@opengsd/gsd-core 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -3
- package/.opencode/plugins/gsd-core.js +8 -1
- package/agents/gsd-code-fixer.md +131 -34
- package/agents/gsd-debugger.md +12 -246
- package/agents/gsd-executor.md +7 -5
- package/agents/gsd-integration-checker.md +3 -0
- package/agents/gsd-plan-checker.md +9 -0
- package/agents/gsd-planner.md +5 -8
- package/agents/gsd-roadmapper.md +21 -3
- package/agents/gsd-verifier.md +14 -70
- package/bin/install.js +503 -341
- package/commands/gsd/mempalace-capture.md +1 -1
- package/commands/gsd/new-milestone.md +1 -1
- package/commands/gsd/plan-phase.md +1 -1
- package/gsd-core/bin/gsd-tools.cjs +607 -63
- package/gsd-core/bin/lib/active-workstream-store.cjs +25 -0
- package/gsd-core/bin/lib/agent-install-check.cjs +38 -6
- package/gsd-core/bin/lib/api-coverage.cjs +120 -0
- package/gsd-core/bin/lib/audit.cjs +89 -1
- package/gsd-core/bin/lib/broken-windows.cjs +36 -6
- package/gsd-core/bin/lib/capability-registry.cjs +96 -110
- package/gsd-core/bin/lib/capability-validator.cjs +12 -2
- package/gsd-core/bin/lib/check-command-router.cjs +43 -1
- package/gsd-core/bin/lib/command-aliases.cjs +72 -0
- package/gsd-core/bin/lib/commands.cjs +26 -25
- package/gsd-core/bin/lib/commonjs-marker.cjs +136 -0
- package/gsd-core/bin/lib/config-loader.cjs +1 -0
- package/gsd-core/bin/lib/config.cjs +12 -1
- package/gsd-core/bin/lib/context-composer.cjs +278 -0
- package/gsd-core/bin/lib/context-predicates.cjs +506 -0
- package/gsd-core/bin/lib/core-utils.cjs +91 -12
- package/gsd-core/bin/lib/docs.cjs +3 -2
- package/gsd-core/bin/lib/external-job.cjs +19 -4
- package/gsd-core/bin/lib/frontmatter.cjs +84 -12
- package/gsd-core/bin/lib/gate-predicate-evaluator.cjs +57 -6
- package/gsd-core/bin/lib/git-base-branch.cjs +58 -15
- package/gsd-core/bin/lib/graphify.cjs +142 -27
- package/gsd-core/bin/lib/gsd2-import.cjs +27 -4
- package/gsd-core/bin/lib/host-integration.cjs +13 -1
- package/gsd-core/bin/lib/init-command-router.cjs +83 -8
- package/gsd-core/bin/lib/init.cjs +1021 -57
- package/gsd-core/bin/lib/install-engine.cjs +64 -10
- package/gsd-core/bin/lib/install-profiles.cjs +27 -1
- package/gsd-core/bin/lib/installer-migration-authoring.cjs +3 -1
- package/gsd-core/bin/lib/installer-migration-report.cjs +4 -0
- package/gsd-core/bin/lib/installer-migrations/007-retire-config-root-commonjs-marker.cjs +149 -0
- package/gsd-core/bin/lib/installer-migrations/008-cursor-retire-commands-surface.cjs +55 -0
- package/gsd-core/bin/lib/installer-migrations/009-pi-retire-reserved-hooks-dir.cjs +199 -0
- package/gsd-core/bin/lib/installer-migrations.cjs +87 -1
- package/gsd-core/bin/lib/io.cjs +28 -3
- package/gsd-core/bin/lib/markdown-sectionizer.cjs +6 -0
- package/gsd-core/bin/lib/mcp-catalog.cjs +518 -0
- package/gsd-core/bin/lib/mcp-server.cjs +135 -3
- package/gsd-core/bin/lib/milestone.cjs +106 -51
- package/gsd-core/bin/lib/phase-id.cjs +63 -0
- package/gsd-core/bin/lib/phase-locator.cjs +138 -45
- package/gsd-core/bin/lib/phase.cjs +260 -25
- package/gsd-core/bin/lib/plan-dependency-graph.cjs +232 -0
- package/gsd-core/bin/lib/planning-workspace.cjs +4 -0
- package/gsd-core/bin/lib/project-root.cjs +48 -0
- package/gsd-core/bin/lib/prompt-budget.cjs +128 -165
- package/gsd-core/bin/lib/retired-artifact-cleanup.cjs +80 -0
- package/gsd-core/bin/lib/review-lane-descriptor.cjs +99 -0
- package/gsd-core/bin/lib/review-lane-runner.cjs +30 -6
- package/gsd-core/bin/lib/roadmap-command-router.cjs +42 -9
- package/gsd-core/bin/lib/roadmap-parser.cjs +100 -18
- package/gsd-core/bin/lib/roadmap.cjs +37 -7
- package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +195 -62
- package/gsd-core/bin/lib/runtime-artifact-layout.cjs +15 -3
- package/gsd-core/bin/lib/runtime-homes.cjs +154 -41
- package/gsd-core/bin/lib/runtime-hooks-surface.cjs +105 -41
- package/gsd-core/bin/lib/section-manifest.cjs +209 -0
- package/gsd-core/bin/lib/shell-command-projection.cjs +113 -27
- package/gsd-core/bin/lib/smart-entry.cjs +12 -0
- package/gsd-core/bin/lib/state-transition.cjs +73 -8
- package/gsd-core/bin/lib/state.cjs +151 -62
- package/gsd-core/bin/lib/surface.cjs +12 -1
- package/gsd-core/bin/lib/uat-predicate.cjs +11 -1
- package/gsd-core/bin/lib/uat.cjs +320 -21
- package/gsd-core/bin/lib/unusable-input.cjs +9 -0
- package/gsd-core/bin/lib/verification.cjs +29 -12
- package/gsd-core/bin/lib/verify.cjs +29 -5
- package/gsd-core/bin/lib/workflow-fragments.cjs +557 -0
- package/gsd-core/bin/lib/workstream-inventory-builder.cjs +181 -18
- package/gsd-core/bin/lib/workstream-inventory.cjs +519 -27
- package/gsd-core/bin/lib/workstream.cjs +6 -0
- package/gsd-core/bin/lib/worktree-base-ref.cjs +50 -6
- package/gsd-core/bin/lib/worktree-safety.cjs +276 -118
- package/gsd-core/bin/shared/config-schema.manifest.json +2 -0
- package/gsd-core/references/artifact-types.md +10 -3
- package/gsd-core/references/autonomous-ui-design-contract.md +42 -0
- package/gsd-core/references/debugger-techniques.md +255 -0
- package/gsd-core/references/research-documentation-lookup.md +5 -3
- package/gsd-core/references/specless-probe-fallback.md +7 -6
- package/gsd-core/references/verifier-wiring-patterns.md +100 -0
- package/gsd-core/references/worktree-branch-check.md +2 -2
- package/gsd-core/templates/summary-complex.md +2 -0
- package/gsd-core/templates/summary-minimal.md +2 -0
- package/gsd-core/templates/summary-standard.md +2 -0
- package/gsd-core/templates/summary.md +2 -0
- package/gsd-core/workflows/audit-milestone.md +3 -0
- package/gsd-core/workflows/autonomous/steps/converge-banner.md +1 -0
- package/gsd-core/workflows/autonomous/steps/converge-dispatch-bg.md +11 -0
- package/gsd-core/workflows/autonomous/steps/converge-dispatch-inline.md +7 -0
- package/gsd-core/workflows/autonomous/steps/converge-fail-fast.md +21 -0
- package/gsd-core/workflows/autonomous/steps/converge-loop.md +7 -0
- package/gsd-core/workflows/autonomous.md +32 -69
- package/gsd-core/workflows/code-review/steps/dispatch-fix.md +39 -0
- package/gsd-core/workflows/code-review/steps/structural-pre-pass.md +83 -0
- package/gsd-core/workflows/code-review.md +42 -145
- package/gsd-core/workflows/complete-milestone/steps/git-tag.md +29 -0
- package/gsd-core/workflows/complete-milestone.md +23 -81
- package/gsd-core/workflows/debug.md +9 -12
- package/gsd-core/workflows/diagnose-issues.md +22 -0
- package/gsd-core/workflows/discovery-phase.md +4 -4
- package/gsd-core/workflows/discuss-phase-assumptions/steps/auto-advance-dispatch.md +15 -0
- package/gsd-core/workflows/discuss-phase-assumptions.md +5 -16
- package/gsd-core/workflows/docs-update/steps/dispatch-monorepo-packages.md +51 -0
- package/gsd-core/workflows/docs-update.md +8 -51
- package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +34 -2
- package/gsd-core/workflows/execute-phase/steps/gap-closure-artifacts.md +50 -0
- package/gsd-core/workflows/execute-phase/steps/partial-wave.md +31 -0
- package/gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +19 -0
- package/gsd-core/workflows/execute-phase/steps/regression-gate-run.md +42 -0
- package/gsd-core/workflows/execute-phase/steps/regression-gate.md +43 -37
- package/gsd-core/workflows/execute-phase.md +65 -137
- package/gsd-core/workflows/execute-plan.md +1 -1
- package/gsd-core/workflows/help/modes/full.md +6 -1
- package/gsd-core/workflows/ingest-docs.md +2 -1
- package/gsd-core/workflows/new-milestone/steps/project-md-milestone-write.md +16 -0
- package/gsd-core/workflows/new-milestone/steps/reset-phase-safety.md +19 -0
- package/gsd-core/workflows/new-milestone.md +21 -38
- package/gsd-core/workflows/new-project/steps/auto-mode-config.md +176 -0
- package/gsd-core/workflows/new-project/steps/auto-mode-detection.md +32 -0
- package/gsd-core/workflows/new-project/steps/codebase-map-offer.md +18 -0
- package/gsd-core/workflows/new-project.md +13 -226
- package/gsd-core/workflows/plan-phase/steps/adr-ingest-express-path.md +15 -0
- package/gsd-core/workflows/plan-phase/steps/chunked-planning-mode.md +110 -0
- package/gsd-core/workflows/plan-phase/steps/prd-express-gate.md +8 -0
- package/gsd-core/workflows/plan-phase/steps/research-only-early-exit.md +17 -0
- package/gsd-core/workflows/plan-phase/steps/research-only-modifiers.md +16 -0
- package/gsd-core/workflows/plan-phase/steps/reviews-prerequisite.md +17 -0
- package/gsd-core/workflows/plan-phase/steps/stall-detection-helpers.md +149 -0
- package/gsd-core/workflows/plan-phase.md +49 -193
- package/gsd-core/workflows/progress/steps/forensic-audit.md +125 -0
- package/gsd-core/workflows/progress/steps/mvp-display.md +18 -0
- package/gsd-core/workflows/progress.md +11 -153
- package/gsd-core/workflows/quick/steps/discussion-phase.md +124 -0
- package/gsd-core/workflows/quick/steps/plan-checker-loop.md +111 -0
- package/gsd-core/workflows/quick/steps/quick-verification.md +46 -0
- package/gsd-core/workflows/quick/steps/research-phase.md +72 -0
- package/gsd-core/workflows/quick/steps/worktree-pre-dispatch-commit.md +37 -0
- package/gsd-core/workflows/quick.md +20 -390
- package/gsd-core/workflows/resume-project.md +3 -0
- package/gsd-core/workflows/review/steps/reviewer-instances-note-1.md +4 -0
- package/gsd-core/workflows/review/steps/reviewer-instances-note-2.md +3 -0
- package/gsd-core/workflows/review.md +15 -8
- package/gsd-core/workflows/section-manifest.json +219 -0
- package/gsd-core/workflows/sketch.md +1 -1
- package/gsd-core/workflows/spec-phase.md +17 -14
- package/gsd-core/workflows/spike-wrap-up.md +20 -5
- package/gsd-core/workflows/spike.md +50 -16
- package/gsd-core/workflows/sync-skills.md +49 -11
- package/gsd-core/workflows/transition/steps/workstream-collision-check.md +17 -0
- package/gsd-core/workflows/transition.md +8 -21
- package/gsd-core/workflows/ui-phase.md +8 -7
- package/gsd-core/workflows/update/steps/channel-banner.md +7 -0
- package/gsd-core/workflows/update.md +18 -7
- package/gsd-core/workflows/verify-phase.md +4 -7
- package/gsd-core/workflows/verify-work/steps/automated-ui-verification.md +36 -0
- package/gsd-core/workflows/verify-work/steps/mvp-uat-framing.md +21 -0
- package/gsd-core/workflows/verify-work.md +8 -58
- package/hooks/dist/gsd-agent-isolation-guard.js +428 -0
- package/hooks/dist/gsd-check-update-worker.js +14 -5
- package/hooks/dist/gsd-cursor-subagent-start.js +532 -26
- package/hooks/dist/gsd-read-injection-scanner.js +7 -0
- package/hooks/dist/gsd-statusline.js +72 -6
- package/hooks/dist/gsd-worktree-path-guard.js +2 -1
- package/hooks/dist/gsd-write-guard.js +359 -0
- package/hooks/dist/lib/isolation-sentinel.js +268 -0
- package/hooks/dist/managed-hooks-registry.cjs +2 -0
- package/hooks/gsd-agent-isolation-guard.js +428 -0
- package/hooks/gsd-check-update-worker.js +14 -5
- package/hooks/gsd-cursor-subagent-start.js +532 -26
- package/hooks/gsd-read-injection-scanner.js +7 -0
- package/hooks/gsd-statusline.js +72 -6
- package/hooks/gsd-worktree-path-guard.js +2 -1
- package/hooks/gsd-write-guard.js +359 -0
- package/hooks/hooks.json +12 -0
- package/hooks/lib/isolation-sentinel.js +268 -0
- package/hooks/managed-hooks-registry.cjs +2 -0
- package/package.json +14 -5
- package/pi/gsd.cjs +57 -12
- package/scripts/build-hooks.js +9 -0
- package/scripts/changeset/lint.cjs +9 -2
- package/scripts/changeset/serialize.cjs +5 -1
- package/scripts/gen-capability-matrix.cjs +1 -1
- package/scripts/gen-context-index.cjs +448 -0
- package/scripts/gen-inventory-manifest.cjs +101 -1
- package/scripts/gen-prompt-budget-parity-corpus.cjs +645 -0
- package/scripts/gen-registry.cjs +39 -15
- package/scripts/gen-section-manifest.cjs +638 -0
- package/scripts/generate-package-identity.cjs +4 -2
- package/scripts/lint-allow-test-rule-refs.allowlist.json +17 -31
- package/scripts/lint-compiled-artifact-sync.cjs +6 -1
- package/scripts/lint-docs-command-form.cjs +195 -0
- package/scripts/lint-docs-required.cjs +9 -1
- package/scripts/lint-emitted-drift-ack.cjs +215 -20
- package/scripts/lint-example-parser-parity.cjs +395 -0
- package/scripts/lint-test-file-count.allowlist.json +27 -1
- package/scripts/mutation-matrix.cjs +13 -0
- package/scripts/prompt-injection-scan.sh +27 -6
- package/scripts/registry-schema.cjs +323 -94
- package/scripts/run-tests.cjs +3 -2
- package/scripts/validate-registry.cjs +10 -6
- package/skills/gsd-autonomous/SKILL.md +1 -1
- package/skills/gsd-execute-phase/SKILL.md +1 -1
- package/skills/gsd-mempalace-capture/SKILL.md +1 -1
- package/skills/gsd-new-milestone/SKILL.md +1 -1
- package/skills/gsd-plan-phase/SKILL.md +2 -2
- package/vscode/package.json +1 -1
- package/scripts/gen-emitted-baseline.cjs +0 -145
|
@@ -27,6 +27,16 @@ const planScan = require("./plan-scan.cjs");
|
|
|
27
27
|
const planningWorkspace = require("./planning-workspace.cjs");
|
|
28
28
|
const { planningPaths, planningRoot, getActiveWorkstream } = planningWorkspace;
|
|
29
29
|
const state_document_cjs_1 = require("./state-document.cjs");
|
|
30
|
+
const markdown_table_cjs_1 = require("./markdown-table.cjs");
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- verification.cjs is an export= CommonJS module
|
|
32
|
+
const verificationMod = require("./verification.cjs");
|
|
33
|
+
const { readVerificationStatus } = verificationMod;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- phase-id.cjs is an export= CommonJS module
|
|
35
|
+
const phaseIdMod = require("./phase-id.cjs");
|
|
36
|
+
const { phaseKeyFromDir, phaseKeyFromProse, parentPhaseKey } = phaseIdMod;
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- roadmap-parser.cjs is an export= CommonJS module
|
|
38
|
+
const roadmapParserMod = require("./roadmap-parser.cjs");
|
|
39
|
+
const { getMilestonePhaseFilter, isMilestoneShippedInRoadmap } = roadmapParserMod;
|
|
30
40
|
const workstream_inventory_builder_cjs_1 = require("./workstream-inventory-builder.cjs");
|
|
31
41
|
// ─── Implementation ───────────────────────────────────────────────────────────
|
|
32
42
|
function workstreamsRoot(cwd) {
|
|
@@ -42,35 +52,97 @@ function countRoadmapPhases(roadmapPath, fallbackCount) {
|
|
|
42
52
|
return fallbackCount;
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
/**
|
|
56
|
+
* #2562: parse the ROADMAP `## Progress` table into canonical phase keys with
|
|
57
|
+
* their milestone attribution, e.g. `| 30. Name | v10.0 | 1/3 | … |` →
|
|
58
|
+
* `{ key: '30', version: 'v10.0' }`. The table is the authoritative per-phase
|
|
59
|
+
* milestone attribution and — crucially — lists phases declared but never
|
|
60
|
+
* scaffolded (no directory), which a directory-only scan misses. `Plans
|
|
61
|
+
* Complete` is present in BOTH RoadmapProgress variants, so this matches the
|
|
62
|
+
* flat (no Milestone column → every `version` null) and milestone-grouped
|
|
63
|
+
* shapes alike.
|
|
64
|
+
*
|
|
65
|
+
* Row keys come from `phaseKeyFromProse`, the same owner-module derivation
|
|
66
|
+
* `phaseKeyFromDir` uses for directories, so a `| 01. … |` row and a `1-slug`
|
|
67
|
+
* directory cannot land in different key spaces (the padding-asymmetry defect).
|
|
68
|
+
*/
|
|
69
|
+
function parseRoadmapProgressRows(roadmapPath) {
|
|
70
|
+
let content;
|
|
71
|
+
try {
|
|
72
|
+
content = node_fs_1.default.readFileSync(roadmapPath, 'utf-8');
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return []; /* no roadmap */
|
|
76
|
+
}
|
|
77
|
+
// Milestone-ATTRIBUTING shape first. Both shapes carry `Plans Complete`, so
|
|
78
|
+
// probing that column first would pick a flat table appearing earlier in the
|
|
79
|
+
// document over a milestone-grouped one later — every row would come back
|
|
80
|
+
// unattributed and be treated as current-milestone, silently over-including.
|
|
81
|
+
const table = (0, markdown_table_cjs_1.findTableWithColumns)(content, ['Phase', 'Milestone'])
|
|
82
|
+
?? (0, markdown_table_cjs_1.findTableWithColumns)(content, ['Phase', 'Plans Complete']);
|
|
83
|
+
if (!table)
|
|
84
|
+
return [];
|
|
85
|
+
const rows = [];
|
|
86
|
+
for (const row of table.rows) {
|
|
87
|
+
const key = phaseKeyFromProse(row['Phase']);
|
|
88
|
+
if (key === null)
|
|
89
|
+
continue;
|
|
90
|
+
const cell = (row['Milestone'] ?? '').trim();
|
|
91
|
+
rows.push({ key, version: /^v\d+(?:\.\d+)+$/.test(cell) ? cell : null });
|
|
92
|
+
}
|
|
93
|
+
return rows;
|
|
48
94
|
}
|
|
49
|
-
|
|
95
|
+
/**
|
|
96
|
+
* #2562: the workstream's CURRENT milestone version, read from the STATE.md
|
|
97
|
+
* `milestone:` frontmatter field (the reliable per-workstream signal — the
|
|
98
|
+
* ROADMAP's own in-progress markers can be stale, e.g. a lingering 🚧 on an
|
|
99
|
+
* already-shipped milestone). Falls back to the ROADMAP in-progress heading
|
|
100
|
+
* marker only when STATE has no field.
|
|
101
|
+
*/
|
|
102
|
+
function readCurrentMilestoneVersion(statePath, roadmapPath) {
|
|
50
103
|
try {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
current_phase: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Current Phase'),
|
|
55
|
-
last_activity: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Last Activity'),
|
|
56
|
-
};
|
|
104
|
+
const m = node_fs_1.default.readFileSync(statePath, 'utf-8').match(/^milestone:\s*["']?(v\d+(?:\.\d+)+)["']?/m);
|
|
105
|
+
if (m)
|
|
106
|
+
return m[1];
|
|
57
107
|
}
|
|
58
108
|
catch {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
109
|
+
/* no state */
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const rm = node_fs_1.default.readFileSync(roadmapPath, 'utf-8').match(/(?:🚧|🔄)\s*\*\*(v\d+(?:\.\d+)+)\b/);
|
|
113
|
+
if (rm)
|
|
114
|
+
return rm[1];
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
/* no roadmap */
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* #2562: does the CURRENT milestone's own ROADMAP heading carry a shipped
|
|
123
|
+
* marker? Delegated to `roadmap-parser`, the module that owns milestone-heading
|
|
124
|
+
* classification: heading/`<summary>` lines only (never a bullet that merely
|
|
125
|
+
* names the version), version-token boundary-matched so `v2.0` does not match
|
|
126
|
+
* inside `v2.0.1`, and in-progress markers win. Scoped to the current version,
|
|
127
|
+
* so a prior milestone's collapsed `<details><summary>✅ … SHIPPED</summary>`
|
|
128
|
+
* block can never mark the current milestone complete.
|
|
129
|
+
*/
|
|
130
|
+
function currentMilestoneHeadingShipped(roadmapPath, version) {
|
|
131
|
+
try {
|
|
132
|
+
return isMilestoneShippedInRoadmap(node_fs_1.default.readFileSync(roadmapPath, 'utf-8'), version);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return false; /* no roadmap */
|
|
64
136
|
}
|
|
65
137
|
}
|
|
66
138
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
139
|
+
* Legacy pre-#2562 shipped detection: ANY archived milestone snapshot OR a
|
|
140
|
+
* SHIPPED marker anywhere in the ROADMAP. Over-broad (project-lifetime, not
|
|
141
|
+
* milestone-scoped) — retained ONLY as the fallback when the current milestone
|
|
142
|
+
* version cannot be determined (malformed/legacy STATE.md with no `milestone:`
|
|
143
|
+
* field), so those projects keep #1913's stale-field protection.
|
|
72
144
|
*/
|
|
73
|
-
function
|
|
145
|
+
function legacyMilestoneShipped(roadmapPath, planningBase) {
|
|
74
146
|
try {
|
|
75
147
|
const milestonesDir = node_path_1.default.join(planningBase, 'milestones');
|
|
76
148
|
for (const entry of node_fs_1.default.readdirSync(milestonesDir, { withFileTypes: true })) {
|
|
@@ -90,6 +162,202 @@ function workstreamMilestoneShipped(roadmapPath, planningBase) {
|
|
|
90
162
|
}
|
|
91
163
|
return false;
|
|
92
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* #2562: directory mtime, used only to break a duplicate-phase-key tie in the
|
|
167
|
+
* rollup (keep the more recently touched directory — the Bug #2445 rule). 0 on
|
|
168
|
+
* a stat failure, which loses the tie rather than throwing.
|
|
169
|
+
*/
|
|
170
|
+
function phaseDirMtime(phaseDir) {
|
|
171
|
+
try {
|
|
172
|
+
return node_fs_1.default.statSync(phaseDir).mtimeMs;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function countPhaseFiles(phaseDir) {
|
|
179
|
+
const scan = planScan(phaseDir);
|
|
180
|
+
return { planCount: scan.planCount, summaryCount: scan.summaryCount };
|
|
181
|
+
}
|
|
182
|
+
function verificationLedgerPath(wsDir) {
|
|
183
|
+
return node_path_1.default.join(wsDir, '.verification-ledger.json');
|
|
184
|
+
}
|
|
185
|
+
function readVerificationLedger(wsDir) {
|
|
186
|
+
const ledgerPath = verificationLedgerPath(wsDir);
|
|
187
|
+
let raw;
|
|
188
|
+
try {
|
|
189
|
+
raw = node_fs_1.default.readFileSync(ledgerPath, 'utf-8');
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
// `fs.readFileSync` FOLLOWS symlinks, so a broken symlink at this path
|
|
193
|
+
// (the entry exists, its target does not) reports the EXACT SAME
|
|
194
|
+
// `ENOENT` as genuine absence — `code` alone cannot distinguish
|
|
195
|
+
// "nothing was ever here" from "something is here and cannot be read".
|
|
196
|
+
// `fs.lstatSync` does NOT follow symlinks, so it still finds the
|
|
197
|
+
// symlink entry itself even when its target is gone. Only when NEITHER
|
|
198
|
+
// call finds anything is this genuinely `'absent'` (pre-adoption); a
|
|
199
|
+
// present-but-broken symlink is evidence something existed and must
|
|
200
|
+
// fail CLOSED like any other unreadable ledger, not fall open.
|
|
201
|
+
const code = err?.code;
|
|
202
|
+
if (code === 'ENOENT') {
|
|
203
|
+
try {
|
|
204
|
+
node_fs_1.default.lstatSync(ledgerPath);
|
|
205
|
+
return { state: 'corrupt', entries: {} }; // a symlink entry exists; its target does not
|
|
206
|
+
}
|
|
207
|
+
catch (lstatErr) {
|
|
208
|
+
// #2645 review: every OTHER failure path in this function fails
|
|
209
|
+
// CLOSED — this one must too. A failed `lstatSync` is only proof of
|
|
210
|
+
// absence when IT ALSO reports `ENOENT`; anything else (a raced
|
|
211
|
+
// permission change, a path component that became inaccessible
|
|
212
|
+
// between the two calls, …) is not evidence the file was never
|
|
213
|
+
// there, and a bare `catch {}` here would silently fall OPEN exactly
|
|
214
|
+
// like the two-state design this fix replaced.
|
|
215
|
+
const lstatCode = lstatErr?.code;
|
|
216
|
+
if (lstatCode === 'ENOENT')
|
|
217
|
+
return { state: 'absent', entries: {} }; // truly nothing at this path
|
|
218
|
+
return { state: 'corrupt', entries: {} };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Any OTHER read failure (EACCES, EISDIR, …) also means the path EXISTS
|
|
222
|
+
// in some form but this process cannot see its content right now — that
|
|
223
|
+
// is corruption from this reader's point of view, not absence, and must
|
|
224
|
+
// fail closed rather than silently falling back to the ungated
|
|
225
|
+
// pre-adoption behavior.
|
|
226
|
+
return { state: 'corrupt', entries: {} };
|
|
227
|
+
}
|
|
228
|
+
let parsed;
|
|
229
|
+
try {
|
|
230
|
+
parsed = JSON.parse(raw);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return { state: 'corrupt', entries: {} };
|
|
234
|
+
}
|
|
235
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
236
|
+
return { state: 'corrupt', entries: {} };
|
|
237
|
+
}
|
|
238
|
+
const out = {};
|
|
239
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
240
|
+
if (typeof value === 'string')
|
|
241
|
+
out[key] = value;
|
|
242
|
+
}
|
|
243
|
+
return { state: 'ok', entries: out };
|
|
244
|
+
}
|
|
245
|
+
// #2645 review: Windows can transiently hold the rename target busy (AV
|
|
246
|
+
// scanners, indexers) — the SAME retry shape `broken-windows.cts`'s
|
|
247
|
+
// `writeLedgerAtomic`/`renameWithRetry` already uses for its own ledger
|
|
248
|
+
// write, mirrored here rather than imported (that function is private to
|
|
249
|
+
// its module) so this fix does not widen its own blast radius by exporting
|
|
250
|
+
// a new cross-module utility.
|
|
251
|
+
const LEDGER_RENAME_RETRY_ERRNOS = new Set(['EPERM', 'EBUSY', 'EACCES']);
|
|
252
|
+
const LEDGER_RENAME_MAX_ATTEMPTS = 5;
|
|
253
|
+
const LEDGER_RENAME_BACKOFF_MS = 25;
|
|
254
|
+
function renameVerificationLedgerWithRetry(tmpPath, finalPath) {
|
|
255
|
+
let lastErr;
|
|
256
|
+
for (let attempt = 0; attempt < LEDGER_RENAME_MAX_ATTEMPTS; attempt++) {
|
|
257
|
+
try {
|
|
258
|
+
node_fs_1.default.renameSync(tmpPath, finalPath);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
lastErr = err;
|
|
263
|
+
const code = (err && typeof err === 'object' && 'code' in err) ? String(err.code) : '';
|
|
264
|
+
if (code && LEDGER_RENAME_RETRY_ERRNOS.has(code) && attempt < LEDGER_RENAME_MAX_ATTEMPTS - 1) {
|
|
265
|
+
// Exponential-ish backoff: 25ms, 50ms, 100ms, 200ms. Transient
|
|
266
|
+
// Windows locks usually clear well inside that window.
|
|
267
|
+
const delay = LEDGER_RENAME_BACKOFF_MS * Math.pow(2, attempt);
|
|
268
|
+
const start = Date.now();
|
|
269
|
+
while (Date.now() - start < delay) {
|
|
270
|
+
// Deliberate short busy-wait — no async/timer seam is available
|
|
271
|
+
// in this synchronous read path.
|
|
272
|
+
}
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
throw err;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
throw lastErr;
|
|
279
|
+
}
|
|
280
|
+
function writeVerificationLedger(wsDir, ledger) {
|
|
281
|
+
// #2645 review: atomic write. A crash or a concurrent read mid-write
|
|
282
|
+
// against `verificationLedgerPath(wsDir)` directly would leave (or briefly
|
|
283
|
+
// expose) TRUNCATED JSON — and now that `'corrupt'` carries real semantic
|
|
284
|
+
// weight (it fails CLOSED, holding every phase with no live report at
|
|
285
|
+
// `'unrecorded'`), producing a corrupt file ourselves is a self-inflicted
|
|
286
|
+
// version of the exact failure mode this fix exists to survive. Write to a
|
|
287
|
+
// sibling temp file in the SAME directory (same filesystem — `rename` is
|
|
288
|
+
// only atomic within one) and rename into place: a reader can only ever
|
|
289
|
+
// observe the prior complete content or the new complete content.
|
|
290
|
+
const finalPath = verificationLedgerPath(wsDir);
|
|
291
|
+
const tmpPath = `${finalPath}.${process.pid}.tmp`;
|
|
292
|
+
try {
|
|
293
|
+
node_fs_1.default.mkdirSync(wsDir, { recursive: true });
|
|
294
|
+
node_fs_1.default.writeFileSync(tmpPath, `${JSON.stringify(ledger, null, 2)}\n`, 'utf-8');
|
|
295
|
+
renameVerificationLedgerWithRetry(tmpPath, finalPath);
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// Best-effort persistence: a missing parent directory that `mkdirSync`
|
|
299
|
+
// itself cannot create, a read-only filesystem, a write failure, or a
|
|
300
|
+
// rename failure that exhausts its retries must not break inventory
|
|
301
|
+
// reads, which are otherwise pure. Losing this observation only
|
|
302
|
+
// re-opens the pre-#2645 window for THIS run; the next successful read
|
|
303
|
+
// while a report is on disk repairs it. Clean up a half-written temp
|
|
304
|
+
// file so repeated failures cannot accumulate orphaned
|
|
305
|
+
// `.verification-ledger.json.<pid>.tmp` files.
|
|
306
|
+
try {
|
|
307
|
+
node_fs_1.default.unlinkSync(tmpPath);
|
|
308
|
+
}
|
|
309
|
+
catch { /* nothing to clean up, or cleanup itself failed — not fatal */ }
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function readStateProjection(statePath) {
|
|
313
|
+
try {
|
|
314
|
+
const stateContent = node_fs_1.default.readFileSync(statePath, 'utf-8');
|
|
315
|
+
return {
|
|
316
|
+
status: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Status') || 'unknown',
|
|
317
|
+
current_phase: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Current Phase'),
|
|
318
|
+
last_activity: (0, state_document_cjs_1.stateExtractField)(stateContent, 'Last Activity'),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return {
|
|
323
|
+
status: 'unknown',
|
|
324
|
+
current_phase: null,
|
|
325
|
+
last_activity: null,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* #1913 + #2562: detect an authoritative shipped signal for a workstream's
|
|
331
|
+
* CURRENT milestone, so the inventory status is never trusted from the mutable
|
|
332
|
+
* STATE.md `Status` field alone (#1913) yet is never pinned to "milestone
|
|
333
|
+
* complete" by a PRIOR milestone's shipped marker (#2562).
|
|
334
|
+
*
|
|
335
|
+
* When the current milestone version is known, the signal is scoped to it:
|
|
336
|
+
* an archived snapshot `milestones/<version>-ROADMAP.md` (the canonical
|
|
337
|
+
* "milestone shipped" artifact) OR the current milestone's own ROADMAP line
|
|
338
|
+
* marked shipped. When the version cannot be determined, we fall back to the
|
|
339
|
+
* over-broad legacy detection to preserve #1913's protection for those
|
|
340
|
+
* (malformed/legacy) projects.
|
|
341
|
+
*
|
|
342
|
+
* Returns WHICH signal fired, not merely that one did. The two differ in how
|
|
343
|
+
* much they can be trusted and therefore in how the builder cross-validates
|
|
344
|
+
* them against the milestone's own artifacts — see the `shippedContradicted`
|
|
345
|
+
* block in `workstream-inventory-builder.cts`. Collapsing them to a boolean is
|
|
346
|
+
* what forced a single completeness check to serve two incompatible shapes.
|
|
347
|
+
*/
|
|
348
|
+
function workstreamShippedSignal(roadmapPath, planningBase, currentVersion) {
|
|
349
|
+
if (!currentVersion) {
|
|
350
|
+
return legacyMilestoneShipped(roadmapPath, planningBase) ? 'legacy' : null;
|
|
351
|
+
}
|
|
352
|
+
// Canonical shipped artifact: the archived ROADMAP snapshot of the CURRENT
|
|
353
|
+
// milestone (`vX.Y-ROADMAP.md`), written at milestone close. REQUIREMENTS
|
|
354
|
+
// snapshots are intentionally NOT accepted — they can be written at milestone
|
|
355
|
+
// START (requirements-locked), so they do not imply shipped.
|
|
356
|
+
const snapshot = node_path_1.default.join(planningBase, 'milestones', `${currentVersion}-ROADMAP.md`);
|
|
357
|
+
if (node_fs_1.default.existsSync(snapshot))
|
|
358
|
+
return 'snapshot';
|
|
359
|
+
return currentMilestoneHeadingShipped(roadmapPath, currentVersion) ? 'heading' : null;
|
|
360
|
+
}
|
|
93
361
|
function sortWorkstreamInventories(inventories, activeWorkstreamName) {
|
|
94
362
|
return [...inventories].sort((a, b) => {
|
|
95
363
|
const aActive = a.name === activeWorkstreamName ? 1 : 0;
|
|
@@ -105,13 +373,232 @@ function inspectWorkstream(cwd, name, options = {}) {
|
|
|
105
373
|
if (!node_fs_1.default.existsSync(wsDir))
|
|
106
374
|
return null;
|
|
107
375
|
const activeWorkstreamName = options.active === undefined ? getActiveWorkstream(cwd) : options.active;
|
|
376
|
+
const writeDiagnostic = options.writeDiagnostic ?? ((message) => process.stderr.write(message));
|
|
108
377
|
const p = planningPaths(cwd, name);
|
|
109
378
|
const phaseDirNames = readSubdirectories(p.phases);
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
379
|
+
// #2562: scope progress to the CURRENT milestone. Membership and the
|
|
380
|
+
// denominator are derived in ONE key space (`phaseKeyFromDir` /
|
|
381
|
+
// `phaseKeyFromProse`, both from the phase-id owner module) so the two sides
|
|
382
|
+
// of the rollup cannot disagree.
|
|
383
|
+
const currentVersion = readCurrentMilestoneVersion(p.state, p.roadmap);
|
|
384
|
+
const progressRows = parseRoadmapProgressRows(p.roadmap);
|
|
385
|
+
// Phase keys the ROADMAP attributes to the current milestone. A row whose
|
|
386
|
+
// Milestone cell is blank or malformed is INCLUDED rather than dropped: a
|
|
387
|
+
// phase we cannot attribute must still be visible to the rollup. Dropping it
|
|
388
|
+
// from both sides was the silent-deletion defect — it let an unstarted phase
|
|
389
|
+
// vanish and the percentage round to 100. Over-inclusive-never-under is the
|
|
390
|
+
// degrade direction this codebase already commits to for unparseable roadmap
|
|
391
|
+
// input (see the getMilestonePhaseFilter catch in roadmap-parser.cts).
|
|
392
|
+
const currentMilestoneKeys = new Set();
|
|
393
|
+
if (currentVersion) {
|
|
394
|
+
for (const row of progressRows) {
|
|
395
|
+
if (row.version === null || row.version === currentVersion)
|
|
396
|
+
currentMilestoneKeys.add(row.key);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
// Roadmap-heading membership, from the module that OWNS milestone-phase
|
|
400
|
+
// filtering. Consulted only when it is genuinely scoped to a single milestone
|
|
401
|
+
// (`versionScoped`); the unversioned whole-roadmap shape spans the project's
|
|
402
|
+
// lifetime and would re-admit prior-milestone phases — the very defect here.
|
|
403
|
+
const headingFilter = getMilestonePhaseFilter(cwd, currentVersion, null, name);
|
|
404
|
+
const headingScoped = headingFilter.versionScoped && headingFilter.phaseCount > 0;
|
|
405
|
+
// Phase keys the ROADMAP attributes to some OTHER milestone. A row carrying an
|
|
406
|
+
// explicit version that is not the current one is a positive claim by a prior
|
|
407
|
+
// (or future) milestone — the only reliable evidence that a phase does NOT
|
|
408
|
+
// belong to the current one.
|
|
409
|
+
const claimedElsewhere = new Set();
|
|
410
|
+
for (const row of progressRows) {
|
|
411
|
+
if (row.version !== null && row.version !== currentVersion)
|
|
412
|
+
claimedElsewhere.add(row.key);
|
|
413
|
+
}
|
|
414
|
+
// #2562: the current milestone is DECLARED but nothing attributes a phase to
|
|
415
|
+
// it yet — the window right after `/gsd-new-milestone`, where STATE.md's
|
|
416
|
+
// `milestone:` field updates the moment the heading lands but the Progress
|
|
417
|
+
// table and phase sections have not caught up.
|
|
418
|
+
//
|
|
419
|
+
// Treating that as "unscoped" was a hole in the original fix: scoping switched
|
|
420
|
+
// off entirely and the fallback below counted the project's ENTIRE phase
|
|
421
|
+
// history as both numerator and denominator, so a workstream whose current
|
|
422
|
+
// milestone had zero phases done reported 100% off its predecessors' work.
|
|
423
|
+
// That is the very symptom #2562 reports, reached by a different route.
|
|
424
|
+
//
|
|
425
|
+
// Three independent signals witness it; ANY of them is enough, and each covers
|
|
426
|
+
// a ROADMAP shape the others miss:
|
|
427
|
+
// - `versionSectionFound` — the milestone's own section exists but declares
|
|
428
|
+
// no phases (heading-only ROADMAPs, and the common `## v3.0` stub).
|
|
429
|
+
// - `missingExplicitVersion` — the ROADMAP versions its milestones but has
|
|
430
|
+
// no section for this one at all.
|
|
431
|
+
// - a Progress table that attributes every row elsewhere (`claimedElsewhere`
|
|
432
|
+
// non-empty while `currentMilestoneKeys` is empty).
|
|
433
|
+
// A ROADMAP that attributes NO versions anywhere matches none of them: its
|
|
434
|
+
// rows parse with `version: null`, land in `currentMilestoneKeys`, and never
|
|
435
|
+
// reach here. That is deliberate — for a free-form legacy project the
|
|
436
|
+
// whole-roadmap count IS the current milestone, and `readCurrentMilestoneVersion`
|
|
437
|
+
// hands back a non-null version for almost every project, so keying off
|
|
438
|
+
// `currentVersion` alone would regress every one of them to 0%.
|
|
439
|
+
const currentMilestoneDeclaredEmpty = currentVersion !== null &&
|
|
440
|
+
currentMilestoneKeys.size === 0 &&
|
|
441
|
+
!headingScoped &&
|
|
442
|
+
(headingFilter.versionSectionFound || headingFilter.missingExplicitVersion || claimedElsewhere.size > 0);
|
|
443
|
+
// A dir-only phase joins the current milestone when the roadmap names it, or
|
|
444
|
+
// when it is a sub-phase (`30.1-…`) of a phase the roadmap names — sub-phases
|
|
445
|
+
// inserted mid-milestone rarely get a row of their own. Membership feeds BOTH
|
|
446
|
+
// the numerator and (via `milestoneKeys` below) the denominator, so a member
|
|
447
|
+
// can never exceed the denominator that counts it.
|
|
448
|
+
const scoped = currentMilestoneKeys.size > 0 || headingScoped || currentMilestoneDeclaredEmpty;
|
|
449
|
+
const isDirInCurrentMilestone = (dir) => {
|
|
450
|
+
if (!scoped)
|
|
451
|
+
return true;
|
|
452
|
+
const key = phaseKeyFromDir(dir);
|
|
453
|
+
if (currentMilestoneKeys.has(key))
|
|
454
|
+
return true;
|
|
455
|
+
const parent = parentPhaseKey(key);
|
|
456
|
+
if (parent !== null && currentMilestoneKeys.has(parent))
|
|
457
|
+
return true;
|
|
458
|
+
// An empty current milestone has no roadmap declarations to match against,
|
|
459
|
+
// so membership inverts: a directory belongs UNLESS another milestone claims
|
|
460
|
+
// it. A phase scaffolded before the roadmap caught up would otherwise vanish
|
|
461
|
+
// from both sides of the rollup — under-reporting, the direction this
|
|
462
|
+
// codebase never degrades in.
|
|
463
|
+
if (currentMilestoneDeclaredEmpty) {
|
|
464
|
+
const parentKey = parentPhaseKey(key);
|
|
465
|
+
return !claimedElsewhere.has(key) && (parentKey === null || !claimedElsewhere.has(parentKey));
|
|
466
|
+
}
|
|
467
|
+
return headingScoped && headingFilter(dir);
|
|
468
|
+
};
|
|
469
|
+
// Collect per-phase file counts (+ canonical key, milestone membership,
|
|
470
|
+
// verification verdict). `phaseKey` lets the builder de-duplicate stale
|
|
471
|
+
// same-numbered directories (Bug #2445's scenario) in the rollup.
|
|
472
|
+
//
|
|
473
|
+
// #2645 review: built from `[...phaseDirNames].sort()`, NOT the raw
|
|
474
|
+
// `phaseDirNames` (unsorted `readdirSync` order — `readSubdirectories`'s
|
|
475
|
+
// default). `buildWorkstreamInventory`'s own de-dup (`rollupDirByKey`,
|
|
476
|
+
// workstream-inventory-builder.cts) iterates the SAME sorted order; the
|
|
477
|
+
// ledger-winner tie-break below (incumbent wins unless a later entry has a
|
|
478
|
+
// STRICTLY newer mtime) only agrees with the builder's winner on an exact
|
|
479
|
+
// mtime tie if both walk entries in the same order. Iterating unsorted
|
|
480
|
+
// input here let the two independently pick different "winning"
|
|
481
|
+
// directories for one phase key on a tie — reopening the stale-duplicate-
|
|
482
|
+
// clobbers-live-verdict hole criterion 4 exists to close.
|
|
483
|
+
const rawPhaseEntries = [...phaseDirNames].sort().map(dir => {
|
|
484
|
+
const phaseDir = node_path_1.default.join(p.phases, dir);
|
|
485
|
+
const counts = countPhaseFiles(phaseDir);
|
|
486
|
+
const verificationResult = readVerificationStatus(phaseDir);
|
|
487
|
+
// #3057 B3: routing is UNCHANGED — `liveVerificationStatus` below is still
|
|
488
|
+
// `.status`, exactly as before, so the ledger/rollup logic that consumes
|
|
489
|
+
// it is unaffected. This only makes an indeterminate staleness check
|
|
490
|
+
// visible (stderr), matching cmdGitBaseBranch's own non-blocking
|
|
491
|
+
// unverified-fallback diagnostic (#3057 B4) — the closest existing idiom,
|
|
492
|
+
// since `WorkstreamInventory`'s aggregate return shape carries no
|
|
493
|
+
// per-phase verification detail for this to attach to.
|
|
494
|
+
if (verificationResult.staleCheckIndeterminate) {
|
|
495
|
+
writeDiagnostic(`⚠ workstream-inventory: verification staleness check could not complete for phase directory '${dir}' in workstream '${name}' — routed as not-stale, but this was not actually verified. See #3057.\n`, { phaseDir: dir, reason: 'staleCheckIndeterminate' });
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
directory: dir,
|
|
499
|
+
phaseKey: phaseKeyFromDir(dir),
|
|
500
|
+
mtimeMs: phaseDirMtime(phaseDir),
|
|
501
|
+
planCount: counts.planCount,
|
|
502
|
+
summaryCount: counts.summaryCount,
|
|
503
|
+
inMilestone: isDirInCurrentMilestone(dir),
|
|
504
|
+
liveVerificationStatus: verificationResult.status,
|
|
505
|
+
};
|
|
506
|
+
});
|
|
507
|
+
// #2645: only the directory Bug #2445's de-dup rollup would actually pick
|
|
508
|
+
// for a phase key may read or write that key's ledger entry. Letting every
|
|
509
|
+
// same-keyed directory (including a stale leftover) write would let a
|
|
510
|
+
// stale duplicate's stale verdict clobber the live directory's remembered
|
|
511
|
+
// one.
|
|
512
|
+
//
|
|
513
|
+
// #2645 review — CORRECTED: an earlier version of this comment claimed the
|
|
514
|
+
// milestone-scoping exclusion (`scoped && entry.inMilestone === false`)
|
|
515
|
+
// was safe to drop here as "out of scope", and hand-wrote a scoping-free
|
|
516
|
+
// tie-break rule. That was a real bug, not a scope call: in a SCOPED
|
|
517
|
+
// workstream, a stale OUT-of-milestone directory sharing a phase key with
|
|
518
|
+
// the live IN-milestone one can have a newer mtime (plausible after a
|
|
519
|
+
// checkout/rebase resets mtimes) and would then win THIS selection while
|
|
520
|
+
// the builder's own `rollupDirByKey` — which DOES apply the scoping filter
|
|
521
|
+
// — picks the live directory instead. `isLedgerWinner` would then be false
|
|
522
|
+
// for the live directory, so deleting ITS `*-VERIFICATION.md` would never
|
|
523
|
+
// consult the ledger and would reopen #2645's exact hole for the phase
|
|
524
|
+
// that actually counts toward `completed_phases` — reachable with a plain
|
|
525
|
+
// `rm`, no ledger tampering required. Fixed by calling the SAME shared
|
|
526
|
+
// `pickRollupWinners` the builder's `rollupDirByKey` now also calls, with
|
|
527
|
+
// the identical scoping filter, rather than a second hand-written copy.
|
|
528
|
+
const ledgerWinnerByKey = (0, workstream_inventory_builder_cjs_1.pickRollupWinners)(rawPhaseEntries, (entry) => entry.phaseKey, (entry) => entry.mtimeMs, (entry) => !(scoped && entry.inMilestone === false));
|
|
529
|
+
const ledgerRead = readVerificationLedger(wsDir);
|
|
530
|
+
// Both `'corrupt'` and `'ok'` start from whatever entries could actually be
|
|
531
|
+
// trusted (empty for `'corrupt'` — nothing in an unparseable file is
|
|
532
|
+
// trusted) and get REPAIRED below by any real verdict this call observes;
|
|
533
|
+
// only `'absent'` skips the ledger mechanism entirely (pre-adoption).
|
|
534
|
+
const verificationLedger = ledgerRead.entries;
|
|
535
|
+
let ledgerDirty = false;
|
|
536
|
+
for (const winner of ledgerWinnerByKey.values()) {
|
|
537
|
+
if (winner.liveVerificationStatus === 'missing')
|
|
538
|
+
continue;
|
|
539
|
+
if (verificationLedger[winner.phaseKey] !== winner.liveVerificationStatus) {
|
|
540
|
+
verificationLedger[winner.phaseKey] = winner.liveVerificationStatus;
|
|
541
|
+
ledgerDirty = true;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
// A `'corrupt'` read that observes no real verdict this call has nothing to
|
|
545
|
+
// repair with — writing an empty `{}` would DESTROY whatever the corrupt
|
|
546
|
+
// file's bytes might still hold (a human could recover it by hand; this
|
|
547
|
+
// fix must not foreclose that). Only write when there is something real to
|
|
548
|
+
// persist, exactly as for `'absent'`/`'ok'`.
|
|
549
|
+
if (ledgerDirty)
|
|
550
|
+
writeVerificationLedger(wsDir, verificationLedger);
|
|
551
|
+
const phaseFilesCounts = rawPhaseEntries.map(entry => {
|
|
552
|
+
const isLedgerWinner = ledgerWinnerByKey.get(entry.phaseKey) === entry;
|
|
553
|
+
let verificationStatus = entry.liveVerificationStatus;
|
|
554
|
+
if (entry.liveVerificationStatus === 'missing' && isLedgerWinner) {
|
|
555
|
+
if (ledgerRead.state === 'absent') {
|
|
556
|
+
// State 1: pre-adoption. Exactly today's behavior — 'missing' is
|
|
557
|
+
// NOT in FAILING_VERIFICATION_STATUSES, so this does not gate.
|
|
558
|
+
verificationStatus = 'missing';
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
// States 2/3 ('corrupt' or 'ok'): this workstream has adopted the
|
|
562
|
+
// ledger. A remembered entry wins; no entry fails CLOSED to the
|
|
563
|
+
// 'unrecorded' sentinel rather than falling open to 'missing'.
|
|
564
|
+
const remembered = verificationLedger[entry.phaseKey];
|
|
565
|
+
verificationStatus = remembered !== undefined ? remembered : 'unrecorded';
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return {
|
|
569
|
+
directory: entry.directory,
|
|
570
|
+
phaseKey: entry.phaseKey,
|
|
571
|
+
mtimeMs: entry.mtimeMs,
|
|
572
|
+
planCount: entry.planCount,
|
|
573
|
+
summaryCount: entry.summaryCount,
|
|
574
|
+
inMilestone: entry.inMilestone,
|
|
575
|
+
verificationStatus,
|
|
576
|
+
};
|
|
114
577
|
});
|
|
578
|
+
// The denominator is the union of what the roadmap DECLARES for the current
|
|
579
|
+
// milestone (including never-scaffolded phases) and the keys of the member
|
|
580
|
+
// directories (including dir-only sub-phases). One key space, so
|
|
581
|
+
// `completed_phases <= denominator` holds by construction rather than by a
|
|
582
|
+
// `Math.min` cap that hid the inconsistency.
|
|
583
|
+
const milestoneKeys = new Set(currentMilestoneKeys);
|
|
584
|
+
for (const entry of phaseFilesCounts) {
|
|
585
|
+
if (entry.inMilestone)
|
|
586
|
+
milestoneKeys.add(entry.phaseKey);
|
|
587
|
+
}
|
|
588
|
+
const currentMilestonePhaseCount = scoped
|
|
589
|
+
? Math.max(milestoneKeys.size, headingScoped ? headingFilter.phaseCount : 0)
|
|
590
|
+
: 0;
|
|
591
|
+
// Unscoped fallback: the denominator must STILL count phases the ROADMAP
|
|
592
|
+
// declares in its Progress table but never scaffolded — the heading-only
|
|
593
|
+
// count drops them, even when other headings exist. Union the declared rows
|
|
594
|
+
// with the phase directories so neither source can silently shrink it.
|
|
595
|
+
let fallbackPhaseCount = countRoadmapPhases(p.roadmap, phaseDirNames.length);
|
|
596
|
+
if (!scoped && progressRows.length > 0) {
|
|
597
|
+
const union = new Set(progressRows.map(row => row.key));
|
|
598
|
+
for (const entry of phaseFilesCounts)
|
|
599
|
+
union.add(entry.phaseKey);
|
|
600
|
+
fallbackPhaseCount = union.size;
|
|
601
|
+
}
|
|
115
602
|
return (0, workstream_inventory_builder_cjs_1.buildWorkstreamInventory)({
|
|
116
603
|
name,
|
|
117
604
|
projectDir: cwd,
|
|
@@ -119,14 +606,19 @@ function inspectWorkstream(cwd, name, options = {}) {
|
|
|
119
606
|
phaseDirNames,
|
|
120
607
|
activeWorkstreamName: activeWorkstreamName ?? '',
|
|
121
608
|
phaseFilesCounts,
|
|
122
|
-
roadmapPhaseCount:
|
|
609
|
+
roadmapPhaseCount: fallbackPhaseCount,
|
|
610
|
+
currentMilestonePhaseCount,
|
|
611
|
+
// Stated, not inferred from the count: a declared-but-empty current
|
|
612
|
+
// milestone is legitimately scoped AND legitimately zero-phase, and the
|
|
613
|
+
// builder cannot tell those apart from `currentMilestonePhaseCount` alone.
|
|
614
|
+
milestoneScoped: scoped,
|
|
123
615
|
stateProjection: readStateProjection(p.state),
|
|
124
616
|
filesExist: {
|
|
125
617
|
roadmap: node_fs_1.default.existsSync(p.roadmap),
|
|
126
618
|
state: node_fs_1.default.existsSync(p.state),
|
|
127
619
|
requirements: node_fs_1.default.existsSync(p.requirements),
|
|
128
620
|
},
|
|
129
|
-
|
|
621
|
+
milestoneShippedSignal: workstreamShippedSignal(p.roadmap, p.planning, currentVersion),
|
|
130
622
|
});
|
|
131
623
|
}
|
|
132
624
|
function listWorkstreamInventories(cwd) {
|
|
@@ -207,6 +207,10 @@ function cmdWorkstreamList(cwd, raw) {
|
|
|
207
207
|
has_roadmap: ws.files.roadmap,
|
|
208
208
|
has_state: ws.files.state,
|
|
209
209
|
status: ws.status,
|
|
210
|
+
// #2562: a refused shipped marker must reach the surface. Projecting
|
|
211
|
+
// `status` without it renders the refusal invisible at the CLI, which is
|
|
212
|
+
// the silent-collapse defect this issue is about.
|
|
213
|
+
milestone_shipped_unverified: ws.milestone_shipped_unverified,
|
|
210
214
|
current_phase: ws.current_phase,
|
|
211
215
|
phase_count: ws.phase_count,
|
|
212
216
|
completed_phases: ws.completed_phases,
|
|
@@ -241,6 +245,7 @@ function cmdWorkstreamStatus(cwd, name, raw) {
|
|
|
241
245
|
phase_count: inv.phase_count,
|
|
242
246
|
completed_phases: inv.completed_phases,
|
|
243
247
|
status: inv.status,
|
|
248
|
+
milestone_shipped_unverified: inv.milestone_shipped_unverified,
|
|
244
249
|
current_phase: inv.current_phase,
|
|
245
250
|
last_activity: inv.last_activity,
|
|
246
251
|
}, raw, undefined);
|
|
@@ -353,6 +358,7 @@ function cmdWorkstreamProgress(cwd, raw) {
|
|
|
353
358
|
name: ws.name,
|
|
354
359
|
active: ws.active,
|
|
355
360
|
status: ws.status,
|
|
361
|
+
milestone_shipped_unverified: ws.milestone_shipped_unverified,
|
|
356
362
|
current_phase: ws.current_phase ?? null,
|
|
357
363
|
phases: `${ws.completed_phases}/${ws.roadmap_phase_count}`,
|
|
358
364
|
plans: `${ws.completed_plans}/${ws.total_plans}`,
|