pi-web-ui 0.113.1 → 0.114.0
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/CHANGELOG.md +43 -1
- package/README.md +117 -246
- package/README.zh-CN.md +145 -217
- package/README.zh-TW.md +145 -217
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +47 -15
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2289 -1120
- package/dist/server/approval-rules.js +29 -3
- package/dist/server/ask-user-question-tool.js +8 -8
- package/dist/server/atomic-file.js +35 -14
- package/dist/server/attachment-store.js +71 -35
- package/dist/server/attachments.js +18 -8
- package/dist/server/canvas/canvas-agent-tool.js +65 -15
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +516 -199
- package/dist/server/canvas/canvas-scheduler.js +99 -0
- package/dist/server/canvas/canvas-store.js +107 -54
- package/dist/server/canvas/canvas-validation.js +131 -0
- package/dist/server/canvas/canvas-workspace.js +284 -0
- package/dist/server/client-id-utils.js +8 -0
- package/dist/server/client-state.js +104 -22
- package/dist/server/communicate-tool.js +76 -0
- package/dist/server/compact-context-tool.js +2 -3
- package/dist/server/compaction-instructions.js +75 -0
- package/dist/server/compaction-markers.js +7 -2
- package/dist/server/compaction-state.js +84 -0
- package/dist/server/composer-drafts.js +43 -40
- package/dist/server/context-evidence.js +346 -0
- package/dist/server/conversation-communication.js +368 -0
- package/dist/server/conversation-read-tool.js +3 -4
- package/dist/server/conversation-tool-names.js +14 -0
- package/dist/server/conversation-tool.js +57 -0
- package/dist/server/delegate-mode.js +17 -4
- package/dist/server/device-center/bot-catalog.js +88 -0
- package/dist/server/device-center/bot-execution.js +106 -0
- package/dist/server/device-center/bots.js +170 -0
- package/dist/server/device-center/collab-service.js +153 -0
- package/dist/server/device-center/collab-tool.js +184 -0
- package/dist/server/device-center/connector.js +332 -0
- package/dist/server/device-center/desktop-linux.js +372 -0
- package/dist/server/device-center/desktop-native.js +413 -0
- package/dist/server/device-center/desktop-page.js +232 -0
- package/dist/server/device-center/desktop-setup.js +30 -0
- package/dist/server/device-center/desktop.js +387 -0
- package/dist/server/device-center/device-portals.js +241 -0
- package/dist/server/device-center/execution-failure.js +70 -0
- package/dist/server/device-center/executor.js +371 -0
- package/dist/server/device-center/file-sync.js +493 -0
- package/dist/server/device-center/hub-auth.js +69 -0
- package/dist/server/device-center/hub-page.js +68 -0
- package/dist/server/device-center/hub-setup.js +214 -0
- package/dist/server/device-center/hub.js +829 -0
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +476 -0
- package/dist/server/device-center/main.js +118 -0
- package/dist/server/device-center/native-desktop/macos.js +192 -0
- package/dist/server/device-center/native-desktop/windows.js +118 -0
- package/dist/server/device-center/path-portal.js +120 -0
- package/dist/server/device-center/relay.js +959 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +122 -0
- package/dist/server/device-center/task-error.js +14 -0
- package/dist/server/device-center/transfers.js +293 -0
- package/dist/server/device-center/workspaces.js +45 -0
- package/dist/server/dispatch-domain-handlers.js +83 -27
- package/dist/server/dsh/dsh-agent-service.js +277 -158
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/evidence-tool-hooks.js +49 -0
- package/dist/server/file-save.js +95 -0
- package/dist/server/file-transfer-routes.js +97 -47
- package/dist/server/files-service.js +38 -26
- package/dist/server/goal-review-gate.js +16 -6
- package/dist/server/goal-service.js +54 -30
- package/dist/server/http-proxy.js +120 -0
- package/dist/server/index.js +229 -223
- package/dist/server/load-timing.js +31 -0
- package/dist/server/mcp-bridge.js +219 -94
- package/dist/server/mcp-hot-reload.js +31 -5
- package/dist/server/mcp-manager.js +192 -93
- package/dist/server/mcp-oauth-login.js +169 -0
- package/dist/server/mcp-oauth-ui.js +137 -0
- package/dist/server/mcp-oauth.js +395 -0
- package/dist/server/mcp-project-runtime.js +207 -0
- package/dist/server/message-window.js +74 -21
- package/dist/server/net-guard.js +122 -20
- package/dist/server/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- package/dist/server/plan-mode.js +338 -137
- package/dist/server/plugin-assets.js +8 -4
- package/dist/server/plugin-chat-attachments.js +48 -0
- package/dist/server/plugin-facilities.js +67 -220
- package/dist/server/plugin-installer.js +2 -1
- package/dist/server/plugin-removal.js +49 -0
- package/dist/server/plugin-secrets.js +179 -0
- package/dist/server/plugins.js +262 -92
- package/dist/server/preset-fields.js +49 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +112 -72
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +160 -67
- package/dist/server/request-context.js +164 -0
- package/dist/server/sandbox-data.js +655 -0
- package/dist/server/sandbox-engines.js +7 -0
- package/dist/server/sandbox-runtime-gate.js +41 -0
- package/dist/server/sandbox-service.js +139 -698
- package/dist/server/sandbox-tool.js +21 -4
- package/dist/server/scheduler-tasks.js +63 -48
- package/dist/server/serialize.js +48 -19
- package/dist/server/session-branch.js +25 -3
- package/dist/server/session-parser.js +28 -18
- package/dist/server/session-scan.js +130 -0
- package/dist/server/session-search.js +51 -37
- package/dist/server/settings-service.js +267 -111
- package/dist/server/setup-config.js +58 -0
- package/dist/server/skill-maintenance.js +112 -24
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagent-notify.js +4 -1
- package/dist/server/subagent-security-gate.js +52 -11
- package/dist/server/subagent-task.js +27 -0
- package/dist/server/subagents.js +217 -46
- package/dist/server/tabs.js +9 -1
- package/dist/server/terminals.js +467 -363
- package/dist/server/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +47 -20
- package/dist/server/tool-overrides.js +13 -11
- package/dist/server/tool-prompt-overrides.js +32 -2
- package/dist/server/tool-prompts.js +1 -1
- package/dist/server/turn-timing.js +11 -0
- package/dist/server/universal/session-store.js +48 -6
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +334 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/docs/device-center.md +142 -0
- package/docs/device-desktop.md +48 -0
- package/package.json +4 -1
- package/plugin-sdk/index.d.ts +28 -6
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +1 -1
- package/themes/aetheris.css +1 -107
- package/themes/ayu-light.css +5 -29
- package/themes/bases/flow-base.css +0 -6
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +1 -0
- package/themes/bases/zhupi-base.css +1 -0
- package/themes/catppuccin-latte.css +4 -27
- package/themes/catppuccin.css +4 -35
- package/themes/claude-code-dark.css +1 -0
- package/themes/codex.css +4 -28
- package/themes/cyberpunk.css +3 -61
- package/themes/dark-teal.css +0 -1
- package/themes/dazzle.css +3 -73
- package/themes/everforest-light.css +4 -27
- package/themes/geist.css +4 -28
- package/themes/gruvbox-light.css +4 -27
- package/themes/kanagawa-lotus.css +4 -27
- package/themes/md-preview.css +3 -213
- package/themes/mist.css +4 -24
- package/themes/nord.css +4 -35
- package/themes/one-dark.css +4 -37
- package/themes/paper.css +4 -16
- package/themes/rose-pine-dawn.css +4 -28
- package/themes/sakura.css +4 -24
- package/themes/solarized-light.css +4 -27
- package/themes/tokyo-night.css +3 -34
- package/themes/white.css +4 -26
- package/themes/zhujian-dark.css +1 -0
- package/themes/zhupi-dark.css +1 -0
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
- package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
- package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
- package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
- package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
- package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
- package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
- package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
- package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
- package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
- package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
- package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/index-CPgAH5q7.js +83 -0
- package/web/dist/assets/index-Cje8iugL.js +83 -0
- package/web/dist/assets/index-DnKeiDbj.css +1 -0
- package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
- package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
- package/web/dist/assets/math-1uRJCsA9.js +257 -0
- package/web/dist/assets/math-BorAY7qD.css +1 -0
- package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-BqdAjEjF.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +15 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
- package/web/dist/assets/index-ByiO9f-N.js +0 -2008
- package/web/dist/assets/index-ycGLh4a4.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { PendingQuestion } from "./pending-question.js";
|
|
4
|
+
const DEFAULT_LIMITS = {
|
|
5
|
+
maxMessageBytes: 24 * 1024,
|
|
6
|
+
maxQueueCount: 64,
|
|
7
|
+
maxQueueBytes: 256 * 1024,
|
|
8
|
+
maxPendingPerEndpoint: 16,
|
|
9
|
+
maxPendingTotal: 256,
|
|
10
|
+
defaultTimeoutSeconds: 240,
|
|
11
|
+
};
|
|
12
|
+
function checkSignal(signal) {
|
|
13
|
+
if (signal?.aborted)
|
|
14
|
+
throw new Error("Communication aborted");
|
|
15
|
+
}
|
|
16
|
+
function nonempty(value) {
|
|
17
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
18
|
+
}
|
|
19
|
+
function checkOptions(options) {
|
|
20
|
+
if (!Array.isArray(options) || options.length < 2 || options.length > 4)
|
|
21
|
+
throw new Error("Expected 2-4 options");
|
|
22
|
+
for (const option of options) {
|
|
23
|
+
if (!option || !nonempty(option.label))
|
|
24
|
+
throw new Error("Invalid question option");
|
|
25
|
+
for (const key of ["description", "preview"]) {
|
|
26
|
+
if (option[key] !== undefined && typeof option[key] !== "string")
|
|
27
|
+
throw new Error("Invalid option text");
|
|
28
|
+
}
|
|
29
|
+
if (option.recommended !== undefined && typeof option.recommended !== "boolean")
|
|
30
|
+
throw new Error("Invalid recommendation");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function checkQuestions(questions) {
|
|
34
|
+
if (!Array.isArray(questions) || questions.length < 1 || questions.length > 3)
|
|
35
|
+
throw new Error("Expected 1-3 structured questions");
|
|
36
|
+
const seen = new Set();
|
|
37
|
+
for (const q of questions) {
|
|
38
|
+
if (!q || !nonempty(q.id) || !nonempty(q.question) || seen.has(q.id))
|
|
39
|
+
throw new Error("Invalid or duplicate question");
|
|
40
|
+
for (const key of ["detail", "header"]) {
|
|
41
|
+
if (q[key] !== undefined && typeof q[key] !== "string")
|
|
42
|
+
throw new Error("Invalid question text");
|
|
43
|
+
}
|
|
44
|
+
if (q.multiSelect !== undefined && typeof q.multiSelect !== "boolean")
|
|
45
|
+
throw new Error("Invalid multiSelect");
|
|
46
|
+
if (q.options !== undefined)
|
|
47
|
+
checkOptions(q.options);
|
|
48
|
+
if (q.dependsOn !== undefined) {
|
|
49
|
+
const dep = q.dependsOn;
|
|
50
|
+
if (!dep ||
|
|
51
|
+
!seen.has(dep.questionId) ||
|
|
52
|
+
(dep.value !== undefined &&
|
|
53
|
+
typeof dep.value !== "string" &&
|
|
54
|
+
!(Array.isArray(dep.value) && dep.value.every((v) => typeof v === "string"))))
|
|
55
|
+
throw new Error("Invalid question dependency");
|
|
56
|
+
}
|
|
57
|
+
if (q.optionsMap !== undefined) {
|
|
58
|
+
if (!q.dependsOn || !q.optionsMap || typeof q.optionsMap !== "object" || Array.isArray(q.optionsMap))
|
|
59
|
+
throw new Error("Invalid optionsMap");
|
|
60
|
+
for (const options of Object.values(q.optionsMap))
|
|
61
|
+
checkOptions(options);
|
|
62
|
+
}
|
|
63
|
+
seen.add(q.id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function checkAnswers(answers, questions) {
|
|
67
|
+
if (!Array.isArray(answers) || answers.length === 0 || answers.length > questions.length)
|
|
68
|
+
throw new Error("Invalid answers");
|
|
69
|
+
const seen = new Set();
|
|
70
|
+
for (const answer of answers) {
|
|
71
|
+
const q = questions.find((q) => q.id === answer?.id);
|
|
72
|
+
if (!q ||
|
|
73
|
+
seen.has(answer.id) ||
|
|
74
|
+
!Array.isArray(answer.selected) ||
|
|
75
|
+
!answer.selected.every((v) => typeof v === "string") ||
|
|
76
|
+
(answer.custom !== undefined && typeof answer.custom !== "string"))
|
|
77
|
+
throw new Error("Invalid answer");
|
|
78
|
+
if (!q.multiSelect && answer.selected.length > 1)
|
|
79
|
+
throw new Error("Multiple answers are not allowed");
|
|
80
|
+
const options = q.optionsMap ? Object.values(q.optionsMap).flat() : q.options;
|
|
81
|
+
if (options && answer.selected.some((v) => !options.some((o) => o.label === v)))
|
|
82
|
+
throw new Error("Unknown option");
|
|
83
|
+
seen.add(answer.id);
|
|
84
|
+
}
|
|
85
|
+
for (const q of questions) {
|
|
86
|
+
const dep = q.dependsOn;
|
|
87
|
+
const prior = dep && answers.find((a) => a.id === dep.questionId);
|
|
88
|
+
const values = dep?.value === undefined ? undefined : [dep.value].flat();
|
|
89
|
+
const active = !dep || (!!prior && (!values || prior.selected.some((v) => values.includes(v))));
|
|
90
|
+
if (active && !seen.has(q.id))
|
|
91
|
+
throw new Error("Missing answer");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Process-wide coordinator. No agent service, holder, transport or wake policy is retained. */
|
|
95
|
+
export class ConversationCommunication {
|
|
96
|
+
queues = new Map();
|
|
97
|
+
requests = new Map();
|
|
98
|
+
closed = new WeakSet();
|
|
99
|
+
limits;
|
|
100
|
+
constructor(limits = {}) {
|
|
101
|
+
const merged = { ...DEFAULT_LIMITS, ...limits };
|
|
102
|
+
for (const [key, value] of Object.entries(merged)) {
|
|
103
|
+
if (!Number.isSafeInteger(value) || value < (key === "defaultTimeoutSeconds" ? 0 : 1))
|
|
104
|
+
throw new Error("Invalid communication limit");
|
|
105
|
+
}
|
|
106
|
+
if (merged.defaultTimeoutSeconds > 86400)
|
|
107
|
+
throw new Error("Timeout must not exceed one day");
|
|
108
|
+
this.limits = Object.freeze(merged);
|
|
109
|
+
}
|
|
110
|
+
inbox(endpoint) {
|
|
111
|
+
return structuredClone([...(this.queues.get(endpoint)?.values() ?? [])]);
|
|
112
|
+
}
|
|
113
|
+
/** Any incoming or outgoing decision still waiting, including user escalation. */
|
|
114
|
+
pending(endpoint) {
|
|
115
|
+
return [...this.requests.values()].some((r) => r.sender === endpoint || r.target === endpoint);
|
|
116
|
+
}
|
|
117
|
+
incomingRequests(endpoint) {
|
|
118
|
+
return [...this.requests.values()]
|
|
119
|
+
.filter((r) => r.target === endpoint && !r.escalated)
|
|
120
|
+
.map((r) => ({ runId: r.sender.id, requestId: r.question.id, questions: structuredClone(r.question.questions) }));
|
|
121
|
+
}
|
|
122
|
+
requestSource(requestId) {
|
|
123
|
+
return this.requests.get(requestId)?.sender;
|
|
124
|
+
}
|
|
125
|
+
/** Original object for host question registration; do not replace its settlement ownership. */
|
|
126
|
+
pendingQuestion(requestId) {
|
|
127
|
+
return this.requests.get(requestId)?.question;
|
|
128
|
+
}
|
|
129
|
+
acknowledge(endpoint, messageId) {
|
|
130
|
+
const queue = this.queues.get(endpoint);
|
|
131
|
+
const removed = queue?.delete(messageId) ?? false;
|
|
132
|
+
if (queue?.size === 0)
|
|
133
|
+
this.queues.delete(endpoint);
|
|
134
|
+
return removed;
|
|
135
|
+
}
|
|
136
|
+
/** Stop/reset cancels current work while preserving the stable endpoint for later turns. */
|
|
137
|
+
cancel(endpoint) {
|
|
138
|
+
this.queues.delete(endpoint);
|
|
139
|
+
for (const record of this.requests.values()) {
|
|
140
|
+
if (record.sender === endpoint || (record.target === endpoint && !record.escalated))
|
|
141
|
+
record.question.resolve({ cancelled: true, reason: "Communication endpoint closed" });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Final removal only. Holder migration must call neither close nor cancel. */
|
|
145
|
+
close(endpoint) {
|
|
146
|
+
this.cancel(endpoint);
|
|
147
|
+
this.closed.add(endpoint);
|
|
148
|
+
}
|
|
149
|
+
authorize(host, sender, target, action) {
|
|
150
|
+
if (this.closed.has(sender) || this.closed.has(target))
|
|
151
|
+
throw new Error("Communication endpoint closed");
|
|
152
|
+
if (!nonempty(sender.id) || !nonempty(target.id) || !nonempty(sender.cwd) || !nonempty(target.cwd))
|
|
153
|
+
throw new Error("Invalid endpoint identity");
|
|
154
|
+
const senderProject = host.projectKey ? host.projectKey(sender) : resolve(sender.cwd);
|
|
155
|
+
const targetProject = host.projectKey ? host.projectKey(target) : resolve(target.cwd);
|
|
156
|
+
if (!nonempty(senderProject) || !nonempty(targetProject) || senderProject !== targetProject)
|
|
157
|
+
throw new Error("Cross-project communication denied");
|
|
158
|
+
host.authorize(sender, target, action);
|
|
159
|
+
}
|
|
160
|
+
enqueue(target, envelope) {
|
|
161
|
+
const queue = this.queues.get(target) ?? new Map();
|
|
162
|
+
const bytes = Buffer.byteLength(JSON.stringify([...queue.values(), envelope]));
|
|
163
|
+
if (queue.size >= this.limits.maxQueueCount || bytes > this.limits.maxQueueBytes)
|
|
164
|
+
throw new Error("Communication inbox capacity exceeded");
|
|
165
|
+
queue.set(envelope.id, envelope);
|
|
166
|
+
this.queues.set(target, queue);
|
|
167
|
+
}
|
|
168
|
+
hasPath(from, to, visited = new Set()) {
|
|
169
|
+
if (from === to)
|
|
170
|
+
return true;
|
|
171
|
+
if (visited.has(from))
|
|
172
|
+
return false;
|
|
173
|
+
visited.add(from);
|
|
174
|
+
for (const record of this.requests.values()) {
|
|
175
|
+
if (!record.escalated && record.sender === from && this.hasPath(record.target, to, visited))
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
async communicate(host, sender, action, args, signal) {
|
|
181
|
+
checkSignal(signal);
|
|
182
|
+
if (!args || Buffer.byteLength(JSON.stringify(args)) > this.limits.maxMessageBytes)
|
|
183
|
+
throw new Error("Communication payload exceeds byte limit");
|
|
184
|
+
// Copy caller-owned data before callbacks or awaits can mutate it.
|
|
185
|
+
args = structuredClone(args);
|
|
186
|
+
if (action === "read") {
|
|
187
|
+
this.authorize(host, sender, sender, action);
|
|
188
|
+
const queue = this.queues.get(sender);
|
|
189
|
+
const messages = [];
|
|
190
|
+
for (const envelope of queue?.values() ?? []) {
|
|
191
|
+
const candidate = { messages: [...messages, envelope], remaining: (queue?.size ?? 0) - messages.length - 1 };
|
|
192
|
+
if (Buffer.byteLength(JSON.stringify(candidate)) > 48 * 1024)
|
|
193
|
+
break;
|
|
194
|
+
messages.push(envelope);
|
|
195
|
+
}
|
|
196
|
+
const result = structuredClone({ messages, remaining: (queue?.size ?? 0) - messages.length });
|
|
197
|
+
if (host.listRecipients) {
|
|
198
|
+
result.conversations = [];
|
|
199
|
+
// Reserve the optional field before fitting directory entries; messages take priority.
|
|
200
|
+
if (Buffer.byteLength(JSON.stringify(result)) > 48 * 1024)
|
|
201
|
+
delete result.conversations;
|
|
202
|
+
else
|
|
203
|
+
for (const recipient of host.listRecipients(sender).slice(0, 256)) {
|
|
204
|
+
if (!nonempty(recipient?.address) ||
|
|
205
|
+
!nonempty(recipient.id) ||
|
|
206
|
+
(recipient.title !== undefined && typeof recipient.title !== "string"))
|
|
207
|
+
continue;
|
|
208
|
+
const entry = {
|
|
209
|
+
address: recipient.address,
|
|
210
|
+
id: recipient.id,
|
|
211
|
+
...(recipient.title === undefined ? {} : { title: recipient.title }),
|
|
212
|
+
};
|
|
213
|
+
result.conversations.push(entry);
|
|
214
|
+
if (Buffer.byteLength(JSON.stringify(result)) > 48 * 1024)
|
|
215
|
+
result.conversations.pop();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
for (const envelope of messages)
|
|
219
|
+
this.acknowledge(sender, envelope.id);
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
if (action === "reply" || action === "escalate") {
|
|
223
|
+
const record = args.requestId && this.requests.get(args.requestId);
|
|
224
|
+
if (!record || record.question.settled)
|
|
225
|
+
throw new Error("Unknown or settled request");
|
|
226
|
+
if (sender !== record.target)
|
|
227
|
+
throw new Error("Only the request receiver may reply or escalate");
|
|
228
|
+
this.authorize(host, sender, record.sender, action);
|
|
229
|
+
if (record.escalated)
|
|
230
|
+
throw new Error("Request already escalated to user");
|
|
231
|
+
if (action === "reply") {
|
|
232
|
+
checkAnswers(args.answers, record.question.questions);
|
|
233
|
+
record.question.resolve(args.answers);
|
|
234
|
+
return { requestId: record.question.id, status: "replied" };
|
|
235
|
+
}
|
|
236
|
+
record.escalated = true;
|
|
237
|
+
record.question.audience = "user";
|
|
238
|
+
this.acknowledge(record.target, record.envelope.id);
|
|
239
|
+
// Return immediately: the original requester waits for the shared question.
|
|
240
|
+
try {
|
|
241
|
+
void Promise.resolve(host.askUser(record.sender, record.question, record.controller.signal)).catch(() => record.question.resolve({ cancelled: true, reason: "User question delivery failed" }));
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
record.question.resolve({ cancelled: true, reason: "User question delivery failed" });
|
|
245
|
+
}
|
|
246
|
+
return { requestId: record.question.id, status: "escalated" };
|
|
247
|
+
}
|
|
248
|
+
if (action !== "send" && action !== "request")
|
|
249
|
+
throw new Error("Unknown communication action");
|
|
250
|
+
if (!nonempty(args.to))
|
|
251
|
+
throw new Error("A communication target is required");
|
|
252
|
+
const target = host.resolveTarget(sender.id, args.to);
|
|
253
|
+
if (!target)
|
|
254
|
+
throw new Error("Communication target not found");
|
|
255
|
+
this.authorize(host, sender, target, action);
|
|
256
|
+
const senderAddress = host.address ? host.address(sender) : sender.id;
|
|
257
|
+
const targetAddress = host.address ? host.address(target) : target.id;
|
|
258
|
+
if (!nonempty(senderAddress) || !nonempty(targetAddress))
|
|
259
|
+
throw new Error("Invalid communication address");
|
|
260
|
+
if (action === "send") {
|
|
261
|
+
if (!nonempty(args.message))
|
|
262
|
+
throw new Error("A nonempty message is required");
|
|
263
|
+
const envelope = Object.freeze({
|
|
264
|
+
kind: "communication_data",
|
|
265
|
+
authority: "data",
|
|
266
|
+
id: randomUUID(),
|
|
267
|
+
senderId: senderAddress,
|
|
268
|
+
targetId: targetAddress,
|
|
269
|
+
action,
|
|
270
|
+
message: args.message,
|
|
271
|
+
});
|
|
272
|
+
this.enqueue(target, envelope);
|
|
273
|
+
try {
|
|
274
|
+
const status = await this.deliver(host, target, envelope, signal, sender);
|
|
275
|
+
if (status === "delivered")
|
|
276
|
+
this.acknowledge(target, envelope.id);
|
|
277
|
+
return { messageId: envelope.id, status };
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
this.acknowledge(target, envelope.id);
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
checkQuestions(args.questions);
|
|
285
|
+
if (args.message !== undefined && typeof args.message !== "string")
|
|
286
|
+
throw new Error("Invalid request context");
|
|
287
|
+
const timeout = args.timeoutSeconds ?? this.limits.defaultTimeoutSeconds;
|
|
288
|
+
if (!Number.isFinite(timeout) || timeout < 0 || timeout > 86400)
|
|
289
|
+
throw new Error("Timeout must be within one day");
|
|
290
|
+
if (this.hasPath(target, sender))
|
|
291
|
+
throw new Error("Communication request cycle detected");
|
|
292
|
+
const pendingCount = [...this.requests.values()].filter((r) => r.sender === sender || r.target === sender || r.sender === target || r.target === target);
|
|
293
|
+
for (const endpoint of [sender, target]) {
|
|
294
|
+
if (pendingCount.filter((r) => r.sender === endpoint || r.target === endpoint).length >=
|
|
295
|
+
this.limits.maxPendingPerEndpoint)
|
|
296
|
+
throw new Error("Endpoint pending request limit exceeded");
|
|
297
|
+
}
|
|
298
|
+
if (this.requests.size >= this.limits.maxPendingTotal)
|
|
299
|
+
throw new Error("Global pending request limit exceeded");
|
|
300
|
+
const controller = new AbortController();
|
|
301
|
+
const question = new PendingQuestion(args.questions, sender.id, "parent", timeout, signal);
|
|
302
|
+
const envelope = Object.freeze({
|
|
303
|
+
kind: "communication_data",
|
|
304
|
+
authority: "data",
|
|
305
|
+
id: randomUUID(),
|
|
306
|
+
senderId: senderAddress,
|
|
307
|
+
targetId: targetAddress,
|
|
308
|
+
action,
|
|
309
|
+
message: args.message,
|
|
310
|
+
requestId: question.id,
|
|
311
|
+
questions: structuredClone(args.questions),
|
|
312
|
+
});
|
|
313
|
+
try {
|
|
314
|
+
this.enqueue(target, envelope);
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
question.resolve(null);
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
const record = { sender, target, question, controller, envelope, escalated: false };
|
|
321
|
+
this.requests.set(question.id, record);
|
|
322
|
+
question.subscribeSettled(() => {
|
|
323
|
+
this.requests.delete(question.id);
|
|
324
|
+
this.acknowledge(target, envelope.id);
|
|
325
|
+
controller.abort();
|
|
326
|
+
});
|
|
327
|
+
if (!question.settled) {
|
|
328
|
+
try {
|
|
329
|
+
host.onRequest?.(sender, target, question);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
question.resolve({ cancelled: true, reason: "Communication request registration failed" });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!question.settled) {
|
|
336
|
+
// Delivery may block or fail. Neither may outlive the pending question clock.
|
|
337
|
+
void this.deliver(host, target, envelope, controller.signal, sender)
|
|
338
|
+
.then((status) => {
|
|
339
|
+
if (status === "delivered")
|
|
340
|
+
this.acknowledge(target, envelope.id);
|
|
341
|
+
})
|
|
342
|
+
.catch(() => question.resolve({ cancelled: true, reason: "Communication delivery failed" }));
|
|
343
|
+
}
|
|
344
|
+
return { requestId: question.id, result: await question.promise };
|
|
345
|
+
}
|
|
346
|
+
async deliver(host, target, envelope, signal, sender) {
|
|
347
|
+
checkSignal(signal);
|
|
348
|
+
let removeAbort;
|
|
349
|
+
try {
|
|
350
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
351
|
+
if (!signal)
|
|
352
|
+
return;
|
|
353
|
+
const abort = () => reject(new Error("Communication aborted"));
|
|
354
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
355
|
+
removeAbort = () => signal.removeEventListener("abort", abort);
|
|
356
|
+
});
|
|
357
|
+
const status = await Promise.race([host.deliver(target, structuredClone(envelope), signal, sender), aborted]);
|
|
358
|
+
if (status !== "queued" && status !== "delivered")
|
|
359
|
+
throw new Error("Invalid delivery status");
|
|
360
|
+
return status;
|
|
361
|
+
}
|
|
362
|
+
finally {
|
|
363
|
+
removeAbort?.();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/** Shared across ClientSession holders. Hosts are supplied per call, never cached. */
|
|
368
|
+
export const conversationCommunication = new ConversationCommunication();
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
23
23
|
import { Type } from "typebox";
|
|
24
24
|
import { pick } from "./i18n.js";
|
|
25
|
-
import { CONVERSATION_READ_TOOL_NAME } from "./tool-manager.js";
|
|
26
25
|
import { extractTouches, formatTouchEntry, formatTouchesCompact, toolCallRefsOfContent, unionTouchLists, } from "./conversation-touches.js";
|
|
27
26
|
/** 由 content 块提 toolCalls 字段(additive;格式化输出不受影响,见接口注释)。 */
|
|
28
27
|
function fillToolCalls(target, content) {
|
|
@@ -367,7 +366,7 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
367
366
|
details,
|
|
368
367
|
});
|
|
369
368
|
return defineTool({
|
|
370
|
-
name:
|
|
369
|
+
name: "conversation_read",
|
|
371
370
|
label: "Read another conversation",
|
|
372
371
|
description: "Read ANOTHER conversation: a running conversation of this client (incl. subagents — id from action=list) " +
|
|
373
372
|
"or a persisted history session (file path). Use it whenever the user references another chat. " +
|
|
@@ -441,8 +440,8 @@ export function makeConversationReadTool(host, lang, extras) {
|
|
|
441
440
|
const histHead = L === "zh" ? "【历史】" : "[history]";
|
|
442
441
|
const empty = L === "zh" ? "(无)" : "(none)";
|
|
443
442
|
const tail = L === "zh"
|
|
444
|
-
? `读某一份:
|
|
445
|
-
: `To read one:
|
|
443
|
+
? `读某一份:conversation(action="read", id="c…") 或 conversation(action="read", path="…"),长转录用 offset/limit 翻页;只看文件用 action="files",先看摘要再决定读不读用 action="status"。`
|
|
444
|
+
: `To read one: conversation(action="read", id="c…") or conversation(action="read", path="…"); page long transcripts with offset/limit; action="files" lists touched files, action="status" summarizes before you decide to read.`;
|
|
446
445
|
const sections = kind === "history"
|
|
447
446
|
? `${head}\n${histHead}\n${histLines.join("\n") || empty}`
|
|
448
447
|
: kind === "running"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SUBAGENT_TOOL_NAMES } from "./tool-manager.js";
|
|
2
|
+
/** Both public names share the same execution and permission boundary. */
|
|
3
|
+
export const CONVERSATION_TOOL_NAMES = SUBAGENT_TOOL_NAMES;
|
|
4
|
+
export const READ_ONLY_CONVERSATION_ACTIONS = ["get_result", "list", "templates", "read", "files", "status"];
|
|
5
|
+
export function isReadOnlyConversationAction(action) {
|
|
6
|
+
return (typeof action === "string" &&
|
|
7
|
+
READ_ONLY_CONVERSATION_ACTIONS.includes(action.trim().toLowerCase()));
|
|
8
|
+
}
|
|
9
|
+
export function isConversationTool(name) {
|
|
10
|
+
return CONVERSATION_TOOL_NAMES.includes(name);
|
|
11
|
+
}
|
|
12
|
+
export function conversationToolAllowed(allowed, name) {
|
|
13
|
+
return allowed.has(name) || (isConversationTool(name) && CONVERSATION_TOOL_NAMES.some((alias) => allowed.has(alias)));
|
|
14
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
/** Compose before wrapping so both paths retain the caller's ownership and cancellation. */
|
|
3
|
+
export function mergeConversationTools(tools) {
|
|
4
|
+
const reader = tools.find((tool) => tool.name === "conversation_read");
|
|
5
|
+
if (!reader)
|
|
6
|
+
return tools;
|
|
7
|
+
return tools
|
|
8
|
+
.filter((tool) => tool !== reader)
|
|
9
|
+
.concat(tools.some((tool) => tool.name === "conversation")
|
|
10
|
+
? []
|
|
11
|
+
: [
|
|
12
|
+
{
|
|
13
|
+
...reader,
|
|
14
|
+
name: "conversation",
|
|
15
|
+
parameters: Type.Object({
|
|
16
|
+
...reader.parameters.properties,
|
|
17
|
+
action: Type.String({ enum: ["list", "read", "files", "status"] }),
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
20
|
+
])
|
|
21
|
+
.map((tool) => {
|
|
22
|
+
if (tool.name !== "conversation" && tool.name !== "subagent")
|
|
23
|
+
return tool;
|
|
24
|
+
if (tool.execute === reader.execute)
|
|
25
|
+
return tool;
|
|
26
|
+
const management = tool;
|
|
27
|
+
const managementSchema = management.parameters;
|
|
28
|
+
const readSchema = reader.parameters;
|
|
29
|
+
return {
|
|
30
|
+
...management,
|
|
31
|
+
description: "Create and manage collaborative conversations, or inspect running and historical conversations. Use list to discover sessions and read/files/status when the user references another chat. Only listed sessions are readable.",
|
|
32
|
+
promptSnippet: "manage conversations and inspect referenced chats (list/read/files/status)",
|
|
33
|
+
parameters: Type.Object({
|
|
34
|
+
...managementSchema.properties,
|
|
35
|
+
...readSchema.properties,
|
|
36
|
+
action: Type.String({
|
|
37
|
+
enum: [...managementSchema.properties.action.enum, "read", "files", "status"],
|
|
38
|
+
description: "Conversation action. list defaults to running and history sessions.",
|
|
39
|
+
}),
|
|
40
|
+
scope: Type.Optional(Type.String({
|
|
41
|
+
enum: ["current", "all", "finished_all"],
|
|
42
|
+
description: "list: current project or all projects (default all); dismiss: finished_all.",
|
|
43
|
+
})),
|
|
44
|
+
kind: Type.Optional(Type.String({
|
|
45
|
+
enum: ["running", "history", "all", "subagent", "persistent"],
|
|
46
|
+
description: "list: running/history/all sessions, or subagent/persistent collaboration sessions.",
|
|
47
|
+
})),
|
|
48
|
+
}),
|
|
49
|
+
execute: (id, params, signal, onUpdate, ctx) => {
|
|
50
|
+
const action = typeof params.action === "string" ? params.action.trim().toLowerCase() : params.action;
|
|
51
|
+
const inspect = ["read", "files", "status"].includes(action) ||
|
|
52
|
+
(action === "list" && !["subagent", "persistent"].includes(params.kind));
|
|
53
|
+
return (inspect ? reader : management).execute(id, { ...params, action }, signal, onUpdate, ctx);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
*
|
|
16
16
|
* 判定全部是纯函数(无 IO),单测见 tests/unit/delegate-mode.test.ts。
|
|
17
17
|
*/
|
|
18
|
-
import { bashCommandIsReadOnly, SESSION_DISPATCH_TOOLS } from "./plan-mode.js";
|
|
18
|
+
import { bashCommandIsReadOnly, readOnlyToolCallAllowed, SESSION_DISPATCH_TOOLS } from "./plan-mode.js";
|
|
19
|
+
import { isReadOnlyConversationAction, CONVERSATION_TOOL_NAMES } from "./conversation-tool-names.js";
|
|
19
20
|
/** 审查者模式下确定禁止的工具名单(写 / 改 / 增删 / git 写 / 派发类)。 */
|
|
20
21
|
export const DELEGATE_MODE_BLOCKED_TOOL_NAMES = [
|
|
21
22
|
"write",
|
|
@@ -51,12 +52,13 @@ export const DELEGATE_MODE_BLOCKED_TOOL_NAMES = [
|
|
|
51
52
|
"eval",
|
|
52
53
|
"codemode",
|
|
53
54
|
"mcp_manage",
|
|
55
|
+
"device_collab",
|
|
54
56
|
"sandbox",
|
|
55
57
|
"format",
|
|
56
58
|
"prettier",
|
|
57
59
|
"lint_fix",
|
|
58
60
|
"autofix",
|
|
59
|
-
|
|
61
|
+
...CONVERSATION_TOOL_NAMES,
|
|
60
62
|
...SESSION_DISPATCH_TOOLS,
|
|
61
63
|
];
|
|
62
64
|
const BLOCKED_TOOLS = new Set(DELEGATE_MODE_BLOCKED_TOOL_NAMES);
|
|
@@ -68,9 +70,9 @@ const BLOCKED_TOOLS = new Set(DELEGATE_MODE_BLOCKED_TOOL_NAMES);
|
|
|
68
70
|
* 名单 = 三闸门共用的真实注册派发工具(SESSION_DISPATCH_TOOLS,#436 前是一堆
|
|
69
71
|
* 幽灵名)+ subagent 整工具(这里不分 action,审查者对话一概不派不问)。
|
|
70
72
|
*/
|
|
71
|
-
const DISPATCH_TOOLS = new Set([...SESSION_DISPATCH_TOOLS,
|
|
73
|
+
const DISPATCH_TOOLS = new Set([...SESSION_DISPATCH_TOOLS, ...CONVERSATION_TOOL_NAMES]);
|
|
72
74
|
/** bash 家族(要逐条判命令是否只读)。 */
|
|
73
|
-
const BASH_TOOLS = new Set(["bash", "shell", "sh", "zsh", "
|
|
75
|
+
const BASH_TOOLS = new Set(["bash", "shell", "sh", "zsh", "terminal_bash", "run_command", "exec"]);
|
|
74
76
|
/** 从工具参数里取命令文本(各工具字段名不同)。 */
|
|
75
77
|
function commandOf(params) {
|
|
76
78
|
if (!params || typeof params !== "object")
|
|
@@ -92,6 +94,8 @@ export function delegationDenial(toolName, params) {
|
|
|
92
94
|
const name = (toolName ?? "").trim();
|
|
93
95
|
if (!name)
|
|
94
96
|
return undefined;
|
|
97
|
+
if (CONVERSATION_TOOL_NAMES.some((alias) => alias === name) && isReadOnlyConversationAction(params?.action))
|
|
98
|
+
return undefined;
|
|
95
99
|
if (DISPATCH_TOOLS.has(name)) {
|
|
96
100
|
return {
|
|
97
101
|
kind: "dispatch-tool",
|
|
@@ -99,6 +103,15 @@ export function delegationDenial(toolName, params) {
|
|
|
99
103
|
reasonEn: `Reviewer mode: ${name} is unavailable — dispatching is done by the server (one persistent executor conversation). Describe the work, review the result, or ask questions.`,
|
|
100
104
|
};
|
|
101
105
|
}
|
|
106
|
+
if (name === "terminal") {
|
|
107
|
+
if (readOnlyToolCallAllowed(name, params))
|
|
108
|
+
return undefined;
|
|
109
|
+
return {
|
|
110
|
+
kind: "write-tool",
|
|
111
|
+
reason: "只读审查仅允许 terminal 的 list/read/wait。",
|
|
112
|
+
reasonEn: "Read-only review permits only terminal list/read/wait actions.",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
102
115
|
if (BASH_TOOLS.has(name)) {
|
|
103
116
|
const cmd = commandOf(params);
|
|
104
117
|
if (cmd.trim() === "") {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
import { DefaultPackageManager, getAgentDir, loadSkills, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { ALL_AGENT_TOOL_ENTRIES, isToolSupportedOnPlatform } from "../tool-manager.js";
|
|
5
|
+
import { discoverDiskSkills, mergeSkillCollections } from "../skill-discovery.js";
|
|
6
|
+
import { listAllMcpServers } from "../mcp-manager.js";
|
|
7
|
+
import { getMcpToolServer } from "../mcp-bridge.js";
|
|
8
|
+
import { isBotToolAllowed } from "./bot-execution.js";
|
|
9
|
+
import { DeviceWorkspaceError } from "./workspaces.js";
|
|
10
|
+
/** Captures the requested project once; only public metadata is returned. */
|
|
11
|
+
export async function getLocalBotOptions(sources, requestedCwd, signal) {
|
|
12
|
+
signal.throwIfAborted();
|
|
13
|
+
if (requestedCwd !== undefined && (typeof requestedCwd !== "string" || !isAbsolute(requestedCwd)))
|
|
14
|
+
throw new DeviceWorkspaceError(400, "BOT_CWD_INVALID", "Project path must be absolute");
|
|
15
|
+
const cwd = resolve(requestedCwd ?? sources.defaultCwd);
|
|
16
|
+
if (!(await stat(cwd).catch(() => undefined))?.isDirectory())
|
|
17
|
+
throw new DeviceWorkspaceError(400, "BOT_CWD_INVALID", "Project directory does not exist");
|
|
18
|
+
signal.throwIfAborted();
|
|
19
|
+
const agentDir = sources.agentDir ?? getAgentDir();
|
|
20
|
+
const settings = SettingsManager.create(cwd, agentDir);
|
|
21
|
+
// Match ResourceLoader package/path resolution, but skip missing packages rather than installing.
|
|
22
|
+
// No extensions are imported and no MCP transport is initialized.
|
|
23
|
+
const resources = await new DefaultPackageManager({ cwd, agentDir, settingsManager: settings }).resolve(async () => {
|
|
24
|
+
signal.throwIfAborted();
|
|
25
|
+
return "skip";
|
|
26
|
+
});
|
|
27
|
+
signal.throwIfAborted();
|
|
28
|
+
const sdkSkills = loadSkills({
|
|
29
|
+
cwd,
|
|
30
|
+
agentDir,
|
|
31
|
+
skillPaths: resources.skills.filter((resource) => resource.enabled).map((resource) => resource.path),
|
|
32
|
+
includeDefaults: false,
|
|
33
|
+
}).skills;
|
|
34
|
+
const skills = mergeSkillCollections(sdkSkills, discoverDiskSkills({ cwd, agentDir }));
|
|
35
|
+
const bridge = sources.peekMcpBridge?.(cwd);
|
|
36
|
+
const definitions = bridge?.getTools() ?? [];
|
|
37
|
+
const counts = new Map();
|
|
38
|
+
for (const tool of definitions)
|
|
39
|
+
counts.set(tool.name, (counts.get(tool.name) ?? 0) + 1);
|
|
40
|
+
const reserved = new Set(ALL_AGENT_TOOL_ENTRIES.map((tool) => tool.name));
|
|
41
|
+
const mcpServers = listAllMcpServers({ cwd, agentDir, dataDir: sources.dataDir, bridge })
|
|
42
|
+
.servers.filter((server) => !server.overriddenBy && Array.isArray(server.tools) && ["global", "project"].includes(server.scope))
|
|
43
|
+
.map((server) => ({
|
|
44
|
+
id: server.name,
|
|
45
|
+
name: server.name,
|
|
46
|
+
scope: server.scope,
|
|
47
|
+
status: !server.enabled
|
|
48
|
+
? "disabled"
|
|
49
|
+
: server.status === "running" && !server.usingPreviousConfig
|
|
50
|
+
? "ready"
|
|
51
|
+
: "not_loaded",
|
|
52
|
+
tools: !server.enabled || server.status !== "running" || server.usingPreviousConfig
|
|
53
|
+
? []
|
|
54
|
+
: definitions
|
|
55
|
+
.filter((tool) => getMcpToolServer(tool) === server.name &&
|
|
56
|
+
counts.get(tool.name) === 1 &&
|
|
57
|
+
!reserved.has(tool.name) &&
|
|
58
|
+
isBotToolAllowed(tool.name))
|
|
59
|
+
.map((tool) => ({ id: tool.name, name: tool.name, description: tool.description, source: server.name })),
|
|
60
|
+
}));
|
|
61
|
+
const models = (await sources.models?.(signal)) ?? [];
|
|
62
|
+
signal.throwIfAborted();
|
|
63
|
+
const defaultModel = sources.defaultModel?.();
|
|
64
|
+
const projects = (await sources.projects?.()) ?? [{ path: sources.defaultCwd }];
|
|
65
|
+
signal.throwIfAborted();
|
|
66
|
+
return {
|
|
67
|
+
cwd,
|
|
68
|
+
defaultCwd: sources.defaultCwd,
|
|
69
|
+
...(defaultModel ? { defaultModel } : {}),
|
|
70
|
+
projects,
|
|
71
|
+
models: models.map(({ id, name, provider, reasoning, vision, enabled }) => ({
|
|
72
|
+
id,
|
|
73
|
+
name,
|
|
74
|
+
provider,
|
|
75
|
+
reasoning,
|
|
76
|
+
vision,
|
|
77
|
+
...(enabled === undefined ? {} : { enabled }),
|
|
78
|
+
})),
|
|
79
|
+
tools: ALL_AGENT_TOOL_ENTRIES.filter((tool) => isToolSupportedOnPlatform(tool.name) && isBotToolAllowed(tool.name)).map(({ name }) => ({ id: name, name, source: "builtin" })),
|
|
80
|
+
skills: skills.map((skill) => ({
|
|
81
|
+
id: skill.name,
|
|
82
|
+
name: skill.name,
|
|
83
|
+
description: skill.description,
|
|
84
|
+
path: skill.filePath,
|
|
85
|
+
})),
|
|
86
|
+
mcpServers,
|
|
87
|
+
};
|
|
88
|
+
}
|