feat(config): remote auto-sync (autoPull + autoPush) across CLI, web and MCP#700
feat(config): remote auto-sync (autoPull + autoPush) across CLI, web and MCP#700tuxo83 wants to merge 2 commits into
Conversation
…ion (CLI, web and MCP) When `auto_pull` is enabled, Backlog.md runs `git pull --rebase --autostash` before serving an operation, so reads and writes work against the latest remote state. Opt-in, off by default. Covers every entry point: - CLI: a commander preAction hook pulls before each command. - MCP: the server pulls before each tool call (so an AI reads/writes the latest). - Web: each API request pulls first — mutations always pull (so a commit/push is never built on a stale base); reads are throttled (AUTO_PULL_READ_THROTTLE_MS) so UI polling cannot flood the remote. New `pull()` git op: rebase+autostash, gated by `remote_operations` and the presence of a remote; never throws (network / no upstream / conflicts are swallowed) so it can't block a command, tool call or request. Config plumbing: type, migration default, load/save/serialize, CLI get/set, config-key lists and help text. Note: like `bypassGitHooks`/`filesystemOnly`, `autoPull` is intentionally NOT added to needsMigration — an absent value is treated as false and existing projects are not force-rewritten on load. Tests: CLI roundtrip of the config flag; MCP pulls a collaborator's pushed commit before a tool call (and does not when disabled); the web server pulls on an API request before serving it (and does not when disabled).
Symmetric counterpart of autoPull. When `auto_push` is enabled, Backlog.md runs `git push` right after each commit, so changes are shared immediately without a per-clone post-commit hook. Implemented at the commit layer (git/operations.ts), so it covers every entry point that writes through Core: the CLI, the web UI and the MCP server. This is the native replacement for a `.git/hooks/post-commit` "git push" hack. - Opt-in, off by default: `auto_push: false`. - New `push()` git op: pushes the current HEAD; gated by `remote_operations` and the presence of a remote; never throws (network / non-fast-forward / no upstream are swallowed) so it can't block a commit. - `autoPushIfEnabled()` is called after each of the 4 commit builders. - Config plumbing: type, migration default, load/save/serialize, CLI get/set, and the config-key lists + help text. Note: like `bypassGitHooks`/`filesystemOnly`, `autoPush` is intentionally NOT added to needsMigration — an absent value is treated as false and existing projects are not force-rewritten. Tests: real bare-remote push verified after a Core commit; no push when disabled; no push when remoteOperations is off; config save/reload roundtrip.
|
Alex's Agent: Thanks for the detailed PR and tests. I am going to close this due to current project scope and risk rather than iterate on the implementation here. Backlog.md is keeping git behavior explicit and user-directed, and automatic git pull/push across CLI, web requests, and MCP tool calls changes the core git behavior and risk profile too broadly, even as opt-in config. In particular, web/MCP-triggered remote mutation, pre-command pulls, post-commit pushes, and swallowed pull/push failures are not behavior we want to add under the current project direction. If there is a follow-up worth splitting out, keep it narrow and non-mutating: a docs/config clarification around the existing Closing as out of scope/deferred. Future PRs in this area should link an issue first, or open one before implementation so scope can be agreed. |
feat(config): remote auto-sync —
autoPullbefore /autoPushafter, across CLI, web and MCPSummary
Two complementary, opt-in config flags that keep a shared Backlog.md repository in
sync with its git remote automatically — no per-clone git hooks required:
autoPull— rungit pull --rebase --autostashbefore an operation, soreads/writes work against the latest remote state.
autoPush— rungit pushafter every commit, so changes are sharedimmediately.
Both are off by default and both cover every entry point that touches the
repo: the CLI, the web UI and the MCP server. Together they make a hosted
Backlog.md (web + MCP behind a gateway) stay consistent with humans using the CLI.
autoPull— sync before each operationcommanderpreActionhook pulls before each command.is never built on a stale base); reads are throttled
(
AUTO_PULL_READ_THROTTLE_MS = 2000ms) so UI polling cannot flood the remote.autoPush— push after each commitgit/operations.ts), so a single seam coversCLI + web + MCP. Native replacement for a
.git/hooks/post-commit"git push" hack.git push origin HEAD).Behavior & safety (both)
false→ no change for existing users.remoteOperationsand the presence of a remote (skipped for--no-git/ filesystem-only, or when no remote is configured).pull()/push()swallow expected failures(network down, no upstream, non-fast-forward, rebase conflicts) — the command,
request or tool call always proceeds.
autoPulluses--rebase --autostash, solocal uncommitted edits are stashed/replayed and never clobbered.
bypassGitHooks/filesystemOnly, neither flag is added toneedsMigration,so existing projects are not force-rewritten on load (absent ⇒ false).
Usage
What's included
src/types/index.ts—autoPull?,autoPush?.src/core/config-migration.ts— defaultsfalse(intentionally not inneedsMigration).src/file-system/operations.ts—auto_pull/auto_pushload + save (snake_case).src/git/operations.ts—pull();push()+autoPushIfEnabled()after the 4 commit builders.src/cli.ts—preActionpull hook;config get/setfor both; config-key lists + help.src/mcp/server.ts—maybeAutoPull()before each tool call.src/server/index.ts—maybeAutoPull(force)+applyAutoPullToRoutes()(mutations force, reads throttled).README.md— documented in the Configuration section.src/test/auto-push.test.ts— real bare-remote push after aCorecommit; no push when disabled / whenremoteOperationsoff.src/test/mcp-auto-pull.test.ts— MCP pulls a collaborator's pushed commit before a tool call (and not when disabled).src/test/server-auto-pull.test.ts— the web server pulls on an API request (and not when disabled).src/test/config-commands.test.ts— save/reload roundtrip for both flags.Testing
bunx tsc --noEmit→ clean.npx biome check .(changed files) → clean.bun test(auto-push, mcp-auto-pull, server-auto-pull, config, cli, mcp suites) → 126 pass / 0 fail, including a realgit pushreaching a bare remote and a realgit pullof a collaborator's commit via both the MCP and web paths.Related Tasks