@ngockhoale/ckit 0.0.0-stage → 0.1.0

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 (244) hide show
  1. package/.env.example +42 -0
  2. package/README.md +116 -2
  3. package/dist/src/adapters/agent/claude/errors.d.ts +13 -0
  4. package/dist/src/adapters/agent/claude/errors.js +16 -0
  5. package/dist/src/adapters/agent/claude/normalize.d.ts +11 -0
  6. package/dist/src/adapters/agent/claude/normalize.js +83 -0
  7. package/dist/src/adapters/agent/errors.d.ts +13 -0
  8. package/dist/src/adapters/agent/errors.js +19 -0
  9. package/dist/src/adapters/agent/fixtures/claude-transcript.d.ts +70 -0
  10. package/dist/src/adapters/agent/fixtures/claude-transcript.js +15 -0
  11. package/dist/src/adapters/agent/fixtures/omp-transcript.d.ts +60 -0
  12. package/dist/src/adapters/agent/fixtures/omp-transcript.js +14 -0
  13. package/dist/src/adapters/agent/normalize.d.ts +18 -0
  14. package/dist/src/adapters/agent/normalize.js +77 -0
  15. package/dist/src/adapters/agent/transport.d.ts +35 -0
  16. package/dist/src/adapters/agent/transport.js +39 -0
  17. package/dist/src/adapters/agent/worker-service.d.ts +49 -0
  18. package/dist/src/adapters/agent/worker-service.js +77 -0
  19. package/dist/src/adapters/fake/fake-advisor.d.ts +15 -0
  20. package/dist/src/adapters/fake/fake-advisor.js +29 -0
  21. package/dist/src/adapters/fake/fake-agent.d.ts +12 -0
  22. package/dist/src/adapters/fake/fake-agent.js +21 -0
  23. package/dist/src/adapters/fake/fake-store.d.ts +13 -0
  24. package/dist/src/adapters/fake/fake-store.js +23 -0
  25. package/dist/src/adapters/fake/fake-web.d.ts +12 -0
  26. package/dist/src/adapters/fake/fake-web.js +21 -0
  27. package/dist/src/adapters/fake/fault-injector.d.ts +18 -0
  28. package/dist/src/adapters/fake/fault-injector.js +64 -0
  29. package/dist/src/adapters/fake/virtual-clock.d.ts +12 -0
  30. package/dist/src/adapters/fake/virtual-clock.js +35 -0
  31. package/dist/src/adapters/launch/discover.d.ts +18 -0
  32. package/dist/src/adapters/launch/discover.js +55 -0
  33. package/dist/src/adapters/launch/executor.d.ts +117 -0
  34. package/dist/src/adapters/launch/executor.js +383 -0
  35. package/dist/src/adapters/launch/profile.d.ts +35 -0
  36. package/dist/src/adapters/launch/profile.js +73 -0
  37. package/dist/src/adapters/launch/spawn.d.ts +29 -0
  38. package/dist/src/adapters/launch/spawn.js +18 -0
  39. package/dist/src/adapters/openai/openai-advisor.d.ts +56 -0
  40. package/dist/src/adapters/openai/openai-advisor.js +146 -0
  41. package/dist/src/cli/ckit.d.ts +5 -0
  42. package/dist/src/cli/ckit.js +472 -0
  43. package/dist/src/cli/demo.d.ts +1 -0
  44. package/dist/src/cli/demo.js +30 -0
  45. package/dist/src/cli/sessions.d.ts +10 -0
  46. package/dist/src/cli/sessions.js +381 -0
  47. package/dist/src/cli/setup.d.ts +11 -0
  48. package/dist/src/cli/setup.js +115 -0
  49. package/dist/src/committee/decision.d.ts +84 -0
  50. package/dist/src/committee/decision.js +167 -0
  51. package/dist/src/committee/handover.d.ts +115 -0
  52. package/dist/src/committee/handover.js +191 -0
  53. package/dist/src/committee/no-progress.d.ts +44 -0
  54. package/dist/src/committee/no-progress.js +64 -0
  55. package/dist/src/committee/primary-registry.d.ts +15 -0
  56. package/dist/src/committee/primary-registry.js +60 -0
  57. package/dist/src/committee/reply-parser.d.ts +28 -0
  58. package/dist/src/committee/reply-parser.js +53 -0
  59. package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
  60. package/dist/src/committee/reviewer-scheduler.js +163 -0
  61. package/dist/src/committee/role-epoch.d.ts +91 -0
  62. package/dist/src/committee/role-epoch.js +154 -0
  63. package/dist/src/core/control.d.ts +18 -0
  64. package/dist/src/core/control.js +29 -0
  65. package/dist/src/core/entities.d.ts +166 -0
  66. package/dist/src/core/entities.js +119 -0
  67. package/dist/src/core/errors.d.ts +9 -0
  68. package/dist/src/core/errors.js +17 -0
  69. package/dist/src/core/events.d.ts +72 -0
  70. package/dist/src/core/events.js +125 -0
  71. package/dist/src/core/ids.d.ts +47 -0
  72. package/dist/src/core/ids.js +32 -0
  73. package/dist/src/core/machine.d.ts +55 -0
  74. package/dist/src/core/machine.js +110 -0
  75. package/dist/src/core/policy.d.ts +34 -0
  76. package/dist/src/core/policy.js +59 -0
  77. package/dist/src/core/provenance.d.ts +20 -0
  78. package/dist/src/core/provenance.js +21 -0
  79. package/dist/src/core/record.d.ts +35 -0
  80. package/dist/src/core/record.js +67 -0
  81. package/dist/src/core/replay.d.ts +10 -0
  82. package/dist/src/core/replay.js +36 -0
  83. package/dist/src/core/run-task.d.ts +20 -0
  84. package/dist/src/core/run-task.js +48 -0
  85. package/dist/src/diagnostics/doctor.d.ts +78 -0
  86. package/dist/src/diagnostics/doctor.js +365 -0
  87. package/dist/src/diagnostics/journal-lock.d.ts +38 -0
  88. package/dist/src/diagnostics/journal-lock.js +181 -0
  89. package/dist/src/evidence/linker.d.ts +44 -0
  90. package/dist/src/evidence/linker.js +75 -0
  91. package/dist/src/evidence/report-parser.d.ts +27 -0
  92. package/dist/src/evidence/report-parser.js +17 -0
  93. package/dist/src/evidence/store.d.ts +36 -0
  94. package/dist/src/evidence/store.js +57 -0
  95. package/dist/src/gui/server.d.ts +27 -0
  96. package/dist/src/gui/server.js +497 -0
  97. package/dist/src/host/checkpoint.d.ts +22 -0
  98. package/dist/src/host/checkpoint.js +74 -0
  99. package/dist/src/host/export.d.ts +52 -0
  100. package/dist/src/host/export.js +45 -0
  101. package/dist/src/host/ipc.d.ts +57 -0
  102. package/dist/src/host/ipc.js +124 -0
  103. package/dist/src/host/leases.d.ts +27 -0
  104. package/dist/src/host/leases.js +40 -0
  105. package/dist/src/host/retention.d.ts +47 -0
  106. package/dist/src/host/retention.js +130 -0
  107. package/dist/src/host/supervisor.d.ts +59 -0
  108. package/dist/src/host/supervisor.js +64 -0
  109. package/dist/src/intake/owner-intake.d.ts +31 -0
  110. package/dist/src/intake/owner-intake.js +97 -0
  111. package/dist/src/intake/types.d.ts +46 -0
  112. package/dist/src/intake/types.js +2 -0
  113. package/dist/src/intent/context-packet.d.ts +68 -0
  114. package/dist/src/intent/context-packet.js +76 -0
  115. package/dist/src/intent/idea-ledger.d.ts +50 -0
  116. package/dist/src/intent/idea-ledger.js +136 -0
  117. package/dist/src/intent/ledger.d.ts +35 -0
  118. package/dist/src/intent/ledger.js +40 -0
  119. package/dist/src/intent/registry.d.ts +51 -0
  120. package/dist/src/intent/registry.js +44 -0
  121. package/dist/src/intent/revision.d.ts +37 -0
  122. package/dist/src/intent/revision.js +48 -0
  123. package/dist/src/orchestration/dispatcher.d.ts +32 -0
  124. package/dist/src/orchestration/dispatcher.js +136 -0
  125. package/dist/src/orchestration/milestone-loop.d.ts +149 -0
  126. package/dist/src/orchestration/milestone-loop.js +132 -0
  127. package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
  128. package/dist/src/orchestration/recovery-coordinator.js +180 -0
  129. package/dist/src/orchestration/work-order-contract.d.ts +44 -0
  130. package/dist/src/orchestration/work-order-contract.js +85 -0
  131. package/dist/src/orchestration/work-queue.d.ts +56 -0
  132. package/dist/src/orchestration/work-queue.js +95 -0
  133. package/dist/src/ports/advisor.d.ts +33 -0
  134. package/dist/src/ports/advisor.js +2 -0
  135. package/dist/src/ports/agent.d.ts +31 -0
  136. package/dist/src/ports/agent.js +2 -0
  137. package/dist/src/ports/capabilities.d.ts +3 -0
  138. package/dist/src/ports/capabilities.js +5 -0
  139. package/dist/src/ports/clock.d.ts +5 -0
  140. package/dist/src/ports/clock.js +5 -0
  141. package/dist/src/ports/store.d.ts +13 -0
  142. package/dist/src/ports/store.js +2 -0
  143. package/dist/src/ports/web.d.ts +29 -0
  144. package/dist/src/ports/web.js +2 -0
  145. package/dist/src/run/api-run.d.ts +49 -0
  146. package/dist/src/run/api-run.js +173 -0
  147. package/dist/src/run/plan-run.d.ts +22 -0
  148. package/dist/src/run/plan-run.js +233 -0
  149. package/dist/src/run/plan.d.ts +36 -0
  150. package/dist/src/run/plan.js +119 -0
  151. package/dist/src/run/verify.d.ts +25 -0
  152. package/dist/src/run/verify.js +81 -0
  153. package/dist/src/security/redact.d.ts +7 -0
  154. package/dist/src/security/redact.js +21 -0
  155. package/dist/src/settings/env-config.d.ts +64 -0
  156. package/dist/src/settings/env-config.js +232 -0
  157. package/dist/src/storage/artifacts.d.ts +30 -0
  158. package/dist/src/storage/artifacts.js +105 -0
  159. package/dist/src/storage/audit.d.ts +6 -0
  160. package/dist/src/storage/audit.js +6 -0
  161. package/dist/src/storage/db.d.ts +9 -0
  162. package/dist/src/storage/db.js +43 -0
  163. package/dist/src/storage/events.d.ts +20 -0
  164. package/dist/src/storage/events.js +69 -0
  165. package/dist/src/storage/migrations.d.ts +8 -0
  166. package/dist/src/storage/migrations.js +48 -0
  167. package/dist/src/storage/outbox.d.ts +25 -0
  168. package/dist/src/storage/outbox.js +40 -0
  169. package/dist/src/storage/projections.d.ts +18 -0
  170. package/dist/src/storage/projections.js +40 -0
  171. package/dist/src/storage/reconcile.d.ts +14 -0
  172. package/dist/src/storage/reconcile.js +93 -0
  173. package/dist/src/storage/reservations.d.ts +12 -0
  174. package/dist/src/storage/reservations.js +80 -0
  175. package/dist/src/storage/store.d.ts +34 -0
  176. package/dist/src/storage/store.js +105 -0
  177. package/dist/src/team/attachments.d.ts +22 -0
  178. package/dist/src/team/attachments.js +211 -0
  179. package/dist/src/team/cli-models.d.ts +24 -0
  180. package/dist/src/team/cli-models.js +72 -0
  181. package/dist/src/team/config.d.ts +20 -0
  182. package/dist/src/team/config.js +111 -0
  183. package/dist/src/team/engine.d.ts +28 -0
  184. package/dist/src/team/engine.js +443 -0
  185. package/dist/src/team/journal.d.ts +30 -0
  186. package/dist/src/team/journal.js +70 -0
  187. package/dist/src/team/runners.d.ts +79 -0
  188. package/dist/src/team/runners.js +436 -0
  189. package/dist/src/team/secrets.d.ts +10 -0
  190. package/dist/src/team/secrets.js +68 -0
  191. package/dist/src/team/types.d.ts +155 -0
  192. package/dist/src/team/types.js +5 -0
  193. package/dist/src/tui/app.d.ts +29 -0
  194. package/dist/src/tui/app.js +96 -0
  195. package/dist/src/tui/control-model.d.ts +101 -0
  196. package/dist/src/tui/control-model.js +109 -0
  197. package/dist/src/tui/control-screens.d.ts +27 -0
  198. package/dist/src/tui/control-screens.js +85 -0
  199. package/dist/src/tui/graph-model.d.ts +34 -0
  200. package/dist/src/tui/graph-model.js +29 -0
  201. package/dist/src/tui/graph-screens.d.ts +13 -0
  202. package/dist/src/tui/graph-screens.js +4 -0
  203. package/dist/src/tui/inspector-model.d.ts +150 -0
  204. package/dist/src/tui/inspector-model.js +15 -0
  205. package/dist/src/tui/inspector-screens.d.ts +14 -0
  206. package/dist/src/tui/inspector-screens.js +61 -0
  207. package/dist/src/tui/live.d.ts +16 -0
  208. package/dist/src/tui/live.js +39 -0
  209. package/dist/src/tui/mission-action-screens.d.ts +15 -0
  210. package/dist/src/tui/mission-action-screens.js +105 -0
  211. package/dist/src/tui/mission-actions.d.ts +46 -0
  212. package/dist/src/tui/mission-actions.js +53 -0
  213. package/dist/src/tui/mission-model.d.ts +120 -0
  214. package/dist/src/tui/mission-model.js +164 -0
  215. package/dist/src/tui/mission-nav.d.ts +82 -0
  216. package/dist/src/tui/mission-nav.js +131 -0
  217. package/dist/src/tui/mission-plan-screens.d.ts +11 -0
  218. package/dist/src/tui/mission-plan-screens.js +40 -0
  219. package/dist/src/tui/mission-plan.d.ts +45 -0
  220. package/dist/src/tui/mission-plan.js +166 -0
  221. package/dist/src/tui/mission-screens.d.ts +7 -0
  222. package/dist/src/tui/mission-screens.js +263 -0
  223. package/dist/src/tui/provenance-label.d.ts +11 -0
  224. package/dist/src/tui/provenance-label.js +16 -0
  225. package/dist/src/tui/screens.d.ts +10 -0
  226. package/dist/src/tui/screens.js +34 -0
  227. package/dist/src/tui/session-outcome.d.ts +14 -0
  228. package/dist/src/tui/session-outcome.js +57 -0
  229. package/dist/src/tui/setup-model.d.ts +159 -0
  230. package/dist/src/tui/setup-model.js +234 -0
  231. package/dist/src/tui/setup-screens.d.ts +66 -0
  232. package/dist/src/tui/setup-screens.js +72 -0
  233. package/dist/src/tui/team/app.d.ts +24 -0
  234. package/dist/src/tui/team/app.js +228 -0
  235. package/dist/src/tui/team/demo-handle.d.ts +22 -0
  236. package/dist/src/tui/team/demo-handle.js +42 -0
  237. package/dist/src/tui/team/model.d.ts +81 -0
  238. package/dist/src/tui/team/model.js +133 -0
  239. package/gui/app.css +177 -0
  240. package/gui/app.js +675 -0
  241. package/gui/index.html +51 -0
  242. package/gui/network.js +413 -0
  243. package/package.json +45 -4
  244. package/src/storage/schema.sql +42 -0
@@ -0,0 +1,117 @@
1
+ import { type ChildProcess, type SpawnOptions } from 'node:child_process';
2
+ import type { CkitConfig } from '../../settings/env-config.js';
3
+ export interface ExecutorSpec {
4
+ readonly kind: 'claude-code' | 'omp';
5
+ readonly executable: 'claude' | 'omp';
6
+ /** Fixed args; the instruction is appended as the final positional by runExecutor. */
7
+ readonly args: readonly string[];
8
+ }
9
+ /** claude: `-p` prompt as trailing positional (help documents `[prompt]`; stdin use is not documented in --help, so not relied on). omp: trailing MESSAGES positional. */
10
+ export declare function selectExecutor(config: Pick<CkitConfig, 'executor' | 'executorModel'> & Partial<Pick<CkitConfig, 'executorPermissionMode'>>): ExecutorSpec;
11
+ /** Preflight/doctor line for the opt-in worker permission mode. omp has no equivalent flag: it is never passed. */
12
+ export declare function describeWorkerPermission(kind: ExecutorSpec['kind'], mode: string | null): string;
13
+ export declare class ExecutorResolveError extends Error {
14
+ }
15
+ /** Finds an absolute executable path without running it. */
16
+ export declare function resolveExecutable(spec: ExecutorSpec, config: Pick<CkitConfig, 'executorPath'>, env?: Readonly<Record<string, string | undefined>>): string;
17
+ /**
18
+ * Worker-credential allowlist per adapter (TASK-T05-10, owner decision 2026-11-08). A name listed here is kept when inherited from the
19
+ * launching env even if its value equals the advisor key: an equal value does not mean CKit copied the advisor key.
20
+ * - claude-code: ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY. Source: `claude --help` (--bare: "Anthropic auth is strictly ANTHROPIC_API_KEY or
21
+ * apiKeyHelper") and the ANTHROPIC_AUTH_TOKEN gateway convention the owner relies on. No other claude credential variable is confirmed locally.
22
+ * - omp: empty. `omp --help` lists ~40 provider keys and omp has its own credential vault (auth-broker), so which variable the worker uses cannot
23
+ * be confirmed; guessing would widen the boundary. Add names here only with a documented source.
24
+ * The lists are isolated: an omp run never keeps ANTHROPIC_* because of the claude list, and the reverse.
25
+ */
26
+ export declare const WORKER_CREDENTIAL_ALLOWLIST: Readonly<Record<ExecutorSpec['kind'], readonly string[]>>;
27
+ export type WithheldReason = 'equals-advisor-key' | 'contains-advisor-key';
28
+ export interface WithheldVar {
29
+ readonly name: string;
30
+ readonly reason: WithheldReason;
31
+ }
32
+ /** present: an allowlisted credential is in the worker env. missing: the adapter has an allowlist and none is there. unmanaged: the adapter has no allowlist (it uses its own login). Presence never implies validity. */
33
+ export type WorkerAuth = 'present' | 'missing' | 'unmanaged';
34
+ export interface WorkerEnvPolicy {
35
+ readonly env: Record<string, string>;
36
+ readonly withheld: readonly WithheldVar[];
37
+ readonly workerAuth: WorkerAuth;
38
+ }
39
+ /** The single env-boundary policy shared by runs, the run preflight and doctor. Never reads or returns advisor-key values in names/reasons; never derives a worker credential from CKIT_*. */
40
+ export declare function executorEnvironmentReport(processEnv: Readonly<Record<string, string | undefined>>, advisorKey: string, kind: ExecutorSpec['kind']): WorkerEnvPolicy;
41
+ /** Child env. `kind` omitted means no allowlist (strictest). */
42
+ export declare function executorEnvironment(processEnv: Readonly<Record<string, string | undefined>>, advisorKey: string, kind?: ExecutorSpec['kind']): Record<string, string>;
43
+ /** One-line diagnostic for the run log and journal note; names and reason codes only. null when nothing was withheld. */
44
+ export declare function envBoundaryNote(withheld: readonly WithheldVar[]): string | null;
45
+ /** Preflight line (run and doctor): names, reason codes and worker-auth state; no values; presence is not validity. */
46
+ export declare function describeWorkerEnv(policy: WorkerEnvPolicy): string;
47
+ export type ExecutorResult = {
48
+ readonly status: 'completed';
49
+ readonly text: string;
50
+ } | {
51
+ readonly status: 'failed';
52
+ readonly exitCode: number | null;
53
+ readonly text: string;
54
+ readonly stderrTail?: string;
55
+ } | {
56
+ readonly status: 'unknown';
57
+ readonly reason: 'timeout' | 'cancelled' | 'spawn-error';
58
+ readonly note: string;
59
+ readonly stderrTail?: string;
60
+ };
61
+ export type SpawnImpl = (command: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
62
+ /** What the owner needs to see after a failed worker: its result text and redacted stderr tail (bounded) and the env-boundary note. */
63
+ export declare function executorFailureDetail(xr: ExecutorResult, withheld: readonly WithheldVar[]): string;
64
+ export interface SubagentObservation {
65
+ readonly childId: string;
66
+ readonly subagentType: string | null;
67
+ readonly description: string | null;
68
+ readonly via: 'task-tool-use' | 'parent-tool-use-id';
69
+ }
70
+ /** Pure: a claude stream-json frame yields an observation only when it explicitly names a subagent. Nothing is inferred. */
71
+ export declare function claudeSubagentObservations(frame: unknown): SubagentObservation[];
72
+ /** Pure NDJSON parse; non-JSON lines are skipped. claude: final `result` line. omp: `agent_end` messages, else last assistant text seen. */
73
+ export declare function parseExecutorOutput(kind: ExecutorSpec['kind'], stdout: string): {
74
+ text: string;
75
+ isError: boolean;
76
+ };
77
+ /** onEvent observer for a run log. claude: one line per observed subagent (deduped by id). omp: states once that child visibility is unsupported; never invents a child. */
78
+ export declare function subagentLogger(kind: ExecutorSpec['kind'], log: (line: string) => void): {
79
+ readonly announce: () => void;
80
+ readonly onEvent: (frame: unknown) => void;
81
+ readonly seen: () => readonly SubagentObservation[];
82
+ };
83
+ export interface RunExecutorOptions {
84
+ readonly cwd: string;
85
+ readonly timeoutMs: number;
86
+ readonly signal?: AbortSignal; /** Aborting this escalates a cancel straight to SIGKILL on the CKit-owned group (no grace wait). */
87
+ readonly hardKill?: AbortSignal;
88
+ readonly spawnImpl?: SpawnImpl;
89
+ readonly env?: Readonly<Record<string, string>>;
90
+ readonly onSpawn?: () => void;
91
+ readonly killGraceMs?: number;
92
+ /** Receives each parsed NDJSON stdout object as soon as its line is complete (line-buffered across chunks). */
93
+ readonly onEvent?: (frame: unknown) => void;
94
+ /** Exact secret values redacted from stderrTail (in addition to pattern redaction). */
95
+ readonly secrets?: readonly string[];
96
+ }
97
+ export declare function runExecutor(spec: ExecutorSpec, path: string, instruction: string, options: RunExecutorOptions): Promise<ExecutorResult>;
98
+ /** Whitespace split with simple double quotes; no escapes, globbing or expansion (the command runs with shell:false). */
99
+ export declare function splitCommand(command: string): string[];
100
+ export interface AcceptanceCommandOptions {
101
+ readonly cwd: string;
102
+ readonly timeoutMs: number;
103
+ readonly env?: Readonly<Record<string, string>>;
104
+ readonly signal?: AbortSignal;
105
+ readonly spawnImpl?: SpawnImpl;
106
+ readonly killGraceMs?: number;
107
+ }
108
+ export interface AcceptanceCommandResult {
109
+ readonly exitCode: number | null;
110
+ readonly signal: string | null;
111
+ readonly timedOut: boolean;
112
+ readonly cancelled: boolean;
113
+ readonly spawnError: string | null;
114
+ readonly output: string;
115
+ }
116
+ /** Runs one allow-listed acceptance command (argv[0] resolved via the child env PATH) with the same kill discipline as the executor. */
117
+ export declare function runAcceptanceCommand(argv: readonly string[], options: AcceptanceCommandOptions): Promise<AcceptanceCommandResult>;
@@ -0,0 +1,383 @@
1
+ // Executor CLI selection and one-shot run (ADR-017): the user's own `claude` or `omp`, using the user's own login/config.
2
+ import { spawn } from 'node:child_process';
3
+ import { accessSync, constants, statSync } from 'node:fs';
4
+ import { delimiter, isAbsolute, join } from 'node:path';
5
+ import { redactSecretText } from '../../security/redact.js';
6
+ /** claude: `-p` prompt as trailing positional (help documents `[prompt]`; stdin use is not documented in --help, so not relied on). omp: trailing MESSAGES positional. */
7
+ export function selectExecutor(config) {
8
+ const model = config.executorModel ? ['--model', config.executorModel] : [];
9
+ if (config.executor === 'omp')
10
+ return { kind: 'omp', executable: 'omp', args: ['-p', '--no-session', '--mode', 'json', ...model] };
11
+ return { kind: 'claude-code', executable: 'claude', args: ['-p', '--output-format', 'stream-json', '--verbose', ...model, ...(config.executorPermissionMode ? ['--permission-mode', config.executorPermissionMode] : [])] };
12
+ }
13
+ /** Preflight/doctor line for the opt-in worker permission mode. omp has no equivalent flag: it is never passed. */
14
+ export function describeWorkerPermission(kind, mode) {
15
+ if (kind === 'omp')
16
+ return mode === null ? 'worker permission: default' : `worker permission: not supported for omp (CKIT_EXECUTOR_PERMISSION_MODE=${mode} ignored; flag not passed)`;
17
+ return `worker permission: ${mode ?? 'default'}`;
18
+ }
19
+ export class ExecutorResolveError extends Error {
20
+ }
21
+ /** Finds an absolute executable path without running it. */
22
+ export function resolveExecutable(spec, config, env = process.env) {
23
+ const check = (path) => {
24
+ try {
25
+ if (!statSync(path).isFile())
26
+ return 'missing';
27
+ }
28
+ catch {
29
+ return 'missing';
30
+ }
31
+ try {
32
+ accessSync(path, constants.X_OK);
33
+ return 'ok';
34
+ }
35
+ catch {
36
+ return 'not-executable';
37
+ }
38
+ };
39
+ if (config.executorPath !== null) {
40
+ if (!isAbsolute(config.executorPath))
41
+ throw new ExecutorResolveError('CKIT_EXECUTOR_PATH must be an absolute path');
42
+ const state = check(config.executorPath);
43
+ if (state === 'missing')
44
+ throw new ExecutorResolveError(`executor "${spec.executable}" not found at CKIT_EXECUTOR_PATH; fix the path or remove it to search PATH`);
45
+ if (state === 'not-executable')
46
+ throw new ExecutorResolveError(`executor at CKIT_EXECUTOR_PATH is not executable; run chmod +x on it or fix the path`);
47
+ return config.executorPath;
48
+ }
49
+ let sawNonExec = false;
50
+ for (const dir of (env['PATH'] ?? '').split(delimiter).filter(Boolean)) {
51
+ if (!isAbsolute(dir))
52
+ continue;
53
+ const candidate = join(dir, spec.executable), state = check(candidate);
54
+ if (state === 'ok')
55
+ return candidate;
56
+ if (state === 'not-executable')
57
+ sawNonExec = true;
58
+ }
59
+ if (sawNonExec)
60
+ throw new ExecutorResolveError(`executor "${spec.executable}" was found on PATH but is not executable; fix its permissions or set CKIT_EXECUTOR_PATH`);
61
+ throw new ExecutorResolveError(`executor "${spec.executable}" not found on PATH; install it or set CKIT_EXECUTOR_PATH`);
62
+ }
63
+ /**
64
+ * Worker-credential allowlist per adapter (TASK-T05-10, owner decision 2026-11-08). A name listed here is kept when inherited from the
65
+ * launching env even if its value equals the advisor key: an equal value does not mean CKit copied the advisor key.
66
+ * - claude-code: ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY. Source: `claude --help` (--bare: "Anthropic auth is strictly ANTHROPIC_API_KEY or
67
+ * apiKeyHelper") and the ANTHROPIC_AUTH_TOKEN gateway convention the owner relies on. No other claude credential variable is confirmed locally.
68
+ * - omp: empty. `omp --help` lists ~40 provider keys and omp has its own credential vault (auth-broker), so which variable the worker uses cannot
69
+ * be confirmed; guessing would widen the boundary. Add names here only with a documented source.
70
+ * The lists are isolated: an omp run never keeps ANTHROPIC_* because of the claude list, and the reverse.
71
+ */
72
+ export const WORKER_CREDENTIAL_ALLOWLIST = {
73
+ 'claude-code': ['ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_API_KEY'],
74
+ omp: [],
75
+ };
76
+ /** The single env-boundary policy shared by runs, the run preflight and doctor. Never reads or returns advisor-key values in names/reasons; never derives a worker credential from CKIT_*. */
77
+ export function executorEnvironmentReport(processEnv, advisorKey, kind) {
78
+ const allow = WORKER_CREDENTIAL_ALLOWLIST[kind];
79
+ const env = {}, withheld = [];
80
+ for (const [key, value] of Object.entries(processEnv)) {
81
+ if (value === undefined || key.startsWith('CKIT_'))
82
+ continue;
83
+ if (advisorKey !== '') {
84
+ // Allowlisted worker credentials are exempt ONLY on exact equality; a value that merely contains the key stays withheld.
85
+ if (value === advisorKey && !allow.includes(key)) {
86
+ withheld.push({ name: key, reason: 'equals-advisor-key' });
87
+ continue;
88
+ }
89
+ if (value !== advisorKey && advisorKey.length >= 8 && value.includes(advisorKey)) {
90
+ withheld.push({ name: key, reason: 'contains-advisor-key' });
91
+ continue;
92
+ }
93
+ }
94
+ env[key] = value;
95
+ }
96
+ const workerAuth = allow.length === 0 ? 'unmanaged' : allow.some(n => (env[n] ?? '') !== '') ? 'present' : 'missing';
97
+ return { env, withheld, workerAuth };
98
+ }
99
+ /** Child env. `kind` omitted means no allowlist (strictest). */
100
+ export function executorEnvironment(processEnv, advisorKey, kind) {
101
+ if (kind === undefined)
102
+ return executorEnvironmentReport(processEnv, advisorKey, 'omp').env;
103
+ return executorEnvironmentReport(processEnv, advisorKey, kind).env;
104
+ }
105
+ const withheldText = (withheld) => withheld.map(w => `${w.name} (${w.reason})`).join(', ');
106
+ /** One-line diagnostic for the run log and journal note; names and reason codes only. null when nothing was withheld. */
107
+ export function envBoundaryNote(withheld) {
108
+ return withheld.length === 0 ? null : `env boundary withheld ${withheldText(withheld)}; the worker may fail to authenticate`;
109
+ }
110
+ /** Preflight line (run and doctor): names, reason codes and worker-auth state; no values; presence is not validity. */
111
+ export function describeWorkerEnv(policy) {
112
+ const auth = policy.workerAuth === 'present' ? 'worker auth: present (an allowlisted credential variable is set; validity not checked)'
113
+ : policy.workerAuth === 'missing' ? 'worker auth: missing (no allowlisted credential variable in the worker env; the worker may use its own login)'
114
+ : 'worker auth: not managed by CKit (adapter uses its own login)';
115
+ return `worker env: ${policy.withheld.length === 0 ? 'nothing withheld' : `withheld ${withheldText(policy.withheld)}`}; ${auth}`;
116
+ }
117
+ /** What the owner needs to see after a failed worker: its result text and redacted stderr tail (bounded) and the env-boundary note. */
118
+ export function executorFailureDetail(xr, withheld) {
119
+ const parts = [];
120
+ if (xr.status === 'failed' && xr.text.trim())
121
+ parts.push(`worker said: "${xr.text.trim().slice(-300)}"`);
122
+ if (xr.status !== 'completed' && xr.stderrTail?.trim())
123
+ parts.push(`stderr: "${xr.stderrTail.trim().slice(-500)}"`);
124
+ const boundary = envBoundaryNote(withheld);
125
+ if (boundary)
126
+ parts.push(boundary);
127
+ return parts.length ? `; ${parts.join('; ')}` : '';
128
+ }
129
+ /** Pure: a claude stream-json frame yields an observation only when it explicitly names a subagent. Nothing is inferred. */
130
+ export function claudeSubagentObservations(frame) {
131
+ if (frame === null || typeof frame !== 'object')
132
+ return [];
133
+ const f = frame, out = [];
134
+ const message = f['message'];
135
+ const content = message && typeof message === 'object' ? message.content : undefined;
136
+ if (Array.isArray(content)) {
137
+ for (const part of content) {
138
+ if (!part || typeof part !== 'object')
139
+ continue;
140
+ const p = part;
141
+ if (p.type !== 'tool_use' || p.name !== 'Task' || typeof p.id !== 'string' || p.id === '')
142
+ continue;
143
+ const input = p.input && typeof p.input === 'object' ? p.input : {};
144
+ const subagentType = typeof input.subagent_type === 'string' && input.subagent_type ? input.subagent_type : null;
145
+ const description = typeof input.description === 'string' && input.description ? input.description : null;
146
+ if (subagentType === null && description === null)
147
+ continue;
148
+ out.push({ childId: p.id, subagentType, description, via: 'task-tool-use' });
149
+ }
150
+ }
151
+ const parent = f['parent_tool_use_id'];
152
+ if (typeof parent === 'string' && parent !== '')
153
+ out.push({ childId: parent, subagentType: null, description: null, via: 'parent-tool-use-id' });
154
+ return out;
155
+ }
156
+ const textOf = (content) => {
157
+ if (typeof content === 'string')
158
+ return content;
159
+ if (Array.isArray(content))
160
+ return content.map(part => typeof part === 'string' ? part : part && typeof part === 'object' && typeof part.text === 'string' && (part.type === undefined || part.type === 'text') ? part.text : '').join('');
161
+ return '';
162
+ };
163
+ /** Pure NDJSON parse; non-JSON lines are skipped. claude: final `result` line. omp: `agent_end` messages, else last assistant text seen. */
164
+ export function parseExecutorOutput(kind, stdout) {
165
+ let result = null, last = '';
166
+ for (const line of stdout.split(/\r?\n/)) {
167
+ const t = line.trim();
168
+ if (!t.startsWith('{'))
169
+ continue;
170
+ let ev;
171
+ try {
172
+ ev = JSON.parse(t);
173
+ }
174
+ catch {
175
+ continue;
176
+ }
177
+ if (kind === 'claude-code' && ev['type'] === 'result')
178
+ result = { text: typeof ev['result'] === 'string' ? ev['result'] : '', isError: ev['is_error'] === true };
179
+ const msgs = ev['type'] === 'agent_end' && Array.isArray(ev['messages']) ? ev['messages'] : [ev['message']];
180
+ for (const m of msgs) {
181
+ if (m && typeof m === 'object' && m.role === 'assistant') {
182
+ const s = textOf(m.content);
183
+ if (s.trim())
184
+ last = s;
185
+ }
186
+ }
187
+ if (typeof ev['type'] === 'string' && /text|delta/.test(ev['type']) && kind === 'omp' && typeof ev['text'] === 'string' && ev['text'].trim())
188
+ last = ev['text'];
189
+ }
190
+ return result ?? { text: last, isError: false };
191
+ }
192
+ /** onEvent observer for a run log. claude: one line per observed subagent (deduped by id). omp: states once that child visibility is unsupported; never invents a child. */
193
+ export function subagentLogger(kind, log) {
194
+ const seen = new Map();
195
+ return {
196
+ announce: () => { if (kind === 'omp')
197
+ log('subagent visibility: unsupported (no documented frame)'); },
198
+ onEvent: frame => {
199
+ if (kind !== 'claude-code')
200
+ return;
201
+ for (const o of claudeSubagentObservations(frame)) {
202
+ if (seen.has(o.childId))
203
+ continue;
204
+ seen.set(o.childId, o);
205
+ log(`observed subagent ${o.childId}${o.subagentType ? ` (${o.subagentType})` : ''}${o.description ? `: ${o.description}` : ''}`);
206
+ }
207
+ },
208
+ seen: () => [...seen.values()],
209
+ };
210
+ }
211
+ const STDERR_TAIL = 16 * 1024;
212
+ export function runExecutor(spec, path, instruction, options) {
213
+ return new Promise(resolve => {
214
+ // A leading "-" must never be parsed as a flag.
215
+ const prompt = instruction.startsWith('-') ? ` ${instruction}` : instruction;
216
+ // POSIX: own process group, so only the group CKit created is signalled. Windows keeps the direct-child kill.
217
+ const grouped = process.platform !== 'win32';
218
+ let child;
219
+ try {
220
+ child = (options.spawnImpl ?? spawn)(path, [...spec.args, prompt], { cwd: options.cwd, shell: false, env: options.env ?? {}, stdio: ['ignore', 'pipe', 'pipe'], ...(grouped ? { detached: true } : {}) });
221
+ }
222
+ catch (error) {
223
+ resolve({ status: 'unknown', reason: 'spawn-error', note: error instanceof Error ? error.message : 'spawn failed' });
224
+ return;
225
+ }
226
+ let stdout = '', stderr = '', pending = '', done = false, stop = null, killTimer;
227
+ const tail = () => { const t = redactSecretText(stderr, options.secrets ?? []).slice(-STDERR_TAIL); return t.trim() ? { stderrTail: t } : {}; };
228
+ const emit = (line) => {
229
+ const t = line.trim();
230
+ if (!options.onEvent || !t.startsWith('{'))
231
+ return;
232
+ let frame;
233
+ try {
234
+ frame = JSON.parse(t);
235
+ }
236
+ catch {
237
+ return;
238
+ }
239
+ try {
240
+ options.onEvent(frame);
241
+ }
242
+ catch { /* an observer must never break the run */ }
243
+ };
244
+ const finish = (r) => { if (done)
245
+ return; done = true; clearTimeout(timer); clearTimeout(killTimer); options.signal?.removeEventListener('abort', onAbort); options.hardKill?.removeEventListener('abort', onHard); resolve(r); };
246
+ /** Group kill only for a pid CKit itself spawned detached (> 1); otherwise the direct child. */
247
+ const signalTree = (sig) => {
248
+ const pid = child.pid;
249
+ if (grouped && !options.spawnImpl && typeof pid === 'number' && pid > 1) {
250
+ try {
251
+ process.kill(-pid, sig);
252
+ return;
253
+ }
254
+ catch { /* group gone: fall through */ }
255
+ }
256
+ child.kill(sig);
257
+ };
258
+ const kill = (why) => {
259
+ if (stop)
260
+ return;
261
+ stop = why;
262
+ signalTree('SIGTERM');
263
+ killTimer = setTimeout(() => { signalTree('SIGKILL'); finish({ status: 'unknown', reason: why, note: `executor ${why === 'timeout' ? 'timed out' : 'cancelled'} and was killed`, ...tail() }); }, options.killGraceMs ?? 5000);
264
+ };
265
+ // Escalation: same guards as signalTree (pid > 1, CKit-spawned group only), then settle without waiting for close.
266
+ const onHard = () => { if (done)
267
+ return; stop ??= 'cancelled'; clearTimeout(killTimer); signalTree('SIGKILL'); finish({ status: 'unknown', reason: stop, note: `executor ${stop === 'timeout' ? 'timed out' : 'cancelled'} and was killed`, ...tail() }); };
268
+ const timer = setTimeout(() => kill('timeout'), options.timeoutMs);
269
+ const onAbort = () => kill('cancelled');
270
+ if (options.signal?.aborted)
271
+ onAbort();
272
+ else
273
+ options.signal?.addEventListener('abort', onAbort, { once: true });
274
+ if (options.hardKill?.aborted)
275
+ onHard();
276
+ else
277
+ options.hardKill?.addEventListener('abort', onHard, { once: true });
278
+ child.stdout?.on('data', (chunk) => {
279
+ const text = chunk.toString('utf8');
280
+ stdout += text;
281
+ pending += text;
282
+ const lines = pending.split('\n');
283
+ pending = lines.pop() ?? '';
284
+ for (const line of lines)
285
+ emit(line);
286
+ });
287
+ child.stderr?.on('data', (chunk) => { stderr += chunk.toString('utf8'); if (stderr.length > STDERR_TAIL * 2)
288
+ stderr = stderr.slice(-STDERR_TAIL * 2); });
289
+ child.on('error', error => finish({ status: 'unknown', reason: 'spawn-error', note: error.message }));
290
+ child.on('spawn', () => options.onSpawn?.());
291
+ child.on('close', code => {
292
+ if (pending) {
293
+ emit(pending);
294
+ pending = '';
295
+ }
296
+ if (stop) {
297
+ finish({ status: 'unknown', reason: stop, note: `executor ${stop === 'timeout' ? 'timed out' : 'cancelled'} and was terminated`, ...tail() });
298
+ return;
299
+ }
300
+ const parsed = parseExecutorOutput(spec.kind, stdout);
301
+ if (code === 0 && !parsed.isError)
302
+ finish({ status: 'completed', text: parsed.text });
303
+ else
304
+ finish({ status: 'failed', exitCode: code, text: parsed.text, ...tail() });
305
+ });
306
+ });
307
+ }
308
+ /** Whitespace split with simple double quotes; no escapes, globbing or expansion (the command runs with shell:false). */
309
+ export function splitCommand(command) {
310
+ const out = [];
311
+ let cur = '', inQuote = false, has = false;
312
+ for (const ch of command) {
313
+ if (ch === '"') {
314
+ inQuote = !inQuote;
315
+ has = true;
316
+ }
317
+ else if (!inQuote && /\s/.test(ch)) {
318
+ if (has) {
319
+ out.push(cur);
320
+ cur = '';
321
+ has = false;
322
+ }
323
+ }
324
+ else {
325
+ cur += ch;
326
+ has = true;
327
+ }
328
+ }
329
+ if (inQuote)
330
+ throw new TypeError('unterminated double quote in command');
331
+ if (has)
332
+ out.push(cur);
333
+ return out;
334
+ }
335
+ const OUTPUT_TAIL = 8192;
336
+ /** Runs one allow-listed acceptance command (argv[0] resolved via the child env PATH) with the same kill discipline as the executor. */
337
+ export function runAcceptanceCommand(argv, options) {
338
+ return new Promise(resolve => {
339
+ const [cmd, ...args] = argv;
340
+ if (cmd === undefined) {
341
+ resolve({ exitCode: null, signal: null, timedOut: false, cancelled: false, spawnError: 'empty command', output: '' });
342
+ return;
343
+ }
344
+ let child;
345
+ try {
346
+ child = (options.spawnImpl ?? spawn)(cmd, args, { cwd: options.cwd, shell: false, env: options.env ?? {}, stdio: ['ignore', 'pipe', 'pipe'] });
347
+ }
348
+ catch (error) {
349
+ resolve({ exitCode: null, signal: null, timedOut: false, cancelled: false, spawnError: error instanceof Error ? error.message : 'spawn failed', output: '' });
350
+ return;
351
+ }
352
+ let output = '', done = false, stop = null, killTimer;
353
+ const take = (chunk) => { output += chunk.toString('utf8'); if (output.length > OUTPUT_TAIL * 2)
354
+ output = output.slice(-OUTPUT_TAIL); };
355
+ const finish = (code, signal, spawnError) => {
356
+ if (done)
357
+ return;
358
+ done = true;
359
+ clearTimeout(timer);
360
+ clearTimeout(killTimer);
361
+ options.signal?.removeEventListener('abort', onAbort);
362
+ resolve({ exitCode: code, signal, timedOut: stop === 'timeout', cancelled: stop === 'cancelled', spawnError, output: output.slice(-OUTPUT_TAIL) });
363
+ };
364
+ const kill = (why) => {
365
+ if (stop)
366
+ return;
367
+ stop = why;
368
+ child.kill('SIGTERM');
369
+ killTimer = setTimeout(() => { child.kill('SIGKILL'); finish(null, 'SIGKILL', null); }, options.killGraceMs ?? 5000);
370
+ };
371
+ const timer = setTimeout(() => kill('timeout'), options.timeoutMs);
372
+ const onAbort = () => kill('cancelled');
373
+ if (options.signal?.aborted)
374
+ onAbort();
375
+ else
376
+ options.signal?.addEventListener('abort', onAbort, { once: true });
377
+ child.stdout?.on('data', take);
378
+ child.stderr?.on('data', take);
379
+ child.on('error', error => finish(null, null, error.message));
380
+ child.on('close', (code, signal) => finish(code, signal, null));
381
+ });
382
+ }
383
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1,35 @@
1
+ export interface LaunchProfile {
2
+ readonly executable: string;
3
+ readonly minimumVersion: string;
4
+ readonly profileRevision: string;
5
+ readonly cwd: string;
6
+ readonly args: readonly string[];
7
+ readonly environment: Readonly<Record<string, string>>;
8
+ }
9
+ export interface ProfileInput extends Omit<LaunchProfile, 'environment'> {
10
+ readonly environment?: Readonly<Record<string, string>>;
11
+ }
12
+ export declare function createLaunchProfile(input: ProfileInput): LaunchProfile;
13
+ export declare const secretKeyPattern: RegExp;
14
+ export declare function redactLaunchMetadata(args: readonly string[], environment: Readonly<Record<string, string>>): {
15
+ readonly args: readonly string[];
16
+ readonly environment: Readonly<Record<string, string>>;
17
+ };
18
+ export declare function constructLaunchArgs(profile: Pick<LaunchProfile, 'args'>): readonly string[];
19
+ export declare function createLaunchEnvironment(profile: Pick<LaunchProfile, 'environment'>, inherited?: Readonly<Record<string, string | undefined>>): Readonly<Record<string, string>>;
20
+ export type ExecutableInspection = {
21
+ readonly ok: true;
22
+ readonly version: string;
23
+ readonly supportsJson: boolean;
24
+ } | {
25
+ readonly ok: false;
26
+ readonly error: string;
27
+ };
28
+ export interface ExecutableInspector {
29
+ inspect(executable: string): Promise<ExecutableInspection>;
30
+ }
31
+ export interface VersionGate {
32
+ readonly minimumVersion: string;
33
+ readonly requiredJsonFlag: boolean;
34
+ }
35
+ export declare function validateExecutable(executable: string, gate: VersionGate, inspector: ExecutableInspector): Promise<string>;
@@ -0,0 +1,73 @@
1
+ import { isAbsolute } from 'node:path';
2
+ import { credentialKeyPattern, redactSecretText } from '../../security/redact.js';
3
+ export function createLaunchProfile(input) {
4
+ if (!input.executable || !input.minimumVersion || !input.profileRevision || !input.cwd)
5
+ throw new Error('Launch profile requires executable, version gate, revision and cwd');
6
+ if (!isAbsolute(input.cwd))
7
+ throw new Error('Launch profile cwd must be absolute');
8
+ if (!Array.isArray(input.args) || input.args.some((arg) => typeof arg !== 'string' || arg.includes('\0')))
9
+ throw new Error('Launch arguments must be an array of valid strings');
10
+ const environment = input.environment ?? {};
11
+ if (Object.entries(environment).some(([key, value]) => !key || key.includes('=') || key.includes('\0') || value.includes('\0')))
12
+ throw new Error('Launch environment contains an invalid variable name or value');
13
+ return Object.freeze({ ...input, args: Object.freeze([...input.args]), environment: Object.freeze({ ...environment }) });
14
+ }
15
+ export const secretKeyPattern = /(?:token|secret|pass|key|pat|passphrase)/i;
16
+ export function redactLaunchMetadata(args, environment) {
17
+ const secretKeys = Object.entries(environment).filter(([key]) => credentialKeyPattern.test(key));
18
+ const secretValues = secretKeys.map(([, value]) => value).filter(Boolean);
19
+ let safeArgs = [...args];
20
+ for (const value of secretValues)
21
+ safeArgs = safeArgs.map((arg) => arg.split(value).join('[REDACTED]'));
22
+ safeArgs = safeArgs.map((arg) => redactSecretText(arg));
23
+ const safeEnvironment = Object.fromEntries(Object.entries(environment).map(([key, value]) => [key, credentialKeyPattern.test(key) ? '[REDACTED]' : value]));
24
+ for (const value of secretValues) {
25
+ for (const [key, current] of Object.entries(safeEnvironment)) {
26
+ if (typeof current === 'string' && current.includes(value))
27
+ safeEnvironment[key] = current.split(value).join('[REDACTED]');
28
+ }
29
+ }
30
+ return { args: Object.freeze(safeArgs), environment: Object.freeze(safeEnvironment) };
31
+ }
32
+ export function constructLaunchArgs(profile) {
33
+ return Object.freeze([...profile.args]);
34
+ }
35
+ export function createLaunchEnvironment(profile, inherited = process.env) {
36
+ const result = {};
37
+ for (const [key, value] of Object.entries(inherited))
38
+ if (value !== undefined)
39
+ result[key] = value;
40
+ for (const [key, value] of Object.entries(profile.environment))
41
+ result[key] = value;
42
+ return Object.freeze(result);
43
+ }
44
+ export async function validateExecutable(executable, gate, inspector) {
45
+ let result;
46
+ try {
47
+ result = await inspector.inspect(executable);
48
+ }
49
+ catch (error) {
50
+ throw new Error(`Launch capability error: executable is unrunnable (${error instanceof Error ? error.message : String(error)}). Check the executable path and permissions.`);
51
+ }
52
+ if (!result.ok)
53
+ throw new Error(`Launch capability error: executable unavailable (${result.error}). Install or configure an executable path; no dispatch performed.`);
54
+ if (compareVersions(result.version, gate.minimumVersion) < 0)
55
+ throw new Error(`Launch capability error: version mismatch (${result.version}; requires >= ${gate.minimumVersion}). Upgrade the executable; no protocol guessing.`);
56
+ if (gate.requiredJsonFlag && !result.supportsJson)
57
+ throw new Error('Launch capability error: JSON flag capability mismatch. Use a supported CLI version; no protocol guessing.');
58
+ return result.version;
59
+ }
60
+ function compareVersions(left, right) {
61
+ const parse = (value) => value.match(/^\d+(?:\.\d+){0,2}/)?.[0].split('.').map(Number);
62
+ const a = parse(left);
63
+ const b = parse(right);
64
+ if (!a || !b)
65
+ throw new Error('Launch capability error: invalid version format; no protocol guessing.');
66
+ for (let i = 0; i < 3; i++) {
67
+ const diff = (a[i] ?? 0) - (b[i] ?? 0);
68
+ if (diff)
69
+ return diff;
70
+ }
71
+ return 0;
72
+ }
73
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1,29 @@
1
+ import type { LaunchProfile } from './profile.js';
2
+ export interface SpawnRequest {
3
+ readonly executable: string;
4
+ readonly args: readonly string[];
5
+ readonly cwd: string;
6
+ readonly env: Readonly<Record<string, string>>;
7
+ }
8
+ export interface SpawnPort {
9
+ spawn(request: SpawnRequest): Promise<{
10
+ readonly stdout: string;
11
+ }>;
12
+ }
13
+ export interface LaunchEvidence {
14
+ readonly label: 'SIMULATED';
15
+ readonly executableVersion: string;
16
+ readonly cwd: string;
17
+ readonly profileRevision: string;
18
+ readonly args: readonly string[];
19
+ readonly environment: Readonly<Record<string, string>>;
20
+ }
21
+ export interface FixtureRunResult {
22
+ readonly label: 'SIMULATED';
23
+ readonly stdout: string;
24
+ readonly evidence: LaunchEvidence;
25
+ }
26
+ /** Offline-only fixture seam; callers supply the observed version and a test spawn port. */
27
+ export declare function runFixture(profile: LaunchProfile, port: SpawnPort, metadata?: {
28
+ readonly version?: string;
29
+ }): Promise<FixtureRunResult>;
@@ -0,0 +1,18 @@
1
+ import { createLaunchEnvironment, constructLaunchArgs, redactLaunchMetadata } from './profile.js';
2
+ import { credentialKeyPattern } from '../../security/redact.js';
3
+ const secretPattern = credentialKeyPattern;
4
+ /** Offline-only fixture seam; callers supply the observed version and a test spawn port. */
5
+ export async function runFixture(profile, port, metadata = {}) {
6
+ const version = metadata.version ?? profile.minimumVersion;
7
+ const response = await port.spawn({ executable: profile.executable, args: constructLaunchArgs(profile), cwd: profile.cwd, env: createLaunchEnvironment(profile, {}) });
8
+ return result(profile, version, profile.environment, response.stdout);
9
+ }
10
+ function result(profile, version, env, rawOutput) {
11
+ const safe = redactLaunchMetadata(constructLaunchArgs(profile), env);
12
+ let stdout = rawOutput;
13
+ for (const [key, value] of Object.entries(env))
14
+ if (secretPattern.test(key) && value.length > 0)
15
+ stdout = stdout.split(value).join('[REDACTED]');
16
+ return { label: 'SIMULATED', stdout, evidence: { label: 'SIMULATED', executableVersion: version, cwd: profile.cwd, profileRevision: profile.profileRevision, args: safe.args, environment: safe.environment } };
17
+ }
18
+ //# sourceMappingURL=spawn.js.map