gsd-pi 2.82.0-dev.9d5798940 → 2.82.0-dev.dfbc5f58f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +2 -2
  2. package/dist/resources/.managed-resources-content-hash +1 -1
  3. package/dist/resources/GSD-WORKFLOW.md +7 -0
  4. package/dist/resources/extensions/gsd/auto/infra-errors.js +9 -3
  5. package/dist/resources/extensions/gsd/auto/loop.js +5 -5
  6. package/dist/resources/extensions/gsd/auto/orchestrator.js +11 -0
  7. package/dist/resources/extensions/gsd/auto/phases.js +8 -1
  8. package/dist/resources/extensions/gsd/auto/workflow-memory-pressure.js +12 -0
  9. package/dist/resources/extensions/gsd/auto-model-selection.js +2 -0
  10. package/dist/resources/extensions/gsd/auto-post-unit.js +1 -1
  11. package/dist/resources/extensions/gsd/auto-start.js +78 -9
  12. package/dist/resources/extensions/gsd/auto-worktree.js +15 -1
  13. package/dist/resources/extensions/gsd/auto.js +30 -3
  14. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +9 -8
  15. package/dist/resources/extensions/gsd/bootstrap/subagent-input.js +5 -2
  16. package/dist/resources/extensions/gsd/crash-recovery.js +31 -5
  17. package/dist/resources/extensions/gsd/db/unit-dispatches.js +1 -0
  18. package/dist/resources/extensions/gsd/dispatch-guard.js +2 -2
  19. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +28 -11
  20. package/dist/resources/extensions/gsd/doctor.js +2 -28
  21. package/dist/resources/extensions/gsd/git-service.js +39 -1
  22. package/dist/resources/extensions/gsd/gsd-db.js +1 -0
  23. package/dist/resources/extensions/gsd/guided-flow.js +6 -0
  24. package/dist/resources/extensions/gsd/migrate/parsers.js +10 -0
  25. package/dist/resources/extensions/gsd/native-git-bridge.js +40 -9
  26. package/dist/resources/extensions/gsd/post-execution-checks.js +73 -2
  27. package/dist/resources/extensions/gsd/pre-execution-checks.js +28 -1
  28. package/dist/resources/extensions/gsd/prompt-loader.js +1 -1
  29. package/dist/resources/extensions/gsd/prompts/plan-slice.md +3 -3
  30. package/dist/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  31. package/dist/resources/extensions/gsd/status-guards.js +4 -0
  32. package/dist/resources/extensions/gsd/templates/plan.md +8 -5
  33. package/dist/resources/extensions/gsd/templates/task-plan.md +4 -2
  34. package/dist/resources/extensions/gsd/tools/complete-milestone.js +6 -8
  35. package/dist/resources/extensions/gsd/tools/complete-slice.js +6 -8
  36. package/dist/resources/extensions/gsd/tools/plan-milestone.js +7 -1
  37. package/dist/resources/extensions/gsd/tools/plan-slice.js +88 -14
  38. package/dist/resources/extensions/gsd/validation.js +23 -1
  39. package/dist/resources/extensions/gsd/verification-gate.js +68 -7
  40. package/dist/resources/extensions/gsd/workflow-projections.js +6 -8
  41. package/dist/resources/extensions/gsd/worktree-lifecycle.js +5 -1
  42. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  43. package/dist/web/standalone/.next/BUILD_ID +1 -1
  44. package/dist/web/standalone/.next/app-path-routes-manifest.json +12 -12
  45. package/dist/web/standalone/.next/build-manifest.json +2 -2
  46. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  47. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  48. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  56. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  60. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  61. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  62. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  63. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  64. package/dist/web/standalone/.next/server/app/index.html +1 -1
  65. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  66. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  67. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  68. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  69. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  70. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  71. package/dist/web/standalone/.next/server/app-paths-manifest.json +12 -12
  72. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  73. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  74. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  75. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  76. package/package.json +2 -2
  77. package/packages/mcp-server/src/workflow-tools.test.ts +1 -1
  78. package/packages/native/tsconfig.json +2 -1
  79. package/packages/native/tsconfig.tsbuildinfo +1 -1
  80. package/packages/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
  81. package/packages/pi-ai/dist/providers/openai-codex-responses.js +82 -1
  82. package/packages/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  83. package/packages/pi-ai/dist/providers/openai-codex-responses.test.d.ts +2 -0
  84. package/packages/pi-ai/dist/providers/openai-codex-responses.test.d.ts.map +1 -0
  85. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js +52 -0
  86. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js.map +1 -0
  87. package/packages/pi-ai/dist/providers/simple-options.d.ts +2 -4
  88. package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  89. package/packages/pi-ai/dist/providers/simple-options.js +5 -6
  90. package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
  91. package/packages/pi-ai/dist/providers/simple-options.test.d.ts +2 -0
  92. package/packages/pi-ai/dist/providers/simple-options.test.d.ts.map +1 -0
  93. package/packages/pi-ai/dist/providers/simple-options.test.js +50 -0
  94. package/packages/pi-ai/dist/providers/simple-options.test.js.map +1 -0
  95. package/packages/pi-ai/src/providers/openai-codex-responses.test.ts +63 -0
  96. package/packages/pi-ai/src/providers/openai-codex-responses.ts +91 -1
  97. package/packages/pi-ai/src/providers/simple-options.test.ts +60 -0
  98. package/packages/pi-ai/src/providers/simple-options.ts +5 -6
  99. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  100. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.d.ts +2 -0
  101. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.d.ts.map +1 -0
  102. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.js +66 -0
  103. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.js.map +1 -0
  104. package/packages/pi-coding-agent/dist/core/agent-session.js +1 -1
  105. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  106. package/packages/pi-coding-agent/src/core/agent-session-thinking-level.test.ts +79 -0
  107. package/packages/pi-coding-agent/src/core/agent-session.ts +1 -1
  108. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  109. package/src/resources/GSD-WORKFLOW.md +7 -0
  110. package/src/resources/extensions/gsd/auto/contracts.ts +14 -6
  111. package/src/resources/extensions/gsd/auto/infra-errors.ts +9 -3
  112. package/src/resources/extensions/gsd/auto/loop.ts +8 -5
  113. package/src/resources/extensions/gsd/auto/orchestrator.ts +11 -0
  114. package/src/resources/extensions/gsd/auto/phases.ts +7 -1
  115. package/src/resources/extensions/gsd/auto/workflow-memory-pressure.ts +13 -0
  116. package/src/resources/extensions/gsd/auto-model-selection.ts +2 -1
  117. package/src/resources/extensions/gsd/auto-post-unit.ts +1 -1
  118. package/src/resources/extensions/gsd/auto-start.ts +85 -6
  119. package/src/resources/extensions/gsd/auto-worktree.ts +15 -1
  120. package/src/resources/extensions/gsd/auto.ts +32 -3
  121. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +9 -8
  122. package/src/resources/extensions/gsd/bootstrap/subagent-input.ts +3 -1
  123. package/src/resources/extensions/gsd/crash-recovery.ts +30 -4
  124. package/src/resources/extensions/gsd/db/unit-dispatches.ts +1 -0
  125. package/src/resources/extensions/gsd/dispatch-guard.ts +2 -2
  126. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +25 -13
  127. package/src/resources/extensions/gsd/doctor.ts +2 -27
  128. package/src/resources/extensions/gsd/git-service.ts +45 -1
  129. package/src/resources/extensions/gsd/gsd-db.ts +3 -0
  130. package/src/resources/extensions/gsd/guided-flow.ts +6 -0
  131. package/src/resources/extensions/gsd/migrate/parsers.ts +11 -0
  132. package/src/resources/extensions/gsd/native-git-bridge.ts +46 -9
  133. package/src/resources/extensions/gsd/post-execution-checks.ts +87 -2
  134. package/src/resources/extensions/gsd/pre-execution-checks.ts +32 -1
  135. package/src/resources/extensions/gsd/prompt-loader.ts +1 -1
  136. package/src/resources/extensions/gsd/prompts/plan-slice.md +3 -3
  137. package/src/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  138. package/src/resources/extensions/gsd/status-guards.ts +5 -0
  139. package/src/resources/extensions/gsd/templates/plan.md +8 -5
  140. package/src/resources/extensions/gsd/templates/task-plan.md +4 -2
  141. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +54 -0
  142. package/src/resources/extensions/gsd/tests/auto-orchestrator.test.ts +80 -1
  143. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +6 -6
  144. package/src/resources/extensions/gsd/tests/auto-start-orphan-bootstrap.test.ts +1 -0
  145. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +4 -1
  146. package/src/resources/extensions/gsd/tests/complete-task.test.ts +3 -1
  147. package/src/resources/extensions/gsd/tests/crash-recovery-via-db.test.ts +43 -2
  148. package/src/resources/extensions/gsd/tests/deep-project-auto-loop.test.ts +2 -0
  149. package/src/resources/extensions/gsd/tests/dispatch-guard.test.ts +27 -0
  150. package/src/resources/extensions/gsd/tests/guided-flow.test.ts +21 -0
  151. package/src/resources/extensions/gsd/tests/hook-model-resolution.test.ts +5 -0
  152. package/src/resources/extensions/gsd/tests/infra-error.test.ts +2 -2
  153. package/src/resources/extensions/gsd/tests/infra-errors-cooldown.test.ts +9 -0
  154. package/src/resources/extensions/gsd/tests/integration/doctor-runtime.test.ts +20 -0
  155. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +103 -1
  156. package/src/resources/extensions/gsd/tests/integration/state-machine-runtime-failures.test.ts +6 -1
  157. package/src/resources/extensions/gsd/tests/migrate-validator-parsers.test.ts +24 -1
  158. package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +63 -2
  159. package/src/resources/extensions/gsd/tests/orphaned-worktree-audit.test.ts +121 -1
  160. package/src/resources/extensions/gsd/tests/plan-milestone.test.ts +26 -0
  161. package/src/resources/extensions/gsd/tests/plan-slice.test.ts +200 -1
  162. package/src/resources/extensions/gsd/tests/plan-task.test.ts +17 -0
  163. package/src/resources/extensions/gsd/tests/post-execution-checks.test.ts +86 -0
  164. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +53 -0
  165. package/src/resources/extensions/gsd/tests/prompt-loader.test.ts +23 -0
  166. package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +31 -1
  167. package/src/resources/extensions/gsd/tests/stuck-state-via-db.test.ts +26 -2
  168. package/src/resources/extensions/gsd/tests/summary-render-parity.test.ts +7 -3
  169. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +110 -1
  170. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +1 -1
  171. package/src/resources/extensions/gsd/tests/workflow-memory-pressure.test.ts +21 -1
  172. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +1 -1
  173. package/src/resources/extensions/gsd/tests/worktree-git-pathspec.test.ts +39 -0
  174. package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +7 -0
  175. package/src/resources/extensions/gsd/tools/complete-milestone.ts +8 -10
  176. package/src/resources/extensions/gsd/tools/complete-slice.ts +6 -8
  177. package/src/resources/extensions/gsd/tools/plan-milestone.ts +5 -1
  178. package/src/resources/extensions/gsd/tools/plan-slice.ts +96 -12
  179. package/src/resources/extensions/gsd/types.ts +1 -1
  180. package/src/resources/extensions/gsd/validation.ts +23 -1
  181. package/src/resources/extensions/gsd/verification-gate.ts +78 -6
  182. package/src/resources/extensions/gsd/workflow-projections.ts +6 -8
  183. package/src/resources/extensions/gsd/worktree-lifecycle.ts +7 -1
  184. /package/dist/web/standalone/.next/static/{BdZQhe8yKl6bdKLiXVEzh → q0WYuDVbHeFFYbdd-fei2}/_buildManifest.js +0 -0
  185. /package/dist/web/standalone/.next/static/{BdZQhe8yKl6bdKLiXVEzh → q0WYuDVbHeFFYbdd-fei2}/_ssgManifest.js +0 -0
@@ -1,6 +1,6 @@
1
1
  import { clearParseCache } from "../files.js";
2
2
  import { isClosedStatus } from "../status-guards.js";
3
- import { isNonEmptyString, validateStringArray } from "../validation.js";
3
+ import { isNonEmptyString, validateStringArray, validateTitle } from "../validation.js";
4
4
  import { transaction, getMilestone, getMilestoneSlices, getSlice, insertMilestone, insertSlice, upsertMilestonePlanning, upsertSlicePlanning, } from "../gsd-db.js";
5
5
  import { invalidateStateCache } from "../state.js";
6
6
  import { renderRoadmapFromDb } from "../markdown-renderer.js";
@@ -77,6 +77,9 @@ function validateSlices(value) {
77
77
  seen.add(sliceId);
78
78
  if (!isNonEmptyString(title))
79
79
  throw new Error(`slices[${index}].title must be a non-empty string`);
80
+ const titleIssue = validateTitle(title);
81
+ if (titleIssue)
82
+ throw new Error(`slices[${index}].title is invalid: ${titleIssue}`);
80
83
  if (!isNonEmptyString(risk))
81
84
  throw new Error(`slices[${index}].risk must be a non-empty string`);
82
85
  if (!Array.isArray(depends) || depends.some((item) => !isNonEmptyString(item))) {
@@ -127,6 +130,9 @@ function validateParams(params) {
127
130
  throw new Error("title is required");
128
131
  if (!isNonEmptyString(params?.vision))
129
132
  throw new Error("vision is required");
133
+ const milestoneTitleIssue = validateTitle(params.title);
134
+ if (milestoneTitleIssue)
135
+ throw new Error(`title is invalid: ${milestoneTitleIssue}`);
130
136
  return {
131
137
  ...params,
132
138
  dependsOn: params.dependsOn ? validateStringArray(params.dependsOn, "dependsOn") : [],
@@ -1,7 +1,9 @@
1
+ import { existsSync, rmSync } from "node:fs";
2
+ import { join, relative } from "node:path";
1
3
  import { clearParseCache } from "../files.js";
2
4
  import { isClosedStatus, isDeferredStatus } from "../status-guards.js";
3
- import { isNonEmptyString } from "../validation.js";
4
- import { transaction, getMilestone, getSlice, insertTask, upsertSlicePlanning, upsertTaskPlanning, insertGateRow, updateSliceStatus, setSliceSketchFlag, } from "../gsd-db.js";
5
+ import { isNonEmptyString, validateStringArray } from "../validation.js";
6
+ import { transaction, getMilestone, getSlice, getSliceTasks, insertTask, upsertSlicePlanning, upsertTaskPlanning, insertGateRow, updateSliceStatus, setSliceSketchFlag, deleteTask, deleteArtifactByPath, } from "../gsd-db.js";
5
7
  import { invalidateStateCache } from "../state.js";
6
8
  import { renderPlanFromDb } from "../markdown-renderer.js";
7
9
  import { renderAllProjections } from "../workflow-projections.js";
@@ -9,6 +11,8 @@ import { writeManifest } from "../workflow-manifest.js";
9
11
  import { appendEvent } from "../workflow-events.js";
10
12
  import { logWarning } from "../workflow-logger.js";
11
13
  import { validatePlanningPathScope } from "../planning-path-scope.js";
14
+ import { checkFilePathConsistency, checkTaskOrdering } from "../pre-execution-checks.js";
15
+ import { buildTaskFileName, gsdRoot, resolveTasksDir } from "../paths.js";
12
16
  function validateTasks(value) {
13
17
  if (!Array.isArray(value) || value.length === 0) {
14
18
  throw new Error("tasks must be a non-empty array");
@@ -39,17 +43,11 @@ function validateTasks(value) {
39
43
  throw new Error(`tasks[${index}].description must be a non-empty string`);
40
44
  if (!isNonEmptyString(estimate))
41
45
  throw new Error(`tasks[${index}].estimate must be a non-empty string`);
42
- if (!Array.isArray(files) || files.some((item) => !isNonEmptyString(item))) {
43
- throw new Error(`tasks[${index}].files must be an array of non-empty strings`);
44
- }
46
+ const validatedFiles = validateStringArray(files, `tasks[${index}].files`);
45
47
  if (!isNonEmptyString(verify))
46
48
  throw new Error(`tasks[${index}].verify must be a non-empty string`);
47
- if (!Array.isArray(inputs) || inputs.some((item) => !isNonEmptyString(item))) {
48
- throw new Error(`tasks[${index}].inputs must be an array of non-empty strings`);
49
- }
50
- if (!Array.isArray(expectedOutput) || expectedOutput.some((item) => !isNonEmptyString(item))) {
51
- throw new Error(`tasks[${index}].expectedOutput must be an array of non-empty strings`);
52
- }
49
+ const validatedInputs = validateStringArray(inputs, `tasks[${index}].inputs`);
50
+ const validatedExpectedOutput = validateStringArray(expectedOutput, `tasks[${index}].expectedOutput`);
53
51
  if (observabilityImpact !== undefined && !isNonEmptyString(observabilityImpact)) {
54
52
  throw new Error(`tasks[${index}].observabilityImpact must be a non-empty string when provided`);
55
53
  }
@@ -58,10 +56,10 @@ function validateTasks(value) {
58
56
  title,
59
57
  description,
60
58
  estimate,
61
- files,
59
+ files: validatedFiles,
62
60
  verify,
63
- inputs,
64
- expectedOutput,
61
+ inputs: validatedInputs,
62
+ expectedOutput: validatedExpectedOutput,
65
63
  observabilityImpact: typeof observabilityImpact === "string" ? observabilityImpact : "",
66
64
  };
67
65
  });
@@ -84,6 +82,53 @@ function validateParams(params) {
84
82
  tasks: validateTasks(params.tasks),
85
83
  };
86
84
  }
85
+ function toTaskRows(params) {
86
+ return params.tasks.map((task, index) => ({
87
+ milestone_id: params.milestoneId,
88
+ slice_id: params.sliceId,
89
+ id: task.taskId,
90
+ title: task.title,
91
+ status: "pending",
92
+ one_liner: "",
93
+ narrative: "",
94
+ verification_result: "",
95
+ duration: "",
96
+ completed_at: null,
97
+ blocker_discovered: false,
98
+ deviations: "",
99
+ known_issues: "",
100
+ key_files: [],
101
+ key_decisions: [],
102
+ full_summary_md: "",
103
+ description: task.description,
104
+ estimate: task.estimate,
105
+ files: task.files,
106
+ verify: task.verify,
107
+ inputs: task.inputs,
108
+ expected_output: task.expectedOutput,
109
+ observability_impact: task.observabilityImpact ?? "",
110
+ full_plan_md: task.fullPlanMd ?? "",
111
+ sequence: index + 1,
112
+ blocker_source: "",
113
+ escalation_pending: 0,
114
+ escalation_awaiting_review: 0,
115
+ escalation_artifact_path: null,
116
+ escalation_override_applied_at: null,
117
+ }));
118
+ }
119
+ function validateTaskPathsBeforePersist(params, basePath) {
120
+ const taskRows = toTaskRows(params);
121
+ const checks = [
122
+ ...checkFilePathConsistency(taskRows, basePath),
123
+ ...checkTaskOrdering(taskRows, basePath),
124
+ ];
125
+ const blocking = checks.filter((check) => !check.passed && check.blocking);
126
+ if (blocking.length === 0)
127
+ return null;
128
+ return blocking
129
+ .map((check) => `[${check.category}] ${check.target}: ${check.message}`)
130
+ .join("\n");
131
+ }
87
132
  export async function handlePlanSlice(rawParams, basePath) {
88
133
  let params;
89
134
  try {
@@ -100,10 +145,15 @@ export async function handlePlanSlice(rawParams, basePath) {
100
145
  if (pathScopeError) {
101
146
  return { error: `validation failed: ${pathScopeError}` };
102
147
  }
148
+ const pathError = validateTaskPathsBeforePersist(params, basePath);
149
+ if (pathError) {
150
+ return { error: `pre-execution validation failed:\n${pathError}` };
151
+ }
103
152
  // ── Guards + DB writes inside a single transaction (prevents TOCTOU) ───
104
153
  // Guards must be inside the transaction so the state they check cannot
105
154
  // change between the read and the write (#2723).
106
155
  let guardError = null;
156
+ let omittedTaskIds = [];
107
157
  try {
108
158
  transaction(() => {
109
159
  const parentMilestone = getMilestone(params.milestoneId);
@@ -124,6 +174,17 @@ export async function handlePlanSlice(rawParams, basePath) {
124
174
  guardError = `cannot re-plan slice ${params.sliceId}: it is already complete — use gsd_slice_reopen first`;
125
175
  return;
126
176
  }
177
+ const newTaskIds = new Set(params.tasks.map((task) => task.taskId));
178
+ const existingTasks = getSliceTasks(params.milestoneId, params.sliceId);
179
+ omittedTaskIds = existingTasks
180
+ .filter((task) => !newTaskIds.has(task.id))
181
+ .map((task) => task.id);
182
+ for (const task of existingTasks) {
183
+ if (!newTaskIds.has(task.id) && isClosedStatus(task.status)) {
184
+ guardError = `cannot remove completed task ${task.id}`;
185
+ return;
186
+ }
187
+ }
127
188
  if (isDeferredStatus(parentSlice.status)) {
128
189
  updateSliceStatus(params.milestoneId, params.sliceId, "pending");
129
190
  }
@@ -135,6 +196,9 @@ export async function handlePlanSlice(rawParams, basePath) {
135
196
  integrationClosure: params.integrationClosure,
136
197
  observabilityImpact: params.observabilityImpact,
137
198
  });
199
+ for (const taskId of omittedTaskIds) {
200
+ deleteTask(params.milestoneId, params.sliceId, taskId);
201
+ }
138
202
  for (const task of params.tasks) {
139
203
  insertTask({
140
204
  id: task.taskId,
@@ -177,6 +241,16 @@ export async function handlePlanSlice(rawParams, basePath) {
177
241
  return { error: guardError };
178
242
  }
179
243
  try {
244
+ const tasksDir = resolveTasksDir(basePath, params.milestoneId, params.sliceId);
245
+ for (const taskId of omittedTaskIds) {
246
+ if (!tasksDir)
247
+ continue;
248
+ const taskPlanPath = join(tasksDir, buildTaskFileName(taskId, "PLAN"));
249
+ if (existsSync(taskPlanPath))
250
+ rmSync(taskPlanPath, { force: true });
251
+ const artifactPath = relative(gsdRoot(basePath), taskPlanPath).replace(/\\/g, "/");
252
+ deleteArtifactByPath(artifactPath);
253
+ }
180
254
  const renderResult = await renderPlanFromDb(basePath, params.milestoneId, params.sliceId);
181
255
  invalidateStateCache();
182
256
  clearParseCache();
@@ -5,6 +5,27 @@
5
5
  export function isNonEmptyString(value) {
6
6
  return typeof value === "string" && value.trim().length > 0;
7
7
  }
8
+ /**
9
+ * Characters that are used as delimiters in GSD state management documents
10
+ * and should not appear in milestone or slice titles.
11
+ */
12
+ const TITLE_DELIMITER_RE = /[\u2014\u2013\/]/; // em dash, en dash, forward slash
13
+ /**
14
+ * Check whether a milestone or slice title contains characters that conflict
15
+ * with GSD's state document delimiter conventions.
16
+ * Returns a human-readable description of the problem, or null if the title is safe.
17
+ */
18
+ export function validateTitle(title) {
19
+ if (TITLE_DELIMITER_RE.test(title)) {
20
+ const found = [];
21
+ if (/[\u2014\u2013]/.test(title))
22
+ found.push("em/en dash (\u2014 or \u2013)");
23
+ if (/\//.test(title))
24
+ found.push("forward slash (/)");
25
+ return `title contains ${found.join(" and ")}, which conflict with GSD state document delimiters`;
26
+ }
27
+ return null;
28
+ }
8
29
  /**
9
30
  * Validate that `value` is an array of non-empty strings.
10
31
  * Throws with a message referencing `field` on failure.
@@ -12,7 +33,8 @@ export function isNonEmptyString(value) {
12
33
  */
13
34
  export function validateStringArray(value, field) {
14
35
  if (!Array.isArray(value)) {
15
- throw new Error(`${field} must be an array`);
36
+ const received = value === null ? "null" : typeof value;
37
+ throw new Error(`${field} must be an array of strings, not ${received}`);
16
38
  }
17
39
  if (value.some((item) => !isNonEmptyString(item))) {
18
40
  throw new Error(`${field} must contain only non-empty strings`);
@@ -3,7 +3,7 @@
3
3
  // Discovery order (D003): preference → task plan verify → package.json scripts.
4
4
  // First non-empty source wins.
5
5
  import { spawnSync } from "node:child_process";
6
- import { existsSync, readFileSync } from "node:fs";
6
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
7
7
  import { join, basename } from "node:path";
8
8
  import { DEFAULT_COMMAND_TIMEOUT_MS } from "./constants.js";
9
9
  import { rewriteCommandWithRtk } from "../shared/rtk.js";
@@ -27,7 +27,8 @@ const PACKAGE_SCRIPT_KEYS = ["typecheck", "lint", "test"];
27
27
  * 1. Explicit preference commands
28
28
  * 2. Task plan verify field (split on &&)
29
29
  * 3. package.json scripts (typecheck, lint, test)
30
- * 4. None found
30
+ * 4. Python pytest project markers
31
+ * 5. None found
31
32
  */
32
33
  export function discoverCommands(options) {
33
34
  // 1. Preference commands
@@ -72,9 +73,57 @@ export function discoverCommands(options) {
72
73
  // Malformed package.json — fall through to "none"
73
74
  }
74
75
  }
75
- // 4. Nothing found
76
+ const pythonCommand = discoverPythonPytestCommand(options.cwd);
77
+ if (pythonCommand) {
78
+ return { commands: [pythonCommand], source: "python-project" };
79
+ }
80
+ // 5. Nothing found
76
81
  return { commands: [], source: "none" };
77
82
  }
83
+ function discoverPythonPytestCommand(cwd) {
84
+ const hasPythonTestFiles = hasPythonTests(join(cwd, "tests"));
85
+ const hasPytestConfig = existsSync(join(cwd, "pytest.ini"));
86
+ const pyprojectPath = join(cwd, "pyproject.toml");
87
+ const hasPyproject = existsSync(pyprojectPath);
88
+ if (!hasPythonTestFiles && !hasPytestConfig && !hasPyproject) {
89
+ return null;
90
+ }
91
+ if (hasPytestConfig || hasPythonTestFiles) {
92
+ return "python3 -m pytest";
93
+ }
94
+ try {
95
+ const pyproject = readFileSync(pyprojectPath, "utf-8");
96
+ if (pyproject.includes("[tool.pytest]") ||
97
+ pyproject.includes("[tool.pytest.") ||
98
+ pyproject.includes("[pytest]") ||
99
+ pyproject.includes("[tool:pytest]")) {
100
+ return "python3 -m pytest";
101
+ }
102
+ }
103
+ catch {
104
+ // Ignore unreadable pyproject.toml and fall through.
105
+ }
106
+ return null;
107
+ }
108
+ function hasPythonTests(dir) {
109
+ let entries;
110
+ try {
111
+ entries = readdirSync(dir, { withFileTypes: true });
112
+ }
113
+ catch {
114
+ return false;
115
+ }
116
+ for (const entry of entries) {
117
+ const path = join(dir, entry.name);
118
+ if (entry.isDirectory() && hasPythonTests(path)) {
119
+ return true;
120
+ }
121
+ if (entry.isFile() && /^test_.*\.py$|^.*_test\.py$/.test(entry.name)) {
122
+ return true;
123
+ }
124
+ }
125
+ return false;
126
+ }
78
127
  // ─── Failure Context Formatting ──────────────────────────────────────────────
79
128
  /** Maximum chars of stderr to include per failed check in failure context. */
80
129
  const MAX_STDERR_PER_CHECK = 2_000;
@@ -112,7 +161,7 @@ export function formatFailureContext(result) {
112
161
  }
113
162
  // ─── Gate Execution ─────────────────────────────────────────────────────────
114
163
  /** Characters that indicate shell injection when found in a command string. */
115
- const SHELL_INJECTION_PATTERN = /[;|`]|\$\(/;
164
+ const SHELL_INJECTION_PATTERN = /[;|`<>]|\$\(/;
116
165
  /**
117
166
  * Known executable first-tokens that are safe to run.
118
167
  * Lowercase commands, common build/test tools, and npm/yarn/pnpm invocations.
@@ -148,6 +197,7 @@ const KNOWN_COMMAND_PREFIXES = new Set([
148
197
  * Heuristics (any true → prose-like):
149
198
  * 1. First token starts with an uppercase letter and the string has 4+ words
150
199
  * 2. String contains commas followed by spaces (prose clause structure)
200
+ * 3. First token has no ASCII letters or digits and the string has 4+ words
151
201
  */
152
202
  export function isLikelyCommand(cmd) {
153
203
  const trimmed = cmd.trim();
@@ -173,16 +223,27 @@ export function isLikelyCommand(cmd) {
173
223
  // First token has uppercase letters and no path separators → prose
174
224
  if (/[A-Z]/.test(firstToken) && !firstToken.includes("/"))
175
225
  return false;
226
+ // Non-ASCII prose with multiple words should not be executed as a command.
227
+ if (!/[A-Za-z0-9]/.test(firstToken) && tokens.length >= 4)
228
+ return false;
176
229
  return true;
177
230
  }
178
231
  /**
179
232
  * Validate a command string for obvious shell injection patterns.
180
233
  * Returns the command unchanged if safe, or null if suspicious.
181
234
  */
235
+ export function validateVerificationCommand(cmd) {
236
+ if (SHELL_INJECTION_PATTERN.test(cmd)) {
237
+ return { ok: false, reason: "contains shell control syntax such as pipes, redirects, semicolons, backticks, or command substitution" };
238
+ }
239
+ if (!isLikelyCommand(cmd)) {
240
+ return { ok: false, reason: "does not look like a runnable command" };
241
+ }
242
+ return { ok: true };
243
+ }
182
244
  function sanitizeCommand(cmd) {
183
- if (SHELL_INJECTION_PATTERN.test(cmd))
184
- return null;
185
- if (!isLikelyCommand(cmd))
245
+ const validation = validateVerificationCommand(cmd);
246
+ if (!validation.ok)
186
247
  return null;
187
248
  return cmd;
188
249
  }
@@ -150,11 +150,11 @@ export function renderSummaryContent(taskRow, sliceId, milestoneId, evidence) {
150
150
  }
151
151
  // ── Frontmatter (YAML list format, matches parseSummary() expectations) ──
152
152
  const keyFilesYaml = taskRow.key_files && taskRow.key_files.length > 0
153
- ? taskRow.key_files.map(f => ` - ${f}`).join("\n")
154
- : " - (none)";
153
+ ? `\n${taskRow.key_files.map(f => ` - ${f}`).join("\n")}`
154
+ : " []";
155
155
  const keyDecisionsYaml = taskRow.key_decisions && taskRow.key_decisions.length > 0
156
- ? taskRow.key_decisions.map(d => ` - ${d}`).join("\n")
157
- : " - (none)";
156
+ ? `\n${taskRow.key_decisions.map(d => ` - ${d}`).join("\n")}`
157
+ : " []";
158
158
  // Derive verification_result from evidence if available
159
159
  const evidenceList = evidence ?? [];
160
160
  const allPassed = evidenceList.length > 0 &&
@@ -182,10 +182,8 @@ export function renderSummaryContent(taskRow, sliceId, milestoneId, evidence) {
182
182
  id: ${taskRow.id}
183
183
  parent: ${sliceId}
184
184
  milestone: ${milestoneId}
185
- key_files:
186
- ${keyFilesYaml}
187
- key_decisions:
188
- ${keyDecisionsYaml}
185
+ key_files:${keyFilesYaml}
186
+ key_decisions:${keyDecisionsYaml}
189
187
  duration: ${taskRow.duration || ""}
190
188
  verification_result: ${verificationResult}
191
189
  completed_at: ${taskRow.completed_at || ""}
@@ -20,6 +20,7 @@ import { existsSync, readFileSync, unlinkSync } from "node:fs";
20
20
  import { randomUUID } from "node:crypto";
21
21
  import { join } from "node:path";
22
22
  import { debugLog } from "./debug-logger.js";
23
+ import { logWarning } from "./workflow-logger.js";
23
24
  import { emitJournalEvent } from "./journal.js";
24
25
  import { emitWorktreeCreated, emitWorktreeMerged } from "./worktree-telemetry.js";
25
26
  import { resolveWorktreeProjectRoot, normalizeWorktreePathForCompare, } from "./worktree-root.js";
@@ -213,7 +214,7 @@ export function _enterMilestoneCore(s, deps, milestoneId, ctx) {
213
214
  }
214
215
  // Phase B: claim a milestone lease before any worktree mutation. Two
215
216
  // workers cannot enter the same milestone concurrently. Best-effort:
216
- // skip if no worker registered (single-worker fallback) or DB
217
+ // warn if no worker registered (single-worker fallback) or skip if DB
217
218
  // unavailable; reuse existing lease if we already hold it on this
218
219
  // milestone (re-entry within the same session).
219
220
  if (s.workerId) {
@@ -293,6 +294,9 @@ export function _enterMilestoneCore(s, deps, milestoneId, ctx) {
293
294
  }
294
295
  }
295
296
  }
297
+ else {
298
+ logWarning("worktree", `enterMilestone(${milestoneId}) ran before auto worker registration; milestone lease was not claimed.`);
299
+ }
296
300
  // Resolve the project root for worktree operations via shared helper.
297
301
  // Handles the case where originalBasePath is falsy and basePath is itself
298
302
  // a worktree path — prevents double-nested worktree paths (#3729).