@devtrack-solution/codesdd 1.2.2

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 (433) hide show
  1. package/.sdd/skills/curated/api-clean-flask-langgraph/SKILL.md +2751 -0
  2. package/.sdd/skills/curated/devtrack-api/SKILL.md +137 -0
  3. package/.sdd/skills/curated/devtrack-api/agents/openai.yaml +4 -0
  4. package/.sdd/skills/curated/devtrack-api/references/application-presentation.md +381 -0
  5. package/.sdd/skills/curated/devtrack-api/references/architecture-governance.md +219 -0
  6. package/.sdd/skills/curated/devtrack-api/references/domain-modeling.md +359 -0
  7. package/.sdd/skills/curated/devtrack-api/references/implementation-checklist.md +127 -0
  8. package/.sdd/skills/curated/devtrack-api/references/imports-lint.md +207 -0
  9. package/.sdd/skills/curated/devtrack-api/references/testing-validation.md +167 -0
  10. package/.sdd/skills/curated/devtrack-api/references/typeorm-infrastructure.md +334 -0
  11. package/LICENSE +21 -0
  12. package/README.md +842 -0
  13. package/bin/codesdd.js +10 -0
  14. package/dist/cli/index.d.ts +3 -0
  15. package/dist/cli/index.js +560 -0
  16. package/dist/commands/change.d.ts +35 -0
  17. package/dist/commands/change.js +296 -0
  18. package/dist/commands/completion.d.ts +72 -0
  19. package/dist/commands/completion.js +258 -0
  20. package/dist/commands/config.d.ts +36 -0
  21. package/dist/commands/config.js +552 -0
  22. package/dist/commands/feedback.d.ts +9 -0
  23. package/dist/commands/feedback.js +184 -0
  24. package/dist/commands/schema.d.ts +6 -0
  25. package/dist/commands/schema.js +870 -0
  26. package/dist/commands/sdd/execution.d.ts +3 -0
  27. package/dist/commands/sdd/execution.js +409 -0
  28. package/dist/commands/sdd/shared.d.ts +9 -0
  29. package/dist/commands/sdd/shared.js +84 -0
  30. package/dist/commands/sdd/skills.d.ts +3 -0
  31. package/dist/commands/sdd/skills.js +154 -0
  32. package/dist/commands/sdd.d.ts +3 -0
  33. package/dist/commands/sdd.js +769 -0
  34. package/dist/commands/show.d.ts +14 -0
  35. package/dist/commands/show.js +133 -0
  36. package/dist/commands/spec.d.ts +15 -0
  37. package/dist/commands/spec.js +228 -0
  38. package/dist/commands/validate.d.ts +24 -0
  39. package/dist/commands/validate.js +295 -0
  40. package/dist/commands/workflow/index.d.ts +17 -0
  41. package/dist/commands/workflow/index.js +12 -0
  42. package/dist/commands/workflow/instructions.d.ts +29 -0
  43. package/dist/commands/workflow/instructions.js +383 -0
  44. package/dist/commands/workflow/new-change.d.ts +11 -0
  45. package/dist/commands/workflow/new-change.js +45 -0
  46. package/dist/commands/workflow/schemas.d.ts +10 -0
  47. package/dist/commands/workflow/schemas.js +34 -0
  48. package/dist/commands/workflow/shared.d.ts +57 -0
  49. package/dist/commands/workflow/shared.js +117 -0
  50. package/dist/commands/workflow/status.d.ts +14 -0
  51. package/dist/commands/workflow/status.js +76 -0
  52. package/dist/commands/workflow/templates.d.ts +16 -0
  53. package/dist/commands/workflow/templates.js +68 -0
  54. package/dist/core/archive.d.ts +16 -0
  55. package/dist/core/archive.js +487 -0
  56. package/dist/core/artifact-graph/graph.d.ts +56 -0
  57. package/dist/core/artifact-graph/graph.js +141 -0
  58. package/dist/core/artifact-graph/index.d.ts +7 -0
  59. package/dist/core/artifact-graph/index.js +13 -0
  60. package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
  61. package/dist/core/artifact-graph/instruction-loader.js +215 -0
  62. package/dist/core/artifact-graph/resolver.d.ts +81 -0
  63. package/dist/core/artifact-graph/resolver.js +258 -0
  64. package/dist/core/artifact-graph/schema.d.ts +13 -0
  65. package/dist/core/artifact-graph/schema.js +108 -0
  66. package/dist/core/artifact-graph/state.d.ts +12 -0
  67. package/dist/core/artifact-graph/state.js +54 -0
  68. package/dist/core/artifact-graph/types.d.ts +45 -0
  69. package/dist/core/artifact-graph/types.js +43 -0
  70. package/dist/core/available-tools.d.ts +16 -0
  71. package/dist/core/available-tools.js +30 -0
  72. package/dist/core/branding.d.ts +8 -0
  73. package/dist/core/branding.js +12 -0
  74. package/dist/core/cli/command-matrix.d.ts +23 -0
  75. package/dist/core/cli/command-matrix.js +123 -0
  76. package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
  77. package/dist/core/command-generation/adapters/amazon-q.js +26 -0
  78. package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
  79. package/dist/core/command-generation/adapters/antigravity.js +26 -0
  80. package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
  81. package/dist/core/command-generation/adapters/auggie.js +27 -0
  82. package/dist/core/command-generation/adapters/claude.d.ts +13 -0
  83. package/dist/core/command-generation/adapters/claude.js +50 -0
  84. package/dist/core/command-generation/adapters/cline.d.ts +14 -0
  85. package/dist/core/command-generation/adapters/cline.js +27 -0
  86. package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
  87. package/dist/core/command-generation/adapters/codebuddy.js +28 -0
  88. package/dist/core/command-generation/adapters/codex.d.ts +16 -0
  89. package/dist/core/command-generation/adapters/codex.js +39 -0
  90. package/dist/core/command-generation/adapters/continue.d.ts +13 -0
  91. package/dist/core/command-generation/adapters/continue.js +28 -0
  92. package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
  93. package/dist/core/command-generation/adapters/costrict.js +27 -0
  94. package/dist/core/command-generation/adapters/crush.d.ts +13 -0
  95. package/dist/core/command-generation/adapters/crush.js +30 -0
  96. package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
  97. package/dist/core/command-generation/adapters/cursor.js +44 -0
  98. package/dist/core/command-generation/adapters/factory.d.ts +13 -0
  99. package/dist/core/command-generation/adapters/factory.js +27 -0
  100. package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
  101. package/dist/core/command-generation/adapters/gemini.js +26 -0
  102. package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
  103. package/dist/core/command-generation/adapters/github-copilot.js +26 -0
  104. package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
  105. package/dist/core/command-generation/adapters/iflow.js +29 -0
  106. package/dist/core/command-generation/adapters/index.d.ts +29 -0
  107. package/dist/core/command-generation/adapters/index.js +29 -0
  108. package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
  109. package/dist/core/command-generation/adapters/kilocode.js +23 -0
  110. package/dist/core/command-generation/adapters/kiro.d.ts +13 -0
  111. package/dist/core/command-generation/adapters/kiro.js +26 -0
  112. package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
  113. package/dist/core/command-generation/adapters/opencode.js +29 -0
  114. package/dist/core/command-generation/adapters/pi.d.ts +14 -0
  115. package/dist/core/command-generation/adapters/pi.js +41 -0
  116. package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
  117. package/dist/core/command-generation/adapters/qoder.js +30 -0
  118. package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
  119. package/dist/core/command-generation/adapters/qwen.js +26 -0
  120. package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
  121. package/dist/core/command-generation/adapters/roocode.js +27 -0
  122. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  123. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  124. package/dist/core/command-generation/generator.d.ts +21 -0
  125. package/dist/core/command-generation/generator.js +27 -0
  126. package/dist/core/command-generation/index.d.ts +22 -0
  127. package/dist/core/command-generation/index.js +24 -0
  128. package/dist/core/command-generation/registry.d.ts +36 -0
  129. package/dist/core/command-generation/registry.js +92 -0
  130. package/dist/core/command-generation/types.d.ts +56 -0
  131. package/dist/core/command-generation/types.js +8 -0
  132. package/dist/core/completions/command-registry.d.ts +7 -0
  133. package/dist/core/completions/command-registry.js +461 -0
  134. package/dist/core/completions/completion-provider.d.ts +60 -0
  135. package/dist/core/completions/completion-provider.js +102 -0
  136. package/dist/core/completions/factory.d.ts +64 -0
  137. package/dist/core/completions/factory.js +75 -0
  138. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  139. package/dist/core/completions/generators/bash-generator.js +174 -0
  140. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  141. package/dist/core/completions/generators/fish-generator.js +157 -0
  142. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  143. package/dist/core/completions/generators/powershell-generator.js +207 -0
  144. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  145. package/dist/core/completions/generators/zsh-generator.js +250 -0
  146. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  147. package/dist/core/completions/installers/bash-installer.js +318 -0
  148. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  149. package/dist/core/completions/installers/fish-installer.js +143 -0
  150. package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
  151. package/dist/core/completions/installers/powershell-installer.js +327 -0
  152. package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
  153. package/dist/core/completions/installers/zsh-installer.js +452 -0
  154. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  155. package/dist/core/completions/templates/bash-templates.js +24 -0
  156. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  157. package/dist/core/completions/templates/fish-templates.js +39 -0
  158. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  159. package/dist/core/completions/templates/powershell-templates.js +25 -0
  160. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  161. package/dist/core/completions/templates/zsh-templates.js +36 -0
  162. package/dist/core/completions/types.d.ts +79 -0
  163. package/dist/core/completions/types.js +2 -0
  164. package/dist/core/config-prompts.d.ts +9 -0
  165. package/dist/core/config-prompts.js +34 -0
  166. package/dist/core/config-schema.d.ts +86 -0
  167. package/dist/core/config-schema.js +213 -0
  168. package/dist/core/config.d.ts +17 -0
  169. package/dist/core/config.js +33 -0
  170. package/dist/core/converters/json-converter.d.ts +6 -0
  171. package/dist/core/converters/json-converter.js +51 -0
  172. package/dist/core/global-config.d.ts +44 -0
  173. package/dist/core/global-config.js +125 -0
  174. package/dist/core/index.d.ts +2 -0
  175. package/dist/core/index.js +3 -0
  176. package/dist/core/init.d.ts +36 -0
  177. package/dist/core/init.js +576 -0
  178. package/dist/core/legacy-cleanup.d.ts +162 -0
  179. package/dist/core/legacy-cleanup.js +512 -0
  180. package/dist/core/list.d.ts +9 -0
  181. package/dist/core/list.js +173 -0
  182. package/dist/core/migration.d.ts +23 -0
  183. package/dist/core/migration.js +108 -0
  184. package/dist/core/parsers/change-parser.d.ts +13 -0
  185. package/dist/core/parsers/change-parser.js +193 -0
  186. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  187. package/dist/core/parsers/markdown-parser.js +187 -0
  188. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  189. package/dist/core/parsers/requirement-blocks.js +201 -0
  190. package/dist/core/profile-sync-drift.d.ts +38 -0
  191. package/dist/core/profile-sync-drift.js +201 -0
  192. package/dist/core/profiles.d.ts +26 -0
  193. package/dist/core/profiles.js +41 -0
  194. package/dist/core/project-config.d.ts +64 -0
  195. package/dist/core/project-config.js +223 -0
  196. package/dist/core/schemas/base.schema.d.ts +13 -0
  197. package/dist/core/schemas/base.schema.js +13 -0
  198. package/dist/core/schemas/change.schema.d.ts +73 -0
  199. package/dist/core/schemas/change.schema.js +31 -0
  200. package/dist/core/schemas/index.d.ts +4 -0
  201. package/dist/core/schemas/index.js +4 -0
  202. package/dist/core/schemas/spec.schema.d.ts +18 -0
  203. package/dist/core/schemas/spec.schema.js +15 -0
  204. package/dist/core/sdd/adr-policy.d.ts +7 -0
  205. package/dist/core/sdd/adr-policy.js +47 -0
  206. package/dist/core/sdd/adr.d.ts +4 -0
  207. package/dist/core/sdd/adr.js +27 -0
  208. package/dist/core/sdd/bootstrap.d.ts +28 -0
  209. package/dist/core/sdd/bootstrap.js +353 -0
  210. package/dist/core/sdd/check.d.ts +51 -0
  211. package/dist/core/sdd/check.js +831 -0
  212. package/dist/core/sdd/coordination/coordination-adapters.d.ts +73 -0
  213. package/dist/core/sdd/coordination/coordination-adapters.js +87 -0
  214. package/dist/core/sdd/coordination/index.d.ts +2 -0
  215. package/dist/core/sdd/coordination/index.js +2 -0
  216. package/dist/core/sdd/dedup.d.ts +23 -0
  217. package/dist/core/sdd/dedup.js +62 -0
  218. package/dist/core/sdd/default-bootstrap-files.d.ts +23 -0
  219. package/dist/core/sdd/default-bootstrap-files.js +385 -0
  220. package/dist/core/sdd/default-skills.d.ts +16 -0
  221. package/dist/core/sdd/default-skills.js +427 -0
  222. package/dist/core/sdd/diagnose.d.ts +25 -0
  223. package/dist/core/sdd/diagnose.js +1312 -0
  224. package/dist/core/sdd/docs-sync.d.ts +21 -0
  225. package/dist/core/sdd/docs-sync.js +231 -0
  226. package/dist/core/sdd/domain/helpers.d.ts +6 -0
  227. package/dist/core/sdd/domain/helpers.js +37 -0
  228. package/dist/core/sdd/domain/lifecycle-guardrails.d.ts +22 -0
  229. package/dist/core/sdd/domain/lifecycle-guardrails.js +31 -0
  230. package/dist/core/sdd/domain/lifecycle-hooks.d.ts +16 -0
  231. package/dist/core/sdd/domain/lifecycle-hooks.js +27 -0
  232. package/dist/core/sdd/domain/post-active-validation.d.ts +15 -0
  233. package/dist/core/sdd/domain/post-active-validation.js +71 -0
  234. package/dist/core/sdd/domain/traceability.d.ts +8 -0
  235. package/dist/core/sdd/domain/traceability.js +83 -0
  236. package/dist/core/sdd/domain/transition-engine.d.ts +49 -0
  237. package/dist/core/sdd/domain/transition-engine.js +120 -0
  238. package/dist/core/sdd/fingerprint.d.ts +23 -0
  239. package/dist/core/sdd/fingerprint.js +146 -0
  240. package/dist/core/sdd/import-openspec.d.ts +31 -0
  241. package/dist/core/sdd/import-openspec.js +232 -0
  242. package/dist/core/sdd/init.d.ts +36 -0
  243. package/dist/core/sdd/init.js +65 -0
  244. package/dist/core/sdd/json-schema.d.ts +6 -0
  245. package/dist/core/sdd/json-schema.js +59 -0
  246. package/dist/core/sdd/legacy-operations.d.ts +286 -0
  247. package/dist/core/sdd/legacy-operations.js +2175 -0
  248. package/dist/core/sdd/lenses.d.ts +14 -0
  249. package/dist/core/sdd/lenses.js +97 -0
  250. package/dist/core/sdd/merge-catalog.d.ts +9 -0
  251. package/dist/core/sdd/merge-catalog.js +70 -0
  252. package/dist/core/sdd/migrate-workspace.d.ts +36 -0
  253. package/dist/core/sdd/migrate-workspace.js +344 -0
  254. package/dist/core/sdd/migrate.d.ts +24 -0
  255. package/dist/core/sdd/migrate.js +385 -0
  256. package/dist/core/sdd/resolve-project-root.d.ts +15 -0
  257. package/dist/core/sdd/resolve-project-root.js +46 -0
  258. package/dist/core/sdd/root-resolver.d.ts +16 -0
  259. package/dist/core/sdd/root-resolver.js +62 -0
  260. package/dist/core/sdd/sanitize.d.ts +35 -0
  261. package/dist/core/sdd/sanitize.js +750 -0
  262. package/dist/core/sdd/services/approve.service.d.ts +20 -0
  263. package/dist/core/sdd/services/approve.service.js +82 -0
  264. package/dist/core/sdd/services/audit.service.d.ts +53 -0
  265. package/dist/core/sdd/services/audit.service.js +136 -0
  266. package/dist/core/sdd/services/breakdown.service.d.ts +35 -0
  267. package/dist/core/sdd/services/breakdown.service.js +185 -0
  268. package/dist/core/sdd/services/context.service.d.ts +346 -0
  269. package/dist/core/sdd/services/context.service.js +278 -0
  270. package/dist/core/sdd/services/debate.service.d.ts +16 -0
  271. package/dist/core/sdd/services/debate.service.js +73 -0
  272. package/dist/core/sdd/services/decide.service.d.ts +23 -0
  273. package/dist/core/sdd/services/decide.service.js +81 -0
  274. package/dist/core/sdd/services/dedup-apply.service.d.ts +39 -0
  275. package/dist/core/sdd/services/dedup-apply.service.js +259 -0
  276. package/dist/core/sdd/services/feature-lint.service.d.ts +29 -0
  277. package/dist/core/sdd/services/feature-lint.service.js +146 -0
  278. package/dist/core/sdd/services/finalize.service.d.ts +33 -0
  279. package/dist/core/sdd/services/finalize.service.js +707 -0
  280. package/dist/core/sdd/services/frontend-gap.service.d.ts +23 -0
  281. package/dist/core/sdd/services/frontend-gap.service.js +117 -0
  282. package/dist/core/sdd/services/frontend-impact.service.d.ts +19 -0
  283. package/dist/core/sdd/services/frontend-impact.service.js +46 -0
  284. package/dist/core/sdd/services/ingest-deposito.service.d.ts +32 -0
  285. package/dist/core/sdd/services/ingest-deposito.service.js +231 -0
  286. package/dist/core/sdd/services/insight.service.d.ts +21 -0
  287. package/dist/core/sdd/services/insight.service.js +81 -0
  288. package/dist/core/sdd/services/legacy-capability.service.d.ts +24 -0
  289. package/dist/core/sdd/services/legacy-capability.service.js +59 -0
  290. package/dist/core/sdd/services/mcp-runtime.service.d.ts +42 -0
  291. package/dist/core/sdd/services/mcp-runtime.service.js +144 -0
  292. package/dist/core/sdd/services/metrics.service.d.ts +49 -0
  293. package/dist/core/sdd/services/metrics.service.js +181 -0
  294. package/dist/core/sdd/services/next.service.d.ts +35 -0
  295. package/dist/core/sdd/services/next.service.js +54 -0
  296. package/dist/core/sdd/services/onboard.service.d.ts +9 -0
  297. package/dist/core/sdd/services/onboard.service.js +165 -0
  298. package/dist/core/sdd/services/rebuild.service.d.ts +31 -0
  299. package/dist/core/sdd/services/rebuild.service.js +482 -0
  300. package/dist/core/sdd/services/scan-naming.service.d.ts +43 -0
  301. package/dist/core/sdd/services/scan-naming.service.js +246 -0
  302. package/dist/core/sdd/services/skills-invoke.service.d.ts +24 -0
  303. package/dist/core/sdd/services/skills-invoke.service.js +63 -0
  304. package/dist/core/sdd/services/skills-sync.service.d.ts +15 -0
  305. package/dist/core/sdd/services/skills-sync.service.js +117 -0
  306. package/dist/core/sdd/services/start.service.d.ts +26 -0
  307. package/dist/core/sdd/services/start.service.js +237 -0
  308. package/dist/core/sdd/skills.d.ts +15 -0
  309. package/dist/core/sdd/skills.js +46 -0
  310. package/dist/core/sdd/state-lock.d.ts +19 -0
  311. package/dist/core/sdd/state-lock.js +144 -0
  312. package/dist/core/sdd/state.d.ts +155 -0
  313. package/dist/core/sdd/state.js +1000 -0
  314. package/dist/core/sdd/store/in-memory-adapter.d.ts +12 -0
  315. package/dist/core/sdd/store/in-memory-adapter.js +27 -0
  316. package/dist/core/sdd/store/index.d.ts +5 -0
  317. package/dist/core/sdd/store/index.js +5 -0
  318. package/dist/core/sdd/store/sdd-stores.d.ts +25 -0
  319. package/dist/core/sdd/store/sdd-stores.js +59 -0
  320. package/dist/core/sdd/store/state-store.d.ts +32 -0
  321. package/dist/core/sdd/store/state-store.js +2 -0
  322. package/dist/core/sdd/store/yaml-file-adapter.d.ts +12 -0
  323. package/dist/core/sdd/store/yaml-file-adapter.js +43 -0
  324. package/dist/core/sdd/structural-health.d.ts +557 -0
  325. package/dist/core/sdd/structural-health.js +187 -0
  326. package/dist/core/sdd/transaction.d.ts +14 -0
  327. package/dist/core/sdd/transaction.js +100 -0
  328. package/dist/core/sdd/types.d.ts +1570 -0
  329. package/dist/core/sdd/types.js +617 -0
  330. package/dist/core/sdd/views.d.ts +3 -0
  331. package/dist/core/sdd/views.js +560 -0
  332. package/dist/core/sdd/workspace-schemas.d.ts +620 -0
  333. package/dist/core/sdd/workspace-schemas.js +254 -0
  334. package/dist/core/sdd/write-manifest.d.ts +25 -0
  335. package/dist/core/sdd/write-manifest.js +353 -0
  336. package/dist/core/shared/index.d.ts +8 -0
  337. package/dist/core/shared/index.js +8 -0
  338. package/dist/core/shared/skill-generation.d.ts +49 -0
  339. package/dist/core/shared/skill-generation.js +106 -0
  340. package/dist/core/shared/tool-detection.d.ts +71 -0
  341. package/dist/core/shared/tool-detection.js +158 -0
  342. package/dist/core/specs-apply.d.ts +73 -0
  343. package/dist/core/specs-apply.js +385 -0
  344. package/dist/core/styles/palette.d.ts +7 -0
  345. package/dist/core/styles/palette.js +8 -0
  346. package/dist/core/templates/index.d.ts +8 -0
  347. package/dist/core/templates/index.js +9 -0
  348. package/dist/core/templates/skill-templates.d.ts +20 -0
  349. package/dist/core/templates/skill-templates.js +19 -0
  350. package/dist/core/templates/types.d.ts +19 -0
  351. package/dist/core/templates/types.js +5 -0
  352. package/dist/core/templates/workflows/apply-change.d.ts +10 -0
  353. package/dist/core/templates/workflows/apply-change.js +308 -0
  354. package/dist/core/templates/workflows/archive-change.d.ts +10 -0
  355. package/dist/core/templates/workflows/archive-change.js +277 -0
  356. package/dist/core/templates/workflows/bulk-archive-change.d.ts +10 -0
  357. package/dist/core/templates/workflows/bulk-archive-change.js +502 -0
  358. package/dist/core/templates/workflows/continue-change.d.ts +10 -0
  359. package/dist/core/templates/workflows/continue-change.js +232 -0
  360. package/dist/core/templates/workflows/explore.d.ts +10 -0
  361. package/dist/core/templates/workflows/explore.js +475 -0
  362. package/dist/core/templates/workflows/feedback.d.ts +9 -0
  363. package/dist/core/templates/workflows/feedback.js +108 -0
  364. package/dist/core/templates/workflows/ff-change.d.ts +10 -0
  365. package/dist/core/templates/workflows/ff-change.js +206 -0
  366. package/dist/core/templates/workflows/new-change.d.ts +10 -0
  367. package/dist/core/templates/workflows/new-change.js +151 -0
  368. package/dist/core/templates/workflows/onboard.d.ts +10 -0
  369. package/dist/core/templates/workflows/onboard.js +573 -0
  370. package/dist/core/templates/workflows/propose.d.ts +10 -0
  371. package/dist/core/templates/workflows/propose.js +224 -0
  372. package/dist/core/templates/workflows/sdd.d.ts +10 -0
  373. package/dist/core/templates/workflows/sdd.js +107 -0
  374. package/dist/core/templates/workflows/sync-specs.d.ts +10 -0
  375. package/dist/core/templates/workflows/sync-specs.js +286 -0
  376. package/dist/core/templates/workflows/verify-change.d.ts +10 -0
  377. package/dist/core/templates/workflows/verify-change.js +346 -0
  378. package/dist/core/update.d.ts +77 -0
  379. package/dist/core/update.js +538 -0
  380. package/dist/core/validation/constants.d.ts +34 -0
  381. package/dist/core/validation/constants.js +40 -0
  382. package/dist/core/validation/types.d.ts +18 -0
  383. package/dist/core/validation/types.js +2 -0
  384. package/dist/core/validation/validator.d.ts +33 -0
  385. package/dist/core/validation/validator.js +409 -0
  386. package/dist/core/view.d.ts +8 -0
  387. package/dist/core/view.js +170 -0
  388. package/dist/index.d.ts +3 -0
  389. package/dist/index.js +3 -0
  390. package/dist/prompts/searchable-multi-select.d.ts +28 -0
  391. package/dist/prompts/searchable-multi-select.js +159 -0
  392. package/dist/telemetry/config.d.ts +32 -0
  393. package/dist/telemetry/config.js +68 -0
  394. package/dist/telemetry/index.d.ts +44 -0
  395. package/dist/telemetry/index.js +207 -0
  396. package/dist/ui/ascii-patterns.d.ts +16 -0
  397. package/dist/ui/ascii-patterns.js +133 -0
  398. package/dist/ui/welcome-screen.d.ts +10 -0
  399. package/dist/ui/welcome-screen.js +146 -0
  400. package/dist/utils/change-metadata.d.ts +51 -0
  401. package/dist/utils/change-metadata.js +147 -0
  402. package/dist/utils/change-utils.d.ts +62 -0
  403. package/dist/utils/change-utils.js +121 -0
  404. package/dist/utils/command-references.d.ts +18 -0
  405. package/dist/utils/command-references.js +20 -0
  406. package/dist/utils/file-system.d.ts +36 -0
  407. package/dist/utils/file-system.js +281 -0
  408. package/dist/utils/index.d.ts +6 -0
  409. package/dist/utils/index.js +9 -0
  410. package/dist/utils/interactive.d.ts +18 -0
  411. package/dist/utils/interactive.js +21 -0
  412. package/dist/utils/item-discovery.d.ts +4 -0
  413. package/dist/utils/item-discovery.js +73 -0
  414. package/dist/utils/match.d.ts +3 -0
  415. package/dist/utils/match.js +22 -0
  416. package/dist/utils/openspec-compat.d.ts +2 -0
  417. package/dist/utils/openspec-compat.js +2 -0
  418. package/dist/utils/shell-detection.d.ts +20 -0
  419. package/dist/utils/shell-detection.js +41 -0
  420. package/dist/utils/task-progress.d.ts +8 -0
  421. package/dist/utils/task-progress.js +36 -0
  422. package/package.json +111 -0
  423. package/schemas/sdd/1-spec.schema.json +221 -0
  424. package/schemas/sdd/2-plan.schema.json +199 -0
  425. package/schemas/sdd/3-tasks.schema.json +102 -0
  426. package/schemas/sdd/4-changelog.schema.json +55 -0
  427. package/schemas/sdd/5-quality.schema.json +427 -0
  428. package/schemas/sdd/workspace-catalog.schema.json +1012 -0
  429. package/schemas/spec-driven/schema.yaml +153 -0
  430. package/schemas/spec-driven/templates/design.md +19 -0
  431. package/schemas/spec-driven/templates/proposal.md +23 -0
  432. package/schemas/spec-driven/templates/spec.md +8 -0
  433. package/schemas/spec-driven/templates/tasks.md +9 -0
@@ -0,0 +1,1000 @@
1
+ import path from 'node:path';
2
+ import { promises as fs } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
5
+ import { resolveOpenSpecLiveSubpath } from './services/legacy-capability.service.js';
6
+ import { ArchitectureStateSchema, BacklogStateSchema, DiscoveryIndexStateSchema, FinalizeQueueStateSchema, IntegrationContractsStateSchema, FrontendDecisionsStateSchema, UnblockEventsStateSchema, TransitionLogStateSchema, AuditHistoryStateSchema, FrontendGapsStateSchema, FrontendMapStateSchema, RepoMapStateSchema, SourceIndexStateSchema, SkillCatalogStateSchema, SkillRoutingStateSchema, ServiceCatalogStateSchema, TechStackStateSchema, TechDebtStateSchema, NamingContractStateSchema, } from './types.js';
7
+ import { CLI_NAME } from '../branding.js';
8
+ import { DEFAULT_CURATED_SKILL_CATALOG, BUILT_IN_SDD_SKILLS, buildCuratedBundlesMarkdown, } from './default-skills.js';
9
+ import { buildSddInternalReadme, PROMPT_00_COMECE_POR_AQUI_MD, PROMPT_01_INGESTAO_DEPOSITO_MD, PROMPT_02_NORMALIZAR_PLANEJAMENTO_MD, PROMPT_03_EXECUCAO_FEATURE_MD, PROMPT_04_CONSOLIDACAO_FINALIZE_MD, PROMPTS_README_MD, TEMPLATE_1_SPEC_MD, TEMPLATE_2_PLAN_MD, TEMPLATE_QUALITY_MD, TEMPLATE_3_TASKS_MD, TEMPLATE_4_CHANGELOG_MD, } from './default-bootstrap-files.js';
10
+ import { SddWriteTransaction } from './transaction.js';
11
+ const LEGACY_LAYOUT_FOLDERS = {
12
+ discovery: 'discovery',
13
+ planning: 'pendencias',
14
+ skills: 'skills',
15
+ templates: 'templates',
16
+ deposito: 'deposito',
17
+ planned: 'planned',
18
+ active: 'active',
19
+ archived: 'archived',
20
+ };
21
+ const EN_US_LAYOUT_FOLDERS = {
22
+ discovery: 'discovery',
23
+ planning: 'planning',
24
+ skills: 'skills',
25
+ templates: 'templates',
26
+ deposito: 'sources',
27
+ planned: 'planned',
28
+ active: 'active',
29
+ archived: 'archived',
30
+ };
31
+ const PT_BR_LAYOUT_FOLDERS = {
32
+ discovery: 'descoberta',
33
+ planning: 'planejamento',
34
+ skills: 'habilidades',
35
+ templates: 'modelos',
36
+ deposito: 'deposito',
37
+ planned: 'planejados',
38
+ active: 'execucao',
39
+ archived: 'arquivados',
40
+ };
41
+ function skillSubfoldersForLayout(layout) {
42
+ if (layout === 'pt-BR') {
43
+ return { curated: 'skills', bundles: 'pacotes' };
44
+ }
45
+ return { curated: 'curated', bundles: 'bundles' };
46
+ }
47
+ function defaultFoldersForLayout(layout) {
48
+ if (layout === 'pt-BR') {
49
+ return { ...PT_BR_LAYOUT_FOLDERS };
50
+ }
51
+ if (layout === 'en-US') {
52
+ return { ...EN_US_LAYOUT_FOLDERS };
53
+ }
54
+ return { ...LEGACY_LAYOUT_FOLDERS };
55
+ }
56
+ const DEFAULT_SDD_CONFIG = {
57
+ enabled: true,
58
+ memoryDir: '.sdd',
59
+ language: 'pt-BR',
60
+ layout: 'legacy',
61
+ folders: defaultFoldersForLayout('legacy'),
62
+ frontend: { enabled: false },
63
+ views: { autoRender: true },
64
+ };
65
+ const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../');
66
+ const CANONICAL_FOLDER_OPTIONS = {
67
+ 'en-US': {
68
+ discovery: ['discovery'],
69
+ planning: ['planning'],
70
+ skills: ['skills'],
71
+ templates: ['templates'],
72
+ deposito: ['sources'],
73
+ planned: ['planned'],
74
+ active: ['active'],
75
+ archived: ['archived'],
76
+ },
77
+ legacy: {
78
+ discovery: ['discovery'],
79
+ planning: ['pendencias'],
80
+ skills: ['skills'],
81
+ templates: ['templates'],
82
+ deposito: ['deposito'],
83
+ planned: ['planned'],
84
+ active: ['active'],
85
+ archived: ['archived'],
86
+ },
87
+ 'pt-BR': {
88
+ discovery: ['descoberta'],
89
+ planning: ['planejamento'],
90
+ skills: ['habilidades'],
91
+ templates: ['modelos'],
92
+ deposito: ['deposito'],
93
+ planned: ['planejados'],
94
+ active: ['execucao'],
95
+ archived: ['arquivados'],
96
+ },
97
+ };
98
+ function isRecord(value) {
99
+ return !!value && typeof value === 'object' && !Array.isArray(value);
100
+ }
101
+ function mergeRuntimeConfig(raw) {
102
+ if (!isRecord(raw)) {
103
+ return {
104
+ ...DEFAULT_SDD_CONFIG,
105
+ folders: { ...DEFAULT_SDD_CONFIG.folders },
106
+ frontend: { enabled: false },
107
+ views: { autoRender: true },
108
+ };
109
+ }
110
+ const frontend = isRecord(raw.frontend) ? raw.frontend : {};
111
+ const views = isRecord(raw.views) ? raw.views : {};
112
+ const language = raw.language === 'en-US' ? 'en-US' : 'pt-BR';
113
+ const layout = raw.layout === 'pt-BR' ? 'pt-BR' : raw.layout === 'en-US' ? 'en-US' : 'legacy';
114
+ const folderDefaults = defaultFoldersForLayout(layout);
115
+ const rawFolders = isRecord(raw.folders) ? raw.folders : {};
116
+ // compatibilidade retroativa para nome legado "pendencias"
117
+ const legacyPlanning = typeof rawFolders.pendencias === 'string' && rawFolders.pendencias.trim().length > 0
118
+ ? rawFolders.pendencias.trim()
119
+ : '';
120
+ const planningFolder = typeof rawFolders.planning === 'string' && rawFolders.planning.trim().length > 0
121
+ ? rawFolders.planning.trim()
122
+ : legacyPlanning || folderDefaults.planning;
123
+ return {
124
+ enabled: typeof raw.enabled === 'boolean' ? raw.enabled : DEFAULT_SDD_CONFIG.enabled,
125
+ memoryDir: typeof raw.memoryDir === 'string' && raw.memoryDir.trim().length > 0
126
+ ? raw.memoryDir.trim()
127
+ : DEFAULT_SDD_CONFIG.memoryDir,
128
+ language,
129
+ layout,
130
+ folders: {
131
+ discovery: typeof rawFolders.discovery === 'string' && rawFolders.discovery.trim().length > 0
132
+ ? rawFolders.discovery.trim()
133
+ : folderDefaults.discovery,
134
+ planning: planningFolder,
135
+ skills: typeof rawFolders.skills === 'string' && rawFolders.skills.trim().length > 0
136
+ ? rawFolders.skills.trim()
137
+ : folderDefaults.skills,
138
+ templates: typeof rawFolders.templates === 'string' && rawFolders.templates.trim().length > 0
139
+ ? rawFolders.templates.trim()
140
+ : folderDefaults.templates,
141
+ deposito: typeof rawFolders.deposito === 'string' && rawFolders.deposito.trim().length > 0
142
+ ? rawFolders.deposito.trim()
143
+ : folderDefaults.deposito,
144
+ planned: typeof rawFolders.planned === 'string' && rawFolders.planned.trim().length > 0
145
+ ? rawFolders.planned.trim()
146
+ : folderDefaults.planned,
147
+ active: typeof rawFolders.active === 'string' && rawFolders.active.trim().length > 0
148
+ ? rawFolders.active.trim()
149
+ : folderDefaults.active,
150
+ archived: typeof rawFolders.archived === 'string' && rawFolders.archived.trim().length > 0
151
+ ? rawFolders.archived.trim()
152
+ : folderDefaults.archived,
153
+ },
154
+ frontend: {
155
+ enabled: typeof frontend.enabled === 'boolean'
156
+ ? frontend.enabled
157
+ : DEFAULT_SDD_CONFIG.frontend.enabled,
158
+ },
159
+ views: {
160
+ autoRender: typeof views.autoRender === 'boolean'
161
+ ? views.autoRender
162
+ : DEFAULT_SDD_CONFIG.views.autoRender,
163
+ },
164
+ };
165
+ }
166
+ function validateRuntimeConfig(config) {
167
+ const allowed = CANONICAL_FOLDER_OPTIONS[config.layout];
168
+ const invalidEntries = Object.entries(config.folders).flatMap(([key, value]) => {
169
+ const folderKey = key;
170
+ const accepted = allowed[folderKey];
171
+ if (!accepted)
172
+ throw new Error("Missing allowed for key: " + folderKey + " value: " + value + " allowed: " + JSON.stringify(allowed));
173
+ if (accepted.includes(value)) {
174
+ return [];
175
+ }
176
+ return [`${folderKey}="${value}" (permitidos: ${accepted.join(', ')})`];
177
+ });
178
+ if (invalidEntries.length > 0) {
179
+ throw new Error(`Configuracao SDD invalida em .sdd/config.yaml: folders fora do canonico para layout ${config.layout}: ${invalidEntries.join('; ')}`);
180
+ }
181
+ }
182
+ function defaultRuntimeConfig() {
183
+ return {
184
+ ...DEFAULT_SDD_CONFIG,
185
+ folders: { ...DEFAULT_SDD_CONFIG.folders },
186
+ frontend: { enabled: DEFAULT_SDD_CONFIG.frontend.enabled },
187
+ views: { autoRender: DEFAULT_SDD_CONFIG.views.autoRender },
188
+ };
189
+ }
190
+ async function fileExists(filePath) {
191
+ try {
192
+ await fs.access(filePath);
193
+ return true;
194
+ }
195
+ catch {
196
+ return false;
197
+ }
198
+ }
199
+ async function ensureDir(dirPath) {
200
+ await fs.mkdir(dirPath, { recursive: true });
201
+ }
202
+ async function firstExistingFile(paths) {
203
+ for (const filePath of paths) {
204
+ if (await fileExists(filePath)) {
205
+ return filePath;
206
+ }
207
+ }
208
+ return null;
209
+ }
210
+ async function readYamlObject(filePath) {
211
+ const parsed = parseYaml(await fs.readFile(filePath, 'utf-8'));
212
+ return isRecord(parsed) ? parsed : {};
213
+ }
214
+ function buildSddConfigDocument(existing, config) {
215
+ const next = { ...existing };
216
+ delete next.sdd;
217
+ next.version = typeof next.version === 'number' ? next.version : 1;
218
+ next.state_version = typeof next.state_version === 'number' ? next.state_version : 2;
219
+ next.generatedBy =
220
+ typeof next.generatedBy === 'string' && !next.generatedBy.startsWith('openspec ')
221
+ ? next.generatedBy
222
+ : `${CLI_NAME} sdd init`;
223
+ next.meta_evolution = isRecord(next.meta_evolution)
224
+ ? next.meta_evolution
225
+ : {
226
+ enabled: true,
227
+ audit_interval_days: 180,
228
+ placeholder_markers: ['(fill in', '(placeholder', 'TODO:', 'TBD:'],
229
+ health_alert_threshold: 75,
230
+ };
231
+ next.language = config.language;
232
+ next.enabled = config.enabled;
233
+ next.memoryDir = config.memoryDir;
234
+ next.layout = config.layout;
235
+ next.folders = { ...config.folders };
236
+ next.frontend = { enabled: config.frontend.enabled };
237
+ next.views = { autoRender: config.views.autoRender };
238
+ return next;
239
+ }
240
+ async function removeSddRuntimeConfigFromOpenSpecConfig(projectRoot) {
241
+ const legacyConfigPath = await firstExistingFile([
242
+ resolveOpenSpecLiveSubpath(projectRoot, 'config.yaml'),
243
+ resolveOpenSpecLiveSubpath(projectRoot, 'config.yml'),
244
+ ]);
245
+ if (!legacyConfigPath) {
246
+ return;
247
+ }
248
+ const legacyRoot = await readYamlObject(legacyConfigPath);
249
+ if (!Object.prototype.hasOwnProperty.call(legacyRoot, 'sdd')) {
250
+ return;
251
+ }
252
+ delete legacyRoot.sdd;
253
+ await fs.writeFile(legacyConfigPath, stringifyYaml(legacyRoot), 'utf-8');
254
+ }
255
+ export async function loadProjectSddConfig(projectRoot) {
256
+ const configPath = await firstExistingFile([
257
+ path.join(projectRoot, DEFAULT_SDD_CONFIG.memoryDir, 'config.yaml'),
258
+ path.join(projectRoot, DEFAULT_SDD_CONFIG.memoryDir, 'config.yml'),
259
+ ]);
260
+ if (configPath) {
261
+ const config = mergeRuntimeConfig(await readYamlObject(configPath));
262
+ validateRuntimeConfig(config);
263
+ return config;
264
+ }
265
+ const legacyConfigPath = await firstExistingFile([
266
+ resolveOpenSpecLiveSubpath(projectRoot, 'config.yaml'),
267
+ resolveOpenSpecLiveSubpath(projectRoot, 'config.yml'),
268
+ ]);
269
+ if (legacyConfigPath) {
270
+ const legacyRoot = await readYamlObject(legacyConfigPath);
271
+ const config = mergeRuntimeConfig(legacyRoot.sdd);
272
+ validateRuntimeConfig(config);
273
+ return config;
274
+ }
275
+ const config = defaultRuntimeConfig();
276
+ validateRuntimeConfig(config);
277
+ return config;
278
+ }
279
+ export async function upsertProjectSddConfig(projectRoot, overrides) {
280
+ const sddDir = path.join(projectRoot, DEFAULT_SDD_CONFIG.memoryDir);
281
+ await ensureDir(sddDir);
282
+ const configPath = (await firstExistingFile([
283
+ path.join(sddDir, 'config.yaml'),
284
+ path.join(sddDir, 'config.yml'),
285
+ ])) ?? path.join(sddDir, 'config.yaml');
286
+ let rootConfig = {};
287
+ if (await fileExists(configPath)) {
288
+ rootConfig = await readYamlObject(configPath);
289
+ }
290
+ else {
291
+ const legacyConfigPath = await firstExistingFile([
292
+ resolveOpenSpecLiveSubpath(projectRoot, 'config.yaml'),
293
+ resolveOpenSpecLiveSubpath(projectRoot, 'config.yml'),
294
+ ]);
295
+ if (legacyConfigPath) {
296
+ const legacyRoot = await readYamlObject(legacyConfigPath);
297
+ rootConfig = isRecord(legacyRoot.sdd) ? legacyRoot.sdd : {};
298
+ }
299
+ }
300
+ const mergedSdd = mergeRuntimeConfig(rootConfig);
301
+ if (overrides?.frontendEnabled !== undefined) {
302
+ mergedSdd.frontend.enabled = overrides.frontendEnabled;
303
+ }
304
+ if (overrides?.language) {
305
+ mergedSdd.language = overrides.language;
306
+ }
307
+ if (overrides?.layout) {
308
+ mergedSdd.layout = overrides.layout;
309
+ mergedSdd.folders = defaultFoldersForLayout(overrides.layout);
310
+ }
311
+ validateRuntimeConfig(mergedSdd);
312
+ await fs.writeFile(configPath, stringifyYaml(buildSddConfigDocument(rootConfig, mergedSdd)), 'utf-8');
313
+ await removeSddRuntimeConfigFromOpenSpecConfig(projectRoot);
314
+ return mergedSdd;
315
+ }
316
+ export function resolveSddPaths(projectRoot, config) {
317
+ const memoryRoot = path.resolve(projectRoot, config.memoryDir);
318
+ const stateDir = path.join(memoryRoot, 'state');
319
+ const discoveryDir = path.join(memoryRoot, config.folders.discovery);
320
+ const pendenciasDir = path.join(memoryRoot, config.folders.planning);
321
+ const skillsDir = path.join(memoryRoot, config.folders.skills);
322
+ const skillSubfolders = skillSubfoldersForLayout(config.layout);
323
+ const skillsCuratedDir = path.join(skillsDir, skillSubfolders.curated);
324
+ const skillsBundlesDir = path.join(skillsDir, skillSubfolders.bundles);
325
+ const templatesDir = path.join(memoryRoot, config.folders.templates);
326
+ const promptsDir = path.join(memoryRoot, 'prompts');
327
+ const depositoDir = path.join(memoryRoot, config.folders.deposito);
328
+ const plannedDir = path.join(memoryRoot, config.folders.planned);
329
+ const activeDir = path.join(memoryRoot, config.folders.active);
330
+ const archivedDir = path.join(memoryRoot, config.folders.archived);
331
+ const discoveryInsightsDir = path.join(discoveryDir, '1-insights');
332
+ const discoveryDebatesDir = path.join(discoveryDir, '2-debates');
333
+ const discoveryEpicDir = path.join(discoveryDir, '3-epic');
334
+ // Mantemos a chave legada por compatibilidade interna, mas novos projetos
335
+ // devem materializar apenas a pasta canonica `3-epic`.
336
+ const discoveryRadarDir = discoveryEpicDir;
337
+ const discoveryDiscardedDir = path.join(discoveryDir, '4-discarded');
338
+ return {
339
+ projectRoot,
340
+ memoryRoot,
341
+ configFile: path.join(memoryRoot, 'config.yaml'),
342
+ coreDir: path.join(memoryRoot, 'core'),
343
+ discoveryDir,
344
+ pendenciasDir,
345
+ stateDir,
346
+ skillsDir,
347
+ skillsCuratedDir,
348
+ skillsBundlesDir,
349
+ skillsCuratedFolderName: skillSubfolders.curated,
350
+ skillsBundlesFolderName: skillSubfolders.bundles,
351
+ templatesDir,
352
+ promptsDir,
353
+ depositoDir,
354
+ plannedDir,
355
+ activeDir,
356
+ archivedDir,
357
+ discoveryInsightsDir,
358
+ discoveryDebatesDir,
359
+ discoveryRadarDir,
360
+ discoveryEpicDir,
361
+ discoveryDiscardedDir,
362
+ stateFiles: {
363
+ discoveryIndex: path.join(stateDir, 'discovery-index.yaml'),
364
+ backlog: path.join(stateDir, 'backlog.yaml'),
365
+ techDebt: path.join(stateDir, 'tech-debt.yaml'),
366
+ finalizeQueue: path.join(stateDir, 'finalize-queue.yaml'),
367
+ skillCatalog: path.join(stateDir, 'skill-catalog.yaml'),
368
+ unblockEvents: path.join(stateDir, 'unblock-events.yaml'),
369
+ transitionLog: path.join(stateDir, 'transition-log.yaml'),
370
+ auditHistory: path.join(stateDir, 'audit-history.yaml'),
371
+ frontendGaps: path.join(stateDir, 'frontend-gaps.yaml'),
372
+ frontendMap: path.join(stateDir, 'frontend-map.yaml'),
373
+ architecture: path.join(stateDir, 'architecture.yaml'),
374
+ serviceCatalog: path.join(stateDir, 'service-catalog.yaml'),
375
+ techStack: path.join(stateDir, 'tech-stack.yaml'),
376
+ integrationContracts: path.join(stateDir, 'integration-contracts.yaml'),
377
+ frontendDecisions: path.join(stateDir, 'frontend-decisions.yaml'),
378
+ repoMap: path.join(stateDir, 'repo-map.yaml'),
379
+ sourceIndex: path.join(stateDir, 'source-index.yaml'),
380
+ skillRouting: path.join(stateDir, 'skill-routing.yaml'),
381
+ namingContract: path.join(stateDir, 'naming-contract.yaml'),
382
+ },
383
+ };
384
+ }
385
+ export async function ensureBaseStructure(paths) {
386
+ await Promise.all([
387
+ ensureDir(paths.memoryRoot),
388
+ ensureDir(paths.coreDir),
389
+ ensureDir(paths.discoveryDir),
390
+ ensureDir(paths.pendenciasDir),
391
+ ensureDir(paths.stateDir),
392
+ ensureDir(paths.plannedDir),
393
+ ensureDir(paths.activeDir),
394
+ ensureDir(paths.archivedDir),
395
+ ensureDir(paths.skillsDir),
396
+ ensureDir(paths.skillsCuratedDir),
397
+ ensureDir(paths.skillsBundlesDir),
398
+ ensureDir(paths.templatesDir),
399
+ ensureDir(paths.promptsDir),
400
+ ensureDir(paths.discoveryInsightsDir),
401
+ ensureDir(paths.discoveryDebatesDir),
402
+ ensureDir(paths.discoveryRadarDir),
403
+ ensureDir(paths.discoveryEpicDir),
404
+ ensureDir(paths.discoveryDiscardedDir),
405
+ ensureDir(path.join(paths.coreDir, 'dados')),
406
+ ensureDir(path.join(paths.coreDir, 'integracoes')),
407
+ ensureDir(path.join(paths.coreDir, 'adrs')),
408
+ ensureDir(paths.depositoDir),
409
+ ensureDir(path.join(paths.depositoDir, 'prds')),
410
+ ensureDir(path.join(paths.depositoDir, 'rfcs')),
411
+ ensureDir(path.join(paths.depositoDir, 'briefings')),
412
+ ensureDir(path.join(paths.depositoDir, 'historias')),
413
+ ensureDir(path.join(paths.depositoDir, 'wireframes')),
414
+ ensureDir(path.join(paths.depositoDir, 'html-mocks')),
415
+ ensureDir(path.join(paths.depositoDir, 'referencias-visuais')),
416
+ ensureDir(path.join(paths.depositoDir, 'entrevistas')),
417
+ ensureDir(path.join(paths.depositoDir, 'anexos')),
418
+ ensureDir(path.join(paths.depositoDir, 'legado')),
419
+ ]);
420
+ }
421
+ async function writeYamlIfMissing(filePath, content) {
422
+ if (await fileExists(filePath)) {
423
+ return;
424
+ }
425
+ await fs.writeFile(filePath, stringifyYaml(content), 'utf-8');
426
+ }
427
+ async function writeFileIfMissing(filePath, content) {
428
+ if (await fileExists(filePath)) {
429
+ return;
430
+ }
431
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
432
+ await fs.writeFile(filePath, content, 'utf-8');
433
+ }
434
+ function isBuiltInSkillSourceTree(definition) {
435
+ return (typeof definition === 'object' &&
436
+ definition !== null &&
437
+ 'kind' in definition &&
438
+ definition.kind === 'source-tree');
439
+ }
440
+ function adaptSkillContentForLayout(content, paths, config) {
441
+ if (config.layout === 'en-US') {
442
+ return content;
443
+ }
444
+ const sourceRoot = `${path.basename(paths.memoryRoot)}/${config.folders.deposito}`;
445
+ return content
446
+ .replaceAll('.sdd/sources', sourceRoot)
447
+ .replaceAll('/stories/', '/historias/')
448
+ .replaceAll('/visual-references/', '/referencias-visuais/')
449
+ .replaceAll('/interviews/', '/entrevistas/')
450
+ .replaceAll('/attachments/', '/anexos/')
451
+ .replaceAll('/legacy/', '/legado/');
452
+ }
453
+ async function listTreeFiles(rootDir) {
454
+ async function walk(currentDir, relativePrefix) {
455
+ const entries = await fs.readdir(currentDir, { withFileTypes: true });
456
+ const files = [];
457
+ for (const entry of entries) {
458
+ if (entry.name.startsWith('.')) {
459
+ continue;
460
+ }
461
+ const relativePath = relativePrefix ? `${relativePrefix}/${entry.name}` : entry.name;
462
+ const absolutePath = path.join(currentDir, entry.name);
463
+ if (entry.isDirectory()) {
464
+ files.push(...(await walk(absolutePath, relativePath)));
465
+ continue;
466
+ }
467
+ if (entry.isFile()) {
468
+ files.push(relativePath.replace(/\\/g, '/'));
469
+ }
470
+ }
471
+ return files;
472
+ }
473
+ const files = await walk(rootDir, '');
474
+ files.sort((a, b) => a.localeCompare(b));
475
+ return files;
476
+ }
477
+ async function resolveBuiltInSourceRoot(paths, sourceRoot) {
478
+ const normalized = sourceRoot.trim();
479
+ if (!normalized) {
480
+ return null;
481
+ }
482
+ const candidates = path.isAbsolute(normalized)
483
+ ? [path.resolve(normalized)]
484
+ : [path.resolve(paths.projectRoot, normalized), path.resolve(PACKAGE_ROOT, normalized)];
485
+ for (const candidate of candidates) {
486
+ try {
487
+ const stats = await fs.stat(candidate);
488
+ if (stats.isDirectory()) {
489
+ return candidate;
490
+ }
491
+ }
492
+ catch {
493
+ // candidate not available; try next
494
+ }
495
+ }
496
+ return null;
497
+ }
498
+ async function materializeBuiltInSkill(paths, config, skillId, definition) {
499
+ if (typeof definition === 'string') {
500
+ const materializedContent = adaptSkillContentForLayout(definition, paths, config);
501
+ await writeFileIfMissing(path.join(paths.skillsCuratedDir, skillId, 'SKILL.md'), materializedContent);
502
+ return;
503
+ }
504
+ if (isBuiltInSkillSourceTree(definition)) {
505
+ const sourceRoot = await resolveBuiltInSourceRoot(paths, definition.sourceRoot);
506
+ if (!sourceRoot) {
507
+ return;
508
+ }
509
+ const files = await listTreeFiles(sourceRoot);
510
+ for (const relativePath of files) {
511
+ const sourceFile = path.join(sourceRoot, relativePath);
512
+ const targetFile = path.join(paths.skillsCuratedDir, skillId, relativePath);
513
+ const content = await fs.readFile(sourceFile, 'utf-8');
514
+ await writeFileIfMissing(targetFile, adaptSkillContentForLayout(content, paths, config));
515
+ }
516
+ return;
517
+ }
518
+ for (const [relativePath, content] of Object.entries(definition)) {
519
+ if (relativePath.trim().length === 0) {
520
+ continue;
521
+ }
522
+ const targetFile = path.join(paths.skillsCuratedDir, skillId, relativePath);
523
+ await writeFileIfMissing(targetFile, adaptSkillContentForLayout(content, paths, config));
524
+ }
525
+ }
526
+ async function ensureCuratedSkillCatalog(filePath) {
527
+ if (!(await fileExists(filePath))) {
528
+ await fs.writeFile(filePath, stringifyYaml(DEFAULT_CURATED_SKILL_CATALOG), 'utf-8');
529
+ return;
530
+ }
531
+ const parsed = SkillCatalogStateSchema.safeParse(await readYaml(filePath));
532
+ if (!parsed.success) {
533
+ return;
534
+ }
535
+ const existing = parsed.data;
536
+ if (existing.skills.length === 0 && existing.bundles.length === 0) {
537
+ await fs.writeFile(filePath, stringifyYaml(DEFAULT_CURATED_SKILL_CATALOG), 'utf-8');
538
+ return;
539
+ }
540
+ const skillById = new Map(existing.skills.map((entry) => [entry.id, entry]));
541
+ let changed = false;
542
+ for (const defaultSkill of DEFAULT_CURATED_SKILL_CATALOG.skills) {
543
+ if (!skillById.has(defaultSkill.id)) {
544
+ skillById.set(defaultSkill.id, defaultSkill);
545
+ changed = true;
546
+ }
547
+ }
548
+ const bundleById = new Map(existing.bundles.map((entry) => [entry.id, entry]));
549
+ for (const defaultBundle of DEFAULT_CURATED_SKILL_CATALOG.bundles) {
550
+ const existingBundle = bundleById.get(defaultBundle.id);
551
+ if (!existingBundle) {
552
+ bundleById.set(defaultBundle.id, defaultBundle);
553
+ changed = true;
554
+ continue;
555
+ }
556
+ const mergedSkillIds = Array.from(new Set([...existingBundle.skill_ids, ...defaultBundle.skill_ids]));
557
+ if (mergedSkillIds.length !== existingBundle.skill_ids.length) {
558
+ bundleById.set(defaultBundle.id, {
559
+ ...existingBundle,
560
+ skill_ids: mergedSkillIds,
561
+ });
562
+ changed = true;
563
+ }
564
+ }
565
+ if (changed) {
566
+ await fs.writeFile(filePath, stringifyYaml({
567
+ version: 1,
568
+ skills: Array.from(skillById.values()).sort((a, b) => a.id.localeCompare(b.id)),
569
+ bundles: Array.from(bundleById.values()).sort((a, b) => a.id.localeCompare(b.id)),
570
+ }), 'utf-8');
571
+ }
572
+ }
573
+ export async function ensureBaseFiles(paths, config) {
574
+ await writeYamlIfMissing(paths.configFile, {
575
+ version: 1,
576
+ state_version: 2,
577
+ generatedBy: `${CLI_NAME} sdd init`,
578
+ meta_evolution: {
579
+ enabled: true,
580
+ audit_interval_days: 180,
581
+ placeholder_markers: ['(fill in', '(placeholder', 'TODO:', 'TBD:'],
582
+ health_alert_threshold: 75,
583
+ },
584
+ language: config.language,
585
+ layout: config.layout,
586
+ folders: config.folders,
587
+ frontend: { enabled: config.frontend.enabled },
588
+ views: { autoRender: config.views.autoRender },
589
+ });
590
+ await writeYamlIfMissing(paths.stateFiles.discoveryIndex, {
591
+ version: 1,
592
+ counters: { INS: 0, DEB: 0, RAD: 0, EPIC: 0, FEAT: 0, FGAP: 0, TD: 0 },
593
+ records: [],
594
+ });
595
+ await writeYamlIfMissing(paths.stateFiles.backlog, { version: 1, items: [] });
596
+ await writeYamlIfMissing(paths.stateFiles.techDebt, { version: 1, items: [] });
597
+ await writeYamlIfMissing(paths.stateFiles.finalizeQueue, { version: 1, items: [] });
598
+ await ensureCuratedSkillCatalog(paths.stateFiles.skillCatalog);
599
+ await writeYamlIfMissing(paths.stateFiles.unblockEvents, { version: 1, events: [] });
600
+ await writeYamlIfMissing(paths.stateFiles.transitionLog, { version: 1, events: [] });
601
+ await writeYamlIfMissing(paths.stateFiles.auditHistory, { version: 1, runs: [] });
602
+ await writeYamlIfMissing(paths.stateFiles.architecture, { version: 1, nodes: [] });
603
+ await writeYamlIfMissing(paths.stateFiles.serviceCatalog, { version: 1, services: [] });
604
+ await writeYamlIfMissing(paths.stateFiles.techStack, { version: 1, items: [] });
605
+ await writeYamlIfMissing(paths.stateFiles.integrationContracts, { version: 1, contracts: [] });
606
+ await writeYamlIfMissing(paths.stateFiles.repoMap, { version: 1, items: [] });
607
+ await writeYamlIfMissing(paths.stateFiles.sourceIndex, {
608
+ version: 1,
609
+ sources: [],
610
+ version_events: [],
611
+ jurisdiction_profiles: [],
612
+ control_catalog: [],
613
+ });
614
+ await writeYamlIfMissing(paths.stateFiles.skillRouting, {
615
+ version: 1,
616
+ default_skills: ['architecture', 'concise-planning', 'context-window-management'],
617
+ routes: [
618
+ { domain: 'backend', skills: ['architecture', 'api-design-principles'], bundles: [] },
619
+ { domain: 'api', skills: ['api-design-principles', 'api-clean-flask-langgraph'], bundles: ['python-agentic-backend'] },
620
+ { domain: 'python', skills: ['api-clean-flask-langgraph', 'architecture'], bundles: ['python-agentic-backend'] },
621
+ { domain: 'flask', skills: ['api-clean-flask-langgraph'], bundles: ['python-agentic-backend'] },
622
+ { domain: 'nestjs', skills: ['devtrack-api', 'architecture'], bundles: ['architecture-backend'] },
623
+ { domain: 'typeorm', skills: ['devtrack-api', 'database-design'], bundles: ['architecture-backend'] },
624
+ { domain: 'devtrack', skills: ['devtrack-api'], bundles: ['architecture-backend'] },
625
+ { domain: 'frontend', skills: ['frontend-design', 'react-patterns'], bundles: [] },
626
+ { domain: 'infra', skills: ['terraform-specialist', 'docker-expert'], bundles: [] }
627
+ ]
628
+ });
629
+ if (config.frontend.enabled) {
630
+ await writeYamlIfMissing(paths.stateFiles.frontendGaps, { version: 1, items: [] });
631
+ await writeYamlIfMissing(paths.stateFiles.frontendMap, { version: 1, routes: [] });
632
+ await writeYamlIfMissing(paths.stateFiles.frontendDecisions, { version: 1, items: [] });
633
+ }
634
+ await writeFileIfMissing(path.join(paths.coreDir, 'arquitetura.md'), '# Architecture\n\nHigh-level project architecture document.\n');
635
+ await writeFileIfMissing(path.join(paths.memoryRoot, 'README.md'), buildSddInternalReadme(path.basename(paths.memoryRoot), {
636
+ discovery: config.folders.discovery,
637
+ planning: config.folders.planning,
638
+ skills: config.folders.skills,
639
+ templates: config.folders.templates,
640
+ active: config.folders.active,
641
+ deposito: config.folders.deposito,
642
+ prompts: 'prompts',
643
+ }));
644
+ await writeFileIfMissing(path.join(paths.skillsBundlesDir, config.layout === 'en-US' ? 'curation-en-us.md' : 'curadoria-pt-br.md'), buildCuratedBundlesMarkdown());
645
+ for (const [skillId, definition] of Object.entries(BUILT_IN_SDD_SKILLS)) {
646
+ await materializeBuiltInSkill(paths, config, skillId, definition);
647
+ }
648
+ await writeFileIfMissing(path.join(paths.depositoDir, 'README.md'), `# Raw Sources\n\nThis folder stores PRDs, RFCs, wireframes, HTML mockups, visual references, interviews, and other consolidated inputs.\n\nRule: nothing here is canonical state. The official inventory lives in \`.sdd/state/source-index.yaml\`.\n`);
649
+ await writeFileIfMissing(path.join(paths.promptsDir, 'README.md'), PROMPTS_README_MD);
650
+ const promptNames = config.layout === 'en-US'
651
+ ? [
652
+ ['00-start-here.md', PROMPT_00_COMECE_POR_AQUI_MD],
653
+ ['01-source-intake.md', PROMPT_01_INGESTAO_DEPOSITO_MD],
654
+ ['02-normalize-planning.md', PROMPT_02_NORMALIZAR_PLANEJAMENTO_MD],
655
+ ['03-feature-execution.md', PROMPT_03_EXECUCAO_FEATURE_MD],
656
+ ['04-finalize-consolidation.md', PROMPT_04_CONSOLIDACAO_FINALIZE_MD],
657
+ ]
658
+ : [
659
+ ['00-comece-por-aqui.md', PROMPT_00_COMECE_POR_AQUI_MD],
660
+ ['01-ingestao-deposito.md', PROMPT_01_INGESTAO_DEPOSITO_MD],
661
+ ['02-normalizar-planejamento.md', PROMPT_02_NORMALIZAR_PLANEJAMENTO_MD],
662
+ ['03-execucao-feature.md', PROMPT_03_EXECUCAO_FEATURE_MD],
663
+ ['04-consolidacao-finalize.md', PROMPT_04_CONSOLIDACAO_FINALIZE_MD],
664
+ ];
665
+ for (const [name, content] of promptNames) {
666
+ await writeFileIfMissing(path.join(paths.promptsDir, name), content);
667
+ }
668
+ await writeFileIfMissing(path.join(paths.templatesDir, 'template-1-spec.yaml'), TEMPLATE_1_SPEC_MD);
669
+ await writeFileIfMissing(path.join(paths.templatesDir, 'template-2-plan.yaml'), TEMPLATE_2_PLAN_MD);
670
+ await writeFileIfMissing(path.join(paths.templatesDir, 'template-5-quality.yaml'), TEMPLATE_QUALITY_MD);
671
+ await writeFileIfMissing(path.join(paths.templatesDir, 'template-3-tasks.yaml'), TEMPLATE_3_TASKS_MD);
672
+ await writeFileIfMissing(path.join(paths.templatesDir, 'template-4-changelog.yaml'), TEMPLATE_4_CHANGELOG_MD);
673
+ if (config.layout === 'pt-BR') {
674
+ await writeFileIfMissing(path.join(paths.templatesDir, 'modelo-1-especificacao.yaml'), TEMPLATE_1_SPEC_MD);
675
+ await writeFileIfMissing(path.join(paths.templatesDir, 'modelo-2-planejamento.yaml'), TEMPLATE_2_PLAN_MD);
676
+ await writeFileIfMissing(path.join(paths.templatesDir, 'modelo-5-quality.yaml'), TEMPLATE_QUALITY_MD);
677
+ await writeFileIfMissing(path.join(paths.templatesDir, 'modelo-3-tarefas.yaml'), TEMPLATE_3_TASKS_MD);
678
+ await writeFileIfMissing(path.join(paths.templatesDir, 'modelo-4-historico.yaml'), TEMPLATE_4_CHANGELOG_MD);
679
+ }
680
+ }
681
+ async function readYaml(filePath) {
682
+ const content = await fs.readFile(filePath, 'utf-8');
683
+ return parseYaml(content);
684
+ }
685
+ async function writeYaml(filePath, value) {
686
+ const tx = new SddWriteTransaction();
687
+ tx.writeFile(filePath, stringifyYaml(value));
688
+ await tx.commit();
689
+ }
690
+ export async function loadStateSnapshot(paths, config) {
691
+ const discoveryIndex = DiscoveryIndexStateSchema.parse(await readYaml(paths.stateFiles.discoveryIndex));
692
+ const backlog = BacklogStateSchema.parse(await readYaml(paths.stateFiles.backlog));
693
+ const techDebt = TechDebtStateSchema.parse(await readYaml(paths.stateFiles.techDebt));
694
+ const finalizeQueue = FinalizeQueueStateSchema.parse(await readYaml(paths.stateFiles.finalizeQueue));
695
+ const skillCatalog = SkillCatalogStateSchema.parse(await readYaml(paths.stateFiles.skillCatalog));
696
+ const unblockEvents = UnblockEventsStateSchema.parse(await readYaml(paths.stateFiles.unblockEvents));
697
+ const transitionLog = TransitionLogStateSchema.parse(await readYaml(paths.stateFiles.transitionLog));
698
+ const auditHistory = AuditHistoryStateSchema.parse(await readYaml(paths.stateFiles.auditHistory).catch(() => ({ version: 1, runs: [] })));
699
+ const architecture = ArchitectureStateSchema.parse(await readYaml(paths.stateFiles.architecture));
700
+ const serviceCatalog = ServiceCatalogStateSchema.parse(await readYaml(paths.stateFiles.serviceCatalog));
701
+ const techStack = TechStackStateSchema.parse(await readYaml(paths.stateFiles.techStack));
702
+ const integrationContracts = IntegrationContractsStateSchema.parse(await readYaml(paths.stateFiles.integrationContracts));
703
+ const repoMap = RepoMapStateSchema.parse(await readYaml(paths.stateFiles.repoMap));
704
+ const sourceIndex = SourceIndexStateSchema.parse(await readYaml(paths.stateFiles.sourceIndex));
705
+ let skillRouting;
706
+ try {
707
+ skillRouting = SkillRoutingStateSchema.parse(await readYaml(paths.stateFiles.skillRouting));
708
+ }
709
+ catch (e) {
710
+ skillRouting = {
711
+ version: 1,
712
+ default_skills: ['architecture', 'concise-planning', 'context-window-management'],
713
+ routes: [
714
+ { domain: 'backend', skills: ['architecture', 'api-design-principles'], bundles: [] },
715
+ { domain: 'api', skills: ['api-design-principles', 'api-clean-flask-langgraph'], bundles: ['python-agentic-backend'] },
716
+ { domain: 'python', skills: ['api-clean-flask-langgraph', 'architecture'], bundles: ['python-agentic-backend'] },
717
+ { domain: 'flask', skills: ['api-clean-flask-langgraph'], bundles: ['python-agentic-backend'] },
718
+ { domain: 'nestjs', skills: ['devtrack-api', 'architecture'], bundles: ['architecture-backend'] },
719
+ { domain: 'typeorm', skills: ['devtrack-api', 'database-design'], bundles: ['architecture-backend'] },
720
+ { domain: 'devtrack', skills: ['devtrack-api'], bundles: ['architecture-backend'] }
721
+ ]
722
+ };
723
+ }
724
+ let frontendGaps;
725
+ let frontendMap;
726
+ let frontendDecisions;
727
+ if (config.frontend.enabled) {
728
+ frontendGaps = FrontendGapsStateSchema.parse(await readYaml(paths.stateFiles.frontendGaps));
729
+ frontendMap = FrontendMapStateSchema.parse(await readYaml(paths.stateFiles.frontendMap));
730
+ frontendDecisions = FrontendDecisionsStateSchema.parse(await readYaml(paths.stateFiles.frontendDecisions));
731
+ }
732
+ return {
733
+ discoveryIndex,
734
+ backlog,
735
+ techDebt,
736
+ finalizeQueue,
737
+ skillCatalog,
738
+ unblockEvents,
739
+ transitionLog,
740
+ auditHistory,
741
+ frontendGaps,
742
+ frontendMap,
743
+ architecture,
744
+ serviceCatalog,
745
+ techStack,
746
+ integrationContracts,
747
+ frontendDecisions,
748
+ repoMap,
749
+ sourceIndex,
750
+ skillRouting,
751
+ };
752
+ }
753
+ export async function loadSkillCatalogState(paths) {
754
+ return SkillCatalogStateSchema.parse(await readYaml(paths.stateFiles.skillCatalog));
755
+ }
756
+ function formatCounterId(prefix, value) {
757
+ return `${prefix}-${String(value).padStart(4, '0')}`;
758
+ }
759
+ export function nowIso() {
760
+ return new Date().toISOString();
761
+ }
762
+ export async function saveDiscoveryIndexState(paths, state) {
763
+ await writeYaml(paths.stateFiles.discoveryIndex, state);
764
+ }
765
+ export async function saveBacklogState(paths, state) {
766
+ await writeYaml(paths.stateFiles.backlog, state);
767
+ }
768
+ export async function saveTechDebtState(paths, state) {
769
+ await writeYaml(paths.stateFiles.techDebt, state);
770
+ }
771
+ export async function saveFinalizeQueueState(paths, state) {
772
+ await writeYaml(paths.stateFiles.finalizeQueue, state);
773
+ }
774
+ export async function saveSkillCatalogState(paths, state) {
775
+ await writeYaml(paths.stateFiles.skillCatalog, state);
776
+ }
777
+ export async function saveUnblockEventsState(paths, state) {
778
+ await writeYaml(paths.stateFiles.unblockEvents, state);
779
+ }
780
+ export async function saveTransitionLogState(paths, state) {
781
+ await writeYaml(paths.stateFiles.transitionLog, state);
782
+ }
783
+ export async function saveFrontendGapsState(paths, state) {
784
+ await writeYaml(paths.stateFiles.frontendGaps, state);
785
+ }
786
+ export async function saveFrontendMapState(paths, state) {
787
+ await writeYaml(paths.stateFiles.frontendMap, state);
788
+ }
789
+ export async function saveArchitectureState(paths, state) {
790
+ await writeYaml(paths.stateFiles.architecture, state);
791
+ }
792
+ export async function saveServiceCatalogState(paths, state) {
793
+ await writeYaml(paths.stateFiles.serviceCatalog, state);
794
+ }
795
+ export async function saveTechStackState(paths, state) {
796
+ await writeYaml(paths.stateFiles.techStack, state);
797
+ }
798
+ export async function saveIntegrationContractsState(paths, state) {
799
+ await writeYaml(paths.stateFiles.integrationContracts, state);
800
+ }
801
+ export async function saveFrontendDecisionsState(paths, state) {
802
+ await writeYaml(paths.stateFiles.frontendDecisions, state);
803
+ }
804
+ export async function saveRepoMapState(paths, state) {
805
+ await writeYaml(paths.stateFiles.repoMap, state);
806
+ }
807
+ export async function saveSourceIndexState(paths, state) {
808
+ await writeYaml(paths.stateFiles.sourceIndex, state);
809
+ }
810
+ export function defaultNamingContractState() {
811
+ const sharedAllowlist = [
812
+ '.sdd/archived/**',
813
+ '.sdd/sources/legado/**',
814
+ '.sdd/discovery/**',
815
+ 'test/core/sdd/fixtures/**',
816
+ ];
817
+ return {
818
+ version: 1,
819
+ product_name: 'CodeSDD',
820
+ cli_bin: 'codesdd',
821
+ package_name: '@devtrack-solution/codesdd',
822
+ current_identity: {
823
+ product_name: 'CodeSDD',
824
+ cli_bin: 'codesdd',
825
+ package_name: '@devtrack-solution/codesdd',
826
+ },
827
+ target_identity: {
828
+ product_name: 'CodeSDD',
829
+ cli_bin: 'codesdd',
830
+ package_name: '@devtrack-solution/codesdd',
831
+ },
832
+ forbidden_terms: [
833
+ { term: 'openspec', scope: 'all', severity: 'warning', allowlist_paths: [...sharedAllowlist] },
834
+ { term: 'OpenSpec', scope: 'all', severity: 'warning', allowlist_paths: [...sharedAllowlist] },
835
+ { term: 'openSpec', scope: 'all', severity: 'warning', allowlist_paths: [...sharedAllowlist] },
836
+ ],
837
+ allowlist: [
838
+ { path_pattern: '.sdd/archived/**', reason: 'Archived SDD artifacts retain legacy terminology', owner: 'sdd-core' },
839
+ { path_pattern: '.sdd/sources/legacy/spec-corpus/**', reason: 'Legacy OpenSpec import sources', owner: 'sdd-core' },
840
+ { path_pattern: 'node_modules/**', reason: 'Third-party dependencies', owner: 'sdd-core' },
841
+ { path_pattern: 'dist/**', reason: 'Build output', owner: 'sdd-core' },
842
+ { path_pattern: 'coverage/**', reason: 'Test coverage artifacts', owner: 'sdd-core' },
843
+ { path_pattern: '.git/**', reason: 'Git internals', owner: 'sdd-core' },
844
+ ],
845
+ rename_rules: [
846
+ {
847
+ from: 'OpenSDD',
848
+ to: 'CodeSDD',
849
+ scope: 'all',
850
+ phase: 'identity-introduction',
851
+ owner: 'sdd-core',
852
+ status: 'planned',
853
+ path_globs: ['README.md', 'docs/**', 'src/**', 'test/**', '.sdd/state/**'],
854
+ },
855
+ {
856
+ from: 'opensdd',
857
+ to: 'codesdd',
858
+ scope: 'all',
859
+ phase: 'identity-introduction',
860
+ owner: 'sdd-core',
861
+ status: 'planned',
862
+ path_globs: ['package.json', 'bin/**', 'src/**', 'test/**', 'docs/**'],
863
+ },
864
+ {
865
+ from: '@devtrack-solution/codesdd',
866
+ to: '@devtrack-solution/codesdd',
867
+ scope: 'all',
868
+ phase: 'package-identity',
869
+ owner: 'sdd-core',
870
+ status: 'planned',
871
+ path_globs: ['package.json', 'README.md', 'docs/**', 'test/**'],
872
+ },
873
+ ],
874
+ zero_residue_gate: {
875
+ enabled: true,
876
+ enforcement: 'warning',
877
+ terms: ['openspec', 'OpenSpec', 'openSpec', 'opensdd', 'OpenSDD', 'openSDD'],
878
+ allowlist_paths: [...sharedAllowlist],
879
+ removal_phase: 'compatibility-shutdown',
880
+ },
881
+ updated_at: nowIso(),
882
+ };
883
+ }
884
+ export async function loadNamingContractState(paths) {
885
+ if (!(await fileExists(paths.stateFiles.namingContract))) {
886
+ return defaultNamingContractState();
887
+ }
888
+ try {
889
+ return NamingContractStateSchema.parse(await readYaml(paths.stateFiles.namingContract));
890
+ }
891
+ catch {
892
+ return defaultNamingContractState();
893
+ }
894
+ }
895
+ export async function saveNamingContractState(paths, state) {
896
+ await writeYaml(paths.stateFiles.namingContract, state);
897
+ }
898
+ export async function saveStateTransaction(paths, updates) {
899
+ const tx = new SddWriteTransaction();
900
+ if (updates.discoveryIndex) {
901
+ tx.writeFile(paths.stateFiles.discoveryIndex, stringifyYaml(updates.discoveryIndex));
902
+ }
903
+ if (updates.backlog) {
904
+ tx.writeFile(paths.stateFiles.backlog, stringifyYaml(updates.backlog));
905
+ }
906
+ if (updates.techDebt) {
907
+ tx.writeFile(paths.stateFiles.techDebt, stringifyYaml(updates.techDebt));
908
+ }
909
+ if (updates.finalizeQueue) {
910
+ tx.writeFile(paths.stateFiles.finalizeQueue, stringifyYaml(updates.finalizeQueue));
911
+ }
912
+ if (updates.skillCatalog) {
913
+ tx.writeFile(paths.stateFiles.skillCatalog, stringifyYaml(updates.skillCatalog));
914
+ }
915
+ if (updates.unblockEvents) {
916
+ tx.writeFile(paths.stateFiles.unblockEvents, stringifyYaml(updates.unblockEvents));
917
+ }
918
+ if (updates.transitionLog) {
919
+ tx.writeFile(paths.stateFiles.transitionLog, stringifyYaml(updates.transitionLog));
920
+ }
921
+ if (updates.auditHistory) {
922
+ tx.writeFile(paths.stateFiles.auditHistory, stringifyYaml(updates.auditHistory));
923
+ }
924
+ if (updates.frontendGaps) {
925
+ tx.writeFile(paths.stateFiles.frontendGaps, stringifyYaml(updates.frontendGaps));
926
+ }
927
+ if (updates.frontendMap) {
928
+ tx.writeFile(paths.stateFiles.frontendMap, stringifyYaml(updates.frontendMap));
929
+ }
930
+ if (updates.architecture) {
931
+ tx.writeFile(paths.stateFiles.architecture, stringifyYaml(updates.architecture));
932
+ }
933
+ if (updates.serviceCatalog) {
934
+ tx.writeFile(paths.stateFiles.serviceCatalog, stringifyYaml(updates.serviceCatalog));
935
+ }
936
+ if (updates.techStack) {
937
+ tx.writeFile(paths.stateFiles.techStack, stringifyYaml(updates.techStack));
938
+ }
939
+ if (updates.integrationContracts) {
940
+ tx.writeFile(paths.stateFiles.integrationContracts, stringifyYaml(updates.integrationContracts));
941
+ }
942
+ if (updates.frontendDecisions) {
943
+ tx.writeFile(paths.stateFiles.frontendDecisions, stringifyYaml(updates.frontendDecisions));
944
+ }
945
+ if (updates.repoMap) {
946
+ tx.writeFile(paths.stateFiles.repoMap, stringifyYaml(updates.repoMap));
947
+ }
948
+ if (updates.sourceIndex) {
949
+ tx.writeFile(paths.stateFiles.sourceIndex, stringifyYaml(updates.sourceIndex));
950
+ }
951
+ await tx.commit();
952
+ }
953
+ /**
954
+ * Allocates a new entity ID with atomic reservation and collision detection.
955
+ * Verifies that the generated ID does not already exist in the discovery index
956
+ * records before persisting. Retries with the next counter value if collision
957
+ * is detected (defensive against manual edits or stale counters).
958
+ *
959
+ * @param paths - SDD directory paths
960
+ * @param type - Counter type (INS, DEB, RAD, EPIC, FEAT, FGAP, TD)
961
+ * @returns The reserved ID string
962
+ */
963
+ export async function allocateEntityId(paths, type) {
964
+ const discoveryIndex = DiscoveryIndexStateSchema.parse(await readYaml(paths.stateFiles.discoveryIndex));
965
+ // Build a set of all existing IDs for fast collision check
966
+ const existingIds = new Set();
967
+ for (const record of discoveryIndex.records) {
968
+ existingIds.add(record.id);
969
+ }
970
+ // Also check backlog items for FEAT collision
971
+ if (type === 'FEAT') {
972
+ try {
973
+ const backlog = BacklogStateSchema.parse(await readYaml(paths.stateFiles.backlog));
974
+ for (const item of backlog.items) {
975
+ existingIds.add(item.id);
976
+ }
977
+ }
978
+ catch {
979
+ // If backlog can't be read, proceed with discovery-only check
980
+ }
981
+ }
982
+ let candidate = (discoveryIndex.counters[type] ?? 0) + 1;
983
+ let candidateId = formatCounterId(type, candidate);
984
+ // Retry loop: advance counter until no collision
985
+ const maxRetries = 100;
986
+ let retries = 0;
987
+ while (existingIds.has(candidateId) && retries < maxRetries) {
988
+ candidate++;
989
+ candidateId = formatCounterId(type, candidate);
990
+ retries++;
991
+ }
992
+ if (retries >= maxRetries) {
993
+ throw new Error(`Falha ao alocar ID para ${type}: ${maxRetries} colisoes consecutivas detectadas. Verifique o estado do discovery-index.`);
994
+ }
995
+ // Persist the updated counter
996
+ discoveryIndex.counters[type] = candidate;
997
+ await saveDiscoveryIndexState(paths, discoveryIndex);
998
+ return candidateId;
999
+ }
1000
+ //# sourceMappingURL=state.js.map