personal-bot 0.3.7 → 0.4.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +5 -8
- package/README.zh-CN.md +5 -8
- package/bin/pbot-pi-acp.mjs +1 -1
- package/docs/architecture/design.md +2 -2
- package/docs/architecture/extensibility.md +1 -1
- package/docs/guides/cross-harness-workers.md +4 -4
- package/docs/guides/history.md +1 -3
- package/docs/guides/workspace-configuration.md +4 -4
- package/docs/hosts/claude-code.md +2 -2
- package/docs/hosts/codex-qoder.md +1 -1
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +1 -1
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +1 -1
- package/lib/antigravity-plugin/lib/extension/acp/member.js +11 -10
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +346 -201
- package/lib/antigravity-plugin/lib/extension/cli.js +563 -538
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +1 -1
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +3 -4
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +0 -11
- package/lib/antigravity-plugin/lib/extension/mcp.js +397 -278
- package/lib/antigravity-plugin/lib/model/acp.d.ts +29 -35
- package/lib/antigravity-plugin/lib/model/agent.d.ts +33 -17
- package/lib/antigravity-plugin/lib/model/agent.js +0 -1
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +5 -8
- package/lib/antigravity-plugin/lib/storage/acp-files.js +34 -40
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +19 -10
- package/lib/antigravity-plugin/lib/storage/agent-files.js +147 -43
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +1 -1
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp/member.js +11 -10
- package/lib/extension/acp/worker.js +34 -33
- package/lib/extension/acp-worker.js +346 -201
- package/lib/extension/cli.js +563 -538
- package/lib/extension/hosts/dsh/acp-member.js +1 -1
- package/lib/extension/hosts/dsh/command.js +1 -1
- package/lib/extension/hosts/dsh/workspace.js +1 -3
- package/lib/extension/hosts/pi/acp-member.js +3 -4
- package/lib/extension/hosts/plugin-runtime.js +0 -11
- package/lib/extension/mcp/tool-contract.d.ts +8 -50
- package/lib/extension/mcp/tool-contract.js +0 -8
- package/lib/extension/mcp/workers.d.ts +7 -27
- package/lib/extension/mcp/workers.js +35 -17
- package/lib/extension/mcp.js +397 -278
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/agents.js +22 -22
- package/lib/integrations/acp/harnesses/claude.js +1 -1
- package/lib/model/acp.d.ts +29 -35
- package/lib/model/agent.d.ts +33 -17
- package/lib/model/agent.js +0 -1
- package/lib/qoder-plugin/.mcp.json +2 -2
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
- package/lib/qoder-plugin/hooks/hooks.json +3 -3
- package/lib/qoder-plugin/skills/pbot/SKILL.md +1 -1
- package/lib/services/agents/acp-run.d.ts +6 -4
- package/lib/services/agents/acp-run.js +62 -43
- package/lib/services/agents/agent-run.d.ts +10 -6
- package/lib/services/agents/agent-run.js +142 -65
- package/lib/services/agents/agent-service.d.ts +3 -21
- package/lib/services/agents/agent-service.js +180 -126
- package/lib/storage/acp-files.d.ts +5 -8
- package/lib/storage/acp-files.js +34 -40
- package/lib/storage/agent-files.d.ts +19 -10
- package/lib/storage/agent-files.js +147 -43
- package/package.json +1 -1
- package/src/extension/acp/member.ts +14 -11
- package/src/extension/acp/worker.ts +31 -28
- package/src/extension/cli/commands/upgrade.ts +8 -36
- package/src/extension/cli/commands/workspace.ts +3 -8
- package/src/extension/cli/index.ts +1 -2
- package/src/extension/hosts/dsh/acp-member.ts +1 -1
- package/src/extension/hosts/dsh/command.ts +1 -1
- package/src/extension/hosts/dsh/workspace.ts +1 -3
- package/src/extension/hosts/pi/acp-member.ts +3 -4
- package/src/extension/hosts/pi/command.ts +1 -1
- package/src/extension/hosts/pi/lifecycle.ts +0 -2
- package/src/extension/hosts/plugin-runtime.ts +0 -10
- package/src/extension/mcp/tool-contract.ts +0 -8
- package/src/extension/mcp/workers.ts +34 -17
- package/src/integrations/acp/agents.ts +28 -27
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/hosts/dsh/session.ts +2 -2
- package/src/integrations/installation/cli-update.ts +2 -2
- package/src/integrations/installation/installers/claude.ts +4 -4
- package/src/integrations/installation/installers/qoder.ts +5 -5
- package/src/integrations/installation/upgraders/antigravity.ts +57 -15
- package/src/integrations/installation/upgraders/claude.ts +1 -4
- package/src/integrations/installation/upgraders/codex.ts +85 -15
- package/src/integrations/installation/upgraders/dsh.ts +46 -24
- package/src/integrations/installation/upgraders/pi.ts +18 -11
- package/src/integrations/installation/upgraders/qoder.ts +95 -20
- package/src/model/acp.ts +27 -29
- package/src/model/agent.ts +80 -16
- package/src/model/installation.ts +0 -2
- package/src/pbot.ts +1 -1
- package/src/services/agents/acp-run.ts +81 -49
- package/src/services/agents/agent-run.ts +154 -56
- package/src/services/agents/agent-service.ts +204 -133
- package/src/services/installation/upgrade-service.ts +1 -5
- package/src/storage/acp-files.ts +50 -45
- package/src/storage/agent-files.ts +159 -46
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +0 -15
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +0 -126
- package/lib/services/workspace/plugin-releases.d.ts +0 -15
- package/lib/services/workspace/plugin-releases.js +0 -126
- package/src/services/workspace/plugin-releases.ts +0 -121
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentDescriptor, AgentHost, AgentOptions, AgentSessionReference } from "../../model/agent.js";
|
|
2
2
|
import type { AcpBackend, AcpCommands, AcpModelsResult } from "../../model/acp.js";
|
|
3
3
|
import { AgentFiles } from "../../storage/agent-files.js";
|
|
4
4
|
/** Pure ACP v1 worker host; spawns isolated acp-worker child processes for any registered or custom harness. */
|
|
@@ -11,12 +11,11 @@ export declare class AcpWorkerHost implements AgentHost {
|
|
|
11
11
|
filterOptions(backend: AcpBackend, options: AgentOptions): AgentOptions;
|
|
12
12
|
prepare(backend: AcpBackend, options: AgentOptions): import("../../model/acp.js").AcpSessionReference;
|
|
13
13
|
/** Probe a backend's advertised model and thinking choices in an isolated ACP process without prompting. */
|
|
14
|
-
inspectModels(backend: AcpBackend,
|
|
14
|
+
inspectModels(backend: AcpBackend, workspace: string, options?: Pick<AgentOptions, "provider" | "model">): Promise<AcpModelsResult>;
|
|
15
15
|
private process;
|
|
16
16
|
alive(id: string): boolean;
|
|
17
17
|
validateSession(d: AgentDescriptor, reference: AgentSessionReference): Promise<void>;
|
|
18
18
|
private spawn;
|
|
19
19
|
launch(d: AgentDescriptor, _directory: string, generation: string, _reference: AgentSessionReference, _resume: boolean, signal: AbortSignal): Promise<void>;
|
|
20
20
|
release(id: string, generation: string): Promise<void>;
|
|
21
|
-
report(d: AgentDescriptor, _reference: AgentSessionReference, leaf: string): string;
|
|
22
21
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { fork, spawnSync } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
-
import { AgentFiles,
|
|
6
|
-
import { acpInput, acpProcess, acpReport } from "../../storage/acp-files.js";
|
|
7
|
-
import { fileId } from "../../storage/file-access.js";
|
|
5
|
+
import { AgentFiles, status, workerRecord } from "../../storage/agent-files.js";
|
|
8
6
|
import { requireThat } from "../../common/validation.js";
|
|
9
7
|
import { resourceRoot } from "../../common/paths.js";
|
|
10
8
|
import { acpLaunch, filterAcpStartOptions } from "./launch.js";
|
|
@@ -29,13 +27,13 @@ export class AcpWorkerHost {
|
|
|
29
27
|
return acpLaunch(backend, this.commands, options);
|
|
30
28
|
}
|
|
31
29
|
/** Probe a backend's advertised model and thinking choices in an isolated ACP process without prompting. */
|
|
32
|
-
async inspectModels(backend,
|
|
30
|
+
async inspectModels(backend, workspace, options = {}) {
|
|
33
31
|
this.available(backend);
|
|
34
32
|
const filtered = this.filterOptions(backend, options);
|
|
35
33
|
const reference = this.prepare(backend, filtered);
|
|
36
34
|
return await new Promise((resolveResult, reject) => {
|
|
37
35
|
const child = fork(this.worker, ["--probe"], {
|
|
38
|
-
cwd, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
|
|
36
|
+
cwd: workspace, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
|
|
39
37
|
});
|
|
40
38
|
let result, failure;
|
|
41
39
|
const timer = setTimeout(() => {
|
|
@@ -60,7 +58,7 @@ export class AcpWorkerHost {
|
|
|
60
58
|
child.once("spawn", () => {
|
|
61
59
|
child.send({
|
|
62
60
|
reference,
|
|
63
|
-
cwd,
|
|
61
|
+
cwd: workspace,
|
|
64
62
|
...(filtered.provider ? { provider: filtered.provider } : {}),
|
|
65
63
|
...(filtered.model ? { model: filtered.model } : {}),
|
|
66
64
|
});
|
|
@@ -75,8 +73,8 @@ export class AcpWorkerHost {
|
|
|
75
73
|
});
|
|
76
74
|
}
|
|
77
75
|
process(id) {
|
|
78
|
-
const record = this.files.optional(id, "
|
|
79
|
-
if (!record
|
|
76
|
+
const record = this.files.optional(id, "worker.json", workerRecord);
|
|
77
|
+
if (!record?.pid)
|
|
80
78
|
return;
|
|
81
79
|
let denied = false;
|
|
82
80
|
try {
|
|
@@ -94,7 +92,7 @@ export class AcpWorkerHost {
|
|
|
94
92
|
// A dead leader can leave its group alive. A reused leader must match our exact launch identity.
|
|
95
93
|
if (leader.status === 0 && !leader.stdout.includes("--pbot-acp-agent " + id + " --generation " + record.generation) || denied && leader.status !== 0)
|
|
96
94
|
return;
|
|
97
|
-
return record;
|
|
95
|
+
return { generation: record.generation, pid: record.pid };
|
|
98
96
|
}
|
|
99
97
|
alive(id) {
|
|
100
98
|
return Boolean(this.process(id));
|
|
@@ -102,10 +100,11 @@ export class AcpWorkerHost {
|
|
|
102
100
|
async validateSession(d, reference) {
|
|
103
101
|
requireThat(!this.alive(d.agentId), "ACP 成员仍在运行,不能恢复。");
|
|
104
102
|
if (reference.sessionId === null) {
|
|
105
|
-
|
|
103
|
+
const saved = this.files.optional(d.agentId, "state.json", status);
|
|
104
|
+
requireThat(!saved?.activeRequestId, "ACP 输入交付状态不明;请核对原请求后新建成员。");
|
|
106
105
|
return;
|
|
107
106
|
}
|
|
108
|
-
const generation = this.files.
|
|
107
|
+
const generation = this.files.worker(d.agentId).generation;
|
|
109
108
|
await new Promise((resolveResult, reject) => {
|
|
110
109
|
const child = this.spawn(d, generation, true);
|
|
111
110
|
let validated = false, failure;
|
|
@@ -137,20 +136,27 @@ export class AcpWorkerHost {
|
|
|
137
136
|
spawn(d, generation, validate = false) {
|
|
138
137
|
return fork(this.worker, ["--pbot-acp-agent", d.agentId, "--generation", generation, "--directory", this.files.directory(d.agentId),
|
|
139
138
|
...(validate ? ["--validate"] : [])], {
|
|
140
|
-
cwd: d.
|
|
139
|
+
cwd: d.workspace, env: { ...process.env }, detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"], execArgv: [],
|
|
141
140
|
});
|
|
142
141
|
}
|
|
143
142
|
async launch(d, _directory, generation, _reference, _resume, signal) {
|
|
144
143
|
signal.throwIfAborted();
|
|
145
144
|
const child = this.spawn(d, generation);
|
|
146
145
|
await new Promise((resolveResult, reject) => { child.once("spawn", resolveResult); child.once("error", reject); });
|
|
147
|
-
|
|
146
|
+
const pid = child.pid;
|
|
147
|
+
requireThat(pid, "ACP worker 没有进程身份。");
|
|
148
148
|
try {
|
|
149
|
-
this.files.
|
|
149
|
+
this.files.control(() => {
|
|
150
|
+
const w = this.files.worker(d.agentId);
|
|
151
|
+
if (w.generation === generation) {
|
|
152
|
+
w.pid = pid;
|
|
153
|
+
this.files.write(d.agentId, "worker.json", w, workerRecord);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
150
156
|
}
|
|
151
157
|
catch (error) {
|
|
152
158
|
try {
|
|
153
|
-
process.kill(-
|
|
159
|
+
process.kill(-pid, "SIGKILL");
|
|
154
160
|
}
|
|
155
161
|
catch (failure) {
|
|
156
162
|
if (failure.code !== "ESRCH")
|
|
@@ -191,10 +197,4 @@ export class AcpWorkerHost {
|
|
|
191
197
|
if (current?.generation === generation && current.pid === record.pid)
|
|
192
198
|
terminate("SIGKILL");
|
|
193
199
|
}
|
|
194
|
-
report(d, _reference, leaf) {
|
|
195
|
-
requireThat(leaf.startsWith("acp:"), "ACP 报告引用无效。");
|
|
196
|
-
const cycleId = fileId(leaf.slice(4)), report = this.files.read(d.agentId, join("reports", cycleId + ".json"), acpReport);
|
|
197
|
-
requireThat(report.cycleId === cycleId, "ACP 报告周期不匹配。");
|
|
198
|
-
return report.text;
|
|
199
|
-
}
|
|
200
200
|
}
|
|
@@ -24,7 +24,7 @@ export const claudeAcpHarness = {
|
|
|
24
24
|
},
|
|
25
25
|
async prepareLaunch(context) {
|
|
26
26
|
const base = defaultPrepareLaunch(context);
|
|
27
|
-
const claude = await claudeOptions(base.command, context.
|
|
27
|
+
const claude = await claudeOptions(base.command, context.workspace, context.options.thinking, context.features?.skills !== false);
|
|
28
28
|
return {
|
|
29
29
|
...base,
|
|
30
30
|
...(claude.thinking ? { defaultThinking: claude.thinking } : {}),
|
package/lib/model/acp.d.ts
CHANGED
|
@@ -48,14 +48,6 @@ export interface AcpModelsResult {
|
|
|
48
48
|
currentThinking?: string;
|
|
49
49
|
selection: AcpModelSelection;
|
|
50
50
|
}
|
|
51
|
-
export interface AcpModelState extends AcpModelSelection {
|
|
52
|
-
generation: string;
|
|
53
|
-
}
|
|
54
|
-
export interface AcpProcess {
|
|
55
|
-
generation: string;
|
|
56
|
-
pid: number;
|
|
57
|
-
startedAt: number;
|
|
58
|
-
}
|
|
59
51
|
export interface AcpInput {
|
|
60
52
|
generation: string;
|
|
61
53
|
requestId: string;
|
|
@@ -66,53 +58,55 @@ export interface AcpAnswer extends AcpInput {
|
|
|
66
58
|
state: typeof acpAnswerStates[number];
|
|
67
59
|
error?: string;
|
|
68
60
|
}
|
|
69
|
-
export
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
export
|
|
61
|
+
export declare const acpElicitationActions: readonly ["accept", "decline", "cancel"];
|
|
62
|
+
export type AcpElicitationAction = typeof acpElicitationActions[number];
|
|
63
|
+
export type AcpElicitationValue = string | number | boolean | string[];
|
|
64
|
+
export declare function isAcpElicitationValue(value: unknown): value is AcpElicitationValue;
|
|
65
|
+
export type AcpElicitationContent = Record<string, AcpElicitationValue>;
|
|
66
|
+
export type AcpInteraction = {
|
|
75
67
|
generation: string;
|
|
76
68
|
requestId: string;
|
|
69
|
+
kind: "permission";
|
|
77
70
|
description: string;
|
|
78
71
|
options: {
|
|
79
72
|
optionId: string;
|
|
80
73
|
name: string;
|
|
81
74
|
kind: string;
|
|
82
75
|
}[];
|
|
83
|
-
}
|
|
84
|
-
export interface AcpPermissionReply {
|
|
76
|
+
} | {
|
|
85
77
|
generation: string;
|
|
86
78
|
requestId: string;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
export type AcpElicitationValue = string | number | boolean | string[];
|
|
92
|
-
export declare function isAcpElicitationValue(value: unknown): value is AcpElicitationValue;
|
|
93
|
-
export type AcpElicitationContent = Record<string, AcpElicitationValue>;
|
|
94
|
-
export interface AcpElicitation {
|
|
79
|
+
kind: "form";
|
|
80
|
+
message: string;
|
|
81
|
+
schema: Record<string, unknown>;
|
|
82
|
+
} | {
|
|
95
83
|
generation: string;
|
|
96
84
|
requestId: string;
|
|
97
|
-
|
|
85
|
+
kind: "url";
|
|
98
86
|
message: string;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export interface AcpElicitationReply {
|
|
87
|
+
url: string;
|
|
88
|
+
};
|
|
89
|
+
export type AcpInteractionReply = {
|
|
103
90
|
generation: string;
|
|
104
91
|
requestId: string;
|
|
92
|
+
kind: "permission";
|
|
93
|
+
optionId: string | null;
|
|
94
|
+
} | {
|
|
95
|
+
generation: string;
|
|
96
|
+
requestId: string;
|
|
97
|
+
kind: "form";
|
|
105
98
|
action: AcpElicitationAction;
|
|
106
99
|
content?: AcpElicitationContent;
|
|
107
|
-
}
|
|
100
|
+
} | {
|
|
101
|
+
generation: string;
|
|
102
|
+
requestId: string;
|
|
103
|
+
kind: "url";
|
|
104
|
+
action: AcpElicitationAction;
|
|
105
|
+
};
|
|
108
106
|
export interface AcpStartOptions {
|
|
109
|
-
name?: string;
|
|
110
|
-
message?: string;
|
|
111
|
-
files?: string[];
|
|
112
107
|
provider?: string;
|
|
113
108
|
model?: string;
|
|
114
109
|
thinking?: string;
|
|
115
|
-
cwd?: string;
|
|
116
110
|
tools?: string[];
|
|
117
111
|
noExtensions?: boolean;
|
|
118
112
|
noSkills?: boolean;
|
|
@@ -121,7 +115,7 @@ export interface AcpStartOptions {
|
|
|
121
115
|
}
|
|
122
116
|
export interface AcpLaunchContext {
|
|
123
117
|
readonly reference: AcpSessionReference;
|
|
124
|
-
readonly
|
|
118
|
+
readonly workspace: string;
|
|
125
119
|
readonly directory: string;
|
|
126
120
|
readonly packageRoot: string;
|
|
127
121
|
readonly options: AcpStartOptions;
|
package/lib/model/agent.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { AcpBackend, AcpElicitationAction, AcpElicitationContent, AcpModelSelection, AcpSessionReference, AcpStartOptions } from "./acp.js";
|
|
1
|
+
import type { AcpBackend, AcpCommand, AcpElicitationAction, AcpElicitationContent, AcpModelSelection, AcpPermissionPolicy, AcpSessionReference, AcpStartOptions } from "./acp.js";
|
|
2
2
|
export type AgentOptions = AcpStartOptions;
|
|
3
3
|
export interface AgentStartOptions extends AgentOptions {
|
|
4
4
|
backend: AcpBackend;
|
|
5
|
+
message?: string;
|
|
6
|
+
files?: string[];
|
|
5
7
|
}
|
|
6
8
|
export interface AgentOwner {
|
|
7
9
|
sessionId: string;
|
|
@@ -12,23 +14,29 @@ export interface AgentDescriptor {
|
|
|
12
14
|
agentId: string;
|
|
13
15
|
release: string;
|
|
14
16
|
workspace: string;
|
|
15
|
-
cwd: string;
|
|
16
17
|
parentSessionId: string;
|
|
17
|
-
parentLeaf: string | null;
|
|
18
|
-
createdAt: number;
|
|
19
18
|
options: AgentOptions;
|
|
20
19
|
}
|
|
21
20
|
export type AgentSessionReference = AcpSessionReference;
|
|
22
|
-
export interface
|
|
21
|
+
export interface AgentAcpConfig extends AcpCommand {
|
|
22
|
+
backend: AcpBackend;
|
|
23
|
+
permission?: AcpPermissionPolicy;
|
|
24
|
+
}
|
|
25
|
+
export interface AgentWorkerRecord {
|
|
26
|
+
agentId: string;
|
|
27
|
+
release: string;
|
|
28
|
+
workspace: string;
|
|
29
|
+
parentSessionId: string;
|
|
23
30
|
generation: string;
|
|
24
|
-
name: string;
|
|
25
31
|
sequence: number;
|
|
26
32
|
stop: boolean;
|
|
27
33
|
startedAt: number;
|
|
34
|
+
pid?: number;
|
|
35
|
+
acp: AgentAcpConfig;
|
|
36
|
+
options?: AgentOptions;
|
|
28
37
|
}
|
|
29
38
|
export declare const messageDeliveries: readonly ["steer", "followUp"];
|
|
30
39
|
export declare const cycleStates: readonly ["running", "completed", "failed", "cancelled", "interrupted"];
|
|
31
|
-
export declare const cycleSources: readonly ["parent", "interactive", "mixed"];
|
|
32
40
|
export declare const agentStates: readonly ["starting", "busy", "idle", "stopping", "stopped", "error"];
|
|
33
41
|
export interface AgentMessage {
|
|
34
42
|
requestId: string;
|
|
@@ -44,9 +52,7 @@ export interface AgentCycle {
|
|
|
44
52
|
startedAt: number;
|
|
45
53
|
finishedAt?: number;
|
|
46
54
|
state: typeof cycleStates[number];
|
|
47
|
-
leaf: string | null;
|
|
48
55
|
requestIds: string[];
|
|
49
|
-
source: typeof cycleSources[number];
|
|
50
56
|
error?: string;
|
|
51
57
|
}
|
|
52
58
|
export interface AgentStatus {
|
|
@@ -54,12 +60,29 @@ export interface AgentStatus {
|
|
|
54
60
|
state: typeof agentStates[number];
|
|
55
61
|
activity: string;
|
|
56
62
|
updatedAt: number;
|
|
63
|
+
sessionId?: string | null;
|
|
64
|
+
capabilities?: {
|
|
65
|
+
resume: boolean;
|
|
66
|
+
load: boolean;
|
|
67
|
+
close: boolean;
|
|
68
|
+
};
|
|
69
|
+
selection?: AcpModelSelection;
|
|
70
|
+
activeRequestId?: string;
|
|
57
71
|
accepted?: string[];
|
|
58
72
|
cycle?: AgentCycle;
|
|
59
73
|
error?: string;
|
|
60
74
|
}
|
|
75
|
+
export interface AgentOutput {
|
|
76
|
+
cycleId: string;
|
|
77
|
+
generation: string;
|
|
78
|
+
startedAt: number;
|
|
79
|
+
finishedAt: number;
|
|
80
|
+
state: Exclude<AgentCycle["state"], "running">;
|
|
81
|
+
requestIds: string[];
|
|
82
|
+
text: string;
|
|
83
|
+
error?: string;
|
|
84
|
+
}
|
|
61
85
|
export interface AgentView extends AgentDescriptor {
|
|
62
|
-
name: string;
|
|
63
86
|
generation: string;
|
|
64
87
|
state: AgentStatus["state"];
|
|
65
88
|
activity: string;
|
|
@@ -103,12 +126,6 @@ export interface AgentResponseInput {
|
|
|
103
126
|
optionId?: string;
|
|
104
127
|
content?: AcpElicitationContent;
|
|
105
128
|
}
|
|
106
|
-
export interface AgentCompletion {
|
|
107
|
-
agentId: string;
|
|
108
|
-
name: string;
|
|
109
|
-
cycle: AgentCycle;
|
|
110
|
-
report: string;
|
|
111
|
-
}
|
|
112
129
|
export interface AgentHost {
|
|
113
130
|
available(backend: AcpBackend): void;
|
|
114
131
|
filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
|
|
@@ -117,5 +134,4 @@ export interface AgentHost {
|
|
|
117
134
|
validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
|
|
118
135
|
launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
|
|
119
136
|
release(id: string, generation: string): void | Promise<void>;
|
|
120
|
-
report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
|
|
121
137
|
}
|
package/lib/model/agent.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export const messageDeliveries = ["steer", "followUp"];
|
|
2
2
|
export const cycleStates = ["running", "completed", "failed", "cancelled", "interrupted"];
|
|
3
|
-
export const cycleSources = ["parent", "interactive", "mixed"];
|
|
4
3
|
export const agentStates = ["starting", "busy", "idle", "stopping", "stopped", "error"];
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
"command": "sh",
|
|
5
5
|
"args": [
|
|
6
6
|
"-c",
|
|
7
|
-
"if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.
|
|
7
|
+
"if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.0 \"$@\"",
|
|
8
8
|
"pbot",
|
|
9
9
|
"mcp"
|
|
10
10
|
],
|
|
11
11
|
"env": {
|
|
12
12
|
"PBOT_HOST": "qoder",
|
|
13
|
-
"PBOT_PLUGIN_VERSION": "0.
|
|
13
|
+
"PBOT_PLUGIN_VERSION": "0.4.0"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"hooks": [
|
|
6
6
|
{
|
|
7
7
|
"type": "command",
|
|
8
|
-
"command": "PBOT_PLUGIN_VERSION=0.
|
|
8
|
+
"command": "PBOT_PLUGIN_VERSION=0.4.0 sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.0 \"$@\"' pbot plugin qoder hook",
|
|
9
9
|
"timeout": 120
|
|
10
10
|
}
|
|
11
11
|
]
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"hooks": [
|
|
17
17
|
{
|
|
18
18
|
"type": "command",
|
|
19
|
-
"command": "PBOT_PLUGIN_VERSION=0.
|
|
19
|
+
"command": "PBOT_PLUGIN_VERSION=0.4.0 sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.0 \"$@\"' pbot plugin qoder hook",
|
|
20
20
|
"timeout": 120
|
|
21
21
|
}
|
|
22
22
|
]
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"hooks": [
|
|
28
28
|
{
|
|
29
29
|
"type": "command",
|
|
30
|
-
"command": "PBOT_PLUGIN_VERSION=0.
|
|
30
|
+
"command": "PBOT_PLUGIN_VERSION=0.4.0 sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.0 \"$@\"' pbot plugin qoder hook",
|
|
31
31
|
"timeout": 120
|
|
32
32
|
}
|
|
33
33
|
]
|
|
@@ -6,4 +6,4 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
`--workspace` 传入当前会话的 `workspaceRoot`(工作区未启用时使用当前工作区根目录)。省略子命令时使用 `status`。可执行 `init`、`status`、`history status|list|summary|migrate|search|read`,保留用户指定的维度、模型和筛选参数。
|
|
8
8
|
|
|
9
|
-
若 `pbot --at-least 0.
|
|
9
|
+
若 `pbot --at-least 0.4.0` 返回 0,运行 `pbot <子命令> --workspace "<workspaceRoot>"`;否则运行 `npx --yes personal-bot@0.4.0 <子命令> --workspace "<workspaceRoot>"`。返回实际结果。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentDescriptor, AgentMessage } from "../../model/agent.js";
|
|
2
|
-
import type { AcpElicitationAction, AcpElicitationContent,
|
|
2
|
+
import type { AcpElicitationAction, AcpElicitationContent, AcpInteraction } from "../../model/acp.js";
|
|
3
3
|
import { AgentFiles } from "../../storage/agent-files.js";
|
|
4
4
|
import { AgentRun } from "./agent-run.js";
|
|
5
5
|
export interface AcpProgress {
|
|
@@ -21,7 +21,7 @@ export interface AcpWork {
|
|
|
21
21
|
}>;
|
|
22
22
|
cancel(): Promise<void>;
|
|
23
23
|
}
|
|
24
|
-
/** ACP prompt completion is the receipt boundary;
|
|
24
|
+
/** ACP prompt completion is the receipt boundary; output publishes before state returns to idle. */
|
|
25
25
|
export declare class AcpAgentRun {
|
|
26
26
|
#private;
|
|
27
27
|
readonly files: AgentFiles;
|
|
@@ -30,11 +30,13 @@ export declare class AcpAgentRun {
|
|
|
30
30
|
readonly work: AcpWork;
|
|
31
31
|
readonly exactAnswer: boolean;
|
|
32
32
|
readonly execution: AgentRun;
|
|
33
|
-
constructor(files: AgentFiles, descriptor: AgentDescriptor, generation: string, work: AcpWork, exactAnswer: boolean);
|
|
33
|
+
constructor(files: AgentFiles, descriptor: AgentDescriptor, generation: string, work: AcpWork, exactAnswer: boolean, execution?: AgentRun);
|
|
34
34
|
private get id();
|
|
35
35
|
private current;
|
|
36
36
|
update(value: AcpProgress): void;
|
|
37
|
-
permission(description: string, options:
|
|
37
|
+
permission(description: string, options: Extract<AcpInteraction, {
|
|
38
|
+
kind: "permission";
|
|
39
|
+
}>["options"], signal: AbortSignal): Promise<string | null>;
|
|
38
40
|
elicitation(input: {
|
|
39
41
|
mode: "form";
|
|
40
42
|
message: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
-
import { AgentFiles
|
|
4
|
-
import { acpAnswer,
|
|
3
|
+
import { AgentFiles } from "../../storage/agent-files.js";
|
|
4
|
+
import { acpAnswer, acpInteraction, acpInteractionReply } from "../../storage/acp-files.js";
|
|
5
5
|
import { AgentRun } from "./agent-run.js";
|
|
6
6
|
export class AcpAnswerBuffer {
|
|
7
7
|
#text = "";
|
|
@@ -19,7 +19,7 @@ export class AcpAnswerBuffer {
|
|
|
19
19
|
this.#text += value.text ?? "";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
/** ACP prompt completion is the receipt boundary;
|
|
22
|
+
/** ACP prompt completion is the receipt boundary; output publishes before state returns to idle. */
|
|
23
23
|
export class AcpAgentRun {
|
|
24
24
|
files;
|
|
25
25
|
descriptor;
|
|
@@ -33,16 +33,16 @@ export class AcpAgentRun {
|
|
|
33
33
|
#work;
|
|
34
34
|
#stop;
|
|
35
35
|
#failure;
|
|
36
|
-
constructor(files, descriptor, generation, work, exactAnswer) {
|
|
36
|
+
constructor(files, descriptor, generation, work, exactAnswer, execution) {
|
|
37
37
|
this.files = files;
|
|
38
38
|
this.descriptor = descriptor;
|
|
39
39
|
this.generation = generation;
|
|
40
40
|
this.work = work;
|
|
41
41
|
this.exactAnswer = exactAnswer;
|
|
42
|
-
this.execution = new AgentRun(files, descriptor.agentId, generation);
|
|
42
|
+
this.execution = execution ?? new AgentRun(files, descriptor.agentId, generation);
|
|
43
43
|
}
|
|
44
44
|
get id() { return this.descriptor.agentId; }
|
|
45
|
-
current() { return this.files.
|
|
45
|
+
current() { return this.files.worker(this.id).generation === this.generation; }
|
|
46
46
|
update(value) {
|
|
47
47
|
if (!this.execution.current || !this.current())
|
|
48
48
|
return;
|
|
@@ -53,44 +53,49 @@ export class AcpAgentRun {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
async permission(description, options, signal) {
|
|
56
|
-
const requestId = randomUUID()
|
|
57
|
-
this.
|
|
58
|
-
this.files.
|
|
56
|
+
const requestId = randomUUID();
|
|
57
|
+
const request = { generation: this.generation, requestId, kind: "permission", description, options };
|
|
58
|
+
this.files.ensureSubdirectory(this.id, "interactions");
|
|
59
|
+
this.files.write(this.id, "interactions/" + requestId + ".json", request, acpInteraction, true);
|
|
59
60
|
this.execution.save({ state: "busy", activity: "等待确认" });
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
try {
|
|
62
|
+
while (!signal.aborted && !this.#stopping && this.current() && !this.files.worker(this.id).stop) {
|
|
63
|
+
const reply = this.files.optional(this.id, "interactions/" + requestId + "-reply.json", acpInteractionReply);
|
|
64
|
+
if (reply?.generation === this.generation && reply.kind === "permission") {
|
|
65
|
+
this.execution.save({ state: this.#stopping ? "stopping" : "busy", activity: reply.optionId ? "已获确认" : "确认被拒绝" });
|
|
66
|
+
return reply.optionId;
|
|
67
|
+
}
|
|
68
|
+
await delay(100);
|
|
65
69
|
}
|
|
66
|
-
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
this.files.removeInteraction(this.id, requestId);
|
|
67
74
|
}
|
|
68
|
-
// Close the request so it no longer shows as pending once the turn or worker has ended.
|
|
69
|
-
if (this.current())
|
|
70
|
-
this.files.write(this.id, "permissions/" + requestId + "-reply.json", { generation: this.generation, requestId, optionId: null }, acpPermissionReply, true);
|
|
71
|
-
return null;
|
|
72
75
|
}
|
|
73
76
|
async elicitation(input, signal) {
|
|
74
77
|
const requestId = randomUUID();
|
|
75
78
|
const request = input.mode === "form"
|
|
76
|
-
? { generation: this.generation, requestId,
|
|
77
|
-
: { generation: this.generation, requestId,
|
|
78
|
-
this.files.ensureSubdirectory(this.id, "
|
|
79
|
-
this.files.write(this.id, "
|
|
79
|
+
? { generation: this.generation, requestId, kind: "form", message: input.message, schema: input.schema }
|
|
80
|
+
: { generation: this.generation, requestId, kind: "url", message: input.message, url: input.url };
|
|
81
|
+
this.files.ensureSubdirectory(this.id, "interactions");
|
|
82
|
+
this.files.write(this.id, "interactions/" + requestId + ".json", request, acpInteraction, true);
|
|
80
83
|
this.execution.save({ state: "busy", activity: "等待回复" });
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
try {
|
|
85
|
+
while (!signal.aborted && !this.#stopping && this.current() && !this.files.worker(this.id).stop) {
|
|
86
|
+
const reply = this.files.optional(this.id, "interactions/" + requestId + "-reply.json", acpInteractionReply);
|
|
87
|
+
if (reply?.generation === this.generation && reply.kind !== "permission") {
|
|
88
|
+
const label = reply.action === "accept" ? "已收到回复" : reply.action === "decline" ? "回复已拒绝" : "回复已取消";
|
|
89
|
+
this.execution.save({ state: this.#stopping ? "stopping" : "busy", activity: label });
|
|
90
|
+
return { action: reply.action, ...(reply.kind === "form" && reply.content ? { content: reply.content } : {}) };
|
|
91
|
+
}
|
|
92
|
+
await delay(100);
|
|
87
93
|
}
|
|
88
|
-
|
|
94
|
+
return { action: "cancel" };
|
|
89
95
|
}
|
|
90
|
-
|
|
91
|
-
this.files.
|
|
96
|
+
finally {
|
|
97
|
+
this.files.removeInteraction(this.id, requestId);
|
|
92
98
|
}
|
|
93
|
-
return { action: "cancel" };
|
|
94
99
|
}
|
|
95
100
|
async run() {
|
|
96
101
|
this.execution.recover();
|
|
@@ -99,7 +104,7 @@ export class AcpAgentRun {
|
|
|
99
104
|
this.files.check();
|
|
100
105
|
if (this.#failure)
|
|
101
106
|
throw this.#failure;
|
|
102
|
-
if (this.files.
|
|
107
|
+
if (this.files.worker(this.id).stop) {
|
|
103
108
|
await this.stop();
|
|
104
109
|
break;
|
|
105
110
|
}
|
|
@@ -126,13 +131,14 @@ export class AcpAgentRun {
|
|
|
126
131
|
this.execution.claim(request.requestId);
|
|
127
132
|
this.execution.enter(request.requestId);
|
|
128
133
|
this.execution.begin();
|
|
129
|
-
this.
|
|
134
|
+
this.execution.setActiveRequest(request.requestId);
|
|
130
135
|
let result;
|
|
131
136
|
try {
|
|
132
137
|
const end = await this.work.prompt(request);
|
|
133
138
|
let snapshot;
|
|
134
139
|
if (this.exactAnswer) {
|
|
135
140
|
snapshot = this.files.optional(this.id, "acp-answer.json", acpAnswer);
|
|
141
|
+
this.files.remove(this.id, "acp-answer.json");
|
|
136
142
|
if (snapshot?.generation !== this.generation || snapshot.requestId !== request.requestId)
|
|
137
143
|
snapshot = undefined;
|
|
138
144
|
}
|
|
@@ -141,19 +147,32 @@ export class AcpAgentRun {
|
|
|
141
147
|
(!this.exactAnswer || snapshot?.state === "completed") && answer.trim() ? "completed" : "failed";
|
|
142
148
|
if (state === "completed")
|
|
143
149
|
this.execution.consume(request.requestId);
|
|
144
|
-
result = {
|
|
145
|
-
|
|
150
|
+
result = {
|
|
151
|
+
generation: this.generation,
|
|
152
|
+
requestId: request.requestId,
|
|
153
|
+
state,
|
|
154
|
+
answer,
|
|
155
|
+
...(state === "failed" ? { error: snapshot?.error ?? "ACP 工作未产生有效最终回答:" + end.stopReason } : {}),
|
|
156
|
+
};
|
|
146
157
|
}
|
|
147
158
|
catch (error) {
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
if (this.exactAnswer)
|
|
160
|
+
this.files.remove(this.id, "acp-answer.json");
|
|
161
|
+
result = {
|
|
162
|
+
generation: this.generation,
|
|
163
|
+
requestId: request.requestId,
|
|
164
|
+
answer: this.#answer.text,
|
|
165
|
+
state: this.#stopping || this.files.worker(this.id).stop ? "cancelled" : "failed",
|
|
166
|
+
error: String(error),
|
|
167
|
+
};
|
|
150
168
|
}
|
|
151
169
|
if (!this.current())
|
|
152
170
|
return;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
171
|
+
this.execution.finish({
|
|
172
|
+
state: this.work.signal.aborted && !this.#stopping ? "interrupted" : result.state,
|
|
173
|
+
answer: result.answer,
|
|
174
|
+
...(result.error ? { error: result.error } : {}),
|
|
175
|
+
});
|
|
157
176
|
}
|
|
158
177
|
settled() { return this.#work; }
|
|
159
178
|
stop() {
|