@quantiya/codevibe-core 2.0.0 → 2.0.1

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.
Files changed (170) hide show
  1. package/dist/__tests__/cp-5-baseline-invariants.test.d.ts +1 -0
  2. package/dist/adapter/__tests__/capabilities.test.d.ts +1 -0
  3. package/dist/adapter/__tests__/contract-conformance.test.d.ts +1 -0
  4. package/dist/adapter/__tests__/packets.test.d.ts +1 -0
  5. package/dist/adapter/__tests__/progress.test.d.ts +1 -0
  6. package/dist/adapter/__tests__/registry.test.d.ts +1 -0
  7. package/dist/adapter/__tests__/smoke/claude.smoke.test.d.ts +1 -0
  8. package/dist/adapter/__tests__/smoke/codex.smoke.test.d.ts +1 -0
  9. package/dist/adapter/__tests__/smoke/gemini.smoke.test.d.ts +1 -0
  10. package/dist/adapter/capabilities.d.ts +68 -0
  11. package/dist/adapter/index.d.ts +7 -0
  12. package/dist/adapter/packets.d.ts +129 -0
  13. package/dist/adapter/progress.d.ts +93 -0
  14. package/dist/adapter/registry.d.ts +24 -0
  15. package/dist/adapter/types.d.ts +22 -0
  16. package/dist/appsync/__tests__/appsync-client-apply-user-decision.test.d.ts +1 -0
  17. package/dist/appsync/__tests__/appsync-client-classb.test.d.ts +1 -0
  18. package/dist/appsync/__tests__/appsync-client-planner.test.d.ts +1 -0
  19. package/dist/appsync/__tests__/appsync-client.test.d.ts +1 -0
  20. package/dist/appsync/appsync-client.d.ts +412 -0
  21. package/dist/appsync/index.d.ts +1 -1
  22. package/dist/appsync/queries.d.ts +15 -0
  23. package/dist/auth/__tests__/auth-telemetry.test.d.ts +1 -0
  24. package/dist/auth/auth-telemetry.d.ts +98 -5
  25. package/dist/companion-mode/__tests__/persist-preference.test.d.ts +1 -0
  26. package/dist/companion-mode/__tests__/resolve-agent.test.d.ts +1 -0
  27. package/dist/companion-mode/agent-picker.d.ts +9 -0
  28. package/dist/companion-mode/index.d.ts +55 -0
  29. package/dist/companion-mode/persist-preference.d.ts +24 -0
  30. package/dist/companion-mode/resolve-agent.d.ts +41 -0
  31. package/dist/index.d.ts +11 -3
  32. package/dist/index.js +243 -42
  33. package/dist/keychain/keychain-manager.d.ts +16 -2
  34. package/dist/local-executor/__tests__/authority-symlink-fixture.d.ts +15 -0
  35. package/dist/local-executor/__tests__/authority.test.d.ts +1 -0
  36. package/dist/local-executor/__tests__/class-a-emit.test.d.ts +1 -0
  37. package/dist/local-executor/__tests__/class-b-consumer.integration.test.d.ts +1 -0
  38. package/dist/local-executor/__tests__/class-b-consumer.test.d.ts +1 -0
  39. package/dist/local-executor/__tests__/hook-bridge.test.d.ts +1 -0
  40. package/dist/local-executor/__tests__/local-executor.integration.test.d.ts +1 -0
  41. package/dist/local-executor/__tests__/spawn.test.d.ts +1 -0
  42. package/dist/local-executor/__tests__/verification-runner.test.d.ts +1 -0
  43. package/dist/local-executor/authority.d.ts +29 -0
  44. package/dist/local-executor/class-a-emit.d.ts +138 -0
  45. package/dist/local-executor/class-b-consumer.d.ts +121 -0
  46. package/dist/local-executor/hook-bridge.d.ts +36 -0
  47. package/dist/local-executor/index.d.ts +8 -0
  48. package/dist/local-executor/local-executor-impl.d.ts +83 -0
  49. package/dist/local-executor/spawn.d.ts +6 -0
  50. package/dist/local-executor/types.d.ts +183 -0
  51. package/dist/local-executor/verification-gates/build.d.ts +6 -0
  52. package/dist/local-executor/verification-gates/deploy-preflight.d.ts +6 -0
  53. package/dist/local-executor/verification-gates/diff-sanity.d.ts +6 -0
  54. package/dist/local-executor/verification-gates/hostile-grep.d.ts +6 -0
  55. package/dist/local-executor/verification-gates/lint.d.ts +6 -0
  56. package/dist/local-executor/verification-gates/shell-runner.d.ts +40 -0
  57. package/dist/local-executor/verification-gates/source-traceability.d.ts +6 -0
  58. package/dist/local-executor/verification-gates/tests.d.ts +6 -0
  59. package/dist/local-executor/verification-gates/typecheck.d.ts +6 -0
  60. package/dist/local-executor/verification-runner.d.ts +28 -0
  61. package/dist/orchestration/__tests__/setup-bootstrap.test.d.ts +1 -0
  62. package/dist/orchestration/__tests__/setup-failure-recourse.test.d.ts +1 -0
  63. package/dist/orchestration/__tests__/setup-save.test.d.ts +1 -0
  64. package/dist/orchestration/__tests__/setup-seat-picker.test.d.ts +1 -0
  65. package/dist/orchestration/__tests__/setup-telemetry.test.d.ts +1 -0
  66. package/dist/orchestration/__tests__/setup-test-agents.test.d.ts +1 -0
  67. package/dist/orchestration/__tests__/setup-types.test.d.ts +1 -0
  68. package/dist/orchestration/__tests__/setup-wizard.test.d.ts +1 -0
  69. package/dist/orchestration/__tests__/v1-options.test.d.ts +1 -0
  70. package/dist/orchestration/detect-agents.d.ts +2 -1
  71. package/dist/orchestration/index.d.ts +1 -0
  72. package/dist/orchestration/orchestration-cli.d.ts +4 -1
  73. package/dist/orchestration/setup-bootstrap.d.ts +146 -0
  74. package/dist/orchestration/setup-failure-recourse.d.ts +23 -0
  75. package/dist/orchestration/setup-save.d.ts +47 -0
  76. package/dist/orchestration/setup-seat-picker.d.ts +72 -0
  77. package/dist/orchestration/setup-telemetry.d.ts +54 -0
  78. package/dist/orchestration/setup-test-agents.d.ts +108 -0
  79. package/dist/orchestration/setup-types.d.ts +140 -0
  80. package/dist/orchestration/setup-wizard.d.ts +57 -0
  81. package/dist/orchestration/v1-options.d.ts +97 -0
  82. package/dist/orchestration-shell/__tests__/cli-authority-bridge.test.d.ts +1 -0
  83. package/dist/orchestration-shell/__tests__/cli-planner-stack.test.d.ts +1 -0
  84. package/dist/orchestration-shell/__tests__/cli-singleton-enforcement.test.d.ts +1 -0
  85. package/dist/orchestration-shell/__tests__/cli-stub-session-adapter.test.d.ts +1 -0
  86. package/dist/orchestration-shell/__tests__/components.test.d.ts +1 -0
  87. package/dist/orchestration-shell/__tests__/emit-shell-event.test.d.ts +1 -0
  88. package/dist/orchestration-shell/__tests__/gate-prompts.test.d.ts +1 -0
  89. package/dist/orchestration-shell/__tests__/hostile-grep.test.d.ts +1 -0
  90. package/dist/orchestration-shell/__tests__/mode-selection.test.d.ts +1 -0
  91. package/dist/orchestration-shell/__tests__/process-markers.test.d.ts +1 -0
  92. package/dist/orchestration-shell/__tests__/reducer.test.d.ts +1 -0
  93. package/dist/orchestration-shell/__tests__/runOrchestrationShell-classify-dispatch.test.d.ts +1 -0
  94. package/dist/orchestration-shell/__tests__/runOrchestrationShell-planner-wiring.test.d.ts +1 -0
  95. package/dist/orchestration-shell/__tests__/runOrchestrationShell-signal.test.d.ts +1 -0
  96. package/dist/orchestration-shell/__tests__/runOrchestrationShell.test.d.ts +1 -0
  97. package/dist/orchestration-shell/__tests__/slash-router.test.d.ts +1 -0
  98. package/dist/orchestration-shell/__tests__/sticky-preference.test.d.ts +1 -0
  99. package/dist/orchestration-shell/cli.d.ts +96 -0
  100. package/dist/orchestration-shell/cli.js +8309 -0
  101. package/dist/orchestration-shell/cohort-flag.d.ts +16 -0
  102. package/dist/orchestration-shell/components/CodeVibeLogo.d.ts +2 -0
  103. package/dist/orchestration-shell/components/ConversationPane.d.ts +7 -0
  104. package/dist/orchestration-shell/components/GatePromptEntry.d.ts +9 -0
  105. package/dist/orchestration-shell/components/InputBar.d.ts +41 -0
  106. package/dist/orchestration-shell/components/OrchestrationApp.d.ts +63 -0
  107. package/dist/orchestration-shell/components/StatusBar.d.ts +7 -0
  108. package/dist/orchestration-shell/components/nodes/AdvisoryEntry.d.ts +8 -0
  109. package/dist/orchestration-shell/components/nodes/GateStatusNode.d.ts +8 -0
  110. package/dist/orchestration-shell/components/nodes/PlannerDecisionEntry.d.ts +8 -0
  111. package/dist/orchestration-shell/components/nodes/ReviewerQuorumStatusNode.d.ts +8 -0
  112. package/dist/orchestration-shell/components/nodes/SlashOutputEntry.d.ts +8 -0
  113. package/dist/orchestration-shell/components/nodes/SubagentEventEntry.d.ts +8 -0
  114. package/dist/orchestration-shell/components/nodes/UserMessageEntry.d.ts +8 -0
  115. package/dist/orchestration-shell/emit-shell-event.d.ts +64 -0
  116. package/dist/orchestration-shell/gate-prompts.d.ts +123 -0
  117. package/dist/orchestration-shell/index.d.ts +100 -0
  118. package/dist/orchestration-shell/ink-runtime.d.ts +64 -0
  119. package/dist/orchestration-shell/mode-selection.d.ts +46 -0
  120. package/dist/orchestration-shell/non-tty-fallback.d.ts +46 -0
  121. package/dist/orchestration-shell/process-markers.d.ts +12 -0
  122. package/dist/orchestration-shell/reducer.d.ts +8 -0
  123. package/dist/orchestration-shell/slash-router.d.ts +45 -0
  124. package/dist/orchestration-shell/sticky-preference.d.ts +24 -0
  125. package/dist/orchestration-shell/store.d.ts +17 -0
  126. package/dist/orchestration-shell/types.d.ts +417 -0
  127. package/dist/planner/__tests__/cache-clarification-bypass.test.d.ts +1 -0
  128. package/dist/planner/__tests__/cache.test.d.ts +1 -0
  129. package/dist/planner/__tests__/client.test.d.ts +1 -0
  130. package/dist/planner/__tests__/health-machine-transitions.test.d.ts +1 -0
  131. package/dist/planner/__tests__/types-zod.test.d.ts +1 -0
  132. package/dist/planner/adapter.d.ts +16 -0
  133. package/dist/planner/cache.d.ts +35 -0
  134. package/dist/planner/client.d.ts +103 -0
  135. package/dist/planner/health-state.d.ts +24 -0
  136. package/dist/planner/index.d.ts +5 -0
  137. package/dist/planner/types.d.ts +113 -0
  138. package/dist/session/__tests__/session-resume-service-keys.test.d.ts +1 -0
  139. package/dist/session/session-rekey.d.ts +40 -0
  140. package/dist/session/session-resume.d.ts +25 -0
  141. package/dist/structural-summary/__tests__/__fixtures__/fixture-helpers.d.ts +11 -0
  142. package/dist/structural-summary/__tests__/assembler.test.d.ts +1 -0
  143. package/dist/structural-summary/__tests__/generator.test.d.ts +1 -0
  144. package/dist/structural-summary/__tests__/language-detect.test.d.ts +1 -0
  145. package/dist/structural-summary/__tests__/manifest-parsers/cargo.test.d.ts +1 -0
  146. package/dist/structural-summary/__tests__/manifest-parsers/gomod.test.d.ts +1 -0
  147. package/dist/structural-summary/__tests__/manifest-parsers/gradle.test.d.ts +1 -0
  148. package/dist/structural-summary/__tests__/manifest-parsers/index.test.d.ts +1 -0
  149. package/dist/structural-summary/__tests__/manifest-parsers/npm.test.d.ts +1 -0
  150. package/dist/structural-summary/__tests__/manifest-parsers/podfile.test.d.ts +1 -0
  151. package/dist/structural-summary/__tests__/manifest-parsers/pyproject.test.d.ts +1 -0
  152. package/dist/structural-summary/__tests__/opt-in-store.test.d.ts +1 -0
  153. package/dist/structural-summary/__tests__/privacy-filter.test.d.ts +1 -0
  154. package/dist/structural-summary/__tests__/safe-file-read.test.d.ts +1 -0
  155. package/dist/structural-summary/__tests__/user-ignore-matcher.test.d.ts +1 -0
  156. package/dist/structural-summary/__tests__/walker.test.d.ts +1 -0
  157. package/dist/structural-summary/generator.d.ts +8 -0
  158. package/dist/structural-summary/index.d.ts +7 -0
  159. package/dist/structural-summary/manifest-parsers/cargo.d.ts +3 -0
  160. package/dist/structural-summary/manifest-parsers/index.d.ts +7 -0
  161. package/dist/structural-summary/manifest-parsers/npm.d.ts +3 -0
  162. package/dist/structural-summary/manifest-parsers/other.d.ts +17 -0
  163. package/dist/structural-summary/opt-in-store.d.ts +24 -0
  164. package/dist/structural-summary/privacy-filter.d.ts +110 -0
  165. package/dist/structural-summary/safe-file-read.d.ts +11 -0
  166. package/dist/structural-summary/types.d.ts +215 -0
  167. package/dist/structural-summary/user-ignore-matcher.d.ts +9 -0
  168. package/dist/structural-summary/walker.d.ts +20 -0
  169. package/dist/types/events.d.ts +17 -2
  170. package/package.json +17 -3
@@ -91,14 +91,28 @@ export declare class KeychainManager {
91
91
  */
92
92
  getSessionKey(sessionId: string, encryptedKeys?: EncryptedSessionKey[]): Promise<string | null>;
93
93
  /**
94
- * Generate and encrypt a new session key for all devices
94
+ * Generate and encrypt a new session key for all devices.
95
+ *
96
+ * Per-device try/catch (task #331 Bug B): one bad publicKey (corrupted
97
+ * base64, wrong curve, ECDH derive failure) does NOT abort the whole
98
+ * call — that device is skipped and reported in `skippedDeviceIds`. The
99
+ * caller decides what to do (telemetry, partial-success UX). Throw only
100
+ * if NO device succeeded, preserving the existing "no encryption"
101
+ * fallback at `prepareSessionEncryption`.
102
+ *
103
+ * Optional `onDeviceSkipped` callback fires per-skip for telemetry —
104
+ * intentionally a callback rather than a direct beacon import so this
105
+ * module stays free of analytics dependencies.
95
106
  */
96
107
  createSessionKey(devicePublicKeys: Array<{
97
108
  deviceId: string;
98
109
  publicKey: string;
99
- }>): {
110
+ }>, options?: {
111
+ onDeviceSkipped?: (totalSkippedSoFar: number) => void;
112
+ }): {
100
113
  sessionKey: string;
101
114
  encryptedKeys: EncryptedSessionKey[];
115
+ skippedDeviceIds: string[];
102
116
  };
103
117
  /**
104
118
  * Cache a session key
@@ -0,0 +1,15 @@
1
+ import type { AuthorityScope } from '../authority';
2
+ export interface SymlinkBypassFixture {
3
+ tmpRoot: string;
4
+ insideScope: string;
5
+ outsideScope: string;
6
+ outsideTarget: string;
7
+ attemptViaSymlink: string;
8
+ scope: AuthorityScope;
9
+ }
10
+ export interface CreateSymlinkBypassFixtureOptions {
11
+ parentMissing?: boolean;
12
+ }
13
+ export declare function createSymlinkBypassFixture(options?: CreateSymlinkBypassFixtureOptions): Promise<SymlinkBypassFixture>;
14
+ export declare function cleanupFixture(fixture: SymlinkBypassFixture): Promise<void>;
15
+ export declare function makeEmptyExpiredScope(): AuthorityScope;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { promises as fs } from 'node:fs';
2
+ export interface AuthorityScope {
3
+ writeScopes: string[];
4
+ readScopes: string[];
5
+ networkAllowed: boolean;
6
+ commandAllowlist: string[];
7
+ expiresAt: string;
8
+ }
9
+ export type AuthorityRefusalCategory = 'authority_scope_conflict' | 'signature_invalid' | 'ulid_replay' | 'policy_rejection';
10
+ export interface AuthorityRefusal {
11
+ category: AuthorityRefusalCategory;
12
+ detail: string;
13
+ }
14
+ export declare class AuthorityError extends Error {
15
+ readonly refusal: AuthorityRefusal;
16
+ constructor(refusal: AuthorityRefusal);
17
+ }
18
+ export declare class FileNotFound extends Error {
19
+ readonly canonicalPath: string;
20
+ constructor(canonicalPath: string, cause?: unknown);
21
+ }
22
+ export declare function enforceWrite(scope: AuthorityScope, p: string): Promise<string>;
23
+ export declare function safeWriteFile(scope: AuthorityScope, p: string, data: Buffer | string, options?: Parameters<typeof fs.writeFile>[2]): Promise<void>;
24
+ export declare function enforceRead(scope: AuthorityScope, p: string): Promise<string>;
25
+ export declare function safeReadFile(scope: AuthorityScope, p: string, options?: {
26
+ encoding?: BufferEncoding;
27
+ }): Promise<string | Buffer>;
28
+ export declare function enforceNetwork(scope: AuthorityScope): void;
29
+ export declare function enforceCommand(scope: AuthorityScope, argv: string[]): void;
@@ -0,0 +1,138 @@
1
+ import type { AdapterProgressEnvelope } from '../adapter/progress';
2
+ import { AuthorityRefusal, AuthorityRefusalCategory } from './authority';
3
+ import { AgentKind, FailureClass, ProcessRole } from './types';
4
+ export type ExecutionEventKind = 'PROCESS_SPAWNED' | 'TOOL_USE' | 'FILE_CHANGE' | 'VERIFICATION_RUN' | 'PROCESS_EXITED';
5
+ export type ClassAMessageType = 'EXECUTION_EVENT' | 'EXECUTOR_REFUSAL' | 'VERIFICATION_RESULT' | 'ADAPTER_PROGRESS';
6
+ export interface ClassAEnvelope {
7
+ messageVersion: 1;
8
+ messageType: ClassAMessageType;
9
+ messageId: string;
10
+ taskId: string;
11
+ sessionId: string;
12
+ userId: string;
13
+ tenantId: string;
14
+ deviceId: string;
15
+ occurredAt: string;
16
+ payload: unknown;
17
+ signature?: string;
18
+ }
19
+ export interface ProcessSpawnedPayload {
20
+ kind: 'PROCESS_SPAWNED';
21
+ processRole: ProcessRole;
22
+ pid: number;
23
+ adapter: AgentKind;
24
+ }
25
+ export interface ToolUsePayload {
26
+ kind: 'TOOL_USE';
27
+ toolName: string;
28
+ bounded: boolean;
29
+ toolInputDigest: string;
30
+ }
31
+ export interface FileChangePayload {
32
+ kind: 'FILE_CHANGE';
33
+ repoPath: string;
34
+ changeSummary: {
35
+ added: number;
36
+ modified: number;
37
+ deleted: number;
38
+ };
39
+ diffDigest: string;
40
+ }
41
+ export interface VerificationRunPayload {
42
+ kind: 'VERIFICATION_RUN';
43
+ check: string;
44
+ passed: boolean;
45
+ runtimeMs: number;
46
+ }
47
+ export interface ProcessExitedPayload {
48
+ kind: 'PROCESS_EXITED';
49
+ pid: number;
50
+ exitCode: number;
51
+ failureClass: FailureClass;
52
+ }
53
+ export interface ExecutorRefusalPayload {
54
+ refusedMessageId: string;
55
+ refusalCategory: AuthorityRefusalCategory;
56
+ refusalDetail: string;
57
+ recommendedRecovery: 'reauthorize_locally' | 'abort_task' | 'ask_user' | 'retry_after_resync';
58
+ }
59
+ export type VerificationGateKind = 'build' | 'tests' | 'lint' | 'typecheck' | 'hostile_grep' | 'source_traceability' | 'diff_sanity' | 'deploy_preflight';
60
+ export interface VerificationResultPayload {
61
+ gate_kind: VerificationGateKind;
62
+ status: 'PASS' | 'FAIL';
63
+ exit_code: number;
64
+ stdout_summary_truncated: string;
65
+ stderr_summary_truncated: string;
66
+ duration_ms: number;
67
+ }
68
+ export interface ClassASink {
69
+ emit(envelope: ClassAEnvelope): Promise<void>;
70
+ }
71
+ export declare class LocalStubSink implements ClassASink {
72
+ private readonly logPath;
73
+ constructor(logPath: string);
74
+ emit(envelope: ClassAEnvelope): Promise<void>;
75
+ }
76
+ export interface ClassAEmitterContext {
77
+ taskId: string;
78
+ sessionId: string;
79
+ userId: string;
80
+ tenantId: string;
81
+ deviceId: string;
82
+ }
83
+ export declare const DEFAULT_DEDUPE_CAP = 10000;
84
+ export declare function isValidUlid(s: string): boolean;
85
+ export interface EmitterLogger {
86
+ debug(msg: string, meta?: Record<string, unknown>): void;
87
+ }
88
+ export declare class ClassAEmitter {
89
+ private readonly sink;
90
+ private readonly cap;
91
+ private readonly logger?;
92
+ private readonly seenUlids;
93
+ private readonly messageIdFactory;
94
+ constructor(sink: ClassASink, seenUlids?: Set<string>, cap?: number, logger?: EmitterLogger | undefined, messageIdFactory?: () => string);
95
+ emitProcessSpawned(ctx: ClassAEmitterContext, args: {
96
+ pid: number;
97
+ processRole: ProcessRole;
98
+ adapter: AgentKind;
99
+ occurredAt?: string;
100
+ }): Promise<void>;
101
+ emitToolUse(ctx: ClassAEmitterContext, args: {
102
+ toolName: string;
103
+ toolInputDigest: string;
104
+ bounded?: boolean;
105
+ occurredAt?: string;
106
+ }): Promise<void>;
107
+ emitFileChange(ctx: ClassAEmitterContext, args: {
108
+ repoPath: string;
109
+ changeSummary: FileChangePayload['changeSummary'];
110
+ diffDigest: string;
111
+ occurredAt?: string;
112
+ }): Promise<void>;
113
+ emitVerificationRun(ctx: ClassAEmitterContext, args: {
114
+ check: string;
115
+ passed: boolean;
116
+ runtimeMs: number;
117
+ occurredAt?: string;
118
+ }): Promise<void>;
119
+ emitProcessExited(ctx: ClassAEmitterContext, args: {
120
+ pid: number;
121
+ exitCode: number;
122
+ failureClass: FailureClass;
123
+ occurredAt?: string;
124
+ }): Promise<void>;
125
+ emitExecutorRefusal(ctx: ClassAEmitterContext, args: {
126
+ refusal: AuthorityRefusal;
127
+ refusedMessageId: string;
128
+ recommendedRecovery?: ExecutorRefusalPayload['recommendedRecovery'];
129
+ occurredAt?: string;
130
+ }): Promise<void>;
131
+ submitVerificationResultClassAEvent(ctx: ClassAEmitterContext, payload: VerificationResultPayload, occurredAt?: string): Promise<void>;
132
+ submitAdapterProgressClassAEvent(ctx: ClassAEmitterContext, envelope: AdapterProgressEnvelope, occurredAt?: string): Promise<void>;
133
+ private emitExecutionEvent;
134
+ private buildEnvelope;
135
+ private dispatchWithDedupe;
136
+ /** @internal */
137
+ get seenUlidsForTests(): ReadonlySet<string>;
138
+ }
@@ -0,0 +1,121 @@
1
+ import type { AuthorityScope } from './authority';
2
+ import { ClassAEmitter, ClassAEmitterContext } from './class-a-emit';
3
+ import { EmitShellEventFn } from './hook-bridge';
4
+ import { ClassBInbound } from './types';
5
+ export type ClassBVerificationResult = {
6
+ ok: true;
7
+ } | {
8
+ ok: false;
9
+ reason: 'malformed_envelope' | 'algorithm_unsupported';
10
+ };
11
+ /**
12
+ * CP-1.e signature-verification STUB per design §4.1.
13
+ *
14
+ * Returns `{ ok: false }` on:
15
+ * - missing/empty `signedEnvelope` or `signatureB64`
16
+ * - unsupported `algorithm` (only `ed25519` / `p384-ecdsa` per CP-0 §2.3 enum)
17
+ * - missing/empty `publicKeyId`
18
+ * - missing/malformed `nonceUlid` (must be 26-char ULID)
19
+ *
20
+ * Returns `{ ok: true }` for every structurally-well-formed envelope. CP-2
21
+ * Stage A replaces the implementation with real signature verification but
22
+ * preserves this exact return-type contract (LOCK #E1-1 stability).
23
+ */
24
+ export declare function verifyClassBSignature(envelope: ClassBInbound): ClassBVerificationResult;
25
+ export declare const INBOUND_REPLAY_CAP = 10000;
26
+ export declare const INBOUND_REPLAY_TTL_MS: number;
27
+ /**
28
+ * INBOUND ULID-replay registry per design §5.1 + CP-0 §2.5 invariant #5.
29
+ *
30
+ * SCOPE DISAMBIGUATION (LOCK inherited from CP-1.c §6.2):
31
+ * - OUTBOUND emitter dedupe = `ClassAEmitter.seenUlids` (CP-1.c scope).
32
+ * - INBOUND consumer replay refusal = this class (CP-1.e scope).
33
+ *
34
+ * Bounded memory: 10K LRU entries × 24h TTL. Sweep is O(n) worst case but
35
+ * amortizes O(1) per insert because JS Map iterates in insertion order — a
36
+ * single non-expired entry means all subsequent ones are non-expired.
37
+ */
38
+ export declare class UlidReplayRegistry {
39
+ private readonly cap;
40
+ private readonly ttlMs;
41
+ private readonly nowMs;
42
+ private readonly seenAt;
43
+ constructor(cap?: number, ttlMs?: number, nowMs?: () => number);
44
+ /**
45
+ * Returns `true` if the ULID is a replay (already seen within the active
46
+ * window). On `false`, the ULID is inserted and the registry is swept for
47
+ * expired entries + cap overflow.
48
+ */
49
+ checkAndInsert(ulid: string): boolean;
50
+ private sweepExpired;
51
+ /** Test-only — exposes seen-set size. */
52
+ get sizeForTests(): number;
53
+ }
54
+ export interface ClassBConsumerState {
55
+ /** Last received PlannerDecisionApproved per taskId; CP-2 reads. */
56
+ plannerDecisionByTask: Map<string, Extract<ClassBInbound, {
57
+ kind: 'PlannerDecisionApproved';
58
+ }>>;
59
+ /** Last received GateDispatch per gateRunId; CP-2 reads. */
60
+ gateDispatchByRun: Map<string, Extract<ClassBInbound, {
61
+ kind: 'GateDispatch';
62
+ }>>;
63
+ /** Last received ContinuationOffer per handoffId; CP-2 reads. */
64
+ continuationOfferByHandoff: Map<string, Extract<ClassBInbound, {
65
+ kind: 'ContinuationOffer';
66
+ }>>;
67
+ }
68
+ export interface ClassBConsumerDeps {
69
+ emitter: ClassAEmitter;
70
+ emitShellEvent: EmitShellEventFn;
71
+ getContext: () => ClassAEmitterContext;
72
+ /** Called on TaskAuthorized to mutate the LocalExecutorImpl's authority scope (CP-0 §2.5 invariant #6). */
73
+ advanceAuthorityScope: (newScope: AuthorityScope, taskId: string) => void;
74
+ /** Called on PolicyRejection to surface the rejection to the user (LOCK C4-3 user-visible channel). */
75
+ notifyPolicyRejection?: (detail: string, category: string, recommendedRecovery: string) => void;
76
+ /** Test seam for deterministic UlidReplayRegistry behavior. */
77
+ replayRegistry?: UlidReplayRegistry;
78
+ }
79
+ /**
80
+ * Class B inbound consumer per design §6.1.
81
+ *
82
+ * Single-entrypoint `consume(packet)` enforces LOCK #E3-1 ordering:
83
+ * 1. verify (LOCK #E1-1 — refuses signature_invalid via Class A audit)
84
+ * 2. replay-check (LOCK #E2-1 — refuses ulid_replay via Class A audit)
85
+ * 3. per-kind dispatch (5 locked variants per CP-0 §2.F.9-§2.F.13)
86
+ *
87
+ * Reverse ordering would let a tampered-but-replayed envelope advance state —
88
+ * explicitly forbidden by LOCK #E3-1.
89
+ */
90
+ export declare class ClassBConsumer {
91
+ private readonly deps;
92
+ private readonly state;
93
+ private readonly replayRegistry;
94
+ constructor(deps: ClassBConsumerDeps);
95
+ consume(packet: ClassBInbound): Promise<void>;
96
+ private handlePlannerDecisionApproved;
97
+ private handleGateDispatch;
98
+ private handleContinuationOffer;
99
+ private handleTaskAuthorized;
100
+ private handlePolicyRejection;
101
+ /**
102
+ * Constructs an AuthorityRefusal with one of the LOCK #E4-1 widened category
103
+ * literals and emits an EXECUTOR_REFUSAL via the CP-1.c emitter. Audit-only:
104
+ * the user-visible NOTIFICATION channel is reserved for PolicyRejection (the
105
+ * only Class B variant that surfaces hosted policy decisions to the user).
106
+ *
107
+ * `recommendedRecovery` is derived per-category to match CP-0 §2.F.14 fixture
108
+ * row literals verbatim on the wire (was Codex Stage-2 r1 H-1 — emitter
109
+ * default `'reauthorize_locally'` is correct for `authority_scope_conflict`
110
+ * (CP-1.c authority paths) but wrong for the CP-1.e Class-B variants):
111
+ * - signature_invalid → 'retry_after_resync' (CP-0 fixture line 458)
112
+ * - ulid_replay → 'abort_task' (CP-0 fixture line 486)
113
+ * - policy_rejection → 'ask_user' (consumer of policy reject)
114
+ * - authority_scope_conflict → 'reauthorize_locally' (inherited CP-1.c default)
115
+ */
116
+ private refuseWithCategory;
117
+ /** Test-only — exposes cached-decision registry for §6.4 assertions. */
118
+ get stateForTests(): Readonly<ClassBConsumerState>;
119
+ /** Test-only — exposes replay registry for §5.3 / §6.4 introspection. */
120
+ get replayRegistryForTests(): UlidReplayRegistry;
121
+ }
@@ -0,0 +1,36 @@
1
+ import { AuthorityError, AuthorityScope } from './authority';
2
+ import { ClassAEmitter, ClassAEmitterContext } from './class-a-emit';
3
+ import { AgentKind, HookEvent } from './types';
4
+ export type EmitShellEventFn = (args: {
5
+ sessionId: string;
6
+ type: 'USER_PROMPT' | 'ASSISTANT_RESPONSE' | 'INTERACTIVE_PROMPT' | 'LOCAL_AUTHORITY_REFUSAL' | 'NOTIFICATION';
7
+ content?: string;
8
+ metadata?: Record<string, unknown>;
9
+ timestamp?: string;
10
+ }) => Promise<void>;
11
+ export interface HookBridgeDeps {
12
+ emitter: ClassAEmitter;
13
+ emitShellEvent: EmitShellEventFn;
14
+ getAuthorityScope: () => AuthorityScope;
15
+ getCurrentTaskId: () => string | null;
16
+ getContextWithoutTask: () => Omit<ClassAEmitterContext, 'taskId'>;
17
+ adapter: AgentKind;
18
+ }
19
+ export declare class HookBridge {
20
+ private readonly deps;
21
+ constructor(deps: HookBridgeDeps);
22
+ ingest(event: HookEvent): Promise<void>;
23
+ private translateToolUse;
24
+ private translateFileChange;
25
+ private translateProcessExited;
26
+ private translateUserPrompt;
27
+ private translateAssistantText;
28
+ bridgeAuthorityRefusal(err: AuthorityError, args: {
29
+ refusedMessageId: string;
30
+ shellContent: string;
31
+ shellMetadata?: Record<string, unknown>;
32
+ }): Promise<void>;
33
+ private contextOrNull;
34
+ /** @internal */
35
+ get adapterForTests(): AgentKind;
36
+ }
@@ -0,0 +1,8 @@
1
+ export { AuthorityError, AuthorityRefusal, AuthorityRefusalCategory, AuthorityScope, FileNotFound, enforceCommand, enforceNetwork, enforceRead, enforceWrite, safeReadFile, safeWriteFile, } from './authority';
2
+ export { spawnHealthProbe, spawnImplementor, spawnReviewer } from './spawn';
3
+ export { AgentKind, AuthorityAction, ClassBInbound, ExecutorError, FailureClass, FileChangeKind, HookEvent, ImplementorHandle, LocalExecutor, ProbeHandle, ProcessExitedInfo, ProcessRole, ProcessSpawnedInfo, ReviewerHandle, SignedEnvelope, SpawnArgs, SpawnArgsInvalid, SpawnHandleBase, } from './types';
4
+ export { EmitShellEventFn, HookBridge, HookBridgeDeps, } from './hook-bridge';
5
+ export { LocalExecutorImpl, LocalExecutorImplDeps, makeEmptyScope, } from './local-executor-impl';
6
+ export { ClassAEmitter, ClassAEmitterContext, ClassAEnvelope, ClassAMessageType, ClassASink, DEFAULT_DEDUPE_CAP, EmitterLogger, ExecutionEventKind, ExecutorRefusalPayload, FileChangePayload, LocalStubSink, ProcessExitedPayload, ProcessSpawnedPayload, ToolUsePayload, VerificationGateKind, VerificationResultPayload, VerificationRunPayload, isValidUlid, } from './class-a-emit';
7
+ export { DEFAULT_GATE_TIMEOUT_MS, GateRunResult, SUMMARY_CAP_BYTES, TIMEOUT_EXIT_CODE, VerificationGateRequest, VerificationRunnerDeps, runVerificationGates, truncateUtf8Safe, } from './verification-runner';
8
+ export { ClassBConsumer, ClassBConsumerDeps, ClassBConsumerState, ClassBVerificationResult, INBOUND_REPLAY_CAP, INBOUND_REPLAY_TTL_MS, UlidReplayRegistry, verifyClassBSignature, } from './class-b-consumer';
@@ -0,0 +1,83 @@
1
+ import { AuthorityScope } from './authority';
2
+ import { ClassAEmitter, ClassAEmitterContext, ClassASink } from './class-a-emit';
3
+ import { EmitShellEventFn } from './hook-bridge';
4
+ import { AgentKind, AuthorityAction, ClassBInbound, HookEvent, ImplementorHandle, LocalExecutor, ProbeHandle, ReviewerHandle, SpawnArgs } from './types';
5
+ export interface LocalExecutorImplDeps {
6
+ sessionId: string;
7
+ initialScope?: AuthorityScope;
8
+ baseCtx: Omit<ClassAEmitterContext, 'taskId'>;
9
+ adapter: AgentKind;
10
+ sink?: ClassASink;
11
+ emitShellEvent: EmitShellEventFn;
12
+ logger?: {
13
+ warn: (msg: string, meta?: Record<string, unknown>) => void;
14
+ };
15
+ }
16
+ export declare function makeEmptyScope(): AuthorityScope;
17
+ export declare class LocalExecutorImpl implements LocalExecutor {
18
+ private scope;
19
+ private taskId;
20
+ private readonly emitter;
21
+ private readonly bridge;
22
+ private readonly classBConsumer;
23
+ private readonly emitShellEvent;
24
+ private readonly baseCtx;
25
+ private readonly adapter;
26
+ private readonly sessionId;
27
+ constructor(deps: LocalExecutorImplDeps);
28
+ /**
29
+ * Single-entrypoint authority gate per master §9:1284. Dispatches to the
30
+ * underlying `authority.ts` primitive based on `action.kind`. Throws
31
+ * `AuthorityError` on refusal — caller (orchestration shell or hook bridge)
32
+ * is responsible for routing to `bridgeAuthorityErrorToShellRefusal` /
33
+ * `HookBridge.bridgeAuthorityRefusal` per LOCK #C4-3.
34
+ */
35
+ enforceAuthority(action: AuthorityAction): Promise<void>;
36
+ /**
37
+ * Read-only view of the current authority scope per master §9:1286.
38
+ * Returns a deep-frozen copy so callers cannot mutate the LE's state.
39
+ */
40
+ authorityScope(): Readonly<AuthorityScope>;
41
+ enforceCommand(argv: string[]): void;
42
+ enforceNetwork(): void;
43
+ enforceWrite(p: string): Promise<string>;
44
+ enforceRead(p: string): Promise<string>;
45
+ safeWriteFile(p: string, data: Buffer | string): Promise<void>;
46
+ safeReadFile(p: string, opts?: {
47
+ encoding?: BufferEncoding;
48
+ }): Promise<string | Buffer>;
49
+ spawnImplementor(args: SpawnArgs): Promise<ImplementorHandle>;
50
+ spawnReviewer(args: SpawnArgs): Promise<ReviewerHandle>;
51
+ spawnHealthProbe(args: SpawnArgs): Promise<ProbeHandle>;
52
+ private spawnWithLifecycle;
53
+ ingestHookEvent(event: HookEvent): Promise<void>;
54
+ /**
55
+ * Single-entrypoint inbound Class B dispatch per master §9:1287.
56
+ * Delegates to `ClassBConsumer.consume` which enforces LOCK #E3-1
57
+ * (verify → replay-check → dispatch) and per-kind handlers per CP-0
58
+ * §2.F.9-§2.F.13.
59
+ *
60
+ * TaskAuthorized advances authority scope + taskId atomically via the DI
61
+ * closure wired in the constructor (CP-0 §2.5 invariant #6).
62
+ */
63
+ consumeClassB(packet: ClassBInbound): Promise<void>;
64
+ /** Set the active taskId (production: CP-1.e on TASK_AUTHORIZED). */
65
+ setActiveTaskId(taskId: string | null): void;
66
+ /** Replace the active authority scope (production: CP-1.e on TASK_AUTHORIZED). */
67
+ setAuthorityScope(scope: AuthorityScope): void;
68
+ /** Expose emitter for §8.5 integration test introspection. */
69
+ get emitterForTests(): ClassAEmitter;
70
+ private contextOrNull;
71
+ /**
72
+ * Context resolver for ClassBConsumer emit paths (refusals + PolicyRejection).
73
+ * Class B inbound packets MAY arrive before a TaskAuthorized has set
74
+ * `this.taskId` (in fact, TaskAuthorized is the variant that SETS it). For
75
+ * the signature_invalid / ulid_replay / policy_rejection / malformed
76
+ * refusal-audit emit path we still need a valid envelope context, so we
77
+ * fall back to `pending` when no task is active. CP-2 may refine this; for
78
+ * CP-1.e the audit emit always succeeds with a deterministic placeholder.
79
+ */
80
+ private contextOrFallback;
81
+ }
82
+ /** @internal */
83
+ export declare function __resetSessionRegistryForTests(): void;
@@ -0,0 +1,6 @@
1
+ import { AuthorityScope } from './authority';
2
+ import { ImplementorHandle, ProbeHandle, ReviewerHandle, SpawnArgs, SpawnHandleBase } from './types';
3
+ export declare function spawnImplementor(scope: AuthorityScope, args: SpawnArgs): Promise<ImplementorHandle>;
4
+ export declare function spawnReviewer(scope: AuthorityScope, args: SpawnArgs): Promise<ReviewerHandle>;
5
+ export declare function spawnHealthProbe(scope: AuthorityScope, args: SpawnArgs): Promise<ProbeHandle>;
6
+ export declare function spawnSubprocess(scope: AuthorityScope, args: SpawnArgs): Promise<SpawnHandleBase>;