Skip to content

Commit 161df58

Browse files
Merge pull request #34 from engineeredsoftware/v30/gate-2-protocol-package-api-boundaries
V30 Gate 2: Protocol Package API Boundaries
2 parents 6f7fd74 + b452e2a commit 161df58

14 files changed

Lines changed: 2088 additions & 1515 deletions

.github/workflows/bitcode-gate-quality.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
node scripts/check-bitcode-canon-posture-drift.mjs --active-canon V29 --draft-target V30
8181
node scripts/check-v29-gate10-local-staging-promotion-readiness.mjs --promotion-mode --skip-branch-check
8282
node scripts/check-v30-gate1-roadmap-and-gating.mjs --skip-branch-check
83+
node scripts/check-v30-gate2-protocol-package-api-boundaries.mjs --skip-branch-check
8384
else
8485
echo "Unexpected BITCODE_SPEC.txt pointer: $POINTER" >&2
8586
exit 1

BITCODE_SPEC_V30_DELTA.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ Closure acceptance:
9393
- no commercial runtime code imports `protocol-demonstration/src/*`;
9494
- package READMEs name ownership boundaries and accepted imports.
9595

96+
Gate 2 implementation centers the currently shared BTD route objects in
97+
`packages/btd/src/api-boundaries.ts`. API routes may authenticate, parse request
98+
bodies, resolve registry projections, commit explicit persistence writes, and
99+
serialize responses, but BTD mint drafts, registry snapshots, read-access
100+
decisions, BTC-fee settlements, ledger anchors, Exchange settlements, Terminal
101+
journal settlements, reconciliation settlements, deployment-readiness receipts,
102+
BigInt parsing, and JSON-safe conversion are package-owned.
103+
104+
The package boundary is proven by `packages/btd/__tests__/api-boundaries.test.ts`,
105+
`packages/api/src/routes/__tests__/btd-crypto.test.ts`, and
106+
`scripts/check-v30-gate2-protocol-package-api-boundaries.mjs`.
107+
96108
### Gate 3: Bitcoin Taproot PSBT Fee Rigor
97109

98110
Gate 3 hardens Bitcoin fee and signer semantics.

BITCODE_SPEC_V30_NOTES.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ V30 owns Protocol/BTD hardening:
6868
- Narrow package APIs for shared Protocol/BTD objects used by API, Terminal, MCP, ChatGPT App, and future Auxillaries/Exchange work.
6969
- Require package-owned builders, validators, parsers, tests, and JSON-safe serialization before cross-interface use.
7070

71+
## Gate 2 protocol package API boundary notes
72+
73+
Gate 2 moves reusable BTD route-facing construction into
74+
`packages/btd/src/api-boundaries.ts`. `packages/api/src/routes/btd-crypto.ts`
75+
remains the route owner: it authenticates requests, parses request bodies,
76+
resolves registry projections, commits explicit persistence writes, and returns
77+
JSON responses. It no longer owns BTD mint draft admission, registry snapshot
78+
construction, read-access policy derivation, BTC-fee settlement receipts,
79+
AssetPack ledger anchors, Exchange settlement receipts, Terminal journal
80+
settlements, reconciliation reports, deployment-readiness receipts, BigInt
81+
parsing, or JSON-safe conversion.
82+
83+
The package test `packages/btd/__tests__/api-boundaries.test.ts` is the local
84+
contract for package-owned builders/parsers/serialization. The API route test
85+
imports those builders from `@bitcode/btd` and keeps route-handler coverage in
86+
the API package. `pnpm run check:v30-gate2` closes the gate by checking this
87+
seam, package README ownership language, and commercial runtime avoidance of
88+
standalone demonstration imports.
89+
7190
3. **Gate 3: Bitcoin Taproot PSBT Fee Rigor**
7291
- Harden BTC fee quote, signer recovery, PSBT, Taproot/script posture, broadcast, replacement, reorg, finality, and testnet/mainnet boundaries.
7392

BITCODE_SPEC_V30_PARITY_MATRIX.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ No `_legacy/` source is active source truth.
5555
| --- | --- | --- | --- | --- |
5656
| Draft family and branch posture | Gate 1 | `BITCODE_SPEC_V30.md`, DELTA, NOTES, PARITY, `BITCODE_SPEC.txt`, branch `v30/gate-1-roadmap-and-gating` | drafted | V30 family validates in draft mode over active V29 and `check:v30-gate1` passes. |
5757
| Roadmap truth | Gate 1 | `SPECIFICATIONS_ROADMAP.md`, README, PR template, workflow posture | drafted | Roadmap states V29 active, V30 draft, and coherent V31-V37 responsibilities. |
58-
| Protocol package API boundaries | Gate 2 | `packages/protocol`, `packages/btd`, `packages/api`, package READMEs/tests | pending | Shared Protocol/BTD objects have package-owned builders, parsers, validators, JSON-safe serializers, and tests. |
58+
| Protocol package API boundaries | Gate 2 | `packages/btd/src/api-boundaries.ts`, `packages/api/src/routes/btd-crypto.ts`, package READMEs/tests | drafted | Shared Protocol/BTD objects have package-owned builders, parsers, validators, JSON-safe serializers, and tests. |
5959
| Bitcoin Taproot PSBT fee rigor | Gate 3 | BTD fee/signer/PSBT primitives, API route adapters, tests | pending | BTC fee and signer states are typed, testnet/mainnet-safe, no-custody, and proof-rooted. |
6060
| BTD AssetPack mint/read receipts | Gate 4 | BTD receipt primitives, asset-pack postprocess, harness evidence, Terminal/API readback | pending | Mint, read, and rights-transfer receipts bind BTD range, preview, paid unlock, delivery, and ledger projection. |
6161
| Testnet ledger projection hardening | Gate 5 | BTD reconciliation, Supabase readback, object-storage evidence, repair tests | pending | Ledger/database/object-storage projections are synchronized or blocked with deterministic repair posture. |
@@ -93,6 +93,25 @@ No `_legacy/` source is active source truth.
9393

9494
- Gate 1 does not implement Protocol/BTD package hardening.
9595
- Gate 1 does not create `BITCODE_SPEC_V30_PROVEN.md`.
96+
97+
## Gate 2 Parity
98+
99+
| Requirement | Source evidence | Current V30 judgment |
100+
| --- | --- | --- |
101+
| Package-owned BTD builders and parsers exist | `packages/btd/src/api-boundaries.ts` exports mint, registry, read-access, fee, ledger-anchor, Exchange, journal, reconciliation, deployment-readiness builders plus `parseBtdRequiredBigInt`, `parseBtdOptionalBigInt`, and `toBtdJsonSafe` | drafted |
102+
| API route delegates BTD policy and receipt derivation | `packages/api/src/routes/btd-crypto.ts` imports package builders from `@bitcode/btd` and keeps route code scoped to auth, request parsing, registry projection reads/writes, and responses | drafted |
103+
| Package tests cover the boundary | `packages/btd/__tests__/api-boundaries.test.ts` proves mint drafts, registry snapshots, read-access decisions, parsers, and JSON-safe serialization | drafted |
104+
| Route tests consume package-owned builders | `packages/api/src/routes/__tests__/btd-crypto.test.ts` imports BTD builders from `@bitcode/btd` and route handlers from the API route module | drafted |
105+
| Commercial runtime avoids standalone demonstration imports | `scripts/check-v30-gate2-protocol-package-api-boundaries.mjs` scans runtime source import statements for `protocol-demonstration/src` and `@bitcode/protocol-demonstration` | drafted |
106+
| Package READMEs state accepted imports | `packages/btd/README.md`, `packages/api/README.md`, and `packages/protocol/README.md` name package ownership and accepted import direction | drafted |
107+
| Gate checker protects the seam | `pnpm run check:v30-gate2` and gate-quality workflow call `scripts/check-v30-gate2-protocol-package-api-boundaries.mjs` | drafted |
108+
109+
## Gate 2 accepted boundaries
110+
111+
- Gate 2 does not change the active canon pointer.
112+
- Gate 2 does not introduce bridge chain-of-record behavior.
113+
- Gate 2 does not admit value-bearing mainnet settlement.
114+
- Gate 2 does not remove existing API route persistence adapters; it narrows their policy and receipt derivation responsibilities to package calls.
96115
- Gate 1 does not promote `BITCODE_SPEC.txt` to V30.
97116
- Gate 1 may retarget workflows to active V29 / draft V30 so later gates are greenable.
98117
- Gate 1 may update roadmap scope for V31-V37 to align with V28/V29 promotion learning without opening those versions.

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ and commit promotion artifacts plus the `BITCODE_SPEC.txt` pointer change from
6969
`V29` to `V30` on the version branch.
7070
Gate 10 is the local/staging promotion-readiness gate; run the V30 Gate 10
7171
checker before opening the final gate PR. V30 Gate 1 wires the first checker as
72-
`pnpm run check:v30-gate1`.
72+
`pnpm run check:v30-gate1`. V30 Gate 2 wires the Protocol/BTD package boundary
73+
checker as `pnpm run check:v30-gate2`; shared BTD objects consumed by API,
74+
Terminal, MCP, ChatGPT App, Auxillaries, or Exchange must be built, parsed,
75+
validated, and JSON-serialized by package owners before route or interface code
76+
uses them.
7377
The promoted V29 closure remains reproducible through `pnpm run check:v29-gate10`
7478
and [v29-canon-promotion.yml](.github/workflows/v29-canon-promotion.yml).
7579
The application CI workflow uses the root pnpm workspace install, runs uapi

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"check:v29-gate9": "node scripts/check-v29-gate9-terminal-ux-browser-proof.mjs",
5656
"check:v29-gate10": "node scripts/check-v29-gate10-local-staging-promotion-readiness.mjs",
5757
"check:v30-gate1": "node scripts/check-v30-gate1-roadmap-and-gating.mjs",
58+
"check:v30-gate2": "node scripts/check-v30-gate2-protocol-package-api-boundaries.mjs",
5859
"check:spec-quality": "node scripts/run-bitcode-spec-quality.mjs --mode basic",
5960
"check:spec-quality:title": "node scripts/run-bitcode-spec-quality.mjs --mode strict-from-title",
6061
"check:spec-quality:v24": "node scripts/run-bitcode-spec-quality.mjs --mode strict-version --version V24",

packages/api/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ Unified Bitcode API orchestration layer. This package owns route-level request l
66

77
Interface-owned route bindings such as `uapi/app/api/*` should stay thin. They import formal route handlers from `packages/api` entry modules such as `@bitcode/api/src/routes/*`, while those handlers import narrower functionality from the appropriate subsystem packages.
88

9+
For BTD routes, the accepted import direction is route code importing
10+
package-owned builders, parsers, validators, and JSON serializers from
11+
`@bitcode/btd`. The route-owned behavior is limited to authentication, request body
12+
parsing, registry projection reads, explicit persistence commits, response
13+
status decisions, and framework-compatible response serialization. Route code
14+
must not duplicate BTD policy, mint admission, receipt derivation, settlement
15+
state construction, or JSON-safe conversion already exported by `@bitcode/btd`.
16+
917
In V26 fourth-gate this package is where merged-world Bitcode becomes concrete:
1018
- `/conversations` continuity
1119
- `/executions` compatibility and pipeline-run APIs

packages/api/src/routes/__tests__/btd-crypto.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jest.mock(
1414
);
1515

1616
import {
17+
advanceBtcFeeQuote,
1718
buildBtdAncestryReviewSettlement,
1819
buildBtdAssetPackLedgerAnchorSettlement,
1920
buildBtdAssetPackExchangeSettlement,
@@ -25,6 +26,10 @@ import {
2526
buildBtdOrganizationInterfaceAuthorityDecision,
2627
buildBtdReadAccessDecision,
2728
buildBtdTerminalJournalSettlement,
29+
buildBtcFeeQuote,
30+
createBtdMeasureMintState,
31+
} from '@bitcode/btd';
32+
import {
2833
buildGetBtdRegistrySnapshotRoute,
2934
buildPostBtdAncestryReviewRoute,
3035
buildPostBtdAssetPackLedgerAnchorRoute,
@@ -38,11 +43,6 @@ import {
3843
buildPostBtdReadAccessRoute,
3944
buildPostBtdTerminalJournalRoute,
4045
} from '../btd-crypto';
41-
import {
42-
advanceBtcFeeQuote,
43-
buildBtcFeeQuote,
44-
createBtdMeasureMintState,
45-
} from '@bitcode/btd';
4646

4747
const issuedAt = '2026-05-06T00:00:00.000Z';
4848

@@ -215,7 +215,7 @@ describe('BTD crypto API builders', () => {
215215
const body = await response.json();
216216

217217
expect(response.status).toBe(400);
218-
expect(body.error).toBe('V27 BTD mint draft requires accepted Read.');
218+
expect(body.error).toBe('BTD mint draft requires accepted Read.');
219219
});
220220

221221
it('fails mint drafts closed when Fit admission is absent', async () => {
@@ -231,7 +231,7 @@ describe('BTD crypto API builders', () => {
231231
const body = await response.json();
232232

233233
expect(response.status).toBe(400);
234-
expect(body.error).toBe('V27 BTD mint draft requires accepted Fit.');
234+
expect(body.error).toBe('BTD mint draft requires accepted Finding Fits result.');
235235
});
236236

237237
it('fails mint drafts closed when uncommitted proof inputs are missing', async () => {
@@ -263,7 +263,7 @@ describe('BTD crypto API builders', () => {
263263
const body = await response.json();
264264

265265
expect(response.status).toBe(400);
266-
expect(body.error).toBe('V27 BTD mint draft requires a positive Exchange sequence.');
266+
expect(body.error).toBe('BTD mint draft requires a positive Exchange sequence.');
267267
});
268268

269269
it('builds read-access decisions without merging owner-read and licensed-read rights', () => {

0 commit comments

Comments
 (0)