Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions LifeOS/install/LIFEOS/PULSE/modules/siri.resume.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
12 changes: 4 additions & 8 deletions LifeOS/install/LIFEOS/PULSE/modules/siri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ async function runTurn(text: string): Promise<string> {
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" },
Expand Down Expand Up @@ -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 {
Expand Down