gsd-pi 2.80.0-dev.cf9433f56 → 2.80.0-dev.d4fc28e6b
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/dist/cli.js +0 -19
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +29 -0
- package/dist/resources/extensions/gsd/auto/loop.js +71 -8
- package/dist/resources/extensions/gsd/auto/phases.js +150 -94
- package/dist/resources/extensions/gsd/auto/resolve.js +12 -0
- package/dist/resources/extensions/gsd/auto/run-unit.js +10 -30
- package/dist/resources/extensions/gsd/auto/session.js +8 -0
- package/dist/resources/extensions/gsd/auto/workflow-dispatch-claim.js +33 -1
- package/dist/resources/extensions/gsd/auto/workflow-worker-heartbeat.js +9 -1
- package/dist/resources/extensions/gsd/auto-direct-dispatch.js +5 -32
- package/dist/resources/extensions/gsd/auto-dispatch.js +16 -0
- package/dist/resources/extensions/gsd/auto-post-unit.js +17 -4
- package/dist/resources/extensions/gsd/auto-prompts.js +90 -15
- package/dist/resources/extensions/gsd/auto-start.js +197 -6
- package/dist/resources/extensions/gsd/auto-worktree.js +111 -1
- package/dist/resources/extensions/gsd/auto.js +18 -22
- package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +86 -19
- package/dist/resources/extensions/gsd/bootstrap/db-tools.js +49 -36
- package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +15 -5
- package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +9 -3
- package/dist/resources/extensions/gsd/bootstrap/journal-tools.js +7 -1
- package/dist/resources/extensions/gsd/bootstrap/memory-tools.js +9 -3
- package/dist/resources/extensions/gsd/bootstrap/query-tools.js +8 -2
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +298 -54
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +82 -23
- package/dist/resources/extensions/gsd/clean-root-preflight.js +24 -6
- package/dist/resources/extensions/gsd/commands-handlers.js +23 -9
- package/dist/resources/extensions/gsd/db/unit-dispatches.js +53 -0
- package/dist/resources/extensions/gsd/ecosystem/gsd-extension-api.js +2 -0
- package/dist/resources/extensions/gsd/guided-flow.js +47 -28
- package/dist/resources/extensions/gsd/native-git-bridge.js +32 -8
- package/dist/resources/extensions/gsd/orphan-stash-audit.js +101 -0
- package/dist/resources/extensions/gsd/parallel-orchestrator.js +13 -3
- package/dist/resources/extensions/gsd/pre-execution-checks.js +15 -0
- package/dist/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
- package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/execute-task.md +4 -2
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/replan-slice.md +2 -2
- package/dist/resources/extensions/gsd/workflow-protocol.js +131 -0
- package/dist/resources/extensions/gsd/worktree-resolver.js +35 -4
- 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 +12 -12
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- 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 +12 -12
- 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/.next/server/server-reference-manifest.json +1 -1
- package/dist/welcome-screen.d.ts +2 -0
- package/dist/welcome-screen.js +9 -7
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +4 -1
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/dist/agent.d.ts +5 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +2 -0
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/dist/index.d.ts +1 -0
- package/packages/pi-agent-core/dist/index.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/index.js +2 -0
- package/packages/pi-agent-core/dist/index.js.map +1 -1
- package/packages/pi-agent-core/dist/token-audit.d.ts +47 -0
- package/packages/pi-agent-core/dist/token-audit.d.ts.map +1 -0
- package/packages/pi-agent-core/dist/token-audit.js +221 -0
- package/packages/pi-agent-core/dist/token-audit.js.map +1 -0
- package/packages/pi-agent-core/dist/types.d.ts +9 -0
- package/packages/pi-agent-core/dist/types.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/types.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.test.ts +128 -0
- package/packages/pi-agent-core/src/agent-loop.ts +4 -1
- package/packages/pi-agent-core/src/agent.ts +8 -0
- package/packages/pi-agent-core/src/index.ts +2 -0
- package/packages/pi-agent-core/src/token-audit.test.ts +189 -0
- package/packages/pi-agent-core/src/token-audit.ts +287 -0
- package/packages/pi-agent-core/src/types.ts +14 -0
- package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js +18 -0
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts +12 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +36 -7
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +8 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +3 -6
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js +3 -3
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +32 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/hooks-runner.test.js +2 -0
- package/packages/pi-coding-agent/dist/core/hooks-runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.js +46 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/sdk.d.ts +10 -2
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +74 -2
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/skill-tool.test.js +22 -0
- package/packages/pi-coding-agent/dist/core/skill-tool.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts +6 -7
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js +2 -3
- package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
- package/packages/pi-coding-agent/src/core/agent-session-tool-refresh.test.ts +25 -0
- package/packages/pi-coding-agent/src/core/agent-session.ts +40 -7
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +10 -0
- package/packages/pi-coding-agent/src/core/extensions/runner.test.ts +3 -3
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +5 -5
- package/packages/pi-coding-agent/src/core/extensions/types.ts +35 -1
- package/packages/pi-coding-agent/src/core/hooks-runner.test.ts +2 -0
- package/packages/pi-coding-agent/src/core/sdk-tool-filter.test.ts +60 -0
- package/packages/pi-coding-agent/src/core/sdk.ts +85 -3
- package/packages/pi-coding-agent/src/core/skill-tool.test.ts +28 -0
- package/packages/pi-coding-agent/src/core/system-prompt.ts +8 -10
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +30 -0
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +26 -0
- package/src/resources/extensions/gsd/auto/loop-deps.ts +2 -2
- package/src/resources/extensions/gsd/auto/loop.ts +84 -8
- package/src/resources/extensions/gsd/auto/phases.ts +218 -154
- package/src/resources/extensions/gsd/auto/resolve.ts +19 -0
- package/src/resources/extensions/gsd/auto/run-unit.ts +10 -29
- package/src/resources/extensions/gsd/auto/session.ts +8 -0
- package/src/resources/extensions/gsd/auto/workflow-dispatch-claim.ts +63 -1
- package/src/resources/extensions/gsd/auto/workflow-worker-heartbeat.ts +14 -1
- package/src/resources/extensions/gsd/auto-direct-dispatch.ts +8 -34
- package/src/resources/extensions/gsd/auto-dispatch.ts +16 -0
- package/src/resources/extensions/gsd/auto-post-unit.ts +18 -4
- package/src/resources/extensions/gsd/auto-prompts.ts +95 -14
- package/src/resources/extensions/gsd/auto-start.ts +230 -9
- package/src/resources/extensions/gsd/auto-worktree.ts +123 -0
- package/src/resources/extensions/gsd/auto.ts +18 -18
- package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +100 -18
- package/src/resources/extensions/gsd/bootstrap/db-tools.ts +50 -36
- package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +16 -5
- package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +10 -3
- package/src/resources/extensions/gsd/bootstrap/journal-tools.ts +8 -1
- package/src/resources/extensions/gsd/bootstrap/memory-tools.ts +10 -3
- package/src/resources/extensions/gsd/bootstrap/query-tools.ts +9 -2
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +347 -54
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +90 -22
- package/src/resources/extensions/gsd/clean-root-preflight.ts +32 -7
- package/src/resources/extensions/gsd/commands-handlers.ts +34 -15
- package/src/resources/extensions/gsd/db/unit-dispatches.ts +66 -0
- package/src/resources/extensions/gsd/ecosystem/gsd-extension-api.ts +3 -0
- package/src/resources/extensions/gsd/guided-flow.ts +52 -35
- package/src/resources/extensions/gsd/native-git-bridge.ts +39 -6
- package/src/resources/extensions/gsd/orphan-stash-audit.ts +117 -0
- package/src/resources/extensions/gsd/parallel-orchestrator.ts +13 -3
- package/src/resources/extensions/gsd/pre-execution-checks.ts +16 -0
- package/src/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
- package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/execute-task.md +4 -2
- package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/replan-slice.md +2 -2
- package/src/resources/extensions/gsd/tests/artifact-retry-cap.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +361 -10
- package/src/resources/extensions/gsd/tests/auto-wrapup-inflight-guard.test.ts +168 -6
- package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +15 -6
- package/src/resources/extensions/gsd/tests/complete-milestone-excerpt.test.ts +31 -0
- package/src/resources/extensions/gsd/tests/complete-slice-composer.test.ts +3 -2
- package/src/resources/extensions/gsd/tests/context-store.test.ts +7 -1
- package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +5 -1
- package/src/resources/extensions/gsd/tests/execute-task-rendering.test.ts +5 -2
- package/src/resources/extensions/gsd/tests/fast-forward-reused-milestone-branch.test.ts +219 -0
- package/src/resources/extensions/gsd/tests/finalize-survivor-branch.test.ts +132 -0
- package/src/resources/extensions/gsd/tests/isolation-none-branch-guard.test.ts +6 -3
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +5 -1
- package/src/resources/extensions/gsd/tests/journal-query-tool.test.ts +32 -0
- package/src/resources/extensions/gsd/tests/knowledge.test.ts +47 -0
- package/src/resources/extensions/gsd/tests/merge-conflict-stops-loop.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/milestone-merge-stash-restore.test.ts +242 -0
- package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +34 -2
- package/src/resources/extensions/gsd/tests/originalbase-path-comparison.test.ts +3 -0
- package/src/resources/extensions/gsd/tests/orphan-merge-bootstrap.test.ts +133 -0
- package/src/resources/extensions/gsd/tests/orphan-stash-audit.test.ts +201 -0
- package/src/resources/extensions/gsd/tests/parallel-orchestrator-fast-forward.test.ts +113 -0
- package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +7 -5
- package/src/resources/extensions/gsd/tests/prompt-duplication-cuts.test.ts +230 -0
- package/src/resources/extensions/gsd/tests/query-tools-db-open.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/restore-tools-after-discuss.test.ts +38 -17
- package/src/resources/extensions/gsd/tests/select-resumable-milestone.test.ts +96 -0
- package/src/resources/extensions/gsd/tests/session-start-footer.test.ts +77 -0
- package/src/resources/extensions/gsd/tests/session-switch-abort-misclassification.test.ts +166 -0
- package/src/resources/extensions/gsd/tests/state-corruption-2945.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/system-context-memory.test.ts +112 -0
- package/src/resources/extensions/gsd/tests/system-context-message-routing.test.ts +7 -9
- package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +291 -0
- package/src/resources/extensions/gsd/tests/unit-dispatches.test.ts +50 -1
- package/src/resources/extensions/gsd/tests/unstructured-continue-context-injection.test.ts +5 -4
- package/src/resources/extensions/gsd/tests/workflow-dispatch-claim.test.ts +142 -0
- package/src/resources/extensions/gsd/tests/workflow-protocol-excerpt.test.ts +99 -0
- package/src/resources/extensions/gsd/tests/workflow-worker-heartbeat.test.ts +32 -1
- package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/worktree-path-injection.test.ts +22 -19
- package/src/resources/extensions/gsd/tests/worktree-project-root-degrade.test.ts +66 -0
- package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +104 -3
- package/src/resources/extensions/gsd/workflow-protocol.ts +160 -0
- package/src/resources/extensions/gsd/worktree-resolver.ts +49 -4
- package/src/resources/extensions/gsd/tests/phases-merge-error-stops-auto.test.ts +0 -97
- /package/dist/web/standalone/.next/static/{-5nHJWzSdG-WkPMul_khA → cWaxzf-sdbSSbbwYu8q7a}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{-5nHJWzSdG-WkPMul_khA → cWaxzf-sdbSSbbwYu8q7a}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: Shared capped workflow protocol and doctor-heal prompt payload helpers.
|
|
3
|
+
|
|
4
|
+
const DEFAULT_WORKFLOW_PROTOCOL_EXCERPT_CHARS = 4_000;
|
|
5
|
+
const MIN_WORKFLOW_PROTOCOL_EXCERPT_CHARS = 1_000;
|
|
6
|
+
const DEFAULT_DOCTOR_SUMMARY_CHARS = 2_400;
|
|
7
|
+
const DEFAULT_DOCTOR_ISSUE_CHARS = 300;
|
|
8
|
+
const DEFAULT_DOCTOR_MAX_ISSUES = 12;
|
|
9
|
+
const DEFAULT_DOCTOR_ISSUES_CHARS = 4_000;
|
|
10
|
+
|
|
11
|
+
export function buildWorkflowProtocolExcerpt(
|
|
12
|
+
workflow: string,
|
|
13
|
+
workflowPath: string,
|
|
14
|
+
opts: { maxChars?: number } = {},
|
|
15
|
+
): string {
|
|
16
|
+
const limit = opts.maxChars ?? getWorkflowProtocolExcerptLimit();
|
|
17
|
+
const trimmed = workflow.trim();
|
|
18
|
+
const excerpt = buildPrioritizedWorkflowExcerpt(trimmed, limit);
|
|
19
|
+
const truncated = trimmed.length > limit;
|
|
20
|
+
const lines = [
|
|
21
|
+
"## GSD Workflow Protocol Excerpt",
|
|
22
|
+
`Source: \`${workflowPath}\``,
|
|
23
|
+
"",
|
|
24
|
+
excerpt,
|
|
25
|
+
];
|
|
26
|
+
if (truncated) {
|
|
27
|
+
lines.push(
|
|
28
|
+
"",
|
|
29
|
+
"[Workflow Protocol Truncated]",
|
|
30
|
+
"The full workflow protocol remains available at the source path above. Read it only if this excerpt lacks a rule required for the dispatched task.",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return lines.join("\n");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function buildWorkflowDispatchContent(opts: {
|
|
37
|
+
workflow: string;
|
|
38
|
+
workflowPath: string;
|
|
39
|
+
task: string;
|
|
40
|
+
maxProtocolChars?: number;
|
|
41
|
+
}): string {
|
|
42
|
+
return [
|
|
43
|
+
"Read the following GSD workflow protocol excerpt and execute exactly. Use the source path for a full protocol read only if the excerpt lacks a required rule.",
|
|
44
|
+
"",
|
|
45
|
+
buildWorkflowProtocolExcerpt(opts.workflow, opts.workflowPath, { maxChars: opts.maxProtocolChars }),
|
|
46
|
+
"",
|
|
47
|
+
"## Your Task",
|
|
48
|
+
"",
|
|
49
|
+
opts.task.trim(),
|
|
50
|
+
].join("\n");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function buildDoctorHealSummary(reportText: string, opts: { maxChars?: number } = {}): string {
|
|
54
|
+
const limit = opts.maxChars ?? DEFAULT_DOCTOR_SUMMARY_CHARS;
|
|
55
|
+
const lines = reportText.split(/\r?\n/).map((line) => line.trimEnd());
|
|
56
|
+
const summaryLines = lines.filter((line) =>
|
|
57
|
+
line.length > 0 && (
|
|
58
|
+
/^#/.test(line) ||
|
|
59
|
+
/^(scope|status|summary|checks?|errors?|warnings?|fixes?|issues?)\b/i.test(line) ||
|
|
60
|
+
/doctor/i.test(line)
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
const selected = summaryLines.length > 0 ? summaryLines : lines.filter((line) => line.trim()).slice(0, 24);
|
|
64
|
+
return capText(selected.join("\n"), limit, "Full doctor report is available in the command output; use the structured issue list below for repairs.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function buildDoctorHealIssuePayload(
|
|
68
|
+
structuredIssues: string,
|
|
69
|
+
opts: { maxIssues?: number; maxIssueChars?: number; maxChars?: number } = {},
|
|
70
|
+
): string {
|
|
71
|
+
const maxIssues = opts.maxIssues ?? DEFAULT_DOCTOR_MAX_ISSUES;
|
|
72
|
+
const maxIssueChars = opts.maxIssueChars ?? DEFAULT_DOCTOR_ISSUE_CHARS;
|
|
73
|
+
const maxChars = opts.maxChars ?? DEFAULT_DOCTOR_ISSUES_CHARS;
|
|
74
|
+
const blocks = splitIssueBlocks(structuredIssues);
|
|
75
|
+
const topBlocks = blocks.slice(0, maxIssues).map((block) =>
|
|
76
|
+
capText(block, maxIssueChars, "Issue details truncated; inspect the relevant artifact before editing."),
|
|
77
|
+
);
|
|
78
|
+
if (blocks.length > maxIssues) {
|
|
79
|
+
topBlocks.push(`[${blocks.length - maxIssues} additional actionable issue(s) omitted from prompt. Re-run /gsd doctor heal after this repair pass.]`);
|
|
80
|
+
}
|
|
81
|
+
return capText(topBlocks.join("\n\n"), maxChars, "Structured issue list truncated; repair top actionable issues first and re-run doctor heal.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getWorkflowProtocolExcerptLimit(): number {
|
|
85
|
+
const raw = process.env.PI_GSD_WORKFLOW_PROTOCOL_MAX_CHARS;
|
|
86
|
+
if (!raw) return DEFAULT_WORKFLOW_PROTOCOL_EXCERPT_CHARS;
|
|
87
|
+
const parsed = Number(raw);
|
|
88
|
+
if (!Number.isFinite(parsed) || parsed < MIN_WORKFLOW_PROTOCOL_EXCERPT_CHARS) {
|
|
89
|
+
return DEFAULT_WORKFLOW_PROTOCOL_EXCERPT_CHARS;
|
|
90
|
+
}
|
|
91
|
+
return Math.floor(parsed);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function buildPrioritizedWorkflowExcerpt(workflow: string, limit: number): string {
|
|
95
|
+
if (workflow.length <= limit) return workflow;
|
|
96
|
+
const sections = splitMarkdownSections(workflow);
|
|
97
|
+
const wanted = [
|
|
98
|
+
/^# /,
|
|
99
|
+
/^## Quick Start\b/i,
|
|
100
|
+
/^## The Hierarchy\b/i,
|
|
101
|
+
/^## The Phases\b/i,
|
|
102
|
+
/^### Phase 4: Execute\b/i,
|
|
103
|
+
/^### Phase 5: Verify\b/i,
|
|
104
|
+
/^### Observable Truths\b/i,
|
|
105
|
+
/^### Artifacts\b/i,
|
|
106
|
+
/^### Key Links\b/i,
|
|
107
|
+
/^### Phase 6: Summarize\b/i,
|
|
108
|
+
/^### Phase 7: Advance\b/i,
|
|
109
|
+
];
|
|
110
|
+
const selected: string[] = [];
|
|
111
|
+
const used = new Set<number>();
|
|
112
|
+
for (const pattern of wanted) {
|
|
113
|
+
const index = sections.findIndex((section, sectionIndex) =>
|
|
114
|
+
!used.has(sectionIndex) && pattern.test(section.heading),
|
|
115
|
+
);
|
|
116
|
+
if (index >= 0) {
|
|
117
|
+
used.add(index);
|
|
118
|
+
selected.push(sections[index].text);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const body = selected.length > 0 ? selected.join("\n\n") : workflow;
|
|
122
|
+
return capText(body, limit, "Workflow protocol excerpt capped; read the source path for omitted details.");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function splitMarkdownSections(markdown: string): Array<{ heading: string; text: string }> {
|
|
126
|
+
const lines = markdown.split(/\r?\n/);
|
|
127
|
+
const sections: Array<{ heading: string; text: string }> = [];
|
|
128
|
+
let currentHeading = lines[0]?.startsWith("#") ? lines[0] : "# Preamble";
|
|
129
|
+
let current: string[] = [];
|
|
130
|
+
for (const line of lines) {
|
|
131
|
+
if (/^#{1,3}\s+/.test(line) && current.length > 0) {
|
|
132
|
+
sections.push({ heading: currentHeading, text: current.join("\n").trim() });
|
|
133
|
+
currentHeading = line;
|
|
134
|
+
current = [line];
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (/^#{1,3}\s+/.test(line)) currentHeading = line;
|
|
138
|
+
current.push(line);
|
|
139
|
+
}
|
|
140
|
+
if (current.length > 0) {
|
|
141
|
+
sections.push({ heading: currentHeading, text: current.join("\n").trim() });
|
|
142
|
+
}
|
|
143
|
+
return sections.filter((section) => section.text.length > 0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function splitIssueBlocks(structuredIssues: string): string[] {
|
|
147
|
+
const trimmed = structuredIssues.trim();
|
|
148
|
+
if (!trimmed) return ["No structured issue details were provided."];
|
|
149
|
+
const split = trimmed.split(/\n(?=(?:#{2,6}\s+|\d+\.\s+|- \*\*|- \[[ x]\]))/i)
|
|
150
|
+
.map((block) => block.trim())
|
|
151
|
+
.filter(Boolean);
|
|
152
|
+
return split.length > 0 ? split : [trimmed];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function capText(text: string, limit: number, notice: string): string {
|
|
156
|
+
if (text.length <= limit) return text;
|
|
157
|
+
const suffix = `\n\n[Truncated]\n${notice}`;
|
|
158
|
+
const headBudget = Math.max(0, limit - suffix.length);
|
|
159
|
+
return `${text.slice(0, headBudget).trimEnd()}${suffix}`;
|
|
160
|
+
}
|
|
@@ -40,6 +40,16 @@ function isSamePath(a: string, b: string): boolean {
|
|
|
40
40
|
return normalizeWorktreePathForCompare(a) === normalizeWorktreePathForCompare(b);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
class UserNotifiedError extends Error {
|
|
44
|
+
readonly cause?: unknown;
|
|
45
|
+
|
|
46
|
+
constructor(message: string, cause?: unknown) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = "UserNotifiedError";
|
|
49
|
+
this.cause = cause;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
43
53
|
// ─── Dependency Interface ──────────────────────────────────────────────────
|
|
44
54
|
|
|
45
55
|
export interface WorktreeResolverDeps {
|
|
@@ -71,6 +81,13 @@ export interface WorktreeResolverDeps {
|
|
|
71
81
|
milestoneId: string,
|
|
72
82
|
) => void;
|
|
73
83
|
getCurrentBranch: (basePath: string) => string;
|
|
84
|
+
/**
|
|
85
|
+
* Force-checkout the named branch in `basePath`. Required by `_mergeBranchMode`
|
|
86
|
+
* when it discovers the working tree is not on the milestone branch — preflight
|
|
87
|
+
* stash + later operations may have switched HEAD to main, and silently skipping
|
|
88
|
+
* the merge would strand the milestone's commits.
|
|
89
|
+
*/
|
|
90
|
+
checkoutBranch: (basePath: string, branch: string) => void;
|
|
74
91
|
autoWorktreeBranch: (milestoneId: string) => string;
|
|
75
92
|
resolveMilestoneFile: (
|
|
76
93
|
basePath: string,
|
|
@@ -824,16 +841,41 @@ export class WorktreeResolver {
|
|
|
824
841
|
const milestoneBranch = this.deps.autoWorktreeBranch(milestoneId);
|
|
825
842
|
|
|
826
843
|
if (currentBranch !== milestoneBranch) {
|
|
844
|
+
// #5538-followup: previous behavior was to silently `return false`
|
|
845
|
+
// when HEAD wasn't on the milestone branch — that let the loop
|
|
846
|
+
// advance with the milestone's commits stranded on the branch (the
|
|
847
|
+
// exact failure mode reported in the test12345 repro). Attempt
|
|
848
|
+
// recovery by force-checking-out the milestone branch; if the
|
|
849
|
+
// checkout fails, throw so the caller pauses auto-mode and the user
|
|
850
|
+
// sees the failure instead of a silent merge skip.
|
|
827
851
|
debugLog("WorktreeResolver", {
|
|
828
852
|
action: "mergeAndExit",
|
|
829
853
|
milestoneId,
|
|
830
854
|
mode: "branch",
|
|
831
|
-
|
|
832
|
-
reason: "not-on-milestone-branch",
|
|
855
|
+
recovery: "checkout-milestone-branch",
|
|
833
856
|
currentBranch,
|
|
834
857
|
milestoneBranch,
|
|
835
858
|
});
|
|
836
|
-
|
|
859
|
+
try {
|
|
860
|
+
this.deps.checkoutBranch(this.s.basePath, milestoneBranch);
|
|
861
|
+
} catch (checkoutErr) {
|
|
862
|
+
const checkoutMsg = checkoutErr instanceof Error ? checkoutErr.message : String(checkoutErr);
|
|
863
|
+
ctx.notify(
|
|
864
|
+
`Cannot merge milestone ${milestoneId}: working tree is on ${currentBranch} and checkout to ${milestoneBranch} failed (${checkoutMsg}). Resolve manually and run /gsd auto to resume.`,
|
|
865
|
+
"error",
|
|
866
|
+
);
|
|
867
|
+
throw new UserNotifiedError(checkoutMsg, checkoutErr);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
const reverify = this.deps.getCurrentBranch(this.s.basePath);
|
|
871
|
+
if (reverify !== milestoneBranch) {
|
|
872
|
+
const reverifyMsg = `branch checkout to ${milestoneBranch} reported success but current branch is ${reverify}`;
|
|
873
|
+
ctx.notify(
|
|
874
|
+
`Cannot merge milestone ${milestoneId}: ${reverifyMsg}. Resolve manually and run /gsd auto to resume.`,
|
|
875
|
+
"error",
|
|
876
|
+
);
|
|
877
|
+
throw new UserNotifiedError(reverifyMsg);
|
|
878
|
+
}
|
|
837
879
|
}
|
|
838
880
|
|
|
839
881
|
const roadmapPath = this.deps.resolveMilestoneFile(
|
|
@@ -890,7 +932,9 @@ export class WorktreeResolver {
|
|
|
890
932
|
result: "error",
|
|
891
933
|
error: msg,
|
|
892
934
|
});
|
|
893
|
-
|
|
935
|
+
if (!(err instanceof UserNotifiedError)) {
|
|
936
|
+
ctx.notify(`Milestone merge failed (branch mode): ${msg}`, "warning");
|
|
937
|
+
}
|
|
894
938
|
// Re-throw all errors so callers can apply their own recovery logic (#4380).
|
|
895
939
|
throw err;
|
|
896
940
|
}
|
|
@@ -918,6 +962,7 @@ export class WorktreeResolver {
|
|
|
918
962
|
try {
|
|
919
963
|
this.mergeAndExit(currentMilestoneId, ctx);
|
|
920
964
|
} catch (err) {
|
|
965
|
+
if (err instanceof UserNotifiedError) throw err;
|
|
921
966
|
// mergeAndExit emits a warning and restores state when it fails during
|
|
922
967
|
// merge/cleanup. But if it throws before recovery runs (e.g., in
|
|
923
968
|
// validateMilestoneId or emitJournalEvent), basePath won't be restored
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* phases-merge-error-stops-auto.test.ts — Regression test for #2766.
|
|
3
|
-
*
|
|
4
|
-
* When mergeAndExit throws a non-MergeConflictError, the auto loop must
|
|
5
|
-
* stop instead of continuing with unmerged work. This test verifies that
|
|
6
|
-
* all catch blocks in auto/phases.ts that handle mergeAndExit errors
|
|
7
|
-
* call stopAuto and return { action: "break" } for non-conflict errors.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { readFileSync } from "node:fs";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { createTestContext } from "./test-helpers.ts";
|
|
13
|
-
|
|
14
|
-
const { assertTrue, report } = createTestContext();
|
|
15
|
-
|
|
16
|
-
const phasesPath = join(import.meta.dirname, "..", "auto", "phases.ts");
|
|
17
|
-
const phasesSrc = readFileSync(phasesPath, "utf-8");
|
|
18
|
-
|
|
19
|
-
console.log("\n=== #2766: Non-MergeConflictError stops auto mode ===");
|
|
20
|
-
|
|
21
|
-
// ── Test 1: every mergeAndExit call site has a catch (mergeErr) block ──
|
|
22
|
-
|
|
23
|
-
// Count all mergeAndExit catch blocks by finding "} catch (mergeErr)" patterns
|
|
24
|
-
const mergeAndExitCallCount = [...phasesSrc.matchAll(/\.mergeAndExit\(/g)].length;
|
|
25
|
-
const mergeErrCatchCount = [...phasesSrc.matchAll(/\} catch \(mergeErr\)/g)].length;
|
|
26
|
-
assertTrue(
|
|
27
|
-
mergeErrCatchCount === mergeAndExitCallCount && mergeAndExitCallCount > 0,
|
|
28
|
-
`every mergeAndExit call site has a catch (mergeErr) block (calls=${mergeAndExitCallCount}, catches=${mergeErrCatchCount})`,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// ── Test 2: Every mergeErr catch block handles non-MergeConflictError ───
|
|
32
|
-
|
|
33
|
-
// Find each catch block and verify it has the non-conflict error handling pattern
|
|
34
|
-
const catchPattern = /\} catch \(mergeErr\) \{/g;
|
|
35
|
-
let match;
|
|
36
|
-
let blocksWithNonConflictHandling = 0;
|
|
37
|
-
let blocksTotal = 0;
|
|
38
|
-
|
|
39
|
-
while ((match = catchPattern.exec(phasesSrc)) !== null) {
|
|
40
|
-
blocksTotal++;
|
|
41
|
-
// Look at the ~800 chars after the catch to find both the MergeConflictError
|
|
42
|
-
// instanceof check AND the non-conflict handling
|
|
43
|
-
const afterCatch = phasesSrc.slice(match.index, match.index + 1200);
|
|
44
|
-
|
|
45
|
-
const hasInstanceofCheck = afterCatch.includes("instanceof MergeConflictError");
|
|
46
|
-
const hasNonConflictStop = afterCatch.includes('reason: "merge-failed"');
|
|
47
|
-
const hasStopAuto = afterCatch.includes("stopAuto");
|
|
48
|
-
const hasLogError = afterCatch.includes("logError");
|
|
49
|
-
|
|
50
|
-
if (hasInstanceofCheck && hasNonConflictStop && hasStopAuto && hasLogError) {
|
|
51
|
-
blocksWithNonConflictHandling++;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
assertTrue(
|
|
56
|
-
blocksWithNonConflictHandling === blocksTotal && blocksTotal >= 3,
|
|
57
|
-
`all ${blocksTotal} mergeAndExit catch blocks stop auto on non-conflict errors (${blocksWithNonConflictHandling}/${blocksTotal})`,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// ── Test 3: Non-conflict handler returns break (does not continue) ──────
|
|
61
|
-
|
|
62
|
-
// Verify the pattern: after the MergeConflictError instanceof block,
|
|
63
|
-
// the non-conflict path returns { action: "break", reason: "merge-failed" }
|
|
64
|
-
const mergeFailedReasons = [...phasesSrc.matchAll(/reason: "merge-failed"/g)].length;
|
|
65
|
-
assertTrue(
|
|
66
|
-
mergeFailedReasons >= 3,
|
|
67
|
-
`all catch blocks return reason: "merge-failed" (found ${mergeFailedReasons}, expected >= 3)`,
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
// ── Test 4: Non-conflict handler notifies user ──────────────────────────
|
|
71
|
-
|
|
72
|
-
// Each non-conflict block should call ctx.ui.notify with error severity
|
|
73
|
-
const notifyErrorPattern = /Merge failed:.*Resolve and run \/gsd auto to resume/g;
|
|
74
|
-
const notifyCount = [...phasesSrc.matchAll(notifyErrorPattern)].length;
|
|
75
|
-
assertTrue(
|
|
76
|
-
notifyCount >= 3,
|
|
77
|
-
`all catch blocks notify user about merge failure (found ${notifyCount}, expected >= 3)`,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
// ── Test 5: logError replaces logWarning for non-conflict merge errors ──
|
|
81
|
-
|
|
82
|
-
// The old code used logWarning — verify logError is used instead
|
|
83
|
-
const logWarningMergePattern = /logWarning\(.*Milestone merge failed with non-conflict error/g;
|
|
84
|
-
const logWarningCount = [...phasesSrc.matchAll(logWarningMergePattern)].length;
|
|
85
|
-
assertTrue(
|
|
86
|
-
logWarningCount === 0,
|
|
87
|
-
"logWarning is no longer used for non-conflict merge errors (replaced by logError)",
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const logErrorMergePattern = /logError\(.*Milestone merge failed with non-conflict error/g;
|
|
91
|
-
const logErrorCount = [...phasesSrc.matchAll(logErrorMergePattern)].length;
|
|
92
|
-
assertTrue(
|
|
93
|
-
logErrorCount >= 3,
|
|
94
|
-
`logError is used for non-conflict merge errors (found ${logErrorCount}, expected >= 3)`,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
report();
|
|
File without changes
|
|
File without changes
|