mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat: 移除 Codex Fast mode 与 AutoReview 后台分析,模型改为配置驱动
移除 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(属外部写操作)。
This commit is contained in:
@@ -43,10 +43,6 @@ test("all package extensions load together without global registration conflicts
|
||||
packageJson.pi.extensions.includes("./pi-minimal-footer/index.ts"),
|
||||
"the bundle must load the locally maintained minimal footer",
|
||||
);
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.includes("./pi-extension-codex-fast-mode/index.ts"),
|
||||
"the bundle must load the locally maintained Codex Fast mode extension",
|
||||
);
|
||||
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(
|
||||
@@ -126,14 +122,6 @@ test("all package extensions load together without global registration conflicts
|
||||
packageJson.pi.extensions.indexOf("./pi-tool-search/extensions/index.ts"),
|
||||
"ask_user_question must register before Tool Search builds its catalog",
|
||||
);
|
||||
assert.equal(
|
||||
packageJson.dependencies["@firstpick/pi-extension-codex-fast-mode"],
|
||||
"file:./pi-extension-codex-fast-mode",
|
||||
);
|
||||
assert.ok(
|
||||
packageJson.files.includes("pi-extension-codex-fast-mode"),
|
||||
"the packed bundle must include the locally maintained Codex Fast mode source",
|
||||
);
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.includes("./pi-notify/src/index.ts"),
|
||||
"the bundle must load the locally maintained Kitty notification extension",
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
LEGACY_PERMISSION_POLICY_HASHES,
|
||||
migratePermissionPolicy,
|
||||
permissionPolicySemanticHash,
|
||||
} from "../scripts/migrate-permission-policy.mjs";
|
||||
|
||||
const knownLegacyHash =
|
||||
"9abf020e80fceae8c52de3e8b758822dfc86cb90e9083381e2569dde1e29400a";
|
||||
|
||||
async function fixture(t: test.TestContext) {
|
||||
const directory = await mkdtemp(join(tmpdir(), "permission-policy-migration-"));
|
||||
t.after(() => rm(directory, { recursive: true, force: true }));
|
||||
const policyPath = join(directory, "policy.jsonc");
|
||||
const seedPath = join(directory, "seed.jsonc");
|
||||
const seed = `{
|
||||
// bundled policy
|
||||
"permission": {
|
||||
"*": "ask",
|
||||
"read": "allow"
|
||||
}
|
||||
}\n`;
|
||||
await writeFile(seedPath, seed, { mode: 0o600 });
|
||||
return { directory, policyPath, seedPath, seed };
|
||||
}
|
||||
|
||||
test("recognizes the exact previously installed policy snapshot", () => {
|
||||
assert.equal(LEGACY_PERMISSION_POLICY_HASHES.has(knownLegacyHash), true);
|
||||
});
|
||||
|
||||
test("semantic hashes ignore JSONC comments, whitespace, and object key order", () => {
|
||||
const left = `{
|
||||
// comment
|
||||
"permission": { "read": "allow", "*": "ask" },
|
||||
"analysis": { "enabled": true }
|
||||
}`;
|
||||
const right = `{"analysis":{"enabled":true},"permission":{"*":"ask","read":"allow"}}`;
|
||||
assert.equal(permissionPolicySemanticHash(left), permissionPolicySemanticHash(right));
|
||||
});
|
||||
|
||||
test("migrates only an exact legacy semantic snapshot and creates private files", async (t) => {
|
||||
const { directory, policyPath, seedPath, seed } = await fixture(t);
|
||||
const legacy = `{
|
||||
// formatting does not matter
|
||||
"permission": { "*": "allow", "path": { "**/.env": "deny" } }
|
||||
}\n`;
|
||||
await writeFile(policyPath, legacy, { mode: 0o644 });
|
||||
|
||||
const result = await migratePermissionPolicy(policyPath, seedPath, {
|
||||
legacyHashes: new Set([permissionPolicySemanticHash(legacy)]),
|
||||
now: new Date("2026-09-02T03:04:05.000Z"),
|
||||
});
|
||||
|
||||
assert.equal(result.status, "migrated");
|
||||
assert.equal(await readFile(policyPath, "utf8"), seed);
|
||||
assert.equal((await stat(policyPath)).mode & 0o777, 0o600);
|
||||
assert.ok(result.backupPath);
|
||||
assert.equal(await readFile(result.backupPath!, "utf8"), legacy);
|
||||
assert.equal((await stat(result.backupPath!)).mode & 0o777, 0o600);
|
||||
assert.equal(
|
||||
(await readdir(directory)).some((name) => name.includes(".tmp.")),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test("preserves customized policy content", async (t) => {
|
||||
const { policyPath, seedPath } = await fixture(t);
|
||||
const custom = `{"permission":{"*":"deny"}}\n`;
|
||||
await writeFile(policyPath, custom, { mode: 0o600 });
|
||||
|
||||
const result = await migratePermissionPolicy(policyPath, seedPath);
|
||||
|
||||
assert.deepEqual(result, { status: "custom" });
|
||||
assert.equal(await readFile(policyPath, "utf8"), custom);
|
||||
});
|
||||
|
||||
test("treats the bundled seed as current and repairs its mode", async (t) => {
|
||||
const { policyPath, seedPath, seed } = await fixture(t);
|
||||
await writeFile(policyPath, seed, { mode: 0o644 });
|
||||
|
||||
const result = await migratePermissionPolicy(policyPath, seedPath);
|
||||
|
||||
assert.deepEqual(result, { status: "current" });
|
||||
assert.equal((await stat(policyPath)).mode & 0o777, 0o600);
|
||||
});
|
||||
|
||||
test("returns missing without creating a policy", async (t) => {
|
||||
const { policyPath, seedPath } = await fixture(t);
|
||||
assert.deepEqual(await migratePermissionPolicy(policyPath, seedPath), {
|
||||
status: "missing",
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects invalid current JSONC without replacing it", async (t) => {
|
||||
const { policyPath, seedPath } = await fixture(t);
|
||||
const invalid = "{ invalid\n";
|
||||
await writeFile(policyPath, invalid, { mode: 0o600 });
|
||||
|
||||
await assert.rejects(
|
||||
migratePermissionPolicy(policyPath, seedPath),
|
||||
/invalid JSONC/,
|
||||
);
|
||||
assert.equal(await readFile(policyPath, "utf8"), invalid);
|
||||
});
|
||||
|
||||
test("aborts if the policy changes before commit", async (t) => {
|
||||
const { directory, policyPath, seedPath } = await fixture(t);
|
||||
const legacy = `{"permission":{"*":"allow"}}\n`;
|
||||
const concurrent = `{"permission":{"*":"deny"}}\n`;
|
||||
await writeFile(policyPath, legacy, { mode: 0o600 });
|
||||
|
||||
await assert.rejects(
|
||||
migratePermissionPolicy(policyPath, seedPath, {
|
||||
legacyHashes: new Set([permissionPolicySemanticHash(legacy)]),
|
||||
beforeCommit: () => writeFile(policyPath, concurrent, "utf8"),
|
||||
}),
|
||||
/changed during migration/,
|
||||
);
|
||||
|
||||
assert.equal(await readFile(policyPath, "utf8"), concurrent);
|
||||
const entries = await readdir(directory);
|
||||
assert.equal(entries.some((name) => name.includes(".bak.")), true);
|
||||
assert.equal(entries.some((name) => name.includes(".tmp.")), false);
|
||||
});
|
||||
@@ -172,10 +172,6 @@ async function updateFixture(t: test.TestContext, piExitStatus = 0) {
|
||||
join(repositoryRoot, "config", "pi-permission-policy.jsonc"),
|
||||
join(updatedBundle, "config", "pi-permission-policy.jsonc"),
|
||||
);
|
||||
await copyFile(
|
||||
join(repositoryRoot, "scripts", "migrate-permission-policy.mjs"),
|
||||
join(updatedBundle, "scripts", "migrate-permission-policy.mjs"),
|
||||
);
|
||||
await writeFile(
|
||||
join(bin, "pi"),
|
||||
`#!/bin/sh\nprintf 'pi %s\\n' "$*" >> "$MOCK_PI_LOG"\nexit ${piExitStatus}\n`,
|
||||
|
||||
Reference in New Issue
Block a user