pi-web-ui 0.118.0 → 0.120.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 +143 -1
- package/bin/hub-upgrade.mjs +33 -15
- package/bin/lib/atomic-file.mjs +90 -0
- package/dist/server/agent-service-daemon.js +44 -10
- package/dist/server/agent-service.js +930 -166
- package/dist/server/approval-default-rules.js +4 -4
- package/dist/server/ask-user-question-tool.js +3 -40
- package/dist/server/atomic-file.js +130 -5
- package/dist/server/background-executors.js +235 -0
- package/dist/server/bash-timeout.js +47 -0
- package/dist/server/bash-tool.js +72 -5
- package/dist/server/bg-servers.js +19 -13
- package/dist/server/browser-page-tool.js +38 -29
- package/dist/server/browser-script-tool.js +119 -0
- package/dist/server/canvas/canvas-agent-tool.js +46 -35
- package/dist/server/canvas/canvas-dispatch.js +12 -1
- package/dist/server/claim-files-tool.js +6 -7
- package/dist/server/client-state.js +457 -41
- package/dist/server/communicate-tool.js +59 -77
- package/dist/server/compact-context-tool.js +4 -13
- package/dist/server/conversation-communication.js +23 -1
- package/dist/server/conversation-read-tool.js +14 -23
- package/dist/server/conversation-rows.js +17 -0
- package/dist/server/conversation-tool-names.js +2 -2
- package/dist/server/conversation-tool.js +23 -15
- package/dist/server/conversation-touches.js +1 -1
- package/dist/server/delegate-mode.js +0 -1
- package/dist/server/delegate-task.js +18 -39
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-execution.js +0 -1
- package/dist/server/device-center/group-router-runtime.js +2 -0
- package/dist/server/device-center/hub-upgrade.js +5 -10
- package/dist/server/device-center/task-progress.js +2 -2
- package/dist/server/dispatch-domain-handlers.js +97 -24
- package/dist/server/dispatch-plugin-handlers.js +10 -0
- package/dist/server/dsh/dsh-agent-service.js +21 -19
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/edit-tool.js +293 -0
- package/dist/server/engine-catalog.js +8 -2
- package/dist/server/engine-cli.js +29 -7
- package/dist/server/engine-probe.js +11 -6
- package/dist/server/eval-tool.js +5 -19
- package/dist/server/files-service.js +41 -19
- package/dist/server/fs-copy.js +93 -0
- package/dist/server/goal-review-gate.js +2 -3
- package/dist/server/index.js +92 -3
- package/dist/server/job-runner.js +345 -0
- package/dist/server/lsp-tool.js +10 -28
- package/dist/server/marker-service.js +42 -30
- package/dist/server/mcp-agent-tool.js +22 -47
- package/dist/server/model-session.js +16 -0
- package/dist/server/native-cli-session-hooks.js +3 -2
- package/dist/server/native-cli-session.js +27 -2
- package/dist/server/patch-tool.js +2 -8
- package/dist/server/phone-tool.js +167 -0
- package/dist/server/plan-mode.js +7 -4
- package/dist/server/plan-update-tool.js +5 -8
- package/dist/server/plugin-api-catalog.js +13 -1
- package/dist/server/plugin-bundled.js +35 -28
- package/dist/server/plugin-catalog.js +6 -0
- package/dist/server/plugin-delivery.js +358 -0
- package/dist/server/plugin-inbox.js +152 -0
- package/dist/server/plugin-installer.js +15 -0
- package/dist/server/plugin-ledger.js +183 -0
- package/dist/server/plugin-manifest-validate.js +19 -0
- package/dist/server/plugin-materialize.js +161 -0
- package/dist/server/plugin-paths.js +60 -0
- package/dist/server/plugin-removal.js +16 -3
- package/dist/server/plugin-schedule.js +8 -7
- package/dist/server/plugin-secrets.js +7 -3
- package/dist/server/plugin-updater.js +2 -4
- package/dist/server/plugins.js +205 -48
- package/dist/server/present-files-tool.js +7 -13
- package/dist/server/preset-fields.js +23 -12
- package/dist/server/preset-share.js +1 -1
- package/dist/server/process-utils.js +11 -0
- package/dist/server/project-scripts.js +38 -0
- package/dist/server/prompt-composer.js +40 -21
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/question-params.js +98 -0
- package/dist/server/quick-ask-settings.js +0 -1
- package/dist/server/quick-ask.js +3 -0
- package/dist/server/read-tool.js +10 -17
- package/dist/server/remote-ssh-service.js +40 -1
- package/dist/server/sandbox-runtime-gate.js +1 -1
- package/dist/server/sandbox-service.js +0 -1
- package/dist/server/sandbox-tool.js +25 -34
- package/dist/server/schedule-agent-tool.js +9 -19
- package/dist/server/scm-commitmsg.js +2 -1
- package/dist/server/serialize.js +8 -0
- package/dist/server/session-list-index.js +246 -0
- package/dist/server/session-list-scan.js +5 -0
- package/dist/server/session-parser.js +16 -0
- package/dist/server/settings-service.js +49 -19
- package/dist/server/skill-tool.js +4 -6
- package/dist/server/subagent-budget.js +68 -0
- package/dist/server/subagent-evidence.js +297 -0
- package/dist/server/subagent-helpers.js +12 -0
- package/dist/server/subagent-ledger.js +401 -0
- package/dist/server/subagent-notify.js +6 -2
- package/dist/server/subagent-security-gate.js +2 -3
- package/dist/server/subagent-settle.js +71 -0
- package/dist/server/subagents.js +566 -211
- package/dist/server/tabs.js +8 -1
- package/dist/server/terminals.js +34 -28
- package/dist/server/tool-approval.js +15 -1
- package/dist/server/tool-guards.js +0 -91
- package/dist/server/tool-manager.js +127 -47
- package/dist/server/tool-overrides.js +8 -1
- package/dist/server/tool-prompt-overrides.js +3 -6
- package/dist/server/tool-prompts.js +60 -17
- package/dist/server/universal/driver-base.js +2 -0
- package/dist/server/universal/drivers/claude-code.js +210 -211
- package/dist/server/universal/drivers/codex.js +29 -24
- package/dist/server/universal/engine-mcp.js +107 -0
- package/dist/server/universal/universal-attachments.js +77 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +106 -69
- package/dist/server/vision-bridge.js +2 -0
- package/dist/server/workspace-handle.js +119 -17
- package/dist/server/workspace-queue.js +37 -0
- package/dist/server/worktree-tool.js +13 -20
- package/docs/README.md +40 -36
- package/docs/architecture-plugins.md +64 -35
- package/docs/device-center.md +1 -1
- package/package.json +16 -4
- package/plugin-sdk/index.d.ts +102 -0
- package/plugins/catalog.json +23 -51
- package/themes/bases/flow-base.css +8 -17
- package/themes/dark-teal.css +0 -3
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
- package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
- package/web/dist/assets/{CanvasStudio-CAWcs9tm.js → CanvasStudio-BB_Iq7pl.js} +3 -3
- package/web/dist/assets/CanvasStudio-DU6O3N4u.js +1579 -0
- package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
- package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-qJzbI0Cf.js +1 -0
- package/web/dist/assets/{DeviceGroups-C_fZMNeK.js → DeviceGroups-DPrQxW6B.js} +1 -1
- package/web/dist/assets/DeviceGroups-DoucyUjI.js +1 -0
- package/web/dist/assets/{Dropdown-CTgVLUbp.js → Dropdown-kj_NIj6e.js} +1 -1
- package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
- package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
- package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
- package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
- package/web/dist/assets/GroupConversation-1-lsPO1f.js +61 -0
- package/web/dist/assets/GroupConversation-HeiyW_O_.js +61 -0
- package/web/dist/assets/{GroupWorkItems-BIvZtr10.js → GroupWorkItems-BYJv2XFj.js} +1 -1
- package/web/dist/assets/{HintTip-Da6qc566.js → HintTip-DFhoclDw.js} +1 -1
- package/web/dist/assets/ModelConfigModal-D2Ro-jUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-DPc9R1pq.js +2 -0
- package/web/dist/assets/{NativeCliPanel-CU1rZmyu.js → NativeCliPanel-B108d697.js} +3 -3
- package/web/dist/assets/NativeCliPanel-DupvGwQM.js +5 -0
- package/web/dist/assets/{PiSetupModal-DZKY5Wiw.js → PiSetupModal-D0HitBfd.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-BLKUEDde.js +1 -0
- package/web/dist/assets/SCMPanel-DDbWrUHR.js +2 -0
- package/web/dist/assets/SCMPanel-DluNcd2-.js +2 -0
- package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
- package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
- package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
- package/web/dist/assets/{TermXterm-Bt5WKAxP.js → TermXterm-SYc-MUk2.js} +2 -2
- package/web/dist/assets/TerminalPanel-CgA_lhVT.js +1 -0
- package/web/dist/assets/TerminalPanel-vdSIOPjD.js +1 -0
- package/web/dist/assets/TuiOverlayModal-Cy1jYYIw.js +1 -0
- package/web/dist/assets/TuiOverlayModal-kXY_4hV8.js +1 -0
- package/web/dist/assets/app-globals-CBEscsYP.js +129 -0
- package/web/dist/assets/{canvas-client-WkhM55mR.js → canvas-client-Clsypfs6.js} +1 -1
- package/web/dist/assets/{desktop-B8NZ3KW-.js → desktop-C6D9a8HZ.js} +1 -1
- package/web/dist/assets/index-BD29OL9L.js +404 -0
- package/web/dist/assets/index-BlCxbqqr.js +404 -0
- package/web/dist/assets/index-DB55rbKC.css +1 -0
- package/web/dist/assets/plugin-host-VWBcq-LQ.js +1 -0
- package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
- package/web/dist/assets/theme-CpQk_Agp.js +1 -0
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/dist/server/edit-soft-tool.js +0 -297
- package/web/dist/assets/BgTasksModal-D-x7kA63.js +0 -1
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +0 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +0 -2
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +0 -1
- package/web/dist/assets/GroupConversation-C81YjF2C.js +0 -61
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +0 -1
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +0 -2
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +0 -33
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +0 -1
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +0 -1
- package/web/dist/assets/app-globals-CZjFtI4F.js +0 -129
- package/web/dist/assets/index-CQc3VrWa.css +0 -1
- package/web/dist/assets/index-D_AGu4Zv.js +0 -404
- package/web/dist/assets/plugin-host-uqZGpvCs.js +0 -1
- package/web/dist/assets/remote-ssh-client-Cdf-cTUe.js +0 -1
- package/web/dist/assets/theme-DGL7hLUs.js +0 -1
|
@@ -6,13 +6,24 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
6
6
|
import { BaseAgentDriver } from "../driver-base.js";
|
|
7
7
|
import { probeEngineCliVersion, resolveEngineCliLaunch } from "../../engine-cli.js";
|
|
8
8
|
import { killPidTree } from "../../process-utils.js";
|
|
9
|
-
import {
|
|
9
|
+
import { decodeInlineImage, describeCliAttachment } from "../universal-attachments.js";
|
|
10
|
+
import { collectEnabledMcpServers, toCodexMcpOverrides } from "../engine-mcp.js";
|
|
10
11
|
export async function probeCodex(executablePath) {
|
|
11
12
|
const result = await probeEngineCliVersion("codex", executablePath);
|
|
12
13
|
return result.available && result.version
|
|
13
14
|
? { ...result, version: result.version.replace(/^codex(?:-cli)?\s+/i, "") }
|
|
14
15
|
: result;
|
|
15
16
|
}
|
|
17
|
+
/** Text content of a completed `mcp_tool_call` item (`result.content[].text`), if any. */
|
|
18
|
+
function mcpResultText(item) {
|
|
19
|
+
if (item?.type !== "mcp_tool_call" || !Array.isArray(item.result?.content))
|
|
20
|
+
return undefined;
|
|
21
|
+
const text = item.result.content
|
|
22
|
+
.map((part) => (part?.type === "text" && typeof part.text === "string" ? part.text : ""))
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join("\n");
|
|
25
|
+
return text || undefined;
|
|
26
|
+
}
|
|
16
27
|
export class CodexDriver extends BaseAgentDriver {
|
|
17
28
|
options;
|
|
18
29
|
id = "codex";
|
|
@@ -77,32 +88,23 @@ export class CodexDriver extends BaseAgentDriver {
|
|
|
77
88
|
let input = prompt;
|
|
78
89
|
try {
|
|
79
90
|
for (const att of attachments ?? []) {
|
|
80
|
-
if (att.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
if (att.mode === "page" || att.mode === "conversation") {
|
|
85
|
-
input += `\nReferenced ${att.mode}: ${JSON.stringify(att.path)} (host access unavailable in Codex).`;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (att.imageData) {
|
|
89
|
-
const match = /^data:(image\/(?:png|jpeg|webp|gif));base64,([\s\S]+)$/.exec(att.imageData);
|
|
90
|
-
const mime = match?.[1] ?? att.mimeType;
|
|
91
|
-
if (!mime || !["image/png", "image/jpeg", "image/webp", "image/gif"].includes(mime))
|
|
91
|
+
if (att.imageData && !att.fileData && !att.uploadPath) {
|
|
92
|
+
const image = decodeInlineImage(att);
|
|
93
|
+
if (!image)
|
|
92
94
|
throw new Error("Unsupported Codex image format");
|
|
93
|
-
|
|
94
|
-
if (encoded.length > 28 * 1024 * 1024)
|
|
95
|
+
if (image.data.length > 28 * 1024 * 1024)
|
|
95
96
|
throw new Error("Codex image exceeds size limit");
|
|
96
97
|
imageDir ??= mkdtempSync(join(tmpdir(), "pi-codex-images-"));
|
|
97
|
-
const path = join(imageDir, `${imageArgs.length}.${
|
|
98
|
-
writeFileSync(path, Buffer.from(
|
|
98
|
+
const path = join(imageDir, `${imageArgs.length}.${image.mimeType.split("/")[1]}`);
|
|
99
|
+
writeFileSync(path, Buffer.from(image.data, "base64"), { mode: 0o600 });
|
|
99
100
|
imageArgs.push("--image", path);
|
|
101
|
+
continue;
|
|
100
102
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
input += `\nFile reference: ${JSON.stringify(att.path)}${att.mode === "lines" ? ` (lines ${att.lines?.start ?? ""}-${att.lines?.end ?? ""})` : ""}`;
|
|
103
|
+
const note = describeCliAttachment(att);
|
|
104
|
+
if (note)
|
|
105
|
+
input += `\n${note}`;
|
|
105
106
|
}
|
|
107
|
+
const mcp = toCodexMcpOverrides(collectEnabledMcpServers({ cwd, agentDir: this.options.agentDir, dataDir: this.options.dataDir }));
|
|
106
108
|
const launch = resolveEngineCliLaunch("codex", { executablePath: this.options.executablePath, cwd });
|
|
107
109
|
const args = [
|
|
108
110
|
...launch.args,
|
|
@@ -117,6 +119,7 @@ export class CodexDriver extends BaseAgentDriver {
|
|
|
117
119
|
"never",
|
|
118
120
|
"-c",
|
|
119
121
|
`model_reasoning_effort=${JSON.stringify(this.effort)}`,
|
|
122
|
+
...mcp.args,
|
|
120
123
|
];
|
|
121
124
|
if (this.model !== "default")
|
|
122
125
|
args.push("--model", this.model);
|
|
@@ -128,7 +131,7 @@ export class CodexDriver extends BaseAgentDriver {
|
|
|
128
131
|
windowsHide: true,
|
|
129
132
|
detached: process.platform !== "win32",
|
|
130
133
|
stdio: ["pipe", "pipe", "pipe"],
|
|
131
|
-
env: { ...process.env, NO_COLOR: "1" },
|
|
134
|
+
env: { ...process.env, ...mcp.env, NO_COLOR: "1" },
|
|
132
135
|
});
|
|
133
136
|
let finish;
|
|
134
137
|
const run = {
|
|
@@ -193,8 +196,10 @@ export class CodexDriver extends BaseAgentDriver {
|
|
|
193
196
|
}
|
|
194
197
|
if (event.type === "item.completed")
|
|
195
198
|
sink.onToolEnd(id, {
|
|
196
|
-
output: item.aggregated_output ?? JSON.stringify(item),
|
|
197
|
-
...(item.status === "failed" ||
|
|
199
|
+
output: item.aggregated_output ?? mcpResultText(item) ?? JSON.stringify(item),
|
|
200
|
+
...(item.status === "failed" ||
|
|
201
|
+
item.error ||
|
|
202
|
+
(typeof item.exit_code === "number" && item.exit_code !== 0)
|
|
198
203
|
? { error: item.error?.message || `Codex ${item.type} failed (${item.exit_code ?? item.status})` }
|
|
199
204
|
: {}),
|
|
200
205
|
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getGlobalMcpPath, getProjectMcpPath, readMcpConfigFile } from "../mcp-manager.js";
|
|
2
|
+
import { isRemoteWorkspaceUri } from "../remote-ssh-service.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bridges the MCP servers configured in pi-web-ui (`<agentDir>/mcp.json` + `<cwd>/.pi/mcp.json`)
|
|
5
|
+
* into the native CLI engines. The CLIs keep loading their own MCP config as well; this only adds
|
|
6
|
+
* pi's servers on top so a server configured in the web UI is visible to every engine.
|
|
7
|
+
*/
|
|
8
|
+
const SERVER_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
9
|
+
export function collectEnabledMcpServers(opts) {
|
|
10
|
+
const global = readMcpConfigFile(getGlobalMcpPath(opts.agentDir, opts.dataDir || undefined)).servers;
|
|
11
|
+
const project = isRemoteWorkspaceUri(opts.cwd) ? {} : readMcpConfigFile(getProjectMcpPath(opts.cwd)).servers;
|
|
12
|
+
const merged = { ...global, ...project };
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const [name, spec] of Object.entries(merged)) {
|
|
15
|
+
if (!SERVER_NAME.test(name) || !spec || spec.enabled === false)
|
|
16
|
+
continue;
|
|
17
|
+
if (spec.url ? !/^https?:\/\//i.test(spec.url) : !spec.command)
|
|
18
|
+
continue;
|
|
19
|
+
out[name] = spec;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function isRemoteSpec(spec) {
|
|
24
|
+
return Boolean(spec.url) && spec.type !== "stdio";
|
|
25
|
+
}
|
|
26
|
+
/** Claude Code `--mcp-config` file body. Only fields Claude's schema knows are emitted. */
|
|
27
|
+
export function toClaudeMcpConfig(servers) {
|
|
28
|
+
const mcpServers = {};
|
|
29
|
+
for (const [name, spec] of Object.entries(servers)) {
|
|
30
|
+
if (isRemoteSpec(spec)) {
|
|
31
|
+
mcpServers[name] = {
|
|
32
|
+
type: "http",
|
|
33
|
+
url: spec.url,
|
|
34
|
+
...(spec.headers && Object.keys(spec.headers).length ? { headers: spec.headers } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else if (spec.command) {
|
|
38
|
+
mcpServers[name] = {
|
|
39
|
+
type: "stdio",
|
|
40
|
+
command: spec.command,
|
|
41
|
+
args: spec.args ?? [],
|
|
42
|
+
...(spec.env && Object.keys(spec.env).length ? { env: spec.env } : {}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { mcpServers };
|
|
47
|
+
}
|
|
48
|
+
/** TOML literal for a `codex -c key=value` override (JSON strings/arrays are valid TOML). */
|
|
49
|
+
function tomlValue(value) {
|
|
50
|
+
if (typeof value === "string")
|
|
51
|
+
return JSON.stringify(value);
|
|
52
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
53
|
+
return String(value);
|
|
54
|
+
if (typeof value === "boolean")
|
|
55
|
+
return String(value);
|
|
56
|
+
if (Array.isArray(value))
|
|
57
|
+
return `[${value.map(tomlValue).join(", ")}]`;
|
|
58
|
+
if (value && typeof value === "object")
|
|
59
|
+
return `{ ${Object.entries(value)
|
|
60
|
+
.map(([k, v]) => `${JSON.stringify(k)} = ${tomlValue(v)}`)
|
|
61
|
+
.join(", ")} }`;
|
|
62
|
+
throw new Error(`Unsupported MCP config value: ${String(value)}`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `-c mcp_servers.<name>.<key>=<toml>` overrides for `codex exec`. HTTP header values (usually
|
|
66
|
+
* bearer tokens) travel through `env_http_headers` + the returned env so they stay out of argv.
|
|
67
|
+
*/
|
|
68
|
+
export function toCodexMcpOverrides(servers) {
|
|
69
|
+
const args = [];
|
|
70
|
+
const env = {};
|
|
71
|
+
const push = (name, key, value) => {
|
|
72
|
+
args.push("-c", `mcp_servers.${name}.${key}=${tomlValue(value)}`);
|
|
73
|
+
};
|
|
74
|
+
for (const [name, spec] of Object.entries(servers)) {
|
|
75
|
+
if (isRemoteSpec(spec)) {
|
|
76
|
+
push(name, "url", spec.url);
|
|
77
|
+
const headers = Object.entries(spec.headers ?? {});
|
|
78
|
+
if (headers.length) {
|
|
79
|
+
const envHeaders = {};
|
|
80
|
+
headers.forEach(([header, value], i) => {
|
|
81
|
+
const envName = `PI_MCP_${name.replace(/-/g, "_").toUpperCase()}_H${i}`;
|
|
82
|
+
env[envName] = value;
|
|
83
|
+
envHeaders[header] = envName;
|
|
84
|
+
});
|
|
85
|
+
push(name, "env_http_headers", envHeaders);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (spec.command) {
|
|
89
|
+
push(name, "command", spec.command);
|
|
90
|
+
if (spec.args?.length)
|
|
91
|
+
push(name, "args", spec.args);
|
|
92
|
+
if (spec.env && Object.keys(spec.env).length)
|
|
93
|
+
push(name, "env", spec.env);
|
|
94
|
+
if (spec.cwd)
|
|
95
|
+
push(name, "cwd", spec.cwd);
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
continue;
|
|
99
|
+
if (typeof spec.timeout === "number" && spec.timeout > 0)
|
|
100
|
+
push(name, "tool_timeout_sec", spec.timeout);
|
|
101
|
+
// The driver runs `--ask-for-approval never`; Codex rejects MCP calls that would need a
|
|
102
|
+
// prompt ("requires approval, but approval policy is never"), so servers the user enabled
|
|
103
|
+
// in pi are pre-approved — same trust level as Claude's --dangerously-skip-permissions.
|
|
104
|
+
push(name, "default_tools_approval_mode", "approve");
|
|
105
|
+
}
|
|
106
|
+
return { args, env };
|
|
107
|
+
}
|
|
@@ -1,12 +1,72 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { existsSync, statSync } from "node:fs";
|
|
3
|
-
import { basename, isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import { basename, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { readSkillInstruction } from "../skill-discovery.js";
|
|
5
5
|
import { isRemoteWorkspaceUri } from "../remote-ssh-service.js";
|
|
6
|
+
import { CLIENT_ID_PATTERN, saveUpload, uploadsRoot } from "../uploads.js";
|
|
6
7
|
export function formatUnavailableCanvasReference(att) {
|
|
7
8
|
const escape = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
8
9
|
return `<canvas-ref id="${escape(att.path)}" title="${escape(att.name || att.path)}">Canvas tooling is unavailable in this engine. This is a graph identifier, not a file path; do not read it as a file or start a run.</canvas-ref>`;
|
|
9
10
|
}
|
|
11
|
+
/** Image MIME types the native CLIs accept as inline image input. */
|
|
12
|
+
export const CLI_IMAGE_MIME_TYPES = ["image/png", "image/jpeg", "image/webp", "image/gif"];
|
|
13
|
+
/** Splits `data:<mime>;base64,<data>` (or bare base64 + mimeType) into its parts. */
|
|
14
|
+
export function decodeInlineImage(att) {
|
|
15
|
+
if (!att.imageData)
|
|
16
|
+
return null;
|
|
17
|
+
const match = /^data:([^;,]+);base64,([\s\S]+)$/.exec(att.imageData);
|
|
18
|
+
const mimeType = (match?.[1] ?? att.mimeType ?? "").toLowerCase();
|
|
19
|
+
const data = (match?.[2] ?? att.imageData).replace(/\s+/g, "");
|
|
20
|
+
if (!CLI_IMAGE_MIME_TYPES.includes(mimeType) || !data)
|
|
21
|
+
return null;
|
|
22
|
+
return { mimeType, data };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Persists browser uploads (`fileData`, or unsupported inline images) into the per-client upload
|
|
26
|
+
* dir so the native CLI can open them by absolute path; turns relative `uploadPath`s absolute.
|
|
27
|
+
* Upload retention/cleanup is shared with the pi engine (`server/uploads.ts`).
|
|
28
|
+
*/
|
|
29
|
+
export function materializeUploads(attachments, opts) {
|
|
30
|
+
const clientId = CLIENT_ID_PATTERN.test(opts.clientId) ? opts.clientId : "universal";
|
|
31
|
+
const root = uploadsRoot(opts.dataDir || undefined);
|
|
32
|
+
return attachments.map((att) => {
|
|
33
|
+
const image = decodeInlineImage(att);
|
|
34
|
+
const oversized = image !== null &&
|
|
35
|
+
opts.maxInlineImageBytes !== undefined &&
|
|
36
|
+
(image.data.length * 3) / 4 > opts.maxInlineImageBytes;
|
|
37
|
+
const encoded = att.fileData ?? (att.imageData && (!image || oversized) ? att.imageData : undefined);
|
|
38
|
+
if (encoded) {
|
|
39
|
+
const raw = encoded.replace(/^data:[^;,]+;base64,/, "");
|
|
40
|
+
const { abs } = saveUpload(clientId, att.name || "file", Buffer.from(raw, "base64"), opts.dataDir || undefined);
|
|
41
|
+
const { fileData: _f, imageData: _i, ...rest } = att;
|
|
42
|
+
return { ...rest, uploadPath: abs, name: att.name || basename(abs) };
|
|
43
|
+
}
|
|
44
|
+
if (att.uploadPath) {
|
|
45
|
+
const abs = resolve(root, att.uploadPath);
|
|
46
|
+
const rel = relative(root, abs);
|
|
47
|
+
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
48
|
+
const { uploadPath: _u, ...rest } = att;
|
|
49
|
+
return rest;
|
|
50
|
+
}
|
|
51
|
+
return { ...att, uploadPath: abs };
|
|
52
|
+
}
|
|
53
|
+
return att;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** Plain-text pointer for a non-image attachment, shared by the CLI drivers. */
|
|
57
|
+
export function describeCliAttachment(att) {
|
|
58
|
+
if (att.mode === "canvas")
|
|
59
|
+
return formatUnavailableCanvasReference(att);
|
|
60
|
+
if (att.mode === "page" || att.mode === "conversation")
|
|
61
|
+
return `Referenced ${att.mode}: ${JSON.stringify(att.path)} (host access unavailable in this engine).`;
|
|
62
|
+
if (att.mode === "quote" && att.quote)
|
|
63
|
+
return `<quote>\n${att.quote.text}\n</quote>`;
|
|
64
|
+
if (att.uploadPath)
|
|
65
|
+
return `Attached file: ${JSON.stringify(att.uploadPath)}${att.name ? ` (${att.name})` : ""}. Read it from this path.`;
|
|
66
|
+
if (att.path)
|
|
67
|
+
return `File reference: ${JSON.stringify(att.path)}${att.mode === "lines" && att.lines ? ` (lines ${att.lines.start}-${att.lines.end})` : ""}`;
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
10
70
|
export function scanAtMentions(text, cwd, availableSkills = [], existingAttachments = []) {
|
|
11
71
|
const detectedAttachments = [];
|
|
12
72
|
const detectedSkills = [];
|
|
@@ -109,6 +169,22 @@ export function createAttachmentUiMessages(attachments, timestamp = Date.now())
|
|
|
109
169
|
});
|
|
110
170
|
continue;
|
|
111
171
|
}
|
|
172
|
+
if (att.uploadPath) {
|
|
173
|
+
out.push({
|
|
174
|
+
id: cardId,
|
|
175
|
+
role: "custom",
|
|
176
|
+
customType: "file",
|
|
177
|
+
timestamp,
|
|
178
|
+
content: [{ type: "text", text: `<file path="${att.uploadPath}" />` }],
|
|
179
|
+
details: {
|
|
180
|
+
name: att.name || basename(att.uploadPath),
|
|
181
|
+
path: att.uploadPath,
|
|
182
|
+
mode: "reference",
|
|
183
|
+
isDir: false,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
112
188
|
if (att.mode === "canvas") {
|
|
113
189
|
out.push({
|
|
114
190
|
id: cardId,
|
|
@@ -41,7 +41,7 @@ export class UniversalAgentService {
|
|
|
41
41
|
catch { }
|
|
42
42
|
}
|
|
43
43
|
if (typeof this.stateStore?.remember === "function") {
|
|
44
|
-
this.stateStore.remember(clientId, effectiveCwd);
|
|
44
|
+
this.stateStore.remember(clientId, effectiveCwd, { promote: false });
|
|
45
45
|
}
|
|
46
46
|
const driver = this.driverFactory(effectiveCwd);
|
|
47
47
|
session = new UniversalSession({
|