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,28 +1,52 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
2
4
|
import type { HistoryExchange, HistoryHost, HistoryLocation, HistoryNode, HistoryRecord, HistorySession, HistorySource, HistorySummarizer } from "../../model/history.js";
|
|
3
5
|
import type { HistoryFiles } from "../../storage/history-files.js";
|
|
6
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
4
7
|
import { requireThat } from "../../common/validation.js";
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
const exchangeSource = (value: HistoryExchange) => [value.entryIds, value.text, value.from, value.to, value.completed];
|
|
10
|
+
|
|
11
|
+
/** Shared prefixes reuse nodes; a partial scan updates observed nodes and retains archived branches. */
|
|
7
12
|
export function indexHistory(session: HistorySession, previous?: HistoryRecord, host: HistoryHost = previous?.host ?? "pi"): HistoryRecord {
|
|
8
|
-
|
|
9
|
-
const
|
|
13
|
+
requireThat(!previous || previous.host === host && previous.sessionId === session.sessionId, "历史会话与归档来源不匹配。");
|
|
14
|
+
const id = previous?.id ?? (host === "pi" ? "" : host + "-") + randomUUID();
|
|
15
|
+
const old = new Map(previous?.nodes.map(node => [node.id, node]));
|
|
16
|
+
const nodes = new Map<string, HistoryNode>(previous?.nodes.filter(node => node.kind !== "session").map(node => [node.id, {
|
|
17
|
+
...node, entryIds: [...node.entryIds], children: [...node.children], parents: [],
|
|
18
|
+
}] satisfies [string, HistoryNode]));
|
|
19
|
+
const exchanges = session.branches.flat(), observedEnds = new Set(exchanges.map(value => value.entryIds.at(-1)));
|
|
20
|
+
const replaced = new Set(session.supersededEntryIds);
|
|
21
|
+
const superseded = new Set([...nodes.values()].filter(node => node.kind === "exchange" && !node.completed &&
|
|
22
|
+
!observedEnds.has(node.entryIds.at(-1)) && replaced.has(node.entryIds.at(-1)!) &&
|
|
23
|
+
exchanges.some(exchange => node.entryIds.slice(0, -1).every(entry => exchange.entryIds.includes(entry)))).map(node => node.id));
|
|
24
|
+
// Native adapters identify replaced observations along the same branch/turn. Preserve
|
|
25
|
+
// terminal forks and interrupted exchanges, then rebuild summaries that used old partials.
|
|
26
|
+
for (const node of [...nodes.values()].filter(node => node.kind === "summary").sort((a, b) => a.level - b.level)) {
|
|
27
|
+
if (node.children.some(id => superseded.has(id))) superseded.add(node.id);
|
|
28
|
+
}
|
|
29
|
+
for (const key of superseded) nodes.delete(key);
|
|
30
|
+
const observed = new Set<string>(), changed = new Set<string>();
|
|
10
31
|
const add = (value: HistoryExchange, level: number, children: string[] = []): HistoryNode => {
|
|
11
|
-
const key = `${id}:${level}:${value.entryIds.at(-1)}
|
|
12
|
-
if (
|
|
13
|
-
const before = old.get(key)
|
|
14
|
-
|
|
15
|
-
|
|
32
|
+
const key = `${id}:${level}:${value.entryIds.at(-1)}`;
|
|
33
|
+
if (observed.has(key)) return nodes.get(key)!;
|
|
34
|
+
const before = old.get(key);
|
|
35
|
+
if (!level && before && value.entryIds.length < before.entryIds.length &&
|
|
36
|
+
value.entryIds.every((entry, index) => entry === before.entryIds[before.entryIds.length - value.entryIds.length + index])) {
|
|
37
|
+
observed.add(key); return nodes.get(key)!;
|
|
38
|
+
}
|
|
39
|
+
const same = before && JSON.stringify(before.children) === JSON.stringify(children) &&
|
|
40
|
+
JSON.stringify(exchangeSource({ ...before, text: level ? "" : before.text })) === JSON.stringify(exchangeSource(value));
|
|
41
|
+
const node: HistoryNode = { ...value, entryIds: [...value.entryIds], id: key, kind: level ? "summary" : "exchange", level, children, parents: [],
|
|
16
42
|
text: level ? same ? before.text : "" : value.text, ready: level ? Boolean(same && before.ready) : true };
|
|
17
43
|
if (!same) changed.add(key);
|
|
18
|
-
nodes.set(key, node); return node;
|
|
44
|
+
observed.add(key); nodes.set(key, node); return node;
|
|
19
45
|
};
|
|
20
|
-
const roots = new Set<string>();
|
|
21
46
|
for (const branch of session.branches) {
|
|
22
47
|
let layer = branch.map(exchange => add(exchange, 0)), level = 1;
|
|
23
48
|
while (layer.length >= 4) {
|
|
24
49
|
const count = Math.floor(layer.length / 4) * 4, next: HistoryNode[] = [];
|
|
25
|
-
layer.slice(count).forEach(node => roots.add(node.id));
|
|
26
50
|
for (let i = 0; i < count; i += 4) {
|
|
27
51
|
const children = layer.slice(i, i + 4), first = children[0]!, last = children.at(-1)!;
|
|
28
52
|
next.push(add({ entryIds: [first.entryIds[0]!, last.entryIds.at(-1)!], text: "", from: first.from, to: last.to,
|
|
@@ -30,32 +54,43 @@ export function indexHistory(session: HistorySession, previous?: HistoryRecord,
|
|
|
30
54
|
}
|
|
31
55
|
layer = next; level++;
|
|
32
56
|
}
|
|
33
|
-
|
|
57
|
+
}
|
|
58
|
+
// Retained summaries can also depend on an observed prefix. Invalidate all affected ancestors.
|
|
59
|
+
for (const node of [...nodes.values()].filter(node => node.kind === "summary").sort((a, b) => a.level - b.level)) {
|
|
60
|
+
const children = node.children.map(id => nodes.get(id)!), first = children[0]!, last = children.at(-1)!;
|
|
61
|
+
const value = { entryIds: [first.entryIds[0]!, last.entryIds.at(-1)!], from: first.from, to: last.to,
|
|
62
|
+
completed: children.every(child => child.completed) };
|
|
63
|
+
if (children.some(child => changed.has(child.id))) { node.text = ""; node.ready = false; changed.add(node.id); }
|
|
64
|
+
Object.assign(node, value);
|
|
34
65
|
}
|
|
35
66
|
const dates = [...nodes.values()].flatMap(node => [node.from, node.to]).sort();
|
|
67
|
+
const nested = new Set([...nodes.values()].flatMap(node => node.children));
|
|
36
68
|
nodes.set(id, { id, kind: "session", level: -1, entryIds: [], text: session.name, ready: true, completed: [...nodes.values()].every(node => node.completed),
|
|
37
69
|
from: dates[0] ?? "", to: dates.at(-1) ?? "", parents: [],
|
|
38
|
-
children: [...
|
|
70
|
+
children: [...nodes.keys()].filter(key => !nested.has(key)).sort((a, b) => nodes.get(a)!.from.localeCompare(nodes.get(b)!.from)) });
|
|
39
71
|
for (const node of nodes.values()) for (const child of node.children) nodes.get(child)!.parents.push(node.id);
|
|
40
72
|
return { host, id, sessionId: session.sessionId, name: session.name, nodes: [...nodes.values()] };
|
|
41
73
|
}
|
|
42
74
|
|
|
43
75
|
export interface HistoryQuery { host?: HistoryHost; query?: string; sessionId?: string; from?: string; to?: string; offset?: number; limit?: number }
|
|
44
76
|
type LocatedRecord = { host: HistoryHost; record: HistoryRecord };
|
|
77
|
+
type HistoryReader = Pick<HistoryFiles, "host" | "list" | "warnings">;
|
|
45
78
|
const page = <T>(values: T[], offset: number, limit: number) => ({ values: values.slice(offset, offset + limit),
|
|
46
79
|
nextOffset: offset + limit < values.length ? offset + limit : null });
|
|
47
80
|
const brief = ({ host, record }: LocatedRecord, node: HistoryNode) => ({ host, id: node.id, kind: node.kind, sessionId: record.sessionId,
|
|
48
81
|
name: record.name, preview: node.text.replace(/\s+/g, " ").slice(0, 100), from: node.from, to: node.to, ready: node.ready, completed: node.completed });
|
|
49
82
|
const rawSource = (record?: HistoryRecord) => record && JSON.stringify({ name: record.name,
|
|
50
|
-
|
|
51
|
-
|
|
83
|
+
nodes: record.nodes.map(node => [node.id, node.kind, node.level, node.entryIds, node.children,
|
|
84
|
+
node.kind === "summary" ? "" : node.text, node.from, node.to, node.completed]) });
|
|
85
|
+
const summarySource = (node: HistoryNode) => [node.id, node.kind, node.level, node.entryIds, node.children, node.text, node.from, node.to, node.completed, node.ready];
|
|
52
86
|
|
|
53
|
-
/** Validate the exact
|
|
54
|
-
export function completeHistorySummary(record: HistoryRecord,
|
|
55
|
-
const node = record.nodes.find(value => value.id === id);
|
|
56
|
-
if (!node || node.kind !== "summary" || node.ready || JSON.stringify(node
|
|
87
|
+
/** Validate the exact target and ordered inputs again; another writer's ready summary wins. */
|
|
88
|
+
export function completeHistorySummary(record: HistoryRecord, expected: HistoryNode, children: readonly HistoryNode[], text: string) {
|
|
89
|
+
const node = record.nodes.find(value => value.id === expected.id);
|
|
90
|
+
if (!node || node.kind !== "summary" || node.ready || JSON.stringify(summarySource(node)) !== JSON.stringify(summarySource(expected)) ||
|
|
91
|
+
JSON.stringify(node.children) !== JSON.stringify(children.map(child => child.id))) return false;
|
|
57
92
|
const current = node.children.map(id => record.nodes.find(value => value.id === id));
|
|
58
|
-
if (current.some(value => !value) || JSON.stringify(current.map(value => summarySource(value!))) !== JSON.stringify(children.map(summarySource))) return false;
|
|
93
|
+
if (current.some(value => !value || !value.ready) || JSON.stringify(current.map(value => summarySource(value!))) !== JSON.stringify(children.map(summarySource))) return false;
|
|
59
94
|
requireThat(text.trim(), "历史摘要为空。");
|
|
60
95
|
node.text = text.trim(); node.ready = true; return true;
|
|
61
96
|
}
|
|
@@ -66,19 +101,22 @@ export class HistoryService {
|
|
|
66
101
|
#loaded = false;
|
|
67
102
|
#refresh: Promise<void> | undefined;
|
|
68
103
|
#work: Promise<void> | undefined;
|
|
104
|
+
readonly #controller = new AbortController();
|
|
69
105
|
#sourceWarnings: string[] = [];
|
|
70
106
|
#summaryError: string | undefined;
|
|
71
107
|
constructor(readonly root: string, private readonly files: HistoryFiles, private readonly source: HistorySource,
|
|
72
|
-
private readonly otherFiles
|
|
73
|
-
requireThat(source.host ===
|
|
108
|
+
private readonly otherFiles: readonly HistoryReader[] = []) {
|
|
109
|
+
requireThat((source.host === "pi" || source.host === "dsh") && source.host === files.host &&
|
|
110
|
+
new Set([files.host, ...otherFiles.map(value => value.host)]).size === otherFiles.length + 1,
|
|
111
|
+
"历史来源与归档目录不匹配。");
|
|
74
112
|
}
|
|
75
113
|
check() { requireThat(!this.#closed, "历史服务已关闭。"); }
|
|
76
|
-
get warnings() { return [...new Set([...this.#sourceWarnings, ...this.files.warnings, ...
|
|
114
|
+
get warnings() { return [...new Set([...this.#sourceWarnings, ...this.files.warnings, ...this.otherFiles.flatMap(value => value.warnings),
|
|
77
115
|
...(this.#summaryError ? [this.files.host + " 摘要:" + this.#summaryError] : [])])]; }
|
|
78
116
|
get status() { return { loaded: this.#loaded, organizing: Boolean(this.#work), pending: this.#loaded ? this.#records.filter(value => value.host === this.files.host)
|
|
79
117
|
.reduce((total, value) => total + value.record.nodes.filter(node => node.kind === "summary" && !node.ready).length, 0) : null, warnings: this.warnings }; }
|
|
80
118
|
refresh(location: HistoryLocation, signal?: AbortSignal): Promise<void> {
|
|
81
|
-
this.check();
|
|
119
|
+
this.check(); requireThat(location.host === this.source.host, "历史位置与来源不匹配。");
|
|
82
120
|
// Each caller keeps its own cancellation. A closed page cannot cancel a server-owned refresh.
|
|
83
121
|
const work = (this.#refresh ?? Promise.resolve()).catch(() => {}).then(() => this.load(location, signal));
|
|
84
122
|
this.#refresh = work;
|
|
@@ -118,10 +156,9 @@ export class HistoryService {
|
|
|
118
156
|
}
|
|
119
157
|
} catch (error) { warning(this.files.host, error); }
|
|
120
158
|
records.push(...known.map(record => ({ host: record.host, record })));
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
|
|
124
|
-
catch (error) { warning(this.otherFiles.host, error); }
|
|
159
|
+
for (const files of this.otherFiles) {
|
|
160
|
+
try { records.push(...files.list(this.root).map(record => ({ host: record.host, record }))); }
|
|
161
|
+
catch (error) { warning(files.host, error); }
|
|
125
162
|
}
|
|
126
163
|
this.check(); signal?.throwIfAborted(); this.#records = records; this.#sourceWarnings = warnings; this.#loaded = true;
|
|
127
164
|
}
|
|
@@ -159,26 +196,27 @@ export class HistoryService {
|
|
|
159
196
|
parents: node.parents.map(id => brief(value, lookup.get(id)!)), children: children.values.map(id => brief(value, lookup.get(id)!)),
|
|
160
197
|
nextChildrenOffset: children.nextOffset, source: { host: value.host, sessionId: value.record.sessionId, entryIds: node.entryIds }, warnings: this.warnings };
|
|
161
198
|
}
|
|
162
|
-
/**
|
|
199
|
+
/** Retain exact inputs only for this call; model work never holds the source write lock. */
|
|
163
200
|
organize(summarize: HistorySummarizer, signal: AbortSignal): Promise<void> {
|
|
164
201
|
this.check();
|
|
202
|
+
const active = AbortSignal.any([signal, this.#controller.signal]);
|
|
165
203
|
const run = async () => {
|
|
166
204
|
for (;;) {
|
|
167
|
-
this.check();
|
|
168
|
-
|
|
169
|
-
for (const record of this.files.list()) {
|
|
205
|
+
this.check(); active.throwIfAborted();
|
|
206
|
+
const pending = this.files.list().flatMap(record => {
|
|
170
207
|
const lookup = new Map(record.nodes.map(node => [node.id, node]));
|
|
171
208
|
const node = [...record.nodes].sort((a, b) => a.level - b.level).find(node => node.kind === "summary" && !node.ready && node.children.every(id => lookup.get(id)!.ready));
|
|
172
|
-
|
|
173
|
-
}
|
|
209
|
+
return node ? [{ record, node, children: node.children.map(id => lookup.get(id)!) }] : [];
|
|
210
|
+
})[0];
|
|
174
211
|
if (!pending) return;
|
|
175
212
|
const { record, node, children } = pending;
|
|
176
|
-
const text = await summarize(
|
|
177
|
-
|
|
213
|
+
const text = await summarize({ system: readFileSync(join(resourceRoot, "prompts/history-summary.md"), "utf8"), maxTokens: 2048,
|
|
214
|
+
prompt: children.map(child => `[${child.from} — ${child.to}${child.completed ? "" : ";未完成"}]\n${child.text}`).join("\n\n") }, active);
|
|
215
|
+
this.check(); active.throwIfAborted();
|
|
178
216
|
const committed = this.files.control(() => {
|
|
179
|
-
this.check();
|
|
180
|
-
const current = this.files.list().find(value => value.id === record.id);
|
|
181
|
-
if (!current || !completeHistorySummary(current, node
|
|
217
|
+
this.check(); active.throwIfAborted();
|
|
218
|
+
const current = this.files.list().find(value => value.id === record.id && value.sessionId === record.sessionId);
|
|
219
|
+
if (!current || !completeHistorySummary(current, node, children, text)) return;
|
|
182
220
|
this.files.save(current); return current;
|
|
183
221
|
});
|
|
184
222
|
if (!committed) return;
|
|
@@ -186,11 +224,14 @@ export class HistoryService {
|
|
|
186
224
|
}
|
|
187
225
|
};
|
|
188
226
|
const work = (this.#work ?? Promise.resolve()).catch(() => {}).then(run).then(() => { this.#summaryError = undefined; }).catch(error => {
|
|
189
|
-
if (!
|
|
227
|
+
if (!active.aborted && !this.#closed) this.#summaryError = String(error);
|
|
190
228
|
throw error;
|
|
191
229
|
});
|
|
192
230
|
this.#work = work;
|
|
193
231
|
return work.finally(() => { if (this.#work === work) this.#work = undefined; });
|
|
194
232
|
}
|
|
195
|
-
async close() {
|
|
233
|
+
async close() {
|
|
234
|
+
this.#closed = true; this.#controller.abort();
|
|
235
|
+
await Promise.allSettled([this.#work, this.#refresh]); this.#records = []; this.#loaded = false;
|
|
236
|
+
}
|
|
196
237
|
}
|
|
@@ -11,6 +11,30 @@ export class PythonEnvironmentService {
|
|
|
11
11
|
constructor(private readonly root: string) {}
|
|
12
12
|
get status() { return { ...this.#status }; }
|
|
13
13
|
|
|
14
|
+
private async run(checkOnly: boolean, signal: AbortSignal) {
|
|
15
|
+
const environment: Record<string, string> = {};
|
|
16
|
+
for (const [key, value] of Object.entries(process.env)) if (value !== undefined) environment[key] = value;
|
|
17
|
+
const result = await runCommand("/bin/sh", ["-c", 'exec "$(command -v python3 || command -v python)" "$@"',
|
|
18
|
+
"pbot-python", "-I", "-B", join(resourceRoot, "../scripts/setup-python.py"), ...(checkOnly ? ["--check"] : [])],
|
|
19
|
+
undefined, this.root, environment, signal, { timeoutMs: 15 * 60_000 });
|
|
20
|
+
signal.throwIfAborted();
|
|
21
|
+
requireThat(result.success && object(result.data) && typeof result.data.directory === "string" && typeof result.data.python === "string",
|
|
22
|
+
"共享 Python 环境未就绪;修复后执行 Python 准备入口。\n" + JSON.stringify(result.data).slice(-6000));
|
|
23
|
+
return { directory: result.data.directory, python: result.data.python, action: result.data.action };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async inspect(signal?: AbortSignal) {
|
|
27
|
+
const cancel = signal ? AbortSignal.any([this.#shutdown.signal, signal]) : this.#shutdown.signal;
|
|
28
|
+
try {
|
|
29
|
+
const result = await this.run(true, cancel);
|
|
30
|
+
this.#status = result.action === "verify" ? { state: "ready", directory: result.directory } : { state: "unprepared" };
|
|
31
|
+
return this.status;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
this.#status = { state: "error", error: error instanceof Error ? error.message : String(error) };
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
14
38
|
setup(signal?: AbortSignal): Promise<{ directory: string; python: string }> {
|
|
15
39
|
const cancel = signal ? AbortSignal.any([this.#shutdown.signal, signal]) : this.#shutdown.signal;
|
|
16
40
|
if (cancel.aborted) return Promise.reject(cancel.reason);
|
|
@@ -18,15 +42,8 @@ export class PythonEnvironmentService {
|
|
|
18
42
|
this.#status = { state: "preparing" };
|
|
19
43
|
this.#pending = (async () => {
|
|
20
44
|
try {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const result = await runCommand("/bin/sh", ["-c", 'exec "$(command -v python3 || command -v python)" "$@"',
|
|
24
|
-
"pbot-python", "-I", "-B", join(resourceRoot, "../scripts/setup-python.py")],
|
|
25
|
-
undefined, this.root, environment, cancel, { timeoutMs: 15 * 60_000 });
|
|
26
|
-
cancel.throwIfAborted();
|
|
27
|
-
requireThat(result.success && object(result.data) && typeof result.data.directory === "string" && typeof result.data.python === "string",
|
|
28
|
-
"共享 Python 环境未就绪;修复后执行 /pbot python setup。\n" + JSON.stringify(result.data).slice(-6000));
|
|
29
|
-
const ready = { directory: result.data.directory, python: result.data.python };
|
|
45
|
+
const result = await this.run(false, cancel);
|
|
46
|
+
const ready = { directory: result.directory, python: result.python };
|
|
30
47
|
this.#status = { state: "ready", directory: ready.directory };
|
|
31
48
|
return ready;
|
|
32
49
|
} catch (error) {
|
|
@@ -7,6 +7,14 @@ function config(value: unknown): Record<string, unknown> {
|
|
|
7
7
|
if (!object(value) || value.enabled !== undefined && typeof value.enabled !== "boolean") {
|
|
8
8
|
throw new Error("配置必须是 JSON 对象,enabled 必须是布尔值。");
|
|
9
9
|
}
|
|
10
|
+
if (value.acp !== undefined) {
|
|
11
|
+
if (!object(value.acp) || Object.keys(value.acp).some(key => !["pi", "dsh", "claude"].includes(key))) throw new Error("acp 仅接受 pi、dsh 和 claude 启动配置。");
|
|
12
|
+
for (const command of Object.values(value.acp)) {
|
|
13
|
+
if (!object(command) || typeof command.command !== "string" || !command.command.trim() || command.command.includes("\0") ||
|
|
14
|
+
!Array.isArray(command.args) || command.args.some(arg => typeof arg !== "string" || arg.includes("\0")) ||
|
|
15
|
+
Object.keys(command).some(key => !["command", "args"].includes(key))) throw new Error("ACP 启动配置需要 command 和 args 字符串数组。");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
10
18
|
return value;
|
|
11
19
|
}
|
|
12
20
|
import type { WorkspaceConfig, WorkspaceConfiguration } from "../../model/workspace-config.js";
|
|
@@ -26,7 +34,8 @@ export async function readWorkspaceConfig(root: string): Promise<WorkspaceConfig
|
|
|
26
34
|
}
|
|
27
35
|
try {
|
|
28
36
|
const value = config(JSON.parse(content));
|
|
29
|
-
|
|
37
|
+
const settings = value as WorkspaceConfig;
|
|
38
|
+
return { path, present: true, enabled: settings.enabled === true, ...(settings.acp ? { acp: settings.acp } : {}) };
|
|
30
39
|
} catch (error) {
|
|
31
40
|
return { path, present: true, enabled: false, error: `工作区配置无效 ${path}: ${String(error)}` };
|
|
32
41
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { object } from "../common/json.js";
|
|
3
|
+
import { requireThat } from "../common/validation.js";
|
|
4
|
+
import { fileId } from "./file-access.js";
|
|
5
|
+
import type { AcpAnswer, AcpInput, AcpPermission, AcpPermissionReply, AcpModelState, AcpProcess, AcpReport, AcpSessionReference } from "../model/acp.js";
|
|
6
|
+
|
|
7
|
+
const text = (value: unknown): value is string => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
8
|
+
export function acpReference(value: unknown): AcpSessionReference {
|
|
9
|
+
requireThat(object(value) && value.host === "acp" && ["pi", "dsh", "claude"].includes(String(value.backend)) &&
|
|
10
|
+
text(value.command) && isAbsolute(value.command) && Array.isArray(value.args) && value.args.every(arg => typeof arg === "string" && !arg.includes("\0")) &&
|
|
11
|
+
(value.sessionId === null || text(value.sessionId)), "ACP 会话引用无效。");
|
|
12
|
+
const capabilities = value.capabilities;
|
|
13
|
+
if (capabilities !== undefined) requireThat(object(capabilities) &&
|
|
14
|
+
["resume", "load", "close"].every(key => typeof capabilities[key] === "boolean"), "ACP 会话能力无效。");
|
|
15
|
+
return value as unknown as AcpSessionReference;
|
|
16
|
+
}
|
|
17
|
+
export function acpModelState(value: unknown): AcpModelState {
|
|
18
|
+
requireThat(object(value) && text(value.generation) && ["provider", "model", "resolvedModel", "thinking"].every(key => value[key] === undefined || text(value[key])), "ACP 模型选择无效。");
|
|
19
|
+
return value as unknown as AcpModelState;
|
|
20
|
+
}
|
|
21
|
+
export function acpProcess(value: unknown): AcpProcess {
|
|
22
|
+
requireThat(object(value) && text(value.generation) && Number.isSafeInteger(value.pid) && Number(value.pid) > 1 &&
|
|
23
|
+
typeof value.startedAt === "number" && Number.isFinite(value.startedAt), "ACP 进程记录无效。");
|
|
24
|
+
return value as unknown as AcpProcess;
|
|
25
|
+
}
|
|
26
|
+
export function acpInput(value: unknown): AcpInput {
|
|
27
|
+
requireThat(object(value) && text(value.generation) && text(value.requestId), "ACP 输入关联无效。");
|
|
28
|
+
fileId(value.requestId); return value as unknown as AcpInput;
|
|
29
|
+
}
|
|
30
|
+
export function acpAnswer(value: unknown): AcpAnswer {
|
|
31
|
+
acpInput(value);
|
|
32
|
+
requireThat(object(value) && typeof value.answer === "string" && ["completed", "failed", "cancelled"].includes(String(value.state)) &&
|
|
33
|
+
(value.error === undefined || typeof value.error === "string"), "ACP 最终回答无效。");
|
|
34
|
+
return value as unknown as AcpAnswer;
|
|
35
|
+
}
|
|
36
|
+
export function acpReport(value: unknown): AcpReport {
|
|
37
|
+
requireThat(object(value) && text(value.generation) && text(value.cycleId) && typeof value.text === "string", "ACP 周期报告无效。");
|
|
38
|
+
fileId(value.cycleId); return value as unknown as AcpReport;
|
|
39
|
+
}
|
|
40
|
+
export function acpPermission(value: unknown): AcpPermission {
|
|
41
|
+
acpInput(value);
|
|
42
|
+
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every(option =>
|
|
43
|
+
object(option) && text(option.optionId) && text(option.name) && ["allow_once", "allow_always", "reject_once", "reject_always"].includes(String(option.kind))), "ACP 确认请求无效。");
|
|
44
|
+
return value as unknown as AcpPermission;
|
|
45
|
+
}
|
|
46
|
+
export function acpPermissionReply(value: unknown): AcpPermissionReply {
|
|
47
|
+
acpInput(value);
|
|
48
|
+
requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP 确认答复无效。");
|
|
49
|
+
return value as unknown as AcpPermissionReply;
|
|
50
|
+
}
|
|
@@ -5,7 +5,9 @@ import { canonical, object } from "../common/json.js";
|
|
|
5
5
|
import { requireThat } from "../common/validation.js";
|
|
6
6
|
import { readJsonFile, writeJsonFile } from "./atomic-json.js";
|
|
7
7
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
8
|
-
import type { AgentDescriptor, AgentLaunch, AgentMessage, AgentStatus, AgentCycle, AgentSessionRef, AgentSessionReference } from "../model/agent.js";
|
|
8
|
+
import type { AgentDescriptor, AgentLaunch, AgentMessage, AgentStatus, AgentCycle, AgentSessionRef, AgentSessionReference, NativeAgentHost } from "../model/agent.js";
|
|
9
|
+
import type { AcpSessionReference } from "../model/acp.js";
|
|
10
|
+
import { acpReference } from "./acp-files.js";
|
|
9
11
|
|
|
10
12
|
const text = (v: unknown): v is string => typeof v === "string" && v.length > 0;
|
|
11
13
|
const number = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v);
|
|
@@ -46,7 +48,9 @@ export function status(v: unknown): AgentStatus {
|
|
|
46
48
|
}
|
|
47
49
|
export class AgentFiles {
|
|
48
50
|
#failure: unknown;
|
|
49
|
-
constructor(readonly root: string, readonly host:
|
|
51
|
+
constructor(readonly root: string, readonly host: NativeAgentHost = "pi") {
|
|
52
|
+
requireThat(host === "pi" || host === "dsh", "子会话所属宿主无效。");
|
|
53
|
+
}
|
|
50
54
|
check() { if (this.#failure) throw this.#failure; }
|
|
51
55
|
fail(error: unknown) { this.#failure = error; }
|
|
52
56
|
directory(id: string) { return join(this.root, fileId(id)); }
|
|
@@ -61,14 +65,19 @@ export class AgentFiles {
|
|
|
61
65
|
catch (error) { this.fail(error); throw error; }
|
|
62
66
|
requireThat(published, "子会话文件已存在。");
|
|
63
67
|
}
|
|
64
|
-
create(value: AgentDescriptor, run: AgentLaunch) {
|
|
68
|
+
create(value: AgentDescriptor, run: AgentLaunch, acp?: AcpSessionReference) {
|
|
65
69
|
this.check();
|
|
70
|
+
if (acp) acpReference(acp);
|
|
66
71
|
mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
67
72
|
mkdirSync(this.directory(value.agentId), { mode: 0o700 });
|
|
68
73
|
for (const dir of ["inbox", "completions"]) privateDirectory(this.directory(value.agentId), dir);
|
|
69
74
|
this.write(value.agentId, "descriptor.json", value, descriptor, true);
|
|
70
75
|
this.write(value.agentId, "launch.json", run, launch, true);
|
|
71
|
-
if (
|
|
76
|
+
if (acp) {
|
|
77
|
+
for (const dir of ["reports", "permissions"]) privateDirectory(this.directory(value.agentId), dir);
|
|
78
|
+
this.write(value.agentId, "acp-session.json", acp, acpReference, true);
|
|
79
|
+
}
|
|
80
|
+
else if (this.host === "pi") this.write(value.agentId, "session-ref.json", { file: null }, sessionRef, true);
|
|
72
81
|
else this.write(value.agentId, "native-session.json", { host: "dsh", sessionId: value.agentId }, dshSessionRef, true);
|
|
73
82
|
}
|
|
74
83
|
list() {
|
|
@@ -86,6 +95,8 @@ export class AgentFiles {
|
|
|
86
95
|
.map(n => this.read(id, "completions/" + n, cycle)).sort((a, b) => (a.finishedAt ?? 0) - (b.finishedAt ?? 0));
|
|
87
96
|
}
|
|
88
97
|
reference(id: string): AgentSessionReference {
|
|
98
|
+
const acp = this.optional(id, "acp-session.json", acpReference);
|
|
99
|
+
if (acp) return acp;
|
|
89
100
|
if (this.host === "pi") return { host: "pi", file: this.session(id) };
|
|
90
101
|
const ref = this.read(id, "native-session.json", dshSessionRef);
|
|
91
102
|
requireThat(ref.sessionId === id, "dsh 原生会话身份不匹配。");
|
|
@@ -8,7 +8,7 @@ import { fileId } from "./file-access.js";
|
|
|
8
8
|
|
|
9
9
|
const strings = (value: unknown): value is string[] => Array.isArray(value) && value.every(item => typeof item === "string");
|
|
10
10
|
function record(value: unknown): HistoryRecord {
|
|
11
|
-
requireThat(object(value) && (value.host === "pi" || value.host === "dsh") &&
|
|
11
|
+
requireThat(object(value) && (value.host === "pi" || value.host === "dsh" || value.host === "claude") &&
|
|
12
12
|
typeof value.id === "string" && typeof value.sessionId === "string" &&
|
|
13
13
|
typeof value.name === "string" && Array.isArray(value.nodes), "历史索引无效。");
|
|
14
14
|
for (const node of value.nodes) requireThat(object(node) && typeof node.id === "string" &&
|
|
@@ -24,21 +24,30 @@ export class HistoryFiles {
|
|
|
24
24
|
#warnings: string[] = [];
|
|
25
25
|
constructor(readonly directory: string, readonly host: HistoryHost = "pi") {}
|
|
26
26
|
get warnings(): readonly string[] { return this.#warnings; }
|
|
27
|
-
|
|
27
|
+
/** A peer can include its legacy directory without migrating or modifying either source. */
|
|
28
|
+
list(legacyRoot?: string) {
|
|
28
29
|
this.#warnings = [];
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
for (const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const records = new Map<string, HistoryRecord>();
|
|
31
|
+
const directories = [this.directory, ...(legacyRoot && this.host !== "claude" ? [join(legacyRoot, "." + this.host, "pbot/history")] : [])];
|
|
32
|
+
for (const directory of directories) {
|
|
33
|
+
if (!existsSync(directory)) continue;
|
|
34
|
+
for (const name of readdirSync(directory).filter(name => name.endsWith(".json"))) {
|
|
35
|
+
try {
|
|
36
|
+
const value = readJsonFile(directory, name, value => {
|
|
37
|
+
if (directory === this.directory) return record(value);
|
|
38
|
+
requireThat(object(value) && (value.host === undefined || value.host === this.host), "旧历史归档与来源目录不匹配。");
|
|
39
|
+
return record({ ...value, host: this.host });
|
|
40
|
+
});
|
|
41
|
+
requireThat(name === fileId(value.id) + ".json", "历史文件名与根 ID 不匹配。");
|
|
42
|
+
if (value.host === this.host && !records.has(value.id)) records.set(value.id, value);
|
|
43
|
+
} catch (error) { this.#warnings.push(join(directory, name) + ": " + String(error)); }
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
|
-
return records;
|
|
46
|
+
return [...records.values()];
|
|
39
47
|
}
|
|
40
48
|
/** Publish each legacy archive with its directory's host before removing the old copy. */
|
|
41
49
|
migrate(root: string) {
|
|
50
|
+
if (this.host !== "pi" && this.host !== "dsh") return;
|
|
42
51
|
const directory = join(root, "." + this.host, "pbot/history");
|
|
43
52
|
if (!existsSync(directory)) return;
|
|
44
53
|
this.control(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Static } from "typebox";
|
|
2
2
|
import type { AgentService } from "../../services/agents/agent-service.js";
|
|
3
|
-
import type { AgentOptions, AgentOwner, AgentView } from "../../model/agent.js";
|
|
3
|
+
import type { AgentOptions, AgentStartOptions, AgentOwner, AgentView } from "../../model/agent.js";
|
|
4
4
|
import { markdownResult } from "../result.js";
|
|
5
5
|
import type { agentParametersSchema, agentViewSchema } from "./contract.js";
|
|
6
6
|
|
|
@@ -11,6 +11,8 @@ function agentOutput(view: AgentView & Partial<AgentOutput>): AgentOutput {
|
|
|
11
11
|
return {
|
|
12
12
|
agentId: view.agentId, name: view.name, cwd: view.cwd, createdAt: view.createdAt,
|
|
13
13
|
owned: view.owned, state: view.state, activity: view.activity,
|
|
14
|
+
...(view.backend ? { backend: view.backend, transport: view.transport, capabilities: view.capabilities } : {}),
|
|
15
|
+
...(view.selection ? { selection: view.selection } : {}),
|
|
14
16
|
...(c ? { cycle: { cycleId: c.cycleId, startedAt: c.startedAt, state: c.state, requestIds: c.requestIds, source: c.source,
|
|
15
17
|
...(c.finishedAt === undefined ? {} : { finishedAt: c.finishedAt }), ...(c.error === undefined ? {} : { error: c.error }) } } : {}),
|
|
16
18
|
...(view.error === undefined ? {} : { error: view.error }),
|
|
@@ -29,7 +31,7 @@ export async function executeAgent(service: AgentService, input: AgentInput, own
|
|
|
29
31
|
switch (input.action) {
|
|
30
32
|
case "start": {
|
|
31
33
|
const { action: _action, ...supplied } = input;
|
|
32
|
-
value = await service.start({ ...defaults, ...supplied } as
|
|
34
|
+
value = await service.start({ ...(supplied.backend ? {} : defaults), ...supplied } as AgentStartOptions, owner); break;
|
|
33
35
|
}
|
|
34
36
|
case "list": return markdownResult({ agents: service.list(owner).map(agentOutput) }, "子会话列表");
|
|
35
37
|
case "send": value = service.send(input.agentId!, input.message!, input.delivery ?? "steer", owner); break;
|
|
@@ -6,25 +6,26 @@ const id = Type.String({ minLength: 1, maxLength: 128 });
|
|
|
6
6
|
const message = Type.String({ minLength: 1, maxLength: 24000, description: "本次目标、相关资料、约束和交付要求。" });
|
|
7
7
|
const name = Type.String({ minLength: 1, maxLength: 64, pattern: "^[^\\r\\n\\x00-\\x1f]+$" });
|
|
8
8
|
export const agentStartOptions = {
|
|
9
|
+
backend: Type.Optional(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")], { description: "选择已安装并配置的子代理程序:pi、dsh 或 claude(Claude Code)。省略时使用当前宿主的原生专家;显式选择时使用目标程序自己的配置。团队成员须省略 backend。" })),
|
|
9
10
|
name: Type.Optional(name), message: Type.Optional(message),
|
|
10
11
|
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "随初始消息读取的文件;相对路径基于原工作区根目录。" })),
|
|
11
12
|
prompts: Type.Optional(Type.Array(message, { maxItems: 32, description: "与 message 按顺序合并为同一初始消息。" })),
|
|
12
|
-
provider: Type.Optional(Type.String({ ...id, description: "
|
|
13
|
-
model: Type.Optional(Type.String({ ...id, description: "Pi
|
|
14
|
-
thinking: Type.Optional(Type.
|
|
13
|
+
provider: Type.Optional(Type.String({ ...id, description: "模型提供方。省略 backend 时默认继承主会话;指定 backend 时,此参数须与 model 一起提供。Claude 子代理省略此参数。" })),
|
|
14
|
+
model: Type.Optional(Type.String({ ...id, description: "模型 ID;指定 backend 时也可使用目标公开的完整模型值。默认值:省略 backend 时继承主会话,指定时使用目标配置。Pi/dsh 同名模型可用 provider 区分。" })),
|
|
15
|
+
thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "思考等级 ID,可单独指定。默认值:省略 backend 时继承主会话,指定时使用目标配置。Pi 使用 off/minimal/low/medium/high/xhigh/max,其他程序使用其原生等级 ID。" })),
|
|
15
16
|
cwd: Type.Optional(Type.String({ minLength: 1, description: "执行目录,相对原工作区根目录;省略时使用工作区根目录。" })),
|
|
16
|
-
tools: Type.Optional(Type.Array(id, { minItems: 1, description: "
|
|
17
|
-
noExtensions: Type.Optional(Type.Boolean({ description: "
|
|
18
|
-
noSkills: Type.Optional(Type.Boolean({ description: "
|
|
19
|
-
noPromptTemplates: Type.Optional(Type.Boolean({ description: "
|
|
20
|
-
noContextFiles: Type.Optional(Type.Boolean({ description: "
|
|
17
|
+
tools: Type.Optional(Type.Array(id, { minItems: 1, description: "Pi/dsh 子代理的工具名;省略时使用所选程序默认工具。Claude 子代理省略此参数并沿用原生配置。" })),
|
|
18
|
+
noExtensions: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭其他扩展的自动发现,默认 true。" })),
|
|
19
|
+
noSkills: Type.Optional(Type.Boolean({ description: "Pi/dsh 子代理关闭技能发现,默认 false;Claude 子代理省略此参数并沿用原生配置。" })),
|
|
20
|
+
noPromptTemplates: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭提示模板发现,默认 false。" })),
|
|
21
|
+
noContextFiles: Type.Optional(Type.Boolean({ description: "仅用于 Pi 子代理:关闭原生上下文文件加载,默认 false。" })),
|
|
21
22
|
};
|
|
22
23
|
const page = {
|
|
23
24
|
cycleId: Type.Optional(Type.String({ ...id, description: "仅 read:省略时读取最近周期;按 nextOffset 续读时须固定为上页返回的 cycle.cycleId,避免切换到新周期。" })),
|
|
24
25
|
offset: Type.Optional(Type.Integer({ minimum: 0, description: "仅 read:报告正文的 UTF-16 字符偏移,默认 0;续读使用上页 nextOffset。" })),
|
|
25
26
|
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000, description: "仅 read:最多返回的正文 UTF-16 字符数,默认 16000,不是消息数或 token 数。" })),
|
|
26
27
|
};
|
|
27
|
-
const delivery = Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "send 默认 steer 补充当前工作;followUp 排到当前工作之后。" }));
|
|
28
|
+
const delivery = Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")], { description: "send 默认 steer 补充当前工作;followUp 排到当前工作之后。capabilities.steer 为 false 的成员运行中使用 followUp。" }));
|
|
28
29
|
export const agentParametersSchema = Type.Object({
|
|
29
30
|
action: Type.Union([Type.Literal("start"), Type.Literal("send"), Type.Literal("rename"), Type.Literal("status"), Type.Literal("list"), Type.Literal("read"), Type.Literal("stop"), Type.Literal("resume")], {
|
|
30
31
|
description: "start 仅接受启动选项,可省略 message/prompts/files 创建待命会话,禁止 agentId/delivery/分页字段;list 只接受 action;status/stop 只接受并必填 agentId;send 必填 agentId/message,仅可选 delivery;resume 必填 agentId/message;rename 必填 agentId/name;read 必填 agentId,仅可选 cycleId/offset/limit。禁止携带其他 action 的字段。",
|
|
@@ -47,6 +48,12 @@ const cycle = Type.Object({ cycleId: Type.String(), startedAt: Type.Number(), fi
|
|
|
47
48
|
source: Type.Union([Type.Literal("parent"), Type.Literal("interactive"), Type.Literal("mixed")]), error: Type.Optional(Type.String()),
|
|
48
49
|
}, { additionalProperties: false });
|
|
49
50
|
export const agentViewSchema = Type.Object({ agentId: Type.String(), name: Type.String(), cwd: Type.String(), createdAt: Type.Number(),
|
|
51
|
+
backend: Type.Optional(Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")])),
|
|
52
|
+
transport: Type.Optional(Type.Union([Type.Literal("native"), Type.Literal("acp")])),
|
|
53
|
+
selection: Type.Optional(Type.Object({ provider: Type.Optional(Type.String()), model: Type.Optional(Type.String()),
|
|
54
|
+
resolvedModel: Type.Optional(Type.String({ description: "目标原生会话报告的模型 ID,可用于识别配置别名。" })), thinking: Type.Optional(Type.String()) },
|
|
55
|
+
{ additionalProperties: false, description: "子代理实际模型配置与有效思考等级,包含默认值。" })),
|
|
56
|
+
capabilities: Type.Optional(Type.Object({ steer: Type.Boolean(), resume: Type.Boolean(), team: Type.Boolean(), transcript: Type.Boolean() }, { additionalProperties: false })),
|
|
50
57
|
owned: Type.Boolean({ description: "是否属于当前父会话分支;false 时须回到所属分支操作。" }),
|
|
51
58
|
state: Type.Union([Type.Literal("starting"), Type.Literal("busy"), Type.Literal("idle"), Type.Literal("stopping"), Type.Literal("stopped"), Type.Literal("error")], { description: "执行状态;idle 不代表上轮工作成功,结果见 cycle.state。" }),
|
|
52
59
|
activity: Type.String(), cycle: Type.Optional(cycle), error: Type.Optional(Type.String()),
|
|
@@ -3,14 +3,18 @@ import { agentActionSchema, agentParametersSchema, agentStartOptions } from "./c
|
|
|
3
3
|
|
|
4
4
|
const options = Type.Omit(Type.Object(agentStartOptions), ["provider", "model", "thinking", "files", "tools", "noExtensions", "noPromptTemplates", "noContextFiles", "noSkills"]).properties;
|
|
5
5
|
const native = {
|
|
6
|
-
provider: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "dsh
|
|
7
|
-
model: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "
|
|
8
|
-
thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "
|
|
9
|
-
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "
|
|
10
|
-
tools: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1, description: "
|
|
11
|
-
noSkills: Type.Optional(Type.Boolean({ description: "
|
|
6
|
+
provider: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "模型提供方,dsh 使用原生 provider route。省略 backend 时默认继承主会话;指定 backend 时,此参数须与 model 一起提供。Claude 子代理省略此参数。" })),
|
|
7
|
+
model: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "模型 ID;指定 backend 时也可使用目标公开的完整模型值。默认值:省略 backend 时继承主会话,指定时使用目标配置。" })),
|
|
8
|
+
thinking: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "思考等级 ID,dsh 使用原生 reasoning effort,可单独指定。默认值:省略 backend 时继承主会话,指定时使用目标配置。" })),
|
|
9
|
+
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32, description: "附给子代理的文件;相对原工作区根目录。图片格式与大小遵循所选程序的支持范围。" })),
|
|
10
|
+
tools: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1, description: "dsh 子代理填 run_code 内的能力工具名,Pi 子代理填 Pi 工具名。省略时使用所选程序默认工具;未指定 backend 的专家另有 pbot_team_message。Claude 子代理省略此参数并沿用原生配置。" })),
|
|
11
|
+
noSkills: Type.Optional(Type.Boolean({ description: "Pi/dsh 子代理关闭技能发现,默认 false;dsh 同时关闭 skill 工具。Claude 子代理省略此参数并沿用原生配置。" })),
|
|
12
12
|
};
|
|
13
13
|
const omitted = ["noExtensions", "noPromptTemplates", "noContextFiles", "provider", "model", "thinking", "files", "tools", "noSkills"] as const;
|
|
14
|
-
export const dshAgentParametersSchema = Type.Object({ ...Type.Omit(agentParametersSchema, omitted).properties, ...native
|
|
14
|
+
export const dshAgentParametersSchema = Type.Object({ ...Type.Omit(agentParametersSchema, omitted).properties, ...native,
|
|
15
|
+
noExtensions: agentStartOptions.noExtensions, noPromptTemplates: agentStartOptions.noPromptTemplates, noContextFiles: agentStartOptions.noContextFiles,
|
|
16
|
+
}, { additionalProperties: false });
|
|
15
17
|
export const dshAgentActionSchema = Type.Union(agentActionSchema.anyOf.map(row => row.properties.action.const === "start"
|
|
16
|
-
? Type.Object({ action: Type.Literal("start"), ...options, ...native
|
|
18
|
+
? Type.Object({ action: Type.Literal("start"), ...options, ...native,
|
|
19
|
+
noExtensions: agentStartOptions.noExtensions, noPromptTemplates: agentStartOptions.noPromptTemplates, noContextFiles: agentStartOptions.noContextFiles,
|
|
20
|
+
}, { additionalProperties: false }) : row));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Type, type Static } from "typebox";
|
|
2
2
|
import { requireThat, schema } from "../../common/validation.js";
|
|
3
3
|
|
|
4
|
-
const host = Type.Union([Type.Literal("pi"), Type.Literal("dsh")]);
|
|
4
|
+
const host = Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")]);
|
|
5
5
|
const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
|
|
6
6
|
const node = Type.Object({ host, id: Type.String(), kind: Type.Union([Type.Literal("session"), Type.Literal("exchange"), Type.Literal("summary")]),
|
|
7
7
|
sessionId: Type.String(), name: Type.String(), preview: Type.String(), from: Type.String(), to: Type.String(), ready: Type.Boolean(), completed: Type.Boolean() });
|
|
@@ -13,7 +13,7 @@ export const historyResultSchema = Type.Object({
|
|
|
13
13
|
source: Type.Object({ host, sessionId: Type.String({ description: "原始宿主会话 ID。" }), entryIds: Type.Array(Type.String()) }), warnings: Type.Array(Type.String()) })),
|
|
14
14
|
warnings: Type.Array(Type.String()),
|
|
15
15
|
});
|
|
16
|
-
export const historyDescription = "查询当前工作区的 Pi/dsh
|
|
16
|
+
export const historyDescription = "查询当前工作区的 Pi/dsh 问答与已有 Claude 归档,host 可筛选来源。search 按不区分大小写的连续文本匹配原文和摘要;无匹配时换词,省略 query 列会话。read 按 parents/children 的 id 展开,nextOffset 续读正文,nextChildrenOffset 续读子节点。需要对话细节时读取 exchange 原文;需要工具日志时查所属宿主的原始会话。";
|
|
17
17
|
export const historyParameters = Type.Object({ action: Type.Union([Type.Literal("search"), Type.Literal("read")]),
|
|
18
18
|
host: Type.Optional(host), query: Type.Optional(Type.String()), sessionId: Type.Optional(Type.String()),
|
|
19
19
|
from: Type.Optional(Type.String({ description: "search:ISO 日期或时间,下界。" })),
|