@agentic-sdlc-kit/cli 0.8.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/dist/application/agent/execution-store.d.ts.map +1 -1
  2. package/dist/application/agent/execution-store.js +2 -1
  3. package/dist/application/agent/execution-store.js.map +1 -1
  4. package/dist/application/agent/orchestrator.d.ts.map +1 -1
  5. package/dist/application/agent/orchestrator.js +5 -4
  6. package/dist/application/agent/orchestrator.js.map +1 -1
  7. package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -1
  8. package/dist/application/agent/providers/claude-code/permission-config.js +8 -2
  9. package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -1
  10. package/dist/application/agent-tools/dispatch.d.ts +12 -0
  11. package/dist/application/agent-tools/dispatch.d.ts.map +1 -0
  12. package/dist/application/agent-tools/dispatch.js +189 -0
  13. package/dist/application/agent-tools/dispatch.js.map +1 -0
  14. package/dist/application/agent-tools/mcp-server.d.ts +10 -0
  15. package/dist/application/agent-tools/mcp-server.d.ts.map +1 -0
  16. package/dist/application/agent-tools/mcp-server.js +100 -0
  17. package/dist/application/agent-tools/mcp-server.js.map +1 -0
  18. package/dist/application/bench/harness.d.ts +5 -0
  19. package/dist/application/bench/harness.d.ts.map +1 -0
  20. package/dist/application/bench/harness.js +82 -0
  21. package/dist/application/bench/harness.js.map +1 -0
  22. package/dist/application/dispatcher.d.ts.map +1 -1
  23. package/dist/application/dispatcher.js +36 -0
  24. package/dist/application/dispatcher.js.map +1 -1
  25. package/dist/application/rule-adapters/ast-grep.d.ts +3 -0
  26. package/dist/application/rule-adapters/ast-grep.d.ts.map +1 -0
  27. package/dist/application/rule-adapters/ast-grep.js +112 -0
  28. package/dist/application/rule-adapters/ast-grep.js.map +1 -0
  29. package/dist/application/rule-adapters/index.d.ts +3 -0
  30. package/dist/application/rule-adapters/index.d.ts.map +1 -0
  31. package/dist/application/rule-adapters/index.js +15 -0
  32. package/dist/application/rule-adapters/index.js.map +1 -0
  33. package/dist/application/rule-adapters/linter.d.ts +31 -0
  34. package/dist/application/rule-adapters/linter.d.ts.map +1 -0
  35. package/dist/application/rule-adapters/linter.js +242 -0
  36. package/dist/application/rule-adapters/linter.js.map +1 -0
  37. package/dist/application/rule-adapters/process.d.ts +10 -0
  38. package/dist/application/rule-adapters/process.d.ts.map +1 -0
  39. package/dist/application/rule-adapters/process.js +38 -0
  40. package/dist/application/rule-adapters/process.js.map +1 -0
  41. package/dist/application/version.d.ts +1 -1
  42. package/dist/application/version.d.ts.map +1 -1
  43. package/dist/application/version.js +7 -4
  44. package/dist/application/version.js.map +1 -1
  45. package/dist/commands/attach-exclude.d.ts +8 -0
  46. package/dist/commands/attach-exclude.d.ts.map +1 -0
  47. package/dist/commands/attach-exclude.js +48 -0
  48. package/dist/commands/attach-exclude.js.map +1 -0
  49. package/dist/commands/attach-git.d.ts +11 -0
  50. package/dist/commands/attach-git.d.ts.map +1 -0
  51. package/dist/commands/attach-git.js +40 -0
  52. package/dist/commands/attach-git.js.map +1 -0
  53. package/dist/commands/attach-store.d.ts +10 -0
  54. package/dist/commands/attach-store.d.ts.map +1 -0
  55. package/dist/commands/attach-store.js +107 -0
  56. package/dist/commands/attach-store.js.map +1 -0
  57. package/dist/commands/attach.d.ts +8 -0
  58. package/dist/commands/attach.d.ts.map +1 -0
  59. package/dist/commands/attach.js +124 -0
  60. package/dist/commands/attach.js.map +1 -0
  61. package/dist/commands/bench.d.ts +3 -0
  62. package/dist/commands/bench.d.ts.map +1 -0
  63. package/dist/commands/bench.js +75 -0
  64. package/dist/commands/bench.js.map +1 -0
  65. package/dist/commands/context.d.ts +3 -0
  66. package/dist/commands/context.d.ts.map +1 -0
  67. package/dist/commands/context.js +56 -0
  68. package/dist/commands/context.js.map +1 -0
  69. package/dist/commands/doctor.d.ts.map +1 -1
  70. package/dist/commands/doctor.js +38 -0
  71. package/dist/commands/doctor.js.map +1 -1
  72. package/dist/commands/feature.d.ts.map +1 -1
  73. package/dist/commands/feature.js +48 -6
  74. package/dist/commands/feature.js.map +1 -1
  75. package/dist/commands/fix.d.ts +1 -0
  76. package/dist/commands/fix.d.ts.map +1 -1
  77. package/dist/commands/fix.js +42 -50
  78. package/dist/commands/fix.js.map +1 -1
  79. package/dist/commands/host-apply.d.ts +12 -0
  80. package/dist/commands/host-apply.d.ts.map +1 -0
  81. package/dist/commands/host-apply.js +43 -0
  82. package/dist/commands/host-apply.js.map +1 -0
  83. package/dist/commands/host.d.ts +3 -0
  84. package/dist/commands/host.d.ts.map +1 -0
  85. package/dist/commands/host.js +107 -0
  86. package/dist/commands/host.js.map +1 -0
  87. package/dist/commands/index.d.ts +12 -0
  88. package/dist/commands/index.d.ts.map +1 -1
  89. package/dist/commands/index.js +12 -0
  90. package/dist/commands/index.js.map +1 -1
  91. package/dist/commands/init.d.ts.map +1 -1
  92. package/dist/commands/init.js +5 -3
  93. package/dist/commands/init.js.map +1 -1
  94. package/dist/commands/install.d.ts.map +1 -1
  95. package/dist/commands/install.js +19 -8
  96. package/dist/commands/install.js.map +1 -1
  97. package/dist/commands/knowledge.d.ts +3 -0
  98. package/dist/commands/knowledge.d.ts.map +1 -0
  99. package/dist/commands/knowledge.js +59 -0
  100. package/dist/commands/knowledge.js.map +1 -0
  101. package/dist/commands/learning.d.ts +3 -0
  102. package/dist/commands/learning.d.ts.map +1 -0
  103. package/dist/commands/learning.js +126 -0
  104. package/dist/commands/learning.js.map +1 -0
  105. package/dist/commands/mcp.d.ts +3 -0
  106. package/dist/commands/mcp.d.ts.map +1 -0
  107. package/dist/commands/mcp.js +26 -0
  108. package/dist/commands/mcp.js.map +1 -0
  109. package/dist/commands/next.d.ts.map +1 -1
  110. package/dist/commands/next.js +3 -1
  111. package/dist/commands/next.js.map +1 -1
  112. package/dist/commands/onboard.d.ts +5 -0
  113. package/dist/commands/onboard.d.ts.map +1 -0
  114. package/dist/commands/onboard.js +137 -0
  115. package/dist/commands/onboard.js.map +1 -0
  116. package/dist/commands/plugin-linker.d.ts +10 -1
  117. package/dist/commands/plugin-linker.d.ts.map +1 -1
  118. package/dist/commands/plugin-linker.js +53 -14
  119. package/dist/commands/plugin-linker.js.map +1 -1
  120. package/dist/commands/routing.d.ts +3 -0
  121. package/dist/commands/routing.d.ts.map +1 -0
  122. package/dist/commands/routing.js +107 -0
  123. package/dist/commands/routing.js.map +1 -0
  124. package/dist/commands/rules-format.d.ts +4 -0
  125. package/dist/commands/rules-format.d.ts.map +1 -0
  126. package/dist/commands/rules-format.js +16 -0
  127. package/dist/commands/rules-format.js.map +1 -0
  128. package/dist/commands/rules.d.ts +3 -0
  129. package/dist/commands/rules.d.ts.map +1 -0
  130. package/dist/commands/rules.js +270 -0
  131. package/dist/commands/rules.js.map +1 -0
  132. package/dist/commands/skills-install-commit.d.ts +34 -0
  133. package/dist/commands/skills-install-commit.d.ts.map +1 -0
  134. package/dist/commands/skills-install-commit.js +113 -0
  135. package/dist/commands/skills-install-commit.js.map +1 -0
  136. package/dist/commands/skills-install-manifest.d.ts +35 -0
  137. package/dist/commands/skills-install-manifest.d.ts.map +1 -0
  138. package/dist/commands/skills-install-manifest.js +89 -0
  139. package/dist/commands/skills-install-manifest.js.map +1 -0
  140. package/dist/commands/skills-install-report.d.ts +12 -0
  141. package/dist/commands/skills-install-report.d.ts.map +1 -0
  142. package/dist/commands/skills-install-report.js +44 -0
  143. package/dist/commands/skills-install-report.js.map +1 -0
  144. package/dist/commands/skills-install-secure.d.ts +14 -0
  145. package/dist/commands/skills-install-secure.d.ts.map +1 -0
  146. package/dist/commands/skills-install-secure.js +96 -0
  147. package/dist/commands/skills-install-secure.js.map +1 -0
  148. package/dist/commands/skills-install.d.ts +15 -0
  149. package/dist/commands/skills-install.d.ts.map +1 -0
  150. package/dist/commands/skills-install.js +182 -0
  151. package/dist/commands/skills-install.js.map +1 -0
  152. package/dist/commands/skills.d.ts +3 -0
  153. package/dist/commands/skills.d.ts.map +1 -0
  154. package/dist/commands/skills.js +217 -0
  155. package/dist/commands/skills.js.map +1 -0
  156. package/dist/commands/uninstall.d.ts +3 -0
  157. package/dist/commands/uninstall.d.ts.map +1 -0
  158. package/dist/commands/uninstall.js +113 -0
  159. package/dist/commands/uninstall.js.map +1 -0
  160. package/dist/commands/verify.d.ts.map +1 -1
  161. package/dist/commands/verify.js +78 -6
  162. package/dist/commands/verify.js.map +1 -1
  163. package/package.json +11 -5
  164. package/src/application/agent/execution-store.ts +2 -1
  165. package/src/application/agent/orchestrator.test.ts +39 -0
  166. package/src/application/agent/orchestrator.ts +8 -1
  167. package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +1 -1
  168. package/src/application/agent/providers/claude-code/permission-config.test.ts +4 -4
  169. package/src/application/agent/providers/claude-code/permission-config.ts +8 -2
  170. package/src/application/agent/providers/claude-code/provider.test.ts +2 -2
  171. package/src/application/agent-tools/dispatch.test.ts +160 -0
  172. package/src/application/agent-tools/dispatch.ts +227 -0
  173. package/src/application/agent-tools/mcp-server.test.ts +86 -0
  174. package/src/application/agent-tools/mcp-server.ts +126 -0
  175. package/src/application/bench/harness.ts +95 -0
  176. package/src/application/dispatcher.test.ts +23 -3
  177. package/src/application/dispatcher.ts +24 -0
  178. package/src/application/rule-adapters/adapters.test.ts +224 -0
  179. package/src/application/rule-adapters/ast-grep.ts +126 -0
  180. package/src/application/rule-adapters/index.ts +16 -0
  181. package/src/application/rule-adapters/linter-paths.test.ts +95 -0
  182. package/src/application/rule-adapters/linter.ts +263 -0
  183. package/src/application/rule-adapters/process.ts +48 -0
  184. package/src/application/version.ts +9 -4
  185. package/src/commands/attach-exclude.ts +50 -0
  186. package/src/commands/attach-git.ts +50 -0
  187. package/src/commands/attach-store.ts +107 -0
  188. package/src/commands/attach.test.ts +192 -0
  189. package/src/commands/attach.ts +143 -0
  190. package/src/commands/bench.test.ts +136 -0
  191. package/src/commands/bench.ts +74 -0
  192. package/src/commands/context.test.ts +47 -0
  193. package/src/commands/context.ts +59 -0
  194. package/src/commands/doctor-isolation.test.ts +76 -0
  195. package/src/commands/doctor.test.ts +2 -1
  196. package/src/commands/doctor.ts +36 -0
  197. package/src/commands/feature.test.ts +36 -4
  198. package/src/commands/feature.ts +71 -8
  199. package/src/commands/fix.test.ts +95 -13
  200. package/src/commands/fix.ts +44 -55
  201. package/src/commands/host-apply.ts +61 -0
  202. package/src/commands/host.test.ts +120 -0
  203. package/src/commands/host.ts +125 -0
  204. package/src/commands/index.ts +12 -0
  205. package/src/commands/init.test.ts +22 -0
  206. package/src/commands/init.ts +10 -3
  207. package/src/commands/install.test.ts +31 -0
  208. package/src/commands/install.ts +25 -8
  209. package/src/commands/knowledge.test.ts +39 -0
  210. package/src/commands/knowledge.ts +63 -0
  211. package/src/commands/learning.test.ts +104 -0
  212. package/src/commands/learning.ts +134 -0
  213. package/src/commands/mcp.ts +30 -0
  214. package/src/commands/next.ts +3 -1
  215. package/src/commands/onboard.test.ts +83 -0
  216. package/src/commands/onboard.ts +146 -0
  217. package/src/commands/plugin-linker.test.ts +80 -0
  218. package/src/commands/plugin-linker.ts +62 -14
  219. package/src/commands/routing.test.ts +64 -0
  220. package/src/commands/routing.ts +107 -0
  221. package/src/commands/rules-format.ts +22 -0
  222. package/src/commands/rules.test.ts +153 -0
  223. package/src/commands/rules.ts +286 -0
  224. package/src/commands/skills-install-commit.ts +149 -0
  225. package/src/commands/skills-install-manifest.ts +124 -0
  226. package/src/commands/skills-install-report.ts +60 -0
  227. package/src/commands/skills-install-secure.ts +113 -0
  228. package/src/commands/skills-install.ts +245 -0
  229. package/src/commands/skills.test.ts +449 -0
  230. package/src/commands/skills.ts +247 -0
  231. package/src/commands/uninstall.test.ts +122 -0
  232. package/src/commands/uninstall.ts +116 -0
  233. package/src/commands/verify.test.ts +115 -0
  234. package/src/commands/verify.ts +95 -7
  235. package/src/commands/version.test.ts +9 -0
@@ -0,0 +1,76 @@
1
+ // kit doctor and the execution profile (roadmap Phase 8): a required profile fails when its runtime
2
+ // cannot be reached; a project without a profile is unaffected.
3
+ import { promises as fs } from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
+ import { doctorCommand } from './doctor.js';
8
+ import type { CommandContext } from './types.js';
9
+
10
+ function ctx(cwd: string): CommandContext & { out: string[] } {
11
+ const out: string[] = [];
12
+ return { argv: [], cwd, stdout: (s) => void out.push(s), stderr: () => undefined, out };
13
+ }
14
+
15
+ const DIGEST = 'b'.repeat(64);
16
+ const requiredProfile = (runtime: 'docker' | 'podman') => `schemaVersion: 1
17
+ kind: container
18
+ requireIsolation: true
19
+ container:
20
+ runtime: ${runtime}
21
+ image: registry.example/tools/node@sha256:${DIGEST}
22
+ network: none
23
+ allowedHosts: []
24
+ cpus: 2
25
+ memoryMb: 2048
26
+ timeoutSeconds: 600
27
+ `;
28
+
29
+ let root: string;
30
+ let savedPath: string | undefined;
31
+ beforeEach(async () => {
32
+ root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-doctor-iso-'));
33
+ savedPath = process.env['PATH'];
34
+ });
35
+ afterEach(async () => {
36
+ if (savedPath === undefined) delete process.env['PATH'];
37
+ else process.env['PATH'] = savedPath;
38
+ await fs.rm(root, { recursive: true, force: true });
39
+ });
40
+
41
+ describe('kit doctor: isolation', () => {
42
+ it('a project with no execution profile is unaffected: host execution, informational only', async () => {
43
+ const c = ctx(root);
44
+ await doctorCommand.run(c);
45
+ expect(c.out.join('')).toContain('no execution profile declared');
46
+ });
47
+
48
+ it('a required profile whose runtime is unreachable fails the doctor and says it will not run on the host', async () => {
49
+ // The probe runs the runtime CLI found on PATH. A real podman on a CI runner can take the whole
50
+ // 15 s probe timeout, so PATH holds only a podman that cannot reach a daemon: the probe fails at
51
+ // once on every machine, and the refusal path is what this test checks.
52
+ const bin = path.join(root, 'bin');
53
+ await fs.mkdir(bin, { recursive: true });
54
+ const podman = path.join(bin, 'podman');
55
+ await fs.writeFile(podman, '#!/bin/sh\necho "Cannot connect to Podman" >&2\nexit 125\n');
56
+ await fs.chmod(podman, 0o755);
57
+ process.env['PATH'] = bin;
58
+
59
+ await fs.mkdir(path.join(root, '.ai-kit'), { recursive: true });
60
+ await fs.writeFile(path.join(root, '.ai-kit', 'execution.yml'), requiredProfile('podman'));
61
+ const c = ctx(root);
62
+ const code = (await doctorCommand.run(c)).exitCode;
63
+ const text = c.out.join('');
64
+ expect(text).toContain('Refusing to run on the host');
65
+ expect(text).toContain('isolation');
66
+ expect(code).not.toBe(0);
67
+ });
68
+
69
+ it('an invalid profile fails the doctor, never a silent weakening', async () => {
70
+ await fs.mkdir(path.join(root, '.ai-kit'), { recursive: true });
71
+ await fs.writeFile(path.join(root, '.ai-kit', 'execution.yml'), requiredProfile('docker').replace(DIGEST, 'latest'));
72
+ const c = ctx(root);
73
+ expect((await doctorCommand.run(c)).exitCode).not.toBe(0);
74
+ expect(c.out.join('')).toContain('execution profile invalid');
75
+ });
76
+ });
@@ -1,6 +1,7 @@
1
1
  // packages/cli/src/commands/doctor.test.ts
2
2
  import { describe, expect, it } from 'vitest';
3
3
  import { doctorCommand } from './doctor.js';
4
+ import { VERSION } from '../application/version.js';
4
5
  import type { CommandContext } from './types.js';
5
6
 
6
7
  const makeCtx = (): CommandContext & { out: string[] } => {
@@ -20,7 +21,7 @@ describe('doctorCommand', () => {
20
21
  const r = await doctorCommand.run(ctx);
21
22
  expect(r.exitCode).toBeLessThanOrEqual(2); // 0 if healthy, 2 if not
22
23
  const text = ctx.out[0] ?? '';
23
- expect(text).toContain('kit 0.8.0');
24
+ expect(text).toContain(`kit ${VERSION}`);
24
25
  expect(text).toContain('node');
25
26
  expect(text).toContain('pnpm');
26
27
  expect(text).toContain('workspace');
@@ -8,6 +8,8 @@
8
8
 
9
9
  import { promises as fs } from 'node:fs';
10
10
  import path from 'node:path';
11
+ import { decideExecution, parseExecutionProfile, runtimeProbeArgv, type RuntimeProbe } from '@agentic-sdlc-kit/core';
12
+ import type { ExecutionProfile } from '@agentic-sdlc-kit/contracts';
11
13
  import { VERSION } from '../application/version.js';
12
14
  import type { Command, CommandContext, CommandResult } from './types.js';
13
15
 
@@ -49,6 +51,12 @@ export const doctorCommand: Command = {
49
51
  const profile = await checkProfile(ctx.cwd);
50
52
  lines.push(` profile ${profile.msg} [${profile.status}]`);
51
53
 
54
+ // Execution isolation (roadmap Phase 8). Only a declared profile is checked: a project without
55
+ // one is unaffected. A profile that requires isolation and cannot get it fails the doctor.
56
+ const execution = await checkExecution(ctx.cwd);
57
+ if (execution.failed) healthy = false;
58
+ lines.push(` isolation ${execution.msg} [${execution.status}]`);
59
+
52
60
  lines.push('');
53
61
  lines.push(healthy ? 'Status: healthy' : 'Status: issues found');
54
62
  ctx.stdout(lines.join('\n') + '\n');
@@ -56,6 +64,34 @@ export const doctorCommand: Command = {
56
64
  },
57
65
  };
58
66
 
67
+ async function checkExecution(cwd: string): Promise<{ msg: string; status: 'ok' | 'info' | 'FAIL'; failed: boolean }> {
68
+ let text: string;
69
+ try {
70
+ text = await fs.readFile(path.join(cwd, '.ai-kit', 'execution.yml'), 'utf8');
71
+ } catch {
72
+ return { msg: 'no execution profile declared (host execution)', status: 'info', failed: false };
73
+ }
74
+ const parsed = parseExecutionProfile(text);
75
+ if (!parsed.ok) return { msg: `execution profile invalid: ${parsed.error}`, status: 'FAIL', failed: true };
76
+ const probe = await probeRuntime(parsed.value);
77
+ const decision = decideExecution(parsed.value, probe);
78
+ if (!decision.ok) return { msg: decision.reason, status: 'FAIL', failed: true };
79
+ return { msg: decision.reason, status: 'ok', failed: false };
80
+ }
81
+
82
+ async function probeRuntime(profile: ExecutionProfile): Promise<RuntimeProbe | null> {
83
+ if (profile.kind !== 'container') return null;
84
+ const { execFile } = await import('node:child_process');
85
+ const { promisify } = await import('node:util');
86
+ const argv = runtimeProbeArgv(profile.container.runtime);
87
+ try {
88
+ const { stdout } = await promisify(execFile)(argv[0] as string, argv.slice(1), { timeout: 15_000 });
89
+ return { reachable: stdout.trim().length > 0, detail: `daemon ${stdout.trim() || 'returned no version'}` };
90
+ } catch (cause) {
91
+ return { reachable: false, detail: cause instanceof Error ? cause.message.split('\n')[0] ?? 'probe failed' : 'probe failed' };
92
+ }
93
+ }
94
+
59
95
  async function findExecutable(name: string): Promise<string | null> {
60
96
  const { execFileSync } = await import('node:child_process');
61
97
  try {
@@ -3,10 +3,7 @@ import { promises as fs } from 'node:fs';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import { describe, expect, it } from 'vitest';
6
- import {
7
- scaffoldSpecification,
8
- serializeProfileYaml,
9
- } from '@agentic-sdlc-kit/core';
6
+ import { scaffoldSpecification, serializeProfileYaml } from '@agentic-sdlc-kit/core';
10
7
  import { MockAgentProvider } from '@agentic-sdlc-kit/testing';
11
8
  import type { AgentProvider } from '@agentic-sdlc-kit/contracts';
12
9
  import { buildOrchestrationFixture } from '../application/agent/test-fixture.js';
@@ -321,3 +318,38 @@ describe('featureCommand run (Mode 1, PR3+PR4)', () => {
321
318
  }
322
319
  });
323
320
  });
321
+
322
+ describe('featureCommand strength (ADR-0022)', () => {
323
+ it('requires a task id and refuses when the profile has no strength section', async () => {
324
+ const project = await setupProject();
325
+ try {
326
+ // No task id.
327
+ const noTask = makeCtx(['FEATURE-001', 'strength'], project.root);
328
+ const r1 = await featureCommand.run(noTask);
329
+ expect(r1.exitCode).toBe(1);
330
+ expect(noTask.err[0]).toContain('strength requires a task id');
331
+
332
+ // Task id present, but strength not enabled in the profile (opt-in).
333
+ // Complete the chain properly: red (marker absent -> assertion failure),
334
+ // then implement (marker), then green, then refactor.
335
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], project.root));
336
+ await featureCommand.run(makeCtx(['FEATURE-001', 'red', 'TASK-001'], project.root));
337
+ await fs.writeFile(project.marker, '');
338
+ await featureCommand.run(makeCtx(['FEATURE-001', 'green', 'TASK-001'], project.root));
339
+ await featureCommand.run(makeCtx(['FEATURE-001', 'refactor', 'TASK-001'], project.root));
340
+
341
+ const ctx = makeCtx(['FEATURE-001', 'strength', 'TASK-001'], project.root);
342
+ const r2 = await featureCommand.run(ctx);
343
+ expect(r2.exitCode).toBe(1);
344
+ expect(ctx.err[0]).toContain('not enabled');
345
+ } finally {
346
+ await fs.rm(project.root, { recursive: true, force: true });
347
+ }
348
+ });
349
+
350
+ it('mentions the strength action in help output', async () => {
351
+ const ctx = makeCtx(['--help'], '/');
352
+ await featureCommand.run(ctx);
353
+ expect(ctx.out[0]).toContain('strength <task-id>');
354
+ });
355
+ });
@@ -20,6 +20,7 @@ import path from 'node:path';
20
20
  import {
21
21
  finalizeFeatureRun,
22
22
  getFeatureRunState,
23
+ runStrengthPhase,
23
24
  runTddPhase,
24
25
  startFeatureRun,
25
26
  type FeatureRunReport,
@@ -59,9 +60,11 @@ function blocked(ctx: CommandContext, message: string): CommandResult {
59
60
  */
60
61
  function resolveActor(argv: ReadonlyArray<string>): JournalActor {
61
62
  const fromFlag = parseFlagValue(argv, '--host');
62
- const host = fromFlag ?? (process.env['KIT_HOST'] && process.env['KIT_HOST'].length > 0
63
- ? process.env['KIT_HOST']
64
- : undefined);
63
+ const host =
64
+ fromFlag ??
65
+ (process.env['KIT_HOST'] && process.env['KIT_HOST'].length > 0
66
+ ? process.env['KIT_HOST']
67
+ : undefined);
65
68
  return host !== undefined ? { kind: 'agent', host } : { kind: 'human' };
66
69
  }
67
70
 
@@ -104,6 +107,8 @@ export function createFeatureCommand(opts: FeatureCommandOptions = {}): Command
104
107
  return runStart(ctx, root, featureId, isJson, actor);
105
108
  case 'status':
106
109
  return runStatus(ctx, root, featureId, isJson);
110
+ case 'strength':
111
+ return runStrength(ctx, root, featureId, positional[2], isJson, actor);
107
112
  case 'verify':
108
113
  return runVerify(ctx, root, featureId, isJson, ctx.argv.includes('--dry-run'), actor);
109
114
  case 'run':
@@ -117,7 +122,7 @@ export function createFeatureCommand(opts: FeatureCommandOptions = {}): Command
117
122
  default:
118
123
  return fail(
119
124
  ctx,
120
- `unknown action '${action}' (expected start|red|green|refactor|status|verify|run)`,
125
+ `unknown action '${action}' (expected start|red|green|refactor|status|strength|verify|run)`,
121
126
  );
122
127
  }
123
128
  },
@@ -161,7 +166,11 @@ async function runPhase(
161
166
  isJson: boolean,
162
167
  actor: JournalActor,
163
168
  ): Promise<CommandResult> {
164
- if (!taskId) return fail(ctx, `phase '${phase}' requires a task id (see \`kit feature ${featureId} status\`)`);
169
+ if (!taskId)
170
+ return fail(
171
+ ctx,
172
+ `phase '${phase}' requires a task id (see \`kit feature ${featureId} status\`)`,
173
+ );
165
174
  const res = await runTddPhase({ featureId, projectRoot: root, taskId, phase, actor });
166
175
  if (!res.ok) return fail(ctx, res.error.message);
167
176
  if (isJson) {
@@ -223,6 +232,56 @@ async function runStatus(
223
232
  return { exitCode: 0 };
224
233
  }
225
234
 
235
+ /**
236
+ * `kit feature <id> strength <task-id>` (ADR-0022): run the optional
237
+ * mutation-score measurement for a completed task and record it as
238
+ * journal + persisted evidence. The gate decision is reported; blocking
239
+ * happens at verify when gateMode is enforce.
240
+ */
241
+ async function runStrength(
242
+ ctx: CommandContext,
243
+ root: string,
244
+ featureId: string,
245
+ taskId: string | undefined,
246
+ isJson: boolean,
247
+ actor: JournalActor,
248
+ ): Promise<CommandResult> {
249
+ if (!taskId) {
250
+ return fail(ctx, `strength requires a task id (see \`kit feature ${featureId} status\`)`);
251
+ }
252
+ const res = await runStrengthPhase({
253
+ featureId,
254
+ projectRoot: root,
255
+ taskId,
256
+ actor,
257
+ });
258
+ if (!res.ok) return fail(ctx, res.error.message);
259
+ if (isJson) {
260
+ ctx.stdout(
261
+ JSON.stringify(
262
+ { taskId, strength: res.value.evidence, gateBlocked: res.value.blocked },
263
+ null,
264
+ 2,
265
+ ) + '\n',
266
+ );
267
+ return { exitCode: 0 };
268
+ }
269
+ const e = res.value.evidence;
270
+ const score = e.score !== undefined ? `${e.score}%` : 'n/a';
271
+ ctx.stdout(
272
+ [
273
+ `${taskId} strength ${e.status} (score ${score} vs threshold ${e.threshold}%).`,
274
+ ` tool=${e.tool} scope=${e.scope} mutants=${e.mutantsKilled}/${e.mutantsGenerated} killed`,
275
+ ` ${e.summary}`,
276
+ res.value.blocked
277
+ ? `Strength gate: BLOCKED (enforce) — \`kit feature ${featureId} verify\` will refuse until the suite clears ${e.threshold}%.`
278
+ : `Strength gate: not blocking (warn mode).`,
279
+ '',
280
+ ].join('\n'),
281
+ );
282
+ return { exitCode: 0 };
283
+ }
284
+
226
285
  async function runVerify(
227
286
  ctx: CommandContext,
228
287
  root: string,
@@ -261,8 +320,9 @@ async function runOrchestrated(
261
320
  // PR4: the shipped CLI registers claude-code against the resolved root
262
321
  // (the provider roots its encrypted resume store there). Explicitly
263
322
  // injected providers override the default entirely.
264
- const providers: ReadonlyArray<AgentProvider> =
265
- opts.agentProviders ?? [new ClaudeCodeProvider({ projectRoot: root })];
323
+ const providers: ReadonlyArray<AgentProvider> = opts.agentProviders ?? [
324
+ new ClaudeCodeProvider({ projectRoot: root }),
325
+ ];
266
326
 
267
327
  const gateway = new AgentGateway({
268
328
  providers,
@@ -302,7 +362,8 @@ async function runOrchestrated(
302
362
  ...(isJson ? {} : { onProgress: (line: string) => ctx.stdout(line) }),
303
363
  });
304
364
  if (!res.ok) {
305
- if (res.error.code === 'AGENT_PROVIDER_NOT_CONFIGURED') return blocked(ctx, res.error.message);
365
+ if (res.error.code === 'AGENT_PROVIDER_NOT_CONFIGURED')
366
+ return blocked(ctx, res.error.message);
306
367
  return fail(ctx, res.error.message);
307
368
  }
308
369
  const report = res.value;
@@ -381,6 +442,8 @@ function formatHelp(): string {
381
442
  ' green <task-id> run verification: it MUST pass (after implementing)',
382
443
  ' refactor <task-id> run verification: it MUST pass (behavior preserved)',
383
444
  ' status show run state and the next action',
445
+ ' strength <task-id> run the optional mutation-score stage for a completed task',
446
+ ' (ADR-0022; requires verification.strength.enabled)',
384
447
  ' verify audit the evidence chain and run final verification',
385
448
  ' run Mode 1: orchestrate all phases through an agent provider',
386
449
  ' in an isolated git worktree (ADR-0019)',
@@ -1,5 +1,9 @@
1
1
  // packages/cli/src/commands/fix.test.ts
2
- import { describe, expect, it } from 'vitest';
2
+ import { promises as fs } from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
6
+ import { scaffoldSpecification, serializeProfileYaml } from '@agentic-sdlc-kit/core';
3
7
  import { fixCommand } from './fix.js';
4
8
  import type { CommandContext } from './types.js';
5
9
 
@@ -9,28 +13,106 @@ const makeCtx = (
9
13
  ): CommandContext & { out: string[]; err: string[] } => {
10
14
  const out: string[] = [];
11
15
  const err: string[] = [];
12
- return {
13
- argv,
14
- cwd,
15
- stdout: (s) => void out.push(s),
16
- stderr: (s) => void err.push(s),
17
- out,
18
- err,
19
- };
16
+ return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
20
17
  };
21
18
 
19
+ let root: string;
20
+ let marker: string;
21
+
22
+ /** The test script fails with a real AssertionError until the marker (the "fix") exists. */
23
+ beforeEach(async () => {
24
+ root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-fix-'));
25
+ marker = path.join(root, '.fixed');
26
+ const script = path.join(root, 'check.js');
27
+ await fs.writeFile(
28
+ script,
29
+ [
30
+ 'const fs = require("node:fs");',
31
+ `if (!fs.existsSync(${JSON.stringify(marker)})) {`,
32
+ ' console.error("AssertionError: expected defect to be fixed");',
33
+ ' process.exit(1);',
34
+ '}',
35
+ ].join('\n'),
36
+ );
37
+ await fs.mkdir(path.join(root, '.ai-kit'), { recursive: true });
38
+ await fs.writeFile(
39
+ path.join(root, '.ai-kit', 'project.yml'),
40
+ serializeProfileYaml({
41
+ schemaVersion: 1,
42
+ name: 'fix-app',
43
+ stack: ['node-typescript'],
44
+ commands: { test: [['node', script]] },
45
+ }),
46
+ );
47
+ await scaffoldSpecification({
48
+ id: 'BUG-101',
49
+ title: 'Transfer accepts negative amounts',
50
+ targetDir: path.join(root, 'docs', 'specifications', 'features'),
51
+ });
52
+ const planDir = path.join(root, 'docs', 'plans', 'BUG-101');
53
+ await fs.mkdir(planDir, { recursive: true });
54
+ await fs.writeFile(
55
+ path.join(planDir, 'plan.json'),
56
+ JSON.stringify({
57
+ featureId: 'BUG-101',
58
+ tasks: [
59
+ {
60
+ id: 'TASK-001',
61
+ description: 'Reject negative transfer amounts',
62
+ acceptanceCriteria: ['negative amount is rejected'],
63
+ verification: { command: ['node', script], expectedStatus: 'passed' },
64
+ dependencies: [],
65
+ likelyFiles: ['src/transfer.js'],
66
+ estimatedScope: 'xs',
67
+ risk: 'low',
68
+ },
69
+ ],
70
+ edges: [],
71
+ verticalSlices: [['TASK-001']],
72
+ }),
73
+ );
74
+ });
75
+ afterEach(() => fs.rm(root, { recursive: true, force: true }));
76
+
22
77
  describe('fixCommand', () => {
23
78
  it('shows help when --help is passed', async () => {
24
79
  const ctx = makeCtx(['--help'], '/');
25
- const r = await fixCommand.run(ctx);
26
- expect(r.exitCode).toBe(0);
80
+ expect((await fixCommand.run(ctx)).exitCode).toBe(0);
27
81
  expect(ctx.out[0]).toContain('Usage: kit fix');
28
82
  });
29
83
 
30
84
  it('fails if issue ID is missing', async () => {
31
85
  const ctx = makeCtx([], '/');
32
- const r = await fixCommand.run(ctx);
33
- expect(r.exitCode).toBe(1);
86
+ expect((await fixCommand.run(ctx)).exitCode).toBe(1);
34
87
  expect(ctx.err[0]).toContain('missing required issue identifier');
35
88
  });
89
+
90
+ it('no longer reports success without a failing test: green before red is rejected', async () => {
91
+ expect((await fixCommand.run(makeCtx(['BUG-101', 'start'], root))).exitCode).toBe(0);
92
+ await fs.writeFile(marker, 'fixed'); // the defect is "fixed" but Red was never observed
93
+ const green = makeCtx(['BUG-101', 'green', 'TASK-001'], root);
94
+ expect((await fixCommand.run(green)).exitCode).toBe(1);
95
+ expect(green.err.join('\n')).toMatch(/red/i);
96
+ });
97
+
98
+ it('drives red -> green -> refactor -> verify with recorded evidence', async () => {
99
+ expect((await fixCommand.run(makeCtx(['BUG-101', 'start'], root))).exitCode).toBe(0);
100
+ expect((await fixCommand.run(makeCtx(['BUG-101', 'red', 'TASK-001'], root))).exitCode).toBe(0);
101
+ await fs.writeFile(marker, 'fixed');
102
+ expect((await fixCommand.run(makeCtx(['BUG-101', 'green', 'TASK-001'], root))).exitCode).toBe(0);
103
+ expect((await fixCommand.run(makeCtx(['BUG-101', 'refactor', 'TASK-001'], root))).exitCode).toBe(0);
104
+ const verify = makeCtx(['BUG-101', 'verify'], root);
105
+ expect((await fixCommand.run(verify)).exitCode).toBe(0);
106
+ expect(verify.out.join('\n')).toContain('red:failed green:passed refactor:passed');
107
+ const journal = await fs.readdir(path.join(root, '.ai-kit', 'journal', 'feature-runs'));
108
+ expect(journal).toContain('BUG-101.jsonl');
109
+ });
110
+
111
+ it('with no action it starts the run, then reports status', async () => {
112
+ const first = makeCtx(['BUG-101'], root);
113
+ expect((await fixCommand.run(first)).exitCode).toBe(0);
114
+ const again = makeCtx(['BUG-101'], root);
115
+ expect((await fixCommand.run(again)).exitCode).toBe(0);
116
+ expect(again.out.join('\n')).toContain('BUG-101');
117
+ });
36
118
  });
@@ -1,69 +1,58 @@
1
1
  // packages/cli/src/commands/fix.ts
2
2
  //
3
- // `kit fix <issue-id> [--dry-run] [--json]`.
4
- // Executes the disciplined bug-fix and refactoring workflow (M9).
3
+ // `kit fix <issue-id> [action] [task-id] [options]`.
4
+ //
5
+ // A defect is driven through the SAME evidence-gated engine as a feature
6
+ // (`kit feature`): the regression test must fail as an ASSERTION (Red) before
7
+ // the correction is accepted (Green), then the suite must stay green
8
+ // (Refactor), with a hash-chained journal and `kit next` guidance.
9
+ //
10
+ // This command used to run the whole-profile verification and report a
11
+ // "confirmed" regression without ever observing a failing test. It no longer
12
+ // carries any workflow of its own: it only delegates, so it cannot assert more
13
+ // than the engine has measured.
5
14
 
6
- import path from 'node:path';
7
- import { runBugfixWorkflow, type BugfixReport } from '@agentic-sdlc-kit/core';
15
+ import { featureCommand } from './feature.js';
8
16
  import type { Command, CommandContext, CommandResult } from './types.js';
9
17
 
10
- export const fixCommand: Command = {
11
- name: 'fix',
12
- summary:
13
- 'Execute disciplined bug-fix workflow with reproduction and regression verification (M9).',
14
- async run(ctx: CommandContext): Promise<CommandResult> {
15
- if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
16
- ctx.stdout(formatHelp());
17
- return { exitCode: 0 };
18
- }
19
-
20
- const issueId = ctx.argv.find((a) => !a.startsWith('-'));
21
- if (!issueId) {
22
- ctx.stderr('kit fix: error: missing required issue identifier (e.g. BUG-001)\n');
23
- return { exitCode: 1, message: 'Missing issue ID' };
24
- }
25
-
26
- const isJson = ctx.argv.includes('--json');
27
- const isDryRun = ctx.argv.includes('--dry-run');
28
- const targetRoot = path.resolve(ctx.cwd, '.');
29
-
30
- const res = await runBugfixWorkflow({ issueId, projectRoot: targetRoot, dryRun: isDryRun });
31
- if (!res.ok) {
32
- ctx.stderr(`kit fix: workflow error: ${res.error.message}\n`);
33
- return { exitCode: 1, message: res.error.message };
34
- }
35
-
36
- if (isJson) {
37
- ctx.stdout(JSON.stringify(res.value, null, 2) + '\n');
38
- } else {
39
- ctx.stdout(formatSummary(res.value));
40
- }
41
- return { exitCode: res.value.status === 'passed' ? 0 : 1 };
42
- },
43
- };
44
-
45
- function formatSummary(report: BugfixReport): string {
46
- const lines: string[] = [
47
- `Bugfix Run: ${report.issueId}`,
48
- `Status: ${report.status.toUpperCase()}`,
49
- `Regression Cover: ${report.regressionCovered ? 'CONFIRMED' : 'MISSING'}`,
50
- `Verification: ${report.verification.status.toUpperCase()}`,
51
- `Duration: ${report.durationMs}ms`,
52
- ];
53
- return lines.join('\n') + '\n';
18
+ export function createFixCommand(engine: Command = featureCommand): Command {
19
+ return {
20
+ name: 'fix',
21
+ summary:
22
+ 'Fix a defect through the evidence-gated engine: failing regression test first (Red/Green/Refactor).',
23
+ async run(ctx: CommandContext): Promise<CommandResult> {
24
+ if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
25
+ ctx.stdout(formatHelp());
26
+ return { exitCode: 0 };
27
+ }
28
+ const issueId = ctx.argv.find((a) => !a.startsWith('-'));
29
+ if (!issueId) {
30
+ ctx.stderr('kit fix: error: missing required issue identifier (e.g. BUG-001)\n');
31
+ return { exitCode: 1, message: 'Missing issue ID' };
32
+ }
33
+ return engine.run(ctx);
34
+ },
35
+ };
54
36
  }
55
37
 
38
+ export const fixCommand: Command = createFixCommand();
39
+
56
40
  function formatHelp(): string {
57
41
  return [
58
- 'Usage: kit fix <issue-id> [--dry-run] [--json]',
42
+ 'Usage: kit fix <issue-id> [start|red|green|refactor|status|verify|run] [task-id] [options]',
43
+ '',
44
+ 'Drive a bug fix through the same evidence gates as a feature. The issue id is the',
45
+ 'run id (e.g. BUG-101): author docs/specifications/features/<id>/SPEC.md (expected vs',
46
+ 'actual behavior) and docs/plans/<id>/plan.json, then:',
59
47
  '',
60
- 'Execute a bug-fix workflow: reproduce via failing test (red), implement fix (green),',
61
- 'and run full regression verification.',
48
+ ' kit fix BUG-101 start begin the run (no action: start, or status if it exists)',
49
+ ' kit fix BUG-101 red TASK-001 the regression test must FAIL as an assertion',
50
+ ' kit fix BUG-101 green TASK-001 the smallest correction must pass it',
51
+ ' kit fix BUG-101 refactor TASK-001 the suite must stay green',
52
+ ' kit fix BUG-101 verify audit every chain + whole-profile regression',
62
53
  '',
63
- 'Options:',
64
- ' --dry-run Simulate execution without running active subprocesses',
65
- ' --json Output machine-readable BugfixReport',
66
- ' --help Show this message',
54
+ 'Options are those of `kit feature` (--json, --host <id>, --dry-run, ...).',
55
+ 'Do not combine a behavior fix with a refactor in one run.',
67
56
  '',
68
57
  ].join('\n');
69
58
  }
@@ -0,0 +1,61 @@
1
+ // packages/cli/src/commands/host-apply.ts
2
+ //
3
+ // Applies planned host-instruction targets to disk. Never overwrites a file
4
+ // the user edited (or one the kit did not write) unless --force is given.
5
+
6
+ import { promises as fs } from 'node:fs';
7
+ import path from 'node:path';
8
+ import { inspectManaged, upsertBlock, type HostTarget } from '@agentic-sdlc-kit/core';
9
+
10
+ export type ApplyAction = 'created' | 'updated' | 'unchanged' | 'refused';
11
+
12
+ export interface ApplyResult {
13
+ readonly path: string;
14
+ readonly action: ApplyAction;
15
+ readonly reason?: string;
16
+ }
17
+
18
+ async function readOrNull(p: string): Promise<string | null> {
19
+ try {
20
+ return await fs.readFile(p, 'utf8');
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+
26
+ interface Decision {
27
+ readonly action: ApplyAction;
28
+ readonly next?: string;
29
+ readonly reason?: string;
30
+ }
31
+
32
+ function decideBlock(existing: string | null, target: HostTarget): Decision {
33
+ const next = upsertBlock(existing, target.content);
34
+ if (existing === null) return { action: 'created', next };
35
+ return next === existing ? { action: 'unchanged' } : { action: 'updated', next };
36
+ }
37
+
38
+ function decideFile(existing: string | null, target: HostTarget, force: boolean): Decision {
39
+ const state = inspectManaged(existing);
40
+ if (state === 'absent') return { action: 'created', next: target.content };
41
+ if (existing === target.content) return { action: 'unchanged' };
42
+ if (state === 'unmodified' || force) return { action: 'updated', next: target.content };
43
+ const why = state === 'modified' ? 'edited since install' : 'not written by the kit';
44
+ return { action: 'refused', reason: `${why}; re-run with --force to replace` };
45
+ }
46
+
47
+ export async function applyTarget(
48
+ root: string,
49
+ target: HostTarget,
50
+ opts: { force: boolean; dryRun: boolean },
51
+ ): Promise<ApplyResult> {
52
+ const abs = path.join(root, target.path);
53
+ const existing = await readOrNull(abs);
54
+ const d =
55
+ target.mode === 'block' ? decideBlock(existing, target) : decideFile(existing, target, opts.force);
56
+ if (d.next !== undefined && !opts.dryRun) {
57
+ await fs.mkdir(path.dirname(abs), { recursive: true });
58
+ await fs.writeFile(abs, d.next, 'utf8');
59
+ }
60
+ return { path: abs, action: d.action, ...(d.reason ? { reason: d.reason } : {}) };
61
+ }