@eloxiv/daemon 0.0.0-stage → 0.1.1

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 (119) 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 +102 -0
  12. package/dist/Client.d.ts.map +1 -0
  13. package/dist/Client.js +482 -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/PersonSession.d.ts +49 -0
  48. package/dist/PersonSession.d.ts.map +1 -0
  49. package/dist/PersonSession.js +173 -0
  50. package/dist/PersonSession.js.map +1 -0
  51. package/dist/Secrets.d.ts +21 -0
  52. package/dist/Secrets.d.ts.map +1 -0
  53. package/dist/Secrets.js +204 -0
  54. package/dist/Secrets.js.map +1 -0
  55. package/dist/SecureUrl.d.ts +11 -0
  56. package/dist/SecureUrl.d.ts.map +1 -0
  57. package/dist/SecureUrl.js +23 -0
  58. package/dist/SecureUrl.js.map +1 -0
  59. package/dist/State.d.ts +77 -0
  60. package/dist/State.d.ts.map +1 -0
  61. package/dist/State.js +38 -0
  62. package/dist/State.js.map +1 -0
  63. package/dist/Terminals.d.ts +49 -0
  64. package/dist/Terminals.d.ts.map +1 -0
  65. package/dist/Terminals.js +203 -0
  66. package/dist/Terminals.js.map +1 -0
  67. package/dist/bin-node.d.ts +2 -0
  68. package/dist/bin-node.d.ts.map +1 -0
  69. package/dist/bin-node.js +4 -0
  70. package/dist/bin-node.js.map +1 -0
  71. package/dist/bin.d.ts +2 -0
  72. package/dist/bin.d.ts.map +1 -0
  73. package/dist/bin.js +4 -0
  74. package/dist/bin.js.map +1 -0
  75. package/dist/index.d.ts +18 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +18 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/runtime/bun.d.ts +11 -0
  80. package/dist/runtime/bun.d.ts.map +1 -0
  81. package/dist/runtime/bun.js +20 -0
  82. package/dist/runtime/bun.js.map +1 -0
  83. package/dist/runtime/node.d.ts +11 -0
  84. package/dist/runtime/node.d.ts.map +1 -0
  85. package/dist/runtime/node.js +21 -0
  86. package/dist/runtime/node.js.map +1 -0
  87. package/dist/testing.d.ts +25 -0
  88. package/dist/testing.d.ts.map +1 -0
  89. package/dist/testing.js +27 -0
  90. package/dist/testing.js.map +1 -0
  91. package/fixtures/claude-code-env-vars.txt +409 -0
  92. package/fixtures/fake-acp-agent.mjs +222 -0
  93. package/fixtures/fake-harness.mjs +299 -0
  94. package/fixtures/recorded/claude-code.jsonl +7 -0
  95. package/fixtures/recorded/codex.jsonl +6 -0
  96. package/package.json +64 -3
  97. package/scripts/build-sidecar.ts +86 -0
  98. package/src/Acp.ts +292 -0
  99. package/src/Canonical.ts +9 -0
  100. package/src/Client.ts +590 -0
  101. package/src/Commands.ts +427 -0
  102. package/src/Config.ts +179 -0
  103. package/src/Daemon.ts +1092 -0
  104. package/src/Harness.ts +839 -0
  105. package/src/Http.ts +563 -0
  106. package/src/KernelLink.ts +197 -0
  107. package/src/LocalAuth.ts +301 -0
  108. package/src/Main.ts +281 -0
  109. package/src/PersonSession.ts +203 -0
  110. package/src/Secrets.ts +226 -0
  111. package/src/SecureUrl.ts +21 -0
  112. package/src/State.ts +109 -0
  113. package/src/Terminals.ts +227 -0
  114. package/src/bin-node.ts +4 -0
  115. package/src/bin.ts +4 -0
  116. package/src/index.ts +17 -0
  117. package/src/runtime/bun.ts +29 -0
  118. package/src/runtime/node.ts +30 -0
  119. package/src/testing.ts +43 -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.1",
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
+ "@eloxiv/client": "^0.1.1",
56
+ "@eloxiv/contracts": "^0.1.1",
57
+ "effect": "4.1.2"
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
  }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Compile the daemon into a single executable with `bun build --compile` and
3
+ * name it the way Tauri expects an `externalBin`: `eloxiv-daemon-<target-triple>`.
4
+ *
5
+ * bun scripts/build-sidecar.ts [--target <rust-triple>] [--out-dir <dir>] [--entry <file>] [--name <name>]
6
+ *
7
+ * `--entry` compiles an app's own sidecar instead of the generic one: a file that calls the daemon's `runMain`
8
+ * with its `clientApp` (decision 14; the desktop-rune item's `sidecar/daemon.ts`), named `<name>-<target-triple>` (default
9
+ * `eloxiv-daemon`). Relative paths are the caller's.
10
+ *
11
+ * The triple defaults to `TAURI_ENV_TARGET_TRIPLE` (set by the Tauri CLI) and
12
+ * then to the host triple from `rustc -vV`. The output directory defaults to
13
+ * this repository's desktop host template's `src-tauri/binaries`; an app passes
14
+ * its own (the desktop item's `scripts/prepare.ts` finds this script through
15
+ * the package export `@eloxiv/daemon/build-sidecar`).
16
+ */
17
+ import { execFileSync } from "node:child_process"
18
+ import { mkdirSync, statSync } from "node:fs"
19
+ import { dirname, join, resolve } from "node:path"
20
+ import { fileURLToPath } from "node:url"
21
+
22
+ const here = dirname(fileURLToPath(import.meta.url))
23
+ const packageRoot = resolve(here, "..")
24
+ const defaultOutDir = resolve(packageRoot, "../../registry/app/desktop/src-tauri/binaries")
25
+
26
+ /** Rust target triple → Bun `--compile` target. */
27
+ const bunTargets: Readonly<Record<string, string>> = {
28
+ "x86_64-unknown-linux-gnu": "bun-linux-x64",
29
+ "aarch64-unknown-linux-gnu": "bun-linux-arm64",
30
+ "x86_64-unknown-linux-musl": "bun-linux-x64-musl",
31
+ "aarch64-unknown-linux-musl": "bun-linux-arm64-musl",
32
+ "x86_64-apple-darwin": "bun-darwin-x64",
33
+ "aarch64-apple-darwin": "bun-darwin-arm64",
34
+ "x86_64-pc-windows-msvc": "bun-windows-x64",
35
+ "aarch64-pc-windows-msvc": "bun-windows-arm64",
36
+ }
37
+
38
+ const flag = (name: string): string | undefined => {
39
+ const args = process.argv.slice(2)
40
+ const index = args.indexOf(name)
41
+ if (index >= 0) return args[index + 1]
42
+ return args.find((arg) => arg.startsWith(`${name}=`))?.slice(name.length + 1)
43
+ }
44
+
45
+ const hostTriple = (): string => {
46
+ const output = execFileSync("rustc", ["-vV"], { encoding: "utf8" })
47
+ const host = /^host:\s*(\S+)$/m.exec(output)?.[1]
48
+ if (host === undefined) throw new Error(`Could not read the host triple from \`rustc -vV\`:\n${output}`)
49
+ return host
50
+ }
51
+
52
+ const triple = flag("--target") ?? process.env["TAURI_ENV_TARGET_TRIPLE"] ?? hostTriple()
53
+ const outDir = resolve(flag("--out-dir") ?? defaultOutDir)
54
+ const extension = triple.includes("windows") ? ".exe" : ""
55
+ const entry = flag("--entry") === undefined ? join(packageRoot, "src/bin.ts") : resolve(flag("--entry")!)
56
+ const name = flag("--name") ?? "eloxiv-daemon"
57
+ if (!/^[a-z0-9][a-z0-9-]*$/u.test(name))
58
+ throw new Error(`--name must be lower-case letters, digits and dashes: ${name}`)
59
+ const outfile = join(outDir, `${name}-${triple}${extension}`)
60
+
61
+ const args = [
62
+ "build",
63
+ "--compile",
64
+ "--minify",
65
+ "--sourcemap",
66
+ "--bytecode",
67
+ "--conditions=@eloxiv/source",
68
+ // A release build: the development origins (the Vite dev server) are not trusted.
69
+ "--define",
70
+ `ELOXIV_DAEMON_BUILD="release"`,
71
+ entry,
72
+ "--outfile",
73
+ outfile,
74
+ ]
75
+ const host = hostTriple()
76
+ if (triple !== host) {
77
+ const target = bunTargets[triple]
78
+ if (target === undefined) throw new Error(`No Bun compile target for ${triple}`)
79
+ args.splice(2, 0, `--target=${target}`)
80
+ }
81
+
82
+ mkdirSync(outDir, { recursive: true })
83
+ console.log(`bun ${args.join(" ")}`)
84
+ execFileSync(process.execPath, args, { stdio: "inherit", cwd: packageRoot })
85
+ const size = statSync(outfile).size
86
+ console.log(`sidecar: ${outfile} (${(size / 1024 / 1024).toFixed(1)} MiB)`)