@agentic-sdlc-kit/cli 0.0.0-stage → 0.9.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/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/application/agent/execution-store.d.ts +55 -0
- package/dist/application/agent/execution-store.d.ts.map +1 -0
- package/dist/application/agent/execution-store.js +91 -0
- package/dist/application/agent/execution-store.js.map +1 -0
- package/dist/application/agent/gateway.d.ts +74 -0
- package/dist/application/agent/gateway.d.ts.map +1 -0
- package/dist/application/agent/gateway.js +580 -0
- package/dist/application/agent/gateway.js.map +1 -0
- package/dist/application/agent/index.d.ts +6 -0
- package/dist/application/agent/index.d.ts.map +1 -0
- package/dist/application/agent/index.js +18 -0
- package/dist/application/agent/index.js.map +1 -0
- package/dist/application/agent/orchestrator.d.ts +76 -0
- package/dist/application/agent/orchestrator.d.ts.map +1 -0
- package/dist/application/agent/orchestrator.js +422 -0
- package/dist/application/agent/orchestrator.js.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js +98 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js.map +1 -0
- package/dist/application/agent/providers/claude-code/index.d.ts +7 -0
- package/dist/application/agent/providers/claude-code/index.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/index.js +13 -0
- package/dist/application/agent/providers/claude-code/index.js.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js +41 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts +59 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.js +189 -0
- package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts +38 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.js +577 -0
- package/dist/application/agent/providers/claude-code/provider.js.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts +25 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.js +120 -0
- package/dist/application/agent/providers/claude-code/resume-store.js.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts +50 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js +129 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js.map +1 -0
- package/dist/application/agent/test-fixture.d.ts +15 -0
- package/dist/application/agent/test-fixture.d.ts.map +1 -0
- package/dist/application/agent/test-fixture.js +93 -0
- package/dist/application/agent/test-fixture.js.map +1 -0
- package/dist/application/agent/workspace.d.ts +24 -0
- package/dist/application/agent/workspace.d.ts.map +1 -0
- package/dist/application/agent/workspace.js +139 -0
- package/dist/application/agent/workspace.js.map +1 -0
- package/dist/application/dispatcher.d.ts +13 -0
- package/dist/application/dispatcher.d.ts.map +1 -0
- package/dist/application/dispatcher.js +116 -0
- package/dist/application/dispatcher.js.map +1 -0
- package/dist/application/index.d.ts +5 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +6 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/registry.d.ts +8 -0
- package/dist/application/registry.d.ts.map +1 -0
- package/dist/application/registry.js +17 -0
- package/dist/application/registry.js.map +1 -0
- package/dist/application/version.d.ts +2 -0
- package/dist/application/version.d.ts.map +1 -0
- package/dist/application/version.js +7 -0
- package/dist/application/version.js.map +1 -0
- package/dist/commands/attach-exclude.d.ts +8 -0
- package/dist/commands/attach-exclude.d.ts.map +1 -0
- package/dist/commands/attach-exclude.js +48 -0
- package/dist/commands/attach-exclude.js.map +1 -0
- package/dist/commands/attach-git.d.ts +11 -0
- package/dist/commands/attach-git.d.ts.map +1 -0
- package/dist/commands/attach-git.js +40 -0
- package/dist/commands/attach-git.js.map +1 -0
- package/dist/commands/attach-store.d.ts +10 -0
- package/dist/commands/attach-store.d.ts.map +1 -0
- package/dist/commands/attach-store.js +107 -0
- package/dist/commands/attach-store.js.map +1 -0
- package/dist/commands/attach.d.ts +8 -0
- package/dist/commands/attach.d.ts.map +1 -0
- package/dist/commands/attach.js +124 -0
- package/dist/commands/attach.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +68 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/elicit.d.ts +3 -0
- package/dist/commands/elicit.d.ts.map +1 -0
- package/dist/commands/elicit.js +163 -0
- package/dist/commands/elicit.js.map +1 -0
- package/dist/commands/evolve.d.ts +3 -0
- package/dist/commands/evolve.d.ts.map +1 -0
- package/dist/commands/evolve.js +165 -0
- package/dist/commands/evolve.js.map +1 -0
- package/dist/commands/feature.d.ts +13 -0
- package/dist/commands/feature.d.ts.map +1 -0
- package/dist/commands/feature.js +326 -0
- package/dist/commands/feature.js.map +1 -0
- package/dist/commands/fix.d.ts +4 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +53 -0
- package/dist/commands/fix.js.map +1 -0
- package/dist/commands/help.d.ts +4 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +32 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/host-apply.d.ts +12 -0
- package/dist/commands/host-apply.d.ts.map +1 -0
- package/dist/commands/host-apply.js +43 -0
- package/dist/commands/host-apply.js.map +1 -0
- package/dist/commands/host.d.ts +3 -0
- package/dist/commands/host.d.ts.map +1 -0
- package/dist/commands/host.js +107 -0
- package/dist/commands/host.js.map +1 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +26 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +92 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/inspect.d.ts +3 -0
- package/dist/commands/inspect.d.ts.map +1 -0
- package/dist/commands/inspect.js +64 -0
- package/dist/commands/inspect.js.map +1 -0
- package/dist/commands/install.d.ts +3 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +337 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/journal.d.ts +3 -0
- package/dist/commands/journal.d.ts.map +1 -0
- package/dist/commands/journal.js +107 -0
- package/dist/commands/journal.js.map +1 -0
- package/dist/commands/memory.d.ts +3 -0
- package/dist/commands/memory.d.ts.map +1 -0
- package/dist/commands/memory.js +85 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/commands/new.d.ts +3 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +68 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/next.d.ts +3 -0
- package/dist/commands/next.d.ts.map +1 -0
- package/dist/commands/next.js +107 -0
- package/dist/commands/next.js.map +1 -0
- package/dist/commands/optimize.d.ts +3 -0
- package/dist/commands/optimize.d.ts.map +1 -0
- package/dist/commands/optimize.js +28 -0
- package/dist/commands/optimize.js.map +1 -0
- package/dist/commands/plugin-linker.d.ts +43 -0
- package/dist/commands/plugin-linker.d.ts.map +1 -0
- package/dist/commands/plugin-linker.js +216 -0
- package/dist/commands/plugin-linker.js.map +1 -0
- package/dist/commands/refactor.d.ts +3 -0
- package/dist/commands/refactor.d.ts.map +1 -0
- package/dist/commands/refactor.js +32 -0
- package/dist/commands/refactor.js.map +1 -0
- package/dist/commands/skills-install-commit.d.ts +34 -0
- package/dist/commands/skills-install-commit.d.ts.map +1 -0
- package/dist/commands/skills-install-commit.js +113 -0
- package/dist/commands/skills-install-commit.js.map +1 -0
- package/dist/commands/skills-install-manifest.d.ts +35 -0
- package/dist/commands/skills-install-manifest.d.ts.map +1 -0
- package/dist/commands/skills-install-manifest.js +89 -0
- package/dist/commands/skills-install-manifest.js.map +1 -0
- package/dist/commands/skills-install-report.d.ts +12 -0
- package/dist/commands/skills-install-report.d.ts.map +1 -0
- package/dist/commands/skills-install-report.js +44 -0
- package/dist/commands/skills-install-report.js.map +1 -0
- package/dist/commands/skills-install-secure.d.ts +14 -0
- package/dist/commands/skills-install-secure.d.ts.map +1 -0
- package/dist/commands/skills-install-secure.js +96 -0
- package/dist/commands/skills-install-secure.js.map +1 -0
- package/dist/commands/skills-install.d.ts +15 -0
- package/dist/commands/skills-install.d.ts.map +1 -0
- package/dist/commands/skills-install.js +182 -0
- package/dist/commands/skills-install.js.map +1 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +217 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/types.d.ts +19 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +7 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/uninstall.d.ts +3 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +113 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/commands/validate-plan.d.ts +3 -0
- package/dist/commands/validate-plan.d.ts.map +1 -0
- package/dist/commands/validate-plan.js +62 -0
- package/dist/commands/validate-plan.js.map +1 -0
- package/dist/commands/validate-spec.d.ts +3 -0
- package/dist/commands/validate-spec.d.ts.map +1 -0
- package/dist/commands/validate-spec.js +62 -0
- package/dist/commands/validate-spec.js.map +1 -0
- package/dist/commands/verify.d.ts +3 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +103 -0
- package/dist/commands/verify.js.map +1 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +12 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/output/formatter.d.ts +2 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +10 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/index.d.ts +2 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +3 -0
- package/dist/output/index.js.map +1 -0
- package/package.json +37 -3
- package/src/application/agent/execution-store.ts +163 -0
- package/src/application/agent/gateway.test.ts +529 -0
- package/src/application/agent/gateway.ts +744 -0
- package/src/application/agent/index.ts +18 -0
- package/src/application/agent/orchestrator.test.ts +341 -0
- package/src/application/agent/orchestrator.ts +629 -0
- package/src/application/agent/providers/claude-code/claude-argv.ts +119 -0
- package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +139 -0
- package/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs +125 -0
- package/src/application/agent/providers/claude-code/index.ts +28 -0
- package/src/application/agent/providers/claude-code/mod-parity.ts +50 -0
- package/src/application/agent/providers/claude-code/permission-config.test.ts +221 -0
- package/src/application/agent/providers/claude-code/permission-config.ts +242 -0
- package/src/application/agent/providers/claude-code/provider.test.ts +378 -0
- package/src/application/agent/providers/claude-code/provider.ts +717 -0
- package/src/application/agent/providers/claude-code/resume-store.test.ts +161 -0
- package/src/application/agent/providers/claude-code/resume-store.ts +157 -0
- package/src/application/agent/providers/claude-code/stream-parser.ts +166 -0
- package/src/application/agent/test-fixture.ts +131 -0
- package/src/application/agent/workspace.test.ts +104 -0
- package/src/application/agent/workspace.ts +156 -0
- package/src/application/dispatcher.test.ts +108 -0
- package/src/application/dispatcher.ts +106 -0
- package/src/application/index.ts +5 -0
- package/src/application/registry.ts +24 -0
- package/src/application/version.ts +7 -0
- package/src/commands/attach-exclude.ts +50 -0
- package/src/commands/attach-git.ts +50 -0
- package/src/commands/attach-store.ts +107 -0
- package/src/commands/attach.test.ts +192 -0
- package/src/commands/attach.ts +143 -0
- package/src/commands/clse.test.ts +181 -0
- package/src/commands/doctor.test.ts +29 -0
- package/src/commands/doctor.ts +78 -0
- package/src/commands/elicit.test.ts +111 -0
- package/src/commands/elicit.ts +188 -0
- package/src/commands/evolve.ts +209 -0
- package/src/commands/feature.test.ts +323 -0
- package/src/commands/feature.ts +405 -0
- package/src/commands/fix.test.ts +118 -0
- package/src/commands/fix.ts +58 -0
- package/src/commands/help.test.ts +33 -0
- package/src/commands/help.ts +35 -0
- package/src/commands/host-apply.ts +61 -0
- package/src/commands/host.test.ts +120 -0
- package/src/commands/host.ts +125 -0
- package/src/commands/index.ts +25 -0
- package/src/commands/init.test.ts +87 -0
- package/src/commands/init.ts +110 -0
- package/src/commands/inspect.test.ts +57 -0
- package/src/commands/inspect.ts +73 -0
- package/src/commands/install.test.ts +92 -0
- package/src/commands/install.ts +389 -0
- package/src/commands/journal.ts +118 -0
- package/src/commands/memory.ts +96 -0
- package/src/commands/new.test.ts +44 -0
- package/src/commands/new.ts +77 -0
- package/src/commands/next.test.ts +241 -0
- package/src/commands/next.ts +124 -0
- package/src/commands/optimize.ts +30 -0
- package/src/commands/plugin-linker.test.ts +219 -0
- package/src/commands/plugin-linker.ts +244 -0
- package/src/commands/refactor.ts +34 -0
- package/src/commands/skills-install-commit.ts +149 -0
- package/src/commands/skills-install-manifest.ts +124 -0
- package/src/commands/skills-install-report.ts +60 -0
- package/src/commands/skills-install-secure.ts +113 -0
- package/src/commands/skills-install.ts +245 -0
- package/src/commands/skills.test.ts +449 -0
- package/src/commands/skills.ts +247 -0
- package/src/commands/stack-commands.test.ts +67 -0
- package/src/commands/tier-c-conformance.test.ts +194 -0
- package/src/commands/types.ts +26 -0
- package/src/commands/uninstall.test.ts +122 -0
- package/src/commands/uninstall.ts +116 -0
- package/src/commands/validate-plan.test.ts +107 -0
- package/src/commands/validate-plan.ts +67 -0
- package/src/commands/validate-spec.test.ts +59 -0
- package/src/commands/validate-spec.ts +68 -0
- package/src/commands/verify.test.ts +117 -0
- package/src/commands/verify.ts +112 -0
- package/src/commands/version.test.ts +11 -0
- package/src/commands/version.ts +14 -0
- package/src/index.ts +30 -0
- package/src/output/formatter.ts +10 -0
- package/src/output/index.ts +2 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/claude-argv.ts
|
|
2
|
+
//
|
|
3
|
+
// Claude Code headless argv builder (ADR-0019 PR4; ADR-0020 §6).
|
|
4
|
+
//
|
|
5
|
+
// ADR-0020 §6.1/§6.2: the provider process is spawned with an allowlisted
|
|
6
|
+
// executable + ARGV ARRAY, `shell: false` — never a shell string, never
|
|
7
|
+
// model-generated shell. This module is a PURE function over the request:
|
|
8
|
+
// same request in, same argv out; every flag is derived from the canonical
|
|
9
|
+
// policy (via permission-config) or the frozen request.
|
|
10
|
+
//
|
|
11
|
+
// Headless mode (Claude Code `-p` / --print) with `--output-format
|
|
12
|
+
// stream-json --verbose` emits newline-delimited JSON lifecycle events the
|
|
13
|
+
// provider parses (stream-parser.ts) — a final `result` object carries the
|
|
14
|
+
// status, session id, and usage the provider normalizes into the honest
|
|
15
|
+
// AgentExecutionResult.
|
|
16
|
+
//
|
|
17
|
+
// SECURITY INVARIANT: `--dangerously-skip-permissions` and
|
|
18
|
+
// `--permission-mode bypassPermissions` are NEVER emitted — asserted here
|
|
19
|
+
// and pinned by provider tests (ADR-0019 §6.5, ADR-0020).
|
|
20
|
+
|
|
21
|
+
import type { AgentExecutionRequest } from '@agentic-sdlc-kit/contracts';
|
|
22
|
+
import {
|
|
23
|
+
deriveClaudeCodePermissionConfig,
|
|
24
|
+
type ClaudeCodePermissionConfig,
|
|
25
|
+
} from './permission-config.js';
|
|
26
|
+
|
|
27
|
+
export interface ClaudeArgv {
|
|
28
|
+
/** The full argv for the claude CLI (argv[0] is the executable; this is argv.slice(1)). */
|
|
29
|
+
readonly args: readonly string[];
|
|
30
|
+
/** The derived permission config, exposed for tests and audit assertions. */
|
|
31
|
+
readonly permissionConfig: ClaudeCodePermissionConfig;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Build the headless invocation for one execution (pure). */
|
|
35
|
+
export function buildClaudeArgv(request: AgentExecutionRequest): ClaudeArgv {
|
|
36
|
+
const config = deriveClaudeCodePermissionConfig(request.permissions, request.budget);
|
|
37
|
+
|
|
38
|
+
const args: string[] = [
|
|
39
|
+
// Headless (print) mode: one bounded, non-interactive execution.
|
|
40
|
+
'-p',
|
|
41
|
+
request.instructions,
|
|
42
|
+
'--output-format',
|
|
43
|
+
'stream-json',
|
|
44
|
+
// stream-json in print mode requires verbose output.
|
|
45
|
+
'--verbose',
|
|
46
|
+
// The generated runtime policy representation (ADR-0020 §2).
|
|
47
|
+
'--permission-mode',
|
|
48
|
+
config.permissionMode,
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
if (config.allowedTools.length > 0) {
|
|
52
|
+
args.push('--allowedTools', config.allowedTools.join(','));
|
|
53
|
+
}
|
|
54
|
+
if (config.disallowedTools.length > 0) {
|
|
55
|
+
args.push('--disallowedTools', config.disallowedTools.join(','));
|
|
56
|
+
}
|
|
57
|
+
if (config.maxTurns !== undefined) {
|
|
58
|
+
// Defense in depth on the turn count; the GATEWAY enforces the real
|
|
59
|
+
// maxToolCalls from tool.requested events (gateway-enforced, honestly
|
|
60
|
+
// declared). Claude Code hitting --max-turns first is surfaced as a
|
|
61
|
+
// BUDGET_EXCEEDED failure, never silent continuation.
|
|
62
|
+
args.push('--max-turns', String(config.maxTurns));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
assertNeverBypassesPermissions(args);
|
|
66
|
+
return { args, permissionConfig: config };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Build the headless RESUME invocation (cross-process, PR4). */
|
|
70
|
+
export function buildClaudeResumeArgv(executionId: string, sessionId: string): ClaudeArgv {
|
|
71
|
+
// The gateway owns the original request and never re-submits it
|
|
72
|
+
// (revision A). The provider only knows how to continue the provider
|
|
73
|
+
// session: a bounded continuation prompt addressed by session id.
|
|
74
|
+
const args = [
|
|
75
|
+
'-p',
|
|
76
|
+
`Continue the interrupted agent execution ${executionId}. Complete the pending work; ` +
|
|
77
|
+
`do not start unrelated work. Finish and report what remains done.`,
|
|
78
|
+
'--output-format',
|
|
79
|
+
'stream-json',
|
|
80
|
+
'--verbose',
|
|
81
|
+
'--resume',
|
|
82
|
+
sessionId,
|
|
83
|
+
// A resumed session is as bounded as the original one: minimal tool
|
|
84
|
+
// surface, no subagents, no network unless the caller re-grants it via
|
|
85
|
+
// the gateway's resume path (which validates policy before calling).
|
|
86
|
+
'--disallowedTools',
|
|
87
|
+
'Task,WebFetch,WebSearch',
|
|
88
|
+
];
|
|
89
|
+
assertNeverBypassesPermissions(args);
|
|
90
|
+
return { args, permissionConfig: deriveMinimalResumeConfig() };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function deriveMinimalResumeConfig(): ClaudeCodePermissionConfig {
|
|
94
|
+
return {
|
|
95
|
+
allowedTools: [],
|
|
96
|
+
disallowedTools: ['Task', 'WebFetch', 'WebSearch'],
|
|
97
|
+
permissionMode: 'default',
|
|
98
|
+
maxTurns: undefined,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Fail closed at build time if any bypass flag ever slips in. This is an
|
|
104
|
+
* implementation assertion, not just a test: PR4 is security-critical and
|
|
105
|
+
* this invariant is cheap to guarantee at the source.
|
|
106
|
+
*/
|
|
107
|
+
function assertNeverBypassesPermissions(args: readonly string[]): void {
|
|
108
|
+
for (const arg of args) {
|
|
109
|
+
if (arg.includes('bypassPermissions') || arg.includes('--dangerously-skip-permissions')) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
'claude-code provider invariant violated: permission bypass flags are never ' +
|
|
112
|
+
'generated (ADR-0019 §6.5). Refusing to build the invocation.',
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Health-probe argv (no execution, no permissions surface). */
|
|
119
|
+
export const CLAUDE_VERSION_ARGS: readonly string[] = ['--version'];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/claude-code-smoke.test.ts
|
|
2
|
+
//
|
|
3
|
+
// REAL-provider smoke test (ADR-0019 PR4 acceptance criterion):
|
|
4
|
+
//
|
|
5
|
+
// "A real provider executes a bounded task without bypassing the
|
|
6
|
+
// approved policy."
|
|
7
|
+
//
|
|
8
|
+
// This test runs ONLY when a real `claude` CLI is available (dev machines,
|
|
9
|
+
// a future CI lane with credentials). When it is not, the suite SKIPS
|
|
10
|
+
// VISIBLY — vitest reports the skipped test — because a green-looking
|
|
11
|
+
// placeholder would violate the kit's no-silent-fabrication principle.
|
|
12
|
+
//
|
|
13
|
+
// The task is deliberately tiny and bounded: create one marker file inside
|
|
14
|
+
// the granted workspace. The assertions prove the policy held:
|
|
15
|
+
// - the execution completed within the granted budget;
|
|
16
|
+
// - the marker exists INSIDE the workspace (the only writablePath);
|
|
17
|
+
// - the derived argv carried the scoped allowlist and NO bypass flags.
|
|
18
|
+
|
|
19
|
+
import { spawn } from 'node:child_process';
|
|
20
|
+
import { promises as fs } from 'node:fs';
|
|
21
|
+
import os from 'node:os';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
24
|
+
import {
|
|
25
|
+
AGENT_POLICY_SNAPSHOT_SCHEMA_VERSION,
|
|
26
|
+
computePolicyHash,
|
|
27
|
+
type AgentExecutionRequest,
|
|
28
|
+
type AgentPolicySnapshot,
|
|
29
|
+
} from '@agentic-sdlc-kit/contracts';
|
|
30
|
+
import { buildClaudeArgv } from './claude-argv.js';
|
|
31
|
+
import { ClaudeCodeProvider } from './provider.js';
|
|
32
|
+
|
|
33
|
+
const CLAUDE_BIN = 'claude';
|
|
34
|
+
const HEALTH_TIMEOUT_MS = 5_000;
|
|
35
|
+
|
|
36
|
+
let available = false;
|
|
37
|
+
let projectRoot: string | undefined;
|
|
38
|
+
let workspaceRoot: string | undefined;
|
|
39
|
+
|
|
40
|
+
function probeClaude(): Promise<boolean> {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
const child = spawn(CLAUDE_BIN, ['--version'], { stdio: 'ignore', shell: false });
|
|
43
|
+
const timer = setTimeout(() => {
|
|
44
|
+
child.kill('SIGKILL');
|
|
45
|
+
resolve(false);
|
|
46
|
+
}, HEALTH_TIMEOUT_MS);
|
|
47
|
+
child.on('error', () => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
resolve(false);
|
|
50
|
+
});
|
|
51
|
+
child.on('exit', (code) => {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
resolve(code === 0);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
beforeAll(async () => {
|
|
59
|
+
available = await probeClaude();
|
|
60
|
+
if (available) {
|
|
61
|
+
projectRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-pr4-smoke-'));
|
|
62
|
+
workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-pr4-smoke-ws-'));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterAll(async () => {
|
|
67
|
+
if (projectRoot) await fs.rm(projectRoot, { recursive: true, force: true });
|
|
68
|
+
if (workspaceRoot) await fs.rm(workspaceRoot, { recursive: true, force: true });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe.skipIf(!available)('claude-code real-provider smoke (acceptance: PR4)', () => {
|
|
72
|
+
it('executes a bounded task inside the granted workspace without bypassing policy', async () => {
|
|
73
|
+
if (!workspaceRoot) return;
|
|
74
|
+
const req: AgentExecutionRequest = {
|
|
75
|
+
schemaVersion: 2,
|
|
76
|
+
executionId: 'exec-RUN-042-TASK-001-red-1',
|
|
77
|
+
workflowRunId: 'RUN-042',
|
|
78
|
+
taskId: 'TASK-001',
|
|
79
|
+
providerId: 'claude-code',
|
|
80
|
+
taskKind: 'implementation',
|
|
81
|
+
policyHash: '', // computed below from the frozen snapshot
|
|
82
|
+
workspace: {
|
|
83
|
+
id: 'ws-smoke-001',
|
|
84
|
+
kind: 'directory',
|
|
85
|
+
rootPath: workspaceRoot,
|
|
86
|
+
createdAt: new Date().toISOString(),
|
|
87
|
+
},
|
|
88
|
+
instructions:
|
|
89
|
+
`Create the file smoke-marker.txt in the current working directory with exactly ` +
|
|
90
|
+
`the content kit-pr4-smoke (no trailing newline beyond the content) and do nothing else. ` +
|
|
91
|
+
`Do not create any other files.`,
|
|
92
|
+
context: { relevantFiles: [], constraints: ['create only smoke-marker.txt'] },
|
|
93
|
+
permissions: {
|
|
94
|
+
capabilities: ['repository.read', 'repository.write'],
|
|
95
|
+
writablePaths: [workspaceRoot],
|
|
96
|
+
networkAllowed: false,
|
|
97
|
+
},
|
|
98
|
+
budget: { maxDurationMs: 120_000, maxToolCalls: 40 },
|
|
99
|
+
approvalPolicy: { requireApprovalFor: ['external.approval'], allowAutonomousExecution: true },
|
|
100
|
+
};
|
|
101
|
+
const policySnapshot: AgentPolicySnapshot = {
|
|
102
|
+
schemaVersion: AGENT_POLICY_SNAPSHOT_SCHEMA_VERSION,
|
|
103
|
+
permissions: req.permissions,
|
|
104
|
+
budget: req.budget,
|
|
105
|
+
approvalPolicy: req.approvalPolicy,
|
|
106
|
+
};
|
|
107
|
+
req.policyHash = computePolicyHash(policySnapshot);
|
|
108
|
+
|
|
109
|
+
// The derived invocation never bypasses the approved policy.
|
|
110
|
+
const { args } = buildClaudeArgv(req);
|
|
111
|
+
const flat = args.join(' ');
|
|
112
|
+
expect(flat).not.toContain('bypassPermissions');
|
|
113
|
+
expect(flat).not.toContain('--dangerously-skip-permissions');
|
|
114
|
+
expect(flat).toContain(`Write(${workspaceRoot}/**)`);
|
|
115
|
+
|
|
116
|
+
const provider = new ClaudeCodeProvider({ projectRoot: projectRoot!, cliPath: CLAUDE_BIN });
|
|
117
|
+
const handle = await provider.start(req, new AbortController().signal);
|
|
118
|
+
const result = await handle.result();
|
|
119
|
+
|
|
120
|
+
expect(result.status).toBe('completed');
|
|
121
|
+
expect(result.usage?.durationMs).toBeLessThanOrEqual(req.budget.maxDurationMs + 5_000);
|
|
122
|
+
|
|
123
|
+
// The evidence: the file exists, inside the ONLY writablePath.
|
|
124
|
+
const marker = path.join(workspaceRoot, 'smoke-marker.txt');
|
|
125
|
+
const content = await fs.readFile(marker, 'utf8');
|
|
126
|
+
expect(content.trim()).toBe('kit-pr4-smoke');
|
|
127
|
+
|
|
128
|
+
// No stray files leaked outside the granted path list.
|
|
129
|
+
const entries = await fs.readdir(workspaceRoot);
|
|
130
|
+
const stray = entries.filter((e) => e !== 'smoke-marker.txt' && e !== '.claude');
|
|
131
|
+
expect(stray).toEqual([]);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe.skipIf(available)('claude-code real-provider smoke (acceptance: PR4)', () => {
|
|
136
|
+
it.skip('SKIPPED: no real claude CLI on this machine — visible skip, not a green fabrication', () => {
|
|
137
|
+
// Intentionally unreachable: the test is reported as skipped by vitest.
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs
|
|
2
|
+
//
|
|
3
|
+
// Fake Claude Code CLI for provider tests — drives the REAL provider code
|
|
4
|
+
// path (spawn, stream parsing, event emission, settlement) without needing
|
|
5
|
+
// the real binary or network. Behavior is selected with FAKE_CLAUDE_MODE:
|
|
6
|
+
//
|
|
7
|
+
// happy — full success stream (text + Write tool_use + tool_result + result)
|
|
8
|
+
// maxturns — result subtype error_max_turns
|
|
9
|
+
// error — result is_error with an API error text
|
|
10
|
+
// denied — result is_error with a permission-denial text
|
|
11
|
+
// sleep — hangs until killed (cancel/timeout paths)
|
|
12
|
+
// crash — exits 137 with a partial stream (no result object)
|
|
13
|
+
// signal — kills itself with SIGKILL mid-stream
|
|
14
|
+
// noresult — exits 0 without a result object
|
|
15
|
+
// resume — happy stream (the test asserts the --resume argv)
|
|
16
|
+
// flood — emits far more than the output bound (used with a tiny cap)
|
|
17
|
+
//
|
|
18
|
+
// The fixture writes its received argv (and cwd) to FAKE_CLAUDE_ARGV_FILE
|
|
19
|
+
// so tests can assert the derived headless invocation without trusting
|
|
20
|
+
// stdout formats.
|
|
21
|
+
|
|
22
|
+
import { writeFileSync } from 'node:fs';
|
|
23
|
+
|
|
24
|
+
const argv = process.argv.slice(2);
|
|
25
|
+
const mode = process.env.FAKE_CLAUDE_MODE ?? 'happy';
|
|
26
|
+
|
|
27
|
+
if (argv.includes('--version')) {
|
|
28
|
+
process.stdout.write('2.1.7 (Claude Code)\n');
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (process.env.FAKE_CLAUDE_ARGV_FILE) {
|
|
33
|
+
writeFileSync(
|
|
34
|
+
process.env.FAKE_CLAUDE_ARGV_FILE,
|
|
35
|
+
JSON.stringify({ argv, cwd: process.cwd(), mode }),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const sid = process.env.FAKE_CLAUDE_SESSION_ID ?? 'sess-fake-001';
|
|
40
|
+
const emit = (obj) => process.stdout.write(JSON.stringify(obj) + '\n');
|
|
41
|
+
|
|
42
|
+
if (mode === 'sleep') {
|
|
43
|
+
emit({ type: 'system', subtype: 'init', session_id: sid, cwd: process.cwd() });
|
|
44
|
+
// Hang until the provider kills us; flush the init line first.
|
|
45
|
+
const timer = setInterval(() => {}, 60_000);
|
|
46
|
+
process.on('SIGTERM', () => {
|
|
47
|
+
clearInterval(timer);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
});
|
|
50
|
+
} else if (mode === 'crash') {
|
|
51
|
+
emit({ type: 'system', subtype: 'init', session_id: sid });
|
|
52
|
+
process.exit(137);
|
|
53
|
+
} else if (mode === 'signal') {
|
|
54
|
+
emit({ type: 'system', subtype: 'init', session_id: sid });
|
|
55
|
+
process.kill(process.pid, 'SIGKILL');
|
|
56
|
+
} else if (mode === 'noresult') {
|
|
57
|
+
emit({ type: 'system', subtype: 'init', session_id: sid });
|
|
58
|
+
process.exit(0);
|
|
59
|
+
} else if (mode === 'flood') {
|
|
60
|
+
const filler = 'x'.repeat(1024);
|
|
61
|
+
for (let i = 0; i < 512; i += 1) {
|
|
62
|
+
emit({ type: 'assistant', message: { content: [{ type: 'text', text: filler }] } });
|
|
63
|
+
}
|
|
64
|
+
process.exit(0);
|
|
65
|
+
} else {
|
|
66
|
+
emit({ type: 'system', subtype: 'init', session_id: sid, cwd: process.cwd(), tools: [] });
|
|
67
|
+
emit({ type: 'assistant', message: { content: [{ type: 'text', text: 'Working on it.' }] } });
|
|
68
|
+
emit({
|
|
69
|
+
type: 'assistant',
|
|
70
|
+
message: {
|
|
71
|
+
content: [{ type: 'tool_use', id: 'toolu_1', name: 'Write', input: { file_path: 'marker.txt', content: 'x' } }],
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
emit({
|
|
75
|
+
type: 'user',
|
|
76
|
+
message: { content: [{ type: 'tool_result', tool_use_id: 'toolu_1', content: 'ok', is_error: false }] },
|
|
77
|
+
});
|
|
78
|
+
const result =
|
|
79
|
+
mode === 'maxturns'
|
|
80
|
+
? {
|
|
81
|
+
type: 'result',
|
|
82
|
+
subtype: 'error_max_turns',
|
|
83
|
+
is_error: true,
|
|
84
|
+
duration_ms: 5,
|
|
85
|
+
num_turns: 99,
|
|
86
|
+
result: 'Max turns reached',
|
|
87
|
+
session_id: sid,
|
|
88
|
+
usage: { input_tokens: 3, output_tokens: 4 },
|
|
89
|
+
}
|
|
90
|
+
: mode === 'error'
|
|
91
|
+
? {
|
|
92
|
+
type: 'result',
|
|
93
|
+
subtype: 'error_during_execution',
|
|
94
|
+
is_error: true,
|
|
95
|
+
duration_ms: 7,
|
|
96
|
+
num_turns: 1,
|
|
97
|
+
result: 'API Error: 500',
|
|
98
|
+
session_id: sid,
|
|
99
|
+
usage: { input_tokens: 1, output_tokens: 1 },
|
|
100
|
+
}
|
|
101
|
+
: mode === 'denied'
|
|
102
|
+
? {
|
|
103
|
+
type: 'result',
|
|
104
|
+
subtype: 'error_during_execution',
|
|
105
|
+
is_error: true,
|
|
106
|
+
duration_ms: 9,
|
|
107
|
+
num_turns: 1,
|
|
108
|
+
result: 'permission denied: Bash is not allowed',
|
|
109
|
+
session_id: sid,
|
|
110
|
+
usage: { input_tokens: 2, output_tokens: 2 },
|
|
111
|
+
}
|
|
112
|
+
: {
|
|
113
|
+
type: 'result',
|
|
114
|
+
subtype: 'success',
|
|
115
|
+
is_error: false,
|
|
116
|
+
duration_ms: 12,
|
|
117
|
+
num_turns: 2,
|
|
118
|
+
result: 'Done: created the marker file.',
|
|
119
|
+
session_id: sid,
|
|
120
|
+
total_cost_usd: 0.003,
|
|
121
|
+
usage: { input_tokens: 10, output_tokens: 20, cache_read_input_tokens: 0, cache_creation_input_tokens: 0 },
|
|
122
|
+
};
|
|
123
|
+
emit(result);
|
|
124
|
+
process.exit(0);
|
|
125
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/index.ts
|
|
2
|
+
//
|
|
3
|
+
// Barrel for the secure Claude Code provider (ADR-0019 PR4). The provider
|
|
4
|
+
// adapter boundary (Kit -> agent) is intentionally SEPARATE from the
|
|
5
|
+
// claude-code-adapter package, which remains the HOST adapter boundary
|
|
6
|
+
// (agent -> Kit); see ADR-0019 §2 and packages/claude-code-adapter/src/index.ts.
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
deriveClaudeCodePermissionConfig,
|
|
10
|
+
inferCapabilityFromBashCommand,
|
|
11
|
+
inferCapabilityFromToolUse,
|
|
12
|
+
bashRulesForCapability,
|
|
13
|
+
BASH_RULE_CAPABILITIES,
|
|
14
|
+
CLAUDE_CODE_SUPPORTED_CAPABILITIES,
|
|
15
|
+
type ClaudeCodePermissionConfig,
|
|
16
|
+
type ClaudeCodePermissionMode,
|
|
17
|
+
} from './permission-config.js';
|
|
18
|
+
export { buildClaudeArgv, buildClaudeResumeArgv, CLAUDE_VERSION_ARGS, type ClaudeArgv } from './claude-argv.js';
|
|
19
|
+
export { ClaudeStreamParser, capabilityOfToolUse, type ClaudeFinalResult, type StreamObservation } from './stream-parser.js';
|
|
20
|
+
export {
|
|
21
|
+
generateResumeToken,
|
|
22
|
+
loadSessionRecord,
|
|
23
|
+
saveSessionRecord,
|
|
24
|
+
verifyResumeToken,
|
|
25
|
+
type StoredSessionRecord,
|
|
26
|
+
} from './resume-store.js';
|
|
27
|
+
export { ensureRuntimeModsActive, type ModsParityResult } from './mod-parity.js';
|
|
28
|
+
export { ClaudeCodeProvider, type ClaudeCodeProviderOptions } from './provider.js';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/mod-parity.ts
|
|
2
|
+
//
|
|
3
|
+
// Runtime Mods enforcement parity (ADR-0019 PR4; ADR-0020 §2).
|
|
4
|
+
//
|
|
5
|
+
// Two enforcement points derive from ONE canonical policy:
|
|
6
|
+
// 1. Claude Code's own permission system — the GENERATED representation
|
|
7
|
+
// (permission-config.ts) passed as session flags; enforced by Claude
|
|
8
|
+
// Code regardless of anything the kit does.
|
|
9
|
+
// 2. The kit's runtime Mods (sdlc-guard, secret-guard, model-router,
|
|
10
|
+
// run-observer) — Claude Code hook plugins the kit ships and links
|
|
11
|
+
// into the PROJECT's .claude/plugins/ (plugin-linker.ts).
|
|
12
|
+
//
|
|
13
|
+
// For a Mode 1 execution the agent runs inside the run's WORKTREE, so the
|
|
14
|
+
// Mods must be active there too — "parity". This module links them into
|
|
15
|
+
// the worktree (idempotent) and reports the result HONESTLY:
|
|
16
|
+
// - linked/already-linked → the second enforcement point is active;
|
|
17
|
+
// - not-found/incomplete → recorded as a note; the execution continues
|
|
18
|
+
// under enforcement point 1 (which is policy-derived and always
|
|
19
|
+
// present), and the summary states the Mods were NOT active.
|
|
20
|
+
//
|
|
21
|
+
// The linked .claude/plugins/ entries are runtime machinery, never project
|
|
22
|
+
// content: the repository's .gitignore excludes .claude/ so the run's
|
|
23
|
+
// evidence diff (the agent's actual footprint) stays clean.
|
|
24
|
+
|
|
25
|
+
import { linkRuntimePlugins, type PluginLinkResult } from '../../../../commands/plugin-linker.js';
|
|
26
|
+
|
|
27
|
+
export interface ModsParityResult {
|
|
28
|
+
/** True when every runtime mod is linked into the workspace. */
|
|
29
|
+
readonly active: boolean;
|
|
30
|
+
readonly results: readonly PluginLinkResult[];
|
|
31
|
+
/** Honest human-readable note for the execution record. */
|
|
32
|
+
readonly note: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Ensure the kit's runtime Mods are linked into the execution workspace.
|
|
37
|
+
* Best-effort with honest reporting — see the module header for the
|
|
38
|
+
* fail-open reasoning and its limits.
|
|
39
|
+
*/
|
|
40
|
+
export async function ensureRuntimeModsActive(workspaceRoot: string): Promise<ModsParityResult> {
|
|
41
|
+
const results = await linkRuntimePlugins(workspaceRoot);
|
|
42
|
+
const bad = results.filter((r) => r.status !== 'linked' && r.status !== 'already-linked');
|
|
43
|
+
const active = bad.length === 0;
|
|
44
|
+
const note = active
|
|
45
|
+
? `runtime Mods active in workspace (${results.map((r) => r.name).join(', ')})`
|
|
46
|
+
: `runtime Mods NOT fully active: ${bad.map((r) => `${r.name} (${r.status})`).join('; ')} — ` +
|
|
47
|
+
`the policy-derived Claude Code permission configuration remains enforced; ` +
|
|
48
|
+
`kit-level Mod guards are absent for this execution`;
|
|
49
|
+
return { active, results, note };
|
|
50
|
+
}
|