mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
移除 pi-extension-codex-fast-mode:
- 删除整个扩展目录;同步清理根 package.json 的 files / pi.extensions /
dependencies 条目、package-lock.json、tests/extension-load.test.ts 断言
与文档章节。
- pi-minimal-footer 的 Fast on 渲染是该扩展的唯一消费者。扩展移除后 accent
分支不再有生产者,collectFooterStatusItems 简化为直接返回非空状态字符串,
去掉 FooterStatusItem 与 accent 标志,避免留下死代码。
移除 500 次裁决后的后台分析体系:
- 删除 analysis-agent.ts(192 行)与 ledger.ts(296 行),以及对应的
auto-review-runtime / auto-review-ledger 测试。
- runtime.ts 由 177 行收敛到 85 行:安装选项缩为 { service, config };删除
handleAgentSettled 与 agent_settled 注册;保留 session_start / turn_start
(denial circuit breaker 属安全语义)/ session_shutdown。
- 删除 analysis 配置键:config、extension-config、config-schema、生成的
permissions.schema.json 与种子配置。
- 删除 reviewer 的 onDecision 回调(唯一消费者是 ledger)。
- 删除迁移机制 scripts/migrate-permission-policy.mjs、其测试与 update.sh 中
46 行 migrate_permission_policy 接线。种子部署保持“目标缺失才写入”,已存在
的 policy.jsonc 永不被覆盖。
AutoReview 模型改为纯配置驱动:
- 删除 DEFAULT_PROVIDER / DEFAULT_MODEL 常量与 findCodexTemplate 合成逻辑;
model.ts 由 65 行收敛到 48 行。
- provider / model 任一缺失时返回新增失败类别 model-unconfigured 并 defer 到
人工审批;provider 未注册或模型未发布同样 defer。
- reasoning 不再有默认常量,完全由配置决定。
- session_start 在 auto-review 已列入 authorizerChain 且 provider/model 未配齐
时 ui.notify 提示一次,避免不使用 AutoReview 的用户被打扰。
- 种子 autoReview 只保留 enabled,provider/model/reasoning 由用户按本机实际
可用的模型填写。
破坏性变更:analysis 键已从 strictObject schema 删除,任何仍带该键的
policy.jsonc 会使整份配置被拒(fail-closed 到全 ask)。这是刻意的变更,已由
config-loader 测试固定,防止将来无声放宽。
测试:
- 新增 auto-review-model.test.ts(7 例),覆盖此前完全缺失的模型解析:真实
命中、未配置、provider 未知、模型未发布,以及不再合成替代模型。
- 重写 auto-review-runtime.test.ts(6 例):authorizer 注册、未配置时提示
一次、已配置 / disabled / 无 UI / 不在 chain 时静默。
- config-loader.test.ts 新增 2 例:带 analysis 的旧配置被拒且 fail-closed、
autoReview 逐字段合并。
- composition-root.test.ts 的 EXPECTED_HANDLERS 移除 agent_settled。
文档:AGENTS.md、README.md、pi-permission-system 的 README / CHANGELOG /
configuration.md / architecture.md / auto-review UPSTREAM.md。
验证:pi-permission-system 的 typecheck、2577 个测试与 build 全部通过;根 50
个测试通过;schema 重新生成无漂移;新种子通过 schema 校验;5 个脚本 sh -n
通过;git diff --check 无空白问题。未安装 shellcheck;未执行真实 pi install /
update(属外部写操作)。
224 lines
12 KiB
TypeScript
224 lines
12 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { spawnSync } from "node:child_process";
|
|
import test from "node:test";
|
|
|
|
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
const hasPi = spawnSync("pi", ["--version"], { encoding: "utf8" }).status === 0;
|
|
|
|
test("subagents source is retained but disabled in the root bundle", async () => {
|
|
const packageJson = JSON.parse(await readFile(join(repositoryRoot, "package.json"), "utf8")) as {
|
|
dependencies: Record<string, string>;
|
|
files: string[];
|
|
pi: { extensions: string[] };
|
|
};
|
|
assert.ok(packageJson.files.includes("pi-subagents"), "the bundle must retain the maintained subagents source");
|
|
assert.equal(packageJson.dependencies["@tintinweb/pi-subagents"], undefined);
|
|
assert.equal(
|
|
packageJson.pi.extensions.includes("./extensions/subagents.ts"),
|
|
false,
|
|
"the bundle must not default-load the disabled subagents wrapper",
|
|
);
|
|
});
|
|
|
|
test("all package extensions load together without global registration conflicts", { skip: !hasPi }, async () => {
|
|
const packageJson = JSON.parse(await readFile(join(repositoryRoot, "package.json"), "utf8")) as {
|
|
dependencies: Record<string, string>;
|
|
files: string[];
|
|
pi: { extensions: string[] };
|
|
allowScripts: Record<string, boolean>;
|
|
};
|
|
assert.ok(
|
|
packageJson.pi.extensions.includes("./extensions/plugin-init.ts"),
|
|
"the bundle must expose the project plugin initializer command",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.includes("./pi-hermes-memory/src/index.ts"),
|
|
"the bundle must load the vendored Hermes memory extension",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.includes("./pi-minimal-footer/index.ts"),
|
|
"the bundle must load the locally maintained minimal footer",
|
|
);
|
|
assert.equal(packageJson.dependencies["pi-compaction"], "file:./pi-compaction");
|
|
assert.ok(packageJson.files.includes("pi-compaction"), "the packed bundle must include maintained pi-compaction source");
|
|
assert.ok(
|
|
packageJson.pi.extensions.includes("./pi-compaction/index.ts"),
|
|
"the bundle must load the unified pi-compaction authority",
|
|
);
|
|
assert.equal(packageJson.dependencies["pi-condense"], undefined);
|
|
assert.equal(packageJson.dependencies["@ogulcancelik/pi-codex-compaction"], undefined);
|
|
assert.equal(packageJson.dependencies["pi-context-view"], undefined);
|
|
assert.ok(packageJson.pi.extensions.includes("./extensions/context-view.ts"));
|
|
assert.ok(
|
|
packageJson.pi.extensions.indexOf("./pi-compaction/index.ts") <
|
|
packageJson.pi.extensions.indexOf("./extensions/context-view.ts"),
|
|
"the context observer must load after the compaction authority",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.indexOf("./pi-compaction/index.ts") <
|
|
packageJson.pi.extensions.indexOf("./pi-minimal-footer/index.ts"),
|
|
"the footer must load after the compaction metrics service",
|
|
);
|
|
assert.ok(packageJson.pi.extensions.includes("./pi-ssh/index.ts"), "the bundle must load the locally maintained SSH extension");
|
|
assert.equal(packageJson.dependencies["pi-ssh"], "file:./pi-ssh");
|
|
assert.equal(packageJson.dependencies.ssh2, "1.17.0", "the packed bundle must install pi-ssh's runtime transport");
|
|
assert.equal(packageJson.dependencies.jiti, "2.7.0", "the packed helper must load local TypeScript outside Pi");
|
|
assert.ok(packageJson.files.includes("pi-ssh"), "the packed bundle must include the locally maintained SSH source");
|
|
assert.ok(packageJson.files.includes("ssh_config.sh"), "the packed bundle must include the SSH host import helper");
|
|
assert.ok(packageJson.pi.extensions.includes("./pi-ask-user/index.ts"), "the bundle must load pi-ask-user");
|
|
assert.equal(packageJson.dependencies["pi-ask-user"], "file:./pi-ask-user");
|
|
assert.ok(packageJson.files.includes("pi-ask-user"), "the packed bundle must include pi-ask-user source");
|
|
const chromeExtension = "./pi-chrome/extensions/chrome-profile-bridge/index.ts";
|
|
assert.equal(packageJson.dependencies["pi-chrome"], "file:./pi-chrome", "the browser bridge must use the locally maintained source");
|
|
assert.ok(packageJson.files.includes("pi-chrome"), "the packed bundle must include the locally maintained pi-chrome source");
|
|
assert.ok(packageJson.pi.extensions.includes(chromeExtension), "the bundle must load the local Chrome profile bridge directly");
|
|
assert.ok(
|
|
packageJson.pi.extensions.indexOf(chromeExtension) <
|
|
packageJson.pi.extensions.indexOf("./pi-tool-search/extensions/index.ts"),
|
|
"pi-chrome must register before Tool Search catalogs its authorized tools",
|
|
);
|
|
const permissionPolicySource = await readFile(
|
|
join(repositoryRoot, "config", "pi-permission-policy.jsonc"),
|
|
"utf8",
|
|
);
|
|
const hardGuardSource = await readFile(
|
|
join(repositoryRoot, "config", "pi-permission-hard-guards.jsonc"),
|
|
"utf8",
|
|
);
|
|
const stripLineComments = (source: string): string => source.replace(/^\s*\/\/.*$/gmu, "");
|
|
const permissionConfig = JSON.parse(stripLineComments(permissionPolicySource)) as {
|
|
authorizerChain: string[];
|
|
permission: Record<string, unknown>;
|
|
};
|
|
const hardGuardConfig = JSON.parse(stripLineComments(hardGuardSource)) as {
|
|
permission: { path?: Record<string, string>; bash: Record<string, string> };
|
|
};
|
|
assert.equal(permissionConfig.permission.ssh_connect, "ask", "SSH connection must enter the permission gate");
|
|
assert.equal(permissionConfig.permission.ssh_cd, "ask", "remote workspace changes must enter the permission gate");
|
|
assert.deepEqual(permissionConfig.authorizerChain, ["auto-review"], "SSH connection asks must reach AutoReview");
|
|
assert.equal(hardGuardConfig.permission.path, undefined, "sensitive paths must not be hard-denied by default");
|
|
assert.equal(hardGuardConfig.permission.bash["rm -rf /"], "deny");
|
|
assert.equal(
|
|
packageJson.pi.extensions.some((entry) => entry.includes("pi-permission-auto-review")),
|
|
false,
|
|
"AutoReview must be integrated instead of loaded as a second extension",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.indexOf("./extensions/permission-system.ts") <
|
|
packageJson.pi.extensions.indexOf("./pi-ssh/index.ts"),
|
|
"the permission service must load before pi-ssh registers its permission bridge",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.indexOf("./pi-ssh/index.ts") <
|
|
packageJson.pi.extensions.indexOf("./pi-tool-search/extensions/index.ts"),
|
|
"pi-ssh tools must register before Tool Search builds its catalog",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.indexOf("./pi-ask-user/index.ts") <
|
|
packageJson.pi.extensions.indexOf("./pi-tool-search/extensions/index.ts"),
|
|
"ask_user_question must register before Tool Search builds its catalog",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.includes("./pi-notify/src/index.ts"),
|
|
"the bundle must load the locally maintained Kitty notification extension",
|
|
);
|
|
assert.equal(packageJson.dependencies["@smoose/pi-notify"], "file:./pi-notify");
|
|
assert.ok(
|
|
packageJson.files.includes("pi-notify"),
|
|
"the packed bundle must include the locally maintained notification source",
|
|
);
|
|
assert.equal(packageJson.dependencies["@ogulcancelik/pi-minimal-footer"], "file:./pi-minimal-footer");
|
|
assert.equal(packageJson.dependencies["@tintinweb/pi-subagents"], undefined);
|
|
assert.equal(packageJson.pi.extensions.includes("./extensions/subagents.ts"), false);
|
|
assert.ok(
|
|
packageJson.pi.extensions.includes("./pi-hermes-memory/src/index.ts"),
|
|
"the bundle must load the locally maintained Hermes memory extension",
|
|
);
|
|
assert.equal(packageJson.dependencies["pi-hermes-memory"], "file:./pi-hermes-memory");
|
|
assert.ok(
|
|
packageJson.files.includes("pi-hermes-memory"),
|
|
"the packed bundle must include the locally maintained Hermes memory source",
|
|
);
|
|
assert.ok(
|
|
packageJson.pi.extensions.indexOf("./pi-hermes-memory/src/index.ts") <
|
|
packageJson.pi.extensions.indexOf("./pi-compaction/index.ts"),
|
|
"the memory extension must register its session_before_compact flush before the compaction authority can cancel the event",
|
|
);
|
|
assert.equal(
|
|
packageJson.pi.extensions.some((entry) => entry.includes("hippo-memory-pi") || entry.includes("the-forge-flow")),
|
|
false,
|
|
"retired Hippo and third-party memory extensions must not be loaded",
|
|
);
|
|
assert.equal(packageJson.dependencies["@the-forge-flow/hippo-memory-pi"], undefined);
|
|
assert.equal(packageJson.dependencies["better-sqlite3"], undefined);
|
|
assert.equal(packageJson.allowScripts["better-sqlite3@12.11.1"], true);
|
|
assert.equal(
|
|
packageJson.allowScripts["better-sqlite3@13.0.3"],
|
|
undefined,
|
|
"Hermes uses better-sqlite3 13 N-API prebuilds, so no extra install-script approval is required",
|
|
);
|
|
assert.equal(packageJson.dependencies["@sinclair/typebox"], undefined);
|
|
const home = await mkdtemp(join(tmpdir(), "my-pi-extension-load-"));
|
|
const mockBin = join(home, "bin");
|
|
await mkdir(mockBin, { recursive: true });
|
|
const args = ["--no-extensions"];
|
|
for (const entry of packageJson.pi.extensions) args.push("-e", resolve(repositoryRoot, entry));
|
|
args.push("--mode", "rpc");
|
|
|
|
const loadEnvironment = {
|
|
...process.env,
|
|
HOME: home,
|
|
XDG_CONFIG_HOME: join(home, ".config"),
|
|
PI_CODING_AGENT_DIR: join(home, ".pi-agent"),
|
|
MY_PI_SEARCH_CONFIG: join(home, "missing-search.env"),
|
|
PATH: `${mockBin}:${process.env.PATH ?? ""}`,
|
|
PI_OFFLINE: "1",
|
|
TAVILY_API_KEY: "",
|
|
EXA_API_KEY: "",
|
|
KEENABLE_API_KEY: "",
|
|
};
|
|
const runBundle = () => spawnSync("pi", args, {
|
|
encoding: "utf8",
|
|
timeout: 60_000,
|
|
env: loadEnvironment,
|
|
});
|
|
const result = runBundle();
|
|
|
|
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
|
assert.doesNotMatch(`${result.stdout}\n${result.stderr}`, /Failed to load extension|conflicts with/u);
|
|
const deployedPermissionPolicy = await readFile(
|
|
join(home, ".pi-agent", "extensions", "pi-permission-system", "policy.jsonc"),
|
|
"utf8",
|
|
);
|
|
const deployedHardGuards = await readFile(
|
|
join(home, ".pi-agent", "extensions", "pi-permission-system", "hard-guards.jsonc"),
|
|
"utf8",
|
|
);
|
|
assert.equal(deployedPermissionPolicy, permissionPolicySource, "the seeded policy must match the bundle source");
|
|
assert.equal(deployedHardGuards, hardGuardSource, "the seeded hard guards must match the bundle source");
|
|
|
|
const deployedConfigDir = join(home, ".pi-agent", "extensions", "pi-permission-system");
|
|
const deployedPolicyPath = join(deployedConfigDir, "policy.jsonc");
|
|
const deployedHardGuardPath = join(deployedConfigDir, "hard-guards.jsonc");
|
|
const customPolicy = `{ "permission": { "*": "deny" } }\n`;
|
|
const customHardGuards = `{ "version": 1, "permission": { "*": "allow" } }\n`;
|
|
await writeFile(deployedPolicyPath, customPolicy, "utf8");
|
|
await writeFile(deployedHardGuardPath, customHardGuards, "utf8");
|
|
const preserveResult = runBundle();
|
|
assert.equal(preserveResult.status, 0, `${preserveResult.stdout}\n${preserveResult.stderr}`);
|
|
assert.equal(await readFile(deployedPolicyPath, "utf8"), customPolicy, "reload must preserve user policy edits");
|
|
assert.equal(await readFile(deployedHardGuardPath, "utf8"), customHardGuards, "reload must preserve user hard guards");
|
|
|
|
await rm(deployedPolicyPath);
|
|
const legacyPolicy = `{ "authorizerChain": ["auto-review"], "permission": { "*": "ask" } }\n`;
|
|
await writeFile(join(deployedConfigDir, "config.json"), legacyPolicy, "utf8");
|
|
const migrationResult = runBundle();
|
|
assert.equal(migrationResult.status, 0, `${migrationResult.stdout}\n${migrationResult.stderr}`);
|
|
assert.equal(await readFile(deployedPolicyPath, "utf8"), legacyPolicy, "legacy config.json must seed policy.jsonc once");
|
|
assert.equal(await readFile(deployedHardGuardPath, "utf8"), customHardGuards, "legacy migration must not replace hard guards");
|
|
});
|