Stop Pi metadata tasks from cluttering session history (#1999)

* fix: 避免内部 Pi Agent 持久化会话

* test: 聚焦 Pi 会话持久化行为
This commit is contained in:
psyche
2026-07-12 21:35:38 +00:00
committed by GitHub
parent 4a1534cacd
commit c2a1ac7c3b
3 changed files with 30 additions and 1 deletions
@@ -82,6 +82,29 @@ test("forwards launch-context env to the Pi process launch", async () => {
await session.close();
});
test("starts internal Pi agents without persisting a native session", async () => {
const pi = new FakePi();
const client = createClient(pi);
const session = await client.createSession(createConfig({ internal: true }));
expect(pi.recordedLaunches[0]).toMatchObject({
noSession: true,
argv: expect.arrayContaining(["--no-session"]),
});
await session.close();
});
test("keeps normal Pi agent sessions persisted", async () => {
const pi = new FakePi();
const client = createClient(pi);
const session = await client.createSession(createConfig());
expect(pi.recordedLaunches[0]?.argv).not.toContain("--no-session");
await session.close();
});
class SessionEvents {
private readonly events: AgentStreamEvent[] = [];
private readonly waiters: Array<{
@@ -1996,6 +1996,7 @@ export class PiRpcAgentClient implements AgentClient {
model: config.model,
thinkingOptionId:
normalizePiThinkingOption(config.thinkingOptionId) ?? DEFAULT_PI_THINKING_LEVEL,
noSession: config.internal === true,
systemPrompt: composeSystemPromptParts(
config.systemPrompt,
config.daemonAppendSystemPrompt,
@@ -15,6 +15,7 @@ export interface PiRuntimeLaunch {
model?: string;
thinkingOptionId?: string;
session?: string;
noSession?: boolean;
systemPrompt?: string;
mcpConfigPath?: string;
extensionPaths?: string[];
@@ -26,6 +27,7 @@ export interface PiStartSessionInput {
model?: string;
thinkingOptionId?: string;
session?: string;
noSession?: boolean;
systemPrompt?: string;
mcpConfigPath?: string;
extensionPaths?: string[];
@@ -79,7 +81,9 @@ export function buildPiLaunch(input: {
if (input.session.thinkingOptionId) {
argv.push("--thinking", input.session.thinkingOptionId);
}
if (input.session.session) {
if (input.session.noSession) {
argv.push("--no-session");
} else if (input.session.session) {
argv.push("--session", input.session.session);
}
const systemPrompt = input.session.systemPrompt?.trim();
@@ -106,6 +110,7 @@ export function buildPiLaunch(input: {
model: input.session.model,
thinkingOptionId: input.session.thinkingOptionId,
session: input.session.session,
noSession: input.session.noSession,
systemPrompt,
mcpConfigPath: input.session.mcpConfigPath,
extensionPaths: input.session.extensionPaths,