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
|
@@ -4,8 +4,9 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// src/extension/acp
|
|
8
|
-
import {
|
|
7
|
+
// src/extension/acp/worker.ts
|
|
8
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
9
|
+
import { dirname as dirname4, join as join11, resolve as resolve5 } from "node:path";
|
|
9
10
|
|
|
10
11
|
// src/storage/agent-files.ts
|
|
11
12
|
import { existsSync, mkdirSync as mkdirSync2, readdirSync, rmSync } from "node:fs";
|
|
@@ -10335,7 +10336,7 @@ requireThat(object(manifest) && typeof manifest.version === "string", "pbot \u53
|
|
|
10335
10336
|
var packageVersion = manifest.version;
|
|
10336
10337
|
releaseLine(packageVersion);
|
|
10337
10338
|
|
|
10338
|
-
// src/integrations/acp/claude.ts
|
|
10339
|
+
// src/integrations/acp/claude-settings.ts
|
|
10339
10340
|
import { createRequire } from "node:module";
|
|
10340
10341
|
import { pathToFileURL } from "node:url";
|
|
10341
10342
|
import { basename, join as join4, resolve } from "node:path";
|
|
@@ -10344,7 +10345,7 @@ import { basename, join as join4, resolve } from "node:path";
|
|
|
10344
10345
|
import { fileURLToPath } from "node:url";
|
|
10345
10346
|
var resourceRoot = fileURLToPath(new URL("../../resources/", import.meta.url));
|
|
10346
10347
|
|
|
10347
|
-
// src/integrations/acp/claude.ts
|
|
10348
|
+
// src/integrations/acp/claude-settings.ts
|
|
10348
10349
|
var levels = ["low", "medium", "high", "xhigh", "max"];
|
|
10349
10350
|
async function claudeOptions(command, cwd, supplied, includeSkills = true) {
|
|
10350
10351
|
const normalized = supplied?.trim().toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
@@ -10476,7 +10477,7 @@ var dshAcpHarness = {
|
|
|
10476
10477
|
const patch = join5(context.directory, "acp-dsh-patch.json");
|
|
10477
10478
|
await writeFile(
|
|
10478
10479
|
patch,
|
|
10479
|
-
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join5(context.packageRoot, "lib/extension/dsh/acp-member.js") }] }]) + "\n",
|
|
10480
|
+
JSON.stringify([{ insert: [{ id: "pbot-acp-member", name: join5(context.packageRoot, "lib/extension/hosts/dsh/acp-member.js") }] }]) + "\n",
|
|
10480
10481
|
{ mode: 384 }
|
|
10481
10482
|
);
|
|
10482
10483
|
return {
|
|
@@ -10866,10 +10867,14 @@ async function openAcp(reference, cwd, env, callbacks, signal, openOptions = {})
|
|
|
10866
10867
|
systemPrompt: { mode: "append", content: [{ type: "text", text: openOptions.systemPrompt }] }
|
|
10867
10868
|
} : {}
|
|
10868
10869
|
};
|
|
10870
|
+
let startupInfo;
|
|
10869
10871
|
if (reference.sessionId === null) {
|
|
10870
10872
|
const created = await connection.agent.request(methods.agent.session.new, setup, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(3e4)]), stopWaitingOnCancel: true });
|
|
10871
10873
|
sessionId = created.sessionId;
|
|
10872
10874
|
options = created.configOptions ?? [];
|
|
10875
|
+
if (object(created._meta) && object(created._meta.piAcp) && typeof created._meta.piAcp.startupInfo === "string") {
|
|
10876
|
+
startupInfo = created._meta.piAcp.startupInfo;
|
|
10877
|
+
}
|
|
10873
10878
|
} else {
|
|
10874
10879
|
requireThat(capabilities.resume || capabilities.load, "\u76EE\u6807 ACP \u540E\u7AEF\u4E0D\u652F\u6301\u6062\u590D\u5DF2\u6709\u4F1A\u8BDD\uFF0C\u8BF7\u65B0\u5EFA worker\u3002");
|
|
10875
10880
|
const restored = capabilities.resume ? await connection.agent.request(methods.agent.session.resume, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(3e4)]), stopWaitingOnCancel: true }) : await connection.agent.request(methods.agent.session.load, { ...setup, sessionId: reference.sessionId }, { cancellationSignal: AbortSignal.any([cancel, AbortSignal.timeout(3e4)]), stopWaitingOnCancel: true });
|
|
@@ -10885,6 +10890,7 @@ async function openAcp(reference, cwd, env, callbacks, signal, openOptions = {})
|
|
|
10885
10890
|
close,
|
|
10886
10891
|
images: advertised?.promptCapabilities?.image === true,
|
|
10887
10892
|
systemPrompt: Boolean(advertised?.sessionCapabilities?.systemPrompt),
|
|
10893
|
+
...startupInfo ? { startupInfo } : {},
|
|
10888
10894
|
selection,
|
|
10889
10895
|
choices: () => acpChoices(options),
|
|
10890
10896
|
async configure(requested) {
|
|
@@ -11003,7 +11009,8 @@ async function loadWorkspaceContext(options) {
|
|
|
11003
11009
|
includePrompts = true,
|
|
11004
11010
|
includeRootAgents = false,
|
|
11005
11011
|
localRoleOnly = false,
|
|
11006
|
-
workspaceSkills = []
|
|
11012
|
+
workspaceSkills = [],
|
|
11013
|
+
notices = []
|
|
11007
11014
|
} = options;
|
|
11008
11015
|
const [workspace, roleText, rootAgents] = includePrompts ? await Promise.all([
|
|
11009
11016
|
readFile(join7(resourceRoot, "prompts/workspace.md"), "utf8"),
|
|
@@ -11011,12 +11018,14 @@ async function loadWorkspaceContext(options) {
|
|
|
11011
11018
|
includeRootAgents ? readOptionalFile(join7(root, "AGENTS.md")) : Promise.resolve("")
|
|
11012
11019
|
]) : ["", "", ""];
|
|
11013
11020
|
const skillsSection = formatWorkspaceSkills(workspaceSkills);
|
|
11021
|
+
const noticesSection = notices.length ? "## \u542F\u52A8\u63D0\u793A\n\n" + notices.map((item) => `- ${item}`).join("\n") : "";
|
|
11014
11022
|
const environment = { host, workspaceRoot: root, resourceRoot };
|
|
11015
11023
|
const text3 = [
|
|
11016
11024
|
workspace,
|
|
11017
11025
|
roleText,
|
|
11018
11026
|
rootAgents,
|
|
11019
11027
|
skillsSection,
|
|
11028
|
+
noticesSection,
|
|
11020
11029
|
"## \u73AF\u5883\n\n" + JSON.stringify(environment)
|
|
11021
11030
|
].filter(Boolean).join("\n\n");
|
|
11022
11031
|
return { workspace, role: roleText, rootAgents, workspaceSkills: [...workspaceSkills], environment, text: text3 };
|
|
@@ -11025,14 +11034,20 @@ async function loadWorkspaceContext(options) {
|
|
|
11025
11034
|
// src/services/workspace/workspace-config.ts
|
|
11026
11035
|
import { mkdir, readFile as readFile2 } from "node:fs/promises";
|
|
11027
11036
|
import { dirname as dirname2, join as join8 } from "node:path";
|
|
11028
|
-
var featureKeys = ["prompts", "skills", "mcp"];
|
|
11037
|
+
var featureKeys = ["prompts", "skills", "mcp", "history"];
|
|
11038
|
+
var summaryKeys = ["backend", "model", "thinking", "concurrency"];
|
|
11039
|
+
var historyKeys = ["layout"];
|
|
11040
|
+
var historyLayouts = ["monthly", "flat"];
|
|
11041
|
+
function nonEmptyString(value) {
|
|
11042
|
+
return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
|
|
11043
|
+
}
|
|
11029
11044
|
function config2(value) {
|
|
11030
11045
|
if (!object(value) || value.enabled !== void 0 && typeof value.enabled !== "boolean") {
|
|
11031
11046
|
throw new Error("\u914D\u7F6E\u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0Cenabled \u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002");
|
|
11032
11047
|
}
|
|
11033
11048
|
if (value.features !== void 0) {
|
|
11034
11049
|
if (!object(value.features) || Object.entries(value.features).some(([key, entry]) => !featureKeys.includes(key) || entry !== void 0 && typeof entry !== "boolean")) {
|
|
11035
|
-
throw new Error("features \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 prompts\u3001skills\u3001mcp \u5E03\u5C14\u5F00\u5173\u3002");
|
|
11050
|
+
throw new Error("features \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 prompts\u3001skills\u3001mcp\u3001history \u5E03\u5C14\u5F00\u5173\u3002");
|
|
11036
11051
|
}
|
|
11037
11052
|
}
|
|
11038
11053
|
if (value.acp !== void 0) {
|
|
@@ -11046,6 +11061,31 @@ function config2(value) {
|
|
|
11046
11061
|
}
|
|
11047
11062
|
}
|
|
11048
11063
|
}
|
|
11064
|
+
if (value.summary !== void 0) {
|
|
11065
|
+
if (!object(value.summary) || Object.keys(value.summary).some((key) => !summaryKeys.includes(key))) {
|
|
11066
|
+
throw new Error("summary \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 backend\u3001model\u3001thinking\u3001concurrency\u3002");
|
|
11067
|
+
}
|
|
11068
|
+
if (value.summary.backend !== void 0 && !isAcpBackend(value.summary.backend)) {
|
|
11069
|
+
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");
|
|
11070
|
+
}
|
|
11071
|
+
if (value.summary.model !== void 0 && !nonEmptyString(value.summary.model)) {
|
|
11072
|
+
throw new Error("summary.model \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002");
|
|
11073
|
+
}
|
|
11074
|
+
if (value.summary.thinking !== void 0 && !nonEmptyString(value.summary.thinking)) {
|
|
11075
|
+
throw new Error("summary.thinking \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002");
|
|
11076
|
+
}
|
|
11077
|
+
if (value.summary.concurrency !== void 0 && (typeof value.summary.concurrency !== "number" || !Number.isInteger(value.summary.concurrency) || value.summary.concurrency < 1 || value.summary.concurrency > 8)) {
|
|
11078
|
+
throw new Error("summary.concurrency \u5FC5\u987B\u662F 1 \u5230 8 \u4E4B\u95F4\u7684\u6574\u6570\u3002");
|
|
11079
|
+
}
|
|
11080
|
+
}
|
|
11081
|
+
if (value.history !== void 0) {
|
|
11082
|
+
if (!object(value.history) || Object.keys(value.history).some((key) => !historyKeys.includes(key))) {
|
|
11083
|
+
throw new Error("history \u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u4EC5\u652F\u6301 layout\u3002");
|
|
11084
|
+
}
|
|
11085
|
+
if (value.history.layout !== void 0 && !historyLayouts.includes(String(value.history.layout))) {
|
|
11086
|
+
throw new Error('history.layout \u5FC5\u987B\u662F "monthly" \u6216 "flat"\u3002');
|
|
11087
|
+
}
|
|
11088
|
+
}
|
|
11049
11089
|
return value;
|
|
11050
11090
|
}
|
|
11051
11091
|
function workspaceFeatures(configuration) {
|
|
@@ -11053,7 +11093,8 @@ function workspaceFeatures(configuration) {
|
|
|
11053
11093
|
return {
|
|
11054
11094
|
prompts: raw?.prompts !== false,
|
|
11055
11095
|
skills: raw?.skills !== false,
|
|
11056
|
-
mcp: raw?.mcp !== false
|
|
11096
|
+
mcp: raw?.mcp !== false,
|
|
11097
|
+
history: raw?.history !== false
|
|
11057
11098
|
};
|
|
11058
11099
|
}
|
|
11059
11100
|
function workspaceConfigPath(root) {
|
|
@@ -11076,7 +11117,9 @@ async function readWorkspaceConfig(root) {
|
|
|
11076
11117
|
present: true,
|
|
11077
11118
|
enabled: settings.enabled === true,
|
|
11078
11119
|
...settings.features ? { features: settings.features } : {},
|
|
11079
|
-
...settings.acp ? { acp: settings.acp } : {}
|
|
11120
|
+
...settings.acp ? { acp: settings.acp } : {},
|
|
11121
|
+
...settings.summary ? { summary: settings.summary } : {},
|
|
11122
|
+
...settings.history ? { history: settings.history } : {}
|
|
11080
11123
|
};
|
|
11081
11124
|
} catch (error2) {
|
|
11082
11125
|
return { path, present: true, enabled: false, error: `\u5DE5\u4F5C\u533A\u914D\u7F6E\u65E0\u6548 ${path}: ${String(error2)}` };
|
|
@@ -11348,7 +11391,7 @@ async function discoverWorkspaceSkills(root) {
|
|
|
11348
11391
|
return results;
|
|
11349
11392
|
}
|
|
11350
11393
|
|
|
11351
|
-
// src/extension/acp
|
|
11394
|
+
// src/extension/acp/worker.ts
|
|
11352
11395
|
var errorMessage = (error2) => error2 instanceof Error ? error2.message : String(error2);
|
|
11353
11396
|
function sendIpc(message2) {
|
|
11354
11397
|
return new Promise((resolveSend) => {
|
|
@@ -11592,6 +11635,108 @@ async function runWorker(args2) {
|
|
|
11592
11635
|
if (process.connected) process.disconnect();
|
|
11593
11636
|
}
|
|
11594
11637
|
}
|
|
11638
|
+
async function runOneShotPrompt() {
|
|
11639
|
+
const lifetime = new AbortController();
|
|
11640
|
+
const stop = () => lifetime.abort(new Error("ACP \u6458\u8981\u4EFB\u52A1\u5DF2\u53D6\u6D88\u3002"));
|
|
11641
|
+
process.on("SIGTERM", stop);
|
|
11642
|
+
process.on("SIGINT", stop);
|
|
11643
|
+
try {
|
|
11644
|
+
const payload = await new Promise((resolvePayload, rejectPayload) => {
|
|
11645
|
+
const timer = setTimeout(() => rejectPayload(new Error("\u7F3A\u5C11 ACP \u6458\u8981\u4EFB\u52A1\u53C2\u6570\u3002")), 5e3);
|
|
11646
|
+
process.once("message", (value) => {
|
|
11647
|
+
clearTimeout(timer);
|
|
11648
|
+
if (!object(value)) {
|
|
11649
|
+
rejectPayload(new Error("ACP \u6458\u8981\u4EFB\u52A1\u53C2\u6570\u5FC5\u987B\u662F\u5BF9\u8C61\u3002"));
|
|
11650
|
+
return;
|
|
11651
|
+
}
|
|
11652
|
+
resolvePayload(value);
|
|
11653
|
+
});
|
|
11654
|
+
process.once("disconnect", () => {
|
|
11655
|
+
clearTimeout(timer);
|
|
11656
|
+
rejectPayload(new Error("ACP \u6458\u8981\u4EFB\u52A1\u901A\u9053\u5DF2\u65AD\u5F00\u3002"));
|
|
11657
|
+
});
|
|
11658
|
+
});
|
|
11659
|
+
const reference = acpReference(payload.reference);
|
|
11660
|
+
requireThat(typeof payload.cwd === "string" && payload.cwd.length > 0, "\u7F3A\u5C11 ACP \u6458\u8981\u5DE5\u4F5C\u76EE\u5F55\u3002");
|
|
11661
|
+
requireThat(typeof payload.prompt === "string" && payload.prompt.trim().length > 0, "\u7F3A\u5C11 ACP \u6458\u8981\u8F93\u5165\u5185\u5BB9\u3002");
|
|
11662
|
+
const harness = resolveAcpHarness(reference.backend);
|
|
11663
|
+
const packageRoot = resolve5(resourceRoot, "..");
|
|
11664
|
+
const env = {
|
|
11665
|
+
...process.env,
|
|
11666
|
+
...reference.env ?? {},
|
|
11667
|
+
PBOT_SUBAGENT_RUN_ID: "pbot-summary-" + randomUUID5(),
|
|
11668
|
+
...reference.backend === "pi" ? {
|
|
11669
|
+
PBOT_SUMMARY_WORKER: "1",
|
|
11670
|
+
PI_OFFLINE: "1",
|
|
11671
|
+
PBOT_ACP_PI_COMMAND: process.env.PI_ACP_PI_COMMAND ?? acpExecutable("pi", "pi"),
|
|
11672
|
+
PI_ACP_PI_COMMAND: join11(packageRoot, "bin/pbot-pi-acp.mjs")
|
|
11673
|
+
} : {}
|
|
11674
|
+
};
|
|
11675
|
+
let collecting = false;
|
|
11676
|
+
let text3 = "";
|
|
11677
|
+
const connection = await openAcp(
|
|
11678
|
+
reference,
|
|
11679
|
+
payload.cwd,
|
|
11680
|
+
env,
|
|
11681
|
+
{
|
|
11682
|
+
update(update) {
|
|
11683
|
+
if (collecting && update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
11684
|
+
text3 += update.content.text;
|
|
11685
|
+
}
|
|
11686
|
+
},
|
|
11687
|
+
async permission() {
|
|
11688
|
+
return { outcome: { outcome: "cancelled" } };
|
|
11689
|
+
}
|
|
11690
|
+
},
|
|
11691
|
+
lifetime.signal,
|
|
11692
|
+
{
|
|
11693
|
+
harness,
|
|
11694
|
+
...payload.system ? { systemPrompt: payload.system } : {}
|
|
11695
|
+
}
|
|
11696
|
+
);
|
|
11697
|
+
try {
|
|
11698
|
+
if (payload.model || payload.thinking) {
|
|
11699
|
+
const parsedModel = payload.model ? harness.parseModelValue ? harness.parseModelValue(payload.model) : { model: payload.model } : void 0;
|
|
11700
|
+
await connection.configure({
|
|
11701
|
+
...parsedModel?.provider ? { provider: parsedModel.provider } : {},
|
|
11702
|
+
...parsedModel?.model ? { model: parsedModel.model } : {},
|
|
11703
|
+
...payload.thinking ? { thinking: payload.thinking } : {}
|
|
11704
|
+
});
|
|
11705
|
+
}
|
|
11706
|
+
const promptText = !connection.systemPrompt && payload.system ? `${payload.system}
|
|
11707
|
+
|
|
11708
|
+
---
|
|
11709
|
+
|
|
11710
|
+
${payload.prompt}` : payload.prompt;
|
|
11711
|
+
collecting = true;
|
|
11712
|
+
await connection.prompt([{ type: "text", text: promptText }]);
|
|
11713
|
+
let cleaned = text3;
|
|
11714
|
+
if (connection.startupInfo) {
|
|
11715
|
+
if (cleaned.startsWith(connection.startupInfo)) {
|
|
11716
|
+
cleaned = cleaned.slice(connection.startupInfo.length);
|
|
11717
|
+
} else {
|
|
11718
|
+
const trimmedInfo = connection.startupInfo.trim();
|
|
11719
|
+
const trimmedText = cleaned.trimStart();
|
|
11720
|
+
if (trimmedInfo && trimmedText.startsWith(trimmedInfo)) {
|
|
11721
|
+
cleaned = trimmedText.slice(trimmedInfo.length);
|
|
11722
|
+
}
|
|
11723
|
+
}
|
|
11724
|
+
}
|
|
11725
|
+
const answer = cleaned.trim();
|
|
11726
|
+
requireThat(answer.length > 0, "ACP \u6458\u8981\u8FD4\u56DE\u4E3A\u7A7A\u3002");
|
|
11727
|
+
await sendIpc({ type: "answer", text: answer });
|
|
11728
|
+
} finally {
|
|
11729
|
+
await connection.close();
|
|
11730
|
+
}
|
|
11731
|
+
} catch (error2) {
|
|
11732
|
+
await sendIpc({ type: "error", error: errorMessage(error2) });
|
|
11733
|
+
process.exitCode = 1;
|
|
11734
|
+
} finally {
|
|
11735
|
+
lifetime.abort();
|
|
11736
|
+
if (process.connected) process.disconnect();
|
|
11737
|
+
}
|
|
11738
|
+
}
|
|
11595
11739
|
var args = process.argv.slice(2);
|
|
11596
11740
|
if (args.includes("--probe")) await runProbe();
|
|
11741
|
+
else if (args.includes("--prompt")) await runOneShotPrompt();
|
|
11597
11742
|
else await runWorker(args);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
2
|
-
import { acpMember } from "
|
|
3
|
-
import { rootAgents } from "
|
|
4
|
-
import { dshResources, dshExpertTools } from "
|
|
5
|
-
import { registerDshSkills } from "
|
|
6
|
-
import { toDshMcpConfig } from "
|
|
7
|
-
import { finalDshAnswer } from "
|
|
8
|
-
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "
|
|
2
|
+
import { acpMember } from "../../acp/member.js";
|
|
3
|
+
import { rootAgents } from "../../../integrations/hosts/dsh/root-agents.js";
|
|
4
|
+
import { dshResources, dshExpertTools } from "../../../integrations/hosts/dsh/resources.js";
|
|
5
|
+
import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
|
|
6
|
+
import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
|
|
7
|
+
import { finalDshAnswer } from "../../../integrations/hosts/dsh/messages.js";
|
|
8
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../../services/workspace/workspace-mcp.js";
|
|
9
9
|
import { registerDshFileEvents } from "./files.js";
|
|
10
|
-
import { requireThat } from "
|
|
10
|
+
import { requireThat } from "../../../common/validation.js";
|
|
11
11
|
export const name = "pbot-acp-member";
|
|
12
12
|
export const inject = ["agents", "sessions", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
|
|
13
13
|
export async function apply(ctx) {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { json } from "../../../common/json.js";
|
|
2
|
+
import { requireThat } from "../../../common/validation.js";
|
|
3
|
+
import { createAcpHistorySummarizer } from "../../../integrations/acp/history-summary.js";
|
|
4
|
+
import { migrateWorkspaceHistory } from "../../../services/history/history-migrate.js";
|
|
5
|
+
import { parseHistoryCommand } from "../../../services/history/summary-command.js";
|
|
6
|
+
import { listSummaryDimensions } from "../../../services/history/summary-registry.js";
|
|
7
|
+
import { inspectWorkspaceSummaries, runWorkspaceSummaries } from "../../../services/history/summary-runner.js";
|
|
8
|
+
import { readWorkspaceConfig, readWorkspaceHistoryLayoutSync, workspaceDisabledMessage, workspaceSummaryConfig } from "../../../services/workspace/workspace-config.js";
|
|
9
|
+
import { dshWorkspaceStatus } from "./management.js";
|
|
10
|
+
import { parseWorkerCommand } from "../../mcp/workers.js";
|
|
11
|
+
const usage = '用法:/pbot status | init | history [summary [维度] [--force] [--backend <acp>] [--model <model>] | migrate [--dry-run] | status | list | {"action":…}] | worker [overview|status|backends|models|create|request|response|output|close] [JSON]';
|
|
12
|
+
export function registerDshCommand(ctx, workspaces, management) {
|
|
13
|
+
ctx.commands.register({
|
|
14
|
+
name: "pbot",
|
|
15
|
+
description: "Personal Bot 工作区、历史摘要与跨 Harness worker 管理",
|
|
16
|
+
recordInput: false,
|
|
17
|
+
input: { hint: "status | init | history ... | worker ...", attachments: false },
|
|
18
|
+
async handler({ agent, rawInput, signal }) {
|
|
19
|
+
signal.throwIfAborted();
|
|
20
|
+
const command = rawInput.trim(), split = command.search(/\s/);
|
|
21
|
+
if (!command || command === "status") {
|
|
22
|
+
const status = await dshWorkspaceStatus(workspaces, agent);
|
|
23
|
+
signal.throwIfAborted();
|
|
24
|
+
return { kind: "success", text: JSON.stringify(status, null, 2) };
|
|
25
|
+
}
|
|
26
|
+
if (command === "init") {
|
|
27
|
+
await workspaces.initialize(agent);
|
|
28
|
+
signal.throwIfAborted();
|
|
29
|
+
return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
|
|
30
|
+
}
|
|
31
|
+
const workspace = await workspaces.get(agent);
|
|
32
|
+
signal.throwIfAborted();
|
|
33
|
+
const verb = split < 0 ? command : command.slice(0, split);
|
|
34
|
+
const rest = split < 0 ? "" : command.slice(split).trim();
|
|
35
|
+
let result;
|
|
36
|
+
switch (verb) {
|
|
37
|
+
case "worker": {
|
|
38
|
+
const { tool, args } = parseWorkerCommand(rest);
|
|
39
|
+
result = await workspace.workers.callTool(tool, { workspace: workspace.root, ...args });
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case "history": {
|
|
43
|
+
requireThat(workspace.features.history, "当前工作区已停用历史功能(features.history: false)。");
|
|
44
|
+
const parsed = parseHistoryCommand(rest);
|
|
45
|
+
if (parsed.kind === "status") {
|
|
46
|
+
result = inspectWorkspaceSummaries(workspace.root);
|
|
47
|
+
}
|
|
48
|
+
else if (parsed.kind === "list") {
|
|
49
|
+
const layout = readWorkspaceHistoryLayoutSync(workspace.root);
|
|
50
|
+
result = { layout, dimensions: listSummaryDimensions(layout).map(({ id, title, description }) => ({ id, title, description })) };
|
|
51
|
+
}
|
|
52
|
+
else if (parsed.kind === "migrate") {
|
|
53
|
+
result = migrateWorkspaceHistory(workspace.root, { dryRun: parsed.dryRun });
|
|
54
|
+
}
|
|
55
|
+
else if (parsed.kind === "query") {
|
|
56
|
+
result = await management.history({ parentSessionId: agent.id, input: json(parsed.input) }, signal);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const active = AbortSignal.any([signal, workspace.lifetime.signal]);
|
|
60
|
+
const config = await readWorkspaceConfig(workspace.root);
|
|
61
|
+
requireThat(config.enabled && !config.error, workspaceDisabledMessage(config));
|
|
62
|
+
const summaryCfg = workspaceSummaryConfig(config);
|
|
63
|
+
const backend = parsed.backend ?? summaryCfg.backend;
|
|
64
|
+
const model = parsed.model ?? summaryCfg.model;
|
|
65
|
+
const thinking = parsed.thinking ?? summaryCfg.thinking;
|
|
66
|
+
const summarizer = createAcpHistorySummarizer({
|
|
67
|
+
cwd: workspace.root,
|
|
68
|
+
backend,
|
|
69
|
+
...(config.acp ? { commands: config.acp } : {}),
|
|
70
|
+
...(model ? { model } : {}),
|
|
71
|
+
...(thinking ? { thinking } : {}),
|
|
72
|
+
});
|
|
73
|
+
const report = await runWorkspaceSummaries({
|
|
74
|
+
root: workspace.root,
|
|
75
|
+
summarizer,
|
|
76
|
+
...(parsed.dimensions ? { dimensions: parsed.dimensions } : {}),
|
|
77
|
+
force: parsed.force,
|
|
78
|
+
...(summaryCfg.concurrency !== undefined ? { concurrency: summaryCfg.concurrency } : {}),
|
|
79
|
+
signal: active,
|
|
80
|
+
});
|
|
81
|
+
result = { backend, ...(model ? { model } : {}), ...report };
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
throw new Error(usage);
|
|
87
|
+
}
|
|
88
|
+
workspace.check();
|
|
89
|
+
return { kind: "success", text: JSON.stringify(result, null, 2) };
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parsePatch } from "@deepseek-ai/dsh-fs-patch";
|
|
2
|
-
import { object } from "
|
|
3
|
-
import { requireThat } from "
|
|
4
|
-
import { mutationScope } from "
|
|
2
|
+
import { object } from "../../../common/json.js";
|
|
3
|
+
import { requireThat } from "../../../common/validation.js";
|
|
4
|
+
import { mutationScope } from "../../../services/workspace/workspace-files.js";
|
|
5
5
|
/** Native filesystem mutations share the original workspace's confirmation rule.
|
|
6
6
|
* This does not confine Bash, Python, MCP, or other extensions. */
|
|
7
7
|
export function registerDshFileEvents(ctx, agent, root, expert, check) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
/** Capture root-session raw Q&A exchanges into .pbot/history/raw/. Summaries run on explicit trigger. */
|
|
4
|
+
export declare function registerDshHistoryEvents(ctx: Context, agent: Agent, root: string): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { recordHistoryCapture } from "../../../services/history/history-capture.js";
|
|
2
|
+
import { finalDshAnswer } from "../../../integrations/hosts/dsh/messages.js";
|
|
3
|
+
function userMessageText(content) {
|
|
4
|
+
return content.flatMap(block => block.type === "text" ? [block.text] :
|
|
5
|
+
block.type === "image" ? ["[图片 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] :
|
|
6
|
+
block.type === "file" ? ["[附件 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] : []).join("\n");
|
|
7
|
+
}
|
|
8
|
+
/** Capture root-session raw Q&A exchanges into .pbot/history/raw/. Summaries run on explicit trigger. */
|
|
9
|
+
export function registerDshHistoryEvents(ctx, agent, root) {
|
|
10
|
+
let final = false;
|
|
11
|
+
let lastAnswer = "";
|
|
12
|
+
let lastAnswerTime;
|
|
13
|
+
ctx.on("session/event", (session, event) => {
|
|
14
|
+
if (session !== agent.session)
|
|
15
|
+
return;
|
|
16
|
+
if (event.type === "turn/start") {
|
|
17
|
+
final = false;
|
|
18
|
+
lastAnswer = "";
|
|
19
|
+
lastAnswerTime = undefined;
|
|
20
|
+
}
|
|
21
|
+
if (event.type === "user/message" && event.data.source.kind === "user") {
|
|
22
|
+
const text = userMessageText(event.data.content).trim();
|
|
23
|
+
if (text) {
|
|
24
|
+
try {
|
|
25
|
+
recordHistoryCapture(root, "dsh", {
|
|
26
|
+
kind: "input",
|
|
27
|
+
sessionId: agent.id,
|
|
28
|
+
text,
|
|
29
|
+
timestamp: new Date(event.time).toISOString(),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch { /* Never block a user turn if history persistence fails. */ }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (event.type === "assistant/message") {
|
|
36
|
+
const completeText = finalDshAnswer(event).trim();
|
|
37
|
+
final = Boolean(completeText);
|
|
38
|
+
const body = completeText || event.data.message.content.filter(block => block.type === "text").map(block => block.text).join("\n").trim();
|
|
39
|
+
if (body) {
|
|
40
|
+
lastAnswer = body;
|
|
41
|
+
lastAnswerTime = new Date(event.time).toISOString();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (event.type === "turn/end") {
|
|
45
|
+
const completed = event.data.reason.kind === "completed" && final;
|
|
46
|
+
if (lastAnswer) {
|
|
47
|
+
try {
|
|
48
|
+
recordHistoryCapture(root, "dsh", {
|
|
49
|
+
kind: "answer",
|
|
50
|
+
sessionId: agent.id,
|
|
51
|
+
assistantText: lastAnswer,
|
|
52
|
+
completed,
|
|
53
|
+
...(lastAnswerTime ? { timestamp: lastAnswerTime } : {}),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch { /* Never block turn completion if history persistence fails. */ }
|
|
57
|
+
}
|
|
58
|
+
lastAnswer = "";
|
|
59
|
+
lastAnswerTime = undefined;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
2
2
|
import type { Context } from "@deepseek-ai/cordis";
|
|
3
3
|
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
4
|
-
import { type Json } from "
|
|
4
|
+
import { type Json } from "../../../common/json.js";
|
|
5
5
|
import type { DshWorkspaces, DshWorkspace } from "./workspace.js";
|
|
6
6
|
export declare function dshStatus(workspace: DshWorkspace): Json;
|
|
7
7
|
/** Status remains available when this workspace has not opted in. */
|
|
@@ -34,14 +34,15 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
34
34
|
};
|
|
35
35
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
36
36
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
37
|
-
import { Type } from "
|
|
38
|
-
import { json } from "
|
|
39
|
-
import { requireThat } from "
|
|
40
|
-
import { schema } from "
|
|
41
|
-
import { packageVersion } from "
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
37
|
+
import { Type } from "../../../common/typebox.js";
|
|
38
|
+
import { json } from "../../../common/json.js";
|
|
39
|
+
import { requireThat } from "../../../common/validation.js";
|
|
40
|
+
import { schema } from "../../../common/schema.js";
|
|
41
|
+
import { packageVersion } from "../../../common/version.js";
|
|
42
|
+
import { inspectWorkspaceSummaries } from "../../../services/history/summary-runner.js";
|
|
43
|
+
import { historyInput } from "../../../tools/history/contract.js";
|
|
44
|
+
import { executeHistory } from "../../../tools/history/actions.js";
|
|
45
|
+
import { pbotReadRemote } from "../../../ui/dsh/remote.js";
|
|
45
46
|
const requestSchema = Type.Object({ parentSessionId: Type.String({ minLength: 1 }), input: Type.Optional(Type.Unknown()) }, { additionalProperties: false });
|
|
46
47
|
const validRequest = schema(requestSchema);
|
|
47
48
|
export function dshStatus(workspace) {
|
|
@@ -54,7 +55,7 @@ export function dshStatus(workspace) {
|
|
|
54
55
|
workspaceRoot: workspace.root,
|
|
55
56
|
sessionId: workspace.agent.id,
|
|
56
57
|
model: workspace.agent.model.current() ?? null,
|
|
57
|
-
history: workspace.history.
|
|
58
|
+
history: workspace.features.history ? inspectWorkspaceSummaries(workspace.root) : null,
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
/** Status remains available when this workspace has not opted in. */
|
|
@@ -119,7 +120,8 @@ let PbotManagement = (() => {
|
|
|
119
120
|
}
|
|
120
121
|
async history(request, signal) {
|
|
121
122
|
const current = await this.workspace(request, signal), { workspace, input } = current;
|
|
122
|
-
|
|
123
|
+
requireThat(workspace.features.history, "当前工作区已停用历史功能(features.history: false)。");
|
|
124
|
+
const result = executeHistory(workspace.root, historyInput(input), current.signal);
|
|
123
125
|
workspace.check();
|
|
124
126
|
current.signal.throwIfAborted();
|
|
125
127
|
return json(result);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
2
2
|
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../model/workspace-config.js";
|
|
6
|
-
import { McpWorkerRuntime } from "../mcp-workers.js";
|
|
3
|
+
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
|
|
4
|
+
import { McpWorkerRuntime } from "../../mcp/workers.js";
|
|
7
5
|
export declare const dshDependencies: string[];
|
|
8
6
|
export declare class DshWorkspace {
|
|
9
7
|
#private;
|
|
@@ -11,13 +9,10 @@ export declare class DshWorkspace {
|
|
|
11
9
|
readonly root: string;
|
|
12
10
|
readonly agent: Agent;
|
|
13
11
|
readonly component: AbortSignal;
|
|
14
|
-
private readonly historyWork;
|
|
15
|
-
private readonly releaseHistory;
|
|
16
12
|
readonly features: ResolvedWorkspaceFeatures;
|
|
17
13
|
readonly lifetime: AbortController;
|
|
18
|
-
readonly history: HistoryService;
|
|
19
14
|
readonly workers: McpWorkerRuntime;
|
|
20
|
-
constructor(ctx: Context, root: string, agent: Agent, component: AbortSignal,
|
|
15
|
+
constructor(ctx: Context, root: string, agent: Agent, component: AbortSignal, features?: ResolvedWorkspaceFeatures);
|
|
21
16
|
check: () => void;
|
|
22
17
|
open(): Promise<void>;
|
|
23
18
|
close(): Promise<void>;
|
|
@@ -26,7 +21,6 @@ export declare class DshWorkspaces {
|
|
|
26
21
|
#private;
|
|
27
22
|
readonly ctx: Context;
|
|
28
23
|
constructor(ctx: Context);
|
|
29
|
-
private history;
|
|
30
24
|
open(agent: Agent): Promise<DshWorkspace | undefined>;
|
|
31
25
|
get(agent: Agent): Promise<DshWorkspace>;
|
|
32
26
|
configuration(agent: Agent): Promise<{
|