@lazehq/cli 0.1.86 → 0.1.87

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 +676 -614
  2. package/package.json +1 -1
package/dist/laze.mjs CHANGED
@@ -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: randomBytes5, createHash: createHash9 } = __require("crypto");
3247
+ var { randomBytes: randomBytes6, createHash: createHash9 } = __require("crypto");
3248
3248
  var { Duplex, Readable: Readable2 } = __require("stream");
3249
3249
  var { URL: URL3 } = __require("url");
3250
3250
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -3782,7 +3782,7 @@ var require_websocket = __commonJS({
3782
3782
  }
3783
3783
  }
3784
3784
  const defaultPort = isSecure ? 443 : 80;
3785
- const key = randomBytes5(16).toString("base64");
3785
+ const key = randomBytes6(16).toString("base64");
3786
3786
  const request2 = isSecure ? https.request : http.request;
3787
3787
  const protocolSet = /* @__PURE__ */ new Set();
3788
3788
  let perMessageDeflate;
@@ -4193,7 +4193,7 @@ var require_stream = __commonJS({
4193
4193
  };
4194
4194
  duplex._final = function(callback) {
4195
4195
  if (ws.readyState === ws.CONNECTING) {
4196
- ws.once("open", function open5() {
4196
+ ws.once("open", function open6() {
4197
4197
  duplex._final(callback);
4198
4198
  });
4199
4199
  return;
@@ -4214,7 +4214,7 @@ var require_stream = __commonJS({
4214
4214
  };
4215
4215
  duplex._write = function(chunk, encoding, callback) {
4216
4216
  if (ws.readyState === ws.CONNECTING) {
4217
- ws.once("open", function open5() {
4217
+ ws.once("open", function open6() {
4218
4218
  duplex._write(chunk, encoding, callback);
4219
4219
  });
4220
4220
  return;
@@ -19486,8 +19486,8 @@ var require_snapshot_utils = __commonJS({
19486
19486
  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
- var { writeFile: writeFile29, readFile: readFile49, mkdir: mkdir29 } = __require("node:fs/promises");
19490
- var { dirname: dirname30, resolve: resolve26 } = __require("node:path");
19489
+ var { writeFile: writeFile12, readFile: readFile38, mkdir: mkdir13 } = __require("node:fs/promises");
19490
+ var { dirname: dirname26, resolve: resolve26 } = __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 readFile49(resolve26(path), "utf8");
19706
+ const data = await readFile38(resolve26(path), "utf8");
19707
19707
  const parsed = JSON.parse(data);
19708
19708
  if (Array.isArray(parsed)) {
19709
19709
  this.#snapshots.clear();
@@ -19733,12 +19733,12 @@ var require_snapshot_recorder = __commonJS({
19733
19733
  throw new InvalidArgumentError("Snapshot path is required");
19734
19734
  }
19735
19735
  const resolvedPath = resolve26(path);
19736
- await mkdir29(dirname30(resolvedPath), { recursive: true });
19736
+ await mkdir13(dirname26(resolvedPath), { recursive: true });
19737
19737
  const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
19738
19738
  hash: hash2,
19739
19739
  snapshot
19740
19740
  }));
19741
- await writeFile29(resolvedPath, JSON.stringify(data, null, 2), { flush: true });
19741
+ await writeFile12(resolvedPath, JSON.stringify(data, null, 2), { flush: true });
19742
19742
  }
19743
19743
  /**
19744
19744
  * Clears all recorded snapshots
@@ -36780,8 +36780,150 @@ function cliEnvironment({
36780
36780
  }
36781
36781
 
36782
36782
  // src/services/config-store.service.ts
36783
- import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
36784
- import { basename, dirname, resolve } from "node:path";
36783
+ import { readFile as readFile2 } from "node:fs/promises";
36784
+ import { basename as basename2, dirname as dirname2, resolve } from "node:path";
36785
+
36786
+ // src/rules/state-file.rules.ts
36787
+ function stepOf({ scan, char }) {
36788
+ if (scan.skip) {
36789
+ scan.skip = false;
36790
+ return false;
36791
+ }
36792
+ if (scan.inString) {
36793
+ if (char === "\\") scan.skip = true;
36794
+ if (char === '"') scan.inString = false;
36795
+ return false;
36796
+ }
36797
+ if (char === '"') scan.inString = true;
36798
+ if (char === "{" || char === "[") scan.depth += 1;
36799
+ if (char !== "}" && char !== "]") return false;
36800
+ scan.depth -= 1;
36801
+ return scan.depth === 0;
36802
+ }
36803
+ function firstValueEndOf({ text: text3 }) {
36804
+ const start2 = text3.search(/\S/);
36805
+ if (start2 < 0 || text3[start2] !== "{" && text3[start2] !== "[") return -1;
36806
+ const scan = { depth: 0, inString: false, skip: false };
36807
+ for (let index = start2; index < text3.length; index += 1) {
36808
+ if (stepOf({ scan, char: text3[index] })) return index + 1;
36809
+ }
36810
+ return -1;
36811
+ }
36812
+ function stateTextOf({ text: text3 }) {
36813
+ try {
36814
+ return { kind: "valid", value: JSON.parse(text3) };
36815
+ } catch {
36816
+ const end = firstValueEndOf({ text: text3 });
36817
+ if (end < 0) return { kind: "damaged" };
36818
+ try {
36819
+ return { kind: "trailing", value: JSON.parse(text3.slice(0, end)) };
36820
+ } catch {
36821
+ return { kind: "damaged" };
36822
+ }
36823
+ }
36824
+ }
36825
+
36826
+ // src/services/state-file.service.ts
36827
+ import { randomBytes } from "node:crypto";
36828
+ import { mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
36829
+ import { basename, dirname, join as join2 } from "node:path";
36830
+ var damaged = /* @__PURE__ */ new Map();
36831
+ function damagedStateFiles() {
36832
+ return [...damaged.values()];
36833
+ }
36834
+ async function writeStateText({
36835
+ path,
36836
+ text: text3,
36837
+ mode = 384
36838
+ }) {
36839
+ const folder = dirname(path);
36840
+ await mkdir(folder, { recursive: true, mode: 448 });
36841
+ const temporary = join2(
36842
+ folder,
36843
+ `.${basename(path)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`
36844
+ );
36845
+ const handle = await open(temporary, "wx", mode);
36846
+ try {
36847
+ await handle.writeFile(text3);
36848
+ await handle.chmod(mode);
36849
+ await handle.sync();
36850
+ } finally {
36851
+ await handle.close();
36852
+ }
36853
+ try {
36854
+ await rename(temporary, path);
36855
+ } catch (error63) {
36856
+ await rm(temporary, { force: true });
36857
+ throw error63;
36858
+ }
36859
+ damaged.delete(path);
36860
+ }
36861
+ async function writeStateJson({
36862
+ path,
36863
+ value,
36864
+ mode,
36865
+ pretty = false
36866
+ }) {
36867
+ const text3 = pretty ? `${JSON.stringify(value, null, 2)}
36868
+ ` : JSON.stringify(value);
36869
+ await writeStateText({ path, text: text3, ...mode === void 0 ? {} : { mode } });
36870
+ }
36871
+ async function readStateJson({ path }) {
36872
+ const text3 = await readFile(path, "utf8").catch(() => void 0);
36873
+ if (text3 === void 0) return void 0;
36874
+ const read4 = stateTextOf({ text: text3 });
36875
+ if (read4.kind === "valid") return read4.value;
36876
+ damaged.set(path, { path, repairable: read4.kind === "trailing" });
36877
+ return read4.kind === "trailing" ? read4.value : void 0;
36878
+ }
36879
+ async function repairDamagedStateFiles() {
36880
+ const lines2 = [];
36881
+ for (const file4 of damagedStateFiles()) {
36882
+ const value = file4.repairable ? await readStateJson({ path: file4.path }) : void 0;
36883
+ if (value !== void 0) {
36884
+ await writeStateJson({ path: file4.path, value });
36885
+ lines2.push(`Repaired ${file4.path}: it had extra text after its JSON.`);
36886
+ } else {
36887
+ damaged.delete(file4.path);
36888
+ lines2.push(`Skipped ${file4.path}: it is not valid JSON; the next write replaces it.`);
36889
+ }
36890
+ }
36891
+ return lines2;
36892
+ }
36893
+ var LOCK_STALE_MS = 5e3;
36894
+ var nowMs = () => nowInstant().epochMilliseconds;
36895
+ var LOCK_WAIT_MS = 3e3;
36896
+ async function withStateLock({
36897
+ path,
36898
+ work
36899
+ }) {
36900
+ const lock = `${path}.lock`;
36901
+ await mkdir(dirname(lock), { recursive: true, mode: 448 });
36902
+ const deadline = nowMs() + LOCK_WAIT_MS;
36903
+ for (; ; ) {
36904
+ const handle = await open(lock, "wx", 384).catch((error63) => {
36905
+ if (error63.code === "EEXIST") return void 0;
36906
+ throw error63;
36907
+ });
36908
+ if (handle) {
36909
+ await handle.close();
36910
+ break;
36911
+ }
36912
+ const since = await stat(lock).then(
36913
+ (info) => nowMs() - info.mtimeMs,
36914
+ () => 0
36915
+ );
36916
+ if (since > LOCK_STALE_MS || nowMs() > deadline) await rm(lock, { force: true });
36917
+ else await new Promise((resolve26) => setTimeout(resolve26, 15 + Math.random() * 20));
36918
+ }
36919
+ try {
36920
+ return await work();
36921
+ } finally {
36922
+ await rm(lock, { force: true });
36923
+ }
36924
+ }
36925
+
36926
+ // src/services/config-store.service.ts
36785
36927
  var EMPTY = { profiles: {}, bindings: {} };
36786
36928
  var ConfigStore = class _ConfigStore {
36787
36929
  constructor(path) {
@@ -36792,21 +36934,19 @@ var ConfigStore = class _ConfigStore {
36792
36934
  return new _ConfigStore(path);
36793
36935
  }
36794
36936
  async read() {
36795
- try {
36796
- const parsed = JSON.parse(await readFile(this.path, "utf8"));
36797
- return { ...EMPTY, ...parsed };
36798
- } catch (error63) {
36799
- if (error63.code === "ENOENT") return EMPTY;
36937
+ const text3 = await readFile2(this.path, "utf8").catch((error63) => {
36938
+ if (error63.code === "ENOENT") return void 0;
36800
36939
  throw error63;
36940
+ });
36941
+ if (text3 === void 0) return EMPTY;
36942
+ const read4 = stateTextOf({ text: text3 });
36943
+ if (read4.kind === "damaged") {
36944
+ throw new Error(`${this.path} is not valid JSON; move it aside and sign in again.`);
36801
36945
  }
36946
+ return { ...EMPTY, ...read4.value };
36802
36947
  }
36803
36948
  async write(config2) {
36804
- await mkdir(dirname(this.path), { recursive: true, mode: 448 });
36805
- const temporary = `${this.path}.${process.pid}.tmp`;
36806
- await writeFile(temporary, `${JSON.stringify(config2, null, 2)}
36807
- `, { mode: 384 });
36808
- await chmod(temporary, 384);
36809
- await rename(temporary, this.path);
36949
+ await writeStateJson({ path: this.path, value: config2, pretty: true });
36810
36950
  }
36811
36951
  async saveProfile({
36812
36952
  name: name3,
@@ -36896,9 +37036,9 @@ function chooseProfile({
36896
37036
  return name3 && profile ? { name: name3, profile } : { name: void 0, profile: void 0 };
36897
37037
  }
36898
37038
  function isWorktreeRoot({ directory }) {
36899
- const parent = dirname(directory);
36900
- if (basename(parent) === ".worktrees") return true;
36901
- return basename(parent) === "worktrees" && basename(dirname(parent)) === ".claude";
37039
+ const parent = dirname2(directory);
37040
+ if (basename2(parent) === ".worktrees") return true;
37041
+ return basename2(parent) === "worktrees" && basename2(dirname2(parent)) === ".claude";
36902
37042
  }
36903
37043
  function boundProfileOf({
36904
37044
  bindings,
@@ -36908,7 +37048,7 @@ function boundProfileOf({
36908
37048
  for (let depth = 0; depth < 64; depth += 1) {
36909
37049
  const bound = bindings[directory];
36910
37050
  if (bound) return bound;
36911
- const parent = dirname(directory);
37051
+ const parent = dirname2(directory);
36912
37052
  if (parent === directory || isWorktreeRoot({ directory })) return void 0;
36913
37053
  directory = parent;
36914
37054
  }
@@ -36990,7 +37130,7 @@ function flagText({
36990
37130
  }
36991
37131
 
36992
37132
  // src/rules/cli-version.rules.ts
36993
- var STAMPED = "0.1.86";
37133
+ var STAMPED = "0.1.87";
36994
37134
  function cliVersionOf({ stamped = STAMPED } = {}) {
36995
37135
  return stamped.startsWith("__") ? "dev" : stamped;
36996
37136
  }
@@ -42189,7 +42329,7 @@ function bucketFor(state, inst) {
42189
42329
  return bucket;
42190
42330
  }
42191
42331
  var handoff;
42192
- var open = [];
42332
+ var open2 = [];
42193
42333
  var memo = {
42194
42334
  alloc(_inst, payload, empty) {
42195
42335
  const bucket = handoff;
@@ -42198,7 +42338,7 @@ var memo = {
42198
42338
  handoff = void 0;
42199
42339
  const entry = { value: empty, issues: null };
42200
42340
  bucket.set(payload.value, entry);
42201
- open.push(entry);
42341
+ open2.push(entry);
42202
42342
  return empty;
42203
42343
  },
42204
42344
  guard(inst) {
@@ -42269,10 +42409,10 @@ var memo = {
42269
42409
  return payload;
42270
42410
  }
42271
42411
  handoff = bucket;
42272
- const depth = open.length;
42412
+ const depth = open2.length;
42273
42413
  const result2 = base(payload, ctx);
42274
42414
  handoff = void 0;
42275
- const entry = open.length > depth ? open.pop() : void 0;
42415
+ const entry = open2.length > depth ? open2.pop() : void 0;
42276
42416
  if (result2 instanceof Promise) {
42277
42417
  return result2.then((r) => {
42278
42418
  if (entry)
@@ -60239,6 +60379,8 @@ var vaultUseInputSchemaDefinition = external_exports.object({
60239
60379
  requiredScopes: external_exports.array(external_exports.string().min(1)).default([]),
60240
60380
  /** A floor on the connection's sensitivity, for a tool its owner marked more guarded. */
60241
60381
  atLeast: vaultSensitivitySchema.optional(),
60382
+ /** The tool `atLeast` is for: when that floor alone asks, Allow for a set time covers it. */
60383
+ leaseScope: external_exports.string().min(1).max(200).optional(),
60242
60384
  /** The caller knows the use only reads, such as an MCP tool marked read-only. */
60243
60385
  readOnly: external_exports.boolean().default(false),
60244
60386
  /** A use that would ask comes back denied with no card: a lookup made only for another card. */
@@ -61170,11 +61312,11 @@ var FENCE = /^\s*(?:>\s?)*(`{3,}|~{3,})/;
61170
61312
  var BLANK = /^\s*(?:>\s*)*$/;
61171
61313
  function segmentsOf({ lines: lines2 }) {
61172
61314
  const out = [];
61173
- let open5 = null;
61315
+ let open6 = null;
61174
61316
  let fence = null;
61175
61317
  const close = (end) => {
61176
- if (open5 && end >= open5.start) out.push({ start: open5.start, end, fenced: open5.fenced });
61177
- open5 = null;
61318
+ if (open6 && end >= open6.start) out.push({ start: open6.start, end, fenced: open6.fenced });
61319
+ open6 = null;
61178
61320
  };
61179
61321
  lines2.forEach((line, index) => {
61180
61322
  const marker = FENCE.exec(line)?.[1];
@@ -61182,7 +61324,7 @@ function segmentsOf({ lines: lines2 }) {
61182
61324
  if (marker && marker[0] === fence[0] && marker.length >= fence.length) {
61183
61325
  close(index - 1);
61184
61326
  fence = null;
61185
- } else if (!open5) open5 = { start: index, fenced: true };
61327
+ } else if (!open6) open6 = { start: index, fenced: true };
61186
61328
  return;
61187
61329
  }
61188
61330
  if (marker) {
@@ -61191,7 +61333,7 @@ function segmentsOf({ lines: lines2 }) {
61191
61333
  return;
61192
61334
  }
61193
61335
  if (BLANK.test(line)) close(index - 1);
61194
- else if (!open5) open5 = { start: index, fenced: false };
61336
+ else if (!open6) open6 = { start: index, fenced: false };
61195
61337
  });
61196
61338
  close(lines2.length - 1);
61197
61339
  return out;
@@ -62208,6 +62350,7 @@ var mirrorSourceSchema = external_exports.enum([
62208
62350
  "laze"
62209
62351
  ]);
62210
62352
  var mirrorDeliverySchema = external_exports.enum(["waiting", "failed"]);
62353
+ var mirrorDeliveryStateSchema = external_exports.enum(["waiting", "failed", "edit_kept"]);
62211
62354
  var messageOriginSchemaDefinition = external_exports.object({
62212
62355
  source: mirrorSourceSchema,
62213
62356
  /** The message's key at the source, unique in the workspace (e.g. `slack:T1:C1:1792.0001`). */
@@ -62608,6 +62751,8 @@ var messageSchemaDefinition = external_exports.object({
62608
62751
  images: external_exports.record(external_exports.string().max(2e3), external_exports.string().max(5e3)).optional(),
62609
62752
  /** A message written in Laze that its mirror is still waiting to send, or could not send. */
62610
62753
  mirrorDelivery: mirrorDeliverySchema.nullable().optional(),
62754
+ /** Set when the source would not take the last edit of this sent message: it is only in Laze. */
62755
+ mirrorEditKept: external_exports.boolean().optional(),
62611
62756
  /** A thread reply also sent to its conversation: it shows in the thread and the channel. */
62612
62757
  alsoInChannel: external_exports.boolean().optional(),
62613
62758
  /** For a reply also sent to the channel: its root's text, for the "replied to a thread" line. */
@@ -63089,7 +63234,7 @@ var pinMirroredInputSchemaDefinition = external_exports.object({
63089
63234
  var setMirrorDeliveryInputSchemaDefinition = external_exports.object({
63090
63235
  workspaceId: workspaceIdSchema,
63091
63236
  messageId: idSchema4,
63092
- state: mirrorDeliverySchema.nullable()
63237
+ state: mirrorDeliveryStateSchema.nullable()
63093
63238
  });
63094
63239
  var reactMirroredInputSchemaDefinition = external_exports.object({
63095
63240
  workspaceId: workspaceIdSchema,
@@ -70008,13 +70153,11 @@ function errorOf({ status: status11, body }) {
70008
70153
 
70009
70154
  // src/services/machine-report.service.ts
70010
70155
  import { createHash } from "node:crypto";
70011
- import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
70156
+ import { readFile as readFile3 } from "node:fs/promises";
70012
70157
  import { hostname as hostname3 } from "node:os";
70013
- import { dirname as dirname3 } from "node:path";
70014
70158
 
70015
70159
  // src/services/inbox-spool.service.ts
70016
- import { mkdir as mkdir2, readFile as readFile2, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
70017
- import { dirname as dirname2, join as join2 } from "node:path";
70160
+ import { dirname as dirname3, join as join3 } from "node:path";
70018
70161
  var PUSH_GRACE_MS = 3 * 6e4;
70019
70162
  var IN_FLIGHT_MS = 35e3;
70020
70163
  function fileNameOf({ profile }) {
@@ -70026,20 +70169,14 @@ function statePathOf({
70026
70169
  profile,
70027
70170
  extension: extension2 = "json"
70028
70171
  }) {
70029
- const directory = join2(dirname2(context.environment.configPath), kind2);
70030
- return join2(directory, `${fileNameOf({ profile })}.${extension2}`);
70172
+ const directory = join3(dirname3(context.environment.configPath), kind2);
70173
+ return join3(directory, `${fileNameOf({ profile })}.${extension2}`);
70031
70174
  }
70032
70175
  async function readSpool({ path }) {
70033
- return readFile2(path, "utf8").then(
70034
- (text3) => JSON.parse(text3),
70035
- () => []
70036
- );
70176
+ return await readStateJson({ path }) ?? [];
70037
70177
  }
70038
70178
  async function writeSpool({ path, entries }) {
70039
- await mkdir2(dirname2(path), { recursive: true, mode: 448 });
70040
- const temporary = `${path}.${process.pid}.tmp`;
70041
- await writeFile2(temporary, JSON.stringify(entries), { mode: 384 });
70042
- await rename2(temporary, path);
70179
+ await writeStateJson({ path, value: entries });
70043
70180
  }
70044
70181
  async function keepTaken({
70045
70182
  context,
@@ -70109,8 +70246,7 @@ async function reportMachine({
70109
70246
  if (await readFile3(path, "utf8").catch(() => "") === stamp) return;
70110
70247
  try {
70111
70248
  await client.post("/api/agents/me/machine", { host: host2 });
70112
- await mkdir3(dirname3(path), { recursive: true, mode: 448 });
70113
- await writeFile3(path, stamp, { mode: 384 });
70249
+ await writeStateText({ path, text: stamp });
70114
70250
  } catch {
70115
70251
  return;
70116
70252
  }
@@ -70403,8 +70539,8 @@ async function copyAgent({
70403
70539
  }
70404
70540
 
70405
70541
  // src/services/agent-commands.service.ts
70406
- import { mkdir as mkdir17, readFile as readFile18, writeFile as writeFile16 } from "node:fs/promises";
70407
- import { join as join18, resolve as resolve5 } from "node:path";
70542
+ import { mkdir as mkdir5, readFile as readFile11, writeFile as writeFile3 } from "node:fs/promises";
70543
+ import { join as join19, resolve as resolve5 } from "node:path";
70408
70544
 
70409
70545
  // src/rules/agent-profile.rules.ts
70410
70546
  var HARNESS_NAMES = {
@@ -71694,13 +71830,13 @@ function formatSearch({
71694
71830
  }
71695
71831
 
71696
71832
  // src/services/claude-turn.service.ts
71697
- import { mkdir as mkdir5, readFile as readFile7, rm, writeFile as writeFile5 } from "node:fs/promises";
71698
- import { dirname as dirname5, join as join5 } from "node:path";
71833
+ import { rm as rm2 } from "node:fs/promises";
71834
+ import { dirname as dirname5, join as join6 } from "node:path";
71699
71835
 
71700
71836
  // src/services/harness-session.service.ts
71701
- import { mkdir as mkdir4, open as open2, readdir, readFile as readFile5, stat, writeFile as writeFile4 } from "node:fs/promises";
71837
+ import { open as open3, readdir, readFile as readFile5, stat as stat2 } from "node:fs/promises";
71702
71838
  import { homedir as homedir2, hostname as hostname4 } from "node:os";
71703
- import { dirname as dirname4, join as join3 } from "node:path";
71839
+ import { dirname as dirname4, join as join4 } from "node:path";
71704
71840
 
71705
71841
  // src/rules/claude-subagent.rules.ts
71706
71842
  function lastCallAtOf({ text: text3, command }) {
@@ -71794,9 +71930,9 @@ function launchEnvOf({
71794
71930
  }
71795
71931
 
71796
71932
  // src/services/claude-project.service.ts
71797
- import { basename as basename2, isAbsolute, relative as relative2, resolve as resolve2 } from "node:path";
71933
+ import { basename as basename3, isAbsolute, relative as relative2, resolve as resolve2 } from "node:path";
71798
71934
  function harnessIn({ words }) {
71799
- const names = words.slice(0, 2).map((word3) => basename2(word3).replace(/\.(js|mjs|cjs)$/, ""));
71935
+ const names = words.slice(0, 2).map((word3) => basename3(word3).replace(/\.(js|mjs|cjs)$/, ""));
71800
71936
  if (names.includes("codex")) return "codex";
71801
71937
  if (words.some((word3) => word3.includes("@openai/codex"))) return "codex";
71802
71938
  const claude = words.some((word3) => word3.includes("@anthropic-ai/claude-code"));
@@ -71861,9 +71997,8 @@ async function rememberSession({
71861
71997
  }) {
71862
71998
  if (!session || !claudePid) return;
71863
71999
  const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
71864
- await mkdir4(dirname4(path), { recursive: true, mode: 448 });
71865
72000
  const launch = launchEnvOf({ inherited: context.environment.inherited });
71866
- await writeFile4(path, JSON.stringify({ ...session, launch }), { mode: 384 });
72001
+ await writeStateJson({ path, value: { ...session, launch } });
71867
72002
  }
71868
72003
  async function currentSessionOf({
71869
72004
  context,
@@ -71882,10 +72017,7 @@ async function currentSessionOf({
71882
72017
  const nearest = await nearestHarnessOf({ context });
71883
72018
  if (!nearest) return void 0;
71884
72019
  const path = statePathOf({ context, kind: "sessions", profile: String(nearest.pid) });
71885
- return readFile5(path, "utf8").then(
71886
- (text3) => JSON.parse(text3),
71887
- () => void 0
71888
- );
72020
+ return readStateJson({ path });
71889
72021
  }
71890
72022
  async function sessionProfileArgs({
71891
72023
  context,
@@ -71939,10 +72071,7 @@ async function liveElsewhere({
71939
72071
  for (const file4 of await readdir(folder).catch(() => [])) {
71940
72072
  const pid = Number(file4.replace(/\.json$/, ""));
71941
72073
  if (!pid || pid === claudePid || !context.processes.alive(pid)) continue;
71942
- const noted = await readFile5(join3(folder, file4), "utf8").then(
71943
- (text3) => JSON.parse(text3),
71944
- () => void 0
71945
- );
72074
+ const noted = await readStateJson({ path: join4(folder, file4) });
71946
72075
  if (noted && sessionKeyOf({ session: noted }) === key) return true;
71947
72076
  }
71948
72077
  return false;
@@ -71952,15 +72081,15 @@ async function claudeTranscriptOf({
71952
72081
  sessionId
71953
72082
  }) {
71954
72083
  const inherited = context.environment.inherited;
71955
- const root = join3(
71956
- inherited.CLAUDE_CONFIG_DIR || join3(inherited.HOME || homedir2(), ".claude"),
72084
+ const root = join4(
72085
+ inherited.CLAUDE_CONFIG_DIR || join4(inherited.HOME || homedir2(), ".claude"),
71957
72086
  "projects"
71958
72087
  );
71959
72088
  const folders = await readdir(root).catch(() => []);
71960
72089
  const found = await Promise.all(
71961
72090
  folders.map(async (folder) => {
71962
- const path = join3(root, folder, `${sessionId}.jsonl`);
71963
- return stat(path).then(
72091
+ const path = join4(root, folder, `${sessionId}.jsonl`);
72092
+ return stat2(path).then(
71964
72093
  (info) => info.isFile() ? [{ path, at: info.mtimeMs }] : [],
71965
72094
  () => []
71966
72095
  );
@@ -71970,7 +72099,7 @@ async function claudeTranscriptOf({
71970
72099
  }
71971
72100
  var TAIL_BYTES = 512 * 1024;
71972
72101
  async function tailOf({ path }) {
71973
- const handle = await open2(path, "r").catch(() => void 0);
72102
+ const handle = await open3(path, "r").catch(() => void 0);
71974
72103
  if (!handle) return "";
71975
72104
  try {
71976
72105
  const { size } = await handle.stat();
@@ -71987,11 +72116,11 @@ async function runsInSubagent({ context, command }) {
71987
72116
  if (!sessionId) return false;
71988
72117
  const { path } = await claudeTranscriptOf({ context, sessionId });
71989
72118
  if (!path) return false;
71990
- const folder = join3(dirname4(path), sessionId, "subagents");
72119
+ const folder = join4(dirname4(path), sessionId, "subagents");
71991
72120
  const files2 = await readdir(folder).catch(() => []);
71992
72121
  const subagents = await Promise.all(
71993
72122
  files2.filter((file4) => file4.endsWith(".jsonl")).map(
71994
- async (file4) => lastCallAtOf({ text: await tailOf({ path: join3(folder, file4) }), command })
72123
+ async (file4) => lastCallAtOf({ text: await tailOf({ path: join4(folder, file4) }), command })
71995
72124
  )
71996
72125
  );
71997
72126
  const session = lastCallAtOf({ text: await tailOf({ path }), command });
@@ -72056,8 +72185,7 @@ async function notBoundNotice({
72056
72185
  () => false
72057
72186
  );
72058
72187
  if (told) return { notice: void 0 };
72059
- await mkdir4(dirname4(path), { recursive: true, mode: 448 });
72060
- await writeFile4(path, String(context.nowMs()), { mode: 384 });
72188
+ await writeStateText({ path, text: String(context.nowMs()) });
72061
72189
  const agent3 = (await context.store.read()).profiles[profile]?.name;
72062
72190
  return {
72063
72191
  notice: notBoundText({ meta: meta3, agent: agent3, configPath: context.environment.configPath })
@@ -72066,7 +72194,7 @@ async function notBoundNotice({
72066
72194
 
72067
72195
  // src/services/plugin-hook.service.ts
72068
72196
  import { readFile as readFile6 } from "node:fs/promises";
72069
- import { join as join4 } from "node:path";
72197
+ import { join as join5 } from "node:path";
72070
72198
  async function agentProfileHere({
72071
72199
  context,
72072
72200
  args,
@@ -72087,11 +72215,8 @@ async function agentProfileHere({
72087
72215
  }
72088
72216
  async function projectHooksHere({ context }) {
72089
72217
  const directory = context.environment.inherited.CLAUDE_PROJECT_DIR || context.cwd;
72090
- const path = join4(directory, ".claude", "settings.local.json");
72091
- return readFile6(path, "utf8").then(
72092
- (text3) => hasLazeHooks({ settings: JSON.parse(text3) }),
72093
- () => false
72094
- );
72218
+ const path = join5(directory, ".claude", "settings.local.json");
72219
+ return readFile6(path, "utf8").then((text3) => hasLazeHooks({ settings: JSON.parse(text3) })).catch(() => false);
72095
72220
  }
72096
72221
  async function pluginHookArgs({
72097
72222
  context,
@@ -72109,13 +72234,10 @@ async function pluginHookArgs({
72109
72234
  var PRE_TOOL_TIMEOUT_MS = 3e3;
72110
72235
  function statePath({ context, agent: agent3 }) {
72111
72236
  const safe = agent3.replace(/[^a-zA-Z0-9_-]/g, "_");
72112
- return join5(dirname5(context.environment.configPath), "turns", `${safe}.json`);
72237
+ return join6(dirname5(context.environment.configPath), "turns", `${safe}.json`);
72113
72238
  }
72114
72239
  async function readState({ context, agent: agent3 }) {
72115
- return readFile7(statePath({ context, agent: agent3 }), "utf8").then(
72116
- (text3) => JSON.parse(text3),
72117
- () => void 0
72118
- );
72240
+ return readStateJson({ path: statePath({ context, agent: agent3 }) });
72119
72241
  }
72120
72242
  function beat({
72121
72243
  client,
@@ -72167,8 +72289,7 @@ async function turnStarted({
72167
72289
  await beat({ client, state: opened, working: true }).catch(() => void 0);
72168
72290
  }
72169
72291
  const path = statePath({ context, agent: agent3 });
72170
- await mkdir5(dirname5(path), { recursive: true, mode: 448 });
72171
- await writeFile5(path, JSON.stringify(state));
72292
+ await writeStateJson({ path, value: state });
72172
72293
  await beat({ client, state, working: true }).catch(() => void 0);
72173
72294
  }
72174
72295
  async function turnEnded({
@@ -72178,7 +72299,7 @@ async function turnEnded({
72178
72299
  }) {
72179
72300
  const state = await readState({ context, agent: agent3 });
72180
72301
  if (!state) return;
72181
- await rm(statePath({ context, agent: agent3 }), { force: true });
72302
+ await rm2(statePath({ context, agent: agent3 }), { force: true });
72182
72303
  await beat({ client, state, working: false }).catch(() => void 0);
72183
72304
  }
72184
72305
  async function preToolHook({ context, args }) {
@@ -72226,8 +72347,8 @@ async function preToolHook({ context, args }) {
72226
72347
  }
72227
72348
 
72228
72349
  // src/services/message-files.service.ts
72229
- import { readFile as readFile8, stat as stat2 } from "node:fs/promises";
72230
- import { basename as basename3, resolve as resolve3 } from "node:path";
72350
+ import { readFile as readFile7, stat as stat3 } from "node:fs/promises";
72351
+ import { basename as basename4, resolve as resolve3 } from "node:path";
72231
72352
 
72232
72353
  // src/rules/file-types.rules.ts
72233
72354
  var TYPES = {
@@ -72325,7 +72446,7 @@ async function readyOf({ context, source }) {
72325
72446
  return asBytes({ source, file: await downloaded({ context, url: value }) });
72326
72447
  }
72327
72448
  const full = resolve3(context.cwd, value);
72328
- const found = await stat2(full).catch(() => void 0);
72449
+ const found = await stat3(full).catch(() => void 0);
72329
72450
  if (found?.isFile()) return asBytes({ source, file: await local({ full }) });
72330
72451
  const marked = fileMarkerIdsIn(value)[0] ?? (UPLOADED_ID.test(value) ? value : void 0);
72331
72452
  if (marked) return { kind: "id", id: marked };
@@ -72342,7 +72463,7 @@ function asBytes({ source, file: file4 }) {
72342
72463
  async function downloaded({ context, url: url2 }) {
72343
72464
  const response = await context.fetcher(url2);
72344
72465
  if (!response.ok) throw new CliUsageError(`${url2} answered ${response.status}`);
72345
- const fileName = basename3(new URL(url2).pathname) || "file";
72466
+ const fileName = basename4(new URL(url2).pathname) || "file";
72346
72467
  const header = (response.headers.get("content-type") ?? "").split(";")[0]?.trim();
72347
72468
  return {
72348
72469
  fileName,
@@ -72351,11 +72472,11 @@ async function downloaded({ context, url: url2 }) {
72351
72472
  };
72352
72473
  }
72353
72474
  async function local({ full }) {
72354
- const fileName = basename3(full);
72475
+ const fileName = basename4(full);
72355
72476
  return {
72356
72477
  fileName,
72357
72478
  contentType: contentTypeOf(fileName),
72358
- bytes: new Uint8Array(await readFile8(full))
72479
+ bytes: new Uint8Array(await readFile7(full))
72359
72480
  };
72360
72481
  }
72361
72482
  async function attachmentIdsOf({
@@ -72978,13 +73099,12 @@ function channelLabelIn(channel) {
72978
73099
  }
72979
73100
 
72980
73101
  // src/services/claude-wait.service.ts
72981
- import { readFile as readFile14, rm as rm4, writeFile as writeFile11, mkdir as mkdir12 } from "node:fs/promises";
72982
- import { dirname as dirname13 } from "node:path";
73102
+ import { readFile as readFile8, rm as rm5 } from "node:fs/promises";
72983
73103
 
72984
73104
  // src/services/connect-service.service.ts
72985
73105
  import { createHash as createHash2 } from "node:crypto";
72986
- import { mkdir as mkdir11, rm as rm3, writeFile as writeFile10 } from "node:fs/promises";
72987
- import { dirname as dirname12, join as join13 } from "node:path";
73106
+ import { mkdir as mkdir3, rm as rm4, writeFile } from "node:fs/promises";
73107
+ import { dirname as dirname12, join as join14 } from "node:path";
72988
73108
 
72989
73109
  // src/rules/connect-service.rules.ts
72990
73110
  function systemdWordOf(word3) {
@@ -73106,31 +73226,31 @@ function rolloutEventOf({
73106
73226
  }
73107
73227
 
73108
73228
  // src/services/connect-delivery.service.ts
73109
- import { mkdir as mkdir10, readFile as readFile13, rename as rename3, rm as rm2, stat as stat4, writeFile as writeFile9 } from "node:fs/promises";
73229
+ import { rm as rm3, stat as stat5 } from "node:fs/promises";
73110
73230
  import { homedir as homedir3, hostname as hostname5 } from "node:os";
73111
- import { dirname as dirname11, join as join12 } from "node:path";
73231
+ import { dirname as dirname11, join as join13 } from "node:path";
73112
73232
 
73113
73233
  // src/services/codex-turn-watch.service.ts
73114
- import { open as open3, readdir as readdir2 } from "node:fs/promises";
73115
- import { basename as basename4, join as join6 } from "node:path";
73234
+ import { open as open4, readdir as readdir2 } from "node:fs/promises";
73235
+ import { basename as basename5, join as join7 } from "node:path";
73116
73236
  var READ_MS = 1500;
73117
73237
  var KEEP_WORKING_MS = 3e4;
73118
73238
  async function codexRolloutPathOf({
73119
73239
  codexHome,
73120
73240
  threadId
73121
73241
  }) {
73122
- const root = join6(codexHome, "sessions");
73242
+ const root = join7(codexHome, "sessions");
73123
73243
  const files2 = await readdir2(root, { recursive: true }).catch(() => []);
73124
73244
  const file4 = files2.find(
73125
- (name3) => basename4(name3).startsWith("rollout-") && name3.endsWith(`-${threadId}.jsonl`)
73245
+ (name3) => basename5(name3).startsWith("rollout-") && name3.endsWith(`-${threadId}.jsonl`)
73126
73246
  );
73127
- return file4 ? join6(root, file4) : void 0;
73247
+ return file4 ? join7(root, file4) : void 0;
73128
73248
  }
73129
73249
  function rolloutPathOf({ delivery }) {
73130
73250
  return codexRolloutPathOf({ codexHome: delivery.codexHome, threadId: delivery.threadId });
73131
73251
  }
73132
73252
  async function readFrom({ path, offset }) {
73133
- const handle = await open3(path, "r");
73253
+ const handle = await open4(path, "r");
73134
73254
  try {
73135
73255
  const { size } = await handle.stat();
73136
73256
  if (size <= offset) return { text: "", size };
@@ -73213,8 +73333,7 @@ var CodexTurnWatch = class _CodexTurnWatch {
73213
73333
  };
73214
73334
 
73215
73335
  // src/services/mcp-relay.service.ts
73216
- import { chmod as chmod2, mkdir as mkdir6, readFile as readFile9, writeFile as writeFile6 } from "node:fs/promises";
73217
- import { dirname as dirname6, join as join7 } from "node:path";
73336
+ import { dirname as dirname6, join as join8 } from "node:path";
73218
73337
 
73219
73338
  // ../../node_modules/.pnpm/ws@8.21.3_bufferutil@4.1.0/node_modules/ws/wrapper.mjs
73220
73339
  var import_stream = __toESM(require_stream(), 1);
@@ -73550,24 +73669,17 @@ var STOPS = /* @__PURE__ */ new Map([
73550
73669
  [CONNECTOR_RELAY_CLOSE.replaced.code, "another relay for this server took over"]
73551
73670
  ]);
73552
73671
  function mcpRelaysPathOf({ context }) {
73553
- return join7(dirname6(context.environment.configPath), "connect", "mcp-relays.json");
73672
+ return join8(dirname6(context.environment.configPath), "connect", "mcp-relays.json");
73554
73673
  }
73555
73674
  async function readMcpRelays({ context }) {
73556
- try {
73557
- return JSON.parse(await readFile9(mcpRelaysPathOf({ context }), "utf8"));
73558
- } catch {
73559
- return {};
73560
- }
73675
+ return await readStateJson({ path: mcpRelaysPathOf({ context }) }) ?? {};
73561
73676
  }
73562
73677
  async function saveMcpRelays({
73563
73678
  context,
73564
73679
  relays
73565
73680
  }) {
73566
73681
  const path = mcpRelaysPathOf({ context });
73567
- await mkdir6(dirname6(path), { recursive: true, mode: 448 });
73568
- await writeFile6(path, `${JSON.stringify(relays, null, 2)}
73569
- `, { mode: 384 });
73570
- await chmod2(path, 384);
73682
+ await writeStateJson({ path, value: relays, pretty: true });
73571
73683
  }
73572
73684
  function mcpRelaySocketUrlOf(url2) {
73573
73685
  const parsed = new URL(CONNECTOR_RELAY_PATH, url2);
@@ -73717,8 +73829,7 @@ var McpRelayLoops = class _McpRelayLoops {
73717
73829
  };
73718
73830
 
73719
73831
  // src/services/openclaw-relay.service.ts
73720
- import { chmod as chmod3, mkdir as mkdir7, readFile as readFile10, writeFile as writeFile7 } from "node:fs/promises";
73721
- import { dirname as dirname7, join as join8 } from "node:path";
73832
+ import { dirname as dirname7, join as join9 } from "node:path";
73722
73833
 
73723
73834
  // ../../modules/openclaw/contract/src/openclaw.ts
73724
73835
  var workspaceIdSchema18 = external_exports.string().min(1);
@@ -73939,24 +74050,17 @@ var STOPS2 = /* @__PURE__ */ new Map([
73939
74050
  [OPENCLAW_RELAY_CLOSE.replaced.code, "another relay for this gateway took over"]
73940
74051
  ]);
73941
74052
  function relaysPathOf({ context }) {
73942
- return join8(dirname7(context.environment.configPath), "connect", "openclaw-relays.json");
74053
+ return join9(dirname7(context.environment.configPath), "connect", "openclaw-relays.json");
73943
74054
  }
73944
74055
  async function readRelays({ context }) {
73945
- try {
73946
- return JSON.parse(await readFile10(relaysPathOf({ context }), "utf8"));
73947
- } catch {
73948
- return {};
73949
- }
74056
+ return await readStateJson({ path: relaysPathOf({ context }) }) ?? {};
73950
74057
  }
73951
74058
  async function saveRelays({
73952
74059
  context,
73953
74060
  relays
73954
74061
  }) {
73955
74062
  const path = relaysPathOf({ context });
73956
- await mkdir7(dirname7(path), { recursive: true, mode: 448 });
73957
- await writeFile7(path, `${JSON.stringify(relays, null, 2)}
73958
- `, { mode: 384 });
73959
- await chmod3(path, 384);
74063
+ await writeStateJson({ path, value: relays, pretty: true });
73960
74064
  }
73961
74065
  function relaySocketUrlOf(url2) {
73962
74066
  const parsed = new URL(OPENCLAW_RELAY_PATH, url2);
@@ -74034,18 +74138,18 @@ var RelaySession = class {
74034
74138
  if (!envelope) return;
74035
74139
  const { line, payload } = envelope;
74036
74140
  if (envelope.kind === "open") return this.dial(relay2, line);
74037
- const open5 = this.#lines.get(line);
74038
- if (!open5) return;
74141
+ const open6 = this.#lines.get(line);
74142
+ if (!open6) return;
74039
74143
  if (envelope.kind === "close") {
74040
74144
  this.#lines.delete(line);
74041
- open5.socket.close(1e3);
74145
+ open6.socket.close(1e3);
74042
74146
  return;
74043
74147
  }
74044
74148
  if (envelope.kind !== "text" && envelope.kind !== "binary") return;
74045
74149
  const frame = { data: Buffer.from(payload), binary: envelope.kind === "binary" };
74046
- if (open5.socket.readyState === wrapper_default.OPEN) {
74047
- open5.socket.send(frame.data, { binary: frame.binary });
74048
- } else open5.waiting.push(frame);
74150
+ if (open6.socket.readyState === wrapper_default.OPEN) {
74151
+ open6.socket.send(frame.data, { binary: frame.binary });
74152
+ } else open6.waiting.push(frame);
74049
74153
  }
74050
74154
  /** Dials the gateway for a line; its frames go back to Laze as they came. */
74051
74155
  dial(relay2, line) {
@@ -74139,12 +74243,11 @@ var RelayLoops = class _RelayLoops {
74139
74243
  };
74140
74244
 
74141
74245
  // src/services/rush-listeners.service.ts
74142
- import { readFile as readFile12, readdir as readdir3, stat as stat3 } from "node:fs/promises";
74143
- import { dirname as dirname9, join as join10 } from "node:path";
74246
+ import { readdir as readdir3, stat as stat4 } from "node:fs/promises";
74247
+ import { dirname as dirname9, join as join11 } from "node:path";
74144
74248
 
74145
74249
  // src/services/rush-host.service.ts
74146
- import { mkdir as mkdir8, readFile as readFile11, writeFile as writeFile8 } from "node:fs/promises";
74147
- import { dirname as dirname8, join as join9 } from "node:path";
74250
+ import { dirname as dirname8, join as join10 } from "node:path";
74148
74251
  async function rushAboveOf({
74149
74252
  context,
74150
74253
  from = context.processes.pid
@@ -74158,7 +74261,7 @@ async function rushAboveOf({
74158
74261
  return void 0;
74159
74262
  }
74160
74263
  function guardPathOf({ context, claudePid }) {
74161
- return join9(dirname8(context.environment.configPath), "rush-guards", `${claudePid}.json`);
74264
+ return join10(dirname8(context.environment.configPath), "rush-guards", `${claudePid}.json`);
74162
74265
  }
74163
74266
  async function startRushGuard({
74164
74267
  context,
@@ -74171,7 +74274,7 @@ async function startRushGuard({
74171
74274
  if (holder && context.processes.alive(holder.pid)) return;
74172
74275
  const flags2 = ["--profile", profile, "--claude-pid", String(claudePid), "--rush-id", rush.id];
74173
74276
  const argv = [...context.program, "hook", "rush-wake", ...flags2, "--rush-program", rush.program];
74174
- const logPath = join9(dirname8(context.environment.configPath), "rush-guards", "guard.log");
74277
+ const logPath = join10(dirname8(context.environment.configPath), "rush-guards", "guard.log");
74175
74278
  context.processes.spawnDetached({ argv: ["sh", "-c", '"$@" &', "sh", ...argv], logPath });
74176
74279
  }
74177
74280
  async function claimRushGuard({
@@ -74179,26 +74282,24 @@ async function claimRushGuard({
74179
74282
  claudePid
74180
74283
  }) {
74181
74284
  const path = guardPathOf({ context, claudePid });
74182
- const holder = await guardHolderOf({ path });
74183
- const self2 = context.processes.pid;
74184
- if (holder && holder.pid !== self2 && context.processes.alive(holder.pid)) return false;
74185
- await mkdir8(dirname8(path), { recursive: true, mode: 448 });
74186
- await writeFile8(path, JSON.stringify({ pid: self2, claudePid }), { mode: 384 });
74187
- return true;
74285
+ return withStateLock({
74286
+ path,
74287
+ work: async () => {
74288
+ const holder = await guardHolderOf({ path });
74289
+ const self2 = context.processes.pid;
74290
+ if (holder && holder.pid !== self2 && context.processes.alive(holder.pid)) return false;
74291
+ await writeStateJson({ path, value: { pid: self2, claudePid } });
74292
+ return true;
74293
+ }
74294
+ });
74188
74295
  }
74189
74296
  function guardHolderOf({ path }) {
74190
- return readFile11(path, "utf8").then(
74191
- (text3) => JSON.parse(text3),
74192
- () => void 0
74193
- );
74297
+ return readStateJson({ path });
74194
74298
  }
74195
74299
 
74196
74300
  // src/services/rush-listeners.service.ts
74197
74301
  async function jsonOf(path) {
74198
- return readFile12(path, "utf8").then(
74199
- (text3) => JSON.parse(text3),
74200
- () => void 0
74201
- );
74302
+ return readStateJson({ path });
74202
74303
  }
74203
74304
  async function notesOf({ context }) {
74204
74305
  const folder = dirname9(statePathOf({ context, kind: "sessions", profile: "x" }));
@@ -74206,8 +74307,8 @@ async function notesOf({ context }) {
74206
74307
  const notes = await Promise.all(
74207
74308
  files2.map(async (file4) => {
74208
74309
  const pid = Number(file4.replace(/\.json$/, ""));
74209
- const note = await jsonOf(join10(folder, file4));
74210
- const at = await stat3(join10(folder, file4)).then(
74310
+ const note = await jsonOf(join11(folder, file4));
74311
+ const at = await stat4(join11(folder, file4)).then(
74211
74312
  (info) => info.mtimeMs,
74212
74313
  () => 0
74213
74314
  );
@@ -74287,8 +74388,8 @@ async function rearmRushGuards({ context }) {
74287
74388
  }
74288
74389
 
74289
74390
  // src/services/rush-watchdog.service.ts
74290
- import { appendFile, mkdir as mkdir9 } from "node:fs/promises";
74291
- import { dirname as dirname10, join as join11 } from "node:path";
74391
+ import { appendFile, mkdir as mkdir2 } from "node:fs/promises";
74392
+ import { dirname as dirname10, join as join12 } from "node:path";
74292
74393
  var UNDELIVERED_AFTER_MS = 6e4;
74293
74394
  var CHECK_TIMEOUT_MS = 5e3;
74294
74395
  function clientOf({ context, profile }) {
@@ -74307,9 +74408,9 @@ async function waitingOf({ context, profile }) {
74307
74408
  const client = await clientOf({ context, profile });
74308
74409
  return client?.get("/api/agents/me/inbox/waiting").catch(() => void 0);
74309
74410
  }
74310
- function waitedMsOf({ waiting, nowMs }) {
74411
+ function waitedMsOf({ waiting, nowMs: nowMs2 }) {
74311
74412
  if (waiting.count === 0 || !waiting.oldestPostedAt) return 0;
74312
- return Math.max(0, nowMs - Temporal3.Instant.from(waiting.oldestPostedAt).epochMilliseconds);
74413
+ return Math.max(0, nowMs2 - Temporal3.Instant.from(waiting.oldestPostedAt).epochMilliseconds);
74313
74414
  }
74314
74415
  function boundAwayOf({ waiting, key }) {
74315
74416
  const bound = waiting.session;
@@ -74317,13 +74418,13 @@ function boundAwayOf({ waiting, key }) {
74317
74418
  return `${sessionLabelOf(bound)} (${bound.harness}:${bound.sessionId})`;
74318
74419
  }
74319
74420
  async function logDelivery({ context, line }) {
74320
- const folder = join11(dirname10(context.environment.configPath), "connect");
74421
+ const folder = join12(dirname10(context.environment.configPath), "connect");
74321
74422
  const at = Temporal3.Instant.fromEpochMilliseconds(context.nowMs());
74322
74423
  const stamped = `${at.toString({ smallestUnit: "second" })} ${line}
74323
74424
  `;
74324
74425
  context.out(stamped);
74325
- await mkdir9(folder, { recursive: true, mode: 448 });
74326
- await appendFile(join11(folder, "delivery.log"), stamped, { mode: 384 });
74426
+ await mkdir2(folder, { recursive: true, mode: 448 });
74427
+ await appendFile(join12(folder, "delivery.log"), stamped, { mode: 384 });
74327
74428
  }
74328
74429
  async function claimFor({
74329
74430
  context,
@@ -74399,17 +74500,13 @@ async function watchRushDelivery({
74399
74500
 
74400
74501
  // src/services/connect-delivery.service.ts
74401
74502
  function connectFolderOf({ context }) {
74402
- return join12(dirname11(context.environment.configPath), "connect");
74503
+ return join13(dirname11(context.environment.configPath), "connect");
74403
74504
  }
74404
74505
  function runStatePathOf({ context }) {
74405
- return join12(connectFolderOf({ context }), "run.json");
74506
+ return join13(connectFolderOf({ context }), "run.json");
74406
74507
  }
74407
74508
  async function readJson({ path }) {
74408
- try {
74409
- return JSON.parse(await readFile13(path, "utf8"));
74410
- } catch {
74411
- return void 0;
74412
- }
74509
+ return readStateJson({ path });
74413
74510
  }
74414
74511
  async function runStateOf({ context }) {
74415
74512
  return readJson({ path: runStatePathOf({ context }) });
@@ -74421,7 +74518,7 @@ var CLI_CHANGED_EXIT = 75;
74421
74518
  async function cliStampOf({ context }) {
74422
74519
  const file4 = context.program.at(-1);
74423
74520
  if (!file4) return "";
74424
- return stat4(file4).then(
74521
+ return stat5(file4).then(
74425
74522
  (info) => `${info.mtimeMs}:${info.size}`,
74426
74523
  () => ""
74427
74524
  );
@@ -74572,12 +74669,8 @@ async function serveRounds({
74572
74669
  }
74573
74670
  }
74574
74671
  }
74575
- var saves = 0;
74576
74672
  async function save(run4) {
74577
- await mkdir10(dirname11(run4.path), { recursive: true, mode: 448 });
74578
- const temporary = `${run4.path}.${run4.self}.${saves += 1}.tmp`;
74579
- await writeFile9(temporary, JSON.stringify(run4.state));
74580
- await rename3(temporary, run4.path);
74673
+ await writeStateJson({ path: run4.path, value: run4.state });
74581
74674
  }
74582
74675
  async function holdsLock(run4) {
74583
74676
  return (await runStateOf({ context: run4.context }))?.pid === run4.self;
@@ -74675,7 +74768,7 @@ async function runConnectLoop({ context }) {
74675
74768
  await mcpRelays.stopAll();
74676
74769
  for (const current3 of run4.served.values()) current3.stop.abort();
74677
74770
  await Promise.all([...run4.served.values()].map((current3) => current3.done));
74678
- if (await holdsLock(run4)) await rm2(run4.path, { force: true });
74771
+ if (await holdsLock(run4)) await rm3(run4.path, { force: true });
74679
74772
  }
74680
74773
  return 0;
74681
74774
  }
@@ -74693,17 +74786,17 @@ var CONNECT_SERVICE_USAGE = `laze connect install|status|stop|uninstall|run: the
74693
74786
  \`laze openclaw connect --local\` and \`laze kanban connect\`, whose relays it also runs.
74694
74787
  `;
74695
74788
  function installedPathOf({ context }) {
74696
- return join13(connectFolderOf({ context }), "service.json");
74789
+ return join14(connectFolderOf({ context }), "service.json");
74697
74790
  }
74698
74791
  function logPathOf({ context }) {
74699
- return join13(connectFolderOf({ context }), "connect.log");
74792
+ return join14(connectFolderOf({ context }), "connect.log");
74700
74793
  }
74701
74794
  function homeOf({ context }) {
74702
74795
  return context.environment.inherited.HOME ?? dirname12(dirname12(context.environment.configPath));
74703
74796
  }
74704
74797
  function serviceNameOf({ context }) {
74705
74798
  const { configPath } = context.environment;
74706
- if (configPath === join13(homeOf({ context }), ".laze", "config.json")) return "laze-connect";
74799
+ if (configPath === join14(homeOf({ context }), ".laze", "config.json")) return "laze-connect";
74707
74800
  return `laze-connect-${createHash2("sha256").update(configPath).digest("hex").slice(0, 8)}`;
74708
74801
  }
74709
74802
  function serviceEnvOf({ context }) {
@@ -74726,10 +74819,10 @@ async function run({ context, command }) {
74726
74819
  async function installSystemd({ context }) {
74727
74820
  const name3 = serviceNameOf({ context });
74728
74821
  const env = context.environment.inherited;
74729
- const base = env.XDG_CONFIG_HOME || join13(homeOf({ context }), ".config");
74730
- const file4 = join13(base, "systemd", "user", `${name3}.service`);
74731
- await mkdir11(dirname12(file4), { recursive: true });
74732
- await writeFile10(
74822
+ const base = env.XDG_CONFIG_HOME || join14(homeOf({ context }), ".config");
74823
+ const file4 = join14(base, "systemd", "user", `${name3}.service`);
74824
+ await mkdir3(dirname12(file4), { recursive: true });
74825
+ await writeFile(
74733
74826
  file4,
74734
74827
  systemdUnitOf({ argv: runArgvOf({ context }), env: serviceEnvOf({ context }) })
74735
74828
  );
@@ -74742,10 +74835,10 @@ async function installSystemd({ context }) {
74742
74835
  async function installLaunchd({ context }) {
74743
74836
  const name3 = serviceNameOf({ context });
74744
74837
  const label3 = `ai.laze.${name3}`;
74745
- const file4 = join13(homeOf({ context }), "Library", "LaunchAgents", `${label3}.plist`);
74838
+ const file4 = join14(homeOf({ context }), "Library", "LaunchAgents", `${label3}.plist`);
74746
74839
  const log = logPathOf({ context });
74747
- await mkdir11(dirname12(file4), { recursive: true });
74748
- await writeFile10(
74840
+ await mkdir3(dirname12(file4), { recursive: true });
74841
+ await writeFile(
74749
74842
  file4,
74750
74843
  launchAgentOf({
74751
74844
  label: label3,
@@ -74797,8 +74890,7 @@ async function installConnectService({ context }) {
74797
74890
  const manager = await managerOf({ context });
74798
74891
  const install = { systemd: installSystemd, launchd: installLaunchd, detached: installDetached };
74799
74892
  const installed = await install[manager]({ context });
74800
- await mkdir11(dirname12(path), { recursive: true, mode: 448 });
74801
- await writeFile10(path, JSON.stringify(installed));
74893
+ await writeStateJson({ path, value: installed });
74802
74894
  return describeInstalled({ installed });
74803
74895
  }
74804
74896
  async function ensureConnectService({ context }) {
@@ -74845,15 +74937,14 @@ async function status2({ context }) {
74845
74937
  }
74846
74938
  const config2 = await context.store.read();
74847
74939
  const linked = Object.entries(config2.profiles).filter(([, profile]) => profile.delivery);
74848
- if (linked.length === 0) {
74849
- context.out("No Codex agent is linked on this machine.\n");
74850
- return;
74851
- }
74940
+ if (linked.length === 0) context.out("No Codex agent is linked on this machine.\n");
74852
74941
  for (const [profile, { name: name3, delivery }] of linked) {
74853
74942
  const state = live ? running.agents[profile]?.state ?? "starting" : "not served";
74854
74943
  context.out(`${profile} ${name3} Codex thread ${delivery?.threadId} ${state}
74855
74944
  `);
74856
74945
  }
74946
+ for (const line of await repairDamagedStateFiles()) context.out(`${line}
74947
+ `);
74857
74948
  }
74858
74949
  async function mcpRelayLinesOf({ context }) {
74859
74950
  const running = await runStateOf({ context });
@@ -74878,12 +74969,12 @@ function rushLineOf({ row }) {
74878
74969
  function inLazeOf({
74879
74970
  row,
74880
74971
  waiting,
74881
- nowMs
74972
+ nowMs: nowMs2
74882
74973
  }) {
74883
74974
  if (!waiting) return "; Laze could not say what waits";
74884
74975
  const away = boundAwayOf({ waiting, key: row.key });
74885
74976
  const bound = away ? `; Laze binds the agent to ${away}, not this session` : "";
74886
- const waited = waitedMsOf({ waiting, nowMs });
74977
+ const waited = waitedMsOf({ waiting, nowMs: nowMs2 });
74887
74978
  if (waiting.count === 0) return bound;
74888
74979
  const age = `the oldest for ${Math.round(waited / 1e3)}s`;
74889
74980
  if (waited > UNDELIVERED_AFTER_MS)
@@ -74914,11 +75005,11 @@ async function uninstall({ context }) {
74914
75005
  command: ["systemctl", "--user", "disable", `${installed.name}.service`]
74915
75006
  });
74916
75007
  }
74917
- if (installed.file) await rm3(installed.file, { force: true });
75008
+ if (installed.file) await rm4(installed.file, { force: true });
74918
75009
  if (installed.manager === "systemd") {
74919
75010
  await run({ context, command: ["systemctl", "--user", "daemon-reload"] });
74920
75011
  }
74921
- await rm3(path, { force: true });
75012
+ await rm4(path, { force: true });
74922
75013
  context.out(
74923
75014
  `Removed the connect service (${installed.manager}, ${installed.name}). Linked Codex agents get no messages until \`laze connect install\`.
74924
75015
  `
@@ -74948,10 +75039,7 @@ var ROUND_SECONDS2 = 50;
74948
75039
  var WATCH_MS = 2e3;
74949
75040
  var CHANNEL_CHECK_MS = 5e3;
74950
75041
  async function holderOf({ path }) {
74951
- return readFile14(path, "utf8").then(
74952
- (text3) => JSON.parse(text3),
74953
- () => void 0
74954
- );
75042
+ return readStateJson({ path });
74955
75043
  }
74956
75044
  async function holderClaudeOf({ context, holder }) {
74957
75045
  if (holder.claudePid) return holder.claudePid;
@@ -74964,25 +75052,27 @@ async function takeLock({
74964
75052
  claudePid,
74965
75053
  preempt = false
74966
75054
  }) {
74967
- const holder = await holderOf({ path });
74968
- const self2 = context.processes.pid;
74969
- if (holder && holder.pid !== self2 && context.processes.alive(holder.pid)) {
74970
- const served = await holderClaudeOf({ context, holder });
74971
- const mine4 = preempt && served === claudePid && !holder.monitor;
74972
- if (served && context.processes.alive(served) && !mine4) return false;
74973
- context.processes.stop(holder.pid);
74974
- }
74975
- await mkdir12(dirname13(path), { recursive: true, mode: 448 });
74976
- await writeFile11(
75055
+ return withStateLock({
74977
75056
  path,
74978
- JSON.stringify({
74979
- pid: self2,
74980
- claudePid,
74981
- ...sessionId ? { sessionId } : {},
74982
- ...preempt ? { monitor: true } : {}
74983
- })
74984
- );
74985
- return true;
75057
+ work: async () => {
75058
+ const holder = await holderOf({ path });
75059
+ const self2 = context.processes.pid;
75060
+ if (holder && holder.pid !== self2 && context.processes.alive(holder.pid)) {
75061
+ const served = await holderClaudeOf({ context, holder });
75062
+ const mine4 = preempt && served === claudePid && !holder.monitor;
75063
+ if (served && context.processes.alive(served) && !mine4) return false;
75064
+ context.processes.stop(holder.pid);
75065
+ }
75066
+ const value = {
75067
+ pid: self2,
75068
+ claudePid,
75069
+ ...sessionId ? { sessionId } : {},
75070
+ ...preempt ? { monitor: true } : {}
75071
+ };
75072
+ await writeStateJson({ path, value });
75073
+ return true;
75074
+ }
75075
+ });
74986
75076
  }
74987
75077
  async function channelLive({ context, profile }) {
74988
75078
  const holder = await holderOf({ path: statePathOf({ context, kind: "channels", profile }) });
@@ -75102,7 +75192,7 @@ async function waitForMessages({ context, args }) {
75102
75192
  if (rush) await healRushDelivery({ context });
75103
75193
  const lock = statePathOf({ context, kind: "waiters", profile: name3 });
75104
75194
  if (!await takeLock({ context, path: lock, sessionId: input2.session_id, claudePid })) return 0;
75105
- const seen = () => input2.transcript_path ? readFile14(input2.transcript_path, "utf8") : Promise.resolve("");
75195
+ const seen = () => input2.transcript_path ? readFile8(input2.transcript_path, "utf8") : Promise.resolve("");
75106
75196
  const deadline = context.nowMs() + (WAIT_HOOK_TIMEOUT_SECONDS - 60) * 1e3;
75107
75197
  try {
75108
75198
  while (context.nowMs() < deadline) {
@@ -75113,7 +75203,7 @@ async function waitForMessages({ context, args }) {
75113
75203
  return 0;
75114
75204
  } finally {
75115
75205
  if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
75116
- await rm4(lock, { force: true });
75206
+ await rm5(lock, { force: true });
75117
75207
  }
75118
75208
  }
75119
75209
  async function healRushDelivery({ context }) {
@@ -75154,14 +75244,14 @@ async function monitorServes({
75154
75244
 
75155
75245
  // src/services/codex-link.service.ts
75156
75246
  import { createReadStream } from "node:fs";
75157
- import { readdir as readdir5, rm as rm6, stat as stat6 } from "node:fs/promises";
75158
- import { join as join15, resolve as resolve4 } from "node:path";
75247
+ import { readdir as readdir5, rm as rm7, stat as stat7 } from "node:fs/promises";
75248
+ import { join as join16, resolve as resolve4 } from "node:path";
75159
75249
  import { createInterface as createInterface2 } from "node:readline";
75160
75250
 
75161
75251
  // src/services/codex-adopt.service.ts
75162
75252
  import { spawn as spawn2 } from "node:child_process";
75163
- import { mkdir as mkdir13, readdir as readdir4, readFile as readFile15, rm as rm5, stat as stat5, writeFile as writeFile12 } from "node:fs/promises";
75164
- import { dirname as dirname14, join as join14 } from "node:path";
75253
+ import { readdir as readdir4, rm as rm6, stat as stat6 } from "node:fs/promises";
75254
+ import { join as join15 } from "node:path";
75165
75255
  import { createInterface } from "node:readline";
75166
75256
 
75167
75257
  // src/rules/codex-requests.rules.ts
@@ -75281,11 +75371,11 @@ var CodexAppServer = class _CodexAppServer {
75281
75371
  }
75282
75372
  };
75283
75373
  async function newestThreadId({ codexHome }) {
75284
- const root = join14(codexHome, "sessions");
75374
+ const root = join15(codexHome, "sessions");
75285
75375
  const files2 = await readdir4(root, { recursive: true }).catch(() => []);
75286
75376
  const rollouts = files2.filter((file4) => /rollout-.*\.jsonl$/.test(file4));
75287
75377
  const dated = await Promise.all(
75288
- rollouts.map(async (file4) => ({ file: file4, at: (await stat5(join14(root, file4))).mtimeMs }))
75378
+ rollouts.map(async (file4) => ({ file: file4, at: (await stat6(join15(root, file4))).mtimeMs }))
75289
75379
  );
75290
75380
  const newest = dated.toSorted((a, b) => b.at - a.at)[0]?.file ?? "";
75291
75381
  const id4 = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/.exec(newest);
@@ -75360,10 +75450,7 @@ async function answer2({
75360
75450
  var MAX_RESTART_WAIT_SECONDS = 60;
75361
75451
  var HEALTHY_RUN_MS = 6e4;
75362
75452
  async function recordOf({ path }) {
75363
- return readFile15(path, "utf8").then(
75364
- (text3) => JSON.parse(text3),
75365
- () => void 0
75366
- );
75453
+ return readStateJson({ path });
75367
75454
  }
75368
75455
  function threadFlag({ thread: thread2 }) {
75369
75456
  return thread2 ? ["--thread", thread2] : [];
@@ -75382,8 +75469,7 @@ async function startAdoptInBackground({
75382
75469
  const adopt = ["adopt", "codex", "--profile", profile, ...threadFlag({ thread: thread2 })];
75383
75470
  const argv = [...context.program, ...adopt, "--supervise"];
75384
75471
  const pid = context.processes.spawnDetached({ argv, logPath: log });
75385
- await mkdir13(dirname14(path), { recursive: true, mode: 448 });
75386
- await writeFile12(path, JSON.stringify({ pid, thread: thread2, log, startedAt: context.nowMs() }));
75472
+ await writeStateJson({ path, value: { pid, thread: thread2, log, startedAt: context.nowMs() } });
75387
75473
  return [
75388
75474
  `Started \`${laze} adopt codex\` in the background (pid ${pid}). It answers each Laze message`,
75389
75475
  `as a turn in ${thread2 ? `this Codex thread (${thread2})` : "the newest Codex thread"}, and starts again if it stops.`,
@@ -75442,7 +75528,7 @@ Log: ${record4.log}
75442
75528
  async function adoptStop({ context, profile }) {
75443
75529
  const path = statePathOf({ context, kind: "adopt", profile });
75444
75530
  const record4 = await recordOf({ path });
75445
- await rm5(path, { force: true });
75531
+ await rm6(path, { force: true });
75446
75532
  if (!record4 || !context.processes.stop(record4.pid)) {
75447
75533
  context.out(`laze adopt codex was not running in the background for profile "${profile}".
75448
75534
  `);
@@ -75467,10 +75553,7 @@ async function adoptedThreadOf({
75467
75553
  );
75468
75554
  if (!held) return threadId;
75469
75555
  const path = statePathOf({ context, kind: "adopt", profile, extension: "forks.json" });
75470
- const forks = await readFile15(path, "utf8").then(
75471
- (text3) => JSON.parse(text3),
75472
- () => ({})
75473
- );
75556
+ const forks = await readStateJson({ path }) ?? {};
75474
75557
  const known = forks[threadId];
75475
75558
  if (known && await codex.call("thread/resume", { threadId: known }).then(
75476
75559
  () => true,
@@ -75482,8 +75565,7 @@ async function adoptedThreadOf({
75482
75565
  }
75483
75566
  const forked = record3((await codex.call("thread/fork", { threadId })).thread).id;
75484
75567
  if (typeof forked !== "string") throw new Error("thread/fork answered no thread id");
75485
- await mkdir13(dirname14(path), { recursive: true, mode: 448 });
75486
- await writeFile12(path, JSON.stringify({ ...forks, [threadId]: forked }));
75568
+ await writeStateJson({ path, value: { ...forks, [threadId]: forked } });
75487
75569
  context.out(
75488
75570
  `Codex holds thread ${threadId} open elsewhere; answering in its new fork ${forked}.
75489
75571
  `
@@ -75554,13 +75636,13 @@ async function newestThreadIn({
75554
75636
  codexHome,
75555
75637
  directory
75556
75638
  }) {
75557
- const root = join15(codexHome, "sessions");
75639
+ const root = join16(codexHome, "sessions");
75558
75640
  const files2 = await readdir5(root, { recursive: true }).catch(() => []);
75559
75641
  const rollouts = files2.filter((file4) => /rollout-.*\.jsonl$/.test(file4));
75560
75642
  const dated = await Promise.all(
75561
75643
  rollouts.map(async (file4) => ({
75562
- path: join15(root, file4),
75563
- at: await stat6(join15(root, file4)).then(
75644
+ path: join16(root, file4),
75645
+ at: await stat7(join16(root, file4)).then(
75564
75646
  (info) => info.mtimeMs,
75565
75647
  () => 0
75566
75648
  )
@@ -75591,7 +75673,7 @@ async function stopAdopt({ context, profile }) {
75591
75673
  const running = await readJson({ path });
75592
75674
  if (!running) return;
75593
75675
  context.processes.stop(running.pid);
75594
- await rm6(path, { force: true });
75676
+ await rm7(path, { force: true });
75595
75677
  }
75596
75678
  async function linkCodexSession({
75597
75679
  context,
@@ -75630,16 +75712,16 @@ async function linkCodexSession({
75630
75712
  }
75631
75713
 
75632
75714
  // src/services/laze-plugin.service.ts
75633
- import { mkdir as mkdir14, readFile as readFile16, rm as rm7, writeFile as writeFile13 } from "node:fs/promises";
75715
+ import { mkdir as mkdir4, readFile as readFile9, rm as rm8, writeFile as writeFile2 } from "node:fs/promises";
75634
75716
  import { homedir as homedir4 } from "node:os";
75635
- import { dirname as dirname15, join as join17 } from "node:path";
75717
+ import { dirname as dirname13, join as join18 } from "node:path";
75636
75718
 
75637
75719
  // src/rules/laze-plugin.rules.ts
75638
75720
  import { createHash as createHash3 } from "node:crypto";
75639
- import { join as join16 } from "node:path";
75721
+ import { join as join17 } from "node:path";
75640
75722
  var LAZE_PLUGIN = "laze";
75641
75723
  function pluginNameOf({ configPath, home }) {
75642
- if (configPath === join16(home, ".laze", "config.json")) return LAZE_PLUGIN;
75724
+ if (configPath === join17(home, ".laze", "config.json")) return LAZE_PLUGIN;
75643
75725
  return `${LAZE_PLUGIN}-${createHash3("sha256").update(configPath).digest("hex").slice(0, 8)}`;
75644
75726
  }
75645
75727
  var NPX_CLI = ["npx", "-y", "@lazehq/cli@latest"];
@@ -75881,14 +75963,11 @@ function installedNameOf({ context }) {
75881
75963
  return `${name3}@${name3}`;
75882
75964
  }
75883
75965
  function pluginFolderOf({ context }) {
75884
- return join17(dirname15(context.environment.configPath), "plugins");
75966
+ return join18(dirname13(context.environment.configPath), "plugins");
75885
75967
  }
75886
75968
  async function pluginIsCurrent({ context }) {
75887
- const manifest = join17(pluginFolderOf({ context }), LAZE_PLUGIN, ".claude-plugin", "plugin.json");
75888
- const written = await readFile16(manifest, "utf8").then(
75889
- (text3) => JSON.parse(text3).version,
75890
- () => void 0
75891
- );
75969
+ const manifest = join18(pluginFolderOf({ context }), LAZE_PLUGIN, ".claude-plugin", "plugin.json");
75970
+ const written = await readFile9(manifest, "utf8").then((text3) => JSON.parse(text3).version).catch(() => void 0);
75892
75971
  return written === cliVersionOf();
75893
75972
  }
75894
75973
  async function writeLazePlugin({ context }) {
@@ -75900,9 +75979,9 @@ async function writeLazePlugin({ context }) {
75900
75979
  configPath: context.environment.configPath
75901
75980
  });
75902
75981
  for (const [path, text3] of Object.entries(files2)) {
75903
- const target = join17(folder, path);
75904
- await mkdir14(dirname15(target), { recursive: true });
75905
- await writeFile13(target, text3);
75982
+ const target = join18(folder, path);
75983
+ await mkdir4(dirname13(target), { recursive: true });
75984
+ await writeFile2(target, text3);
75906
75985
  }
75907
75986
  return folder;
75908
75987
  }
@@ -75931,7 +76010,7 @@ async function registerWithClaude({ context, folder }) {
75931
76010
  return claudeScript({ context, script });
75932
76011
  }
75933
76012
  function claudeDirOf({ context }) {
75934
- return context.environment.inherited.CLAUDE_CONFIG_DIR || join17(homeOf2({ context }), ".claude");
76013
+ return context.environment.inherited.CLAUDE_CONFIG_DIR || join18(homeOf2({ context }), ".claude");
75935
76014
  }
75936
76015
  function unregisterAs({ context, name: name3 }) {
75937
76016
  const script = [
@@ -75942,8 +76021,8 @@ function unregisterAs({ context, name: name3 }) {
75942
76021
  }
75943
76022
  async function dropOwnLeftover({ context, folder }) {
75944
76023
  if (pluginNameHere({ context }) === LAZE_PLUGIN) return;
75945
- const known = await readFile16(
75946
- join17(claudeDirOf({ context }), "plugins", "known_marketplaces.json"),
76024
+ const known = await readFile9(
76025
+ join18(claudeDirOf({ context }), "plugins", "known_marketplaces.json"),
75947
76026
  "utf8"
75948
76027
  ).then((text3) => JSON.parse(text3)).catch(() => void 0);
75949
76028
  if (known?.[LAZE_PLUGIN]?.source?.path !== folder) return;
@@ -75951,20 +76030,17 @@ async function dropOwnLeftover({ context, folder }) {
75951
76030
  }
75952
76031
  var RUN_FILES = ["hooks/hooks.json", "monitors/monitors.json"];
75953
76032
  async function cachedPluginOf({ context }) {
75954
- const path = join17(claudeDirOf({ context }), "plugins", "installed_plugins.json");
75955
- const listed = await readFile16(path, "utf8").then(
75956
- (text3) => JSON.parse(text3),
75957
- () => void 0
75958
- );
76033
+ const path = join18(claudeDirOf({ context }), "plugins", "installed_plugins.json");
76034
+ const listed = await readFile9(path, "utf8").then((text3) => JSON.parse(text3)).catch(() => void 0);
75959
76035
  return listed?.plugins?.[installedNameOf({ context })]?.[0]?.installPath;
75960
76036
  }
75961
76037
  async function refreshStaleCache({ context, folder }) {
75962
76038
  const cached2 = await cachedPluginOf({ context });
75963
76039
  if (!cached2) return true;
75964
- const read4 = (path) => readFile16(path, "utf8").catch(() => "");
76040
+ const read4 = (path) => readFile9(path, "utf8").catch(() => "");
75965
76041
  for (const file4 of RUN_FILES) {
75966
- const ours = await read4(join17(folder, LAZE_PLUGIN, file4));
75967
- if (ours === await read4(join17(cached2, file4))) continue;
76042
+ const ours = await read4(join18(folder, LAZE_PLUGIN, file4));
76043
+ if (ours === await read4(join18(cached2, file4))) continue;
75968
76044
  const plugin2 = installedNameOf({ context });
75969
76045
  const script = [
75970
76046
  `claude plugin uninstall ${plugin2} --scope user ${QUIET}`,
@@ -75975,10 +76051,10 @@ async function refreshStaleCache({ context, folder }) {
75975
76051
  return true;
75976
76052
  }
75977
76053
  function registeredMarkOf({ context }) {
75978
- return join17(pluginFolderOf({ context }), "registered");
76054
+ return join18(pluginFolderOf({ context }), "registered");
75979
76055
  }
75980
76056
  async function pluginRegistered({ context }) {
75981
- return readFile16(registeredMarkOf({ context }), "utf8").then(
76057
+ return readFile9(registeredMarkOf({ context }), "utf8").then(
75982
76058
  () => true,
75983
76059
  () => false
75984
76060
  );
@@ -75987,20 +76063,20 @@ async function installLazePlugin({ context }) {
75987
76063
  const folder = await writeLazePlugin({ context });
75988
76064
  await dropOwnLeftover({ context, folder });
75989
76065
  const registered = await registerWithClaude({ context, folder }) && await refreshStaleCache({ context, folder });
75990
- if (registered) await writeFile13(registeredMarkOf({ context }), cliVersionOf());
76066
+ if (registered) await writeFile2(registeredMarkOf({ context }), cliVersionOf());
75991
76067
  return { folder, registered };
75992
76068
  }
75993
76069
  async function plugin({ context, args }) {
75994
76070
  const action = args.words[1] ?? "install";
75995
76071
  if (action === "path") {
75996
- context.out(`${join17(pluginFolderOf({ context }), LAZE_PLUGIN)}
76072
+ context.out(`${join18(pluginFolderOf({ context }), LAZE_PLUGIN)}
75997
76073
  `);
75998
76074
  return 0;
75999
76075
  }
76000
76076
  if (action === "uninstall") {
76001
76077
  const name3 = pluginNameHere({ context });
76002
76078
  const removed = await unregisterAs({ context, name: name3 });
76003
- await rm7(registeredMarkOf({ context }), { force: true });
76079
+ await rm8(registeredMarkOf({ context }), { force: true });
76004
76080
  context.out(
76005
76081
  removed ? `Removed the Laze plugin ${name3}@${name3} from Claude Code.
76006
76082
  ` : `Claude Code did not remove it; run: claude plugin uninstall ${name3}@${name3} && claude plugin marketplace remove ${name3}
@@ -76022,8 +76098,7 @@ async function plugin({ context, args }) {
76022
76098
  }
76023
76099
 
76024
76100
  // src/services/mcp-channel.service.ts
76025
- import { mkdir as mkdir15, rm as rm8, writeFile as writeFile14 } from "node:fs/promises";
76026
- import { dirname as dirname16 } from "node:path";
76101
+ import { rm as rm9 } from "node:fs/promises";
76027
76102
  var LAZE_MCP_SERVER = "laze";
76028
76103
  var DEV_CHANNELS_FLAG = "--dangerously-load-development-channels";
76029
76104
  var ROUND_SECONDS3 = 50;
@@ -76113,8 +76188,7 @@ async function pushInbox({
76113
76188
  signal
76114
76189
  }) {
76115
76190
  const marker = statePathOf({ context, kind: "channels", profile });
76116
- await mkdir15(dirname16(marker), { recursive: true, mode: 448 });
76117
- await writeFile14(marker, JSON.stringify({ pid: context.processes.pid }));
76191
+ await writeStateJson({ path: marker, value: { pid: context.processes.pid } });
76118
76192
  try {
76119
76193
  while (!signal.aborted) {
76120
76194
  const messages = await client.post("/api/agents/me/inbox", { waitSeconds: ROUND_SECONDS3 }, { signal }).catch(async (error63) => {
@@ -76143,13 +76217,12 @@ async function pushInbox({
76143
76217
  `);
76144
76218
  }
76145
76219
  } finally {
76146
- await rm8(marker, { force: true });
76220
+ await rm9(marker, { force: true });
76147
76221
  }
76148
76222
  }
76149
76223
 
76150
76224
  // src/services/plugin-tip.service.ts
76151
- import { mkdir as mkdir16, readFile as readFile17, writeFile as writeFile15 } from "node:fs/promises";
76152
- import { dirname as dirname17 } from "node:path";
76225
+ import { readFile as readFile10 } from "node:fs/promises";
76153
76226
  var RELOAD_TIP = "Laze: the Laze plugin is installed in Claude Code, and this session has not loaded it yet. Tell the user once, in one plain line, that it is optional: typing /reload-plugins makes Laze messages arrive right away; until then they still arrive through the hooks.";
76154
76227
  var LINK_RELOAD_TIP = "Tell the user once, in one plain line, that it is optional: typing /reload-plugins makes Laze messages arrive right away; until then they still arrive through the hooks.";
76155
76228
  function monitorsRunHere({ context }) {
@@ -76183,8 +76256,7 @@ async function markReloadTipTold({
76183
76256
  }) {
76184
76257
  if (!session) return;
76185
76258
  const path = toldPathOf({ context, session });
76186
- await mkdir16(dirname17(path), { recursive: true, mode: 448 });
76187
- await writeFile15(path, String(context.nowMs()), { mode: 384 });
76259
+ await writeStateText({ path, text: String(context.nowMs()) });
76188
76260
  }
76189
76261
  async function reloadTipOnce({
76190
76262
  context,
@@ -76192,7 +76264,7 @@ async function reloadTipOnce({
76192
76264
  }) {
76193
76265
  if (!session || !monitorsRunHere({ context })) return void 0;
76194
76266
  if (!await pluginRegistered({ context })) return void 0;
76195
- const told = await readFile17(toldPathOf({ context, session }), "utf8").then(
76267
+ const told = await readFile10(toldPathOf({ context, session }), "utf8").then(
76196
76268
  () => true,
76197
76269
  () => false
76198
76270
  );
@@ -76253,17 +76325,22 @@ async function harnessOf2({ context, args }) {
76253
76325
  function slugOf(name3) {
76254
76326
  return name3.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "agent";
76255
76327
  }
76328
+ function settingsOf({ path, text: text3 }) {
76329
+ try {
76330
+ return JSON.parse(text3);
76331
+ } catch {
76332
+ throw new CliUsageError(`${path} is not valid JSON; fix it, then link again.`);
76333
+ }
76334
+ }
76256
76335
  async function installHooks({
76257
76336
  context,
76258
76337
  directory,
76259
76338
  profile
76260
76339
  }) {
76261
- const folder = join18(directory, ".claude");
76262
- const path = join18(folder, "settings.local.json");
76263
- const current3 = await readFile18(path, "utf8").then(
76264
- (text3) => JSON.parse(text3),
76265
- () => ({})
76266
- );
76340
+ const folder = join19(directory, ".claude");
76341
+ const path = join19(folder, "settings.local.json");
76342
+ const text3 = await readFile11(path, "utf8").catch(() => "{}");
76343
+ const current3 = settingsOf({ path, text: text3 });
76267
76344
  const command = (hook) => hookCommand({ program: context.program, profile, hook });
76268
76345
  const settings3 = withLazeHooks({
76269
76346
  settings: current3,
@@ -76271,8 +76348,8 @@ async function installHooks({
76271
76348
  waitCommand: command("wait"),
76272
76349
  preToolCommand: command("pre-tool")
76273
76350
  });
76274
- await mkdir17(folder, { recursive: true });
76275
- await writeFile16(path, `${JSON.stringify(settings3, null, 2)}
76351
+ await mkdir5(folder, { recursive: true });
76352
+ await writeFile3(path, `${JSON.stringify(settings3, null, 2)}
76276
76353
  `);
76277
76354
  return path;
76278
76355
  }
@@ -76499,7 +76576,7 @@ async function reportTranscript({
76499
76576
  input: input2
76500
76577
  }) {
76501
76578
  if (!input2.transcript_path || !input2.session_id) return;
76502
- const lines2 = (await readFile18(input2.transcript_path, "utf8")).split("\n");
76579
+ const lines2 = (await readFile11(input2.transcript_path, "utf8")).split("\n");
76503
76580
  const context = readTranscript({ lines: lines2 });
76504
76581
  await client.post("/api/agents/me/activity", {
76505
76582
  sessionId: input2.session_id,
@@ -76538,7 +76615,7 @@ async function handOver({ context, args }) {
76538
76615
  const kept = await dueFromSpool({
76539
76616
  context,
76540
76617
  profile: agent3,
76541
- seen: () => input2.transcript_path ? readFile18(input2.transcript_path, "utf8") : Promise.resolve(""),
76618
+ seen: () => input2.transcript_path ? readFile11(input2.transcript_path, "utf8") : Promise.resolve(""),
76542
76619
  pushedToo: false,
76543
76620
  settledOnly: true
76544
76621
  });
@@ -76579,17 +76656,14 @@ async function addSessionStartWaiter({ context, args }) {
76579
76656
  const directory = context.environment.inherited.CLAUDE_PROJECT_DIR;
76580
76657
  const profile = flagText({ args, name: "profile" });
76581
76658
  if (!directory || !profile) return;
76582
- const path = join18(directory, ".claude", "settings.local.json");
76583
- const settings3 = await readFile18(path, "utf8").then(
76584
- (text3) => JSON.parse(text3),
76585
- () => void 0
76586
- );
76659
+ const path = join19(directory, ".claude", "settings.local.json");
76660
+ const settings3 = await readFile11(path, "utf8").then((text3) => JSON.parse(text3)).catch(() => void 0);
76587
76661
  if (!settings3 || !lacksSessionStartWaiter({ settings: settings3 })) return;
76588
76662
  await installHooks({ context, directory, profile });
76589
76663
  }
76590
76664
  async function refreshPlugin({ context }) {
76591
76665
  if (await pluginIsCurrent({ context })) return;
76592
- const logPath = join18(pluginFolderOf({ context }), "install.log");
76666
+ const logPath = join19(pluginFolderOf({ context }), "install.log");
76593
76667
  context.processes.spawnDetached({ argv: [...context.program, "plugin", "install"], logPath });
76594
76668
  }
76595
76669
  async function stopHook({ context, args }) {
@@ -76610,7 +76684,7 @@ async function stopHook({ context, args }) {
76610
76684
  }
76611
76685
 
76612
76686
  // src/services/agent-manage-commands.service.ts
76613
- import { readFile as readFile19 } from "node:fs/promises";
76687
+ import { readFile as readFile12 } from "node:fs/promises";
76614
76688
  import { extname, resolve as resolve6 } from "node:path";
76615
76689
 
76616
76690
  // src/rules/login-format.rules.ts
@@ -76618,31 +76692,31 @@ var HARNESS_NAMES2 = {
76618
76692
  "claude-code": "Claude",
76619
76693
  codex: "Codex"
76620
76694
  };
76621
- function ahead({ iso: iso3, nowMs }) {
76622
- return iso3 !== null && Temporal3.Instant.from(iso3).epochMilliseconds > nowMs ? iso3 : null;
76695
+ function ahead({ iso: iso3, nowMs: nowMs2 }) {
76696
+ return iso3 !== null && Temporal3.Instant.from(iso3).epochMilliseconds > nowMs2 ? iso3 : null;
76623
76697
  }
76624
76698
  function usageOf2({
76625
76699
  usedPercent,
76626
76700
  resetsAt,
76627
76701
  limitedUntil,
76628
- nowMs
76702
+ nowMs: nowMs2
76629
76703
  }) {
76630
- const limited2 = ahead({ iso: limitedUntil, nowMs });
76704
+ const limited2 = ahead({ iso: limitedUntil, nowMs: nowMs2 });
76631
76705
  if (limited2) return `out of usage until ${utcTimeOf(limited2)}`;
76632
76706
  if (usedPercent === null) return "no usage reading yet";
76633
- const resets = ahead({ iso: resetsAt, nowMs });
76707
+ const resets = ahead({ iso: resetsAt, nowMs: nowMs2 });
76634
76708
  const used = `${Math.round(usedPercent)}% used`;
76635
76709
  return resets ? `${used}, resets ${utcTimeOf(resets)}` : used;
76636
76710
  }
76637
76711
  var INVALID2 = "signed out: its provider refused this token, sign in again with a new one";
76638
76712
  var EXPIRES_SOON = " expires within hours: run claude setup-token for a token that lasts a year";
76639
- function formatLogins({ list: list12, nowMs }) {
76713
+ function formatLogins({ list: list12, nowMs: nowMs2 }) {
76640
76714
  if (list12.logins.length === 0) {
76641
76715
  return "No logins yet. Add one with: laze agent logins add --harness claude-code --name <name> < token-file\n";
76642
76716
  }
76643
76717
  const lines2 = list12.logins.map((login2) => {
76644
76718
  const state = login2.agentsOnIt > 0 ? `in use by ${login2.agentsOnIt} ${login2.agentsOnIt === 1 ? "agent" : "agents"}` : "ready";
76645
- const usage = usageOf2({ ...login2, nowMs });
76719
+ const usage = usageOf2({ ...login2, nowMs: nowMs2 });
76646
76720
  let shown2 = usage.startsWith("out of usage") ? usage : `${state}, ${usage}`;
76647
76721
  if (login2.state === "invalid") shown2 = INVALID2;
76648
76722
  const line = `${HARNESS_NAMES2[login2.harness]} ${login2.name} (${shown2}) ${login2.id}`;
@@ -76652,13 +76726,13 @@ ${EXPIRES_SOON}` : line;
76652
76726
  return `${lines2.join("\n")}
76653
76727
  `;
76654
76728
  }
76655
- function formatPool({ pool, nowMs }) {
76729
+ function formatPool({ pool, nowMs: nowMs2 }) {
76656
76730
  const role2 = pool.myRole ?? "admin view";
76657
76731
  const lines2 = [`${pool.name} (you: ${role2}) ${pool.id}`];
76658
76732
  lines2.push(
76659
76733
  pool.logins.length === 0 ? " Logins: none yet" : " Logins:",
76660
76734
  ...pool.logins.map((login2) => {
76661
- const usage = login2.invalid ? INVALID2 : usageOf2({ ...login2, nowMs });
76735
+ const usage = login2.invalid ? INVALID2 : usageOf2({ ...login2, nowMs: nowMs2 });
76662
76736
  const use = login2.inUse && !login2.invalid ? "in use, " : "";
76663
76737
  const line = ` ${HARNESS_NAMES2[login2.harness]} ${login2.name} added by ${login2.contributedByName} (${use}${usage})`;
76664
76738
  return login2.expiresSoon ? `${line}
@@ -76674,8 +76748,8 @@ function formatPool({ pool, nowMs }) {
76674
76748
  }
76675
76749
  return lines2.join("\n");
76676
76750
  }
76677
- function formatOnePool({ pool, nowMs }) {
76678
- return `${formatPool({ pool, nowMs })}
76751
+ function formatOnePool({ pool, nowMs: nowMs2 }) {
76752
+ return `${formatPool({ pool, nowMs: nowMs2 })}
76679
76753
  `;
76680
76754
  }
76681
76755
  function formatUsageCheck({ check: check3 }) {
@@ -76686,11 +76760,11 @@ function formatUsageCheck({ check: check3 }) {
76686
76760
  return `${checked}, ${check3.skipped} skipped (checked in the last ${minutes} minutes).
76687
76761
  `;
76688
76762
  }
76689
- function formatPools({ pools, nowMs }) {
76763
+ function formatPools({ pools, nowMs: nowMs2 }) {
76690
76764
  if (pools.pools.length === 0) {
76691
76765
  return 'You are in no login pool. Create one with: laze agent pools create "<name>"\n';
76692
76766
  }
76693
- return `${pools.pools.map((pool) => formatPool({ pool, nowMs })).join("\n\n")}
76767
+ return `${pools.pools.map((pool) => formatPool({ pool, nowMs: nowMs2 })).join("\n\n")}
76694
76768
  `;
76695
76769
  }
76696
76770
  function refusalLine({ code, message: message2 }) {
@@ -76748,7 +76822,7 @@ async function avatarOf({
76748
76822
  return emoji4;
76749
76823
  }
76750
76824
  if (!path) return void 0;
76751
- const bytes = await readFile19(resolve6(context.cwd, path)).catch(() => {
76825
+ const bytes = await readFile12(resolve6(context.cwd, path)).catch(() => {
76752
76826
  throw new CliUsageError(`laze: cannot read the avatar file ${path}.`);
76753
76827
  });
76754
76828
  const uploaded = await client.post("/api/agents/avatars", {
@@ -77164,7 +77238,7 @@ var LOGIN_ACTIONS = {
77164
77238
  PATHS.checkLogins,
77165
77239
  wanted ? { poolId: wanted } : {}
77166
77240
  );
77167
- const nowMs = step.context.nowMs();
77241
+ const nowMs2 = step.context.nowMs();
77168
77242
  if (wanted) {
77169
77243
  const pools = await step.client.get(PATHS.pools);
77170
77244
  const pool = poolNamed({ pools: pools.pools, wanted });
@@ -77172,14 +77246,14 @@ var LOGIN_ACTIONS = {
77172
77246
  return step.context.out(`${JSON.stringify({ ...check3, pool }, null, 2)}
77173
77247
  `);
77174
77248
  }
77175
- return step.context.out(`${formatUsageCheck({ check: check3 })}${formatOnePool({ pool, nowMs })}`);
77249
+ return step.context.out(`${formatUsageCheck({ check: check3 })}${formatOnePool({ pool, nowMs: nowMs2 })}`);
77176
77250
  }
77177
77251
  const list12 = await step.client.get(PATHS.logins);
77178
77252
  if (step.args.flags.json) {
77179
77253
  return step.context.out(`${JSON.stringify({ ...check3, ...list12 }, null, 2)}
77180
77254
  `);
77181
77255
  }
77182
- step.context.out(`${formatUsageCheck({ check: check3 })}${formatLogins({ list: list12, nowMs })}`);
77256
+ step.context.out(`${formatUsageCheck({ check: check3 })}${formatLogins({ list: list12, nowMs: nowMs2 })}`);
77183
77257
  }
77184
77258
  },
77185
77259
  history: {
@@ -77464,8 +77538,8 @@ async function setAgentRunsOn({
77464
77538
  }
77465
77539
 
77466
77540
  // src/services/agent-migrate-commands.service.ts
77467
- import { readFile as readFile20, stat as stat7 } from "node:fs/promises";
77468
- import { basename as basename5, join as join19, resolve as resolve7 } from "node:path";
77541
+ import { readFile as readFile13, stat as stat8 } from "node:fs/promises";
77542
+ import { basename as basename6, join as join20, resolve as resolve7 } from "node:path";
77469
77543
 
77470
77544
  // src/rules/migration-upload.rules.ts
77471
77545
  import { createHash as createHash4 } from "node:crypto";
@@ -77676,13 +77750,13 @@ async function chosenTranscriptOf({
77676
77750
  file: file4
77677
77751
  }) {
77678
77752
  const path = resolve7(context.cwd, file4);
77679
- const sessionId = basename5(path).replace(/\.jsonl$/, "");
77753
+ const sessionId = basename6(path).replace(/\.jsonl$/, "");
77680
77754
  if (ticket.source !== "claude-code" || !SESSION_ID.test(sessionId)) {
77681
77755
  throw new CliUsageError(
77682
77756
  "--transcript takes a Claude Code transcript named <session id>.jsonl. Nothing was uploaded."
77683
77757
  );
77684
77758
  }
77685
- const found = await stat7(path).then(
77759
+ const found = await stat8(path).then(
77686
77760
  (info) => info.isFile(),
77687
77761
  () => false
77688
77762
  );
@@ -77702,7 +77776,7 @@ async function transcriptOf({ context, args, ticket }) {
77702
77776
  if (ticket.source === "codex") {
77703
77777
  const codexHome = context.environment.codexHome;
77704
77778
  const path2 = await codexRolloutPathOf({ codexHome, threadId: sessionId });
77705
- return { sessionId, path: path2, where: join19(codexHome, "sessions") };
77779
+ return { sessionId, path: path2, where: join20(codexHome, "sessions") };
77706
77780
  }
77707
77781
  const { root, path } = await claudeTranscriptOf({ context, sessionId });
77708
77782
  return { sessionId, path, where: root };
@@ -77754,7 +77828,7 @@ async function uploadTranscript({ context, args, client }) {
77754
77828
  `The transcript of session ${found.sessionId} was not found under ${found.where}; nothing was uploaded.`
77755
77829
  );
77756
77830
  }
77757
- const raw = await readFile20(found.path, "utf8");
77831
+ const raw = await readFile13(found.path, "utf8");
77758
77832
  if (!raw.trim()) throw new CliUsageError(`${found.path} is empty; nothing was uploaded.`);
77759
77833
  const redacted = await redactTranscript({ text: raw });
77760
77834
  const { parts, truncated } = transcriptPartsOf({
@@ -77764,7 +77838,7 @@ async function uploadTranscript({ context, args, client }) {
77764
77838
  });
77765
77839
  const upload = { parts, truncated, redactions: redacted.redactions };
77766
77840
  await uploadParts({ client, migrationId: id4, upload });
77767
- const fileName = basename5(found.path);
77841
+ const fileName = basename6(found.path);
77768
77842
  const completed = await client.post(
77769
77843
  `/api/agents/me/migrations/${id4}/complete`,
77770
77844
  {
@@ -78008,8 +78082,8 @@ async function requestAgent({ context, args }) {
78008
78082
  }
78009
78083
 
78010
78084
  // src/services/app-commands.service.ts
78011
- import { mkdir as mkdir18, readdir as readdir6, readFile as readFile22, writeFile as writeFile18 } from "node:fs/promises";
78012
- import { dirname as dirname18, join as join22, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
78085
+ import { mkdir as mkdir6, readdir as readdir6, readFile as readFile15, writeFile as writeFile5 } from "node:fs/promises";
78086
+ import { dirname as dirname14, join as join23, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
78013
78087
 
78014
78088
  // ../../modules/app/contract/src/app.connections.ts
78015
78089
  var appFunctionNameSchema = external_exports.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/);
@@ -80148,16 +80222,16 @@ function print({
80148
80222
  async function appConnections({
80149
80223
  context,
80150
80224
  args,
80151
- open: open5
80225
+ open: open6
80152
80226
  }) {
80153
- const { client, appId, name: name3 } = await open5();
80227
+ const { client, appId, name: name3 } = await open6();
80154
80228
  const listed = await client.post("/api/apps/connections", { appId });
80155
80229
  print({ context, args, value: listed, text: connectionsText({ name: name3, listed }) });
80156
80230
  }
80157
80231
  async function appConnection({
80158
80232
  context,
80159
80233
  args,
80160
- open: open5
80234
+ open: open6
80161
80235
  }) {
80162
80236
  const [, , verb, connection] = args.words;
80163
80237
  if (verb !== "allow" && verb !== "revoke" || !connection) {
@@ -80166,7 +80240,7 @@ async function appConnection({
80166
80240
  if (verb) throw new CliUsageError(USAGE2);
80167
80241
  return;
80168
80242
  }
80169
- const { client, appId, name: name3 } = await open5();
80243
+ const { client, appId, name: name3 } = await open6();
80170
80244
  const listed = await client.post(`/api/apps/connections/${verb}`, { appId, connection }).catch((error63) => {
80171
80245
  if (!(error63 instanceof LazeApiError) || error63.code !== "permission_denied") throw error63;
80172
80246
  throw new CliUsageError(
@@ -80195,40 +80269,40 @@ function appAndWord({ args, usage }) {
80195
80269
  if (!word3) throw new CliUsageError(usage);
80196
80270
  return { app: app2, word: word3 };
80197
80271
  }
80198
- var rename4 = async ({ context, args, open: open5 }) => {
80272
+ var rename2 = async ({ context, args, open: open6 }) => {
80199
80273
  const { app: app2, word: word3 } = appAndWord({ args, usage: "Usage: laze app rename [app] <new name>" });
80200
- const { client, appId, name: name3 } = await open5(app2);
80274
+ const { client, appId, name: name3 } = await open6(app2);
80201
80275
  const renamed = await client.post("/api/apps/rename", { appId, name: word3 });
80202
80276
  print2({ context, args, value: renamed, text: `${name3} is now called ${renamed.name}.
80203
80277
  ` });
80204
80278
  };
80205
- var archive = async ({ context, args, open: open5 }) => {
80206
- const { client, appId } = await open5(args.words[2]);
80279
+ var archive = async ({ context, args, open: open6 }) => {
80280
+ const { client, appId } = await open6(args.words[2]);
80207
80281
  const archived = await client.post("/api/apps/archive", { appId });
80208
80282
  const text3 = `Archived ${archived.name}: it serves nothing and keeps its versions and data. laze app unarchive brings it back.
80209
80283
  `;
80210
80284
  print2({ context, args, value: archived, text: text3 });
80211
80285
  };
80212
- var unarchive = async ({ context, args, open: open5 }) => {
80213
- const { client, appId } = await open5(args.words[2]);
80286
+ var unarchive = async ({ context, args, open: open6 }) => {
80287
+ const { client, appId } = await open6(args.words[2]);
80214
80288
  const back = await client.post("/api/apps/unarchive", { appId });
80215
80289
  const text3 = `${back.name} is back at the same addresses.
80216
80290
  `;
80217
80291
  print2({ context, args, value: back, text: text3 });
80218
80292
  };
80219
- var remove = async ({ context, args, open: open5 }) => {
80293
+ var remove = async ({ context, args, open: open6 }) => {
80220
80294
  const confirmName = flagText({ args, name: "confirm" });
80221
80295
  if (!confirmName) {
80222
80296
  throw new CliUsageError("Usage: laze app delete [app] --confirm <the app's name>");
80223
80297
  }
80224
- const { client, appId, name: name3 } = await open5(args.words[2]);
80298
+ const { client, appId, name: name3 } = await open6(args.words[2]);
80225
80299
  await client.post("/api/apps/delete", { appId, confirmName });
80226
80300
  const text3 = `Deleted ${name3}: it stopped serving and is gone from the workspace.
80227
80301
  `;
80228
80302
  print2({ context, args, value: { deleted: appId }, text: text3 });
80229
80303
  };
80230
- var revokeLease = async ({ context, args, open: open5 }) => {
80231
- const { client, appId, name: name3 } = await open5(args.words[2]);
80304
+ var revokeLease = async ({ context, args, open: open6 }) => {
80305
+ const { client, appId, name: name3 } = await open6(args.words[2]);
80232
80306
  const app2 = await client.post("/api/apps/publish/revoke-lease", { appId });
80233
80307
  const text3 = `${name3}'s builder asks for an approval again before its next public publish.
80234
80308
  `;
@@ -80289,18 +80363,18 @@ function backupsText({ name: name3, status: status11 }) {
80289
80363
  return `${name3}: ${replicating} ${window2}
80290
80364
  ${restores.join("")}`;
80291
80365
  }
80292
- var backups = async ({ context, args, open: open5 }) => {
80293
- const { client, appId, name: name3 } = await open5(args.words[2]);
80366
+ var backups = async ({ context, args, open: open6 }) => {
80367
+ const { client, appId, name: name3 } = await open6(args.words[2]);
80294
80368
  const status11 = await client.post("/api/apps/backups", { appId });
80295
80369
  print2({ context, args, value: status11, text: backupsText({ name: name3, status: status11 }) });
80296
80370
  };
80297
- var restore = async ({ context, args, open: open5 }) => {
80371
+ var restore = async ({ context, args, open: open6 }) => {
80298
80372
  const to = flagText({ args, name: "to" });
80299
80373
  const undo = flagText({ args, name: "undo" });
80300
80374
  if (Boolean(to) === Boolean(undo)) {
80301
80375
  throw new CliUsageError("Usage: laze app restore [app] --to <ISO time> | --undo <restore-id>");
80302
80376
  }
80303
- const { client, appId, name: name3 } = await open5(args.words[2]);
80377
+ const { client, appId, name: name3 } = await open6(args.words[2]);
80304
80378
  const done = await client.post("/api/apps/backups/restore", {
80305
80379
  appId,
80306
80380
  ...to ? { to } : { undo }
@@ -80326,16 +80400,16 @@ function usersText({ name: name3, users: users2 }) {
80326
80400
  return `${name3}'s app users:
80327
80401
  ${lines2.join("")}`;
80328
80402
  }
80329
- var users = async ({ context, args, open: open5 }) => {
80330
- const { client, appId, name: name3 } = await open5(args.words[2]);
80403
+ var users = async ({ context, args, open: open6 }) => {
80404
+ const { client, appId, name: name3 } = await open6(args.words[2]);
80331
80405
  const listed = await client.post("/api/apps/users", { appId });
80332
80406
  print2({ context, args, value: listed, text: usersText({ name: name3, users: listed }) });
80333
80407
  };
80334
80408
  function blocking(blocked) {
80335
- return async ({ context, args, open: open5 }) => {
80409
+ return async ({ context, args, open: open6 }) => {
80336
80410
  const verb = blocked ? "block-user" : "unblock-user";
80337
80411
  const { app: app2, word: word3 } = appAndWord({ args, usage: `Usage: laze app ${verb} [app] <user-id>` });
80338
- const { client, appId, name: name3 } = await open5(app2);
80412
+ const { client, appId, name: name3 } = await open6(app2);
80339
80413
  const listed = await client.post("/api/apps/users/block", {
80340
80414
  appId,
80341
80415
  userId: word3,
@@ -80344,16 +80418,16 @@ function blocking(blocked) {
80344
80418
  print2({ context, args, value: listed, text: usersText({ name: name3, users: listed }) });
80345
80419
  };
80346
80420
  }
80347
- var deleteUser = async ({ context, args, open: open5 }) => {
80421
+ var deleteUser = async ({ context, args, open: open6 }) => {
80348
80422
  const { app: app2, word: word3 } = appAndWord({ args, usage: "Usage: laze app delete-user [app] <user-id>" });
80349
- const { client, appId, name: name3 } = await open5(app2);
80423
+ const { client, appId, name: name3 } = await open6(app2);
80350
80424
  const gone = await client.post("/api/apps/users/delete", { appId, userId: word3 });
80351
80425
  const text3 = `Deleted ${gone.userId} from ${name3} with the ${gone.removedRecords.toString()} records they owned.
80352
80426
  `;
80353
80427
  print2({ context, args, value: gone, text: text3 });
80354
80428
  };
80355
80429
  var appManageCommands = {
80356
- rename: rename4,
80430
+ rename: rename2,
80357
80431
  archive,
80358
80432
  unarchive,
80359
80433
  delete: remove,
@@ -80422,10 +80496,10 @@ async function appPinCommand({
80422
80496
  context,
80423
80497
  args,
80424
80498
  verb,
80425
- open: open5
80499
+ open: open6
80426
80500
  }) {
80427
80501
  const channel = flagText({ args, name: "channel" });
80428
- const { client, appId, name: name3 } = await open5();
80502
+ const { client, appId, name: name3 } = await open6();
80429
80503
  const role2 = verb === "pin" ? pinRoleOf(args) : void 0;
80430
80504
  const listed = await client.post(`/api/apps/${verb}`, {
80431
80505
  appId,
@@ -80459,9 +80533,9 @@ async function appPinsCommand({
80459
80533
 
80460
80534
  // src/services/app-script-check.service.ts
80461
80535
  import { execFile } from "node:child_process";
80462
- import { mkdtemp, rm as rm9, writeFile as writeFile17 } from "node:fs/promises";
80536
+ import { mkdtemp, rm as rm10, writeFile as writeFile4 } from "node:fs/promises";
80463
80537
  import { tmpdir } from "node:os";
80464
- import { join as join20 } from "node:path";
80538
+ import { join as join21 } from "node:path";
80465
80539
  import { promisify } from "node:util";
80466
80540
  var run2 = promisify(execFile);
80467
80541
  var MODULE_SYNTAX = /^\s*(import|export)\s/m;
@@ -80490,12 +80564,12 @@ async function scriptErrorsOf({
80490
80564
  const unknown2 = unknownCollectionsOf({ files: files2, collections });
80491
80565
  const scripts = files2.flatMap(scriptsOf);
80492
80566
  if (scripts.length === 0) return unknown2;
80493
- const dir = await mkdtemp(join20(tmpdir(), "laze-app-check-"));
80567
+ const dir = await mkdtemp(join21(tmpdir(), "laze-app-check-"));
80494
80568
  try {
80495
80569
  const errors = await Promise.all(
80496
80570
  scripts.map(async (script, index) => {
80497
- const file4 = join20(dir, `${index}.${script.module ? "mjs" : "cjs"}`);
80498
- await writeFile17(file4, script.code);
80571
+ const file4 = join21(dir, `${index}.${script.module ? "mjs" : "cjs"}`);
80572
+ await writeFile4(file4, script.code);
80499
80573
  try {
80500
80574
  await run2(process.execPath, ["--check", file4]);
80501
80575
  return null;
@@ -80507,14 +80581,14 @@ async function scriptErrorsOf({
80507
80581
  );
80508
80582
  return [...errors.filter((error63) => error63 !== null), ...unknown2];
80509
80583
  } finally {
80510
- await rm9(dir, { recursive: true, force: true });
80584
+ await rm10(dir, { recursive: true, force: true });
80511
80585
  }
80512
80586
  }
80513
80587
 
80514
80588
  // src/services/app-serve.service.ts
80515
- import { readFile as readFile21, stat as stat8 } from "node:fs/promises";
80589
+ import { readFile as readFile14, stat as stat9 } from "node:fs/promises";
80516
80590
  import { createServer } from "node:http";
80517
- import { extname as extname2, join as join21, normalize, sep as sep2 } from "node:path";
80591
+ import { extname as extname2, join as join22, normalize, sep as sep2 } from "node:path";
80518
80592
  var TYPES2 = {
80519
80593
  ".html": "text/html; charset=utf-8",
80520
80594
  ".js": "text/javascript; charset=utf-8",
@@ -80565,13 +80639,13 @@ async function staticFile({
80565
80639
  if (clean.startsWith("..") || hidden) {
80566
80640
  return json2({ response, status: 404, value: { code: "not_found", message: "Not found" } });
80567
80641
  }
80568
- const candidates = [join21(folder, clean), join21(folder, clean, "index.html")];
80569
- if (!extname2(clean)) candidates.push(join21(folder, "index.html"));
80642
+ const candidates = [join22(folder, clean), join22(folder, clean, "index.html")];
80643
+ if (!extname2(clean)) candidates.push(join22(folder, "index.html"));
80570
80644
  for (const target of candidates) {
80571
- const info = await stat8(target).catch(() => void 0);
80645
+ const info = await stat9(target).catch(() => void 0);
80572
80646
  if (!info?.isFile()) continue;
80573
80647
  const type = TYPES2[extname2(target).toLowerCase()] ?? "application/octet-stream";
80574
- const body = await readFile21(target);
80648
+ const body = await readFile14(target);
80575
80649
  if (extname2(target) === ".html") {
80576
80650
  return send2({ response, status: 200, type, body: withServeThemeScript(body.toString()) });
80577
80651
  }
@@ -80717,26 +80791,26 @@ function print4({
80717
80791
  context.out(args.flags.json ? `${JSON.stringify(value, null, 2)}
80718
80792
  ` : text3);
80719
80793
  }
80720
- async function add({ context, args, open: open5, word: word3 }) {
80794
+ async function add({ context, args, open: open6, word: word3 }) {
80721
80795
  const prompt = flagText({ args, name: "prompt" }).trim();
80722
80796
  if (!prompt) throw new CliUsageError("--prompt says what the agent does with the records");
80723
80797
  const body = { collection: word3, on: onOf(args), where: whereOf3(args), prompt };
80724
- const { client, appId, name: name3 } = await open5();
80798
+ const { client, appId, name: name3 } = await open6();
80725
80799
  const trigger = await client.post("/api/apps/triggers/add", { appId, ...body });
80726
80800
  const text3 = `Added a trigger on ${name3}:
80727
80801
  ${triggerLine(trigger)}Matching changes to ${word3} records wake ${trigger.agentName} in ${trigger.channelName}.
80728
80802
  `;
80729
80803
  print4({ context, args, value: trigger, text: text3 });
80730
80804
  }
80731
- async function list({ context, args, open: open5 }) {
80732
- const { client, appId, name: name3 } = await open5();
80805
+ async function list({ context, args, open: open6 }) {
80806
+ const { client, appId, name: name3 } = await open6();
80733
80807
  const listed = await client.post("/api/apps/triggers", { appId });
80734
80808
  const text3 = listed.triggers.length === 0 ? `${name3} has no triggers. laze app trigger add <collection> adds one.
80735
80809
  ` : listed.triggers.map(triggerLine).join("");
80736
80810
  print4({ context, args, value: listed, text: text3 });
80737
80811
  }
80738
- async function setPaused({ context, args, open: open5, word: word3, paused }) {
80739
- const { client, appId } = await open5();
80812
+ async function setPaused({ context, args, open: open6, word: word3, paused }) {
80813
+ const { client, appId } = await open6();
80740
80814
  const trigger = await client.post("/api/apps/triggers/pause", {
80741
80815
  appId,
80742
80816
  triggerId: word3,
@@ -80744,8 +80818,8 @@ async function setPaused({ context, args, open: open5, word: word3, paused }) {
80744
80818
  });
80745
80819
  print4({ context, args, value: trigger, text: triggerLine(trigger) });
80746
80820
  }
80747
- async function remove2({ context, args, open: open5, word: word3 }) {
80748
- const { client, appId } = await open5();
80821
+ async function remove2({ context, args, open: open6, word: word3 }) {
80822
+ const { client, appId } = await open6();
80749
80823
  await client.post("/api/apps/triggers/remove", { appId, triggerId: word3 });
80750
80824
  print4({ context, args, value: { removed: word3 }, text: `Removed trigger ${word3}.
80751
80825
  ` });
@@ -80753,14 +80827,14 @@ async function remove2({ context, args, open: open5, word: word3 }) {
80753
80827
  async function appTrigger({
80754
80828
  context,
80755
80829
  args,
80756
- open: open5
80830
+ open: open6
80757
80831
  }) {
80758
80832
  const [, , verb, word3] = args.words;
80759
- if (verb === "list") return list({ context, args, open: open5 });
80833
+ if (verb === "list") return list({ context, args, open: open6 });
80760
80834
  const known = verb === "add" || verb === "pause" || verb === "resume" || verb === "remove";
80761
80835
  if (known && !word3) throw new CliUsageError(USAGE4);
80762
80836
  if (known && word3) {
80763
- const run4 = { context, args, open: open5, word: word3 };
80837
+ const run4 = { context, args, open: open6, word: word3 };
80764
80838
  if (verb === "add") return add(run4);
80765
80839
  if (verb === "remove") return remove2(run4);
80766
80840
  return setPaused({ ...run4, paused: verb === "pause" });
@@ -80804,7 +80878,7 @@ async function turnTokenOf2({
80804
80878
  const pinned = env.LAZE_TURN_TOKEN?.trim();
80805
80879
  if (pinned) return pinned;
80806
80880
  if (env.LAZE_TURN_FILE) {
80807
- return readFile22(env.LAZE_TURN_FILE, "utf8").then(
80881
+ return readFile15(env.LAZE_TURN_FILE, "utf8").then(
80808
80882
  (text3) => text3.trim(),
80809
80883
  () => ""
80810
80884
  );
@@ -80834,7 +80908,7 @@ function folderOf({ context, word: word3 }) {
80834
80908
  return resolve8(context.cwd, word3 ?? ".");
80835
80909
  }
80836
80910
  async function readManifest(folder) {
80837
- const text3 = await readFile22(join22(folder, APP_MANIFEST_FILE), "utf8").catch(() => void 0);
80911
+ const text3 = await readFile15(join23(folder, APP_MANIFEST_FILE), "utf8").catch(() => void 0);
80838
80912
  if (text3 === void 0) return void 0;
80839
80913
  const parsed = appManifestSchema.safeParse(JSON.parse(text3));
80840
80914
  if (!parsed.success) {
@@ -80869,7 +80943,7 @@ async function jsonFlag({
80869
80943
  }) {
80870
80944
  const raw = flagText({ args, name: name3 });
80871
80945
  if (!raw) return void 0;
80872
- const text3 = raw.startsWith("@") ? await readFile22(resolve8(context.cwd, raw.slice(1)), "utf8") : raw;
80946
+ const text3 = raw.startsWith("@") ? await readFile15(resolve8(context.cwd, raw.slice(1)), "utf8") : raw;
80873
80947
  try {
80874
80948
  return JSON.parse(text3);
80875
80949
  } catch {
@@ -80882,7 +80956,7 @@ async function listFiles(folder) {
80882
80956
  while (pending2.length > 0 && found.length <= MAX_FILES) {
80883
80957
  const current3 = pending2.pop() ?? folder;
80884
80958
  for (const entry of await readdir6(current3, { withFileTypes: true })) {
80885
- const path = join22(current3, entry.name);
80959
+ const path = join23(current3, entry.name);
80886
80960
  const rel = relative3(folder, path).split(sep3).join("/");
80887
80961
  if (isSkippedPath({ path: rel })) continue;
80888
80962
  if (entry.isDirectory()) pending2.push(path);
@@ -80918,12 +80992,12 @@ var appCreate = async ({ context, args }) => {
80918
80992
  ...template ? { template } : {}
80919
80993
  });
80920
80994
  const folder = resolve8(context.cwd, flagText({ args, name: "dir", fallback: app2.slug }));
80921
- await mkdir18(folder, { recursive: true });
80995
+ await mkdir6(folder, { recursive: true });
80922
80996
  const start2 = template ? await templateStart({ client, appId: app2.id, template }) : null;
80923
80997
  for (const file4 of start2?.files ?? []) {
80924
- const target = join22(folder, ...file4.path.split("/"));
80925
- await mkdir18(dirname18(target), { recursive: true });
80926
- await writeFile18(
80998
+ const target = join23(folder, ...file4.path.split("/"));
80999
+ await mkdir6(dirname14(target), { recursive: true });
81000
+ await writeFile5(
80927
81001
  target,
80928
81002
  file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
80929
81003
  );
@@ -80934,7 +81008,7 @@ var appCreate = async ({ context, args }) => {
80934
81008
  views: [...start2?.template.views ?? []],
80935
81009
  seed: { ...start2?.template.seed }
80936
81010
  };
80937
- await writeFile18(join22(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
81011
+ await writeFile5(join23(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
80938
81012
  `);
80939
81013
  const where = relative3(context.cwd, folder) || ".";
80940
81014
  print5({
@@ -81006,7 +81080,7 @@ var appPush = async ({ context, args }) => {
81006
81080
  paths.map(
81007
81081
  async (path) => buildFileOf({
81008
81082
  path: relative3(folder, path).split(sep3).join("/"),
81009
- bytes: await readFile22(path)
81083
+ bytes: await readFile15(path)
81010
81084
  })
81011
81085
  )
81012
81086
  );
@@ -81076,7 +81150,7 @@ var appWrite = async ({ context, args }) => {
81076
81150
  const path = resolve8(context.cwd, word3);
81077
81151
  const { bytes: _bytes, ...file4 } = buildFileOf({
81078
81152
  path: relative3(folder, path).split(sep3).join("/"),
81079
- bytes: await readFile22(path)
81153
+ bytes: await readFile15(path)
81080
81154
  });
81081
81155
  return file4;
81082
81156
  })
@@ -81203,9 +81277,9 @@ var appPull = async ({ context, args }) => {
81203
81277
  );
81204
81278
  }
81205
81279
  for (const file4 of pulled.files) {
81206
- const target = join22(folder, ...file4.path.split("/"));
81207
- await mkdir18(dirname18(target), { recursive: true });
81208
- await writeFile18(
81280
+ const target = join23(folder, ...file4.path.split("/"));
81281
+ await mkdir6(dirname14(target), { recursive: true });
81282
+ await writeFile5(
81209
81283
  target,
81210
81284
  file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
81211
81285
  );
@@ -81222,7 +81296,7 @@ var appPull = async ({ context, args }) => {
81222
81296
  ])
81223
81297
  )
81224
81298
  };
81225
- await writeFile18(join22(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
81299
+ await writeFile5(join23(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
81226
81300
  `);
81227
81301
  const names = pulled.collections.map((collection) => collection.name);
81228
81302
  const where = relative3(context.cwd, folder) || ".";
@@ -81529,7 +81603,7 @@ var appExport = async ({ context, args }) => {
81529
81603
  const out = flagText({ args, name: "out" });
81530
81604
  if (!out) return context.out(exported.body);
81531
81605
  const target = resolve8(context.cwd, out);
81532
- await writeFile18(target, exported.body);
81606
+ await writeFile5(target, exported.body);
81533
81607
  context.out(`Wrote ${exported.rows} records to ${relative3(context.cwd, target)}
81534
81608
  `);
81535
81609
  };
@@ -81537,7 +81611,7 @@ var appImport = async ({ context, args }) => {
81537
81611
  const words = args.words.slice(2);
81538
81612
  const [named, collection, file4] = words.length >= 3 ? words : [void 0, ...words];
81539
81613
  if (!collection || !file4) throw new CliUsageError(USAGE5);
81540
- const csv = await readFile22(resolve8(context.cwd, file4), "utf8").catch(() => {
81614
+ const csv = await readFile15(resolve8(context.cwd, file4), "utf8").catch(() => {
81541
81615
  throw new CliUsageError(`Cannot read ${file4}`);
81542
81616
  });
81543
81617
  const scoped = named ? { ...args, flags: { ...args.flags, app: named } } : args;
@@ -81555,7 +81629,7 @@ var appImport = async ({ context, args }) => {
81555
81629
  });
81556
81630
  const refusedOut = flagText({ args, name: "refused" });
81557
81631
  if (refusedOut && result2.refusedCsv) {
81558
- await writeFile18(resolve8(context.cwd, refusedOut), result2.refusedCsv);
81632
+ await writeFile5(resolve8(context.cwd, refusedOut), result2.refusedCsv);
81559
81633
  }
81560
81634
  const fitting = result2.rows - result2.refused.length;
81561
81635
  const skipped = result2.refused.slice(0, 20).map((row) => ` line ${row.line}: ${row.reason}
@@ -81951,7 +82025,7 @@ async function app({ context, args }) {
81951
82025
  import { hostname as hostname6 } from "node:os";
81952
82026
 
81953
82027
  // src/rules/machine-proof.rules.ts
81954
- import { createHash as createHash5, randomBytes } from "node:crypto";
82028
+ import { createHash as createHash5, randomBytes as randomBytes2 } from "node:crypto";
81955
82029
  var b64url3 = (bytes) => Buffer.from(bytes).toString("base64url");
81956
82030
  function thumbprintOf({ jwk }) {
81957
82031
  const canonical = JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y });
@@ -81968,16 +82042,16 @@ function machineProofOf({
81968
82042
  method,
81969
82043
  url: url2,
81970
82044
  credential,
81971
- nowMs,
82045
+ nowMs: nowMs2,
81972
82046
  tailscaleNodeId,
81973
- jti = b64url3(randomBytes(18))
82047
+ jti = b64url3(randomBytes2(18))
81974
82048
  }) {
81975
82049
  const header = b64url3(JSON.stringify({ typ: "dpop+jwt", alg: "ES256", jwk }));
81976
82050
  const payload = b64url3(
81977
82051
  JSON.stringify({
81978
82052
  htm: method.toUpperCase(),
81979
82053
  htu: url2,
81980
- iat: Math.floor(nowMs / 1e3),
82054
+ iat: Math.floor(nowMs2 / 1e3),
81981
82055
  jti,
81982
82056
  ath: b64url3(createHash5("sha256").update(credential).digest()),
81983
82057
  lz_tier: tier,
@@ -82395,14 +82469,14 @@ async function billing({ context, args }) {
82395
82469
  }
82396
82470
 
82397
82471
  // src/services/browser-commands.service.ts
82398
- import { randomBytes as randomBytes2 } from "node:crypto";
82399
- import { mkdir as mkdir21, readFile as readFile24, writeFile as writeFile21 } from "node:fs/promises";
82400
- import { dirname as dirname20, join as join25 } from "node:path";
82472
+ import { randomBytes as randomBytes3 } from "node:crypto";
82473
+ import { readFile as readFile17 } from "node:fs/promises";
82474
+ import { dirname as dirname16, join as join26 } from "node:path";
82401
82475
 
82402
82476
  // src/services/browser-tab-commands.service.ts
82403
- import { mkdir as mkdir20, writeFile as writeFile20 } from "node:fs/promises";
82477
+ import { mkdir as mkdir7, writeFile as writeFile6 } from "node:fs/promises";
82404
82478
  import { tmpdir as tmpdir3 } from "node:os";
82405
- import { join as join24 } from "node:path";
82479
+ import { join as join25 } from "node:path";
82406
82480
 
82407
82481
  // src/rules/browser-login.rules.ts
82408
82482
  var PASSWORD_NAME = /pass|pwd/i;
@@ -82433,9 +82507,9 @@ function loginValuesOf({
82433
82507
 
82434
82508
  // src/services/vault-commands.service.ts
82435
82509
  import { createHash as createHash6 } from "node:crypto";
82436
- import { mkdir as mkdir19, readFile as readFile23, rm as rm10, writeFile as writeFile19 } from "node:fs/promises";
82510
+ import { readFile as readFile16, rm as rm11 } from "node:fs/promises";
82437
82511
  import { hostname as hostname7, tmpdir as tmpdir2 } from "node:os";
82438
- import { dirname as dirname19, join as join23 } from "node:path";
82512
+ import { dirname as dirname15, join as join24 } from "node:path";
82439
82513
 
82440
82514
  // src/rules/vault-session.rules.ts
82441
82515
  function vaultSessionOf({
@@ -82500,7 +82574,7 @@ async function turnTokenOf3({
82500
82574
  if (pinned) return pinned;
82501
82575
  if (!turnFile) throw new CliUsageError(`${command} works only during an agent's turn`);
82502
82576
  try {
82503
- return (await readFile23(turnFile, "utf8")).trim();
82577
+ return (await readFile16(turnFile, "utf8")).trim();
82504
82578
  } catch {
82505
82579
  throw new CliUsageError(`${command} works only during an agent's turn`);
82506
82580
  }
@@ -82511,24 +82585,20 @@ function runKeyPathOf({
82511
82585
  profile = ""
82512
82586
  }) {
82513
82587
  const name3 = createHash6("sha256").update(connection).digest("hex");
82514
- const base = turnFile ? dirname19(turnFile) : join23(tmpdir2(), "laze-vault", profile);
82515
- return join23(base, "vault-run-keys", `${name3}.json`);
82588
+ const base = turnFile ? dirname15(turnFile) : join24(tmpdir2(), "laze-vault", profile);
82589
+ return join24(base, "vault-run-keys", `${name3}.json`);
82516
82590
  }
82517
82591
  async function runKeyAt({ path }) {
82518
- const saved3 = await readFile23(path, "utf8").then(
82519
- (text3) => JSON.parse(text3),
82520
- () => void 0
82521
- );
82592
+ const saved3 = await readStateJson({
82593
+ path
82594
+ });
82522
82595
  if (saved3 && typeof saved3.publicKey === "string" && saved3.privateKey) {
82523
82596
  const privateKey = await globalThis.crypto.subtle.importKey("jwk", saved3.privateKey, P2562, false, ["deriveBits"]).catch(() => void 0);
82524
82597
  if (privateKey) return { privateKey, publicKey: saved3.publicKey };
82525
82598
  }
82526
82599
  const fresh = await generateEcdhKeys();
82527
82600
  const jwk = await globalThis.crypto.subtle.exportKey("jwk", fresh.privateKey);
82528
- await mkdir19(dirname19(path), { recursive: true, mode: 448 });
82529
- await writeFile19(path, JSON.stringify({ publicKey: fresh.publicKey, privateKey: jwk }), {
82530
- mode: 384
82531
- });
82601
+ await writeStateJson({ path, value: { publicKey: fresh.publicKey, privateKey: jwk } });
82532
82602
  return fresh;
82533
82603
  }
82534
82604
  function connectionRefused(error63) {
@@ -82602,12 +82672,12 @@ async function envOf({
82602
82672
  });
82603
82673
  return { ...release2.env, ...sealed };
82604
82674
  }
82605
- function deadlineOf({ args, nowMs }) {
82675
+ function deadlineOf({ args, nowMs: nowMs2 }) {
82606
82676
  const wait = flagText({ args, name: "wait" }) || (args.flags.wait === true ? args.words[3] : "");
82607
82677
  if (!wait) return Infinity;
82608
82678
  if (!(Number(wait) >= 0)) throw new CliUsageError(`--wait takes a number of seconds
82609
82679
  ${USAGE6}`);
82610
- return nowMs + Number(wait) * 1e3;
82680
+ return nowMs2 + Number(wait) * 1e3;
82611
82681
  }
82612
82682
  async function untilAnswered({
82613
82683
  context,
@@ -82633,10 +82703,10 @@ async function untilAnswered({
82633
82703
  }
82634
82704
  function leaseHolds({
82635
82705
  release: release2,
82636
- nowMs
82706
+ nowMs: nowMs2
82637
82707
  }) {
82638
82708
  const ends = release2.sealed?.leaseEndsAt;
82639
- return ends !== void 0 && Temporal3.Instant.from(ends).epochMilliseconds > nowMs;
82709
+ return ends !== void 0 && Temporal3.Instant.from(ends).epochMilliseconds > nowMs2;
82640
82710
  }
82641
82711
  async function vaultRelease({
82642
82712
  context,
@@ -82690,13 +82760,13 @@ async function settled({
82690
82760
  }) {
82691
82761
  if (release2 === "capped") return { exitCode: 75 };
82692
82762
  if (release2.outcome === "deny") {
82693
- await rm10(keyPath, { force: true });
82763
+ await rm11(keyPath, { force: true });
82694
82764
  context.err(`${release2.message}
82695
82765
  `);
82696
82766
  return { exitCode: release2.exitCode || 1 };
82697
82767
  }
82698
82768
  const values = await envOf({ release: release2, run: run4 });
82699
- if (!leaseHolds({ release: release2, nowMs: context.nowMs() })) await rm10(keyPath, { force: true });
82769
+ if (!leaseHolds({ release: release2, nowMs: context.nowMs() })) await rm11(keyPath, { force: true });
82700
82770
  if (release2.message) context.err(`${release2.message}
82701
82771
  `);
82702
82772
  return { env: values };
@@ -83039,12 +83109,12 @@ ${page}${shot}`;
83039
83109
  async function savedScreenshot({
83040
83110
  tabId,
83041
83111
  data,
83042
- nowMs
83112
+ nowMs: nowMs2
83043
83113
  }) {
83044
- const folder = join24(tmpdir3(), "laze-browser");
83045
- await mkdir20(folder, { recursive: true, mode: 448 });
83046
- const path = join24(folder, `${tabId.replace(/[^a-zA-Z0-9_-]/g, "_")}-login-${nowMs}.jpg`);
83047
- await writeFile20(path, Buffer.from(data, "base64"), { mode: 384 });
83114
+ const folder = join25(tmpdir3(), "laze-browser");
83115
+ await mkdir7(folder, { recursive: true, mode: 448 });
83116
+ const path = join25(folder, `${tabId.replace(/[^a-zA-Z0-9_-]/g, "_")}-login-${nowMs2}.jpg`);
83117
+ await writeFile6(path, Buffer.from(data, "base64"), { mode: 384 });
83048
83118
  return path;
83049
83119
  }
83050
83120
  async function shareTab({ args, client, channel, print: print9 }) {
@@ -83520,7 +83590,7 @@ async function turnTokenOf4({
83520
83590
  const pinned = env.LAZE_TURN_TOKEN?.trim();
83521
83591
  if (pinned) return pinned;
83522
83592
  if (env.LAZE_TURN_FILE) {
83523
- return readFile24(env.LAZE_TURN_FILE, "utf8").then(
83593
+ return readFile17(env.LAZE_TURN_FILE, "utf8").then(
83524
83594
  (text3) => text3.trim(),
83525
83595
  () => ""
83526
83596
  );
@@ -83610,7 +83680,7 @@ async function answering({
83610
83680
  }
83611
83681
  function bridgeStatePath({ context, machine: machine2 }) {
83612
83682
  const safe = machine2.replace(/[^a-zA-Z0-9_-]/g, "_");
83613
- return join25(dirname20(context.environment.configPath), "bridges", `${safe}.json`);
83683
+ return join26(dirname16(context.environment.configPath), "bridges", `${safe}.json`);
83614
83684
  }
83615
83685
  async function bridgePort({
83616
83686
  context,
@@ -83618,21 +83688,17 @@ async function bridgePort({
83618
83688
  access
83619
83689
  }) {
83620
83690
  const path = bridgeStatePath({ context, machine: machine2 });
83621
- const live = await readFile24(path, "utf8").then(
83622
- (text3) => JSON.parse(text3),
83623
- () => void 0
83624
- );
83691
+ const live = await readStateJson({ path });
83625
83692
  const target = { target: access.url, expiresAt: access.expiresAt };
83626
83693
  if (live && await retargetCdpBridge({ ...live, ...target })) return live.port;
83627
- const key = randomBytes2(24).toString("hex");
83694
+ const key = randomBytes3(24).toString("hex");
83628
83695
  const port = await launchCdpBridge({
83629
83696
  program: context.program,
83630
83697
  env: context.environment.inherited,
83631
83698
  key,
83632
83699
  ...target
83633
83700
  });
83634
- await mkdir21(dirname20(path), { recursive: true, mode: 448 });
83635
- await writeFile21(path, JSON.stringify({ port, key }), { mode: 384 });
83701
+ await writeStateJson({ path, value: { port, key } });
83636
83702
  return port;
83637
83703
  }
83638
83704
  async function bridge({ context }) {
@@ -84328,13 +84394,13 @@ async function channelSettings({ context, args }) {
84328
84394
  }
84329
84395
 
84330
84396
  // src/services/chat-actions-commands.service.ts
84331
- import { readFile as readFile25 } from "node:fs/promises";
84332
- import { basename as basename7, isAbsolute as isAbsolute2, relative as relative4, resolve as resolve10 } from "node:path";
84397
+ import { readFile as readFile18 } from "node:fs/promises";
84398
+ import { basename as basename8, isAbsolute as isAbsolute2, relative as relative4, resolve as resolve10 } from "node:path";
84333
84399
 
84334
84400
  // src/services/file-download.service.ts
84335
84401
  import { createWriteStream } from "node:fs";
84336
- import { mkdir as mkdir22, rename as rename5, rm as rm11, stat as stat9, truncate } from "node:fs/promises";
84337
- import { basename as basename6, dirname as dirname21, resolve as resolve9 } from "node:path";
84402
+ import { mkdir as mkdir8, rename as rename3, rm as rm12, stat as stat10, truncate } from "node:fs/promises";
84403
+ import { basename as basename7, dirname as dirname17, resolve as resolve9 } from "node:path";
84338
84404
  import { Readable, Transform } from "node:stream";
84339
84405
  import { pipeline } from "node:stream/promises";
84340
84406
  var NOT_READY_WAIT_MS = 5e3;
@@ -84362,7 +84428,7 @@ function nameFrom({ response, attachmentId }) {
84362
84428
  const encoded = /filename\*=UTF-8''([^;]+)/i.exec(header)?.[1];
84363
84429
  const plain3 = /filename="?([^";]+)"?/i.exec(header)?.[1];
84364
84430
  const name3 = encoded ? decodeURIComponent(encoded) : plain3;
84365
- const safe = name3 ? basename6(name3.replaceAll("\\", "/")) : "";
84431
+ const safe = name3 ? basename7(name3.replaceAll("\\", "/")) : "";
84366
84432
  return safe && safe !== "." && safe !== ".." ? safe : attachmentId;
84367
84433
  }
84368
84434
  function limited({ start: start2 }) {
@@ -84382,7 +84448,7 @@ function totalOf({ response, start: start2 }) {
84382
84448
  if (length === null) return void 0;
84383
84449
  return Number(length) + (response.status === 206 ? start2 : 0);
84384
84450
  }
84385
- var sizeOnDisk = (path) => stat9(path).then(
84451
+ var sizeOnDisk = (path) => stat10(path).then(
84386
84452
  (found) => found.size,
84387
84453
  () => 0
84388
84454
  );
@@ -84454,17 +84520,17 @@ async function downloadFile({
84454
84520
  out
84455
84521
  }) {
84456
84522
  const asked = out ? resolve9(context.cwd, out) : void 0;
84457
- const part = resolve9(asked ? dirname21(asked) : context.cwd, `.${attachmentId}.part`);
84458
- await mkdir22(dirname21(part), { recursive: true });
84523
+ const part = resolve9(asked ? dirname17(asked) : context.cwd, `.${attachmentId}.part`);
84524
+ await mkdir8(dirname17(part), { recursive: true });
84459
84525
  const named = await fetchWhole({ context, client, attachmentId, part, out }).catch(
84460
84526
  async (error63) => {
84461
- await rm11(part, { force: true });
84527
+ await rm12(part, { force: true });
84462
84528
  if (!isDiskError(error63)) throw error63;
84463
84529
  throw new CliUsageError(`Could not write ${attachmentId} to disk: ${String(error63)}`);
84464
84530
  }
84465
84531
  );
84466
84532
  const path = asked ?? resolve9(context.cwd, named ?? attachmentId);
84467
- await rename5(part, path);
84533
+ await rename3(part, path);
84468
84534
  return { path, sizeBytes: await sizeOnDisk(path) };
84469
84535
  }
84470
84536
 
@@ -84722,11 +84788,11 @@ var files = async ({ context, args, client }) => {
84722
84788
  };
84723
84789
  function uploadNameOf({ cwd, path }) {
84724
84790
  const inside = relative4(cwd, path);
84725
- return inside && !inside.startsWith("..") && !isAbsolute2(inside) ? inside : basename7(path);
84791
+ return inside && !inside.startsWith("..") && !isAbsolute2(inside) ? inside : basename8(path);
84726
84792
  }
84727
84793
  var fileUpload = async ({ context, args, client }) => {
84728
84794
  const path = resolve10(context.cwd, wordAt(args, 3));
84729
- const bytes = new Uint8Array(await readFile25(path));
84795
+ const bytes = new Uint8Array(await readFile18(path));
84730
84796
  const answer6 = await uploadFile({
84731
84797
  context,
84732
84798
  client,
@@ -84910,7 +84976,7 @@ async function chatActions({
84910
84976
  }
84911
84977
 
84912
84978
  // src/services/claude-monitor.service.ts
84913
- import { readFile as readFile26, rm as rm12 } from "node:fs/promises";
84979
+ import { rm as rm13 } from "node:fs/promises";
84914
84980
  var MONITOR_IDLE_MS = 3e4;
84915
84981
  var MONITOR_OUTRANKED_MS = 3e3;
84916
84982
  async function deliverOnce({
@@ -84978,7 +85044,7 @@ async function monitorRound(turn) {
84978
85044
  async function release({ context, profile }) {
84979
85045
  const lock = statePathOf({ context, kind: "waiters", profile });
84980
85046
  if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
84981
- await rm12(lock, { force: true });
85047
+ await rm13(lock, { force: true });
84982
85048
  }
84983
85049
  async function monitorHook({ context, args }) {
84984
85050
  const claudePid = await claudePidOf({ context });
@@ -85017,10 +85083,7 @@ async function monitorSessionOf({
85017
85083
  const fromEnv = sessionOf({ context, harness: "claude-code", sessionId });
85018
85084
  if (fromEnv || !claudePid) return fromEnv;
85019
85085
  const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
85020
- return readFile26(path, "utf8").then(
85021
- (text3) => JSON.parse(text3),
85022
- () => void 0
85023
- );
85086
+ return readStateJson({ path });
85024
85087
  }
85025
85088
 
85026
85089
  // ../../modules/compute/contract/src/browser-tab.ts
@@ -86796,7 +86859,12 @@ var openLoginTerminalDefinition = external_exports.object({
86796
86859
  });
86797
86860
  var openLoginTerminalInputSchema = openLoginTerminalDefinition;
86798
86861
  var loginTerminalDefinition = external_exports.discriminatedUnion("status", [
86799
- external_exports.object({ status: external_exports.literal("starting"), retryAfterSeconds: external_exports.number().int().positive() }),
86862
+ external_exports.object({
86863
+ status: external_exports.literal("starting"),
86864
+ retryAfterSeconds: external_exports.number().int().positive(),
86865
+ /** The computer is awake and only its link is coming back, e.g. after a deploy. */
86866
+ reconnecting: external_exports.boolean().optional()
86867
+ }),
86800
86868
  external_exports.object({
86801
86869
  status: external_exports.literal("ready"),
86802
86870
  /** The WebSocket path of the terminal, token included; add `cols` and `rows`. */
@@ -87008,9 +87076,9 @@ var restSettleComputerCopyInputDefinition = settleComputerCopyInputDefinition.om
87008
87076
  });
87009
87077
 
87010
87078
  // src/services/computer-copy-commands.service.ts
87011
- import { mkdtemp as mkdtemp2, open as open4, rm as rm13, stat as stat10 } from "node:fs/promises";
87079
+ import { mkdtemp as mkdtemp2, open as open5, rm as rm14, stat as stat11 } from "node:fs/promises";
87012
87080
  import { tmpdir as tmpdir4 } from "node:os";
87013
- import { basename as basename8, dirname as dirname22, resolve as resolve11 } from "node:path";
87081
+ import { basename as basename9, dirname as dirname18, resolve as resolve11 } from "node:path";
87014
87082
  var COMPUTER_COPY_USAGE = ` laze computer copy <path> --agent <agent> [--to <folder>] [--json]
87015
87083
  copy a local file or folder into your hosted agent's work folder
87016
87084
  (its owner only, up to 2 GiB packed); <folder> is relative to the
@@ -87025,8 +87093,8 @@ function stringFlag(args, name3) {
87025
87093
  function packingOf({ path, isDirectory }) {
87026
87094
  const contents = isDirectory && path.endsWith("/");
87027
87095
  const absolute = resolve11(path);
87028
- const name3 = basename8(absolute);
87029
- return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent: dirname22(absolute), entry: name3 };
87096
+ const name3 = basename9(absolute);
87097
+ return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent: dirname18(absolute), entry: name3 };
87030
87098
  }
87031
87099
  async function sendParts2({
87032
87100
  context,
@@ -87035,7 +87103,7 @@ async function sendParts2({
87035
87103
  }) {
87036
87104
  const { upload } = started;
87037
87105
  const parts = [];
87038
- const file4 = await open4(archive2, "r");
87106
+ const file4 = await open5(archive2, "r");
87039
87107
  try {
87040
87108
  for (const part of upload.parts) {
87041
87109
  const length = part.end - part.start;
@@ -87071,7 +87139,7 @@ async function copy({ context, args }) {
87071
87139
  ${COMPUTER_COPY_USAGE}`);
87072
87140
  const to = stringFlag(args, "to") ?? ".";
87073
87141
  const full = resolve11(context.cwd, path);
87074
- const found = await stat10(full).catch(() => void 0);
87142
+ const found = await stat11(full).catch(() => void 0);
87075
87143
  if (!found) throw new CliUsageError(`${path} does not exist`);
87076
87144
  const { name: name3, parent, entry } = packingOf({
87077
87145
  path: path.endsWith("/") ? `${full}/` : full,
@@ -87085,7 +87153,7 @@ ${COMPUTER_COPY_USAGE}`);
87085
87153
  env: { COPYFILE_DISABLE: "1" }
87086
87154
  });
87087
87155
  if (code !== 0) throw new CliUsageError(`tar could not pack ${path} (exit ${code})`);
87088
- const sizeBytes = (await stat10(archive2)).size;
87156
+ const sizeBytes = (await stat11(archive2)).size;
87089
87157
  if (sizeBytes > COMPUTER_COPY_MAX_BYTES)
87090
87158
  throw new CliUsageError(`${path} packs to ${mb(sizeBytes)}; a copy holds at most 2 GiB`);
87091
87159
  const client = await computeClient({ context, args });
@@ -87109,7 +87177,7 @@ It lands before ${done.agentName}'s next turn.
87109
87177
  `
87110
87178
  );
87111
87179
  } finally {
87112
- await rm13(dir, { recursive: true, force: true });
87180
+ await rm14(dir, { recursive: true, force: true });
87113
87181
  }
87114
87182
  }
87115
87183
 
@@ -87400,11 +87468,11 @@ async function computer({ context, args }) {
87400
87468
  }
87401
87469
 
87402
87470
  // src/services/connect-commands.service.ts
87403
- import { readFile as readFile28 } from "node:fs/promises";
87471
+ import { readFile as readFile20 } from "node:fs/promises";
87404
87472
 
87405
87473
  // src/services/mcp-gateway.service.ts
87406
- import { mkdir as mkdir23, readFile as readFile27, writeFile as writeFile22 } from "node:fs/promises";
87407
- import { basename as basename9, join as join26, resolve as resolve12 } from "node:path";
87474
+ import { mkdir as mkdir9, readFile as readFile19, writeFile as writeFile7 } from "node:fs/promises";
87475
+ import { basename as basename10, join as join27, resolve as resolve12 } from "node:path";
87408
87476
  import { createInterface as createInterface3 } from "node:readline";
87409
87477
  var TURN_HEADER = "x-laze-turn";
87410
87478
  function serveMcpGateway({
@@ -87447,7 +87515,7 @@ async function relayMcpLines({
87447
87515
  const github3 = env.LAZE_GITHUB_CONNECTION;
87448
87516
  const url2 = `${profile.url.replace(/\/+$/, "")}/api/connectors/mcp/${encodeURIComponent(profile.agentId)}${github3 ? `?github=${encodeURIComponent(github3)}` : ""}`;
87449
87517
  const turnFile = env.LAZE_TURN_FILE;
87450
- const readTurn = () => readFile27(turnFile, "utf8").then(
87518
+ const readTurn = () => readFile19(turnFile, "utf8").then(
87451
87519
  (text3) => text3.trim(),
87452
87520
  () => ""
87453
87521
  );
@@ -87485,14 +87553,14 @@ var SAVES_FILES_META = "laze/files";
87485
87553
  var FILE_META = "laze/file";
87486
87554
  function safeName(name3, fallback) {
87487
87555
  const printable = name3.replace(new RegExp("\\p{Cc}", "gu"), "");
87488
- const last = basename9(printable.replaceAll("\\", "/"));
87556
+ const last = basename10(printable.replaceAll("\\", "/"));
87489
87557
  return last && last !== "." && last !== ".." ? last : fallback;
87490
87558
  }
87491
87559
  async function saveMailFile({ root, file: file4 }) {
87492
- const dir = join26(root, safeName(file4.messageId, "message"));
87493
- const path = join26(dir, safeName(file4.fileName, "attachment"));
87494
- await mkdir23(dir, { recursive: true });
87495
- await writeFile22(path, Buffer.from(file4.base64, "base64"));
87560
+ const dir = join27(root, safeName(file4.messageId, "message"));
87561
+ const path = join27(dir, safeName(file4.fileName, "attachment"));
87562
+ await mkdir9(dir, { recursive: true });
87563
+ await writeFile7(path, Buffer.from(file4.base64, "base64"));
87496
87564
  return path;
87497
87565
  }
87498
87566
  function markSavesFiles(line) {
@@ -87609,7 +87677,7 @@ async function turnOf({ context }) {
87609
87677
  const pinned = env.LAZE_TURN_TOKEN?.trim();
87610
87678
  if (pinned) return pinned;
87611
87679
  const file4 = env.LAZE_TURN_FILE;
87612
- const turn = file4 ? await readFile28(file4, "utf8").then(
87680
+ const turn = file4 ? await readFile20(file4, "utf8").then(
87613
87681
  (text3) => text3.trim(),
87614
87682
  () => ""
87615
87683
  ) : "";
@@ -87667,11 +87735,11 @@ async function connect({
87667
87735
  }
87668
87736
 
87669
87737
  // src/services/connector-commands.service.ts
87670
- import { readFile as readFile30 } from "node:fs/promises";
87738
+ import { readFile as readFile22 } from "node:fs/promises";
87671
87739
  import { resolve as resolve13 } from "node:path";
87672
87740
 
87673
87741
  // src/services/vault-keychain-commands.service.ts
87674
- import { readFile as readFile29 } from "node:fs/promises";
87742
+ import { readFile as readFile21 } from "node:fs/promises";
87675
87743
 
87676
87744
  // src/rules/vault-input.rules.ts
87677
87745
  function secondsOf(text3) {
@@ -88089,7 +88157,7 @@ async function secretText({ context, args }) {
88089
88157
  );
88090
88158
  }
88091
88159
  const file4 = flagText({ args, name: "from-file" });
88092
- const text3 = file4 ? await readFile29(file4, "utf8") : await context.readStdin();
88160
+ const text3 = file4 ? await readFile21(file4, "utf8") : await context.readStdin();
88093
88161
  const trimmed = text3.replace(/\r?\n$/, "");
88094
88162
  if (!trimmed.trim()) throw new CliUsageError("No value: pipe it on stdin or use --from-file.");
88095
88163
  return trimmed;
@@ -88103,7 +88171,7 @@ async function keychainOf2({ client, args }) {
88103
88171
  const me = await client.get("/api/agents/me");
88104
88172
  return { kind: "personal", ownerUserId: me.id };
88105
88173
  }
88106
- function settingsOf(args) {
88174
+ function settingsOf2(args) {
88107
88175
  const lease = flagText({ args, name: "lease" }) || flagText({ args, name: "max-lease" });
88108
88176
  const approvers = args.lists.approver;
88109
88177
  const everyUseAsks = yesNoOf({ args, name: "every-use-asks" });
@@ -88145,7 +88213,7 @@ var add3 = async ({ context, args }) => {
88145
88213
  name: name3,
88146
88214
  keychain: await keychainOf2({ client, args }),
88147
88215
  sensitivity: levelOf2(args) ?? "checked",
88148
- ...settingsOf(args),
88216
+ ...settingsOf2(args),
88149
88217
  secret
88150
88218
  });
88151
88219
  if (args.flags.json) return printJson4({ context, data: created });
@@ -88155,7 +88223,7 @@ var add3 = async ({ context, args }) => {
88155
88223
  );
88156
88224
  };
88157
88225
  var update = async ({ context, args }) => {
88158
- const settings3 = { ...settingsOf(args), ...deviceApprovalOf(args) };
88226
+ const settings3 = { ...settingsOf2(args), ...deviceApprovalOf(args) };
88159
88227
  const { client, profile } = await signedIn({ context, args });
88160
88228
  if (Object.keys(settings3).length === 0) throw new CliUsageError(VAULT_USAGE);
88161
88229
  const word3 = args.words[2];
@@ -88322,7 +88390,7 @@ async function keyText({ context, args }) {
88322
88390
  throw new CliUsageError("A key never goes in a flag: pipe it on stdin or use --from-file.");
88323
88391
  }
88324
88392
  const file4 = flagText({ args, name: "from-file" });
88325
- const text3 = file4 ? await readFile30(resolve13(context.cwd, file4), "utf8") : await context.readStdin();
88393
+ const text3 = file4 ? await readFile22(resolve13(context.cwd, file4), "utf8") : await context.readStdin();
88326
88394
  const trimmed = text3.trim();
88327
88395
  if (!trimmed) throw new CliUsageError("No key: pipe it on stdin or use --from-file.");
88328
88396
  return trimmed;
@@ -88643,7 +88711,7 @@ async function conversationDelete({ context, args }) {
88643
88711
  }
88644
88712
 
88645
88713
  // src/services/discord-commands.service.ts
88646
- import { readFile as readFile31 } from "node:fs/promises";
88714
+ import { readFile as readFile23 } from "node:fs/promises";
88647
88715
  import { resolve as resolve14 } from "node:path";
88648
88716
 
88649
88717
  // ../../modules/discord/contract/src/discord.ts
@@ -88965,7 +89033,7 @@ async function secretsOf({ context, args }) {
88965
89033
  const fromConnection = flagText({ args, name: "from-vault" });
88966
89034
  if (fromConnection) return { fromConnection };
88967
89035
  const file4 = flagText({ args, name: "from-file" });
88968
- const text3 = file4 ? await readFile31(resolve14(context.cwd, file4), "utf8") : await context.readStdin();
89036
+ const text3 = file4 ? await readFile23(resolve14(context.cwd, file4), "utf8") : await context.readStdin();
88969
89037
  const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
88970
89038
  if (lines2.length !== 2) {
88971
89039
  throw new CliUsageError(
@@ -89235,8 +89303,8 @@ var DOMAINS_USAGE = `Usage:
89235
89303
  var printJson5 = (context, data) => context.out(`${JSON.stringify(data, null, 2)}
89236
89304
  `);
89237
89305
  function printDomain(context, row) {
89238
- const join34 = row.autoJoin ? "auto-join on" : "auto-join off";
89239
- context.out(`${row.domain} ${join34}${row.enforced ? " single sign-on enforced" : ""}
89306
+ const join35 = row.autoJoin ? "auto-join on" : "auto-join off";
89307
+ context.out(`${row.domain} ${join35}${row.enforced ? " single sign-on enforced" : ""}
89240
89308
  `);
89241
89309
  }
89242
89310
  async function list4({ context, args }) {
@@ -89268,7 +89336,7 @@ async function domains({ context, args }) {
89268
89336
  }
89269
89337
 
89270
89338
  // src/services/emoji-commands.service.ts
89271
- import { readFile as readFile32 } from "node:fs/promises";
89339
+ import { readFile as readFile24 } from "node:fs/promises";
89272
89340
  import { resolve as resolve15 } from "node:path";
89273
89341
  var EMOJI_USAGE = `Usage:
89274
89342
  laze emoji list [--json] the workspace's custom emoji, aliases and who added each
@@ -89309,7 +89377,7 @@ async function addEmoji({ context, args, client }) {
89309
89377
  const file4 = wordAt4(args, 3);
89310
89378
  let bytes;
89311
89379
  try {
89312
- bytes = new Uint8Array(await readFile32(resolve15(context.cwd, file4)));
89380
+ bytes = new Uint8Array(await readFile24(resolve15(context.cwd, file4)));
89313
89381
  } catch {
89314
89382
  throw new CliUsageError(`Cannot read ${file4}.`);
89315
89383
  }
@@ -89625,7 +89693,7 @@ var ExternalChannelBannerSlot = externalUi.component("channel-banner");
89625
89693
  var ExternalSharingHooksToken = externalUi.hooks("sharing");
89626
89694
 
89627
89695
  // src/services/workspace-commands.service.ts
89628
- import { readFile as readFile33 } from "node:fs/promises";
89696
+ import { readFile as readFile25 } from "node:fs/promises";
89629
89697
  import { resolve as resolve16 } from "node:path";
89630
89698
  var ROLE_NAMES2 = {
89631
89699
  OWNER: "Owner",
@@ -89669,7 +89737,7 @@ async function mine2({ context, args }) {
89669
89737
  `).join("") || "No workspaces.\n"
89670
89738
  });
89671
89739
  }
89672
- async function rename6({ context, args }) {
89740
+ async function rename4({ context, args }) {
89673
89741
  const name3 = args.words.slice(2).join(" ").trim();
89674
89742
  if (!name3) throw new CliUsageError("Usage: laze workspace rename <name>");
89675
89743
  const { client } = await signedIn({ context, args });
@@ -89808,7 +89876,7 @@ var LOGO_USAGE = "Usage: laze workspace logo set <file.png|jpg|webp> | laze work
89808
89876
  async function readLogo({ context, file: file4 }) {
89809
89877
  let bytes;
89810
89878
  try {
89811
- bytes = new Uint8Array(await readFile33(resolve16(context.cwd, file4)));
89879
+ bytes = new Uint8Array(await readFile25(resolve16(context.cwd, file4)));
89812
89880
  } catch {
89813
89881
  throw new CliUsageError(`No file to read at ${file4}.`);
89814
89882
  }
@@ -89848,7 +89916,7 @@ var WORKSPACE_COMMANDS = {
89848
89916
  switch: switchTo,
89849
89917
  logo,
89850
89918
  mine: mine2,
89851
- rename: rename6,
89919
+ rename: rename4,
89852
89920
  create,
89853
89921
  leave,
89854
89922
  delete: scheduleDeletion,
@@ -90408,7 +90476,7 @@ async function agentFeedAccess({
90408
90476
  }
90409
90477
 
90410
90478
  // src/services/feed-commands.service.ts
90411
- import { readFile as readFile34 } from "node:fs/promises";
90479
+ import { readFile as readFile26 } from "node:fs/promises";
90412
90480
  import { resolve as resolve17 } from "node:path";
90413
90481
 
90414
90482
  // ../../modules/feed/contract/src/feed.delegate.ts
@@ -90730,6 +90798,11 @@ var feedViewerStateSchemaDefinition = external_exports.object({
90730
90798
  unread: external_exports.boolean(),
90731
90799
  /** Back from a snooze or a show-at date, not yet touched. */
90732
90800
  woke: external_exports.enum(["snooze", "show_at"]).nullable(),
90801
+ /** Why a woke card came back and who brought it; `by` is null on the reader's own snooze. */
90802
+ wake: external_exports.object({
90803
+ cause: external_exports.enum(["snooze", "show_at", "urgent_reply"]),
90804
+ by: feedAuthorSchema.nullable()
90805
+ }).optional(),
90733
90806
  snoozedUntil: external_exports.iso.datetime().nullable(),
90734
90807
  /** The agent that snoozed it for the person, when it was not the person. */
90735
90808
  snoozedBy: feedAuthorSchema.nullable(),
@@ -91500,7 +91573,7 @@ async function feedTurnOf({
91500
91573
  const read4 = async () => {
91501
91574
  const pinned = env.LAZE_TURN_TOKEN?.trim();
91502
91575
  if (pinned) return pinned;
91503
- if (env.LAZE_TURN_FILE) return (await readFile34(env.LAZE_TURN_FILE, "utf8")).trim();
91576
+ if (env.LAZE_TURN_FILE) return (await readFile26(env.LAZE_TURN_FILE, "utf8")).trim();
91504
91577
  return agent3 ? connectedTurnTokenOf({ client, channelId: channel }) : "";
91505
91578
  };
91506
91579
  const turn = await read4().catch(() => "");
@@ -91574,7 +91647,7 @@ async function bodyOf2({
91574
91647
  flags: flags2
91575
91648
  }) {
91576
91649
  const body = { ...flags2.fields };
91577
- const read4 = (source) => "file" in source ? readFile34(resolve17(context.cwd, source.file), "utf8") : source.text;
91650
+ const read4 = (source) => "file" in source ? readFile26(resolve17(context.cwd, source.file), "utf8") : source.text;
91578
91651
  for (const [field, source] of Object.entries(flags2.texts)) body[field] = await read4(source);
91579
91652
  if (flags2.rich) {
91580
91653
  const text3 = await read4(flags2.rich.source);
@@ -91837,7 +91910,7 @@ async function textFlag({
91837
91910
  }) {
91838
91911
  const value = flagText({ args, name: name3 });
91839
91912
  if (!value.startsWith("@")) return value;
91840
- return readFile34(resolve17(context.cwd, value.slice(1)), "utf8");
91913
+ return readFile26(resolve17(context.cwd, value.slice(1)), "utf8");
91841
91914
  }
91842
91915
  async function feedList({ context, args }) {
91843
91916
  const { client } = await signedIn({ context, args });
@@ -91927,7 +92000,7 @@ async function ranksOf({
91927
92000
  }) {
91928
92001
  const file4 = flagText({ args, name: "file" });
91929
92002
  if (file4) {
91930
- const parsed = JSON.parse(await readFile34(resolve17(context.cwd, file4), "utf8"));
92003
+ const parsed = JSON.parse(await readFile26(resolve17(context.cwd, file4), "utf8"));
91931
92004
  if (Array.isArray(parsed)) return parsed;
91932
92005
  throw new CliUsageError("--file holds a list of {itemId, priority}");
91933
92006
  }
@@ -92040,7 +92113,7 @@ async function feed({ context, args }) {
92040
92113
  }
92041
92114
 
92042
92115
  // src/services/github-commands.service.ts
92043
- import { readFile as readFile35 } from "node:fs/promises";
92116
+ import { readFile as readFile27 } from "node:fs/promises";
92044
92117
 
92045
92118
  // src/rules/github-signature.rules.ts
92046
92119
  var TURN_SEPARATOR = "~";
@@ -92110,7 +92183,7 @@ var REAL_GH = "/usr/bin/gh";
92110
92183
  var NOT_SET = "laze: agent_github_not_set: this agent has no GitHub connection. Run `laze github request --repo <owner/name>` to post a card that gets it in one click, or its owner runs `laze agent set-github <agent> <connection>`.";
92111
92184
  async function turnFileToken({ env }) {
92112
92185
  if (!env.LAZE_TURN_FILE) return "";
92113
- return readFile35(env.LAZE_TURN_FILE, "utf8").then(
92186
+ return readFile27(env.LAZE_TURN_FILE, "utf8").then(
92114
92187
  (text3) => text3.trim(),
92115
92188
  () => ""
92116
92189
  );
@@ -92144,7 +92217,7 @@ async function githubGh({
92144
92217
  args: args.rest,
92145
92218
  agentName: profile.name ?? "An agent",
92146
92219
  threadUrl: threadUrlOf({ env, workspaceId: profile.workspaceId }),
92147
- readBodyFile: (path) => path === "-" ? context.readStdin() : readFile35(path, "utf8")
92220
+ readBodyFile: (path) => path === "-" ? context.readStdin() : readFile27(path, "utf8")
92148
92221
  });
92149
92222
  return context.runCommand({
92150
92223
  command: [REAL_GH, ...ghArgs],
@@ -92307,7 +92380,7 @@ async function create2({ context, args }) {
92307
92380
  });
92308
92381
  printGroup({ context, args, group });
92309
92382
  }
92310
- async function rename7({ context, args }) {
92383
+ async function rename5({ context, args }) {
92311
92384
  const group = wordAt6({ args, at: 2 });
92312
92385
  const name3 = wordAt6({ args, at: 3 });
92313
92386
  const { client } = await signedIn({ context, args });
@@ -92346,7 +92419,7 @@ function changing3(key) {
92346
92419
  var COMMANDS = {
92347
92420
  list: list7,
92348
92421
  create: create2,
92349
- rename: rename7,
92422
+ rename: rename5,
92350
92423
  delete: remove5,
92351
92424
  add: changing3("add"),
92352
92425
  remove: changing3("remove")
@@ -92754,35 +92827,28 @@ async function ip({ context, args }) {
92754
92827
  }
92755
92828
 
92756
92829
  // src/services/join-commands.service.ts
92757
- import { mkdir as mkdir24, readFile as readFile36, rename as rename8, rm as rm14, writeFile as writeFile23 } from "node:fs/promises";
92758
- import { dirname as dirname23, join as join27 } from "node:path";
92830
+ import { rm as rm15 } from "node:fs/promises";
92831
+ import { dirname as dirname19, join as join28 } from "node:path";
92759
92832
  var DEFAULT_WAIT_SECONDS2 = 100;
92760
92833
  var JOIN_USAGE = "Usage: laze join [--workspace <name|id|invite link>] [--for <email>] [--name <name>] [--note <text>] [--timeout <seconds>] [--project <folder>]";
92761
92834
  function pendingPathOf({ context }) {
92762
- return join27(dirname23(context.environment.configPath), "join", "pending.json");
92835
+ return join28(dirname19(context.environment.configPath), "join", "pending.json");
92763
92836
  }
92764
92837
  async function readPending({
92765
92838
  context,
92766
92839
  url: url2,
92767
92840
  args
92768
92841
  }) {
92769
- const pending2 = await readFile36(pendingPathOf({ context }), "utf8").then(
92770
- (text3) => JSON.parse(text3),
92771
- () => void 0
92772
- );
92842
+ const pending2 = await readStateJson({ path: pendingPathOf({ context }) });
92773
92843
  if (!pending2 || pending2.url !== url2) return void 0;
92774
92844
  if (args && !asksTheSame({ pending: pending2, flags: flaggedOf({ args }) })) return void 0;
92775
92845
  return Temporal3.Instant.from(pending2.expiresAt).epochMilliseconds > context.nowMs() ? pending2 : void 0;
92776
92846
  }
92777
92847
  async function keepPending({ context, pending: pending2 }) {
92778
- const path = pendingPathOf({ context });
92779
- await mkdir24(dirname23(path), { recursive: true, mode: 448 });
92780
- const temporary = `${path}.${process.pid}.tmp`;
92781
- await writeFile23(temporary, JSON.stringify(pending2), { mode: 384 });
92782
- await rename8(temporary, path);
92848
+ await writeStateJson({ path: pendingPathOf({ context }), value: pending2 });
92783
92849
  }
92784
92850
  async function dropPending({ context }) {
92785
- await rm14(pendingPathOf({ context }), { force: true });
92851
+ await rm15(pendingPathOf({ context }), { force: true });
92786
92852
  }
92787
92853
  function waitSecondsOf3({ args }) {
92788
92854
  const raw = flagText({ args, name: "timeout" });
@@ -93350,7 +93416,7 @@ async function get({ context, args }) {
93350
93416
  machine: await client.post(COMPUTE_REST_PATHS.get, { machine: machine2 })
93351
93417
  });
93352
93418
  }
93353
- async function rename9({ context, args }) {
93419
+ async function rename6({ context, args }) {
93354
93420
  const machine2 = wordAt7({ args, at: 2 });
93355
93421
  const name3 = wordAt7({ args, at: 3 });
93356
93422
  const client = await computeClient({ context, args });
@@ -93396,7 +93462,7 @@ ${MACHINE_ACCESS_USAGE}`);
93396
93462
  });
93397
93463
  printMachine({ context, args, machine: changed });
93398
93464
  }
93399
- var COMMANDS2 = { status: status8, get, rename: rename9, grant: share2, revoke: share2, budget };
93465
+ var COMMANDS2 = { status: status8, get, rename: rename6, grant: share2, revoke: share2, budget };
93400
93466
  function machineAccessCommand(name3) {
93401
93467
  return name3 && Object.hasOwn(COMMANDS2, name3) ? COMMANDS2[name3] : void 0;
93402
93468
  }
@@ -93916,18 +93982,18 @@ async function serveMcp({
93916
93982
  }
93917
93983
 
93918
93984
  // src/services/memory-commands.service.ts
93919
- import { readdir as readdir7, readFile as readFile38 } from "node:fs/promises";
93920
- import { join as join28, resolve as resolve19 } from "node:path";
93985
+ import { readdir as readdir7, readFile as readFile29 } from "node:fs/promises";
93986
+ import { join as join29, resolve as resolve19 } from "node:path";
93921
93987
 
93922
93988
  // src/services/mount-files.service.ts
93923
- import { mkdir as mkdir25, readFile as readFile37, rm as rm15, writeFile as writeFile24 } from "node:fs/promises";
93924
- import { dirname as dirname24, relative as relative5, resolve as resolve18 } from "node:path";
93989
+ import { mkdir as mkdir10, readFile as readFile28, rm as rm16, writeFile as writeFile8 } from "node:fs/promises";
93990
+ import { dirname as dirname20, relative as relative5, resolve as resolve18 } from "node:path";
93925
93991
  async function textArgument({
93926
93992
  context,
93927
93993
  value
93928
93994
  }) {
93929
93995
  if (value === "-") return context.readStdin();
93930
- if (value.startsWith("@")) return readFile37(resolve18(context.cwd, value.slice(1)), "utf8");
93996
+ if (value.startsWith("@")) return readFile28(resolve18(context.cwd, value.slice(1)), "utf8");
93931
93997
  return value;
93932
93998
  }
93933
93999
  function turnChannel({ context, args }) {
@@ -93940,15 +94006,15 @@ async function writeMount({
93940
94006
  files: files2
93941
94007
  }) {
93942
94008
  const root = resolve18(context.cwd, flagText({ args, name: "dir", fallback: ".laze" }), folder);
93943
- await rm15(root, { recursive: true, force: true });
93944
- await mkdir25(root, { recursive: true });
94009
+ await rm16(root, { recursive: true, force: true });
94010
+ await mkdir10(root, { recursive: true });
93945
94011
  for (const file4 of files2) {
93946
94012
  const target = resolve18(root, file4.path);
93947
94013
  const inside = relative5(root, target);
93948
94014
  if (!inside || inside.startsWith(".."))
93949
94015
  throw new Error(`Refusing to write outside ${root}: ${file4.path}`);
93950
- await mkdir25(dirname24(target), { recursive: true });
93951
- await writeFile24(target, file4.content);
94016
+ await mkdir10(dirname20(target), { recursive: true });
94017
+ await writeFile8(target, file4.content);
93952
94018
  }
93953
94019
  return root;
93954
94020
  }
@@ -94074,7 +94140,7 @@ async function turnTokenOf5({ context }) {
94074
94140
  const pinned = env.LAZE_TURN_TOKEN?.trim();
94075
94141
  if (pinned) return pinned;
94076
94142
  if (!env.LAZE_TURN_FILE) return "";
94077
- return readFile38(env.LAZE_TURN_FILE, "utf8").then(
94143
+ return readFile29(env.LAZE_TURN_FILE, "utf8").then(
94078
94144
  (text3) => text3.trim(),
94079
94145
  () => ""
94080
94146
  );
@@ -94204,15 +94270,15 @@ async function siestaImport({
94204
94270
  dir
94205
94271
  }) {
94206
94272
  const root = resolve19(context.cwd, dir);
94207
- const log = await readFile38(join28(root, "LOG.md"));
94208
- const names = (await readdir7(join28(root, "tree")).catch(() => [])).filter(
94273
+ const log = await readFile29(join29(root, "LOG.md"));
94274
+ const names = (await readdir7(join29(root, "tree")).catch(() => [])).filter(
94209
94275
  (name3) => /^\d{1,6}-\d{1,6}\.md$/.test(name3)
94210
94276
  );
94211
94277
  const tree = Object.fromEntries(
94212
94278
  await Promise.all(
94213
94279
  names.map(async (name3) => [
94214
94280
  name3.slice(0, -3),
94215
- (await readFile38(join28(root, "tree", name3))).toString("base64")
94281
+ (await readFile29(join29(root, "tree", name3))).toString("base64")
94216
94282
  ])
94217
94283
  )
94218
94284
  );
@@ -94232,15 +94298,15 @@ async function memoryImport({ context, args }) {
94232
94298
  const dir = flagText({ args, name: "optmem" });
94233
94299
  if (!dir) throw new CliUsageError(USAGE13);
94234
94300
  const root = resolve19(context.cwd, dir);
94235
- const log = await readFile38(join28(root, "LOG.txt"));
94236
- const sizes2 = (await readdir7(join28(root, "TREE")).catch(() => [])).filter(
94301
+ const log = await readFile29(join29(root, "LOG.txt"));
94302
+ const sizes2 = (await readdir7(join29(root, "TREE")).catch(() => [])).filter(
94237
94303
  (name3) => /^\d{1,4}$/.test(name3)
94238
94304
  );
94239
94305
  const tree = Object.fromEntries(
94240
94306
  await Promise.all(
94241
94307
  sizes2.map(async (size) => [
94242
94308
  size,
94243
- (await readFile38(join28(root, "TREE", size))).toString("base64")
94309
+ (await readFile29(join29(root, "TREE", size))).toString("base64")
94244
94310
  ])
94245
94311
  )
94246
94312
  );
@@ -94804,9 +94870,9 @@ async function openclaw({
94804
94870
  }
94805
94871
 
94806
94872
  // src/services/operator-key-commands.service.ts
94807
- import { createHash as createHash7, randomBytes as randomBytes3 } from "node:crypto";
94808
- import { mkdir as mkdir26, readFile as readFile39, rm as rm16, writeFile as writeFile25 } from "node:fs/promises";
94809
- import { dirname as dirname25, join as join29 } from "node:path";
94873
+ import { createHash as createHash7, randomBytes as randomBytes4 } from "node:crypto";
94874
+ import { mkdir as mkdir11, readFile as readFile30, rm as rm17, writeFile as writeFile9 } from "node:fs/promises";
94875
+ import { dirname as dirname21, join as join30 } from "node:path";
94810
94876
 
94811
94877
  // ../../modules/audit-log/contract/src/audit-log.api.ts
94812
94878
  var auditEntrySchemaDefinition = external_exports.object({
@@ -96151,15 +96217,15 @@ var OPERATOR_KEY_USAGE = `Temporary operator keys (ask, an operator approves wit
96151
96217
  laze ops status <key> waiting, approved or ended
96152
96218
  laze ops use <key> run the approved action and print the answer`;
96153
96219
  var POLL_MS3 = 5e3;
96154
- var keyFile = ({ context, keyId }) => join29(dirname25(context.environment.configPath), "operator-keys", keyId.replaceAll("/", "_"));
96220
+ var keyFile = ({ context, keyId }) => join30(dirname21(context.environment.configPath), "operator-keys", keyId.replaceAll("/", "_"));
96155
96221
  async function saveSecret({
96156
96222
  context,
96157
96223
  keyId,
96158
96224
  secret
96159
96225
  }) {
96160
96226
  const path = keyFile({ context, keyId });
96161
- await mkdir26(dirname25(path), { recursive: true, mode: 448 });
96162
- await writeFile25(path, secret, { mode: 384 });
96227
+ await mkdir11(dirname21(path), { recursive: true, mode: 448 });
96228
+ await writeFile9(path, secret, { mode: 384 });
96163
96229
  }
96164
96230
  function typedArg(text3) {
96165
96231
  if (["true", "false", "null"].includes(text3)) return JSON.parse(text3);
@@ -96176,12 +96242,12 @@ ${OPERATOR_KEY_USAGE}`);
96176
96242
  return Object.fromEntries(pairs);
96177
96243
  }
96178
96244
  var EXPIRED_LINE = `Expired: nobody answered within ${OPERATOR_KEY.pendingMinutes} minutes. Nothing ran. Ask again with laze ops request.`;
96179
- function statusLine2({ key, nowMs }) {
96245
+ function statusLine2({ key, nowMs: nowMs2 }) {
96180
96246
  switch (key.status) {
96181
96247
  case "approved":
96182
96248
  return `Approved until ${key.endsAt}. Run: laze ops use ${key.id}`;
96183
96249
  case "pending":
96184
- return Temporal3.Instant.from(key.pendingUntil).epochMilliseconds <= nowMs ? EXPIRED_LINE : `Waiting for an operator's passkey at /ops/keys. Nothing runs until they approve. It expires at ${key.pendingUntil} if nobody answers.`;
96250
+ return Temporal3.Instant.from(key.pendingUntil).epochMilliseconds <= nowMs2 ? EXPIRED_LINE : `Waiting for an operator's passkey at /ops/keys. Nothing runs until they approve. It expires at ${key.pendingUntil} if nobody answers.`;
96185
96251
  case "expired":
96186
96252
  return EXPIRED_LINE;
96187
96253
  case "denied":
@@ -96210,7 +96276,7 @@ async function requestKey({ context, args }) {
96210
96276
  const reason2 = flagText({ args, name: "reason" });
96211
96277
  if (!action || !target || !reason2.trim()) throw new CliUsageError(OPERATOR_KEY_USAGE);
96212
96278
  const { client } = await signedIn({ context, args });
96213
- const secret = randomBytes3(32).toString("hex");
96279
+ const secret = randomBytes4(32).toString("hex");
96214
96280
  const key = await client.post(OPERATOR_KEY_REST_PATHS.request, {
96215
96281
  action,
96216
96282
  target,
@@ -96243,7 +96309,7 @@ async function forgetIfOver({
96243
96309
  const key = await client.post(OPERATOR_KEY_REST_PATHS.status, { keyId });
96244
96310
  const windowOver = key.endsAt !== null && Temporal3.Instant.from(key.endsAt).epochMilliseconds <= context.nowMs();
96245
96311
  if (key.status !== "pending" && (key.status !== "approved" || windowOver || key.spentAt)) {
96246
- await rm16(keyFile({ context, keyId }), { force: true });
96312
+ await rm17(keyFile({ context, keyId }), { force: true });
96247
96313
  }
96248
96314
  return key;
96249
96315
  }
@@ -96252,7 +96318,7 @@ async function useKey({ context, args }) {
96252
96318
  if (!keyId) throw new CliUsageError(OPERATOR_KEY_USAGE);
96253
96319
  const { client } = await signedIn({ context, args });
96254
96320
  const path = keyFile({ context, keyId });
96255
- const secret = await readFile39(path, "utf8").catch(() => null);
96321
+ const secret = await readFile30(path, "utf8").catch(() => null);
96256
96322
  if (secret === null) {
96257
96323
  throw new CliUsageError(`No operator key ${keyId} is kept on this machine.`);
96258
96324
  }
@@ -96317,8 +96383,8 @@ ${OPS_USAGE}`);
96317
96383
  }
96318
96384
 
96319
96385
  // src/services/release-watch.service.ts
96320
- import { mkdir as mkdir27, readFile as readFile40, realpath, writeFile as writeFile26 } from "node:fs/promises";
96321
- import { dirname as dirname26, join as join30 } from "node:path";
96386
+ import { realpath } from "node:fs/promises";
96387
+ import { dirname as dirname22, join as join31 } from "node:path";
96322
96388
 
96323
96389
  // src/rules/cli-update.rules.ts
96324
96390
  var CLI_PACKAGE = "@lazehq/cli";
@@ -96464,16 +96530,15 @@ async function startedUpdate({
96464
96530
  if (context.environment.inherited.LAZE_AUTO_UPDATE === "0") return null;
96465
96531
  const plan2 = updatePlanOf({ script: await scriptOf(context) });
96466
96532
  if (plan2.kind !== "install") return null;
96467
- const folder = dirname26(context.environment.configPath);
96468
- const stamp = join30(folder, "auto-update.json");
96469
- const last = await readFile40(stamp, "utf8").then((text3) => JSON.parse(text3)).catch(() => null);
96533
+ const folder = dirname22(context.environment.configPath);
96534
+ const stamp = join31(folder, "auto-update.json");
96535
+ const last = await readStateJson({ path: stamp }) ?? null;
96470
96536
  const now = context.nowMs();
96471
96537
  if (last?.server === server && now - last.atMs < RETRY_AFTER_MS) return null;
96472
- await mkdir27(folder, { recursive: true, mode: 448 });
96473
- await writeFile26(stamp, JSON.stringify({ server, atMs: now }), { mode: 384 });
96538
+ await writeStateJson({ path: stamp, value: { server, atMs: now } });
96474
96539
  context.processes.spawnDetached({
96475
96540
  argv: [...context.program, "update"],
96476
- logPath: join30(folder, "auto-update.log")
96541
+ logPath: join31(folder, "auto-update.log")
96477
96542
  });
96478
96543
  return { manager: plan2.manager };
96479
96544
  }
@@ -96510,7 +96575,7 @@ function watchingRelease({
96510
96575
  }
96511
96576
 
96512
96577
  // src/services/rush-guard.service.ts
96513
- import { readFile as readFile41, rm as rm17 } from "node:fs/promises";
96578
+ import { rm as rm18 } from "node:fs/promises";
96514
96579
  var WATCH_MS3 = 2e3;
96515
96580
  var RETRY_MS2 = 3e4;
96516
96581
  async function guardRound(guard) {
@@ -96553,10 +96618,7 @@ async function rushWakeHook({ context, args }) {
96553
96618
  while (context.processes.alive(claudePid)) await context.sleep(WATCH_MS3);
96554
96619
  const { client, name: name3 } = await signedIn({ context, args });
96555
96620
  const noted = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
96556
- const note = await readFile41(noted, "utf8").then(
96557
- (text3) => JSON.parse(text3),
96558
- () => void 0
96559
- );
96621
+ const note = await readStateJson({ path: noted });
96560
96622
  const { launch = {}, ...session } = note ?? {};
96561
96623
  const lock = statePathOf({ context, kind: "waiters", profile: name3 });
96562
96624
  const rush = { id: id4, program };
@@ -96582,10 +96644,10 @@ async function rushWakeHook({ context, args }) {
96582
96644
  return 0;
96583
96645
  } finally {
96584
96646
  if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
96585
- await rm17(lock, { force: true });
96647
+ await rm18(lock, { force: true });
96586
96648
  }
96587
96649
  } finally {
96588
- await rm17(path, { force: true });
96650
+ await rm18(path, { force: true });
96589
96651
  }
96590
96652
  }
96591
96653
 
@@ -96751,8 +96813,8 @@ async function schedule({ context, args }) {
96751
96813
  }
96752
96814
 
96753
96815
  // src/services/skill-commands.service.ts
96754
- import { readdir as readdir8, readFile as readFile42 } from "node:fs/promises";
96755
- import { join as join31, relative as relative6, resolve as resolve21 } from "node:path";
96816
+ import { readdir as readdir8, readFile as readFile31 } from "node:fs/promises";
96817
+ import { join as join32, relative as relative6, resolve as resolve21 } from "node:path";
96756
96818
  var USAGE17 = `Usage:
96757
96819
  laze skill list [--agent <agentId>]
96758
96820
  laze skill install <catalogue-id> [--as <name>] [--agent <agentId>]
@@ -96773,8 +96835,8 @@ async function folderFiles({ root }) {
96773
96835
  const files2 = [];
96774
96836
  for (const entry of entries) {
96775
96837
  if (!entry.isFile()) continue;
96776
- const full = join31(entry.parentPath, entry.name);
96777
- files2.push({ path: relative6(root, full), content: await readFile42(full, "utf8") });
96838
+ const full = join32(entry.parentPath, entry.name);
96839
+ files2.push({ path: relative6(root, full), content: await readFile31(full, "utf8") });
96778
96840
  }
96779
96841
  return files2.toSorted((a, b) => a.path.localeCompare(b.path));
96780
96842
  }
@@ -96872,7 +96934,7 @@ async function skillUpdate({ context, args }) {
96872
96934
  if (!name3 || !newName && description === void 0 && !skillMdFile) {
96873
96935
  throw new CliUsageError(USAGE17);
96874
96936
  }
96875
- const skillMd = skillMdFile ? await readFile42(resolve21(context.cwd, skillMdFile), "utf8") : void 0;
96937
+ const skillMd = skillMdFile ? await readFile31(resolve21(context.cwd, skillMdFile), "utf8") : void 0;
96876
96938
  const { client } = await signedIn({ context, args });
96877
96939
  const updated = await client.post("/api/skills/update", {
96878
96940
  name: name3,
@@ -96918,7 +96980,7 @@ async function skill({ context, args }) {
96918
96980
  }
96919
96981
 
96920
96982
  // src/services/slack-commands.service.ts
96921
- import { readFile as readFile43 } from "node:fs/promises";
96983
+ import { readFile as readFile32 } from "node:fs/promises";
96922
96984
  import { resolve as resolve22 } from "node:path";
96923
96985
  var SLACK_USAGE = `Usage (a person's key; Slack stays the source, the bot joins no channel by itself):
96924
96986
  laze slack overview connected Slack workspaces, mirrors, your link
@@ -96966,7 +97028,7 @@ async function secretLines({ context, args }) {
96966
97028
  throw new CliUsageError("A secret never goes in a flag: pipe it on stdin or use --from-file.");
96967
97029
  }
96968
97030
  const file4 = flagText({ args, name: "from-file" });
96969
- const text3 = file4 ? await readFile43(resolve22(context.cwd, file4), "utf8") : await context.readStdin();
97031
+ const text3 = file4 ? await readFile32(resolve22(context.cwd, file4), "utf8") : await context.readStdin();
96970
97032
  return text3.split("\n").map((line) => line.trim()).filter(Boolean);
96971
97033
  }
96972
97034
  async function secretsOf2({
@@ -97270,7 +97332,7 @@ async function slack({
97270
97332
  }
97271
97333
 
97272
97334
  // src/services/sso-commands.service.ts
97273
- import { readFile as readFile44 } from "node:fs/promises";
97335
+ import { readFile as readFile33 } from "node:fs/promises";
97274
97336
  var SSO_USAGE = `Usage:
97275
97337
  laze sso domains claimed domains and how each signs in (admins)
97276
97338
  laze sso claim <domain> the TXT record that proves the domain
@@ -97357,7 +97419,7 @@ function refuseSecretFlags({ args }) {
97357
97419
  }
97358
97420
  async function clientSecretOf({ context, args }) {
97359
97421
  const file4 = flagText({ args, name: "from-file" });
97360
- const text3 = file4 ? await readFile44(file4, "utf8") : await context.readStdin();
97422
+ const text3 = file4 ? await readFile33(file4, "utf8") : await context.readStdin();
97361
97423
  const secret = text3.trim();
97362
97424
  if (!secret) throw new CliUsageError("No client secret: pipe it on stdin or use --from-file.");
97363
97425
  return secret;
@@ -97689,8 +97751,8 @@ async function update2({
97689
97751
  }
97690
97752
 
97691
97753
  // src/services/vault-env-commands.service.ts
97692
- import { readFile as readFile45, stat as stat11 } from "node:fs/promises";
97693
- import { dirname as dirname27, join as join32, resolve as resolve23 } from "node:path";
97754
+ import { readFile as readFile34, stat as stat12 } from "node:fs/promises";
97755
+ import { dirname as dirname23, join as join33, resolve as resolve23 } from "node:path";
97694
97756
 
97695
97757
  // src/rules/vault-manifest.rules.ts
97696
97758
  var VARIABLE = /^[A-Za-z_][A-Za-z0-9_]*$/;
@@ -97778,7 +97840,7 @@ function credentialProcessJson(fields) {
97778
97840
  }
97779
97841
 
97780
97842
  // src/services/vault-batch.service.ts
97781
- import { rm as rm18 } from "node:fs/promises";
97843
+ import { rm as rm19 } from "node:fs/promises";
97782
97844
  async function batchOf({ response }) {
97783
97845
  const text3 = await response.text();
97784
97846
  if (!response.ok) {
@@ -97960,7 +98022,7 @@ async function valuesOf({
97960
98022
  }) {
97961
98023
  const refused = refusalOf({ context, settled: settled2 });
97962
98024
  if (refused !== 0) {
97963
- await rm18(keyPath, { force: true });
98025
+ await rm19(keyPath, { force: true });
97964
98026
  return { exitCode: refused };
97965
98027
  }
97966
98028
  const opened = /* @__PURE__ */ new Map();
@@ -97972,7 +98034,7 @@ async function valuesOf({
97972
98034
  if (release2.message) context.err(`${release2.message}
97973
98035
  `);
97974
98036
  }
97975
- if (!keep2) await rm18(keyPath, { force: true });
98037
+ if (!keep2) await rm19(keyPath, { force: true });
97976
98038
  const released = /* @__PURE__ */ new Map();
97977
98039
  for (const entry of entries) {
97978
98040
  const fields = opened.get(keyOf(entry));
@@ -98025,7 +98087,7 @@ function refusedReason({
98025
98087
  return VAULT_EXIT_BAD_REASON;
98026
98088
  }
98027
98089
  async function isFile(path) {
98028
- return stat11(path).then(
98090
+ return stat12(path).then(
98029
98091
  (found) => found.isFile(),
98030
98092
  () => false
98031
98093
  );
@@ -98038,9 +98100,9 @@ async function manifestPathOf({
98038
98100
  if (named) return resolve23(context.cwd, named);
98039
98101
  const environment = flagText({ args, name: "env" });
98040
98102
  const file4 = environment ? `.env.${environment}.vault` : ".env.vault";
98041
- for (let dir = resolve23(context.cwd); ; dir = dirname27(dir)) {
98042
- if (await isFile(join32(dir, file4))) return join32(dir, file4);
98043
- if (dirname27(dir) === dir) break;
98103
+ for (let dir = resolve23(context.cwd); ; dir = dirname23(dir)) {
98104
+ if (await isFile(join33(dir, file4))) return join33(dir, file4);
98105
+ if (dirname23(dir) === dir) break;
98044
98106
  }
98045
98107
  throw new CliUsageError(`laze vault: no ${file4} here or in a parent folder
98046
98108
  ${ENV_USAGE}`);
@@ -98050,7 +98112,7 @@ async function manifestOf({
98050
98112
  args
98051
98113
  }) {
98052
98114
  const file4 = await manifestPathOf({ context, args });
98053
- const text3 = await readFile45(file4, "utf8").catch(() => {
98115
+ const text3 = await readFile34(file4, "utf8").catch(() => {
98054
98116
  throw new CliUsageError(`laze vault: cannot read ${file4}`);
98055
98117
  });
98056
98118
  return { file: file4, lines: parseManifest({ text: text3, file: file4 }) };
@@ -98365,7 +98427,7 @@ async function vaultScrub({ context, args }) {
98365
98427
  }
98366
98428
 
98367
98429
  // src/services/whatsapp-business-commands.service.ts
98368
- import { readFile as readFile46 } from "node:fs/promises";
98430
+ import { readFile as readFile35 } from "node:fs/promises";
98369
98431
  import { resolve as resolve24 } from "node:path";
98370
98432
 
98371
98433
  // ../../modules/whatsapp-business/contract/src/whatsapp-business.prices.ts
@@ -98785,7 +98847,7 @@ async function secretsOf3({ context, args }) {
98785
98847
  const fromConnection = flagText({ args, name: "from-vault" });
98786
98848
  if (fromConnection) return { fromConnection };
98787
98849
  const file4 = flagText({ args, name: "from-file" });
98788
- const text3 = file4 ? await readFile46(resolve24(context.cwd, file4), "utf8") : await context.readStdin();
98850
+ const text3 = file4 ? await readFile35(resolve24(context.cwd, file4), "utf8") : await context.readStdin();
98789
98851
  const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
98790
98852
  if (lines2.length !== 2) {
98791
98853
  throw new CliUsageError(
@@ -98986,8 +99048,8 @@ async function whatsappBusiness({
98986
99048
  }
98987
99049
 
98988
99050
  // src/services/whatsapp-commands.service.ts
98989
- import { writeFile as writeFile27 } from "node:fs/promises";
98990
- import { basename as basename10, resolve as resolve25 } from "node:path";
99051
+ import { writeFile as writeFile10 } from "node:fs/promises";
99052
+ import { basename as basename11, resolve as resolve25 } from "node:path";
98991
99053
 
98992
99054
  // src/services/whatsapp-pairing-commands.service.ts
98993
99055
  var WHATSAPP_PAIRING_USAGE = " laze whatsapp unpair <machine> unlink WhatsApp from the machine (owner)";
@@ -99127,10 +99189,10 @@ async function file3({ context, args }) {
99127
99189
  },
99128
99190
  args
99129
99191
  });
99130
- const out = resolve25(context.cwd, flagText({ args, name: "out" }) ?? basename10(answer6.fileName));
99192
+ const out = resolve25(context.cwd, flagText({ args, name: "out" }) ?? basename11(answer6.fileName));
99131
99193
  const response = await context.fetcher(answer6.url);
99132
99194
  if (!response.ok) throw new Error(`The file link answered ${response.status}`);
99133
- await writeFile27(out, new Uint8Array(await response.arrayBuffer()));
99195
+ await writeFile10(out, new Uint8Array(await response.arrayBuffer()));
99134
99196
  if (args.flags.json) return context.out(`${JSON.stringify({ ...answer6, path: out }, null, 2)}
99135
99197
  `);
99136
99198
  context.out(`${out}
@@ -99942,11 +100004,11 @@ import {
99942
100004
  createHash as createHash8,
99943
100005
  createPrivateKey,
99944
100006
  generateKeyPairSync,
99945
- randomBytes as randomBytes4,
100007
+ randomBytes as randomBytes5,
99946
100008
  sign
99947
100009
  } from "node:crypto";
99948
- import { chmod as chmod4, link, mkdir as mkdir28, readFile as readFile47, rm as rm19, writeFile as writeFile28 } from "node:fs/promises";
99949
- import { dirname as dirname28, join as join33 } from "node:path";
100010
+ import { chmod, link, mkdir as mkdir12, readFile as readFile36, rm as rm20, writeFile as writeFile11 } from "node:fs/promises";
100011
+ import { dirname as dirname24, join as join34 } from "node:path";
99950
100012
  var KEYCHAIN_SERVICE = "laze-cli-machine-key";
99951
100013
  var runProgram = ({ program, args, stdin: stdin2, timeoutMs }) => new Promise((resolve26, reject) => {
99952
100014
  const child = execFile2(
@@ -99986,11 +100048,11 @@ var MachineKeyStore = class _MachineKeyStore {
99986
100048
  });
99987
100049
  }
99988
100050
  get metaPath() {
99989
- return join33(dirname28(this.options.configPath), "machine-key.json");
100051
+ return join34(dirname24(this.options.configPath), "machine-key.json");
99990
100052
  }
99991
100053
  /** Named by the key, so two CLIs making a key at once never overwrite each other's. */
99992
100054
  pemPathOf(jwk) {
99993
- return join33(dirname28(this.options.configPath), `machine-key-${shortOf(jwk)}.pem`);
100055
+ return join34(dirname24(this.options.configPath), `machine-key-${shortOf(jwk)}.pem`);
99994
100056
  }
99995
100057
  /** The Keychain item's account: one per config file and key. */
99996
100058
  accountOf(jwk) {
@@ -100018,7 +100080,7 @@ var MachineKeyStore = class _MachineKeyStore {
100018
100080
  async read() {
100019
100081
  let meta3;
100020
100082
  try {
100021
- meta3 = machineKeyRegistrationSchema.parse(JSON.parse(await readFile47(this.metaPath, "utf8")));
100083
+ meta3 = machineKeyRegistrationSchema.parse(JSON.parse(await readFile36(this.metaPath, "utf8")));
100022
100084
  } catch {
100023
100085
  return null;
100024
100086
  }
@@ -100033,7 +100095,7 @@ var MachineKeyStore = class _MachineKeyStore {
100033
100095
  "-w"
100034
100096
  ],
100035
100097
  timeoutMs: 1e4
100036
- }) : await readFile47(this.pemPathOf(meta3.jwk), "utf8");
100098
+ }) : await readFile36(this.pemPathOf(meta3.jwk), "utf8");
100037
100099
  return keyOf2({ meta: meta3, privateKey: createPrivateKey(pemOf(pem)) });
100038
100100
  }
100039
100101
  async make() {
@@ -100057,7 +100119,7 @@ var MachineKeyStore = class _MachineKeyStore {
100057
100119
  return kept;
100058
100120
  }
100059
100121
  async drop({ tier, jwk }) {
100060
- if (tier === "file") return rm19(this.pemPathOf(jwk), { force: true });
100122
+ if (tier === "file") return rm20(this.pemPathOf(jwk), { force: true });
100061
100123
  await this.options.run({
100062
100124
  program: "security",
100063
100125
  args: ["delete-generic-password", "-s", KEYCHAIN_SERVICE, "-a", this.accountOf(jwk)],
@@ -100104,7 +100166,7 @@ function keyOf2({ meta: meta3, privateKey }) {
100104
100166
  }
100105
100167
  var shortOf = (jwk) => thumbprintOf({ jwk }).slice(0, 12);
100106
100168
  async function writeOnce({ path, text: text3 }) {
100107
- const temporary = `${path}.${process.pid}.${randomBytes4(6).toString("hex")}.tmp`;
100169
+ const temporary = `${path}.${process.pid}.${randomBytes5(6).toString("hex")}.tmp`;
100108
100170
  await writePrivate({ path: temporary, text: text3 });
100109
100171
  try {
100110
100172
  await link(temporary, path);
@@ -100113,13 +100175,13 @@ async function writeOnce({ path, text: text3 }) {
100113
100175
  if (error63.code === "EEXIST") return false;
100114
100176
  throw error63;
100115
100177
  } finally {
100116
- await rm19(temporary, { force: true });
100178
+ await rm20(temporary, { force: true });
100117
100179
  }
100118
100180
  }
100119
100181
  async function writePrivate({ path, text: text3 }) {
100120
- await mkdir28(dirname28(path), { recursive: true, mode: 448 });
100121
- await writeFile28(path, text3, { mode: 384 });
100122
- await chmod4(path, 384);
100182
+ await mkdir12(dirname24(path), { recursive: true, mode: 448 });
100183
+ await writeFile11(path, text3, { mode: 384 });
100184
+ await chmod(path, 384);
100123
100185
  }
100124
100186
 
100125
100187
  // src/services/machine-proof-fetch.service.ts
@@ -100141,7 +100203,7 @@ function machineProofFetch({
100141
100203
  fetcher,
100142
100204
  store,
100143
100205
  keys: keys2,
100144
- nowMs,
100206
+ nowMs: nowMs2,
100145
100207
  warn
100146
100208
  }) {
100147
100209
  const warned = /* @__PURE__ */ new Set();
@@ -100157,7 +100219,7 @@ function machineProofFetch({
100157
100219
  method: init?.method ?? "GET",
100158
100220
  url: input2,
100159
100221
  credential: token2,
100160
- nowMs: nowMs(),
100222
+ nowMs: nowMs2(),
100161
100223
  tailscaleNodeId: key.tailscale?.nodeId ?? null
100162
100224
  });
100163
100225
  }
@@ -100175,8 +100237,8 @@ function machineProofFetch({
100175
100237
  // src/services/processes.service.ts
100176
100238
  import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
100177
100239
  import { mkdirSync, openSync } from "node:fs";
100178
- import { readFile as readFile48, readlink } from "node:fs/promises";
100179
- import { dirname as dirname29 } from "node:path";
100240
+ import { readFile as readFile37, readlink } from "node:fs/promises";
100241
+ import { dirname as dirname25 } from "node:path";
100180
100242
  import { promisify as promisify2 } from "node:util";
100181
100243
  var run3 = promisify2(execFile3);
100182
100244
  function alive(pid) {
@@ -100189,15 +100251,15 @@ function alive(pid) {
100189
100251
  }
100190
100252
  }
100191
100253
  async function argsOf2(pid) {
100192
- const raw = await readFile48(`/proc/${pid}/cmdline`, "utf8").catch(() => void 0);
100254
+ const raw = await readFile37(`/proc/${pid}/cmdline`, "utf8").catch(() => void 0);
100193
100255
  if (raw) return raw.split("\0").filter(Boolean);
100194
100256
  const listed = await run3("ps", ["-o", "args=", "-p", String(pid)]).catch(() => void 0);
100195
100257
  const line = listed?.stdout.trim();
100196
100258
  return line ? line.split(/\s+/) : void 0;
100197
100259
  }
100198
100260
  async function parentOf(pid) {
100199
- const stat12 = await readFile48(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
100200
- const fromStat = stat12 ? Number(stat12.slice(stat12.lastIndexOf(")") + 2).split(" ")[1]) : NaN;
100261
+ const stat13 = await readFile37(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
100262
+ const fromStat = stat13 ? Number(stat13.slice(stat13.lastIndexOf(")") + 2).split(" ")[1]) : NaN;
100201
100263
  if (fromStat > 0) return fromStat;
100202
100264
  const listed = await run3("ps", ["-o", "ppid=", "-p", String(pid)]).catch(() => void 0);
100203
100265
  const parent = Number(listed?.stdout.trim());
@@ -100213,7 +100275,7 @@ async function cwdOf(pid) {
100213
100275
  return line ? line.slice(1) : void 0;
100214
100276
  }
100215
100277
  function spawnDetached({ argv, logPath }) {
100216
- mkdirSync(dirname29(logPath), { recursive: true, mode: 448 });
100278
+ mkdirSync(dirname25(logPath), { recursive: true, mode: 448 });
100217
100279
  const log = openSync(logPath, "a", 384);
100218
100280
  const [program = "", ...rest] = argv;
100219
100281
  const child = spawn4(program, rest, { detached: true, stdio: ["ignore", log, log] });
@@ -100335,7 +100397,7 @@ if (true) {
100335
100397
  configPath: environment.configPath,
100336
100398
  tier: environment.machineKeyTier
100337
100399
  });
100338
- const nowMs = () => nowInstant().epochMilliseconds;
100400
+ const nowMs2 = () => nowInstant().epochMilliseconds;
100339
100401
  process.exitCode = await runCli({
100340
100402
  argv: process.argv.slice(2),
100341
100403
  context: {
@@ -100348,7 +100410,7 @@ if (true) {
100348
100410
  fetcher: proxiedFetch(environment.inherited),
100349
100411
  store,
100350
100412
  keys: machineKeys,
100351
- nowMs,
100413
+ nowMs: nowMs2,
100352
100414
  warn: (text3) => void process.stderr.write(text3)
100353
100415
  }),
100354
100416
  out: (text3) => void process.stdout.write(text3),
@@ -100357,7 +100419,7 @@ if (true) {
100357
100419
  stdoutIsTerminal: process.stdout.isTTY === true,
100358
100420
  ...ask ? { ask } : {},
100359
100421
  sleep,
100360
- nowMs,
100422
+ nowMs: nowMs2,
100361
100423
  processes: nodeProcesses(),
100362
100424
  runCommand: (input2) => runCommand({ ...input2, inherited: environment.inherited })
100363
100425
  }