Repository navigation
Contract: declare the tools in Swift, checked against the generated contract (#237) - #252
Merged
Merged
Conversation
…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>
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 1 of the plan in #237 (#237 (comment)). Nothing that is served changes.
native2/Sources/DesktopProtocol/ContractTools.swiftdeclares all 48 tools in Swift, in order: each tool's name, op,actionflag, 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.placeandappare parameters, as indesktopTools({ place, app }).JSONgainsExpressibleByDictionaryLiteral, which keeps keys in the order they are written, so the schemas read like the TS objects.ContractDeclarations(CoreTests) checks thatContract.listed(place: "this Mac", app: "Desktop Tools")andContract.instructions(app:)serialize to exactly whatContractText.swiftholds (the Node server's output, byte for byte). It also checks that theactionflags equal the read-only annotations.src/tools.tsmust also be made inContractTools.swift. The test fails otherwise.Most of the Swift was converted from
src/tools.tsby 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.actionsandTools.expectToolsread these declarations.ContractText.swiftandscripts/contract.mjsgo, and/toolsis generated from Swift.🤖 Generated with Claude Code