Repository navigation
prototype: people's own agents use patches through Patchy's MCP - #727
Closed
allisonmahmood wants to merge 8 commits into
Closed
allisonmahmood wants to merge 8 commits into
allisonmahmood wants to merge 8 commits into
Conversation
…n's agent Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SDK's agent area (server/agent.ts, descriptions, ctx.agent), OAuth for MCP clients with use-purpose machine tokens and the company's agent access switch, agent calls on the served version with "via" attribution, and the /mcp door. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… can do on the card Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and readable refusals Co-Authored-By: Claude Opus 5.5 <[email protected]>
… no 2026-07-28 claim From the Sol review: the read/change kind is checked against the version actually invoked, another instance's address resolves to nothing, and the stateless revision isn't advertised until its envelopes exist. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Claude Code accepts over http Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 17, 2026
Closed
1 of 2 tasks
This was referenced Oct 22, 2026
allisonmahmood
added a commit
that referenced
this pull request
Oct 23, 2026
Stacked on #869 (ticket #839); merges with the rest of #833's stack, not alone. ## What changed A tier 2 patch can now have tools for people's agents: every export of a root `agent/*.ts` file publishes as an agent tool named after its export, with no `refresh`. The page can't import or call them. #837's readers already refuse page calls to them; this PR is what first writes the mark. Closes #840 ## Look at **1. The build folds `agent/` into one module named `agent`.** The generated entry in `packages/patchy/src/serverBuild.ts` passes `agent/` files by name to `createGuest`. `foldAgentArea` in `handlerDescriptors.ts` merges them, and `extractHandlerDescriptors` marks each `agent.<export>` descriptor `agentTool: true`. A re-export is one handler under two names, unmarked for the page. Published on a dev instance, from a fresh `patchy init --tier 2` plus this file, with no refresh: ```ts // agent/deals.ts export { list } from "../server/notes.js"; export const addNote = mutation({ description: "Adds a note with a title. Refuses a blank title.", … }); ``` ``` $ patchy publish --json | jq -c '[.handlers[].name]' ["agent.addNote","agent.list","notes.create","notes.list"] ``` Inspection returns `agent.list` with `"agentTool": true` and `notes.list` without it. **2. Duplicate names are refused naming both files, `export *` included.** The guest's fold reads the real module namespaces, so it knows exactly which two files export a name. Inside workerd, though, a throw while loading loses its message. So `createGuest` answers every request with its refusal instead of throwing (`guest.ts`). `packages/execution/src/inspection.ts` reports that answer as reason `refused`, carrying its text as `problem`, and the CLI's publish and dev builds show it. The instance keeps its generic `invalid_manifest` and never echoes text from a bundle, and a refused bundle never binds. Statically following `export *` was tried and dropped after review (see the review comment). The build reads each file's own export statements only to name a tool's file in #839's description refusals, or `agent/*.ts` when there is none. The four refusals and the warning, from the same dev repo: ``` $ patchy publish --json # agent/crm.ts re-exports addNote from agent/deals.ts {"ok":false,"error":"addNote is exported by agent/crm.ts and agent/deals.ts; each tool needs its own name.","kind":"local","code":"invalid_manifest"} $ patchy publish --json # with server/agent.ts {"ok":false,"error":"server/agent.ts: Agent tools live in agent/; move these exports there.","kind":"local","code":"invalid_manifest"} $ patchy publish --json # src/App.tsx imports ../agent/deals.js {"ok":false,"error":"src/App.tsx imports \"../agent/deals.js\", but the page can't import agent/ at runtime. Agent tools are for people's agents only; call server/ handlers through patchy.server.","kind":"local","code":"import_refused"} $ patchy publish --json | jq -c '{ok, warnings}' # tsconfig.json include without agent {"ok":true,"warnings":["tsconfig.json doesn't include agent/, so pnpm typecheck skips your agent tools. Add \"agent\" to its include list."]} ``` `agent/` below tier 2 is `tier_mismatch` (`agent/ requires tier 2. Change the tier and run \`patchy refresh\`, or remove agent/.`), from the same check as `server/` (`repoBuild.test.ts`). Page imports from `server/` now get the same kind of fix-it message instead of the generic package one. **3. The dev watcher watches `agent/` beside `server/`.** `devServerWatch.ts` keeps one directory watch per folder and restarts the Vite watcher when either file list changes. A new agent file rebinds with no refresh reminder. The tsconfig check runs whenever the agent file list changes. ## How it was verified - `vitest`: `devServerWatch.test.ts` covers, on real Vite and workerd builds: - a re-export plus a tool of its own, folded and marked with no refresh; - a named duplicate and an `export *` duplicate, each refused naming both files in watch, and through inspection of publish's `buildServer` output; - ambiguous `export *` and a `__proto__` file building cleanly; - recovery; - an agent tool's blank description naming `agent/intake.ts`. `Inspection.test.ts` carries a guest's refusal as `refused` and no other failure's text, and `guest.test.ts` covers the refusing guest. Also `server.test.ts`, `serverModules.test.ts`, `pageImports.test.ts`, `repoBuild.test.ts`, `initProject.test.ts` and the bundled-CLI suites. #837's fixtures for older `server/agent.ts` bundles (`InvocationLocal.test.ts`, `PatchesApi.test.ts`) still pass. - Typecheck of `patchy` and `tsconfig.test.json`; lint on the changed files. - Hand-checked on this worktree's dev instance, as above. `~/Patchy` gained nothing. - Rollback rehearsal: against `main` dd3f41f, which has #837 and #838: `pnpm test:rollback-rehearsal --live dd3f41f` gives `Exercised rollback paths passed: dd3f41f → bde24e7 → dd3f41f, in 208s.` Step 2 publishes the rehearsal's `agent/notes.ts` through HEAD's CLI, which marks `agent.countNotes` as an agent tool, and both releases refuse the page's call to it. CI's run against production's d77baaf fails at step 3, because d77baaf can't read the new descriptor fields. That's the gate #833 documents until #837 is live. - `pnpm verify` on bde24e7: format, lint, typecheck, synth, postgres-concurrency, cli-smoke, tier2-smoke and browser pass. The test stage had seven timeouts while other lanes loaded the machine. Its seven failing files, rerun alone with two workers, pass (78 tests). - Not checked here: an agent actually calling a tool. That needs #843 (agent invocation) and #844/#854 (`patchy dev agent`, the door). ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required Today the build ignores `agent/`. Now it builds it, and only tier 2 repos that have the folder change. A repo with a `server/agent.ts` is refused; only the unmerged prototype (#727) used that file. - **What does a revert leave behind?** Versions whose stored descriptors mark `agent.*` handlers `agentTool: true`. - **Does the release before it still work with that?** Yes, from #837 on, which reads the mark and refuses page calls to marked tools. #833 releases this stack only after #837 is live. Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prototype, not for merge. It's up so we can try the agent side of patches and react. Related: the tier 3 map (#623) reserved "Patchy MCP" as a seam; this is that seam, built as a throwaway.
Patches are nice to look at, but today a person has to type everything into them. People want their own agents (Claude Code, Codex, ChatGPT, whatever speaks MCP) to do that work for them, without every field becoming editable by an agent.
This prototype has three parts:
server/agent.ts(the agent area) are the only things an agent can call. Each export needs a description, and its fields take.describe(…). Handlers seectx.agent(the client's name), so a patch can hold agents to stricter rules (Brightline'saddLeadsmakes agents fill every field) or tag what they did. Publish refuses undescribed tools and uploads or file handles in them. Thepatchy-serverskill teaches all of this to the builder agent.<instance>/mcpoffers four fixed tools:find_patches,open_patch,read_patchandchange_patch. The agent explores from there, so a new patch needs no new connection and the agent's context stays small. The door is stateless JSON-RPC, so any replica answers.use. CLI tokens arebuild, and neither works on the other door. Connections are listed and disconnected on Your machines./companyis off until an admin turns it on.Try it
pnpm dev up brightline pnpm dev open allison # Company → Agent access → Turn onThe card printed by
uplists the launchers:<env>/workerstarts Claude Code connected only to Patchy's MCP. On first use it opens the consent page, where you sign in as anyone.<env>/worker-codex jordanand<env>/worker-grok priyastart Codex or Grok as that person, with a minted token.pnpm dev mcp-token <person> --client <name>and give it the MCP URL from the card.Things to ask:
Keep New Business open as someone else and watch rows arrive live. The card's Log says who did what, via which agent.
To build your own patch, use
<env>/agent, the builder. Ask it for a patch "where agents can …" with whatever constraints you like, then use it from a worker.What happened when I tried it
codex mcp login) went end to end against the instance: it discovered the server, registered itself, got consent as Sofia and exchanged the code.workerlauncher) works too. Claude Code sends credentials over plain http only tolocalhostor127.0.0.1, so a dev instance advertises its token endpoint on127.0.0.1; production is https.standuppatch from the skills alone. A Claude Code worker then posted through it.pnpm checkpasses: 186 test files, 1,847 tests. GPT 6.1 Sol reviewed the build. It found no high-severity issues and three medium ones, all fixed:read_patchracing a publish into a writeWhat Allison's testing showed (2026-10-17)
She ran Claude Code, Codex and other agents against the brightline environment, had the builder make an agent comms board from one sentence, then had several people's agents use it to coordinate for the team. LGTM as a prototype; next is the map.
Permissions come in three layers.
In testing, Patchy would have allowed "mark Northline Won" for an admin, but Claude Code's auto mode held it back without an explicit confirmation. Claude also skipped a lead it judged a duplicate, though the patch has no duplicate rule.
Agents say who they act for. Signed in as Jordan from Allison's Claude account, the agent pointed out the mismatch before writing.
Agents confirm before writes. Clients ask before writes unless the person pre-approves. Open for the map: should a patch be able to mark a tool safe to run without asking?
Drafts for money and approvals. Spend's "agents draft, people submit" read well. Open for the map: should the builder skill steer that way by default?
Agents poll for now. They can loop and poll on tier 2. Pushing changes to agents waits for tier 3.
The builder needs no help. It moved itself from tier 1 to tier 2 once it found agent tools, and wrote about a dozen described tools with claims, hand-offs and dependencies.
Dev environment fixes:
localhost/127.0.0.1, so dev instances advertise their token endpoint on127.0.0.1.~/Patchy(the global skill's default) instead of the workspace. The workspace should say where to build.What this leaves out
patchy dev: publish to try a tool.docs/product.md, an amendment to ADR-0008 (a second token purpose) and the glossaries beyond auth.Screenshots
The consent page an MCP client opens:
Your machines: connect an agent, and the connection it made:
The card shows what agents can do, and its recent activity names the agent:
Agent access on the Company page:
Spend, after Codex drafted a request for Jordan:
The patch's log
Made by Claude Opus 5.5 via Claude Code (Opus 5.5 subagents built the lanes; GPT 6.1 Sol reviewed through Codex).