create-yss-spec 3.1.0 → 3.2.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 (302) hide show
  1. package/README.md +119 -89
  2. package/bin/create-yss-spec.js +11 -3
  3. package/package.json +9 -2
  4. package/src/api/_sync-service.js +191 -0
  5. package/src/api/index.js +22 -0
  6. package/src/api/project-diff.js +9 -0
  7. package/src/api/project-doctor.js +10 -0
  8. package/src/api/template-apply.js +10 -0
  9. package/src/api/template-plan.js +9 -0
  10. package/src/cli/args.js +60 -0
  11. package/src/cli/error-output.js +52 -0
  12. package/src/cli/flags.js +9 -0
  13. package/src/cli/help.js +95 -0
  14. package/src/cli/index.js +82 -0
  15. package/src/cli/plan-output.js +61 -0
  16. package/src/cli/prompts.js +91 -0
  17. package/src/cli/router.js +41 -0
  18. package/src/cli.js +5 -2253
  19. package/src/commands/attach.js +280 -0
  20. package/src/commands/diff.js +23 -0
  21. package/src/commands/doctor.js +417 -0
  22. package/src/commands/init.js +193 -0
  23. package/src/commands/sync.js +146 -0
  24. package/src/commands/update.js +14 -0
  25. package/src/contracts/apply-result-v1.json +45 -0
  26. package/src/contracts/customization-policy-v1.json +28 -0
  27. package/src/contracts/doctor-report-v1.json +29 -0
  28. package/src/contracts/error-envelope-v1.json +24 -0
  29. package/src/contracts/generator-policy-v1.json +24 -0
  30. package/src/contracts/ownership-policy-v1.json +40 -0
  31. package/src/contracts/plan-schema-v1.json +115 -0
  32. package/src/family-identity.js +365 -0
  33. package/src/family-runtime.js +23 -0
  34. package/src/filesystem/apply-plan.js +44 -0
  35. package/src/filesystem/copy-path.js +28 -0
  36. package/src/filesystem/path-utils.js +67 -0
  37. package/src/filesystem/transaction-runner.js +41 -0
  38. package/src/filesystem/transaction.js +153 -0
  39. package/src/git/submodule.js +115 -0
  40. package/src/git/worktree.js +69 -0
  41. package/src/template/attach-planner-runtime.js +51 -0
  42. package/src/template/attach-planner.js +160 -0
  43. package/src/template/instance-runtime.js +463 -0
  44. package/src/template/lifecycle-metadata.js +99 -0
  45. package/src/template/lifecycle-policy.js +129 -0
  46. package/src/template/lifecycle-runtime.js +90 -0
  47. package/src/template/migration-planner.js +95 -0
  48. package/src/template/migration-runtime.js +247 -0
  49. package/src/template/ownership-metadata.js +79 -0
  50. package/src/template/ownership-policy.js +149 -0
  51. package/src/template/ownership-runtime.js +109 -0
  52. package/src/template/plan-schema.js +36 -0
  53. package/src/template/sync-planner-runtime.js +57 -0
  54. package/src/template/sync-planner.js +206 -0
  55. package/src/template/verification-runtime.js +154 -0
  56. package/src/validation/identity.js +41 -0
  57. package/src/validation/metadata.js +105 -0
  58. package/src/validation/security.js +67 -0
  59. package/src/validation/snapshot.js +47 -0
  60. package/template/.agents/skills/.strategic-design-skills-manifest.json +1 -1
  61. package/template/.agents/skills/yss-domain/SKILL.md +3 -3
  62. package/template/.agents/skills/yss-frontend-scaffold-generator/SKILL.md +2 -0
  63. package/template/.agents/skills/yss-implementation-contract-compiler/SKILL.md +4 -2
  64. package/template/.agents/skills/yss-implementation-contract-compiler/references/boundaries.md +5 -0
  65. package/template/.agents/skills/yss-implementation-contract-compiler/references/compiler-contract.yaml +16 -2
  66. package/template/.agents/skills/yss-implementation-contract-compiler/references/slice-implementation-contract.md +10 -1
  67. package/template/.agents/skills/yss-mvc-design/SKILL.md +16 -0
  68. package/template/.agents/skills/yss-mvc-design/agents/openai.yaml +4 -0
  69. package/template/.agents/skills/yss-mvc-design/references/mvc-design.schema.json +315 -0
  70. package/template/.agents/skills/yss-product-lifecycle/SKILL.md +4 -2
  71. package/template/.agents/skills/yss-product-lifecycle/references/artifact-dependencies.md +2 -2
  72. package/template/.agents/skills/yss-product-lifecycle/references/orchestration-contract.yaml +14 -9
  73. package/template/.agents/skills/yss-product-lifecycle/references/orchestration.md +1 -1
  74. package/template/.agents/skills/yss-product-lifecycle/references/state-model.md +1 -1
  75. package/template/.agents/skills/yss-tactical-design/SKILL.md +2 -2
  76. package/template/.agents/skills/yss-tactical-design/references/output-template.md +2 -0
  77. package/template/.agents/skills/yss-tactical-design/references/tactical-design-contract.md +3 -1
  78. package/template/.agents/skills/yss-tactical-design/scripts/validate-tactical-design.mjs +3 -2
  79. package/template/.agents/skills/yss-technical-design/SKILL.md +31 -0
  80. package/template/.agents/skills/yss-technical-design/agents/openai.yaml +4 -0
  81. package/template/.agents/skills/yss-technical-design/references/technical-design-common.schema.json +290 -0
  82. package/template/.agents/skills/yss-technical-design/references/technical-design-contract.md +31 -0
  83. package/template/.agents/skills/yss-technical-design/references/technical-design.schema.json +759 -0
  84. package/template/.agents/skills/yss-technical-design/scripts/generate-schema.mjs +20 -0
  85. package/template/.agents/skills/yss-technical-design/scripts/validate-technical-design.mjs +134 -0
  86. package/template/.agents/skills/yss-technical-design/tests/fixtures.mjs +32 -0
  87. package/template/.agents/skills/yss-technical-design/tests/run-scenarios.mjs +82 -0
  88. package/template/.agents/skills/yss-ui/SKILL.md +2 -0
  89. package/template/.claude/skills/yss-domain/SKILL.md +3 -3
  90. package/template/.claude/skills/yss-frontend-scaffold-generator/SKILL.md +2 -0
  91. package/template/.claude/skills/yss-implementation-contract-compiler/SKILL.md +4 -2
  92. package/template/.claude/skills/yss-implementation-contract-compiler/references/boundaries.md +5 -0
  93. package/template/.claude/skills/yss-implementation-contract-compiler/references/compiler-contract.yaml +16 -2
  94. package/template/.claude/skills/yss-implementation-contract-compiler/references/slice-implementation-contract.md +10 -1
  95. package/template/.claude/skills/yss-mvc-design/SKILL.md +16 -0
  96. package/template/.claude/skills/yss-mvc-design/agents/openai.yaml +4 -0
  97. package/template/.claude/skills/yss-mvc-design/references/mvc-design.schema.json +315 -0
  98. package/template/.claude/skills/yss-product-lifecycle/SKILL.md +4 -2
  99. package/template/.claude/skills/yss-product-lifecycle/references/artifact-dependencies.md +2 -2
  100. package/template/.claude/skills/yss-product-lifecycle/references/orchestration-contract.yaml +14 -9
  101. package/template/.claude/skills/yss-product-lifecycle/references/orchestration.md +1 -1
  102. package/template/.claude/skills/yss-product-lifecycle/references/state-model.md +1 -1
  103. package/template/.claude/skills/yss-tactical-design/SKILL.md +2 -2
  104. package/template/.claude/skills/yss-tactical-design/references/output-template.md +2 -0
  105. package/template/.claude/skills/yss-tactical-design/references/tactical-design-contract.md +3 -1
  106. package/template/.claude/skills/yss-tactical-design/scripts/validate-tactical-design.mjs +3 -2
  107. package/template/.claude/skills/yss-technical-design/SKILL.md +31 -0
  108. package/template/.claude/skills/yss-technical-design/agents/openai.yaml +4 -0
  109. package/template/.claude/skills/yss-technical-design/references/technical-design-common.schema.json +290 -0
  110. package/template/.claude/skills/yss-technical-design/references/technical-design-contract.md +31 -0
  111. package/template/.claude/skills/yss-technical-design/references/technical-design.schema.json +759 -0
  112. package/template/.claude/skills/yss-technical-design/scripts/generate-schema.mjs +20 -0
  113. package/template/.claude/skills/yss-technical-design/scripts/validate-technical-design.mjs +134 -0
  114. package/template/.claude/skills/yss-technical-design/tests/fixtures.mjs +32 -0
  115. package/template/.claude/skills/yss-technical-design/tests/run-scenarios.mjs +82 -0
  116. package/template/.claude/skills/yss-ui/SKILL.md +2 -0
  117. package/template/.codex/skills/yss-domain/SKILL.md +3 -3
  118. package/template/.codex/skills/yss-frontend-scaffold-generator/SKILL.md +2 -0
  119. package/template/.codex/skills/yss-implementation-contract-compiler/SKILL.md +4 -2
  120. package/template/.codex/skills/yss-implementation-contract-compiler/references/boundaries.md +5 -0
  121. package/template/.codex/skills/yss-implementation-contract-compiler/references/compiler-contract.yaml +16 -2
  122. package/template/.codex/skills/yss-implementation-contract-compiler/references/slice-implementation-contract.md +10 -1
  123. package/template/.codex/skills/yss-mvc-design/SKILL.md +16 -0
  124. package/template/.codex/skills/yss-mvc-design/agents/openai.yaml +4 -0
  125. package/template/.codex/skills/yss-mvc-design/references/mvc-design.schema.json +315 -0
  126. package/template/.codex/skills/yss-product-lifecycle/SKILL.md +4 -2
  127. package/template/.codex/skills/yss-product-lifecycle/references/artifact-dependencies.md +2 -2
  128. package/template/.codex/skills/yss-product-lifecycle/references/orchestration-contract.yaml +14 -9
  129. package/template/.codex/skills/yss-product-lifecycle/references/orchestration.md +1 -1
  130. package/template/.codex/skills/yss-product-lifecycle/references/state-model.md +1 -1
  131. package/template/.codex/skills/yss-tactical-design/SKILL.md +2 -2
  132. package/template/.codex/skills/yss-tactical-design/references/output-template.md +2 -0
  133. package/template/.codex/skills/yss-tactical-design/references/tactical-design-contract.md +3 -1
  134. package/template/.codex/skills/yss-tactical-design/scripts/validate-tactical-design.mjs +3 -2
  135. package/template/.codex/skills/yss-technical-design/SKILL.md +31 -0
  136. package/template/.codex/skills/yss-technical-design/agents/openai.yaml +4 -0
  137. package/template/.codex/skills/yss-technical-design/references/technical-design-common.schema.json +290 -0
  138. package/template/.codex/skills/yss-technical-design/references/technical-design-contract.md +31 -0
  139. package/template/.codex/skills/yss-technical-design/references/technical-design.schema.json +759 -0
  140. package/template/.codex/skills/yss-technical-design/scripts/generate-schema.mjs +20 -0
  141. package/template/.codex/skills/yss-technical-design/scripts/validate-technical-design.mjs +134 -0
  142. package/template/.codex/skills/yss-technical-design/tests/fixtures.mjs +32 -0
  143. package/template/.codex/skills/yss-technical-design/tests/run-scenarios.mjs +82 -0
  144. package/template/.codex/skills/yss-ui/SKILL.md +2 -0
  145. package/template/.cursor/skills/yss-domain/SKILL.md +3 -3
  146. package/template/.cursor/skills/yss-frontend-scaffold-generator/SKILL.md +2 -0
  147. package/template/.cursor/skills/yss-implementation-contract-compiler/SKILL.md +4 -2
  148. package/template/.cursor/skills/yss-implementation-contract-compiler/references/boundaries.md +5 -0
  149. package/template/.cursor/skills/yss-implementation-contract-compiler/references/compiler-contract.yaml +16 -2
  150. package/template/.cursor/skills/yss-implementation-contract-compiler/references/slice-implementation-contract.md +10 -1
  151. package/template/.cursor/skills/yss-mvc-design/SKILL.md +16 -0
  152. package/template/.cursor/skills/yss-mvc-design/agents/openai.yaml +4 -0
  153. package/template/.cursor/skills/yss-mvc-design/references/mvc-design.schema.json +315 -0
  154. package/template/.cursor/skills/yss-product-lifecycle/SKILL.md +4 -2
  155. package/template/.cursor/skills/yss-product-lifecycle/references/artifact-dependencies.md +2 -2
  156. package/template/.cursor/skills/yss-product-lifecycle/references/orchestration-contract.yaml +14 -9
  157. package/template/.cursor/skills/yss-product-lifecycle/references/orchestration.md +1 -1
  158. package/template/.cursor/skills/yss-product-lifecycle/references/state-model.md +1 -1
  159. package/template/.cursor/skills/yss-tactical-design/SKILL.md +2 -2
  160. package/template/.cursor/skills/yss-tactical-design/references/output-template.md +2 -0
  161. package/template/.cursor/skills/yss-tactical-design/references/tactical-design-contract.md +3 -1
  162. package/template/.cursor/skills/yss-tactical-design/scripts/validate-tactical-design.mjs +3 -2
  163. package/template/.cursor/skills/yss-technical-design/SKILL.md +31 -0
  164. package/template/.cursor/skills/yss-technical-design/agents/openai.yaml +4 -0
  165. package/template/.cursor/skills/yss-technical-design/references/technical-design-common.schema.json +290 -0
  166. package/template/.cursor/skills/yss-technical-design/references/technical-design-contract.md +31 -0
  167. package/template/.cursor/skills/yss-technical-design/references/technical-design.schema.json +759 -0
  168. package/template/.cursor/skills/yss-technical-design/scripts/generate-schema.mjs +20 -0
  169. package/template/.cursor/skills/yss-technical-design/scripts/validate-technical-design.mjs +134 -0
  170. package/template/.cursor/skills/yss-technical-design/tests/fixtures.mjs +32 -0
  171. package/template/.cursor/skills/yss-technical-design/tests/run-scenarios.mjs +82 -0
  172. package/template/.cursor/skills/yss-ui/SKILL.md +2 -0
  173. package/template/.pi/skills/yss-domain/SKILL.md +3 -3
  174. package/template/.pi/skills/yss-frontend-scaffold-generator/SKILL.md +2 -0
  175. package/template/.pi/skills/yss-implementation-contract-compiler/SKILL.md +4 -2
  176. package/template/.pi/skills/yss-implementation-contract-compiler/references/boundaries.md +5 -0
  177. package/template/.pi/skills/yss-implementation-contract-compiler/references/compiler-contract.yaml +16 -2
  178. package/template/.pi/skills/yss-implementation-contract-compiler/references/slice-implementation-contract.md +10 -1
  179. package/template/.pi/skills/yss-mvc-design/SKILL.md +16 -0
  180. package/template/.pi/skills/yss-mvc-design/agents/openai.yaml +4 -0
  181. package/template/.pi/skills/yss-mvc-design/references/mvc-design.schema.json +315 -0
  182. package/template/.pi/skills/yss-product-lifecycle/SKILL.md +4 -2
  183. package/template/.pi/skills/yss-product-lifecycle/references/artifact-dependencies.md +2 -2
  184. package/template/.pi/skills/yss-product-lifecycle/references/orchestration-contract.yaml +14 -9
  185. package/template/.pi/skills/yss-product-lifecycle/references/orchestration.md +1 -1
  186. package/template/.pi/skills/yss-product-lifecycle/references/state-model.md +1 -1
  187. package/template/.pi/skills/yss-tactical-design/SKILL.md +2 -2
  188. package/template/.pi/skills/yss-tactical-design/references/output-template.md +2 -0
  189. package/template/.pi/skills/yss-tactical-design/references/tactical-design-contract.md +3 -1
  190. package/template/.pi/skills/yss-tactical-design/scripts/validate-tactical-design.mjs +3 -2
  191. package/template/.pi/skills/yss-technical-design/SKILL.md +31 -0
  192. package/template/.pi/skills/yss-technical-design/agents/openai.yaml +4 -0
  193. package/template/.pi/skills/yss-technical-design/references/technical-design-common.schema.json +290 -0
  194. package/template/.pi/skills/yss-technical-design/references/technical-design-contract.md +31 -0
  195. package/template/.pi/skills/yss-technical-design/references/technical-design.schema.json +759 -0
  196. package/template/.pi/skills/yss-technical-design/scripts/generate-schema.mjs +20 -0
  197. package/template/.pi/skills/yss-technical-design/scripts/validate-technical-design.mjs +134 -0
  198. package/template/.pi/skills/yss-technical-design/tests/fixtures.mjs +32 -0
  199. package/template/.pi/skills/yss-technical-design/tests/run-scenarios.mjs +82 -0
  200. package/template/.pi/skills/yss-ui/SKILL.md +2 -0
  201. package/template/.qoder/skills/yss-domain/SKILL.md +3 -3
  202. package/template/.qoder/skills/yss-frontend-scaffold-generator/SKILL.md +2 -0
  203. package/template/.qoder/skills/yss-implementation-contract-compiler/SKILL.md +4 -2
  204. package/template/.qoder/skills/yss-implementation-contract-compiler/references/boundaries.md +5 -0
  205. package/template/.qoder/skills/yss-implementation-contract-compiler/references/compiler-contract.yaml +16 -2
  206. package/template/.qoder/skills/yss-implementation-contract-compiler/references/slice-implementation-contract.md +10 -1
  207. package/template/.qoder/skills/yss-mvc-design/SKILL.md +16 -0
  208. package/template/.qoder/skills/yss-mvc-design/agents/openai.yaml +4 -0
  209. package/template/.qoder/skills/yss-mvc-design/references/mvc-design.schema.json +315 -0
  210. package/template/.qoder/skills/yss-product-lifecycle/SKILL.md +4 -2
  211. package/template/.qoder/skills/yss-product-lifecycle/references/artifact-dependencies.md +2 -2
  212. package/template/.qoder/skills/yss-product-lifecycle/references/orchestration-contract.yaml +14 -9
  213. package/template/.qoder/skills/yss-product-lifecycle/references/orchestration.md +1 -1
  214. package/template/.qoder/skills/yss-product-lifecycle/references/state-model.md +1 -1
  215. package/template/.qoder/skills/yss-tactical-design/SKILL.md +2 -2
  216. package/template/.qoder/skills/yss-tactical-design/references/output-template.md +2 -0
  217. package/template/.qoder/skills/yss-tactical-design/references/tactical-design-contract.md +3 -1
  218. package/template/.qoder/skills/yss-tactical-design/scripts/validate-tactical-design.mjs +3 -2
  219. package/template/.qoder/skills/yss-technical-design/SKILL.md +31 -0
  220. package/template/.qoder/skills/yss-technical-design/agents/openai.yaml +4 -0
  221. package/template/.qoder/skills/yss-technical-design/references/technical-design-common.schema.json +290 -0
  222. package/template/.qoder/skills/yss-technical-design/references/technical-design-contract.md +31 -0
  223. package/template/.qoder/skills/yss-technical-design/references/technical-design.schema.json +759 -0
  224. package/template/.qoder/skills/yss-technical-design/scripts/generate-schema.mjs +20 -0
  225. package/template/.qoder/skills/yss-technical-design/scripts/validate-technical-design.mjs +134 -0
  226. package/template/.qoder/skills/yss-technical-design/tests/fixtures.mjs +32 -0
  227. package/template/.qoder/skills/yss-technical-design/tests/run-scenarios.mjs +82 -0
  228. package/template/.qoder/skills/yss-ui/SKILL.md +2 -0
  229. package/template/.trae/skills/yss-domain/SKILL.md +3 -3
  230. package/template/.trae/skills/yss-frontend-scaffold-generator/SKILL.md +2 -0
  231. package/template/.trae/skills/yss-implementation-contract-compiler/SKILL.md +4 -2
  232. package/template/.trae/skills/yss-implementation-contract-compiler/references/boundaries.md +5 -0
  233. package/template/.trae/skills/yss-implementation-contract-compiler/references/compiler-contract.yaml +16 -2
  234. package/template/.trae/skills/yss-implementation-contract-compiler/references/slice-implementation-contract.md +10 -1
  235. package/template/.trae/skills/yss-mvc-design/SKILL.md +16 -0
  236. package/template/.trae/skills/yss-mvc-design/agents/openai.yaml +4 -0
  237. package/template/.trae/skills/yss-mvc-design/references/mvc-design.schema.json +315 -0
  238. package/template/.trae/skills/yss-product-lifecycle/SKILL.md +4 -2
  239. package/template/.trae/skills/yss-product-lifecycle/references/artifact-dependencies.md +2 -2
  240. package/template/.trae/skills/yss-product-lifecycle/references/orchestration-contract.yaml +14 -9
  241. package/template/.trae/skills/yss-product-lifecycle/references/orchestration.md +1 -1
  242. package/template/.trae/skills/yss-product-lifecycle/references/state-model.md +1 -1
  243. package/template/.trae/skills/yss-tactical-design/SKILL.md +2 -2
  244. package/template/.trae/skills/yss-tactical-design/references/output-template.md +2 -0
  245. package/template/.trae/skills/yss-tactical-design/references/tactical-design-contract.md +3 -1
  246. package/template/.trae/skills/yss-tactical-design/scripts/validate-tactical-design.mjs +3 -2
  247. package/template/.trae/skills/yss-technical-design/SKILL.md +31 -0
  248. package/template/.trae/skills/yss-technical-design/agents/openai.yaml +4 -0
  249. package/template/.trae/skills/yss-technical-design/references/technical-design-common.schema.json +290 -0
  250. package/template/.trae/skills/yss-technical-design/references/technical-design-contract.md +31 -0
  251. package/template/.trae/skills/yss-technical-design/references/technical-design.schema.json +759 -0
  252. package/template/.trae/skills/yss-technical-design/scripts/generate-schema.mjs +20 -0
  253. package/template/.trae/skills/yss-technical-design/scripts/validate-technical-design.mjs +134 -0
  254. package/template/.trae/skills/yss-technical-design/tests/fixtures.mjs +32 -0
  255. package/template/.trae/skills/yss-technical-design/tests/run-scenarios.mjs +82 -0
  256. package/template/.trae/skills/yss-ui/SKILL.md +2 -0
  257. package/template/CONTEXT.md +4 -1
  258. package/template/README.md +4 -0
  259. package/template/docs/agents/digital-human-roles.yaml +3 -2
  260. package/template/docs/agents/yss-skill-registry.yaml +20 -1
  261. package/template/docs/architecture/templates/architecture-review-checklist.md +1 -1
  262. package/template/docs/architecture/templates/system-overview-design-template.md +15 -4
  263. package/template/docs/process/frontend-backend-delivery.md +72 -0
  264. package/template/docs/process/implementation-repo-integration.md +2 -0
  265. package/template/docs/process/lifecycle-artifact-map.md +3 -0
  266. package/template/docs/process/lifecycle-registry-baseline.json +4 -1
  267. package/template/docs/process/lifecycle-registry.yaml +14 -2
  268. package/template/docs/process/schemas/backend-delivery-verification.schema.json +113 -0
  269. package/template/docs/process/schemas/backend-delivery.schema.json +301 -0
  270. package/template/docs/process/schemas/digital-human-task-package.schema.json +8 -0
  271. package/template/docs/process/schemas/frontend-delivery-acceptance.schema.json +200 -0
  272. package/template/docs/process/schemas/frontend-implementation-evidence.schema.json +3 -0
  273. package/template/docs/process/schemas/strategic-design-handoff.schema.json +77 -4
  274. package/template/docs/process/strategic-handoff-package.md +4 -2
  275. package/template/docs/process/template-verification-profiles.yaml +20 -0
  276. package/template/docs/user-guide//346/210/230/346/234/257/350/256/276/350/256/241/345/255/220/351/241/271/347/233/256/347/224/250/346/210/267/346/211/213/345/206/214.md +21 -206
  277. package/template/docs/user-guide//347/224/250/346/210/267/346/211/213/345/206/214.md +63 -963
  278. package/template/docs/user-guide//347/224/250/346/210/267/346/211/213/345/206/214/347/264/242/345/274/225.md +11 -14
  279. package/template/docs/user-guide//350/256/276/345/244/207/345/200/237/347/224/250/350/264/257/347/251/277/346/241/210/344/276/213.md +127 -0
  280. package/template/scripts/backend-delivery +14 -0
  281. package/template/scripts/fixtures/backend-delivery/revision-server.mjs +11 -0
  282. package/template/scripts/fixtures/strategic-handoff/fixture.mjs +3 -2
  283. package/template/scripts/instantiate-harness +69 -0
  284. package/template/scripts/lib/backend-delivery.mjs +164 -0
  285. package/template/scripts/lib/frontend-delivery-boundary.mjs +49 -0
  286. package/template/scripts/lib/frontend-delivery.mjs +73 -0
  287. package/template/scripts/lib/harness-execution-scope.mjs +52 -0
  288. package/template/scripts/lib/implementation-contract-compiler.mjs +19 -2
  289. package/template/scripts/lib/lifecycle-transition.mjs +7 -0
  290. package/template/scripts/lib/strategic-handoff-consumption.mjs +17 -10
  291. package/template/scripts/lib/strategic-handoff-design-targets.mjs +15 -0
  292. package/template/scripts/lib/strategic-handoff.mjs +1 -1
  293. package/template/scripts/lib/task-package.mjs +7 -0
  294. package/template/scripts/lib/technical-design-boundary.mjs +23 -0
  295. package/template/scripts/sync-strategic-handoff-tools +5 -2
  296. package/template/scripts/verify-frontend-delivery +9 -0
  297. package/template/scripts/verify-frontend-delivery-scenarios +131 -0
  298. package/template/scripts/verify-frontend-implementation-evidence +2 -0
  299. package/template/scripts/verify-strategic-handoff-package-scenarios +7 -1
  300. package/template/skills-lock.json +43 -13
  301. package/template.manifest.json +43 -1
  302. package/template.snapshot.json +5 -5
package/README.md CHANGED
@@ -2,61 +2,53 @@
2
2
 
3
3
  用于初始化、接管已有项目并持续同步 `yss-spec-project-template` 研发管理资产的 npm CLI。
4
4
 
5
- ## 用法
5
+ 源码候选版本:`3.2.0`。当前固定模板为 `yss-spec-project-template@0347a5f6d100791cf012ef0f4ae3e148eece644a`;CLI 运行时不会拉取模板仓库。`npm create yss-spec@latest` 获取的是实际已发布 npm 包,发布版本请以 `npm view create-yss-spec version` 为准。
6
6
 
7
- ```bash
8
- npm create yss-spec@latest
9
- ```
10
-
11
- 也可以使用 `npx`:
7
+ ## 本版模板能力
12
8
 
13
- ```bash
14
- npx create-yss-spec@latest
15
- ```
9
+ 技术设计统一通过 `yss-technical-design` 进入,按已确认架构调用 DDD `yss-tactical-design` 或传统 MVC `yss-mvc-design`。新合同使用 v2,旧 DDD 合同显式兼容读取;初始化和同步会分发对应技能、Schema 与校验工具。版本升级只完成 GitHub 源码交付,npm 发布状态仍以 registry 为准。
16
10
 
17
- 查看用法、命令、参数和样例:
11
+ ## 快速开始
18
12
 
19
13
  ```bash
14
+ npm create yss-spec@latest
20
15
  npx create-yss-spec@latest --help
16
+ npx create-yss-spec@latest --version
21
17
  ```
22
18
 
23
- 查看 CLI 版本:
19
+ 候选源码示例:
24
20
 
25
21
  ```bash
26
- npx create-yss-spec@latest --version
22
+ npx create-yss-spec@latest \
23
+ --project-name "设备借用" \
24
+ --business-domain "内部设备管理" \
25
+ --target-dir ./equipment-project
27
26
  ```
28
27
 
29
- ## 当前支持
28
+ ## 五家族身份保护
30
29
 
31
- - 交互式收集 `projectName`、`businessDomain`、`targetDir`
32
- - `--team-size`
33
- - `--dry-run`
34
- - 非空目录默认拒绝,初始化命令的 `--force` 允许重新生成
35
- - `--git-init`
36
- - `--issue-tracker github|gitlab`
37
- - `--include-example-docs`
38
- - `--no-example-docs`
39
- - `attach` 子命令:在已有项目中补齐研发管理资产
40
- - `sync` 子命令
41
- - `update` / `upgrade` 子命令:检查 npm 最新版本,如有更新则安装 CLI 自身
42
- - 基于 `.yss-template.json` 的模板版本基线和 managed baseline
43
- - 只使用当前 CLI 包内置、绑定不可变 commit 的模板快照
44
- - 初始化时将 `yss-project.yaml` 从 `template-source` 改写为 `project-instance`
45
- - 接管 / 升级时迁移 Spec / Ticket 路径并删除 `to-prd`、`to-issues` 旧 skill
46
- - 旧、新资产内容冲突或清单 schema / mode 非法时 fail closed
47
- - 保留模板的共享 skill 投影;生成实例可在尚未 `git init` 时运行模板校验
48
- - init / sync 不把模板源治理笔记、wiki、审查证据、源仓 CI / Cloud 环境和公开发布清单写入项目实例;attach 会带上 `yss-public-skills.json` 供 `verify-template` 使用
49
- - 空 gitlink / detached HEAD / git-submodule 挂载点 fail closed,`--force` 也不能覆盖
30
+ CLI 在规划和写入前检查模板家族身份,当前识别:
50
31
 
51
- 本轮模板快照绑定 `yss-spec-project-template@248c1723cc0e4e88adabcf00931f78b9aa632d48`。`templateCommit` 会写入实例 metadata;“最新模板”指用户执行的 `npx create-yss-spec@latest` 所携带的最新已发布快照,CLI 运行时不会拉取模板仓库。实例会带上数字人角色叠加(`docs/agents/digital-human-roles.yaml`)、YSS 前端技能叠加层、DDD Tactical Design 与生命周期转换校验资产、唯一 `code-review` 入口及其 YSS / Alibaba 专项检查与 finding 分流合同、`.cursorrules` 与 `.agents/rules/yss-ai-skills.md`;审查临时目录 `docs/.scratch/` 与已退役的独立入口不进入快照。
32
+ - `create-yss-spec` / `.yss-template.json`
33
+ - `create-yss-harness-design` / `.yss-harness-design.json`
34
+ - `create-yss-harness-dev` / `.yss-harness-dev.json`
35
+ - repository-local backend / `.yss-harness-backend.json`
36
+ - repository-local frontend / `.yss-harness-frontend.json`
52
37
 
53
- ## 当前版本说明
38
+ `docs/process/harness-profile.yaml` 也参与身份判断。异族、多重 identity、损坏 metadata、未知或矛盾 profile、identity symlink 均在写入前 fail closed,`--force` 不能绕过;Programmatic API 使用相同 guard。帮助和版本查询不受目标家族限制。
54
39
 
55
- 当前 CLI 版本为 `3.1.0`,模板固定到 `248c1723cc0e4e88adabcf00931f78b9aa632d48`。本版本同步可离线核验的战略交接快照包、受控导入与逐条战术追溯,并强化关键决定的真实用户回复校验。
40
+ 后端/前端专职模板使用各自仓库的 `scripts/instantiate-harness --target <新目录>`,不由本 CLI 做跨家族原地迁移。
56
41
 
57
- ## 接管已有项目
42
+ ## CLI 能力
58
43
 
59
- `attach` 只处理 manifest 声明的研发管理资产,不扫描或覆盖前后端运行时代码、业务目录、用户文件和 `.git`。必须先 dry-run,再显式 apply:
44
+ - `attach`:接管已有未管理项目。
45
+ - `sync`:同步受管资产。
46
+ - `sync --dry-run`:传统文本预演。
47
+ - `sync --plan`:结构化文本计划。
48
+ - `sync --json`:Plan Schema v1。
49
+ - `diff / diff --json`:只读差异。
50
+ - `doctor / doctor --json`:只读健康诊断。
51
+ - `update / upgrade`:只更新 CLI 程序,不同步实例资产。
60
52
 
61
53
  ```bash
62
54
  npx create-yss-spec@latest attach \
@@ -69,83 +61,121 @@ npx create-yss-spec@latest attach \
69
61
  --target-dir . \
70
62
  --project-name "项目名称" \
71
63
  --business-domain "业务领域" \
72
- --apply [--force]
64
+ --apply
65
+
66
+ npx create-yss-spec@latest sync --target-dir . --dry-run
67
+ npx create-yss-spec@latest sync --target-dir .
73
68
  ```
74
69
 
75
- 规则:
70
+ 同步安全规则:
76
71
 
77
- - 目标已有 `.yss-template.json` 时拒绝接管,请使用 `sync`。
78
- - `--dry-run` 与 `--apply` 互斥;非交互执行只依赖显式参数。
79
- - 根规则文件等受管冲突默认阻断;`--force` 才覆盖,并把被覆盖文件备份到目标目录外的临时目录。
80
- - 合法 `template-source` 身份会转换为 `project-instance`;非法身份、迁移冲突和 attach 时无法判断归属的扁平 Ticket 始终阻断。
81
- - Git worktree 有脏改动时只提醒,不自动 stash 或提交。
82
- - `.gitmodules`、gitlink 和 `apps/` 挂载工作树是用户资产;空 gitlink / detached HEAD 即使 `--force` 也阻断。
72
+ - 默认只更新未被本地修改的受管文件。
73
+ - `replace-with-force` 冲突只有显式 `--force` 才覆盖。
74
+ - `manual` 冲突即使 `--force` 也不会覆盖。
75
+ - `user-owned` / `protected`、gitlink/submodule/detached HEAD、路径越界和中间 symlink 均不可被 force 绕过。
76
+ - 模板删除项只报告,不自动删除。
77
+ - 校验失败通过 FileTransaction 回滚,并保留必要备份。
83
78
 
84
- ## 同步已有模板实例仓库
79
+ ## Programmatic API v1
85
80
 
86
- 当项目仓库已经由 `create-yss-spec` 初始化,或已经通过 `attach` 接管,并且根目录存在 `.yss-template.json` 时,可以执行:
81
+ npm package 根入口已经开放稳定 Node.js API:
87
82
 
88
- ```bash
89
- npx create-yss-spec@latest sync
83
+ ```js
84
+ const {
85
+ API_VERSION,
86
+ projectDoctor,
87
+ projectDiff,
88
+ templatePlan,
89
+ templateApply,
90
+ toErrorEnvelope,
91
+ } = require("create-yss-spec");
90
92
  ```
91
93
 
92
- 只预演,不真实写入:
94
+ 当前 `API_VERSION = 1`。
93
95
 
94
- ```bash
95
- npx create-yss-spec@latest sync --dry-run
96
+ ```js
97
+ const plan = templatePlan({ targetDir: "/path/to/project" });
98
+ const report = projectDoctor({ targetDir: "/path/to/project" });
99
+ const result = templateApply({ targetDir: "/path/to/project", force: true });
96
100
  ```
97
101
 
98
- 当前同步能力的边界:
102
+ 返回合同:
99
103
 
100
- - 只支持带模板元数据的模板实例仓库
101
- - 默认只更新未被本地修改的受管模板文件
102
- - 对本地已修改文件只提示和跳过,不自动覆盖
103
- - `--force` 先备份,再覆盖受管冲突文件;不覆盖模板无关文件
104
- - 对模板已删除文件只报告,不自动删除
105
- - 对已知的 Spec / Ticket 旧路径执行一次性迁移
106
- - `docs/requirements/tickets/` 只在 attach 时检查归属;sync 不迁移、不删除,也不因其中存在 Ticket 而阻断
107
- - 迁移目标已存在且内容不一致时停止,不静默覆盖
108
- - `.gitmodules`、gitlink(mode `160000`)和 `apps/` 下已挂载实现仓是用户资产,不创建、不覆盖、不删除
109
- - init / sync 保持实例边界:不复制 `wiki/`、`.github/`、`.template-source/`、源仓库 ADR、Cursor Cloud 环境配置、`docs/reviews/` 或根 `package.json`;共享 `scripts/`、`scripts/vendor/`、`.nvmrc` 和 `.gitignore` 属于实例门禁所需资产。attach 结束后会执行 `scripts/sync-skills --check`、`scripts/update-skill-lock --check` 和 `scripts/verify-template`,门禁失败会回滚文件和 metadata
104
+ - `projectDoctor()` → Doctor Report v1
105
+ - `projectDiff()` / `templatePlan()` → Plan Schema v1
106
+ - `templateApply()` → Apply Result v1
107
+ - `toErrorEnvelope(error)` → Error Envelope v1
110
108
 
111
- ```bash
112
- npx create-yss-spec@latest sync --target-dir . --dry-run
113
- npx create-yss-spec@latest sync --target-dir . [--force]
109
+ API 不解析 argv,也不负责 CLI 文本输出;CLI 与未来 MCP 复用同一 Planner / Policy / Security / Transaction 逻辑。
110
+
111
+ ## Policy 与 metadata baseline
112
+
113
+ 当前五类 ownership:
114
+
115
+ - `managed`
116
+ - `managed-customizable`
117
+ - `generated`
118
+ - `user-owned`
119
+ - `protected`
120
+
121
+ Customization Policy v1:
122
+
123
+ - `replace-with-force`
124
+ - `manual`
125
+
126
+ Generator Policy v1 为 generated 资产记录稳定 `generatorId + generatorVersion`。
127
+
128
+ `.yss-template.json` 会持久化 ownership/customization/generator policy version/hash,以及每个 managed file 的 ownership、mergeStrategy、generatorId/generatorVersion。Doctor 会报告 policy missing/drift/matched。
129
+
130
+ ## 模块化架构
131
+
132
+ 历史约 72KB 的 `src/cli.js` 已退役为兼容桥接。当前执行模型:
133
+
134
+ ```text
135
+ CLI / Programmatic API
136
+ ↓
137
+ Inspect → Desired State → Policy → Plan → Validate → Transaction → Verify → Metadata
114
138
  ```
115
139
 
116
- ## 升级 CLI 自身
140
+ 核心机器合同:
141
+
142
+ - Plan Schema v1
143
+ - Error Envelope v1
144
+ - Doctor Report v1
145
+ - Apply Result v1
146
+ - Ownership Policy v1
147
+ - Customization Policy v1
148
+ - Generator Policy v1
117
149
 
118
- `update`(别名 `upgrade`)检查 npm registry 上的最新 `create-yss-spec` 版本,如有更新则按当前安装方式自动安装。它升级的是 CLI 包本身,不会同步项目里的模板资产;模板同步仍使用 `sync`。
150
+ ## 使用未发布候选包
151
+
152
+ 从本仓固定提交构建候选包时,先使用 `scripts/sync-template.js` 中的 `DEFAULT_TEMPLATE_REF` 重建模板快照,再打包:
119
153
 
120
154
  ```bash
121
- npx create-yss-spec update
122
- npx create-yss-spec update --dry-run
123
- npx create-yss-spec upgrade
155
+ YSS_SPEC_TEMPLATE_REPO=https://github.com/iloveZzz/yss-spec-project-template.git \
156
+ YSS_SPEC_TEMPLATE_REF=017925706a981aec9eadefd470232bb531acd4d6 \
157
+ node scripts/sync-template.js
158
+
159
+ npm pack --ignore-scripts
124
160
  ```
125
161
 
126
- - 全局安装会执行 `npm install -g create-yss-spec@latest`
127
- - 项目本地依赖会在对应项目根执行 `npm install create-yss-spec@latest`
128
- - 通过 npx 运行或在源码目录中运行时只报告版本并给出安装建议,不覆盖当前文件
129
- - `--dry-run` 只查询和预览,不安装;`--force` 在已是最新时仍重新安装(npx / 源码目录除外)
162
+ `--ignore-scripts` 仅用于已经显式重建并核对固定快照后的候选打包,不代表 npm 发布。
130
163
 
131
164
  ## 开发验证
132
165
 
133
- CLI 源码和研发记录由本仓库独立维护。首次测试会从
134
- [`iloveZzz/yss-spec-project-template`](https://github.com/iloveZzz/yss-spec-project-template)
135
- 同步受管模板快照;正式发布应显式绑定确定 commit:
136
-
137
166
  ```bash
138
- YSS_SPEC_TEMPLATE_REF=<pinned-commit> npm test
139
- YSS_SPEC_TEMPLATE_REF=<pinned-commit> npm pack --dry-run
167
+ npm run test:contracts
168
+ npm run test:unit
169
+ npm run test:integration
170
+ YSS_SPEC_TEMPLATE_REF=017925706a981aec9eadefd470232bb531acd4d6 npm test
171
+ npm pack --dry-run
140
172
  ```
141
173
 
142
- ## 研发记录
174
+ ## 设计与手册
143
175
 
144
- - [初始化 CLI Discovery](docs/discovery/yss-spec-cli-init-discovery.md)
145
- - [模板同步 Discovery](docs/discovery/yss-spec-cli-template-sync-discovery.md)
146
- - [初始化 CLI PRD](docs/requirements/yss-spec-cli-init-prd.md)
147
- - [模板同步 PRD](docs/requirements/yss-spec-cli-template-sync-prd.md)
148
- - [垂直切片](docs/requirements/issues/)
149
- - [`yss-project.yaml` 跨仓库实现记录](docs/implementation/yss-project-repository-mode-contract.md)
150
- - [实施路由与 Build Architecture Checklist](docs/implementation/)
176
+ - [CLI v4 模块化](docs/implementation/cli-v4-modularization.md)
177
+ - [Machine Contracts v1](docs/implementation/machine-contracts-v1.md)
178
+ - [Ownership Policy v1](docs/implementation/ownership-policy-v1.md)
179
+ - [Lifecycle Policies v1](docs/implementation/lifecycle-policies-v1.md)
180
+ - [Programmatic API v1](docs/implementation/programmatic-api-v1.md)
151
181
  - [完整中文使用手册](docs/user-guide/create-yss-spec-cli-guide.md)
@@ -1,10 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { runCli } = require("../src/cli");
3
+ const { runCli } = require("../src/cli/index.js");
4
+ const { serializeError } = require("../src/cli/error-output.js");
5
+
6
+ const argv = process.argv.slice(2);
7
+ const wantsJson = argv.includes("--json");
4
8
 
5
9
  (async () => {
6
- await runCli(process.argv.slice(2));
10
+ await runCli(argv);
7
11
  })().catch((error) => {
8
- console.error(error.message);
12
+ if (wantsJson) {
13
+ process.stdout.write(serializeError(error));
14
+ } else {
15
+ console.error(error.message);
16
+ }
9
17
  process.exitCode = 1;
10
18
  });
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "create-yss-spec",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Initialize a YSS spec project template repository",
5
+ "main": "src/api/index.js",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "git+https://github.com/iloveZzz/create-yss-spec.git"
@@ -23,7 +24,13 @@
23
24
  "scripts": {
24
25
  "sync-template": "node scripts/sync-template.js",
25
26
  "pretest": "npm run sync-template",
26
- "test": "node --test tests/*.test.js",
27
+ "test": "node --test --test-concurrency=1 tests/*.test.js",
28
+ "test:contracts": "node --test tests/contracts.test.js tests/error-output.test.js tests/apply-result-contract.test.js",
29
+ "test:unit": "node --test tests/*planner*.test.js tests/filesystem-*.test.js tests/validation-modules.test.js tests/doctor-checks.test.js tests/ownership-policy.test.js tests/lifecycle-policy.test.js tests/lifecycle-metadata.test.js tests/verification-runtime.test.js tests/cli-modules.test.js tests/cli-entrypoint.test.js tests/self-update.test.js tests/plan-schema.test.js tests/contracts.test.js tests/error-output.test.js tests/apply-result-contract.test.js tests/programmatic-api-unit.test.js",
30
+ "test:integration": "npm run sync-template && node --test tests/init-cli.test.js tests/sync-command-modular.test.js tests/attach-command-modular.test.js tests/doctor-diff-command.test.js tests/programmatic-api.test.js tests/family-identity.test.js",
27
31
  "prepack": "npm run sync-template"
32
+ },
33
+ "devDependencies": {
34
+ "ajv": "^8.17.1"
28
35
  }
29
36
  }
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const { pathKind, normalizeRelativePath } = require("../filesystem/path-utils");
7
+ const { applyManagedOperation, applyMigrationOperations } = require("../filesystem/apply-plan");
8
+ const { runInTransaction } = require("../filesystem/transaction-runner");
9
+ const { assertBundledFamily, assertTargetFamily } = require("../family-runtime");
10
+ const { gitDirtyWarning } = require("../git/worktree");
11
+ const { unmanagedPathReason, assertTargetWorkingTreeWritable } = require("../validation/security");
12
+ const { buildSyncPlanFromRuntime } = require("../template/sync-planner-runtime");
13
+ const { buildLegacyMigrationPlan } = require("../template/migration-runtime");
14
+ const { decorateMetadataOwnership } = require("../template/ownership-metadata");
15
+ const { decorateMetadataLifecycle } = require("../template/lifecycle-metadata");
16
+ const {
17
+ PACKAGE_ROOT,
18
+ PACKAGE_MANIFEST,
19
+ BUNDLED_TEMPLATE_ROOT,
20
+ TEMPLATE_METADATA_FILENAME,
21
+ fileHash,
22
+ readTemplateSnapshot,
23
+ readTargetIdentity,
24
+ buildSyncDesiredOperations,
25
+ loadTemplateMetadata,
26
+ writeTemplateMetadata,
27
+ buildNextSyncMetadata,
28
+ verifyGeneratedSyncInstance,
29
+ } = require("../template/instance-runtime");
30
+
31
+ const APPLY_RESULT_SCHEMA_VERSION = 1;
32
+
33
+ function normalizeTargetDir(targetDir = ".", cwd = process.cwd()) {
34
+ return path.resolve(cwd, targetDir);
35
+ }
36
+
37
+ function isInsideTemplateRoot(targetDir) {
38
+ const relativePath = path.relative(BUNDLED_TEMPLATE_ROOT, targetDir);
39
+ return (
40
+ relativePath === "" ||
41
+ (!relativePath.startsWith("..") && !path.isAbsolute(relativePath))
42
+ );
43
+ }
44
+
45
+ function inspectExistingTargetDir(targetDir, { force = false } = {}) {
46
+ if (isInsideTemplateRoot(targetDir)) {
47
+ throw new Error("目标目录不能位于模板源仓库内部");
48
+ }
49
+ if (!fs.existsSync(targetDir) || pathKind(targetDir) !== "directory") {
50
+ throw new Error("attach 目标目录必须是已经存在的项目目录");
51
+ }
52
+ assertTargetWorkingTreeWritable(targetDir, {
53
+ force,
54
+ packageRoot: PACKAGE_ROOT,
55
+ });
56
+ }
57
+
58
+ function affectedPathsForManagedOperations(operations) {
59
+ return operations.map((operation) => normalizeRelativePath(operation.relativePath));
60
+ }
61
+
62
+ function affectedPathsForMigration(migrationPlan) {
63
+ return (migrationPlan.operations || []).flatMap((operation) =>
64
+ operation.kind === "move" ? [operation.from, operation.to] : [operation.path],
65
+ );
66
+ }
67
+
68
+ function buildSyncContext({ targetDir = ".", force = false, cwd = process.cwd() } = {}) {
69
+ const snapshot = readTemplateSnapshot();
70
+ assertBundledFamily(snapshot);
71
+ const resolvedTargetDir = normalizeTargetDir(targetDir, cwd);
72
+ assertTargetFamily(resolvedTargetDir);
73
+ inspectExistingTargetDir(resolvedTargetDir, { force: Boolean(force) });
74
+
75
+ const { metadata } = loadTemplateMetadata(resolvedTargetDir);
76
+ const identity = readTargetIdentity(resolvedTargetDir);
77
+ const desiredOperations = buildSyncDesiredOperations(
78
+ resolvedTargetDir,
79
+ metadata,
80
+ identity,
81
+ );
82
+ const migrationPlan = buildLegacyMigrationPlan(
83
+ resolvedTargetDir,
84
+ desiredOperations,
85
+ { checkFlatTickets: false },
86
+ );
87
+ const warning = gitDirtyWarning(resolvedTargetDir);
88
+
89
+ const { classified: syncPlan, plan } = buildSyncPlanFromRuntime({
90
+ targetDir: resolvedTargetDir,
91
+ metadata,
92
+ desiredOperations,
93
+ migration: migrationPlan,
94
+ warning,
95
+ toVersion: PACKAGE_MANIFEST.version,
96
+ getUnmanagedReason: (operation) =>
97
+ unmanagedPathReason(resolvedTargetDir, operation.relativePath, {
98
+ packageRoot: PACKAGE_ROOT,
99
+ }),
100
+ getPathKind: (operation) => pathKind(operation.targetPath),
101
+ getFileHash: (operation) => fileHash(operation.targetPath),
102
+ });
103
+
104
+ return {
105
+ targetDir: resolvedTargetDir,
106
+ metadata,
107
+ identity,
108
+ desiredOperations,
109
+ migrationPlan,
110
+ warning,
111
+ syncPlan,
112
+ plan,
113
+ };
114
+ }
115
+
116
+ function assertSyncApplicable(context) {
117
+ const { migrationPlan, syncPlan } = context;
118
+ if (migrationPlan.unsafe.length > 0) {
119
+ throw new Error("sync 被 unsafe 迁移项阻断;请先人工整理 Ticket 归属");
120
+ }
121
+ if (syncPlan.unsafe.length > 0) {
122
+ throw new Error(
123
+ "sync 被 unsafe 受管路径阻断;--force 不能绕过,请先人工整理目标路径",
124
+ );
125
+ }
126
+ if (migrationPlan.conflicts.length > 0) {
127
+ throw new Error("sync 被旧路径迁移冲突阻断,请先处理目标冲突");
128
+ }
129
+ }
130
+
131
+ function applySyncContext(context, { force = false } = {}) {
132
+ assertSyncApplicable(context);
133
+ const { targetDir, metadata, migrationPlan, syncPlan } = context;
134
+ const managedToApply = [
135
+ ...syncPlan.updated,
136
+ ...syncPlan.added,
137
+ ...(force ? syncPlan.forceableConflicts : []),
138
+ ];
139
+
140
+ const { backupPath } = runInTransaction({
141
+ targetDir,
142
+ operation: "sync",
143
+ affectedPaths: [
144
+ ...affectedPathsForManagedOperations(managedToApply),
145
+ ...affectedPathsForMigration(migrationPlan),
146
+ TEMPLATE_METADATA_FILENAME,
147
+ ],
148
+ execute: (transaction) => {
149
+ for (const operation of managedToApply) {
150
+ applyManagedOperation(operation, transaction);
151
+ }
152
+ applyMigrationOperations(migrationPlan, transaction);
153
+ verifyGeneratedSyncInstance(targetDir);
154
+ const nextMetadata = decorateMetadataLifecycle(
155
+ decorateMetadataOwnership(buildNextSyncMetadata(metadata, syncPlan)),
156
+ );
157
+ writeTemplateMetadata(targetDir, nextMetadata, transaction);
158
+ },
159
+ });
160
+
161
+ return {
162
+ schemaVersion: APPLY_RESULT_SCHEMA_VERSION,
163
+ operation: "sync",
164
+ targetDir,
165
+ backupPath,
166
+ template: context.plan.template,
167
+ stats: {
168
+ updated: syncPlan.updated.length,
169
+ added: syncPlan.added.length,
170
+ skipped: syncPlan.skipped.length,
171
+ removed: syncPlan.removed.length,
172
+ forceApplied: force ? syncPlan.forceableConflicts.length : 0,
173
+ },
174
+ skipped: syncPlan.skipped.map((operation) => ({
175
+ path: operation.relativePath,
176
+ reason: operation.reason,
177
+ ownership: operation.ownership || null,
178
+ mergeStrategy: operation.mergeStrategy || null,
179
+ })),
180
+ removed: [...syncPlan.removed],
181
+ };
182
+ }
183
+
184
+ module.exports = {
185
+ APPLY_RESULT_SCHEMA_VERSION,
186
+ normalizeTargetDir,
187
+ inspectExistingTargetDir,
188
+ buildSyncContext,
189
+ assertSyncApplicable,
190
+ applySyncContext,
191
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ const { normalizeError } = require("../cli/error-output");
4
+ const { projectDoctor } = require("./project-doctor");
5
+ const { projectDiff } = require("./project-diff");
6
+ const { templatePlan } = require("./template-plan");
7
+ const { templateApply } = require("./template-apply");
8
+
9
+ const API_VERSION = 1;
10
+
11
+ function toErrorEnvelope(error) {
12
+ return normalizeError(error);
13
+ }
14
+
15
+ module.exports = {
16
+ API_VERSION,
17
+ projectDoctor,
18
+ projectDiff,
19
+ templatePlan,
20
+ templateApply,
21
+ toErrorEnvelope,
22
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ const { templatePlan } = require("./template-plan");
4
+
5
+ function projectDiff(options = {}) {
6
+ return templatePlan(options);
7
+ }
8
+
9
+ module.exports = { projectDiff };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const path = require("node:path");
4
+
5
+ function projectDoctor({ targetDir = ".", cwd = process.cwd() } = {}) {
6
+ const { buildDoctorReport } = require("../commands/doctor");
7
+ return buildDoctorReport(path.resolve(cwd, targetDir));
8
+ }
9
+
10
+ module.exports = { projectDoctor };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const { buildSyncContext, applySyncContext } = require("./_sync-service");
4
+
5
+ function templateApply(options = {}) {
6
+ const context = buildSyncContext(options);
7
+ return applySyncContext(context, { force: Boolean(options.force) });
8
+ }
9
+
10
+ module.exports = { templateApply };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ const { buildSyncContext } = require("./_sync-service");
4
+
5
+ function templatePlan(options = {}) {
6
+ return buildSyncContext(options).plan;
7
+ }
8
+
9
+ module.exports = { templatePlan };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ const { HELP_FLAGS, VERSION_FLAGS } = require("./flags");
4
+
5
+ const VALUE_OPTIONS = new Map([
6
+ ["--project-name", "projectName"],
7
+ ["--business-domain", "businessDomain"],
8
+ ["--team-size", "teamSize"],
9
+ ["--target-dir", "targetDir"],
10
+ ["--issue-tracker", "issueTracker"],
11
+ ]);
12
+
13
+ function parseArgs(argv = []) {
14
+ const options = {};
15
+
16
+ for (let index = 0; index < argv.length; index += 1) {
17
+ const current = argv[index];
18
+ const next = argv[index + 1];
19
+
20
+ if (VALUE_OPTIONS.has(current)) {
21
+ if (!next || next.startsWith("--")) {
22
+ throw new Error(`${current} 需要一个值`);
23
+ }
24
+ options[VALUE_OPTIONS.get(current)] = next;
25
+ index += 1;
26
+ continue;
27
+ }
28
+
29
+ if (current === "--dry-run") {
30
+ options.dryRun = true;
31
+ } else if (current === "--plan") {
32
+ options.plan = true;
33
+ } else if (current === "--json") {
34
+ options.json = true;
35
+ } else if (current === "--apply") {
36
+ options.apply = true;
37
+ } else if (current === "--force") {
38
+ options.force = true;
39
+ } else if (current === "--git-init") {
40
+ options.gitInit = true;
41
+ } else if (current === "--include-example-docs") {
42
+ options.includeExampleDocs = true;
43
+ } else if (current === "--no-example-docs") {
44
+ options.includeExampleDocs = false;
45
+ } else if (HELP_FLAGS.has(current)) {
46
+ options.help = true;
47
+ } else if (VERSION_FLAGS.has(current)) {
48
+ options.version = true;
49
+ } else {
50
+ throw new Error(`不支持的参数:${current}`);
51
+ }
52
+ }
53
+
54
+ return options;
55
+ }
56
+
57
+ module.exports = {
58
+ VALUE_OPTIONS,
59
+ parseArgs,
60
+ };