@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.
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/Acp.d.ts +8 -0
- package/dist/Acp.d.ts.map +1 -0
- package/dist/Acp.js +268 -0
- package/dist/Acp.js.map +1 -0
- package/dist/Canonical.d.ts +3 -0
- package/dist/Canonical.d.ts.map +1 -0
- package/dist/Canonical.js +12 -0
- package/dist/Canonical.js.map +1 -0
- package/dist/Client.d.ts +100 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +474 -0
- package/dist/Client.js.map +1 -0
- package/dist/Commands.d.ts +85 -0
- package/dist/Commands.d.ts.map +1 -0
- package/dist/Commands.js +370 -0
- package/dist/Commands.js.map +1 -0
- package/dist/Config.d.ts +74 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +126 -0
- package/dist/Config.js.map +1 -0
- package/dist/Daemon.d.ts +243 -0
- package/dist/Daemon.d.ts.map +1 -0
- package/dist/Daemon.js +965 -0
- package/dist/Daemon.js.map +1 -0
- package/dist/Harness.d.ts +133 -0
- package/dist/Harness.d.ts.map +1 -0
- package/dist/Harness.js +734 -0
- package/dist/Harness.js.map +1 -0
- package/dist/Http.d.ts +15 -0
- package/dist/Http.d.ts.map +1 -0
- package/dist/Http.js +548 -0
- package/dist/Http.js.map +1 -0
- package/dist/KernelLink.d.ts +145 -0
- package/dist/KernelLink.d.ts.map +1 -0
- package/dist/KernelLink.js +109 -0
- package/dist/KernelLink.js.map +1 -0
- package/dist/LocalAuth.d.ts +99 -0
- package/dist/LocalAuth.d.ts.map +1 -0
- package/dist/LocalAuth.js +225 -0
- package/dist/LocalAuth.js.map +1 -0
- package/dist/Main.d.ts +51 -0
- package/dist/Main.d.ts.map +1 -0
- package/dist/Main.js +219 -0
- package/dist/Main.js.map +1 -0
- package/dist/Secrets.d.ts +21 -0
- package/dist/Secrets.d.ts.map +1 -0
- package/dist/Secrets.js +204 -0
- package/dist/Secrets.js.map +1 -0
- package/dist/SecureUrl.d.ts +11 -0
- package/dist/SecureUrl.d.ts.map +1 -0
- package/dist/SecureUrl.js +23 -0
- package/dist/SecureUrl.js.map +1 -0
- package/dist/State.d.ts +77 -0
- package/dist/State.d.ts.map +1 -0
- package/dist/State.js +38 -0
- package/dist/State.js.map +1 -0
- package/dist/Terminals.d.ts +49 -0
- package/dist/Terminals.d.ts.map +1 -0
- package/dist/Terminals.js +203 -0
- package/dist/Terminals.js.map +1 -0
- package/dist/bin-node.d.ts +2 -0
- package/dist/bin-node.d.ts.map +1 -0
- package/dist/bin-node.js +4 -0
- package/dist/bin-node.js.map +1 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/bun.d.ts +11 -0
- package/dist/runtime/bun.d.ts.map +1 -0
- package/dist/runtime/bun.js +20 -0
- package/dist/runtime/bun.js.map +1 -0
- package/dist/runtime/node.d.ts +11 -0
- package/dist/runtime/node.d.ts.map +1 -0
- package/dist/runtime/node.js +21 -0
- package/dist/runtime/node.js.map +1 -0
- package/dist/testing.d.ts +25 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/fixtures/claude-code-env-vars.txt +409 -0
- package/fixtures/fake-acp-agent.mjs +222 -0
- package/fixtures/fake-harness.mjs +299 -0
- package/fixtures/recorded/claude-code.jsonl +7 -0
- package/fixtures/recorded/codex.jsonl +6 -0
- package/package.json +64 -3
- package/scripts/build-sidecar.ts +86 -0
- package/src/Acp.ts +292 -0
- package/src/Canonical.ts +9 -0
- package/src/Client.ts +585 -0
- package/src/Commands.ts +427 -0
- package/src/Config.ts +179 -0
- package/src/Daemon.ts +1092 -0
- package/src/Harness.ts +839 -0
- package/src/Http.ts +563 -0
- package/src/KernelLink.ts +197 -0
- package/src/LocalAuth.ts +301 -0
- package/src/Main.ts +281 -0
- package/src/Secrets.ts +226 -0
- package/src/SecureUrl.ts +21 -0
- package/src/State.ts +109 -0
- package/src/Terminals.ts +227 -0
- package/src/bin-node.ts +4 -0
- package/src/bin.ts +4 -0
- package/src/index.ts +16 -0
- package/src/runtime/bun.ts +29 -0
- package/src/runtime/node.ts +30 -0
- package/src/testing.ts +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eloxiv contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @eloxiv/daemon
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The local device daemon for Eloxiv desktop and headless clients. It handles device pairing, session storage, the local synced replica, local agent runtimes, and the LocalClient protocol that native hosts use to reach the client runtime. Desktop hosts ship it as a standalone sidecar binary built with Bun (`@eloxiv/daemon/build-sidecar`); `@eloxiv/daemon/testing` provides fake harnesses for tests.
|
|
4
|
+
|
|
5
|
+
Eloxiv is a framework for agent-native applications: a headless kernel, a registry of app-owned modules, and the tools to assemble apps from them. Start with [Getting started](https://github.com/eloxiv/eloxiv/blob/main/docs/getting-started.md).
|
|
6
|
+
|
|
7
|
+
MIT licensed.
|
package/dist/Acp.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type HarnessConfig, type HarnessResult, type HarnessRunInput } from "./Harness.ts";
|
|
2
|
+
/** Whether an ACP tool call is one of the Eloxiv tools (OpenCode names them `eloxiv_<tool>`). */
|
|
3
|
+
export declare const isEloxivTool: (title: string | null) => boolean;
|
|
4
|
+
/** OpenCode's permissions for a turn: only the Eloxiv tools, unless the turn has workspace tools. */
|
|
5
|
+
export declare const opencodePermissions: (workspaceTools: boolean) => string;
|
|
6
|
+
/** Run one turn with an ACP agent. Never throws: failures are the result's `outcome` and `error`. */
|
|
7
|
+
export declare const runAcpHarness: (config: HarnessConfig, input: HarnessRunInput) => Promise<HarnessResult>;
|
|
8
|
+
//# sourceMappingURL=Acp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Acp.d.ts","sourceRoot":"","sources":["../src/Acp.ts"],"names":[],"mappings":"AAkBA,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAA;AASrB,iGAAiG;AACjG,eAAO,MAAM,YAAY,UAAW,MAAM,GAAG,IAAI,YAC4B,CAAA;AAY7E,qGAAqG;AACrG,eAAO,MAAM,mBAAmB,mBAAoB,OAAO,WAGvD,CAAA;AAEJ,qGAAqG;AACrG,eAAO,MAAM,aAAa,WAAY,aAAa,SAAS,eAAe,KAAG,OAAO,CAAC,aAAa,CA4O/F,CAAA"}
|
package/dist/Acp.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { MCP_SERVER, NOT_FORWARDED, harnessEnv, } from "./Harness.js";
|
|
3
|
+
const GRACE_MS = 3_000;
|
|
4
|
+
const clip = (text, limit = 4000) => (text.length > limit ? `${text.slice(0, limit)}…` : text);
|
|
5
|
+
const object = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
6
|
+
const str = (value) => (typeof value === "string" ? value : null);
|
|
7
|
+
/** Whether an ACP tool call is one of the Eloxiv tools (OpenCode names them `eloxiv_<tool>`). */
|
|
8
|
+
export const isEloxivTool = (title) => title !== null && new RegExp(`^(mcp__)?${MCP_SERVER}[_.]`, "u").test(title);
|
|
9
|
+
/** The text of an ACP content block or a tool call's content list. */
|
|
10
|
+
const contentText = (content) => {
|
|
11
|
+
if (Array.isArray(content))
|
|
12
|
+
return content.map(contentText).join("");
|
|
13
|
+
const record = object(content);
|
|
14
|
+
if (record === undefined)
|
|
15
|
+
return typeof content === "string" ? content : "";
|
|
16
|
+
if (record["type"] === "text" && typeof record["text"] === "string")
|
|
17
|
+
return record["text"];
|
|
18
|
+
if (record["type"] === "content")
|
|
19
|
+
return contentText(record["content"]);
|
|
20
|
+
return "";
|
|
21
|
+
};
|
|
22
|
+
/** OpenCode's permissions for a turn: only the Eloxiv tools, unless the turn has workspace tools. */
|
|
23
|
+
export const opencodePermissions = (workspaceTools) => JSON.stringify({
|
|
24
|
+
permission: workspaceTools ? { "*": "allow" } : { "*": "deny", [`${MCP_SERVER}_*`]: "allow" },
|
|
25
|
+
});
|
|
26
|
+
/** Run one turn with an ACP agent. Never throws: failures are the result's `outcome` and `error`. */
|
|
27
|
+
export const runAcpHarness = (config, input) => new Promise((resolve) => {
|
|
28
|
+
const events = [];
|
|
29
|
+
const emit = (event) => {
|
|
30
|
+
events.push(event);
|
|
31
|
+
input.onEvent?.(event);
|
|
32
|
+
};
|
|
33
|
+
const workspaceTools = input.workspaceTools === true;
|
|
34
|
+
const refuseEarly = (error) => resolve({ outcome: "failed", result: null, usage: null, error, events, sessionId: null });
|
|
35
|
+
if (!workspaceTools && config.toolsOnly !== true) {
|
|
36
|
+
refuseEarly(`${config.kind} cannot be limited to the Eloxiv tools (it may run code its working directory configures, or its own tools, without asking): send the turn with workspace tools${config.kind === "acp" ? ", or declare the configured agent tools-only (ELOXIV_DAEMON_ACP_TOOLS_ONLY=1)" : ""}`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const env = {
|
|
40
|
+
...(config.kind === "opencode" ? { OPENCODE_CONFIG_CONTENT: opencodePermissions(workspaceTools) } : {}),
|
|
41
|
+
...config.env,
|
|
42
|
+
};
|
|
43
|
+
const [command, ...prefix] = config.command;
|
|
44
|
+
const child = spawn(command, [...prefix, ...(config.extraArgs ?? [])], {
|
|
45
|
+
cwd: input.cwd,
|
|
46
|
+
env: harnessEnv(env, config.passEnv),
|
|
47
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
48
|
+
detached: process.platform !== "win32",
|
|
49
|
+
});
|
|
50
|
+
const signalGroup = (name) => {
|
|
51
|
+
try {
|
|
52
|
+
if (process.platform !== "win32" && child.pid !== undefined)
|
|
53
|
+
process.kill(-child.pid, name);
|
|
54
|
+
else
|
|
55
|
+
child.kill(name);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Already gone.
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
let nextId = 0;
|
|
62
|
+
const pending = new Map();
|
|
63
|
+
const send = (message) => {
|
|
64
|
+
try {
|
|
65
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}\n`);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// The agent is gone; its exit settles the turn.
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const request = (method, params) => new Promise((ok, fail) => {
|
|
72
|
+
const id = ++nextId;
|
|
73
|
+
pending.set(id, { resolve: ok, reject: fail });
|
|
74
|
+
send({ id, method, params });
|
|
75
|
+
});
|
|
76
|
+
let sessionId = input.resume ?? null;
|
|
77
|
+
let loading = input.resume !== null && input.resume !== undefined;
|
|
78
|
+
let text = "";
|
|
79
|
+
const texts = [];
|
|
80
|
+
const tools = new Map();
|
|
81
|
+
const flushText = () => {
|
|
82
|
+
if (text.length === 0)
|
|
83
|
+
return;
|
|
84
|
+
texts.push(text);
|
|
85
|
+
emit({ type: "text", data: { text } });
|
|
86
|
+
text = "";
|
|
87
|
+
};
|
|
88
|
+
let stderr = "";
|
|
89
|
+
let ended;
|
|
90
|
+
let finished = false;
|
|
91
|
+
const finish = (outcome, error) => {
|
|
92
|
+
if (finished)
|
|
93
|
+
return;
|
|
94
|
+
finished = true;
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
input.signal?.removeEventListener("abort", onAbort);
|
|
97
|
+
flushText();
|
|
98
|
+
signalGroup("SIGKILL");
|
|
99
|
+
for (const waiting of pending.values())
|
|
100
|
+
waiting.reject(new Error("The agent exited"));
|
|
101
|
+
const final = ended ?? outcome;
|
|
102
|
+
emit({ type: "finished", data: { succeeded: final === "succeeded" } });
|
|
103
|
+
resolve({
|
|
104
|
+
outcome: final,
|
|
105
|
+
result: texts.length > 0 ? texts.join("\n") : null,
|
|
106
|
+
usage: null,
|
|
107
|
+
error: final === "succeeded"
|
|
108
|
+
? null
|
|
109
|
+
: final === "cancelled"
|
|
110
|
+
? "The turn was cancelled"
|
|
111
|
+
: final === "timed-out"
|
|
112
|
+
? `The turn exceeded its time limit (${input.timeoutMs} ms)`
|
|
113
|
+
: (error ?? (stderr.trim().slice(-2_000) || "The agent exited without a result")),
|
|
114
|
+
events,
|
|
115
|
+
sessionId,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const stop = (reason) => {
|
|
119
|
+
if (ended !== undefined || finished)
|
|
120
|
+
return;
|
|
121
|
+
ended = reason;
|
|
122
|
+
if (sessionId !== null)
|
|
123
|
+
send({ method: "session/cancel", params: { sessionId } });
|
|
124
|
+
setTimeout(() => signalGroup("SIGTERM"), GRACE_MS / 2).unref();
|
|
125
|
+
setTimeout(() => finish(reason, null), GRACE_MS).unref();
|
|
126
|
+
};
|
|
127
|
+
const timer = setTimeout(() => stop("timed-out"), input.timeoutMs);
|
|
128
|
+
const onAbort = () => stop("cancelled");
|
|
129
|
+
if (input.signal?.aborted)
|
|
130
|
+
onAbort();
|
|
131
|
+
input.signal?.addEventListener("abort", onAbort, { once: true });
|
|
132
|
+
/** What the agent sends: answers to our requests, its notifications, and its own requests (permissions). */
|
|
133
|
+
const onMessage = (message) => {
|
|
134
|
+
const id = message["id"];
|
|
135
|
+
if (typeof id === "number" && message["method"] === undefined) {
|
|
136
|
+
const waiting = pending.get(id);
|
|
137
|
+
pending.delete(id);
|
|
138
|
+
const error = object(message["error"]);
|
|
139
|
+
if (error !== undefined)
|
|
140
|
+
waiting?.reject(new Error(str(error["message"]) ?? "ACP error"));
|
|
141
|
+
else
|
|
142
|
+
waiting?.resolve(message["result"]);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const params = object(message["params"]) ?? {};
|
|
146
|
+
if (message["method"] === "session/update") {
|
|
147
|
+
// A loaded session's history is replayed first: not this turn's.
|
|
148
|
+
if (loading)
|
|
149
|
+
return;
|
|
150
|
+
const update = object(params["update"]) ?? {};
|
|
151
|
+
switch (update["sessionUpdate"]) {
|
|
152
|
+
case "agent_message_chunk":
|
|
153
|
+
text += contentText(update["content"]);
|
|
154
|
+
return;
|
|
155
|
+
case "tool_call": {
|
|
156
|
+
flushText();
|
|
157
|
+
const callId = str(update["toolCallId"]);
|
|
158
|
+
const title = str(update["title"]);
|
|
159
|
+
if (callId !== null)
|
|
160
|
+
tools.set(callId, title);
|
|
161
|
+
emit({ type: "tool-call", data: { id: callId, name: title, input: update["rawInput"] ?? null } });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
case "tool_call_update": {
|
|
165
|
+
const status = update["status"];
|
|
166
|
+
if (status !== "completed" && status !== "failed")
|
|
167
|
+
return;
|
|
168
|
+
const callId = str(update["toolCallId"]);
|
|
169
|
+
const eloxiv = isEloxivTool(tools.get(callId ?? "") ?? str(update["title"]));
|
|
170
|
+
emit({
|
|
171
|
+
type: "tool-result",
|
|
172
|
+
data: {
|
|
173
|
+
id: callId,
|
|
174
|
+
isError: status === "failed",
|
|
175
|
+
// A built-in tool's output stays on the machine.
|
|
176
|
+
output: eloxiv
|
|
177
|
+
? clip(contentText(update["content"]) || JSON.stringify(update["rawOutput"] ?? ""))
|
|
178
|
+
: NOT_FORWARDED,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
default:
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (message["method"] === "session/request_permission" && id !== undefined) {
|
|
188
|
+
const call = object(params["toolCall"]) ?? {};
|
|
189
|
+
const title = str(call["title"]) ?? tools.get(str(call["toolCallId"]) ?? "") ?? null;
|
|
190
|
+
const options = Array.isArray(params["options"]) ? params["options"].map(object) : [];
|
|
191
|
+
const allow = workspaceTools || isEloxivTool(title);
|
|
192
|
+
const chosen = options.find((option) => option?.["kind"] === (allow ? "allow_once" : "reject_once"));
|
|
193
|
+
send({
|
|
194
|
+
id,
|
|
195
|
+
result: {
|
|
196
|
+
outcome: chosen === undefined ? { outcome: "cancelled" } : { outcome: "selected", optionId: chosen["optionId"] },
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// The client offers no file system or terminal: anything else it is asked is refused.
|
|
202
|
+
if (id !== undefined && message["method"] !== undefined) {
|
|
203
|
+
send({
|
|
204
|
+
id,
|
|
205
|
+
error: { code: -32601, message: `${JSON.stringify(message["method"])} is not offered by this client` },
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
let buffer = "";
|
|
210
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
211
|
+
buffer += chunk;
|
|
212
|
+
let newline = buffer.indexOf("\n");
|
|
213
|
+
while (newline >= 0) {
|
|
214
|
+
const line = buffer.slice(0, newline).trim();
|
|
215
|
+
buffer = buffer.slice(newline + 1);
|
|
216
|
+
if (line.length > 0) {
|
|
217
|
+
input.onRawLine?.(line);
|
|
218
|
+
try {
|
|
219
|
+
const parsed = object(JSON.parse(line));
|
|
220
|
+
if (parsed !== undefined)
|
|
221
|
+
onMessage(parsed);
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
// Not a protocol message.
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
newline = buffer.indexOf("\n");
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
child.stderr.setEncoding("utf8").on("data", (chunk) => {
|
|
231
|
+
stderr = (stderr + chunk).slice(-8_000);
|
|
232
|
+
});
|
|
233
|
+
child.on("error", (error) => finish("failed", `Could not start ${config.command.join(" ")}: ${error.message}`));
|
|
234
|
+
child.on("close", (code) => finish("failed", `${config.kind} exited with ${code ?? "a signal"}`));
|
|
235
|
+
const mcpServers = [
|
|
236
|
+
{
|
|
237
|
+
type: "http",
|
|
238
|
+
name: MCP_SERVER,
|
|
239
|
+
url: input.mcp.url,
|
|
240
|
+
headers: [{ name: "authorization", value: `Bearer ${input.mcp.token}` }],
|
|
241
|
+
},
|
|
242
|
+
];
|
|
243
|
+
void (async () => {
|
|
244
|
+
try {
|
|
245
|
+
await request("initialize", {
|
|
246
|
+
protocolVersion: 1,
|
|
247
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
|
|
248
|
+
clientInfo: { name: "eloxiv-daemon", version: "0.0.0" },
|
|
249
|
+
});
|
|
250
|
+
if (sessionId !== null) {
|
|
251
|
+
await request("session/load", { sessionId, cwd: input.cwd, mcpServers });
|
|
252
|
+
loading = false;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const created = object(await request("session/new", { cwd: input.cwd, mcpServers }));
|
|
256
|
+
sessionId = str(created?.["sessionId"]);
|
|
257
|
+
}
|
|
258
|
+
emit({ type: "started", data: { harness: config.kind, sessionId } });
|
|
259
|
+
const answer = object(await request("session/prompt", { sessionId, prompt: [{ type: "text", text: input.prompt }] }));
|
|
260
|
+
const stopReason = str(answer?.["stopReason"]);
|
|
261
|
+
finish(stopReason === "end_turn" ? "succeeded" : stopReason === "cancelled" ? "cancelled" : "failed", `The agent stopped (${stopReason ?? "no reason"})`);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
finish("failed", error.message);
|
|
265
|
+
}
|
|
266
|
+
})();
|
|
267
|
+
});
|
|
268
|
+
//# sourceMappingURL=Acp.js.map
|
package/dist/Acp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Acp.js","sourceRoot":"","sources":["../src/Acp.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,GAIX,MAAM,cAAc,CAAA;AAErB,MAAM,QAAQ,GAAG,KAAK,CAAA;AACtB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,KAAK,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAEtG,MAAM,MAAM,GAAG,CAAC,KAAc,EAAuC,EAAE,CACrE,OAAO,KAAK,KAAK,QA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AAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,EAC7F,sBAAsB,UAAU,IAAI,WAAW,GAAG,CACnD,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,QAAQ,EAAG,KAAe,CAAC,OAAO,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC,CAAC,EAAE,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canonical.d.ts","sourceRoot":"","sources":["../src/Canonical.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,MAO7C,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Canonical JSON (sorted keys, no undefined), for hashing tool inputs into idempotency keys. */
|
|
2
|
+
export const canonicalize = (value) => {
|
|
3
|
+
if (value === null || typeof value !== "object")
|
|
4
|
+
return JSON.stringify(value) ?? "null";
|
|
5
|
+
if (Array.isArray(value))
|
|
6
|
+
return `[${value.map(canonicalize).join(",")}]`;
|
|
7
|
+
const entries = Object.entries(value)
|
|
8
|
+
.filter(([, v]) => v !== undefined)
|
|
9
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
10
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalize(v)}`).join(",")}}`;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=Canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canonical.js","sourceRoot":"","sources":["../src/Canonical.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAU,EAAE;IACrD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAA;IACvF,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAA;IACzE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC;SAC7D,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC;SAClC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAA;AAC5F,CAAC,CAAA"}
|
package/dist/Client.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalClient v1 (decision 14; docs/contracts/local-client.md): the client core (`ClientRuntime`, from
|
|
3
|
+
* `@eloxiv/client/runtime`) served to native clients under `/client/v1` on the loopback relay, for an app that
|
|
4
|
+
* composed its sidecar with a `clientApp` (its sync schema, named queries, mutators and module contracts).
|
|
5
|
+
*
|
|
6
|
+
* The daemon holds a **person session** of its own, obtained by desktop sign-in with its own loopback callback
|
|
7
|
+
* (`/client/v1/sign-in/callback`) and kept in the secret store under its own key (`personSessionKey`), never in
|
|
8
|
+
* `state.json`; it is a second identity beside the device credential, which it never touches. Only the host and
|
|
9
|
+
* paired `desktop-app` clients may use it; no answer or event carries a kernel credential.
|
|
10
|
+
*/
|
|
11
|
+
import { type AnyModuleContract } from "@eloxiv/contracts";
|
|
12
|
+
import { type ClientRuntime } from "@eloxiv/client/runtime";
|
|
13
|
+
import { type SyncSqliteDatabase } from "@eloxiv/client/storage";
|
|
14
|
+
import { type AuthenticatedClient } from "./LocalAuth.ts";
|
|
15
|
+
import type { SecretStore } from "./Secrets.ts";
|
|
16
|
+
/** What an app composes into its sidecar so the daemon can serve LocalClient for it. */
|
|
17
|
+
export interface ClientApp {
|
|
18
|
+
/** The app's module contracts (`contracts` from `eloxiv.modules.ts`): its typed actions. */
|
|
19
|
+
readonly modules: ReadonlyArray<AnyModuleContract>;
|
|
20
|
+
/** The app's sync schema, named queries and mutators (`eloxiv.sync.ts`). */
|
|
21
|
+
readonly schema: unknown;
|
|
22
|
+
readonly queries: object;
|
|
23
|
+
readonly mutators?: object | undefined;
|
|
24
|
+
/** The kernel and zero-cache (default `ELOXIV_KERNEL_URL` and `ELOXIV_ZERO_URL`, read at start). */
|
|
25
|
+
readonly kernelUrl?: string | undefined;
|
|
26
|
+
readonly zeroUrl?: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The app's web page that approves a desktop sign-in (it calls `approveDesktopSignIn` with the `challenge`,
|
|
29
|
+
* `redirect_uri` and `state` it is opened with). Default `ELOXIV_SIGN_IN_PAGE`, else the web shell's
|
|
30
|
+
* `/desktop/sign-in` (the reference shell's approval page) at `shellUrl`.
|
|
31
|
+
*/
|
|
32
|
+
readonly signInPage?: string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The app's web shell (its origin), whose `/desktop/sign-in` approves a desktop sign-in when `signInPage` is not
|
|
35
|
+
* given. Default `ELOXIV_SHELL_URL`, else `http://localhost:5173` (the shell's development server, which the
|
|
36
|
+
* kernel trusts by default).
|
|
37
|
+
*/
|
|
38
|
+
readonly shellUrl?: string | undefined;
|
|
39
|
+
/** The app build's version, sent with calls and writes. */
|
|
40
|
+
readonly clientVersion?: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
/** The page a desktop sign-in opens: the app's `signInPage`, `ELOXIV_SIGN_IN_PAGE`, else the web shell's own. */
|
|
43
|
+
export declare const signInPageOf: (app: Pick<ClientApp, "signInPage" | "shellUrl">, env: Readonly<Record<string, string | undefined>>) => string;
|
|
44
|
+
/** The secret-store key the person's session is kept under (per state directory, apart from the device credential). */
|
|
45
|
+
export declare const personSessionKey: (stateDir: string) => string;
|
|
46
|
+
/** Where the replica's SQLite files live (one per person and organisation). */
|
|
47
|
+
export declare const replicaDirFor: (stateDir: string) => string;
|
|
48
|
+
/** A failure on `/client/v1`: its status and its LocalClient error. */
|
|
49
|
+
export declare class ClientProblem extends Error {
|
|
50
|
+
readonly status: number;
|
|
51
|
+
readonly body: Record<string, unknown>;
|
|
52
|
+
constructor(status: number, body: {
|
|
53
|
+
readonly _tag: string;
|
|
54
|
+
readonly message: string;
|
|
55
|
+
readonly [key: string]: unknown;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** A thrown value as a LocalClient refusal (`{ _tag, message, ...fields }`) with its status. */
|
|
59
|
+
export declare const problemOf: (error: unknown) => ClientProblem;
|
|
60
|
+
export interface LocalClientServiceOptions {
|
|
61
|
+
readonly app: ClientApp;
|
|
62
|
+
readonly stateDir: string;
|
|
63
|
+
readonly secrets: SecretStore;
|
|
64
|
+
/** Opens the runtime's synchronous SQLite (`bun:sqlite`, `node:sqlite`); memory storage without one. */
|
|
65
|
+
readonly sqlite?: ((path: string) => SyncSqliteDatabase) | undefined;
|
|
66
|
+
/** The daemon's port, once listening (the callback's redirect names it). */
|
|
67
|
+
readonly port: () => number;
|
|
68
|
+
/** Credentials no answer may carry (the device credential), for the scrub. */
|
|
69
|
+
readonly credentials: () => Promise<ReadonlyArray<string | undefined>>;
|
|
70
|
+
readonly env?: Readonly<Record<string, string | undefined>> | undefined;
|
|
71
|
+
readonly log: (line: string) => void;
|
|
72
|
+
}
|
|
73
|
+
/** `/client/v1`, over one `ClientRuntime` for the daemon's person session. */
|
|
74
|
+
export declare class LocalClientService {
|
|
75
|
+
#private;
|
|
76
|
+
readonly runtime: ClientRuntime;
|
|
77
|
+
readonly kernelUrl: string;
|
|
78
|
+
constructor(options: LocalClientServiceOptions);
|
|
79
|
+
/** Check the stored person session (once, when the daemon is listening). */
|
|
80
|
+
start(): Promise<unknown>;
|
|
81
|
+
close(): Promise<void>;
|
|
82
|
+
/** A refusal as LocalClient answers it. */
|
|
83
|
+
refusal(error: unknown): Response;
|
|
84
|
+
/** The browser's redirect: state-checked, accepted once and within the sign-in's time; no local token. */
|
|
85
|
+
callback(request: Request): Promise<Response>;
|
|
86
|
+
/** Every other `/client/v1` route, for an authenticated client: only the host and desktop apps. */
|
|
87
|
+
handle(request: Request, path: string, who: AuthenticatedClient): Promise<Response>;
|
|
88
|
+
}
|
|
89
|
+
/** Whether `path` is one of LocalClient's (under `/client/v1`). */
|
|
90
|
+
export declare const isClientPath: (path: string) => boolean;
|
|
91
|
+
/** The one browser-facing route: no token, no Origin check, checked by its state. */
|
|
92
|
+
export declare const CLIENT_CALLBACK = "/client/v1/sign-in/callback";
|
|
93
|
+
/** A refusal on `/client/v1` before the service answers (no app, the Host or Origin, the token): `{ _tag, message }`. */
|
|
94
|
+
export declare const clientRefusal: (error: unknown) => Response;
|
|
95
|
+
/**
|
|
96
|
+
* Serve one `/client/v1` request: `404 ClientNotConfigured` without a service; the callback without a token;
|
|
97
|
+
* everything else for the client `authenticate` names (it throws for a missing or unknown token).
|
|
98
|
+
*/
|
|
99
|
+
export declare const serveClient: (service: LocalClientService | undefined, request: Request, path: string, authenticate: () => AuthenticatedClient) => Promise<Response>;
|
|
100
|
+
//# sourceMappingURL=Client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAkBL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