@quantiya/codevibe-core 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/prompt-parser.test.d.ts +1 -0
- package/dist/adapter/registry.d.ts +69 -2
- package/dist/appsync/__tests__/appsync-client-event-source-filter.test.d.ts +1 -0
- package/dist/appsync/__tests__/appsync-client-task-group.test.d.ts +1 -0
- package/dist/appsync/__tests__/cleanup-subscription.test.d.ts +1 -0
- package/dist/appsync/__tests__/coerce-awsjson-and-review-summary.test.d.ts +1 -0
- package/dist/appsync/__tests__/cp1f-quorum-sdk.test.d.ts +1 -0
- package/dist/appsync/__tests__/event-throttle.test.d.ts +1 -0
- package/dist/appsync/appsync-client.d.ts +621 -10
- package/dist/appsync/event-throttle.d.ts +28 -0
- package/dist/appsync/index.d.ts +3 -0
- package/dist/appsync/queries.d.ts +19 -0
- package/dist/audit-keys/index.d.ts +32 -0
- package/dist/auth/auth-service.d.ts +32 -2
- package/dist/auth/auth-telemetry.d.ts +19 -1
- package/dist/auth/index.d.ts +1 -0
- package/dist/companion-mode/__tests__/detect-parallel.test.d.ts +1 -0
- package/dist/companion-mode/index.d.ts +4 -3
- package/dist/companion-mode/persist-preference.d.ts +1 -1
- package/dist/config/config.d.ts +8 -1
- package/dist/continuation/__tests__/dirty-state-collector.test.d.ts +1 -0
- package/dist/continuation/__tests__/integration.test.d.ts +1 -0
- package/dist/continuation/__tests__/packet-reader.test.d.ts +1 -0
- package/dist/continuation/__tests__/packet-writer.test.d.ts +1 -0
- package/dist/continuation/__tests__/parity.test.d.ts +1 -0
- package/dist/continuation/__tests__/status-cli.test.d.ts +1 -0
- package/dist/continuation/dirty-state-collector.d.ts +46 -0
- package/dist/continuation/index.d.ts +8 -0
- package/dist/continuation/packet-reader.d.ts +33 -0
- package/dist/continuation/packet-writer.d.ts +86 -0
- package/dist/continuation/types.d.ts +239 -0
- package/dist/credential-broker/__tests__/broker.test.d.ts +1 -0
- package/dist/credential-broker/__tests__/canonical.test.d.ts +1 -0
- package/dist/credential-broker/__tests__/scrubber.test.d.ts +1 -0
- package/dist/credential-broker/__tests__/upstream-client.test.d.ts +1 -0
- package/dist/credential-broker/__tests__/vendor-key-store.test.d.ts +1 -0
- package/dist/credential-broker/audit-sink.d.ts +69 -0
- package/dist/credential-broker/broker-config.d.ts +39 -0
- package/dist/credential-broker/broker-token.d.ts +123 -0
- package/dist/credential-broker/broker.d.ts +165 -0
- package/dist/credential-broker/canonical.d.ts +119 -0
- package/dist/credential-broker/index.d.ts +15 -0
- package/dist/credential-broker/scrubber.d.ts +45 -0
- package/dist/credential-broker/types.d.ts +141 -0
- package/dist/credential-broker/upstream-client.d.ts +20 -0
- package/dist/credential-broker/vendor-key-store.d.ts +54 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +427 -124
- package/dist/keychain/__tests__/keychain-backend.test.d.ts +1 -0
- package/dist/keychain/keychain-backend.d.ts +82 -0
- package/dist/local-executor/__tests__/agentic-disposable-repo.test.d.ts +1 -0
- package/dist/local-executor/__tests__/agentic-resolve.test.d.ts +1 -0
- package/dist/local-executor/__tests__/agentic-resolver-flag.test.d.ts +1 -0
- package/dist/local-executor/__tests__/class-a-sign.test.d.ts +1 -0
- package/dist/local-executor/__tests__/class1-reconcilers.test.d.ts +1 -0
- package/dist/local-executor/__tests__/class2-resolver.test.d.ts +1 -0
- package/dist/local-executor/__tests__/confined-model-caller.test.d.ts +1 -0
- package/dist/local-executor/__tests__/conflict-classifier.test.d.ts +1 -0
- package/dist/local-executor/__tests__/conflict-resolution-durable-store.test.d.ts +1 -0
- package/dist/local-executor/__tests__/conflict-resolution-store.test.d.ts +1 -0
- package/dist/local-executor/__tests__/cp1f-quorum-consumer.test.d.ts +1 -0
- package/dist/local-executor/__tests__/cp7-audit-writer.test.d.ts +1 -0
- package/dist/local-executor/__tests__/durable-store.test.d.ts +1 -0
- package/dist/local-executor/__tests__/git-lock-retry.test.d.ts +1 -0
- package/dist/local-executor/__tests__/implementor-argv.test.d.ts +1 -0
- package/dist/local-executor/__tests__/local-executor-teams.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-conflict-extract.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-conflict-git.integration.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-conflict-resolve-agentic.integration.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-conflict-resolve.integration.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-journal-store.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-train-agentic-recovery.integration.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-train-w3.integration.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-train-waveb.integration.test.d.ts +1 -0
- package/dist/local-executor/__tests__/merge-train.test.d.ts +1 -0
- package/dist/local-executor/__tests__/promote-wal-store.test.d.ts +1 -0
- package/dist/local-executor/__tests__/revert-reconcile.test.d.ts +1 -0
- package/dist/local-executor/__tests__/revert-runner.test.d.ts +1 -0
- package/dist/local-executor/__tests__/shared-contract-detector.test.d.ts +1 -0
- package/dist/local-executor/__tests__/substrate-engage.test.d.ts +1 -0
- package/dist/local-executor/__tests__/team-execution-flag.test.d.ts +1 -0
- package/dist/local-executor/__tests__/track-registry.test.d.ts +1 -0
- package/dist/local-executor/__tests__/wb2-review-bundle.test.d.ts +1 -0
- package/dist/local-executor/__tests__/wb2-substrate-spawn.live.test.d.ts +1 -0
- package/dist/local-executor/__tests__/workspace-shadow.test.d.ts +1 -0
- package/dist/local-executor/__tests__/worktree-merge.test.d.ts +1 -0
- package/dist/local-executor/agentic-disposable-repo.d.ts +52 -0
- package/dist/local-executor/agentic-resolve.d.ts +54 -0
- package/dist/local-executor/agentic-resolver-flag.d.ts +9 -0
- package/dist/local-executor/authority.d.ts +33 -1
- package/dist/local-executor/class-a-emit.d.ts +3 -1
- package/dist/local-executor/class-a-sign.d.ts +57 -0
- package/dist/local-executor/class-b-consumer.d.ts +159 -4
- package/dist/local-executor/class-b-verify.d.ts +30 -0
- package/dist/local-executor/class1-reconcilers.d.ts +58 -0
- package/dist/local-executor/class2-resolver.d.ts +74 -0
- package/dist/local-executor/confined-model-caller.d.ts +39 -0
- package/dist/local-executor/conflict-classifier.d.ts +21 -0
- package/dist/local-executor/conflict-resolution-durable-store.d.ts +61 -0
- package/dist/local-executor/conflict-resolution-store.d.ts +210 -0
- package/dist/local-executor/conflict-types.d.ts +86 -0
- package/dist/local-executor/cp7-audit-writer.d.ts +152 -0
- package/dist/local-executor/durable-store.d.ts +334 -0
- package/dist/local-executor/git-lock-retry.d.ts +40 -0
- package/dist/local-executor/hook-bridge.d.ts +1 -1
- package/dist/local-executor/implementor-argv.d.ts +183 -0
- package/dist/local-executor/index.d.ts +44 -3
- package/dist/local-executor/local-executor-impl.d.ts +645 -4
- package/dist/local-executor/merge-conflict-extract.d.ts +34 -0
- package/dist/local-executor/merge-conflict-resolve.d.ts +101 -0
- package/dist/local-executor/merge-journal-store.d.ts +311 -0
- package/dist/local-executor/merge-train.d.ts +713 -0
- package/dist/local-executor/promote-wal-store.d.ts +301 -0
- package/dist/local-executor/resolution-set-index.d.ts +51 -0
- package/dist/local-executor/revert-reconcile.d.ts +89 -0
- package/dist/local-executor/revert-runner.d.ts +17 -0
- package/dist/local-executor/shared-contract-detector.d.ts +57 -0
- package/dist/local-executor/spawn.d.ts +29 -1
- package/dist/local-executor/task-group-types.d.ts +346 -0
- package/dist/local-executor/team-execution-flag.d.ts +21 -0
- package/dist/local-executor/track-registry.d.ts +50 -0
- package/dist/local-executor/types.d.ts +238 -4
- package/dist/local-executor/wb2-review-bundle.d.ts +59 -0
- package/dist/local-executor/workspace-shadow.d.ts +290 -0
- package/dist/local-executor/worktree-merge.d.ts +601 -0
- package/dist/local-model/__tests__/installer.test.d.ts +1 -0
- package/dist/local-model/__tests__/manager.test.d.ts +1 -0
- package/dist/local-model/__tests__/ollama.test.d.ts +1 -0
- package/dist/local-model/__tests__/runtime.test.d.ts +1 -0
- package/dist/local-model/__tests__/state.test.d.ts +1 -0
- package/dist/local-model/manager.d.ts +119 -0
- package/dist/local-model/ollama.d.ts +27 -0
- package/dist/local-model/runtime.d.ts +27 -0
- package/dist/local-model/state.d.ts +32 -0
- package/dist/orchestration/detect-agents.d.ts +15 -2
- package/dist/orchestration/setup-types.d.ts +2 -1
- package/dist/orchestration-shell/__tests__/attachments.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/audit-browser.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/audited-path-fixes.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/bracketed-paste.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cli-group-halt-wiring.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cli-orchestration-session-bootstrap.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cli-probe-group-status.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cli-quorum-loop-tier.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cli-verdict-classifier-wiring.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/context-store.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp10-585-accept-echo-target.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp10-585-loop.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp10-585-prompts.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp12-w2b-team-loop.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp12-w4-team-recovery.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp1f-quorum-loop.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp606-team-track-user-resolved.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/cp7-reviewer-substrate.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/declared-test-runner.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/familiarize-routing.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/gate-decision-submit.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/gate-details-panel.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/gate-verdict-details-dispatch.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/group-decision-submit.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/image-attach-e2e.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/input-bar-autocomplete.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/live-region-cap.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/live-static-order.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/model-cli.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/non-gate-prompt-routing.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/orchestration-app-group-decision-transport.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/orchestration-app-layout.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/reissue-team-retained-spec.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/review-summary-render.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/reviewer-wizard.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/reviewers-format.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/root-discovery.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/serialize-submissions.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/slash-suggest.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/status-format.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/task-progress.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/team-decompose-routing.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/team-decompose-types.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/team-decompose.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/team-e2e-smoke.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/tier2-reviewer-selection.test.d.ts +1 -0
- package/dist/orchestration-shell/__tests__/web-browsing.test.d.ts +1 -0
- package/dist/orchestration-shell/attachments.d.ts +152 -0
- package/dist/orchestration-shell/audit-browser.d.ts +115 -0
- package/dist/orchestration-shell/audit-runner.d.ts +59 -0
- package/dist/orchestration-shell/bracketed-paste.d.ts +26 -0
- package/dist/orchestration-shell/cli.d.ts +336 -1
- package/dist/orchestration-shell/cli.js +40580 -4692
- package/dist/orchestration-shell/components/AuditLogPanel.d.ts +11 -0
- package/dist/orchestration-shell/components/ConversationPane.d.ts +7 -1
- package/dist/orchestration-shell/components/GateDetailsPanel.d.ts +57 -0
- package/dist/orchestration-shell/components/GatePanelEntry.d.ts +9 -0
- package/dist/orchestration-shell/components/GatePromptEntry.d.ts +7 -0
- package/dist/orchestration-shell/components/InputBar.d.ts +17 -3
- package/dist/orchestration-shell/components/LiveProgressLine.d.ts +8 -0
- package/dist/orchestration-shell/components/MultiTrackStatusNode.d.ts +8 -0
- package/dist/orchestration-shell/components/OrchestrationApp.d.ts +81 -15
- package/dist/orchestration-shell/components/ReviewerSetupWizard.d.ts +24 -0
- package/dist/orchestration-shell/components/StatusBar.d.ts +15 -2
- package/dist/orchestration-shell/context-store.d.ts +389 -0
- package/dist/orchestration-shell/declared-test-runner.d.ts +84 -0
- package/dist/orchestration-shell/emit-shell-event.d.ts +1 -1
- package/dist/orchestration-shell/gate-decision-submit.d.ts +245 -0
- package/dist/orchestration-shell/gate-prompts.d.ts +361 -3
- package/dist/orchestration-shell/index.d.ts +613 -1
- package/dist/orchestration-shell/ink-runtime.d.ts +21 -1
- package/dist/orchestration-shell/live-region-cap.d.ts +70 -0
- package/dist/orchestration-shell/live-static-order.d.ts +22 -0
- package/dist/orchestration-shell/non-tty-fallback.d.ts +21 -0
- package/dist/orchestration-shell/quorum-loop.d.ts +1900 -0
- package/dist/orchestration-shell/root-discovery.d.ts +25 -0
- package/dist/orchestration-shell/route-browse.d.ts +20 -0
- package/dist/orchestration-shell/slash-router.d.ts +20 -1
- package/dist/orchestration-shell/slash-routes/continuation.d.ts +71 -0
- package/dist/orchestration-shell/slash-routes/reviewers.d.ts +41 -0
- package/dist/orchestration-shell/slash-suggest.d.ts +29 -0
- package/dist/orchestration-shell/status-format.d.ts +59 -0
- package/dist/orchestration-shell/task-progress.d.ts +122 -0
- package/dist/orchestration-shell/team-decompose.d.ts +196 -0
- package/dist/orchestration-shell/types.d.ts +363 -3
- package/dist/orchestration-shell/vendor/ink-parse-keypress.d.ts +42 -0
- package/dist/orchestration-shell/web/extract.d.ts +11 -0
- package/dist/orchestration-shell/web/fetch.d.ts +15 -0
- package/dist/orchestration-shell/web/ip.d.ts +26 -0
- package/dist/orchestration-shell/web/sanitize.d.ts +14 -0
- package/dist/orchestration-shell/web/search.d.ts +16 -0
- package/dist/planner/__tests__/local-gemma.test.d.ts +1 -0
- package/dist/planner/index.d.ts +2 -0
- package/dist/planner/local-advisory.d.ts +84 -0
- package/dist/planner/local-gemma.d.ts +23 -0
- package/dist/planner/types.d.ts +16 -6
- package/dist/reviewer/__tests__/antigravity-provider.test.d.ts +1 -0
- package/dist/reviewer/__tests__/claude-provider-json.test.d.ts +1 -0
- package/dist/reviewer/__tests__/cp7-reviewer-sandbox.test.d.ts +1 -0
- package/dist/reviewer/__tests__/output-parser-classifier-helpers.test.d.ts +1 -0
- package/dist/reviewer/__tests__/verdict-classifier.test.d.ts +1 -0
- package/dist/reviewer/index.d.ts +2 -0
- package/dist/reviewer/output-parser.d.ts +48 -12
- package/dist/reviewer/provider.d.ts +107 -3
- package/dist/reviewer/providers/__tests__/failure-classifier.test.d.ts +1 -0
- package/dist/reviewer/providers/antigravity.d.ts +49 -0
- package/dist/reviewer/providers/claude.d.ts +19 -4
- package/dist/reviewer/providers/codex.d.ts +47 -5
- package/dist/reviewer/providers/failure-classifier.d.ts +26 -0
- package/dist/reviewer/providers/gemini.d.ts +5 -4
- package/dist/reviewer/registry.d.ts +5 -5
- package/dist/reviewer/subprocess.d.ts +37 -0
- package/dist/reviewer/token-usage.d.ts +32 -0
- package/dist/reviewer/types.d.ts +5 -5
- package/dist/reviewer/verdict-classifier.d.ts +62 -0
- package/dist/session/__tests__/prepare-event-timestamp.test.d.ts +1 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/prepare-event-timestamp.d.ts +30 -0
- package/dist/substrate/__tests__/docker.test.d.ts +1 -0
- package/dist/substrate/__tests__/forwarder.test.d.ts +1 -0
- package/dist/substrate/__tests__/git-proxy.test.d.ts +1 -0
- package/dist/substrate/__tests__/sandbox-exec.test.d.ts +1 -0
- package/dist/substrate/__tests__/substrate-e2e.integration.test.d.ts +1 -0
- package/dist/substrate/command-runner.d.ts +19 -0
- package/dist/substrate/docker.d.ts +134 -0
- package/dist/substrate/errors.d.ts +33 -0
- package/dist/substrate/forwarder.d.ts +67 -0
- package/dist/substrate/git-proxy.d.ts +35 -0
- package/dist/substrate/index.d.ts +12 -0
- package/dist/substrate/relay-script.d.ts +27 -0
- package/dist/substrate/sandbox-exec.d.ts +116 -0
- package/dist/substrate/types.d.ts +218 -0
- package/dist/substrate-launch/__tests__/apikey-bootstrap.test.d.ts +1 -0
- package/dist/substrate-launch/__tests__/creditless-loop.integration.test.d.ts +1 -0
- package/dist/substrate-launch/__tests__/engage-substrate.test.d.ts +1 -0
- package/dist/substrate-launch/__tests__/fallback-ladder.test.d.ts +1 -0
- package/dist/substrate-launch/__tests__/le-env-scrub.test.d.ts +1 -0
- package/dist/substrate-launch/__tests__/sanitized-env.test.d.ts +1 -0
- package/dist/substrate-launch/apikey-bootstrap.d.ts +84 -0
- package/dist/substrate-launch/engage-substrate.d.ts +102 -0
- package/dist/substrate-launch/fallback-ladder.d.ts +49 -0
- package/dist/substrate-launch/index.d.ts +12 -0
- package/dist/substrate-launch/le-env-scrub.d.ts +77 -0
- package/dist/substrate-launch/sanitized-env.d.ts +73 -0
- package/dist/types/auth.d.ts +6 -1
- package/dist/types/events.d.ts +3 -1
- package/dist/types/reviewer.d.ts +6 -6
- package/package.json +7 -3
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CP-6 LOCK #C6-A-1 AgentKind union — 4 values per AGY-2.0-SUPPORT-DESIGN.md.
|
|
3
|
+
* As of Phase C, ANTIGRAVITY is a fully-valid continuation SOURCE and TARGET
|
|
4
|
+
* end-to-end (TS `VALID_TARGET_AGENTS` + the Rust
|
|
5
|
+
* `recordContinuationPacketWritten` / `apply_user_decision` validators all
|
|
6
|
+
* accept it; the Codex M2 §4.10.4 rejection was inverted in Phase C).
|
|
7
|
+
*/
|
|
8
|
+
export type AgentKind = 'CLAUDE' | 'CODEX' | 'GEMINI' | 'ANTIGRAVITY';
|
|
9
|
+
/**
|
|
10
|
+
* CP-6 LOCK #C6-A-1 — 4-value `HandoffReason` union. Implementor-
|
|
11
|
+
* continuation triggers only (master §8:932-937 reserves
|
|
12
|
+
* `reviewer_unavailable` / `reviewer_conflict` / `unsafe_action` for
|
|
13
|
+
* CP-3.h / CP-2.h / CP-9 min escalation — NOT CP-6 continuation
|
|
14
|
+
* packet-write paths).
|
|
15
|
+
*
|
|
16
|
+
* The 4 §7 trigger rows map onto §6:827 wire spellings 1:1:
|
|
17
|
+
* - §7 "Quota exhausted" → `quota_exhausted`
|
|
18
|
+
* - §7 "Auth failed" → `auth_failed`
|
|
19
|
+
* - §7 "Agent timeout" → `timeout`
|
|
20
|
+
* - §7 "User request" → `user_requested`
|
|
21
|
+
*
|
|
22
|
+
* §6:827 also defines `explicit_escalation` + `reviewer_conflict`;
|
|
23
|
+
* the CP-6 reader accepts them but the writer never emits them.
|
|
24
|
+
*/
|
|
25
|
+
export type HandoffReason = 'quota_exhausted' | 'auth_failed' | 'timeout' | 'user_requested';
|
|
26
|
+
/**
|
|
27
|
+
* Gate-state snapshot embedded in every continuation packet. Captures
|
|
28
|
+
* the prior implementor's verification + reviewer-quorum + final-
|
|
29
|
+
* approval pose so the next implementor can read but not bypass.
|
|
30
|
+
*/
|
|
31
|
+
export interface GateState {
|
|
32
|
+
verification: 'not_started' | 'pass' | 'fail';
|
|
33
|
+
reviewerQuorum: 'not_started' | 'pass' | 'revise' | 'block';
|
|
34
|
+
finalApproval: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Per-repo state captured at packet-write time by LOCK #C6-A-7
|
|
38
|
+
* dirty-state collector. `headSha` / `branch` fall through to the
|
|
39
|
+
* literal `"unknown"` sentinel when git is unavailable or
|
|
40
|
+
* `git rev-parse` times out.
|
|
41
|
+
*/
|
|
42
|
+
export interface RepoState {
|
|
43
|
+
/** repo basename (e.g., `codevibe-backend`). */
|
|
44
|
+
repo: string;
|
|
45
|
+
/** absolute filesystem path (clamped to authority writeScopes/readScopes). */
|
|
46
|
+
path: string;
|
|
47
|
+
/** git branch — literal `"unknown"` when git rev-parse fails. */
|
|
48
|
+
branch: string;
|
|
49
|
+
/** 40-hex git sha — literal `"unknown"` when git rev-parse fails. */
|
|
50
|
+
headSha: string;
|
|
51
|
+
dirty: boolean;
|
|
52
|
+
/** git status --porcelain output, relative to repo root. */
|
|
53
|
+
changedFiles: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* CP-6 LOCK #C6-A-1 — 17-field continuation packet structural type.
|
|
57
|
+
* Mirrors master §6:820-852 byte-for-byte.
|
|
58
|
+
*
|
|
59
|
+
* Sentinel taxonomy per §8.1:
|
|
60
|
+
* - WRITER-CONSTANT (1): packetVersion (always 1)
|
|
61
|
+
* - STRICT-REQUIRED (8): taskId, sessionId, sourceAgent,
|
|
62
|
+
* targetAgent, handoffReason, role,
|
|
63
|
+
* taskSummary, expiresAt
|
|
64
|
+
* - CALLER-OR-COLLECTOR (1): repoStates (falls through to
|
|
65
|
+
* dirty-state collector when caller
|
|
66
|
+
* passes undefined)
|
|
67
|
+
* - AUTO-SENTINEL (7): completedWork, remainingWork,
|
|
68
|
+
* verification, activeRules, gateState,
|
|
69
|
+
* safetyConstraints, reviewHistoryRefs
|
|
70
|
+
*/
|
|
71
|
+
export interface ContinuationPacket {
|
|
72
|
+
packetVersion: 1;
|
|
73
|
+
taskId: string;
|
|
74
|
+
sessionId: string;
|
|
75
|
+
sourceAgent: AgentKind;
|
|
76
|
+
targetAgent: AgentKind;
|
|
77
|
+
handoffReason: HandoffReason;
|
|
78
|
+
/** CP-6 always emits `"implementor"`; reviewer-role packets deferred. */
|
|
79
|
+
role: 'implementor';
|
|
80
|
+
repoStates: RepoState[];
|
|
81
|
+
/** Master §6:839 — "what the implementor is trying to complete". */
|
|
82
|
+
taskSummary: string;
|
|
83
|
+
/** Master §6:840 — facts already done. */
|
|
84
|
+
completedWork: string[];
|
|
85
|
+
/** Master §6:841 — next actions. */
|
|
86
|
+
remainingWork: string[];
|
|
87
|
+
/** Master §6:842 — tests run AND tests intentionally not run. */
|
|
88
|
+
verification: string[];
|
|
89
|
+
/** Master §6:843 — gate plan + commit/push rules + safety constraints. */
|
|
90
|
+
activeRules: string[];
|
|
91
|
+
gateState: GateState;
|
|
92
|
+
/** Master §6:849. */
|
|
93
|
+
safetyConstraints: string[];
|
|
94
|
+
/** Master §6:850 — file paths or AppSync row IDs. */
|
|
95
|
+
reviewHistoryRefs: string[];
|
|
96
|
+
/** ISO-8601 RFC 3339 timestamp. */
|
|
97
|
+
expiresAt: string;
|
|
98
|
+
}
|
|
99
|
+
export declare class PacketFidelityError extends Error {
|
|
100
|
+
readonly missingFields: string[];
|
|
101
|
+
constructor(missingFields: string[], message?: string);
|
|
102
|
+
}
|
|
103
|
+
export declare class PacketIoError extends Error {
|
|
104
|
+
readonly cause?: NodeJS.ErrnoException;
|
|
105
|
+
constructor(message: string, cause?: NodeJS.ErrnoException);
|
|
106
|
+
}
|
|
107
|
+
export declare class PacketHashMismatch extends Error {
|
|
108
|
+
readonly expectedHash: string;
|
|
109
|
+
readonly actualHash: string;
|
|
110
|
+
constructor(expectedHash: string, actualHash: string);
|
|
111
|
+
}
|
|
112
|
+
export declare class PacketAuditEmitError extends Error {
|
|
113
|
+
readonly reason: string;
|
|
114
|
+
constructor(reason: string);
|
|
115
|
+
}
|
|
116
|
+
export declare class PacketNotFound extends Error {
|
|
117
|
+
readonly packetPath: string;
|
|
118
|
+
constructor(packetPath: string);
|
|
119
|
+
}
|
|
120
|
+
export declare class PacketUnverified extends Error {
|
|
121
|
+
readonly packetPath: string;
|
|
122
|
+
readonly taskId: string;
|
|
123
|
+
readonly packetHash: string;
|
|
124
|
+
constructor(packetPath: string, taskId: string, packetHash: string);
|
|
125
|
+
}
|
|
126
|
+
export declare class FrontmatterMalformed extends Error {
|
|
127
|
+
readonly cause?: Error;
|
|
128
|
+
constructor(message: string, cause?: Error);
|
|
129
|
+
}
|
|
130
|
+
export declare class SchemaInvalid extends Error {
|
|
131
|
+
readonly errors: string[];
|
|
132
|
+
constructor(errors: string[]);
|
|
133
|
+
}
|
|
134
|
+
export declare class PacketPermissionsLoose extends Error {
|
|
135
|
+
readonly path: string;
|
|
136
|
+
readonly actualMode: number;
|
|
137
|
+
constructor(filePath: string, actualMode: number);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Caller-supplied fields for `writer.write()`. All 8 STRICT-REQUIRED
|
|
141
|
+
* fields (per §8.1 sentinel taxonomy) are required at the type level;
|
|
142
|
+
* AUTO-SENTINEL fields are optional and default to the §8.1 sentinel
|
|
143
|
+
* when omitted. `repoStates` is optional — when undefined, the writer
|
|
144
|
+
* dispatches to the dirty-state collector.
|
|
145
|
+
*
|
|
146
|
+
* `offerId` is not part of the packet body itself (it lives on the
|
|
147
|
+
* backend audit row per LOCK #C6-A-10); the writer forwards it to
|
|
148
|
+
* `AppSyncClient.recordContinuationPacketWritten`. Use `null` for
|
|
149
|
+
* LE-initiated writes that have no prior Class B offer.
|
|
150
|
+
*/
|
|
151
|
+
export interface PacketWriteInput {
|
|
152
|
+
taskId: string;
|
|
153
|
+
sessionId: string;
|
|
154
|
+
sourceAgent: AgentKind;
|
|
155
|
+
targetAgent: AgentKind;
|
|
156
|
+
handoffReason: HandoffReason;
|
|
157
|
+
/**
|
|
158
|
+
* STRICT-REQUIRED per §8.1 sentinel taxonomy (Stage 2 R1 M-2 fix —
|
|
159
|
+
* was previously optional with a silent `?? 'implementor'` default,
|
|
160
|
+
* a contract deviation from the locked design). Callers MUST pass
|
|
161
|
+
* `'implementor'` explicitly; the writer throws `PacketFidelityError`
|
|
162
|
+
* with `missingFields: ['role', ...]` when undefined.
|
|
163
|
+
*/
|
|
164
|
+
role: 'implementor';
|
|
165
|
+
taskSummary: string;
|
|
166
|
+
expiresAt: string;
|
|
167
|
+
repoStates?: RepoState[];
|
|
168
|
+
completedWork?: string[];
|
|
169
|
+
remainingWork?: string[];
|
|
170
|
+
verification?: string[];
|
|
171
|
+
activeRules?: string[];
|
|
172
|
+
gateState?: GateState;
|
|
173
|
+
safetyConstraints?: string[];
|
|
174
|
+
reviewHistoryRefs?: string[];
|
|
175
|
+
offerId?: string | null;
|
|
176
|
+
blockedReason?: HandoffReason;
|
|
177
|
+
/**
|
|
178
|
+
* PHASE-CP-10-MIN (#585) — the round's gate the desktop is handing off from
|
|
179
|
+
* (H-A). Forwarded to `recordContinuationPacketWritten` (the additive
|
|
180
|
+
* `gateId: ID` input) so the handler `fetch_row`s it, cross-checks
|
|
181
|
+
* `gate_row.task_id == input.task_id`, and uses it as the #C10M-14
|
|
182
|
+
* mutual-exclusion stamp target + the emitted prompt's `EmitContext.gate_id`.
|
|
183
|
+
* NOT embedded in the packet body. Required at the handler for #585's two
|
|
184
|
+
* triggers; optional at the type level so legacy/LE-initiated writes that
|
|
185
|
+
* predate CP-10 still type-check.
|
|
186
|
+
*/
|
|
187
|
+
gateId?: string;
|
|
188
|
+
}
|
|
189
|
+
export interface PacketWriteResult {
|
|
190
|
+
/** 64-char lowercase hex SHA-256 of JCS-canonical-JSON(packet). */
|
|
191
|
+
packetHash: string;
|
|
192
|
+
/** Absolute path of the written CONTINUATION.md. */
|
|
193
|
+
path: string;
|
|
194
|
+
}
|
|
195
|
+
export interface PacketListEntry {
|
|
196
|
+
taskId: string;
|
|
197
|
+
packetExists: boolean;
|
|
198
|
+
lastModified: Date | null;
|
|
199
|
+
packetHash?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Discriminated union returned by `reader.read()` when used in
|
|
203
|
+
* fail-soft mode. Throwing variants live on the reader directly; the
|
|
204
|
+
* union is exported for callers that prefer typed-return semantics.
|
|
205
|
+
*/
|
|
206
|
+
export type ContinuationPacketReadResult = {
|
|
207
|
+
kind: 'ok';
|
|
208
|
+
packet: ContinuationPacket;
|
|
209
|
+
packetHash: string;
|
|
210
|
+
} | {
|
|
211
|
+
kind: 'not_found';
|
|
212
|
+
path: string;
|
|
213
|
+
} | {
|
|
214
|
+
kind: 'unverified';
|
|
215
|
+
path: string;
|
|
216
|
+
taskId: string;
|
|
217
|
+
packetHash: string;
|
|
218
|
+
} | {
|
|
219
|
+
kind: 'permissions_loose';
|
|
220
|
+
path: string;
|
|
221
|
+
actualMode: number;
|
|
222
|
+
} | {
|
|
223
|
+
kind: 'frontmatter_malformed';
|
|
224
|
+
path: string;
|
|
225
|
+
message: string;
|
|
226
|
+
} | {
|
|
227
|
+
kind: 'schema_invalid';
|
|
228
|
+
path: string;
|
|
229
|
+
errors: string[];
|
|
230
|
+
} | {
|
|
231
|
+
kind: 'hash_mismatch';
|
|
232
|
+
path: string;
|
|
233
|
+
expectedHash: string;
|
|
234
|
+
actualHash: string;
|
|
235
|
+
} | {
|
|
236
|
+
kind: 'io_error';
|
|
237
|
+
path: string;
|
|
238
|
+
message: string;
|
|
239
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The five CP-7 audit kinds (§3.5), in their snake_case wire form — the
|
|
3
|
+
* exact strings the `AuditEventKind` enum serializes as and the
|
|
4
|
+
* `audit-keys` discriminator constants use. Defined here (not imported
|
|
5
|
+
* from a Rust-mirrored module) because W1 only needs the broker-side
|
|
6
|
+
* wire kinds; W3 wires these to the real `AuditEventKind` enum + NAPI
|
|
7
|
+
* `parse_audit_kind`.
|
|
8
|
+
*
|
|
9
|
+
* Note: only `model_call`, `model_call_result`, `model_context_scrubbed`,
|
|
10
|
+
* and `broker_credential_loaded` are broker-emitted. `egress_denied` is
|
|
11
|
+
* emitted by the substrate's egress proxy (§3.5, W2/W3) — it is included
|
|
12
|
+
* in the union for completeness of the CP-7 audit taxonomy but the broker
|
|
13
|
+
* never emits it.
|
|
14
|
+
*/
|
|
15
|
+
export type AuditKindCp7 = "model_call" | "model_call_result" | "egress_denied" | "model_context_scrubbed" | "broker_credential_loaded";
|
|
16
|
+
/**
|
|
17
|
+
* The strict audit sink the broker emits through (§3.5).
|
|
18
|
+
*
|
|
19
|
+
* Per §3.5: the sender transmits `{kind, payload}` and BLOCKS for the
|
|
20
|
+
* LE's durable ACK. A resolved `{ ack }` means the row is durably on
|
|
21
|
+
* disk (the gated effect — the upstream forward — may proceed for a
|
|
22
|
+
* pre-forward row). A resolved `{ nack }` means the durable write failed
|
|
23
|
+
* (the broker fails closed: 503, no forward). A rejected/timed-out promise
|
|
24
|
+
* is treated by the broker exactly like a NACK (fail closed on a
|
|
25
|
+
* pre-forward row).
|
|
26
|
+
*/
|
|
27
|
+
export interface StrictAuditSink {
|
|
28
|
+
emit(kind: AuditKindCp7, payload: Record<string, unknown>): Promise<{
|
|
29
|
+
ack: string;
|
|
30
|
+
} | {
|
|
31
|
+
nack: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A recorded emit, surfaced by {@link StubStrictAuditSink} for test
|
|
36
|
+
* assertions (the real LE emitter exposes nothing comparable — this is a
|
|
37
|
+
* test seam only).
|
|
38
|
+
*/
|
|
39
|
+
export interface RecordedAuditEmit {
|
|
40
|
+
kind: AuditKindCp7;
|
|
41
|
+
payload: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* In-memory deterministic `StrictAuditSink` for unit tests + the injected
|
|
45
|
+
* default until W3. Every `emit` ACKs with a deterministic
|
|
46
|
+
* `stub-ack-<n>` id and records the `{kind, payload}` for assertions.
|
|
47
|
+
*
|
|
48
|
+
* Two test hooks (both default off so the happy path is deterministic):
|
|
49
|
+
* - `nackKinds`: any kind in this set NACKs instead of ACKing — exercises
|
|
50
|
+
* the audit-before-effect 503 path.
|
|
51
|
+
* - `failKinds`: any kind in this set REJECTS the promise — exercises the
|
|
52
|
+
* "IPC error / timeout treated as fail-closed" path.
|
|
53
|
+
*/
|
|
54
|
+
export declare class StubStrictAuditSink implements StrictAuditSink {
|
|
55
|
+
private readonly opts;
|
|
56
|
+
readonly emitted: RecordedAuditEmit[];
|
|
57
|
+
private counter;
|
|
58
|
+
constructor(opts?: {
|
|
59
|
+
nackKinds?: ReadonlyArray<AuditKindCp7>;
|
|
60
|
+
failKinds?: ReadonlyArray<AuditKindCp7>;
|
|
61
|
+
});
|
|
62
|
+
emit(kind: AuditKindCp7, payload: Record<string, unknown>): Promise<{
|
|
63
|
+
ack: string;
|
|
64
|
+
} | {
|
|
65
|
+
nack: string;
|
|
66
|
+
}>;
|
|
67
|
+
/** All emitted rows of a given kind (test helper). */
|
|
68
|
+
ofKind(kind: AuditKindCp7): RecordedAuditEmit[];
|
|
69
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { VendorProvider } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Per-provider wire facts the broker synthesizes on the upstream call.
|
|
4
|
+
*/
|
|
5
|
+
export interface ProviderConfig {
|
|
6
|
+
/** Upstream origin (scheme + host) the broker forwards to. */
|
|
7
|
+
readonly upstreamBaseUrl: string;
|
|
8
|
+
/** The canonical upstream path for this provider's model route. */
|
|
9
|
+
readonly upstreamPath: "/v1/messages" | "/v1/responses";
|
|
10
|
+
/**
|
|
11
|
+
* Headers the broker synthesizes on EVERY upstream call — overriding
|
|
12
|
+
* whatever the agent supplied. `content-type` is always normalized to
|
|
13
|
+
* `application/json` (the only carried-through content type, §3.4).
|
|
14
|
+
*/
|
|
15
|
+
readonly synthesizedHeaders: Readonly<Record<string, string>>;
|
|
16
|
+
/**
|
|
17
|
+
* The EXACT allowlist of `anthropic-beta` (or provider equivalent)
|
|
18
|
+
* tokens the broker will pass through. A request carrying a beta token
|
|
19
|
+
* outside this set is rejected (400) — header VALUES are agent-
|
|
20
|
+
* controlled and can carry data (Codex R2). Empty for OpenAI (no beta
|
|
21
|
+
* header is forwarded).
|
|
22
|
+
*/
|
|
23
|
+
readonly betaTokenAllowlist: ReadonlySet<string>;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the agent-supplied beta header this provider honors
|
|
26
|
+
* (lowercased), or `null` if the provider has none. Used by the
|
|
27
|
+
* canonical constructor to find the agent's beta tokens to validate.
|
|
28
|
+
*/
|
|
29
|
+
readonly betaHeaderName: string | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the locked wire facts for a provider. Pure data — no I/O.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getProviderConfig(provider: VendorProvider): ProviderConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Map an inbound broker route path to the vendor provider it gateways.
|
|
37
|
+
* `/v1/messages` → Anthropic, `/v1/responses` → OpenAI.
|
|
38
|
+
*/
|
|
39
|
+
export declare function providerForPath(path: string): VendorProvider | null;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { BrokerToken } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Mints + holds the current per-session broker token, and authenticates
|
|
4
|
+
* inbound agent→broker tokens against it. A new token replaces the prior
|
|
5
|
+
* one (single active token per session); `authenticate` accepts ONLY the
|
|
6
|
+
* current, unexpired value — every other value (including a just-rotated
|
|
7
|
+
* old token) is rejected, which the broker maps to the only 401 it emits.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A grace-rotation handle (Finding 3). `rotateWithGrace` returns this; the LE
|
|
11
|
+
* passes it back to {@link BrokerTokenMinter.commitRotation} /
|
|
12
|
+
* {@link BrokerTokenMinter.rollbackRotation}. The `generation` GENERATION-BINDS
|
|
13
|
+
* the commit/rollback to the SPECIFIC rotation that produced it: a stale handle
|
|
14
|
+
* (from a rotation already superseded by a newer one) is rejected, so a slow
|
|
15
|
+
* commit/rollback cannot clobber a newer in-flight rotation's token.
|
|
16
|
+
*/
|
|
17
|
+
export interface RotationHandle {
|
|
18
|
+
readonly token: BrokerToken;
|
|
19
|
+
readonly generation: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class BrokerTokenMinter {
|
|
22
|
+
private readonly ttlMs;
|
|
23
|
+
private current;
|
|
24
|
+
/**
|
|
25
|
+
* During a rotation the PRIOR token stays acceptable until the LE confirms
|
|
26
|
+
* the apiKeyHelper file holds the NEW token (`commitRotation`). This closes
|
|
27
|
+
* the 401-loop window the contract forbids (Stage-2 M-3): if we invalidated
|
|
28
|
+
* the prior token BEFORE the file refresh landed, the agent's file would hold
|
|
29
|
+
* a now-rejected token until the next refresh. With the grace token, BOTH the
|
|
30
|
+
* new and the prior token authenticate until the write is confirmed.
|
|
31
|
+
*/
|
|
32
|
+
private graceToken;
|
|
33
|
+
/**
|
|
34
|
+
* Finding 3 — generation counter, bumped on every successful grace rotation.
|
|
35
|
+
* Commit/rollback are bound to the generation of the rotation they belong to;
|
|
36
|
+
* a stale (superseded) commit/rollback is a no-op. The generation also gates
|
|
37
|
+
* OVERLAPPING rotations: `rotateWithGrace` REJECTS (returns null) while a grace
|
|
38
|
+
* is still pending, so two near-concurrent rotations can never chain
|
|
39
|
+
* grace→grace and strand the file token.
|
|
40
|
+
*/
|
|
41
|
+
private generation;
|
|
42
|
+
constructor(ttlMs?: number);
|
|
43
|
+
/** Mint (or rotate) the session's broker token; returns the new token. */
|
|
44
|
+
mint(now?: number): BrokerToken;
|
|
45
|
+
/**
|
|
46
|
+
* M-3 — SAFE rotation. Mint a NEW current token but KEEP the prior token
|
|
47
|
+
* valid (as a grace token) so there is no window where the agent's file (which
|
|
48
|
+
* still holds the prior token until the LE rewrites it) is rejected. The LE
|
|
49
|
+
* MUST call {@link commitRotation} AFTER it confirms the helper file now holds
|
|
50
|
+
* the new token (drops the grace token), or {@link rollbackRotation} if the
|
|
51
|
+
* file write FAILED (restores the prior token as current and discards the new
|
|
52
|
+
* one — the agent's file is still valid, fail-closed, no dead token).
|
|
53
|
+
*
|
|
54
|
+
* Finding 3 — OVERLAP REJECTION: returns null when a grace rotation is already
|
|
55
|
+
* pending (not yet committed/rolled back). Chaining grace→grace would make the
|
|
56
|
+
* SECOND rotation's grace token be the FIRST rotation's new token (not the
|
|
57
|
+
* file-resident prior token); if the first refresh then writes its token and
|
|
58
|
+
* commits, the file token could be left unauthenticated. By refusing to start a
|
|
59
|
+
* second rotation until the first settles, BOTH tokens that ever authenticate
|
|
60
|
+
* are {file-resident prior, new} — the file token is never stranded.
|
|
61
|
+
*
|
|
62
|
+
* Returns the {@link RotationHandle} for the new token, or null if the broker
|
|
63
|
+
* has no current token yet (nothing to rotate) OR a rotation is in-flight.
|
|
64
|
+
*/
|
|
65
|
+
rotateWithGrace(now?: number): RotationHandle | null;
|
|
66
|
+
/**
|
|
67
|
+
* Confirm the helper file now holds the new token — drop the grace token so
|
|
68
|
+
* the prior token stops authenticating (single-active-token restored).
|
|
69
|
+
*
|
|
70
|
+
* Finding 3 — generation-bound: a commit whose `generation` does not match the
|
|
71
|
+
* current generation is STALE (a newer rotation/mint superseded it) and is a
|
|
72
|
+
* NO-OP, so it cannot drop a newer rotation's grace token.
|
|
73
|
+
*/
|
|
74
|
+
commitRotation(handle?: RotationHandle): void;
|
|
75
|
+
/**
|
|
76
|
+
* The file refresh FAILED — roll back: restore the prior (grace) token as
|
|
77
|
+
* current and discard the just-minted new token. The agent's file still holds
|
|
78
|
+
* the prior token, which is once again the sole active token → no dead-token
|
|
79
|
+
* window. No-op if there is no pending grace rotation.
|
|
80
|
+
*
|
|
81
|
+
* Finding 3 — generation-bound: a rollback whose `generation` does not match
|
|
82
|
+
* the current generation is STALE and a NO-OP, so a late rollback from a
|
|
83
|
+
* superseded rotation cannot revert a newer rotation's token.
|
|
84
|
+
*/
|
|
85
|
+
rollbackRotation(handle?: RotationHandle): void;
|
|
86
|
+
/** Whether a rotation is mid-flight (grace token still accepted). Test seam. */
|
|
87
|
+
hasPendingGrace(): boolean;
|
|
88
|
+
/** The current token, or null if none minted yet. */
|
|
89
|
+
get(): BrokerToken | null;
|
|
90
|
+
/**
|
|
91
|
+
* EVERY broker-token value that `authenticate()` would currently accept — the
|
|
92
|
+
* CURRENT token plus, during a mid-flight grace rotation, the PRIOR (grace)
|
|
93
|
+
* token. Used by the broker's self-credential guard so it scrubs ALL tokens a
|
|
94
|
+
* model-bound field could be carrying, not just `get()` (Stage-2 MEDIUM): the
|
|
95
|
+
* prior token still authenticates during the grace window AND is still resident
|
|
96
|
+
* in the agent's helper file, so a model-bound field echoing it is a live-token
|
|
97
|
+
* leak the guard must redact. Values are returned only (the actual scrub +
|
|
98
|
+
* commit/rollback gate is the caller's); a stale/expired grace token is NOT
|
|
99
|
+
* included (it can no longer authenticate, so it is not a live secret).
|
|
100
|
+
*
|
|
101
|
+
* NOTE: this does NOT filter on `expiresAtMs` — `authenticate()` rejects an
|
|
102
|
+
* expired token, but an expired-yet-still-resident token in the helper file is
|
|
103
|
+
* still a secret-shaped value the guard should keep out of model-bound content;
|
|
104
|
+
* we err toward scrubbing both held values whenever they are non-null. (An
|
|
105
|
+
* expired token cannot be USED, but redacting it is strictly safer and never
|
|
106
|
+
* wrong — the guard only ever removes a value, never adds one.)
|
|
107
|
+
*/
|
|
108
|
+
acceptedValues(): string[];
|
|
109
|
+
/**
|
|
110
|
+
* Authenticate an inbound agent→broker token. True for the current, unexpired
|
|
111
|
+
* token value OR (during a mid-flight rotation) the unexpired grace token —
|
|
112
|
+
* the latter keeps the agent's pre-refresh file valid until the LE confirms
|
|
113
|
+
* the file rewrite (M-3 no-rejection-window contract). A missing / stale /
|
|
114
|
+
* expired / mismatched token → false (the broker returns 401 — the ONLY 401
|
|
115
|
+
* it emits, §3.2).
|
|
116
|
+
*
|
|
117
|
+
* Constant-time-ish compare is unnecessary for a loopback-only local
|
|
118
|
+
* token, but we still avoid leaking via early-return on length.
|
|
119
|
+
*/
|
|
120
|
+
authenticate(token: string | undefined, now?: number): boolean;
|
|
121
|
+
/** Zeroize the held token (broker teardown). */
|
|
122
|
+
clear(): void;
|
|
123
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type StrictAuditSink } from "./audit-sink";
|
|
2
|
+
import { getProviderConfig } from "./broker-config";
|
|
3
|
+
import { type RotationHandle } from "./broker-token";
|
|
4
|
+
import { type BrokerRequest, type BrokerResponse, type BrokerToken, type ModelGatewayBroker, type UpstreamClient, type VendorKeyStore, type VendorProvider } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Construction-time dependencies. All injectable so W1 unit-tests run
|
|
7
|
+
* against stubs (no network, deterministic audit ACKs). Defaults wire the
|
|
8
|
+
* real keychain store + a deterministic stub audit sink (the real strict
|
|
9
|
+
* sink is W3). `upstreamClient` has NO default — a network client is out
|
|
10
|
+
* of W1 scope, so the broker MUST be given one (tests pass a stub).
|
|
11
|
+
*/
|
|
12
|
+
export interface BrokerDeps {
|
|
13
|
+
/** Orchestration task_id = the audit scope (§3.5), passed at session start. */
|
|
14
|
+
taskId: string;
|
|
15
|
+
/** Injected upstream HTTP client (no real network in W1). */
|
|
16
|
+
upstreamClient: UpstreamClient;
|
|
17
|
+
/** Vendor-key store (defaults to the keychain-backed store, §3.3). */
|
|
18
|
+
vendorKeyStore?: VendorKeyStore;
|
|
19
|
+
/** Strict audit sink (defaults to the in-memory stub until W3, §3.5). */
|
|
20
|
+
auditSink?: StrictAuditSink;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The local model-gateway broker (§3.2). One per session on
|
|
24
|
+
* `127.0.0.1:<ephemeral>`. Holds the upstream credential in-process only
|
|
25
|
+
* (zeroized on `stop()`), authenticates the agent's broker token, builds
|
|
26
|
+
* a canonical upstream request, scrubs secrets (I2), enforces audit-
|
|
27
|
+
* before-effect via the injected `StrictAuditSink`, and forwards.
|
|
28
|
+
*/
|
|
29
|
+
export declare class LocalModelGatewayBroker implements ModelGatewayBroker, VendorKeyStore {
|
|
30
|
+
private readonly taskId;
|
|
31
|
+
private readonly upstreamClient;
|
|
32
|
+
private readonly vendorKeyStore;
|
|
33
|
+
private readonly auditSink;
|
|
34
|
+
private readonly tokenMinter;
|
|
35
|
+
private readonly brokerId;
|
|
36
|
+
private server;
|
|
37
|
+
private boundAddr;
|
|
38
|
+
/** In-process cache of upstream vendor keys (zeroized on stop()). */
|
|
39
|
+
private upstreamKeys;
|
|
40
|
+
/** Latest `credential_issuance_id` per provider (for the model_call FK). */
|
|
41
|
+
private issuanceIds;
|
|
42
|
+
private issuanceCounter;
|
|
43
|
+
constructor(deps: BrokerDeps);
|
|
44
|
+
/**
|
|
45
|
+
* Start the per-session HTTP gateway on an ephemeral loopback port + mint
|
|
46
|
+
* the session's broker token. Resolves the bound `127.0.0.1:<port>`.
|
|
47
|
+
*/
|
|
48
|
+
start(): Promise<{
|
|
49
|
+
hostBrokerAddr: string;
|
|
50
|
+
}>;
|
|
51
|
+
/** Liveness — the LE waits for this before launching the agent. */
|
|
52
|
+
healthz(): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Tear down: close the HTTP server, ZEROIZE the in-process upstream
|
|
55
|
+
* credentials, and clear the broker token. Idempotent.
|
|
56
|
+
*/
|
|
57
|
+
stop(): Promise<void>;
|
|
58
|
+
/** The current broker token (for the agent's apiKeyHelper bootstrap). */
|
|
59
|
+
currentBrokerToken(): BrokerToken | null;
|
|
60
|
+
/**
|
|
61
|
+
* Re-mint (rotate) the broker token and return the new value. The LE calls
|
|
62
|
+
* this periodically (well within the TTL) + rewrites the apiKeyHelper token
|
|
63
|
+
* file so a long-running session never hits an expired-token 401 loop.
|
|
64
|
+
*
|
|
65
|
+
* M-3 — this is a GRACE rotation: the NEW token becomes current but the PRIOR
|
|
66
|
+
* token KEEPS authenticating until the LE confirms the helper file holds the
|
|
67
|
+
* new token (then calls {@link commitBrokerTokenRotation}). This closes the
|
|
68
|
+
* 401-loop window: there is NEVER a moment where the agent's file (which holds
|
|
69
|
+
* the prior token until the rewrite lands) is rejected. If the file rewrite
|
|
70
|
+
* FAILS, the LE calls {@link rollbackBrokerTokenRotation} to restore the prior
|
|
71
|
+
* token as the sole active one (fail-closed — no dead token left in the file).
|
|
72
|
+
* Returns null if the broker is stopped OR a rotation is already in-flight
|
|
73
|
+
* (Finding 3 overlap guard — the minter refuses a second concurrent rotation).
|
|
74
|
+
* The returned {@link RotationHandle} MUST be passed back to
|
|
75
|
+
* {@link commitBrokerTokenRotation} / {@link rollbackBrokerTokenRotation} so a
|
|
76
|
+
* stale (superseded) commit/rollback cannot clobber a newer rotation.
|
|
77
|
+
*/
|
|
78
|
+
rotateBrokerToken(): RotationHandle | null;
|
|
79
|
+
/**
|
|
80
|
+
* Confirm a grace rotation: the helper file now holds the new token, so the
|
|
81
|
+
* prior (grace) token stops authenticating (single-active-token restored).
|
|
82
|
+
* Generation-bound (Finding 3): pass the {@link RotationHandle} from the
|
|
83
|
+
* matching {@link rotateBrokerToken}; a stale handle is a no-op.
|
|
84
|
+
*/
|
|
85
|
+
commitBrokerTokenRotation(handle?: RotationHandle): void;
|
|
86
|
+
/**
|
|
87
|
+
* Roll back a grace rotation whose file rewrite FAILED: the prior token is
|
|
88
|
+
* restored as current (still in the agent's file, still valid) and the new
|
|
89
|
+
* token is discarded. No dead-token window. Generation-bound (Finding 3): pass
|
|
90
|
+
* the {@link RotationHandle} from the matching {@link rotateBrokerToken}.
|
|
91
|
+
*/
|
|
92
|
+
rollbackBrokerTokenRotation(handle?: RotationHandle): void;
|
|
93
|
+
getVendorKey(provider: VendorProvider): Promise<string | null>;
|
|
94
|
+
setVendorKey(provider: VendorProvider, key: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Handle one broker request (§3.2). The pure, transport-agnostic core —
|
|
97
|
+
* the HTTP server (`handleHttp`) adapts node req/res onto this. Route
|
|
98
|
+
* table check first (everything else → 403), then broker-token auth on
|
|
99
|
+
* the two POSTs (the ONLY 401 is an invalid agent→broker token), then
|
|
100
|
+
* the per-provider gateway (§3.3/§3.4/§3.5).
|
|
101
|
+
*/
|
|
102
|
+
handle(req: BrokerRequest): Promise<BrokerResponse>;
|
|
103
|
+
private gateway;
|
|
104
|
+
/**
|
|
105
|
+
* Load the vendor key, caching it in-process, and emit
|
|
106
|
+
* `broker_credential_loaded` (§3.5) on each keychain load — with a
|
|
107
|
+
* `key_fingerprint` (sha256 prefix) and a fresh `credential_issuance_id`,
|
|
108
|
+
* NEVER the key. The credential-loaded audit is best-effort (it does not
|
|
109
|
+
* gate the forward — the `model_call` row does); a lost load-audit is a
|
|
110
|
+
* forensic gap, not an unsafe effect.
|
|
111
|
+
*/
|
|
112
|
+
private loadVendorKey;
|
|
113
|
+
private lastIssuanceId;
|
|
114
|
+
/**
|
|
115
|
+
* Map an upstream response to the agent-facing status (§3.2). An upstream
|
|
116
|
+
* 401/403 (bad/expired vendor key) → 502 (NOT a pass-through 401, which
|
|
117
|
+
* would loop the agent's token-refresh hook). Every other status carries
|
|
118
|
+
* through; the body is the upstream JSON on success.
|
|
119
|
+
*/
|
|
120
|
+
private mapUpstream;
|
|
121
|
+
/**
|
|
122
|
+
* Best-effort extraction of the requested model name for the audit row.
|
|
123
|
+
*
|
|
124
|
+
* OWN-property check ONLY (Codex W1 R3 prototype-pollution class). The
|
|
125
|
+
* body originates from `JSON.parse`, so a `{"__proto__":{"model":"<secret>"}}`
|
|
126
|
+
* payload could leave an INHERITED `model` on the prototype chain. A bare
|
|
127
|
+
* `"model" in body` / `body.model` would WALK the chain and read that
|
|
128
|
+
* injected secret straight into the durable `model_call.model` audit row
|
|
129
|
+
* (exfil). `Object.hasOwn` + an own-only read see ONLY a real top-level
|
|
130
|
+
* `$.model`; an inherited one is invisible → audited `model` is `"unknown"`,
|
|
131
|
+
* never the leaked value. (This is also fed the POST-scrub body, so even a
|
|
132
|
+
* real secret-shaped own `$.model` is already redacted by the scrubber —
|
|
133
|
+
* Codex W1 R1; the own-only read closes the inherited-property variant.)
|
|
134
|
+
*/
|
|
135
|
+
private extractModel;
|
|
136
|
+
/** Best-effort token/cost extraction from an upstream response body. */
|
|
137
|
+
private extractUsage;
|
|
138
|
+
/**
|
|
139
|
+
* Emit a PRE-FORWARD (gated) audit row and BLOCK for a durable ACK
|
|
140
|
+
* (§3.5 audit-before-effect). Returns true ONLY on `{ack}`; a `{nack}`,
|
|
141
|
+
* a rejected promise (IPC failure), or any thrown error → false (the
|
|
142
|
+
* caller fails closed: 503, no forward). A security audit cannot
|
|
143
|
+
* silently drop.
|
|
144
|
+
*/
|
|
145
|
+
private emitGated;
|
|
146
|
+
/**
|
|
147
|
+
* Emit a BEST-EFFORT audit row (`model_call_result` post-response,
|
|
148
|
+
* `broker_credential_loaded`). Losing it is a cost-tracking / forensic
|
|
149
|
+
* gap, never a security-invariant violation — so it never gates an
|
|
150
|
+
* effect and swallows nack/error.
|
|
151
|
+
*/
|
|
152
|
+
private emitBestEffort;
|
|
153
|
+
/**
|
|
154
|
+
* Adapt a node HTTP request/response onto `handle`. Extracts the broker
|
|
155
|
+
* token (Anthropic `x-api-key` / `authorization: Bearer`; OpenAI
|
|
156
|
+
* `authorization: Bearer`), the agent headers/query/content-type, and the
|
|
157
|
+
* JSON body, then writes the `BrokerResponse` back. A malformed JSON body
|
|
158
|
+
* on a model POST → 400 (outside the canonical shape).
|
|
159
|
+
*/
|
|
160
|
+
private handleHttp;
|
|
161
|
+
private extractBrokerToken;
|
|
162
|
+
private readBody;
|
|
163
|
+
private writeJson;
|
|
164
|
+
}
|
|
165
|
+
export { getProviderConfig };
|