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,619 @@
1
+ # Developer Guide
2
+
3
+ This guide is for developers who want to contribute to Kiro Spec Engine or extend its functionality.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Architecture Overview](#architecture-overview)
8
+ - [Core Components](#core-components)
9
+ - [Migration Script Interface](#migration-script-interface)
10
+ - [Extension Points](#extension-points)
11
+ - [API Documentation](#api-documentation)
12
+ - [Testing Guidelines](#testing-guidelines)
13
+ - [Contributing](#contributing)
14
+
15
+ ---
16
+
17
+ ## Architecture Overview
18
+
19
+ Kiro Spec Engine follows a modular architecture with clear separation of concerns:
20
+
21
+ ```
22
+ ┌─────────────────────────────────────────────────────────────┐
23
+ │ CLI Layer │
24
+ │ (bin/kiro-spec-engine.js, lib/commands/*.js) │
25
+ └─────────────────────────────────────────────────────────────┘
26
+
27
+
28
+ ┌─────────────────────────────────────────────────────────────┐
29
+ │ Core Systems │
30
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
31
+ │ │ Adoption │ │ Upgrade │ │ Backup │ │
32
+ │ │ System │ │ System │ │ System │ │
33
+ │ └──────────────┘ └──────────────┘ └──────────────┘ │
34
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
35
+ │ │ Scene │ │ Workspace │ │ Environment │ │
36
+ │ │ Runtime │ │ Manager │ │ Manager │ │
37
+ │ └──────────────┘ └──────────────┘ └──────────────┘ │
38
+ └─────────────────────────────────────────────────────────────┘
39
+
40
+
41
+ ┌─────────────────────────────────────────────────────────────┐
42
+ │ Utility Layer │
43
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
44
+ │ │ Version │ │ Validation │ │ File System │ │
45
+ │ │ Manager │ │ Utils │ │ Utils │ │
46
+ │ └──────────────┘ └──────────────┘ └──────────────┘ │
47
+ └─────────────────────────────────────────────────────────────┘
48
+ ```
49
+
50
+ ### Design Principles
51
+
52
+ 1. **Modularity**: Each component has a single responsibility
53
+ 2. **Safety**: All operations are atomic with automatic backups
54
+ 3. **Extensibility**: Clear extension points for future features
55
+ 4. **Testability**: Components are designed for easy testing
56
+ 5. **User-Friendly**: Clear error messages and progress indicators
57
+
58
+ ---
59
+
60
+ ## Core Components
61
+
62
+ ### 1. DetectionEngine (`lib/adoption/detection-engine.js`)
63
+
64
+ Analyzes project structure and determines the appropriate adoption strategy.
65
+
66
+ **Key Methods**:
67
+ - `analyze(projectPath)`: Scans project structure
68
+ - `determineStrategy()`: Selects adoption mode (fresh/partial/full)
69
+ - `detectProjectType()`: Identifies Node.js/Python/mixed projects
70
+ - `detectConflicts()`: Finds template file conflicts
71
+
72
+ **Usage Example**:
73
+ ```javascript
74
+ const DetectionEngine = require('./lib/adoption/detection-engine');
75
+
76
+ const engine = new DetectionEngine('/path/to/project');
77
+ const analysis = engine.analyze();
78
+ console.log(analysis.mode); // 'fresh', 'partial', or 'full'
79
+ ```
80
+
81
+ ### 2. AdoptionStrategy (`lib/adoption/adoption-strategy.js`)
82
+
83
+ Implements different adoption modes for various project states.
84
+
85
+ **Strategies**:
86
+ - `FreshAdoption`: Creates complete .kiro/ structure from scratch
87
+ - `PartialAdoption`: Adds missing components to existing .kiro/
88
+ - `FullAdoption`: Upgrades existing complete .kiro/ to current version
89
+
90
+ **Usage Example**:
91
+ ```javascript
92
+ const { getStrategy } = require('./lib/adoption/adoption-strategy');
93
+
94
+ const strategy = getStrategy('fresh');
95
+ await strategy.execute('/path/to/project', {
96
+ preserveSpecs: true,
97
+ backupFirst: true
98
+ });
99
+ ```
100
+
101
+ ### 3. VersionManager (`lib/version/version-manager.js`)
102
+
103
+ Manages project versions and upgrade paths.
104
+
105
+ **Key Methods**:
106
+ - `readVersion(projectPath)`: Reads version.json
107
+ - `writeVersion(projectPath, versionInfo)`: Writes version.json atomically
108
+ - `needsUpgrade(currentVersion, targetVersion)`: Checks if upgrade needed
109
+ - `calculateUpgradePath(from, to)`: Calculates intermediate versions
110
+
111
+ **Usage Example**:
112
+ ```javascript
113
+ const VersionManager = require('./lib/version/version-manager');
114
+
115
+ const vm = new VersionManager();
116
+ const needsUpgrade = vm.needsUpgrade('1.0.0', '1.2.0');
117
+ if (needsUpgrade) {
118
+ const path = vm.calculateUpgradePath('1.0.0', '1.2.0');
119
+ console.log(path); // ['1.0.0', '1.1.0', '1.2.0']
120
+ }
121
+ ```
122
+
123
+ ### 4. MigrationEngine (`lib/upgrade/migration-engine.js`)
124
+
125
+ Plans and executes version upgrades with migration scripts.
126
+
127
+ **Key Methods**:
128
+ - `planUpgrade(from, to)`: Creates upgrade plan
129
+ - `executeUpgrade(projectPath, plan)`: Runs migrations sequentially
130
+ - `loadMigration(version)`: Loads migration script
131
+ - `validate(projectPath)`: Post-upgrade validation
132
+
133
+ **Usage Example**:
134
+ ```javascript
135
+ const MigrationEngine = require('./lib/upgrade/migration-engine');
136
+
137
+ const engine = new MigrationEngine();
138
+ const plan = engine.planUpgrade('1.0.0', '1.2.0');
139
+ await engine.executeUpgrade('/path/to/project', plan);
140
+ ```
141
+
142
+ ### 5. BackupSystem (`lib/backup/backup-system.js`)
143
+
144
+ Creates, manages, and restores backups for safe operations.
145
+
146
+ **Key Methods**:
147
+ - `createBackup(projectPath, reason)`: Creates timestamped backup
148
+ - `listBackups(projectPath)`: Lists available backups
149
+ - `restore(projectPath, backupId)`: Restores from backup
150
+ - `validateBackup(backupPath)`: Verifies backup integrity
151
+
152
+ **Usage Example**:
153
+ ```javascript
154
+ const BackupSystem = require('./lib/backup/backup-system');
155
+
156
+ const backup = new BackupSystem();
157
+ const backupId = await backup.createBackup('/path/to/project', 'before-upgrade');
158
+ // ... perform operations ...
159
+ if (failed) {
160
+ await backup.restore('/path/to/project', backupId);
161
+ }
162
+ ```
163
+
164
+ ---
165
+
166
+ ## Migration Script Interface
167
+
168
+ Migration scripts enable smooth upgrades between versions with breaking changes.
169
+
170
+ ### Script Structure
171
+
172
+ Create migration scripts in `lib/upgrade/migrations/` with the naming pattern:
173
+ `{from-version}-to-{to-version}.js`
174
+
175
+ Example: `1.0.0-to-1.1.0.js`
176
+
177
+ ### Required Interface
178
+
179
+ ```javascript
180
+ /**
181
+ * Migration script from version X to version Y
182
+ */
183
+ module.exports = {
184
+ /**
185
+ * Migrate project from old version to new version
186
+ * @param {string} projectPath - Absolute path to project root
187
+ * @param {Object} context - Migration context
188
+ * @param {Object} context.oldVersion - Old version info
189
+ * @param {Object} context.newVersion - New version info
190
+ * @param {Object} context.logger - Logger instance
191
+ * @returns {Promise<Object>} Migration result
192
+ */
193
+ async migrate(projectPath, context) {
194
+ const { oldVersion, newVersion, logger } = context;
195
+
196
+ logger.info(`Migrating from ${oldVersion.version} to ${newVersion.version}`);
197
+
198
+ // Perform migration steps
199
+ // 1. Read existing files
200
+ // 2. Transform data/structure
201
+ // 3. Write new files
202
+ // 4. Update configuration
203
+
204
+ return {
205
+ success: true,
206
+ changes: [
207
+ 'Added new steering file: ENVIRONMENT.md',
208
+ 'Updated version.json structure'
209
+ ],
210
+ warnings: []
211
+ };
212
+ },
213
+
214
+ /**
215
+ * Rollback migration (optional but recommended)
216
+ * @param {string} projectPath - Absolute path to project root
217
+ * @param {Object} context - Migration context
218
+ * @returns {Promise<Object>} Rollback result
219
+ */
220
+ async rollback(projectPath, context) {
221
+ const { logger } = context;
222
+
223
+ logger.info('Rolling back migration');
224
+
225
+ // Reverse migration steps
226
+ // Usually handled by backup restore, but can be implemented
227
+ // for more granular control
228
+
229
+ return {
230
+ success: true,
231
+ message: 'Rollback completed'
232
+ };
233
+ },
234
+
235
+ /**
236
+ * Validate migration result (optional)
237
+ * @param {string} projectPath - Absolute path to project root
238
+ * @returns {Promise<Object>} Validation result
239
+ */
240
+ async validate(projectPath) {
241
+ // Verify migration was successful
242
+ // Check file existence, structure, etc.
243
+
244
+ return {
245
+ valid: true,
246
+ errors: []
247
+ };
248
+ }
249
+ };
250
+ ```
251
+
252
+ ### Migration Best Practices
253
+
254
+ 1. **Idempotency**: Migrations should be safe to run multiple times
255
+ 2. **Validation**: Always validate before and after migration
256
+ 3. **Logging**: Log all significant operations
257
+ 4. **Error Handling**: Handle errors gracefully with clear messages
258
+ 5. **Rollback**: Implement rollback when possible
259
+ 6. **Testing**: Test migrations with various project states
260
+
261
+ ### Example Migration Script
262
+
263
+ ```javascript
264
+ const fs = require('fs-extra');
265
+ const path = require('path');
266
+
267
+ module.exports = {
268
+ async migrate(projectPath, context) {
269
+ const { logger } = context;
270
+ const changes = [];
271
+
272
+ // Add new steering file
273
+ const steeringDir = path.join(projectPath, '.kiro', 'steering');
274
+ const envFile = path.join(steeringDir, 'ENVIRONMENT.md');
275
+
276
+ if (!fs.existsSync(envFile)) {
277
+ const template = `# Environment Configuration
278
+ ...template content...`;
279
+ await fs.writeFile(envFile, template, 'utf8');
280
+ changes.push('Created ENVIRONMENT.md');
281
+ logger.info('✅ Created ENVIRONMENT.md');
282
+ }
283
+
284
+ // Update version.json structure
285
+ const versionFile = path.join(projectPath, '.kiro', 'version.json');
286
+ const versionData = await fs.readJson(versionFile);
287
+
288
+ if (!versionData.upgradeHistory) {
289
+ versionData.upgradeHistory = [];
290
+ await fs.writeJson(versionFile, versionData, { spaces: 2 });
291
+ changes.push('Added upgradeHistory to version.json');
292
+ logger.info('✅ Updated version.json structure');
293
+ }
294
+
295
+ return {
296
+ success: true,
297
+ changes,
298
+ warnings: []
299
+ };
300
+ },
301
+
302
+ async validate(projectPath) {
303
+ const errors = [];
304
+
305
+ // Check ENVIRONMENT.md exists
306
+ const envFile = path.join(projectPath, '.kiro', 'steering', 'ENVIRONMENT.md');
307
+ if (!fs.existsSync(envFile)) {
308
+ errors.push('ENVIRONMENT.md not found');
309
+ }
310
+
311
+ // Check version.json structure
312
+ const versionFile = path.join(projectPath, '.kiro', 'version.json');
313
+ const versionData = await fs.readJson(versionFile);
314
+ if (!versionData.upgradeHistory) {
315
+ errors.push('version.json missing upgradeHistory field');
316
+ }
317
+
318
+ return {
319
+ valid: errors.length === 0,
320
+ errors
321
+ };
322
+ }
323
+ };
324
+ ```
325
+
326
+ ---
327
+
328
+ ## Extension Points
329
+
330
+ ### 1. Custom Adoption Strategies
331
+
332
+ Add new adoption strategies by extending the base class:
333
+
334
+ ```javascript
335
+ const { AdoptionStrategy } = require('./lib/adoption/adoption-strategy');
336
+
337
+ class CustomAdoption extends AdoptionStrategy {
338
+ async execute(projectPath, options) {
339
+ // Custom adoption logic
340
+ }
341
+ }
342
+
343
+ // Register strategy
344
+ const strategies = {
345
+ custom: CustomAdoption
346
+ };
347
+ ```
348
+
349
+ ### 2. Custom Validation Rules
350
+
351
+ Extend validation system with custom rules:
352
+
353
+ ```javascript
354
+ const validation = require('./lib/utils/validation');
355
+
356
+ function validateCustomRule(projectPath) {
357
+ // Custom validation logic
358
+ return {
359
+ valid: true,
360
+ errors: []
361
+ };
362
+ }
363
+
364
+ // Use in validation pipeline
365
+ const result = await validation.validateProject(projectPath, {
366
+ customValidators: [validateCustomRule]
367
+ });
368
+ ```
369
+
370
+ ### 3. Custom Migration Hooks
371
+
372
+ Add hooks to migration process:
373
+
374
+ ```javascript
375
+ const MigrationEngine = require('./lib/upgrade/migration-engine');
376
+
377
+ class CustomMigrationEngine extends MigrationEngine {
378
+ async beforeMigration(projectPath, plan) {
379
+ // Pre-migration hook
380
+ }
381
+
382
+ async afterMigration(projectPath, result) {
383
+ // Post-migration hook
384
+ }
385
+ }
386
+ ```
387
+
388
+ ### 4. Custom CLI Commands
389
+
390
+ Add new commands to the CLI:
391
+
392
+ ```javascript
393
+ // lib/commands/my-command.js
394
+ module.exports = {
395
+ name: 'my-command',
396
+ description: 'My custom command',
397
+
398
+ async execute(options) {
399
+ // Command logic
400
+ }
401
+ };
402
+
403
+ // Register in bin/kiro-spec-engine.js
404
+ program
405
+ .command('my-command')
406
+ .description('My custom command')
407
+ .action(require('../lib/commands/my-command').execute);
408
+ ```
409
+
410
+ ---
411
+
412
+ ## API Documentation
413
+
414
+ ### DetectionEngine API
415
+
416
+ #### `constructor(projectPath)`
417
+ Creates a new DetectionEngine instance.
418
+
419
+ #### `analyze()`
420
+ Analyzes project structure and returns analysis result.
421
+
422
+ **Returns**: `Object`
423
+ ```javascript
424
+ {
425
+ mode: 'fresh' | 'partial' | 'full',
426
+ projectType: 'nodejs' | 'python' | 'mixed',
427
+ hasKiroDir: boolean,
428
+ hasSpecs: boolean,
429
+ hasVersion: boolean,
430
+ conflicts: string[],
431
+ currentVersion: string | null
432
+ }
433
+ ```
434
+
435
+ ### VersionManager API
436
+
437
+ #### `readVersion(projectPath)`
438
+ Reads version.json from project.
439
+
440
+ **Returns**: `Promise<Object>`
441
+ ```javascript
442
+ {
443
+ version: '1.2.0',
444
+ kseVersion: '1.2.0',
445
+ createdAt: '2026-01-23T00:00:00.000Z',
446
+ updatedAt: '2026-01-23T00:00:00.000Z',
447
+ upgradeHistory: []
448
+ }
449
+ ```
450
+
451
+ #### `needsUpgrade(currentVersion, targetVersion)`
452
+ Checks if upgrade is needed.
453
+
454
+ **Returns**: `boolean`
455
+
456
+ #### `calculateUpgradePath(fromVersion, toVersion)`
457
+ Calculates intermediate versions for upgrade.
458
+
459
+ **Returns**: `string[]` - Array of versions in upgrade order
460
+
461
+ ### BackupSystem API
462
+
463
+ #### `createBackup(projectPath, reason)`
464
+ Creates a timestamped backup.
465
+
466
+ **Returns**: `Promise<string>` - Backup ID
467
+
468
+ #### `listBackups(projectPath)`
469
+ Lists available backups.
470
+
471
+ **Returns**: `Promise<Array>`
472
+ ```javascript
473
+ [
474
+ {
475
+ id: 'backup-20260123-120000',
476
+ timestamp: '2026-01-23T12:00:00.000Z',
477
+ reason: 'before-upgrade',
478
+ size: 1024000
479
+ }
480
+ ]
481
+ ```
482
+
483
+ #### `restore(projectPath, backupId)`
484
+ Restores project from backup.
485
+
486
+ **Returns**: `Promise<void>`
487
+
488
+ ---
489
+
490
+ ## Testing Guidelines
491
+
492
+ ### Unit Tests
493
+
494
+ Unit tests are located in `tests/unit/` and test individual components.
495
+
496
+ **Running unit tests**:
497
+ ```bash
498
+ npm run test:unit
499
+ ```
500
+
501
+ **Writing unit tests**:
502
+ ```javascript
503
+ const DetectionEngine = require('../../lib/adoption/detection-engine');
504
+
505
+ describe('DetectionEngine', () => {
506
+ test('should detect fresh adoption mode', () => {
507
+ const engine = new DetectionEngine('/path/to/project');
508
+ const analysis = engine.analyze();
509
+ expect(analysis.mode).toBe('fresh');
510
+ });
511
+ });
512
+ ```
513
+
514
+ ### Property-Based Tests
515
+
516
+ Property-based tests are located in `tests/properties/` and test universal properties.
517
+
518
+ **Running property tests**:
519
+ ```bash
520
+ npm run test:properties
521
+ ```
522
+
523
+ **Writing property tests**:
524
+ ```javascript
525
+ const fc = require('fast-check');
526
+ const VersionManager = require('../../lib/version/version-manager');
527
+
528
+ describe('VersionManager Properties', () => {
529
+ test('version comparison is transitive', () => {
530
+ fc.assert(
531
+ fc.property(
532
+ fc.string(), fc.string(), fc.string(),
533
+ (v1, v2, v3) => {
534
+ const vm = new VersionManager();
535
+ // If v1 < v2 and v2 < v3, then v1 < v3
536
+ // Property test logic
537
+ }
538
+ )
539
+ );
540
+ });
541
+ });
542
+ ```
543
+
544
+ ### Integration Tests
545
+
546
+ Integration tests are located in `tests/integration/` and test end-to-end flows.
547
+
548
+ **Running integration tests**:
549
+ ```bash
550
+ npm run test:integration
551
+ ```
552
+
553
+ ---
554
+
555
+ ## Contributing
556
+
557
+ ### Development Setup
558
+
559
+ 1. Clone the repository:
560
+ ```bash
561
+ git clone https://github.com/heguangyong/scene-capability-engine.git
562
+ cd kiro-spec-engine
563
+ ```
564
+
565
+ 2. Install dependencies:
566
+ ```bash
567
+ npm install
568
+ ```
569
+
570
+ 3. Run tests:
571
+ ```bash
572
+ npm test
573
+ ```
574
+
575
+ 4. Install globally for testing:
576
+ ```bash
577
+ npm run install-global
578
+ ```
579
+
580
+ ### Code Style
581
+
582
+ - Use 2 spaces for indentation
583
+ - Use semicolons
584
+ - Use single quotes for strings
585
+ - Follow existing code patterns
586
+ - Add JSDoc comments for public APIs
587
+
588
+ ### Pull Request Process
589
+
590
+ 1. Create a feature branch from `main`
591
+ 2. Make your changes with tests
592
+ 3. Ensure all tests pass
593
+ 4. Update documentation if needed
594
+ 5. Submit pull request with clear description
595
+
596
+ ### Commit Message Format
597
+
598
+ Follow conventional commits:
599
+ ```
600
+ feat: add new adoption strategy
601
+ fix: correct version comparison logic
602
+ docs: update developer guide
603
+ test: add property tests for backup system
604
+ ```
605
+
606
+ ---
607
+
608
+ ## Additional Resources
609
+
610
+ - [User Adoption Guide](./adoption-guide.md)
611
+ - [User Upgrade Guide](./upgrade-guide.md)
612
+ - [Spec Workflow Guide](../.kiro/specs/SPEC_WORKFLOW_GUIDE.md)
613
+ - [GitHub Repository](https://github.com/heguangyong/scene-capability-engine)
614
+ - [Issue Tracker](https://github.com/heguangyong/scene-capability-engine/issues)
615
+
616
+ ---
617
+
618
+ **Version**: 1.42.0
619
+ **Last Updated**: 2026-02-11