@agentic-sdlc-kit/cli 0.0.0-stage → 0.9.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 (309) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -2
  3. package/dist/application/agent/execution-store.d.ts +55 -0
  4. package/dist/application/agent/execution-store.d.ts.map +1 -0
  5. package/dist/application/agent/execution-store.js +91 -0
  6. package/dist/application/agent/execution-store.js.map +1 -0
  7. package/dist/application/agent/gateway.d.ts +74 -0
  8. package/dist/application/agent/gateway.d.ts.map +1 -0
  9. package/dist/application/agent/gateway.js +580 -0
  10. package/dist/application/agent/gateway.js.map +1 -0
  11. package/dist/application/agent/index.d.ts +6 -0
  12. package/dist/application/agent/index.d.ts.map +1 -0
  13. package/dist/application/agent/index.js +18 -0
  14. package/dist/application/agent/index.js.map +1 -0
  15. package/dist/application/agent/orchestrator.d.ts +76 -0
  16. package/dist/application/agent/orchestrator.d.ts.map +1 -0
  17. package/dist/application/agent/orchestrator.js +422 -0
  18. package/dist/application/agent/orchestrator.js.map +1 -0
  19. package/dist/application/agent/providers/claude-code/claude-argv.d.ts +15 -0
  20. package/dist/application/agent/providers/claude-code/claude-argv.d.ts.map +1 -0
  21. package/dist/application/agent/providers/claude-code/claude-argv.js +98 -0
  22. package/dist/application/agent/providers/claude-code/claude-argv.js.map +1 -0
  23. package/dist/application/agent/providers/claude-code/index.d.ts +7 -0
  24. package/dist/application/agent/providers/claude-code/index.d.ts.map +1 -0
  25. package/dist/application/agent/providers/claude-code/index.js +13 -0
  26. package/dist/application/agent/providers/claude-code/index.js.map +1 -0
  27. package/dist/application/agent/providers/claude-code/mod-parity.d.ts +15 -0
  28. package/dist/application/agent/providers/claude-code/mod-parity.d.ts.map +1 -0
  29. package/dist/application/agent/providers/claude-code/mod-parity.js +41 -0
  30. package/dist/application/agent/providers/claude-code/mod-parity.js.map +1 -0
  31. package/dist/application/agent/providers/claude-code/permission-config.d.ts +59 -0
  32. package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -0
  33. package/dist/application/agent/providers/claude-code/permission-config.js +189 -0
  34. package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -0
  35. package/dist/application/agent/providers/claude-code/provider.d.ts +38 -0
  36. package/dist/application/agent/providers/claude-code/provider.d.ts.map +1 -0
  37. package/dist/application/agent/providers/claude-code/provider.js +577 -0
  38. package/dist/application/agent/providers/claude-code/provider.js.map +1 -0
  39. package/dist/application/agent/providers/claude-code/resume-store.d.ts +25 -0
  40. package/dist/application/agent/providers/claude-code/resume-store.d.ts.map +1 -0
  41. package/dist/application/agent/providers/claude-code/resume-store.js +120 -0
  42. package/dist/application/agent/providers/claude-code/resume-store.js.map +1 -0
  43. package/dist/application/agent/providers/claude-code/stream-parser.d.ts +50 -0
  44. package/dist/application/agent/providers/claude-code/stream-parser.d.ts.map +1 -0
  45. package/dist/application/agent/providers/claude-code/stream-parser.js +129 -0
  46. package/dist/application/agent/providers/claude-code/stream-parser.js.map +1 -0
  47. package/dist/application/agent/test-fixture.d.ts +15 -0
  48. package/dist/application/agent/test-fixture.d.ts.map +1 -0
  49. package/dist/application/agent/test-fixture.js +93 -0
  50. package/dist/application/agent/test-fixture.js.map +1 -0
  51. package/dist/application/agent/workspace.d.ts +24 -0
  52. package/dist/application/agent/workspace.d.ts.map +1 -0
  53. package/dist/application/agent/workspace.js +139 -0
  54. package/dist/application/agent/workspace.js.map +1 -0
  55. package/dist/application/dispatcher.d.ts +13 -0
  56. package/dist/application/dispatcher.d.ts.map +1 -0
  57. package/dist/application/dispatcher.js +116 -0
  58. package/dist/application/dispatcher.js.map +1 -0
  59. package/dist/application/index.d.ts +5 -0
  60. package/dist/application/index.d.ts.map +1 -0
  61. package/dist/application/index.js +6 -0
  62. package/dist/application/index.js.map +1 -0
  63. package/dist/application/registry.d.ts +8 -0
  64. package/dist/application/registry.d.ts.map +1 -0
  65. package/dist/application/registry.js +17 -0
  66. package/dist/application/registry.js.map +1 -0
  67. package/dist/application/version.d.ts +2 -0
  68. package/dist/application/version.d.ts.map +1 -0
  69. package/dist/application/version.js +7 -0
  70. package/dist/application/version.js.map +1 -0
  71. package/dist/commands/attach-exclude.d.ts +8 -0
  72. package/dist/commands/attach-exclude.d.ts.map +1 -0
  73. package/dist/commands/attach-exclude.js +48 -0
  74. package/dist/commands/attach-exclude.js.map +1 -0
  75. package/dist/commands/attach-git.d.ts +11 -0
  76. package/dist/commands/attach-git.d.ts.map +1 -0
  77. package/dist/commands/attach-git.js +40 -0
  78. package/dist/commands/attach-git.js.map +1 -0
  79. package/dist/commands/attach-store.d.ts +10 -0
  80. package/dist/commands/attach-store.d.ts.map +1 -0
  81. package/dist/commands/attach-store.js +107 -0
  82. package/dist/commands/attach-store.js.map +1 -0
  83. package/dist/commands/attach.d.ts +8 -0
  84. package/dist/commands/attach.d.ts.map +1 -0
  85. package/dist/commands/attach.js +124 -0
  86. package/dist/commands/attach.js.map +1 -0
  87. package/dist/commands/doctor.d.ts +3 -0
  88. package/dist/commands/doctor.d.ts.map +1 -0
  89. package/dist/commands/doctor.js +68 -0
  90. package/dist/commands/doctor.js.map +1 -0
  91. package/dist/commands/elicit.d.ts +3 -0
  92. package/dist/commands/elicit.d.ts.map +1 -0
  93. package/dist/commands/elicit.js +163 -0
  94. package/dist/commands/elicit.js.map +1 -0
  95. package/dist/commands/evolve.d.ts +3 -0
  96. package/dist/commands/evolve.d.ts.map +1 -0
  97. package/dist/commands/evolve.js +165 -0
  98. package/dist/commands/evolve.js.map +1 -0
  99. package/dist/commands/feature.d.ts +13 -0
  100. package/dist/commands/feature.d.ts.map +1 -0
  101. package/dist/commands/feature.js +326 -0
  102. package/dist/commands/feature.js.map +1 -0
  103. package/dist/commands/fix.d.ts +4 -0
  104. package/dist/commands/fix.d.ts.map +1 -0
  105. package/dist/commands/fix.js +53 -0
  106. package/dist/commands/fix.js.map +1 -0
  107. package/dist/commands/help.d.ts +4 -0
  108. package/dist/commands/help.d.ts.map +1 -0
  109. package/dist/commands/help.js +32 -0
  110. package/dist/commands/help.js.map +1 -0
  111. package/dist/commands/host-apply.d.ts +12 -0
  112. package/dist/commands/host-apply.d.ts.map +1 -0
  113. package/dist/commands/host-apply.js +43 -0
  114. package/dist/commands/host-apply.js.map +1 -0
  115. package/dist/commands/host.d.ts +3 -0
  116. package/dist/commands/host.d.ts.map +1 -0
  117. package/dist/commands/host.js +107 -0
  118. package/dist/commands/host.js.map +1 -0
  119. package/dist/commands/index.d.ts +25 -0
  120. package/dist/commands/index.d.ts.map +1 -0
  121. package/dist/commands/index.js +26 -0
  122. package/dist/commands/index.js.map +1 -0
  123. package/dist/commands/init.d.ts +3 -0
  124. package/dist/commands/init.d.ts.map +1 -0
  125. package/dist/commands/init.js +92 -0
  126. package/dist/commands/init.js.map +1 -0
  127. package/dist/commands/inspect.d.ts +3 -0
  128. package/dist/commands/inspect.d.ts.map +1 -0
  129. package/dist/commands/inspect.js +64 -0
  130. package/dist/commands/inspect.js.map +1 -0
  131. package/dist/commands/install.d.ts +3 -0
  132. package/dist/commands/install.d.ts.map +1 -0
  133. package/dist/commands/install.js +337 -0
  134. package/dist/commands/install.js.map +1 -0
  135. package/dist/commands/journal.d.ts +3 -0
  136. package/dist/commands/journal.d.ts.map +1 -0
  137. package/dist/commands/journal.js +107 -0
  138. package/dist/commands/journal.js.map +1 -0
  139. package/dist/commands/memory.d.ts +3 -0
  140. package/dist/commands/memory.d.ts.map +1 -0
  141. package/dist/commands/memory.js +85 -0
  142. package/dist/commands/memory.js.map +1 -0
  143. package/dist/commands/new.d.ts +3 -0
  144. package/dist/commands/new.d.ts.map +1 -0
  145. package/dist/commands/new.js +68 -0
  146. package/dist/commands/new.js.map +1 -0
  147. package/dist/commands/next.d.ts +3 -0
  148. package/dist/commands/next.d.ts.map +1 -0
  149. package/dist/commands/next.js +107 -0
  150. package/dist/commands/next.js.map +1 -0
  151. package/dist/commands/optimize.d.ts +3 -0
  152. package/dist/commands/optimize.d.ts.map +1 -0
  153. package/dist/commands/optimize.js +28 -0
  154. package/dist/commands/optimize.js.map +1 -0
  155. package/dist/commands/plugin-linker.d.ts +43 -0
  156. package/dist/commands/plugin-linker.d.ts.map +1 -0
  157. package/dist/commands/plugin-linker.js +216 -0
  158. package/dist/commands/plugin-linker.js.map +1 -0
  159. package/dist/commands/refactor.d.ts +3 -0
  160. package/dist/commands/refactor.d.ts.map +1 -0
  161. package/dist/commands/refactor.js +32 -0
  162. package/dist/commands/refactor.js.map +1 -0
  163. package/dist/commands/skills-install-commit.d.ts +34 -0
  164. package/dist/commands/skills-install-commit.d.ts.map +1 -0
  165. package/dist/commands/skills-install-commit.js +113 -0
  166. package/dist/commands/skills-install-commit.js.map +1 -0
  167. package/dist/commands/skills-install-manifest.d.ts +35 -0
  168. package/dist/commands/skills-install-manifest.d.ts.map +1 -0
  169. package/dist/commands/skills-install-manifest.js +89 -0
  170. package/dist/commands/skills-install-manifest.js.map +1 -0
  171. package/dist/commands/skills-install-report.d.ts +12 -0
  172. package/dist/commands/skills-install-report.d.ts.map +1 -0
  173. package/dist/commands/skills-install-report.js +44 -0
  174. package/dist/commands/skills-install-report.js.map +1 -0
  175. package/dist/commands/skills-install-secure.d.ts +14 -0
  176. package/dist/commands/skills-install-secure.d.ts.map +1 -0
  177. package/dist/commands/skills-install-secure.js +96 -0
  178. package/dist/commands/skills-install-secure.js.map +1 -0
  179. package/dist/commands/skills-install.d.ts +15 -0
  180. package/dist/commands/skills-install.d.ts.map +1 -0
  181. package/dist/commands/skills-install.js +182 -0
  182. package/dist/commands/skills-install.js.map +1 -0
  183. package/dist/commands/skills.d.ts +3 -0
  184. package/dist/commands/skills.d.ts.map +1 -0
  185. package/dist/commands/skills.js +217 -0
  186. package/dist/commands/skills.js.map +1 -0
  187. package/dist/commands/types.d.ts +19 -0
  188. package/dist/commands/types.d.ts.map +1 -0
  189. package/dist/commands/types.js +7 -0
  190. package/dist/commands/types.js.map +1 -0
  191. package/dist/commands/uninstall.d.ts +3 -0
  192. package/dist/commands/uninstall.d.ts.map +1 -0
  193. package/dist/commands/uninstall.js +113 -0
  194. package/dist/commands/uninstall.js.map +1 -0
  195. package/dist/commands/validate-plan.d.ts +3 -0
  196. package/dist/commands/validate-plan.d.ts.map +1 -0
  197. package/dist/commands/validate-plan.js +62 -0
  198. package/dist/commands/validate-plan.js.map +1 -0
  199. package/dist/commands/validate-spec.d.ts +3 -0
  200. package/dist/commands/validate-spec.d.ts.map +1 -0
  201. package/dist/commands/validate-spec.js +62 -0
  202. package/dist/commands/validate-spec.js.map +1 -0
  203. package/dist/commands/verify.d.ts +3 -0
  204. package/dist/commands/verify.d.ts.map +1 -0
  205. package/dist/commands/verify.js +103 -0
  206. package/dist/commands/verify.js.map +1 -0
  207. package/dist/commands/version.d.ts +3 -0
  208. package/dist/commands/version.d.ts.map +1 -0
  209. package/dist/commands/version.js +12 -0
  210. package/dist/commands/version.js.map +1 -0
  211. package/dist/index.d.ts +3 -0
  212. package/dist/index.d.ts.map +1 -0
  213. package/dist/index.js +27 -0
  214. package/dist/index.js.map +1 -0
  215. package/dist/output/formatter.d.ts +2 -0
  216. package/dist/output/formatter.d.ts.map +1 -0
  217. package/dist/output/formatter.js +10 -0
  218. package/dist/output/formatter.js.map +1 -0
  219. package/dist/output/index.d.ts +2 -0
  220. package/dist/output/index.d.ts.map +1 -0
  221. package/dist/output/index.js +3 -0
  222. package/dist/output/index.js.map +1 -0
  223. package/package.json +37 -3
  224. package/src/application/agent/execution-store.ts +163 -0
  225. package/src/application/agent/gateway.test.ts +529 -0
  226. package/src/application/agent/gateway.ts +744 -0
  227. package/src/application/agent/index.ts +18 -0
  228. package/src/application/agent/orchestrator.test.ts +341 -0
  229. package/src/application/agent/orchestrator.ts +629 -0
  230. package/src/application/agent/providers/claude-code/claude-argv.ts +119 -0
  231. package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +139 -0
  232. package/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs +125 -0
  233. package/src/application/agent/providers/claude-code/index.ts +28 -0
  234. package/src/application/agent/providers/claude-code/mod-parity.ts +50 -0
  235. package/src/application/agent/providers/claude-code/permission-config.test.ts +221 -0
  236. package/src/application/agent/providers/claude-code/permission-config.ts +242 -0
  237. package/src/application/agent/providers/claude-code/provider.test.ts +378 -0
  238. package/src/application/agent/providers/claude-code/provider.ts +717 -0
  239. package/src/application/agent/providers/claude-code/resume-store.test.ts +161 -0
  240. package/src/application/agent/providers/claude-code/resume-store.ts +157 -0
  241. package/src/application/agent/providers/claude-code/stream-parser.ts +166 -0
  242. package/src/application/agent/test-fixture.ts +131 -0
  243. package/src/application/agent/workspace.test.ts +104 -0
  244. package/src/application/agent/workspace.ts +156 -0
  245. package/src/application/dispatcher.test.ts +108 -0
  246. package/src/application/dispatcher.ts +106 -0
  247. package/src/application/index.ts +5 -0
  248. package/src/application/registry.ts +24 -0
  249. package/src/application/version.ts +7 -0
  250. package/src/commands/attach-exclude.ts +50 -0
  251. package/src/commands/attach-git.ts +50 -0
  252. package/src/commands/attach-store.ts +107 -0
  253. package/src/commands/attach.test.ts +192 -0
  254. package/src/commands/attach.ts +143 -0
  255. package/src/commands/clse.test.ts +181 -0
  256. package/src/commands/doctor.test.ts +29 -0
  257. package/src/commands/doctor.ts +78 -0
  258. package/src/commands/elicit.test.ts +111 -0
  259. package/src/commands/elicit.ts +188 -0
  260. package/src/commands/evolve.ts +209 -0
  261. package/src/commands/feature.test.ts +323 -0
  262. package/src/commands/feature.ts +405 -0
  263. package/src/commands/fix.test.ts +118 -0
  264. package/src/commands/fix.ts +58 -0
  265. package/src/commands/help.test.ts +33 -0
  266. package/src/commands/help.ts +35 -0
  267. package/src/commands/host-apply.ts +61 -0
  268. package/src/commands/host.test.ts +120 -0
  269. package/src/commands/host.ts +125 -0
  270. package/src/commands/index.ts +25 -0
  271. package/src/commands/init.test.ts +87 -0
  272. package/src/commands/init.ts +110 -0
  273. package/src/commands/inspect.test.ts +57 -0
  274. package/src/commands/inspect.ts +73 -0
  275. package/src/commands/install.test.ts +92 -0
  276. package/src/commands/install.ts +389 -0
  277. package/src/commands/journal.ts +118 -0
  278. package/src/commands/memory.ts +96 -0
  279. package/src/commands/new.test.ts +44 -0
  280. package/src/commands/new.ts +77 -0
  281. package/src/commands/next.test.ts +241 -0
  282. package/src/commands/next.ts +124 -0
  283. package/src/commands/optimize.ts +30 -0
  284. package/src/commands/plugin-linker.test.ts +219 -0
  285. package/src/commands/plugin-linker.ts +244 -0
  286. package/src/commands/refactor.ts +34 -0
  287. package/src/commands/skills-install-commit.ts +149 -0
  288. package/src/commands/skills-install-manifest.ts +124 -0
  289. package/src/commands/skills-install-report.ts +60 -0
  290. package/src/commands/skills-install-secure.ts +113 -0
  291. package/src/commands/skills-install.ts +245 -0
  292. package/src/commands/skills.test.ts +449 -0
  293. package/src/commands/skills.ts +247 -0
  294. package/src/commands/stack-commands.test.ts +67 -0
  295. package/src/commands/tier-c-conformance.test.ts +194 -0
  296. package/src/commands/types.ts +26 -0
  297. package/src/commands/uninstall.test.ts +122 -0
  298. package/src/commands/uninstall.ts +116 -0
  299. package/src/commands/validate-plan.test.ts +107 -0
  300. package/src/commands/validate-plan.ts +67 -0
  301. package/src/commands/validate-spec.test.ts +59 -0
  302. package/src/commands/validate-spec.ts +68 -0
  303. package/src/commands/verify.test.ts +117 -0
  304. package/src/commands/verify.ts +112 -0
  305. package/src/commands/version.test.ts +11 -0
  306. package/src/commands/version.ts +14 -0
  307. package/src/index.ts +30 -0
  308. package/src/output/formatter.ts +10 -0
  309. package/src/output/index.ts +2 -0
@@ -0,0 +1,219 @@
1
+ // packages/cli/src/commands/plugin-linker.test.ts
2
+ //
3
+ // Tests the runtime plugin linking introduced to make `kit install` do what
4
+ // docs/HOST_INTEGRATIONS.md documents: the four guard plugins land in
5
+ // <project>/.claude/plugins/ with hooks module paths that actually resolve.
6
+ //
7
+ // The shipped manifests declare `./register.ts` (TypeScript source, loaded
8
+ // directly by Claude Code — no build step), so the fixtures below write a
9
+ // register.ts source file, not a dist bundle.
10
+ import { promises as fs } from 'node:fs';
11
+ import os from 'node:os';
12
+ import path from 'node:path';
13
+ import { describe, expect, it } from 'vitest';
14
+ import {
15
+ RUNTIME_PLUGIN_NAMES,
16
+ linkRuntimePlugins,
17
+ resolveKitPluginsDir,
18
+ validatePluginHooks,
19
+ } from './plugin-linker.js';
20
+
21
+ async function makeFakeKit(kitRoot: string, complete: boolean): Promise<void> {
22
+ for (const name of RUNTIME_PLUGIN_NAMES) {
23
+ const pluginDir = path.join(kitRoot, 'plugins', name);
24
+ await fs.mkdir(path.join(pluginDir, '.claude-plugin'), { recursive: true });
25
+ await fs.mkdir(path.join(pluginDir, 'hooks'), { recursive: true });
26
+ await fs.writeFile(
27
+ path.join(pluginDir, '.claude-plugin', 'plugin.json'),
28
+ JSON.stringify({ name, version: '0.8.0', description: `${name} test plugin` }),
29
+ 'utf8',
30
+ );
31
+ await fs.writeFile(
32
+ path.join(pluginDir, 'hooks', 'hooks.json'),
33
+ JSON.stringify({ description: `${name} hooks`, modules: ['./register.ts'] }),
34
+ 'utf8',
35
+ );
36
+ if (complete) {
37
+ // The shipped layout: TypeScript source inside hooks/, committed.
38
+ await fs.writeFile(
39
+ path.join(pluginDir, 'hooks', 'register.ts'),
40
+ 'export function register(): void {}\n',
41
+ 'utf8',
42
+ );
43
+ }
44
+ }
45
+ }
46
+
47
+ describe('plugin-linker', () => {
48
+ it('links all four plugins and the hooks modules resolve through the link', async () => {
49
+ const kitRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-kitroot-'));
50
+ const project = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-project-'));
51
+ try {
52
+ await makeFakeKit(kitRoot, true);
53
+ const results = await linkRuntimePlugins(project, kitRoot);
54
+ expect(results).toHaveLength(4);
55
+ for (const r of results) {
56
+ expect(r.status).toBe('linked');
57
+ // The declared hooks module must exist THROUGH the project symlink —
58
+ // exactly what the Claude Code plugin validator checks.
59
+ const throughLink = path.resolve(
60
+ path.dirname(r.linkPath),
61
+ path.basename(r.linkPath),
62
+ 'hooks/register.ts',
63
+ );
64
+ await expect(fs.access(throughLink)).resolves.toBeUndefined();
65
+ }
66
+ // Idempotent: re-running reports already-linked.
67
+ const again = await linkRuntimePlugins(project, kitRoot);
68
+ for (const r of again) expect(r.status).toBe('already-linked');
69
+ } finally {
70
+ await fs.rm(kitRoot, { recursive: true, force: true });
71
+ await fs.rm(project, { recursive: true, force: true });
72
+ }
73
+ });
74
+
75
+ it('reports incomplete (with fix instructions) when the hooks module is missing', async () => {
76
+ const kitRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-kitroot-'));
77
+ const project = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-project-'));
78
+ try {
79
+ await makeFakeKit(kitRoot, false);
80
+ const results = await linkRuntimePlugins(project, kitRoot);
81
+ for (const r of results) {
82
+ expect(r.status).toBe('incomplete');
83
+ expect(r.detail).toContain('incomplete');
84
+ // And crucially: no symlink was created for a broken plugin.
85
+ await expect(fs.lstat(r.linkPath)).rejects.toThrow();
86
+ }
87
+ } finally {
88
+ await fs.rm(kitRoot, { recursive: true, force: true });
89
+ await fs.rm(project, { recursive: true, force: true });
90
+ }
91
+ });
92
+
93
+ it('validatePluginHooks flags a manifest pointing at a missing module', async () => {
94
+ const kitRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-kitroot-'));
95
+ try {
96
+ await makeFakeKit(kitRoot, false);
97
+ const dir = path.join(kitRoot, 'plugins', 'sdlc-guard');
98
+ const res = await validatePluginHooks(dir);
99
+ expect(res.ok).toBe(false);
100
+ expect(res.missing).toContain('./register.ts');
101
+ } finally {
102
+ await fs.rm(kitRoot, { recursive: true, force: true });
103
+ }
104
+ });
105
+
106
+ it('validatePluginHooks resolves module paths relative to the hooks/ directory (like Claude Code)', async () => {
107
+ const kitRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-kitroot-'));
108
+ try {
109
+ // A manifest whose path resolves only against hooks/: the module
110
+ // lives next to the manifest, not at the plugin root.
111
+ const pluginDir = path.join(kitRoot, 'plugins', 'sdlc-guard');
112
+ await fs.mkdir(path.join(pluginDir, 'hooks'), { recursive: true });
113
+ await fs.writeFile(
114
+ path.join(pluginDir, 'hooks', 'register.ts'),
115
+ 'export function register(): void {}',
116
+ 'utf8',
117
+ );
118
+ await fs.writeFile(
119
+ path.join(pluginDir, 'hooks', 'hooks.json'),
120
+ JSON.stringify({ modules: ['./register.ts'] }),
121
+ 'utf8',
122
+ );
123
+ const res = await validatePluginHooks(pluginDir);
124
+ expect(res.ok).toBe(true);
125
+ expect(res.missing).toEqual([]);
126
+ } finally {
127
+ await fs.rm(kitRoot, { recursive: true, force: true });
128
+ }
129
+ });
130
+
131
+ it('resolveKitPluginsDir returns null for a layout without plugins/', async () => {
132
+ const empty = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-empty-'));
133
+ try {
134
+ expect(resolveKitPluginsDir(empty)).toBeNull();
135
+ } finally {
136
+ await fs.rm(empty, { recursive: true, force: true });
137
+ }
138
+ });
139
+
140
+ describe('ownership: never adopt or replace something the kit did not create', () => {
141
+ const withKit = async (
142
+ fn: (kitRoot: string, project: string, linkPath: (n: string) => string) => Promise<void>,
143
+ ): Promise<void> => {
144
+ const kitRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-kitroot-'));
145
+ const project = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-project-'));
146
+ try {
147
+ await makeFakeKit(kitRoot, true);
148
+ await fn(kitRoot, project, (n) => path.join(project, '.claude', 'plugins', n));
149
+ } finally {
150
+ await fs.rm(kitRoot, { recursive: true, force: true });
151
+ await fs.rm(project, { recursive: true, force: true });
152
+ }
153
+ };
154
+ const only = (rs: Awaited<ReturnType<typeof linkRuntimePlugins>>, name: string) =>
155
+ rs.find((r) => r.name === name)!;
156
+
157
+ it('reports conflict for a symlink to somewhere else and leaves it untouched', async () => {
158
+ await withKit(async (kitRoot, project, link) => {
159
+ const foreign = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-foreign-'));
160
+ await fs.mkdir(path.dirname(link('sdlc-guard')), { recursive: true });
161
+ await fs.symlink(foreign, link('sdlc-guard'), 'dir');
162
+ const r = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
163
+ expect(r.status).toBe('conflict');
164
+ expect(await fs.readlink(link('sdlc-guard'))).toBe(foreign);
165
+ await fs.rm(foreign, { recursive: true, force: true });
166
+ });
167
+ });
168
+
169
+ it('reports conflict for a dangling symlink', async () => {
170
+ await withKit(async (kitRoot, project, link) => {
171
+ await fs.mkdir(path.dirname(link('sdlc-guard')), { recursive: true });
172
+ await fs.symlink('/nonexistent/kit-target', link('sdlc-guard'), 'dir');
173
+ expect(only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard').status).toBe('conflict');
174
+ });
175
+ });
176
+
177
+ it('reports conflict (not already-linked) for a real directory at the path', async () => {
178
+ await withKit(async (kitRoot, project, link) => {
179
+ await fs.mkdir(link('sdlc-guard'), { recursive: true });
180
+ await fs.writeFile(path.join(link('sdlc-guard'), 'mine.txt'), 'user data');
181
+ const r = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
182
+ expect(r.status).toBe('conflict');
183
+ expect(await fs.readFile(path.join(link('sdlc-guard'), 'mine.txt'), 'utf8')).toBe('user data');
184
+ });
185
+ });
186
+
187
+ it("reports the verified target for the kit's own link, on create and on re-run", async () => {
188
+ await withKit(async (kitRoot, project) => {
189
+ const first = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
190
+ const second = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
191
+ expect(first.status).toBe('linked');
192
+ expect(second.status).toBe('already-linked');
193
+ expect(second.target).toBe(first.target);
194
+ expect(first.target).toBe(path.join(kitRoot, 'plugins', 'sdlc-guard'));
195
+ });
196
+ });
197
+
198
+ it('refuses to write through a symlinked .claude directory', async () => {
199
+ await withKit(async (kitRoot, project) => {
200
+ const elsewhere = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-elsewhere-'));
201
+ await fs.symlink(elsewhere, path.join(project, '.claude'), 'dir');
202
+ const results = await linkRuntimePlugins(project, kitRoot);
203
+ for (const r of results) expect(r.status).toBe('conflict');
204
+ expect(await fs.readdir(elsewhere)).toEqual([]);
205
+ await fs.rm(elsewhere, { recursive: true, force: true });
206
+ });
207
+ });
208
+
209
+ it('treats a hooks.json that declares no modules as incomplete', async () => {
210
+ await withKit(async (kitRoot, project) => {
211
+ await fs.writeFile(
212
+ path.join(kitRoot, 'plugins', 'sdlc-guard', 'hooks', 'hooks.json'),
213
+ JSON.stringify({ modules: [] }),
214
+ );
215
+ expect(only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard').status).toBe('incomplete');
216
+ });
217
+ });
218
+ });
219
+ });
@@ -0,0 +1,244 @@
1
+ // packages/cli/src/commands/plugin-linker.ts
2
+ //
3
+ // Runtime plugin (Mod) linking for `kit install`.
4
+ //
5
+ // The kit ships four Claude Code plugins (model-router, run-observer,
6
+ // sdlc-guard, secret-guard) in `plugins/` of the kit repository. Claude Code
7
+ // discovers them via `<plugin>/.claude-plugin/plugin.json` and loads their
8
+ // hook modules from the paths declared in `hooks/hooks.json`.
9
+ //
10
+ // IMPORTANT (official docs, verified November 2026): module paths in
11
+ // hooks/hooks.json resolve relative to the hooks/ DIRECTORY (where the
12
+ // manifest lives), and Claude Code loads `.ts` hooks modules DIRECTLY —
13
+ // no build step. The shipped manifests therefore declare `./register.ts`
14
+ // (source committed in the repository), so a fresh clone validates as-is.
15
+ //
16
+ // This module:
17
+ // 1. Locates the kit's `plugins/` directory relative to the CLI's own
18
+ // installed location (so it works through `pnpm link --global`).
19
+ // 2. Validates each plugin's hooks module path actually exists, resolved
20
+ // the same way the Claude Code plugin validator resolves it (relative
21
+ // to the hooks/ directory).
22
+ // 3. Creates idempotent symlinks in `<project>/.claude/plugins/<name>`.
23
+ //
24
+ // Per the kit's no-silent-fabrication principle: a plugin whose hooks module
25
+ // is missing is reported as a WARNING with a fix instruction, never silently
26
+ // skipped, and never reported as installed when it is not.
27
+
28
+ import { existsSync, promises as fs } from 'node:fs';
29
+ import path from 'node:path';
30
+ import { fileURLToPath } from 'node:url';
31
+
32
+ export const RUNTIME_PLUGIN_NAMES = [
33
+ 'sdlc-guard',
34
+ 'secret-guard',
35
+ 'model-router',
36
+ 'run-observer',
37
+ ] as const;
38
+
39
+ export interface PluginLinkResult {
40
+ name: string;
41
+ /** Where the symlink was created (or already existed) inside the project. */
42
+ linkPath: string;
43
+ /**
44
+ * `conflict`: something that is not the kit's own link to this plugin
45
+ * occupies the path (foreign or dangling symlink, real file/dir, or a
46
+ * symlinked parent). Left untouched and never recorded as kit-owned.
47
+ */
48
+ status: 'linked' | 'already-linked' | 'incomplete' | 'not-found' | 'conflict';
49
+ /** For linked/already-linked: the absolute path the link points at. */
50
+ target?: string;
51
+ detail?: string;
52
+ }
53
+
54
+ /**
55
+ * Resolve the kit repository's `plugins/` directory from the CLI's own
56
+ * module location. `packages/cli/dist/commands/plugin-linker.js` ->
57
+ * `<repo>/plugins`. Returns null when the layout does not match (e.g. the
58
+ * CLI was installed from a tarball without the plugins).
59
+ *
60
+ * `overrideRoot` exists for tests so they can point at a fake kit layout.
61
+ */
62
+ export function resolveKitPluginsDir(overrideRoot?: string): string | null {
63
+ if (overrideRoot) {
64
+ const dir = path.join(overrideRoot, 'plugins');
65
+ return existsSync(dir) ? dir : null;
66
+ }
67
+ // this file: <repo>/packages/cli/dist/commands/plugin-linker.js
68
+ const here = path.dirname(fileURLToPath(import.meta.url));
69
+ const repoRoot = path.resolve(here, '..', '..', '..', '..');
70
+ const pluginsDir = path.join(repoRoot, 'plugins');
71
+ return existsSync(pluginsDir) ? pluginsDir : null;
72
+ }
73
+
74
+ /**
75
+ * Validate that the hooks module paths declared by a plugin's
76
+ * `hooks/hooks.json` resolve to real files. Paths resolve relative to the
77
+ * hooks/ directory — the same base the Claude Code plugin validator uses
78
+ * (an easy mistake: relative to the plugin root the same string would point
79
+ * one directory too high).
80
+ */
81
+ export async function validatePluginHooks(
82
+ pluginDir: string,
83
+ ): Promise<{ ok: boolean; missing: string[] }> {
84
+ const hooksDir = path.join(pluginDir, 'hooks');
85
+ const manifestPath = path.join(hooksDir, 'hooks.json');
86
+ let modules: string[] = [];
87
+ try {
88
+ const raw = await fs.readFile(manifestPath, 'utf8');
89
+ const parsed = JSON.parse(raw) as { modules?: unknown };
90
+ if (Array.isArray(parsed.modules)) {
91
+ modules = parsed.modules.filter((m): m is string => typeof m === 'string');
92
+ }
93
+ } catch {
94
+ return { ok: false, missing: [manifestPath] };
95
+ }
96
+ if (modules.length === 0) {
97
+ return { ok: false, missing: [`${manifestPath} (declares no hooks modules)`] };
98
+ }
99
+ const missing: string[] = [];
100
+ for (const mod of modules) {
101
+ const resolved = path.resolve(hooksDir, mod);
102
+ try {
103
+ await fs.access(resolved);
104
+ } catch {
105
+ missing.push(mod);
106
+ }
107
+ }
108
+ return { ok: missing.length === 0, missing };
109
+ }
110
+
111
+ /** Where a symlink points, resolved to an absolute path (works for dangling links). */
112
+ export async function linkTarget(linkPath: string): Promise<string> {
113
+ return path.resolve(path.dirname(linkPath), await fs.readlink(linkPath));
114
+ }
115
+
116
+ type Occupant = 'none' | 'ours' | 'foreign';
117
+
118
+ /**
119
+ * Classify what already sits at `linkPath`. Only a symlink that resolves to
120
+ * this kit's own plugin directory is "ours"; a foreign or dangling symlink,
121
+ * a real file or directory are all "foreign".
122
+ */
123
+ async function classifyOccupant(linkPath: string, pluginDir: string): Promise<Occupant> {
124
+ const stat = await fs.lstat(linkPath).catch(() => null);
125
+ if (!stat) return 'none';
126
+ if (!stat.isSymbolicLink()) return 'foreign';
127
+ try {
128
+ return (await fs.realpath(linkPath)) === (await fs.realpath(pluginDir)) ? 'ours' : 'foreign';
129
+ } catch {
130
+ return 'foreign'; // dangling
131
+ }
132
+ }
133
+
134
+ /** A symlinked .claude or .claude/plugins would redirect every write elsewhere. */
135
+ async function symlinkedParent(projectRoot: string): Promise<string | null> {
136
+ for (const dir of [path.join(projectRoot, '.claude'), path.join(projectRoot, '.claude', 'plugins')]) {
137
+ if ((await fs.lstat(dir).catch(() => null))?.isSymbolicLink()) return dir;
138
+ }
139
+ return null;
140
+ }
141
+
142
+ /**
143
+ * Link the runtime plugins into `<project>/.claude/plugins/`.
144
+ * Never throws: every failure is reported per-plugin in the results.
145
+ */
146
+ export async function linkRuntimePlugins(
147
+ projectRoot: string,
148
+ overrideKitRoot?: string,
149
+ ): Promise<PluginLinkResult[]> {
150
+ const pluginsDir = resolveKitPluginsDir(overrideKitRoot);
151
+ const results: PluginLinkResult[] = [];
152
+
153
+ if (!pluginsDir) {
154
+ return RUNTIME_PLUGIN_NAMES.map((name) => ({
155
+ name,
156
+ linkPath: path.join(projectRoot, '.claude', 'plugins', name),
157
+ status: 'not-found' as const,
158
+ detail:
159
+ 'kit plugins/ directory not found next to the CLI installation. ' +
160
+ 'Link plugins manually (see docs/HOST_INTEGRATIONS.md).',
161
+ }));
162
+ }
163
+
164
+ const targetBase = path.join(projectRoot, '.claude', 'plugins');
165
+ const redirected = await symlinkedParent(projectRoot);
166
+ if (redirected !== null) {
167
+ return RUNTIME_PLUGIN_NAMES.map((name) => ({
168
+ name,
169
+ linkPath: path.join(targetBase, name),
170
+ status: 'conflict' as const,
171
+ detail: `refusing to link: ${redirected} is a symlink, so links would land outside the project`,
172
+ }));
173
+ }
174
+ await fs.mkdir(targetBase, { recursive: true });
175
+
176
+ for (const name of RUNTIME_PLUGIN_NAMES) {
177
+ const pluginDir = path.join(pluginsDir, name);
178
+ const linkPath = path.join(targetBase, name);
179
+ try {
180
+ // Does the plugin source exist at all?
181
+ await fs.access(path.join(pluginDir, '.claude-plugin', 'plugin.json'));
182
+ } catch {
183
+ results.push({
184
+ name,
185
+ linkPath,
186
+ status: 'not-found',
187
+ detail: `plugin source not found at ${pluginDir}`,
188
+ });
189
+ continue;
190
+ }
191
+
192
+ // Validate hooks modules BEFORE linking so we never install a plugin
193
+ // whose hook module path is broken (which is what the Claude Code
194
+ // plugin validator would reject). The shipped manifests point at
195
+ // TypeScript source inside the repository, so a missing module means
196
+ // an incomplete plugin directory (bad clone, partial copy) — not a
197
+ // missing build.
198
+ //
199
+ // Note: validatePluginHooks resolves module paths relative to the
200
+ // hooks/ directory — mirroring the real Claude Code validator — so a
201
+ // manifest that passes here also passes `claude plugin validate`.
202
+ const hooks = await validatePluginHooks(pluginDir);
203
+ if (!hooks.ok) {
204
+ results.push({
205
+ name,
206
+ linkPath,
207
+ status: 'incomplete',
208
+ detail:
209
+ `hooks module(s) ${hooks.missing.join(', ')} not found under ${pluginDir}. ` +
210
+ 'The plugin directory is incomplete — reinstall or repair the kit repository, then re-run `kit install`.',
211
+ });
212
+ continue;
213
+ }
214
+
215
+ // Idempotent linking. Only our own link counts as already linked;
216
+ // anything else at the path is a conflict and is never adopted.
217
+ const occupant = await classifyOccupant(linkPath, pluginDir);
218
+ if (occupant === 'ours') {
219
+ results.push({ name, linkPath, status: 'already-linked', target: await linkTarget(linkPath) });
220
+ continue;
221
+ }
222
+ if (occupant === 'foreign') {
223
+ results.push({
224
+ name,
225
+ linkPath,
226
+ status: 'conflict',
227
+ detail: 'path exists and is not a link to this kit plugin; left untouched and not recorded as kit-owned',
228
+ });
229
+ continue;
230
+ }
231
+ try {
232
+ await fs.symlink(pluginDir, linkPath, 'dir');
233
+ results.push({ name, linkPath, status: 'linked', target: await linkTarget(linkPath) });
234
+ } catch (err) {
235
+ results.push({
236
+ name,
237
+ linkPath,
238
+ status: 'not-found',
239
+ detail: `failed to create symlink: ${err instanceof Error ? err.message : String(err)}`,
240
+ });
241
+ }
242
+ }
243
+ return results;
244
+ }
@@ -0,0 +1,34 @@
1
+ // packages/cli/src/commands/refactor.ts
2
+ //
3
+ // `kit refactor` — informational. The /kit:refactor workflow is driven
4
+ // by the /kit:refactor slash command in the host runtime.
5
+
6
+ import type { Command, CommandContext, CommandResult } from './types.js';
7
+
8
+ export const refactorCommand: Command = {
9
+ name: 'refactor',
10
+ summary: 'Show how to start a refactoring workflow (/kit:refactor).',
11
+ run(ctx: CommandContext): CommandResult {
12
+ const lines: string[] = [];
13
+ lines.push('kit refactor — Refactoring workflow');
14
+ lines.push('');
15
+ lines.push('The /kit:refactor workflow is driven by your AI assistant.');
16
+ lines.push('');
17
+ lines.push(' /kit:refactor <target module and goal>');
18
+ lines.push('');
19
+ lines.push('Lifecycle (M9):');
20
+ lines.push(' contract → discover-deps → characterization-tests →');
21
+ lines.push(' target-structure → identify-patterns →');
22
+ lines.push(' incremental-refactor → contract-validation →');
23
+ lines.push(' regression-testing → quality-comparison → review');
24
+ lines.push('');
25
+ lines.push('Constraints:');
26
+ lines.push(' - Preserve observable behavior unless behavior changes are');
27
+ lines.push(' explicitly approved.');
28
+ lines.push(' - Establish baseline tests before structural changes.');
29
+ lines.push(' - Do not use a design pattern simply because it exists.');
30
+ lines.push(' - Avoid broad renaming or formatting changes unrelated to the task.');
31
+ ctx.stdout(lines.join('\n'));
32
+ return { exitCode: 0 };
33
+ },
34
+ };
@@ -0,0 +1,149 @@
1
+ // packages/cli/src/commands/skills-install-commit.ts
2
+ //
3
+ // The staged-commit half of `kit skills install` (see ./skills-install.ts).
4
+ //
5
+ // Order of operations: plan (decide per skill, nothing written yet) →
6
+ // stage (copy into .ai-kit/tmp staging and validate) → commit (rename into
7
+ // place, replaced directories moved aside first). A commit failure rolls
8
+ // back everything this commit changed; if the rollback itself fails, the
9
+ // staging directory is kept for manual recovery instead of being deleted.
10
+
11
+ import { promises as fs } from 'node:fs';
12
+ import path from 'node:path';
13
+ import {
14
+ type SkillInstallStatus,
15
+ type SkillsManifest,
16
+ ownedSkillNames,
17
+ } from './skills-install-manifest.js';
18
+ import { copyTreeSecure, validateSkillFrontmatter } from './skills-install-secure.js';
19
+
20
+ export type SkillAction = 'install' | 'skipped-existing' | 'skipped-unowned';
21
+
22
+ export interface SkillPlanEntry {
23
+ name: string;
24
+ action: SkillAction;
25
+ }
26
+
27
+ /** Commit-phase failure. `clean` records whether the rollback fully restored the project. */
28
+ export class CommitError extends Error {
29
+ constructor(
30
+ message: string,
31
+ readonly clean: boolean,
32
+ ) {
33
+ super(message);
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Decide the action per skill before anything is written. `--force` may
39
+ * replace only directories the kit owns (manifest `installed` records for
40
+ * this target directory); anything else that already exists is reported and
41
+ * left untouched.
42
+ */
43
+ export async function planSkillInstalls(
44
+ names: readonly string[],
45
+ targetDir: string,
46
+ force: boolean,
47
+ manifest: SkillsManifest,
48
+ into: string,
49
+ ): Promise<SkillPlanEntry[]> {
50
+ const owned = ownedSkillNames(manifest, into);
51
+ const plan: SkillPlanEntry[] = [];
52
+ for (const name of names) {
53
+ const dest = path.join(targetDir, name);
54
+ const exists = await fs.access(dest).then(
55
+ () => true,
56
+ () => false,
57
+ );
58
+ if (!exists) plan.push({ name, action: 'install' });
59
+ else if (!force) plan.push({ name, action: 'skipped-existing' });
60
+ else if (owned.has(name)) plan.push({ name, action: 'install' });
61
+ else plan.push({ name, action: 'skipped-unowned' });
62
+ }
63
+ return plan;
64
+ }
65
+
66
+ /**
67
+ * Copy every planned skill into the staging tree and validate it there.
68
+ * A validation failure leaves the project untouched: staging is discarded
69
+ * by the caller.
70
+ */
71
+ export async function stageSkills(
72
+ skillsDir: string,
73
+ plan: SkillPlanEntry[],
74
+ stagingRoot: string,
75
+ ): Promise<Map<string, string>> {
76
+ const staged = new Map<string, string>();
77
+ for (const entry of plan) {
78
+ if (entry.action !== 'install') continue;
79
+ const stage = path.join(stagingRoot, 'skills', entry.name);
80
+ await copyTreeSecure(path.join(skillsDir, entry.name), stage);
81
+ await validateSkillFrontmatter(path.join(stage, 'SKILL.md'), entry.name);
82
+ staged.set(entry.name, stage);
83
+ }
84
+ return staged;
85
+ }
86
+
87
+ /**
88
+ * Commit staged directories into the target. Replaced directories are moved
89
+ * aside first; on failure everything the kit changed in this commit is rolled
90
+ * back (best effort, honestly reported), so a partial install never stands.
91
+ * If the rollback itself fails, staging is kept for manual recovery.
92
+ */
93
+ export async function commitStagedSkills(
94
+ staged: ReadonlyMap<string, string>,
95
+ targetDir: string,
96
+ stagingRoot: string,
97
+ ): Promise<void> {
98
+ const applied: string[] = [];
99
+ const movedAside: Array<{ dest: string; backup: string }> = [];
100
+ try {
101
+ await fs.mkdir(targetDir, { recursive: true });
102
+ for (const [name, stage] of staged) {
103
+ const dest = path.join(targetDir, name);
104
+ const exists = await fs.access(dest).then(
105
+ () => true,
106
+ () => false,
107
+ );
108
+ if (exists) {
109
+ const backup = path.join(stagingRoot, 'backups', name);
110
+ await fs.mkdir(path.dirname(backup), { recursive: true });
111
+ await fs.rename(dest, backup);
112
+ movedAside.push({ dest, backup });
113
+ }
114
+ await fs.rename(stage, dest);
115
+ applied.push(dest);
116
+ }
117
+ } catch (err) {
118
+ let clean = true;
119
+ const markDirty = (): void => {
120
+ clean = false;
121
+ };
122
+ for (const dest of applied) {
123
+ await fs.rm(dest, { recursive: true, force: true }).catch(markDirty);
124
+ }
125
+ for (const { dest, backup } of movedAside) {
126
+ const present = await fs.access(dest).then(
127
+ () => true,
128
+ () => false,
129
+ );
130
+ if (!present) await fs.rename(backup, dest).catch(markDirty);
131
+ }
132
+ const detail = err instanceof Error ? err.message : String(err);
133
+ throw new CommitError(
134
+ clean
135
+ ? `staged commit failed and was rolled back: ${detail}`
136
+ : `staged commit failed; ROLLBACK INCOMPLETE — the staging directory ${stagingRoot} ` +
137
+ `was kept for manual recovery: ${detail}`,
138
+ clean,
139
+ );
140
+ }
141
+ }
142
+
143
+ /** Derive the manifest statuses from the plan. */
144
+ export function statusesFromPlan(plan: SkillPlanEntry[]): SkillInstallStatus[] {
145
+ return plan.map((p) => ({
146
+ name: p.name,
147
+ status: p.action === 'install' ? 'installed' : p.action,
148
+ }));
149
+ }