personal-bot 0.2.11 → 0.2.13
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/.claude-plugin/marketplace.json +18 -0
- package/.claude-plugin/plugin.json +15 -0
- package/CONTEXT.md +11 -5
- package/README.md +45 -14
- package/README.zh-CN.md +45 -14
- package/bin/pbot-pi-acp.mjs +20 -0
- package/docs/README.md +6 -4
- package/docs/adr/0001-claude-skill-discovery.md +3 -0
- package/docs/adr/0002-claude-native-collaboration.md +3 -0
- package/docs/agent-collaboration.md +54 -6
- package/docs/architecture-guidelines.md +1 -1
- package/docs/capability-design.md +15 -3
- package/docs/claude-code-design.md +45 -0
- package/docs/claude-code.md +64 -0
- package/docs/dsh.md +12 -11
- package/docs/file-storage.md +26 -9
- package/docs/history.md +17 -9
- package/docs/interaction-design.md +11 -3
- package/docs/model-context.md +43 -12
- package/docs/model-instruction-guidelines.md +3 -3
- package/docs/release.md +13 -5
- package/docs/technical-design.md +59 -19
- package/docs/workspace-configuration.md +50 -23
- package/hooks/hooks.json +19 -0
- package/lib/claude.d.ts +1 -0
- package/lib/claude.js +20 -0
- package/lib/client.js +41 -8
- package/lib/dsh.js +2 -0
- package/lib/extension/acp-member.d.ts +16 -0
- package/lib/extension/acp-member.js +45 -0
- package/lib/extension/acp-worker.d.ts +1 -0
- package/lib/extension/acp-worker.js +159 -0
- package/lib/extension/claude-hooks.d.ts +15 -0
- package/lib/extension/claude-hooks.js +104 -0
- package/lib/extension/dsh/acp-member.d.ts +4 -0
- package/lib/extension/dsh/acp-member.js +48 -0
- package/lib/extension/dsh/command.js +11 -1
- package/lib/extension/dsh/history.js +1 -1
- package/lib/extension/dsh/management.js +3 -1
- package/lib/extension/dsh/workspace.d.ts +35 -1
- package/lib/extension/dsh/workspace.js +21 -3
- package/lib/integrations/acp/agents.d.ts +24 -0
- package/lib/integrations/acp/agents.js +168 -0
- package/lib/integrations/acp/claude.d.ts +18 -0
- package/lib/integrations/acp/claude.js +33 -0
- package/lib/integrations/acp/connection.d.ts +27 -0
- package/lib/integrations/acp/connection.js +167 -0
- package/lib/integrations/acp/input.d.ts +4 -0
- package/lib/integrations/acp/input.js +45 -0
- package/lib/integrations/acp/launch.d.ts +4 -0
- package/lib/integrations/acp/launch.js +52 -0
- package/lib/integrations/acp/model-selection.d.ts +12 -0
- package/lib/integrations/acp/model-selection.js +65 -0
- package/lib/integrations/agent-resources.d.ts +1 -1
- package/lib/integrations/agent-resources.js +3 -1
- package/lib/integrations/dsh/dsh-agents.d.ts +2 -1
- package/lib/integrations/dsh/dsh-agents.js +4 -0
- package/lib/integrations/dsh/history-summary.js +5 -9
- package/lib/integrations/dsh/history.js +13 -5
- package/lib/integrations/history-summary.d.ts +2 -0
- package/lib/integrations/history-summary.js +21 -10
- package/lib/model/acp.d.ts +59 -0
- package/lib/model/acp.js +1 -0
- package/lib/model/agent.d.ts +15 -1
- package/lib/model/history.d.ts +11 -4
- package/lib/model/workspace-config.d.ts +3 -0
- package/lib/services/agents/acp-run.d.ts +42 -0
- package/lib/services/agents/acp-run.js +149 -0
- package/lib/services/agents/agent-service.d.ts +114 -6
- package/lib/services/agents/agent-service.js +81 -10
- package/lib/services/agents/team-service.js +4 -2
- package/lib/services/history/history-service.d.ts +8 -6
- package/lib/services/history/history-service.js +90 -48
- package/lib/services/workspace/python-environment-service.d.ts +6 -0
- package/lib/services/workspace/python-environment-service.js +25 -9
- package/lib/services/workspace/workspace-config.js +12 -1
- package/lib/storage/acp-files.d.ts +9 -0
- package/lib/storage/acp-files.js +50 -0
- package/lib/storage/agent-files.d.ts +5 -4
- package/lib/storage/agent-files.js +14 -2
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +26 -15
- package/lib/tools/agents/actions.d.ts +16 -2
- package/lib/tools/agents/actions.js +3 -1
- package/lib/tools/agents/contract.d.ts +48 -3
- package/lib/tools/agents/contract.js +15 -9
- package/lib/tools/agents/dsh-contract.d.ts +8 -15
- package/lib/tools/agents/dsh-contract.js +12 -8
- package/lib/tools/history/contract.d.ts +7 -7
- package/lib/tools/history/contract.js +2 -2
- package/lib/ui/dsh/management.js +37 -9
- package/npm-shrinkwrap.json +975 -51
- package/package.json +40 -29
- package/python/README.md +17 -14
- package/resources/agents/coordinator.md +1 -1
- package/resources/claude/agents/general-purpose.md +12 -0
- package/resources/claude/skills/pbot/SKILL.md +17 -0
- package/resources/prompts/claude-coordinator.md +1 -0
- package/resources/prompts/native-coordinator.md +1 -0
- package/resources/prompts/workspace.md +2 -2
- package/resources/references/compute.md +2 -2
- package/resources/references/task-conductor.md +3 -2
- package/resources/skills/.claude-plugin/plugin.json +4 -0
- package/resources/skills/provider-connections/SKILL.md +17 -1
- package/scripts/README.md +29 -5
- package/src/claude.ts +19 -0
- package/src/dsh.ts +1 -0
- package/src/extension/acp-member.ts +44 -0
- package/src/extension/acp-worker.ts +124 -0
- package/src/extension/agent-events.ts +28 -3
- package/src/extension/agents-command.ts +33 -5
- package/src/extension/claude-hooks.ts +94 -0
- package/src/extension/dsh/acp-member.ts +44 -0
- package/src/extension/dsh/command.ts +10 -1
- package/src/extension/dsh/history.ts +1 -1
- package/src/extension/dsh/management.ts +2 -1
- package/src/extension/dsh/workspace.ts +21 -3
- package/src/extension/lifecycle.ts +2 -2
- package/src/extension/pi-acp-member.ts +64 -0
- package/src/integrations/acp/agents.ts +118 -0
- package/src/integrations/acp/claude.ts +40 -0
- package/src/integrations/acp/connection.ts +152 -0
- package/src/integrations/acp/input.ts +39 -0
- package/src/integrations/acp/launch.ts +50 -0
- package/src/integrations/acp/model-selection.ts +66 -0
- package/src/integrations/agent-resources.ts +2 -1
- package/src/integrations/dsh/dsh-agents.ts +4 -1
- package/src/integrations/dsh/history-summary.ts +5 -9
- package/src/integrations/dsh/history.ts +12 -6
- package/src/integrations/history-summary.ts +18 -8
- package/src/integrations/pi/history.ts +16 -15
- package/src/integrations/pi/pi-agents.ts +4 -1
- package/src/model/acp.ts +26 -0
- package/src/model/agent.ts +7 -1
- package/src/model/history.ts +12 -4
- package/src/model/workspace-config.ts +4 -0
- package/src/pbot.ts +5 -4
- package/src/services/agents/acp-run.ts +123 -0
- package/src/services/agents/agent-service.ts +85 -12
- package/src/services/agents/team-service.ts +3 -2
- package/src/services/history/history-service.ts +82 -41
- package/src/services/workspace/python-environment-service.ts +26 -9
- package/src/services/workspace/workspace-config.ts +10 -1
- package/src/storage/acp-files.ts +50 -0
- package/src/storage/agent-files.ts +15 -4
- package/src/storage/history-files.ts +20 -11
- package/src/tools/agents/actions.ts +4 -2
- package/src/tools/agents/contract.ts +16 -9
- package/src/tools/agents/dsh-contract.ts +12 -8
- package/src/tools/history/contract.ts +2 -2
- package/src/ui/dsh/management.ts +32 -9
|
@@ -7,6 +7,12 @@ export declare class PythonEnvironmentService {
|
|
|
7
7
|
directory?: string;
|
|
8
8
|
error?: string;
|
|
9
9
|
};
|
|
10
|
+
private run;
|
|
11
|
+
inspect(signal?: AbortSignal): Promise<{
|
|
12
|
+
state: "unprepared" | "preparing" | "ready" | "error";
|
|
13
|
+
directory?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
}>;
|
|
10
16
|
setup(signal?: AbortSignal): Promise<{
|
|
11
17
|
directory: string;
|
|
12
18
|
python: string;
|
|
@@ -12,6 +12,29 @@ export class PythonEnvironmentService {
|
|
|
12
12
|
this.root = root;
|
|
13
13
|
}
|
|
14
14
|
get status() { return { ...this.#status }; }
|
|
15
|
+
async run(checkOnly, signal) {
|
|
16
|
+
const environment = {};
|
|
17
|
+
for (const [key, value] of Object.entries(process.env))
|
|
18
|
+
if (value !== undefined)
|
|
19
|
+
environment[key] = value;
|
|
20
|
+
const result = await runCommand("/bin/sh", ["-c", 'exec "$(command -v python3 || command -v python)" "$@"',
|
|
21
|
+
"pbot-python", "-I", "-B", join(resourceRoot, "../scripts/setup-python.py"), ...(checkOnly ? ["--check"] : [])], undefined, this.root, environment, signal, { timeoutMs: 15 * 60_000 });
|
|
22
|
+
signal.throwIfAborted();
|
|
23
|
+
requireThat(result.success && object(result.data) && typeof result.data.directory === "string" && typeof result.data.python === "string", "共享 Python 环境未就绪;修复后执行 Python 准备入口。\n" + JSON.stringify(result.data).slice(-6000));
|
|
24
|
+
return { directory: result.data.directory, python: result.data.python, action: result.data.action };
|
|
25
|
+
}
|
|
26
|
+
async inspect(signal) {
|
|
27
|
+
const cancel = signal ? AbortSignal.any([this.#shutdown.signal, signal]) : this.#shutdown.signal;
|
|
28
|
+
try {
|
|
29
|
+
const result = await this.run(true, cancel);
|
|
30
|
+
this.#status = result.action === "verify" ? { state: "ready", directory: result.directory } : { state: "unprepared" };
|
|
31
|
+
return this.status;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.#status = { state: "error", error: error instanceof Error ? error.message : String(error) };
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
15
38
|
setup(signal) {
|
|
16
39
|
const cancel = signal ? AbortSignal.any([this.#shutdown.signal, signal]) : this.#shutdown.signal;
|
|
17
40
|
if (cancel.aborted)
|
|
@@ -21,15 +44,8 @@ export class PythonEnvironmentService {
|
|
|
21
44
|
this.#status = { state: "preparing" };
|
|
22
45
|
this.#pending = (async () => {
|
|
23
46
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
if (value !== undefined)
|
|
27
|
-
environment[key] = value;
|
|
28
|
-
const result = await runCommand("/bin/sh", ["-c", 'exec "$(command -v python3 || command -v python)" "$@"',
|
|
29
|
-
"pbot-python", "-I", "-B", join(resourceRoot, "../scripts/setup-python.py")], undefined, this.root, environment, cancel, { timeoutMs: 15 * 60_000 });
|
|
30
|
-
cancel.throwIfAborted();
|
|
31
|
-
requireThat(result.success && object(result.data) && typeof result.data.directory === "string" && typeof result.data.python === "string", "共享 Python 环境未就绪;修复后执行 /pbot python setup。\n" + JSON.stringify(result.data).slice(-6000));
|
|
32
|
-
const ready = { directory: result.data.directory, python: result.data.python };
|
|
47
|
+
const result = await this.run(false, cancel);
|
|
48
|
+
const ready = { directory: result.directory, python: result.python };
|
|
33
49
|
this.#status = { state: "ready", directory: ready.directory };
|
|
34
50
|
return ready;
|
|
35
51
|
}
|
|
@@ -6,6 +6,16 @@ function config(value) {
|
|
|
6
6
|
if (!object(value) || value.enabled !== undefined && typeof value.enabled !== "boolean") {
|
|
7
7
|
throw new Error("配置必须是 JSON 对象,enabled 必须是布尔值。");
|
|
8
8
|
}
|
|
9
|
+
if (value.acp !== undefined) {
|
|
10
|
+
if (!object(value.acp) || Object.keys(value.acp).some(key => !["pi", "dsh", "claude"].includes(key)))
|
|
11
|
+
throw new Error("acp 仅接受 pi、dsh 和 claude 启动配置。");
|
|
12
|
+
for (const command of Object.values(value.acp)) {
|
|
13
|
+
if (!object(command) || typeof command.command !== "string" || !command.command.trim() || command.command.includes("\0") ||
|
|
14
|
+
!Array.isArray(command.args) || command.args.some(arg => typeof arg !== "string" || arg.includes("\0")) ||
|
|
15
|
+
Object.keys(command).some(key => !["command", "args"].includes(key)))
|
|
16
|
+
throw new Error("ACP 启动配置需要 command 和 args 字符串数组。");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
9
19
|
return value;
|
|
10
20
|
}
|
|
11
21
|
export function workspaceConfigPath(root) {
|
|
@@ -25,7 +35,8 @@ export async function readWorkspaceConfig(root) {
|
|
|
25
35
|
}
|
|
26
36
|
try {
|
|
27
37
|
const value = config(JSON.parse(content));
|
|
28
|
-
|
|
38
|
+
const settings = value;
|
|
39
|
+
return { path, present: true, enabled: settings.enabled === true, ...(settings.acp ? { acp: settings.acp } : {}) };
|
|
29
40
|
}
|
|
30
41
|
catch (error) {
|
|
31
42
|
return { path, present: true, enabled: false, error: `工作区配置无效 ${path}: ${String(error)}` };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AcpAnswer, AcpInput, AcpPermission, AcpPermissionReply, AcpModelState, AcpProcess, AcpReport, AcpSessionReference } from "../model/acp.js";
|
|
2
|
+
export declare function acpReference(value: unknown): AcpSessionReference;
|
|
3
|
+
export declare function acpModelState(value: unknown): AcpModelState;
|
|
4
|
+
export declare function acpProcess(value: unknown): AcpProcess;
|
|
5
|
+
export declare function acpInput(value: unknown): AcpInput;
|
|
6
|
+
export declare function acpAnswer(value: unknown): AcpAnswer;
|
|
7
|
+
export declare function acpReport(value: unknown): AcpReport;
|
|
8
|
+
export declare function acpPermission(value: unknown): AcpPermission;
|
|
9
|
+
export declare function acpPermissionReply(value: unknown): AcpPermissionReply;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { object } from "../common/json.js";
|
|
3
|
+
import { requireThat } from "../common/validation.js";
|
|
4
|
+
import { fileId } from "./file-access.js";
|
|
5
|
+
const text = (value) => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
6
|
+
export function acpReference(value) {
|
|
7
|
+
requireThat(object(value) && value.host === "acp" && ["pi", "dsh", "claude"].includes(String(value.backend)) &&
|
|
8
|
+
text(value.command) && isAbsolute(value.command) && Array.isArray(value.args) && value.args.every(arg => typeof arg === "string" && !arg.includes("\0")) &&
|
|
9
|
+
(value.sessionId === null || text(value.sessionId)), "ACP 会话引用无效。");
|
|
10
|
+
const capabilities = value.capabilities;
|
|
11
|
+
if (capabilities !== undefined)
|
|
12
|
+
requireThat(object(capabilities) &&
|
|
13
|
+
["resume", "load", "close"].every(key => typeof capabilities[key] === "boolean"), "ACP 会话能力无效。");
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export function acpModelState(value) {
|
|
17
|
+
requireThat(object(value) && text(value.generation) && ["provider", "model", "resolvedModel", "thinking"].every(key => value[key] === undefined || text(value[key])), "ACP 模型选择无效。");
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
export function acpProcess(value) {
|
|
21
|
+
requireThat(object(value) && text(value.generation) && Number.isSafeInteger(value.pid) && Number(value.pid) > 1 &&
|
|
22
|
+
typeof value.startedAt === "number" && Number.isFinite(value.startedAt), "ACP 进程记录无效。");
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
export function acpInput(value) {
|
|
26
|
+
requireThat(object(value) && text(value.generation) && text(value.requestId), "ACP 输入关联无效。");
|
|
27
|
+
fileId(value.requestId);
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
export function acpAnswer(value) {
|
|
31
|
+
acpInput(value);
|
|
32
|
+
requireThat(object(value) && typeof value.answer === "string" && ["completed", "failed", "cancelled"].includes(String(value.state)) &&
|
|
33
|
+
(value.error === undefined || typeof value.error === "string"), "ACP 最终回答无效。");
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
export function acpReport(value) {
|
|
37
|
+
requireThat(object(value) && text(value.generation) && text(value.cycleId) && typeof value.text === "string", "ACP 周期报告无效。");
|
|
38
|
+
fileId(value.cycleId);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
export function acpPermission(value) {
|
|
42
|
+
acpInput(value);
|
|
43
|
+
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every(option => object(option) && text(option.optionId) && text(option.name) && ["allow_once", "allow_always", "reject_once", "reject_always"].includes(String(option.kind))), "ACP 确认请求无效。");
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
export function acpPermissionReply(value) {
|
|
47
|
+
acpInput(value);
|
|
48
|
+
requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP 确认答复无效。");
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { AgentDescriptor, AgentLaunch, AgentMessage, AgentStatus, AgentCycle, AgentSessionRef, AgentSessionReference } from "../model/agent.js";
|
|
1
|
+
import type { AgentDescriptor, AgentLaunch, AgentMessage, AgentStatus, AgentCycle, AgentSessionRef, AgentSessionReference, NativeAgentHost } from "../model/agent.js";
|
|
2
|
+
import type { AcpSessionReference } from "../model/acp.js";
|
|
2
3
|
export declare function descriptor(v: unknown): AgentDescriptor;
|
|
3
4
|
export declare function sessionRef(v: unknown): AgentSessionRef;
|
|
4
5
|
export declare function launch(v: unknown): AgentLaunch;
|
|
@@ -8,15 +9,15 @@ export declare function status(v: unknown): AgentStatus;
|
|
|
8
9
|
export declare class AgentFiles {
|
|
9
10
|
#private;
|
|
10
11
|
readonly root: string;
|
|
11
|
-
readonly host:
|
|
12
|
-
constructor(root: string, host?:
|
|
12
|
+
readonly host: NativeAgentHost;
|
|
13
|
+
constructor(root: string, host?: NativeAgentHost);
|
|
13
14
|
check(): void;
|
|
14
15
|
fail(error: unknown): void;
|
|
15
16
|
directory(id: string): string;
|
|
16
17
|
read<T>(id: string, path: string, parse: (v: unknown) => T): T;
|
|
17
18
|
optional<T>(id: string, path: string, parse: (v: unknown) => T): T | undefined;
|
|
18
19
|
write<T>(id: string, path: string, value: T, parse: (v: unknown) => T, create?: boolean): void;
|
|
19
|
-
create(value: AgentDescriptor, run: AgentLaunch): void;
|
|
20
|
+
create(value: AgentDescriptor, run: AgentLaunch, acp?: AcpSessionReference): void;
|
|
20
21
|
list(): AgentDescriptor[];
|
|
21
22
|
messages(id: string): AgentMessage[];
|
|
22
23
|
completions(id: string): AgentCycle[];
|
|
@@ -5,6 +5,7 @@ import { canonical, object } from "../common/json.js";
|
|
|
5
5
|
import { requireThat } from "../common/validation.js";
|
|
6
6
|
import { readJsonFile, writeJsonFile } from "./atomic-json.js";
|
|
7
7
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
8
|
+
import { acpReference } from "./acp-files.js";
|
|
8
9
|
const text = (v) => typeof v === "string" && v.length > 0;
|
|
9
10
|
const number = (v) => typeof v === "number" && Number.isFinite(v);
|
|
10
11
|
export function descriptor(v) {
|
|
@@ -52,6 +53,7 @@ export class AgentFiles {
|
|
|
52
53
|
constructor(root, host = "pi") {
|
|
53
54
|
this.root = root;
|
|
54
55
|
this.host = host;
|
|
56
|
+
requireThat(host === "pi" || host === "dsh", "子会话所属宿主无效。");
|
|
55
57
|
}
|
|
56
58
|
check() { if (this.#failure)
|
|
57
59
|
throw this.#failure; }
|
|
@@ -81,15 +83,22 @@ export class AgentFiles {
|
|
|
81
83
|
}
|
|
82
84
|
requireThat(published, "子会话文件已存在。");
|
|
83
85
|
}
|
|
84
|
-
create(value, run) {
|
|
86
|
+
create(value, run, acp) {
|
|
85
87
|
this.check();
|
|
88
|
+
if (acp)
|
|
89
|
+
acpReference(acp);
|
|
86
90
|
mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
87
91
|
mkdirSync(this.directory(value.agentId), { mode: 0o700 });
|
|
88
92
|
for (const dir of ["inbox", "completions"])
|
|
89
93
|
privateDirectory(this.directory(value.agentId), dir);
|
|
90
94
|
this.write(value.agentId, "descriptor.json", value, descriptor, true);
|
|
91
95
|
this.write(value.agentId, "launch.json", run, launch, true);
|
|
92
|
-
if (
|
|
96
|
+
if (acp) {
|
|
97
|
+
for (const dir of ["reports", "permissions"])
|
|
98
|
+
privateDirectory(this.directory(value.agentId), dir);
|
|
99
|
+
this.write(value.agentId, "acp-session.json", acp, acpReference, true);
|
|
100
|
+
}
|
|
101
|
+
else if (this.host === "pi")
|
|
93
102
|
this.write(value.agentId, "session-ref.json", { file: null }, sessionRef, true);
|
|
94
103
|
else
|
|
95
104
|
this.write(value.agentId, "native-session.json", { host: "dsh", sessionId: value.agentId }, dshSessionRef, true);
|
|
@@ -111,6 +120,9 @@ export class AgentFiles {
|
|
|
111
120
|
.map(n => this.read(id, "completions/" + n, cycle)).sort((a, b) => (a.finishedAt ?? 0) - (b.finishedAt ?? 0));
|
|
112
121
|
}
|
|
113
122
|
reference(id) {
|
|
123
|
+
const acp = this.optional(id, "acp-session.json", acpReference);
|
|
124
|
+
if (acp)
|
|
125
|
+
return acp;
|
|
114
126
|
if (this.host === "pi")
|
|
115
127
|
return { host: "pi", file: this.session(id) };
|
|
116
128
|
const ref = this.read(id, "native-session.json", dshSessionRef);
|
|
@@ -5,7 +5,8 @@ export declare class HistoryFiles {
|
|
|
5
5
|
readonly host: HistoryHost;
|
|
6
6
|
constructor(directory: string, host?: HistoryHost);
|
|
7
7
|
get warnings(): readonly string[];
|
|
8
|
-
|
|
8
|
+
/** A peer can include its legacy directory without migrating or modifying either source. */
|
|
9
|
+
list(legacyRoot?: string): HistoryRecord[];
|
|
9
10
|
/** Publish each legacy archive with its directory's host before removing the old copy. */
|
|
10
11
|
migrate(root: string): void;
|
|
11
12
|
/** The callback is synchronous: no SDK reads or model work can hold this source's write lock. */
|
|
@@ -6,7 +6,7 @@ import { internalPath, readJsonFile, syncDirectory, writeJsonFile } from "./atom
|
|
|
6
6
|
import { fileId } from "./file-access.js";
|
|
7
7
|
const strings = (value) => Array.isArray(value) && value.every(item => typeof item === "string");
|
|
8
8
|
function record(value) {
|
|
9
|
-
requireThat(object(value) && (value.host === "pi" || value.host === "dsh") &&
|
|
9
|
+
requireThat(object(value) && (value.host === "pi" || value.host === "dsh" || value.host === "claude") &&
|
|
10
10
|
typeof value.id === "string" && typeof value.sessionId === "string" &&
|
|
11
11
|
typeof value.name === "string" && Array.isArray(value.nodes), "历史索引无效。");
|
|
12
12
|
for (const node of value.nodes)
|
|
@@ -28,26 +28,37 @@ export class HistoryFiles {
|
|
|
28
28
|
this.host = host;
|
|
29
29
|
}
|
|
30
30
|
get warnings() { return this.#warnings; }
|
|
31
|
-
|
|
31
|
+
/** A peer can include its legacy directory without migrating or modifying either source. */
|
|
32
|
+
list(legacyRoot) {
|
|
32
33
|
this.#warnings = [];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
const records = new Map();
|
|
35
|
+
const directories = [this.directory, ...(legacyRoot && this.host !== "claude" ? [join(legacyRoot, "." + this.host, "pbot/history")] : [])];
|
|
36
|
+
for (const directory of directories) {
|
|
37
|
+
if (!existsSync(directory))
|
|
38
|
+
continue;
|
|
39
|
+
for (const name of readdirSync(directory).filter(name => name.endsWith(".json"))) {
|
|
40
|
+
try {
|
|
41
|
+
const value = readJsonFile(directory, name, value => {
|
|
42
|
+
if (directory === this.directory)
|
|
43
|
+
return record(value);
|
|
44
|
+
requireThat(object(value) && (value.host === undefined || value.host === this.host), "旧历史归档与来源目录不匹配。");
|
|
45
|
+
return record({ ...value, host: this.host });
|
|
46
|
+
});
|
|
47
|
+
requireThat(name === fileId(value.id) + ".json", "历史文件名与根 ID 不匹配。");
|
|
48
|
+
if (value.host === this.host && !records.has(value.id))
|
|
49
|
+
records.set(value.id, value);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.#warnings.push(join(directory, name) + ": " + String(error));
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
|
-
return records;
|
|
56
|
+
return [...records.values()];
|
|
48
57
|
}
|
|
49
58
|
/** Publish each legacy archive with its directory's host before removing the old copy. */
|
|
50
59
|
migrate(root) {
|
|
60
|
+
if (this.host !== "pi" && this.host !== "dsh")
|
|
61
|
+
return;
|
|
51
62
|
const directory = join(root, "." + this.host, "pbot/history");
|
|
52
63
|
if (!existsSync(directory))
|
|
53
64
|
return;
|
|
@@ -16,18 +16,32 @@ export declare function executeAgent(service: AgentService, input: AgentInput, o
|
|
|
16
16
|
} | {
|
|
17
17
|
details: {
|
|
18
18
|
agentReadKeys?: string[];
|
|
19
|
+
backend?: "pi" | "dsh" | "claude";
|
|
19
20
|
error?: string;
|
|
21
|
+
capabilities?: {
|
|
22
|
+
steer: boolean;
|
|
23
|
+
resume: boolean;
|
|
24
|
+
team: boolean;
|
|
25
|
+
transcript: boolean;
|
|
26
|
+
};
|
|
20
27
|
requestId?: string;
|
|
21
28
|
cycle?: {
|
|
22
29
|
error?: string;
|
|
23
30
|
finishedAt?: number;
|
|
24
|
-
state: "
|
|
31
|
+
state: "completed" | "failed" | "cancelled" | "running" | "interrupted";
|
|
25
32
|
startedAt: number;
|
|
26
33
|
cycleId: string;
|
|
27
34
|
requestIds: string[];
|
|
28
35
|
source: "parent" | "interactive" | "mixed";
|
|
29
36
|
};
|
|
37
|
+
selection?: {
|
|
38
|
+
provider?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
resolvedModel?: string;
|
|
41
|
+
thinking?: string;
|
|
42
|
+
};
|
|
30
43
|
report?: string;
|
|
44
|
+
transport?: "acp" | "native";
|
|
31
45
|
messageStatus?: "queued";
|
|
32
46
|
cycles?: {
|
|
33
47
|
state: string;
|
|
@@ -36,10 +50,10 @@ export declare function executeAgent(service: AgentService, input: AgentInput, o
|
|
|
36
50
|
totalLength?: number;
|
|
37
51
|
nextOffset?: number | null;
|
|
38
52
|
state: "starting" | "busy" | "idle" | "stopping" | "stopped" | "error";
|
|
53
|
+
name: string;
|
|
39
54
|
agentId: string;
|
|
40
55
|
cwd: string;
|
|
41
56
|
createdAt: number;
|
|
42
|
-
name: string;
|
|
43
57
|
activity: string;
|
|
44
58
|
owned: boolean;
|
|
45
59
|
};
|
|
@@ -4,6 +4,8 @@ function agentOutput(view) {
|
|
|
4
4
|
return {
|
|
5
5
|
agentId: view.agentId, name: view.name, cwd: view.cwd, createdAt: view.createdAt,
|
|
6
6
|
owned: view.owned, state: view.state, activity: view.activity,
|
|
7
|
+
...(view.backend ? { backend: view.backend, transport: view.transport, capabilities: view.capabilities } : {}),
|
|
8
|
+
...(view.selection ? { selection: view.selection } : {}),
|
|
7
9
|
...(c ? { cycle: { cycleId: c.cycleId, startedAt: c.startedAt, state: c.state, requestIds: c.requestIds, source: c.source,
|
|
8
10
|
...(c.finishedAt === undefined ? {} : { finishedAt: c.finishedAt }), ...(c.error === undefined ? {} : { error: c.error }) } } : {}),
|
|
9
11
|
...(view.error === undefined ? {} : { error: view.error }),
|
|
@@ -20,7 +22,7 @@ export async function executeAgent(service, input, owner, defaults = {}) {
|
|
|
20
22
|
switch (input.action) {
|
|
21
23
|
case "start": {
|
|
22
24
|
const { action: _action, ...supplied } = input;
|
|
23
|
-
value = await service.start({ ...defaults, ...supplied }, owner);
|
|
25
|
+
value = await service.start({ ...(supplied.backend ? {} : defaults), ...supplied }, owner);
|
|
24
26
|
break;
|
|
25
27
|
}
|
|
26
28
|
case "list": return markdownResult({ agents: service.list(owner).map(agentOutput) }, "子会话列表");
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
export declare const agentDescription = "\u59D4\u6D3E\u4E13\u5BB6\u5E76\u7EE7\u7EED\u5BF9\u8BDD\u3002start \u542F\u52A8\u540E\u5373\u8FD4\u56DE\uFF0C\u5B8C\u6210\u81EA\u52A8\u901A\u77E5\uFF0C\u65E0\u9700\u8F6E\u8BE2\uFF1B\u7701\u7565\u521D\u59CB\u8F93\u5165\u65F6\u5F85\u547D\u3002send \u7EE7\u7EED\u5BF9\u8BDD\uFF0C\u56E2\u961F\u5360\u7528\u671F\u95F4\u4E0D\u53EF\u79C1\u4EBA send\u3002status \u67E5\u770B\u72B6\u6001\uFF0Cread \u8BFB\u53D6\u62A5\u544A\uFF1B\u8BFB\u53D6\u5DF2\u7ED3\u675F\u5468\u671F\u5373\u9886\u53D6\u5176\u901A\u77E5\uFF0C\u5305\u62EC\u90E8\u5206\u8BFB\u53D6\u3002\u7EED\u8BFB\u56FA\u5B9A cycle.cycleId \u5E76\u4F7F\u7528 nextOffset\u3002state \u8868\u793A\u6267\u884C\u72B6\u6001\uFF0Ccycle.state \u8868\u793A\u5DE5\u4F5C\u7ED3\u679C\uFF0Cqueued \u53EA\u8868\u793A\u5165\u961F\u3002stop \u4FDD\u7559\u5386\u53F2\uFF0Cresume \u643A\u65B0 message \u7EE7\u7EED\u3002\u6BCF\u4E2A\u7236\u4F1A\u8BDD\u6700\u591A 50 \u4E2A\u5B58\u6D3B\u4E13\u5BB6\uFF0C\u7A7A\u95F2\u4E5F\u8BA1\u5165\u3002";
|
|
3
3
|
export declare const agentStartOptions: {
|
|
4
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
4
5
|
name: Type.TOptional<Type.TString>;
|
|
5
6
|
message: Type.TOptional<Type.TString>;
|
|
6
7
|
files: Type.TOptional<Type.TArray<Type.TString>>;
|
|
7
8
|
prompts: Type.TOptional<Type.TArray<Type.TString>>;
|
|
8
9
|
provider: Type.TOptional<Type.TString>;
|
|
9
10
|
model: Type.TOptional<Type.TString>;
|
|
10
|
-
thinking: Type.TOptional<Type.
|
|
11
|
+
thinking: Type.TOptional<Type.TString>;
|
|
11
12
|
cwd: Type.TOptional<Type.TString>;
|
|
12
13
|
tools: Type.TOptional<Type.TArray<Type.TString>>;
|
|
13
14
|
noExtensions: Type.TOptional<Type.TBoolean>;
|
|
@@ -20,13 +21,14 @@ export declare const agentParametersSchema: Type.TObject<{
|
|
|
20
21
|
cycleId: Type.TOptional<Type.TString>;
|
|
21
22
|
offset: Type.TOptional<Type.TInteger>;
|
|
22
23
|
limit: Type.TOptional<Type.TInteger>;
|
|
24
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
23
25
|
name: Type.TOptional<Type.TString>;
|
|
24
26
|
message: Type.TOptional<Type.TString>;
|
|
25
27
|
files: Type.TOptional<Type.TArray<Type.TString>>;
|
|
26
28
|
prompts: Type.TOptional<Type.TArray<Type.TString>>;
|
|
27
29
|
provider: Type.TOptional<Type.TString>;
|
|
28
30
|
model: Type.TOptional<Type.TString>;
|
|
29
|
-
thinking: Type.TOptional<Type.
|
|
31
|
+
thinking: Type.TOptional<Type.TString>;
|
|
30
32
|
cwd: Type.TOptional<Type.TString>;
|
|
31
33
|
tools: Type.TOptional<Type.TArray<Type.TString>>;
|
|
32
34
|
noExtensions: Type.TOptional<Type.TBoolean>;
|
|
@@ -37,13 +39,14 @@ export declare const agentParametersSchema: Type.TObject<{
|
|
|
37
39
|
agentId: Type.TOptional<Type.TString>;
|
|
38
40
|
}>;
|
|
39
41
|
export declare const agentActionSchema: Type.TUnion<[Type.TObject<{
|
|
42
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
40
43
|
name: Type.TOptional<Type.TString>;
|
|
41
44
|
message: Type.TOptional<Type.TString>;
|
|
42
45
|
files: Type.TOptional<Type.TArray<Type.TString>>;
|
|
43
46
|
prompts: Type.TOptional<Type.TArray<Type.TString>>;
|
|
44
47
|
provider: Type.TOptional<Type.TString>;
|
|
45
48
|
model: Type.TOptional<Type.TString>;
|
|
46
|
-
thinking: Type.TOptional<Type.
|
|
49
|
+
thinking: Type.TOptional<Type.TString>;
|
|
47
50
|
cwd: Type.TOptional<Type.TString>;
|
|
48
51
|
tools: Type.TOptional<Type.TArray<Type.TString>>;
|
|
49
52
|
noExtensions: Type.TOptional<Type.TBoolean>;
|
|
@@ -81,6 +84,20 @@ export declare const agentViewSchema: Type.TObject<{
|
|
|
81
84
|
name: Type.TString;
|
|
82
85
|
cwd: Type.TString;
|
|
83
86
|
createdAt: Type.TNumber;
|
|
87
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
88
|
+
transport: Type.TOptional<Type.TUnion<[Type.TLiteral<"native">, Type.TLiteral<"acp">]>>;
|
|
89
|
+
selection: Type.TOptional<Type.TObject<{
|
|
90
|
+
provider: Type.TOptional<Type.TString>;
|
|
91
|
+
model: Type.TOptional<Type.TString>;
|
|
92
|
+
resolvedModel: Type.TOptional<Type.TString>;
|
|
93
|
+
thinking: Type.TOptional<Type.TString>;
|
|
94
|
+
}>>;
|
|
95
|
+
capabilities: Type.TOptional<Type.TObject<{
|
|
96
|
+
steer: Type.TBoolean;
|
|
97
|
+
resume: Type.TBoolean;
|
|
98
|
+
team: Type.TBoolean;
|
|
99
|
+
transcript: Type.TBoolean;
|
|
100
|
+
}>>;
|
|
84
101
|
owned: Type.TBoolean;
|
|
85
102
|
state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"busy">, Type.TLiteral<"idle">, Type.TLiteral<"stopping">, Type.TLiteral<"stopped">, Type.TLiteral<"error">]>;
|
|
86
103
|
activity: Type.TString;
|
|
@@ -109,6 +126,20 @@ export declare const agentResultSchema: Type.TUnion<[Type.TObject<{
|
|
|
109
126
|
name: Type.TString;
|
|
110
127
|
cwd: Type.TString;
|
|
111
128
|
createdAt: Type.TNumber;
|
|
129
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
130
|
+
transport: Type.TOptional<Type.TUnion<[Type.TLiteral<"native">, Type.TLiteral<"acp">]>>;
|
|
131
|
+
selection: Type.TOptional<Type.TObject<{
|
|
132
|
+
provider: Type.TOptional<Type.TString>;
|
|
133
|
+
model: Type.TOptional<Type.TString>;
|
|
134
|
+
resolvedModel: Type.TOptional<Type.TString>;
|
|
135
|
+
thinking: Type.TOptional<Type.TString>;
|
|
136
|
+
}>>;
|
|
137
|
+
capabilities: Type.TOptional<Type.TObject<{
|
|
138
|
+
steer: Type.TBoolean;
|
|
139
|
+
resume: Type.TBoolean;
|
|
140
|
+
team: Type.TBoolean;
|
|
141
|
+
transcript: Type.TBoolean;
|
|
142
|
+
}>>;
|
|
112
143
|
owned: Type.TBoolean;
|
|
113
144
|
state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"busy">, Type.TLiteral<"idle">, Type.TLiteral<"stopping">, Type.TLiteral<"stopped">, Type.TLiteral<"error">]>;
|
|
114
145
|
activity: Type.TString;
|
|
@@ -137,6 +168,20 @@ export declare const agentResultSchema: Type.TUnion<[Type.TObject<{
|
|
|
137
168
|
name: Type.TString;
|
|
138
169
|
cwd: Type.TString;
|
|
139
170
|
createdAt: Type.TNumber;
|
|
171
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
172
|
+
transport: Type.TOptional<Type.TUnion<[Type.TLiteral<"native">, Type.TLiteral<"acp">]>>;
|
|
173
|
+
selection: Type.TOptional<Type.TObject<{
|
|
174
|
+
provider: Type.TOptional<Type.TString>;
|
|
175
|
+
model: Type.TOptional<Type.TString>;
|
|
176
|
+
resolvedModel: Type.TOptional<Type.TString>;
|
|
177
|
+
thinking: Type.TOptional<Type.TString>;
|
|
178
|
+
}>>;
|
|
179
|
+
capabilities: Type.TOptional<Type.TObject<{
|
|
180
|
+
steer: Type.TBoolean;
|
|
181
|
+
resume: Type.TBoolean;
|
|
182
|
+
team: Type.TBoolean;
|
|
183
|
+
transcript: Type.TBoolean;
|
|
184
|
+
}>>;
|
|
140
185
|
owned: Type.TBoolean;
|
|
141
186
|
state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"busy">, Type.TLiteral<"idle">, Type.TLiteral<"stopping">, Type.TLiteral<"stopped">, Type.TLiteral<"error">]>;
|
|
142
187
|
activity: Type.TString;
|
|
@@ -4,25 +4,26 @@ const id = Type.String({ minLength: 1, maxLength: 128 });
|
|
|
4
4
|
const message = Type.String({ minLength: 1, maxLength: 24000, description: "本次目标、相关资料、约束和交付要求。" });
|
|
5
5
|
const name = Type.String({ minLength: 1, maxLength: 64, pattern: "^[^\\r\\n\\x00-\\x1f]+$" });
|
|
6
6
|
export const agentStartOptions = {
|
|
7
|
+
backend: Type.Optional(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")], { description: "选择已安装并配置的子代理程序:pi、dsh 或 claude(Claude Code)。省略时使用当前宿主的原生专家;显式选择时使用目标程序自己的配置。团队成员须省略 backend。" })),
|
|
7
8
|
name: Type.Optional(name), message: Type.Optional(message),
|
|
8
9
|
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "随初始消息读取的文件;相对路径基于原工作区根目录。" })),
|
|
9
10
|
prompts: Type.Optional(Type.Array(message, { maxItems: 32, description: "与 message 按顺序合并为同一初始消息。" })),
|
|
10
|
-
provider: Type.Optional(Type.String({ ...id, description: "
|
|
11
|
-
model: Type.Optional(Type.String({ ...id, description: "Pi
|
|
12
|
-
thinking: Type.Optional(Type.
|
|
11
|
+
provider: Type.Optional(Type.String({ ...id, description: "模型提供方。省略 backend 时默认继承主会话;指定 backend 时,此参数须与 model 一起提供。Claude 子代理省略此参数。" })),
|
|
12
|
+
model: Type.Optional(Type.String({ ...id, description: "模型 ID;指定 backend 时也可使用目标公开的完整模型值。默认值:省略 backend 时继承主会话,指定时使用目标配置。Pi/dsh 同名模型可用 provider 区分。" })),
|
|
13
|
+
thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "思考等级 ID,可单独指定。默认值:省略 backend 时继承主会话,指定时使用目标配置。Pi 使用 off/minimal/low/medium/high/xhigh/max,其他程序使用其原生等级 ID。" })),
|
|
13
14
|
cwd: Type.Optional(Type.String({ minLength: 1, description: "执行目录,相对原工作区根目录;省略时使用工作区根目录。" })),
|
|
14
|
-
tools: Type.Optional(Type.Array(id, { minItems: 1, description: "
|
|
15
|
-
noExtensions: Type.Optional(Type.Boolean({ description: "
|
|
16
|
-
noSkills: Type.Optional(Type.Boolean({ description: "
|
|
17
|
-
noPromptTemplates: Type.Optional(Type.Boolean({ description: "
|
|
18
|
-
noContextFiles: Type.Optional(Type.Boolean({ description: "
|
|
15
|
+
tools: Type.Optional(Type.Array(id, { minItems: 1, description: "Pi/dsh 子代理的工具名;省略时使用所选程序默认工具。Claude 子代理省略此参数并沿用原生配置。" })),
|
|
16
|
+
noExtensions: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭其他扩展的自动发现,默认 true。" })),
|
|
17
|
+
noSkills: Type.Optional(Type.Boolean({ description: "Pi/dsh 子代理关闭技能发现,默认 false;Claude 子代理省略此参数并沿用原生配置。" })),
|
|
18
|
+
noPromptTemplates: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭提示模板发现,默认 false。" })),
|
|
19
|
+
noContextFiles: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭原生上下文文件加载,默认 false。" })),
|
|
19
20
|
};
|
|
20
21
|
const page = {
|
|
21
22
|
cycleId: Type.Optional(Type.String({ ...id, description: "仅 read:省略时读取最近周期;按 nextOffset 续读时须固定为上页返回的 cycle.cycleId,避免切换到新周期。" })),
|
|
22
23
|
offset: Type.Optional(Type.Integer({ minimum: 0, description: "仅 read:报告正文的 UTF-16 字符偏移,默认 0;续读使用上页 nextOffset。" })),
|
|
23
24
|
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:最多返回的正文 UTF-16 字符数,默认 16000,不是消息数或 token 数。" })),
|
|
24
25
|
};
|
|
25
|
-
const delivery = Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "send 默认 steer 补充当前工作;followUp 排到当前工作之后。" }));
|
|
26
|
+
const delivery = Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "send 默认 steer 补充当前工作;followUp 排到当前工作之后。capabilities.steer 为 false 的成员运行中使用 followUp。" }));
|
|
26
27
|
export const agentParametersSchema = Type.Object({
|
|
27
28
|
action: Type.Union([Type.Literal("start"), Type.Literal("send"), Type.Literal("rename"), Type.Literal("status"), Type.Literal("list"), Type.Literal("read"), Type.Literal("stop"), Type.Literal("resume")], {
|
|
28
29
|
description: "start 仅接受启动选项,可省略 message/prompts/files 创建待命会话,禁止 agentId/delivery/分页字段;list 只接受 action;status/stop 只接受并必填 agentId;send 必填 agentId/message,仅可选 delivery;resume 必填 agentId/message;rename 必填 agentId/name;read 必填 agentId,仅可选 cycleId/offset/limit。禁止携带其他 action 的字段。",
|
|
@@ -44,6 +45,11 @@ const cycle = Type.Object({ cycleId: Type.String(), startedAt: Type.Number(), fi
|
|
|
44
45
|
source: Type.Union([Type.Literal("parent"), Type.Literal("interactive"), Type.Literal("mixed")]), error: Type.Optional(Type.String()),
|
|
45
46
|
}, { additionalProperties: false });
|
|
46
47
|
export const agentViewSchema = Type.Object({ agentId: Type.String(), name: Type.String(), cwd: Type.String(), createdAt: Type.Number(),
|
|
48
|
+
backend: Type.Optional(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")])),
|
|
49
|
+
transport: Type.Optional(Type.Union([Type.Literal("native"), Type.Literal("acp")])),
|
|
50
|
+
selection: Type.Optional(Type.Object({ provider: Type.Optional(Type.String()), model: Type.Optional(Type.String()),
|
|
51
|
+
resolvedModel: Type.Optional(Type.String({ description: "目标原生会话报告的模型 ID,可用于识别配置别名。" })), thinking: Type.Optional(Type.String()) }, { additionalProperties: false, description: "子代理实际模型配置与有效思考等级,包含默认值。" })),
|
|
52
|
+
capabilities: Type.Optional(Type.Object({ steer: Type.Boolean(), resume: Type.Boolean(), team: Type.Boolean(), transcript: Type.Boolean() }, { additionalProperties: false })),
|
|
47
53
|
owned: Type.Boolean({ description: "是否属于当前父会话分支;false 时须回到所属分支操作。" }),
|
|
48
54
|
state: Type.Union([Type.Literal("starting"), Type.Literal("busy"), Type.Literal("idle"), Type.Literal("stopping"), Type.Literal("stopped"), Type.Literal("error")], { description: "执行状态;idle 不代表上轮工作成功,结果见 cycle.state。" }),
|
|
49
55
|
activity: Type.String(), cycle: Type.Optional(cycle), error: Type.Optional(Type.String()),
|
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
export declare const dshAgentParametersSchema: Type.TObject<{
|
|
3
|
+
noExtensions: Type.TOptional<Type.TBoolean>;
|
|
4
|
+
noPromptTemplates: Type.TOptional<Type.TBoolean>;
|
|
5
|
+
noContextFiles: Type.TOptional<Type.TBoolean>;
|
|
3
6
|
provider: Type.TOptional<Type.TString>;
|
|
4
7
|
model: Type.TOptional<Type.TString>;
|
|
5
8
|
thinking: Type.TOptional<Type.TString>;
|
|
6
9
|
files: Type.TOptional<Type.TArray<Type.TString>>;
|
|
7
10
|
tools: Type.TOptional<Type.TArray<Type.TString>>;
|
|
8
11
|
noSkills: Type.TOptional<Type.TBoolean>;
|
|
12
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
13
|
+
cycleId: Type.TOptional<Type.TString>;
|
|
14
|
+
name: Type.TOptional<Type.TString>;
|
|
9
15
|
agentId: Type.TOptional<Type.TString>;
|
|
10
16
|
cwd: Type.TOptional<Type.TString>;
|
|
11
|
-
name: Type.TOptional<Type.TString>;
|
|
12
17
|
message: Type.TOptional<Type.TString>;
|
|
13
18
|
delivery: Type.TOptional<Type.TUnion<[Type.TLiteral<"steer">, Type.TLiteral<"followUp">]>>;
|
|
14
|
-
cycleId: Type.TOptional<Type.TString>;
|
|
15
19
|
prompts: Type.TOptional<Type.TArray<Type.TString>>;
|
|
16
20
|
action: Type.TUnion<[Type.TLiteral<"start">, Type.TLiteral<"send">, Type.TLiteral<"rename">, Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"read">, Type.TLiteral<"stop">, Type.TLiteral<"resume">]>;
|
|
17
21
|
offset: Type.TOptional<Type.TInteger>;
|
|
18
22
|
limit: Type.TOptional<Type.TInteger>;
|
|
19
23
|
}>;
|
|
20
24
|
export declare const dshAgentActionSchema: Type.TUnion<(Type.TObject<{
|
|
25
|
+
backend: Type.TOptional<Type.TUnion<[Type.TLiteral<"pi">, Type.TLiteral<"dsh">, Type.TLiteral<"claude">]>>;
|
|
21
26
|
name: Type.TOptional<Type.TString>;
|
|
22
27
|
message: Type.TOptional<Type.TString>;
|
|
23
28
|
files: Type.TOptional<Type.TArray<Type.TString>>;
|
|
24
29
|
prompts: Type.TOptional<Type.TArray<Type.TString>>;
|
|
25
30
|
provider: Type.TOptional<Type.TString>;
|
|
26
31
|
model: Type.TOptional<Type.TString>;
|
|
27
|
-
thinking: Type.TOptional<Type.
|
|
32
|
+
thinking: Type.TOptional<Type.TString>;
|
|
28
33
|
cwd: Type.TOptional<Type.TString>;
|
|
29
34
|
tools: Type.TOptional<Type.TArray<Type.TString>>;
|
|
30
35
|
noExtensions: Type.TOptional<Type.TBoolean>;
|
|
@@ -37,16 +42,4 @@ export declare const dshAgentActionSchema: Type.TUnion<(Type.TObject<{
|
|
|
37
42
|
}> | Type.TObject<{
|
|
38
43
|
action: Type.TLiteral<string>;
|
|
39
44
|
agentId: Type.TString;
|
|
40
|
-
}> | Type.TObject<{
|
|
41
|
-
provider: Type.TOptional<Type.TString>;
|
|
42
|
-
model: Type.TOptional<Type.TString>;
|
|
43
|
-
thinking: Type.TOptional<Type.TString>;
|
|
44
|
-
files: Type.TOptional<Type.TArray<Type.TString>>;
|
|
45
|
-
tools: Type.TOptional<Type.TArray<Type.TString>>;
|
|
46
|
-
noSkills: Type.TOptional<Type.TBoolean>;
|
|
47
|
-
cwd: Type.TOptional<Type.TString>;
|
|
48
|
-
name: Type.TOptional<Type.TString>;
|
|
49
|
-
message: Type.TOptional<Type.TString>;
|
|
50
|
-
prompts: Type.TOptional<Type.TArray<Type.TString>>;
|
|
51
|
-
action: Type.TLiteral<"start">;
|
|
52
45
|
}>)[]>;
|
|
@@ -2,14 +2,18 @@ import { Type } from "../../common/typebox.js";
|
|
|
2
2
|
import { agentActionSchema, agentParametersSchema, agentStartOptions } from "./contract.js";
|
|
3
3
|
const options = Type.Omit(Type.Object(agentStartOptions), ["provider", "model", "thinking", "files", "tools", "noExtensions", "noPromptTemplates", "noContextFiles", "noSkills"]).properties;
|
|
4
4
|
const native = {
|
|
5
|
-
provider: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "dsh
|
|
6
|
-
model: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "
|
|
7
|
-
thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "
|
|
8
|
-
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "
|
|
9
|
-
tools: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1, description: "
|
|
10
|
-
noSkills: Type.Optional(Type.Boolean({ description: "
|
|
5
|
+
provider: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "模型提供方,dsh 使用原生 provider route。省略 backend 时默认继承主会话;指定 backend 时,此参数须与 model 一起提供。Claude 子代理省略此参数。" })),
|
|
6
|
+
model: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "模型 ID;指定 backend 时也可使用目标公开的完整模型值。默认值:省略 backend 时继承主会话,指定时使用目标配置。" })),
|
|
7
|
+
thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "思考等级 ID,dsh 使用原生 reasoning effort,可单独指定。默认值:省略 backend 时继承主会话,指定时使用目标配置。" })),
|
|
8
|
+
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "附给子代理的文件;相对原工作区根目录。图片格式与大小遵循所选程序的支持范围。" })),
|
|
9
|
+
tools: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1, description: "dsh 子代理填 run_code 内的能力工具名,Pi 子代理填 Pi 工具名。省略时使用所选程序默认工具;未指定 backend 的专家另有 pbot_team_message。Claude 子代理省略此参数并沿用原生配置。" })),
|
|
10
|
+
noSkills: Type.Optional(Type.Boolean({ description: "Pi/dsh 子代理关闭技能发现,默认 false;dsh 同时关闭 skill 工具。Claude 子代理省略此参数并沿用原生配置。" })),
|
|
11
11
|
};
|
|
12
12
|
const omitted = ["noExtensions", "noPromptTemplates", "noContextFiles", "provider", "model", "thinking", "files", "tools", "noSkills"];
|
|
13
|
-
export const dshAgentParametersSchema = Type.Object({ ...Type.Omit(agentParametersSchema, omitted).properties, ...native
|
|
13
|
+
export const dshAgentParametersSchema = Type.Object({ ...Type.Omit(agentParametersSchema, omitted).properties, ...native,
|
|
14
|
+
noExtensions: agentStartOptions.noExtensions, noPromptTemplates: agentStartOptions.noPromptTemplates, noContextFiles: agentStartOptions.noContextFiles,
|
|
15
|
+
}, { additionalProperties: false });
|
|
14
16
|
export const dshAgentActionSchema = Type.Union(agentActionSchema.anyOf.map(row => row.properties.action.const === "start"
|
|
15
|
-
? Type.Object({ action: Type.Literal("start"), ...options, ...native
|
|
17
|
+
? Type.Object({ action: Type.Literal("start"), ...options, ...native,
|
|
18
|
+
noExtensions: agentStartOptions.noExtensions, noPromptTemplates: agentStartOptions.noPromptTemplates, noContextFiles: agentStartOptions.noContextFiles,
|
|
19
|
+
}, { additionalProperties: false }) : row));
|