Skip to content

Contract: declare the tools in Swift, checked against the generated contract (#237) - #252

Merged
iamnbutler merged 3 commits into
mainfrom
contract-swift-port
Nov 13, 2026
Merged

iamnbutler merged 3 commits into
mainfrom
contract-swift-port

Conversation

@iamnbutler

Copy link
Copy Markdown
Contributor

Step 1 of the plan in #237 (#237 (comment)). Nothing that is served changes.

  • native2/Sources/DesktopProtocol/ContractTools.swift declares all 48 tools in Swift, in order: each tool's name, op, action flag, description and schema. It also has the shared rules (Contract.rules(app:)), the server instructions (Contract.instructions(app:)), the limits, and the key and wait-condition lists. place and app are parameters, as in desktopTools({ place, app }).
  • JSON gains ExpressibleByDictionaryLiteral, which keeps keys in the order they are written, so the schemas read like the TS objects.
  • ContractDeclarations (CoreTests) checks that Contract.listed(place: "this Mac", app: "Desktop Tools") and Contract.instructions(app:) serialize to exactly what ContractText.swift holds (the Node server's output, byte for byte). It also checks that the action flags equal the read-only annotations.
  • AGENTS.md and native2/README.md say that, until the next PR flips the source, a change to src/tools.ts must also be made in ContractTools.swift. The test fails otherwise.

Most of the Swift was converted from src/tools.ts by a throwaway tokenizer, so the description text wasn't retyped. The byte-equality test is the check on it.

Checks run: swift test --package-path native2 (all pass, including the new suite), npm run check, npm test, node scripts/contract.mjs --check.

Next (after this merges): the server, Contract.actions and Tools.expectTools read these declarations. ContractText.swift and scripts/contract.mjs go, and /tools is generated from Swift.

🤖 Generated with Claude Code

iamnbutler and others added 3 commits November 12, 2026 20:08
…ontract (#237)

First step of moving the tool contract out of TypeScript. ContractTools.swift declares every tool's description,
schema and action flag, the shared rules and the server instructions, as src/tools.ts and src/mcp.ts build them.
Nothing serves them yet: a CoreTests suite checks they serialize to exactly ContractText.swift, which still comes
from the Node server. JSON gains dictionary literals, which keep their written order.

Why: native2/Sources/DesktopProtocol/ContractTools.swift | until the server serves these declarations (#237), every change to src/tools.ts must be made here too; ContractDeclarations in CoreTests fails when they differ from ContractText.swift

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamnbutler
iamnbutler merged commit 674fbed into main Nov 13, 2026
2 checks passed
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