@opengsd/gsd-pi 1.7.0 → 1.8.1
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/README.md +8 -6
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/gsd/doctor-history.js +65 -0
- package/dist/resources/extensions/gsd/doctor-state-checks.js +509 -0
- package/dist/resources/extensions/gsd/doctor-workspace-checks.js +91 -0
- package/dist/resources/extensions/gsd/doctor.js +14 -653
- package/dist/resources/extensions/gsd/md-importer.js +7 -2
- package/dist/resources/extensions/gsd/migrate/planning-writer.js +8 -2
- package/dist/resources/extensions/gsd/migration-auto-check.js +4 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/project-md.js +54 -14
- package/dist/resources/extensions/gsd/state-reconciliation/drift/sketch-flag.js +48 -5
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/node_modules/@gsd/native/package.json +1 -1
- package/dist/web/standalone/node_modules/node-pty/build/Makefile +2 -2
- package/dist/web/standalone/node_modules/node-pty/build/Release/pty.node +0 -0
- package/dist/web/standalone/node_modules/node-pty/build/pty.target.mk +14 -14
- package/integrations/hermes/open_gsd_hermes/gsd_client.py +1 -1
- package/integrations/hermes/pyproject.toml +1 -1
- package/package.json +6 -6
- package/packages/cloud-mcp-gateway/package.json +2 -2
- package/packages/contracts/package.json +1 -1
- package/packages/daemon/dist/cloud-config.d.ts.map +1 -1
- package/packages/daemon/dist/cloud-config.js +25 -7
- package/packages/daemon/dist/cloud-config.js.map +1 -1
- package/packages/daemon/dist/cloud-config.test.js +19 -1
- package/packages/daemon/dist/cloud-config.test.js.map +1 -1
- package/packages/daemon/package.json +4 -4
- package/packages/gsd-agent-core/package.json +5 -5
- package/packages/gsd-agent-modes/package.json +7 -7
- package/packages/gsd-cloud/README.md +18 -4
- package/packages/gsd-cloud/bin/gsd-cloud.js +6 -5
- package/packages/gsd-cloud/package.json +6 -4
- package/packages/mcp-server/package.json +4 -4
- package/packages/native/package.json +1 -1
- package/packages/pi-agent-core/package.json +1 -1
- package/packages/pi-ai/package.json +1 -1
- package/packages/pi-coding-agent/package.json +7 -7
- package/packages/pi-tui/package.json +2 -2
- package/packages/rpc-client/package.json +2 -2
- package/pkg/package.json +1 -1
- package/src/resources/extensions/gsd/doctor-history.ts +81 -0
- package/src/resources/extensions/gsd/doctor-state-checks.ts +527 -0
- package/src/resources/extensions/gsd/doctor-workspace-checks.ts +97 -0
- package/src/resources/extensions/gsd/doctor.ts +14 -673
- package/src/resources/extensions/gsd/md-importer.ts +7 -2
- package/src/resources/extensions/gsd/migrate/planning-writer.ts +9 -3
- package/src/resources/extensions/gsd/migration-auto-check.ts +3 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/project-md.ts +67 -20
- package/src/resources/extensions/gsd/state-reconciliation/drift/sketch-flag.ts +47 -5
- package/src/resources/extensions/gsd/tests/db-authority-regression.test.ts +76 -1
- package/src/resources/extensions/gsd/tests/doctor-history-public-api.test.ts +25 -0
- package/src/resources/extensions/gsd/tests/migrate-hierarchy.test.ts +53 -0
- package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +53 -0
- package/src/resources/extensions/gsd/tests/parsers-legacy-importers.test.ts +4 -0
- package/src/resources/extensions/gsd/tests/planning-writer.test.ts +18 -1
- package/src/resources/extensions/gsd/tests/progressive-planning.test.ts +18 -3
- package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +177 -25
- /package/dist/web/standalone/.next/static/{enWQFRY-aLTUq3wmxG2Qz → UaXRrOYxBpG9QBINKhZkg}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{enWQFRY-aLTUq3wmxG2Qz → UaXRrOYxBpG9QBINKhZkg}/_ssgManifest.js +0 -0
|
@@ -810,8 +810,13 @@ export function migrateHierarchyToDb(basePath: string): {
|
|
|
810
810
|
}
|
|
811
811
|
counts.slices++;
|
|
812
812
|
|
|
813
|
-
// Insert tasks from parsed plan
|
|
814
|
-
|
|
813
|
+
// Insert tasks from parsed plan.
|
|
814
|
+
// Sketch slices carry only a stub PLAN until refined; do not seed DB
|
|
815
|
+
// tasks from a placeholder <tasks> block (would falsely flip
|
|
816
|
+
// planning -> executing before the slice is decomposed). Once the
|
|
817
|
+
// `[sketch]` badge is removed by a real plan-slice, tasks import
|
|
818
|
+
// normally on the next pass. (#1286)
|
|
819
|
+
if (!plan || sliceEntry.isSketch) continue;
|
|
815
820
|
|
|
816
821
|
for (const taskEntry of plan.tasks) {
|
|
817
822
|
// Per K002: use 'complete' not 'done'
|
|
@@ -11,6 +11,7 @@ import { join, relative } from "node:path";
|
|
|
11
11
|
|
|
12
12
|
import { getAllMilestones, getMilestoneSlices, getSliceTasks } from "../gsd-db.js";
|
|
13
13
|
import { saveFile } from "../files.js";
|
|
14
|
+
import { isClosedStatus } from "../status-guards.js";
|
|
14
15
|
import type { PlanningLayout } from "../compat/compat-marker.js";
|
|
15
16
|
import {
|
|
16
17
|
applyPlanningProjectionWrites,
|
|
@@ -104,7 +105,7 @@ function formatPlanningPlan(
|
|
|
104
105
|
phaseNum: number,
|
|
105
106
|
planNum: number,
|
|
106
107
|
title: string,
|
|
107
|
-
tasks: Array<{ id: string; title: string; estimate?: string }>,
|
|
108
|
+
tasks: Array<{ id: string; title: string; estimate?: string; done?: boolean }>,
|
|
108
109
|
): string {
|
|
109
110
|
const lines: string[] = [];
|
|
110
111
|
lines.push(`# ${pad(phaseNum)}-${pad(planNum)}: ${title}`, "");
|
|
@@ -115,7 +116,11 @@ function formatPlanningPlan(
|
|
|
115
116
|
lines.push("<tasks>");
|
|
116
117
|
for (const t of tasks) {
|
|
117
118
|
const est = t.estimate ? ` _(${t.estimate})_` : "";
|
|
118
|
-
|
|
119
|
+
// Render the checkbox from the task's DB status so a DB→.planning
|
|
120
|
+
// projection preserves completion. Hardcoding `[ ]` here silently reset
|
|
121
|
+
// every completed historical task to unchecked on each reconcile (#1276).
|
|
122
|
+
const box = t.done ? "[x]" : "[ ]";
|
|
123
|
+
lines.push(`- ${box} **${t.id}**: ${t.title}${est}`);
|
|
119
124
|
}
|
|
120
125
|
lines.push("</tasks>");
|
|
121
126
|
lines.push("");
|
|
@@ -173,7 +178,7 @@ export async function writePlanningDirectory(
|
|
|
173
178
|
|
|
174
179
|
const tasks = getSliceTasks(milestone.id, slice.id);
|
|
175
180
|
const isDone =
|
|
176
|
-
tasks.length > 0 && tasks.every((t) => t.status
|
|
181
|
+
tasks.length > 0 && tasks.every((t) => isClosedStatus(t.status));
|
|
177
182
|
roadmapEntries.push({
|
|
178
183
|
number: phaseNum,
|
|
179
184
|
title: slice.title || slice.id,
|
|
@@ -204,6 +209,7 @@ export async function writePlanningDirectory(
|
|
|
204
209
|
id: task.id,
|
|
205
210
|
title: task.title || task.id,
|
|
206
211
|
estimate: task.estimate || undefined,
|
|
212
|
+
done: isClosedStatus(task.status),
|
|
207
213
|
},
|
|
208
214
|
]),
|
|
209
215
|
);
|
|
@@ -169,6 +169,9 @@ export function scanMarkdownHierarchy(basePath: string): HierarchyScan {
|
|
|
169
169
|
|
|
170
170
|
for (const slice of roadmap.slices) {
|
|
171
171
|
scan.slices.add(`${milestoneId}/${slice.id}`);
|
|
172
|
+
// Sketch slices carry only a stub PLAN until refined; match migrateHierarchyToDb
|
|
173
|
+
// and do not count placeholder tasks from the <tasks> block (#1286).
|
|
174
|
+
if (slice.isSketch) continue;
|
|
172
175
|
const planPath = resolveSliceFile(basePath, milestoneId, slice.id, "PLAN");
|
|
173
176
|
if (!planPath || !existsSync(planPath)) continue;
|
|
174
177
|
const plan = parsePlan(readFileSync(planPath, "utf-8"));
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
9
|
|
|
10
|
-
import { getMilestone, isDbAvailable } from "../../gsd-db.js";
|
|
11
|
-
import { findMilestoneIds } from "../../milestone-ids.js";
|
|
10
|
+
import { getAllMilestones, getMilestone, isDbAvailable } from "../../gsd-db.js";
|
|
11
|
+
import { findMilestoneIds, parseMilestoneId } from "../../milestone-ids.js";
|
|
12
12
|
import { resolveMilestoneFile, resolveMilestonePath } from "../../paths.js";
|
|
13
13
|
import type { GSDState } from "../../types.js";
|
|
14
14
|
import type { DriftContext, DriftHandler, DriftRecord } from "../types.js";
|
|
@@ -29,6 +29,26 @@ function milestoneHasContent(basePath: string, milestoneId: string): boolean {
|
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* A directory extracted to a bare `M{NNN}` id is not unregistered when the
|
|
34
|
+
* milestone is actually registered under a `unique_milestone_ids` suffixed id
|
|
35
|
+
* (`M{NNN}-<suffix>`) for the same sequence number. The flat-phase extractor in
|
|
36
|
+
* `milestone-ids` cannot recover the suffix from a descriptive slug (e.g.
|
|
37
|
+
* `07-v40fmq-m007-...-footer-system`), so it falls through to the bare `M007`.
|
|
38
|
+
* Probing the DB for a suffixed row on that sequence resolves the directory to
|
|
39
|
+
* its registered identity instead of firing a false-positive drift (issue
|
|
40
|
+
* #1281).
|
|
41
|
+
*/
|
|
42
|
+
function hasRegisteredSuffixedVariant(milestoneId: string): boolean {
|
|
43
|
+
const { suffix, num } = parseMilestoneId(milestoneId);
|
|
44
|
+
// Only bare, well-formed `M{NNN}` ids can be ambiguous with a suffixed row.
|
|
45
|
+
if (suffix || num === 0) return false;
|
|
46
|
+
return getAllMilestones().some((m) => {
|
|
47
|
+
const parsed = parseMilestoneId(m.id);
|
|
48
|
+
return parsed.num === num && parsed.suffix !== undefined;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
export function detectUnregisteredMilestoneDrift(
|
|
33
53
|
_state: GSDState,
|
|
34
54
|
ctx: DriftContext,
|
|
@@ -38,6 +58,7 @@ export function detectUnregisteredMilestoneDrift(
|
|
|
38
58
|
const drifts: UnregisteredMilestoneDrift[] = [];
|
|
39
59
|
for (const milestoneId of findMilestoneIds(ctx.basePath)) {
|
|
40
60
|
if (getMilestone(milestoneId)) continue;
|
|
61
|
+
if (hasRegisteredSuffixedVariant(milestoneId)) continue;
|
|
41
62
|
if (!milestoneHasContent(ctx.basePath, milestoneId)) continue;
|
|
42
63
|
drifts.push({ kind: "unregistered-milestone", milestoneId });
|
|
43
64
|
}
|
|
@@ -45,35 +66,61 @@ export function detectUnregisteredMilestoneDrift(
|
|
|
45
66
|
}
|
|
46
67
|
|
|
47
68
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* directory — not a full DB reimport. `/gsd recover --confirm` is a destructive
|
|
56
|
-
* clear-and-reimport of the entire DB and is offered only as a last resort, so
|
|
57
|
-
* users do not reach for it expecting a targeted repair (see issue #826).
|
|
69
|
+
* The recovery hint deliberately leads with the *targeted*, non-destructive
|
|
70
|
+
* options. The common cause of this drift is a directory left under an old ID
|
|
71
|
+
* after a `unique_milestone_ids` rename, where the right fix is to rename (move)
|
|
72
|
+
* the directory — not a full DB reimport. `/gsd recover --confirm` is a
|
|
73
|
+
* destructive clear-and-reimport of the entire DB and is offered only as a last
|
|
74
|
+
* resort, so users do not reach for it expecting a targeted repair (see issue
|
|
75
|
+
* #826).
|
|
58
76
|
*/
|
|
59
|
-
|
|
77
|
+
function unregisteredMilestoneGuidance(
|
|
60
78
|
record: UnregisteredMilestoneDrift,
|
|
61
79
|
ctx: DriftContext,
|
|
62
|
-
):
|
|
80
|
+
): string {
|
|
63
81
|
const dir = resolveMilestonePath(ctx.basePath, record.milestoneId);
|
|
64
82
|
const dirHint = dir ?? `the .gsd directory for ${record.milestoneId}`;
|
|
65
|
-
|
|
83
|
+
return (
|
|
66
84
|
`Milestone ${record.milestoneId} exists only as markdown projection ` +
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
"(on-disk ROADMAP/CONTEXT/SUMMARY with no authoritative DB row). " +
|
|
86
|
+
"Runtime reconciliation will not import markdown into the DB. Choose one:\n" +
|
|
87
|
+
` • Rename: if this directory is the same milestone under an old ID (e.g. a unique_milestone_ids rename), move \`${dirHint}\` to the current ID's directory and re-run.\n` +
|
|
88
|
+
` • Discard: if this milestone is no longer relevant, delete \`${dirHint}\` and re-run.\n` +
|
|
89
|
+
" • Last resort: `/gsd recover --confirm` performs a destructive full DB clear-and-reimport — it does NOT do a targeted import and can replace or duplicate existing DB milestones."
|
|
72
90
|
);
|
|
73
91
|
}
|
|
74
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Terminal blocker for an unregistered milestone. The project-root DB is
|
|
95
|
+
* authoritative at runtime; markdown-only milestones must be reconciled through
|
|
96
|
+
* an explicit, operator-controlled action so operators opt into changing
|
|
97
|
+
* canonical state. Exposing this as a `blocker` (matching the `artifact-db`
|
|
98
|
+
* convention) surfaces the drift as a pause-with-hint that gates dispatch,
|
|
99
|
+
* instead of a guaranteed repair throw that escalates auto-mode health to red
|
|
100
|
+
* (see issue #1281).
|
|
101
|
+
*/
|
|
102
|
+
export function describeUnregisteredMilestoneBlocker(
|
|
103
|
+
record: UnregisteredMilestoneDrift,
|
|
104
|
+
ctx: DriftContext,
|
|
105
|
+
): string {
|
|
106
|
+
return unregisteredMilestoneGuidance(record, ctx);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Repair intentionally fails closed. Retained as a defensive fallback for the
|
|
111
|
+
* reconciliation engine; in practice `blocker` short-circuits this drift into a
|
|
112
|
+
* non-fatal pause before repair is ever attempted.
|
|
113
|
+
*/
|
|
114
|
+
export function repairUnregisteredMilestone(
|
|
115
|
+
record: UnregisteredMilestoneDrift,
|
|
116
|
+
ctx: DriftContext,
|
|
117
|
+
): void {
|
|
118
|
+
throw new Error(unregisteredMilestoneGuidance(record, ctx));
|
|
119
|
+
}
|
|
120
|
+
|
|
75
121
|
export const unregisteredMilestoneHandler: DriftHandler<UnregisteredMilestoneDrift> = {
|
|
76
122
|
kind: "unregistered-milestone",
|
|
77
123
|
detect: detectUnregisteredMilestoneDrift,
|
|
124
|
+
blocker: describeUnregisteredMilestoneBlocker,
|
|
78
125
|
repair: repairUnregisteredMilestone,
|
|
79
126
|
};
|
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
// sketch slices to plan-slice, which writes PLAN.md but leaves
|
|
9
9
|
// is_sketch=1 — the next reconciliation pass clears it.
|
|
10
10
|
|
|
11
|
-
import { existsSync } from "node:fs";
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
14
|
getSketchedSliceIds,
|
|
15
15
|
isDbAvailable,
|
|
16
16
|
setSliceSketchFlag,
|
|
17
17
|
} from "../../gsd-db.js";
|
|
18
|
+
import { parsePlan } from "../../parsers-legacy.js";
|
|
18
19
|
import { resolveSliceFile } from "../../paths.js";
|
|
19
20
|
import type { GSDState } from "../../types.js";
|
|
20
21
|
import type { DriftContext, DriftHandler, DriftRecord } from "../types.js";
|
|
@@ -31,13 +32,54 @@ export function detectStaleSketchFlags(
|
|
|
31
32
|
|
|
32
33
|
const sliceIds = getSketchedSliceIds(mid);
|
|
33
34
|
return sliceIds
|
|
34
|
-
.filter((sid) =>
|
|
35
|
-
const planPath = resolveSliceFile(ctx.basePath, mid, sid, "PLAN");
|
|
36
|
-
return planPath !== null && existsSync(planPath);
|
|
37
|
-
})
|
|
35
|
+
.filter((sid) => sketchIsPlanned(ctx.basePath, mid, sid))
|
|
38
36
|
.map((sid) => ({ kind: "stale-sketch-flag" as const, mid, sid }));
|
|
39
37
|
}
|
|
40
38
|
|
|
39
|
+
/**
|
|
40
|
+
* True when a task title is a synthetic placeholder emitted by a projection
|
|
41
|
+
* round-trip rather than a real, refined task. `migrate/transformer.buildTaskTitle`
|
|
42
|
+
* produces two shapes when a plan was never decomposed:
|
|
43
|
+
* - `Plan NN` (fallback when phase/plan frontmatter is absent)
|
|
44
|
+
* - `${phase} ${plan}` (e.g. `00 01`, `00 03b`, `29-auth-system 01`)
|
|
45
|
+
* Neither carries genuine planning intent, so both must be treated as stubs.
|
|
46
|
+
*/
|
|
47
|
+
function isPlaceholderTaskTitle(title: string): boolean {
|
|
48
|
+
const t = title.trim();
|
|
49
|
+
if (/^Plan\s+\d+[a-z]*$/i.test(t)) return true;
|
|
50
|
+
// buildTaskTitle returns `${phase} ${plan}` when frontmatter has both fields.
|
|
51
|
+
// Phase slugs are digit-led (e.g. `00`, `29-auth-system`); require that so
|
|
52
|
+
// legitimate titles like `Step 1` are not misclassified as stubs.
|
|
53
|
+
return /^\d[\w-]*\s+\d+[a-z]*$/i.test(t);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A sketch slice counts as "planned" (so its is_sketch flag may be cleared)
|
|
58
|
+
* only when it has a *real* plan on disk — not merely any PLAN file.
|
|
59
|
+
*
|
|
60
|
+
* File existence alone (#1287) is too weak: a stub/placeholder PLAN, a
|
|
61
|
+
* crash-leftover, or a projection round-trip that emits synthetic placeholder
|
|
62
|
+
* task titles (migrate/transformer.buildTaskTitle) all satisfy existsSync yet
|
|
63
|
+
* were never actually refined. Clearing the flag for one strips the `refining`
|
|
64
|
+
* guard in phase derivation and lets a phantom task drive dispatch.
|
|
65
|
+
*
|
|
66
|
+
* A legitimate plan-slice always decomposes into >= 1 genuine task, so require
|
|
67
|
+
* at least one non-placeholder task. This is strictly stricter than the old
|
|
68
|
+
* existence check — the documented crash-recovery scenarios (a real plan-slice
|
|
69
|
+
* that wrote its tasks) still clear, a bare stub no longer does.
|
|
70
|
+
*/
|
|
71
|
+
function sketchIsPlanned(basePath: string, mid: string, sid: string): boolean {
|
|
72
|
+
const planPath = resolveSliceFile(basePath, mid, sid, "PLAN");
|
|
73
|
+
if (planPath === null || !existsSync(planPath)) return false;
|
|
74
|
+
try {
|
|
75
|
+
const plan = parsePlan(readFileSync(planPath, "utf-8"));
|
|
76
|
+
return plan.tasks.some((t) => !isPlaceholderTaskTitle(t.title));
|
|
77
|
+
} catch {
|
|
78
|
+
// A PLAN we cannot parse is not a trustworthy "planning done" signal.
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
41
83
|
export function repairStaleSketchFlag(record: SketchFlagDrift): void {
|
|
42
84
|
setSliceSketchFlag(record.mid, record.sid, false);
|
|
43
85
|
}
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
openDatabase,
|
|
18
18
|
} from "../gsd-db.ts";
|
|
19
19
|
import { migrateHierarchyToDb } from "../md-importer.ts";
|
|
20
|
-
import { checkMarkdownHierarchyAgainstDb } from "../migration-auto-check.ts";
|
|
20
|
+
import { checkMarkdownHierarchyAgainstDb, countMarkdownHierarchy } from "../migration-auto-check.ts";
|
|
21
21
|
import { queryDecisions } from "../context-store.ts";
|
|
22
22
|
import { deriveStateFromDb, invalidateStateCache } from "../state.ts";
|
|
23
23
|
import type { Requirement } from "../types.ts";
|
|
@@ -206,3 +206,78 @@ test("explicit markdown import remains opt-in and is not run by startup mismatch
|
|
|
206
206
|
assert.equal(getAllMilestones().length, 1);
|
|
207
207
|
assert.equal(getSliceTasks("M001", "S01").length, 1);
|
|
208
208
|
});
|
|
209
|
+
|
|
210
|
+
// #1286: migrateHierarchyToDb skips a `[sketch]` slice's stub PLAN tasks, so
|
|
211
|
+
// scanMarkdownHierarchy must skip counting them too. Otherwise the markdown
|
|
212
|
+
// scan claims task rows the DB authoritatively omits, and the startup drift
|
|
213
|
+
// check perpetually reports recovery-required / recommends
|
|
214
|
+
// `/gsd recover --confirm` — which re-skips the stub tasks and never converges.
|
|
215
|
+
test("sketch slice stub tasks are not treated as markdown/DB drift", async (t) => {
|
|
216
|
+
const base = makeBase();
|
|
217
|
+
t.after(() => cleanup(base));
|
|
218
|
+
|
|
219
|
+
const milestoneDir = join(base, ".gsd", "milestones", "M001");
|
|
220
|
+
const sketchSliceDir = join(milestoneDir, "slices", "S01");
|
|
221
|
+
const realSliceDir = join(milestoneDir, "slices", "S02");
|
|
222
|
+
mkdirSync(sketchSliceDir, { recursive: true });
|
|
223
|
+
mkdirSync(realSliceDir, { recursive: true });
|
|
224
|
+
|
|
225
|
+
// S01 is a sketch (badge before risk, per ADR-011 render); S02 is refined.
|
|
226
|
+
writeFileSync(
|
|
227
|
+
join(milestoneDir, "M001-ROADMAP.md"),
|
|
228
|
+
[
|
|
229
|
+
"# M001: Sketch Drift",
|
|
230
|
+
"",
|
|
231
|
+
"**Vision:** Sketch stub tasks must not count as drift",
|
|
232
|
+
"",
|
|
233
|
+
"## Slices",
|
|
234
|
+
"- [ ] **S01: Sketch Slice** `[sketch]` `risk:low` `depends:[]`",
|
|
235
|
+
" > After this: Sketch decomposed.",
|
|
236
|
+
"",
|
|
237
|
+
"- [ ] **S02: Real Slice** `risk:low` `depends:[]`",
|
|
238
|
+
" > After this: Real work done.",
|
|
239
|
+
"",
|
|
240
|
+
].join("\n"),
|
|
241
|
+
);
|
|
242
|
+
// The sketch slice still carries a stub PLAN with a placeholder <tasks> block.
|
|
243
|
+
writeFileSync(
|
|
244
|
+
join(sketchSliceDir, "S01-PLAN.md"),
|
|
245
|
+
[
|
|
246
|
+
"# S01: Sketch Slice",
|
|
247
|
+
"",
|
|
248
|
+
"**Goal:** Placeholder.",
|
|
249
|
+
"",
|
|
250
|
+
"## Tasks",
|
|
251
|
+
"- [ ] **T01: Plan 01**",
|
|
252
|
+
" Stub placeholder task.",
|
|
253
|
+
"",
|
|
254
|
+
].join("\n"),
|
|
255
|
+
);
|
|
256
|
+
writeFileSync(
|
|
257
|
+
join(realSliceDir, "S02-PLAN.md"),
|
|
258
|
+
[
|
|
259
|
+
"# S02: Real Slice",
|
|
260
|
+
"",
|
|
261
|
+
"**Goal:** Real work.",
|
|
262
|
+
"",
|
|
263
|
+
"## Tasks",
|
|
264
|
+
"- [ ] **T01: Task** `est:5m`",
|
|
265
|
+
"",
|
|
266
|
+
].join("\n"),
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
openProjectDb(base);
|
|
270
|
+
// The importer seeds S02's task but skips S01's stub (1 task total).
|
|
271
|
+
const imported = migrateHierarchyToDb(base);
|
|
272
|
+
assert.deepEqual(imported, { milestones: 1, slices: 2, tasks: 1 });
|
|
273
|
+
assert.equal(getSliceTasks("M001", "S01").length, 0, "sketch slice seeds no tasks");
|
|
274
|
+
assert.equal(getSliceTasks("M001", "S02").length, 1, "real slice seeds its task");
|
|
275
|
+
|
|
276
|
+
// The markdown scan must mirror the importer: the sketch stub task is not
|
|
277
|
+
// counted, so markdown (1 task) matches the DB (1 task) and the check is
|
|
278
|
+
// in-sync rather than recommending a recover that would never converge.
|
|
279
|
+
assert.deepEqual(countMarkdownHierarchy(base), { milestones: 1, slices: 2, tasks: 1 });
|
|
280
|
+
const check = await checkMarkdownHierarchyAgainstDb(base);
|
|
281
|
+
assert.equal(check.action, "none", "sketch stub tasks must not be flagged as drift");
|
|
282
|
+
assert.equal(check.reason, "in-sync");
|
|
283
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
import { readDoctorHistory, runGSDDoctor, type DoctorHistoryEntry } from "../doctor.ts";
|
|
8
|
+
|
|
9
|
+
test("doctor.ts preserves readDoctorHistory public API and records doctor runs", async (t) => {
|
|
10
|
+
const base = mkdtempSync(join(tmpdir(), "gsd-doctor-history-api-"));
|
|
11
|
+
mkdirSync(join(base, ".gsd"), { recursive: true });
|
|
12
|
+
|
|
13
|
+
t.after(() => rmSync(base, { recursive: true, force: true }));
|
|
14
|
+
|
|
15
|
+
const report = await runGSDDoctor(base, { fix: false });
|
|
16
|
+
const history: DoctorHistoryEntry[] = await readDoctorHistory(base, 1);
|
|
17
|
+
|
|
18
|
+
assert.equal(history.length, 1);
|
|
19
|
+
assert.equal(history[0].ok, report.ok);
|
|
20
|
+
assert.equal(history[0].errors, report.issues.filter(issue => issue.severity === "error").length);
|
|
21
|
+
assert.equal(history[0].warnings, report.issues.filter(issue => issue.severity === "warning").length);
|
|
22
|
+
assert.equal(history[0].fixes, 0);
|
|
23
|
+
assert.ok(Array.isArray(history[0].codes));
|
|
24
|
+
assert.equal(typeof history[0].summary, "string");
|
|
25
|
+
});
|
|
@@ -427,3 +427,56 @@ test('migrate-hier: demo text extracted', () => {
|
|
|
427
427
|
}
|
|
428
428
|
});
|
|
429
429
|
|
|
430
|
+
// ─── Test (i): Sketch slice stub tasks are not seeded (#1286) ─────────
|
|
431
|
+
|
|
432
|
+
test('migrate-hier: sketch slice stub PLAN tasks are not imported', () => {
|
|
433
|
+
const base = createFixtureBase();
|
|
434
|
+
try {
|
|
435
|
+
// S01 is a sketch (badge before risk, per ADR-011 render); its PLAN is a
|
|
436
|
+
// stub with a placeholder <tasks> block. S02 is a real, refined slice.
|
|
437
|
+
const roadmap = `# M001: Test Milestone
|
|
438
|
+
|
|
439
|
+
**Vision:** Sketch slices must not seed DB tasks.
|
|
440
|
+
|
|
441
|
+
## Slices
|
|
442
|
+
|
|
443
|
+
- [ ] **S01: Sketch Slice** \`[sketch]\` \`risk:low\` \`depends:[]\`
|
|
444
|
+
> After this: Sketch decomposed.
|
|
445
|
+
|
|
446
|
+
- [ ] **S02: Real Slice** \`risk:low\` \`depends:[]\`
|
|
447
|
+
> After this: Real work done.
|
|
448
|
+
`;
|
|
449
|
+
const sketchPlan = `# S01: Sketch Slice
|
|
450
|
+
|
|
451
|
+
**Goal:** Placeholder.
|
|
452
|
+
|
|
453
|
+
## Tasks
|
|
454
|
+
|
|
455
|
+
- [ ] **T01: Plan 01**
|
|
456
|
+
Stub placeholder task.
|
|
457
|
+
`;
|
|
458
|
+
writeFile(base, 'milestones/M001/M001-ROADMAP.md', roadmap);
|
|
459
|
+
writeFile(base, 'milestones/M001/slices/S01/S01-PLAN.md', sketchPlan);
|
|
460
|
+
writeFile(base, 'milestones/M001/slices/S02/S02-PLAN.md', PLAN_S02_1_TASK);
|
|
461
|
+
|
|
462
|
+
openDatabase(':memory:');
|
|
463
|
+
const counts = migrateHierarchyToDb(base);
|
|
464
|
+
|
|
465
|
+
const slices = getMilestoneSlices('M001');
|
|
466
|
+
assert.deepStrictEqual(slices.length, 2, 'sketch: 2 slices inserted');
|
|
467
|
+
assert.deepStrictEqual(slices[0]!.is_sketch, 1, 'sketch: S01 preserves is_sketch flag');
|
|
468
|
+
|
|
469
|
+
const s01Tasks = getSliceTasks('M001', 'S01');
|
|
470
|
+
assert.deepStrictEqual(s01Tasks.length, 0, 'sketch: no stub tasks seeded for sketch slice S01');
|
|
471
|
+
|
|
472
|
+
const s02Tasks = getSliceTasks('M001', 'S02');
|
|
473
|
+
assert.deepStrictEqual(s02Tasks.length, 1, 'sketch: real slice S02 still imports its task');
|
|
474
|
+
assert.deepStrictEqual(counts.tasks, 1, 'sketch: only the non-sketch slice contributes tasks');
|
|
475
|
+
|
|
476
|
+
closeDatabase();
|
|
477
|
+
} finally {
|
|
478
|
+
closeDatabase();
|
|
479
|
+
cleanup(base);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
@@ -420,6 +420,59 @@ test("migration auto-check still reports real drift with scratch dirs excluded f
|
|
|
420
420
|
}
|
|
421
421
|
});
|
|
422
422
|
|
|
423
|
+
test("migration auto-check excludes sketch slice stub tasks from the markdown scan (#1286)", () => {
|
|
424
|
+
const base = makeBase();
|
|
425
|
+
try {
|
|
426
|
+
// S01 is a sketch (`[sketch]` badge): its PLAN is a stub carrying a
|
|
427
|
+
// placeholder <tasks> block until refinement. migrateHierarchyToDb skips
|
|
428
|
+
// seeding those stub tasks, so the markdown scan must skip them too — else
|
|
429
|
+
// the stub inflates the markdown count and reports false drift against a DB
|
|
430
|
+
// that (correctly) holds zero tasks for the sketch slice.
|
|
431
|
+
const roadmap = `# M001: Test Milestone
|
|
432
|
+
|
|
433
|
+
**Vision:** Sketch slices must not inflate markdown task counts.
|
|
434
|
+
|
|
435
|
+
## Slices
|
|
436
|
+
|
|
437
|
+
- [ ] **S01: Sketch Slice** \`[sketch]\` \`risk:low\` \`depends:[]\`
|
|
438
|
+
> After this: Sketch decomposed.
|
|
439
|
+
|
|
440
|
+
- [ ] **S02: Real Slice** \`risk:low\` \`depends:[]\`
|
|
441
|
+
> After this: Real work done.
|
|
442
|
+
`;
|
|
443
|
+
const sketchPlan = `# S01: Sketch Slice
|
|
444
|
+
|
|
445
|
+
**Goal:** Placeholder.
|
|
446
|
+
|
|
447
|
+
## Tasks
|
|
448
|
+
|
|
449
|
+
- [ ] **T01: Plan 01**
|
|
450
|
+
Stub placeholder task.
|
|
451
|
+
`;
|
|
452
|
+
const realPlan = `# S02: Real Slice
|
|
453
|
+
|
|
454
|
+
**Goal:** Real work.
|
|
455
|
+
|
|
456
|
+
## Tasks
|
|
457
|
+
|
|
458
|
+
- [ ] **T01: Real Task**
|
|
459
|
+
Real work.
|
|
460
|
+
`;
|
|
461
|
+
const milestoneDir = join(base, ".gsd", "milestones", "M001");
|
|
462
|
+
mkdirSync(join(milestoneDir, "slices", "S01"), { recursive: true });
|
|
463
|
+
mkdirSync(join(milestoneDir, "slices", "S02"), { recursive: true });
|
|
464
|
+
writeFileSync(join(milestoneDir, "M001-ROADMAP.md"), roadmap);
|
|
465
|
+
writeFileSync(join(milestoneDir, "slices", "S01", "S01-PLAN.md"), sketchPlan);
|
|
466
|
+
writeFileSync(join(milestoneDir, "slices", "S02", "S02-PLAN.md"), realPlan);
|
|
467
|
+
|
|
468
|
+
// Both slices count, but only the refined slice contributes a task; the
|
|
469
|
+
// sketch stub task is excluded, matching migrateHierarchyToDb.
|
|
470
|
+
assert.deepEqual(countMarkdownHierarchy(base), { milestones: 1, slices: 2, tasks: 1 });
|
|
471
|
+
} finally {
|
|
472
|
+
cleanup(base);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
423
476
|
test("migration auto-check still compares a roadmapless milestone that HAS a DB row", async () => {
|
|
424
477
|
const base = makeBase();
|
|
425
478
|
try {
|
|
@@ -47,6 +47,9 @@ const ALLOWED_IMPORTERS = new Set([
|
|
|
47
47
|
"gsd/migration-auto-check.ts",
|
|
48
48
|
// drift detection: compares markdown projection against DB by design
|
|
49
49
|
"gsd/state-reconciliation/drift/roadmap.ts",
|
|
50
|
+
// drift detection: reads PLAN.md tasks to distinguish a real plan from a
|
|
51
|
+
// stub before clearing a stale is_sketch flag (#1287)
|
|
52
|
+
"gsd/state-reconciliation/drift/sketch-flag.ts",
|
|
50
53
|
// stale-render detection + render verification helpers over rendered output
|
|
51
54
|
"gsd/markdown-renderer.ts",
|
|
52
55
|
// pre-migration fallback: deriveState must work before the DB exists
|
|
@@ -58,6 +61,7 @@ const ALLOWED_IMPORTERS = new Set([
|
|
|
58
61
|
"gsd/artifact-verification.ts",
|
|
59
62
|
// diagnostics-only surfaces: report on projections, make no dispatch decisions
|
|
60
63
|
"gsd/doctor.ts",
|
|
64
|
+
"gsd/doctor-state-checks.ts",
|
|
61
65
|
// diagnostics-only: compares PLAN.md task checkboxes against DB status
|
|
62
66
|
"gsd/doctor-engine-checks.ts",
|
|
63
67
|
// display/telemetry-only surfaces
|
|
@@ -8,7 +8,7 @@ import { tmpdir } from "node:os";
|
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
9
|
|
|
10
10
|
import { writePlanningDirectory } from "../migrate/planning-writer.ts";
|
|
11
|
-
import { openDatabase, closeDatabase, insertMilestone, insertSlice, insertTask } from "../gsd-db.ts";
|
|
11
|
+
import { openDatabase, closeDatabase, insertMilestone, insertSlice, insertTask, updateTaskStatus } from "../gsd-db.ts";
|
|
12
12
|
|
|
13
13
|
const tmpDirs: string[] = [];
|
|
14
14
|
function makeTmp(): string {
|
|
@@ -65,6 +65,23 @@ test("writePlanningDirectory emits phase plan file with XML structure", async ()
|
|
|
65
65
|
assert.match(plan, /<tasks>/);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
test("writePlanningDirectory renders completed task checkboxes as [x] (#1276)", async () => {
|
|
69
|
+
const base = makeTmp();
|
|
70
|
+
updateTaskStatus("M001", "S01", "T01", "complete");
|
|
71
|
+
await writePlanningDirectory(base, "flat-phases");
|
|
72
|
+
|
|
73
|
+
const phaseDir = readdirSync(join(base, ".planning", "phases"), { withFileTypes: true })
|
|
74
|
+
.filter((d) => d.isDirectory())
|
|
75
|
+
.map((d) => d.name)[0]!;
|
|
76
|
+
const planFile = readdirSync(join(base, ".planning", "phases", phaseDir))
|
|
77
|
+
.filter((f) => f.endsWith("PLAN.md"))[0]!;
|
|
78
|
+
const plan = readFileSync(join(base, ".planning", "phases", phaseDir, planFile), "utf-8");
|
|
79
|
+
assert.match(plan, /- \[x\] \*\*T01\*\*/, "completed task should project as [x], not [ ]");
|
|
80
|
+
|
|
81
|
+
const roadmap = readFileSync(join(base, ".planning", "ROADMAP.md"), "utf-8");
|
|
82
|
+
assert.match(roadmap, /- \[x\] 01 —/, "phase with all tasks complete should be [x] in ROADMAP");
|
|
83
|
+
});
|
|
84
|
+
|
|
68
85
|
test("writePlanningDirectory is idempotent: writing twice produces stable content", async () => {
|
|
69
86
|
const base = makeTmp();
|
|
70
87
|
await writePlanningDirectory(base, "flat-phases");
|
|
@@ -76,6 +76,21 @@ function writeS01Artifacts(base: string): void {
|
|
|
76
76
|
writeFileSync(join(base, ".gsd", "milestones", "M001", "slices", "S01", "S01-SUMMARY.md"), "# S01 Summary\n");
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// A *real* decomposed PLAN (>= 1 genuine task). #1287: the stale-sketch-flag
|
|
80
|
+
// detector requires a real plan — not a bare stub — before clearing is_sketch.
|
|
81
|
+
function realPlanContent(sliceId: string): string {
|
|
82
|
+
return [
|
|
83
|
+
`# ${sliceId}: Feature`,
|
|
84
|
+
"",
|
|
85
|
+
"**Goal:** Ship the feature",
|
|
86
|
+
"",
|
|
87
|
+
"## Tasks",
|
|
88
|
+
"",
|
|
89
|
+
"- [ ] **T01: Build the feature** `est:1h`",
|
|
90
|
+
"",
|
|
91
|
+
].join("\n");
|
|
92
|
+
}
|
|
93
|
+
|
|
79
94
|
function cleanup(base: string, originalCwd: string): void {
|
|
80
95
|
try { closeDatabase(); } catch { /* noop */ }
|
|
81
96
|
process.chdir(originalCwd);
|
|
@@ -185,7 +200,7 @@ test("ADR-011: existing PLAN + stale sketch flag heals via reconcileBeforeDispat
|
|
|
185
200
|
writePreferences(base, "phases:\n progressive_planning: true");
|
|
186
201
|
writeFileSync(
|
|
187
202
|
join(base, ".gsd", "milestones", "M001", "slices", "S02", "S02-PLAN.md"),
|
|
188
|
-
"
|
|
203
|
+
realPlanContent("S02"),
|
|
189
204
|
);
|
|
190
205
|
process.chdir(base);
|
|
191
206
|
|
|
@@ -252,7 +267,7 @@ test("ADR-011: reconcileBeforeDispatch auto-heals stale sketch flag when PLAN ex
|
|
|
252
267
|
// Simulate plan-slice completion where PLAN exists but is_sketch was not flipped.
|
|
253
268
|
writeFileSync(
|
|
254
269
|
join(base, ".gsd", "milestones", "M001", "slices", "S02", "S02-PLAN.md"),
|
|
255
|
-
"
|
|
270
|
+
realPlanContent("S02"),
|
|
256
271
|
);
|
|
257
272
|
process.chdir(base);
|
|
258
273
|
|
|
@@ -282,7 +297,7 @@ test("ADR-011: deriveState stays pure across worktree/canonical-root; healing be
|
|
|
282
297
|
writePreferences(base, "phases:\n skip_research: false");
|
|
283
298
|
writeFileSync(
|
|
284
299
|
join(base, ".gsd", "milestones", "M001", "slices", "S02", "S02-PLAN.md"),
|
|
285
|
-
"
|
|
300
|
+
realPlanContent("S02"),
|
|
286
301
|
);
|
|
287
302
|
const worktreePath = join(base, "worker");
|
|
288
303
|
mkdirSync(worktreePath, { recursive: true });
|