personal-bot 0.3.5 → 0.3.7

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.
Files changed (86) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +191 -65
  4. package/README.zh-CN.md +189 -63
  5. package/docs/README.md +2 -2
  6. package/docs/architecture/design.md +3 -4
  7. package/docs/architecture/model-context.md +1 -2
  8. package/docs/guides/capabilities.md +4 -8
  9. package/docs/hosts/antigravity.md +4 -2
  10. package/docs/hosts/pi.md +4 -15
  11. package/docs/maintainers/release.md +2 -2
  12. package/lib/antigravity-plugin/lib/extension/acp-worker.js +2 -2
  13. package/lib/antigravity-plugin/lib/extension/cli.js +1403 -1504
  14. package/lib/antigravity-plugin/lib/extension/mcp.js +66 -49
  15. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +2 -2
  16. package/lib/antigravity-plugin/package.json +1 -1
  17. package/lib/antigravity-plugin/plugin.json +1 -1
  18. package/lib/antigravity-plugin/resources/agents/coordinator.md +3 -7
  19. package/lib/antigravity-plugin/resources/agents/general-purpose.md +3 -3
  20. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -2
  21. package/lib/antigravity-plugin/resources/prompts/workspace.md +12 -16
  22. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +7 -6
  23. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +0 -4
  24. package/lib/antigravity-plugin/skills/pbot/SKILL.md +14 -6
  25. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +7 -6
  26. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
  27. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  28. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  29. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +2 -2
  30. package/lib/extension/acp-worker.js +2 -2
  31. package/lib/extension/cli.js +1403 -1504
  32. package/lib/extension/mcp/tool-contract.js +49 -55
  33. package/lib/extension/mcp/workers.d.ts +6 -0
  34. package/lib/extension/mcp/workers.js +25 -8
  35. package/lib/extension/mcp.js +66 -49
  36. package/lib/integrations/agent-resources.js +2 -2
  37. package/lib/qoder-plugin/.mcp.json +2 -2
  38. package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
  39. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  40. package/lib/qoder-plugin/skills/pbot/SKILL.md +2 -2
  41. package/lib/tools/history/contract.js +12 -12
  42. package/package.json +1 -1
  43. package/resources/agents/coordinator.md +3 -7
  44. package/resources/agents/general-purpose.md +3 -3
  45. package/resources/antigravity/skills/pbot/SKILL.md +14 -6
  46. package/resources/claude/skills/pbot/SKILL.md +14 -6
  47. package/resources/plugin/skills/pbot/SKILL.md +2 -2
  48. package/resources/prompts/history-coordinator.md +1 -2
  49. package/resources/prompts/plugin-coordinator.md +1 -2
  50. package/resources/prompts/workspace.md +12 -16
  51. package/resources/skills/provider-connections/SKILL.md +7 -6
  52. package/resources/templates/workspace-agents.md +0 -4
  53. package/src/extension/cli/commands/install.ts +77 -0
  54. package/src/extension/cli/index.ts +3 -4
  55. package/src/extension/mcp/tool-contract.ts +49 -55
  56. package/src/extension/mcp/workers.ts +32 -10
  57. package/src/integrations/agent-resources.ts +2 -2
  58. package/src/integrations/installation/installers/antigravity.ts +49 -0
  59. package/src/integrations/installation/installers/claude.ts +30 -0
  60. package/src/integrations/installation/installers/codex.ts +56 -0
  61. package/src/integrations/installation/installers/dsh.ts +25 -0
  62. package/src/integrations/installation/installers/pi.ts +26 -0
  63. package/src/integrations/installation/installers/qoder.ts +49 -0
  64. package/src/integrations/installation/installers/registry.ts +48 -0
  65. package/src/integrations/installation/processes.ts +2 -41
  66. package/src/model/installation.ts +28 -36
  67. package/src/pbot.ts +1 -1
  68. package/src/services/installation/install-service.ts +107 -0
  69. package/src/tools/history/contract.ts +12 -12
  70. package/lib/antigravity-plugin/resources/references/compute-finance.md +0 -22
  71. package/lib/antigravity-plugin/resources/references/compute.md +0 -16
  72. package/lib/antigravity-plugin/resources/references/task-conductor.md +0 -25
  73. package/lib/common/package-source.js +0 -16
  74. package/lib/extension/setup/guard.js +0 -11
  75. package/lib/integrations/installation/pi-bridge.js +0 -131
  76. package/lib/model/installation.js +0 -1
  77. package/resources/installer/plugins.json +0 -16
  78. package/resources/references/compute-finance.md +0 -22
  79. package/resources/references/compute.md +0 -16
  80. package/resources/references/task-conductor.md +0 -25
  81. package/src/extension/cli/commands/setup.ts +0 -159
  82. package/src/extension/setup/guard.ts +0 -12
  83. package/src/integrations/installation/pi-bridge.ts +0 -109
  84. package/src/integrations/installation/pi-setup.ts +0 -165
  85. package/src/services/installation/setup-service.ts +0 -91
  86. package/src/ui/setup.ts +0 -40
@@ -50,24 +50,24 @@ export const historyResultSchema = Type.Object({
50
50
  });
51
51
 
52
52
  export const historyDescription =
53
- "查询当前工作区的历史问答与各维度摘要,host 可筛选来源(如 pi、dsh、claude、antigravity),dimension 可筛选 raw 原文或特定摘要维度(如 monthly 月度汇总、session 会话摘要)。" +
54
- "search 按不区分大小写的连续关键词匹配原文和摘要,省略 query 列出各会话或指定维度摘要;无匹配时换词。" +
55
- "read 按节点 id 展开正文与上下级(可从 monthly 下钻至 session 摘要,再下钻至 exchange 原文),nextOffset 续读正文,nextChildrenOffset 续读子节点。归档不含工具调用日志。";
53
+ "查询当前工作区跨宿主历史问答与摘要归档。" +
54
+ "search 按不区分大小写的连续关键词匹配原文与摘要,省略 query 列出各会话或指定维度摘要;" +
55
+ "read 按 id 读取正文与上下级(可从 monthly 汇总下钻至 session 摘要和 exchange 原文),用 nextOffset 与 nextChildrenOffset 分页续读。";
56
56
 
57
57
  export const historyParameters = Type.Object({
58
58
  action: Type.Union([Type.Literal("search"), Type.Literal("read")], {
59
- description: "search 搜索或列会话;read 读取指定节点正文与上下级。各动作仅读取自身字段,其余字段忽略。",
59
+ description: "search 搜索或列表;read 按 id 读取正文与上下级。仅读取对应动作参数,其余忽略。",
60
60
  }),
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
- query: nullable(Type.String({ description: "仅 search:不区分大小写的连续关键词;省略时列出各会话(或指定维度摘要)。" })),
64
- sessionId: nullable(Type.String({ description: "仅 search:限定在指定会话 ID 内搜索。" })),
61
+ host: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "来源宿主筛选(如 pi、dsh、claude、antigravity、codex、qoder);省略查全部。" })),
62
+ dimension: nullable(Type.String({ pattern: historyIdentifierPattern.source, description: "仅 search:raw 仅原文,或指定摘要维度(如 monthly、session);省略查全部。" })),
63
+ query: nullable(Type.String({ description: "仅 search:连续关键词(不区分大小写);省略列会话或指定维度摘要。" })),
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
- id: nullable(Type.String({ description: "仅 read,必填:search 或上下级返回的节点 id。" })),
68
- offset: nullable(Type.Integer({ minimum: 0, description: "search:匹配结果偏移;read:正文字符偏移。默认 0。" })),
69
- limit: nullable(Type.Integer({ minimum: 1, maximum: historyPageLimits.read.max, description: `search:最多返回条数(默认 ${historyPageLimits.search.default},上限 ${historyPageLimits.search.max});read:正文字符数(默认 ${historyPageLimits.read.default})。` })),
70
- childrenOffset: nullable(Type.Integer({ minimum: 0, description: "仅 read:子节点列表偏移,默认 0;续读传上页 nextChildrenOffset。" })),
67
+ id: nullable(Type.String({ description: "仅 read,必填:节点 id(来自 search 或上下级)。" })),
68
+ offset: nullable(Type.Integer({ minimum: 0, description: "search 为结果偏移,read 为正文字符偏移;默认 0。" })),
69
+ limit: nullable(Type.Integer({ minimum: 1, maximum: historyPageLimits.read.max, description: `search:返回条数(1–${historyPageLimits.search.max},默认 ${historyPageLimits.search.default});read:正文字符数(默认 ${historyPageLimits.read.default})。` })),
70
+ childrenOffset: nullable(Type.Integer({ minimum: 0, description: "仅 read:子节点偏移,默认 0;续读传上次 nextChildrenOffset。" })),
71
71
  }, { additionalProperties: false });
72
72
 
73
73
  export type HistoryInput =
@@ -1,22 +0,0 @@
1
- # 指标与回测
2
-
3
- ## TA-Lib
4
-
5
- 通过 `import talib` 使用原生函数。用 `talib.get_function_groups()`、`talib.get_functions()` 和 `help(talib.函数名)` 核对能力、参数与返回值。
6
-
7
- 计算前核对时间顺序、复权、缺失数据、单位与样本长度,多输入 OHLCV 数组必须按同一时间轴对齐。保留影响结果解释的原生规则:
8
-
9
- - `MACD` 返回 `(macd, signal, hist)`,其中 `hist = macd - signal`,不乘 2。
10
- - `BBANDS` 返回 `(upper, middle, lower)`,默认使用 SMA 中轨和两倍总体标准差。
11
- - 暖机期为 NaN,例如 SMA(20) 前 19 根、RSI(14) 前 14 根不可用。EMA、RSI 的种子和平滑规则不等同于直接 pandas ewm;持平序列的 RSI 暖机后为 0,不是 50。
12
- - NaN 输入可能影响后续输出,不擅自填零或把暖机值当成信号。严格 JSON 中将非有限值转为 null。
13
-
14
- 按需记录参数、库版本和数据来源,便于复现。
15
-
16
- ## backtesting
17
-
18
- 用 `from backtesting import Backtest, Strategy`,通过 Strategy 的 `init()`、`next()` 定义策略,再运行 `Backtest(data, 策略类, ...).run()`。数据为按时间升序的 OHLC DataFrame,可带 Volume;参数以当前版本 API 为准。TA-Lib 指标可用 `self.I(talib.SMA, self.data.Close, 20)` 注册。
19
-
20
- 显式确定资金、手续费、价差、成交时点与仓位假设。原生 Backtest 不自动提供 A 股 T+1、整手买入、涨跌停或交易日历约束;任务需要时明确建模和验证,无法表达时说明限制,不把默认值当作市场规则。
21
-
22
- 按研究问题选择样本内外划分及暖机方法,避免未来数据泄漏。交付时说明参数、版本与限制,按需保留统计和交易记录;导出时处理 Series、DataFrame、时间和非有限值。
@@ -1,16 +0,0 @@
1
- # Python 计算
2
-
3
- ## 运行方式
4
-
5
- 通过当前宿主的原生 Bash,沿用项目声明的解释器、依赖、工作目录、入口和输出位置。尚无约定时,先检查可用解释器和所需库再执行。
6
-
7
- 包内相对导入在项目根目录用 `python -m 包.模块`,不靠改 `sys.path` 绕过导入错误。交付时核对结果并给出实际产物路径。
8
-
9
- 解释器或依赖异常时,检查实际路径、导入错误与项目配置,继续不受影响的工作;专家需要主会话协助时交回具体阻碍和所需条件。
10
-
11
- ## 常见约束
12
-
13
- - 无图形界面绘图:导入 `pyplot`/`seaborn` 前设置 Matplotlib `Agg` 后端,保存文件后关闭 figure。
14
- - 表格与二进制文件(Excel/Parquet/Feather):核对读写后的字段类型、时间单位与时区;Excel 不直接保存带时区的 `datetime`,转换前先确定目标时区。
15
- - 统计与建模:记录数据口径和假设;时间序列按时间切分,预处理只在训练集拟合,避免未来数据泄漏。
16
- - 技术指标或回测:另读同目录 [compute-finance.md](compute-finance.md),显式确定数据口径和交易假设。
@@ -1,25 +0,0 @@
1
- # Task Conductor
2
-
3
- 需要周期执行、重复流程、DAG 或离开当前会话后继续运行时使用本文。普通单次协助直接使用当前宿主专家。
4
-
5
- ## 发现与操作
6
-
7
- 在当前宿主原生工具与技能中查找 Task Conductor,先读取 `using-task-conductor` 技能,再按实际 MCP schema 调用(保留工具名中的连字符,如 `mcp__task-conductor__task_list`)。
8
-
9
- 工具或技能未出现时,向用户说明缺失项及对应宿主检查入口(如 Pi/Claude 的 `/mcp`、dsh 的 `/task-conductor status`),不要通过 Bash 代执行宿主聊天命令;继续不受影响的工作。
10
-
11
- 若需要在 dsh 后台执行节点,`executorId` 选择已注册的自定义执行端 `dsh-acp`(不是 `dsh`)。后台节点使用独立的 `acp` profile 运行环境,不继承当前主会话的模型、工具或 Python 配置。
12
-
13
- ## 定义任务
14
-
15
- 提交前写明输入、工作目录、所需工具与模型及预期产物;周期任务另须写明频率、时区、执行范围及每轮数据来源、期间与时点。
16
-
17
- 确认节点具备所需工具、技能、Python 环境和认证。需要人工交互的步骤留在交互会话中完成,节点直接执行分配任务,不递归委派。
18
-
19
- ## 状态与取消
20
-
21
- 任务定义、单次执行和节点分别用 `taskId`、`runId` 和节点 ID 标识。提交结果不明时先按 ID 或任务列表查询,避免重复创建。实时状态查 Task Conductor,项目资料只记录任务定义、标识和产物位置。
22
-
23
- 事件通知回到提交任务的原会话;新会话不代收,但可通过 MCP 查询。
24
-
25
- 取消当前执行与停止未来周期须分别操作并查询确认;停止本地专家或关闭当前会话不会停止 Task Conductor。汇报时区分“调度已创建”和“本轮已完成”,并给出状态与产物路径。
@@ -1,16 +0,0 @@
1
- import { prerelease, satisfies, valid } from "semver";
2
- export function npmName(source) {
3
- return /^npm:((?:@[a-z0-9._-]+\/)?[a-z0-9._-]+)(?:@[^\s]+)?$/.exec(source)?.[1];
4
- }
5
- export function ordinaryNpm(source) {
6
- const name = npmName(source);
7
- return name !== undefined && (source === `npm:${name}` || source === `npm:${name}@latest`);
8
- }
9
- export function checkStableVersion(version, nodeRange) {
10
- if (!valid(version) || prerelease(version))
11
- throw new Error(`latest 不是稳定版本:${version}`);
12
- if (nodeRange && !satisfies(process.versions.node, nodeRange)) {
13
- throw new Error(`目标版本要求 Node.js ${nodeRange},当前为 ${process.versions.node}。请先升级 Node.js。`);
14
- }
15
- return version;
16
- }
@@ -1,11 +0,0 @@
1
- // Native extension commands run before input handlers. Reaching this handler for
2
- // /pbot init means it was not dispatched; never let the setup input reach a model.
3
- export default function setupGuard(pi) {
4
- pi.on("input", (event, ctx) => {
5
- if (event.text.trim() !== "/pbot init")
6
- return { action: "continue" };
7
- ctx.ui.notify("pbot 未加载或命令存在冲突。请检查项目信任和 pi config --local 后重新运行 setup。", "error");
8
- ctx.shutdown();
9
- return { action: "handled" };
10
- });
11
- }
@@ -1,131 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { readFile, stat } from "node:fs/promises";
3
- import { join, resolve } from "node:path";
4
- import { fileURLToPath, pathToFileURL } from "node:url";
5
- import { npmName } from "../../common/package-source.js";
6
- async function sdkAt(root) {
7
- const manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
8
- if (manifest.name !== "@earendil-works/pi-coding-agent")
9
- throw new Error("不是支持的 Pi 安装。");
10
- return import(pathToFileURL(join(root, "dist/index.js")).href);
11
- }
12
- const sourceOf = (entry) => {
13
- if (typeof entry === "string")
14
- return entry;
15
- if (entry && typeof entry === "object" && "source" in entry && typeof entry.source === "string")
16
- return entry.source;
17
- throw new Error("无效的 Pi packages 声明。");
18
- };
19
- export async function inspectPackages(root, workspace) {
20
- const sdk = await sdkAt(root), agentDir = sdk.getAgentDir();
21
- // Inspect project declarations as data only. This does not load extensions, execute
22
- // project npmCommand, grant project trust, or persist migrated settings.
23
- const settings = sdk.SettingsManager.fromStorage({ withLock(scope, read) {
24
- const file = scope === "global" ? join(agentDir, "settings.json") : join(workspace, sdk.CONFIG_DIR_NAME, "settings.json");
25
- let content;
26
- try {
27
- content = readFileSync(file, "utf8");
28
- }
29
- catch (error) {
30
- if (error.code !== "ENOENT")
31
- throw error;
32
- }
33
- if (content !== undefined) {
34
- const value = JSON.parse(content);
35
- if (!value || typeof value !== "object" || Array.isArray(value))
36
- throw new Error(`无效的 Pi 配置:${file}`);
37
- const packages = value.packages;
38
- if (packages !== undefined) {
39
- if (!Array.isArray(packages))
40
- throw new Error(`packages 必须是数组:${file}`);
41
- packages.forEach(sourceOf);
42
- }
43
- }
44
- if (read(content) !== undefined)
45
- throw new Error("安装检查不得修改 Pi 配置。");
46
- } }, { projectTrusted: true });
47
- const errors = settings.drainErrors();
48
- if (errors.length)
49
- throw new Error(errors.map(item => `${item.scope}: ${item.error.message}`).join("\n"));
50
- const manager = new sdk.DefaultPackageManager({ cwd: workspace, agentDir, settingsManager: settings });
51
- const result = [];
52
- for (const pkg of manager.listConfiguredPackages()) {
53
- const entries = (pkg.scope === "project" ? settings.getProjectSettings() : settings.getGlobalSettings()).packages ?? [];
54
- const entry = entries.find(item => sourceOf(item) === pkg.source);
55
- let name = npmName(pkg.source), version, singleFile = false;
56
- if (pkg.installedPath) {
57
- const info = await stat(pkg.installedPath);
58
- singleFile = info.isFile(); // An existing standalone extension has no npm identity.
59
- if (info.isDirectory()) {
60
- try {
61
- const manifest = JSON.parse(await readFile(join(pkg.installedPath, "package.json"), "utf8"));
62
- if (name && manifest.name !== name)
63
- throw new Error(`安装包身份不匹配:${pkg.source}`);
64
- name = typeof manifest.name === "string" && manifest.name.trim() ? manifest.name : name;
65
- version = typeof manifest.version === "string" ? manifest.version : undefined;
66
- }
67
- catch (error) {
68
- if (error.code !== "ENOENT")
69
- throw error;
70
- }
71
- }
72
- }
73
- if (!name && !singleFile) {
74
- throw new Error(`无法辨认 ${pkg.scope} 来源的包身份:${pkg.source}。请先通过 Pi 原生配置恢复或修正该来源,再重新运行 setup。`);
75
- }
76
- result.push({ source: pkg.source, scope: pkg.scope, filtered: pkg.filtered, entry,
77
- ...(pkg.installedPath ? { installedPath: pkg.installedPath } : {}), ...(name ? { name } : {}), ...(version ? { version } : {}) });
78
- }
79
- return result;
80
- }
81
- export async function replaceProjectSource(root, workspace, old, target) {
82
- const fromProject = old.scope === "project" && !npmName(old.source);
83
- const fromUser = old.scope === "user" && !!npmName(old.source);
84
- if (!fromProject && !fromUser)
85
- throw new Error("此操作只替换工作区自定义来源,或继承全局 npm 资源过滤。");
86
- const sdk = await sdkAt(root);
87
- const settings = sdk.SettingsManager.create(workspace, sdk.getAgentDir(), { projectTrusted: true });
88
- const errors = settings.drainErrors();
89
- if (errors.length)
90
- throw new Error(errors.map(item => item.error.message).join("\n"));
91
- const packages = settings.getProjectSettings().packages ?? [];
92
- const originals = fromProject ? packages : settings.getGlobalSettings().packages ?? [];
93
- const previous = originals.find(entry => sourceOf(entry) === old.source);
94
- if (previous === undefined || JSON.stringify(previous) !== JSON.stringify(old.entry))
95
- throw new Error("插件配置已发生变化,请重新运行 setup。");
96
- if (!packages.some(entry => sourceOf(entry) === target))
97
- throw new Error("目标包尚未安装,保留原声明。");
98
- const manager = new sdk.DefaultPackageManager({ cwd: workspace, agentDir: sdk.getAgentDir(), settingsManager: settings });
99
- const installed = manager.getInstalledPath(target, "project");
100
- if (!installed || !npmName(target))
101
- throw new Error("目标 npm 包尚未安装,保留原声明。");
102
- const manifest = JSON.parse(await readFile(join(installed, "package.json"), "utf8"));
103
- if (manifest.name !== npmName(target))
104
- throw new Error("目标安装包身份不符,保留原声明。");
105
- // Change only declarations; do not call remove(), which deletes managed git caches.
106
- const replacement = typeof previous === "string" ? target : { ...previous, source: target };
107
- const next = fromProject
108
- ? packages.filter(entry => sourceOf(entry) !== target).map(entry => sourceOf(entry) === old.source ? replacement : entry)
109
- : packages.map(entry => sourceOf(entry) === target ? replacement : entry);
110
- settings.setProjectPackages(next);
111
- await settings.flush();
112
- const failures = settings.drainErrors();
113
- if (failures.length)
114
- throw new Error(failures.map(item => item.error.message).join("\n"));
115
- }
116
- async function main() {
117
- const [action, root, workspace, input] = process.argv.slice(2);
118
- if (!root || !workspace)
119
- throw new Error("缺少 Pi 路径或工作区。");
120
- if (action === "inspect")
121
- console.log(JSON.stringify(await inspectPackages(root, workspace)));
122
- else if (action === "replace" && input) {
123
- const { old, target } = JSON.parse(input);
124
- await replaceProjectSource(root, workspace, old, target);
125
- }
126
- else
127
- throw new Error("无效的安装检查操作。");
128
- }
129
- if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
130
- await main().catch(error => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; });
131
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- [
2
- {
3
- "id": "task-conductor",
4
- "label": "Task Conductor",
5
- "description": "周期任务、流程和 DAG 的接入与使用引导;服务另行准备",
6
- "source": "npm:task-conductor-plugin",
7
- "defaultSelected": true
8
- },
9
- {
10
- "id": "web-access",
11
- "label": "Pi Web Access",
12
- "description": "网页搜索与内容获取",
13
- "source": "npm:pi-web-access",
14
- "defaultSelected": true
15
- }
16
- ]
@@ -1,22 +0,0 @@
1
- # 指标与回测
2
-
3
- ## TA-Lib
4
-
5
- 通过 `import talib` 使用原生函数。用 `talib.get_function_groups()`、`talib.get_functions()` 和 `help(talib.函数名)` 核对能力、参数与返回值。
6
-
7
- 计算前核对时间顺序、复权、缺失数据、单位与样本长度,多输入 OHLCV 数组必须按同一时间轴对齐。保留影响结果解释的原生规则:
8
-
9
- - `MACD` 返回 `(macd, signal, hist)`,其中 `hist = macd - signal`,不乘 2。
10
- - `BBANDS` 返回 `(upper, middle, lower)`,默认使用 SMA 中轨和两倍总体标准差。
11
- - 暖机期为 NaN,例如 SMA(20) 前 19 根、RSI(14) 前 14 根不可用。EMA、RSI 的种子和平滑规则不等同于直接 pandas ewm;持平序列的 RSI 暖机后为 0,不是 50。
12
- - NaN 输入可能影响后续输出,不擅自填零或把暖机值当成信号。严格 JSON 中将非有限值转为 null。
13
-
14
- 按需记录参数、库版本和数据来源,便于复现。
15
-
16
- ## backtesting
17
-
18
- 用 `from backtesting import Backtest, Strategy`,通过 Strategy 的 `init()`、`next()` 定义策略,再运行 `Backtest(data, 策略类, ...).run()`。数据为按时间升序的 OHLC DataFrame,可带 Volume;参数以当前版本 API 为准。TA-Lib 指标可用 `self.I(talib.SMA, self.data.Close, 20)` 注册。
19
-
20
- 显式确定资金、手续费、价差、成交时点与仓位假设。原生 Backtest 不自动提供 A 股 T+1、整手买入、涨跌停或交易日历约束;任务需要时明确建模和验证,无法表达时说明限制,不把默认值当作市场规则。
21
-
22
- 按研究问题选择样本内外划分及暖机方法,避免未来数据泄漏。交付时说明参数、版本与限制,按需保留统计和交易记录;导出时处理 Series、DataFrame、时间和非有限值。
@@ -1,16 +0,0 @@
1
- # Python 计算
2
-
3
- ## 运行方式
4
-
5
- 通过当前宿主的原生 Bash,沿用项目声明的解释器、依赖、工作目录、入口和输出位置。尚无约定时,先检查可用解释器和所需库再执行。
6
-
7
- 包内相对导入在项目根目录用 `python -m 包.模块`,不靠改 `sys.path` 绕过导入错误。交付时核对结果并给出实际产物路径。
8
-
9
- 解释器或依赖异常时,检查实际路径、导入错误与项目配置,继续不受影响的工作;专家需要主会话协助时交回具体阻碍和所需条件。
10
-
11
- ## 常见约束
12
-
13
- - 无图形界面绘图:导入 `pyplot`/`seaborn` 前设置 Matplotlib `Agg` 后端,保存文件后关闭 figure。
14
- - 表格与二进制文件(Excel/Parquet/Feather):核对读写后的字段类型、时间单位与时区;Excel 不直接保存带时区的 `datetime`,转换前先确定目标时区。
15
- - 统计与建模:记录数据口径和假设;时间序列按时间切分,预处理只在训练集拟合,避免未来数据泄漏。
16
- - 技术指标或回测:另读同目录 [compute-finance.md](compute-finance.md),显式确定数据口径和交易假设。
@@ -1,25 +0,0 @@
1
- # Task Conductor
2
-
3
- 需要周期执行、重复流程、DAG 或离开当前会话后继续运行时使用本文。普通单次协助直接使用当前宿主专家。
4
-
5
- ## 发现与操作
6
-
7
- 在当前宿主原生工具与技能中查找 Task Conductor,先读取 `using-task-conductor` 技能,再按实际 MCP schema 调用(保留工具名中的连字符,如 `mcp__task-conductor__task_list`)。
8
-
9
- 工具或技能未出现时,向用户说明缺失项及对应宿主检查入口(如 Pi/Claude 的 `/mcp`、dsh 的 `/task-conductor status`),不要通过 Bash 代执行宿主聊天命令;继续不受影响的工作。
10
-
11
- 若需要在 dsh 后台执行节点,`executorId` 选择已注册的自定义执行端 `dsh-acp`(不是 `dsh`)。后台节点使用独立的 `acp` profile 运行环境,不继承当前主会话的模型、工具或 Python 配置。
12
-
13
- ## 定义任务
14
-
15
- 提交前写明输入、工作目录、所需工具与模型及预期产物;周期任务另须写明频率、时区、执行范围及每轮数据来源、期间与时点。
16
-
17
- 确认节点具备所需工具、技能、Python 环境和认证。需要人工交互的步骤留在交互会话中完成,节点直接执行分配任务,不递归委派。
18
-
19
- ## 状态与取消
20
-
21
- 任务定义、单次执行和节点分别用 `taskId`、`runId` 和节点 ID 标识。提交结果不明时先按 ID 或任务列表查询,避免重复创建。实时状态查 Task Conductor,项目资料只记录任务定义、标识和产物位置。
22
-
23
- 事件通知回到提交任务的原会话;新会话不代收,但可通过 MCP 查询。
24
-
25
- 取消当前执行与停止未来周期须分别操作并查询确认;停止本地专家或关闭当前会话不会停止 Task Conductor。汇报时区分“调度已创建”和“本轮已完成”,并给出状态与产物路径。
@@ -1,159 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
- import { mkdir, readFile, realpath } from "node:fs/promises";
4
- import { join } from "node:path";
5
- import { npmName, ordinaryNpm } from "../../../common/package-source.js";
6
- import { packageRoot } from "../../../common/paths.js";
7
- import { packageVersion } from "../../../common/version.js";
8
- import { PiBootstrapRequired, PiSetup, piPackageName } from "../../../integrations/installation/pi-setup.js";
9
- import { findExecutable, inspectSystem, SetupProcesses } from "../../../integrations/installation/processes.js";
10
- import type { InstalledPackage, SetupPlan } from "../../../model/installation.js";
11
- import { executeSetup, packageChoices, parseCatalog } from "../../../services/installation/setup-service.js";
12
- import { SetupUI } from "../../../ui/setup.js";
13
- import { CliError, requireNoExtraArgs, resolveCliWorkspace, withSignals } from "../args.js";
14
- import type { CliCommand } from "../types.js";
15
-
16
- const quote = (value: string) => "'" + value.replaceAll("'", "'\\''") + "'";
17
-
18
- const setupUsage =
19
- "用法:pbot setup [--workspace <目录>]\n" +
20
- "安装或升级 Pi、Personal Bot 和选中的配套插件,然后启动 Pi 执行 /pbot init。";
21
-
22
- const installAntigravityUsage =
23
- "用法:pbot install-antigravity\n" +
24
- "通过原生 agy plugin install 安装或更新 Antigravity 插件。";
25
-
26
- export const setupCommand: CliCommand = {
27
- name: "setup",
28
- summary: "交互式安装或升级 Pi 与工作区插件",
29
- usage: setupUsage,
30
- updatePolicy: "none",
31
- supportsWorkspaceFlag: true,
32
- async run(ctx) {
33
- requireNoExtraArgs(ctx.args, setupUsage);
34
- if (!process.stdin.isTTY || !process.stdout.isTTY) {
35
- throw new CliError("setup 需要交互终端。请在终端运行 npx personal-bot@latest setup。", 2);
36
- }
37
- const outcome = await withSignals(
38
- async controller => {
39
- const ui = new SetupUI(controller);
40
- const processes = new SetupProcesses(controller.signal);
41
- const cwd = ctx.cwd;
42
- ui.text("Personal Bot " + packageVersion + " — 安装与升级\n正在检查 Node/npm 和 tmux…");
43
- const system = await inspectSystem(processes, cwd);
44
- const supplied = ctx.workspace ?? await ui.ask("工作区目录(当前、已有或新建目录)", cwd);
45
- const workspace = await resolveCliWorkspace(supplied, cwd);
46
- const host = new PiSetup(processes, system.npm, cwd);
47
- let pi = await host.inspectPi();
48
- let installed: InstalledPackage[];
49
- try {
50
- installed = await host.inspectPackages(pi, workspace);
51
- } catch (error) {
52
- if (!(error instanceof PiBootstrapRequired)) throw error;
53
- const version = await host.latest(piPackageName);
54
- ui.text(error.message + "\n需先安装 Pi 才能使用其原生接口核对这些来源。目标版本:" + version);
55
- if (!await ui.confirm("先通过 npm 安装 Pi,再继续选择工作区插件")) return 130;
56
- pi = await host.ensurePi(undefined, version);
57
- installed = await host.inspectPackages(pi, workspace);
58
- }
59
- const catalog = parseCatalog(JSON.parse(await readFile(join(packageRoot, "resources/installer/plugins.json"), "utf8")));
60
- const choices = packageChoices(catalog, installed);
61
- const optional = choices.filter(choice => !choice.required);
62
- ui.text("\nPersonal Bot 必装。选择配套插件(取消勾选不会卸载已有插件):");
63
- const selected = await ui.selectMany(
64
- optional.map(choice => choice.plugin.label + " — " + choice.plugin.description),
65
- optional.flatMap((choice, index) => choice.selected ? [index] : []),
66
- );
67
- optional.forEach((choice, index) => { choice.selected = selected.includes(index); });
68
- for (const choice of choices.filter(item => item.selected)) {
69
- if (choice.existing.some(pkg => !ordinaryNpm(pkg.source))) {
70
- ui.text("\n" + choice.plugin.label + " 的已有来源:\n" + choice.existing.map(pkg =>
71
- " " + pkg.scope + ": " + pkg.source + " (" + (pkg.version ?? "版本未知") + ")").join("\n"));
72
- choice.keep = !await ui.confirm("切换到 npm 最新稳定版", false);
73
- }
74
- if (choice.keep) {
75
- if (choice.existing.length !== 1 || !choice.existing[0]?.installedPath) {
76
- choice.error = "保留来源未安装或存在多份来源,请先通过 Pi 原生配置处理。";
77
- }
78
- } else {
79
- const others = choice.existing.filter(pkg => !npmName(pkg.source));
80
- if (others.length > 1 || others.some(pkg => pkg.scope === "user")) {
81
- choice.error = "请先用 pi config 调整全局或重复来源的加载范围,再切换到 npm。";
82
- } else {
83
- try {
84
- choice.target = await host.latest(npmName(choice.plugin.source)!);
85
- } catch (error) {
86
- controller.signal.throwIfAborted();
87
- choice.error = String(error);
88
- }
89
- }
90
- }
91
- }
92
- const plan: SetupPlan = {
93
- workspace,
94
- piVersion: await host.latest(piPackageName),
95
- packages: choices,
96
- ...(pi ? { pi } : {}),
97
- ...(system.tmux ? { tmux: system.tmux } : {}),
98
- };
99
- ui.text("\n安装计划\n工作区:" + workspace + "\nPi:" + (pi ? pi.command + " (" + pi.version + ")" : "通过 npm 全局安装") + " → " + plan.piVersion);
100
- if (system.tmux) ui.text("tmux:" + [system.tmux.command, ...system.tmux.args].map(quote).join(" "));
101
- for (const choice of choices) {
102
- ui.text(" " + choice.plugin.label + ": " + (!choice.selected ? "本次跳过" : choice.error ??
103
- (choice.keep ? "保留 " + choice.existing[0]?.source : (choice.existing.map(pkg => pkg.version ?? "未知").join(", ") || "未安装") + " → " + choice.target)));
104
- if (choice.selected && choice.existing.some(pkg => pkg.filtered)) {
105
- ui.text(" 保留已有资源过滤;如 pbot 被禁用,请通过 pi config --local 启用。");
106
- }
107
- }
108
- const blocking = choices.find(choice => choice.required && choice.error);
109
- if (blocking) throw new Error(blocking.error);
110
- ui.text("升级前请停止活动 pbot 子会话。Pi 为当前用户共用,插件只处理此工作区。");
111
- if (!await ui.confirm("执行以上计划")) return 130;
112
- await mkdir(workspace, { recursive: true });
113
- if (await realpath(workspace) !== workspace) throw new Error("工作区路径已发生变化,请重新运行 setup。");
114
- const result = await executeSetup(plan, host, item => ui.text("[" + item.state + "] " + item.name + ": " + item.detail), controller.signal);
115
- const failed = result.results.some(item => item.state === "failed");
116
- if (!result.pi) return 1;
117
- ui.text("\n软件安装阶段结束。工作区初始化和外部服务的状态由 Pi/pbot/插件分别报告。");
118
- if (await ui.confirm(failed ? "部分插件失败,是否仍启动 Pi 并初始化启用工作区" : "启动 Pi 并初始化启用工作区", !failed)) {
119
- process.stdin.pause();
120
- await host.start(result.pi, workspace);
121
- } else {
122
- ui.text("稍后执行:\ncd " + quote(workspace) + "\n" + quote(result.pi.command) + " --extension " +
123
- quote(join(packageRoot, "lib/extension/setup/guard.js")) + " '/pbot init'");
124
- }
125
- return failed ? 1 : 0;
126
- },
127
- () => console.error("安装已取消;已完成的步骤保留。"),
128
- );
129
- return outcome.ok ? outcome.value : outcome.exitCode;
130
- },
131
- };
132
-
133
- export const installAntigravityCommand: CliCommand = {
134
- name: "install-antigravity",
135
- summary: "安装或更新 Antigravity 插件",
136
- usage: installAntigravityUsage,
137
- updatePolicy: "none",
138
- async run(ctx) {
139
- requireNoExtraArgs(ctx.args, installAntigravityUsage);
140
- const pluginDir = join(packageRoot, "lib/antigravity-plugin");
141
- if (!existsSync(join(pluginDir, "plugin.json"))) {
142
- console.error("缺少 Antigravity 插件构建产物:" + pluginDir + "。请先运行 npm run build。");
143
- return 1;
144
- }
145
- const agy = process.env.PBOT_AGY_COMMAND || await findExecutable("agy", process.env);
146
- if (!agy) {
147
- console.error("未找到 Antigravity CLI(agy)。请先安装 agy,然后运行:\n agy plugin install " + quote(pluginDir));
148
- return 1;
149
- }
150
- const installed = spawnSync(agy, ["plugin", "install", pluginDir], { stdio: "inherit" });
151
- if (installed.error) {
152
- console.error(String(installed.error));
153
- return 1;
154
- }
155
- if (installed.status !== 0) return installed.status ?? 1;
156
- console.log("Antigravity 插件已安装。在目标工作区运行 /pbot init 启用 Personal Bot。");
157
- return 0;
158
- },
159
- };
@@ -1,12 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
-
3
- // Native extension commands run before input handlers. Reaching this handler for
4
- // /pbot init means it was not dispatched; never let the setup input reach a model.
5
- export default function setupGuard(pi: ExtensionAPI) {
6
- pi.on("input", (event, ctx) => {
7
- if (event.text.trim() !== "/pbot init") return { action: "continue" };
8
- ctx.ui.notify("pbot 未加载或命令存在冲突。请检查项目信任和 pi config --local 后重新运行 setup。", "error");
9
- ctx.shutdown();
10
- return { action: "handled" };
11
- });
12
- }