@gong-ym/ai-spec-auto 0.2.14 → 0.2.15
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.
- package/.agents/commands/README.md +33 -33
- package/.agents/commands/claude/spec-start-review.md +88 -88
- package/.agents/commands/codex/spec-continue.md +74 -74
- package/.agents/commands/codex/spec-orchestrate.md +35 -35
- package/.agents/commands/codex/spec-start-review.md +88 -88
- package/.agents/commands/codex/spec-start.md +67 -67
- package/.agents/commands/codex/spec-status.md +22 -22
- package/.agents/commands/codex/spec-stop.md +29 -29
- package/.agents/commands/codex/spec-update.md +40 -40
- package/.agents/commands/common/branch-review.md +117 -117
- package/.agents/commands/common/project-init.md +25 -25
- package/.agents/commands/common/spec-continue.md +74 -74
- package/.agents/commands/common/spec-orchestrate.md +35 -35
- package/.agents/commands/common/spec-start-review.md +82 -82
- package/.agents/commands/common/spec-start.md +67 -67
- package/.agents/commands/common/spec-status.md +22 -22
- package/.agents/commands/common/spec-stop.md +29 -29
- package/.agents/commands/common/spec-update.md +60 -40
- package/.agents/commands/cursor/opsx-apply.md +55 -55
- package/.agents/commands/cursor/opsx-archive.md +48 -48
- package/.agents/commands/cursor/opsx-explore.md +45 -45
- package/.agents/commands/cursor/opsx-propose.md +59 -59
- package/.agents/commands/cursor/spec-continue.md +63 -63
- package/.agents/commands/cursor/spec-orchestrate.md +53 -53
- package/.agents/commands/cursor/spec-start-review.md +78 -78
- package/.agents/commands/cursor/spec-start.md +59 -59
- package/.agents/commands/cursor/spec-status.md +30 -30
- package/.agents/commands/cursor/spec-stop.md +29 -29
- package/.agents/commands/cursor/spec-update.md +41 -41
- package/.agents/flows/FRONTMATTER.md +263 -263
- package/.agents/flows/RUN_OUTPUT.md +263 -263
- package/.agents/flows/common/README.md +29 -29
- package/.agents/flows/common/bugfix-to-verification.md +95 -95
- package/.agents/flows/common/change-to-architecture-review.md +89 -89
- package/.agents/flows/common/change-to-release.md +94 -94
- package/.agents/flows/common/prd-to-delivery.md +184 -184
- package/.agents/flows/common/requirement-to-observability.md +97 -97
- package/.agents/orchestration/README.md +22 -22
- package/.agents/orchestration/expert-dispatch-spec.md +155 -155
- package/.agents/orchestration/expert-executor-spec.md +84 -84
- package/.agents/orchestration/expert-runtime-action-spec.md +73 -73
- package/.agents/orchestration/runtime-state-handoff-spec.md +264 -264
- package/.agents/orchestration/task-anchor-spec.md +212 -212
- package/.agents/orchestration/task-orchestrator-adapter-payload.md +153 -153
- package/.agents/orchestration/task-orchestrator-bootstrap-payload.md +145 -145
- package/.agents/orchestration/task-orchestrator-output-extractor-spec.md +93 -93
- package/.agents/orchestration/task-orchestrator-run-plan-template.md +312 -312
- package/.agents/orchestration/task-orchestrator-runtime-hooks.md +214 -214
- package/.agents/registry/README.md +63 -63
- package/.agents/registry/flows.json +125 -125
- package/.agents/registry/profiles.json +101 -101
- package/.agents/registry/roles.json +1265 -1265
- package/.agents/registry/rules.json +148 -148
- package/.agents/registry/scenario-packages.json +123 -123
- package/.agents/registry/skills.json +130 -130
- package/.agents/roles/INDEX.md +346 -346
- package/.agents/roles/common/README.md +76 -76
- package/.agents/roles/common/archive-change.md +80 -80
- package/.agents/roles/common/backend-implementer.md +92 -92
- package/.agents/roles/common/code-guardian.md +151 -151
- package/.agents/roles/common/frontend-implementer.md +146 -146
- package/.agents/roles/common/requirement-analyst.md +138 -138
- package/.agents/roles/common/task-orchestrator-routing.md +301 -301
- package/.agents/roles/common/task-orchestrator.md +224 -224
- package/.agents/roles/common/tooling-implementer.md +92 -92
- package/.agents/roles/domains/README.md +35 -35
- package/.agents/roles/domains/delivery/README.md +11 -11
- package/.agents/roles/domains/delivery/container-specialist.md +50 -50
- package/.agents/roles/domains/delivery/deployment-specialist.md +50 -50
- package/.agents/roles/domains/delivery/pipeline-specialist.md +50 -50
- package/.agents/roles/domains/demand-design/README.md +16 -16
- package/.agents/roles/domains/demand-design/api-contract-specialist.md +52 -52
- package/.agents/roles/domains/demand-design/design-collaborator.md +58 -58
- package/.agents/roles/domains/documentation/README.md +11 -11
- package/.agents/roles/domains/documentation/api-doc-specialist.md +50 -50
- package/.agents/roles/domains/documentation/component-doc-specialist.md +49 -49
- package/.agents/roles/domains/documentation/technical-writing-specialist.md +48 -48
- package/.agents/roles/domains/engineering/README.md +17 -17
- package/.agents/roles/domains/engineering/architecture-advisor.md +53 -53
- package/.agents/roles/domains/engineering/build-specialist.md +51 -51
- package/.agents/roles/domains/engineering/dependency-governor.md +52 -52
- package/.agents/roles/domains/governance/README.md +17 -17
- package/.agents/roles/domains/governance/api-governance-specialist.md +51 -51
- package/.agents/roles/domains/governance/lint-policy-specialist.md +49 -49
- package/.agents/roles/domains/governance/route-governance-specialist.md +52 -52
- package/.agents/roles/domains/observability/README.md +11 -11
- package/.agents/roles/domains/observability/error-tracker.md +50 -50
- package/.agents/roles/domains/observability/event-instrumentation-specialist.md +51 -51
- package/.agents/roles/domains/observability/rum-analyst.md +50 -50
- package/.agents/roles/domains/performance/README.md +11 -11
- package/.agents/roles/domains/performance/asset-optimizer.md +50 -50
- package/.agents/roles/domains/performance/performance-auditor.md +56 -56
- package/.agents/roles/domains/performance/vitals-analyst.md +50 -50
- package/.agents/roles/domains/security-a11y/README.md +11 -11
- package/.agents/roles/domains/security-a11y/a11y-auditor.md +50 -50
- package/.agents/roles/domains/security-a11y/aria-specialist.md +51 -51
- package/.agents/roles/domains/security-a11y/security-reviewer.md +49 -49
- package/.agents/roles/domains/testing/README.md +12 -12
- package/.agents/roles/domains/testing/coverage-analyst.md +50 -50
- package/.agents/roles/domains/testing/e2e-test-specialist.md +51 -51
- package/.agents/roles/domains/testing/unit-test-specialist.md +56 -56
- package/.agents/roles/domains/testing/verification-reviewer.md +67 -67
- package/.agents/rules/README.md +87 -87
- package/.agents/rules/common/02-/347/274/226/347/240/201/350/247/204/350/214/203.md +45 -45
- package/.agents/rules/common/08-/351/200/232/347/224/250/347/272/246/346/235/237.md +63 -63
- package/.agents/rules/common/10-/346/226/207/346/241/243/350/247/204/350/214/203.md +101 -101
- package/.agents/rules/common/12-Superpowers/346/211/247/350/241/214/350/247/204/350/214/203.md +46 -46
- package/.agents/rules/common/14-/345/256/241/350/256/241/346/261/207/346/212/245/350/247/204/350/214/203.md +107 -107
- package/.agents/rules/common/15-visual-gate-wait.md +90 -90
- package/.agents/rules/profiles/nestjs/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +27 -27
- package/.agents/rules/profiles/nestjs/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +20 -20
- package/.agents/rules/profiles/nestjs/04-/346/250/241/345/235/227/347/273/223/346/236/204/350/247/204/350/214/203.md +24 -24
- package/.agents/rules/profiles/nestjs/05-/346/216/245/345/217/243/344/270/216/345/245/221/347/272/246/350/247/204/350/214/203.md +24 -24
- package/.agents/rules/profiles/nestjs/06-/346/225/260/346/215/256/350/256/277/351/227/256/350/247/204/350/214/203.md +24 -24
- package/.agents/rules/profiles/nestjs/07-/351/205/215/347/275/256/344/270/216/350/277/220/350/241/214/346/227/266/350/247/204/350/214/203.md +20 -20
- package/.agents/rules/profiles/nestjs/09-/345/274/202/345/270/270/344/270/216/346/227/245/345/277/227/350/247/204/350/214/203.md +20 -20
- package/.agents/rules/profiles/nestjs/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +24 -24
- package/.agents/rules/profiles/nestjs/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +20 -20
- package/.agents/rules/profiles/node-tooling/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +30 -30
- package/.agents/rules/profiles/node-tooling/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +37 -37
- package/.agents/rules/profiles/node-tooling/04-CLI/344/270/216/346/250/241/345/235/227/350/247/204/350/214/203.md +42 -42
- package/.agents/rules/profiles/node-tooling/05-Contract/344/270/216Schema/350/247/204/350/214/203.md +42 -42
- package/.agents/rules/profiles/node-tooling/06-/350/277/220/350/241/214/346/227/266/346/226/207/344/273/266/350/247/204/350/214/203.md +30 -30
- package/.agents/rules/profiles/node-tooling/07-/346/227/245/345/277/227/344/270/216/351/224/231/350/257/257/345/244/204/347/220/206/350/247/204/350/214/203.md +60 -60
- package/.agents/rules/profiles/node-tooling/09-/350/204/232/346/234/254/344/270/216/345/205/245/345/217/243/350/247/204/350/214/203.md +45 -45
- package/.agents/rules/profiles/node-tooling/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +41 -41
- package/.agents/rules/profiles/node-tooling/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +55 -55
- package/.agents/rules/profiles/react/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +29 -29
- package/.agents/rules/profiles/react/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +104 -104
- package/.agents/rules/profiles/react/04-/347/273/204/344/273/266/350/247/204/350/214/203.md +46 -46
- package/.agents/rules/profiles/react/05-API/350/247/204/350/214/203.md +67 -67
- package/.agents/rules/profiles/react/06-/350/267/257/347/224/261/350/247/204/350/214/203.md +54 -54
- package/.agents/rules/profiles/react/07-/347/212/266/346/200/201/347/256/241/347/220/206.md +226 -226
- package/.agents/rules/profiles/react/09-/346/240/267/345/274/217/350/247/204/350/214/203.md +71 -71
- package/.agents/rules/profiles/react/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +80 -80
- package/.agents/rules/profiles/react/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +159 -159
- package/.agents/rules/profiles/springboot/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +31 -31
- package/.agents/rules/profiles/springboot/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +37 -37
- package/.agents/rules/profiles/springboot/04-/345/210/206/345/261/202/350/247/204/350/214/203.md +33 -33
- package/.agents/rules/profiles/springboot/05-/346/216/245/345/217/243/344/270/216/345/245/221/347/272/246/350/247/204/350/214/203.md +51 -51
- package/.agents/rules/profiles/springboot/06-/346/225/260/346/215/256/350/256/277/351/227/256/350/247/204/350/214/203.md +34 -34
- package/.agents/rules/profiles/springboot/07-/351/205/215/347/275/256/344/270/216/350/277/220/350/241/214/346/227/266/350/247/204/350/214/203.md +38 -38
- package/.agents/rules/profiles/springboot/09-/345/274/202/345/270/270/344/270/216/346/227/245/345/277/227/350/247/204/350/214/203.md +48 -48
- package/.agents/rules/profiles/springboot/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +43 -43
- package/.agents/rules/profiles/springboot/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +48 -48
- package/.agents/rules/profiles/vue/01-/351/241/271/347/233/256/346/246/202/350/277/260.md +47 -47
- package/.agents/rules/profiles/vue/03-/351/241/271/347/233/256/347/273/223/346/236/204.md +106 -106
- package/.agents/rules/profiles/vue/04-/347/273/204/344/273/266/350/247/204/350/214/203.md +61 -61
- package/.agents/rules/profiles/vue/05-API/350/247/204/350/214/203.md +67 -67
- package/.agents/rules/profiles/vue/06-/350/267/257/347/224/261/350/247/204/350/214/203.md +69 -69
- package/.agents/rules/profiles/vue/07-/347/212/266/346/200/201/347/256/241/347/220/206.md +93 -93
- package/.agents/rules/profiles/vue/09-/346/240/267/345/274/217/350/247/204/350/214/203.md +67 -67
- package/.agents/rules/profiles/vue/11-/346/265/213/350/257/225/350/247/204/350/214/203.md +80 -80
- package/.agents/rules/profiles/vue/13-/344/273/243/347/240/201/346/240/274/345/274/217/345/214/226/344/270/216/346/243/200/346/237/245.md +159 -159
- package/.agents/skills/README.md +171 -171
- package/.agents/skills/common/archive-change/SKILL.md +180 -180
- package/.agents/skills/common/branch-code-reviewer/SKILL.md +533 -533
- package/.agents/skills/common/branch-code-reviewer/references/business-risk-guide.md +293 -293
- package/.agents/skills/common/branch-code-reviewer/references/html-template-guide.md +121 -121
- package/.agents/skills/common/config-and-secret-scan/SKILL.md +99 -99
- package/.agents/skills/common/create-proposal/SKILL.md +192 -192
- package/.agents/skills/common/create-proposal/evals/evals.json +16 -16
- package/.agents/skills/common/create-proposal/evals/train_queries.json +18 -18
- package/.agents/skills/common/create-proposal/evals/validation_queries.json +18 -18
- package/.agents/skills/common/create-proposal/references/interaction-spec-template.md +42 -42
- package/.agents/skills/common/create-test/SKILL.md +292 -292
- package/.agents/skills/common/dependency-impact-graph/SKILL.md +80 -80
- package/.agents/skills/common/execute-task/SKILL.md +206 -206
- package/.agents/skills/common/execute-task/evals/evals.json +16 -16
- package/.agents/skills/common/execute-task/evals/train_queries.json +18 -18
- package/.agents/skills/common/execute-task/evals/validation_queries.json +18 -18
- package/.agents/skills/common/find-skills/SKILL.md +144 -144
- package/.agents/skills/common/install-ai-spec-auto/SKILL.md +260 -260
- package/.agents/skills/common/install-ai-spec-auto/evals/evals.json +17 -17
- package/.agents/skills/common/install-ai-spec-auto/evals/train_queries.json +18 -18
- package/.agents/skills/common/install-ai-spec-auto/evals/validation_queries.json +18 -18
- package/.agents/skills/common/project-init/SKILL.md +178 -178
- package/.agents/skills/common/project-init/evals/evals.json +16 -16
- package/.agents/skills/common/project-init/evals/train_queries.json +18 -18
- package/.agents/skills/common/project-init/evals/validation_queries.json +18 -18
- package/.agents/skills/common/project-init/references/custom-rule-generation.md +89 -89
- package/.agents/skills/common/project-init/references/deep-scan-rules.md +67 -67
- package/.agents/skills/common/project-init/references/output-contracts.md +71 -71
- package/.agents/skills/common/project-init/references/repo-fact-gathering.md +83 -83
- package/.agents/skills/common/project-init/references/scope-resolution.md +76 -76
- package/.agents/skills/common/project-init/scripts/inspect-project.js +112 -112
- package/.agents/skills/common/skill-creator/LICENSE.txt +201 -201
- package/.agents/skills/common/skill-creator/SKILL.md +370 -370
- package/.agents/skills/common/skill-creator/evals/evals.json +16 -16
- package/.agents/skills/common/skill-creator/evals/train_queries.json +18 -18
- package/.agents/skills/common/skill-creator/evals/validation_queries.json +18 -18
- package/.agents/skills/common/skill-creator/references/output-patterns.md +82 -82
- package/.agents/skills/common/skill-creator/references/workflows.md +27 -27
- package/.agents/skills/common/skill-creator/scripts/init_skill.py +209 -209
- package/.agents/skills/common/skill-creator/scripts/package_skill.py +110 -110
- package/.agents/skills/common/skill-creator/scripts/quick_validate.py +51 -51
- package/.agents/skills/common/skill-optimizer/SKILL.md +102 -102
- package/.agents/skills/common/skill-optimizer/evals/evals.json +16 -16
- package/.agents/skills/common/skill-optimizer/evals/train_queries.json +18 -18
- package/.agents/skills/common/skill-optimizer/evals/validation_queries.json +18 -18
- package/.agents/skills/common/skill-optimizer/references/design-patterns.md +26 -26
- package/.agents/skills/common/skill-optimizer/references/review-checklist.md +22 -22
- package/.agents/skills/common/using-superpowers/SKILL.md +151 -151
- package/.agents/skills/common/wait-for-gate-signal/SKILL.md +85 -85
- package/.agents/skills/domains/README.md +19 -19
- package/.agents/skills/domains/ui-ux-pro-max/SKILL.md +58 -58
- package/.agents/skills/domains/web/design-analysis/SKILL.md +89 -89
- package/.agents/skills/domains/web/design-analysis/rules/analysis-order.md +61 -61
- package/.agents/skills/domains/web/design-analysis/rules/analysis-priorities.md +136 -136
- package/.agents/skills/domains/web/design-analysis/rules/checklist-common-misses.md +107 -107
- package/.agents/skills/domains/web/design-analysis/rules/implementation-common-errors.md +204 -204
- package/.agents/skills/domains/web/design-analysis/rules/implementation-guidelines.md +211 -211
- package/.agents/skills/domains/web/design-analysis/rules/output-analysis-checklist.md +247 -247
- package/.agents/skills/domains/web/design-analysis/rules/tools-design-guidelines.md +108 -108
- package/.agents/skills/domains/web/design-analysis/rules/workflow-element-extraction.md +162 -162
- package/.agents/skills/domains/web/design-analysis/rules/workflow-layout-map.md +131 -131
- package/.agents/skills/domains/web/design-analysis/rules/workflow-output-checklist.md +70 -70
- package/.agents/skills/domains/web/design-analysis/rules/workflow-style-summary.md +91 -91
- package/.agents/skills/domains/web/route-permission-map/SKILL.md +103 -103
- package/.agents/skills/domains/web/ui-verification/SKILL.md +114 -114
- package/.agents/skills/domains/web/ui-verification/evals/evals.json +16 -16
- package/.agents/skills/domains/web/ui-verification/evals/train_queries.json +18 -18
- package/.agents/skills/domains/web/ui-verification/evals/validation_queries.json +18 -18
- package/.agents/skills/domains/web/ui-verification/rules/comparison-content-image.md +34 -34
- package/.agents/skills/domains/web/ui-verification/rules/comparison-content-text.md +30 -30
- package/.agents/skills/domains/web/ui-verification/rules/comparison-hierarchy.md +33 -33
- package/.agents/skills/domains/web/ui-verification/rules/comparison-layout.md +35 -35
- package/.agents/skills/domains/web/ui-verification/rules/errors-alignment.md +42 -42
- package/.agents/skills/domains/web/ui-verification/rules/errors-button-dimensions.md +28 -28
- package/.agents/skills/domains/web/ui-verification/rules/errors-button-position.md +25 -25
- package/.agents/skills/domains/web/ui-verification/rules/errors-css-priority.md +50 -50
- package/.agents/skills/domains/web/ui-verification/rules/errors-flex-column-width.md +46 -46
- package/.agents/skills/domains/web/ui-verification/rules/errors-flex-layout.md +46 -46
- package/.agents/skills/domains/web/ui-verification/rules/errors-grid-container-width.md +44 -44
- package/.agents/skills/domains/web/ui-verification/rules/errors-page-container-width.md +39 -39
- package/.agents/skills/domains/web/ui-verification/rules/tools-browser-navigation.md +53 -53
- package/.agents/skills/domains/web/ui-verification/rules/tools-design-guidelines.md +53 -53
- package/.agents/skills/domains/web/ui-verification/rules/workflow-checklist.md +27 -27
- package/.agents/skills/domains/web/ui-verification/rules/workflow-problem-list.md +56 -56
- package/.agents/skills/domains/web/ui-verification/rules/workflow-reflection.md +44 -44
- package/.agents/skills/domains/web/ui-verification/rules/writing-alignment.md +44 -44
- package/.agents/skills/domains/web/ui-verification/rules/writing-element-completeness.md +63 -63
- package/.agents/skills/domains/web/ui-verification/rules/writing-list-layout.md +75 -75
- package/.agents/skills/domains/web/ui-verification/rules/writing-page-container-width.md +37 -37
- package/.agents/skills/domains/web/web-design-guidelines/SKILL.md +40 -40
- package/.agents/skills/profiles/nestjs/README.md +4 -4
- package/.agents/skills/profiles/node-tooling/README.md +9 -9
- package/.agents/skills/profiles/react/create-api/SKILL.md +145 -145
- package/.agents/skills/profiles/react/create-component/SKILL.md +160 -160
- package/.agents/skills/profiles/react/create-route/SKILL.md +168 -168
- package/.agents/skills/profiles/react/create-store/SKILL.md +262 -262
- package/.agents/skills/profiles/react/theme-variables/SKILL.md +82 -82
- package/.agents/skills/profiles/react/vercel-composition-patterns/AGENTS.md +899 -899
- package/.agents/skills/profiles/react/vercel-composition-patterns/SKILL.md +81 -81
- package/.agents/skills/profiles/react/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -100
- package/.agents/skills/profiles/react/vercel-composition-patterns/rules/architecture-compound-components.md +112 -112
- package/.agents/skills/profiles/react/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -87
- package/.agents/skills/profiles/react/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -100
- package/.agents/skills/profiles/react/vercel-composition-patterns/rules/state-context-interface.md +191 -191
- package/.agents/skills/profiles/react/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -113
- package/.agents/skills/profiles/react/vercel-composition-patterns/rules/state-lift-state.md +125 -125
- package/.agents/skills/profiles/react/vercel-react-best-practices/AGENTS.md +2934 -2934
- package/.agents/skills/profiles/react/vercel-react-best-practices/SKILL.md +136 -136
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -55
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/advanced-init-once.md +42 -42
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/advanced-use-latest.md +39 -39
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-api-routes.md +38 -38
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-defer-await.md +80 -80
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-dependencies.md +51 -51
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-parallel.md +28 -28
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -99
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-barrel-imports.md +59 -59
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-conditional.md +31 -31
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -49
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -35
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/bundle-preload.md +50 -50
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-event-listeners.md +74 -74
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -71
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -48
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/client-swr-dedup.md +56 -56
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -107
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-cache-function-results.md +80 -80
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-cache-property-access.md +28 -28
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-cache-storage.md +70 -70
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-combine-iterations.md +32 -32
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-early-exit.md +50 -50
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -45
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-index-maps.md +37 -37
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-length-check-first.md +49 -49
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-min-max-loop.md +82 -82
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -24
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -57
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-activity.md +26 -26
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -47
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -40
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -38
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -46
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -82
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -30
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -28
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -75
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -39
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-dependencies.md +45 -45
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -40
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-derived-state.md +29 -29
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -74
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -58
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -38
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-memo.md +44 -44
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -45
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -35
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-transitions.md +40 -40
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -73
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -73
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-auth-actions.md +96 -96
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-cache-lru.md +41 -41
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-cache-react.md +76 -76
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-dedup-props.md +65 -65
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -83
- package/.agents/skills/profiles/react/vercel-react-best-practices/rules/server-serialization.md +38 -38
- package/.agents/skills/profiles/springboot/README.md +10 -10
- package/.agents/skills/profiles/vue/create-api/SKILL.md +105 -105
- package/.agents/skills/profiles/vue/create-component/SKILL.md +76 -76
- package/.agents/skills/profiles/vue/create-route/SKILL.md +141 -141
- package/.agents/skills/profiles/vue/create-store/SKILL.md +97 -97
- package/.agents/skills/profiles/vue/create-view/SKILL.md +81 -81
- package/.agents/skills/profiles/vue/theme-variables/SKILL.md +73 -73
- package/.agents/skills/profiles/vue/vue-best-practices/SKILL.md +166 -166
- package/.agents/skills/profiles/vue/vue-best-practices/references/animation-class-based-technique.md +254 -254
- package/.agents/skills/profiles/vue/vue-best-practices/references/animation-state-driven-technique.md +291 -291
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-async.md +97 -97
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-data-flow.md +307 -307
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-fallthrough-attrs.md +174 -174
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-keep-alive.md +137 -137
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-slots.md +216 -216
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-suspense.md +228 -228
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-teleport.md +108 -108
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-transition-group.md +128 -128
- package/.agents/skills/profiles/vue/vue-best-practices/references/component-transition.md +125 -125
- package/.agents/skills/profiles/vue/vue-best-practices/references/composables.md +290 -290
- package/.agents/skills/profiles/vue/vue-best-practices/references/directives.md +162 -162
- package/.agents/skills/profiles/vue/vue-best-practices/references/perf-avoid-component-abstraction-in-lists.md +159 -159
- package/.agents/skills/profiles/vue/vue-best-practices/references/perf-v-once-v-memo-directives.md +182 -182
- package/.agents/skills/profiles/vue/vue-best-practices/references/perf-virtualize-large-lists.md +187 -187
- package/.agents/skills/profiles/vue/vue-best-practices/references/plugins.md +166 -166
- package/.agents/skills/profiles/vue/vue-best-practices/references/reactivity.md +344 -344
- package/.agents/skills/profiles/vue/vue-best-practices/references/render-functions.md +201 -201
- package/.agents/skills/profiles/vue/vue-best-practices/references/sfc.md +310 -310
- package/.agents/skills/profiles/vue/vue-best-practices/references/state-management.md +135 -135
- package/.agents/skills/profiles/vue/vue-best-practices/references/updated-hook-performance.md +187 -187
- package/.agents/templates/common/README.md +23 -23
- package/.agents/templates/common/bugfix.md +22 -22
- package/.agents/templates/common/create-expert-package.md +458 -458
- package/.agents/templates/common/mock-page.md +28 -28
- package/.agents/templates/common/new-component.md +25 -25
- package/.agents/templates/common/new-page.md +31 -31
- package/.cursor/mcp.json +35 -35
- package/.qoder/mcp.json +26 -26
- package/bin/archive-change.js +560 -474
- package/bin/check-command.js +62 -62
- package/bin/cli.js +0 -0
- package/bin/command-template-renderer.js +40 -40
- package/bin/context-command.js +102 -102
- package/bin/demo-runtime-smoke.js +760 -760
- package/bin/execution-semantics.js +821 -821
- package/bin/executor-command.js +93 -93
- package/bin/expert-dispatch.js +334 -334
- package/bin/expert-executor.js +1148 -1148
- package/bin/guard-command.js +52 -52
- package/bin/hub-command.js +876 -876
- package/bin/ide-command.js +242 -242
- package/bin/init-command.js +193 -193
- package/bin/install-workflow.js +35 -3
- package/bin/manifest-export.js +34 -34
- package/bin/profile-registry.js +90 -90
- package/bin/protocol-workflow.js +452 -446
- package/bin/repair-command.js +161 -161
- package/bin/repo-map.js +177 -177
- package/bin/report-command.js +236 -236
- package/bin/runtime-bootstrap.js +428 -428
- package/bin/runtime-embedded.js +101 -101
- package/bin/runtime-fallback.js +106 -106
- package/bin/runtime-launcher.js +116 -116
- package/bin/runtime-paths.js +177 -177
- package/bin/runtime-registry.js +289 -289
- package/bin/runtime-state.js +2541 -2541
- package/bin/scan.js +96 -96
- package/bin/self-upgrade.js +206 -206
- package/bin/skill-spec-validator.js +457 -457
- package/bin/spec-command.js +366 -366
- package/bin/superpowers.js +384 -384
- package/bin/sync-command.js +59 -59
- package/bin/sync.js +1904 -1904
- package/bin/task-orchestrator-adapter.js +341 -341
- package/bin/task-orchestrator-extractor.js +274 -274
- package/bin/task-orchestrator-runner.js +1208 -1208
- package/bin/telemetry/README.md +66 -66
- package/bin/telemetry/aspect.js +153 -153
- package/bin/telemetry/collect.js +67 -67
- package/bin/telemetry/config.js +114 -114
- package/bin/telemetry/defaults.json +5 -5
- package/bin/telemetry/healthcheck.js +195 -195
- package/bin/telemetry/identity.js +53 -53
- package/bin/telemetry/index.js +25 -25
- package/bin/telemetry/reporter.js +83 -83
- package/bin/telemetry/safe.js +39 -39
- package/bin/validate-registry.js +740 -740
- package/bin/visual-bridge-config.js +117 -117
- package/bin/visual-bridge.js +287 -287
- package/bin/visual-command.js +432 -432
- package/bin/worktree-command.js +194 -194
- package/configs/common/.editorconfig +15 -15
- package/configs/common/.husky/commit-msg +4 -4
- package/configs/common/.husky/pre-commit +4 -4
- package/configs/common/.lintstagedrc +11 -11
- package/configs/common/.prettierignore +11 -11
- package/configs/common/.prettierrc.json +11 -11
- package/configs/common/.stylelintignore +14 -14
- package/configs/common/.stylelintrc.json +21 -21
- package/configs/common/commitlint.config.js +3 -3
- package/configs/profiles/nestjs/.gitkeep +1 -1
- package/configs/profiles/node-tooling/.gitkeep +1 -1
- package/configs/profiles/react/.eslintignore +6 -6
- package/configs/profiles/react/.eslintrc.js +16 -16
- package/configs/profiles/react/.stylelintrc.json +18 -18
- package/configs/profiles/springboot/.gitkeep +1 -1
- package/configs/profiles/vue/.eslintignore +6 -6
- package/configs/profiles/vue/.eslintrc.cjs +17 -17
- package/contracts/README.md +28 -28
- package/contracts/fixtures/asset-package.fixture.json +26 -26
- package/contracts/fixtures/asset-usage-feedback.fixture.json +14 -14
- package/contracts/fixtures/evidence-report.fixture.json +28 -28
- package/contracts/fixtures/manifest.fixture.json +20 -20
- package/contracts/fixtures/run-event.fixture.json +15 -15
- package/contracts/schemas/asset-package.schema.json +76 -76
- package/contracts/schemas/asset-usage-feedback.schema.json +57 -57
- package/contracts/schemas/evidence-report.schema.json +60 -60
- package/contracts/schemas/manifest.schema.json +63 -63
- package/contracts/schemas/run-event.schema.json +72 -72
- package/install.ps1 +35 -35
- package/install.sh +17 -17
- package/internal/ai-protocol-workflow.js +5824 -5600
- package/internal/hub-client.js +98 -98
- package/internal/hub-sync-selection.js +69 -69
- package/internal/visual-hooks/README.md +481 -481
- package/internal/visual-hooks/config-loader.js +218 -218
- package/internal/visual-hooks/control-puller.js +206 -206
- package/internal/visual-hooks/gate-signal.js +150 -150
- package/internal/visual-hooks/inbox-consumer.js +469 -469
- package/internal/visual-hooks/index.js +197 -197
- package/internal/visual-hooks/push-client.js +189 -189
- package/internal/visual-hooks/receipt-pusher.js +176 -176
- package/internal/visual-hooks/runtime-state-pusher.js +128 -128
- package/openspec/config.yaml.template +52 -52
- package/openspec/schemas/expert-delivery/schema.yaml +68 -68
- package/openspec/schemas/expert-delivery/templates/checklist.md +39 -39
- package/openspec/schemas/expert-delivery/templates/design.md +61 -61
- package/openspec/schemas/expert-delivery/templates/iterations.md +25 -25
- package/openspec/schemas/expert-delivery/templates/proposal.md +45 -45
- package/openspec/schemas/expert-delivery/templates/spec.md +29 -29
- package/openspec/schemas/expert-delivery/templates/tasks.md +24 -24
- package/package.json +1 -1
- package/scripts/acceptance-zero-intrusion.sh +168 -168
- package/scripts/hub-sync-assets.config.example.json +296 -296
- package/scripts/hub-sync-assets.js +2038 -2038
- package/scripts/local-verify.sh +280 -280
- package/scripts/post-publish-auto-fix-check.js +404 -404
- package/scripts/post-publish-verify.sh +175 -175
- package/scripts/setup-cursor-manual-test.sh +107 -107
- package/scripts/setup-cursor-spec-archive-test.sh +111 -111
- package/scripts/setup-visual-integration.sh +225 -225
- package/scripts/test-integration.sh +176 -176
- package/scripts/update-test-project.sh +93 -93
- package/scripts/upload-four-web.sh +57 -57
- package/scripts/verify-install-ps1-bom.js +26 -26
- package/src/agent/agent-context.js +259 -259
- package/src/agent/agent-profile.js +185 -185
- package/src/agent/agent-templates.js +161 -161
- package/src/agent/agent-types.js +108 -108
- package/src/agent/collaboration-protocol.js +333 -333
- package/src/agent/conflict-handler.js +364 -364
- package/src/agent/file-permission.js +121 -121
- package/src/agent/index.js +38 -38
- package/src/agent/permission-audit.js +151 -151
- package/src/agent/review-repair-loop.js +270 -270
- package/src/agent/tool-permission.js +101 -101
- package/src/asset/asset-dependency.js +322 -322
- package/src/asset/asset-feedback.js +350 -350
- package/src/asset/asset-fork.js +300 -300
- package/src/asset/asset-install.js +278 -278
- package/src/asset/asset-installer.js +497 -497
- package/src/asset/asset-lifecycle.js +324 -324
- package/src/asset/asset-manager.js +245 -245
- package/src/asset/asset-package-manager.js +349 -349
- package/src/asset/asset-package.js +186 -186
- package/src/asset/asset-quality.js +262 -262
- package/src/asset/asset-registry.js +387 -387
- package/src/asset/asset-version.js +293 -293
- package/src/asset/index.js +86 -86
- package/src/cache/agent-profile-cache.js +59 -59
- package/src/cache/asset-cache.js +63 -63
- package/src/cache/global-cache.js +61 -61
- package/src/cache/manifest-cache.js +30 -30
- package/src/check/check-service.js +32 -32
- package/src/config/config-layer.js +343 -343
- package/src/config/config-loader.js +60 -60
- package/src/config/defaults.js +49 -49
- package/src/connectors/hub/asset-package.js +72 -72
- package/src/connectors/hub/asset-usage-feedback.js +46 -46
- package/src/connectors/hub/hub-connector.js +44 -44
- package/src/connectors/hub/index.js +21 -21
- package/src/connectors/visual/evidence-report.js +49 -49
- package/src/connectors/visual/index.js +15 -15
- package/src/connectors/visual/queue.js +41 -41
- package/src/connectors/visual/run-event.js +81 -81
- package/src/connectors/visual/visual-connector.js +77 -77
- package/src/context/context-budget.js +59 -59
- package/src/context/context-builder.js +285 -285
- package/src/context/context-loader.js +116 -116
- package/src/context/context-planner.js +158 -158
- package/src/context/types.js +96 -96
- package/src/contracts/index.js +63 -63
- package/src/executor/executor-registry.js +78 -78
- package/src/executor/executor-result-parser.js +44 -44
- package/src/executor/executor-runner.js +141 -141
- package/src/executor/executor-selector.js +139 -139
- package/src/executor/executor-timeout.js +36 -36
- package/src/executor/providers/base-provider-utils.js +189 -189
- package/src/executor/providers/claude-code-executor-provider.js +128 -128
- package/src/executor/providers/codex-executor-provider.js +126 -126
- package/src/executor/providers/cursor-executor-provider.js +99 -99
- package/src/executor/types.js +137 -137
- package/src/git/branch-manager.js +71 -71
- package/src/git/dirty-checker.js +43 -43
- package/src/git/dirty-strategy-handler.js +29 -29
- package/src/git/git-command.js +37 -37
- package/src/git/git-repository-detector.js +45 -45
- package/src/git/multi-repo-worktree-planner.js +88 -88
- package/src/git/policy.js +19 -19
- package/src/git/strategies/block-dirty-strategy.js +34 -34
- package/src/git/strategies/ignore-dirty-strategy.js +33 -33
- package/src/git/strategies/patch-snapshot-strategy.js +53 -53
- package/src/git/strategies/wip-commit-strategy.js +38 -38
- package/src/git/types.js +71 -71
- package/src/git/worktree-manager.js +85 -85
- package/src/governance/asset-review.js +351 -351
- package/src/governance/audit-log.js +368 -368
- package/src/governance/gray-release.js +312 -312
- package/src/governance/index.js +31 -31
- package/src/governance/policy-types.js +56 -56
- package/src/governance/rbac-types.js +171 -171
- package/src/governance/rbac.js +382 -382
- package/src/governance/rollback.js +360 -360
- package/src/governance/security-policy.js +354 -354
- package/src/hook/hook-config-writer.js +125 -125
- package/src/hub/hub-client.js +186 -186
- package/src/hub/hub-config.js +39 -39
- package/src/hub/project-facts.js +31 -31
- package/src/hub/runtime-feedback-reporter.js +55 -55
- package/src/ide/adapters/adapter-protocol.js +385 -385
- package/src/ide/adapters/claude-adapter.js +419 -419
- package/src/ide/adapters/codex-adapter.js +60 -60
- package/src/ide/adapters/cursor-adapter.js +484 -484
- package/src/ide/adapters/index.js +24 -24
- package/src/ide/anchors/markdown-anchor-writer.js +152 -152
- package/src/ide/ide-service.js +270 -270
- package/src/ide/ide-types.js +94 -94
- package/src/ide/links/link-mode-resolver.js +160 -160
- package/src/ide/registry/ide-registry-builder.js +165 -165
- package/src/incident/incident-writer.js +47 -47
- package/src/incident/types.js +22 -22
- package/src/init/ide-linker.js +126 -126
- package/src/init/ide-pointer-injector.js +75 -75
- package/src/init/init-applier.js +197 -197
- package/src/init/init-plan.js +294 -294
- package/src/init/init-service.js +65 -65
- package/src/init/manifest-installer.js +302 -302
- package/src/init/types.js +26 -26
- package/src/project/config-writer.js +83 -83
- package/src/project/context-index-writer.js +82 -82
- package/src/project/json-utils.js +72 -72
- package/src/project/local-state-writer.js +50 -50
- package/src/project/lock-file-writer.js +98 -98
- package/src/project/manifest-writer.js +126 -126
- package/src/project/policy-config-writer.js +91 -91
- package/src/project/project-config-writer.js +74 -74
- package/src/project/project-files.js +39 -39
- package/src/project/registry-index-writer.js +43 -43
- package/src/project/workspace-config-writer.js +63 -63
- package/src/run/index.js +11 -11
- package/src/run/run-id.js +32 -32
- package/src/run/run-service.js +269 -269
- package/src/run/run-store.js +80 -80
- package/src/scanner/aggregator/detection-aggregator.js +23 -23
- package/src/scanner/boundary/boundary-resolver.js +229 -229
- package/src/scanner/detectors/detector-registry.js +44 -44
- package/src/scanner/detectors/fastapi-detector.js +46 -46
- package/src/scanner/detectors/go-detector.js +46 -46
- package/src/scanner/detectors/nestjs-detector.js +57 -57
- package/src/scanner/detectors/nextjs-detector.js +52 -52
- package/src/scanner/detectors/react-vite-detector.js +52 -52
- package/src/scanner/detectors/react-webpack-detector.js +57 -57
- package/src/scanner/detectors/springboot-detector.js +46 -46
- package/src/scanner/detectors/springcloud-detector.js +46 -46
- package/src/scanner/detectors/springmvc-detector.js +46 -46
- package/src/scanner/detectors/vue-vite-detector.js +52 -52
- package/src/scanner/engine.js +72 -72
- package/src/scanner/facts/fact-extractor.js +211 -211
- package/src/scanner/types.js +30 -30
- package/src/security/asset-tamper-checker.js +188 -188
- package/src/security/checksum.js +40 -40
- package/src/spec/spec-writer.js +302 -302
- package/src/state-machine/circuit-breaker.js +112 -112
- package/src/state-machine/escape-hatch.js +49 -49
- package/src/state-machine/stage-runner.js +281 -281
- package/src/state-machine/state-machine.js +24 -24
- package/src/state-machine/transition-guard.js +36 -36
- package/src/state-machine/types.js +37 -37
- package/src/sync/sync-service.js +192 -192
- package/src/visual/agent-visual.js +142 -142
- package/src/visual/event-gateway.js +357 -357
- package/src/visual/event-mapper.js +128 -128
- package/src/visual/hook-dashboard.js +216 -216
- package/src/visual/index.js +27 -27
- package/src/visual/metrics.js +287 -287
- package/src/visual/privacy-filter.js +100 -100
- package/src/visual/risk-board.js +252 -252
- package/src/visual/timeline.js +245 -245
- package/src/visual/visual-client.js +94 -94
- package/src/visual/visual-config.js +40 -40
- package/src/visual/visual-reporter.js +88 -88
package/bin/expert-executor.js
CHANGED
|
@@ -1,1148 +1,1148 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { spawnSync } = require('child_process');
|
|
5
|
-
const runtimeState = require('./runtime-state');
|
|
6
|
-
const expertDispatch = require('./expert-dispatch');
|
|
7
|
-
const { archiveChange } = require('./archive-change');
|
|
8
|
-
const {
|
|
9
|
-
getRoleArtifactRequirements,
|
|
10
|
-
inferExecutionOpenSpecAction,
|
|
11
|
-
inferRuntimeActionOpenSpecAction,
|
|
12
|
-
buildAutoRuntimeAction,
|
|
13
|
-
guardRuntimeActionForIncompleteExecution,
|
|
14
|
-
} = require('./execution-semantics');
|
|
15
|
-
const {
|
|
16
|
-
resolveRuntimePaths,
|
|
17
|
-
getCandidatePaths,
|
|
18
|
-
getExistingPath,
|
|
19
|
-
shouldPersistHistory,
|
|
20
|
-
} = require('./runtime-paths');
|
|
21
|
-
const { drainVisualRuntimeStatePushes } = require('../internal/visual-hooks/runtime-state-pusher');
|
|
22
|
-
|
|
23
|
-
function printUsage() {
|
|
24
|
-
console.log(`Usage:
|
|
25
|
-
ai-spec-auto expert-executor apply --payload <file> [options]
|
|
26
|
-
ai-spec-auto expert-executor apply --stdin [options]
|
|
27
|
-
ai-spec-auto expert-executor apply-action --payload <file> [options]
|
|
28
|
-
ai-spec-auto expert-executor apply-action --stdin [options]
|
|
29
|
-
ai-spec-auto expert-executor clear [options]
|
|
30
|
-
ai-spec-auto expert-executor clear-action [options]
|
|
31
|
-
|
|
32
|
-
Options:
|
|
33
|
-
--target <dir> Target project directory (default: .)
|
|
34
|
-
--payload <file> Path to payload JSON file
|
|
35
|
-
--stdin Read payload JSON from stdin
|
|
36
|
-
--advance-runtime Persist payload and apply inferred runtime-state mutation
|
|
37
|
-
--json Print JSON result only
|
|
38
|
-
--pretty Print readable summary (default)
|
|
39
|
-
--help Show this help
|
|
40
|
-
`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function parseArgs(argv) {
|
|
44
|
-
const args = [...argv];
|
|
45
|
-
const command = args.shift();
|
|
46
|
-
const options = {
|
|
47
|
-
target: '.',
|
|
48
|
-
pretty: true,
|
|
49
|
-
json: false,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
while (args.length > 0) {
|
|
53
|
-
const arg = args.shift();
|
|
54
|
-
switch (arg) {
|
|
55
|
-
case '--target':
|
|
56
|
-
options.target = args.shift();
|
|
57
|
-
break;
|
|
58
|
-
case '--payload':
|
|
59
|
-
options.payload = args.shift();
|
|
60
|
-
break;
|
|
61
|
-
case '--stdin':
|
|
62
|
-
options.stdin = true;
|
|
63
|
-
break;
|
|
64
|
-
case '--advance-runtime':
|
|
65
|
-
options.advanceRuntime = true;
|
|
66
|
-
break;
|
|
67
|
-
case '--json':
|
|
68
|
-
options.json = true;
|
|
69
|
-
options.pretty = false;
|
|
70
|
-
break;
|
|
71
|
-
case '--pretty':
|
|
72
|
-
options.pretty = true;
|
|
73
|
-
options.json = false;
|
|
74
|
-
break;
|
|
75
|
-
case '--help':
|
|
76
|
-
case '-h':
|
|
77
|
-
options.help = true;
|
|
78
|
-
break;
|
|
79
|
-
default:
|
|
80
|
-
throw new Error(`Unknown argument: ${arg}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return { command, options };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function ensureDir(dirPath) {
|
|
88
|
-
fs.mkdirSync(dirPath, { recursive: true });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function writeJson(filePath, value) {
|
|
92
|
-
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function writeText(filePath, value) {
|
|
96
|
-
fs.writeFileSync(filePath, `${value}\n`, 'utf8');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function readJson(filePath, label) {
|
|
100
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
101
|
-
try {
|
|
102
|
-
return JSON.parse(raw);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
throw new Error(`${label} is not valid JSON: ${filePath}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function readJsonFromStdin(label) {
|
|
109
|
-
const raw = fs.readFileSync(0, 'utf8');
|
|
110
|
-
if (!raw.trim()) {
|
|
111
|
-
throw new Error(`${label} stdin is empty`);
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
return JSON.parse(raw);
|
|
115
|
-
} catch (error) {
|
|
116
|
-
throw new Error(`${label} stdin is not valid JSON`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function createStampedId(prefix, suffix = '', now = new Date()) {
|
|
121
|
-
const iso = now.toISOString().replace(/[:.]/g, '-');
|
|
122
|
-
return suffix ? `${iso}__${suffix}` : `${prefix}_${iso}`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function normalizeList(value) {
|
|
126
|
-
if (!value) return [];
|
|
127
|
-
if (Array.isArray(value)) return value.filter(Boolean);
|
|
128
|
-
return [String(value)].filter(Boolean);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function loadPackageManifest(targetDir) {
|
|
132
|
-
const packagePath = path.join(targetDir, 'package.json');
|
|
133
|
-
if (!fs.existsSync(packagePath)) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
return readJson(packagePath, 'package.json');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function detectPackageManager(targetDir) {
|
|
140
|
-
if (fs.existsSync(path.join(targetDir, 'pnpm-lock.yaml'))) {
|
|
141
|
-
return 'pnpm';
|
|
142
|
-
}
|
|
143
|
-
if (fs.existsSync(path.join(targetDir, 'yarn.lock'))) {
|
|
144
|
-
return 'yarn';
|
|
145
|
-
}
|
|
146
|
-
if (fs.existsSync(path.join(targetDir, 'package-lock.json'))) {
|
|
147
|
-
return 'npm';
|
|
148
|
-
}
|
|
149
|
-
return 'npm';
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function trimOutput(value, maxLength = 400) {
|
|
153
|
-
const text = String(value || '').trim();
|
|
154
|
-
if (!text) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function buildVerificationCommand(packageManager, stepName) {
|
|
161
|
-
if (packageManager === 'yarn') {
|
|
162
|
-
return {
|
|
163
|
-
command: 'yarn',
|
|
164
|
-
args: [stepName],
|
|
165
|
-
printable: `yarn ${stepName}`,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
command: packageManager,
|
|
171
|
-
args: ['run', stepName],
|
|
172
|
-
printable: `${packageManager} run ${stepName}`,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function runVerificationSuite(targetDir) {
|
|
177
|
-
const pkg = loadPackageManifest(targetDir);
|
|
178
|
-
const scripts = pkg?.scripts && typeof pkg.scripts === 'object' ? pkg.scripts : {};
|
|
179
|
-
const packageManager = detectPackageManager(targetDir);
|
|
180
|
-
const stepNames = ['build', 'lint', 'test'];
|
|
181
|
-
const steps = [];
|
|
182
|
-
|
|
183
|
-
for (const stepName of stepNames) {
|
|
184
|
-
if (typeof scripts[stepName] !== 'string' || !scripts[stepName].trim()) {
|
|
185
|
-
steps.push({
|
|
186
|
-
name: stepName,
|
|
187
|
-
status: 'skipped',
|
|
188
|
-
reason: `package.json scripts.${stepName} 未定义`,
|
|
189
|
-
});
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const command = buildVerificationCommand(packageManager, stepName);
|
|
194
|
-
const result = spawnSync(command.command, command.args, {
|
|
195
|
-
cwd: targetDir,
|
|
196
|
-
encoding: 'utf8',
|
|
197
|
-
env: process.env,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
if (result.error) {
|
|
201
|
-
steps.push({
|
|
202
|
-
name: stepName,
|
|
203
|
-
command: command.printable,
|
|
204
|
-
status: 'failed',
|
|
205
|
-
exit_code: typeof result.status === 'number' ? result.status : null,
|
|
206
|
-
error: result.error.message,
|
|
207
|
-
});
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
steps.push({
|
|
212
|
-
name: stepName,
|
|
213
|
-
command: command.printable,
|
|
214
|
-
status: result.status === 0 ? 'passed' : 'failed',
|
|
215
|
-
exit_code: typeof result.status === 'number' ? result.status : null,
|
|
216
|
-
stdout_excerpt: trimOutput(result.stdout),
|
|
217
|
-
stderr_excerpt: trimOutput(result.stderr),
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const summary = steps.reduce((accumulator, step) => {
|
|
222
|
-
const key = step.status === 'passed' || step.status === 'failed' ? step.status : 'skipped';
|
|
223
|
-
accumulator[key] += 1;
|
|
224
|
-
return accumulator;
|
|
225
|
-
}, { passed: 0, failed: 0, skipped: 0 });
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
schema_version: 1,
|
|
229
|
-
kind: 'verification',
|
|
230
|
-
auto_generated: true,
|
|
231
|
-
generated_at: new Date().toISOString(),
|
|
232
|
-
package_manager: packageManager,
|
|
233
|
-
overall_status: summary.failed > 0 ? 'failed' : summary.passed > 0 ? 'passed' : 'skipped',
|
|
234
|
-
steps,
|
|
235
|
-
summary,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function shouldWriteRuntimeMarkdown() {
|
|
240
|
-
return shouldPersistHistory() || process.env.AI_SPEC_WRITE_RUNTIME_MD === '1';
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function readJsonIfExists(filePath) {
|
|
244
|
-
if (!fs.existsSync(filePath)) {
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return readJson(filePath, 'json');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function resolveRuntimeContext(targetDir) {
|
|
252
|
-
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
253
|
-
return {
|
|
254
|
-
runtimePaths,
|
|
255
|
-
currentRun: readJsonIfExists(runtimePaths.currentRun.path),
|
|
256
|
-
currentDispatch: readJsonIfExists(getExistingPath(runtimePaths.currentDispatch)),
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function shouldAdvanceRuntime(options = {}) {
|
|
261
|
-
return options.advanceRuntime === true;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function buildExecutionArtifactMap(changeId, artifacts = {}, options = {}) {
|
|
265
|
-
const flowId = String(options.flowId || '').trim();
|
|
266
|
-
const runId = String(options.runId || '').trim();
|
|
267
|
-
const traceMode = String(options.traceMode || '').trim();
|
|
268
|
-
const implementationNotes = artifacts.implementation_notes || artifacts.implementationNotes || null;
|
|
269
|
-
|
|
270
|
-
if ((flowId === 'bugfix-to-verification' || traceMode === 'direct-fix') && runId) {
|
|
271
|
-
const historyDir = `.ai-spec/history/${runId}`;
|
|
272
|
-
return {
|
|
273
|
-
proposal: null,
|
|
274
|
-
specs: null,
|
|
275
|
-
design: null,
|
|
276
|
-
tasks: null,
|
|
277
|
-
bugfix: artifacts.bugfix || `${historyDir}/bugfix.md`,
|
|
278
|
-
implementation_notes: implementationNotes || `${historyDir}/implementation-notes.md`,
|
|
279
|
-
checklist: artifacts.checklist || `${historyDir}/checklist.md`,
|
|
280
|
-
iterations: artifacts.iterations || `${historyDir}/iterations.md`,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (!changeId) {
|
|
285
|
-
return {
|
|
286
|
-
proposal: null,
|
|
287
|
-
specs: null,
|
|
288
|
-
design: null,
|
|
289
|
-
tasks: null,
|
|
290
|
-
bugfix: artifacts.bugfix || null,
|
|
291
|
-
implementation_notes: implementationNotes,
|
|
292
|
-
checklist: artifacts.checklist || null,
|
|
293
|
-
iterations: artifacts.iterations || null,
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const baseDir = `openspec/changes/${changeId}`;
|
|
298
|
-
return {
|
|
299
|
-
proposal: artifacts.proposal || `${baseDir}/proposal.md`,
|
|
300
|
-
specs: runtimeState.normalizeSpecsArtifactPath(artifacts.specs || `${baseDir}/specs`),
|
|
301
|
-
design: artifacts.design || `${baseDir}/design.md`,
|
|
302
|
-
tasks: artifacts.tasks || `${baseDir}/tasks.md`,
|
|
303
|
-
bugfix: artifacts.bugfix || null,
|
|
304
|
-
implementation_notes: implementationNotes,
|
|
305
|
-
checklist: artifacts.checklist || `${baseDir}/checklist.md`,
|
|
306
|
-
iterations: artifacts.iterations || `${baseDir}/iterations.md`,
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function hydrateExecutionPayload(targetDir, payload) {
|
|
311
|
-
const hydrated = JSON.parse(JSON.stringify(payload || {}));
|
|
312
|
-
const context = resolveRuntimeContext(targetDir);
|
|
313
|
-
const { currentRun, currentDispatch } = context;
|
|
314
|
-
|
|
315
|
-
hydrated.run_id = hydrated.run_id || currentDispatch?.run_id || currentRun?.run_id || null;
|
|
316
|
-
hydrated.dispatch_id = hydrated.dispatch_id || currentDispatch?.dispatch_id || null;
|
|
317
|
-
hydrated.role = typeof hydrated.role === 'object' && hydrated.role ? hydrated.role : {};
|
|
318
|
-
hydrated.role.id = hydrated.role.id || currentDispatch?.role?.id || null;
|
|
319
|
-
hydrated.role.name = hydrated.role.name || currentDispatch?.role?.name || null;
|
|
320
|
-
hydrated.flow = typeof hydrated.flow === 'object' && hydrated.flow ? hydrated.flow : {};
|
|
321
|
-
hydrated.flow.id = hydrated.flow.id || currentDispatch?.flow?.id || currentRun?.flow?.id || null;
|
|
322
|
-
hydrated.task = typeof hydrated.task === 'object' && hydrated.task ? hydrated.task : {};
|
|
323
|
-
hydrated.task.change_id =
|
|
324
|
-
hydrated.task.change_id ||
|
|
325
|
-
currentDispatch?.task?.change_id ||
|
|
326
|
-
currentRun?.task?.change_id ||
|
|
327
|
-
currentRun?.anchor?.task?.change_id ||
|
|
328
|
-
null;
|
|
329
|
-
hydrated.task.trace_mode =
|
|
330
|
-
hydrated.task.trace_mode ||
|
|
331
|
-
currentRun?.task?.trace_mode ||
|
|
332
|
-
currentRun?.incremental_update?.trace_mode ||
|
|
333
|
-
null;
|
|
334
|
-
|
|
335
|
-
const artifactMap = buildExecutionArtifactMap(
|
|
336
|
-
hydrated.task.change_id,
|
|
337
|
-
currentRun?.artifacts || {},
|
|
338
|
-
{
|
|
339
|
-
flowId: hydrated.flow.id,
|
|
340
|
-
runId: hydrated.run_id,
|
|
341
|
-
traceMode: hydrated.task.trace_mode,
|
|
342
|
-
},
|
|
343
|
-
);
|
|
344
|
-
hydrated.artifacts = {
|
|
345
|
-
...artifactMap,
|
|
346
|
-
...(typeof hydrated.artifacts === 'object' && hydrated.artifacts ? hydrated.artifacts : {}),
|
|
347
|
-
};
|
|
348
|
-
hydrated.openspec_action = hydrated.openspec_action || inferExecutionOpenSpecAction(hydrated, targetDir);
|
|
349
|
-
|
|
350
|
-
return {
|
|
351
|
-
payload: hydrated,
|
|
352
|
-
context,
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function hydrateRuntimeActionPayload(targetDir, payload) {
|
|
357
|
-
const hydrated = JSON.parse(JSON.stringify(payload || {}));
|
|
358
|
-
const context = resolveRuntimeContext(targetDir);
|
|
359
|
-
const { currentRun } = context;
|
|
360
|
-
|
|
361
|
-
hydrated.run_id = hydrated.run_id || currentRun?.run_id || null;
|
|
362
|
-
hydrated.from_role = hydrated.from_role || currentRun?.current_role || null;
|
|
363
|
-
hydrated.to_role = hydrated.to_role || null;
|
|
364
|
-
hydrated.openspec_action = hydrated.openspec_action || inferRuntimeActionOpenSpecAction(hydrated);
|
|
365
|
-
|
|
366
|
-
return {
|
|
367
|
-
payload: hydrated,
|
|
368
|
-
context,
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function collectMissingArtifacts(targetDir, artifactMap, keys) {
|
|
373
|
-
return keys
|
|
374
|
-
.map((key) => artifactMap[key])
|
|
375
|
-
.filter((relPath) => !relPath || !fs.existsSync(path.join(targetDir, relPath)));
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function validateExecutionArtifacts(targetDir, payload) {
|
|
379
|
-
const flowId = payload.flow?.id || null;
|
|
380
|
-
const changeId = payload.task?.change_id || null;
|
|
381
|
-
if (flowId === 'prd-to-delivery' && !changeId) {
|
|
382
|
-
throw new Error(
|
|
383
|
-
`Execution payload for ${payload.role.id} requires task.change_id or current-run.task.change_id to resolve OpenSpec artifacts`,
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const artifactMap = buildExecutionArtifactMap(changeId, payload.artifacts || {}, {
|
|
388
|
-
flowId,
|
|
389
|
-
runId: payload.run_id,
|
|
390
|
-
traceMode: payload.task?.trace_mode || null,
|
|
391
|
-
});
|
|
392
|
-
const requirements = getRoleArtifactRequirements(targetDir, payload.role.id, flowId);
|
|
393
|
-
const requiredInputs = requirements.required_inputs;
|
|
394
|
-
const requiredOutputs = requirements.required_outputs;
|
|
395
|
-
const missingInputs = collectMissingArtifacts(targetDir, artifactMap, requiredInputs);
|
|
396
|
-
const missingOutputs = collectMissingArtifacts(targetDir, artifactMap, requiredOutputs);
|
|
397
|
-
|
|
398
|
-
if (missingInputs.length > 0) {
|
|
399
|
-
throw new Error(
|
|
400
|
-
`Execution payload for ${payload.role.id} is missing required inputs: ${missingInputs.join(', ')}`,
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
if (missingOutputs.length > 0) {
|
|
404
|
-
throw new Error(
|
|
405
|
-
`Execution payload for ${payload.role.id} is missing required artifacts: ${missingOutputs.join(', ')}`,
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return {
|
|
410
|
-
change_id: changeId,
|
|
411
|
-
openspec_action: payload.openspec_action || null,
|
|
412
|
-
required_inputs: requiredInputs.map((key) => artifactMap[key]),
|
|
413
|
-
required_outputs: requiredOutputs.map((key) => artifactMap[key]),
|
|
414
|
-
artifact_map: artifactMap,
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
function shouldTriggerArchiveChange(payload) {
|
|
419
|
-
const roleId = payload?.role?.id || null;
|
|
420
|
-
const status = String(payload?.status || '').trim().toLowerCase();
|
|
421
|
-
return roleId === 'archive-change' && ['done', 'success', 'completed'].includes(status);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function maybeApplyArchiveChange(targetDir, payload) {
|
|
425
|
-
if (!shouldTriggerArchiveChange(payload)) {
|
|
426
|
-
return null;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
return archiveChange({
|
|
430
|
-
target: targetDir,
|
|
431
|
-
changeId: payload.task?.change_id || null,
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
function renderExecutionMarkdown(payload) {
|
|
436
|
-
if (payload.markdown && typeof payload.markdown === 'string') {
|
|
437
|
-
return payload.markdown.trim();
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const lines = [];
|
|
441
|
-
lines.push('# 当前专家执行载荷');
|
|
442
|
-
lines.push('');
|
|
443
|
-
lines.push(`- run_id(运行 ID): ${payload.run_id || 'n/a'}`);
|
|
444
|
-
lines.push(`- role(专家角色): ${payload.role?.id || 'n/a'}${payload.role?.name ? `(${payload.role.name})` : ''}`);
|
|
445
|
-
if (payload.openspec_action) {
|
|
446
|
-
lines.push(`- openspec_action(OpenSpec 动作): ${payload.openspec_action}`);
|
|
447
|
-
}
|
|
448
|
-
lines.push(`- execution_id(执行 ID): ${payload.execution_id || 'n/a'}`);
|
|
449
|
-
lines.push(`- status(状态): ${payload.status || 'n/a'}`);
|
|
450
|
-
if (payload.flow?.id) lines.push(`- flow(流程模板): ${payload.flow.id}`);
|
|
451
|
-
lines.push('');
|
|
452
|
-
lines.push('## 执行摘要');
|
|
453
|
-
const steps = normalizeList(payload.execution_plan?.execution_steps);
|
|
454
|
-
if (steps.length === 0) {
|
|
455
|
-
lines.push('- 无');
|
|
456
|
-
} else {
|
|
457
|
-
for (const step of steps) {
|
|
458
|
-
lines.push(`- ${step}`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return lines.join('\n').trim();
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
function renderRuntimeActionMarkdown(payload) {
|
|
465
|
-
if (payload.markdown && typeof payload.markdown === 'string') {
|
|
466
|
-
return payload.markdown.trim();
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
const lines = [];
|
|
470
|
-
lines.push('# 当前运行动作草案');
|
|
471
|
-
lines.push('');
|
|
472
|
-
lines.push(`- run_id(运行 ID): ${payload.run_id || 'n/a'}`);
|
|
473
|
-
lines.push(`- action(动作): ${payload.action || 'n/a'}`);
|
|
474
|
-
if (payload.openspec_action) {
|
|
475
|
-
lines.push(`- openspec_action(OpenSpec 动作): ${payload.openspec_action}`);
|
|
476
|
-
}
|
|
477
|
-
lines.push(`- from_role(来源专家): ${payload.from_role || 'n/a'}`);
|
|
478
|
-
if (payload.to_role) lines.push(`- to_role(目标专家): ${payload.to_role}`);
|
|
479
|
-
if (payload.next_role) lines.push(`- next_role(下一位专家): ${payload.next_role}`);
|
|
480
|
-
lines.push(`- status(状态): ${payload.status || 'n/a'}`);
|
|
481
|
-
if (payload.message) lines.push(`- message(说明): ${payload.message}`);
|
|
482
|
-
return lines.join('\n').trim();
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function validateExecutionPayload(payload, sourceLabel, context = {}) {
|
|
486
|
-
if (!payload || typeof payload !== 'object') {
|
|
487
|
-
throw new Error(`Invalid execution payload: ${sourceLabel}`);
|
|
488
|
-
}
|
|
489
|
-
if (payload.kind !== 'expert-execution') {
|
|
490
|
-
throw new Error(`Expected kind "expert-execution" but got "${payload.kind || 'undefined'}": ${sourceLabel}`);
|
|
491
|
-
}
|
|
492
|
-
if (!payload.run_id) {
|
|
493
|
-
throw new Error(`Execution payload is missing run_id: ${sourceLabel}`);
|
|
494
|
-
}
|
|
495
|
-
if (!payload.role || typeof payload.role !== 'object' || !payload.role.id) {
|
|
496
|
-
throw new Error(`Execution payload is missing role.id: ${sourceLabel}`);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
const currentDispatch = context.currentDispatch || null;
|
|
500
|
-
if (currentDispatch?.run_id && payload.run_id && currentDispatch.run_id !== payload.run_id) {
|
|
501
|
-
throw new Error(
|
|
502
|
-
`Execution payload run_id does not match current-dispatch: expected ${currentDispatch.run_id}, got ${payload.run_id}`,
|
|
503
|
-
);
|
|
504
|
-
}
|
|
505
|
-
if (currentDispatch?.dispatch_id && payload.dispatch_id && currentDispatch.dispatch_id !== payload.dispatch_id) {
|
|
506
|
-
throw new Error(
|
|
507
|
-
`Execution payload dispatch_id does not match current-dispatch: expected ${currentDispatch.dispatch_id}, got ${payload.dispatch_id}`,
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
if (currentDispatch?.role?.id && payload.role.id && currentDispatch.role.id !== payload.role.id) {
|
|
511
|
-
throw new Error(
|
|
512
|
-
`Execution payload role.id does not match current-dispatch: expected ${currentDispatch.role.id}, got ${payload.role.id}`,
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function validateRuntimeActionPayload(payload, sourceLabel) {
|
|
518
|
-
if (!payload || typeof payload !== 'object') {
|
|
519
|
-
throw new Error(`Invalid runtime-action payload: ${sourceLabel}`);
|
|
520
|
-
}
|
|
521
|
-
if (payload.kind !== 'task-orchestrator-runtime-action') {
|
|
522
|
-
throw new Error(`Expected kind "task-orchestrator-runtime-action" but got "${payload.kind || 'undefined'}": ${sourceLabel}`);
|
|
523
|
-
}
|
|
524
|
-
if (!payload.run_id) {
|
|
525
|
-
throw new Error(`Runtime-action payload is missing run_id: ${sourceLabel}`);
|
|
526
|
-
}
|
|
527
|
-
if (!payload.action) {
|
|
528
|
-
throw new Error(`Runtime-action payload is missing action: ${sourceLabel}`);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
function normalizeExecutionPayload(payload) {
|
|
533
|
-
const normalized = JSON.parse(JSON.stringify(payload));
|
|
534
|
-
normalized.schema_version = normalized.schema_version || 1;
|
|
535
|
-
normalized.kind = 'expert-execution';
|
|
536
|
-
normalized.openspec_action = normalized.openspec_action || inferExecutionOpenSpecAction(normalized);
|
|
537
|
-
normalized.execution_id = normalized.execution_id || createStampedId('execution', normalized.role.id);
|
|
538
|
-
normalized.generated_at = normalized.generated_at || new Date().toISOString();
|
|
539
|
-
if (normalized.markdown || shouldWriteRuntimeMarkdown()) {
|
|
540
|
-
normalized.markdown = renderExecutionMarkdown(normalized);
|
|
541
|
-
} else {
|
|
542
|
-
delete normalized.markdown;
|
|
543
|
-
}
|
|
544
|
-
return normalized;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
function attachVerificationIfNeeded(targetDir, payload) {
|
|
548
|
-
if (payload?.role?.id !== 'frontend-implementer') {
|
|
549
|
-
return payload;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
const normalizedStatus = String(payload.status || '').trim().toLowerCase();
|
|
553
|
-
if (!['done', 'success', 'completed'].includes(normalizedStatus)) {
|
|
554
|
-
return payload;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
if (payload.verification && Array.isArray(payload.verification.steps) && payload.verification.steps.length > 0) {
|
|
558
|
-
return payload;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
return {
|
|
562
|
-
...payload,
|
|
563
|
-
verification: runVerificationSuite(targetDir),
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function normalizeRuntimeActionPayload(payload) {
|
|
568
|
-
const normalized = JSON.parse(JSON.stringify(payload));
|
|
569
|
-
normalized.schema_version = normalized.schema_version || 1;
|
|
570
|
-
normalized.kind = 'task-orchestrator-runtime-action';
|
|
571
|
-
normalized.openspec_action = normalized.openspec_action || inferRuntimeActionOpenSpecAction(normalized);
|
|
572
|
-
normalized.action_id = normalized.action_id || createStampedId('action', normalized.action);
|
|
573
|
-
normalized.generated_at = normalized.generated_at || new Date().toISOString();
|
|
574
|
-
if (normalized.markdown || shouldWriteRuntimeMarkdown()) {
|
|
575
|
-
normalized.markdown = renderRuntimeActionMarkdown(normalized);
|
|
576
|
-
} else {
|
|
577
|
-
delete normalized.markdown;
|
|
578
|
-
}
|
|
579
|
-
return normalized;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
function writeExecutionArtifacts(targetDir, payload) {
|
|
583
|
-
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
584
|
-
const currentExecutionJson = runtimePaths.currentExecutionJson.path;
|
|
585
|
-
const currentExecutionMd = runtimePaths.currentExecutionMd.path;
|
|
586
|
-
const persistHistory = shouldPersistHistory();
|
|
587
|
-
const writeCurrentMarkdown = shouldWriteRuntimeMarkdown();
|
|
588
|
-
let recordJson = null;
|
|
589
|
-
let recordMd = null;
|
|
590
|
-
if (persistHistory) {
|
|
591
|
-
const executionsDir = path.join(runtimePaths.executionsDir.path, payload.run_id);
|
|
592
|
-
ensureDir(executionsDir);
|
|
593
|
-
recordJson = path.join(executionsDir, `${payload.execution_id}.json`);
|
|
594
|
-
recordMd = path.join(executionsDir, `${payload.execution_id}.md`);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
if (runtimePaths.currentExecutionJson.legacyPath && fs.existsSync(runtimePaths.currentExecutionJson.legacyPath)) {
|
|
598
|
-
fs.unlinkSync(runtimePaths.currentExecutionJson.legacyPath);
|
|
599
|
-
}
|
|
600
|
-
if (runtimePaths.currentExecutionMd.legacyPath && fs.existsSync(runtimePaths.currentExecutionMd.legacyPath)) {
|
|
601
|
-
fs.unlinkSync(runtimePaths.currentExecutionMd.legacyPath);
|
|
602
|
-
}
|
|
603
|
-
writeJson(currentExecutionJson, payload);
|
|
604
|
-
if (writeCurrentMarkdown && payload.markdown) {
|
|
605
|
-
writeText(currentExecutionMd, payload.markdown);
|
|
606
|
-
}
|
|
607
|
-
if (recordJson && recordMd && payload.markdown) {
|
|
608
|
-
writeJson(recordJson, payload);
|
|
609
|
-
writeText(recordMd, payload.markdown);
|
|
610
|
-
} else if (recordJson) {
|
|
611
|
-
writeJson(recordJson, payload);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return {
|
|
615
|
-
current_execution_json: currentExecutionJson,
|
|
616
|
-
current_execution_md: writeCurrentMarkdown && payload.markdown ? currentExecutionMd : null,
|
|
617
|
-
execution_record_json: recordJson,
|
|
618
|
-
execution_record_md: recordMd && payload.markdown ? recordMd : null,
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
function writeRuntimeActionArtifacts(targetDir, payload) {
|
|
623
|
-
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
624
|
-
const currentActionJson = runtimePaths.currentRuntimeActionJson.path;
|
|
625
|
-
const currentActionMd = runtimePaths.currentRuntimeActionMd.path;
|
|
626
|
-
const persistHistory = shouldPersistHistory();
|
|
627
|
-
const writeCurrentMarkdown = shouldWriteRuntimeMarkdown();
|
|
628
|
-
let recordJson = null;
|
|
629
|
-
let recordMd = null;
|
|
630
|
-
if (persistHistory) {
|
|
631
|
-
const actionDir = path.join(runtimePaths.runtimeActionsDir.path, payload.run_id);
|
|
632
|
-
ensureDir(actionDir);
|
|
633
|
-
recordJson = path.join(actionDir, `${payload.action_id}.json`);
|
|
634
|
-
recordMd = path.join(actionDir, `${payload.action_id}.md`);
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
if (runtimePaths.currentRuntimeActionJson.legacyPath && fs.existsSync(runtimePaths.currentRuntimeActionJson.legacyPath)) {
|
|
638
|
-
fs.unlinkSync(runtimePaths.currentRuntimeActionJson.legacyPath);
|
|
639
|
-
}
|
|
640
|
-
if (runtimePaths.currentRuntimeActionMd.legacyPath && fs.existsSync(runtimePaths.currentRuntimeActionMd.legacyPath)) {
|
|
641
|
-
fs.unlinkSync(runtimePaths.currentRuntimeActionMd.legacyPath);
|
|
642
|
-
}
|
|
643
|
-
writeJson(currentActionJson, payload);
|
|
644
|
-
if (writeCurrentMarkdown && payload.markdown) {
|
|
645
|
-
writeText(currentActionMd, payload.markdown);
|
|
646
|
-
}
|
|
647
|
-
if (recordJson && recordMd && payload.markdown) {
|
|
648
|
-
writeJson(recordJson, payload);
|
|
649
|
-
writeText(recordMd, payload.markdown);
|
|
650
|
-
} else if (recordJson) {
|
|
651
|
-
writeJson(recordJson, payload);
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return {
|
|
655
|
-
current_runtime_action_json: currentActionJson,
|
|
656
|
-
current_runtime_action_md: writeCurrentMarkdown && payload.markdown ? currentActionMd : null,
|
|
657
|
-
runtime_action_record_json: recordJson,
|
|
658
|
-
runtime_action_record_md: recordMd && payload.markdown ? recordMd : null,
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
function readPayloadFromOptions(options, label) {
|
|
663
|
-
const inputCount = [Boolean(options.payload), Boolean(options.stdin)].filter(Boolean).length;
|
|
664
|
-
if (inputCount === 0) {
|
|
665
|
-
throw new Error(`Missing ${label} input: use --payload <file> or --stdin`);
|
|
666
|
-
}
|
|
667
|
-
if (inputCount > 1) {
|
|
668
|
-
throw new Error('Use either --payload <file> or --stdin, not both');
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
const sourcePath = options.payload
|
|
672
|
-
? path.resolve(process.cwd(), options.payload)
|
|
673
|
-
: 'stdin';
|
|
674
|
-
|
|
675
|
-
const rawPayload = options.payload
|
|
676
|
-
? readJson(sourcePath, label)
|
|
677
|
-
: readJsonFromStdin(label);
|
|
678
|
-
|
|
679
|
-
return { sourcePath, rawPayload };
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
function cleanupTmpSource(targetDir, sourcePath) {
|
|
683
|
-
if (!sourcePath || sourcePath === 'stdin' || !fs.existsSync(sourcePath)) {
|
|
684
|
-
return null;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
const runtimePaths = resolveRuntimePaths(path.resolve(targetDir));
|
|
688
|
-
for (const candidate of getCandidatePaths(runtimePaths.tmpDir)) {
|
|
689
|
-
const relative = path.relative(candidate, sourcePath);
|
|
690
|
-
if (!relative.startsWith('..') && !path.isAbsolute(relative)) {
|
|
691
|
-
fs.unlinkSync(sourcePath);
|
|
692
|
-
return sourcePath;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
return null;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
function clearCurrentExpertArtifacts(targetDir) {
|
|
699
|
-
return {
|
|
700
|
-
dispatch: expertDispatch.clearDispatch({ target: targetDir }),
|
|
701
|
-
execution: clearExecution({ target: targetDir }),
|
|
702
|
-
runtime_action: clearRuntimeAction({ target: targetDir }),
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
function applyRuntimeMutation(targetDir, payload, payloadSource) {
|
|
707
|
-
const guardedPayload = guardRuntimeActionForIncompleteExecution(targetDir, payload);
|
|
708
|
-
const requestedAction = String(guardedPayload.action || '').trim().toLowerCase();
|
|
709
|
-
const runtimeAction = requestedAction === 'archive'
|
|
710
|
-
? 'complete'
|
|
711
|
-
: requestedAction === 'completed'
|
|
712
|
-
? 'complete'
|
|
713
|
-
: requestedAction === 'blocked'
|
|
714
|
-
? 'gate-blocked'
|
|
715
|
-
: requestedAction;
|
|
716
|
-
const options = {
|
|
717
|
-
target: targetDir,
|
|
718
|
-
runId: guardedPayload.run_id,
|
|
719
|
-
toRole: guardedPayload.to_role,
|
|
720
|
-
nextRole: guardedPayload.next_role,
|
|
721
|
-
fromRole: guardedPayload.from_role,
|
|
722
|
-
gate: guardedPayload.gate,
|
|
723
|
-
pendingGate: guardedPayload.pending_gate,
|
|
724
|
-
blockedByRole: guardedPayload.blocked_by_role,
|
|
725
|
-
resumeToRole: guardedPayload.resume_to_role,
|
|
726
|
-
requiredUserAction: guardedPayload.required_user_action,
|
|
727
|
-
blockedReason: guardedPayload.blocked_reason,
|
|
728
|
-
message: guardedPayload.message,
|
|
729
|
-
error: guardedPayload.error,
|
|
730
|
-
eventType: guardedPayload.event_type || guardedPayload.eventType,
|
|
731
|
-
status: guardedPayload.status,
|
|
732
|
-
artifactsData: guardedPayload.artifacts || null,
|
|
733
|
-
verificationData: guardedPayload.verification || null,
|
|
734
|
-
autoFixData: guardedPayload.auto_fix || null,
|
|
735
|
-
skipArtifactCheck:
|
|
736
|
-
Object.prototype.hasOwnProperty.call(guardedPayload, 'skip_artifact_check') ||
|
|
737
|
-
Object.prototype.hasOwnProperty.call(guardedPayload, 'skipArtifactCheck')
|
|
738
|
-
? Boolean(
|
|
739
|
-
Object.prototype.hasOwnProperty.call(guardedPayload, 'skip_artifact_check')
|
|
740
|
-
? guardedPayload.skip_artifact_check
|
|
741
|
-
: guardedPayload.skipArtifactCheck
|
|
742
|
-
)
|
|
743
|
-
: undefined,
|
|
744
|
-
clearPendingGate:
|
|
745
|
-
Object.prototype.hasOwnProperty.call(guardedPayload, 'clear_pending_gate') ||
|
|
746
|
-
Object.prototype.hasOwnProperty.call(guardedPayload, 'clearPendingGate')
|
|
747
|
-
? Boolean(
|
|
748
|
-
Object.prototype.hasOwnProperty.call(guardedPayload, 'clear_pending_gate')
|
|
749
|
-
? guardedPayload.clear_pending_gate
|
|
750
|
-
: guardedPayload.clearPendingGate
|
|
751
|
-
)
|
|
752
|
-
: undefined,
|
|
753
|
-
taskAnchorData: guardedPayload.task_anchor || guardedPayload.taskAnchor || null,
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
let result = null;
|
|
757
|
-
switch (runtimeAction) {
|
|
758
|
-
case 'handoff':
|
|
759
|
-
result = runtimeState.handoffRunState(options);
|
|
760
|
-
break;
|
|
761
|
-
case 'approve':
|
|
762
|
-
result = runtimeState.approveRunState(options);
|
|
763
|
-
break;
|
|
764
|
-
case 'resume':
|
|
765
|
-
result = runtimeState.resumeRunState(options);
|
|
766
|
-
break;
|
|
767
|
-
case 'gate-blocked':
|
|
768
|
-
result = runtimeState.gateBlockedRunState(options);
|
|
769
|
-
break;
|
|
770
|
-
case 'status':
|
|
771
|
-
result = runtimeState.statusRunState(options);
|
|
772
|
-
break;
|
|
773
|
-
case 'complete':
|
|
774
|
-
result = runtimeState.completeRunState(options);
|
|
775
|
-
break;
|
|
776
|
-
case 'fail':
|
|
777
|
-
result = runtimeState.failRunState(options);
|
|
778
|
-
break;
|
|
779
|
-
case 'cancel':
|
|
780
|
-
result = runtimeState.cancelRunState(options);
|
|
781
|
-
break;
|
|
782
|
-
default:
|
|
783
|
-
throw new Error(`Unsupported runtime action for expert-executor: ${guardedPayload.action}`);
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
const clearableActions = new Set([
|
|
787
|
-
'handoff',
|
|
788
|
-
'approve',
|
|
789
|
-
'resume',
|
|
790
|
-
'gate-blocked',
|
|
791
|
-
'complete',
|
|
792
|
-
'fail',
|
|
793
|
-
'cancel',
|
|
794
|
-
]);
|
|
795
|
-
const cleared = clearableActions.has(runtimeAction)
|
|
796
|
-
? clearCurrentExpertArtifacts(targetDir)
|
|
797
|
-
: null;
|
|
798
|
-
|
|
799
|
-
return {
|
|
800
|
-
requested_action: requestedAction,
|
|
801
|
-
applied_action: runtimeAction,
|
|
802
|
-
adapter_source: payloadSource,
|
|
803
|
-
result,
|
|
804
|
-
cleared,
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
function applyExecution(options) {
|
|
809
|
-
const targetDir = path.resolve(options.target || '.');
|
|
810
|
-
const { sourcePath, rawPayload } = readPayloadFromOptions(options, 'expert-execution');
|
|
811
|
-
const hydrated = hydrateExecutionPayload(targetDir, rawPayload);
|
|
812
|
-
validateExecutionPayload(hydrated.payload, sourcePath, hydrated.context);
|
|
813
|
-
const validation = validateExecutionArtifacts(targetDir, hydrated.payload);
|
|
814
|
-
const archive_result = maybeApplyArchiveChange(targetDir, hydrated.payload);
|
|
815
|
-
const payload = normalizeExecutionPayload(attachVerificationIfNeeded(targetDir, hydrated.payload));
|
|
816
|
-
const artifacts = writeExecutionArtifacts(targetDir, payload);
|
|
817
|
-
let runtime_transition = null;
|
|
818
|
-
if (shouldAdvanceRuntime(options)) {
|
|
819
|
-
const runtimeActionPayload = buildAutoRuntimeAction(targetDir, payload);
|
|
820
|
-
if (runtimeActionPayload) {
|
|
821
|
-
if (archive_result?.archived_artifacts) {
|
|
822
|
-
runtimeActionPayload.artifacts = archive_result.archived_artifacts;
|
|
823
|
-
runtimeActionPayload.skip_artifact_check = true;
|
|
824
|
-
}
|
|
825
|
-
const runtimePayload = normalizeRuntimeActionPayload(runtimeActionPayload);
|
|
826
|
-
const runtimeArtifacts = writeRuntimeActionArtifacts(targetDir, runtimePayload);
|
|
827
|
-
const applied = applyRuntimeMutation(targetDir, runtimePayload, 'expert-executor:auto-runtime');
|
|
828
|
-
runtime_transition = {
|
|
829
|
-
payload: runtimePayload,
|
|
830
|
-
artifacts: {
|
|
831
|
-
...runtimeArtifacts,
|
|
832
|
-
current_runtime_action_json: applied.cleared ? null : runtimeArtifacts.current_runtime_action_json,
|
|
833
|
-
current_runtime_action_md: applied.cleared ? null : runtimeArtifacts.current_runtime_action_md,
|
|
834
|
-
},
|
|
835
|
-
applied: {
|
|
836
|
-
requested_action: applied.requested_action,
|
|
837
|
-
applied_action: applied.applied_action,
|
|
838
|
-
run_id: applied.result?.state?.run_id || null,
|
|
839
|
-
status: applied.result?.state?.status || null,
|
|
840
|
-
current_role: applied.result?.state?.current_role || null,
|
|
841
|
-
pending_gate: applied.result?.state?.pending_gate || null,
|
|
842
|
-
},
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
const cleanedSource = cleanupTmpSource(targetDir, sourcePath);
|
|
847
|
-
|
|
848
|
-
return {
|
|
849
|
-
status: 'success',
|
|
850
|
-
target: targetDir,
|
|
851
|
-
source: sourcePath,
|
|
852
|
-
artifacts: {
|
|
853
|
-
...artifacts,
|
|
854
|
-
current_execution_json: runtime_transition?.applied ? null : artifacts.current_execution_json,
|
|
855
|
-
current_execution_md: runtime_transition?.applied ? null : artifacts.current_execution_md,
|
|
856
|
-
},
|
|
857
|
-
payload,
|
|
858
|
-
validation,
|
|
859
|
-
archive_result,
|
|
860
|
-
runtime_transition,
|
|
861
|
-
cleaned_source: cleanedSource,
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
function applyExecutionData(options) {
|
|
866
|
-
const targetDir = path.resolve(options.target || '.');
|
|
867
|
-
const sourcePath = options.source || 'memory-payload';
|
|
868
|
-
const hydrated = hydrateExecutionPayload(targetDir, options.payloadData);
|
|
869
|
-
validateExecutionPayload(hydrated.payload, sourcePath, hydrated.context);
|
|
870
|
-
const validation = validateExecutionArtifacts(targetDir, hydrated.payload);
|
|
871
|
-
const archive_result = maybeApplyArchiveChange(targetDir, hydrated.payload);
|
|
872
|
-
const payload = normalizeExecutionPayload(attachVerificationIfNeeded(targetDir, hydrated.payload));
|
|
873
|
-
const artifacts = writeExecutionArtifacts(targetDir, payload);
|
|
874
|
-
let runtime_transition = null;
|
|
875
|
-
if (shouldAdvanceRuntime(options)) {
|
|
876
|
-
const runtimeActionPayload = buildAutoRuntimeAction(targetDir, payload);
|
|
877
|
-
if (runtimeActionPayload) {
|
|
878
|
-
if (archive_result?.archived_artifacts) {
|
|
879
|
-
runtimeActionPayload.artifacts = archive_result.archived_artifacts;
|
|
880
|
-
runtimeActionPayload.skip_artifact_check = true;
|
|
881
|
-
}
|
|
882
|
-
const runtimePayload = normalizeRuntimeActionPayload(runtimeActionPayload);
|
|
883
|
-
const runtimeArtifacts = writeRuntimeActionArtifacts(targetDir, runtimePayload);
|
|
884
|
-
const applied = applyRuntimeMutation(targetDir, runtimePayload, 'expert-executor:auto-runtime');
|
|
885
|
-
runtime_transition = {
|
|
886
|
-
payload: runtimePayload,
|
|
887
|
-
artifacts: {
|
|
888
|
-
...runtimeArtifacts,
|
|
889
|
-
current_runtime_action_json: applied.cleared ? null : runtimeArtifacts.current_runtime_action_json,
|
|
890
|
-
current_runtime_action_md: applied.cleared ? null : runtimeArtifacts.current_runtime_action_md,
|
|
891
|
-
},
|
|
892
|
-
applied: {
|
|
893
|
-
requested_action: applied.requested_action,
|
|
894
|
-
applied_action: applied.applied_action,
|
|
895
|
-
run_id: applied.result?.state?.run_id || null,
|
|
896
|
-
status: applied.result?.state?.status || null,
|
|
897
|
-
current_role: applied.result?.state?.current_role || null,
|
|
898
|
-
pending_gate: applied.result?.state?.pending_gate || null,
|
|
899
|
-
},
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
return {
|
|
905
|
-
status: 'success',
|
|
906
|
-
target: targetDir,
|
|
907
|
-
source: sourcePath,
|
|
908
|
-
artifacts: {
|
|
909
|
-
...artifacts,
|
|
910
|
-
current_execution_json: runtime_transition?.applied ? null : artifacts.current_execution_json,
|
|
911
|
-
current_execution_md: runtime_transition?.applied ? null : artifacts.current_execution_md,
|
|
912
|
-
},
|
|
913
|
-
payload,
|
|
914
|
-
validation,
|
|
915
|
-
archive_result,
|
|
916
|
-
runtime_transition,
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
function applyRuntimeAction(options) {
|
|
921
|
-
const targetDir = path.resolve(options.target || '.');
|
|
922
|
-
const { sourcePath, rawPayload } = readPayloadFromOptions(options, 'runtime-action');
|
|
923
|
-
const hydrated = hydrateRuntimeActionPayload(targetDir, rawPayload);
|
|
924
|
-
validateRuntimeActionPayload(hydrated.payload, sourcePath);
|
|
925
|
-
const payload = normalizeRuntimeActionPayload(hydrated.payload);
|
|
926
|
-
const artifacts = writeRuntimeActionArtifacts(targetDir, payload);
|
|
927
|
-
let runtime_transition = null;
|
|
928
|
-
if (shouldAdvanceRuntime(options)) {
|
|
929
|
-
const applied = applyRuntimeMutation(targetDir, payload, sourcePath);
|
|
930
|
-
runtime_transition = {
|
|
931
|
-
applied: {
|
|
932
|
-
requested_action: applied.requested_action,
|
|
933
|
-
applied_action: applied.applied_action,
|
|
934
|
-
run_id: applied.result?.state?.run_id || null,
|
|
935
|
-
status: applied.result?.state?.status || null,
|
|
936
|
-
current_role: applied.result?.state?.current_role || null,
|
|
937
|
-
pending_gate: applied.result?.state?.pending_gate || null,
|
|
938
|
-
},
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
const cleanedSource = cleanupTmpSource(targetDir, sourcePath);
|
|
942
|
-
|
|
943
|
-
return {
|
|
944
|
-
status: 'success',
|
|
945
|
-
target: targetDir,
|
|
946
|
-
source: sourcePath,
|
|
947
|
-
artifacts: {
|
|
948
|
-
...artifacts,
|
|
949
|
-
current_runtime_action_json: runtime_transition?.applied ? null : artifacts.current_runtime_action_json,
|
|
950
|
-
current_runtime_action_md: runtime_transition?.applied ? null : artifacts.current_runtime_action_md,
|
|
951
|
-
},
|
|
952
|
-
payload,
|
|
953
|
-
runtime_transition,
|
|
954
|
-
cleaned_source: cleanedSource,
|
|
955
|
-
};
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
function applyRuntimeActionData(options) {
|
|
959
|
-
const targetDir = path.resolve(options.target || '.');
|
|
960
|
-
const sourcePath = options.source || 'memory-payload';
|
|
961
|
-
const hydrated = hydrateRuntimeActionPayload(targetDir, options.payloadData);
|
|
962
|
-
validateRuntimeActionPayload(hydrated.payload, sourcePath);
|
|
963
|
-
const payload = normalizeRuntimeActionPayload(hydrated.payload);
|
|
964
|
-
const artifacts = writeRuntimeActionArtifacts(targetDir, payload);
|
|
965
|
-
let runtime_transition = null;
|
|
966
|
-
if (shouldAdvanceRuntime(options)) {
|
|
967
|
-
const applied = applyRuntimeMutation(targetDir, payload, sourcePath);
|
|
968
|
-
runtime_transition = {
|
|
969
|
-
applied: {
|
|
970
|
-
requested_action: applied.requested_action,
|
|
971
|
-
applied_action: applied.applied_action,
|
|
972
|
-
run_id: applied.result?.state?.run_id || null,
|
|
973
|
-
status: applied.result?.state?.status || null,
|
|
974
|
-
current_role: applied.result?.state?.current_role || null,
|
|
975
|
-
pending_gate: applied.result?.state?.pending_gate || null,
|
|
976
|
-
},
|
|
977
|
-
};
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
return {
|
|
981
|
-
status: 'success',
|
|
982
|
-
target: targetDir,
|
|
983
|
-
source: sourcePath,
|
|
984
|
-
artifacts: {
|
|
985
|
-
...artifacts,
|
|
986
|
-
current_runtime_action_json: runtime_transition?.applied ? null : artifacts.current_runtime_action_json,
|
|
987
|
-
current_runtime_action_md: runtime_transition?.applied ? null : artifacts.current_runtime_action_md,
|
|
988
|
-
},
|
|
989
|
-
payload,
|
|
990
|
-
runtime_transition,
|
|
991
|
-
};
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
function clearExecution(options) {
|
|
995
|
-
const targetDir = path.resolve(options.target || '.');
|
|
996
|
-
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
997
|
-
|
|
998
|
-
for (const currentExecutionJson of getCandidatePaths(runtimePaths.currentExecutionJson)) {
|
|
999
|
-
if (fs.existsSync(currentExecutionJson)) {
|
|
1000
|
-
fs.unlinkSync(currentExecutionJson);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
for (const currentExecutionMd of getCandidatePaths(runtimePaths.currentExecutionMd)) {
|
|
1004
|
-
if (fs.existsSync(currentExecutionMd)) {
|
|
1005
|
-
fs.unlinkSync(currentExecutionMd);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
return {
|
|
1010
|
-
status: 'success',
|
|
1011
|
-
target: targetDir,
|
|
1012
|
-
artifacts: {
|
|
1013
|
-
current_execution_json: runtimePaths.currentExecutionJson.path,
|
|
1014
|
-
current_execution_md: runtimePaths.currentExecutionMd.path,
|
|
1015
|
-
},
|
|
1016
|
-
};
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function clearRuntimeAction(options) {
|
|
1020
|
-
const targetDir = path.resolve(options.target || '.');
|
|
1021
|
-
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
1022
|
-
|
|
1023
|
-
for (const currentActionJson of getCandidatePaths(runtimePaths.currentRuntimeActionJson)) {
|
|
1024
|
-
if (fs.existsSync(currentActionJson)) {
|
|
1025
|
-
fs.unlinkSync(currentActionJson);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
for (const currentActionMd of getCandidatePaths(runtimePaths.currentRuntimeActionMd)) {
|
|
1029
|
-
if (fs.existsSync(currentActionMd)) {
|
|
1030
|
-
fs.unlinkSync(currentActionMd);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
return {
|
|
1035
|
-
status: 'success',
|
|
1036
|
-
target: targetDir,
|
|
1037
|
-
artifacts: {
|
|
1038
|
-
current_runtime_action_json: runtimePaths.currentRuntimeActionJson.path,
|
|
1039
|
-
current_runtime_action_md: runtimePaths.currentRuntimeActionMd.path,
|
|
1040
|
-
},
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
function printPretty(result, command) {
|
|
1045
|
-
console.log(`expert-executor ${command}`);
|
|
1046
|
-
console.log(` target: ${result.target}`);
|
|
1047
|
-
if (result.payload) {
|
|
1048
|
-
console.log(` run_id: ${result.payload.run_id}`);
|
|
1049
|
-
if (result.payload.kind === 'expert-execution') {
|
|
1050
|
-
console.log(` role: ${result.payload.role.id}`);
|
|
1051
|
-
console.log(` openspec_action: ${result.payload.openspec_action || 'n/a'}`);
|
|
1052
|
-
console.log(` execution_id: ${result.payload.execution_id}`);
|
|
1053
|
-
console.log(` current_execution: ${result.artifacts.current_execution_json}`);
|
|
1054
|
-
} else {
|
|
1055
|
-
console.log(` action: ${result.payload.action}`);
|
|
1056
|
-
console.log(` openspec_action: ${result.payload.openspec_action || 'n/a'}`);
|
|
1057
|
-
console.log(` current_runtime_action: ${result.artifacts.current_runtime_action_json}`);
|
|
1058
|
-
}
|
|
1059
|
-
if (result.runtime_transition?.applied) {
|
|
1060
|
-
console.log(` runtime_action: ${result.runtime_transition.applied.requested_action || 'n/a'}`);
|
|
1061
|
-
console.log(` runtime_status: ${result.runtime_transition.applied.status || 'n/a'}`);
|
|
1062
|
-
console.log(` runtime_current_role: ${result.runtime_transition.applied.current_role || 'n/a'}`);
|
|
1063
|
-
}
|
|
1064
|
-
} else {
|
|
1065
|
-
if (result.artifacts.current_execution_json) {
|
|
1066
|
-
console.log(` current_execution: ${result.artifacts.current_execution_json}`);
|
|
1067
|
-
}
|
|
1068
|
-
if (result.artifacts.current_runtime_action_json) {
|
|
1069
|
-
console.log(` current_runtime_action: ${result.artifacts.current_runtime_action_json}`);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
async function main(argv = process.argv.slice(2)) {
|
|
1075
|
-
const { command, options } = parseArgs(argv);
|
|
1076
|
-
|
|
1077
|
-
if (!command || options.help || command === 'help' || command === '--help' || command === '-h') {
|
|
1078
|
-
printUsage();
|
|
1079
|
-
return 0;
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
if (command === 'apply' || command === 'run') {
|
|
1083
|
-
const result = applyExecution(options);
|
|
1084
|
-
await drainVisualRuntimeStatePushes();
|
|
1085
|
-
if (options.json) {
|
|
1086
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1087
|
-
} else {
|
|
1088
|
-
printPretty(result, command);
|
|
1089
|
-
}
|
|
1090
|
-
return 0;
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
if (command === 'apply-action' || command === 'finish') {
|
|
1094
|
-
const result = applyRuntimeAction(options);
|
|
1095
|
-
await drainVisualRuntimeStatePushes();
|
|
1096
|
-
if (options.json) {
|
|
1097
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1098
|
-
} else {
|
|
1099
|
-
printPretty(result, command);
|
|
1100
|
-
}
|
|
1101
|
-
return 0;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
if (command === 'clear') {
|
|
1105
|
-
const result = clearExecution(options);
|
|
1106
|
-
if (options.json) {
|
|
1107
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1108
|
-
} else {
|
|
1109
|
-
printPretty(result, command);
|
|
1110
|
-
}
|
|
1111
|
-
return 0;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
if (command === 'clear-action') {
|
|
1115
|
-
const result = clearRuntimeAction(options);
|
|
1116
|
-
if (options.json) {
|
|
1117
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1118
|
-
} else {
|
|
1119
|
-
printPretty(result, command);
|
|
1120
|
-
}
|
|
1121
|
-
return 0;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
throw new Error(`Unsupported expert-executor command: ${command}`);
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
module.exports = {
|
|
1128
|
-
main,
|
|
1129
|
-
applyExecution,
|
|
1130
|
-
applyExecutionData,
|
|
1131
|
-
applyRuntimeAction,
|
|
1132
|
-
applyRuntimeActionData,
|
|
1133
|
-
clearExecution,
|
|
1134
|
-
clearRuntimeAction,
|
|
1135
|
-
validateExecutionPayload,
|
|
1136
|
-
validateRuntimeActionPayload,
|
|
1137
|
-
normalizeExecutionPayload,
|
|
1138
|
-
normalizeRuntimeActionPayload,
|
|
1139
|
-
};
|
|
1140
|
-
|
|
1141
|
-
if (require.main === module) {
|
|
1142
|
-
try {
|
|
1143
|
-
main().then((code) => process.exit(code));
|
|
1144
|
-
} catch (error) {
|
|
1145
|
-
console.error(`expert-executor error: ${error.message}`);
|
|
1146
|
-
process.exit(1);
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { spawnSync } = require('child_process');
|
|
5
|
+
const runtimeState = require('./runtime-state');
|
|
6
|
+
const expertDispatch = require('./expert-dispatch');
|
|
7
|
+
const { archiveChange } = require('./archive-change');
|
|
8
|
+
const {
|
|
9
|
+
getRoleArtifactRequirements,
|
|
10
|
+
inferExecutionOpenSpecAction,
|
|
11
|
+
inferRuntimeActionOpenSpecAction,
|
|
12
|
+
buildAutoRuntimeAction,
|
|
13
|
+
guardRuntimeActionForIncompleteExecution,
|
|
14
|
+
} = require('./execution-semantics');
|
|
15
|
+
const {
|
|
16
|
+
resolveRuntimePaths,
|
|
17
|
+
getCandidatePaths,
|
|
18
|
+
getExistingPath,
|
|
19
|
+
shouldPersistHistory,
|
|
20
|
+
} = require('./runtime-paths');
|
|
21
|
+
const { drainVisualRuntimeStatePushes } = require('../internal/visual-hooks/runtime-state-pusher');
|
|
22
|
+
|
|
23
|
+
function printUsage() {
|
|
24
|
+
console.log(`Usage:
|
|
25
|
+
ai-spec-auto expert-executor apply --payload <file> [options]
|
|
26
|
+
ai-spec-auto expert-executor apply --stdin [options]
|
|
27
|
+
ai-spec-auto expert-executor apply-action --payload <file> [options]
|
|
28
|
+
ai-spec-auto expert-executor apply-action --stdin [options]
|
|
29
|
+
ai-spec-auto expert-executor clear [options]
|
|
30
|
+
ai-spec-auto expert-executor clear-action [options]
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--target <dir> Target project directory (default: .)
|
|
34
|
+
--payload <file> Path to payload JSON file
|
|
35
|
+
--stdin Read payload JSON from stdin
|
|
36
|
+
--advance-runtime Persist payload and apply inferred runtime-state mutation
|
|
37
|
+
--json Print JSON result only
|
|
38
|
+
--pretty Print readable summary (default)
|
|
39
|
+
--help Show this help
|
|
40
|
+
`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function parseArgs(argv) {
|
|
44
|
+
const args = [...argv];
|
|
45
|
+
const command = args.shift();
|
|
46
|
+
const options = {
|
|
47
|
+
target: '.',
|
|
48
|
+
pretty: true,
|
|
49
|
+
json: false,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
while (args.length > 0) {
|
|
53
|
+
const arg = args.shift();
|
|
54
|
+
switch (arg) {
|
|
55
|
+
case '--target':
|
|
56
|
+
options.target = args.shift();
|
|
57
|
+
break;
|
|
58
|
+
case '--payload':
|
|
59
|
+
options.payload = args.shift();
|
|
60
|
+
break;
|
|
61
|
+
case '--stdin':
|
|
62
|
+
options.stdin = true;
|
|
63
|
+
break;
|
|
64
|
+
case '--advance-runtime':
|
|
65
|
+
options.advanceRuntime = true;
|
|
66
|
+
break;
|
|
67
|
+
case '--json':
|
|
68
|
+
options.json = true;
|
|
69
|
+
options.pretty = false;
|
|
70
|
+
break;
|
|
71
|
+
case '--pretty':
|
|
72
|
+
options.pretty = true;
|
|
73
|
+
options.json = false;
|
|
74
|
+
break;
|
|
75
|
+
case '--help':
|
|
76
|
+
case '-h':
|
|
77
|
+
options.help = true;
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { command, options };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function ensureDir(dirPath) {
|
|
88
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function writeJson(filePath, value) {
|
|
92
|
+
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function writeText(filePath, value) {
|
|
96
|
+
fs.writeFileSync(filePath, `${value}\n`, 'utf8');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function readJson(filePath, label) {
|
|
100
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
101
|
+
try {
|
|
102
|
+
return JSON.parse(raw);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new Error(`${label} is not valid JSON: ${filePath}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function readJsonFromStdin(label) {
|
|
109
|
+
const raw = fs.readFileSync(0, 'utf8');
|
|
110
|
+
if (!raw.trim()) {
|
|
111
|
+
throw new Error(`${label} stdin is empty`);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return JSON.parse(raw);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new Error(`${label} stdin is not valid JSON`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function createStampedId(prefix, suffix = '', now = new Date()) {
|
|
121
|
+
const iso = now.toISOString().replace(/[:.]/g, '-');
|
|
122
|
+
return suffix ? `${iso}__${suffix}` : `${prefix}_${iso}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function normalizeList(value) {
|
|
126
|
+
if (!value) return [];
|
|
127
|
+
if (Array.isArray(value)) return value.filter(Boolean);
|
|
128
|
+
return [String(value)].filter(Boolean);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function loadPackageManifest(targetDir) {
|
|
132
|
+
const packagePath = path.join(targetDir, 'package.json');
|
|
133
|
+
if (!fs.existsSync(packagePath)) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return readJson(packagePath, 'package.json');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function detectPackageManager(targetDir) {
|
|
140
|
+
if (fs.existsSync(path.join(targetDir, 'pnpm-lock.yaml'))) {
|
|
141
|
+
return 'pnpm';
|
|
142
|
+
}
|
|
143
|
+
if (fs.existsSync(path.join(targetDir, 'yarn.lock'))) {
|
|
144
|
+
return 'yarn';
|
|
145
|
+
}
|
|
146
|
+
if (fs.existsSync(path.join(targetDir, 'package-lock.json'))) {
|
|
147
|
+
return 'npm';
|
|
148
|
+
}
|
|
149
|
+
return 'npm';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function trimOutput(value, maxLength = 400) {
|
|
153
|
+
const text = String(value || '').trim();
|
|
154
|
+
if (!text) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function buildVerificationCommand(packageManager, stepName) {
|
|
161
|
+
if (packageManager === 'yarn') {
|
|
162
|
+
return {
|
|
163
|
+
command: 'yarn',
|
|
164
|
+
args: [stepName],
|
|
165
|
+
printable: `yarn ${stepName}`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
command: packageManager,
|
|
171
|
+
args: ['run', stepName],
|
|
172
|
+
printable: `${packageManager} run ${stepName}`,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function runVerificationSuite(targetDir) {
|
|
177
|
+
const pkg = loadPackageManifest(targetDir);
|
|
178
|
+
const scripts = pkg?.scripts && typeof pkg.scripts === 'object' ? pkg.scripts : {};
|
|
179
|
+
const packageManager = detectPackageManager(targetDir);
|
|
180
|
+
const stepNames = ['build', 'lint', 'test'];
|
|
181
|
+
const steps = [];
|
|
182
|
+
|
|
183
|
+
for (const stepName of stepNames) {
|
|
184
|
+
if (typeof scripts[stepName] !== 'string' || !scripts[stepName].trim()) {
|
|
185
|
+
steps.push({
|
|
186
|
+
name: stepName,
|
|
187
|
+
status: 'skipped',
|
|
188
|
+
reason: `package.json scripts.${stepName} 未定义`,
|
|
189
|
+
});
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const command = buildVerificationCommand(packageManager, stepName);
|
|
194
|
+
const result = spawnSync(command.command, command.args, {
|
|
195
|
+
cwd: targetDir,
|
|
196
|
+
encoding: 'utf8',
|
|
197
|
+
env: process.env,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (result.error) {
|
|
201
|
+
steps.push({
|
|
202
|
+
name: stepName,
|
|
203
|
+
command: command.printable,
|
|
204
|
+
status: 'failed',
|
|
205
|
+
exit_code: typeof result.status === 'number' ? result.status : null,
|
|
206
|
+
error: result.error.message,
|
|
207
|
+
});
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
steps.push({
|
|
212
|
+
name: stepName,
|
|
213
|
+
command: command.printable,
|
|
214
|
+
status: result.status === 0 ? 'passed' : 'failed',
|
|
215
|
+
exit_code: typeof result.status === 'number' ? result.status : null,
|
|
216
|
+
stdout_excerpt: trimOutput(result.stdout),
|
|
217
|
+
stderr_excerpt: trimOutput(result.stderr),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const summary = steps.reduce((accumulator, step) => {
|
|
222
|
+
const key = step.status === 'passed' || step.status === 'failed' ? step.status : 'skipped';
|
|
223
|
+
accumulator[key] += 1;
|
|
224
|
+
return accumulator;
|
|
225
|
+
}, { passed: 0, failed: 0, skipped: 0 });
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
schema_version: 1,
|
|
229
|
+
kind: 'verification',
|
|
230
|
+
auto_generated: true,
|
|
231
|
+
generated_at: new Date().toISOString(),
|
|
232
|
+
package_manager: packageManager,
|
|
233
|
+
overall_status: summary.failed > 0 ? 'failed' : summary.passed > 0 ? 'passed' : 'skipped',
|
|
234
|
+
steps,
|
|
235
|
+
summary,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function shouldWriteRuntimeMarkdown() {
|
|
240
|
+
return shouldPersistHistory() || process.env.AI_SPEC_WRITE_RUNTIME_MD === '1';
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function readJsonIfExists(filePath) {
|
|
244
|
+
if (!fs.existsSync(filePath)) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return readJson(filePath, 'json');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function resolveRuntimeContext(targetDir) {
|
|
252
|
+
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
253
|
+
return {
|
|
254
|
+
runtimePaths,
|
|
255
|
+
currentRun: readJsonIfExists(runtimePaths.currentRun.path),
|
|
256
|
+
currentDispatch: readJsonIfExists(getExistingPath(runtimePaths.currentDispatch)),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function shouldAdvanceRuntime(options = {}) {
|
|
261
|
+
return options.advanceRuntime === true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function buildExecutionArtifactMap(changeId, artifacts = {}, options = {}) {
|
|
265
|
+
const flowId = String(options.flowId || '').trim();
|
|
266
|
+
const runId = String(options.runId || '').trim();
|
|
267
|
+
const traceMode = String(options.traceMode || '').trim();
|
|
268
|
+
const implementationNotes = artifacts.implementation_notes || artifacts.implementationNotes || null;
|
|
269
|
+
|
|
270
|
+
if ((flowId === 'bugfix-to-verification' || traceMode === 'direct-fix') && runId) {
|
|
271
|
+
const historyDir = `.ai-spec/history/${runId}`;
|
|
272
|
+
return {
|
|
273
|
+
proposal: null,
|
|
274
|
+
specs: null,
|
|
275
|
+
design: null,
|
|
276
|
+
tasks: null,
|
|
277
|
+
bugfix: artifacts.bugfix || `${historyDir}/bugfix.md`,
|
|
278
|
+
implementation_notes: implementationNotes || `${historyDir}/implementation-notes.md`,
|
|
279
|
+
checklist: artifacts.checklist || `${historyDir}/checklist.md`,
|
|
280
|
+
iterations: artifacts.iterations || `${historyDir}/iterations.md`,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (!changeId) {
|
|
285
|
+
return {
|
|
286
|
+
proposal: null,
|
|
287
|
+
specs: null,
|
|
288
|
+
design: null,
|
|
289
|
+
tasks: null,
|
|
290
|
+
bugfix: artifacts.bugfix || null,
|
|
291
|
+
implementation_notes: implementationNotes,
|
|
292
|
+
checklist: artifacts.checklist || null,
|
|
293
|
+
iterations: artifacts.iterations || null,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const baseDir = `openspec/changes/${changeId}`;
|
|
298
|
+
return {
|
|
299
|
+
proposal: artifacts.proposal || `${baseDir}/proposal.md`,
|
|
300
|
+
specs: runtimeState.normalizeSpecsArtifactPath(artifacts.specs || `${baseDir}/specs`),
|
|
301
|
+
design: artifacts.design || `${baseDir}/design.md`,
|
|
302
|
+
tasks: artifacts.tasks || `${baseDir}/tasks.md`,
|
|
303
|
+
bugfix: artifacts.bugfix || null,
|
|
304
|
+
implementation_notes: implementationNotes,
|
|
305
|
+
checklist: artifacts.checklist || `${baseDir}/checklist.md`,
|
|
306
|
+
iterations: artifacts.iterations || `${baseDir}/iterations.md`,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function hydrateExecutionPayload(targetDir, payload) {
|
|
311
|
+
const hydrated = JSON.parse(JSON.stringify(payload || {}));
|
|
312
|
+
const context = resolveRuntimeContext(targetDir);
|
|
313
|
+
const { currentRun, currentDispatch } = context;
|
|
314
|
+
|
|
315
|
+
hydrated.run_id = hydrated.run_id || currentDispatch?.run_id || currentRun?.run_id || null;
|
|
316
|
+
hydrated.dispatch_id = hydrated.dispatch_id || currentDispatch?.dispatch_id || null;
|
|
317
|
+
hydrated.role = typeof hydrated.role === 'object' && hydrated.role ? hydrated.role : {};
|
|
318
|
+
hydrated.role.id = hydrated.role.id || currentDispatch?.role?.id || null;
|
|
319
|
+
hydrated.role.name = hydrated.role.name || currentDispatch?.role?.name || null;
|
|
320
|
+
hydrated.flow = typeof hydrated.flow === 'object' && hydrated.flow ? hydrated.flow : {};
|
|
321
|
+
hydrated.flow.id = hydrated.flow.id || currentDispatch?.flow?.id || currentRun?.flow?.id || null;
|
|
322
|
+
hydrated.task = typeof hydrated.task === 'object' && hydrated.task ? hydrated.task : {};
|
|
323
|
+
hydrated.task.change_id =
|
|
324
|
+
hydrated.task.change_id ||
|
|
325
|
+
currentDispatch?.task?.change_id ||
|
|
326
|
+
currentRun?.task?.change_id ||
|
|
327
|
+
currentRun?.anchor?.task?.change_id ||
|
|
328
|
+
null;
|
|
329
|
+
hydrated.task.trace_mode =
|
|
330
|
+
hydrated.task.trace_mode ||
|
|
331
|
+
currentRun?.task?.trace_mode ||
|
|
332
|
+
currentRun?.incremental_update?.trace_mode ||
|
|
333
|
+
null;
|
|
334
|
+
|
|
335
|
+
const artifactMap = buildExecutionArtifactMap(
|
|
336
|
+
hydrated.task.change_id,
|
|
337
|
+
currentRun?.artifacts || {},
|
|
338
|
+
{
|
|
339
|
+
flowId: hydrated.flow.id,
|
|
340
|
+
runId: hydrated.run_id,
|
|
341
|
+
traceMode: hydrated.task.trace_mode,
|
|
342
|
+
},
|
|
343
|
+
);
|
|
344
|
+
hydrated.artifacts = {
|
|
345
|
+
...artifactMap,
|
|
346
|
+
...(typeof hydrated.artifacts === 'object' && hydrated.artifacts ? hydrated.artifacts : {}),
|
|
347
|
+
};
|
|
348
|
+
hydrated.openspec_action = hydrated.openspec_action || inferExecutionOpenSpecAction(hydrated, targetDir);
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
payload: hydrated,
|
|
352
|
+
context,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function hydrateRuntimeActionPayload(targetDir, payload) {
|
|
357
|
+
const hydrated = JSON.parse(JSON.stringify(payload || {}));
|
|
358
|
+
const context = resolveRuntimeContext(targetDir);
|
|
359
|
+
const { currentRun } = context;
|
|
360
|
+
|
|
361
|
+
hydrated.run_id = hydrated.run_id || currentRun?.run_id || null;
|
|
362
|
+
hydrated.from_role = hydrated.from_role || currentRun?.current_role || null;
|
|
363
|
+
hydrated.to_role = hydrated.to_role || null;
|
|
364
|
+
hydrated.openspec_action = hydrated.openspec_action || inferRuntimeActionOpenSpecAction(hydrated);
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
payload: hydrated,
|
|
368
|
+
context,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function collectMissingArtifacts(targetDir, artifactMap, keys) {
|
|
373
|
+
return keys
|
|
374
|
+
.map((key) => artifactMap[key])
|
|
375
|
+
.filter((relPath) => !relPath || !fs.existsSync(path.join(targetDir, relPath)));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function validateExecutionArtifacts(targetDir, payload) {
|
|
379
|
+
const flowId = payload.flow?.id || null;
|
|
380
|
+
const changeId = payload.task?.change_id || null;
|
|
381
|
+
if (flowId === 'prd-to-delivery' && !changeId) {
|
|
382
|
+
throw new Error(
|
|
383
|
+
`Execution payload for ${payload.role.id} requires task.change_id or current-run.task.change_id to resolve OpenSpec artifacts`,
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const artifactMap = buildExecutionArtifactMap(changeId, payload.artifacts || {}, {
|
|
388
|
+
flowId,
|
|
389
|
+
runId: payload.run_id,
|
|
390
|
+
traceMode: payload.task?.trace_mode || null,
|
|
391
|
+
});
|
|
392
|
+
const requirements = getRoleArtifactRequirements(targetDir, payload.role.id, flowId);
|
|
393
|
+
const requiredInputs = requirements.required_inputs;
|
|
394
|
+
const requiredOutputs = requirements.required_outputs;
|
|
395
|
+
const missingInputs = collectMissingArtifacts(targetDir, artifactMap, requiredInputs);
|
|
396
|
+
const missingOutputs = collectMissingArtifacts(targetDir, artifactMap, requiredOutputs);
|
|
397
|
+
|
|
398
|
+
if (missingInputs.length > 0) {
|
|
399
|
+
throw new Error(
|
|
400
|
+
`Execution payload for ${payload.role.id} is missing required inputs: ${missingInputs.join(', ')}`,
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
if (missingOutputs.length > 0) {
|
|
404
|
+
throw new Error(
|
|
405
|
+
`Execution payload for ${payload.role.id} is missing required artifacts: ${missingOutputs.join(', ')}`,
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
change_id: changeId,
|
|
411
|
+
openspec_action: payload.openspec_action || null,
|
|
412
|
+
required_inputs: requiredInputs.map((key) => artifactMap[key]),
|
|
413
|
+
required_outputs: requiredOutputs.map((key) => artifactMap[key]),
|
|
414
|
+
artifact_map: artifactMap,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function shouldTriggerArchiveChange(payload) {
|
|
419
|
+
const roleId = payload?.role?.id || null;
|
|
420
|
+
const status = String(payload?.status || '').trim().toLowerCase();
|
|
421
|
+
return roleId === 'archive-change' && ['done', 'success', 'completed'].includes(status);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function maybeApplyArchiveChange(targetDir, payload) {
|
|
425
|
+
if (!shouldTriggerArchiveChange(payload)) {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return archiveChange({
|
|
430
|
+
target: targetDir,
|
|
431
|
+
changeId: payload.task?.change_id || null,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function renderExecutionMarkdown(payload) {
|
|
436
|
+
if (payload.markdown && typeof payload.markdown === 'string') {
|
|
437
|
+
return payload.markdown.trim();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const lines = [];
|
|
441
|
+
lines.push('# 当前专家执行载荷');
|
|
442
|
+
lines.push('');
|
|
443
|
+
lines.push(`- run_id(运行 ID): ${payload.run_id || 'n/a'}`);
|
|
444
|
+
lines.push(`- role(专家角色): ${payload.role?.id || 'n/a'}${payload.role?.name ? `(${payload.role.name})` : ''}`);
|
|
445
|
+
if (payload.openspec_action) {
|
|
446
|
+
lines.push(`- openspec_action(OpenSpec 动作): ${payload.openspec_action}`);
|
|
447
|
+
}
|
|
448
|
+
lines.push(`- execution_id(执行 ID): ${payload.execution_id || 'n/a'}`);
|
|
449
|
+
lines.push(`- status(状态): ${payload.status || 'n/a'}`);
|
|
450
|
+
if (payload.flow?.id) lines.push(`- flow(流程模板): ${payload.flow.id}`);
|
|
451
|
+
lines.push('');
|
|
452
|
+
lines.push('## 执行摘要');
|
|
453
|
+
const steps = normalizeList(payload.execution_plan?.execution_steps);
|
|
454
|
+
if (steps.length === 0) {
|
|
455
|
+
lines.push('- 无');
|
|
456
|
+
} else {
|
|
457
|
+
for (const step of steps) {
|
|
458
|
+
lines.push(`- ${step}`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return lines.join('\n').trim();
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function renderRuntimeActionMarkdown(payload) {
|
|
465
|
+
if (payload.markdown && typeof payload.markdown === 'string') {
|
|
466
|
+
return payload.markdown.trim();
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const lines = [];
|
|
470
|
+
lines.push('# 当前运行动作草案');
|
|
471
|
+
lines.push('');
|
|
472
|
+
lines.push(`- run_id(运行 ID): ${payload.run_id || 'n/a'}`);
|
|
473
|
+
lines.push(`- action(动作): ${payload.action || 'n/a'}`);
|
|
474
|
+
if (payload.openspec_action) {
|
|
475
|
+
lines.push(`- openspec_action(OpenSpec 动作): ${payload.openspec_action}`);
|
|
476
|
+
}
|
|
477
|
+
lines.push(`- from_role(来源专家): ${payload.from_role || 'n/a'}`);
|
|
478
|
+
if (payload.to_role) lines.push(`- to_role(目标专家): ${payload.to_role}`);
|
|
479
|
+
if (payload.next_role) lines.push(`- next_role(下一位专家): ${payload.next_role}`);
|
|
480
|
+
lines.push(`- status(状态): ${payload.status || 'n/a'}`);
|
|
481
|
+
if (payload.message) lines.push(`- message(说明): ${payload.message}`);
|
|
482
|
+
return lines.join('\n').trim();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function validateExecutionPayload(payload, sourceLabel, context = {}) {
|
|
486
|
+
if (!payload || typeof payload !== 'object') {
|
|
487
|
+
throw new Error(`Invalid execution payload: ${sourceLabel}`);
|
|
488
|
+
}
|
|
489
|
+
if (payload.kind !== 'expert-execution') {
|
|
490
|
+
throw new Error(`Expected kind "expert-execution" but got "${payload.kind || 'undefined'}": ${sourceLabel}`);
|
|
491
|
+
}
|
|
492
|
+
if (!payload.run_id) {
|
|
493
|
+
throw new Error(`Execution payload is missing run_id: ${sourceLabel}`);
|
|
494
|
+
}
|
|
495
|
+
if (!payload.role || typeof payload.role !== 'object' || !payload.role.id) {
|
|
496
|
+
throw new Error(`Execution payload is missing role.id: ${sourceLabel}`);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const currentDispatch = context.currentDispatch || null;
|
|
500
|
+
if (currentDispatch?.run_id && payload.run_id && currentDispatch.run_id !== payload.run_id) {
|
|
501
|
+
throw new Error(
|
|
502
|
+
`Execution payload run_id does not match current-dispatch: expected ${currentDispatch.run_id}, got ${payload.run_id}`,
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
if (currentDispatch?.dispatch_id && payload.dispatch_id && currentDispatch.dispatch_id !== payload.dispatch_id) {
|
|
506
|
+
throw new Error(
|
|
507
|
+
`Execution payload dispatch_id does not match current-dispatch: expected ${currentDispatch.dispatch_id}, got ${payload.dispatch_id}`,
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
if (currentDispatch?.role?.id && payload.role.id && currentDispatch.role.id !== payload.role.id) {
|
|
511
|
+
throw new Error(
|
|
512
|
+
`Execution payload role.id does not match current-dispatch: expected ${currentDispatch.role.id}, got ${payload.role.id}`,
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function validateRuntimeActionPayload(payload, sourceLabel) {
|
|
518
|
+
if (!payload || typeof payload !== 'object') {
|
|
519
|
+
throw new Error(`Invalid runtime-action payload: ${sourceLabel}`);
|
|
520
|
+
}
|
|
521
|
+
if (payload.kind !== 'task-orchestrator-runtime-action') {
|
|
522
|
+
throw new Error(`Expected kind "task-orchestrator-runtime-action" but got "${payload.kind || 'undefined'}": ${sourceLabel}`);
|
|
523
|
+
}
|
|
524
|
+
if (!payload.run_id) {
|
|
525
|
+
throw new Error(`Runtime-action payload is missing run_id: ${sourceLabel}`);
|
|
526
|
+
}
|
|
527
|
+
if (!payload.action) {
|
|
528
|
+
throw new Error(`Runtime-action payload is missing action: ${sourceLabel}`);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function normalizeExecutionPayload(payload) {
|
|
533
|
+
const normalized = JSON.parse(JSON.stringify(payload));
|
|
534
|
+
normalized.schema_version = normalized.schema_version || 1;
|
|
535
|
+
normalized.kind = 'expert-execution';
|
|
536
|
+
normalized.openspec_action = normalized.openspec_action || inferExecutionOpenSpecAction(normalized);
|
|
537
|
+
normalized.execution_id = normalized.execution_id || createStampedId('execution', normalized.role.id);
|
|
538
|
+
normalized.generated_at = normalized.generated_at || new Date().toISOString();
|
|
539
|
+
if (normalized.markdown || shouldWriteRuntimeMarkdown()) {
|
|
540
|
+
normalized.markdown = renderExecutionMarkdown(normalized);
|
|
541
|
+
} else {
|
|
542
|
+
delete normalized.markdown;
|
|
543
|
+
}
|
|
544
|
+
return normalized;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function attachVerificationIfNeeded(targetDir, payload) {
|
|
548
|
+
if (payload?.role?.id !== 'frontend-implementer') {
|
|
549
|
+
return payload;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const normalizedStatus = String(payload.status || '').trim().toLowerCase();
|
|
553
|
+
if (!['done', 'success', 'completed'].includes(normalizedStatus)) {
|
|
554
|
+
return payload;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (payload.verification && Array.isArray(payload.verification.steps) && payload.verification.steps.length > 0) {
|
|
558
|
+
return payload;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return {
|
|
562
|
+
...payload,
|
|
563
|
+
verification: runVerificationSuite(targetDir),
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function normalizeRuntimeActionPayload(payload) {
|
|
568
|
+
const normalized = JSON.parse(JSON.stringify(payload));
|
|
569
|
+
normalized.schema_version = normalized.schema_version || 1;
|
|
570
|
+
normalized.kind = 'task-orchestrator-runtime-action';
|
|
571
|
+
normalized.openspec_action = normalized.openspec_action || inferRuntimeActionOpenSpecAction(normalized);
|
|
572
|
+
normalized.action_id = normalized.action_id || createStampedId('action', normalized.action);
|
|
573
|
+
normalized.generated_at = normalized.generated_at || new Date().toISOString();
|
|
574
|
+
if (normalized.markdown || shouldWriteRuntimeMarkdown()) {
|
|
575
|
+
normalized.markdown = renderRuntimeActionMarkdown(normalized);
|
|
576
|
+
} else {
|
|
577
|
+
delete normalized.markdown;
|
|
578
|
+
}
|
|
579
|
+
return normalized;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function writeExecutionArtifacts(targetDir, payload) {
|
|
583
|
+
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
584
|
+
const currentExecutionJson = runtimePaths.currentExecutionJson.path;
|
|
585
|
+
const currentExecutionMd = runtimePaths.currentExecutionMd.path;
|
|
586
|
+
const persistHistory = shouldPersistHistory();
|
|
587
|
+
const writeCurrentMarkdown = shouldWriteRuntimeMarkdown();
|
|
588
|
+
let recordJson = null;
|
|
589
|
+
let recordMd = null;
|
|
590
|
+
if (persistHistory) {
|
|
591
|
+
const executionsDir = path.join(runtimePaths.executionsDir.path, payload.run_id);
|
|
592
|
+
ensureDir(executionsDir);
|
|
593
|
+
recordJson = path.join(executionsDir, `${payload.execution_id}.json`);
|
|
594
|
+
recordMd = path.join(executionsDir, `${payload.execution_id}.md`);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (runtimePaths.currentExecutionJson.legacyPath && fs.existsSync(runtimePaths.currentExecutionJson.legacyPath)) {
|
|
598
|
+
fs.unlinkSync(runtimePaths.currentExecutionJson.legacyPath);
|
|
599
|
+
}
|
|
600
|
+
if (runtimePaths.currentExecutionMd.legacyPath && fs.existsSync(runtimePaths.currentExecutionMd.legacyPath)) {
|
|
601
|
+
fs.unlinkSync(runtimePaths.currentExecutionMd.legacyPath);
|
|
602
|
+
}
|
|
603
|
+
writeJson(currentExecutionJson, payload);
|
|
604
|
+
if (writeCurrentMarkdown && payload.markdown) {
|
|
605
|
+
writeText(currentExecutionMd, payload.markdown);
|
|
606
|
+
}
|
|
607
|
+
if (recordJson && recordMd && payload.markdown) {
|
|
608
|
+
writeJson(recordJson, payload);
|
|
609
|
+
writeText(recordMd, payload.markdown);
|
|
610
|
+
} else if (recordJson) {
|
|
611
|
+
writeJson(recordJson, payload);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
return {
|
|
615
|
+
current_execution_json: currentExecutionJson,
|
|
616
|
+
current_execution_md: writeCurrentMarkdown && payload.markdown ? currentExecutionMd : null,
|
|
617
|
+
execution_record_json: recordJson,
|
|
618
|
+
execution_record_md: recordMd && payload.markdown ? recordMd : null,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function writeRuntimeActionArtifacts(targetDir, payload) {
|
|
623
|
+
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
624
|
+
const currentActionJson = runtimePaths.currentRuntimeActionJson.path;
|
|
625
|
+
const currentActionMd = runtimePaths.currentRuntimeActionMd.path;
|
|
626
|
+
const persistHistory = shouldPersistHistory();
|
|
627
|
+
const writeCurrentMarkdown = shouldWriteRuntimeMarkdown();
|
|
628
|
+
let recordJson = null;
|
|
629
|
+
let recordMd = null;
|
|
630
|
+
if (persistHistory) {
|
|
631
|
+
const actionDir = path.join(runtimePaths.runtimeActionsDir.path, payload.run_id);
|
|
632
|
+
ensureDir(actionDir);
|
|
633
|
+
recordJson = path.join(actionDir, `${payload.action_id}.json`);
|
|
634
|
+
recordMd = path.join(actionDir, `${payload.action_id}.md`);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (runtimePaths.currentRuntimeActionJson.legacyPath && fs.existsSync(runtimePaths.currentRuntimeActionJson.legacyPath)) {
|
|
638
|
+
fs.unlinkSync(runtimePaths.currentRuntimeActionJson.legacyPath);
|
|
639
|
+
}
|
|
640
|
+
if (runtimePaths.currentRuntimeActionMd.legacyPath && fs.existsSync(runtimePaths.currentRuntimeActionMd.legacyPath)) {
|
|
641
|
+
fs.unlinkSync(runtimePaths.currentRuntimeActionMd.legacyPath);
|
|
642
|
+
}
|
|
643
|
+
writeJson(currentActionJson, payload);
|
|
644
|
+
if (writeCurrentMarkdown && payload.markdown) {
|
|
645
|
+
writeText(currentActionMd, payload.markdown);
|
|
646
|
+
}
|
|
647
|
+
if (recordJson && recordMd && payload.markdown) {
|
|
648
|
+
writeJson(recordJson, payload);
|
|
649
|
+
writeText(recordMd, payload.markdown);
|
|
650
|
+
} else if (recordJson) {
|
|
651
|
+
writeJson(recordJson, payload);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
return {
|
|
655
|
+
current_runtime_action_json: currentActionJson,
|
|
656
|
+
current_runtime_action_md: writeCurrentMarkdown && payload.markdown ? currentActionMd : null,
|
|
657
|
+
runtime_action_record_json: recordJson,
|
|
658
|
+
runtime_action_record_md: recordMd && payload.markdown ? recordMd : null,
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function readPayloadFromOptions(options, label) {
|
|
663
|
+
const inputCount = [Boolean(options.payload), Boolean(options.stdin)].filter(Boolean).length;
|
|
664
|
+
if (inputCount === 0) {
|
|
665
|
+
throw new Error(`Missing ${label} input: use --payload <file> or --stdin`);
|
|
666
|
+
}
|
|
667
|
+
if (inputCount > 1) {
|
|
668
|
+
throw new Error('Use either --payload <file> or --stdin, not both');
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const sourcePath = options.payload
|
|
672
|
+
? path.resolve(process.cwd(), options.payload)
|
|
673
|
+
: 'stdin';
|
|
674
|
+
|
|
675
|
+
const rawPayload = options.payload
|
|
676
|
+
? readJson(sourcePath, label)
|
|
677
|
+
: readJsonFromStdin(label);
|
|
678
|
+
|
|
679
|
+
return { sourcePath, rawPayload };
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function cleanupTmpSource(targetDir, sourcePath) {
|
|
683
|
+
if (!sourcePath || sourcePath === 'stdin' || !fs.existsSync(sourcePath)) {
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const runtimePaths = resolveRuntimePaths(path.resolve(targetDir));
|
|
688
|
+
for (const candidate of getCandidatePaths(runtimePaths.tmpDir)) {
|
|
689
|
+
const relative = path.relative(candidate, sourcePath);
|
|
690
|
+
if (!relative.startsWith('..') && !path.isAbsolute(relative)) {
|
|
691
|
+
fs.unlinkSync(sourcePath);
|
|
692
|
+
return sourcePath;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function clearCurrentExpertArtifacts(targetDir) {
|
|
699
|
+
return {
|
|
700
|
+
dispatch: expertDispatch.clearDispatch({ target: targetDir }),
|
|
701
|
+
execution: clearExecution({ target: targetDir }),
|
|
702
|
+
runtime_action: clearRuntimeAction({ target: targetDir }),
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function applyRuntimeMutation(targetDir, payload, payloadSource) {
|
|
707
|
+
const guardedPayload = guardRuntimeActionForIncompleteExecution(targetDir, payload);
|
|
708
|
+
const requestedAction = String(guardedPayload.action || '').trim().toLowerCase();
|
|
709
|
+
const runtimeAction = requestedAction === 'archive'
|
|
710
|
+
? 'complete'
|
|
711
|
+
: requestedAction === 'completed'
|
|
712
|
+
? 'complete'
|
|
713
|
+
: requestedAction === 'blocked'
|
|
714
|
+
? 'gate-blocked'
|
|
715
|
+
: requestedAction;
|
|
716
|
+
const options = {
|
|
717
|
+
target: targetDir,
|
|
718
|
+
runId: guardedPayload.run_id,
|
|
719
|
+
toRole: guardedPayload.to_role,
|
|
720
|
+
nextRole: guardedPayload.next_role,
|
|
721
|
+
fromRole: guardedPayload.from_role,
|
|
722
|
+
gate: guardedPayload.gate,
|
|
723
|
+
pendingGate: guardedPayload.pending_gate,
|
|
724
|
+
blockedByRole: guardedPayload.blocked_by_role,
|
|
725
|
+
resumeToRole: guardedPayload.resume_to_role,
|
|
726
|
+
requiredUserAction: guardedPayload.required_user_action,
|
|
727
|
+
blockedReason: guardedPayload.blocked_reason,
|
|
728
|
+
message: guardedPayload.message,
|
|
729
|
+
error: guardedPayload.error,
|
|
730
|
+
eventType: guardedPayload.event_type || guardedPayload.eventType,
|
|
731
|
+
status: guardedPayload.status,
|
|
732
|
+
artifactsData: guardedPayload.artifacts || null,
|
|
733
|
+
verificationData: guardedPayload.verification || null,
|
|
734
|
+
autoFixData: guardedPayload.auto_fix || null,
|
|
735
|
+
skipArtifactCheck:
|
|
736
|
+
Object.prototype.hasOwnProperty.call(guardedPayload, 'skip_artifact_check') ||
|
|
737
|
+
Object.prototype.hasOwnProperty.call(guardedPayload, 'skipArtifactCheck')
|
|
738
|
+
? Boolean(
|
|
739
|
+
Object.prototype.hasOwnProperty.call(guardedPayload, 'skip_artifact_check')
|
|
740
|
+
? guardedPayload.skip_artifact_check
|
|
741
|
+
: guardedPayload.skipArtifactCheck
|
|
742
|
+
)
|
|
743
|
+
: undefined,
|
|
744
|
+
clearPendingGate:
|
|
745
|
+
Object.prototype.hasOwnProperty.call(guardedPayload, 'clear_pending_gate') ||
|
|
746
|
+
Object.prototype.hasOwnProperty.call(guardedPayload, 'clearPendingGate')
|
|
747
|
+
? Boolean(
|
|
748
|
+
Object.prototype.hasOwnProperty.call(guardedPayload, 'clear_pending_gate')
|
|
749
|
+
? guardedPayload.clear_pending_gate
|
|
750
|
+
: guardedPayload.clearPendingGate
|
|
751
|
+
)
|
|
752
|
+
: undefined,
|
|
753
|
+
taskAnchorData: guardedPayload.task_anchor || guardedPayload.taskAnchor || null,
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
let result = null;
|
|
757
|
+
switch (runtimeAction) {
|
|
758
|
+
case 'handoff':
|
|
759
|
+
result = runtimeState.handoffRunState(options);
|
|
760
|
+
break;
|
|
761
|
+
case 'approve':
|
|
762
|
+
result = runtimeState.approveRunState(options);
|
|
763
|
+
break;
|
|
764
|
+
case 'resume':
|
|
765
|
+
result = runtimeState.resumeRunState(options);
|
|
766
|
+
break;
|
|
767
|
+
case 'gate-blocked':
|
|
768
|
+
result = runtimeState.gateBlockedRunState(options);
|
|
769
|
+
break;
|
|
770
|
+
case 'status':
|
|
771
|
+
result = runtimeState.statusRunState(options);
|
|
772
|
+
break;
|
|
773
|
+
case 'complete':
|
|
774
|
+
result = runtimeState.completeRunState(options);
|
|
775
|
+
break;
|
|
776
|
+
case 'fail':
|
|
777
|
+
result = runtimeState.failRunState(options);
|
|
778
|
+
break;
|
|
779
|
+
case 'cancel':
|
|
780
|
+
result = runtimeState.cancelRunState(options);
|
|
781
|
+
break;
|
|
782
|
+
default:
|
|
783
|
+
throw new Error(`Unsupported runtime action for expert-executor: ${guardedPayload.action}`);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
const clearableActions = new Set([
|
|
787
|
+
'handoff',
|
|
788
|
+
'approve',
|
|
789
|
+
'resume',
|
|
790
|
+
'gate-blocked',
|
|
791
|
+
'complete',
|
|
792
|
+
'fail',
|
|
793
|
+
'cancel',
|
|
794
|
+
]);
|
|
795
|
+
const cleared = clearableActions.has(runtimeAction)
|
|
796
|
+
? clearCurrentExpertArtifacts(targetDir)
|
|
797
|
+
: null;
|
|
798
|
+
|
|
799
|
+
return {
|
|
800
|
+
requested_action: requestedAction,
|
|
801
|
+
applied_action: runtimeAction,
|
|
802
|
+
adapter_source: payloadSource,
|
|
803
|
+
result,
|
|
804
|
+
cleared,
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function applyExecution(options) {
|
|
809
|
+
const targetDir = path.resolve(options.target || '.');
|
|
810
|
+
const { sourcePath, rawPayload } = readPayloadFromOptions(options, 'expert-execution');
|
|
811
|
+
const hydrated = hydrateExecutionPayload(targetDir, rawPayload);
|
|
812
|
+
validateExecutionPayload(hydrated.payload, sourcePath, hydrated.context);
|
|
813
|
+
const validation = validateExecutionArtifacts(targetDir, hydrated.payload);
|
|
814
|
+
const archive_result = maybeApplyArchiveChange(targetDir, hydrated.payload);
|
|
815
|
+
const payload = normalizeExecutionPayload(attachVerificationIfNeeded(targetDir, hydrated.payload));
|
|
816
|
+
const artifacts = writeExecutionArtifacts(targetDir, payload);
|
|
817
|
+
let runtime_transition = null;
|
|
818
|
+
if (shouldAdvanceRuntime(options)) {
|
|
819
|
+
const runtimeActionPayload = buildAutoRuntimeAction(targetDir, payload);
|
|
820
|
+
if (runtimeActionPayload) {
|
|
821
|
+
if (archive_result?.archived_artifacts) {
|
|
822
|
+
runtimeActionPayload.artifacts = archive_result.archived_artifacts;
|
|
823
|
+
runtimeActionPayload.skip_artifact_check = true;
|
|
824
|
+
}
|
|
825
|
+
const runtimePayload = normalizeRuntimeActionPayload(runtimeActionPayload);
|
|
826
|
+
const runtimeArtifacts = writeRuntimeActionArtifacts(targetDir, runtimePayload);
|
|
827
|
+
const applied = applyRuntimeMutation(targetDir, runtimePayload, 'expert-executor:auto-runtime');
|
|
828
|
+
runtime_transition = {
|
|
829
|
+
payload: runtimePayload,
|
|
830
|
+
artifacts: {
|
|
831
|
+
...runtimeArtifacts,
|
|
832
|
+
current_runtime_action_json: applied.cleared ? null : runtimeArtifacts.current_runtime_action_json,
|
|
833
|
+
current_runtime_action_md: applied.cleared ? null : runtimeArtifacts.current_runtime_action_md,
|
|
834
|
+
},
|
|
835
|
+
applied: {
|
|
836
|
+
requested_action: applied.requested_action,
|
|
837
|
+
applied_action: applied.applied_action,
|
|
838
|
+
run_id: applied.result?.state?.run_id || null,
|
|
839
|
+
status: applied.result?.state?.status || null,
|
|
840
|
+
current_role: applied.result?.state?.current_role || null,
|
|
841
|
+
pending_gate: applied.result?.state?.pending_gate || null,
|
|
842
|
+
},
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
const cleanedSource = cleanupTmpSource(targetDir, sourcePath);
|
|
847
|
+
|
|
848
|
+
return {
|
|
849
|
+
status: 'success',
|
|
850
|
+
target: targetDir,
|
|
851
|
+
source: sourcePath,
|
|
852
|
+
artifacts: {
|
|
853
|
+
...artifacts,
|
|
854
|
+
current_execution_json: runtime_transition?.applied ? null : artifacts.current_execution_json,
|
|
855
|
+
current_execution_md: runtime_transition?.applied ? null : artifacts.current_execution_md,
|
|
856
|
+
},
|
|
857
|
+
payload,
|
|
858
|
+
validation,
|
|
859
|
+
archive_result,
|
|
860
|
+
runtime_transition,
|
|
861
|
+
cleaned_source: cleanedSource,
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
function applyExecutionData(options) {
|
|
866
|
+
const targetDir = path.resolve(options.target || '.');
|
|
867
|
+
const sourcePath = options.source || 'memory-payload';
|
|
868
|
+
const hydrated = hydrateExecutionPayload(targetDir, options.payloadData);
|
|
869
|
+
validateExecutionPayload(hydrated.payload, sourcePath, hydrated.context);
|
|
870
|
+
const validation = validateExecutionArtifacts(targetDir, hydrated.payload);
|
|
871
|
+
const archive_result = maybeApplyArchiveChange(targetDir, hydrated.payload);
|
|
872
|
+
const payload = normalizeExecutionPayload(attachVerificationIfNeeded(targetDir, hydrated.payload));
|
|
873
|
+
const artifacts = writeExecutionArtifacts(targetDir, payload);
|
|
874
|
+
let runtime_transition = null;
|
|
875
|
+
if (shouldAdvanceRuntime(options)) {
|
|
876
|
+
const runtimeActionPayload = buildAutoRuntimeAction(targetDir, payload);
|
|
877
|
+
if (runtimeActionPayload) {
|
|
878
|
+
if (archive_result?.archived_artifacts) {
|
|
879
|
+
runtimeActionPayload.artifacts = archive_result.archived_artifacts;
|
|
880
|
+
runtimeActionPayload.skip_artifact_check = true;
|
|
881
|
+
}
|
|
882
|
+
const runtimePayload = normalizeRuntimeActionPayload(runtimeActionPayload);
|
|
883
|
+
const runtimeArtifacts = writeRuntimeActionArtifacts(targetDir, runtimePayload);
|
|
884
|
+
const applied = applyRuntimeMutation(targetDir, runtimePayload, 'expert-executor:auto-runtime');
|
|
885
|
+
runtime_transition = {
|
|
886
|
+
payload: runtimePayload,
|
|
887
|
+
artifacts: {
|
|
888
|
+
...runtimeArtifacts,
|
|
889
|
+
current_runtime_action_json: applied.cleared ? null : runtimeArtifacts.current_runtime_action_json,
|
|
890
|
+
current_runtime_action_md: applied.cleared ? null : runtimeArtifacts.current_runtime_action_md,
|
|
891
|
+
},
|
|
892
|
+
applied: {
|
|
893
|
+
requested_action: applied.requested_action,
|
|
894
|
+
applied_action: applied.applied_action,
|
|
895
|
+
run_id: applied.result?.state?.run_id || null,
|
|
896
|
+
status: applied.result?.state?.status || null,
|
|
897
|
+
current_role: applied.result?.state?.current_role || null,
|
|
898
|
+
pending_gate: applied.result?.state?.pending_gate || null,
|
|
899
|
+
},
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return {
|
|
905
|
+
status: 'success',
|
|
906
|
+
target: targetDir,
|
|
907
|
+
source: sourcePath,
|
|
908
|
+
artifacts: {
|
|
909
|
+
...artifacts,
|
|
910
|
+
current_execution_json: runtime_transition?.applied ? null : artifacts.current_execution_json,
|
|
911
|
+
current_execution_md: runtime_transition?.applied ? null : artifacts.current_execution_md,
|
|
912
|
+
},
|
|
913
|
+
payload,
|
|
914
|
+
validation,
|
|
915
|
+
archive_result,
|
|
916
|
+
runtime_transition,
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function applyRuntimeAction(options) {
|
|
921
|
+
const targetDir = path.resolve(options.target || '.');
|
|
922
|
+
const { sourcePath, rawPayload } = readPayloadFromOptions(options, 'runtime-action');
|
|
923
|
+
const hydrated = hydrateRuntimeActionPayload(targetDir, rawPayload);
|
|
924
|
+
validateRuntimeActionPayload(hydrated.payload, sourcePath);
|
|
925
|
+
const payload = normalizeRuntimeActionPayload(hydrated.payload);
|
|
926
|
+
const artifacts = writeRuntimeActionArtifacts(targetDir, payload);
|
|
927
|
+
let runtime_transition = null;
|
|
928
|
+
if (shouldAdvanceRuntime(options)) {
|
|
929
|
+
const applied = applyRuntimeMutation(targetDir, payload, sourcePath);
|
|
930
|
+
runtime_transition = {
|
|
931
|
+
applied: {
|
|
932
|
+
requested_action: applied.requested_action,
|
|
933
|
+
applied_action: applied.applied_action,
|
|
934
|
+
run_id: applied.result?.state?.run_id || null,
|
|
935
|
+
status: applied.result?.state?.status || null,
|
|
936
|
+
current_role: applied.result?.state?.current_role || null,
|
|
937
|
+
pending_gate: applied.result?.state?.pending_gate || null,
|
|
938
|
+
},
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
const cleanedSource = cleanupTmpSource(targetDir, sourcePath);
|
|
942
|
+
|
|
943
|
+
return {
|
|
944
|
+
status: 'success',
|
|
945
|
+
target: targetDir,
|
|
946
|
+
source: sourcePath,
|
|
947
|
+
artifacts: {
|
|
948
|
+
...artifacts,
|
|
949
|
+
current_runtime_action_json: runtime_transition?.applied ? null : artifacts.current_runtime_action_json,
|
|
950
|
+
current_runtime_action_md: runtime_transition?.applied ? null : artifacts.current_runtime_action_md,
|
|
951
|
+
},
|
|
952
|
+
payload,
|
|
953
|
+
runtime_transition,
|
|
954
|
+
cleaned_source: cleanedSource,
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function applyRuntimeActionData(options) {
|
|
959
|
+
const targetDir = path.resolve(options.target || '.');
|
|
960
|
+
const sourcePath = options.source || 'memory-payload';
|
|
961
|
+
const hydrated = hydrateRuntimeActionPayload(targetDir, options.payloadData);
|
|
962
|
+
validateRuntimeActionPayload(hydrated.payload, sourcePath);
|
|
963
|
+
const payload = normalizeRuntimeActionPayload(hydrated.payload);
|
|
964
|
+
const artifacts = writeRuntimeActionArtifacts(targetDir, payload);
|
|
965
|
+
let runtime_transition = null;
|
|
966
|
+
if (shouldAdvanceRuntime(options)) {
|
|
967
|
+
const applied = applyRuntimeMutation(targetDir, payload, sourcePath);
|
|
968
|
+
runtime_transition = {
|
|
969
|
+
applied: {
|
|
970
|
+
requested_action: applied.requested_action,
|
|
971
|
+
applied_action: applied.applied_action,
|
|
972
|
+
run_id: applied.result?.state?.run_id || null,
|
|
973
|
+
status: applied.result?.state?.status || null,
|
|
974
|
+
current_role: applied.result?.state?.current_role || null,
|
|
975
|
+
pending_gate: applied.result?.state?.pending_gate || null,
|
|
976
|
+
},
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
return {
|
|
981
|
+
status: 'success',
|
|
982
|
+
target: targetDir,
|
|
983
|
+
source: sourcePath,
|
|
984
|
+
artifacts: {
|
|
985
|
+
...artifacts,
|
|
986
|
+
current_runtime_action_json: runtime_transition?.applied ? null : artifacts.current_runtime_action_json,
|
|
987
|
+
current_runtime_action_md: runtime_transition?.applied ? null : artifacts.current_runtime_action_md,
|
|
988
|
+
},
|
|
989
|
+
payload,
|
|
990
|
+
runtime_transition,
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function clearExecution(options) {
|
|
995
|
+
const targetDir = path.resolve(options.target || '.');
|
|
996
|
+
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
997
|
+
|
|
998
|
+
for (const currentExecutionJson of getCandidatePaths(runtimePaths.currentExecutionJson)) {
|
|
999
|
+
if (fs.existsSync(currentExecutionJson)) {
|
|
1000
|
+
fs.unlinkSync(currentExecutionJson);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
for (const currentExecutionMd of getCandidatePaths(runtimePaths.currentExecutionMd)) {
|
|
1004
|
+
if (fs.existsSync(currentExecutionMd)) {
|
|
1005
|
+
fs.unlinkSync(currentExecutionMd);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
return {
|
|
1010
|
+
status: 'success',
|
|
1011
|
+
target: targetDir,
|
|
1012
|
+
artifacts: {
|
|
1013
|
+
current_execution_json: runtimePaths.currentExecutionJson.path,
|
|
1014
|
+
current_execution_md: runtimePaths.currentExecutionMd.path,
|
|
1015
|
+
},
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function clearRuntimeAction(options) {
|
|
1020
|
+
const targetDir = path.resolve(options.target || '.');
|
|
1021
|
+
const runtimePaths = resolveRuntimePaths(targetDir);
|
|
1022
|
+
|
|
1023
|
+
for (const currentActionJson of getCandidatePaths(runtimePaths.currentRuntimeActionJson)) {
|
|
1024
|
+
if (fs.existsSync(currentActionJson)) {
|
|
1025
|
+
fs.unlinkSync(currentActionJson);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
for (const currentActionMd of getCandidatePaths(runtimePaths.currentRuntimeActionMd)) {
|
|
1029
|
+
if (fs.existsSync(currentActionMd)) {
|
|
1030
|
+
fs.unlinkSync(currentActionMd);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
return {
|
|
1035
|
+
status: 'success',
|
|
1036
|
+
target: targetDir,
|
|
1037
|
+
artifacts: {
|
|
1038
|
+
current_runtime_action_json: runtimePaths.currentRuntimeActionJson.path,
|
|
1039
|
+
current_runtime_action_md: runtimePaths.currentRuntimeActionMd.path,
|
|
1040
|
+
},
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function printPretty(result, command) {
|
|
1045
|
+
console.log(`expert-executor ${command}`);
|
|
1046
|
+
console.log(` target: ${result.target}`);
|
|
1047
|
+
if (result.payload) {
|
|
1048
|
+
console.log(` run_id: ${result.payload.run_id}`);
|
|
1049
|
+
if (result.payload.kind === 'expert-execution') {
|
|
1050
|
+
console.log(` role: ${result.payload.role.id}`);
|
|
1051
|
+
console.log(` openspec_action: ${result.payload.openspec_action || 'n/a'}`);
|
|
1052
|
+
console.log(` execution_id: ${result.payload.execution_id}`);
|
|
1053
|
+
console.log(` current_execution: ${result.artifacts.current_execution_json}`);
|
|
1054
|
+
} else {
|
|
1055
|
+
console.log(` action: ${result.payload.action}`);
|
|
1056
|
+
console.log(` openspec_action: ${result.payload.openspec_action || 'n/a'}`);
|
|
1057
|
+
console.log(` current_runtime_action: ${result.artifacts.current_runtime_action_json}`);
|
|
1058
|
+
}
|
|
1059
|
+
if (result.runtime_transition?.applied) {
|
|
1060
|
+
console.log(` runtime_action: ${result.runtime_transition.applied.requested_action || 'n/a'}`);
|
|
1061
|
+
console.log(` runtime_status: ${result.runtime_transition.applied.status || 'n/a'}`);
|
|
1062
|
+
console.log(` runtime_current_role: ${result.runtime_transition.applied.current_role || 'n/a'}`);
|
|
1063
|
+
}
|
|
1064
|
+
} else {
|
|
1065
|
+
if (result.artifacts.current_execution_json) {
|
|
1066
|
+
console.log(` current_execution: ${result.artifacts.current_execution_json}`);
|
|
1067
|
+
}
|
|
1068
|
+
if (result.artifacts.current_runtime_action_json) {
|
|
1069
|
+
console.log(` current_runtime_action: ${result.artifacts.current_runtime_action_json}`);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
async function main(argv = process.argv.slice(2)) {
|
|
1075
|
+
const { command, options } = parseArgs(argv);
|
|
1076
|
+
|
|
1077
|
+
if (!command || options.help || command === 'help' || command === '--help' || command === '-h') {
|
|
1078
|
+
printUsage();
|
|
1079
|
+
return 0;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
if (command === 'apply' || command === 'run') {
|
|
1083
|
+
const result = applyExecution(options);
|
|
1084
|
+
await drainVisualRuntimeStatePushes();
|
|
1085
|
+
if (options.json) {
|
|
1086
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1087
|
+
} else {
|
|
1088
|
+
printPretty(result, command);
|
|
1089
|
+
}
|
|
1090
|
+
return 0;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
if (command === 'apply-action' || command === 'finish') {
|
|
1094
|
+
const result = applyRuntimeAction(options);
|
|
1095
|
+
await drainVisualRuntimeStatePushes();
|
|
1096
|
+
if (options.json) {
|
|
1097
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1098
|
+
} else {
|
|
1099
|
+
printPretty(result, command);
|
|
1100
|
+
}
|
|
1101
|
+
return 0;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
if (command === 'clear') {
|
|
1105
|
+
const result = clearExecution(options);
|
|
1106
|
+
if (options.json) {
|
|
1107
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1108
|
+
} else {
|
|
1109
|
+
printPretty(result, command);
|
|
1110
|
+
}
|
|
1111
|
+
return 0;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
if (command === 'clear-action') {
|
|
1115
|
+
const result = clearRuntimeAction(options);
|
|
1116
|
+
if (options.json) {
|
|
1117
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1118
|
+
} else {
|
|
1119
|
+
printPretty(result, command);
|
|
1120
|
+
}
|
|
1121
|
+
return 0;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
throw new Error(`Unsupported expert-executor command: ${command}`);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
module.exports = {
|
|
1128
|
+
main,
|
|
1129
|
+
applyExecution,
|
|
1130
|
+
applyExecutionData,
|
|
1131
|
+
applyRuntimeAction,
|
|
1132
|
+
applyRuntimeActionData,
|
|
1133
|
+
clearExecution,
|
|
1134
|
+
clearRuntimeAction,
|
|
1135
|
+
validateExecutionPayload,
|
|
1136
|
+
validateRuntimeActionPayload,
|
|
1137
|
+
normalizeExecutionPayload,
|
|
1138
|
+
normalizeRuntimeActionPayload,
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
if (require.main === module) {
|
|
1142
|
+
try {
|
|
1143
|
+
main().then((code) => process.exit(code));
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
console.error(`expert-executor error: ${error.message}`);
|
|
1146
|
+
process.exit(1);
|
|
1147
|
+
}
|
|
1148
|
+
}
|