sdtk-spec-kit 0.4.11 → 0.4.14

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 (143) hide show
  1. package/README.md +353 -353
  2. package/assets/atlas/build_atlas.py +880 -880
  3. package/assets/atlas/doc_atlas_viewer_template.html +3796 -3796
  4. package/assets/atlas/vendor/mermaid.min.js +2029 -2029
  5. package/assets/keys/spec-entitlement-public.pem +9 -9
  6. package/assets/manifest/toolkit-bundle.manifest.json +496 -496
  7. package/assets/manifest/toolkit-bundle.sha256.txt +97 -97
  8. package/assets/toolkit/toolkit/AGENTS.md +157 -241
  9. package/assets/toolkit/toolkit/README.md +51 -51
  10. package/assets/toolkit/toolkit/SDTK_TOOLKIT.md +206 -206
  11. package/assets/toolkit/toolkit/install.ps1 +362 -362
  12. package/assets/toolkit/toolkit/runtimes/claude/CLAUDE_TEMPLATE.md +95 -91
  13. package/assets/toolkit/toolkit/runtimes/codex/CODEX_TEMPLATE.md +70 -69
  14. package/assets/toolkit/toolkit/scripts/agents/run-claude-task.ps1 +332 -332
  15. package/assets/toolkit/toolkit/scripts/agents/run-codex-task.ps1 +618 -618
  16. package/assets/toolkit/toolkit/scripts/agents/validate-mailbox-formal-artifact.py +87 -87
  17. package/assets/toolkit/toolkit/scripts/generate-code-handoff.ps1 +317 -317
  18. package/assets/toolkit/toolkit/scripts/init-feature.ps1 +262 -262
  19. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +180 -180
  20. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +209 -209
  21. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +139 -139
  22. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +143 -143
  23. package/assets/toolkit/toolkit/sdtk-spec.config.json +28 -28
  24. package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +50 -50
  25. package/assets/toolkit/toolkit/session/SDTK_ACTIVE_BOOTSTRAP.md +46 -46
  26. package/assets/toolkit/toolkit/session/SDTK_AGENT_WORKING_RULES.md +48 -48
  27. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/SKILL.md +111 -111
  28. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/scripts/generate_api_design_detail.py +732 -732
  29. package/assets/toolkit/toolkit/skills/sdtk-api-doc/SKILL.md +79 -79
  30. package/assets/toolkit/toolkit/skills/sdtk-arch/SKILL.md +85 -85
  31. package/assets/toolkit/toolkit/skills/sdtk-ba/SKILL.md +46 -46
  32. package/assets/toolkit/toolkit/skills/sdtk-design-layout/SKILL.md +91 -91
  33. package/assets/toolkit/toolkit/skills/sdtk-design-layout/scripts/render_design_layout_images.py +246 -246
  34. package/assets/toolkit/toolkit/skills/sdtk-dev/SKILL.md +133 -133
  35. package/assets/toolkit/toolkit/skills/sdtk-dev/prompts/code-quality-reviewer.md +34 -34
  36. package/assets/toolkit/toolkit/skills/sdtk-dev/prompts/implementer.md +60 -60
  37. package/assets/toolkit/toolkit/skills/sdtk-dev/prompts/spec-reviewer.md +41 -41
  38. package/assets/toolkit/toolkit/skills/sdtk-dev-backend/SKILL.md +80 -80
  39. package/assets/toolkit/toolkit/skills/sdtk-dev-frontend/SKILL.md +80 -80
  40. package/assets/toolkit/toolkit/skills/sdtk-mailbox-dispatch/SKILL.md +73 -73
  41. package/assets/toolkit/toolkit/skills/sdtk-orchestrator/SKILL.md +176 -108
  42. package/assets/toolkit/toolkit/skills/sdtk-pm/SKILL.md +74 -74
  43. package/assets/toolkit/toolkit/skills/sdtk-qa/SKILL.md +75 -75
  44. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/SKILL.md +108 -107
  45. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/references/excel-image-export.md +51 -51
  46. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/references/figma-mcp.md +54 -54
  47. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/references/numbering-rules.md +28 -28
  48. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/scripts/renumber_flow_action_spec_global.py +136 -136
  49. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/scripts/validate_flow_action_spec_numbering.py +414 -414
  50. package/assets/toolkit/toolkit/skills/sdtk-test-case-spec/SKILL.md +110 -110
  51. package/assets/toolkit/toolkit/skills/sdtk-test-case-spec/scripts/validate_test_case_spec.py +97 -97
  52. package/assets/toolkit/toolkit/skills/skills.catalog.yaml +330 -330
  53. package/assets/toolkit/toolkit/skills-claude/api-design-spec/SKILL.md +116 -116
  54. package/assets/toolkit/toolkit/skills-claude/api-doc/SKILL.md +87 -87
  55. package/assets/toolkit/toolkit/skills-claude/arch/SKILL.md +59 -59
  56. package/assets/toolkit/toolkit/skills-claude/ba/SKILL.md +67 -67
  57. package/assets/toolkit/toolkit/skills-claude/design-layout/SKILL.md +91 -91
  58. package/assets/toolkit/toolkit/skills-claude/dev/SKILL.md +59 -59
  59. package/assets/toolkit/toolkit/skills-claude/dev-backend/SKILL.md +73 -73
  60. package/assets/toolkit/toolkit/skills-claude/dev-frontend/SKILL.md +73 -73
  61. package/assets/toolkit/toolkit/skills-claude/mailbox-dispatch/SKILL.md +73 -73
  62. package/assets/toolkit/toolkit/skills-claude/orchestrator/SKILL.md +88 -42
  63. package/assets/toolkit/toolkit/skills-claude/pm/SKILL.md +88 -88
  64. package/assets/toolkit/toolkit/skills-claude/qa/SKILL.md +58 -58
  65. package/assets/toolkit/toolkit/skills-claude/screen-design-spec/SKILL.md +113 -112
  66. package/assets/toolkit/toolkit/skills-claude/test-case-spec/SKILL.md +115 -115
  67. package/assets/toolkit/toolkit/templates/QUALITY_CHECKLIST.md +124 -124
  68. package/assets/toolkit/toolkit/templates/README.md +68 -68
  69. package/assets/toolkit/toolkit/templates/SHARED_PLANNING.md +81 -81
  70. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_CREATION_RULES.md +21 -21
  71. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_DETAIL_TEMPLATE.md +67 -67
  72. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_FLOWCHART_CREATION_RULES.md +468 -468
  73. package/assets/toolkit/toolkit/templates/docs/api/API_ENDPOINTS_TEMPLATE.md +229 -229
  74. package/assets/toolkit/toolkit/templates/docs/api/FEATURE_API_TEMPLATE.yaml +20 -20
  75. package/assets/toolkit/toolkit/templates/docs/api/FLOWCHART_CREATION_RULES.md +20 -20
  76. package/assets/toolkit/toolkit/templates/docs/api/YAML_CREATION_RULES.md +128 -128
  77. package/assets/toolkit/toolkit/templates/docs/api/feature_api_flow_list_TEMPLATE.txt +12 -12
  78. package/assets/toolkit/toolkit/templates/docs/architecture/ARCH_DESIGN_TEMPLATE.md +109 -109
  79. package/assets/toolkit/toolkit/templates/docs/database/DATABASE_SPEC_TEMPLATE.md +175 -175
  80. package/assets/toolkit/toolkit/templates/docs/design/DESIGN_LAYOUT_TEMPLATE.md +60 -60
  81. package/assets/toolkit/toolkit/templates/docs/dev/FEATURE_IMPL_PLAN_TEMPLATE.md +117 -117
  82. package/assets/toolkit/toolkit/templates/docs/dev/OPS_HANDOFF_CREATION_RULES.md +369 -369
  83. package/assets/toolkit/toolkit/templates/docs/discovery/REQUIREMENT_TEMPLATE.md +155 -155
  84. package/assets/toolkit/toolkit/templates/docs/product/BACKLOG_TEMPLATE.md +50 -50
  85. package/assets/toolkit/toolkit/templates/docs/product/CONDENSED_UPSTREAM_INPUT_TEMPLATE.md +276 -276
  86. package/assets/toolkit/toolkit/templates/docs/product/PRD_TEMPLATE.md +66 -66
  87. package/assets/toolkit/toolkit/templates/docs/product/PROJECT_INITIATION_TEMPLATE.md +98 -98
  88. package/assets/toolkit/toolkit/templates/docs/qa/CONTROLLER_ACCEPTANCE_TEMPLATE.md +90 -90
  89. package/assets/toolkit/toolkit/templates/docs/qa/QA_RELEASE_REPORT_TEMPLATE.md +162 -162
  90. package/assets/toolkit/toolkit/templates/docs/qa/TEST_CASE_CREATION_RULES.md +129 -129
  91. package/assets/toolkit/toolkit/templates/docs/qa/TEST_CASE_TEMPLATE.md +104 -104
  92. package/assets/toolkit/toolkit/templates/docs/specs/BA_SPEC_TEMPLATE.md +139 -139
  93. package/assets/toolkit/toolkit/templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md +220 -220
  94. package/assets/toolkit/toolkit/templates/docs/specs/FLOW_ACTION_SPEC_TEMPLATE.md +197 -197
  95. package/assets/toolkit/toolkit/templates/handoffs/ARCH_TO_DEV.md +31 -31
  96. package/assets/toolkit/toolkit/templates/handoffs/BA_TO_ARCH.md +28 -28
  97. package/assets/toolkit/toolkit/templates/handoffs/DEV_STAGE1_SPEC_REVIEW.md +26 -26
  98. package/assets/toolkit/toolkit/templates/handoffs/DEV_STAGE2_CODE_QUALITY_REVIEW.md +20 -20
  99. package/assets/toolkit/toolkit/templates/handoffs/DEV_TO_QA.md +33 -33
  100. package/assets/toolkit/toolkit/templates/handoffs/DEV_TO_SDTK_CODE.md +60 -60
  101. package/assets/toolkit/toolkit/templates/handoffs/PM_TO_BA.md +30 -30
  102. package/assets/toolkit/toolkit/templates/handoffs/QA_RELEASE_DECISION.md +26 -26
  103. package/assets/toolkit/toolkit/templates/mailbox/AGENT_REPORT_TEMPLATE.md +63 -63
  104. package/assets/toolkit/toolkit/templates/mailbox/AGENT_TASK_TEMPLATE.md +76 -76
  105. package/bin/sdtk.js +15 -15
  106. package/package.json +48 -48
  107. package/src/commands/activate.js +94 -94
  108. package/src/commands/atlas.js +339 -339
  109. package/src/commands/auth.js +85 -85
  110. package/src/commands/entitlement.js +170 -170
  111. package/src/commands/generate.js +191 -170
  112. package/src/commands/help.js +248 -246
  113. package/src/commands/init.js +117 -117
  114. package/src/commands/project.js +51 -51
  115. package/src/commands/runtime.js +239 -239
  116. package/src/commands/update.js +11 -11
  117. package/src/index.js +68 -68
  118. package/src/lib/activation-state.js +68 -68
  119. package/src/lib/args.js +116 -116
  120. package/src/lib/atlas-config.js +200 -200
  121. package/src/lib/atlas-runner.js +435 -435
  122. package/src/lib/browser-open.js +39 -39
  123. package/src/lib/capabilities.js +89 -89
  124. package/src/lib/entitlements.js +245 -245
  125. package/src/lib/errors.js +41 -41
  126. package/src/lib/github-access.js +143 -143
  127. package/src/lib/legacy-auth-migration.js +56 -56
  128. package/src/lib/license-activation.js +386 -386
  129. package/src/lib/powershell.js +85 -85
  130. package/src/lib/premium-loader.js +124 -124
  131. package/src/lib/premium-packs.js +333 -333
  132. package/src/lib/premium-sync.js +235 -235
  133. package/src/lib/project-audit.js +332 -332
  134. package/src/lib/project-config.js +108 -108
  135. package/src/lib/project-ingest.js +450 -450
  136. package/src/lib/project-refresh.js +666 -666
  137. package/src/lib/project-target-guard.js +79 -79
  138. package/src/lib/requirement-analysis.js +14 -4
  139. package/src/lib/scope.js +83 -83
  140. package/src/lib/state.js +74 -74
  141. package/src/lib/suite-state.js +70 -70
  142. package/src/lib/toolkit-payload.js +99 -99
  143. package/src/lib/update.js +333 -333
@@ -1,450 +1,450 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { parseFlags } = require("./args");
6
- const { resolveProjectConfig, writeProjectConfig } = require("./project-config");
7
- const { assertProjectRefreshTargetAllowed } = require("./project-target-guard");
8
- const { loadPremiumHandler } = require("./premium-loader");
9
-
10
- const CAPABILITY = "spec.project.ingest";
11
- const SCHEMA_VERSION = "bk083-r1";
12
- const ISSUE_ID = "BK-083";
13
-
14
- const DOC_SYNTHESIS_SCHEMA_VERSION = 1;
15
- const DOC_SYNTHESIS_ISSUE_ID = "BK-084";
16
-
17
- const REQUIRED_STAGED_DOCS = [
18
- "docs/product/PROJECT_BASELINE_SUMMARY.md",
19
- "docs/architecture/ARCH_DESIGN_PROJECT_BASELINE.md",
20
- "docs/database/DATABASE_SPEC_PROJECT_BASELINE.md",
21
- "docs/api/PROJECT_API_SURFACE_BASELINE.md",
22
- "docs/dev/PROJECT_RUNTIME_BASELINE.md",
23
- ];
24
-
25
- const OPTIONAL_STAGED_DOCS = [
26
- "docs/design/PROJECT_UI_INVENTORY_BASELINE.md",
27
- "docs/qa/PROJECT_TESTING_BASELINE.md",
28
- ];
29
-
30
- // BK-088: Required system-level documentation pack.
31
- // These four docs must be present in every successful ingest result.
32
- const REQUIRED_SYSTEM_DOCS = [
33
- "docs/system/SYSTEM_CONTEXT.md",
34
- "docs/system/MODULE_MAP.md",
35
- "docs/system/INTEGRATION_CATALOG.md",
36
- "docs/system/DEPLOYMENT_TOPOLOGY.md",
37
- ];
38
-
39
- const VALID_CONFIDENCE_VALUES = new Set(["low", "medium", "high"]);
40
-
41
- const INGEST_FLAG_DEFS = {
42
- "project-path": { type: "string" },
43
- "output-dir": { type: "string" },
44
- json: { type: "boolean" },
45
- };
46
-
47
- /**
48
- * Return true when relPath is a safe relative path that stays inside baseDir.
49
- *
50
- * Rejects absolute paths, paths containing ".." segments, and paths that
51
- * resolve outside baseDir after normalization.
52
- *
53
- * @param {string} relPath
54
- * @param {string} baseDir - absolute path used as the containment root
55
- * @returns {boolean}
56
- */
57
- function isSafeRelativeStagedPath(relPath, baseDir) {
58
- if (!relPath || typeof relPath !== "string") return false;
59
- if (path.isAbsolute(relPath)) return false;
60
- // Reject any ".." segment in the raw path string (covers backslash variants too)
61
- const parts = relPath.replace(/\\/g, "/").split("/");
62
- for (const part of parts) {
63
- if (part === "..") return false;
64
- }
65
- // Confirm the resolved path is contained inside baseDir
66
- const normalizedBase = path.resolve(baseDir);
67
- const resolved = path.resolve(baseDir, relPath);
68
- return (
69
- resolved === normalizedBase ||
70
- resolved.startsWith(normalizedBase + path.sep)
71
- );
72
- }
73
-
74
- /**
75
- * Validate a single staged doc entry.
76
- *
77
- * @param {string} relPath
78
- * @param {*} entry
79
- * @param {string} docBaselineDir - absolute path used for path-safety check
80
- * @returns {{ valid: true } | { valid: false, reason: string }}
81
- */
82
- function validateDocBaselineEntry(relPath, entry, docBaselineDir) {
83
- if (!isSafeRelativeStagedPath(relPath, docBaselineDir)) {
84
- return {
85
- valid: false,
86
- reason: `staged doc path is invalid or unsafe: "${relPath}"`,
87
- };
88
- }
89
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
90
- return {
91
- valid: false,
92
- reason: `docBaseline.files["${relPath}"] must be a plain object`,
93
- };
94
- }
95
- if (typeof entry.content !== "string" || entry.content.trim() === "") {
96
- return {
97
- valid: false,
98
- reason: `docBaseline.files["${relPath}"].content must be a non-empty string`,
99
- };
100
- }
101
- if (!Array.isArray(entry.sourcePacks) || entry.sourcePacks.length === 0) {
102
- return {
103
- valid: false,
104
- reason: `docBaseline.files["${relPath}"].sourcePacks must be a non-empty array`,
105
- };
106
- }
107
- if (!VALID_CONFIDENCE_VALUES.has(entry.confidence)) {
108
- return {
109
- valid: false,
110
- reason: `docBaseline.files["${relPath}"].confidence must be low, medium, or high`,
111
- };
112
- }
113
- if (entry.reviewRequired !== true) {
114
- return {
115
- valid: false,
116
- reason: `docBaseline.files["${relPath}"].reviewRequired must be true`,
117
- };
118
- }
119
- if (!Array.isArray(entry.nonClaims)) {
120
- return {
121
- valid: false,
122
- reason: `docBaseline.files["${relPath}"].nonClaims must be an array`,
123
- };
124
- }
125
- return { valid: true };
126
- }
127
-
128
- /**
129
- * Validate the docBaseline block returned by the premium handler.
130
- *
131
- * @param {*} docBaseline
132
- * @param {string} docBaselineDir - absolute path used for per-entry path-safety checks
133
- * @returns {{ valid: true } | { valid: false, reason: string }}
134
- */
135
- function validateDocBaseline(docBaseline, docBaselineDir) {
136
- if (!docBaseline || typeof docBaseline !== "object" || Array.isArray(docBaseline)) {
137
- return { valid: false, reason: "docBaseline must be a plain object" };
138
- }
139
- if (
140
- !docBaseline.files ||
141
- typeof docBaseline.files !== "object" ||
142
- Array.isArray(docBaseline.files)
143
- ) {
144
- return { valid: false, reason: "docBaseline.files must be a plain object" };
145
- }
146
- if (
147
- !docBaseline.summary ||
148
- typeof docBaseline.summary !== "object" ||
149
- Array.isArray(docBaseline.summary)
150
- ) {
151
- return { valid: false, reason: "docBaseline.summary must be a plain object" };
152
- }
153
- // Validate each file entry
154
- for (const [relPath, entry] of Object.entries(docBaseline.files)) {
155
- const entryResult = validateDocBaselineEntry(relPath, entry, docBaselineDir);
156
- if (!entryResult.valid) return entryResult;
157
- }
158
- // All required staged docs must be present
159
- for (const requiredDoc of REQUIRED_STAGED_DOCS) {
160
- if (!(requiredDoc in docBaseline.files)) {
161
- return {
162
- valid: false,
163
- reason: `missing required staged doc: ${requiredDoc}`,
164
- };
165
- }
166
- }
167
- // All required system-level docs must be present (BK-088)
168
- for (const requiredDoc of REQUIRED_SYSTEM_DOCS) {
169
- if (!(requiredDoc in docBaseline.files)) {
170
- return {
171
- valid: false,
172
- reason: `missing required staged system doc: ${requiredDoc}`,
173
- };
174
- }
175
- }
176
- return { valid: true };
177
- }
178
-
179
- /**
180
- * Validate top-level result shape returned by the premium handler.
181
- *
182
- * Required keys: census, inventory, profile, moduleGraph, runtimeMarkers,
183
- * evidencePacks, docBaseline, summary -- each must be a plain object.
184
- *
185
- * @param {*} result
186
- * @returns {{ valid: true } | { valid: false, reason: string }}
187
- */
188
- function validateHandlerResult(result) {
189
- if (!result || typeof result !== "object" || Array.isArray(result)) {
190
- return { valid: false, reason: "result is not an object" };
191
- }
192
-
193
- const requiredObjects = [
194
- "census",
195
- "inventory",
196
- "profile",
197
- "moduleGraph",
198
- "runtimeMarkers",
199
- "evidencePacks",
200
- "docBaseline",
201
- "summary",
202
- ];
203
-
204
- for (const key of requiredObjects) {
205
- if (!(key in result)) {
206
- return { valid: false, reason: `missing required key: ${key}` };
207
- }
208
- const val = result[key];
209
- if (!val || typeof val !== "object" || Array.isArray(val)) {
210
- return { valid: false, reason: `${key} must be a plain object` };
211
- }
212
- }
213
-
214
- return { valid: true };
215
- }
216
-
217
- /**
218
- * Execute sdtk-spec project ingest premium command.
219
- *
220
- * Flow:
221
- * 1. Parse flags and resolve project config / output paths.
222
- * 2. Reject the SDTK maintainer monorepo root via the existing target guard.
223
- * 3. Load and verify the premium handler via loadPremiumHandler.
224
- * 4. Build the bounded context object (mode: foundation+synthesis).
225
- * 5. Execute the premium handler.
226
- * 6. Validate the returned result shape (top-level keys).
227
- * 7. Validate the docBaseline contract (per-entry safety + required docs).
228
- * 8. Create output dir and write config.json.
229
- * 9. Write canonical JSON foundation outputs (BK-083).
230
- * 10. Materialize evidence packs under PROJECT_EVIDENCE_PACKS/.
231
- * 11. Write INGEST_STATE.json.
232
- * 12. Materialize staged markdown docs under DOC_SYNTHESIS_BASELINE/docs/...
233
- * 13. Write DOC_SYNTHESIS_STATE.json.
234
- * 14. Print human summary or JSON summary.
235
- *
236
- * @param {string[]} args - Remaining argv after "project ingest"
237
- * @returns {Promise<number>} CLI exit code
238
- */
239
- async function runProjectIngest(args) {
240
- const { flags } = parseFlags(args, INGEST_FLAG_DEFS);
241
-
242
- // 1. Resolve project config and canonical output paths
243
- let config;
244
- try {
245
- config = resolveProjectConfig(flags);
246
- } catch (err) {
247
- console.error(`[project ingest] ${err.message}`);
248
- return 1;
249
- }
250
-
251
- // 2. Reject maintainer repo root as ingest target
252
- try {
253
- assertProjectRefreshTargetAllowed("sdtk-spec", "ingest", config.projectPath);
254
- } catch (err) {
255
- console.error(`[project ingest] ${err.message}`);
256
- return 1;
257
- }
258
-
259
- // 3. Load and verify premium handler (entitlement + pack verification)
260
- const loaderResult = await loadPremiumHandler(CAPABILITY, "projectIngest");
261
- if (!loaderResult.ok) {
262
- console.error(`[project ingest] ${loaderResult.message}`);
263
- return loaderResult.exitCode;
264
- }
265
-
266
- // 4. Build bounded context object
267
- const context = {
268
- capability: CAPABILITY,
269
- mode: "foundation+synthesis",
270
- projectPath: config.projectPath,
271
- outputDir: config.outputDir,
272
- configPath: config.configPath,
273
- statePath: config.statePath,
274
- censusPath: config.censusPath,
275
- inventoryPath: config.inventoryPath,
276
- profilePath: config.profilePath,
277
- moduleGraphPath: config.moduleGraphPath,
278
- runtimeMarkersPath: config.runtimeMarkersPath,
279
- evidencePacksDir: config.evidencePacksDir,
280
- docBaselineDir: config.docBaselineDir,
281
- docBaselineDocsRoot: config.docBaselineDocsRoot,
282
- docSynthesisStatePath: config.docSynthesisStatePath,
283
- json: !!flags.json,
284
- argv: args,
285
- };
286
-
287
- // 5. Execute premium handler
288
- let result;
289
- try {
290
- result = await loaderResult.handler(context);
291
- } catch (err) {
292
- console.error(`[project ingest] Premium pack handler error: ${err.message}`);
293
- return 4;
294
- }
295
-
296
- // 6. Validate returned result shape (top-level keys)
297
- const validation = validateHandlerResult(result);
298
- if (!validation.valid) {
299
- console.error(
300
- `[project ingest] Premium pack output contract is invalid: ${validation.reason}`
301
- );
302
- return 3;
303
- }
304
-
305
- // 7. Validate docBaseline contract (per-entry path safety + required docs)
306
- const docValidation = validateDocBaseline(result.docBaseline, config.docBaselineDir);
307
- if (!docValidation.valid) {
308
- console.error(
309
- `[project ingest] Premium pack output contract is invalid: ${docValidation.reason}`
310
- );
311
- return 3;
312
- }
313
-
314
- // 8. Create output dir and write config.json only after the gated handler succeeds.
315
- writeProjectConfig(config);
316
-
317
- // 9. Write canonical JSON foundation outputs
318
- fs.writeFileSync(config.censusPath, JSON.stringify(result.census, null, 2), "utf8");
319
- fs.writeFileSync(config.inventoryPath, JSON.stringify(result.inventory, null, 2), "utf8");
320
- fs.writeFileSync(config.profilePath, JSON.stringify(result.profile, null, 2), "utf8");
321
- fs.writeFileSync(config.moduleGraphPath, JSON.stringify(result.moduleGraph, null, 2), "utf8");
322
- fs.writeFileSync(config.runtimeMarkersPath, JSON.stringify(result.runtimeMarkers, null, 2), "utf8");
323
-
324
- // 10. Materialize evidence packs under PROJECT_EVIDENCE_PACKS/
325
- if (!fs.existsSync(config.evidencePacksDir)) {
326
- fs.mkdirSync(config.evidencePacksDir, { recursive: true });
327
- }
328
- for (const [packKey, packData] of Object.entries(result.evidencePacks)) {
329
- const packFileName = `${packKey}.pack.json`;
330
- fs.writeFileSync(
331
- path.join(config.evidencePacksDir, packFileName),
332
- JSON.stringify(packData, null, 2),
333
- "utf8"
334
- );
335
- }
336
-
337
- // 11. Write INGEST_STATE.json
338
- const state = {
339
- schemaVersion: SCHEMA_VERSION,
340
- issueId: ISSUE_ID,
341
- projectPath: config.projectPath,
342
- outputDir: config.outputDir,
343
- generatedAt: new Date().toISOString(),
344
- summary: result.summary,
345
- };
346
- fs.writeFileSync(config.statePath, JSON.stringify(state, null, 2), "utf8");
347
-
348
- // 12. Materialize staged markdown docs under DOC_SYNTHESIS_BASELINE/docs/...
349
- for (const [relPath, entry] of Object.entries(result.docBaseline.files)) {
350
- const fullPath = path.join(config.docBaselineDir, relPath);
351
- const dirPath = path.dirname(fullPath);
352
- if (!fs.existsSync(dirPath)) {
353
- fs.mkdirSync(dirPath, { recursive: true });
354
- }
355
- try {
356
- fs.writeFileSync(fullPath, entry.content, "utf8");
357
- } catch (writeErr) {
358
- console.error(
359
- `[project ingest] Doc materialization error for "${relPath}": ${writeErr.message}`
360
- );
361
- return 4;
362
- }
363
- }
364
-
365
- // 13. Write DOC_SYNTHESIS_STATE.json
366
- const allRequiredDocs = [...REQUIRED_STAGED_DOCS, ...REQUIRED_SYSTEM_DOCS];
367
- const requiredDocsWritten = allRequiredDocs.filter(
368
- (d) => d in result.docBaseline.files
369
- );
370
- const optionalDocsGenerated = OPTIONAL_STAGED_DOCS.filter(
371
- (d) => d in result.docBaseline.files
372
- );
373
- const optionalDocsOmitted = OPTIONAL_STAGED_DOCS.filter(
374
- (d) => !(d in result.docBaseline.files)
375
- );
376
- const docSources = {};
377
- for (const [relPath, entry] of Object.entries(result.docBaseline.files)) {
378
- docSources[relPath] = entry.sourcePacks;
379
- }
380
- const docSynthesisState = {
381
- schemaVersion: DOC_SYNTHESIS_SCHEMA_VERSION,
382
- issueId: DOC_SYNTHESIS_ISSUE_ID,
383
- projectPath: config.projectPath,
384
- outputDir: config.outputDir,
385
- docBaselineDir: config.docBaselineDir,
386
- generatedAt: new Date().toISOString(),
387
- requiredDocs: requiredDocsWritten,
388
- optionalDocsGenerated,
389
- optionalDocsOmitted,
390
- docSources,
391
- summary: result.docBaseline.summary,
392
- };
393
- fs.writeFileSync(
394
- config.docSynthesisStatePath,
395
- JSON.stringify(docSynthesisState, null, 2),
396
- "utf8"
397
- );
398
-
399
- // 14. Print summary
400
- if (flags.json) {
401
- const packKeys = Object.keys(result.evidencePacks);
402
- const jsonOut = {
403
- outputDir: config.outputDir,
404
- summary: result.summary,
405
- evidencePacks: packKeys,
406
- docBaseline: {
407
- docBaselineDir: config.docBaselineDir,
408
- generatedFiles: requiredDocsWritten.length + optionalDocsGenerated.length,
409
- requiredDocs: requiredDocsWritten,
410
- optionalDocsGenerated,
411
- optionalDocsOmitted,
412
- },
413
- };
414
- console.log(JSON.stringify(jsonOut));
415
- } else {
416
- const s = result.summary;
417
- console.log("[project ingest] Foundation and staged docs baseline written.");
418
- console.log(` Output dir: ${config.outputDir}`);
419
- if (typeof s.scannedFiles === "number") {
420
- console.log(` Scanned files: ${s.scannedFiles}`);
421
- }
422
- if (typeof s.includedFiles === "number") {
423
- console.log(` Included files: ${s.includedFiles}`);
424
- }
425
- if (Array.isArray(s.primaryLanguages) && s.primaryLanguages.length > 0) {
426
- console.log(` Languages: ${s.primaryLanguages.join(", ")}`);
427
- }
428
- if (Array.isArray(s.markers) && s.markers.length > 0) {
429
- console.log(` Markers: ${s.markers.join(", ")}`);
430
- }
431
- const packKeys = Object.keys(result.evidencePacks);
432
- if (packKeys.length > 0) {
433
- console.log(` Evidence packs: ${packKeys.join(", ")}`);
434
- }
435
- const systemDocsWritten = REQUIRED_SYSTEM_DOCS.filter(
436
- (d) => d in result.docBaseline.files
437
- );
438
- const totalDocs = requiredDocsWritten.length + optionalDocsGenerated.length;
439
- console.log(` Generated docs: ${totalDocs}`);
440
- console.log(` System docs: ${systemDocsWritten.length}`);
441
- console.log(` Staged baseline: ${config.docBaselineDir}`);
442
- if (optionalDocsOmitted.length > 0) {
443
- console.log(` Omitted (optional): ${optionalDocsOmitted.join(", ")}`);
444
- }
445
- }
446
-
447
- return 0;
448
- }
449
-
450
- module.exports = { runProjectIngest };
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { parseFlags } = require("./args");
6
+ const { resolveProjectConfig, writeProjectConfig } = require("./project-config");
7
+ const { assertProjectRefreshTargetAllowed } = require("./project-target-guard");
8
+ const { loadPremiumHandler } = require("./premium-loader");
9
+
10
+ const CAPABILITY = "spec.project.ingest";
11
+ const SCHEMA_VERSION = "bk083-r1";
12
+ const ISSUE_ID = "BK-083";
13
+
14
+ const DOC_SYNTHESIS_SCHEMA_VERSION = 1;
15
+ const DOC_SYNTHESIS_ISSUE_ID = "BK-084";
16
+
17
+ const REQUIRED_STAGED_DOCS = [
18
+ "docs/product/PROJECT_BASELINE_SUMMARY.md",
19
+ "docs/architecture/ARCH_DESIGN_PROJECT_BASELINE.md",
20
+ "docs/database/DATABASE_SPEC_PROJECT_BASELINE.md",
21
+ "docs/api/PROJECT_API_SURFACE_BASELINE.md",
22
+ "docs/dev/PROJECT_RUNTIME_BASELINE.md",
23
+ ];
24
+
25
+ const OPTIONAL_STAGED_DOCS = [
26
+ "docs/design/PROJECT_UI_INVENTORY_BASELINE.md",
27
+ "docs/qa/PROJECT_TESTING_BASELINE.md",
28
+ ];
29
+
30
+ // BK-088: Required system-level documentation pack.
31
+ // These four docs must be present in every successful ingest result.
32
+ const REQUIRED_SYSTEM_DOCS = [
33
+ "docs/system/SYSTEM_CONTEXT.md",
34
+ "docs/system/MODULE_MAP.md",
35
+ "docs/system/INTEGRATION_CATALOG.md",
36
+ "docs/system/DEPLOYMENT_TOPOLOGY.md",
37
+ ];
38
+
39
+ const VALID_CONFIDENCE_VALUES = new Set(["low", "medium", "high"]);
40
+
41
+ const INGEST_FLAG_DEFS = {
42
+ "project-path": { type: "string" },
43
+ "output-dir": { type: "string" },
44
+ json: { type: "boolean" },
45
+ };
46
+
47
+ /**
48
+ * Return true when relPath is a safe relative path that stays inside baseDir.
49
+ *
50
+ * Rejects absolute paths, paths containing ".." segments, and paths that
51
+ * resolve outside baseDir after normalization.
52
+ *
53
+ * @param {string} relPath
54
+ * @param {string} baseDir - absolute path used as the containment root
55
+ * @returns {boolean}
56
+ */
57
+ function isSafeRelativeStagedPath(relPath, baseDir) {
58
+ if (!relPath || typeof relPath !== "string") return false;
59
+ if (path.isAbsolute(relPath)) return false;
60
+ // Reject any ".." segment in the raw path string (covers backslash variants too)
61
+ const parts = relPath.replace(/\\/g, "/").split("/");
62
+ for (const part of parts) {
63
+ if (part === "..") return false;
64
+ }
65
+ // Confirm the resolved path is contained inside baseDir
66
+ const normalizedBase = path.resolve(baseDir);
67
+ const resolved = path.resolve(baseDir, relPath);
68
+ return (
69
+ resolved === normalizedBase ||
70
+ resolved.startsWith(normalizedBase + path.sep)
71
+ );
72
+ }
73
+
74
+ /**
75
+ * Validate a single staged doc entry.
76
+ *
77
+ * @param {string} relPath
78
+ * @param {*} entry
79
+ * @param {string} docBaselineDir - absolute path used for path-safety check
80
+ * @returns {{ valid: true } | { valid: false, reason: string }}
81
+ */
82
+ function validateDocBaselineEntry(relPath, entry, docBaselineDir) {
83
+ if (!isSafeRelativeStagedPath(relPath, docBaselineDir)) {
84
+ return {
85
+ valid: false,
86
+ reason: `staged doc path is invalid or unsafe: "${relPath}"`,
87
+ };
88
+ }
89
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
90
+ return {
91
+ valid: false,
92
+ reason: `docBaseline.files["${relPath}"] must be a plain object`,
93
+ };
94
+ }
95
+ if (typeof entry.content !== "string" || entry.content.trim() === "") {
96
+ return {
97
+ valid: false,
98
+ reason: `docBaseline.files["${relPath}"].content must be a non-empty string`,
99
+ };
100
+ }
101
+ if (!Array.isArray(entry.sourcePacks) || entry.sourcePacks.length === 0) {
102
+ return {
103
+ valid: false,
104
+ reason: `docBaseline.files["${relPath}"].sourcePacks must be a non-empty array`,
105
+ };
106
+ }
107
+ if (!VALID_CONFIDENCE_VALUES.has(entry.confidence)) {
108
+ return {
109
+ valid: false,
110
+ reason: `docBaseline.files["${relPath}"].confidence must be low, medium, or high`,
111
+ };
112
+ }
113
+ if (entry.reviewRequired !== true) {
114
+ return {
115
+ valid: false,
116
+ reason: `docBaseline.files["${relPath}"].reviewRequired must be true`,
117
+ };
118
+ }
119
+ if (!Array.isArray(entry.nonClaims)) {
120
+ return {
121
+ valid: false,
122
+ reason: `docBaseline.files["${relPath}"].nonClaims must be an array`,
123
+ };
124
+ }
125
+ return { valid: true };
126
+ }
127
+
128
+ /**
129
+ * Validate the docBaseline block returned by the premium handler.
130
+ *
131
+ * @param {*} docBaseline
132
+ * @param {string} docBaselineDir - absolute path used for per-entry path-safety checks
133
+ * @returns {{ valid: true } | { valid: false, reason: string }}
134
+ */
135
+ function validateDocBaseline(docBaseline, docBaselineDir) {
136
+ if (!docBaseline || typeof docBaseline !== "object" || Array.isArray(docBaseline)) {
137
+ return { valid: false, reason: "docBaseline must be a plain object" };
138
+ }
139
+ if (
140
+ !docBaseline.files ||
141
+ typeof docBaseline.files !== "object" ||
142
+ Array.isArray(docBaseline.files)
143
+ ) {
144
+ return { valid: false, reason: "docBaseline.files must be a plain object" };
145
+ }
146
+ if (
147
+ !docBaseline.summary ||
148
+ typeof docBaseline.summary !== "object" ||
149
+ Array.isArray(docBaseline.summary)
150
+ ) {
151
+ return { valid: false, reason: "docBaseline.summary must be a plain object" };
152
+ }
153
+ // Validate each file entry
154
+ for (const [relPath, entry] of Object.entries(docBaseline.files)) {
155
+ const entryResult = validateDocBaselineEntry(relPath, entry, docBaselineDir);
156
+ if (!entryResult.valid) return entryResult;
157
+ }
158
+ // All required staged docs must be present
159
+ for (const requiredDoc of REQUIRED_STAGED_DOCS) {
160
+ if (!(requiredDoc in docBaseline.files)) {
161
+ return {
162
+ valid: false,
163
+ reason: `missing required staged doc: ${requiredDoc}`,
164
+ };
165
+ }
166
+ }
167
+ // All required system-level docs must be present (BK-088)
168
+ for (const requiredDoc of REQUIRED_SYSTEM_DOCS) {
169
+ if (!(requiredDoc in docBaseline.files)) {
170
+ return {
171
+ valid: false,
172
+ reason: `missing required staged system doc: ${requiredDoc}`,
173
+ };
174
+ }
175
+ }
176
+ return { valid: true };
177
+ }
178
+
179
+ /**
180
+ * Validate top-level result shape returned by the premium handler.
181
+ *
182
+ * Required keys: census, inventory, profile, moduleGraph, runtimeMarkers,
183
+ * evidencePacks, docBaseline, summary -- each must be a plain object.
184
+ *
185
+ * @param {*} result
186
+ * @returns {{ valid: true } | { valid: false, reason: string }}
187
+ */
188
+ function validateHandlerResult(result) {
189
+ if (!result || typeof result !== "object" || Array.isArray(result)) {
190
+ return { valid: false, reason: "result is not an object" };
191
+ }
192
+
193
+ const requiredObjects = [
194
+ "census",
195
+ "inventory",
196
+ "profile",
197
+ "moduleGraph",
198
+ "runtimeMarkers",
199
+ "evidencePacks",
200
+ "docBaseline",
201
+ "summary",
202
+ ];
203
+
204
+ for (const key of requiredObjects) {
205
+ if (!(key in result)) {
206
+ return { valid: false, reason: `missing required key: ${key}` };
207
+ }
208
+ const val = result[key];
209
+ if (!val || typeof val !== "object" || Array.isArray(val)) {
210
+ return { valid: false, reason: `${key} must be a plain object` };
211
+ }
212
+ }
213
+
214
+ return { valid: true };
215
+ }
216
+
217
+ /**
218
+ * Execute sdtk-spec project ingest premium command.
219
+ *
220
+ * Flow:
221
+ * 1. Parse flags and resolve project config / output paths.
222
+ * 2. Reject the SDTK maintainer monorepo root via the existing target guard.
223
+ * 3. Load and verify the premium handler via loadPremiumHandler.
224
+ * 4. Build the bounded context object (mode: foundation+synthesis).
225
+ * 5. Execute the premium handler.
226
+ * 6. Validate the returned result shape (top-level keys).
227
+ * 7. Validate the docBaseline contract (per-entry safety + required docs).
228
+ * 8. Create output dir and write config.json.
229
+ * 9. Write canonical JSON foundation outputs (BK-083).
230
+ * 10. Materialize evidence packs under PROJECT_EVIDENCE_PACKS/.
231
+ * 11. Write INGEST_STATE.json.
232
+ * 12. Materialize staged markdown docs under DOC_SYNTHESIS_BASELINE/docs/...
233
+ * 13. Write DOC_SYNTHESIS_STATE.json.
234
+ * 14. Print human summary or JSON summary.
235
+ *
236
+ * @param {string[]} args - Remaining argv after "project ingest"
237
+ * @returns {Promise<number>} CLI exit code
238
+ */
239
+ async function runProjectIngest(args) {
240
+ const { flags } = parseFlags(args, INGEST_FLAG_DEFS);
241
+
242
+ // 1. Resolve project config and canonical output paths
243
+ let config;
244
+ try {
245
+ config = resolveProjectConfig(flags);
246
+ } catch (err) {
247
+ console.error(`[project ingest] ${err.message}`);
248
+ return 1;
249
+ }
250
+
251
+ // 2. Reject maintainer repo root as ingest target
252
+ try {
253
+ assertProjectRefreshTargetAllowed("sdtk-spec", "ingest", config.projectPath);
254
+ } catch (err) {
255
+ console.error(`[project ingest] ${err.message}`);
256
+ return 1;
257
+ }
258
+
259
+ // 3. Load and verify premium handler (entitlement + pack verification)
260
+ const loaderResult = await loadPremiumHandler(CAPABILITY, "projectIngest");
261
+ if (!loaderResult.ok) {
262
+ console.error(`[project ingest] ${loaderResult.message}`);
263
+ return loaderResult.exitCode;
264
+ }
265
+
266
+ // 4. Build bounded context object
267
+ const context = {
268
+ capability: CAPABILITY,
269
+ mode: "foundation+synthesis",
270
+ projectPath: config.projectPath,
271
+ outputDir: config.outputDir,
272
+ configPath: config.configPath,
273
+ statePath: config.statePath,
274
+ censusPath: config.censusPath,
275
+ inventoryPath: config.inventoryPath,
276
+ profilePath: config.profilePath,
277
+ moduleGraphPath: config.moduleGraphPath,
278
+ runtimeMarkersPath: config.runtimeMarkersPath,
279
+ evidencePacksDir: config.evidencePacksDir,
280
+ docBaselineDir: config.docBaselineDir,
281
+ docBaselineDocsRoot: config.docBaselineDocsRoot,
282
+ docSynthesisStatePath: config.docSynthesisStatePath,
283
+ json: !!flags.json,
284
+ argv: args,
285
+ };
286
+
287
+ // 5. Execute premium handler
288
+ let result;
289
+ try {
290
+ result = await loaderResult.handler(context);
291
+ } catch (err) {
292
+ console.error(`[project ingest] Premium pack handler error: ${err.message}`);
293
+ return 4;
294
+ }
295
+
296
+ // 6. Validate returned result shape (top-level keys)
297
+ const validation = validateHandlerResult(result);
298
+ if (!validation.valid) {
299
+ console.error(
300
+ `[project ingest] Premium pack output contract is invalid: ${validation.reason}`
301
+ );
302
+ return 3;
303
+ }
304
+
305
+ // 7. Validate docBaseline contract (per-entry path safety + required docs)
306
+ const docValidation = validateDocBaseline(result.docBaseline, config.docBaselineDir);
307
+ if (!docValidation.valid) {
308
+ console.error(
309
+ `[project ingest] Premium pack output contract is invalid: ${docValidation.reason}`
310
+ );
311
+ return 3;
312
+ }
313
+
314
+ // 8. Create output dir and write config.json only after the gated handler succeeds.
315
+ writeProjectConfig(config);
316
+
317
+ // 9. Write canonical JSON foundation outputs
318
+ fs.writeFileSync(config.censusPath, JSON.stringify(result.census, null, 2), "utf8");
319
+ fs.writeFileSync(config.inventoryPath, JSON.stringify(result.inventory, null, 2), "utf8");
320
+ fs.writeFileSync(config.profilePath, JSON.stringify(result.profile, null, 2), "utf8");
321
+ fs.writeFileSync(config.moduleGraphPath, JSON.stringify(result.moduleGraph, null, 2), "utf8");
322
+ fs.writeFileSync(config.runtimeMarkersPath, JSON.stringify(result.runtimeMarkers, null, 2), "utf8");
323
+
324
+ // 10. Materialize evidence packs under PROJECT_EVIDENCE_PACKS/
325
+ if (!fs.existsSync(config.evidencePacksDir)) {
326
+ fs.mkdirSync(config.evidencePacksDir, { recursive: true });
327
+ }
328
+ for (const [packKey, packData] of Object.entries(result.evidencePacks)) {
329
+ const packFileName = `${packKey}.pack.json`;
330
+ fs.writeFileSync(
331
+ path.join(config.evidencePacksDir, packFileName),
332
+ JSON.stringify(packData, null, 2),
333
+ "utf8"
334
+ );
335
+ }
336
+
337
+ // 11. Write INGEST_STATE.json
338
+ const state = {
339
+ schemaVersion: SCHEMA_VERSION,
340
+ issueId: ISSUE_ID,
341
+ projectPath: config.projectPath,
342
+ outputDir: config.outputDir,
343
+ generatedAt: new Date().toISOString(),
344
+ summary: result.summary,
345
+ };
346
+ fs.writeFileSync(config.statePath, JSON.stringify(state, null, 2), "utf8");
347
+
348
+ // 12. Materialize staged markdown docs under DOC_SYNTHESIS_BASELINE/docs/...
349
+ for (const [relPath, entry] of Object.entries(result.docBaseline.files)) {
350
+ const fullPath = path.join(config.docBaselineDir, relPath);
351
+ const dirPath = path.dirname(fullPath);
352
+ if (!fs.existsSync(dirPath)) {
353
+ fs.mkdirSync(dirPath, { recursive: true });
354
+ }
355
+ try {
356
+ fs.writeFileSync(fullPath, entry.content, "utf8");
357
+ } catch (writeErr) {
358
+ console.error(
359
+ `[project ingest] Doc materialization error for "${relPath}": ${writeErr.message}`
360
+ );
361
+ return 4;
362
+ }
363
+ }
364
+
365
+ // 13. Write DOC_SYNTHESIS_STATE.json
366
+ const allRequiredDocs = [...REQUIRED_STAGED_DOCS, ...REQUIRED_SYSTEM_DOCS];
367
+ const requiredDocsWritten = allRequiredDocs.filter(
368
+ (d) => d in result.docBaseline.files
369
+ );
370
+ const optionalDocsGenerated = OPTIONAL_STAGED_DOCS.filter(
371
+ (d) => d in result.docBaseline.files
372
+ );
373
+ const optionalDocsOmitted = OPTIONAL_STAGED_DOCS.filter(
374
+ (d) => !(d in result.docBaseline.files)
375
+ );
376
+ const docSources = {};
377
+ for (const [relPath, entry] of Object.entries(result.docBaseline.files)) {
378
+ docSources[relPath] = entry.sourcePacks;
379
+ }
380
+ const docSynthesisState = {
381
+ schemaVersion: DOC_SYNTHESIS_SCHEMA_VERSION,
382
+ issueId: DOC_SYNTHESIS_ISSUE_ID,
383
+ projectPath: config.projectPath,
384
+ outputDir: config.outputDir,
385
+ docBaselineDir: config.docBaselineDir,
386
+ generatedAt: new Date().toISOString(),
387
+ requiredDocs: requiredDocsWritten,
388
+ optionalDocsGenerated,
389
+ optionalDocsOmitted,
390
+ docSources,
391
+ summary: result.docBaseline.summary,
392
+ };
393
+ fs.writeFileSync(
394
+ config.docSynthesisStatePath,
395
+ JSON.stringify(docSynthesisState, null, 2),
396
+ "utf8"
397
+ );
398
+
399
+ // 14. Print summary
400
+ if (flags.json) {
401
+ const packKeys = Object.keys(result.evidencePacks);
402
+ const jsonOut = {
403
+ outputDir: config.outputDir,
404
+ summary: result.summary,
405
+ evidencePacks: packKeys,
406
+ docBaseline: {
407
+ docBaselineDir: config.docBaselineDir,
408
+ generatedFiles: requiredDocsWritten.length + optionalDocsGenerated.length,
409
+ requiredDocs: requiredDocsWritten,
410
+ optionalDocsGenerated,
411
+ optionalDocsOmitted,
412
+ },
413
+ };
414
+ console.log(JSON.stringify(jsonOut));
415
+ } else {
416
+ const s = result.summary;
417
+ console.log("[project ingest] Foundation and staged docs baseline written.");
418
+ console.log(` Output dir: ${config.outputDir}`);
419
+ if (typeof s.scannedFiles === "number") {
420
+ console.log(` Scanned files: ${s.scannedFiles}`);
421
+ }
422
+ if (typeof s.includedFiles === "number") {
423
+ console.log(` Included files: ${s.includedFiles}`);
424
+ }
425
+ if (Array.isArray(s.primaryLanguages) && s.primaryLanguages.length > 0) {
426
+ console.log(` Languages: ${s.primaryLanguages.join(", ")}`);
427
+ }
428
+ if (Array.isArray(s.markers) && s.markers.length > 0) {
429
+ console.log(` Markers: ${s.markers.join(", ")}`);
430
+ }
431
+ const packKeys = Object.keys(result.evidencePacks);
432
+ if (packKeys.length > 0) {
433
+ console.log(` Evidence packs: ${packKeys.join(", ")}`);
434
+ }
435
+ const systemDocsWritten = REQUIRED_SYSTEM_DOCS.filter(
436
+ (d) => d in result.docBaseline.files
437
+ );
438
+ const totalDocs = requiredDocsWritten.length + optionalDocsGenerated.length;
439
+ console.log(` Generated docs: ${totalDocs}`);
440
+ console.log(` System docs: ${systemDocsWritten.length}`);
441
+ console.log(` Staged baseline: ${config.docBaselineDir}`);
442
+ if (optionalDocsOmitted.length > 0) {
443
+ console.log(` Omitted (optional): ${optionalDocsOmitted.join(", ")}`);
444
+ }
445
+ }
446
+
447
+ return 0;
448
+ }
449
+
450
+ module.exports = { runProjectIngest };