@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,101 @@
|
|
|
1
|
+
import type { ModelSelection } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* WHEN A SCHEDULED TASK RUNS.
|
|
4
|
+
*
|
|
5
|
+
* FOUR SHAPES, AND NOT A CRON EXPRESSION. A cron string would bring a parser, a timezone story and a
|
|
6
|
+
* daylight-saving story to a panel that runs on the same machine as the server - and the two shapes
|
|
7
|
+
* people actually ask for are "every N minutes" and "every day at HH:MM". The set is closed on purpose:
|
|
8
|
+
* a schedule that cannot be expressed here is not a schedule the panel can edit, and the panel is the
|
|
9
|
+
* only place a user can see what they are agreeing to.
|
|
10
|
+
*
|
|
11
|
+
* - `interval`: every N minutes. The interval is anchored on the last run, not on the wall clock, so a
|
|
12
|
+
* task that takes four minutes to run does not slowly drift later every cycle.
|
|
13
|
+
* - `daily`: every day at a local `HH:MM`.
|
|
14
|
+
* - `weekly`: on the listed weekdays (0 = Sunday) at a local `HH:MM`.
|
|
15
|
+
* - `once`: at one instant. The task is finished after it fires.
|
|
16
|
+
*
|
|
17
|
+
* THE TIME IS LOCAL, not UTC and not a named zone, because the server and the panel are the same
|
|
18
|
+
* machine for every installation that exists. A "09:00" that means something different in the panel
|
|
19
|
+
* than in the scheduler would be the worst possible bug in this feature: it would fire at the wrong
|
|
20
|
+
* hour and look like it had fired at the right one.
|
|
21
|
+
*/
|
|
22
|
+
export type ScheduleSpec = {
|
|
23
|
+
kind: "interval";
|
|
24
|
+
everyMinutes: number;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "daily";
|
|
27
|
+
time: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "weekly";
|
|
30
|
+
weekdays: number[];
|
|
31
|
+
time: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "once";
|
|
34
|
+
at: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* ONE SCHEDULED TASK: a prompt, a model to run it with, and when to run it.
|
|
38
|
+
*
|
|
39
|
+
* `conversationId` is the task's OWN conversation, created lazily on the first run. The task never runs
|
|
40
|
+
* in somebody else's conversation: a scheduled run that landed in the user's working session would
|
|
41
|
+
* interleave with what they were doing, and would change that session's model out from under it.
|
|
42
|
+
*/
|
|
43
|
+
export type ScheduledTask = {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
/** The instruction, sent VERBATIM as the user message of the task's conversation. */
|
|
47
|
+
prompt: string;
|
|
48
|
+
/** The workspace the task belongs to: it decides the working directory and the defaults. */
|
|
49
|
+
workspaceId: string;
|
|
50
|
+
/** The task's own conversation, created on the first run. Absent until then. */
|
|
51
|
+
conversationId?: string;
|
|
52
|
+
/** Overrides the workspace's default agent. */
|
|
53
|
+
agentId?: string;
|
|
54
|
+
/** Overrides the workspace's default model. A `provider`/`modelId` PAIR, never half of one. */
|
|
55
|
+
model?: ModelSelection;
|
|
56
|
+
schedule: ScheduleSpec;
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
/** When the task fires next, in epoch milliseconds. Absent for a finished one-shot task. */
|
|
59
|
+
nextRunAt?: number;
|
|
60
|
+
lastRunAt?: number;
|
|
61
|
+
lastRunStatus?: "completed" | "failed" | "skipped";
|
|
62
|
+
lastRunMessage?: string;
|
|
63
|
+
/** Whether a person or the agent created it. Both are editable by both. */
|
|
64
|
+
createdBy: "user" | "agent";
|
|
65
|
+
createdAt: number;
|
|
66
|
+
updatedAt: number;
|
|
67
|
+
};
|
|
68
|
+
/** The shortest interval a task may ask for. A one-minute floor is what makes a task a task. */
|
|
69
|
+
export declare const MIN_INTERVAL_MINUTES = 1;
|
|
70
|
+
/** The longest interval: a week. Anything longer is a calendar arrangement, not an interval. */
|
|
71
|
+
export declare const MAX_INTERVAL_MINUTES: number;
|
|
72
|
+
/**
|
|
73
|
+
* Reads a schedule out of whatever a caller sent, or explains why it cannot.
|
|
74
|
+
*
|
|
75
|
+
* THE SERVER OWNS THIS, and the extension on the other side of the wire deliberately does NOT have a
|
|
76
|
+
* copy of it. The extension hands over what the model wrote; this function decides what it means. A
|
|
77
|
+
* second implementation on the extension side would be a second opinion about the same wire, and the two
|
|
78
|
+
* would disagree the first time a model wrote a schedule in a shape one of them accepted and the other
|
|
79
|
+
* did not - with the model's mistake showing up as a server error it cannot explain.
|
|
80
|
+
*/
|
|
81
|
+
export declare function normalizeSchedule(raw: unknown): ScheduleSpec;
|
|
82
|
+
/**
|
|
83
|
+
* WHEN THE TASK FIRES NEXT, given a moment to look forward from.
|
|
84
|
+
*
|
|
85
|
+
* `undefined` means "never again": a one-shot task whose moment has passed.
|
|
86
|
+
*
|
|
87
|
+
* The daily and weekly cases walk forward day by day in LOCAL time rather than adding 24 hours, so a
|
|
88
|
+
* schedule at 09:00 stays at 09:00 across a daylight-saving change instead of drifting to 08:00 or
|
|
89
|
+
* 10:00 for half the year.
|
|
90
|
+
*/
|
|
91
|
+
export declare function nextRunAt(spec: ScheduleSpec, from: number): number | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* THE SCHEDULE IN WORDS, for the panel and for the text the agent reads back.
|
|
94
|
+
*
|
|
95
|
+
* One implementation for both readers, because two descriptions of one schedule would eventually say
|
|
96
|
+
* two different things - and the agent's description is what the user is told when the agent says
|
|
97
|
+
* "I set up a daily task". If the two disagreed, the user would find out from the clock.
|
|
98
|
+
*/
|
|
99
|
+
export declare function describeSchedule(spec: ScheduleSpec): string;
|
|
100
|
+
/** A moment as `YYYY-MM-DD HH:MM`, in local time. */
|
|
101
|
+
export declare function formatMoment(ms: number): string;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** The shortest interval a task may ask for. A one-minute floor is what makes a task a task. */
|
|
2
|
+
export const MIN_INTERVAL_MINUTES = 1;
|
|
3
|
+
/** The longest interval: a week. Anything longer is a calendar arrangement, not an interval. */
|
|
4
|
+
export const MAX_INTERVAL_MINUTES = 60 * 24 * 7;
|
|
5
|
+
/**
|
|
6
|
+
* Reads a schedule out of whatever a caller sent, or explains why it cannot.
|
|
7
|
+
*
|
|
8
|
+
* THE SERVER OWNS THIS, and the extension on the other side of the wire deliberately does NOT have a
|
|
9
|
+
* copy of it. The extension hands over what the model wrote; this function decides what it means. A
|
|
10
|
+
* second implementation on the extension side would be a second opinion about the same wire, and the two
|
|
11
|
+
* would disagree the first time a model wrote a schedule in a shape one of them accepted and the other
|
|
12
|
+
* did not - with the model's mistake showing up as a server error it cannot explain.
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeSchedule(raw) {
|
|
15
|
+
if (!raw || typeof raw !== "object")
|
|
16
|
+
throw new Error("周期必须是一个对象:{\"kind\":\"interval\",\"everyMinutes\":30} 这样写。");
|
|
17
|
+
const value = raw;
|
|
18
|
+
const kind = typeof value.kind === "string" ? value.kind.trim() : "";
|
|
19
|
+
if (kind === "interval") {
|
|
20
|
+
const everyMinutes = Number(value.everyMinutes);
|
|
21
|
+
if (!Number.isFinite(everyMinutes) || !Number.isInteger(everyMinutes))
|
|
22
|
+
throw new Error("每隔 N 分钟需要一个整数分钟数。");
|
|
23
|
+
if (everyMinutes < MIN_INTERVAL_MINUTES || everyMinutes > MAX_INTERVAL_MINUTES) {
|
|
24
|
+
throw new Error(`间隔分钟数要在 ${MIN_INTERVAL_MINUTES} 到 ${MAX_INTERVAL_MINUTES} 之间。`);
|
|
25
|
+
}
|
|
26
|
+
return { kind: "interval", everyMinutes };
|
|
27
|
+
}
|
|
28
|
+
if (kind === "daily")
|
|
29
|
+
return { kind: "daily", time: normalizeTime(value.time) };
|
|
30
|
+
if (kind === "weekly") {
|
|
31
|
+
const weekdays = normalizeWeekdays(value.weekdays);
|
|
32
|
+
return { kind: "weekly", weekdays, time: normalizeTime(value.time) };
|
|
33
|
+
}
|
|
34
|
+
if (kind === "once") {
|
|
35
|
+
const at = Number(value.at);
|
|
36
|
+
if (!Number.isFinite(at) || at <= 0)
|
|
37
|
+
throw new Error("一次性任务需要一个触发时刻(毫秒时间戳)。");
|
|
38
|
+
return { kind: "once", at };
|
|
39
|
+
}
|
|
40
|
+
throw new Error("周期只能是 interval(每隔 N 分钟)、daily(每天)、weekly(每周)或 once(仅一次)。");
|
|
41
|
+
}
|
|
42
|
+
/** `HH:MM`, twenty-four hour, leading zero or not. The only time shape this feature accepts. */
|
|
43
|
+
function normalizeTime(raw) {
|
|
44
|
+
if (typeof raw !== "string")
|
|
45
|
+
throw new Error("触发时刻要写成 \"HH:MM\",比如 \"09:00\"。");
|
|
46
|
+
const match = /^(\d{1,2}):(\d{2})$/.exec(raw.trim());
|
|
47
|
+
if (!match)
|
|
48
|
+
throw new Error("触发时刻要写成 \"HH:MM\",比如 \"09:00\"。");
|
|
49
|
+
const hours = Number(match[1]);
|
|
50
|
+
const minutes = Number(match[2]);
|
|
51
|
+
if (hours > 23 || minutes > 59)
|
|
52
|
+
throw new Error("触发时刻不是一个真实的时间。");
|
|
53
|
+
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
|
|
54
|
+
}
|
|
55
|
+
/** The weekdays of a weekly schedule, sorted and deduplicated. An empty list means every day. */
|
|
56
|
+
function normalizeWeekdays(raw) {
|
|
57
|
+
if (!Array.isArray(raw))
|
|
58
|
+
throw new Error("每周任务需要给出星期几,比如 [1,3] 表示周一和周三。");
|
|
59
|
+
const days = Array.from(new Set(raw.map((item) => Number(item)).filter((item) => Number.isInteger(item) && item >= 0 && item <= 6)));
|
|
60
|
+
if (!days.length)
|
|
61
|
+
throw new Error("每周任务至少要有一天。");
|
|
62
|
+
return days.sort((a, b) => a - b);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* WHEN THE TASK FIRES NEXT, given a moment to look forward from.
|
|
66
|
+
*
|
|
67
|
+
* `undefined` means "never again": a one-shot task whose moment has passed.
|
|
68
|
+
*
|
|
69
|
+
* The daily and weekly cases walk forward day by day in LOCAL time rather than adding 24 hours, so a
|
|
70
|
+
* schedule at 09:00 stays at 09:00 across a daylight-saving change instead of drifting to 08:00 or
|
|
71
|
+
* 10:00 for half the year.
|
|
72
|
+
*/
|
|
73
|
+
export function nextRunAt(spec, from) {
|
|
74
|
+
if (spec.kind === "interval")
|
|
75
|
+
return from + spec.everyMinutes * 60_000;
|
|
76
|
+
if (spec.kind === "once")
|
|
77
|
+
return spec.at > from ? spec.at : undefined;
|
|
78
|
+
if (spec.kind === "daily")
|
|
79
|
+
return nextDailyAt(spec.time, from);
|
|
80
|
+
return nextWeeklyAt(spec.weekdays, spec.time, from);
|
|
81
|
+
}
|
|
82
|
+
/** The next moment at `HH:MM` strictly after `from`, in local time. */
|
|
83
|
+
function nextDailyAt(time, from) {
|
|
84
|
+
const [hours, minutes] = time.split(":").map(Number);
|
|
85
|
+
const candidate = new Date(from);
|
|
86
|
+
candidate.setHours(hours, minutes, 0, 0);
|
|
87
|
+
if (candidate.getTime() <= from)
|
|
88
|
+
candidate.setDate(candidate.getDate() + 1);
|
|
89
|
+
return candidate.getTime();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The next moment at `HH:MM` on one of `weekdays`, strictly after `from`, in local time.
|
|
93
|
+
*
|
|
94
|
+
* At most eight days are examined, which covers every weekday list including an empty one: an empty
|
|
95
|
+
* list means "every day", and the daily case is a special case of it.
|
|
96
|
+
*/
|
|
97
|
+
function nextWeeklyAt(weekdays, time, from) {
|
|
98
|
+
const days = weekdays.length ? weekdays : [0, 1, 2, 3, 4, 5, 6];
|
|
99
|
+
const [hours, minutes] = time.split(":").map(Number);
|
|
100
|
+
for (let offset = 0; offset <= 7; offset += 1) {
|
|
101
|
+
const candidate = new Date(from);
|
|
102
|
+
candidate.setDate(candidate.getDate() + offset);
|
|
103
|
+
candidate.setHours(hours, minutes, 0, 0);
|
|
104
|
+
if (candidate.getTime() <= from)
|
|
105
|
+
continue;
|
|
106
|
+
if (days.includes(candidate.getDay()))
|
|
107
|
+
return candidate.getTime();
|
|
108
|
+
}
|
|
109
|
+
// Unreachable: within eight days every weekday in a full week comes round. The fallback keeps the
|
|
110
|
+
// function total rather than returning `undefined` for a shape that cannot happen.
|
|
111
|
+
return nextDailyAt(time, from);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* THE SCHEDULE IN WORDS, for the panel and for the text the agent reads back.
|
|
115
|
+
*
|
|
116
|
+
* One implementation for both readers, because two descriptions of one schedule would eventually say
|
|
117
|
+
* two different things - and the agent's description is what the user is told when the agent says
|
|
118
|
+
* "I set up a daily task". If the two disagreed, the user would find out from the clock.
|
|
119
|
+
*/
|
|
120
|
+
export function describeSchedule(spec) {
|
|
121
|
+
if (spec.kind === "interval")
|
|
122
|
+
return `每隔 ${spec.everyMinutes} 分钟`;
|
|
123
|
+
if (spec.kind === "daily")
|
|
124
|
+
return `每天 ${spec.time}`;
|
|
125
|
+
if (spec.kind === "weekly")
|
|
126
|
+
return `每周${spec.weekdays.map(weekdayName).join("、")} ${spec.time}`;
|
|
127
|
+
return `仅一次:${formatMoment(spec.at)}`;
|
|
128
|
+
}
|
|
129
|
+
/** 0 = Sunday, which is what `Date.getDay()` says. */
|
|
130
|
+
function weekdayName(day) {
|
|
131
|
+
return ["日", "一", "二", "三", "四", "五", "六"][day] ?? "?";
|
|
132
|
+
}
|
|
133
|
+
/** A moment as `YYYY-MM-DD HH:MM`, in local time. */
|
|
134
|
+
export function formatMoment(ms) {
|
|
135
|
+
const date = new Date(ms);
|
|
136
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
137
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
138
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { Store } from "./store.js";
|
|
2
|
+
import type { AgentRuntime } from "./runtime.js";
|
|
3
|
+
import type { SubagentRunRecorder } from "./subagent-runs.js";
|
|
4
|
+
import type { ServerEvent } from "./types.js";
|
|
5
|
+
import type { WorkspaceService } from "./application/workspace-service.js";
|
|
6
|
+
import type { ConversationService } from "./application/conversation-service.js";
|
|
7
|
+
import type { RunService } from "./application/run-service.js";
|
|
8
|
+
import type { ExtensionUiService } from "./application/extension-ui-service.js";
|
|
9
|
+
import type { CatalogService } from "./application/catalog-service.js";
|
|
10
|
+
import type { ProviderService } from "./application/provider-service.js";
|
|
11
|
+
import type { ExecService } from "./exec-service.js";
|
|
12
|
+
import type { ToolRegistry } from "./tool-registry.js";
|
|
13
|
+
import type { ToolRunner } from "./tool-runner.js";
|
|
14
|
+
/**
|
|
15
|
+
* Common filesystem paths used across the server.
|
|
16
|
+
*/
|
|
17
|
+
export interface ServerPaths {
|
|
18
|
+
dataDir: string;
|
|
19
|
+
rootDir: string;
|
|
20
|
+
agentsDir: string;
|
|
21
|
+
agentDirs?: string[];
|
|
22
|
+
agentPromptDir?: string;
|
|
23
|
+
uploadsDir: string;
|
|
24
|
+
clientDir: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* EventBroadcaster abstracts the WebSocket transport's broadcast mechanism
|
|
28
|
+
* so application services do not directly couple to WebSocket connections.
|
|
29
|
+
*/
|
|
30
|
+
export interface EventBroadcaster {
|
|
31
|
+
/** Broadcast a server event to all connected clients. */
|
|
32
|
+
broadcast(event: ServerEvent): void;
|
|
33
|
+
/** Broadcast the current state snapshot to all connected clients. */
|
|
34
|
+
broadcastState(): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Central server context containing infrastructure dependencies and application services.
|
|
38
|
+
*/
|
|
39
|
+
export interface ServerContext {
|
|
40
|
+
managedServers?: import("./managed-servers.js").ManagedServers;
|
|
41
|
+
browserAccess?: import("./browser-access.js").BrowserAccess;
|
|
42
|
+
memory?: import("./active-memory.js").ActiveMemory;
|
|
43
|
+
knowledge?: import("./knowledge.js").KnowledgeBase;
|
|
44
|
+
web?: import("./web.js").WebService;
|
|
45
|
+
tavily?: import("./tavily.js").TavilyService;
|
|
46
|
+
/** The agent-facing document tools. Optional so the server can start without them. */
|
|
47
|
+
documentService?: import("./application/document-service.js").DocumentService;
|
|
48
|
+
/**
|
|
49
|
+
* THE FEISHU TOOLS.
|
|
50
|
+
*
|
|
51
|
+
* Optional because the credential may be missing, not because the feature may be missing: the
|
|
52
|
+
* service is always constructed, and a call made before the credential is configured is refused
|
|
53
|
+
* with the message that says what to do - which a missing service could not say.
|
|
54
|
+
*/
|
|
55
|
+
feishu?: import("./application/feishu-service.js").FeishuService;
|
|
56
|
+
paths: ServerPaths;
|
|
57
|
+
store: Store;
|
|
58
|
+
runtime: AgentRuntime;
|
|
59
|
+
subagents: SubagentRunRecorder;
|
|
60
|
+
broadcaster: EventBroadcaster;
|
|
61
|
+
accessToken?: string;
|
|
62
|
+
workspaceService: WorkspaceService;
|
|
63
|
+
conversationService: ConversationService;
|
|
64
|
+
runService: RunService;
|
|
65
|
+
extensionUiService: ExtensionUiService;
|
|
66
|
+
catalogService: CatalogService;
|
|
67
|
+
/** The providers a person added through the settings window. */
|
|
68
|
+
providerService: ProviderService;
|
|
69
|
+
/**
|
|
70
|
+
* The scheduled tasks and the clock behind them.
|
|
71
|
+
*
|
|
72
|
+
* In the context because TWO layers need it: the command handler routes the panel's five commands
|
|
73
|
+
* into it, and the HTTP layer exposes the agent-facing endpoint that lets a running turn create a
|
|
74
|
+
* task of its own.
|
|
75
|
+
*/
|
|
76
|
+
scheduledTaskService?: import("./application/scheduled-task-service.js").ScheduledTaskService;
|
|
77
|
+
sessionLedger?: import("./session-ledger.js").SessionLedger;
|
|
78
|
+
sessionOrchestratorService?: import("./application/session-orchestrator-service.js").SessionOrchestratorService;
|
|
79
|
+
sessionReminderService?: import("./application/session-reminder-service.js").SessionReminderService;
|
|
80
|
+
projectService?: import("./application/project-service.js").ProjectService;
|
|
81
|
+
groupChatService?: import("./application/group-chat-service.js").GroupChatService;
|
|
82
|
+
execService: ExecService;
|
|
83
|
+
toolRegistry: ToolRegistry;
|
|
84
|
+
toolRunner: ToolRunner;
|
|
85
|
+
/**
|
|
86
|
+
* WHAT THE AGENT CHANGED, and what each file looked like before.
|
|
87
|
+
*
|
|
88
|
+
* The tracker is here because TWO layers need it: the run service writes to it (a write tool is
|
|
89
|
+
* announced, so the "before" is captured) and the HTTP layer reads from it (a diff request asks for
|
|
90
|
+
* the "before" of one file). Putting it in the context rather than inside either service is what
|
|
91
|
+
* keeps it ONE tracker - two trackers would be two answers to "what did the agent change", and only
|
|
92
|
+
* one of them would have the baselines.
|
|
93
|
+
*/
|
|
94
|
+
fileChanges?: import("./file-changes.js").FileChangeTracker;
|
|
95
|
+
/** Shared file indexes: the HTTP layer starts them lazily and write paths refresh known entries. */
|
|
96
|
+
fileIndexes?: Map<string, import("./file-index.js").FileIndex>;
|
|
97
|
+
/**
|
|
98
|
+
* THE NAME INDEXES, and why they are a SECOND map rather than a mode of `fileIndexes`.
|
|
99
|
+
*
|
|
100
|
+
* `FileIndex` skips dependency directories because content search and quick-open want the project's
|
|
101
|
+
* own files. A filename search wants the opposite: a person typing `config` must be able to find
|
|
102
|
+
* `node_modules/some-pkg/config.js`, and the old behaviour made it unfindable while announcing the
|
|
103
|
+
* omission in the UI. Two indexes, two scopes, one question each - see `file-name-index.ts`.
|
|
104
|
+
*/
|
|
105
|
+
nameIndexes?: Map<string, import("./file-name-index.js").FileNameIndex>;
|
|
106
|
+
/** Absent only if construction failed; a runtime with no Pi reports itself through `available`. */
|
|
107
|
+
toolLlm?: import("./tool-llm.js").ToolLlmService;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the right rail's terminal tab should exist, and why not when it should not.
|
|
110
|
+
*
|
|
111
|
+
* TWO PREDICATES AND NOT A `TerminalService` HANDLE, and that is the load-bearing part. `/api/terminal`
|
|
112
|
+
* only ever needs to answer "is it on"; handing the HTTP layer the service itself would put a
|
|
113
|
+
* `spawn` within reach of a GET request, and the terminal is the one part of this server that is not
|
|
114
|
+
* confined to a workspace. Keeping the handle on `CommandHandler` alone means the only route to a
|
|
115
|
+
* shell is a WebSocket message that `TerminalService.assertUsable` has already vetted.
|
|
116
|
+
*/
|
|
117
|
+
terminalEnabled?: () => boolean;
|
|
118
|
+
terminalDisabledReason?: () => string;
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Explicit file scopes must still name an existing directory. */
|
|
2
|
+
export declare function resolveFileCwd(workspaceRoot: string, cwd?: string | null): Promise<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a conversation's optional relative cwd without ever letting it leave the workspace.
|
|
5
|
+
* An absent value preserves the workspace root; an invalid or escaping value is rejected back to
|
|
6
|
+
* that same root rather than thrown or allowed to select another directory.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveSessionCwd(workspaceRoot: string, cwd?: string | null): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Validates an explicitly requested session cwd at creation time. Unlike the request-time fallback
|
|
11
|
+
* above, an invalid value is an error: the caller must not receive a session rooted somewhere else.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertSessionCwdInsideWorkspace(workspaceRoot: string, cwd?: string | null): Promise<void>;
|
|
14
|
+
/** The canonical, workspace-relative spelling persisted on a conversation. */
|
|
15
|
+
export declare function normalizeSessionCwd(workspaceRoot: string, cwd?: string | null): Promise<string | undefined>;
|
|
16
|
+
/** Converts a path relative to the effective session root into a workspace-relative Git path. */
|
|
17
|
+
export declare function workspacePathFromSession(workspaceRoot: string, sessionRoot: string, path: string): Promise<string>;
|
|
18
|
+
/** One map identity per workspace/cwd pair. The root-session key remains the bare workspace id. */
|
|
19
|
+
export declare function sessionScopeKey(workspaceId: string, cwd?: string): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { relative, resolve, sep } from "node:path";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import { FilesError, resolveInsideRoot } from "./files.js";
|
|
4
|
+
/** Explicit file scopes must still name an existing directory. */
|
|
5
|
+
export async function resolveFileCwd(workspaceRoot, cwd) {
|
|
6
|
+
const target = await resolveInsideRoot(workspaceRoot, cwd);
|
|
7
|
+
if (!cwd?.trim())
|
|
8
|
+
return target;
|
|
9
|
+
const info = await stat(target).catch((error) => {
|
|
10
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR")
|
|
11
|
+
throw new FilesError(404, "会话目录已不存在。", "cwd_missing");
|
|
12
|
+
throw error;
|
|
13
|
+
});
|
|
14
|
+
if (!info.isDirectory())
|
|
15
|
+
throw new FilesError(400, "会话路径必须是目录。", "cwd_not_directory");
|
|
16
|
+
return target;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a conversation's optional relative cwd without ever letting it leave the workspace.
|
|
20
|
+
* An absent value preserves the workspace root; an invalid or escaping value is rejected back to
|
|
21
|
+
* that same root rather than thrown or allowed to select another directory.
|
|
22
|
+
*/
|
|
23
|
+
export async function resolveSessionCwd(workspaceRoot, cwd) {
|
|
24
|
+
if (!cwd?.trim())
|
|
25
|
+
return resolveInsideRoot(workspaceRoot, "");
|
|
26
|
+
try {
|
|
27
|
+
return await resolveInsideRoot(workspaceRoot, cwd);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return resolveInsideRoot(workspaceRoot, "");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validates an explicitly requested session cwd at creation time. Unlike the request-time fallback
|
|
35
|
+
* above, an invalid value is an error: the caller must not receive a session rooted somewhere else.
|
|
36
|
+
*/
|
|
37
|
+
export async function assertSessionCwdInsideWorkspace(workspaceRoot, cwd) {
|
|
38
|
+
if (!cwd?.trim())
|
|
39
|
+
return;
|
|
40
|
+
await resolveInsideRoot(workspaceRoot, cwd);
|
|
41
|
+
}
|
|
42
|
+
/** The canonical, workspace-relative spelling persisted on a conversation. */
|
|
43
|
+
export async function normalizeSessionCwd(workspaceRoot, cwd) {
|
|
44
|
+
if (!cwd?.trim())
|
|
45
|
+
return undefined;
|
|
46
|
+
const effective = await resolveSessionCwd(workspaceRoot, cwd);
|
|
47
|
+
const normalized = relative(resolve(workspaceRoot), effective).split(sep).join("/");
|
|
48
|
+
return normalized ? normalized : undefined;
|
|
49
|
+
}
|
|
50
|
+
/** Converts a path relative to the effective session root into a workspace-relative Git path. */
|
|
51
|
+
export async function workspacePathFromSession(workspaceRoot, sessionRoot, path) {
|
|
52
|
+
const absolute = await resolveInsideRoot(sessionRoot, path);
|
|
53
|
+
return relative(resolve(workspaceRoot), absolute).split(sep).join("/");
|
|
54
|
+
}
|
|
55
|
+
/** One map identity per workspace/cwd pair. The root-session key remains the bare workspace id. */
|
|
56
|
+
export function sessionScopeKey(workspaceId, cwd) {
|
|
57
|
+
return cwd ? `${workspaceId}\0${cwd}` : workspaceId;
|
|
58
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type SessionOrigin = "user" | "orchestrator";
|
|
2
|
+
export type SessionLedgerStatus = "idle" | "running" | "waiting" | "stopped" | "failed" | "completed";
|
|
3
|
+
/**
|
|
4
|
+
* Metadata entry for a conversation managed or observed by the orchestrator.
|
|
5
|
+
* Crucially, NO transcript or message history is retained here to keep memory footprint bounded.
|
|
6
|
+
*/
|
|
7
|
+
export interface SessionLedgerEntry {
|
|
8
|
+
conversationId: string;
|
|
9
|
+
workspaceId: string;
|
|
10
|
+
/** Whether created manually by user or by orchestrator agent */
|
|
11
|
+
origin: SessionOrigin;
|
|
12
|
+
/** If created by orchestrator: the parent conversation that dispatched it */
|
|
13
|
+
parentConversationId?: string;
|
|
14
|
+
/** One-line task description assigned to this session */
|
|
15
|
+
task?: string;
|
|
16
|
+
/** Current status */
|
|
17
|
+
status: SessionLedgerStatus;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
updatedAt: number;
|
|
20
|
+
/** High-level progress snippet or latest outcome */
|
|
21
|
+
lastProgress?: string;
|
|
22
|
+
/** Currently executing tool, if any */
|
|
23
|
+
activeTool?: {
|
|
24
|
+
label: string;
|
|
25
|
+
detail?: string;
|
|
26
|
+
};
|
|
27
|
+
/** Error message if execution failed */
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* In-memory relationship ledger for sibling and child sessions.
|
|
32
|
+
* Holds only metadata (parent-child relationships, tasks, statuses) - never transcripts.
|
|
33
|
+
*/
|
|
34
|
+
export declare class SessionLedger {
|
|
35
|
+
private readonly entries;
|
|
36
|
+
/**
|
|
37
|
+
* Registers a session into the ledger.
|
|
38
|
+
*/
|
|
39
|
+
register(entry: Omit<SessionLedgerEntry, "createdAt" | "updatedAt"> & {
|
|
40
|
+
createdAt?: number;
|
|
41
|
+
updatedAt?: number;
|
|
42
|
+
}): SessionLedgerEntry;
|
|
43
|
+
/**
|
|
44
|
+
* Updates metadata for an existing session in the ledger.
|
|
45
|
+
*/
|
|
46
|
+
update(conversationId: string, patch: Partial<Omit<SessionLedgerEntry, "conversationId" | "createdAt">>): SessionLedgerEntry | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves metadata for one session.
|
|
49
|
+
*/
|
|
50
|
+
get(conversationId: string): SessionLedgerEntry | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Lists all sessions dispatched by a given parent conversation, sorted newest first.
|
|
53
|
+
*/
|
|
54
|
+
listByParent(parentConversationId: string): SessionLedgerEntry[];
|
|
55
|
+
/**
|
|
56
|
+
* Lists all recorded sessions in the ledger, sorted newest first.
|
|
57
|
+
*/
|
|
58
|
+
listAll(): SessionLedgerEntry[];
|
|
59
|
+
/**
|
|
60
|
+
* Removes a session from the ledger.
|
|
61
|
+
*/
|
|
62
|
+
delete(conversationId: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Clears all ledger entries (primarily for test cleanup).
|
|
65
|
+
*/
|
|
66
|
+
clear(): void;
|
|
67
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory relationship ledger for sibling and child sessions.
|
|
3
|
+
* Holds only metadata (parent-child relationships, tasks, statuses) - never transcripts.
|
|
4
|
+
*/
|
|
5
|
+
export class SessionLedger {
|
|
6
|
+
entries = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* Registers a session into the ledger.
|
|
9
|
+
*/
|
|
10
|
+
register(entry) {
|
|
11
|
+
const now = Date.now();
|
|
12
|
+
const fullEntry = {
|
|
13
|
+
...entry,
|
|
14
|
+
createdAt: entry.createdAt ?? now,
|
|
15
|
+
updatedAt: entry.updatedAt ?? now,
|
|
16
|
+
};
|
|
17
|
+
this.entries.set(entry.conversationId, fullEntry);
|
|
18
|
+
return { ...fullEntry };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Updates metadata for an existing session in the ledger.
|
|
22
|
+
*/
|
|
23
|
+
update(conversationId, patch) {
|
|
24
|
+
const existing = this.entries.get(conversationId);
|
|
25
|
+
if (!existing)
|
|
26
|
+
return undefined;
|
|
27
|
+
const updated = {
|
|
28
|
+
...existing,
|
|
29
|
+
...patch,
|
|
30
|
+
updatedAt: Date.now(),
|
|
31
|
+
};
|
|
32
|
+
this.entries.set(conversationId, updated);
|
|
33
|
+
return { ...updated };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves metadata for one session.
|
|
37
|
+
*/
|
|
38
|
+
get(conversationId) {
|
|
39
|
+
const entry = this.entries.get(conversationId);
|
|
40
|
+
return entry ? { ...entry } : undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Lists all sessions dispatched by a given parent conversation, sorted newest first.
|
|
44
|
+
*/
|
|
45
|
+
listByParent(parentConversationId) {
|
|
46
|
+
const result = [];
|
|
47
|
+
for (const entry of this.entries.values()) {
|
|
48
|
+
if (entry.parentConversationId === parentConversationId) {
|
|
49
|
+
result.push({ ...entry });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result.sort((a, b) => b.createdAt - a.createdAt);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Lists all recorded sessions in the ledger, sorted newest first.
|
|
56
|
+
*/
|
|
57
|
+
listAll() {
|
|
58
|
+
const result = [];
|
|
59
|
+
for (const entry of this.entries.values()) {
|
|
60
|
+
result.push({ ...entry });
|
|
61
|
+
}
|
|
62
|
+
return result.sort((a, b) => b.createdAt - a.createdAt);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Removes a session from the ledger.
|
|
66
|
+
*/
|
|
67
|
+
delete(conversationId) {
|
|
68
|
+
return this.entries.delete(conversationId);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clears all ledger entries (primarily for test cleanup).
|
|
72
|
+
*/
|
|
73
|
+
clear() {
|
|
74
|
+
this.entries.clear();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Conversation } from "./types.js";
|
|
2
|
+
/** Resolve legacy trees from persisted edges, never from the sidebar's presentation roots. */
|
|
3
|
+
export declare function memoryTreeId(conversation: Conversation, conversations: readonly Conversation[]): string;
|
|
4
|
+
export declare function initializeMemoryTrees(conversations: Conversation[]): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Resolve legacy trees from persisted edges, never from the sidebar's presentation roots. */
|
|
2
|
+
export function memoryTreeId(conversation, conversations) {
|
|
3
|
+
if (conversation.treeId)
|
|
4
|
+
return conversation.treeId;
|
|
5
|
+
const byId = new Map(conversations.map(item => [item.id, item]));
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
let current = conversation;
|
|
8
|
+
while (current.parentConversationId) {
|
|
9
|
+
if (seen.has(current.id) || seen.size >= 64)
|
|
10
|
+
throw new Error("会话树存在循环或层级过深");
|
|
11
|
+
seen.add(current.id);
|
|
12
|
+
const parent = byId.get(current.parentConversationId);
|
|
13
|
+
if (!parent || parent.workspaceId !== conversation.workspaceId)
|
|
14
|
+
throw new Error("会话树父节点不存在或跨工作区");
|
|
15
|
+
if (parent.treeId)
|
|
16
|
+
return parent.treeId;
|
|
17
|
+
current = parent;
|
|
18
|
+
}
|
|
19
|
+
return current.id;
|
|
20
|
+
}
|
|
21
|
+
export function initializeMemoryTrees(conversations) {
|
|
22
|
+
for (const conversation of conversations) {
|
|
23
|
+
if (conversation.treeId)
|
|
24
|
+
continue;
|
|
25
|
+
try {
|
|
26
|
+
conversation.treeId = memoryTreeId(conversation, conversations);
|
|
27
|
+
}
|
|
28
|
+
catch { /* Invalid legacy trees stay unscoped; memory access will fail closed. */ }
|
|
29
|
+
}
|
|
30
|
+
}
|