@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
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Filesystem location of the cohort-flag file (`~/.codevibe/cohort-flags.json`).
3
+ * Exposed as a function so test code can monkey-patch via env override.
4
+ */
5
+ export declare function cohortFlagFilePath(): string;
6
+ /**
7
+ * Reads the named cohort flag for the given session/user. Returns
8
+ * `false` on every failure mode (file missing, malformed JSON, flag
9
+ * unset, non-boolean value). This is fail-closed by design — per §3
10
+ * H6 mitigation, the cohort gate MUST default off until Phase 4 flips
11
+ * the flag.
12
+ *
13
+ * `sessionId` is accepted in the signature for future per-session
14
+ * cohort overrides; CP-1.a ignores it.
15
+ */
16
+ export declare function getCohortFlag(name: string, _sessionId: string): Promise<boolean>;
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare function CodeVibeLogo(): React.ReactElement;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../types';
3
+ export interface ConversationPaneProps {
4
+ entries: ConversationEntry[];
5
+ }
6
+ export declare function renderConversationEntry(entry: ConversationEntry): React.ReactElement;
7
+ export declare function ConversationPane(props: ConversationPaneProps): React.ReactElement;
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../types';
3
+ export interface GatePromptEntryProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'gate-prompt';
6
+ }>;
7
+ }
8
+ export declare function GatePromptEntry(props: GatePromptEntryProps): React.ReactElement;
9
+ export default GatePromptEntry;
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Gate-prompt-aware input modes per PHASE-CP-8-MIN-DESIGN.md §7
4
+ * + #C8M-5. `maxOption: number` (NOT a `2 | 5` literal union) per
5
+ * #C8M-1 server-derived purity — the parent derives it from
6
+ * `envelope.options.length` at the active gate-prompt entry.
7
+ */
8
+ export type GatePromptMode = {
9
+ kind: 'awaiting-number';
10
+ maxOption: number;
11
+ } | {
12
+ kind: 'awaiting-notes';
13
+ decisionDraft: string;
14
+ } | {
15
+ kind: 'submitting';
16
+ } | null;
17
+ /**
18
+ * Sentinel string emitted via `onSubmit` when the user types the exact
19
+ * literal `/cancel` (case-sensitive) in `awaiting-notes` mode. The parent
20
+ * (`<OrchestrationApp>`) MUST intercept this sentinel and dispatch
21
+ * `GATE_PROMPT_NOTES_CANCELLED` instead of treating the text as notes
22
+ * plaintext. Without this sentinel, `/cancel` would be submitted AS the
23
+ * notes string to `applyUserDecision`, destroying user intent
24
+ * (Stage 2 r2 Codex NEW-HIGH-1). Sentinel string is intentionally
25
+ * non-printable / non-collidable with any plausible notes content.
26
+ */
27
+ export declare const GATE_PROMPT_NOTES_CANCEL_SENTINEL = "__GATE_PROMPT_NOTES_CANCEL__";
28
+ export interface InputBarProps {
29
+ onSubmit: (text: string) => void;
30
+ /** Optional placeholder shown when value is empty. */
31
+ placeholder?: string;
32
+ /** Initial value (used for history recall). */
33
+ initialValue?: string;
34
+ /**
35
+ * CP-8 min Wave 1B. When non-null, restricts/disables input per the
36
+ * gate-prompt mode; when null, normal text-input behavior. See module
37
+ * docstring for the four states.
38
+ */
39
+ gatePromptMode?: GatePromptMode;
40
+ }
41
+ export declare function InputBar(props: InputBarProps): React.ReactElement;
@@ -0,0 +1,63 @@
1
+ import * as React from 'react';
2
+ import { OrchestrationStore } from '../store';
3
+ import { PostDecisionAction, Tier } from '../types';
4
+ /**
5
+ * Minimal SDK contract for the applyUserDecision wire. Structurally
6
+ * compatible with the full `AppSyncClient.applyUserDecision` signature
7
+ * — keeps the orchestration shell decoupled from the heavier AppSync
8
+ * surface (tests can inject a stub).
9
+ */
10
+ export interface ApplyUserDecisionClient {
11
+ applyUserDecision(input: {
12
+ gateId: string;
13
+ taskId: string;
14
+ sessionId: string;
15
+ currentRound: number;
16
+ decision: string;
17
+ notes?: string;
18
+ }, sessionKeyBase64?: string): Promise<{
19
+ decision: string;
20
+ postAction: PostDecisionAction;
21
+ }>;
22
+ }
23
+ export interface OrchestrationAppProps {
24
+ store: OrchestrationStore;
25
+ tier: Tier;
26
+ /** Hook called when `<InputBar>` submits text AND there is no active
27
+ * gate-prompt. The host wires this to the slash router / planner
28
+ * classifier. Gate-prompt submits are intercepted internally per
29
+ * #C8M-11 and never reach `onUserInput`. */
30
+ onUserInput: (text: string) => void;
31
+ /**
32
+ * CP-8 min Stage 1 R1 closure + Stage 2 r1 Codex HIGH-1 (REQUIRED). The
33
+ * desktop-side AppSync transport surface (codevibe-core's own
34
+ * AppSyncClient — see #C8M-6 deviation). Required so production gate
35
+ * submits cannot silently fail-closed at the SDK edge with "AppSync
36
+ * client not configured". The shell entry (`runOrchestrationShell`)
37
+ * always has an authenticated client by the
38
+ * `RunOrchestrationShellArgs` contract; tests inject a stub.
39
+ * Future omissions will fail TypeScript compile rather than break at
40
+ * runtime.
41
+ */
42
+ appsyncClient: ApplyUserDecisionClient;
43
+ /**
44
+ * Session-key resolver invoked just-in-time when a gate-prompt submit
45
+ * includes notes. Returns the base64 session key for the caller's
46
+ * session, or `null` if the session is not E2E-encrypted.
47
+ *
48
+ * Stage 2 r2 Codex NEW-HIGH-2: this prop is now REQUIRED (non-optional)
49
+ * because the underlying `AppSyncClient.applyUserDecision` enforces
50
+ * `sessionKeyBase64 !== undefined` whenever `notes` is supplied. Without
51
+ * the resolver, production Path B `_WITH_NOTES` submits throw at the
52
+ * SDK edge with "sessionKeyBase64 is required when notes are
53
+ * supplied" — masked by Tests 21/22 which stub the resolver. Production
54
+ * callers (`runOrchestrationShell`) bind this to
55
+ * `keychainManager.getSessionKey(sessionId)`. Tests inject a stub.
56
+ *
57
+ * If the resolver returns `null` AND `notes` are present, the submit
58
+ * handler dispatches `GATE_PROMPT_SUBMIT_FAILED` with a locked error
59
+ * message — it MUST NOT silently submit unencrypted notes.
60
+ */
61
+ getSessionKey: (sessionId: string) => Promise<string | null>;
62
+ }
63
+ export declare function OrchestrationApp(props: OrchestrationAppProps): React.ReactElement;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { PlannerHealthState, Tier } from '../types';
3
+ export interface StatusBarProps {
4
+ plannerHealth: PlannerHealthState;
5
+ tier: Tier;
6
+ }
7
+ export declare function StatusBar(props: StatusBarProps): React.ReactElement;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../../types';
3
+ export interface AdvisoryEntryProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'advisory';
6
+ }>;
7
+ }
8
+ export declare function AdvisoryEntry(props: AdvisoryEntryProps): React.ReactElement;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../../types';
3
+ export interface GateStatusNodeProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'gate-status-node';
6
+ }>;
7
+ }
8
+ export declare function GateStatusNode(props: GateStatusNodeProps): React.ReactElement;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../../types';
3
+ export interface PlannerDecisionEntryProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'planner-decision';
6
+ }>;
7
+ }
8
+ export declare function PlannerDecisionEntry(props: PlannerDecisionEntryProps): React.ReactElement;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../../types';
3
+ export interface ReviewerQuorumStatusNodeProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'reviewer-status-node';
6
+ }>;
7
+ }
8
+ export declare function ReviewerQuorumStatusNode(props: ReviewerQuorumStatusNodeProps): React.ReactElement;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../../types';
3
+ export interface SlashOutputEntryProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'slash-output';
6
+ }>;
7
+ }
8
+ export declare function SlashOutputEntry(props: SlashOutputEntryProps): React.ReactElement;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../../types';
3
+ export interface SubagentEventEntryProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'subagent-event';
6
+ }>;
7
+ }
8
+ export declare function SubagentEventEntry(props: SubagentEventEntryProps): React.ReactElement;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { ConversationEntry } from '../../types';
3
+ export interface UserMessageEntryProps {
4
+ entry: Extract<ConversationEntry, {
5
+ kind: 'user-message';
6
+ }>;
7
+ }
8
+ export declare function UserMessageEntry(props: UserMessageEntryProps): React.ReactElement;
@@ -0,0 +1,64 @@
1
+ import { AppSyncClient } from '../appsync';
2
+ /**
3
+ * §3 LOCK lines 173-181. Names + per-type metadata shapes are part of
4
+ * the Stage A contract. CP-1.a ships the union; CP-1.b/c/d add call
5
+ * sites for each emit type.
6
+ */
7
+ export type NewEventTypeKind = 'MODE_SELECTED' | 'PLANNER_DECISION' | 'PLANNER_CACHE_HIT' | 'PLANNER_DEGRADED' | 'PLANNER_OUTAGE' | 'PLANNER_RECOVERED' | 'SLASH_COMMAND_INVOKED' | 'STRUCTURAL_SUMMARY_GENERATED' | 'LOCAL_AUTHORITY_REFUSAL' | 'NOTIFICATION';
8
+ /**
9
+ * §3 LOCK lines 160-170. ShellEventEmit contract.
10
+ *
11
+ * Per Stage 2 r1 Codex HIGH-2: `source` and `isEncrypted` MUST be
12
+ * present on every call. The Stage A LOCK on §3 fixes both: every CP-1
13
+ * shell event is DESKTOP-sourced and E2E-encrypted under the session
14
+ * key. Making them required (vs optional) prevents accidental plaintext
15
+ * fall-through if a caller forgets either field.
16
+ */
17
+ export interface ShellEventEmit {
18
+ /** Current Session.sessionId; orchestration shell tracks this. */
19
+ sessionId: string;
20
+ /** One of the 9 new EventType enums (plus NOTIFICATION reuse). */
21
+ type: NewEventTypeKind;
22
+ /** Shell is desktop-side; mobile uses its own emit path. REQUIRED. */
23
+ source: 'DESKTOP';
24
+ /** Human-readable summary; encrypted under session key. */
25
+ content?: string;
26
+ /** Event-specific structured payload; encrypted; per-type shape per §3. */
27
+ metadata?: Record<string, unknown>;
28
+ /** All CP-1 shell events are E2E encrypted per existing pattern. REQUIRED. */
29
+ isEncrypted: true;
30
+ /** RFC3339; if omitted, server fills in via existing VTL. */
31
+ timestamp?: string;
32
+ }
33
+ /**
34
+ * Test seam — allows the unit tests to swap the AppSync client without
35
+ * mounting the full singleton. Production code calls
36
+ * `emitShellEvent(args)` which uses `getDefaultClient()`.
37
+ */
38
+ export interface EmitShellEventDeps {
39
+ appsyncClient: Pick<AppSyncClient, 'createEvent'>;
40
+ getSessionKey: (sessionId: string) => Promise<string | null>;
41
+ getCohortFlag: (name: string, sessionId: string) => Promise<boolean>;
42
+ }
43
+ /**
44
+ * §3 LOCK lines 184-207. Single chokepoint enforcing the cohort-flag
45
+ * gate + encryption invariants for all 9 new EventTypes.
46
+ *
47
+ * When the cohort flag is off: log at debug and return without
48
+ * touching AppSync. When on: encrypt content + metadata under the
49
+ * session key, call `createEvent` via Pattern B Lambda resolver
50
+ * (existing surface, no schema change).
51
+ *
52
+ * `deps` is the test seam. Production callers omit it and the function
53
+ * resolves the default `keychainManager` + `cryptoService` references.
54
+ * The AppSync client is REQUIRED — there is no global default in
55
+ * codevibe-core (each plugin instantiates its own `AppSyncClient`).
56
+ */
57
+ export declare function emitShellEvent(args: ShellEventEmit, deps: EmitShellEventDeps): Promise<void>;
58
+ /**
59
+ * Convenience helper for production callers — binds default
60
+ * dependencies (`keychainManager` for session-key lookup,
61
+ * `getCohortFlag` for the flag read) and accepts the AppSync client
62
+ * separately because there's no global default in `codevibe-core`.
63
+ */
64
+ export declare function createShellEventEmitter(appsyncClient: Pick<AppSyncClient, 'createEvent'>): (args: ShellEventEmit) => Promise<void>;
@@ -0,0 +1,123 @@
1
+ import { Event } from '../types/events';
2
+ /**
3
+ * `metadata.prompt_kind` value for the 5-option Path B (Halted-resolution)
4
+ * gate prompt. Mirrors `METADATA_PROMPT_KIND` at `appsync_emit.rs:68`.
5
+ *
6
+ * Cross-impl literal parity is a load-bearing invariant — see Test 23
7
+ * (`hostile-grep.test.ts`).
8
+ */
9
+ export declare const ORCHESTRATION_ESCALATED_GATE_PROMPT_KIND: "orchestration_escalated_gate";
10
+ /**
11
+ * `metadata.prompt_kind` value for the 2-option Path A (FinalApproval)
12
+ * gate prompt. Mirrors `METADATA_PROMPT_KIND_FINAL_APPROVAL` at
13
+ * `appsync_emit.rs:297`.
14
+ */
15
+ export declare const ORCHESTRATION_FINAL_APPROVAL_PROMPT_KIND: "orchestration_final_approval";
16
+ /**
17
+ * Source-of-truth string literals for the hostile-grep cross-impl parity
18
+ * test (`__tests__/hostile-grep.test.ts`, Test 23). Mirrors the Rust
19
+ * emitter at
20
+ * `codevibe-core-rs/crates/codevibe-orchestration-lambda/src/appsync_emit.rs`
21
+ * lines 63 / 68 / 297 / 312-340 / 351-364.
22
+ *
23
+ * Do NOT remove or reorder — Test 23 greps this module for each literal
24
+ * verbatim. Drift here = silent cross-platform breakage:
25
+ * - tool_name discriminator → `metadata.tool_name`
26
+ * - prompt_kind discriminators → `metadata.prompt_kind`
27
+ * - 5-tuple escalation option ids → `metadata.payload.options[*].id`
28
+ * (position-ordered: ACCEPT, ACCEPT_WITH_NOTES, REJECT_WITH_NOTES,
29
+ * REJECT_RESTART, ABORT_TASK)
30
+ * - 2-tuple final-approval ids → `metadata.payload.options[*].id`
31
+ * (position-ordered: APPROVE, CANCEL)
32
+ *
33
+ * NB: the option ids themselves are NEVER referenced as TS string
34
+ * constants at runtime — the renderer + mapper read them from the wire
35
+ * per #C8M-1. This block exists purely as a hostile-grep anchor so any
36
+ * Rust-side reordering or rename trips the parity test on the TS side
37
+ * as well.
38
+ */
39
+ export declare const SOURCE_OF_TRUTH_LITERALS: {
40
+ readonly toolName: "OrchestrationGate";
41
+ readonly escalatedPromptKind: "orchestration_escalated_gate";
42
+ readonly finalApprovalPromptKind: "orchestration_final_approval";
43
+ readonly escalationOptionIds: readonly ["ACCEPT", "ACCEPT_WITH_NOTES", "REJECT_WITH_NOTES", "REJECT_RESTART", "ABORT_TASK"];
44
+ readonly finalApprovalOptionIds: readonly ["APPROVE", "CANCEL"];
45
+ };
46
+ /**
47
+ * Discriminated union over the two prompt kinds CP-8 min routes through
48
+ * the gate-prompt path. Anything outside this union flows to the
49
+ * existing `subagent-event` / `mobile-event-replay` path per #C8M-3.
50
+ */
51
+ export type GatePromptKind = typeof ORCHESTRATION_ESCALATED_GATE_PROMPT_KIND | typeof ORCHESTRATION_FINAL_APPROVAL_PROMPT_KIND;
52
+ /**
53
+ * One option entry on the wire — matches the Rust struct projected by
54
+ * `build_escalation_options()` / `build_final_approval_options()`.
55
+ */
56
+ export interface GatePromptOption {
57
+ readonly id: string;
58
+ readonly label: string;
59
+ readonly description: string;
60
+ }
61
+ /**
62
+ * Locked design §4 #C8M-9. The plaintext-parsed envelope the
63
+ * dispatcher hands to the reducer via `GATE_PROMPT_RECEIVED`. Captures
64
+ * everything the renderer + submit path need; no other field is read
65
+ * from `event.metadata` after extraction.
66
+ *
67
+ * Field provenance (Rust `appsync_emit.rs::build_metadata_json` lines
68
+ * 1459-1493):
69
+ * - `promptKind` from `metadata.prompt_kind`
70
+ * - `taskId` / `gateId` from `metadata.payload.outcome.{taskId,gateId}`
71
+ * - `currentRound` from `metadata.payload.outcome.round`
72
+ * - `options` from `metadata.payload.options` (5 or 2 entries)
73
+ * - `reason` from `metadata.payload.outcome.reason` (Path B only)
74
+ * - `summary` from `metadata.summary`
75
+ * - `receivedAt` from `event.timestamp` (server-set; ISO 8601)
76
+ */
77
+ export interface GatePromptEnvelope {
78
+ readonly promptKind: GatePromptKind;
79
+ readonly taskId: string;
80
+ readonly gateId: string;
81
+ readonly currentRound: number;
82
+ readonly options: ReadonlyArray<GatePromptOption>;
83
+ readonly reason?: string;
84
+ readonly summary?: string;
85
+ readonly receivedAt: string;
86
+ }
87
+ /**
88
+ * Defensive validator (per #C8M-1 + #C8M-2). Returns `null` on ANY of:
89
+ * - event is not an INTERACTIVE_PROMPT
90
+ * - metadata absent / un-parseable
91
+ * - `prompt_kind` not one of the two orchestration discriminators
92
+ * - `payload.options` not an array, OR wrong length
93
+ * (5 for escalation, 2 for final-approval)
94
+ * - any entry missing `id` / `label` / `description` or with non-string
95
+ * `id`
96
+ * - `outcome.{taskId,gateId,round}` missing or wrong type
97
+ *
98
+ * The caller (dispatcher in `index.ts`) is responsible for emitting the
99
+ * `kind: 'advisory'` ConversationEntry on null-return per #C8M-1.
100
+ */
101
+ export declare function extractGatePromptEnvelope(event: Event): GatePromptEnvelope | null;
102
+ /**
103
+ * Per #C8M-1: typed_number N (1-based) → `lowercase(envelope.options[N-1].id)`.
104
+ * Result is the `decision` value the caller passes to
105
+ * `sdk.applyUserDecision({ decision, ... })`. The SDK uppercases via
106
+ * `toWireEnum` before AppSync wire-send (see `client.ts:244-246`).
107
+ *
108
+ * Returns `null` for ANY of:
109
+ * - `n` is not an integer (NaN, fractional, non-number)
110
+ * - `n < 1` or `n > envelope.options.length`
111
+ *
112
+ * `needsNotes` is `true` iff the resolved kind ends with `_with_notes`,
113
+ * driving the InputBar transition to the notes-entry sub-prompt per
114
+ * #C8M-5. For Path A's APPROVE / CANCEL, `needsNotes` is always false.
115
+ *
116
+ * The caller MUST treat `null` as a typo / out-of-range and reject the
117
+ * submit — silent fallback to a default kind would destroy or accept
118
+ * the user's work without consent (matches the v1-options rule).
119
+ */
120
+ export declare function mapTypedNumberToDecisionKind(envelope: GatePromptEnvelope, n: number): {
121
+ kind: string;
122
+ needsNotes: boolean;
123
+ } | null;
@@ -0,0 +1,100 @@
1
+ import { AppSyncClient } from '../appsync';
2
+ import { Session } from '../types';
3
+ import { OrchestrationStore } from './store';
4
+ import { createShellEventEmitter } from './emit-shell-event';
5
+ import { Tier } from './types';
6
+ import { type StructuralSummaryGenerator } from '../structural-summary';
7
+ import type { PlannerAdapter } from '../planner/adapter';
8
+ import type { PlannerCacheLayer } from '../planner/cache';
9
+ import type { PlannerInput, PlannerDecision as PlannerDecisionRuntime } from '../planner/types';
10
+ export interface RunOrchestrationShellArgs {
11
+ /** Authenticated AppSync client (caller is responsible for `authenticateWithStoredTokens`). */
12
+ appsyncClient: AppSyncClient;
13
+ /** Resolved session (caller ran `resumeOrCreateSession` already). */
14
+ session: Session;
15
+ /** Current tier — used by the StatusBar + downstream tier gating. */
16
+ tier: Tier;
17
+ /**
18
+ * CP-1.b IMPL r2 H-3 — Optional planner adapter. When supplied,
19
+ * `runOrchestrationShell` binds the active session via
20
+ * `plannerAdapter.setActiveSession(sessionId)` immediately after
21
+ * startup, and clears it on session teardown. The
22
+ * `PlannerAdapter.probe()` contract (CP-1.b §4.10) reads the
23
+ * session from this binding. CP-1.a callers may omit; CP-1.b+
24
+ * wires the real `BackendPlannerClient`.
25
+ */
26
+ plannerAdapter?: PlannerAdapter;
27
+ /**
28
+ * CP-1.b IMPL r2 M-3 — Optional planner cache layer. With LOCK #18
29
+ * write-through removed, normal session exit (no LRU eviction, no
30
+ * TTL deletion) would lose pending in-memory inserts. When
31
+ * supplied, `runOrchestrationShell` calls `cache.flush()` from
32
+ * every teardown path (`/quit`, non-TTY EOF, SIGINT/SIGTERM,
33
+ * finally-block cleanup).
34
+ */
35
+ plannerCache?: PlannerCacheLayer;
36
+ }
37
+ export { processMarkers, withRoleMarker } from './process-markers';
38
+ export { emitShellEvent, createShellEventEmitter, type ShellEventEmit, type NewEventTypeKind, } from './emit-shell-event';
39
+ export { pickMode, TierError, type ParsedModeArgs, type ModeSelectionDeps, } from './mode-selection';
40
+ export { readStickyPreference, writeStickyPreference, stickyPreferenceFilePath, } from './sticky-preference';
41
+ export { getCohortFlag, cohortFlagFilePath } from './cohort-flag';
42
+ export { routeSlashCommand, applySlashOutput, type SlashOutput, type ShellAction, } from './slash-router';
43
+ export { reducer } from './reducer';
44
+ export { createOrchestrationStore, type OrchestrationStore } from './store';
45
+ export type { Mode, Tier, PlannerDecision, AgentKind, PlannerHealthState, RunningTaskState, ReviewerSeatState, GateState, ExecutionEventEntry, RefusalEventEntry, BypassEventEntry, MobileEventEntry, EventStreamEntry, ConversationEntry, QueuedTask, PendingClarification, OrchestrationState, OrchestrationAction, LastModeFile, } from './types';
46
+ /**
47
+ * §5 lines 336-365 LOCK + §16 LOCK #14. Single entrypoint that wires
48
+ * the store + emit chokepoint + slash router and either mounts the
49
+ * Ink TUI (TTY) or falls back to line-log (non-TTY).
50
+ */
51
+ export declare function runOrchestrationShell(args: RunOrchestrationShellArgs): Promise<void>;
52
+ /**
53
+ * Higher-level entrypoint used by the `cli.ts` glue. CP-1.a ships the
54
+ * basic argv parse — full plumbing (session resume, AppSync client
55
+ * bootstrap, tier read) lands when CP-1.b/c hooks the rest of the
56
+ * sub-phases.
57
+ */
58
+ export interface RunOrchestrationCliArgs {
59
+ argv: string[];
60
+ /** Test seam — runOrchestrationShell injected for unit tests. */
61
+ runOrchestrationShellFn?: typeof runOrchestrationShell;
62
+ /** Test seam — invoked when CP-1.a needs Companion Mode handoff (§4). */
63
+ runCompanionModeFn?: (args: {
64
+ agent?: string;
65
+ passthrough: string[];
66
+ }) => Promise<void>;
67
+ }
68
+ interface StructuralSummaryRunDeps {
69
+ store: OrchestrationStore;
70
+ args: RunOrchestrationShellArgs;
71
+ emitShellEventBound: ReturnType<typeof createShellEventEmitter>;
72
+ generator: StructuralSummaryGenerator;
73
+ }
74
+ /**
75
+ * Test seam — accepts an injected `addBodyPath` so unit tests can drive
76
+ * the dispatch logic without touching the filesystem. Production callers
77
+ * use the default which imports the real one from `../structural-summary`.
78
+ */
79
+ export interface HandleShellUserInputDeps extends StructuralSummaryRunDeps {
80
+ text: string;
81
+ /** Test seam — defaults to the real `addBodyPath`. */
82
+ addBodyPathFn?: (path: string, tier: Tier) => Promise<unknown>;
83
+ /** Test seam — defaults to the real `regenerateStructuralSummary`. */
84
+ regenerateStructuralSummaryFn?: (deps: StructuralSummaryRunDeps) => Promise<void>;
85
+ /**
86
+ * CP-1.b IMPL r4 H-1 — Optional override for the natural-language
87
+ * classify dispatch. Defaults to `args.plannerAdapter?.classify`. Tests
88
+ * may inject a stub to drive the conversion to PLANNER_DECISION
89
+ * without spinning up the BackendPlannerClient.
90
+ */
91
+ classifyFn?: (input: PlannerInput) => Promise<PlannerDecisionRuntime>;
92
+ }
93
+ /**
94
+ * Slash + natural-language dispatch. Extracted from `runOrchestrationShell`
95
+ * so unit tests can drive the §4.8 wiring (REGENERATE / OPT_IN_BODY_PATH
96
+ * / default `/structural-summary` placeholder rewrite) without spinning
97
+ * up the full TUI. Behaves identically to the inline closure in
98
+ * `runOrchestrationShell`.
99
+ */
100
+ export declare function handleShellUserInput(deps: HandleShellUserInputDeps): Promise<void>;
@@ -0,0 +1,64 @@
1
+ interface InkExports {
2
+ Box: any;
3
+ Text: any;
4
+ Static: any;
5
+ render: (tree: any) => {
6
+ waitUntilExit(): Promise<void>;
7
+ unmount(): void;
8
+ };
9
+ useApp: () => {
10
+ exit: (err?: Error) => void;
11
+ };
12
+ useInput: (handler: (input: string, key: any) => void) => void;
13
+ useStdin: () => {
14
+ stdin: any;
15
+ setRawMode: (raw: boolean) => void;
16
+ isRawModeSupported: boolean;
17
+ };
18
+ }
19
+ interface InkTextInputExports {
20
+ default: any;
21
+ }
22
+ interface InkSpinnerExports {
23
+ default: any;
24
+ }
25
+ interface InkSelectInputExports {
26
+ default: any;
27
+ }
28
+ interface GradientStringExports {
29
+ default: (colors: string[] | string) => (s: string) => string;
30
+ }
31
+ interface InkRuntime {
32
+ ink: InkExports;
33
+ inkTextInput: InkTextInputExports;
34
+ inkSpinner: InkSpinnerExports;
35
+ inkSelectInput: InkSelectInputExports;
36
+ gradientString: GradientStringExports;
37
+ }
38
+ /**
39
+ * Test seam — replace the ESM loader (e.g., for Vitest, which gets
40
+ * the dynamic-import error via the VM).
41
+ */
42
+ export declare function __setEsmLoaderForTest(loader: <T>(name: string) => Promise<T>): void;
43
+ /**
44
+ * Resets the ESM loader to the production default.
45
+ */
46
+ export declare function __resetEsmLoaderForTest(): void;
47
+ /**
48
+ * Loads the ESM-only ink packages. Idempotent — second call returns
49
+ * the cached runtime. Throws if any package fails to load.
50
+ */
51
+ export declare function initInkRuntime(): Promise<InkRuntime>;
52
+ /**
53
+ * Synchronous accessor. Components call this AFTER the entrypoint
54
+ * `await initInkRuntime()` succeeds. Throws if ink isn't loaded — that
55
+ * indicates a programming error in the entrypoint sequencing.
56
+ */
57
+ export declare function getInkRuntime(): InkRuntime;
58
+ /**
59
+ * Test seam — lets the unit tests inject a fake runtime so component
60
+ * tests can render without launching real terminals. Production code
61
+ * never calls this.
62
+ */
63
+ export declare function __setInkRuntimeForTest(rt: InkRuntime | null): void;
64
+ export {};
@@ -0,0 +1,46 @@
1
+ import { Mode, Tier } from './types';
2
+ /**
3
+ * Thrown when a Free-tier user explicitly requests `--mode orchestration`.
4
+ * Per §2 + §16 LOCK #1: Orchestration Mode is Pro/Max-gated; Free-tier
5
+ * users hit this error with the upgrade URL.
6
+ */
7
+ export declare class TierError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ /**
11
+ * Parsed arguments the entrypoint hands to `pickMode`. Either flag is
12
+ * optional; a value of `undefined` means "not specified".
13
+ */
14
+ export interface ParsedModeArgs {
15
+ /** `--mode companion` | `--mode orchestration` | undefined */
16
+ mode?: Mode;
17
+ }
18
+ /**
19
+ * Test seam — lets the unit tests inject a deterministic prompt
20
+ * callback instead of opening a real TTY.
21
+ */
22
+ export interface ModeSelectionDeps {
23
+ readStickyPreference: (tier: Tier) => Promise<Mode | null>;
24
+ writeStickyPreference: (args: {
25
+ mode: Mode;
26
+ pickedByTier: 'PRO' | 'MAX';
27
+ }) => Promise<void>;
28
+ promptUserForMode: (tier: 'PRO' | 'MAX') => Promise<Mode>;
29
+ }
30
+ /**
31
+ * §2 LOCK lines 80-99. Pure decision function — only filesystem I/O is
32
+ * the sticky-preference read via `deps.readStickyPreference`.
33
+ *
34
+ * Rules:
35
+ * 1. Free-tier + `--mode orchestration` → `TierError` with upgrade URL.
36
+ * 2. Explicit `--mode` flag → honor it.
37
+ * 3. Free-tier (no flag) → 'companion'.
38
+ * 4. Pro/Max (no flag) + sticky present → sticky mode.
39
+ * 5. Pro/Max (no flag) + no sticky → prompt user; write sticky after pick.
40
+ */
41
+ export declare function pickMode(args: ParsedModeArgs, tier: Tier, deps?: ModeSelectionDeps): Promise<Mode>;
42
+ /**
43
+ * Default deps wiring — production callers can omit `deps` from
44
+ * `pickMode()` and get this. Tests override via the optional 3rd arg.
45
+ */
46
+ export declare function defaultDeps(): ModeSelectionDeps;