Skip to content

feat(mcp): add pull and push commands for documents - #769

Merged
pikann merged 30 commits into
Paca-AI:masterfrom
msammu07:feat/mcp-pull-push
Nov 15, 2026
Merged

pikann merged 30 commits into
Paca-AI:masterfrom
msammu07:feat/mcp-pull-push

Conversation

@msammu07

@msammu07 msammu07 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #747 (docs pull / push / content check for coding agents). Adds two commands to @paca-ai/paca-mcp that use the API from #751, #753, #754 and #759. Only apps/mcp changes; nothing in the MCP tools changes.

npx @paca-ai/paca-mcp pull [--project <id>] [--dir .paca/docs] [--force]
npx @paca-ai/paca-mcp push <file> [--path "Folder/Title"] [--project <id>] [--note "…"] [--task PACA-88] [--lock] [--force] [--dry-run]

They read the same environment as the server (PACA_API_KEY, PACA_API_URL, PACA_PROJECT_ID). Without a command the binary starts the MCP server as before.

pull: mirror documents to Markdown files

  • The first run downloads every document the caller can read; later runs ask the change feed what changed, so an up-to-date pull is one request.
  • Edited documents are fetched again. Moved or renamed ones, folder renames included, are moved without downloading. Deleted ones, and ones the caller lost access to, are removed.
  • The mirror is read-only for now. A mirror file edited locally is kept and reported (exit 2); --force overwrites it.

push: write a repository file to a document

  • Writes the file to a document by path (Plans/<name>, or Specifications/<name> for a file under a specs folder; --path sets another) as a managed copy that records repository, file path and commit.
  • An unchanged file is not sent. Each push after the first sends If-Match with the ETag of the last push.
  • If the Paca copy changed since, the push stops (exit 2) and prints who changed it, when, their note, and a diff from the last pushed version to the Paca copy. --force overwrites.
  • --lock makes the document read-only in Paca for everything but a push from the same repository.
  • Two files never share a document: a push whose document path is already recorded for another file is refused (exit 1) and points at --path. Paths are compared the way the server resolves them (segments trimmed, empty ones dropped, case ignored). When that other file no longer exists (a git mv, including a case-only one), the moved file takes over the entry and its ETag.

Exit codes: 0 done, 1 error, 2 conflict, 3 server unreachable (nothing recorded). The README has a new section, "Command line: pull and push", with the full rules.

Safety rules in pull

  • Nothing is written outside --dir. Unsafe characters in titles become _; names that clash (compared without case and Unicode normalisation) get ~<first 8 characters of the id>; Windows reserved names get a _ prefix.
  • A file in --dir that pull did not write is never overwritten.
  • pull refuses to run when the mirror contains a symlink.
  • One pull per mirror at a time (.paca-pull.lock; a lock left by a process that is gone is taken over).
  • Sibling folders whose names differ only by case, Unicode normalisation or unsafe characters get their own directories (~<first 8 characters of the id> for the later one); a directory keeps its name across pulls.
  • A pull that fails part way puts moved files back and removes files it created.
  • A pull that is killed part way is finished by the next one, with one file per document and no duplicate: new file names are recorded (with the old cursor) before files get them, and names of files about to be created are reserved. The state never claims content that pull did not write. A test kills a pull at each of its renames and checks the restart.
  • A kept file whose document comes back under another title moves with the document and stays kept.

Decisions, listed so they can be challenged

  1. source.repository is owner/name from the origin remote, with the folder name as fallback. The lock compares this string exactly, so a bare repository name would let two forks' pushes collide.
  2. A deleted document whose mirror file was edited locally is kept and reported with exit 2, in line with "never destroy local edits". --force removes it.
  3. The conflict diff is built in, with no new dependency and no need for git.
  4. Push state is kept per project and server (.paca/push.json), so an entry made against another project or server is ignored.
  5. No version bump: the CHANGELOG entry is under [Unreleased].

Known gaps

  • A file the user creates or edits at a reserved name between a killed pull and its restart is overwritten by the restart.
  • The pull lock is taken over when its process id is not running; a recycled process id can make a stale lock look live until it is removed by hand.
  • Requests have no timeout.
  • A 404 from something that is not Paca (a wrong PACA_API_URL) is reported as "this Paca server is too old for pull/push".
  • pull makes one extra request per managed document to record that it is managed.
  • batchGet is added to the document client here; the partial-edit tools that follow in [Feature] Docs: efficient pull/push/content-check for coding agents (change feed, ETags, upsert by path, partial reads) #747 need the same method and will reuse it.

Type of Change

  • New feature (MCP package)

Testing

  • apps/mcp: tsc clean; lint reports 4 warnings, all in files this PR does not touch; vitest 918 of 918 (42 files). New test files: cli/pull.test.ts, cli/pull-interrupt.test.ts, cli/pull-kill-every-rename.test.ts, cli/pull-rollback.test.ts, cli/push.test.ts, cli/mirror-paths.test.ts, cli/dispatch.test.ts, cli/diff.test.ts, cli/git-source.test.ts, api/doc-client-changes.test.ts.
  • Live run of the built CLI through the gateway of the e2e stack (master with fix(api): accept a document ETag with a compression suffix in If-Match #759):
    • first push: created Plans/plan
    • same file again: unchanged
    • edited file: updated Plans/plan. The recorded ETag carried the gateway's -gzip suffix and was accepted as If-Match.
    • after an edit made in Paca: exit 2 with the writer, the time and the diff
    • push --force: updated
    • pull: 1 updated; pull again: up to date
  • Second live run through the gateway: a second file with the same default path is refused (also with --dry-run), --path sends it to its own document, and a moved file takes over its entry (the document's source.path follows).
  • Earlier live runs against an API built from master also covered a folder rename (file moved without a download), a delete, --lock with a push from another repository (refused, names the owning repository) and --dry-run.

Checklist

  • The change is focused and scoped.
  • Related documentation is updated: apps/mcp/README.md and apps/mcp/CHANGELOG.md.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

push can silently overwrite another file's managed document: the default document path keeps only the basename, so two plan.md files in different folders resolve to the same Plans/plan, and the second file's first push carries no If-Match.

Reviewed changes

Read the full diff (18 files, 9 commits) and checked the client calls against the Go handlers and contract docs already on master. In short: the pull mirror (change feed, name sanitization, symlink refusal, per-mirror lock, rollback), the push managed-copy writer (source metadata, If-Match conflict handling with diff, --lock/--dry-run), the CLI dispatch and exit codes, the getChanges/batchGet client additions, and the README/CHANGELOG with seven new test files.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread apps/mcp/src/cli/push.ts Resolved
Comment thread apps/mcp/src/cli/pull.ts Resolved
Comment thread apps/mcp/src/cli/mirror-paths.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new shared-document guard in push compares document paths as raw strings, but the server resolves them case-insensitively and trims segments, so Plans/plan and Plans/Plan are one document — the second file still overwrites the first's without an If-Match. There is also a smaller gap in the new interrupted-pull state.

Reviewed changes

Reviewed the 17 commits since the last Pullfrog review (3f46afc), which close the three earlier findings.

  • Added a shared-document guard to push: a path another file already records is refused, and an entry whose file was moved away is taken over with its ETag and base copy.
  • Wrote an interim pull state before any file is moved into place or written, with reserved and pending_sha256 recovery fields so a killed pull is finished by the next one.
  • Gave sibling folders whose names share one key (case, Unicode form, characters mapped to _) their own mirror directories, remembered in the state's new dirs.
  • Moved a revived kept file with its document instead of writing over it.
  • Restricted rollback's state restore to the case where every created file is gone and every moved file is back under its temporary name.
  • Added crash tests that stop a pull at every rename and at chosen content writes, plus new pull, push and mirror-path cases and the matching README/state documentation.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread apps/mcp/src/cli/push.ts Resolved
Comment thread apps/mcp/src/cli/pull.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — both findings from the last review are fixed and covered by tests; one small wording fix inline.

Reviewed changes

Reviewed the 3 commits since the prior Pullfrog review (0560073); both open findings are addressed.

  • Added docPathKey (segments trimmed, empty segments dropped, case-folded) and used it for the unchanged shortcut, the owner lookup and If-Match, collecting every entry that claims the document rather than the first.
  • After a write, refused to record a document id another entry already records, which covers both the few characters JavaScript and Postgres lowercase differently and a document moved in Paca.
  • Replaced the single pending_sha256 with a list settled at the start of every pull by settlePending: only the hash the file on disk actually holds survives, and the interim state appends the hash being written instead of replacing it.
  • Added tests for case, space and double-slash path variants, several stale owners, the document-id guard, and repeated interrupted pulls including a local edit and a deleted document, plus the matching README and state documentation.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread apps/mcp/src/cli/push.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the single commit since the prior Pullfrog review (5a8d53a), which closes the last open finding.

  • Pointed the push twin-document error at --force when telling the user to re-push the other file, since this write already bumped the document's ETag and a plain re-push would end in a 412. --force bypasses both the unchanged short-circuit and If-Match, so the suggested command does restore the other file's content.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Docs: efficient pull/push/content-check for coding agents (change feed, ETags, upsert by path, partial reads)

2 participants