sillyspec 3.27.2 → 3.27.6
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/.claude/skills/sillyspec-execute/SKILL.md +8 -0
- package/.claude/skills/sillyspec-quick/SKILL.md +2 -1
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-archive/SKILL.md +87 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-auto/SKILL.md +93 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-commit/SKILL.md +67 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-continue/SKILL.md +47 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-execute/SKILL.md +214 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-explore/SKILL.md +102 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-export/SKILL.md +57 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-init/SKILL.md +177 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-plan/SKILL.md +156 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-quick/SKILL.md +116 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-resume/SKILL.md +70 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-scan/SKILL.md +79 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-state/SKILL.md +64 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-status/SKILL.md +54 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-verify/SKILL.md +87 -0
- package/.claude/worktrees/sillyspec-data-model-research/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
- package/.claude/worktrees/sillyspec-data-model-research/.gitattributes +2 -0
- package/.claude/worktrees/sillyspec-data-model-research/.husky/pre-push +20 -0
- package/.claude/worktrees/sillyspec-data-model-research/README.md +203 -0
- package/.claude/worktrees/sillyspec-data-model-research/SKILL.md +91 -0
- package/.claude/worktrees/sillyspec-data-model-research/bin/sillyspec.js +2 -0
- package/.claude/worktrees/sillyspec-data-model-research/logo.jpg +0 -0
- package/.claude/worktrees/sillyspec-data-model-research/package-lock.json +977 -0
- package/.claude/worktrees/sillyspec-data-model-research/package.json +39 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/dist/favicon.jpg +0 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/dist/index.html +16 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/dist/logo.jpg +0 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/dist/prototype-dashboard.html +836 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/dist/prototype-overview.html +256 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/package.json +25 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/server/executor.js +95 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/server/index.js +679 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/server/parser.js +526 -0
- package/.claude/worktrees/sillyspec-data-model-research/packages/dashboard/server/watcher.js +357 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/agent-session-log.js +803 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/change-list.js +290 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/change-risk-profile.js +270 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/check-primitives.js +65 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/classify-change.js +109 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/commit-suggest.js +202 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/config-cat.js +88 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/config-schema.js +328 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/constants.js +97 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/contract-matrix.js +480 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/datetime.js +20 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/db-engine.js +55 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/db.js +381 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/decision-distill.js +517 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/dispatch/backends/local-agent.js +155 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/dispatch/backends/sillyhub-mcp.js +245 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/dispatch/probe.js +246 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/dispatch/strategy.js +121 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/docs-check.js +825 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/docs-debt.js +393 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/docs-gate.js +107 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/doctor-diagnostics.js +1099 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/endpoint-extractor.js +420 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/foreign-declared.js +78 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/fs-atomic.js +73 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/git-helper.js +150 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/hooks/claude-pre-tool-use.cjs +130 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/hooks/worktree-guard.js +892 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/index.js +2798 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/init.js +626 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/knowledge-match.js +231 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/local-detect.js +128 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/local-register.js +104 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/machine-interface.js +543 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/migrate.js +127 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/module-impact.js +166 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/module-resolve.js +222 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/modules.js +580 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/progress/change-registry.js +336 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/progress/consistency-doctor.js +355 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/progress/shared.js +36 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/progress/stage-machine.js +594 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/progress/step-store.js +265 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/progress.js +1304 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/quick-recommend.js +115 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/quicklog.js +852 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/review-tier.js +77 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/command.js +1595 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/complete-handlers.js +1552 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/complete.js +1259 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/concurrent-detect.js +156 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/gates.js +1084 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/multi-repo-context.js +208 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/next.js +128 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/prompt.js +843 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/quick-audit.js +186 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/scan-profile.js +269 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/shared.js +1562 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run/stage.js +584 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/run.js +23 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/scan-diff.js +388 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/scan-postcheck.js +512 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/scan-staleness.js +95 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/setup.js +414 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/sillyhub-mcp/client.js +597 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/sillyhub-mcp/config.js +62 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/spec-dir-typo.js +50 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/spec-sync.js +358 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stage-contract-engine.js +171 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stage-contract-spec.js +550 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stage-contract.js +889 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stage-review.js +597 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/archive.js +199 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/brainstorm-auto.js +236 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/brainstorm.js +617 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/cmd-existence.js +145 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/doctor.js +540 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/execute.js +1275 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/explore.js +43 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/index.js +29 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/knowledge.js +514 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/plan-postcheck.js +1344 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/plan.js +650 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/quick.js +167 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/scan.js +608 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/status.js +64 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/stages/verify.js +246 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/sync.js +1470 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/task-review.js +1498 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/taskcard.js +210 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/verify-postcheck.js +1718 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/verify-probes.js +277 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/version.js +19 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/workflow.js +600 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/workspace.js +125 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/worktree-apply.js +1446 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/worktree-deps.js +576 -0
- package/.claude/worktrees/sillyspec-data-model-research/src/worktree.js +1715 -0
- package/.claude/worktrees/sillyspec-data-model-research/templates/claude-instruction.md +23 -0
- package/.claude/worktrees/sillyspec-data-model-research/templates/prompts/taskcard-rules.md +28 -0
- package/.claude/worktrees/sillyspec-data-model-research/templates/prompts/testcase-design.md +12 -0
- package/.claude/worktrees/sillyspec-data-model-research/templates/prompts/verify-probes.md +32 -0
- package/.claude/worktrees/sillyspec-data-model-research/templates/workflows/archive-impact.yaml +79 -0
- package/.claude/worktrees/sillyspec-data-model-research/templates/workflows/scan-docs.yaml +132 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-archive/SKILL.md +87 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-auto/SKILL.md +93 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-commit/SKILL.md +67 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-continue/SKILL.md +47 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-execute/SKILL.md +214 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-explore/SKILL.md +102 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-export/SKILL.md +57 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-init/SKILL.md +177 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-plan/SKILL.md +156 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-propose/SKILL.md +87 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-quick/SKILL.md +116 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-resume/SKILL.md +70 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-scan/SKILL.md +79 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-state/SKILL.md +64 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-status/SKILL.md +54 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-verify/SKILL.md +87 -0
- package/.worktrees/8d2d0392/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
- package/.worktrees/8d2d0392/.claude/skills/verify-per-user/SKILL.md +6 -0
- package/.worktrees/8d2d0392/.gitattributes +2 -0
- package/.worktrees/8d2d0392/.husky/pre-push +20 -0
- package/.worktrees/8d2d0392/README.md +203 -0
- package/.worktrees/8d2d0392/SKILL.md +91 -0
- package/.worktrees/8d2d0392/architecture-analysis.md +448 -0
- package/.worktrees/8d2d0392/bin/sillyspec.js +2 -0
- package/.worktrees/8d2d0392/eval/README.md +86 -0
- package/.worktrees/8d2d0392/eval/eval.config.json +28 -0
- package/.worktrees/8d2d0392/eval/lib/adapters/cli.mjs +63 -0
- package/.worktrees/8d2d0392/eval/lib/adapters/dryrun.mjs +27 -0
- package/.worktrees/8d2d0392/eval/lib/config.mjs +82 -0
- package/.worktrees/8d2d0392/eval/lib/db.mjs +76 -0
- package/.worktrees/8d2d0392/eval/lib/report.mjs +120 -0
- package/.worktrees/8d2d0392/eval/lib/runner.mjs +157 -0
- package/.worktrees/8d2d0392/eval/lib/tasks.mjs +73 -0
- package/.worktrees/8d2d0392/eval/lib/util.mjs +107 -0
- package/.worktrees/8d2d0392/eval/lib/workdir.mjs +30 -0
- package/.worktrees/8d2d0392/eval/run.mjs +83 -0
- package/.worktrees/8d2d0392/eval/tasks/001-slugify/files/package.json +6 -0
- package/.worktrees/8d2d0392/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
- package/.worktrees/8d2d0392/eval/tasks/001-slugify/task.json +6 -0
- package/.worktrees/8d2d0392/eval/tasks/001-slugify/verify.mjs +28 -0
- package/.worktrees/8d2d0392/eval/tasks/002-each-day/files/package.json +6 -0
- package/.worktrees/8d2d0392/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
- package/.worktrees/8d2d0392/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
- package/.worktrees/8d2d0392/eval/tasks/002-each-day/task.json +6 -0
- package/.worktrees/8d2d0392/eval/tasks/002-each-day/verify.mjs +31 -0
- package/.worktrees/8d2d0392/eval/tasks/003-word-report/files/data/notes.txt +5 -0
- package/.worktrees/8d2d0392/eval/tasks/003-word-report/files/package.json +6 -0
- package/.worktrees/8d2d0392/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
- package/.worktrees/8d2d0392/eval/tasks/003-word-report/task.json +6 -0
- package/.worktrees/8d2d0392/eval/tasks/003-word-report/verify.mjs +38 -0
- package/.worktrees/8d2d0392/logo.jpg +0 -0
- package/.worktrees/8d2d0392/package-lock.json +977 -0
- package/.worktrees/8d2d0392/package.json +41 -0
- package/.worktrees/8d2d0392/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
- package/.worktrees/8d2d0392/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
- package/.worktrees/8d2d0392/packages/dashboard/dist/favicon.jpg +0 -0
- package/.worktrees/8d2d0392/packages/dashboard/dist/index.html +16 -0
- package/.worktrees/8d2d0392/packages/dashboard/dist/logo.jpg +0 -0
- package/.worktrees/8d2d0392/packages/dashboard/dist/prototype-dashboard.html +836 -0
- package/.worktrees/8d2d0392/packages/dashboard/dist/prototype-overview.html +256 -0
- package/.worktrees/8d2d0392/packages/dashboard/package.json +25 -0
- package/.worktrees/8d2d0392/packages/dashboard/server/executor.js +95 -0
- package/.worktrees/8d2d0392/packages/dashboard/server/index.js +679 -0
- package/.worktrees/8d2d0392/packages/dashboard/server/parser.js +526 -0
- package/.worktrees/8d2d0392/packages/dashboard/server/watcher.js +357 -0
- package/.worktrees/8d2d0392/src/agent-session-log.js +803 -0
- package/.worktrees/8d2d0392/src/change-list.js +290 -0
- package/.worktrees/8d2d0392/src/change-risk-profile.js +339 -0
- package/.worktrees/8d2d0392/src/check-primitives.js +65 -0
- package/.worktrees/8d2d0392/src/classify-change.js +109 -0
- package/.worktrees/8d2d0392/src/commit-suggest.js +202 -0
- package/.worktrees/8d2d0392/src/config-cat.js +88 -0
- package/.worktrees/8d2d0392/src/config-schema.js +328 -0
- package/.worktrees/8d2d0392/src/constants.js +97 -0
- package/.worktrees/8d2d0392/src/contract-matrix.js +533 -0
- package/.worktrees/8d2d0392/src/datetime.js +20 -0
- package/.worktrees/8d2d0392/src/db-engine.js +55 -0
- package/.worktrees/8d2d0392/src/db.js +381 -0
- package/.worktrees/8d2d0392/src/decision-distill.js +517 -0
- package/.worktrees/8d2d0392/src/dispatch/backends/local-agent.js +155 -0
- package/.worktrees/8d2d0392/src/dispatch/backends/sillyhub-mcp.js +245 -0
- package/.worktrees/8d2d0392/src/dispatch/probe.js +246 -0
- package/.worktrees/8d2d0392/src/dispatch/strategy.js +121 -0
- package/.worktrees/8d2d0392/src/docs-check.js +825 -0
- package/.worktrees/8d2d0392/src/docs-debt.js +393 -0
- package/.worktrees/8d2d0392/src/docs-gate.js +107 -0
- package/.worktrees/8d2d0392/src/doctor-diagnostics.js +1099 -0
- package/.worktrees/8d2d0392/src/endpoint-extractor.js +409 -0
- package/.worktrees/8d2d0392/src/foreign-declared.js +78 -0
- package/.worktrees/8d2d0392/src/fs-atomic.js +73 -0
- package/.worktrees/8d2d0392/src/git-helper.js +150 -0
- package/.worktrees/8d2d0392/src/hooks/claude-pre-tool-use.cjs +130 -0
- package/.worktrees/8d2d0392/src/hooks/worktree-guard.js +892 -0
- package/.worktrees/8d2d0392/src/index.js +2854 -0
- package/.worktrees/8d2d0392/src/init.js +626 -0
- package/.worktrees/8d2d0392/src/knowledge-match.js +231 -0
- package/.worktrees/8d2d0392/src/local-detect.js +128 -0
- package/.worktrees/8d2d0392/src/local-register.js +104 -0
- package/.worktrees/8d2d0392/src/machine-interface.js +543 -0
- package/.worktrees/8d2d0392/src/migrate.js +127 -0
- package/.worktrees/8d2d0392/src/module-impact.js +166 -0
- package/.worktrees/8d2d0392/src/module-resolve.js +222 -0
- package/.worktrees/8d2d0392/src/modules.js +580 -0
- package/.worktrees/8d2d0392/src/plan-adopt-waves.js +126 -0
- package/.worktrees/8d2d0392/src/progress/change-registry.js +336 -0
- package/.worktrees/8d2d0392/src/progress/consistency-doctor.js +355 -0
- package/.worktrees/8d2d0392/src/progress/shared.js +36 -0
- package/.worktrees/8d2d0392/src/progress/stage-machine.js +594 -0
- package/.worktrees/8d2d0392/src/progress/step-store.js +265 -0
- package/.worktrees/8d2d0392/src/progress.js +1304 -0
- package/.worktrees/8d2d0392/src/quick-recommend.js +115 -0
- package/.worktrees/8d2d0392/src/quicklog.js +883 -0
- package/.worktrees/8d2d0392/src/review-tier.js +77 -0
- package/.worktrees/8d2d0392/src/run/command.js +1641 -0
- package/.worktrees/8d2d0392/src/run/complete-handlers.js +1552 -0
- package/.worktrees/8d2d0392/src/run/complete.js +1259 -0
- package/.worktrees/8d2d0392/src/run/concurrent-detect.js +156 -0
- package/.worktrees/8d2d0392/src/run/gates.js +1094 -0
- package/.worktrees/8d2d0392/src/run/multi-repo-context.js +208 -0
- package/.worktrees/8d2d0392/src/run/next.js +128 -0
- package/.worktrees/8d2d0392/src/run/prompt.js +843 -0
- package/.worktrees/8d2d0392/src/run/quick-audit.js +186 -0
- package/.worktrees/8d2d0392/src/run/scan-profile.js +269 -0
- package/.worktrees/8d2d0392/src/run/shared.js +1562 -0
- package/.worktrees/8d2d0392/src/run/stage.js +587 -0
- package/.worktrees/8d2d0392/src/run.js +23 -0
- package/.worktrees/8d2d0392/src/scan-diff.js +388 -0
- package/.worktrees/8d2d0392/src/scan-postcheck.js +524 -0
- package/.worktrees/8d2d0392/src/scan-staleness.js +95 -0
- package/.worktrees/8d2d0392/src/setup.js +414 -0
- package/.worktrees/8d2d0392/src/sillyhub-mcp/client.js +597 -0
- package/.worktrees/8d2d0392/src/sillyhub-mcp/config.js +62 -0
- package/.worktrees/8d2d0392/src/spec-dir-typo.js +50 -0
- package/.worktrees/8d2d0392/src/spec-sync.js +358 -0
- package/.worktrees/8d2d0392/src/stage-contract-engine.js +171 -0
- package/.worktrees/8d2d0392/src/stage-contract-spec.js +551 -0
- package/.worktrees/8d2d0392/src/stage-contract.js +948 -0
- package/.worktrees/8d2d0392/src/stage-review.js +597 -0
- package/.worktrees/8d2d0392/src/stages/archive.js +199 -0
- package/.worktrees/8d2d0392/src/stages/brainstorm-auto.js +285 -0
- package/.worktrees/8d2d0392/src/stages/brainstorm.js +624 -0
- package/.worktrees/8d2d0392/src/stages/cmd-existence.js +145 -0
- package/.worktrees/8d2d0392/src/stages/doctor.js +540 -0
- package/.worktrees/8d2d0392/src/stages/execute.js +1277 -0
- package/.worktrees/8d2d0392/src/stages/explore.js +43 -0
- package/.worktrees/8d2d0392/src/stages/index.js +29 -0
- package/.worktrees/8d2d0392/src/stages/knowledge.js +514 -0
- package/.worktrees/8d2d0392/src/stages/plan-postcheck.js +1398 -0
- package/.worktrees/8d2d0392/src/stages/plan.js +651 -0
- package/.worktrees/8d2d0392/src/stages/quick.js +167 -0
- package/.worktrees/8d2d0392/src/stages/scan.js +608 -0
- package/.worktrees/8d2d0392/src/stages/status.js +64 -0
- package/.worktrees/8d2d0392/src/stages/verify.js +246 -0
- package/.worktrees/8d2d0392/src/sync.js +1470 -0
- package/.worktrees/8d2d0392/src/task-review.js +1498 -0
- package/.worktrees/8d2d0392/src/taskcard-placeholders.js +21 -0
- package/.worktrees/8d2d0392/src/taskcard.js +217 -0
- package/.worktrees/8d2d0392/src/verify-postcheck.js +1718 -0
- package/.worktrees/8d2d0392/src/verify-probes.js +327 -0
- package/.worktrees/8d2d0392/src/version.js +19 -0
- package/.worktrees/8d2d0392/src/workflow.js +600 -0
- package/.worktrees/8d2d0392/src/workspace.js +125 -0
- package/.worktrees/8d2d0392/src/worktree-apply.js +1611 -0
- package/.worktrees/8d2d0392/src/worktree-deps.js +576 -0
- package/.worktrees/8d2d0392/src/worktree.js +1838 -0
- package/.worktrees/8d2d0392/templates/claude-instruction.md +23 -0
- package/.worktrees/8d2d0392/templates/prompts/taskcard-rules.md +29 -0
- package/.worktrees/8d2d0392/templates/prompts/testcase-design.md +12 -0
- package/.worktrees/8d2d0392/templates/prompts/verify-probes.md +32 -0
- package/.worktrees/8d2d0392/templates/workflows/archive-impact.yaml +79 -0
- package/.worktrees/8d2d0392/templates/workflows/scan-docs.yaml +132 -0
- package/architecture-analysis.md +448 -0
- package/eval/README.md +86 -0
- package/eval/eval.config.json +28 -0
- package/eval/lib/adapters/cli.mjs +63 -0
- package/eval/lib/adapters/dryrun.mjs +27 -0
- package/eval/lib/config.mjs +82 -0
- package/eval/lib/db.mjs +76 -0
- package/eval/lib/report.mjs +120 -0
- package/eval/lib/runner.mjs +157 -0
- package/eval/lib/tasks.mjs +73 -0
- package/eval/lib/util.mjs +107 -0
- package/eval/lib/workdir.mjs +30 -0
- package/eval/run.mjs +83 -0
- package/eval/tasks/001-slugify/files/package.json +6 -0
- package/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
- package/eval/tasks/001-slugify/task.json +6 -0
- package/eval/tasks/001-slugify/verify.mjs +28 -0
- package/eval/tasks/002-each-day/files/package.json +6 -0
- package/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
- package/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
- package/eval/tasks/002-each-day/task.json +6 -0
- package/eval/tasks/002-each-day/verify.mjs +31 -0
- package/eval/tasks/003-word-report/files/data/notes.txt +5 -0
- package/eval/tasks/003-word-report/files/package.json +6 -0
- package/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
- package/eval/tasks/003-word-report/task.json +6 -0
- package/eval/tasks/003-word-report/verify.mjs +38 -0
- package/package.json +4 -2
- package/src/agent-session-log.js +45 -5
- package/src/change-risk-profile.js +83 -14
- package/src/config-schema.js +18 -3
- package/src/contract-matrix.js +90 -29
- package/src/datetime.js +20 -0
- package/src/decision-distill.js +517 -0
- package/src/dispatch/backends/local-agent.js +4 -4
- package/src/docs-check.js +227 -0
- package/src/docs-debt.js +187 -24
- package/src/doctor-diagnostics.js +102 -2
- package/src/endpoint-extractor.js +41 -52
- package/src/foreign-declared.js +155 -0
- package/src/index.js +95 -13
- package/src/init.js +9 -7
- package/src/knowledge-match.js +107 -6
- package/src/local-register.js +7 -1
- package/src/module-resolve.js +12 -1
- package/src/modules.js +2 -1
- package/src/plan-adopt-waves.js +126 -0
- package/src/quicklog.js +50 -4
- package/src/run/command.js +124 -44
- package/src/run/complete-handlers.js +48 -19
- package/src/run/complete.js +5 -2
- package/src/run/gates.js +104 -22
- package/src/run/prompt.js +84 -42
- package/src/run/quick-audit.js +11 -0
- package/src/run/shared.js +152 -10
- package/src/run/stage.js +8 -5
- package/src/run.js +2 -2
- package/src/scan-postcheck.js +30 -17
- package/src/stage-contract-spec.js +3 -2
- package/src/stage-contract.js +68 -4
- package/src/stages/archive.js +53 -12
- package/src/stages/brainstorm-auto.js +50 -1
- package/src/stages/brainstorm.js +13 -0
- package/src/stages/doctor.js +157 -1
- package/src/stages/execute.js +32 -6
- package/src/stages/plan-postcheck.js +76 -17
- package/src/stages/plan.js +9 -4
- package/src/stages/quick.js +6 -1
- package/src/stages/verify.js +32 -15
- package/src/sync.js +41 -3
- package/src/task-review.js +2 -2
- package/src/taskcard-placeholders.js +21 -0
- package/src/taskcard.js +43 -1
- package/src/verify-postcheck.js +315 -13
- package/src/verify-probes.js +73 -10
- package/src/worktree-apply.js +569 -227
- package/src/worktree-deps.js +150 -1
- package/src/worktree.js +285 -77
- package/templates/prompts/taskcard-rules.md +2 -1
|
@@ -0,0 +1,1304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SillySpec ProgressManager — 进度恢复管理
|
|
3
|
+
*
|
|
4
|
+
* 纯 Node.js,无外部依赖。支持多变更并行。
|
|
5
|
+
*
|
|
6
|
+
* 存储结构:
|
|
7
|
+
* .sillyspec/.runtime/sillyspec.db — SQLite 数据库(权威状态源,含全局状态/项目名/活跃变更)
|
|
8
|
+
*
|
|
9
|
+
* 历史迁移:v1/v2 使用 progress.json 文件,v3 已全部迁移至 SQLite。
|
|
10
|
+
* worktree-guard hook 直读 sillyspec.db,不再有 gate-status.json 缓存双源(task-10 废除)。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, unlinkSync, appendFileSync, copyFileSync, readdirSync, statSync } from 'fs';
|
|
14
|
+
import { join, basename, dirname, resolve, sep } from 'path';
|
|
15
|
+
import { tmpdir } from 'os';
|
|
16
|
+
import { writeAtomicSync } from './fs-atomic.js';
|
|
17
|
+
import { DB } from './db.js';
|
|
18
|
+
import { checkExecuteCodeEvidence } from './stage-contract.js';
|
|
19
|
+
import { ConsistencyDoctor } from './progress/consistency-doctor.js';
|
|
20
|
+
import { ChangeRegistry } from './progress/change-registry.js';
|
|
21
|
+
import { StepStore } from './progress/step-store.js';
|
|
22
|
+
import { StageMachine } from './progress/stage-machine.js';
|
|
23
|
+
import { stageRegistry } from './stages/index.js';
|
|
24
|
+
import { STAGE_ORDER, MAIN_FLOW_ORDER, VALID_STAGES, STAGE_LABELS, SPEC_DIR_NAME, CURRENT_VERSION, emptyStage } from './progress/shared.js';
|
|
25
|
+
// resolveSpecDir 单一真相源在 src/run/shared.js(含 home 拒绝守卫,坑 cwd-correction-home-collision
|
|
26
|
+
// 根治:home 下 .sillyspec 恒不命中,防 smoke/临时目录污染自我延续)。此处 re-export 保持
|
|
27
|
+
// 既有 import 路径兼容;run/shared.js 对 progress.js 只有动态 import,无静态循环。
|
|
28
|
+
import { resolveSpecDir } from './run/shared.js';
|
|
29
|
+
import { checkPlatformManaged, PLATFORM_MANAGED_FILENAME } from './run/shared.js';
|
|
30
|
+
export { resolveSpecDir };
|
|
31
|
+
|
|
32
|
+
// 默认规范目录名(相对于 cwd)
|
|
33
|
+
// SPEC_DIR_NAME → ./progress/shared.js(W6 Step9d)
|
|
34
|
+
const RUNTIME_SUBDIR = '.runtime';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 向上查找含 .sillyspec 目录的祖先目录——实现已收敛至 src/run/shared.js(单一真相源,
|
|
38
|
+
* 含 home 拒绝守卫),此处 re-export。见顶部 import 说明。
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 平台指针不可达错误。pointer 存在但失效时抛出,阻止静默回退到本地孤儿 db。
|
|
43
|
+
* 逃生口:显式 --spec-dir 绕过 pointer 校验。
|
|
44
|
+
*/
|
|
45
|
+
export class PointerUnreachableError extends Error {
|
|
46
|
+
constructor({ pointerPath, specRoot, reason, hint }) {
|
|
47
|
+
super(
|
|
48
|
+
`平台指针不可用:${reason}\n` +
|
|
49
|
+
` pointer: ${pointerPath}\n` +
|
|
50
|
+
` specRoot: ${specRoot || '(缺失)'}\n` +
|
|
51
|
+
`修复:${hint}`
|
|
52
|
+
);
|
|
53
|
+
this.name = 'PointerUnreachableError';
|
|
54
|
+
this.pointerPath = pointerPath;
|
|
55
|
+
this.specRoot = specRoot || null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 平台接管声明生效错误(指针缺失但声明存在)。fail-closed 入口一:
|
|
61
|
+
* 防指针被 cleanup/STALE 清理或项目挪动后裸调静默建本地进度库(状态分裂根因)。
|
|
62
|
+
*
|
|
63
|
+
* ⚠️ 不覆写 this.name(保持父类的 'PointerUnreachableError')——CLI 顶层 catch 按
|
|
64
|
+
* err?.name === 'PointerUnreachableError' 严格字符串匹配(index.js),子类改名会
|
|
65
|
+
* 落通用错误分支打 stack noise。靠 message 首行"平台接管声明生效"区分场景。
|
|
66
|
+
*/
|
|
67
|
+
export class PlatformManagedError extends PointerUnreachableError {
|
|
68
|
+
constructor({ declarationPath, specRoot }) {
|
|
69
|
+
super({
|
|
70
|
+
pointerPath: declarationPath,
|
|
71
|
+
specRoot,
|
|
72
|
+
reason: `平台接管声明生效——本项目已由平台托管,但恢复指针缺失(可能被 platform pointer --cleanup 清理或项目目录被移动),拒绝静默回退本地模式`,
|
|
73
|
+
hint: `① 重跑平台 scan/init(带 --spec-root)重建指针;② 确认不再使用平台:sillyspec platform disconnect(删除接管声明);③ 显式 --spec-dir <路径> 临时指定目录`,
|
|
74
|
+
});
|
|
75
|
+
this.declarationPath = declarationPath;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 平台感知的 specDir 解析(fail-closed,所有 CLI 子命令统一入口)。
|
|
81
|
+
*
|
|
82
|
+
* 优先级:显式 --spec-dir > pointer.specRoot(可达)> resolveSpecDir(cwd)。
|
|
83
|
+
*
|
|
84
|
+
* fail-closed 语义(修复"状态穿越"定时炸弹):
|
|
85
|
+
* 一旦项目进入过平台模式(pointer 文件存在),pointer 失效(specRoot 不可达 /
|
|
86
|
+
* 损坏 / 缺字段)不再静默回退到本地——否则会读到切平台前的过期本地 db。
|
|
87
|
+
* 此时抛 PointerUnreachableError,由 CLI 顶层捕获并打印修复引导。
|
|
88
|
+
*
|
|
89
|
+
* 无 pointer = 纯本地项目(从未平台 scan),正常走本地解析,不受影响。
|
|
90
|
+
*/
|
|
91
|
+
export function resolvePlatformSpecDir(cwd, explicitSpecDir = null) {
|
|
92
|
+
if (explicitSpecDir) return resolve(explicitSpecDir);
|
|
93
|
+
const pointerPath = join(resolve(cwd), '.sillyspec-platform.json');
|
|
94
|
+
if (!existsSync(pointerPath)) {
|
|
95
|
+
// 指针缺失:查平台接管声明(fail-closed 入口一)。声明存在 = 项目进过平台模式,
|
|
96
|
+
// 指针丢失不该静默当纯本地项目处理(会建本地进度库 → 状态分裂)。
|
|
97
|
+
const decl = checkPlatformManaged(cwd);
|
|
98
|
+
if (decl) {
|
|
99
|
+
throw new PlatformManagedError({
|
|
100
|
+
declarationPath: join(resolve(cwd), PLATFORM_MANAGED_FILENAME),
|
|
101
|
+
specRoot: decl.specRoot,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return resolveSpecDir(cwd);
|
|
105
|
+
}
|
|
106
|
+
// pointer 存在 = 进过平台模式,严格校验,不静默回退
|
|
107
|
+
let ptr;
|
|
108
|
+
try {
|
|
109
|
+
ptr = JSON.parse(readFileSync(pointerPath, 'utf8'));
|
|
110
|
+
} catch (e) {
|
|
111
|
+
throw new PointerUnreachableError({
|
|
112
|
+
pointerPath,
|
|
113
|
+
specRoot: null,
|
|
114
|
+
reason: `pointer 文件损坏(${e.message})`,
|
|
115
|
+
hint: `sillyspec platform pointer --cleanup 删除后重跑平台 scan`,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (!ptr.specRoot) {
|
|
119
|
+
throw new PointerUnreachableError({
|
|
120
|
+
pointerPath,
|
|
121
|
+
specRoot: null,
|
|
122
|
+
reason: 'pointer 缺少 specRoot 字段',
|
|
123
|
+
hint: `sillyspec platform pointer --cleanup 删除后重跑平台 scan`,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (!existsSync(ptr.specRoot)) {
|
|
127
|
+
throw new PointerUnreachableError({
|
|
128
|
+
pointerPath,
|
|
129
|
+
specRoot: ptr.specRoot,
|
|
130
|
+
reason: 'pointer.specRoot 路径不存在(daemon 未起?已迁移?)',
|
|
131
|
+
hint: `启动 SillyHub daemon;或 sillyspec doctor --json 诊断;或显式 --spec-dir <本地路径> 临时走本地`,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// 驾驭:pointer 指向 OS temp 目录几乎肯定是陈旧测试/CI 残留(合法项目不会把 specRoot 放 temp)。
|
|
135
|
+
// 历史:npm test 等会写 pointer 到 Temp/spec-dir-test-*,不清理则污染真实环境,所有命令静默落错库。
|
|
136
|
+
// 非阻断警告:让 agent 知道当前解析到的 specDir 可疑,而非静默写到死库。
|
|
137
|
+
const resolvedTmp = resolve(tmpdir());
|
|
138
|
+
if (resolve(ptr.specRoot) === resolvedTmp || resolve(ptr.specRoot).startsWith(resolvedTmp + sep)) {
|
|
139
|
+
console.warn(
|
|
140
|
+
`⚠️ 平台 pointer 的 specRoot 指向系统 temp 目录:${ptr.specRoot}\n` +
|
|
141
|
+
` 这通常是陈旧的测试/CI 残留,命令会写进这个可疑库而非你当前项目。\n` +
|
|
142
|
+
` 修复:sillyspec platform pointer --cleanup(删除 ${pointerPath}),或删除该 pointer 文件后回到项目目录重跑。`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return ptr.specRoot;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const CHANGES_SUBDIR = 'changes';
|
|
149
|
+
// CURRENT_VERSION → ./progress/shared.js(W6 Step9d)
|
|
150
|
+
// VALID_STAGES → ./progress/shared.js(W6 Step9c)
|
|
151
|
+
// VALID_STATUSES → ./progress/step-store.js(updateStep 专用,本地化)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
// ── ProgressManager ──
|
|
155
|
+
|
|
156
|
+
export class ProgressManager {
|
|
157
|
+
/** 模块级 DB 连接池:Map<dbPath, DB>(SEC-09/PERF-10,见 _ensureDB 注释) */
|
|
158
|
+
static _dbPool = new Map();
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @param {object} [opts]
|
|
162
|
+
* @param {string} [opts.specDir] - 规范目录绝对路径(默认 cwd/.sillyspec)
|
|
163
|
+
*/
|
|
164
|
+
constructor(opts = {}) {
|
|
165
|
+
this._customSpecDir = opts.specDir || null;
|
|
166
|
+
this._consistency = new ConsistencyDoctor(this);
|
|
167
|
+
this._changeRegistry = new ChangeRegistry(this);
|
|
168
|
+
this._stepStore = new StepStore(this);
|
|
169
|
+
this._stageMachine = new StageMachine(this);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ── 路径工具 ──
|
|
173
|
+
|
|
174
|
+
/** 获取 specDir(优先自定义,否则向上查找含 .sillyspec 的目录,fallback 到 cwd/.sillyspec) */
|
|
175
|
+
_getSpecDir(cwd) {
|
|
176
|
+
if (this._customSpecDir) return this._customSpecDir;
|
|
177
|
+
// specDir 对给定 cwd 在进程生命周期内不变(.sillyspec 目录不会被移动),
|
|
178
|
+
// 按 cwd 缓存,避免每次路径解析都向上 existsSync 遍历目录树(热路径)。
|
|
179
|
+
if (!this._specDirCache) this._specDirCache = new Map();
|
|
180
|
+
const cached = this._specDirCache.get(cwd);
|
|
181
|
+
if (cached) return cached;
|
|
182
|
+
const resolved = resolveSpecDir(cwd);
|
|
183
|
+
this._specDirCache.set(cwd, resolved);
|
|
184
|
+
return resolved;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
_runtimePath(cwd, ...parts) {
|
|
188
|
+
return join(this._getSpecDir(cwd), RUNTIME_SUBDIR, ...parts);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
_changePath(cwd, changeName, ...parts) {
|
|
192
|
+
return join(this._getSpecDir(cwd), CHANGES_SUBDIR, changeName, ...parts);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_ensureRuntimeDir(cwd) {
|
|
196
|
+
const runtimeDir = this._runtimePath(cwd);
|
|
197
|
+
if (!existsSync(runtimeDir)) {
|
|
198
|
+
mkdirSync(runtimeDir, { recursive: true });
|
|
199
|
+
for (const d of ['artifacts', 'history', 'logs', 'templates']) {
|
|
200
|
+
mkdirSync(join(runtimeDir, d), { recursive: true });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 懒初始化 DB 连接,缓存在实例上(better-sqlite3 同步 API,init 无 async)。
|
|
207
|
+
*
|
|
208
|
+
* SEC-09/PERF-10(2026-08-20 体检):连接额外进模块级 Map<dbPath, DB> 单例——
|
|
209
|
+
* 一条平台命令此前会 new 多个 ProgressManager(triggerPull / sync / import 各建),
|
|
210
|
+
* 同一 sillyspec.db 被 open 3-5 次,每次重跑 PRAGMA + schema 探测,且多连接
|
|
211
|
+
* 提升 SQLITE_BUSY 概率、Windows 残留句柄影响文件替换。CLI 短进程生命周期内
|
|
212
|
+
* dbPath 不变,进程退出由 OS 回收句柄(node:sqlite 无显式泄漏);进程内共享
|
|
213
|
+
* 单连接后 WAL 写竞争面反而缩小。
|
|
214
|
+
*/
|
|
215
|
+
_ensureDB(cwd) {
|
|
216
|
+
if (!this._db) {
|
|
217
|
+
const dbPath = this._runtimePath(cwd, 'sillyspec.db');
|
|
218
|
+
let db = ProgressManager._dbPool.get(dbPath);
|
|
219
|
+
if (!db) {
|
|
220
|
+
db = new DB(dbPath);
|
|
221
|
+
db.init();
|
|
222
|
+
ProgressManager._dbPool.set(dbPath, db);
|
|
223
|
+
}
|
|
224
|
+
this._db = db;
|
|
225
|
+
}
|
|
226
|
+
return this._db;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
_ensureChangeDir(cwd, changeName) {
|
|
230
|
+
const dir = this._changePath(cwd, changeName);
|
|
231
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
232
|
+
return dir;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ── 全局状态 ──
|
|
236
|
+
|
|
237
|
+
readGlobal(cwd) {
|
|
238
|
+
// SQL: SELECT FROM project + changes
|
|
239
|
+
const db = this._ensureDB(cwd);
|
|
240
|
+
const sqlDb = db.getDb();
|
|
241
|
+
|
|
242
|
+
// 读取 project 行(id=1)
|
|
243
|
+
const row = sqlDb.prepare('SELECT name, schema_version FROM project WHERE id = 1').get();
|
|
244
|
+
if (row === undefined) return null;
|
|
245
|
+
const { name, schema_version: schemaVersion } = row;
|
|
246
|
+
|
|
247
|
+
// 读取 active 变更列表
|
|
248
|
+
const changeRows = sqlDb.prepare("SELECT name FROM changes WHERE status = 'active' ORDER BY name").all();
|
|
249
|
+
const activeChanges = changeRows.map(r => r.name);
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
_version: schemaVersion,
|
|
253
|
+
project: name,
|
|
254
|
+
activeChanges,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ── 变更级别状态 ──
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 读取指定变更的 progress(SQL 版)
|
|
262
|
+
* @param {string} cwd
|
|
263
|
+
* @param {string|null} changeName - 变更名,null 时尝试自动检测
|
|
264
|
+
* @returns {object|null} 与 SQLite 查询结果一致的 JS 对象
|
|
265
|
+
*/
|
|
266
|
+
read(cwd, changeName = null) {
|
|
267
|
+
// 自动检测变更名(listChanges 已在 task-08 同步化,此处直接拿到活跃变更数组)
|
|
268
|
+
if (!changeName) {
|
|
269
|
+
const changes = this.listChanges(cwd);
|
|
270
|
+
if (changes.length === 1) {
|
|
271
|
+
changeName = changes[0];
|
|
272
|
+
} else {
|
|
273
|
+
// 多个或零个活跃变更,无法确定
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const db = this._ensureDB(cwd);
|
|
279
|
+
const sqlDb = db.getDb();
|
|
280
|
+
|
|
281
|
+
// 1. 从 changes 表获取基本信息
|
|
282
|
+
const changeRow = sqlDb.prepare('SELECT id, name, current_stage, no_worktree, last_active FROM changes WHERE name = ?').get(changeName);
|
|
283
|
+
if (changeRow === undefined) return null;
|
|
284
|
+
const { id: changeId, name: cName, current_stage: currentStage, no_worktree: noWorktree, last_active: lastActive } = changeRow;
|
|
285
|
+
|
|
286
|
+
// 2. 从 stages 表获取所有阶段(含 revision 列)
|
|
287
|
+
const stageRows = sqlDb.prepare('SELECT id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason FROM stages WHERE change_id = ? ORDER BY id').all(changeId);
|
|
288
|
+
const stageMap = {};
|
|
289
|
+
const stageIds = [];
|
|
290
|
+
for (const row of stageRows) {
|
|
291
|
+
const { id: sId, stage, status, started_at: startedAt, completed_at: completedAt, revision, reopened_from_step: reopenedFromStep, reopened_at: reopenedAt, stale_reason: staleReason } = row;
|
|
292
|
+
stageMap[stage] = { _dbId: sId, status, startedAt, completedAt,
|
|
293
|
+
...(revision != null ? { revision } : {}),
|
|
294
|
+
...(reopenedFromStep ? { reopenedFromStep } : {}),
|
|
295
|
+
...(reopenedAt ? { reopenedAt } : {}),
|
|
296
|
+
...(staleReason ? { staleReason } : {}),
|
|
297
|
+
};
|
|
298
|
+
stageIds.push(sId);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 3. 从 steps 表获取所有步骤
|
|
302
|
+
const stepsByStage = {};
|
|
303
|
+
if (stageIds.length > 0) {
|
|
304
|
+
const placeholders = stageIds.map(() => '?').join(',');
|
|
305
|
+
const stepRows = sqlDb.prepare(
|
|
306
|
+
`SELECT stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options, wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds FROM steps WHERE stage_id IN (${placeholders}) ORDER BY stage_id, ordering`
|
|
307
|
+
).all(...stageIds);
|
|
308
|
+
// 按阶段分组步骤
|
|
309
|
+
for (const row of stepRows) {
|
|
310
|
+
const { stage_id: stageId, name, status, output, completed_at: completedAt, wait_reason: waitReason, wait_options: waitOptions, wait_answer: waitAnswer, waited_at: waitedAt, wait_answers: waitAnswersJson, wait_round: waitRound, max_wait_rounds: maxWaitRounds } = row;
|
|
311
|
+
if (!stepsByStage[stageId]) stepsByStage[stageId] = [];
|
|
312
|
+
let waitAnswers = null;
|
|
313
|
+
if (waitAnswersJson) {
|
|
314
|
+
try { waitAnswers = JSON.parse(waitAnswersJson); } catch (e) { console.warn(`[progress] waitAnswers JSON 损坏,已跳过: ${e.message}`); }
|
|
315
|
+
}
|
|
316
|
+
stepsByStage[stageId].push({
|
|
317
|
+
name, status, output, completedAt,
|
|
318
|
+
...(waitReason ? { waitReason } : {}),
|
|
319
|
+
...(waitOptions ? { waitOptions } : {}),
|
|
320
|
+
...(waitAnswer ? { waitAnswer } : {}),
|
|
321
|
+
...(waitedAt ? { waitedAt } : {}),
|
|
322
|
+
...(waitAnswers ? { waitAnswers } : {}),
|
|
323
|
+
...(waitRound != null ? { waitRound } : {}),
|
|
324
|
+
...(maxWaitRounds != null ? { maxWaitRounds } : {}),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 4. 从 batch_progress 表获取批量进度
|
|
330
|
+
const batchRow = sqlDb.prepare('SELECT total, completed, failed, skipped FROM batch_progress WHERE change_id = ?').get(changeId);
|
|
331
|
+
let batchProgress = undefined;
|
|
332
|
+
if (batchRow !== undefined) {
|
|
333
|
+
const { total, completed, failed, skipped } = batchRow;
|
|
334
|
+
batchProgress = { total, completed, failed, skipped };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 5. 获取项目名
|
|
338
|
+
const projectRow = sqlDb.prepare('SELECT name FROM project WHERE id = 1').get();
|
|
339
|
+
const projectName = projectRow !== undefined ? projectRow.name : '';
|
|
340
|
+
|
|
341
|
+
// 6. 组装为兼容对象
|
|
342
|
+
const stages = {};
|
|
343
|
+
// 先填充所有 VALID_STAGES
|
|
344
|
+
for (const s of VALID_STAGES) {
|
|
345
|
+
stages[s] = emptyStage();
|
|
346
|
+
}
|
|
347
|
+
// 用 DB 数据覆盖
|
|
348
|
+
for (const [stage, info] of Object.entries(stageMap)) {
|
|
349
|
+
const steps = (stepsByStage[info._dbId] || []).map(s => ({
|
|
350
|
+
name: s.name,
|
|
351
|
+
status: s.status,
|
|
352
|
+
output: s.output,
|
|
353
|
+
completedAt: s.completedAt,
|
|
354
|
+
...(s.waitReason ? { waitReason: s.waitReason } : {}),
|
|
355
|
+
...(s.waitOptions ? { waitOptions: s.waitOptions } : {}),
|
|
356
|
+
...(s.waitAnswer ? { waitAnswer: s.waitAnswer } : {}),
|
|
357
|
+
...(s.waitedAt ? { waitedAt: s.waitedAt } : {}),
|
|
358
|
+
...(s.waitAnswers ? { waitAnswers: s.waitAnswers } : {}),
|
|
359
|
+
...(s.waitRound != null ? { waitRound: s.waitRound } : {}),
|
|
360
|
+
...(s.maxWaitRounds != null ? { maxWaitRounds: s.maxWaitRounds } : {}),
|
|
361
|
+
}));
|
|
362
|
+
stages[stage] = {
|
|
363
|
+
status: info.status,
|
|
364
|
+
steps,
|
|
365
|
+
startedAt: info.startedAt,
|
|
366
|
+
completedAt: info.completedAt,
|
|
367
|
+
// Revision v1 fields
|
|
368
|
+
...(info.revision ? { revision: info.revision } : {}),
|
|
369
|
+
...(info.reopenedFromStep ? { reopenedFromStep: info.reopenedFromStep } : {}),
|
|
370
|
+
...(info.reopenedAt ? { reopenedAt: info.reopenedAt } : {}),
|
|
371
|
+
...(info.staleReason ? { staleReason: info.staleReason } : {}),
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const result = {
|
|
376
|
+
_version: 5,
|
|
377
|
+
project: projectName,
|
|
378
|
+
currentChange: cName,
|
|
379
|
+
currentStage: currentStage || '',
|
|
380
|
+
lastActive: lastActive || null,
|
|
381
|
+
stages,
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
// noWorktree
|
|
385
|
+
if (noWorktree) result.noWorktree = true;
|
|
386
|
+
|
|
387
|
+
// batchProgress(仅在 DB 中有记录时才包含)
|
|
388
|
+
if (batchProgress) result.batchProgress = batchProgress;
|
|
389
|
+
|
|
390
|
+
return result;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* 同步专用六表完整序列化(design §8/B1,task-02 / D-005@v2 / FR-07)。
|
|
395
|
+
* 与 read()(聚合视图,不读 approvals 且 changes 只投影五列)不同,本方法输出真正六表投影,
|
|
396
|
+
* 作为同步载体(ProgressManager.import() 的逆运算,task-03)。
|
|
397
|
+
*
|
|
398
|
+
* 输出契约(字段名 = DB 列名 snake_case,import 直接对列写回,round-trip 无映射损耗):
|
|
399
|
+
* project { name, schema_version } —— 全局单行稳定字段(id/created_at/updated_at 本地元数据不同步)
|
|
400
|
+
* changes [{ name, current_stage, status, last_active,
|
|
401
|
+
* last_synced_platform_ts, last_local_modified_ts }] —— 只投影流程进度列;
|
|
402
|
+
* 排除 isolation_* 系列 与 platform_* 系列(platform_change_id/workspace_id/last_sync/sync_enabled)
|
|
403
|
+
* 以及 created_at(本地强相关,不同步,B2)
|
|
404
|
+
* stages [{ change_name, stage, status, started_at, completed_at,
|
|
405
|
+
* revision, reopened_from_step, reopened_at, stale_reason }] —— 用 change_name+stage 替代 id 外键
|
|
406
|
+
* steps [{ change_name, stage, name, status, output, completed_at, ordering,
|
|
407
|
+
* wait_reason, wait_options, wait_answer, waited_at, wait_answers,
|
|
408
|
+
* wait_round, max_wait_rounds }] —— wait_options/wait_answers 透传 DB JSON 字符串
|
|
409
|
+
* batch_progress [{ change_name, total, completed, failed, skipped }]
|
|
410
|
+
* approvals [{ change_name, status, requested_at, approved_by, approved_at, rejection_reason }]
|
|
411
|
+
* 可空列归一为 null(非 undefined,保证 JSON 往返键稳定);不含 user/base_ts/pushed_at(D-015,sync.js 放 HTTP header)。
|
|
412
|
+
*
|
|
413
|
+
* @param {string} cwd
|
|
414
|
+
* @param {string|null} [changeName] - 空时单活跃变更自动推导(对齐 read());多/零活跃返回 null
|
|
415
|
+
* @returns {object|null} 六键同步 JSON;change 不存在或无法推导返回 null
|
|
416
|
+
*/
|
|
417
|
+
serializeForSync(cwd, changeName = null) {
|
|
418
|
+
// 自动检测变更名(与 read() 同口径):单活跃变更推导,多/零无法确定返回 null
|
|
419
|
+
if (!changeName) {
|
|
420
|
+
const changes = this.listChanges(cwd);
|
|
421
|
+
if (changes.length === 1) {
|
|
422
|
+
changeName = changes[0];
|
|
423
|
+
} else {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const db = this._ensureDB(cwd);
|
|
429
|
+
const sqlDb = db.getDb();
|
|
430
|
+
|
|
431
|
+
// 1. changes 行(投影流程进度列 + name 标识)
|
|
432
|
+
const changeRow = sqlDb.prepare(
|
|
433
|
+
`SELECT id, name, current_stage, status, last_active, last_synced_platform_ts, last_local_modified_ts
|
|
434
|
+
FROM changes WHERE name = ?`
|
|
435
|
+
).get(changeName);
|
|
436
|
+
if (changeRow === undefined) return null;
|
|
437
|
+
const changeId = changeRow.id;
|
|
438
|
+
const changeProj = {
|
|
439
|
+
name: changeRow.name,
|
|
440
|
+
current_stage: changeRow.current_stage,
|
|
441
|
+
status: changeRow.status,
|
|
442
|
+
last_active: changeRow.last_active,
|
|
443
|
+
last_synced_platform_ts: changeRow.last_synced_platform_ts ?? null,
|
|
444
|
+
last_local_modified_ts: changeRow.last_local_modified_ts ?? null,
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// 2. project 全局单行(只投影稳定字段 name/schema_version;created_at/updated_at 是本地库元数据,
|
|
448
|
+
// 同步无意义且破坏 round-trip 跨库等值——与 changes 排除 created_at 同理,B2)
|
|
449
|
+
const projectRow = sqlDb.prepare(
|
|
450
|
+
'SELECT name, schema_version FROM project WHERE id = 1'
|
|
451
|
+
).get();
|
|
452
|
+
|
|
453
|
+
// 3. stages(该 change 下,用 change_name+stage 表达外键)
|
|
454
|
+
const stageRows = sqlDb.prepare(
|
|
455
|
+
`SELECT id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason
|
|
456
|
+
FROM stages WHERE change_id = ? ORDER BY id`
|
|
457
|
+
).all(changeId);
|
|
458
|
+
const stageJson = stageRows.map(r => ({
|
|
459
|
+
change_name: changeRow.name,
|
|
460
|
+
stage: r.stage,
|
|
461
|
+
status: r.status,
|
|
462
|
+
started_at: r.started_at ?? null,
|
|
463
|
+
completed_at: r.completed_at ?? null,
|
|
464
|
+
revision: r.revision ?? null,
|
|
465
|
+
reopened_from_step: r.reopened_from_step ?? null,
|
|
466
|
+
reopened_at: r.reopened_at ?? null,
|
|
467
|
+
stale_reason: r.stale_reason ?? null,
|
|
468
|
+
}));
|
|
469
|
+
|
|
470
|
+
// 4. steps(stage_id IN;用 change_name+stage 关联回 stage)
|
|
471
|
+
const stageIds = stageRows.map(r => r.id);
|
|
472
|
+
const stageIdToName = new Map(stageRows.map(r => [r.id, r.stage]));
|
|
473
|
+
let stepJson = [];
|
|
474
|
+
if (stageIds.length > 0) {
|
|
475
|
+
const placeholders = stageIds.map(() => '?').join(',');
|
|
476
|
+
const stepRows = sqlDb.prepare(
|
|
477
|
+
`SELECT stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options,
|
|
478
|
+
wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds
|
|
479
|
+
FROM steps WHERE stage_id IN (${placeholders}) ORDER BY stage_id, ordering`
|
|
480
|
+
).all(...stageIds);
|
|
481
|
+
stepJson = stepRows.map(r => ({
|
|
482
|
+
change_name: changeRow.name,
|
|
483
|
+
stage: stageIdToName.get(r.stage_id),
|
|
484
|
+
name: r.name,
|
|
485
|
+
status: r.status,
|
|
486
|
+
output: r.output ?? null,
|
|
487
|
+
completed_at: r.completed_at ?? null,
|
|
488
|
+
ordering: r.ordering ?? null,
|
|
489
|
+
wait_reason: r.wait_reason ?? null,
|
|
490
|
+
wait_options: r.wait_options ?? null,
|
|
491
|
+
wait_answer: r.wait_answer ?? null,
|
|
492
|
+
waited_at: r.waited_at ?? null,
|
|
493
|
+
wait_answers: r.wait_answers ?? null,
|
|
494
|
+
wait_round: r.wait_round ?? null,
|
|
495
|
+
max_wait_rounds: r.max_wait_rounds ?? null,
|
|
496
|
+
}));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// 5. batch_progress(无行则空数组,import 侧幂等)
|
|
500
|
+
const batchRow = sqlDb.prepare(
|
|
501
|
+
'SELECT total, completed, failed, skipped FROM batch_progress WHERE change_id = ?'
|
|
502
|
+
).get(changeId);
|
|
503
|
+
const batchJson = batchRow !== undefined ? [{
|
|
504
|
+
change_name: changeRow.name,
|
|
505
|
+
total: batchRow.total,
|
|
506
|
+
completed: batchRow.completed,
|
|
507
|
+
failed: batchRow.failed,
|
|
508
|
+
skipped: batchRow.skipped,
|
|
509
|
+
}] : [];
|
|
510
|
+
|
|
511
|
+
// 6. approvals(read() 不读此表,serializeForSync 补齐;无行则空数组)
|
|
512
|
+
const approvalRow = sqlDb.prepare(
|
|
513
|
+
'SELECT status, requested_at, approved_by, approved_at, rejection_reason FROM approvals WHERE change_id = ?'
|
|
514
|
+
).get(changeId);
|
|
515
|
+
const approvalJson = approvalRow !== undefined ? [{
|
|
516
|
+
change_name: changeRow.name,
|
|
517
|
+
status: approvalRow.status,
|
|
518
|
+
requested_at: approvalRow.requested_at ?? null,
|
|
519
|
+
approved_by: approvalRow.approved_by ?? null,
|
|
520
|
+
approved_at: approvalRow.approved_at ?? null,
|
|
521
|
+
rejection_reason: approvalRow.rejection_reason ?? null,
|
|
522
|
+
}] : [];
|
|
523
|
+
|
|
524
|
+
return {
|
|
525
|
+
project: projectRow || null,
|
|
526
|
+
changes: [changeProj],
|
|
527
|
+
stages: stageJson,
|
|
528
|
+
steps: stepJson,
|
|
529
|
+
batch_progress: batchJson,
|
|
530
|
+
approvals: approvalJson,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* serializeForSync 的逆运算:把平台权威 JSON 原子写回本地 DB 的该 change 行(design §8/B1,task-03 / D-005@v2 / D-011 / FR-07)。
|
|
536
|
+
* ⚠️ 必须保护真实资产:import 前对 DB 做【独立】snapshot `.runtime/sillyspec.db.pre-import-<ts>.bak`,
|
|
537
|
+
* 不抢 _openWithFallback 的 `${dbPath}.bak`(gap5/R-08);任何失败本地进度库不损坏。
|
|
538
|
+
*
|
|
539
|
+
* 语义:
|
|
540
|
+
* - 单个 DB.transaction() 包裹,原子重建 stages/steps/batch_progress/approvals 四表(任一失败整体回滚)
|
|
541
|
+
* - changes 行用 UPDATE 选择投影列(current_stage/status/last_active/last_synced_platform_ts/last_local_modified_ts),
|
|
542
|
+
* 保留 isolation_* / platform_* / created_at(本地强相关状态不被覆盖,B2;change 不存在时 INSERT 兜底平台新增)
|
|
543
|
+
* - import 后 last_synced_platform_ts 与 last_local_modified_ts 均置为 progressObj.pushed_at(D-013 例外:
|
|
544
|
+
* 不更新 now()——否则 now()>base_ts 下次 pull 误判冲突;pushed_at 由 sync.js pull() 从响应 header attach)
|
|
545
|
+
* - 本地确定性操作,失败 throw 中文(非 sync 类 Best Effort,CONVENTIONS #4)
|
|
546
|
+
*
|
|
547
|
+
* @param {string} cwd
|
|
548
|
+
* @param {object} progressObj - serializeForSync 输出 + sync.js 附加的 pushed_at
|
|
549
|
+
* @param {string|null} [changeName] - 空则从 progressObj.changes[0].name 推导
|
|
550
|
+
* @returns {ImportResult} { ok:true, imported:changeName, reason?, bakPath }
|
|
551
|
+
*/
|
|
552
|
+
import(cwd, progressObj, changeName = null) {
|
|
553
|
+
if (!progressObj || typeof progressObj !== 'object') {
|
|
554
|
+
throw new Error('import 参数无效:progressObj 必须是 serializeForSync() 输出的六表 JSON 对象');
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const cn = changeName || (progressObj.changes && progressObj.changes[0] && progressObj.changes[0].name);
|
|
558
|
+
if (!cn) {
|
|
559
|
+
throw new Error('import 缺少 changeName:无法定位目标 change(progressObj.changes[0].name 为空)');
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// ⚠️ 必须保护真实资产:独立 .bak snapshot(前缀 pre-import- 区分于主 .bak 备份机制)
|
|
563
|
+
const dbPath = this._runtimePath(cwd, 'sillyspec.db');
|
|
564
|
+
if (!existsSync(dbPath)) {
|
|
565
|
+
throw new Error(`本地进度库不存在,无法 import:${dbPath}`);
|
|
566
|
+
}
|
|
567
|
+
const bakTs = new Date().toISOString().replace(/[:.]/g, '-');
|
|
568
|
+
const bakPath = this._runtimePath(cwd, `sillyspec.db.pre-import-${bakTs}.bak`);
|
|
569
|
+
// 体检 BUG-18:WAL 模式下最近已提交事务可能仍在 -wal 侧车,直接 copy 主库文件会拿到
|
|
570
|
+
// 缺尾部提交的快照(恢复时静默回退进度)。先尽力 checkpoint(TRUNCATE) 把 WAL 合并回主库;
|
|
571
|
+
// 他进程持连接致 checkpoint 不完全时,把 -wal 侧车一并备份,恢复侧才有完整提交
|
|
572
|
+
try {
|
|
573
|
+
this._ensureDB(cwd).getDb().exec('PRAGMA wal_checkpoint(TRUNCATE)');
|
|
574
|
+
} catch { /* best-effort:失败退化为连 -wal 一起备份 */ }
|
|
575
|
+
copyFileSync(dbPath, bakPath);
|
|
576
|
+
const walSidecar = `${dbPath}-wal`;
|
|
577
|
+
if (existsSync(walSidecar)) {
|
|
578
|
+
try { copyFileSync(walSidecar, `${bakPath}-wal`); } catch { /* 侧车消失=已 checkpoint,无碍 */ }
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const pushedAt = progressObj.pushed_at ?? null;
|
|
582
|
+
const now = new Date().toISOString();
|
|
583
|
+
|
|
584
|
+
try {
|
|
585
|
+
const db = this._ensureDB(cwd);
|
|
586
|
+
db.transaction(() => {
|
|
587
|
+
const sqlDb = db.getDb();
|
|
588
|
+
|
|
589
|
+
// 1. changes 行:INSERT OR IGNORE 兜底平台新增 change;UPDATE 只覆盖投影列(保留本地隔离/平台/created_at 列)
|
|
590
|
+
sqlDb.prepare(
|
|
591
|
+
`INSERT OR IGNORE INTO changes (name, current_stage, status, created_at, last_active)
|
|
592
|
+
VALUES (?, '', 'active', ?, ?)`
|
|
593
|
+
).run(cn, now, now);
|
|
594
|
+
const ch = progressObj.changes && progressObj.changes[0];
|
|
595
|
+
sqlDb.prepare(
|
|
596
|
+
`UPDATE changes SET
|
|
597
|
+
current_stage = ?, status = ?, last_active = ?,
|
|
598
|
+
last_synced_platform_ts = ?, last_local_modified_ts = ?
|
|
599
|
+
WHERE name = ?`
|
|
600
|
+
).run(
|
|
601
|
+
ch && ch.current_stage != null ? ch.current_stage : '',
|
|
602
|
+
ch && ch.status != null ? ch.status : 'active',
|
|
603
|
+
ch && ch.last_active != null ? ch.last_active : now,
|
|
604
|
+
pushedAt, pushedAt, cn
|
|
605
|
+
);
|
|
606
|
+
const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(cn);
|
|
607
|
+
const changeId = changeRow.id;
|
|
608
|
+
|
|
609
|
+
// 2. project 行:幂等确保存在(不覆盖已有全局行,round-trip 等值不受影响;仅补缺失)
|
|
610
|
+
const projExists = sqlDb.prepare('SELECT id FROM project WHERE id = 1').get();
|
|
611
|
+
if (projExists === undefined) {
|
|
612
|
+
const pj = progressObj.project || {};
|
|
613
|
+
sqlDb.prepare(
|
|
614
|
+
`INSERT INTO project (id, name, schema_version, created_at, updated_at)
|
|
615
|
+
VALUES (1, ?, ?, ?, ?)`
|
|
616
|
+
).run(pj.name != null ? pj.name : 'project', pj.schema_version != null ? pj.schema_version : CURRENT_VERSION, now, now);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// 3. 重建 stages + steps:DELETE stages(ON DELETE CASCADE 级联删 steps),按 JSON 重建
|
|
620
|
+
sqlDb.prepare('DELETE FROM stages WHERE change_id = ?').run(changeId);
|
|
621
|
+
const stageToId = new Map();
|
|
622
|
+
for (const s of (progressObj.stages || [])) {
|
|
623
|
+
if (!s || !s.stage) continue;
|
|
624
|
+
sqlDb.prepare(
|
|
625
|
+
`INSERT INTO stages (change_id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason)
|
|
626
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
627
|
+
).run(changeId, s.stage, s.status != null ? s.status : 'pending', s.started_at ?? null, s.completed_at ?? null,
|
|
628
|
+
s.revision != null ? s.revision : 0, s.reopened_from_step ?? null, s.reopened_at ?? null, s.stale_reason ?? null);
|
|
629
|
+
const row = sqlDb.prepare('SELECT id FROM stages WHERE change_id = ? AND stage = ?').get(changeId, s.stage);
|
|
630
|
+
stageToId.set(s.stage, row.id);
|
|
631
|
+
}
|
|
632
|
+
for (const st of (progressObj.steps || [])) {
|
|
633
|
+
if (!st || !st.name) continue;
|
|
634
|
+
const stageId = stageToId.get(st.stage);
|
|
635
|
+
if (stageId === undefined) continue; // 孤儿 step(stage 不在 JSON)跳过,不破坏完整性
|
|
636
|
+
sqlDb.prepare(
|
|
637
|
+
`INSERT INTO steps (stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options, wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds)
|
|
638
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
639
|
+
).run(stageId, st.name, st.status != null ? st.status : 'pending', st.output ?? null, st.completed_at ?? null,
|
|
640
|
+
st.ordering != null ? st.ordering : 0, st.wait_reason ?? null, st.wait_options ?? null, st.wait_answer ?? null,
|
|
641
|
+
st.waited_at ?? null, st.wait_answers ?? null, st.wait_round ?? null, st.max_wait_rounds ?? null);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// 4. 重建 batch_progress(DELETE 再插,无行则清空)
|
|
645
|
+
sqlDb.prepare('DELETE FROM batch_progress WHERE change_id = ?').run(changeId);
|
|
646
|
+
const bp = progressObj.batch_progress && progressObj.batch_progress[0];
|
|
647
|
+
if (bp) {
|
|
648
|
+
sqlDb.prepare(
|
|
649
|
+
`INSERT INTO batch_progress (change_id, total, completed, failed, skipped)
|
|
650
|
+
VALUES (?, ?, ?, ?, ?)`
|
|
651
|
+
).run(changeId, bp.total != null ? bp.total : 0, bp.completed != null ? bp.completed : 0,
|
|
652
|
+
bp.failed != null ? bp.failed : 0, bp.skipped != null ? bp.skipped : 0);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// 5. 重建 approvals(DELETE 再插,无行则清空)
|
|
656
|
+
sqlDb.prepare('DELETE FROM approvals WHERE change_id = ?').run(changeId);
|
|
657
|
+
const ap = progressObj.approvals && progressObj.approvals[0];
|
|
658
|
+
if (ap) {
|
|
659
|
+
sqlDb.prepare(
|
|
660
|
+
`INSERT INTO approvals (change_id, status, requested_at, approved_by, approved_at, rejection_reason)
|
|
661
|
+
VALUES (?, ?, ?, ?, ?, ?)`
|
|
662
|
+
).run(changeId, ap.status != null ? ap.status : 'not_required', ap.requested_at ?? null, ap.approved_by ?? null,
|
|
663
|
+
ap.approved_at ?? null, ap.rejection_reason ?? null);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
} catch (e) {
|
|
667
|
+
// 事务失败自动回滚(DB 未变),.bak 保留可恢复;fail-loud 中文
|
|
668
|
+
throw new Error(`import 失败,本地进度库已回滚(snapshot: ${bakPath}):${e.message}`);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return { ok: true, imported: cn, reason: undefined, bakPath };
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* 本地脏度标记(D-013 / task-04):写入路径末尾更新 changes.last_local_modified_ts。
|
|
676
|
+
* 在写方法的事务内调用则属于该事务(原子,失败整体回滚);import 是例外不调本方法
|
|
677
|
+
* (import 自己把 last_local_modified_ts 置为 pushed_at,表示本地=平台干净)。
|
|
678
|
+
* @param {string} cwd
|
|
679
|
+
* @param {string} changeName
|
|
680
|
+
* @param {string} [ts] - 复用调用方事务内的时间戳,保证与本次写入同时刻
|
|
681
|
+
*/
|
|
682
|
+
_touchLocalModified(cwd, changeName, ts = null) {
|
|
683
|
+
if (!changeName) return;
|
|
684
|
+
const db = this._ensureDB(cwd);
|
|
685
|
+
const stamp = ts || new Date().toISOString();
|
|
686
|
+
db.getDb().prepare('UPDATE changes SET last_local_modified_ts = ? WHERE name = ?').run(stamp, changeName);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* 写入指定变更的 progress
|
|
691
|
+
* @param {string} cwd
|
|
692
|
+
* @param {object} data
|
|
693
|
+
* @param {string|null} changeName - 从 data.currentChange 推导,或显式传入
|
|
694
|
+
*
|
|
695
|
+
* 持锁窗口评估(task-05 / R-08):本方法采用全量 UPSERT——无条件 UPDATE changes 行 +
|
|
696
|
+
* 遍历所有 stages(每 stage UPSERT stages 行 + 每 step 先 DELETE 再 INSERT 全量 + 末尾
|
|
697
|
+
* DELETE data 中不存在的多余 step)。评估过改"只写 diff(仅写变更过的 change/stage/step 行)"
|
|
698
|
+
* 以缩小事务持锁窗口、降低 BUSY 概率,结论:保持现状(全量 UPSERT)。
|
|
699
|
+
* 理由:
|
|
700
|
+
* 1. steps 表无 UNIQUE 约束(见循环内 DELETE-then-INSERT 注释),diff 写需先读现状再逐条
|
|
701
|
+
* 比较,复杂度高易错,易引入孤儿/缺失步骤破坏 FK 级联语义(design §3/§8);
|
|
702
|
+
* 2. busy_timeout=5000 + DB 层 SQLITE_BUSY 应用层有限重试(见 db.js transaction)已兜底
|
|
703
|
+
* 并发冲突,全量 UPSERT 的持锁窗口在此兜底下不是瓶颈;
|
|
704
|
+
* 3. 单进程内调用串行(design §9),事务窗口短(毫秒级),全量写正确性远高于 diff 的边际收益。
|
|
705
|
+
* 结论:全量 UPSERT 的简单正确性 > 持锁窗口优化的边际收益,不强行改 diff。
|
|
706
|
+
*/
|
|
707
|
+
_write(cwd, data, changeName = null) {
|
|
708
|
+
const cn = changeName || data.currentChange;
|
|
709
|
+
if (!cn) {
|
|
710
|
+
console.warn('⚠️ _write: 无变更名,跳过写入');
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const db = this._ensureDB(cwd);
|
|
715
|
+
db.transaction(() => {
|
|
716
|
+
const sqlDb = db.getDb();
|
|
717
|
+
// 1. 更新 changes 表(last_local_modified_ts 脏度:D-013 / task-04)
|
|
718
|
+
const now = new Date().toISOString();
|
|
719
|
+
const noWorktree = data.noWorktree ? 1 : 0;
|
|
720
|
+
sqlDb.prepare(
|
|
721
|
+
'UPDATE changes SET current_stage = ?, last_active = ?, no_worktree = ?, last_local_modified_ts = ? WHERE name = ?'
|
|
722
|
+
).run(data.currentStage || '', now, noWorktree, now, cn);
|
|
723
|
+
|
|
724
|
+
// 2. 获取 change_id
|
|
725
|
+
const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(cn);
|
|
726
|
+
if (changeRow === undefined) return;
|
|
727
|
+
const changeId = changeRow.id;
|
|
728
|
+
|
|
729
|
+
// 3. 遍历 stages,UPSERT stages 表和 steps 表
|
|
730
|
+
if (data.stages && typeof data.stages === 'object') {
|
|
731
|
+
for (const [stageName, stageData] of Object.entries(data.stages)) {
|
|
732
|
+
// UPSERT stages 行(含 revision 列)
|
|
733
|
+
sqlDb.prepare(
|
|
734
|
+
`INSERT INTO stages (change_id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason)
|
|
735
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
736
|
+
ON CONFLICT(change_id, stage) DO UPDATE SET
|
|
737
|
+
status = excluded.status,
|
|
738
|
+
started_at = excluded.started_at,
|
|
739
|
+
completed_at = excluded.completed_at,
|
|
740
|
+
revision = COALESCE(excluded.revision, stages.revision),
|
|
741
|
+
reopened_from_step = excluded.reopened_from_step,
|
|
742
|
+
reopened_at = excluded.reopened_at,
|
|
743
|
+
stale_reason = excluded.stale_reason`
|
|
744
|
+
).run(changeId, stageName, stageData.status || 'pending', stageData.startedAt || null, stageData.completedAt || null,
|
|
745
|
+
stageData.revision || 0, stageData.reopenedFromStep || null, stageData.reopenedAt || null, stageData.staleReason || null);
|
|
746
|
+
|
|
747
|
+
// 获取 stage_id
|
|
748
|
+
const stageRow = sqlDb.prepare('SELECT id FROM stages WHERE change_id = ? AND stage = ?').get(changeId, stageName);
|
|
749
|
+
if (stageRow === undefined) continue;
|
|
750
|
+
const stageId = stageRow.id;
|
|
751
|
+
|
|
752
|
+
// 收集 data 中的步骤名
|
|
753
|
+
const stepNames = new Set();
|
|
754
|
+
if (Array.isArray(stageData.steps)) {
|
|
755
|
+
for (let i = 0; i < stageData.steps.length; i++) {
|
|
756
|
+
const step = stageData.steps[i];
|
|
757
|
+
stepNames.add(step.name);
|
|
758
|
+
// UPSERT 步骤(先删再插,steps 表无 UNIQUE 约束)
|
|
759
|
+
sqlDb.prepare('DELETE FROM steps WHERE stage_id = ? AND name = ?').run(stageId, step.name);
|
|
760
|
+
sqlDb.prepare(
|
|
761
|
+
'INSERT INTO steps (stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options, wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
|
762
|
+
).run(stageId, step.name, step.status || 'pending', step.output || null, step.completedAt || null, i,
|
|
763
|
+
step.waitReason ?? null, Array.isArray(step.waitOptions) ? JSON.stringify(step.waitOptions) : (step.waitOptions ?? null), step.waitAnswer ?? null, step.waitedAt ?? null,
|
|
764
|
+
Array.isArray(step.waitAnswers) ? JSON.stringify(step.waitAnswers) : null,
|
|
765
|
+
step.waitRound ?? null, step.maxWaitRounds ?? null);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// 删除 data 中不存在的多余步骤
|
|
770
|
+
if (stepNames.size > 0) {
|
|
771
|
+
const namePlaceholders = [...stepNames].map(() => '?').join(',');
|
|
772
|
+
sqlDb.prepare(
|
|
773
|
+
`DELETE FROM steps WHERE stage_id = ? AND name NOT IN (${namePlaceholders})`
|
|
774
|
+
).run(stageId, ...stepNames);
|
|
775
|
+
} else {
|
|
776
|
+
// data 中没有步骤,清空该阶段所有步骤
|
|
777
|
+
sqlDb.prepare('DELETE FROM steps WHERE stage_id = ?').run(stageId);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// 4. UPSERT batch_progress
|
|
783
|
+
if (data.batchProgress && typeof data.batchProgress === 'object') {
|
|
784
|
+
sqlDb.prepare(
|
|
785
|
+
`INSERT INTO batch_progress (change_id, total, completed, failed, skipped)
|
|
786
|
+
VALUES (?, ?, ?, ?, ?)
|
|
787
|
+
ON CONFLICT(change_id) DO UPDATE SET
|
|
788
|
+
total = excluded.total,
|
|
789
|
+
completed = excluded.completed,
|
|
790
|
+
failed = excluded.failed,
|
|
791
|
+
skipped = excluded.skipped`
|
|
792
|
+
).run(changeId, data.batchProgress.total || 0, data.batchProgress.completed || 0, data.batchProgress.failed || 0, data.batchProgress.skipped || 0);
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// ── 变更管理 ──
|
|
798
|
+
|
|
799
|
+
listChanges(cwd) { return this._changeRegistry.listChanges(cwd); }
|
|
800
|
+
|
|
801
|
+
// 单变更阶段查询(quick 轻量归档阶段闸):无行 null,读失败抛(调用方 fail-closed)
|
|
802
|
+
getChangeStage(cwd, changeName) { return this._changeRegistry.getChangeStage(cwd, changeName); }
|
|
803
|
+
|
|
804
|
+
registerChange(cwd, changeName) { return this._changeRegistry.registerChange(cwd, changeName); }
|
|
805
|
+
|
|
806
|
+
updateChangeIsolation(cwd, changeName, isolation) { return this._changeRegistry.updateChangeIsolation(cwd, changeName, isolation); }
|
|
807
|
+
|
|
808
|
+
readChangeIsolation(cwd, changeName) { return this._changeRegistry.readChangeIsolation(cwd, changeName); }
|
|
809
|
+
|
|
810
|
+
// syncedTs 透传(ql-20260818-008):push 成功推进 base_ts,facade 曾丢参致列永不写入
|
|
811
|
+
_updatePlatformLastSync(cwd, changeName, syncedTs = null) { return this._changeRegistry._updatePlatformLastSync(cwd, changeName, syncedTs); }
|
|
812
|
+
|
|
813
|
+
_updateApprovalStatus(cwd, changeName, status, reason = null) { return this._changeRegistry._updateApprovalStatus(cwd, changeName, status, reason); }
|
|
814
|
+
|
|
815
|
+
renameChange(cwd, oldName, newName) { return this._changeRegistry.renameChange(cwd, oldName, newName); }
|
|
816
|
+
|
|
817
|
+
// opts.archiveStepNames 给定时做归档终态一致化收尾(见 change-registry.unregisterChange 注释,
|
|
818
|
+
// 坑 manual-archive-desync-status-only);archiveStepNamesForArchive() 取 stageRegistry 单一真相
|
|
819
|
+
//(stages/* 不反向依赖 progress.js,静态 import 无环)。
|
|
820
|
+
unregisterChange(cwd, changeName, opts) { return this._changeRegistry.unregisterChange(cwd, changeName, opts); }
|
|
821
|
+
|
|
822
|
+
archiveStepNamesForArchive() {
|
|
823
|
+
if (!this._archiveStepNamesCache) {
|
|
824
|
+
const defs = stageRegistry?.archive?.steps
|
|
825
|
+
this._archiveStepNamesCache = Array.isArray(defs) ? defs.map(s => s.name) : []
|
|
826
|
+
}
|
|
827
|
+
return this._archiveStepNamesCache
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
updateChangeMeta(cwd, changeName, meta) { return this._changeRegistry.updateChangeMeta(cwd, changeName, meta); }
|
|
831
|
+
|
|
832
|
+
// ── CLI 命令 ──
|
|
833
|
+
|
|
834
|
+
init(cwd) {
|
|
835
|
+
this._ensureRuntimeDir(cwd);
|
|
836
|
+
|
|
837
|
+
// 初始化 DB(如不存在则创建文件 + 建表)
|
|
838
|
+
const db = this._ensureDB(cwd);
|
|
839
|
+
db.transaction(() => {
|
|
840
|
+
const sqlDb = db.getDb();
|
|
841
|
+
const now = new Date().toISOString();
|
|
842
|
+
const projectName = basename(cwd) || 'project';
|
|
843
|
+
|
|
844
|
+
// 检查 project id=1 是否已存在
|
|
845
|
+
const existing = sqlDb.prepare('SELECT id FROM project WHERE id = 1').get();
|
|
846
|
+
if (existing === undefined) {
|
|
847
|
+
sqlDb.prepare(
|
|
848
|
+
`INSERT INTO project (id, name, schema_version, created_at, updated_at)
|
|
849
|
+
VALUES (1, ?, ?, ?, ?)`
|
|
850
|
+
).run(projectName, CURRENT_VERSION, now, now);
|
|
851
|
+
console.log(`✅ 已创建全局状态文件(SQLite)`);
|
|
852
|
+
} else {
|
|
853
|
+
console.log(`ℹ️ 全局状态文件已存在,跳过`);
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
// 创建 user-inputs.md
|
|
858
|
+
const inputsPath = this._runtimePath(cwd, 'user-inputs.md');
|
|
859
|
+
if (!existsSync(inputsPath)) {
|
|
860
|
+
writeFileSync(inputsPath, '# 用户输入记录\n\n> 每步完成时由 AI 自动追加,记录用户所有原话。\n\n');
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
this._ensureGitignore(cwd);
|
|
864
|
+
return this.readGlobal(cwd);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* 初始化指定变更的 progress
|
|
869
|
+
* SQL: INSERT changes + 批量 INSERT stages
|
|
870
|
+
*/
|
|
871
|
+
initChange(cwd, changeName, meta = {}) {
|
|
872
|
+
if (!changeName) {
|
|
873
|
+
console.warn('⚠️ initChange: changeName 为空,跳过');
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
// quick 会话 id(quick-<uuid8>,见 run.js QUICK_SID_RE)只作 progress 的跨进程 session key,
|
|
877
|
+
// 进度存 SQL 不需要实体 change 目录——跳过避免 changes/quick-<uuid>/ 空目录残留。
|
|
878
|
+
if (!/^quick-[0-9a-f]{8}$/.test(changeName)) {
|
|
879
|
+
this._ensureChangeDir(cwd, changeName);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
const db = this._ensureDB(cwd);
|
|
883
|
+
db.transaction(() => {
|
|
884
|
+
const sqlDb = db.getDb();
|
|
885
|
+
const now = new Date().toISOString();
|
|
886
|
+
|
|
887
|
+
// 检查变更是否已存在
|
|
888
|
+
const existing = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(changeName);
|
|
889
|
+
if (existing === undefined) {
|
|
890
|
+
// 插入 changes 行
|
|
891
|
+
sqlDb.prepare(
|
|
892
|
+
`INSERT INTO changes (name, current_stage, status, created_at, last_active, title, quicklog_id)
|
|
893
|
+
VALUES (?, 'scan', 'active', ?, ?, ?, ?)`
|
|
894
|
+
).run(changeName, now, now, meta.title || null, meta.quicklogId || null);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// 获取 change_id
|
|
898
|
+
const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(changeName);
|
|
899
|
+
const changeId = changeRow.id;
|
|
900
|
+
|
|
901
|
+
// 批量插入所有合法阶段(INSERT OR IGNORE 跳过已存在的);沿用顶部 import 的 VALID_STAGES 单一源
|
|
902
|
+
for (const stage of VALID_STAGES) {
|
|
903
|
+
sqlDb.prepare(
|
|
904
|
+
`INSERT OR IGNORE INTO stages (change_id, stage, status)
|
|
905
|
+
VALUES (?, ?, 'pending')`
|
|
906
|
+
).run(changeId, stage);
|
|
907
|
+
}
|
|
908
|
+
// 本地脏度(D-013 / task-04):新建 change 视为有未同步数据
|
|
909
|
+
this._touchLocalModified(cwd, changeName, now);
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
// 不再需要写文件:read() 已改为 SQL
|
|
913
|
+
return this.read(cwd, changeName);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
setStage(cwd, stage, changeName = null) { return this._stepStore.setStage(cwd, stage, changeName); }
|
|
917
|
+
|
|
918
|
+
addStep(cwd, stage, stepName, changeName = null) { return this._stepStore.addStep(cwd, stage, stepName, changeName); }
|
|
919
|
+
|
|
920
|
+
updateStep(cwd, stage, stepName, options = {}, changeName = null) { return this._stepStore.updateStep(cwd, stage, stepName, options, changeName); }
|
|
921
|
+
|
|
922
|
+
_appendAuditLog(cwd, entry) { return this._consistency._appendAuditLog(cwd, entry); }
|
|
923
|
+
|
|
924
|
+
_validateStageArtifacts(cwd, stage, changeName) { return this._stageMachine._validateStageArtifacts(cwd, stage, changeName); }
|
|
925
|
+
|
|
926
|
+
completeStage(cwd, stage, changeName = null, opts = {}) { return this._stageMachine.completeStage(cwd, stage, changeName, opts); }
|
|
927
|
+
|
|
928
|
+
show(cwd, changeName = null) { return this._stageMachine.show(cwd, changeName); }
|
|
929
|
+
|
|
930
|
+
_showChange(cwd, changeName) { return this._stageMachine._showChange(cwd, changeName); }
|
|
931
|
+
|
|
932
|
+
_getNextSuggestion(data) { return this._stageMachine._getNextSuggestion(data); }
|
|
933
|
+
|
|
934
|
+
status(cwd, changeName = null) { return this._stageMachine.status(cwd, changeName); }
|
|
935
|
+
|
|
936
|
+
checkConsistency(cwd, changeName = null) { return this._consistency.checkConsistency(cwd, changeName); }
|
|
937
|
+
|
|
938
|
+
repairConsistency(cwd, opts = {}) { return this._consistency.repairConsistency(cwd, opts); }
|
|
939
|
+
|
|
940
|
+
validate(cwd, changeName = null) { return this._stageMachine.validate(cwd, changeName); }
|
|
941
|
+
|
|
942
|
+
reopenStage(cwd, stage, opts = {}) { return this._stageMachine.reopenStage(cwd, stage, opts); }
|
|
943
|
+
|
|
944
|
+
_getDownstreamStages(stage) { return this._stageMachine._getDownstreamStages(stage); }
|
|
945
|
+
|
|
946
|
+
reset(cwd, stage, changeName = null) { return this._stageMachine.reset(cwd, stage, changeName); }
|
|
947
|
+
|
|
948
|
+
// ── 内部辅助 ──
|
|
949
|
+
|
|
950
|
+
_readOrInit(cwd, changeName = null) {
|
|
951
|
+
let data = this.read(cwd, changeName);
|
|
952
|
+
if (!data) {
|
|
953
|
+
// 尝试自动检测变更名
|
|
954
|
+
if (!changeName) {
|
|
955
|
+
const changes = this.listChanges(cwd);
|
|
956
|
+
if (changes.length === 1) changeName = changes[0];
|
|
957
|
+
}
|
|
958
|
+
if (changeName) {
|
|
959
|
+
// 确保变更在 DB 中已初始化
|
|
960
|
+
const db = this._ensureDB(cwd);
|
|
961
|
+
db.transaction(() => {
|
|
962
|
+
const sqlDb = db.getDb();
|
|
963
|
+
const now = new Date().toISOString();
|
|
964
|
+
const ins = sqlDb.prepare(
|
|
965
|
+
`INSERT OR IGNORE INTO changes (name, current_stage, status, created_at, last_active) VALUES (?, 'scan', 'active', ?, ?)`
|
|
966
|
+
).run(changeName, now, now);
|
|
967
|
+
const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(changeName);
|
|
968
|
+
if (changeRow !== undefined) {
|
|
969
|
+
const changeId = changeRow.id;
|
|
970
|
+
for (const s of VALID_STAGES) {
|
|
971
|
+
sqlDb.prepare(`INSERT OR IGNORE INTO stages (change_id, stage, status) VALUES (?, ?, 'pending')`).run(changeId, s);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
// 只在真正创建 change 时标脏(D-013/task-04);读路径(change 已存在)不标,避免 pull 误判本地有未同步改动
|
|
975
|
+
if (ins.changes > 0) this._touchLocalModified(cwd, changeName, now);
|
|
976
|
+
});
|
|
977
|
+
this.registerChange(cwd, changeName);
|
|
978
|
+
}
|
|
979
|
+
if (!data) {
|
|
980
|
+
data = this.read(cwd, changeName);
|
|
981
|
+
}
|
|
982
|
+
if (!data) {
|
|
983
|
+
console.log('❌ 无法确定当前变更,请指定 --change <name>');
|
|
984
|
+
return null;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
return data;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
_requireStage(cwd, stage, changeName = null) {
|
|
991
|
+
if (!VALID_STAGES.includes(stage)) {
|
|
992
|
+
console.log(`❌ 未知阶段: ${stage},可选: ${VALID_STAGES.join(', ')}`);
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
const data = this._readOrInit(cwd, changeName);
|
|
996
|
+
if (!data) return null;
|
|
997
|
+
if (!data.stages[stage]) data.stages[stage] = emptyStage();
|
|
998
|
+
return data;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
_timeAgo(dateStr) { return this._stageMachine._timeAgo(dateStr); }
|
|
1002
|
+
|
|
1003
|
+
// ── 批量进度 ──
|
|
1004
|
+
|
|
1005
|
+
updateBatchProgress(cwd, batchData, changeName = null) { return this._stepStore.updateBatchProgress(cwd, batchData, changeName); }
|
|
1006
|
+
|
|
1007
|
+
readBatchProgress(cwd, changeName = null) { return this._stepStore.readBatchProgress(cwd, changeName); }
|
|
1008
|
+
|
|
1009
|
+
_renderBatchProgress(batchProgress) { return this._stepStore._renderBatchProgress(batchProgress); }
|
|
1010
|
+
|
|
1011
|
+
_ensureGitignore(cwd) {
|
|
1012
|
+
// 外部 specDir 不需要修改项目 .gitignore
|
|
1013
|
+
if (this._customSpecDir) return;
|
|
1014
|
+
const gitignorePath = join(cwd, '.gitignore');
|
|
1015
|
+
const rule = '.sillyspec/.runtime/';
|
|
1016
|
+
if (existsSync(gitignorePath)) {
|
|
1017
|
+
const content = readFileSync(gitignorePath, 'utf8');
|
|
1018
|
+
if (content.includes(rule)) return;
|
|
1019
|
+
// 按既有 EOL 追加(2026-08-21 审查 BUG-9):CRLF 检出的文件混入 LF 行产生全文件
|
|
1020
|
+
// diff 噪声/autocrlf 折腾;写走原子 rename 防并发 init 双跑交错
|
|
1021
|
+
const eol = content.includes('\r\n') ? '\r\n' : '\n';
|
|
1022
|
+
writeAtomicSync(gitignorePath, content.trimEnd() + eol + rule + eol);
|
|
1023
|
+
} else {
|
|
1024
|
+
writeAtomicSync(gitignorePath, rule + '\n');
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// ── plan.md 对齐(doctor --align-execute-progress 入口)──
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* 解析 changeDir/tasks.md(任务注册表唯一真相)的 task checkbox 统计。
|
|
1032
|
+
* 2026-08-20-task-truth-unify:源从「plan.md 优先回退 tasks.md」改为 tasks.md 唯一源——
|
|
1033
|
+
* 旧顺序下新契约 plan.md(纯 ID 引用行)恒 total=0,doctor --align-execute-progress 会静默失效。
|
|
1034
|
+
* tasks.md 缺失时回退 plan.md(旧归档变更兼容读侧,不写侧迁移)。
|
|
1035
|
+
* 仅匹配 `- [ ] task-NN` / `- [x] task-NN` 形态的行(task- 前缀锚定,避免误捞非任务项)。
|
|
1036
|
+
* @param {string} changeDir - 变更目录绝对路径(含 tasks.md/plan.md)
|
|
1037
|
+
* @returns {{ total: number, checked: number }}
|
|
1038
|
+
*/
|
|
1039
|
+
readPlanCheckboxStatus(changeDir) {
|
|
1040
|
+
if (!changeDir || typeof changeDir !== 'string') {
|
|
1041
|
+
throw new Error('changeDir 不能为空');
|
|
1042
|
+
}
|
|
1043
|
+
const tasksPath = join(changeDir, 'tasks.md');
|
|
1044
|
+
const planPath = join(changeDir, 'plan.md');
|
|
1045
|
+
let content = null;
|
|
1046
|
+
if (existsSync(tasksPath)) {
|
|
1047
|
+
content = readFileSync(tasksPath, 'utf8');
|
|
1048
|
+
} else if (existsSync(planPath)) {
|
|
1049
|
+
content = readFileSync(planPath, 'utf8');
|
|
1050
|
+
} else {
|
|
1051
|
+
return { total: 0, checked: 0 };
|
|
1052
|
+
}
|
|
1053
|
+
// 匹配 `- [ ] task-NN` / `- [x] task-NN`(允许 [x] 大小写、空格弹性、task- 前缀)
|
|
1054
|
+
const re = /^\s*[-*]\s+\[([ xX])\]\s+task-\d+/gm;
|
|
1055
|
+
let total = 0;
|
|
1056
|
+
let checked = 0;
|
|
1057
|
+
let m;
|
|
1058
|
+
while ((m = re.exec(content)) !== null) {
|
|
1059
|
+
total++;
|
|
1060
|
+
if (m[1] === 'x' || m[1] === 'X') checked++;
|
|
1061
|
+
}
|
|
1062
|
+
return { total, checked };
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* 按 plan.md 声明对齐 execute 阶段派生进度戳。
|
|
1067
|
+
* 仅当 plan.md 所有 task checkbox 全勾时,把 execute 阶段所有非 completed step 标 completed,
|
|
1068
|
+
* 并显式置 execute stageData.status='completed' + completedAt(绕过 completeStep 推导,D-003@v2)。
|
|
1069
|
+
* 不复核代码,信任 plan.md 声明(与 archive 同源,verify 阶段兜底,D-002/D-004)。
|
|
1070
|
+
*
|
|
1071
|
+
* @param {string} cwd
|
|
1072
|
+
* @param {string} changeName
|
|
1073
|
+
* @param {string} specBase - platformOpts.specRoot || join(cwd, '.sillyspec'),用于定位 changes 目录
|
|
1074
|
+
* @param {object} [opts]
|
|
1075
|
+
* @param {boolean} [opts.confirm=false] - 默认 dry-run,仅当 confirm=true 才落盘
|
|
1076
|
+
* @returns {{ ok: boolean, aligned: number, skipped: number, planTotal: number, planChecked: number, reason?: string, dryRun?: boolean }}
|
|
1077
|
+
*/
|
|
1078
|
+
alignExecuteToPlan(cwd, changeName, specBase, opts = {}) {
|
|
1079
|
+
if (!changeName) throw new Error('changeName 不能为空');
|
|
1080
|
+
const { confirm = false } = opts;
|
|
1081
|
+
|
|
1082
|
+
// 1. 读 progress;无 progress / 无 execute 阶段 → 拒绝
|
|
1083
|
+
const progress = this.read(cwd, changeName);
|
|
1084
|
+
if (!progress || !progress.stages || !progress.stages.execute) {
|
|
1085
|
+
return { ok: false, aligned: 0, skipped: 0, planTotal: 0, planChecked: 0, reason: 'execute 阶段无进度数据' };
|
|
1086
|
+
}
|
|
1087
|
+
const executeStage = progress.stages.execute;
|
|
1088
|
+
const steps = Array.isArray(executeStage.steps) ? executeStage.steps : [];
|
|
1089
|
+
if (steps.length === 0) {
|
|
1090
|
+
return { ok: false, aligned: 0, skipped: 0, planTotal: 0, planChecked: 0, reason: 'execute 阶段无进度数据' };
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// 2. 读 plan.md checkbox;未全勾 → 拒绝(D-002)
|
|
1094
|
+
const specRoot = specBase || this._getSpecDir(cwd);
|
|
1095
|
+
const changeDir = join(specRoot, CHANGES_SUBDIR, changeName);
|
|
1096
|
+
const { total: planTotal, checked: planChecked } = this.readPlanCheckboxStatus(changeDir);
|
|
1097
|
+
if (planTotal === 0) {
|
|
1098
|
+
return { ok: false, aligned: 0, skipped: 0, planTotal, planChecked, reason: 'plan.md 无 task checkbox(无法判定完成度)' };
|
|
1099
|
+
}
|
|
1100
|
+
if (planChecked < planTotal) {
|
|
1101
|
+
return {
|
|
1102
|
+
ok: false,
|
|
1103
|
+
aligned: 0,
|
|
1104
|
+
skipped: 0,
|
|
1105
|
+
planTotal,
|
|
1106
|
+
planChecked,
|
|
1107
|
+
reason: `plan.md 有未勾选 task(${planChecked}/${planTotal}),拒绝对齐`,
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// 2.5 最低事实核验:plan.md checkbox 可被手动勾选伪造,
|
|
1112
|
+
// 对齐前用 git 客观核验是否存在真实代码变更(能确证零变更时才拒绝,
|
|
1113
|
+
// unknown 不阻断——worktree 已清理且变更已提交的正常场景无法对账)。
|
|
1114
|
+
try {
|
|
1115
|
+
const evidence = checkExecuteCodeEvidence(cwd, changeName);
|
|
1116
|
+
if (evidence.status === 'unchanged') {
|
|
1117
|
+
return {
|
|
1118
|
+
ok: false,
|
|
1119
|
+
aligned: 0,
|
|
1120
|
+
skipped: 0,
|
|
1121
|
+
planTotal,
|
|
1122
|
+
planChecked,
|
|
1123
|
+
reason: `plan.md 全勾但代码零变更(${evidence.detail}),拒绝对齐 — 请先运行 sillyspec doctor --json 诊断`,
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
} catch (e) {
|
|
1127
|
+
console.warn(`⚠️ 代码变更核验异常(不阻断对齐): ${e.message}`);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// 3. 全勾:计算将补哪些 step
|
|
1131
|
+
const now = new Date().toISOString();
|
|
1132
|
+
let aligned = 0;
|
|
1133
|
+
let skipped = 0;
|
|
1134
|
+
for (const step of steps) {
|
|
1135
|
+
if (step.status === 'completed') {
|
|
1136
|
+
skipped++;
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
aligned++;
|
|
1140
|
+
if (confirm) {
|
|
1141
|
+
step.status = 'completed';
|
|
1142
|
+
step.completedAt = now;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
// dry-run:只报告,不落盘
|
|
1147
|
+
if (!confirm) {
|
|
1148
|
+
return { ok: true, aligned, skipped, planTotal, planChecked, dryRun: true };
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// 4. confirm:显式置 execute stageData.status='completed' + completedAt(D-003@v2,复刻 run.js:2303-2304)
|
|
1152
|
+
executeStage.status = 'completed';
|
|
1153
|
+
executeStage.completedAt = now;
|
|
1154
|
+
progress.currentStage = progress.currentStage || 'execute';
|
|
1155
|
+
progress.lastActive = now;
|
|
1156
|
+
this._write(cwd, progress, changeName);
|
|
1157
|
+
|
|
1158
|
+
return { ok: true, aligned, skipped, planTotal, planChecked };
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// ── 只读 dump(task-01/02/03:daemon 进度读取)──
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* dump 输出的时间戳规范化:DB 内部两类形态(步骤推进时 JS Date 变量序列化
|
|
1165
|
+
* 的 ISO 形态、部分历史路径写入的 `YYYY/M/D H:mm:ss` 斜杠形态)统一转 ISO。
|
|
1166
|
+
* backend pydantic datetime 只吃 ISO(斜杠形态校验失败),斜杠 → new Date
|
|
1167
|
+
* 可解析;解析失败原样返回(backend 侧按无效丢弃)。
|
|
1168
|
+
*/
|
|
1169
|
+
_dumpIso(ts) {
|
|
1170
|
+
if (!ts) return ts;
|
|
1171
|
+
if (typeof ts === 'string' && /^\d{4}-\d{2}-\d{2}/.test(ts)) return ts;
|
|
1172
|
+
const d = new Date(ts);
|
|
1173
|
+
if (Number.isNaN(d.getTime())) return ts;
|
|
1174
|
+
return d.toISOString();
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* 只读导出进度数据,供 daemon 通过 `sillyspec progress dump --json` 消费。
|
|
1179
|
+
*
|
|
1180
|
+
* 纯读路径:打开 DB 只读、读 user-inputs.md、列 artifacts 目录,不写任何状态。
|
|
1181
|
+
* 无活跃变更或 DB 不存在时返回 null(不抛异常,daemon 按 null 处理空数据)。
|
|
1182
|
+
*
|
|
1183
|
+
* 输出字段 snake_case + ISO 时间戳(2026-08-19-runtime-live-daemon-read
|
|
1184
|
+
* acceptance review P0 修复):契约消费端 backend RuntimeProgress pydantic
|
|
1185
|
+
* 是 snake_case(current_stage/last_active/started_at/size_bytes),
|
|
1186
|
+
* dump 早期误用内部 camelCase;跨端字段名断裂会让 pydantic 静默忽略
|
|
1187
|
+
* 未知字段导致前端核心字段全空。
|
|
1188
|
+
*
|
|
1189
|
+
* @param {string} cwd - specDir(`.sillyspec` 目录),由 CLI 层 --spec-dir 传入
|
|
1190
|
+
* @returns {object|null} 结构化进度数据,格式见 design.md §6.2
|
|
1191
|
+
*/
|
|
1192
|
+
dump(cwd) {
|
|
1193
|
+
const specRoot = this._getSpecDir(cwd);
|
|
1194
|
+
const dbPath = this._runtimePath(cwd, 'sillyspec.db');
|
|
1195
|
+
|
|
1196
|
+
// DB 不存在 → 返回 null(项目未初始化进度)
|
|
1197
|
+
if (!existsSync(dbPath)) return null;
|
|
1198
|
+
|
|
1199
|
+
const db = this._ensureDB(cwd);
|
|
1200
|
+
const sqlDb = db.getDb();
|
|
1201
|
+
|
|
1202
|
+
// 1. project 行
|
|
1203
|
+
const projectRow = sqlDb.prepare('SELECT name FROM project WHERE id = 1').get();
|
|
1204
|
+
if (projectRow === undefined) return null;
|
|
1205
|
+
const projectName = projectRow.name;
|
|
1206
|
+
|
|
1207
|
+
// 2. 活跃变更(取 last_active 最新的一个)
|
|
1208
|
+
// ql-20260821-003:多活跃仓(变更隔离是常态,单仓可同时存在 N 个 active)下
|
|
1209
|
+
// 原 ORDER BY name 恒取字典序最前(通常是最老的变更),「当前变更/最后活动」
|
|
1210
|
+
// 停留在历史数据。dump 语义是「当前工作流状态」→ 取最近活跃的那个。
|
|
1211
|
+
const changeRows = sqlDb.prepare("SELECT id, name, current_stage, last_active FROM changes WHERE status = 'active' ORDER BY last_active DESC").all();
|
|
1212
|
+
if (changeRows.length === 0) {
|
|
1213
|
+
// 无活跃变更 → 返回仅含 project 的骨架
|
|
1214
|
+
return {
|
|
1215
|
+
project: projectName,
|
|
1216
|
+
current_stage: null,
|
|
1217
|
+
current_change: null,
|
|
1218
|
+
last_active: null,
|
|
1219
|
+
stages: {},
|
|
1220
|
+
user_inputs: this._readUserInputs(cwd),
|
|
1221
|
+
artifacts: this._listArtifacts(cwd),
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
const change = changeRows[0];
|
|
1226
|
+
const { id: changeId, name: changeName, current_stage: currentStage, last_active: lastActive } = change;
|
|
1227
|
+
|
|
1228
|
+
// 3. stages
|
|
1229
|
+
const stageRows = sqlDb.prepare(
|
|
1230
|
+
'SELECT id, stage, status, started_at, completed_at, revision FROM stages WHERE change_id = ? ORDER BY id'
|
|
1231
|
+
).all(changeId);
|
|
1232
|
+
|
|
1233
|
+
const stages = {};
|
|
1234
|
+
for (const s of VALID_STAGES) {
|
|
1235
|
+
stages[s] = { status: 'pending', steps: [] };
|
|
1236
|
+
}
|
|
1237
|
+
// PERF-06:一次 IN (...) 批量取全部 steps 再按 stage_id 分组(原逐 stage 查询是 N+1,
|
|
1238
|
+
// dump 是 daemon 轮询接口;与 read() :283-287 的批量读法对齐)
|
|
1239
|
+
const stepsByStage = new Map();
|
|
1240
|
+
if (stageRows.length > 0) {
|
|
1241
|
+
const placeholders = stageRows.map(() => '?').join(', ');
|
|
1242
|
+
const allStepRows = sqlDb.prepare(
|
|
1243
|
+
`SELECT stage_id, name, status, output, completed_at FROM steps WHERE stage_id IN (${placeholders}) ORDER BY stage_id, ordering`
|
|
1244
|
+
).all(...stageRows.map(r => r.id));
|
|
1245
|
+
for (const sr of allStepRows) {
|
|
1246
|
+
if (!stepsByStage.has(sr.stage_id)) stepsByStage.set(sr.stage_id, []);
|
|
1247
|
+
stepsByStage.get(sr.stage_id).push(sr);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
for (const row of stageRows) {
|
|
1251
|
+
const stepRows = stepsByStage.get(row.id) || [];
|
|
1252
|
+
stages[row.stage] = {
|
|
1253
|
+
status: row.status,
|
|
1254
|
+
started_at: this._dumpIso(row.started_at) || undefined,
|
|
1255
|
+
completed_at: this._dumpIso(row.completed_at) || undefined,
|
|
1256
|
+
...(row.revision ? { revision: row.revision } : {}),
|
|
1257
|
+
steps: stepRows.map(sr => ({
|
|
1258
|
+
name: sr.name,
|
|
1259
|
+
status: sr.status,
|
|
1260
|
+
...(sr.output ? { output: sr.output } : {}),
|
|
1261
|
+
...(sr.completed_at ? { completed_at: this._dumpIso(sr.completed_at) } : {}),
|
|
1262
|
+
})),
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
return {
|
|
1267
|
+
project: projectName,
|
|
1268
|
+
current_stage: currentStage || null,
|
|
1269
|
+
current_change: changeName,
|
|
1270
|
+
last_active: this._dumpIso(lastActive) || null,
|
|
1271
|
+
stages,
|
|
1272
|
+
user_inputs: this._readUserInputs(cwd),
|
|
1273
|
+
artifacts: this._listArtifacts(cwd),
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/** 只读 user-inputs.md 内容(不存在返回 null) */
|
|
1278
|
+
_readUserInputs(cwd) {
|
|
1279
|
+
const p = this._runtimePath(cwd, 'user-inputs.md');
|
|
1280
|
+
if (!existsSync(p)) return null;
|
|
1281
|
+
return readFileSync(p, 'utf8');
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/** 列 artifacts 目录(不存在返回空数组) */
|
|
1285
|
+
_listArtifacts(cwd) {
|
|
1286
|
+
const dir = this._runtimePath(cwd, 'artifacts');
|
|
1287
|
+
if (!existsSync(dir)) return [];
|
|
1288
|
+
try {
|
|
1289
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
1290
|
+
.filter(e => e.isFile())
|
|
1291
|
+
.map(e => {
|
|
1292
|
+
const fullPath = join(dir, e.name);
|
|
1293
|
+
const st = statSync(fullPath);
|
|
1294
|
+
return {
|
|
1295
|
+
filename: e.name,
|
|
1296
|
+
size_bytes: st.size,
|
|
1297
|
+
last_modified: st.mtime.toISOString(),
|
|
1298
|
+
};
|
|
1299
|
+
});
|
|
1300
|
+
} catch {
|
|
1301
|
+
return [];
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|