personal-bot 0.2.13 → 0.2.15
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 +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +10 -11
- package/README.zh-CN.md +10 -11
- package/docs/README.md +2 -2
- package/docs/adr/0001-claude-skill-discovery.md +1 -1
- package/docs/agent-collaboration.md +3 -3
- package/docs/architecture-guidelines.md +1 -1
- package/docs/capability-design.md +2 -2
- package/docs/claude-code-design.md +10 -11
- package/docs/claude-code.md +8 -15
- package/docs/dsh.md +7 -8
- package/docs/file-storage.md +2 -3
- package/docs/installation-design.md +4 -5
- package/docs/interaction-design.md +1 -1
- package/docs/model-context.md +9 -10
- package/docs/release.md +6 -6
- package/docs/technical-design.md +18 -23
- package/docs/workspace-configuration.md +5 -8
- package/hooks/hooks.json +1 -4
- package/lib/client.js +3 -15
- package/lib/common/schema.d.ts +2 -0
- package/lib/common/schema.js +10 -0
- package/lib/common/validation.d.ts +0 -2
- package/lib/common/validation.js +0 -10
- package/lib/extension/acp-member.js +1 -3
- package/lib/extension/acp-worker.js +3 -22
- package/lib/extension/claude-hooks.d.ts +0 -6
- package/lib/extension/claude-hooks.js +5 -31
- package/lib/extension/dsh/acp-member.js +1 -2
- package/lib/extension/dsh/command.js +4 -8
- package/lib/extension/dsh/management.d.ts +1 -1
- package/lib/extension/dsh/management.js +5 -4
- package/lib/extension/dsh/workspace.d.ts +1 -9
- package/lib/extension/dsh/workspace.js +4 -29
- package/lib/extension/setup-cli.js +4 -4
- package/lib/integrations/dsh/resources.d.ts +1 -5
- package/lib/integrations/dsh/resources.js +2 -5
- package/lib/integrations/installation/processes.js +0 -15
- package/lib/tools/agents/dsh-tool.js +2 -1
- package/lib/tools/history/contract.js +2 -1
- package/lib/tools/history/dsh-tool.js +2 -1
- package/lib/tools/teams/dsh-tool.js +2 -1
- package/lib/ui/dsh/management.js +1 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +2 -2
- package/lib/ui/presentation.js +1 -1
- package/package.json +1 -5
- package/resources/claude/skills/pbot/SKILL.md +2 -3
- package/resources/prompts/workspace.md +1 -1
- package/resources/references/compute.md +6 -8
- package/scripts/README.md +5 -9
- package/src/common/schema.ts +11 -0
- package/src/common/validation.ts +0 -11
- package/src/extension/acp-member.ts +1 -3
- package/src/extension/acp-worker.ts +3 -12
- package/src/extension/claude-hooks.ts +5 -25
- package/src/extension/command.ts +7 -16
- package/src/extension/dsh/acp-member.ts +1 -2
- package/src/extension/dsh/command.ts +4 -7
- package/src/extension/dsh/management.ts +5 -4
- package/src/extension/dsh/workspace.ts +5 -25
- package/src/extension/events.ts +2 -11
- package/src/extension/lifecycle.ts +8 -23
- package/src/extension/setup-cli.ts +4 -4
- package/src/extension/subagent-entry.ts +6 -12
- package/src/integrations/dsh/resources.ts +2 -5
- package/src/integrations/installation/processes.ts +0 -13
- package/src/integrations/pi/pi-agents.ts +12 -5
- package/src/pbot.ts +1 -2
- package/src/tools/agents/dsh-tool.ts +2 -1
- package/src/tools/agents/tool.ts +2 -1
- package/src/tools/history/contract.ts +2 -1
- package/src/tools/history/dsh-tool.ts +2 -1
- package/src/tools/teams/dsh-tool.ts +2 -1
- package/src/tools/teams/tool.ts +2 -1
- package/src/ui/dsh/management.ts +2 -8
- package/src/ui/dsh/styles.ts +2 -2
- package/src/ui/presentation.ts +1 -1
- package/lib/integrations/process.d.ts +0 -14
- package/lib/integrations/process.js +0 -48
- package/lib/integrations/python-activation.d.ts +0 -2
- package/lib/integrations/python-activation.js +0 -29
- package/lib/services/workspace/python-environment-service.d.ts +0 -21
- package/lib/services/workspace/python-environment-service.js +0 -66
- package/npm-shrinkwrap.json +0 -13544
- package/python/README.md +0 -72
- package/python/requirements.lock +0 -38
- package/scripts/setup-python.py +0 -170
- package/src/integrations/process.ts +0 -40
- package/src/integrations/python-activation.ts +0 -23
- package/src/services/workspace/python-environment-service.ts +0 -61
|
@@ -89,7 +89,8 @@ import { SessionId } from "@deepseek-ai/dsh-session";
|
|
|
89
89
|
import { extractSessionEventText } from "@deepseek-ai/dsh-session-query";
|
|
90
90
|
import { Type } from "../../common/typebox.js";
|
|
91
91
|
import { json } from "../../common/json.js";
|
|
92
|
-
import { requireThat
|
|
92
|
+
import { requireThat } from "../../common/validation.js";
|
|
93
|
+
import { schema } from "../../common/schema.js";
|
|
93
94
|
import { packageVersion } from "../../common/version.js";
|
|
94
95
|
import { historyInput } from "../../tools/history/contract.js";
|
|
95
96
|
import { executeHistory } from "../../tools/history/actions.js";
|
|
@@ -103,11 +104,11 @@ const teamSchema = Type.Object({ teamId: Type.String({ minLength: 1 }), afterSeq
|
|
|
103
104
|
seq: Type.Optional(Type.Integer({ minimum: 1 })), offset: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
104
105
|
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000 })) }, { additionalProperties: false });
|
|
105
106
|
const validRequest = schema(requestSchema), validExpert = schema(expertSchema), validTeam = schema(teamSchema);
|
|
106
|
-
export function dshStatus(
|
|
107
|
+
export function dshStatus(workspace) {
|
|
107
108
|
workspace.check();
|
|
108
109
|
const agents = workspace.agents.list(workspace.owner);
|
|
109
110
|
return json({ host: "dsh", release: packageVersion, enabled: true, state: "running", workspaceRoot: workspace.root, sessionId: workspace.agent.id,
|
|
110
|
-
model: workspace.agent.model.current() ?? null,
|
|
111
|
+
model: workspace.agent.model.current() ?? null,
|
|
111
112
|
controlError: workspace.controlError ?? null, history: workspace.history.status,
|
|
112
113
|
agents, permissions: workspace.agents.pendingPermissions(workspace.owner), teams: workspace.teams.list(workspace.owner, agents) });
|
|
113
114
|
}
|
|
@@ -118,7 +119,7 @@ export async function dshWorkspaceStatus(workspaces, agent) {
|
|
|
118
119
|
return json({ host: "dsh", release: packageVersion, enabled: false,
|
|
119
120
|
state: configuration.error ? "error" : "disabled", nextStep: configuration.error ? configuration.error : "/pbot init",
|
|
120
121
|
workspaceRoot: root, sessionId: agent.id, configuration, model: agent.model.current() ?? null, agents: [], teams: [] });
|
|
121
|
-
return json({ ...dshStatus(
|
|
122
|
+
return json({ ...dshStatus(await workspaces.get(agent)), configuration });
|
|
122
123
|
}
|
|
123
124
|
/** Native Remote owns transport and access checks. These workspace reads do not admit or cancel execution. */
|
|
124
125
|
let PbotManagement = (() => {
|
|
@@ -9,7 +9,6 @@ import { TeamService } from "../../services/agents/team-service.js";
|
|
|
9
9
|
import { DshAgentRuntime } from "./agent-runtime.js";
|
|
10
10
|
import { DshHistoryWork } from "./history.js";
|
|
11
11
|
import type { HistoryService } from "../../services/history/history-service.js";
|
|
12
|
-
import { PythonEnvironmentService } from "../../services/workspace/python-environment-service.js";
|
|
13
12
|
import type { WorkspaceConfiguration } from "../../model/workspace-config.js";
|
|
14
13
|
export declare const dshDependencies: string[];
|
|
15
14
|
export declare class DshWorkspace {
|
|
@@ -17,7 +16,6 @@ export declare class DshWorkspace {
|
|
|
17
16
|
readonly ctx: Context;
|
|
18
17
|
readonly root: string;
|
|
19
18
|
readonly agent: Agent;
|
|
20
|
-
readonly python: PythonEnvironmentService;
|
|
21
19
|
readonly component: AbortSignal;
|
|
22
20
|
private readonly historyWork;
|
|
23
21
|
private readonly releaseHistory;
|
|
@@ -27,7 +25,7 @@ export declare class DshWorkspace {
|
|
|
27
25
|
readonly teams: TeamService;
|
|
28
26
|
readonly history: HistoryService;
|
|
29
27
|
readonly owner: AgentOwner;
|
|
30
|
-
constructor(ctx: Context, root: string, agent: Agent,
|
|
28
|
+
constructor(ctx: Context, root: string, agent: Agent, component: AbortSignal, historyWork: DshHistoryWork, releaseHistory: () => Promise<void>, acp?: AcpCommands);
|
|
31
29
|
check: () => void;
|
|
32
30
|
get controlError(): string | undefined;
|
|
33
31
|
open(): Promise<void>;
|
|
@@ -66,11 +64,9 @@ export declare class DshWorkspace {
|
|
|
66
64
|
expert(id: string): DshAgentRuntime;
|
|
67
65
|
close(): Promise<void>;
|
|
68
66
|
}
|
|
69
|
-
/** The execution component owns Python; closing one Session must not undo its activation. */
|
|
70
67
|
export declare class DshWorkspaces {
|
|
71
68
|
#private;
|
|
72
69
|
readonly ctx: Context;
|
|
73
|
-
readonly python: PythonEnvironmentService;
|
|
74
70
|
constructor(ctx: Context);
|
|
75
71
|
private history;
|
|
76
72
|
open(agent: Agent): Promise<DshWorkspace | undefined>;
|
|
@@ -80,9 +76,5 @@ export declare class DshWorkspaces {
|
|
|
80
76
|
configuration: WorkspaceConfiguration;
|
|
81
77
|
}>;
|
|
82
78
|
initialize(agent: Agent): Promise<DshWorkspace>;
|
|
83
|
-
preparePython(): Promise<{
|
|
84
|
-
directory: string;
|
|
85
|
-
python: string;
|
|
86
|
-
}>;
|
|
87
79
|
close(): Promise<void>;
|
|
88
80
|
}
|
|
@@ -12,8 +12,6 @@ import { DshAgentEvents } from "./agent-events.js";
|
|
|
12
12
|
import { registerDshFileEvents } from "./files.js";
|
|
13
13
|
import { DshHistoryWork, registerDshHistoryEvents } from "./history.js";
|
|
14
14
|
import { registerDshHistoryTool } from "../../tools/history/dsh-tool.js";
|
|
15
|
-
import { activatePython } from "../../integrations/python-activation.js";
|
|
16
|
-
import { PythonEnvironmentService } from "../../services/workspace/python-environment-service.js";
|
|
17
15
|
import { requireThat } from "../../common/validation.js";
|
|
18
16
|
import { registerDshSkills } from "../../integrations/dsh/skills.js";
|
|
19
17
|
import { readWorkspaceConfig, workspaceDisabledMessage } from "../../services/workspace/workspace-config.js";
|
|
@@ -23,7 +21,6 @@ export class DshWorkspace {
|
|
|
23
21
|
ctx;
|
|
24
22
|
root;
|
|
25
23
|
agent;
|
|
26
|
-
python;
|
|
27
24
|
component;
|
|
28
25
|
historyWork;
|
|
29
26
|
releaseHistory;
|
|
@@ -37,11 +34,10 @@ export class DshWorkspace {
|
|
|
37
34
|
#scope;
|
|
38
35
|
#events;
|
|
39
36
|
#closing;
|
|
40
|
-
constructor(ctx, root, agent,
|
|
37
|
+
constructor(ctx, root, agent, component, historyWork, releaseHistory, acp) {
|
|
41
38
|
this.ctx = ctx;
|
|
42
39
|
this.root = root;
|
|
43
40
|
this.agent = agent;
|
|
44
|
-
this.python = python;
|
|
45
41
|
this.component = component;
|
|
46
42
|
this.historyWork = historyWork;
|
|
47
43
|
this.releaseHistory = releaseHistory;
|
|
@@ -57,7 +53,7 @@ export class DshWorkspace {
|
|
|
57
53
|
scope.effect(() => () => { if (this.#experts.get(d.agentId) === runtime)
|
|
58
54
|
this.#experts.delete(d.agentId); });
|
|
59
55
|
registerDshSkills(scope, child);
|
|
60
|
-
await dshResources(scope, child, root, "general-purpose",
|
|
56
|
+
await dshResources(scope, child, root, "general-purpose", runtime.check);
|
|
61
57
|
const teamTool = dshExpertTools(scope, child, d.options);
|
|
62
58
|
if (teamTool)
|
|
63
59
|
registerDshTeamMessageTool(scope, child, this.teams, runtime.actor, runtime.check);
|
|
@@ -84,7 +80,7 @@ export class DshWorkspace {
|
|
|
84
80
|
this.check();
|
|
85
81
|
this.#scope = await this.agent.ctx.plugin({ name: "pbot-coordinator", inject: dshDependencies, apply: async (ctx) => {
|
|
86
82
|
registerDshSkills(ctx, this.agent);
|
|
87
|
-
await dshResources(ctx, this.agent, this.root, "coordinator",
|
|
83
|
+
await dshResources(ctx, this.agent, this.root, "coordinator", this.check);
|
|
88
84
|
registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
|
|
89
85
|
registerDshAgentTool(ctx, this.agent, this.agents, this.owner, this.check);
|
|
90
86
|
registerDshTeamTool(ctx, this.agent, this.teams, this.agents, this.owner, this.check);
|
|
@@ -170,18 +166,14 @@ export class DshWorkspace {
|
|
|
170
166
|
return this.#closing;
|
|
171
167
|
}
|
|
172
168
|
}
|
|
173
|
-
/** The execution component owns Python; closing one Session must not undo its activation. */
|
|
174
169
|
export class DshWorkspaces {
|
|
175
170
|
ctx;
|
|
176
|
-
python = new PythonEnvironmentService(process.cwd());
|
|
177
171
|
#parents = new Map();
|
|
178
172
|
#initializing = new Map();
|
|
179
173
|
#configurations = new Map();
|
|
180
174
|
#parentEffects = new Map();
|
|
181
175
|
#histories = new Map();
|
|
182
176
|
#lifetime = new AbortController();
|
|
183
|
-
#restorePython;
|
|
184
|
-
#preparing;
|
|
185
177
|
#closing;
|
|
186
178
|
constructor(ctx) {
|
|
187
179
|
this.ctx = ctx;
|
|
@@ -244,7 +236,7 @@ export class DshWorkspaces {
|
|
|
244
236
|
const history = await this.history(root);
|
|
245
237
|
let workspace;
|
|
246
238
|
try {
|
|
247
|
-
workspace = new DshWorkspace(this.ctx, root, agent, this
|
|
239
|
+
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, configuration.acp);
|
|
248
240
|
const owned = workspace;
|
|
249
241
|
const dispose = agent.ctx.effect(() => async () => {
|
|
250
242
|
this.#parents.delete(agent);
|
|
@@ -255,7 +247,6 @@ export class DshWorkspaces {
|
|
|
255
247
|
this.#parentEffects.set(agent, dispose);
|
|
256
248
|
await workspace.open();
|
|
257
249
|
this.#lifetime.signal.throwIfAborted();
|
|
258
|
-
void this.preparePython().catch(error => this.ctx.logger.warn(String(error)));
|
|
259
250
|
return workspace;
|
|
260
251
|
}
|
|
261
252
|
catch (error) {
|
|
@@ -332,19 +323,6 @@ export class DshWorkspaces {
|
|
|
332
323
|
}
|
|
333
324
|
return this.get(agent);
|
|
334
325
|
}
|
|
335
|
-
preparePython() {
|
|
336
|
-
this.#lifetime.signal.throwIfAborted();
|
|
337
|
-
if (this.#preparing)
|
|
338
|
-
return this.#preparing;
|
|
339
|
-
this.#preparing = (async () => {
|
|
340
|
-
const result = await this.python.setup(this.#lifetime.signal);
|
|
341
|
-
this.#lifetime.signal.throwIfAborted();
|
|
342
|
-
if (!this.#restorePython)
|
|
343
|
-
this.#restorePython = activatePython(result.directory);
|
|
344
|
-
return result;
|
|
345
|
-
})().finally(() => { this.#preparing = undefined; });
|
|
346
|
-
return this.#preparing;
|
|
347
|
-
}
|
|
348
326
|
close() {
|
|
349
327
|
if (this.#closing)
|
|
350
328
|
return this.#closing;
|
|
@@ -356,7 +334,6 @@ export class DshWorkspaces {
|
|
|
356
334
|
const closed = await Promise.allSettled(opened.flatMap(value => value.status === "fulfilled" && value.value ? [value.value.close()] : []));
|
|
357
335
|
const effects = await Promise.allSettled([...this.#parentEffects.values()].map(dispose => dispose()));
|
|
358
336
|
const histories = await Promise.allSettled([...this.#histories.values()].map(value => value.work.close()));
|
|
359
|
-
await this.python.close();
|
|
360
337
|
const errors = [...new Set([...closed, ...effects, ...histories].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
|
|
361
338
|
if (errors.length)
|
|
362
339
|
throw new AggregateError(errors, "部分 dsh 工作区未能完成关闭。");
|
|
@@ -366,8 +343,6 @@ export class DshWorkspaces {
|
|
|
366
343
|
this.#configurations.clear();
|
|
367
344
|
this.#parentEffects.clear();
|
|
368
345
|
this.#histories.clear();
|
|
369
|
-
this.#restorePython?.();
|
|
370
|
-
this.#restorePython = undefined;
|
|
371
346
|
}
|
|
372
347
|
})();
|
|
373
348
|
return this.#closing;
|
|
@@ -26,7 +26,7 @@ export async function main(args) {
|
|
|
26
26
|
if (options.action === "help") {
|
|
27
27
|
console.log("Personal Bot " + manifest.version + "\n\n用法:pbot setup [--workspace <目录>]\n" +
|
|
28
28
|
" npx personal-bot@latest setup\n\nsetup 安装或升级 Pi、pbot 和选中的插件,然后启动 Pi 执行 /pbot init。\n" +
|
|
29
|
-
"支持 Linux/macOS,需要 Node.js 22.19
|
|
29
|
+
"支持 Linux/macOS,需要 Node.js 22.19+ 和 npm。\n--help 显示帮助;--version 显示安装器版本。");
|
|
30
30
|
return 0;
|
|
31
31
|
}
|
|
32
32
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
@@ -40,7 +40,7 @@ export async function main(args) {
|
|
|
40
40
|
const ui = new SetupUI(controller), processes = new SetupProcesses(controller.signal);
|
|
41
41
|
try {
|
|
42
42
|
const cwd = process.cwd();
|
|
43
|
-
ui.text("Personal Bot " + manifest.version + " — 安装与升级\n正在检查 Node/npm
|
|
43
|
+
ui.text("Personal Bot " + manifest.version + " — 安装与升级\n正在检查 Node/npm 和 tmux…");
|
|
44
44
|
const system = await inspectSystem(processes, cwd);
|
|
45
45
|
const supplied = options.workspace ?? await ui.ask("工作区目录(当前、已有或新建目录)", cwd);
|
|
46
46
|
const workspace = await resolveWorkspace(supplied, cwd, homedir());
|
|
@@ -104,7 +104,7 @@ export async function main(args) {
|
|
|
104
104
|
const blocking = choices.find(choice => choice.required && choice.error);
|
|
105
105
|
if (blocking)
|
|
106
106
|
throw new Error(blocking.error);
|
|
107
|
-
ui.text("升级前请停止活动 pbot
|
|
107
|
+
ui.text("升级前请停止活动 pbot 子会话。Pi 为当前用户共用,插件只处理此工作区。");
|
|
108
108
|
if (!await ui.confirm("执行以上计划"))
|
|
109
109
|
return 130;
|
|
110
110
|
await mkdir(workspace, { recursive: true });
|
|
@@ -114,7 +114,7 @@ export async function main(args) {
|
|
|
114
114
|
const failed = result.results.some(item => item.state === "failed");
|
|
115
115
|
if (!result.pi)
|
|
116
116
|
return 1;
|
|
117
|
-
ui.text("\n
|
|
117
|
+
ui.text("\n软件安装阶段结束。工作区初始化和外部服务的状态由 Pi/pbot/插件分别报告。");
|
|
118
118
|
if (await ui.confirm(failed ? "部分插件失败,是否仍启动 Pi 并初始化启用工作区" : "启动 Pi 并初始化启用工作区", !failed)) {
|
|
119
119
|
process.stdin.pause();
|
|
120
120
|
await host.start(result.pi, workspace);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import type { AgentOptions } from "../../model/agent.js";
|
|
4
|
-
export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose",
|
|
5
|
-
state: string;
|
|
6
|
-
directory?: string;
|
|
7
|
-
error?: string;
|
|
8
|
-
}, check: () => void): Promise<void>;
|
|
4
|
+
export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose", check: () => void): Promise<void>;
|
|
9
5
|
/** Map the expert's native loadout; this is not isolation from Bash, CLI, or MCP. */
|
|
10
6
|
export declare function dshExpertTools(ctx: Context, agent: Agent, options: AgentOptions): boolean;
|
|
@@ -3,17 +3,14 @@ import { join } from "node:path";
|
|
|
3
3
|
import { agentText } from "../agent-resources.js";
|
|
4
4
|
import { resourceRoot } from "../../common/paths.js";
|
|
5
5
|
import { requireThat } from "../../common/validation.js";
|
|
6
|
-
export async function dshResources(ctx, _agent, root, role,
|
|
6
|
+
export async function dshResources(ctx, _agent, root, role, check) {
|
|
7
7
|
const read = () => Promise.all([agentText(role, root), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
|
|
8
8
|
const [text, workspace] = await read();
|
|
9
9
|
check();
|
|
10
10
|
ctx.systemPrompt.section({ name: "pbot:role", order: 1, text, interpolate: false });
|
|
11
11
|
ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: workspace, interpolate: false });
|
|
12
12
|
ctx.systemPrompt.context({ name: "pbot:environment", order: 300, required: true, interpolate: false,
|
|
13
|
-
text: ()
|
|
14
|
-
const { state, directory } = python();
|
|
15
|
-
return JSON.stringify({ workspaceRoot: root, resourceRoot, python: { state, ...(directory ? { directory } : {}) } });
|
|
16
|
-
} });
|
|
13
|
+
text: JSON.stringify({ workspaceRoot: root, resourceRoot }) });
|
|
17
14
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
18
15
|
check();
|
|
19
16
|
const [roleText, workspaceText] = await read();
|
|
@@ -127,21 +127,6 @@ export async function inspectSystem(processes, cwd) {
|
|
|
127
127
|
const npm = await findExecutable("npm", processes.env);
|
|
128
128
|
if (!npm)
|
|
129
129
|
throw new Error("未找到 npm。请先安装 Node.js/npm。");
|
|
130
|
-
const python = await findExecutable("python3", processes.env) ?? await findExecutable("python", processes.env);
|
|
131
|
-
if (!python)
|
|
132
|
-
throw new Error("需要 Python 3.11+ 和 venv/ensurepip。请先安装后重试。");
|
|
133
|
-
try {
|
|
134
|
-
await processes.run(python, ["-I", "-B", "-c", [
|
|
135
|
-
"import sys, tempfile, venv, ensurepip",
|
|
136
|
-
"assert sys.version_info >= (3, 11), 'Python 3.11+ required'",
|
|
137
|
-
"with tempfile.TemporaryDirectory(prefix='pbot-python-check-') as path:",
|
|
138
|
-
" venv.EnvBuilder(with_pip=True).create(path)",
|
|
139
|
-
].join("\n")], cwd);
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
processes.signal.throwIfAborted();
|
|
143
|
-
throw new Error("基础 Python 检查失败。需要 Python 3.11+ 和 venv/ensurepip;Debian/Ubuntu 还需 python3-venv。\n" + String(error));
|
|
144
|
-
}
|
|
145
130
|
const tmux = await findExecutable("tmux", processes.env);
|
|
146
131
|
if (tmux) {
|
|
147
132
|
await processes.run(tmux, ["-V"], cwd);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { dshParameters, dshOutputSchema } from "../../integrations/dsh/schema.js";
|
|
2
2
|
import { object, json } from "../../common/json.js";
|
|
3
|
-
import { requireThat
|
|
3
|
+
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
import { schema } from "../../common/schema.js";
|
|
4
5
|
import { markdownFields } from "../../common/markdown.js";
|
|
5
6
|
import { executeAgent } from "./actions.js";
|
|
6
7
|
import { agentDescription, agentResultSchema } from "./contract.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "../../common/typebox.js";
|
|
2
|
-
import { requireThat
|
|
2
|
+
import { requireThat } from "../../common/validation.js";
|
|
3
|
+
import { schema } from "../../common/schema.js";
|
|
3
4
|
const host = Type.Union([Type.Literal("pi"), Type.Literal("dsh"), Type.Literal("claude")]);
|
|
4
5
|
const nullableOffset = Type.Union([Type.Integer(), Type.Null()]);
|
|
5
6
|
const node = Type.Object({ host, id: Type.String(), kind: Type.Union([Type.Literal("session"), Type.Literal("exchange"), Type.Literal("summary")]),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dshParameters, dshOutputSchema } from "../../integrations/dsh/schema.js";
|
|
2
|
-
import { requireThat
|
|
2
|
+
import { requireThat } from "../../common/validation.js";
|
|
3
|
+
import { schema } from "../../common/schema.js";
|
|
3
4
|
import { json } from "../../common/json.js";
|
|
4
5
|
import { markdownFields } from "../../common/markdown.js";
|
|
5
6
|
import { historyDescription, historyInput, historyParameters, historyResultSchema } from "./contract.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { dshParameters, dshOutputSchema } from "../../integrations/dsh/schema.js";
|
|
2
2
|
import { object } from "../../common/json.js";
|
|
3
|
-
import { requireThat
|
|
3
|
+
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
import { schema } from "../../common/schema.js";
|
|
4
5
|
import { markdownFields } from "../../common/markdown.js";
|
|
5
6
|
import { teamMessagesMarkdown } from "../../integrations/team-context.js";
|
|
6
7
|
import { executeTeam, executeTeamMessage } from "./actions.js";
|
package/lib/ui/dsh/management.js
CHANGED
|
@@ -160,8 +160,6 @@ export function showManagement(ctx, parentSessionId) {
|
|
|
160
160
|
const materials = group(status, "pbot-setting");
|
|
161
161
|
materials.append(element("h3", "资料目录"));
|
|
162
162
|
const initializeButton = button(materials, "准备目录", async () => { await command("init", undefined, "工作区已初始化并启用。"); });
|
|
163
|
-
const pythonCard = group(status, "pbot-setting"), pythonInfo = group(pythonCard);
|
|
164
|
-
const pythonButton = button(pythonCard, "准备 Python", async () => { await command("python setup", undefined, "Python 准备完成。"); });
|
|
165
163
|
const diagnostic = details(status, "环境详情"), statusBody = block("");
|
|
166
164
|
statusBody.classList.add("pbot-raw");
|
|
167
165
|
diagnostic.append(statusBody);
|
|
@@ -643,13 +641,11 @@ export function showManagement(ctx, parentSessionId) {
|
|
|
643
641
|
const configuration = record(snapshot.configuration);
|
|
644
642
|
counts.textContent = configuration.error ? "Personal Bot 配置错误" : "Personal Bot 未启用";
|
|
645
643
|
workspaceInfo.replaceChildren(facts([["状态", configuration.error ? "配置错误" : "未启用"], ["工作区", snapshot.workspaceRoot], ["配置文件", configuration.path]]), note(configuration.error ? "修复配置文件后执行 /pbot init。" : "执行 /pbot init,或点击下方按钮初始化并启用。"));
|
|
646
|
-
pythonInfo.replaceChildren(note("启用工作区后自动准备共享 Python 环境。"));
|
|
647
644
|
materials.hidden = false;
|
|
648
645
|
initializeButton.textContent = "初始化并启用";
|
|
649
646
|
enabled(initializeButton, !configuration.error);
|
|
650
647
|
for (const [id, control] of tabs)
|
|
651
648
|
enabled(control, id === "status");
|
|
652
|
-
enabled(pythonButton, false);
|
|
653
649
|
activate("status");
|
|
654
650
|
statusBody.textContent = JSON.stringify(snapshot, null, 2);
|
|
655
651
|
if (configuration.error)
|
|
@@ -661,7 +657,7 @@ export function showManagement(ctx, parentSessionId) {
|
|
|
661
657
|
materials.hidden = false;
|
|
662
658
|
initializeButton.textContent = "准备目录";
|
|
663
659
|
enabled(initializeButton, true);
|
|
664
|
-
const agents = rows(snapshot.agents), teams = rows(snapshot.teams),
|
|
660
|
+
const agents = rows(snapshot.agents), teams = rows(snapshot.teams), history = record(snapshot.history);
|
|
665
661
|
tabCounts.get("experts").textContent = text(agents.length);
|
|
666
662
|
tabCounts.get("teams").textContent = text(teams.length);
|
|
667
663
|
const active = agents.filter(agent => ["starting", "busy", "stopping"].includes(text(agent.state))).length;
|
|
@@ -669,10 +665,6 @@ export function showManagement(ctx, parentSessionId) {
|
|
|
669
665
|
const model = object(snapshot.model) ? snapshot.model : {};
|
|
670
666
|
workspaceInfo.replaceChildren(facts([["状态", "已启动"], ["工作区", snapshot.workspaceRoot], ["配置文件", record(snapshot.configuration).path], ["模型", model.model || "尚未选择"], ["Provider", model.provider || "—"],
|
|
671
667
|
["历史", history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : `${history.pending} 项待整理`]]));
|
|
672
|
-
pythonInfo.replaceChildren(element("h3", "Python"), badge(python.state));
|
|
673
|
-
if (python.error)
|
|
674
|
-
pythonInfo.append(element("p", text(python.error), "pbot-warning"));
|
|
675
|
-
enabled(pythonButton, python.state !== "preparing");
|
|
676
668
|
const { agents: _agents, teams: _teams, ...summary } = snapshot;
|
|
677
669
|
statusBody.textContent = JSON.stringify(summary, null, 2);
|
|
678
670
|
const pending = rows(snapshot.permissions), nextPermissionKey = pending.map(request => text(request.agentId) + ":" + text(request.requestId)).join(",");
|
package/lib/ui/dsh/styles.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const managementStyles = "\n.pbot-management {\n --pbot-bg: var(--dsw-alias-bg-base, #f8f9fb);\n --pbot-surface: var(--dsw-alias-bg-layer-1, #fff);\n --pbot-ink: var(--dsw-alias-label-primary, #20232b);\n --pbot-muted: var(--dsw-alias-label-secondary, #696e79);\n --pbot-line: var(--dsw-alias-border-l2, #e3e5eb);\n --pbot-accent: var(--dsw-alias-brand-primary, #4d6bfe);\n --pbot-tint: color-mix(in srgb, var(--pbot-accent) 9%, var(--pbot-surface));\n --pbot-danger: var(--dsw-alias-state-error-primary, #c93535);\n width: min(1180px, calc(100vw - 48px)); height: min(820px, calc(100dvh - 64px));\n max-width: none; max-height: none; padding: 0; margin: auto; overflow: hidden;\n border: 1px solid var(--pbot-line); border-radius: 12px; color: var(--pbot-ink); background: var(--pbot-surface);\n box-shadow: 0 12px 40px #0002; font: 14px/1.55 var(--dsw-font-family, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif);\n}\n.pbot-management::backdrop { background: #10182866; }\n.pbot-management *, .pbot-management *::before, .pbot-management *::after { box-sizing: border-box; }\n.pbot-management [hidden] { display: none !important; }\n.pbot-management h2, .pbot-management h3, .pbot-management h4, .pbot-management p { margin: 0; }\n.pbot-management h2 { font-size: 21px; font-weight: 600; }\n.pbot-management h3 { font-size: 16px; font-weight: 600; }\n.pbot-management h4 { font-size: 14px; font-weight: 600; }\n.pbot-management button, .pbot-management input, .pbot-management textarea, .pbot-management select { font: inherit; color: inherit; }\n.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; }\n.pbot-management button:hover:not(:disabled) { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }\n.pbot-management button:disabled { opacity: .45; cursor: not-allowed; }\n.pbot-management :is(button, input, textarea, select, summary):focus-visible { outline: 2px solid var(--pbot-accent); outline-offset: 3px; }\n.pbot-management button.pbot-primary { background: var(--pbot-accent); border-color: var(--pbot-accent); color: var(--pbot-surface); font-weight: 600; }\n.pbot-management button.pbot-primary:hover:not(:disabled) { filter: brightness(.94); background: var(--pbot-accent); }\n.pbot-management button.pbot-quiet { border-color: transparent; background: transparent; }\n.pbot-management button.pbot-danger { color: var(--pbot-danger); }\n.pbot-management button[data-busy=true]::after { content: \"\u2026\"; }\n.pbot-shell { height: 100%; display: grid; grid-template-columns: 178px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }\n.pbot-header { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--pbot-line); }\n.pbot-brand { font-size: 16px; font-weight: 650; letter-spacing: -.3px; }\n.pbot-location { color: var(--pbot-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; max-width: 65vw; }\n.pbot-header-copy { min-width: 0; flex: 1; }\n.pbot-management .pbot-close { width: 34px; padding: 0; font-size: 22px; }\n.pbot-nav { display: flex; flex-direction: column; gap: 6px; padding: 22px 12px; background: var(--pbot-bg); border-right: 1px solid var(--pbot-line); }\n.pbot-nav button { text-align: left; justify-content: space-between; border-color: transparent; background: transparent; padding: 11px 12px; color: var(--pbot-muted); }\n.pbot-nav button[aria-selected=true] { color: var(--pbot-accent); background: var(--pbot-tint); font-weight: 600; }\n.pbot-nav small { font-size: 11px; font-variant-numeric: tabular-nums; opacity: .8; }\n.pbot-main { min-width: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 26px 28px; }\n.pbot-page-title { margin-bottom: 22px; display: grid; gap: 5px; }\n.pbot-muted { color: var(--pbot-muted); font-size: 13px; overflow-wrap: anywhere; }\n.pbot-footer { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 10px 22px; border-top: 1px solid var(--pbot-line); color: var(--pbot-muted); font-size: 12px; }\n.pbot-footer > span { flex: 1; }\n.pbot-footer button { min-height: 28px; padding: 4px 9px; font-size: 12px; }\n.pbot-notice { position: sticky; top: -26px; z-index: 2; padding: 12px 14px; margin: -6px 0 18px; border: 1px solid var(--pbot-line); border-left: 3px solid var(--pbot-accent); background: var(--pbot-surface); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow-y: auto; }\n.pbot-notice[data-tone=error] { border-left-color: var(--pbot-danger); }\n.pbot-notice:empty { display: none; }\n.pbot-stack { display: grid; gap: 16px; }\n.pbot-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }\n.pbot-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }\n.pbot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }\n.pbot-counts { margin: -8px 0 20px !important; }\n.pbot-setting { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 0; border-top: 1px solid var(--pbot-line); }\n.pbot-setting > div { min-width: 0; }\n.pbot-setting h3 { margin-bottom: 8px; }\n.pbot-setting > button { flex-shrink: 0; }\n.pbot-card { padding: 18px; border: 1px solid var(--pbot-line); border-radius: 12px; background: var(--pbot-surface); min-width: 0; }\n.pbot-card > :is(h3, .pbot-between) { margin-bottom: 12px; }\n.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; }\n.pbot-badge::before { content: \"\"; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }\n.pbot-badge:is([data-state=busy],[data-state=running],[data-state=starting],[data-state=preparing]) { color: var(--pbot-accent); background: var(--pbot-tint); }\n.pbot-badge:is([data-state=error],[data-state=failed]) { color: var(--pbot-danger); }\n.pbot-badge:is([data-state=ready],[data-state=completed]) { color: var(--dsw-alias-state-success-primary, #26834b); }\n.pbot-badge:is([data-state=paused],[data-state=stopping]) { color: var(--dsw-alias-state-warn-label, #9a6500); }\n.pbot-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 18px; margin: 12px 0; font-size: 13px; }\n.pbot-facts dt { color: var(--pbot-muted); }\n.pbot-facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }\n.pbot-disclosure { margin: 16px 0; padding: 12px 14px; border: 1px solid var(--pbot-line); border-radius: 10px; }\n.pbot-disclosure > summary { cursor: pointer; font-size: 13px; font-weight: 550; }\n.pbot-disclosure[open] > summary { margin-bottom: 16px; }\n.pbot-disclosure .pbot-disclosure { background: var(--pbot-bg); }\n.pbot-field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; font-size: 13px; }\n.pbot-field > span { font-weight: 500; }\n.pbot-field :is(input,textarea,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; }\n.pbot-field input[type=file] { padding: 7px; font-size: 12px; }\n.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; }\n.pbot-field textarea { resize: vertical; min-height: 84px; }\n.pbot-field input::placeholder, .pbot-field textarea::placeholder { color: var(--pbot-muted); opacity: .8; }\n.pbot-split { display: grid; grid-template-columns: minmax(180px, 230px) minmax(0, 1fr); gap: 22px; align-items: start; }\n.pbot-list { display: grid; align-content: start; grid-auto-rows: max-content; gap: 6px; max-height: 470px; overflow-y: auto; padding: 3px; }\n.pbot-management .pbot-list-item { display: block; width: 100%; text-align: left; padding: 12px; border: 1px solid transparent; min-width: 0; }\n.pbot-list-item[aria-pressed=true] { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }\n.pbot-list-item strong { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }\n.pbot-list-item .pbot-muted { margin-top: 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }\n.pbot-empty { padding: 38px 20px; border: 1px dashed var(--pbot-line); border-radius: 12px; text-align: center; display: grid; gap: 8px; }\n.pbot-empty h3 { font-weight: 550; }\n.pbot-empty button { justify-self: center; margin-top: 10px; }\n.pbot-detail { min-width: 0; display: grid; gap: 18px; }\n.pbot-detail-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }\n.pbot-prose { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 10px 0; line-height: 1.7; }\n.pbot-raw { font: 12px/1.6 ui-monospace, SFMono-Regular, monospace; max-height: 340px; overflow: auto; }\n.pbot-transcript { margin-top: 14px; }\n.pbot-event { border-left: 2px solid var(--pbot-line); padding: 0 0 0 14px; margin: 18px 0; }\n.pbot-event .pbot-prose { font-size: 13px; }\n.pbot-event .pbot-row, .pbot-message .pbot-row { justify-content: space-between; }\n.pbot-management .pbot-pagination { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0; color: var(--pbot-muted); font-size: 12px; }\n.pbot-pagination button { font-size: 12px; min-height: 30px; padding: 5px 9px; }\n.pbot-message { padding: 16px 0; border-bottom: 1px solid var(--pbot-line); }\n.pbot-message:last-child { border-bottom: 0; }\n.pbot-message .pbot-prose { font-size: 13px; }\n.pbot-search { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto; gap: 12px; align-items: end; }\n.pbot-search .pbot-field { margin: 0; }\n.pbot-search > button { margin-bottom: 2px; }\n.pbot-history-results { display: grid; gap: 10px; margin: 18px 0; }\n.pbot-history-results article { border: 1px solid var(--pbot-line); border-radius: 10px; padding: 16px; }\n.pbot-history-results article[aria-current=true] { border-color: var(--pbot-accent); }\n.pbot-warning { border-left: 3px solid var(--dsw-alias-state-warn-primary, #ab7a15); padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }\n@media (max-width: 800px) {\n .pbot-management { width: calc(100vw - 24px); height: calc(100dvh - 32px); border-radius: 12px; }\n .pbot-shell { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr) auto; }\n .pbot-nav { flex-direction: row; padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--pbot-line); }\n .pbot-nav button { flex: 1; justify-content: center; padding: 8px; }\n .pbot-nav small { display: none; }\n .pbot-main { padding: 22px 18px; }\n .pbot-notice { top: -22px; }\n .pbot-header { padding: 14px 18px; }\n .pbot-split { grid-template-columns: minmax(150px, 190px) minmax(0, 1fr); gap: 16px; }\n}\n@media (max-width: 600px) {\n .pbot-management { width: calc(100vw - 12px); height: calc(100dvh - 16px); }\n .pbot-grid, .pbot-split { grid-template-columns: minmax(0, 1fr); }\n .pbot-list { max-height: 215px; }\n .pbot-search { grid-template-columns: minmax(0, 1fr) 110px; }\n .pbot-search > button { grid-column: 1 / -1; }\n .pbot-footer { padding: 8px 14px; }\n .pbot-location { max-width: 68vw; }\n}\n";
|
|
1
|
+
export declare const managementStyles = "\n.pbot-management {\n --pbot-bg: var(--dsw-alias-bg-base, #f8f9fb);\n --pbot-surface: var(--dsw-alias-bg-layer-1, #fff);\n --pbot-ink: var(--dsw-alias-label-primary, #20232b);\n --pbot-muted: var(--dsw-alias-label-secondary, #696e79);\n --pbot-line: var(--dsw-alias-border-l2, #e3e5eb);\n --pbot-accent: var(--dsw-alias-brand-primary, #4d6bfe);\n --pbot-tint: color-mix(in srgb, var(--pbot-accent) 9%, var(--pbot-surface));\n --pbot-danger: var(--dsw-alias-state-error-primary, #c93535);\n width: min(1180px, calc(100vw - 48px)); height: min(820px, calc(100dvh - 64px));\n max-width: none; max-height: none; padding: 0; margin: auto; overflow: hidden;\n border: 1px solid var(--pbot-line); border-radius: 12px; color: var(--pbot-ink); background: var(--pbot-surface);\n box-shadow: 0 12px 40px #0002; font: 14px/1.55 var(--dsw-font-family, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif);\n}\n.pbot-management::backdrop { background: #10182866; }\n.pbot-management *, .pbot-management *::before, .pbot-management *::after { box-sizing: border-box; }\n.pbot-management [hidden] { display: none !important; }\n.pbot-management h2, .pbot-management h3, .pbot-management h4, .pbot-management p { margin: 0; }\n.pbot-management h2 { font-size: 21px; font-weight: 600; }\n.pbot-management h3 { font-size: 16px; font-weight: 600; }\n.pbot-management h4 { font-size: 14px; font-weight: 600; }\n.pbot-management button, .pbot-management input, .pbot-management textarea, .pbot-management select { font: inherit; color: inherit; }\n.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; }\n.pbot-management button:hover:not(:disabled) { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }\n.pbot-management button:disabled { opacity: .45; cursor: not-allowed; }\n.pbot-management :is(button, input, textarea, select, summary):focus-visible { outline: 2px solid var(--pbot-accent); outline-offset: 3px; }\n.pbot-management button.pbot-primary { background: var(--pbot-accent); border-color: var(--pbot-accent); color: var(--pbot-surface); font-weight: 600; }\n.pbot-management button.pbot-primary:hover:not(:disabled) { filter: brightness(.94); background: var(--pbot-accent); }\n.pbot-management button.pbot-quiet { border-color: transparent; background: transparent; }\n.pbot-management button.pbot-danger { color: var(--pbot-danger); }\n.pbot-management button[data-busy=true]::after { content: \"\u2026\"; }\n.pbot-shell { height: 100%; display: grid; grid-template-columns: 178px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }\n.pbot-header { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--pbot-line); }\n.pbot-brand { font-size: 16px; font-weight: 650; letter-spacing: -.3px; }\n.pbot-location { color: var(--pbot-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; max-width: 65vw; }\n.pbot-header-copy { min-width: 0; flex: 1; }\n.pbot-management .pbot-close { width: 34px; padding: 0; font-size: 22px; }\n.pbot-nav { display: flex; flex-direction: column; gap: 6px; padding: 22px 12px; background: var(--pbot-bg); border-right: 1px solid var(--pbot-line); }\n.pbot-nav button { text-align: left; justify-content: space-between; border-color: transparent; background: transparent; padding: 11px 12px; color: var(--pbot-muted); }\n.pbot-nav button[aria-selected=true] { color: var(--pbot-accent); background: var(--pbot-tint); font-weight: 600; }\n.pbot-nav small { font-size: 11px; font-variant-numeric: tabular-nums; opacity: .8; }\n.pbot-main { min-width: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 26px 28px; }\n.pbot-page-title { margin-bottom: 22px; display: grid; gap: 5px; }\n.pbot-muted { color: var(--pbot-muted); font-size: 13px; overflow-wrap: anywhere; }\n.pbot-footer { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 10px 22px; border-top: 1px solid var(--pbot-line); color: var(--pbot-muted); font-size: 12px; }\n.pbot-footer > span { flex: 1; }\n.pbot-footer button { min-height: 28px; padding: 4px 9px; font-size: 12px; }\n.pbot-notice { position: sticky; top: -26px; z-index: 2; padding: 12px 14px; margin: -6px 0 18px; border: 1px solid var(--pbot-line); border-left: 3px solid var(--pbot-accent); background: var(--pbot-surface); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow-y: auto; }\n.pbot-notice[data-tone=error] { border-left-color: var(--pbot-danger); }\n.pbot-notice:empty { display: none; }\n.pbot-stack { display: grid; gap: 16px; }\n.pbot-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }\n.pbot-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }\n.pbot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }\n.pbot-counts { margin: -8px 0 20px !important; }\n.pbot-setting { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 0; border-top: 1px solid var(--pbot-line); }\n.pbot-setting > div { min-width: 0; }\n.pbot-setting h3 { margin-bottom: 8px; }\n.pbot-setting > button { flex-shrink: 0; }\n.pbot-card { padding: 18px; border: 1px solid var(--pbot-line); border-radius: 12px; background: var(--pbot-surface); min-width: 0; }\n.pbot-card > :is(h3, .pbot-between) { margin-bottom: 12px; }\n.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; }\n.pbot-badge::before { content: \"\"; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }\n.pbot-badge:is([data-state=busy],[data-state=running],[data-state=starting]) { color: var(--pbot-accent); background: var(--pbot-tint); }\n.pbot-badge:is([data-state=error],[data-state=failed]) { color: var(--pbot-danger); }\n.pbot-badge[data-state=completed] { color: var(--dsw-alias-state-success-primary, #26834b); }\n.pbot-badge:is([data-state=paused],[data-state=stopping]) { color: var(--dsw-alias-state-warn-label, #9a6500); }\n.pbot-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 18px; margin: 12px 0; font-size: 13px; }\n.pbot-facts dt { color: var(--pbot-muted); }\n.pbot-facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }\n.pbot-disclosure { margin: 16px 0; padding: 12px 14px; border: 1px solid var(--pbot-line); border-radius: 10px; }\n.pbot-disclosure > summary { cursor: pointer; font-size: 13px; font-weight: 550; }\n.pbot-disclosure[open] > summary { margin-bottom: 16px; }\n.pbot-disclosure .pbot-disclosure { background: var(--pbot-bg); }\n.pbot-field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; font-size: 13px; }\n.pbot-field > span { font-weight: 500; }\n.pbot-field :is(input,textarea,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; }\n.pbot-field input[type=file] { padding: 7px; font-size: 12px; }\n.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; }\n.pbot-field textarea { resize: vertical; min-height: 84px; }\n.pbot-field input::placeholder, .pbot-field textarea::placeholder { color: var(--pbot-muted); opacity: .8; }\n.pbot-split { display: grid; grid-template-columns: minmax(180px, 230px) minmax(0, 1fr); gap: 22px; align-items: start; }\n.pbot-list { display: grid; align-content: start; grid-auto-rows: max-content; gap: 6px; max-height: 470px; overflow-y: auto; padding: 3px; }\n.pbot-management .pbot-list-item { display: block; width: 100%; text-align: left; padding: 12px; border: 1px solid transparent; min-width: 0; }\n.pbot-list-item[aria-pressed=true] { background: var(--pbot-tint); border-color: color-mix(in srgb, var(--pbot-accent) 40%, var(--pbot-line)); }\n.pbot-list-item strong { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }\n.pbot-list-item .pbot-muted { margin-top: 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }\n.pbot-empty { padding: 38px 20px; border: 1px dashed var(--pbot-line); border-radius: 12px; text-align: center; display: grid; gap: 8px; }\n.pbot-empty h3 { font-weight: 550; }\n.pbot-empty button { justify-self: center; margin-top: 10px; }\n.pbot-detail { min-width: 0; display: grid; gap: 18px; }\n.pbot-detail-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }\n.pbot-prose { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 10px 0; line-height: 1.7; }\n.pbot-raw { font: 12px/1.6 ui-monospace, SFMono-Regular, monospace; max-height: 340px; overflow: auto; }\n.pbot-transcript { margin-top: 14px; }\n.pbot-event { border-left: 2px solid var(--pbot-line); padding: 0 0 0 14px; margin: 18px 0; }\n.pbot-event .pbot-prose { font-size: 13px; }\n.pbot-event .pbot-row, .pbot-message .pbot-row { justify-content: space-between; }\n.pbot-management .pbot-pagination { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0; color: var(--pbot-muted); font-size: 12px; }\n.pbot-pagination button { font-size: 12px; min-height: 30px; padding: 5px 9px; }\n.pbot-message { padding: 16px 0; border-bottom: 1px solid var(--pbot-line); }\n.pbot-message:last-child { border-bottom: 0; }\n.pbot-message .pbot-prose { font-size: 13px; }\n.pbot-search { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto; gap: 12px; align-items: end; }\n.pbot-search .pbot-field { margin: 0; }\n.pbot-search > button { margin-bottom: 2px; }\n.pbot-history-results { display: grid; gap: 10px; margin: 18px 0; }\n.pbot-history-results article { border: 1px solid var(--pbot-line); border-radius: 10px; padding: 16px; }\n.pbot-history-results article[aria-current=true] { border-color: var(--pbot-accent); }\n.pbot-warning { border-left: 3px solid var(--dsw-alias-state-warn-primary, #ab7a15); padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }\n@media (max-width: 800px) {\n .pbot-management { width: calc(100vw - 24px); height: calc(100dvh - 32px); border-radius: 12px; }\n .pbot-shell { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr) auto; }\n .pbot-nav { flex-direction: row; padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--pbot-line); }\n .pbot-nav button { flex: 1; justify-content: center; padding: 8px; }\n .pbot-nav small { display: none; }\n .pbot-main { padding: 22px 18px; }\n .pbot-notice { top: -22px; }\n .pbot-header { padding: 14px 18px; }\n .pbot-split { grid-template-columns: minmax(150px, 190px) minmax(0, 1fr); gap: 16px; }\n}\n@media (max-width: 600px) {\n .pbot-management { width: calc(100vw - 12px); height: calc(100dvh - 16px); }\n .pbot-grid, .pbot-split { grid-template-columns: minmax(0, 1fr); }\n .pbot-list { max-height: 215px; }\n .pbot-search { grid-template-columns: minmax(0, 1fr) 110px; }\n .pbot-search > button { grid-column: 1 / -1; }\n .pbot-footer { padding: 8px 14px; }\n .pbot-location { max-width: 68vw; }\n}\n";
|
package/lib/ui/dsh/styles.js
CHANGED
|
@@ -62,9 +62,9 @@ export const managementStyles = `
|
|
|
62
62
|
.pbot-card > :is(h3, .pbot-between) { margin-bottom: 12px; }
|
|
63
63
|
.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
64
|
.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]
|
|
65
|
+
.pbot-badge:is([data-state=busy],[data-state=running],[data-state=starting]) { color: var(--pbot-accent); background: var(--pbot-tint); }
|
|
66
66
|
.pbot-badge:is([data-state=error],[data-state=failed]) { color: var(--pbot-danger); }
|
|
67
|
-
.pbot-badge
|
|
67
|
+
.pbot-badge[data-state=completed] { color: var(--dsw-alias-state-success-primary, #26834b); }
|
|
68
68
|
.pbot-badge:is([data-state=paused],[data-state=stopping]) { color: var(--dsw-alias-state-warn-label, #9a6500); }
|
|
69
69
|
.pbot-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 18px; margin: 12px 0; font-size: 13px; }
|
|
70
70
|
.pbot-facts dt { color: var(--pbot-muted); }
|
package/lib/ui/presentation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const states = {
|
|
2
2
|
starting: "启动中", busy: "执行中", idle: "待命", stopping: "停止中", stopped: "已停止", error: "需要处理",
|
|
3
3
|
running: "进行中", paused: "已暂停", finished: "已结束", completed: "已完成", failed: "失败",
|
|
4
|
-
cancelled: "已取消", interrupted: "已中断",
|
|
4
|
+
cancelled: "已取消", interrupted: "已中断",
|
|
5
5
|
open: "待安排", closed: "已关闭",
|
|
6
6
|
};
|
|
7
7
|
export const stateLabel = (state) => states[String(state)] ?? String(state ?? "未知");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "personal-bot",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/realqiyan/personal-bot.git"
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"./*": "./*"
|
|
56
56
|
},
|
|
57
57
|
"files": [
|
|
58
|
-
"npm-shrinkwrap.json",
|
|
59
58
|
"bin",
|
|
60
59
|
"lib",
|
|
61
60
|
"src",
|
|
@@ -63,10 +62,7 @@
|
|
|
63
62
|
".claude-plugin/plugin.json",
|
|
64
63
|
".claude-plugin/marketplace.json",
|
|
65
64
|
"hooks/hooks.json",
|
|
66
|
-
"scripts/setup-python.py",
|
|
67
65
|
"scripts/README.md",
|
|
68
|
-
"python/requirements.lock",
|
|
69
|
-
"python/README.md",
|
|
70
66
|
"README.md",
|
|
71
67
|
"README.zh-CN.md",
|
|
72
68
|
"CONTEXT.md",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: pbot
|
|
3
|
-
description: 初始化 Personal Bot
|
|
3
|
+
description: 初始化 Personal Bot 工作区或查看状态。
|
|
4
4
|
disable-model-invocation: true
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -11,7 +11,6 @@ disable-model-invocation: true
|
|
|
11
11
|
```sh
|
|
12
12
|
node "${CLAUDE_SKILL_DIR}/../../../../lib/claude.js" init
|
|
13
13
|
node "${CLAUDE_SKILL_DIR}/../../../../lib/claude.js" status
|
|
14
|
-
node "${CLAUDE_SKILL_DIR}/../../../../lib/claude.js" python setup
|
|
15
14
|
```
|
|
16
15
|
|
|
17
|
-
根据用户参数选择一条:`init` 补建资料并启用工作区,`status`
|
|
16
|
+
根据用户参数选择一条:`init` 补建资料并启用工作区,`status` 只查看工作区及当前配置状态。省略参数时查看状态。返回命令的实际结果和需要处理的错误。
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
|
|
26
26
|
保存有后续用途的结论、方法、决策和产物;普通问答不逐轮存档。保存前查找同主题正文,直接修订,合并重复内容并替换过时说明。必要的实现细节放入对应技术资料,排查过程和测试流水不逐次追加到正文。更新或整理时使用 project-maintenance。可再次查询的数据按记录的口径获取。保留用户资料、历史记录和备份。
|
|
27
27
|
|
|
28
|
-
环境上下文中的 `workspaceRoot` 是资料工作区根目录,`resourceRoot`
|
|
28
|
+
环境上下文中的 `workspaceRoot` 是资料工作区根目录,`resourceRoot` 是包内资料根目录。资料路径相对工作区根目录,命令与文件工具按实际 cwd 解析路径。需要 Python 计算时读取包内 `references/compute.md`;计算、项目构建和测试遵循项目声明的环境。
|
|
29
29
|
|
|
30
30
|
答复先给结论,按需补充说明和产物路径。自然语言说明直接回答当前问题,不惯常追加否定式限定或免责声明,也不设想用户未提出的推论再逐一否定。必要的未知、条件和风险清楚说明一次。数值注明影响理解的对象、期间、单位与口径。任务要求、操作权限、必要确认和规定的输出格式照常遵循。
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
# Python 计算
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## 环境异常
|
|
3
|
+
## 按项目运行
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
使用当前宿主的原生 Bash,沿用项目声明的解释器、依赖、工作目录、脚本或模块入口、输入参数与输出位置。尚无约定时,先检查可用解释器及本次计算需要的库,再选择运行方式。依赖和 Python 版本以项目及所选库的要求为准。
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
包内相对导入通常使用项目根目录下的 `python -m 包.模块`,不为绕过导入错误随意改 `sys.path`。相对数据路径取决于 cwd 或脚本自身的处理;交付时提供实际产物路径,并检查结果。
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
解释器或依赖异常时,检查实际路径、导入错误及项目配置,继续不受影响的工作。专家需要主会话协助时交回具体阻碍和所需条件。
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## 第三方库
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
按任务选择当前环境中可用的库,并查阅所用版本的原生 API:NumPy、pandas 用于数组和表格,SciPy、statsmodels、scikit-learn(导入名 sklearn)用于数值分析、统计和建模,Matplotlib、seaborn、Bokeh 用于绘图,openpyxl、PyArrow 用于文件读写。
|
|
16
14
|
|
|
17
15
|
- 无图形界面的绘图:在导入 pyplot/seaborn 前选择 Matplotlib 的 Agg 后端,保存文件并关闭 figure。
|
|
18
16
|
- Excel、Parquet、Feather:按格式选择 openpyxl 或 pyarrow;核对读写后的字段类型、时间单位与时区。Excel 不直接保存带时区的 datetime,转换前明确目标时区。
|
package/scripts/README.md
CHANGED
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
|
|
14
14
|
## 安装包检查
|
|
15
15
|
|
|
16
|
-
先 `npm pack`,使用生成的实际 tarball 检查交付路径;`npm pack --dry-run`
|
|
16
|
+
先 `npm pack`,使用生成的实际 tarball 检查交付路径;`npm pack --dry-run` 仅用于查看清单。完整开发 npm-shrinkwrap.json 留在仓库,不进入发布包;消费者按正常运行依赖安装。
|
|
17
17
|
|
|
18
18
|
| 命令 | 检查内容 | 环境 |
|
|
19
19
|
| --- | --- | --- |
|
|
20
|
-
| `node scripts/check-consumer.mjs <tarball>` | 独立 CLI、Pi
|
|
20
|
+
| `node scripts/check-consumer.mjs <tarball>` | 独立 CLI、Pi 扩展、技能、工具与资料初始化;安装 Pi 前核对消费根和包内均未安装宿主依赖 | CI 使用 Node.js 22.19.0,脚本安装锁定的 Pi SDK |
|
|
21
21
|
| `node scripts/check-dsh-consumer.mjs <tarball>` | dsh 原生插件安装、独立 CLI 与 Host 导入;检查无需单独安装 TypeBox 或宿主 SDK | Node.js 24.9+、仓库开发依赖和 PATH 中的 pnpm |
|
|
22
|
-
| `node scripts/check-claude-consumer.mjs <tarball>` | 实际 tarball
|
|
22
|
+
| `node scripts/check-claude-consumer.mjs <tarball>` | 实际 tarball 安装与原生 plugin validate;另在直接解包且没有 node_modules 的目录执行 hook、CLI 和资料读取 | Node.js 22.19+、Claude Code 2.1.325+;PBOT_CLAUDE_COMMAND 可指定 CLI |
|
|
23
23
|
|
|
24
|
-
上述脚本使用隔离用户目录、宿主配置与工作目录,结束后清理临时目录,不调用模型。Pi
|
|
24
|
+
上述脚本使用隔离用户目录、宿主配置与工作目录,结束后清理临时目录,不调用模型。Pi 检查扩展加载与资料初始化,dsh 通过原生 schema 收集导入 Host。Claude 在独立 npm 消费目录安装实际 tarball,核对版本、原生资源与 hook 参数;再从直接解包目录运行未启用工作区的 hook/status,以及已启用工作区的专家资料读取,覆盖原生 marketplace 不安装 npm 依赖的缓存目录。不访问日常会话或凭据。
|
|
25
25
|
|
|
26
26
|
Claude 包内路径包括 `.claude-plugin/plugin.json`、marketplace、`hooks/hooks.json`、`lib/claude.js`、`resources/claude/skills/pbot/SKILL.md`、原生 Markdown agent、共享资料与工作方法技能。`resources/skills/.claude-plugin/plugin.json` 保留给 Pi/dsh 的 Claude ACP 目标。可对实际安装包执行原生校验:
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ Claude 包内路径包括 `.claude-plugin/plugin.json`、marketplace、`hooks/ho
|
|
|
29
29
|
claude plugin validate /absolute/path/to/installed/package/.claude-plugin/plugin.json
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
消费环境不依赖仓库 cwd、dist 或开发 node_modules
|
|
32
|
+
消费环境不依赖仓库 cwd、dist 或开发 node_modules。发布后运行 `node scripts/check-consumer.mjs npm:personal-bot@<version>`,通过公开 registry 按包名安装再执行相同检查;分别记录实际 Node/npm 版本,不能用本地 tarball 安装代替这条路径。只有实际执行的项目才记录为通过,版本与未执行项写在任务、PR 或 CI。
|
|
33
33
|
|
|
34
34
|
## 本地 Node hook 检查
|
|
35
35
|
|
|
@@ -44,7 +44,3 @@ Claude 的实际首任务上下文、`/personal-bot:pbot` 技能调用、工作
|
|
|
44
44
|
在明确批准、单独准备 Pi/dsh/Claude 模型与测试认证的环境执行 `npm run test:e2e:acp`。该命令在临时工作区调用三个真实后端,省略 model、thinking 和 provider 验证默认值;另测 Claude 显式 low 覆盖原生环境 max。检查文件结果、报告分页、停止耗时,并对照 Claude 原生请求中的模型与思考等级。它单独运行,不进入 `npm test`,属于 Pi/dsh 的 ACP 目标验证。
|
|
45
45
|
|
|
46
46
|
入口默认从 PATH 查找。可用 `PBOT_ACP_E2E_PI_COMMAND`、`PBOT_ACP_E2E_DSH_COMMAND`、`PBOT_ACP_E2E_CLAUDE_COMMAND` 指定已有可执行文件路径;dsh 仍使用 acp profile。`PBOT_ACP_E2E_OUTPUT_DIR` 指定输出目录,默认使用临时目录;每个工作区保留 input.json、output.json、report.txt 和 result.json;Claude 用例还保留仅含模型与等级的 native-requests.json。
|
|
47
|
-
|
|
48
|
-
## Python 准备
|
|
49
|
-
|
|
50
|
-
setup-python.py 按 python/requirements.lock 准备用户共享 venv。工作区启用后自动调用,也可运行独立脚本。Pi/dsh 使用 `/pbot python setup` 重试;Claude 使用原生 `/personal-bot:pbot python setup` 技能或 `node <plugin>/lib/claude.js python setup`。路径、依赖与排障见 [Python 说明](../python/README.md)。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Ajv } from "ajv";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
3
|
+
import type { ValidateFunction } from "ajv";
|
|
4
|
+
import { object } from "./json.js";
|
|
5
|
+
|
|
6
|
+
export function schema(value: unknown): ValidateFunction {
|
|
7
|
+
if (!object(value)) throw new Error("需要对象形式的 JSON Schema。");
|
|
8
|
+
const ajv = new Ajv({ strict: false, allErrors: false, validateFormats: true, coerceTypes: false, useDefaults: false, removeAdditional: false });
|
|
9
|
+
addFormats.default(ajv);
|
|
10
|
+
return ajv.compile(value);
|
|
11
|
+
}
|
package/src/common/validation.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import { Ajv } from "ajv";
|
|
2
|
-
import addFormats from "ajv-formats";
|
|
3
|
-
import type { ValidateFunction } from "ajv";
|
|
4
|
-
import { object } from "./json.js";
|
|
5
|
-
|
|
6
|
-
export function schema(value: unknown): ValidateFunction {
|
|
7
|
-
if (!object(value)) throw new Error("需要对象形式的 JSON Schema。");
|
|
8
|
-
const ajv = new Ajv({ strict: false, allErrors: false, validateFormats: true, coerceTypes: false, useDefaults: false, removeAdditional: false });
|
|
9
|
-
addFormats.default(ajv);
|
|
10
|
-
return ajv.compile(value);
|
|
11
|
-
}
|
|
12
1
|
export function requireThat(condition: unknown, message: string): asserts condition {
|
|
13
2
|
if (!condition) throw new Error(message);
|
|
14
3
|
}
|