mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-26 23:51:14 +02:00
2.8 KiB
2.8 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/read/write/edit/mv/rm/glob/grep operate on real files in the workspace git repo instead of faked-over-Postgres rows.
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). - Reads hit git; writes stage in the working tree (commit happens at end of turn — Phase 3). Reuse the same staging/
Command.updatepattern the current wrappers use, but backed by the working tree rather than thefilescache + Postgres. path_resolverretires for flagged workspaces — virtual/documents/...paths become real repo paths. 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.- Map protocol calls →
GitRepoServiceprimitives (aread→read_file,aglob_info→list_tree+fnmatch,agrep_raw→tree scan, etc.). - Preserve read rendering behavior the agent expects (document text/XML view) so reads never regress.
- Map protocol 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/read/glob/grepreturn results identical toKBPostgresBackendfor the same content (golden comparison). readof a nested path returns file content;glob("**/*.md")lists the tree;greprespects the existing match caps.- 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.
Open questions
- Read rendering: serve raw markdown from git vs. reproduce the current rendered-document view (citations). Confirm what the agent contract needs.
- Whether
grep/globscan the working tree directly or use git plumbing (git grepsemantics via dulwich) for large repos.