scene-capability-engine 3.0.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 (336) hide show
  1. package/CHANGELOG.md +2513 -0
  2. package/LICENSE +21 -0
  3. package/README.md +765 -0
  4. package/README.zh.md +630 -0
  5. package/bin/kiro-spec-engine.js +796 -0
  6. package/bin/kse.js +3 -0
  7. package/bin/sce.js +3 -0
  8. package/bin/sco.js +3 -0
  9. package/docs/331-poc-adaptation-roadmap.md +156 -0
  10. package/docs/331-poc-dual-track-integration-guide.md +120 -0
  11. package/docs/331-poc-weekly-delivery-checklist.md +52 -0
  12. package/docs/OFFLINE_INSTALL.md +96 -0
  13. package/docs/README.md +279 -0
  14. package/docs/adopt-migration-guide.md +599 -0
  15. package/docs/adoption-guide.md +616 -0
  16. package/docs/agent-hooks-analysis.md +815 -0
  17. package/docs/architecture.md +733 -0
  18. package/docs/articles/ai-driven-development-philosophy-and-practice-review.md +208 -0
  19. package/docs/articles/ai-driven-development-philosophy-and-practice.en.md +459 -0
  20. package/docs/articles/ai-driven-development-philosophy-and-practice.md +492 -0
  21. package/docs/autonomous-control-guide.md +851 -0
  22. package/docs/command-reference.md +1368 -0
  23. package/docs/community.md +115 -0
  24. package/docs/cross-tool-guide.md +555 -0
  25. package/docs/developer-guide.md +619 -0
  26. package/docs/document-governance.md +865 -0
  27. package/docs/environment-management-guide.md +526 -0
  28. package/docs/examples/add-export-command/design.md +194 -0
  29. package/docs/examples/add-export-command/requirements.md +110 -0
  30. package/docs/examples/add-export-command/tasks.md +88 -0
  31. package/docs/examples/add-rest-api/design.md +855 -0
  32. package/docs/examples/add-rest-api/requirements.md +323 -0
  33. package/docs/examples/add-rest-api/tasks.md +355 -0
  34. package/docs/examples/add-user-dashboard/design.md +192 -0
  35. package/docs/examples/add-user-dashboard/requirements.md +143 -0
  36. package/docs/examples/add-user-dashboard/tasks.md +91 -0
  37. package/docs/faq.md +697 -0
  38. package/docs/handoffs/evidence/ontology/moqui-template-baseline-2026-02-17-232922.json +156 -0
  39. package/docs/handoffs/evidence/ontology/moqui-template-baseline-2026-02-17-232922.md +24 -0
  40. package/docs/images/wechat-qr.png +0 -0
  41. package/docs/integration-modes.md +529 -0
  42. package/docs/integration-philosophy.md +313 -0
  43. package/docs/knowledge-management-guide.md +263 -0
  44. package/docs/manual-workflows-guide.md +418 -0
  45. package/docs/moqui-capability-matrix.md +73 -0
  46. package/docs/moqui-template-core-library-playbook.md +109 -0
  47. package/docs/multi-agent-coordination-guide.md +553 -0
  48. package/docs/multi-repo-management-guide.md +1344 -0
  49. package/docs/quick-start-with-ai-tools.md +375 -0
  50. package/docs/quick-start.md +146 -0
  51. package/docs/release-checklist.md +121 -0
  52. package/docs/releases/README.md +13 -0
  53. package/docs/releases/v1.46.2-validation.md +45 -0
  54. package/docs/releases/v1.46.2.md +50 -0
  55. package/docs/scene-runtime-guide.md +347 -0
  56. package/docs/spec-collaboration-guide.md +369 -0
  57. package/docs/spec-locking-guide.md +225 -0
  58. package/docs/spec-numbering-guide.md +348 -0
  59. package/docs/spec-workflow.md +519 -0
  60. package/docs/steering-strategy-guide.md +196 -0
  61. package/docs/team-collaboration-guide.md +465 -0
  62. package/docs/testing-strategy.md +272 -0
  63. package/docs/tools/claude-guide.md +654 -0
  64. package/docs/tools/cursor-guide.md +706 -0
  65. package/docs/tools/generic-guide.md +446 -0
  66. package/docs/tools/kiro-guide.md +308 -0
  67. package/docs/tools/vscode-guide.md +445 -0
  68. package/docs/tools/windsurf-guide.md +391 -0
  69. package/docs/troubleshooting.md +1135 -0
  70. package/docs/upgrade-guide.md +639 -0
  71. package/docs/value-observability-guide.md +127 -0
  72. package/docs/zh/README.md +341 -0
  73. package/docs/zh/quick-start.md +764 -0
  74. package/docs/zh/release-checklist.md +121 -0
  75. package/docs/zh/releases/README.md +13 -0
  76. package/docs/zh/releases/v1.46.2-validation.md +45 -0
  77. package/docs/zh/releases/v1.46.2.md +50 -0
  78. package/docs/zh/spec-numbering-guide.md +348 -0
  79. package/docs/zh/tools/claude-guide.md +349 -0
  80. package/docs/zh/tools/cursor-guide.md +281 -0
  81. package/docs/zh/tools/generic-guide.md +499 -0
  82. package/docs/zh/tools/kiro-guide.md +342 -0
  83. package/docs/zh/tools/vscode-guide.md +449 -0
  84. package/docs/zh/tools/windsurf-guide.md +378 -0
  85. package/docs/zh/value-observability-guide.md +127 -0
  86. package/docs//344/272/244/344/273/230/346/270/205/345/215/225.md +75 -0
  87. package/lib/adoption/adoption-logger.js +487 -0
  88. package/lib/adoption/adoption-strategy.js +538 -0
  89. package/lib/adoption/backup-manager.js +420 -0
  90. package/lib/adoption/conflict-resolver.js +410 -0
  91. package/lib/adoption/detection-engine.js +275 -0
  92. package/lib/adoption/diff-viewer.js +226 -0
  93. package/lib/adoption/error-formatter.js +509 -0
  94. package/lib/adoption/file-classifier.js +385 -0
  95. package/lib/adoption/progress-reporter.js +534 -0
  96. package/lib/adoption/smart-orchestrator.js +470 -0
  97. package/lib/adoption/strategy-selector.js +218 -0
  98. package/lib/adoption/summary-generator.js +493 -0
  99. package/lib/adoption/template-sync.js +605 -0
  100. package/lib/auto/autonomous-engine.js +485 -0
  101. package/lib/auto/checkpoint-manager.js +300 -0
  102. package/lib/auto/close-loop-runner.js +2476 -0
  103. package/lib/auto/config-schema.js +176 -0
  104. package/lib/auto/decision-engine.js +344 -0
  105. package/lib/auto/error-recovery-manager.js +580 -0
  106. package/lib/auto/goal-decomposer.js +278 -0
  107. package/lib/auto/progress-tracker.js +502 -0
  108. package/lib/auto/safety-manager.js +186 -0
  109. package/lib/auto/semantic-decomposer.js +137 -0
  110. package/lib/auto/state-manager.js +126 -0
  111. package/lib/auto/task-queue-manager.js +340 -0
  112. package/lib/backup/backup-system.js +372 -0
  113. package/lib/backup/selective-backup.js +207 -0
  114. package/lib/collab/agent-registry.js +240 -0
  115. package/lib/collab/collab-manager.js +285 -0
  116. package/lib/collab/contract-manager.js +320 -0
  117. package/lib/collab/coordinator.js +370 -0
  118. package/lib/collab/dependency-manager.js +280 -0
  119. package/lib/collab/index.js +20 -0
  120. package/lib/collab/integration-manager.js +202 -0
  121. package/lib/collab/merge-coordinator.js +252 -0
  122. package/lib/collab/metadata-manager.js +233 -0
  123. package/lib/collab/multi-agent-config.js +120 -0
  124. package/lib/collab/spec-lifecycle-manager.js +304 -0
  125. package/lib/collab/sync-barrier.js +88 -0
  126. package/lib/collab/visualizer.js +208 -0
  127. package/lib/commands/adopt.js +749 -0
  128. package/lib/commands/auto.js +19559 -0
  129. package/lib/commands/collab.js +275 -0
  130. package/lib/commands/context.js +99 -0
  131. package/lib/commands/docs.js +808 -0
  132. package/lib/commands/doctor.js +273 -0
  133. package/lib/commands/env.js +420 -0
  134. package/lib/commands/knowledge.js +309 -0
  135. package/lib/commands/lock.js +235 -0
  136. package/lib/commands/ops.js +409 -0
  137. package/lib/commands/orchestrate.js +446 -0
  138. package/lib/commands/prompt.js +105 -0
  139. package/lib/commands/repo.js +118 -0
  140. package/lib/commands/rollback.js +219 -0
  141. package/lib/commands/scene.js +15549 -0
  142. package/lib/commands/spec-bootstrap.js +147 -0
  143. package/lib/commands/spec-gate.js +157 -0
  144. package/lib/commands/spec-pipeline.js +205 -0
  145. package/lib/commands/status.js +321 -0
  146. package/lib/commands/task.js +199 -0
  147. package/lib/commands/templates.js +654 -0
  148. package/lib/commands/upgrade.js +231 -0
  149. package/lib/commands/value.js +569 -0
  150. package/lib/commands/watch.js +684 -0
  151. package/lib/commands/workflows.js +240 -0
  152. package/lib/commands/workspace-multi.js +325 -0
  153. package/lib/commands/workspace.js +189 -0
  154. package/lib/context/context-exporter.js +378 -0
  155. package/lib/context/prompt-generator.js +482 -0
  156. package/lib/data/moqui-capability-lexicon.json +45 -0
  157. package/lib/environment/backup-system.js +189 -0
  158. package/lib/environment/environment-manager.js +379 -0
  159. package/lib/environment/environment-registry.js +168 -0
  160. package/lib/gitignore/gitignore-backup.js +229 -0
  161. package/lib/gitignore/gitignore-detector.js +239 -0
  162. package/lib/gitignore/gitignore-integration.js +267 -0
  163. package/lib/gitignore/gitignore-transformer.js +193 -0
  164. package/lib/gitignore/layered-rules-template.js +42 -0
  165. package/lib/governance/archive-tool.js +284 -0
  166. package/lib/governance/cleanup-tool.js +237 -0
  167. package/lib/governance/config-manager.js +186 -0
  168. package/lib/governance/diagnostic-engine.js +271 -0
  169. package/lib/governance/doc-reference-checker.js +200 -0
  170. package/lib/governance/execution-logger.js +243 -0
  171. package/lib/governance/file-scanner.js +285 -0
  172. package/lib/governance/hooks-manager.js +333 -0
  173. package/lib/governance/reporter.js +337 -0
  174. package/lib/governance/validation-engine.js +181 -0
  175. package/lib/i18n.js +79 -0
  176. package/lib/knowledge/entry-manager.js +208 -0
  177. package/lib/knowledge/index-manager.js +261 -0
  178. package/lib/knowledge/knowledge-manager.js +273 -0
  179. package/lib/knowledge/template-manager.js +191 -0
  180. package/lib/lock/index.js +21 -0
  181. package/lib/lock/lock-file.js +192 -0
  182. package/lib/lock/lock-manager.js +321 -0
  183. package/lib/lock/machine-identifier.js +135 -0
  184. package/lib/lock/steering-file-lock.js +207 -0
  185. package/lib/lock/task-lock-manager.js +345 -0
  186. package/lib/operations/audit-logger.js +293 -0
  187. package/lib/operations/feedback-manager.js +1147 -0
  188. package/lib/operations/index.js +23 -0
  189. package/lib/operations/models/index.js +170 -0
  190. package/lib/operations/operations-manager.js +151 -0
  191. package/lib/operations/operations-validator.js +280 -0
  192. package/lib/operations/permission-manager.js +354 -0
  193. package/lib/operations/template-loader.js +143 -0
  194. package/lib/orchestrator/agent-spawner.js +629 -0
  195. package/lib/orchestrator/bootstrap-prompt-builder.js +236 -0
  196. package/lib/orchestrator/index.js +19 -0
  197. package/lib/orchestrator/orchestration-engine.js +1270 -0
  198. package/lib/orchestrator/orchestrator-config.js +173 -0
  199. package/lib/orchestrator/status-monitor.js +591 -0
  200. package/lib/python-checker.js +209 -0
  201. package/lib/repo/config-manager.js +580 -0
  202. package/lib/repo/errors/config-error.js +13 -0
  203. package/lib/repo/errors/git-error.js +15 -0
  204. package/lib/repo/errors/repo-error.js +14 -0
  205. package/lib/repo/git-operations.js +181 -0
  206. package/lib/repo/handlers/.gitkeep +1 -0
  207. package/lib/repo/handlers/exec-handler.js +155 -0
  208. package/lib/repo/handlers/health-handler.js +169 -0
  209. package/lib/repo/handlers/init-handler.js +197 -0
  210. package/lib/repo/handlers/status-handler.js +176 -0
  211. package/lib/repo/output-formatter.js +184 -0
  212. package/lib/repo/path-resolver.js +178 -0
  213. package/lib/repo/repo-manager.js +514 -0
  214. package/lib/scene-runtime/audit-emitter.js +59 -0
  215. package/lib/scene-runtime/binding-plugin-loader.js +351 -0
  216. package/lib/scene-runtime/binding-registry.js +349 -0
  217. package/lib/scene-runtime/eval-bridge.js +44 -0
  218. package/lib/scene-runtime/index.js +19 -0
  219. package/lib/scene-runtime/moqui-adapter.js +620 -0
  220. package/lib/scene-runtime/moqui-client.js +606 -0
  221. package/lib/scene-runtime/moqui-extractor.js +2029 -0
  222. package/lib/scene-runtime/plan-compiler.js +208 -0
  223. package/lib/scene-runtime/policy-gate.js +58 -0
  224. package/lib/scene-runtime/runtime-executor.js +358 -0
  225. package/lib/scene-runtime/scene-loader.js +96 -0
  226. package/lib/scene-runtime/scene-ontology.js +959 -0
  227. package/lib/scene-runtime/scene-template-linter.js +852 -0
  228. package/lib/scene-runtime/templates/scene-template-erp-query-v0.1.yaml +28 -0
  229. package/lib/scene-runtime/templates/scene-template-hybrid-shadow-v0.1.yaml +34 -0
  230. package/lib/spec/bootstrap/context-collector.js +48 -0
  231. package/lib/spec/bootstrap/draft-generator.js +158 -0
  232. package/lib/spec/bootstrap/questionnaire-engine.js +70 -0
  233. package/lib/spec/bootstrap/trace-emitter.js +59 -0
  234. package/lib/spec/multi-spec-orchestrate.js +93 -0
  235. package/lib/spec/pipeline/constants.js +6 -0
  236. package/lib/spec/pipeline/stage-adapters.js +118 -0
  237. package/lib/spec/pipeline/stage-runner.js +146 -0
  238. package/lib/spec/pipeline/state-store.js +119 -0
  239. package/lib/spec-gate/engine/gate-engine.js +165 -0
  240. package/lib/spec-gate/policy/default-policy.js +22 -0
  241. package/lib/spec-gate/policy/policy-loader.js +103 -0
  242. package/lib/spec-gate/result-emitter.js +81 -0
  243. package/lib/spec-gate/rules/default-rules.js +156 -0
  244. package/lib/spec-gate/rules/rule-registry.js +51 -0
  245. package/lib/steering/adoption-config.js +164 -0
  246. package/lib/steering/compliance-auto-fixer.js +204 -0
  247. package/lib/steering/compliance-cache.js +99 -0
  248. package/lib/steering/compliance-error-reporter.js +70 -0
  249. package/lib/steering/context-sync-manager.js +273 -0
  250. package/lib/steering/index.js +92 -0
  251. package/lib/steering/spec-steering.js +230 -0
  252. package/lib/steering/steering-compliance-checker.js +73 -0
  253. package/lib/steering/steering-loader.js +144 -0
  254. package/lib/steering/steering-manager.js +289 -0
  255. package/lib/task/index.js +12 -0
  256. package/lib/task/task-claimer.js +489 -0
  257. package/lib/task/task-status-store.js +418 -0
  258. package/lib/templates/cache-manager.js +440 -0
  259. package/lib/templates/content-generalizer.js +247 -0
  260. package/lib/templates/frontmatter-generator.js +128 -0
  261. package/lib/templates/git-handler.js +471 -0
  262. package/lib/templates/metadata-collector.js +328 -0
  263. package/lib/templates/path-utils.js +144 -0
  264. package/lib/templates/registry-parser.js +505 -0
  265. package/lib/templates/spec-reader.js +216 -0
  266. package/lib/templates/template-applicator.js +249 -0
  267. package/lib/templates/template-creator.js +256 -0
  268. package/lib/templates/template-error.js +143 -0
  269. package/lib/templates/template-exporter.js +502 -0
  270. package/lib/templates/template-manager.js +782 -0
  271. package/lib/templates/template-validator.js +361 -0
  272. package/lib/upgrade/migration-engine.js +382 -0
  273. package/lib/upgrade/migrations/.gitkeep +52 -0
  274. package/lib/upgrade/migrations/1.0.0-to-1.1.0.js +78 -0
  275. package/lib/utils/file-diff.js +177 -0
  276. package/lib/utils/fs-utils.js +274 -0
  277. package/lib/utils/tool-detector.js +383 -0
  278. package/lib/utils/validation.js +324 -0
  279. package/lib/value/gate-summary-emitter.js +99 -0
  280. package/lib/value/metric-contract-loader.js +210 -0
  281. package/lib/value/risk-evaluator.js +117 -0
  282. package/lib/value/weekly-snapshot-builder.js +61 -0
  283. package/lib/version/version-checker.js +156 -0
  284. package/lib/version/version-manager.js +327 -0
  285. package/lib/watch/action-executor.js +458 -0
  286. package/lib/watch/event-debouncer.js +323 -0
  287. package/lib/watch/execution-logger.js +550 -0
  288. package/lib/watch/file-watcher.js +499 -0
  289. package/lib/watch/presets.js +266 -0
  290. package/lib/watch/watch-manager.js +533 -0
  291. package/lib/workspace/multi/global-config.js +150 -0
  292. package/lib/workspace/multi/index.js +22 -0
  293. package/lib/workspace/multi/path-utils.js +173 -0
  294. package/lib/workspace/multi/workspace-context-resolver.js +244 -0
  295. package/lib/workspace/multi/workspace-registry.js +196 -0
  296. package/lib/workspace/multi/workspace-state-manager.js +537 -0
  297. package/lib/workspace/multi/workspace.js +90 -0
  298. package/lib/workspace/workspace-manager.js +370 -0
  299. package/lib/workspace/workspace-sync.js +356 -0
  300. package/locales/en.json +114 -0
  301. package/locales/zh.json +114 -0
  302. package/package.json +102 -0
  303. package/template/.kiro/README.md +247 -0
  304. package/template/.kiro/hooks/check-spec-on-create.kiro.hook +17 -0
  305. package/template/.kiro/hooks/run-tests-on-save.kiro.hook +13 -0
  306. package/template/.kiro/hooks/sync-tasks-on-edit.kiro.hook +16 -0
  307. package/template/.kiro/specs/SPEC_WORKFLOW_GUIDE.md +134 -0
  308. package/template/.kiro/steering/CORE_PRINCIPLES.md +133 -0
  309. package/template/.kiro/steering/CURRENT_CONTEXT.md +30 -0
  310. package/template/.kiro/steering/ENVIRONMENT.md +35 -0
  311. package/template/.kiro/steering/RULES_GUIDE.md +46 -0
  312. package/template/.kiro/templates/operations/default/change-impact.md +112 -0
  313. package/template/.kiro/templates/operations/default/deployment.md +91 -0
  314. package/template/.kiro/templates/operations/default/feedback-response.md +269 -0
  315. package/template/.kiro/templates/operations/default/migration-plan.md +172 -0
  316. package/template/.kiro/templates/operations/default/monitoring.md +135 -0
  317. package/template/.kiro/templates/operations/default/operations.md +135 -0
  318. package/template/.kiro/templates/operations/default/rollback.md +143 -0
  319. package/template/.kiro/templates/operations/default/tools.yaml +364 -0
  320. package/template/.kiro/templates/operations/default/troubleshooting.md +123 -0
  321. package/template/.kiro/tools/backup_manager.py +295 -0
  322. package/template/.kiro/tools/configuration_manager.py +218 -0
  323. package/template/.kiro/tools/document_evaluator.py +550 -0
  324. package/template/.kiro/tools/enhancement_logger.py +168 -0
  325. package/template/.kiro/tools/error_handler.py +335 -0
  326. package/template/.kiro/tools/improvement_identifier.py +444 -0
  327. package/template/.kiro/tools/modification_applicator.py +737 -0
  328. package/template/.kiro/tools/quality_gate_enforcer.py +207 -0
  329. package/template/.kiro/tools/quality_scorer.py +305 -0
  330. package/template/.kiro/tools/report_generator.py +154 -0
  331. package/template/.kiro/tools/ultrawork_enhancer.py +676 -0
  332. package/template/.kiro/tools/ultrawork_enhancer_refactored.py +0 -0
  333. package/template/.kiro/tools/ultrawork_enhancer_v2.py +463 -0
  334. package/template/.kiro/tools/ultrawork_enhancer_v3.py +606 -0
  335. package/template/.kiro/tools/workflow_quality_gate.py +100 -0
  336. package/template/README.md +111 -0
@@ -0,0 +1,808 @@
1
+ /**
2
+ * Document Governance Command Handler
3
+ *
4
+ * Provides CLI interface for document governance operations
5
+ */
6
+
7
+ const chalk = require('chalk');
8
+ const ConfigManager = require('../governance/config-manager');
9
+ const DiagnosticEngine = require('../governance/diagnostic-engine');
10
+ const CleanupTool = require('../governance/cleanup-tool');
11
+ const ValidationEngine = require('../governance/validation-engine');
12
+ const ArchiveTool = require('../governance/archive-tool');
13
+ const HooksManager = require('../governance/hooks-manager');
14
+ const Reporter = require('../governance/reporter');
15
+ const ExecutionLogger = require('../governance/execution-logger');
16
+ const DocReferenceChecker = require('../governance/doc-reference-checker');
17
+
18
+ /**
19
+ * Execute document governance command
20
+ *
21
+ * @param {string} subcommand - The subcommand (cleanup, validate, archive, etc.)
22
+ * @param {Object} options - Command options
23
+ * @returns {Promise<number>} - Exit code (0 for success, non-zero for error)
24
+ */
25
+ async function docsCommand(subcommand, options = {}) {
26
+ const projectPath = process.cwd();
27
+ const reporter = new Reporter();
28
+
29
+ try {
30
+ // Load configuration
31
+ const configManager = new ConfigManager(projectPath);
32
+ const config = await configManager.load();
33
+
34
+ // Route to appropriate handler
35
+ switch (subcommand) {
36
+ case 'diagnose':
37
+ case 'diagnostic':
38
+ return await handleDiagnostic(projectPath, config, reporter);
39
+
40
+ case 'cleanup':
41
+ return await handleCleanup(projectPath, config, reporter, options);
42
+
43
+ case 'validate':
44
+ return await handleValidate(projectPath, config, reporter, options);
45
+
46
+ case 'archive':
47
+ return await handleArchive(projectPath, config, reporter, options);
48
+
49
+ case 'hooks':
50
+ return await handleHooks(projectPath, reporter, options);
51
+
52
+ case 'config':
53
+ return await handleConfig(projectPath, configManager, reporter, options);
54
+
55
+ case 'stats':
56
+ return await handleStats(projectPath, reporter, options);
57
+
58
+ case 'report':
59
+ return await handleReport(projectPath, reporter, options);
60
+
61
+ case 'check-refs':
62
+ case 'check-references':
63
+ return await handleCheckReferences(projectPath, reporter, options);
64
+
65
+ case 'help':
66
+ default:
67
+ showHelp();
68
+ return 0;
69
+ }
70
+ } catch (error) {
71
+ reporter.displayError(error.message);
72
+ if (options.verbose) {
73
+ console.error(error.stack);
74
+ }
75
+ return 2; // Fatal error
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Handle diagnostic command
81
+ */
82
+ async function handleDiagnostic(projectPath, config, reporter) {
83
+ const engine = new DiagnosticEngine(projectPath, config);
84
+ const report = await engine.scan();
85
+
86
+ reporter.displayDiagnostic(report);
87
+
88
+ // Log execution
89
+ const logger = new ExecutionLogger(projectPath);
90
+ await logger.logExecution('diagnostic', 'scan', report);
91
+
92
+ return report.compliant ? 0 : 1;
93
+ }
94
+
95
+ /**
96
+ * Handle cleanup command
97
+ */
98
+ async function handleCleanup(projectPath, config, reporter, options) {
99
+ const tool = new CleanupTool(projectPath, config);
100
+
101
+ const cleanupOptions = {
102
+ dryRun: options.dryRun || options.dry || false,
103
+ interactive: options.interactive || options.i || false,
104
+ spec: options.spec || null
105
+ };
106
+
107
+ const report = await tool.cleanup(cleanupOptions);
108
+
109
+ reporter.displayCleanup(report, cleanupOptions.dryRun);
110
+
111
+ // Log execution (only if not dry run)
112
+ if (!cleanupOptions.dryRun) {
113
+ const logger = new ExecutionLogger(projectPath);
114
+ await logger.logExecution('cleanup', 'delete', report);
115
+ }
116
+
117
+ return report.success ? 0 : 1;
118
+ }
119
+
120
+ /**
121
+ * Handle validate command
122
+ */
123
+ async function handleValidate(projectPath, config, reporter, options) {
124
+ const engine = new ValidationEngine(projectPath, config);
125
+
126
+ const validateOptions = {
127
+ spec: options.spec || null,
128
+ all: options.all || false
129
+ };
130
+
131
+ const report = await engine.validate(validateOptions);
132
+
133
+ reporter.displayValidation(report);
134
+
135
+ // Log execution
136
+ const logger = new ExecutionLogger(projectPath);
137
+ await logger.logExecution('validation', 'validate', report);
138
+
139
+ return report.valid ? 0 : 1;
140
+ }
141
+
142
+ /**
143
+ * Handle archive command
144
+ */
145
+ async function handleArchive(projectPath, config, reporter, options) {
146
+ if (!options.spec) {
147
+ reporter.displayError('--spec option is required for archive command');
148
+ console.log('Usage: kse docs archive --spec <spec-name> [--dry-run]');
149
+ return 2;
150
+ }
151
+
152
+ const tool = new ArchiveTool(projectPath, config);
153
+
154
+ const archiveOptions = {
155
+ dryRun: options.dryRun || options.dry || false
156
+ };
157
+
158
+ const report = await tool.archive(options.spec, archiveOptions);
159
+
160
+ reporter.displayArchive(report, archiveOptions.dryRun);
161
+
162
+ // Log execution (only if not dry run)
163
+ if (!archiveOptions.dryRun) {
164
+ const logger = new ExecutionLogger(projectPath);
165
+ await logger.logExecution('archive', 'move', report);
166
+ }
167
+
168
+ return report.success ? 0 : 1;
169
+ }
170
+
171
+ /**
172
+ * Handle hooks command
173
+ */
174
+ async function handleHooks(projectPath, reporter, options) {
175
+ const manager = new HooksManager(projectPath);
176
+
177
+ // Determine subcommand (install, uninstall, status)
178
+ const hookSubcommand = options._?.[0] || 'status';
179
+
180
+ switch (hookSubcommand) {
181
+ case 'install':
182
+ return await handleHooksInstall(manager, reporter);
183
+
184
+ case 'uninstall':
185
+ return await handleHooksUninstall(manager, reporter);
186
+
187
+ case 'status':
188
+ default:
189
+ return await handleHooksStatus(manager, reporter);
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Handle hooks install
195
+ */
196
+ async function handleHooksInstall(manager, reporter) {
197
+ console.log(chalk.cyan('šŸ”§ Installing document governance hooks...\n'));
198
+
199
+ const result = await manager.installHooks();
200
+
201
+ if (result.success) {
202
+ console.log(chalk.green('āœ… ' + result.message));
203
+
204
+ if (result.backupCreated) {
205
+ console.log(chalk.gray(' Backup created at: .git/hooks/pre-commit.backup'));
206
+ }
207
+
208
+ console.log(chalk.cyan('\nThe pre-commit hook will now validate documents before each commit.'));
209
+ console.log(chalk.gray('To bypass validation, use: git commit --no-verify\n'));
210
+
211
+ return 0;
212
+ } else {
213
+ console.log(chalk.red('āŒ ' + result.message));
214
+
215
+ if (result.reason === 'not_git_repo') {
216
+ console.log(chalk.yellow('\nThis is not a Git repository.'));
217
+ console.log(chalk.gray('Initialize Git first: git init\n'));
218
+ }
219
+
220
+ return 1;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Handle hooks uninstall
226
+ */
227
+ async function handleHooksUninstall(manager, reporter) {
228
+ console.log(chalk.cyan('šŸ”§ Uninstalling document governance hooks...\n'));
229
+
230
+ const result = await manager.uninstallHooks();
231
+
232
+ if (result.success) {
233
+ console.log(chalk.green('āœ… ' + result.message + '\n'));
234
+ return 0;
235
+ } else {
236
+ console.log(chalk.red('āŒ ' + result.message));
237
+
238
+ if (result.reason === 'not_our_hook') {
239
+ console.log(chalk.yellow('\nThe pre-commit hook was not installed by kiro-spec-engine.'));
240
+ console.log(chalk.gray('You may need to manually edit: .git/hooks/pre-commit\n'));
241
+ }
242
+
243
+ return 1;
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Handle hooks status
249
+ */
250
+ async function handleHooksStatus(manager, reporter) {
251
+ console.log(chalk.cyan('šŸ” Checking Git hooks status...\n'));
252
+
253
+ const status = await manager.checkHooksInstalled();
254
+
255
+ if (status.installed) {
256
+ console.log(chalk.green('āœ… Document governance hooks are installed'));
257
+ console.log(chalk.gray(' Pre-commit validation is active\n'));
258
+ return 0;
259
+ } else {
260
+ console.log(chalk.yellow('āš ļø Document governance hooks are not installed'));
261
+ console.log(chalk.gray(' Reason: ' + status.message));
262
+ console.log(chalk.cyan('\nTo install hooks: kse docs hooks install\n'));
263
+ return 1;
264
+ }
265
+ }
266
+
267
+ /**
268
+ * Handle config command
269
+ */
270
+ async function handleConfig(projectPath, configManager, reporter, options) {
271
+ // Check if --set flag is provided
272
+ if (options.set) {
273
+ return await handleConfigSet(configManager, reporter, options);
274
+ }
275
+
276
+ // Check if --reset flag is provided
277
+ if (options.reset) {
278
+ return await handleConfigReset(configManager, reporter);
279
+ }
280
+
281
+ // Default: display current configuration
282
+ return await handleConfigDisplay(configManager, reporter);
283
+ }
284
+
285
+ /**
286
+ * Handle config display
287
+ */
288
+ async function handleConfigDisplay(configManager, reporter) {
289
+ console.log(chalk.bold.cyan('\nāš™ļø Document Governance Configuration\n'));
290
+
291
+ const config = configManager.getAll();
292
+
293
+ console.log(chalk.bold('Root Allowed Files:'));
294
+ config.rootAllowedFiles.forEach(file => {
295
+ console.log(` • ${file}`);
296
+ });
297
+ console.log();
298
+
299
+ console.log(chalk.bold('Spec Subdirectories:'));
300
+ config.specSubdirs.forEach(dir => {
301
+ console.log(` • ${dir}`);
302
+ });
303
+ console.log();
304
+
305
+ console.log(chalk.bold('Temporary Patterns:'));
306
+ config.temporaryPatterns.forEach(pattern => {
307
+ console.log(` • ${pattern}`);
308
+ });
309
+ console.log();
310
+
311
+ console.log(chalk.gray('Configuration file: .kiro/config/docs.json'));
312
+ console.log(chalk.gray('To modify: kse docs config --set <key> <value>'));
313
+ console.log(chalk.gray('To reset: kse docs config --reset\n'));
314
+
315
+ return 0;
316
+ }
317
+
318
+ /**
319
+ * Handle config set
320
+ */
321
+ async function handleConfigSet(configManager, reporter, options) {
322
+ // Parse the key and value from options
323
+ // Expected format: --set key value or --set key "value1,value2"
324
+ const args = options._ || [];
325
+
326
+ // Find the index of the key after 'config'
327
+ const configIndex = args.indexOf('config');
328
+ const keyIndex = configIndex + 1;
329
+
330
+ if (keyIndex >= args.length) {
331
+ reporter.displayError('Missing configuration key');
332
+ console.log(chalk.gray('Usage: kse docs config --set <key> <value>'));
333
+ console.log(chalk.gray('Example: kse docs config --set root-allowed-files "README.md,CUSTOM.md"\n'));
334
+ return 2;
335
+ }
336
+
337
+ const key = args[keyIndex];
338
+ const valueIndex = keyIndex + 1;
339
+
340
+ if (valueIndex >= args.length) {
341
+ reporter.displayError('Missing configuration value');
342
+ console.log(chalk.gray('Usage: kse docs config --set <key> <value>'));
343
+ console.log(chalk.gray('Example: kse docs config --set root-allowed-files "README.md,CUSTOM.md"\n'));
344
+ return 2;
345
+ }
346
+
347
+ const valueStr = args[valueIndex];
348
+
349
+ // Convert kebab-case to camelCase
350
+ const camelKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
351
+
352
+ // Validate key
353
+ const validKeys = ['rootAllowedFiles', 'specSubdirs', 'temporaryPatterns'];
354
+ if (!validKeys.includes(camelKey)) {
355
+ reporter.displayError(`Invalid configuration key: ${key}`);
356
+ console.log(chalk.gray('Valid keys: root-allowed-files, spec-subdirs, temporary-patterns\n'));
357
+ return 2;
358
+ }
359
+
360
+ // Parse value (comma-separated list)
361
+ const value = valueStr.split(',').map(v => v.trim()).filter(v => v.length > 0);
362
+
363
+ if (value.length === 0) {
364
+ reporter.displayError('Value cannot be empty');
365
+ return 2;
366
+ }
367
+
368
+ // Set the value
369
+ try {
370
+ await configManager.set(camelKey, value);
371
+
372
+ console.log(chalk.green(`āœ… Configuration updated: ${key}`));
373
+ console.log(chalk.gray(` New value: ${value.join(', ')}\n`));
374
+
375
+ return 0;
376
+ } catch (error) {
377
+ reporter.displayError(`Failed to update configuration: ${error.message}`);
378
+ return 1;
379
+ }
380
+ }
381
+
382
+ /**
383
+ * Handle config reset
384
+ */
385
+ async function handleConfigReset(configManager, reporter) {
386
+ console.log(chalk.yellow('āš ļø Resetting configuration to defaults...\n'));
387
+
388
+ try {
389
+ await configManager.reset();
390
+
391
+ console.log(chalk.green('āœ… Configuration reset to defaults'));
392
+ console.log(chalk.gray(' Run "kse docs config" to view current configuration\n'));
393
+
394
+ return 0;
395
+ } catch (error) {
396
+ reporter.displayError(`Failed to reset configuration: ${error.message}`);
397
+ return 1;
398
+ }
399
+ }
400
+
401
+ /**
402
+ * Handle stats command
403
+ */
404
+ async function handleStats(projectPath, reporter, options) {
405
+ const logger = new ExecutionLogger(projectPath);
406
+
407
+ // Get execution history
408
+ const history = await logger.getHistory();
409
+
410
+ if (history.length === 0) {
411
+ console.log(chalk.yellow('āš ļø No execution history found'));
412
+ console.log(chalk.gray(' Run document governance commands to generate statistics\n'));
413
+ return 0;
414
+ }
415
+
416
+ // Calculate statistics
417
+ const stats = calculateStatistics(history);
418
+
419
+ // Display statistics
420
+ reporter.displayStats(stats);
421
+
422
+ return 0;
423
+ }
424
+
425
+ /**
426
+ * Handle report command
427
+ */
428
+ async function handleReport(projectPath, reporter, options) {
429
+ const logger = new ExecutionLogger(projectPath);
430
+ const fs = require('fs-extra');
431
+ const path = require('path');
432
+
433
+ // Get execution history
434
+ const history = await logger.getHistory();
435
+
436
+ if (history.length === 0) {
437
+ console.log(chalk.yellow('āš ļø No execution history found'));
438
+ console.log(chalk.gray(' Run document governance commands to generate a report\n'));
439
+ return 0;
440
+ }
441
+
442
+ // Calculate statistics
443
+ const stats = calculateStatistics(history);
444
+
445
+ // Generate markdown report
446
+ const report = generateMarkdownReport(stats, history);
447
+
448
+ // Ensure reports directory exists
449
+ const reportsDir = path.join(projectPath, '.kiro', 'reports');
450
+ await fs.ensureDir(reportsDir);
451
+
452
+ // Generate filename with timestamp
453
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-').split('T')[0];
454
+ const filename = `document-compliance-${timestamp}.md`;
455
+ const reportPath = path.join(reportsDir, filename);
456
+
457
+ // Save report
458
+ await fs.writeFile(reportPath, report, 'utf8');
459
+
460
+ console.log(chalk.green('āœ… Compliance report generated'));
461
+ console.log(chalk.gray(` Saved to: ${reportPath}\n`));
462
+
463
+ return 0;
464
+ }
465
+
466
+ /**
467
+ * Calculate statistics from execution history
468
+ *
469
+ * @param {Array} history - Execution history entries
470
+ * @returns {Object} - Statistics object
471
+ */
472
+ function calculateStatistics(history) {
473
+ const stats = {
474
+ totalExecutions: history.length,
475
+ executionsByTool: {},
476
+ totalViolations: 0,
477
+ violationsByType: {},
478
+ totalCleanupActions: 0,
479
+ totalArchiveActions: 0,
480
+ totalErrors: 0,
481
+ firstExecution: null,
482
+ lastExecution: null,
483
+ violationsOverTime: [],
484
+ cleanupActionsOverTime: []
485
+ };
486
+
487
+ // Process each history entry
488
+ history.forEach(entry => {
489
+ // Track executions by tool
490
+ if (!stats.executionsByTool[entry.tool]) {
491
+ stats.executionsByTool[entry.tool] = 0;
492
+ }
493
+ stats.executionsByTool[entry.tool]++;
494
+
495
+ // Track timestamps
496
+ if (!stats.firstExecution || entry.timestamp < stats.firstExecution) {
497
+ stats.firstExecution = entry.timestamp;
498
+ }
499
+ if (!stats.lastExecution || entry.timestamp > stats.lastExecution) {
500
+ stats.lastExecution = entry.timestamp;
501
+ }
502
+
503
+ // Process diagnostic results
504
+ if (entry.tool === 'diagnostic' && entry.results) {
505
+ if (entry.results.violations) {
506
+ const violationCount = entry.results.violations.length;
507
+ stats.totalViolations += violationCount;
508
+
509
+ // Track violations over time
510
+ stats.violationsOverTime.push({
511
+ timestamp: entry.timestamp,
512
+ count: violationCount
513
+ });
514
+
515
+ // Track violations by type
516
+ entry.results.violations.forEach(violation => {
517
+ if (!stats.violationsByType[violation.type]) {
518
+ stats.violationsByType[violation.type] = 0;
519
+ }
520
+ stats.violationsByType[violation.type]++;
521
+ });
522
+ }
523
+ }
524
+
525
+ // Process cleanup results
526
+ if (entry.tool === 'cleanup' && entry.results) {
527
+ if (entry.results.deletedFiles) {
528
+ const cleanupCount = entry.results.deletedFiles.length;
529
+ stats.totalCleanupActions += cleanupCount;
530
+
531
+ // Track cleanup actions over time
532
+ stats.cleanupActionsOverTime.push({
533
+ timestamp: entry.timestamp,
534
+ count: cleanupCount
535
+ });
536
+ }
537
+
538
+ if (entry.results.errors) {
539
+ stats.totalErrors += entry.results.errors.length;
540
+ }
541
+ }
542
+
543
+ // Process archive results
544
+ if (entry.tool === 'archive' && entry.results) {
545
+ if (entry.results.movedFiles) {
546
+ stats.totalArchiveActions += entry.results.movedFiles.length;
547
+ }
548
+
549
+ if (entry.results.errors) {
550
+ stats.totalErrors += entry.results.errors.length;
551
+ }
552
+ }
553
+
554
+ // Process validation results
555
+ if (entry.tool === 'validation' && entry.results) {
556
+ if (entry.results.errors) {
557
+ stats.totalErrors += entry.results.errors.length;
558
+ }
559
+ }
560
+ });
561
+
562
+ return stats;
563
+ }
564
+
565
+ /**
566
+ * Generate markdown compliance report
567
+ *
568
+ * @param {Object} stats - Statistics object
569
+ * @param {Array} history - Execution history
570
+ * @returns {string} - Markdown report
571
+ */
572
+ function generateMarkdownReport(stats, history) {
573
+ const lines = [];
574
+
575
+ // Header
576
+ lines.push('# Document Compliance Report');
577
+ lines.push('');
578
+ lines.push(`**Generated:** ${new Date().toISOString()}`);
579
+ lines.push('');
580
+
581
+ // Summary
582
+ lines.push('## Summary');
583
+ lines.push('');
584
+ lines.push(`- **Total Executions:** ${stats.totalExecutions}`);
585
+ lines.push(`- **Total Violations Found:** ${stats.totalViolations}`);
586
+ lines.push(`- **Total Cleanup Actions:** ${stats.totalCleanupActions}`);
587
+ lines.push(`- **Total Archive Actions:** ${stats.totalArchiveActions}`);
588
+ lines.push(`- **Total Errors:** ${stats.totalErrors}`);
589
+ lines.push(`- **First Execution:** ${stats.firstExecution || 'N/A'}`);
590
+ lines.push(`- **Last Execution:** ${stats.lastExecution || 'N/A'}`);
591
+ lines.push('');
592
+
593
+ // Executions by Tool
594
+ lines.push('## Executions by Tool');
595
+ lines.push('');
596
+ lines.push('| Tool | Count |');
597
+ lines.push('|------|-------|');
598
+ Object.entries(stats.executionsByTool).forEach(([tool, count]) => {
599
+ lines.push(`| ${tool} | ${count} |`);
600
+ });
601
+ lines.push('');
602
+
603
+ // Violations by Type
604
+ if (Object.keys(stats.violationsByType).length > 0) {
605
+ lines.push('## Violations by Type');
606
+ lines.push('');
607
+ lines.push('| Type | Count |');
608
+ lines.push('|------|-------|');
609
+ Object.entries(stats.violationsByType)
610
+ .sort((a, b) => b[1] - a[1])
611
+ .forEach(([type, count]) => {
612
+ lines.push(`| ${type} | ${count} |`);
613
+ });
614
+ lines.push('');
615
+ }
616
+
617
+ // Violations Over Time
618
+ if (stats.violationsOverTime.length > 0) {
619
+ lines.push('## Violations Over Time');
620
+ lines.push('');
621
+ lines.push('| Timestamp | Count |');
622
+ lines.push('|-----------|-------|');
623
+ stats.violationsOverTime.forEach(entry => {
624
+ lines.push(`| ${entry.timestamp} | ${entry.count} |`);
625
+ });
626
+ lines.push('');
627
+ }
628
+
629
+ // Cleanup Actions Over Time
630
+ if (stats.cleanupActionsOverTime.length > 0) {
631
+ lines.push('## Cleanup Actions Over Time');
632
+ lines.push('');
633
+ lines.push('| Timestamp | Files Deleted |');
634
+ lines.push('|-----------|---------------|');
635
+ stats.cleanupActionsOverTime.forEach(entry => {
636
+ lines.push(`| ${entry.timestamp} | ${entry.count} |`);
637
+ });
638
+ lines.push('');
639
+ }
640
+
641
+ // Recent Executions
642
+ lines.push('## Recent Executions');
643
+ lines.push('');
644
+ const recentHistory = history.slice(-10).reverse();
645
+ recentHistory.forEach(entry => {
646
+ lines.push(`### ${entry.tool} - ${entry.operation}`);
647
+ lines.push('');
648
+ lines.push(`**Timestamp:** ${entry.timestamp}`);
649
+ lines.push('');
650
+
651
+ if (entry.results) {
652
+ if (entry.results.violations) {
653
+ lines.push(`**Violations Found:** ${entry.results.violations.length}`);
654
+ }
655
+ if (entry.results.deletedFiles) {
656
+ lines.push(`**Files Deleted:** ${entry.results.deletedFiles.length}`);
657
+ }
658
+ if (entry.results.movedFiles) {
659
+ lines.push(`**Files Moved:** ${entry.results.movedFiles.length}`);
660
+ }
661
+ if (entry.results.errors && entry.results.errors.length > 0) {
662
+ lines.push(`**Errors:** ${entry.results.errors.length}`);
663
+ }
664
+ }
665
+
666
+ lines.push('');
667
+ });
668
+
669
+ // Footer
670
+ lines.push('---');
671
+ lines.push('');
672
+ lines.push('*Generated by kiro-spec-engine document governance system*');
673
+ lines.push('');
674
+
675
+ return lines.join('\n');
676
+ }
677
+
678
+ /**
679
+ * Display help information
680
+ */
681
+ function showHelp() {
682
+ console.log(chalk.bold.cyan('\nšŸ“‹ Document Governance Commands\n'));
683
+
684
+ console.log(chalk.bold('Usage:'));
685
+ console.log(' kse docs <subcommand> [options]\n');
686
+
687
+ console.log(chalk.bold('Subcommands:'));
688
+ console.log(' diagnose Scan project for document violations');
689
+ console.log(' cleanup Remove temporary documents');
690
+ console.log(' validate Validate document structure');
691
+ console.log(' archive Organize Spec artifacts into subdirectories');
692
+ console.log(' hooks <action> Manage Git hooks (install, uninstall, status)');
693
+ console.log(' config Display or modify configuration');
694
+ console.log(' stats Display compliance statistics');
695
+ console.log(' report Generate compliance report');
696
+ console.log(' check-refs Check for incorrect project references and placeholders');
697
+ console.log(' help Show this help message\n');
698
+
699
+ console.log(chalk.bold('Options:'));
700
+ console.log(' --dry-run, --dry Preview changes without applying them');
701
+ console.log(' --interactive, -i Prompt for confirmation (cleanup only)');
702
+ console.log(' --spec <name> Target specific Spec directory');
703
+ console.log(' --all Validate all Specs (validate only)');
704
+ console.log(' --set <key> <value> Set configuration value (config only)');
705
+ console.log(' --reset Reset configuration to defaults (config only)');
706
+ console.log(' --report Save report to file (check-refs only)');
707
+ console.log(' --verbose Show detailed error information\n');
708
+
709
+ console.log(chalk.bold('Examples:'));
710
+ console.log(' kse docs diagnose');
711
+ console.log(' kse docs cleanup --dry-run');
712
+ console.log(' kse docs cleanup --spec my-spec');
713
+ console.log(' kse docs validate --all');
714
+ console.log(' kse docs archive --spec my-spec --dry-run');
715
+ console.log(' kse docs hooks install');
716
+ console.log(' kse docs hooks status');
717
+ console.log(' kse docs config');
718
+ console.log(' kse docs config --set root-allowed-files "README.md,CUSTOM.md"');
719
+ console.log(' kse docs config --reset');
720
+ console.log(' kse docs stats');
721
+ console.log(' kse docs report');
722
+ console.log(' kse docs check-refs');
723
+ console.log(' kse docs check-refs --report\n');
724
+ }
725
+
726
+ /**
727
+ * Handle check-references subcommand
728
+ *
729
+ * @param {string} projectPath - Project root path
730
+ * @param {Object} reporter - Reporter instance
731
+ * @param {Object} options - Command options
732
+ * @returns {Promise<number>} - Exit code
733
+ */
734
+ async function handleCheckReferences(projectPath, reporter, options) {
735
+ const path = require('path');
736
+
737
+ try {
738
+ console.log(chalk.bold.cyan('\nšŸ” Checking Document References...\n'));
739
+
740
+ const checker = new DocReferenceChecker(projectPath);
741
+ const results = await checker.checkAll();
742
+
743
+ // Display results
744
+ if (results.issuesFound === 0) {
745
+ console.log(chalk.green('āœ… No issues found! All documentation is clean.\n'));
746
+ console.log(`Files checked: ${results.filesChecked}`);
747
+ return 0;
748
+ }
749
+
750
+ console.log(chalk.yellow(`āš ļø Found ${results.issuesFound} issue(s) in ${results.filesChecked} file(s)\n`));
751
+
752
+ // Display incorrect references
753
+ if (results.incorrectReferences.length > 0) {
754
+ console.log(chalk.red.bold('šŸ”“ Incorrect Project References:\n'));
755
+ results.incorrectReferences.forEach(item => {
756
+ console.log(chalk.bold(` ${item.file}:`));
757
+ item.references.forEach(ref => {
758
+ console.log(chalk.red(` Line ${ref.line}: Found "${ref.reference}"`));
759
+ console.log(chalk.gray(` ${ref.content}`));
760
+ });
761
+ console.log();
762
+ });
763
+ }
764
+
765
+ // Display unresolved placeholders
766
+ if (results.unresolvedPlaceholders.length > 0) {
767
+ console.log(chalk.yellow.bold('🟔 Unresolved Placeholders:\n'));
768
+ results.unresolvedPlaceholders.forEach(item => {
769
+ console.log(chalk.bold(` ${item.file}:`));
770
+ item.placeholders.forEach(ph => {
771
+ console.log(chalk.yellow(` Line ${ph.line}: ${ph.placeholder}`));
772
+ console.log(chalk.gray(` ${ph.content}`));
773
+ });
774
+ console.log();
775
+ });
776
+ }
777
+
778
+ // Recommendations
779
+ console.log(chalk.bold.cyan('šŸ’” Recommendations:\n'));
780
+ if (results.incorrectReferences.length > 0) {
781
+ console.log(' 1. Remove or replace incorrect project references');
782
+ console.log(' 2. Ensure all documentation reflects the correct project identity');
783
+ }
784
+ if (results.unresolvedPlaceholders.length > 0) {
785
+ console.log(' 3. Replace all [TODO: ...] placeholders with actual project information');
786
+ console.log(' 4. Update ENVIRONMENT.md with correct project details');
787
+ }
788
+ console.log();
789
+
790
+ // Save report if requested
791
+ if (options.report) {
792
+ const report = checker.generateReport(results);
793
+ const reportPath = path.join(projectPath, '.kiro/reports', `doc-reference-check-${new Date().toISOString().split('T')[0]}.md`);
794
+ await checker.saveReport(report, reportPath);
795
+ console.log(chalk.green(`āœ… Report saved to: ${reportPath}\n`));
796
+ }
797
+
798
+ return results.issuesFound > 0 ? 1 : 0;
799
+ } catch (error) {
800
+ reporter.displayError(`Failed to check references: ${error.message}`);
801
+ if (options.verbose) {
802
+ console.error(error.stack);
803
+ }
804
+ return 2;
805
+ }
806
+ }
807
+
808
+ module.exports = docsCommand;