Class WorkspaceIndex
- All Implemented Interfaces:
AutoCloseable
Tracks files that have been materialized locally under two path prefixes:
agents/*/sessions/** and memory/**. The index is used to speed up
ls / glob / exists / grep in remote-backed workspace mode by avoiding full-store
key scans when enumerating paths under a prefix. File content is never stored in
the index — grep still fetches each candidate file from the remote store
authoritatively.
Consistency model: the index is best-effort and may lag remote changes. Remote writes remain authoritative. Index update failures are silently logged and never propagate to callers.
Thread-safety: SQLite serialises concurrent writers through its own transaction machinery. No external locks are required.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanReturnstrueif the index contains an entry for the given path withpresent_local = 1.booleanReturns true if the index has any entries under the given prefix.listByPrefix(String prefix) Returns all locally-present paths that start with the given prefix.static WorkspaceIndexOpens (or creates) the workspace index for the given workspace root.voidrebuildFromDisk(Path workspaceRoot) Rebuilds the index by walking the local workspace directories (agents/*/sessionsandmemory).voidRemoves a file entry from the index.voidRenames (moves) an index entry fromfromPathtotoPath.voidUpserts a file entry in the index.voidupsertFromLocalFile(String path, Path localFile) Convenience overload that reads file size from the local file if it exists.
-
Method Details
-
open
Opens (or creates) the workspace index for the given workspace root.Returns
nullif the index cannot be initialized — callers should treat anullindex as "unavailable" and fall back to remote scan.- Parameters:
workspaceRoot- absolute path to the workspace root directory- Returns:
- a ready-to-use
WorkspaceIndex, ornullon failure
-
upsert
Upserts a file entry in the index. Silently no-ops if the path is not under an indexed prefix, or if any error occurs.- Parameters:
path- workspace-relative path (forward slashes)sizeBytes- file size in bytes; pass-1if unknownmodifiedAt- ISO-8601 timestamp string; passnullto use current time
-
upsertFromLocalFile
Convenience overload that reads file size from the local file if it exists.- Parameters:
path- workspace-relative pathlocalFile- absolute path on disk (used for size / mtime); may not exist
-
remove
Removes a file entry from the index. Silently no-ops on errors.- Parameters:
path- workspace-relative path
-
rename
Renames (moves) an index entry fromfromPathtotoPath. Silently no-ops on errors. -
exists
Returnstrueif the index contains an entry for the given path withpresent_local = 1. -
listByPrefix
Returns all locally-present paths that start with the given prefix.- Parameters:
prefix- workspace-relative directory prefix (e.g.agents/a1/sessions/)- Returns:
- list of matching paths, may be empty
-
hasPrefix
Returns true if the index has any entries under the given prefix. Faster thanlistByPrefix(java.lang.String)when only presence is needed. -
rebuildFromDisk
Rebuilds the index by walking the local workspace directories (agents/*/sessionsandmemory). Existing entries are replaced; stale entries for files that no longer exist are removed.This is a best-effort operation: errors are logged and do not throw.
- Parameters:
workspaceRoot- absolute path to workspace root
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-