mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-26 23:51:14 +02:00
3.6 KiB
3.6 KiB
Phase 2 — Git-working-tree backend
Build after Phase 1. Umbrella:
00-umbrella-plan.md. Replaces the read-side fake (KBPostgresBackend) with a backend over the real git tree. Agent tools are unchanged.
Objective
A GitTreeBackend implementing deepagents' BackendProtocol over the Phase-1 GitRepoService, so the agent's ls/glob/grep/structure comes from the real git tree instead of the path_resolver + DB folder walk — without regressing read_file's chunk-level citations (see 00c-shared-contract.md C2).
Locked model
- Same tool interface, new backend. Implement the exact
BackendProtocolsurfaceKBPostgresBackendimplements:als_info,aread,awrite,aedit,aglob_info,agrep_raw,alist_tree_listing(return the upstreamWriteResult/EditResult/FileInfo/GrepMatchshapes — no extra fields). - Structure from git;
read_filecontent still renders from chunks (v1).als_info/aglob_info/alist_tree_listing/existence read the git working tree. Butread_filetoday renders XML fromChunkrows and registers[n]citations (aload_document→render_full_document) — v1 keeps that render path (sourced from the derived chunks, one-way from git) so citations don't regress.grepmay scan working-tree source directly (its matches are already coarse<chunk-match>snippets). See C2. - Writes stage in the working tree (commit at end of turn — Phase 3). Reuse the current staging/
Command.updatepattern, backed by the working tree rather than thefilescache. path_resolverpath computation retires for flagged workspaces — folder walk + collision suffixing is replaced by real repo paths (filename rules still reused, C1). KeepDOCUMENTS_ROOTas the repo-relative prefix for continuity.- Selected via the resolver behind
KB_GIT_ENABLED.
Work items
- New
.../filesystem/backends/git_tree.py—GitTreeBackend(workspace_id, runtime)implementingBackendProtocoloverGitRepoService.- Structure calls →
GitRepoServiceprimitives (als_info/alist_tree_listing→list_tree,aglob_info→list_tree+fnmatch,agrep_raw→working-tree scan). read_file/aread/aeditexistence + content: reuse the existing chunk-render path (aload_document/render_full_document) so[n]citations are unchanged in v1.
- Structure calls →
- Wire into
.../filesystem/backends/resolver.py::build_backend_resolver: whenKB_GIT_ENABLEDandworkspace_id is not None, returnGitTreeBackend(workspace_id, runtime)instead ofKBPostgresBackend. - Gate
path_resolver/kb_postgresusage behind the flag (keep both paths compilable during rollout).
Tests
- For a seeded repo,
ls/glob/grep/list_treereturn results identical toKBPostgresBackendfor the same content (golden comparison). read_fileof a nested path returns the rendered document view and registers the same[n]citations as the Postgres backend (no citation regression).- Resolver returns
GitTreeBackendonly when the flag is on; falls back toKBPostgresBackend/StateBackendotherwise.
Out of scope
- End-of-turn commit → Phase 3. Index refresh → Phase 4.
- Desktop-local (
MultiRootLocalFolderBackend) path — unchanged. - Raw-git-blob reads with per-document citations — deferred (C2); revisit with the
raw/+wiki/content model.
Resolved (see 00c-shared-contract.md)
- Read rendering: structure from git,
read_filecontent keeps the chunk-render + citation path in v1 (C2). - glob/grep source: working-tree scan via
GitRepoService(dulwich plumbing optimization deferred).