diff --git a/LifeOS/install/LIFEOS/PULSE/modules/siri.resume.test.ts b/LifeOS/install/LIFEOS/PULSE/modules/siri.resume.test.ts new file mode 100644 index 0000000000..ee42bc478c --- /dev/null +++ b/LifeOS/install/LIFEOS/PULSE/modules/siri.resume.test.ts @@ -0,0 +1,46 @@ +/** + * Verifies that the second Siri turn passes the first session id to query() + * inside options.resume rather than beside options. + * + * Issue #2795 + */ +import { test, expect, mock } from "bun:test"; +import { join } from "node:path"; +import { homedir } from "node:os"; + +const pulse = join(process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"), "LIFEOS", "PULSE"); +const calls: any[] = []; +mock.module(Bun.resolveSync("@anthropic-ai/claude-agent-sdk", join(pulse, "modules")), () => ({ + query: (args: any) => { + calls.push(args); + return (async function* () { + yield { type: "system", subtype: "init", session_id: "sess-1" }; + yield { type: "assistant", message: { content: [{ type: "text", text: "ok" }] } }; + })(); + }, +})); +mock.module(join(pulse, "lib", "lifeos-context.ts"), () => ({ buildLifeosContextBlock: async () => "" })); +mock.module(join(pulse, "lib", "mcp-allowlist.ts"), () => ({ loadRemoteMcpServers: () => ({}), mcpStatusPromptLine: () => "" })); +mock.module(join(pulse, "..", "..", "hooks", "lib", "identity.ts"), () => ({ getDAName: () => "DA", getPrincipalName: () => "Principal" })); + +const TEST_BEARER = "probe"; +process.env.SIRI_API_KEY = TEST_BEARER; + +const { handleSiriRequest } = await import("./siri.ts"); +const turn = (text: string) => + handleSiriRequest( + new Request("http://localhost/api/siri/turn", { + method: "POST", + headers: { authorization: `Bearer ${TEST_BEARER}`, "content-type": "application/json" }, + body: JSON.stringify({ text }), + }), + "/api/siri/turn" + ); + +test("second Siri turn passes the first session id to query() as options.resume", async () => { + await turn("first"); + await turn("second"); + expect(calls.length).toBe(2); + expect(calls[1].options?.resume).toBe("sess-1"); + expect(calls[1].options?.permissionMode).toBe("default"); +}); \ No newline at end of file diff --git a/LifeOS/install/LIFEOS/PULSE/modules/siri.ts b/LifeOS/install/LIFEOS/PULSE/modules/siri.ts index d4099fcca4..d2fb560815 100644 --- a/LifeOS/install/LIFEOS/PULSE/modules/siri.ts +++ b/LifeOS/install/LIFEOS/PULSE/modules/siri.ts @@ -98,6 +98,8 @@ async function runTurn(text: string): Promise { tools: { type: "preset", preset: "claude_code" }, ...(Object.keys(remoteMcp).length > 0 ? { mcpServers: remoteMcp } : {}), settingSources: ["user", "project"], // no "local" — skip CLAUDE.md mode/format machinery + permissionMode: "default", + ...(resumeFromSdk ? { resume: resumeFromSdk } : {}), // Channel marker — hooks skip the desktop /notify voice when not "desktop". // The principal hears the reply through Siri's TTS on the phone, not the Mac speaker. env: { ...process.env, LIFEOS_NOTIFICATION_CHANNEL: "siri" }, @@ -132,20 +134,14 @@ Rules, absolute: }, } - const queryOpts: { prompt: string; resume?: string; options?: unknown } = { - prompt: text, - options: sdkOptions, - } - if (resumeFromSdk) queryOpts.resume = resumeFromSdk - - // The controller must reach query() via `options.abortController`; a flag + // The controller must reach query() via options.abortController; a flag // checked between messages cannot cancel a turn stalled mid-tool. // (public issue #2027, @bowlax) const timeoutController = new AbortController() const timeout = setTimeout(() => timeoutController.abort(), SDK_TIMEOUT_MS) sdkOptions.abortController = timeoutController - const conversation = query(queryOpts as never) + const conversation = query({ prompt: text, options: sdkOptions as never }) let fullText = "" try {