@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,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
+ }
@@ -0,0 +1,192 @@
1
+ // packages/cli/src/commands/attach.test.ts
2
+ import { execFileSync } from 'node:child_process';
3
+ import { promises as fs } from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
+ import { attachCommand } from './attach.js';
8
+ import { BLOCK_BEGIN, stripBlock, withBlock } from './attach-exclude.js';
9
+ import type { CommandContext } from './types.js';
10
+
11
+ const git = (cwd: string, ...args: string[]): string =>
12
+ execFileSync('git', args, { cwd, encoding: 'utf8' });
13
+
14
+ async function mkrepo(dir: string, files: Record<string, string> = { 'README.md': 'hi' }) {
15
+ await fs.mkdir(dir, { recursive: true });
16
+ git(dir, 'init', '-q');
17
+ git(dir, 'config', 'user.email', 't@t');
18
+ git(dir, 'config', 'user.name', 't');
19
+ for (const [rel, body] of Object.entries(files)) {
20
+ await fs.mkdir(path.dirname(path.join(dir, rel)), { recursive: true });
21
+ await fs.writeFile(path.join(dir, rel), body);
22
+ }
23
+ git(dir, 'add', '-A');
24
+ git(dir, 'commit', '-qm', 'init');
25
+ }
26
+
27
+ const run = async (cwd: string, ...argv: string[]) => {
28
+ const out: string[] = [];
29
+ const err: string[] = [];
30
+ const ctx: CommandContext = {
31
+ argv,
32
+ cwd,
33
+ stdout: (s) => void out.push(s),
34
+ stderr: (s) => void err.push(s),
35
+ };
36
+ const r = await attachCommand.run(ctx);
37
+ return { ...r, out: out.join('\n'), err: err.join('\n') };
38
+ };
39
+
40
+ const clean = (dir: string): boolean => git(dir, 'status', '--porcelain').trim() === '';
41
+ const exists = (p: string) => fs.lstat(p).then(() => true, () => false);
42
+
43
+ let tmp: string;
44
+ let store: string;
45
+ beforeEach(async () => {
46
+ tmp = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'kit-attach-')));
47
+ store = path.join(tmp, 'store');
48
+ process.env['KIT_ATTACH_HOME'] = store;
49
+ });
50
+ afterEach(async () => {
51
+ delete process.env['KIT_ATTACH_HOME'];
52
+ await fs.rm(tmp, { recursive: true, force: true });
53
+ });
54
+
55
+ describe('attach exclude block (pure)', () => {
56
+ it('is idempotent and preserves foreign lines', () => {
57
+ const once = withBlock('node_modules\n', ['a', 'b']);
58
+ expect(withBlock(once, ['a', 'b'])).toBe(once);
59
+ expect(stripBlock(once)).toBe('node_modules\n');
60
+ });
61
+ });
62
+
63
+ describe('kit attach', () => {
64
+ it('local: invisible to git, writes work, idempotent', async () => {
65
+ const repo = path.join(tmp, 'a');
66
+ await mkrepo(repo);
67
+ const r = await run(repo, 'local');
68
+ expect(r.exitCode).toBe(0);
69
+ await fs.writeFile(path.join(repo, '.ai-kit', 'project.yml'), 'x');
70
+ expect(clean(repo)).toBe(true);
71
+ expect((await run(repo, 'local')).exitCode).toBe(0);
72
+ const ex = await fs.readFile(path.join(repo, '.git', 'info', 'exclude'), 'utf8');
73
+ expect(ex.split(BLOCK_BEGIN).length - 1).toBe(1);
74
+ });
75
+
76
+ it('global: symlink is ignored and bytes land in the store', async () => {
77
+ const repo = path.join(tmp, 'b');
78
+ await mkrepo(repo);
79
+ expect((await run(repo, 'global')).exitCode).toBe(0);
80
+ await fs.writeFile(path.join(repo, '.ai-kit', 'project.yml'), 'x');
81
+ expect((await fs.lstat(path.join(repo, '.ai-kit'))).isSymbolicLink()).toBe(true);
82
+ expect(clean(repo)).toBe(true);
83
+ const target = await fs.readlink(path.join(repo, '.ai-kit'));
84
+ expect(target.startsWith(store)).toBe(true);
85
+ expect(await fs.readFile(path.join(target, 'project.yml'), 'utf8')).toBe('x');
86
+ });
87
+
88
+ it('refuses when a managed path has tracked files, changing nothing', async () => {
89
+ const repo = path.join(tmp, 'c');
90
+ await mkrepo(repo, { 'README.md': 'hi', 'docs/plans/keep.md': 'k' });
91
+ for (const mode of ['local', 'global']) {
92
+ const r = await run(repo, mode);
93
+ expect(r.exitCode).toBe(1);
94
+ expect(r.err).toContain('tracked files');
95
+ }
96
+ expect(await exists(path.join(repo, '.ai-kit'))).toBe(false);
97
+ });
98
+
99
+ it('global without --adopt refuses untracked content and is atomic', async () => {
100
+ const repo = path.join(tmp, 'd1');
101
+ await mkrepo(repo);
102
+ await fs.mkdir(path.join(repo, 'docs/plans'), { recursive: true });
103
+ await fs.writeFile(path.join(repo, 'docs/plans/old.md'), 'old');
104
+ const r = await run(repo, 'global');
105
+ expect(r.exitCode).toBe(1);
106
+ expect(r.err).toContain('--adopt');
107
+ expect(await exists(path.join(repo, '.ai-kit'))).toBe(false); // no half-attach
108
+ });
109
+
110
+ it('global --adopt migrates untracked content into the store', async () => {
111
+ const repo = path.join(tmp, 'd2');
112
+ await mkrepo(repo);
113
+ await fs.mkdir(path.join(repo, 'docs/plans'), { recursive: true });
114
+ await fs.writeFile(path.join(repo, 'docs/plans/old.md'), 'old');
115
+ expect((await run(repo, 'global', '--adopt')).exitCode).toBe(0);
116
+ expect(await fs.readFile(path.join(repo, 'docs/plans/old.md'), 'utf8')).toBe('old');
117
+ expect((await fs.lstat(path.join(repo, 'docs/plans'))).isSymbolicLink()).toBe(true);
118
+ expect(clean(repo)).toBe(true);
119
+ });
120
+
121
+ it('--adopt is rejected for local', async () => {
122
+ const repo = path.join(tmp, 'e1');
123
+ await mkrepo(repo);
124
+ const r = await run(repo, 'local', '--adopt');
125
+ expect(r.exitCode).toBe(1);
126
+ expect(r.err).toContain("only valid with 'global'");
127
+ });
128
+
129
+ it('local refuses to run over a global symlink', async () => {
130
+ const repo = path.join(tmp, 'e2');
131
+ await mkrepo(repo);
132
+ await run(repo, 'global');
133
+ const r = await run(repo, 'local');
134
+ expect(r.exitCode).toBe(1);
135
+ expect(r.err).toContain('detach');
136
+ });
137
+
138
+ it('detach removes symlinks and exclusion but keeps store data', async () => {
139
+ const repo = path.join(tmp, 'f');
140
+ await mkrepo(repo);
141
+ await run(repo, 'global');
142
+ await fs.writeFile(path.join(repo, '.ai-kit', 'project.yml'), 'x');
143
+ const target = await fs.readlink(path.join(repo, '.ai-kit'));
144
+ expect((await run(repo, 'detach')).exitCode).toBe(0);
145
+ expect(await exists(path.join(repo, '.ai-kit'))).toBe(false);
146
+ expect(await fs.readFile(path.join(target, 'project.yml'), 'utf8')).toBe('x');
147
+ const ex = await fs.readFile(path.join(repo, '.git', 'info', 'exclude'), 'utf8');
148
+ expect(ex).not.toContain(BLOCK_BEGIN);
149
+ });
150
+
151
+ it('detach leaves symlinks that point outside the store alone', async () => {
152
+ const repo = path.join(tmp, 'g');
153
+ await mkrepo(repo);
154
+ const foreign = path.join(tmp, 'foreign');
155
+ await fs.mkdir(foreign);
156
+ await fs.symlink(foreign, path.join(repo, '.ai-kit'), 'dir');
157
+ await run(repo, 'detach');
158
+ expect((await fs.lstat(path.join(repo, '.ai-kit'))).isSymbolicLink()).toBe(true);
159
+ });
160
+
161
+ it('linked worktree: exclude lives in the common git dir', async () => {
162
+ const repo = path.join(tmp, 'h');
163
+ await mkrepo(repo);
164
+ const wt = path.join(tmp, 'h-wt');
165
+ git(repo, 'worktree', 'add', '-q', wt, '-b', 'wt');
166
+ expect((await run(wt, 'local')).exitCode).toBe(0);
167
+ expect(await fs.readFile(path.join(repo, '.git', 'info', 'exclude'), 'utf8')).toContain(BLOCK_BEGIN);
168
+ expect(clean(wt)).toBe(true);
169
+ });
170
+
171
+ it('status reports mode and invisibility; fails closed when not attached', async () => {
172
+ const repo = path.join(tmp, 'i');
173
+ await mkrepo(repo);
174
+ await fs.mkdir(path.join(repo, '.ai-kit'));
175
+ await fs.writeFile(path.join(repo, '.ai-kit', 'x'), 'x');
176
+ const before = await run(repo, 'status');
177
+ expect(before.exitCode).toBe(1); // leaking
178
+ await run(repo, 'local');
179
+ const after = await run(repo, 'status');
180
+ expect(after.exitCode).toBe(0);
181
+ expect(after.out).toContain('exclude block: present');
182
+ });
183
+
184
+ it('errors outside a git repo and on unknown subcommand', async () => {
185
+ const plain = path.join(tmp, 'plain');
186
+ await fs.mkdir(plain);
187
+ expect((await run(plain, 'local')).err).toContain('not inside a git repository');
188
+ expect((await run(plain, 'bogus')).exitCode).toBe(1);
189
+ expect((await run(plain)).exitCode).toBe(1);
190
+ expect((await run(plain, '--help')).exitCode).toBe(0);
191
+ });
192
+ });
@@ -0,0 +1,143 @@
1
+ // packages/cli/src/commands/attach.ts
2
+ //
3
+ // `kit attach <local|global|status|detach> [--adopt]`
4
+ //
5
+ // Provisions the kit's working paths (.ai-kit, .claude, docs/specifications,
6
+ // docs/plans) WITHOUT touching tracked files, and proves git-invisibility
7
+ // before reporting success (fail closed).
8
+ // local real directories, hidden via .git/info/exclude
9
+ // global symlinks into $KIT_ATTACH_HOME/<repo>-<hash>/ (default
10
+ // ~/.agentic-sdlc/projects)
11
+ //
12
+ // Mode 1 (`kit feature <id> run`) needs committed artifacts and therefore
13
+ // cannot be used while attached; Mode 2 / `kit next` is unaffected.
14
+
15
+ import path from 'node:path';
16
+ import {
17
+ hasTrackedFiles,
18
+ isIgnored,
19
+ resolveRepo,
20
+ statusLeaks,
21
+ type RepoInfo,
22
+ } from './attach-git.js';
23
+ import { hasBlock, removeBlock, writeBlock } from './attach-exclude.js';
24
+ import {
25
+ AttachError,
26
+ MANAGED_PATHS,
27
+ attachGlobal,
28
+ attachLocal,
29
+ describePath,
30
+ detachLinks,
31
+ storeBase,
32
+ storeDirFor,
33
+ } from './attach-store.js';
34
+ import type { Command, CommandContext, CommandResult } from './types.js';
35
+
36
+ const USAGE = [
37
+ 'Usage: kit attach <local|global|status|detach> [--adopt]',
38
+ ' local real dirs in the repo, hidden via .git/info/exclude',
39
+ ' global symlinks into $KIT_ATTACH_HOME/<repo>-<hash>/',
40
+ ' status show mode per path and prove git invisibility',
41
+ ' detach remove exclude block; remove global symlinks (store data kept)',
42
+ ' --adopt global only: migrate existing UNTRACKED content into the store',
43
+ ].join('\n');
44
+
45
+ const excludeFile = (repo: RepoInfo): string => path.join(repo.commonDir, 'info', 'exclude');
46
+
47
+ /** Returns report lines; `leaked` is true when any managed path is visible to git. */
48
+ export function verifyInvisible(root: string): { lines: string[]; leaked: boolean } {
49
+ const lines: string[] = [];
50
+ let leaked = false;
51
+ for (const rel of MANAGED_PATHS) {
52
+ const ignored = isIgnored(root, rel);
53
+ lines.push(` ${ignored ? 'ignored: ' : 'NOT IGNORED:'} ${rel}`);
54
+ if (!ignored) leaked = true;
55
+ }
56
+ const leaks = statusLeaks(root, MANAGED_PATHS);
57
+ for (const l of leaks) lines.push(` git status LEAK: ${l}`);
58
+ return { lines, leaked: leaked || leaks.length > 0 };
59
+ }
60
+
61
+ function assertUntracked(root: string): void {
62
+ for (const rel of MANAGED_PATHS) {
63
+ if (hasTrackedFiles(root, rel)) {
64
+ throw new AttachError(
65
+ `REFUSED: '${rel}' contains tracked files. Untrack first (git rm -r --cached '${rel}').`,
66
+ );
67
+ }
68
+ }
69
+ }
70
+
71
+ function proof(root: string, header: string): CommandResult & { text: string } {
72
+ const v = verifyInvisible(root);
73
+ if (v.leaked) {
74
+ const text = [...v.lines, 'verification failed: managed paths are visible to git'].join('\n');
75
+ return { exitCode: 1, text };
76
+ }
77
+ return { exitCode: 0, text: [header, ...v.lines, ' git status: clean for all managed paths.'].join('\n') };
78
+ }
79
+
80
+ async function runMode(mode: 'local' | 'global', repo: RepoInfo, adopt: boolean): Promise<string> {
81
+ assertUntracked(repo.root);
82
+ const store = storeDirFor(repo.root);
83
+ if (mode === 'local') await attachLocal(repo.root);
84
+ else await attachGlobal(repo.root, store, adopt);
85
+ await writeBlock(excludeFile(repo), MANAGED_PATHS);
86
+ return mode === 'local' ? `Attached (local). Exclude: ${excludeFile(repo)}` : `Attached (global). Store: ${store}`;
87
+ }
88
+
89
+ async function runStatus(repo: RepoInfo): Promise<CommandResult & { text: string }> {
90
+ const lines = [`repo: ${repo.root}`, `store: ${storeDirFor(repo.root)}`];
91
+ for (const rel of MANAGED_PATHS) lines.push(` ${await describePath(repo.root, rel)}`);
92
+ const present = await hasBlock(excludeFile(repo));
93
+ lines.push(`exclude block: ${present ? 'present' : 'absent'}`);
94
+ const v = verifyInvisible(repo.root);
95
+ lines.push(...v.lines);
96
+ return { exitCode: v.leaked ? 1 : 0, text: lines.join('\n') };
97
+ }
98
+
99
+ async function runDetach(repo: RepoInfo): Promise<string> {
100
+ await removeBlock(excludeFile(repo));
101
+ const removed = await detachLinks(repo.root, storeBase(storeDirFor(repo.root)));
102
+ const lines = removed.map((r) => ` removed symlink: ${r} (data kept in store)`);
103
+ lines.push('Detached. Local directories (if any) left untouched.');
104
+ return lines.join('\n');
105
+ }
106
+
107
+ async function execute(sub: string, repo: RepoInfo, adopt: boolean): Promise<CommandResult & { text: string }> {
108
+ if (sub === 'status') return runStatus(repo);
109
+ if (sub === 'detach') return { exitCode: 0, text: await runDetach(repo) };
110
+ if (adopt && sub !== 'global') throw new AttachError("--adopt is only valid with 'global'");
111
+ const header = await runMode(sub as 'local' | 'global', repo, adopt);
112
+ return proof(repo.root, header);
113
+ }
114
+
115
+ export const attachCommand: Command = {
116
+ name: 'attach',
117
+ summary: 'Attach kit working paths to a repo without tracking them (local|global).',
118
+ async run(ctx: CommandContext): Promise<CommandResult> {
119
+ const positional = ctx.argv.filter((a) => !a.startsWith('-'));
120
+ const sub = positional[0];
121
+ if (ctx.argv.includes('--help') || !sub) {
122
+ ctx.stdout(USAGE);
123
+ return { exitCode: sub || ctx.argv.includes('--help') ? 0 : 1 };
124
+ }
125
+ if (!['local', 'global', 'status', 'detach'].includes(sub)) {
126
+ ctx.stderr(`kit attach: unknown subcommand '${sub}'\n${USAGE}`);
127
+ return { exitCode: 1 };
128
+ }
129
+ const repo = resolveRepo(ctx.cwd);
130
+ if (!repo) {
131
+ ctx.stderr('kit attach: not inside a git repository');
132
+ return { exitCode: 1 };
133
+ }
134
+ try {
135
+ const r = await execute(sub, repo, ctx.argv.includes('--adopt'));
136
+ (r.exitCode === 0 ? ctx.stdout : ctx.stderr)(r.text);
137
+ return { exitCode: r.exitCode };
138
+ } catch (e) {
139
+ ctx.stderr(`kit attach: ${e instanceof Error ? e.message : String(e)}`);
140
+ return { exitCode: 1 };
141
+ }
142
+ },
143
+ };
@@ -0,0 +1,181 @@
1
+ // packages/cli/src/commands/clse.test.ts
2
+ import { promises as fs } from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { describe, expect, it } from 'vitest';
6
+ import { installCommand } from './install.js';
7
+ import { memoryCommand } from './memory.js';
8
+ import { evolveCommand } from './evolve.js';
9
+ import type { CommandContext } from './types.js';
10
+
11
+ const makeCtx = (
12
+ argv: string[],
13
+ cwd: string,
14
+ ): CommandContext & { out: string[]; err: string[] } => {
15
+ const out: string[] = [];
16
+ const err: string[] = [];
17
+ return {
18
+ argv,
19
+ cwd,
20
+ stdout: (s) => void out.push(s),
21
+ stderr: (s) => void err.push(s),
22
+ out,
23
+ err,
24
+ };
25
+ };
26
+
27
+ describe('installCommand (M15)', () => {
28
+ it('installs kit configuration files and writes ownership manifest', async () => {
29
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-install-'));
30
+ try {
31
+ const ctx = makeCtx(['--profile', 'full-sdlc', '--stack', 'node-typescript'], tmp);
32
+ const r = await installCommand.run(ctx);
33
+ expect(r.exitCode).toBe(0);
34
+ expect(ctx.out[0]).toContain('kit install: SUCCESS');
35
+ // Verify files were actually written.
36
+ const projectYml = path.join(tmp, '.ai-kit', 'project.yml');
37
+ const stat = await fs.stat(projectYml);
38
+ expect(stat.isFile()).toBe(true);
39
+ // Verify ownership manifest was written.
40
+ const manifest = path.join(tmp, '.ai-kit', 'ownership-manifest.json');
41
+ const manifestStat = await fs.stat(manifest);
42
+ expect(manifestStat.isFile()).toBe(true);
43
+ // Verify docs directories were created.
44
+ await fs.stat(path.join(tmp, 'docs', 'specifications', '.gitkeep'));
45
+ await fs.stat(path.join(tmp, 'docs', 'plans', '.gitkeep'));
46
+ } finally {
47
+ await fs.rm(tmp, { recursive: true, force: true });
48
+ }
49
+ });
50
+
51
+ it('supports --dry-run without writing files', async () => {
52
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-dryrun-'));
53
+ try {
54
+ const ctx = makeCtx(['--profile', 'minimal', '--dry-run'], tmp);
55
+ const r = await installCommand.run(ctx);
56
+ expect(r.exitCode).toBe(0);
57
+ expect(ctx.out[0]).toContain('dry-run');
58
+ // Verify NO files were written.
59
+ await expect(fs.stat(path.join(tmp, '.ai-kit', 'project.yml'))).rejects.toThrow();
60
+ } finally {
61
+ await fs.rm(tmp, { recursive: true, force: true });
62
+ }
63
+ });
64
+ });
65
+
66
+ describe('memoryCommand (M29)', () => {
67
+ it('reports honestly when no memory has been persisted', async () => {
68
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-memory-empty-'));
69
+ try {
70
+ const ctx = makeCtx(['architecture'], tmp);
71
+ const r = await memoryCommand.run(ctx);
72
+ expect(r.exitCode).toBe(0);
73
+ expect(ctx.out[0]).toContain('no memory entries found');
74
+ } finally {
75
+ await fs.rm(tmp, { recursive: true, force: true });
76
+ }
77
+ });
78
+
79
+ it('reads and searches persisted memory entries', async () => {
80
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-memory-search-'));
81
+ try {
82
+ // Write a memory file.
83
+ await fs.mkdir(path.join(tmp, '.ai-kit', 'state'), { recursive: true });
84
+ const memory = {
85
+ schemaVersion: 1,
86
+ entries: [
87
+ {
88
+ id: 'MEM-TEST-001',
89
+ type: 'semantic',
90
+ domain: 'architecture',
91
+ summary: 'Modular Monorepo Invariant',
92
+ content: 'Contracts depends on nothing; Core depends only on Contracts.',
93
+ confidence: 1.0,
94
+ provenance: ['ARCHITECTURE.md'],
95
+ appliedCount: 12,
96
+ successCount: 12,
97
+ createdAt: '2026-01-01T00:00:00.000Z',
98
+ updatedAt: '2026-01-01T00:00:00.000Z',
99
+ },
100
+ ],
101
+ };
102
+ await fs.writeFile(
103
+ path.join(tmp, '.ai-kit', 'state', 'memory.json'),
104
+ JSON.stringify(memory, null, 2),
105
+ 'utf8',
106
+ );
107
+
108
+ const ctx = makeCtx(['Monorepo'], tmp);
109
+ const r = await memoryCommand.run(ctx);
110
+ expect(r.exitCode).toBe(0);
111
+ expect(ctx.out[0]).toContain('MEM-TEST-001');
112
+ expect(ctx.out[0]).toContain('Modular Monorepo Invariant');
113
+ } finally {
114
+ await fs.rm(tmp, { recursive: true, force: true });
115
+ }
116
+ });
117
+ });
118
+
119
+ describe('evolveCommand (M31-M33)', () => {
120
+ it('reports honestly when no experiences have been persisted', async () => {
121
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-evolve-empty-'));
122
+ try {
123
+ const ctx = makeCtx(['--dry-run'], tmp);
124
+ const r = await evolveCommand.run(ctx);
125
+ expect(r.exitCode).toBe(1);
126
+ expect(ctx.out[0]).toContain('no experience records found');
127
+ } finally {
128
+ await fs.rm(tmp, { recursive: true, force: true });
129
+ }
130
+ });
131
+
132
+ it('distills lessons from persisted experiences', async () => {
133
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-evolve-real-'));
134
+ try {
135
+ // Write an experiences file with recurring failures.
136
+ await fs.mkdir(path.join(tmp, '.ai-kit', 'state'), { recursive: true });
137
+ const experiences = {
138
+ schemaVersion: 1,
139
+ records: [
140
+ {
141
+ id: 'EXP-1',
142
+ workflowId: 'WF-1',
143
+ featureId: 'FEATURE-A',
144
+ stack: 'node-typescript',
145
+ outcome: 'failure',
146
+ phases: [{ name: 'tdd', status: 'failed', durationMs: 200 }],
147
+ timestamp: '2026-01-01T00:00:00.000Z',
148
+ },
149
+ {
150
+ id: 'EXP-2',
151
+ workflowId: 'WF-2',
152
+ featureId: 'FEATURE-B',
153
+ stack: 'node-typescript',
154
+ outcome: 'failure',
155
+ phases: [{ name: 'tdd', status: 'failed', durationMs: 250 }],
156
+ timestamp: '2026-01-01T01:00:00.000Z',
157
+ },
158
+ ],
159
+ };
160
+ await fs.writeFile(
161
+ path.join(tmp, '.ai-kit', 'state', 'experiences.json'),
162
+ JSON.stringify(experiences, null, 2),
163
+ 'utf8',
164
+ );
165
+
166
+ const ctx = makeCtx(['--dry-run'], tmp);
167
+ const r = await evolveCommand.run(ctx);
168
+ expect(r.exitCode).toBe(0);
169
+ // The output should reference the real distilled data, not demo data.
170
+ expect(ctx.out[0]).toContain('Experiences Loaded: 2');
171
+ expect(ctx.out[0]).toContain('Distilled Lessons: 1');
172
+ // The benchmark environment is not implemented, so the lab must say
173
+ // so instead of reporting COMPLETED with empty numbers (ADR-0018).
174
+ expect(ctx.out[0]).toContain('NOT RUN');
175
+ expect(ctx.out[0]).toContain('0 executed, 1 not run');
176
+ expect(ctx.out[0]).not.toContain('Evolution Lab: COMPLETED');
177
+ } finally {
178
+ await fs.rm(tmp, { recursive: true, force: true });
179
+ }
180
+ });
181
+ });
@@ -0,0 +1,29 @@
1
+ // packages/cli/src/commands/doctor.test.ts
2
+ import { describe, expect, it } from 'vitest';
3
+ import { doctorCommand } from './doctor.js';
4
+ import type { CommandContext } from './types.js';
5
+
6
+ const makeCtx = (): CommandContext & { out: string[] } => {
7
+ const out: string[] = [];
8
+ return {
9
+ argv: [],
10
+ cwd: '/',
11
+ stdout: (s) => void out.push(s),
12
+ stderr: () => {},
13
+ out,
14
+ };
15
+ };
16
+
17
+ describe('doctorCommand', () => {
18
+ it('prints the kit version and node version', async () => {
19
+ const ctx = makeCtx();
20
+ const r = await doctorCommand.run(ctx);
21
+ expect(r.exitCode).toBeLessThanOrEqual(2); // 0 if healthy, 2 if not
22
+ const text = ctx.out[0] ?? '';
23
+ expect(text).toContain('kit 0.9.1');
24
+ expect(text).toContain('node');
25
+ expect(text).toContain('pnpm');
26
+ expect(text).toContain('workspace');
27
+ expect(text).toContain('Status:');
28
+ });
29
+ });