@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
+ // The linter adapter's path rules. These reproduce the macOS CI failure on Linux: the project root
2
+ // is reached through a symlink, and the tool reports the resolved (real) path. A silent miss here
3
+ // turns a violation into a pass, so each rule below must hold.
4
+ import { promises as fs } from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
8
+ import type { EngineeringRule } from '@agentic-sdlc-kit/contracts';
9
+ import { linterAdapter } from './linter.js';
10
+
11
+ let base: string;
12
+ beforeEach(async () => {
13
+ base = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-linter-paths-'));
14
+ });
15
+ afterEach(async () => {
16
+ await fs.rm(base, { recursive: true, force: true });
17
+ });
18
+
19
+ const rule = (): EngineeringRule =>
20
+ ({
21
+ schemaVersion: 1, id: 'LINT-EVAL-001', title: 't', statement: 's', rationale: 'r',
22
+ scope: { stacks: [], paths: ['src/**/*.ts'], exclude: [] }, status: 'active', mode: 'blocking',
23
+ check: { kind: 'linter', tool: 'eslint', ruleId: 'no-eval' }, source: 'human', confidence: 1, evidence: [], owner: 'o', supersedes: [],
24
+ }) as unknown as EngineeringRule;
25
+
26
+ /**
27
+ * A project at `base/real`, reached through the symlink `base/link` (the macOS shape: /var is a
28
+ * link to /private/var). ESLint runs in the resolved root and prints resolved paths, so the fake
29
+ * prints `json(resolved)`. The adapter is handed `link`, never the resolved path.
30
+ */
31
+ async function project(json: (resolved: string) => unknown): Promise<{ real: string; link: string }> {
32
+ const real = path.join(base, 'real');
33
+ await fs.mkdir(path.join(real, 'src'), { recursive: true });
34
+ await fs.mkdir(path.join(real, 'node_modules', '.bin'), { recursive: true });
35
+ await fs.writeFile(path.join(real, 'src', 'a.ts'), 'eval(1)\n');
36
+ const resolved = await fs.realpath(real);
37
+ const exe = path.join(real, 'node_modules', '.bin', 'eslint');
38
+ await fs.writeFile(exe, `#!/bin/sh\ncat <<'JSON'\n${JSON.stringify(json(resolved))}\nJSON\nexit 1\n`);
39
+ await fs.chmod(exe, 0o755);
40
+ const link = path.join(base, 'link');
41
+ await fs.symlink(real, link);
42
+ return { real, link };
43
+ }
44
+
45
+ const req = (projectRoot: string, files = ['src/a.ts']) => ({
46
+ projectRoot, rule: rule(), files, timeoutMs: 30_000, maxOutputBytes: 1_000_000,
47
+ });
48
+
49
+ describe('symlinked project roots (the macOS CI failure)', () => {
50
+ it('a finding reported at the resolved path is found through the symlink', async () => {
51
+ const { link } = await project((resolved) => [
52
+ { filePath: path.join(resolved, 'src', 'a.ts'), messages: [{ ruleId: 'no-eval', line: 1, message: 'eval' }] },
53
+ ]);
54
+ const out = await linterAdapter.run(req(link));
55
+ expect(out.ok && out.violations.map((v) => [v.path, v.line])).toEqual([['src/a.ts', 1]]);
56
+ });
57
+
58
+ it('a file whose name starts with two dots is inside the project, not outside it', async () => {
59
+ const { link } = await project((resolved) => [
60
+ { filePath: path.join(resolved, '..dotfile.js'), messages: [{ ruleId: 'no-eval', line: 1, message: 'eval' }] },
61
+ ]);
62
+ const out = await linterAdapter.run(req(link, ['..dotfile.js']));
63
+ expect(out.ok && out.violations.map((v) => v.path)).toEqual(['..dotfile.js']);
64
+ });
65
+ });
66
+
67
+ describe('coverage: a requested file the tool did not list was not linted', () => {
68
+ it('an error, not a clean run, when ESLint does not list a requested file', async () => {
69
+ const { real, link } = await project(() => []);
70
+ await fs.writeFile(path.join(real, 'src', 'b.ts'), 'const b = 1\n');
71
+ const out = await linterAdapter.run(req(link, ['src/a.ts', 'src/b.ts']));
72
+ expect(out.ok).toBe(false);
73
+ if (!out.ok) {
74
+ expect(out.outcome).toBe('adapter-error');
75
+ expect(out.detail).toMatch(/did not report on src\/a\.ts/);
76
+ }
77
+ });
78
+
79
+ it('a listed file with no messages is clean, which is different from not listed', async () => {
80
+ const { link } = await project((resolved) => [{ filePath: path.join(resolved, 'src', 'a.ts'), messages: [] }]);
81
+ expect(await linterAdapter.run(req(link))).toEqual({ ok: true, violations: [] });
82
+ });
83
+ });
84
+
85
+ describe('a finding outside the project is an error, never dropped', () => {
86
+ it('reports the outside path as an error, even when the in-scope file is listed', async () => {
87
+ const { link } = await project((resolved) => [
88
+ { filePath: '/etc/passwd', messages: [{ ruleId: 'no-eval', line: 1, message: 'eval' }] },
89
+ { filePath: path.join(resolved, 'src', 'a.ts'), messages: [] },
90
+ ]);
91
+ const out = await linterAdapter.run(req(link));
92
+ expect(out.ok).toBe(false);
93
+ if (!out.ok) expect(out.detail).toMatch(/outside the project/);
94
+ });
95
+ });
@@ -0,0 +1,263 @@
1
+ // packages/cli/src/application/rule-adapters/linter.ts
2
+ //
3
+ // Linter adapters (ADR-0023 §5, roadmap Phase 4A). A `linter` check names one tool from a fixed
4
+ // registry and one of its rule ids. The adapter runs the tool with JSON output and keeps the
5
+ // findings for that rule id, inside the rule's files.
6
+ //
7
+ // The linters run the project's own configuration, the same trust `kit verify` already extends
8
+ // to the project's test and lint commands. Linters exit non-zero when they find problems, so the
9
+ // exit status is not used: the JSON must parse, or the outcome is an error.
10
+ //
11
+ // Three rules keep a checker from passing by accident:
12
+ // - paths are compared against the REAL project root (symlinks resolved). On macOS the temp dir
13
+ // and many checkouts sit behind a symlink, and a tool reports the resolved path;
14
+ // - a finding outside the project is an error, never silently dropped;
15
+ // - a tool that lists every file it inspects (ESLint, RuboCop) must list each requested file.
16
+ // A requested file it did not list was not linted, so it is unverified, not clean.
17
+
18
+ import { promises as fs } from 'node:fs';
19
+ import path from 'node:path';
20
+ import type { RuleViolation } from '@agentic-sdlc-kit/contracts';
21
+ import {
22
+ computeFingerprint,
23
+ failure,
24
+ type AdapterOutput,
25
+ type AdapterRequest,
26
+ type RuleAdapter,
27
+ } from '@agentic-sdlc-kit/core';
28
+ import { CHUNK_SIZE, chunks, resolveTool, runTool, tail } from './process.js';
29
+
30
+ interface Finding {
31
+ readonly file: string;
32
+ readonly code: string;
33
+ readonly line: number;
34
+ readonly message: string;
35
+ }
36
+
37
+ type ToolSpec = {
38
+ readonly binary: string;
39
+ // Arguments for a run over the given files (or none, for tools that take packages).
40
+ readonly argv: (files: readonly string[]) => readonly string[];
41
+ readonly parse: (json: unknown, root: string) => Finding[] | null;
42
+ // The files the tool reports having inspected, for tools that list every file. Undefined for
43
+ // tools that list only the files they found something in.
44
+ readonly listed?: (json: unknown, root: string) => string[] | null;
45
+ readonly wholeModule?: boolean;
46
+ };
47
+
48
+ /** A path relative to the real root, posix-separated. A result that climbs out is kept as-is. */
49
+ export function relativeTo(realRoot: string, file: string): string {
50
+ return path.relative(realRoot, path.resolve(realRoot, file)).split(path.sep).join('/');
51
+ }
52
+
53
+ /**
54
+ * True when a relative path leaves the root: it climbs with a `..` segment, or it is absolute. A
55
+ * file named `..config.js` inside the project does not climb, so it is not outside.
56
+ */
57
+ export function isOutside(rel: string): boolean {
58
+ return rel === '..' || rel.startsWith('../') || path.isAbsolute(rel);
59
+ }
60
+
61
+ function asArray(v: unknown): unknown[] | null {
62
+ return Array.isArray(v) ? v : null;
63
+ }
64
+
65
+ function asRecord(v: unknown): Record<string, unknown> | null {
66
+ return typeof v === 'object' && v !== null && !Array.isArray(v) ? (v as Record<string, unknown>) : null;
67
+ }
68
+
69
+ // ESLint -f json: [{ filePath, messages: [{ ruleId, line, message }] }]. Lists every linted file.
70
+ const ESLINT: ToolSpec = {
71
+ binary: 'eslint',
72
+ argv: (files) => ['-f', 'json', ...files],
73
+ parse: (json, root) => {
74
+ const files = asArray(json);
75
+ if (files === null) return null;
76
+ const out: Finding[] = [];
77
+ for (const f of files) {
78
+ const rec = asRecord(f);
79
+ const messages = rec ? asArray(rec['messages']) : null;
80
+ if (!rec || typeof rec['filePath'] !== 'string' || messages === null) return null;
81
+ for (const m of messages) {
82
+ const msg = asRecord(m);
83
+ if (!msg || typeof msg['ruleId'] !== 'string' || typeof msg['message'] !== 'string') continue;
84
+ out.push({ file: relativeTo(root, rec['filePath']), code: msg['ruleId'], line: Number(msg['line'] ?? 1), message: msg['message'] });
85
+ }
86
+ }
87
+ return out;
88
+ },
89
+ listed: (json, root) => {
90
+ const files = asArray(json);
91
+ if (files === null) return null;
92
+ const out: string[] = [];
93
+ for (const f of files) {
94
+ const rec = asRecord(f);
95
+ if (!rec || typeof rec['filePath'] !== 'string') return null;
96
+ out.push(relativeTo(root, rec['filePath']));
97
+ }
98
+ return out;
99
+ },
100
+ };
101
+
102
+ // ruff check --output-format json: [{ code, filename, location: { row }, message }]. Findings only.
103
+ const RUFF: ToolSpec = {
104
+ binary: 'ruff',
105
+ argv: (files) => ['check', '--output-format', 'json', '--no-cache', ...files],
106
+ parse: (json, root) => {
107
+ const items = asArray(json);
108
+ if (items === null) return null;
109
+ const out: Finding[] = [];
110
+ for (const it of items) {
111
+ const rec = asRecord(it);
112
+ const loc = rec ? asRecord(rec['location']) : null;
113
+ if (!rec || !loc || typeof rec['code'] !== 'string' || typeof rec['filename'] !== 'string' || typeof rec['message'] !== 'string') return null;
114
+ out.push({ file: relativeTo(root, rec['filename']), code: rec['code'], line: Number(loc['row'] ?? 1), message: rec['message'] });
115
+ }
116
+ return out;
117
+ },
118
+ };
119
+
120
+ // rubocop --format json: { files: [{ path, offenses: [{ cop_name, message, location: { line } }] }] }.
121
+ // Lists every inspected file.
122
+ const RUBOCOP: ToolSpec = {
123
+ binary: 'rubocop',
124
+ argv: (files) => ['--format', 'json', ...files],
125
+ parse: (json, root) => {
126
+ const rec = asRecord(json);
127
+ const files = rec ? asArray(rec['files']) : null;
128
+ if (files === null) return null;
129
+ const out: Finding[] = [];
130
+ for (const f of files) {
131
+ const fr = asRecord(f);
132
+ const offenses = fr ? asArray(fr['offenses']) : null;
133
+ if (!fr || typeof fr['path'] !== 'string' || offenses === null) return null;
134
+ for (const o of offenses) {
135
+ const orec = asRecord(o);
136
+ const loc = orec ? asRecord(orec['location']) : null;
137
+ if (!orec || !loc || typeof orec['cop_name'] !== 'string' || typeof orec['message'] !== 'string') return null;
138
+ out.push({ file: relativeTo(root, fr['path']), code: orec['cop_name'], line: Number(loc['line'] ?? 1), message: orec['message'] });
139
+ }
140
+ }
141
+ return out;
142
+ },
143
+ listed: (json, root) => {
144
+ const rec = asRecord(json);
145
+ const files = rec ? asArray(rec['files']) : null;
146
+ if (files === null) return null;
147
+ const out: string[] = [];
148
+ for (const f of files) {
149
+ const fr = asRecord(f);
150
+ if (!fr || typeof fr['path'] !== 'string') return null;
151
+ out.push(relativeTo(root, fr['path']));
152
+ }
153
+ return out;
154
+ },
155
+ };
156
+
157
+ // golangci-lint run --out-format json: { Issues: [{ FromLinter, Text, Pos: { Filename, Line } }] }
158
+ const GOLANGCI: ToolSpec = {
159
+ binary: 'golangci-lint',
160
+ argv: () => ['run', '--out-format', 'json', './...'],
161
+ wholeModule: true,
162
+ parse: (json, root) => {
163
+ const rec = asRecord(json);
164
+ const issues = rec ? asArray(rec['Issues'] ?? []) : null;
165
+ if (issues === null) return null;
166
+ const out: Finding[] = [];
167
+ for (const it of issues) {
168
+ const ir = asRecord(it);
169
+ const pos = ir ? asRecord(ir['Pos']) : null;
170
+ if (!ir || !pos || typeof ir['FromLinter'] !== 'string' || typeof pos['Filename'] !== 'string') return null;
171
+ out.push({ file: relativeTo(root, pos['Filename']), code: ir['FromLinter'], line: Number(pos['Line'] ?? 1), message: String(ir['Text'] ?? '') });
172
+ }
173
+ return out;
174
+ },
175
+ };
176
+
177
+ export const TOOLS: Readonly<Record<string, ToolSpec>> = {
178
+ eslint: ESLINT,
179
+ ruff: RUFF,
180
+ rubocop: RUBOCOP,
181
+ 'golangci-lint': GOLANGCI,
182
+ };
183
+
184
+ /**
185
+ * A finding matches a configured rule id exactly, or by its unscoped name. ESLint reports
186
+ * typescript-eslint rules under a plugin prefix (`@typescript-eslint/no-unused-vars`); a rule that
187
+ * names `no-unused-vars` means the same check, and a silent miss would turn a violation into a pass.
188
+ */
189
+ export function sameRule(found: string, configured: string): boolean {
190
+ if (found === configured) return true;
191
+ const unscoped = (id: string): string => id.replace(/^@[^/]+\//, '');
192
+ return unscoped(found) === unscoped(configured);
193
+ }
194
+
195
+ async function runChunk(
196
+ realRoot: string,
197
+ spec: ToolSpec,
198
+ files: readonly string[],
199
+ timeoutMs: number,
200
+ maxOutputBytes: number,
201
+ ): Promise<{ findings: Finding[] } | AdapterOutput> {
202
+ const exe = await resolveTool(realRoot, spec.binary);
203
+ const run = await runTool(exe, spec.argv(files), realRoot, timeoutMs, maxOutputBytes);
204
+ if (run.spawnError !== undefined) return failure('adapter-unavailable', `${spec.binary} is not installed`);
205
+ if (run.timedOut) return failure('timed-out', `${spec.binary} did not finish within ${timeoutMs} ms`);
206
+ if (run.truncated) return failure('adapter-error', `${spec.binary} output exceeded the byte budget; results are incomplete`);
207
+ let json: unknown;
208
+ try {
209
+ json = JSON.parse(run.stdout);
210
+ } catch {
211
+ return failure('adapter-error', `${spec.binary} did not print JSON: ${tail(run.stderr || run.stdout)}`);
212
+ }
213
+ const findings = spec.parse(json, realRoot);
214
+ if (findings === null) return failure('adapter-error', `${spec.binary} JSON has an unexpected shape`);
215
+ if (spec.listed !== undefined) {
216
+ const listed = spec.listed(json, realRoot);
217
+ if (listed === null) return failure('adapter-error', `${spec.binary} JSON lists no files in the expected shape`);
218
+ const seen = new Set(listed);
219
+ const missing = files.filter((f) => !seen.has(f));
220
+ if (missing.length > 0) {
221
+ return failure(
222
+ 'adapter-error',
223
+ `${spec.binary} did not report on ${missing[0]}; that file was not linted, so it is unverified, not clean`,
224
+ );
225
+ }
226
+ }
227
+ return { findings };
228
+ }
229
+
230
+ export const linterAdapter: RuleAdapter = {
231
+ kind: 'linter',
232
+ async run(request: AdapterRequest): Promise<AdapterOutput> {
233
+ const { rule, projectRoot, files, timeoutMs, maxOutputBytes } = request;
234
+ if (rule.check.kind !== 'linter') return failure('adapter-error', 'linter adapter given a different check kind');
235
+ const spec = TOOLS[rule.check.tool];
236
+ if (spec === undefined) return failure('adapter-unavailable', `no linter adapter for ${rule.check.tool}`);
237
+ if (files.length === 0 && !spec.wholeModule) return { ok: true, violations: [] };
238
+
239
+ // The real root: tools report resolved paths, so the comparison must use them too.
240
+ const realRoot = await fs.realpath(projectRoot);
241
+ const inScope = new Set(files);
242
+ const groups = spec.wholeModule ? [[]] : chunks(files, CHUNK_SIZE);
243
+ const violations: RuleViolation[] = [];
244
+ for (const group of groups) {
245
+ const result = await runChunk(realRoot, spec, group, timeoutMs, maxOutputBytes);
246
+ if (!('findings' in result)) return result;
247
+ for (const f of result.findings) {
248
+ if (isOutside(f.file)) {
249
+ return failure('adapter-error', `${spec.binary} reported ${f.file}, outside the project; results are not trusted`);
250
+ }
251
+ if (!sameRule(f.code, rule.check.ruleId) || !inScope.has(f.file)) continue;
252
+ violations.push({
253
+ ruleId: rule.id,
254
+ path: f.file,
255
+ line: f.line,
256
+ fingerprint: computeFingerprint(rule.id, f.file, `${f.code}:${f.message}`),
257
+ message: `${rule.check.tool} ${f.code}: ${f.message}`,
258
+ });
259
+ }
260
+ }
261
+ return { ok: true, violations };
262
+ },
263
+ };
@@ -0,0 +1,48 @@
1
+ // packages/cli/src/application/rule-adapters/process.ts
2
+ //
3
+ // Runs one external tool for a rule adapter, through the core's bounded runner: argv with no
4
+ // shell, a hard timeout that terminates the whole process group, and a cap on captured output.
5
+ // A tool that is not installed is reported as such, never as a clean run.
6
+
7
+ import path from 'node:path';
8
+ import { promises as fs } from 'node:fs';
9
+ import { runToSettlement, type RunOutcome } from '@agentic-sdlc-kit/core';
10
+
11
+ export function toolPath(projectRoot: string, name: string): string {
12
+ // A project-local binary (node_modules/.bin) is the one the project's own scripts use.
13
+ return path.join(projectRoot, 'node_modules', '.bin', name);
14
+ }
15
+
16
+ /** The executable to run: the project-local one when it exists, else the name on PATH. */
17
+ export async function resolveTool(projectRoot: string, name: string): Promise<string> {
18
+ try {
19
+ await fs.access(toolPath(projectRoot, name));
20
+ return toolPath(projectRoot, name);
21
+ } catch {
22
+ return name;
23
+ }
24
+ }
25
+
26
+ export function runTool(
27
+ file: string,
28
+ args: readonly string[],
29
+ cwd: string,
30
+ timeoutMs: number,
31
+ maxOutputBytes: number,
32
+ ): Promise<RunOutcome> {
33
+ return runToSettlement(file, args, cwd, timeoutMs, maxOutputBytes);
34
+ }
35
+
36
+ /** Readable tail of tool output for an error detail. */
37
+ export function tail(text: string, max = 400): string {
38
+ const trimmed = text.trim();
39
+ return trimmed.length > max ? `…${trimmed.slice(-max)}` : trimmed;
40
+ }
41
+
42
+ export const CHUNK_SIZE = 200;
43
+
44
+ export function chunks<T>(items: readonly T[], size: number): T[][] {
45
+ const out: T[][] = [];
46
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
47
+ return out;
48
+ }
@@ -1,7 +1,12 @@
1
1
  // packages/cli/src/application/version.ts
2
2
  //
3
- // Single source of truth for the kit version. Sourced from package.json at
4
- // build time via a build-time constant. In M1 we hard-code to keep the
5
- // build simple; M16 wires this to a generated file.
3
+ // Single source of truth for the kit version. Read from package.json at
4
+ // runtime so the CLI can never drift behind the manifest (the M1 hard-code
5
+ // did exactly that — see #88).
6
6
 
7
- export const VERSION = '0.8.0';
7
+ import { createRequire } from 'node:module';
8
+
9
+ const require = createRequire(import.meta.url);
10
+ const { version } = require('../../package.json') as { version: string };
11
+
12
+ export const VERSION = version;
@@ -0,0 +1,50 @@
1
+ // packages/cli/src/commands/attach-exclude.ts
2
+ //
3
+ // Managed block inside `.git/info/exclude`. Patterns carry NO trailing slash:
4
+ // a slash-suffixed gitignore pattern matches directories only and git treats
5
+ // a symlink as a file, so the symlinked (global) mode would leak.
6
+
7
+ import { promises as fs } from 'node:fs';
8
+ import path from 'node:path';
9
+
10
+ export const BLOCK_BEGIN = '# >>> kit-attach managed block >>>';
11
+ export const BLOCK_END = '# <<< kit-attach managed block <<<';
12
+
13
+ export function stripBlock(text: string): string {
14
+ const out: string[] = [];
15
+ let skip = false;
16
+ for (const line of text.split('\n')) {
17
+ if (line === BLOCK_BEGIN) skip = true;
18
+ if (!skip) out.push(line);
19
+ if (line === BLOCK_END) skip = false;
20
+ }
21
+ return out.join('\n');
22
+ }
23
+
24
+ export function withBlock(text: string, paths: readonly string[]): string {
25
+ const base = stripBlock(text).replace(/\n*$/, '');
26
+ const block = [BLOCK_BEGIN, ...paths, BLOCK_END].join('\n');
27
+ return (base ? base + '\n' : '') + block + '\n';
28
+ }
29
+
30
+ async function readOrEmpty(file: string): Promise<string> {
31
+ try {
32
+ return await fs.readFile(file, 'utf8');
33
+ } catch {
34
+ return '';
35
+ }
36
+ }
37
+
38
+ export async function writeBlock(file: string, paths: readonly string[]): Promise<void> {
39
+ await fs.mkdir(path.dirname(file), { recursive: true });
40
+ await fs.writeFile(file, withBlock(await readOrEmpty(file), paths));
41
+ }
42
+
43
+ export async function removeBlock(file: string): Promise<void> {
44
+ const text = await readOrEmpty(file);
45
+ if (text.includes(BLOCK_BEGIN)) await fs.writeFile(file, stripBlock(text));
46
+ }
47
+
48
+ export async function hasBlock(file: string): Promise<boolean> {
49
+ return (await readOrEmpty(file)).includes(BLOCK_BEGIN);
50
+ }
@@ -0,0 +1,50 @@
1
+ // packages/cli/src/commands/attach-git.ts
2
+ //
3
+ // Thin git helpers for `kit attach`. All calls use argument arrays (never a
4
+ // shell string) so paths with spaces or metacharacters cannot be injected.
5
+
6
+ import { execFileSync } from 'node:child_process';
7
+ import path from 'node:path';
8
+
9
+ export interface RepoInfo {
10
+ /** Working-tree root of the repository (or linked worktree). */
11
+ root: string;
12
+ /** Shared git dir: where `info/exclude` must live so linked worktrees agree. */
13
+ commonDir: string;
14
+ }
15
+
16
+ function git(cwd: string, args: readonly string[]): string {
17
+ return execFileSync('git', [...args], {
18
+ cwd,
19
+ encoding: 'utf8',
20
+ stdio: ['ignore', 'pipe', 'pipe'],
21
+ });
22
+ }
23
+
24
+ export function resolveRepo(cwd: string): RepoInfo | null {
25
+ try {
26
+ const root = git(cwd, ['rev-parse', '--show-toplevel']).trim();
27
+ const common = git(root, ['rev-parse', '--git-common-dir']).trim();
28
+ return { root, commonDir: path.resolve(root, common) };
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+
34
+ export function hasTrackedFiles(root: string, rel: string): boolean {
35
+ return git(root, ['ls-files', '--', rel]).trim().length > 0;
36
+ }
37
+
38
+ export function isIgnored(root: string, rel: string): boolean {
39
+ try {
40
+ git(root, ['check-ignore', '-q', '--', rel]);
41
+ return true;
42
+ } catch {
43
+ return false; // exit 1 = not ignored
44
+ }
45
+ }
46
+
47
+ export function statusLeaks(root: string, rels: readonly string[]): string[] {
48
+ const out = git(root, ['status', '--porcelain', '--', ...rels]);
49
+ return out.split('\n').filter((l) => l.length > 0);
50
+ }
@@ -0,0 +1,107 @@
1
+ // packages/cli/src/commands/attach-store.ts
2
+ //
3
+ // Filesystem operations for `kit attach local|global|detach`.
4
+
5
+ import { createHash } from 'node:crypto';
6
+ import { promises as fs, type Stats } from 'node:fs';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
9
+
10
+ export const MANAGED_PATHS: readonly string[] = [
11
+ '.ai-kit',
12
+ '.claude',
13
+ 'docs/specifications',
14
+ 'docs/plans',
15
+ ];
16
+
17
+ export class AttachError extends Error {}
18
+
19
+ export function storeDirFor(root: string, env: NodeJS.ProcessEnv = process.env): string {
20
+ const base = env['KIT_ATTACH_HOME'] ?? path.join(os.homedir(), '.agentic-sdlc', 'projects');
21
+ const hash = createHash('sha256').update(root).digest('hex').slice(0, 8);
22
+ return path.join(base, `${path.basename(root)}-${hash}`);
23
+ }
24
+
25
+ export const storeBase = (storeDir: string): string => path.dirname(storeDir);
26
+
27
+ async function lstatOrNull(p: string): Promise<Stats | null> {
28
+ try {
29
+ return await fs.lstat(p);
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ export async function attachLocal(root: string): Promise<void> {
36
+ for (const rel of MANAGED_PATHS) {
37
+ const abs = path.join(root, rel);
38
+ if ((await lstatOrNull(abs))?.isSymbolicLink()) {
39
+ throw new AttachError(`'${rel}' is a symlink; run 'kit attach detach' before switching modes`);
40
+ }
41
+ await fs.mkdir(abs, { recursive: true });
42
+ }
43
+ }
44
+
45
+ async function linkOne(root: string, storeDir: string, rel: string, adopt: boolean): Promise<void> {
46
+ const abs = path.join(root, rel);
47
+ const target = path.join(storeDir, rel);
48
+ await fs.mkdir(target, { recursive: true });
49
+ await fs.mkdir(path.dirname(abs), { recursive: true });
50
+ const st = await lstatOrNull(abs);
51
+ if (st?.isSymbolicLink()) {
52
+ if ((await fs.readlink(abs)) !== target) {
53
+ throw new AttachError(`'${rel}' points elsewhere; refusing to touch it`);
54
+ }
55
+ return;
56
+ }
57
+ if (st) await migrateExisting(abs, target, rel, adopt);
58
+ await fs.symlink(target, abs, 'dir');
59
+ }
60
+
61
+ async function migrateExisting(abs: string, target: string, rel: string, adopt: boolean): Promise<void> {
62
+ const st = await fs.lstat(abs);
63
+ if (!st.isDirectory()) throw new AttachError(`'${rel}' exists and is not a directory`);
64
+ if ((await fs.readdir(abs)).length > 0) {
65
+ if (!adopt) {
66
+ throw new AttachError(`'${rel}' has content; re-run with --adopt to migrate it into the store`);
67
+ }
68
+ await fs.cp(abs, target, { recursive: true });
69
+ }
70
+ await fs.rm(abs, { recursive: true, force: true });
71
+ }
72
+
73
+ export async function attachGlobal(root: string, storeDir: string, adopt: boolean): Promise<void> {
74
+ // Preflight so a refusal on a later path cannot leave a half-attached repo.
75
+ for (const rel of MANAGED_PATHS) await preflight(path.join(root, rel), rel, adopt);
76
+ for (const rel of MANAGED_PATHS) await linkOne(root, storeDir, rel, adopt);
77
+ }
78
+
79
+ async function preflight(abs: string, rel: string, adopt: boolean): Promise<void> {
80
+ const st = await lstatOrNull(abs);
81
+ if (!st || st.isSymbolicLink()) return;
82
+ if (!st.isDirectory()) throw new AttachError(`'${rel}' exists and is not a directory`);
83
+ if (!adopt && (await fs.readdir(abs)).length > 0) {
84
+ throw new AttachError(`'${rel}' has content; re-run with --adopt to migrate it into the store`);
85
+ }
86
+ }
87
+
88
+ export async function detachLinks(root: string, base: string): Promise<string[]> {
89
+ const removed: string[] = [];
90
+ for (const rel of MANAGED_PATHS) {
91
+ const abs = path.join(root, rel);
92
+ if (!(await lstatOrNull(abs))?.isSymbolicLink()) continue;
93
+ const dest = await fs.readlink(abs);
94
+ if (!dest.startsWith(base + path.sep)) continue; // not ours
95
+ await fs.unlink(abs);
96
+ removed.push(rel);
97
+ }
98
+ return removed;
99
+ }
100
+
101
+ export async function describePath(root: string, rel: string): Promise<string> {
102
+ const abs = path.join(root, rel);
103
+ const st = await lstatOrNull(abs);
104
+ if (!st) return `${rel} (absent)`;
105
+ if (st.isSymbolicLink()) return `${rel} -> ${await fs.readlink(abs)} (global)`;
106
+ return `${rel} (local dir)`;
107
+ }