@evandu/super-pi-server 0.0.0-stage → 0.1.259
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +248 -3
- package/agents/code-auditor.md +64 -0
- package/agents/code-designer.md +64 -0
- package/agents/coder.md +24 -0
- package/agents/critic.md +24 -0
- package/agents/document-organizer.md +48 -0
- package/agents/patcher.md +27 -0
- package/agents/planner.md +30 -0
- package/agents/project-leader.md +28 -0
- package/agents/reviewer.md +27 -0
- package/agents/scout.md +27 -0
- package/agents/solution-designer.md +62 -0
- package/agents/super-pi-documents/index.ts +92 -0
- package/agents/super-pi-feishu/index.ts +88 -0
- package/agents/super-pi-knowledge/index.ts +70 -0
- package/agents/super-pi-managed-model/index.ts +9 -0
- package/agents/super-pi-memory/index.ts +75 -0
- package/agents/super-pi-native-tools/index.ts +1 -0
- package/agents/super-pi-task/core.ts +2262 -0
- package/agents/super-pi-task/index.ts +814 -0
- package/agents/super-pi-task/workflow-schema.ts +34 -0
- package/agents/super-pi-web/index.ts +32 -0
- package/agents/verifier.md +25 -0
- package/assets/fonts/LICENSE +92 -0
- package/assets/fonts/NotoSansSC-Bold.otf +0 -0
- package/assets/fonts/NotoSansSC-Regular.otf +0 -0
- package/assets/knowledge-model/README.md +37 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/config.json +31 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/onnx/model_quantized.onnx +0 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/special_tokens_map.json +7 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer.json +21278 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer_config.json +15 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/vocab.txt +21128 -0
- package/bin/npm-prefix.d.ts +1 -0
- package/bin/npm-prefix.js +10 -0
- package/bin/super-pi.js +349 -0
- package/dist/client/.super-pi-client-sources.json +82 -0
- package/dist/client/assets/CodeMirrorEditor-mi9rGUce.js +2 -0
- package/dist/client/assets/GitDiffEditor-CpoDDQrA.css +1 -0
- package/dist/client/assets/GitDiffEditor-FQBfGxOY.js +29 -0
- package/dist/client/assets/diff-ChtP43wD.js +1 -0
- package/dist/client/assets/dist-AW5lyI3I.js +1 -0
- package/dist/client/assets/dist-B3-a6uF0.js +7 -0
- package/dist/client/assets/dist-BGxkyh6e.js +1 -0
- package/dist/client/assets/dist-BJxfd7yb.js +11 -0
- package/dist/client/assets/dist-BRVQKlcp.js +1 -0
- package/dist/client/assets/dist-BV64A9Ji.js +1 -0
- package/dist/client/assets/dist-BXAOrsjq.js +1 -0
- package/dist/client/assets/dist-CKF2Jksy.js +1 -0
- package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
- package/dist/client/assets/dist-Cus6_oaF.js +2 -0
- package/dist/client/assets/dist-Cx00EZKR.js +23 -0
- package/dist/client/assets/dist-D71y2EI1.js +1 -0
- package/dist/client/assets/dist-D978o95T.js +5 -0
- package/dist/client/assets/dist-Dc1MBGAG.js +1 -0
- package/dist/client/assets/dist-Dds-qLxY.js +9 -0
- package/dist/client/assets/dist-DeD9copn.js +1 -0
- package/dist/client/assets/dist-DuvGReu-.js +6 -0
- package/dist/client/assets/dist-Dvb0SqcK.js +2 -0
- package/dist/client/assets/dist-J6XWqRpB.js +3 -0
- package/dist/client/assets/dist-QzbOCAU6.js +1 -0
- package/dist/client/assets/dist-moiMRpw_.js +1 -0
- package/dist/client/assets/dist-scBkrwv-.js +2 -0
- package/dist/client/assets/dockerfile-BDePf5PZ.js +1 -0
- package/dist/client/assets/index-Cn7hdrDw.js +350 -0
- package/dist/client/assets/index-UfzqdECL.css +1 -0
- package/dist/client/assets/powershell-D8WpQPaX.js +1 -0
- package/dist/client/assets/properties-C357ku5U.js +1 -0
- package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/client/assets/ruby-ChfNwlCY.js +1 -0
- package/dist/client/assets/shell-DwuoZtxw.js +1 -0
- package/dist/client/assets/swift-DKB6_1j6.js +1 -0
- package/dist/client/assets/toml-BPTmHmyx.js +1 -0
- package/dist/client/favicon.ico +0 -0
- package/dist/client/favicon.png +0 -0
- package/dist/client/favicon.svg +10 -0
- package/dist/client/index.html +18 -0
- package/dist/extension.d.ts +15 -0
- package/dist/extension.js +126 -0
- package/dist/server/active-memory.d.ts +247 -0
- package/dist/server/active-memory.js +669 -0
- package/dist/server/agents.d.ts +245 -0
- package/dist/server/agents.js +701 -0
- package/dist/server/application/catalog-service.d.ts +98 -0
- package/dist/server/application/catalog-service.js +245 -0
- package/dist/server/application/conversation-service.d.ts +245 -0
- package/dist/server/application/conversation-service.js +654 -0
- package/dist/server/application/document-service.d.ts +68 -0
- package/dist/server/application/document-service.js +120 -0
- package/dist/server/application/extension-ui-service.d.ts +44 -0
- package/dist/server/application/extension-ui-service.js +135 -0
- package/dist/server/application/feishu-service.d.ts +179 -0
- package/dist/server/application/feishu-service.js +358 -0
- package/dist/server/application/group-chat-service.d.ts +75 -0
- package/dist/server/application/group-chat-service.js +953 -0
- package/dist/server/application/group-execution.d.ts +15 -0
- package/dist/server/application/group-execution.js +77 -0
- package/dist/server/application/project-service.d.ts +464 -0
- package/dist/server/application/project-service.js +2523 -0
- package/dist/server/application/provider-service.d.ts +174 -0
- package/dist/server/application/provider-service.js +510 -0
- package/dist/server/application/run-service.d.ts +547 -0
- package/dist/server/application/run-service.js +2683 -0
- package/dist/server/application/scheduled-task-service.d.ts +184 -0
- package/dist/server/application/scheduled-task-service.js +391 -0
- package/dist/server/application/session-orchestrator-service.d.ts +388 -0
- package/dist/server/application/session-orchestrator-service.js +1146 -0
- package/dist/server/application/session-reminder-service.d.ts +59 -0
- package/dist/server/application/session-reminder-service.js +141 -0
- package/dist/server/application/session-watchdog.d.ts +171 -0
- package/dist/server/application/session-watchdog.js +284 -0
- package/dist/server/application/workspace-service.d.ts +52 -0
- package/dist/server/application/workspace-service.js +186 -0
- package/dist/server/application/worktree-service.d.ts +13 -0
- package/dist/server/application/worktree-service.js +76 -0
- package/dist/server/browser-access.d.ts +34 -0
- package/dist/server/browser-access.js +89 -0
- package/dist/server/capability.d.ts +105 -0
- package/dist/server/capability.js +170 -0
- package/dist/server/command-handler.d.ts +93 -0
- package/dist/server/command-handler.js +540 -0
- package/dist/server/content-search.d.ts +16 -0
- package/dist/server/content-search.js +235 -0
- package/dist/server/conversation-usage.d.ts +22 -0
- package/dist/server/conversation-usage.js +43 -0
- package/dist/server/documents.d.ts +152 -0
- package/dist/server/documents.js +998 -0
- package/dist/server/engineering-learning.d.ts +30 -0
- package/dist/server/engineering-learning.js +106 -0
- package/dist/server/exec-service.d.ts +45 -0
- package/dist/server/exec-service.js +167 -0
- package/dist/server/explicit-file-open.d.ts +34 -0
- package/dist/server/explicit-file-open.js +105 -0
- package/dist/server/failure-text.d.ts +18 -0
- package/dist/server/failure-text.js +44 -0
- package/dist/server/feishu-cli.d.ts +223 -0
- package/dist/server/feishu-cli.js +464 -0
- package/dist/server/file-changes.d.ts +119 -0
- package/dist/server/file-changes.js +280 -0
- package/dist/server/file-diff.d.ts +41 -0
- package/dist/server/file-diff.js +97 -0
- package/dist/server/file-index.d.ts +100 -0
- package/dist/server/file-index.js +296 -0
- package/dist/server/file-name-index.d.ts +160 -0
- package/dist/server/file-name-index.js +411 -0
- package/dist/server/files.d.ts +269 -0
- package/dist/server/files.js +748 -0
- package/dist/server/git.d.ts +245 -0
- package/dist/server/git.js +903 -0
- package/dist/server/http-server.d.ts +45 -0
- package/dist/server/http-server.js +3830 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +485 -0
- package/dist/server/inline-thinking.d.ts +90 -0
- package/dist/server/inline-thinking.js +181 -0
- package/dist/server/json-comments.d.ts +14 -0
- package/dist/server/json-comments.js +71 -0
- package/dist/server/knowledge-embedding-worker.d.ts +1 -0
- package/dist/server/knowledge-embedding-worker.js +27 -0
- package/dist/server/knowledge-vectors.d.ts +150 -0
- package/dist/server/knowledge-vectors.js +385 -0
- package/dist/server/knowledge.d.ts +273 -0
- package/dist/server/knowledge.js +848 -0
- package/dist/server/length-continuation.d.ts +83 -0
- package/dist/server/length-continuation.js +118 -0
- package/dist/server/logging.d.ts +32 -0
- package/dist/server/logging.js +185 -0
- package/dist/server/managed-http-tunnel.d.ts +6 -0
- package/dist/server/managed-http-tunnel.js +85 -0
- package/dist/server/managed-http.d.ts +4 -0
- package/dist/server/managed-http.js +85 -0
- package/dist/server/managed-model-adapter.d.ts +17 -0
- package/dist/server/managed-model-adapter.js +75 -0
- package/dist/server/managed-model-gateway.d.ts +49 -0
- package/dist/server/managed-model-gateway.js +73 -0
- package/dist/server/managed-servers.d.ts +55 -0
- package/dist/server/managed-servers.js +392 -0
- package/dist/server/managed-ssh.d.ts +26 -0
- package/dist/server/managed-ssh.js +73 -0
- package/dist/server/manager-vault.d.ts +11 -0
- package/dist/server/manager-vault.js +67 -0
- package/dist/server/memory-recall.d.ts +25 -0
- package/dist/server/memory-recall.js +45 -0
- package/dist/server/memory.d.ts +67 -0
- package/dist/server/memory.js +216 -0
- package/dist/server/message-media.d.ts +7 -0
- package/dist/server/message-media.js +54 -0
- package/dist/server/model-context-window.d.ts +186 -0
- package/dist/server/model-context-window.js +444 -0
- package/dist/server/model-filter.d.ts +23 -0
- package/dist/server/model-filter.js +48 -0
- package/dist/server/models-store.d.ts +36 -0
- package/dist/server/models-store.js +132 -0
- package/dist/server/native-tool-settings.d.ts +25 -0
- package/dist/server/native-tool-settings.js +41 -0
- package/dist/server/native-tools-extension.d.ts +2 -0
- package/dist/server/native-tools-extension.js +39 -0
- package/dist/server/native-tools-service.d.ts +39 -0
- package/dist/server/native-tools-service.js +240 -0
- package/dist/server/persistence/app-state-repository.d.ts +65 -0
- package/dist/server/persistence/app-state-repository.js +1 -0
- package/dist/server/persistence/json-state-repository.d.ts +14 -0
- package/dist/server/persistence/json-state-repository.js +43 -0
- package/dist/server/persistence/open-state-store.d.ts +3 -0
- package/dist/server/persistence/open-state-store.js +35 -0
- package/dist/server/persistence/rename.d.ts +22 -0
- package/dist/server/persistence/rename.js +44 -0
- package/dist/server/persistence/sqlite-state-repository.d.ts +12 -0
- package/dist/server/persistence/sqlite-state-repository.js +264 -0
- package/dist/server/pi-command.d.ts +94 -0
- package/dist/server/pi-command.js +265 -0
- package/dist/server/pi-native.d.ts +12 -0
- package/dist/server/pi-native.js +16 -0
- package/dist/server/pi-session-events.d.ts +158 -0
- package/dist/server/pi-session-events.js +373 -0
- package/dist/server/pi-session-pool.d.ts +233 -0
- package/dist/server/pi-session-pool.js +382 -0
- package/dist/server/pi-session.d.ts +642 -0
- package/dist/server/pi-session.js +655 -0
- package/dist/server/presentations/schema.d.ts +120 -0
- package/dist/server/presentations/schema.js +128 -0
- package/dist/server/provider-network.d.ts +16 -0
- package/dist/server/provider-network.js +106 -0
- package/dist/server/provider-proxy.d.ts +18 -0
- package/dist/server/provider-proxy.js +200 -0
- package/dist/server/providers.d.ts +333 -0
- package/dist/server/providers.js +989 -0
- package/dist/server/remote-bootstrap.d.ts +17 -0
- package/dist/server/remote-bootstrap.js +119 -0
- package/dist/server/rpc-channel.d.ts +131 -0
- package/dist/server/rpc-channel.js +135 -0
- package/dist/server/runtime.d.ts +1393 -0
- package/dist/server/runtime.js +3286 -0
- package/dist/server/scheduled-tasks.d.ts +101 -0
- package/dist/server/scheduled-tasks.js +138 -0
- package/dist/server/server-context.d.ts +119 -0
- package/dist/server/server-context.js +1 -0
- package/dist/server/session-cwd.d.ts +19 -0
- package/dist/server/session-cwd.js +58 -0
- package/dist/server/session-ledger.d.ts +67 -0
- package/dist/server/session-ledger.js +76 -0
- package/dist/server/session-memory-scope.d.ts +4 -0
- package/dist/server/session-memory-scope.js +30 -0
- package/dist/server/session-repository.d.ts +100 -0
- package/dist/server/session-repository.js +246 -0
- package/dist/server/session-tree-scope.d.ts +125 -0
- package/dist/server/session-tree-scope.js +337 -0
- package/dist/server/skills.d.ts +23 -0
- package/dist/server/skills.js +190 -0
- package/dist/server/store.d.ts +1062 -0
- package/dist/server/store.js +3305 -0
- package/dist/server/subagent-runs.d.ts +185 -0
- package/dist/server/subagent-runs.js +383 -0
- package/dist/server/subagents.d.ts +200 -0
- package/dist/server/subagents.js +619 -0
- package/dist/server/task-tool.d.ts +282 -0
- package/dist/server/task-tool.js +507 -0
- package/dist/server/tavily.d.ts +32 -0
- package/dist/server/tavily.js +136 -0
- package/dist/server/team-context.d.ts +12 -0
- package/dist/server/team-context.js +180 -0
- package/dist/server/terminal.d.ts +163 -0
- package/dist/server/terminal.js +557 -0
- package/dist/server/thinking-level-discovery.d.ts +38 -0
- package/dist/server/thinking-level-discovery.js +183 -0
- package/dist/server/time-zone.d.ts +20 -0
- package/dist/server/time-zone.js +32 -0
- package/dist/server/tool-calls.d.ts +130 -0
- package/dist/server/tool-calls.js +341 -0
- package/dist/server/tool-llm.d.ts +72 -0
- package/dist/server/tool-llm.js +146 -0
- package/dist/server/tool-registry.d.ts +129 -0
- package/dist/server/tool-registry.js +249 -0
- package/dist/server/tool-runner.d.ts +112 -0
- package/dist/server/tool-runner.js +306 -0
- package/dist/server/turn-failure.d.ts +48 -0
- package/dist/server/turn-failure.js +148 -0
- package/dist/server/types.d.ts +2315 -0
- package/dist/server/types.js +11 -0
- package/dist/server/update-status.d.ts +14 -0
- package/dist/server/update-status.js +69 -0
- package/dist/server/update.d.ts +46 -0
- package/dist/server/update.js +104 -0
- package/dist/server/upload.d.ts +35 -0
- package/dist/server/upload.js +177 -0
- package/dist/server/version.d.ts +33 -0
- package/dist/server/version.js +111 -0
- package/dist/server/web.d.ts +27 -0
- package/dist/server/web.js +183 -0
- package/dist/server/workflow-engine.d.ts +47 -0
- package/dist/server/workflow-engine.js +255 -0
- package/dist/server/workflow.d.ts +329 -0
- package/dist/server/workflow.js +469 -0
- package/dist/server/workspace-file-indexes.d.ts +2 -0
- package/dist/server/workspace-file-indexes.js +61 -0
- package/dist/server/workspace-file-operations.d.ts +36 -0
- package/dist/server/workspace-file-operations.js +281 -0
- package/dist/server/workspace-file-response.d.ts +7 -0
- package/dist/server/workspace-file-response.js +79 -0
- package/dist/server/ws-server.d.ts +149 -0
- package/dist/server/ws-server.js +640 -0
- package/dist/shared/agent-order.d.ts +44 -0
- package/dist/shared/agent-order.js +50 -0
- package/dist/shared/archive-decisions.d.ts +44 -0
- package/dist/shared/archive-decisions.js +98 -0
- package/dist/shared/background-task.d.ts +25 -0
- package/dist/shared/background-task.js +183 -0
- package/dist/shared/child-session-lock.d.ts +37 -0
- package/dist/shared/child-session-lock.js +59 -0
- package/dist/shared/content-search.d.ts +22 -0
- package/dist/shared/content-search.js +1 -0
- package/dist/shared/conversation-title.d.ts +4 -0
- package/dist/shared/conversation-title.js +4 -0
- package/dist/shared/file-mentions.d.ts +17 -0
- package/dist/shared/file-mentions.js +91 -0
- package/dist/shared/git-commit.d.ts +11 -0
- package/dist/shared/git-commit.js +1 -0
- package/dist/shared/git-graph.d.ts +42 -0
- package/dist/shared/git-graph.js +30 -0
- package/dist/shared/group-chat.d.ts +132 -0
- package/dist/shared/group-chat.js +6 -0
- package/dist/shared/managed-servers.d.ts +36 -0
- package/dist/shared/managed-servers.js +1 -0
- package/dist/shared/message-media.d.ts +12 -0
- package/dist/shared/message-media.js +27 -0
- package/dist/shared/model-window-label.d.ts +39 -0
- package/dist/shared/model-window-label.js +55 -0
- package/dist/shared/native-tools.d.ts +43 -0
- package/dist/shared/native-tools.js +1 -0
- package/dist/shared/pi-cache-warming.d.ts +9 -0
- package/dist/shared/pi-cache-warming.js +4 -0
- package/dist/shared/project-overview.d.ts +107 -0
- package/dist/shared/project-overview.js +92 -0
- package/dist/shared/project-presentation.d.ts +55 -0
- package/dist/shared/project-presentation.js +111 -0
- package/dist/shared/provider-network.d.ts +30 -0
- package/dist/shared/provider-network.js +1 -0
- package/dist/shared/session-reporting.d.ts +40 -0
- package/dist/shared/session-reporting.js +97 -0
- package/dist/shared/session-search.d.ts +14 -0
- package/dist/shared/session-search.js +1 -0
- package/dist/shared/team-context-view.d.ts +33 -0
- package/dist/shared/team-context-view.js +49 -0
- package/dist/shared/team-context.d.ts +59 -0
- package/dist/shared/team-context.js +3 -0
- package/dist/shared/terminal-protocol.d.ts +71 -0
- package/dist/shared/terminal-protocol.js +1 -0
- package/dist/shared/thinking-levels.d.ts +53 -0
- package/dist/shared/thinking-levels.js +85 -0
- package/dist/shared/tool-glyph.d.ts +7 -0
- package/dist/shared/tool-glyph.js +19 -0
- package/dist/shared/transcript-order.d.ts +7 -0
- package/dist/shared/transcript-order.js +12 -0
- package/dist/shared/update-status.d.ts +28 -0
- package/dist/shared/update-status.js +1 -0
- package/dist/shared/workspace-file-preview.d.ts +4 -0
- package/dist/shared/workspace-file-preview.js +28 -0
- package/package.json +448 -4
- package/scripts/diagnose.mjs +603 -0
- package/scripts/patch-brace-expansion.mjs +260 -0
- package/scripts/restart-server.mjs +104 -0
- package/skills/presentation/SKILL.md +30 -0
- package/skills/presentation/references/data.md +10 -0
- package/skills/presentation/references/quality.md +12 -0
- package/skills/presentation/references/story.md +12 -0
- package/skills/presentation/references/templates-and-editing.md +11 -0
- package/skills/presentation/references/visual-system.md +10 -0
- package/skills/super-pi-agent-development/SKILL.md +25 -0
- package/skills/super-pi-development/SKILL.md +31 -0
- package/skills/super-pi-tool-development/SKILL.md +39 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { accessSync, constants, existsSync } from "node:fs";
|
|
2
|
+
import { posix, win32 } from "node:path";
|
|
3
|
+
/** npm's launcher names, most specific first: `.cmd` is what `shell: true` can actually start on Windows. */
|
|
4
|
+
const launcherNames = (platform) => platform === "win32" ? ["pi.cmd", "pi.exe", "pi.bat", "pi"] : ["pi", "pi.exe"];
|
|
5
|
+
/**
|
|
6
|
+
* Turns one PATH entry into a path this platform can stat.
|
|
7
|
+
*
|
|
8
|
+
* Git Bash and MSYS hand a native program a POSIX-looking PATH (`/c/Users/...`), and Windows cannot
|
|
9
|
+
* stat that: `existsSync("/c/Users/...")` resolves against the current drive root and says no. So the
|
|
10
|
+
* drive-letter form is rewritten, which is what makes PATH scanning work in exactly the shells this
|
|
11
|
+
* bug appeared in.
|
|
12
|
+
*/
|
|
13
|
+
function nativeEntry(entry, platform) {
|
|
14
|
+
const trimmed = entry.trim().replace(/^"(.*)"$/, "$1");
|
|
15
|
+
if (!trimmed)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (platform !== "win32")
|
|
18
|
+
return trimmed;
|
|
19
|
+
const drive = /^\/([a-zA-Z])(\/.*)?$/.exec(trimmed);
|
|
20
|
+
return drive ? `${drive[1].toUpperCase()}:${(drive[2] ?? "/").replace(/\//g, "\\")}` : trimmed;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Splits PATH the way the platform that handed it to us actually wrote it.
|
|
24
|
+
*
|
|
25
|
+
* Windows uses `;`, but a Git Bash / MSYS PATH arrives colon-separated with drive-letter prefixes, and a
|
|
26
|
+
* `C:` in an ordinary Windows entry means the drive, never a separator. So `;` always wins when present;
|
|
27
|
+
* otherwise `:` is treated as a separator only if the string has no drive-letter prefix at all.
|
|
28
|
+
*/
|
|
29
|
+
const splitPath = (value, platform) => {
|
|
30
|
+
if (platform !== "win32")
|
|
31
|
+
return value.split(":");
|
|
32
|
+
if (value.includes(";"))
|
|
33
|
+
return value.split(";");
|
|
34
|
+
return /(^|[;,])[a-zA-Z]:[\\/]/.test(value) ? [value] : value.split(":");
|
|
35
|
+
};
|
|
36
|
+
const pathDirectories = (env, platform) => splitPath(env.PATH ?? env.Path ?? "", platform).map((entry) => nativeEntry(entry, platform)).filter((entry) => Boolean(entry));
|
|
37
|
+
/** Joins with the target platform's separator, so a POSIX expectation stays comparable on Windows. */
|
|
38
|
+
const joinFor = (platform) => (platform === "win32" ? win32.join : posix.join);
|
|
39
|
+
/**
|
|
40
|
+
* The directories npm installs global CLIs into, beyond PATH.
|
|
41
|
+
*
|
|
42
|
+
* `npm_config_prefix` is npm's own answer when it is set; the rest are the defaults per platform. The
|
|
43
|
+
* home directory is read from the ENVIRONMENT only - `os.homedir()` is never consulted - so a
|
|
44
|
+
* deliberately isolated environment (empty PATH, no HOME) really is isolated instead of quietly
|
|
45
|
+
* finding the developer's own install through the OS.
|
|
46
|
+
*/
|
|
47
|
+
function globalBinDirectories(env, platform) {
|
|
48
|
+
const home = env.HOME?.trim() || env.USERPROFILE?.trim();
|
|
49
|
+
const at = joinFor(platform);
|
|
50
|
+
const directories = [];
|
|
51
|
+
const prefix = env.npm_config_prefix?.trim();
|
|
52
|
+
if (prefix)
|
|
53
|
+
directories.push(platform === "win32" ? nativeEntry(prefix, platform) ?? prefix : at(prefix, "bin"));
|
|
54
|
+
if (platform === "win32") {
|
|
55
|
+
if (env.APPDATA?.trim())
|
|
56
|
+
directories.push(at(env.APPDATA.trim(), "npm"));
|
|
57
|
+
if (env.LOCALAPPDATA?.trim())
|
|
58
|
+
directories.push(at(env.LOCALAPPDATA.trim(), "npm"));
|
|
59
|
+
if (env.ProgramFiles?.trim())
|
|
60
|
+
directories.push(at(env.ProgramFiles.trim(), "npm"));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (home)
|
|
64
|
+
directories.push(at(home, ".local", "bin"), at(home, ".npm-global", "bin"), at(home, "bin"));
|
|
65
|
+
directories.push("/usr/local/bin", "/opt/homebrew/bin");
|
|
66
|
+
}
|
|
67
|
+
return [...new Set(directories.filter(Boolean))];
|
|
68
|
+
}
|
|
69
|
+
/** On POSIX a file that is not executable is not runnable; on Windows that bit does not exist. */
|
|
70
|
+
const defaultExists = (platform) => (path) => {
|
|
71
|
+
if (!existsSync(path))
|
|
72
|
+
return false;
|
|
73
|
+
if (platform === "win32")
|
|
74
|
+
return true;
|
|
75
|
+
try {
|
|
76
|
+
accessSync(path, constants.X_OK);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const firstHit = (names, directories, exists, platform) => {
|
|
84
|
+
const at = joinFor(platform);
|
|
85
|
+
for (const dir of directories)
|
|
86
|
+
for (const name of names) {
|
|
87
|
+
const candidate = at(dir, name);
|
|
88
|
+
if (exists(candidate))
|
|
89
|
+
return { command: candidate, dir };
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Resolves the command that starts Pi: the explicit override, then PATH, then npm's global bin
|
|
95
|
+
* directories, and only then a report of every place it looked.
|
|
96
|
+
*
|
|
97
|
+
* An explicit override that does not exist is REPORTED rather than handed to the spawn, because a
|
|
98
|
+
* silent fallback would make a typo in `SUPER_PI_PI_COMMAND` look like a working Pi somewhere else.
|
|
99
|
+
*/
|
|
100
|
+
export function resolvePiCommand(options = {}) {
|
|
101
|
+
const { command, env = process.env, platform = process.platform } = options;
|
|
102
|
+
const exists = options.exists ?? defaultExists(platform);
|
|
103
|
+
const findBundled = options.bundled ?? bundledPiCommand;
|
|
104
|
+
const names = launcherNames(platform);
|
|
105
|
+
const explicit = (command ?? env.SUPER_PI_PI_COMMAND ?? "").trim();
|
|
106
|
+
const onPath = pathDirectories(env, platform);
|
|
107
|
+
const globalDirs = globalBinDirectories(env, platform);
|
|
108
|
+
if (explicit) {
|
|
109
|
+
const label = command ? "the command given to the runtime" : "SUPER_PI_PI_COMMAND";
|
|
110
|
+
if (/[\\/]/.test(explicit)) {
|
|
111
|
+
const full = nativeEntry(explicit, platform) ?? explicit;
|
|
112
|
+
if (exists(full))
|
|
113
|
+
return { found: true, command: full, via: label, explicit: true };
|
|
114
|
+
return {
|
|
115
|
+
found: false,
|
|
116
|
+
reason: `${label} points at ${full}, and no such file exists. Fix ${command ? "that argument" : "SUPER_PI_PI_COMMAND"} or unset it to fall back to PATH and npm's global bin directory. This is an environment problem, not a defect of the agent mechanism.`,
|
|
117
|
+
searched: [full],
|
|
118
|
+
// STILL EXPLICIT. A Pi was NAMED, and naming one is a statement about which Pi runs a turn -
|
|
119
|
+
// so the fact survives the file being missing, and the honest answer to "that Pi cannot be
|
|
120
|
+
// asked" is "unavailable", never a list belonging to some other Pi.
|
|
121
|
+
explicit: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const hit = firstHit([explicit], [...onPath, ...globalDirs], exists, platform);
|
|
125
|
+
if (hit)
|
|
126
|
+
return { found: true, command: hit.command, via: `${label} (${hit.dir})`, explicit: true };
|
|
127
|
+
return {
|
|
128
|
+
found: false,
|
|
129
|
+
reason: `${label} names ${explicit}, which is on no PATH entry and in none of npm's global bin directories. This is an environment problem, not a defect of the agent mechanism.`,
|
|
130
|
+
searched: [...onPath, ...globalDirs],
|
|
131
|
+
explicit: true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// THE PI THAT IS HOSTING SUPER PI, when Super Pi was started from inside Pi itself.
|
|
135
|
+
//
|
|
136
|
+
// It is NOT the same thing as an explicitly named Pi, and the difference is the whole point:
|
|
137
|
+
// `SUPER_PI_PI_COMMAND` means "the USER named this Pi", and naming a Pi is what tells Super Pi to
|
|
138
|
+
// run CONVERSATIONS by spawning it - the SDK is a library, and it can only be the one that came with
|
|
139
|
+
// Super Pi. A conversation that spawns a process for every turn is the slow architecture this all
|
|
140
|
+
// replaced, so the hosting Pi must NOT set that flag.
|
|
141
|
+
//
|
|
142
|
+
// What the hosting Pi IS good for is the one-shot work: the sub-agents spawn a Pi process, and they
|
|
143
|
+
// should run on the same Pi that is hosting Super Pi. So it is preferred over the bundled copy here,
|
|
144
|
+
// without being a user override.
|
|
145
|
+
const hostPi = (env.SUPER_PI_HOST_PI ?? "").trim();
|
|
146
|
+
if (hostPi) {
|
|
147
|
+
if (/[\\/]/.test(hostPi)) {
|
|
148
|
+
const full = nativeEntry(hostPi, platform) ?? hostPi;
|
|
149
|
+
if (exists(full))
|
|
150
|
+
return { found: true, command: full, via: "the Pi that is hosting Super Pi", explicit: false };
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const hit = firstHit([hostPi], [...onPath, ...globalDirs], exists, platform);
|
|
154
|
+
if (hit)
|
|
155
|
+
return { found: true, command: hit.command, via: `the Pi that is hosting Super Pi (${hit.dir})`, explicit: false };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// THE COPY OF PI THAT CAME WITH SUPER PI, and it comes FIRST among the automatic choices.
|
|
159
|
+
//
|
|
160
|
+
// Super Pi depends on Pi's package, so npm installs it and puts its `pi` executable in
|
|
161
|
+
// `node_modules/.bin` - which is not on the user's PATH, and which is therefore invisible to the
|
|
162
|
+
// lookups below. Two reasons it wins over a Pi the user installed separately:
|
|
163
|
+
//
|
|
164
|
+
// 1. ONE Pi version in the product. The primary agent runs on the SDK - the very same package - and
|
|
165
|
+
// the sub-agents spawn an executable. If those two were different versions, one conversation could
|
|
166
|
+
// load the same extension file into two different Pi versions, and the older one would quietly
|
|
167
|
+
// lack a tool the newer one has. One package, one version, one set of extensions.
|
|
168
|
+
// 2. "Installing Super Pi installs Pi" is the product's promise, and it only holds if the copy that
|
|
169
|
+
// came with Super Pi is the copy Super Pi runs.
|
|
170
|
+
//
|
|
171
|
+
// A user's own Pi is still reachable by NAMING it (`SUPER_PI_PI_COMMAND`), which is the explicit
|
|
172
|
+
// override and wins outright - that is how the test suite drives a fake peer, and it is a legitimate
|
|
173
|
+
// thing for a person to want.
|
|
174
|
+
const bundled = findBundled(exists, platform);
|
|
175
|
+
if (bundled)
|
|
176
|
+
return { found: true, command: bundled, via: "the copy of Pi that came with Super Pi", explicit: false };
|
|
177
|
+
const namesFound = firstHit(names, onPath, exists, platform);
|
|
178
|
+
if (namesFound)
|
|
179
|
+
return { found: true, command: namesFound.command, via: `PATH (${namesFound.dir})`, explicit: false };
|
|
180
|
+
const globalFound = firstHit(names, globalDirs, exists, platform);
|
|
181
|
+
if (globalFound)
|
|
182
|
+
return { found: true, command: globalFound.command, via: `npm's global bin directory (${globalFound.dir})`, explicit: false };
|
|
183
|
+
const searched = [...new Set([...onPath, ...globalDirs])];
|
|
184
|
+
return {
|
|
185
|
+
found: false,
|
|
186
|
+
reason: `Pi was not found: no ${names.map((name) => `"${name}"`).join(" or ")} in ${searched.length} directory(ies) on PATH or in npm's global bin location (${searched.join(", ") || "none known"}), and Super Pi's own copy of Pi is not installed either. Reinstall Super Pi (npm i -g @evandu/super-pi) so that Pi comes with it, or set SUPER_PI_PI_COMMAND to a Pi's full path. This is an environment fact, NOT evidence that the agent mechanism is broken - only a Pi that IS present and disagrees can say that.`,
|
|
187
|
+
searched,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The `pi` executable of the Pi package Super Pi depends on, if it is installed next to Super Pi.
|
|
192
|
+
*
|
|
193
|
+
* npm puts a dependency's binaries in `node_modules/.bin`, as a shell script on POSIX and as a `.cmd`
|
|
194
|
+
* shim on Windows. Two layouts have to be covered, because Super Pi runs in both:
|
|
195
|
+
*
|
|
196
|
+
* - INSTALLED: `<node_modules>/@evandu/super-pi/dist/server/pi-command.js`, and the shim is at
|
|
197
|
+
* `<node_modules>/.bin/pi` - the `.bin` of the tree that HOLDS Super Pi, two levels up.
|
|
198
|
+
* - A CHECKOUT: `<repo>/dist/server/pi-command.js`, and the shim is at `<repo>/node_modules/.bin/pi`
|
|
199
|
+
* - the `.bin` of Super Pi's OWN tree.
|
|
200
|
+
*
|
|
201
|
+
* So every level of the walk checks both `<dir>/.bin` and `<dir>/node_modules/.bin`, and the walk
|
|
202
|
+
* starts at this module's own location rather than at `process.cwd()`: the server is started from
|
|
203
|
+
* wherever the user happened to be, and the answer must not depend on that.
|
|
204
|
+
*/
|
|
205
|
+
export function bundledPiCommand(exists = defaultExists(process.platform), platform = process.platform) {
|
|
206
|
+
const at = joinFor(platform);
|
|
207
|
+
let dir = import.meta.dirname;
|
|
208
|
+
for (let depth = 0; depth < 6; depth += 1) {
|
|
209
|
+
for (const binDir of [at(dir, ".bin"), at(dir, "node_modules", ".bin")]) {
|
|
210
|
+
for (const name of launcherNames(platform)) {
|
|
211
|
+
const candidate = at(binDir, name);
|
|
212
|
+
if (exists(candidate))
|
|
213
|
+
return candidate;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const parent = at(dir, "..");
|
|
217
|
+
if (parent === dir)
|
|
218
|
+
break;
|
|
219
|
+
dir = parent;
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Decodes a child process's output, falling back to the console code page when it is not UTF-8.
|
|
225
|
+
*
|
|
226
|
+
* A Windows `.cmd` shim runs under cmd.exe, which writes its own diagnostics in the console's code
|
|
227
|
+
* page - GBK on a Chinese Windows - so `chunk.toString()` renders `'pi.cmd' 不是内部或外部命令` as
|
|
228
|
+
* `'pi.cmd' ??????`. Reading those bytes as UTF-8 fatal first and retrying as GBK is what keeps the
|
|
229
|
+
* message readable, and therefore what keeps the next reader from mistaking a PATH problem for an
|
|
230
|
+
* encoding one.
|
|
231
|
+
*/
|
|
232
|
+
export function decodeProcessOutput(chunks, fallbackCodePage = "gbk") {
|
|
233
|
+
const buffer = Buffer.concat([...chunks]);
|
|
234
|
+
try {
|
|
235
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(buffer);
|
|
236
|
+
}
|
|
237
|
+
catch { /* not UTF-8 - fall through to the code page below */ }
|
|
238
|
+
try {
|
|
239
|
+
return new TextDecoder(fallbackCodePage).decode(buffer);
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return buffer.toString("latin1");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* True when the text says the command itself was not found, which is a PATH or install problem rather
|
|
247
|
+
* than a rejection by Pi - the two are indistinguishable once the output is garbled, so the diagnosis
|
|
248
|
+
* is made on the decoded text rather than guessed from an exit code.
|
|
249
|
+
*/
|
|
250
|
+
export function looksLikeCommandNotFound(text) {
|
|
251
|
+
return /不是内部或外部命令|不是可识别的内部或外部命令|not recognized as an internal or external command|command not found|No such file or directory/i.test(text);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Quotes a resolved command for `shell: true` spawns on Windows.
|
|
255
|
+
*
|
|
256
|
+
* npm's global bin directory can sit under a path with spaces (`C:\Program Files\nodejs`), and node
|
|
257
|
+
* joins a shell command out of argv WITHOUT quoting it, so an unquoted resolved path fails to launch
|
|
258
|
+
* on exactly the machine where PATH lookup did not already find Pi. A command with no spaces - the
|
|
259
|
+
* common case, and every fake launcher the tests use - is returned untouched.
|
|
260
|
+
*/
|
|
261
|
+
export function shellQuote(command, platform = process.platform) {
|
|
262
|
+
if (platform !== "win32" || !/\s/.test(command) || command.includes("\""))
|
|
263
|
+
return command;
|
|
264
|
+
return `"${command}"`;
|
|
265
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Module = Record<string, any>;
|
|
2
|
+
export declare function piNative(): Promise<{
|
|
3
|
+
sdk: any;
|
|
4
|
+
config: Module;
|
|
5
|
+
cli: Module;
|
|
6
|
+
oauth: Module;
|
|
7
|
+
auth: Module;
|
|
8
|
+
core: Module;
|
|
9
|
+
runtime: Module;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function mcpCredentials(api: Awaited<ReturnType<typeof piNative>>, agentDir: string): any;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let modules;
|
|
2
|
+
export function piNative() {
|
|
3
|
+
return modules ??= (async () => {
|
|
4
|
+
const name = "@earendil-works/pi-coding-agent";
|
|
5
|
+
const base = import.meta.resolve(name);
|
|
6
|
+
const read = (path) => import(new URL(path, base).href);
|
|
7
|
+
const [sdk, config, cli, oauth, auth, core, runtime] = await Promise.all([
|
|
8
|
+
import(name), read("./extensions/mcp/config.js"), read("./extensions/mcp/cli.js"),
|
|
9
|
+
read("./extensions/mcp/oauth.js"), read("./core/auth-storage.js"), read("./core/mcp-servers.js"), read("./extensions/mcp/runtime.js"),
|
|
10
|
+
]);
|
|
11
|
+
return { sdk, config, cli, oauth, auth, core, runtime };
|
|
12
|
+
})();
|
|
13
|
+
}
|
|
14
|
+
export function mcpCredentials(api, agentDir) {
|
|
15
|
+
return new api.oauth.McpOAuthCredentialStore(new api.auth.FileAuthStorageBackend(`${agentDir}/mcp-auth.json`), agentDir);
|
|
16
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE EVENT BRIDGE: turns a Pi session's event stream into the turn-shaped stream Super Pi consumes.
|
|
3
|
+
*
|
|
4
|
+
* WHY A BRIDGE AND NOT AN INLINE LOOP. The old design read a child's stdout in a `while` loop and
|
|
5
|
+
* dispatched records inline. The new design has no child and no stdout: Pi emits EVENTS through a
|
|
6
|
+
* subscription. A subscription is a push, and Super Pi's turn is a pull - `answer()` is an async
|
|
7
|
+
* generator that yields text deltas to its caller.
|
|
8
|
+
*
|
|
9
|
+
* A push has to become a pull somewhere, and this is where. The bridge keeps a queue of pending items
|
|
10
|
+
* and hands them out one at a time; the generator awaits the next item when the queue is empty. The
|
|
11
|
+
* ordering that matters is preserved exactly: the subscription callback pushes, and the queue is FIFO,
|
|
12
|
+
* so the order the reader sees is the order Pi emitted.
|
|
13
|
+
*
|
|
14
|
+
* THE BOUNDARY IS THE SAME AS BEFORE. Only the events Super Pi already consumed are routed; everything
|
|
15
|
+
* else is counted and reported once, exactly as the old `noteUnhandled` did. A record type that used to
|
|
16
|
+
* be announced as unhandled is still announced as unhandled - this bridge changes WHERE the events come
|
|
17
|
+
* from, not what they mean.
|
|
18
|
+
*/
|
|
19
|
+
import type { PiQueueSnapshot, ToolCallNotice, ToolCallPreparing } from "./types.js";
|
|
20
|
+
/**
|
|
21
|
+
* Reads a `queue_update` payload, or returns undefined when the record is not one.
|
|
22
|
+
*
|
|
23
|
+
* The same recogniser the RPC drain loop uses, and deliberately so: Pi's RPC mode forwards the session's
|
|
24
|
+
* own events verbatim, so a `queue_update` from a persistent SDK session and one from a child's stdout
|
|
25
|
+
* are the same fact in the same shape - Pi reporting what its in-memory steering/follow-up queues hold
|
|
26
|
+
* (`agent-session.ts:_emitQueueUpdate`). It is the ONLY proof that a steer was actually picked up: Pi
|
|
27
|
+
* removes the entry from its queue and emits this snapshot BEFORE it emits the delivered `message_start`,
|
|
28
|
+
* so a host that ignored it would have no way to tell "queued in Pi" from "delivered to the model".
|
|
29
|
+
*/
|
|
30
|
+
export declare function describePiQueue(record: unknown): PiQueueSnapshot | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Reads the text of a steer Pi has just delivered, or undefined when this record is not one.
|
|
33
|
+
*
|
|
34
|
+
* A `message_start` carrying a `user` message is exactly that, and nothing else is: the prompt that
|
|
35
|
+
* opened the turn is never re-announced this way, and `assistant` messages are not deliveries.
|
|
36
|
+
*
|
|
37
|
+
* Content is joined with a newline rather than taken from the first block, so a multi-block steer comes
|
|
38
|
+
* back as the text the user actually wrote instead of its first paragraph. The text is a MATCHING HINT
|
|
39
|
+
* only - Pi identifies its own queued entry by `indexOf` on this string (`agent-session.ts:1123`) and so
|
|
40
|
+
* cannot tell two identical messages apart either, which is why the caller resolves a delivery by
|
|
41
|
+
* position and not by comparing this.
|
|
42
|
+
*/
|
|
43
|
+
export declare function describeDeliveredUserMessage(record: unknown): string | undefined;
|
|
44
|
+
/** What the bridge hands to the turn, one item at a time. */
|
|
45
|
+
export type TurnItem =
|
|
46
|
+
/** A chunk of assistant text. */
|
|
47
|
+
{
|
|
48
|
+
kind: "text";
|
|
49
|
+
delta: string;
|
|
50
|
+
}
|
|
51
|
+
/** Non-text notices share the text FIFO; delivery may await a transcript boundary. */
|
|
52
|
+
| {
|
|
53
|
+
kind: "callback";
|
|
54
|
+
run: () => void | Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** The turn is over. */
|
|
57
|
+
| {
|
|
58
|
+
kind: "end";
|
|
59
|
+
}
|
|
60
|
+
/** The turn failed. */
|
|
61
|
+
| {
|
|
62
|
+
kind: "error";
|
|
63
|
+
error: Error;
|
|
64
|
+
};
|
|
65
|
+
/** The callbacks a turn supplies. The names match the RPC runtime's, so the two paths behave alike. */
|
|
66
|
+
export interface TurnEventHandlers {
|
|
67
|
+
onToolCall?(call: ToolCallNotice): void;
|
|
68
|
+
/**
|
|
69
|
+
* Called when a tool that WRITES A FILE is announced, with the path it is about to write.
|
|
70
|
+
*
|
|
71
|
+
* The same hook the RPC runtime has, and for the same reason: the announcement is the last moment
|
|
72
|
+
* the old content is still on the disk, so it is the only moment a diff baseline can be taken. The two
|
|
73
|
+
* paths (SDK session and spawned RPC) must agree on WHEN this fires, or the same edit would be
|
|
74
|
+
* baselined on one path and not on the other.
|
|
75
|
+
*/
|
|
76
|
+
onFileWrite?(path: string, toolName: string, toolCallId?: string): void;
|
|
77
|
+
onToolUpdate?(call: ToolCallNotice): void;
|
|
78
|
+
onToolPreparing?(call: ToolCallPreparing): void;
|
|
79
|
+
onToolEnd?(call: ToolCallNotice): void;
|
|
80
|
+
onThinking?(delta: string): void;
|
|
81
|
+
onThinkingEnd?(): void;
|
|
82
|
+
/** A steer this turn delivered - the text Pi picked up from its own queue. */
|
|
83
|
+
onSteerDelivered?(text: string): void | Promise<void>;
|
|
84
|
+
/** Pi's own queue, as a full snapshot. */
|
|
85
|
+
onPiQueue?(queue: {
|
|
86
|
+
steering: string[];
|
|
87
|
+
followUp: string[];
|
|
88
|
+
}): void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The failure Pi reported in the message that ended the turn, if it reported one.
|
|
92
|
+
*
|
|
93
|
+
* WHY IT IS HELD AND NOT THROWN ON THE SPOT. Pi retries on its own: an assistant message that ends
|
|
94
|
+
* with `stopReason: "error"` may be followed by another assistant message, and only the LAST one
|
|
95
|
+
* decides whether the turn failed. So the failure is remembered when it arrives and raised when Pi
|
|
96
|
+
* SETTLES - which is the moment Pi has stopped working on its own and the answer is final. A failure
|
|
97
|
+
* raised at the moment it arrives would abort a turn Pi was about to retry, and the retry would then
|
|
98
|
+
* look like the user's problem.
|
|
99
|
+
*
|
|
100
|
+
* THE SAME RULES AS THE ONE-SHOT PATH, which already got this right (`runtime.ts`: the RPC drain loop
|
|
101
|
+
* reads the terminal outcome off `agent_end` and throws at `agent_settled`). A provider failure is a
|
|
102
|
+
* failure; a response that hit the length limit is an INCOMPLETE answer and is one too. An `"aborted"`
|
|
103
|
+
* is NOT a failure here: the person stopped the turn, and a stopped turn is a turn that ended - the
|
|
104
|
+
* one-shot path can tell the difference because it knows whether the signal was aborted, and the
|
|
105
|
+
* session path does not need to: an abort is the user's own action and the run service already
|
|
106
|
+
* records it as stopped.
|
|
107
|
+
*/
|
|
108
|
+
export interface TurnFailure {
|
|
109
|
+
/** The message Pi reported, in its own words. */
|
|
110
|
+
message: string;
|
|
111
|
+
/** The raw reason, kept so a caller can tell a provider failure from anything else. */
|
|
112
|
+
stopReason: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Reads the failure out of a `message_end` record, or undefined when it is not a failed one.
|
|
116
|
+
*
|
|
117
|
+
* ONLY THE ASSISTANT'S MESSAGE COUNTS. `message_end` also fires for user messages, tool results and
|
|
118
|
+
* custom messages, and none of those is a turn failing.
|
|
119
|
+
*/
|
|
120
|
+
export declare function describeMessageFailure(record: unknown): TurnFailure | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* A queue of turn items, with the waiters that are blocked on it.
|
|
123
|
+
*
|
|
124
|
+
* The `settled` flag matters: a turn that ends must release every waiter, including one that is
|
|
125
|
+
* waiting for text that will never arrive. A generator awaiting an item on a queue nobody will ever
|
|
126
|
+
* push to is a turn that hangs forever, and a hung turn is a conversation that never answers.
|
|
127
|
+
*/
|
|
128
|
+
export declare class TurnQueue {
|
|
129
|
+
private readonly items;
|
|
130
|
+
private readonly waiters;
|
|
131
|
+
private settled;
|
|
132
|
+
/**
|
|
133
|
+
* Resolves when Pi has SETTLED the turn, which is the real end of a turn.
|
|
134
|
+
*
|
|
135
|
+
* The distinction matters: Pi's `prompt()` resolves when the message has been accepted, which is
|
|
136
|
+
* long before the agent has settled. A caller that treats the prompt's resolution as the end of the
|
|
137
|
+
* turn would release the reader while the model was still producing - and the next turn would then
|
|
138
|
+
* arrive at a session Pi considers busy, which Pi refuses outright.
|
|
139
|
+
*/
|
|
140
|
+
readonly settledSignal: Promise<void>;
|
|
141
|
+
private markSettled;
|
|
142
|
+
constructor();
|
|
143
|
+
push(item: TurnItem): void;
|
|
144
|
+
/** Settles the queue with an error, for a turn that failed before it produced anything. */
|
|
145
|
+
fail(error: Error): void;
|
|
146
|
+
next(): Promise<TurnItem>;
|
|
147
|
+
get isSettled(): boolean;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Handles one Pi event, routing it to the queue and to the turn's callbacks.
|
|
151
|
+
*
|
|
152
|
+
* Returns whether the event was consumed. An unconsumed event is reported once per distinct type and
|
|
153
|
+
* then counted - the same policy the RPC loop applied, and for the same reason: an event type nobody
|
|
154
|
+
* understands is worth saying out loud exactly once.
|
|
155
|
+
*/
|
|
156
|
+
export declare function handleSessionEvent(event: unknown, queue: TurnQueue, handlers: TurnEventHandlers, report: (key: string) => void, failure?: {
|
|
157
|
+
current: TurnFailure | undefined;
|
|
158
|
+
}): boolean;
|