Repository navigation
Contract: serve the Swift declarations, and generate /tools from them (#237) - #253
Merged
Merged
Conversation
…#237) The tool contract's source moves from src/tools.ts into native2's ContractTools.swift. The MCP server, the host's action and expect sets read the declarations; ContractText.swift and the Node-to-Swift generation go. desktop-tools-mcp --contract exports the declarations with {{place}} and {{app}} marking what embedders name, and scripts/contract.mjs (npm run contract) writes that into src/contract.ts, which /tools and /protocol's key and wait-condition lists read. CI checks it on the macOS job. The /tools and /protocol exports are the same values as before, except DESKTOP_EXPECT_OPS's order; desktopRequest leaves the exclusive argument forms to the host, which refuses them with the same text. Type assertions keep the hand-written request types' ops and actions equal to the declared tools'. Why: native2/Sources/DesktopProtocol/ContractTools.swift | src/contract.ts is generated from this file by npm run contract; CI's native job fails when it is stale, so regenerate after every change here Why: src/protocol.ts | DesktopRequest and DesktopAction are hand-written but must name exactly the declared tools' ops and actions; the Assert types make tsc fail when they drift Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Step 2 of the plan in #237 (#237 (comment)). The tool contract's source moves from
src/tools.tsinto Swift.Swift
Contractreads the declarations inContractTools.swift(from Contract: declare the tools in Swift, checked against the generated contract (#237) #252).ContractText.swiftis deleted.Contract.actions, which the MCP server's queue,AdmissionandHooksuse, comes from each tool'sactionflag.Tools.expectToolsbecomesContract.expecting: the tools whose schema takesexpect. Addingexpectto a tool is now one change.Tools.actionTools(bad argument → refused action) stays hand-written. It deliberately differs fromContract.actions, and a comment now names how.desktop-tools-mcp --contractprints the declarations as JSON, with{{place}}and{{app}}marking what embedders name.npm package
scripts/contract.mjs(npm run contract) buildsdesktop-tools-mcp, runs it with--contract, and writessrc/contract.ts.--checkfails when the file is stale. CI moves that check to the macOS job, since it needs Swift.src/tools.tsis now a thin wrapper overcontract.ts, with the same exports./protocol'sDESKTOP_KEYS,DESKTOP_SYSTEM_KEYS,DESKTOP_WAIT_CONDITIONS,DESKTOP_EXPECT_OPSandisDesktopActioncome from it too.tscfail if the hand-writtenDesktopRequestops orDesktopActionops drift from the declared tools. Checked by removing"dock"fromDesktopAction.desktopRequestno longer checks the exclusive forms ofdesktop_clipboard_writeanddesktop_dialog_answer. The host refuses them with the same text (TextClipboard.swift,Dialogs.swift). The user approved this in Remove Node from the MCP path: make the app's Swift server the only server and the contract's source #237.Verified to be the same as before
initializeinstructions andtools/listequal main'sContractText.swiftexactly./toolsand/protocolexport (desktopToolsforthis Mac/Desktop Toolsand for Ace's place and app,desktopToolRules, every constant,isDesktopActionandisDesktopManagementfor every op) is identical to main's dist output. The one exception is thatDESKTOP_EXPECT_OPSnow lists its ops in tool order.Checks run:
swift test --package-path native2(all pass),npm run check,npm test,node scripts/contract.mjs --check.Docs: AGENTS.md, native2/README.md, docs/tools.md, docs/mcp.md, CHANGELOG (Unreleased). Lane notes on
src/tools.tsandsrc/mcp.tsare replaced or retired.🤖 Generated with Claude Code