mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat: 组合包配置以包内 config/ 为唯一来源,并新增受保护写入人工审批
配置统一:权限策略、硬防御、Tool Search、提示词封面以及新迁入的 RTK、pi-compaction、pi-worktree、pi-hermes-memory 配置全部由扩展 直接读取已安装组合包内的 config/,pi install / pi update 即完成部署; 删除 rebuild-bundle-config.mjs 与 bundle-manifest.json,my-pi/ 只保留 日志与缓存。update.sh 成功升级后将默认 git 来源的已安装副本 reset 回发布版本。AGENTS.md 新增「组合包配置原则」。 脚本整合:search_config.sh / ssh_config.sh 合并为 configure.sh search|ssh;install.sh / update.sh 共享函数抽到 scripts/lib.sh,远程 安装器改为先下载到临时文件再执行,下载失败可被检测。 权限:hard-guards 新增 protectedWrites,写入 Pi 凭据/设置、已安装 组合包与扩展目录、pi-ssh 凭据库时一律人工确认(跳过 AutoReview、 yolo 与 Session grant,无 UI 时拒绝);放行 ls、LSP 查询、ctx 只读、 web_search、Chrome 只读与 git 只读命令,skill_manage 改为 ask。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
a0ee9389c7
commit
2aa1be0b54
@@ -0,0 +1,114 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
getGlobalConfigPath,
|
||||
getGlobalLogsDir,
|
||||
getHardGuardConfigPath,
|
||||
} from "../pi-permission-system/src/config-paths.ts";
|
||||
import {
|
||||
getToolSearchCatalogPath,
|
||||
getToolSearchConfigPath,
|
||||
} from "../pi-tool-search/extensions/config.ts";
|
||||
import {
|
||||
CONFIG_PATH as RTK_CONFIG_PATH,
|
||||
resolveConfigPath as resolveRtkConfigPath,
|
||||
} from "../pi-rtk-optimizer/src/constants.ts";
|
||||
import { CONFIG_PATH as COMPACTION_CONFIG_PATH } from "../pi-compaction/src/config.ts";
|
||||
import { WORKTREE_CONFIG_PATH } from "../pi-worktree/src/settings.ts";
|
||||
import { resolveCoverPath } from "../extensions/system-prompt-cover-config.ts";
|
||||
|
||||
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const bundleConfigDir = join(repositoryRoot, "config");
|
||||
|
||||
// pi-hermes-memory's config module uses runtime "./x.js" specifiers that
|
||||
// Node's type stripping cannot resolve to sibling ".ts" files, so it is
|
||||
// loaded through jiti instead of a plain import.
|
||||
const { createJiti } = await import("jiti");
|
||||
const jiti = createJiti(import.meta.url);
|
||||
const { DEFAULT_CONFIG_PATH: HERMES_CONFIG_PATH } = (await jiti.import(
|
||||
join(repositoryRoot, "pi-hermes-memory", "src", "config.ts"),
|
||||
)) as { DEFAULT_CONFIG_PATH: string };
|
||||
|
||||
/** Bundle config files every extension reads directly at runtime. */
|
||||
const BUNDLE_CONFIG_FILES = [
|
||||
"pi-permission-policy.jsonc",
|
||||
"pi-permission-hard-guards.jsonc",
|
||||
"tool-search.json",
|
||||
"rtk-optimizer.json",
|
||||
"pi-compaction.json",
|
||||
"pi-worktree.json",
|
||||
"pi-hermes-memory.json",
|
||||
"system-prompt-cover.md",
|
||||
"pi-hashline-edit.json",
|
||||
"lsp.json",
|
||||
"p10k.zsh",
|
||||
];
|
||||
|
||||
/** Strip JSONC comments (line and block) — same approach as the seed test. */
|
||||
function stripJsonc(raw: string): string {
|
||||
return raw.replace(/^\s*\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
||||
}
|
||||
|
||||
test("every bundle config file exists and is non-empty", async () => {
|
||||
for (const name of BUNDLE_CONFIG_FILES) {
|
||||
const content = await readFile(join(bundleConfigDir, name), "utf8");
|
||||
assert.ok(content.trim().length > 0, `config/${name} must not be empty`);
|
||||
}
|
||||
});
|
||||
|
||||
test("every bundle JSON/JSONC config file parses", async () => {
|
||||
for (const name of BUNDLE_CONFIG_FILES) {
|
||||
if (!name.endsWith(".json") && !name.endsWith(".jsonc")) continue;
|
||||
const raw = await readFile(join(bundleConfigDir, name), "utf8");
|
||||
assert.doesNotThrow(
|
||||
() => JSON.parse(stripJsonc(raw)),
|
||||
`config/${name} must parse as JSONC`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("each extension resolves its config path inside the bundle config/ dir", () => {
|
||||
const savedToolSearch = process.env.PI_TOOL_SEARCH_CONFIG_PATH;
|
||||
const savedRtk = process.env.PI_RTK_CONFIG_PATH;
|
||||
delete process.env.PI_TOOL_SEARCH_CONFIG_PATH;
|
||||
delete process.env.PI_RTK_CONFIG_PATH;
|
||||
try {
|
||||
const inBundleConfig = (resolved: string, file: string) =>
|
||||
assert.equal(
|
||||
resolved,
|
||||
join(bundleConfigDir, file),
|
||||
`expected the bundle config path for ${file}`,
|
||||
);
|
||||
|
||||
inBundleConfig(getGlobalConfigPath(), "pi-permission-policy.jsonc");
|
||||
inBundleConfig(getHardGuardConfigPath(), "pi-permission-hard-guards.jsonc");
|
||||
inBundleConfig(getToolSearchConfigPath(), "tool-search.json");
|
||||
inBundleConfig(RTK_CONFIG_PATH, "rtk-optimizer.json");
|
||||
inBundleConfig(resolveRtkConfigPath(), "rtk-optimizer.json");
|
||||
inBundleConfig(COMPACTION_CONFIG_PATH, "pi-compaction.json");
|
||||
inBundleConfig(WORKTREE_CONFIG_PATH, "pi-worktree.json");
|
||||
inBundleConfig(HERMES_CONFIG_PATH, "pi-hermes-memory.json");
|
||||
inBundleConfig(resolveCoverPath(), "system-prompt-cover.md");
|
||||
} finally {
|
||||
if (savedToolSearch === undefined) delete process.env.PI_TOOL_SEARCH_CONFIG_PATH;
|
||||
else process.env.PI_TOOL_SEARCH_CONFIG_PATH = savedToolSearch;
|
||||
if (savedRtk === undefined) delete process.env.PI_RTK_CONFIG_PATH;
|
||||
else process.env.PI_RTK_CONFIG_PATH = savedRtk;
|
||||
}
|
||||
});
|
||||
|
||||
test("disposable runtime state stays under the agent-dir my-pi tree", () => {
|
||||
const agentDir = "/agent";
|
||||
assert.ok(
|
||||
getGlobalLogsDir(agentDir).endsWith("my-pi/permission-system/logs"),
|
||||
);
|
||||
assert.ok(
|
||||
getToolSearchCatalogPath(agentDir).endsWith(
|
||||
"my-pi/tool-search/catalog-v1.json",
|
||||
),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user