personal-bot 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/bin/pbot-pi-acp.mjs +27 -11
- package/bin/pbot.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/architecture/design.md +23 -10
- package/docs/architecture/extensibility.md +20 -18
- package/docs/architecture/model-context.md +2 -2
- package/docs/architecture/principles.md +4 -3
- package/docs/guides/capabilities.md +3 -3
- package/docs/guides/history.md +50 -16
- package/docs/guides/workspace-configuration.md +31 -6
- package/docs/hosts/antigravity.md +2 -0
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/dsh.md +1 -1
- package/docs/hosts/pi.md +1 -1
- package/hooks/hooks.json +3 -0
- package/lib/antigravity-plugin/hooks.json +7 -0
- package/lib/antigravity-plugin/lib/claude.js +2 -2
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +75 -4
- package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
- package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
- package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
- package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
- package/lib/claude.js +2 -2
- package/lib/client.js +21 -11
- package/lib/dsh.js +4 -4
- package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
- package/lib/extension/{acp-member.js → acp/member.js} +6 -6
- package/lib/extension/acp/worker.d.ts +1 -0
- package/lib/extension/acp/worker.js +384 -0
- package/lib/extension/acp-worker.js +156 -11
- package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
- package/lib/extension/hosts/dsh/command.js +92 -0
- package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
- package/lib/extension/hosts/dsh/history.d.ts +4 -0
- package/lib/extension/hosts/dsh/history.js +62 -0
- package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
- package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
- package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
- package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
- package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
- package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
- package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
- package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
- package/lib/extension/mcp.js +1113 -78
- package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
- package/lib/integrations/acp/connection.d.ts +11 -10
- package/lib/integrations/acp/connection.js +6 -0
- package/lib/integrations/acp/harnesses/claude.js +1 -1
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/history-summary.d.ts +17 -0
- package/lib/integrations/acp/history-summary.js +100 -0
- package/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/integrations/agent-resources.js +5 -1
- package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
- package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
- package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/integrations/installation/pi-setup.js +1 -1
- package/lib/model/history.d.ts +133 -34
- package/lib/model/plugin-host.d.ts +26 -0
- package/lib/model/workspace-config.d.ts +25 -0
- package/lib/plugin.js +2 -2
- package/lib/services/agents/agent-run.d.ts +1 -1
- package/lib/services/history/history-capture.d.ts +4 -0
- package/lib/services/history/history-capture.js +86 -0
- package/lib/services/history/history-index.d.ts +16 -7
- package/lib/services/history/history-index.js +48 -70
- package/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/services/history/history-migrate.js +88 -0
- package/lib/services/history/history-query.d.ts +51 -0
- package/lib/services/history/history-query.js +371 -0
- package/lib/services/history/summary-command.d.ts +20 -0
- package/lib/services/history/summary-command.js +68 -0
- package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/services/history/summary-registry.js +36 -0
- package/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/services/history/summary-runner.js +301 -0
- package/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/services/workspace/workspace-config.js +75 -4
- package/lib/storage/history-files.d.ts +45 -9
- package/lib/storage/history-files.js +373 -247
- package/lib/storage/history-format.d.ts +3 -12
- package/lib/storage/history-format.js +26 -50
- package/lib/tools/history/actions.d.ts +3 -68
- package/lib/tools/history/actions.js +7 -5
- package/lib/tools/history/contract.d.ts +14 -7
- package/lib/tools/history/contract.js +58 -18
- package/lib/tools/history/dsh-tool.d.ts +1 -2
- package/lib/tools/history/dsh-tool.js +11 -5
- package/lib/ui/dsh/management.js +18 -5
- package/package.json +1 -1
- package/resources/prompts/history-coordinator.md +1 -1
- package/resources/prompts/history-monthly-summary.md +13 -0
- package/resources/prompts/history-summary.md +10 -4
- package/resources/skills/provider-connections/SKILL.md +22 -12
- package/src/claude.ts +2 -2
- package/src/dsh.ts +4 -4
- package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
- package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
- package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
- package/src/extension/hosts/dsh/command.ts +92 -0
- package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
- package/src/extension/hosts/dsh/history.ts +67 -0
- package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
- package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
- package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
- package/src/extension/hosts/pi/command.ts +158 -0
- package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
- package/src/extension/hosts/pi/history.ts +45 -0
- package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
- package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
- package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
- package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
- package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
- package/src/integrations/acp/connection.ts +6 -0
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/history-summary.ts +108 -0
- package/src/integrations/agent-resources.ts +6 -0
- package/src/integrations/hosts/antigravity/adapter.ts +161 -0
- package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
- package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
- package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
- package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
- package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/mcp.ts +1 -1
- package/src/model/history.ts +151 -26
- package/src/model/plugin-host.ts +26 -2
- package/src/model/workspace-config.ts +30 -0
- package/src/pbot.ts +13 -22
- package/src/plugin.ts +2 -2
- package/src/services/history/history-capture.ts +83 -0
- package/src/services/history/history-index.ts +48 -62
- package/src/services/history/history-migrate.ts +89 -0
- package/src/services/history/history-query.ts +415 -0
- package/src/services/history/summary-command.ts +69 -0
- package/src/services/history/summary-dimensions/monthly.ts +139 -0
- package/src/services/history/summary-dimensions/session.ts +149 -0
- package/src/services/history/summary-registry.ts +44 -0
- package/src/services/history/summary-runner.ts +352 -0
- package/src/services/workspace/workspace-config.ts +93 -5
- package/src/storage/history-files.ts +408 -188
- package/src/storage/history-format.ts +46 -60
- package/src/tools/history/actions.ts +8 -6
- package/src/tools/history/contract.ts +65 -20
- package/src/tools/history/dsh-tool.ts +17 -8
- package/src/tools/history/pi-tool.ts +21 -0
- package/src/tools/register.ts +3 -4
- package/src/ui/dsh/management.ts +27 -11
- package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/extension/dsh/command.js +0 -50
- package/lib/extension/dsh/history.d.ts +0 -15
- package/lib/extension/dsh/history.js +0 -87
- package/lib/integrations/dsh/history-summary.d.ts +0 -11
- package/lib/integrations/dsh/history-summary.js +0 -36
- package/lib/integrations/dsh/history.d.ts +0 -16
- package/lib/integrations/dsh/history.js +0 -167
- package/lib/integrations/history-summary.d.ts +0 -4
- package/lib/integrations/history-summary.js +0 -32
- package/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/services/history/history-service.d.ts +0 -106
- package/lib/services/history/history-service.js +0 -242
- package/lib/storage/acp-history.d.ts +0 -10
- package/lib/storage/acp-history.js +0 -57
- package/src/extension/command.ts +0 -76
- package/src/extension/dsh/command.ts +0 -54
- package/src/extension/dsh/history.ts +0 -74
- package/src/extension/history.ts +0 -26
- package/src/integrations/dsh/history-summary.ts +0 -39
- package/src/integrations/dsh/history.ts +0 -84
- package/src/integrations/history-summary.ts +0 -30
- package/src/integrations/hosts/antigravity.ts +0 -83
- package/src/integrations/pi/history.ts +0 -99
- package/src/services/history/history-service.ts +0 -195
- package/src/storage/acp-history.ts +0 -49
- package/src/tools/history/tool.ts +0 -19
- /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
- /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
- /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
- /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
- /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
- /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
- /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/mcp.ts
|
|
2
|
-
import { realpathSync as
|
|
2
|
+
import { realpathSync as realpathSync5 } from "node:fs";
|
|
3
3
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
4
4
|
|
|
5
|
-
// src/extension/mcp
|
|
5
|
+
// src/extension/mcp/workers.ts
|
|
6
6
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
7
7
|
import { realpath, stat } from "node:fs/promises";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
|
-
import { isAbsolute as isAbsolute3, join as
|
|
9
|
+
import { isAbsolute as isAbsolute3, join as join12 } from "node:path";
|
|
10
10
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
11
11
|
|
|
12
12
|
// src/common/json.ts
|
|
@@ -72,8 +72,8 @@ import {
|
|
|
72
72
|
} from "node:fs";
|
|
73
73
|
import { dirname, join } from "node:path";
|
|
74
74
|
import { randomUUID } from "node:crypto";
|
|
75
|
-
function internalPath(directory,
|
|
76
|
-
const parts =
|
|
75
|
+
function internalPath(directory, relative2) {
|
|
76
|
+
const parts = relative2.split("/");
|
|
77
77
|
requireThat(parts.every((part) => part && part !== "." && part !== ".." && !/[\\\x00-\x1f]/.test(part)), "\u5185\u90E8\u72B6\u6001\u8DEF\u5F84\u65E0\u6548\u3002");
|
|
78
78
|
const info = lstatSync(directory);
|
|
79
79
|
requireThat(info.isDirectory() && !info.isSymbolicLink(), "\u5185\u90E8\u72B6\u6001\u5FC5\u987B\u4F7F\u7528\u666E\u901A\u76EE\u5F55\u3002");
|
|
@@ -97,8 +97,8 @@ function syncDirectory(directory) {
|
|
|
97
97
|
closeSync(fd);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
function readJsonFile(directory,
|
|
101
|
-
const path = internalPath(directory,
|
|
100
|
+
function readJsonFile(directory, relative2, validate) {
|
|
101
|
+
const path = internalPath(directory, relative2);
|
|
102
102
|
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
103
103
|
try {
|
|
104
104
|
requireThat(fstatSync(fd).isFile(), "\u5185\u90E8\u72B6\u6001\u5FC5\u987B\u662F\u666E\u901A\u6587\u4EF6\u3002");
|
|
@@ -106,19 +106,19 @@ function readJsonFile(directory, relative, validate) {
|
|
|
106
106
|
try {
|
|
107
107
|
value = JSON.parse(readFileSync2(fd, "utf8"));
|
|
108
108
|
} catch (error) {
|
|
109
|
-
throw new Error("\u5185\u90E8 JSON \u6587\u4EF6\u4E0D\u53EF\u8BFB\u53D6\uFF1A" +
|
|
109
|
+
throw new Error("\u5185\u90E8 JSON \u6587\u4EF6\u4E0D\u53EF\u8BFB\u53D6\uFF1A" + relative2, { cause: error });
|
|
110
110
|
}
|
|
111
111
|
return validate(value);
|
|
112
112
|
} finally {
|
|
113
113
|
closeSync(fd);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
function writeJsonFile(directory,
|
|
116
|
+
function writeJsonFile(directory, relative2, value, validate, createOnly = false) {
|
|
117
117
|
const validated = validate(value);
|
|
118
118
|
const expected = canonical(validated);
|
|
119
119
|
const content = JSON.stringify(validated, null, 2) + "\n";
|
|
120
120
|
requireThat(canonical(JSON.parse(content)) === expected, "JSON \u5E8F\u5217\u5316\u4E0D\u80FD\u6539\u53D8\u72B6\u6001\u503C\u3002");
|
|
121
|
-
const path = internalPath(directory,
|
|
121
|
+
const path = internalPath(directory, relative2), parent = dirname(path);
|
|
122
122
|
const temporary = join(parent, `.tmp-${randomUUID()}`);
|
|
123
123
|
const fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
|
|
124
124
|
try {
|
|
@@ -128,7 +128,7 @@ function writeJsonFile(directory, relative, value, validate, createOnly = false)
|
|
|
128
128
|
} finally {
|
|
129
129
|
closeSync(fd);
|
|
130
130
|
}
|
|
131
|
-
requireThat(internalPath(directory,
|
|
131
|
+
requireThat(internalPath(directory, relative2) === path, "\u5185\u90E8\u72B6\u6001\u8DEF\u5F84\u5DF2\u53D8\u5316\u3002");
|
|
132
132
|
if (createOnly) {
|
|
133
133
|
try {
|
|
134
134
|
linkSync(temporary, path);
|
|
@@ -155,8 +155,8 @@ function fileId(id) {
|
|
|
155
155
|
requireThat(/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(id), "\u5185\u90E8\u8BB0\u5F55 ID \u65E0\u6548\u3002");
|
|
156
156
|
return id;
|
|
157
157
|
}
|
|
158
|
-
function privateDirectory(root,
|
|
159
|
-
const parts =
|
|
158
|
+
function privateDirectory(root, relative2) {
|
|
159
|
+
const parts = relative2.split("/");
|
|
160
160
|
let parent = root;
|
|
161
161
|
for (const part of parts) {
|
|
162
162
|
fileId(part);
|
|
@@ -410,7 +410,7 @@ function acpExecutable(command, backend, harness) {
|
|
|
410
410
|
].join("\n"));
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
// src/integrations/acp/claude.ts
|
|
413
|
+
// src/integrations/acp/claude-settings.ts
|
|
414
414
|
import { createRequire } from "node:module";
|
|
415
415
|
import { pathToFileURL } from "node:url";
|
|
416
416
|
import { basename, join as join4, resolve as resolve2 } from "node:path";
|
|
@@ -545,7 +545,7 @@ var dshAcpHarness = {
|
|
|
545
545
|
const patch = join5(context.directory, "acp-dsh-patch.json");
|
|
546
546
|
await writeFile(
|
|
547
547
|
patch,
|
|
548
|
-
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join5(context.packageRoot, "lib/extension/dsh/acp-member.js") }] }]) + "\n",
|
|
548
|
+
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join5(context.packageRoot, "lib/extension/hosts/dsh/acp-member.js") }] }]) + "\n",
|
|
549
549
|
{ mode: 384 }
|
|
550
550
|
);
|
|
551
551
|
return {
|
|
@@ -1320,17 +1320,501 @@ var AgentService = class {
|
|
|
1320
1320
|
}
|
|
1321
1321
|
};
|
|
1322
1322
|
|
|
1323
|
+
// src/services/history/history-query.ts
|
|
1324
|
+
import { join as join10 } from "node:path";
|
|
1325
|
+
|
|
1326
|
+
// src/storage/history-files.ts
|
|
1327
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
1328
|
+
import { linkSync as linkSync2, lstatSync as lstatSync3, mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync4, rmdirSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
1329
|
+
import { basename as basename2, dirname as dirname2, join as join8, relative, resolve as resolve5 } from "node:path";
|
|
1330
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1331
|
+
|
|
1332
|
+
// src/storage/history-format.ts
|
|
1333
|
+
var strings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
1334
|
+
var fields = (value, names) => Object.keys(value).every((key) => names.includes(key));
|
|
1335
|
+
var rawFields = ["host", "id", "sessionId", "name", "exchanges", "branches"];
|
|
1336
|
+
var exchangeFields = ["id", "entryIds", "text", "from", "to", "completed"];
|
|
1337
|
+
var summaryArtifactFields = ["id", "dimension", "host", "sessionId", "title", "text", "from", "to", "updatedAt", "source"];
|
|
1338
|
+
var summarySourceFields = ["rawIds", "exchangeIds", "fingerprint"];
|
|
1339
|
+
var identifierPattern = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
1340
|
+
var isHistoryHost = (value) => typeof value === "string" && identifierPattern.test(value);
|
|
1341
|
+
var isSummaryDimension = (value) => typeof value === "string" && identifierPattern.test(value);
|
|
1342
|
+
function identity(value) {
|
|
1343
|
+
requireThat(
|
|
1344
|
+
object(value) && isHistoryHost(value.host) && typeof value.id === "string" && typeof value.sessionId === "string" && value.sessionId.length > 0,
|
|
1345
|
+
"\u5386\u53F2\u5F52\u6863\u8EAB\u4EFD\u65E0\u6548\u3002"
|
|
1346
|
+
);
|
|
1347
|
+
fileId(value.id);
|
|
1348
|
+
}
|
|
1349
|
+
function matchIdentity(value, expected) {
|
|
1350
|
+
for (const key of ["host", "id", "sessionId"]) {
|
|
1351
|
+
requireThat(value[key] === expected[key], `\u5386\u53F2\u5F52\u6863 ${key} \u4E0D\u5339\u914D\uFF0C\u9884\u671F ${expected[key]}\uFF0C\u5B9E\u9645 ${value[key]}\u3002`);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
function exchange(value) {
|
|
1355
|
+
return object(value) && typeof value.id === "string" && value.id.length > 0 && strings(value.entryIds) && typeof value.text === "string" && typeof value.from === "string" && typeof value.to === "string" && typeof value.completed === "boolean";
|
|
1356
|
+
}
|
|
1357
|
+
function rawHistory(value) {
|
|
1358
|
+
identity(value);
|
|
1359
|
+
requireThat(
|
|
1360
|
+
object(value) && fields(value, rawFields) && typeof value.name === "string" && Array.isArray(value.exchanges) && Array.isArray(value.branches),
|
|
1361
|
+
"\u5386\u53F2\u539F\u6587\u5F52\u6863\u65E0\u6548\u3002"
|
|
1362
|
+
);
|
|
1363
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1364
|
+
for (const item of value.exchanges) {
|
|
1365
|
+
requireThat(exchange(item) && fields(item, exchangeFields) && item.entryIds.length > 0, "\u5386\u53F2\u95EE\u7B54\u6216\u5176\u6765\u6E90\u6D88\u606F ID \u65E0\u6548\u3002");
|
|
1366
|
+
requireThat(item.id !== value.id && !ids.has(item.id), "\u5386\u53F2\u95EE\u7B54 ID \u91CD\u590D\uFF1A" + item.id);
|
|
1367
|
+
ids.add(item.id);
|
|
1368
|
+
}
|
|
1369
|
+
for (const branch of value.branches) {
|
|
1370
|
+
requireThat(
|
|
1371
|
+
strings(branch) && new Set(branch).size === branch.length && branch.every((id) => ids.has(id)),
|
|
1372
|
+
"\u5386\u53F2\u5206\u652F\u5305\u542B\u91CD\u590D\u6216\u672A\u77E5\u7684\u95EE\u7B54 ID\u3002"
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
return value;
|
|
1376
|
+
}
|
|
1377
|
+
function summaryArtifact(value, expectedDimension) {
|
|
1378
|
+
requireThat(object(value) && fields(value, summaryArtifactFields), "\u5386\u53F2\u6458\u8981\u4EA7\u7269\u683C\u5F0F\u65E0\u6548\u3002");
|
|
1379
|
+
requireThat(typeof value.id === "string" && value.id.length > 0, "\u5386\u53F2\u6458\u8981 ID \u65E0\u6548\u3002");
|
|
1380
|
+
fileId(value.id);
|
|
1381
|
+
requireThat(isSummaryDimension(value.dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\u3002");
|
|
1382
|
+
if (expectedDimension !== void 0) {
|
|
1383
|
+
requireThat(value.dimension === expectedDimension, `\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u4E0D\u5339\u914D\uFF0C\u9884\u671F ${expectedDimension}\uFF0C\u5B9E\u9645 ${value.dimension}\u3002`);
|
|
1384
|
+
}
|
|
1385
|
+
if (value.host !== void 0) requireThat(isHistoryHost(value.host), "\u5386\u53F2\u6458\u8981\u6765\u6E90 host \u65E0\u6548\u3002");
|
|
1386
|
+
if (value.sessionId !== void 0) requireThat(typeof value.sessionId === "string" && value.sessionId.length > 0, "\u5386\u53F2\u6458\u8981 sessionId \u65E0\u6548\u3002");
|
|
1387
|
+
requireThat(
|
|
1388
|
+
typeof value.title === "string" && typeof value.text === "string" && value.text.trim().length > 0 && typeof value.from === "string" && typeof value.to === "string" && typeof value.updatedAt === "string",
|
|
1389
|
+
"\u5386\u53F2\u6458\u8981\u6B63\u6587\u6216\u65F6\u95F4\u5B57\u6BB5\u65E0\u6548\u3002"
|
|
1390
|
+
);
|
|
1391
|
+
const source = value.source;
|
|
1392
|
+
requireThat(
|
|
1393
|
+
object(source) && fields(source, summarySourceFields) && strings(source.rawIds) && source.rawIds.length > 0 && strings(source.exchangeIds) && typeof source.fingerprint === "string" && source.fingerprint.length > 0,
|
|
1394
|
+
"\u5386\u53F2\u6458\u8981\u6765\u6E90\u6307\u7EB9\u65E0\u6548\u3002"
|
|
1395
|
+
);
|
|
1396
|
+
return value;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// src/storage/history-files.ts
|
|
1400
|
+
var yearPattern = /^\d{4}$/;
|
|
1401
|
+
var monthPattern = /^(?:0[1-9]|1[0-2])$/;
|
|
1402
|
+
var monthlyIdPattern = /^(\d{4})-(0[1-9]|1[0-2])$/;
|
|
1403
|
+
var monthlyRelativeJsonPattern = /^(?:\d{4}\/(?:0[1-9]|1[0-2])|unknown)\/[^/]+\.json$/;
|
|
1404
|
+
var yearlyRelativeJsonPattern = /^(?:\d{4}|unknown)\/[^/]+\.json$/;
|
|
1405
|
+
var unknownHistoryBucket = "unknown";
|
|
1406
|
+
function ordinaryDirectory(path) {
|
|
1407
|
+
const stat2 = lstatSync3(path, { throwIfNoEntry: false });
|
|
1408
|
+
if (!stat2) return false;
|
|
1409
|
+
requireThat(stat2.isDirectory() && !stat2.isSymbolicLink(), "\u5386\u53F2\u76EE\u5F55\u5FC5\u987B\u4F7F\u7528\u666E\u901A\u76EE\u5F55\uFF1A" + path);
|
|
1410
|
+
return true;
|
|
1411
|
+
}
|
|
1412
|
+
function ordinaryFile(path) {
|
|
1413
|
+
const stat2 = lstatSync3(path, { throwIfNoEntry: false });
|
|
1414
|
+
return Boolean(stat2 && stat2.isFile() && !stat2.isSymbolicLink());
|
|
1415
|
+
}
|
|
1416
|
+
function sharedDirectory(path) {
|
|
1417
|
+
const parent = dirname2(path);
|
|
1418
|
+
return (basename2(parent) !== ".pbot" || ordinaryDirectory(parent)) && ordinaryDirectory(path);
|
|
1419
|
+
}
|
|
1420
|
+
function ensureDirectory(path) {
|
|
1421
|
+
if (sharedDirectory(path)) return;
|
|
1422
|
+
const first = mkdirSync3(path, { recursive: true, mode: 448 });
|
|
1423
|
+
requireThat(sharedDirectory(path), "\u65E0\u6CD5\u521B\u5EFA\u5386\u53F2\u76EE\u5F55\uFF1A" + path);
|
|
1424
|
+
if (first) {
|
|
1425
|
+
const existing = dirname2(resolve5(first));
|
|
1426
|
+
for (let child = resolve5(path); child !== existing && child !== dirname2(child); child = dirname2(child)) {
|
|
1427
|
+
syncDirectory(realpathSync4(dirname2(child)));
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
function earliestTimestamp(values) {
|
|
1432
|
+
let bestMs;
|
|
1433
|
+
let bestValue;
|
|
1434
|
+
for (const value of values) {
|
|
1435
|
+
if (!value) continue;
|
|
1436
|
+
const ms = Date.parse(value);
|
|
1437
|
+
if (Number.isNaN(ms)) continue;
|
|
1438
|
+
if (bestMs === void 0 || ms < bestMs) {
|
|
1439
|
+
bestMs = ms;
|
|
1440
|
+
bestValue = value;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return bestValue;
|
|
1444
|
+
}
|
|
1445
|
+
function historyBucketFromTimestamp(timestamp) {
|
|
1446
|
+
if (!timestamp) return unknownHistoryBucket;
|
|
1447
|
+
const ms = Date.parse(timestamp);
|
|
1448
|
+
if (Number.isNaN(ms)) return unknownHistoryBucket;
|
|
1449
|
+
const date = new Date(ms);
|
|
1450
|
+
const year = String(date.getUTCFullYear()).padStart(4, "0");
|
|
1451
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
1452
|
+
return `${year}/${month}`;
|
|
1453
|
+
}
|
|
1454
|
+
function rawHistoryBucket(raw) {
|
|
1455
|
+
const earliest = earliestTimestamp(raw.exchanges.map((item) => item.from)) ?? earliestTimestamp(raw.exchanges.map((item) => item.to));
|
|
1456
|
+
return historyBucketFromTimestamp(earliest);
|
|
1457
|
+
}
|
|
1458
|
+
function summaryArtifactBucket(artifact) {
|
|
1459
|
+
if (artifact.dimension === "monthly") {
|
|
1460
|
+
const match = monthlyIdPattern.exec(artifact.id);
|
|
1461
|
+
if (match) return match[1];
|
|
1462
|
+
const bucket = historyBucketFromTimestamp(artifact.from || artifact.to);
|
|
1463
|
+
return bucket === unknownHistoryBucket ? unknownHistoryBucket : bucket.slice(0, 4);
|
|
1464
|
+
}
|
|
1465
|
+
return historyBucketFromTimestamp(artifact.from || artifact.to);
|
|
1466
|
+
}
|
|
1467
|
+
var topLevelJsonNames = (directory) => readdirSync2(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && !entry.isSymbolicLink() && entry.name.endsWith(".json")).map((entry) => entry.name).sort();
|
|
1468
|
+
function bucketDirs(directory, depth) {
|
|
1469
|
+
if (!ordinaryDirectory(directory)) return [];
|
|
1470
|
+
const buckets = [];
|
|
1471
|
+
const entries = readdirSync2(directory, { withFileTypes: true });
|
|
1472
|
+
const years = entries.filter((entry) => entry.isDirectory() && !entry.isSymbolicLink() && yearPattern.test(entry.name)).map((entry) => entry.name).sort((a, b) => b.localeCompare(a));
|
|
1473
|
+
if (depth === "year") {
|
|
1474
|
+
buckets.push(...years);
|
|
1475
|
+
} else {
|
|
1476
|
+
for (const year of years) {
|
|
1477
|
+
const yearDir = join8(directory, year);
|
|
1478
|
+
const months = readdirSync2(yearDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.isSymbolicLink() && monthPattern.test(entry.name)).map((entry) => entry.name).sort((a, b) => b.localeCompare(a));
|
|
1479
|
+
for (const month of months) buckets.push(`${year}/${month}`);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
if (entries.some((entry) => entry.isDirectory() && !entry.isSymbolicLink() && entry.name === unknownHistoryBucket)) {
|
|
1483
|
+
buckets.push(unknownHistoryBucket);
|
|
1484
|
+
}
|
|
1485
|
+
return buckets;
|
|
1486
|
+
}
|
|
1487
|
+
function listLayoutJsonFiles(directory, layout, depth = "month") {
|
|
1488
|
+
if (!ordinaryDirectory(directory)) return [];
|
|
1489
|
+
if (layout === "flat") return topLevelJsonNames(directory);
|
|
1490
|
+
const results = [];
|
|
1491
|
+
for (const bucket of bucketDirs(directory, depth)) {
|
|
1492
|
+
const dir = join8(directory, bucket);
|
|
1493
|
+
for (const name of topLevelJsonNames(dir)) {
|
|
1494
|
+
results.push(`${bucket}/${name}`);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return results;
|
|
1498
|
+
}
|
|
1499
|
+
function locateLayoutFile(directory, name, layout, depth = "month") {
|
|
1500
|
+
if (!ordinaryDirectory(directory)) return void 0;
|
|
1501
|
+
if (layout === "flat") {
|
|
1502
|
+
return ordinaryFile(join8(directory, name)) ? name : void 0;
|
|
1503
|
+
}
|
|
1504
|
+
for (const bucket of bucketDirs(directory, depth)) {
|
|
1505
|
+
if (ordinaryFile(join8(directory, bucket, name))) return `${bucket}/${name}`;
|
|
1506
|
+
}
|
|
1507
|
+
return void 0;
|
|
1508
|
+
}
|
|
1509
|
+
var filename = (id) => fileId(id) + ".json";
|
|
1510
|
+
var diagnostic = (path, error) => path + ": " + String(error);
|
|
1511
|
+
function optional(read) {
|
|
1512
|
+
try {
|
|
1513
|
+
return read();
|
|
1514
|
+
} catch (error) {
|
|
1515
|
+
if (error.code !== "ENOENT") throw error;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
function namedRaw(value, relPath) {
|
|
1519
|
+
const raw = rawHistory(value);
|
|
1520
|
+
requireThat(basename2(relPath) === filename(raw.id), "\u5386\u53F2\u6587\u4EF6\u540D\u4E0E\u6839 ID \u4E0D\u5339\u914D\u3002");
|
|
1521
|
+
return raw;
|
|
1522
|
+
}
|
|
1523
|
+
function namedSummary(value, relPath, dimension) {
|
|
1524
|
+
const artifact = summaryArtifact(value, dimension);
|
|
1525
|
+
requireThat(basename2(relPath) === filename(artifact.id), "\u5386\u53F2\u6458\u8981\u6587\u4EF6\u540D\u4E0E ID \u4E0D\u5339\u914D\u3002");
|
|
1526
|
+
return artifact;
|
|
1527
|
+
}
|
|
1528
|
+
function canPrefilterWithRg(query) {
|
|
1529
|
+
return query.length > 0 && !/["\\\n\r\t]/.test(query);
|
|
1530
|
+
}
|
|
1531
|
+
function findCandidateJsonFiles(directory, query, layout = "monthly", depth = "month") {
|
|
1532
|
+
if (!ordinaryDirectory(directory)) return [];
|
|
1533
|
+
const trimmed = query.trim();
|
|
1534
|
+
if (!trimmed) return listLayoutJsonFiles(directory, layout, depth);
|
|
1535
|
+
const relativePattern = depth === "year" ? yearlyRelativeJsonPattern : monthlyRelativeJsonPattern;
|
|
1536
|
+
if (canPrefilterWithRg(trimmed)) {
|
|
1537
|
+
const args = [
|
|
1538
|
+
"--ignore-case",
|
|
1539
|
+
"--fixed-strings",
|
|
1540
|
+
"--files-with-matches",
|
|
1541
|
+
"--glob",
|
|
1542
|
+
"*.json",
|
|
1543
|
+
"--no-ignore",
|
|
1544
|
+
"--hidden",
|
|
1545
|
+
...layout === "flat" ? ["--max-depth", "1"] : [],
|
|
1546
|
+
"--",
|
|
1547
|
+
trimmed,
|
|
1548
|
+
directory
|
|
1549
|
+
];
|
|
1550
|
+
const result = spawnSync2("rg", args, { encoding: "utf8", maxBuffer: 8 * 1024 * 1024 });
|
|
1551
|
+
if (!result.error && (result.status === 0 || result.status === 1)) {
|
|
1552
|
+
if (result.status === 1) return [];
|
|
1553
|
+
const base = realpathSync4(directory);
|
|
1554
|
+
const matched2 = [];
|
|
1555
|
+
for (const line of result.stdout.split(/\r?\n/)) {
|
|
1556
|
+
const trimmedLine = line.trim();
|
|
1557
|
+
if (!trimmedLine) continue;
|
|
1558
|
+
const rel = relative(base, resolve5(trimmedLine)).replaceAll("\\", "/");
|
|
1559
|
+
if (layout === "flat") {
|
|
1560
|
+
if (!rel.includes("/") && rel.endsWith(".json")) matched2.push(rel);
|
|
1561
|
+
} else if (relativePattern.test(rel)) {
|
|
1562
|
+
matched2.push(rel);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
return matched2;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
const needle = trimmed.toLowerCase();
|
|
1569
|
+
const matched = [];
|
|
1570
|
+
for (const rel of listLayoutJsonFiles(directory, layout, depth)) {
|
|
1571
|
+
try {
|
|
1572
|
+
const content = readFileSync3(join8(directory, rel), "utf8");
|
|
1573
|
+
if (content.toLowerCase().includes(needle)) matched.push(rel);
|
|
1574
|
+
} catch {
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
return matched;
|
|
1578
|
+
}
|
|
1579
|
+
var HistoryFiles = class {
|
|
1580
|
+
constructor(directory, host = "pi", layout = "monthly") {
|
|
1581
|
+
this.directory = directory;
|
|
1582
|
+
this.host = host;
|
|
1583
|
+
this.layout = layout;
|
|
1584
|
+
requireThat(isHistoryHost(host), "\u5386\u53F2\u6765\u6E90\u65E0\u6548\u3002");
|
|
1585
|
+
}
|
|
1586
|
+
#warnings = [];
|
|
1587
|
+
#rawWarnings = [];
|
|
1588
|
+
get warnings() {
|
|
1589
|
+
return this.#warnings;
|
|
1590
|
+
}
|
|
1591
|
+
get rawWarnings() {
|
|
1592
|
+
return this.#rawWarnings;
|
|
1593
|
+
}
|
|
1594
|
+
get rawDirectory() {
|
|
1595
|
+
return join8(this.directory, "raw");
|
|
1596
|
+
}
|
|
1597
|
+
get summariesDirectory() {
|
|
1598
|
+
return join8(this.directory, "summaries");
|
|
1599
|
+
}
|
|
1600
|
+
summaryDirectory(dimension) {
|
|
1601
|
+
requireThat(isSummaryDimension(dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\uFF1A" + dimension);
|
|
1602
|
+
return join8(this.summariesDirectory, dimension);
|
|
1603
|
+
}
|
|
1604
|
+
withLock(lockName, label, operation) {
|
|
1605
|
+
ensureDirectory(this.directory);
|
|
1606
|
+
const lock = join8(this.directory, lockName);
|
|
1607
|
+
try {
|
|
1608
|
+
mkdirSync3(lock, { mode: 448 });
|
|
1609
|
+
} catch (error) {
|
|
1610
|
+
if (error.code === "EEXIST") {
|
|
1611
|
+
throw Object.assign(new Error("\u5386\u53F2\u5199\u9501\u88AB\u5360\u7528\uFF1A" + label), { code: "PBOT_HISTORY_BUSY" });
|
|
1612
|
+
}
|
|
1613
|
+
throw error;
|
|
1614
|
+
}
|
|
1615
|
+
try {
|
|
1616
|
+
return operation();
|
|
1617
|
+
} finally {
|
|
1618
|
+
rmdirSync(lock);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
/** Synchronous host write lock for raw history files. */
|
|
1622
|
+
control(operation) {
|
|
1623
|
+
return this.withLock(".write-" + this.host, this.host, operation);
|
|
1624
|
+
}
|
|
1625
|
+
/** Synchronous dimension write lock for derived summary files. */
|
|
1626
|
+
controlSummary(dimension, operation) {
|
|
1627
|
+
requireThat(isSummaryDimension(dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\uFF1A" + dimension);
|
|
1628
|
+
return this.withLock(".write-summary-" + dimension, "summary:" + dimension, operation);
|
|
1629
|
+
}
|
|
1630
|
+
/** Synchronous migration lock for explicit layout migration. */
|
|
1631
|
+
controlMigration(operation) {
|
|
1632
|
+
return this.withLock(".write-migrate", "migrate", operation);
|
|
1633
|
+
}
|
|
1634
|
+
/** Detect unmigrated top-level flat JSON files when running under monthly layout. */
|
|
1635
|
+
detectFlatFiles() {
|
|
1636
|
+
if (!sharedDirectory(this.directory)) return { rawCount: 0, summaryCount: 0, total: 0 };
|
|
1637
|
+
const rawCount = ordinaryDirectory(this.rawDirectory) ? topLevelJsonNames(this.rawDirectory).length : 0;
|
|
1638
|
+
let summaryCount = 0;
|
|
1639
|
+
for (const dim of this.listDimensions()) {
|
|
1640
|
+
const dir = this.summaryDirectory(dim);
|
|
1641
|
+
if (ordinaryDirectory(dir)) summaryCount += topLevelJsonNames(dir).length;
|
|
1642
|
+
}
|
|
1643
|
+
const total = rawCount + summaryCount;
|
|
1644
|
+
if (total === 0) return { rawCount: 0, summaryCount: 0, total: 0 };
|
|
1645
|
+
return {
|
|
1646
|
+
rawCount,
|
|
1647
|
+
summaryCount,
|
|
1648
|
+
total,
|
|
1649
|
+
message: `\u68C0\u6D4B\u5230 ${total} \u4E2A\u672A\u8FC1\u79FB\u7684\u5E73\u94FA\u5386\u53F2\u6587\u4EF6\uFF08raw ${rawCount}\uFF0Csummaries ${summaryCount}\uFF09\uFF1B\u5F53\u524D\u4E3A\u5E74\u6708\u76EE\u5F55\u5E03\u5C40\uFF08history.layout: monthly\uFF09\uFF0C\u672A\u8FC1\u79FB\u6587\u4EF6\u4E0D\u4F1A\u88AB\u8BFB\u53D6\u3002\u8BF7\u8FD0\u884C /pbot history migrate \u6574\u7406\u5230 YYYY/MM/ \u76EE\u5F55\uFF0C\u6216\u5728 .pbot/config.json \u4E2D\u8BBE\u7F6E "history": { "layout": "flat" } \u5207\u56DE\u5E73\u94FA\u5E03\u5C40\u3002`
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
listFlatRawFiles() {
|
|
1653
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.rawDirectory)) return [];
|
|
1654
|
+
return topLevelJsonNames(this.rawDirectory);
|
|
1655
|
+
}
|
|
1656
|
+
listFlatSummaryFiles(dimension) {
|
|
1657
|
+
requireThat(isSummaryDimension(dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\uFF1A" + dimension);
|
|
1658
|
+
const dir = this.summaryDirectory(dimension);
|
|
1659
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return [];
|
|
1660
|
+
return topLevelJsonNames(dir);
|
|
1661
|
+
}
|
|
1662
|
+
readFlatRawFile(name) {
|
|
1663
|
+
return readJsonFile(this.directory, "raw/" + name, (value) => namedRaw(value, name));
|
|
1664
|
+
}
|
|
1665
|
+
readFlatSummaryFile(dimension, name) {
|
|
1666
|
+
requireThat(isSummaryDimension(dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\uFF1A" + dimension);
|
|
1667
|
+
return readJsonFile(this.directory, `summaries/${dimension}/${name}`, (value) => namedSummary(value, name, dimension));
|
|
1668
|
+
}
|
|
1669
|
+
/** Atomically move a file within .pbot/history/ without ever overwriting an existing destination. */
|
|
1670
|
+
moveHistoryFile(fromRelative, toRelative) {
|
|
1671
|
+
ensureDirectory(this.directory);
|
|
1672
|
+
const src = internalPath(this.directory, fromRelative);
|
|
1673
|
+
const dstParentRel = dirname2(toRelative);
|
|
1674
|
+
if (dstParentRel && dstParentRel !== ".") {
|
|
1675
|
+
privateDirectory(this.directory, dstParentRel);
|
|
1676
|
+
}
|
|
1677
|
+
const dst = internalPath(this.directory, toRelative);
|
|
1678
|
+
try {
|
|
1679
|
+
linkSync2(src, dst);
|
|
1680
|
+
} catch (error) {
|
|
1681
|
+
if (error.code === "EEXIST") return "conflict";
|
|
1682
|
+
throw error;
|
|
1683
|
+
}
|
|
1684
|
+
unlinkSync2(src);
|
|
1685
|
+
syncDirectory(dirname2(dst));
|
|
1686
|
+
syncDirectory(dirname2(src));
|
|
1687
|
+
return "moved";
|
|
1688
|
+
}
|
|
1689
|
+
listRaw(filterHost, onlyFiles) {
|
|
1690
|
+
this.#warnings = [];
|
|
1691
|
+
this.#rawWarnings = [];
|
|
1692
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.rawDirectory)) return [];
|
|
1693
|
+
const files = onlyFiles ?? listLayoutJsonFiles(this.rawDirectory, this.layout);
|
|
1694
|
+
const results = [];
|
|
1695
|
+
for (const rel of files) {
|
|
1696
|
+
const path = join8(this.rawDirectory, rel);
|
|
1697
|
+
try {
|
|
1698
|
+
const raw = readJsonFile(this.directory, "raw/" + rel, (value) => namedRaw(value, rel));
|
|
1699
|
+
if (filterHost !== void 0 && raw.host !== filterHost) continue;
|
|
1700
|
+
results.push(raw);
|
|
1701
|
+
} catch (error) {
|
|
1702
|
+
if (error.code !== "ENOENT") {
|
|
1703
|
+
const message2 = diagnostic(path, error);
|
|
1704
|
+
this.#warnings.push(message2);
|
|
1705
|
+
this.#rawWarnings.push(message2);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
return results;
|
|
1710
|
+
}
|
|
1711
|
+
readRaw(id) {
|
|
1712
|
+
const name = filename(id);
|
|
1713
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.rawDirectory)) return void 0;
|
|
1714
|
+
const rel = locateLayoutFile(this.rawDirectory, name, this.layout);
|
|
1715
|
+
if (!rel) return void 0;
|
|
1716
|
+
return optional(() => readJsonFile(this.directory, "raw/" + rel, (value) => namedRaw(value, rel)));
|
|
1717
|
+
}
|
|
1718
|
+
saveRaw(raw) {
|
|
1719
|
+
requireThat(isHistoryHost(raw.host) && raw.host === this.host, "\u5386\u53F2\u5F52\u6863\u53EA\u5141\u8BB8\u6240\u5C5E\u6765\u6E90\u5199\u5165\u3002");
|
|
1720
|
+
rawHistory(raw);
|
|
1721
|
+
ensureDirectory(this.directory);
|
|
1722
|
+
const name = filename(raw.id);
|
|
1723
|
+
const existingRel = ordinaryDirectory(this.rawDirectory) ? locateLayoutFile(this.rawDirectory, name, this.layout) : void 0;
|
|
1724
|
+
const bucket = this.layout === "monthly" ? rawHistoryBucket(raw) : void 0;
|
|
1725
|
+
const rel = existingRel ?? (bucket ? `${bucket}/${name}` : name);
|
|
1726
|
+
const current = optional(() => readJsonFile(this.directory, "raw/" + rel, (value) => namedRaw(value, rel)));
|
|
1727
|
+
if (current) {
|
|
1728
|
+
matchIdentity(current, raw);
|
|
1729
|
+
if (isDeepStrictEqual(current, raw)) return;
|
|
1730
|
+
} else {
|
|
1731
|
+
privateDirectory(this.directory, bucket ? `raw/${bucket}` : "raw");
|
|
1732
|
+
}
|
|
1733
|
+
requireThat(writeJsonFile(this.directory, "raw/" + rel, raw, rawHistory, !current), "\u5386\u53F2\u6839 ID \u5DF2\u88AB\u5360\u7528\uFF1A" + rel);
|
|
1734
|
+
}
|
|
1735
|
+
listDimensions() {
|
|
1736
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory)) return [];
|
|
1737
|
+
const entries = readdirSync2(this.summariesDirectory, { withFileTypes: true });
|
|
1738
|
+
return entries.filter((entry) => entry.isDirectory() && !entry.isSymbolicLink() && isSummaryDimension(entry.name)).map((entry) => entry.name).sort();
|
|
1739
|
+
}
|
|
1740
|
+
summaryBucketDepth(dimension) {
|
|
1741
|
+
return dimension === "monthly" ? "year" : "month";
|
|
1742
|
+
}
|
|
1743
|
+
listSummaries(dimension, onlyFiles) {
|
|
1744
|
+
requireThat(isSummaryDimension(dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\uFF1A" + dimension);
|
|
1745
|
+
const dir = this.summaryDirectory(dimension);
|
|
1746
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return [];
|
|
1747
|
+
const files = onlyFiles ?? listLayoutJsonFiles(dir, this.layout, this.summaryBucketDepth(dimension));
|
|
1748
|
+
const results = [];
|
|
1749
|
+
for (const rel of files) {
|
|
1750
|
+
const path = join8(dir, rel);
|
|
1751
|
+
try {
|
|
1752
|
+
results.push(readJsonFile(this.directory, `summaries/${dimension}/${rel}`, (value) => namedSummary(value, rel, dimension)));
|
|
1753
|
+
} catch (error) {
|
|
1754
|
+
if (error.code !== "ENOENT") {
|
|
1755
|
+
this.#warnings.push(diagnostic(path, error));
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
return results;
|
|
1760
|
+
}
|
|
1761
|
+
readSummary(dimension, id) {
|
|
1762
|
+
requireThat(isSummaryDimension(dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\uFF1A" + dimension);
|
|
1763
|
+
const dir = this.summaryDirectory(dimension);
|
|
1764
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return void 0;
|
|
1765
|
+
const name = filename(id);
|
|
1766
|
+
const rel = locateLayoutFile(dir, name, this.layout, this.summaryBucketDepth(dimension));
|
|
1767
|
+
if (!rel) return void 0;
|
|
1768
|
+
return optional(() => readJsonFile(this.directory, `summaries/${dimension}/${rel}`, (value) => namedSummary(value, rel, dimension)));
|
|
1769
|
+
}
|
|
1770
|
+
saveSummary(artifact) {
|
|
1771
|
+
summaryArtifact(artifact);
|
|
1772
|
+
ensureDirectory(this.directory);
|
|
1773
|
+
const name = filename(artifact.id);
|
|
1774
|
+
const dir = this.summaryDirectory(artifact.dimension);
|
|
1775
|
+
const depth = this.summaryBucketDepth(artifact.dimension);
|
|
1776
|
+
const existingRel = ordinaryDirectory(this.summariesDirectory) && ordinaryDirectory(dir) ? locateLayoutFile(dir, name, this.layout, depth) : void 0;
|
|
1777
|
+
const bucket = this.layout === "monthly" ? summaryArtifactBucket(artifact) : void 0;
|
|
1778
|
+
const rel = existingRel ?? (bucket ? `${bucket}/${name}` : name);
|
|
1779
|
+
const relativePath = `summaries/${artifact.dimension}/${rel}`;
|
|
1780
|
+
privateDirectory(this.directory, dirname2(relativePath));
|
|
1781
|
+
const current = optional(() => readJsonFile(this.directory, relativePath, (value) => namedSummary(value, rel, artifact.dimension)));
|
|
1782
|
+
if (current && isDeepStrictEqual(current, artifact)) return;
|
|
1783
|
+
requireThat(
|
|
1784
|
+
writeJsonFile(this.directory, relativePath, artifact, (value) => summaryArtifact(value, artifact.dimension), !current),
|
|
1785
|
+
"\u5386\u53F2\u6458\u8981\u6587\u4EF6\u5DF2\u88AB\u5360\u7528\uFF1A" + relativePath
|
|
1786
|
+
);
|
|
1787
|
+
}
|
|
1788
|
+
/** Isolated read-only candidate search across raw/ and summaries/<dimension>/. */
|
|
1789
|
+
searchCandidateRaw(query) {
|
|
1790
|
+
const names = findCandidateJsonFiles(this.rawDirectory, query, this.layout, "month");
|
|
1791
|
+
return this.listRaw(void 0, names);
|
|
1792
|
+
}
|
|
1793
|
+
searchCandidateSummaries(dimension, query) {
|
|
1794
|
+
const dir = this.summaryDirectory(dimension);
|
|
1795
|
+
const names = findCandidateJsonFiles(dir, query, this.layout, this.summaryBucketDepth(dimension));
|
|
1796
|
+
return this.listSummaries(dimension, names);
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
|
|
1323
1800
|
// src/services/workspace/workspace-config.ts
|
|
1801
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
1324
1802
|
import { mkdir, readFile } from "node:fs/promises";
|
|
1325
|
-
import { dirname as
|
|
1326
|
-
var featureKeys = ["prompts", "skills", "mcp"];
|
|
1803
|
+
import { dirname as dirname3, join as join9 } from "node:path";
|
|
1804
|
+
var featureKeys = ["prompts", "skills", "mcp", "history"];
|
|
1805
|
+
var summaryKeys = ["backend", "model", "thinking", "concurrency"];
|
|
1806
|
+
var historyKeys = ["layout"];
|
|
1807
|
+
var historyLayouts = ["monthly", "flat"];
|
|
1808
|
+
function nonEmptyString(value) {
|
|
1809
|
+
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
1810
|
+
}
|
|
1327
1811
|
function config(value) {
|
|
1328
1812
|
if (!object(value) || value.enabled !== void 0 && typeof value.enabled !== "boolean") {
|
|
1329
1813
|
throw new Error("\u914D\u7F6E\u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0Cenabled \u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002");
|
|
1330
1814
|
}
|
|
1331
1815
|
if (value.features !== void 0) {
|
|
1332
1816
|
if (!object(value.features) || Object.entries(value.features).some(([key, entry]) => !featureKeys.includes(key) || entry !== void 0 && typeof entry !== "boolean")) {
|
|
1333
|
-
throw new Error("features \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 prompts\u3001skills\u3001mcp \u5E03\u5C14\u5F00\u5173\u3002");
|
|
1817
|
+
throw new Error("features \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 prompts\u3001skills\u3001mcp\u3001history \u5E03\u5C14\u5F00\u5173\u3002");
|
|
1334
1818
|
}
|
|
1335
1819
|
}
|
|
1336
1820
|
if (value.acp !== void 0) {
|
|
@@ -1344,6 +1828,31 @@ function config(value) {
|
|
|
1344
1828
|
}
|
|
1345
1829
|
}
|
|
1346
1830
|
}
|
|
1831
|
+
if (value.summary !== void 0) {
|
|
1832
|
+
if (!object(value.summary) || Object.keys(value.summary).some((key) => !summaryKeys.includes(key))) {
|
|
1833
|
+
throw new Error("summary \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 backend\u3001model\u3001thinking\u3001concurrency\u3002");
|
|
1834
|
+
}
|
|
1835
|
+
if (value.summary.backend !== void 0 && !isAcpBackend(value.summary.backend)) {
|
|
1836
|
+
throw new Error("summary.backend \u5FC5\u987B\u4E3A\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26\uFF081\u201364 \u5B57\u7B26\uFF09\u3002");
|
|
1837
|
+
}
|
|
1838
|
+
if (value.summary.model !== void 0 && !nonEmptyString(value.summary.model)) {
|
|
1839
|
+
throw new Error("summary.model \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002");
|
|
1840
|
+
}
|
|
1841
|
+
if (value.summary.thinking !== void 0 && !nonEmptyString(value.summary.thinking)) {
|
|
1842
|
+
throw new Error("summary.thinking \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002");
|
|
1843
|
+
}
|
|
1844
|
+
if (value.summary.concurrency !== void 0 && (typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > 8)) {
|
|
1845
|
+
throw new Error("summary.concurrency \u5FC5\u987B\u662F 1 \u5230 8 \u4E4B\u95F4\u7684\u6574\u6570\u3002");
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
if (value.history !== void 0) {
|
|
1849
|
+
if (!object(value.history) || Object.keys(value.history).some((key) => !historyKeys.includes(key))) {
|
|
1850
|
+
throw new Error("history \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 layout\u3002");
|
|
1851
|
+
}
|
|
1852
|
+
if (value.history.layout !== void 0 && !historyLayouts.includes(String(value.history.layout))) {
|
|
1853
|
+
throw new Error('history.layout \u5FC5\u987B\u662F "monthly" \u6216 "flat"\u3002');
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1347
1856
|
return value;
|
|
1348
1857
|
}
|
|
1349
1858
|
function workspaceFeatures(configuration) {
|
|
@@ -1351,11 +1860,28 @@ function workspaceFeatures(configuration) {
|
|
|
1351
1860
|
return {
|
|
1352
1861
|
prompts: raw?.prompts !== false,
|
|
1353
1862
|
skills: raw?.skills !== false,
|
|
1354
|
-
mcp: raw?.mcp !== false
|
|
1863
|
+
mcp: raw?.mcp !== false,
|
|
1864
|
+
history: raw?.history !== false
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
function workspaceHistoryConfig(configuration) {
|
|
1868
|
+
const raw = configuration && "history" in configuration ? configuration.history : configuration;
|
|
1869
|
+
return {
|
|
1870
|
+
layout: raw?.layout === "flat" ? "flat" : "monthly"
|
|
1355
1871
|
};
|
|
1356
1872
|
}
|
|
1357
1873
|
function workspaceConfigPath(root) {
|
|
1358
|
-
return
|
|
1874
|
+
return join9(root, ".pbot", "config.json");
|
|
1875
|
+
}
|
|
1876
|
+
function readWorkspaceHistoryLayoutSync(root) {
|
|
1877
|
+
const path = workspaceConfigPath(root);
|
|
1878
|
+
try {
|
|
1879
|
+
const content = readFileSync4(path, "utf8");
|
|
1880
|
+
const parsed = config(JSON.parse(content));
|
|
1881
|
+
return workspaceHistoryConfig(parsed.history).layout;
|
|
1882
|
+
} catch {
|
|
1883
|
+
return "monthly";
|
|
1884
|
+
}
|
|
1359
1885
|
}
|
|
1360
1886
|
async function readWorkspaceConfig(root) {
|
|
1361
1887
|
const path = workspaceConfigPath(root);
|
|
@@ -1374,7 +1900,9 @@ async function readWorkspaceConfig(root) {
|
|
|
1374
1900
|
present: true,
|
|
1375
1901
|
enabled: settings.enabled === true,
|
|
1376
1902
|
...settings.features ? { features: settings.features } : {},
|
|
1377
|
-
...settings.acp ? { acp: settings.acp } : {}
|
|
1903
|
+
...settings.acp ? { acp: settings.acp } : {},
|
|
1904
|
+
...settings.summary ? { summary: settings.summary } : {},
|
|
1905
|
+
...settings.history ? { history: settings.history } : {}
|
|
1378
1906
|
};
|
|
1379
1907
|
} catch (error) {
|
|
1380
1908
|
return { path, present: true, enabled: false, error: `\u5DE5\u4F5C\u533A\u914D\u7F6E\u65E0\u6548 ${path}: ${String(error)}` };
|
|
@@ -1384,13 +1912,363 @@ function workspaceDisabledMessage(configuration) {
|
|
|
1384
1912
|
return configuration.error ?? `Personal Bot \u672A\u5728\u6B64\u5DE5\u4F5C\u533A\u542F\u7528\u3002\u8BF7\u6267\u884C /pbot init \u521D\u59CB\u5316\u5E76\u542F\u7528\uFF1B\u914D\u7F6E\u6587\u4EF6\uFF1A${configuration.path}`;
|
|
1385
1913
|
}
|
|
1386
1914
|
|
|
1387
|
-
// src/
|
|
1915
|
+
// src/services/history/history-index.ts
|
|
1916
|
+
function orderedRawExchanges(raw) {
|
|
1917
|
+
const lookup = new Map(raw.exchanges.map((item) => [item.id, item]));
|
|
1918
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1919
|
+
const ordered = [];
|
|
1920
|
+
for (const branch of raw.branches) {
|
|
1921
|
+
for (const id of branch) {
|
|
1922
|
+
if (seen.has(id)) continue;
|
|
1923
|
+
const item = lookup.get(id);
|
|
1924
|
+
if (!item) continue;
|
|
1925
|
+
seen.add(id);
|
|
1926
|
+
ordered.push(item);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
const rest = raw.exchanges.filter((item) => !seen.has(item.id)).sort((a, b) => a.from.localeCompare(b.from) || a.id.localeCompare(b.id));
|
|
1930
|
+
ordered.push(...rest);
|
|
1931
|
+
return ordered;
|
|
1932
|
+
}
|
|
1933
|
+
function rawSessionTitle(raw) {
|
|
1934
|
+
return raw.name.trim();
|
|
1935
|
+
}
|
|
1936
|
+
function rawSessionSpan(exchanges) {
|
|
1937
|
+
const dates = exchanges.flatMap((item) => [item.from, item.to]).filter(Boolean).sort();
|
|
1938
|
+
return {
|
|
1939
|
+
from: dates[0] ?? "",
|
|
1940
|
+
to: dates.at(-1) ?? "",
|
|
1941
|
+
completed: exchanges.every((item) => item.completed)
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
// src/services/history/history-query.ts
|
|
1946
|
+
var summaryIdPrefix = "summary:";
|
|
1947
|
+
var page = (values, offset, limit) => ({
|
|
1948
|
+
values: values.slice(offset, offset + limit),
|
|
1949
|
+
nextOffset: offset + limit < values.length ? offset + limit : null
|
|
1950
|
+
});
|
|
1951
|
+
var previewText = (text3) => text3.replace(/\s+/g, " ").trim().slice(0, 100);
|
|
1952
|
+
function summaryNodeId(dimension, artifactId) {
|
|
1953
|
+
return `${summaryIdPrefix}${dimension}:${artifactId}`;
|
|
1954
|
+
}
|
|
1955
|
+
function parseSummaryNodeId(id) {
|
|
1956
|
+
if (!id.startsWith(summaryIdPrefix)) return void 0;
|
|
1957
|
+
const rest = id.slice(summaryIdPrefix.length);
|
|
1958
|
+
const sep = rest.indexOf(":");
|
|
1959
|
+
if (sep <= 0 || sep === rest.length - 1) return void 0;
|
|
1960
|
+
return { dimension: rest.slice(0, sep), artifactId: rest.slice(sep + 1) };
|
|
1961
|
+
}
|
|
1962
|
+
function parseExchangeNodeId(id) {
|
|
1963
|
+
const index = id.indexOf(":0:");
|
|
1964
|
+
if (index <= 0) return void 0;
|
|
1965
|
+
return { rawId: id.slice(0, index) };
|
|
1966
|
+
}
|
|
1967
|
+
function sessionBrief(raw, summaryPreview) {
|
|
1968
|
+
const ordered = orderedRawExchanges(raw);
|
|
1969
|
+
const span = rawSessionSpan(ordered);
|
|
1970
|
+
const name = rawSessionTitle(raw);
|
|
1971
|
+
return {
|
|
1972
|
+
host: raw.host,
|
|
1973
|
+
id: raw.id,
|
|
1974
|
+
kind: "session",
|
|
1975
|
+
sessionId: raw.sessionId,
|
|
1976
|
+
name,
|
|
1977
|
+
preview: summaryPreview ? previewText(summaryPreview) : previewText(name || ordered[0]?.text || ""),
|
|
1978
|
+
from: span.from,
|
|
1979
|
+
to: span.to,
|
|
1980
|
+
ready: true,
|
|
1981
|
+
completed: span.completed
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
function exchangeBrief(raw, exchange2, title) {
|
|
1985
|
+
return {
|
|
1986
|
+
host: raw.host,
|
|
1987
|
+
id: exchange2.id,
|
|
1988
|
+
kind: "exchange",
|
|
1989
|
+
sessionId: raw.sessionId,
|
|
1990
|
+
name: title,
|
|
1991
|
+
preview: previewText(exchange2.text),
|
|
1992
|
+
from: exchange2.from,
|
|
1993
|
+
to: exchange2.to,
|
|
1994
|
+
ready: true,
|
|
1995
|
+
completed: exchange2.completed
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
function summaryBrief(artifact) {
|
|
1999
|
+
return {
|
|
2000
|
+
host: artifact.host ?? "workspace",
|
|
2001
|
+
id: summaryNodeId(artifact.dimension, artifact.id),
|
|
2002
|
+
kind: "summary",
|
|
2003
|
+
dimension: artifact.dimension,
|
|
2004
|
+
sessionId: artifact.sessionId ?? artifact.id,
|
|
2005
|
+
name: artifact.title,
|
|
2006
|
+
preview: previewText(artifact.text),
|
|
2007
|
+
from: artifact.from,
|
|
2008
|
+
to: artifact.to,
|
|
2009
|
+
ready: true,
|
|
2010
|
+
completed: true
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
function sliceSnippet(text3, needle) {
|
|
2014
|
+
if (!needle) return text3.slice(0, 400);
|
|
2015
|
+
const start = Math.max(0, text3.toLowerCase().indexOf(needle) - 80);
|
|
2016
|
+
return text3.slice(start, start + 400);
|
|
2017
|
+
}
|
|
2018
|
+
function inTimeRange(from, to, after, before) {
|
|
2019
|
+
const fromMs = from ? Date.parse(from) : NaN;
|
|
2020
|
+
const toMs = to ? Date.parse(to) : NaN;
|
|
2021
|
+
if (after !== -Infinity && !Number.isNaN(toMs) && toMs < after) return false;
|
|
2022
|
+
if (before !== Infinity && !Number.isNaN(fromMs) && fromMs > before) return false;
|
|
2023
|
+
return true;
|
|
2024
|
+
}
|
|
2025
|
+
function searchWorkspaceHistory(root, query = {}) {
|
|
2026
|
+
const { host, sessionId, dimension, from, to, offset = 0, limit = 20 } = query;
|
|
2027
|
+
const needle = (query.query ?? "").trim().toLowerCase();
|
|
2028
|
+
const after = from === void 0 ? -Infinity : Date.parse(from);
|
|
2029
|
+
const before = to === void 0 ? Infinity : Date.parse(to);
|
|
2030
|
+
requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "\u65F6\u95F4\u8303\u56F4\u65E0\u6548\uFF0C\u8BF7\u4F7F\u7528 ISO \u65E5\u671F\u6216\u65F6\u95F4\u3002");
|
|
2031
|
+
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
2032
|
+
const files = new HistoryFiles(join10(root, ".pbot/history"), "pi", layout);
|
|
2033
|
+
const warnings = [];
|
|
2034
|
+
if (layout === "monthly") {
|
|
2035
|
+
const flatNotice = files.detectFlatFiles().message;
|
|
2036
|
+
if (flatNotice) warnings.push(flatNotice);
|
|
2037
|
+
}
|
|
2038
|
+
const matches = [];
|
|
2039
|
+
if (!needle) {
|
|
2040
|
+
if (dimension && dimension !== "raw") {
|
|
2041
|
+
const summaries = files.listSummaries(dimension);
|
|
2042
|
+
warnings.push(...files.warnings);
|
|
2043
|
+
for (const artifact of summaries) {
|
|
2044
|
+
if (host && artifact.host !== host) continue;
|
|
2045
|
+
if (sessionId && artifact.sessionId !== sessionId) continue;
|
|
2046
|
+
if (!inTimeRange(artifact.from, artifact.to, after, before)) continue;
|
|
2047
|
+
const brief = summaryBrief(artifact);
|
|
2048
|
+
matches.push({
|
|
2049
|
+
...brief,
|
|
2050
|
+
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
2051
|
+
snippet: sliceSnippet(artifact.text, "")
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
} else {
|
|
2055
|
+
const raws = files.listRaw(host);
|
|
2056
|
+
warnings.push(...files.warnings);
|
|
2057
|
+
const sessionSummaries = new Map(files.listSummaries("session").map((item) => [item.id, item]));
|
|
2058
|
+
warnings.push(...files.warnings);
|
|
2059
|
+
for (const raw of raws) {
|
|
2060
|
+
if (sessionId && raw.sessionId !== sessionId) continue;
|
|
2061
|
+
const summary = sessionSummaries.get(raw.id);
|
|
2062
|
+
const brief = sessionBrief(raw, summary?.text);
|
|
2063
|
+
if (!inTimeRange(brief.from, brief.to, after, before)) continue;
|
|
2064
|
+
matches.push({
|
|
2065
|
+
...brief,
|
|
2066
|
+
parents: [],
|
|
2067
|
+
snippet: summary ? sliceSnippet(summary.text, "") : brief.preview
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
} else {
|
|
2072
|
+
const searchRaw = !dimension || dimension === "raw";
|
|
2073
|
+
const summaryDimensions = dimension === "raw" ? [] : dimension ? [dimension] : files.listDimensions();
|
|
2074
|
+
if (searchRaw) {
|
|
2075
|
+
const candidateRaws = files.searchCandidateRaw(needle);
|
|
2076
|
+
warnings.push(...files.warnings);
|
|
2077
|
+
for (const raw of candidateRaws) {
|
|
2078
|
+
if (host && raw.host !== host) continue;
|
|
2079
|
+
if (sessionId && raw.sessionId !== sessionId) continue;
|
|
2080
|
+
const ordered = orderedRawExchanges(raw);
|
|
2081
|
+
const title = rawSessionTitle(raw);
|
|
2082
|
+
for (const item of ordered) {
|
|
2083
|
+
if (!item.text.toLowerCase().includes(needle)) continue;
|
|
2084
|
+
if (!inTimeRange(item.from, item.to, after, before)) continue;
|
|
2085
|
+
matches.push({
|
|
2086
|
+
...exchangeBrief(raw, item, title),
|
|
2087
|
+
parents: [raw.id],
|
|
2088
|
+
snippet: sliceSnippet(item.text, needle)
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
for (const dim of summaryDimensions) {
|
|
2094
|
+
const candidateSummaries = files.searchCandidateSummaries(dim, needle);
|
|
2095
|
+
warnings.push(...files.warnings);
|
|
2096
|
+
for (const artifact of candidateSummaries) {
|
|
2097
|
+
if (host && artifact.host !== host) continue;
|
|
2098
|
+
if (sessionId && artifact.sessionId !== sessionId) continue;
|
|
2099
|
+
const searchable = `${artifact.title}
|
|
2100
|
+
${artifact.text}`;
|
|
2101
|
+
if (!searchable.toLowerCase().includes(needle)) continue;
|
|
2102
|
+
if (!inTimeRange(artifact.from, artifact.to, after, before)) continue;
|
|
2103
|
+
matches.push({
|
|
2104
|
+
...summaryBrief(artifact),
|
|
2105
|
+
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
2106
|
+
snippet: sliceSnippet(artifact.text, needle)
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
matches.sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
|
|
2112
|
+
const paged = page(matches, offset, limit);
|
|
2113
|
+
return {
|
|
2114
|
+
matches: paged.values,
|
|
2115
|
+
total: matches.length,
|
|
2116
|
+
nextOffset: paged.nextOffset,
|
|
2117
|
+
warnings: [...new Set(warnings)]
|
|
2118
|
+
};
|
|
2119
|
+
}
|
|
2120
|
+
function sliceText(text3, offset, limit) {
|
|
2121
|
+
requireThat(offset <= text3.length, "\u8BFB\u53D6\u4F4D\u7F6E\u8D85\u51FA\u6B63\u6587\u3002");
|
|
2122
|
+
let start = offset;
|
|
2123
|
+
if (start && /[\uDC00-\uDFFF]/.test(text3[start] ?? "")) start--;
|
|
2124
|
+
let end = Math.min(text3.length, start + limit);
|
|
2125
|
+
if (end < text3.length && /[\uD800-\uDBFF]/.test(text3[end - 1] ?? "")) end += end - start === 1 ? 1 : -1;
|
|
2126
|
+
return {
|
|
2127
|
+
text: text3.slice(start, end),
|
|
2128
|
+
totalLength: text3.length,
|
|
2129
|
+
nextOffset: end < text3.length ? end : null
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
function findMonthlyParent(files, bucket, rawId) {
|
|
2133
|
+
if (files.layout !== "monthly" || bucket === unknownHistoryBucket) return void 0;
|
|
2134
|
+
const monthly = files.readSummary("monthly", bucket.replace("/", "-"));
|
|
2135
|
+
if (!monthly || !monthly.source.rawIds.includes(rawId)) return void 0;
|
|
2136
|
+
return summaryBrief(monthly);
|
|
2137
|
+
}
|
|
2138
|
+
function readWorkspaceHistory(root, id, offset = 0, limit = 12e3, childrenOffset = 0, host) {
|
|
2139
|
+
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
2140
|
+
const files = new HistoryFiles(join10(root, ".pbot/history"), "pi", layout);
|
|
2141
|
+
const baseWarnings = [];
|
|
2142
|
+
if (layout === "monthly") {
|
|
2143
|
+
const flatNotice = files.detectFlatFiles().message;
|
|
2144
|
+
if (flatNotice) baseWarnings.push(flatNotice);
|
|
2145
|
+
}
|
|
2146
|
+
const parsedSummary = parseSummaryNodeId(id);
|
|
2147
|
+
if (parsedSummary) {
|
|
2148
|
+
const artifact = files.readSummary(parsedSummary.dimension, parsedSummary.artifactId);
|
|
2149
|
+
requireThat(artifact && (!host || artifact.host === host), "\u5386\u53F2\u8282\u70B9\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u641C\u7D22\u3002");
|
|
2150
|
+
const parents = [];
|
|
2151
|
+
const children = [];
|
|
2152
|
+
if (artifact.dimension === "monthly") {
|
|
2153
|
+
for (const rawId of artifact.source.rawIds) {
|
|
2154
|
+
const sessionSummary = files.readSummary("session", rawId);
|
|
2155
|
+
if (sessionSummary) {
|
|
2156
|
+
children.push(summaryBrief(sessionSummary));
|
|
2157
|
+
continue;
|
|
2158
|
+
}
|
|
2159
|
+
const raw2 = files.readRaw(rawId);
|
|
2160
|
+
if (raw2) children.push(sessionBrief(raw2));
|
|
2161
|
+
}
|
|
2162
|
+
} else {
|
|
2163
|
+
const wantedExchanges = new Set(artifact.source.exchangeIds);
|
|
2164
|
+
for (const rawId of artifact.source.rawIds) {
|
|
2165
|
+
const raw2 = files.readRaw(rawId);
|
|
2166
|
+
if (!raw2) continue;
|
|
2167
|
+
parents.push(sessionBrief(raw2, artifact.dimension === "session" ? artifact.text : void 0));
|
|
2168
|
+
const ordered2 = orderedRawExchanges(raw2);
|
|
2169
|
+
const title2 = rawSessionTitle(raw2);
|
|
2170
|
+
for (const item of ordered2) {
|
|
2171
|
+
if (!wantedExchanges.size || wantedExchanges.has(item.id)) {
|
|
2172
|
+
children.push(exchangeBrief(raw2, item, title2));
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
if (artifact.dimension === "session") {
|
|
2177
|
+
const bucket = historyBucketFromTimestamp(artifact.from || artifact.to);
|
|
2178
|
+
const monthlyParent2 = findMonthlyParent(files, bucket, artifact.id);
|
|
2179
|
+
if (monthlyParent2) parents.push(monthlyParent2);
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
const pagedChildren2 = page(children, childrenOffset, 20);
|
|
2183
|
+
const sliced2 = sliceText(artifact.text, offset, limit);
|
|
2184
|
+
return {
|
|
2185
|
+
...summaryBrief(artifact),
|
|
2186
|
+
...sliced2,
|
|
2187
|
+
parents,
|
|
2188
|
+
children: pagedChildren2.values,
|
|
2189
|
+
nextChildrenOffset: pagedChildren2.nextOffset,
|
|
2190
|
+
source: {
|
|
2191
|
+
host: artifact.host ?? "workspace",
|
|
2192
|
+
sessionId: artifact.sessionId ?? artifact.id,
|
|
2193
|
+
entryIds: artifact.source.exchangeIds,
|
|
2194
|
+
dimension: artifact.dimension
|
|
2195
|
+
},
|
|
2196
|
+
warnings: [.../* @__PURE__ */ new Set([...baseWarnings, ...files.warnings])]
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
const parsedExchange = parseExchangeNodeId(id);
|
|
2200
|
+
if (parsedExchange) {
|
|
2201
|
+
const raw2 = files.readRaw(parsedExchange.rawId);
|
|
2202
|
+
requireThat(raw2 && (!host || raw2.host === host), "\u5386\u53F2\u8282\u70B9\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u641C\u7D22\u3002");
|
|
2203
|
+
const exchange2 = raw2.exchanges.find((item) => item.id === id);
|
|
2204
|
+
requireThat(exchange2, "\u5386\u53F2\u8282\u70B9\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u641C\u7D22\u3002");
|
|
2205
|
+
const title2 = rawSessionTitle(raw2);
|
|
2206
|
+
const parents = [sessionBrief(raw2)];
|
|
2207
|
+
for (const dim of files.listDimensions()) {
|
|
2208
|
+
if (dim === "monthly") continue;
|
|
2209
|
+
const artifact = files.readSummary(dim, raw2.id);
|
|
2210
|
+
if (artifact) parents.push(summaryBrief(artifact));
|
|
2211
|
+
}
|
|
2212
|
+
const sliced2 = sliceText(exchange2.text, offset, limit);
|
|
2213
|
+
return {
|
|
2214
|
+
...exchangeBrief(raw2, exchange2, title2),
|
|
2215
|
+
...sliced2,
|
|
2216
|
+
parents,
|
|
2217
|
+
children: [],
|
|
2218
|
+
nextChildrenOffset: null,
|
|
2219
|
+
source: {
|
|
2220
|
+
host: raw2.host,
|
|
2221
|
+
sessionId: raw2.sessionId,
|
|
2222
|
+
entryIds: exchange2.entryIds
|
|
2223
|
+
},
|
|
2224
|
+
warnings: [.../* @__PURE__ */ new Set([...baseWarnings, ...files.warnings])]
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
const raw = files.readRaw(id);
|
|
2228
|
+
requireThat(raw && (!host || raw.host === host), "\u5386\u53F2\u8282\u70B9\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u641C\u7D22\u3002");
|
|
2229
|
+
const ordered = orderedRawExchanges(raw);
|
|
2230
|
+
const title = rawSessionTitle(raw);
|
|
2231
|
+
const summaryChildren = [];
|
|
2232
|
+
let sessionSummaryText;
|
|
2233
|
+
for (const dim of files.listDimensions()) {
|
|
2234
|
+
if (dim === "monthly") continue;
|
|
2235
|
+
const artifact = files.readSummary(dim, raw.id);
|
|
2236
|
+
if (!artifact) continue;
|
|
2237
|
+
if (dim === "session") sessionSummaryText = artifact.text;
|
|
2238
|
+
summaryChildren.push(summaryBrief(artifact));
|
|
2239
|
+
}
|
|
2240
|
+
const monthlyParent = findMonthlyParent(files, rawHistoryBucket(raw), raw.id);
|
|
2241
|
+
const allChildren = [
|
|
2242
|
+
...summaryChildren,
|
|
2243
|
+
...ordered.map((item) => exchangeBrief(raw, item, title))
|
|
2244
|
+
];
|
|
2245
|
+
const pagedChildren = page(allChildren, childrenOffset, 20);
|
|
2246
|
+
const body = sessionSummaryText ? title ? `${title}
|
|
2247
|
+
|
|
2248
|
+
${sessionSummaryText}` : sessionSummaryText : title;
|
|
2249
|
+
const sliced = sliceText(body, offset, limit);
|
|
2250
|
+
return {
|
|
2251
|
+
...sessionBrief(raw, sessionSummaryText),
|
|
2252
|
+
...sliced,
|
|
2253
|
+
parents: monthlyParent ? [monthlyParent] : [],
|
|
2254
|
+
children: pagedChildren.values,
|
|
2255
|
+
nextChildrenOffset: pagedChildren.nextOffset,
|
|
2256
|
+
source: {
|
|
2257
|
+
host: raw.host,
|
|
2258
|
+
sessionId: raw.sessionId,
|
|
2259
|
+
entryIds: ordered.flatMap((item) => item.entryIds)
|
|
2260
|
+
},
|
|
2261
|
+
warnings: [.../* @__PURE__ */ new Set([...baseWarnings, ...files.warnings])]
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
// src/extension/mcp/bridge.ts
|
|
1388
2266
|
import { spawn } from "node:child_process";
|
|
1389
2267
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
1390
2268
|
|
|
1391
2269
|
// src/services/workspace/workspace-mcp.ts
|
|
1392
2270
|
import { mkdir as mkdir2, readFile as readFile2 } from "node:fs/promises";
|
|
1393
|
-
import { dirname as
|
|
2271
|
+
import { dirname as dirname4, join as join11, resolve as resolve6 } from "node:path";
|
|
1394
2272
|
var serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
|
|
1395
2273
|
var reservedServerNames = /* @__PURE__ */ new Set(["pbot"]);
|
|
1396
2274
|
var stdioKeys = /* @__PURE__ */ new Set(["command", "args", "env", "cwd", "description", "timeout", "enabled"]);
|
|
@@ -1502,7 +2380,7 @@ function validateMcpFile(value) {
|
|
|
1502
2380
|
return { mcpServers: servers };
|
|
1503
2381
|
}
|
|
1504
2382
|
function workspaceMcpPath(root) {
|
|
1505
|
-
return
|
|
2383
|
+
return join11(root, ".pbot", "mcp.json");
|
|
1506
2384
|
}
|
|
1507
2385
|
async function readWorkspaceMcpConfig(root) {
|
|
1508
2386
|
const path = workspaceMcpPath(root);
|
|
@@ -1551,7 +2429,7 @@ function resolveWorkspaceMcpServer(root, name, server, env = process.env) {
|
|
|
1551
2429
|
for (const [key, value] of Object.entries(server.env ?? {})) {
|
|
1552
2430
|
resolvedEnv[key] = expandEnvTemplate(value, env, `MCP \u670D\u52A1 "${name}" \u7684 env.${key}`);
|
|
1553
2431
|
}
|
|
1554
|
-
const cwd = server.cwd ?
|
|
2432
|
+
const cwd = server.cwd ? resolve6(root, expandEnvTemplate(server.cwd, env, `MCP \u670D\u52A1 "${name}" \u7684 cwd`)) : root;
|
|
1555
2433
|
return {
|
|
1556
2434
|
transport: "stdio",
|
|
1557
2435
|
name,
|
|
@@ -1564,7 +2442,7 @@ function resolveWorkspaceMcpServer(root, name, server, env = process.env) {
|
|
|
1564
2442
|
};
|
|
1565
2443
|
}
|
|
1566
2444
|
|
|
1567
|
-
// src/extension/mcp
|
|
2445
|
+
// src/extension/mcp/bridge.ts
|
|
1568
2446
|
var protocolVersion = "2025-03-26";
|
|
1569
2447
|
var maxStderrBytes = 4096;
|
|
1570
2448
|
function rpcError(server, method, error) {
|
|
@@ -1884,9 +2762,9 @@ var WorkspaceMcpBridge = class {
|
|
|
1884
2762
|
const tools = [];
|
|
1885
2763
|
let cursor;
|
|
1886
2764
|
for (; ; ) {
|
|
1887
|
-
const
|
|
1888
|
-
if (object(
|
|
1889
|
-
const next = object(
|
|
2765
|
+
const page2 = await client.request("tools/list", cursor ? { cursor } : {});
|
|
2766
|
+
if (object(page2) && Array.isArray(page2.tools)) tools.push(...page2.tools);
|
|
2767
|
+
const next = object(page2) && typeof page2.nextCursor === "string" && page2.nextCursor ? page2.nextCursor : void 0;
|
|
1890
2768
|
if (!next) break;
|
|
1891
2769
|
cursor = next;
|
|
1892
2770
|
}
|
|
@@ -1936,7 +2814,7 @@ var WorkspaceMcpBridge = class {
|
|
|
1936
2814
|
}
|
|
1937
2815
|
};
|
|
1938
2816
|
|
|
1939
|
-
// src/extension/mcp
|
|
2817
|
+
// src/extension/mcp/workers.ts
|
|
1940
2818
|
var protocolVersion2 = "2025-03-26";
|
|
1941
2819
|
var readyTimeoutMs = 45e3;
|
|
1942
2820
|
var defaultWaitMs = 5e4;
|
|
@@ -1945,7 +2823,8 @@ var reportPageSize = 16e3;
|
|
|
1945
2823
|
var progressIntervalMs = 5e3;
|
|
1946
2824
|
var responseActions = ["accept", "decline", "cancel"];
|
|
1947
2825
|
var discoverTargets = ["overview", "workers", "backends", "models"];
|
|
1948
|
-
var
|
|
2826
|
+
var mcpHistoryToolNames = ["history_search", "history_read"];
|
|
2827
|
+
var allMcpToolNames = [...mcpWorkerToolNames, ...workspaceMcpToolNames, ...mcpHistoryToolNames];
|
|
1949
2828
|
var toolParams = {
|
|
1950
2829
|
worker_create: /* @__PURE__ */ new Set(["backend", "model", "thinking", "cwd", "workspace"]),
|
|
1951
2830
|
worker_close: /* @__PURE__ */ new Set(["workerId", "workspace"]),
|
|
@@ -1954,9 +2833,12 @@ var toolParams = {
|
|
|
1954
2833
|
worker_output: /* @__PURE__ */ new Set(["workerId", "offset", "waitMs", "workspace"]),
|
|
1955
2834
|
worker_discover: /* @__PURE__ */ new Set(["target", "workerId", "backend", "model", "workspace"]),
|
|
1956
2835
|
workspace_mcp_discover: /* @__PURE__ */ new Set(["server", "workspace"]),
|
|
1957
|
-
workspace_mcp_call: /* @__PURE__ */ new Set(["server", "tool", "arguments", "workspace"])
|
|
2836
|
+
workspace_mcp_call: /* @__PURE__ */ new Set(["server", "tool", "arguments", "workspace"]),
|
|
2837
|
+
history_search: /* @__PURE__ */ new Set(["host", "dimension", "query", "sessionId", "from", "to", "offset", "limit", "workspace"]),
|
|
2838
|
+
history_read: /* @__PURE__ */ new Set(["id", "host", "offset", "limit", "childrenOffset", "workspace"])
|
|
1958
2839
|
};
|
|
1959
|
-
var
|
|
2840
|
+
var mcpWorkerOnlyInstructions = "\u63D0\u4F9B\u8DE8\u52A9\u624B\u534F\u4F5C\u80FD\u529B\uFF08worker_*\uFF09\uFF1A\u53EF\u542F\u52A8\u5E76\u8C03\u5EA6\u5176\u4ED6\u5916\u90E8 AI \u52A9\u624B\u5728\u5F53\u524D\u5DE5\u4F5C\u533A\u4E2D\u72EC\u7ACB\u6267\u884C\u4EFB\u52A1\uFF0C\u9002\u7528\u4E8E\u7528\u6237\u6307\u5B9A\u5176\u4ED6\u52A9\u624B\u3001\u9700\u8981\u7279\u5B9A\u6A21\u578B\u6216\u601D\u8003\u6DF1\u5EA6\u3001\u83B7\u53D6\u72EC\u7ACB\u5BA1\u67E5/\u7B2C\u4E8C\u610F\u89C1\uFF0C\u6216\u5E76\u884C\u5904\u7406\u5B50\u4EFB\u52A1\u3002\u4E0D\u9700\u8981\u501F\u52A9\u5176\u4ED6\u52A9\u624B\u65F6\uFF0C\u4F18\u5148\u81EA\u884C\u5B8C\u6210\u6216\u4F7F\u7528\u5F53\u524D\u5185\u7F6E\u5B50\u4EE3\u7406\u3002\n\u4F7F\u7528\u6D41\u7A0B\uFF1A\u7528 worker_create \u542F\u52A8\u76EE\u6807\u52A9\u624B\uFF08\u6216\u7528 worker_discover \u590D\u7528\u5DF2\u6709\u4F1A\u8BDD\uFF09\u2192 \u7528 worker_request \u6D3E\u53D1\u4EFB\u52A1\u6216\u7EE7\u7EED\u8FFD\u95EE \u2192 \u4EFB\u52A1\u5B8C\u6210\u540E\u53EF\u7528 worker_close \u7ED3\u675F\u4F1A\u8BDD\u3002\u540E\u53F0\u7B49\u5F85\u3001\u8D85\u65F6\u7EED\u7B49\uFF08timedOut\uFF09\u6216\u957F\u7ED3\u679C\u7FFB\u9875\uFF08nextOffset\uFF09\u7528 worker_output\uFF1B\u52A9\u624B\u8BF7\u6C42\u6388\u6743\u6216\u63D0\u95EE\uFF08needsResponse\uFF09\u65F6\uFF0C\u5148\u5411\u7528\u6237\u786E\u8BA4\uFF0C\u518D\u7528 worker_response \u56DE\u590D\u3002";
|
|
2841
|
+
var mcpInstructions = "\u63D0\u4F9B\u4E09\u7C7B\u80FD\u529B\uFF1A\n1. \u8DE8\u52A9\u624B\u534F\u4F5C\uFF08worker_*\uFF09\uFF1A\u542F\u52A8\u5E76\u8C03\u5EA6\u5176\u4ED6\u5916\u90E8 AI \u52A9\u624B\u5728\u5F53\u524D\u5DE5\u4F5C\u533A\u4E2D\u72EC\u7ACB\u6267\u884C\u4EFB\u52A1\uFF0C\u9002\u7528\u4E8E\u7528\u6237\u6307\u5B9A\u5176\u4ED6\u52A9\u624B\u3001\u9700\u8981\u7279\u5B9A\u6A21\u578B\u6216\u601D\u8003\u6DF1\u5EA6\u3001\u83B7\u53D6\u72EC\u7ACB\u5BA1\u67E5/\u7B2C\u4E8C\u610F\u89C1\uFF0C\u6216\u5E76\u884C\u5904\u7406\u5B50\u4EFB\u52A1\u3002\u4E0D\u9700\u8981\u501F\u52A9\u5176\u4ED6\u52A9\u624B\u65F6\uFF0C\u4F18\u5148\u81EA\u884C\u5B8C\u6210\u6216\u4F7F\u7528\u5F53\u524D\u5185\u7F6E\u5B50\u4EE3\u7406\u3002\u4F7F\u7528\u6D41\u7A0B\uFF1Aworker_create \u542F\u52A8\u52A9\u624B\uFF08\u6216 worker_discover \u590D\u7528\u5DF2\u6709\u4F1A\u8BDD\uFF09\u2192 worker_request \u6D3E\u53D1\u4EFB\u52A1\u6216\u8FFD\u95EE \u2192 \u5B8C\u6210\u540E worker_close \u7ED3\u675F\uFF1B\u540E\u53F0\u7B49\u5F85\u3001\u8D85\u65F6\u7EED\u7B49\uFF08timedOut\uFF09\u6216\u957F\u7ED3\u679C\u7FFB\u9875\uFF08nextOffset\uFF09\u7528 worker_output\uFF1B\u8FD4\u56DE needsResponse \u65F6\u5148\u5411\u7528\u6237\u786E\u8BA4\uFF0C\u518D\u7528 worker_response \u56DE\u590D\u3002\n2. \u5DE5\u4F5C\u533A\u5171\u4EAB\u5916\u90E8\u5DE5\u5177\uFF08workspace_mcp_*\uFF09\uFF1A\u53D1\u73B0\u5E76\u8C03\u7528\u5F53\u524D\u5DE5\u4F5C\u533A\u63A5\u5165\u7684\u5916\u90E8\u5DE5\u5177\u670D\u52A1\u4E0E\u6570\u636E\u6E90\uFF08\u53EF\u4E0E\u5F53\u524D\u73AF\u5883\u539F\u751F\u5DE5\u5177\u540C\u65F6\u4F7F\u7528\uFF09\u3002\u5148\u7528 workspace_mcp_discover \u67E5\u770B\u53EF\u7528\u670D\u52A1\u4E0E\u5DE5\u5177\u8BF4\u660E\uFF0C\u518D\u7528 workspace_mcp_call \u8C03\u7528\u3002\n3. \u8DE8\u5BBF\u4E3B\u5386\u53F2\u67E5\u8BE2\uFF08history_search / history_read\uFF09\uFF1A\u53EA\u8BFB\u68C0\u7D22\u5F53\u524D\u5DE5\u4F5C\u533A\u5728 Pi\u3001dsh\u3001Claude Code\u3001Antigravity \u7B49\u5BBF\u4E3B\u4E2D\u8BB0\u5F55\u7684\u5386\u53F2\u95EE\u7B54\u4E0E\u6458\u8981\u5F52\u6863\u3002";
|
|
1960
2842
|
function formatBackendItem(entry, defaultBackend) {
|
|
1961
2843
|
const tags = [];
|
|
1962
2844
|
if (entry.label) tags.push(entry.label);
|
|
@@ -1969,14 +2851,14 @@ function summarizeBackends(commands = {}, defaultBackend) {
|
|
|
1969
2851
|
const unavailable = entries.filter((item) => !item.available);
|
|
1970
2852
|
const availableText = available.map((item) => formatBackendItem(item, defaultBackend)).join("\u3001");
|
|
1971
2853
|
const unavailableText = unavailable.map((item) => formatBackendItem(item, defaultBackend)).join("\u3001");
|
|
1972
|
-
const overview = available.length ? unavailable.length ? `\u53EF\u7528
|
|
2854
|
+
const overview = available.length ? unavailable.length ? `\u5F53\u524D\u53EF\u7528\u52A9\u624B\uFF1A${availableText}\uFF1B\u6682\u4E0D\u53EF\u7528\uFF1A${unavailableText}\u3002` : `\u5F53\u524D\u53EF\u7528\u52A9\u624B\uFF1A${availableText}\u3002` : `\u5F53\u524D\u65E0\u53EF\u7528\u5916\u90E8\u52A9\u624B\uFF08\u6682\u4E0D\u53EF\u7528\uFF1A${unavailableText}\uFF09\u3002`;
|
|
1973
2855
|
const availableIds = available.map((item) => item.backend).join("\u3001");
|
|
1974
2856
|
return { overview, availableIds };
|
|
1975
2857
|
}
|
|
1976
2858
|
function workspaceProperty(workspaceBound) {
|
|
1977
2859
|
return {
|
|
1978
2860
|
type: "string",
|
|
1979
|
-
description: workspaceBound ? "\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u7EDD\u5BF9\u8DEF\u5F84\uFF1B\
|
|
2861
|
+
description: workspaceBound ? "\u76EE\u6807\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF1B\u9ED8\u8BA4\u4F7F\u7528\u5F53\u524D\u5DE5\u4F5C\u533A\uFF0C\u901A\u5E38\u7701\u7565\u3002" : "\u76EE\u6807\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF08\u5982\u4E0A\u4E0B\u6587\u4E2D\u63D0\u4F9B\u4E86 workspaceRoot \u5219\u4F20\u8BE5\u8DEF\u5F84\uFF09\uFF1B\u8BF7\u663E\u5F0F\u4F20\u5165\u3002"
|
|
1980
2862
|
};
|
|
1981
2863
|
}
|
|
1982
2864
|
function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = false) {
|
|
@@ -1986,7 +2868,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1986
2868
|
return [
|
|
1987
2869
|
{
|
|
1988
2870
|
name: "worker_create",
|
|
1989
|
-
description: "\
|
|
2871
|
+
description: "\u542F\u52A8\u4E00\u4E2A\u72EC\u7ACB\u7684\u5916\u90E8 AI \u52A9\u624B\u4F1A\u8BDD\uFF08worker\uFF09\uFF0C\u7528\u4E8E\u5C06\u4EFB\u52A1\u59D4\u6D3E\u7ED9\u5176\u4ED6\u52A9\u624B\u6216\u6307\u5B9A\u6A21\u578B/\u601D\u8003\u6DF1\u5EA6\u6765\u72EC\u7ACB\u5904\u7406\uFF08\u5982\u6309\u7528\u6237\u8981\u6C42\u5207\u6362\u52A9\u624B\u3001\u83B7\u53D6\u72EC\u7ACB\u5BA1\u67E5\u6216\u7B2C\u4E8C\u610F\u89C1\u3001\u5E76\u884C\u5206\u62C5\u5B50\u4EFB\u52A1\uFF09\u3002\u672C\u5DE5\u5177\u4EC5\u5EFA\u7ACB\u4F1A\u8BDD\u5E76\u8FD4\u56DE workerId\uFF0C\u968F\u540E\u901A\u8FC7 worker_request \u53D1\u9001\u5177\u4F53\u4EFB\u52A1\u3002\u4E0D\u9700\u8981\u501F\u52A9\u5176\u4ED6\u52A9\u624B\u65F6\uFF0C\u4F18\u5148\u81EA\u884C\u5B8C\u6210\u6216\u4F7F\u7528\u5F53\u524D\u5185\u7F6E\u5B50\u4EE3\u7406\u3002\n" + overview,
|
|
1990
2872
|
annotations: {
|
|
1991
2873
|
title: "Create Worker",
|
|
1992
2874
|
readOnlyHint: false,
|
|
@@ -2001,19 +2883,19 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2001
2883
|
properties: {
|
|
2002
2884
|
backend: {
|
|
2003
2885
|
type: "string",
|
|
2004
|
-
description: "\
|
|
2886
|
+
description: "\u8981\u542F\u52A8\u7684\u5916\u90E8\u52A9\u624B\u6807\u8BC6\uFF08\u4E0D\u533A\u5206\u5927\u5C0F\u5199\uFF0C\u652F\u6301\u5E38\u89C1\u522B\u540D\uFF0C\u5982 claude-code\u3001agy\uFF09\u3002"
|
|
2005
2887
|
},
|
|
2006
2888
|
model: {
|
|
2007
2889
|
type: "string",
|
|
2008
|
-
description: '\u4EC5\u7528\u6237\u660E\u786E\
|
|
2890
|
+
description: '\u4EC5\u7528\u6237\u660E\u786E\u8981\u6C42\u7279\u5B9A\u6A21\u578B\u65F6\u6307\u5B9A\uFF08\u652F\u6301\u6A21\u578B ID\u3001\u663E\u793A\u540D\u6216 provider/model\uFF0C\u4E0D\u533A\u5206\u5927\u5C0F\u5199\uFF09\uFF1B\u4E0D\u786E\u5B9A\u53EF\u7528\u503C\u65F6\u5148\u7528 worker_discover(target="models") \u67E5\u8BE2\uFF1B\u4E0D\u586B\u5219\u4F7F\u7528\u8BE5\u52A9\u624B\u9ED8\u8BA4\u6A21\u578B\u3002'
|
|
2009
2891
|
},
|
|
2010
2892
|
thinking: {
|
|
2011
2893
|
type: "string",
|
|
2012
|
-
description: "\u4EC5\u7528\u6237\u660E\u786E\
|
|
2894
|
+
description: "\u4EC5\u7528\u6237\u660E\u786E\u8981\u6C42\u601D\u8003\u6DF1\u5EA6\u65F6\u6307\u5B9A\uFF08\u5982 low / medium / high / xhigh / max\uFF0C\u4E0D\u533A\u5206\u5927\u5C0F\u5199\uFF09\uFF1B\u4E0D\u586B\u5219\u4F7F\u7528\u9ED8\u8BA4\u8BBE\u7F6E\u3002"
|
|
2013
2895
|
},
|
|
2014
2896
|
cwd: {
|
|
2015
2897
|
type: "string",
|
|
2016
|
-
description: "
|
|
2898
|
+
description: "\u52A9\u624B\u6267\u884C\u4EFB\u52A1\u65F6\u7684\u5DE5\u4F5C\u76EE\u5F55\uFF08\u7EDD\u5BF9\u8DEF\u5F84\u6216\u76F8\u5BF9\u5DE5\u4F5C\u533A\u7684\u8DEF\u5F84\uFF09\uFF0C\u9ED8\u8BA4\u4E3A\u5F53\u524D\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u3002"
|
|
2017
2899
|
},
|
|
2018
2900
|
workspace
|
|
2019
2901
|
}
|
|
@@ -2021,7 +2903,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2021
2903
|
},
|
|
2022
2904
|
{
|
|
2023
2905
|
name: "worker_close",
|
|
2024
|
-
description: "\
|
|
2906
|
+
description: "\u7ED3\u675F\u4E0D\u518D\u9700\u8981\u7684\u5916\u90E8\u52A9\u624B\u4F1A\u8BDD\u5E76\u91CA\u653E\u8D44\u6E90\u3002\u82E5\u8BE5\u52A9\u624B\u652F\u6301\u4F1A\u8BDD\u6062\u590D\uFF0C\u540E\u7EED\u4ECD\u53EF\u76F4\u63A5\u7528 worker_request \u5728\u539F\u4E0A\u4E0B\u6587\u4E2D\u7EE7\u7EED\u5BF9\u8BDD\u3002",
|
|
2025
2907
|
annotations: {
|
|
2026
2908
|
title: "Close Worker",
|
|
2027
2909
|
readOnlyHint: false,
|
|
@@ -2036,7 +2918,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2036
2918
|
properties: {
|
|
2037
2919
|
workerId: {
|
|
2038
2920
|
type: "string",
|
|
2039
|
-
description: "\u8981\
|
|
2921
|
+
description: "\u8981\u7ED3\u675F\u7684\u52A9\u624B\u4F1A\u8BDD ID\uFF08\u6765\u81EA worker_create \u6216 worker_discover\uFF09\u3002"
|
|
2040
2922
|
},
|
|
2041
2923
|
workspace
|
|
2042
2924
|
}
|
|
@@ -2044,7 +2926,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2044
2926
|
},
|
|
2045
2927
|
{
|
|
2046
2928
|
name: "worker_request",
|
|
2047
|
-
description: `\u5411\u6307\u5B9A
|
|
2929
|
+
description: `\u5411\u6307\u5B9A\u7684\u5916\u90E8\u52A9\u624B\u6D3E\u53D1\u4EFB\u52A1\uFF0C\u6216\u5728\u540C\u4E00\u4E0A\u4E0B\u6587\u4E2D\u8FFD\u95EE\u4E0E\u8865\u5145\u8981\u6C42\uFF0C\u5E76\u83B7\u53D6\u6267\u884C\u7ED3\u679C\uFF08\u5DF2\u5173\u95ED\u4F46\u652F\u6301\u6062\u590D\u7684\u4F1A\u8BDD\u4F1A\u81EA\u52A8\u7EED\u63A5\uFF09\u3002\u9ED8\u8BA4\u6700\u591A\u7B49\u5F85 ${defaultWaitMs / 1e3} \u79D2\u8FD4\u56DE\u7ED3\u679C\uFF1B\u5C06 waitMs \u8BBE\u4E3A 0 \u53EF\u7ACB\u5373\u8FD4\u56DE\u5E76\u8F6C\u5165\u540E\u53F0\u6267\u884C\uFF0C\u9002\u5408\u8017\u65F6\u4EFB\u52A1\u6216\u591A\u52A9\u624B\u5E76\u884C\u3002\u82E5\u8FD4\u56DE timedOut \u6216\u7ED3\u679C\u542B nextOffset\uFF0C\u7528 worker_output \u7EE7\u7EED\u7B49\u5F85\u6216\u7FFB\u9875\uFF1B\u82E5\u8FD4\u56DE needsResponse\uFF0C\u5148\u5411\u7528\u6237\u786E\u8BA4\u518D\u7528 worker_response \u56DE\u590D\u3002`,
|
|
2048
2930
|
annotations: {
|
|
2049
2931
|
title: "Send Request to Worker",
|
|
2050
2932
|
readOnlyHint: false,
|
|
@@ -2059,17 +2941,17 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2059
2941
|
properties: {
|
|
2060
2942
|
workerId: {
|
|
2061
2943
|
type: "string",
|
|
2062
|
-
description: "\u76EE\u6807
|
|
2944
|
+
description: "\u76EE\u6807\u52A9\u624B\u4F1A\u8BDD ID\uFF08\u6765\u81EA worker_create \u6216 worker_discover\uFF09\u3002"
|
|
2063
2945
|
},
|
|
2064
2946
|
message: {
|
|
2065
2947
|
type: "string",
|
|
2066
|
-
description: "\u53D1\
|
|
2948
|
+
description: "\u8981\u53D1\u9001\u7684\u4EFB\u52A1\u8BF4\u660E\u6216\u8FFD\u95EE\u5185\u5BB9\u3002\u5916\u90E8\u52A9\u624B\u770B\u4E0D\u5230\u4F60\u4E0E\u7528\u6237\u7684\u5BF9\u8BDD\u5386\u53F2\uFF0C\u9996\u6B21\u6D3E\u53D1\u65F6\u8BF7\u5199\u6E05\u80CC\u666F\u3001\u76EE\u6807\u3001\u76F8\u5173\u6587\u4EF6\u8DEF\u5F84\u3001\u7EA6\u675F\u6761\u4EF6\u548C\u671F\u671B\u4EA7\u51FA\u3002"
|
|
2067
2949
|
},
|
|
2068
2950
|
waitMs: {
|
|
2069
2951
|
type: "integer",
|
|
2070
2952
|
minimum: 0,
|
|
2071
2953
|
maximum: maxWaitMs,
|
|
2072
|
-
description: `\u6700\u591A\u7B49\u5F85\u7684\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B\
|
|
2954
|
+
description: `\u6700\u591A\u7B49\u5F85\u7ED3\u679C\u7684\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B\u8BBE\u4E3A 0 \u53EF\u7ACB\u5373\u8FD4\u56DE\u5E76\u5728\u540E\u53F0\u6267\u884C\u3002`
|
|
2073
2955
|
},
|
|
2074
2956
|
workspace
|
|
2075
2957
|
}
|
|
@@ -2077,7 +2959,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2077
2959
|
},
|
|
2078
2960
|
{
|
|
2079
2961
|
name: "worker_response",
|
|
2080
|
-
description: `\
|
|
2962
|
+
description: `\u5F53\u5916\u90E8\u52A9\u624B\u5728\u6267\u884C\u8FC7\u7A0B\u4E2D\u6682\u505C\u5E76\u8BF7\u6C42\u786E\u8BA4\u6216\u8865\u5145\u4FE1\u606F\uFF08\u8FD4\u56DE needsResponse: true\uFF09\u65F6\uFF0C\u5411\u5176\u63D0\u4EA4\u51B3\u5B9A\u4EE5\u7EE7\u7EED\u6267\u884C\u3002\u652F\u6301\u4E09\u7C7B\u8BF7\u6C42\uFF1A\u64CD\u4F5C\u6388\u6743\uFF08kind="permission"\uFF09\u3001\u95EE\u7B54\u8868\u5355\uFF08kind="form"\uFF09\u548C\u94FE\u63A5\u786E\u8BA4\uFF08kind="url"\uFF09\u3002\u63D0\u4EA4\u524D\u5148\u5411\u7528\u6237\u786E\u8BA4\uFF1B\u63D0\u4EA4\u540E\u9ED8\u8BA4\u6700\u591A\u7B49\u5F85 ${defaultWaitMs / 1e3} \u79D2\u8FD4\u56DE\u540E\u7EED\u7ED3\u679C\uFF08waitMs \u8BBE\u4E3A 0 \u7ACB\u5373\u8FD4\u56DE\uFF09\u3002`,
|
|
2081
2963
|
annotations: {
|
|
2082
2964
|
title: "Respond to Worker Request",
|
|
2083
2965
|
readOnlyHint: false,
|
|
@@ -2092,31 +2974,31 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2092
2974
|
properties: {
|
|
2093
2975
|
workerId: {
|
|
2094
2976
|
type: "string",
|
|
2095
|
-
description: "\
|
|
2977
|
+
description: "\u7B49\u5F85\u56DE\u590D\u7684\u52A9\u624B\u4F1A\u8BDD ID\u3002"
|
|
2096
2978
|
},
|
|
2097
2979
|
action: {
|
|
2098
2980
|
type: "string",
|
|
2099
2981
|
enum: [...responseActions],
|
|
2100
|
-
description: "
|
|
2982
|
+
description: "\u5904\u7406\u65B9\u5F0F\uFF1Aaccept \u8868\u793A\u540C\u610F\u6388\u6743\u3001\u63D0\u4EA4\u8868\u5355\u56DE\u7B54\u6216\u786E\u8BA4\u94FE\u63A5\uFF1Bdecline \u8868\u793A\u62D2\u7EDD\uFF1Bcancel \u8868\u793A\u53D6\u6D88\u672C\u6B21\u8BF7\u6C42\u3002"
|
|
2101
2983
|
},
|
|
2102
2984
|
requestId: {
|
|
2103
2985
|
type: "string",
|
|
2104
|
-
description: "\
|
|
2986
|
+
description: "\u8981\u56DE\u590D\u7684\u8BF7\u6C42 ID\uFF08\u6765\u81EA pendingRequests[].requestId\uFF09\uFF1B\u4EC5\u4E00\u6761\u5F85\u5904\u7406\u8BF7\u6C42\u65F6\u53EF\u7701\u7565\uFF0C\u591A\u6761\u65F6\u5FC5\u586B\u3002"
|
|
2105
2987
|
},
|
|
2106
2988
|
optionId: {
|
|
2107
2989
|
type: "string",
|
|
2108
|
-
description: '\u4EC5
|
|
2990
|
+
description: '\u4EC5\u6388\u6743\u8BF7\u6C42\uFF08kind="permission"\uFF09\u4E14 action \u4E0D\u4E3A cancel \u65F6\u53EF\u7528\uFF1A\u6307\u5B9A\u9009\u9879 ID\uFF08\u6765\u81EA pendingRequests[].options[].optionId\uFF09\uFF0C\u7701\u7565\u65F6\u9ED8\u8BA4\u5355\u6B21\u5141\u8BB8\u6216\u62D2\u7EDD\u3002'
|
|
2109
2991
|
},
|
|
2110
2992
|
content: {
|
|
2111
2993
|
type: "object",
|
|
2112
2994
|
additionalProperties: true,
|
|
2113
|
-
description: '\u4EC5
|
|
2995
|
+
description: '\u4EC5\u8868\u5355\u63D0\u95EE\uFF08kind="form"\uFF09\u4E14 action="accept" \u65F6\u53EF\u7528\uFF1A\u6309 pendingRequests[].schema.properties \u586B\u5199\u7684\u56DE\u7B54\u5BF9\u8C61\uFF08\u503C\u4E3A\u5B57\u7B26\u4E32\u3001\u6570\u5B57\u3001\u5E03\u5C14\u503C\u6216\u5B57\u7B26\u4E32\u6570\u7EC4\uFF09\u3002'
|
|
2114
2996
|
},
|
|
2115
2997
|
waitMs: {
|
|
2116
2998
|
type: "integer",
|
|
2117
2999
|
minimum: 0,
|
|
2118
3000
|
maximum: maxWaitMs,
|
|
2119
|
-
description: `\u56DE\u590D\u540E\u6700\u591A\u7B49\u5F85\u7684\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B\
|
|
3001
|
+
description: `\u63D0\u4EA4\u56DE\u590D\u540E\u6700\u591A\u7B49\u5F85\u540E\u7EED\u7ED3\u679C\u7684\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B\u8BBE\u4E3A 0 \u7ACB\u5373\u8FD4\u56DE\u3002`
|
|
2120
3002
|
},
|
|
2121
3003
|
workspace
|
|
2122
3004
|
}
|
|
@@ -2124,7 +3006,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2124
3006
|
},
|
|
2125
3007
|
{
|
|
2126
3008
|
name: "worker_output",
|
|
2127
|
-
description: "\u83B7\u53D6\
|
|
3009
|
+
description: "\u83B7\u53D6\u6216\u7B49\u5F85\u5916\u90E8\u52A9\u624B\u7684\u6700\u65B0\u6267\u884C\u7ED3\u679C\u3002\u7528\u4E8E\u6536\u53D6\u540E\u53F0\u4EFB\u52A1\u7684\u4EA7\u51FA\u3001\u5728\u7B49\u5F85\u8D85\u65F6\uFF08timedOut\uFF09\u540E\u7EE7\u7EED\u7B49\u5F85\uFF0C\u6216\u5728\u957F\u7ED3\u679C\u5206\u9875\uFF08\u542B nextOffset\uFF09\u65F6\u8BFB\u53D6\u540E\u7EED\u5185\u5BB9\u3002\u4EFB\u52A1\u4ECD\u5728\u8FD0\u884C\u65F6\u4F1A\u7B49\u5F85\u5176\u5B8C\u6210\uFF08\u4E5F\u53EF\u80FD\u8FD4\u56DE timedOut \u6216 needsResponse\uFF09\uFF0C\u5DF2\u7ED3\u675F\u5219\u7ACB\u5373\u8FD4\u56DE\u3002",
|
|
2128
3010
|
annotations: {
|
|
2129
3011
|
title: "Get Worker Output",
|
|
2130
3012
|
readOnlyHint: true,
|
|
@@ -2139,18 +3021,18 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2139
3021
|
properties: {
|
|
2140
3022
|
workerId: {
|
|
2141
3023
|
type: "string",
|
|
2142
|
-
description: "\u8981\u7B49\u5F85\u6216\
|
|
3024
|
+
description: "\u8981\u7B49\u5F85\u6216\u83B7\u53D6\u7ED3\u679C\u7684\u52A9\u624B\u4F1A\u8BDD ID\u3002"
|
|
2143
3025
|
},
|
|
2144
3026
|
offset: {
|
|
2145
3027
|
type: "integer",
|
|
2146
3028
|
minimum: 0,
|
|
2147
|
-
description: "\
|
|
3029
|
+
description: "\u7ED3\u679C\u8BFB\u53D6\u8D77\u59CB\u4F4D\u7F6E\uFF08\u9ED8\u8BA4 0\uFF09\uFF1B\u7FFB\u9875\u8BFB\u53D6\u5269\u4F59\u5185\u5BB9\u65F6\u4F20\u5165\u4E0A\u6B21\u8FD4\u56DE\u7684 nextOffset\u3002"
|
|
2148
3030
|
},
|
|
2149
3031
|
waitMs: {
|
|
2150
3032
|
type: "integer",
|
|
2151
3033
|
minimum: 0,
|
|
2152
3034
|
maximum: maxWaitMs,
|
|
2153
|
-
description: `\u4EFB\u52A1\u4ECD\u5728\u8FD0\u884C\u65F6\u6700\u591A\u7B49\u5F85\u7684\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B\u5DF2\u7ED3\u675F\u6216\u7FFB\u9875\u65F6\u7ACB\u5373\u8FD4\u56DE\u3002`
|
|
3035
|
+
description: `\u4EFB\u52A1\u4ECD\u5728\u8FD0\u884C\u65F6\u6700\u591A\u7B49\u5F85\u7684\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B\u4EFB\u52A1\u5DF2\u7ED3\u675F\u6216\u7FFB\u9875\u8BFB\u53D6\u65F6\u4F1A\u7ACB\u5373\u8FD4\u56DE\u3002`
|
|
2154
3036
|
},
|
|
2155
3037
|
workspace
|
|
2156
3038
|
}
|
|
@@ -2158,7 +3040,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2158
3040
|
},
|
|
2159
3041
|
{
|
|
2160
3042
|
name: "worker_discover",
|
|
2161
|
-
description: '\
|
|
3043
|
+
description: '\u4E86\u89E3\u5F53\u524D\u53EF\u4EE5\u59D4\u6D3E\u54EA\u4E9B\u5916\u90E8\u52A9\u624B\u3001\u67E5\u770B\u5DF2\u6709\u52A9\u624B\u4F1A\u8BDD\u7684\u8FD0\u884C\u72B6\u6001\u4EE5\u4FBF\u590D\u7528\uFF0C\u6216\u67E5\u8BE2\u67D0\u4E2A\u52A9\u624B\u652F\u6301\u7684\u6A21\u578B\u4E0E\u601D\u8003\u6DF1\u5EA6\u9009\u9879\u3002\u9ED8\u8BA4\uFF08target="overview"\uFF09\u540C\u65F6\u8FD4\u56DE\u53EF\u7528\u52A9\u624B\u4E0E\u5DF2\u6709\u4F1A\u8BDD\uFF1B\u4EC5\u5728\u9700\u8981\u6838\u5BF9\u6A21\u578B\u6216\u601D\u8003\u6DF1\u5EA6\u53EF\u9009\u503C\u65F6\u518D\u67E5 target="models"\uFF08\u8017\u65F6\u8F83\u957F\uFF09\u3002',
|
|
2162
3044
|
annotations: {
|
|
2163
3045
|
title: "Discover Workers, Backends & Models",
|
|
2164
3046
|
readOnlyHint: true,
|
|
@@ -2174,19 +3056,19 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
2174
3056
|
target: {
|
|
2175
3057
|
type: "string",
|
|
2176
3058
|
enum: [...discoverTargets],
|
|
2177
|
-
description: '\u67E5\u8BE2\u8303\u56F4\uFF0C\u9ED8\u8BA4 "overview"\uFF08\u540C\u65F6\u8FD4\u56DE
|
|
3059
|
+
description: '\u67E5\u8BE2\u8303\u56F4\uFF0C\u9ED8\u8BA4 "overview"\uFF08\u540C\u65F6\u8FD4\u56DE\u53EF\u7528\u52A9\u624B\u4E0E\u5DF2\u6709\u4F1A\u8BDD\uFF09\uFF1B"workers" \u67E5\u5168\u90E8\u6216\u5355\u4E2A\u4F1A\u8BDD\u72B6\u6001\uFF1B"backends" \u67E5\u53EF\u7528\u52A9\u624B\u5217\u8868\uFF1B"models" \u67E5\u6307\u5B9A\u52A9\u624B\u652F\u6301\u7684\u6A21\u578B\u4E0E\u601D\u8003\u6DF1\u5EA6\u3002'
|
|
2178
3060
|
},
|
|
2179
3061
|
workerId: {
|
|
2180
3062
|
type: "string",
|
|
2181
|
-
description: '\u4EC5 target="workers" \u53EF\u7528\uFF1A\u6307\u5B9A\u5355\u4E2A
|
|
3063
|
+
description: '\u4EC5 target="workers" \u53EF\u7528\uFF1A\u6307\u5B9A\u5355\u4E2A\u52A9\u624B\u4F1A\u8BDD ID\uFF1B\u4E0D\u586B\u5219\u5217\u51FA\u5168\u90E8\u3002'
|
|
2182
3064
|
},
|
|
2183
3065
|
backend: {
|
|
2184
3066
|
type: "string",
|
|
2185
|
-
description: availableIds ? `\u4EC5 target="models" \u53EF\u7528\uFF08${modelsBackendHint}\uFF09\uFF1A\u76EE\u6807\
|
|
3067
|
+
description: availableIds ? `\u4EC5 target="models" \u53EF\u7528\uFF08${modelsBackendHint}\uFF09\uFF1A\u76EE\u6807\u5916\u90E8\u52A9\u624B\u6807\u8BC6\uFF0C\u652F\u6301\u5E38\u89C1\u522B\u540D\uFF1B\u5F53\u524D\u53EF\u7528\uFF1A${availableIds}\u3002` : `\u4EC5 target="models" \u53EF\u7528\uFF08${modelsBackendHint}\uFF09\uFF1A\u76EE\u6807\u5916\u90E8\u52A9\u624B\u6807\u8BC6\uFF0C\u652F\u6301\u5E38\u89C1\u522B\u540D\u3002`
|
|
2186
3068
|
},
|
|
2187
3069
|
model: {
|
|
2188
3070
|
type: "string",
|
|
2189
|
-
description: '\u4EC5 target="models" \u53EF\u7528\uFF1A\u6307\u5B9A\u6A21\u578B\u4EE5\u67E5\
|
|
3071
|
+
description: '\u4EC5 target="models" \u53EF\u7528\uFF1A\u6307\u5B9A\u6A21\u578B\u4EE5\u67E5\u770B\u8BE5\u6A21\u578B\u652F\u6301\u7684\u601D\u8003\u6DF1\u5EA6\u9009\u9879\u3002'
|
|
2190
3072
|
},
|
|
2191
3073
|
workspace
|
|
2192
3074
|
}
|
|
@@ -2199,7 +3081,7 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
2199
3081
|
return [
|
|
2200
3082
|
{
|
|
2201
3083
|
name: "workspace_mcp_discover",
|
|
2202
|
-
description: "\
|
|
3084
|
+
description: "\u53D1\u73B0\u5F53\u524D\u5DE5\u4F5C\u533A\u5171\u4EAB\u7684\u5916\u90E8\u5DE5\u5177\u670D\u52A1\uFF08MCP\uFF09\u53CA\u5176\u53EF\u7528\u5DE5\u5177\u3002\u4E0D\u4F20 server \u65F6\u5217\u51FA\u53EF\u7528\u670D\u52A1\uFF1B\u4F20\u5165 server \u65F6\u8FD4\u56DE\u8BE5\u670D\u52A1\u63D0\u4F9B\u7684\u5DE5\u5177\u6E05\u5355\u4E0E\u53C2\u6570\u8BF4\u660E\u3002",
|
|
2203
3085
|
annotations: {
|
|
2204
3086
|
title: "Discover Workspace MCP Servers & Tools",
|
|
2205
3087
|
readOnlyHint: true,
|
|
@@ -2214,7 +3096,7 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
2214
3096
|
properties: {
|
|
2215
3097
|
server: {
|
|
2216
3098
|
type: "string",
|
|
2217
|
-
description: "\u76EE\u6807
|
|
3099
|
+
description: "\u76EE\u6807\u5DE5\u5177\u670D\u52A1\u540D\u79F0\uFF1B\u4E0D\u586B\u65F6\u5217\u51FA\u5DE5\u4F5C\u533A\u5168\u90E8\u53EF\u7528\u670D\u52A1\u3002"
|
|
2218
3100
|
},
|
|
2219
3101
|
workspace
|
|
2220
3102
|
}
|
|
@@ -2222,7 +3104,7 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
2222
3104
|
},
|
|
2223
3105
|
{
|
|
2224
3106
|
name: "workspace_mcp_call",
|
|
2225
|
-
description: "\u8C03\u7528\u5DE5\u4F5C\u533A
|
|
3107
|
+
description: "\u8C03\u7528\u5F53\u524D\u5DE5\u4F5C\u533A\u5171\u4EAB\u7684\u5916\u90E8\u5DE5\u5177\u670D\u52A1\uFF08MCP\uFF09\u4E2D\u7684\u6307\u5B9A\u5DE5\u5177\uFF0C\u7528\u4E8E\u8BBF\u95EE\u5DE5\u4F5C\u533A\u63A5\u5165\u7684\u5916\u90E8\u80FD\u529B\u4E0E\u6570\u636E\u6E90\u3002\u4E0D\u786E\u5B9A\u5DE5\u5177\u540D\u6216\u53C2\u6570\u683C\u5F0F\u65F6\uFF0C\u5148\u7528 workspace_mcp_discover(server) \u67E5\u8BE2\u3002",
|
|
2226
3108
|
annotations: {
|
|
2227
3109
|
title: "Call Workspace MCP Tool",
|
|
2228
3110
|
readOnlyHint: false,
|
|
@@ -2237,16 +3119,118 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
2237
3119
|
properties: {
|
|
2238
3120
|
server: {
|
|
2239
3121
|
type: "string",
|
|
2240
|
-
description: "\u76EE\u6807
|
|
3122
|
+
description: "\u76EE\u6807\u5DE5\u5177\u670D\u52A1\u540D\u79F0\uFF08\u53EF\u901A\u8FC7 workspace_mcp_discover \u83B7\u53D6\uFF09\u3002"
|
|
2241
3123
|
},
|
|
2242
3124
|
tool: {
|
|
2243
3125
|
type: "string",
|
|
2244
|
-
description: "\u8981\u8C03\u7528\u7684\
|
|
3126
|
+
description: "\u8981\u8C03\u7528\u7684\u5DE5\u5177\u540D\u79F0\u3002"
|
|
2245
3127
|
},
|
|
2246
3128
|
arguments: {
|
|
2247
3129
|
type: "object",
|
|
2248
3130
|
additionalProperties: true,
|
|
2249
|
-
description: "\u4F20\
|
|
3131
|
+
description: "\u4F20\u7ED9\u76EE\u6807\u5DE5\u5177\u7684\u53C2\u6570\u5BF9\u8C61\uFF0C\u4E0D\u586B\u5219\u4E3A\u7A7A\u5BF9\u8C61\u3002"
|
|
3132
|
+
},
|
|
3133
|
+
workspace
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
];
|
|
3138
|
+
}
|
|
3139
|
+
function buildHistoryMcpTools(workspaceBound = false) {
|
|
3140
|
+
const workspace = workspaceProperty(workspaceBound);
|
|
3141
|
+
return [
|
|
3142
|
+
{
|
|
3143
|
+
name: "history_search",
|
|
3144
|
+
description: "\u641C\u7D22\u5F53\u524D\u5DE5\u4F5C\u533A\u8DE8\u5BBF\u4E3B\uFF08pi\u3001dsh\u3001claude\u3001antigravity \u7B49\uFF09\u7684\u5386\u53F2\u95EE\u7B54\u4E0E\u6458\u8981\u5F52\u6863\u3002\u7701\u7565 query \u65F6\u5217\u51FA\u5404\u4F1A\u8BDD\uFF1B\u4F20\u5165 query \u6309\u4E0D\u533A\u5206\u5927\u5C0F\u5199\u7684\u8FDE\u7EED\u5173\u952E\u8BCD\u5339\u914D\u539F\u6587\u4E0E\u6458\u8981\u3002",
|
|
3145
|
+
annotations: {
|
|
3146
|
+
title: "Search Workspace History",
|
|
3147
|
+
readOnlyHint: true,
|
|
3148
|
+
destructiveHint: false,
|
|
3149
|
+
idempotentHint: true,
|
|
3150
|
+
openWorldHint: false
|
|
3151
|
+
},
|
|
3152
|
+
inputSchema: {
|
|
3153
|
+
type: "object",
|
|
3154
|
+
additionalProperties: false,
|
|
3155
|
+
required: [],
|
|
3156
|
+
properties: {
|
|
3157
|
+
host: {
|
|
3158
|
+
type: "string",
|
|
3159
|
+
description: "\u53EF\u9009\u6765\u6E90\u7B5B\u9009\uFF08\u5982 pi\u3001dsh\u3001claude\u3001antigravity\uFF09\uFF1B\u7701\u7565\u67E5\u5168\u90E8\u5BBF\u4E3B\u3002"
|
|
3160
|
+
},
|
|
3161
|
+
dimension: {
|
|
3162
|
+
type: "string",
|
|
3163
|
+
description: "\u53EF\u9009\u8303\u56F4\u7B5B\u9009\uFF1Araw \u8868\u793A\u4EC5\u641C\u539F\u6587\uFF0C\u6216\u6307\u5B9A\u6458\u8981\u7EF4\u5EA6\uFF08\u5982 monthly\u3001session\uFF09\uFF1B\u7701\u7565\u67E5\u5168\u90E8\u539F\u6587\u4E0E\u7EF4\u5EA6\u6458\u8981\u3002"
|
|
3164
|
+
},
|
|
3165
|
+
query: {
|
|
3166
|
+
type: "string",
|
|
3167
|
+
description: "\u4E0D\u533A\u5206\u5927\u5C0F\u5199\u7684\u8FDE\u7EED\u5173\u952E\u8BCD\uFF1B\u7701\u7565\u65F6\u5217\u51FA\u5404\u4F1A\u8BDD\uFF08\u6216\u6307\u5B9A\u7EF4\u5EA6\u6458\u8981\uFF09\u3002"
|
|
3168
|
+
},
|
|
3169
|
+
sessionId: {
|
|
3170
|
+
type: "string",
|
|
3171
|
+
description: "\u9650\u5B9A\u5728\u6307\u5B9A\u539F\u59CB\u4F1A\u8BDD ID \u5185\u641C\u7D22\u3002"
|
|
3172
|
+
},
|
|
3173
|
+
from: {
|
|
3174
|
+
type: "string",
|
|
3175
|
+
description: "ISO \u65E5\u671F\u6216\u65F6\u95F4\u4E0B\u754C\u3002"
|
|
3176
|
+
},
|
|
3177
|
+
to: {
|
|
3178
|
+
type: "string",
|
|
3179
|
+
description: "ISO \u65E5\u671F\u6216\u65F6\u95F4\u4E0A\u754C\u3002"
|
|
3180
|
+
},
|
|
3181
|
+
offset: {
|
|
3182
|
+
type: "integer",
|
|
3183
|
+
minimum: 0,
|
|
3184
|
+
description: "\u5339\u914D\u7ED3\u679C\u504F\u79FB\uFF0C\u9ED8\u8BA4 0\u3002"
|
|
3185
|
+
},
|
|
3186
|
+
limit: {
|
|
3187
|
+
type: "integer",
|
|
3188
|
+
minimum: 1,
|
|
3189
|
+
maximum: 50,
|
|
3190
|
+
description: "\u6700\u591A\u8FD4\u56DE\u6761\u6570\uFF081\u201350\uFF09\uFF0C\u9ED8\u8BA4 20\u3002"
|
|
3191
|
+
},
|
|
3192
|
+
workspace
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
3195
|
+
},
|
|
3196
|
+
{
|
|
3197
|
+
name: "history_read",
|
|
3198
|
+
description: "\u6309\u8282\u70B9 id \u8BFB\u53D6\u5F53\u524D\u5DE5\u4F5C\u533A\u5386\u53F2\u5F52\u6863\u7684\u6B63\u6587\u4E0E\u4E0A\u4E0B\u7EA7\u8282\u70B9\uFF08monthly\u3001session\u3001summary\u3001exchange\uFF09\uFF0C\u652F\u6301\u4ECE\u6708\u5EA6\u6C47\u603B\u4E0B\u94BB\u81F3\u5355\u4F1A\u8BDD\u6458\u8981\u4E0E\u539F\u59CB\u95EE\u7B54\u3002\u6B63\u6587\u8FC7\u957F\u65F6\u7528 nextOffset \u7EED\u8BFB\uFF0C\u5B50\u8282\u70B9\u8FC7\u591A\u65F6\u7528 nextChildrenOffset \u7EED\u8BFB\u3002",
|
|
3199
|
+
annotations: {
|
|
3200
|
+
title: "Read Workspace History Node",
|
|
3201
|
+
readOnlyHint: true,
|
|
3202
|
+
destructiveHint: false,
|
|
3203
|
+
idempotentHint: true,
|
|
3204
|
+
openWorldHint: false
|
|
3205
|
+
},
|
|
3206
|
+
inputSchema: {
|
|
3207
|
+
type: "object",
|
|
3208
|
+
additionalProperties: false,
|
|
3209
|
+
required: ["id"],
|
|
3210
|
+
properties: {
|
|
3211
|
+
id: {
|
|
3212
|
+
type: "string",
|
|
3213
|
+
description: "history_search \u6216\u4E0A\u4E0B\u7EA7\u8FD4\u56DE\u7684\u8282\u70B9 id\u3002"
|
|
3214
|
+
},
|
|
3215
|
+
host: {
|
|
3216
|
+
type: "string",
|
|
3217
|
+
description: "\u8DE8\u6765\u6E90 ID \u51B2\u7A81\u65F6\u663E\u5F0F\u6307\u5B9A\u6765\u6E90\u5BBF\u4E3B\u3002"
|
|
3218
|
+
},
|
|
3219
|
+
offset: {
|
|
3220
|
+
type: "integer",
|
|
3221
|
+
minimum: 0,
|
|
3222
|
+
description: "\u6B63\u6587\u5B57\u7B26\u504F\u79FB\uFF0C\u9ED8\u8BA4 0\u3002"
|
|
3223
|
+
},
|
|
3224
|
+
limit: {
|
|
3225
|
+
type: "integer",
|
|
3226
|
+
minimum: 1,
|
|
3227
|
+
maximum: 24e3,
|
|
3228
|
+
description: "\u6B63\u6587\u5B57\u7B26\u6570\uFF081\u201324000\uFF09\uFF0C\u9ED8\u8BA4 12000\u3002"
|
|
3229
|
+
},
|
|
3230
|
+
childrenOffset: {
|
|
3231
|
+
type: "integer",
|
|
3232
|
+
minimum: 0,
|
|
3233
|
+
description: "\u5B50\u8282\u70B9\u5217\u8868\u504F\u79FB\uFF0C\u9ED8\u8BA4 0\uFF1B\u7EED\u8BFB\u4F20\u4E0A\u9875 nextChildrenOffset\u3002"
|
|
2250
3234
|
},
|
|
2251
3235
|
workspace
|
|
2252
3236
|
}
|
|
@@ -2257,8 +3241,8 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
2257
3241
|
var pbotWorkerTools = buildPbotWorkerTools();
|
|
2258
3242
|
function defaultWorkerDirectory() {
|
|
2259
3243
|
if (process.env.PBOT_MCP_AGENT_DIR) return process.env.PBOT_MCP_AGENT_DIR;
|
|
2260
|
-
if (process.env.PLUGIN_DATA) return
|
|
2261
|
-
return
|
|
3244
|
+
if (process.env.PLUGIN_DATA) return join12(process.env.PLUGIN_DATA, "subagents");
|
|
3245
|
+
return join12(homedir(), ".pbot/subagents");
|
|
2262
3246
|
}
|
|
2263
3247
|
function isKnownTool(name) {
|
|
2264
3248
|
return allMcpToolNames.includes(name);
|
|
@@ -2330,11 +3314,21 @@ var McpWorkerRuntime = class {
|
|
|
2330
3314
|
#sessionId;
|
|
2331
3315
|
#directory;
|
|
2332
3316
|
#defaultBackend;
|
|
3317
|
+
#nativeWorkspaceMcp;
|
|
3318
|
+
#nativeHistory;
|
|
2333
3319
|
#closed = false;
|
|
2334
|
-
constructor(directory = defaultWorkerDirectory(), sessionId = process.env.PBOT_MCP_SESSION_ID || "mcp-" + randomUUID4(), defaultBackend = process.env.PBOT_HOST || void 0) {
|
|
3320
|
+
constructor(directory = defaultWorkerDirectory(), sessionId = process.env.PBOT_MCP_SESSION_ID || "mcp-" + randomUUID4(), defaultBackend = process.env.PBOT_HOST || void 0, nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""), nativeHistory = /^(1|true)$/i.test(process.env.PBOT_NATIVE_HISTORY ?? "")) {
|
|
2335
3321
|
this.#directory = directory;
|
|
2336
3322
|
this.#sessionId = sessionId;
|
|
2337
3323
|
this.#defaultBackend = defaultBackend?.trim() || void 0;
|
|
3324
|
+
this.#nativeWorkspaceMcp = nativeWorkspaceMcp;
|
|
3325
|
+
this.#nativeHistory = nativeHistory;
|
|
3326
|
+
}
|
|
3327
|
+
get nativeWorkspaceMcp() {
|
|
3328
|
+
return this.#nativeWorkspaceMcp;
|
|
3329
|
+
}
|
|
3330
|
+
get nativeHistory() {
|
|
3331
|
+
return this.#nativeHistory;
|
|
2338
3332
|
}
|
|
2339
3333
|
resolveBackend(rawArgs, commands, allowDefault) {
|
|
2340
3334
|
const raw = asString(rawArgs, "backend") ?? (allowDefault ? this.#defaultBackend : void 0);
|
|
@@ -2371,13 +3365,16 @@ var McpWorkerRuntime = class {
|
|
|
2371
3365
|
}
|
|
2372
3366
|
async toolDefinitions() {
|
|
2373
3367
|
let commands;
|
|
2374
|
-
let includeWorkspaceMcp =
|
|
3368
|
+
let includeWorkspaceMcp = !this.#nativeWorkspaceMcp;
|
|
3369
|
+
let includeHistory = !this.#nativeHistory;
|
|
2375
3370
|
try {
|
|
2376
3371
|
const root = await this.resolveWorkspace();
|
|
2377
3372
|
const configuration = await readWorkspaceConfig(root);
|
|
2378
3373
|
if (configuration.enabled) {
|
|
2379
3374
|
commands = configuration.acp;
|
|
2380
|
-
|
|
3375
|
+
const features = workspaceFeatures(configuration);
|
|
3376
|
+
includeWorkspaceMcp = !this.#nativeWorkspaceMcp && features.mcp;
|
|
3377
|
+
includeHistory = !this.#nativeHistory && features.history;
|
|
2381
3378
|
}
|
|
2382
3379
|
} catch {
|
|
2383
3380
|
}
|
|
@@ -2385,7 +3382,8 @@ var McpWorkerRuntime = class {
|
|
|
2385
3382
|
const workspaceBound = Boolean(process.env.CLAUDE_PROJECT_DIR || process.env.PBOT_WORKSPACE_ROOT);
|
|
2386
3383
|
return [
|
|
2387
3384
|
...buildPbotWorkerTools(commands, defaultBackend, workspaceBound),
|
|
2388
|
-
...includeWorkspaceMcp ? buildWorkspaceMcpTools(workspaceBound) : []
|
|
3385
|
+
...includeWorkspaceMcp ? buildWorkspaceMcpTools(workspaceBound) : [],
|
|
3386
|
+
...includeHistory ? buildHistoryMcpTools(workspaceBound) : []
|
|
2389
3387
|
];
|
|
2390
3388
|
}
|
|
2391
3389
|
/** Wait until ACP handshake and model/thinking configuration finish so invalid options fail synchronously on create/resume. */
|
|
@@ -2427,8 +3425,8 @@ var McpWorkerRuntime = class {
|
|
|
2427
3425
|
const terminalWithoutCycle = !latestRequest && (current.state === "stopped" || current.state === "error" || current.state === "idle" && !targetCycle);
|
|
2428
3426
|
const failedBeforeCycle = Boolean(latestRequest && !targetCycle && (current.state === "stopped" || current.state === "error"));
|
|
2429
3427
|
if (settled) {
|
|
2430
|
-
const
|
|
2431
|
-
return { settled: true, ...presentWorker(
|
|
3428
|
+
const page2 = await service.read(workerId, owner, targetCycle.cycleId, offset, reportPageSize);
|
|
3429
|
+
return { settled: true, ...presentWorker(page2) };
|
|
2432
3430
|
}
|
|
2433
3431
|
if (terminalWithoutCycle || failedBeforeCycle) {
|
|
2434
3432
|
if (offset > 0) await service.read(workerId, owner, void 0, offset, reportPageSize);
|
|
@@ -2463,11 +3461,13 @@ var McpWorkerRuntime = class {
|
|
|
2463
3461
|
const { root, configuration, host, service, owner } = await this.workspace(asString(rawArgs, "workspace"));
|
|
2464
3462
|
switch (name) {
|
|
2465
3463
|
case "workspace_mcp_discover": {
|
|
3464
|
+
requireThat(!this.#nativeWorkspaceMcp, "\u5F53\u524D\u5BBF\u4E3B\u5DF2\u539F\u751F\u6302\u8F7D\u5DE5\u4F5C\u533A .pbot/mcp.json \u670D\u52A1\uFF0C\u8BF7\u76F4\u63A5\u8C03\u7528\u5BF9\u5E94\u539F\u751F MCP \u5DE5\u5177\uFF0C\u52FF\u91CD\u590D\u7ECF\u7531 workspace_mcp_* \u6865\u63A5\u3002");
|
|
2466
3465
|
requireThat(workspaceFeatures(configuration).mcp, `\u5DE5\u4F5C\u533A\u7EDF\u4E00 MCP \u529F\u80FD\u5DF2\u5728 ${configuration.path} \u4E2D\u505C\u7528\uFF08features.mcp: false\uFF09\u3002`);
|
|
2467
3466
|
const server = asString(rawArgs, "server");
|
|
2468
3467
|
return this.#bridge.discover(root, server);
|
|
2469
3468
|
}
|
|
2470
3469
|
case "workspace_mcp_call": {
|
|
3470
|
+
requireThat(!this.#nativeWorkspaceMcp, "\u5F53\u524D\u5BBF\u4E3B\u5DF2\u539F\u751F\u6302\u8F7D\u5DE5\u4F5C\u533A .pbot/mcp.json \u670D\u52A1\uFF0C\u8BF7\u76F4\u63A5\u8C03\u7528\u5BF9\u5E94\u539F\u751F MCP \u5DE5\u5177\uFF0C\u52FF\u91CD\u590D\u7ECF\u7531 workspace_mcp_* \u6865\u63A5\u3002");
|
|
2471
3471
|
requireThat(workspaceFeatures(configuration).mcp, `\u5DE5\u4F5C\u533A\u7EDF\u4E00 MCP \u529F\u80FD\u5DF2\u5728 ${configuration.path} \u4E2D\u505C\u7528\uFF08features.mcp: false\uFF09\u3002`);
|
|
2472
3472
|
const server = asString(rawArgs, "server", true);
|
|
2473
3473
|
const tool = asString(rawArgs, "tool", true);
|
|
@@ -2475,6 +3475,41 @@ var McpWorkerRuntime = class {
|
|
|
2475
3475
|
requireThat(object(toolArgs), "\u53C2\u6570 arguments \u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002");
|
|
2476
3476
|
return this.#bridge.call(root, server, tool, toolArgs);
|
|
2477
3477
|
}
|
|
3478
|
+
case "history_search": {
|
|
3479
|
+
requireThat(!this.#nativeHistory, "\u5F53\u524D\u5BBF\u4E3B\u5DF2\u63D0\u4F9B\u539F\u751F pbot_history \u5DE5\u5177\uFF0C\u8BF7\u76F4\u63A5\u8C03\u7528 pbot_history\u3002");
|
|
3480
|
+
requireThat(workspaceFeatures(configuration).history, `\u5DE5\u4F5C\u533A\u5386\u53F2\u529F\u80FD\u5DF2\u5728 ${configuration.path} \u4E2D\u505C\u7528\uFF08features.history: false\uFF09\u3002`);
|
|
3481
|
+
const hostFilter = asString(rawArgs, "host");
|
|
3482
|
+
if (hostFilter !== void 0) requireThat(isHistoryHost(hostFilter), "\u65E0\u6548\u7684 host \u6765\u6E90\uFF1A" + hostFilter);
|
|
3483
|
+
const dimension = asString(rawArgs, "dimension");
|
|
3484
|
+
if (dimension !== void 0) requireThat(isSummaryDimension(dimension), "\u65E0\u6548\u7684 dimension\uFF1A" + dimension);
|
|
3485
|
+
const query = asString(rawArgs, "query");
|
|
3486
|
+
const sessionId = asString(rawArgs, "sessionId");
|
|
3487
|
+
const from = asString(rawArgs, "from");
|
|
3488
|
+
const to = asString(rawArgs, "to");
|
|
3489
|
+
const offset = asInt(rawArgs, "offset", 0, 1e7) ?? 0;
|
|
3490
|
+
const limit = asInt(rawArgs, "limit", 1, 50) ?? 20;
|
|
3491
|
+
return searchWorkspaceHistory(root, {
|
|
3492
|
+
...hostFilter ? { host: hostFilter } : {},
|
|
3493
|
+
...dimension ? { dimension } : {},
|
|
3494
|
+
...query ? { query } : {},
|
|
3495
|
+
...sessionId ? { sessionId } : {},
|
|
3496
|
+
...from ? { from } : {},
|
|
3497
|
+
...to ? { to } : {},
|
|
3498
|
+
offset,
|
|
3499
|
+
limit
|
|
3500
|
+
});
|
|
3501
|
+
}
|
|
3502
|
+
case "history_read": {
|
|
3503
|
+
requireThat(!this.#nativeHistory, "\u5F53\u524D\u5BBF\u4E3B\u5DF2\u63D0\u4F9B\u539F\u751F pbot_history \u5DE5\u5177\uFF0C\u8BF7\u76F4\u63A5\u8C03\u7528 pbot_history\u3002");
|
|
3504
|
+
requireThat(workspaceFeatures(configuration).history, `\u5DE5\u4F5C\u533A\u5386\u53F2\u529F\u80FD\u5DF2\u5728 ${configuration.path} \u4E2D\u505C\u7528\uFF08features.history: false\uFF09\u3002`);
|
|
3505
|
+
const id = asString(rawArgs, "id", true);
|
|
3506
|
+
const hostFilter = asString(rawArgs, "host");
|
|
3507
|
+
if (hostFilter !== void 0) requireThat(isHistoryHost(hostFilter), "\u65E0\u6548\u7684 host \u6765\u6E90\uFF1A" + hostFilter);
|
|
3508
|
+
const offset = asInt(rawArgs, "offset", 0, 1e7) ?? 0;
|
|
3509
|
+
const limit = asInt(rawArgs, "limit", 1, 24e3) ?? 12e3;
|
|
3510
|
+
const childrenOffset = asInt(rawArgs, "childrenOffset", 0, 1e7) ?? 0;
|
|
3511
|
+
return { node: readWorkspaceHistory(root, id, offset, limit, childrenOffset, hostFilter) };
|
|
3512
|
+
}
|
|
2478
3513
|
case "worker_create": {
|
|
2479
3514
|
const backend = this.resolveBackend(rawArgs, configuration.acp, false);
|
|
2480
3515
|
const model = asString(rawArgs, "model");
|
|
@@ -2612,7 +3647,7 @@ async function handleMcpRequest(runtime, message2, notify) {
|
|
|
2612
3647
|
protocolVersion: requested || protocolVersion2,
|
|
2613
3648
|
capabilities: { tools: {} },
|
|
2614
3649
|
serverInfo: { name: "personal-bot", version: packageVersion },
|
|
2615
|
-
instructions: mcpInstructions
|
|
3650
|
+
instructions: runtime.nativeWorkspaceMcp ? mcpWorkerOnlyInstructions : mcpInstructions
|
|
2616
3651
|
}
|
|
2617
3652
|
};
|
|
2618
3653
|
}
|
|
@@ -2704,7 +3739,7 @@ async function serveMcpStdio(runtime = new McpWorkerRuntime()) {
|
|
|
2704
3739
|
function main() {
|
|
2705
3740
|
return serveMcpStdio();
|
|
2706
3741
|
}
|
|
2707
|
-
if (process.argv[1] && import.meta.url === pathToFileURL2(
|
|
3742
|
+
if (process.argv[1] && import.meta.url === pathToFileURL2(realpathSync5(process.argv[1])).href) {
|
|
2708
3743
|
void main().catch((error) => {
|
|
2709
3744
|
process.stderr.write("Personal Bot MCP: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
2710
3745
|
process.exitCode = 1;
|