@lazehq/cli 0.1.126 → 0.1.128

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 (2) hide show
  1. package/dist/laze.mjs +982 -825
  2. package/package.json +1 -1
package/dist/laze.mjs CHANGED
@@ -849,9 +849,9 @@ var require_node_gyp_build = __commonJS({
849
849
  var debug = getFirst(path.join(dir, "build/Debug"), matchBuild);
850
850
  if (debug) return debug;
851
851
  }
852
- var prebuild = resolve28(dir);
852
+ var prebuild = resolve27(dir);
853
853
  if (prebuild) return prebuild;
854
- var nearby = resolve28(path.dirname(process.execPath));
854
+ var nearby = resolve27(path.dirname(process.execPath));
855
855
  if (nearby) return nearby;
856
856
  var target = [
857
857
  "platform=" + platform,
@@ -867,7 +867,7 @@ var require_node_gyp_build = __commonJS({
867
867
  // eslint-disable-line
868
868
  ].filter(Boolean).join(" ");
869
869
  throw new Error("No native build was found for " + target + "\n loaded from: " + dir + "\n");
870
- function resolve28(dir2) {
870
+ function resolve27(dir2) {
871
871
  var tuples = readdirSync(path.join(dir2, "prebuilds")).map(parseTuple);
872
872
  var tuple2 = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
873
873
  if (!tuple2) return;
@@ -3244,7 +3244,7 @@ var require_websocket = __commonJS({
3244
3244
  var http = __require("http");
3245
3245
  var net = __require("net");
3246
3246
  var tls = __require("tls");
3247
- var { randomBytes: randomBytes7, createHash: createHash11 } = __require("crypto");
3247
+ var { randomBytes: randomBytes7, createHash: createHash12 } = __require("crypto");
3248
3248
  var { Duplex, Readable: Readable2 } = __require("stream");
3249
3249
  var { URL: URL3 } = __require("url");
3250
3250
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -3912,7 +3912,7 @@ var require_websocket = __commonJS({
3912
3912
  abortHandshake(websocket, socket, "Invalid Upgrade header");
3913
3913
  return;
3914
3914
  }
3915
- const digest = createHash11("sha1").update(key + GUID).digest("base64");
3915
+ const digest = createHash12("sha1").update(key + GUID).digest("base64");
3916
3916
  if (res.headers["sec-websocket-accept"] !== digest) {
3917
3917
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
3918
3918
  return;
@@ -4281,7 +4281,7 @@ var require_websocket_server = __commonJS({
4281
4281
  var EventEmitter = __require("events");
4282
4282
  var http = __require("http");
4283
4283
  var { Duplex } = __require("stream");
4284
- var { createHash: createHash11 } = __require("crypto");
4284
+ var { createHash: createHash12 } = __require("crypto");
4285
4285
  var extension2 = require_extension();
4286
4286
  var PerMessageDeflate2 = require_permessage_deflate();
4287
4287
  var subprotocol2 = require_subprotocol();
@@ -4588,7 +4588,7 @@ var require_websocket_server = __commonJS({
4588
4588
  );
4589
4589
  }
4590
4590
  if (this._state > RUNNING) return abortHandshake(socket, 503);
4591
- const digest = createHash11("sha1").update(key + GUID).digest("base64");
4591
+ const digest = createHash12("sha1").update(key + GUID).digest("base64");
4592
4592
  const headers = [
4593
4593
  "HTTP/1.1 101 Switching Protocols",
4594
4594
  "Upgrade: websocket",
@@ -7314,9 +7314,9 @@ var require_dispatcher_base = __commonJS({
7314
7314
  }
7315
7315
  close(callback) {
7316
7316
  if (callback === void 0) {
7317
- return new Promise((resolve28, reject) => {
7317
+ return new Promise((resolve27, reject) => {
7318
7318
  this.close((err, data) => {
7319
- return err ? reject(err) : resolve28(data);
7319
+ return err ? reject(err) : resolve27(data);
7320
7320
  });
7321
7321
  });
7322
7322
  }
@@ -7354,9 +7354,9 @@ var require_dispatcher_base = __commonJS({
7354
7354
  err = null;
7355
7355
  }
7356
7356
  if (callback === void 0) {
7357
- return new Promise((resolve28, reject) => {
7357
+ return new Promise((resolve27, reject) => {
7358
7358
  this.destroy(err, (err2, data) => {
7359
- return err2 ? reject(err2) : resolve28(data);
7359
+ return err2 ? reject(err2) : resolve27(data);
7360
7360
  });
7361
7361
  });
7362
7362
  }
@@ -7474,14 +7474,14 @@ var require_connect = __commonJS({
7474
7474
  const sessionCache = new SessionCache(maxCachedSessions == null ? 100 : maxCachedSessions);
7475
7475
  timeout = timeout == null ? 1e4 : timeout;
7476
7476
  allowH2 = allowH2 != null ? allowH2 : true;
7477
- return function connect8({ hostname: hostname9, host: host2, protocol, port, servername, localAddress, httpSocket }, callback) {
7477
+ return function connect8({ hostname: hostname10, host: host2, protocol, port, servername, localAddress, httpSocket }, callback) {
7478
7478
  let socket;
7479
7479
  if (protocol === "https:") {
7480
7480
  if (!tls) {
7481
7481
  tls = __require("node:tls");
7482
7482
  }
7483
7483
  servername = servername || options.servername || util.getServerName(host2) || null;
7484
- const sessionKey = servername || hostname9;
7484
+ const sessionKey = servername || hostname10;
7485
7485
  assert2(sessionKey);
7486
7486
  const session = customSession || sessionCache.get(sessionKey) || null;
7487
7487
  port = port || 443;
@@ -7496,7 +7496,7 @@ var require_connect = __commonJS({
7496
7496
  socket: httpSocket,
7497
7497
  // upgrade socket connection
7498
7498
  port,
7499
- host: hostname9
7499
+ host: hostname10
7500
7500
  });
7501
7501
  socket.on("session", function(session2) {
7502
7502
  sessionCache.set(sessionKey, session2);
@@ -7510,16 +7510,16 @@ var require_connect = __commonJS({
7510
7510
  ...options,
7511
7511
  localAddress,
7512
7512
  port,
7513
- host: hostname9
7513
+ host: hostname10
7514
7514
  };
7515
- const family2 = net.isIP(hostname9);
7516
- if (family2 !== 0 && servername && servername !== hostname9) {
7515
+ const family2 = net.isIP(hostname10);
7516
+ if (family2 !== 0 && servername && servername !== hostname10) {
7517
7517
  connectOptions.host = servername;
7518
7518
  connectOptions.lookup = (_hostname, lookupOptions, cb) => {
7519
7519
  if (lookupOptions.all) {
7520
- cb(null, [{ address: hostname9, family: family2 }]);
7520
+ cb(null, [{ address: hostname10, family: family2 }]);
7521
7521
  } else {
7522
- cb(null, hostname9, family2);
7522
+ cb(null, hostname10, family2);
7523
7523
  }
7524
7524
  };
7525
7525
  }
@@ -7532,7 +7532,7 @@ var require_connect = __commonJS({
7532
7532
  const keepAliveInitialDelay = options.keepAliveInitialDelay === void 0 ? 6e4 : options.keepAliveInitialDelay;
7533
7533
  socket.setKeepAlive(true, keepAliveInitialDelay);
7534
7534
  }
7535
- const clearConnectTimeout = util.setupConnectTimeout(new WeakRef(socket), { timeout, hostname: hostname9, port });
7535
+ const clearConnectTimeout = util.setupConnectTimeout(new WeakRef(socket), { timeout, hostname: hostname10, port });
7536
7536
  socket.setNoDelay(true).once(protocol === "https:" ? "secureConnect" : "connect", function() {
7537
7537
  queueMicrotask(clearConnectTimeout);
7538
7538
  if (callback) {
@@ -7545,7 +7545,7 @@ var require_connect = __commonJS({
7545
7545
  if (callback) {
7546
7546
  const cb = callback;
7547
7547
  callback = null;
7548
- cb(maybeNormalizeConnectError(err, this, { timeout, hostname: hostname9, port }));
7548
+ cb(maybeNormalizeConnectError(err, this, { timeout, hostname: hostname10, port }));
7549
7549
  }
7550
7550
  });
7551
7551
  return socket;
@@ -12311,12 +12311,12 @@ upgrade: ${upgrade2}\r
12311
12311
  cb();
12312
12312
  }
12313
12313
  }
12314
- const waitForDrain = () => new Promise((resolve28, reject) => {
12314
+ const waitForDrain = () => new Promise((resolve27, reject) => {
12315
12315
  assert2(callback === null);
12316
12316
  if (socket[kError]) {
12317
12317
  reject(socket[kError]);
12318
12318
  } else {
12319
- callback = resolve28;
12319
+ callback = resolve27;
12320
12320
  }
12321
12321
  });
12322
12322
  socket.on("close", onDrain).on("drain", onDrain);
@@ -13674,12 +13674,12 @@ var require_client_h2 = __commonJS({
13674
13674
  cb();
13675
13675
  }
13676
13676
  }
13677
- const waitForDrain = () => new Promise((resolve28, reject) => {
13677
+ const waitForDrain = () => new Promise((resolve27, reject) => {
13678
13678
  assert2(callback === null);
13679
13679
  if (socket[kError]) {
13680
13680
  reject(socket[kError]);
13681
13681
  } else {
13682
- callback = resolve28;
13682
+ callback = resolve27;
13683
13683
  }
13684
13684
  });
13685
13685
  h2stream.on("close", onDrain).on("drain", onDrain);
@@ -14047,16 +14047,16 @@ var require_client = __commonJS({
14047
14047
  return this[kNeedDrain] < 2;
14048
14048
  }
14049
14049
  [kClose]() {
14050
- return new Promise((resolve28) => {
14050
+ return new Promise((resolve27) => {
14051
14051
  if (this[kSize]) {
14052
- this[kClosedResolve] = resolve28;
14052
+ this[kClosedResolve] = resolve27;
14053
14053
  } else {
14054
- resolve28(null);
14054
+ resolve27(null);
14055
14055
  }
14056
14056
  });
14057
14057
  }
14058
14058
  [kDestroy](err) {
14059
- return new Promise((resolve28) => {
14059
+ return new Promise((resolve27) => {
14060
14060
  const requests2 = this[kQueue].splice(this[kPendingIdx]);
14061
14061
  for (let i = 0; i < requests2.length; i++) {
14062
14062
  const request2 = requests2[i];
@@ -14069,7 +14069,7 @@ var require_client = __commonJS({
14069
14069
  this[kClosedResolve]();
14070
14070
  this[kClosedResolve] = null;
14071
14071
  }
14072
- resolve28(null);
14072
+ resolve27(null);
14073
14073
  };
14074
14074
  if (this[kHTTPContext]) {
14075
14075
  this[kHTTPContext].destroy(err, callback);
@@ -14097,20 +14097,20 @@ var require_client = __commonJS({
14097
14097
  function connect8(client) {
14098
14098
  assert2(!client[kConnecting]);
14099
14099
  assert2(!client[kHTTPContext]);
14100
- let { host: host2, hostname: hostname9, protocol, port } = client[kUrl];
14101
- if (hostname9[0] === "[") {
14102
- const idx = hostname9.indexOf("]");
14100
+ let { host: host2, hostname: hostname10, protocol, port } = client[kUrl];
14101
+ if (hostname10[0] === "[") {
14102
+ const idx = hostname10.indexOf("]");
14103
14103
  assert2(idx !== -1);
14104
- const ip2 = hostname9.substring(1, idx);
14104
+ const ip2 = hostname10.substring(1, idx);
14105
14105
  assert2(net.isIPv6(ip2));
14106
- hostname9 = ip2;
14106
+ hostname10 = ip2;
14107
14107
  }
14108
14108
  client[kConnecting] = true;
14109
14109
  if (channels3.beforeConnect.hasSubscribers) {
14110
14110
  channels3.beforeConnect.publish({
14111
14111
  connectParams: {
14112
14112
  host: host2,
14113
- hostname: hostname9,
14113
+ hostname: hostname10,
14114
14114
  protocol,
14115
14115
  port,
14116
14116
  version: client[kHTTPContext]?.version,
@@ -14123,14 +14123,14 @@ var require_client = __commonJS({
14123
14123
  try {
14124
14124
  client[kConnector]({
14125
14125
  host: host2,
14126
- hostname: hostname9,
14126
+ hostname: hostname10,
14127
14127
  protocol,
14128
14128
  port,
14129
14129
  servername: client[kServerName],
14130
14130
  localAddress: client[kLocalAddress]
14131
14131
  }, (err, socket) => {
14132
14132
  if (err) {
14133
- handleConnectError(client, err, { host: host2, hostname: hostname9, protocol, port });
14133
+ handleConnectError(client, err, { host: host2, hostname: hostname10, protocol, port });
14134
14134
  client[kResume]();
14135
14135
  return;
14136
14136
  }
@@ -14144,7 +14144,7 @@ var require_client = __commonJS({
14144
14144
  client[kHTTPContext] = socket.alpnProtocol === "h2" ? connectH2(client, socket) : connectH1(client, socket);
14145
14145
  } catch (err2) {
14146
14146
  socket.destroy().on("error", noop2);
14147
- handleConnectError(client, err2, { host: host2, hostname: hostname9, protocol, port });
14147
+ handleConnectError(client, err2, { host: host2, hostname: hostname10, protocol, port });
14148
14148
  client[kResume]();
14149
14149
  return;
14150
14150
  }
@@ -14157,7 +14157,7 @@ var require_client = __commonJS({
14157
14157
  channels3.connected.publish({
14158
14158
  connectParams: {
14159
14159
  host: host2,
14160
- hostname: hostname9,
14160
+ hostname: hostname10,
14161
14161
  protocol,
14162
14162
  port,
14163
14163
  version: client[kHTTPContext]?.version,
@@ -14172,11 +14172,11 @@ var require_client = __commonJS({
14172
14172
  client[kResume]();
14173
14173
  });
14174
14174
  } catch (err) {
14175
- handleConnectError(client, err, { host: host2, hostname: hostname9, protocol, port });
14175
+ handleConnectError(client, err, { host: host2, hostname: hostname10, protocol, port });
14176
14176
  client[kResume]();
14177
14177
  }
14178
14178
  }
14179
- function handleConnectError(client, err, { host: host2, hostname: hostname9, protocol, port }) {
14179
+ function handleConnectError(client, err, { host: host2, hostname: hostname10, protocol, port }) {
14180
14180
  if (client.destroyed) {
14181
14181
  return;
14182
14182
  }
@@ -14185,7 +14185,7 @@ var require_client = __commonJS({
14185
14185
  channels3.connectError.publish({
14186
14186
  connectParams: {
14187
14187
  host: host2,
14188
- hostname: hostname9,
14188
+ hostname: hostname10,
14189
14189
  protocol,
14190
14190
  port,
14191
14191
  version: client[kHTTPContext]?.version,
@@ -14482,8 +14482,8 @@ var require_pool_base = __commonJS({
14482
14482
  }
14483
14483
  return Promise.all(closeAll);
14484
14484
  } else {
14485
- return new Promise((resolve28) => {
14486
- this[kClosedResolve] = resolve28;
14485
+ return new Promise((resolve27) => {
14486
+ this[kClosedResolve] = resolve27;
14487
14487
  });
14488
14488
  }
14489
14489
  }
@@ -16240,10 +16240,10 @@ var require_env_http_proxy_agent = __commonJS({
16240
16240
  ]);
16241
16241
  }
16242
16242
  #getProxyAgentForUrl(url2) {
16243
- let { protocol, host: hostname9, port } = url2;
16244
- hostname9 = hostname9.replace(/:\d*$/, "").replace(/^\[(.+)\]$/, "$1").toLowerCase();
16243
+ let { protocol, host: hostname10, port } = url2;
16244
+ hostname10 = hostname10.replace(/:\d*$/, "").replace(/^\[(.+)\]$/, "$1").toLowerCase();
16245
16245
  port = Number.parseInt(port, 10) || DEFAULT_PORTS[protocol] || 0;
16246
- if (!this.#shouldProxy(hostname9, port)) {
16246
+ if (!this.#shouldProxy(hostname10, port)) {
16247
16247
  return this[kNoProxyAgent];
16248
16248
  }
16249
16249
  if (protocol === "https:") {
@@ -16251,7 +16251,7 @@ var require_env_http_proxy_agent = __commonJS({
16251
16251
  }
16252
16252
  return this[kHttpProxyAgent];
16253
16253
  }
16254
- #shouldProxy(hostname9, port) {
16254
+ #shouldProxy(hostname10, port) {
16255
16255
  if (this.#noProxyChanged) {
16256
16256
  this.#parseNoProxy();
16257
16257
  }
@@ -16266,10 +16266,10 @@ var require_env_http_proxy_agent = __commonJS({
16266
16266
  if (entry2.port && entry2.port !== port) {
16267
16267
  continue;
16268
16268
  }
16269
- if (hostname9 === entry2.hostname) {
16269
+ if (hostname10 === entry2.hostname) {
16270
16270
  return false;
16271
16271
  }
16272
- if (hostname9.slice(-(entry2.hostname.length + 1)) === `.${entry2.hostname}`) {
16272
+ if (hostname10.slice(-(entry2.hostname.length + 1)) === `.${entry2.hostname}`) {
16273
16273
  return false;
16274
16274
  }
16275
16275
  }
@@ -16284,21 +16284,21 @@ var require_env_http_proxy_agent = __commonJS({
16284
16284
  if (!entry2) {
16285
16285
  continue;
16286
16286
  }
16287
- let hostname9, port;
16287
+ let hostname10, port;
16288
16288
  const ipv6WithPort = entry2.match(/^\[(.+)\]:(\d+)$/);
16289
16289
  if (ipv6WithPort) {
16290
- hostname9 = ipv6WithPort[1];
16290
+ hostname10 = ipv6WithPort[1];
16291
16291
  port = Number.parseInt(ipv6WithPort[2], 10);
16292
16292
  } else {
16293
16293
  const unbracketed = entry2.replace(/^\[(.+)\]$/, "$1");
16294
16294
  const colonCount = (unbracketed.match(/:/g) || []).length;
16295
16295
  const parsed = colonCount === 1 && unbracketed.match(/^(.+):(\d+)$/);
16296
- hostname9 = parsed ? parsed[1] : unbracketed;
16296
+ hostname10 = parsed ? parsed[1] : unbracketed;
16297
16297
  port = parsed ? Number.parseInt(parsed[2], 10) : 0;
16298
16298
  }
16299
16299
  noProxyEntries.push({
16300
16300
  // strip leading dot or asterisk with dot
16301
- hostname: hostname9.replace(/^\*?\./, "").toLowerCase(),
16301
+ hostname: hostname10.replace(/^\*?\./, "").toLowerCase(),
16302
16302
  port
16303
16303
  });
16304
16304
  }
@@ -16994,7 +16994,7 @@ var require_readable = __commonJS({
16994
16994
  if (this._readableState.closeEmitted) {
16995
16995
  return Promise.resolve(null);
16996
16996
  }
16997
- return new Promise((resolve28, reject) => {
16997
+ return new Promise((resolve27, reject) => {
16998
16998
  if (this[kContentLength] && this[kContentLength] > limit || this[kBytesRead] > limit) {
16999
16999
  this.destroy(new AbortError());
17000
17000
  }
@@ -17008,11 +17008,11 @@ var require_readable = __commonJS({
17008
17008
  if (signal.aborted) {
17009
17009
  reject(signal.reason ?? new AbortError());
17010
17010
  } else {
17011
- resolve28(null);
17011
+ resolve27(null);
17012
17012
  }
17013
17013
  });
17014
17014
  } else {
17015
- this.on("close", resolve28);
17015
+ this.on("close", resolve27);
17016
17016
  }
17017
17017
  this.on("error", noop2).on("data", () => {
17018
17018
  if (this[kBytesRead] > limit) {
@@ -17040,7 +17040,7 @@ var require_readable = __commonJS({
17040
17040
  }
17041
17041
  function consume(stream, type) {
17042
17042
  assert2(!stream[kConsume]);
17043
- return new Promise((resolve28, reject) => {
17043
+ return new Promise((resolve27, reject) => {
17044
17044
  if (isUnusable(stream)) {
17045
17045
  const rState = stream._readableState;
17046
17046
  if (rState.destroyed && rState.closeEmitted === false) {
@@ -17055,7 +17055,7 @@ var require_readable = __commonJS({
17055
17055
  stream[kConsume] = {
17056
17056
  type,
17057
17057
  stream,
17058
- resolve: resolve28,
17058
+ resolve: resolve27,
17059
17059
  reject,
17060
17060
  length: 0,
17061
17061
  body: []
@@ -17133,18 +17133,18 @@ var require_readable = __commonJS({
17133
17133
  return buffer;
17134
17134
  }
17135
17135
  function consumeEnd(consume2, encoding) {
17136
- const { type, body, resolve: resolve28, stream, length } = consume2;
17136
+ const { type, body, resolve: resolve27, stream, length } = consume2;
17137
17137
  try {
17138
17138
  if (type === "text") {
17139
- resolve28(chunksDecode(body, length, encoding));
17139
+ resolve27(chunksDecode(body, length, encoding));
17140
17140
  } else if (type === "json") {
17141
- resolve28(JSON.parse(chunksDecode(body, length, encoding)));
17141
+ resolve27(JSON.parse(chunksDecode(body, length, encoding)));
17142
17142
  } else if (type === "arrayBuffer") {
17143
- resolve28(chunksConcat(body, length).buffer);
17143
+ resolve27(chunksConcat(body, length).buffer);
17144
17144
  } else if (type === "blob") {
17145
- resolve28(new Blob(body, { type: stream[kContentType] }));
17145
+ resolve27(new Blob(body, { type: stream[kContentType] }));
17146
17146
  } else if (type === "bytes") {
17147
- resolve28(chunksConcat(body, length));
17147
+ resolve27(chunksConcat(body, length));
17148
17148
  }
17149
17149
  consumeFinish(consume2);
17150
17150
  } catch (err) {
@@ -17363,9 +17363,9 @@ var require_api_request = __commonJS({
17363
17363
  };
17364
17364
  function request2(opts, callback) {
17365
17365
  if (callback === void 0) {
17366
- return new Promise((resolve28, reject) => {
17366
+ return new Promise((resolve27, reject) => {
17367
17367
  request2.call(this, opts, (err, data) => {
17368
- return err ? reject(err) : resolve28(data);
17368
+ return err ? reject(err) : resolve27(data);
17369
17369
  });
17370
17370
  });
17371
17371
  }
@@ -17626,9 +17626,9 @@ var require_api_stream = __commonJS({
17626
17626
  };
17627
17627
  function stream(opts, factory, callback) {
17628
17628
  if (callback === void 0) {
17629
- return new Promise((resolve28, reject) => {
17629
+ return new Promise((resolve27, reject) => {
17630
17630
  stream.call(this, opts, factory, (err, data) => {
17631
- return err ? reject(err) : resolve28(data);
17631
+ return err ? reject(err) : resolve27(data);
17632
17632
  });
17633
17633
  });
17634
17634
  }
@@ -17928,9 +17928,9 @@ var require_api_upgrade = __commonJS({
17928
17928
  };
17929
17929
  function upgrade2(opts, callback) {
17930
17930
  if (callback === void 0) {
17931
- return new Promise((resolve28, reject) => {
17931
+ return new Promise((resolve27, reject) => {
17932
17932
  upgrade2.call(this, opts, (err, data) => {
17933
- return err ? reject(err) : resolve28(data);
17933
+ return err ? reject(err) : resolve27(data);
17934
17934
  });
17935
17935
  });
17936
17936
  }
@@ -18024,9 +18024,9 @@ var require_api_connect = __commonJS({
18024
18024
  };
18025
18025
  function connect8(opts, callback) {
18026
18026
  if (callback === void 0) {
18027
- return new Promise((resolve28, reject) => {
18027
+ return new Promise((resolve27, reject) => {
18028
18028
  connect8.call(this, opts, (err, data) => {
18029
- return err ? reject(err) : resolve28(data);
18029
+ return err ? reject(err) : resolve27(data);
18030
18030
  });
18031
18031
  });
18032
18032
  }
@@ -19487,7 +19487,7 @@ var require_snapshot_recorder = __commonJS({
19487
19487
  "../../node_modules/.pnpm/undici@8.10.0/node_modules/undici/lib/mock/snapshot-recorder.js"(exports, module) {
19488
19488
  "use strict";
19489
19489
  var { writeFile: writeFile12, readFile: readFile39, mkdir: mkdir14 } = __require("node:fs/promises");
19490
- var { dirname: dirname28, resolve: resolve28 } = __require("node:path");
19490
+ var { dirname: dirname29, resolve: resolve27 } = __require("node:path");
19491
19491
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = __require("node:timers");
19492
19492
  var { InvalidArgumentError, UndiciError } = require_errors();
19493
19493
  var { hashId, isUrlExcludedFactory, normalizeHeaders, createHeaderFilters } = require_snapshot_utils();
@@ -19703,7 +19703,7 @@ var require_snapshot_recorder = __commonJS({
19703
19703
  throw new InvalidArgumentError("Snapshot path is required");
19704
19704
  }
19705
19705
  try {
19706
- const data = await readFile39(resolve28(path), "utf8");
19706
+ const data = await readFile39(resolve27(path), "utf8");
19707
19707
  const parsed = JSON.parse(data);
19708
19708
  if (Array.isArray(parsed)) {
19709
19709
  this.#snapshots.clear();
@@ -19732,8 +19732,8 @@ var require_snapshot_recorder = __commonJS({
19732
19732
  if (!path) {
19733
19733
  throw new InvalidArgumentError("Snapshot path is required");
19734
19734
  }
19735
- const resolvedPath = resolve28(path);
19736
- await mkdir14(dirname28(resolvedPath), { recursive: true });
19735
+ const resolvedPath = resolve27(path);
19736
+ await mkdir14(dirname29(resolvedPath), { recursive: true });
19737
19737
  const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
19738
19738
  hash: hash2,
19739
19739
  snapshot
@@ -20765,14 +20765,14 @@ var require_dns = __commonJS({
20765
20765
  get size() {
20766
20766
  return this.#records.size;
20767
20767
  }
20768
- get(hostname9) {
20769
- return this.#records.get(hostname9) ?? null;
20768
+ get(hostname10) {
20769
+ return this.#records.get(hostname10) ?? null;
20770
20770
  }
20771
- set(hostname9, records) {
20772
- this.#records.set(hostname9, records);
20771
+ set(hostname10, records) {
20772
+ this.#records.set(hostname10, records);
20773
20773
  }
20774
- delete(hostname9) {
20775
- this.#records.delete(hostname9);
20774
+ delete(hostname10) {
20775
+ this.#records.delete(hostname10);
20776
20776
  }
20777
20777
  // Delegate to storage decide can we do more lookups or not
20778
20778
  full() {
@@ -27230,7 +27230,7 @@ var require_fetch = __commonJS({
27230
27230
  const hasTrailingQuestionMark = url2.search.length === 0 && url2.href[url2.href.length - url2.hash.length - 1] === "?";
27231
27231
  return dispatchWithProtocolPreference(body);
27232
27232
  function dispatchWithProtocolPreference(body2, allowH2) {
27233
- return new Promise((resolve28, reject) => agent3.dispatch(
27233
+ return new Promise((resolve27, reject) => agent3.dispatch(
27234
27234
  {
27235
27235
  path: hasTrailingQuestionMark ? `${path}?` : path,
27236
27236
  origin: url2.origin,
@@ -27313,7 +27313,7 @@ var require_fetch = __commonJS({
27313
27313
  }
27314
27314
  }
27315
27315
  const onError = (err) => this.onResponseError(controller, err);
27316
- resolve28({
27316
+ resolve27({
27317
27317
  status: status11,
27318
27318
  statusText,
27319
27319
  headersList,
@@ -27346,7 +27346,7 @@ var require_fetch = __commonJS({
27346
27346
  fetchParams.controller.off("terminated", this.abort);
27347
27347
  }
27348
27348
  if (request2.mode === "websocket" && allowH2 !== false && error63?.code === "UND_ERR_INFO" && error63?.message === "HTTP/2: Extended CONNECT protocol not supported by server") {
27349
- resolve28(dispatchWithProtocolPreference(body2, false));
27349
+ resolve27(dispatchWithProtocolPreference(body2, false));
27350
27350
  return;
27351
27351
  }
27352
27352
  this.body?.destroy(error63);
@@ -27360,7 +27360,7 @@ var require_fetch = __commonJS({
27360
27360
  const rawHeaders = controller?.rawHeaders ?? [];
27361
27361
  const headersList = new HeadersList();
27362
27362
  appendHeadersListFromResponseHeaders(headersList, headers, rawHeaders);
27363
- resolve28({
27363
+ resolve27({
27364
27364
  status: status11,
27365
27365
  statusText: STATUS_CODES[status11],
27366
27366
  headersList,
@@ -31634,7 +31634,7 @@ ${captureLines}` : capture.stack;
31634
31634
  // src/main.ts
31635
31635
  import { homedir as homedir5 } from "node:os";
31636
31636
  import { stderr, stdin, stdout } from "node:process";
31637
- import { createInterface as createInterface5 } from "node:readline/promises";
31637
+ import { createInterface as createInterface4 } from "node:readline/promises";
31638
31638
 
31639
31639
  // ../../packages/secret-guard/src/detector/laze-id.ts
31640
31640
  var LAZE_ID = /^(?:[a-z\d]+_)?[a-z\d]+_([0-9A-Za-z]{29})$/;
@@ -32693,7 +32693,7 @@ function runRedacted({
32693
32693
  redact
32694
32694
  }) {
32695
32695
  const values = redact ?? Object.values(env);
32696
- return new Promise((resolve28, reject) => {
32696
+ return new Promise((resolve27, reject) => {
32697
32697
  const [file4, ...args] = command;
32698
32698
  const child = spawn(file4, args, {
32699
32699
  env: { ...baseEnv, ...env },
@@ -32719,7 +32719,7 @@ function runRedacted({
32719
32719
  child.on("error", reject);
32720
32720
  child.on("close", (code4, ended) => {
32721
32721
  signal?.removeEventListener("abort", killGroup);
32722
- void drained.then(() => resolve28(code4 ?? (ended ? 128 + signalNumber(ended) : 1)));
32722
+ void drained.then(() => resolve27(code4 ?? (ended ? 128 + signalNumber(ended) : 1)));
32723
32723
  });
32724
32724
  });
32725
32725
  }
@@ -36960,7 +36960,7 @@ function shadowedLinkLineOf({ shadow }) {
36960
36960
  }
36961
36961
 
36962
36962
  // src/rules/cli-version.rules.ts
36963
- var STAMPED = "0.1.126";
36963
+ var STAMPED = "0.1.128";
36964
36964
  function cliVersionOf({ stamped = STAMPED } = {}) {
36965
36965
  return stamped.startsWith("__") ? "dev" : stamped;
36966
36966
  }
@@ -37056,8 +37056,87 @@ async function rerunCommandOf({
37056
37056
  }
37057
37057
 
37058
37058
  // src/services/config-store.service.ts
37059
+ import { readFileSync } from "node:fs";
37059
37060
  import { readFile as readFile3 } from "node:fs/promises";
37060
- import { basename as basename2, dirname as dirname3, resolve } from "node:path";
37061
+ import { basename as basename2, dirname as dirname3, join as join4, resolve } from "node:path";
37062
+
37063
+ // src/rules/hook-settings.rules.ts
37064
+ var LAZE_HOOK_MARKER = "laze-cli-hook";
37065
+ var HOOK_TIMEOUTS = { Stop: 30, PreToolUse: 5, SessionStart: 30 };
37066
+ var TIMEOUTS = HOOK_TIMEOUTS;
37067
+ var WAIT_HOOK_TIMEOUT_SECONDS = 7 * 24 * 60 * 60;
37068
+ function withHooks({
37069
+ hooks,
37070
+ event,
37071
+ added
37072
+ }) {
37073
+ const current3 = Array.isArray(hooks[event]) ? hooks[event] : [];
37074
+ const others = current3.filter(
37075
+ (entry2) => !entry2.hooks?.some((hook) => hook.command?.includes(LAZE_HOOK_MARKER))
37076
+ );
37077
+ hooks[event] = [...others, ...added.map((hook) => ({ hooks: [hook] }))];
37078
+ }
37079
+ function withLazeHooks({
37080
+ settings: settings3,
37081
+ stopCommand,
37082
+ waitCommand,
37083
+ preToolCommand
37084
+ }) {
37085
+ const hooks = { ...settings3.hooks };
37086
+ withHooks({
37087
+ hooks,
37088
+ event: "Stop",
37089
+ added: [
37090
+ { type: "command", command: stopCommand, timeout: TIMEOUTS.Stop },
37091
+ {
37092
+ type: "command",
37093
+ command: waitCommand,
37094
+ timeout: WAIT_HOOK_TIMEOUT_SECONDS,
37095
+ async: true,
37096
+ asyncRewake: true
37097
+ }
37098
+ ]
37099
+ });
37100
+ withHooks({
37101
+ hooks,
37102
+ event: "SessionStart",
37103
+ added: [
37104
+ {
37105
+ type: "command",
37106
+ command: waitCommand,
37107
+ timeout: WAIT_HOOK_TIMEOUT_SECONDS,
37108
+ async: true,
37109
+ asyncRewake: true
37110
+ }
37111
+ ]
37112
+ });
37113
+ withHooks({
37114
+ hooks,
37115
+ event: "PreToolUse",
37116
+ added: [{ type: "command", command: preToolCommand, timeout: TIMEOUTS.PreToolUse }]
37117
+ });
37118
+ return { ...settings3, hooks };
37119
+ }
37120
+ function hookCommand({
37121
+ program,
37122
+ hook
37123
+ }) {
37124
+ const quote4 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
37125
+ const words = [...program, "hook", hook].map(quote4).join(" ");
37126
+ return `${words} # ${LAZE_HOOK_MARKER}`;
37127
+ }
37128
+ function holdsOurs({ settings: settings3, event }) {
37129
+ const hooks = settings3.hooks ?? {};
37130
+ return Array.isArray(hooks[event]) && hooks[event].some(
37131
+ (entry2) => entry2.hooks?.some((hook) => hook.command?.includes(LAZE_HOOK_MARKER))
37132
+ );
37133
+ }
37134
+ function lacksSessionStartWaiter({ settings: settings3 }) {
37135
+ return holdsOurs({ settings: settings3, event: "Stop" }) && !holdsOurs({ settings: settings3, event: "SessionStart" });
37136
+ }
37137
+ function hasLazeHooks({ settings: settings3 }) {
37138
+ return holdsOurs({ settings: settings3, event: "Stop" });
37139
+ }
37061
37140
 
37062
37141
  // src/rules/state-file.rules.ts
37063
37142
  function stepOf({ scan, char }) {
@@ -37188,7 +37267,7 @@ async function withStateLock({
37188
37267
  () => 0
37189
37268
  );
37190
37269
  if (since > LOCK_STALE_MS) await rm(lock, { force: true });
37191
- else await new Promise((resolve28) => setTimeout(resolve28, 15 + Math.random() * 20));
37270
+ else await new Promise((resolve27) => setTimeout(resolve27, 15 + Math.random() * 20));
37192
37271
  }
37193
37272
  try {
37194
37273
  return await work();
@@ -37261,12 +37340,23 @@ var ConfigStore = class _ConfigStore {
37261
37340
  config: { ...config2, profiles: { ...config2.profiles, [name3]: profile } }
37262
37341
  }));
37263
37342
  }
37264
- /** Binds a harness session to a profile, so its hooks use it whatever the folder says. */
37343
+ /** Binds a harness session to a profile, the agent's one session on this machine. */
37265
37344
  async bindSession({ session, profile }) {
37266
- await this.update((config2) => ({
37267
- result: void 0,
37268
- config: { ...config2, sessions: { ...config2.sessions, [session]: profile } }
37269
- }));
37345
+ await this.update((config2) => {
37346
+ const others = Object.entries(config2.sessions ?? {}).filter(([, bound]) => bound !== profile);
37347
+ const sessions = { ...Object.fromEntries(others), [session]: profile };
37348
+ return { result: void 0, config: { ...config2, sessions } };
37349
+ });
37350
+ }
37351
+ /** Drops the session's binding while it still names `profile`; true when it did. */
37352
+ async unbindSession({ session, profile }) {
37353
+ return this.update((config2) => {
37354
+ if (config2.sessions?.[session] !== profile) return { result: false };
37355
+ const sessions = Object.fromEntries(
37356
+ Object.entries(config2.sessions).filter(([key]) => key !== session)
37357
+ );
37358
+ return { result: true, config: { ...config2, sessions } };
37359
+ });
37270
37360
  }
37271
37361
  /** Keeps a profile's agent name in step with Laze; a missing or unchanged profile stays. */
37272
37362
  async renameProfileAgent({ name: name3, agentName }) {
@@ -37350,11 +37440,35 @@ function chooseProfile({
37350
37440
  }) {
37351
37441
  const heard = session ? config2.sessions?.[session] : void 0;
37352
37442
  const sessionBound = heard && config2.profiles[heard] ? heard : void 0;
37353
- const bound = boundProfileOf({ bindings: config2.bindings, cwd });
37443
+ const bound = folderLoginOf({ config: config2, cwd });
37354
37444
  const name3 = flag2 || environment || sessionBound || bound || config2.current;
37355
37445
  const profile = name3 ? config2.profiles[name3] : void 0;
37356
37446
  return name3 && profile ? { name: name3, profile } : { name: void 0, profile: void 0 };
37357
37447
  }
37448
+ function linkedFolder({
37449
+ config: config2,
37450
+ directory,
37451
+ profile
37452
+ }) {
37453
+ if (Object.values(config2.sessions ?? {}).includes(profile)) return true;
37454
+ if (config2.profiles[profile]?.delivery) return true;
37455
+ const settings3 = (() => {
37456
+ try {
37457
+ return readFileSync(join4(directory, ".claude", "settings.local.json"), "utf8");
37458
+ } catch {
37459
+ return "";
37460
+ }
37461
+ })();
37462
+ return settings3.includes(LAZE_HOOK_MARKER);
37463
+ }
37464
+ function folderLoginOf({ config: config2, cwd }) {
37465
+ const logins = Object.fromEntries(
37466
+ Object.entries(config2.bindings).filter(
37467
+ ([directory, profile]) => !linkedFolder({ config: config2, directory, profile })
37468
+ )
37469
+ );
37470
+ return boundProfileOf({ bindings: logins, cwd });
37471
+ }
37358
37472
  function isWorktreeRoot({ directory }) {
37359
37473
  const parent = dirname3(directory);
37360
37474
  if (basename2(parent) === ".worktrees") return true;
@@ -40324,9 +40438,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
40324
40438
  function stripTabAndNewline(value) {
40325
40439
  return value.replace(asciiTabOrNewline, "");
40326
40440
  }
40327
- function urlHostnameOk(url2, hostname9) {
40328
- hostname9.lastIndex = 0;
40329
- return hostname9.test(url2.hostname);
40441
+ function urlHostnameOk(url2, hostname10) {
40442
+ hostname10.lastIndex = 0;
40443
+ return hostname10.test(url2.hostname);
40330
40444
  }
40331
40445
  function urlProtocolOk(url2, protocol) {
40332
40446
  protocol.lastIndex = 0;
@@ -42537,7 +42651,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
42537
42651
  var NONE = 0;
42538
42652
  var ASSUMED = 1;
42539
42653
  var PROVEN = 2;
42540
- function isRecursive(inst, stack, resolve28) {
42654
+ function isRecursive(inst, stack, resolve27) {
42541
42655
  const cached2 = recursive.get(inst);
42542
42656
  if (cached2 !== void 0)
42543
42657
  return cached2 ? PROVEN : NONE;
@@ -42547,7 +42661,7 @@ function isRecursive(inst, stack, resolve28) {
42547
42661
  let result2 = NONE;
42548
42662
  const check4 = (child) => {
42549
42663
  if (result2 !== PROVEN && child?._zod) {
42550
- const answer6 = isRecursive(child, stack, resolve28);
42664
+ const answer6 = isRecursive(child, stack, resolve27);
42551
42665
  if (answer6 > result2)
42552
42666
  result2 = answer6;
42553
42667
  }
@@ -42558,7 +42672,7 @@ function isRecursive(inst, stack, resolve28) {
42558
42672
  const desc = Object.getOwnPropertyDescriptor(sh, key);
42559
42673
  if (spread && !desc.enumerable)
42560
42674
  continue;
42561
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve28) : NONE;
42675
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve27) : NONE;
42562
42676
  if (child > answer6)
42563
42677
  answer6 = child;
42564
42678
  }
@@ -42622,7 +42736,7 @@ function isRecursive(inst, stack, resolve28) {
42622
42736
  break;
42623
42737
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
42624
42738
  case "lazy": {
42625
- const inner = def._cachedInner ?? (resolve28 ? inst._zod.innerType : void 0);
42739
+ const inner = def._cachedInner ?? (resolve27 ? inst._zod.innerType : void 0);
42626
42740
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
42627
42741
  break;
42628
42742
  }
@@ -73113,6 +73227,123 @@ function displayFolderOf({ folder, home }) {
73113
73227
  return `~/${below.split(sep).join("/")}`;
73114
73228
  }
73115
73229
 
73230
+ // src/services/claude-project.service.ts
73231
+ import { basename as basename3, isAbsolute, relative as relative2, resolve as resolve2 } from "node:path";
73232
+ function harnessIn({ words }) {
73233
+ const names = words.slice(0, 2).map((word3) => basename3(word3).replace(/\.(js|mjs|cjs)$/, ""));
73234
+ if (names.includes("codex")) return "codex";
73235
+ if (words.some((word3) => word3.includes("@openai/codex"))) return "codex";
73236
+ const claude = words.some((word3) => word3.includes("@anthropic-ai/claude-code"));
73237
+ return claude || names.includes("claude") ? "claude-code" : void 0;
73238
+ }
73239
+ async function nearestHarnessOf({
73240
+ context,
73241
+ from = context.processes.pid
73242
+ }) {
73243
+ let pid = await context.processes.parentOf(from);
73244
+ for (let depth = 0; pid !== void 0 && pid > 1 && depth < 12; depth += 1) {
73245
+ const harness = harnessIn({ words: await context.processes.argsOf(pid) ?? [] });
73246
+ if (harness) return { harness, pid };
73247
+ pid = await context.processes.parentOf(pid);
73248
+ }
73249
+ return void 0;
73250
+ }
73251
+ function holds({ folder, inner }) {
73252
+ const rel = relative2(resolve2(folder), resolve2(inner));
73253
+ return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
73254
+ }
73255
+ async function claudeFoldersOf({
73256
+ context,
73257
+ claudePid
73258
+ }) {
73259
+ const env = context.environment.inherited;
73260
+ const pid = Number(env.CLAUDE_PID);
73261
+ const candidates = [
73262
+ claudePid ? await context.processes.cwdOf(claudePid) : void 0,
73263
+ env.CLAUDE_PROJECT_DIR ? resolve2(env.CLAUDE_PROJECT_DIR) : void 0,
73264
+ pid > 0 ? await context.processes.cwdOf(pid) : void 0
73265
+ ].filter((folder) => Boolean(folder));
73266
+ const holding = candidates.find((folder) => holds({ folder, inner: context.cwd }));
73267
+ if (holding) return { folder: holding, elsewhere: void 0 };
73268
+ return { folder: resolve2(context.cwd), elsewhere: candidates[0] };
73269
+ }
73270
+
73271
+ // src/services/inbox-spool.service.ts
73272
+ import { dirname as dirname4, join as join5 } from "node:path";
73273
+ var PUSH_GRACE_MS = 3 * 6e4;
73274
+ var IN_FLIGHT_MS = 35e3;
73275
+ function fileNameOf({ profile }) {
73276
+ return profile.replace(/[^a-zA-Z0-9_-]/g, "_");
73277
+ }
73278
+ function statePathOf({
73279
+ context,
73280
+ kind: kind2,
73281
+ profile,
73282
+ extension: extension2 = "json"
73283
+ }) {
73284
+ const directory = join5(dirname4(context.environment.configPath), kind2);
73285
+ return join5(directory, `${fileNameOf({ profile })}.${extension2}`);
73286
+ }
73287
+ async function readSpool({ path }) {
73288
+ return await readStateJson({ path }) ?? [];
73289
+ }
73290
+ async function writeSpool({ path, entries }) {
73291
+ await writeStateJson({ path, value: entries });
73292
+ }
73293
+ async function keepTaken({
73294
+ context,
73295
+ profile,
73296
+ messages,
73297
+ pushed = false
73298
+ }) {
73299
+ if (messages.length === 0) return;
73300
+ const path = statePathOf({ context, kind: "spool", profile });
73301
+ const ids = new Set(messages.map((message2) => message2.messageId));
73302
+ const kept = (await readSpool({ path })).filter((entry2) => !ids.has(entry2.message.messageId));
73303
+ const now = context.nowMs();
73304
+ const taken = messages.map((message2) => ({
73305
+ message: message2,
73306
+ takenAt: now,
73307
+ ...pushed ? { pushedAt: now } : {}
73308
+ }));
73309
+ await writeSpool({ path, entries: [...kept, ...taken] });
73310
+ }
73311
+ async function dropFromSpool({
73312
+ context,
73313
+ profile,
73314
+ messageIds
73315
+ }) {
73316
+ if (messageIds.length === 0) return;
73317
+ const path = statePathOf({ context, kind: "spool", profile });
73318
+ const entries = await readSpool({ path });
73319
+ const ids = new Set(messageIds);
73320
+ const kept = entries.filter((entry2) => !ids.has(entry2.message.messageId));
73321
+ if (kept.length !== entries.length) await writeSpool({ path, entries: kept });
73322
+ }
73323
+ async function dueFromSpool({
73324
+ context,
73325
+ profile,
73326
+ seen,
73327
+ pushedToo,
73328
+ settledOnly = false
73329
+ }) {
73330
+ const path = statePathOf({ context, kind: "spool", profile });
73331
+ const entries = await readSpool({ path });
73332
+ const pushed = entries.some((entry2) => entry2.pushedAt !== void 0);
73333
+ const text3 = pushed ? await seen().catch(() => "") : "";
73334
+ const shown2 = entries.filter(
73335
+ (entry2) => entry2.pushedAt !== void 0 && text3.includes(entry2.message.messageId)
73336
+ );
73337
+ await dropFromSpool({
73338
+ context,
73339
+ profile,
73340
+ messageIds: shown2.map((entry2) => entry2.message.messageId)
73341
+ });
73342
+ const late = context.nowMs() - PUSH_GRACE_MS;
73343
+ const settled3 = context.nowMs() - IN_FLIGHT_MS;
73344
+ return entries.filter((entry2) => !shown2.includes(entry2)).filter((entry2) => !settledOnly || entry2.takenAt <= settled3).filter((entry2) => entry2.pushedAt === void 0 || pushedToo && entry2.pushedAt <= late).map((entry2) => entry2.message);
73345
+ }
73346
+
73116
73347
  // src/services/laze-client.service.ts
73117
73348
  var CLI_VERSION_HEADER = "x-laze-cli-version";
73118
73349
  var LazeApiError = class extends Error {
@@ -73262,84 +73493,6 @@ function errorOf({ status: status11, body }) {
73262
73493
  import { createHash } from "node:crypto";
73263
73494
  import { readFile as readFile4 } from "node:fs/promises";
73264
73495
  import { hostname as hostname3 } from "node:os";
73265
-
73266
- // src/services/inbox-spool.service.ts
73267
- import { dirname as dirname4, join as join4 } from "node:path";
73268
- var PUSH_GRACE_MS = 3 * 6e4;
73269
- var IN_FLIGHT_MS = 35e3;
73270
- function fileNameOf({ profile }) {
73271
- return profile.replace(/[^a-zA-Z0-9_-]/g, "_");
73272
- }
73273
- function statePathOf({
73274
- context,
73275
- kind: kind2,
73276
- profile,
73277
- extension: extension2 = "json"
73278
- }) {
73279
- const directory = join4(dirname4(context.environment.configPath), kind2);
73280
- return join4(directory, `${fileNameOf({ profile })}.${extension2}`);
73281
- }
73282
- async function readSpool({ path }) {
73283
- return await readStateJson({ path }) ?? [];
73284
- }
73285
- async function writeSpool({ path, entries }) {
73286
- await writeStateJson({ path, value: entries });
73287
- }
73288
- async function keepTaken({
73289
- context,
73290
- profile,
73291
- messages,
73292
- pushed = false
73293
- }) {
73294
- if (messages.length === 0) return;
73295
- const path = statePathOf({ context, kind: "spool", profile });
73296
- const ids = new Set(messages.map((message2) => message2.messageId));
73297
- const kept = (await readSpool({ path })).filter((entry2) => !ids.has(entry2.message.messageId));
73298
- const now = context.nowMs();
73299
- const taken = messages.map((message2) => ({
73300
- message: message2,
73301
- takenAt: now,
73302
- ...pushed ? { pushedAt: now } : {}
73303
- }));
73304
- await writeSpool({ path, entries: [...kept, ...taken] });
73305
- }
73306
- async function dropFromSpool({
73307
- context,
73308
- profile,
73309
- messageIds
73310
- }) {
73311
- if (messageIds.length === 0) return;
73312
- const path = statePathOf({ context, kind: "spool", profile });
73313
- const entries = await readSpool({ path });
73314
- const ids = new Set(messageIds);
73315
- const kept = entries.filter((entry2) => !ids.has(entry2.message.messageId));
73316
- if (kept.length !== entries.length) await writeSpool({ path, entries: kept });
73317
- }
73318
- async function dueFromSpool({
73319
- context,
73320
- profile,
73321
- seen,
73322
- pushedToo,
73323
- settledOnly = false
73324
- }) {
73325
- const path = statePathOf({ context, kind: "spool", profile });
73326
- const entries = await readSpool({ path });
73327
- const pushed = entries.some((entry2) => entry2.pushedAt !== void 0);
73328
- const text3 = pushed ? await seen().catch(() => "") : "";
73329
- const shown2 = entries.filter(
73330
- (entry2) => entry2.pushedAt !== void 0 && text3.includes(entry2.message.messageId)
73331
- );
73332
- await dropFromSpool({
73333
- context,
73334
- profile,
73335
- messageIds: shown2.map((entry2) => entry2.message.messageId)
73336
- });
73337
- const late = context.nowMs() - PUSH_GRACE_MS;
73338
- const settled3 = context.nowMs() - IN_FLIGHT_MS;
73339
- return entries.filter((entry2) => !shown2.includes(entry2)).filter((entry2) => !settledOnly || entry2.takenAt <= settled3).filter((entry2) => entry2.pushedAt === void 0 || pushedToo && entry2.pushedAt <= late).map((entry2) => entry2.message);
73340
- }
73341
-
73342
- // src/services/machine-report.service.ts
73343
73496
  async function reportMachine({
73344
73497
  context,
73345
73498
  profile,
@@ -73411,14 +73564,20 @@ async function turnTokenOf({ context }) {
73411
73564
  () => ""
73412
73565
  );
73413
73566
  }
73414
- function harnessSessionKeyOf({ context }) {
73567
+ async function harnessSessionKeyOf({ context }) {
73415
73568
  const { harness, inherited } = context.environment;
73416
73569
  const ids = {
73417
73570
  "claude-code": inherited.CLAUDE_CODE_SESSION_ID,
73418
73571
  codex: inherited.CODEX_THREAD_ID
73419
73572
  };
73420
73573
  const sessionId = ids[harness];
73421
- return sessionId ? sessionKeyOf({ session: { harness, sessionId } }) : void 0;
73574
+ if (sessionId) return sessionKeyOf({ session: { harness, sessionId } });
73575
+ if (harness !== "claude-code") return void 0;
73576
+ const nearest = await nearestHarnessOf({ context }).catch(() => void 0);
73577
+ if (nearest?.harness !== "claude-code") return void 0;
73578
+ const path = statePathOf({ context, kind: "sessions", profile: String(nearest.pid) });
73579
+ const noted = await readStateJson({ path });
73580
+ return noted ? sessionKeyOf({ session: noted }) : void 0;
73422
73581
  }
73423
73582
  async function profileKindOf({
73424
73583
  context,
@@ -73428,7 +73587,7 @@ async function profileKindOf({
73428
73587
  config: await context.store.read(),
73429
73588
  flag: flagText({ args, name: "profile" }) || void 0,
73430
73589
  environment: context.environment.profile,
73431
- session: harnessSessionKeyOf({ context }),
73590
+ session: await harnessSessionKeyOf({ context }),
73432
73591
  cwd: context.cwd
73433
73592
  });
73434
73593
  return chosen.profile?.kind;
@@ -73442,7 +73601,7 @@ async function signedIn({
73442
73601
  config: config2,
73443
73602
  flag: flagText({ args, name: "profile" }) || void 0,
73444
73603
  environment: context.environment.profile,
73445
- session: harnessSessionKeyOf({ context }),
73604
+ session: await harnessSessionKeyOf({ context }),
73446
73605
  cwd: context.cwd
73447
73606
  });
73448
73607
  if (!chosen.profile)
@@ -73826,7 +73985,7 @@ async function copyAgent({
73826
73985
 
73827
73986
  // src/services/agent-commands.service.ts
73828
73987
  import { mkdir as mkdir6, readFile as readFile12, writeFile as writeFile3 } from "node:fs/promises";
73829
- import { join as join21, resolve as resolve5 } from "node:path";
73988
+ import { join as join22, resolve as resolve4 } from "node:path";
73830
73989
 
73831
73990
  // src/rules/link-format.rules.ts
73832
73991
  function linkOf({ url: url2, base }) {
@@ -73940,85 +74099,6 @@ ${lines2.join("\n")}
73940
74099
  `;
73941
74100
  }
73942
74101
 
73943
- // src/rules/hook-settings.rules.ts
73944
- var LAZE_HOOK_MARKER = "laze-cli-hook";
73945
- var HOOK_TIMEOUTS = { Stop: 30, PreToolUse: 5, SessionStart: 30 };
73946
- var TIMEOUTS = HOOK_TIMEOUTS;
73947
- var WAIT_HOOK_TIMEOUT_SECONDS = 7 * 24 * 60 * 60;
73948
- function withHooks({
73949
- hooks,
73950
- event,
73951
- added
73952
- }) {
73953
- const current3 = Array.isArray(hooks[event]) ? hooks[event] : [];
73954
- const others = current3.filter(
73955
- (entry2) => !entry2.hooks?.some((hook) => hook.command?.includes(LAZE_HOOK_MARKER))
73956
- );
73957
- hooks[event] = [...others, ...added.map((hook) => ({ hooks: [hook] }))];
73958
- }
73959
- function withLazeHooks({
73960
- settings: settings3,
73961
- stopCommand,
73962
- waitCommand,
73963
- preToolCommand
73964
- }) {
73965
- const hooks = { ...settings3.hooks };
73966
- withHooks({
73967
- hooks,
73968
- event: "Stop",
73969
- added: [
73970
- { type: "command", command: stopCommand, timeout: TIMEOUTS.Stop },
73971
- {
73972
- type: "command",
73973
- command: waitCommand,
73974
- timeout: WAIT_HOOK_TIMEOUT_SECONDS,
73975
- async: true,
73976
- asyncRewake: true
73977
- }
73978
- ]
73979
- });
73980
- withHooks({
73981
- hooks,
73982
- event: "SessionStart",
73983
- added: [
73984
- {
73985
- type: "command",
73986
- command: waitCommand,
73987
- timeout: WAIT_HOOK_TIMEOUT_SECONDS,
73988
- async: true,
73989
- asyncRewake: true
73990
- }
73991
- ]
73992
- });
73993
- withHooks({
73994
- hooks,
73995
- event: "PreToolUse",
73996
- added: [{ type: "command", command: preToolCommand, timeout: TIMEOUTS.PreToolUse }]
73997
- });
73998
- return { ...settings3, hooks };
73999
- }
74000
- function hookCommand({
74001
- program,
74002
- profile,
74003
- hook
74004
- }) {
74005
- const quote4 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
74006
- const words = [...program, "hook", hook, "--profile", profile].map(quote4).join(" ");
74007
- return `${words} # ${LAZE_HOOK_MARKER}`;
74008
- }
74009
- function holdsOurs({ settings: settings3, event }) {
74010
- const hooks = settings3.hooks ?? {};
74011
- return Array.isArray(hooks[event]) && hooks[event].some(
74012
- (entry2) => entry2.hooks?.some((hook) => hook.command?.includes(LAZE_HOOK_MARKER))
74013
- );
74014
- }
74015
- function lacksSessionStartWaiter({ settings: settings3 }) {
74016
- return holdsOurs({ settings: settings3, event: "Stop" }) && !holdsOurs({ settings: settings3, event: "SessionStart" });
74017
- }
74018
- function hasLazeHooks({ settings: settings3 }) {
74019
- return holdsOurs({ settings: settings3, event: "Stop" });
74020
- }
74021
-
74022
74102
  // src/rules/inbox-format.rules.ts
74023
74103
  function whereOf(message2) {
74024
74104
  if (message2.channelKind === "dm" || message2.channelKind === "group") return "a direct message";
@@ -75092,6 +75172,27 @@ function waitsForLinesOf({ posted }) {
75092
75172
  }).join("");
75093
75173
  }
75094
75174
 
75175
+ // src/rules/post-request-id.rules.ts
75176
+ import { createHash as createHash2 } from "node:crypto";
75177
+ var POST_REQUEST_ID_HEADER = "x-laze-request-id";
75178
+ var POST_REPEAT_WINDOW_MS = 15 * 6e4;
75179
+ function postRequestIdOf({
75180
+ path,
75181
+ payload,
75182
+ nowMs: nowMs2
75183
+ }) {
75184
+ const { attachmentIds: _files, ...said } = payload;
75185
+ const window2 = Math.floor(nowMs2 / POST_REPEAT_WINDOW_MS);
75186
+ const digest = createHash2("sha256").update(
75187
+ JSON.stringify([
75188
+ path,
75189
+ window2,
75190
+ Object.entries(said).toSorted(([a], [b]) => a.localeCompare(b))
75191
+ ])
75192
+ ).digest("base64url");
75193
+ return `p${digest.slice(0, 40)}`;
75194
+ }
75195
+
75095
75196
  // src/rules/search-format.rules.ts
75096
75197
  var SNIPPET_CHARACTERS = 160;
75097
75198
  var TOKEN = /<@(person|agent):([A-Za-z0-9_-]+)>|<!(channel|here)>|<#([A-Za-z0-9_-]{1,64})>/g;
@@ -75243,12 +75344,12 @@ function formatSearch({
75243
75344
 
75244
75345
  // src/services/claude-turn.service.ts
75245
75346
  import { rm as rm3 } from "node:fs/promises";
75246
- import { dirname as dirname7, join as join8 } from "node:path";
75347
+ import { dirname as dirname9, join as join11 } from "node:path";
75247
75348
 
75248
75349
  // src/services/harness-session.service.ts
75249
- import { open as open3, readdir as readdir3, readFile as readFile6, stat as stat3 } from "node:fs/promises";
75350
+ import { open as open3, readdir as readdir3, stat as stat3 } from "node:fs/promises";
75250
75351
  import { homedir as homedir2, hostname as hostname4 } from "node:os";
75251
- import { dirname as dirname6, join as join6 } from "node:path";
75352
+ import { dirname as dirname7, join as join8 } from "node:path";
75252
75353
 
75253
75354
  // src/rules/claude-subagent.rules.ts
75254
75355
  function lastCallAtOf({ text: text3, command }) {
@@ -75341,50 +75442,22 @@ function launchEnvOf({
75341
75442
  return picked;
75342
75443
  }
75343
75444
 
75344
- // src/services/claude-project.service.ts
75345
- import { basename as basename3, isAbsolute, relative as relative2, resolve as resolve2 } from "node:path";
75346
- function harnessIn({ words }) {
75347
- const names = words.slice(0, 2).map((word3) => basename3(word3).replace(/\.(js|mjs|cjs)$/, ""));
75348
- if (names.includes("codex")) return "codex";
75349
- if (words.some((word3) => word3.includes("@openai/codex"))) return "codex";
75350
- const claude = words.some((word3) => word3.includes("@anthropic-ai/claude-code"));
75351
- return claude || names.includes("claude") ? "claude-code" : void 0;
75352
- }
75353
- async function nearestHarnessOf({
75354
- context,
75355
- from = context.processes.pid
75356
- }) {
75357
- let pid = await context.processes.parentOf(from);
75358
- for (let depth = 0; pid !== void 0 && pid > 1 && depth < 12; depth += 1) {
75359
- const harness = harnessIn({ words: await context.processes.argsOf(pid) ?? [] });
75360
- if (harness) return { harness, pid };
75361
- pid = await context.processes.parentOf(pid);
75362
- }
75363
- return void 0;
75364
- }
75365
- function holds({ folder, inner }) {
75366
- const rel = relative2(resolve2(folder), resolve2(inner));
75367
- return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
75368
- }
75369
- async function claudeFoldersOf({
75370
- context,
75371
- claudePid
75372
- }) {
75373
- const env = context.environment.inherited;
75374
- const pid = Number(env.CLAUDE_PID);
75375
- const candidates = [
75376
- claudePid ? await context.processes.cwdOf(claudePid) : void 0,
75377
- env.CLAUDE_PROJECT_DIR ? resolve2(env.CLAUDE_PROJECT_DIR) : void 0,
75378
- pid > 0 ? await context.processes.cwdOf(pid) : void 0
75379
- ].filter((folder) => Boolean(folder));
75380
- const holding = candidates.find((folder) => holds({ folder, inner: context.cwd }));
75381
- if (holding) return { folder: holding, elsewhere: void 0 };
75382
- return { folder: resolve2(context.cwd), elsewhere: candidates[0] };
75445
+ // src/services/connect-log.service.ts
75446
+ import { appendFile, mkdir as mkdir2 } from "node:fs/promises";
75447
+ import { dirname as dirname5, join as join6 } from "node:path";
75448
+ async function logDelivery({ context, line }) {
75449
+ const folder = join6(dirname5(context.environment.configPath), "connect");
75450
+ const at8 = Temporal3.Instant.fromEpochMilliseconds(context.nowMs());
75451
+ const stamped = `${at8.toString({ smallestUnit: "second" })} ${line}
75452
+ `;
75453
+ context.out(stamped);
75454
+ await mkdir2(folder, { recursive: true, mode: 448 });
75455
+ await appendFile(join6(folder, "delivery.log"), stamped, { mode: 384 });
75383
75456
  }
75384
75457
 
75385
75458
  // src/services/session-notes.service.ts
75386
75459
  import { readdir as readdir2, rm as rm2, stat as stat2 } from "node:fs/promises";
75387
- import { dirname as dirname5, join as join5 } from "node:path";
75460
+ import { dirname as dirname6, join as join7 } from "node:path";
75388
75461
  function notePathOf({ context, pid }) {
75389
75462
  return statePathOf({ context, kind: "sessions", profile: String(pid) });
75390
75463
  }
@@ -75431,13 +75504,13 @@ async function sessionNotesOf({
75431
75504
  context,
75432
75505
  tell = true
75433
75506
  }) {
75434
- const folder = dirname5(notePathOf({ context, pid: 1 }));
75507
+ const folder = dirname6(notePathOf({ context, pid: 1 }));
75435
75508
  const files2 = await readdir2(folder).catch(() => []);
75436
75509
  const notes = [];
75437
75510
  const dropped = [];
75438
75511
  for (const file4 of files2) {
75439
75512
  const pid = Number(file4.replace(/\.json$/, ""));
75440
- const path = join5(folder, file4);
75513
+ const path = join7(folder, file4);
75441
75514
  const note = pid ? await readStateJson({ path }) : void 0;
75442
75515
  if (!note) continue;
75443
75516
  const standing = await standingOf({ context, pid, note });
@@ -75509,24 +75582,51 @@ async function currentSessionOf({
75509
75582
  const path = statePathOf({ context, kind: "sessions", profile: String(nearest.pid) });
75510
75583
  return readStateJson({ path });
75511
75584
  }
75585
+ async function sessionAgentOf({
75586
+ context,
75587
+ session
75588
+ }) {
75589
+ if (!session) return void 0;
75590
+ const config2 = await context.store.read();
75591
+ const bound = config2.sessions?.[sessionKeyOf({ session })];
75592
+ const profile = bound ? config2.profiles[bound] : void 0;
75593
+ return bound && profile?.kind === "agent" && !profile.migrated ? bound : void 0;
75594
+ }
75512
75595
  async function sessionProfileArgs({
75513
75596
  context,
75514
75597
  args,
75515
- session,
75516
- binds = true
75598
+ session
75517
75599
  }) {
75518
- if (!session) return args;
75519
- const key = sessionKeyOf({ session });
75600
+ if (flagText({ args, name: "profile" })) return args;
75601
+ const bound = await sessionAgentOf({ context, session });
75602
+ return bound ? { ...args, flags: { ...args.flags, profile: bound } } : args;
75603
+ }
75604
+ async function carryOverClear({
75605
+ context,
75606
+ claudePid,
75607
+ session
75608
+ }) {
75609
+ if (!session || !claudePid) return void 0;
75610
+ const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
75611
+ const before = await readStateJson({ path });
75612
+ if (!before || before.sessionId === session.sessionId) return void 0;
75613
+ const profile = await sessionAgentOf({ context, session: before });
75614
+ if (!profile) return void 0;
75520
75615
  const config2 = await context.store.read();
75521
- const bound = config2.sessions?.[key];
75522
- if (bound && config2.profiles[bound]) {
75523
- return { ...args, flags: { ...args.flags, profile: bound } };
75524
- }
75525
- const own2 = flagText({ args, name: "profile" });
75526
- if (binds && !args.flags.plugin && own2 && config2.profiles[own2]?.kind === "agent") {
75527
- await context.store.bindSession({ session: key, profile: own2 });
75528
- }
75529
- return args;
75616
+ const own2 = config2.profiles[profile];
75617
+ if (!own2) return void 0;
75618
+ const client = LazeClient.create({
75619
+ baseUrl: own2.url,
75620
+ token: own2.token,
75621
+ fetcher: context.fetcher
75622
+ });
75623
+ await forSession({ client, session }).post("/api/agents/me/bind", {});
75624
+ await context.store.bindSession({ session: sessionKeyOf({ session }), profile });
75625
+ await logDelivery({
75626
+ context: { ...context, out: () => void 0 },
75627
+ line: `${profile}: /clear moved the agent from ${sessionKeyOf({ session: before })} to ${sessionKeyOf({ session })}`
75628
+ }).catch(() => void 0);
75629
+ return profile;
75530
75630
  }
75531
75631
  async function rushListingOf({ context }) {
75532
75632
  let listed = "";
@@ -75567,14 +75667,14 @@ async function claudeTranscriptOf({
75567
75667
  sessionId
75568
75668
  }) {
75569
75669
  const inherited = context.environment.inherited;
75570
- const root = join6(
75571
- inherited.CLAUDE_CONFIG_DIR || join6(inherited.HOME || homedir2(), ".claude"),
75670
+ const root = join8(
75671
+ inherited.CLAUDE_CONFIG_DIR || join8(inherited.HOME || homedir2(), ".claude"),
75572
75672
  "projects"
75573
75673
  );
75574
75674
  const folders = await readdir3(root).catch(() => []);
75575
75675
  const found = await Promise.all(
75576
75676
  folders.map(async (folder) => {
75577
- const path = join6(root, folder, `${sessionId}.jsonl`);
75677
+ const path = join8(root, folder, `${sessionId}.jsonl`);
75578
75678
  return stat3(path).then(
75579
75679
  (info) => info.isFile() ? [{ path, at: info.mtimeMs }] : [],
75580
75680
  () => []
@@ -75602,11 +75702,11 @@ async function runsInSubagent({ context, command }) {
75602
75702
  if (!sessionId) return false;
75603
75703
  const { path } = await claudeTranscriptOf({ context, sessionId });
75604
75704
  if (!path) return false;
75605
- const folder = join6(dirname6(path), sessionId, "subagents");
75705
+ const folder = join8(dirname7(path), sessionId, "subagents");
75606
75706
  const files2 = await readdir3(folder).catch(() => []);
75607
75707
  const subagents = await Promise.all(
75608
75708
  files2.filter((file4) => file4.endsWith(".jsonl")).map(
75609
- async (file4) => lastCallAtOf({ text: await tailOf({ path: join6(folder, file4) }), command })
75709
+ async (file4) => lastCallAtOf({ text: await tailOf({ path: join8(folder, file4) }), command })
75610
75710
  )
75611
75711
  );
75612
75712
  const session = lastCallAtOf({ text: await tailOf({ path }), command });
@@ -75623,96 +75723,142 @@ async function refuseInSubagent({
75623
75723
  "This runs inside a Claude Code subagent, which shares its parent's session: it would take that session. Run it in the session itself, or pass --session <id>."
75624
75724
  );
75625
75725
  }
75626
- function notBoundText({
75627
- meta: meta3,
75628
- agent: agent3,
75629
- configPath
75630
- }) {
75631
- const who = `${agent3 ? `"${agent3}"` : "this agent"} (config ${configPath})`;
75632
- return `Laze: ${who} listens in another session${meta3.bound ? `: ${meta3.bound}` : ""}. Create a new Laze agent with this session: laze agent request. Or move this agent here: laze agent bind.`;
75633
- }
75634
75726
  function boundMetaOf({ error: error63 }) {
75635
75727
  if (!(error63 instanceof LazeApiError) || error63.code !== "session_not_bound") return void 0;
75636
75728
  return error63.meta ?? {};
75637
75729
  }
75638
- async function takeOverHere({
75730
+ async function droppedBinding({
75639
75731
  context,
75640
- client,
75641
75732
  session,
75642
- meta: meta3,
75733
+ error: error63,
75643
75734
  profile
75644
75735
  }) {
75645
- if (!session || !meta3.session || meta3.host !== session.host) return false;
75646
- const sessions = (await context.store.read()).sessions ?? {};
75647
- const theirs = sessions[meta3.session];
75648
- const mine5 = sessions[sessionKeyOf({ session })] === profile;
75649
- const stale = mine5 && theirs !== void 0 && theirs !== profile;
75650
- const claudePid = (await nearestHarnessOf({ context }))?.pid;
75651
- if (!stale && await liveElsewhere({ context, key: meta3.session, claudePid })) return false;
75652
- await forSession({ client, session }).post("/api/agents/me/bind", {});
75736
+ const meta3 = boundMetaOf({ error: error63 });
75737
+ if (!meta3) return false;
75738
+ if (!session) return true;
75739
+ const key = sessionKeyOf({ session });
75740
+ if (await context.store.unbindSession({ session: key, profile })) {
75741
+ await logDelivery({
75742
+ context: { ...context, out: () => void 0 },
75743
+ line: `${profile}: Laze binds the agent to ${meta3.bound ?? meta3.session ?? "another session"}, so ${key} no longer listens for it`
75744
+ }).catch(() => void 0);
75745
+ }
75653
75746
  return true;
75654
75747
  }
75655
- async function notBoundNotice({
75748
+
75749
+ // src/services/plugin-hook.service.ts
75750
+ import { readFile as readFile7 } from "node:fs/promises";
75751
+ import { join as join10 } from "node:path";
75752
+
75753
+ // src/services/session-migration.service.ts
75754
+ import { readFile as readFile6 } from "node:fs/promises";
75755
+ import { hostname as hostname5 } from "node:os";
75756
+ import { dirname as dirname8, join as join9 } from "node:path";
75757
+ var START_EVERY_MS = 10 * 60 * 1e3;
75758
+ function needsMigration({ config: config2 }) {
75759
+ return !config2.sessionsMigratedAt && Object.keys(config2.bindings).length > 0;
75760
+ }
75761
+ async function migrateLaterIfNeeded({ context }) {
75762
+ if (!needsMigration({ config: await context.store.read() })) return;
75763
+ const marker = statePathOf({ context, kind: "told", profile: "sessions-migration" });
75764
+ const last = Number(await readFile6(marker, "utf8").catch(() => "0"));
75765
+ if (context.nowMs() - last < START_EVERY_MS) return;
75766
+ await writeStateText({ path: marker, text: String(context.nowMs()) });
75767
+ const logPath = join9(dirname8(context.environment.configPath), "connect", "migrate.log");
75768
+ context.processes.spawnDetached({
75769
+ argv: [...context.program, "agent", "sessions", "--migrate"],
75770
+ logPath
75771
+ });
75772
+ }
75773
+ async function boundOf({ context, profile }) {
75774
+ const entry2 = (await context.store.read()).profiles[profile];
75775
+ if (!entry2) return "unknown";
75776
+ const client = LazeClient.create({
75777
+ baseUrl: entry2.url,
75778
+ token: entry2.token,
75779
+ fetcher: (input2, init) => context.fetcher(input2, { ...init, signal: AbortSignal.timeout(1e4) })
75780
+ });
75781
+ const waiting = await client.get("/api/agents/me/inbox/waiting").catch(() => void 0);
75782
+ if (!waiting) return "unknown";
75783
+ const session = waiting.session;
75784
+ return session ? { key: `${session.harness}:${session.sessionId}`, host: session.host } : null;
75785
+ }
75786
+ async function settleProfile({
75656
75787
  context,
75657
- client,
75658
- session,
75659
- error: error63,
75660
- profile
75788
+ profile,
75789
+ bound
75661
75790
  }) {
75662
- if (!(error63 instanceof LazeApiError) || error63.code !== "session_not_bound") return void 0;
75663
- const meta3 = error63.meta ?? {};
75664
- if (client && await takeOverHere({ context, client, session, meta: meta3, profile })) {
75665
- return { notice: void 0, rebound: true };
75666
- }
75667
- const key = session ? sessionKeyOf({ session }) : "unknown";
75668
- const path = statePathOf({ context, kind: "told", profile: key });
75669
- const told = await readFile6(path, "utf8").then(
75670
- () => true,
75671
- () => false
75791
+ if (bound === "unknown") return `${profile}: Laze did not say where it listens; left as it is`;
75792
+ const here = bound && bound.host === hostname5() ? bound.key : void 0;
75793
+ return context.store.update((config2) => {
75794
+ const sessions = config2.sessions ?? {};
75795
+ const mine5 = Object.keys(sessions).filter((key) => sessions[key] === profile);
75796
+ if (bound === null) {
75797
+ return { result: `${profile}: bound to no session in Laze; ${mine5.length} kept` };
75798
+ }
75799
+ const taken = here && sessions[here] && sessions[here] !== profile;
75800
+ const kept = Object.fromEntries(
75801
+ Object.entries(sessions).filter(([key, name3]) => name3 !== profile || key === here)
75802
+ );
75803
+ const next = here && !taken ? { ...kept, [here]: profile } : kept;
75804
+ const where = here ?? `${bound.key} on ${bound.host}`;
75805
+ const line = taken ? `${profile}: Laze binds it to ${here}, which this machine binds to ${sessions[here]}; left unbound here` : `${profile}: listens in ${where}; dropped ${mine5.filter((key) => key !== here).length} other sessions`;
75806
+ return { result: line, config: { ...config2, sessions: next } };
75807
+ });
75808
+ }
75809
+ async function migrateSessions({ context }) {
75810
+ const config2 = await context.store.read();
75811
+ const agents2 = Object.entries(config2.profiles).filter(
75812
+ ([, one]) => one.kind === "agent" && !one.migrated && !one.refused
75672
75813
  );
75673
- if (told) return { notice: void 0 };
75674
- await writeStateText({ path, text: String(context.nowMs()) });
75675
- const agent3 = (await context.store.read()).profiles[profile]?.name;
75676
- return {
75677
- notice: notBoundText({ meta: meta3, agent: agent3, configPath: context.environment.configPath })
75678
- };
75814
+ const lines2 = [];
75815
+ for (const [profile] of agents2) {
75816
+ const bound = await boundOf({ context, profile });
75817
+ lines2.push(await settleProfile({ context, profile, bound }));
75818
+ }
75819
+ const dropped = await context.store.update((current3) => {
75820
+ const gone = Object.entries(current3.bindings).filter(
75821
+ ([directory, profile]) => linkedFolder({ config: config2, directory, profile })
75822
+ );
75823
+ const bindings = Object.fromEntries(
75824
+ Object.entries(current3.bindings).filter(
75825
+ ([directory]) => gone.every(([other]) => other !== directory)
75826
+ )
75827
+ );
75828
+ const next = { ...current3, bindings, sessionsMigratedAt: context.nowMs() };
75829
+ return { result: gone, config: next };
75830
+ });
75831
+ for (const [directory, profile] of dropped) {
75832
+ lines2.push(`${profile}: dropped the folder binding of ${directory}`);
75833
+ }
75834
+ for (const line of lines2) {
75835
+ await logDelivery({ context: { ...context, out: () => void 0 }, line: `migrate ${line}` });
75836
+ }
75837
+ return lines2;
75679
75838
  }
75680
75839
 
75681
75840
  // src/services/plugin-hook.service.ts
75682
- import { readFile as readFile7 } from "node:fs/promises";
75683
- import { join as join7 } from "node:path";
75684
75841
  async function agentProfileHere({
75685
75842
  context,
75686
- args,
75687
- session,
75688
- claudePid
75843
+ session
75689
75844
  }) {
75690
- const config2 = await context.store.read();
75691
- const cwd = (claudePid ? await context.processes.cwdOf(claudePid) : void 0) ?? (context.environment.inherited.CLAUDE_PROJECT_DIR || context.cwd);
75692
- const folder = boundProfileOf({ bindings: config2.bindings, cwd });
75693
- if (!folder && !session) return void 0;
75694
- const asked = { ...args, flags: { ...args.flags, ...folder ? { profile: folder } : {} } };
75695
- const name3 = flagText({
75696
- args: await sessionProfileArgs({ context, args: asked, session, binds: false }),
75697
- name: "profile"
75698
- });
75699
- const profile = name3 ? config2.profiles[name3] : void 0;
75700
- return name3 && profile?.kind === "agent" && !profile.migrated ? name3 : void 0;
75845
+ return sessionAgentOf({ context, session });
75701
75846
  }
75702
75847
  async function projectHooksHere({ context }) {
75703
75848
  const directory = context.environment.inherited.CLAUDE_PROJECT_DIR || context.cwd;
75704
- const path = join7(directory, ".claude", "settings.local.json");
75849
+ const path = join10(directory, ".claude", "settings.local.json");
75705
75850
  return readFile7(path, "utf8").then((text3) => hasLazeHooks({ settings: JSON.parse(text3) })).catch(() => false);
75706
75851
  }
75707
75852
  async function pluginHookArgs({
75708
75853
  context,
75709
75854
  args,
75710
75855
  session,
75711
- claudePid
75856
+ claudePid,
75857
+ source
75712
75858
  }) {
75713
- if (!args.flags.plugin) return args;
75714
- if (await projectHooksHere({ context })) return void 0;
75715
- const profile = await agentProfileHere({ context, args, session, claudePid });
75859
+ await migrateLaterIfNeeded({ context }).catch(() => void 0);
75860
+ if (args.flags.plugin && await projectHooksHere({ context })) return void 0;
75861
+ const profile = await agentProfileHere({ context, session }) ?? (source === "clear" ? await carryOverClear({ context, claudePid, session }).catch(() => void 0) : void 0);
75716
75862
  return profile ? { ...args, flags: { ...args.flags, profile } } : void 0;
75717
75863
  }
75718
75864
 
@@ -75720,7 +75866,7 @@ async function pluginHookArgs({
75720
75866
  var PRE_TOOL_TIMEOUT_MS = 3e3;
75721
75867
  function statePath({ context, agent: agent3 }) {
75722
75868
  const safe = agent3.replace(/[^a-zA-Z0-9_-]/g, "_");
75723
- return join8(dirname7(context.environment.configPath), "turns", `${safe}.json`);
75869
+ return join11(dirname9(context.environment.configPath), "turns", `${safe}.json`);
75724
75870
  }
75725
75871
  async function readState({ context, agent: agent3 }) {
75726
75872
  return readStateJson({ path: statePath({ context, agent: agent3 }) });
@@ -76374,6 +76520,14 @@ function turnAnswersOf({ context }) {
76374
76520
  var FILES_USAGE = "[--image <path|url|fileId>]... [--file <path|url|fileId>]... (at most 6)";
76375
76521
  var POST_USAGE = `Usage: laze post <channel> <text|-> [--thread <id>] ${FILES_USAGE} [--at <time> [--tz <zone>]] [--json]`;
76376
76522
  var REPLY_USAGE = `Usage: laze reply <message-id> <text|-> [--new-thread] [--also-channel] ${FILES_USAGE} [--at <time> [--tz <zone>]]`;
76523
+ function keyedPost({
76524
+ client,
76525
+ path,
76526
+ payload
76527
+ }) {
76528
+ const requestId = postRequestIdOf({ path, payload, nowMs: nowInstant().epochMilliseconds });
76529
+ return client.withHeaders({ [POST_REQUEST_ID_HEADER]: requestId }).post(path, payload);
76530
+ }
76377
76531
  async function filesOf({
76378
76532
  context,
76379
76533
  args,
@@ -76413,12 +76567,16 @@ async function post({
76413
76567
  const target = { channel, ...thread2 ? { threadRootId: thread2 } : {} };
76414
76568
  return scheduleMessage({ context, args, client, at: at8, target, body });
76415
76569
  }
76416
- const posted = await client.post("/api/agents/me/messages", {
76417
- channel,
76418
- body,
76419
- ...thread2 ? { threadRootId: thread2 } : {},
76420
- ...files2,
76421
- ...turnAnswersOf({ context })
76570
+ const posted = await keyedPost({
76571
+ client,
76572
+ path: "/api/agents/me/messages",
76573
+ payload: {
76574
+ channel,
76575
+ body,
76576
+ ...thread2 ? { threadRootId: thread2 } : {},
76577
+ ...files2,
76578
+ ...turnAnswersOf({ context })
76579
+ }
76422
76580
  });
76423
76581
  if (args.flags.json) {
76424
76582
  context.out(`${JSON.stringify(posted, null, 2)}
@@ -76454,14 +76612,18 @@ async function reply({
76454
76612
  if (at8) {
76455
76613
  return scheduleMessage({ context, args, client, at: at8, target: { replyTo: messageId }, body });
76456
76614
  }
76457
- const posted = await client.post("/api/agents/me/replies", {
76458
- messageId,
76459
- body,
76460
- ...channel ? { channel } : {},
76461
- ...args.flags["new-thread"] === true ? { thread: true } : {},
76462
- ...args.flags["also-channel"] === true ? { alsoInChannel: true } : {},
76463
- ...files2,
76464
- ...turnAnswersOf({ context })
76615
+ const posted = await keyedPost({
76616
+ client,
76617
+ path: "/api/agents/me/replies",
76618
+ payload: {
76619
+ messageId,
76620
+ body,
76621
+ ...channel ? { channel } : {},
76622
+ ...args.flags["new-thread"] === true ? { thread: true } : {},
76623
+ ...args.flags["also-channel"] === true ? { alsoInChannel: true } : {},
76624
+ ...files2,
76625
+ ...turnAnswersOf({ context })
76626
+ }
76465
76627
  });
76466
76628
  await dropFromSpool({ context, profile: name3, messageIds: [messageId] }).catch(() => void 0);
76467
76629
  context.out(
@@ -76640,9 +76802,9 @@ var ListenerBackoff = class {
76640
76802
  };
76641
76803
 
76642
76804
  // src/services/connect-service.service.ts
76643
- import { createHash as createHash2 } from "node:crypto";
76805
+ import { createHash as createHash3 } from "node:crypto";
76644
76806
  import { mkdir as mkdir3, rm as rm5, writeFile } from "node:fs/promises";
76645
- import { dirname as dirname13, join as join15 } from "node:path";
76807
+ import { dirname as dirname14, join as join17 } from "node:path";
76646
76808
 
76647
76809
  // src/rules/connect-service.rules.ts
76648
76810
  function systemdWordOf(word3) {
@@ -76721,20 +76883,6 @@ function launchAgentOf({
76721
76883
  function codexQueueFailureOf({ stderr: stderr2 }) {
76722
76884
  return /no rollout found|thread not found|unknown thread/i.test(stderr2) ? "thread_unknown" : "failed";
76723
76885
  }
76724
- function rolloutSessionOf({
76725
- firstLine
76726
- }) {
76727
- try {
76728
- const parsed = JSON.parse(firstLine);
76729
- const { id: id8, cwd } = parsed.payload ?? {};
76730
- if (parsed.type !== "session_meta" || typeof id8 !== "string" || typeof cwd !== "string") {
76731
- return void 0;
76732
- }
76733
- return { id: id8, cwd };
76734
- } catch {
76735
- return void 0;
76736
- }
76737
- }
76738
76886
  function userTextOf({ parsed }) {
76739
76887
  const payload = parsed.payload ?? {};
76740
76888
  if (parsed.type === "event_msg" && payload.type === "user_message") {
@@ -76765,24 +76913,24 @@ function rolloutEventOf({
76765
76913
 
76766
76914
  // src/services/connect-delivery.service.ts
76767
76915
  import { rm as rm4, stat as stat5 } from "node:fs/promises";
76768
- import { homedir as homedir3, hostname as hostname5 } from "node:os";
76769
- import { dirname as dirname12, join as join14 } from "node:path";
76916
+ import { homedir as homedir3, hostname as hostname6 } from "node:os";
76917
+ import { dirname as dirname13, join as join16 } from "node:path";
76770
76918
 
76771
76919
  // src/services/codex-turn-watch.service.ts
76772
76920
  import { open as open4, readdir as readdir4 } from "node:fs/promises";
76773
- import { basename as basename5, join as join9 } from "node:path";
76921
+ import { basename as basename5, join as join12 } from "node:path";
76774
76922
  var READ_MS = 1500;
76775
76923
  var KEEP_WORKING_MS = 3e4;
76776
76924
  async function codexRolloutPathOf({
76777
76925
  codexHome,
76778
76926
  threadId
76779
76927
  }) {
76780
- const root = join9(codexHome, "sessions");
76928
+ const root = join12(codexHome, "sessions");
76781
76929
  const files2 = await readdir4(root, { recursive: true }).catch(() => []);
76782
76930
  const file4 = files2.find(
76783
76931
  (name3) => basename5(name3).startsWith("rollout-") && name3.endsWith(`-${threadId}.jsonl`)
76784
76932
  );
76785
- return file4 ? join9(root, file4) : void 0;
76933
+ return file4 ? join12(root, file4) : void 0;
76786
76934
  }
76787
76935
  function rolloutPathOf({ delivery }) {
76788
76936
  return codexRolloutPathOf({ codexHome: delivery.codexHome, threadId: delivery.threadId });
@@ -76871,7 +77019,7 @@ var CodexTurnWatch = class _CodexTurnWatch {
76871
77019
  };
76872
77020
 
76873
77021
  // src/services/mcp-relay.service.ts
76874
- import { dirname as dirname8, join as join10 } from "node:path";
77022
+ import { dirname as dirname10, join as join13 } from "node:path";
76875
77023
 
76876
77024
  // ../../node_modules/.pnpm/ws@8.21.3_bufferutil@4.1.0/node_modules/ws/wrapper.mjs
76877
77025
  var import_stream = __toESM(require_stream(), 1);
@@ -77207,7 +77355,7 @@ var STOPS = /* @__PURE__ */ new Map([
77207
77355
  [CONNECTOR_RELAY_CLOSE.replaced.code, "another relay for this server took over"]
77208
77356
  ]);
77209
77357
  function mcpRelaysPathOf({ context }) {
77210
- return join10(dirname8(context.environment.configPath), "connect", "mcp-relays.json");
77358
+ return join13(dirname10(context.environment.configPath), "connect", "mcp-relays.json");
77211
77359
  }
77212
77360
  async function readMcpRelays({ context }) {
77213
77361
  return await readStateJson({ path: mcpRelaysPathOf({ context }) }) ?? {};
@@ -77367,7 +77515,7 @@ var McpRelayLoops = class _McpRelayLoops {
77367
77515
  };
77368
77516
 
77369
77517
  // src/services/openclaw-relay.service.ts
77370
- import { dirname as dirname9, join as join11 } from "node:path";
77518
+ import { dirname as dirname11, join as join14 } from "node:path";
77371
77519
 
77372
77520
  // ../../modules/openclaw/contract/src/openclaw.ts
77373
77521
  var workspaceIdSchema18 = external_exports.string().min(1);
@@ -77588,7 +77736,7 @@ var STOPS2 = /* @__PURE__ */ new Map([
77588
77736
  [OPENCLAW_RELAY_CLOSE.replaced.code, "another relay for this gateway took over"]
77589
77737
  ]);
77590
77738
  function relaysPathOf({ context }) {
77591
- return join11(dirname9(context.environment.configPath), "connect", "openclaw-relays.json");
77739
+ return join14(dirname11(context.environment.configPath), "connect", "openclaw-relays.json");
77592
77740
  }
77593
77741
  async function readRelays({ context }) {
77594
77742
  return await readStateJson({ path: relaysPathOf({ context }) }) ?? {};
@@ -77781,7 +77929,7 @@ var RelayLoops = class _RelayLoops {
77781
77929
  };
77782
77930
 
77783
77931
  // src/services/rush-host.service.ts
77784
- import { dirname as dirname10, join as join12 } from "node:path";
77932
+ import { dirname as dirname12, join as join15 } from "node:path";
77785
77933
  async function rushAboveOf({
77786
77934
  context,
77787
77935
  from = context.processes.pid
@@ -77795,7 +77943,7 @@ async function rushAboveOf({
77795
77943
  return void 0;
77796
77944
  }
77797
77945
  function guardPathOf({ context, claudePid }) {
77798
- return join12(dirname10(context.environment.configPath), "rush-guards", `${claudePid}.json`);
77946
+ return join15(dirname12(context.environment.configPath), "rush-guards", `${claudePid}.json`);
77799
77947
  }
77800
77948
  async function startRushGuard({
77801
77949
  context,
@@ -77808,7 +77956,7 @@ async function startRushGuard({
77808
77956
  if (holder && context.processes.alive(holder.pid)) return;
77809
77957
  const flags2 = ["--profile", profile, "--claude-pid", String(claudePid), "--rush-id", rush.id];
77810
77958
  const argv = [...context.program, "hook", "rush-wake", ...flags2, "--rush-program", rush.program];
77811
- const logPath = join12(dirname10(context.environment.configPath), "rush-guards", "guard.log");
77959
+ const logPath = join15(dirname12(context.environment.configPath), "rush-guards", "guard.log");
77812
77960
  context.processes.spawnDetached({ argv: ["sh", "-c", '"$@" &', "sh", ...argv], logPath });
77813
77961
  }
77814
77962
  async function claimRushGuard({
@@ -77925,8 +78073,6 @@ async function rearmRushGuards({ context }) {
77925
78073
  }
77926
78074
 
77927
78075
  // src/services/rush-watchdog.service.ts
77928
- import { appendFile, mkdir as mkdir2 } from "node:fs/promises";
77929
- import { dirname as dirname11, join as join13 } from "node:path";
77930
78076
  var UNDELIVERED_AFTER_MS = 6e4;
77931
78077
  var CHECK_TIMEOUT_MS = 5e3;
77932
78078
  function clientOf({ context, profile }) {
@@ -77961,38 +78107,20 @@ function boundAwayOf({ waiting, key }) {
77961
78107
  if (!bound || `${bound.harness}:${bound.sessionId}` === key) return void 0;
77962
78108
  return `${sessionLabelOf(bound)} (${bound.harness}:${bound.sessionId})`;
77963
78109
  }
77964
- async function logDelivery({ context, line }) {
77965
- const folder = join13(dirname11(context.environment.configPath), "connect");
77966
- const at8 = Temporal3.Instant.fromEpochMilliseconds(context.nowMs());
77967
- const stamped = `${at8.toString({ smallestUnit: "second" })} ${line}
77968
- `;
77969
- context.out(stamped);
77970
- await mkdir2(folder, { recursive: true, mode: 448 });
77971
- await appendFile(join13(folder, "delivery.log"), stamped, { mode: 384 });
77972
- }
77973
78110
  async function claimFor({
77974
78111
  context,
77975
78112
  client,
77976
78113
  row
77977
78114
  }) {
77978
78115
  const session = row.noted.session;
77979
- const claim3 = () => forSession({ client, session }).post("/api/agents/me/inbox", {
77980
- waitSeconds: 0
77981
- });
77982
78116
  try {
77983
- return await claim3();
78117
+ return await forSession({ client, session }).post("/api/agents/me/inbox", {
78118
+ waitSeconds: 0
78119
+ });
77984
78120
  } catch (error63) {
77985
- const meta3 = boundMetaOf({ error: error63 });
77986
- if (!meta3) throw error63;
77987
78121
  const profile = row.profile;
77988
- if (!await takeOverHere({ context, client, session, meta: meta3, profile })) {
77989
- return `Laze binds it to ${meta3.bound ?? meta3.session ?? "another session"}, which this machine still runs; \`laze agent bind\` in rush ${row.rushId} moves it here`;
77990
- }
77991
- await logDelivery({
77992
- context,
77993
- line: `${profile}: moved the agent from ${meta3.session} to ${row.key}, which this machine binds it to`
77994
- });
77995
- return claim3();
78122
+ if (!await droppedBinding({ context, session, error: error63, profile })) throw error63;
78123
+ return `Laze binds it to another session, so rush ${row.rushId} no longer listens for it`;
77996
78124
  }
77997
78125
  }
77998
78126
  async function checkSession({ context, row }) {
@@ -78044,10 +78172,10 @@ async function watchRushDelivery({
78044
78172
 
78045
78173
  // src/services/connect-delivery.service.ts
78046
78174
  function connectFolderOf({ context }) {
78047
- return join14(dirname12(context.environment.configPath), "connect");
78175
+ return join16(dirname13(context.environment.configPath), "connect");
78048
78176
  }
78049
78177
  function runStatePathOf({ context }) {
78050
- return join14(connectFolderOf({ context }), "run.json");
78178
+ return join16(connectFolderOf({ context }), "run.json");
78051
78179
  }
78052
78180
  async function readJson({ path }) {
78053
78181
  return readStateJson({ path });
@@ -78105,7 +78233,7 @@ async function takeRound({
78105
78233
  harness: "codex",
78106
78234
  sessionId: delivery.threadId,
78107
78235
  folder: displayFolderOf({ folder: delivery.cwd, home: homedir3() }),
78108
- host: hostname5()
78236
+ host: hostname6()
78109
78237
  };
78110
78238
  try {
78111
78239
  return await client.withHeaders(sessionHeadersOf({ session })).post("/api/agents/me/inbox", { waitSeconds: ROUND_SECONDS }, { signal });
@@ -78345,18 +78473,18 @@ var CONNECT_SERVICE_USAGE = `laze connect install|status|stop|uninstall|run: the
78345
78473
  \`laze openclaw connect --local\` and \`laze kanban connect\`, whose relays it also runs.
78346
78474
  `;
78347
78475
  function installedPathOf({ context }) {
78348
- return join15(connectFolderOf({ context }), "service.json");
78476
+ return join17(connectFolderOf({ context }), "service.json");
78349
78477
  }
78350
78478
  function logPathOf({ context }) {
78351
- return join15(connectFolderOf({ context }), "connect.log");
78479
+ return join17(connectFolderOf({ context }), "connect.log");
78352
78480
  }
78353
78481
  function homeOf({ context }) {
78354
- return context.environment.inherited.HOME ?? dirname13(dirname13(context.environment.configPath));
78482
+ return context.environment.inherited.HOME ?? dirname14(dirname14(context.environment.configPath));
78355
78483
  }
78356
78484
  function serviceNameOf({ context }) {
78357
78485
  const { configPath } = context.environment;
78358
- if (configPath === join15(homeOf({ context }), ".laze", "config.json")) return "laze-connect";
78359
- return `laze-connect-${createHash2("sha256").update(configPath).digest("hex").slice(0, 8)}`;
78486
+ if (configPath === join17(homeOf({ context }), ".laze", "config.json")) return "laze-connect";
78487
+ return `laze-connect-${createHash3("sha256").update(configPath).digest("hex").slice(0, 8)}`;
78360
78488
  }
78361
78489
  function serviceEnvOf({ context }) {
78362
78490
  const path = context.environment.inherited.PATH;
@@ -78378,9 +78506,9 @@ async function run({ context, command }) {
78378
78506
  async function installSystemd({ context }) {
78379
78507
  const name3 = serviceNameOf({ context });
78380
78508
  const env = context.environment.inherited;
78381
- const base = env.XDG_CONFIG_HOME || join15(homeOf({ context }), ".config");
78382
- const file4 = join15(base, "systemd", "user", `${name3}.service`);
78383
- await mkdir3(dirname13(file4), { recursive: true });
78509
+ const base = env.XDG_CONFIG_HOME || join17(homeOf({ context }), ".config");
78510
+ const file4 = join17(base, "systemd", "user", `${name3}.service`);
78511
+ await mkdir3(dirname14(file4), { recursive: true });
78384
78512
  await writeFile(
78385
78513
  file4,
78386
78514
  systemdUnitOf({ argv: runArgvOf({ context }), env: serviceEnvOf({ context }) })
@@ -78394,9 +78522,9 @@ async function installSystemd({ context }) {
78394
78522
  async function installLaunchd({ context }) {
78395
78523
  const name3 = serviceNameOf({ context });
78396
78524
  const label3 = `ai.laze.${name3}`;
78397
- const file4 = join15(homeOf({ context }), "Library", "LaunchAgents", `${label3}.plist`);
78525
+ const file4 = join17(homeOf({ context }), "Library", "LaunchAgents", `${label3}.plist`);
78398
78526
  const log = logPathOf({ context });
78399
- await mkdir3(dirname13(file4), { recursive: true });
78527
+ await mkdir3(dirname14(file4), { recursive: true });
78400
78528
  await writeFile(
78401
78529
  file4,
78402
78530
  launchAgentOf({
@@ -78712,24 +78840,10 @@ async function claudePidOf({ context }) {
78712
78840
  async function settleRound(round) {
78713
78841
  const { context, client, name: name3, session } = round;
78714
78842
  const messages = await roundOf(round).catch(async (error63) => {
78715
- const refused = await notBoundNotice({
78716
- context,
78717
- client: forSession({ client, session }),
78718
- session,
78719
- error: error63,
78720
- profile: name3
78721
- });
78722
- if (!refused) throw error63;
78723
- return refused;
78843
+ if (await droppedBinding({ context, session, error: error63, profile: name3 })) return void 0;
78844
+ throw error63;
78724
78845
  });
78725
78846
  if (messages === void 0) return 0;
78726
- if (!Array.isArray(messages)) {
78727
- if (messages.rebound) return "again";
78728
- if (!messages.notice) return 0;
78729
- context.err(`${messages.notice}
78730
- `);
78731
- return 2;
78732
- }
78733
78847
  if (messages.length === 0) return "again";
78734
78848
  const self2 = await currentNameOf({ context, client, profile: name3 });
78735
78849
  const text3 = hookContextOf({ messages, self: self2 });
@@ -78755,9 +78869,8 @@ async function waitForMessages({ context, args }) {
78755
78869
  const input2 = raw.trim() ? JSON.parse(raw) : {};
78756
78870
  const session = sessionOf({ context, harness: "claude-code", sessionId: input2.session_id });
78757
78871
  const claudePid = await claudePidOf({ context });
78758
- const asked = await pluginHookArgs({ context, args, session, claudePid });
78759
- if (!asked) return 0;
78760
- const named = await sessionProfileArgs({ context, args: asked, session });
78872
+ const named = await pluginHookArgs({ context, args, session, claudePid, source: input2.source });
78873
+ if (!named) return 0;
78761
78874
  const { client, name: name3 } = await signedIn({ context, args: named });
78762
78875
  await rememberSession({ context, claudePid, session });
78763
78876
  const rush = claudePid ? await rushAboveOf({ context, from: claudePid }) : void 0;
@@ -78877,15 +78990,12 @@ async function monitorServes({
78877
78990
  }
78878
78991
 
78879
78992
  // src/services/codex-link.service.ts
78880
- import { createReadStream } from "node:fs";
78881
- import { readdir as readdir6, rm as rm8, stat as stat7 } from "node:fs/promises";
78882
- import { join as join17, resolve as resolve4 } from "node:path";
78883
- import { createInterface as createInterface2 } from "node:readline";
78993
+ import { rm as rm8 } from "node:fs/promises";
78884
78994
 
78885
78995
  // src/services/codex-adopt.service.ts
78886
78996
  import { spawn as spawn2 } from "node:child_process";
78887
78997
  import { readdir as readdir5, rm as rm7, stat as stat6 } from "node:fs/promises";
78888
- import { join as join16 } from "node:path";
78998
+ import { join as join18 } from "node:path";
78889
78999
  import { createInterface } from "node:readline";
78890
79000
 
78891
79001
  // src/rules/codex-requests.rules.ts
@@ -78944,8 +79054,8 @@ var CodexAppServer = class _CodexAppServer {
78944
79054
  }
78945
79055
  async call(method, params) {
78946
79056
  const id8 = ++this.#nextId;
78947
- const reply2 = await new Promise((resolve28) => {
78948
- this.#pending.set(id8, resolve28);
79057
+ const reply2 = await new Promise((resolve27) => {
79058
+ this.#pending.set(id8, resolve27);
78949
79059
  this.write({ id: id8, method, params });
78950
79060
  });
78951
79061
  if (reply2.error !== void 0) throw new Error(`${method}: ${JSON.stringify(reply2.error)}`);
@@ -78957,12 +79067,12 @@ var CodexAppServer = class _CodexAppServer {
78957
79067
  /** Starts one turn; `done` settles when it completes, keeping its last agent message. */
78958
79068
  async startTurn({ threadId, text: text3 }) {
78959
79069
  const result2 = { answer: "" };
78960
- const done = new Promise((resolve28) => {
79070
+ const done = new Promise((resolve27) => {
78961
79071
  const listen = (message2) => {
78962
79072
  absorbTurnEvent({ result: result2, message: message2 });
78963
79073
  if (message2.method !== "turn/completed") return;
78964
79074
  this.#listeners.delete(listen);
78965
- resolve28(result2);
79075
+ resolve27(result2);
78966
79076
  };
78967
79077
  this.#listeners.add(listen);
78968
79078
  });
@@ -79005,11 +79115,11 @@ var CodexAppServer = class _CodexAppServer {
79005
79115
  }
79006
79116
  };
79007
79117
  async function newestThreadId({ codexHome }) {
79008
- const root = join16(codexHome, "sessions");
79118
+ const root = join18(codexHome, "sessions");
79009
79119
  const files2 = await readdir5(root, { recursive: true }).catch(() => []);
79010
79120
  const rollouts = files2.filter((file4) => /rollout-.*\.jsonl$/.test(file4));
79011
79121
  const dated = await Promise.all(
79012
- rollouts.map(async (file4) => ({ file: file4, at: (await stat6(join16(root, file4))).mtimeMs }))
79122
+ rollouts.map(async (file4) => ({ file: file4, at: (await stat6(join18(root, file4))).mtimeMs }))
79013
79123
  );
79014
79124
  const newest = dated.toSorted((a, b) => b.at - a.at)[0]?.file ?? "";
79015
79125
  const id8 = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/.exec(newest);
@@ -79254,49 +79364,8 @@ async function adoptCodex({ context, args }) {
79254
79364
  }
79255
79365
 
79256
79366
  // src/services/codex-link.service.ts
79257
- var ROLLOUTS_READ = 200;
79258
- async function firstLineOf({ path }) {
79259
- const stream = createReadStream(path, { encoding: "utf8" });
79260
- const lines2 = createInterface2({ input: stream, crlfDelay: Infinity });
79261
- try {
79262
- for await (const line of lines2) return line;
79263
- return "";
79264
- } finally {
79265
- lines2.close();
79266
- stream.destroy();
79267
- }
79268
- }
79269
- async function newestThreadIn({
79270
- codexHome,
79271
- directory
79272
- }) {
79273
- const root = join17(codexHome, "sessions");
79274
- const files2 = await readdir6(root, { recursive: true }).catch(() => []);
79275
- const rollouts = files2.filter((file4) => /rollout-.*\.jsonl$/.test(file4));
79276
- const dated = await Promise.all(
79277
- rollouts.map(async (file4) => ({
79278
- path: join17(root, file4),
79279
- at: await stat7(join17(root, file4)).then(
79280
- (info) => info.mtimeMs,
79281
- () => 0
79282
- )
79283
- }))
79284
- );
79285
- const newest = dated.toSorted((a, b) => b.at - a.at).slice(0, ROLLOUTS_READ);
79286
- for (const { path } of newest) {
79287
- const session = rolloutSessionOf({ firstLine: await firstLineOf({ path }).catch(() => "") });
79288
- if (session && resolve4(session.cwd) === resolve4(directory)) return session.id;
79289
- }
79290
- return void 0;
79291
- }
79292
- async function threadOf({
79293
- context,
79294
- args,
79295
- directory
79296
- }) {
79297
- const named = flagText({ args, name: "thread" }) || context.environment.inherited.CODEX_THREAD_ID;
79298
- if (named) return named;
79299
- return newestThreadIn({ codexHome: context.environment.codexHome, directory });
79367
+ function threadOf({ context, args }) {
79368
+ return flagText({ args, name: "thread" }) || context.environment.inherited.CODEX_THREAD_ID;
79300
79369
  }
79301
79370
  async function codexQueues({ context }) {
79302
79371
  const code4 = await context.runCommand({ command: ["sh", "-c", "codex queue --help >/dev/null 2>&1"], env: {} }).catch(() => 1);
@@ -79309,6 +79378,24 @@ async function stopAdopt({ context, profile }) {
79309
79378
  context.processes.stop(running.pid);
79310
79379
  await rm8(path, { force: true });
79311
79380
  }
79381
+ async function bindThread({
79382
+ context,
79383
+ args,
79384
+ profile,
79385
+ threadId
79386
+ }) {
79387
+ const session = sessionOf({ context, harness: "codex", sessionId: threadId });
79388
+ if (!session) return;
79389
+ await context.store.bindSession({ session: sessionKeyOf({ session }), profile });
79390
+ try {
79391
+ const named = { ...args, flags: { ...args.flags, profile } };
79392
+ const { client } = await signedIn({ context, args: named });
79393
+ await forSession({ client, session }).post("/api/agents/me/bind", {});
79394
+ } catch (error63) {
79395
+ context.err(`laze: could not bind the agent to this thread yet: ${String(error63)}
79396
+ `);
79397
+ }
79398
+ }
79312
79399
  async function linkCodexSession({
79313
79400
  context,
79314
79401
  args,
@@ -79316,8 +79403,12 @@ async function linkCodexSession({
79316
79403
  laze,
79317
79404
  directory
79318
79405
  }) {
79319
- const threadId = await threadOf({ context, args, directory });
79320
- if (!threadId || !await codexQueues({ context })) {
79406
+ const threadId = threadOf({ context, args });
79407
+ if (!threadId) {
79408
+ return `No Codex thread id here (CODEX_THREAD_ID): link again with --thread <id>, so ${profile} is bound to that thread and no other.`;
79409
+ }
79410
+ await bindThread({ context, args, profile, threadId });
79411
+ if (!await codexQueues({ context })) {
79321
79412
  return startAdoptInBackground({ context, args, profile, laze });
79322
79413
  }
79323
79414
  await stopAdopt({ context, profile });
@@ -79348,15 +79439,15 @@ async function linkCodexSession({
79348
79439
  // src/services/laze-plugin.service.ts
79349
79440
  import { mkdir as mkdir4, readFile as readFile10, rm as rm9, writeFile as writeFile2 } from "node:fs/promises";
79350
79441
  import { homedir as homedir4 } from "node:os";
79351
- import { dirname as dirname14, join as join19 } from "node:path";
79442
+ import { dirname as dirname15, join as join20 } from "node:path";
79352
79443
 
79353
79444
  // src/rules/laze-plugin.rules.ts
79354
- import { createHash as createHash3 } from "node:crypto";
79355
- import { join as join18 } from "node:path";
79445
+ import { createHash as createHash4 } from "node:crypto";
79446
+ import { join as join19 } from "node:path";
79356
79447
  var LAZE_PLUGIN = "laze";
79357
79448
  function pluginNameOf({ configPath, home }) {
79358
- if (configPath === join18(home, ".laze", "config.json")) return LAZE_PLUGIN;
79359
- return `${LAZE_PLUGIN}-${createHash3("sha256").update(configPath).digest("hex").slice(0, 8)}`;
79449
+ if (configPath === join19(home, ".laze", "config.json")) return LAZE_PLUGIN;
79450
+ return `${LAZE_PLUGIN}-${createHash4("sha256").update(configPath).digest("hex").slice(0, 8)}`;
79360
79451
  }
79361
79452
  var NPX_CLI = ["npx", "-y", "@lazehq/cli@latest"];
79362
79453
  var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
@@ -79626,10 +79717,10 @@ function installedNameOf({ context }) {
79626
79717
  return `${name3}@${name3}`;
79627
79718
  }
79628
79719
  function pluginFolderOf({ context }) {
79629
- return join19(dirname14(context.environment.configPath), "plugins");
79720
+ return join20(dirname15(context.environment.configPath), "plugins");
79630
79721
  }
79631
79722
  async function pluginIsCurrent({ context }) {
79632
- const manifest = join19(pluginFolderOf({ context }), LAZE_PLUGIN, ".claude-plugin", "plugin.json");
79723
+ const manifest = join20(pluginFolderOf({ context }), LAZE_PLUGIN, ".claude-plugin", "plugin.json");
79633
79724
  const written = await readFile10(manifest, "utf8").then((text3) => JSON.parse(text3).version).catch(() => void 0);
79634
79725
  return written === cliVersionOf();
79635
79726
  }
@@ -79642,8 +79733,8 @@ async function writeLazePlugin({ context }) {
79642
79733
  configPath: context.environment.configPath
79643
79734
  });
79644
79735
  for (const [path, text3] of Object.entries(files2)) {
79645
- const target = join19(folder, path);
79646
- await mkdir4(dirname14(target), { recursive: true });
79736
+ const target = join20(folder, path);
79737
+ await mkdir4(dirname15(target), { recursive: true });
79647
79738
  await writeFile2(target, text3);
79648
79739
  }
79649
79740
  return folder;
@@ -79673,7 +79764,7 @@ async function registerWithClaude({ context, folder }) {
79673
79764
  return claudeScript({ context, script });
79674
79765
  }
79675
79766
  function claudeDirOf({ context }) {
79676
- return context.environment.inherited.CLAUDE_CONFIG_DIR || join19(homeOf2({ context }), ".claude");
79767
+ return context.environment.inherited.CLAUDE_CONFIG_DIR || join20(homeOf2({ context }), ".claude");
79677
79768
  }
79678
79769
  function unregisterAs({ context, name: name3 }) {
79679
79770
  const script = [
@@ -79685,7 +79776,7 @@ function unregisterAs({ context, name: name3 }) {
79685
79776
  async function dropOwnLeftover({ context, folder }) {
79686
79777
  if (pluginNameHere({ context }) === LAZE_PLUGIN) return;
79687
79778
  const known = await readFile10(
79688
- join19(claudeDirOf({ context }), "plugins", "known_marketplaces.json"),
79779
+ join20(claudeDirOf({ context }), "plugins", "known_marketplaces.json"),
79689
79780
  "utf8"
79690
79781
  ).then((text3) => JSON.parse(text3)).catch(() => void 0);
79691
79782
  if (known?.[LAZE_PLUGIN]?.source?.path !== folder) return;
@@ -79693,7 +79784,7 @@ async function dropOwnLeftover({ context, folder }) {
79693
79784
  }
79694
79785
  var RUN_FILES = ["hooks/hooks.json", "monitors/monitors.json"];
79695
79786
  async function cachedPluginOf({ context }) {
79696
- const path = join19(claudeDirOf({ context }), "plugins", "installed_plugins.json");
79787
+ const path = join20(claudeDirOf({ context }), "plugins", "installed_plugins.json");
79697
79788
  const listed = await readFile10(path, "utf8").then((text3) => JSON.parse(text3)).catch(() => void 0);
79698
79789
  return listed?.plugins?.[installedNameOf({ context })]?.[0]?.installPath;
79699
79790
  }
@@ -79702,8 +79793,8 @@ async function refreshStaleCache({ context, folder }) {
79702
79793
  if (!cached2) return true;
79703
79794
  const read4 = (path) => readFile10(path, "utf8").catch(() => "");
79704
79795
  for (const file4 of RUN_FILES) {
79705
- const ours = await read4(join19(folder, LAZE_PLUGIN, file4));
79706
- if (ours === await read4(join19(cached2, file4))) continue;
79796
+ const ours = await read4(join20(folder, LAZE_PLUGIN, file4));
79797
+ if (ours === await read4(join20(cached2, file4))) continue;
79707
79798
  const plugin2 = installedNameOf({ context });
79708
79799
  const script = [
79709
79800
  `claude plugin uninstall ${plugin2} --scope user ${QUIET}`,
@@ -79714,7 +79805,7 @@ async function refreshStaleCache({ context, folder }) {
79714
79805
  return true;
79715
79806
  }
79716
79807
  function registeredMarkOf({ context }) {
79717
- return join19(pluginFolderOf({ context }), "registered");
79808
+ return join20(pluginFolderOf({ context }), "registered");
79718
79809
  }
79719
79810
  async function pluginRegistered({ context }) {
79720
79811
  return readFile10(registeredMarkOf({ context }), "utf8").then(
@@ -79732,7 +79823,7 @@ async function installLazePlugin({ context }) {
79732
79823
  async function plugin({ context, args }) {
79733
79824
  const action = args.words[1] ?? "install";
79734
79825
  if (action === "path") {
79735
- context.out(`${join19(pluginFolderOf({ context }), LAZE_PLUGIN)}
79826
+ context.out(`${join20(pluginFolderOf({ context }), LAZE_PLUGIN)}
79736
79827
  `);
79737
79828
  return 0;
79738
79829
  }
@@ -79996,9 +80087,9 @@ async function reloadTipOnce({
79996
80087
 
79997
80088
  // src/services/session-scrub.service.ts
79998
80089
  import { Buffer as Buffer3 } from "node:buffer";
79999
- import { createHash as createHash4 } from "node:crypto";
80090
+ import { createHash as createHash5 } from "node:crypto";
80000
80091
  import { mkdir as mkdir5, open as open5 } from "node:fs/promises";
80001
- import { dirname as dirname15, join as join20 } from "node:path";
80092
+ import { dirname as dirname16, join as join21 } from "node:path";
80002
80093
 
80003
80094
  // src/rules/session-scrub.rules.ts
80004
80095
  import { Buffer as Buffer2 } from "node:buffer";
@@ -80057,15 +80148,15 @@ function paddedTo({ text: text3, bytes }) {
80057
80148
 
80058
80149
  // src/services/session-scrub.service.ts
80059
80150
  function offsetPathOf({ context, transcript }) {
80060
- const key = createHash4("sha256").update(transcript).digest("hex").slice(0, 24);
80061
- return join20(dirname15(context.environment.configPath), "session-scrub", `${key}.json`);
80151
+ const key = createHash5("sha256").update(transcript).digest("hex").slice(0, 24);
80152
+ return join21(dirname16(context.environment.configPath), "session-scrub", `${key}.json`);
80062
80153
  }
80063
80154
  async function offsetOf({ path }) {
80064
80155
  const saved3 = await readStateJson({ path });
80065
80156
  return typeof saved3?.offset === "number" && saved3.offset >= 0 ? saved3.offset : 0;
80066
80157
  }
80067
80158
  async function keepOffset({ path, offset }) {
80068
- await mkdir5(dirname15(path), { recursive: true });
80159
+ await mkdir5(dirname16(path), { recursive: true });
80069
80160
  await writeStateJson({ path, value: { offset } });
80070
80161
  }
80071
80162
  async function stillThere({ file: file4, line }) {
@@ -80244,16 +80335,12 @@ function settingsOf({ path, text: text3 }) {
80244
80335
  throw new CliUsageError(`${path} is not valid JSON; fix it, then link again.`);
80245
80336
  }
80246
80337
  }
80247
- async function installHooks({
80248
- context,
80249
- directory,
80250
- profile
80251
- }) {
80252
- const folder = join21(directory, ".claude");
80253
- const path = join21(folder, "settings.local.json");
80338
+ async function installHooks({ context, directory }) {
80339
+ const folder = join22(directory, ".claude");
80340
+ const path = join22(folder, "settings.local.json");
80254
80341
  const text3 = await readFile12(path, "utf8").catch(() => "{}");
80255
80342
  const current3 = settingsOf({ path, text: text3 });
80256
- const command = (hook) => hookCommand({ program: context.program, profile, hook });
80343
+ const command = (hook) => hookCommand({ program: context.program, hook });
80257
80344
  const settings3 = withLazeHooks({
80258
80345
  settings: current3,
80259
80346
  stopCommand: command("stop"),
@@ -80361,7 +80448,7 @@ async function sessionFolderOf({
80361
80448
  pid
80362
80449
  }) {
80363
80450
  const asked = flagText({ args, name: "project" });
80364
- if (asked) return { folder: resolve5(context.cwd, asked), elsewhere: void 0 };
80451
+ if (asked) return { folder: resolve4(context.cwd, asked), elsewhere: void 0 };
80365
80452
  if (!claude) return { folder: context.cwd, elsewhere: void 0 };
80366
80453
  return claudeFoldersOf({ context, claudePid: pid });
80367
80454
  }
@@ -80387,9 +80474,9 @@ async function settleLinked({
80387
80474
  });
80388
80475
  const claude = harness === "claude-code";
80389
80476
  const { folder: directory, elsewhere } = await sessionFolderOf({ context, args, claude, pid });
80390
- await context.store.saveProfile({
80477
+ const first = !(await context.store.read()).current;
80478
+ await context.store[first ? "saveProfile" : "keepProfile"]({
80391
80479
  name: name3,
80392
- bindDirectory: directory,
80393
80480
  profile: {
80394
80481
  url: url2,
80395
80482
  token: linked.apiKey,
@@ -80412,7 +80499,7 @@ async function settleLinked({
80412
80499
  });
80413
80500
  }
80414
80501
  const hooked = claude && !args.flags["no-hook"];
80415
- const hookPath = hooked ? await installHooks({ context, directory, profile: name3 }) : void 0;
80502
+ const hookPath = hooked ? await installHooks({ context, directory }) : void 0;
80416
80503
  const listener = hooked ? await listenAfterLink({ context, args, profile: name3, claudePid: pid }) : void 0;
80417
80504
  const { command: laze, shadow } = await rerunCommandOf({ context });
80418
80505
  const steps = await nextStepsFor({
@@ -80426,7 +80513,7 @@ async function settleLinked({
80426
80513
  });
80427
80514
  context.out(
80428
80515
  [
80429
- `Linked as ${linked.agent.name} (${linked.agent.id}), profile "${name3}" for ${directory}.`,
80516
+ `Linked as ${linked.agent.name} (${linked.agent.id}), profile "${name3}", in ${directory}.`,
80430
80517
  ...hookPath ? [`Added the Laze hooks to ${hookPath}.`] : [],
80431
80518
  ...elsewhereLinesOf({ folder: directory, elsewhere }),
80432
80519
  ...shadowedLinkLineOf({ shadow }),
@@ -80451,12 +80538,12 @@ async function nextStepsFor({
80451
80538
  laze
80452
80539
  }) {
80453
80540
  if (harness === "codex") return linkCodexSession({ context, args, profile, laze, directory });
80454
- if (!hooked) return waiterStepsOf({ profile, laze });
80455
80541
  const session = await currentSessionOf({ context, args });
80456
80542
  if (session) {
80457
80543
  await context.store.bindSession({ session: sessionKeyOf({ session }), profile });
80458
80544
  await bindInLaze({ context, args, session, profile });
80459
80545
  }
80546
+ if (!hooked) return waiterStepsOf({ profile, laze });
80460
80547
  const plugin2 = args.flags["no-plugin"] ? void 0 : await installLazePlugin({ context });
80461
80548
  if (plugin2?.registered) await markReloadTipTold({ context, session });
80462
80549
  const mcp2 = args.flags.mcp ? await registerMcp({ context, directory, profile }) : void 0;
@@ -80509,9 +80596,8 @@ async function handOver({ context, args }) {
80509
80596
  const input2 = raw.trim() ? JSON.parse(raw) : {};
80510
80597
  const session = sessionOf({ context, harness: "claude-code", sessionId: input2.session_id });
80511
80598
  const claudePid = await claudePidOf({ context });
80512
- const asked = await pluginHookArgs({ context, args, session, claudePid });
80513
- if (!asked) return;
80514
- const named = await sessionProfileArgs({ context, args: asked, session });
80599
+ const named = await pluginHookArgs({ context, args, session, claudePid });
80600
+ if (!named) return;
80515
80601
  const { client, name: agent3 } = await signedIn({ context, args: named });
80516
80602
  await reportTranscript({ client, input: input2 }).catch(
80517
80603
  (error63) => reportFailed({ context, error: error63 })
@@ -80540,16 +80626,8 @@ async function handOver({ context, args }) {
80540
80626
  try {
80541
80627
  fresh = await receiveMessages({ context, client: claim3, waitSeconds: 0 });
80542
80628
  } catch (error63) {
80543
- const refused = await notBoundNotice({
80544
- context,
80545
- client: claim3,
80546
- session,
80547
- error: error63,
80548
- profile: agent3
80549
- });
80550
- if (!refused) throw error63;
80551
- if (refused.notice) stopContext({ context, text: refused.notice });
80552
- return;
80629
+ if (await droppedBinding({ context, session, error: error63, profile: agent3 })) return;
80630
+ throw error63;
80553
80631
  }
80554
80632
  await keepTaken({ context, profile: agent3, messages: fresh });
80555
80633
  const messages = [...kept, ...fresh];
@@ -80570,16 +80648,15 @@ async function handOver({ context, args }) {
80570
80648
  }
80571
80649
  async function addSessionStartWaiter({ context, args }) {
80572
80650
  const directory = context.environment.inherited.CLAUDE_PROJECT_DIR;
80573
- const profile = flagText({ args, name: "profile" });
80574
- if (!directory || !profile) return;
80575
- const path = join21(directory, ".claude", "settings.local.json");
80651
+ if (!directory || args.flags.plugin) return;
80652
+ const path = join22(directory, ".claude", "settings.local.json");
80576
80653
  const settings3 = await readFile12(path, "utf8").then((text3) => JSON.parse(text3)).catch(() => void 0);
80577
80654
  if (!settings3 || !lacksSessionStartWaiter({ settings: settings3 })) return;
80578
- await installHooks({ context, directory, profile });
80655
+ await installHooks({ context, directory });
80579
80656
  }
80580
80657
  async function refreshPlugin({ context }) {
80581
80658
  if (await pluginIsCurrent({ context })) return;
80582
- const logPath = join21(pluginFolderOf({ context }), "install.log");
80659
+ const logPath = join22(pluginFolderOf({ context }), "install.log");
80583
80660
  context.processes.spawnDetached({ argv: [...context.program, "plugin", "install"], logPath });
80584
80661
  }
80585
80662
  async function stopHook({ context, args }) {
@@ -80606,7 +80683,7 @@ async function stopHook({ context, args }) {
80606
80683
 
80607
80684
  // src/services/agent-manage-commands.service.ts
80608
80685
  import { readFile as readFile13 } from "node:fs/promises";
80609
- import { extname, resolve as resolve6 } from "node:path";
80686
+ import { extname, resolve as resolve5 } from "node:path";
80610
80687
 
80611
80688
  // src/rules/login-format.rules.ts
80612
80689
  var HARNESS_NAMES2 = {
@@ -80738,7 +80815,7 @@ async function avatarOf({
80738
80815
  return emoji4;
80739
80816
  }
80740
80817
  if (!path) return void 0;
80741
- const bytes = await readFile13(resolve6(context.cwd, path)).catch(() => {
80818
+ const bytes = await readFile13(resolve5(context.cwd, path)).catch(() => {
80742
80819
  throw new CliUsageError(`laze: cannot read the avatar file ${path}.`);
80743
80820
  });
80744
80821
  const uploaded = await client.post("/api/agents/avatars", {
@@ -81454,11 +81531,11 @@ async function setAgentRunsOn({
81454
81531
  }
81455
81532
 
81456
81533
  // src/services/agent-migrate-commands.service.ts
81457
- import { readFile as readFile14, stat as stat8 } from "node:fs/promises";
81458
- import { basename as basename6, join as join22, resolve as resolve7 } from "node:path";
81534
+ import { readFile as readFile14, stat as stat7 } from "node:fs/promises";
81535
+ import { basename as basename6, join as join23, resolve as resolve6 } from "node:path";
81459
81536
 
81460
81537
  // src/rules/migration-upload.rules.ts
81461
- import { createHash as createHash5 } from "node:crypto";
81538
+ import { createHash as createHash6 } from "node:crypto";
81462
81539
  function markersIn(text3) {
81463
81540
  return text3.split(REDACTION_MARKER).length - 1;
81464
81541
  }
@@ -81477,7 +81554,7 @@ async function redactTranscript({
81477
81554
  return { text: redacted.text, redactions };
81478
81555
  }
81479
81556
  function sha256Of({ text: text3 }) {
81480
- return createHash5("sha256").update(text3, "utf8").digest("hex");
81557
+ return createHash6("sha256").update(text3, "utf8").digest("hex");
81481
81558
  }
81482
81559
  var bytesOf2 = (text3) => Buffer.byteLength(text3, "utf8");
81483
81560
  function piecesOf({ line, maxBytes }) {
@@ -81665,14 +81742,14 @@ async function chosenTranscriptOf({
81665
81742
  ticket,
81666
81743
  file: file4
81667
81744
  }) {
81668
- const path = resolve7(context.cwd, file4);
81745
+ const path = resolve6(context.cwd, file4);
81669
81746
  const sessionId = basename6(path).replace(/\.jsonl$/, "");
81670
81747
  if (ticket.source !== "claude-code" || !SESSION_ID.test(sessionId)) {
81671
81748
  throw new CliUsageError(
81672
81749
  "--transcript takes a Claude Code transcript named <session id>.jsonl. Nothing was uploaded."
81673
81750
  );
81674
81751
  }
81675
- const found = await stat8(path).then(
81752
+ const found = await stat7(path).then(
81676
81753
  (info) => info.isFile(),
81677
81754
  () => false
81678
81755
  );
@@ -81692,7 +81769,7 @@ async function transcriptOf({ context, args, ticket }) {
81692
81769
  if (ticket.source === "codex") {
81693
81770
  const codexHome = context.environment.codexHome;
81694
81771
  const path2 = await codexRolloutPathOf({ codexHome, threadId: sessionId });
81695
- return { sessionId, path: path2, where: join22(codexHome, "sessions") };
81772
+ return { sessionId, path: path2, where: join23(codexHome, "sessions") };
81696
81773
  }
81697
81774
  const { root, path } = await claudeTranscriptOf({ context, sessionId });
81698
81775
  return { sessionId, path, where: root };
@@ -81700,7 +81777,7 @@ async function transcriptOf({ context, args, ticket }) {
81700
81777
  async function agentHere({ context, args }) {
81701
81778
  const chosen = Boolean(flagText({ args, name: "transcript" }));
81702
81779
  const session = chosen ? void 0 : await currentSessionOf({ context, args });
81703
- const named = await sessionProfileArgs({ context, args, session, binds: false });
81780
+ const named = await sessionProfileArgs({ context, args, session });
81704
81781
  const signed2 = await signedIn({ context, args: named });
81705
81782
  if (signed2.profile.kind !== "agent") {
81706
81783
  throw new CliUsageError(
@@ -81818,7 +81895,7 @@ function whyOf(error63) {
81818
81895
 
81819
81896
  // src/services/agent-session-commands.service.ts
81820
81897
  var NO_SESSION = "Run this inside the Claude Code or Codex session the agent should listen in, or pass --session <id>.";
81821
- var NO_AGENT = "This session and its folder have no agent: name one with `laze agent bind --profile <name>`.";
81898
+ var NO_AGENT = "This session has no agent: name one with `laze agent bind --profile <name>`.";
81822
81899
  var DEFAULT_WAIT_SECONDS = 300;
81823
81900
  async function bindAgentSession({
81824
81901
  context,
@@ -81832,7 +81909,7 @@ async function bindAgentSession({
81832
81909
  const held = config2.sessions?.[key];
81833
81910
  const own2 = held && config2.profiles[held] ? held : void 0;
81834
81911
  const explicit = flagText({ args, name: "profile" }) || void 0;
81835
- const target = explicit ?? own2 ?? boundProfileOf({ bindings: config2.bindings, cwd: context.cwd });
81912
+ const target = explicit ?? own2;
81836
81913
  if (!target) throw new CliUsageError(NO_AGENT);
81837
81914
  const named = { ...args, flags: { ...args.flags, profile: target } };
81838
81915
  const { client, name: name3, profile } = await signedIn({ context, args: named });
@@ -81906,7 +81983,8 @@ async function requestProfileOf({
81906
81983
  const config2 = await context.store.read();
81907
81984
  const requests2 = Object.entries(config2.profiles).filter(([, one]) => one.kind === "request");
81908
81985
  const asked = flagText({ args, name: "from" });
81909
- const bound = boundProfileOf({ bindings: config2.bindings, cwd: context.cwd });
81986
+ const session = await currentSessionOf({ context, args });
81987
+ const bound = await sessionAgentOf({ context, session });
81910
81988
  const wanted = asked ? requestProfileNameOf({ profile: asked }) : bound && requestProfileNameOf({ profile: bound });
81911
81989
  const found = requests2.find(([name3]) => name3 === wanted || name3 === asked) ?? (requests2.length === 1 && !asked ? requests2[0] : void 0);
81912
81990
  if (found) return { name: found[0], profile: found[1] };
@@ -82022,10 +82100,48 @@ async function requestAgent({ context, args }) {
82022
82100
  await forSession({ client: own2, session }).post("/api/agents/me/bind", {});
82023
82101
  await context.store.bindSession({ session: sessionKeyOf({ session }), profile });
82024
82102
  }
82103
+ async function listAgentSessions({
82104
+ context,
82105
+ args
82106
+ }) {
82107
+ if (args.flags.migrate) {
82108
+ const lines2 = await migrateSessions({ context });
82109
+ context.out(lines2.length > 0 ? `${lines2.join("\n")}
82110
+ ` : "Nothing to migrate.\n");
82111
+ return;
82112
+ }
82113
+ const config2 = await context.store.read();
82114
+ const rows = Object.entries(config2.sessions ?? {}).map(([key, profile]) => {
82115
+ const split = key.indexOf(":");
82116
+ const entry2 = config2.profiles[profile];
82117
+ return {
82118
+ harness: key.slice(0, split),
82119
+ sessionId: key.slice(split + 1),
82120
+ profile,
82121
+ agent: entry2?.name ?? null,
82122
+ exists: Boolean(entry2)
82123
+ };
82124
+ });
82125
+ if (args.flags.json) {
82126
+ context.out(`${JSON.stringify(rows, null, 2)}
82127
+ `);
82128
+ return;
82129
+ }
82130
+ if (rows.length === 0) {
82131
+ context.out("No session on this machine is bound to an agent.\n");
82132
+ return;
82133
+ }
82134
+ const text3 = rows.map((row) => {
82135
+ const who = row.exists ? `"${row.agent}" (profile ${row.profile})` : `profile ${row.profile}, gone`;
82136
+ return `${row.harness} ${row.sessionId} ${who}
82137
+ `;
82138
+ });
82139
+ context.out(text3.join(""));
82140
+ }
82025
82141
 
82026
82142
  // src/services/app-commands.service.ts
82027
- import { mkdir as mkdir8, readdir as readdir7, readFile as readFile17, writeFile as writeFile6 } from "node:fs/promises";
82028
- import { dirname as dirname17, join as join27, relative as relative3, resolve as resolve10, sep as sep3 } from "node:path";
82143
+ import { mkdir as mkdir8, readdir as readdir6, readFile as readFile17, writeFile as writeFile6 } from "node:fs/promises";
82144
+ import { dirname as dirname18, join as join28, relative as relative3, resolve as resolve9, sep as sep3 } from "node:path";
82029
82145
 
82030
82146
  // ../../modules/app/contract/src/app.connections.ts
82031
82147
  var appFunctionNameSchema = external_exports.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/);
@@ -84621,10 +84737,10 @@ function unknownCollectionsOf({
84621
84737
  }
84622
84738
 
84623
84739
  // src/services/app-asset-commands.service.ts
84624
- import { createHash as createHash6 } from "node:crypto";
84625
- import { createReadStream as createReadStream2 } from "node:fs";
84626
- import { open as open6, stat as stat9 } from "node:fs/promises";
84627
- import { basename as basename7, resolve as resolve8 } from "node:path";
84740
+ import { createHash as createHash7 } from "node:crypto";
84741
+ import { createReadStream } from "node:fs";
84742
+ import { open as open6, stat as stat8 } from "node:fs/promises";
84743
+ import { basename as basename7, resolve as resolve7 } from "node:path";
84628
84744
  var USAGE2 = `Usage:
84629
84745
  laze app asset add <file> [--type <content type>] upload a video, audio, image, PDF, font or captions file
84630
84746
  laze app asset list the app's assets with their addresses
@@ -84676,8 +84792,8 @@ async function h264LevelOf(path) {
84676
84792
  }
84677
84793
  }
84678
84794
  async function sha256Of2(path) {
84679
- const hash2 = createHash6("sha256");
84680
- for await (const chunk of createReadStream2(path)) hash2.update(chunk);
84795
+ const hash2 = createHash7("sha256");
84796
+ for await (const chunk of createReadStream(path)) hash2.update(chunk);
84681
84797
  return hash2.digest("hex");
84682
84798
  }
84683
84799
  async function sendParts2({
@@ -84736,8 +84852,8 @@ function sizeText(bytes) {
84736
84852
  async function add({ context, args, open: openApp }) {
84737
84853
  const file4 = args.words[3];
84738
84854
  if (!file4) throw new CliUsageError(USAGE2);
84739
- const path = resolve8(context.cwd, file4);
84740
- const info = await stat9(path).catch(() => void 0);
84855
+ const path = resolve7(context.cwd, file4);
84856
+ const info = await stat8(path).catch(() => void 0);
84741
84857
  if (!info?.isFile()) throw new CliUsageError(`No file at ${file4}`);
84742
84858
  if (info.size > MAX_APP_ASSET_BYTES) {
84743
84859
  throw new CliUsageError(
@@ -84831,7 +84947,7 @@ async function appAsset(input2) {
84831
84947
  // src/services/browser-tab-commands.service.ts
84832
84948
  import { mkdir as mkdir7, writeFile as writeFile4 } from "node:fs/promises";
84833
84949
  import { tmpdir as tmpdir2 } from "node:os";
84834
- import { join as join24, resolve as resolve9 } from "node:path";
84950
+ import { join as join25, resolve as resolve8 } from "node:path";
84835
84951
 
84836
84952
  // src/rules/browser-login.rules.ts
84837
84953
  var PASSWORD_NAME = /pass|pwd/i;
@@ -84860,11 +84976,45 @@ function loginValuesOf({
84860
84976
  return username ? { username, password } : { password };
84861
84977
  }
84862
84978
 
84979
+ // src/services/patient-poll.service.ts
84980
+ var BACKOFF_MS = [1e3, 2e3, 4e3, 8e3, 15e3, 3e4];
84981
+ var PROXY_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
84982
+ function transientFailure(error63) {
84983
+ if (error63 instanceof LazeApiError) {
84984
+ return PROXY_STATUSES.has(error63.status) ? `status ${error63.status} ${error63.code}` : void 0;
84985
+ }
84986
+ if (error63 instanceof TypeError) return error63.message;
84987
+ const code4 = error63?.code;
84988
+ return typeof code4 === "string" && /^(E[A-Z]+|UND_ERR_[A-Z_]+)$/.test(code4) ? code4 : void 0;
84989
+ }
84990
+ async function patiently({
84991
+ context,
84992
+ call,
84993
+ giveUpAt = Infinity
84994
+ }) {
84995
+ for (let attempt = 0; ; attempt += 1) {
84996
+ try {
84997
+ return await call();
84998
+ } catch (error63) {
84999
+ const why = transientFailure(error63);
85000
+ if (why === void 0 || context.nowMs() >= giveUpAt) throw error63;
85001
+ if (attempt === 0) {
85002
+ context.err(
85003
+ `laze: Laze is not answering (${why}), probably restarting; still waiting...
85004
+ `
85005
+ );
85006
+ }
85007
+ const wait = BACKOFF_MS[Math.min(attempt, BACKOFF_MS.length - 1)] ?? 0;
85008
+ await context.sleep(Math.max(0, Math.min(wait, giveUpAt - context.nowMs())));
85009
+ }
85010
+ }
85011
+ }
85012
+
84863
85013
  // src/services/vault-commands.service.ts
84864
- import { createHash as createHash7 } from "node:crypto";
85014
+ import { createHash as createHash8 } from "node:crypto";
84865
85015
  import { readFile as readFile15, rm as rm11 } from "node:fs/promises";
84866
- import { hostname as hostname6, tmpdir } from "node:os";
84867
- import { dirname as dirname16, join as join23 } from "node:path";
85016
+ import { hostname as hostname7, tmpdir } from "node:os";
85017
+ import { dirname as dirname17, join as join24 } from "node:path";
84868
85018
 
84869
85019
  // src/rules/vault-session.rules.ts
84870
85020
  function vaultSessionOf({
@@ -84899,7 +85049,7 @@ as the calling Claude Code, Codex, Kanban or terminal session.
84899
85049
  --channel <id> the conversation whose turn it runs in, when the agent answers in several
84900
85050
  --as <name> the session's name on the card when signed in as yourself (or LAZE_SESSION_NAME)`;
84901
85051
  var POLL_MS = 3e3;
84902
- var RESTART_WAIT_MS = 12e4;
85052
+ var RESTART_WAIT_MS = 6e5;
84903
85053
  var RESTART_BACKOFF_MS = [1e3, 2e3, 4e3, 8e3, 1e4];
84904
85054
  var P2562 = { name: "ECDH", namedCurve: "P-256" };
84905
85055
  var ServerGoneError = class extends Error {
@@ -84939,9 +85089,9 @@ function runKeyPathOf({
84939
85089
  connection,
84940
85090
  profile = ""
84941
85091
  }) {
84942
- const name3 = createHash7("sha256").update(connection).digest("hex");
84943
- const base = turnFile ? dirname16(turnFile) : join23(tmpdir(), "laze-vault", profile);
84944
- return join23(base, "vault-run-keys", `${name3}.json`);
85092
+ const name3 = createHash8("sha256").update(connection).digest("hex");
85093
+ const base = turnFile ? dirname17(turnFile) : join24(tmpdir(), "laze-vault", profile);
85094
+ return join24(base, "vault-run-keys", `${name3}.json`);
84945
85095
  }
84946
85096
  async function runKeyAt({ path }) {
84947
85097
  const saved3 = await readStateJson({
@@ -84974,7 +85124,9 @@ async function sendOnce({
84974
85124
  if (init.method === "POST" && !wasRefused) throw error63;
84975
85125
  return { restarting: wasRefused ? "connection refused" : String(error63) };
84976
85126
  }
84977
- if (response.status !== 502 && response.status !== 503) return { response };
85127
+ if (response.status !== 502 && response.status !== 503 && response.status !== 504) {
85128
+ return { response };
85129
+ }
84978
85130
  const code4 = codeOf(await response.clone().text());
84979
85131
  const neverReached = response.status === 503 && code4 === "vault_not_answering";
84980
85132
  if (init.method === "POST" && !neverReached) return { response };
@@ -84993,7 +85145,7 @@ async function reach(input2) {
84993
85145
  }
84994
85146
  if (attempt === 0) {
84995
85147
  context.err(
84996
- `laze vault: the Laze server is not answering (${sent.restarting}), probably restarting; waiting up to 2 min...
85148
+ `laze vault: the Laze server is not answering (${sent.restarting}), probably restarting; waiting up to 10 min...
84997
85149
  `
84998
85150
  );
84999
85151
  }
@@ -85144,7 +85296,7 @@ async function vaultSessionFor({
85144
85296
  harnessSession,
85145
85297
  inherited: context.environment.inherited,
85146
85298
  cwd: context.cwd,
85147
- host: hostname6(),
85299
+ host: hostname7(),
85148
85300
  named: flagText({ args, name: "as" }),
85149
85301
  shellPid: await context.processes.parentOf(context.processes.pid),
85150
85302
  terminal: context.stdoutIsTerminal === true
@@ -85178,7 +85330,11 @@ async function keyRelease({
85178
85330
  extra: { channelId: flagText({ args, name: "channel" }) || null }
85179
85331
  };
85180
85332
  const first = await client.post(door.ask, { ...body, ...door.extra }).catch(refusedRelease);
85181
- const next = (requestId) => client.post(door.status, { requestId, ...door.extra }).catch(refusedRelease);
85333
+ const next = (requestId) => patiently({
85334
+ context,
85335
+ giveUpAt: deadline,
85336
+ call: () => client.post(door.status, { requestId, ...door.extra })
85337
+ }).catch(refusedRelease);
85182
85338
  const release2 = await untilAnswered({ context, first, next, deadline });
85183
85339
  return settled2({ context, release: release2, run: run4, keyPath });
85184
85340
  }
@@ -85352,7 +85508,7 @@ async function saveScreenshot({
85352
85508
  path
85353
85509
  }) {
85354
85510
  if (path) {
85355
- const target = resolve9(context.cwd, path);
85511
+ const target = resolve8(context.cwd, path);
85356
85512
  await writeFile4(target, Buffer.from(shot.image, "base64"), { mode: 384 });
85357
85513
  return target;
85358
85514
  }
@@ -85406,7 +85562,11 @@ async function waitForDone({
85406
85562
  const deadline = context.nowMs() + seconds * 1e3;
85407
85563
  while (context.nowMs() < deadline) {
85408
85564
  await context.sleep(Math.min(ASK_POLL_MS, Math.max(0, deadline - context.nowMs())));
85409
- const now = await client.post(BROWSER_TAB_PATHS.get, { tab: tab.id, ...channel });
85565
+ const now = await patiently({
85566
+ context,
85567
+ giveUpAt: deadline,
85568
+ call: () => client.post(BROWSER_TAB_PATHS.get, { tab: tab.id, ...channel })
85569
+ });
85410
85570
  if (!now.ask) return print9(now, `${who} pressed Done. ${now.title} shows ${now.url}
85411
85571
  `);
85412
85572
  }
@@ -85502,9 +85662,9 @@ async function savedScreenshot({
85502
85662
  nowMs: nowMs2,
85503
85663
  what
85504
85664
  }) {
85505
- const folder = join24(tmpdir2(), "laze-browser");
85665
+ const folder = join25(tmpdir2(), "laze-browser");
85506
85666
  await mkdir7(folder, { recursive: true, mode: 448 });
85507
- const path = join24(folder, `${tabId.replace(/[^a-zA-Z0-9_-]/g, "_")}-${what}-${nowMs2}.jpg`);
85667
+ const path = join25(folder, `${tabId.replace(/[^a-zA-Z0-9_-]/g, "_")}-${what}-${nowMs2}.jpg`);
85508
85668
  await writeFile4(path, Buffer.from(data, "base64"), { mode: 384 });
85509
85669
  return path;
85510
85670
  }
@@ -85982,7 +86142,7 @@ async function appPinsCommand({
85982
86142
  import { execFile } from "node:child_process";
85983
86143
  import { mkdtemp, rm as rm12, writeFile as writeFile5 } from "node:fs/promises";
85984
86144
  import { tmpdir as tmpdir3 } from "node:os";
85985
- import { join as join25 } from "node:path";
86145
+ import { join as join26 } from "node:path";
85986
86146
  import { promisify } from "node:util";
85987
86147
  var run2 = promisify(execFile);
85988
86148
  var MODULE_SYNTAX = /^\s*(import|export)\s/m;
@@ -86011,11 +86171,11 @@ async function scriptErrorsOf({
86011
86171
  const unknown2 = unknownCollectionsOf({ files: files2, collections });
86012
86172
  const scripts = files2.flatMap(scriptsOf);
86013
86173
  if (scripts.length === 0) return unknown2;
86014
- const dir = await mkdtemp(join25(tmpdir3(), "laze-app-check-"));
86174
+ const dir = await mkdtemp(join26(tmpdir3(), "laze-app-check-"));
86015
86175
  try {
86016
86176
  const errors = await Promise.all(
86017
86177
  scripts.map(async (script, index) => {
86018
- const file4 = join25(dir, `${index}.${script.module ? "mjs" : "cjs"}`);
86178
+ const file4 = join26(dir, `${index}.${script.module ? "mjs" : "cjs"}`);
86019
86179
  await writeFile5(file4, script.code);
86020
86180
  try {
86021
86181
  await run2(process.execPath, ["--check", file4]);
@@ -86033,9 +86193,9 @@ async function scriptErrorsOf({
86033
86193
  }
86034
86194
 
86035
86195
  // src/services/app-serve.service.ts
86036
- import { readFile as readFile16, stat as stat10 } from "node:fs/promises";
86196
+ import { readFile as readFile16, stat as stat9 } from "node:fs/promises";
86037
86197
  import { createServer } from "node:http";
86038
- import { extname as extname2, join as join26, normalize, sep as sep2 } from "node:path";
86198
+ import { extname as extname2, join as join27, normalize, sep as sep2 } from "node:path";
86039
86199
  var TYPES2 = {
86040
86200
  ".html": "text/html; charset=utf-8",
86041
86201
  ".js": "text/javascript; charset=utf-8",
@@ -86086,10 +86246,10 @@ async function staticFile({
86086
86246
  if (clean.startsWith("..") || hidden) {
86087
86247
  return json2({ response, status: 404, value: { code: "not_found", message: "Not found" } });
86088
86248
  }
86089
- const candidates = [join26(folder, clean), join26(folder, clean, "index.html")];
86090
- if (!extname2(clean)) candidates.push(join26(folder, "index.html"));
86249
+ const candidates = [join27(folder, clean), join27(folder, clean, "index.html")];
86250
+ if (!extname2(clean)) candidates.push(join27(folder, "index.html"));
86091
86251
  for (const target of candidates) {
86092
- const info = await stat10(target).catch(() => void 0);
86252
+ const info = await stat9(target).catch(() => void 0);
86093
86253
  if (!info?.isFile()) continue;
86094
86254
  const type = TYPES2[extname2(target).toLowerCase()] ?? "application/octet-stream";
86095
86255
  const body = await readFile16(target);
@@ -86178,16 +86338,16 @@ async function serveAppFolder({
86178
86338
  (error63) => failed({ response, error: error63 })
86179
86339
  );
86180
86340
  });
86181
- await new Promise((resolve28, reject) => {
86341
+ await new Promise((resolve27, reject) => {
86182
86342
  server.once("error", reject);
86183
- server.listen(port, "127.0.0.1", () => resolve28());
86343
+ server.listen(port, "127.0.0.1", () => resolve27());
86184
86344
  });
86185
86345
  const { port: bound } = server.address();
86186
86346
  return {
86187
86347
  url: `http://127.0.0.1:${bound}/`,
86188
- close: () => new Promise((resolve28) => {
86348
+ close: () => new Promise((resolve27) => {
86189
86349
  server.closeAllConnections();
86190
- server.close(() => resolve28());
86350
+ server.close(() => resolve27());
86191
86351
  })
86192
86352
  };
86193
86353
  }
@@ -86358,10 +86518,10 @@ function noteRetiredFlags({ context, args }) {
86358
86518
  }
86359
86519
  }
86360
86520
  function folderOf({ context, word: word3 }) {
86361
- return resolve10(context.cwd, word3 ?? ".");
86521
+ return resolve9(context.cwd, word3 ?? ".");
86362
86522
  }
86363
86523
  async function readManifest(folder) {
86364
- const text3 = await readFile17(join27(folder, APP_MANIFEST_FILE), "utf8").catch(() => void 0);
86524
+ const text3 = await readFile17(join28(folder, APP_MANIFEST_FILE), "utf8").catch(() => void 0);
86365
86525
  if (text3 === void 0) return void 0;
86366
86526
  const parsed = appManifestSchema.safeParse(JSON.parse(text3));
86367
86527
  if (!parsed.success) {
@@ -86402,7 +86562,7 @@ async function jsonFlag({
86402
86562
  }) {
86403
86563
  const raw = flagText({ args, name: name3 });
86404
86564
  if (!raw) return void 0;
86405
- const text3 = raw.startsWith("@") ? await readFile17(resolve10(context.cwd, raw.slice(1)), "utf8") : raw;
86565
+ const text3 = raw.startsWith("@") ? await readFile17(resolve9(context.cwd, raw.slice(1)), "utf8") : raw;
86406
86566
  try {
86407
86567
  return JSON.parse(text3);
86408
86568
  } catch {
@@ -86414,8 +86574,8 @@ async function listFiles(folder) {
86414
86574
  const pending2 = [folder];
86415
86575
  while (pending2.length > 0 && found.length <= MAX_FILES) {
86416
86576
  const current3 = pending2.pop() ?? folder;
86417
- for (const entry2 of await readdir7(current3, { withFileTypes: true })) {
86418
- const path = join27(current3, entry2.name);
86577
+ for (const entry2 of await readdir6(current3, { withFileTypes: true })) {
86578
+ const path = join28(current3, entry2.name);
86419
86579
  const rel = relative3(folder, path).split(sep3).join("/");
86420
86580
  if (isSkippedPath({ path: rel })) continue;
86421
86581
  if (entry2.isDirectory()) pending2.push(path);
@@ -86450,12 +86610,12 @@ var appCreate = async ({ context, args }) => {
86450
86610
  ...visibility ? { visibility } : {},
86451
86611
  ...template ? { template } : {}
86452
86612
  });
86453
- const folder = resolve10(context.cwd, flagText({ args, name: "dir", fallback: app2.slug }));
86613
+ const folder = resolve9(context.cwd, flagText({ args, name: "dir", fallback: app2.slug }));
86454
86614
  await mkdir8(folder, { recursive: true });
86455
86615
  const start2 = template ? await templateStart({ client, appId: app2.id, template }) : null;
86456
86616
  for (const file4 of start2?.files ?? []) {
86457
- const target = join27(folder, ...file4.path.split("/"));
86458
- await mkdir8(dirname17(target), { recursive: true });
86617
+ const target = join28(folder, ...file4.path.split("/"));
86618
+ await mkdir8(dirname18(target), { recursive: true });
86459
86619
  await writeFile6(
86460
86620
  target,
86461
86621
  file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
@@ -86467,7 +86627,7 @@ var appCreate = async ({ context, args }) => {
86467
86627
  views: [...start2?.template.views ?? []],
86468
86628
  seed: { ...start2?.template.seed }
86469
86629
  };
86470
- await writeFile6(join27(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86630
+ await writeFile6(join28(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86471
86631
  `);
86472
86632
  const where = relative3(context.cwd, folder) || ".";
86473
86633
  const created = start2 ? `Created ${app2.name} (${app2.id}) from the ${template} template in ${where}; its first version is live at ${app2.publishedUrl}.
@@ -86605,7 +86765,7 @@ var appWrite = async ({ context, args }) => {
86605
86765
  const remove9 = (flagText({ args, name: "remove" }) ?? "").split(",").map((path) => path.trim()).filter(Boolean);
86606
86766
  const files2 = await Promise.all(
86607
86767
  words.slice(2).map(async (word3) => {
86608
- const path = resolve10(context.cwd, word3);
86768
+ const path = resolve9(context.cwd, word3);
86609
86769
  const { bytes: _bytes, ...file4 } = buildFileOf({
86610
86770
  path: relative3(folder, path).split(sep3).join("/"),
86611
86771
  bytes: await readFile17(path)
@@ -86697,7 +86857,7 @@ async function folderClaim({
86697
86857
  folder,
86698
86858
  appId
86699
86859
  }) {
86700
- const entries = await readdir7(folder).catch(() => []);
86860
+ const entries = await readdir6(folder).catch(() => []);
86701
86861
  if (entries.length === 0) return "empty";
86702
86862
  const manifest = await readManifest(folder).catch(() => void 0);
86703
86863
  if (!manifest) return "other-files";
@@ -86735,8 +86895,8 @@ var appPull = async ({ context, args }) => {
86735
86895
  );
86736
86896
  }
86737
86897
  for (const file4 of pulled.files) {
86738
- const target = join27(folder, ...file4.path.split("/"));
86739
- await mkdir8(dirname17(target), { recursive: true });
86898
+ const target = join28(folder, ...file4.path.split("/"));
86899
+ await mkdir8(dirname18(target), { recursive: true });
86740
86900
  await writeFile6(
86741
86901
  target,
86742
86902
  file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
@@ -86754,7 +86914,7 @@ var appPull = async ({ context, args }) => {
86754
86914
  ])
86755
86915
  )
86756
86916
  };
86757
- await writeFile6(join27(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86917
+ await writeFile6(join28(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86758
86918
  `);
86759
86919
  const names = pulled.collections.map((collection) => collection.name);
86760
86920
  const where = relative3(context.cwd, folder) || ".";
@@ -87061,7 +87221,7 @@ var appExport = async ({ context, args }) => {
87061
87221
  });
87062
87222
  const out = flagText({ args, name: "out" });
87063
87223
  if (!out) return context.out(exported.body);
87064
- const target = resolve10(context.cwd, out);
87224
+ const target = resolve9(context.cwd, out);
87065
87225
  await writeFile6(target, exported.body);
87066
87226
  context.out(`Wrote ${exported.rows} records to ${relative3(context.cwd, target)}
87067
87227
  `);
@@ -87070,7 +87230,7 @@ var appImport = async ({ context, args }) => {
87070
87230
  const words = args.words.slice(2);
87071
87231
  const [named, collection, file4] = words.length >= 3 ? words : [void 0, ...words];
87072
87232
  if (!collection || !file4) throw new CliUsageError(USAGE7);
87073
- const csv = await readFile17(resolve10(context.cwd, file4), "utf8").catch(() => {
87233
+ const csv = await readFile17(resolve9(context.cwd, file4), "utf8").catch(() => {
87074
87234
  throw new CliUsageError(`Cannot read ${file4}`);
87075
87235
  });
87076
87236
  const scoped = named ? { ...args, flags: { ...args.flags, app: named } } : args;
@@ -87088,7 +87248,7 @@ var appImport = async ({ context, args }) => {
87088
87248
  });
87089
87249
  const refusedOut = flagText({ args, name: "refused" });
87090
87250
  if (refusedOut && result2.refusedCsv) {
87091
- await writeFile6(resolve10(context.cwd, refusedOut), result2.refusedCsv);
87251
+ await writeFile6(resolve9(context.cwd, refusedOut), result2.refusedCsv);
87092
87252
  }
87093
87253
  const fitting = result2.rows - result2.refused.length;
87094
87254
  const skipped = result2.refused.slice(0, 20).map((row) => ` line ${row.line}: ${row.reason}
@@ -87505,14 +87665,14 @@ async function app({ context, args }) {
87505
87665
  }
87506
87666
 
87507
87667
  // src/services/auth-commands.service.ts
87508
- import { hostname as hostname7 } from "node:os";
87668
+ import { hostname as hostname8 } from "node:os";
87509
87669
 
87510
87670
  // src/rules/machine-proof.rules.ts
87511
- import { createHash as createHash8, randomBytes as randomBytes2 } from "node:crypto";
87671
+ import { createHash as createHash9, randomBytes as randomBytes2 } from "node:crypto";
87512
87672
  var b64url3 = (bytes) => Buffer.from(bytes).toString("base64url");
87513
87673
  function thumbprintOf({ jwk }) {
87514
87674
  const canonical = JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y });
87515
- return b64url3(createHash8("sha256").update(canonical).digest());
87675
+ return b64url3(createHash9("sha256").update(canonical).digest());
87516
87676
  }
87517
87677
  function lazeTokenOf({ authorization }) {
87518
87678
  const match = /^Bearer (lz_\S+)$/.exec(authorization ?? "");
@@ -87536,7 +87696,7 @@ function machineProofOf({
87536
87696
  htu: url2,
87537
87697
  iat: Math.floor(nowMs2 / 1e3),
87538
87698
  jti,
87539
- ath: b64url3(createHash8("sha256").update(credential).digest()),
87699
+ ath: b64url3(createHash9("sha256").update(credential).digest()),
87540
87700
  lz_tier: tier,
87541
87701
  ...tailscaleNodeId ? { lz_ts: tailscaleNodeId } : {}
87542
87702
  })
@@ -87609,7 +87769,7 @@ async function deviceToken({
87609
87769
  clientName: flagText({
87610
87770
  args,
87611
87771
  name: "client",
87612
- fallback: `laze CLI on ${hostname7()}`.slice(0, 80)
87772
+ fallback: `laze CLI on ${hostname8()}`.slice(0, 80)
87613
87773
  }),
87614
87774
  ...machineKey ? { machineKey } : {}
87615
87775
  });
@@ -88022,7 +88182,7 @@ async function billing({ context, args }) {
88022
88182
  // src/services/browser-commands.service.ts
88023
88183
  import { randomBytes as randomBytes3 } from "node:crypto";
88024
88184
  import { readFile as readFile18 } from "node:fs/promises";
88025
- import { dirname as dirname18, join as join28 } from "node:path";
88185
+ import { dirname as dirname19, join as join29 } from "node:path";
88026
88186
 
88027
88187
  // src/services/cdp-bridge.service.ts
88028
88188
  import { spawn as spawn3 } from "node:child_process";
@@ -88053,7 +88213,7 @@ function tunnel({
88053
88213
  host: host2,
88054
88214
  port
88055
88215
  }) {
88056
- return new Promise((resolve28, reject) => {
88216
+ return new Promise((resolve27, reject) => {
88057
88217
  const socket = connectTcp(proxy.port, proxy.host);
88058
88218
  let answer6 = "";
88059
88219
  const auth = proxy.authorization ? `Proxy-Authorization: ${proxy.authorization}\r
@@ -88070,7 +88230,7 @@ ${auth}\r
88070
88230
  answer6 += chunk.toString("latin1");
88071
88231
  if (!answer6.includes(HEADER_END)) return;
88072
88232
  socket.off("data", onData);
88073
- if (/^HTTP\/1\.[01] 200/.test(answer6)) return resolve28(socket);
88233
+ if (/^HTTP\/1\.[01] 200/.test(answer6)) return resolve27(socket);
88074
88234
  socket.destroy();
88075
88235
  reject(new Error(`proxy refused the tunnel: ${answer6.split("\r\n")[0] ?? ""}`));
88076
88236
  };
@@ -88083,8 +88243,8 @@ async function upstreamOf({ target, proxy }) {
88083
88243
  const raw = proxy ? await tunnel({ proxy, host: target.hostname, port }) : connectTcp(port, target.hostname);
88084
88244
  if (!secure) return raw;
88085
88245
  const tls = connectTls({ socket: raw, servername: target.hostname });
88086
- await new Promise((resolve28, reject) => {
88087
- tls.once("secureConnect", () => resolve28());
88246
+ await new Promise((resolve27, reject) => {
88247
+ tls.once("secureConnect", () => resolve27());
88088
88248
  tls.once("error", reject);
88089
88249
  });
88090
88250
  return tls;
@@ -88126,8 +88286,8 @@ async function browserSocket({
88126
88286
  createConnection: () => upstream,
88127
88287
  perMessageDeflate: false
88128
88288
  });
88129
- await new Promise((resolve28, reject) => {
88130
- socket.once("open", () => resolve28());
88289
+ await new Promise((resolve27, reject) => {
88290
+ socket.once("open", () => resolve27());
88131
88291
  socket.once("error", reject);
88132
88292
  });
88133
88293
  return socket;
@@ -88140,12 +88300,12 @@ async function browserCall({
88140
88300
  }) {
88141
88301
  const socket = await browserSocket({ target, proxy });
88142
88302
  try {
88143
- return await new Promise((resolve28, reject) => {
88303
+ return await new Promise((resolve27, reject) => {
88144
88304
  socket.on("message", (data) => {
88145
88305
  const reply2 = JSON.parse(textOf3(data));
88146
88306
  if (reply2.id !== 1) return;
88147
88307
  if (reply2.error) reject(new Error(`${method}: ${JSON.stringify(reply2.error)}`));
88148
- else resolve28(reply2.result ?? {});
88308
+ else resolve27(reply2.result ?? {});
88149
88309
  });
88150
88310
  socket.once(
88151
88311
  "close",
@@ -88309,18 +88469,18 @@ function retargetCdpBridge({
88309
88469
  target,
88310
88470
  expiresAt
88311
88471
  }) {
88312
- return new Promise((resolve28) => {
88472
+ return new Promise((resolve27) => {
88313
88473
  const call = httpRequest(
88314
88474
  { host: "127.0.0.1", port, path: TARGET_PATH, method: "PUT", timeout: 2e3 },
88315
88475
  (response) => {
88316
88476
  response.resume();
88317
- resolve28(response.statusCode === 204);
88477
+ resolve27(response.statusCode === 204);
88318
88478
  }
88319
88479
  );
88320
88480
  call.setHeader(KEY_HEADER, key);
88321
88481
  call.setHeader("content-type", "application/json");
88322
88482
  call.once("timeout", () => call.destroy());
88323
- call.once("error", () => resolve28(false));
88483
+ call.once("error", () => resolve27(false));
88324
88484
  call.end(JSON.stringify({ target, expiresAt }));
88325
88485
  });
88326
88486
  }
@@ -88369,15 +88529,15 @@ async function startCdpBridge({
88369
88529
  (socket) => relayPage({ client: socket, targetId, target: url2, proxy })
88370
88530
  );
88371
88531
  });
88372
- await new Promise((resolve28) => server.listen(0, "127.0.0.1", resolve28));
88532
+ await new Promise((resolve27) => server.listen(0, "127.0.0.1", resolve27));
88373
88533
  const port = server.address().port;
88374
88534
  return {
88375
88535
  port,
88376
- close: () => new Promise((resolve28) => {
88536
+ close: () => new Promise((resolve27) => {
88377
88537
  for (const client of relayed) client.destroy();
88378
88538
  pages.close();
88379
88539
  server.closeAllConnections();
88380
- server.close(() => resolve28());
88540
+ server.close(() => resolve27());
88381
88541
  })
88382
88542
  };
88383
88543
  }
@@ -88394,7 +88554,7 @@ function launchCdpBridge({
88394
88554
  stdio: ["ignore", "pipe", "ignore"],
88395
88555
  env: { ...env, LAZE_CDP_TARGET: target, LAZE_CDP_EXPIRES_AT: expiresAt, LAZE_CDP_KEY: key }
88396
88556
  });
88397
- return new Promise((resolve28, reject) => {
88557
+ return new Promise((resolve27, reject) => {
88398
88558
  let printed2 = "";
88399
88559
  child.once("error", reject);
88400
88560
  child.once("exit", (code4) => reject(new Error(`the CDP bridge stopped (${code4})`)));
@@ -88405,7 +88565,7 @@ function launchCdpBridge({
88405
88565
  child.stdout.destroy();
88406
88566
  child.removeAllListeners("exit");
88407
88567
  child.unref();
88408
- if (Number.isInteger(port) && port > 0) resolve28(port);
88568
+ if (Number.isInteger(port) && port > 0) resolve27(port);
88409
88569
  else reject(new Error("the CDP bridge printed no port"));
88410
88570
  });
88411
88571
  });
@@ -88532,7 +88692,7 @@ async function answering({
88532
88692
  }
88533
88693
  function bridgeStatePath({ context, machine: machine2 }) {
88534
88694
  const safe = machine2.replace(/[^a-zA-Z0-9_-]/g, "_");
88535
- return join28(dirname18(context.environment.configPath), "bridges", `${safe}.json`);
88695
+ return join29(dirname19(context.environment.configPath), "bridges", `${safe}.json`);
88536
88696
  }
88537
88697
  async function bridgePort({
88538
88698
  context,
@@ -89246,7 +89406,7 @@ async function channelSettings({ context, args }) {
89246
89406
 
89247
89407
  // src/services/chat-actions-commands.service.ts
89248
89408
  import { readFile as readFile19 } from "node:fs/promises";
89249
- import { basename as basename9, isAbsolute as isAbsolute2, relative as relative4, resolve as resolve12 } from "node:path";
89409
+ import { basename as basename9, isAbsolute as isAbsolute2, relative as relative4, resolve as resolve11 } from "node:path";
89250
89410
 
89251
89411
  // src/rules/app-link.rules.ts
89252
89412
  var MARKDOWN_LINK = /^\[[^\]]*\]\((\S+)\)$/;
@@ -89274,8 +89434,8 @@ function appOfLinkOnly(body) {
89274
89434
 
89275
89435
  // src/services/file-download.service.ts
89276
89436
  import { createWriteStream } from "node:fs";
89277
- import { mkdir as mkdir9, rename as rename3, rm as rm13, stat as stat11, truncate } from "node:fs/promises";
89278
- import { basename as basename8, dirname as dirname19, resolve as resolve11 } from "node:path";
89437
+ import { mkdir as mkdir9, rename as rename3, rm as rm13, stat as stat10, truncate } from "node:fs/promises";
89438
+ import { basename as basename8, dirname as dirname20, resolve as resolve10 } from "node:path";
89279
89439
  import { Readable, Transform } from "node:stream";
89280
89440
  import { pipeline } from "node:stream/promises";
89281
89441
  var NOT_READY_WAIT_MS = 5e3;
@@ -89323,7 +89483,7 @@ function totalOf({ response, start: start2 }) {
89323
89483
  if (length === null) return void 0;
89324
89484
  return Number(length) + (response.status === 206 ? start2 : 0);
89325
89485
  }
89326
- var sizeOnDisk = (path) => stat11(path).then(
89486
+ var sizeOnDisk = (path) => stat10(path).then(
89327
89487
  (found) => found.size,
89328
89488
  () => 0
89329
89489
  );
@@ -89394,9 +89554,9 @@ async function downloadFile({
89394
89554
  attachmentId,
89395
89555
  out
89396
89556
  }) {
89397
- const asked = out ? resolve11(context.cwd, out) : void 0;
89398
- const part = resolve11(asked ? dirname19(asked) : context.cwd, `.${attachmentId}.part`);
89399
- await mkdir9(dirname19(part), { recursive: true });
89557
+ const asked = out ? resolve10(context.cwd, out) : void 0;
89558
+ const part = resolve10(asked ? dirname20(asked) : context.cwd, `.${attachmentId}.part`);
89559
+ await mkdir9(dirname20(part), { recursive: true });
89400
89560
  const named = await fetchWhole({ context, client, attachmentId, part, out }).catch(
89401
89561
  async (error63) => {
89402
89562
  await rm13(part, { force: true });
@@ -89404,7 +89564,7 @@ async function downloadFile({
89404
89564
  throw new CliUsageError(`Could not write ${attachmentId} to disk: ${String(error63)}`);
89405
89565
  }
89406
89566
  );
89407
- const path = asked ?? resolve11(context.cwd, named ?? attachmentId);
89567
+ const path = asked ?? resolve10(context.cwd, named ?? attachmentId);
89408
89568
  await rename3(part, path);
89409
89569
  return { path, sizeBytes: await sizeOnDisk(path) };
89410
89570
  }
@@ -89695,7 +89855,7 @@ function uploadNameOf({ cwd, path }) {
89695
89855
  return inside && !inside.startsWith("..") && !isAbsolute2(inside) ? inside : basename9(path);
89696
89856
  }
89697
89857
  var fileUpload = async ({ context, args, client }) => {
89698
- const path = resolve12(context.cwd, wordAt(args, 3));
89858
+ const path = resolve11(context.cwd, wordAt(args, 3));
89699
89859
  const bytes = new Uint8Array(await readFile19(path));
89700
89860
  const answer6 = await uploadFile({
89701
89861
  context,
@@ -89927,20 +90087,8 @@ async function monitorRound(turn) {
89927
90087
  `);
89928
90088
  return false;
89929
90089
  }
89930
- const named = { ...turn.args, flags: { ...turn.args.flags, profile: turn.profile } };
89931
- const { client } = await signedIn({ context, args: named });
89932
- const claim3 = forSession({ client, session });
89933
- const refused = await notBoundNotice({
89934
- context,
89935
- client: claim3,
89936
- session,
89937
- error: error63,
89938
- profile: turn.profile
89939
- });
89940
- if (refused?.rebound) return true;
89941
- if (refused?.notice) context.out(`${refused.notice}
89942
- `);
89943
- if (!refused) context.err(`laze: the monitor will try again: ${String(error63)}
90090
+ if (await droppedBinding({ context, session, error: error63, profile: turn.profile })) return false;
90091
+ context.err(`laze: the monitor will try again: ${String(error63)}
89944
90092
  `);
89945
90093
  return false;
89946
90094
  });
@@ -89952,13 +90100,13 @@ async function release({ context, profile }) {
89952
90100
  }
89953
90101
  async function monitorHook({ context, args }) {
89954
90102
  const claudePid = await claudePidOf({ context });
89955
- const session = await monitorSessionOf({ context, claudePid });
89956
- await rememberSession({ context, claudePid, session }).catch(() => void 0);
90103
+ const first = await monitorSessionOf({ context, claudePid });
90104
+ await rememberSession({ context, claudePid, session: first }).catch(() => void 0);
89957
90105
  const held = /* @__PURE__ */ new Set();
89958
- const turn = { context, args, claudePid, session };
89959
90106
  try {
89960
90107
  while (claudePid && context.processes.alive(claudePid)) {
89961
- const round = await oneRound({ turn, held });
90108
+ const session = await monitorSessionOf({ context, claudePid }) ?? first;
90109
+ const round = await oneRound({ turn: { context, args, claudePid, session }, held });
89962
90110
  if (round === "outranked") await context.sleep(MONITOR_OUTRANKED_MS);
89963
90111
  else if (!round) await context.sleep(MONITOR_IDLE_MS);
89964
90112
  }
@@ -89969,7 +90117,7 @@ async function monitorHook({ context, args }) {
89969
90117
  }
89970
90118
  async function oneRound({ turn, held }) {
89971
90119
  try {
89972
- const profile = await agentProfileHere(turn);
90120
+ const profile = await agentProfileHere({ context: turn.context, session: turn.session });
89973
90121
  const round = profile ? await monitorRound({ ...turn, profile }) : false;
89974
90122
  if (profile && round === true) held.add(profile);
89975
90123
  return round;
@@ -89985,9 +90133,9 @@ async function monitorSessionOf({
89985
90133
  }) {
89986
90134
  const sessionId = context.environment.inherited.CLAUDE_CODE_SESSION_ID;
89987
90135
  const fromEnv = sessionOf({ context, harness: "claude-code", sessionId });
89988
- if (fromEnv || !claudePid) return fromEnv;
90136
+ if (!claudePid) return fromEnv;
89989
90137
  const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
89990
- return readStateJson({ path });
90138
+ return await readStateJson({ path }) ?? fromEnv;
89991
90139
  }
89992
90140
 
89993
90141
  // ../../modules/compute/contract/src/browser-tab.ts
@@ -92834,9 +92982,9 @@ var computerBrowserFactsDefinition = external_exports.object({
92834
92982
  var computerBrowserFactsSchema = computerBrowserFactsDefinition;
92835
92983
 
92836
92984
  // src/services/computer-copy-commands.service.ts
92837
- import { mkdtemp as mkdtemp2, open as open7, rm as rm15, stat as stat12 } from "node:fs/promises";
92985
+ import { mkdtemp as mkdtemp2, open as open7, rm as rm15, stat as stat11 } from "node:fs/promises";
92838
92986
  import { tmpdir as tmpdir4 } from "node:os";
92839
- import { basename as basename10, dirname as dirname20, resolve as resolve13 } from "node:path";
92987
+ import { basename as basename10, dirname as dirname21, resolve as resolve12 } from "node:path";
92840
92988
  var COMPUTER_COPY_USAGE = ` laze computer copy <path> --agent <agent> [--to <folder>] [--json]
92841
92989
  copy a local file or folder into your hosted agent's work folder
92842
92990
  (its owner only, up to 2 GiB packed); <folder> is relative to the
@@ -92850,9 +92998,9 @@ function stringFlag(args, name3) {
92850
92998
  }
92851
92999
  function packingOf({ path, isDirectory }) {
92852
93000
  const contents = isDirectory && path.endsWith("/");
92853
- const absolute = resolve13(path);
93001
+ const absolute = resolve12(path);
92854
93002
  const name3 = basename10(absolute);
92855
- return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent: dirname20(absolute), entry: name3 };
93003
+ return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent: dirname21(absolute), entry: name3 };
92856
93004
  }
92857
93005
  async function sendParts3({
92858
93006
  context,
@@ -92896,22 +93044,22 @@ async function copy({ context, args }) {
92896
93044
  if (!path || !agent3) throw new CliUsageError(`Usage:
92897
93045
  ${COMPUTER_COPY_USAGE}`);
92898
93046
  const to = stringFlag(args, "to") ?? ".";
92899
- const full = resolve13(context.cwd, path);
92900
- const found = await stat12(full).catch(() => void 0);
93047
+ const full = resolve12(context.cwd, path);
93048
+ const found = await stat11(full).catch(() => void 0);
92901
93049
  if (!found) throw new CliUsageError(`${path} does not exist`);
92902
93050
  const { name: name3, parent, entry: entry2 } = packingOf({
92903
93051
  path: path.endsWith("/") ? `${full}/` : full,
92904
93052
  isDirectory: found.isDirectory()
92905
93053
  });
92906
- const dir = await mkdtemp2(resolve13(tmpdir4(), "laze-copy-"));
92907
- const archive2 = resolve13(dir, `${name3}.tar.gz`);
93054
+ const dir = await mkdtemp2(resolve12(tmpdir4(), "laze-copy-"));
93055
+ const archive2 = resolve12(dir, `${name3}.tar.gz`);
92908
93056
  try {
92909
93057
  const code4 = await context.runCommand({
92910
93058
  command: ["tar", "-czf", archive2, "-C", parent, entry2],
92911
93059
  env: { COPYFILE_DISABLE: "1" }
92912
93060
  });
92913
93061
  if (code4 !== 0) throw new CliUsageError(`tar could not pack ${path} (exit ${code4})`);
92914
- const sizeBytes = (await stat12(archive2)).size;
93062
+ const sizeBytes = (await stat11(archive2)).size;
92915
93063
  if (sizeBytes > COMPUTER_COPY_MAX_BYTES)
92916
93064
  throw new CliUsageError(`${path} packs to ${mb(sizeBytes)}; a copy holds at most 2 GiB`);
92917
93065
  const client = await computeClient({ context, args });
@@ -93235,8 +93383,8 @@ import { readFile as readFile21 } from "node:fs/promises";
93235
93383
 
93236
93384
  // src/services/mcp-gateway.service.ts
93237
93385
  import { mkdir as mkdir10, readFile as readFile20, writeFile as writeFile7 } from "node:fs/promises";
93238
- import { basename as basename11, join as join29, resolve as resolve14 } from "node:path";
93239
- import { createInterface as createInterface3 } from "node:readline";
93386
+ import { basename as basename11, join as join30, resolve as resolve13 } from "node:path";
93387
+ import { createInterface as createInterface2 } from "node:readline";
93240
93388
 
93241
93389
  // src/services/mcp-support.service.ts
93242
93390
  var SUPPORT_TOOL_NAMES = ["support_read_thread", "support_answer", "support_needs_human"];
@@ -93335,7 +93483,7 @@ function serveMcpGateway({
93335
93483
  context,
93336
93484
  args
93337
93485
  }) {
93338
- return relayMcpLines({ context, args, lines: createInterface3({ input: process.stdin }) });
93486
+ return relayMcpLines({ context, args, lines: createInterface2({ input: process.stdin }) });
93339
93487
  }
93340
93488
  var WATCH_MS2 = 2e3;
93341
93489
  var LIST_CHANGED = '{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}';
@@ -93378,7 +93526,7 @@ async function relayMcpLines({
93378
93526
  const relay2 = {
93379
93527
  readTurn,
93380
93528
  out: (text3) => context.out(text3),
93381
- saveFile: (file4) => saveMailFile({ root: resolve14(context.cwd, MAIL_FILES_DIR), file: file4 }),
93529
+ saveFile: (file4) => saveMailFile({ root: resolve13(context.cwd, MAIL_FILES_DIR), file: file4 }),
93382
93530
  post: async ({ line, turn }) => {
93383
93531
  if (args.flags.support === true) return answerSupportLine({ line, turn, client });
93384
93532
  const response = await context.fetcher(url2, {
@@ -93414,8 +93562,8 @@ function safeName(name3, fallback) {
93414
93562
  return last && last !== "." && last !== ".." ? last : fallback;
93415
93563
  }
93416
93564
  async function saveMailFile({ root, file: file4 }) {
93417
- const dir = join29(root, safeName(file4.messageId, "message"));
93418
- const path = join29(dir, safeName(file4.fileName, "attachment"));
93565
+ const dir = join30(root, safeName(file4.messageId, "message"));
93566
+ const path = join30(dir, safeName(file4.fileName, "attachment"));
93419
93567
  await mkdir10(dir, { recursive: true });
93420
93568
  await writeFile7(path, Buffer.from(file4.base64, "base64"));
93421
93569
  return path;
@@ -93666,7 +93814,7 @@ async function suggestServer({
93666
93814
 
93667
93815
  // src/services/connector-commands.service.ts
93668
93816
  import { readFile as readFile23 } from "node:fs/promises";
93669
- import { resolve as resolve15 } from "node:path";
93817
+ import { resolve as resolve14 } from "node:path";
93670
93818
 
93671
93819
  // src/services/vault-keychain-commands.service.ts
93672
93820
  import { readFile as readFile22 } from "node:fs/promises";
@@ -94326,7 +94474,7 @@ async function keyText({ context, args }) {
94326
94474
  throw new CliUsageError("A key never goes in a flag: pipe it on stdin or use --from-file.");
94327
94475
  }
94328
94476
  const file4 = flagText({ args, name: "from-file" });
94329
- const text3 = file4 ? await readFile23(resolve15(context.cwd, file4), "utf8") : await context.readStdin();
94477
+ const text3 = file4 ? await readFile23(resolve14(context.cwd, file4), "utf8") : await context.readStdin();
94330
94478
  const trimmed = text3.trim();
94331
94479
  if (!trimmed) throw new CliUsageError("No key: pipe it on stdin or use --from-file.");
94332
94480
  return trimmed;
@@ -94716,7 +94864,7 @@ async function conversationDelete({ context, args }) {
94716
94864
 
94717
94865
  // src/services/discord-commands.service.ts
94718
94866
  import { readFile as readFile24 } from "node:fs/promises";
94719
- import { resolve as resolve16 } from "node:path";
94867
+ import { resolve as resolve15 } from "node:path";
94720
94868
 
94721
94869
  // ../../modules/discord/contract/src/discord.ts
94722
94870
  var workspaceIdSchema25 = external_exports.string().min(1).max(64);
@@ -95063,7 +95211,7 @@ async function secretsOf({ context, args }) {
95063
95211
  const fromConnection = flagText({ args, name: "from-vault" });
95064
95212
  if (fromConnection) return { fromConnection };
95065
95213
  const file4 = flagText({ args, name: "from-file" });
95066
- const text3 = file4 ? await readFile24(resolve16(context.cwd, file4), "utf8") : await context.readStdin();
95214
+ const text3 = file4 ? await readFile24(resolve15(context.cwd, file4), "utf8") : await context.readStdin();
95067
95215
  const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
95068
95216
  if (lines2.length !== 2) {
95069
95217
  throw new CliUsageError(
@@ -95333,8 +95481,8 @@ var DOMAINS_USAGE = `Usage:
95333
95481
  var printJson5 = (context, data) => context.out(`${JSON.stringify(data, null, 2)}
95334
95482
  `);
95335
95483
  function printDomain(context, row) {
95336
- const join37 = row.autoJoin ? "auto-join on" : "auto-join off";
95337
- context.out(`${row.domain} ${join37}${row.enforced ? " single sign-on enforced" : ""}
95484
+ const join38 = row.autoJoin ? "auto-join on" : "auto-join off";
95485
+ context.out(`${row.domain} ${join38}${row.enforced ? " single sign-on enforced" : ""}
95338
95486
  `);
95339
95487
  }
95340
95488
  async function list5({ context, args }) {
@@ -95367,7 +95515,7 @@ async function domains({ context, args }) {
95367
95515
 
95368
95516
  // src/services/emoji-commands.service.ts
95369
95517
  import { readFile as readFile25 } from "node:fs/promises";
95370
- import { resolve as resolve17 } from "node:path";
95518
+ import { resolve as resolve16 } from "node:path";
95371
95519
  var EMOJI_USAGE = `Usage:
95372
95520
  laze emoji list [--json] the workspace's custom emoji, aliases and who added each
95373
95521
  laze emoji add <name> <file> [--alias <a,b>] add a PNG, JPEG or GIF as :name: (made 128px square)
@@ -95407,7 +95555,7 @@ async function addEmoji({ context, args, client }) {
95407
95555
  const file4 = wordAt4(args, 3);
95408
95556
  let bytes;
95409
95557
  try {
95410
- bytes = new Uint8Array(await readFile25(resolve17(context.cwd, file4)));
95558
+ bytes = new Uint8Array(await readFile25(resolve16(context.cwd, file4)));
95411
95559
  } catch {
95412
95560
  throw new CliUsageError(`Cannot read ${file4}.`);
95413
95561
  }
@@ -95747,7 +95895,7 @@ var ExternalSharingHooksToken = externalUi.hooks("sharing");
95747
95895
 
95748
95896
  // src/services/workspace-commands.service.ts
95749
95897
  import { readFile as readFile26 } from "node:fs/promises";
95750
- import { resolve as resolve18 } from "node:path";
95898
+ import { resolve as resolve17 } from "node:path";
95751
95899
  var ROLE_NAMES2 = {
95752
95900
  OWNER: "Owner",
95753
95901
  ADMIN: "Admin",
@@ -95929,7 +96077,7 @@ var LOGO_USAGE = "Usage: laze workspace logo set <file.png|jpg|webp> | laze work
95929
96077
  async function readLogo({ context, file: file4 }) {
95930
96078
  let bytes;
95931
96079
  try {
95932
- bytes = new Uint8Array(await readFile26(resolve18(context.cwd, file4)));
96080
+ bytes = new Uint8Array(await readFile26(resolve17(context.cwd, file4)));
95933
96081
  } catch {
95934
96082
  throw new CliUsageError(`No file to read at ${file4}.`);
95935
96083
  }
@@ -96565,7 +96713,7 @@ async function agentFeedAccess({
96565
96713
 
96566
96714
  // src/services/feed-commands.service.ts
96567
96715
  import { readFile as readFile27 } from "node:fs/promises";
96568
- import { resolve as resolve19 } from "node:path";
96716
+ import { resolve as resolve18 } from "node:path";
96569
96717
 
96570
96718
  // ../../modules/feed/contract/src/feed.delegate.ts
96571
96719
  var feedDelegateSchemaDefinition = external_exports.object({
@@ -97792,7 +97940,7 @@ async function bodyOf2({
97792
97940
  flags: flags2
97793
97941
  }) {
97794
97942
  const body = { ...flags2.fields };
97795
- const read4 = (source) => "file" in source ? readFile27(resolve19(context.cwd, source.file), "utf8") : source.text;
97943
+ const read4 = (source) => "file" in source ? readFile27(resolve18(context.cwd, source.file), "utf8") : source.text;
97796
97944
  for (const [field, source] of Object.entries(flags2.texts)) body[field] = await read4(source);
97797
97945
  if (flags2.rich) {
97798
97946
  const text3 = await read4(flags2.rich.source);
@@ -98069,7 +98217,7 @@ async function textFlag({
98069
98217
  }) {
98070
98218
  const value = flagText({ args, name: name3 });
98071
98219
  if (!value.startsWith("@")) return value;
98072
- return readFile27(resolve19(context.cwd, value.slice(1)), "utf8");
98220
+ return readFile27(resolve18(context.cwd, value.slice(1)), "utf8");
98073
98221
  }
98074
98222
  async function feedList({ context, args }) {
98075
98223
  const { client, profile } = await signedIn({ context, args });
@@ -98159,7 +98307,7 @@ async function ranksOf({
98159
98307
  }) {
98160
98308
  const file4 = flagText({ args, name: "file" });
98161
98309
  if (file4) {
98162
- const parsed = JSON.parse(await readFile27(resolve19(context.cwd, file4), "utf8"));
98310
+ const parsed = JSON.parse(await readFile27(resolve18(context.cwd, file4), "utf8"));
98163
98311
  if (Array.isArray(parsed)) return parsed;
98164
98312
  throw new CliUsageError("--file holds a list of {itemId, priority}");
98165
98313
  }
@@ -99027,12 +99175,12 @@ async function ip({ context, args }) {
99027
99175
 
99028
99176
  // src/services/join-commands.service.ts
99029
99177
  import { rm as rm16 } from "node:fs/promises";
99030
- import { hostname as hostname8 } from "node:os";
99031
- import { dirname as dirname21, join as join30 } from "node:path";
99178
+ import { hostname as hostname9 } from "node:os";
99179
+ import { dirname as dirname22, join as join31 } from "node:path";
99032
99180
  var DEFAULT_WAIT_SECONDS2 = 100;
99033
99181
  var JOIN_USAGE = "Usage: laze join [--workspace <name|id|invite link>] [--for <email>] [--name <name>] [--note <text>] [--timeout <seconds>] [--project <folder>]";
99034
99182
  function pendingPathOf({ context }) {
99035
- return join30(dirname21(context.environment.configPath), "join", "pending.json");
99183
+ return join31(dirname22(context.environment.configPath), "join", "pending.json");
99036
99184
  }
99037
99185
  async function readPending({
99038
99186
  context,
@@ -99169,7 +99317,7 @@ async function joinAsAgent({ context, args }) {
99169
99317
  harness,
99170
99318
  ...asked,
99171
99319
  ...machineOwners.length > 0 ? { machineOwners } : {},
99172
- machine: hostname8().slice(0, 120),
99320
+ machine: hostname9().slice(0, 120),
99173
99321
  ...flagText({ args, name: "name" }) ? { name: flagText({ args, name: "name" }) } : {},
99174
99322
  ...flagText({ args, name: "note" }) ? { note: flagText({ args, name: "note" }) } : {}
99175
99323
  }).then((started) => ({ ...started, url: url2, asked })).catch((error63) => sandboxed({ context, error: error63 }));
@@ -100057,7 +100205,7 @@ async function machine({ context, args }) {
100057
100205
  }
100058
100206
 
100059
100207
  // src/services/mcp-server.service.ts
100060
- import { createInterface as createInterface4 } from "node:readline";
100208
+ import { createInterface as createInterface3 } from "node:readline";
100061
100209
  var SERVER_REFUSED = -32001;
100062
100210
  var MCP_REFUSED_COMMANDS = /* @__PURE__ */ new Set([
100063
100211
  "login",
@@ -100301,24 +100449,24 @@ async function serveMcp({
100301
100449
  runCommandLine
100302
100450
  }) {
100303
100451
  const lines2 = {
100304
- [Symbol.asyncIterator]: () => createInterface4({ input: process.stdin })[Symbol.asyncIterator]()
100452
+ [Symbol.asyncIterator]: () => createInterface3({ input: process.stdin })[Symbol.asyncIterator]()
100305
100453
  };
100306
100454
  await answerMcpLines({ context, args, lines: lines2, runCommandLine });
100307
100455
  }
100308
100456
 
100309
100457
  // src/services/memory-commands.service.ts
100310
- import { readdir as readdir8, readFile as readFile30 } from "node:fs/promises";
100311
- import { join as join31, resolve as resolve21 } from "node:path";
100458
+ import { readdir as readdir7, readFile as readFile30 } from "node:fs/promises";
100459
+ import { join as join32, resolve as resolve20 } from "node:path";
100312
100460
 
100313
100461
  // src/services/mount-files.service.ts
100314
100462
  import { mkdir as mkdir11, readFile as readFile29, rm as rm17, writeFile as writeFile8 } from "node:fs/promises";
100315
- import { dirname as dirname22, relative as relative5, resolve as resolve20 } from "node:path";
100463
+ import { dirname as dirname23, relative as relative5, resolve as resolve19 } from "node:path";
100316
100464
  async function textArgument({
100317
100465
  context,
100318
100466
  value
100319
100467
  }) {
100320
100468
  if (value === "-") return context.readStdin();
100321
- if (value.startsWith("@")) return readFile29(resolve20(context.cwd, value.slice(1)), "utf8");
100469
+ if (value.startsWith("@")) return readFile29(resolve19(context.cwd, value.slice(1)), "utf8");
100322
100470
  return value;
100323
100471
  }
100324
100472
  function turnChannel({ context, args }) {
@@ -100330,15 +100478,15 @@ async function writeMount({
100330
100478
  folder,
100331
100479
  files: files2
100332
100480
  }) {
100333
- const root = resolve20(context.cwd, flagText({ args, name: "dir", fallback: ".laze" }), folder);
100481
+ const root = resolve19(context.cwd, flagText({ args, name: "dir", fallback: ".laze" }), folder);
100334
100482
  await rm17(root, { recursive: true, force: true });
100335
100483
  await mkdir11(root, { recursive: true });
100336
100484
  for (const file4 of files2) {
100337
- const target = resolve20(root, file4.path);
100485
+ const target = resolve19(root, file4.path);
100338
100486
  const inside = relative5(root, target);
100339
100487
  if (!inside || inside.startsWith(".."))
100340
100488
  throw new Error(`Refusing to write outside ${root}: ${file4.path}`);
100341
- await mkdir11(dirname22(target), { recursive: true });
100489
+ await mkdir11(dirname23(target), { recursive: true });
100342
100490
  await writeFile8(target, file4.content);
100343
100491
  }
100344
100492
  return root;
@@ -100594,16 +100742,16 @@ async function siestaImport({
100594
100742
  args,
100595
100743
  dir
100596
100744
  }) {
100597
- const root = resolve21(context.cwd, dir);
100598
- const log = await readFile30(join31(root, "LOG.md"));
100599
- const names = (await readdir8(join31(root, "tree")).catch(() => [])).filter(
100745
+ const root = resolve20(context.cwd, dir);
100746
+ const log = await readFile30(join32(root, "LOG.md"));
100747
+ const names = (await readdir7(join32(root, "tree")).catch(() => [])).filter(
100600
100748
  (name3) => /^\d{1,6}-\d{1,6}\.md$/.test(name3)
100601
100749
  );
100602
100750
  const tree = Object.fromEntries(
100603
100751
  await Promise.all(
100604
100752
  names.map(async (name3) => [
100605
100753
  name3.slice(0, -3),
100606
- (await readFile30(join31(root, "tree", name3))).toString("base64")
100754
+ (await readFile30(join32(root, "tree", name3))).toString("base64")
100607
100755
  ])
100608
100756
  )
100609
100757
  );
@@ -100622,16 +100770,16 @@ async function memoryImport({ context, args }) {
100622
100770
  if (siesta) return siestaImport({ context, args, dir: siesta });
100623
100771
  const dir = flagText({ args, name: "optmem" });
100624
100772
  if (!dir) throw new CliUsageError(USAGE14);
100625
- const root = resolve21(context.cwd, dir);
100626
- const log = await readFile30(join31(root, "LOG.txt"));
100627
- const sizes2 = (await readdir8(join31(root, "TREE")).catch(() => [])).filter(
100773
+ const root = resolve20(context.cwd, dir);
100774
+ const log = await readFile30(join32(root, "LOG.txt"));
100775
+ const sizes2 = (await readdir7(join32(root, "TREE")).catch(() => [])).filter(
100628
100776
  (name3) => /^\d{1,4}$/.test(name3)
100629
100777
  );
100630
100778
  const tree = Object.fromEntries(
100631
100779
  await Promise.all(
100632
100780
  sizes2.map(async (size) => [
100633
100781
  size,
100634
- (await readFile30(join31(root, "TREE", size))).toString("base64")
100782
+ (await readFile30(join32(root, "TREE", size))).toString("base64")
100635
100783
  ])
100636
100784
  )
100637
100785
  );
@@ -101024,7 +101172,7 @@ async function notifications({ context, args }) {
101024
101172
  }
101025
101173
 
101026
101174
  // src/services/openclaw-commands.service.ts
101027
- import { resolve as resolve22 } from "node:path";
101175
+ import { resolve as resolve21 } from "node:path";
101028
101176
  var OPENCLAW_USAGE = `Usage (a person's key; a gateway belongs to the person who connects it):
101029
101177
  laze openclaw list the gateways connected here and their agents
101030
101178
  laze openclaw connect <wss url> [--label <label>] (< token | --from-file <file> | --from-vault <connection>)
@@ -101175,7 +101323,7 @@ var agentKey = async ({ context, args, client, url: url2 }) => {
101175
101323
  });
101176
101324
  const login2 = flagText({ args, name: "login" });
101177
101325
  if (login2) {
101178
- const folder = resolve22(context.cwd, login2);
101326
+ const folder = resolve21(context.cwd, login2);
101179
101327
  const profile = profileNameOf(key.agentName);
101180
101328
  await signInFolder({ context, url: url2, token: key.token, name: profile, folder });
101181
101329
  context.out(
@@ -101227,9 +101375,9 @@ async function openclaw({
101227
101375
  }
101228
101376
 
101229
101377
  // src/services/operator-key-commands.service.ts
101230
- import { createHash as createHash9, randomBytes as randomBytes5 } from "node:crypto";
101378
+ import { createHash as createHash10, randomBytes as randomBytes5 } from "node:crypto";
101231
101379
  import { mkdir as mkdir12, readFile as readFile31, rm as rm18, writeFile as writeFile9 } from "node:fs/promises";
101232
- import { dirname as dirname23, join as join32 } from "node:path";
101380
+ import { dirname as dirname24, join as join33 } from "node:path";
101233
101381
 
101234
101382
  // ../../modules/audit-log/contract/src/audit-log.api.ts
101235
101383
  var auditEntrySchemaDefinition = external_exports.object({
@@ -103004,14 +103152,14 @@ Ops function leases (ADR-214), instead of reading the database:
103004
103152
  call one function of an approved lease; a cut
103005
103153
  list says so and names the cursor of the next page`;
103006
103154
  var POLL_MS3 = 5e3;
103007
- var keyFile = ({ context, keyId }) => join32(dirname23(context.environment.configPath), "operator-keys", keyId.replaceAll("/", "_"));
103155
+ var keyFile = ({ context, keyId }) => join33(dirname24(context.environment.configPath), "operator-keys", keyId.replaceAll("/", "_"));
103008
103156
  async function saveSecret({
103009
103157
  context,
103010
103158
  keyId,
103011
103159
  secret
103012
103160
  }) {
103013
103161
  const path = keyFile({ context, keyId });
103014
- await mkdir12(dirname23(path), { recursive: true, mode: 448 });
103162
+ await mkdir12(dirname24(path), { recursive: true, mode: 448 });
103015
103163
  await writeFile9(path, secret, { mode: 384 });
103016
103164
  }
103017
103165
  function typedArg(text3) {
@@ -103054,7 +103202,11 @@ async function waitForAnswer({
103054
103202
  let current3 = key;
103055
103203
  while (current3.status === "pending" && context.nowMs() < giveUpAt) {
103056
103204
  await context.sleep(POLL_MS3);
103057
- current3 = await client.post(OPERATOR_KEY_REST_PATHS.status, { keyId: key.id });
103205
+ current3 = await patiently({
103206
+ context,
103207
+ giveUpAt,
103208
+ call: () => client.post(OPERATOR_KEY_REST_PATHS.status, { keyId: key.id })
103209
+ });
103058
103210
  }
103059
103211
  return current3;
103060
103212
  }
@@ -103069,7 +103221,7 @@ async function requestKey({ context, args }) {
103069
103221
  target,
103070
103222
  args: argsOf({ args }),
103071
103223
  reason: reason2,
103072
- secretHash: createHash9("sha256").update(secret).digest("hex")
103224
+ secretHash: createHash10("sha256").update(secret).digest("hex")
103073
103225
  });
103074
103226
  await saveSecret({ context, keyId: key.id, secret });
103075
103227
  const answered = args.flags.wait ? await waitForAnswer({ context, client, key }) : key;
@@ -103167,7 +103319,7 @@ async function requestLease({ context, args }) {
103167
103319
  args: {},
103168
103320
  functions,
103169
103321
  reason: reason2,
103170
- secretHash: createHash9("sha256").update(secret).digest("hex")
103322
+ secretHash: createHash10("sha256").update(secret).digest("hex")
103171
103323
  });
103172
103324
  await saveSecret({ context, keyId: key.id, secret });
103173
103325
  const answered = args.flags.wait ? await waitForAnswer({ context, client, key }) : key;
@@ -103248,7 +103400,7 @@ ${OPS_USAGE}`);
103248
103400
 
103249
103401
  // src/services/release-watch.service.ts
103250
103402
  import { realpath as realpath2 } from "node:fs/promises";
103251
- import { dirname as dirname24, join as join33 } from "node:path";
103403
+ import { dirname as dirname25, join as join34 } from "node:path";
103252
103404
  var RETRY_AFTER_MS = 6 * 60 * 60 * 1e3;
103253
103405
  async function scriptOf(context) {
103254
103406
  const script = context.program.at(-1) ?? "";
@@ -103265,15 +103417,15 @@ async function startedUpdate({
103265
103417
  if (context.environment.inherited.LAZE_AUTO_UPDATE === "0") return null;
103266
103418
  const plan2 = updatePlanOf({ script: await scriptOf(context) });
103267
103419
  if (plan2.kind !== "install") return null;
103268
- const folder = dirname24(context.environment.configPath);
103269
- const stamp = join33(folder, "auto-update.json");
103420
+ const folder = dirname25(context.environment.configPath);
103421
+ const stamp = join34(folder, "auto-update.json");
103270
103422
  const last = await readStateJson({ path: stamp }) ?? null;
103271
103423
  const now = context.nowMs();
103272
103424
  if (last?.server === server && now - last.atMs < RETRY_AFTER_MS) return null;
103273
103425
  await writeStateJson({ path: stamp, value: { server, atMs: now } });
103274
103426
  context.processes.spawnDetached({
103275
103427
  argv: [...context.program, "update"],
103276
- logPath: join33(folder, "auto-update.log")
103428
+ logPath: join34(folder, "auto-update.log")
103277
103429
  });
103278
103430
  return { manager: plan2.manager };
103279
103431
  }
@@ -103569,8 +103721,8 @@ async function schedule({ context, args }) {
103569
103721
  }
103570
103722
 
103571
103723
  // src/services/skill-commands.service.ts
103572
- import { readdir as readdir9, readFile as readFile32 } from "node:fs/promises";
103573
- import { join as join34, relative as relative6, resolve as resolve23 } from "node:path";
103724
+ import { readdir as readdir8, readFile as readFile32 } from "node:fs/promises";
103725
+ import { join as join35, relative as relative6, resolve as resolve22 } from "node:path";
103574
103726
  var USAGE18 = `Usage:
103575
103727
  laze skill list [--agent <agentId>]
103576
103728
  laze skill install <catalogue-id> [--as <name>] [--agent <agentId>]
@@ -103587,11 +103739,11 @@ var USAGE18 = `Usage:
103587
103739
  --agent names the agent with a person's key; an agent's key works on its own skills.
103588
103740
  With a person's key, list without --agent shows every agent's skills.`;
103589
103741
  async function folderFiles({ root }) {
103590
- const entries = await readdir9(root, { recursive: true, withFileTypes: true });
103742
+ const entries = await readdir8(root, { recursive: true, withFileTypes: true });
103591
103743
  const files2 = [];
103592
103744
  for (const entry2 of entries) {
103593
103745
  if (!entry2.isFile()) continue;
103594
- const full = join34(entry2.parentPath, entry2.name);
103746
+ const full = join35(entry2.parentPath, entry2.name);
103595
103747
  files2.push({ path: relative6(root, full), content: await readFile32(full, "utf8") });
103596
103748
  }
103597
103749
  return files2.toSorted((a, b) => a.path.localeCompare(b.path));
@@ -103623,7 +103775,7 @@ async function skillInstall({ context, args }) {
103623
103775
  if (!catalogueId === !from) throw new CliUsageError(USAGE18);
103624
103776
  const name3 = flagText({ args, name: "as" });
103625
103777
  const agent3 = flagText({ args, name: "agent" });
103626
- const files2 = from ? await folderFiles({ root: resolve23(context.cwd, from) }) : void 0;
103778
+ const files2 = from ? await folderFiles({ root: resolve22(context.cwd, from) }) : void 0;
103627
103779
  const { client } = await signedIn({ context, args });
103628
103780
  const installed = await client.post("/api/skills/install", {
103629
103781
  ...catalogueId ? { catalogueId } : {},
@@ -103690,7 +103842,7 @@ async function skillUpdate({ context, args }) {
103690
103842
  if (!name3 || !newName && description === void 0 && !skillMdFile) {
103691
103843
  throw new CliUsageError(USAGE18);
103692
103844
  }
103693
- const skillMd = skillMdFile ? await readFile32(resolve23(context.cwd, skillMdFile), "utf8") : void 0;
103845
+ const skillMd = skillMdFile ? await readFile32(resolve22(context.cwd, skillMdFile), "utf8") : void 0;
103694
103846
  const { client } = await signedIn({ context, args });
103695
103847
  const updated = await client.post("/api/skills/update", {
103696
103848
  name: name3,
@@ -103737,7 +103889,7 @@ async function skill({ context, args }) {
103737
103889
 
103738
103890
  // src/services/slack-commands.service.ts
103739
103891
  import { readFile as readFile33 } from "node:fs/promises";
103740
- import { resolve as resolve24 } from "node:path";
103892
+ import { resolve as resolve23 } from "node:path";
103741
103893
  var SLACK_USAGE = `Usage (a person's key; Slack stays the source, the bot joins no channel by itself):
103742
103894
  laze slack overview connected Slack workspaces, mirrors, your link
103743
103895
  laze slack link-prompts Slack workspaces you have not linked yet
@@ -103787,7 +103939,7 @@ async function secretLines({ context, args }) {
103787
103939
  throw new CliUsageError("A secret never goes in a flag: pipe it on stdin or use --from-file.");
103788
103940
  }
103789
103941
  const file4 = flagText({ args, name: "from-file" });
103790
- const text3 = file4 ? await readFile33(resolve24(context.cwd, file4), "utf8") : await context.readStdin();
103942
+ const text3 = file4 ? await readFile33(resolve23(context.cwd, file4), "utf8") : await context.readStdin();
103791
103943
  return text3.split("\n").map((line) => line.trim()).filter(Boolean);
103792
103944
  }
103793
103945
  async function secretsOf2({
@@ -104536,8 +104688,8 @@ async function checkInstalled({
104536
104688
  }
104537
104689
 
104538
104690
  // src/services/vault-env-commands.service.ts
104539
- import { readFile as readFile35, stat as stat13 } from "node:fs/promises";
104540
- import { dirname as dirname25, join as join35, resolve as resolve25 } from "node:path";
104691
+ import { readFile as readFile35, stat as stat12 } from "node:fs/promises";
104692
+ import { dirname as dirname26, join as join36, resolve as resolve24 } from "node:path";
104541
104693
 
104542
104694
  // src/rules/vault-manifest.rules.ts
104543
104695
  var VARIABLE = /^[A-Za-z_][A-Za-z0-9_]*$/;
@@ -104695,7 +104847,10 @@ async function doorOf({
104695
104847
  throw new CliUsageError(`laze vault: the batch was refused: ${refusalText(error63)}`);
104696
104848
  }
104697
104849
  },
104698
- status: (requestId) => client.post(door.status, { requestId, ...door.extra }).catch(refusedRelease)
104850
+ status: (requestId) => patiently({
104851
+ context,
104852
+ call: () => client.post(door.status, { requestId, ...door.extra })
104853
+ }).catch(refusedRelease)
104699
104854
  };
104700
104855
  }
104701
104856
  async function resolveBatch({
@@ -104870,7 +105025,7 @@ function refusedReason({
104870
105025
  return VAULT_EXIT_BAD_REASON;
104871
105026
  }
104872
105027
  async function isFile(path) {
104873
- return stat13(path).then(
105028
+ return stat12(path).then(
104874
105029
  (found) => found.isFile(),
104875
105030
  () => false
104876
105031
  );
@@ -104880,12 +105035,12 @@ async function manifestPathOf({
104880
105035
  args
104881
105036
  }) {
104882
105037
  const named = args.words[2];
104883
- if (named) return resolve25(context.cwd, named);
105038
+ if (named) return resolve24(context.cwd, named);
104884
105039
  const environment = flagText({ args, name: "env" });
104885
105040
  const file4 = environment ? `.env.${environment}.vault` : ".env.vault";
104886
- for (let dir = resolve25(context.cwd); ; dir = dirname25(dir)) {
104887
- if (await isFile(join35(dir, file4))) return join35(dir, file4);
104888
- if (dirname25(dir) === dir) break;
105041
+ for (let dir = resolve24(context.cwd); ; dir = dirname26(dir)) {
105042
+ if (await isFile(join36(dir, file4))) return join36(dir, file4);
105043
+ if (dirname26(dir) === dir) break;
104889
105044
  }
104890
105045
  throw new CliUsageError(`laze vault: no ${file4} here or in a parent folder
104891
105046
  ${ENV_USAGE}`);
@@ -105258,7 +105413,7 @@ async function vaultScrub({ context, args }) {
105258
105413
 
105259
105414
  // src/services/whatsapp-business-commands.service.ts
105260
105415
  import { readFile as readFile36 } from "node:fs/promises";
105261
- import { resolve as resolve26 } from "node:path";
105416
+ import { resolve as resolve25 } from "node:path";
105262
105417
 
105263
105418
  // ../../modules/whatsapp-business/contract/src/whatsapp-business.prices.ts
105264
105419
  var whatsappBusinessCategorySchema = external_exports.enum([
@@ -105754,7 +105909,7 @@ async function secretsOf3({ context, args }) {
105754
105909
  const fromConnection = flagText({ args, name: "from-vault" });
105755
105910
  if (fromConnection) return { fromConnection };
105756
105911
  const file4 = flagText({ args, name: "from-file" });
105757
- const text3 = file4 ? await readFile36(resolve26(context.cwd, file4), "utf8") : await context.readStdin();
105912
+ const text3 = file4 ? await readFile36(resolve25(context.cwd, file4), "utf8") : await context.readStdin();
105758
105913
  const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
105759
105914
  if (lines2.length !== 2) {
105760
105915
  throw new CliUsageError(
@@ -105956,7 +106111,7 @@ async function whatsappBusiness({
105956
106111
 
105957
106112
  // src/services/whatsapp-commands.service.ts
105958
106113
  import { writeFile as writeFile10 } from "node:fs/promises";
105959
- import { basename as basename12, resolve as resolve27 } from "node:path";
106114
+ import { basename as basename12, resolve as resolve26 } from "node:path";
105960
106115
 
105961
106116
  // src/services/whatsapp-pairing-commands.service.ts
105962
106117
  var WHATSAPP_PAIRING_USAGE = " laze whatsapp unpair <machine> unlink WhatsApp from the machine (owner)";
@@ -106096,7 +106251,7 @@ async function file3({ context, args }) {
106096
106251
  },
106097
106252
  args
106098
106253
  });
106099
- const out = resolve27(context.cwd, flagText({ args, name: "out" }) ?? basename12(answer6.fileName));
106254
+ const out = resolve26(context.cwd, flagText({ args, name: "out" }) ?? basename12(answer6.fileName));
106100
106255
  const response = await context.fetcher(answer6.url);
106101
106256
  if (!response.ok) throw new Error(`The file link answered ${response.status}`);
106102
106257
  await writeFile10(out, new Uint8Array(await response.arrayBuffer()));
@@ -106522,6 +106677,7 @@ var HELP = `laze: work in a Laze workspace from your terminal or your agent.
106522
106677
  laze join [--workspace <name|link>] [--for <email>] [--name <name>] [--project <folder>] ask to join as an agent: a person approves once in their feed
106523
106678
  laze agent link --token <token> [--name <name>] [--project <folder>] connect this Claude Code or Codex session
106524
106679
  laze agent bind the linked agent listens in this session from now on
106680
+ laze agent sessions [--migrate] [--json] the sessions this machine binds to its agents
106525
106681
  laze agent request [--name <name>] ask the agent's owner for a new Laze agent with this session
106526
106682
  laze agent create --name <name> [--description <text>] [--harness laze-models|claude-code|codex] [--avatar <file>|--avatar-emoji <emoji>]
106527
106683
  make an agent for your owner (or for you): personal, opened in their direct messages
@@ -106743,6 +106899,7 @@ var COMMANDS5 = {
106743
106899
  "agent link": linkAgent,
106744
106900
  "agent bind": bindAgentSession,
106745
106901
  "agent request": requestAgent,
106902
+ "agent sessions": listAgentSessions,
106746
106903
  "hook stop": stopHook,
106747
106904
  "hook wait": waitHook,
106748
106905
  "hook pre-tool": preToolHook,
@@ -106951,21 +107108,21 @@ function exitCodeOf({
106951
107108
  // src/services/machine-key.service.ts
106952
107109
  import { execFile as execFile2 } from "node:child_process";
106953
107110
  import {
106954
- createHash as createHash10,
107111
+ createHash as createHash11,
106955
107112
  createPrivateKey,
106956
107113
  generateKeyPairSync,
106957
107114
  randomBytes as randomBytes6,
106958
107115
  sign
106959
107116
  } from "node:crypto";
106960
107117
  import { chmod, link, mkdir as mkdir13, readFile as readFile37, rm as rm21, writeFile as writeFile11 } from "node:fs/promises";
106961
- import { dirname as dirname26, join as join36 } from "node:path";
107118
+ import { dirname as dirname27, join as join37 } from "node:path";
106962
107119
  var KEYCHAIN_SERVICE = "laze-cli-machine-key";
106963
- var runProgram = ({ program, args, stdin: stdin2, timeoutMs }) => new Promise((resolve28, reject) => {
107120
+ var runProgram = ({ program, args, stdin: stdin2, timeoutMs }) => new Promise((resolve27, reject) => {
106964
107121
  const child = execFile2(
106965
107122
  program,
106966
107123
  [...args],
106967
107124
  { timeout: timeoutMs },
106968
- (error63, stdout2) => error63 ? reject(error63) : resolve28(String(stdout2))
107125
+ (error63, stdout2) => error63 ? reject(error63) : resolve27(String(stdout2))
106969
107126
  );
106970
107127
  if (stdin2 !== void 0) child.stdin?.end(stdin2);
106971
107128
  });
@@ -106998,15 +107155,15 @@ var MachineKeyStore = class _MachineKeyStore {
106998
107155
  });
106999
107156
  }
107000
107157
  get metaPath() {
107001
- return join36(dirname26(this.options.configPath), "machine-key.json");
107158
+ return join37(dirname27(this.options.configPath), "machine-key.json");
107002
107159
  }
107003
107160
  /** Named by the key, so two CLIs making a key at once never overwrite each other's. */
107004
107161
  pemPathOf(jwk) {
107005
- return join36(dirname26(this.options.configPath), `machine-key-${shortOf(jwk)}.pem`);
107162
+ return join37(dirname27(this.options.configPath), `machine-key-${shortOf(jwk)}.pem`);
107006
107163
  }
107007
107164
  /** The Keychain item's account: one per config file and key. */
107008
107165
  accountOf(jwk) {
107009
- const config2 = createHash10("sha256").update(this.options.configPath).digest("hex");
107166
+ const config2 = createHash11("sha256").update(this.options.configPath).digest("hex");
107010
107167
  return `${config2.slice(0, 32)}-${shortOf(jwk)}`;
107011
107168
  }
107012
107169
  /** The key if this machine made one; null otherwise. Read once per process. */
@@ -107129,7 +107286,7 @@ async function writeOnce({ path, text: text3 }) {
107129
107286
  }
107130
107287
  }
107131
107288
  async function writePrivate({ path, text: text3 }) {
107132
- await mkdir13(dirname26(path), { recursive: true, mode: 448 });
107289
+ await mkdir13(dirname27(path), { recursive: true, mode: 448 });
107133
107290
  await writeFile11(path, text3, { mode: 384 });
107134
107291
  await chmod(path, 384);
107135
107292
  }
@@ -107188,7 +107345,7 @@ function machineProofFetch({
107188
107345
  import { execFile as execFile3, spawn as spawn4, spawnSync } from "node:child_process";
107189
107346
  import { closeSync, mkdirSync, openSync, renameSync, statSync } from "node:fs";
107190
107347
  import { readFile as readFile38, readlink } from "node:fs/promises";
107191
- import { dirname as dirname27 } from "node:path";
107348
+ import { dirname as dirname28 } from "node:path";
107192
107349
  import { promisify as promisify2 } from "node:util";
107193
107350
  var run3 = promisify2(execFile3);
107194
107351
  function alive(pid) {
@@ -107208,16 +107365,16 @@ async function argsOf2(pid) {
107208
107365
  return line ? line.split(/\s+/) : void 0;
107209
107366
  }
107210
107367
  async function parentOf(pid) {
107211
- const stat14 = await readFile38(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
107212
- const fromStat = stat14 ? Number(stat14.slice(stat14.lastIndexOf(")") + 2).split(" ")[1]) : NaN;
107368
+ const stat13 = await readFile38(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
107369
+ const fromStat = stat13 ? Number(stat13.slice(stat13.lastIndexOf(")") + 2).split(" ")[1]) : NaN;
107213
107370
  if (fromStat > 0) return fromStat;
107214
107371
  const listed = await run3("ps", ["-o", "ppid=", "-p", String(pid)]).catch(() => void 0);
107215
107372
  const parent = Number(listed?.stdout.trim());
107216
107373
  return parent > 0 ? parent : void 0;
107217
107374
  }
107218
107375
  async function startOf(pid) {
107219
- const stat14 = await readFile38(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
107220
- const ticks = stat14 ? stat14.slice(stat14.lastIndexOf(")") + 2).split(" ")[19] : void 0;
107376
+ const stat13 = await readFile38(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
107377
+ const ticks = stat13 ? stat13.slice(stat13.lastIndexOf(")") + 2).split(" ")[19] : void 0;
107221
107378
  if (ticks) return ticks;
107222
107379
  const listed = await run3("ps", ["-o", "lstart=", "-p", String(pid)]).catch(() => void 0);
107223
107380
  return listed?.stdout.trim() || void 0;
@@ -107256,7 +107413,7 @@ function spawnDetached({
107256
107413
  logPath,
107257
107414
  orphan = false
107258
107415
  }) {
107259
- mkdirSync(dirname27(logPath), { recursive: true, mode: 448 });
107416
+ mkdirSync(dirname28(logPath), { recursive: true, mode: 448 });
107260
107417
  keepLogSmall({ logPath });
107261
107418
  const log = openSync(logPath, "a", 384);
107262
107419
  if (orphan) {
@@ -107351,7 +107508,7 @@ async function readStdin() {
107351
107508
  function terminalAsk() {
107352
107509
  if (!stdin.isTTY || !stdout.isTTY) return void 0;
107353
107510
  return async (question) => {
107354
- const terminal = createInterface5({ input: stdin, output: stderr });
107511
+ const terminal = createInterface4({ input: stdin, output: stderr });
107355
107512
  try {
107356
107513
  return await terminal.question(question);
107357
107514
  } finally {
@@ -107360,15 +107517,15 @@ function terminalAsk() {
107360
107517
  };
107361
107518
  }
107362
107519
  function sleep(ms2, signal) {
107363
- return new Promise((resolve28) => {
107364
- if (signal?.aborted) return resolve28();
107520
+ return new Promise((resolve27) => {
107521
+ if (signal?.aborted) return resolve27();
107365
107522
  const stop3 = () => {
107366
107523
  clearTimeout(timer);
107367
- resolve28();
107524
+ resolve27();
107368
107525
  };
107369
107526
  const timer = setTimeout(() => {
107370
107527
  signal?.removeEventListener("abort", stop3);
107371
- resolve28();
107528
+ resolve27();
107372
107529
  }, ms2);
107373
107530
  signal?.addEventListener("abort", stop3, { once: true });
107374
107531
  });