@guanlin4924/devflow-pi 0.1.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 (254) hide show
  1. package/README.md +164 -0
  2. package/docs/OMP-NATIVE-ARCHITECTURE.md +104 -0
  3. package/package.json +40 -0
  4. package/plugins/devflow-core/extensions/devflow-core.ts +1642 -0
  5. package/plugins/devflow-core/package.json +14 -0
  6. package/plugins/devflow-core/runtime/hooks/context_sync_gate.py +174 -0
  7. package/plugins/devflow-core/runtime/hooks/hook_common.py +696 -0
  8. package/plugins/devflow-core/runtime/hooks/index_gate.py +63 -0
  9. package/plugins/devflow-core/runtime/hooks/injection_code_specification.py +7 -0
  10. package/plugins/devflow-core/runtime/hooks/post_tool.py +44 -0
  11. package/plugins/devflow-core/runtime/hooks/start.py +288 -0
  12. package/plugins/devflow-core/skills/workflow-orchestrator/SKILL.md +265 -0
  13. package/plugins/devflow-core/skills/workflow-orchestrator/agents/openai.yaml +4 -0
  14. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/advance_state.rb +520 -0
  15. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/control_io.rb +42 -0
  16. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/init_state.rb +138 -0
  17. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/init_workflow.rb +121 -0
  18. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/inspect_state.rb +553 -0
  19. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/manage_lessons.rb +219 -0
  20. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/sync_artifacts.rb +168 -0
  21. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/update_triage_route.rb +110 -0
  22. package/plugins/devflow-core/skills/workflow-orchestrator/scripts/validate_state.rb +565 -0
  23. package/plugins/devflow-core/skills/workflow-orchestrator/templates/feature-development.yaml +783 -0
  24. package/plugins/devflow-core/skills/workflow-orchestrator/templates/uat-remediation.yaml +143 -0
  25. package/plugins/devflow-core/skills/workflow-orchestrator/templates/workflows-README.md +10 -0
  26. package/plugins/devflow-core/skills/workflow-pipeline/SKILL.md +117 -0
  27. package/plugins/devflow-core/skills/workflow-pipeline/references/pipeline-flow.md +167 -0
  28. package/plugins/devflow-core/skills/workflow-pipeline/references/slice-safety-guide.md +125 -0
  29. package/plugins/devflow-core/skills/workflow-project-context/SKILL.md +819 -0
  30. package/plugins/devflow-core/skills/workflow-project-context/assets/agents-md-template.md +25 -0
  31. package/plugins/devflow-core/skills/workflow-project-context/assets/codebase-backend-spec-template.md +68 -0
  32. package/plugins/devflow-core/skills/workflow-project-context/assets/codebase-frontend-spec-template.md +64 -0
  33. package/plugins/devflow-core/skills/workflow-project-context/assets/codebase-navigation-template.md +168 -0
  34. package/plugins/devflow-core/skills/workflow-project-context/assets/context-domain-index-template.md +43 -0
  35. package/plugins/devflow-core/skills/workflow-project-context/assets/context-spec-index-template.md +45 -0
  36. package/plugins/devflow-core/skills/workflow-project-context/assets/execution-contract-template.md +57 -0
  37. package/plugins/devflow-core/skills/workflow-project-context/assets/navigation-index-template.md +40 -0
  38. package/plugins/devflow-core/skills/workflow-project-context/assets/project-initialization-template.md +109 -0
  39. package/plugins/devflow-core/skills/workflow-project-context/assets/rules-index-template.md +80 -0
  40. package/plugins/devflow-core/skills/workflow-project-context/assets/run-manifest-template.json +40 -0
  41. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/directory-structure.md +46 -0
  42. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/engine.md +46 -0
  43. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/errors.md +46 -0
  44. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/locator.md +46 -0
  45. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/model.md +46 -0
  46. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/repository.md +46 -0
  47. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/router.md +46 -0
  48. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/scheduler.md +46 -0
  49. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/schema.md +46 -0
  50. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/service.md +46 -0
  51. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/backend/testing.md +46 -0
  52. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/api-client.md +46 -0
  53. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/case-editor.md +46 -0
  54. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/components.md +46 -0
  55. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/directory-structure.md +46 -0
  56. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/forms.md +46 -0
  57. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/routing.md +46 -0
  58. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/state.md +46 -0
  59. package/plugins/devflow-core/skills/workflow-project-context/assets/spec-templates/frontend/testing.md +46 -0
  60. package/plugins/devflow-core/skills/workflow-project-context/assets/stack-spec-template.md +106 -0
  61. package/plugins/devflow-core/skills/workflow-project-context/assets/state-template.md +77 -0
  62. package/plugins/devflow-core/skills/workflow-project-context/assets/toolchain-template.md +37 -0
  63. package/plugins/devflow-core/skills/workflow-project-context/references/navigation-guide.md +262 -0
  64. package/plugins/devflow-core/skills/workflow-project-context/scripts/validate_initialization.py +545 -0
  65. package/plugins/devflow-design/agents/contract-auditor.md +18 -0
  66. package/plugins/devflow-design/extensions/devflow-design.ts +47 -0
  67. package/plugins/devflow-design/package.json +14 -0
  68. package/plugins/devflow-design/skills/workflow-api-call-guide/SKILL.md +142 -0
  69. package/plugins/devflow-design/skills/workflow-api-contract/SKILL.md +150 -0
  70. package/plugins/devflow-design/skills/workflow-api-supplement/SKILL.md +121 -0
  71. package/plugins/devflow-design/skills/workflow-backend-tech-spec/SKILL.md +257 -0
  72. package/plugins/devflow-design/skills/workflow-backend-tech-spec/assets/adr-template.md +57 -0
  73. package/plugins/devflow-design/skills/workflow-backend-tech-spec/assets/backend-spec-template.md +205 -0
  74. package/plugins/devflow-design/skills/workflow-backend-tech-spec/references/affected-module-exploration.md +59 -0
  75. package/plugins/devflow-design/skills/workflow-backend-tech-spec/references/backend-conventions.md +30 -0
  76. package/plugins/devflow-design/skills/workflow-backend-tech-spec/references/code-explore-guide.md +40 -0
  77. package/plugins/devflow-design/skills/workflow-backend-tech-spec/references/project-rule-contract.md +66 -0
  78. package/plugins/devflow-design/skills/workflow-design-rule-pack/SKILL.md +91 -0
  79. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/index.md +71 -0
  80. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/recommendations/accessibility.md +31 -0
  81. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/recommendations/component-library.md +31 -0
  82. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/recommendations/design-systems.md +47 -0
  83. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/recommendations/responsive-grid.md +29 -0
  84. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/recommendations/stack-guidelines.md +31 -0
  85. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/recommendations/ux-patterns.md +40 -0
  86. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tokens/project-tokens.md +19 -0
  87. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/SKILL.md +377 -0
  88. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/charts.csv +26 -0
  89. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/colors.csv +97 -0
  90. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/icons.csv +101 -0
  91. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/landing.csv +31 -0
  92. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/products.csv +97 -0
  93. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/react-performance.csv +45 -0
  94. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  95. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  96. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  97. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  98. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  99. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  100. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  101. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  102. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/react.csv +54 -0
  103. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  104. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  105. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  106. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  107. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/styles.csv +68 -0
  108. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/typography.csv +58 -0
  109. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  110. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  111. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/data/web-interface.csv +31 -0
  112. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/scripts/core.py +253 -0
  113. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/scripts/design_system.py +1067 -0
  114. package/plugins/devflow-design/skills/workflow-design-rule-pack/assets/design/tools/ui-ux-pro-max/scripts/search.py +114 -0
  115. package/plugins/devflow-design/skills/workflow-design-rule-pack/scripts/install.py +67 -0
  116. package/plugins/devflow-design/skills/workflow-feature-breakdown/SKILL.md +370 -0
  117. package/plugins/devflow-design/skills/workflow-feature-breakdown/assets/admin-system-template.md +57 -0
  118. package/plugins/devflow-design/skills/workflow-feature-breakdown/assets/api-service-template.md +42 -0
  119. package/plugins/devflow-design/skills/workflow-feature-breakdown/assets/c-end-system-template.md +25 -0
  120. package/plugins/devflow-design/skills/workflow-feature-breakdown/assets/output-template.md +139 -0
  121. package/plugins/devflow-design/skills/workflow-feature-breakdown/references/bug-rules.md +12 -0
  122. package/plugins/devflow-design/skills/workflow-feature-breakdown/references/exception-checklist.md +31 -0
  123. package/plugins/devflow-design/skills/workflow-feature-breakdown/references/trace-integrity-guide.md +153 -0
  124. package/plugins/devflow-design/skills/workflow-feature-breakdown/references/writing-guide.md +92 -0
  125. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/SKILL.md +223 -0
  126. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/assets/frontend-spec-template.md +204 -0
  127. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/affected-module-exploration.md +58 -0
  128. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/component-patterns.md +42 -0
  129. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/frontend-conventions.md +28 -0
  130. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/frontend-stack-slots/common-web.md +53 -0
  131. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/frontend-stack-slots/next.md +40 -0
  132. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/frontend-stack-slots/react.md +41 -0
  133. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/frontend-stack-slots/vue.md +41 -0
  134. package/plugins/devflow-design/skills/workflow-frontend-tech-spec/references/project-rule-contract.md +95 -0
  135. package/plugins/devflow-design/skills/workflow-integration-verify/SKILL.md +172 -0
  136. package/plugins/devflow-design/skills/workflow-ui-spec/SKILL.md +302 -0
  137. package/plugins/devflow-design/skills/workflow-ui-spec/assets/ui-spec-template.md +244 -0
  138. package/plugins/devflow-design/skills/workflow-ui-spec/references/affected-module-exploration.md +55 -0
  139. package/plugins/devflow-implementation/agents/implementation-worker.md +20 -0
  140. package/plugins/devflow-implementation/package.json +6 -0
  141. package/plugins/devflow-implementation/skills/workflow-bug-fix/SKILL.md +124 -0
  142. package/plugins/devflow-implementation/skills/workflow-bug-fix/references/INDEX.md +13 -0
  143. package/plugins/devflow-implementation/skills/workflow-bug-fix/references/adversarial-review.md +35 -0
  144. package/plugins/devflow-implementation/skills/workflow-bug-fix/references/first-principles.md +26 -0
  145. package/plugins/devflow-implementation/skills/workflow-bug-fix/references/lesson-format.md +28 -0
  146. package/plugins/devflow-implementation/skills/workflow-bug-fix/references/root-cause-ladder.md +51 -0
  147. package/plugins/devflow-implementation/skills/workflow-bug-fix/references/seam-analysis.md +30 -0
  148. package/plugins/devflow-implementation/skills/workflow-change-plan/SKILL.md +160 -0
  149. package/plugins/devflow-implementation/skills/workflow-change-plan/references/code-conventions.md +33 -0
  150. package/plugins/devflow-implementation/skills/workflow-change-plan/references/ddl-guidelines.md +60 -0
  151. package/plugins/devflow-implementation/skills/workflow-change-plan/references/output-template.md +217 -0
  152. package/plugins/devflow-implementation/skills/workflow-change-plan/references/project-rule-contract.md +55 -0
  153. package/plugins/devflow-implementation/skills/workflow-execute-phase/SKILL.md +271 -0
  154. package/plugins/devflow-implementation/skills/workflow-execute-phase/references/execute-phase.md +1251 -0
  155. package/plugins/devflow-implementation/skills/workflow-execute-phase/references/ui-brand.md +160 -0
  156. package/plugins/devflow-intel/agents/project-scout.md +27 -0
  157. package/plugins/devflow-intel/extensions/devflow-intel.ts +104 -0
  158. package/plugins/devflow-intel/package.json +14 -0
  159. package/plugins/devflow-intel/skills/code-index-query/SKILL.md +37 -0
  160. package/plugins/devflow-intel/skills/code-index-query/references/query-patterns.md +27 -0
  161. package/plugins/devflow-intel/skills/workflow-code-index/SKILL.md +68 -0
  162. package/plugins/devflow-intel/skills/workflow-code-index/references/adapter-contract.md +38 -0
  163. package/plugins/devflow-intel/skills/workflow-code-index/references/audit-checklist.md +10 -0
  164. package/plugins/devflow-intel/skills/workflow-code-index/references/confidence-rules.md +43 -0
  165. package/plugins/devflow-intel/skills/workflow-code-index/references/data-model.md +74 -0
  166. package/plugins/devflow-intel/skills/workflow-code-index/references/discovery.md +24 -0
  167. package/plugins/devflow-intel/skills/workflow-code-index/references/query-guide.md +20 -0
  168. package/plugins/devflow-intel/skills/workflow-code-index/scripts/adapters/__init__.py +1 -0
  169. package/plugins/devflow-intel/skills/workflow-code-index/scripts/adapters/base.py +30 -0
  170. package/plugins/devflow-intel/skills/workflow-code-index/scripts/adapters/generic_text.py +287 -0
  171. package/plugins/devflow-intel/skills/workflow-code-index/scripts/adapters/registry.py +17 -0
  172. package/plugins/devflow-intel/skills/workflow-code-index/scripts/code_index.py +437 -0
  173. package/plugins/devflow-intel/skills/workflow-code-index/scripts/core/__init__.py +1 -0
  174. package/plugins/devflow-intel/skills/workflow-code-index/scripts/core/discovery.py +139 -0
  175. package/plugins/devflow-intel/skills/workflow-code-index/scripts/core/hashing.py +11 -0
  176. package/plugins/devflow-intel/skills/workflow-code-index/scripts/core/scanner.py +115 -0
  177. package/plugins/devflow-intel/skills/workflow-code-index/scripts/core/schema.py +123 -0
  178. package/plugins/devflow-intel/skills/workflow-code-index/scripts/validators/__init__.py +1 -0
  179. package/plugins/devflow-intel/skills/workflow-code-index/scripts/validators/project_binding_check.py +66 -0
  180. package/plugins/devflow-intel/skills/workflow-code-index/scripts/validators/relation_check.py +36 -0
  181. package/plugins/devflow-intel/skills/workflow-code-index/scripts/validators/schema_validate.py +11 -0
  182. package/plugins/devflow-intel/skills/workflow-code-index/scripts/validators/stale_check.py +42 -0
  183. package/plugins/devflow-intel/skills/workflow-code-index/scripts/writers/__init__.py +1 -0
  184. package/plugins/devflow-intel/skills/workflow-code-index/scripts/writers/jsonl_writer.py +25 -0
  185. package/plugins/devflow-intel/skills/workflow-code-index/scripts/writers/markdown_writer.py +106 -0
  186. package/plugins/devflow-intel/skills/workflow-code-index/scripts/writers/sqlite_writer.py +143 -0
  187. package/plugins/devflow-intel/skills/workflow-context-sync/SKILL.md +381 -0
  188. package/plugins/devflow-intel/skills/workflow-context-sync/agents/openai.yaml +4 -0
  189. package/plugins/devflow-intel/skills/workflow-context-sync/scripts/context_sync_cursor.py +241 -0
  190. package/plugins/devflow-intel/skills/workflow-update-navigation/SKILL.md +186 -0
  191. package/plugins/devflow-intel/skills/workflow-update-navigation/references/incremental-update-guide.md +47 -0
  192. package/plugins/devflow-quality/agents/code-reviewer.md +18 -0
  193. package/plugins/devflow-quality/agents/verification-runner.md +21 -0
  194. package/plugins/devflow-quality/extensions/devflow-quality.ts +59 -0
  195. package/plugins/devflow-quality/package.json +14 -0
  196. package/plugins/devflow-quality/skills/code-review/SKILL.md +288 -0
  197. package/plugins/devflow-quality/skills/code-review/references/cross-layer-checklist.md +70 -0
  198. package/plugins/devflow-quality/skills/code-review/references/dao-checklist.md +70 -0
  199. package/plugins/devflow-quality/skills/code-review/references/handler-checklist.md +48 -0
  200. package/plugins/devflow-quality/skills/code-review/references/repository-checklist.md +44 -0
  201. package/plugins/devflow-quality/skills/code-review/references/service-checklist.md +57 -0
  202. package/plugins/devflow-quality/skills/code-review/references/spec-checklist.md +34 -0
  203. package/plugins/devflow-quality/skills/code-review/references/vo-checklist.md +26 -0
  204. package/plugins/devflow-quality/skills/workflow-audit-milestone/SKILL.md +31 -0
  205. package/plugins/devflow-quality/skills/workflow-audit-milestone/references/audit-milestone.md +328 -0
  206. package/plugins/devflow-quality/skills/workflow-complete-milestone/SKILL.md +132 -0
  207. package/plugins/devflow-quality/skills/workflow-complete-milestone/assets/milestone-archive.md +123 -0
  208. package/plugins/devflow-quality/skills/workflow-complete-milestone/references/complete-milestone.md +775 -0
  209. package/plugins/devflow-quality/skills/workflow-complete-milestone/references/milestone-archive.md +123 -0
  210. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/SKILL.md +126 -0
  211. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/references/api-mainflow-rules.md +27 -0
  212. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/references/codebase-discovery.md +54 -0
  213. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/references/intermediate-format.md +244 -0
  214. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/references/mainflow-selection.md +36 -0
  215. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/references/project-dsl-contract.md +190 -0
  216. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/references/ui-mainflow-rules.md +110 -0
  217. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/scripts/compile_dsl.py +583 -0
  218. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/scripts/discover_codebases.py +199 -0
  219. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/scripts/normalize_case_payloads.py +177 -0
  220. package/plugins/devflow-quality/skills/workflow-generate-mainflow-cases/scripts/validate_case_payloads.py +370 -0
  221. package/plugins/devflow-quality/skills/workflow-verify-work/SKILL.md +106 -0
  222. package/plugins/devflow-quality/skills/workflow-verify-work/assets/UAT.md +265 -0
  223. package/plugins/devflow-quality/skills/workflow-verify-work/references/verify-work.md +759 -0
  224. package/plugins/devflow-requirements/agents/requirements-auditor.md +20 -0
  225. package/plugins/devflow-requirements/package.json +6 -0
  226. package/plugins/devflow-requirements/skills/requirement-feasibility-review/SKILL.md +219 -0
  227. package/plugins/devflow-requirements/skills/requirement-feasibility-review/agents/openai.yaml +4 -0
  228. package/plugins/devflow-requirements/skills/requirement-feasibility-review/references/review-method.md +257 -0
  229. package/plugins/devflow-requirements/skills/requirement-feasibility-review/references/review-template.md +80 -0
  230. package/plugins/devflow-requirements/skills/workflow-demand-clarify/SKILL.md +325 -0
  231. package/plugins/devflow-requirements/skills/workflow-domain-modeling/SKILL.md +163 -0
  232. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/SKILL.md +748 -0
  233. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/assets/baseline-template.md +281 -0
  234. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/references/antipatterns.md +69 -0
  235. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/references/challenge-review-guide.md +158 -0
  236. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/references/decomposition-guide.md +115 -0
  237. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/references/project-context-guide.md +119 -0
  238. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/references/questioning.md +76 -0
  239. package/plugins/devflow-requirements/skills/workflow-requirement-baseline/references/requirement-review-checklist.md +115 -0
  240. package/plugins/devflow-requirements/skills/workflow-requirement-triage/SKILL.md +204 -0
  241. package/plugins/devflow-requirements/skills/workflow-wayfinder/SKILL.md +183 -0
  242. package/src/cli.ts +76 -0
  243. package/src/constants.ts +15 -0
  244. package/src/doctor.ts +66 -0
  245. package/src/paths.ts +37 -0
  246. package/src/platform-extension.ts +46 -0
  247. package/src/project-context.ts +165 -0
  248. package/src/runtime.ts +167 -0
  249. package/src/usage-stats.ts +101 -0
  250. package/templates/commands/start.md +58 -0
  251. package/templates/omp/AGENTS.md +36 -0
  252. package/templates/omp/config.yml +112 -0
  253. package/templates/omp/hook-config.json +18 -0
  254. package/templates/omp/index-policy.json +57 -0
@@ -0,0 +1,520 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "date"
5
+ require "fileutils"
6
+ require "json"
7
+ require "optparse"
8
+ require "yaml"
9
+ require_relative "control_io"
10
+ require_relative "validate_state"
11
+
12
+ options = {
13
+ state: nil,
14
+ write: false,
15
+ complete_step: nil,
16
+ confirm_checkpoint: false,
17
+ checkpoint_decision: nil,
18
+ enter_failure_branch: false,
19
+ expected_revision: nil,
20
+ json: false
21
+ }
22
+
23
+ OptionParser.new do |opts|
24
+ opts.banner = "Usage: advance_state.rb [options]"
25
+ opts.on("--state PATH", "Read/write an alternate STATE.md file") { |path| options[:state] = path }
26
+ opts.on("--write", "Persist changes. Without this flag, the script only previews.") { options[:write] = true }
27
+ opts.on("--complete-step STEP", "Mark STEP complete and advance state") { |step| options[:complete_step] = step }
28
+ opts.on("--confirm-checkpoint", "Advance from waiting checkpoint to the next pending step") { options[:confirm_checkpoint] = true }
29
+ opts.on("--checkpoint-decision VALUE", "Set checkpoint decision, e.g. approved, rejected, needs_fix") { |value| options[:checkpoint_decision] = value }
30
+ opts.on("--enter-failure-branch", "Transition into the configured failure branch for the current step") { options[:enter_failure_branch] = true }
31
+ opts.on("--expected-revision REVISION", Integer, "Reject a stale write unless STATE.md has this revision") { |value| options[:expected_revision] = value }
32
+ opts.on("--json", "Print JSON output") { options[:json] = true }
33
+ end.parse!
34
+
35
+ root = Dir.pwd
36
+ state_path = options[:state] ? File.expand_path(options[:state], root) : File.join(root, ".planning", "STATE.md")
37
+
38
+ def front_matter(markdown)
39
+ match = markdown.match(/\A---\n(.*?)\n---\n/m)
40
+ match && match[1]
41
+ end
42
+
43
+ def load_yaml_file(path)
44
+ YAML.safe_load(File.read(path), permitted_classes: [], aliases: false)
45
+ end
46
+
47
+ def workflow_path_for(root, state)
48
+ state["workflow_config"] || File.join(".planning", "workflows", "#{state.fetch("current_flow")}.yaml")
49
+ end
50
+
51
+ def load_workflow(root, state)
52
+ path = workflow_path_for(root, state)
53
+ [path, load_yaml_file(File.join(root, path))]
54
+ end
55
+
56
+ def interpolate_path(path, state)
57
+ path
58
+ .gsub("{feature}", state.fetch("current_feature", "").to_s)
59
+ .gsub("{phase}", state.fetch("current_phase", "").to_s)
60
+ end
61
+
62
+ def load_artifact_registry(root, workflow)
63
+ registry_path = workflow.dig("artifact_registry", "source")
64
+ return {} unless registry_path
65
+
66
+ abs = File.join(root, registry_path)
67
+ return {} unless File.exist?(abs)
68
+
69
+ registry = load_yaml_file(abs)
70
+ Array(registry["artifacts"]).to_h { |a| [a.fetch("path"), a] }
71
+ end
72
+
73
+ def collect_outputs(workflow)
74
+ Array(workflow["steps"]).flat_map do |step|
75
+ Array(step["outputs"]).map { |output| [step, output] }
76
+ end
77
+ end
78
+
79
+ def content_validity(root, path, checks)
80
+ abs = File.join(root, path)
81
+ return { "valid" => false, "issues" => ["file_missing"] } unless File.exist?(abs)
82
+
83
+ issues = []
84
+ min_bytes = checks["min_bytes"]
85
+ required_header = checks["required_header"]
86
+
87
+ if min_bytes && File.size(abs) < min_bytes
88
+ issues << "below_min_bytes(#{File.size(abs)} < #{min_bytes})"
89
+ end
90
+
91
+ if required_header
92
+ head = File.read(abs, [required_header.length + 50, 200].min)
93
+ issues << "missing_required_header(#{required_header.inspect})" unless head.include?(required_header)
94
+ end
95
+
96
+ { "valid" => issues.empty?, "issues" => issues }
97
+ end
98
+
99
+ def sync_artifact_registry(root, workflow, state)
100
+ registry_path = workflow.dig("artifact_registry", "source")
101
+ return nil unless registry_path
102
+
103
+ abs = File.join(root, registry_path)
104
+ existing_by_path = if File.exist?(abs)
105
+ Array(load_yaml_file(abs)["artifacts"]).to_h { |artifact| [artifact.fetch("path"), artifact] }
106
+ else
107
+ {}
108
+ end
109
+
110
+ completed = Array(state["completed_steps"])
111
+ current_step = state["current_step"]
112
+ content_checks = workflow.dig("artifact_registry", "content_checks") || {}
113
+ preservable_statuses = %w[approved completed passed pending_rerun stale failed]
114
+
115
+ artifacts = collect_outputs(workflow).map do |step, output|
116
+ path = interpolate_path(output.fetch("path"), state)
117
+ existing = existing_by_path[path] || {}
118
+ generated_status =
119
+ if completed.include?(step.fetch("id"))
120
+ step["checkpoint"] ? "approved" : "completed"
121
+ elsif step.fetch("id") == current_step && state["status"] == "waiting_checkpoint"
122
+ "generated"
123
+ else
124
+ "planned"
125
+ end
126
+
127
+ validity = content_validity(root, path, content_checks)
128
+ file_exists = File.exist?(File.join(root, path))
129
+ status = if preservable_statuses.include?(existing["status"])
130
+ existing["status"]
131
+ else
132
+ generated_status
133
+ end
134
+
135
+ {
136
+ "path" => path,
137
+ "type" => output["type"],
138
+ "workflow_step" => step.fetch("id"),
139
+ "produced_by" => step["skill"] || step["action"],
140
+ "status" => status,
141
+ "checkpoint" => existing["checkpoint"] || step["checkpoint"],
142
+ "covers" => Array(existing["covers"]),
143
+ "downstream_steps" => Array(existing["downstream_steps"]),
144
+ "exists" => file_exists,
145
+ "content_valid" => validity["valid"],
146
+ "content_issues" => validity["issues"].empty? ? nil : validity["issues"]
147
+ }.reject { |_, value| value.nil? || value == [] }
148
+ end
149
+
150
+ registry = {
151
+ "schema_version" => 1,
152
+ "state_revision" => state.fetch("revision", 0),
153
+ "updated_at" => Date.today.to_s,
154
+ "registry_scope" => {
155
+ "flow" => state["current_flow"],
156
+ "feature" => state["current_feature"],
157
+ "phase" => state["current_phase"]
158
+ },
159
+ "artifacts" => artifacts
160
+ }
161
+
162
+ DevflowControlIO.atomic_write(abs, registry.to_yaml)
163
+ registry_path
164
+ end
165
+
166
+ def artifact_status_icon(status, exists, content_valid)
167
+ return "❌" unless exists
168
+ return "⚠️" if content_valid == false
169
+ case status
170
+ when "approved", "completed", "passed" then "✅"
171
+ when "generated" then "📝"
172
+ when "failed" then "❌"
173
+ else "⬜"
174
+ end
175
+ end
176
+
177
+ def generate_body(root, state, workflow, artifact_by_path, action_description)
178
+ feature = state["current_feature"] || "—"
179
+ phase = state["current_phase"] || "—"
180
+ status = state["status"] || "unknown"
181
+ current_step_id = state["current_step"]
182
+ checkpoint_id = state["checkpoint"]
183
+
184
+ steps = Array(workflow["steps"])
185
+ step_by_id = steps.to_h { |s| [s.fetch("id"), s] }
186
+
187
+ completed_ids = Array(state["completed_steps"])
188
+ pending_ids = Array(state["pending_steps"])
189
+
190
+ status_labels = { "completed" => "All steps complete", "blocked" => "Blocked", "failed" => "Failed" }
191
+ current_step = step_by_id[current_step_id]
192
+ current_label = if current_step
193
+ "#{current_step["label"]} (#{current_step_id})"
194
+ elsif status_labels.key?(current_step_id.to_s)
195
+ status_labels[current_step_id.to_s]
196
+ else
197
+ current_step_id.to_s
198
+ end
199
+
200
+ checkpoint = checkpoint_id && workflow.dig("checkpoints", checkpoint_id)
201
+ cp_label = checkpoint ? "#{checkpoint_id}: #{checkpoint["name"]}" : checkpoint_id
202
+
203
+ lines = []
204
+ lines << "<!-- ⚠ GENERATED by advance_state.rb on #{Time.now.strftime("%Y-%m-%d %H:%M")} — DO NOT EDIT -->"
205
+ lines << ""
206
+ lines << "## Current State"
207
+ lines << ""
208
+ lines << "| Field | Value |"
209
+ lines << "|-------|-------|"
210
+ lines << "| Flow | `#{state["current_flow"]}` |"
211
+ lines << "| Feature | #{feature} |"
212
+ lines << "| Phase | #{phase} |"
213
+ lines << "| Step | #{current_label} |"
214
+ lines << "| Status | **#{status}** |"
215
+ lines << "| Checkpoint | #{cp_label || "—"} |"
216
+ if state["checkpoint_decision"]
217
+ lines << "| CP Decision | #{state["checkpoint_decision"]} |"
218
+ end
219
+
220
+ unless completed_ids.empty?
221
+ lines << ""
222
+ lines << "## Completed Steps"
223
+ lines << ""
224
+ completed_ids.each do |sid|
225
+ s = step_by_id[sid]
226
+ label = s ? s["label"] : sid
227
+ outputs = Array(s && s["outputs"]).map { |o| interpolate_path(o.fetch("path"), state) }
228
+ parts = outputs.map do |p|
229
+ art = artifact_by_path[p]
230
+ icon = artifact_status_icon(art&.dig("status"), art&.dig("exists") || File.exist?(File.join(root, p)), art&.dig("content_valid"))
231
+ "#{icon} #{p}"
232
+ end
233
+ lines << "- **#{label}** (`#{sid}`) #{parts.join(" ")}".strip
234
+ end
235
+ end
236
+
237
+ unless pending_ids.empty?
238
+ lines << ""
239
+ lines << "## Pending Steps"
240
+ lines << ""
241
+ pending_ids.each do |sid|
242
+ s = step_by_id[sid]
243
+ label = s ? s["label"] : sid
244
+ cp = s && s["checkpoint"]
245
+ note = cp ? " — gates at #{cp}" : ""
246
+ lines << "- **#{label}** (`#{sid}`)#{note}"
247
+ end
248
+ end
249
+
250
+ if status == "waiting_checkpoint" && checkpoint
251
+ lines << ""
252
+ lines << "## Checkpoint: #{cp_label}"
253
+ lines << ""
254
+ lines << "Waiting for user confirmation before advancing."
255
+ end
256
+
257
+ if action_description
258
+ lines << ""
259
+ lines << "## Last Action"
260
+ lines << ""
261
+ lines << "- #{action_description} — #{Time.now.strftime("%Y-%m-%d %H:%M")}"
262
+ end
263
+
264
+ lines << ""
265
+ lines.join("\n")
266
+ end
267
+
268
+ def write_state_file(root, path, state, workflow, artifact_by_path, action_description)
269
+ front = state.to_yaml.sub(/\A---\n/, "")
270
+ body = generate_body(root, state, workflow, artifact_by_path, action_description)
271
+ DevflowControlIO.atomic_write(path, "---\n#{front}---\n\n#{body}")
272
+ end
273
+
274
+ def checkpoint_label(workflow, checkpoint_id)
275
+ checkpoint_id && workflow.fetch("checkpoints", {}).dig(checkpoint_id, "name")
276
+ end
277
+
278
+ def next_intent_path(root, workflow)
279
+ workflow.dig("resume_rules", "continue_keyword", "next_intent_path") || ".planning/.next-intent"
280
+ end
281
+
282
+ def write_next_intent(root, workflow)
283
+ path = File.join(root, next_intent_path(root, workflow))
284
+ DevflowControlIO.atomic_write(path, '{"action":"continue"}')
285
+ path
286
+ end
287
+
288
+ def dependencies_satisfied?(step, completed_ids)
289
+ Array(step["depends_on"]).all? { |dependency| completed_ids.include?(dependency) }
290
+ end
291
+
292
+ def active_track(state)
293
+ track = state["active_track"].to_s
294
+ %w[A B].include?(track) ? track : nil
295
+ end
296
+
297
+ def track_allowed_steps(track)
298
+ case track
299
+ when "A"
300
+ %w[requirement-triage requirement-wayfinder domain-modeling requirement-feasibility-review requirement-baseline api-contract backend-tech-spec api-call-guide]
301
+ when "B"
302
+ %w[requirement-triage requirement-wayfinder domain-modeling requirement-feasibility-review requirement-baseline api-contract ui-spec feature-breakdown frontend-tech-spec api-supplement]
303
+ else
304
+ []
305
+ end
306
+ end
307
+
308
+ def next_pending_step_id(state, pending_ids, step_by_id, completed_ids)
309
+ track = active_track(state)
310
+ return pending_ids.first unless track
311
+
312
+ allowed = track_allowed_steps(track)
313
+ pending_ids.find do |step_id|
314
+ allowed.include?(step_id) &&
315
+ step_by_id[step_id] &&
316
+ dependencies_satisfied?(step_by_id[step_id], completed_ids)
317
+ end
318
+ end
319
+
320
+ def track_boundary?(state, pending_ids)
321
+ track = active_track(state)
322
+ return false unless track
323
+
324
+ (pending_ids & track_allowed_steps(track)).empty? && pending_ids.any?
325
+ end
326
+
327
+ def fail_result(reason, details = {})
328
+ { "ok" => false, "reason" => reason, "details" => details }
329
+ end
330
+
331
+ project_lock = DevflowControlIO.acquire_project_lock(root) if options[:write]
332
+
333
+ begin
334
+ result =
335
+ if !File.exist?(state_path)
336
+ fail_result("missing_state_file", "path" => state_path)
337
+ else
338
+ original_doc = File.read(state_path)
339
+ yaml = front_matter(original_doc)
340
+ if yaml.nil?
341
+ fail_result("missing_state_front_matter", "path" => state_path)
342
+ else
343
+ state = YAML.safe_load(yaml, permitted_classes: [], aliases: false)
344
+ workflow_path, workflow = load_workflow(root, state)
345
+ artifact_by_path = load_artifact_registry(root, workflow)
346
+ steps = workflow.fetch("steps", [])
347
+ step_by_id = steps.to_h { |step| [step.fetch("id"), step] }
348
+ changed = false
349
+ next_intent_written = nil
350
+ actions = []
351
+ action_description = nil
352
+ next_intent_requested = false
353
+ current_revision = Integer(state.fetch("revision", 0))
354
+
355
+ if !options[:expected_revision].nil? && current_revision != options[:expected_revision]
356
+ result = fail_result(
357
+ "stale_revision",
358
+ "expected_revision" => options[:expected_revision],
359
+ "actual_revision" => current_revision
360
+ )
361
+ end
362
+
363
+ if result.nil? && options[:checkpoint_decision]
364
+ state["checkpoint_decision"] = options[:checkpoint_decision]
365
+ changed = true
366
+ actions << "checkpoint_decision_set"
367
+ action_description = "Checkpoint decision set to: #{options[:checkpoint_decision]}"
368
+ end
369
+
370
+ if result.nil? && options[:complete_step]
371
+ step_id = options[:complete_step]
372
+ step = step_by_id[step_id]
373
+ if step.nil?
374
+ result = fail_result("unknown_step", "step" => step_id)
375
+ else
376
+ completed = Array(state["completed_steps"])
377
+ pending = Array(state["pending_steps"])
378
+ completed << step_id unless completed.include?(step_id)
379
+ pending = pending.reject { |id| id == step_id }
380
+
381
+ state["completed_steps"] = completed
382
+ state["pending_steps"] = pending
383
+ state["last_completed_step"] = step_id
384
+ state.delete("checkpoint_decision")
385
+
386
+ if step["checkpoint"]
387
+ state["current_step"] = step_id
388
+ state["status"] = "waiting_checkpoint"
389
+ state["checkpoint"] = step["checkpoint"]
390
+ state["checkpoint_label"] = checkpoint_label(workflow, step["checkpoint"])
391
+ action_description = "Step completed: #{step["label"]} (#{step_id}). Now waiting at #{step["checkpoint"]}."
392
+ elsif track_boundary?(state, pending)
393
+ state["current_step"] = step_id
394
+ state["status"] = "blocked"
395
+ state["block_reason"] = "track_scope_complete"
396
+ state.delete("checkpoint")
397
+ state.delete("checkpoint_label")
398
+ action_description = "Step completed: #{step["label"]} (#{step_id}). Active track output scope is complete."
399
+ elsif (next_id = next_pending_step_id(state, pending, step_by_id, completed))
400
+ state["current_step"] = next_id
401
+ state["status"] = "in_progress"
402
+ state.delete("checkpoint")
403
+ state.delete("checkpoint_label")
404
+ next_step = step_by_id[next_id]
405
+ action_description = "Step completed: #{step["label"]} (#{step_id}). Advanced to #{next_step ? next_step["label"] : next_id}."
406
+ else
407
+ state["current_step"] = step_id
408
+ state["status"] = "completed"
409
+ state.delete("checkpoint")
410
+ state.delete("checkpoint_label")
411
+ action_description = "Step completed: #{step["label"]} (#{step_id}). All steps complete."
412
+ end
413
+
414
+ changed = true
415
+ actions << "step_completed"
416
+ end
417
+ end
418
+
419
+ if result.nil? && options[:confirm_checkpoint]
420
+ if state["status"] != "waiting_checkpoint"
421
+ result = fail_result("not_waiting_checkpoint", "status" => state["status"])
422
+ elsif Array(state["pending_steps"]).empty?
423
+ result = fail_result("no_pending_step")
424
+ else
425
+ pending = Array(state["pending_steps"])
426
+ completed = Array(state["completed_steps"])
427
+ next_id = next_pending_step_id(state, pending, step_by_id, completed)
428
+ if next_id.nil? && track_boundary?(state, pending)
429
+ state["checkpoint_decision"] = "approved"
430
+ state["status"] = "blocked"
431
+ state["block_reason"] = "track_scope_complete"
432
+ state.delete("checkpoint")
433
+ state.delete("checkpoint_label")
434
+ changed = true
435
+ actions << "checkpoint_confirmed_track_complete"
436
+ action_description = "Checkpoint confirmed. Active track output scope is complete."
437
+ next_intent_requested = true
438
+ else
439
+ state["checkpoint_decision"] = "approved"
440
+ state["current_step"] = next_id || pending.first
441
+ state["status"] = "in_progress"
442
+ state.delete("checkpoint")
443
+ state.delete("checkpoint_label")
444
+ changed = true
445
+ actions << "checkpoint_confirmed"
446
+ action_description = "Checkpoint confirmed. Advanced to next step."
447
+ next_intent_requested = true
448
+ end
449
+ end
450
+ end
451
+
452
+ if result.nil? && options[:enter_failure_branch]
453
+ current_step = step_by_id[state["current_step"]]
454
+ branch = current_step && workflow.fetch("failure_branches", {})[current_step["id"]]
455
+ if branch.nil?
456
+ result = fail_result("missing_failure_branch", "current_step" => state["current_step"])
457
+ else
458
+ branch_path = branch.fetch("workflow_config")
459
+ branch_workflow = load_yaml_file(File.join(root, branch_path))
460
+ transition = branch_workflow.dig("state_contract", "suggested_transition") || {}
461
+ state["source_flow"] = state["current_flow"]
462
+ state["source_workflow_config"] = workflow_path
463
+ state["current_flow"] = transition["current_flow"] || branch.fetch("workflow")
464
+ state["workflow_config"] = branch_path
465
+ state["current_step"] = transition["current_step"] || branch_workflow.dig("entry", "initial_step")
466
+ state["status"] = transition["status"] || "in_progress"
467
+ state["completed_steps"] = Array(transition["completed_steps"])
468
+ state["pending_steps"] = Array(transition["pending_steps"])
469
+ state.delete("checkpoint")
470
+ state.delete("checkpoint_label")
471
+ changed = true
472
+ actions << "failure_branch_entered"
473
+ action_description = "Entered failure branch: #{branch["label"] || branch.fetch("workflow")}."
474
+ end
475
+ end
476
+
477
+ if result.nil?
478
+ if changed
479
+ state["state_updated_at"] = Date.today.to_s
480
+ state["revision"] = current_revision + 1
481
+ end
482
+ validation = WorkflowStateValidator.validate(
483
+ root: root,
484
+ state_path: state_path,
485
+ state_override: state,
486
+ strict_artifact_status: false,
487
+ strict_registry_revision: false
488
+ )
489
+
490
+ if changed && !validation["ok"]
491
+ result = fail_result("state_validation_failed", "validation" => validation)
492
+ elsif changed && options[:write]
493
+ sync_artifact_registry(root, workflow, state)
494
+ artifact_by_path = load_artifact_registry(root, workflow)
495
+ write_state_file(root, state_path, state, workflow, artifact_by_path, action_description)
496
+ next_intent_written = write_next_intent(root, workflow) if next_intent_requested
497
+ end
498
+
499
+ result ||= {
500
+ "ok" => true,
501
+ "written" => changed && options[:write],
502
+ "actions" => actions,
503
+ "state_path" => state_path,
504
+ "next_intent_written" => next_intent_written,
505
+ "state_validation" => validation,
506
+ "state" => state
507
+ }
508
+ end
509
+ result
510
+ end
511
+ end
512
+ ensure
513
+ DevflowControlIO.release_lock(project_lock)
514
+ end
515
+
516
+ if options[:json]
517
+ puts JSON.pretty_generate(result)
518
+ else
519
+ puts JSON.pretty_generate(result)
520
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "fileutils"
5
+ require "securerandom"
6
+
7
+ # Shared durability primitives for every writer in the Devflow control plane.
8
+ # The project lock serializes state, workflow, registry, and next-intent updates;
9
+ # atomic rename prevents readers from observing partially written documents.
10
+ module DevflowControlIO
11
+ module_function
12
+
13
+ def acquire_project_lock(root)
14
+ planning_dir = File.join(root, ".planning")
15
+ FileUtils.mkdir_p(planning_dir)
16
+ handle = File.open(File.join(planning_dir, ".devflow.lock"), File::RDWR | File::CREAT, 0o644)
17
+ handle.flock(File::LOCK_EX)
18
+ handle
19
+ end
20
+
21
+ def release_lock(handle)
22
+ return unless handle
23
+
24
+ handle.flock(File::LOCK_UN)
25
+ handle.close
26
+ end
27
+
28
+ def atomic_write(path, content)
29
+ directory = File.dirname(path)
30
+ FileUtils.mkdir_p(directory)
31
+ temporary = File.join(directory, ".#{File.basename(path)}.#{Process.pid}.#{SecureRandom.hex(6)}.tmp")
32
+
33
+ File.open(temporary, File::WRONLY | File::CREAT | File::EXCL, 0o644) do |file|
34
+ file.write(content)
35
+ file.flush
36
+ file.fsync
37
+ end
38
+ File.rename(temporary, path)
39
+ ensure
40
+ File.delete(temporary) if temporary && File.exist?(temporary)
41
+ end
42
+ end