Files
my-pi/tests/bundle-config.test.ts
T
云服务部-叶林立andDevin <158243242+devin-ai-integration[bot]@users.noreply.github.com> ba164896d2 feat: 系统提示词改为单一入口统一管理
多个扩展各自整段改写系统提示词并按加载顺序接力,任一扩展定死提示词后
其余只能做字符串手术,且各上游的工具说明与组合包实际工具格局冲突。

- 新增 extensions/system-prompt.ts 作为唯一出口(加载列表最后),按
  config/prompt/(preamble.md、tools.jsonc、routing.jsonc、sections.jsonc)
  组合开场白、工具简介/规则与 <tool_routing> 分区;替代原封面与
  tool-routing 扩展,/dump-system-prompt 输出最终提示词。
- pi-chrome、pi-ssh、pi-hermes-memory 改为写命名分区,pi-rtk-optimizer
  改写 promptGuidelines,pi-permission-system 直接过滤结构化 skills,
  均不再返回 systemPrompt;pi-chrome 未授权时不再每轮冻结提示词。
- 新增 prompt-guard 代理加载第三方扩展(Hashline、FFF、LSP、
  context-mode):拦截直接改写提示词并按目录覆盖工具说明;context-mode
  去掉与组合包路由冲突的锚点段,保留记忆与恢复快照。
- 消除冲突:bash 简介不再建议 grep/find;Hashline edit 不再称可用 grep
  锚点、不再介绍已关闭的 replace_text;context-mode 读写/网页路由提示。
- 守门测试:工具目录覆盖率、禁用用法检查、context-mode 上游原文锁定;
  AGENTS.md 新增「系统提示词单一所有权」。

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-20 17:53:04 -07:00

118 lines
4.3 KiB
TypeScript

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 { resolvePreamblePath } from "../extensions/system-prompt-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",
"prompt/preamble.md",
"prompt/tools.jsonc",
"prompt/routing.jsonc",
"prompt/sections.jsonc",
"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(resolvePreamblePath(), "prompt/preamble.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",
),
);
});