ruicode 0.74.1 → 0.74.3

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/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from "node:events";
2
- import { type HostSettings } from "./settings.ts";
2
+ import { type HostSettings, type PreparedSettings } from "./settings.ts";
3
3
  import { SessionNotifications } from "./notifications.ts";
4
4
  import { RuiStartError } from "./errors.ts";
5
5
  import { Session, Sessions, type ModelSummary } from "./sessions.ts";
@@ -24,7 +24,7 @@ type HostInfo = components["schemas"]["HostInfoReply"];
24
24
  interface Launch {
25
25
  binary: string;
26
26
  document: Buffer;
27
- interfaceDir: NonNullable<NonNullable<Schemas["HostSettings"]["interface"]>["dir"]>;
27
+ interfaceDir: PreparedSettings["interfaceDir"];
28
28
  aliasReady?: Promise<void>;
29
29
  detached: boolean;
30
30
  socketPath: string;
package/dist/client.js CHANGED
@@ -11,11 +11,11 @@ import { mkdtemp, rm, stat, symlink } from "node:fs/promises";
11
11
  import { tmpdir } from "node:os";
12
12
  import { dirname, join } from "node:path";
13
13
  import { setTimeout as sleep } from "node:timers/promises";
14
- import { pipeSettings } from "./settings.js";
14
+ import { prepareSettings } from "./settings.js";
15
15
  import { SessionNotifications } from "./notifications.js";
16
16
  import { resolveBinary } from "./binary.js";
17
17
  import { RuiStartError, RuiUnavailableError } from "./errors.js";
18
- import { agentSpec, models, Session, Sessions, setPaused } from "./sessions.js";
18
+ import { models, Session, Sessions, setPaused } from "./sessions.js";
19
19
  import { ConnectionError, post, WIRE_VERSION } from "./transport.js";
20
20
  const SOCKET_NAME = "rui.sock";
21
21
  const DEFAULT_LOCK_WAIT_MS = 120_000;
@@ -253,35 +253,7 @@ export function launchFor(settings, runtimeDir, options = {}) {
253
253
  if (value !== undefined)
254
254
  env[name] = value;
255
255
  }
256
- let document = pipeSettings(settings, (source, path) => {
257
- const name = environmentName(source, path);
258
- if (name === undefined)
259
- return;
260
- const value = process.env[name];
261
- if (value !== undefined)
262
- env[name] = value;
263
- });
264
- let interfaceDir = runtimeDir;
265
- let detached = false;
266
- if (document !== null && typeof document === "object" && !Array.isArray(document)) {
267
- if (Object.hasOwn(document, "presets") && document.presets !== undefined) {
268
- // Presets retain their existing friendly spec writer after settings normalization.
269
- const presets = document.presets;
270
- document = { ...document, presets: Object.fromEntries(Object.entries(presets).map(([name, spec]) => [name, presetFor(spec)])) };
271
- }
272
- const supplied = Object.hasOwn(document, "interface") && document.interface !== undefined ? document.interface : {};
273
- if (supplied !== null && typeof supplied === "object" && !Array.isArray(supplied)) {
274
- // Choose client defaults once, from canonical own data; invalid groups reach the Host unchanged.
275
- const selected = {
276
- ...supplied,
277
- ...(!Object.hasOwn(supplied, "dir") || supplied.dir == null ? { dir: runtimeDir } : {}),
278
- ...(!Object.hasOwn(supplied, "lifetime") || supplied.lifetime === undefined ? { lifetime: "stdin" } : {}),
279
- };
280
- document = { ...document, interface: selected };
281
- interfaceDir = selected.dir; // The single default choice above supplies every omitted/null directory.
282
- detached = selected.lifetime !== "stdin";
283
- }
284
- }
256
+ const { document, interfaceDir, detached } = prepareSettings(settings, runtimeDir, env);
285
257
  return {
286
258
  binary: resolveBinary(options.binary), document: encodeSettings(document), interfaceDir,
287
259
  socketPath: join(runtimeDir, "interface", SOCKET_NAME), env, detached,
@@ -293,37 +265,6 @@ function disposeLaunch(launch) {
293
265
  for (const name of Object.keys(launch.env))
294
266
  delete launch.env[name];
295
267
  }
296
- /** Consume the byte codec's canonical JSON value before allowing any Node environment lookup.
297
- * Malformed values stay in the document for Host refusal; Host bounds remain its own. */
298
- function environmentName(source, path) {
299
- let name;
300
- if (typeof source === "string")
301
- name = source;
302
- else {
303
- if (source === null || typeof source !== "object")
304
- return undefined;
305
- const fields = Object.keys(source);
306
- if (fields.length !== 1 || fields[0] !== "hex")
307
- return undefined;
308
- const hex = source.hex;
309
- if (typeof hex !== "string")
310
- return undefined;
311
- if (hex.length % 2 !== 0 || /[^0-9a-f]/.test(hex))
312
- return undefined;
313
- try {
314
- name = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Buffer.from(hex, "hex"));
315
- }
316
- catch {
317
- throw new RuiStartError("settings_invalid", `${path}: Node requires UTF-8 environment names; use a file source for OS-byte names`);
318
- }
319
- }
320
- // Node truncates NUL and replaces lone UTF-16 surrogates; neither may choose another key.
321
- return name.length !== 0 && !/[\0=\uD800-\uDFFF]/u.test(name) ? name : undefined;
322
- }
323
- /** Presets and Session mutation requests use the same wire writer. */
324
- function presetFor(spec) {
325
- return agentSpec(spec);
326
- }
327
268
  /** Starts one child and resolves once it answers host-info, or throws AttemptFailed. */
328
269
  async function start(launch, spawned) {
329
270
  let child;
package/dist/feed.js CHANGED
@@ -104,7 +104,7 @@ export function readContentBytes(link, session, entry) {
104
104
  export async function readContent(link, session, entry) {
105
105
  return (await readContentBytes(link, session, entry)).toString("utf8");
106
106
  }
107
- /** Waits `ms`, or less when `signal` aborts. */
107
+ /** Waits `ms`, or less when `signal` aborts; with no `ms`, waits only for the abort. */
108
108
  function pause(ms, signal) {
109
109
  return new Promise((resolve) => {
110
110
  if (signal?.aborted)
@@ -114,7 +114,7 @@ function pause(ms, signal) {
114
114
  signal?.removeEventListener("abort", done);
115
115
  resolve();
116
116
  };
117
- const timer = setTimeout(done, ms);
117
+ const timer = ms === undefined ? undefined : setTimeout(done, ms);
118
118
  signal?.addEventListener("abort", done, { once: true });
119
119
  });
120
120
  }
@@ -186,7 +186,8 @@ export async function* listActivity(link, session, options = {}) {
186
186
  if (receivedItems)
187
187
  wait = FIRST_POLL_MS;
188
188
  else if (idle) {
189
- await (watcher ? watcher.wait(revision, signal) : untilAbort(signal));
189
+ // A bare internal Link has no local writes to observe; cancellation still ends its idle wait.
190
+ await (watcher ? watcher.wait(revision, signal) : pause(undefined, signal));
190
191
  wait = FIRST_POLL_MS;
191
192
  }
192
193
  else {
@@ -202,15 +203,6 @@ export async function* listActivity(link, session, options = {}) {
202
203
  function dormant(kind) {
203
204
  return kind === "idle" || kind === "finished" || kind === "failed" || kind === "stopped";
204
205
  }
205
- /** A bare internal Link has no local writes to observe; cancellation still ends its idle wait. */
206
- function untilAbort(signal) {
207
- return new Promise((resolve) => {
208
- if (signal?.aborted)
209
- resolve();
210
- else
211
- signal?.addEventListener("abort", () => resolve(), { once: true });
212
- });
213
- }
214
206
  /** Search public feed text newest first. Empty budget-limited pages still advance. */
215
207
  export async function* searchActivity(link, session, query, options = {}) {
216
208
  const bytes = Buffer.byteLength(query, "utf8");
@@ -1,4 +1,4 @@
1
- import type { AgentSpec } from "./sessions.ts";
1
+ import { type AgentSpec } from "./sessions.ts";
2
2
  import type { components } from "./wire.ts";
3
3
  type Input<T> = T extends {
4
4
  value: string;
@@ -14,4 +14,12 @@ export type HostSettings = Omit<Input<components["schemas"]["HostSettings"]>, "p
14
14
  };
15
15
  /** Normalize only generated schema leaves. Arbitrary preset JSON is not interpreted. */
16
16
  export declare function pipeSettings(value: HostSettings, environmentSource?: (name: unknown, path: string) => void): components["schemas"]["HostSettings"];
17
+ /** Launch projection is owned alongside the document, not by child supervision. */
18
+ export interface PreparedSettings {
19
+ document: components["schemas"]["HostSettings"];
20
+ interfaceDir: NonNullable<NonNullable<components["schemas"]["HostSettings"]["interface"]>["dir"]>;
21
+ detached: boolean;
22
+ }
23
+ /** Preserve client defaults and friendly preset encoding after canonical normalization. */
24
+ export declare function prepareSettings(settings: HostSettings, runtimeDir: string, env: NodeJS.ProcessEnv): PreparedSettings;
17
25
  export {};
package/dist/settings.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Friendly inputs are mechanically derived from the generated document type.
2
2
  // Runtime codecs come from annotations on that same schema, never a field list.
3
3
  import { SETTINGS_KINDS } from "./settings-kinds.js";
4
+ import { agentSpec } from "./sessions.js";
5
+ import { RuiStartError } from "./errors.js";
4
6
  /** Normalize only generated schema leaves. Arbitrary preset JSON is not interpreted. */
5
7
  export function pipeSettings(value, environmentSource) {
6
8
  function visit(value, codec, path) {
@@ -37,3 +39,63 @@ export function pipeSettings(value, environmentSource) {
37
39
  }
38
40
  return visit(value, SETTINGS_KINDS, "");
39
41
  }
42
+ /** Preserve client defaults and friendly preset encoding after canonical normalization. */
43
+ export function prepareSettings(settings, runtimeDir, env) {
44
+ let document = pipeSettings(settings, (source, path) => {
45
+ const name = environmentName(source, path);
46
+ if (name === undefined)
47
+ return;
48
+ const value = process.env[name];
49
+ if (value !== undefined)
50
+ env[name] = value;
51
+ });
52
+ let interfaceDir = runtimeDir;
53
+ let detached = false;
54
+ if (document !== null && typeof document === "object" && !Array.isArray(document)) {
55
+ if (Object.hasOwn(document, "presets") && document.presets !== undefined) {
56
+ // Presets retain their existing friendly spec writer after settings normalization.
57
+ const presets = document.presets;
58
+ document = { ...document, presets: Object.fromEntries(Object.entries(presets).map(([name, spec]) => [name, agentSpec(spec)])) };
59
+ }
60
+ const supplied = Object.hasOwn(document, "interface") && document.interface !== undefined ? document.interface : {};
61
+ if (supplied !== null && typeof supplied === "object" && !Array.isArray(supplied)) {
62
+ // Choose client defaults once, from canonical own data; invalid groups reach the Host unchanged.
63
+ const selected = {
64
+ ...supplied,
65
+ ...(!Object.hasOwn(supplied, "dir") || supplied.dir == null ? { dir: runtimeDir } : {}),
66
+ ...(!Object.hasOwn(supplied, "lifetime") || supplied.lifetime === undefined ? { lifetime: "stdin" } : {}),
67
+ };
68
+ document = { ...document, interface: selected };
69
+ interfaceDir = selected.dir; // The single default choice above supplies every omitted/null directory.
70
+ detached = selected.lifetime !== "stdin";
71
+ }
72
+ }
73
+ return { document, interfaceDir, detached };
74
+ }
75
+ /** Consume the byte codec's canonical JSON value before allowing any Node environment lookup.
76
+ * Malformed values stay in the document for Host refusal; Host bounds remain its own. */
77
+ function environmentName(source, path) {
78
+ let name;
79
+ if (typeof source === "string")
80
+ name = source;
81
+ else {
82
+ if (source === null || typeof source !== "object")
83
+ return undefined;
84
+ const fields = Object.keys(source);
85
+ if (fields.length !== 1 || fields[0] !== "hex")
86
+ return undefined;
87
+ const hex = source.hex;
88
+ if (typeof hex !== "string")
89
+ return undefined;
90
+ if (hex.length % 2 !== 0 || /[^0-9a-f]/.test(hex))
91
+ return undefined;
92
+ try {
93
+ name = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Buffer.from(hex, "hex"));
94
+ }
95
+ catch {
96
+ throw new RuiStartError("settings_invalid", `${path}: Node requires UTF-8 environment names; use a file source for OS-byte names`);
97
+ }
98
+ }
99
+ // Node truncates NUL and replaces lone UTF-16 surrogates; neither may choose another key.
100
+ return name.length !== 0 && !/[\0=\uD800-\uDFFF]/u.test(name) ? name : undefined;
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ruicode",
3
- "version": "0.74.1",
3
+ "version": "0.74.3",
4
4
  "description": "Start a Rui Host as a child process and talk to it over its local socket.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -28,8 +28,8 @@
28
28
  "mcp"
29
29
  ],
30
30
  "optionalDependencies": {
31
- "ruicode-linux-x64": "0.74.1",
32
- "ruicode-linux-arm64": "0.74.1",
33
- "ruicode-darwin-arm64": "0.74.1"
31
+ "ruicode-linux-x64": "0.74.3",
32
+ "ruicode-linux-arm64": "0.74.3",
33
+ "ruicode-darwin-arm64": "0.74.3"
34
34
  }
35
35
  }