De-amplify contract definitions#142
Open
ymichael wants to merge 12 commits into
Open
Conversation
5a28daf to
59a2cb2
Compare
59a2cb2 to
196bc63
Compare
Owner
Author
|
Agreed. This is accurate, and I should not frame this PR as completing those two exit criteria. What this PR does finish is the structural contract de-amplification work: desktop IPC extraction, public API resource split, route descriptors, descriptor-derived public API schema, host-daemon command registry, SDK return-type derivation, and an initial boundary-defaulting pass. What it does not finish:
I’d treat both as next-slice acceptance criteria, not as completed scope for this PR. The PR should be reviewed as the enabling structure that makes those follow-up reductions cheaper, not as the final Phase 1 completion marker. |
196bc63 to
94c30f4
Compare
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.
Why this PR exists
The contract layer had become an amplifier: adding or changing one public field could require edits across the public schema, typed route registration, SDK return interfaces, handler request plumbing, daemon command maps, and desktop IPC types that were not actually served by the server. That made small API changes noisy, raised the chance of drift, and made later behavioral work pay the same churn tax repeatedly.
This PR is the structural cleanup before those behavioral phases. It reduces the number of authoritative contract definitions and moves boundary-specific contracts to the package that owns them.
Concrete before / after
Before, desktop-only IPC lived inside
@bb/server-contracteven though the server never served it. For example, the app and Electron shell importedBbDesktopApi, browser IPC schemas, version-feed types, and popout IPC contracts frompackages/server-contract/src/api-types.ts. After this PR, those contracts live in@bb/desktop-contractundersrc/browser.ts,src/info.ts,src/popout.ts, andsrc/version-feed.ts;@bb/server-contractno longer owns desktop IPC symbols.Before, a public route shape had multiple authorities: the response type lived in
api-types.ts, the route path/method lived inpublic-api.ts, typed route registration repeated the route shape in the server, and the SDK could still hand-declare a different return interface. After this PR, route descriptors colocatepath,method,request, andresponse,typedRoutesregisters from that descriptor, and SDK result types derive fromPublicApiSchemasuccess outputs. A thread route response change now flows through the descriptor-derived contract instead of a parallel SDK type universe.Before, adding a daemon command meant touching separate command unions, schema maps, result maps, command type lists, routing metadata, and flush behavior. After this PR, each command is registered once in the host-daemon command registry with its descriptor:
type,schema,resultSchema, delivery mode, retryability, flush behavior, and lane metadata. The unions and lookup maps derive from that descriptor table.Before, request defaults could leak past the API boundary. For example, automation/thread creation inputs could still carry omitted/defaulted fields into internal code, forcing service types to accept optional forms. After this PR, route handlers resolve those inputs once, then internal code receives explicit values.
What changed
@bb/desktop-contractand moved the desktop IPC surface out of@bb/server-contract, including browser, version feed, theme, and popout IPC contracts.packages/server-contract/src/api/.@bb/hono-typed-routesso each route can colocatepath,method,request, andresponseonce.Why this should be accepted
z.inferover the contract instead of handwritten interfaces.Review notes
The highest-value review path is:
packages/hono-typed-routes.packages/server-contract/src/public-api.tsand the split resource modules to confirm route descriptors preserve the old public API shape.packages/host-daemon-contract/src/commands.tsfor command registry derivations.@bb/desktop-contractwithout changing the IPC channel semantics.Validation
pnpm exec turbo run build typecheck lint test --cache-dir=.turbo/cache --output-logs=new-onlypnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/sdk --filter=@bb/clipnpm exec turbo run test --filter=@bb/sdk --filter=@bb/cli