SessionStore
public final class SessionStore
io/agentscope/harness/coding/session/SessionStore.java:47–250会话存储,负责持久化与读取数据。位于 io.agentscope.harness.coding.session 包。核心成员包括 load、save、touch、remove、listAll、get。
Durable session registry backed by a JSON file (sessions.json). Mirrors OpenClaw's
sessions.json store that tracks session metadata across restarts.
Thread-safe: uses a read-write lock so concurrent reads are non-blocking and writes are serialized. File writes are atomic (write to temp, then rename).
The store file contains a JSON object keyed by sessionKey, where each value is a
StoredEntry capturing the subset of SessionEntry fields that need to survive
restarts.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
StoredEntry | 记录record | 承载已存储条目数据的记录类型。 JSON-serializable subset of `SessionEntry` for disk persistence. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public SessionStore(Path storeFile) | 初始化 `SessionStore` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void load() | 从持久化存储恢复数据。 Loads all entries from the store file into memory. |
public void save(SessionEntry entry) | 保存数据到持久化存储。 Persists a single session entry (upsert). |
public void touch(String sessionKey, long lastActivityMs) | 执行 `touch` 方法。 Updates only the `lastActivityMs` for the given key without a full entry replace. |
public void remove(String sessionKey) | 设置移除。 Removes a session entry by key. |
public Collection<StoredEntry> listAll() | 返回快照的所有已存储条目。 Returns a snapshot of all stored entries. |
public Optional<StoredEntry> get(String sessionKey) | 按条件读取数据。 Returns a single entry by key, if present. |
public int size() | 返回大小。 Returns the size. |
public Path getStoreFile() | 获取存储文件。 The path to the backing store file. |
构造器详情Constructor Detail
SessionStore
public SessionStore(Path storeFile)
初始化 SessionStore 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
storeFile | Path | 存储文件(类型 `Path`)。The store file. |
io/agentscope/harness/coding/session/SessionStore.java:114–116方法详情Method Detail
load
public void load()
从持久化存储恢复数据。
Loads all entries from the store file into memory.
io/agentscope/harness/coding/session/SessionStore.java:122–145save
public void save(SessionEntry entry)
保存数据到持久化存储。
Persists a single session entry (upsert).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
entry | SessionEntry | 条目(类型 `SessionEntry`)。The entry. |
io/agentscope/harness/coding/session/SessionStore.java:148–156touch
public void touch(String sessionKey, long lastActivityMs)
执行 touch 方法。
Updates only the lastActivityMs for the given key without a full entry replace.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
lastActivityMs | long | 最后 Activity Ms(类型 `long`)。The last activity ms. |
io/agentscope/harness/coding/session/SessionStore.java:159–186remove
public void remove(String sessionKey)
设置移除。
Removes a session entry by key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
io/agentscope/harness/coding/session/SessionStore.java:189–198listAll
public Collection<StoredEntry> listAll()
返回快照的所有已存储条目。
Returns a snapshot of all stored entries.
Collection<StoredEntry>io/agentscope/harness/coding/session/SessionStore.java:201–208get
public Optional<StoredEntry> get(String sessionKey)
按条件读取数据。
Returns a single entry by key, if present.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
Optional<StoredEntry>io/agentscope/harness/coding/session/SessionStore.java:211–218size
public int size()
返回大小。
Returns the size.
intio/agentscope/harness/coding/session/SessionStore.java:220–227getStoreFile
public Path getStoreFile()
获取存储文件。
The path to the backing store file.
Pathio/agentscope/harness/coding/session/SessionStore.java:230–232嵌套类详情Nested Class Detail
StoredEntry
@JsonIgnoreProperties(ignoreUnknown = true) public record StoredEntry( String sessionKey, String agentId, String sessionId, String label, String kind, String spawnedBy, int spawnDepth, long createdAtMs, long lastActivityMs, String sessionFilePath, String spawnRunId, String gateKey, String userId)承载已存储条目数据的记录类型。位于 io.agentscope.harness.coding.session 包。核心成员包括 sessionKey、agentId、sessionId、label、kind、spawnedBy。
JSON-serializable subset of SessionEntry for disk persistence. Uses
@JsonIgnoreProperties(ignoreUnknown = true) for forward compatibility when new
fields are added.