@ngockhoale/ckit 0.0.0-stage → 0.1.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.
- package/.env.example +21 -0
- package/README.md +70 -2
- package/dist/src/adapters/agent/claude/errors.d.ts +13 -0
- package/dist/src/adapters/agent/claude/errors.js +16 -0
- package/dist/src/adapters/agent/claude/normalize.d.ts +11 -0
- package/dist/src/adapters/agent/claude/normalize.js +83 -0
- package/dist/src/adapters/agent/errors.d.ts +13 -0
- package/dist/src/adapters/agent/errors.js +19 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.d.ts +70 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.js +15 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.d.ts +60 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.js +14 -0
- package/dist/src/adapters/agent/normalize.d.ts +18 -0
- package/dist/src/adapters/agent/normalize.js +77 -0
- package/dist/src/adapters/agent/transport.d.ts +35 -0
- package/dist/src/adapters/agent/transport.js +39 -0
- package/dist/src/adapters/agent/worker-service.d.ts +49 -0
- package/dist/src/adapters/agent/worker-service.js +77 -0
- package/dist/src/adapters/fake/fake-advisor.d.ts +15 -0
- package/dist/src/adapters/fake/fake-advisor.js +29 -0
- package/dist/src/adapters/fake/fake-agent.d.ts +12 -0
- package/dist/src/adapters/fake/fake-agent.js +21 -0
- package/dist/src/adapters/fake/fake-store.d.ts +13 -0
- package/dist/src/adapters/fake/fake-store.js +23 -0
- package/dist/src/adapters/fake/fake-web.d.ts +12 -0
- package/dist/src/adapters/fake/fake-web.js +21 -0
- package/dist/src/adapters/fake/fault-injector.d.ts +18 -0
- package/dist/src/adapters/fake/fault-injector.js +64 -0
- package/dist/src/adapters/fake/virtual-clock.d.ts +12 -0
- package/dist/src/adapters/fake/virtual-clock.js +35 -0
- package/dist/src/adapters/launch/discover.d.ts +18 -0
- package/dist/src/adapters/launch/discover.js +55 -0
- package/dist/src/adapters/launch/executor.d.ts +117 -0
- package/dist/src/adapters/launch/executor.js +383 -0
- package/dist/src/adapters/launch/profile.d.ts +35 -0
- package/dist/src/adapters/launch/profile.js +73 -0
- package/dist/src/adapters/launch/spawn.d.ts +29 -0
- package/dist/src/adapters/launch/spawn.js +18 -0
- package/dist/src/adapters/openai/openai-advisor.d.ts +56 -0
- package/dist/src/adapters/openai/openai-advisor.js +146 -0
- package/dist/src/cli/ckit.d.ts +5 -0
- package/dist/src/cli/ckit.js +384 -0
- package/dist/src/cli/demo.d.ts +1 -0
- package/dist/src/cli/demo.js +30 -0
- package/dist/src/cli/lifecycle.d.ts +19 -0
- package/dist/src/cli/lifecycle.js +90 -0
- package/dist/src/cli/sessions.d.ts +10 -0
- package/dist/src/cli/sessions.js +381 -0
- package/dist/src/cli/setup.d.ts +11 -0
- package/dist/src/cli/setup.js +115 -0
- package/dist/src/committee/decision.d.ts +84 -0
- package/dist/src/committee/decision.js +167 -0
- package/dist/src/committee/handover.d.ts +115 -0
- package/dist/src/committee/handover.js +191 -0
- package/dist/src/committee/no-progress.d.ts +44 -0
- package/dist/src/committee/no-progress.js +64 -0
- package/dist/src/committee/primary-registry.d.ts +15 -0
- package/dist/src/committee/primary-registry.js +60 -0
- package/dist/src/committee/reply-parser.d.ts +28 -0
- package/dist/src/committee/reply-parser.js +53 -0
- package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
- package/dist/src/committee/reviewer-scheduler.js +163 -0
- package/dist/src/committee/role-epoch.d.ts +91 -0
- package/dist/src/committee/role-epoch.js +154 -0
- package/dist/src/core/control.d.ts +18 -0
- package/dist/src/core/control.js +29 -0
- package/dist/src/core/entities.d.ts +166 -0
- package/dist/src/core/entities.js +119 -0
- package/dist/src/core/errors.d.ts +9 -0
- package/dist/src/core/errors.js +17 -0
- package/dist/src/core/events.d.ts +72 -0
- package/dist/src/core/events.js +125 -0
- package/dist/src/core/ids.d.ts +47 -0
- package/dist/src/core/ids.js +32 -0
- package/dist/src/core/machine.d.ts +55 -0
- package/dist/src/core/machine.js +110 -0
- package/dist/src/core/policy.d.ts +34 -0
- package/dist/src/core/policy.js +59 -0
- package/dist/src/core/provenance.d.ts +20 -0
- package/dist/src/core/provenance.js +21 -0
- package/dist/src/core/record.d.ts +35 -0
- package/dist/src/core/record.js +67 -0
- package/dist/src/core/replay.d.ts +10 -0
- package/dist/src/core/replay.js +36 -0
- package/dist/src/core/run-task.d.ts +20 -0
- package/dist/src/core/run-task.js +48 -0
- package/dist/src/diagnostics/doctor.d.ts +78 -0
- package/dist/src/diagnostics/doctor.js +365 -0
- package/dist/src/diagnostics/journal-lock.d.ts +38 -0
- package/dist/src/diagnostics/journal-lock.js +181 -0
- package/dist/src/evidence/linker.d.ts +44 -0
- package/dist/src/evidence/linker.js +75 -0
- package/dist/src/evidence/report-parser.d.ts +27 -0
- package/dist/src/evidence/report-parser.js +17 -0
- package/dist/src/evidence/store.d.ts +36 -0
- package/dist/src/evidence/store.js +57 -0
- package/dist/src/gui/server.d.ts +27 -0
- package/dist/src/gui/server.js +497 -0
- package/dist/src/host/checkpoint.d.ts +22 -0
- package/dist/src/host/checkpoint.js +74 -0
- package/dist/src/host/export.d.ts +52 -0
- package/dist/src/host/export.js +45 -0
- package/dist/src/host/ipc.d.ts +57 -0
- package/dist/src/host/ipc.js +124 -0
- package/dist/src/host/leases.d.ts +27 -0
- package/dist/src/host/leases.js +40 -0
- package/dist/src/host/retention.d.ts +47 -0
- package/dist/src/host/retention.js +130 -0
- package/dist/src/host/supervisor.d.ts +59 -0
- package/dist/src/host/supervisor.js +64 -0
- package/dist/src/intake/owner-intake.d.ts +31 -0
- package/dist/src/intake/owner-intake.js +97 -0
- package/dist/src/intake/types.d.ts +46 -0
- package/dist/src/intake/types.js +2 -0
- package/dist/src/intent/context-packet.d.ts +68 -0
- package/dist/src/intent/context-packet.js +76 -0
- package/dist/src/intent/idea-ledger.d.ts +50 -0
- package/dist/src/intent/idea-ledger.js +136 -0
- package/dist/src/intent/ledger.d.ts +35 -0
- package/dist/src/intent/ledger.js +40 -0
- package/dist/src/intent/registry.d.ts +51 -0
- package/dist/src/intent/registry.js +44 -0
- package/dist/src/intent/revision.d.ts +37 -0
- package/dist/src/intent/revision.js +48 -0
- package/dist/src/orchestration/dispatcher.d.ts +32 -0
- package/dist/src/orchestration/dispatcher.js +136 -0
- package/dist/src/orchestration/milestone-loop.d.ts +149 -0
- package/dist/src/orchestration/milestone-loop.js +132 -0
- package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
- package/dist/src/orchestration/recovery-coordinator.js +180 -0
- package/dist/src/orchestration/work-order-contract.d.ts +44 -0
- package/dist/src/orchestration/work-order-contract.js +85 -0
- package/dist/src/orchestration/work-queue.d.ts +56 -0
- package/dist/src/orchestration/work-queue.js +95 -0
- package/dist/src/ports/advisor.d.ts +33 -0
- package/dist/src/ports/advisor.js +2 -0
- package/dist/src/ports/agent.d.ts +31 -0
- package/dist/src/ports/agent.js +2 -0
- package/dist/src/ports/capabilities.d.ts +3 -0
- package/dist/src/ports/capabilities.js +5 -0
- package/dist/src/ports/clock.d.ts +5 -0
- package/dist/src/ports/clock.js +5 -0
- package/dist/src/ports/store.d.ts +13 -0
- package/dist/src/ports/store.js +2 -0
- package/dist/src/ports/web.d.ts +29 -0
- package/dist/src/ports/web.js +2 -0
- package/dist/src/run/api-run.d.ts +49 -0
- package/dist/src/run/api-run.js +173 -0
- package/dist/src/run/plan-run.d.ts +22 -0
- package/dist/src/run/plan-run.js +233 -0
- package/dist/src/run/plan.d.ts +36 -0
- package/dist/src/run/plan.js +119 -0
- package/dist/src/run/verify.d.ts +25 -0
- package/dist/src/run/verify.js +81 -0
- package/dist/src/security/redact.d.ts +7 -0
- package/dist/src/security/redact.js +21 -0
- package/dist/src/settings/env-config.d.ts +64 -0
- package/dist/src/settings/env-config.js +232 -0
- package/dist/src/storage/artifacts.d.ts +30 -0
- package/dist/src/storage/artifacts.js +105 -0
- package/dist/src/storage/audit.d.ts +6 -0
- package/dist/src/storage/audit.js +6 -0
- package/dist/src/storage/db.d.ts +9 -0
- package/dist/src/storage/db.js +43 -0
- package/dist/src/storage/events.d.ts +20 -0
- package/dist/src/storage/events.js +69 -0
- package/dist/src/storage/migrations.d.ts +8 -0
- package/dist/src/storage/migrations.js +48 -0
- package/dist/src/storage/outbox.d.ts +25 -0
- package/dist/src/storage/outbox.js +40 -0
- package/dist/src/storage/projections.d.ts +18 -0
- package/dist/src/storage/projections.js +40 -0
- package/dist/src/storage/reconcile.d.ts +14 -0
- package/dist/src/storage/reconcile.js +93 -0
- package/dist/src/storage/reservations.d.ts +12 -0
- package/dist/src/storage/reservations.js +80 -0
- package/dist/src/storage/store.d.ts +34 -0
- package/dist/src/storage/store.js +105 -0
- package/dist/src/team/attachments.d.ts +22 -0
- package/dist/src/team/attachments.js +211 -0
- package/dist/src/team/cli-models.d.ts +24 -0
- package/dist/src/team/cli-models.js +72 -0
- package/dist/src/team/config.d.ts +20 -0
- package/dist/src/team/config.js +113 -0
- package/dist/src/team/engine.d.ts +28 -0
- package/dist/src/team/engine.js +443 -0
- package/dist/src/team/journal.d.ts +30 -0
- package/dist/src/team/journal.js +70 -0
- package/dist/src/team/runners.d.ts +79 -0
- package/dist/src/team/runners.js +436 -0
- package/dist/src/team/secrets.d.ts +10 -0
- package/dist/src/team/secrets.js +68 -0
- package/dist/src/team/types.d.ts +157 -0
- package/dist/src/team/types.js +5 -0
- package/dist/src/tui/app.d.ts +29 -0
- package/dist/src/tui/app.js +96 -0
- package/dist/src/tui/control-model.d.ts +101 -0
- package/dist/src/tui/control-model.js +109 -0
- package/dist/src/tui/control-screens.d.ts +27 -0
- package/dist/src/tui/control-screens.js +85 -0
- package/dist/src/tui/graph-model.d.ts +34 -0
- package/dist/src/tui/graph-model.js +29 -0
- package/dist/src/tui/graph-screens.d.ts +13 -0
- package/dist/src/tui/graph-screens.js +4 -0
- package/dist/src/tui/inspector-model.d.ts +150 -0
- package/dist/src/tui/inspector-model.js +15 -0
- package/dist/src/tui/inspector-screens.d.ts +14 -0
- package/dist/src/tui/inspector-screens.js +61 -0
- package/dist/src/tui/live.d.ts +16 -0
- package/dist/src/tui/live.js +39 -0
- package/dist/src/tui/mission-action-screens.d.ts +15 -0
- package/dist/src/tui/mission-action-screens.js +105 -0
- package/dist/src/tui/mission-actions.d.ts +46 -0
- package/dist/src/tui/mission-actions.js +53 -0
- package/dist/src/tui/mission-model.d.ts +120 -0
- package/dist/src/tui/mission-model.js +164 -0
- package/dist/src/tui/mission-nav.d.ts +82 -0
- package/dist/src/tui/mission-nav.js +131 -0
- package/dist/src/tui/mission-plan-screens.d.ts +11 -0
- package/dist/src/tui/mission-plan-screens.js +40 -0
- package/dist/src/tui/mission-plan.d.ts +45 -0
- package/dist/src/tui/mission-plan.js +166 -0
- package/dist/src/tui/mission-screens.d.ts +7 -0
- package/dist/src/tui/mission-screens.js +263 -0
- package/dist/src/tui/provenance-label.d.ts +11 -0
- package/dist/src/tui/provenance-label.js +16 -0
- package/dist/src/tui/screens.d.ts +10 -0
- package/dist/src/tui/screens.js +34 -0
- package/dist/src/tui/session-outcome.d.ts +14 -0
- package/dist/src/tui/session-outcome.js +57 -0
- package/dist/src/tui/setup-model.d.ts +159 -0
- package/dist/src/tui/setup-model.js +234 -0
- package/dist/src/tui/setup-screens.d.ts +66 -0
- package/dist/src/tui/setup-screens.js +72 -0
- package/dist/src/tui/team/app.d.ts +24 -0
- package/dist/src/tui/team/app.js +228 -0
- package/dist/src/tui/team/demo-handle.d.ts +22 -0
- package/dist/src/tui/team/demo-handle.js +42 -0
- package/dist/src/tui/team/model.d.ts +81 -0
- package/dist/src/tui/team/model.js +133 -0
- package/gui/app.css +177 -0
- package/gui/app.js +677 -0
- package/gui/index.html +51 -0
- package/gui/network.js +413 -0
- package/package.json +44 -4
- package/src/storage/schema.sql +42 -0
|
@@ -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
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AdvisorMessage, AdvisorPort, DispatchRequest } from '../../ports/advisor.js';
|
|
2
|
+
import type { CkitConfig } from '../../settings/env-config.js';
|
|
3
|
+
export type FetchImpl = (url: string, init: {
|
|
4
|
+
method: string;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
body?: string;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
status: number;
|
|
10
|
+
ok: boolean;
|
|
11
|
+
text(): Promise<string>;
|
|
12
|
+
}>;
|
|
13
|
+
export interface ChatMessage {
|
|
14
|
+
readonly role: 'system' | 'user' | 'assistant';
|
|
15
|
+
readonly content: string;
|
|
16
|
+
}
|
|
17
|
+
export interface AdvisorThread {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly role: 'primary' | 'reviewer';
|
|
20
|
+
readonly model: string;
|
|
21
|
+
readonly messages: ChatMessage[];
|
|
22
|
+
}
|
|
23
|
+
/** Persists a (redacted) assistant reply and returns its artifact reference. */
|
|
24
|
+
export interface ThreadStore {
|
|
25
|
+
saveReply(thread: AdvisorThread, text: string): Promise<string>;
|
|
26
|
+
}
|
|
27
|
+
export type AdvisorConfig = Pick<CkitConfig, 'baseUrl' | 'auth' | 'apiKey' | 'timeoutMs' | 'maxTokens'>;
|
|
28
|
+
/** never-sent only when a cause code proves it and no code says otherwise; no code, or any other code, is unknown. */
|
|
29
|
+
export declare function isNeverSent(error: unknown): boolean;
|
|
30
|
+
export declare class OpenAiCompatibleAdvisor implements AdvisorPort {
|
|
31
|
+
private readonly config;
|
|
32
|
+
private readonly store;
|
|
33
|
+
private readonly fetchImpl;
|
|
34
|
+
readonly name = "openai-compatible";
|
|
35
|
+
readonly isSimulated = false;
|
|
36
|
+
/** Number of HTTP requests this instance has issued (for tests and audit). */
|
|
37
|
+
requests: number;
|
|
38
|
+
private readonly prompts;
|
|
39
|
+
constructor(config: AdvisorConfig, store: ThreadStore, fetchImpl?: FetchImpl);
|
|
40
|
+
createAdvisorThread(role: 'primary' | 'reviewer', id: string, model: string, system?: string): AdvisorThread;
|
|
41
|
+
/** Registers the prompt text a later dispatch({promptRef}) will send on `thread`. */
|
|
42
|
+
registerPrompt(promptRef: string, thread: AdvisorThread, text: string): void;
|
|
43
|
+
dispatch(req: DispatchRequest): AsyncIterable<AdvisorMessage>;
|
|
44
|
+
private redact;
|
|
45
|
+
private note;
|
|
46
|
+
/** Sends exactly one request. The user text is appended to the thread only when sent; the reply only when valid. */
|
|
47
|
+
sendTurn(thread: AdvisorThread, userText: string, opts?: {
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}): AsyncIterable<AdvisorMessage>;
|
|
50
|
+
}
|
|
51
|
+
export type ConnectionStatus = 'ok' | 'auth' | 'not-found' | 'client-error' | 'server-error' | 'timeout' | 'unreachable';
|
|
52
|
+
/** Single GET {base}/models. Returns a status class only. Used only by `ckit doctor --check-connection`. */
|
|
53
|
+
export declare function checkConnection(config: Pick<CkitConfig, 'baseUrl' | 'auth' | 'apiKey'>, fetchImpl?: FetchImpl): Promise<{
|
|
54
|
+
status: ConnectionStatus;
|
|
55
|
+
http: number | null;
|
|
56
|
+
}>;
|