← Back to PRs

#19570: feat(workspace): core document change tracking — git-backed history & rollback

by aronchick open 2026-02-17 23:47 View on GitHub →
cli agents size: L
Closes #19569 ## Summary Adds git-backed change tracking for core workspace documents (AGENTS.md, SOUL.md, TOOLS.md, USER.md, MEMORY.md, POLICY.md). Every mutation is auto-committed to the workspace git repo with provenance metadata. ## What's Changed ### `src/agents/tracked-docs.ts` — Core API - `writeTrackedDoc()` — write a file + auto-commit with session/agent/reason metadata - `getDocHistory()` — list commits touching a specific doc - `getDocAtCommit()` — get file content at any historical commit - `getDocDiff()` — unified diff between commits - `rollbackDoc()` — restore a prior version (recorded as a new rollback commit) - `TRACKED_DOC_FILENAMES` — canonical set of core doc names - Graceful fallback: plain write if git unavailable (warns once) ### `src/agents/tracked-docs.test.ts` — Tests 10 tests covering all public functions. All pass ✅ ### `src/cli/docs-workspace-cli.ts` — CLI `openclaw workspace-docs` subcommand with history, diff, show, rollback. ## Design Principles - **Zero new dependencies** — uses the git repo already initialized by `ensureGitRepo()` in `workspace.ts` - **Non-breaking** — existing raw writes continue to work; `writeTrackedDoc()` is opt-in in phase 1 - **Files stay as Markdown** — no schema, no migration, no database - **Traceable** — commit body always includes session key and agent label ## Out of Scope (Phase 2) - `workspace_doc_edit` agent tool to replace raw writes - Tool policy enforcement to require tracked writes for core docs <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds git-backed change tracking for workspace documents (`AGENTS.md`, `SOUL.md`, `TOOLS.md`, etc.) with a clean API in `tracked-docs.ts` and CLI commands for viewing history, diffs, and rollbacks. The implementation is well-tested with 10 passing tests and gracefully falls back to plain writes when git is unavailable. Key issues: - **CLI commands are not registered** - `registerWorkspaceDocsCommands` is never called from the command registry, so `openclaw workspace-docs` won't work - The `write` command mentioned in help text doesn't exist - `POLICY.md` is hardcoded rather than using a constant from `workspace.ts` The core tracking logic is solid and follows good practices (explicit provenance, graceful degradation, immutable history). Once the CLI registration is fixed, this will provide valuable change tracking for workspace documents. <h3>Confidence Score: 2/5</h3> - This PR has a critical issue that prevents the main feature from being usable - The CLI commands are not registered in the command registry, making the entire `openclaw workspace-docs` command unavailable to users. This is a blocking issue that prevents the feature from working. The underlying implementation is well-designed and thoroughly tested, but the integration step is incomplete. - `src/cli/docs-workspace-cli.ts` requires registration in the command registry to make commands accessible <sub>Last reviewed commit: fdc349b</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs