gsd-pi 2.73.0 → 2.73.1-dev.d987996
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 -47
- package/dist/help-text.js +1 -1
- package/dist/resources/extensions/gsd/auto-dispatch.js +5 -3
- package/dist/resources/extensions/gsd/auto-prompts.js +9 -6
- package/dist/resources/extensions/gsd/auto.js +5 -1
- package/dist/resources/extensions/gsd/bootstrap/crash-log.js +31 -0
- package/dist/resources/extensions/gsd/bootstrap/register-extension.js +18 -7
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +6 -1
- package/dist/resources/extensions/gsd/crash-recovery.js +51 -0
- package/dist/resources/extensions/gsd/gsd-db.js +36 -2
- package/dist/resources/extensions/gsd/milestone-actions.js +19 -1
- package/dist/startup-model-validation.js +8 -5
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +11 -11
- package/dist/web/standalone/.next/build-manifest.json +3 -3
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/required-server-files.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error/page.js +3 -3
- package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- 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/page.js +2 -2
- package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +3 -3
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
- 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 +3 -3
- 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/api/boot/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/boot/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/browse-directories/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/browse-directories/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/dev-mode/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/dev-mode/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/experimental/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/experimental/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/notifications/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/notifications/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/preferences/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/preferences/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/remote-questions/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/remote-questions/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/events/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/session/events/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/shutdown/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/shutdown/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/terminal/input/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/terminal/resize/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +4 -4
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/upload/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/upload/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/update/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +4 -4
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
- 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 +3 -3
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/page.js +2 -2
- package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +11 -11
- package/dist/web/standalone/.next/server/chunks/63.js +3 -3
- package/dist/web/standalone/.next/server/chunks/6897.js +1 -1
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
- package/dist/web/standalone/.next/server/middleware.js +2 -2
- package/dist/web/standalone/.next/server/next-font-manifest.js +1 -1
- package/dist/web/standalone/.next/server/next-font-manifest.json +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/web/standalone/.next/static/chunks/app/_not-found/{page-2f24283c162b6ab3.js → page-f2a7482d42a5614b.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/app/{layout-9ecfd95f343793f0.js → layout-a16c7a7ecdf0c2cf.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/app/page-f1e30ab6bb269149.js +1 -0
- package/dist/web/standalone/.next/static/chunks/main-app-fdab67f7802d7832.js +1 -0
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-459824ffb8c323dd.js +1 -0
- 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/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api.target.mk +14 -14
- package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api_except.target.mk +14 -14
- package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api_maybe.target.mk +14 -14
- package/dist/web/standalone/server.js +1 -1
- package/package.json +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.js +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js +27 -0
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-resolver.js +25 -68
- package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +22 -9
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js +63 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js.map +1 -0
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/auth-storage.test.ts +38 -0
- package/packages/pi-coding-agent/src/core/auth-storage.ts +1 -1
- package/packages/pi-coding-agent/src/core/model-resolver.ts +26 -70
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.test.ts +71 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +23 -9
- package/pkg/package.json +1 -1
- package/src/resources/extensions/gsd/auto-dispatch.ts +5 -0
- package/src/resources/extensions/gsd/auto-prompts.ts +9 -3
- package/src/resources/extensions/gsd/auto.ts +5 -0
- package/src/resources/extensions/gsd/bootstrap/crash-log.ts +32 -0
- package/src/resources/extensions/gsd/bootstrap/register-extension.ts +19 -7
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +8 -1
- package/src/resources/extensions/gsd/crash-recovery.ts +59 -0
- package/src/resources/extensions/gsd/gsd-db.ts +52 -2
- package/src/resources/extensions/gsd/milestone-actions.ts +19 -1
- package/src/resources/extensions/gsd/tests/crash-handler-secondary.test.ts +235 -0
- package/src/resources/extensions/gsd/tests/gsd-db.test.ts +59 -1
- package/src/resources/extensions/gsd/tests/park-milestone.test.ts +64 -0
- package/src/resources/extensions/gsd/tests/subagent-model-dispatch.test.ts +267 -0
- package/dist/web/standalone/.next/static/chunks/app/page-7115e62689b5fd84.js +0 -1
- package/dist/web/standalone/.next/static/chunks/main-app-d3d4c336195465f9.js +0 -1
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-ab5a8926e07ec673.js +0 -1
- /package/dist/web/standalone/.next/static/{KSZ2dcC3p4z6lOmUpPpzr → cGmbVq2su4f9tMpgIkG8u}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{KSZ2dcC3p4z6lOmUpPpzr → cGmbVq2su4f9tMpgIkG8u}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { findLatestPinnableText } from "./chat-controller.js";
|
|
4
|
+
test("findLatestPinnableText: empty content returns empty string", () => {
|
|
5
|
+
assert.equal(findLatestPinnableText([]), "");
|
|
6
|
+
});
|
|
7
|
+
test("findLatestPinnableText: no tool calls returns empty string", () => {
|
|
8
|
+
const blocks = [
|
|
9
|
+
{ type: "text", text: "hello" },
|
|
10
|
+
{ type: "text", text: "world" },
|
|
11
|
+
];
|
|
12
|
+
assert.equal(findLatestPinnableText(blocks), "");
|
|
13
|
+
});
|
|
14
|
+
test("findLatestPinnableText: returns text preceding a tool call", () => {
|
|
15
|
+
const blocks = [
|
|
16
|
+
{ type: "text", text: "doing the thing" },
|
|
17
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
18
|
+
];
|
|
19
|
+
assert.equal(findLatestPinnableText(blocks), "doing the thing");
|
|
20
|
+
});
|
|
21
|
+
test("findLatestPinnableText: ignores trailing streaming text after the last tool call (regression: pinned mirror duplicated chat-container tokens)", () => {
|
|
22
|
+
const blocks = [
|
|
23
|
+
{ type: "text", text: "first prose" },
|
|
24
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
25
|
+
{ type: "text", text: "second prose still streaming" },
|
|
26
|
+
];
|
|
27
|
+
assert.equal(findLatestPinnableText(blocks), "first prose");
|
|
28
|
+
});
|
|
29
|
+
test("findLatestPinnableText: with multiple tools, picks text before the most recent tool call", () => {
|
|
30
|
+
const blocks = [
|
|
31
|
+
{ type: "text", text: "first" },
|
|
32
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
33
|
+
{ type: "text", text: "second" },
|
|
34
|
+
{ type: "toolCall", id: "2", name: "Grep" },
|
|
35
|
+
{ type: "text", text: "third streaming" },
|
|
36
|
+
];
|
|
37
|
+
assert.equal(findLatestPinnableText(blocks), "second");
|
|
38
|
+
});
|
|
39
|
+
test("findLatestPinnableText: treats serverToolUse the same as toolCall", () => {
|
|
40
|
+
const blocks = [
|
|
41
|
+
{ type: "text", text: "before web search" },
|
|
42
|
+
{ type: "serverToolUse", id: "ws1", name: "web_search" },
|
|
43
|
+
{ type: "text", text: "answer streaming" },
|
|
44
|
+
];
|
|
45
|
+
assert.equal(findLatestPinnableText(blocks), "before web search");
|
|
46
|
+
});
|
|
47
|
+
test("findLatestPinnableText: skips empty/whitespace-only text blocks", () => {
|
|
48
|
+
const blocks = [
|
|
49
|
+
{ type: "text", text: "real prose" },
|
|
50
|
+
{ type: "text", text: " " },
|
|
51
|
+
{ type: "text", text: "" },
|
|
52
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
53
|
+
];
|
|
54
|
+
assert.equal(findLatestPinnableText(blocks), "real prose");
|
|
55
|
+
});
|
|
56
|
+
test("findLatestPinnableText: thinking blocks are not pinnable", () => {
|
|
57
|
+
const blocks = [
|
|
58
|
+
{ type: "thinking", thinking: "internal" },
|
|
59
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
60
|
+
];
|
|
61
|
+
assert.equal(findLatestPinnableText(blocks), "");
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=chat-controller.test.js.map
|
package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-controller.test.js","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.test.ts"],"names":[],"mappings":"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","sourcesContent":["import assert from \"node:assert/strict\";\nimport test from \"node:test\";\n\nimport { findLatestPinnableText } from \"./chat-controller.js\";\n\ntest(\"findLatestPinnableText: empty content returns empty string\", () => {\n\tassert.equal(findLatestPinnableText([]), \"\");\n});\n\ntest(\"findLatestPinnableText: no tool calls returns empty string\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"hello\" },\n\t\t{ type: \"text\", text: \"world\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"\");\n});\n\ntest(\"findLatestPinnableText: returns text preceding a tool call\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"doing the thing\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"doing the thing\");\n});\n\ntest(\"findLatestPinnableText: ignores trailing streaming text after the last tool call (regression: pinned mirror duplicated chat-container tokens)\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"first prose\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t\t{ type: \"text\", text: \"second prose still streaming\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"first prose\");\n});\n\ntest(\"findLatestPinnableText: with multiple tools, picks text before the most recent tool call\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"first\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t\t{ type: \"text\", text: \"second\" },\n\t\t{ type: \"toolCall\", id: \"2\", name: \"Grep\" },\n\t\t{ type: \"text\", text: \"third streaming\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"second\");\n});\n\ntest(\"findLatestPinnableText: treats serverToolUse the same as toolCall\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"before web search\" },\n\t\t{ type: \"serverToolUse\", id: \"ws1\", name: \"web_search\" },\n\t\t{ type: \"text\", text: \"answer streaming\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"before web search\");\n});\n\ntest(\"findLatestPinnableText: skips empty/whitespace-only text blocks\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"real prose\" },\n\t\t{ type: \"text\", text: \" \" },\n\t\t{ type: \"text\", text: \"\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"real prose\");\n});\n\ntest(\"findLatestPinnableText: thinking blocks are not pinnable\", () => {\n\tconst blocks = [\n\t\t{ type: \"thinking\", thinking: \"internal\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"\");\n});\n"]}
|
|
@@ -531,3 +531,41 @@ describe("AuthStorage — getEarliestBackoffExpiry", () => {
|
|
|
531
531
|
assert.equal(expiry, nearExpiry, "should return the nearest (smallest) expiry");
|
|
532
532
|
});
|
|
533
533
|
});
|
|
534
|
+
|
|
535
|
+
// ─── localhost baseUrl shortcut ────────────────────────────────────────────────
|
|
536
|
+
|
|
537
|
+
describe("AuthStorage — localhost baseUrl shortcut", () => {
|
|
538
|
+
it("returns 'local-no-key-needed' for localhost provider with no configured key", async () => {
|
|
539
|
+
const storage = inMemory({});
|
|
540
|
+
const key = await storage.getApiKey("ollama", undefined, { baseUrl: "http://localhost:11434" });
|
|
541
|
+
assert.equal(key, "local-no-key-needed");
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("returns 'local-no-key-needed' for 127.0.0.1 provider with no configured key", async () => {
|
|
545
|
+
const storage = inMemory({});
|
|
546
|
+
const key = await storage.getApiKey("custom", undefined, { baseUrl: "http://127.0.0.1:8080/v1" });
|
|
547
|
+
assert.equal(key, "local-no-key-needed");
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("returns configured key from fallback resolver for localhost custom provider (#4106)", async () => {
|
|
551
|
+
// Regression test: compaction called getApiKey(model) where model.baseUrl is localhost.
|
|
552
|
+
// The localhost shortcut must NOT override an explicitly configured apiKey from models.json.
|
|
553
|
+
const storage = inMemory({});
|
|
554
|
+
storage.setFallbackResolver((provider) =>
|
|
555
|
+
provider === "cliproxy" ? "sk-real-proxy-key" : undefined,
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
const key = await storage.getApiKey("cliproxy", undefined, { baseUrl: "http://localhost:8317/v1" });
|
|
559
|
+
assert.equal(key, "sk-real-proxy-key");
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("returns configured key from fallback resolver when baseUrl uses 127.0.0.1 (#4106)", async () => {
|
|
563
|
+
const storage = inMemory({});
|
|
564
|
+
storage.setFallbackResolver((provider) =>
|
|
565
|
+
provider === "myproxy" ? "sk-myproxy-key" : undefined,
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
const key = await storage.getApiKey("myproxy", undefined, { baseUrl: "http://127.0.0.1:9000/v1" });
|
|
569
|
+
assert.equal(key, "sk-myproxy-key");
|
|
570
|
+
});
|
|
571
|
+
});
|
|
@@ -819,7 +819,7 @@ export class AuthStorage {
|
|
|
819
819
|
*/
|
|
820
820
|
async getApiKey(providerId: string, sessionId?: string, options?: { baseUrl?: string }): Promise<string | undefined> {
|
|
821
821
|
// If the model has a local baseUrl, return a dummy key to avoid auth blocking
|
|
822
|
-
if (options?.baseUrl) {
|
|
822
|
+
if (options?.baseUrl && !this.fallbackResolver?.(providerId)) {
|
|
823
823
|
try {
|
|
824
824
|
const hostname = new URL(options.baseUrl).hostname;
|
|
825
825
|
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
@@ -3,45 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { ThinkingLevel } from "@gsd/pi-agent-core";
|
|
6
|
-
import { type Api, type
|
|
6
|
+
import { type Api, type Model, modelsAreEqual } from "@gsd/pi-ai";
|
|
7
7
|
import chalk from "chalk";
|
|
8
8
|
import { minimatch } from "minimatch";
|
|
9
9
|
import { isValidThinkingLevel } from "../cli/args.js";
|
|
10
10
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
11
11
|
import type { ModelRegistry } from "./model-registry.js";
|
|
12
12
|
|
|
13
|
-
/** Default model IDs for each known provider */
|
|
14
|
-
const defaultModelPerProvider: Record<KnownProvider, string> = {
|
|
15
|
-
"amazon-bedrock": "us.anthropic.claude-opus-4-6-v1",
|
|
16
|
-
anthropic: "claude-opus-4-6",
|
|
17
|
-
"anthropic-vertex": "claude-sonnet-4-6",
|
|
18
|
-
openai: "gpt-5.4",
|
|
19
|
-
"azure-openai-responses": "gpt-5.2",
|
|
20
|
-
"openai-codex": "gpt-5.4",
|
|
21
|
-
google: "gemini-2.5-pro",
|
|
22
|
-
"google-gemini-cli": "gemini-2.5-pro",
|
|
23
|
-
"google-antigravity": "gemini-3.1-pro-high",
|
|
24
|
-
"google-vertex": "gemini-3-pro-preview",
|
|
25
|
-
"github-copilot": "gpt-4o",
|
|
26
|
-
openrouter: "openai/gpt-5.1-codex",
|
|
27
|
-
"vercel-ai-gateway": "anthropic/claude-opus-4-6",
|
|
28
|
-
xai: "grok-4-fast-non-reasoning",
|
|
29
|
-
groq: "openai/gpt-oss-120b",
|
|
30
|
-
cerebras: "zai-glm-4.6",
|
|
31
|
-
zai: "glm-4.6",
|
|
32
|
-
mistral: "devstral-medium-latest",
|
|
33
|
-
minimax: "MiniMax-M2.1",
|
|
34
|
-
"minimax-cn": "MiniMax-M2.1",
|
|
35
|
-
huggingface: "moonshotai/Kimi-K2.5",
|
|
36
|
-
opencode: "claude-opus-4-6",
|
|
37
|
-
"opencode-go": "kimi-k2.5",
|
|
38
|
-
"kimi-coding": "kimi-k2-thinking",
|
|
39
|
-
"alibaba-coding-plan": "qwen3.5-plus",
|
|
40
|
-
"alibaba-dashscope": "qwen3.5-plus",
|
|
41
|
-
ollama: "llama3.1:8b",
|
|
42
|
-
"ollama-cloud": "qwen3:32b",
|
|
43
|
-
};
|
|
44
|
-
|
|
45
13
|
export interface ScopedModel {
|
|
46
14
|
model: Model<Api>;
|
|
47
15
|
/** Thinking level if explicitly specified in pattern (e.g., "model:high"), undefined otherwise */
|
|
@@ -123,10 +91,11 @@ function buildFallbackModel(provider: string, modelId: string, availableModels:
|
|
|
123
91
|
const providerModels = availableModels.filter((m) => m.provider === provider);
|
|
124
92
|
if (providerModels.length === 0) return undefined;
|
|
125
93
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
94
|
+
// Use the first available model from this provider as a template for
|
|
95
|
+
// capabilities (context window, reasoning support, etc.). The user is
|
|
96
|
+
// explicitly providing a custom model id, so we just need any shape of
|
|
97
|
+
// model from the same provider to inherit from.
|
|
98
|
+
const baseModel = providerModels[0];
|
|
130
99
|
|
|
131
100
|
return {
|
|
132
101
|
...baseModel,
|
|
@@ -503,33 +472,19 @@ export async function findInitialModel(options: {
|
|
|
503
472
|
};
|
|
504
473
|
}
|
|
505
474
|
|
|
506
|
-
// 3. Try saved default from settings
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
if (recommendedId && recommendedId !== defaultModelId && recommendedId.startsWith(defaultModelId)) {
|
|
518
|
-
const recommended = modelRegistry.find(defaultProvider, recommendedId);
|
|
519
|
-
if (recommended) {
|
|
520
|
-
model = recommended;
|
|
521
|
-
if (defaultThinkingLevel) {
|
|
522
|
-
thinkingLevel = defaultThinkingLevel;
|
|
523
|
-
}
|
|
524
|
-
return { model, thinkingLevel, fallbackMessage: undefined };
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
model = found;
|
|
528
|
-
if (defaultThinkingLevel) {
|
|
529
|
-
thinkingLevel = defaultThinkingLevel;
|
|
530
|
-
}
|
|
531
|
-
return { model, thinkingLevel, fallbackMessage: undefined };
|
|
475
|
+
// 3. Try saved default from settings — use it exactly as configured.
|
|
476
|
+
// Whatever the user chose is what gets used; no silent substitution.
|
|
477
|
+
// Skip the saved default if its provider is not request-ready (no auth
|
|
478
|
+
// available) so we fall through to an actually-usable model instead of
|
|
479
|
+
// returning a stale selection every selector surface would display.
|
|
480
|
+
if (defaultProvider && defaultModelId && modelRegistry.isProviderRequestReady(defaultProvider)) {
|
|
481
|
+
const found = modelRegistry.find(defaultProvider, defaultModelId);
|
|
482
|
+
if (found) {
|
|
483
|
+
model = found;
|
|
484
|
+
if (defaultThinkingLevel) {
|
|
485
|
+
thinkingLevel = defaultThinkingLevel;
|
|
532
486
|
}
|
|
487
|
+
return { model, thinkingLevel, fallbackMessage: undefined };
|
|
533
488
|
}
|
|
534
489
|
}
|
|
535
490
|
|
|
@@ -537,16 +492,17 @@ export async function findInitialModel(options: {
|
|
|
537
492
|
const availableModels = await modelRegistry.getAvailable();
|
|
538
493
|
|
|
539
494
|
if (availableModels.length > 0) {
|
|
540
|
-
//
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const
|
|
544
|
-
if (
|
|
545
|
-
return { model:
|
|
495
|
+
// Prefer a model from the user's saved provider if any is still available —
|
|
496
|
+
// provider stickiness, not a hard-coded Anthropic/OpenAI preference.
|
|
497
|
+
if (defaultProvider) {
|
|
498
|
+
const sameProvider = availableModels.find((m) => m.provider === defaultProvider);
|
|
499
|
+
if (sameProvider) {
|
|
500
|
+
return { model: sameProvider, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
|
|
546
501
|
}
|
|
547
502
|
}
|
|
548
503
|
|
|
549
|
-
//
|
|
504
|
+
// Otherwise use the first available — registry order reflects models.json
|
|
505
|
+
// order, which the user controls.
|
|
550
506
|
return { model: availableModels[0], thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
|
|
551
507
|
}
|
|
552
508
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { findLatestPinnableText } from "./chat-controller.js";
|
|
5
|
+
|
|
6
|
+
test("findLatestPinnableText: empty content returns empty string", () => {
|
|
7
|
+
assert.equal(findLatestPinnableText([]), "");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("findLatestPinnableText: no tool calls returns empty string", () => {
|
|
11
|
+
const blocks = [
|
|
12
|
+
{ type: "text", text: "hello" },
|
|
13
|
+
{ type: "text", text: "world" },
|
|
14
|
+
];
|
|
15
|
+
assert.equal(findLatestPinnableText(blocks), "");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("findLatestPinnableText: returns text preceding a tool call", () => {
|
|
19
|
+
const blocks = [
|
|
20
|
+
{ type: "text", text: "doing the thing" },
|
|
21
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
22
|
+
];
|
|
23
|
+
assert.equal(findLatestPinnableText(blocks), "doing the thing");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("findLatestPinnableText: ignores trailing streaming text after the last tool call (regression: pinned mirror duplicated chat-container tokens)", () => {
|
|
27
|
+
const blocks = [
|
|
28
|
+
{ type: "text", text: "first prose" },
|
|
29
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
30
|
+
{ type: "text", text: "second prose still streaming" },
|
|
31
|
+
];
|
|
32
|
+
assert.equal(findLatestPinnableText(blocks), "first prose");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("findLatestPinnableText: with multiple tools, picks text before the most recent tool call", () => {
|
|
36
|
+
const blocks = [
|
|
37
|
+
{ type: "text", text: "first" },
|
|
38
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
39
|
+
{ type: "text", text: "second" },
|
|
40
|
+
{ type: "toolCall", id: "2", name: "Grep" },
|
|
41
|
+
{ type: "text", text: "third streaming" },
|
|
42
|
+
];
|
|
43
|
+
assert.equal(findLatestPinnableText(blocks), "second");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("findLatestPinnableText: treats serverToolUse the same as toolCall", () => {
|
|
47
|
+
const blocks = [
|
|
48
|
+
{ type: "text", text: "before web search" },
|
|
49
|
+
{ type: "serverToolUse", id: "ws1", name: "web_search" },
|
|
50
|
+
{ type: "text", text: "answer streaming" },
|
|
51
|
+
];
|
|
52
|
+
assert.equal(findLatestPinnableText(blocks), "before web search");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("findLatestPinnableText: skips empty/whitespace-only text blocks", () => {
|
|
56
|
+
const blocks = [
|
|
57
|
+
{ type: "text", text: "real prose" },
|
|
58
|
+
{ type: "text", text: " " },
|
|
59
|
+
{ type: "text", text: "" },
|
|
60
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
61
|
+
];
|
|
62
|
+
assert.equal(findLatestPinnableText(blocks), "real prose");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("findLatestPinnableText: thinking blocks are not pinnable", () => {
|
|
66
|
+
const blocks = [
|
|
67
|
+
{ type: "thinking", thinking: "internal" },
|
|
68
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
69
|
+
];
|
|
70
|
+
assert.equal(findLatestPinnableText(blocks), "");
|
|
71
|
+
});
|
|
@@ -22,6 +22,28 @@ function hasAssistantToolBlocks(message: { content: Array<any> }): boolean {
|
|
|
22
22
|
return message.content.some((c) => c.type === "toolCall" || c.type === "serverToolUse");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// Pick the latest non-empty text block that appears strictly before the most
|
|
26
|
+
// recent tool call. Text blocks that come after the last tool call are still
|
|
27
|
+
// streaming live into the chat container, so mirroring them into the pinned
|
|
28
|
+
// "Latest Output" zone would render the same tokens twice.
|
|
29
|
+
export function findLatestPinnableText(contentBlocks: Array<any>): string {
|
|
30
|
+
let lastToolIdx = -1;
|
|
31
|
+
for (let i = contentBlocks.length - 1; i >= 0; i--) {
|
|
32
|
+
const c = contentBlocks[i];
|
|
33
|
+
if (c?.type === "toolCall" || c?.type === "serverToolUse") {
|
|
34
|
+
lastToolIdx = i;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (let i = lastToolIdx - 1; i >= 0; i--) {
|
|
39
|
+
const c = contentBlocks[i];
|
|
40
|
+
if (c?.type === "text" && typeof c.text === "string" && c.text.trim()) {
|
|
41
|
+
return c.text.trim();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
|
|
25
47
|
// Tracks the latest assistant text for the pinned message zone
|
|
26
48
|
let lastPinnedText = "";
|
|
27
49
|
// Whether any tool execution has been added in this assistant turn (triggers pinned display)
|
|
@@ -286,15 +308,7 @@ export async function handleAgentEvent(host: InteractiveModeStateHost & {
|
|
|
286
308
|
if (hasTools) hasToolsInTurn = true;
|
|
287
309
|
|
|
288
310
|
if (hasToolsInTurn) {
|
|
289
|
-
|
|
290
|
-
let latestText = "";
|
|
291
|
-
for (let i = contentBlocks.length - 1; i >= 0; i--) {
|
|
292
|
-
const c = contentBlocks[i] as any;
|
|
293
|
-
if (c.type === "text" && c.text?.trim()) {
|
|
294
|
-
latestText = c.text.trim();
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
311
|
+
const latestText = findLatestPinnableText(contentBlocks);
|
|
298
312
|
|
|
299
313
|
if (latestText && latestText !== lastPinnedText) {
|
|
300
314
|
lastPinnedText = latestText;
|
package/pkg/package.json
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
checkNeedsReassessment,
|
|
53
53
|
checkNeedsRunUat,
|
|
54
54
|
} from "./auto-prompts.js";
|
|
55
|
+
import { resolveModelWithFallbacksForUnit } from "./preferences-models.js";
|
|
55
56
|
|
|
56
57
|
// ─── Types ────────────────────────────────────────────────────────────────
|
|
57
58
|
|
|
@@ -423,6 +424,7 @@ export const DISPATCH_RULES: DispatchRule[] = [
|
|
|
423
424
|
midTitle,
|
|
424
425
|
researchReadySlices,
|
|
425
426
|
basePath,
|
|
427
|
+
resolveModelWithFallbacksForUnit("subagent")?.primary,
|
|
426
428
|
),
|
|
427
429
|
};
|
|
428
430
|
},
|
|
@@ -510,6 +512,7 @@ export const DISPATCH_RULES: DispatchRule[] = [
|
|
|
510
512
|
sid,
|
|
511
513
|
sTitle,
|
|
512
514
|
basePath,
|
|
515
|
+
resolveModelWithFallbacksForUnit("subagent")?.primary,
|
|
513
516
|
),
|
|
514
517
|
};
|
|
515
518
|
},
|
|
@@ -548,6 +551,7 @@ export const DISPATCH_RULES: DispatchRule[] = [
|
|
|
548
551
|
const sid = state.activeSlice.id;
|
|
549
552
|
const sTitle = state.activeSlice.title;
|
|
550
553
|
const maxParallel = reactiveConfig.max_parallel ?? 2;
|
|
554
|
+
const subagentModel = reactiveConfig.subagent_model ?? resolveModelWithFallbacksForUnit("subagent")?.primary;
|
|
551
555
|
|
|
552
556
|
// Dry-run mode: max_parallel=1 means graph is derived and logged but
|
|
553
557
|
// execution remains sequential
|
|
@@ -618,6 +622,7 @@ export const DISPATCH_RULES: DispatchRule[] = [
|
|
|
618
622
|
sTitle,
|
|
619
623
|
selected,
|
|
620
624
|
basePath,
|
|
625
|
+
subagentModel,
|
|
621
626
|
),
|
|
622
627
|
};
|
|
623
628
|
} catch (err) {
|
|
@@ -1926,6 +1926,7 @@ export async function buildReassessRoadmapPrompt(
|
|
|
1926
1926
|
export async function buildReactiveExecutePrompt(
|
|
1927
1927
|
mid: string, midTitle: string, sid: string, sTitle: string,
|
|
1928
1928
|
readyTaskIds: string[], base: string,
|
|
1929
|
+
subagentModel?: string,
|
|
1929
1930
|
): Promise<string> {
|
|
1930
1931
|
const { loadSliceTaskIO, deriveTaskGraph, graphMetrics } = await import("./reactive-graph.js");
|
|
1931
1932
|
|
|
@@ -1970,10 +1971,11 @@ export async function buildReactiveExecutePrompt(
|
|
|
1970
1971
|
{ carryForwardPaths: depPaths },
|
|
1971
1972
|
);
|
|
1972
1973
|
|
|
1974
|
+
const modelSuffix = subagentModel ? ` with model: "${subagentModel}"` : "";
|
|
1973
1975
|
subagentSections.push([
|
|
1974
1976
|
`### ${tid}: ${tTitle}`,
|
|
1975
1977
|
"",
|
|
1976
|
-
|
|
1978
|
+
`Use this as the prompt for a \`subagent\` call${modelSuffix}:`,
|
|
1977
1979
|
"",
|
|
1978
1980
|
"```",
|
|
1979
1981
|
taskPrompt,
|
|
@@ -2049,15 +2051,17 @@ export async function buildParallelResearchSlicesPrompt(
|
|
|
2049
2051
|
midTitle: string,
|
|
2050
2052
|
slices: Array<{ id: string; title: string }>,
|
|
2051
2053
|
basePath: string,
|
|
2054
|
+
subagentModel?: string,
|
|
2052
2055
|
): Promise<string> {
|
|
2053
2056
|
// Build individual research-slice prompts for each slice
|
|
2054
2057
|
const subagentSections: string[] = [];
|
|
2058
|
+
const modelSuffix = subagentModel ? ` with model: "${subagentModel}"` : "";
|
|
2055
2059
|
for (const slice of slices) {
|
|
2056
2060
|
const slicePrompt = await buildResearchSlicePrompt(mid, midTitle, slice.id, slice.title, basePath);
|
|
2057
2061
|
subagentSections.push([
|
|
2058
2062
|
`### ${slice.id}: ${slice.title}`,
|
|
2059
2063
|
"",
|
|
2060
|
-
|
|
2064
|
+
`Use this as the prompt for a \`subagent\` call${modelSuffix} (agent: \`gsd-executor\` or the default agent):`,
|
|
2061
2065
|
"",
|
|
2062
2066
|
"```",
|
|
2063
2067
|
slicePrompt,
|
|
@@ -2077,6 +2081,7 @@ export async function buildParallelResearchSlicesPrompt(
|
|
|
2077
2081
|
export async function buildGateEvaluatePrompt(
|
|
2078
2082
|
mid: string, midTitle: string, sid: string, sTitle: string,
|
|
2079
2083
|
base: string,
|
|
2084
|
+
subagentModel?: string,
|
|
2080
2085
|
): Promise<string> {
|
|
2081
2086
|
// Pull only the gates this turn actually owns (Q3/Q4). Filter via the
|
|
2082
2087
|
// registry so that scope:"slice" gates owned by other turns (Q8) can't
|
|
@@ -2128,10 +2133,11 @@ export async function buildGateEvaluatePrompt(
|
|
|
2128
2133
|
"- `findings`: detailed markdown findings (or empty if omitted)",
|
|
2129
2134
|
].join("\n");
|
|
2130
2135
|
|
|
2136
|
+
const modelSuffix = subagentModel ? ` with model: "${subagentModel}"` : "";
|
|
2131
2137
|
subagentSections.push([
|
|
2132
2138
|
`### ${def.id}: ${def.question}`,
|
|
2133
2139
|
"",
|
|
2134
|
-
|
|
2140
|
+
`Use this as the prompt for a \`subagent\` call${modelSuffix}:`,
|
|
2135
2141
|
"",
|
|
2136
2142
|
"```",
|
|
2137
2143
|
subPrompt,
|
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
readCrashLock,
|
|
53
53
|
isLockProcessAlive,
|
|
54
54
|
formatCrashInfo,
|
|
55
|
+
emitCrashRecoveredUnitEnd,
|
|
55
56
|
} from "./crash-recovery.js";
|
|
56
57
|
import {
|
|
57
58
|
acquireSessionLock,
|
|
@@ -1332,6 +1333,10 @@ export async function startAuto(
|
|
|
1332
1333
|
}
|
|
1333
1334
|
|
|
1334
1335
|
if (freshStartAssessment.lock) {
|
|
1336
|
+
// Emit a synthetic unit-end for any unit-start that has no closing event.
|
|
1337
|
+
// This closes the journal gap reported in #3348 where the worker wrote side
|
|
1338
|
+
// effects (SUMMARY.md, DB updates) but died before emitting unit-end.
|
|
1339
|
+
emitCrashRecoveredUnitEnd(base, freshStartAssessment.lock);
|
|
1335
1340
|
clearLock(base);
|
|
1336
1341
|
}
|
|
1337
1342
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* crash-log.ts — Write crash diagnostics to ~/.gsd/crash/<timestamp>.log
|
|
3
|
+
*
|
|
4
|
+
* Zero cross-dependencies: only uses Node.js built-ins so it can be imported
|
|
5
|
+
* safely from uncaughtException / unhandledRejection handlers and from tests
|
|
6
|
+
* without pulling in the full extension dependency tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Write a crash log to ~/.gsd/crash/<timestamp>.log (or $GSD_HOME/crash/).
|
|
15
|
+
* Never throws — must be safe to call from any error handler.
|
|
16
|
+
*/
|
|
17
|
+
export function writeCrashLog(err: Error, source: string): void {
|
|
18
|
+
try {
|
|
19
|
+
const crashDir = join(process.env.GSD_HOME ?? join(homedir(), ".gsd"), "crash");
|
|
20
|
+
mkdirSync(crashDir, { recursive: true });
|
|
21
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-");
|
|
22
|
+
const logPath = join(crashDir, `${ts}.log`);
|
|
23
|
+
const lines = [
|
|
24
|
+
`[gsd] ${source}: ${err.message}`,
|
|
25
|
+
`timestamp: ${new Date().toISOString()}`,
|
|
26
|
+
`pid: ${process.pid}`,
|
|
27
|
+
err.stack ?? "(no stack trace available)",
|
|
28
|
+
"",
|
|
29
|
+
];
|
|
30
|
+
appendFileSync(logPath, lines.join("\n"));
|
|
31
|
+
} catch { /* never throw from crash handler */ }
|
|
32
|
+
}
|
|
@@ -11,6 +11,9 @@ import { registerJournalTools } from "./journal-tools.js";
|
|
|
11
11
|
import { registerQueryTools } from "./query-tools.js";
|
|
12
12
|
import { registerHooks } from "./register-hooks.js";
|
|
13
13
|
import { registerShortcuts } from "./register-shortcuts.js";
|
|
14
|
+
import { writeCrashLog } from "./crash-log.js";
|
|
15
|
+
|
|
16
|
+
export { writeCrashLog } from "./crash-log.js";
|
|
14
17
|
|
|
15
18
|
export function handleRecoverableExtensionProcessError(err: Error): boolean {
|
|
16
19
|
if ((err as NodeJS.ErrnoException).code === "EPIPE") {
|
|
@@ -33,16 +36,25 @@ export function handleRecoverableExtensionProcessError(err: Error): boolean {
|
|
|
33
36
|
function installEpipeGuard(): void {
|
|
34
37
|
if (!process.listeners("uncaughtException").some((listener) => listener.name === "_gsdEpipeGuard")) {
|
|
35
38
|
const _gsdEpipeGuard = (err: Error): void => {
|
|
36
|
-
if (handleRecoverableExtensionProcessError(err))
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
process.
|
|
42
|
-
if (err.stack) process.stderr.write(`${err.stack}\n`);
|
|
39
|
+
if (handleRecoverableExtensionProcessError(err)) return;
|
|
40
|
+
// Write crash log and exit cleanly for unrecoverable errors.
|
|
41
|
+
// Logging and continuing was the original double-fault fix (#3163), but
|
|
42
|
+
// continuing in an indeterminate state is worse than a clean exit (#3348).
|
|
43
|
+
writeCrashLog(err, "uncaughtException");
|
|
44
|
+
process.exit(1);
|
|
43
45
|
};
|
|
44
46
|
process.on("uncaughtException", _gsdEpipeGuard);
|
|
45
47
|
}
|
|
48
|
+
|
|
49
|
+
if (!process.listeners("unhandledRejection").some((listener) => listener.name === "_gsdRejectionGuard")) {
|
|
50
|
+
const _gsdRejectionGuard = (reason: unknown, _promise: Promise<unknown>): void => {
|
|
51
|
+
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
52
|
+
if (handleRecoverableExtensionProcessError(err)) return;
|
|
53
|
+
writeCrashLog(err, "unhandledRejection");
|
|
54
|
+
process.exit(1);
|
|
55
|
+
};
|
|
56
|
+
process.on("unhandledRejection", _gsdRejectionGuard);
|
|
57
|
+
}
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
export function registerGsdExtension(pi: ExtensionAPI): void {
|
|
@@ -9,6 +9,7 @@ import { debugTime } from "../debug-logger.js";
|
|
|
9
9
|
import { loadPrompt, getTemplatesDir } from "../prompt-loader.js";
|
|
10
10
|
import { readForensicsMarker } from "../forensics.js";
|
|
11
11
|
import { resolveAllSkillReferences, renderPreferencesForSystemPrompt, loadEffectiveGSDPreferences } from "../preferences.js";
|
|
12
|
+
import { resolveModelWithFallbacksForUnit } from "../preferences-models.js";
|
|
12
13
|
import { resolveSkillReference } from "../preferences-skills.js";
|
|
13
14
|
import { resolveGsdRootFile, resolveSliceFile, resolveSlicePath, resolveTaskFile, resolveTaskFiles, resolveTasksDir, relSliceFile, relSlicePath, relTaskFile } from "../paths.js";
|
|
14
15
|
import { ensureCodebaseMapFresh, readCodebaseMap } from "../codebase-generator.js";
|
|
@@ -175,7 +176,13 @@ export async function buildBeforeAgentStartResult(
|
|
|
175
176
|
const forensicsInjection = !injection ? buildForensicsContextInjection(process.cwd(), event.prompt) : null;
|
|
176
177
|
|
|
177
178
|
const worktreeBlock = buildWorktreeContextBlock();
|
|
178
|
-
|
|
179
|
+
|
|
180
|
+
const subagentModelConfig = resolveModelWithFallbacksForUnit("subagent");
|
|
181
|
+
const subagentModelBlock = subagentModelConfig
|
|
182
|
+
? `\n\n## Subagent Model\n\nWhen spawning subagents via the \`subagent\` tool, always pass \`model: "${subagentModelConfig.primary}"\` in the tool call parameters. Never omit this — always specify it explicitly.`
|
|
183
|
+
: "";
|
|
184
|
+
|
|
185
|
+
const fullSystem = `${event.systemPrompt}\n\n[SYSTEM CONTEXT — GSD]\n\n${systemContent}${preferenceBlock}${knowledgeBlock}${codebaseBlock}${memoryBlock}${newSkillsBlock}${worktreeBlock}${subagentModelBlock}`;
|
|
179
186
|
|
|
180
187
|
stopContextTimer({
|
|
181
188
|
systemPromptSize: fullSystem.length,
|