@eloxiv/daemon 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/Acp.d.ts +8 -0
  4. package/dist/Acp.d.ts.map +1 -0
  5. package/dist/Acp.js +268 -0
  6. package/dist/Acp.js.map +1 -0
  7. package/dist/Canonical.d.ts +3 -0
  8. package/dist/Canonical.d.ts.map +1 -0
  9. package/dist/Canonical.js +12 -0
  10. package/dist/Canonical.js.map +1 -0
  11. package/dist/Client.d.ts +100 -0
  12. package/dist/Client.d.ts.map +1 -0
  13. package/dist/Client.js +474 -0
  14. package/dist/Client.js.map +1 -0
  15. package/dist/Commands.d.ts +85 -0
  16. package/dist/Commands.d.ts.map +1 -0
  17. package/dist/Commands.js +370 -0
  18. package/dist/Commands.js.map +1 -0
  19. package/dist/Config.d.ts +74 -0
  20. package/dist/Config.d.ts.map +1 -0
  21. package/dist/Config.js +126 -0
  22. package/dist/Config.js.map +1 -0
  23. package/dist/Daemon.d.ts +243 -0
  24. package/dist/Daemon.d.ts.map +1 -0
  25. package/dist/Daemon.js +965 -0
  26. package/dist/Daemon.js.map +1 -0
  27. package/dist/Harness.d.ts +133 -0
  28. package/dist/Harness.d.ts.map +1 -0
  29. package/dist/Harness.js +734 -0
  30. package/dist/Harness.js.map +1 -0
  31. package/dist/Http.d.ts +15 -0
  32. package/dist/Http.d.ts.map +1 -0
  33. package/dist/Http.js +548 -0
  34. package/dist/Http.js.map +1 -0
  35. package/dist/KernelLink.d.ts +145 -0
  36. package/dist/KernelLink.d.ts.map +1 -0
  37. package/dist/KernelLink.js +109 -0
  38. package/dist/KernelLink.js.map +1 -0
  39. package/dist/LocalAuth.d.ts +99 -0
  40. package/dist/LocalAuth.d.ts.map +1 -0
  41. package/dist/LocalAuth.js +225 -0
  42. package/dist/LocalAuth.js.map +1 -0
  43. package/dist/Main.d.ts +51 -0
  44. package/dist/Main.d.ts.map +1 -0
  45. package/dist/Main.js +219 -0
  46. package/dist/Main.js.map +1 -0
  47. package/dist/Secrets.d.ts +21 -0
  48. package/dist/Secrets.d.ts.map +1 -0
  49. package/dist/Secrets.js +204 -0
  50. package/dist/Secrets.js.map +1 -0
  51. package/dist/SecureUrl.d.ts +11 -0
  52. package/dist/SecureUrl.d.ts.map +1 -0
  53. package/dist/SecureUrl.js +23 -0
  54. package/dist/SecureUrl.js.map +1 -0
  55. package/dist/State.d.ts +77 -0
  56. package/dist/State.d.ts.map +1 -0
  57. package/dist/State.js +38 -0
  58. package/dist/State.js.map +1 -0
  59. package/dist/Terminals.d.ts +49 -0
  60. package/dist/Terminals.d.ts.map +1 -0
  61. package/dist/Terminals.js +203 -0
  62. package/dist/Terminals.js.map +1 -0
  63. package/dist/bin-node.d.ts +2 -0
  64. package/dist/bin-node.d.ts.map +1 -0
  65. package/dist/bin-node.js +4 -0
  66. package/dist/bin-node.js.map +1 -0
  67. package/dist/bin.d.ts +2 -0
  68. package/dist/bin.d.ts.map +1 -0
  69. package/dist/bin.js +4 -0
  70. package/dist/bin.js.map +1 -0
  71. package/dist/index.d.ts +17 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +17 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/runtime/bun.d.ts +11 -0
  76. package/dist/runtime/bun.d.ts.map +1 -0
  77. package/dist/runtime/bun.js +20 -0
  78. package/dist/runtime/bun.js.map +1 -0
  79. package/dist/runtime/node.d.ts +11 -0
  80. package/dist/runtime/node.d.ts.map +1 -0
  81. package/dist/runtime/node.js +21 -0
  82. package/dist/runtime/node.js.map +1 -0
  83. package/dist/testing.d.ts +25 -0
  84. package/dist/testing.d.ts.map +1 -0
  85. package/dist/testing.js +27 -0
  86. package/dist/testing.js.map +1 -0
  87. package/fixtures/claude-code-env-vars.txt +409 -0
  88. package/fixtures/fake-acp-agent.mjs +222 -0
  89. package/fixtures/fake-harness.mjs +299 -0
  90. package/fixtures/recorded/claude-code.jsonl +7 -0
  91. package/fixtures/recorded/codex.jsonl +6 -0
  92. package/package.json +64 -3
  93. package/scripts/build-sidecar.ts +86 -0
  94. package/src/Acp.ts +292 -0
  95. package/src/Canonical.ts +9 -0
  96. package/src/Client.ts +585 -0
  97. package/src/Commands.ts +427 -0
  98. package/src/Config.ts +179 -0
  99. package/src/Daemon.ts +1092 -0
  100. package/src/Harness.ts +839 -0
  101. package/src/Http.ts +563 -0
  102. package/src/KernelLink.ts +197 -0
  103. package/src/LocalAuth.ts +301 -0
  104. package/src/Main.ts +281 -0
  105. package/src/Secrets.ts +226 -0
  106. package/src/SecureUrl.ts +21 -0
  107. package/src/State.ts +109 -0
  108. package/src/Terminals.ts +227 -0
  109. package/src/bin-node.ts +4 -0
  110. package/src/bin.ts +4 -0
  111. package/src/index.ts +16 -0
  112. package/src/runtime/bun.ts +29 -0
  113. package/src/runtime/node.ts +30 -0
  114. package/src/testing.ts +43 -0
@@ -0,0 +1,222 @@
1
+ // A stand-in for an Agent Client Protocol agent (OpenCode's `opencode acp`, Gemini CLI's `--experimental-acp`, ...),
2
+ // for tests that need no subscription. It answers `initialize`, `session/new` and `session/load` (sessions are kept
3
+ // in <cwd>/.fake-sessions/<id>.json), runs `session/prompt` as a script and streams `session/update` notifications,
4
+ // calling MCP tools through the server `session/new` named (the daemon's relay).
5
+ //
6
+ // The prompt is a script, one instruction per line:
7
+ // CALL <tool> <json> call an MCP tool (the kernel's tool name, e.g. workshop_write) with these arguments
8
+ // SAY <text> say something (everything said is the answer)
9
+ // RECALL say what the loaded session last said ("recalled <answer>")
10
+ // BUILTIN <name> ask permission to run a built-in tool; say "<name> allowed" or "<name> refused"
11
+ // PERMISSIONS say the OpenCode permission configuration it was given (OPENCODE_CONFIG_CONTENT)
12
+ // FAIL <message> end the turn with a refusal
13
+ // Exits when its parent dies or its stdin closes.
14
+
15
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
16
+ import { join } from "node:path"
17
+
18
+ if (process.argv.includes("--version")) {
19
+ process.stdout.write("0.0.0-fake-acp\n")
20
+ process.exit(0)
21
+ }
22
+ const parent = process.ppid
23
+ setInterval(() => {
24
+ if (process.ppid !== parent) process.exit(1)
25
+ }, 100).unref()
26
+
27
+ const out = (message) => process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}\n`)
28
+ const sessionFile = (cwd, id) => join(cwd, ".fake-sessions", `${id}.json`)
29
+ const sessions = new Map()
30
+ const waiting = new Map()
31
+ let nextId = 1000
32
+
33
+ const ask = (method, params) =>
34
+ new Promise((resolve) => {
35
+ const id = ++nextId
36
+ waiting.set(id, resolve)
37
+ out({ id, method, params })
38
+ })
39
+
40
+ const update = (sessionId, value) => out({ method: "session/update", params: { sessionId, update: value } })
41
+
42
+ const mcp = async (server, state, message) => {
43
+ const headers = {
44
+ "content-type": "application/json",
45
+ accept: "application/json, text/event-stream",
46
+ "mcp-protocol-version": "2025-06-18",
47
+ }
48
+ for (const header of server.headers ?? []) headers[header.name] = header.value
49
+ if (state.mcpSession) headers["mcp-session-id"] = state.mcpSession
50
+ const response = await fetch(server.url, { method: "POST", headers, body: JSON.stringify(message) })
51
+ const session = response.headers.get("mcp-session-id")
52
+ if (session) state.mcpSession = session
53
+ const text = await response.text()
54
+ if (!response.ok) throw new Error(`MCP ${response.status}: ${text.slice(0, 300)}`)
55
+ if (message.id === undefined || text.trim() === "") return undefined
56
+ if ((response.headers.get("content-type") ?? "").includes("text/event-stream")) {
57
+ for (const line of text.split("\n")) {
58
+ if (!line.startsWith("data:")) continue
59
+ const data = JSON.parse(line.slice(5))
60
+ if (data.id === message.id) return data
61
+ }
62
+ return undefined
63
+ }
64
+ return JSON.parse(text)
65
+ }
66
+
67
+ const run = async (sessionId, prompt) => {
68
+ const session = sessions.get(sessionId)
69
+ const said = []
70
+ const say = (text) => {
71
+ // Lines of one message: chunks the client joins as they come.
72
+ update(sessionId, {
73
+ sessionUpdate: "agent_message_chunk",
74
+ content: { type: "text", text: said.length > 0 ? `\n${text}` : text },
75
+ })
76
+ said.push(text)
77
+ }
78
+ let call = 0
79
+ for (const raw of prompt.split("\n")) {
80
+ const line = raw.trim()
81
+ const space = line.indexOf(" ")
82
+ const verb = space < 0 ? line : line.slice(0, space)
83
+ const rest = space < 0 ? "" : line.slice(space + 1).trim()
84
+ if (verb === "SAY") say(rest)
85
+ else if (verb === "RECALL") say(`recalled ${session.said ?? "nothing"}`)
86
+ else if (verb === "PERMISSIONS") say(process.env.OPENCODE_CONFIG_CONTENT ?? "none")
87
+ else if (verb === "FAIL") return "refusal"
88
+ else if (verb === "BUILTIN") {
89
+ const toolCallId = `call_${call++}`
90
+ update(sessionId, { sessionUpdate: "tool_call", toolCallId, title: rest, kind: "execute", status: "pending" })
91
+ const answer = await ask("session/request_permission", {
92
+ sessionId,
93
+ toolCall: { toolCallId, title: rest },
94
+ options: [
95
+ { optionId: "yes", name: "Allow", kind: "allow_once" },
96
+ { optionId: "no", name: "Reject", kind: "reject_once" },
97
+ ],
98
+ })
99
+ const allowed = answer?.outcome?.outcome === "selected" && answer.outcome.optionId === "yes"
100
+ update(sessionId, {
101
+ sessionUpdate: "tool_call_update",
102
+ toolCallId,
103
+ status: allowed ? "completed" : "failed",
104
+ content: [{ type: "content", content: { type: "text", text: "secret file contents" } }],
105
+ })
106
+ say(`${rest} ${allowed ? "allowed" : "refused"}`)
107
+ } else if (verb === "CALL") {
108
+ const toolSpace = rest.indexOf(" ")
109
+ const tool = toolSpace < 0 ? rest : rest.slice(0, toolSpace)
110
+ const input = toolSpace < 0 ? {} : JSON.parse(rest.slice(toolSpace + 1))
111
+ const toolCallId = `call_${call++}`
112
+ update(sessionId, {
113
+ sessionUpdate: "tool_call",
114
+ toolCallId,
115
+ title: `eloxiv_${tool}`,
116
+ kind: "other",
117
+ status: "pending",
118
+ rawInput: input,
119
+ })
120
+ let text
121
+ let failed = false
122
+ try {
123
+ if (!session.connected) {
124
+ await mcp(session.server, session, {
125
+ jsonrpc: "2.0",
126
+ id: ++nextId,
127
+ method: "initialize",
128
+ params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "fake-acp", version: "0" } },
129
+ })
130
+ await mcp(session.server, session, { jsonrpc: "2.0", method: "notifications/initialized" })
131
+ session.connected = true
132
+ }
133
+ const answer = await mcp(session.server, session, {
134
+ jsonrpc: "2.0",
135
+ id: ++nextId,
136
+ method: "tools/call",
137
+ params: { name: tool, arguments: input },
138
+ })
139
+ if (answer?.error) {
140
+ failed = true
141
+ text = answer.error.message
142
+ } else {
143
+ failed = answer?.result?.isError === true
144
+ text = (answer?.result?.content ?? []).map((part) => part.text ?? "").join("")
145
+ }
146
+ } catch (error) {
147
+ failed = true
148
+ text = String(error)
149
+ }
150
+ update(sessionId, {
151
+ sessionUpdate: "tool_call_update",
152
+ toolCallId,
153
+ status: failed ? "failed" : "completed",
154
+ content: [{ type: "content", content: { type: "text", text } }],
155
+ })
156
+ }
157
+ }
158
+ session.said = said.join("\n")
159
+ mkdirSync(join(session.cwd, ".fake-sessions"), { recursive: true })
160
+ writeFileSync(sessionFile(session.cwd, sessionId), JSON.stringify({ said: session.said }))
161
+ return "end_turn"
162
+ }
163
+
164
+ const handle = async (message) => {
165
+ if (message.id !== undefined && message.method === undefined) {
166
+ waiting.get(message.id)?.(message.result)
167
+ waiting.delete(message.id)
168
+ return
169
+ }
170
+ const params = message.params ?? {}
171
+ switch (message.method) {
172
+ case "initialize":
173
+ out({
174
+ id: message.id,
175
+ result: { protocolVersion: 1, agentCapabilities: { loadSession: true, mcpCapabilities: { http: true } } },
176
+ })
177
+ return
178
+ case "session/new": {
179
+ const sessionId = crypto.randomUUID()
180
+ sessions.set(sessionId, { cwd: params.cwd, server: params.mcpServers?.[0] })
181
+ out({ id: message.id, result: { sessionId } })
182
+ return
183
+ }
184
+ case "session/load": {
185
+ if (!existsSync(sessionFile(params.cwd, params.sessionId))) {
186
+ out({ id: message.id, error: { code: -32002, message: `No session ${params.sessionId}` } })
187
+ return
188
+ }
189
+ const kept = JSON.parse(readFileSync(sessionFile(params.cwd, params.sessionId), "utf8"))
190
+ sessions.set(params.sessionId, { cwd: params.cwd, server: params.mcpServers?.[0], said: kept.said })
191
+ // The history is replayed before the answer, as ACP agents do.
192
+ update(params.sessionId, { sessionUpdate: "agent_message_chunk", content: { type: "text", text: kept.said } })
193
+ out({ id: message.id, result: {} })
194
+ return
195
+ }
196
+ case "session/prompt": {
197
+ const text = (params.prompt ?? []).map((block) => block.text ?? "").join("")
198
+ const stopReason = await run(params.sessionId, text)
199
+ out({ id: message.id, result: { stopReason } })
200
+ return
201
+ }
202
+ case "session/cancel":
203
+ process.exit(0)
204
+ return
205
+ default:
206
+ if (message.id !== undefined) out({ id: message.id, error: { code: -32601, message: "Method not found" } })
207
+ }
208
+ }
209
+
210
+ let buffer = ""
211
+ process.stdin.setEncoding("utf8")
212
+ process.stdin.on("data", (chunk) => {
213
+ buffer += chunk
214
+ let newline = buffer.indexOf("\n")
215
+ while (newline >= 0) {
216
+ const line = buffer.slice(0, newline).trim()
217
+ buffer = buffer.slice(newline + 1)
218
+ if (line.length > 0) void handle(JSON.parse(line))
219
+ newline = buffer.indexOf("\n")
220
+ }
221
+ })
222
+ process.stdin.on("end", () => process.exit(0))
@@ -0,0 +1,299 @@
1
+ // A stand-in for the `claude` and `codex` CLIs, for tests that need no subscription. It accepts the arguments
2
+ // the daemon's adapters pass, connects to the MCP endpoint they configure (the daemon's relay), and prints the
3
+ // same stream format as the real CLI (see fixtures/recorded/, captured from real runs).
4
+ //
5
+ // The prompt is a script, one instruction per line:
6
+ // CALL <tool> <json> call an MCP tool (the kernel's tool name, e.g. desk_write) with these arguments
7
+ // SAY <text> say something (the last thing said is the answer)
8
+ // SLEEP <ms> wait
9
+ // MARK <path> create a file (tests wait for it)
10
+ // WAITFILE <path> wait until a file exists
11
+ // FAIL <message> end the turn as failed
12
+ // RECALL say what the resumed session last said ("recalled <answer>")
13
+ // Anything else is ignored. Exits when its parent dies (it is the daemon's child).
14
+ //
15
+ // Sessions: unless told to keep nothing (Claude Code's --no-session-persistence, Codex's --ephemeral), the session's
16
+ // last answer is kept in <cwd>/.fake-sessions/<id>.json, as the real CLIs keep sessions per working directory;
17
+ // `--resume <id>` (Claude Code) or `exec resume ... -- <id> <prompt>` (Codex) continues one, and fails like the real
18
+ // CLI when there is none in this directory.
19
+
20
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
21
+ import { join } from "node:path"
22
+
23
+ const args = process.argv.slice(2)
24
+ const parent = process.ppid
25
+ setInterval(() => {
26
+ if (process.ppid !== parent) process.exit(1)
27
+ }, 100).unref()
28
+
29
+ const out = (value) => process.stdout.write(`${JSON.stringify(value)}\n`)
30
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
31
+
32
+ // --- version and sign-in probes ------------------------------------------------------------------------------
33
+ if (args[0] === "--version") {
34
+ process.stdout.write(args.includes("exec") ? "codex-cli 0.0.0-fake\n" : "0.0.0-fake (Fake Harness)\n")
35
+ process.exit(0)
36
+ }
37
+ if (args[0] === "auth" && args[1] === "status") {
38
+ out({ loggedIn: true, authMethod: "fake", apiProvider: "firstParty" })
39
+ process.exit(0)
40
+ }
41
+ if (args[0] === "login" && args[1] === "status") {
42
+ process.stdout.write("Logged in using a fake subscription\n")
43
+ process.exit(0)
44
+ }
45
+
46
+ const codex = args[0] === "exec"
47
+ const codexResume = codex && args[1] === "resume"
48
+ const dash = args.indexOf("--")
49
+ const positional = dash >= 0 ? args.slice(dash + 1) : [args.at(-1) ?? ""]
50
+ const prompt = (codexResume ? positional.slice(1) : positional).join(" ")
51
+ const option = (name) => {
52
+ const index = args.indexOf(name)
53
+ return index >= 0 ? args[index + 1] : undefined
54
+ }
55
+ const resumeId = codexResume ? positional[0] : option("--resume")
56
+ const keepSession = codex ? !args.includes("--ephemeral") : !args.includes("--no-session-persistence")
57
+ const sessionFile = (id) => join(process.cwd(), ".fake-sessions", `${id}.json`)
58
+
59
+ // --- the MCP endpoint ------------------------------------------------------------------------------------------
60
+ let url
61
+ let authorization
62
+ if (codex) {
63
+ for (let i = 0; i < args.length; i++) {
64
+ if (args[i] !== "-c") continue
65
+ const [key, ...rest] = args[i + 1].split("=")
66
+ const value = rest.join("=")
67
+ if (key === "mcp_servers.eloxiv.url") url = JSON.parse(value)
68
+ if (key === "mcp_servers.eloxiv.bearer_token_env_var") authorization = `Bearer ${process.env[JSON.parse(value)]}`
69
+ }
70
+ } else {
71
+ const config = JSON.parse(readFileSync(option("--mcp-config"), "utf8")).mcpServers.eloxiv
72
+ url = config.url
73
+ authorization = config.headers.authorization
74
+ }
75
+
76
+ let mcpSession
77
+ let rpcId = 0
78
+ const rpc = async (message) => {
79
+ const response = await fetch(url, {
80
+ method: "POST",
81
+ headers: {
82
+ "content-type": "application/json",
83
+ accept: "application/json, text/event-stream",
84
+ "mcp-protocol-version": "2025-06-18",
85
+ authorization,
86
+ ...(mcpSession ? { "mcp-session-id": mcpSession } : {}),
87
+ },
88
+ body: JSON.stringify(message),
89
+ })
90
+ const session = response.headers.get("mcp-session-id")
91
+ if (session) mcpSession = session
92
+ const text = await response.text()
93
+ if (!response.ok) throw new Error(`MCP ${response.status}: ${text.slice(0, 300)}`)
94
+ if (message.id === undefined || text.trim() === "") return undefined
95
+ if ((response.headers.get("content-type") ?? "").includes("text/event-stream")) {
96
+ for (const line of text.split("\n")) {
97
+ if (!line.startsWith("data:")) continue
98
+ const data = JSON.parse(line.slice(5))
99
+ if (data.id === message.id) return data
100
+ }
101
+ return undefined
102
+ }
103
+ return JSON.parse(text)
104
+ }
105
+
106
+ const connect = async () => {
107
+ await rpc({
108
+ jsonrpc: "2.0",
109
+ id: ++rpcId,
110
+ method: "initialize",
111
+ params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "fake-harness", version: "0.0.0" } },
112
+ })
113
+ await rpc({ jsonrpc: "2.0", method: "notifications/initialized" })
114
+ }
115
+
116
+ const toolText = (result) =>
117
+ (result?.content ?? [])
118
+ .filter((part) => part.type === "text")
119
+ .map((part) => part.text)
120
+ .join("")
121
+
122
+ // --- the turn ------------------------------------------------------------------------------------------------
123
+ if (resumeId !== undefined && !existsSync(sessionFile(resumeId))) {
124
+ // As the real CLIs answer a session they do not have (in this working directory).
125
+ process.stderr.write(`No conversation found with session ID: ${resumeId}\n`)
126
+ process.exit(1)
127
+ }
128
+ const remembered = resumeId === undefined ? undefined : JSON.parse(readFileSync(sessionFile(resumeId), "utf8"))
129
+ const session = resumeId ?? crypto.randomUUID()
130
+ let item = 0
131
+ let said = "done"
132
+ let failure
133
+
134
+ if (codex) {
135
+ out({ type: "thread.started", thread_id: session })
136
+ out({ type: "turn.started" })
137
+ } else {
138
+ out({
139
+ type: "system",
140
+ subtype: "init",
141
+ cwd: process.cwd(),
142
+ session_id: session,
143
+ tools: [],
144
+ mcp_servers: [{ name: "eloxiv", status: "connected" }],
145
+ model: "fake-model",
146
+ permissionMode: "default",
147
+ apiKeySource: "none",
148
+ })
149
+ }
150
+
151
+ let connected = false
152
+ for (const raw of prompt.split("\n")) {
153
+ const line = raw.trim()
154
+ const space = line.indexOf(" ")
155
+ const verb = space < 0 ? line : line.slice(0, space)
156
+ const rest = space < 0 ? "" : line.slice(space + 1).trim()
157
+ if (verb === "RECALL") {
158
+ said = `recalled ${remembered?.said ?? "nothing"}`
159
+ if (codex) out({ type: "item.completed", item: { id: `item_${item++}`, type: "agent_message", text: said } })
160
+ else
161
+ out({
162
+ type: "assistant",
163
+ message: { type: "message", role: "assistant", model: "fake-model", content: [{ type: "text", text: said }] },
164
+ parent_tool_use_id: null,
165
+ session_id: session,
166
+ })
167
+ } else if (verb === "SLEEP") await sleep(Number(rest))
168
+ else if (verb === "MARK") writeFileSync(rest, "")
169
+ else if (verb === "WAITFILE") {
170
+ while (!existsSync(rest)) await sleep(50)
171
+ } else if (verb === "SAY") {
172
+ said = rest
173
+ if (codex) out({ type: "item.completed", item: { id: `item_${item++}`, type: "agent_message", text: rest } })
174
+ else
175
+ out({
176
+ type: "assistant",
177
+ message: { type: "message", role: "assistant", model: "fake-model", content: [{ type: "text", text: rest }] },
178
+ parent_tool_use_id: null,
179
+ session_id: session,
180
+ })
181
+ } else if (verb === "FAIL") {
182
+ failure = rest
183
+ break
184
+ } else if (verb === "CALL") {
185
+ const toolSpace = rest.indexOf(" ")
186
+ const tool = toolSpace < 0 ? rest : rest.slice(0, toolSpace)
187
+ const input = toolSpace < 0 ? {} : JSON.parse(rest.slice(toolSpace + 1))
188
+ const id = `item_${item++}`
189
+ if (codex) {
190
+ out({
191
+ type: "item.started",
192
+ item: {
193
+ id,
194
+ type: "mcp_tool_call",
195
+ server: "eloxiv",
196
+ tool,
197
+ arguments: input,
198
+ result: null,
199
+ error: null,
200
+ status: "in_progress",
201
+ },
202
+ })
203
+ } else {
204
+ out({
205
+ type: "assistant",
206
+ message: {
207
+ type: "message",
208
+ role: "assistant",
209
+ model: "fake-model",
210
+ content: [{ type: "tool_use", id: `toolu_${id}`, name: `mcp__eloxiv__${tool}`, input }],
211
+ },
212
+ parent_tool_use_id: null,
213
+ session_id: session,
214
+ })
215
+ }
216
+ let result
217
+ let error
218
+ try {
219
+ if (!connected) {
220
+ await connect()
221
+ connected = true
222
+ }
223
+ const answer = await rpc({
224
+ jsonrpc: "2.0",
225
+ id: ++rpcId,
226
+ method: "tools/call",
227
+ params: { name: tool, arguments: input },
228
+ })
229
+ if (answer?.error) error = answer.error.message
230
+ else result = answer?.result
231
+ } catch (e) {
232
+ error = String(e)
233
+ }
234
+ const isError = error !== undefined || result?.isError === true
235
+ const text = error ?? toolText(result)
236
+ if (codex) {
237
+ out({
238
+ type: "item.completed",
239
+ item: {
240
+ id,
241
+ type: "mcp_tool_call",
242
+ server: "eloxiv",
243
+ tool,
244
+ arguments: input,
245
+ result: error === undefined ? { content: result?.content ?? [], structured_content: null } : null,
246
+ error: error === undefined ? null : { message: error },
247
+ status: isError ? "failed" : "completed",
248
+ },
249
+ })
250
+ } else {
251
+ out({
252
+ type: "user",
253
+ message: {
254
+ role: "user",
255
+ content: [
256
+ { tool_use_id: `toolu_${id}`, type: "tool_result", content: [{ type: "text", text }], is_error: isError },
257
+ ],
258
+ },
259
+ parent_tool_use_id: null,
260
+ session_id: session,
261
+ })
262
+ }
263
+ }
264
+ }
265
+
266
+ // Exit once stdout has been written out: `process.exit` straight away can drop what is still queued for a pipe
267
+ // (and an empty write's callback can run before earlier writes are flushed), so end the stream and wait.
268
+ const exit = (code) => {
269
+ if (keepSession && failure === undefined) {
270
+ mkdirSync(join(process.cwd(), ".fake-sessions"), { recursive: true })
271
+ writeFileSync(sessionFile(session), JSON.stringify({ said }))
272
+ }
273
+ process.exitCode = code
274
+ process.stdout.once("finish", () => process.exit(code))
275
+ process.stdout.end()
276
+ }
277
+
278
+ if (codex) {
279
+ if (failure !== undefined) {
280
+ out({ type: "turn.failed", error: { message: failure } })
281
+ exit(1)
282
+ } else {
283
+ out({ type: "turn.completed", usage: { input_tokens: 120, cached_input_tokens: 20, output_tokens: 12 } })
284
+ exit(0)
285
+ }
286
+ } else {
287
+ out({
288
+ type: "result",
289
+ subtype: failure === undefined ? "success" : "error_during_execution",
290
+ is_error: failure !== undefined,
291
+ duration_ms: 1,
292
+ num_turns: item + 1,
293
+ result: failure ?? said,
294
+ session_id: session,
295
+ total_cost_usd: 0,
296
+ usage: { input_tokens: 100, cache_creation_input_tokens: 10, cache_read_input_tokens: 20, output_tokens: 12 },
297
+ })
298
+ exit(failure === undefined ? 0 : 1)
299
+ }
@@ -0,0 +1,7 @@
1
+ {"type":"system","subtype":"init","cwd":"/workspace","session_id":"3eab94b4-833e-497e-9a7e-7264b25a49aa","model":"claude-a/claude-opus-5-5","permissionMode":"auto","apiKeySource":"none","mcp_servers":[{"name":"eloxiv","status":"connected","source":"dynamic"}],"claude_code_version":"2.1.317","tools":["mcp__eloxiv__approvals_approve","mcp__eloxiv__approvals_reject","mcp__eloxiv__consent_approve","mcp__eloxiv__consent_reject","mcp__eloxiv__consent_revoke","mcp__eloxiv__devices_cancelTurn","mcp__eloxiv__devices_sendTurn","mcp__eloxiv__inbox_claim","mcp__eloxiv__inbox_complete","mcp__eloxiv__inbox_dismiss","mcp__eloxiv__inbox_reassign","mcp__eloxiv__notifications_dismiss","mcp__eloxiv__notifications_markRead","mcp__eloxiv__notifications_markUnread","mcp__eloxiv__notifications_setEmailTemplate","mcp__eloxiv__notifications_setPreference","mcp__eloxiv__scheduler_create","mcp__eloxiv__scheduler_delete","mcp__eloxiv__scheduler_pause","mcp__eloxiv__scheduler_resume","mcp__eloxiv__workshop_discard","mcp__eloxiv__workshop_write"],"uuid":"b872e983-5050-4f76-a1b8-31648f5a33ea"}
2
+ {"type":"assistant","message":{"model":"claude-opus-5-5","id":"msg_011CghZ1ME9SSjkD2H1Xbm3U","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01SMGbVZbHW7zJJbC845NZtf","name":"ToolSearch","input":{"query":"select:mcp__eloxiv__workshop_write","max_results":1},"caller":{"type":"direct"}}],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":2,"cache_creation_input_tokens":22360,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":22360,"ephemeral_1h_input_tokens":0},"output_tokens":24,"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null,"context_management":null},"parent_tool_use_id":null,"session_id":"3eab94b4-833e-497e-9a7e-7264b25a49aa","uuid":"f2a0a6e4-97cd-4e7c-bc4a-0c8639a699a3","timestamp":"2026-11-04T08:13:24.656Z","wire_tool_inputs":{"toolu_01SMGbVZbHW7zJJbC845NZtf":{"query":"select:mcp__eloxiv__workshop_write","max_results":1}}}
3
+ {"type":"user","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_01SMGbVZbHW7zJJbC845NZtf","content":[{"type":"tool_reference","tool_name":"mcp__eloxiv__workshop_write"}]}]},"parent_tool_use_id":null,"session_id":"3eab94b4-833e-497e-9a7e-7264b25a49aa","uuid":"58e2a8e3-9b46-41d9-bcf0-11881f2aa17f","timestamp":"2026-11-04T08:13:24.664Z","tool_use_result":{"matches":["mcp__eloxiv__workshop_write"],"query":"select:mcp__eloxiv__workshop_write","total_deferred_tools":35},"tool_result_meta":[{"id":"toolu_01SMGbVZbHW7zJJbC845NZtf","permission_decision":{"decision":"accept","source":"config"}}]}
4
+ {"type":"assistant","message":{"model":"claude-opus-5-5","id":"msg_011CghZ1ZiEUpjoYJGXmwqUn","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01C6abr5F2qQaYWcZoQxc5fj","name":"mcp__eloxiv__workshop_write","input":{"body":"real-claude-code-37c08aa4"},"caller":{"type":"direct"}}],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":4,"cache_creation_input_tokens":233,"cache_read_input_tokens":22360,"cache_creation":{"ephemeral_5m_input_tokens":233,"ephemeral_1h_input_tokens":0},"output_tokens":32,"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null,"context_management":null},"parent_tool_use_id":null,"session_id":"3eab94b4-833e-497e-9a7e-7264b25a49aa","uuid":"914b16d0-5d84-4297-a3a2-266bb756dcec","timestamp":"2026-11-04T08:13:27.741Z","wire_tool_inputs":{"toolu_01C6abr5F2qQaYWcZoQxc5fj":{"body":"real-claude-code-37c08aa4"}},"tool_use_meta":[{"id":"toolu_01C6abr5F2qQaYWcZoQxc5fj","display_name":"Workshop Write","server_display_name":"eloxiv","tool_name":"workshop_write"}]}
5
+ {"type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_01C6abr5F2qQaYWcZoQxc5fj","type":"tool_result","content":"{\"kind\":\"output\",\"output\":{\"id\":\"ff3065d9-3a41-4eb3-a58e-31ac9c627392\"}}"}]},"parent_tool_use_id":null,"session_id":"3eab94b4-833e-497e-9a7e-7264b25a49aa","uuid":"6f8223f9-048d-4c61-804d-5efe5b4ca58b","timestamp":"2026-11-04T08:13:27.766Z","tool_use_result":{"content":"{\"kind\":\"output\",\"output\":{\"id\":\"ff3065d9-3a41-4eb3-a58e-31ac9c627392\"}}","structuredContent":{"kind":"output","output":{"id":"ff3065d9-3a41-4eb3-a58e-31ac9c627392"}}},"tool_result_meta":[{"id":"toolu_01C6abr5F2qQaYWcZoQxc5fj","permission_decision":{"decision":"accept","source":"config","reason_type":"rule"}}]}
6
+ {"type":"assistant","message":{"model":"claude-opus-5-5","id":"msg_011CghZ1odP3EqaFVCHfZdFg","type":"message","role":"assistant","content":[{"type":"text","text":"done"}],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":2,"cache_creation_input_tokens":123,"cache_read_input_tokens":22593,"cache_creation":{"ephemeral_5m_input_tokens":123,"ephemeral_1h_input_tokens":0},"output_tokens":3,"service_tier":"standard","inference_geo":"global","speed":"standard"},"diagnostics":null,"context_management":null},"parent_tool_use_id":null,"session_id":"3eab94b4-833e-497e-9a7e-7264b25a49aa","uuid":"9f0e2b30-abbd-4c86-a967-eb8fd1141aa8","timestamp":"2026-11-04T08:13:29.769Z"}
7
+ {"duration_api_ms":7972,"stop_reason":"end_turn","session_id":"3eab94b4-833e-497e-9a7e-7264b25a49aa","total_cost_usd":0.1258626,"usage":{"input_tokens":8,"cache_creation_input_tokens":22716,"cache_read_input_tokens":44953,"output_tokens":163,"output_tokens_details":{"thinking_tokens":0},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":22716},"inference_geo":"global","iterations":[{"input_tokens":2,"output_tokens":3,"cache_read_input_tokens":22593,"cache_creation_input_tokens":123,"cache_creation":{"ephemeral_5m_input_tokens":123,"ephemeral_1h_input_tokens":0},"type":"message"}],"speed":"standard","fallback_credit":null},"modelUsage":{"claude-a/claude-opus-5-5":{"inputTokens":8,"outputTokens":163,"cacheReadInputTokens":44953,"cacheCreationInputTokens":22716,"webSearchRequests":0,"costUSD":0.1258626,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":0,"cacheCreationEphemeral5mInputTokens":22716,"cacheCreationEphemeral1hInputTokens":0,"canonicalModel":"claude-opus-5-5","provider":"firstParty","costBasis":"list"}},"permission_denials":[],"terminal_reason":"completed","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","subagent_stats":{"spawned":0,"requested":{"background":0,"foreground":0,"unset":0},"started_in_background":0,"max_depth":0,"spawned_by_subagents":0,"completed":0,"failed":0,"killed":{"parent":0,"user":0,"system":0},"refused":{"depth_limit":0,"concurrency_limit":0,"budget":0},"by_type":{}},"safety_stops":0,"is_error":false,"num_turns":3,"subtype":"success","api_error_status":null,"result":"done","ttft_ms":3135,"type":"result","duration_ms":8252,"uuid":"e47f0ba2-a13f-4716-a0b7-d98a7fb5dcee","ttft_stream_ms":2642,"time_to_request_ms":259,"first_content_frame_ms":2642,"queued_turn_count":0,"result_index":0,"model_usage_since_last_result":{"claude-a/claude-opus-5-5":{"inputTokens":8,"outputTokens":163,"cacheReadInputTokens":44953,"cacheCreationInputTokens":22716,"webSearchRequests":0,"costUSD":0.1258626,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":0,"cacheCreationEphemeral5mInputTokens":22716,"cacheCreationEphemeral1hInputTokens":0,"canonicalModel":"claude-opus-5-5","provider":"firstParty","costBasis":"list"}}}
@@ -0,0 +1,6 @@
1
+ {"type":"thread.started","thread_id":"01a1a59e-f98c-71d2-b6d7-d77ac638d82a"}
2
+ {"type":"turn.started"}
3
+ {"type":"item.started","item":{"id":"item_0","type":"mcp_tool_call","server":"eloxiv","tool":"workshop_write","arguments":{"body":"real-codex-f401e7cd"},"result":null,"error":null,"status":"in_progress"}}
4
+ {"type":"item.completed","item":{"id":"item_0","type":"mcp_tool_call","server":"eloxiv","tool":"workshop_write","arguments":{"body":"real-codex-f401e7cd"},"result":{"content":[{"type":"text","text":"{\"kind\":\"output\",\"output\":{\"id\":\"7df48b22-19c5-4cd3-8e9b-1c7510bde963\"}}"}],"structured_content":{"kind":"output","output":{"id":"7df48b22-19c5-4cd3-8e9b-1c7510bde963"}}},"error":null,"status":"completed"}}
5
+ {"type":"item.completed","item":{"id":"item_1","type":"agent_message","text":"done"}}
6
+ {"type":"turn.completed","usage":{"input_tokens":37827,"cached_input_tokens":24576,"cache_write_input_tokens":0,"output_tokens":65,"reasoning_output_tokens":0}}
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@eloxiv/daemon",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "The Eloxiv device daemon, shipped as a Bun-compiled sidecar binary",
5
+ "homepage": "https://github.com/eloxiv/eloxiv/tree/main/packages/daemon#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/eloxiv/eloxiv/issues"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/eloxiv/eloxiv.git",
13
+ "directory": "packages/daemon"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "scripts",
19
+ "fixtures"
20
+ ],
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./runtime/bun": {
28
+ "types": "./dist/runtime/bun.d.ts",
29
+ "default": "./dist/runtime/bun.js"
30
+ },
31
+ "./runtime/node": {
32
+ "types": "./dist/runtime/node.d.ts",
33
+ "default": "./dist/runtime/node.js"
34
+ },
35
+ "./testing": {
36
+ "types": "./dist/testing.d.ts",
37
+ "default": "./dist/testing.js"
38
+ },
39
+ "./bin": {
40
+ "types": "./dist/bin.d.ts",
41
+ "default": "./dist/bin.js"
42
+ },
43
+ "./bin-node": {
44
+ "types": "./dist/bin-node.d.ts",
45
+ "default": "./dist/bin-node.js"
46
+ },
47
+ "./build-sidecar": "./scripts/build-sidecar.ts"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "dependencies": {
53
+ "@effect/platform-bun": "4.1.2",
54
+ "@effect/platform-node": "4.1.2",
55
+ "effect": "4.1.2",
56
+ "@eloxiv/client": "^0.1.0",
57
+ "@eloxiv/contracts": "^0.1.0"
58
+ },
59
+ "scripts": {
60
+ "build": "tsc -p tsconfig.build.json",
61
+ "build:sidecar": "bun scripts/build-sidecar.ts",
62
+ "dev": "bun --conditions=@eloxiv/source src/bin.ts",
63
+ "typecheck": "tsc -p tsconfig.json --noEmit",
64
+ "test": "vitest run",
65
+ "test:bun": "bun --bun vitest run"
66
+ }
6
67
  }