@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,95 @@
1
+ // packages/cli/src/application/bench/harness.ts
2
+ //
3
+ // Runs one benchmark suite (roadmap Phase 5). For each task: a disposable git worktree at the pinned
4
+ // commit, the suite's runner under the task budget, then the task's acceptance commands in order.
5
+ // The worktree is removed afterwards, whatever happened. Commands are argv arrays, never a shell.
6
+ //
7
+ // Trust: the runner and the acceptance commands execute code from the repository under test, the
8
+ // same trust `kit verify` extends to a project's own commands. The worktree isolates the working
9
+ // tree, not the process: this runner does not provide a sandbox, and the docs say so.
10
+
11
+ import { promises as fs } from 'node:fs';
12
+ import os from 'node:os';
13
+ import path from 'node:path';
14
+ import {
15
+ classifyRun,
16
+ runToSettlement,
17
+ summarise,
18
+ type LoadedSuite,
19
+ type RunFacts,
20
+ } from '@agentic-sdlc-kit/core';
21
+ import type { BenchReport, BenchRun, BenchTask } from '@agentic-sdlc-kit/contracts';
22
+
23
+ const GIT_TIMEOUT_MS = 120_000;
24
+ const MAX_OUTPUT = 4 * 1024 * 1024;
25
+
26
+ async function runGit(repo: string, args: readonly string[]): Promise<boolean> {
27
+ const run = await runToSettlement('git', args, repo, GIT_TIMEOUT_MS, MAX_OUTPUT);
28
+ return run.spawnError === undefined && !run.timedOut && run.exitCode === 0;
29
+ }
30
+
31
+ async function runAcceptance(
32
+ task: BenchTask,
33
+ worktree: string,
34
+ timeoutMs: number,
35
+ ): Promise<RunFacts['acceptance']> {
36
+ for (const argv of task.acceptance) {
37
+ const [file = '', ...args] = argv;
38
+ const run = await runToSettlement(file, args, worktree, timeoutMs, MAX_OUTPUT);
39
+ if (run.spawnError !== undefined) return { spawnError: true, allPassed: false, failedCheck: argv.join(' ') };
40
+ if (run.timedOut || run.exitCode !== 0) return { spawnError: false, allPassed: false, failedCheck: argv.join(' ') };
41
+ }
42
+ return { spawnError: false, allPassed: true, failedCheck: null };
43
+ }
44
+
45
+ async function runOne(loaded: LoadedSuite, task: BenchTask): Promise<BenchRun> {
46
+ const started = Date.now();
47
+ const repo = path.resolve(loaded.dir, task.repository);
48
+ const scratch = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-bench-'));
49
+ const worktree = path.join(scratch, 'wt');
50
+ try {
51
+ const worktreeOk = await runGit(repo, ['worktree', 'add', '--detach', worktree, task.commit]);
52
+ if (!worktreeOk) {
53
+ const facts: RunFacts = {
54
+ worktreeOk: false,
55
+ runner: { spawnError: false, timedOut: false, exitCode: null },
56
+ acceptance: { spawnError: false, allPassed: false, failedCheck: null },
57
+ };
58
+ return finish(task, classifyRun(facts), Date.now() - started);
59
+ }
60
+ const budget = Math.min(task.budget.timeoutMs, loaded.suite.runner.timeoutMs);
61
+ const [file = '', ...args] = loaded.suite.runner.argv;
62
+ const runner = await runToSettlement(file, args, worktree, budget, MAX_OUTPUT);
63
+ const acceptance = runner.spawnError !== undefined || runner.timedOut || runner.exitCode !== 0
64
+ ? { spawnError: false, allPassed: false, failedCheck: null }
65
+ : await runAcceptance(task, worktree, budget);
66
+ const facts: RunFacts = {
67
+ worktreeOk: true,
68
+ runner: { spawnError: runner.spawnError !== undefined, timedOut: runner.timedOut, exitCode: runner.exitCode },
69
+ acceptance,
70
+ };
71
+ return finish(task, classifyRun(facts), Date.now() - started);
72
+ } finally {
73
+ await runGit(repo, ['worktree', 'remove', '--force', worktree]);
74
+ await runGit(repo, ['worktree', 'prune']);
75
+ await fs.rm(scratch, { recursive: true, force: true });
76
+ }
77
+ }
78
+
79
+ function finish(task: BenchTask, verdict: { outcome: BenchRun['outcome']; reason: string }, durationMs: number): BenchRun {
80
+ return { task: task.id, split: task.split, outcome: verdict.outcome, durationMs, reason: verdict.reason };
81
+ }
82
+
83
+ /** Runs every task of a suite, in order. A task's failure never stops the others. */
84
+ export async function runSuite(loaded: LoadedSuite, now: Date): Promise<BenchReport> {
85
+ const runs: BenchRun[] = [];
86
+ for (const task of loaded.tasks) runs.push(await runOne(loaded, task));
87
+ return {
88
+ schemaVersion: 1,
89
+ suite: { name: loaded.suite.name, version: loaded.suite.version },
90
+ generatedAt: now.toISOString(),
91
+ runs,
92
+ tune: summarise(runs.filter((r) => r.split === 'tune')),
93
+ holdout: summarise(runs.filter((r) => r.split === 'holdout')),
94
+ };
95
+ }
@@ -1,6 +1,10 @@
1
1
  // packages/cli/src/application/dispatcher.test.ts
2
+ import { readFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
2
5
  import { describe, expect, it } from 'vitest';
3
6
  import { createDispatcher } from './dispatcher.js';
7
+ import { VERSION } from './version.js';
4
8
  import type { CommandContext } from '../commands/types.js';
5
9
 
6
10
  const makeCtx = (
@@ -24,7 +28,7 @@ describe('dispatcher', () => {
24
28
  const ctx = makeCtx(['--version']);
25
29
  const r = await dispatch(ctx);
26
30
  expect(r.exitCode).toBe(0);
27
- expect(r.message).toBe('0.8.0');
31
+ expect(r.message).toBe(VERSION);
28
32
  expect(r.command).toBe('version');
29
33
  });
30
34
 
@@ -33,7 +37,7 @@ describe('dispatcher', () => {
33
37
  const ctx = makeCtx(['-v']);
34
38
  const r = await dispatch(ctx);
35
39
  expect(r.exitCode).toBe(0);
36
- expect(r.message).toBe('0.8.0');
40
+ expect(r.message).toBe(VERSION);
37
41
  });
38
42
 
39
43
  it('handles --help', async () => {
@@ -74,7 +78,7 @@ describe('dispatcher', () => {
74
78
  const r = await dispatch(ctx);
75
79
  expect(r.exitCode).toBe(0);
76
80
  expect(r.command).toBe('doctor');
77
- expect(ctx.out[0]).toContain('kit 0.8.0');
81
+ expect(ctx.out[0]).toContain(`kit ${VERSION}`);
78
82
  expect(ctx.out[0]).toContain('node');
79
83
  });
80
84
 
@@ -87,3 +91,19 @@ describe('dispatcher', () => {
87
91
  expect(ctx.err[0]).toContain("unknown command 'bogus'");
88
92
  });
89
93
  });
94
+
95
+ // The docs quote the command count in prose; it drifted (16 vs 17 vs the real
96
+ // registry size) because nothing tied them together. This does.
97
+ describe('documented command count', () => {
98
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..', '..');
99
+ it.each([
100
+ ['README.md', /\((\d+) commands\)/],
101
+ ['README.md', /provides (\d+) commands/],
102
+ ['AGENTS.md', /\((\d+) commands\)/],
103
+ ])('%s states the registry size (%s)', (file, re) => {
104
+ const size = createDispatcher().registry.list().length;
105
+ const match = re.exec(readFileSync(path.join(root, file), 'utf8'));
106
+ expect(match, `${file} must state the command count`).not.toBeNull();
107
+ expect(Number(match![1])).toBe(size);
108
+ });
109
+ });
@@ -12,16 +12,28 @@ import { validateSpecCommand } from '../commands/validate-spec.js';
12
12
  import { elicitCommand } from '../commands/elicit.js';
13
13
  import { validatePlanCommand } from '../commands/validate-plan.js';
14
14
  import { verifyCommand } from '../commands/verify.js';
15
+ import { rulesCommand } from '../commands/rules.js';
16
+ import { onboardCommand } from '../commands/onboard.js';
17
+ import { contextCommand } from '../commands/context.js';
18
+ import { learningCommand } from '../commands/learning.js';
19
+ import { benchCommand } from '../commands/bench.js';
20
+ import { routingCommand } from '../commands/routing.js';
21
+ import { knowledgeCommand } from '../commands/knowledge.js';
15
22
  import { featureCommand } from '../commands/feature.js';
16
23
  import { newCommand } from '../commands/new.js';
17
24
  import { fixCommand } from '../commands/fix.js';
18
25
  import { installCommand } from '../commands/install.js';
26
+ import { uninstallCommand } from '../commands/uninstall.js';
19
27
  import { memoryCommand } from '../commands/memory.js';
20
28
  import { evolveCommand } from '../commands/evolve.js';
21
29
  import { refactorCommand } from '../commands/refactor.js';
22
30
  import { optimizeCommand } from '../commands/optimize.js';
23
31
  import { nextCommand } from '../commands/next.js';
32
+ import { mcpCommand } from '../commands/mcp.js';
24
33
  import { journalCommand } from '../commands/journal.js';
34
+ import { skillsCommand } from '../commands/skills.js';
35
+ import { attachCommand } from '../commands/attach.js';
36
+ import { hostCommand } from '../commands/host.js';
25
37
  import type { Command, CommandContext, CommandResult } from '../commands/types.js';
26
38
  import { createCommandRegistry, type CommandRegistry } from './registry.js';
27
39
  import { VERSION } from './version.js';
@@ -48,16 +60,28 @@ export function createDispatcher(opts: DispatcherOptions = {}): {
48
60
  if (!registry.get('elicit')) registry.register(elicitCommand);
49
61
  if (!registry.get('validate-plan')) registry.register(validatePlanCommand);
50
62
  if (!registry.get('verify')) registry.register(verifyCommand);
63
+ if (!registry.get('rules')) registry.register(rulesCommand);
64
+ if (!registry.get('onboard')) registry.register(onboardCommand);
65
+ if (!registry.get('context')) registry.register(contextCommand);
66
+ if (!registry.get('learning')) registry.register(learningCommand);
67
+ if (!registry.get('bench')) registry.register(benchCommand);
68
+ if (!registry.get('routing')) registry.register(routingCommand);
69
+ if (!registry.get('knowledge')) registry.register(knowledgeCommand);
51
70
  if (!registry.get('feature')) registry.register(featureCommand);
52
71
  if (!registry.get('new')) registry.register(newCommand);
53
72
  if (!registry.get('fix')) registry.register(fixCommand);
54
73
  if (!registry.get('install')) registry.register(installCommand);
74
+ if (!registry.get('uninstall')) registry.register(uninstallCommand);
55
75
  if (!registry.get('memory')) registry.register(memoryCommand);
56
76
  if (!registry.get('evolve')) registry.register(evolveCommand);
57
77
  if (!registry.get('refactor')) registry.register(refactorCommand);
58
78
  if (!registry.get('optimize')) registry.register(optimizeCommand);
59
79
  if (!registry.get('next')) registry.register(nextCommand);
60
80
  if (!registry.get('journal')) registry.register(journalCommand);
81
+ if (!registry.get('mcp')) registry.register(mcpCommand);
82
+ if (!registry.get('skills')) registry.register(skillsCommand);
83
+ if (!registry.get('attach')) registry.register(attachCommand);
84
+ if (!registry.get('host')) registry.register(hostCommand);
61
85
  if (!registry.get('help')) registry.register(makeHelpCommand(registry));
62
86
 
63
87
  return {
@@ -0,0 +1,224 @@
1
+ // The process-backed rule adapters (roadmap Phase 4A). Deterministic failure modes use fake
2
+ // binaries placed in the project's node_modules/.bin, which the resolver prefers. Live tests run
3
+ // only where the real tool is installed and say so when they skip.
4
+
5
+ import { execFileSync } from 'node:child_process';
6
+ import { mkdtemp, mkdir, realpath, rm, writeFile, chmod } from 'node:fs/promises';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
9
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
10
+ import type { EngineeringRule } from '@agentic-sdlc-kit/contracts';
11
+ import { astGrepAdapter } from './ast-grep.js';
12
+ import { linterAdapter, sameRule, TOOLS } from './linter.js';
13
+
14
+ const hasTool = (name: string): boolean => {
15
+ try {
16
+ execFileSync(name, ['--version'], { stdio: 'ignore' });
17
+ return true;
18
+ } catch {
19
+ return false;
20
+ }
21
+ };
22
+
23
+ let root: string;
24
+ let savedPath: string | undefined;
25
+
26
+ beforeEach(async () => {
27
+ // Tools print resolved paths (macOS: /var is a link to /private/var), so the fixture root is
28
+ // resolved too: fake output then matches what a real tool prints from the resolved root.
29
+ root = await realpath(await mkdtemp(path.join(os.tmpdir(), 'kit-adapters-')));
30
+ await mkdir(path.join(root, 'node_modules', '.bin'), { recursive: true });
31
+ await mkdir(path.join(root, 'rules'), { recursive: true });
32
+ await mkdir(path.join(root, 'src'), { recursive: true });
33
+ await writeFile(path.join(root, 'rules', 'no-eval.yml'), 'id: no-eval\nlanguage: TypeScript\nrule:\n pattern: eval($A)\nmessage: m\nseverity: error\n');
34
+ await writeFile(path.join(root, 'src', 'a.ts'), 'const z = 1\nconst y = eval("1")\n');
35
+ savedPath = process.env['PATH'];
36
+ });
37
+ afterEach(async () => {
38
+ process.env['PATH'] = savedPath;
39
+ await rm(root, { recursive: true, force: true });
40
+ });
41
+
42
+ /** A fake executable in the project's node_modules/.bin. Body is a POSIX shell script. */
43
+ async function fakeTool(name: string, body: string): Promise<void> {
44
+ const file = path.join(root, 'node_modules', '.bin', name);
45
+ await writeFile(file, `#!/bin/sh\n${body}\n`);
46
+ await chmod(file, 0o755);
47
+ }
48
+
49
+ function astRule(ruleFile = 'rules/no-eval.yml'): EngineeringRule {
50
+ return {
51
+ schemaVersion: 1, id: 'AST-EVAL-001', title: 't', statement: 's', rationale: 'r',
52
+ scope: { stacks: [], paths: ['src/**/*.ts'], exclude: [] },
53
+ status: 'active', mode: 'blocking', check: { kind: 'ast-grep', ruleFile },
54
+ source: 'human', confidence: 1, evidence: [], owner: 'o', supersedes: [],
55
+ } as EngineeringRule;
56
+ }
57
+
58
+ function lintRule(tool: string, ruleId: string): EngineeringRule {
59
+ return { ...astRule(), id: 'LINT-EVAL-001', check: { kind: 'linter', tool, ruleId } } as unknown as EngineeringRule;
60
+ }
61
+
62
+ const req = (rule: EngineeringRule, timeoutMs = 30_000) => ({
63
+ projectRoot: root, rule, files: ['src/a.ts'], timeoutMs, maxOutputBytes: 1_000_000,
64
+ });
65
+
66
+ describe('ast-grep adapter', () => {
67
+ it('refuses the sg binary: a different tool with the same name is unavailable, not clean', async () => {
68
+ await fakeTool('ast-grep', 'echo "usage: sg group [[-c] command]"');
69
+ const out = await astGrepAdapter.run(req(astRule()));
70
+ expect(out.ok).toBe(false);
71
+ if (!out.ok) {
72
+ expect(out.outcome).toBe('adapter-unavailable');
73
+ expect(out.detail).toContain('not ast-grep');
74
+ }
75
+ });
76
+
77
+ it('turns matches into violations with a 1-based line and a fingerprint', async () => {
78
+ await fakeTool(
79
+ 'ast-grep',
80
+ `case "$1" in --version) echo "ast-grep 0.51.2";; scan) echo '[{"file":"src/a.ts","text":"eval(\\"1\\")","message":"eval is forbidden","range":{"start":{"line":1,"column":10}}}]';; esac`,
81
+ );
82
+ const out = await astGrepAdapter.run(req(astRule()));
83
+ expect(out.ok).toBe(true);
84
+ if (out.ok) {
85
+ expect(out.violations).toHaveLength(1);
86
+ expect(out.violations[0]).toMatchObject({ ruleId: 'AST-EVAL-001', path: 'src/a.ts', line: 2 });
87
+ expect(out.violations[0]?.fingerprint).toMatch(/^[0-9a-f]{64}$/);
88
+ }
89
+ });
90
+
91
+ it('an empty match list is a clean run', async () => {
92
+ await fakeTool('ast-grep', 'case "$1" in --version) echo "ast-grep 0.51.2";; scan) echo "[]";; esac');
93
+ const out = await astGrepAdapter.run(req(astRule()));
94
+ expect(out).toEqual({ ok: true, violations: [] });
95
+ });
96
+
97
+ it('output that is not a match list is an error, never zero violations', async () => {
98
+ await fakeTool('ast-grep', 'case "$1" in --version) echo "ast-grep 0.51.2";; scan) echo "garbage";; esac');
99
+ const out = await astGrepAdapter.run(req(astRule()));
100
+ expect(out.ok).toBe(false);
101
+ if (!out.ok) expect(out.outcome).toBe('adapter-error');
102
+ });
103
+
104
+ it('an unexpected exit status is an error', async () => {
105
+ await fakeTool('ast-grep', 'case "$1" in --version) echo "ast-grep 0.51.2";; scan) echo "bad rule" >&2; exit 8;; esac');
106
+ const out = await astGrepAdapter.run(req(astRule()));
107
+ expect(out.ok).toBe(false);
108
+ if (!out.ok) expect(out.outcome).toBe('adapter-error');
109
+ });
110
+
111
+ it('a scan that outlives its timeout is timed-out', async () => {
112
+ await fakeTool('ast-grep', 'case "$1" in --version) echo "ast-grep 0.51.2";; scan) sleep 30;; esac');
113
+ const out = await astGrepAdapter.run(req(astRule(), 500));
114
+ expect(out.ok).toBe(false);
115
+ if (!out.ok) expect(out.outcome).toBe('timed-out');
116
+ });
117
+
118
+ it('a missing binary is unavailable', async () => {
119
+ process.env['PATH'] = '';
120
+ const out = await astGrepAdapter.run(req(astRule()));
121
+ expect(out.ok).toBe(false);
122
+ if (!out.ok) expect(out.outcome).toBe('adapter-unavailable');
123
+ });
124
+
125
+ it('a rule file outside the project is refused even if the contract was bypassed', async () => {
126
+ const out = await astGrepAdapter.run(req(astRule('../outside.yml')));
127
+ expect(out.ok).toBe(false);
128
+ if (!out.ok) expect(out.outcome).toBe('adapter-error');
129
+ });
130
+
131
+ it.skipIf(!hasTool('ast-grep'))('live: the real ast-grep finds the eval (skipped when ast-grep is not installed)', async () => {
132
+ const out = await astGrepAdapter.run(req(astRule()));
133
+ expect(out.ok).toBe(true);
134
+ if (out.ok) expect(out.violations.map((v) => v.line)).toEqual([2]);
135
+ });
136
+ });
137
+
138
+ describe('linter adapter', () => {
139
+ it('a tool outside the registry is unavailable', async () => {
140
+ const out = await linterAdapter.run(req(lintRule('curl', 'x')));
141
+ expect(out.ok).toBe(false);
142
+ if (!out.ok) expect(out.outcome).toBe('adapter-unavailable');
143
+ });
144
+
145
+ it('a missing linter binary is unavailable', async () => {
146
+ process.env['PATH'] = '';
147
+ const out = await linterAdapter.run(req(lintRule('eslint', 'no-eval')));
148
+ expect(out.ok).toBe(false);
149
+ if (!out.ok) expect(out.outcome).toBe('adapter-unavailable');
150
+ });
151
+
152
+ it('non-JSON linter output is an error, never zero findings', async () => {
153
+ await fakeTool('eslint', 'echo "Oops: config error"; exit 2');
154
+ const out = await linterAdapter.run(req(lintRule('eslint', 'no-eval')));
155
+ expect(out.ok).toBe(false);
156
+ if (!out.ok) expect(out.outcome).toBe('adapter-error');
157
+ });
158
+
159
+ it('keeps only findings for the rule id, inside the rule files', async () => {
160
+ const json = JSON.stringify([
161
+ { filePath: path.join(root, 'src', 'a.ts'), messages: [{ ruleId: 'no-eval', line: 2, message: 'eval', severity: 2 }, { ruleId: 'no-var', line: 1, message: 'var', severity: 2 }] },
162
+ { filePath: path.join(root, 'src', 'other.ts'), messages: [{ ruleId: 'no-eval', line: 1, message: 'eval', severity: 2 }] },
163
+ ]);
164
+ await fakeTool('eslint', `echo '${json}'; exit 1`);
165
+ const out = await linterAdapter.run(req(lintRule('eslint', 'no-eval')));
166
+ expect(out.ok).toBe(true);
167
+ if (out.ok) expect(out.violations.map((v) => v.path)).toEqual(['src/a.ts']);
168
+ });
169
+
170
+ it('a namespaced finding matches the unscoped rule id (no silent miss)', async () => {
171
+ const json = JSON.stringify([
172
+ { filePath: path.join(root, 'src', 'a.ts'), messages: [{ ruleId: '@typescript-eslint/no-unused-vars', line: 1, message: 'unused' }] },
173
+ ]);
174
+ await fakeTool('eslint', `echo '${json}'; exit 1`);
175
+ const out = await linterAdapter.run(req(lintRule('eslint', 'no-unused-vars')));
176
+ expect(out.ok && out.violations.map((v) => v.line)).toEqual([1]);
177
+ });
178
+
179
+ it('sameRule: exact, unscoped and different rules', () => {
180
+ expect(sameRule('no-eval', 'no-eval')).toBe(true);
181
+ expect(sameRule('@typescript-eslint/no-unused-vars', 'no-unused-vars')).toBe(true);
182
+ expect(sameRule('no-unused-vars', '@typescript-eslint/no-unused-vars')).toBe(true);
183
+ expect(sameRule('no-unused-expressions', 'no-unused-vars')).toBe(false);
184
+ });
185
+
186
+ it.skipIf(!hasTool('eslint'))('live: the real ESLint reports no-eval (skipped when eslint is not installed)', async () => {
187
+ await writeFile(path.join(root, 'eslint.config.mjs'), "export default [{ files: ['**/*.ts'], rules: { 'no-eval': 'error' } }];\n");
188
+ process.env['PATH'] = savedPath;
189
+ const out = await linterAdapter.run(req(lintRule('eslint', 'no-eval')));
190
+ expect(out.ok).toBe(true);
191
+ if (out.ok) expect(out.violations.map((v) => v.line)).toEqual([2]);
192
+ });
193
+ });
194
+
195
+ describe('recorded fixtures for linters not installed here', () => {
196
+ it('ruff: parses its JSON array and keeps the code', () => {
197
+ const parsed = TOOLS['ruff']!.parse(
198
+ [{ code: 'S307', filename: path.join(root, 'src', 'a.py'), location: { row: 3, column: 1 }, message: 'eval' }],
199
+ root,
200
+ );
201
+ expect(parsed).toEqual([{ file: 'src/a.py', code: 'S307', line: 3, message: 'eval' }]);
202
+ });
203
+
204
+ it('rubocop: parses files, offenses and cop names', () => {
205
+ const parsed = TOOLS['rubocop']!.parse(
206
+ { files: [{ path: path.join(root, 'app', 'x.rb'), offenses: [{ cop_name: 'Style/Eval', message: 'no eval', location: { line: 7 } }] }] },
207
+ root,
208
+ );
209
+ expect(parsed).toEqual([{ file: 'app/x.rb', code: 'Style/Eval', line: 7, message: 'no eval' }]);
210
+ });
211
+
212
+ it('golangci-lint: parses issues by linter name', () => {
213
+ const parsed = TOOLS['golangci-lint']!.parse(
214
+ { Issues: [{ FromLinter: 'gosec', Text: 'G204', Pos: { Filename: 'cmd/x.go', Line: 9 } }] },
215
+ root,
216
+ );
217
+ expect(parsed).toEqual([{ file: 'cmd/x.go', code: 'gosec', line: 9, message: 'G204' }]);
218
+ });
219
+
220
+ it('a linter JSON with an unexpected shape is rejected, not read as clean', () => {
221
+ expect(TOOLS['ruff']!.parse({ not: 'an array' }, root)).toBeNull();
222
+ expect(TOOLS['rubocop']!.parse({ files: 'x' }, root)).toBeNull();
223
+ });
224
+ });
@@ -0,0 +1,126 @@
1
+ // packages/cli/src/application/rule-adapters/ast-grep.ts
2
+ //
3
+ // The ast-grep adapter (ADR-0023 §5, roadmap Phase 4A). It runs a repository-local ast-grep rule
4
+ // file over the rule's files and turns each match into a violation.
5
+ //
6
+ // The binary is `ast-grep`, never `sg`: on many systems `sg` is the group-switch command. The
7
+ // adapter checks the version banner before it trusts the binary.
8
+
9
+ import { promises as fs } from 'node:fs';
10
+ import path from 'node:path';
11
+ import type { RuleViolation } from '@agentic-sdlc-kit/contracts';
12
+ import {
13
+ computeFingerprint,
14
+ failure,
15
+ type AdapterOutput,
16
+ type AdapterRequest,
17
+ type RuleAdapter,
18
+ } from '@agentic-sdlc-kit/core';
19
+ import { CHUNK_SIZE, chunks, resolveTool, runTool, tail } from './process.js';
20
+
21
+ const BINARY = 'ast-grep';
22
+ const VERSION_BANNER = /^ast-grep \d+\.\d+\.\d+/;
23
+
24
+ interface AstGrepMatch {
25
+ readonly file: string;
26
+ readonly text: string;
27
+ readonly message: string;
28
+ readonly line: number;
29
+ }
30
+
31
+ function parseMatches(stdout: string): AstGrepMatch[] | null {
32
+ let raw: unknown;
33
+ try {
34
+ raw = JSON.parse(stdout);
35
+ } catch {
36
+ return null;
37
+ }
38
+ if (!Array.isArray(raw)) return null;
39
+ const out: AstGrepMatch[] = [];
40
+ for (const item of raw) {
41
+ if (typeof item !== 'object' || item === null) return null;
42
+ const m = item as Record<string, unknown>;
43
+ const range = m['range'] as { start?: { line?: unknown } } | undefined;
44
+ const line = range?.start?.line;
45
+ if (typeof m['file'] !== 'string' || typeof m['text'] !== 'string' || typeof line !== 'number') return null;
46
+ out.push({
47
+ file: m['file'].split(path.sep).join('/'),
48
+ text: m['text'],
49
+ message: typeof m['message'] === 'string' && m['message'] !== '' ? m['message'] : 'rule violated',
50
+ // ast-grep reports zero-based lines.
51
+ line: line + 1,
52
+ });
53
+ }
54
+ return out;
55
+ }
56
+
57
+ async function checkBinary(root: string, timeoutMs: number, maxOutputBytes: number): Promise<AdapterOutput | null> {
58
+ const exe = await resolveTool(root, BINARY);
59
+ const run = await runTool(exe, ['--version'], root, timeoutMs, maxOutputBytes);
60
+ if (run.spawnError !== undefined) {
61
+ return failure('adapter-unavailable', 'ast-grep is not installed (the adapter looks for `ast-grep`, not `sg`)');
62
+ }
63
+ if (run.timedOut) return failure('timed-out', 'ast-grep --version did not finish in time');
64
+ if (!VERSION_BANNER.test(run.stdout.trim())) {
65
+ return failure('adapter-unavailable', `the binary named ast-grep is not ast-grep: ${tail(run.stdout || run.stderr)}`);
66
+ }
67
+ return null;
68
+ }
69
+
70
+ async function scanChunk(
71
+ root: string,
72
+ exe: string,
73
+ ruleAbs: string,
74
+ files: readonly string[],
75
+ timeoutMs: number,
76
+ maxOutputBytes: number,
77
+ ): Promise<{ matches: AstGrepMatch[] } | AdapterOutput> {
78
+ const run = await runTool(exe, ['scan', '-r', ruleAbs, '--json', ...files], root, timeoutMs, maxOutputBytes);
79
+ if (run.timedOut) return failure('timed-out', `ast-grep scan did not finish within ${timeoutMs} ms`);
80
+ if (run.truncated) return failure('adapter-error', 'ast-grep output exceeded the byte budget; results are incomplete');
81
+ // ast-grep exits 1 when it finds error-level matches: a normal result. Any other non-zero status,
82
+ // or output that is not the JSON array, is an error, never zero matches.
83
+ if (run.exitCode !== 0 && run.exitCode !== 1) {
84
+ return failure('adapter-error', `ast-grep exited ${run.exitCode}: ${tail(run.stderr || run.stdout)}`);
85
+ }
86
+ const matches = parseMatches(run.stdout);
87
+ if (matches === null) return failure('adapter-error', `ast-grep did not print a match list: ${tail(run.stderr || run.stdout)}`);
88
+ return { matches };
89
+ }
90
+
91
+ export const astGrepAdapter: RuleAdapter = {
92
+ kind: 'ast-grep',
93
+ async run(request: AdapterRequest): Promise<AdapterOutput> {
94
+ const { rule, projectRoot: root, files, timeoutMs, maxOutputBytes } = request;
95
+ if (rule.check.kind !== 'ast-grep') return failure('adapter-error', 'ast-grep adapter given a different check kind');
96
+ const ruleAbs = path.resolve(root, rule.check.ruleFile);
97
+ if (!ruleAbs.startsWith(path.resolve(root) + path.sep)) {
98
+ return failure('adapter-error', `ast-grep rule file ${rule.check.ruleFile} lies outside the project`);
99
+ }
100
+ try {
101
+ await fs.access(ruleAbs);
102
+ } catch {
103
+ return failure('adapter-error', `ast-grep rule file ${rule.check.ruleFile} does not exist`);
104
+ }
105
+ const unavailable = await checkBinary(root, timeoutMs, maxOutputBytes);
106
+ if (unavailable !== null) return unavailable;
107
+ if (files.length === 0) return { ok: true, violations: [] };
108
+
109
+ const exe = await resolveTool(root, BINARY);
110
+ const violations: RuleViolation[] = [];
111
+ for (const group of chunks(files, CHUNK_SIZE)) {
112
+ const scanned = await scanChunk(root, exe, ruleAbs, group, timeoutMs, maxOutputBytes);
113
+ if (!('matches' in scanned)) return scanned;
114
+ for (const match of scanned.matches) {
115
+ violations.push({
116
+ ruleId: rule.id,
117
+ path: match.file,
118
+ line: match.line,
119
+ fingerprint: computeFingerprint(rule.id, match.file, match.text),
120
+ message: match.message,
121
+ });
122
+ }
123
+ }
124
+ return { ok: true, violations };
125
+ },
126
+ };
@@ -0,0 +1,16 @@
1
+ // packages/cli/src/application/rule-adapters/index.ts
2
+ //
3
+ // The adapters the CLI registers for every constitution evaluation: core's import-boundary plus
4
+ // the process-backed ast-grep and linter adapters. Core evaluates; this module decides what can
5
+ // run in this environment.
6
+
7
+ import { builtinAdapters, type AdapterRegistry } from '@agentic-sdlc-kit/core';
8
+ import { astGrepAdapter } from './ast-grep.js';
9
+ import { linterAdapter } from './linter.js';
10
+
11
+ export function constitutionAdapters(): AdapterRegistry {
12
+ const registry = new Map(builtinAdapters());
13
+ registry.set(astGrepAdapter.kind, astGrepAdapter);
14
+ registry.set(linterAdapter.kind, linterAdapter);
15
+ return registry;
16
+ }