@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,44 @@
1
+ // packages/cli/src/commands/new.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 { newCommand } from './new.js';
7
+ import type { CommandContext } from './types.js';
8
+
9
+ const makeCtx = (
10
+ argv: string[],
11
+ cwd: string,
12
+ ): CommandContext & { out: string[]; err: string[] } => {
13
+ const out: string[] = [];
14
+ const err: string[] = [];
15
+ return {
16
+ argv,
17
+ cwd,
18
+ stdout: (s) => void out.push(s),
19
+ stderr: (s) => void err.push(s),
20
+ out,
21
+ err,
22
+ };
23
+ };
24
+
25
+ describe('newCommand', () => {
26
+ it('shows help when --help is passed', async () => {
27
+ const ctx = makeCtx(['--help'], '/');
28
+ const r = await newCommand.run(ctx);
29
+ expect(r.exitCode).toBe(0);
30
+ expect(ctx.out[0]).toContain('Usage: kit new');
31
+ });
32
+
33
+ it('scaffolds greenfield app in target directory', async () => {
34
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-new-'));
35
+ try {
36
+ const ctx = makeCtx(['crypto-trader', '--dir', tmp], tmp);
37
+ const r = await newCommand.run(ctx);
38
+ expect(r.exitCode).toBe(0);
39
+ expect(ctx.out[0]).toContain('Application: crypto-trader');
40
+ } finally {
41
+ await fs.rm(tmp, { recursive: true, force: true });
42
+ }
43
+ });
44
+ });
@@ -0,0 +1,77 @@
1
+ // packages/cli/src/commands/new.ts
2
+ //
3
+ // `kit new <name> [--stack <stack>] [--dir <path>] [--json]`.
4
+ // Scaffolds a new greenfield application repository (M8).
5
+
6
+ import path from 'node:path';
7
+ import { scaffoldGreenfieldApp, type GreenfieldAppResult } from '@agentic-sdlc-kit/core';
8
+ import type { Command, CommandContext, CommandResult } from './types.js';
9
+
10
+ export const newCommand: Command = {
11
+ name: 'new',
12
+ summary:
13
+ 'Scaffold a new application with baseline architecture ADR, profile, and initial spec (M8).',
14
+ async run(ctx: CommandContext): Promise<CommandResult> {
15
+ if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
16
+ ctx.stdout(formatHelp());
17
+ return { exitCode: 0 };
18
+ }
19
+
20
+ const name = ctx.argv.find((a) => !a.startsWith('-'));
21
+ if (!name) {
22
+ ctx.stderr('kit new: error: missing required application name\n');
23
+ return { exitCode: 1, message: 'Missing application name' };
24
+ }
25
+
26
+ const isJson = ctx.argv.includes('--json');
27
+ const stackIdx = ctx.argv.indexOf('--stack');
28
+ const stack = stackIdx !== -1 ? ctx.argv[stackIdx + 1] : 'node-typescript';
29
+ const dirIdx = ctx.argv.indexOf('--dir');
30
+ const targetDir =
31
+ dirIdx !== -1 && ctx.argv[dirIdx + 1]
32
+ ? path.resolve(ctx.cwd, ctx.argv[dirIdx + 1]!)
33
+ : ctx.cwd;
34
+
35
+ const res = await scaffoldGreenfieldApp({ name, targetDir, stack });
36
+ if (!res.ok) {
37
+ ctx.stderr(`kit new: error: ${res.error.message}\n`);
38
+ return { exitCode: 1, message: res.error.message };
39
+ }
40
+
41
+ if (isJson) {
42
+ ctx.stdout(JSON.stringify(res.value, null, 2) + '\n');
43
+ } else {
44
+ ctx.stdout(formatSummary(res.value));
45
+ }
46
+ return { exitCode: 0 };
47
+ },
48
+ };
49
+
50
+ function formatSummary(result: GreenfieldAppResult): string {
51
+ const lines: string[] = [
52
+ `Application: ${result.name}`,
53
+ `Location: ${result.appDir}`,
54
+ `Profile: ${result.profilePath}`,
55
+ `Baseline ADR: ${result.adrPath}`,
56
+ `Initial Spec: ${result.specPath}`,
57
+ '',
58
+ `Successfully created greenfield application '${result.name}'.`,
59
+ ];
60
+ return lines.join('\n') + '\n';
61
+ }
62
+
63
+ function formatHelp(): string {
64
+ return [
65
+ 'Usage: kit new <name> [--stack <stack>] [--dir <path>] [--json]',
66
+ '',
67
+ 'Scaffold a new greenfield application repository with baseline architecture ADRs,',
68
+ 'project profile (.ai-kit/project.yml), and initial feature specification.',
69
+ '',
70
+ 'Options:',
71
+ ' --stack <stack> Target stack (default: node-typescript)',
72
+ ' --dir <path> Destination directory (default: current working directory)',
73
+ ' --json Output machine-readable creation result',
74
+ ' --help Show this message',
75
+ '',
76
+ ].join('\n');
77
+ }
@@ -0,0 +1,241 @@
1
+ // packages/cli/src/commands/next.test.ts
2
+ //
3
+ // Tests for `kit next` and `kit journal` (ADR-0021): the host-driven
4
+ // agent protocol entry point and its tamper-evident record.
5
+ import { promises as fs } from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import { describe, expect, it } from 'vitest';
9
+ import { scaffoldSpecification, serializeProfileYaml } from '@agentic-sdlc-kit/core';
10
+ import type { NextAction } from '@agentic-sdlc-kit/contracts';
11
+ import { featureCommand } from './feature.js';
12
+ import { journalCommand } from './journal.js';
13
+ import { nextCommand } from './next.js';
14
+ import type { CommandContext } from './types.js';
15
+
16
+ const makeCtx = (
17
+ argv: string[],
18
+ cwd: string,
19
+ ): CommandContext & { out: string[]; err: string[] } => {
20
+ const out: string[] = [];
21
+ const err: string[] = [];
22
+ return {
23
+ argv,
24
+ cwd,
25
+ stdout: (s) => void out.push(s),
26
+ stderr: (s) => void err.push(s),
27
+ out,
28
+ err,
29
+ };
30
+ };
31
+
32
+ async function setupProject(featureIds: readonly string[] = ['FEATURE-001']): Promise<string> {
33
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-next-'));
34
+ const marker = path.join(tmp, '.done');
35
+
36
+ await fs.mkdir(path.join(tmp, '.git'), { recursive: true });
37
+ await fs.writeFile(path.join(tmp, '.git', 'HEAD'), 'ref: refs/heads/main\n');
38
+
39
+ const script = path.join(tmp, 'check.js');
40
+ await fs.writeFile(
41
+ script,
42
+ [
43
+ 'const fs = require("node:fs");',
44
+ `const marker = ${JSON.stringify(marker)};`,
45
+ 'if (!fs.existsSync(marker)) {',
46
+ ' console.error("AssertionError: expected marker to exist (target not implemented)");',
47
+ ' process.exit(1);',
48
+ '}',
49
+ 'process.exit(0);',
50
+ ].join('\n'),
51
+ );
52
+
53
+ const aiKit = path.join(tmp, '.ai-kit');
54
+ await fs.mkdir(aiKit, { recursive: true });
55
+ await fs.writeFile(
56
+ path.join(aiKit, 'project.yml'),
57
+ serializeProfileYaml({
58
+ schemaVersion: 1,
59
+ name: 'cli-next-app',
60
+ stack: ['node-typescript'],
61
+ commands: { test: [['node', script]] },
62
+ }),
63
+ );
64
+
65
+ for (const featureId of featureIds) {
66
+ await scaffoldSpecification({
67
+ id: featureId,
68
+ title: `Feature ${featureId}`,
69
+ targetDir: path.join(tmp, 'docs', 'specifications', 'features'),
70
+ });
71
+ const planDir = path.join(tmp, 'docs', 'plans', featureId);
72
+ await fs.mkdir(planDir, { recursive: true });
73
+ await fs.writeFile(
74
+ path.join(planDir, 'plan.json'),
75
+ JSON.stringify(
76
+ {
77
+ featureId,
78
+ tasks: [
79
+ {
80
+ id: 'TASK-001',
81
+ description: 'Implement TASK-001',
82
+ acceptanceCriteria: ['TASK-001 works'],
83
+ verification: { command: ['node', script], expectedStatus: 'passed' },
84
+ dependencies: [],
85
+ likelyFiles: ['src/TASK-001.ts'],
86
+ estimatedScope: 's',
87
+ risk: 'low',
88
+ },
89
+ ],
90
+ edges: [],
91
+ verticalSlices: [['TASK-001']],
92
+ },
93
+ null,
94
+ 2,
95
+ ),
96
+ );
97
+ }
98
+ return tmp;
99
+ }
100
+
101
+ describe('kit next', () => {
102
+ it('is blocked (exit 3) when no feature run exists', async () => {
103
+ const root = await setupProject();
104
+ const ctx = makeCtx([], root);
105
+ const result = await nextCommand.run(ctx);
106
+ expect(result.exitCode).toBe(3);
107
+ expect(ctx.err.join('')).toContain('no active feature runs');
108
+ });
109
+
110
+ it('resolves the single active run and reports task.red as JSON', async () => {
111
+ const root = await setupProject();
112
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
113
+
114
+ const ctx = makeCtx(['--json'], root);
115
+ const result = await nextCommand.run(ctx);
116
+ expect(result.exitCode).toBe(0);
117
+ const action = JSON.parse(ctx.out.join('')) as NextAction;
118
+ expect(action.schemaVersion).toBe(1);
119
+ expect(action.featureId).toBe('FEATURE-001');
120
+ expect(action.requiredAction).toBe('task.red');
121
+ expect(action.taskId).toBe('TASK-001');
122
+ expect(action.verificationCommand[0]).toBe('node');
123
+ expect(action.nextInvocation).toBe('kit feature FEATURE-001 red TASK-001');
124
+ });
125
+
126
+ it('prints a human-readable next invocation without --json', async () => {
127
+ const root = await setupProject();
128
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
129
+ const ctx = makeCtx([], root);
130
+ const result = await nextCommand.run(ctx);
131
+ expect(result.exitCode).toBe(0);
132
+ expect(ctx.out.join('')).toContain('kit feature FEATURE-001 red TASK-001');
133
+ });
134
+
135
+ it('is blocked (exit 3) when multiple runs are active and no id is given', async () => {
136
+ const root = await setupProject(['FEATURE-001', 'FEATURE-002']);
137
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
138
+ await featureCommand.run(makeCtx(['FEATURE-002', 'start'], root));
139
+
140
+ const ctx = makeCtx([], root);
141
+ const result = await nextCommand.run(ctx);
142
+ expect(result.exitCode).toBe(3);
143
+ expect(ctx.err.join('')).toContain('multiple active feature runs');
144
+ });
145
+
146
+ it('follows the protocol forward: red -> green after the red phase records', async () => {
147
+ const root = await setupProject();
148
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
149
+ await featureCommand.run(makeCtx(['FEATURE-001', 'red', 'TASK-001'], root));
150
+
151
+ const ctx = makeCtx(['--json'], root);
152
+ await nextCommand.run(ctx);
153
+ const action = JSON.parse(ctx.out.join('')) as NextAction;
154
+ expect(action.requiredAction).toBe('task.green');
155
+ });
156
+
157
+ it('reports feature.verify once every task completed, then run.completed after a passed verify', async () => {
158
+ const root = await setupProject();
159
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
160
+ await featureCommand.run(makeCtx(['FEATURE-001', 'red', 'TASK-001'], root));
161
+ await fs.writeFile(path.join(root, '.done'), 'implemented\n', 'utf8');
162
+ await featureCommand.run(makeCtx(['FEATURE-001', 'green', 'TASK-001'], root));
163
+ await featureCommand.run(makeCtx(['FEATURE-001', 'refactor', 'TASK-001'], root));
164
+
165
+ const before = makeCtx(['--json'], root);
166
+ await nextCommand.run(before);
167
+ expect((JSON.parse(before.out.join('')) as NextAction).requiredAction).toBe('feature.verify');
168
+
169
+ const verify = await featureCommand.run(makeCtx(['FEATURE-001', 'verify'], root));
170
+ expect(verify.exitCode).toBe(0);
171
+
172
+ const after = makeCtx(['--json'], root);
173
+ await nextCommand.run(after);
174
+ const completed = JSON.parse(after.out.join('')) as NextAction;
175
+ expect(completed.requiredAction).toBe('run.completed');
176
+ expect(completed.status).toBe('completed');
177
+ });
178
+ });
179
+
180
+ describe('kit journal', () => {
181
+ it('lists the events of a driven run in human form', async () => {
182
+ const root = await setupProject();
183
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
184
+ await featureCommand.run(makeCtx(['FEATURE-001', 'red', 'TASK-001'], root));
185
+
186
+ const ctx = makeCtx(['FEATURE-001'], root);
187
+ const result = await journalCommand.run(ctx);
188
+ expect(result.exitCode).toBe(0);
189
+ const text = ctx.out.join('');
190
+ expect(text).toContain('workflow.started');
191
+ expect(text).toContain('phase.recorded');
192
+ });
193
+
194
+ it('emits machine-readable events with --json', async () => {
195
+ const root = await setupProject();
196
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start', '--host', 'cursor'], root));
197
+
198
+ const ctx = makeCtx(['FEATURE-001', '--json'], root);
199
+ await journalCommand.run(ctx);
200
+ const events = JSON.parse(ctx.out.join('')) as Array<{
201
+ kind: string;
202
+ actor: { kind: string; host?: string };
203
+ }>;
204
+ expect(events).toHaveLength(1);
205
+ expect(events[0]?.kind).toBe('workflow.started');
206
+ expect(events[0]?.actor).toEqual({ kind: 'agent', host: 'cursor' });
207
+ });
208
+
209
+ it('verifies an intact chain (exit 0)', async () => {
210
+ const root = await setupProject();
211
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
212
+ const ctx = makeCtx(['FEATURE-001', '--verify'], root);
213
+ const result = await journalCommand.run(ctx);
214
+ expect(result.exitCode).toBe(0);
215
+ expect(ctx.out.join('')).toContain('Journal verified');
216
+ });
217
+
218
+ it('fails (exit 1) when the chain was tampered with', async () => {
219
+ const root = await setupProject();
220
+ await featureCommand.run(makeCtx(['FEATURE-001', 'start'], root));
221
+
222
+ const file = path.join(root, '.ai-kit', 'journal', 'feature-runs', 'FEATURE-001.jsonl');
223
+ const lines = (await fs.readFile(file, 'utf8')).split('\n').filter((l) => l.trim());
224
+ const event = JSON.parse(lines[0] ?? '{}') as { payload: Record<string, unknown> };
225
+ event.payload['taskCount'] = 999;
226
+ lines[0] = JSON.stringify(event);
227
+ await fs.writeFile(file, `${lines.join('\n')}\n`, 'utf8');
228
+
229
+ const ctx = makeCtx(['FEATURE-001', '--verify'], root);
230
+ const result = await journalCommand.run(ctx);
231
+ expect(result.exitCode).toBe(1);
232
+ expect(ctx.err.join('')).toContain('chain violation');
233
+ });
234
+
235
+ it('fails when the journal does not exist', async () => {
236
+ const root = await setupProject();
237
+ const ctx = makeCtx(['FEATURE-404', '--verify'], root);
238
+ const result = await journalCommand.run(ctx);
239
+ expect(result.exitCode).toBe(1);
240
+ });
241
+ });
@@ -0,0 +1,124 @@
1
+ // packages/cli/src/commands/next.ts
2
+ //
3
+ // `kit next [feature-id] [--json]` — the host-driven agent protocol
4
+ // entry point (ADR-0021 §2).
5
+ //
6
+ // A Tier C host (Cursor, AGY, CI, any terminal-capable agent) drives
7
+ // the entire TDD workflow with ONE loop:
8
+ //
9
+ // while true:
10
+ // action = kit next --json
11
+ // if action.requiredAction == 'run.completed': stop
12
+ // act on action.nextInvocation (write test / implement / refactor)
13
+ // run action.nextInvocation
14
+ //
15
+ // The payload is bounded and machine-readable; the evidence gate, not
16
+ // this command, decides what advances. With no feature id, the command
17
+ // resolves the single active run; ambiguity is a blocked exit, never a
18
+ // guess.
19
+
20
+ import path from 'node:path';
21
+ import { computeNextAction, listFeatureRunStates } from '@agentic-sdlc-kit/core';
22
+ import type { NextAction } from '@agentic-sdlc-kit/contracts';
23
+ import type { Command, CommandContext, CommandResult } from './types.js';
24
+
25
+ function fail(ctx: CommandContext, message: string): CommandResult {
26
+ ctx.stderr(`kit next: ${message}\n`);
27
+ return { exitCode: 1, message };
28
+ }
29
+
30
+ function blocked(ctx: CommandContext, message: string): CommandResult {
31
+ ctx.stderr(`kit next: ${message}\n`);
32
+ return { exitCode: 3, message };
33
+ }
34
+
35
+ export const nextCommand: Command = {
36
+ name: 'next',
37
+ summary:
38
+ 'Show the next action for the active feature run (host-driven agent protocol, ADR-0021).',
39
+ async run(ctx: CommandContext): Promise<CommandResult> {
40
+ if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
41
+ ctx.stdout(formatHelp());
42
+ return { exitCode: 0 };
43
+ }
44
+
45
+ const isJson = ctx.argv.includes('--json');
46
+ const positional = ctx.argv.filter((a) => !a.startsWith('-'));
47
+ const root = path.resolve(ctx.cwd, '.');
48
+
49
+ let featureId = positional[0];
50
+ if (!featureId) {
51
+ const runs = await listFeatureRunStates(root);
52
+ const single = runs[0];
53
+ if (single === undefined) {
54
+ return blocked(
55
+ ctx,
56
+ 'no active feature runs — start one with `kit feature <feature-id> start`',
57
+ );
58
+ }
59
+ if (runs.length > 1) {
60
+ const ids = runs.map((r) => r.featureId).join(', ');
61
+ return blocked(
62
+ ctx,
63
+ `multiple active feature runs (${ids}) — specify one: \`kit next <feature-id>\``,
64
+ );
65
+ }
66
+ featureId = single.featureId;
67
+ }
68
+
69
+ const res = await computeNextAction({ projectRoot: root, featureId });
70
+ if (!res.ok) return fail(ctx, res.error.message);
71
+ const action = res.value;
72
+
73
+ if (isJson) {
74
+ ctx.stdout(JSON.stringify(action, null, 2) + '\n');
75
+ return { exitCode: 0 };
76
+ }
77
+ ctx.stdout(formatHuman(action));
78
+ return { exitCode: 0 };
79
+ },
80
+ };
81
+
82
+ function formatHuman(action: NextAction): string {
83
+ const lines: string[] = [
84
+ `${action.featureId} (${action.status}): ${
85
+ action.taskId ? `${action.taskId} ${action.phase}` : action.requiredAction
86
+ }`,
87
+ `Next: ${action.nextInvocation}`,
88
+ ];
89
+ if (action.verificationCommand.length > 0) {
90
+ lines.push(`Verify with: ${action.verificationCommand.join(' ')}`);
91
+ }
92
+ if (action.blockingQuestions.length > 0) {
93
+ lines.push('Waiting on a human:');
94
+ for (const q of action.blockingQuestions) lines.push(` - ${q}`);
95
+ }
96
+ if (action.advisoryLessons.length > 0) {
97
+ lines.push('Advisory lessons (advice only, never authority):');
98
+ for (const lesson of action.advisoryLessons) lines.push(` - ${lesson.summary}`);
99
+ }
100
+ return lines.join('\n') + '\n';
101
+ }
102
+
103
+ function formatHelp(): string {
104
+ return [
105
+ 'Usage: kit next [feature-id] [--json]',
106
+ '',
107
+ 'Show the next action for the active feature run — the host-driven agent',
108
+ 'protocol entry point (ADR-0021). Tier C hosts (Cursor, AGY, CI) loop:',
109
+ 'kit next --json, act, run nextInvocation, repeat.',
110
+ '',
111
+ 'With no feature id: uses the single active run; zero or multiple active',
112
+ 'runs are a blocked exit (3), never a guess.',
113
+ '',
114
+ 'Options:',
115
+ ' --json output the machine-readable NextAction payload',
116
+ ' --help Show this message',
117
+ '',
118
+ 'Exit codes:',
119
+ ' 0 action resolved',
120
+ ' 1 error (corrupt state, diverged plan)',
121
+ ' 3 blocked: no active run, or multiple runs without a feature id',
122
+ '',
123
+ ].join('\n');
124
+ }
@@ -0,0 +1,30 @@
1
+ // packages/cli/src/commands/optimize.ts
2
+ //
3
+ // `kit optimize` — informational. The /kit:optimize workflow is an
4
+ // optional M9 extension (post-M7 §3.3). Declared in 0.6.0; full state
5
+ // machine lands in a later release.
6
+
7
+ import type { Command, CommandContext, CommandResult } from './types.js';
8
+
9
+ export const optimizeCommand: Command = {
10
+ name: 'optimize',
11
+ summary: 'Show how to start a performance optimization workflow (/kit:optimize).',
12
+ run(ctx: CommandContext): CommandResult {
13
+ const lines: string[] = [];
14
+ lines.push('kit optimize — Performance optimization workflow (M9 optional)');
15
+ lines.push('');
16
+ lines.push('Status: declared in 0.6.0; full workflow lands in a later release.');
17
+ lines.push('');
18
+ lines.push('Expected lifecycle:');
19
+ lines.push(' define problem → establish baseline → profile bottleneck →');
20
+ lines.push(' propose alternatives → define measurable targets →');
21
+ lines.push(' implement one change at a time → benchmark → correctness +');
22
+ lines.push(' regression tests');
23
+ lines.push('');
24
+ lines.push('INVARIANT: performance optimization requires baseline');
25
+ lines.push('measurements. The kit will not propose an optimization');
26
+ lines.push('without an established baseline.');
27
+ ctx.stdout(lines.join('\n'));
28
+ return { exitCode: 0 };
29
+ },
30
+ };