@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,507 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `task` tool: how a primary agent hands work to a sub-agent on its own initiative.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS FILE EXISTS. The pipe was already built - `subagents.ts` spawns a child and streams it,
|
|
5
|
+
* `subagent-runs.ts` records and publishes it, and a human can already press a button to use it. What
|
|
6
|
+
* was missing is the mouth: a primary agent had no way to reach any of it, so the ONLY way to use a
|
|
7
|
+
* sub-agent was for a person to type into a form. This module is the policy half of that mouth - the
|
|
8
|
+
* rules about WHO may dispatch, HOW DEEP, and WITH WHICH TOOLS - and it holds no I/O at all, so every
|
|
9
|
+
* rule here can be proved without spawning a process.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IS BORROWED FROM OPENCODE, and what is not:
|
|
12
|
+
*
|
|
13
|
+
* - `tool/task.ts:104-117` - the depth walk and `depth >= subagent_depth` refusal. OpenCode counts
|
|
14
|
+
* depth by walking session parents; Super Pi has one level of session, so depth is a number the
|
|
15
|
+
* caller states and the server checks (see `checkSubagentDepth`).
|
|
16
|
+
* - `tool/task.ts:64-79` - the `<task id state><task_result>` envelope. Rendered on the EXTENSION side
|
|
17
|
+
* (`agents/super-pi-task/core.ts`), because that is the tool's return value, not the server's.
|
|
18
|
+
* - `agent/subagent-permissions.ts:21-23` - a child inherits the parent's DENY rules. Note what that
|
|
19
|
+
* file does NOT do: it never intersects the parent's ALLOWLIST into the child, because "the parent
|
|
20
|
+
* agent's restrictions govern that agent" (its own header). Super Pi follows the same rule - see
|
|
21
|
+
* `parentDeniedTools`.
|
|
22
|
+
* - `tool/registry.ts:265-278` - the roster injected into the model's view of the tool. Built here
|
|
23
|
+
* from `readAgents`, injected through the environment, rendered by the extension.
|
|
24
|
+
*/
|
|
25
|
+
/** The name the model calls. Also the key Pi's tool allowlist matches on, and the deny key in `tools:`. */
|
|
26
|
+
export const TASK_TOOL_NAME = "task";
|
|
27
|
+
export const WORKTREE_TOOL_NAME = "worktree";
|
|
28
|
+
/**
|
|
29
|
+
* The independent background-command tool. NOT a sub-agent dispatch.
|
|
30
|
+
*
|
|
31
|
+
* Mirrored from `agents/super-pi-task/core.ts` for the same reason `TASK_TOOL_NAME` is: a tool name
|
|
32
|
+
* is a wire between two files Pi's module loader cannot cross, and `scripts/task-tool.test.mjs`
|
|
33
|
+
* asserts the two copies agree. Renaming on one side alone would fail at registerTool time with a
|
|
34
|
+
* message nobody reads.
|
|
35
|
+
*/
|
|
36
|
+
export const RUN_ASYNC_TOOL_NAME = "run_async";
|
|
37
|
+
/**
|
|
38
|
+
* How many task hops are allowed below a primary agent.
|
|
39
|
+
*
|
|
40
|
+
* `1` means: a primary agent may dispatch a sub-agent, and that sub-agent may not dispatch anything.
|
|
41
|
+
* OpenCode's default is the same number (`task.ts:111`, `cfg.subagent_depth ?? 1`).
|
|
42
|
+
*
|
|
43
|
+
* WHY THE NUMBER IS NOT A LOOP WALK. OpenCode counts session parents because it runs the child as a
|
|
44
|
+
* session inside the same process. Super Pi runs the child as a SEPARATE Pi process
|
|
45
|
+
* (`subagents.ts`, research note 3), so a child has no parent session to walk. It is enforced three
|
|
46
|
+
* other ways instead, and this constant is the belt to those braces:
|
|
47
|
+
*
|
|
48
|
+
* 1. STRUCTURAL - only `PiRpcRuntime` passes `--extension`, and only the primary agent runs through
|
|
49
|
+
* `PiRpcRuntime`. A child's argv never names the extension, so the child has no `task` tool at all.
|
|
50
|
+
* 2. ALLOWLIST - `toolFlags` adds `task` to the primary's `--tools` list and to nothing else's, so even
|
|
51
|
+
* an agent that loads the extension cannot be handed the tool by inheritance.
|
|
52
|
+
* 3. DECLARED - `checkSubagentDepth` refuses a request that says it is already nested.
|
|
53
|
+
*
|
|
54
|
+
* All three agree, and (1) is the one that actually holds. Raising this constant alone would change
|
|
55
|
+
* nothing, which is deliberate: the constant is the server's statement of intent, and the wiring is
|
|
56
|
+
* the enforcement.
|
|
57
|
+
*/
|
|
58
|
+
export const DEFAULT_SUBAGENT_DEPTH = 1;
|
|
59
|
+
/**
|
|
60
|
+
* The environment contract between the server and the Pi child that carries the extension.
|
|
61
|
+
*
|
|
62
|
+
* These four names are a WIRE between two files that live in the same repository and are loaded by two
|
|
63
|
+
* different module systems, so they are written out on both sides rather than imported. The extension
|
|
64
|
+
* side is `agents/super-pi-task/core.ts`; `scripts/task-tool.test.mjs` asserts the two copies agree,
|
|
65
|
+
* because a rename on one side would otherwise fail at dispatch time with a message no one reads.
|
|
66
|
+
*/
|
|
67
|
+
export const TASK_ENDPOINT_ENV = "SUPER_PI_TASK_ENDPOINT";
|
|
68
|
+
/** Exec endpoint for background shell commands, independent from subagent dispatch. */
|
|
69
|
+
export const TASK_EXEC_ENDPOINT_ENV = "SUPER_PI_EXEC_ENDPOINT";
|
|
70
|
+
/** JSON roster, read from `readAgents(dir, { mode: "subagent" })` at SPAWN time - never hardcoded. */
|
|
71
|
+
export const TASK_ROSTER_ENV = "SUPER_PI_TASK_ROSTER";
|
|
72
|
+
/** The conversation the dispatch belongs to. The server resolves the workspace from this itself. */
|
|
73
|
+
export const TASK_CONVERSATION_ENV = "SUPER_PI_TASK_CONVERSATION";
|
|
74
|
+
/** The conversation that spawned this one. Empty means a top-level conversation. */
|
|
75
|
+
export const PARENT_CONVERSATION_ENV = "SUPER_PI_PARENT_CONVERSATION";
|
|
76
|
+
/** How many task hops deep this process already is. A primary is `0`. See `DEFAULT_SUBAGENT_DEPTH`. */
|
|
77
|
+
export const TASK_DEPTH_ENV = "SUPER_PI_TASK_DEPTH";
|
|
78
|
+
/**
|
|
79
|
+
* The name the model calls to hand an ordered plan of sub-agent steps to the server.
|
|
80
|
+
*
|
|
81
|
+
* A THIRD tool rather than an extra parameter on `task`, and the reason is what the server does with the
|
|
82
|
+
* two. `task` is one delegation whose result the model reads back and acts on itself; `workflow` is a
|
|
83
|
+
* plan the server walks, carrying each step's output into the next without the model in the middle. One
|
|
84
|
+
* tool with a `steps` array would make every single delegation carry a shape it cannot use, and would make
|
|
85
|
+
* "dispatch one agent" and "run this pipeline" indistinguishable in the transcript - which is the opposite
|
|
86
|
+
* of what the model needs to choose between them.
|
|
87
|
+
*/
|
|
88
|
+
export const WORKFLOW_TOOL_NAME = "workflow";
|
|
89
|
+
/**
|
|
90
|
+
* The endpoint the `workflow` tool dials. A FIFTH name in the same wire as the four above, written out on
|
|
91
|
+
* both sides for the same reason.
|
|
92
|
+
*
|
|
93
|
+
* A SEPARATE variable rather than a path derived from `TASK_ENDPOINT_ENV`, for the reason
|
|
94
|
+
* `TODO_ENDPOINT_ENV` already states: a Pi can legitimately be started with a dispatch endpoint and no
|
|
95
|
+
* workflow endpoint, and a derived path could not tell that apart from a misconfiguration. The tool then
|
|
96
|
+
* refuses in words instead of posting somewhere that does not exist.
|
|
97
|
+
*/
|
|
98
|
+
export const WORKFLOW_ENDPOINT_ENV = "SUPER_PI_WORKFLOW_ENDPOINT";
|
|
99
|
+
/**
|
|
100
|
+
* The dispatchable roster, in the order it will be injected.
|
|
101
|
+
*
|
|
102
|
+
* `hidden` definitions are excluded, matching `readAgentCatalog`: a sub-agent marked hidden is
|
|
103
|
+
* documented as not for automatic dispatch, and the model's only channel for dispatching IS automatic.
|
|
104
|
+
* The sort is the one `readAgents` already applied, kept rather than re-sorted so the injected list
|
|
105
|
+
* reads the same way as the picker.
|
|
106
|
+
*/
|
|
107
|
+
export function subagentRoster(agents) {
|
|
108
|
+
return agents
|
|
109
|
+
.filter((agent) => agent.mode === "subagent" && !agent.hidden)
|
|
110
|
+
.map((agent) => ({ id: agent.id, name: agent.name, description: agent.description }));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The roster as one environment variable's worth of JSON.
|
|
114
|
+
*
|
|
115
|
+
* A CHILD PROCESS ENVIRONMENT IS NOT A CONFIG FILE. On Windows the whole environment block is capped at
|
|
116
|
+
* 32,768 characters, and a server that would spawn a primary Pi successfully and then fail to spawn
|
|
117
|
+
* one a moment later because a directory of agents grew would be a fault with no visible cause. So the
|
|
118
|
+
* payload is truncated at a budget that leaves the rest of the block alone, and the truncation is
|
|
119
|
+
* announced rather than silent: the injected list ends with a line saying it was cut short, because a
|
|
120
|
+
* roster that quietly omits an agent is a roster that makes the model pick wrongly with no way to know.
|
|
121
|
+
*/
|
|
122
|
+
export const ROSTER_ENV_BUDGET = 12_000;
|
|
123
|
+
export function rosterPayload(agents) {
|
|
124
|
+
const roster = subagentRoster(agents);
|
|
125
|
+
const json = JSON.stringify(roster);
|
|
126
|
+
if (json.length <= ROSTER_ENV_BUDGET)
|
|
127
|
+
return json;
|
|
128
|
+
const kept = [];
|
|
129
|
+
let used = 2;
|
|
130
|
+
for (const entry of roster) {
|
|
131
|
+
const size = JSON.stringify(entry).length + 1;
|
|
132
|
+
if (used + size > ROSTER_ENV_BUDGET - 160)
|
|
133
|
+
break;
|
|
134
|
+
kept.push(entry);
|
|
135
|
+
used += size;
|
|
136
|
+
}
|
|
137
|
+
return JSON.stringify([...kept, { id: "__truncated__", name: "(名单过长已截断)", description: `There were ${roster.length} sub-agents and only ${kept.length} fit into this session's environment; the rest were dropped rather than risk failing to start Pi.` }]);
|
|
138
|
+
}
|
|
139
|
+
/** Reads a roster back out of an environment value. Anything unreadable is an empty roster, never a throw. */
|
|
140
|
+
export function parseRoster(raw) {
|
|
141
|
+
if (!raw)
|
|
142
|
+
return [];
|
|
143
|
+
let parsed;
|
|
144
|
+
try {
|
|
145
|
+
parsed = JSON.parse(raw);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
if (!Array.isArray(parsed))
|
|
151
|
+
return [];
|
|
152
|
+
return parsed.filter((entry) => typeof entry === "object" && entry !== null &&
|
|
153
|
+
typeof entry.id === "string" && entry.id !== "" &&
|
|
154
|
+
typeof entry.description === "string");
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Refuses a dispatch that claims to be nested deeper than this install allows.
|
|
158
|
+
*
|
|
159
|
+
* `depth` is how many task hops the CALLER already is: a primary agent's extension is `0`, and anything
|
|
160
|
+
* that dispatched from inside a sub-agent would be `1` or more. `>=` rather than `>` is OpenCode's
|
|
161
|
+
* comparison (`task.ts:111`) and it is what makes the default mean "one layer of children".
|
|
162
|
+
*
|
|
163
|
+
* The message is the deliverable as much as the refusal is. It arrives as the tool's error text and is
|
|
164
|
+
* therefore read by a MODEL that is about to retry, so it names the number, says what to do about it,
|
|
165
|
+
* and does not say "invalid request".
|
|
166
|
+
*/
|
|
167
|
+
export function checkSubagentDepth(depth, maxDepth = DEFAULT_SUBAGENT_DEPTH) {
|
|
168
|
+
if (Number.isFinite(depth) && depth < maxDepth)
|
|
169
|
+
return;
|
|
170
|
+
throw new Error(`Subagent depth limit reached (${maxDepth}). This agent is already running as a sub-agent, and a sub-agent may not dispatch another one. Ask whoever is driving the primary agent to make the call instead, or raise the limit deliberately if this really needs to nest.`);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The tools a parent agent's own definition DENIES, as concrete Pi tool names.
|
|
174
|
+
*
|
|
175
|
+
* ONLY denies, never an allowlist - the same rule as OpenCode's `deriveSubagentSessionPermission`, whose
|
|
176
|
+
* header states why: "Parent agent restrictions only govern that agent; the subagent's own permissions
|
|
177
|
+
* determine its capabilities." A parent that narrowed itself to `{read}` has not expressed "everything
|
|
178
|
+
* else is forbidden everywhere", and copying that into every child would silently strip a child of the
|
|
179
|
+
* write tools its own author gave it.
|
|
180
|
+
*
|
|
181
|
+
* Read out of `toolFlags` rather than a kept copy of the raw frontmatter because `toolFlags` IS the
|
|
182
|
+
* translated decision: `{"bash": false}` has already become `--exclude-tools bash` by the time a
|
|
183
|
+
* definition exists, and re-deriving it from the map would be a second implementation of the
|
|
184
|
+
* translation rather than a reader of the first.
|
|
185
|
+
*/
|
|
186
|
+
export function parentDeniedTools(parent) {
|
|
187
|
+
if (!parent)
|
|
188
|
+
return [];
|
|
189
|
+
const index = parent.toolFlags.indexOf("--exclude-tools");
|
|
190
|
+
if (index < 0)
|
|
191
|
+
return [];
|
|
192
|
+
const value = parent.toolFlags[index + 1];
|
|
193
|
+
return value ? value.split(",").map((name) => name.trim()).filter((name) => name !== "") : [];
|
|
194
|
+
}
|
|
195
|
+
// ---------------------------------------------------------------------------------------------
|
|
196
|
+
// The `todowrite` tool: the model's own task list, which the right sidebar renders.
|
|
197
|
+
//
|
|
198
|
+
// WHAT IS BORROWED FROM OPENCODE, and what is not:
|
|
199
|
+
//
|
|
200
|
+
// - `tool/todo.ts` is 46 lines and almost all of it is Effect plumbing: a schema, an `ask()` for the
|
|
201
|
+
// `todowrite` permission, and a call into a per-session store. What survives the port is the two
|
|
202
|
+
// decisions that file makes - the tool's OUTPUT is the whole list as JSON (so the model's next turn
|
|
203
|
+
// reads the current plan back out of its own history rather than out of a UI), and the tool is
|
|
204
|
+
// REGISTERED per session rather than globally.
|
|
205
|
+
// - `tool/todowrite.txt` is the description, and it is ported nearly verbatim (see
|
|
206
|
+
// `agents/super-pi-task/core.ts`). The "Use proactively when" list IS the mechanism: OpenCode never
|
|
207
|
+
// injects the todo list into a system prompt, so the trigger rules in the description are the only
|
|
208
|
+
// thing that makes a model update the list unprompted, and they are therefore not paraphrased here.
|
|
209
|
+
// - OpenCode's `session/todo.ts` keys the list by session. Super Pi has one list, not one per
|
|
210
|
+
// conversation, because `AppState.todos` is a single array - see the note on `TodoItem` for what that
|
|
211
|
+
// costs and why it is not solved in this file.
|
|
212
|
+
//
|
|
213
|
+
// WHAT IS ADDED, and why it is here rather than in the extension: TRUST BOUNDARY. Everything in this
|
|
214
|
+
// section runs on data that arrived over HTTP from a process the model controls the inputs of. The
|
|
215
|
+
// extension cannot import this file (Pi hands extensions a different module system - see
|
|
216
|
+
// `agents/super-pi-task/index.ts`), so if the rules lived there the server would be validating a list it
|
|
217
|
+
// never checked, and `state.json` would carry whatever the model happened to send.
|
|
218
|
+
/**
|
|
219
|
+
* The name the model calls. OpenCode's name, kept: a model trained on OpenCode's tool set reaches for
|
|
220
|
+
* `todowrite` and not `todo`, and there is nothing to gain from renaming a tool whose description has
|
|
221
|
+
* already been written to explain that name.
|
|
222
|
+
*/
|
|
223
|
+
export const PROJECT_TOOL_NAME = "project";
|
|
224
|
+
export const PROJECT_ENDPOINT_ENV = "SUPER_PI_PROJECT_ENDPOINT";
|
|
225
|
+
export const TODO_TOOL_NAME = "todowrite";
|
|
226
|
+
/**
|
|
227
|
+
* The endpoint the `todowrite` extension dials. A FIFTH name in the same wire as the four above, written
|
|
228
|
+
* out on both sides for the same reason: `agents/super-pi-task/core.ts` is loaded by Pi's module loader
|
|
229
|
+
* and `src/server/task-tool.ts` by tsc, so a relative import across the two would resolve differently
|
|
230
|
+
* under each. `scripts/todo-tool.test.mjs` asserts the two copies agree.
|
|
231
|
+
*
|
|
232
|
+
* It is a SEPARATE variable rather than a path derived from `TASK_ENDPOINT_ENV` because a Pi can
|
|
233
|
+
* legitimately be started with a task endpoint and no todo endpoint - a test harness, a checkout from
|
|
234
|
+
* before this tool existed - and a derived path could not tell that apart from a misconfiguration. The
|
|
235
|
+
* tool then refuses in words instead of posting somewhere that does not exist.
|
|
236
|
+
*/
|
|
237
|
+
export const TODO_ENDPOINT_ENV = "SUPER_PI_TODO_ENDPOINT";
|
|
238
|
+
/**
|
|
239
|
+
* The name the model calls to manage the SCHEDULED TASKS.
|
|
240
|
+
*
|
|
241
|
+
* `scheduled_task`, with an underscore, because this is not one of OpenCode's tools and there is no
|
|
242
|
+
* prior name to match. The name says what it is: a task that runs on a schedule.
|
|
243
|
+
*/
|
|
244
|
+
export const SCHEDULED_TASK_TOOL_NAME = "scheduled_task";
|
|
245
|
+
/**
|
|
246
|
+
* The endpoint the `scheduled_task` tool dials. Another name in the same wire, written out on both
|
|
247
|
+
* sides for the same reason `TODO_ENDPOINT_ENV` states: `agents/super-pi-task/core.ts` is loaded by
|
|
248
|
+
* Pi's module loader and this file by tsc, so the two copies have to agree by hand -
|
|
249
|
+
* `scripts/scheduled-task-tool.test.mjs` asserts that they do.
|
|
250
|
+
*
|
|
251
|
+
* A SEPARATE variable rather than a path derived from `TODO_ENDPOINT_ENV`, for the reason that one
|
|
252
|
+
* states: a Pi can legitimately have one and not the other, and a derived path could not tell those
|
|
253
|
+
* apart from a misconfiguration.
|
|
254
|
+
*/
|
|
255
|
+
export const SCHEDULED_TASK_ENDPOINT_ENV = "SUPER_PI_SCHEDULED_TASK_ENDPOINT";
|
|
256
|
+
/**
|
|
257
|
+
* How many todos may be stored, and how long one may be.
|
|
258
|
+
*
|
|
259
|
+
* NOT A LIMIT OPENCODE HAS, and the reason it exists here is specific to this app: `state.json` is
|
|
260
|
+
* serialized on EVERY broadcast - every text delta of every turn - and `snapshot()` is a structuredClone
|
|
261
|
+
* of the whole state per connected browser. An unbounded list written by a model in a loop is therefore
|
|
262
|
+
* not just a large file, it is a large file re-serialized thousands of times within one turn. Fifty items
|
|
263
|
+
* is more than a plan of any real size and 400 characters is more than a sidebar row shows before it
|
|
264
|
+
* truncates, so neither bound is one a person would notice being reached.
|
|
265
|
+
*
|
|
266
|
+
* Over the cap is TRUNCATED, not refused. The model is mid-task and its call was correct in kind;
|
|
267
|
+
* refusing would produce an error envelope about a limit it cannot reason about, while a truncated list
|
|
268
|
+
* still shows the first fifty steps and the call still succeeds. `dropped` travels back to the caller so
|
|
269
|
+
* the model is told rather than left to notice.
|
|
270
|
+
*/
|
|
271
|
+
export const TODO_MAX_ITEMS = 50;
|
|
272
|
+
export const TODO_MAX_CONTENT = 400;
|
|
273
|
+
/**
|
|
274
|
+
* What a `todowrite` body is allowed to become.
|
|
275
|
+
*
|
|
276
|
+
* Every field is checked because every field is rendered: `content` is the row a person reads, `status`
|
|
277
|
+
* chooses that row's colour and glyph, and `priority` is its badge. A list read straight out of
|
|
278
|
+
* `JSON.parse` would put `undefined` into all three, and a status of `"banana"` would fall through every
|
|
279
|
+
* colour rule in `styles.css` and render like a completed item - because "is this the completed style"
|
|
280
|
+
* is asked with `===`, and anything unknown is not it.
|
|
281
|
+
*
|
|
282
|
+
* THE FOUR RULES, and what each failure would cost:
|
|
283
|
+
*
|
|
284
|
+
* - A non-string or blank `content` is DROPPED. There is no safe default text: a row that says nothing is
|
|
285
|
+
* a row the user cannot act on, and it also consumes a slot of the cap below.
|
|
286
|
+
* - An unknown `status` becomes `pending`, neither dropped nor thrown on. Dropping loses work the model is
|
|
287
|
+
* about to do and throwing fails a call that was otherwise correct; `pending` is the state that claims
|
|
288
|
+
* the least, so the row is visible and slightly wrong rather than invisible.
|
|
289
|
+
* - An unknown `priority` DELETES the key. Absent is a real state here - the badge is simply not drawn -
|
|
290
|
+
* so there is nothing to repair, and inventing `"medium"` would put a badge on a row that never asked.
|
|
291
|
+
* - A missing `id` is FILLED IN, and an existing one is KEPT rather than regenerated, so the sidebar's
|
|
292
|
+
* React keys stay stable and a status change does not remount the row it changed. Two identical lines
|
|
293
|
+
* of text without ids would share one key, and React would reuse the first row's DOM for the second.
|
|
294
|
+
*/
|
|
295
|
+
export function normalizeTodos(raw) {
|
|
296
|
+
if (!Array.isArray(raw))
|
|
297
|
+
return { todos: [], dropped: 0 };
|
|
298
|
+
const statuses = new Set(["pending", "in_progress", "completed"]);
|
|
299
|
+
const priorities = new Set(["high", "medium", "low"]);
|
|
300
|
+
const todos = [];
|
|
301
|
+
let dropped = 0;
|
|
302
|
+
for (const entry of raw) {
|
|
303
|
+
if (todos.length >= TODO_MAX_ITEMS) {
|
|
304
|
+
dropped++;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (typeof entry !== "object" || entry === null) {
|
|
308
|
+
dropped++;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const item = entry;
|
|
312
|
+
const content = typeof item.content === "string" ? item.content.trim().slice(0, TODO_MAX_CONTENT) : "";
|
|
313
|
+
if (!content) {
|
|
314
|
+
dropped++;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const status = typeof item.status === "string" && statuses.has(item.status) ? item.status : "pending";
|
|
318
|
+
const priority = typeof item.priority === "string" && priorities.has(item.priority) ? item.priority : undefined;
|
|
319
|
+
const id = typeof item.id === "string" && item.id.trim() ? item.id.trim() : `todo_${crypto.randomUUID()}`;
|
|
320
|
+
todos.push({ id, content, status, ...(priority ? { priority } : {}) });
|
|
321
|
+
}
|
|
322
|
+
return { todos, dropped };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The sentence the model reads back, which is also what the sidebar's header says.
|
|
326
|
+
*
|
|
327
|
+
* OpenCode's title for this tool is `${n} todos` where n counts what is NOT completed
|
|
328
|
+
* (`tool/todo.ts:37`), and that number is kept - but alone it lies at the end of a task: "3 todos" after
|
|
329
|
+
* the only three steps are done reads as three things still owed. So the completed count is in the
|
|
330
|
+
* sentence too, and derived HERE rather than in the sidebar, so the tool's own answer and the sidebar's
|
|
331
|
+
* header are computed from the same stored list and cannot disagree.
|
|
332
|
+
*/
|
|
333
|
+
export function todoSummary(todos) {
|
|
334
|
+
const open = todos.filter((todo) => todo.status !== "completed").length;
|
|
335
|
+
if (!todos.length)
|
|
336
|
+
return "0 个待办任务";
|
|
337
|
+
if (!open)
|
|
338
|
+
return `全部完成:${todos.length} 个待办任务`;
|
|
339
|
+
return `${open} 个待办未完成,共 ${todos.length} 个`;
|
|
340
|
+
}
|
|
341
|
+
// ---------------------------------------------------------------------------------------------
|
|
342
|
+
// The `session_*` orchestrator tools: manage sibling conversations in the current workspace.
|
|
343
|
+
//
|
|
344
|
+
// WHY THESE TOOLS EXIST. A primary agent can already delegate a single transient job to a subagent
|
|
345
|
+
// via `task` (a one-shot Pi process), or pipeline 2-8 steps via `workflow`. What was missing was the
|
|
346
|
+
// ability to spin up INDEPENDENT, PERSISTENT sibling conversations in Super Pi — sessions that appear
|
|
347
|
+
// in the workspace sidebar, carry their own full message history, run concurrently in the background,
|
|
348
|
+
// and can be conversed with over multiple turns via `session_dispatch`, monitored via `session_status`,
|
|
349
|
+
// or cancelled via `session_stop`.
|
|
350
|
+
//
|
|
351
|
+
// WHY THEY DIFFER FROM `task`. `task` runs an ephemeral child process: it has no conversation history,
|
|
352
|
+
// cannot be conversed with across turns, does not appear in the sidebar, and dies upon returning its
|
|
353
|
+
// final text. Sibling conversations are first-class Super Pi conversations: they retain their own
|
|
354
|
+
// transcripts, can be opened and viewed by the user in the UI, and can execute complex multi-phase
|
|
355
|
+
// work in parallel with the orchestrator.
|
|
356
|
+
// ---------------------------------------------------------------------------------------------
|
|
357
|
+
/**
|
|
358
|
+
* The orchestrator extension's half of the environment contract.
|
|
359
|
+
* `agents/super-pi-task/core.ts` is the other end; `scripts/task-tool.test.mjs` asserts the two copies agree.
|
|
360
|
+
*/
|
|
361
|
+
export const ORCHESTRATOR_ENDPOINT_ENV = "SUPER_PI_ORCHESTRATOR_ENDPOINT";
|
|
362
|
+
export const ORCHESTRATOR_WORKSPACE_ENV = "SUPER_PI_ORCHESTRATOR_WORKSPACE";
|
|
363
|
+
/** Tool names registered with Pi. */
|
|
364
|
+
export const SESSION_SPAWN_TOOL_NAME = "session_spawn";
|
|
365
|
+
export const SESSION_STATUS_TOOL_NAME = "session_status";
|
|
366
|
+
export const SESSION_DISPATCH_TOOL_NAME = "session_dispatch";
|
|
367
|
+
export const SESSION_STOP_TOOL_NAME = "session_stop";
|
|
368
|
+
export const SESSION_REPORT_TOOL_NAME = "session_report";
|
|
369
|
+
export const SESSION_STOP_SUBTREE_TOOL_NAME = "session_stop_subtree";
|
|
370
|
+
export const SESSION_REMOVE_TOOL_NAME = "session_remove";
|
|
371
|
+
export const SESSION_REMINDER_TOOL_NAME = "session_reminder";
|
|
372
|
+
/** Model-facing description for session_reminder. */
|
|
373
|
+
export const SESSION_REMINDER_DESCRIPTION = `Set a timer that wakes THIS conversation. A timer without a note reports only the elapsed time. It does not introduce a new agenda or tell you how to act.
|
|
374
|
+
|
|
375
|
+
For a periodic project check-in, set delaySeconds and repeat: true once. On each wake-up, decide what to do based on the project’s current state. Cancel the timer when it is no longer needed.
|
|
376
|
+
|
|
377
|
+
Actions:
|
|
378
|
+
- "create" (default): Requires a positive delaySeconds (or seconds). Set repeat: true for recurring wake-ups that only report elapsed time. A one-off reminder can optionally include a short note. Returns reminderId.
|
|
379
|
+
- "cancel": Cancel future wake-ups. Requires reminderId.
|
|
380
|
+
- "list": List this conversation’s active timers.
|
|
381
|
+
|
|
382
|
+
Use scheduled_task for work that should run in a separate conversation.`;
|
|
383
|
+
/** Model-facing description for session_spawn. */
|
|
384
|
+
export const SESSION_SPAWN_DESCRIPTION = `Create a child conversation in the current workspace and immediately dispatch its initial task. You can specify a primary agent as the child's role.
|
|
385
|
+
|
|
386
|
+
DIFFERENCE FROM THE 'task' TOOL:
|
|
387
|
+
- The 'task' tool delegates to a transient, one-shot subagent process (scout, critic, patcher) that runs once, returns its final text, and terminates. It has no conversation history and does not appear in the workspace sidebar.
|
|
388
|
+
- 'session_spawn' creates a real, persistent child CONVERSATION in Super Pi. It appears in the sidebar, retains multi-turn message history, can receive follow-up messages via session_dispatch, can be inspected via session_status, and can be stopped via session_stop. The user can also switch to it in the Web UI.
|
|
389
|
+
|
|
390
|
+
WHEN TO USE THIS:
|
|
391
|
+
- Long-running, multi-phase tracks of work that require ongoing context, multiple turns of dialogue, or independent user visibility.
|
|
392
|
+
- Multi-phase or complex work where the user needs each step to be visible and available for inspection or intervention: create a child session with session_spawn.
|
|
393
|
+
- Parallel work streams (e.g., Track A: backend refactor, Track B: frontend component update) where both need full conversational capabilities.
|
|
394
|
+
- When the user asks you to act as an orchestrator/manager who delegates to multiple sessions.
|
|
395
|
+
|
|
396
|
+
WHEN NOT TO USE THIS:
|
|
397
|
+
- For one-off, focused delegation with a single answer: use 'task' (with scout/critic/patcher). It is faster, cheaper, and returns directly to your transcript.
|
|
398
|
+
- For running shell commands or build watchers: use 'run_async'.
|
|
399
|
+
- For a single one-off delegation with a single answer: use 'task'.
|
|
400
|
+
|
|
401
|
+
Usage notes:
|
|
402
|
+
1. Spawning is ASYNCHRONOUS by default: it creates the conversation, enqueues the initial task, and returns the new conversationId immediately. The sibling session runs in the background.
|
|
403
|
+
2. The initial task should provide clear context and goals since the new session starts with a fresh conversation history.
|
|
404
|
+
3. Use session_status with the returned conversationId to check progress, or session_dispatch to send further messages.
|
|
405
|
+
4. The new session reports completion to its DIRECT parent automatically, and that parent is always the calling session. 'parentConversationId' may only repeat the calling session's own id - the server refuses (403) any other session as the parent and creates nothing.
|
|
406
|
+
5. The new session always belongs to the calling session's workspace. Pass 'cwd' as a workspace-relative subdirectory (for example, 'packages/a') when it should work below the workspace root; absolute paths and traversal are rejected.
|
|
407
|
+
6. Optionally pass 'model' to choose which model the NEW session runs on: {"provider":"...","modelId":"..."} - the same "provider/modelId" pair the model picker shows, and BOTH halves are required. Leave 'model' out and the new session starts on the workspace default model.
|
|
408
|
+
7. Optionally pass 'watchdogTimeoutSeconds' to declare how long YOU are willing to wait for a report before you want to be reminded: a positive number of seconds. If the new session stays silent that long, you receive a '[Watchdog 提醒]' message naming it. A report from the child (session_report) restarts the clock; the watchdog never stops the child. Leave it out to run without a watchdog.`;
|
|
409
|
+
/** Model-facing description for session_status. */
|
|
410
|
+
export const SESSION_STATUS_DESCRIPTION = `Inspect the progress, run state, and latest activity of sibling conversations created by the orchestrator.
|
|
411
|
+
|
|
412
|
+
WHEN TO USE THIS:
|
|
413
|
+
- To check whether a spawned sibling conversation is still running, has finished (idle), is stopped, or encountered an error.
|
|
414
|
+
- To read the latest assistant progress snippet without bloating your context with the session's entire raw message transcript.
|
|
415
|
+
- To list all sibling conversations under your coordination when conversationId is omitted.
|
|
416
|
+
|
|
417
|
+
Usage notes:
|
|
418
|
+
1. When 'conversationId' is provided: returns a compact summary for that specific session, including its run status ('idle', 'running', 'waiting', 'stopped', 'failed'), messageCount, turnCount, lastAssistantSnippet, lastUserSnippet, activeTool, and error (if any).
|
|
419
|
+
2. When 'conversationId' is omitted: returns a summary list of sibling conversations whose direct parent is 'parentConversationId' (the calling session by default).
|
|
420
|
+
3. By default it never returns full transcripts; concise summaries keep your context window lean. Set 'includeOutput' with a conversationId to read the final output from its result file, capped to the last 64Ki characters with an explicit truncation notice.`;
|
|
421
|
+
/** Model-facing description for session_dispatch. */
|
|
422
|
+
export const SESSION_DISPATCH_DESCRIPTION = `Send a message, follow-up instructions, or steering guidance to an existing sibling conversation.
|
|
423
|
+
|
|
424
|
+
WHEN TO USE THIS:
|
|
425
|
+
- To follow up with a sibling session after reading its progress with session_status.
|
|
426
|
+
- To give feedback, provide additional requirements, or answer a question from a sibling session.
|
|
427
|
+
- To kick off a new turn on an idle or stopped sibling session.
|
|
428
|
+
|
|
429
|
+
Usage notes:
|
|
430
|
+
1. 'conversationId' is required and must identify an existing sibling conversation.
|
|
431
|
+
2. 'content' is the text instruction sent to that session, just as if typed by a user in that session's chat.
|
|
432
|
+
3. Dispatch is ASYNCHRONOUS by default: it enqueues the message into the session's queue and returns immediately.
|
|
433
|
+
4. If the sibling session is currently busy running a turn, the dispatched message is placed in its waiting queue and processed when the active turn completes.
|
|
434
|
+
5. 'mode' controls delivery when the target session is busy:
|
|
435
|
+
- 'queue' (default): waits until the active turn and earlier queued messages finish (delivered via follow-up queue / subsequent turn; multiple queued messages wait in order).
|
|
436
|
+
- 'steer': delivers at the NEXT turn boundary (after the current tool-call batch completes) ahead of queued follow-up messages. It does NOT kill or abort an in-flight tool call mid-execution. Multiple steered messages arriving before the next boundary may be delivered together at that boundary; when the session is idle, it starts a turn immediately.
|
|
437
|
+
- Invalid 'mode' values are rejected with an error (never silently fall back to 'queue').`;
|
|
438
|
+
/** Model-facing description for session_stop. */
|
|
439
|
+
export const SESSION_STOP_DESCRIPTION = `Stop execution in a sibling conversation.
|
|
440
|
+
|
|
441
|
+
WHEN TO USE THIS:
|
|
442
|
+
- When a sibling session has gone down the wrong path, is stuck in an unwanted loop, or when the overall goal has changed and remaining work should be aborted.
|
|
443
|
+
- To clear pending queued messages before they start running.
|
|
444
|
+
|
|
445
|
+
Usage notes:
|
|
446
|
+
1. 'mode' controls what to stop:
|
|
447
|
+
- 'all' (default): stops the currently running turn and cancels all pending queued messages in the session.
|
|
448
|
+
- 'active': only interrupts the active running turn; leaves any pending queued messages untouched.
|
|
449
|
+
- 'queued': only cancels pending queued messages; lets the currently running turn complete naturally.
|
|
450
|
+
2. Use 'messageId' if you want to cancel or interrupt one specific queued message instead of all queued messages.
|
|
451
|
+
3. Use 'messageIds' (an array of queued message IDs from session_status or session_dispatch) to selectively withdraw only those queued messages while keeping the running turn, other queued messages, and unrelated steered messages intact.`;
|
|
452
|
+
/** Model-facing description for session_report. */
|
|
453
|
+
export const SESSION_REPORT_DESCRIPTION = `Report progress from THIS session to the parent session that spawned it.
|
|
454
|
+
|
|
455
|
+
WHEN TO USE THIS:
|
|
456
|
+
- You are a spawned sibling session, and the parent is waiting to hear from you: a milestone is done, a roadblock appeared, or the task is finished.
|
|
457
|
+
- The parent set a watchdog (session_spawn's 'watchdogTimeoutSeconds'): a report is what restarts that clock, and silence is what triggers the reminder.
|
|
458
|
+
- The task is over and the parent needs the outcome NOW rather than after the automatic end-of-turn result.
|
|
459
|
+
|
|
460
|
+
WHEN NOT TO USE THIS:
|
|
461
|
+
- This session has no parent (the user opened it directly): there is nobody to report to, and the server refuses the call.
|
|
462
|
+
- You want to ASK the parent something or send it new instructions: that is session_dispatch, and only the parent can send it. A report is one-way - the parent receives it as a message.
|
|
463
|
+
|
|
464
|
+
Usage notes:
|
|
465
|
+
1. 'content' is required: it is the text the parent receives. Write it for the parent - what is done, what is left, what you need.
|
|
466
|
+
2. 'status' says what the report MEANS:
|
|
467
|
+
- 'in_progress' (default): an interim update. The task continues, and the parent's watchdog clock restarts.
|
|
468
|
+
- 'completed': the task is finished and this is your final word.
|
|
469
|
+
- 'failed': the task could not be finished, and this says why.
|
|
470
|
+
3. A 'completed' or 'failed' report tells the server the work is over, so the parent is NOT also sent the automatic end-of-turn result. Send it once, at the end, with the final answer in 'content'.
|
|
471
|
+
4. Reporting does NOT end your turn. If the task is not done, keep working afterwards - the parent is waiting on the work, not on the report.
|
|
472
|
+
5. The report reaches your DIRECT parent only. A sibling, a cousin, and the user's own session are all out of reach, and the server refuses those.`;
|
|
473
|
+
/** Model-facing description for session_stop_subtree. */
|
|
474
|
+
export const SESSION_STOP_SUBTREE_DESCRIPTION = `Stop a sibling session AND every session underneath it.
|
|
475
|
+
|
|
476
|
+
WHEN TO USE THIS:
|
|
477
|
+
- The session has children of its own and you are stopping it: those children would otherwise keep running with a dead parent - zombies that burn tokens, keep writing files, and report results nobody is left to read.
|
|
478
|
+
- The whole branch should go: stopping only the top leaves the work underneath it alive.
|
|
479
|
+
- A child went wrong and everything it started has to go down with it.
|
|
480
|
+
|
|
481
|
+
WHEN NOT TO USE THIS:
|
|
482
|
+
- The session has no children: session_stop does the same thing to one session and says less.
|
|
483
|
+
- The session is only misbehaving at the top and its children are doing work you still want: stop it alone with session_stop.
|
|
484
|
+
- You want to cancel one queued message: session_stop's 'messageId'.
|
|
485
|
+
|
|
486
|
+
Usage notes:
|
|
487
|
+
1. 'conversationId' must be your own DIRECT child, exactly as for session_stop. You are not reaching across levels to manage anybody.
|
|
488
|
+
2. Everything under that session goes down with it - children, grandchildren, the whole tree - deepest first, so nothing is left running under a session that is already gone.
|
|
489
|
+
3. The descendants are stopped AS A CONSEQUENCE of stopping the root. They cannot be spared, because a session cannot outlive the one that owns it.
|
|
490
|
+
4. The answer says how many sessions were stopped in total, including the one you named.`;
|
|
491
|
+
/** Model-facing description for session_remove. */
|
|
492
|
+
export const SESSION_REMOVE_DESCRIPTION = `Permanently destroy a direct child session (and any descendant sessions under it) from the current working group.
|
|
493
|
+
|
|
494
|
+
WHEN TO USE THIS:
|
|
495
|
+
- A child session's work is finished and you no longer need its session, transcript, or saved output.
|
|
496
|
+
- A child session is stuck and no longer needed, or was spawned by mistake / as a duplicate.
|
|
497
|
+
|
|
498
|
+
WHEN NOT TO USE THIS:
|
|
499
|
+
- You still plan to send follow-up instructions to it later, or still need its transcript, messages, or saved result file.
|
|
500
|
+
- You want to delete yourself, a top-level user session (top-level projects are archived by the user, not destroyed by agents), or any session that is not your direct child.
|
|
501
|
+
|
|
502
|
+
Usage notes:
|
|
503
|
+
1. Destroying is PERMANENT, NOT archiving: the child session and its entire descendant subtree are permanently deleted from the store along with their messages, tool calls, sub-agent runs, todos, and saved output artifacts.
|
|
504
|
+
2. Once destroyed, the session and its branch disappear from your active child list, session_status queries, and reporting wait state.
|
|
505
|
+
3. If the child session or any of its descendants is still running or has queued work, session_remove stops the subtree first; if stopping any session fails, the destruction is refused.
|
|
506
|
+
4. Only your DIRECT child can be targeted (top-level user sessions and non-direct-child sessions are refused). Deleting a direct child that has subordinates destroys that whole branch together.
|
|
507
|
+
5. Destroying a session that is already gone is idempotent and succeeds without error.`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type TavilyPublicStatus = {
|
|
2
|
+
configured: boolean;
|
|
3
|
+
connected: boolean;
|
|
4
|
+
keyHint?: string;
|
|
5
|
+
usage?: {
|
|
6
|
+
used: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
remaining: number;
|
|
9
|
+
plan?: string;
|
|
10
|
+
};
|
|
11
|
+
error?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Keeps the user's Tavily credential on the Super Pi server and never returns it to the UI or agent. */
|
|
14
|
+
export declare class TavilyService {
|
|
15
|
+
private readonly configPath;
|
|
16
|
+
private apiKey?;
|
|
17
|
+
constructor(configPath: string);
|
|
18
|
+
get configured(): boolean;
|
|
19
|
+
status(): Promise<TavilyPublicStatus>;
|
|
20
|
+
configure(apiKey: string): Promise<TavilyPublicStatus>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
search(query: string, limit?: number, signal?: AbortSignal): Promise<{
|
|
23
|
+
query: string;
|
|
24
|
+
results: Array<{
|
|
25
|
+
title: string;
|
|
26
|
+
url: string;
|
|
27
|
+
snippet: string;
|
|
28
|
+
}>;
|
|
29
|
+
}>;
|
|
30
|
+
private fetchUsage;
|
|
31
|
+
private publicStatus;
|
|
32
|
+
}
|