personal-bot 0.3.1 → 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 +73 -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 +73 -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 +91 -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
|
@@ -35,7 +35,7 @@ export function formatWorkspaceSkills(skills) {
|
|
|
35
35
|
return "## 工作区技能\n\n以下为工作区自有专业方法(位于 `.agents/skills/`),匹配任务时按需读取对应 `SKILL.md` 正文:\n" + lines.join("\n");
|
|
36
36
|
}
|
|
37
37
|
export async function loadWorkspaceContext(options) {
|
|
38
|
-
const { host, root, role, coordinatorPrompt, includePrompts = true, includeRootAgents = false, localRoleOnly = false, workspaceSkills = [], } = options;
|
|
38
|
+
const { host, root, role, coordinatorPrompt, includePrompts = true, includeRootAgents = false, localRoleOnly = false, workspaceSkills = [], notices = [], } = options;
|
|
39
39
|
const [workspace, roleText, rootAgents] = includePrompts
|
|
40
40
|
? await Promise.all([
|
|
41
41
|
readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"),
|
|
@@ -44,12 +44,16 @@ export async function loadWorkspaceContext(options) {
|
|
|
44
44
|
])
|
|
45
45
|
: ["", "", ""];
|
|
46
46
|
const skillsSection = formatWorkspaceSkills(workspaceSkills);
|
|
47
|
+
const noticesSection = notices.length
|
|
48
|
+
? "## 启动提示\n\n" + notices.map(item => `- ${item}`).join("\n")
|
|
49
|
+
: "";
|
|
47
50
|
const environment = { host, workspaceRoot: root, resourceRoot };
|
|
48
51
|
const text = [
|
|
49
52
|
workspace,
|
|
50
53
|
roleText,
|
|
51
54
|
rootAgents,
|
|
52
55
|
skillsSection,
|
|
56
|
+
noticesSection,
|
|
53
57
|
"## 环境\n\n" + JSON.stringify(environment),
|
|
54
58
|
].filter(Boolean).join("\n\n");
|
|
55
59
|
return { workspace, role: roleText, rootAgents, workspaceSkills: [...workspaceSkills], environment, text };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HistorySession } from "../../../model/history.js";
|
|
2
|
+
import type { PluginHostAdapter } from "../../../model/plugin-host.js";
|
|
3
|
+
export declare function projectAntigravityTranscript(sessionId: string, content: string, terminationReason?: string): HistorySession;
|
|
4
|
+
export declare function antigravityWorkspaceRoot(cwd: string, payload?: unknown): Promise<string>;
|
|
5
|
+
export declare const antigravityAdapter: PluginHostAdapter;
|
|
6
|
+
export declare const antigravitySkillPath: (pluginRoot: string, skill: string) => string;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { readFile, realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { object } from "../../../common/json.js";
|
|
4
|
+
import { resourceRoot } from "../../../common/paths.js";
|
|
5
|
+
import { requireThat } from "../../../common/validation.js";
|
|
6
|
+
const supportedEvents = ["SessionStart", "PreToolUse", "Stop"];
|
|
7
|
+
function cleanUserRequest(content) {
|
|
8
|
+
const match = content.match(/<USER_REQUEST>\s*([\s\S]*?)\s*<\/USER_REQUEST>/);
|
|
9
|
+
return (match ? match[1] : content).trim();
|
|
10
|
+
}
|
|
11
|
+
export function projectAntigravityTranscript(sessionId, content, terminationReason) {
|
|
12
|
+
const exchanges = [];
|
|
13
|
+
const lines = content.split(/\r?\n/);
|
|
14
|
+
let users = [];
|
|
15
|
+
let answer;
|
|
16
|
+
const finish = (completed) => {
|
|
17
|
+
if (!users.length)
|
|
18
|
+
return;
|
|
19
|
+
const entryIds = [...users.map(u => u.id), ...(answer ? [answer.id] : [])];
|
|
20
|
+
const from = users[0].time;
|
|
21
|
+
const to = answer?.time ?? users.at(-1).time;
|
|
22
|
+
const text = users.map(u => "用户:\n" + u.text).join("\n\n") +
|
|
23
|
+
(answer ? "\n\n助手:\n" + answer.text : "");
|
|
24
|
+
exchanges.push({ entryIds, from, to, completed, text });
|
|
25
|
+
users = [];
|
|
26
|
+
answer = undefined;
|
|
27
|
+
};
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
const trimmed = line.trim();
|
|
30
|
+
if (!trimmed)
|
|
31
|
+
continue;
|
|
32
|
+
let entry;
|
|
33
|
+
try {
|
|
34
|
+
entry = JSON.parse(trimmed);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!object(entry) || typeof entry.type !== "string")
|
|
40
|
+
continue;
|
|
41
|
+
const stepIndex = typeof entry.step_index === "number" ? entry.step_index : exchanges.length;
|
|
42
|
+
const time = typeof entry.created_at === "string" && entry.created_at ? entry.created_at : new Date().toISOString();
|
|
43
|
+
if (entry.type === "USER_INPUT" && typeof entry.content === "string") {
|
|
44
|
+
if (answer)
|
|
45
|
+
finish(true);
|
|
46
|
+
const cleaned = cleanUserRequest(entry.content);
|
|
47
|
+
if (cleaned)
|
|
48
|
+
users.push({ id: `agy:${stepIndex}`, text: cleaned, time });
|
|
49
|
+
}
|
|
50
|
+
else if (entry.type === "PLANNER_RESPONSE" && users.length) {
|
|
51
|
+
const hasToolCalls = Array.isArray(entry.tool_calls) && entry.tool_calls.length > 0;
|
|
52
|
+
const text = typeof entry.content === "string" ? entry.content.trim() : "";
|
|
53
|
+
if (!hasToolCalls && text) {
|
|
54
|
+
answer = { id: `agy:${stepIndex}`, text, time };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const completed = Boolean(answer) && (!terminationReason || terminationReason === "NO_TOOL_CALL");
|
|
59
|
+
finish(completed);
|
|
60
|
+
return { sessionId, name: "", branches: exchanges.length ? [exchanges] : [] };
|
|
61
|
+
}
|
|
62
|
+
async function readAntigravityTranscript(transcriptPath) {
|
|
63
|
+
const fullPath = join(dirname(transcriptPath), "transcript_full.jsonl");
|
|
64
|
+
for (const path of [fullPath, transcriptPath]) {
|
|
65
|
+
try {
|
|
66
|
+
return await readFile(path, "utf8");
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error.code !== "ENOENT")
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
function workspaceFromPayload(cwd, payload) {
|
|
76
|
+
if (object(payload) && Array.isArray(payload.workspacePaths)) {
|
|
77
|
+
const first = payload.workspacePaths.find(value => typeof value === "string" && value.length > 0);
|
|
78
|
+
if (typeof first === "string")
|
|
79
|
+
return first;
|
|
80
|
+
}
|
|
81
|
+
return cwd;
|
|
82
|
+
}
|
|
83
|
+
function skillFromReadPath(targetPath, pluginRoot = process.env.PLUGIN_ROOT || resolve(resourceRoot, "..")) {
|
|
84
|
+
const skillsRoot = resolve(pluginRoot, "skills");
|
|
85
|
+
const rel = relative(skillsRoot, resolve(targetPath));
|
|
86
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel))
|
|
87
|
+
return undefined;
|
|
88
|
+
const skill = rel.split(sep)[0];
|
|
89
|
+
if (!skill || skill === "pbot")
|
|
90
|
+
return undefined;
|
|
91
|
+
return skill;
|
|
92
|
+
}
|
|
93
|
+
function isPreToolUse(payload) {
|
|
94
|
+
return object(payload) && payload.hookEventName === "PreToolUse";
|
|
95
|
+
}
|
|
96
|
+
export async function antigravityWorkspaceRoot(cwd, payload) {
|
|
97
|
+
const directory = workspaceFromPayload(cwd, payload);
|
|
98
|
+
requireThat(isAbsolute(directory), "Antigravity 工作区需要绝对路径。");
|
|
99
|
+
const root = await realpath(directory);
|
|
100
|
+
requireThat((await stat(root)).isDirectory(), "Antigravity 工作区需要目录。");
|
|
101
|
+
return root;
|
|
102
|
+
}
|
|
103
|
+
export const antigravityAdapter = {
|
|
104
|
+
host: "antigravity",
|
|
105
|
+
nativeRootAgents: true,
|
|
106
|
+
nativeWorkspaceSkills: true,
|
|
107
|
+
coordinatorPrompt: "plugin-coordinator.md",
|
|
108
|
+
initCommandHint: "/pbot init",
|
|
109
|
+
usage: "用法:node <插件目录>/lib/plugin.js antigravity init|status",
|
|
110
|
+
resolveRoot(cwd, rawPayload) {
|
|
111
|
+
return antigravityWorkspaceRoot(cwd, rawPayload);
|
|
112
|
+
},
|
|
113
|
+
parseEvent(value) {
|
|
114
|
+
requireThat(object(value) && typeof value.hookEventName === "string", "Antigravity hook 输入无效。");
|
|
115
|
+
const event = value.hookEventName;
|
|
116
|
+
requireThat(supportedEvents.includes(event), "Antigravity hook 事件未支持。");
|
|
117
|
+
const cwd = typeof value.cwd === "string" && value.cwd ? value.cwd : workspaceFromPayload("", value);
|
|
118
|
+
requireThat(cwd, "Antigravity hook 缺少工作目录。");
|
|
119
|
+
if (event === "SessionStart") {
|
|
120
|
+
return { kind: "inject-context", role: "coordinator", isSessionStart: true, cwd, raw: value };
|
|
121
|
+
}
|
|
122
|
+
if (event === "Stop") {
|
|
123
|
+
return { kind: "record-history", cwd, raw: value };
|
|
124
|
+
}
|
|
125
|
+
if (!object(value.toolCall) || typeof value.toolCall.name !== "string" || !object(value.toolCall.args)) {
|
|
126
|
+
return { kind: "ignore" };
|
|
127
|
+
}
|
|
128
|
+
const { name, args } = value.toolCall;
|
|
129
|
+
if (name === "read_file" && typeof args.Path === "string") {
|
|
130
|
+
const skill = skillFromReadPath(args.Path);
|
|
131
|
+
if (skill)
|
|
132
|
+
return { kind: "check-skill", skill, cwd, raw: value };
|
|
133
|
+
}
|
|
134
|
+
return { kind: "ignore" };
|
|
135
|
+
},
|
|
136
|
+
async extractHistory(event) {
|
|
137
|
+
if (event.kind !== "record-history" || !object(event.raw))
|
|
138
|
+
return undefined;
|
|
139
|
+
const sessionId = typeof event.raw.conversationId === "string" ? event.raw.conversationId.trim() : "";
|
|
140
|
+
if (!sessionId)
|
|
141
|
+
return undefined;
|
|
142
|
+
const terminationReason = typeof event.raw.terminationReason === "string" ? event.raw.terminationReason : undefined;
|
|
143
|
+
const transcriptPath = typeof event.raw.transcriptPath === "string" ? event.raw.transcriptPath.trim() : "";
|
|
144
|
+
if (transcriptPath) {
|
|
145
|
+
const content = await readAntigravityTranscript(transcriptPath);
|
|
146
|
+
if (content) {
|
|
147
|
+
const session = projectAntigravityTranscript(sessionId, content, terminationReason);
|
|
148
|
+
if (session.branches.length)
|
|
149
|
+
return { kind: "session", session };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const lastUserInput = typeof event.raw.lastUserInput === "string" ? event.raw.lastUserInput.trim() : "";
|
|
153
|
+
if (lastUserInput)
|
|
154
|
+
return { kind: "input", sessionId, text: lastUserInput };
|
|
155
|
+
return undefined;
|
|
156
|
+
},
|
|
157
|
+
formatPass(payload) {
|
|
158
|
+
return isPreToolUse(payload) ? { decision: "allow" } : {};
|
|
159
|
+
},
|
|
160
|
+
formatContext(_event, context) {
|
|
161
|
+
return {
|
|
162
|
+
injectSteps: [
|
|
163
|
+
{ systemMessage: { systemMessage: context.text } },
|
|
164
|
+
],
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
formatDeny(_event, reason) {
|
|
168
|
+
return { decision: "deny", reason };
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
export const antigravitySkillPath = (pluginRoot, skill) => join(pluginRoot, "skills", skill, "SKILL.md");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { PluginHostAdapter } from "
|
|
1
|
+
import type { PluginHostAdapter } from "../../../model/plugin-host.js";
|
|
2
2
|
export declare function claudeWorkspaceRoot(cwd: string, projectDirectory?: string | undefined): Promise<string>;
|
|
3
3
|
export declare const claudeAdapter: PluginHostAdapter;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { realpath, stat } from "node:fs/promises";
|
|
2
2
|
import { isAbsolute } from "node:path";
|
|
3
|
-
import { object } from "
|
|
4
|
-
import { requireThat } from "
|
|
5
|
-
const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion"];
|
|
3
|
+
import { object } from "../../../common/json.js";
|
|
4
|
+
import { requireThat } from "../../../common/validation.js";
|
|
5
|
+
const supportedEvents = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
|
|
6
6
|
export async function claudeWorkspaceRoot(cwd, projectDirectory = process.env.CLAUDE_PROJECT_DIR) {
|
|
7
7
|
const directory = projectDirectory || cwd;
|
|
8
8
|
requireThat(isAbsolute(directory), "Claude 工作区需要绝对路径。");
|
|
@@ -33,12 +33,40 @@ export const claudeAdapter = {
|
|
|
33
33
|
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
34
34
|
return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
|
|
35
35
|
}
|
|
36
|
-
// Leave Claude's native subagents untouched; only inject coordinator context
|
|
36
|
+
// Leave Claude's native subagents untouched; only inject coordinator context or record history in main sessions.
|
|
37
37
|
if (typeof value.agent_id === "string")
|
|
38
38
|
return { kind: "ignore" };
|
|
39
39
|
requireThat(typeof value.cwd === "string", "Claude hook 缺少工作目录。");
|
|
40
|
+
if (event === "Stop")
|
|
41
|
+
return { kind: "record-history", cwd: value.cwd, raw: value };
|
|
40
42
|
return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
|
|
41
43
|
},
|
|
44
|
+
async extractHistory(event) {
|
|
45
|
+
if (!object(event.raw))
|
|
46
|
+
return undefined;
|
|
47
|
+
const sessionId = typeof event.raw.session_id === "string" ? event.raw.session_id.trim() : "";
|
|
48
|
+
if (!sessionId)
|
|
49
|
+
return undefined;
|
|
50
|
+
if (event.raw.hook_event_name === "UserPromptSubmit") {
|
|
51
|
+
const text = typeof event.raw.prompt === "string" ? event.raw.prompt.trim() : "";
|
|
52
|
+
if (!text)
|
|
53
|
+
return undefined;
|
|
54
|
+
return { kind: "input", sessionId, text };
|
|
55
|
+
}
|
|
56
|
+
if (event.raw.hook_event_name === "Stop") {
|
|
57
|
+
const assistantText = typeof event.raw.last_assistant_message === "string" ? event.raw.last_assistant_message.trim() : "";
|
|
58
|
+
if (!assistantText)
|
|
59
|
+
return undefined;
|
|
60
|
+
return {
|
|
61
|
+
kind: "answer",
|
|
62
|
+
sessionId,
|
|
63
|
+
assistantText,
|
|
64
|
+
completed: true,
|
|
65
|
+
...(event.raw.stop_hook_active === true ? { isContinuation: true } : {}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
},
|
|
42
70
|
formatPass() {
|
|
43
71
|
return {};
|
|
44
72
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { requireThat } from "../../common/validation.js";
|
|
2
|
-
import { antigravityAdapter } from "./antigravity.js";
|
|
3
|
-
import { claudeAdapter } from "./claude.js";
|
|
2
|
+
import { antigravityAdapter } from "./antigravity/adapter.js";
|
|
3
|
+
import { claudeAdapter } from "./claude/adapter.js";
|
|
4
4
|
/** Extensible registry of hook-based plugin host adapters; runtime never branches on host IDs. */
|
|
5
5
|
export class PluginHostRegistry {
|
|
6
6
|
#adapters = new Map();
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { HistoryLayout } from "./workspace-config.js";
|
|
2
|
+
export type { HistoryLayout };
|
|
3
|
+
export type HistoryHost = string;
|
|
4
|
+
export interface HistoryExchange {
|
|
5
|
+
entryIds: string[];
|
|
6
|
+
text: string;
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
completed: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface HistorySession {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
branches: HistoryExchange[][];
|
|
15
|
+
/** Earlier partial observations replaced along the same native branch or turn; never persisted. */
|
|
16
|
+
supersededEntryIds?: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface HistoryIdentity {
|
|
19
|
+
host: HistoryHost;
|
|
20
|
+
id: string;
|
|
21
|
+
sessionId: string;
|
|
22
|
+
}
|
|
23
|
+
export interface RawHistory extends HistoryIdentity {
|
|
24
|
+
name: string;
|
|
25
|
+
/** One entry per archived exchange; array order does not describe a conversation. */
|
|
26
|
+
exchanges: (HistoryExchange & {
|
|
27
|
+
id: string;
|
|
28
|
+
})[];
|
|
29
|
+
/** Ordered paths observed in the native source. */
|
|
30
|
+
branches: string[][];
|
|
31
|
+
}
|
|
32
|
+
export interface SummarySource {
|
|
33
|
+
rawIds: string[];
|
|
34
|
+
exchangeIds: string[];
|
|
35
|
+
fingerprint: string;
|
|
36
|
+
}
|
|
37
|
+
export interface SummaryArtifact {
|
|
38
|
+
id: string;
|
|
39
|
+
dimension: string;
|
|
40
|
+
host?: HistoryHost;
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
title: string;
|
|
43
|
+
text: string;
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
source: SummarySource;
|
|
48
|
+
}
|
|
49
|
+
export interface HistorySummaryRequest {
|
|
50
|
+
system: string;
|
|
51
|
+
prompt: string;
|
|
52
|
+
maxTokens: number;
|
|
53
|
+
}
|
|
54
|
+
export type HistorySummarizer = (request: HistorySummaryRequest, signal: AbortSignal) => Promise<string>;
|
|
55
|
+
export type SummaryTaskMode = "create" | "incremental" | "rebuild";
|
|
56
|
+
export interface SummaryTask {
|
|
57
|
+
id: string;
|
|
58
|
+
dimension: string;
|
|
59
|
+
mode: SummaryTaskMode;
|
|
60
|
+
title: string;
|
|
61
|
+
host?: HistoryHost;
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
from: string;
|
|
64
|
+
to: string;
|
|
65
|
+
source: SummarySource;
|
|
66
|
+
exchanges: readonly (HistoryExchange & {
|
|
67
|
+
id: string;
|
|
68
|
+
})[];
|
|
69
|
+
existing?: SummaryArtifact;
|
|
70
|
+
addedExchanges?: readonly (HistoryExchange & {
|
|
71
|
+
id: string;
|
|
72
|
+
})[];
|
|
73
|
+
sourceSummaries?: readonly SummaryArtifact[];
|
|
74
|
+
}
|
|
75
|
+
export interface SummaryPlanOptions {
|
|
76
|
+
force?: boolean;
|
|
77
|
+
summariesByDimension?: ReadonlyMap<string, ReadonlyMap<string, SummaryArtifact>>;
|
|
78
|
+
}
|
|
79
|
+
export interface SummaryPlanResult {
|
|
80
|
+
tasks: SummaryTask[];
|
|
81
|
+
skipped: number;
|
|
82
|
+
}
|
|
83
|
+
export interface SummaryDimension {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly title: string;
|
|
86
|
+
readonly description: string;
|
|
87
|
+
readonly requiresMonthlyLayout?: boolean;
|
|
88
|
+
plan(raws: readonly RawHistory[], existing: ReadonlyMap<string, SummaryArtifact>, options?: SummaryPlanOptions): SummaryPlanResult;
|
|
89
|
+
buildRequest(task: SummaryTask): HistorySummaryRequest;
|
|
90
|
+
finalize(task: SummaryTask, output: string, now: string): SummaryArtifact;
|
|
91
|
+
}
|
|
92
|
+
export interface HistoryMigrationItem {
|
|
93
|
+
kind: "raw" | "summary";
|
|
94
|
+
dimension?: string;
|
|
95
|
+
id: string;
|
|
96
|
+
from: string;
|
|
97
|
+
to: string;
|
|
98
|
+
}
|
|
99
|
+
export interface HistoryMigrationConflict {
|
|
100
|
+
kind: "raw" | "summary";
|
|
101
|
+
dimension?: string;
|
|
102
|
+
from: string;
|
|
103
|
+
to: string;
|
|
104
|
+
reason: string;
|
|
105
|
+
}
|
|
106
|
+
export interface HistoryMigrationReport {
|
|
107
|
+
layout: HistoryLayout;
|
|
108
|
+
dryRun: boolean;
|
|
109
|
+
moved: HistoryMigrationItem[];
|
|
110
|
+
skipped: HistoryMigrationConflict[];
|
|
111
|
+
errors: {
|
|
112
|
+
path: string;
|
|
113
|
+
error: string;
|
|
114
|
+
}[];
|
|
115
|
+
}
|
|
116
|
+
export interface SummaryDimensionStatus {
|
|
117
|
+
dimension: string;
|
|
118
|
+
title: string;
|
|
119
|
+
description: string;
|
|
120
|
+
total: number;
|
|
121
|
+
ready: number;
|
|
122
|
+
pendingCreate: number;
|
|
123
|
+
pendingIncremental: number;
|
|
124
|
+
pendingRebuild: number;
|
|
125
|
+
}
|
|
126
|
+
export interface HistorySummaryReminder {
|
|
127
|
+
rawCount: number;
|
|
128
|
+
pendingCount: number;
|
|
129
|
+
oldestRawAt: string;
|
|
130
|
+
latestSummaryAt?: string;
|
|
131
|
+
rawAgeDays: number;
|
|
132
|
+
daysSinceLastSummary?: number;
|
|
133
|
+
thresholdDays: number;
|
|
134
|
+
message: string;
|
|
135
|
+
}
|
|
136
|
+
export interface SummaryRunProgress {
|
|
137
|
+
dimension: string;
|
|
138
|
+
completed: number;
|
|
139
|
+
total: number;
|
|
140
|
+
currentId: string;
|
|
141
|
+
mode: SummaryTaskMode;
|
|
142
|
+
}
|
|
143
|
+
export interface SummaryDimensionReport {
|
|
144
|
+
dimension: string;
|
|
145
|
+
scanned: number;
|
|
146
|
+
skipped: number;
|
|
147
|
+
created: number;
|
|
148
|
+
incremental: number;
|
|
149
|
+
rebuilt: number;
|
|
150
|
+
failed: {
|
|
151
|
+
id: string;
|
|
152
|
+
error: string;
|
|
153
|
+
}[];
|
|
154
|
+
}
|
|
155
|
+
export interface SummaryRunReport {
|
|
156
|
+
dimensions: SummaryDimensionReport[];
|
|
157
|
+
durationMs: number;
|
|
158
|
+
warnings: string[];
|
|
159
|
+
}
|
|
160
|
+
export interface HistoryQuery {
|
|
161
|
+
host?: HistoryHost;
|
|
162
|
+
query?: string;
|
|
163
|
+
sessionId?: string;
|
|
164
|
+
dimension?: string;
|
|
165
|
+
from?: string;
|
|
166
|
+
to?: string;
|
|
167
|
+
offset?: number;
|
|
168
|
+
limit?: number;
|
|
169
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HistorySession } from "./history.js";
|
|
1
2
|
import type { WorkspaceSkillMeta } from "./workspace-mcp.js";
|
|
2
3
|
export type HostId = string;
|
|
3
4
|
export type PluginHostId = string;
|
|
@@ -15,12 +16,30 @@ export interface WorkspaceContext {
|
|
|
15
16
|
environment: WorkspaceEnvironment;
|
|
16
17
|
text: string;
|
|
17
18
|
}
|
|
19
|
+
export type HistoryCapture = {
|
|
20
|
+
kind: "input";
|
|
21
|
+
sessionId: string;
|
|
22
|
+
text: string;
|
|
23
|
+
timestamp?: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "answer";
|
|
26
|
+
sessionId: string;
|
|
27
|
+
userText?: string;
|
|
28
|
+
assistantText: string;
|
|
29
|
+
completed: boolean;
|
|
30
|
+
isContinuation?: boolean;
|
|
31
|
+
timestamp?: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "session";
|
|
34
|
+
session: HistorySession;
|
|
35
|
+
};
|
|
18
36
|
export type HostEvent = {
|
|
19
37
|
kind: "ignore";
|
|
20
38
|
} | {
|
|
21
39
|
kind: "inject-context";
|
|
22
40
|
role: WorkspaceRole;
|
|
23
41
|
localRoleOnly?: boolean;
|
|
42
|
+
isSessionStart?: boolean;
|
|
24
43
|
cwd: string;
|
|
25
44
|
raw: unknown;
|
|
26
45
|
} | {
|
|
@@ -28,6 +47,10 @@ export type HostEvent = {
|
|
|
28
47
|
skill: string;
|
|
29
48
|
cwd: string;
|
|
30
49
|
raw: unknown;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "record-history";
|
|
52
|
+
cwd: string;
|
|
53
|
+
raw: unknown;
|
|
31
54
|
};
|
|
32
55
|
export interface PluginHostAdapter {
|
|
33
56
|
readonly host: PluginHostId;
|
|
@@ -38,6 +61,9 @@ export interface PluginHostAdapter {
|
|
|
38
61
|
readonly usage: string;
|
|
39
62
|
resolveRoot(cwd: string, rawPayload?: unknown): Promise<string>;
|
|
40
63
|
parseEvent(payload: unknown): HostEvent;
|
|
64
|
+
extractHistory?(event: Extract<HostEvent, {
|
|
65
|
+
kind: "inject-context" | "record-history";
|
|
66
|
+
}>): Promise<HistoryCapture | undefined>;
|
|
41
67
|
formatPass(payload: unknown): Record<string, unknown>;
|
|
42
68
|
formatContext(event: Extract<HostEvent, {
|
|
43
69
|
kind: "inject-context";
|
|
@@ -3,16 +3,39 @@ export interface WorkspaceFeatures {
|
|
|
3
3
|
prompts?: boolean;
|
|
4
4
|
skills?: boolean;
|
|
5
5
|
mcp?: boolean;
|
|
6
|
+
history?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export interface ResolvedWorkspaceFeatures {
|
|
8
9
|
readonly prompts: boolean;
|
|
9
10
|
readonly skills: boolean;
|
|
10
11
|
readonly mcp: boolean;
|
|
12
|
+
readonly history: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkspaceSummaryConfig {
|
|
15
|
+
backend?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
thinking?: string;
|
|
18
|
+
concurrency?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ResolvedWorkspaceSummaryConfig {
|
|
21
|
+
readonly backend: string;
|
|
22
|
+
readonly model?: string;
|
|
23
|
+
readonly thinking?: string;
|
|
24
|
+
readonly concurrency: number;
|
|
25
|
+
}
|
|
26
|
+
export type HistoryLayout = "monthly" | "flat";
|
|
27
|
+
export interface WorkspaceHistoryConfig {
|
|
28
|
+
layout?: HistoryLayout;
|
|
29
|
+
}
|
|
30
|
+
export interface ResolvedWorkspaceHistoryConfig {
|
|
31
|
+
readonly layout: HistoryLayout;
|
|
11
32
|
}
|
|
12
33
|
export interface WorkspaceConfig {
|
|
13
34
|
enabled?: boolean;
|
|
14
35
|
features?: WorkspaceFeatures;
|
|
15
36
|
acp?: AcpCommands;
|
|
37
|
+
summary?: WorkspaceSummaryConfig;
|
|
38
|
+
history?: WorkspaceHistoryConfig;
|
|
16
39
|
}
|
|
17
40
|
export interface WorkspaceConfiguration {
|
|
18
41
|
path: string;
|
|
@@ -21,4 +44,6 @@ export interface WorkspaceConfiguration {
|
|
|
21
44
|
error?: string;
|
|
22
45
|
features?: WorkspaceFeatures;
|
|
23
46
|
acp?: AcpCommands;
|
|
47
|
+
summary?: WorkspaceSummaryConfig;
|
|
48
|
+
history?: WorkspaceHistoryConfig;
|
|
24
49
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { requireThat } from "./common/validation.js";
|
|
4
|
-
import { runPluginHost } from "./extension/plugin-runtime.js";
|
|
5
|
-
import { listPluginHosts, pluginHosts } from "./integrations/hosts/registry.js";
|
|
4
|
+
import { runPluginHost } from "./extension/hosts/plugin-runtime.js";
|
|
5
|
+
import { listPluginHosts, pluginHosts } from "./integrations/hosts/plugin-registry.js";
|
|
6
6
|
export async function main(args) {
|
|
7
7
|
const [host, ...rest] = args;
|
|
8
8
|
const adapter = host ? pluginHosts.get(host) : undefined;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HistoryHost } from "../../model/history.js";
|
|
2
|
+
import type { HistoryCapture } from "../../model/plugin-host.js";
|
|
3
|
+
/** Persist a host raw history observation atomically into .pbot/history/raw/. */
|
|
4
|
+
export declare function recordHistoryCapture(root: string, host: HistoryHost, capture: HistoryCapture): void;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { HistoryFiles } from "../../storage/history-files.js";
|
|
5
|
+
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
6
|
+
import { indexHistory, orderedRawExchanges } from "./history-index.js";
|
|
7
|
+
function orderedExchanges(raw) {
|
|
8
|
+
if (!raw)
|
|
9
|
+
return [];
|
|
10
|
+
return orderedRawExchanges(raw).map(({ entryIds, text, from, to, completed }) => ({
|
|
11
|
+
entryIds: [...entryIds],
|
|
12
|
+
text,
|
|
13
|
+
from,
|
|
14
|
+
to,
|
|
15
|
+
completed,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
function replaceAssistantSuffix(text, assistantText) {
|
|
19
|
+
const marker = "\n\n助手:\n";
|
|
20
|
+
const index = text.lastIndexOf(marker);
|
|
21
|
+
if (index >= 0)
|
|
22
|
+
return text.slice(0, index) + marker + assistantText;
|
|
23
|
+
return text ? `${text}${marker}${assistantText}` : `助手:\n${assistantText}`;
|
|
24
|
+
}
|
|
25
|
+
function buildSession(host, capture, previous) {
|
|
26
|
+
if (capture.kind === "session") {
|
|
27
|
+
return capture.session.branches.length ? capture.session : undefined;
|
|
28
|
+
}
|
|
29
|
+
const timestamp = capture.timestamp ?? new Date().toISOString();
|
|
30
|
+
const branch = orderedExchanges(previous);
|
|
31
|
+
if (capture.kind === "input") {
|
|
32
|
+
const text = capture.text.trim();
|
|
33
|
+
if (!text)
|
|
34
|
+
return undefined;
|
|
35
|
+
const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
36
|
+
branch.push({
|
|
37
|
+
entryIds: [entryId],
|
|
38
|
+
text: "用户:\n" + text,
|
|
39
|
+
from: timestamp,
|
|
40
|
+
to: timestamp,
|
|
41
|
+
completed: false,
|
|
42
|
+
});
|
|
43
|
+
return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
|
|
44
|
+
}
|
|
45
|
+
const assistantText = capture.assistantText.trim();
|
|
46
|
+
if (!assistantText)
|
|
47
|
+
return undefined;
|
|
48
|
+
const last = branch.at(-1);
|
|
49
|
+
if (last && (!last.completed || capture.isContinuation)) {
|
|
50
|
+
last.text = replaceAssistantSuffix(last.text, assistantText);
|
|
51
|
+
last.to = timestamp;
|
|
52
|
+
last.completed = capture.completed;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
56
|
+
const userText = capture.userText?.trim();
|
|
57
|
+
branch.push({
|
|
58
|
+
entryIds: [entryId],
|
|
59
|
+
text: userText ? `用户:\n${userText}\n\n助手:\n${assistantText}` : `助手:\n${assistantText}`,
|
|
60
|
+
from: timestamp,
|
|
61
|
+
to: timestamp,
|
|
62
|
+
completed: capture.completed,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
|
|
66
|
+
}
|
|
67
|
+
/** Persist a host raw history observation atomically into .pbot/history/raw/. */
|
|
68
|
+
export function recordHistoryCapture(root, host, capture) {
|
|
69
|
+
const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
|
|
70
|
+
if (!sessionId)
|
|
71
|
+
return;
|
|
72
|
+
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
73
|
+
const files = new HistoryFiles(join(root, ".pbot/history"), host, layout);
|
|
74
|
+
files.control(() => {
|
|
75
|
+
const previous = files.listRaw(host).find(raw => raw.sessionId === sessionId);
|
|
76
|
+
if (!previous && files.rawWarnings.length)
|
|
77
|
+
return;
|
|
78
|
+
const session = buildSession(host, capture, previous);
|
|
79
|
+
if (!session || !session.branches.length)
|
|
80
|
+
return;
|
|
81
|
+
const raw = indexHistory(session, previous, host);
|
|
82
|
+
if (isDeepStrictEqual(raw, previous))
|
|
83
|
+
return;
|
|
84
|
+
files.saveRaw(raw);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
|
|
2
|
+
/** Merge a native session observation into its raw archive without modifying persisted order invariants. */
|
|
3
|
+
export declare function indexHistory(session: HistorySession, previous?: RawHistory, host?: HistoryHost): RawHistory;
|
|
4
|
+
/** Return deduplicated exchanges in conversation order (branch order first, then any unbranched entries by timestamp). */
|
|
5
|
+
export declare function orderedRawExchanges(raw: RawHistory): (HistoryExchange & {
|
|
6
|
+
id: string;
|
|
7
|
+
})[];
|
|
8
|
+
export declare function rawSessionTitle(raw: RawHistory): string;
|
|
9
|
+
export declare function rawSessionSpan(exchanges: readonly HistoryExchange[]): {
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
completed: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Stable SHA-256 fingerprint over ordered exchange contents for exact deduplication and prefix matching. */
|
|
15
|
+
export declare function fingerprintExchanges(exchanges: readonly (HistoryExchange & {
|
|
16
|
+
id: string;
|
|
17
|
+
})[]): string;
|