mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
- codemode:Tool Search 常驻(alwaysEnabled)、权限 allow(嵌套调用仍逐个过权限门)、 tools.jsonc 登记使用规则;RTK 跳过 parentToolCallId 嵌套调用,避免丢失 bash structuredContent;Tool Search 目录过滤 hidden / codemode(script-only)exposure; 扩展加载测试加载 builtin:codemode 并断言其常驻激活 - 搜索 key 不再经命令行参数传递:search-auth.mjs 改为 --set-stdin(先读校验再加锁), configure.sh 交互输入经管道、非交互用 --<provider> - - CodeGraph 客户端监听子进程 stdin error,避免 EPIPE 未处理导致崩溃 - 移除 PI_TOOL_SEARCH/HERMES_MEMORY/RTK_CONFIG_PATH 环境变量入口,测试改用工厂 configPath 注入 - pi-subagents 固定 vitest / coverage-istanbul 4.1.10,修复 npm ls 版本冲突 - 补 pi-web-search / pi-worktree UPSTREAM.md 与 pi-minimal-footer AGENTS.md, files 白名单补齐并加测试;.codegraph/.gitignore 移出跟踪 - detect_kitty 优先识别官方安装目录 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
112 lines
4.5 KiB
TypeScript
112 lines
4.5 KiB
TypeScript
import * as assert from "node:assert/strict";
|
|
import * as fs from "node:fs/promises";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { describe, it } from "node:test";
|
|
|
|
interface MockPi {
|
|
handlers: Record<string, Array<(event: any, ctx: any) => unknown>>;
|
|
tools: Record<string, { execute: (...args: any[]) => Promise<any> }>;
|
|
on(event: string, handler: (event: any, ctx: any) => unknown): void;
|
|
registerTool(def: { name: string; execute: (...args: any[]) => Promise<any> }): void;
|
|
registerCommand(): void;
|
|
}
|
|
|
|
describe("session project memory rebinding", () => {
|
|
it("writes project memory using session cwd when factory cwd differs", async () => {
|
|
const agentRoot = await fs.mkdtemp(path.join(os.tmpdir(), "pi-project-rebind-agent-"));
|
|
const launchDir = await fs.mkdtemp(path.join(os.tmpdir(), "pi-project-rebind-launch-"));
|
|
const targetDir = await fs.mkdtemp(path.join(os.tmpdir(), "pi-project-rebind-target-"));
|
|
const previousAgentRoot = process.env.PI_CODING_AGENT_DIR;
|
|
const configPath = path.join(agentRoot, "hermes-memory-config.json");
|
|
const previousCwd = process.cwd();
|
|
try {
|
|
await fs.writeFile(
|
|
configPath,
|
|
JSON.stringify({
|
|
memoryMode: "legacy-inject",
|
|
reviewEnabled: false,
|
|
flushOnCompact: false,
|
|
flushOnShutdown: false,
|
|
autoConsolidate: false,
|
|
correctionDetection: false,
|
|
standingInstructionsEnabled: false,
|
|
}),
|
|
);
|
|
const launchMemoryDir = path.join(agentRoot, "projects-memory", path.basename(launchDir));
|
|
const sessionMemoryDir = path.join(agentRoot, "projects-memory", path.basename(targetDir));
|
|
await fs.mkdir(launchMemoryDir, { recursive: true });
|
|
await fs.mkdir(sessionMemoryDir, { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(launchMemoryDir, "MEMORY.md"),
|
|
"launch-directory memory",
|
|
);
|
|
await fs.writeFile(
|
|
path.join(sessionMemoryDir, "MEMORY.md"),
|
|
"active-session memory",
|
|
);
|
|
|
|
process.env.PI_CODING_AGENT_DIR = agentRoot;
|
|
process.chdir(launchDir);
|
|
// Import after setting PI_CODING_AGENT_DIR so AGENT_ROOT is test-local.
|
|
const { createHermesMemoryExtension } = await import("../src/index.js");
|
|
const registerExtension = createHermesMemoryExtension({ configPath });
|
|
const mockPi: MockPi = {
|
|
handlers: {},
|
|
tools: {},
|
|
on(event, handler) {
|
|
(this.handlers[event] ??= []).push(handler);
|
|
},
|
|
registerTool(def) {
|
|
this.tools[def.name] = def;
|
|
},
|
|
registerCommand() {},
|
|
};
|
|
registerExtension(mockPi as any);
|
|
|
|
const sessionStart = mockPi.handlers.session_start?.[0];
|
|
const resourcesDiscover = mockPi.handlers.resources_discover?.[0];
|
|
const beforeAgentStart = mockPi.handlers.before_agent_start?.[0];
|
|
assert.ok(sessionStart);
|
|
assert.ok(resourcesDiscover);
|
|
assert.ok(beforeAgentStart);
|
|
assert.ok(mockPi.tools.memory_add);
|
|
|
|
const sessionCtx = {
|
|
cwd: targetDir,
|
|
sessionManager: { getBranch: () => [] },
|
|
ui: { notify() {} },
|
|
};
|
|
|
|
// Pi lifecycle: session_start, then resources_discover, then tool execute.
|
|
await sessionStart({}, sessionCtx);
|
|
await resourcesDiscover({ cwd: targetDir, reason: "startup" }, sessionCtx);
|
|
|
|
const result = await beforeAgentStart({ systemPrompt: "base" }, sessionCtx) as { systemPrompt: string };
|
|
assert.match(result.systemPrompt, /active-session memory/);
|
|
assert.doesNotMatch(result.systemPrompt, /launch-directory memory/);
|
|
|
|
const writeResult = await mockPi.tools.memory_add.execute(
|
|
"tc-session-cwd",
|
|
{ target: "project", content: "session-cwd write" },
|
|
undefined,
|
|
undefined,
|
|
{ cwd: targetDir },
|
|
);
|
|
assert.equal(writeResult.details.success, true);
|
|
|
|
const sessionMemory = await fs.readFile(path.join(sessionMemoryDir, "MEMORY.md"), "utf-8");
|
|
const launchMemory = await fs.readFile(path.join(launchMemoryDir, "MEMORY.md"), "utf-8");
|
|
assert.match(sessionMemory, /session-cwd write/);
|
|
assert.doesNotMatch(launchMemory, /session-cwd write/);
|
|
} finally {
|
|
process.chdir(previousCwd);
|
|
if (previousAgentRoot === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
else process.env.PI_CODING_AGENT_DIR = previousAgentRoot;
|
|
await fs.rm(agentRoot, { recursive: true, force: true });
|
|
await fs.rm(launchDir, { recursive: true, force: true });
|
|
await fs.rm(targetDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|