@addai/node 0.30.1 → 0.30.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.
@@ -76,7 +76,14 @@ function runCmd(cmd, args, timeoutMs = 5000) {
76
76
  // a single failing probe must not take down the whole heartbeat.
77
77
  try {
78
78
  const inv = (0, win_1.resolveCliInvocation)(cmd, args);
79
- (0, child_process_1.execFile)(inv.file, inv.args, { timeout: timeoutMs, maxBuffer: 256 * 1024 }, (err, stdout, stderr) => {
79
+ // windowsHide: this probe runs for every harness on every heartbeat, so
80
+ // without it a Windows node flashes a console window several times a
81
+ // minute, for ever. stderr is captured here rather than discarded — a
82
+ // probe's error text is the diagnosis when a harness is present but
83
+ // broken, unlike the "not found" that whereLookup drops.
84
+ (0, child_process_1.execFile)(inv.file, inv.args, {
85
+ timeout: timeoutMs, maxBuffer: 256 * 1024, windowsHide: true,
86
+ }, (err, stdout, stderr) => {
80
87
  resolve({ ok: !err, stdout: (stdout ?? '').trim(), stderr: (stderr ?? '').trim() });
81
88
  });
82
89
  }
@@ -86,7 +86,13 @@ function findClaudeBinary() {
86
86
  // (extensionless bash script, .cmd, .ps1). Prefer a native .exe
87
87
  // (installer builds), then .cmd — never the extensionless one,
88
88
  // which CreateProcess can't run.
89
- const lines = (0, child_process_1.execSync)('where claude', { encoding: 'utf-8', timeout: 5000 })
89
+ // windowsHide and a discarded stderr see whereLookup in win.ts for
90
+ // why. execSync goes through cmd.exe, so a miss here costs a console
91
+ // window AND a line of noise in daemon.log every time it runs.
92
+ const lines = (0, child_process_1.execSync)('where claude', {
93
+ encoding: 'utf-8', timeout: 5000, windowsHide: true,
94
+ stdio: ['ignore', 'pipe', 'ignore'],
95
+ })
90
96
  .split(/\r?\n/)
91
97
  .map(l => l.trim())
92
98
  .filter(Boolean);
@@ -181,6 +181,9 @@ function spawnClaudePrint(input) {
181
181
  cwd: input.workingDirectory,
182
182
  env: { ...process.env, TERM: 'dumb' },
183
183
  stdio: ['ignore', 'pipe', 'pipe'],
184
+ // No console window. This is headless work on somebody's machine —
185
+ // on Windows a spawn without this flashes a terminal every run.
186
+ windowsHide: true,
184
187
  });
185
188
  }
186
189
  catch (err) {
@@ -301,6 +301,9 @@ function spawnCodex(input) {
301
301
  cwd: input.workingDirectory,
302
302
  env: childEnv,
303
303
  stdio: ['ignore', 'pipe', 'pipe'],
304
+ // No console window. This is headless work on somebody's machine —
305
+ // on Windows a spawn without this flashes a terminal every run.
306
+ windowsHide: true,
304
307
  });
305
308
  }
306
309
  catch (err) {
@@ -87,6 +87,31 @@ exports.WRAPPER_PATH = '/usr/local/bin/browser';
87
87
  * so the loop cannot be rebuilt even if something else recreates the shape.
88
88
  */
89
89
  exports.WRAPPER_MARKER = 'Written by @addai/node';
90
+ /**
91
+ * The first-run flow, off.
92
+ *
93
+ * ⚠️ Without these you do not get a browser. You get Chrome's first-run
94
+ * DIALOGS — the terms of service, then "make Chrome your default" — each one a
95
+ * separate top-level X window. Over xpra, which forwards windows one at a
96
+ * time, that is what lands on somebody's desktop: a 610x564 dialog, then a
97
+ * 490x162 one, and never the browser behind them.
98
+ *
99
+ * Worse, they are modal and they are traps. Escape on the terms dialog means
100
+ * DECLINE, and Chrome exits — so "close that popup" closed the whole thing,
101
+ * and an entity typing into what it assumed was a search box was typing into
102
+ * a consent prompt.
103
+ *
104
+ * Every container starts with a fresh profile, so this happened on every
105
+ * desktop, every time, and only ever looked like the browser being broken.
106
+ *
107
+ * The crash bubble is the same class of problem: any unclean exit — a rebuild,
108
+ * a killed container — and the next launch opens with "Restore pages?" over
109
+ * the top of whatever was asked for.
110
+ *
111
+ * Verified on a live container: with these flags the first window is
112
+ * 1918x1078 with a tab strip and an address bar, instead of a dialog.
113
+ */
114
+ const FIRST_RUN = ' --no-first-run --no-default-browser-check --hide-crash-restore-bubble';
90
115
  /** The in-container script that signs the browser in. Beside the extension,
91
116
  * under the same bind mount, so it arrives by the same route. */
92
117
  exports.SEED_SCRIPT = '/conf/vault/vault-seed.mjs';
@@ -117,7 +142,7 @@ function wrapperScript(realBrowser, extensionDir) {
117
142
  return `#!/bin/sh
118
143
  # Written by @addai/node so +Ai Learn can watch this browser${extensionDir ? ' and the +Ai Vault can fill logins in it' : ''}.
119
144
  # Removing it costs you the page detail in a lesson${extensionDir ? ' and vault autofill' : ''} and nothing else.
120
- ${seed}exec ${realBrowser} --remote-debugging-port=${exports.DEBUG_PORT} --remote-debugging-address=127.0.0.1${ext} "$@"
145
+ ${seed}exec ${realBrowser} --remote-debugging-port=${exports.DEBUG_PORT} --remote-debugging-address=127.0.0.1${FIRST_RUN}${ext} "$@"
121
146
  `;
122
147
  }
123
148
  /** Is what is on disk already what we would write? Exact match, so a change to
@@ -83,6 +83,30 @@ let missedPongs = 0;
83
83
  * people watching the same screen each need their own connection and their
84
84
  * own handshake. x11vnc runs with -shared precisely so it will serve them. */
85
85
  const bridges = new Map();
86
+ /**
87
+ * Bytes that arrived while their bridge was still being built.
88
+ *
89
+ * ⚠️ There is an await between 'attach' and the socket existing — the row has
90
+ * to be looked up to know which port to dial — and a viewer can send in that
91
+ * window. RFB never did: x11vnc speaks first, so noVNC has nothing to say
92
+ * until the server has already said hello, and the gap was invisible for as
93
+ * long as the screen was the only channel.
94
+ *
95
+ * xpra is the other way round. Its client sends its own hello the moment the
96
+ * socket opens, so on the windows channel the first packet ALWAYS raced the
97
+ * lookup — and losing it was not a dropped packet but a dead session: the data
98
+ * branch found no bridge, reported the viewer gone, and the connection that
99
+ * finished opening a moment later sat there with nothing on it until xpra
100
+ * timed out 20 seconds on:
101
+ *
102
+ * New tcp connection received from '172.17.0.1:58222'
103
+ * 0 packets received
104
+ * 1 packets sent (25 bytes)
105
+ *
106
+ * A viewerId present here means "attaching" — distinct from present in
107
+ * `bridges` (attached) and from neither (gone, and the sender should be told).
108
+ */
109
+ const pendingWrites = new Map();
86
110
  const wakeHooks = new Map();
87
111
  function onWake(kind, fn) {
88
112
  wakeHooks.set(kind, fn);
@@ -95,6 +119,9 @@ function dropBridges() {
95
119
  catch { /* gone */ }
96
120
  }
97
121
  bridges.clear();
122
+ // The link went down mid-attach. Nothing will ever flush these, and keeping
123
+ // them would hand a reconnecting viewer the last session's first packet.
124
+ pendingWrites.clear();
98
125
  }
99
126
  /**
100
127
  * Start a connection attempt that CANNOT take the daemon down with it.
@@ -175,11 +202,17 @@ async function connect() {
175
202
  const gone = (viewerId, reason) => {
176
203
  bridges.get(viewerId)?.destroy();
177
204
  bridges.delete(viewerId);
205
+ // Anything still waiting for a bridge that is never coming.
206
+ pendingWrites.delete(viewerId);
178
207
  if (sock.readyState === ws_1.default.OPEN) {
179
208
  sock.send(JSON.stringify({ type: 'gone', viewerId, reason }));
180
209
  }
181
210
  };
182
211
  if (msg.type === 'attach') {
212
+ // Claim the viewer BEFORE the await, so a packet arriving during the
213
+ // lookup is held rather than treated as arriving after a lost bridge.
214
+ if (!pendingWrites.has(msg.viewerId))
215
+ pendingWrites.set(msg.viewerId, []);
183
216
  const row = (await (0, manager_1.listDesktops)()).find(d => d.id === msg.desktopId);
184
217
  if (!row?.vnc_port) {
185
218
  gone(msg.viewerId, 'desktop is not running');
@@ -223,14 +256,28 @@ async function connect() {
223
256
  tcp.on('close', () => gone(msg.viewerId, 'the desktop closed the connection'));
224
257
  bridges.get(msg.viewerId)?.destroy();
225
258
  bridges.set(msg.viewerId, tcp);
259
+ // Whatever arrived while the row was being looked up, in order and
260
+ // before anything newer. net.connect returns a socket that is still
261
+ // connecting, and node queues writes on it until it is — so this needs
262
+ // no wait of its own.
263
+ const queued = pendingWrites.get(msg.viewerId) ?? [];
264
+ pendingWrites.delete(msg.viewerId);
265
+ for (const chunk of queued)
266
+ tcp.write(chunk);
226
267
  return;
227
268
  }
228
269
  if (msg.type === 'data' && msg.b64) {
229
270
  const bridge = bridges.get(msg.viewerId);
230
- // Input for a bridge that no longer exists. Dropping it quietly is how
231
- // "take control does nothing" happens: the pointer never moves and the
232
- // viewer has no idea why.
233
271
  if (!bridge) {
272
+ // Still attaching: hold it. The first xpra packet always lands here.
273
+ const queue = pendingWrites.get(msg.viewerId);
274
+ if (queue) {
275
+ queue.push(Buffer.from(msg.b64, 'base64'));
276
+ return;
277
+ }
278
+ // Input for a bridge that no longer exists. Dropping it quietly is how
279
+ // "take control does nothing" happens: the pointer never moves and the
280
+ // viewer has no idea why.
234
281
  gone(msg.viewerId, 'no longer connected to the desktop');
235
282
  return;
236
283
  }
@@ -260,6 +307,8 @@ async function connect() {
260
307
  if (msg.type === 'detach') {
261
308
  bridges.get(msg.viewerId)?.destroy();
262
309
  bridges.delete(msg.viewerId);
310
+ // A viewer that left while it was still attaching.
311
+ pendingWrites.delete(msg.viewerId);
263
312
  }
264
313
  });
265
314
  const retry = () => {
@@ -357,6 +357,9 @@ function spawnGemini(input) {
357
357
  cwd: input.workingDirectory,
358
358
  env: childEnv,
359
359
  stdio: ['ignore', 'pipe', 'pipe'],
360
+ // No console window. This is headless work on somebody's machine —
361
+ // on Windows a spawn without this flashes a terminal every run.
362
+ windowsHide: true,
360
363
  });
361
364
  }
362
365
  catch (err) {
@@ -66,7 +66,9 @@ async function applyGitIdentity(dir, requestId, token) {
66
66
  if (!ident?.configured || !ident.author_name || !ident.author_email)
67
67
  return;
68
68
  const git = (args) => new Promise((resolve) => {
69
- (0, child_process_1.execFile)('git', ['-C', dir, ...args], { timeout: 10_000 }, () => resolve());
69
+ (0, child_process_1.execFile)('git', ['-C', dir, ...args],
70
+ // Headless: no console window on Windows.
71
+ { timeout: 10_000, windowsHide: true }, () => resolve());
70
72
  });
71
73
  // Repo-local only — never touch the machine's global config, which other
72
74
  // entities and the human owner share.
@@ -349,6 +349,9 @@ function spawnGrok(input) {
349
349
  cwd: input.workingDirectory,
350
350
  env: childEnv,
351
351
  stdio: ['ignore', 'pipe', 'pipe'],
352
+ // No console window. This is headless work on somebody's machine —
353
+ // on Windows a spawn without this flashes a terminal every run.
354
+ windowsHide: true,
352
355
  });
353
356
  }
354
357
  catch (err) {
@@ -390,6 +390,9 @@ function spawnKimi(input) {
390
390
  cwd: input.workingDirectory,
391
391
  env: childEnv,
392
392
  stdio: ['ignore', 'pipe', 'pipe'],
393
+ // No console window. This is headless work on somebody's machine —
394
+ // on Windows a spawn without this flashes a terminal every run.
395
+ windowsHide: true,
393
396
  });
394
397
  }
395
398
  catch (err) {
package/dist/projects.js CHANGED
@@ -105,7 +105,12 @@ function projectDir(p) {
105
105
  }
106
106
  function run(cmd, args, opts = {}) {
107
107
  return new Promise(resolve => {
108
- (0, child_process_1.execFile)(cmd, args, { cwd: opts.cwd, timeout: opts.timeoutMs ?? 5 * 60_000, maxBuffer: 4 * 1024 * 1024 }, (err, stdout, stderr) => {
108
+ (0, child_process_1.execFile)(cmd, args, {
109
+ cwd: opts.cwd, timeout: opts.timeoutMs ?? 5 * 60_000,
110
+ maxBuffer: 4 * 1024 * 1024,
111
+ // Headless: no console window on Windows.
112
+ windowsHide: true,
113
+ }, (err, stdout, stderr) => {
109
114
  resolve({ ok: !err, stdout: stdout.toString(), stderr: stderr.toString() });
110
115
  });
111
116
  });
package/dist/win.js CHANGED
@@ -91,7 +91,19 @@ function whereLookup(name) {
91
91
  if (!exports.IS_WINDOWS)
92
92
  return null;
93
93
  try {
94
- const out = (0, child_process_1.execFileSync)('where', [name], { encoding: 'utf8', timeout: 5000 });
94
+ // ⚠️ windowsHide, and stderr thrown away. Both for the same reason: this
95
+ // runs for every CLI we look for, on a timer, and most of them are not
96
+ // installed. Without windowsHide each miss flashes a console window on
97
+ // the user's screen; without the stdio the miss writes
98
+ //
99
+ // INFO: Could not find files for the given pattern(s).
100
+ //
101
+ // to our stderr, and daemon.log fills with nothing else. "Not found" is
102
+ // the return value here, not an event worth reporting.
103
+ const out = (0, child_process_1.execFileSync)('where', [name], {
104
+ encoding: 'utf8', timeout: 5000, windowsHide: true,
105
+ stdio: ['ignore', 'pipe', 'ignore'],
106
+ });
95
107
  const lines = out.split(/\r?\n/).map(l => l.trim()).filter(Boolean);
96
108
  const pick = lines.find(l => /\.exe$/i.test(l)) ??
97
109
  lines.find(l => /\.cmd$/i.test(l)) ??
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addai/node",
3
- "version": "0.30.1",
3
+ "version": "0.30.3",
4
4
  "description": "Daemon that pairs a machine with your +Ai account and runs Claude / Codex / Kimi / Gemini agents on its behalf. Reachable via Supabase from Vault, Entity Studio, or any other +Ai surface.",
5
5
  "license": "MIT",
6
6
  "keywords": [