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
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -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"];
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type { AcpAnswer,
|
|
1
|
+
import type { AcpAnswer, AcpInput, AcpInteraction, AcpInteractionReply, AcpSessionReference } from "../model/acp.js";
|
|
2
|
+
import type { AgentAcpConfig } from "../model/agent.js";
|
|
3
|
+
export declare function acpConfig(value: unknown): AgentAcpConfig;
|
|
2
4
|
export declare function acpReference(value: unknown): AcpSessionReference;
|
|
3
|
-
export declare function acpModelState(value: unknown): AcpModelState;
|
|
4
|
-
export declare function acpProcess(value: unknown): AcpProcess;
|
|
5
5
|
export declare function acpInput(value: unknown): AcpInput;
|
|
6
6
|
export declare function acpAnswer(value: unknown): AcpAnswer;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function acpPermissionReply(value: unknown): AcpPermissionReply;
|
|
10
|
-
export declare function acpElicitation(value: unknown): AcpElicitation;
|
|
11
|
-
export declare function acpElicitationReply(value: unknown): AcpElicitationReply;
|
|
7
|
+
export declare function acpInteraction(value: unknown): AcpInteraction;
|
|
8
|
+
export declare function acpInteractionReply(value: unknown): AcpInteractionReply;
|
|
@@ -4,27 +4,24 @@ import { isAcpBackend, isOneOf, requireThat } from "../common/validation.js";
|
|
|
4
4
|
import { fileId } from "./file-access.js";
|
|
5
5
|
import { acpAnswerStates, acpElicitationActions, acpPermissionPolicies, isAcpElicitationValue } from "../model/acp.js";
|
|
6
6
|
const text = (value) => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
7
|
-
export function
|
|
8
|
-
requireThat(object(value) &&
|
|
9
|
-
text(value.command) && isAbsolute(value.command) &&
|
|
10
|
-
(value.
|
|
7
|
+
export function acpConfig(value) {
|
|
8
|
+
requireThat(object(value) && isAcpBackend(value.backend) &&
|
|
9
|
+
text(value.command) && isAbsolute(value.command) &&
|
|
10
|
+
Array.isArray(value.args) && value.args.every(arg => typeof arg === "string" && !arg.includes("\0")), "ACP 启动配置无效。");
|
|
11
11
|
if (value.env !== undefined) {
|
|
12
12
|
requireThat(object(value.env) && Object.entries(value.env).every(([k, v]) => text(k) && typeof v === "string" && !v.includes("\0")), "ACP 环境变量配置无效。");
|
|
13
13
|
}
|
|
14
14
|
requireThat(value.permission === undefined || isOneOf(value.permission, acpPermissionPolicies), "ACP 权限策略无效。");
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export function acpReference(value) {
|
|
18
|
+
requireThat(object(value) && value.host === "acp" && (value.sessionId === null || text(value.sessionId)), "ACP 会话引用无效。");
|
|
19
|
+
acpConfig(value);
|
|
15
20
|
const capabilities = value.capabilities;
|
|
16
|
-
if (capabilities !== undefined)
|
|
21
|
+
if (capabilities !== undefined) {
|
|
17
22
|
requireThat(object(capabilities) &&
|
|
18
23
|
["resume", "load", "close"].every(key => typeof capabilities[key] === "boolean"), "ACP 会话能力无效。");
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
export function acpModelState(value) {
|
|
22
|
-
requireThat(object(value) && text(value.generation) && ["provider", "model", "resolvedModel", "thinking"].every(key => value[key] === undefined || text(value[key])), "ACP 模型选择无效。");
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
export function acpProcess(value) {
|
|
26
|
-
requireThat(object(value) && text(value.generation) && Number.isSafeInteger(value.pid) && Number(value.pid) > 1 &&
|
|
27
|
-
typeof value.startedAt === "number" && Number.isFinite(value.startedAt), "ACP 进程记录无效。");
|
|
24
|
+
}
|
|
28
25
|
return value;
|
|
29
26
|
}
|
|
30
27
|
export function acpInput(value) {
|
|
@@ -38,38 +35,35 @@ export function acpAnswer(value) {
|
|
|
38
35
|
(value.error === undefined || typeof value.error === "string"), "ACP 最终回答无效。");
|
|
39
36
|
return value;
|
|
40
37
|
}
|
|
41
|
-
export function
|
|
42
|
-
requireThat(object(value) && text(value.generation) && text(value.cycleId) && typeof value.text === "string", "ACP 周期报告无效。");
|
|
43
|
-
fileId(value.cycleId);
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
export function acpPermission(value) {
|
|
47
|
-
acpInput(value);
|
|
48
|
-
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every(option => object(option) && text(option.optionId) && text(option.name) && isOneOf(option.kind, ["allow_once", "allow_always", "reject_once", "reject_always"])), "ACP 确认请求无效。");
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
export function acpPermissionReply(value) {
|
|
38
|
+
export function acpInteraction(value) {
|
|
52
39
|
acpInput(value);
|
|
53
|
-
requireThat(object(value)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
acpInput(value);
|
|
58
|
-
requireThat(object(value) && (value.mode === "form" || value.mode === "url") && typeof value.message === "string", "ACP 交互请求无效。");
|
|
59
|
-
if (value.mode === "form") {
|
|
60
|
-
requireThat(object(value.schema) && value.url === undefined, "ACP 表单交互请求缺少有效 schema。");
|
|
40
|
+
requireThat(object(value), "ACP 交互请求无效。");
|
|
41
|
+
if (value.kind === "permission") {
|
|
42
|
+
requireThat(typeof value.description === "string" && Array.isArray(value.options) && value.options.every(option => object(option) && text(option.optionId) && text(option.name) && isOneOf(option.kind, ["allow_once", "allow_always", "reject_once", "reject_always"])), "ACP 确认请求无效。");
|
|
43
|
+
return value;
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
requireThat(
|
|
45
|
+
if (value.kind === "form") {
|
|
46
|
+
requireThat(typeof value.message === "string" && object(value.schema), "ACP 表单交互请求缺少有效 schema。");
|
|
47
|
+
return value;
|
|
64
48
|
}
|
|
49
|
+
requireThat(value.kind === "url" && typeof value.message === "string" && text(value.url), "ACP URL 交互请求无效。");
|
|
65
50
|
return value;
|
|
66
51
|
}
|
|
67
|
-
export function
|
|
52
|
+
export function acpInteractionReply(value) {
|
|
68
53
|
acpInput(value);
|
|
69
|
-
requireThat(object(value)
|
|
70
|
-
if (value.
|
|
71
|
-
requireThat(value.
|
|
72
|
-
|
|
54
|
+
requireThat(object(value), "ACP 交互答复无效。");
|
|
55
|
+
if (value.kind === "permission") {
|
|
56
|
+
requireThat(value.optionId === null || text(value.optionId), "ACP 确认答复无效。");
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
if (value.kind === "form") {
|
|
60
|
+
requireThat(isOneOf(value.action, acpElicitationActions), "ACP 表单答复 action 无效。");
|
|
61
|
+
if (value.content !== undefined) {
|
|
62
|
+
requireThat(value.action === "accept" && object(value.content) &&
|
|
63
|
+
Object.values(value.content).every(isAcpElicitationValue), "ACP 表单答复 content 无效。");
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
73
66
|
}
|
|
67
|
+
requireThat(value.kind === "url" && isOneOf(value.action, acpElicitationActions), "ACP URL 交互答复无效。");
|
|
74
68
|
return value;
|
|
75
69
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentCycle, AgentDescriptor, AgentMessage, AgentOutput, AgentSessionReference, AgentStatus, AgentWorkerRecord } from "../model/agent.js";
|
|
2
2
|
import type { AcpSessionReference } from "../model/acp.js";
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function launch(v: unknown): AgentLaunch;
|
|
3
|
+
export declare function workerRecord(v: unknown): AgentWorkerRecord;
|
|
5
4
|
export declare function message(v: unknown): AgentMessage;
|
|
6
5
|
export declare function cycle(v: unknown): AgentCycle;
|
|
7
6
|
export declare function status(v: unknown): AgentStatus;
|
|
7
|
+
export declare function outputRecord(v: unknown): AgentOutput;
|
|
8
|
+
export declare function toDescriptor(record: AgentWorkerRecord): AgentDescriptor;
|
|
8
9
|
export declare class AgentFiles {
|
|
9
10
|
#private;
|
|
10
11
|
readonly root: string;
|
|
@@ -15,14 +16,22 @@ export declare class AgentFiles {
|
|
|
15
16
|
read<T>(id: string, path: string, parse: (v: unknown) => T): T;
|
|
16
17
|
optional<T>(id: string, path: string, parse: (v: unknown) => T): T | undefined;
|
|
17
18
|
write<T>(id: string, path: string, value: T, parse: (v: unknown) => T, create?: boolean): void;
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
remove(id: string, path: string): void;
|
|
20
|
+
create(value: AgentDescriptor, run: {
|
|
21
|
+
generation: string;
|
|
22
|
+
sequence: number;
|
|
23
|
+
stop: boolean;
|
|
24
|
+
startedAt: number;
|
|
25
|
+
}, acp: AcpSessionReference): void;
|
|
26
|
+
worker(id: string): AgentWorkerRecord;
|
|
27
|
+
list(): AgentWorkerRecord[];
|
|
20
28
|
messages(id: string): AgentMessage[];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
removeMessage(id: string, requestId: string): void;
|
|
30
|
+
output(id: string): AgentOutput | undefined;
|
|
31
|
+
pendingInteractions(id: string, generation: string): import("../model/acp.js").AcpInteraction[];
|
|
32
|
+
removeInteraction(id: string, requestId: string): void;
|
|
33
|
+
clearTransient(id: string): void;
|
|
34
|
+
removeWorker(id: string): void;
|
|
26
35
|
ensureSubdirectory(id: string, name: string): void;
|
|
27
36
|
reference(id: string): AgentSessionReference;
|
|
28
37
|
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, rmdirSync, rmSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { canonical, object } from "../common/json.js";
|
|
5
5
|
import { isOneOf, 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 { agentStates,
|
|
9
|
-
import {
|
|
8
|
+
import { agentStates, cycleStates, messageDeliveries } from "../model/agent.js";
|
|
9
|
+
import { acpConfig, acpInteraction, acpReference } from "./acp-files.js";
|
|
10
10
|
const text = (v) => typeof v === "string" && v.length > 0;
|
|
11
11
|
const number = (v) => typeof v === "number" && Number.isFinite(v);
|
|
12
|
-
export function
|
|
13
|
-
requireThat(object(v) && text(v.agentId) && text(v.release) && text(v.workspace) && text(v.
|
|
14
|
-
(v.
|
|
12
|
+
export function workerRecord(v) {
|
|
13
|
+
requireThat(object(v) && text(v.agentId) && text(v.release) && text(v.workspace) && text(v.parentSessionId) &&
|
|
14
|
+
text(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.stop === "boolean" && number(v.startedAt) &&
|
|
15
|
+
(v.pid === undefined || (Number.isSafeInteger(v.pid) && Number(v.pid) > 1)) &&
|
|
16
|
+
(v.options === undefined || object(v.options)), "worker 控制记录无效。");
|
|
15
17
|
fileId(v.agentId);
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export function launch(v) {
|
|
19
|
-
requireThat(object(v) && text(v.generation) && text(v.name) && Number.isSafeInteger(v.sequence) && typeof v.stop === "boolean" && number(v.startedAt), "子会话启动状态无效。");
|
|
18
|
+
acpConfig(v.acp);
|
|
20
19
|
return v;
|
|
21
20
|
}
|
|
22
21
|
export function message(v) {
|
|
@@ -26,18 +25,72 @@ export function message(v) {
|
|
|
26
25
|
}
|
|
27
26
|
export function cycle(v) {
|
|
28
27
|
requireThat(object(v) && text(v.cycleId) && text(v.generation) && number(v.startedAt) &&
|
|
29
|
-
isOneOf(v.state, cycleStates) &&
|
|
30
|
-
(v.
|
|
31
|
-
|
|
28
|
+
isOneOf(v.state, cycleStates) && Array.isArray(v.requestIds) && v.requestIds.every(text) &&
|
|
29
|
+
(v.finishedAt === undefined || number(v.finishedAt)) &&
|
|
30
|
+
(v.error === undefined || typeof v.error === "string"), "子会话周期无效。");
|
|
32
31
|
return v;
|
|
33
32
|
}
|
|
34
33
|
export function status(v) {
|
|
35
34
|
requireThat(object(v) && text(v.generation) && isOneOf(v.state, agentStates) &&
|
|
36
35
|
typeof v.activity === "string" && number(v.updatedAt), "子会话状态无效。");
|
|
37
|
-
if (v.
|
|
36
|
+
if (v.sessionId !== undefined)
|
|
37
|
+
requireThat(v.sessionId === null || text(v.sessionId), "ACP 会话 ID 无效。");
|
|
38
|
+
if (v.capabilities !== undefined) {
|
|
39
|
+
requireThat(object(v.capabilities) &&
|
|
40
|
+
["resume", "load", "close"].every(key => typeof v.capabilities[key] === "boolean"), "ACP 会话能力无效。");
|
|
41
|
+
}
|
|
42
|
+
if (v.selection !== undefined) {
|
|
43
|
+
requireThat(object(v.selection) &&
|
|
44
|
+
["provider", "model", "resolvedModel", "thinking"].every(key => v.selection[key] === undefined || text(v.selection[key])), "ACP 模型选择无效。");
|
|
45
|
+
}
|
|
46
|
+
if (v.activeRequestId !== undefined) {
|
|
47
|
+
requireThat(text(v.activeRequestId), "ACP 输入关联无效。");
|
|
48
|
+
fileId(v.activeRequestId);
|
|
49
|
+
}
|
|
50
|
+
if (v.accepted !== undefined)
|
|
51
|
+
requireThat(Array.isArray(v.accepted) && v.accepted.every(text), "已领取请求列表无效。");
|
|
52
|
+
if (v.cycle !== undefined)
|
|
38
53
|
cycle(v.cycle);
|
|
54
|
+
if (v.error !== undefined)
|
|
55
|
+
requireThat(typeof v.error === "string", "子会话错误信息无效。");
|
|
56
|
+
return v;
|
|
57
|
+
}
|
|
58
|
+
export function outputRecord(v) {
|
|
59
|
+
requireThat(object(v) && text(v.cycleId) && text(v.generation) && number(v.startedAt) && number(v.finishedAt) &&
|
|
60
|
+
isOneOf(v.state, ["completed", "failed", "cancelled", "interrupted"]) &&
|
|
61
|
+
Array.isArray(v.requestIds) && v.requestIds.every(text) &&
|
|
62
|
+
typeof v.text === "string" && (v.error === undefined || typeof v.error === "string"), "子会话输出记录无效。");
|
|
63
|
+
fileId(v.cycleId);
|
|
39
64
|
return v;
|
|
40
65
|
}
|
|
66
|
+
export function toDescriptor(record) {
|
|
67
|
+
return {
|
|
68
|
+
agentId: record.agentId,
|
|
69
|
+
release: record.release,
|
|
70
|
+
workspace: record.workspace,
|
|
71
|
+
parentSessionId: record.parentSessionId,
|
|
72
|
+
options: record.options ?? {},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function tryUnlink(path) {
|
|
76
|
+
try {
|
|
77
|
+
unlinkSync(path);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error.code !== "ENOENT")
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function tryRmdir(path) {
|
|
85
|
+
try {
|
|
86
|
+
rmdirSync(path);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const code = error.code;
|
|
90
|
+
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST")
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
41
94
|
export class AgentFiles {
|
|
42
95
|
root;
|
|
43
96
|
#failure;
|
|
@@ -72,56 +125,105 @@ export class AgentFiles {
|
|
|
72
125
|
}
|
|
73
126
|
requireThat(published, "子会话文件已存在。");
|
|
74
127
|
}
|
|
128
|
+
remove(id, path) {
|
|
129
|
+
tryUnlink(join(this.directory(id), path));
|
|
130
|
+
}
|
|
75
131
|
create(value, run, acp) {
|
|
76
132
|
this.check();
|
|
77
133
|
acpReference(acp);
|
|
78
134
|
mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
79
135
|
mkdirSync(this.directory(value.agentId), { mode: 0o700 });
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
136
|
+
const hasOptions = Object.keys(value.options).length > 0;
|
|
137
|
+
const record = {
|
|
138
|
+
agentId: value.agentId,
|
|
139
|
+
release: value.release,
|
|
140
|
+
workspace: value.workspace,
|
|
141
|
+
parentSessionId: value.parentSessionId,
|
|
142
|
+
generation: run.generation,
|
|
143
|
+
sequence: run.sequence,
|
|
144
|
+
stop: run.stop,
|
|
145
|
+
startedAt: run.startedAt,
|
|
146
|
+
acp: {
|
|
147
|
+
backend: acp.backend,
|
|
148
|
+
command: acp.command,
|
|
149
|
+
args: acp.args,
|
|
150
|
+
...(acp.env ? { env: acp.env } : {}),
|
|
151
|
+
...(acp.permission ? { permission: acp.permission } : {}),
|
|
152
|
+
},
|
|
153
|
+
...(hasOptions ? { options: value.options } : {}),
|
|
154
|
+
};
|
|
155
|
+
this.write(value.agentId, "worker.json", record, workerRecord, true);
|
|
156
|
+
}
|
|
157
|
+
worker(id) {
|
|
158
|
+
return this.read(id, "worker.json", workerRecord);
|
|
85
159
|
}
|
|
86
160
|
list() {
|
|
87
161
|
if (!existsSync(this.root))
|
|
88
162
|
return [];
|
|
89
163
|
return readdirSync(this.root, { withFileTypes: true }).filter(e => e.isDirectory() && !e.name.startsWith(".")).flatMap(e => {
|
|
90
|
-
const
|
|
91
|
-
return
|
|
164
|
+
const record = this.optional(e.name, "worker.json", workerRecord);
|
|
165
|
+
return record ? [record] : [];
|
|
92
166
|
});
|
|
93
167
|
}
|
|
94
168
|
messages(id) {
|
|
95
|
-
|
|
169
|
+
const dir = join(this.directory(id), "inbox");
|
|
170
|
+
if (!existsSync(dir))
|
|
171
|
+
return [];
|
|
172
|
+
return readdirSync(dir).filter(n => n.endsWith(".json"))
|
|
96
173
|
.map(n => this.read(id, "inbox/" + n, message)).sort((a, b) => a.sequence - b.sequence);
|
|
97
174
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
175
|
+
removeMessage(id, requestId) {
|
|
176
|
+
fileId(requestId);
|
|
177
|
+
const dir = join(this.directory(id), "inbox");
|
|
178
|
+
tryUnlink(join(dir, requestId + ".json"));
|
|
179
|
+
tryRmdir(dir);
|
|
101
180
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const dir = join(this.directory(id), "permissions");
|
|
105
|
-
if (!existsSync(dir))
|
|
106
|
-
return [];
|
|
107
|
-
const names = readdirSync(dir);
|
|
108
|
-
return names.filter(n => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json"))
|
|
109
|
-
.map(n => this.read(id, "permissions/" + n, acpPermission)).filter(item => item.generation === generation);
|
|
181
|
+
output(id) {
|
|
182
|
+
return this.optional(id, "output.json", outputRecord);
|
|
110
183
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const dir = join(this.directory(id), "elicitations");
|
|
184
|
+
pendingInteractions(id, generation) {
|
|
185
|
+
const dir = join(this.directory(id), "interactions");
|
|
114
186
|
if (!existsSync(dir))
|
|
115
187
|
return [];
|
|
116
188
|
const names = readdirSync(dir);
|
|
117
189
|
return names.filter(n => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json"))
|
|
118
|
-
.map(n => this.read(id, "
|
|
190
|
+
.map(n => this.read(id, "interactions/" + n, acpInteraction)).filter(item => item.generation === generation);
|
|
191
|
+
}
|
|
192
|
+
removeInteraction(id, requestId) {
|
|
193
|
+
fileId(requestId);
|
|
194
|
+
const dir = join(this.directory(id), "interactions");
|
|
195
|
+
tryUnlink(join(dir, requestId + ".json"));
|
|
196
|
+
tryUnlink(join(dir, requestId + "-reply.json"));
|
|
197
|
+
tryRmdir(dir);
|
|
198
|
+
}
|
|
199
|
+
clearTransient(id) {
|
|
200
|
+
const base = this.directory(id);
|
|
201
|
+
if (!existsSync(base))
|
|
202
|
+
return;
|
|
203
|
+
rmSync(join(base, "inbox"), { recursive: true, force: true });
|
|
204
|
+
rmSync(join(base, "interactions"), { recursive: true, force: true });
|
|
205
|
+
tryUnlink(join(base, "acp-answer.json"));
|
|
206
|
+
}
|
|
207
|
+
removeWorker(id) {
|
|
208
|
+
rmSync(this.directory(id), { recursive: true, force: true });
|
|
209
|
+
tryRmdir(this.root);
|
|
119
210
|
}
|
|
120
211
|
ensureSubdirectory(id, name) {
|
|
121
212
|
privateDirectory(this.directory(id), name);
|
|
122
213
|
}
|
|
123
214
|
reference(id) {
|
|
124
|
-
|
|
215
|
+
const w = this.worker(id);
|
|
216
|
+
const saved = this.optional(id, "state.json", status);
|
|
217
|
+
return {
|
|
218
|
+
host: "acp",
|
|
219
|
+
backend: w.acp.backend,
|
|
220
|
+
command: w.acp.command,
|
|
221
|
+
args: w.acp.args,
|
|
222
|
+
...(w.acp.env ? { env: w.acp.env } : {}),
|
|
223
|
+
...(w.acp.permission ? { permission: w.acp.permission } : {}),
|
|
224
|
+
sessionId: saved?.sessionId ?? null,
|
|
225
|
+
...(saved?.capabilities ? { capabilities: saved.capabilities } : {}),
|
|
226
|
+
};
|
|
125
227
|
}
|
|
126
228
|
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
127
229
|
control(work) {
|
|
@@ -145,14 +247,16 @@ export class AgentFiles {
|
|
|
145
247
|
}
|
|
146
248
|
enqueue(id, text, delivery, files = [], requestId = randomUUID()) {
|
|
147
249
|
fileId(requestId);
|
|
148
|
-
const
|
|
250
|
+
const w = this.worker(id);
|
|
251
|
+
const previous = this.optional(id, "inbox/" + requestId + ".json", message);
|
|
149
252
|
if (previous) {
|
|
150
|
-
requireThat(previous.generation ===
|
|
253
|
+
requireThat(previous.generation === w.generation && previous.message === text && previous.delivery === delivery && canonical(previous.files) === canonical(files), "请求 ID 已被不同输入使用。");
|
|
151
254
|
return previous;
|
|
152
255
|
}
|
|
153
|
-
|
|
154
|
-
this.write(id, "
|
|
155
|
-
|
|
256
|
+
w.sequence++;
|
|
257
|
+
this.write(id, "worker.json", w, workerRecord);
|
|
258
|
+
this.ensureSubdirectory(id, "inbox");
|
|
259
|
+
const value = { requestId, generation: w.generation, sequence: w.sequence, message: text, delivery, files };
|
|
156
260
|
this.write(id, "inbox/" + value.requestId + ".json", value, message, true);
|
|
157
261
|
return value;
|
|
158
262
|
}
|