@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,122 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4
+ import { makeTempDir, type TempDir } from '@agentic-sdlc-kit/testing';
5
+ import { installCommand } from './install.js';
6
+ import { uninstallCommand } from './uninstall.js';
7
+ import type { CommandContext } from './types.js';
8
+
9
+ const ctxFor = (argv: string[], cwd: string): CommandContext => ({
10
+ argv,
11
+ cwd,
12
+ stdout: () => undefined,
13
+ stderr: () => undefined,
14
+ });
15
+
16
+ const exists = (p: string): Promise<boolean> =>
17
+ fs.access(p).then(
18
+ () => true,
19
+ () => false,
20
+ );
21
+
22
+ describe('uninstallCommand', () => {
23
+ let dir: TempDir;
24
+ beforeEach(async () => {
25
+ dir = await makeTempDir('kit-uninstall-');
26
+ await installCommand.run(ctxFor(['--profile', 'full-sdlc', '--dir', dir.path], dir.path));
27
+ });
28
+ afterEach(() => dir.cleanup());
29
+
30
+ it('removes unchanged installed files and the manifest', async () => {
31
+ const r = await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
32
+ expect(r.exitCode).toBe(0);
33
+ expect(await exists(path.join(dir.path, 'docs/specifications/.gitkeep'))).toBe(false);
34
+ expect(await exists(path.join(dir.path, '.ai-kit/ownership-manifest.json'))).toBe(false);
35
+ });
36
+
37
+ it('keeps a file the user edited after install', async () => {
38
+ const yml = path.join(dir.path, '.ai-kit/project.yml');
39
+ await fs.appendFile(yml, 'name: mine\n');
40
+ await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
41
+ expect(await exists(yml)).toBe(true);
42
+ });
43
+
44
+ it('removes nothing on --dry-run', async () => {
45
+ await uninstallCommand.run(ctxFor(['--dry-run', '--dir', dir.path], dir.path));
46
+ expect(await exists(path.join(dir.path, '.ai-kit/ownership-manifest.json'))).toBe(true);
47
+ });
48
+
49
+ it('still owns first-install files after a second install', async () => {
50
+ await installCommand.run(ctxFor(['--profile', 'full-sdlc', '--dir', dir.path], dir.path));
51
+ await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
52
+ expect(await exists(path.join(dir.path, 'docs/specifications/.gitkeep'))).toBe(false);
53
+ });
54
+
55
+ it('fails when there is no manifest', async () => {
56
+ const empty = await makeTempDir('kit-uninstall-empty-');
57
+ const r = await uninstallCommand.run(ctxFor(['--dir', empty.path], empty.path));
58
+ await empty.cleanup();
59
+ expect(r.exitCode).toBe(1);
60
+ });
61
+
62
+ describe('ownership integrity', () => {
63
+ const manifestPath = (): string => path.join(dir.path, '.ai-kit/ownership-manifest.json');
64
+ const readManifest = async (): Promise<{ entries: Array<Record<string, unknown>> }> =>
65
+ JSON.parse(await fs.readFile(manifestPath(), 'utf8'));
66
+ const writeManifest = (m: unknown): Promise<void> =>
67
+ fs.writeFile(manifestPath(), JSON.stringify(m, null, 2));
68
+ const pluginLink = (): string => path.join(dir.path, '.claude/plugins/sdlc-guard');
69
+
70
+ it('removes the kit-created plugin links (the link, never its target)', async () => {
71
+ const target = await fs.realpath(pluginLink());
72
+ await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
73
+ expect(await exists(pluginLink())).toBe(false);
74
+ expect(await exists(path.join(target, '.claude-plugin/plugin.json'))).toBe(true);
75
+ });
76
+
77
+ it('keeps a recorded link the user has since re-pointed elsewhere', async () => {
78
+ const mine = await makeTempDir('kit-mine-');
79
+ await fs.rm(pluginLink());
80
+ await fs.symlink(mine.path, pluginLink(), 'dir');
81
+ const r = await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
82
+ expect(r.exitCode).toBe(0);
83
+ expect(await fs.readlink(pluginLink())).toBe(mine.path);
84
+ await mine.cleanup();
85
+ });
86
+
87
+ it('keeps a real directory at a recorded path and still removes the rest (no crash)', async () => {
88
+ await fs.rm(pluginLink());
89
+ await fs.mkdir(pluginLink());
90
+ await fs.writeFile(path.join(pluginLink(), 'mine.txt'), 'user data');
91
+ const r = await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
92
+ expect(r.exitCode).toBe(0);
93
+ expect(await exists(path.join(pluginLink(), 'mine.txt'))).toBe(true);
94
+ expect(await exists(path.join(dir.path, 'docs/specifications/.gitkeep'))).toBe(false);
95
+ expect(await exists(manifestPath())).toBe(false);
96
+ });
97
+
98
+ it('never deletes outside the root, even if the manifest says so', async () => {
99
+ const outside = await makeTempDir('kit-outside-');
100
+ const victim = path.join(outside.path, 'victim.txt');
101
+ await fs.writeFile(victim, 'precious');
102
+ const m = await readManifest();
103
+ m.entries.push({
104
+ ...m.entries[0]!,
105
+ path: path.relative(dir.path, victim),
106
+ sha256: (await import('node:crypto')).createHash('sha256').update('precious').digest('hex'),
107
+ });
108
+ await writeManifest(m);
109
+ await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
110
+ expect(await exists(victim)).toBe(true);
111
+ await outside.cleanup();
112
+ });
113
+
114
+ it('still removes a legacy link entry (no recorded target) that points at the kit plugin', async () => {
115
+ const m = await readManifest();
116
+ for (const e of m.entries) delete e['target'];
117
+ await writeManifest(m);
118
+ await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
119
+ expect(await exists(pluginLink())).toBe(false);
120
+ });
121
+ });
122
+ });
@@ -0,0 +1,116 @@
1
+ // packages/cli/src/commands/uninstall.ts
2
+ //
3
+ // `kit uninstall [--dir <path>] [--dry-run] [--json]`. Removes only what
4
+ // `kit install` recorded in the ownership manifest: files whose content is
5
+ // unchanged since install, and plugin symlinks (the link, never its target).
6
+ // Files the user edited or that were never ours are kept and reported.
7
+
8
+ import crypto from 'node:crypto';
9
+ import { promises as fs } from 'node:fs';
10
+ import path from 'node:path';
11
+ import { OwnershipManifestSchema, type OwnershipEntry } from '@agentic-sdlc-kit/contracts';
12
+ import { linkTarget } from './plugin-linker.js';
13
+ import type { Command, CommandContext, CommandResult } from './types.js';
14
+
15
+ const MANIFEST_PATH = '.ai-kit/ownership-manifest.json';
16
+
17
+ type Verdict = 'remove' | 'keep-modified' | 'keep-foreign' | 'missing';
18
+
19
+ const sha256 = (text: string): string => crypto.createHash('sha256').update(text, 'utf8').digest('hex');
20
+
21
+ /** True only when `full` stays inside `root` (a manifest must never reach outside it). */
22
+ function isInside(root: string, full: string): boolean {
23
+ const rel = path.relative(root, full);
24
+ return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
25
+ }
26
+
27
+ /**
28
+ * A recorded link is the kit's only while it still points where the kit
29
+ * pointed it. Entries from before `target` existed are verified by content:
30
+ * the plugin identity file read through the link must hash to the recorded value.
31
+ */
32
+ async function ownsLink(full: string, entry: OwnershipEntry): Promise<boolean> {
33
+ if (entry.target !== undefined) return (await linkTarget(full)) === entry.target;
34
+ const identity = await fs
35
+ .readFile(path.join(full, '.claude-plugin', 'plugin.json'), 'utf8')
36
+ .catch(() => undefined);
37
+ return identity !== undefined && sha256(identity) === entry.sha256;
38
+ }
39
+
40
+ async function judge(root: string, entry: OwnershipEntry): Promise<Verdict> {
41
+ const full = path.resolve(root, entry.path);
42
+ if (!isInside(root, full)) return 'keep-foreign';
43
+ const stat = await fs.lstat(full).catch(() => null);
44
+ if (!stat) return 'missing';
45
+ if (stat.isSymbolicLink()) return (await ownsLink(full, entry)) ? 'remove' : 'keep-foreign';
46
+ if (!stat.isFile()) return 'keep-foreign'; // a real directory is never ours to delete
47
+ const content = await fs.readFile(full, 'utf8');
48
+ return sha256(content) === entry.sha256 ? 'remove' : 'keep-modified';
49
+ }
50
+
51
+ /** One bad entry must not abort the run half-way: anything unjudgeable is kept. */
52
+ async function safeJudge(root: string, entry: OwnershipEntry): Promise<Verdict> {
53
+ try {
54
+ return await judge(root, entry);
55
+ } catch {
56
+ return 'keep-foreign';
57
+ }
58
+ }
59
+
60
+ async function readManifest(root: string): Promise<OwnershipEntry[] | undefined> {
61
+ const raw = await fs.readFile(path.join(root, MANIFEST_PATH), 'utf8').catch(() => undefined);
62
+ if (raw === undefined) return undefined;
63
+ return OwnershipManifestSchema.parse(JSON.parse(raw)).entries;
64
+ }
65
+
66
+ export const uninstallCommand: Command = {
67
+ name: 'uninstall',
68
+ summary: 'Remove files and plugin links that kit install created and you have not edited.',
69
+ async run(ctx: CommandContext): Promise<CommandResult> {
70
+ const dryRun = ctx.argv.includes('--dry-run');
71
+ const dirIdx = ctx.argv.indexOf('--dir');
72
+ const dirArg = dirIdx !== -1 ? ctx.argv[dirIdx + 1] : undefined;
73
+ if (dirIdx !== -1 && (!dirArg || dirArg.startsWith('-'))) {
74
+ ctx.stderr('kit uninstall: --dir requires a directory path\n');
75
+ return { exitCode: 1, message: 'missing --dir value' };
76
+ }
77
+ const root = path.resolve(ctx.cwd, dirArg ?? '.');
78
+
79
+ let entries: OwnershipEntry[] | undefined;
80
+ try {
81
+ entries = await readManifest(root);
82
+ } catch (err) {
83
+ ctx.stderr(`kit uninstall: unreadable ownership manifest in ${root}: ${String(err)}\n`);
84
+ return { exitCode: 1, message: 'invalid ownership manifest' };
85
+ }
86
+ if (!entries) {
87
+ ctx.stderr(`kit uninstall: no ${MANIFEST_PATH} in ${root}; nothing owned to remove\n`);
88
+ return { exitCode: 1, message: 'no ownership manifest' };
89
+ }
90
+
91
+ const removed: string[] = [];
92
+ const kept: string[] = [];
93
+ const foreign: string[] = [];
94
+ for (const entry of entries) {
95
+ const verdict = await safeJudge(root, entry);
96
+ if (verdict === 'keep-modified') kept.push(entry.path);
97
+ if (verdict === 'keep-foreign') foreign.push(entry.path);
98
+ if (verdict !== 'remove') continue;
99
+ if (!dryRun) await fs.rm(path.resolve(root, entry.path), { force: true });
100
+ removed.push(entry.path);
101
+ }
102
+ if (!dryRun) await fs.rm(path.join(root, MANIFEST_PATH), { force: true });
103
+
104
+ const label = dryRun ? 'would remove' : 'removed';
105
+ ctx.stdout(
106
+ [
107
+ `kit uninstall${dryRun ? ' --dry-run' : ''}`,
108
+ ...removed.map((p) => ` ${label} ${p}`),
109
+ ...kept.map((p) => ` kept (edited since install) ${p}`),
110
+ ...foreign.map((p) => ` kept (not a file or link the kit created) ${p}`),
111
+ '',
112
+ ].join('\n'),
113
+ );
114
+ return { exitCode: 0 };
115
+ },
116
+ };
@@ -69,6 +69,89 @@ describe('verifyCommand', () => {
69
69
  }
70
70
  });
71
71
 
72
+ it('records the last verification report under the state directory', async () => {
73
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-record-'));
74
+ try {
75
+ await fs.mkdir(path.join(tmp, '.ai-kit'), { recursive: true });
76
+ const profile: ProjectProfile = {
77
+ schemaVersion: 1,
78
+ name: 'test-cli-app',
79
+ stack: ['node-typescript'],
80
+ commands: { test: [['node', '-e', 'process.exit(0)']] },
81
+ };
82
+ await fs.writeFile(path.join(tmp, '.ai-kit', 'project.yml'), serializeProfileYaml(profile), 'utf8');
83
+ await verifyCommand.run(makeCtx([], tmp));
84
+ const recorded = JSON.parse(
85
+ await fs.readFile(path.join(tmp, '.ai-kit', 'state', 'last-verify.json'), 'utf8'),
86
+ );
87
+ expect(recorded.status).toBe('passed');
88
+ const events = await fs.readFile(
89
+ path.join(tmp, '.ai-kit', 'state', 'learning', 'events.jsonl'),
90
+ 'utf8',
91
+ );
92
+ const learned = JSON.parse(events.trim().split('\n').at(-1) ?? '{}');
93
+ expect(learned.taskType).toBe('verify');
94
+ expect(learned.outcome).toBe('passed');
95
+ } finally {
96
+ await fs.rm(tmp, { recursive: true, force: true });
97
+ }
98
+ });
99
+
100
+ it('fails verification when a blocking constitution rule is violated (ADR-0023)', async () => {
101
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-rules-'));
102
+ try {
103
+ const aiKitDir = path.join(tmp, '.ai-kit');
104
+ await fs.mkdir(path.join(aiKitDir, 'constitution', 'rules'), { recursive: true });
105
+ const profile: ProjectProfile = {
106
+ schemaVersion: 1,
107
+ name: 'test-cli-app',
108
+ stack: ['node-typescript'],
109
+ commands: { test: [['node', '-e', 'process.exit(0)']] },
110
+ };
111
+ await fs.writeFile(path.join(aiKitDir, 'project.yml'), serializeProfileYaml(profile), 'utf8');
112
+ await fs.writeFile(
113
+ path.join(aiKitDir, 'constitution', 'rules', 'ARCH-CORE-001.yml'),
114
+ [
115
+ 'schemaVersion: 1',
116
+ 'id: ARCH-CORE-001',
117
+ 'title: t',
118
+ 'statement: s',
119
+ 'rationale: r',
120
+ 'scope:',
121
+ ' paths:',
122
+ ' - "packages/core/src/**/*.ts"',
123
+ 'status: active',
124
+ 'mode: blocking',
125
+ 'check:',
126
+ ' kind: import-boundary',
127
+ ' from: "@agentic-sdlc-kit/"',
128
+ ' allow:',
129
+ ' - "@agentic-sdlc-kit/contracts"',
130
+ 'source: declared',
131
+ 'confidence: 1',
132
+ 'owner: architecture',
133
+ '',
134
+ ].join('\n'),
135
+ );
136
+ await fs.mkdir(path.join(tmp, 'packages', 'core', 'src'), { recursive: true });
137
+ const source = await fs.readFile(
138
+ new URL('../../../core/src/constitution/fixtures/core-imports-cli.txt', import.meta.url),
139
+ 'utf8',
140
+ );
141
+ await fs.writeFile(path.join(tmp, 'packages', 'core', 'src', 'a.ts'), source, 'utf8');
142
+
143
+ const ctx = makeCtx([], tmp);
144
+ const r = await verifyCommand.run(ctx);
145
+ expect(r.exitCode).toBe(1);
146
+ const text = ctx.out.join('');
147
+ expect(text).toContain('Status: FAILED');
148
+ expect(text).toContain('constitution');
149
+ expect(text).toContain('packages/core/src/a.ts:1');
150
+ } finally {
151
+ await fs.rm(tmp, { recursive: true, force: true });
152
+ }
153
+ });
154
+
72
155
  it('surfaces schema issues when the profile fails validation (no bare error)', async () => {
73
156
  const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-schema-'));
74
157
  try {
@@ -115,3 +198,35 @@ describe('verifyCommand', () => {
115
198
  }
116
199
  });
117
200
  });
201
+
202
+ describe('verifyCommand --strength (ADR-0022)', () => {
203
+ it('fails closed with an honest error for a stack without a mutation adapter', async () => {
204
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-strength-'));
205
+ try {
206
+ const aiKitDir = path.join(tmp, '.ai-kit');
207
+ await fs.mkdir(aiKitDir, { recursive: true });
208
+ const profile: ProjectProfile = {
209
+ schemaVersion: 1,
210
+ name: 'strength-cli-app',
211
+ stack: ['cobol'], // no adapter — must fail honestly, never silently skip
212
+ commands: { test: [['node', '-e', 'process.exit(0)']] },
213
+ };
214
+ await fs.writeFile(path.join(aiKitDir, 'project.yml'), serializeProfileYaml(profile), 'utf8');
215
+
216
+ const ctx = makeCtx(['--strength'], tmp);
217
+ const r = await verifyCommand.run(ctx);
218
+ expect(r.exitCode).toBe(1);
219
+ expect(ctx.err[0]).toContain('not supported');
220
+ expect(ctx.err[0]).toContain('cobol');
221
+ } finally {
222
+ await fs.rm(tmp, { recursive: true, force: true });
223
+ }
224
+ });
225
+
226
+ it('mentions --strength in help output', async () => {
227
+ const ctx = makeCtx(['--help'], '/');
228
+ await verifyCommand.run(ctx);
229
+ expect(ctx.out[0]).toContain('--strength');
230
+ expect(ctx.out[0]).toContain('ADR-0022');
231
+ });
232
+ });
@@ -1,13 +1,30 @@
1
1
  // packages/cli/src/commands/verify.ts
2
2
  //
3
- // `kit verify [path] [--dry-run] [--json]`.
3
+ // `kit verify [path] [--dry-run] [--json] [--strength]`.
4
4
  // Deterministic verification runner executing configured test, lint, and typecheck commands.
5
+ // `--strength` additionally runs the optional mutation-score stage (ADR-0022).
5
6
 
6
7
  import { promises as fs } from 'node:fs';
7
8
  import path from 'node:path';
8
- import { parseProfileYaml, ProcessVerificationRunner } from '@agentic-sdlc-kit/core';
9
- import type { VerificationReport } from '@agentic-sdlc-kit/contracts';
9
+ import {
10
+ applyConstitution,
11
+ evaluateConstitution,
12
+ parseProfileYaml,
13
+ ProcessVerificationRunner,
14
+ appendLearningEvent,
15
+ learningEventFromReport,
16
+ recordLastVerify,
17
+ runStrengthCheck,
18
+ } from '@agentic-sdlc-kit/core';
19
+ import {
20
+ DEFAULT_STRENGTH_SETTINGS,
21
+ evaluateStrengthGate,
22
+ type StrengthEvidence,
23
+ type VerificationReport,
24
+ } from '@agentic-sdlc-kit/contracts';
10
25
  import type { Command, CommandContext, CommandResult } from './types.js';
26
+ import { constitutionAdapters } from '../application/rule-adapters/index.js';
27
+ import { formatRuleResultLine, formatViolationLines } from './rules-format.js';
11
28
 
12
29
  export const verifyCommand: Command = {
13
30
  name: 'verify',
@@ -20,6 +37,7 @@ export const verifyCommand: Command = {
20
37
 
21
38
  const isJson = ctx.argv.includes('--json');
22
39
  const isDryRun = ctx.argv.includes('--dry-run');
40
+ const withStrength = ctx.argv.includes('--strength');
23
41
  const targetArg = ctx.argv.find((a) => !a.startsWith('-'));
24
42
  const targetRoot = path.resolve(ctx.cwd, targetArg ?? '.');
25
43
  const profilePath = path.join(targetRoot, '.ai-kit', 'project.yml');
@@ -60,14 +78,62 @@ export const verifyCommand: Command = {
60
78
  return { exitCode: 1, message: repRes.error.message };
61
79
  }
62
80
 
63
- const report = repRes.value;
81
+ // ADR-0023: the constitution is one more check, plus per-rule detail.
82
+ // A project with no .ai-kit/constitution/rules is unaffected.
83
+ const constitution = await evaluateConstitution({
84
+ projectRoot: targetRoot,
85
+ stacks: profileRes.value.stack,
86
+ adapters: constitutionAdapters(),
87
+ });
88
+ const report = applyConstitution(repRes.value, constitution);
89
+ // The last report is evidence for context and status tools. Failing to
90
+ // record it is a warning: it must not change the verdict of this run.
91
+ const recorded = await recordLastVerify(targetRoot, report);
92
+ if (!recorded.ok) ctx.stderr(`kit verify: warning: ${recorded.error.message}\n`);
93
+ // The same run, as a privacy-safe learning event (ADR-0025 / roadmap Phase 6). Non-fatal.
94
+ const learned = await appendLearningEvent(
95
+ targetRoot,
96
+ learningEventFromReport(report, profileRes.value.stack, new Date()),
97
+ );
98
+ if (!learned.ok) ctx.stderr(`kit verify: warning: ${learned.error.message}\n`);
99
+
100
+ // Optional strength stage (ADR-0022): `--strength` runs the mutation
101
+ // tool under the profile's budget. Disabled-by-default stays honest —
102
+ // the flag also honors an explicit profile `enabled: true` run.
103
+ let strength: StrengthEvidence | undefined;
104
+ let strengthBlocked = false;
105
+ if (withStrength) {
106
+ const settings = profileRes.value.verification?.strength ?? {
107
+ ...DEFAULT_STRENGTH_SETTINGS,
108
+ enabled: true, // explicit flag is the opt-in
109
+ };
110
+ const strengthRes = await runStrengthCheck({
111
+ cwd: targetRoot,
112
+ stack: profileRes.value.stack[0] ?? '',
113
+ settings: { ...settings, enabled: true },
114
+ scopeFiles: [],
115
+ });
116
+ if (!strengthRes.ok) {
117
+ ctx.stderr(`kit verify --strength: ${strengthRes.error.message}\n`);
118
+ return { exitCode: 1, message: strengthRes.error.message };
119
+ }
120
+ strength = strengthRes.value;
121
+ strengthBlocked = evaluateStrengthGate(strength, settings.gateMode).block;
122
+ }
123
+
64
124
  if (isJson) {
65
- ctx.stdout(JSON.stringify(report, null, 2) + '\n');
125
+ const reportJson: Record<string, unknown> = { ...report };
126
+ if (strength !== undefined) {
127
+ reportJson['strength'] = strength;
128
+ }
129
+ ctx.stdout(JSON.stringify(reportJson, null, 2) + '\n');
66
130
  } else {
67
131
  ctx.stdout(formatReportSummary(report));
132
+ if (strength !== undefined) ctx.stdout(formatStrengthSummary(strength));
68
133
  }
69
134
 
70
- return { exitCode: report.status === 'passed' ? 0 : 1 };
135
+ const exitCode = report.status === 'passed' && !strengthBlocked ? 0 : 1;
136
+ return { exitCode };
71
137
  },
72
138
  };
73
139
 
@@ -82,6 +148,13 @@ function formatReportSummary(report: VerificationReport): string {
82
148
  const cmdStr = c.command ? ` [${c.command.join(' ')}]` : '';
83
149
  lines.push(` - ${c.id.padEnd(12)} ${c.status.toUpperCase()}${dur}${cmdStr}`);
84
150
  }
151
+ if (report.rules && report.rules.length > 0) {
152
+ lines.push('Rules:');
153
+ for (const r of report.rules) {
154
+ lines.push(formatRuleResultLine(r));
155
+ lines.push(...formatViolationLines(r));
156
+ }
157
+ }
85
158
  if (report.checks.length === 0) {
86
159
  // Zero checks usually means the profile's commands were not parsed.
87
160
  // Surface the likely cause instead of a bare BLOCKED.
@@ -96,9 +169,21 @@ function formatReportSummary(report: VerificationReport): string {
96
169
  return lines.join('\n') + '\n';
97
170
  }
98
171
 
172
+ function formatStrengthSummary(strength: StrengthEvidence): string {
173
+ const score = strength.score !== undefined ? `${strength.score}%` : 'n/a';
174
+ const lines: string[] = [
175
+ `Strength: ${strength.status.toUpperCase()} (score ${score} vs threshold ${strength.threshold}%)`,
176
+ ` tool=${strength.tool} scope=${strength.scope} mutants=${strength.mutantsKilled}/${strength.mutantsGenerated} killed`,
177
+ ` budget=${strength.budgetMs}ms duration=${strength.durationMs}ms`,
178
+ ` ${strength.summary}`,
179
+ '',
180
+ ];
181
+ return lines.join('\n') + '\n';
182
+ }
183
+
99
184
  function formatHelp(): string {
100
185
  return [
101
- 'Usage: kit verify [path] [--dry-run] [--json]',
186
+ 'Usage: kit verify [path] [--dry-run] [--json] [--strength]',
102
187
  '',
103
188
  'Execute deterministic verification checks configured in .ai-kit/project.yml.',
104
189
  'Commands run with shell: false and bounded timeouts.',
@@ -106,6 +191,9 @@ function formatHelp(): string {
106
191
  'Options:',
107
192
  ' --dry-run Mark checks as skipped without executing processes',
108
193
  ' --json Output full machine-readable VerificationReport',
194
+ ' --strength Additionally run the mutation-score stage (ADR-0022);',
195
+ ' budgeted by verification.strength.budgetMs; exit 1 when',
196
+ ' gateMode enforce and below threshold',
109
197
  ' --help Show this message',
110
198
  '',
111
199
  ].join('\n');
@@ -1,6 +1,8 @@
1
1
  // packages/cli/src/commands/version.test.ts
2
+ import { createRequire } from 'node:module';
2
3
  import { describe, expect, it } from 'vitest';
3
4
  import { versionCommand } from './version.js';
5
+ import { VERSION } from '../application/version.js';
4
6
 
5
7
  describe('versionCommand', () => {
6
8
  it('returns the version with exit code 0', () => {
@@ -8,4 +10,11 @@ describe('versionCommand', () => {
8
10
  expect(r.exitCode).toBe(0);
9
11
  expect(r.message).toMatch(/^\d+\.\d+\.\d+$/);
10
12
  });
13
+
14
+ it('never drifts from the package.json version', () => {
15
+ // Regression pin for the M1 hard-code drift (#88): the CLI must always
16
+ // report whatever version package.json carries.
17
+ const pkg = createRequire(import.meta.url)('../../package.json') as { version: string };
18
+ expect(VERSION).toBe(pkg.version);
19
+ });
11
20
  });