@unieai/code 0.0.39 → 0.0.40

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/README.md CHANGED
@@ -32,6 +32,8 @@ also used by UnieAI Studio.
32
32
 
33
33
  ## What's new
34
34
 
35
+ **0.0.40** (2026-11-18) — the uac engine now starts on Windows instead of falling back to codex.
36
+
35
37
  **0.0.39** (2026-10-24) — fixes uac not starting in 0.0.38 (Rabi sign-ins saw a 404),
36
38
  Windows builds reporting version 0.0.22, and the welcome logo vanishing at launch;
37
39
  merges upstream Codex through 2026-10-23 and moves uac to deepseek-harness 0.2.1-rc.3.
@@ -50,6 +50,7 @@ import { acpMcpServers, sessionMcpServers, studioMcpServer } from "../src/unieai
50
50
  import { agentFailureReason } from "../src/unieai-dsh/acp-client.mjs";
51
51
  import { createOneShotEngine, createOneShotModel } from "../src/unieai-dsh/unieai-oneshot.mjs";
52
52
  import { claimServer } from "../src/unieai-dsh/unieai-server-lock.mjs";
53
+ import { IS_WINDOWS, nodeSocketEndpoint } from "../src/app-server/unieai-local-endpoint.mjs";
53
54
 
54
55
  // A thread on a self-hosted model titles itself on that server: no UnieAI
55
56
  // sign-in is needed, and nothing about it reaches the gateway.
@@ -106,8 +107,11 @@ process.once("exit", claimed.release);
106
107
  // pid keeps it this process's: a server of another release can start while
107
108
  // this one still serves its clients (see unieai-launch's drain), and a shared
108
109
  // path would hand this server's dsh control channel to the new one's dsh.
109
- const controlSocketFor = (mode) =>
110
+ // On Windows the path only names it: Node serves no unix sockets there, so
111
+ // both ends use the named pipe derived from it (unieai-local-endpoint.mjs).
112
+ const controlSocketPathFor = (mode) =>
110
113
  appSocket.replace(/(\.sock)?$/, mode === "standard" ? `.${process.pid}.dsh.sock` : `.${process.pid}.${mode}.dsh.sock`);
114
+ const controlSocketFor = (mode) => nodeSocketEndpoint(controlSocketPathFor(mode));
111
115
  removeStaleControlSockets(dirname(appSocket));
112
116
 
113
117
  /** Control sockets of uac servers that are no longer running. */
@@ -272,7 +276,8 @@ await launchAppServer({
272
276
  onHandOver: claimed.release,
273
277
  onShutdown: async () => {
274
278
  await Promise.all([...hosts.values()].map((host) => host.close()));
275
- for (const mode of hosts.keys()) rmSync(controlSocketFor(mode), { force: true });
279
+ // A named pipe goes with its listener; only unix socket files linger.
280
+ if (!IS_WINDOWS) for (const mode of hosts.keys()) rmSync(controlSocketFor(mode), { force: true });
276
281
  },
277
282
  // What this account can actually run: a model it does not offer (a config
278
283
  // written for another account — Studio's ids differ from Rabi's) becomes
@@ -1494,7 +1494,7 @@ export function textOf(input) {
1494
1494
  * — useful in tests, wrong in production, where the platform surface has to
1495
1495
  * reach the Rust app-server.
1496
1496
  */
1497
- export async function startAppServer({ socketPath, createEngineFor, codexHome, version, sandboxMode, threadStore = null, defaultModel = null, threadMode, resolveModel, onTurnError, forward = null, onError = () => {}, onTrace = null, onIdle = null }) {
1497
+ export async function startAppServer({ socketPath, createEngineFor, codexHome, version, sandboxMode, threadStore = null, defaultModel = null, threadMode, resolveModel, onTurnError, forward = null, onError = () => {}, onTrace = null, onIdle = null, loopback = false, authToken = null }) {
1498
1498
  const handlers = createHandlers({ createEngineFor, codexHome, version, sandboxMode, threadStore, defaultModel, threadMode, resolveModel, onTurnError });
1499
1499
  // Ours are unknown to the Rust side: a thread id it would look up is dropped.
1500
1500
  const forwardPlatform = forward
@@ -1530,6 +1530,8 @@ export async function startAppServer({ socketPath, createEngineFor, codexHome, v
1530
1530
 
1531
1531
  const transport = serveJsonOverUnixSocket({
1532
1532
  socketPath,
1533
+ loopback,
1534
+ authToken,
1533
1535
  onError,
1534
1536
  onConnection: (conn) => {
1535
1537
  // Without this there is no way to tell a client that never connected from
@@ -14,6 +14,8 @@ import { createForwarder } from "./forward.mjs";
14
14
  import { createItemBridge } from "./items.mjs";
15
15
  import { createApprovalBridge } from "./approval.mjs";
16
16
  import { loadCredentials, sandboxBin } from "../config.mjs";
17
+ import { randomBytes } from "node:crypto";
18
+ import { USE_LOOPBACK } from "./unieai-local-endpoint.mjs";
17
19
 
18
20
  export const log = (...parts) => process.stderr.write(`${parts.join(" ")}\n`);
19
21
 
@@ -38,6 +40,13 @@ export async function launchAppServer({ name, version, buildEngine, sandboxMode,
38
40
  // A socket file left by a crashed process would make the CLI think a server is
39
41
  // live and then fail to connect, so clear a stale one before binding.
40
42
  if (existsSync(socketPath)) rmSync(socketPath, { force: true });
43
+ // Windows: Node cannot serve a unix socket there, so the server listens on
44
+ // loopback with a token, and the stamp below tells clients where (see
45
+ // unieai-local-endpoint.mjs). A stamp left by a crashed server would point
46
+ // them at a dead port until this one writes its own.
47
+ const loopback = USE_LOOPBACK;
48
+ const authToken = loopback ? randomBytes(32).toString("base64url") : null;
49
+ if (loopback) rmSync(`${socketPath}.json`, { force: true });
41
50
 
42
51
  // The server does not exist yet, and the forwarder needs to reach it: the Rust
43
52
  // child starts pushing notifications as soon as it is initialized. A ref keeps
@@ -54,6 +63,8 @@ export async function launchAppServer({ name, version, buildEngine, sandboxMode,
54
63
 
55
64
  const server = appServer = await startAppServer({
56
65
  socketPath,
66
+ loopback,
67
+ authToken,
57
68
  codexHome,
58
69
  version,
59
70
  sandboxMode,
@@ -129,7 +140,8 @@ export async function launchAppServer({ name, version, buildEngine, sandboxMode,
129
140
 
130
141
  // Only this user may drive the engine: the socket accepts turns that run
131
142
  // commands in the user's workspace.
132
- chmodSync(socketPath, 0o600);
143
+ // (On Windows there is no socket file; the token is what keeps others out.)
144
+ if (!loopback) chmodSync(socketPath, 0o600);
133
145
  // The server outlives the client that started it, so the next client can
134
146
  // find it running an older release than itself. This says which release it
135
147
  // is and how to stop it (see the TUI's ensure_uac_server).
@@ -142,6 +154,10 @@ export async function launchAppServer({ name, version, buildEngine, sandboxMode,
142
154
  accountId: loadCredentials().accountId || null,
143
155
  engineVersion: version,
144
156
  socket: socketPath,
157
+ // Windows only: where the server really listens, and the bearer token
158
+ // every client must present. The stamp is the user's own file (0600 on
159
+ // Unix; on Windows it inherits the profile directory's per-user ACL).
160
+ ...(loopback ? { port: server.port(), token: authToken } : {}),
145
161
  startedAt: new Date().toISOString(),
146
162
  };
147
163
  try {
@@ -149,7 +165,7 @@ export async function launchAppServer({ name, version, buildEngine, sandboxMode,
149
165
  } catch (error) {
150
166
  log(`[app-server] could not write ${stampPath}: ${error.message}`);
151
167
  }
152
- log(`${name} app-server ${version} listening on ${socketPath}`);
168
+ log(`${name} app-server ${version} listening on ${loopback ? `127.0.0.1:${server.port()} (for ${socketPath})` : socketPath}`);
153
169
 
154
170
  const { shutdown, drain } = createStopControls({
155
171
  server,
@@ -0,0 +1,76 @@
1
+ // Copyright (c) 2026 UnieAI. All rights reserved.
2
+ /**
3
+ * unieai-local-endpoint.mjs — where a local server actually listens, per OS.
4
+ *
5
+ * Everything here is named by a socket PATH (`<home>/uac/app-server.sock`),
6
+ * and on Unix that path is the endpoint. Windows has no such thing for Node:
7
+ * `net.listen(path)` there only makes named pipes and rejects any other path
8
+ * with EACCES, while the TUI's Rust client dials AF_UNIX sockets — the two
9
+ * never meet, so every Windows launch fell back to the codex engine.
10
+ *
11
+ * On Windows, then:
12
+ * - the app-server socket becomes a loopback WebSocket (127.0.0.1, a port
13
+ * the OS picks) guarded by a bearer token; port and token go into the
14
+ * stamp beside the path (`<path>.json`), which is where the TUI already
15
+ * looks to learn about the server. The Rust client already speaks
16
+ * `ws://` with a token, so nothing new is needed on that side but reading
17
+ * the stamp.
18
+ * - sockets only Node talks to (dsh's unieai-control channel) become named
19
+ * pipes, derived from the path so both ends compute the same name.
20
+ *
21
+ * The path stays the identity in both cases: locks, stamps and the TUI's
22
+ * "is this the uac server?" check keep using it.
23
+ */
24
+ import { readFileSync } from "node:fs";
25
+
26
+ export const IS_WINDOWS = process.platform === "win32";
27
+ /** Whether the app-server uses the loopback transport: on Windows, or when
28
+ * UNIEAI_UAC_LOOPBACK=1 forces it elsewhere to exercise that path. */
29
+ export const USE_LOOPBACK = IS_WINDOWS || process.env.UNIEAI_UAC_LOOPBACK === "1";
30
+
31
+ /** FNV-1a, 64-bit, as hex: the TUI hashes socket paths the same way. */
32
+ export function fnv1a64(text) {
33
+ let hash = 0xcbf29ce484222325n;
34
+ for (const byte of Buffer.from(String(text), "utf8")) {
35
+ hash ^= BigInt(byte);
36
+ hash = (hash * 0x100000001b3n) & 0xffffffffffffffffn;
37
+ }
38
+ return hash.toString(16).padStart(16, "0");
39
+ }
40
+
41
+ /** The named pipe standing in for `path` on Windows. */
42
+ export function pipeNameFor(path) {
43
+ return `\\\\.\\pipe\\unieai-${fnv1a64(String(path).toLowerCase())}`;
44
+ }
45
+
46
+ /**
47
+ * What to hand `net.listen` / `net.connect` for a socket only Node peers use:
48
+ * the path itself on Unix, its named pipe on Windows.
49
+ */
50
+ export function nodeSocketEndpoint(path, { windows = IS_WINDOWS } = {}) {
51
+ return windows ? pipeNameFor(path) : path;
52
+ }
53
+
54
+ /** Whether `endpoint` is a Windows named pipe (no file to chmod or remove). */
55
+ export const isPipeName = (endpoint) => /^\\\\[.?]\\pipe\\/i.test(String(endpoint));
56
+
57
+ /** The stamp a server left beside its socket path, or null. */
58
+ export function readStamp(socketPath) {
59
+ try {
60
+ return JSON.parse(readFileSync(`${socketPath}.json`, "utf8"));
61
+ } catch {
62
+ return null;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Where to dial the app-server named by `socketPath`: `{ path }` on Unix,
68
+ * `{ host, port }` from the stamp on Windows (null when no server stamped one).
69
+ */
70
+ export function appServerDialTarget(socketPath, { windows = USE_LOOPBACK, stamp = readStamp } = {}) {
71
+ if (!windows) return { path: socketPath };
72
+ const found = stamp(socketPath);
73
+ const port = Number(found?.port);
74
+ if (!Number.isInteger(port) || port <= 0) return null;
75
+ return { host: "127.0.0.1", port, token: found?.token ?? null };
76
+ }
@@ -13,7 +13,7 @@
13
13
  * local processes we ship, so the negotiation surface is one handshake and the
14
14
  * frame types a JSON-RPC stream actually uses.
15
15
  */
16
- import { createHash, randomBytes } from "node:crypto";
16
+ import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
17
17
  import { createServer } from "node:net";
18
18
 
19
19
  const GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
@@ -128,8 +128,13 @@ export function decodeFrames(buffer, carry = { opcode: null, chunks: [] }) {
128
128
  * Every message is one JSON value; malformed text is reported through `onError`
129
129
  * rather than killing the connection, because one bad frame from a client should
130
130
  * not take down a session.
131
+ *
132
+ * `loopback: true` listens on 127.0.0.1 (a port the OS picks) instead of
133
+ * `socketPath` — Windows, where Node cannot serve a unix socket (see
134
+ * unieai-local-endpoint.mjs). A TCP port is reachable by every local user,
135
+ * so `authToken` is then required of every upgrade as `Authorization: Bearer`.
131
136
  */
132
- export function serveJsonOverUnixSocket({ socketPath, onConnection, onError = () => {} }) {
137
+ export function serveJsonOverUnixSocket({ socketPath, onConnection, onError = () => {}, loopback = false, authToken = null }) {
133
138
  const server = createServer((socket) => {
134
139
  let upgraded = false;
135
140
  let buffer = Buffer.alloc(0);
@@ -152,12 +157,16 @@ export function serveJsonOverUnixSocket({ socketPath, onConnection, onError = ()
152
157
  if (!upgraded) {
153
158
  const end = buffer.indexOf("\r\n\r\n");
154
159
  if (end < 0) return; // headers still arriving
155
- const { ok, key } = parseUpgrade(buffer.subarray(0, end).toString("utf8"));
160
+ const { ok, key, headers } = parseUpgrade(buffer.subarray(0, end).toString("utf8"));
156
161
  buffer = buffer.subarray(end + 4);
157
162
  if (!ok) {
158
163
  socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
159
164
  return;
160
165
  }
166
+ if (authToken && !bearerMatches(headers.get("authorization"), authToken)) {
167
+ socket.end("HTTP/1.1 401 Unauthorized\r\n\r\n");
168
+ return;
169
+ }
161
170
  socket.write(
162
171
  "HTTP/1.1 101 Switching Protocols\r\n" +
163
172
  "Upgrade: websocket\r\n" +
@@ -189,12 +198,24 @@ export function serveJsonOverUnixSocket({ socketPath, onConnection, onError = ()
189
198
  return {
190
199
  listen: () => new Promise((resolve, reject) => {
191
200
  server.once("error", reject);
192
- server.listen(socketPath, () => resolve(socketPath));
201
+ if (loopback) server.listen(0, "127.0.0.1", () => resolve(socketPath));
202
+ else server.listen(socketPath, () => resolve(socketPath));
193
203
  }),
204
+ /** The loopback port, once listening with `loopback: true`; else null. */
205
+ port: () => (loopback ? server.address()?.port ?? null : null),
194
206
  close: () => new Promise((resolve) => server.close(() => resolve())),
195
207
  server,
196
208
  };
197
209
  }
198
210
 
211
+ /** Constant-time comparison of an `Authorization: Bearer <token>` header. */
212
+ export function bearerMatches(header, token) {
213
+ const match = /^Bearer\s+(.+)$/i.exec(String(header ?? "").trim());
214
+ if (!match) return false;
215
+ const given = Buffer.from(match[1].trim());
216
+ const expected = Buffer.from(String(token));
217
+ return given.length === expected.length && timingSafeEqual(given, expected);
218
+ }
219
+
199
220
  /** A client key, for tests and for any future outbound connection. */
200
221
  export const newClientKey = () => randomBytes(16).toString("base64");
@@ -875,14 +875,18 @@ export function apply(ctx, config = {}) {
875
875
  socket.on("close", failPending);
876
876
  socket.on("error", () => {});
877
877
  });
878
+ // A Windows named pipe (the uac server passes one there) has no file to
879
+ // chmod or remove. Node cannot set its ACL; the default one lets other
880
+ // local users open it read-only at most, so they cannot send requests.
881
+ const isPipe = /^\\\\[.?]\\pipe\\/i.test(socketPath);
878
882
  server.listen(socketPath, () => {
879
- chmodSync(socketPath, 0o600);
883
+ if (!isPipe) chmodSync(socketPath, 0o600);
880
884
  ctx.logger.info(`unieai-control: listening on ${socketPath}`);
881
885
  });
882
886
  ctx.on("dispose", () => {
883
887
  execLifetime.abort();
884
888
  unsubscribeExec();
885
889
  server.close();
886
- rmSync(socketPath, { force: true });
890
+ if (!isPipe) rmSync(socketPath, { force: true });
887
891
  });
888
892
  }
@@ -26,6 +26,7 @@
26
26
  */
27
27
  import { closeSync, openSync, readFileSync, rmSync, writeSync } from "node:fs";
28
28
  import { connect } from "node:net";
29
+ import { appServerDialTarget } from "../app-server/unieai-local-endpoint.mjs";
29
30
 
30
31
  /** Whether `pid` is a running process (signal 0 only checks). */
31
32
  export function processIsAlive(pid) {
@@ -39,10 +40,15 @@ export function processIsAlive(pid) {
39
40
  }
40
41
  }
41
42
 
42
- /** Whether something accepts connections on the unix socket at `path`. */
43
- export function socketIsLive(path, timeoutMs = 600) {
43
+ /**
44
+ * Whether something accepts connections on the app-server socket at `path`
45
+ * (on Windows: the loopback port its stamp names; see unieai-local-endpoint.mjs).
46
+ */
47
+ export function socketIsLive(path, timeoutMs = 600, { target = appServerDialTarget } = {}) {
48
+ const dial = target(path);
49
+ if (!dial) return Promise.resolve(false);
44
50
  return new Promise((resolve) => {
45
- const socket = connect(path);
51
+ const socket = dial.path ? connect(dial.path) : connect(dial.port, dial.host);
46
52
  const done = (live) => {
47
53
  clearTimeout(timer);
48
54
  socket.destroy();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unieai/code",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "description": "UnieAI Code is a coding agent that runs locally on your computer.",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -331,11 +331,11 @@
331
331
  "@deepseek-ai/schemastery": "3.18.5"
332
332
  },
333
333
  "optionalDependencies": {
334
- "@unieai/code-linux-x64": "npm:@unieai/code@0.0.39-linux-x64",
335
- "@unieai/code-linux-arm64": "npm:@unieai/code@0.0.39-linux-arm64",
336
- "@unieai/code-darwin-x64": "npm:@unieai/code@0.0.39-darwin-x64",
337
- "@unieai/code-darwin-arm64": "npm:@unieai/code@0.0.39-darwin-arm64",
338
- "@unieai/code-win32-x64": "npm:@unieai/code@0.0.39-win32-x64",
339
- "@unieai/code-win32-arm64": "npm:@unieai/code@0.0.39-win32-arm64"
334
+ "@unieai/code-linux-x64": "npm:@unieai/code@0.0.40-linux-x64",
335
+ "@unieai/code-linux-arm64": "npm:@unieai/code@0.0.40-linux-arm64",
336
+ "@unieai/code-darwin-x64": "npm:@unieai/code@0.0.40-darwin-x64",
337
+ "@unieai/code-darwin-arm64": "npm:@unieai/code@0.0.40-darwin-arm64",
338
+ "@unieai/code-win32-x64": "npm:@unieai/code@0.0.40-win32-x64",
339
+ "@unieai/code-win32-arm64": "npm:@unieai/code@0.0.40-win32-arm64"
340
340
  }
341
341
  }