@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,120 @@
1
+ // packages/cli/src/commands/host.test.ts
2
+ import { promises as fs } from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
6
+ import { hostCommand } from './host.js';
7
+ import type { CommandContext } from './types.js';
8
+
9
+ let tmp: string;
10
+ let home: string;
11
+ let proj: string;
12
+
13
+ beforeEach(async () => {
14
+ tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-host-'));
15
+ home = path.join(tmp, 'home');
16
+ proj = path.join(tmp, 'proj');
17
+ await fs.mkdir(home);
18
+ await fs.mkdir(proj);
19
+ });
20
+ afterEach(() => fs.rm(tmp, { recursive: true, force: true }));
21
+
22
+ const run = async (...argv: string[]) => {
23
+ const out: string[] = [];
24
+ const err: string[] = [];
25
+ const ctx: CommandContext = {
26
+ argv: [...argv, '--home', home, '--dir', proj],
27
+ cwd: tmp,
28
+ stdout: (s) => void out.push(s),
29
+ stderr: (s) => void err.push(s),
30
+ };
31
+ const r = await hostCommand.run(ctx);
32
+ return { ...r, out: out.join('\n'), err: err.join('\n') };
33
+ };
34
+ const read = (p: string) => fs.readFile(p, 'utf8');
35
+ const exists = (p: string) => fs.stat(p).then(() => true, () => false);
36
+
37
+ describe('kit host', () => {
38
+ it('list shows every host with its default scope', async () => {
39
+ const r = await run('list');
40
+ expect(r.exitCode).toBe(0);
41
+ for (const h of ['claude-code', 'codex', 'cursor', 'agy', 'gemini', 'aider']) {
42
+ expect(r.out).toContain(h);
43
+ }
44
+ });
45
+
46
+ it('claude-code installs slash commands and a skill at user scope, nothing in the project', async () => {
47
+ const r = await run('install', 'claude-code');
48
+ expect(r.exitCode).toBe(0);
49
+ const cmd = await read(path.join(home, '.claude/commands/kit-feature.md'));
50
+ expect(cmd).toContain('$ARGUMENTS');
51
+ expect(cmd).toContain('KIT_HOST=claude-code');
52
+ expect(await exists(path.join(home, '.claude/skills/agentic-sdlc-kit/SKILL.md'))).toBe(true);
53
+ expect(await fs.readdir(proj)).toEqual([]);
54
+ });
55
+
56
+ it('is idempotent: second install reports unchanged and rewrites nothing', async () => {
57
+ await run('install', 'claude-code');
58
+ const p = path.join(home, '.claude/commands/kit-fix.md');
59
+ const before = await fs.stat(p);
60
+ const r = await run('install', 'claude-code');
61
+ expect(r.exitCode).toBe(0);
62
+ expect(r.out).not.toMatch(/created|updated|refused/);
63
+ expect((await fs.stat(p)).mtimeMs).toBe(before.mtimeMs);
64
+ });
65
+
66
+ it('refuses to overwrite an edited file; --force replaces it', async () => {
67
+ await run('install', 'cursor');
68
+ const p = path.join(proj, '.cursor/rules/sdlc.mdc');
69
+ await fs.writeFile(p, (await read(p)).replace('kit doctor', 'MY OWN RULE'));
70
+ const refused = await run('install', 'cursor');
71
+ expect(refused.exitCode).toBe(1);
72
+ expect(refused.out).toContain('refused');
73
+ expect(await read(p)).toContain('MY OWN RULE');
74
+ expect((await run('install', 'cursor', '--force')).exitCode).toBe(0);
75
+ expect(await read(p)).not.toContain('MY OWN RULE');
76
+ });
77
+
78
+ it('refuses a pre-existing file the kit did not write', async () => {
79
+ const p = path.join(home, '.gemini/skills/agentic-sdlc-kit/SKILL.md');
80
+ await fs.mkdir(path.dirname(p), { recursive: true });
81
+ await fs.writeFile(p, 'my skill');
82
+ const r = await run('install', 'agy');
83
+ expect(r.exitCode).toBe(1);
84
+ expect(await read(p)).toBe('my skill');
85
+ });
86
+
87
+ it('shared files keep user text and only the managed block is replaced', async () => {
88
+ const p = path.join(proj, 'AGENTS.md');
89
+ await fs.writeFile(p, '# My project rules\nkeep me\n');
90
+ expect((await run('install', 'codex', '--scope', 'project')).exitCode).toBe(0);
91
+ const once = await read(p);
92
+ expect(once).toContain('keep me');
93
+ expect(once).toContain('KIT_HOST=codex');
94
+ await run('install', 'codex', '--scope', 'project');
95
+ expect(await read(p)).toBe(once);
96
+ });
97
+
98
+ it('dry-run writes nothing', async () => {
99
+ const r = await run('install', 'all', '--dry-run');
100
+ expect(r.exitCode).toBe(0);
101
+ expect(r.out).toContain('dry run');
102
+ expect(await fs.readdir(home)).toEqual([]);
103
+ expect(await fs.readdir(proj)).toEqual([]);
104
+ });
105
+
106
+ it('rejects unknown hosts, bad scopes and scopes a host lacks', async () => {
107
+ expect((await run('install', 'vim')).err).toContain("unknown host 'vim'");
108
+ expect((await run('install', 'codex', '--scope', 'galaxy')).err).toContain('--scope');
109
+ expect((await run('install', 'cursor', '--scope', 'user')).err).toContain('no user-scope');
110
+ });
111
+
112
+ it('install all uses each host default scope', async () => {
113
+ const r = await run('install', 'all');
114
+ expect(r.exitCode).toBe(0);
115
+ expect(await exists(path.join(home, '.codex/AGENTS.md'))).toBe(true);
116
+ expect(await exists(path.join(home, '.gemini/GEMINI.md'))).toBe(true);
117
+ expect(await exists(path.join(proj, '.cursor/rules/sdlc.mdc'))).toBe(true);
118
+ expect(await exists(path.join(proj, 'CONVENTIONS.md'))).toBe(true);
119
+ });
120
+ });
@@ -0,0 +1,125 @@
1
+ // packages/cli/src/commands/host.ts
2
+ //
3
+ // `kit host list | install <host|all> [--scope user|project] [--dir <p>]
4
+ // [--home <p>] [--force] [--dry-run] [--json]`
5
+ //
6
+ // Installs the standing agent procedure into each AI host's instruction
7
+ // surface once, so per ticket the user types a single line and the host
8
+ // drives the kit's evidence-gated loop (`kit next --json`) on its own.
9
+
10
+ import os from 'node:os';
11
+ import path from 'node:path';
12
+ import {
13
+ DEFAULT_SCOPE,
14
+ HOST_IDS,
15
+ isHostId,
16
+ planHostTargets,
17
+ type HostId,
18
+ type HostScope,
19
+ } from '@agentic-sdlc-kit/core';
20
+ import { applyTarget, type ApplyResult } from './host-apply.js';
21
+ import type { Command, CommandContext, CommandResult } from './types.js';
22
+
23
+ const USAGE = [
24
+ 'Usage: kit host list',
25
+ ' kit host install <host|all> [--scope user|project] [--dir <project>] [--home <dir>]',
26
+ ' [--force] [--dry-run] [--json]',
27
+ '',
28
+ `Hosts: ${HOST_IDS.join(', ')}`,
29
+ 'Default scope: user where the host has a global surface, otherwise project.',
30
+ 'Existing files you edited are never overwritten without --force; shared files',
31
+ '(AGENTS.md, GEMINI.md, CONVENTIONS.md) only get a replaceable managed block.',
32
+ ].join('\n');
33
+
34
+ function opt(argv: ReadonlyArray<string>, name: string): string | undefined {
35
+ const i = argv.indexOf(name);
36
+ const v = i === -1 ? undefined : argv[i + 1];
37
+ return v && !v.startsWith('-') ? v : undefined;
38
+ }
39
+
40
+ function listText(): string {
41
+ const lines = ['kit host: instruction surfaces', ''];
42
+ for (const host of HOST_IDS) {
43
+ const scope = DEFAULT_SCOPE[host];
44
+ const paths = planHostTargets(host, scope)!.map((t) => t.path);
45
+ lines.push(` ${host.padEnd(12)} [${scope}] ${paths.join(', ')}`);
46
+ }
47
+ return lines.join('\n');
48
+ }
49
+
50
+ interface Plan {
51
+ readonly host: HostId;
52
+ readonly scope: HostScope;
53
+ readonly root: string;
54
+ }
55
+
56
+ function resolvePlans(ctx: CommandContext, which: string): Plan[] | string {
57
+ const explicit = opt(ctx.argv, '--scope');
58
+ if (explicit !== undefined && explicit !== 'user' && explicit !== 'project') {
59
+ return `--scope must be 'user' or 'project' (got '${explicit}')`;
60
+ }
61
+ if (which !== 'all' && !isHostId(which)) return `unknown host '${which}'`;
62
+ const hosts: HostId[] = which === 'all' ? [...HOST_IDS] : [which as HostId];
63
+ const home = path.resolve(opt(ctx.argv, '--home') ?? os.homedir());
64
+ const project = path.resolve(ctx.cwd, opt(ctx.argv, '--dir') ?? '.');
65
+ const plans: Plan[] = [];
66
+ for (const host of hosts) {
67
+ const scope = (explicit as HostScope | undefined) ?? DEFAULT_SCOPE[host];
68
+ if (!planHostTargets(host, scope)) {
69
+ if (which === 'all') continue; // an explicit scope that some hosts lack is not an error for 'all'
70
+ return `${host} has no ${scope}-scope instruction surface`;
71
+ }
72
+ plans.push({ host, scope, root: scope === 'user' ? home : project });
73
+ }
74
+ return plans;
75
+ }
76
+
77
+ async function runInstall(ctx: CommandContext, which: string): Promise<CommandResult> {
78
+ const plans = resolvePlans(ctx, which);
79
+ if (typeof plans === 'string') {
80
+ ctx.stderr(`kit host: ${plans}`);
81
+ return { exitCode: 1 };
82
+ }
83
+ const opts = { force: ctx.argv.includes('--force'), dryRun: ctx.argv.includes('--dry-run') };
84
+ const results: Array<ApplyResult & { host: HostId; scope: HostScope }> = [];
85
+ for (const p of plans) {
86
+ for (const t of planHostTargets(p.host, p.scope)!) {
87
+ results.push({ host: p.host, scope: p.scope, ...(await applyTarget(p.root, t, opts)) });
88
+ }
89
+ }
90
+ const refused = results.some((r) => r.action === 'refused');
91
+ ctx.stdout(formatResults(results, opts.dryRun, ctx.argv.includes('--json')));
92
+ return { exitCode: refused ? 1 : 0 };
93
+ }
94
+
95
+ function formatResults(rs: ReadonlyArray<ApplyResult & { host: HostId }>, dry: boolean, json: boolean): string {
96
+ if (json) return JSON.stringify({ dryRun: dry, results: rs }, null, 2);
97
+ const lines = rs.map((r) => ` ${r.action.padEnd(9)} ${r.host.padEnd(12)} ${r.path}${r.reason ? ` (${r.reason})` : ''}`);
98
+ return [dry ? 'kit host install (dry run, nothing written)' : 'kit host install', ...lines].join('\n');
99
+ }
100
+
101
+ export const hostCommand: Command = {
102
+ name: 'host',
103
+ summary: 'Install the standing agent procedure into AI hosts (claude-code, codex, cursor, agy, gemini, aider).',
104
+ async run(ctx: CommandContext): Promise<CommandResult> {
105
+ const positional = ctx.argv.filter((a, i) => !a.startsWith('-') && !isOptValue(ctx.argv, i));
106
+ const [sub, which] = positional;
107
+ if (ctx.argv.includes('--help') || !sub) {
108
+ ctx.stdout(USAGE);
109
+ return { exitCode: sub || ctx.argv.includes('--help') ? 0 : 1 };
110
+ }
111
+ if (sub === 'list') {
112
+ ctx.stdout(listText());
113
+ return { exitCode: 0 };
114
+ }
115
+ if (sub === 'install' && which) return runInstall(ctx, which);
116
+ ctx.stderr(`kit host: unknown or incomplete subcommand\n${USAGE}`);
117
+ return { exitCode: 1 };
118
+ },
119
+ };
120
+
121
+ /** True when argv[i] is the value of a value-taking flag (so it is not a positional). */
122
+ function isOptValue(argv: ReadonlyArray<string>, i: number): boolean {
123
+ const prev = argv[i - 1];
124
+ return prev === '--scope' || prev === '--dir' || prev === '--home';
125
+ }
@@ -8,10 +8,14 @@ export * from './init.js';
8
8
  export * from './validate-spec.js';
9
9
  export * from './validate-plan.js';
10
10
  export * from './verify.js';
11
+ export * from './rules.js';
12
+ export * from './onboard.js';
13
+ export * from './rules-format.js';
11
14
  export * from './feature.js';
12
15
  export * from './new.js';
13
16
  export * from './fix.js';
14
17
  export * from './install.js';
18
+ export * from './uninstall.js';
15
19
  export * from './memory.js';
16
20
  export * from './evolve.js';
17
21
  export * from './refactor.js';
@@ -19,3 +23,11 @@ export * from './optimize.js';
19
23
  export * from './elicit.js';
20
24
  export * from './next.js';
21
25
  export * from './journal.js';
26
+ export * from './skills.js';
27
+ export * from './attach.js';
28
+ export * from './host.js';
29
+ export * from './context.js';
30
+ export * from './learning.js';
31
+ export * from './bench.js';
32
+ export * from './routing.js';
33
+ export * from './knowledge.js';
@@ -62,4 +62,26 @@ describe('initCommand', () => {
62
62
  await fs.rm(tmp, { recursive: true, force: true });
63
63
  }
64
64
  });
65
+
66
+ it('creates state/reports under KIT_STATE_DIR, not in the project', async () => {
67
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-init-state-'));
68
+ const proj = path.join(tmp, 'proj');
69
+ const stateDir = path.join(tmp, 'state');
70
+ await fs.mkdir(proj);
71
+ await fs.writeFile(
72
+ path.join(proj, 'package.json'),
73
+ JSON.stringify({ name: 'p', scripts: { test: 'node --test' } }),
74
+ );
75
+ process.env['KIT_STATE_DIR'] = stateDir;
76
+ try {
77
+ const r = await initCommand.run(makeCtx([], proj));
78
+ expect(r.exitCode).toBe(0);
79
+ expect(await fs.readdir(path.join(proj, '.ai-kit'))).toEqual(['project.yml']);
80
+ const [sub] = await fs.readdir(stateDir);
81
+ expect((await fs.readdir(path.join(stateDir, sub!))).sort()).toEqual(['reports', 'state']);
82
+ } finally {
83
+ delete process.env['KIT_STATE_DIR'];
84
+ await fs.rm(tmp, { recursive: true, force: true });
85
+ }
86
+ });
65
87
  });
@@ -5,7 +5,12 @@
5
5
 
6
6
  import { promises as fs } from 'node:fs';
7
7
  import path from 'node:path';
8
- import { FileSystemRepositoryScanner, generateProfile, writeProfile } from '@agentic-sdlc-kit/core';
8
+ import {
9
+ FileSystemRepositoryScanner,
10
+ generateProfile,
11
+ kitStateRoot,
12
+ writeProfile,
13
+ } from '@agentic-sdlc-kit/core';
9
14
  import type { ProjectProfile } from '@agentic-sdlc-kit/contracts';
10
15
  import type { Command, CommandContext, CommandResult } from './types.js';
11
16
 
@@ -71,8 +76,10 @@ async function fileExists(p: string): Promise<boolean> {
71
76
  }
72
77
 
73
78
  async function ensureDirectories(root: string): Promise<void> {
74
- await fs.mkdir(path.join(root, '.ai-kit', 'state'), { recursive: true });
75
- await fs.mkdir(path.join(root, '.ai-kit', 'reports'), { recursive: true });
79
+ // Machinery dirs follow KIT_STATE_DIR; project.yml itself stays project-rooted.
80
+ const stateRoot = kitStateRoot(root);
81
+ await fs.mkdir(path.join(stateRoot, 'state'), { recursive: true });
82
+ await fs.mkdir(path.join(stateRoot, 'reports'), { recursive: true });
76
83
  }
77
84
 
78
85
  function formatOutput(root: string, profile: ProjectProfile): string {
@@ -59,3 +59,34 @@ describe('installCommand --dir', () => {
59
59
  expect(await exists(path.join(elsewhere.path, '.ai-kit'))).toBe(false);
60
60
  });
61
61
  });
62
+
63
+ describe('installCommand plugin ownership', () => {
64
+ let target: TempDir;
65
+ beforeEach(async () => {
66
+ target = await makeTempDir('kit-install-own-');
67
+ });
68
+ afterEach(() => target.cleanup());
69
+
70
+ const manifest = async (): Promise<{ entries: Array<{ path: string; target?: string }> }> =>
71
+ JSON.parse(await fs.readFile(path.join(target.path, '.ai-kit/ownership-manifest.json'), 'utf8'));
72
+
73
+ it('records the link target for the links it creates', async () => {
74
+ const r = await installCommand.run(makeCtx(['--profile', 'full-sdlc', '--dir', target.path], target.path));
75
+ expect(r.exitCode).toBe(0);
76
+ const link = (await manifest()).entries.find((e) => e.path === '.claude/plugins/sdlc-guard');
77
+ expect(link?.target).toBe(await fs.realpath(path.join(target.path, '.claude/plugins/sdlc-guard')));
78
+ });
79
+
80
+ it('does not record a foreign symlink as kit-owned, leaves it alone, and exits non-zero', async () => {
81
+ const foreign = await makeTempDir('kit-foreign-');
82
+ const linkPath = path.join(target.path, '.claude/plugins/sdlc-guard');
83
+ await fs.mkdir(path.dirname(linkPath), { recursive: true });
84
+ await fs.symlink(foreign.path, linkPath, 'dir');
85
+ const ctx = makeCtx(['--profile', 'full-sdlc', '--dir', target.path], target.path);
86
+ const r = await installCommand.run(ctx);
87
+ expect(r.exitCode).toBe(1);
88
+ expect(await fs.readlink(linkPath)).toBe(foreign.path);
89
+ expect((await manifest()).entries.some((e) => e.path === '.claude/plugins/sdlc-guard')).toBe(false);
90
+ await foreign.cleanup();
91
+ });
92
+ });
@@ -7,6 +7,7 @@
7
7
  import { promises as fs } from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { resolveStackPack } from '@agentic-sdlc-kit/core';
10
+ import { VERSION } from '../application/version.js';
10
11
  import type { Command, CommandContext, CommandResult } from './types.js';
11
12
  import type { OwnershipEntry } from '@agentic-sdlc-kit/contracts';
12
13
  import { linkRuntimePlugins, type PluginLinkResult } from './plugin-linker.js';
@@ -202,7 +203,7 @@ export const installCommand: Command = {
202
203
  // preserved is false because we did not skip it.
203
204
  ownershipEntries.push({
204
205
  packageId: 'agentic-sdlc-kit',
205
- packageVersion: '0.8.0',
206
+ packageVersion: VERSION,
206
207
  path: op.path,
207
208
  sha256: op.sha256,
208
209
  installedAt: now,
@@ -233,11 +234,12 @@ export const installCommand: Command = {
233
234
  }
234
235
  ownershipEntries.push({
235
236
  packageId: 'agentic-sdlc-kit',
236
- packageVersion: '0.8.0',
237
+ packageVersion: VERSION,
237
238
  path: path.relative(targetRoot, pr.linkPath),
238
239
  sha256: pluginHash,
239
240
  installedAt: now,
240
241
  preserved: pr.status === 'already-linked',
242
+ ...(pr.target !== undefined ? { target: pr.target } : {}),
241
243
  });
242
244
  }
243
245
  }
@@ -246,11 +248,18 @@ export const installCommand: Command = {
246
248
  // Write ownership manifest so kit uninstall knows what we own.
247
249
  const manifestPath = path.join(targetRoot, '.ai-kit', 'ownership-manifest.json');
248
250
  await fs.mkdir(path.dirname(manifestPath), { recursive: true });
251
+ // A re-install skips files it already owns, so carry earlier entries
252
+ // forward; dropping them would orphan those files from `kit uninstall`.
253
+ const written = new Set(ownershipEntries.map((e) => e.path));
254
+ const earlier = await fs.readFile(manifestPath, 'utf8').then(
255
+ (raw) => (JSON.parse(raw) as { entries?: OwnershipEntry[] }).entries ?? [],
256
+ () => [] as OwnershipEntry[],
257
+ );
249
258
  const manifest = {
250
259
  schemaVersion: 1,
251
260
  root: targetRoot,
252
261
  scope: 'project',
253
- entries: ownershipEntries,
262
+ entries: [...earlier.filter((e) => !written.has(e.path)), ...ownershipEntries],
254
263
  };
255
264
  await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf8');
256
265
 
@@ -264,13 +273,19 @@ export const installCommand: Command = {
264
273
  ownershipManifest: '.ai-kit/ownership-manifest.json',
265
274
  };
266
275
 
276
+ // A plugin that is not linked (conflict, incomplete, not found) means the
277
+ // guards the profile promised are not active: that is not a success.
278
+ const problems = pluginResults.filter(
279
+ (pr) => pr.status !== 'linked' && pr.status !== 'already-linked',
280
+ );
281
+
267
282
  if (isJson) {
268
- ctx.stdout(JSON.stringify(result, null, 2) + '\n');
283
+ ctx.stdout(JSON.stringify({ ...result, installed: problems.length === 0 }, null, 2) + '\n');
269
284
  } else {
270
- ctx.stdout(formatResult(result));
285
+ ctx.stdout(formatResult({ ...result, installed: problems.length === 0 }));
271
286
  }
272
287
 
273
- return { exitCode: 0 };
288
+ return { exitCode: problems.length === 0 ? 0 : 1 };
274
289
  },
275
290
  };
276
291
 
@@ -314,7 +329,9 @@ interface InstallResult {
314
329
 
315
330
  function formatResult(r: InstallResult): string {
316
331
  const lines: string[] = [
317
- 'kit install: SUCCESS',
332
+ r.installed
333
+ ? 'kit install: SUCCESS'
334
+ : 'kit install: COMPLETED WITH PROBLEMS (see plugin status below)',
318
335
  ` Profile: ${r.profile}`,
319
336
  ` Stack: ${r.stack}`,
320
337
  ` Written: ${r.writtenFiles.length} file(s)`,
@@ -361,7 +378,7 @@ function formatHelp(): string {
361
378
  'The full-sdlc and runtime profiles link the four guard plugins',
362
379
  '(sdlc-guard, secret-guard, model-router, run-observer) into',
363
380
  '.claude/plugins/. They are Claude Code Mods: Claude Code loads each',
364
- 'plugin\'s TypeScript hooks module (hooks/register.ts) directly, so they',
381
+ "plugin's TypeScript hooks module (hooks/register.ts) directly, so they",
365
382
  'work from a fresh clone with no build step (Claude Code v2.1.287+).',
366
383
  '',
367
384
  'Options:',
@@ -0,0 +1,39 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
5
+ import { knowledgeCommand } from './knowledge.js';
6
+ import type { CommandContext } from './types.js';
7
+
8
+ function ctx(argv: string[], cwd: string): CommandContext & { out: string[]; err: string[] } {
9
+ const out: string[] = [];
10
+ const err: string[] = [];
11
+ return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
12
+ }
13
+
14
+ let root: string;
15
+ beforeEach(async () => {
16
+ root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-knowledge-'));
17
+ });
18
+ afterEach(async () => {
19
+ await fs.rm(root, { recursive: true, force: true });
20
+ });
21
+
22
+ describe('kit knowledge export', () => {
23
+ it('refuses to run without --dry-run: there is no transport', async () => {
24
+ const c = ctx(['export', '--namespace', 'tooling'], root);
25
+ expect((await knowledgeCommand.run(c)).exitCode).toBe(2);
26
+ expect(c.err.join('')).toContain('only --dry-run exists');
27
+ });
28
+
29
+ it('requires a namespace', async () => {
30
+ expect((await knowledgeCommand.run(ctx(['export', '--dry-run'], root))).exitCode).toBe(2);
31
+ });
32
+
33
+ it('a dry run with no constitution shares nothing and writes nothing', async () => {
34
+ const c = ctx(['export', '--dry-run', '--namespace', 'tooling'], root);
35
+ expect((await knowledgeCommand.run(c)).exitCode).toBe(0);
36
+ expect(c.out.join('')).toContain('nothing written, nothing sent');
37
+ await expect(fs.access(path.join(root, '.ai-kit', 'knowledge'))).rejects.toThrow();
38
+ });
39
+ });
@@ -0,0 +1,63 @@
1
+ // packages/cli/src/commands/knowledge.ts
2
+ //
3
+ // `kit knowledge export --dry-run --namespace <name> [--json]` (ADR-0027). Shows which rules this
4
+ // repository would share, after the secret scan. Only --dry-run exists: there is no transport, and
5
+ // nothing is pushed or written.
6
+
7
+ import path from 'node:path';
8
+ import { knowledgeExportDryRun } from '@agentic-sdlc-kit/core';
9
+ import type { Command, CommandContext, CommandResult } from './types.js';
10
+
11
+ const HELP = `Usage: kit knowledge export --dry-run --namespace <name> [--json]
12
+
13
+ Shows the rules this repository would share, after a secret scan. Only rules marked
14
+ shareable: true are considered. Nothing is written and nothing is sent: the transport is not built.
15
+ `;
16
+
17
+ function flag(argv: readonly string[], name: string): string | undefined {
18
+ const i = argv.indexOf(name);
19
+ return i >= 0 ? argv[i + 1] : undefined;
20
+ }
21
+
22
+ export const knowledgeCommand: Command = {
23
+ name: 'knowledge',
24
+ summary: 'Show the rules this repository would share, dry run only (ADR-0027).',
25
+ async run(ctx: CommandContext): Promise<CommandResult> {
26
+ if (ctx.argv.includes('--help') || ctx.argv.includes('-h') || ctx.argv.length === 0) {
27
+ ctx.stdout(HELP);
28
+ return { exitCode: 0 };
29
+ }
30
+ const sub = ctx.argv.find((a) => !a.startsWith('-'));
31
+ if (sub !== 'export') {
32
+ ctx.stderr(`kit knowledge: unknown subcommand "${sub ?? ''}"\n${HELP}`);
33
+ return { exitCode: 2, message: 'unknown subcommand' };
34
+ }
35
+ if (!ctx.argv.includes('--dry-run')) {
36
+ ctx.stderr('kit knowledge export: only --dry-run exists; the transport is not built (ADR-0027)\n');
37
+ return { exitCode: 2, message: 'dry run required' };
38
+ }
39
+ const namespace = flag(ctx.argv, '--namespace');
40
+ if (namespace === undefined) {
41
+ ctx.stderr('kit knowledge export: --namespace <name> is required\n');
42
+ return { exitCode: 2, message: 'namespace required' };
43
+ }
44
+ const res = await knowledgeExportDryRun(path.resolve(ctx.cwd), namespace);
45
+ if (!res.ok) {
46
+ ctx.stderr(`kit knowledge export: ${res.error.message}\n`);
47
+ return { exitCode: 1, message: res.error.message };
48
+ }
49
+ if (ctx.argv.includes('--json')) {
50
+ ctx.stdout(`${JSON.stringify(res.value, null, 2)}\n`);
51
+ return { exitCode: 0 };
52
+ }
53
+ const m = res.value;
54
+ const lines = [
55
+ `Dry run for namespace ${m.namespace}: nothing written, nothing sent.`,
56
+ `Scanned ${m.scanned} rule(s): ${m.shared.length} shareable, ${m.keptLocal} kept local, ${m.refused.length} refused by the secret scan.`,
57
+ ...m.shared.map((s) => ` share ${s.id} ${s.title}`),
58
+ ...m.refused.map((r) => ` refuse ${r.id} ${r.reason}`),
59
+ ];
60
+ ctx.stdout(`${lines.join('\n')}\n`);
61
+ return { exitCode: 0 };
62
+ },
63
+ };
@@ -0,0 +1,104 @@
1
+ // kit learning: record from a file, propose candidates, status, and a non-destructive migration.
2
+ import { promises as fs } from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
6
+ import { learningCommand } from './learning.js';
7
+ import type { CommandContext } from './types.js';
8
+
9
+ function ctx(argv: string[], cwd: string): CommandContext & { out: string[]; err: string[] } {
10
+ const out: string[] = [];
11
+ const err: string[] = [];
12
+ return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
13
+ }
14
+
15
+ const event = (runId: string) => ({
16
+ schemaVersion: 1,
17
+ id: `ev-${runId}`,
18
+ occurredAt: '2026-11-28T10:00:00.000Z',
19
+ runId,
20
+ taskType: 'feature',
21
+ outcome: 'failed',
22
+ stacks: ['node-typescript'],
23
+ affectedFiles: ['packages/core/src/a.ts'],
24
+ ruleViolations: [{ ruleId: 'ARCH-CORE-001', path: 'packages/core/src/a.ts' }],
25
+ verification: { passed: 1, failed: 1, skipped: 0 },
26
+ durationMs: 10,
27
+ });
28
+
29
+ let root: string;
30
+ beforeEach(async () => {
31
+ root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-learning-'));
32
+ });
33
+ afterEach(async () => {
34
+ await fs.rm(root, { recursive: true, force: true });
35
+ });
36
+
37
+ async function recordRun(runId: string): Promise<void> {
38
+ const file = path.join(root, `${runId}.json`);
39
+ await fs.writeFile(file, JSON.stringify(event(runId)));
40
+ expect((await learningCommand.run(ctx(['record', '--file', file], root))).exitCode).toBe(0);
41
+ }
42
+
43
+ describe('kit learning', () => {
44
+ it('record refuses an event with free text and writes nothing', async () => {
45
+ const file = path.join(root, 'bad.json');
46
+ await fs.writeFile(file, JSON.stringify({ ...event('r'), prompt: 'the user said' }));
47
+ const c = ctx(['record', '--file', file], root);
48
+ expect((await learningCommand.run(c)).exitCode).toBe(1);
49
+ expect(c.err.join('')).toContain('validation');
50
+ });
51
+
52
+ it('propose adds candidates only after the recurrence threshold, and status counts them', async () => {
53
+ await recordRun('run-1');
54
+ await recordRun('run-2');
55
+ const early = ctx(['propose'], root);
56
+ await learningCommand.run(early);
57
+ expect(early.out.join('')).toContain('candidates added: 0');
58
+ await recordRun('run-3');
59
+ const p = ctx(['propose'], root);
60
+ await learningCommand.run(p);
61
+ expect(p.out.join('')).toContain('candidates added: 1');
62
+ const s = ctx(['status'], root);
63
+ await learningCommand.run(s);
64
+ expect(s.out.join('')).toContain('events: 3');
65
+ expect(s.out.join('')).toContain('candidates: 1');
66
+ });
67
+
68
+ it('a second propose adds nothing and does not extend a candidate’s expiry', async () => {
69
+ for (const r of ['run-1', 'run-2', 'run-3']) await recordRun(r);
70
+ await learningCommand.run(ctx(['propose'], root));
71
+ const file = path.join(root, '.ai-kit', 'state', 'engineering-memory.json');
72
+ const first = await fs.readFile(file, 'utf8');
73
+ const again = ctx(['propose'], root);
74
+ await learningCommand.run(again);
75
+ expect(again.out.join('')).toContain('candidates added: 0');
76
+ expect(await fs.readFile(file, 'utf8')).toBe(first);
77
+ });
78
+
79
+ it('migrate-memory copies legacy entries, keeps the original file, and is idempotent', async () => {
80
+ const legacyDir = path.join(root, '.ai-kit', 'state');
81
+ await fs.mkdir(legacyDir, { recursive: true });
82
+ const legacy = path.join(legacyDir, 'memory.json');
83
+ const original = JSON.stringify({
84
+ schemaVersion: 1,
85
+ entries: [{
86
+ id: 'mem-1', type: 'semantic', domain: 'billing', summary: 's', content: 'c', confidence: 0.7,
87
+ provenance: ['run-9'], appliedCount: 2, successCount: 1, createdAt: '2026-10-01T00:00:00.000Z', updatedAt: '2026-10-01T00:00:00.000Z',
88
+ }],
89
+ });
90
+ await fs.writeFile(legacy, original);
91
+ const first = ctx(['migrate-memory'], root);
92
+ expect((await learningCommand.run(first)).exitCode).toBe(0);
93
+ expect(first.out.join('')).toContain('migrated 1 of 1');
94
+ expect(first.out.join('')).toContain('lossy:');
95
+ expect(await fs.readFile(legacy, 'utf8')).toBe(original);
96
+ const second = ctx(['migrate-memory'], root);
97
+ await learningCommand.run(second);
98
+ expect(second.out.join('')).toContain('migrated 0 of 1');
99
+ });
100
+
101
+ it('an unknown subcommand is a usage error', async () => {
102
+ expect((await learningCommand.run(ctx(['frobnicate'], root))).exitCode).toBe(2);
103
+ });
104
+ });