@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,194 @@
1
+ // packages/cli/src/commands/tier-c-conformance.test.ts
2
+ //
3
+ // Tier C conformance for the REAL CLI (ADR-0021 §5): every driver
4
+ // operation goes through the actual commands — feature, next, journal —
5
+ // against a real fixture project. This is the executable proof that
6
+ // the kit's own CLI implements the host-driven agent protocol a Tier C
7
+ // host (Cursor, AGY, CI) depends on. Any future host adapter runs the
8
+ // SAME golden trace through its own driver and must observe the same
9
+ // sequence.
10
+ import { promises as fs } from 'node:fs';
11
+ import os from 'node:os';
12
+ import path from 'node:path';
13
+ import { describe, expect, it } from 'vitest';
14
+ import { scaffoldSpecification, serializeProfileYaml } from '@agentic-sdlc-kit/core';
15
+ import type { JournalEvent, NextAction } from '@agentic-sdlc-kit/contracts';
16
+ import { runTierCConformanceTrace, type TierCConformanceDriver } from '@agentic-sdlc-kit/testing';
17
+ import { featureCommand } from './feature.js';
18
+ import { journalCommand } from './journal.js';
19
+ import { nextCommand } from './next.js';
20
+ import type { CommandContext } from './types.js';
21
+
22
+ function makeCtx(argv: string[], cwd: string): CommandContext {
23
+ return {
24
+ argv,
25
+ cwd,
26
+ stdout: () => undefined,
27
+ stderr: () => undefined,
28
+ };
29
+ }
30
+
31
+ async function setupProject(): Promise<string> {
32
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-tier-c-'));
33
+
34
+ await fs.mkdir(path.join(tmp, '.git'), { recursive: true });
35
+ await fs.writeFile(path.join(tmp, '.git', 'HEAD'), 'ref: refs/heads/main\n');
36
+
37
+ // Per-task markers: each task's verification fails with a REAL
38
+ // assertion error until ITS OWN marker exists, so a multi-task golden
39
+ // trace can implement tasks one at a time (same shape as the Mode 1
40
+ // orchestration fixture).
41
+ const script = path.join(tmp, 'check.js');
42
+ await fs.writeFile(
43
+ script,
44
+ [
45
+ 'const task = process.argv[2];',
46
+ 'if (!task) { console.error("AssertionError: missing task argument"); process.exit(1); }',
47
+ 'const fs = require("node:fs");',
48
+ 'if (!fs.existsSync(".done-" + task)) {',
49
+ ' console.error("AssertionError: expected target for " + task + " to be implemented");',
50
+ ' process.exit(1);',
51
+ '}',
52
+ 'process.exit(0);',
53
+ ].join('\n'),
54
+ );
55
+
56
+ const aiKit = path.join(tmp, '.ai-kit');
57
+ await fs.mkdir(aiKit, { recursive: true });
58
+ await fs.writeFile(
59
+ path.join(aiKit, 'project.yml'),
60
+ serializeProfileYaml({
61
+ schemaVersion: 1,
62
+ name: 'tier-c-conformance-app',
63
+ stack: ['node-typescript'],
64
+ commands: {
65
+ test: [
66
+ ['node', 'check.js', 'TASK-001'],
67
+ ['node', 'check.js', 'TASK-002'],
68
+ ],
69
+ },
70
+ }),
71
+ );
72
+
73
+ await scaffoldSpecification({
74
+ id: 'FEATURE-001',
75
+ title: 'Tier C Conformance',
76
+ targetDir: path.join(tmp, 'docs', 'specifications', 'features'),
77
+ });
78
+
79
+ const planDir = path.join(tmp, 'docs', 'plans', 'FEATURE-001');
80
+ await fs.mkdir(planDir, { recursive: true });
81
+ await fs.writeFile(
82
+ path.join(planDir, 'plan.json'),
83
+ JSON.stringify(
84
+ {
85
+ featureId: 'FEATURE-001',
86
+ tasks: ['TASK-001', 'TASK-002'].map((id) => ({
87
+ id,
88
+ description: `Implement ${id}`,
89
+ acceptanceCriteria: [`${id} works`],
90
+ verification: { command: ['node', 'check.js', id], expectedStatus: 'passed' },
91
+ dependencies: [],
92
+ likelyFiles: [`src/${id}.ts`],
93
+ estimatedScope: 's',
94
+ risk: 'low',
95
+ })),
96
+ edges: [],
97
+ verticalSlices: [['TASK-001'], ['TASK-002']],
98
+ },
99
+ null,
100
+ 2,
101
+ ),
102
+ );
103
+ return tmp;
104
+ }
105
+
106
+ /** The CLI driver: every protocol action is a REAL command invocation. */
107
+ function cliDriver(root: string): TierCConformanceDriver {
108
+ const runCommand = async (
109
+ command: { run(ctx: CommandContext): Promise<{ exitCode: number; message?: string }> },
110
+ argv: string[],
111
+ ): Promise<{ ok: boolean; message?: string }> => {
112
+ const result = await command.run(makeCtx(argv, root));
113
+ return result.exitCode === 0
114
+ ? { ok: true }
115
+ : { ok: false, message: result.message ?? `exit ${result.exitCode}` };
116
+ };
117
+
118
+ return {
119
+ start: (featureId) => runCommand(featureCommand, [featureId, 'start']),
120
+ async next(featureId) {
121
+ const out: string[] = [];
122
+ const result = await nextCommand.run({
123
+ argv: [featureId, '--json'],
124
+ cwd: root,
125
+ stdout: (s) => void out.push(s),
126
+ stderr: () => undefined,
127
+ });
128
+ expect(result.exitCode).toBe(0);
129
+ return JSON.parse(out.join('')) as NextAction;
130
+ },
131
+ runPhase: (featureId, taskId, phase) =>
132
+ runCommand(featureCommand, [featureId, phase, taskId, '--host', 'conformance-test']),
133
+ verify: (featureId) => runCommand(featureCommand, [featureId, 'verify']),
134
+ async journal(featureId) {
135
+ const out: string[] = [];
136
+ const result = await journalCommand.run({
137
+ argv: [featureId, '--json'],
138
+ cwd: root,
139
+ stdout: (s) => void out.push(s),
140
+ stderr: () => undefined,
141
+ });
142
+ expect(result.exitCode).toBe(0);
143
+ return JSON.parse(out.join('')) as JournalEvent[];
144
+ },
145
+ async verifyJournal(featureId) {
146
+ const out: string[] = [];
147
+ const result = await journalCommand.run({
148
+ argv: [featureId, '--verify', '--json'],
149
+ cwd: root,
150
+ stdout: (s) => void out.push(s),
151
+ stderr: () => undefined,
152
+ });
153
+ const parsed = JSON.parse(out.join('')) as {
154
+ valid: boolean;
155
+ eventCount: number;
156
+ };
157
+ return { ...parsed, ...(result.exitCode !== 0 ? { reason: 'verify command failed' } : {}) };
158
+ },
159
+ async applyImplementation(_featureId: string, taskId: string) {
160
+ // The fixture's "implementation" is the task's marker file — exactly
161
+ // where a real host's code edits would land between phases.
162
+ await fs.writeFile(path.join(root, `.done-${taskId}`), 'implemented\n', 'utf8');
163
+ },
164
+ };
165
+ }
166
+
167
+ describe('Tier C conformance: the real CLI drives the golden trace', () => {
168
+ it('passes the full golden trace for a two-task feature', async () => {
169
+ const root = await setupProject();
170
+ const report = await runTierCConformanceTrace(cliDriver(root), {
171
+ featureId: 'FEATURE-001',
172
+ taskIds: ['TASK-001', 'TASK-002'],
173
+ });
174
+ const failures = report.steps.filter((s) => !s.passed);
175
+ expect(failures).toEqual([]);
176
+ expect(report.passed).toBe(true);
177
+ });
178
+
179
+ it('records the host declaration in the journal actor for phase events', async () => {
180
+ const root = await setupProject();
181
+ const report = await runTierCConformanceTrace(cliDriver(root), {
182
+ featureId: 'FEATURE-001',
183
+ taskIds: ['TASK-001', 'TASK-002'],
184
+ });
185
+ expect(report.passed).toBe(true);
186
+ const driver = cliDriver(root);
187
+ const events = await driver.journal('FEATURE-001');
188
+ const phaseEvents = events.filter((e) => e.kind.startsWith('phase.'));
189
+ expect(phaseEvents.length).toBeGreaterThan(0);
190
+ for (const event of phaseEvents) {
191
+ expect(event.actor).toEqual({ kind: 'agent', host: 'conformance-test' });
192
+ }
193
+ });
194
+ });
@@ -0,0 +1,26 @@
1
+ // packages/cli/src/commands/types.ts
2
+ //
3
+ // Command interface. Every command implements this. The dispatcher
4
+ // (application/dispatcher.ts) is the only place that knows the full
5
+ // command list. Adding a command = adding one file + one registry entry.
6
+
7
+ export interface CommandContext {
8
+ argv: ReadonlyArray<string>;
9
+ cwd: string;
10
+ stdout: (s: string) => void;
11
+ stderr: (s: string) => void;
12
+ }
13
+
14
+ export interface CommandResult {
15
+ exitCode: number;
16
+ message?: string;
17
+ }
18
+
19
+ export interface Command {
20
+ /** Command name as invoked on the CLI: `doctor`, `version`, etc. */
21
+ readonly name: string;
22
+ /** One-line summary for `kit --help`. */
23
+ readonly summary: string;
24
+ /** Run the command. MUST NOT throw; failures return a non-zero exitCode. */
25
+ run(ctx: CommandContext): Promise<CommandResult> | CommandResult;
26
+ }
@@ -0,0 +1,107 @@
1
+ // packages/cli/src/commands/validate-plan.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 { validatePlanCommand } from './validate-plan.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('validatePlanCommand', () => {
26
+ it('shows help when --help is passed', async () => {
27
+ const ctx = makeCtx(['--help'], '/');
28
+ const r = await validatePlanCommand.run(ctx);
29
+ expect(r.exitCode).toBe(0);
30
+ expect(ctx.out[0]).toContain('Usage: kit validate-plan');
31
+ });
32
+
33
+ it('validates a valid implementation plan', async () => {
34
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-plan-'));
35
+ try {
36
+ const planFile = path.join(tmp, 'plan.json');
37
+ const plan = {
38
+ featureId: 'FEATURE-001',
39
+ tasks: [
40
+ {
41
+ id: 'TASK-001',
42
+ description: 'Build domain logic',
43
+ acceptanceCriteria: ['Valid behavior'],
44
+ verification: { command: ['npm', 'test'], expectedStatus: 'passed' },
45
+ dependencies: [],
46
+ likelyFiles: ['src/index.ts'],
47
+ estimatedScope: 's',
48
+ risk: 'low',
49
+ },
50
+ ],
51
+ edges: [],
52
+ verticalSlices: [['TASK-001']],
53
+ };
54
+ await fs.writeFile(planFile, JSON.stringify(plan, null, 2), 'utf8');
55
+
56
+ const ctx = makeCtx([planFile], tmp);
57
+ const r = await validatePlanCommand.run(ctx);
58
+ expect(r.exitCode).toBe(0);
59
+ expect(ctx.out[0]).toContain('kit validate-plan: PASS');
60
+ expect(ctx.out[0]).toContain('FEATURE-001');
61
+ } finally {
62
+ await fs.rm(tmp, { recursive: true, force: true });
63
+ }
64
+ });
65
+
66
+ it('fails when plan has dependency cycle', async () => {
67
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-plan-cycle-'));
68
+ try {
69
+ const planFile = path.join(tmp, 'plan.json');
70
+ const plan = {
71
+ featureId: 'FEATURE-001',
72
+ tasks: [
73
+ {
74
+ id: 'TASK-001',
75
+ description: 'Task A',
76
+ acceptanceCriteria: ['OK'],
77
+ verification: { command: ['npm', 'test'], expectedStatus: 'passed' },
78
+ dependencies: ['TASK-002'],
79
+ likelyFiles: [],
80
+ estimatedScope: 's',
81
+ risk: 'low',
82
+ },
83
+ {
84
+ id: 'TASK-002',
85
+ description: 'Task B',
86
+ acceptanceCriteria: ['OK'],
87
+ verification: { command: ['npm', 'test'], expectedStatus: 'passed' },
88
+ dependencies: ['TASK-001'],
89
+ likelyFiles: [],
90
+ estimatedScope: 's',
91
+ risk: 'low',
92
+ },
93
+ ],
94
+ edges: [],
95
+ verticalSlices: [['TASK-001', 'TASK-002']],
96
+ };
97
+ await fs.writeFile(planFile, JSON.stringify(plan, null, 2), 'utf8');
98
+
99
+ const ctx = makeCtx([planFile], tmp);
100
+ const r = await validatePlanCommand.run(ctx);
101
+ expect(r.exitCode).toBe(1);
102
+ expect(ctx.err[0]).toContain('Dependency cycle detected');
103
+ } finally {
104
+ await fs.rm(tmp, { recursive: true, force: true });
105
+ }
106
+ });
107
+ });
@@ -0,0 +1,67 @@
1
+ // packages/cli/src/commands/validate-plan.ts
2
+ //
3
+ // `kit validate-plan [path] [--json]`.
4
+ // Validates an implementation plan against schema, DAG acyclicity, and vertical slices.
5
+
6
+ import path from 'node:path';
7
+ import { loadPlan, type PlanValidationResult } from '@agentic-sdlc-kit/core';
8
+ import type { Command, CommandContext, CommandResult } from './types.js';
9
+
10
+ export const validatePlanCommand: Command = {
11
+ name: 'validate-plan',
12
+ summary: 'Validate an implementation plan against schema, DAG acyclicity, and task references.',
13
+ async run(ctx: CommandContext): Promise<CommandResult> {
14
+ if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
15
+ ctx.stdout(formatHelp());
16
+ return { exitCode: 0 };
17
+ }
18
+
19
+ const isJson = ctx.argv.includes('--json');
20
+ const targetArg = ctx.argv.find((a) => !a.startsWith('-'));
21
+ const targetPath = path.resolve(ctx.cwd, targetArg ?? 'docs/plans');
22
+
23
+ const res = await loadPlan(targetPath);
24
+ if (!res.ok) {
25
+ if (isJson) {
26
+ ctx.stdout(JSON.stringify({ valid: false, error: res.error }, null, 2) + '\n');
27
+ } else {
28
+ ctx.stderr(`kit validate-plan: FAIL: ${res.error.message}\n`);
29
+ }
30
+ return { exitCode: 1, message: res.error.message };
31
+ }
32
+
33
+ if (isJson) {
34
+ ctx.stdout(JSON.stringify({ valid: true, ...res.value }, null, 2) + '\n');
35
+ } else {
36
+ ctx.stdout(formatSuccessSummary(res.value));
37
+ }
38
+ return { exitCode: 0 };
39
+ },
40
+ };
41
+
42
+ function formatSuccessSummary(val: PlanValidationResult): string {
43
+ const { plan, analysis } = val;
44
+ const highRisk = plan.tasks.filter((t) => t.risk === 'high').length;
45
+ const lines: string[] = [
46
+ `kit validate-plan: PASS`,
47
+ `Feature: ${plan.featureId}`,
48
+ `Tasks: ${plan.tasks.length} total (${highRisk} high risk)`,
49
+ `Slices: ${plan.verticalSlices.length} vertical slices`,
50
+ `Execution DAG: ${analysis.executionOrder.join(' -> ')}`,
51
+ ];
52
+ return lines.join('\n') + '\n';
53
+ }
54
+
55
+ function formatHelp(): string {
56
+ return [
57
+ 'Usage: kit validate-plan [path] [--json]',
58
+ '',
59
+ 'Validate an implementation plan for schema compliance, task dependency integrity,',
60
+ 'and acyclic execution order.',
61
+ '',
62
+ 'Options:',
63
+ ' --json Output machine-readable validation result',
64
+ ' --help Show this message',
65
+ '',
66
+ ].join('\n');
67
+ }
@@ -0,0 +1,59 @@
1
+ // packages/cli/src/commands/validate-spec.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 { scaffoldSpecification } from '@agentic-sdlc-kit/core';
7
+ import { validateSpecCommand } from './validate-spec.js';
8
+ import type { CommandContext } from './types.js';
9
+
10
+ const makeCtx = (
11
+ argv: string[],
12
+ cwd: string,
13
+ ): CommandContext & { out: string[]; err: string[] } => {
14
+ const out: string[] = [];
15
+ const err: string[] = [];
16
+ return {
17
+ argv,
18
+ cwd,
19
+ stdout: (s) => void out.push(s),
20
+ stderr: (s) => void err.push(s),
21
+ out,
22
+ err,
23
+ };
24
+ };
25
+
26
+ describe('validateSpecCommand', () => {
27
+ it('shows help when --help is passed', async () => {
28
+ const ctx = makeCtx(['--help'], '/');
29
+ const r = await validateSpecCommand.run(ctx);
30
+ expect(r.exitCode).toBe(0);
31
+ expect(ctx.out[0]).toContain('Usage: kit validate-spec');
32
+ });
33
+
34
+ it('validates a scaffolded specification successfully', async () => {
35
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-spec-'));
36
+ try {
37
+ const featureDir = await scaffoldSpecification({
38
+ id: 'FEATURE-001',
39
+ title: 'Test Feature',
40
+ targetDir: tmp,
41
+ });
42
+
43
+ const ctx = makeCtx([featureDir], tmp);
44
+ const r = await validateSpecCommand.run(ctx);
45
+ expect(r.exitCode).toBe(0);
46
+ expect(ctx.out[0]).toContain('kit validate-spec: PASS');
47
+ expect(ctx.out[0]).toContain('FEATURE-001');
48
+ } finally {
49
+ await fs.rm(tmp, { recursive: true, force: true });
50
+ }
51
+ });
52
+
53
+ it('fails when specification file is invalid or missing', async () => {
54
+ const ctx = makeCtx(['/nonexistent/spec/path'], '/');
55
+ const r = await validateSpecCommand.run(ctx);
56
+ expect(r.exitCode).toBe(1);
57
+ expect(ctx.err[0]).toContain('kit validate-spec: FAIL');
58
+ });
59
+ });
@@ -0,0 +1,68 @@
1
+ // packages/cli/src/commands/validate-spec.ts
2
+ //
3
+ // `kit validate-spec [path] [--json]`.
4
+ // Validates a feature specification against schema, acceptance criteria, and scope rules.
5
+
6
+ import path from 'node:path';
7
+ import { loadSpecification } from '@agentic-sdlc-kit/core';
8
+ import type { FeatureSpecification } from '@agentic-sdlc-kit/contracts';
9
+ import type { Command, CommandContext, CommandResult } from './types.js';
10
+
11
+ export const validateSpecCommand: Command = {
12
+ name: 'validate-spec',
13
+ summary: 'Validate a feature specification against schema, quality, and risk invariants.',
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 isJson = ctx.argv.includes('--json');
21
+ const targetArg = ctx.argv.find((a) => !a.startsWith('-'));
22
+ const targetPath = path.resolve(ctx.cwd, targetArg ?? 'docs/specifications');
23
+
24
+ const res = await loadSpecification(targetPath);
25
+ if (!res.ok) {
26
+ if (isJson) {
27
+ ctx.stdout(JSON.stringify({ valid: false, error: res.error }, null, 2) + '\n');
28
+ } else {
29
+ ctx.stderr(`kit validate-spec: FAIL: ${res.error.message}\n`);
30
+ }
31
+ return { exitCode: 1, message: res.error.message };
32
+ }
33
+
34
+ if (isJson) {
35
+ ctx.stdout(JSON.stringify({ valid: true, specification: res.value }, null, 2) + '\n');
36
+ } else {
37
+ ctx.stdout(formatSuccessSummary(res.value));
38
+ }
39
+ return { exitCode: 0 };
40
+ },
41
+ };
42
+
43
+ function formatSuccessSummary(spec: FeatureSpecification): string {
44
+ const lines: string[] = [
45
+ `kit validate-spec: PASS`,
46
+ `Feature: ${spec.id} - ${spec.title}`,
47
+ `Scope: ${spec.scope.in.length} in-scope, ${spec.scope.out.length} out-of-scope`,
48
+ `Requirements: ${spec.functionalRequirements.length} functional, ${spec.nonFunctionalRequirements.length} non-functional`,
49
+ `Acceptance: ${spec.acceptanceCriteria.length} criteria defined`,
50
+ `Risks: ${spec.risks.length} analyzed (${spec.risks.filter((r) => r.severity === 'high').length} high)`,
51
+ `Open Questions:${spec.openQuestions.length} (${spec.openQuestions.filter((q) => !q.resolved).length} unresolved)`,
52
+ ];
53
+ return lines.join('\n') + '\n';
54
+ }
55
+
56
+ function formatHelp(): string {
57
+ return [
58
+ 'Usage: kit validate-spec [path] [--json]',
59
+ '',
60
+ 'Validate a feature specification (SPEC.md or JSON) for structural completeness,',
61
+ 'scope boundaries, ID uniqueness, and risk governance.',
62
+ '',
63
+ 'Options:',
64
+ ' --json Output machine-readable validation result',
65
+ ' --help Show this message',
66
+ '',
67
+ ].join('\n');
68
+ }
@@ -0,0 +1,117 @@
1
+ // packages/cli/src/commands/verify.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 { serializeProfileYaml } from '@agentic-sdlc-kit/core';
7
+ import type { ProjectProfile } from '@agentic-sdlc-kit/contracts';
8
+ import { verifyCommand } from './verify.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('verifyCommand', () => {
28
+ it('shows help when --help is passed', async () => {
29
+ const ctx = makeCtx(['--help'], '/');
30
+ const r = await verifyCommand.run(ctx);
31
+ expect(r.exitCode).toBe(0);
32
+ expect(ctx.out[0]).toContain('Usage: kit verify');
33
+ });
34
+
35
+ it('fails if .ai-kit/project.yml does not exist', async () => {
36
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-empty-'));
37
+ try {
38
+ const ctx = makeCtx([], tmp);
39
+ const r = await verifyCommand.run(ctx);
40
+ expect(r.exitCode).toBe(1);
41
+ expect(ctx.err[0]).toContain('Profile not found');
42
+ } finally {
43
+ await fs.rm(tmp, { recursive: true, force: true });
44
+ }
45
+ });
46
+
47
+ it('executes configured verification commands and passes', async () => {
48
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-pass-'));
49
+ try {
50
+ const aiKitDir = path.join(tmp, '.ai-kit');
51
+ await fs.mkdir(aiKitDir, { recursive: true });
52
+
53
+ const profile: ProjectProfile = {
54
+ schemaVersion: 1,
55
+ name: 'test-cli-app',
56
+ stack: ['node-typescript'],
57
+ commands: {
58
+ test: [['node', '-e', 'process.exit(0)']],
59
+ },
60
+ };
61
+ await fs.writeFile(path.join(aiKitDir, 'project.yml'), serializeProfileYaml(profile), 'utf8');
62
+
63
+ const ctx = makeCtx([], tmp);
64
+ const r = await verifyCommand.run(ctx);
65
+ expect(r.exitCode).toBe(0);
66
+ expect(ctx.out[0]).toContain('Status: PASSED');
67
+ } finally {
68
+ await fs.rm(tmp, { recursive: true, force: true });
69
+ }
70
+ });
71
+
72
+ it('surfaces schema issues when the profile fails validation (no bare error)', async () => {
73
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-schema-'));
74
+ try {
75
+ const aiKitDir = path.join(tmp, '.ai-kit');
76
+ await fs.mkdir(aiKitDir, { recursive: true });
77
+ // stack: [] violates the contract (min 1 entry) — the CLI must say
78
+ // WHY, not just "failed schema validation".
79
+ await fs.writeFile(
80
+ path.join(aiKitDir, 'project.yml'),
81
+ ['schemaVersion: 1', 'name: "x"', 'stack: []', ''].join('\n'),
82
+ 'utf8',
83
+ );
84
+ const ctx = makeCtx([], tmp);
85
+ const r = await verifyCommand.run(ctx);
86
+ expect(r.exitCode).toBe(1);
87
+ expect(ctx.err[0]).toContain('failed schema validation');
88
+ expect(ctx.err[0]).toContain('stack');
89
+ expect(ctx.err[0]).toContain('at least one entry');
90
+ } finally {
91
+ await fs.rm(tmp, { recursive: true, force: true });
92
+ }
93
+ });
94
+
95
+ it('hints at the expected commands shape when zero checks are configured', async () => {
96
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-verify-zero-'));
97
+ try {
98
+ const aiKitDir = path.join(tmp, '.ai-kit');
99
+ await fs.mkdir(aiKitDir, { recursive: true });
100
+ const profile: ProjectProfile = {
101
+ schemaVersion: 1,
102
+ name: 'zero-checks-app',
103
+ stack: ['node-typescript'],
104
+ commands: {},
105
+ };
106
+ await fs.writeFile(path.join(aiKitDir, 'project.yml'), serializeProfileYaml(profile), 'utf8');
107
+
108
+ const ctx = makeCtx([], tmp);
109
+ const r = await verifyCommand.run(ctx);
110
+ expect(r.exitCode).toBe(1);
111
+ expect(ctx.out[0]).toContain('(none configured)');
112
+ expect(ctx.out[0]).toContain('commands:');
113
+ } finally {
114
+ await fs.rm(tmp, { recursive: true, force: true });
115
+ }
116
+ });
117
+ });