mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(plugins): start Windows script launch wraps through cmd.exe
applyLaunchWrap rejected a Windows .cmd or .bat file on either side of the wrap, and it did so at spawn time, after a refresh had already closed the running session. Both wrapped paths spawn through spawnProcess, which runs a command-script launcher through cmd.exe with each argument quoted, and the provider command is only an argument to the wrapper. Drop the rejection from applyLaunchWrap and from the manager's admission check. Document the wrap in the public hook reference (with its zh-CN translation), state the Windows launcher rule where the wrap contract lives, and name wrap in the open-hook diagnostic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2547edefcc
commit
ab4bd6d59d
+8
-7
@@ -472,8 +472,10 @@ the provider process, so a reload must not reopen agents the plugin does not cha
|
||||
### Launch wrap
|
||||
|
||||
An `agent.open.before` result can carry `wrap: [executable, ...args]`. The provider then starts that
|
||||
session's harness as `[...wrap, command, ...args]`: one direct argv exec with `shell: false` and the
|
||||
final hook env, so an argument with spaces stays one element. `executable` must be an absolute path.
|
||||
session's harness as `[...wrap, command, ...args]` with the final hook env. It starts with no shell,
|
||||
except Windows script launchers, which go through cmd.exe like any provider launcher
|
||||
(`spawnProcess` quotes each argument). An argument with spaces stays one element. `executable` must
|
||||
be an absolute path.
|
||||
The wrap is never saved on the agent; every open asks the hooks again, and a plugin session reopen
|
||||
reuses the wrap it opened with.
|
||||
|
||||
@@ -486,11 +488,10 @@ reuses the wrap it opened with.
|
||||
registration metadata, so it is in the snapshot before the provider first connects.
|
||||
- **One wrap per open.** A later hook, in the same plugin or a later one, may omit the wrap or return
|
||||
the same value. A different value fails the open.
|
||||
- **Fail closed.** `buildLaunchContext` admits a wrapped open before anything starts. It throws
|
||||
`LaunchWrapUnsupportedError` (`code: "launch_wrap_unsupported"`) when the provider does not declare
|
||||
support, when a plugin provider's live connection lacks `session.launch_wrap`, or on Windows when the
|
||||
wrap executable or provider command is a command script, which would need a shell. A host that
|
||||
predates `wrap` rejects the key: the hook result schema is strict. A missing launcher fails the
|
||||
- **Fail closed.** `buildLaunchContext` admits a wrapped open before any session harness starts. It
|
||||
throws `LaunchWrapUnsupportedError` (`code: "launch_wrap_unsupported"`) when the provider does not
|
||||
declare support, or when a plugin provider's live connection lacks `session.launch_wrap`. A host
|
||||
that predates `wrap` rejects the key: the hook result schema is strict. A missing launcher fails the
|
||||
spawn; nothing retries the bare command.
|
||||
|
||||
Once an open selects a wrap, a supported provider runs that session's harness through it or fails
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, expect, test } from "vitest";
|
||||
import { execCommand, spawnProcess } from "./index.js";
|
||||
import type * as ChildProcess from "node:child_process";
|
||||
import { afterEach, expect, test, vi } from "vitest";
|
||||
import { applyLaunchWrap, execCommand, spawnProcess } from "./index.js";
|
||||
|
||||
// Delegates to the real spawn; a test can capture one call instead of starting a process.
|
||||
const spawnSpy = vi.hoisted(() => ({
|
||||
current: undefined as undefined | ((...args: unknown[]) => unknown),
|
||||
}));
|
||||
vi.mock("node:child_process", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof ChildProcess>();
|
||||
return {
|
||||
...actual,
|
||||
spawn: (...args: Parameters<typeof actual.spawn>) =>
|
||||
spawnSpy.current ? spawnSpy.current(...args) : actual.spawn(...args),
|
||||
};
|
||||
});
|
||||
|
||||
const roots: string[] = [];
|
||||
afterEach(async () => {
|
||||
@@ -51,3 +65,34 @@ test("spawnProcess delivers shell arguments to the real child unchanged", async
|
||||
});
|
||||
expect(JSON.parse(stdout)).toEqual(argumentsToPreserve);
|
||||
});
|
||||
|
||||
test("a Windows command-script wrapper starts through cmd.exe with each argument quoted whole", () => {
|
||||
const platform = Object.getOwnPropertyDescriptor(process, "platform")!;
|
||||
const calls: unknown[][] = [];
|
||||
spawnSpy.current = (...args) => {
|
||||
calls.push(args);
|
||||
return {};
|
||||
};
|
||||
Object.defineProperty(process, "platform", { ...platform, value: "win32" });
|
||||
try {
|
||||
const { command, args } = applyLaunchWrap(
|
||||
["C:\\Program Files\\Sandbox\\run.cmd", "--profile", "work profile"],
|
||||
{ command: "C:\\tools\\agy.cmd", args: ["acp", "--disable-telemetry"] },
|
||||
);
|
||||
spawnProcess(command, args, { stdio: "pipe" });
|
||||
} finally {
|
||||
Object.defineProperty(process, "platform", platform);
|
||||
spawnSpy.current = undefined;
|
||||
}
|
||||
expect(calls).toHaveLength(1);
|
||||
const [command, args, options] = calls[0] as [string, string[], { shell: unknown }];
|
||||
expect(options.shell).toBe(true);
|
||||
expect(command).toBe('"C:\\Program Files\\Sandbox\\run.cmd"');
|
||||
expect(args).toEqual([
|
||||
"--profile",
|
||||
'"work profile"',
|
||||
"C:\\tools\\agy.cmd",
|
||||
"acp",
|
||||
"--disable-telemetry",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -45,18 +45,13 @@ function shouldUseWindowsShell(
|
||||
}
|
||||
|
||||
/**
|
||||
* Put `wrap` in front of a launch as one direct argv exec. A Windows command script on either side
|
||||
* would need a shell to start, so it is rejected instead of being quoted into one.
|
||||
* Put `wrap` in front of a launch. Spawn the result with `spawnProcess`, which runs a Windows
|
||||
* command-script wrapper through cmd.exe with quoted arguments, as for any provider launcher.
|
||||
*/
|
||||
export function applyLaunchWrap(
|
||||
wrap: readonly [string, ...string[]],
|
||||
launch: { command: string; args: readonly string[] },
|
||||
): { command: string; args: string[] } {
|
||||
for (const executable of [wrap[0], launch.command]) {
|
||||
if (isWindowsCommandScript(executable)) {
|
||||
throw new Error(`A launch wrap cannot start ${executable}: a command script needs a shell`);
|
||||
}
|
||||
}
|
||||
return { command: wrap[0], args: [...wrap.slice(1), launch.command, ...launch.args] };
|
||||
}
|
||||
|
||||
|
||||
@@ -16403,21 +16403,3 @@ test("a supporting provider receives the wrap at launch and the record never sto
|
||||
expect(JSON.stringify(await storage.get(created.id))).not.toContain("/opt/sandbox");
|
||||
await manager.closeAgent(created.id);
|
||||
});
|
||||
|
||||
test("a supporting provider rejects a Windows command-script wrap before it starts", async () => {
|
||||
const client = new LaunchWrapRecordingClient(true);
|
||||
const { manager, workdir, hook } = createLaunchWrapManager(client);
|
||||
hook.wrap = ["C:\\tools\\sandbox.cmd"];
|
||||
const platform = Object.getOwnPropertyDescriptor(process, "platform")!;
|
||||
Object.defineProperty(process, "platform", { ...platform, value: "win32" });
|
||||
try {
|
||||
await expect(
|
||||
manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
}),
|
||||
).rejects.toMatchObject({ code: "launch_wrap_unsupported" });
|
||||
} finally {
|
||||
Object.defineProperty(process, "platform", platform);
|
||||
}
|
||||
expect(client.calls.create).toBe(0);
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ import { describeHookAgent, publishAgentStream } from "../plugins/lifecycle/inde
|
||||
import { applyRecordPatch } from "../record-patch.js";
|
||||
import type { PluginSessionOpenRequest } from "@getpaseo/plugin/server";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { basename, extname, resolve } from "node:path";
|
||||
import { basename, resolve } from "node:path";
|
||||
import { stat } from "node:fs/promises";
|
||||
import {
|
||||
AGENT_LIFECYCLE_STATUSES,
|
||||
@@ -6669,7 +6669,7 @@ export class AgentManager {
|
||||
mcpServerOwners = transformed.mcpServerOwners;
|
||||
}
|
||||
// launchAgent discards this open when the wrap is refused, so a running session keeps its tools.
|
||||
if (wrap) await requireLaunchWrap(client, wrap);
|
||||
if (wrap) await requireLaunchWrap(client);
|
||||
}
|
||||
const context: AgentLaunchContext = {
|
||||
agentId,
|
||||
@@ -6861,18 +6861,7 @@ function pluginPromptContext(
|
||||
return appendSystemPrompt?.length ? { appendSystemPrompt } : {};
|
||||
}
|
||||
|
||||
async function requireLaunchWrap(
|
||||
client: AgentClient,
|
||||
wrap: NonNullable<AgentLaunchContext["wrap"]>,
|
||||
): Promise<void> {
|
||||
async function requireLaunchWrap(client: AgentClient): Promise<void> {
|
||||
if (client.supportsLaunchWrap !== true) throw new LaunchWrapUnsupportedError(client.provider);
|
||||
// The wrap is one direct exec; a Windows command script would need a shell to start.
|
||||
const extension = extname(wrap[0]).toLowerCase();
|
||||
if (process.platform === "win32" && (extension === ".cmd" || extension === ".bat")) {
|
||||
throw new LaunchWrapUnsupportedError(
|
||||
client.provider,
|
||||
`A launch wrap cannot start ${wrap[0]} on Windows: a command script needs a shell`,
|
||||
);
|
||||
}
|
||||
await client.requireLaunchWrap?.();
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ test.each([{ title: "Changed" }, { labels: { changed: "true" } }, { background:
|
||||
paseo,
|
||||
),
|
||||
).rejects.toThrow(
|
||||
"agent.open.before hooks can only change env, tools, mcpServers, and appendSystemPrompt",
|
||||
"agent.open.before hooks can only change env, tools, mcpServers, appendSystemPrompt, and wrap",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -285,7 +285,7 @@ export async function validateBeforeResult<Name extends keyof PluginWireBeforeRe
|
||||
const next = beforeSchemas["agent.open.before"].parse(result);
|
||||
if (changesSessionOpenTarget(previous, next)) {
|
||||
throw new Error(
|
||||
"agent.open.before hooks can only change env, tools, mcpServers, and appendSystemPrompt",
|
||||
"agent.open.before hooks can only change env, tools, mcpServers, appendSystemPrompt, and wrap",
|
||||
);
|
||||
}
|
||||
// One wrap per open: a later hook may omit or repeat it, never replace it.
|
||||
|
||||
@@ -49,22 +49,22 @@ Paseo only sees the returned promise, so detached work gets no error reporting a
|
||||
|
||||
## Hooks
|
||||
|
||||
| Hook | Waits | Payload | Handler may change |
|
||||
| ------------------------- | ----- | ----------------------------------------- | -------------------------------------------------------------- |
|
||||
| `workspace.create.before` | yes | `{ request }` | Entire create request |
|
||||
| `workspace.create.after` | no | `{ workspace }` | |
|
||||
| `workspace.archive.after` | no | `{ workspace }` | |
|
||||
| `worktree.create.before` | yes | `{ request }` | Creation options and destination |
|
||||
| `worktree.create.after` | yes | `{ worktree }` | Files in the worktree; throw to abort creation |
|
||||
| `agent.create.before` | yes | `{ request: { config, env?, metadata } }` | Saved config except `cwd`; `env`; `metadata` |
|
||||
| `agent.create.after` | no | `{ agent }` | |
|
||||
| `agent.open.before` | yes | `{ request }` | Launch-only `env`, `appendSystemPrompt`, `tools`, `mcpServers` |
|
||||
| `agent.close.after` | no | `{ agent }` | |
|
||||
| `agent.archive.after` | no | `{ agent, archivedAt }` | |
|
||||
| `agent.turn.before` | no | `{ agent, turnId }` | |
|
||||
| `agent.turn.after` | no | `{ agent, turnId, outcome }` | |
|
||||
| `agent.permission.before` | no | `{ agent, request }` | |
|
||||
| `agent.permission.after` | no | `{ agent, requestId, resolution }` | |
|
||||
| Hook | Waits | Payload | Handler may change |
|
||||
|---------------------------|-------|-------------------------------------------|------------------------------------------------------------------------|
|
||||
| `workspace.create.before` | yes | `{ request }` | Entire create request |
|
||||
| `workspace.create.after` | no | `{ workspace }` | |
|
||||
| `workspace.archive.after` | no | `{ workspace }` | |
|
||||
| `worktree.create.before` | yes | `{ request }` | Creation options and destination |
|
||||
| `worktree.create.after` | yes | `{ worktree }` | Files in the worktree; throw to abort creation |
|
||||
| `agent.create.before` | yes | `{ request: { config, env?, metadata } }` | Saved config except `cwd`; `env`; `metadata` |
|
||||
| `agent.create.after` | no | `{ agent }` | |
|
||||
| `agent.open.before` | yes | `{ request }` | Launch-only `env`, `appendSystemPrompt`, `tools`, `mcpServers`, `wrap` |
|
||||
| `agent.close.after` | no | `{ agent }` | |
|
||||
| `agent.archive.after` | no | `{ agent, archivedAt }` | |
|
||||
| `agent.turn.before` | no | `{ agent, turnId }` | |
|
||||
| `agent.turn.after` | no | `{ agent, turnId, outcome }` | |
|
||||
| `agent.permission.before` | no | `{ agent, request }` | |
|
||||
| `agent.permission.after` | no | `{ agent, requestId, resolution }` | |
|
||||
|
||||
## Shared payloads
|
||||
|
||||
@@ -283,7 +283,7 @@ server.addHook("agent.create.after", async ({ agent }) => {
|
||||
|
||||
## agent.open.before
|
||||
|
||||
Receives `{ request }`; only `env`, `appendSystemPrompt`, `tools`, and `mcpServers` may change, for this launch. All other fields are read-only. A throw, invalid result, or timeout fails the open.
|
||||
Receives `{ request }`; only `env`, `appendSystemPrompt`, `tools`, `mcpServers`, and `wrap` may change, for this launch. All other fields are read-only. A throw, invalid result, or timeout fails the open.
|
||||
|
||||
Do not await a write to the agent being opened: `setMetadata`, `setLabels`, or an option, model, thinking or mode change. The write waits for the open to finish, the open waits for your hook, so the hook times out and the open fails. Start the write without awaiting it; it runs right after the open:
|
||||
|
||||
@@ -316,18 +316,36 @@ server.addHook("agent.open.before", async ({ request }, { paseo }) => {
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Values |
|
||||
| ------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
||||
| `workspaceId` | String or `null` |
|
||||
| `title` | Read-only string or `null`; creation title on create, stored title on resume. |
|
||||
| `background` | Read-only `true` for a [background agent](#background-agents). Fixed at creation. |
|
||||
| `labels` | Read-only string map; creation labels on create, stored labels on resume. |
|
||||
| `metadata` | Read-only JSON map; the [metadata](#metadata) stored on the agent. |
|
||||
| `tools` | Editable `AgentToolDefinition[]`, local to this plugin. See [Attach tools to agents](#attach-tools-to-agents). |
|
||||
| `mcpServers` | Editable launch-only server map, local to this plugin. See [Inject MCP servers](#inject-mcp-servers). |
|
||||
| `reason` | `create`, `resume`, `refresh`, `import` |
|
||||
| `purpose` | `interactive`, `history` |
|
||||
| `env` | Launch override map; excludes the daemon's inherited environment. Replace the map to add, replace, or remove overrides. |
|
||||
| Field | Values |
|
||||
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `workspaceId` | String or `null` |
|
||||
| `title` | Read-only string or `null`; creation title on create, stored title on resume. |
|
||||
| `background` | Read-only `true` for a [background agent](#background-agents). Fixed at creation. |
|
||||
| `labels` | Read-only string map; creation labels on create, stored labels on resume. |
|
||||
| `metadata` | Read-only JSON map; the [metadata](#metadata) stored on the agent. |
|
||||
| `tools` | Editable `AgentToolDefinition[]`, local to this plugin. See [Attach tools to agents](#attach-tools-to-agents). |
|
||||
| `mcpServers` | Editable launch-only server map, local to this plugin. See [Inject MCP servers](#inject-mcp-servers). |
|
||||
| `reason` | `create`, `resume`, `refresh`, `import` |
|
||||
| `purpose` | `interactive`, `history` |
|
||||
| `env` | Launch override map; excludes the daemon's inherited environment. Replace the map to add, replace, or remove overrides. |
|
||||
| `wrap` | Optional `[executable, ...args]` to start the harness behind. See [Run the harness behind a launch wrap](#run-the-harness-behind-a-launch-wrap). |
|
||||
|
||||
### Run the harness behind a launch wrap
|
||||
|
||||
Return `wrap` to start the provider's harness as `[...wrap, command, ...args]`, for example under a sandbox:
|
||||
|
||||
```ts
|
||||
server.addHook("agent.open.before", async ({ request }) => ({
|
||||
...request,
|
||||
wrap: ["/usr/local/bin/sandbox-run", "--profile", "agent"],
|
||||
}));
|
||||
```
|
||||
|
||||
- The executable must be an absolute path. Paseo runs it without a shell, except Windows script launchers, which go through cmd.exe like any provider launcher. Each element stays one argument.
|
||||
- Only a provider whose provider snapshot entry has `launchWrap: true` applies a wrap. Read it with `paseo.providers.snapshot()` in `agent.create.before` and choose a provider there. A wrap for any other provider fails the open; it is never dropped. A host without wrap support rejects the field and fails the open too.
|
||||
- A later hook may omit `wrap` or return the same value. A different value fails the open.
|
||||
- History opens keep the wrap. It is not saved on the agent; every open asks the hooks again.
|
||||
- The wrap covers the session's harness process only. Paseo's host terminal tools, provider availability and catalog probes, and draft discovery run outside it.
|
||||
|
||||
### Append instructions on every session opening
|
||||
|
||||
|
||||
@@ -47,22 +47,22 @@ Paseo 只观察返回的 Promise,因此独立任务没有错误报告,也没
|
||||
|
||||
## 钩子一览 {#hooks}
|
||||
|
||||
| 钩子 | 等待 | 载荷 | 可修改 |
|
||||
| ------------------------- | ---- | ----------------------------------------- | --------------------------------------------------------------- |
|
||||
| `workspace.create.before` | 是 | `{ request }` | 整个创建请求 |
|
||||
| `workspace.create.after` | 否 | `{ workspace }` | |
|
||||
| `workspace.archive.after` | 否 | `{ workspace }` | |
|
||||
| `worktree.create.before` | 是 | `{ request }` | 创建选项和目标路径 |
|
||||
| `worktree.create.after` | 是 | `{ worktree }` | worktree 中的文件;抛出错误中止创建 |
|
||||
| `agent.create.before` | 是 | `{ request: { config, env?, metadata } }` | 除 `cwd` 外的已保存配置;`env`;`metadata` |
|
||||
| `agent.create.after` | 否 | `{ agent }` | |
|
||||
| `agent.open.before` | 是 | `{ request }` | 仅用于启动的 `env`、`appendSystemPrompt`、`tools`、`mcpServers` |
|
||||
| `agent.close.after` | 否 | `{ agent }` | |
|
||||
| `agent.archive.after` | 否 | `{ agent, archivedAt }` | |
|
||||
| `agent.turn.before` | 否 | `{ agent, turnId }` | |
|
||||
| `agent.turn.after` | 否 | `{ agent, turnId, outcome }` | |
|
||||
| `agent.permission.before` | 否 | `{ agent, request }` | |
|
||||
| `agent.permission.after` | 否 | `{ agent, requestId, resolution }` | |
|
||||
| 钩子 | 等待 | 载荷 | 可修改 |
|
||||
|---------------------------|------|-------------------------------------------|-------------------------------------------------------------------------|
|
||||
| `workspace.create.before` | 是 | `{ request }` | 整个创建请求 |
|
||||
| `workspace.create.after` | 否 | `{ workspace }` | |
|
||||
| `workspace.archive.after` | 否 | `{ workspace }` | |
|
||||
| `worktree.create.before` | 是 | `{ request }` | 创建选项和目标路径 |
|
||||
| `worktree.create.after` | 是 | `{ worktree }` | worktree 中的文件;抛出错误中止创建 |
|
||||
| `agent.create.before` | 是 | `{ request: { config, env?, metadata } }` | 除 `cwd` 外的已保存配置;`env`;`metadata` |
|
||||
| `agent.create.after` | 否 | `{ agent }` | |
|
||||
| `agent.open.before` | 是 | `{ request }` | 仅用于启动的 `env`、`appendSystemPrompt`、`tools`、`mcpServers`、`wrap` |
|
||||
| `agent.close.after` | 否 | `{ agent }` | |
|
||||
| `agent.archive.after` | 否 | `{ agent, archivedAt }` | |
|
||||
| `agent.turn.before` | 否 | `{ agent, turnId }` | |
|
||||
| `agent.turn.after` | 否 | `{ agent, turnId, outcome }` | |
|
||||
| `agent.permission.before` | 否 | `{ agent, request }` | |
|
||||
| `agent.permission.after` | 否 | `{ agent, requestId, resolution }` | |
|
||||
|
||||
## 共享载荷 {#shared-payloads}
|
||||
|
||||
@@ -279,7 +279,7 @@ server.addHook("agent.create.after", async ({ agent }) => {
|
||||
|
||||
## agent.open.before {#agentopenbefore}
|
||||
|
||||
收到 `{ request }`,只能修改 `env`、`appendSystemPrompt`、`tools` 和 `mcpServers`,修改只用于此次启动。其他字段只读。抛出错误、无效返回或超时会让打开操作失败。
|
||||
收到 `{ request }`,只能修改 `env`、`appendSystemPrompt`、`tools`、`mcpServers` 和 `wrap`,修改只用于此次启动。其他字段只读。抛出错误、无效返回或超时会让打开操作失败。
|
||||
|
||||
不要 await 对正在打开的 Agent 的写入,例如 `setMetadata`。该写入要等打开完成,而打开在等你的钩子,结果钩子超时,打开失败。启动写入但不要 await,它会在打开完成后立即执行:
|
||||
|
||||
@@ -312,18 +312,36 @@ server.addHook("agent.open.before", async ({ request }, { paseo }) => {
|
||||
}
|
||||
```
|
||||
|
||||
| 字段 | 取值 |
|
||||
| ------------- | -------------------------------------------------------------------------------------------------------- |
|
||||
| `workspaceId` | 字符串或 `null` |
|
||||
| `title` | 只读字符串或 `null`;创建时使用创建请求的标题,恢复时使用已保存的标题。 |
|
||||
| `background` | 只读;[后台 Agent](#background-agents) 为 `true`。在创建时确定。 |
|
||||
| `labels` | 只读的字符串映射;创建时使用创建请求的标签,恢复时使用已保存的标签。 |
|
||||
| `metadata` | 只读的 JSON 映射;Agent 上已保存的[元数据](#metadata)。 |
|
||||
| `tools` | 可编辑的 `AgentToolDefinition[]`,仅包含此插件的工具。参阅[为 Agent 附加工具](#attach-tools-to-agents)。 |
|
||||
| `mcpServers` | 可编辑的服务器映射,仅用于启动且仅包含本插件的条目。参阅[注入 MCP 服务器](#inject-mcp-servers)。 |
|
||||
| `reason` | `create`、`resume`、`refresh`、`import` |
|
||||
| `purpose` | `interactive`、`history` |
|
||||
| `env` | 启动覆盖映射;不包括 daemon 继承的环境变量。替换整个映射即可添加、替换或移除覆盖项。 |
|
||||
| 字段 | 取值 |
|
||||
| ------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `workspaceId` | 字符串或 `null` |
|
||||
| `title` | 只读字符串或 `null`;创建时使用创建请求的标题,恢复时使用已保存的标题。 |
|
||||
| `background` | 只读;[后台 Agent](#background-agents) 为 `true`。在创建时确定。 |
|
||||
| `labels` | 只读的字符串映射;创建时使用创建请求的标签,恢复时使用已保存的标签。 |
|
||||
| `metadata` | 只读的 JSON 映射;Agent 上已保存的[元数据](#metadata)。 |
|
||||
| `tools` | 可编辑的 `AgentToolDefinition[]`,仅包含此插件的工具。参阅[为 Agent 附加工具](#attach-tools-to-agents)。 |
|
||||
| `mcpServers` | 可编辑的服务器映射,仅用于启动且仅包含本插件的条目。参阅[注入 MCP 服务器](#inject-mcp-servers)。 |
|
||||
| `reason` | `create`、`resume`、`refresh`、`import` |
|
||||
| `purpose` | `interactive`、`history` |
|
||||
| `env` | 启动覆盖映射;不包括 daemon 继承的环境变量。替换整个映射即可添加、替换或移除覆盖项。 |
|
||||
| `wrap` | 可选的 `[executable, ...args]`,用它启动 harness。参阅[通过启动包装运行 harness](#run-the-harness-behind-a-launch-wrap)。 |
|
||||
|
||||
### 通过启动包装运行 harness {#run-the-harness-behind-a-launch-wrap}
|
||||
|
||||
返回 `wrap`,让 Provider 的 harness 以 `[...wrap, command, ...args]` 启动,例如在沙盒中运行:
|
||||
|
||||
```ts
|
||||
server.addHook("agent.open.before", async ({ request }) => ({
|
||||
...request,
|
||||
wrap: ["/usr/local/bin/sandbox-run", "--profile", "agent"],
|
||||
}));
|
||||
```
|
||||
|
||||
- 可执行文件必须是绝对路径。Paseo 不经过 shell 运行它;Windows 脚本启动器例外,它和其他 Provider 启动器一样通过 cmd.exe 运行。每个元素保持为一个参数。
|
||||
- 只有 Provider 快照条目中 `launchWrap: true` 的 Provider 才会应用包装。在 `agent.create.before` 中用 `paseo.providers.snapshot()` 读取它,并在那里选择 Provider。为其他 Provider 返回包装会让打开失败,包装绝不会被丢弃。不支持包装的主机会拒绝该字段,同样让打开失败。
|
||||
- 后面的钩子可以省略 `wrap` 或返回相同的值。返回不同的值会让打开失败。
|
||||
- 读取历史的打开也保留包装。包装不会保存在 Agent 上,每次打开都会重新询问钩子。
|
||||
- 包装只覆盖会话的 harness 进程。Paseo 的主机终端工具、Provider 可用性和目录探测以及草稿发现都在包装之外运行。
|
||||
|
||||
### 在每次打开会话时追加指令 {#append-instructions-on-every-session-opening}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user