Skip to content

Commit ee150ed

Browse files
Gate 7 Terminal operational readiness
1 parent 4687972 commit ee150ed

19 files changed

Lines changed: 1129 additions & 13 deletions

BITCODE_SPEC_V28.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,24 @@ Acceptance criteria:
713713
they satisfy the same typed envelope, telemetry, and fail-closed contracts as
714714
the live Reading pipelines.
715715

716+
Implementation evidence:
717+
718+
- `packages/btd/src/terminal-operational-health.ts` is the canonical package
719+
adapter for Terminal operational health. It builds the displayed lane,
720+
telemetry, upgrade, provider, settlement-network, synthetic testnet minting,
721+
Terminal journal, ledger anchor, and ledger/database reconciliation read
722+
from BTD primitives rather than a UI-only fixture.
723+
- `uapi/app/terminal/TerminalOperationalHealthPanel.tsx` renders that package
724+
read in Terminal. It keeps all six lanes visible, blocks value-bearing
725+
mainnet without an operational approval root, exposes broadcaster/observer
726+
severity, displays rollback/migration/generated-type refresh posture, shows
727+
GitHub as the active VCS path, and marks BSC/opBNB/Binance Web3 Wallet pilots
728+
disabled.
729+
- Gate 7 implementation tests are
730+
`packages/btd/__tests__/terminal-operational-health.test.ts` and
731+
`uapi/tests/terminalOperationalHealthPanel.test.tsx`; package-level BTD tests
732+
are runnable through `pnpm -C packages/btd test`.
733+
716734
### Gate 8: V28 Promotion Proof
717735

718736
Purpose:

BITCODE_SPEC_V28_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ The minimum useful V28 gate plan is Protocol/Terminal-MVP-first:
512512
7. **Gate 7: Terminal Operations And Testnet Readiness**
513513
- Regtest/signet harness, telemetry sinks, alert panels, upgrade readiness, and rollback posture become Terminal-operated.
514514
- Taproot/PSBT/BTC remains the V28 crypto lane; BSC/opBNB/Binance/BitVM bridge work is future bridge/distribution readiness unless proof-bound artifacts exist.
515+
- Terminal operational health now reads from package BTD primitives through
516+
`terminal-operational-health.ts`, then renders lane approval, telemetry,
517+
upgrade, generated type refresh, VCS, settlement-network, and synthetic
518+
testnet mint/reconciliation state in Terminal.
515519
- Reading pipeline test coverage becomes a gate contract: Read-Need,
516520
Need-Fit, depository search, embedding/vector search, sandbox harness,
517521
route preflight, Terminal stream adaptation, and demonstration local

BITCODE_SPEC_V28_PARITY_MATRIX.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,17 @@ It links manual screenshots, console logs, server logs, Supabase SQL checks, and
154154
| ChatGPT App authorization based on range/read-license/policy truth | ChatGPT App MVP parity must use the same registry-derived access posture as MCP and Terminal; retained in V28 MVP scope. | not yet implemented | Gate 6 |
155155
| Deterministic model posture for ledgerized synthesis | `uapi/app/auxillaries/components/AuxillariesInterfacesPane.tsx` and `uapi/app/auxillaries/components/models/GlobalModelSelection.tsx` still expose broad user-driven model preferences; V28 SPEC now forbids user-selected models for Fit, AssetPack, semantic measurement, measuremint, proof, journal, and settlement paths. Remove, hide, or scope model selection to non-ledgerized conversation UX before promotion. | not yet implemented | Gate 3 / Gate 8 |
156156
| access-policy legal templates | policy id/hash exists; full templates not complete | pending | Gate 6 |
157-
| deployment lanes and telemetry surfaced in Terminal | `deployment-lanes.ts`, `telemetry.ts`, deployment-readiness route | implemented prerequisite | Gate 7 |
158-
| migration/type refresh visible as readiness | V27 migrations and dashboard RLS migration are applied/aligned in staging Supabase; generated type refresh is deferred. | substantially advanced | Gate 7 |
159-
| GitHub-only provider readiness disclosed | `internal-docs/INTEGRATIONS.md` shows GitHub implemented and broader providers incomplete | implemented prerequisite | Gate 7 |
160-
| BTD-AssetPack testnet minting and ledgerized synthetic measurement | V27 package primitives exist for measuremint, range, receipts, ledger anchors, Terminal journal, and reconciliation. V28 must prove realistic testnet or testnet-readiness flow with synthetic measurement, BTD-AssetPack mint/read state, journal rows, ledger anchors or blocked ledger readiness, and projection/reconciliation readback. | substantially advanced | Gate 3 / Gate 5 / Gate 7 |
161-
| Taproot/BNB/Binance research posture | current V28 sources center Bitcoin wallet/PSBT/Taproot-compatible providers; no BSC/opBNB/BEP-20/Binance Web3 Wallet BTD deployment artifact is bound. V28 documents Bitcoin/Taproot-first testnet posture and records BSC/opBNB/Binance/BitVM bridge pilots as future bridge/distribution work unless proof-bound artifacts are added. | accepted boundary | Gate 7 / V36+ |
157+
| deployment lanes and telemetry surfaced in Terminal | `packages/btd/src/terminal-operational-health.ts`, `deployment-lanes.ts`, `telemetry.ts`, `uapi/app/terminal/TerminalOperationalHealthPanel.tsx`, `uapi/tests/terminalOperationalHealthPanel.test.tsx` | implemented | Gate 7 |
158+
| migration/type refresh visible as readiness | `terminal-operational-health.ts` builds upgrade readiness from `upgrade.ts` and exposes migration root, rollback root, approval root, and generated type refresh posture in Terminal. | implemented | Gate 7 |
159+
| GitHub-only provider readiness disclosed | `terminal-operational-health.ts` marks GitHub ready and GitLab, Bitbucket, generic Git future-scoped for Terminal Reading; Terminal renders the provider states. | implemented | Gate 7 |
160+
| BTD-AssetPack testnet minting and ledgerized synthetic measurement | `terminal-operational-health.ts` builds a synthetic testnet AssetPack readback using measuremint, range allocation, mint receipt, Terminal journal rows, Bitcoin Taproot ledger anchor, observed/projected ledger facts, and reconciliation; `packages/btd/__tests__/terminal-operational-health.test.ts` proves diff/repair shape. | implemented | Gate 3 / Gate 5 / Gate 7 |
161+
| Taproot/BNB/Binance research posture | Terminal operational health marks Bitcoin Taproot/PSBT ready and BSC, opBNB, and Binance Web3 Wallet disabled until a later Protocol gate admits proof-bound artifacts. | accepted boundary | Gate 7 / V36+ |
162162

163163
## V28 implementation checklist
164164

165165
| Area | Required V28 result | Judgment |
166166
| --- | --- | --- |
167+
| Terminal operations | lane approval posture, broadcaster/observer telemetry, upgrade/migration/generated-type refresh, GitHub-only VCS posture, Bitcoin Taproot/PSBT readiness, disabled Binance-family pilots, and synthetic testnet mint/read reconciliation are rendered from package primitives | implemented |
167168
| Draft family | SPEC, DELTA, NOTES, PARITY exist | closed |
168169
| Canon posture | V27 active / V28 draft in source posture carriers | closed |
169170
| Routes | unversioned UAPI route scan passes | closed |
@@ -179,7 +180,6 @@ It links manual screenshots, console logs, server logs, Supabase SQL checks, and
179180
| Terminal Read/Fit | Read, Fit, semantic volume, measuremint, policy UX | pending |
180181
| Terminal range/read | AssetPack range and read-right detail | pending |
181182
| Terminal journal/reconcile | selected transaction Journal section separates ledger observations, database projections, canonical roots, repair receipts, and blocking drift reasons | substantially advanced |
182-
| Terminal operations | telemetry, lanes, upgrade, migration readiness | pending |
183183

184184
## Later-Version Deferrals
185185

packages/btd/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ This package owns:
1111
- contributor allocation, access evaluation, ancestry review, and revenue routing
1212
- wallet-signed BTC fee receipts, ledger anchors, Exchange rights transfers,
1313
Terminal journals, reconciliation, telemetry, and upgrade receipts
14+
- Terminal operational health reads that compose deployment lanes, telemetry,
15+
upgrade posture, provider readiness, settlement-network posture, synthetic
16+
testnet minting, journal rows, ledger anchors, and reconciliation state
1417

1518
`$BTD` is not a fungible fee token. BTC pays fees. `$BTD` represents a
1619
non-fungible AssetPack share/read-right and the measured Bitcode amount in
@@ -34,3 +37,10 @@ import {
3437
readBtdHoldings,
3538
} from '@bitcode/btd';
3639
```
40+
41+
Terminal should consume the operational-health subpath when it needs the
42+
client-safe read model without importing storage-backed package entry points:
43+
44+
```ts
45+
import { buildTerminalOperationalHealthRead } from '@bitcode/btd/terminal-operational-health';
46+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const supabaseAdmin = {
2+
from: jest.fn(() => {
3+
const query = {
4+
select: jest.fn(),
5+
eq: jest.fn(),
6+
maybeSingle: jest.fn().mockResolvedValue({ data: null, error: null }),
7+
};
8+
query.select.mockImplementation(() => query);
9+
query.eq.mockImplementation(() => query);
10+
return query;
11+
}),
12+
};
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import {
2+
aggregateTerminalOperationalTelemetrySeverity,
3+
buildTerminalOperationalHealthRead,
4+
} from '../src/terminal-operational-health';
5+
import { buildV27CryptoTelemetryRecord } from '../src/telemetry';
6+
7+
const issuedAt = 'terminal-operational-health-test';
8+
9+
describe('Terminal operational health read', () => {
10+
it('surfaces all deployment lanes and blocks value-bearing mainnet without approval root', () => {
11+
const read = buildTerminalOperationalHealthRead({ issuedAt });
12+
13+
expect(read.lanes.map((lane) => lane.lane)).toEqual([
14+
'local',
15+
'regtest',
16+
'signet',
17+
'testnet',
18+
'mainnet-ready',
19+
'mainnet-value-bearing',
20+
]);
21+
expect(read.lanes.find((lane) => lane.lane === 'testnet')).toMatchObject({
22+
label: 'Public testnet',
23+
state: 'ready',
24+
bitcoinNetwork: 'testnet',
25+
});
26+
expect(read.lanes.find((lane) => lane.lane === 'mainnet-value-bearing')).toMatchObject({
27+
state: 'blocked',
28+
valueBearing: true,
29+
operationalApprovalRoot: null,
30+
missingEnvironmentKeys: ['BITCODE_OPERATIONAL_APPROVAL_ROOT'],
31+
readinessReceipt: null,
32+
});
33+
});
34+
35+
it('admits value-bearing mainnet only when an operational approval root is present', () => {
36+
const read = buildTerminalOperationalHealthRead({
37+
issuedAt,
38+
operationalApprovalRoots: {
39+
'mainnet-value-bearing': 'approval-root',
40+
},
41+
});
42+
const mainnetValueLane = read.lanes.find((lane) => lane.lane === 'mainnet-value-bearing');
43+
44+
expect(mainnetValueLane).toMatchObject({
45+
state: 'ready',
46+
operationalApprovalRoot: 'approval-root',
47+
valueBearing: true,
48+
});
49+
expect(mainnetValueLane?.readinessReceipt?.mainnetValueBearingBlocked).toBe(false);
50+
});
51+
52+
it('aggregates telemetry into broadcaster and observer health', () => {
53+
const telemetryRecords = [
54+
buildV27CryptoTelemetryRecord({
55+
event: 'btc_fee.broadcast_rejected',
56+
subjectId: 'fee-1',
57+
issuedAt,
58+
}),
59+
buildV27CryptoTelemetryRecord({
60+
event: 'ledger_provider.disagreement',
61+
subjectId: 'anchor-1',
62+
issuedAt,
63+
}),
64+
];
65+
const read = buildTerminalOperationalHealthRead({ issuedAt, telemetryRecords });
66+
67+
expect(aggregateTerminalOperationalTelemetrySeverity(telemetryRecords)).toBe('critical');
68+
expect(read.telemetry.severity).toBe('critical');
69+
expect(read.broadcaster).toMatchObject({
70+
state: 'review',
71+
severity: 'warning',
72+
});
73+
expect(read.observer).toMatchObject({
74+
state: 'blocked',
75+
severity: 'critical',
76+
});
77+
});
78+
79+
it('keeps upgrade, rollback, migration, and generated type refresh visible', () => {
80+
const read = buildTerminalOperationalHealthRead({
81+
issuedAt,
82+
rollbackPlanRoot: 'rollback-root',
83+
generatedTypeRefreshState: 'current',
84+
});
85+
86+
expect(read.upgrade).toMatchObject({
87+
state: 'planned',
88+
migrationRoot: 'terminal-migration-root',
89+
rollbackPlanRoot: 'rollback-root',
90+
approvalReceiptRoot: 'terminal-approval-root',
91+
generatedTypeRefresh: {
92+
state: 'current',
93+
source: 'packages/orm/src/types/database.generated.ts',
94+
},
95+
});
96+
expect(read.upgrade.receipt.kind).toBe('btd.protocol_upgrade');
97+
});
98+
99+
it('declares GitHub as the active VCS path and leaves broader providers future-scoped', () => {
100+
const read = buildTerminalOperationalHealthRead({ issuedAt });
101+
102+
expect(read.providers).toEqual(
103+
expect.arrayContaining([
104+
expect.objectContaining({ provider: 'github', state: 'ready' }),
105+
expect.objectContaining({ provider: 'gitlab', state: 'future' }),
106+
expect.objectContaining({ provider: 'bitbucket', state: 'future' }),
107+
expect.objectContaining({ provider: 'generic-git', state: 'future' }),
108+
]),
109+
);
110+
});
111+
112+
it('uses Bitcoin Taproot/PSBT as first-class and keeps Binance-family pilots disabled', () => {
113+
const read = buildTerminalOperationalHealthRead({ issuedAt });
114+
115+
expect(read.settlementNetworks).toEqual(
116+
expect.arrayContaining([
117+
expect.objectContaining({ id: 'bitcoin-taproot-psbt', state: 'ready' }),
118+
expect.objectContaining({ id: 'bsc', state: 'disabled' }),
119+
expect.objectContaining({ id: 'opbnb', state: 'disabled' }),
120+
expect.objectContaining({ id: 'binance-web3-wallet', state: 'disabled' }),
121+
]),
122+
);
123+
});
124+
125+
it('builds a synthetic testnet minting readback that can be ledger/database diffed', () => {
126+
const read = buildTerminalOperationalHealthRead({ issuedAt });
127+
128+
expect(read.testnetMinting.measurementReceipt.kind).toBe('btd.measure_mint');
129+
expect(read.testnetMinting.measurementReceipt.tokenCount).toBe(1);
130+
expect(read.testnetMinting.mintReceipt.kind).toBe('btd.asset_pack_mint');
131+
expect(read.testnetMinting.assetPackRange.tokenCount).toBe(1);
132+
expect(read.testnetMinting.ledgerAnchor).toMatchObject({
133+
chain: 'bitcoin',
134+
network: 'signet',
135+
commitmentMethod: 'taproot',
136+
finalityState: 'prepared',
137+
});
138+
expect(read.testnetMinting.terminalJournalRows.map((row) => row.transactionKind)).toEqual([
139+
'asset_pack_mint',
140+
'asset_pack_anchor',
141+
]);
142+
expect(read.testnetMinting.terminalJournalDiff.blocking).toBe(false);
143+
expect(read.testnetMinting.ledgerDatabaseReconciliation.blocking).toBe(false);
144+
expect(read.testnetMinting.ledgerObservedFacts).toEqual(read.testnetMinting.databaseProjectedFacts.map((fact) => ({
145+
factId: fact.factId,
146+
ledgerRoot: fact.projectedLedgerRoot,
147+
finalityState: fact.projectedFinalityState,
148+
})));
149+
});
150+
});

packages/btd/__tests__/v27-crypto-primitives.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ describe('V27 Terminal journal and ledger/database reconciliation primitives', (
15121512
metaphysicalFacts: [
15131513
{
15141514
factId: 'public-private-fact',
1515-
factKind: 'read_fit_context',
1515+
factKind: 'need_fit_context',
15161516
canonicalRoot: 'root',
15171517
private: false,
15181518
},

packages/btd/jest.config.cjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/__tests__'],
5+
testMatch: ['<rootDir>/__tests__/**/*.test.ts'],
6+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7+
transform: {
8+
'^.+\\.[jt]sx?$': ['ts-jest', {
9+
tsconfig: {
10+
target: 'ES2020',
11+
module: 'CommonJS',
12+
esModuleInterop: true,
13+
skipLibCheck: true,
14+
},
15+
}],
16+
},
17+
moduleNameMapper: {
18+
'^@bitcode/models/src/(.+)$': '<rootDir>/../models/src/$1',
19+
'^@bitcode/supabase$': '<rootDir>/__tests__/mocks/supabase.ts',
20+
},
21+
};

packages/btd/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@
44
"private": true,
55
"main": "src/index.ts",
66
"types": "src/index.ts",
7+
"exports": {
8+
".": "./src/index.ts",
9+
"./terminal-operational-health": "./src/terminal-operational-health.ts"
10+
},
11+
"scripts": {
12+
"test": "jest --config jest.config.cjs --runInBand"
13+
},
714
"dependencies": {
815
"@bitcode/models": "workspace:*",
916
"@bitcode/supabase": "workspace:*"
17+
},
18+
"devDependencies": {
19+
"@types/jest": "^29.0.0",
20+
"@types/node": "^20.0.0",
21+
"jest": "^29.0.0",
22+
"ts-jest": "^29.0.0",
23+
"typescript": "^5.0.0"
1024
}
1125
}

0 commit comments

Comments
 (0)