@agentic-sdlc-kit/cli 0.0.0-stage → 0.8.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 (240) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -2
  3. package/dist/application/agent/execution-store.d.ts +55 -0
  4. package/dist/application/agent/execution-store.d.ts.map +1 -0
  5. package/dist/application/agent/execution-store.js +90 -0
  6. package/dist/application/agent/execution-store.js.map +1 -0
  7. package/dist/application/agent/gateway.d.ts +74 -0
  8. package/dist/application/agent/gateway.d.ts.map +1 -0
  9. package/dist/application/agent/gateway.js +580 -0
  10. package/dist/application/agent/gateway.js.map +1 -0
  11. package/dist/application/agent/index.d.ts +6 -0
  12. package/dist/application/agent/index.d.ts.map +1 -0
  13. package/dist/application/agent/index.js +18 -0
  14. package/dist/application/agent/index.js.map +1 -0
  15. package/dist/application/agent/orchestrator.d.ts +76 -0
  16. package/dist/application/agent/orchestrator.d.ts.map +1 -0
  17. package/dist/application/agent/orchestrator.js +422 -0
  18. package/dist/application/agent/orchestrator.js.map +1 -0
  19. package/dist/application/agent/providers/claude-code/claude-argv.d.ts +15 -0
  20. package/dist/application/agent/providers/claude-code/claude-argv.d.ts.map +1 -0
  21. package/dist/application/agent/providers/claude-code/claude-argv.js +98 -0
  22. package/dist/application/agent/providers/claude-code/claude-argv.js.map +1 -0
  23. package/dist/application/agent/providers/claude-code/index.d.ts +7 -0
  24. package/dist/application/agent/providers/claude-code/index.d.ts.map +1 -0
  25. package/dist/application/agent/providers/claude-code/index.js +13 -0
  26. package/dist/application/agent/providers/claude-code/index.js.map +1 -0
  27. package/dist/application/agent/providers/claude-code/mod-parity.d.ts +15 -0
  28. package/dist/application/agent/providers/claude-code/mod-parity.d.ts.map +1 -0
  29. package/dist/application/agent/providers/claude-code/mod-parity.js +41 -0
  30. package/dist/application/agent/providers/claude-code/mod-parity.js.map +1 -0
  31. package/dist/application/agent/providers/claude-code/permission-config.d.ts +59 -0
  32. package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -0
  33. package/dist/application/agent/providers/claude-code/permission-config.js +189 -0
  34. package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -0
  35. package/dist/application/agent/providers/claude-code/provider.d.ts +38 -0
  36. package/dist/application/agent/providers/claude-code/provider.d.ts.map +1 -0
  37. package/dist/application/agent/providers/claude-code/provider.js +577 -0
  38. package/dist/application/agent/providers/claude-code/provider.js.map +1 -0
  39. package/dist/application/agent/providers/claude-code/resume-store.d.ts +25 -0
  40. package/dist/application/agent/providers/claude-code/resume-store.d.ts.map +1 -0
  41. package/dist/application/agent/providers/claude-code/resume-store.js +120 -0
  42. package/dist/application/agent/providers/claude-code/resume-store.js.map +1 -0
  43. package/dist/application/agent/providers/claude-code/stream-parser.d.ts +50 -0
  44. package/dist/application/agent/providers/claude-code/stream-parser.d.ts.map +1 -0
  45. package/dist/application/agent/providers/claude-code/stream-parser.js +129 -0
  46. package/dist/application/agent/providers/claude-code/stream-parser.js.map +1 -0
  47. package/dist/application/agent/test-fixture.d.ts +15 -0
  48. package/dist/application/agent/test-fixture.d.ts.map +1 -0
  49. package/dist/application/agent/test-fixture.js +93 -0
  50. package/dist/application/agent/test-fixture.js.map +1 -0
  51. package/dist/application/agent/workspace.d.ts +24 -0
  52. package/dist/application/agent/workspace.d.ts.map +1 -0
  53. package/dist/application/agent/workspace.js +139 -0
  54. package/dist/application/agent/workspace.js.map +1 -0
  55. package/dist/application/dispatcher.d.ts +13 -0
  56. package/dist/application/dispatcher.d.ts.map +1 -0
  57. package/dist/application/dispatcher.js +104 -0
  58. package/dist/application/dispatcher.js.map +1 -0
  59. package/dist/application/index.d.ts +5 -0
  60. package/dist/application/index.d.ts.map +1 -0
  61. package/dist/application/index.js +6 -0
  62. package/dist/application/index.js.map +1 -0
  63. package/dist/application/registry.d.ts +8 -0
  64. package/dist/application/registry.d.ts.map +1 -0
  65. package/dist/application/registry.js +17 -0
  66. package/dist/application/registry.js.map +1 -0
  67. package/dist/application/version.d.ts +2 -0
  68. package/dist/application/version.d.ts.map +1 -0
  69. package/dist/application/version.js +7 -0
  70. package/dist/application/version.js.map +1 -0
  71. package/dist/commands/doctor.d.ts +3 -0
  72. package/dist/commands/doctor.d.ts.map +1 -0
  73. package/dist/commands/doctor.js +68 -0
  74. package/dist/commands/doctor.js.map +1 -0
  75. package/dist/commands/elicit.d.ts +3 -0
  76. package/dist/commands/elicit.d.ts.map +1 -0
  77. package/dist/commands/elicit.js +163 -0
  78. package/dist/commands/elicit.js.map +1 -0
  79. package/dist/commands/evolve.d.ts +3 -0
  80. package/dist/commands/evolve.d.ts.map +1 -0
  81. package/dist/commands/evolve.js +165 -0
  82. package/dist/commands/evolve.js.map +1 -0
  83. package/dist/commands/feature.d.ts +13 -0
  84. package/dist/commands/feature.d.ts.map +1 -0
  85. package/dist/commands/feature.js +326 -0
  86. package/dist/commands/feature.js.map +1 -0
  87. package/dist/commands/fix.d.ts +3 -0
  88. package/dist/commands/fix.d.ts.map +1 -0
  89. package/dist/commands/fix.js +61 -0
  90. package/dist/commands/fix.js.map +1 -0
  91. package/dist/commands/help.d.ts +4 -0
  92. package/dist/commands/help.d.ts.map +1 -0
  93. package/dist/commands/help.js +32 -0
  94. package/dist/commands/help.js.map +1 -0
  95. package/dist/commands/index.d.ts +21 -0
  96. package/dist/commands/index.d.ts.map +1 -0
  97. package/dist/commands/index.js +22 -0
  98. package/dist/commands/index.js.map +1 -0
  99. package/dist/commands/init.d.ts +3 -0
  100. package/dist/commands/init.d.ts.map +1 -0
  101. package/dist/commands/init.js +90 -0
  102. package/dist/commands/init.js.map +1 -0
  103. package/dist/commands/inspect.d.ts +3 -0
  104. package/dist/commands/inspect.d.ts.map +1 -0
  105. package/dist/commands/inspect.js +64 -0
  106. package/dist/commands/inspect.js.map +1 -0
  107. package/dist/commands/install.d.ts +3 -0
  108. package/dist/commands/install.d.ts.map +1 -0
  109. package/dist/commands/install.js +329 -0
  110. package/dist/commands/install.js.map +1 -0
  111. package/dist/commands/journal.d.ts +3 -0
  112. package/dist/commands/journal.d.ts.map +1 -0
  113. package/dist/commands/journal.js +107 -0
  114. package/dist/commands/journal.js.map +1 -0
  115. package/dist/commands/memory.d.ts +3 -0
  116. package/dist/commands/memory.d.ts.map +1 -0
  117. package/dist/commands/memory.js +85 -0
  118. package/dist/commands/memory.js.map +1 -0
  119. package/dist/commands/new.d.ts +3 -0
  120. package/dist/commands/new.d.ts.map +1 -0
  121. package/dist/commands/new.js +68 -0
  122. package/dist/commands/new.js.map +1 -0
  123. package/dist/commands/next.d.ts +3 -0
  124. package/dist/commands/next.d.ts.map +1 -0
  125. package/dist/commands/next.js +107 -0
  126. package/dist/commands/next.js.map +1 -0
  127. package/dist/commands/optimize.d.ts +3 -0
  128. package/dist/commands/optimize.d.ts.map +1 -0
  129. package/dist/commands/optimize.js +28 -0
  130. package/dist/commands/optimize.js.map +1 -0
  131. package/dist/commands/plugin-linker.d.ts +34 -0
  132. package/dist/commands/plugin-linker.d.ts.map +1 -0
  133. package/dist/commands/plugin-linker.js +177 -0
  134. package/dist/commands/plugin-linker.js.map +1 -0
  135. package/dist/commands/refactor.d.ts +3 -0
  136. package/dist/commands/refactor.d.ts.map +1 -0
  137. package/dist/commands/refactor.js +32 -0
  138. package/dist/commands/refactor.js.map +1 -0
  139. package/dist/commands/types.d.ts +19 -0
  140. package/dist/commands/types.d.ts.map +1 -0
  141. package/dist/commands/types.js +7 -0
  142. package/dist/commands/types.js.map +1 -0
  143. package/dist/commands/validate-plan.d.ts +3 -0
  144. package/dist/commands/validate-plan.d.ts.map +1 -0
  145. package/dist/commands/validate-plan.js +62 -0
  146. package/dist/commands/validate-plan.js.map +1 -0
  147. package/dist/commands/validate-spec.d.ts +3 -0
  148. package/dist/commands/validate-spec.d.ts.map +1 -0
  149. package/dist/commands/validate-spec.js +62 -0
  150. package/dist/commands/validate-spec.js.map +1 -0
  151. package/dist/commands/verify.d.ts +3 -0
  152. package/dist/commands/verify.d.ts.map +1 -0
  153. package/dist/commands/verify.js +103 -0
  154. package/dist/commands/verify.js.map +1 -0
  155. package/dist/commands/version.d.ts +3 -0
  156. package/dist/commands/version.d.ts.map +1 -0
  157. package/dist/commands/version.js +12 -0
  158. package/dist/commands/version.js.map +1 -0
  159. package/dist/index.d.ts +3 -0
  160. package/dist/index.d.ts.map +1 -0
  161. package/dist/index.js +27 -0
  162. package/dist/index.js.map +1 -0
  163. package/dist/output/formatter.d.ts +2 -0
  164. package/dist/output/formatter.d.ts.map +1 -0
  165. package/dist/output/formatter.js +10 -0
  166. package/dist/output/formatter.js.map +1 -0
  167. package/dist/output/index.d.ts +2 -0
  168. package/dist/output/index.d.ts.map +1 -0
  169. package/dist/output/index.js +3 -0
  170. package/dist/output/index.js.map +1 -0
  171. package/package.json +37 -3
  172. package/src/application/agent/execution-store.ts +162 -0
  173. package/src/application/agent/gateway.test.ts +529 -0
  174. package/src/application/agent/gateway.ts +744 -0
  175. package/src/application/agent/index.ts +18 -0
  176. package/src/application/agent/orchestrator.test.ts +341 -0
  177. package/src/application/agent/orchestrator.ts +628 -0
  178. package/src/application/agent/providers/claude-code/claude-argv.ts +119 -0
  179. package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +139 -0
  180. package/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs +125 -0
  181. package/src/application/agent/providers/claude-code/index.ts +28 -0
  182. package/src/application/agent/providers/claude-code/mod-parity.ts +50 -0
  183. package/src/application/agent/providers/claude-code/permission-config.test.ts +221 -0
  184. package/src/application/agent/providers/claude-code/permission-config.ts +242 -0
  185. package/src/application/agent/providers/claude-code/provider.test.ts +378 -0
  186. package/src/application/agent/providers/claude-code/provider.ts +717 -0
  187. package/src/application/agent/providers/claude-code/resume-store.test.ts +161 -0
  188. package/src/application/agent/providers/claude-code/resume-store.ts +157 -0
  189. package/src/application/agent/providers/claude-code/stream-parser.ts +166 -0
  190. package/src/application/agent/test-fixture.ts +131 -0
  191. package/src/application/agent/workspace.test.ts +104 -0
  192. package/src/application/agent/workspace.ts +156 -0
  193. package/src/application/dispatcher.test.ts +89 -0
  194. package/src/application/dispatcher.ts +98 -0
  195. package/src/application/index.ts +5 -0
  196. package/src/application/registry.ts +24 -0
  197. package/src/application/version.ts +7 -0
  198. package/src/commands/clse.test.ts +181 -0
  199. package/src/commands/doctor.test.ts +29 -0
  200. package/src/commands/doctor.ts +78 -0
  201. package/src/commands/elicit.test.ts +111 -0
  202. package/src/commands/elicit.ts +188 -0
  203. package/src/commands/evolve.ts +209 -0
  204. package/src/commands/feature.test.ts +323 -0
  205. package/src/commands/feature.ts +405 -0
  206. package/src/commands/fix.test.ts +36 -0
  207. package/src/commands/fix.ts +69 -0
  208. package/src/commands/help.test.ts +33 -0
  209. package/src/commands/help.ts +35 -0
  210. package/src/commands/index.ts +21 -0
  211. package/src/commands/init.test.ts +65 -0
  212. package/src/commands/init.ts +103 -0
  213. package/src/commands/inspect.test.ts +57 -0
  214. package/src/commands/inspect.ts +73 -0
  215. package/src/commands/install.test.ts +61 -0
  216. package/src/commands/install.ts +375 -0
  217. package/src/commands/journal.ts +118 -0
  218. package/src/commands/memory.ts +96 -0
  219. package/src/commands/new.test.ts +44 -0
  220. package/src/commands/new.ts +77 -0
  221. package/src/commands/next.test.ts +241 -0
  222. package/src/commands/next.ts +124 -0
  223. package/src/commands/optimize.ts +30 -0
  224. package/src/commands/plugin-linker.test.ts +139 -0
  225. package/src/commands/plugin-linker.ts +196 -0
  226. package/src/commands/refactor.ts +34 -0
  227. package/src/commands/stack-commands.test.ts +67 -0
  228. package/src/commands/tier-c-conformance.test.ts +194 -0
  229. package/src/commands/types.ts +26 -0
  230. package/src/commands/validate-plan.test.ts +107 -0
  231. package/src/commands/validate-plan.ts +67 -0
  232. package/src/commands/validate-spec.test.ts +59 -0
  233. package/src/commands/validate-spec.ts +68 -0
  234. package/src/commands/verify.test.ts +117 -0
  235. package/src/commands/verify.ts +112 -0
  236. package/src/commands/version.test.ts +11 -0
  237. package/src/commands/version.ts +14 -0
  238. package/src/index.ts +30 -0
  239. package/src/output/formatter.ts +10 -0
  240. 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
+ }