Skip to content

feat(mcp): add pull_docs and push_docs tools for document mirroring and editing - #776

Merged
pikann merged 4 commits into
masterfrom
feature/add-pull-and-push-docs-tools
Nov 16, 2026
Merged

pikann merged 4 commits into
masterfrom
feature/add-pull-and-push-docs-tools

Conversation

@pikann

@pikann pikann commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Asked to "pull docs", an agent had no tool for it. pull and push exist only as command-line commands of @paca-ai/paca-mcp, so the agent saw only list_docs / read_doc and read the documents one by one into the conversation, saving nothing locally. Nothing in the skills pointed it at the commands either.

Changes

MCP tools (apps/mcp)

  • pull_docs (projectId, dir, force) runs the existing pull: mirrors every document to <dir>/<folder>/<title>.md. A file edited locally is merged with changes made in Paca.
  • push_docs (projectId, file, path, note, task, lock, force, dryRun) runs the existing push: a file from a pull mirror goes back to its document as an edit of only the blocks it changes; any other file is written to path as a managed copy.
  • Both reuse runPull / runPush through one runner that collects the command's output. A conflict (exit 2) is a normal result that says to pull_docs, resolve, and push again; a real failure or an unreachable server is a tool error.
  • merge and diff are internal helpers of those two commands, not commands, so they get no tools.
  • Files are read and written relative to the MCP server's working directory. push_docs records state per PACA_API_URL (default http://localhost:8080), as the command line does.

Bundled skills (services/api/.../bundledskills/content: paca, paca-doc, paca-do, each in CLI and agent form)

  • Routing rows and a "Reading and editing docs as files" section: pull, read/search/edit the files, push back; on a conflict pull again, resolve markers, push.
  • Agents are told to pull into a temporary folder outside the workspace (e.g. dir: "/tmp/paca-docs"). If they pull inside the workspace (the default .paca/docs), they must add the folder to .gitignore first so the mirror is never committed.
  • The existing "never leave a doc only on disk" rule stays: the mirror is a working copy, and changes are always pushed back.
  • read_doc / write_doc remain the default for a single document.

Not changed

The default dir is still .paca/docs, inside the workspace, so an agent that omits dir pulls there. A default under the system temp folder would need a per-project path so mirrors of different projects do not mix.

Testing

  • apps/mcp: full vitest suite passes (1296 tests), including new tests for both tools and a routing check; biome clean on the changed files.
  • services/api: go test ./internal/platform/bundledskills/ passes.
  • Not run against a live server or agent. tsc -b could not write build/ (root-owned by Docker); tsc --noEmit -p . shows no errors besides the write errors.

The MCP server and the API need redeploying before agents see the new tools and skill text.

@pikann pikann changed the title feat(mcp): add pull_docs and push_docs tools for document mirroring a… feat(mcp): add pull_docs and push_docs tools for document mirroring and editing Nov 16, 2026

@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 — three minor suggestions inline, plus one design question about where the default mirror lives.

Reviewed changes

  • pull_docs / push_docs tools (apps/mcp/src/tools/doc-mirror-tools.ts) — thin wrappers over the existing runPull / runPush, sharing a runCommand helper that collects CLI output; exit 0 is success, 2 is a non-error conflict, 1 and unreachable are tool errors.
  • Registration and routing (apps/mcp/src/tools/index.ts) — both tools added to getAllTools() and routed through DOC_MIRROR_TOOL_NAMES, after the filesystem document tools.
  • Tests — doc-mirror-tools.test.ts covers the tool list, required arguments and result shaping for ok/conflict/failure/unreachable; index.test.ts adds a routing check.
  • Skills and reference docs — a new "Reading and editing docs as files" section, routing rows and tool-reference entries in paca, paca-do and paca-doc (CLI and agent forms), a README paragraph and a CHANGELOG entry, all steering agents to a temporary mirror outside the workspace.
  • Underlying CLI wiring checked — runPull refuses symlinks and writes only under the mirror root, runPush resolves a mirror through findMirror and pushMirrorFile refuses path/lock/force for pulled files, honours dryRun, and reads with the caller's projectId. The mapping in runCommand is faithful to those exit codes.

ℹ️ The default mirror folder lands inside the working tree

pull_docs defaults dir to .paca/docs, relative to the MCP server's working directory, which for an agent is the repository checkout. The skills tell the model to gitignore that folder first, but the fallback is only as good as the model remembering it, and git_commit with all: true runs git add -A, which would stage every mirrored document plus .paca-sync.json and .paca-base/ into the user's branch. The PR body already flags this as deliberately unchanged, so this is a question rather than a defect.

Technical details
# Default `dir` inside the checkout can be committed

## Affected sites
- `apps/mcp/src/tools/doc-mirror-tools.ts:11` — `dir` defaults to `.paca/docs` (same as the CLI).
- `apps/mcp/src/git/workspace.ts:696` — `git_commit` with `all: true` stages the whole work tree.
- `services/api/.../content/paca.agent.md` / `paca.md` — the instruction to gitignore the folder is a model step, not an enforced one.

## Required outcome
- Either the default mirror is guaranteed not to be commit-or-push-able (a per-project path under the system temp directory), or `pull_docs` refuses/warns when `dir` resolves inside a git work tree and is not already ignored by `.gitignore`/`.git/info/exclude`.

## Open questions for the human
- Is the CLI-compatible `.paca/docs` default worth keeping now that the caller is an autonomous agent rather than a person watching the output?
- If keeping it, should the tool report the exact `.gitignore` line (or check `git check-ignore`) instead of leaving it to the skill text?

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

Comment thread apps/mcp/src/tools/doc-mirror-tools.ts Resolved
Comment thread apps/mcp/src/tools/doc-mirror-tools.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. The three inline findings from the previous review are addressed, and the new routing test now exercises real routing.

Reviewed changes

  • pull_docs description — now sends the agent to push_docs rather than the npx @paca-ai/paca-mcp push shell command.
  • push_docs conflict summary — no longer assumes the pull-mirror flow; it defers to the CLI guidance appended to the result and maps force/pull to those flags.
  • Document-mirror routing test — doc-mirror-tools.js is mocked and the test is parametrized over pull_docs/push_docs, asserting handleDocMirrorTool receives (name, {}, docClient) and the filesystem handler is not called, so it fails if routing is lost.

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

@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.

Approved: the three inline findings from review 5915689761 are addressed and the new routing test exercises real routing.

@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 path confinement refuses the temp folder that the tool descriptions and the bundled skills tell agents to use, on macOS and Windows.

Reviewed changes

  • Confined both tools' filesystem targets — assertAllowedPath resolves the nearest existing ancestor with realish and refuses a pull_docs dir or push_docs file outside the server's working directory, os.tmpdir() and PACA_MCP_FILE_ROOTS; tests cover absolute and .. escapes.
  • Made pull_docs ignore its mirror — a pull that is not a tool error writes <dir>/.gitignore containing *, so the mirror files, .paca-sync.json and .paca-base/ stay out of Git.
  • Tightened the conflict and result text — the pull conflict summary now says force discards local edits, push_docs documents .paca/push.json and the confinement, and runCommand returns a typed ToolResult.
  • Documented the confinement — README and CHANGELOG describe the allowed roots and the per-mirror ignore file.

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

Comment thread apps/mcp/src/tools/doc-mirror-tools.ts Outdated
const extra = (process.env.PACA_MCP_FILE_ROOTS ?? "")
.split(path.delimiter)
.filter(Boolean);
return [process.cwd(), os.tmpdir(), ...extra].map((r) => path.resolve(r));

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.

The allowlist is the server's cwd, os.tmpdir() and PACA_MCP_FILE_ROOTS, but the pull_docs description (line 101), the dir help (line 114) and every bundled skill tell agents to use dir: "/tmp/paca-docs". On macOS os.tmpdir() is normally $TMPDIR (/var/folders/.../T) while /tmp resolves to /private/tmp, and on Windows /tmp resolves under the current drive, so the documented call is refused as outside the allowed folders.

Technical details
# The documented temp folder is outside the allowlist on macOS and Windows

## Affected sites
- `apps/mcp/src/tools/doc-mirror-tools.ts:43` — roots are `process.cwd()`, `os.tmpdir()`, `PACA_MCP_FILE_ROOTS`.
- `apps/mcp/src/tools/doc-mirror-tools.ts:101` and `:114` — recommend `dir: "/tmp/paca-docs"`.
- `services/api/internal/platform/bundledskills/content/paca.md:74`, `paca.agent.md:93`, `paca-do.md:17`, `paca-do.agent.md:18`, `paca-doc.md:19` — same example.

## Required outcome
- Either admit the conventional POSIX temp root (`/tmp`, realpath-resolved) to `allowedRoots()`, or stop naming `/tmp/...` and point agents at a folder under the system temp directory; the refusal message should name the actual temp root so an agent can recover.
- The tool description, the `dir` help and the skill text must agree with the allowlist on macOS and Windows.

Comment thread apps/mcp/src/tools/doc-mirror-tools.ts Resolved
Comment thread apps/mcp/src/tools/doc-mirror-tools.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 — two minor suggestions inline.

Reviewed changes

  • Admitted /tmp on POSIX — allowedRoots() now adds /tmp on non-Windows platforms, so the folder the tool help and skills name is accepted on macOS, and the refusal message names os.tmpdir().
  • Scoped the mirror .gitignore — a pull now writes <dir>/.gitignore only for a folder it creates or an existing mirror, and a dir resolving to the server's working directory is refused before the pull runs.
  • Covered the new guards with tests — new cases for the working-directory refusal, /tmp acceptance, and the untouched pre-existing folder.

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

).rejects.toThrow(/working directory/);
});

it("accepts /tmp as documented", async () => {

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.

allowedRoots() excludes /tmp on win32, so this test fails on a Windows checkout while its name asserts the documented path works. Use os.tmpdir() for the platform-neutral check, or guard the /tmp case with it.skipIf(process.platform === "win32") and keep it as a POSIX-only test.

failed: "Pull failed; nothing was changed.",
},
);
if (!res.isError && ownsFolder) await ignoreMirror(dir);

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.

When dir already exists and is not yet a mirror, ownsFolder is false, so no .gitignore is written — even though the pull then writes .paca-sync.json and makes it a mirror (the next pull would add the file). Meanwhile the pull_docs description (line 127) and the dir help (line 140) promise the folder gets its own .gitignore, so an agent pulling into a pre-existing in-repo folder (e.g. dir: "docs") leaves mirror files that git_commit with all: true will stage. Say in the result when the folder was left alone so the caller can add it to .gitignore, or make the promise conditional.

@pikann
pikann merged commit 12bba1f into master Nov 16, 2026
7 checks passed
@pikann
pikann deleted the feature/add-pull-and-push-docs-tools branch November 16, 2026 07:01
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.

1 participant