@evandu/super-pi-server 0.0.0-stage → 0.1.260
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 +250 -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 +396 -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 +450 -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,17 @@
|
|
|
1
|
+
import type { Client } from "ssh2";
|
|
2
|
+
export interface RemoteInstallation {
|
|
3
|
+
root: string;
|
|
4
|
+
packageRoot: string;
|
|
5
|
+
node: string;
|
|
6
|
+
piCommand: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function uploadFile(client: Client, local: string, remote: string): Promise<void>;
|
|
9
|
+
export declare function installRemote(options: {
|
|
10
|
+
client: Client;
|
|
11
|
+
id: string;
|
|
12
|
+
archive: string;
|
|
13
|
+
archiveHash: string;
|
|
14
|
+
cacheDir: string;
|
|
15
|
+
progress(step: string, output?: string): void;
|
|
16
|
+
}): Promise<RemoteInstallation>;
|
|
17
|
+
export declare function startRemote(client: Client, installation: RemoteInstallation, port: number): Promise<void>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join, basename, posix } from "node:path";
|
|
4
|
+
import { sh, sshExec, sshSftp, sshWrite } from "./managed-ssh.js";
|
|
5
|
+
export async function uploadFile(client, local, remote) {
|
|
6
|
+
const sftp = await sshSftp(client);
|
|
7
|
+
try {
|
|
8
|
+
await new Promise((resolve, reject) => sftp.fastPut(local, remote, { mode: 0o600 }, error => error ? reject(new Error("上传远端安装文件失败")) : resolve()));
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
sftp.end();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async function nodeArchive(platform, arch, directory) {
|
|
15
|
+
const version = "v22.20.0", filename = `node-${version}-${platform}-${arch}.tar.gz`;
|
|
16
|
+
const path = join(directory, filename);
|
|
17
|
+
await mkdir(directory, { recursive: true });
|
|
18
|
+
const sums = await fetch(`https://nodejs.org/dist/${version}/SHASUMS256.txt`, { signal: AbortSignal.timeout(30_000) });
|
|
19
|
+
if (!sums.ok)
|
|
20
|
+
throw new Error("无法下载 Node.js 校验信息,请检查本地网络");
|
|
21
|
+
const expected = (await sums.text()).split("\n").find(line => line.endsWith(` ${filename}`))?.trim().split(/\s+/)[0];
|
|
22
|
+
if (!expected)
|
|
23
|
+
throw new Error("Node.js 官方未提供该平台的安装包");
|
|
24
|
+
try {
|
|
25
|
+
const bytes = await readFile(path);
|
|
26
|
+
if (createHash("sha256").update(bytes).digest("hex") === expected)
|
|
27
|
+
return path;
|
|
28
|
+
}
|
|
29
|
+
catch { }
|
|
30
|
+
const result = await fetch(`https://nodejs.org/dist/${version}/${filename}`, { signal: AbortSignal.timeout(10 * 60_000) });
|
|
31
|
+
if (!result.ok)
|
|
32
|
+
throw new Error("下载 Node.js 失败");
|
|
33
|
+
const data = Buffer.from(await result.arrayBuffer());
|
|
34
|
+
if (data.length > 150 * 1024 * 1024 || createHash("sha256").update(data).digest("hex") !== expected)
|
|
35
|
+
throw new Error("Node.js 安装包校验失败");
|
|
36
|
+
await writeFile(path, data);
|
|
37
|
+
return path;
|
|
38
|
+
}
|
|
39
|
+
export async function installRemote(options) {
|
|
40
|
+
const { client, progress } = options;
|
|
41
|
+
progress("检查远端系统与运行环境");
|
|
42
|
+
const home = (await sshExec(client, "printf '%s' \"$HOME\"")).trim();
|
|
43
|
+
if (!home.startsWith("/") || /[\r\n\0]/.test(home))
|
|
44
|
+
throw new Error("远端没有有效的 POSIX 用户目录;当前支持 Linux 和 macOS 服务端");
|
|
45
|
+
const platformName = (await sshExec(client, "uname -s")).trim();
|
|
46
|
+
const platform = platformName === "Linux" ? "linux" : platformName === "Darwin" ? "darwin" : "";
|
|
47
|
+
const architecture = (await sshExec(client, "uname -m")).trim();
|
|
48
|
+
const arch = ["x86_64", "amd64"].includes(architecture) ? "x64" : ["aarch64", "arm64"].includes(architecture) ? "arm64" : "";
|
|
49
|
+
if (!platform || !arch)
|
|
50
|
+
throw new Error("远端自动安装当前支持 Linux/macOS 的 x64、arm64 平台");
|
|
51
|
+
const root = posix.join(home, ".super-pi", "managed", options.id);
|
|
52
|
+
await sshExec(client, `umask 077; mkdir -p ${sh(root)} ${sh(posix.join(root, "data"))} ${sh(posix.join(root, "agent"))}`);
|
|
53
|
+
let node = "", npm = "";
|
|
54
|
+
try {
|
|
55
|
+
const found = JSON.parse((await sshExec(client, "node -p 'JSON.stringify({version:process.versions.node,path:process.execPath})'")).trim());
|
|
56
|
+
const [major, minor] = String(found.version).split(".").map(Number);
|
|
57
|
+
npm = (await sshExec(client, "command -v npm")).trim();
|
|
58
|
+
if (major > 22 || (major === 22 && minor >= 19))
|
|
59
|
+
node = found.path;
|
|
60
|
+
}
|
|
61
|
+
catch { /* A private Node runtime is installed when the login environment lacks a usable one. */ }
|
|
62
|
+
if (!node || !npm) {
|
|
63
|
+
progress("下载并校验 Node.js(仅首次需要)");
|
|
64
|
+
const local = await nodeArchive(platform, arch, options.cacheDir), remote = posix.join(root, basename(local));
|
|
65
|
+
await uploadFile(client, local, remote);
|
|
66
|
+
const nodeRoot = posix.join(root, "node");
|
|
67
|
+
progress("安装用户目录内的 Node.js,无需管理员权限");
|
|
68
|
+
await sshExec(client, `mkdir -p ${sh(nodeRoot)}; tar -xzf ${sh(remote)} --strip-components=1 -C ${sh(nodeRoot)}`, { timeout: 120_000 });
|
|
69
|
+
node = posix.join(nodeRoot, "bin", "node");
|
|
70
|
+
npm = posix.join(nodeRoot, "bin", "npm");
|
|
71
|
+
await sshExec(client, `${sh(node)} --version`);
|
|
72
|
+
}
|
|
73
|
+
progress("上传纯服务安装包");
|
|
74
|
+
const remoteArchive = posix.join(root, "server.tgz");
|
|
75
|
+
await uploadFile(client, options.archive, remoteArchive);
|
|
76
|
+
const runtime = posix.join(root, `runtime-${options.archiveHash.slice(0, 16)}`);
|
|
77
|
+
const packageRoot = posix.join(runtime, "node_modules", "@evandu", "super-pi-server");
|
|
78
|
+
progress("安装远端服务依赖");
|
|
79
|
+
await sshExec(client, `umask 077; export PATH=${sh(posix.dirname(node))}:"$PATH"; ${sh(npm)} install --prefix ${sh(runtime)} --omit=dev --no-audit --no-fund --fetch-timeout=900000 --fetch-retries=3 ${sh(remoteArchive)}`, { timeout: 20 * 60_000, onOutput: output => progress("安装远端服务依赖", output) });
|
|
80
|
+
const piCommand = posix.join(root, "pi-managed");
|
|
81
|
+
progress("配置远端 Pi 启动器");
|
|
82
|
+
const resolvePi = `import{fileURLToPath}from'node:url';import{dirname,resolve,join}from'node:path';import{readFileSync,accessSync}from'node:fs';const root=resolve(dirname(fileURLToPath(import.meta.resolve('@earendil-works/pi-coding-agent'))),'..');const bin=JSON.parse(readFileSync(join(root,'package.json'),'utf8')).bin.pi;const cli=resolve(root,bin);accessSync(cli);process.stdout.write(cli);`;
|
|
83
|
+
const piCli = (await sshExec(client, `cd ${sh(packageRoot)} && ${sh(node)} --input-type=module -e ${sh(resolvePi)}`, { onOutput: output => progress("配置远端 Pi 启动器", output) })).trim();
|
|
84
|
+
if (!piCli || !piCli.endsWith("/cli.js"))
|
|
85
|
+
throw new Error("远端 Pi 安装不完整,请重试部署");
|
|
86
|
+
const extension = posix.join(packageRoot, "agents", "super-pi-managed-model", "index.ts");
|
|
87
|
+
await sshWrite(client, piCommand, `#!/bin/sh\nexec ${sh(node)} ${sh(piCli)} --extension ${sh(extension)} "$@"\n`, 0o700);
|
|
88
|
+
return { root, packageRoot, node, piCommand };
|
|
89
|
+
}
|
|
90
|
+
export async function startRemote(client, installation, port) {
|
|
91
|
+
const { root, packageRoot, node, piCommand } = installation;
|
|
92
|
+
const pidFile = posix.join(root, "service.pid");
|
|
93
|
+
const entry = posix.join(packageRoot, "dist", "server", "index.js");
|
|
94
|
+
const script = `#!/bin/sh
|
|
95
|
+
set -eu
|
|
96
|
+
umask 077
|
|
97
|
+
if [ -f ${sh(pidFile)} ]; then
|
|
98
|
+
pid=$(cat ${sh(pidFile)})
|
|
99
|
+
case "$pid" in *[!0-9]*|"") ;; *)
|
|
100
|
+
if ps -p "$pid" -o args= 2>/dev/null | grep -F ${sh(`${root}/runtime-`)} >/dev/null; then
|
|
101
|
+
kill "$pid" 2>/dev/null || true
|
|
102
|
+
for n in 1 2 3 4 5; do kill -0 "$pid" 2>/dev/null || break; sleep 1; done
|
|
103
|
+
fi ;;
|
|
104
|
+
esac
|
|
105
|
+
fi
|
|
106
|
+
export SUPER_PI_DATA_DIR=${sh(posix.join(root, "data"))}
|
|
107
|
+
export PI_CODING_AGENT_DIR=${sh(posix.join(root, "agent"))}
|
|
108
|
+
export SUPER_PI_MANAGED_CONFIG=${sh(posix.join(root, "models.json"))}
|
|
109
|
+
export SUPER_PI_PI_COMMAND=${sh(piCommand)}
|
|
110
|
+
export SUPER_PI_HOST=127.0.0.1
|
|
111
|
+
export SUPER_PI_PORT=${port}
|
|
112
|
+
export PATH=${sh(posix.dirname(node))}:"$PATH"
|
|
113
|
+
nohup ${sh(node)} ${sh(entry)} >>${sh(posix.join(root, "service.log"))} 2>&1 </dev/null &
|
|
114
|
+
echo $! >${sh(pidFile)}
|
|
115
|
+
`;
|
|
116
|
+
const launcher = posix.join(root, "start-service.sh");
|
|
117
|
+
await sshWrite(client, launcher, script, 0o700);
|
|
118
|
+
await sshExec(client, `sh ${sh(launcher)}`, { timeout: 30_000 });
|
|
119
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
/** Open-ended Pi RPC record; consumers validate fields before use. */
|
|
3
|
+
export type RpcRecord = {
|
|
4
|
+
type?: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
success?: boolean;
|
|
7
|
+
error?: string;
|
|
8
|
+
/** Every `response` record's payload. Kept opaque: only the catalog reader knows these shapes. */
|
|
9
|
+
data?: unknown;
|
|
10
|
+
/**
|
|
11
|
+
* `tool_execution_end` carries the tool's OUTPUT. Declared so it can be REDUCED by
|
|
12
|
+
* extractToolResultText and then dropped: the raw object must never travel past this record, and that
|
|
13
|
+
* reduction is the whole reason the result is safe to persist. Kept opaque for the same reason `data` is.
|
|
14
|
+
*/
|
|
15
|
+
result?: unknown;
|
|
16
|
+
/** The tool_execution_update record's running output. Reduced by the same function as `result`, never carried raw. */
|
|
17
|
+
partialResult?: unknown;
|
|
18
|
+
/**
|
|
19
|
+
* The inner event of a `message_update`. `message` rides on `done` - the authoritative final
|
|
20
|
+
* assistant message, with its text content, its stop reason and its model (pi-ai AssistantMessageEvent).
|
|
21
|
+
*/
|
|
22
|
+
assistantMessageEvent?: {
|
|
23
|
+
type?: string;
|
|
24
|
+
delta?: string;
|
|
25
|
+
contentIndex?: number;
|
|
26
|
+
partial?: unknown;
|
|
27
|
+
reason?: string;
|
|
28
|
+
message?: {
|
|
29
|
+
role?: string;
|
|
30
|
+
content?: unknown;
|
|
31
|
+
stopReason?: string;
|
|
32
|
+
errorMessage?: string;
|
|
33
|
+
model?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** `agent_end` is Pi's terminal result for one attempt. `willRetry` keeps a transient provider failure from becoming a terminal failure. */
|
|
37
|
+
messages?: Array<{
|
|
38
|
+
role?: string;
|
|
39
|
+
content?: unknown;
|
|
40
|
+
stopReason?: string;
|
|
41
|
+
errorMessage?: string;
|
|
42
|
+
}>;
|
|
43
|
+
willRetry?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Cumulative usage of the CURRENT assistant message, repeated on every one of that message's updates
|
|
46
|
+
* (modes/json-event.ts:56-59). Reading it anywhere but on `done` counts the same tokens per token.
|
|
47
|
+
*/
|
|
48
|
+
usage?: {
|
|
49
|
+
input?: number;
|
|
50
|
+
output?: number;
|
|
51
|
+
cacheRead?: number;
|
|
52
|
+
cacheWrite?: number;
|
|
53
|
+
cost?: {
|
|
54
|
+
total?: number;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
toolCallId?: string;
|
|
58
|
+
toolName?: string;
|
|
59
|
+
args?: unknown;
|
|
60
|
+
/**
|
|
61
|
+
* tool_execution_end payload. `result` is NOT declared: it is deliberately never read, because for a
|
|
62
|
+
* `read` it is the file's contents and this type is the one place a reader would reach for it. The two
|
|
63
|
+
* numbers below are the whole of what a human-readable tool row can honestly report.
|
|
64
|
+
*/
|
|
65
|
+
isError?: boolean;
|
|
66
|
+
durationMs?: number;
|
|
67
|
+
method?: string;
|
|
68
|
+
title?: string;
|
|
69
|
+
options?: unknown;
|
|
70
|
+
message?: string;
|
|
71
|
+
placeholder?: string;
|
|
72
|
+
prefill?: string;
|
|
73
|
+
timeout?: number;
|
|
74
|
+
notifyType?: string;
|
|
75
|
+
statusKey?: string;
|
|
76
|
+
statusText?: string;
|
|
77
|
+
widgetKey?: string;
|
|
78
|
+
widgetLines?: unknown;
|
|
79
|
+
widgetPlacement?: string;
|
|
80
|
+
text?: string;
|
|
81
|
+
extensionPath?: string;
|
|
82
|
+
event?: string;
|
|
83
|
+
steering?: unknown;
|
|
84
|
+
followUp?: unknown;
|
|
85
|
+
};
|
|
86
|
+
/** One Pi child, its stdout reader, and the single writer to its stdin. */
|
|
87
|
+
export declare class RpcChannel {
|
|
88
|
+
private readonly child;
|
|
89
|
+
private readonly records;
|
|
90
|
+
/** See `stash`: a drain loop must not discard another command's response. */
|
|
91
|
+
private readonly stashed;
|
|
92
|
+
private readonly waiters;
|
|
93
|
+
private buffer;
|
|
94
|
+
private exited;
|
|
95
|
+
private exitReason;
|
|
96
|
+
/** stderr is kept only to explain an early exit; a well-behaved Pi writes nothing here. */
|
|
97
|
+
stderr: string;
|
|
98
|
+
constructor(child: ChildProcessWithoutNullStreams);
|
|
99
|
+
get exitCode(): number | null;
|
|
100
|
+
get closed(): boolean;
|
|
101
|
+
private wake;
|
|
102
|
+
/** Waits for stdout or process exit without adding a fixed polling delay to every record. */
|
|
103
|
+
private changed;
|
|
104
|
+
/** Writes one JSONL command. Throws rather than silently dropping: a command Pi never sees is a lie the caller would act on. */
|
|
105
|
+
write(command: object): void;
|
|
106
|
+
/** Returns a response to its waiter after the drain loop encountered it. */
|
|
107
|
+
stash(record: RpcRecord): void;
|
|
108
|
+
/**
|
|
109
|
+
* Removes and returns the next record, or returns `undefined` after `timeoutMs` with nothing to read.
|
|
110
|
+
*
|
|
111
|
+
* THROWS once the child is gone, rather than returning undefined. The old contract was "undefined on
|
|
112
|
+
* EOF" and it had a specific shape of failure it could not see: Pi dying without ever emitting
|
|
113
|
+
* `agent_settled` (a 4xx/5xx from the model provider is the obvious one, an OOM kill another) used
|
|
114
|
+
* to look exactly like "Pi had nothing to say", so the host's drain loop kept polling until the
|
|
115
|
+
* generator returned and the turn was reported as completed - a quota-exhausted turn presented to
|
|
116
|
+
* the reader as 「已完成」 with no error and no message, which is the exact silence this threw exit
|
|
117
|
+
* exists to break. The thrown `Error` carries the exit reason and a `code: "CHANNEL_CLOSED"`
|
|
118
|
+
* property the runtime layer can pattern-match on when it wants to decide between "this turn
|
|
119
|
+
* failed before settling" and any other drain-loop failure; a host that does not match it still
|
|
120
|
+
* sees a real error with a real reason.
|
|
121
|
+
*/
|
|
122
|
+
next(timeoutMs?: number): Promise<RpcRecord | undefined>;
|
|
123
|
+
/** Sends a command and waits for its response. For one command; use write()+waitFor() to overlap several. */
|
|
124
|
+
request(command: {
|
|
125
|
+
id: string;
|
|
126
|
+
type: string;
|
|
127
|
+
} & Record<string, unknown>, timeoutMs: number): Promise<RpcRecord>;
|
|
128
|
+
private take;
|
|
129
|
+
/** Waits for one correlated response while leaving every unrelated record in order. */
|
|
130
|
+
waitFor(id: string, timeoutMs: number, what?: string): Promise<RpcRecord>;
|
|
131
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/** One Pi child, its stdout reader, and the single writer to its stdin. */
|
|
2
|
+
export class RpcChannel {
|
|
3
|
+
child;
|
|
4
|
+
records = [];
|
|
5
|
+
/** See `stash`: a drain loop must not discard another command's response. */
|
|
6
|
+
stashed = new Map();
|
|
7
|
+
waiters = new Set();
|
|
8
|
+
buffer = "";
|
|
9
|
+
exited = false;
|
|
10
|
+
exitReason = "";
|
|
11
|
+
/** stderr is kept only to explain an early exit; a well-behaved Pi writes nothing here. */
|
|
12
|
+
stderr = "";
|
|
13
|
+
constructor(child) {
|
|
14
|
+
this.child = child;
|
|
15
|
+
child.stdout.setEncoding("utf8");
|
|
16
|
+
child.stderr.setEncoding("utf8");
|
|
17
|
+
child.stderr.on("data", (chunk) => { this.stderr += chunk.toString(); });
|
|
18
|
+
child.stdout.on("data", (chunk) => {
|
|
19
|
+
this.buffer += chunk.toString("utf8");
|
|
20
|
+
let changed = false;
|
|
21
|
+
let newline;
|
|
22
|
+
while ((newline = this.buffer.indexOf("\n")) >= 0) {
|
|
23
|
+
const line = this.buffer.slice(0, newline).replace(/\r$/, "");
|
|
24
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
25
|
+
if (!line)
|
|
26
|
+
continue;
|
|
27
|
+
try {
|
|
28
|
+
this.records.push(JSON.parse(line));
|
|
29
|
+
changed = true;
|
|
30
|
+
}
|
|
31
|
+
catch { /* Pi stdout must be JSONL */ }
|
|
32
|
+
}
|
|
33
|
+
if (changed)
|
|
34
|
+
this.wake();
|
|
35
|
+
});
|
|
36
|
+
child.once("exit", (code, signal) => {
|
|
37
|
+
this.exited = true;
|
|
38
|
+
this.exitReason = signal ? `signal ${signal}` : `code ${code}`;
|
|
39
|
+
this.wake();
|
|
40
|
+
});
|
|
41
|
+
child.once("error", (error) => {
|
|
42
|
+
this.exited = true;
|
|
43
|
+
this.exitReason = error.message;
|
|
44
|
+
this.wake();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
get exitCode() { return this.child.exitCode; }
|
|
48
|
+
get closed() { return this.exited || this.child.exitCode !== null; }
|
|
49
|
+
wake() {
|
|
50
|
+
for (const resolve of this.waiters)
|
|
51
|
+
resolve();
|
|
52
|
+
this.waiters.clear();
|
|
53
|
+
}
|
|
54
|
+
/** Waits for stdout or process exit without adding a fixed polling delay to every record. */
|
|
55
|
+
changed(timeoutMs) {
|
|
56
|
+
if (timeoutMs <= 0)
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
const finish = () => { clearTimeout(timer); this.waiters.delete(finish); resolve(); };
|
|
60
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
61
|
+
this.waiters.add(finish);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Writes one JSONL command. Throws rather than silently dropping: a command Pi never sees is a lie the caller would act on. */
|
|
65
|
+
write(command) {
|
|
66
|
+
if (this.child.killed || this.child.stdin.destroyed)
|
|
67
|
+
throw new Error(`Pi RPC stdin is closed, so ${JSON.stringify(command)} was not sent`);
|
|
68
|
+
this.child.stdin.write(`${JSON.stringify(command)}\n`);
|
|
69
|
+
}
|
|
70
|
+
/** Returns a response to its waiter after the drain loop encountered it. */
|
|
71
|
+
stash(record) {
|
|
72
|
+
if (record.type === "response" && typeof record.id === "string") {
|
|
73
|
+
this.stashed.set(record.id, record);
|
|
74
|
+
this.wake();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Removes and returns the next record, or returns `undefined` after `timeoutMs` with nothing to read.
|
|
79
|
+
*
|
|
80
|
+
* THROWS once the child is gone, rather than returning undefined. The old contract was "undefined on
|
|
81
|
+
* EOF" and it had a specific shape of failure it could not see: Pi dying without ever emitting
|
|
82
|
+
* `agent_settled` (a 4xx/5xx from the model provider is the obvious one, an OOM kill another) used
|
|
83
|
+
* to look exactly like "Pi had nothing to say", so the host's drain loop kept polling until the
|
|
84
|
+
* generator returned and the turn was reported as completed - a quota-exhausted turn presented to
|
|
85
|
+
* the reader as 「已完成」 with no error and no message, which is the exact silence this threw exit
|
|
86
|
+
* exists to break. The thrown `Error` carries the exit reason and a `code: "CHANNEL_CLOSED"`
|
|
87
|
+
* property the runtime layer can pattern-match on when it wants to decide between "this turn
|
|
88
|
+
* failed before settling" and any other drain-loop failure; a host that does not match it still
|
|
89
|
+
* sees a real error with a real reason.
|
|
90
|
+
*/
|
|
91
|
+
async next(timeoutMs = 100) {
|
|
92
|
+
const deadline = performance.now() + timeoutMs;
|
|
93
|
+
for (;;) {
|
|
94
|
+
if (this.records.length)
|
|
95
|
+
return this.records.shift();
|
|
96
|
+
if (this.exited || this.child.exitCode !== null) {
|
|
97
|
+
const err = new Error(`Pi RPC channel closed before producing a record (${this.exitReason || "no reason recorded"}). ${this.stderr.trim()}`);
|
|
98
|
+
err.code = "CHANNEL_CLOSED";
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
if (performance.now() >= deadline)
|
|
102
|
+
return undefined;
|
|
103
|
+
await this.changed(deadline - performance.now());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Sends a command and waits for its response. For one command; use write()+waitFor() to overlap several. */
|
|
107
|
+
async request(command, timeoutMs) {
|
|
108
|
+
this.write(command);
|
|
109
|
+
return this.waitFor(command.id, timeoutMs, command.type);
|
|
110
|
+
}
|
|
111
|
+
take(id) {
|
|
112
|
+
const index = this.records.findIndex((record) => record.type === "response" && record.id === id);
|
|
113
|
+
if (index >= 0)
|
|
114
|
+
return this.records.splice(index, 1)[0];
|
|
115
|
+
const stashed = this.stashed.get(id);
|
|
116
|
+
if (!stashed)
|
|
117
|
+
return undefined;
|
|
118
|
+
this.stashed.delete(id);
|
|
119
|
+
return stashed;
|
|
120
|
+
}
|
|
121
|
+
/** Waits for one correlated response while leaving every unrelated record in order. */
|
|
122
|
+
async waitFor(id, timeoutMs, what = id) {
|
|
123
|
+
const deadline = performance.now() + timeoutMs;
|
|
124
|
+
for (;;) {
|
|
125
|
+
const record = this.take(id);
|
|
126
|
+
if (record)
|
|
127
|
+
return record;
|
|
128
|
+
if (this.exited || this.child.exitCode !== null)
|
|
129
|
+
throw new Error(`Pi RPC exited (${this.exitReason || `code ${this.child.exitCode}`}) while waiting for ${what}. ${this.stderr.trim()}`);
|
|
130
|
+
if (performance.now() >= deadline)
|
|
131
|
+
throw new Error(`Pi did not answer ${what} within ${timeoutMs}ms`);
|
|
132
|
+
await this.changed(deadline - performance.now());
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|