@agentic-sdlc-kit/cli 0.0.0-stage → 0.8.0

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 (240) 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 +90 -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 +104 -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/doctor.d.ts +3 -0
  72. package/dist/commands/doctor.d.ts.map +1 -0
  73. package/dist/commands/doctor.js +68 -0
  74. package/dist/commands/doctor.js.map +1 -0
  75. package/dist/commands/elicit.d.ts +3 -0
  76. package/dist/commands/elicit.d.ts.map +1 -0
  77. package/dist/commands/elicit.js +163 -0
  78. package/dist/commands/elicit.js.map +1 -0
  79. package/dist/commands/evolve.d.ts +3 -0
  80. package/dist/commands/evolve.d.ts.map +1 -0
  81. package/dist/commands/evolve.js +165 -0
  82. package/dist/commands/evolve.js.map +1 -0
  83. package/dist/commands/feature.d.ts +13 -0
  84. package/dist/commands/feature.d.ts.map +1 -0
  85. package/dist/commands/feature.js +326 -0
  86. package/dist/commands/feature.js.map +1 -0
  87. package/dist/commands/fix.d.ts +3 -0
  88. package/dist/commands/fix.d.ts.map +1 -0
  89. package/dist/commands/fix.js +61 -0
  90. package/dist/commands/fix.js.map +1 -0
  91. package/dist/commands/help.d.ts +4 -0
  92. package/dist/commands/help.d.ts.map +1 -0
  93. package/dist/commands/help.js +32 -0
  94. package/dist/commands/help.js.map +1 -0
  95. package/dist/commands/index.d.ts +21 -0
  96. package/dist/commands/index.d.ts.map +1 -0
  97. package/dist/commands/index.js +22 -0
  98. package/dist/commands/index.js.map +1 -0
  99. package/dist/commands/init.d.ts +3 -0
  100. package/dist/commands/init.d.ts.map +1 -0
  101. package/dist/commands/init.js +90 -0
  102. package/dist/commands/init.js.map +1 -0
  103. package/dist/commands/inspect.d.ts +3 -0
  104. package/dist/commands/inspect.d.ts.map +1 -0
  105. package/dist/commands/inspect.js +64 -0
  106. package/dist/commands/inspect.js.map +1 -0
  107. package/dist/commands/install.d.ts +3 -0
  108. package/dist/commands/install.d.ts.map +1 -0
  109. package/dist/commands/install.js +329 -0
  110. package/dist/commands/install.js.map +1 -0
  111. package/dist/commands/journal.d.ts +3 -0
  112. package/dist/commands/journal.d.ts.map +1 -0
  113. package/dist/commands/journal.js +107 -0
  114. package/dist/commands/journal.js.map +1 -0
  115. package/dist/commands/memory.d.ts +3 -0
  116. package/dist/commands/memory.d.ts.map +1 -0
  117. package/dist/commands/memory.js +85 -0
  118. package/dist/commands/memory.js.map +1 -0
  119. package/dist/commands/new.d.ts +3 -0
  120. package/dist/commands/new.d.ts.map +1 -0
  121. package/dist/commands/new.js +68 -0
  122. package/dist/commands/new.js.map +1 -0
  123. package/dist/commands/next.d.ts +3 -0
  124. package/dist/commands/next.d.ts.map +1 -0
  125. package/dist/commands/next.js +107 -0
  126. package/dist/commands/next.js.map +1 -0
  127. package/dist/commands/optimize.d.ts +3 -0
  128. package/dist/commands/optimize.d.ts.map +1 -0
  129. package/dist/commands/optimize.js +28 -0
  130. package/dist/commands/optimize.js.map +1 -0
  131. package/dist/commands/plugin-linker.d.ts +34 -0
  132. package/dist/commands/plugin-linker.d.ts.map +1 -0
  133. package/dist/commands/plugin-linker.js +177 -0
  134. package/dist/commands/plugin-linker.js.map +1 -0
  135. package/dist/commands/refactor.d.ts +3 -0
  136. package/dist/commands/refactor.d.ts.map +1 -0
  137. package/dist/commands/refactor.js +32 -0
  138. package/dist/commands/refactor.js.map +1 -0
  139. package/dist/commands/types.d.ts +19 -0
  140. package/dist/commands/types.d.ts.map +1 -0
  141. package/dist/commands/types.js +7 -0
  142. package/dist/commands/types.js.map +1 -0
  143. package/dist/commands/validate-plan.d.ts +3 -0
  144. package/dist/commands/validate-plan.d.ts.map +1 -0
  145. package/dist/commands/validate-plan.js +62 -0
  146. package/dist/commands/validate-plan.js.map +1 -0
  147. package/dist/commands/validate-spec.d.ts +3 -0
  148. package/dist/commands/validate-spec.d.ts.map +1 -0
  149. package/dist/commands/validate-spec.js +62 -0
  150. package/dist/commands/validate-spec.js.map +1 -0
  151. package/dist/commands/verify.d.ts +3 -0
  152. package/dist/commands/verify.d.ts.map +1 -0
  153. package/dist/commands/verify.js +103 -0
  154. package/dist/commands/verify.js.map +1 -0
  155. package/dist/commands/version.d.ts +3 -0
  156. package/dist/commands/version.d.ts.map +1 -0
  157. package/dist/commands/version.js +12 -0
  158. package/dist/commands/version.js.map +1 -0
  159. package/dist/index.d.ts +3 -0
  160. package/dist/index.d.ts.map +1 -0
  161. package/dist/index.js +27 -0
  162. package/dist/index.js.map +1 -0
  163. package/dist/output/formatter.d.ts +2 -0
  164. package/dist/output/formatter.d.ts.map +1 -0
  165. package/dist/output/formatter.js +10 -0
  166. package/dist/output/formatter.js.map +1 -0
  167. package/dist/output/index.d.ts +2 -0
  168. package/dist/output/index.d.ts.map +1 -0
  169. package/dist/output/index.js +3 -0
  170. package/dist/output/index.js.map +1 -0
  171. package/package.json +37 -3
  172. package/src/application/agent/execution-store.ts +162 -0
  173. package/src/application/agent/gateway.test.ts +529 -0
  174. package/src/application/agent/gateway.ts +744 -0
  175. package/src/application/agent/index.ts +18 -0
  176. package/src/application/agent/orchestrator.test.ts +341 -0
  177. package/src/application/agent/orchestrator.ts +628 -0
  178. package/src/application/agent/providers/claude-code/claude-argv.ts +119 -0
  179. package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +139 -0
  180. package/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs +125 -0
  181. package/src/application/agent/providers/claude-code/index.ts +28 -0
  182. package/src/application/agent/providers/claude-code/mod-parity.ts +50 -0
  183. package/src/application/agent/providers/claude-code/permission-config.test.ts +221 -0
  184. package/src/application/agent/providers/claude-code/permission-config.ts +242 -0
  185. package/src/application/agent/providers/claude-code/provider.test.ts +378 -0
  186. package/src/application/agent/providers/claude-code/provider.ts +717 -0
  187. package/src/application/agent/providers/claude-code/resume-store.test.ts +161 -0
  188. package/src/application/agent/providers/claude-code/resume-store.ts +157 -0
  189. package/src/application/agent/providers/claude-code/stream-parser.ts +166 -0
  190. package/src/application/agent/test-fixture.ts +131 -0
  191. package/src/application/agent/workspace.test.ts +104 -0
  192. package/src/application/agent/workspace.ts +156 -0
  193. package/src/application/dispatcher.test.ts +89 -0
  194. package/src/application/dispatcher.ts +98 -0
  195. package/src/application/index.ts +5 -0
  196. package/src/application/registry.ts +24 -0
  197. package/src/application/version.ts +7 -0
  198. package/src/commands/clse.test.ts +181 -0
  199. package/src/commands/doctor.test.ts +29 -0
  200. package/src/commands/doctor.ts +78 -0
  201. package/src/commands/elicit.test.ts +111 -0
  202. package/src/commands/elicit.ts +188 -0
  203. package/src/commands/evolve.ts +209 -0
  204. package/src/commands/feature.test.ts +323 -0
  205. package/src/commands/feature.ts +405 -0
  206. package/src/commands/fix.test.ts +36 -0
  207. package/src/commands/fix.ts +69 -0
  208. package/src/commands/help.test.ts +33 -0
  209. package/src/commands/help.ts +35 -0
  210. package/src/commands/index.ts +21 -0
  211. package/src/commands/init.test.ts +65 -0
  212. package/src/commands/init.ts +103 -0
  213. package/src/commands/inspect.test.ts +57 -0
  214. package/src/commands/inspect.ts +73 -0
  215. package/src/commands/install.test.ts +61 -0
  216. package/src/commands/install.ts +375 -0
  217. package/src/commands/journal.ts +118 -0
  218. package/src/commands/memory.ts +96 -0
  219. package/src/commands/new.test.ts +44 -0
  220. package/src/commands/new.ts +77 -0
  221. package/src/commands/next.test.ts +241 -0
  222. package/src/commands/next.ts +124 -0
  223. package/src/commands/optimize.ts +30 -0
  224. package/src/commands/plugin-linker.test.ts +139 -0
  225. package/src/commands/plugin-linker.ts +196 -0
  226. package/src/commands/refactor.ts +34 -0
  227. package/src/commands/stack-commands.test.ts +67 -0
  228. package/src/commands/tier-c-conformance.test.ts +194 -0
  229. package/src/commands/types.ts +26 -0
  230. package/src/commands/validate-plan.test.ts +107 -0
  231. package/src/commands/validate-plan.ts +67 -0
  232. package/src/commands/validate-spec.test.ts +59 -0
  233. package/src/commands/validate-spec.ts +68 -0
  234. package/src/commands/verify.test.ts +117 -0
  235. package/src/commands/verify.ts +112 -0
  236. package/src/commands/version.test.ts +11 -0
  237. package/src/commands/version.ts +14 -0
  238. package/src/index.ts +30 -0
  239. package/src/output/formatter.ts +10 -0
  240. package/src/output/index.ts +2 -0
@@ -0,0 +1,118 @@
1
+ // packages/cli/src/commands/journal.ts
2
+ //
3
+ // `kit journal <feature-id> [--verify] [--json] [--limit N]`
4
+ //
5
+ // Read and verify the hash-chained execution journal (ADR-0021 §3),
6
+ // persisted at .ai-kit/journal/feature-runs/<featureId>.jsonl.
7
+ //
8
+ // The journal is the EXECUTED record — what happened, in order, with a
9
+ // tamper-evident hash chain. The run state remains the authority for
10
+ // phase advancement; this command observes, it never decides.
11
+ //
12
+ // Honest limits: --verify detects modification, insertion, and
13
+ // reordering. Tail truncation is NOT detectable from the journal alone
14
+ // (ADR-0021 §3.4); the verification output includes the last verified
15
+ // hash so it can be anchored externally.
16
+
17
+ import path from 'node:path';
18
+ import { readJournal, verifyJournal } from '@agentic-sdlc-kit/core';
19
+ import type { JournalEvent } from '@agentic-sdlc-kit/contracts';
20
+ import type { Command, CommandContext, CommandResult } from './types.js';
21
+
22
+ const DEFAULT_HUMAN_LIMIT = 50;
23
+
24
+ function fail(ctx: CommandContext, message: string): CommandResult {
25
+ ctx.stderr(`kit journal: ${message}\n`);
26
+ return { exitCode: 1, message };
27
+ }
28
+
29
+ export const journalCommand: Command = {
30
+ name: 'journal',
31
+ summary: 'Read or verify the hash-chained execution journal for a feature run (ADR-0021).',
32
+ async run(ctx: CommandContext): Promise<CommandResult> {
33
+ if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
34
+ ctx.stdout(formatHelp());
35
+ return { exitCode: 0 };
36
+ }
37
+
38
+ const isJson = ctx.argv.includes('--json');
39
+ const verify = ctx.argv.includes('--verify');
40
+ const positional = ctx.argv.filter((a) => !a.startsWith('-'));
41
+ const featureId = positional[0];
42
+ if (!featureId) {
43
+ return fail(ctx, 'missing required feature identifier (e.g. FEATURE-001)');
44
+ }
45
+ const root = path.resolve(ctx.cwd, '.');
46
+
47
+ if (verify) {
48
+ const res = await verifyJournal(root, featureId);
49
+ if (!res.ok) return fail(ctx, res.error.message);
50
+ if (isJson) {
51
+ ctx.stdout(JSON.stringify({ featureId, valid: true, ...res.value }, null, 2) + '\n');
52
+ } else {
53
+ const hash = res.value.lastHash ? ` (last hash ${res.value.lastHash.slice(0, 12)}…)` : '';
54
+ ctx.stdout(`Journal verified for ${featureId}: ${res.value.eventCount} event(s)${hash}\n`);
55
+ }
56
+ return { exitCode: 0 };
57
+ }
58
+
59
+ const res = await readJournal(root, featureId);
60
+ if (!res.ok) return fail(ctx, res.error.message);
61
+ const events = res.value;
62
+
63
+ if (isJson) {
64
+ ctx.stdout(JSON.stringify(events, null, 2) + '\n');
65
+ return { exitCode: 0 };
66
+ }
67
+
68
+ const limitIdx = ctx.argv.indexOf('--limit');
69
+ const limitArg = limitIdx >= 0 ? ctx.argv[limitIdx + 1] : undefined;
70
+ const limit =
71
+ limitArg && Number.isInteger(Number(limitArg)) && Number(limitArg) > 0
72
+ ? Number(limitArg)
73
+ : DEFAULT_HUMAN_LIMIT;
74
+ const shown = events.slice(-limit);
75
+ if (shown.length < events.length) {
76
+ ctx.stdout(`… ${events.length - shown.length} earlier event(s) hidden (use --limit) …\n`);
77
+ }
78
+ for (const event of shown) {
79
+ ctx.stdout(formatEvent(event));
80
+ }
81
+ if (events.length === 0) {
82
+ ctx.stdout(`Journal for ${featureId} is empty.\n`);
83
+ }
84
+ return { exitCode: 0 };
85
+ },
86
+ };
87
+
88
+ function formatEvent(event: JournalEvent): string {
89
+ const actor =
90
+ event.actor.host !== undefined ? `${event.actor.kind}:${event.actor.host}` : event.actor.kind;
91
+ const task = event.taskId !== undefined ? ` ${event.taskId}` : '';
92
+ const detail = Object.entries(event.payload)
93
+ .filter(([, v]) => v !== null && v !== undefined)
94
+ .map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
95
+ .join(' ');
96
+ return `[${event.seq}] ${event.ts} ${event.kind}${task} (${actor})${detail ? ` ${detail}` : ''}\n`;
97
+ }
98
+
99
+ function formatHelp(): string {
100
+ return [
101
+ 'Usage: kit journal <feature-id> [--verify] [--json] [--limit N]',
102
+ '',
103
+ 'Read or verify the hash-chained execution journal for a feature run:',
104
+ 'every workflow event, in order, with a tamper-evident hash chain',
105
+ '(ADR-0021). The journal observes; it never decides.',
106
+ '',
107
+ 'Options:',
108
+ ' --verify verify the chain (seq continuity + hash linkage + digests)',
109
+ ' --json machine-readable events (or verification result)',
110
+ ' --limit N list only the last N events (default 50, human output only)',
111
+ ' --help Show this message',
112
+ '',
113
+ 'Exit codes:',
114
+ ' 0 listed or verified',
115
+ ' 1 error: journal missing, unreadable, or (with --verify) chain violated',
116
+ '',
117
+ ].join('\n');
118
+ }
@@ -0,0 +1,96 @@
1
+ // packages/cli/src/commands/memory.ts
2
+ //
3
+ // `kit memory [query] [--domain <domain>] [--list] [--json]`.
4
+ // Inspects and queries hierarchical episodic, semantic, and procedural memories (M29).
5
+ //
6
+ // Reads from persisted memory at .ai-kit/state/memory.json.
7
+ // If no persisted memory exists, reports honestly that no memories have been
8
+ // accumulated yet (rather than seeding fake demo data).
9
+
10
+ import { MemoryStore } from '@agentic-sdlc-kit/core';
11
+ import type { Command, CommandContext, CommandResult } from './types.js';
12
+
13
+ export const memoryCommand: Command = {
14
+ name: 'memory',
15
+ summary: 'Query hierarchical episodic, semantic, and procedural engineering memories (M29).',
16
+ async run(ctx: CommandContext): Promise<CommandResult> {
17
+ if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
18
+ ctx.stdout(formatHelp());
19
+ return { exitCode: 0 };
20
+ }
21
+
22
+ const isJson = ctx.argv.includes('--json');
23
+ const isList = ctx.argv.includes('--list') || ctx.argv.includes('-l');
24
+ const domainIdx = ctx.argv.indexOf('--domain');
25
+ const domain = domainIdx !== -1 ? ctx.argv[domainIdx + 1] : undefined;
26
+ const query = ctx.argv.find((a) => !a.startsWith('-') && a !== '--list' && a !== '-l') ?? '';
27
+
28
+ const store = new MemoryStore();
29
+
30
+ // Load persisted memory from .ai-kit/state/memory.json.
31
+ // This file is written by `kit evolve` and by workflow runs that
32
+ // produce distilled lessons.
33
+ const loaded = await store.loadFromDisk(ctx.cwd);
34
+
35
+ if (loaded === 0) {
36
+ const msg =
37
+ 'kit memory: no memory entries found at .ai-kit/state/memory.json.\n' +
38
+ 'Run `kit evolve` to distill lessons from accumulated experiences, or\n' +
39
+ 'run workflows (`kit feature`) to produce experience records that\n' +
40
+ 'the evolution engine can learn from.\n';
41
+ if (isJson) {
42
+ ctx.stdout(JSON.stringify({ entries: [], message: msg.trim() }) + '\n');
43
+ } else {
44
+ ctx.stdout(msg);
45
+ }
46
+ return { exitCode: 0 };
47
+ }
48
+
49
+ // If --list, show all entries (optionally filtered by domain).
50
+ // Otherwise, search by query.
51
+ const results = isList
52
+ ? store.list().filter((e) => !domain || e.domain === domain)
53
+ : store.search(query, domain);
54
+
55
+ if (isJson) {
56
+ ctx.stdout(JSON.stringify(results, null, 2) + '\n');
57
+ } else {
58
+ ctx.stdout(formatResults(results));
59
+ }
60
+
61
+ return { exitCode: 0 };
62
+ },
63
+ };
64
+
65
+ function formatResults(results: ReturnType<MemoryStore['list']>): string {
66
+ if (results.length === 0) return 'No matching engineering memories found.\n';
67
+ const lines: string[] = [`Found ${results.length} memory entries:`];
68
+ for (const r of results) {
69
+ lines.push(
70
+ ` [${r.type.toUpperCase()}] ${r.id} (${r.domain}) - conf: ${(r.confidence * 100).toFixed(0)}%`,
71
+ );
72
+ lines.push(` ${r.summary}`);
73
+ lines.push(` ${r.content}`);
74
+ if (r.appliedCount > 0) {
75
+ lines.push(` applied: ${r.appliedCount}x, success: ${r.successCount}x`);
76
+ }
77
+ lines.push('');
78
+ }
79
+ return lines.join('\n');
80
+ }
81
+
82
+ function formatHelp(): string {
83
+ return [
84
+ 'Usage: kit memory [query] [--domain <domain>] [--list] [--json]',
85
+ '',
86
+ 'Search accumulated hierarchical engineering memories (episodic, semantic, procedural).',
87
+ 'Reads from .ai-kit/state/memory.json (produced by `kit evolve`).',
88
+ '',
89
+ 'Options:',
90
+ ' --domain <name> Filter by domain (e.g. architecture, tdd, security)',
91
+ ' --list, -l List all entries (ignores query argument)',
92
+ ' --json Output machine-readable memory entries',
93
+ ' --help Show this message',
94
+ '',
95
+ ].join('\n');
96
+ }
@@ -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
+ });