@lazehq/cli 0.1.126 → 0.1.127

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 +994 -888
  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.127";
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,158 +73227,49 @@ function displayFolderOf({ folder, home }) {
73113
73227
  return `~/${below.split(sep).join("/")}`;
73114
73228
  }
73115
73229
 
73116
- // src/services/laze-client.service.ts
73117
- var CLI_VERSION_HEADER = "x-laze-cli-version";
73118
- var LazeApiError = class extends Error {
73119
- constructor(status11, code4, message2) {
73120
- super(message2);
73121
- this.status = status11;
73122
- this.code = code4;
73123
- this.name = "LazeApiError";
73124
- }
73125
- status;
73126
- code;
73127
- /** What Laze adds to the code, such as the bound session of a `session_not_bound`. */
73128
- meta;
73129
- };
73130
- var AGENT_MIGRATED = "agent_migrated";
73131
- function unreachableReasonOf(error63) {
73132
- if (!(error63 instanceof TypeError) || error63.message !== "fetch failed") return void 0;
73133
- const { cause } = error63;
73134
- return cause instanceof Error && cause.message ? cause.message : "the connection failed";
73135
- }
73136
- function migratedNoticeOf(error63) {
73137
- if (!(error63 instanceof LazeApiError) || error63.code !== AGENT_MIGRATED) return void 0;
73138
- const notice = typeof error63.meta?.notice === "string" ? error63.meta.notice : error63.message;
73139
- const link2 = typeof error63.meta?.link === "string" ? error63.meta.link : null;
73140
- return { notice, link: link2 };
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;
73141
73238
  }
73142
- var LazeClient = class _LazeClient {
73143
- constructor(options) {
73144
- this.options = options;
73145
- }
73146
- options;
73147
- static create({
73148
- baseUrl,
73149
- token: token2,
73150
- fetcher,
73151
- onMigrated,
73152
- onRefused,
73153
- onAnswered
73154
- }) {
73155
- return new _LazeClient({
73156
- baseUrl: baseUrl.replace(/\/+$/, ""),
73157
- token: token2,
73158
- fetcher,
73159
- headers: {},
73160
- onMigrated,
73161
- onRefused,
73162
- onAnswered
73163
- });
73164
- }
73165
- /** The address this client calls, which completes a link the api wrote as a path. */
73166
- get baseUrl() {
73167
- return this.options.baseUrl;
73168
- }
73169
- /** The same client, sending these headers too on every call. */
73170
- withHeaders(headers) {
73171
- return new _LazeClient({ ...this.options, headers: { ...this.options.headers, ...headers } });
73172
- }
73173
- get(path) {
73174
- return this.send({ method: "GET", path });
73175
- }
73176
- /** `signal` aborts the call, such as a long-poll whose caller left. */
73177
- post(path, body, { signal } = {}) {
73178
- return this.send({ method: "POST", path, body, signal });
73179
- }
73180
- put(path, body) {
73181
- return this.send({ method: "PUT", path, body });
73182
- }
73183
- /** A JSON body sent as it is, answered as it came: the status and text, never thrown. */
73184
- async forward({
73185
- path,
73186
- body
73187
- }) {
73188
- const headers = {
73189
- ...this.options.headers,
73190
- accept: "application/json, text/event-stream",
73191
- "content-type": "application/json",
73192
- [CLI_VERSION_HEADER]: cliVersionOf()
73193
- };
73194
- if (this.options.token) headers.authorization = `Bearer ${this.options.token}`;
73195
- const response = await this.options.fetcher(`${this.options.baseUrl}${path}`, {
73196
- method: "POST",
73197
- headers,
73198
- body
73199
- });
73200
- const text3 = await response.text();
73201
- if (response.status === 401) await this.toldMigrated(apiErrorOf({ status: 401, text: text3 }));
73202
- return { status: response.status, text: text3 };
73203
- }
73204
- async toldMigrated(error63) {
73205
- const found = migratedNoticeOf(error63);
73206
- if (found && this.options.onMigrated)
73207
- await this.options.onMigrated(found).catch(() => void 0);
73208
- else if (!found && refusesTheKey(error63) && this.options.onRefused)
73209
- await this.options.onRefused(error63).catch(() => void 0);
73210
- }
73211
- async send({
73212
- method,
73213
- path,
73214
- body,
73215
- signal
73216
- }) {
73217
- const headers = {
73218
- ...this.options.headers,
73219
- accept: "application/json",
73220
- [CLI_VERSION_HEADER]: cliVersionOf()
73221
- };
73222
- if (body !== void 0) headers["content-type"] = "application/json";
73223
- if (this.options.token) headers.authorization = `Bearer ${this.options.token}`;
73224
- const response = await this.options.fetcher(`${this.options.baseUrl}${path}`, {
73225
- method,
73226
- headers,
73227
- ...body !== void 0 ? { body: JSON.stringify(body) } : {},
73228
- ...signal ? { signal } : {}
73229
- });
73230
- const text3 = await response.text();
73231
- if (!response.ok) {
73232
- const error63 = apiErrorOf({ status: response.status, text: text3 });
73233
- await this.toldMigrated(error63);
73234
- throw error63;
73235
- }
73236
- if (this.options.onAnswered) await this.options.onAnswered().catch(() => void 0);
73237
- return text3 ? JSON.parse(text3) : void 0;
73238
- }
73239
- };
73240
- function apiErrorOf({ status: status11, text: text3 }) {
73241
- let body;
73242
- try {
73243
- body = text3 ? JSON.parse(text3) : void 0;
73244
- } catch {
73245
- body = void 0;
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);
73246
73248
  }
73247
- return errorOf({ status: status11, body });
73249
+ return void 0;
73248
73250
  }
73249
- function errorOf({ status: status11, body }) {
73250
- const record4 = typeof body === "object" && body !== null ? body : {};
73251
- const nested = typeof record4.error === "object" && record4.error !== null ? record4.error : record4;
73252
- const fallback = typeof record4.error === "string" ? record4.error : `http_${status11}`;
73253
- const code4 = typeof nested.code === "string" ? nested.code : fallback;
73254
- const message2 = typeof nested.message === "string" ? nested.message : `Laze answered ${status11}`;
73255
- const meta3 = typeof nested.meta === "object" && nested.meta !== null ? nested.meta : void 0;
73256
- const error63 = new LazeApiError(status11, code4, message2);
73257
- error63.meta = meta3;
73258
- return error63;
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] };
73259
73269
  }
73260
-
73261
- // src/services/machine-report.service.ts
73262
- import { createHash } from "node:crypto";
73263
- import { readFile as readFile4 } from "node:fs/promises";
73264
- import { hostname as hostname3 } from "node:os";
73265
73270
 
73266
73271
  // src/services/inbox-spool.service.ts
73267
- import { dirname as dirname4, join as join4 } from "node:path";
73272
+ import { dirname as dirname4, join as join5 } from "node:path";
73268
73273
  var PUSH_GRACE_MS = 3 * 6e4;
73269
73274
  var IN_FLIGHT_MS = 35e3;
73270
73275
  function fileNameOf({ profile }) {
@@ -73276,8 +73281,8 @@ function statePathOf({
73276
73281
  profile,
73277
73282
  extension: extension2 = "json"
73278
73283
  }) {
73279
- const directory = join4(dirname4(context.environment.configPath), kind2);
73280
- return join4(directory, `${fileNameOf({ profile })}.${extension2}`);
73284
+ const directory = join5(dirname4(context.environment.configPath), kind2);
73285
+ return join5(directory, `${fileNameOf({ profile })}.${extension2}`);
73281
73286
  }
73282
73287
  async function readSpool({ path }) {
73283
73288
  return await readStateJson({ path }) ?? [];
@@ -73339,7 +73344,155 @@ async function dueFromSpool({
73339
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);
73340
73345
  }
73341
73346
 
73347
+ // src/services/laze-client.service.ts
73348
+ var CLI_VERSION_HEADER = "x-laze-cli-version";
73349
+ var LazeApiError = class extends Error {
73350
+ constructor(status11, code4, message2) {
73351
+ super(message2);
73352
+ this.status = status11;
73353
+ this.code = code4;
73354
+ this.name = "LazeApiError";
73355
+ }
73356
+ status;
73357
+ code;
73358
+ /** What Laze adds to the code, such as the bound session of a `session_not_bound`. */
73359
+ meta;
73360
+ };
73361
+ var AGENT_MIGRATED = "agent_migrated";
73362
+ function unreachableReasonOf(error63) {
73363
+ if (!(error63 instanceof TypeError) || error63.message !== "fetch failed") return void 0;
73364
+ const { cause } = error63;
73365
+ return cause instanceof Error && cause.message ? cause.message : "the connection failed";
73366
+ }
73367
+ function migratedNoticeOf(error63) {
73368
+ if (!(error63 instanceof LazeApiError) || error63.code !== AGENT_MIGRATED) return void 0;
73369
+ const notice = typeof error63.meta?.notice === "string" ? error63.meta.notice : error63.message;
73370
+ const link2 = typeof error63.meta?.link === "string" ? error63.meta.link : null;
73371
+ return { notice, link: link2 };
73372
+ }
73373
+ var LazeClient = class _LazeClient {
73374
+ constructor(options) {
73375
+ this.options = options;
73376
+ }
73377
+ options;
73378
+ static create({
73379
+ baseUrl,
73380
+ token: token2,
73381
+ fetcher,
73382
+ onMigrated,
73383
+ onRefused,
73384
+ onAnswered
73385
+ }) {
73386
+ return new _LazeClient({
73387
+ baseUrl: baseUrl.replace(/\/+$/, ""),
73388
+ token: token2,
73389
+ fetcher,
73390
+ headers: {},
73391
+ onMigrated,
73392
+ onRefused,
73393
+ onAnswered
73394
+ });
73395
+ }
73396
+ /** The address this client calls, which completes a link the api wrote as a path. */
73397
+ get baseUrl() {
73398
+ return this.options.baseUrl;
73399
+ }
73400
+ /** The same client, sending these headers too on every call. */
73401
+ withHeaders(headers) {
73402
+ return new _LazeClient({ ...this.options, headers: { ...this.options.headers, ...headers } });
73403
+ }
73404
+ get(path) {
73405
+ return this.send({ method: "GET", path });
73406
+ }
73407
+ /** `signal` aborts the call, such as a long-poll whose caller left. */
73408
+ post(path, body, { signal } = {}) {
73409
+ return this.send({ method: "POST", path, body, signal });
73410
+ }
73411
+ put(path, body) {
73412
+ return this.send({ method: "PUT", path, body });
73413
+ }
73414
+ /** A JSON body sent as it is, answered as it came: the status and text, never thrown. */
73415
+ async forward({
73416
+ path,
73417
+ body
73418
+ }) {
73419
+ const headers = {
73420
+ ...this.options.headers,
73421
+ accept: "application/json, text/event-stream",
73422
+ "content-type": "application/json",
73423
+ [CLI_VERSION_HEADER]: cliVersionOf()
73424
+ };
73425
+ if (this.options.token) headers.authorization = `Bearer ${this.options.token}`;
73426
+ const response = await this.options.fetcher(`${this.options.baseUrl}${path}`, {
73427
+ method: "POST",
73428
+ headers,
73429
+ body
73430
+ });
73431
+ const text3 = await response.text();
73432
+ if (response.status === 401) await this.toldMigrated(apiErrorOf({ status: 401, text: text3 }));
73433
+ return { status: response.status, text: text3 };
73434
+ }
73435
+ async toldMigrated(error63) {
73436
+ const found = migratedNoticeOf(error63);
73437
+ if (found && this.options.onMigrated)
73438
+ await this.options.onMigrated(found).catch(() => void 0);
73439
+ else if (!found && refusesTheKey(error63) && this.options.onRefused)
73440
+ await this.options.onRefused(error63).catch(() => void 0);
73441
+ }
73442
+ async send({
73443
+ method,
73444
+ path,
73445
+ body,
73446
+ signal
73447
+ }) {
73448
+ const headers = {
73449
+ ...this.options.headers,
73450
+ accept: "application/json",
73451
+ [CLI_VERSION_HEADER]: cliVersionOf()
73452
+ };
73453
+ if (body !== void 0) headers["content-type"] = "application/json";
73454
+ if (this.options.token) headers.authorization = `Bearer ${this.options.token}`;
73455
+ const response = await this.options.fetcher(`${this.options.baseUrl}${path}`, {
73456
+ method,
73457
+ headers,
73458
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {},
73459
+ ...signal ? { signal } : {}
73460
+ });
73461
+ const text3 = await response.text();
73462
+ if (!response.ok) {
73463
+ const error63 = apiErrorOf({ status: response.status, text: text3 });
73464
+ await this.toldMigrated(error63);
73465
+ throw error63;
73466
+ }
73467
+ if (this.options.onAnswered) await this.options.onAnswered().catch(() => void 0);
73468
+ return text3 ? JSON.parse(text3) : void 0;
73469
+ }
73470
+ };
73471
+ function apiErrorOf({ status: status11, text: text3 }) {
73472
+ let body;
73473
+ try {
73474
+ body = text3 ? JSON.parse(text3) : void 0;
73475
+ } catch {
73476
+ body = void 0;
73477
+ }
73478
+ return errorOf({ status: status11, body });
73479
+ }
73480
+ function errorOf({ status: status11, body }) {
73481
+ const record4 = typeof body === "object" && body !== null ? body : {};
73482
+ const nested = typeof record4.error === "object" && record4.error !== null ? record4.error : record4;
73483
+ const fallback = typeof record4.error === "string" ? record4.error : `http_${status11}`;
73484
+ const code4 = typeof nested.code === "string" ? nested.code : fallback;
73485
+ const message2 = typeof nested.message === "string" ? nested.message : `Laze answered ${status11}`;
73486
+ const meta3 = typeof nested.meta === "object" && nested.meta !== null ? nested.meta : void 0;
73487
+ const error63 = new LazeApiError(status11, code4, message2);
73488
+ error63.meta = meta3;
73489
+ return error63;
73490
+ }
73491
+
73342
73492
  // src/services/machine-report.service.ts
73493
+ import { createHash } from "node:crypto";
73494
+ import { readFile as readFile4 } from "node:fs/promises";
73495
+ import { hostname as hostname3 } from "node:os";
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;
@@ -84861,10 +84977,10 @@ function loginValuesOf({
84861
84977
  }
84862
84978
 
84863
84979
  // src/services/vault-commands.service.ts
84864
- import { createHash as createHash7 } from "node:crypto";
84980
+ import { createHash as createHash8 } from "node:crypto";
84865
84981
  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";
84982
+ import { hostname as hostname7, tmpdir } from "node:os";
84983
+ import { dirname as dirname17, join as join24 } from "node:path";
84868
84984
 
84869
84985
  // src/rules/vault-session.rules.ts
84870
84986
  function vaultSessionOf({
@@ -84939,9 +85055,9 @@ function runKeyPathOf({
84939
85055
  connection,
84940
85056
  profile = ""
84941
85057
  }) {
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`);
85058
+ const name3 = createHash8("sha256").update(connection).digest("hex");
85059
+ const base = turnFile ? dirname17(turnFile) : join24(tmpdir(), "laze-vault", profile);
85060
+ return join24(base, "vault-run-keys", `${name3}.json`);
84945
85061
  }
84946
85062
  async function runKeyAt({ path }) {
84947
85063
  const saved3 = await readStateJson({
@@ -85144,7 +85260,7 @@ async function vaultSessionFor({
85144
85260
  harnessSession,
85145
85261
  inherited: context.environment.inherited,
85146
85262
  cwd: context.cwd,
85147
- host: hostname6(),
85263
+ host: hostname7(),
85148
85264
  named: flagText({ args, name: "as" }),
85149
85265
  shellPid: await context.processes.parentOf(context.processes.pid),
85150
85266
  terminal: context.stdoutIsTerminal === true
@@ -85352,7 +85468,7 @@ async function saveScreenshot({
85352
85468
  path
85353
85469
  }) {
85354
85470
  if (path) {
85355
- const target = resolve9(context.cwd, path);
85471
+ const target = resolve8(context.cwd, path);
85356
85472
  await writeFile4(target, Buffer.from(shot.image, "base64"), { mode: 384 });
85357
85473
  return target;
85358
85474
  }
@@ -85502,9 +85618,9 @@ async function savedScreenshot({
85502
85618
  nowMs: nowMs2,
85503
85619
  what
85504
85620
  }) {
85505
- const folder = join24(tmpdir2(), "laze-browser");
85621
+ const folder = join25(tmpdir2(), "laze-browser");
85506
85622
  await mkdir7(folder, { recursive: true, mode: 448 });
85507
- const path = join24(folder, `${tabId.replace(/[^a-zA-Z0-9_-]/g, "_")}-${what}-${nowMs2}.jpg`);
85623
+ const path = join25(folder, `${tabId.replace(/[^a-zA-Z0-9_-]/g, "_")}-${what}-${nowMs2}.jpg`);
85508
85624
  await writeFile4(path, Buffer.from(data, "base64"), { mode: 384 });
85509
85625
  return path;
85510
85626
  }
@@ -85982,7 +86098,7 @@ async function appPinsCommand({
85982
86098
  import { execFile } from "node:child_process";
85983
86099
  import { mkdtemp, rm as rm12, writeFile as writeFile5 } from "node:fs/promises";
85984
86100
  import { tmpdir as tmpdir3 } from "node:os";
85985
- import { join as join25 } from "node:path";
86101
+ import { join as join26 } from "node:path";
85986
86102
  import { promisify } from "node:util";
85987
86103
  var run2 = promisify(execFile);
85988
86104
  var MODULE_SYNTAX = /^\s*(import|export)\s/m;
@@ -86011,11 +86127,11 @@ async function scriptErrorsOf({
86011
86127
  const unknown2 = unknownCollectionsOf({ files: files2, collections });
86012
86128
  const scripts = files2.flatMap(scriptsOf);
86013
86129
  if (scripts.length === 0) return unknown2;
86014
- const dir = await mkdtemp(join25(tmpdir3(), "laze-app-check-"));
86130
+ const dir = await mkdtemp(join26(tmpdir3(), "laze-app-check-"));
86015
86131
  try {
86016
86132
  const errors = await Promise.all(
86017
86133
  scripts.map(async (script, index) => {
86018
- const file4 = join25(dir, `${index}.${script.module ? "mjs" : "cjs"}`);
86134
+ const file4 = join26(dir, `${index}.${script.module ? "mjs" : "cjs"}`);
86019
86135
  await writeFile5(file4, script.code);
86020
86136
  try {
86021
86137
  await run2(process.execPath, ["--check", file4]);
@@ -86033,9 +86149,9 @@ async function scriptErrorsOf({
86033
86149
  }
86034
86150
 
86035
86151
  // src/services/app-serve.service.ts
86036
- import { readFile as readFile16, stat as stat10 } from "node:fs/promises";
86152
+ import { readFile as readFile16, stat as stat9 } from "node:fs/promises";
86037
86153
  import { createServer } from "node:http";
86038
- import { extname as extname2, join as join26, normalize, sep as sep2 } from "node:path";
86154
+ import { extname as extname2, join as join27, normalize, sep as sep2 } from "node:path";
86039
86155
  var TYPES2 = {
86040
86156
  ".html": "text/html; charset=utf-8",
86041
86157
  ".js": "text/javascript; charset=utf-8",
@@ -86086,10 +86202,10 @@ async function staticFile({
86086
86202
  if (clean.startsWith("..") || hidden) {
86087
86203
  return json2({ response, status: 404, value: { code: "not_found", message: "Not found" } });
86088
86204
  }
86089
- const candidates = [join26(folder, clean), join26(folder, clean, "index.html")];
86090
- if (!extname2(clean)) candidates.push(join26(folder, "index.html"));
86205
+ const candidates = [join27(folder, clean), join27(folder, clean, "index.html")];
86206
+ if (!extname2(clean)) candidates.push(join27(folder, "index.html"));
86091
86207
  for (const target of candidates) {
86092
- const info = await stat10(target).catch(() => void 0);
86208
+ const info = await stat9(target).catch(() => void 0);
86093
86209
  if (!info?.isFile()) continue;
86094
86210
  const type = TYPES2[extname2(target).toLowerCase()] ?? "application/octet-stream";
86095
86211
  const body = await readFile16(target);
@@ -86178,16 +86294,16 @@ async function serveAppFolder({
86178
86294
  (error63) => failed({ response, error: error63 })
86179
86295
  );
86180
86296
  });
86181
- await new Promise((resolve28, reject) => {
86297
+ await new Promise((resolve27, reject) => {
86182
86298
  server.once("error", reject);
86183
- server.listen(port, "127.0.0.1", () => resolve28());
86299
+ server.listen(port, "127.0.0.1", () => resolve27());
86184
86300
  });
86185
86301
  const { port: bound } = server.address();
86186
86302
  return {
86187
86303
  url: `http://127.0.0.1:${bound}/`,
86188
- close: () => new Promise((resolve28) => {
86304
+ close: () => new Promise((resolve27) => {
86189
86305
  server.closeAllConnections();
86190
- server.close(() => resolve28());
86306
+ server.close(() => resolve27());
86191
86307
  })
86192
86308
  };
86193
86309
  }
@@ -86358,10 +86474,10 @@ function noteRetiredFlags({ context, args }) {
86358
86474
  }
86359
86475
  }
86360
86476
  function folderOf({ context, word: word3 }) {
86361
- return resolve10(context.cwd, word3 ?? ".");
86477
+ return resolve9(context.cwd, word3 ?? ".");
86362
86478
  }
86363
86479
  async function readManifest(folder) {
86364
- const text3 = await readFile17(join27(folder, APP_MANIFEST_FILE), "utf8").catch(() => void 0);
86480
+ const text3 = await readFile17(join28(folder, APP_MANIFEST_FILE), "utf8").catch(() => void 0);
86365
86481
  if (text3 === void 0) return void 0;
86366
86482
  const parsed = appManifestSchema.safeParse(JSON.parse(text3));
86367
86483
  if (!parsed.success) {
@@ -86402,7 +86518,7 @@ async function jsonFlag({
86402
86518
  }) {
86403
86519
  const raw = flagText({ args, name: name3 });
86404
86520
  if (!raw) return void 0;
86405
- const text3 = raw.startsWith("@") ? await readFile17(resolve10(context.cwd, raw.slice(1)), "utf8") : raw;
86521
+ const text3 = raw.startsWith("@") ? await readFile17(resolve9(context.cwd, raw.slice(1)), "utf8") : raw;
86406
86522
  try {
86407
86523
  return JSON.parse(text3);
86408
86524
  } catch {
@@ -86414,8 +86530,8 @@ async function listFiles(folder) {
86414
86530
  const pending2 = [folder];
86415
86531
  while (pending2.length > 0 && found.length <= MAX_FILES) {
86416
86532
  const current3 = pending2.pop() ?? folder;
86417
- for (const entry2 of await readdir7(current3, { withFileTypes: true })) {
86418
- const path = join27(current3, entry2.name);
86533
+ for (const entry2 of await readdir6(current3, { withFileTypes: true })) {
86534
+ const path = join28(current3, entry2.name);
86419
86535
  const rel = relative3(folder, path).split(sep3).join("/");
86420
86536
  if (isSkippedPath({ path: rel })) continue;
86421
86537
  if (entry2.isDirectory()) pending2.push(path);
@@ -86450,12 +86566,12 @@ var appCreate = async ({ context, args }) => {
86450
86566
  ...visibility ? { visibility } : {},
86451
86567
  ...template ? { template } : {}
86452
86568
  });
86453
- const folder = resolve10(context.cwd, flagText({ args, name: "dir", fallback: app2.slug }));
86569
+ const folder = resolve9(context.cwd, flagText({ args, name: "dir", fallback: app2.slug }));
86454
86570
  await mkdir8(folder, { recursive: true });
86455
86571
  const start2 = template ? await templateStart({ client, appId: app2.id, template }) : null;
86456
86572
  for (const file4 of start2?.files ?? []) {
86457
- const target = join27(folder, ...file4.path.split("/"));
86458
- await mkdir8(dirname17(target), { recursive: true });
86573
+ const target = join28(folder, ...file4.path.split("/"));
86574
+ await mkdir8(dirname18(target), { recursive: true });
86459
86575
  await writeFile6(
86460
86576
  target,
86461
86577
  file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
@@ -86467,7 +86583,7 @@ var appCreate = async ({ context, args }) => {
86467
86583
  views: [...start2?.template.views ?? []],
86468
86584
  seed: { ...start2?.template.seed }
86469
86585
  };
86470
- await writeFile6(join27(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86586
+ await writeFile6(join28(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86471
86587
  `);
86472
86588
  const where = relative3(context.cwd, folder) || ".";
86473
86589
  const created = start2 ? `Created ${app2.name} (${app2.id}) from the ${template} template in ${where}; its first version is live at ${app2.publishedUrl}.
@@ -86605,7 +86721,7 @@ var appWrite = async ({ context, args }) => {
86605
86721
  const remove9 = (flagText({ args, name: "remove" }) ?? "").split(",").map((path) => path.trim()).filter(Boolean);
86606
86722
  const files2 = await Promise.all(
86607
86723
  words.slice(2).map(async (word3) => {
86608
- const path = resolve10(context.cwd, word3);
86724
+ const path = resolve9(context.cwd, word3);
86609
86725
  const { bytes: _bytes, ...file4 } = buildFileOf({
86610
86726
  path: relative3(folder, path).split(sep3).join("/"),
86611
86727
  bytes: await readFile17(path)
@@ -86697,7 +86813,7 @@ async function folderClaim({
86697
86813
  folder,
86698
86814
  appId
86699
86815
  }) {
86700
- const entries = await readdir7(folder).catch(() => []);
86816
+ const entries = await readdir6(folder).catch(() => []);
86701
86817
  if (entries.length === 0) return "empty";
86702
86818
  const manifest = await readManifest(folder).catch(() => void 0);
86703
86819
  if (!manifest) return "other-files";
@@ -86735,8 +86851,8 @@ var appPull = async ({ context, args }) => {
86735
86851
  );
86736
86852
  }
86737
86853
  for (const file4 of pulled.files) {
86738
- const target = join27(folder, ...file4.path.split("/"));
86739
- await mkdir8(dirname17(target), { recursive: true });
86854
+ const target = join28(folder, ...file4.path.split("/"));
86855
+ await mkdir8(dirname18(target), { recursive: true });
86740
86856
  await writeFile6(
86741
86857
  target,
86742
86858
  file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
@@ -86754,7 +86870,7 @@ var appPull = async ({ context, args }) => {
86754
86870
  ])
86755
86871
  )
86756
86872
  };
86757
- await writeFile6(join27(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86873
+ await writeFile6(join28(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
86758
86874
  `);
86759
86875
  const names = pulled.collections.map((collection) => collection.name);
86760
86876
  const where = relative3(context.cwd, folder) || ".";
@@ -87061,7 +87177,7 @@ var appExport = async ({ context, args }) => {
87061
87177
  });
87062
87178
  const out = flagText({ args, name: "out" });
87063
87179
  if (!out) return context.out(exported.body);
87064
- const target = resolve10(context.cwd, out);
87180
+ const target = resolve9(context.cwd, out);
87065
87181
  await writeFile6(target, exported.body);
87066
87182
  context.out(`Wrote ${exported.rows} records to ${relative3(context.cwd, target)}
87067
87183
  `);
@@ -87070,7 +87186,7 @@ var appImport = async ({ context, args }) => {
87070
87186
  const words = args.words.slice(2);
87071
87187
  const [named, collection, file4] = words.length >= 3 ? words : [void 0, ...words];
87072
87188
  if (!collection || !file4) throw new CliUsageError(USAGE7);
87073
- const csv = await readFile17(resolve10(context.cwd, file4), "utf8").catch(() => {
87189
+ const csv = await readFile17(resolve9(context.cwd, file4), "utf8").catch(() => {
87074
87190
  throw new CliUsageError(`Cannot read ${file4}`);
87075
87191
  });
87076
87192
  const scoped = named ? { ...args, flags: { ...args.flags, app: named } } : args;
@@ -87088,7 +87204,7 @@ var appImport = async ({ context, args }) => {
87088
87204
  });
87089
87205
  const refusedOut = flagText({ args, name: "refused" });
87090
87206
  if (refusedOut && result2.refusedCsv) {
87091
- await writeFile6(resolve10(context.cwd, refusedOut), result2.refusedCsv);
87207
+ await writeFile6(resolve9(context.cwd, refusedOut), result2.refusedCsv);
87092
87208
  }
87093
87209
  const fitting = result2.rows - result2.refused.length;
87094
87210
  const skipped = result2.refused.slice(0, 20).map((row) => ` line ${row.line}: ${row.reason}
@@ -87505,14 +87621,14 @@ async function app({ context, args }) {
87505
87621
  }
87506
87622
 
87507
87623
  // src/services/auth-commands.service.ts
87508
- import { hostname as hostname7 } from "node:os";
87624
+ import { hostname as hostname8 } from "node:os";
87509
87625
 
87510
87626
  // src/rules/machine-proof.rules.ts
87511
- import { createHash as createHash8, randomBytes as randomBytes2 } from "node:crypto";
87627
+ import { createHash as createHash9, randomBytes as randomBytes2 } from "node:crypto";
87512
87628
  var b64url3 = (bytes) => Buffer.from(bytes).toString("base64url");
87513
87629
  function thumbprintOf({ jwk }) {
87514
87630
  const canonical = JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y });
87515
- return b64url3(createHash8("sha256").update(canonical).digest());
87631
+ return b64url3(createHash9("sha256").update(canonical).digest());
87516
87632
  }
87517
87633
  function lazeTokenOf({ authorization }) {
87518
87634
  const match = /^Bearer (lz_\S+)$/.exec(authorization ?? "");
@@ -87536,7 +87652,7 @@ function machineProofOf({
87536
87652
  htu: url2,
87537
87653
  iat: Math.floor(nowMs2 / 1e3),
87538
87654
  jti,
87539
- ath: b64url3(createHash8("sha256").update(credential).digest()),
87655
+ ath: b64url3(createHash9("sha256").update(credential).digest()),
87540
87656
  lz_tier: tier,
87541
87657
  ...tailscaleNodeId ? { lz_ts: tailscaleNodeId } : {}
87542
87658
  })
@@ -87609,7 +87725,7 @@ async function deviceToken({
87609
87725
  clientName: flagText({
87610
87726
  args,
87611
87727
  name: "client",
87612
- fallback: `laze CLI on ${hostname7()}`.slice(0, 80)
87728
+ fallback: `laze CLI on ${hostname8()}`.slice(0, 80)
87613
87729
  }),
87614
87730
  ...machineKey ? { machineKey } : {}
87615
87731
  });
@@ -88022,7 +88138,7 @@ async function billing({ context, args }) {
88022
88138
  // src/services/browser-commands.service.ts
88023
88139
  import { randomBytes as randomBytes3 } from "node:crypto";
88024
88140
  import { readFile as readFile18 } from "node:fs/promises";
88025
- import { dirname as dirname18, join as join28 } from "node:path";
88141
+ import { dirname as dirname19, join as join29 } from "node:path";
88026
88142
 
88027
88143
  // src/services/cdp-bridge.service.ts
88028
88144
  import { spawn as spawn3 } from "node:child_process";
@@ -88053,7 +88169,7 @@ function tunnel({
88053
88169
  host: host2,
88054
88170
  port
88055
88171
  }) {
88056
- return new Promise((resolve28, reject) => {
88172
+ return new Promise((resolve27, reject) => {
88057
88173
  const socket = connectTcp(proxy.port, proxy.host);
88058
88174
  let answer6 = "";
88059
88175
  const auth = proxy.authorization ? `Proxy-Authorization: ${proxy.authorization}\r
@@ -88070,7 +88186,7 @@ ${auth}\r
88070
88186
  answer6 += chunk.toString("latin1");
88071
88187
  if (!answer6.includes(HEADER_END)) return;
88072
88188
  socket.off("data", onData);
88073
- if (/^HTTP\/1\.[01] 200/.test(answer6)) return resolve28(socket);
88189
+ if (/^HTTP\/1\.[01] 200/.test(answer6)) return resolve27(socket);
88074
88190
  socket.destroy();
88075
88191
  reject(new Error(`proxy refused the tunnel: ${answer6.split("\r\n")[0] ?? ""}`));
88076
88192
  };
@@ -88083,8 +88199,8 @@ async function upstreamOf({ target, proxy }) {
88083
88199
  const raw = proxy ? await tunnel({ proxy, host: target.hostname, port }) : connectTcp(port, target.hostname);
88084
88200
  if (!secure) return raw;
88085
88201
  const tls = connectTls({ socket: raw, servername: target.hostname });
88086
- await new Promise((resolve28, reject) => {
88087
- tls.once("secureConnect", () => resolve28());
88202
+ await new Promise((resolve27, reject) => {
88203
+ tls.once("secureConnect", () => resolve27());
88088
88204
  tls.once("error", reject);
88089
88205
  });
88090
88206
  return tls;
@@ -88126,8 +88242,8 @@ async function browserSocket({
88126
88242
  createConnection: () => upstream,
88127
88243
  perMessageDeflate: false
88128
88244
  });
88129
- await new Promise((resolve28, reject) => {
88130
- socket.once("open", () => resolve28());
88245
+ await new Promise((resolve27, reject) => {
88246
+ socket.once("open", () => resolve27());
88131
88247
  socket.once("error", reject);
88132
88248
  });
88133
88249
  return socket;
@@ -88140,12 +88256,12 @@ async function browserCall({
88140
88256
  }) {
88141
88257
  const socket = await browserSocket({ target, proxy });
88142
88258
  try {
88143
- return await new Promise((resolve28, reject) => {
88259
+ return await new Promise((resolve27, reject) => {
88144
88260
  socket.on("message", (data) => {
88145
88261
  const reply2 = JSON.parse(textOf3(data));
88146
88262
  if (reply2.id !== 1) return;
88147
88263
  if (reply2.error) reject(new Error(`${method}: ${JSON.stringify(reply2.error)}`));
88148
- else resolve28(reply2.result ?? {});
88264
+ else resolve27(reply2.result ?? {});
88149
88265
  });
88150
88266
  socket.once(
88151
88267
  "close",
@@ -88309,18 +88425,18 @@ function retargetCdpBridge({
88309
88425
  target,
88310
88426
  expiresAt
88311
88427
  }) {
88312
- return new Promise((resolve28) => {
88428
+ return new Promise((resolve27) => {
88313
88429
  const call = httpRequest(
88314
88430
  { host: "127.0.0.1", port, path: TARGET_PATH, method: "PUT", timeout: 2e3 },
88315
88431
  (response) => {
88316
88432
  response.resume();
88317
- resolve28(response.statusCode === 204);
88433
+ resolve27(response.statusCode === 204);
88318
88434
  }
88319
88435
  );
88320
88436
  call.setHeader(KEY_HEADER, key);
88321
88437
  call.setHeader("content-type", "application/json");
88322
88438
  call.once("timeout", () => call.destroy());
88323
- call.once("error", () => resolve28(false));
88439
+ call.once("error", () => resolve27(false));
88324
88440
  call.end(JSON.stringify({ target, expiresAt }));
88325
88441
  });
88326
88442
  }
@@ -88369,15 +88485,15 @@ async function startCdpBridge({
88369
88485
  (socket) => relayPage({ client: socket, targetId, target: url2, proxy })
88370
88486
  );
88371
88487
  });
88372
- await new Promise((resolve28) => server.listen(0, "127.0.0.1", resolve28));
88488
+ await new Promise((resolve27) => server.listen(0, "127.0.0.1", resolve27));
88373
88489
  const port = server.address().port;
88374
88490
  return {
88375
88491
  port,
88376
- close: () => new Promise((resolve28) => {
88492
+ close: () => new Promise((resolve27) => {
88377
88493
  for (const client of relayed) client.destroy();
88378
88494
  pages.close();
88379
88495
  server.closeAllConnections();
88380
- server.close(() => resolve28());
88496
+ server.close(() => resolve27());
88381
88497
  })
88382
88498
  };
88383
88499
  }
@@ -88394,7 +88510,7 @@ function launchCdpBridge({
88394
88510
  stdio: ["ignore", "pipe", "ignore"],
88395
88511
  env: { ...env, LAZE_CDP_TARGET: target, LAZE_CDP_EXPIRES_AT: expiresAt, LAZE_CDP_KEY: key }
88396
88512
  });
88397
- return new Promise((resolve28, reject) => {
88513
+ return new Promise((resolve27, reject) => {
88398
88514
  let printed2 = "";
88399
88515
  child.once("error", reject);
88400
88516
  child.once("exit", (code4) => reject(new Error(`the CDP bridge stopped (${code4})`)));
@@ -88405,7 +88521,7 @@ function launchCdpBridge({
88405
88521
  child.stdout.destroy();
88406
88522
  child.removeAllListeners("exit");
88407
88523
  child.unref();
88408
- if (Number.isInteger(port) && port > 0) resolve28(port);
88524
+ if (Number.isInteger(port) && port > 0) resolve27(port);
88409
88525
  else reject(new Error("the CDP bridge printed no port"));
88410
88526
  });
88411
88527
  });
@@ -88532,7 +88648,7 @@ async function answering({
88532
88648
  }
88533
88649
  function bridgeStatePath({ context, machine: machine2 }) {
88534
88650
  const safe = machine2.replace(/[^a-zA-Z0-9_-]/g, "_");
88535
- return join28(dirname18(context.environment.configPath), "bridges", `${safe}.json`);
88651
+ return join29(dirname19(context.environment.configPath), "bridges", `${safe}.json`);
88536
88652
  }
88537
88653
  async function bridgePort({
88538
88654
  context,
@@ -89246,7 +89362,7 @@ async function channelSettings({ context, args }) {
89246
89362
 
89247
89363
  // src/services/chat-actions-commands.service.ts
89248
89364
  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";
89365
+ import { basename as basename9, isAbsolute as isAbsolute2, relative as relative4, resolve as resolve11 } from "node:path";
89250
89366
 
89251
89367
  // src/rules/app-link.rules.ts
89252
89368
  var MARKDOWN_LINK = /^\[[^\]]*\]\((\S+)\)$/;
@@ -89274,8 +89390,8 @@ function appOfLinkOnly(body) {
89274
89390
 
89275
89391
  // src/services/file-download.service.ts
89276
89392
  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";
89393
+ import { mkdir as mkdir9, rename as rename3, rm as rm13, stat as stat10, truncate } from "node:fs/promises";
89394
+ import { basename as basename8, dirname as dirname20, resolve as resolve10 } from "node:path";
89279
89395
  import { Readable, Transform } from "node:stream";
89280
89396
  import { pipeline } from "node:stream/promises";
89281
89397
  var NOT_READY_WAIT_MS = 5e3;
@@ -89323,7 +89439,7 @@ function totalOf({ response, start: start2 }) {
89323
89439
  if (length === null) return void 0;
89324
89440
  return Number(length) + (response.status === 206 ? start2 : 0);
89325
89441
  }
89326
- var sizeOnDisk = (path) => stat11(path).then(
89442
+ var sizeOnDisk = (path) => stat10(path).then(
89327
89443
  (found) => found.size,
89328
89444
  () => 0
89329
89445
  );
@@ -89394,9 +89510,9 @@ async function downloadFile({
89394
89510
  attachmentId,
89395
89511
  out
89396
89512
  }) {
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 });
89513
+ const asked = out ? resolve10(context.cwd, out) : void 0;
89514
+ const part = resolve10(asked ? dirname20(asked) : context.cwd, `.${attachmentId}.part`);
89515
+ await mkdir9(dirname20(part), { recursive: true });
89400
89516
  const named = await fetchWhole({ context, client, attachmentId, part, out }).catch(
89401
89517
  async (error63) => {
89402
89518
  await rm13(part, { force: true });
@@ -89404,7 +89520,7 @@ async function downloadFile({
89404
89520
  throw new CliUsageError(`Could not write ${attachmentId} to disk: ${String(error63)}`);
89405
89521
  }
89406
89522
  );
89407
- const path = asked ?? resolve11(context.cwd, named ?? attachmentId);
89523
+ const path = asked ?? resolve10(context.cwd, named ?? attachmentId);
89408
89524
  await rename3(part, path);
89409
89525
  return { path, sizeBytes: await sizeOnDisk(path) };
89410
89526
  }
@@ -89695,7 +89811,7 @@ function uploadNameOf({ cwd, path }) {
89695
89811
  return inside && !inside.startsWith("..") && !isAbsolute2(inside) ? inside : basename9(path);
89696
89812
  }
89697
89813
  var fileUpload = async ({ context, args, client }) => {
89698
- const path = resolve12(context.cwd, wordAt(args, 3));
89814
+ const path = resolve11(context.cwd, wordAt(args, 3));
89699
89815
  const bytes = new Uint8Array(await readFile19(path));
89700
89816
  const answer6 = await uploadFile({
89701
89817
  context,
@@ -89927,20 +90043,8 @@ async function monitorRound(turn) {
89927
90043
  `);
89928
90044
  return false;
89929
90045
  }
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)}
90046
+ if (await droppedBinding({ context, session, error: error63, profile: turn.profile })) return false;
90047
+ context.err(`laze: the monitor will try again: ${String(error63)}
89944
90048
  `);
89945
90049
  return false;
89946
90050
  });
@@ -89952,13 +90056,13 @@ async function release({ context, profile }) {
89952
90056
  }
89953
90057
  async function monitorHook({ context, args }) {
89954
90058
  const claudePid = await claudePidOf({ context });
89955
- const session = await monitorSessionOf({ context, claudePid });
89956
- await rememberSession({ context, claudePid, session }).catch(() => void 0);
90059
+ const first = await monitorSessionOf({ context, claudePid });
90060
+ await rememberSession({ context, claudePid, session: first }).catch(() => void 0);
89957
90061
  const held = /* @__PURE__ */ new Set();
89958
- const turn = { context, args, claudePid, session };
89959
90062
  try {
89960
90063
  while (claudePid && context.processes.alive(claudePid)) {
89961
- const round = await oneRound({ turn, held });
90064
+ const session = await monitorSessionOf({ context, claudePid }) ?? first;
90065
+ const round = await oneRound({ turn: { context, args, claudePid, session }, held });
89962
90066
  if (round === "outranked") await context.sleep(MONITOR_OUTRANKED_MS);
89963
90067
  else if (!round) await context.sleep(MONITOR_IDLE_MS);
89964
90068
  }
@@ -89969,7 +90073,7 @@ async function monitorHook({ context, args }) {
89969
90073
  }
89970
90074
  async function oneRound({ turn, held }) {
89971
90075
  try {
89972
- const profile = await agentProfileHere(turn);
90076
+ const profile = await agentProfileHere({ context: turn.context, session: turn.session });
89973
90077
  const round = profile ? await monitorRound({ ...turn, profile }) : false;
89974
90078
  if (profile && round === true) held.add(profile);
89975
90079
  return round;
@@ -89985,9 +90089,9 @@ async function monitorSessionOf({
89985
90089
  }) {
89986
90090
  const sessionId = context.environment.inherited.CLAUDE_CODE_SESSION_ID;
89987
90091
  const fromEnv = sessionOf({ context, harness: "claude-code", sessionId });
89988
- if (fromEnv || !claudePid) return fromEnv;
90092
+ if (!claudePid) return fromEnv;
89989
90093
  const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
89990
- return readStateJson({ path });
90094
+ return await readStateJson({ path }) ?? fromEnv;
89991
90095
  }
89992
90096
 
89993
90097
  // ../../modules/compute/contract/src/browser-tab.ts
@@ -92834,9 +92938,9 @@ var computerBrowserFactsDefinition = external_exports.object({
92834
92938
  var computerBrowserFactsSchema = computerBrowserFactsDefinition;
92835
92939
 
92836
92940
  // 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";
92941
+ import { mkdtemp as mkdtemp2, open as open7, rm as rm15, stat as stat11 } from "node:fs/promises";
92838
92942
  import { tmpdir as tmpdir4 } from "node:os";
92839
- import { basename as basename10, dirname as dirname20, resolve as resolve13 } from "node:path";
92943
+ import { basename as basename10, dirname as dirname21, resolve as resolve12 } from "node:path";
92840
92944
  var COMPUTER_COPY_USAGE = ` laze computer copy <path> --agent <agent> [--to <folder>] [--json]
92841
92945
  copy a local file or folder into your hosted agent's work folder
92842
92946
  (its owner only, up to 2 GiB packed); <folder> is relative to the
@@ -92850,9 +92954,9 @@ function stringFlag(args, name3) {
92850
92954
  }
92851
92955
  function packingOf({ path, isDirectory }) {
92852
92956
  const contents = isDirectory && path.endsWith("/");
92853
- const absolute = resolve13(path);
92957
+ const absolute = resolve12(path);
92854
92958
  const name3 = basename10(absolute);
92855
- return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent: dirname20(absolute), entry: name3 };
92959
+ return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent: dirname21(absolute), entry: name3 };
92856
92960
  }
92857
92961
  async function sendParts3({
92858
92962
  context,
@@ -92896,22 +93000,22 @@ async function copy({ context, args }) {
92896
93000
  if (!path || !agent3) throw new CliUsageError(`Usage:
92897
93001
  ${COMPUTER_COPY_USAGE}`);
92898
93002
  const to = stringFlag(args, "to") ?? ".";
92899
- const full = resolve13(context.cwd, path);
92900
- const found = await stat12(full).catch(() => void 0);
93003
+ const full = resolve12(context.cwd, path);
93004
+ const found = await stat11(full).catch(() => void 0);
92901
93005
  if (!found) throw new CliUsageError(`${path} does not exist`);
92902
93006
  const { name: name3, parent, entry: entry2 } = packingOf({
92903
93007
  path: path.endsWith("/") ? `${full}/` : full,
92904
93008
  isDirectory: found.isDirectory()
92905
93009
  });
92906
- const dir = await mkdtemp2(resolve13(tmpdir4(), "laze-copy-"));
92907
- const archive2 = resolve13(dir, `${name3}.tar.gz`);
93010
+ const dir = await mkdtemp2(resolve12(tmpdir4(), "laze-copy-"));
93011
+ const archive2 = resolve12(dir, `${name3}.tar.gz`);
92908
93012
  try {
92909
93013
  const code4 = await context.runCommand({
92910
93014
  command: ["tar", "-czf", archive2, "-C", parent, entry2],
92911
93015
  env: { COPYFILE_DISABLE: "1" }
92912
93016
  });
92913
93017
  if (code4 !== 0) throw new CliUsageError(`tar could not pack ${path} (exit ${code4})`);
92914
- const sizeBytes = (await stat12(archive2)).size;
93018
+ const sizeBytes = (await stat11(archive2)).size;
92915
93019
  if (sizeBytes > COMPUTER_COPY_MAX_BYTES)
92916
93020
  throw new CliUsageError(`${path} packs to ${mb(sizeBytes)}; a copy holds at most 2 GiB`);
92917
93021
  const client = await computeClient({ context, args });
@@ -93235,8 +93339,8 @@ import { readFile as readFile21 } from "node:fs/promises";
93235
93339
 
93236
93340
  // src/services/mcp-gateway.service.ts
93237
93341
  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";
93342
+ import { basename as basename11, join as join30, resolve as resolve13 } from "node:path";
93343
+ import { createInterface as createInterface2 } from "node:readline";
93240
93344
 
93241
93345
  // src/services/mcp-support.service.ts
93242
93346
  var SUPPORT_TOOL_NAMES = ["support_read_thread", "support_answer", "support_needs_human"];
@@ -93335,7 +93439,7 @@ function serveMcpGateway({
93335
93439
  context,
93336
93440
  args
93337
93441
  }) {
93338
- return relayMcpLines({ context, args, lines: createInterface3({ input: process.stdin }) });
93442
+ return relayMcpLines({ context, args, lines: createInterface2({ input: process.stdin }) });
93339
93443
  }
93340
93444
  var WATCH_MS2 = 2e3;
93341
93445
  var LIST_CHANGED = '{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}';
@@ -93378,7 +93482,7 @@ async function relayMcpLines({
93378
93482
  const relay2 = {
93379
93483
  readTurn,
93380
93484
  out: (text3) => context.out(text3),
93381
- saveFile: (file4) => saveMailFile({ root: resolve14(context.cwd, MAIL_FILES_DIR), file: file4 }),
93485
+ saveFile: (file4) => saveMailFile({ root: resolve13(context.cwd, MAIL_FILES_DIR), file: file4 }),
93382
93486
  post: async ({ line, turn }) => {
93383
93487
  if (args.flags.support === true) return answerSupportLine({ line, turn, client });
93384
93488
  const response = await context.fetcher(url2, {
@@ -93414,8 +93518,8 @@ function safeName(name3, fallback) {
93414
93518
  return last && last !== "." && last !== ".." ? last : fallback;
93415
93519
  }
93416
93520
  async function saveMailFile({ root, file: file4 }) {
93417
- const dir = join29(root, safeName(file4.messageId, "message"));
93418
- const path = join29(dir, safeName(file4.fileName, "attachment"));
93521
+ const dir = join30(root, safeName(file4.messageId, "message"));
93522
+ const path = join30(dir, safeName(file4.fileName, "attachment"));
93419
93523
  await mkdir10(dir, { recursive: true });
93420
93524
  await writeFile7(path, Buffer.from(file4.base64, "base64"));
93421
93525
  return path;
@@ -93666,7 +93770,7 @@ async function suggestServer({
93666
93770
 
93667
93771
  // src/services/connector-commands.service.ts
93668
93772
  import { readFile as readFile23 } from "node:fs/promises";
93669
- import { resolve as resolve15 } from "node:path";
93773
+ import { resolve as resolve14 } from "node:path";
93670
93774
 
93671
93775
  // src/services/vault-keychain-commands.service.ts
93672
93776
  import { readFile as readFile22 } from "node:fs/promises";
@@ -94326,7 +94430,7 @@ async function keyText({ context, args }) {
94326
94430
  throw new CliUsageError("A key never goes in a flag: pipe it on stdin or use --from-file.");
94327
94431
  }
94328
94432
  const file4 = flagText({ args, name: "from-file" });
94329
- const text3 = file4 ? await readFile23(resolve15(context.cwd, file4), "utf8") : await context.readStdin();
94433
+ const text3 = file4 ? await readFile23(resolve14(context.cwd, file4), "utf8") : await context.readStdin();
94330
94434
  const trimmed = text3.trim();
94331
94435
  if (!trimmed) throw new CliUsageError("No key: pipe it on stdin or use --from-file.");
94332
94436
  return trimmed;
@@ -94716,7 +94820,7 @@ async function conversationDelete({ context, args }) {
94716
94820
 
94717
94821
  // src/services/discord-commands.service.ts
94718
94822
  import { readFile as readFile24 } from "node:fs/promises";
94719
- import { resolve as resolve16 } from "node:path";
94823
+ import { resolve as resolve15 } from "node:path";
94720
94824
 
94721
94825
  // ../../modules/discord/contract/src/discord.ts
94722
94826
  var workspaceIdSchema25 = external_exports.string().min(1).max(64);
@@ -95063,7 +95167,7 @@ async function secretsOf({ context, args }) {
95063
95167
  const fromConnection = flagText({ args, name: "from-vault" });
95064
95168
  if (fromConnection) return { fromConnection };
95065
95169
  const file4 = flagText({ args, name: "from-file" });
95066
- const text3 = file4 ? await readFile24(resolve16(context.cwd, file4), "utf8") : await context.readStdin();
95170
+ const text3 = file4 ? await readFile24(resolve15(context.cwd, file4), "utf8") : await context.readStdin();
95067
95171
  const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
95068
95172
  if (lines2.length !== 2) {
95069
95173
  throw new CliUsageError(
@@ -95333,8 +95437,8 @@ var DOMAINS_USAGE = `Usage:
95333
95437
  var printJson5 = (context, data) => context.out(`${JSON.stringify(data, null, 2)}
95334
95438
  `);
95335
95439
  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" : ""}
95440
+ const join38 = row.autoJoin ? "auto-join on" : "auto-join off";
95441
+ context.out(`${row.domain} ${join38}${row.enforced ? " single sign-on enforced" : ""}
95338
95442
  `);
95339
95443
  }
95340
95444
  async function list5({ context, args }) {
@@ -95367,7 +95471,7 @@ async function domains({ context, args }) {
95367
95471
 
95368
95472
  // src/services/emoji-commands.service.ts
95369
95473
  import { readFile as readFile25 } from "node:fs/promises";
95370
- import { resolve as resolve17 } from "node:path";
95474
+ import { resolve as resolve16 } from "node:path";
95371
95475
  var EMOJI_USAGE = `Usage:
95372
95476
  laze emoji list [--json] the workspace's custom emoji, aliases and who added each
95373
95477
  laze emoji add <name> <file> [--alias <a,b>] add a PNG, JPEG or GIF as :name: (made 128px square)
@@ -95407,7 +95511,7 @@ async function addEmoji({ context, args, client }) {
95407
95511
  const file4 = wordAt4(args, 3);
95408
95512
  let bytes;
95409
95513
  try {
95410
- bytes = new Uint8Array(await readFile25(resolve17(context.cwd, file4)));
95514
+ bytes = new Uint8Array(await readFile25(resolve16(context.cwd, file4)));
95411
95515
  } catch {
95412
95516
  throw new CliUsageError(`Cannot read ${file4}.`);
95413
95517
  }
@@ -95747,7 +95851,7 @@ var ExternalSharingHooksToken = externalUi.hooks("sharing");
95747
95851
 
95748
95852
  // src/services/workspace-commands.service.ts
95749
95853
  import { readFile as readFile26 } from "node:fs/promises";
95750
- import { resolve as resolve18 } from "node:path";
95854
+ import { resolve as resolve17 } from "node:path";
95751
95855
  var ROLE_NAMES2 = {
95752
95856
  OWNER: "Owner",
95753
95857
  ADMIN: "Admin",
@@ -95929,7 +96033,7 @@ var LOGO_USAGE = "Usage: laze workspace logo set <file.png|jpg|webp> | laze work
95929
96033
  async function readLogo({ context, file: file4 }) {
95930
96034
  let bytes;
95931
96035
  try {
95932
- bytes = new Uint8Array(await readFile26(resolve18(context.cwd, file4)));
96036
+ bytes = new Uint8Array(await readFile26(resolve17(context.cwd, file4)));
95933
96037
  } catch {
95934
96038
  throw new CliUsageError(`No file to read at ${file4}.`);
95935
96039
  }
@@ -96565,7 +96669,7 @@ async function agentFeedAccess({
96565
96669
 
96566
96670
  // src/services/feed-commands.service.ts
96567
96671
  import { readFile as readFile27 } from "node:fs/promises";
96568
- import { resolve as resolve19 } from "node:path";
96672
+ import { resolve as resolve18 } from "node:path";
96569
96673
 
96570
96674
  // ../../modules/feed/contract/src/feed.delegate.ts
96571
96675
  var feedDelegateSchemaDefinition = external_exports.object({
@@ -97792,7 +97896,7 @@ async function bodyOf2({
97792
97896
  flags: flags2
97793
97897
  }) {
97794
97898
  const body = { ...flags2.fields };
97795
- const read4 = (source) => "file" in source ? readFile27(resolve19(context.cwd, source.file), "utf8") : source.text;
97899
+ const read4 = (source) => "file" in source ? readFile27(resolve18(context.cwd, source.file), "utf8") : source.text;
97796
97900
  for (const [field, source] of Object.entries(flags2.texts)) body[field] = await read4(source);
97797
97901
  if (flags2.rich) {
97798
97902
  const text3 = await read4(flags2.rich.source);
@@ -98069,7 +98173,7 @@ async function textFlag({
98069
98173
  }) {
98070
98174
  const value = flagText({ args, name: name3 });
98071
98175
  if (!value.startsWith("@")) return value;
98072
- return readFile27(resolve19(context.cwd, value.slice(1)), "utf8");
98176
+ return readFile27(resolve18(context.cwd, value.slice(1)), "utf8");
98073
98177
  }
98074
98178
  async function feedList({ context, args }) {
98075
98179
  const { client, profile } = await signedIn({ context, args });
@@ -98159,7 +98263,7 @@ async function ranksOf({
98159
98263
  }) {
98160
98264
  const file4 = flagText({ args, name: "file" });
98161
98265
  if (file4) {
98162
- const parsed = JSON.parse(await readFile27(resolve19(context.cwd, file4), "utf8"));
98266
+ const parsed = JSON.parse(await readFile27(resolve18(context.cwd, file4), "utf8"));
98163
98267
  if (Array.isArray(parsed)) return parsed;
98164
98268
  throw new CliUsageError("--file holds a list of {itemId, priority}");
98165
98269
  }
@@ -99027,12 +99131,12 @@ async function ip({ context, args }) {
99027
99131
 
99028
99132
  // src/services/join-commands.service.ts
99029
99133
  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";
99134
+ import { hostname as hostname9 } from "node:os";
99135
+ import { dirname as dirname22, join as join31 } from "node:path";
99032
99136
  var DEFAULT_WAIT_SECONDS2 = 100;
99033
99137
  var JOIN_USAGE = "Usage: laze join [--workspace <name|id|invite link>] [--for <email>] [--name <name>] [--note <text>] [--timeout <seconds>] [--project <folder>]";
99034
99138
  function pendingPathOf({ context }) {
99035
- return join30(dirname21(context.environment.configPath), "join", "pending.json");
99139
+ return join31(dirname22(context.environment.configPath), "join", "pending.json");
99036
99140
  }
99037
99141
  async function readPending({
99038
99142
  context,
@@ -99169,7 +99273,7 @@ async function joinAsAgent({ context, args }) {
99169
99273
  harness,
99170
99274
  ...asked,
99171
99275
  ...machineOwners.length > 0 ? { machineOwners } : {},
99172
- machine: hostname8().slice(0, 120),
99276
+ machine: hostname9().slice(0, 120),
99173
99277
  ...flagText({ args, name: "name" }) ? { name: flagText({ args, name: "name" }) } : {},
99174
99278
  ...flagText({ args, name: "note" }) ? { note: flagText({ args, name: "note" }) } : {}
99175
99279
  }).then((started) => ({ ...started, url: url2, asked })).catch((error63) => sandboxed({ context, error: error63 }));
@@ -100057,7 +100161,7 @@ async function machine({ context, args }) {
100057
100161
  }
100058
100162
 
100059
100163
  // src/services/mcp-server.service.ts
100060
- import { createInterface as createInterface4 } from "node:readline";
100164
+ import { createInterface as createInterface3 } from "node:readline";
100061
100165
  var SERVER_REFUSED = -32001;
100062
100166
  var MCP_REFUSED_COMMANDS = /* @__PURE__ */ new Set([
100063
100167
  "login",
@@ -100301,24 +100405,24 @@ async function serveMcp({
100301
100405
  runCommandLine
100302
100406
  }) {
100303
100407
  const lines2 = {
100304
- [Symbol.asyncIterator]: () => createInterface4({ input: process.stdin })[Symbol.asyncIterator]()
100408
+ [Symbol.asyncIterator]: () => createInterface3({ input: process.stdin })[Symbol.asyncIterator]()
100305
100409
  };
100306
100410
  await answerMcpLines({ context, args, lines: lines2, runCommandLine });
100307
100411
  }
100308
100412
 
100309
100413
  // 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";
100414
+ import { readdir as readdir7, readFile as readFile30 } from "node:fs/promises";
100415
+ import { join as join32, resolve as resolve20 } from "node:path";
100312
100416
 
100313
100417
  // src/services/mount-files.service.ts
100314
100418
  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";
100419
+ import { dirname as dirname23, relative as relative5, resolve as resolve19 } from "node:path";
100316
100420
  async function textArgument({
100317
100421
  context,
100318
100422
  value
100319
100423
  }) {
100320
100424
  if (value === "-") return context.readStdin();
100321
- if (value.startsWith("@")) return readFile29(resolve20(context.cwd, value.slice(1)), "utf8");
100425
+ if (value.startsWith("@")) return readFile29(resolve19(context.cwd, value.slice(1)), "utf8");
100322
100426
  return value;
100323
100427
  }
100324
100428
  function turnChannel({ context, args }) {
@@ -100330,15 +100434,15 @@ async function writeMount({
100330
100434
  folder,
100331
100435
  files: files2
100332
100436
  }) {
100333
- const root = resolve20(context.cwd, flagText({ args, name: "dir", fallback: ".laze" }), folder);
100437
+ const root = resolve19(context.cwd, flagText({ args, name: "dir", fallback: ".laze" }), folder);
100334
100438
  await rm17(root, { recursive: true, force: true });
100335
100439
  await mkdir11(root, { recursive: true });
100336
100440
  for (const file4 of files2) {
100337
- const target = resolve20(root, file4.path);
100441
+ const target = resolve19(root, file4.path);
100338
100442
  const inside = relative5(root, target);
100339
100443
  if (!inside || inside.startsWith(".."))
100340
100444
  throw new Error(`Refusing to write outside ${root}: ${file4.path}`);
100341
- await mkdir11(dirname22(target), { recursive: true });
100445
+ await mkdir11(dirname23(target), { recursive: true });
100342
100446
  await writeFile8(target, file4.content);
100343
100447
  }
100344
100448
  return root;
@@ -100594,16 +100698,16 @@ async function siestaImport({
100594
100698
  args,
100595
100699
  dir
100596
100700
  }) {
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(
100701
+ const root = resolve20(context.cwd, dir);
100702
+ const log = await readFile30(join32(root, "LOG.md"));
100703
+ const names = (await readdir7(join32(root, "tree")).catch(() => [])).filter(
100600
100704
  (name3) => /^\d{1,6}-\d{1,6}\.md$/.test(name3)
100601
100705
  );
100602
100706
  const tree = Object.fromEntries(
100603
100707
  await Promise.all(
100604
100708
  names.map(async (name3) => [
100605
100709
  name3.slice(0, -3),
100606
- (await readFile30(join31(root, "tree", name3))).toString("base64")
100710
+ (await readFile30(join32(root, "tree", name3))).toString("base64")
100607
100711
  ])
100608
100712
  )
100609
100713
  );
@@ -100622,16 +100726,16 @@ async function memoryImport({ context, args }) {
100622
100726
  if (siesta) return siestaImport({ context, args, dir: siesta });
100623
100727
  const dir = flagText({ args, name: "optmem" });
100624
100728
  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(
100729
+ const root = resolve20(context.cwd, dir);
100730
+ const log = await readFile30(join32(root, "LOG.txt"));
100731
+ const sizes2 = (await readdir7(join32(root, "TREE")).catch(() => [])).filter(
100628
100732
  (name3) => /^\d{1,4}$/.test(name3)
100629
100733
  );
100630
100734
  const tree = Object.fromEntries(
100631
100735
  await Promise.all(
100632
100736
  sizes2.map(async (size) => [
100633
100737
  size,
100634
- (await readFile30(join31(root, "TREE", size))).toString("base64")
100738
+ (await readFile30(join32(root, "TREE", size))).toString("base64")
100635
100739
  ])
100636
100740
  )
100637
100741
  );
@@ -101024,7 +101128,7 @@ async function notifications({ context, args }) {
101024
101128
  }
101025
101129
 
101026
101130
  // src/services/openclaw-commands.service.ts
101027
- import { resolve as resolve22 } from "node:path";
101131
+ import { resolve as resolve21 } from "node:path";
101028
101132
  var OPENCLAW_USAGE = `Usage (a person's key; a gateway belongs to the person who connects it):
101029
101133
  laze openclaw list the gateways connected here and their agents
101030
101134
  laze openclaw connect <wss url> [--label <label>] (< token | --from-file <file> | --from-vault <connection>)
@@ -101175,7 +101279,7 @@ var agentKey = async ({ context, args, client, url: url2 }) => {
101175
101279
  });
101176
101280
  const login2 = flagText({ args, name: "login" });
101177
101281
  if (login2) {
101178
- const folder = resolve22(context.cwd, login2);
101282
+ const folder = resolve21(context.cwd, login2);
101179
101283
  const profile = profileNameOf(key.agentName);
101180
101284
  await signInFolder({ context, url: url2, token: key.token, name: profile, folder });
101181
101285
  context.out(
@@ -101227,9 +101331,9 @@ async function openclaw({
101227
101331
  }
101228
101332
 
101229
101333
  // src/services/operator-key-commands.service.ts
101230
- import { createHash as createHash9, randomBytes as randomBytes5 } from "node:crypto";
101334
+ import { createHash as createHash10, randomBytes as randomBytes5 } from "node:crypto";
101231
101335
  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";
101336
+ import { dirname as dirname24, join as join33 } from "node:path";
101233
101337
 
101234
101338
  // ../../modules/audit-log/contract/src/audit-log.api.ts
101235
101339
  var auditEntrySchemaDefinition = external_exports.object({
@@ -103004,14 +103108,14 @@ Ops function leases (ADR-214), instead of reading the database:
103004
103108
  call one function of an approved lease; a cut
103005
103109
  list says so and names the cursor of the next page`;
103006
103110
  var POLL_MS3 = 5e3;
103007
- var keyFile = ({ context, keyId }) => join32(dirname23(context.environment.configPath), "operator-keys", keyId.replaceAll("/", "_"));
103111
+ var keyFile = ({ context, keyId }) => join33(dirname24(context.environment.configPath), "operator-keys", keyId.replaceAll("/", "_"));
103008
103112
  async function saveSecret({
103009
103113
  context,
103010
103114
  keyId,
103011
103115
  secret
103012
103116
  }) {
103013
103117
  const path = keyFile({ context, keyId });
103014
- await mkdir12(dirname23(path), { recursive: true, mode: 448 });
103118
+ await mkdir12(dirname24(path), { recursive: true, mode: 448 });
103015
103119
  await writeFile9(path, secret, { mode: 384 });
103016
103120
  }
103017
103121
  function typedArg(text3) {
@@ -103069,7 +103173,7 @@ async function requestKey({ context, args }) {
103069
103173
  target,
103070
103174
  args: argsOf({ args }),
103071
103175
  reason: reason2,
103072
- secretHash: createHash9("sha256").update(secret).digest("hex")
103176
+ secretHash: createHash10("sha256").update(secret).digest("hex")
103073
103177
  });
103074
103178
  await saveSecret({ context, keyId: key.id, secret });
103075
103179
  const answered = args.flags.wait ? await waitForAnswer({ context, client, key }) : key;
@@ -103167,7 +103271,7 @@ async function requestLease({ context, args }) {
103167
103271
  args: {},
103168
103272
  functions,
103169
103273
  reason: reason2,
103170
- secretHash: createHash9("sha256").update(secret).digest("hex")
103274
+ secretHash: createHash10("sha256").update(secret).digest("hex")
103171
103275
  });
103172
103276
  await saveSecret({ context, keyId: key.id, secret });
103173
103277
  const answered = args.flags.wait ? await waitForAnswer({ context, client, key }) : key;
@@ -103248,7 +103352,7 @@ ${OPS_USAGE}`);
103248
103352
 
103249
103353
  // src/services/release-watch.service.ts
103250
103354
  import { realpath as realpath2 } from "node:fs/promises";
103251
- import { dirname as dirname24, join as join33 } from "node:path";
103355
+ import { dirname as dirname25, join as join34 } from "node:path";
103252
103356
  var RETRY_AFTER_MS = 6 * 60 * 60 * 1e3;
103253
103357
  async function scriptOf(context) {
103254
103358
  const script = context.program.at(-1) ?? "";
@@ -103265,15 +103369,15 @@ async function startedUpdate({
103265
103369
  if (context.environment.inherited.LAZE_AUTO_UPDATE === "0") return null;
103266
103370
  const plan2 = updatePlanOf({ script: await scriptOf(context) });
103267
103371
  if (plan2.kind !== "install") return null;
103268
- const folder = dirname24(context.environment.configPath);
103269
- const stamp = join33(folder, "auto-update.json");
103372
+ const folder = dirname25(context.environment.configPath);
103373
+ const stamp = join34(folder, "auto-update.json");
103270
103374
  const last = await readStateJson({ path: stamp }) ?? null;
103271
103375
  const now = context.nowMs();
103272
103376
  if (last?.server === server && now - last.atMs < RETRY_AFTER_MS) return null;
103273
103377
  await writeStateJson({ path: stamp, value: { server, atMs: now } });
103274
103378
  context.processes.spawnDetached({
103275
103379
  argv: [...context.program, "update"],
103276
- logPath: join33(folder, "auto-update.log")
103380
+ logPath: join34(folder, "auto-update.log")
103277
103381
  });
103278
103382
  return { manager: plan2.manager };
103279
103383
  }
@@ -103569,8 +103673,8 @@ async function schedule({ context, args }) {
103569
103673
  }
103570
103674
 
103571
103675
  // 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";
103676
+ import { readdir as readdir8, readFile as readFile32 } from "node:fs/promises";
103677
+ import { join as join35, relative as relative6, resolve as resolve22 } from "node:path";
103574
103678
  var USAGE18 = `Usage:
103575
103679
  laze skill list [--agent <agentId>]
103576
103680
  laze skill install <catalogue-id> [--as <name>] [--agent <agentId>]
@@ -103587,11 +103691,11 @@ var USAGE18 = `Usage:
103587
103691
  --agent names the agent with a person's key; an agent's key works on its own skills.
103588
103692
  With a person's key, list without --agent shows every agent's skills.`;
103589
103693
  async function folderFiles({ root }) {
103590
- const entries = await readdir9(root, { recursive: true, withFileTypes: true });
103694
+ const entries = await readdir8(root, { recursive: true, withFileTypes: true });
103591
103695
  const files2 = [];
103592
103696
  for (const entry2 of entries) {
103593
103697
  if (!entry2.isFile()) continue;
103594
- const full = join34(entry2.parentPath, entry2.name);
103698
+ const full = join35(entry2.parentPath, entry2.name);
103595
103699
  files2.push({ path: relative6(root, full), content: await readFile32(full, "utf8") });
103596
103700
  }
103597
103701
  return files2.toSorted((a, b) => a.path.localeCompare(b.path));
@@ -103623,7 +103727,7 @@ async function skillInstall({ context, args }) {
103623
103727
  if (!catalogueId === !from) throw new CliUsageError(USAGE18);
103624
103728
  const name3 = flagText({ args, name: "as" });
103625
103729
  const agent3 = flagText({ args, name: "agent" });
103626
- const files2 = from ? await folderFiles({ root: resolve23(context.cwd, from) }) : void 0;
103730
+ const files2 = from ? await folderFiles({ root: resolve22(context.cwd, from) }) : void 0;
103627
103731
  const { client } = await signedIn({ context, args });
103628
103732
  const installed = await client.post("/api/skills/install", {
103629
103733
  ...catalogueId ? { catalogueId } : {},
@@ -103690,7 +103794,7 @@ async function skillUpdate({ context, args }) {
103690
103794
  if (!name3 || !newName && description === void 0 && !skillMdFile) {
103691
103795
  throw new CliUsageError(USAGE18);
103692
103796
  }
103693
- const skillMd = skillMdFile ? await readFile32(resolve23(context.cwd, skillMdFile), "utf8") : void 0;
103797
+ const skillMd = skillMdFile ? await readFile32(resolve22(context.cwd, skillMdFile), "utf8") : void 0;
103694
103798
  const { client } = await signedIn({ context, args });
103695
103799
  const updated = await client.post("/api/skills/update", {
103696
103800
  name: name3,
@@ -103737,7 +103841,7 @@ async function skill({ context, args }) {
103737
103841
 
103738
103842
  // src/services/slack-commands.service.ts
103739
103843
  import { readFile as readFile33 } from "node:fs/promises";
103740
- import { resolve as resolve24 } from "node:path";
103844
+ import { resolve as resolve23 } from "node:path";
103741
103845
  var SLACK_USAGE = `Usage (a person's key; Slack stays the source, the bot joins no channel by itself):
103742
103846
  laze slack overview connected Slack workspaces, mirrors, your link
103743
103847
  laze slack link-prompts Slack workspaces you have not linked yet
@@ -103787,7 +103891,7 @@ async function secretLines({ context, args }) {
103787
103891
  throw new CliUsageError("A secret never goes in a flag: pipe it on stdin or use --from-file.");
103788
103892
  }
103789
103893
  const file4 = flagText({ args, name: "from-file" });
103790
- const text3 = file4 ? await readFile33(resolve24(context.cwd, file4), "utf8") : await context.readStdin();
103894
+ const text3 = file4 ? await readFile33(resolve23(context.cwd, file4), "utf8") : await context.readStdin();
103791
103895
  return text3.split("\n").map((line) => line.trim()).filter(Boolean);
103792
103896
  }
103793
103897
  async function secretsOf2({
@@ -104536,8 +104640,8 @@ async function checkInstalled({
104536
104640
  }
104537
104641
 
104538
104642
  // 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";
104643
+ import { readFile as readFile35, stat as stat12 } from "node:fs/promises";
104644
+ import { dirname as dirname26, join as join36, resolve as resolve24 } from "node:path";
104541
104645
 
104542
104646
  // src/rules/vault-manifest.rules.ts
104543
104647
  var VARIABLE = /^[A-Za-z_][A-Za-z0-9_]*$/;
@@ -104870,7 +104974,7 @@ function refusedReason({
104870
104974
  return VAULT_EXIT_BAD_REASON;
104871
104975
  }
104872
104976
  async function isFile(path) {
104873
- return stat13(path).then(
104977
+ return stat12(path).then(
104874
104978
  (found) => found.isFile(),
104875
104979
  () => false
104876
104980
  );
@@ -104880,12 +104984,12 @@ async function manifestPathOf({
104880
104984
  args
104881
104985
  }) {
104882
104986
  const named = args.words[2];
104883
- if (named) return resolve25(context.cwd, named);
104987
+ if (named) return resolve24(context.cwd, named);
104884
104988
  const environment = flagText({ args, name: "env" });
104885
104989
  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;
104990
+ for (let dir = resolve24(context.cwd); ; dir = dirname26(dir)) {
104991
+ if (await isFile(join36(dir, file4))) return join36(dir, file4);
104992
+ if (dirname26(dir) === dir) break;
104889
104993
  }
104890
104994
  throw new CliUsageError(`laze vault: no ${file4} here or in a parent folder
104891
104995
  ${ENV_USAGE}`);
@@ -105258,7 +105362,7 @@ async function vaultScrub({ context, args }) {
105258
105362
 
105259
105363
  // src/services/whatsapp-business-commands.service.ts
105260
105364
  import { readFile as readFile36 } from "node:fs/promises";
105261
- import { resolve as resolve26 } from "node:path";
105365
+ import { resolve as resolve25 } from "node:path";
105262
105366
 
105263
105367
  // ../../modules/whatsapp-business/contract/src/whatsapp-business.prices.ts
105264
105368
  var whatsappBusinessCategorySchema = external_exports.enum([
@@ -105754,7 +105858,7 @@ async function secretsOf3({ context, args }) {
105754
105858
  const fromConnection = flagText({ args, name: "from-vault" });
105755
105859
  if (fromConnection) return { fromConnection };
105756
105860
  const file4 = flagText({ args, name: "from-file" });
105757
- const text3 = file4 ? await readFile36(resolve26(context.cwd, file4), "utf8") : await context.readStdin();
105861
+ const text3 = file4 ? await readFile36(resolve25(context.cwd, file4), "utf8") : await context.readStdin();
105758
105862
  const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
105759
105863
  if (lines2.length !== 2) {
105760
105864
  throw new CliUsageError(
@@ -105956,7 +106060,7 @@ async function whatsappBusiness({
105956
106060
 
105957
106061
  // src/services/whatsapp-commands.service.ts
105958
106062
  import { writeFile as writeFile10 } from "node:fs/promises";
105959
- import { basename as basename12, resolve as resolve27 } from "node:path";
106063
+ import { basename as basename12, resolve as resolve26 } from "node:path";
105960
106064
 
105961
106065
  // src/services/whatsapp-pairing-commands.service.ts
105962
106066
  var WHATSAPP_PAIRING_USAGE = " laze whatsapp unpair <machine> unlink WhatsApp from the machine (owner)";
@@ -106096,7 +106200,7 @@ async function file3({ context, args }) {
106096
106200
  },
106097
106201
  args
106098
106202
  });
106099
- const out = resolve27(context.cwd, flagText({ args, name: "out" }) ?? basename12(answer6.fileName));
106203
+ const out = resolve26(context.cwd, flagText({ args, name: "out" }) ?? basename12(answer6.fileName));
106100
106204
  const response = await context.fetcher(answer6.url);
106101
106205
  if (!response.ok) throw new Error(`The file link answered ${response.status}`);
106102
106206
  await writeFile10(out, new Uint8Array(await response.arrayBuffer()));
@@ -106522,6 +106626,7 @@ var HELP = `laze: work in a Laze workspace from your terminal or your agent.
106522
106626
  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
106627
  laze agent link --token <token> [--name <name>] [--project <folder>] connect this Claude Code or Codex session
106524
106628
  laze agent bind the linked agent listens in this session from now on
106629
+ laze agent sessions [--migrate] [--json] the sessions this machine binds to its agents
106525
106630
  laze agent request [--name <name>] ask the agent's owner for a new Laze agent with this session
106526
106631
  laze agent create --name <name> [--description <text>] [--harness laze-models|claude-code|codex] [--avatar <file>|--avatar-emoji <emoji>]
106527
106632
  make an agent for your owner (or for you): personal, opened in their direct messages
@@ -106743,6 +106848,7 @@ var COMMANDS5 = {
106743
106848
  "agent link": linkAgent,
106744
106849
  "agent bind": bindAgentSession,
106745
106850
  "agent request": requestAgent,
106851
+ "agent sessions": listAgentSessions,
106746
106852
  "hook stop": stopHook,
106747
106853
  "hook wait": waitHook,
106748
106854
  "hook pre-tool": preToolHook,
@@ -106951,21 +107057,21 @@ function exitCodeOf({
106951
107057
  // src/services/machine-key.service.ts
106952
107058
  import { execFile as execFile2 } from "node:child_process";
106953
107059
  import {
106954
- createHash as createHash10,
107060
+ createHash as createHash11,
106955
107061
  createPrivateKey,
106956
107062
  generateKeyPairSync,
106957
107063
  randomBytes as randomBytes6,
106958
107064
  sign
106959
107065
  } from "node:crypto";
106960
107066
  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";
107067
+ import { dirname as dirname27, join as join37 } from "node:path";
106962
107068
  var KEYCHAIN_SERVICE = "laze-cli-machine-key";
106963
- var runProgram = ({ program, args, stdin: stdin2, timeoutMs }) => new Promise((resolve28, reject) => {
107069
+ var runProgram = ({ program, args, stdin: stdin2, timeoutMs }) => new Promise((resolve27, reject) => {
106964
107070
  const child = execFile2(
106965
107071
  program,
106966
107072
  [...args],
106967
107073
  { timeout: timeoutMs },
106968
- (error63, stdout2) => error63 ? reject(error63) : resolve28(String(stdout2))
107074
+ (error63, stdout2) => error63 ? reject(error63) : resolve27(String(stdout2))
106969
107075
  );
106970
107076
  if (stdin2 !== void 0) child.stdin?.end(stdin2);
106971
107077
  });
@@ -106998,15 +107104,15 @@ var MachineKeyStore = class _MachineKeyStore {
106998
107104
  });
106999
107105
  }
107000
107106
  get metaPath() {
107001
- return join36(dirname26(this.options.configPath), "machine-key.json");
107107
+ return join37(dirname27(this.options.configPath), "machine-key.json");
107002
107108
  }
107003
107109
  /** Named by the key, so two CLIs making a key at once never overwrite each other's. */
107004
107110
  pemPathOf(jwk) {
107005
- return join36(dirname26(this.options.configPath), `machine-key-${shortOf(jwk)}.pem`);
107111
+ return join37(dirname27(this.options.configPath), `machine-key-${shortOf(jwk)}.pem`);
107006
107112
  }
107007
107113
  /** The Keychain item's account: one per config file and key. */
107008
107114
  accountOf(jwk) {
107009
- const config2 = createHash10("sha256").update(this.options.configPath).digest("hex");
107115
+ const config2 = createHash11("sha256").update(this.options.configPath).digest("hex");
107010
107116
  return `${config2.slice(0, 32)}-${shortOf(jwk)}`;
107011
107117
  }
107012
107118
  /** The key if this machine made one; null otherwise. Read once per process. */
@@ -107129,7 +107235,7 @@ async function writeOnce({ path, text: text3 }) {
107129
107235
  }
107130
107236
  }
107131
107237
  async function writePrivate({ path, text: text3 }) {
107132
- await mkdir13(dirname26(path), { recursive: true, mode: 448 });
107238
+ await mkdir13(dirname27(path), { recursive: true, mode: 448 });
107133
107239
  await writeFile11(path, text3, { mode: 384 });
107134
107240
  await chmod(path, 384);
107135
107241
  }
@@ -107188,7 +107294,7 @@ function machineProofFetch({
107188
107294
  import { execFile as execFile3, spawn as spawn4, spawnSync } from "node:child_process";
107189
107295
  import { closeSync, mkdirSync, openSync, renameSync, statSync } from "node:fs";
107190
107296
  import { readFile as readFile38, readlink } from "node:fs/promises";
107191
- import { dirname as dirname27 } from "node:path";
107297
+ import { dirname as dirname28 } from "node:path";
107192
107298
  import { promisify as promisify2 } from "node:util";
107193
107299
  var run3 = promisify2(execFile3);
107194
107300
  function alive(pid) {
@@ -107208,16 +107314,16 @@ async function argsOf2(pid) {
107208
107314
  return line ? line.split(/\s+/) : void 0;
107209
107315
  }
107210
107316
  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;
107317
+ const stat13 = await readFile38(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
107318
+ const fromStat = stat13 ? Number(stat13.slice(stat13.lastIndexOf(")") + 2).split(" ")[1]) : NaN;
107213
107319
  if (fromStat > 0) return fromStat;
107214
107320
  const listed = await run3("ps", ["-o", "ppid=", "-p", String(pid)]).catch(() => void 0);
107215
107321
  const parent = Number(listed?.stdout.trim());
107216
107322
  return parent > 0 ? parent : void 0;
107217
107323
  }
107218
107324
  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;
107325
+ const stat13 = await readFile38(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
107326
+ const ticks = stat13 ? stat13.slice(stat13.lastIndexOf(")") + 2).split(" ")[19] : void 0;
107221
107327
  if (ticks) return ticks;
107222
107328
  const listed = await run3("ps", ["-o", "lstart=", "-p", String(pid)]).catch(() => void 0);
107223
107329
  return listed?.stdout.trim() || void 0;
@@ -107256,7 +107362,7 @@ function spawnDetached({
107256
107362
  logPath,
107257
107363
  orphan = false
107258
107364
  }) {
107259
- mkdirSync(dirname27(logPath), { recursive: true, mode: 448 });
107365
+ mkdirSync(dirname28(logPath), { recursive: true, mode: 448 });
107260
107366
  keepLogSmall({ logPath });
107261
107367
  const log = openSync(logPath, "a", 384);
107262
107368
  if (orphan) {
@@ -107351,7 +107457,7 @@ async function readStdin() {
107351
107457
  function terminalAsk() {
107352
107458
  if (!stdin.isTTY || !stdout.isTTY) return void 0;
107353
107459
  return async (question) => {
107354
- const terminal = createInterface5({ input: stdin, output: stderr });
107460
+ const terminal = createInterface4({ input: stdin, output: stderr });
107355
107461
  try {
107356
107462
  return await terminal.question(question);
107357
107463
  } finally {
@@ -107360,15 +107466,15 @@ function terminalAsk() {
107360
107466
  };
107361
107467
  }
107362
107468
  function sleep(ms2, signal) {
107363
- return new Promise((resolve28) => {
107364
- if (signal?.aborted) return resolve28();
107469
+ return new Promise((resolve27) => {
107470
+ if (signal?.aborted) return resolve27();
107365
107471
  const stop3 = () => {
107366
107472
  clearTimeout(timer);
107367
- resolve28();
107473
+ resolve27();
107368
107474
  };
107369
107475
  const timer = setTimeout(() => {
107370
107476
  signal?.removeEventListener("abort", stop3);
107371
- resolve28();
107477
+ resolve27();
107372
107478
  }, ms2);
107373
107479
  signal?.addEventListener("abort", stop3, { once: true });
107374
107480
  });