gsd-pi 2.79.0-dev.bbb2f88ce → 2.79.0-dev.ece5fd8ba

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 (53) hide show
  1. package/dist/resources/.managed-resources-content-hash +1 -1
  2. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +8 -8
  3. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +8 -8
  4. package/dist/resources/extensions/gsd/guided-flow.js +40 -0
  5. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +45 -4
  6. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  7. package/dist/web/standalone/.next/BUILD_ID +1 -1
  8. package/dist/web/standalone/.next/app-path-routes-manifest.json +15 -15
  9. package/dist/web/standalone/.next/build-manifest.json +2 -2
  10. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  11. package/dist/web/standalone/.next/required-server-files.json +1 -1
  12. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  13. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  14. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  15. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  16. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  17. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  18. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  19. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  20. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  21. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  22. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  25. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  27. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/index.html +1 -1
  29. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  30. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  33. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app-paths-manifest.json +15 -15
  36. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  37. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  38. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  39. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  40. package/dist/web/standalone/server.js +1 -1
  41. package/package.json +1 -1
  42. package/packages/mcp-server/src/workflow-tools.test.ts +13 -2
  43. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +11 -8
  44. package/src/resources/extensions/gsd/bootstrap/tests/write-gate-shouldblock-basepath.test.ts +97 -0
  45. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +8 -4
  46. package/src/resources/extensions/gsd/guided-flow.ts +47 -0
  47. package/src/resources/extensions/gsd/tests/check-auto-start-pending-gate.test.ts +203 -0
  48. package/src/resources/extensions/gsd/tests/check-auto-start-ready-guard.test.ts +148 -0
  49. package/src/resources/extensions/gsd/tests/execute-summary-save-empty-project.test.ts +109 -0
  50. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +36 -7
  51. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +47 -4
  52. /package/dist/web/standalone/.next/static/{3HYkAopiKls15zp5a8I9n → TzEVJ1Lh8vbez4n4Q9TqQ}/_buildManifest.js +0 -0
  53. /package/dist/web/standalone/.next/static/{3HYkAopiKls15zp5a8I9n → TzEVJ1Lh8vbez4n4Q9TqQ}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- b873eb2a8c4529c9
1
+ 76e1a0d39c0a27d8
@@ -166,7 +166,7 @@ export function registerHooks(pi, ecosystemHandlers) {
166
166
  const { getEcosystemReadyPromise } = await import("../ecosystem/loader.js");
167
167
  await getEcosystemReadyPromise();
168
168
  const beforeAgentBasePath = process.cwd();
169
- const pendingApprovalGate = getPendingGate();
169
+ const pendingApprovalGate = getPendingGate(beforeAgentBasePath);
170
170
  if (pendingApprovalGate && isExplicitApprovalResponse(event.prompt, pendingApprovalGate)) {
171
171
  markApprovalGateVerified(pendingApprovalGate, beforeAgentBasePath);
172
172
  const milestoneId = extractDepthVerificationMilestoneId(pendingApprovalGate);
@@ -363,15 +363,15 @@ export function registerHooks(pi, ecosystemHandlers) {
363
363
  // ── Discussion gate enforcement: block tool calls while gate is pending ──
364
364
  // If ask_user_questions was called with a gate ID but hasn't been confirmed,
365
365
  // block all non-read-only tool calls to prevent the model from skipping gates.
366
- if (getPendingGate()) {
366
+ if (getPendingGate(discussionBasePath)) {
367
367
  const milestoneId = await getDiscussionMilestoneIdFor(discussionBasePath);
368
368
  if (isToolCallEventType("bash", event)) {
369
- const bashGuard = shouldBlockPendingGateBash(event.input.command, milestoneId, isQueuePhaseActive());
369
+ const bashGuard = shouldBlockPendingGateBash(event.input.command, milestoneId, isQueuePhaseActive(discussionBasePath), discussionBasePath);
370
370
  if (bashGuard.block)
371
371
  return bashGuard;
372
372
  }
373
373
  else {
374
- const gateGuard = shouldBlockPendingGate(toolName, milestoneId, isQueuePhaseActive());
374
+ const gateGuard = shouldBlockPendingGate(toolName, milestoneId, isQueuePhaseActive(discussionBasePath), discussionBasePath);
375
375
  if (gateGuard.block)
376
376
  return gateGuard;
377
377
  }
@@ -380,7 +380,7 @@ export function registerHooks(pi, ecosystemHandlers) {
380
380
  // When /gsd queue is active, the agent should only create milestones,
381
381
  // not execute work. Block write/edit to non-.gsd/ paths and bash commands
382
382
  // that would modify files.
383
- if (isQueuePhaseActive()) {
383
+ if (isQueuePhaseActive(discussionBasePath)) {
384
384
  let queueInput = "";
385
385
  if (isToolCallEventType("write", event)) {
386
386
  queueInput = event.input.path;
@@ -445,7 +445,7 @@ export function registerHooks(pi, ecosystemHandlers) {
445
445
  }
446
446
  if (!isToolCallEventType("write", event))
447
447
  return;
448
- const result = shouldBlockContextWrite(event.toolName, event.input.path, await getDiscussionMilestoneIdFor(discussionBasePath), isQueuePhaseActive());
448
+ const result = shouldBlockContextWrite(event.toolName, event.input.path, await getDiscussionMilestoneIdFor(discussionBasePath), isQueuePhaseActive(discussionBasePath), discussionBasePath);
449
449
  if (result.block)
450
450
  return result;
451
451
  });
@@ -500,7 +500,7 @@ export function registerHooks(pi, ecosystemHandlers) {
500
500
  return;
501
501
  const basePath = process.cwd();
502
502
  const milestoneId = await getDiscussionMilestoneIdFor(basePath);
503
- const queueActive = isQueuePhaseActive();
503
+ const queueActive = isQueuePhaseActive(basePath);
504
504
  const details = event.details;
505
505
  // ── Discussion gate enforcement: handle gate question responses ──
506
506
  // If the result is cancelled or has no response, the pending gate stays active
@@ -508,7 +508,7 @@ export function registerHooks(pi, ecosystemHandlers) {
508
508
  // If the user responded at all (even "needs adjustment"), clear the pending gate
509
509
  // because the user engaged — the prompt handles the re-ask-after-adjustment flow.
510
510
  const questions = event.input?.questions ?? [];
511
- const currentPendingGate = getPendingGate();
511
+ const currentPendingGate = getPendingGate(basePath);
512
512
  if (currentPendingGate) {
513
513
  if (details?.cancelled || !details?.response) {
514
514
  // Gate stays pending. Direct the agent to the most reliable recovery
@@ -298,8 +298,8 @@ export function getPendingGate(basePath = process.cwd()) {
298
298
  * Returns { block: true, reason } if the tool should be blocked.
299
299
  * ask_user_questions itself is allowed so the model can re-ask the gate.
300
300
  */
301
- export function shouldBlockPendingGate(toolName, milestoneId, queuePhaseActive) {
302
- return shouldBlockPendingGateInSnapshot(currentWriteGateSnapshot(), toolName, milestoneId, queuePhaseActive);
301
+ export function shouldBlockPendingGate(toolName, milestoneId, queuePhaseActive, basePath = process.cwd()) {
302
+ return shouldBlockPendingGateInSnapshot(currentWriteGateSnapshot(basePath), toolName, milestoneId, queuePhaseActive);
303
303
  }
304
304
  export function shouldBlockPendingGateInSnapshot(snapshot, toolName, _milestoneId, _queuePhaseActive) {
305
305
  if (!snapshot.pendingGateId)
@@ -322,8 +322,8 @@ export function shouldBlockPendingGateInSnapshot(snapshot, toolName, _milestoneI
322
322
  * Check whether a bash command should be blocked because a discussion gate is pending.
323
323
  * All bash is blocked while waiting for confirmation so the question stays visible.
324
324
  */
325
- export function shouldBlockPendingGateBash(command, milestoneId, queuePhaseActive) {
326
- return shouldBlockPendingGateBashInSnapshot(currentWriteGateSnapshot(), command, milestoneId, queuePhaseActive);
325
+ export function shouldBlockPendingGateBash(command, milestoneId, queuePhaseActive, basePath = process.cwd()) {
326
+ return shouldBlockPendingGateBashInSnapshot(currentWriteGateSnapshot(basePath), command, milestoneId, queuePhaseActive);
327
327
  }
328
328
  export function shouldBlockPendingGateBashInSnapshot(snapshot, command, _milestoneId, _queuePhaseActive) {
329
329
  if (!snapshot.pendingGateId)
@@ -363,7 +363,7 @@ export function isDepthConfirmationAnswer(selected, options) {
363
363
  // Returning false prevents any free-form string from unlocking the gate.
364
364
  return false;
365
365
  }
366
- export function shouldBlockContextWrite(toolName, inputPath, milestoneId, _queuePhaseActive) {
366
+ export function shouldBlockContextWrite(toolName, inputPath, milestoneId, _queuePhaseActive, basePath = process.cwd()) {
367
367
  if (toolName !== "write")
368
368
  return { block: false };
369
369
  if (!MILESTONE_CONTEXT_RE.test(inputPath))
@@ -379,7 +379,7 @@ export function shouldBlockContextWrite(toolName, inputPath, milestoneId, _queue
379
379
  ].join(" "),
380
380
  };
381
381
  }
382
- if (isMilestoneDepthVerified(targetMilestoneId))
382
+ if (isMilestoneDepthVerified(targetMilestoneId, basePath))
383
383
  return { block: false };
384
384
  return {
385
385
  block: true,
@@ -397,8 +397,8 @@ export function shouldBlockContextWrite(toolName, inputPath, milestoneId, _queue
397
397
  * Slice-level CONTEXT artifacts are allowed; milestone-level CONTEXT writes
398
398
  * require the milestone to be depth-verified first.
399
399
  */
400
- export function shouldBlockContextArtifactSave(artifactType, milestoneId, sliceId) {
401
- return shouldBlockContextArtifactSaveInSnapshot(currentWriteGateSnapshot(), artifactType, milestoneId, sliceId);
400
+ export function shouldBlockContextArtifactSave(artifactType, milestoneId, sliceId, basePath = process.cwd()) {
401
+ return shouldBlockContextArtifactSaveInSnapshot(currentWriteGateSnapshot(basePath), artifactType, milestoneId, sliceId);
402
402
  }
403
403
  export function shouldBlockContextArtifactSaveInSnapshot(snapshot, artifactType, milestoneId, sliceId) {
404
404
  if (artifactType !== "CONTEXT")
@@ -44,6 +44,7 @@ import { getWorkflowTransportSupportError, getRequiredWorkflowToolsForGuidedUnit
44
44
  import { runPreparation, formatCodebaseBrief, formatPriorContextBrief, } from "./preparation.js";
45
45
  import { verifyExpectedArtifact } from "./auto-recovery.js";
46
46
  import { createWorkspace, scopeMilestone } from "./workspace.js";
47
+ import { getPendingGate, extractDepthVerificationMilestoneId } from "./bootstrap/write-gate.js";
47
48
  // ─── Re-exports (preserve public API for existing importers) ────────────────
48
49
  export { MILESTONE_ID_RE, generateMilestoneSuffix, nextMilestoneId, extractMilestoneSeq, parseMilestoneId, milestoneIdSort, maxMilestoneNum, findMilestoneIds, reserveMilestoneId, claimReservedId, getReservedMilestoneIds, clearReservedMilestoneIds, } from "./milestone-ids.js";
49
50
  export { showQueue, handleQueueReorder, showQueueAdd, buildExistingMilestonesContext, } from "./guided-flow-queue.js";
@@ -295,6 +296,14 @@ export async function checkDeepProjectSetupAfterTurn(_event, ctx, basePath) {
295
296
  return false;
296
297
  }
297
298
  }
299
+ // R2: a depth-verification gate is still pending — the LLM emitted the
300
+ // confirmation question (via ask_user_questions or plain chat) but the user
301
+ // has not approved yet. Returning false keeps the entry in the
302
+ // pendingDeepProjectSetupMap so the next user message can resume.
303
+ const pendingGateId = getPendingGate(entry.basePath);
304
+ if (pendingGateId) {
305
+ return false;
306
+ }
298
307
  return dispatchNextDeepProjectSetupStage(entry);
299
308
  }
300
309
  async function dispatchNextDeepProjectSetupStage(entry) {
@@ -368,6 +377,23 @@ export function checkAutoStartAfterDiscuss() {
368
377
  const roadmapFile = existsSync(roadmapFilePath) ? roadmapFilePath : null;
369
378
  if (!contextFile && !roadmapFile)
370
379
  return false; // neither artifact yet — keep waiting
380
+ // Gate 1a: a depth-verification gate is still pending for THIS milestone — the
381
+ // LLM emitted the confirmation question (via ask_user_questions or plain chat)
382
+ // but the user has not answered yet. Advancing now would skip the gate and
383
+ // race ahead with unverified context.
384
+ const basePathForGate = entry.scope.workspace.projectRoot;
385
+ const pendingGateId = getPendingGate(basePathForGate);
386
+ if (pendingGateId) {
387
+ const pendingMilestoneId = extractDepthVerificationMilestoneId(pendingGateId);
388
+ // Block advancement if the gate is for THIS milestone, OR if it's a
389
+ // project/requirements gate (no milestone id encoded) for the deep setup flow.
390
+ const isProjectGate = pendingGateId === "depth_verification_project_confirm" ||
391
+ pendingGateId === "depth_verification_requirements_confirm" ||
392
+ pendingGateId === "depth_verification_research_decision_confirm";
393
+ if (pendingMilestoneId === milestoneId || isProjectGate) {
394
+ return false;
395
+ }
396
+ }
371
397
  // Gate 1b: Discriminate plan-blocked from discuss-incomplete when the DB row is queued.
372
398
  // If the DB is available and the row is still "queued" but CONTEXT.md already exists on
373
399
  // disk, the discuss phase completed but gsd_plan_milestone was hard-blocked by the
@@ -489,6 +515,20 @@ export function checkAutoStartAfterDiscuss() {
489
515
  logWarning("guided", `manifest unlink failed: ${e.message}`);
490
516
  }
491
517
  }
518
+ // R3b: belt-and-suspenders for silent registration failure. The discuss flow
519
+ // finished and STATE.md exists, but the milestone may never have landed in
520
+ // the DB. Without this guard, the user sees "Milestone M001 ready." and then
521
+ // /gsd reports "No Active Milestone".
522
+ if (isDbAvailable()) {
523
+ const milestoneRow = getMilestone(milestoneId);
524
+ if (!milestoneRow) {
525
+ ctx.ui.notify(`Milestone ${milestoneId}: discuss artifacts on disk but no DB row exists. ` +
526
+ `PROJECT.md may have failed to register milestones. ` +
527
+ `Re-save PROJECT.md with canonical "- [ ] M001: Title — One-liner" lines, ` +
528
+ `then re-run /gsd to recover.`, "error");
529
+ return false;
530
+ }
531
+ }
492
532
  pendingAutoStartMap.delete(basePath);
493
533
  ctx.ui.notify(`Milestone ${milestoneId} ready.`, "success");
494
534
  startAutoDetached(ctx, pi, basePath, false, { step });
@@ -141,7 +141,6 @@ export async function executeSummarySave(params, basePath = process.cwd()) {
141
141
  task_id: isRootArtifact ? undefined : params.task_id,
142
142
  }, basePath);
143
143
  let registeredMilestones = [];
144
- let registrationWarning;
145
144
  if (params.artifact_type === "PROJECT") {
146
145
  try {
147
146
  registeredMilestones = registerProjectMilestoneSequence(contentToSave);
@@ -150,12 +149,55 @@ export async function executeSummarySave(params, basePath = process.cwd()) {
150
149
  }
151
150
  catch (err) {
152
151
  const msg = err instanceof Error ? err.message : String(err);
153
- registrationWarning = `PROJECT artifact saved, but milestone registration failed: ${msg}`;
154
- logWarning("tool", registrationWarning, {
152
+ logError("tool", `gsd_summary_save: PROJECT artifact persisted but milestone registration threw: ${msg}`, {
155
153
  tool: "gsd_summary_save",
156
154
  error: String(err),
157
155
  stack: err instanceof Error ? err.stack ?? "" : "",
158
156
  });
157
+ // PROJECT.md was persisted by saveArtifactToDb above; the artifacts row
158
+ // changed even though no milestones registered. Invalidate so subsequent
159
+ // /gsd reads see the persisted artifact instead of the pre-save cache.
160
+ invalidateStateCache();
161
+ return {
162
+ content: [{
163
+ type: "text",
164
+ text: `Error: PROJECT.md was saved to ${relativePath} but milestone registration failed: ${msg}. ` +
165
+ `The DB has no milestone rows for this project, so /gsd will report "No Active Milestone". ` +
166
+ `Re-call gsd_summary_save(PROJECT) once the underlying error is resolved — INSERT OR IGNORE makes registration idempotent.`,
167
+ }],
168
+ details: {
169
+ operation: "save_summary",
170
+ path: relativePath,
171
+ artifact_type: params.artifact_type,
172
+ error: "milestone_registration_threw",
173
+ registration_error: msg,
174
+ },
175
+ isError: true,
176
+ };
177
+ }
178
+ if (registeredMilestones.length === 0) {
179
+ logError("tool", `gsd_summary_save: PROJECT.md saved to ${relativePath} but parsed zero milestones — registration produced no DB rows`, {
180
+ tool: "gsd_summary_save",
181
+ });
182
+ // PROJECT.md was persisted; invalidate so subsequent reads see the new
183
+ // artifacts row even though no milestones registered.
184
+ invalidateStateCache();
185
+ return {
186
+ content: [{
187
+ type: "text",
188
+ text: `Error: PROJECT.md was saved to ${relativePath} but contains zero parseable milestone lines, ` +
189
+ `so no milestones were registered in the DB. /gsd will report "No Active Milestone". ` +
190
+ `Rewrite PROJECT.md so the "Milestone Sequence" section uses canonical lines: ` +
191
+ `\`- [ ] M001: <Title> — <One-liner>\` (em-dash, double-dash \`--\`, or single-dash \`-\` separator), then re-call gsd_summary_save(PROJECT).`,
192
+ }],
193
+ details: {
194
+ operation: "save_summary",
195
+ path: relativePath,
196
+ artifact_type: params.artifact_type,
197
+ error: "milestone_registration_empty_parse",
198
+ },
199
+ isError: true,
200
+ };
159
201
  }
160
202
  }
161
203
  if (params.artifact_type === "CONTEXT" && !params.task_id) {
@@ -178,7 +220,6 @@ export async function executeSummarySave(params, basePath = process.cwd()) {
178
220
  artifact_type: params.artifact_type,
179
221
  content_source: contentSource,
180
222
  ...(registeredMilestones.length > 0 ? { registeredMilestones } : {}),
181
- ...(registrationWarning ? { warning: registrationWarning } : {}),
182
223
  },
183
224
  };
184
225
  }