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
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
2
|
import { parseSessionEntries, SessionManager, type ExtensionContext, type SessionEntry, type SessionMessageEntry } from "@earendil-works/pi-coding-agent";
|
|
4
3
|
import type { HistoryExchange, HistoryLocation, HistorySession, HistorySource, HistorySummarizer } from "../../model/history.js";
|
|
5
4
|
import { requireThat } from "../../common/validation.js";
|
|
6
|
-
import { resourceRoot } from "../../common/paths.js";
|
|
7
5
|
import { reduceHistorySummary } from "../history-summary.js";
|
|
8
6
|
|
|
9
7
|
function text(content: unknown): string {
|
|
@@ -11,30 +9,32 @@ function text(content: unknown): string {
|
|
|
11
9
|
if (!Array.isArray(content)) return "";
|
|
12
10
|
return content.flatMap(block => block.type === "text" ? [String(block.text)] : block.type === "image" ? ["[图片]"] : []).join("\n");
|
|
13
11
|
}
|
|
14
|
-
function exchanges(branch: SessionEntry[])
|
|
15
|
-
const result: HistoryExchange[] = [];
|
|
16
|
-
let users: SessionMessageEntry[] = [], partial: SessionMessageEntry | undefined;
|
|
12
|
+
function exchanges(branch: SessionEntry[]) {
|
|
13
|
+
const result: HistoryExchange[] = [], supersededEntryIds: string[] = [];
|
|
14
|
+
let users: SessionMessageEntry[] = [], partial: SessionMessageEntry | undefined, observed: string[] = [];
|
|
17
15
|
const finish = (answer?: SessionMessageEntry, completed = false) => {
|
|
18
16
|
if (!users.length) return;
|
|
19
17
|
const entries = [...users, ...(answer ? [answer] : [])];
|
|
20
18
|
result.push({ entryIds: entries.map(entry => entry.id), from: users[0]!.timestamp, to: entries.at(-1)!.timestamp, completed,
|
|
21
19
|
text: users.map(entry => "用户:\n" + text("content" in entry.message ? entry.message.content : "")).join("\n\n") +
|
|
22
20
|
(answer && "content" in answer.message ? "\n\n助手:\n" + text(answer.message.content) : "") });
|
|
23
|
-
|
|
21
|
+
supersededEntryIds.push(...observed.filter(id => id !== entries.at(-1)!.id));
|
|
22
|
+
users = []; partial = undefined; observed = [];
|
|
24
23
|
};
|
|
25
24
|
for (const entry of branch) {
|
|
26
25
|
if (entry.type !== "message") continue;
|
|
27
26
|
const message = entry.message;
|
|
28
27
|
if (message.role === "user") {
|
|
29
28
|
if (partial?.message.role === "assistant" && ["aborted", "error"].includes(partial.message.stopReason)) finish(partial);
|
|
29
|
+
if (!partial) observed.push(entry.id);
|
|
30
30
|
users.push(entry);
|
|
31
31
|
} else if (message.role === "assistant" && users.length) {
|
|
32
|
-
partial = entry;
|
|
32
|
+
partial = entry; observed.push(entry.id);
|
|
33
33
|
if (message.stopReason === "stop" && !message.content.some(block => block.type === "toolCall")) finish(entry, true);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
finish(partial);
|
|
37
|
-
return result;
|
|
37
|
+
return { exchanges: result, supersededEntryIds };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** Parse in memory; never open a writable SessionManager or migrate native JSONL. */
|
|
@@ -44,18 +44,20 @@ export function projectHistory(content: string): HistorySession {
|
|
|
44
44
|
const manager = SessionManager.inMemory(header.cwd, undefined, parsed), entries = manager.getEntries();
|
|
45
45
|
const parents = new Set(entries.map(entry => entry.parentId));
|
|
46
46
|
const tips = entries.filter(entry => !parents.has(entry.id));
|
|
47
|
-
|
|
47
|
+
const branches = tips.map(tip => exchanges(manager.getBranch(tip.id)));
|
|
48
|
+
return { sessionId: header.id, name: manager.getSessionName() ?? "", branches: branches.map(value => value.exchanges).filter(branch => branch.length),
|
|
49
|
+
supersededEntryIds: [...new Set(branches.flatMap(value => value.supersededEntryIds))] };
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export const historyLocation = (ctx: ExtensionContext): HistoryLocation => {
|
|
51
53
|
const file = ctx.sessionManager.getSessionFile();
|
|
52
|
-
return { directory: ctx.sessionManager.getSessionDir(), ...(file ? { file } : {}) };
|
|
54
|
+
return { host: "pi", directory: ctx.sessionManager.getSessionDir(), ...(file ? { file } : {}) };
|
|
53
55
|
};
|
|
54
56
|
export class PiHistory implements HistorySource {
|
|
55
57
|
readonly host = "pi";
|
|
56
58
|
constructor(private readonly root: string, private readonly relatedFiles: () => string[] = () => []) {}
|
|
57
59
|
async scan(location: HistoryLocation, signal?: AbortSignal) {
|
|
58
|
-
requireThat(location.host
|
|
60
|
+
requireThat(location.host === "pi", "Pi 历史只读取 Pi 原生会话。");
|
|
59
61
|
const lists = await Promise.all([SessionManager.list(this.root, undefined, undefined, signal),
|
|
60
62
|
SessionManager.list(this.root, location.directory, undefined, signal)]);
|
|
61
63
|
const files = new Set([...lists.flat().map(session => session.path), ...this.relatedFiles(), ...(location.file ? [location.file] : [])]);
|
|
@@ -81,12 +83,11 @@ export class PiHistory implements HistorySource {
|
|
|
81
83
|
export async function historySummarizer(ctx: ExtensionContext): Promise<HistorySummarizer> {
|
|
82
84
|
const model = ctx.model;
|
|
83
85
|
requireThat(model, "请先选择 Pi 模型。");
|
|
84
|
-
const systemPrompt = await readFile(join(resourceRoot, "prompts/history-summary.md"), "utf8");
|
|
85
86
|
const budget = Math.max(2000, Math.min(24000, Math.floor(model.contextWindow / 2)));
|
|
86
|
-
const ask = async (
|
|
87
|
+
const ask: HistorySummarizer = async ({ system, prompt, maxTokens }, signal) => {
|
|
87
88
|
signal.throwIfAborted();
|
|
88
|
-
const response = await ctx.modelRegistry.streamSimple(model, { systemPrompt,
|
|
89
|
-
messages: [{ role: "user", content, timestamp: Date.now() }] }, { signal, reasoning: "low", maxTokens
|
|
89
|
+
const response = await ctx.modelRegistry.streamSimple(model, { systemPrompt: system,
|
|
90
|
+
messages: [{ role: "user", content: prompt, timestamp: Date.now() }] }, { signal, reasoning: "low", maxTokens, transport: "sse" }).result();
|
|
90
91
|
signal.throwIfAborted();
|
|
91
92
|
requireThat(response.stopReason === "stop", response.errorMessage ?? "历史摘要未完成:" + response.stopReason);
|
|
92
93
|
const answer = response.content.filter(part => part.type === "text").map(part => part.text).join("\n").trim();
|
|
@@ -4,7 +4,7 @@ import { existsSync, lstatSync, readFileSync } from "node:fs";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { CURRENT_SESSION_VERSION, getAgentDir, getPackageDir, parseSessionEntries, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { requireThat } from "../../common/validation.js";
|
|
7
|
-
import type { AgentDescriptor, AgentSessionReference } from "../../model/agent.js";
|
|
7
|
+
import type { AgentDescriptor, AgentOptions, AgentSessionReference } from "../../model/agent.js";
|
|
8
8
|
import type { AgentHost } from "../../services/agents/agent-service.js";
|
|
9
9
|
|
|
10
10
|
export const agentDirectory = () => join(getAgentDir(), "pbot/subagents");
|
|
@@ -26,6 +26,9 @@ export class PiAgents implements AgentHost {
|
|
|
26
26
|
requireThat(reference.host === "pi", "不能接管其他宿主的会话。");
|
|
27
27
|
return reference.file;
|
|
28
28
|
}
|
|
29
|
+
validateOptions(options: AgentOptions) {
|
|
30
|
+
requireThat(options.thinking === undefined || ["off", "minimal", "low", "medium", "high", "xhigh", "max"].includes(options.thinking), "Pi 思考级别无效。");
|
|
31
|
+
}
|
|
29
32
|
available() {
|
|
30
33
|
requireThat(spawnSync("tmux", ["-V"], { encoding: "utf8" }).status === 0, "子会话需要 tmux。");
|
|
31
34
|
requireThat(existsSync(join(getPackageDir(), "dist/cli.js")), "无法定位 Pi CLI。");
|
package/src/model/acp.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type AcpBackend = "pi" | "dsh" | "claude";
|
|
2
|
+
export interface AcpCommand { command: string; args: string[] }
|
|
3
|
+
export type AcpCommands = Partial<Record<AcpBackend, AcpCommand>>;
|
|
4
|
+
export interface AcpSessionReference extends AcpCommand {
|
|
5
|
+
host: "acp";
|
|
6
|
+
backend: AcpBackend;
|
|
7
|
+
sessionId: string | null;
|
|
8
|
+
capabilities?: { resume: boolean; load: boolean; close: boolean };
|
|
9
|
+
}
|
|
10
|
+
export interface AcpModelSelection { provider?: string; model?: string; resolvedModel?: string; thinking?: string }
|
|
11
|
+
export interface AcpModelState extends AcpModelSelection { generation: string }
|
|
12
|
+
export interface AcpProcess { generation: string; pid: number; startedAt: number }
|
|
13
|
+
export interface AcpInput { generation: string; requestId: string }
|
|
14
|
+
export interface AcpAnswer extends AcpInput {
|
|
15
|
+
answer: string;
|
|
16
|
+
state: "completed" | "failed" | "cancelled";
|
|
17
|
+
error?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AcpReport { generation: string; cycleId: string; text: string }
|
|
20
|
+
export interface AcpPermission {
|
|
21
|
+
generation: string;
|
|
22
|
+
requestId: string;
|
|
23
|
+
description: string;
|
|
24
|
+
options: { optionId: string; name: string; kind: string }[];
|
|
25
|
+
}
|
|
26
|
+
export interface AcpPermissionReply { generation: string; requestId: string; optionId: string | null }
|
package/src/model/agent.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { AcpBackend, AcpModelSelection, AcpSessionReference } from "./acp.js";
|
|
2
|
+
|
|
3
|
+
export interface AgentStartOptions extends AgentOptions { backend?: AcpBackend }
|
|
1
4
|
export interface AgentOptions {
|
|
2
5
|
name?: string; message?: string; files?: string[]; prompts?: string[];
|
|
3
6
|
provider?: string; model?: string; thinking?: string; cwd?: string; tools?: string[];
|
|
@@ -10,8 +13,9 @@ export interface AgentDescriptor {
|
|
|
10
13
|
}
|
|
11
14
|
/** null means no conversation input has been handed to Pi yet. */
|
|
12
15
|
export interface AgentSessionRef { file: string | null }
|
|
16
|
+
export type NativeAgentHost = "pi" | "dsh";
|
|
13
17
|
/** Native references are interpreted only by their owning host adapter. */
|
|
14
|
-
export type AgentSessionReference = { host: "pi"; file: string | null } | { host: "dsh"; sessionId: string };
|
|
18
|
+
export type AgentSessionReference = { host: "pi"; file: string | null } | { host: "dsh"; sessionId: string } | AcpSessionReference;
|
|
15
19
|
export interface AgentLaunch { generation: string; name: string; sequence: number; stop: boolean; startedAt: number }
|
|
16
20
|
export interface AgentMessage { requestId: string; generation: string; sequence: number; message: string; delivery: "steer" | "followUp"; files: string[] }
|
|
17
21
|
export interface AgentCycle {
|
|
@@ -26,6 +30,8 @@ export interface AgentStatus {
|
|
|
26
30
|
}
|
|
27
31
|
export interface AgentView extends AgentDescriptor {
|
|
28
32
|
name: string; generation: string; state: AgentStatus["state"]; activity: string;
|
|
33
|
+
backend?: AcpBackend; transport?: "native" | "acp"; selection?: AcpModelSelection;
|
|
34
|
+
capabilities?: { steer: boolean; resume: boolean; team: boolean; transcript: boolean };
|
|
29
35
|
cycle?: AgentCycle; error?: string; owned: boolean;
|
|
30
36
|
}
|
|
31
37
|
export interface AgentCompletion { agentId: string; name: string; cycle: AgentCycle; report: string }
|
package/src/model/history.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface HistorySession {
|
|
|
9
9
|
sessionId: string;
|
|
10
10
|
name: string;
|
|
11
11
|
branches: HistoryExchange[][];
|
|
12
|
+
/** Earlier partial observations replaced along the same native branch or turn; never persisted. */
|
|
13
|
+
supersededEntryIds?: string[];
|
|
12
14
|
}
|
|
13
15
|
export interface HistoryNode extends HistoryExchange {
|
|
14
16
|
id: string;
|
|
@@ -25,10 +27,16 @@ export interface HistoryRecord {
|
|
|
25
27
|
name: string;
|
|
26
28
|
nodes: HistoryNode[];
|
|
27
29
|
}
|
|
28
|
-
export type HistoryHost = "pi" | "dsh";
|
|
29
|
-
export type HistoryLocation = { host
|
|
30
|
+
export type HistoryHost = "pi" | "dsh" | "claude";
|
|
31
|
+
export type HistoryLocation = { host: "pi"; directory: string; file?: string } |
|
|
32
|
+
{ host: "dsh"; sessionId?: string };
|
|
30
33
|
export interface HistorySource {
|
|
31
|
-
readonly host:
|
|
34
|
+
readonly host: HistoryLocation["host"];
|
|
32
35
|
scan(location: HistoryLocation, signal?: AbortSignal): Promise<{ sessions: HistorySession[]; warnings: string[] }>;
|
|
33
36
|
}
|
|
34
|
-
export
|
|
37
|
+
export interface HistorySummaryRequest {
|
|
38
|
+
system: string;
|
|
39
|
+
prompt: string;
|
|
40
|
+
maxTokens: number;
|
|
41
|
+
}
|
|
42
|
+
export type HistorySummarizer = (request: HistorySummaryRequest, signal: AbortSignal) => Promise<string>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { AcpCommands } from "./acp.js";
|
|
2
|
+
|
|
1
3
|
export interface WorkspaceConfig {
|
|
2
4
|
enabled?: boolean;
|
|
5
|
+
acp?: AcpCommands;
|
|
3
6
|
}
|
|
4
7
|
|
|
5
8
|
export interface WorkspaceConfiguration {
|
|
@@ -7,4 +10,5 @@ export interface WorkspaceConfiguration {
|
|
|
7
10
|
present: boolean;
|
|
8
11
|
enabled: boolean;
|
|
9
12
|
error?: string;
|
|
13
|
+
acp?: AcpCommands;
|
|
10
14
|
}
|
package/src/pbot.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { PiAgents, agentDirectory } from "./integrations/pi/pi-agents.js";
|
|
3
|
+
import { AgentBackends } from "./integrations/acp/agents.js";
|
|
3
4
|
import { PythonEnvironmentService } from "./services/workspace/python-environment-service.js";
|
|
4
5
|
import { AgentService } from "./services/agents/agent-service.js";
|
|
5
6
|
import { TeamService } from "./services/agents/team-service.js";
|
|
@@ -20,13 +21,13 @@ export default function pbot(pi: ExtensionAPI) {
|
|
|
20
21
|
// The explicitly loaded child entry owns the child; normal discovery never grants main privileges.
|
|
21
22
|
if (process.env.PBOT_SUBAGENT_RUN_ID) return;
|
|
22
23
|
const confirmations = new Confirmations(), registry = new ToolRegistry(pi);
|
|
23
|
-
const lifecycle = new Lifecycle(root => {
|
|
24
|
-
const agents = new AgentService(root, agentDirectory(), new PiAgents());
|
|
25
|
-
const history = new HistoryService(root, new HistoryFiles(join(root, ".pbot/history")), new PiHistory(root, () =>
|
|
24
|
+
const lifecycle = new Lifecycle((root, configuration) => {
|
|
25
|
+
const agents = new AgentService(root, agentDirectory(), new AgentBackends(new PiAgents(), agentDirectory(), configuration.acp));
|
|
26
|
+
const history = new HistoryService(root, new HistoryFiles(join(root, ".pbot/history"), "pi"), new PiHistory(root, () =>
|
|
26
27
|
agents.files.list().filter(agent => agent.workspace === root).flatMap(agent => {
|
|
27
28
|
const file = agents.files.optional(agent.agentId, "session-ref.json", sessionRef)?.file;
|
|
28
29
|
return file ? [file] : [];
|
|
29
|
-
})), new HistoryFiles(join(root, ".pbot/history"), "dsh"));
|
|
30
|
+
})), [new HistoryFiles(join(root, ".pbot/history"), "dsh"), new HistoryFiles(join(root, ".pbot/history"), "claude")]);
|
|
30
31
|
return new WorkspaceInstance(root, new PythonEnvironmentService(root), agents, new TeamService(root, agents.files, agents.teamFiles), history);
|
|
31
32
|
}, instance => registry.register(mainTools(instance.agents, instance.teams, instance.history, instance)), () => registry.hide());
|
|
32
33
|
registerCommand(pi, lifecycle, confirmations);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
+
import type { AgentDescriptor, AgentMessage } from "../../model/agent.js";
|
|
4
|
+
import type { AcpAnswer, AcpPermission } from "../../model/acp.js";
|
|
5
|
+
import { AgentFiles, launch } from "../../storage/agent-files.js";
|
|
6
|
+
import { acpAnswer, acpInput, acpPermission, acpPermissionReply, acpReport } from "../../storage/acp-files.js";
|
|
7
|
+
import { AgentRun } from "./agent-run.js";
|
|
8
|
+
|
|
9
|
+
export interface AcpProgress { kind: "text" | "thought" | "tool" | "activity"; text?: string; messageId?: string; activity?: string }
|
|
10
|
+
export class AcpAnswerBuffer {
|
|
11
|
+
#text = "";
|
|
12
|
+
#messageId: string | undefined;
|
|
13
|
+
get text() { return this.#text; }
|
|
14
|
+
reset() { this.#text = ""; this.#messageId = undefined; }
|
|
15
|
+
update(value: AcpProgress) {
|
|
16
|
+
if (value.kind === "tool") this.reset();
|
|
17
|
+
if (value.kind !== "text") return;
|
|
18
|
+
if (value.messageId && value.messageId !== this.#messageId) this.#text = "";
|
|
19
|
+
this.#messageId = value.messageId; this.#text += value.text ?? "";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export interface AcpWork {
|
|
23
|
+
readonly signal: AbortSignal;
|
|
24
|
+
prompt(request: AgentMessage): Promise<{ stopReason: string }>;
|
|
25
|
+
cancel(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** ACP prompt completion is the receipt boundary; final reports publish before completions. */
|
|
29
|
+
export class AcpAgentRun {
|
|
30
|
+
readonly execution: AgentRun;
|
|
31
|
+
readonly #answer = new AcpAnswerBuffer();
|
|
32
|
+
#lastActivity = 0;
|
|
33
|
+
#stopping = false;
|
|
34
|
+
#work: Promise<void> | undefined;
|
|
35
|
+
#stop: Promise<void> | undefined;
|
|
36
|
+
#failure: unknown;
|
|
37
|
+
constructor(readonly files: AgentFiles, readonly descriptor: AgentDescriptor, readonly generation: string,
|
|
38
|
+
readonly work: AcpWork, readonly exactAnswer: boolean) {
|
|
39
|
+
this.execution = new AgentRun(files, descriptor.agentId, generation);
|
|
40
|
+
}
|
|
41
|
+
private get id() { return this.descriptor.agentId; }
|
|
42
|
+
private current() { return this.files.read(this.id, "launch.json", launch).generation === this.generation; }
|
|
43
|
+
update(value: AcpProgress) {
|
|
44
|
+
if (!this.execution.current || !this.current()) return;
|
|
45
|
+
this.#answer.update(value);
|
|
46
|
+
if (Date.now() - this.#lastActivity >= 500) {
|
|
47
|
+
this.#lastActivity = Date.now();
|
|
48
|
+
this.execution.save({ state: this.#stopping ? "stopping" : "busy", activity: value.activity ?? (value.kind === "text" ? "回答" : "思考") });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async permission(description: string, options: AcpPermission["options"], signal: AbortSignal): Promise<string | null> {
|
|
52
|
+
const requestId = randomUUID(), request = { generation: this.generation, requestId, description, options };
|
|
53
|
+
this.files.write(this.id, "permissions/" + requestId + ".json", request, acpPermission, true);
|
|
54
|
+
this.execution.save({ state: "busy", activity: "等待确认" });
|
|
55
|
+
while (!signal.aborted && !this.#stopping && this.current() && !this.files.read(this.id, "launch.json", launch).stop) {
|
|
56
|
+
const reply = this.files.optional(this.id, "permissions/" + requestId + "-reply.json", acpPermissionReply);
|
|
57
|
+
if (reply?.generation === this.generation) return reply.optionId;
|
|
58
|
+
await delay(100);
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
async run() {
|
|
63
|
+
this.execution.recover(); this.execution.save({ state: "idle", activity: "空闲" });
|
|
64
|
+
while (!this.#stopping && this.current() && !this.work.signal.aborted) {
|
|
65
|
+
this.files.check(); if (this.#failure) throw this.#failure;
|
|
66
|
+
if (this.files.read(this.id, "launch.json", launch).stop) { await this.stop(); break; }
|
|
67
|
+
if (!this.#work) {
|
|
68
|
+
const request = this.files.messages(this.id).find(message => message.generation === this.generation && !this.execution.accepted(message.requestId));
|
|
69
|
+
if (request) {
|
|
70
|
+
const pending = this.perform(request).finally(() => { if (this.#work === pending) this.#work = undefined; });
|
|
71
|
+
this.#work = pending;
|
|
72
|
+
void pending.catch(error => { this.#failure = error; });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
await delay(100);
|
|
76
|
+
}
|
|
77
|
+
if (!this.current() && !this.#stopping) await this.stop();
|
|
78
|
+
if (!this.#stopping) await this.#work;
|
|
79
|
+
if (this.work.signal.aborted && !this.#stopping) throw this.work.signal.reason;
|
|
80
|
+
}
|
|
81
|
+
private async perform(request: AgentMessage) {
|
|
82
|
+
this.#answer.reset();
|
|
83
|
+
this.execution.claim(request.requestId); this.execution.enter(request.requestId); this.execution.begin();
|
|
84
|
+
this.files.write(this.id, "acp-input.json", { generation: this.generation, requestId: request.requestId }, acpInput);
|
|
85
|
+
let result: AcpAnswer;
|
|
86
|
+
try {
|
|
87
|
+
const end = await this.work.prompt(request);
|
|
88
|
+
let snapshot: AcpAnswer | undefined;
|
|
89
|
+
if (this.exactAnswer) {
|
|
90
|
+
snapshot = this.files.optional(this.id, "acp-answer.json", acpAnswer);
|
|
91
|
+
if (snapshot?.generation !== this.generation || snapshot.requestId !== request.requestId) snapshot = undefined;
|
|
92
|
+
}
|
|
93
|
+
const answer = this.exactAnswer ? snapshot?.answer ?? "" : this.#answer.text;
|
|
94
|
+
const state = end.stopReason === "cancelled" || this.#stopping ? "cancelled" : end.stopReason === "end_turn" &&
|
|
95
|
+
(!this.exactAnswer || snapshot?.state === "completed") && answer.trim() ? "completed" : "failed";
|
|
96
|
+
if (state === "completed") this.execution.consume(request.requestId);
|
|
97
|
+
result = { generation: this.generation, requestId: request.requestId, state, answer,
|
|
98
|
+
...(state === "failed" ? { error: snapshot?.error ?? "ACP 工作未产生有效最终回答:" + end.stopReason } : {}) };
|
|
99
|
+
} catch (error) {
|
|
100
|
+
result = { generation: this.generation, requestId: request.requestId, answer: this.#answer.text,
|
|
101
|
+
state: this.#stopping || this.files.read(this.id, "launch.json", launch).stop ? "cancelled" : "failed", error: String(error) };
|
|
102
|
+
}
|
|
103
|
+
if (!this.current()) return;
|
|
104
|
+
const cycleId = this.execution.current!.cycleId;
|
|
105
|
+
this.files.write(this.id, "reports/" + cycleId + ".json", { generation: this.generation, cycleId, text: result.answer }, acpReport, true);
|
|
106
|
+
this.execution.finish({ state: this.work.signal.aborted && !this.#stopping ? "interrupted" : result.state,
|
|
107
|
+
position: "acp:" + cycleId, answer: result.answer, ...(result.error ? { error: result.error } : {}) });
|
|
108
|
+
}
|
|
109
|
+
settled() { return this.#work; }
|
|
110
|
+
stop(): Promise<void> {
|
|
111
|
+
return this.#stop ??= (async () => {
|
|
112
|
+
this.#stopping = true;
|
|
113
|
+
if (this.current()) this.execution.save({ state: "stopping", activity: "停止" });
|
|
114
|
+
const pending = this.#work;
|
|
115
|
+
if (!pending) return;
|
|
116
|
+
const grace = new AbortController();
|
|
117
|
+
try {
|
|
118
|
+
const cancelAndSettle = this.work.cancel().catch(() => {}).then(() => pending);
|
|
119
|
+
await Promise.race([cancelAndSettle, delay(4000, undefined, { signal: grace.signal })]);
|
|
120
|
+
} finally { grace.abort(); }
|
|
121
|
+
})();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { realpathSync } from "node:fs";
|
|
2
|
+
import { realpathSync, readdirSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { packageVersion, releaseLine } from "../../common/version.js";
|
|
5
5
|
import { requireThat } from "../../common/validation.js";
|
|
6
6
|
import { AgentFiles, descriptor, launch, status, cycle } from "../../storage/agent-files.js";
|
|
7
7
|
import { TeamFiles } from "../../storage/team-files.js";
|
|
8
8
|
import type { TeamAgent, TeamInput } from "../../model/team.js";
|
|
9
|
-
import type { AgentOwner, AgentOptions, AgentDescriptor, AgentCycle, AgentCompletion, AgentSessionReference } from "../../model/agent.js";
|
|
9
|
+
import type { AgentOwner, AgentOptions, AgentStartOptions, AgentDescriptor, AgentCycle, AgentCompletion, AgentSessionReference, NativeAgentHost } from "../../model/agent.js";
|
|
10
|
+
import type { AcpBackend, AcpSessionReference } from "../../model/acp.js";
|
|
11
|
+
import { acpModelState, acpPermission, acpPermissionReply, acpReference } from "../../storage/acp-files.js";
|
|
10
12
|
|
|
11
13
|
export interface AgentHost {
|
|
12
|
-
readonly kind:
|
|
13
|
-
available(): void;
|
|
14
|
+
readonly kind: NativeAgentHost;
|
|
15
|
+
available(backend?: AcpBackend): void;
|
|
16
|
+
prepare?(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
|
|
17
|
+
validateOptions?(options: AgentOptions, backend?: AcpBackend): void;
|
|
14
18
|
alive(id: string): boolean;
|
|
15
19
|
validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
|
|
16
20
|
launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
|
|
@@ -51,15 +55,28 @@ export class AgentService {
|
|
|
51
55
|
const current = saved?.generation === run.generation ? saved : undefined;
|
|
52
56
|
const alive = this.alive(d.agentId), pending = this.#starting.get(d.agentId);
|
|
53
57
|
const starting = pending && !pending.controller.signal.aborted;
|
|
58
|
+
const reference = this.files.optional(d.agentId, "acp-session.json", acpReference);
|
|
59
|
+
const model = reference ? this.files.optional(d.agentId, "acp-model.json", acpModelState) : undefined;
|
|
60
|
+
const selection = model?.generation === run.generation ? { ...(model.provider ? { provider: model.provider } : {}),
|
|
61
|
+
...(model.model ? { model: model.model } : {}), ...(model.resolvedModel ? { resolvedModel: model.resolvedModel } : {}),
|
|
62
|
+
...(model.thinking ? { thinking: model.thinking } : {}) } : undefined;
|
|
54
63
|
return { ...d, name: run.name, generation: run.generation, owned: this.owned(d, owner), alive,
|
|
64
|
+
...(reference?.host === "acp" ? { backend: reference.backend, transport: "acp" as const,
|
|
65
|
+
capabilities: { steer: false, resume: Boolean(reference.capabilities?.resume || reference.capabilities?.load), team: false, transcript: false },
|
|
66
|
+
...(selection ? { selection } : {}) } : {}),
|
|
55
67
|
state: alive ? starting ? "starting" : run.stop || pending?.controller.signal.aborted ? "stopping" : current?.state ?? "starting" : current?.state === "error" ? "error" : "stopped",
|
|
56
68
|
activity: starting ? "启动" : alive ? current?.activity ?? "启动" : current?.error ?? "已停止",
|
|
57
69
|
...(current?.cycle ? { cycle: current.cycle } : {}), ...(current?.error ? { error: current.error } : {}) };
|
|
58
70
|
}
|
|
59
|
-
async start(
|
|
60
|
-
this.check();
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
async start(input: AgentStartOptions, owner: AgentOwner) {
|
|
72
|
+
this.check();
|
|
73
|
+
const { backend, ...supplied } = input;
|
|
74
|
+
this.host.available(backend);
|
|
75
|
+
const options: AgentOptions = Object.fromEntries(Object.entries(supplied).filter(([, v]) => v !== undefined));
|
|
76
|
+
this.host.validateOptions?.(options, backend);
|
|
77
|
+
requireThat(backend || options.provider && options.model, "请选择可在专家会话使用的模型。");
|
|
78
|
+
const reference = backend ? this.host.prepare?.(backend, options) : undefined;
|
|
79
|
+
requireThat(!backend || reference, "当前执行接入不支持 ACP 后端。");
|
|
63
80
|
const prepared = this.files.control(() => {
|
|
64
81
|
requireThat(this.list(owner).filter(v => v.alive).length < 50, "最多 50 个存活或启动中子会话;请先停止一个空闲会话。");
|
|
65
82
|
const agentId = randomUUID();
|
|
@@ -68,7 +85,7 @@ export class AgentService {
|
|
|
68
85
|
const d: AgentDescriptor = { agentId, release: packageVersion, workspace: this.root, cwd,
|
|
69
86
|
parentSessionId: owner.sessionId, parentLeaf: owner.leaf, createdAt: Date.now(), options: { ...options, files, cwd } };
|
|
70
87
|
const run = { generation: randomUUID(), name: options.name ?? agentId.slice(0, 8), sequence: 0, stop: false, startedAt: Date.now() };
|
|
71
|
-
this.files.create(d, run);
|
|
88
|
+
this.files.create(d, run, reference);
|
|
72
89
|
const initial = [options.message, ...(options.prompts ?? [])].filter(Boolean).join("\n\n");
|
|
73
90
|
const request = initial || files.length ? this.files.enqueue(agentId, initial, "steer", files) : undefined;
|
|
74
91
|
this.#starting.set(agentId, { generation: run.generation, controller: new AbortController(), stage: "launch" });
|
|
@@ -99,12 +116,15 @@ export class AgentService {
|
|
|
99
116
|
this.#launches.add(operation);
|
|
100
117
|
try { await operation; } finally { this.#launches.delete(operation); }
|
|
101
118
|
}
|
|
102
|
-
send(id: string, text: string, delivery: "steer" | "followUp", owner: AgentOwner) {
|
|
119
|
+
send(id: string, text: string, delivery: "steer" | "followUp", owner: AgentOwner, attachments: readonly string[] = []) {
|
|
103
120
|
const d = this.get(id, owner);
|
|
104
121
|
return this.files.control(() => {
|
|
105
122
|
requireThat(this.alive(id) && this.#starting.get(id)?.stage !== "validate" && !this.files.read(id, "launch.json", launch).stop, "子会话已停止或仍在恢复校验,请等待显式恢复完成。");
|
|
106
123
|
this.assertPrivate(id);
|
|
107
|
-
const
|
|
124
|
+
const view = this.view(d, owner);
|
|
125
|
+
requireThat(!(view.transport === "acp" && delivery === "steer" && view.state !== "idle"), "该子代理运行中不支持 steer;请用 delivery: followUp 排队。");
|
|
126
|
+
const files = attachments.map(path => realpathSync(resolve(this.root, path)));
|
|
127
|
+
const request = this.files.enqueue(id, text, delivery, files);
|
|
108
128
|
return { ...this.view(d, owner), requestId: request.requestId, messageStatus: "queued" as const };
|
|
109
129
|
});
|
|
110
130
|
}
|
|
@@ -160,7 +180,8 @@ export class AgentService {
|
|
|
160
180
|
return this.restart(id, owner, text);
|
|
161
181
|
}
|
|
162
182
|
private async restart(id: string, owner: AgentOwner, text?: string) {
|
|
163
|
-
const d = this.get(id, owner)
|
|
183
|
+
const d = this.get(id, owner), reference = this.files.reference(id);
|
|
184
|
+
this.host.available(reference.host === "acp" ? reference.backend : undefined);
|
|
164
185
|
const reserved = this.files.control(() => {
|
|
165
186
|
requireThat(!this.alive(id), "子会话仍在运行。");
|
|
166
187
|
this.assertPrivate(id);
|
|
@@ -240,6 +261,58 @@ export class AgentService {
|
|
|
240
261
|
if (c.leaf === null) return "";
|
|
241
262
|
return this.host.report(d, this.files.reference(d.agentId), c.leaf);
|
|
242
263
|
}
|
|
264
|
+
async recordPage(id: string, owner: AgentOwner, options: { seq?: number; offset?: number; limit?: number; textOffset?: number; textLimit?: number; format?: string } = {}) {
|
|
265
|
+
const d = this.get(id, owner), view = this.view(d, owner);
|
|
266
|
+
requireThat(view.transport === "acp", "该记录入口用于 ACP 成员。");
|
|
267
|
+
const messages = this.files.messages(id), cycles = this.cycles(id, owner).sort((a, b) => a.startedAt - b.startedAt);
|
|
268
|
+
const records: { seq: number; type: string; time: number; text: string; requestId?: string; cycleId?: string; state: string }[] = [];
|
|
269
|
+
const included = new Set<string>();
|
|
270
|
+
for (const c of cycles) {
|
|
271
|
+
for (const requestId of c.requestIds) {
|
|
272
|
+
const request = messages.find(message => message.requestId === requestId);
|
|
273
|
+
if (!request || included.has(requestId)) continue;
|
|
274
|
+
included.add(requestId);
|
|
275
|
+
records.push({ seq: records.length, type: "acp/input", time: c.startedAt, requestId, state: c.state,
|
|
276
|
+
text: [request.message, ...request.files.map(file => "附件:" + file)].filter(Boolean).join("\n\n") });
|
|
277
|
+
}
|
|
278
|
+
const report = await this.report(d, c); this.check();
|
|
279
|
+
records.push({ seq: records.length, type: "acp/report", time: c.finishedAt ?? c.startedAt, cycleId: c.cycleId, state: c.state,
|
|
280
|
+
text: [c.error, report].filter(Boolean).join("\n\n") });
|
|
281
|
+
}
|
|
282
|
+
const run = this.files.read(id, "launch.json", launch);
|
|
283
|
+
for (const request of messages.filter(message => message.generation === run.generation && !included.has(message.requestId))) {
|
|
284
|
+
records.push({ seq: records.length, type: "acp/input", time: run.startedAt, requestId: request.requestId, state: "queued",
|
|
285
|
+
text: [request.message, ...request.files.map(file => "附件:" + file)].filter(Boolean).join("\n\n") });
|
|
286
|
+
}
|
|
287
|
+
const cursor = run.generation + ":" + records.length + ":" + cycles.at(-1)?.state;
|
|
288
|
+
if (options.seq !== undefined) {
|
|
289
|
+
const record = records[options.seq]; requireThat(record, "ACP 记录位置不存在。");
|
|
290
|
+
const text = options.format === "json" ? JSON.stringify(record, null, 2) : record.text;
|
|
291
|
+
const offset = options.textOffset ?? 0, end = offset + (options.textLimit ?? 12000);
|
|
292
|
+
requireThat(offset <= text.length, "ACP 记录分页位置超出范围。");
|
|
293
|
+
return { kind: "acp", agent: view, cursor, seq: record.seq, offset, text: text.slice(offset, end), totalLength: text.length, nextOffset: end < text.length ? end : null };
|
|
294
|
+
}
|
|
295
|
+
const limit = options.limit ?? 30, offset = options.offset ?? Math.max(0, records.length - limit);
|
|
296
|
+
requireThat(offset <= records.length, "ACP 记录分页位置超出范围。");
|
|
297
|
+
return { kind: "acp", agent: view, cursor, total: records.length, offset, nextOffset: offset + limit < records.length ? offset + limit : null,
|
|
298
|
+
records: records.slice(offset, offset + limit).map(record => { const { text, ...fields } = record; return { ...fields, preview: text.slice(0, 800) }; }) };
|
|
299
|
+
}
|
|
300
|
+
pendingPermissions(owner: AgentOwner) {
|
|
301
|
+
return this.list(owner).filter(view => view.owned && view.alive && view.transport === "acp").flatMap(view =>
|
|
302
|
+
readdirSync(resolve(this.files.directory(view.agentId), "permissions")).filter(name => name.endsWith(".json") && !name.endsWith("-reply.json")).flatMap(name => {
|
|
303
|
+
const request = this.files.read(view.agentId, "permissions/" + name, acpPermission);
|
|
304
|
+
if (request.generation !== view.generation || this.files.optional(view.agentId, "permissions/" + request.requestId + "-reply.json", acpPermissionReply)) return [];
|
|
305
|
+
return [{ ...request, agentId: view.agentId, name: view.name }];
|
|
306
|
+
})).slice(0, 32);
|
|
307
|
+
}
|
|
308
|
+
answerPermission(id: string, requestId: string, optionId: string | null, owner: AgentOwner) {
|
|
309
|
+
this.get(id, owner);
|
|
310
|
+
const request = this.files.read(id, "permissions/" + requestId + ".json", acpPermission);
|
|
311
|
+
const run = this.files.read(id, "launch.json", launch);
|
|
312
|
+
requireThat(run.generation === request.generation && !run.stop && this.alive(id), "ACP 确认请求已失效。");
|
|
313
|
+
requireThat(optionId === null || request.options.some(option => option.optionId === optionId), "ACP 确认选项无效。");
|
|
314
|
+
this.files.write(id, "permissions/" + requestId + "-reply.json", { generation: run.generation, requestId, optionId }, acpPermissionReply, true);
|
|
315
|
+
}
|
|
243
316
|
private release(id: string) {
|
|
244
317
|
let pending = this.#releasing.get(id);
|
|
245
318
|
if (!pending) {
|
|
@@ -108,7 +108,8 @@ export class TeamService {
|
|
|
108
108
|
if (changed) this.files.save(team);
|
|
109
109
|
}
|
|
110
110
|
pauseAll(owner: AgentOwner, reason: string) {
|
|
111
|
-
|
|
111
|
+
if (!this.records(owner.sessionId).length) return;
|
|
112
|
+
this.agents.control(() => { for (const team of this.records(owner.sessionId)) this.pauseRecord(team, reason); });
|
|
112
113
|
}
|
|
113
114
|
recover(owner: AgentOwner) {
|
|
114
115
|
if (this.#recovered.has(owner.sessionId)) return;
|
|
@@ -201,7 +202,7 @@ export class TeamService {
|
|
|
201
202
|
});
|
|
202
203
|
}
|
|
203
204
|
advance(owner: AgentOwner, views: TeamAgent[], completions: AgentCompletion[]): TeamInput[] {
|
|
204
|
-
this.
|
|
205
|
+
if (!this.records(owner.sessionId).length) return [];
|
|
205
206
|
return this.agents.control(() => {
|
|
206
207
|
const inputs: TeamInput[] = [], records = this.records(owner.sessionId), links = this.files.links(records);
|
|
207
208
|
for (const team of records) {
|