personal-bot 0.4.1 → 0.4.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 +4 -1
- package/README.zh-CN.md +4 -1
- package/docs/README.md +2 -3
- package/docs/architecture/design.md +41 -2
- package/docs/architecture/model-context.md +4 -1
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/cross-harness-workers.md +26 -1
- package/docs/guides/workspace-configuration.md +2 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +19 -3
- package/lib/antigravity-plugin/lib/extension/cli.js +136 -61
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +2 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +96 -17
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +20 -2
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +2 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +12 -13
- package/lib/antigravity-plugin/lib/model/worker-template.d.ts +21 -0
- package/lib/antigravity-plugin/lib/model/worker-template.js +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/worker-templates.d.ts +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/worker-templates.js +88 -0
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +1 -1
- package/lib/extension/acp-worker.js +19 -3
- package/lib/extension/cli.js +136 -61
- package/lib/extension/hosts/dsh/workspace.js +2 -1
- package/lib/extension/hosts/plugin-runtime.js +2 -0
- package/lib/extension/mcp/tool-contract.d.ts +3 -3
- package/lib/extension/mcp/tool-contract.js +4 -4
- package/lib/extension/mcp/workers.d.ts +1 -1
- package/lib/extension/mcp/workers.js +15 -7
- package/lib/extension/mcp.js +96 -17
- package/lib/integrations/agent-resources.d.ts +2 -0
- package/lib/integrations/agent-resources.js +20 -2
- package/lib/integrations/hosts/dsh/resources.d.ts +2 -1
- package/lib/integrations/hosts/dsh/resources.js +12 -13
- package/lib/model/worker-template.d.ts +21 -0
- package/lib/model/worker-template.js +1 -0
- package/lib/qoder-plugin/.mcp.json +2 -2
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
- package/lib/qoder-plugin/hooks/hooks.json +3 -3
- package/lib/qoder-plugin/skills/pbot/SKILL.md +1 -1
- package/lib/services/workspace/worker-templates.d.ts +17 -0
- package/lib/services/workspace/worker-templates.js +88 -0
- package/package.json +1 -1
- package/src/extension/hosts/dsh/workspace.ts +2 -1
- package/src/extension/hosts/pi/events.ts +2 -0
- package/src/extension/hosts/plugin-runtime.ts +2 -0
- package/src/extension/mcp/tool-contract.ts +4 -5
- package/src/extension/mcp/workers.ts +17 -8
- package/src/integrations/agent-resources.ts +22 -2
- package/src/integrations/hosts/dsh/resources.ts +13 -12
- package/src/model/worker-template.ts +24 -0
- package/src/services/workspace/worker-templates.ts +80 -0
- package/docs/architecture/model-instruction-guidelines.md +0 -34
|
@@ -6,7 +6,7 @@ import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
|
6
6
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
7
7
|
import { existsSync as existsSync3 } from "node:fs";
|
|
8
8
|
import { realpath as realpath3, stat as stat3 } from "node:fs/promises";
|
|
9
|
-
import { isAbsolute as isAbsolute5, join as
|
|
9
|
+
import { isAbsolute as isAbsolute5, join as join13 } from "node:path";
|
|
10
10
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
11
11
|
|
|
12
12
|
// src/common/json.ts
|
|
@@ -1342,7 +1342,7 @@ var historyPageLimits = {
|
|
|
1342
1342
|
// src/extension/mcp/tool-contract.ts
|
|
1343
1343
|
var defaultWaitMs = 5e4;
|
|
1344
1344
|
var maxWaitMs = 6e5;
|
|
1345
|
-
var discoverTargets = ["overview", "workers", "backends", "models"];
|
|
1345
|
+
var discoverTargets = ["overview", "workers", "backends", "models", "templates"];
|
|
1346
1346
|
function formatBackendItem(entry, defaultBackend) {
|
|
1347
1347
|
const tags = [];
|
|
1348
1348
|
if (entry.label) tags.push(entry.label);
|
|
@@ -1506,9 +1506,9 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1506
1506
|
},
|
|
1507
1507
|
{
|
|
1508
1508
|
name: "worker_discover",
|
|
1509
|
-
description: "\u67E5\u627E\u53EF\
|
|
1509
|
+
description: "\u67E5\u627E\u53EF\u7528\u52A9\u624B\u3001\u6A21\u677F\u6216\u5DF2\u6709\u4F1A\u8BDD\u3002\u67E5\u8BE2\u6A21\u578B\u4F1A\u4E34\u65F6\u542F\u52A8\u6240\u9009\u52A9\u624B\u3002",
|
|
1510
1510
|
annotations: {
|
|
1511
|
-
title: "Discover Workers, Backends & Models",
|
|
1511
|
+
title: "Discover Workers, Templates, Backends & Models",
|
|
1512
1512
|
readOnlyHint: true,
|
|
1513
1513
|
destructiveHint: false,
|
|
1514
1514
|
idempotentHint: true,
|
|
@@ -1522,7 +1522,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1522
1522
|
target: {
|
|
1523
1523
|
type: "string",
|
|
1524
1524
|
enum: [...discoverTargets],
|
|
1525
|
-
description: "overview\uFF08\u9ED8\u8BA4\uFF09\u5217\u52A9\u624B\
|
|
1525
|
+
description: "overview\uFF08\u9ED8\u8BA4\uFF09\u5217\u52A9\u624B\u548C\u672C\u4F1A\u8BDD\u7684 worker\uFF0Cworkers \u67E5\u4F1A\u8BDD\u72B6\u6001\uFF0Cbackends \u67E5\u53EF\u7528\u52A9\u624B\uFF0Cmodels \u67E5\u6A21\u578B\u4E0E\u601D\u8003\u6DF1\u5EA6\u3002templates \u5217\u51FA\u5DE5\u4F5C\u533A\u7684\u52A9\u624B\u6A21\u677F\uFF0C\u9009\u4E2D\u6A21\u677F\u7684 create \u53EF\u76F4\u63A5\u4F20\u7ED9 worker_create\u3002"
|
|
1526
1526
|
},
|
|
1527
1527
|
workerId: {
|
|
1528
1528
|
type: "string",
|
|
@@ -3093,13 +3093,87 @@ ${sessionSummaryText}` : sessionSummaryText : title;
|
|
|
3093
3093
|
};
|
|
3094
3094
|
}
|
|
3095
3095
|
|
|
3096
|
+
// src/services/workspace/worker-templates.ts
|
|
3097
|
+
import { constants as constants3 } from "node:fs";
|
|
3098
|
+
import { open } from "node:fs/promises";
|
|
3099
|
+
import { homedir } from "node:os";
|
|
3100
|
+
import { join as join11, resolve as resolve8 } from "node:path";
|
|
3101
|
+
var templateIdPattern = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
3102
|
+
var templateFields = ["name", "description", "create"];
|
|
3103
|
+
var createFields = ["backend", "workspace", "model", "thinking"];
|
|
3104
|
+
function validString(value) {
|
|
3105
|
+
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
3106
|
+
}
|
|
3107
|
+
function parseTemplate(id, entry) {
|
|
3108
|
+
if (!templateIdPattern.test(id)) return { id, message: "\u6A21\u677F\u6807\u8BC6\u65E0\u6548\u3002" };
|
|
3109
|
+
if (!object(entry) || Object.keys(entry).some((key) => !templateFields.includes(key))) {
|
|
3110
|
+
return { id, message: "\u6A21\u677F\u8BBE\u7F6E\u65E0\u6548\u3002" };
|
|
3111
|
+
}
|
|
3112
|
+
const { name = id, description, create } = entry;
|
|
3113
|
+
if (!validString(name)) return { id, message: "\u6A21\u677F\u540D\u79F0\u65E0\u6548\u3002" };
|
|
3114
|
+
if (!validString(description)) return { id, message: "\u6A21\u677F\u7F3A\u5C11\u6709\u6548\u7684\u804C\u8D23\u8BF4\u660E\u3002" };
|
|
3115
|
+
if (!object(create) || Object.keys(create).some((key) => !createFields.includes(key))) {
|
|
3116
|
+
return { id, message: "\u52A9\u624B\u7684\u542F\u52A8\u8BBE\u7F6E\u65E0\u6548\u3002" };
|
|
3117
|
+
}
|
|
3118
|
+
if (!validString(create.backend)) return { id, message: "\u6A21\u677F\u7F3A\u5C11\u6709\u6548\u7684\u52A9\u624B\u6807\u8BC6\u3002" };
|
|
3119
|
+
const options = { backend: create.backend, workspace: "." };
|
|
3120
|
+
for (const key of ["workspace", "model", "thinking"]) {
|
|
3121
|
+
const value = create[key];
|
|
3122
|
+
if (value === void 0) continue;
|
|
3123
|
+
if (!validString(value)) return { id, message: "\u52A9\u624B\u7684\u542F\u52A8\u8BBE\u7F6E\u65E0\u6548\u3002" };
|
|
3124
|
+
options[key] = value;
|
|
3125
|
+
}
|
|
3126
|
+
return { id, name, description, create: options };
|
|
3127
|
+
}
|
|
3128
|
+
async function readWorkerTemplates(root) {
|
|
3129
|
+
const path = join11(root, ".pbot", "worker", "templates.json");
|
|
3130
|
+
const catalog = { templates: [], errors: [] };
|
|
3131
|
+
const unavailable = { ...catalog, error: "\u5F53\u524D\u5DE5\u4F5C\u533A\u7684\u52A9\u624B\u6A21\u677F\u4E0D\u53EF\u7528\u3002" };
|
|
3132
|
+
let entries;
|
|
3133
|
+
try {
|
|
3134
|
+
const file = await open(path, constants3.O_RDONLY | constants3.O_NONBLOCK);
|
|
3135
|
+
try {
|
|
3136
|
+
if (!(await file.stat()).isFile()) return unavailable;
|
|
3137
|
+
entries = JSON.parse(await file.readFile("utf8"));
|
|
3138
|
+
} finally {
|
|
3139
|
+
await file.close();
|
|
3140
|
+
}
|
|
3141
|
+
} catch (error) {
|
|
3142
|
+
if (error.code === "ENOENT") return catalog;
|
|
3143
|
+
return unavailable;
|
|
3144
|
+
}
|
|
3145
|
+
if (!object(entries)) return unavailable;
|
|
3146
|
+
for (const id of Object.keys(entries).sort()) {
|
|
3147
|
+
const result = parseTemplate(id, entries[id]);
|
|
3148
|
+
if ("message" in result) catalog.errors.push(result);
|
|
3149
|
+
else catalog.templates.push(result);
|
|
3150
|
+
}
|
|
3151
|
+
return catalog;
|
|
3152
|
+
}
|
|
3153
|
+
function resolveTemplateWorkspace(root, workspace) {
|
|
3154
|
+
if (workspace === "~" || workspace.startsWith("~/")) return join11(homedir(), workspace.slice(2));
|
|
3155
|
+
return resolve8(root, workspace);
|
|
3156
|
+
}
|
|
3157
|
+
async function discoverWorkerTemplates(root) {
|
|
3158
|
+
const { templates, errors, error } = await readWorkerTemplates(root);
|
|
3159
|
+
if (error) throw new Error(error);
|
|
3160
|
+
return {
|
|
3161
|
+
target: "templates",
|
|
3162
|
+
templates: templates.map((template) => ({
|
|
3163
|
+
...template,
|
|
3164
|
+
create: { ...template.create, workspace: resolveTemplateWorkspace(root, template.create.workspace) }
|
|
3165
|
+
})),
|
|
3166
|
+
...errors.length ? { errors } : {}
|
|
3167
|
+
};
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3096
3170
|
// src/extension/mcp/bridge.ts
|
|
3097
3171
|
import { spawn } from "node:child_process";
|
|
3098
3172
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
3099
3173
|
|
|
3100
3174
|
// src/services/workspace/workspace-mcp.ts
|
|
3101
3175
|
import { mkdir as mkdir2, readFile as readFile3 } from "node:fs/promises";
|
|
3102
|
-
import { dirname as dirname5, join as
|
|
3176
|
+
import { dirname as dirname5, join as join12, resolve as resolve9 } from "node:path";
|
|
3103
3177
|
var serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
|
|
3104
3178
|
var reservedServerNames = /* @__PURE__ */ new Set(["pbot"]);
|
|
3105
3179
|
var stdioKeys = /* @__PURE__ */ new Set(["command", "args", "env", "cwd", "description", "timeout", "enabled"]);
|
|
@@ -3209,7 +3283,7 @@ function validateMcpFile(value) {
|
|
|
3209
3283
|
return { ...value, mcpServers: servers };
|
|
3210
3284
|
}
|
|
3211
3285
|
function workspaceMcpPath(root) {
|
|
3212
|
-
return
|
|
3286
|
+
return join12(root, ".pbot", "mcp.json");
|
|
3213
3287
|
}
|
|
3214
3288
|
async function readWorkspaceMcpConfig(root) {
|
|
3215
3289
|
const path = workspaceMcpPath(root);
|
|
@@ -3253,7 +3327,7 @@ function resolveWorkspaceMcpServer(root, name, server, env = process.env) {
|
|
|
3253
3327
|
}
|
|
3254
3328
|
const command = expandEnvTemplate(server.command, env, `MCP \u670D\u52A1 "${name}" \u7684 command`);
|
|
3255
3329
|
const args = (server.args ?? []).map((arg, index) => expandEnvTemplate(arg, env, `MCP \u670D\u52A1 "${name}" \u7684 args[${index}]`));
|
|
3256
|
-
const cwd = server.cwd ?
|
|
3330
|
+
const cwd = server.cwd ? resolve9(root, expandEnvTemplate(server.cwd, env, `MCP \u670D\u52A1 "${name}" \u7684 cwd`)) : root;
|
|
3257
3331
|
return {
|
|
3258
3332
|
transport: "stdio",
|
|
3259
3333
|
name,
|
|
@@ -3627,7 +3701,7 @@ var protocolVersion2 = "2025-03-26";
|
|
|
3627
3701
|
var readyTimeoutMs = 45e3;
|
|
3628
3702
|
var reportPageSize = 16e3;
|
|
3629
3703
|
var progressIntervalMs = 5e3;
|
|
3630
|
-
var workerCapabilityInstruction = "\
|
|
3704
|
+
var workerCapabilityInstruction = "\u53EF\u67E5\u8BE2\u5DE5\u4F5C\u533A\u7684\u52A9\u624B\u6A21\u677F\uFF0C\u4E5F\u53EF\u6309\u7528\u6237\u8981\u6C42\u6216\u5DE5\u4F5C\u533A\u5206\u5DE5\u59D4\u6D3E\u7ED9\u6307\u5B9A\u52A9\u624B\u6216\u6A21\u578B\u3002\u5E38\u89C4\u4EFB\u52A1\u4F18\u5148\u81EA\u884C\u5904\u7406\u6216\u4F7F\u7528\u5BBF\u4E3B\u5185\u7F6E\u5B50\u4EE3\u7406\u3002";
|
|
3631
3705
|
var workspaceMcpCapabilityInstruction = "\u53EF\u8C03\u7528\u672C\u5DE5\u4F5C\u533A .pbot/mcp.json \u4E2D\u767B\u8BB0\u7684 MCP \u5DE5\u5177\u3002";
|
|
3632
3706
|
var historyCapabilityInstruction = "\u53EF\u68C0\u7D22\u672C\u5DE5\u4F5C\u533A\u5404\u5BBF\u4E3B\u5F52\u6863\u7684\u95EE\u7B54\u548C\u6458\u8981\u3002";
|
|
3633
3707
|
function buildMcpInstructions(options) {
|
|
@@ -3640,7 +3714,7 @@ var mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, hist
|
|
|
3640
3714
|
var mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
|
|
3641
3715
|
function defaultWorkerDirectory(workspaceRoot) {
|
|
3642
3716
|
if (process.env.PBOT_MCP_AGENT_DIR) return process.env.PBOT_MCP_AGENT_DIR;
|
|
3643
|
-
return
|
|
3717
|
+
return join13(workspaceRoot, ".pbot", "worker", "runtime");
|
|
3644
3718
|
}
|
|
3645
3719
|
function asString(args, key, required = false) {
|
|
3646
3720
|
const value = args[key];
|
|
@@ -3716,7 +3790,7 @@ var McpWorkerRuntime = class {
|
|
|
3716
3790
|
}
|
|
3717
3791
|
/** Mount the stdio sibling with the same worker ownership as the native host command. */
|
|
3718
3792
|
nativeServer(root) {
|
|
3719
|
-
const entry =
|
|
3793
|
+
const entry = join13(resourceRoot, "../lib/extension/mcp.js");
|
|
3720
3794
|
if (!existsSync3(entry)) return void 0;
|
|
3721
3795
|
requireThat(this.#defaultBackend, "\u539F\u751F MCP \u6302\u8F7D\u9700\u8981\u5BBF\u4E3B\u540D\u79F0\u3002");
|
|
3722
3796
|
return {
|
|
@@ -3876,10 +3950,11 @@ var McpWorkerRuntime = class {
|
|
|
3876
3950
|
const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
|
|
3877
3951
|
requireThat(!this.#closing, "Personal Bot MCP \u670D\u52A1\u5DF2\u5173\u95ED\u3002");
|
|
3878
3952
|
const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
|
|
3879
|
-
const
|
|
3953
|
+
const isTemplateQuery = name === "worker_discover" && rawArgs.target === "templates";
|
|
3954
|
+
const root = isWorkerScoped ? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true), defaultWorkspace) : await this.resolveWorkspace(asString(rawArgs, "workspace", isTemplateQuery && rawArgs.workspace !== void 0) ?? defaultWorkspace);
|
|
3880
3955
|
const configuration = await readWorkspaceConfig(root);
|
|
3881
3956
|
requireThat(!this.#closing, "Personal Bot MCP \u670D\u52A1\u5DF2\u5173\u95ED\u3002");
|
|
3882
|
-
requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
|
|
3957
|
+
requireThat(configuration.enabled, isTemplateQuery ? `\u65E0\u6CD5\u5728\u5DE5\u4F5C\u533A ${root} \u67E5\u8BE2\u52A9\u624B\u6A21\u677F\u3002` : workspaceDisabledMessage(configuration));
|
|
3883
3958
|
switch (name) {
|
|
3884
3959
|
case "workspace_mcp_discover":
|
|
3885
3960
|
case "workspace_mcp_call": {
|
|
@@ -3928,6 +4003,11 @@ var McpWorkerRuntime = class {
|
|
|
3928
4003
|
return { node: readWorkspaceHistory(root, id, offset, limit, childrenOffset, hostFilter) };
|
|
3929
4004
|
}
|
|
3930
4005
|
}
|
|
4006
|
+
if (isTemplateQuery) {
|
|
4007
|
+
const extra = Object.keys(rawArgs).find((key) => key !== "target" && key !== "workspace");
|
|
4008
|
+
requireThat(extra === void 0, `\u67E5\u8BE2\u6A21\u677F\u53EA\u63A5\u53D7 target \u548C workspace\uFF0C\u6536\u5230\u53C2\u6570 ${extra}\u3002`);
|
|
4009
|
+
return discoverWorkerTemplates(root);
|
|
4010
|
+
}
|
|
3931
4011
|
const { host, service, owner } = this.workerService(root, configuration.acp);
|
|
3932
4012
|
switch (name) {
|
|
3933
4013
|
case "worker_create": {
|
|
@@ -3998,12 +4078,11 @@ var McpWorkerRuntime = class {
|
|
|
3998
4078
|
return this.waitFor(service, owner, workerId, void 0, waitMs, offset, progress);
|
|
3999
4079
|
}
|
|
4000
4080
|
case "worker_discover": {
|
|
4001
|
-
const
|
|
4081
|
+
const target = asString(rawArgs, "target") ?? "overview";
|
|
4002
4082
|
requireThat(
|
|
4003
|
-
isOneOf(
|
|
4004
|
-
`\u53C2\u6570 target \u65E0\u6548\uFF1A${
|
|
4083
|
+
isOneOf(target, discoverTargets),
|
|
4084
|
+
`\u53C2\u6570 target \u65E0\u6548\uFF1A${target}\uFF08\u53EF\u7528\uFF1A${discoverTargets.join(", ")}\uFF09\u3002`
|
|
4005
4085
|
);
|
|
4006
|
-
const target = rawTarget;
|
|
4007
4086
|
const workerId = asString(rawArgs, "workerId");
|
|
4008
4087
|
const backendRaw = asString(rawArgs, "backend");
|
|
4009
4088
|
const model = asString(rawArgs, "model");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HostId, WorkspaceContext, WorkspaceRole } from "../model/plugin-host.js";
|
|
2
|
+
import type { ReadWorkerTemplates } from "../model/worker-template.js";
|
|
2
3
|
import type { WorkspaceSkillMeta } from "../model/workspace-mcp.js";
|
|
3
4
|
export declare function readOptionalFile(path: string): Promise<string>;
|
|
4
5
|
export declare function readLocalRole(agent: WorkspaceRole, root: string): Promise<string>;
|
|
@@ -12,6 +13,7 @@ export declare function loadWorkspaceContext(options: {
|
|
|
12
13
|
includePrompts?: boolean;
|
|
13
14
|
includeRootAgents?: boolean;
|
|
14
15
|
localRoleOnly?: boolean;
|
|
16
|
+
readWorkerTemplates?: ReadWorkerTemplates;
|
|
15
17
|
workspaceSkills?: readonly WorkspaceSkillMeta[];
|
|
16
18
|
notices?: readonly string[];
|
|
17
19
|
}): Promise<WorkspaceContext>;
|
|
@@ -34,15 +34,33 @@ export function formatWorkspaceSkills(skills) {
|
|
|
34
34
|
const lines = skills.map(skill => `- **${skill.name}**(\`${skill.path}\`):${skill.description}`);
|
|
35
35
|
return "## 按需读取的技能\n\n" + lines.join("\n");
|
|
36
36
|
}
|
|
37
|
+
function formatWorkerTemplates(templates) {
|
|
38
|
+
if (!templates.length)
|
|
39
|
+
return "";
|
|
40
|
+
const lines = templates.map(({ id, name, description, create }) => {
|
|
41
|
+
const label = name === id ? id : `${name}(${id})`;
|
|
42
|
+
const settings = [
|
|
43
|
+
["助手", create.backend],
|
|
44
|
+
["执行工作区", create.workspace],
|
|
45
|
+
["模型", create.model],
|
|
46
|
+
["思考深度", create.thinking],
|
|
47
|
+
].filter(([, value]) => value !== undefined)
|
|
48
|
+
.map(([field, value]) => `${field} ${JSON.stringify(value)}`).join(",");
|
|
49
|
+
return `- ${label} ${description}(${settings})`;
|
|
50
|
+
});
|
|
51
|
+
return "## 工作区助手模板\n\n选用模板时,用 worker_discover 查询最新设置(target=templates)。\n\n" + lines.join("\n");
|
|
52
|
+
}
|
|
37
53
|
export async function loadWorkspaceContext(options) {
|
|
38
54
|
const { host, root, role, coordinatorPrompt, includePrompts = true, includeRootAgents = false, localRoleOnly = false, workspaceSkills = [], notices = [], } = options;
|
|
39
|
-
const [workspace,
|
|
55
|
+
const [workspace, baseRole, rootAgents, catalog] = includePrompts
|
|
40
56
|
? await Promise.all([
|
|
41
57
|
readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"),
|
|
42
58
|
localRoleOnly ? readLocalRole(role, root) : agentText(role, root, coordinatorPrompt),
|
|
43
59
|
includeRootAgents ? readOptionalFile(join(root, "AGENTS.md")) : Promise.resolve(""),
|
|
60
|
+
role === "coordinator" ? options.readWorkerTemplates?.(root) : undefined,
|
|
44
61
|
])
|
|
45
|
-
: ["", "", ""];
|
|
62
|
+
: ["", "", "", undefined];
|
|
63
|
+
const roleText = [baseRole, formatWorkerTemplates(catalog?.templates ?? [])].filter(Boolean).join("\n\n");
|
|
46
64
|
const skillsSection = formatWorkspaceSkills(workspaceSkills);
|
|
47
65
|
const noticesSection = notices.length
|
|
48
66
|
? "## 维护提醒\n\n告知用户,按用户要求执行。\n\n" + notices.map(item => `- ${item}`).join("\n")
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import type { AgentOptions } from "../../../model/agent.js";
|
|
4
|
-
|
|
4
|
+
import type { ReadWorkerTemplates } from "../../../model/worker-template.js";
|
|
5
|
+
export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose", check: () => void, coordinatorPrompt?: string | null, readWorkerTemplates?: ReadWorkerTemplates): Promise<void>;
|
|
5
6
|
/** Map an ACP dsh worker's native loadout without interfering with coordinator sessions. */
|
|
6
7
|
export declare function dshExpertTools(ctx: Context, agent: Agent, options: AgentOptions): void;
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { agentText } from "../../agent-resources.js";
|
|
4
|
-
import { resourceRoot } from "../../../common/paths.js";
|
|
1
|
+
import { loadWorkspaceContext } from "../../agent-resources.js";
|
|
5
2
|
import { requireThat } from "../../../common/validation.js";
|
|
6
3
|
import { isMcpWorkerTool } from "../../../model/acp.js";
|
|
7
|
-
export async function dshResources(ctx, _agent, root, role, check, coordinatorPrompt = "history-coordinator.md") {
|
|
8
|
-
const read = () =>
|
|
9
|
-
|
|
4
|
+
export async function dshResources(ctx, _agent, root, role, check, coordinatorPrompt = "history-coordinator.md", readWorkerTemplates) {
|
|
5
|
+
const read = () => loadWorkspaceContext({
|
|
6
|
+
host: "dsh", root, role, coordinatorPrompt, ...(readWorkerTemplates ? { readWorkerTemplates } : {}),
|
|
7
|
+
});
|
|
8
|
+
const context = await read();
|
|
10
9
|
check();
|
|
11
|
-
ctx.systemPrompt.section({ name: "pbot:role", order: 1, text, interpolate: false });
|
|
12
|
-
ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: workspace, interpolate: false });
|
|
10
|
+
ctx.systemPrompt.section({ name: "pbot:role", order: 1, text: context.role, interpolate: false });
|
|
11
|
+
ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: context.workspace, interpolate: false });
|
|
13
12
|
ctx.systemPrompt.context({
|
|
14
13
|
name: "pbot:environment", order: 300, required: true, interpolate: false,
|
|
15
|
-
text: JSON.stringify(
|
|
14
|
+
text: JSON.stringify(context.environment),
|
|
16
15
|
});
|
|
17
16
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
18
17
|
check();
|
|
19
|
-
const
|
|
18
|
+
const current = await read();
|
|
20
19
|
check();
|
|
21
20
|
const assembly = await next();
|
|
22
21
|
return {
|
|
23
22
|
...assembly,
|
|
24
|
-
sections: assembly.sections.map(section => section.name === "pbot:role" ? { ...section, text:
|
|
25
|
-
: section.name === "pbot:workspace" ? { ...section, text:
|
|
23
|
+
sections: assembly.sections.map(section => section.name === "pbot:role" ? { ...section, text: current.role }
|
|
24
|
+
: section.name === "pbot:workspace" ? { ...section, text: current.workspace } : section),
|
|
26
25
|
};
|
|
27
26
|
});
|
|
28
27
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface WorkerTemplate {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
create: {
|
|
6
|
+
backend: string;
|
|
7
|
+
workspace: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
thinking?: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface WorkerTemplateError {
|
|
13
|
+
id: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
export interface WorkerTemplateCatalog {
|
|
17
|
+
templates: WorkerTemplate[];
|
|
18
|
+
errors: WorkerTemplateError[];
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
export type ReadWorkerTemplates = (root: string) => Promise<WorkerTemplateCatalog>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WorkerTemplateCatalog, WorkerTemplateError } from "../../model/worker-template.js";
|
|
2
|
+
export declare function readWorkerTemplates(root: string): Promise<WorkerTemplateCatalog>;
|
|
3
|
+
export declare function discoverWorkerTemplates(root: string): Promise<{
|
|
4
|
+
errors?: WorkerTemplateError[];
|
|
5
|
+
target: string;
|
|
6
|
+
templates: {
|
|
7
|
+
create: {
|
|
8
|
+
workspace: string;
|
|
9
|
+
backend: string;
|
|
10
|
+
model?: string;
|
|
11
|
+
thinking?: string;
|
|
12
|
+
};
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}[];
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { open } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { object } from "../../common/json.js";
|
|
6
|
+
const templateIdPattern = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
7
|
+
const templateFields = ["name", "description", "create"];
|
|
8
|
+
const createFields = ["backend", "workspace", "model", "thinking"];
|
|
9
|
+
function validString(value) {
|
|
10
|
+
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
11
|
+
}
|
|
12
|
+
function parseTemplate(id, entry) {
|
|
13
|
+
if (!templateIdPattern.test(id))
|
|
14
|
+
return { id, message: "模板标识无效。" };
|
|
15
|
+
if (!object(entry) || Object.keys(entry).some(key => !templateFields.includes(key))) {
|
|
16
|
+
return { id, message: "模板设置无效。" };
|
|
17
|
+
}
|
|
18
|
+
const { name = id, description, create } = entry;
|
|
19
|
+
if (!validString(name))
|
|
20
|
+
return { id, message: "模板名称无效。" };
|
|
21
|
+
if (!validString(description))
|
|
22
|
+
return { id, message: "模板缺少有效的职责说明。" };
|
|
23
|
+
if (!object(create) || Object.keys(create).some(key => !createFields.includes(key))) {
|
|
24
|
+
return { id, message: "助手的启动设置无效。" };
|
|
25
|
+
}
|
|
26
|
+
if (!validString(create.backend))
|
|
27
|
+
return { id, message: "模板缺少有效的助手标识。" };
|
|
28
|
+
const options = { backend: create.backend, workspace: "." };
|
|
29
|
+
for (const key of ["workspace", "model", "thinking"]) {
|
|
30
|
+
const value = create[key];
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
continue;
|
|
33
|
+
if (!validString(value))
|
|
34
|
+
return { id, message: "助手的启动设置无效。" };
|
|
35
|
+
options[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return { id, name, description, create: options };
|
|
38
|
+
}
|
|
39
|
+
export async function readWorkerTemplates(root) {
|
|
40
|
+
const path = join(root, ".pbot", "worker", "templates.json");
|
|
41
|
+
const catalog = { templates: [], errors: [] };
|
|
42
|
+
const unavailable = { ...catalog, error: "当前工作区的助手模板不可用。" };
|
|
43
|
+
let entries;
|
|
44
|
+
try {
|
|
45
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
46
|
+
try {
|
|
47
|
+
if (!(await file.stat()).isFile())
|
|
48
|
+
return unavailable;
|
|
49
|
+
entries = JSON.parse(await file.readFile("utf8"));
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
await file.close();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === "ENOENT")
|
|
57
|
+
return catalog;
|
|
58
|
+
return unavailable;
|
|
59
|
+
}
|
|
60
|
+
if (!object(entries))
|
|
61
|
+
return unavailable;
|
|
62
|
+
for (const id of Object.keys(entries).sort()) {
|
|
63
|
+
const result = parseTemplate(id, entries[id]);
|
|
64
|
+
if ("message" in result)
|
|
65
|
+
catalog.errors.push(result);
|
|
66
|
+
else
|
|
67
|
+
catalog.templates.push(result);
|
|
68
|
+
}
|
|
69
|
+
return catalog;
|
|
70
|
+
}
|
|
71
|
+
function resolveTemplateWorkspace(root, workspace) {
|
|
72
|
+
if (workspace === "~" || workspace.startsWith("~/"))
|
|
73
|
+
return join(homedir(), workspace.slice(2));
|
|
74
|
+
return resolve(root, workspace);
|
|
75
|
+
}
|
|
76
|
+
export async function discoverWorkerTemplates(root) {
|
|
77
|
+
const { templates, errors, error } = await readWorkerTemplates(root);
|
|
78
|
+
if (error)
|
|
79
|
+
throw new Error(error);
|
|
80
|
+
return {
|
|
81
|
+
target: "templates",
|
|
82
|
+
templates: templates.map(template => ({
|
|
83
|
+
...template,
|
|
84
|
+
create: { ...template.create, workspace: resolveTemplateWorkspace(root, template.create.workspace) },
|
|
85
|
+
})),
|
|
86
|
+
...(errors.length ? { errors } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "personal-bot",
|
|
3
3
|
"displayName": "Personal Bot",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"description": "Organize workspace files, search past conversations, use shared MCP tools, and delegate tasks to other assistants.",
|
|
6
6
|
"repository": "https://github.com/realqiyan/personal-bot"
|
|
7
7
|
}
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
"command": "sh",
|
|
5
5
|
"args": [
|
|
6
6
|
"-c",
|
|
7
|
-
"if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.
|
|
7
|
+
"if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.2 \"$@\"",
|
|
8
8
|
"pbot",
|
|
9
9
|
"mcp"
|
|
10
10
|
],
|
|
11
11
|
"env": {
|
|
12
12
|
"PBOT_HOST": "codex",
|
|
13
|
-
"PBOT_PLUGIN_VERSION": "0.4.
|
|
13
|
+
"PBOT_PLUGIN_VERSION": "0.4.2"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"hooks": [
|
|
6
6
|
{
|
|
7
7
|
"type": "command",
|
|
8
|
-
"command": "PBOT_PLUGIN_VERSION=0.4.
|
|
8
|
+
"command": "PBOT_PLUGIN_VERSION=0.4.2 sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.2 \"$@\"' pbot plugin codex hook",
|
|
9
9
|
"timeout": 120
|
|
10
10
|
}
|
|
11
11
|
]
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"hooks": [
|
|
17
17
|
{
|
|
18
18
|
"type": "command",
|
|
19
|
-
"command": "PBOT_PLUGIN_VERSION=0.4.
|
|
19
|
+
"command": "PBOT_PLUGIN_VERSION=0.4.2 sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.2 \"$@\"' pbot plugin codex hook",
|
|
20
20
|
"timeout": 120
|
|
21
21
|
}
|
|
22
22
|
]
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"hooks": [
|
|
28
28
|
{
|
|
29
29
|
"type": "command",
|
|
30
|
-
"command": "PBOT_PLUGIN_VERSION=0.4.
|
|
30
|
+
"command": "PBOT_PLUGIN_VERSION=0.4.2 sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.4.2 \"$@\"' pbot plugin codex hook",
|
|
31
31
|
"timeout": 120
|
|
32
32
|
}
|
|
33
33
|
]
|
|
@@ -12,6 +12,6 @@ disable-model-invocation: true
|
|
|
12
12
|
node "<resourceRoot>/../lib/extension/cli.js" status --workspace "<workspaceRoot>"
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
没有该路径时,若 `pbot --at-least 0.4.
|
|
15
|
+
没有该路径时,若 `pbot --at-least 0.4.2` 成功,用 `pbot` 替换上例的 `node ".../cli.js"`,否则用 `npx --yes --ignore-scripts personal-bot@0.4.2`。
|
|
16
16
|
|
|
17
17
|
历史操作将 `status` 替换为 `history` 和用户指定的子命令、参数。`history summary` 更新各维度,`history summary monthly` 汇总已有会话摘要。迁移预览用 `history migrate --dry-run`,其他用法见 `history --help`。
|
|
@@ -11171,6 +11171,20 @@ function formatWorkspaceSkills(skills) {
|
|
|
11171
11171
|
const lines = skills.map((skill) => `- **${skill.name}**\uFF08\`${skill.path}\`\uFF09\uFF1A${skill.description}`);
|
|
11172
11172
|
return "## \u6309\u9700\u8BFB\u53D6\u7684\u6280\u80FD\n\n" + lines.join("\n");
|
|
11173
11173
|
}
|
|
11174
|
+
function formatWorkerTemplates(templates) {
|
|
11175
|
+
if (!templates.length) return "";
|
|
11176
|
+
const lines = templates.map(({ id, name, description, create }) => {
|
|
11177
|
+
const label = name === id ? id : `${name}\uFF08${id}\uFF09`;
|
|
11178
|
+
const settings = [
|
|
11179
|
+
["\u52A9\u624B", create.backend],
|
|
11180
|
+
["\u6267\u884C\u5DE5\u4F5C\u533A", create.workspace],
|
|
11181
|
+
["\u6A21\u578B", create.model],
|
|
11182
|
+
["\u601D\u8003\u6DF1\u5EA6", create.thinking]
|
|
11183
|
+
].filter(([, value]) => value !== void 0).map(([field, value]) => `${field} ${JSON.stringify(value)}`).join("\uFF0C");
|
|
11184
|
+
return `- ${label}\u3000${description}\uFF08${settings}\uFF09`;
|
|
11185
|
+
});
|
|
11186
|
+
return "## \u5DE5\u4F5C\u533A\u52A9\u624B\u6A21\u677F\n\n\u9009\u7528\u6A21\u677F\u65F6\uFF0C\u7528 worker_discover \u67E5\u8BE2\u6700\u65B0\u8BBE\u7F6E\uFF08target=templates\uFF09\u3002\n\n" + lines.join("\n");
|
|
11187
|
+
}
|
|
11174
11188
|
async function loadWorkspaceContext(options) {
|
|
11175
11189
|
const {
|
|
11176
11190
|
host,
|
|
@@ -11183,11 +11197,13 @@ async function loadWorkspaceContext(options) {
|
|
|
11183
11197
|
workspaceSkills = [],
|
|
11184
11198
|
notices = []
|
|
11185
11199
|
} = options;
|
|
11186
|
-
const [workspace,
|
|
11200
|
+
const [workspace, baseRole, rootAgents, catalog] = includePrompts ? await Promise.all([
|
|
11187
11201
|
readFile(join7(resourceRoot, "prompts/workspace.md"), "utf8"),
|
|
11188
11202
|
localRoleOnly ? readLocalRole(role, root) : agentText(role, root, coordinatorPrompt),
|
|
11189
|
-
includeRootAgents ? readOptionalFile(join7(root, "AGENTS.md")) : Promise.resolve("")
|
|
11190
|
-
|
|
11203
|
+
includeRootAgents ? readOptionalFile(join7(root, "AGENTS.md")) : Promise.resolve(""),
|
|
11204
|
+
role === "coordinator" ? options.readWorkerTemplates?.(root) : void 0
|
|
11205
|
+
]) : ["", "", "", void 0];
|
|
11206
|
+
const roleText = [baseRole, formatWorkerTemplates(catalog?.templates ?? [])].filter(Boolean).join("\n\n");
|
|
11191
11207
|
const skillsSection = formatWorkspaceSkills(workspaceSkills);
|
|
11192
11208
|
const noticesSection = notices.length ? "## \u7EF4\u62A4\u63D0\u9192\n\n\u544A\u77E5\u7528\u6237\uFF0C\u6309\u7528\u6237\u8981\u6C42\u6267\u884C\u3002\n\n" + notices.map((item) => `- ${item}`).join("\n") : "";
|
|
11193
11209
|
const environment = { host, workspaceRoot: root, resourceRoot };
|