personal-bot 0.3.2 → 0.3.4
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 +2 -1
- package/DISCLAIMER.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -5
- package/README.zh-CN.md +15 -5
- package/bin/pbot-pi-acp.mjs +1 -1
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +2 -0
- package/docs/architecture/design.md +16 -16
- package/docs/architecture/extensibility.md +29 -2
- package/docs/architecture/model-context.md +3 -2
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/capabilities.md +1 -1
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +30 -7
- package/docs/guides/workspace-configuration.md +20 -3
- package/docs/hosts/antigravity.md +1 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/maintainers/architecture-governance.md +78 -0
- package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
- package/lib/antigravity-plugin/LICENSE +21 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
- package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/common/files.js +44 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
- package/lib/antigravity-plugin/lib/model/acp.js +8 -0
- package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
- package/lib/antigravity-plugin/lib/model/agent.js +4 -0
- package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -1
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
- package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
- package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
- package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
- package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
- package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
- package/lib/client.js +22 -50
- package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
- package/lib/common/validation.d.ts +4 -0
- package/lib/common/validation.js +8 -0
- package/lib/dsh.js +2 -2
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp-worker.js +71 -45
- package/lib/extension/history/command.d.ts +37 -0
- package/lib/extension/history/command.js +57 -0
- package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/extension/hosts/dsh/acp-member.js +4 -18
- package/lib/extension/hosts/dsh/command.d.ts +1 -2
- package/lib/extension/hosts/dsh/command.js +5 -49
- package/lib/extension/hosts/dsh/workspace.js +13 -44
- package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/extension/mcp/bridge.d.ts +6 -8
- package/lib/extension/mcp/bridge.js +66 -84
- package/lib/extension/mcp/tool-contract.d.ts +735 -0
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +29 -742
- package/lib/extension/mcp/workers.js +75 -525
- package/lib/extension/mcp.js +2577 -2255
- package/lib/extension/setup/cli.js +15 -0
- package/lib/extension/setup/upgrade.js +153 -0
- package/lib/extension/workspace-cli.js +20171 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.js +2 -1
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.js +1 -1
- package/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/integrations/installation/cli-update.js +146 -0
- package/lib/integrations/installation/upgraders/antigravity.js +67 -0
- package/lib/integrations/installation/upgraders/claude.js +123 -0
- package/lib/integrations/installation/upgraders/codex.js +73 -0
- package/lib/integrations/installation/upgraders/dsh.js +62 -0
- package/lib/integrations/installation/upgraders/pi.js +90 -0
- package/lib/integrations/installation/upgraders/qoder.js +67 -0
- package/lib/integrations/installation/upgraders/registry.js +40 -0
- package/lib/model/acp.d.ts +7 -3
- package/lib/model/acp.js +8 -0
- package/lib/model/agent.d.ts +18 -4
- package/lib/model/agent.js +4 -1
- package/lib/model/history.d.ts +10 -0
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +5 -0
- package/lib/model/workspace-config.d.ts +8 -12
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -2
- package/lib/qoder-plugin/.mcp.json +17 -0
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
- package/lib/qoder-plugin/DISCLAIMER.md +17 -0
- package/lib/qoder-plugin/LICENSE +21 -0
- package/lib/qoder-plugin/hooks/hooks.json +37 -0
- package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
- package/lib/services/agents/agent-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.js +34 -22
- package/lib/services/history/history-migrate.js +26 -60
- package/lib/services/history/history-query.js +38 -57
- package/lib/services/history/summary-command.d.ts +1 -1
- package/lib/services/history/summary-command.js +8 -7
- package/lib/services/history/summary-registry.js +2 -3
- package/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/services/history/summary-runner.js +72 -74
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/installation/setup-service.js +4 -1
- package/lib/services/installation/upgrade-service.js +95 -0
- package/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/services/workspace/workspace-config.js +9 -8
- package/lib/services/workspace/workspace-mcp.js +22 -29
- package/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/storage/acp-files.js +7 -12
- package/lib/storage/agent-files.js +6 -5
- package/lib/storage/atomic-json.d.ts +3 -1
- package/lib/storage/atomic-json.js +43 -3
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +21 -15
- package/lib/storage/history-format.d.ts +2 -3
- package/lib/storage/history-format.js +5 -7
- package/lib/tools/history/contract.d.ts +3 -11
- package/lib/tools/history/contract.js +8 -7
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +9 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +5 -33
- package/package.json +4 -1
- package/resources/antigravity/skills/pbot/SKILL.md +11 -1
- package/resources/claude/skills/pbot/SKILL.md +11 -1
- package/resources/plugin/skills/pbot/SKILL.md +9 -0
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/scripts/README.md +3 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +2 -2
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/hosts/dsh/acp-member.ts +4 -15
- package/src/extension/hosts/dsh/command.ts +6 -46
- package/src/extension/hosts/dsh/workspace.ts +12 -38
- package/src/extension/hosts/pi/acp-member.ts +4 -10
- package/src/extension/hosts/pi/command.ts +14 -63
- package/src/extension/hosts/pi/events.ts +2 -8
- package/src/extension/hosts/pi/lifecycle.ts +3 -2
- package/src/extension/hosts/plugin-runtime.ts +39 -19
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/mcp/bridge.ts +80 -80
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/mcp/workers.ts +81 -551
- package/src/extension/setup/cli.ts +11 -1
- package/src/extension/setup/upgrade.ts +158 -0
- package/src/extension/setup/workspace-cli.ts +167 -0
- package/src/integrations/acp/agents.ts +2 -3
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +2 -1
- package/src/integrations/agent-resources.ts +1 -1
- package/src/integrations/hosts/claude/adapter.ts +7 -53
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/hosts/plugin-registry.ts +9 -1
- package/src/integrations/hosts/prompt-hooks.ts +72 -0
- package/src/integrations/hosts/qoder/adapter.ts +19 -0
- package/src/integrations/installation/cli-update.ts +144 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/integrations/installation/processes.ts +1 -1
- package/src/integrations/installation/upgraders/antigravity.ts +68 -0
- package/src/integrations/installation/upgraders/claude.ts +123 -0
- package/src/integrations/installation/upgraders/codex.ts +73 -0
- package/src/integrations/installation/upgraders/dsh.ts +63 -0
- package/src/integrations/installation/upgraders/pi.ts +87 -0
- package/src/integrations/installation/upgraders/qoder.ts +68 -0
- package/src/integrations/installation/upgraders/registry.ts +48 -0
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +86 -0
- package/src/model/plugin-host.ts +5 -1
- package/src/model/workspace-config.ts +6 -12
- package/src/pbot.ts +13 -32
- package/src/plugin.ts +3 -3
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +30 -22
- package/src/services/history/history-migrate.ts +23 -50
- package/src/services/history/history-query.ts +34 -48
- package/src/services/history/summary-command.ts +9 -8
- package/src/services/history/summary-registry.ts +2 -3
- package/src/services/history/summary-runner.ts +72 -81
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +9 -43
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +121 -0
- package/src/services/workspace/workspace-config.ts +9 -8
- package/src/services/workspace/workspace-mcp.ts +23 -28
- package/src/services/workspace/workspace-skills.ts +5 -2
- package/src/storage/acp-files.ts +7 -12
- package/src/storage/agent-files.ts +6 -5
- package/src/storage/atomic-json.ts +31 -4
- package/src/storage/history-files.ts +22 -15
- package/src/storage/history-format.ts +6 -8
- package/src/tools/history/contract.ts +9 -9
- package/src/tools/history/pi-tool.ts +6 -4
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +10 -10
- package/src/ui/dsh/styles.ts +5 -33
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/tools/access.ts +0 -7
- package/src/tools/register.ts +0 -21
- package/src/ui/presentation.ts +0 -12
|
@@ -2,11 +2,11 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmdirSync, unlinkSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { isDeepStrictEqual } from "node:util";
|
|
5
|
-
import { requireThat } from "../common/validation.js";
|
|
5
|
+
import { isHistoryIdentifier, requireThat } from "../common/validation.js";
|
|
6
6
|
import type { HistoryHost, HistoryLayout, RawHistory, SummaryArtifact } from "../model/history.js";
|
|
7
7
|
import { internalPath, readJsonFile, syncDirectory, writeJsonFile } from "./atomic-json.js";
|
|
8
8
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
9
|
-
import {
|
|
9
|
+
import { matchIdentity, rawHistory, summaryArtifact } from "./history-format.js";
|
|
10
10
|
|
|
11
11
|
const yearPattern = /^\d{4}$/;
|
|
12
12
|
const monthPattern = /^(?:0[1-9]|1[0-2])$/;
|
|
@@ -243,7 +243,7 @@ export class HistoryFiles {
|
|
|
243
243
|
readonly host: HistoryHost = "pi",
|
|
244
244
|
readonly layout: HistoryLayout = "monthly",
|
|
245
245
|
) {
|
|
246
|
-
requireThat(
|
|
246
|
+
requireThat(isHistoryIdentifier(host), "历史来源无效。");
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
get warnings(): readonly string[] { return this.#warnings; }
|
|
@@ -252,7 +252,7 @@ export class HistoryFiles {
|
|
|
252
252
|
get rawDirectory(): string { return join(this.directory, "raw"); }
|
|
253
253
|
get summariesDirectory(): string { return join(this.directory, "summaries"); }
|
|
254
254
|
summaryDirectory(dimension: string): string {
|
|
255
|
-
requireThat(
|
|
255
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
256
256
|
return join(this.summariesDirectory, dimension);
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -276,7 +276,7 @@ export class HistoryFiles {
|
|
|
276
276
|
|
|
277
277
|
/** Synchronous dimension write lock for derived summary files. */
|
|
278
278
|
controlSummary<T>(dimension: string, operation: () => T): T {
|
|
279
|
-
requireThat(
|
|
279
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
280
280
|
return this.withLock(".write-summary-" + dimension, "summary:" + dimension, operation);
|
|
281
281
|
}
|
|
282
282
|
|
|
@@ -285,6 +285,10 @@ export class HistoryFiles {
|
|
|
285
285
|
return this.withLock(".write-migrate", "migrate", operation);
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
migrationNotice(): string | undefined {
|
|
289
|
+
return this.layout === "monthly" ? this.detectFlatFiles().message : undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
288
292
|
/** Detect unmigrated top-level flat JSON files when running under monthly layout. */
|
|
289
293
|
detectFlatFiles(): FlatHistoryInventory {
|
|
290
294
|
if (!sharedDirectory(this.directory)) return { rawCount: 0, summaryCount: 0, total: 0 };
|
|
@@ -302,7 +306,7 @@ export class HistoryFiles {
|
|
|
302
306
|
total,
|
|
303
307
|
message:
|
|
304
308
|
`检测到 ${total} 个未迁移的平铺历史文件(raw ${rawCount},summaries ${summaryCount});当前为年月目录布局(history.layout: monthly),未迁移文件不会被读取。` +
|
|
305
|
-
|
|
309
|
+
`请在终端运行 pbot history migrate 整理到 YYYY/MM/ 目录(Pi/dsh 可用 /pbot history migrate),或在 .pbot/config.json 中设置 "history": { "layout": "flat" } 切回平铺布局。`,
|
|
306
310
|
};
|
|
307
311
|
}
|
|
308
312
|
|
|
@@ -312,7 +316,7 @@ export class HistoryFiles {
|
|
|
312
316
|
}
|
|
313
317
|
|
|
314
318
|
listFlatSummaryFiles(dimension: string): string[] {
|
|
315
|
-
requireThat(
|
|
319
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
316
320
|
const dir = this.summaryDirectory(dimension);
|
|
317
321
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return [];
|
|
318
322
|
return topLevelJsonNames(dir);
|
|
@@ -323,14 +327,17 @@ export class HistoryFiles {
|
|
|
323
327
|
}
|
|
324
328
|
|
|
325
329
|
readFlatSummaryFile(dimension: string, name: string): SummaryArtifact {
|
|
326
|
-
requireThat(
|
|
330
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
327
331
|
return readJsonFile(this.directory, `summaries/${dimension}/${name}`, value => namedSummary(value, name, dimension));
|
|
328
332
|
}
|
|
329
333
|
|
|
330
334
|
/** Atomically move a file within .pbot/history/ without ever overwriting an existing destination. */
|
|
331
|
-
moveHistoryFile(fromRelative: string, toRelative: string): "moved" | "conflict" {
|
|
332
|
-
ensureDirectory(this.directory);
|
|
335
|
+
moveHistoryFile(fromRelative: string, toRelative: string, dryRun = false): "moved" | "conflict" {
|
|
333
336
|
const src = internalPath(this.directory, fromRelative);
|
|
337
|
+
if (dryRun) {
|
|
338
|
+
const target = internalPath(this.directory, toRelative, true);
|
|
339
|
+
return ordinaryFile(target) ? "conflict" : "moved";
|
|
340
|
+
}
|
|
334
341
|
const dstParentRel = dirname(toRelative);
|
|
335
342
|
if (dstParentRel && dstParentRel !== ".") {
|
|
336
343
|
privateDirectory(this.directory, dstParentRel);
|
|
@@ -342,8 +349,8 @@ export class HistoryFiles {
|
|
|
342
349
|
if ((error as NodeJS.ErrnoException).code === "EEXIST") return "conflict";
|
|
343
350
|
throw error;
|
|
344
351
|
}
|
|
345
|
-
unlinkSync(src);
|
|
346
352
|
syncDirectory(dirname(dst));
|
|
353
|
+
unlinkSync(src);
|
|
347
354
|
syncDirectory(dirname(src));
|
|
348
355
|
return "moved";
|
|
349
356
|
}
|
|
@@ -380,7 +387,7 @@ export class HistoryFiles {
|
|
|
380
387
|
}
|
|
381
388
|
|
|
382
389
|
saveRaw(raw: RawHistory) {
|
|
383
|
-
requireThat(
|
|
390
|
+
requireThat(isHistoryIdentifier(raw.host) && raw.host === this.host, "历史归档只允许所属来源写入。");
|
|
384
391
|
rawHistory(raw);
|
|
385
392
|
ensureDirectory(this.directory);
|
|
386
393
|
const name = filename(raw.id);
|
|
@@ -403,7 +410,7 @@ export class HistoryFiles {
|
|
|
403
410
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory)) return [];
|
|
404
411
|
const entries = readdirSync(this.summariesDirectory, { withFileTypes: true });
|
|
405
412
|
return entries
|
|
406
|
-
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() &&
|
|
413
|
+
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() && isHistoryIdentifier(entry.name))
|
|
407
414
|
.map(entry => entry.name)
|
|
408
415
|
.sort();
|
|
409
416
|
}
|
|
@@ -413,7 +420,7 @@ export class HistoryFiles {
|
|
|
413
420
|
}
|
|
414
421
|
|
|
415
422
|
listSummaries(dimension: string, onlyFiles?: readonly string[]): SummaryArtifact[] {
|
|
416
|
-
requireThat(
|
|
423
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
417
424
|
const dir = this.summaryDirectory(dimension);
|
|
418
425
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return [];
|
|
419
426
|
const files = onlyFiles ?? listLayoutJsonFiles(dir, this.layout, this.summaryBucketDepth(dimension));
|
|
@@ -432,7 +439,7 @@ export class HistoryFiles {
|
|
|
432
439
|
}
|
|
433
440
|
|
|
434
441
|
readSummary(dimension: string, id: string): SummaryArtifact | undefined {
|
|
435
|
-
requireThat(
|
|
442
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
436
443
|
const dir = this.summaryDirectory(dimension);
|
|
437
444
|
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir)) return undefined;
|
|
438
445
|
const name = filename(id);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { object } from "../common/json.js";
|
|
2
|
-
import { requireThat } from "../common/validation.js";
|
|
3
|
-
import type { HistoryExchange,
|
|
2
|
+
import { isHistoryIdentifier, requireThat } from "../common/validation.js";
|
|
3
|
+
import type { HistoryExchange, HistoryIdentity, RawHistory, SummaryArtifact } from "../model/history.js";
|
|
4
4
|
import { fileId } from "./file-access.js";
|
|
5
5
|
|
|
6
6
|
const strings = (value: unknown): value is string[] => Array.isArray(value) && value.every(item => typeof item === "string");
|
|
@@ -11,13 +11,11 @@ const exchangeFields = ["id", "entryIds", "text", "from", "to", "completed"];
|
|
|
11
11
|
const summaryArtifactFields = ["id", "dimension", "host", "sessionId", "title", "text", "from", "to", "updatedAt", "source"];
|
|
12
12
|
const summarySourceFields = ["rawIds", "exchangeIds", "fingerprint"];
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
export const isHistoryHost = (value: unknown): value is HistoryHost => typeof value === "string" && identifierPattern.test(value);
|
|
16
|
-
export const isSummaryDimension = (value: unknown): value is string => typeof value === "string" && identifierPattern.test(value);
|
|
14
|
+
export { isHistoryIdentifier as isHistoryHost, isHistoryIdentifier as isSummaryDimension } from "../common/validation.js";
|
|
17
15
|
|
|
18
16
|
function identity(value: unknown): asserts value is HistoryIdentity {
|
|
19
17
|
requireThat(
|
|
20
|
-
object(value) &&
|
|
18
|
+
object(value) && isHistoryIdentifier(value.host) && typeof value.id === "string" &&
|
|
21
19
|
typeof value.sessionId === "string" && value.sessionId.length > 0,
|
|
22
20
|
"历史归档身份无效。",
|
|
23
21
|
);
|
|
@@ -61,11 +59,11 @@ export function summaryArtifact(value: unknown, expectedDimension?: string): Sum
|
|
|
61
59
|
requireThat(object(value) && fields(value, summaryArtifactFields), "历史摘要产物格式无效。");
|
|
62
60
|
requireThat(typeof value.id === "string" && value.id.length > 0, "历史摘要 ID 无效。");
|
|
63
61
|
fileId(value.id);
|
|
64
|
-
requireThat(
|
|
62
|
+
requireThat(isHistoryIdentifier(value.dimension), "历史摘要维度无效。");
|
|
65
63
|
if (expectedDimension !== undefined) {
|
|
66
64
|
requireThat(value.dimension === expectedDimension, `历史摘要维度不匹配,预期 ${expectedDimension},实际 ${value.dimension}。`);
|
|
67
65
|
}
|
|
68
|
-
if (value.host !== undefined) requireThat(
|
|
66
|
+
if (value.host !== undefined) requireThat(isHistoryIdentifier(value.host), "历史摘要来源 host 无效。");
|
|
69
67
|
if (value.sessionId !== undefined) requireThat(typeof value.sessionId === "string" && value.sessionId.length > 0, "历史摘要 sessionId 无效。");
|
|
70
68
|
requireThat(
|
|
71
69
|
typeof value.title === "string" && typeof value.text === "string" && value.text.trim().length > 0 &&
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
import type
|
|
3
|
-
import { requireThat } from "../../common/validation.js";
|
|
2
|
+
import { historyPageLimits, type HistoryHost, type HistoryQuery } from "../../model/history.js";
|
|
3
|
+
import { historyIdentifierPattern, requireThat } from "../../common/validation.js";
|
|
4
4
|
import { schema } from "../../common/schema.js";
|
|
5
5
|
import { inputObject, need, nullable, pick } from "../input.js";
|
|
6
6
|
|
|
7
|
-
const identifier = Type.String({ pattern:
|
|
7
|
+
const identifier = Type.String({ pattern: historyIdentifierPattern.source });
|
|
8
8
|
const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
|
|
9
9
|
const node = Type.Object({
|
|
10
10
|
host: identifier,
|
|
@@ -58,20 +58,20 @@ export const historyParameters = Type.Object({
|
|
|
58
58
|
action: Type.Union([Type.Literal("search"), Type.Literal("read")], {
|
|
59
59
|
description: "search 搜索或列会话;read 读取指定节点正文与上下级。各动作仅读取自身字段,其余字段忽略。",
|
|
60
60
|
}),
|
|
61
|
-
host: nullable(Type.String({ pattern:
|
|
62
|
-
dimension: nullable(Type.String({ pattern:
|
|
61
|
+
host: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "可选来源筛选(如 pi、dsh、claude、antigravity)。" })),
|
|
62
|
+
dimension: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "仅 search:可选范围筛选(raw 表示仅原文,或指定摘要维度如 monthly、session;省略查全部)。" })),
|
|
63
63
|
query: nullable(Type.String({ description: "仅 search:不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。" })),
|
|
64
64
|
sessionId: nullable(Type.String({ description: "仅 search:限定在指定会话 ID 内搜索。" })),
|
|
65
65
|
from: nullable(Type.String({ description: "仅 search:ISO 日期或时间下界。" })),
|
|
66
66
|
to: nullable(Type.String({ description: "仅 search:ISO 日期或时间上界。" })),
|
|
67
67
|
id: nullable(Type.String({ description: "仅 read,必填:search 或上下级返回的节点 id。" })),
|
|
68
68
|
offset: nullable(Type.Integer({ minimum: 0, description: "search:匹配结果偏移;read:正文字符偏移。默认 0。" })),
|
|
69
|
-
limit: nullable(Type.Integer({ minimum: 1, maximum:
|
|
69
|
+
limit: nullable(Type.Integer({ minimum: 1, maximum: historyPageLimits.read.max, description: `search:最多返回条数(默认 ${historyPageLimits.search.default},上限 ${historyPageLimits.search.max});read:正文字符数(默认 ${historyPageLimits.read.default})。` })),
|
|
70
70
|
childrenOffset: nullable(Type.Integer({ minimum: 0, description: "仅 read:子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。" })),
|
|
71
71
|
}, { additionalProperties: false });
|
|
72
72
|
|
|
73
73
|
export type HistoryInput =
|
|
74
|
-
| { action: "search"
|
|
74
|
+
| ({ action: "search" } & HistoryQuery)
|
|
75
75
|
| { action: "read"; id: string; host?: HistoryHost; offset?: number; limit?: number; childrenOffset?: number };
|
|
76
76
|
|
|
77
77
|
const valid = schema(historyParameters);
|
|
@@ -79,8 +79,8 @@ const valid = schema(historyParameters);
|
|
|
79
79
|
export function historyInput(value: unknown): HistoryInput {
|
|
80
80
|
const args = inputObject(value, valid, "历史参数格式无效");
|
|
81
81
|
if (args.action === "search") {
|
|
82
|
-
const limit = args.limit === undefined ?
|
|
83
|
-
requireThat(limit <=
|
|
82
|
+
const limit = args.limit === undefined ? historyPageLimits.search.default : args.limit as number;
|
|
83
|
+
requireThat(limit <= historyPageLimits.search.max, `search 的 limit 最多 ${historyPageLimits.search.max}。`);
|
|
84
84
|
return {
|
|
85
85
|
action: "search",
|
|
86
86
|
...(pick(args, ["host", "dimension", "query", "sessionId", "from", "to", "offset", "limit"]) as
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { CallAccess } from "../access.js";
|
|
1
|
+
import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
2
|
import { markdownResult } from "../result.js";
|
|
4
3
|
import { historyDescription, historyInput, historyParameters, historyResultSchema } from "./contract.js";
|
|
5
4
|
import { executeHistory } from "./actions.js";
|
|
6
5
|
|
|
7
|
-
export function
|
|
8
|
-
|
|
6
|
+
export function registerPiHistoryTool(pi: ExtensionAPI, root: string, access: { check(): void }) {
|
|
7
|
+
const tool = defineTool({
|
|
8
|
+
namespace: { name: "pbot", description: "工作区历史查询。" },
|
|
9
9
|
name: "pbot_history",
|
|
10
10
|
label: "历史对话",
|
|
11
11
|
description: historyDescription,
|
|
@@ -18,4 +18,6 @@ export function historyTool(root: string, access: CallAccess) {
|
|
|
18
18
|
return markdownResult(result, args.action === "search" ? "历史搜索" : "历史正文");
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
|
+
pi.registerTool(tool);
|
|
22
|
+
return () => pi.registerTool({ ...tool, exposure: "hidden" });
|
|
21
23
|
}
|
package/src/ui/dsh/elements.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { object } from "../../common/json.js";
|
|
2
|
-
import { stateLabel } from "../presentation.js";
|
|
3
2
|
|
|
4
3
|
export const record = (value: unknown): Record<string, unknown> => { if (!object(value)) throw new Error("管理数据无效。"); return value; };
|
|
5
4
|
export const rows = (value: unknown) => Array.isArray(value) ? value.map(record) : [];
|
|
6
5
|
export const text = (value: unknown) => value === null || value === undefined ? "" : String(value);
|
|
7
|
-
export const objectInput = (value: string) => record(JSON.parse(value || "{}"));
|
|
8
|
-
export const lines = (value: string) => value.split(/\r?\n/).map(item => item.trim()).filter(Boolean);
|
|
9
6
|
|
|
10
7
|
export function element<K extends keyof HTMLElementTagNameMap>(tag: K, content = "", className = "") {
|
|
11
8
|
const node = document.createElement(tag); node.textContent = content; node.className = className; return node;
|
|
@@ -18,10 +15,9 @@ export function group(parent: HTMLElement, className = "pbot-stack") {
|
|
|
18
15
|
export function details(parent: HTMLElement, title: string) {
|
|
19
16
|
const node = element("details", "", "pbot-disclosure"); node.append(element("summary", title)); parent.append(node); return node;
|
|
20
17
|
}
|
|
21
|
-
export function field(parent: HTMLElement, label: string
|
|
22
|
-
const wrapper = element("label", "", "pbot-field"), input =
|
|
23
|
-
wrapper.append(element("span", label)); input.
|
|
24
|
-
if (input instanceof HTMLTextAreaElement) input.rows = 3;
|
|
18
|
+
export function field(parent: HTMLElement, label: string) {
|
|
19
|
+
const wrapper = element("label", "", "pbot-field"), input = element("input");
|
|
20
|
+
wrapper.append(element("span", label)); input.setAttribute("aria-label", label);
|
|
25
21
|
wrapper.append(input); parent.append(wrapper); return input;
|
|
26
22
|
}
|
|
27
23
|
export function select(parent: HTMLElement, label: string, values: [string, string][]) {
|
|
@@ -30,9 +26,6 @@ export function select(parent: HTMLElement, label: string, values: [string, stri
|
|
|
30
26
|
for (const [value, title] of values) { const option = element("option", title); option.value = value; input.append(option); }
|
|
31
27
|
wrapper.append(input); parent.append(wrapper); return input;
|
|
32
28
|
}
|
|
33
|
-
export function badge(state: unknown) {
|
|
34
|
-
const node = element("span", stateLabel(state), "pbot-badge"); node.dataset.state = text(state); return node;
|
|
35
|
-
}
|
|
36
29
|
export function facts(values: [string, unknown][]) {
|
|
37
30
|
const node = element("dl", "", "pbot-facts");
|
|
38
31
|
for (const [label, value] of values) node.append(element("dt", label), element("dd", text(value) || "—"));
|
|
@@ -41,8 +34,8 @@ export function facts(values: [string, unknown][]) {
|
|
|
41
34
|
export function empty(title: string, description: string) {
|
|
42
35
|
const node = element("div", "", "pbot-empty"); node.append(element("h3", title), note(description)); return node;
|
|
43
36
|
}
|
|
44
|
-
export function pageTitle(parent: HTMLElement, title: string
|
|
45
|
-
const node = element("header", "", "pbot-page-title"); node.append(element("h2", title));
|
|
37
|
+
export function pageTitle(parent: HTMLElement, title: string) {
|
|
38
|
+
const node = element("header", "", "pbot-page-title"); node.append(element("h2", title)); parent.append(node); return node;
|
|
46
39
|
}
|
|
47
40
|
export function time(value: unknown) {
|
|
48
41
|
const date = new Date(typeof value === "number" ? value : text(value));
|
package/src/ui/dsh/management.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type {} from "@deepseek-ai/dsh-api-remotes/client";
|
|
3
3
|
import type { SessionId } from "@deepseek-ai/dsh-session/types";
|
|
4
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
4
5
|
import { object, json } from "../../common/json.js";
|
|
5
6
|
import { block, details, element, empty, facts, field, group, note, pageTitle, record, rows, select, text, time } from "./elements.js";
|
|
6
7
|
import { managementStyles } from "./styles.js";
|
|
@@ -72,29 +73,28 @@ export function showManagement(ctx: Context, parentSessionId: SessionId) {
|
|
|
72
73
|
if (!result.ok) throw new Error(result.error.message);
|
|
73
74
|
lifetime.signal.throwIfAborted(); return record(result.value);
|
|
74
75
|
}
|
|
75
|
-
async function
|
|
76
|
-
const result = await ctx.remote.commands.execute(parentSessionId, "/pbot "
|
|
76
|
+
async function initializeWorkspace() {
|
|
77
|
+
const result = await ctx.remote.commands.execute(parentSessionId, "/pbot init", []);
|
|
77
78
|
if (!result.ok) throw new Error(result.error.message + ";如连接中断,请先刷新记录确认操作是否已接纳。");
|
|
78
79
|
if (!result.value) throw new Error("管理命令未被接纳。");
|
|
79
80
|
if (result.value.result.kind === "error") throw new Error(result.value.result.text);
|
|
80
|
-
inform(
|
|
81
|
+
inform("工作区已初始化并启用。");
|
|
81
82
|
if (!closed) { try { await refresh(); } catch (error) { inform("操作已接纳;刷新状态未成功:" + String(error), "error"); } }
|
|
82
|
-
return result.value.result.text ?? "";
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
const status = section("status", "工作区"); pageTitle(status, "工作区"
|
|
85
|
+
const status = section("status", "工作区"); pageTitle(status, "工作区");
|
|
86
86
|
const counts = note(""), workspaceInfo = group(status); status.querySelector("header")!.after(counts); counts.classList.add("pbot-counts");
|
|
87
87
|
const materials = group(status, "pbot-setting"); materials.append(element("h3", "资料目录"));
|
|
88
|
-
const initializeButton = button(materials, "准备目录",
|
|
88
|
+
const initializeButton = button(materials, "准备目录", initializeWorkspace);
|
|
89
89
|
const diagnostic = details(status, "环境详情"), statusBody = block(""); statusBody.classList.add("pbot-raw"); diagnostic.append(statusBody);
|
|
90
90
|
|
|
91
|
-
const history = section("history", "历史"); pageTitle(history, "历史"
|
|
91
|
+
const history = section("history", "历史"); pageTitle(history, "历史");
|
|
92
92
|
const searchForm = form(history); searchForm.className = "pbot-search";
|
|
93
|
-
const historyQuery = field(searchForm, "关键词"), host = select(searchForm, "来源", [["", "全部"], ["pi", "Pi"], ["dsh", "dsh"], ["claude", "Claude Code"], ["antigravity", "Antigravity"]]);
|
|
93
|
+
const historyQuery = field(searchForm, "关键词"), host = select(searchForm, "来源", [["", "全部"], ["pi", "Pi"], ["dsh", "dsh"], ["claude", "Claude Code"], ["antigravity", "Antigravity"], ["codex", "Codex"], ["qoder", "Qoder CLI"]]);
|
|
94
94
|
historyQuery.placeholder = "留空查看最近会话"; submit(searchForm, "查询", () => searchHistory());
|
|
95
95
|
const dateFilters = details(history, "时间范围"), dateGrid = group(dateFilters, "pbot-grid");
|
|
96
96
|
const historyFrom = field(dateGrid, "开始时间"), historyTo = field(dateGrid, "结束时间");
|
|
97
|
-
for (const input of [historyFrom, historyTo])
|
|
97
|
+
for (const input of [historyFrom, historyTo]) input.type = "datetime-local";
|
|
98
98
|
const historyBody = group(history, "pbot-history-results"), historyPaging = group(history, "pbot-pagination"), historyNode = group(history, "pbot-card"); historyNode.hidden = true;
|
|
99
99
|
historyBody.append(empty("查询历史", "输入关键词,或留空查看最近会话。"));
|
|
100
100
|
let historySearch: Record<string, unknown> = {};
|
|
@@ -119,7 +119,7 @@ export function showManagement(ctx: Context, parentSessionId: SessionId) {
|
|
|
119
119
|
button(item, "读取", () => readHistory(text(match.id), text(match.host)), "pbot-quiet"); historyBody.append(item);
|
|
120
120
|
}
|
|
121
121
|
if (!rows(data.matches).length) historyBody.append(empty("没有找到匹配内容", "试试更短的关键词,或调整来源和时间范围。"));
|
|
122
|
-
if (offset) button(historyPaging, "上一页", () => searchHistory(Math.max(0, offset -
|
|
122
|
+
if (offset) button(historyPaging, "上一页", () => searchHistory(Math.max(0, offset - historyPageLimits.search.default), true));
|
|
123
123
|
if (typeof data.nextOffset === "number") button(historyPaging, "下一页", () => searchHistory(data.nextOffset as number, true));
|
|
124
124
|
}
|
|
125
125
|
async function readHistory(id: string, source: string, offset = 0, childrenOffset = 0) {
|
package/src/ui/dsh/styles.ts
CHANGED
|
@@ -20,15 +20,14 @@ export const managementStyles = `
|
|
|
20
20
|
.pbot-management h2 { font-size: 21px; font-weight: 600; }
|
|
21
21
|
.pbot-management h3 { font-size: 16px; font-weight: 600; }
|
|
22
22
|
.pbot-management h4 { font-size: 14px; font-weight: 600; }
|
|
23
|
-
.pbot-management button, .pbot-management input, .pbot-management
|
|
23
|
+
.pbot-management button, .pbot-management input, .pbot-management select { font: inherit; color: inherit; }
|
|
24
24
|
.pbot-management button { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 7px 13px; border: 1px solid var(--pbot-line); border-radius: 8px; background: var(--pbot-surface); cursor: pointer; line-height: 1.4; }
|
|
25
25
|
.pbot-management button:hover:not(:disabled) { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }
|
|
26
26
|
.pbot-management button:disabled { opacity: .45; cursor: not-allowed; }
|
|
27
|
-
.pbot-management :is(button, input,
|
|
27
|
+
.pbot-management :is(button, input, select, summary):focus-visible { outline: 2px solid var(--pbot-accent); outline-offset: 3px; }
|
|
28
28
|
.pbot-management button.pbot-primary { background: var(--pbot-accent); border-color: var(--pbot-accent); color: var(--pbot-surface); font-weight: 600; }
|
|
29
29
|
.pbot-management button.pbot-primary:hover:not(:disabled) { filter: brightness(.94); background: var(--pbot-accent); }
|
|
30
30
|
.pbot-management button.pbot-quiet { border-color: transparent; background: transparent; }
|
|
31
|
-
.pbot-management button.pbot-danger { color: var(--pbot-danger); }
|
|
32
31
|
.pbot-management button[data-busy=true]::after { content: "…"; }
|
|
33
32
|
.pbot-shell { height: 100%; display: grid; grid-template-columns: 178px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
|
|
34
33
|
.pbot-header { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--pbot-line); }
|
|
@@ -39,7 +38,6 @@ export const managementStyles = `
|
|
|
39
38
|
.pbot-nav { display: flex; flex-direction: column; gap: 6px; padding: 22px 12px; background: var(--pbot-bg); border-right: 1px solid var(--pbot-line); }
|
|
40
39
|
.pbot-nav button { text-align: left; justify-content: space-between; border-color: transparent; background: transparent; padding: 11px 12px; color: var(--pbot-muted); }
|
|
41
40
|
.pbot-nav button[aria-selected=true] { color: var(--pbot-accent); background: var(--pbot-tint); font-weight: 600; }
|
|
42
|
-
.pbot-nav small { font-size: 11px; font-variant-numeric: tabular-nums; opacity: .8; }
|
|
43
41
|
.pbot-main { min-width: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 26px 28px; }
|
|
44
42
|
.pbot-page-title { margin-bottom: 22px; display: grid; gap: 5px; }
|
|
45
43
|
.pbot-muted { color: var(--pbot-muted); font-size: 13px; overflow-wrap: anywhere; }
|
|
@@ -50,7 +48,6 @@ export const managementStyles = `
|
|
|
50
48
|
.pbot-notice[data-tone=error] { border-left-color: var(--pbot-danger); }
|
|
51
49
|
.pbot-notice:empty { display: none; }
|
|
52
50
|
.pbot-stack { display: grid; gap: 16px; }
|
|
53
|
-
.pbot-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
|
54
51
|
.pbot-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
|
|
55
52
|
.pbot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
|
|
56
53
|
.pbot-counts { margin: -8px 0 20px !important; }
|
|
@@ -62,10 +59,6 @@ export const managementStyles = `
|
|
|
62
59
|
.pbot-card > :is(h3, .pbot-between) { margin-bottom: 12px; }
|
|
63
60
|
.pbot-badge { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; color: var(--pbot-muted); background: var(--pbot-bg); padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; }
|
|
64
61
|
.pbot-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
|
|
65
|
-
.pbot-badge:is([data-state=busy],[data-state=running],[data-state=starting]) { color: var(--pbot-accent); background: var(--pbot-tint); }
|
|
66
|
-
.pbot-badge:is([data-state=error],[data-state=failed]) { color: var(--pbot-danger); }
|
|
67
|
-
.pbot-badge[data-state=completed] { color: var(--dsw-alias-state-success-primary, #26834b); }
|
|
68
|
-
.pbot-badge:is([data-state=paused],[data-state=stopping]) { color: var(--dsw-alias-state-warn-label, #9a6500); }
|
|
69
62
|
.pbot-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 18px; margin: 12px 0; font-size: 13px; }
|
|
70
63
|
.pbot-facts dt { color: var(--pbot-muted); }
|
|
71
64
|
.pbot-facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
@@ -75,33 +68,15 @@ export const managementStyles = `
|
|
|
75
68
|
.pbot-disclosure .pbot-disclosure { background: var(--pbot-bg); }
|
|
76
69
|
.pbot-field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; font-size: 13px; }
|
|
77
70
|
.pbot-field > span { font-weight: 500; }
|
|
78
|
-
.pbot-field :is(input,
|
|
79
|
-
.pbot-field input
|
|
80
|
-
.pbot-field input::file-selector-button { border: 0; padding: 5px 8px; margin-right: 10px; border-radius: 4px; background: var(--pbot-tint); color: var(--pbot-ink); cursor: pointer; }
|
|
81
|
-
.pbot-field textarea { resize: vertical; min-height: 84px; }
|
|
82
|
-
.pbot-field input::placeholder, .pbot-field textarea::placeholder { color: var(--pbot-muted); opacity: .8; }
|
|
83
|
-
.pbot-split { display: grid; grid-template-columns: minmax(180px, 230px) minmax(0, 1fr); gap: 22px; align-items: start; }
|
|
84
|
-
.pbot-list { display: grid; align-content: start; grid-auto-rows: max-content; gap: 6px; max-height: 470px; overflow-y: auto; padding: 3px; }
|
|
85
|
-
.pbot-management .pbot-list-item { display: block; width: 100%; text-align: left; padding: 12px; border: 1px solid transparent; min-width: 0; }
|
|
86
|
-
.pbot-list-item[aria-pressed=true] { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }
|
|
87
|
-
.pbot-list-item strong { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
|
|
88
|
-
.pbot-list-item .pbot-muted { margin-top: 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
|
71
|
+
.pbot-field :is(input,select) { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--pbot-line); border-radius: 7px; background: var(--pbot-surface); line-height: 1.5; }
|
|
72
|
+
.pbot-field input::placeholder { color: var(--pbot-muted); opacity: .8; }
|
|
89
73
|
.pbot-empty { padding: 38px 20px; border: 1px dashed var(--pbot-line); border-radius: 12px; text-align: center; display: grid; gap: 8px; }
|
|
90
74
|
.pbot-empty h3 { font-weight: 550; }
|
|
91
75
|
.pbot-empty button { justify-self: center; margin-top: 10px; }
|
|
92
|
-
.pbot-detail { min-width: 0; display: grid; gap: 18px; }
|
|
93
|
-
.pbot-detail-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
|
|
94
76
|
.pbot-prose { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 10px 0; line-height: 1.7; }
|
|
95
77
|
.pbot-raw { font: 12px/1.6 ui-monospace, SFMono-Regular, monospace; max-height: 340px; overflow: auto; }
|
|
96
|
-
.pbot-transcript { margin-top: 14px; }
|
|
97
|
-
.pbot-event { border-left: 2px solid var(--pbot-line); padding: 0 0 0 14px; margin: 18px 0; }
|
|
98
|
-
.pbot-event .pbot-prose { font-size: 13px; }
|
|
99
|
-
.pbot-event .pbot-row, .pbot-message .pbot-row { justify-content: space-between; }
|
|
100
78
|
.pbot-management .pbot-pagination { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0; color: var(--pbot-muted); font-size: 12px; }
|
|
101
79
|
.pbot-pagination button { font-size: 12px; min-height: 30px; padding: 5px 9px; }
|
|
102
|
-
.pbot-message { padding: 16px 0; border-bottom: 1px solid var(--pbot-line); }
|
|
103
|
-
.pbot-message:last-child { border-bottom: 0; }
|
|
104
|
-
.pbot-message .pbot-prose { font-size: 13px; }
|
|
105
80
|
.pbot-search { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto; gap: 12px; align-items: end; }
|
|
106
81
|
.pbot-search .pbot-field { margin: 0; }
|
|
107
82
|
.pbot-search > button { margin-bottom: 2px; }
|
|
@@ -114,16 +89,13 @@ export const managementStyles = `
|
|
|
114
89
|
.pbot-shell { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr) auto; }
|
|
115
90
|
.pbot-nav { flex-direction: row; padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--pbot-line); }
|
|
116
91
|
.pbot-nav button { flex: 1; justify-content: center; padding: 8px; }
|
|
117
|
-
.pbot-nav small { display: none; }
|
|
118
92
|
.pbot-main { padding: 22px 18px; }
|
|
119
93
|
.pbot-notice { top: -22px; }
|
|
120
94
|
.pbot-header { padding: 14px 18px; }
|
|
121
|
-
.pbot-split { grid-template-columns: minmax(150px, 190px) minmax(0, 1fr); gap: 16px; }
|
|
122
95
|
}
|
|
123
96
|
@media (max-width: 600px) {
|
|
124
97
|
.pbot-management { width: calc(100vw - 12px); height: calc(100dvh - 16px); }
|
|
125
|
-
.pbot-grid
|
|
126
|
-
.pbot-list { max-height: 215px; }
|
|
98
|
+
.pbot-grid { grid-template-columns: minmax(0, 1fr); }
|
|
127
99
|
.pbot-search { grid-template-columns: minmax(0, 1fr) 110px; }
|
|
128
100
|
.pbot-search > button { grid-column: 1 / -1; }
|
|
129
101
|
.pbot-footer { padding: 8px 14px; }
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { HistoryMigrationReport } from "../../model/history.js";
|
|
2
|
-
export interface MigrateHistoryOptions {
|
|
3
|
-
dryRun?: boolean;
|
|
4
|
-
}
|
|
5
|
-
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
6
|
-
export declare function checkHistoryMigrationNotice(root: string): string | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Explicitly migrate flat .pbot/history/raw/*.json and .pbot/history/summaries/<dim>/*.json
|
|
9
|
-
* into UTC YYYY/MM/ (or unknown/) buckets. Moves files directly without keeping duplicates
|
|
10
|
-
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
11
|
-
*/
|
|
12
|
-
export declare function migrateWorkspaceHistory(root: string, options?: MigrateHistoryOptions): HistoryMigrationReport;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { lstatSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { requireThat } from "../../common/validation.js";
|
|
4
|
-
import { HistoryFiles, rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
|
|
5
|
-
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
6
|
-
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
7
|
-
export function checkHistoryMigrationNotice(root) {
|
|
8
|
-
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
9
|
-
if (layout !== "monthly")
|
|
10
|
-
return undefined;
|
|
11
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
12
|
-
return files.detectFlatFiles().message;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Explicitly migrate flat .pbot/history/raw/*.json and .pbot/history/summaries/<dim>/*.json
|
|
16
|
-
* into UTC YYYY/MM/ (or unknown/) buckets. Moves files directly without keeping duplicates
|
|
17
|
-
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
18
|
-
*/
|
|
19
|
-
export function migrateWorkspaceHistory(root, options = {}) {
|
|
20
|
-
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
21
|
-
requireThat(layout === "monthly", '当前工作区配置为平铺布局(history.layout: "flat"),无需迁移到年月目录;如需迁移,请先在 .pbot/config.json 中将 history.layout 设为 "monthly" 或移除该配置项。');
|
|
22
|
-
const dryRun = Boolean(options.dryRun);
|
|
23
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", "monthly");
|
|
24
|
-
const moved = [];
|
|
25
|
-
const skipped = [];
|
|
26
|
-
const errors = [];
|
|
27
|
-
const run = () => {
|
|
28
|
-
for (const name of files.listFlatRawFiles()) {
|
|
29
|
-
const from = `raw/${name}`;
|
|
30
|
-
try {
|
|
31
|
-
const raw = files.readFlatRawFile(name);
|
|
32
|
-
const bucket = rawHistoryBucket(raw);
|
|
33
|
-
const to = `raw/${bucket}/${name}`;
|
|
34
|
-
if (dryRun) {
|
|
35
|
-
if (lstatSync(join(files.directory, to), { throwIfNoEntry: false })) {
|
|
36
|
-
skipped.push({ kind: "raw", from, to, reason: "目标路径已存在同名文件。" });
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
moved.push({ kind: "raw", id: raw.id, from, to });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
44
|
-
if (outcome === "moved")
|
|
45
|
-
moved.push({ kind: "raw", id: raw.id, from, to });
|
|
46
|
-
else
|
|
47
|
-
skipped.push({ kind: "raw", from, to, reason: "目标路径已存在同名文件。" });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
for (const dimension of files.listDimensions()) {
|
|
55
|
-
for (const name of files.listFlatSummaryFiles(dimension)) {
|
|
56
|
-
const from = `summaries/${dimension}/${name}`;
|
|
57
|
-
try {
|
|
58
|
-
const artifact = files.readFlatSummaryFile(dimension, name);
|
|
59
|
-
const bucket = summaryArtifactBucket(artifact);
|
|
60
|
-
const to = `summaries/${dimension}/${bucket}/${name}`;
|
|
61
|
-
if (dryRun) {
|
|
62
|
-
if (lstatSync(join(files.directory, to), { throwIfNoEntry: false })) {
|
|
63
|
-
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
71
|
-
if (outcome === "moved")
|
|
72
|
-
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
73
|
-
else
|
|
74
|
-
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
if (dryRun)
|
|
84
|
-
run();
|
|
85
|
-
else
|
|
86
|
-
files.controlMigration(run);
|
|
87
|
-
return { layout, dryRun, moved, skipped, errors };
|
|
88
|
-
}
|
package/lib/ui/presentation.d.ts
DELETED
package/lib/ui/presentation.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const states = {
|
|
2
|
-
starting: "启动中", busy: "执行中", idle: "待命", stopping: "停止中", stopped: "已停止", error: "需要处理",
|
|
3
|
-
running: "进行中", paused: "已暂停", finished: "已结束", completed: "已完成", failed: "失败",
|
|
4
|
-
cancelled: "已取消", interrupted: "已中断",
|
|
5
|
-
open: "待安排", closed: "已关闭",
|
|
6
|
-
};
|
|
7
|
-
export const stateLabel = (state) => states[String(state)] ?? String(state ?? "未知");
|
|
8
|
-
export const oneLine = (value) => value.replace(/\s+/g, " ").trim();
|
|
9
|
-
export function duration(milliseconds) {
|
|
10
|
-
const seconds = Math.max(0, Math.floor(milliseconds / 1000));
|
|
11
|
-
return seconds < 60 ? `${seconds} 秒` : seconds < 3600 ? `${Math.floor(seconds / 60)} 分钟` : `${Math.floor(seconds / 3600)} 小时 ${Math.floor(seconds % 3600 / 60)} 分钟`;
|
|
12
|
-
}
|
package/src/tools/access.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/** Each tool is bound to one workspace instance, not a mutable global lookup. */
|
|
3
|
-
export interface CallAccess {
|
|
4
|
-
check(): void;
|
|
5
|
-
signal(signal?: AbortSignal): AbortSignal;
|
|
6
|
-
authorizeFile(path: string, change: unknown, confirm: (value: unknown) => Promise<boolean>, signal: AbortSignal): Promise<void>;
|
|
7
|
-
}
|
package/src/tools/register.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { CallAccess } from "./access.js";
|
|
3
|
-
import { historyTool } from "./history/pi-tool.js";
|
|
4
|
-
|
|
5
|
-
export function mainTools(root: string, access: CallAccess): ToolDefinition[] {
|
|
6
|
-
return [historyTool(root, access)];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class ToolRegistry {
|
|
10
|
-
readonly #registered = new Map<string, ToolDefinition>();
|
|
11
|
-
constructor(private readonly pi: ExtensionAPI) {}
|
|
12
|
-
register(tools: ToolDefinition[]) {
|
|
13
|
-
for (const definition of tools) {
|
|
14
|
-
const tool = { ...definition, namespace: { name: "pbot", description: "工作区历史查询。" } };
|
|
15
|
-
this.#registered.set(tool.name, tool); this.pi.registerTool(tool);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
hide() {
|
|
19
|
-
for (const tool of this.#registered.values()) this.pi.registerTool({ ...tool, exposure: "hidden" });
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/ui/presentation.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const states: Record<string, string> = {
|
|
2
|
-
starting: "启动中", busy: "执行中", idle: "待命", stopping: "停止中", stopped: "已停止", error: "需要处理",
|
|
3
|
-
running: "进行中", paused: "已暂停", finished: "已结束", completed: "已完成", failed: "失败",
|
|
4
|
-
cancelled: "已取消", interrupted: "已中断",
|
|
5
|
-
open: "待安排", closed: "已关闭",
|
|
6
|
-
};
|
|
7
|
-
export const stateLabel = (state: unknown) => states[String(state)] ?? String(state ?? "未知");
|
|
8
|
-
export const oneLine = (value: string) => value.replace(/\s+/g, " ").trim();
|
|
9
|
-
export function duration(milliseconds: number) {
|
|
10
|
-
const seconds = Math.max(0, Math.floor(milliseconds / 1000));
|
|
11
|
-
return seconds < 60 ? `${seconds} 秒` : seconds < 3600 ? `${Math.floor(seconds / 60)} 分钟` : `${Math.floor(seconds / 3600)} 小时 ${Math.floor(seconds % 3600 / 60)} 分钟`;
|
|
12
|
-
}
|