personal-bot 0.2.12 → 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 +33 -16
- package/README.zh-CN.md +33 -16
- 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 +20 -8
- package/docs/architecture-guidelines.md +1 -1
- package/docs/capability-design.md +10 -4
- package/docs/claude-code-design.md +45 -0
- package/docs/claude-code.md +64 -0
- package/docs/dsh.md +3 -3
- package/docs/file-storage.md +18 -9
- package/docs/history.md +17 -9
- package/docs/interaction-design.md +9 -1
- package/docs/model-context.md +37 -14
- package/docs/model-instruction-guidelines.md +3 -3
- package/docs/release.md +13 -5
- package/docs/technical-design.md +40 -18
- package/docs/workspace-configuration.md +34 -26
- package/hooks/hooks.json +19 -0
- package/lib/claude.d.ts +1 -0
- package/lib/claude.js +20 -0
- package/lib/client.js +1 -1
- package/lib/extension/acp-worker.js +6 -3
- package/lib/extension/claude-hooks.d.ts +15 -0
- package/lib/extension/claude-hooks.js +104 -0
- package/lib/extension/dsh/history.js +1 -1
- package/lib/integrations/agent-resources.d.ts +1 -1
- package/lib/integrations/agent-resources.js +3 -1
- 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/agent.d.ts +1 -1
- package/lib/model/history.d.ts +11 -4
- 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/storage/agent-files.js +3 -0
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +26 -15
- package/lib/tools/history/contract.d.ts +7 -7
- package/lib/tools/history/contract.js +2 -2
- package/lib/ui/dsh/management.js +1 -1
- package/npm-shrinkwrap.json +10 -27
- package/package.json +33 -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/provider-connections/SKILL.md +17 -1
- package/scripts/README.md +24 -6
- package/src/claude.ts +19 -0
- package/src/extension/acp-worker.ts +2 -2
- package/src/extension/claude-hooks.ts +94 -0
- package/src/extension/dsh/history.ts +1 -1
- package/src/integrations/agent-resources.ts +2 -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/model/agent.ts +1 -1
- package/src/model/history.ts +12 -4
- package/src/pbot.ts +2 -2
- package/src/services/history/history-service.ts +82 -41
- package/src/services/workspace/python-environment-service.ts +26 -9
- package/src/storage/agent-files.ts +4 -1
- package/src/storage/history-files.ts +20 -11
- package/src/tools/history/contract.ts +2 -2
- package/src/ui/dsh/management.ts +1 -1
|
@@ -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) {
|
|
@@ -48,7 +48,9 @@ export function status(v: unknown): AgentStatus {
|
|
|
48
48
|
}
|
|
49
49
|
export class AgentFiles {
|
|
50
50
|
#failure: unknown;
|
|
51
|
-
constructor(readonly root: string, readonly host: NativeAgentHost = "pi") {
|
|
51
|
+
constructor(readonly root: string, readonly host: NativeAgentHost = "pi") {
|
|
52
|
+
requireThat(host === "pi" || host === "dsh", "子会话所属宿主无效。");
|
|
53
|
+
}
|
|
52
54
|
check() { if (this.#failure) throw this.#failure; }
|
|
53
55
|
fail(error: unknown) { this.#failure = error; }
|
|
54
56
|
directory(id: string) { return join(this.root, fileId(id)); }
|
|
@@ -65,6 +67,7 @@ export class AgentFiles {
|
|
|
65
67
|
}
|
|
66
68
|
create(value: AgentDescriptor, run: AgentLaunch, acp?: AcpSessionReference) {
|
|
67
69
|
this.check();
|
|
70
|
+
if (acp) acpReference(acp);
|
|
68
71
|
mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
69
72
|
mkdirSync(this.directory(value.agentId), { mode: 0o700 });
|
|
70
73
|
for (const dir of ["inbox", "completions"]) privateDirectory(this.directory(value.agentId), dir);
|
|
@@ -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,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 日期或时间,下界。" })),
|
package/src/ui/dsh/management.ts
CHANGED
|
@@ -301,7 +301,7 @@ export function showManagement(ctx: Context, parentSessionId: SessionId) {
|
|
|
301
301
|
|
|
302
302
|
const history = section("history", "历史"); pageTitle(history, "历史", "");
|
|
303
303
|
const searchForm = form(history); searchForm.className = "pbot-search";
|
|
304
|
-
const historyQuery = field(searchForm, "关键词"), host = select(searchForm, "来源", [["", "全部"], ["pi", "Pi"], ["dsh", "dsh"]]);
|
|
304
|
+
const historyQuery = field(searchForm, "关键词"), host = select(searchForm, "来源", [["", "全部"], ["pi", "Pi"], ["dsh", "dsh"], ["claude", "Claude Code"]]);
|
|
305
305
|
historyQuery.placeholder = "留空查看最近会话"; submit(searchForm, "查询", () => searchHistory());
|
|
306
306
|
const dateFilters = details(history, "时间范围"), dateGrid = group(dateFilters, "pbot-grid");
|
|
307
307
|
const historyFrom = field(dateGrid, "开始时间"), historyTo = field(dateGrid, "结束时间");
|