@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,124 @@
1
+ // packages/cli/src/commands/skills-install-manifest.ts
2
+ //
3
+ // The skills manifest (`.ai-kit/skills-manifest.json`) is the ownership
4
+ // record for `kit skills install`: it is the only evidence of which skill
5
+ // directories the kit placed into a project, so `--force` may replace
6
+ // exactly those directories and nothing else.
7
+ //
8
+ // Reading is fail-closed: a manifest that exists but cannot be parsed is a
9
+ // hard error, never a silent reset — overwriting it with a fresh one would
10
+ // erase the ownership records of every previously installed pack.
11
+
12
+ import { promises as fs } from 'node:fs';
13
+ import { SecureInstallError } from './skills-install-secure.js';
14
+
15
+ export interface SkillInstallStatus {
16
+ name: string;
17
+ status: 'installed' | 'skipped-existing' | 'skipped-unowned';
18
+ }
19
+
20
+ export interface PackRecord {
21
+ repository: string;
22
+ url: string;
23
+ ref: string;
24
+ commit: string;
25
+ into: string;
26
+ installedAt: string;
27
+ skills: SkillInstallStatus[];
28
+ }
29
+
30
+ export interface SkillsManifest {
31
+ schemaVersion: 1;
32
+ packs: Record<string, PackRecord>;
33
+ }
34
+
35
+ const RECOVERY_HINT =
36
+ 'kit refuses to overwrite a manifest it cannot read — earlier pack records would be lost.\n' +
37
+ 'Restore the file from version control, repair it by hand, or delete it to forget\n' +
38
+ 'all recorded installs and start fresh.';
39
+
40
+ const isSkillStatus = (v: unknown): v is SkillInstallStatus =>
41
+ typeof v === 'object' &&
42
+ v !== null &&
43
+ typeof (v as Record<string, unknown>).name === 'string' &&
44
+ typeof (v as Record<string, unknown>).status === 'string';
45
+
46
+ const isPackRecord = (v: unknown): v is PackRecord =>
47
+ typeof v === 'object' &&
48
+ v !== null &&
49
+ typeof (v as Record<string, unknown>).repository === 'string' &&
50
+ typeof (v as Record<string, unknown>).url === 'string' &&
51
+ typeof (v as Record<string, unknown>).ref === 'string' &&
52
+ typeof (v as Record<string, unknown>).commit === 'string' &&
53
+ typeof (v as Record<string, unknown>).into === 'string' &&
54
+ typeof (v as Record<string, unknown>).installedAt === 'string' &&
55
+ Array.isArray((v as Record<string, unknown>).skills) &&
56
+ ((v as Record<string, unknown>).skills as unknown[]).every(isSkillStatus);
57
+
58
+ /**
59
+ * Read the skills manifest. A missing file is a fresh start; a file that
60
+ * exists but is malformed fails closed instead of being silently reset.
61
+ */
62
+ export async function readSkillsManifest(manifestPath: string): Promise<SkillsManifest> {
63
+ let raw: string;
64
+ try {
65
+ raw = await fs.readFile(manifestPath, 'utf8');
66
+ } catch {
67
+ return { schemaVersion: 1, packs: {} };
68
+ }
69
+ const where = ` (at ${manifestPath})`;
70
+ let parsed: unknown;
71
+ try {
72
+ parsed = JSON.parse(raw);
73
+ } catch {
74
+ throw new SecureInstallError(`skills manifest is not valid JSON${where}\n${RECOVERY_HINT}`);
75
+ }
76
+ const shape = parsed as { schemaVersion?: unknown; packs?: unknown };
77
+ const packsOk =
78
+ typeof shape.packs === 'object' &&
79
+ shape.packs !== null &&
80
+ !Array.isArray(shape.packs) &&
81
+ Object.values(shape.packs as Record<string, unknown>).every(isPackRecord);
82
+ if (shape.schemaVersion !== 1 || !packsOk) {
83
+ throw new SecureInstallError(
84
+ `skills manifest has an unexpected shape${where} ` +
85
+ `(expected schemaVersion 1 with a packs object of pack records)\n${RECOVERY_HINT}`,
86
+ );
87
+ }
88
+ return parsed as SkillsManifest;
89
+ }
90
+
91
+ /**
92
+ * Skill directories the kit previously installed into this exact target
93
+ * directory. Only `installed` statuses count: `skipped-existing` means the
94
+ * directory was already there (possibly user-authored) and was never touched.
95
+ */
96
+ export function ownedSkillNames(manifest: SkillsManifest, into: string): Set<string> {
97
+ const owned = new Set<string>();
98
+ for (const record of Object.values(manifest.packs)) {
99
+ if (record.into !== into) continue;
100
+ for (const s of record.skills) {
101
+ if (s.status === 'installed') owned.add(s.name);
102
+ }
103
+ }
104
+ return owned;
105
+ }
106
+
107
+ /**
108
+ * Merge the run's statuses with the previous record so ownership survives
109
+ * idempotent re-runs: a skill the kit installed once stays `installed` when
110
+ * a later no-force run merely reports it as `skipped-existing`.
111
+ */
112
+ export function mergeOwnership(
113
+ previous: PackRecord | undefined,
114
+ statuses: SkillInstallStatus[],
115
+ ): SkillInstallStatus[] {
116
+ const wasInstalled = new Set(
117
+ (previous?.skills ?? []).filter((s) => s.status === 'installed').map((s) => s.name),
118
+ );
119
+ return statuses.map((s) =>
120
+ s.status === 'skipped-existing' && wasInstalled.has(s.name)
121
+ ? { name: s.name, status: 'installed' }
122
+ : s,
123
+ );
124
+ }
@@ -0,0 +1,60 @@
1
+ // packages/cli/src/commands/skills-install-report.ts
2
+ //
3
+ // Human- and machine-facing result formatting for `kit skills install`.
4
+ // Text output keeps the original layout (Target / Installed / Skipped) and
5
+ // adds Refused for directories --force declined to touch because the kit
6
+ // did not install them.
7
+
8
+ import type { SkillInstallStatus } from './skills-install-manifest.js';
9
+
10
+ export function formatResult(
11
+ packName: string,
12
+ into: string,
13
+ statuses: SkillInstallStatus[],
14
+ manifestPath: string,
15
+ ): string {
16
+ const installed = statuses.filter((s) => s.status === 'installed');
17
+ const skipped = statuses.filter((s) => s.status === 'skipped-existing');
18
+ const refused = statuses.filter((s) => s.status === 'skipped-unowned');
19
+ const lines: string[] = [`kit skills install: SUCCESS (${packName})`];
20
+ lines.push(` Target: ${into}`);
21
+ lines.push(` Installed: ${installed.length} skill(s)`);
22
+ for (const s of installed) lines.push(` + ${s.name}`);
23
+ if (skipped.length > 0) {
24
+ lines.push(` Skipped: ${skipped.length} existing skill(s) (use --force to overwrite)`);
25
+ for (const s of skipped) lines.push(` ~ ${s.name}`);
26
+ }
27
+ if (refused.length > 0) {
28
+ lines.push(
29
+ ` Refused: ${refused.length} unowned skill(s) (--force replaces only kit-installed skills)`,
30
+ );
31
+ for (const s of refused) lines.push(` ! ${s.name}`);
32
+ }
33
+ lines.push(` Manifest: ${manifestPath}`);
34
+ lines.push('');
35
+ return lines.join('\n');
36
+ }
37
+
38
+ export interface DryRunPlan {
39
+ pack: string;
40
+ repository: string;
41
+ ref: string;
42
+ target: string;
43
+ expectedSkills: number;
44
+ dryRun: boolean;
45
+ }
46
+
47
+ export function formatDryRun(plan: DryRunPlan): string {
48
+ const lines: string[] = [
49
+ 'kit skills install --dry-run',
50
+ ` Pack: ${plan.pack}`,
51
+ ` Repository: ${plan.repository}`,
52
+ ` Ref: ${plan.ref}`,
53
+ ` Target: ${plan.target}`,
54
+ ` Expected: ${plan.expectedSkills} skill(s) from pack metadata`,
55
+ '',
56
+ 'No files written and no repository cloned. Run without --dry-run to execute.',
57
+ '',
58
+ ];
59
+ return lines.join('\n');
60
+ }
@@ -0,0 +1,113 @@
1
+ // packages/cli/src/commands/skills-install-secure.ts
2
+ //
3
+ // Fail-closed filesystem primitives for `kit skills install`
4
+ // (docs/security/SECURITY.md threat model: an external skills pack is
5
+ // untrusted content; a skills destination is untrusted until proven clean).
6
+ //
7
+ // Every rule here is a hard error, never a warning and never a silent skip:
8
+ // 1. `--into` must resolve inside the target project (path traversal).
9
+ // 2. No component of the destination path may be a symlink, so a planted
10
+ // link can never redirect kit writes outside the project.
11
+ // 3. Pack content is copied without ever following symlinks; a symlink
12
+ // anywhere in a skill directory is rejected, not skipped.
13
+ // 4. Every SKILL.md must carry YAML frontmatter whose `name` matches its
14
+ // directory and that declares a `description` (Agent Skills format).
15
+
16
+ import { promises as fs } from 'node:fs';
17
+ import path from 'node:path';
18
+
19
+ /** Hard installer error. The message is user-facing; there is never a default. */
20
+ export class SecureInstallError extends Error {}
21
+
22
+ const SKILL_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
23
+
24
+ /** Resolve `--into` against the project root and enforce containment. */
25
+ export function resolveInstallTarget(targetRoot: string, into: string): string {
26
+ const root = path.resolve(targetRoot);
27
+ const target = path.resolve(root, into);
28
+ if (target === root) {
29
+ throw new SecureInstallError(
30
+ `--into must name a subdirectory of the project, not the project itself: '${into}'`,
31
+ );
32
+ }
33
+ if (!target.startsWith(root + path.sep)) {
34
+ throw new SecureInstallError(
35
+ `--into escapes the project directory: '${into}' ` +
36
+ `(resolved to ${target}; the project is ${root})`,
37
+ );
38
+ }
39
+ return target;
40
+ }
41
+
42
+ /** Reject a destination whose path traverses a symlinked component. */
43
+ export async function assertPathSymlinkFree(root: string, target: string): Promise<void> {
44
+ const rel = path.relative(path.resolve(root), path.resolve(target));
45
+ let current = path.resolve(root);
46
+ for (const part of rel.split(path.sep)) {
47
+ if (!part || part === '.') continue;
48
+ current = path.join(current, part);
49
+ const stat = await fs.lstat(current).catch(() => null);
50
+ if (stat?.isSymbolicLink()) {
51
+ throw new SecureInstallError(
52
+ `refusing to install through a symlinked path component: ${current}`,
53
+ );
54
+ }
55
+ }
56
+ }
57
+
58
+ /** Skill directory names become filesystem path components: validate them. */
59
+ export function assertSafeSkillName(name: string): void {
60
+ if (!SKILL_NAME_PATTERN.test(name)) {
61
+ throw new SecureInstallError(`unsafe skill directory name in pack: '${name}'`);
62
+ }
63
+ }
64
+
65
+ /** Copy a directory tree, rejecting symlinks and special file types. */
66
+ export async function copyTreeSecure(src: string, dest: string): Promise<void> {
67
+ const entries = await fs.readdir(src, { withFileTypes: true });
68
+ await fs.mkdir(dest, { recursive: true });
69
+ for (const entry of entries) {
70
+ const from = path.join(src, entry.name);
71
+ if (entry.isSymbolicLink()) {
72
+ throw new SecureInstallError(`symlink in pack content (nothing installed): ${from}`);
73
+ }
74
+ if (!entry.isFile() && !entry.isDirectory()) {
75
+ throw new SecureInstallError(`unsupported file type in pack (nothing installed): ${from}`);
76
+ }
77
+ if (entry.isDirectory()) {
78
+ await copyTreeSecure(from, path.join(dest, entry.name));
79
+ } else {
80
+ await fs.copyFile(from, path.join(dest, entry.name));
81
+ }
82
+ }
83
+ }
84
+
85
+ /** Validate a staged SKILL.md against the Agent Skills frontmatter contract. */
86
+ export async function validateSkillFrontmatter(
87
+ skillMd: string,
88
+ expectedName: string,
89
+ ): Promise<void> {
90
+ const raw = await fs.readFile(skillMd, 'utf8');
91
+ const lines = raw.replace(/^\uFEFF/, '').split(/\r?\n/);
92
+ if (lines[0]?.trim() !== '---') {
93
+ throw new SecureInstallError(`SKILL.md has no YAML frontmatter: ${skillMd}`);
94
+ }
95
+ const close = lines.findIndex((line, i) => i > 0 && line.trim() === '---');
96
+ if (close === -1) {
97
+ throw new SecureInstallError(`SKILL.md frontmatter is never closed: ${skillMd}`);
98
+ }
99
+ const frontmatter = lines.slice(1, close);
100
+ const nameLine = frontmatter.find((l) => l.startsWith('name:'));
101
+ const name = nameLine?.slice('name:'.length).trim();
102
+ const hasDescription = frontmatter.some((l) => l.startsWith('description:'));
103
+ if (!name || !hasDescription) {
104
+ throw new SecureInstallError(
105
+ `SKILL.md frontmatter must declare name and description: ${skillMd}`,
106
+ );
107
+ }
108
+ if (name !== expectedName) {
109
+ throw new SecureInstallError(
110
+ `SKILL.md name '${name}' does not match its directory '${expectedName}': ${skillMd}`,
111
+ );
112
+ }
113
+ }
@@ -0,0 +1,245 @@
1
+ // packages/cli/src/commands/skills-install.ts
2
+ //
3
+ // Executor for `kit skills install <pack>`. Fetches an external skills pack
4
+ // from its GitHub repository (shallow clone, default branch), copies the
5
+ // pack's `skills/*` directories into the target project, and records the
6
+ // installation in `.ai-kit/skills-manifest.json`.
7
+ //
8
+ // Failure policy (kit convention): never fabricate success. A failed clone or
9
+ // a missing skills/ directory returns exit code 1 with a fix instruction, and
10
+ // nothing is written to the project. Already-present skill directories are
11
+ // skipped unless `--force`; `--force` replaces only directories the kit
12
+ // previously installed (the manifest is the ownership record), so re-running
13
+ // is idempotent and user-authored skills are never deleted.
14
+ //
15
+ // Install path security is split across focused modules:
16
+ // ./skills-install-secure.ts containment, symlink refusal, frontmatter
17
+ // ./skills-install-manifest.ts fail-closed manifest reads and ownership
18
+ // ./skills-install-commit.ts staged plan → validate → atomic commit
19
+
20
+ import { execFile } from 'node:child_process';
21
+ import { promises as fs } from 'node:fs';
22
+ import os from 'node:os';
23
+ import path from 'node:path';
24
+ import { promisify } from 'node:util';
25
+ import { resolveSkillsPack } from '@agentic-sdlc-kit/core';
26
+ import type { CommandContext, CommandResult } from './types.js';
27
+ import {
28
+ SecureInstallError,
29
+ assertPathSymlinkFree,
30
+ assertSafeSkillName,
31
+ resolveInstallTarget,
32
+ } from './skills-install-secure.js';
33
+ import {
34
+ type PackRecord,
35
+ type SkillsManifest,
36
+ mergeOwnership,
37
+ readSkillsManifest,
38
+ } from './skills-install-manifest.js';
39
+ import {
40
+ CommitError,
41
+ commitStagedSkills,
42
+ planSkillInstalls,
43
+ stageSkills,
44
+ statusesFromPlan,
45
+ } from './skills-install-commit.js';
46
+ import { formatDryRun, formatResult } from './skills-install-report.js';
47
+
48
+ const execFileAsync = promisify(execFile);
49
+
50
+ const DEFAULT_INTO = '.claude/skills';
51
+
52
+ export interface SkillsInstallOptions {
53
+ packId: string;
54
+ targetRoot: string;
55
+ into?: string;
56
+ ref?: string;
57
+ force: boolean;
58
+ dryRun: boolean;
59
+ json: boolean;
60
+ /** Install from a local checkout of the pack instead of cloning GitHub. */
61
+ source?: string;
62
+ }
63
+
64
+ async function clonePackSource(
65
+ packUrl: string,
66
+ ref: string | undefined,
67
+ dest: string,
68
+ ): Promise<string> {
69
+ const args = ['clone', '--depth', '1', '--quiet'];
70
+ if (ref) args.push('--branch', ref);
71
+ args.push(packUrl, dest);
72
+ await execFileAsync('git', args, { maxBuffer: 8 * 1024 * 1024 });
73
+ const { stdout } = await execFileAsync('git', ['-C', dest, 'rev-parse', 'HEAD']);
74
+ return stdout.trim();
75
+ }
76
+
77
+ /** Locate the pack source (local --source or a shallow clone) and its commit. */
78
+ async function acquireSource(
79
+ packUrl: string,
80
+ skillsPath: string,
81
+ opts: SkillsInstallOptions,
82
+ ): Promise<{ sourceRoot: string; commit: string; isTemp: boolean }> {
83
+ if (opts.source) {
84
+ const present = await fs.access(path.join(opts.source, skillsPath)).then(
85
+ () => true,
86
+ () => false,
87
+ );
88
+ if (!present) {
89
+ throw new SecureInstallError(
90
+ `--source directory has no '${skillsPath}/' directory: ${opts.source}`,
91
+ );
92
+ }
93
+ return { sourceRoot: opts.source, commit: 'local-source', isTemp: false };
94
+ }
95
+ const sourceRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-skills-'));
96
+ const commit = await clonePackSource(packUrl, opts.ref, sourceRoot);
97
+ return { sourceRoot, commit, isTemp: true };
98
+ }
99
+
100
+ async function listSkillDirs(skillsDir: string): Promise<string[]> {
101
+ const entries = await fs.readdir(skillsDir, { withFileTypes: true });
102
+ const names: string[] = [];
103
+ for (const e of entries) {
104
+ if (e.isSymbolicLink()) {
105
+ throw new SecureInstallError(
106
+ `symlinked entry in pack skills/ (nothing installed): ${path.join(skillsDir, e.name)}`,
107
+ );
108
+ }
109
+ if (!e.isDirectory()) continue;
110
+ const hasSkillMd = await fs.access(path.join(skillsDir, e.name, 'SKILL.md')).then(
111
+ () => true,
112
+ () => false,
113
+ );
114
+ if (!hasSkillMd) continue;
115
+ assertSafeSkillName(e.name);
116
+ names.push(e.name);
117
+ }
118
+ return names.sort();
119
+ }
120
+
121
+ /** Resolve and validate the install target, or fail closed with exit 1. */
122
+ async function resolveTarget(
123
+ opts: SkillsInstallOptions,
124
+ into: string,
125
+ ctx: CommandContext,
126
+ ): Promise<string | null> {
127
+ try {
128
+ const targetDir = resolveInstallTarget(opts.targetRoot, into);
129
+ await assertPathSymlinkFree(opts.targetRoot, targetDir);
130
+ return targetDir;
131
+ } catch (err) {
132
+ if (!(err instanceof SecureInstallError)) throw err;
133
+ ctx.stderr(`kit skills: ${err.message}\n`);
134
+ return null;
135
+ }
136
+ }
137
+
138
+ /** Run the install subcommand. Never throws; failures return exitCode 1. */
139
+ export async function runSkillsInstall(
140
+ opts: SkillsInstallOptions,
141
+ ctx: CommandContext,
142
+ ): Promise<CommandResult> {
143
+ const pack = resolveSkillsPack(opts.packId);
144
+ if (!pack) {
145
+ ctx.stderr(`kit skills: unknown skills pack '${opts.packId}'\n`);
146
+ return { exitCode: 1, message: `unknown skills pack: ${opts.packId}` };
147
+ }
148
+ const into = opts.into ?? DEFAULT_INTO;
149
+ const targetDir = await resolveTarget(opts, into, ctx);
150
+ if (targetDir === null) return { exitCode: 1, message: `unsafe install target: ${into}` };
151
+ const manifestPath = path.join(opts.targetRoot, '.ai-kit', 'skills-manifest.json');
152
+
153
+ if (opts.dryRun) {
154
+ const plan = {
155
+ pack: pack.id,
156
+ repository: pack.repository,
157
+ ref: opts.ref ?? 'default branch',
158
+ target: into,
159
+ expectedSkills: pack.skillCount,
160
+ dryRun: true,
161
+ };
162
+ const text = opts.json ? JSON.stringify(plan, null, 2) + '\n' : formatDryRun(plan);
163
+ ctx.stdout(text);
164
+ return { exitCode: 0 };
165
+ }
166
+
167
+ let stagingRoot = '';
168
+ let keepStaging = false;
169
+ try {
170
+ let manifest: SkillsManifest;
171
+ try {
172
+ manifest = await readSkillsManifest(manifestPath);
173
+ } catch (err) {
174
+ if (!(err instanceof SecureInstallError)) throw err;
175
+ ctx.stderr(`kit skills: ${err.message}\n`);
176
+ return { exitCode: 1, message: 'skills manifest is unreadable' };
177
+ }
178
+
179
+ const { sourceRoot, commit, isTemp } = await acquireSource(pack.url, pack.skillsPath, opts);
180
+ try {
181
+ const skillsDir = path.join(sourceRoot, pack.skillsPath);
182
+ const present = await fs.access(skillsDir).then(
183
+ () => true,
184
+ () => false,
185
+ );
186
+ if (!present) {
187
+ ctx.stderr(
188
+ `kit skills: ${pack.id} has no '${pack.skillsPath}/' directory at ${sourceRoot}\n`,
189
+ );
190
+ return { exitCode: 1, message: 'pack skills directory missing' };
191
+ }
192
+ const names = await listSkillDirs(skillsDir);
193
+ const plan = await planSkillInstalls(names, targetDir, opts.force, manifest, into);
194
+
195
+ const tmpRoot = path.join(opts.targetRoot, '.ai-kit', 'tmp');
196
+ await fs.mkdir(tmpRoot, { recursive: true });
197
+ stagingRoot = await fs.mkdtemp(path.join(tmpRoot, 'skills-'));
198
+ const staged = await stageSkills(skillsDir, plan, stagingRoot);
199
+ await commitStagedSkills(staged, targetDir, stagingRoot);
200
+
201
+ const statuses = statusesFromPlan(plan);
202
+ const previous: PackRecord | undefined = manifest.packs[pack.id];
203
+ manifest.packs[pack.id] = {
204
+ repository: pack.repository,
205
+ url: pack.url,
206
+ ref: opts.ref ?? 'default-branch',
207
+ commit,
208
+ into,
209
+ installedAt: new Date().toISOString(),
210
+ skills: mergeOwnership(previous, statuses),
211
+ };
212
+ await fs.mkdir(path.dirname(manifestPath), { recursive: true });
213
+ await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf8');
214
+ const text = opts.json
215
+ ? JSON.stringify(
216
+ {
217
+ installed: true,
218
+ pack: pack.id,
219
+ commit,
220
+ into,
221
+ skills: statuses,
222
+ manifest: '.ai-kit/skills-manifest.json',
223
+ },
224
+ null,
225
+ 2,
226
+ ) + '\n'
227
+ : formatResult(pack.id, into, statuses, '.ai-kit/skills-manifest.json');
228
+ ctx.stdout(text);
229
+ return { exitCode: 0 };
230
+ } finally {
231
+ if (isTemp && sourceRoot.startsWith(os.tmpdir())) {
232
+ await fs.rm(sourceRoot, { recursive: true, force: true }).catch(() => undefined);
233
+ }
234
+ }
235
+ } catch (err) {
236
+ if (err instanceof CommitError && !err.clean) keepStaging = true;
237
+ const detail = err instanceof Error ? err.message : String(err);
238
+ ctx.stderr(`kit skills: failed to install '${opts.packId}': ${detail}\n`);
239
+ return { exitCode: 1, message: `install failed: ${opts.packId}` };
240
+ } finally {
241
+ if (stagingRoot !== '' && !keepStaging) {
242
+ await fs.rm(stagingRoot, { recursive: true, force: true }).catch(() => undefined);
243
+ }
244
+ }
245
+ }