@lazehq/cli 0.1.86 → 0.1.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/laze.mjs +781 -667
- 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:
|
|
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 =
|
|
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
|
|
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
|
|
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:
|
|
19490
|
-
var { dirname:
|
|
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
|
|
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
|
|
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
|
|
19741
|
+
await writeFile12(resolvedPath, JSON.stringify(data, null, 2), { flush: true });
|
|
19742
19742
|
}
|
|
19743
19743
|
/**
|
|
19744
19744
|
* Clears all recorded snapshots
|
|
@@ -36780,8 +36780,148 @@ function cliEnvironment({
|
|
|
36780
36780
|
}
|
|
36781
36781
|
|
|
36782
36782
|
// src/services/config-store.service.ts
|
|
36783
|
-
import {
|
|
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
|
+
async function withStateLock({
|
|
36896
|
+
path,
|
|
36897
|
+
work
|
|
36898
|
+
}) {
|
|
36899
|
+
const lock = `${path}.lock`;
|
|
36900
|
+
await mkdir(dirname(lock), { recursive: true, mode: 448 });
|
|
36901
|
+
for (; ; ) {
|
|
36902
|
+
const handle = await open(lock, "wx", 384).catch((error63) => {
|
|
36903
|
+
if (error63.code === "EEXIST") return void 0;
|
|
36904
|
+
throw error63;
|
|
36905
|
+
});
|
|
36906
|
+
if (handle) {
|
|
36907
|
+
await handle.close();
|
|
36908
|
+
break;
|
|
36909
|
+
}
|
|
36910
|
+
const since = await stat(lock).then(
|
|
36911
|
+
(info) => nowMs() - info.mtimeMs,
|
|
36912
|
+
() => 0
|
|
36913
|
+
);
|
|
36914
|
+
if (since > LOCK_STALE_MS) await rm(lock, { force: true });
|
|
36915
|
+
else await new Promise((resolve26) => setTimeout(resolve26, 15 + Math.random() * 20));
|
|
36916
|
+
}
|
|
36917
|
+
try {
|
|
36918
|
+
return await work();
|
|
36919
|
+
} finally {
|
|
36920
|
+
await rm(lock, { force: true });
|
|
36921
|
+
}
|
|
36922
|
+
}
|
|
36923
|
+
|
|
36924
|
+
// src/services/config-store.service.ts
|
|
36785
36925
|
var EMPTY = { profiles: {}, bindings: {} };
|
|
36786
36926
|
var ConfigStore = class _ConfigStore {
|
|
36787
36927
|
constructor(path) {
|
|
@@ -36792,21 +36932,35 @@ var ConfigStore = class _ConfigStore {
|
|
|
36792
36932
|
return new _ConfigStore(path);
|
|
36793
36933
|
}
|
|
36794
36934
|
async read() {
|
|
36795
|
-
|
|
36796
|
-
|
|
36797
|
-
return { ...EMPTY, ...parsed };
|
|
36798
|
-
} catch (error63) {
|
|
36799
|
-
if (error63.code === "ENOENT") return EMPTY;
|
|
36935
|
+
const text3 = await readFile2(this.path, "utf8").catch((error63) => {
|
|
36936
|
+
if (error63.code === "ENOENT") return void 0;
|
|
36800
36937
|
throw error63;
|
|
36801
|
-
}
|
|
36938
|
+
});
|
|
36939
|
+
if (text3 === void 0) return EMPTY;
|
|
36940
|
+
const read4 = stateTextOf({ text: text3 });
|
|
36941
|
+
if (read4.kind === "damaged") {
|
|
36942
|
+
throw new Error(`${this.path} is not valid JSON; move it aside and sign in again.`);
|
|
36943
|
+
}
|
|
36944
|
+
return { ...EMPTY, ...read4.value };
|
|
36945
|
+
}
|
|
36946
|
+
/** Applies `change` to the newest config under the lock; undefined from it writes nothing. */
|
|
36947
|
+
async update(change2) {
|
|
36948
|
+
return withStateLock({
|
|
36949
|
+
path: this.path,
|
|
36950
|
+
work: async () => {
|
|
36951
|
+
const { config: config2, result: result2 } = change2(await this.read());
|
|
36952
|
+
if (config2) await writeStateJson({ path: this.path, value: config2, pretty: true });
|
|
36953
|
+
return result2;
|
|
36954
|
+
}
|
|
36955
|
+
});
|
|
36802
36956
|
}
|
|
36957
|
+
/** Sets the profile used outside bound folders. */
|
|
36958
|
+
async setCurrent({ name: name3 }) {
|
|
36959
|
+
await this.update((config2) => ({ config: { ...config2, current: name3 }, result: void 0 }));
|
|
36960
|
+
}
|
|
36961
|
+
/** Replaces the whole config; for tests and first setup, where nothing else writes. */
|
|
36803
36962
|
async write(config2) {
|
|
36804
|
-
await
|
|
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);
|
|
36963
|
+
await this.update(() => ({ config: config2, result: void 0 }));
|
|
36810
36964
|
}
|
|
36811
36965
|
async saveProfile({
|
|
36812
36966
|
name: name3,
|
|
@@ -36814,32 +36968,37 @@ var ConfigStore = class _ConfigStore {
|
|
|
36814
36968
|
bindDirectory,
|
|
36815
36969
|
onlyThere = false
|
|
36816
36970
|
}) {
|
|
36817
|
-
|
|
36818
|
-
|
|
36819
|
-
|
|
36820
|
-
|
|
36821
|
-
|
|
36822
|
-
|
|
36823
|
-
|
|
36971
|
+
await this.update((config2) => ({
|
|
36972
|
+
result: void 0,
|
|
36973
|
+
config: {
|
|
36974
|
+
...config2,
|
|
36975
|
+
current: bindDirectory && (onlyThere || config2.current) ? config2.current : name3,
|
|
36976
|
+
profiles: { ...config2.profiles, [name3]: profile },
|
|
36977
|
+
bindings: bindDirectory ? { ...config2.bindings, [resolve(bindDirectory)]: name3 } : config2.bindings
|
|
36978
|
+
}
|
|
36979
|
+
}));
|
|
36824
36980
|
}
|
|
36825
36981
|
/** Keeps a profile beside the others: never the current one, bound to no folder. */
|
|
36826
36982
|
async keepProfile({ name: name3, profile }) {
|
|
36827
|
-
|
|
36828
|
-
|
|
36983
|
+
await this.update((config2) => ({
|
|
36984
|
+
result: void 0,
|
|
36985
|
+
config: { ...config2, profiles: { ...config2.profiles, [name3]: profile } }
|
|
36986
|
+
}));
|
|
36829
36987
|
}
|
|
36830
36988
|
/** Binds a harness session to a profile, so its hooks use it whatever the folder says. */
|
|
36831
36989
|
async bindSession({ session, profile }) {
|
|
36832
|
-
|
|
36833
|
-
|
|
36990
|
+
await this.update((config2) => ({
|
|
36991
|
+
result: void 0,
|
|
36992
|
+
config: { ...config2, sessions: { ...config2.sessions, [session]: profile } }
|
|
36993
|
+
}));
|
|
36834
36994
|
}
|
|
36835
36995
|
/** Keeps a profile's agent name in step with Laze; a missing or unchanged profile stays. */
|
|
36836
36996
|
async renameProfileAgent({ name: name3, agentName }) {
|
|
36837
|
-
|
|
36838
|
-
|
|
36839
|
-
|
|
36840
|
-
|
|
36841
|
-
...config2,
|
|
36842
|
-
profiles: { ...config2.profiles, [name3]: { ...profile, name: agentName } }
|
|
36997
|
+
await this.update((config2) => {
|
|
36998
|
+
const profile = config2.profiles[name3];
|
|
36999
|
+
if (!profile || profile.name === agentName) return { result: void 0 };
|
|
37000
|
+
const profiles2 = { ...config2.profiles, [name3]: { ...profile, name: agentName } };
|
|
37001
|
+
return { result: void 0, config: { ...config2, profiles: profiles2 } };
|
|
36843
37002
|
});
|
|
36844
37003
|
}
|
|
36845
37004
|
/** Sets or clears how the connect service delivers to a profile; false when there is none. */
|
|
@@ -36847,43 +37006,48 @@ var ConfigStore = class _ConfigStore {
|
|
|
36847
37006
|
name: name3,
|
|
36848
37007
|
delivery
|
|
36849
37008
|
}) {
|
|
36850
|
-
|
|
36851
|
-
|
|
36852
|
-
|
|
36853
|
-
|
|
36854
|
-
|
|
36855
|
-
|
|
36856
|
-
|
|
37009
|
+
return this.update((config2) => {
|
|
37010
|
+
const profile = config2.profiles[name3];
|
|
37011
|
+
if (!profile) return { result: false };
|
|
37012
|
+
const { delivery: _old, ...rest } = profile;
|
|
37013
|
+
const updated = delivery ? { ...rest, delivery } : rest;
|
|
37014
|
+
return {
|
|
37015
|
+
result: true,
|
|
37016
|
+
config: { ...config2, profiles: { ...config2.profiles, [name3]: updated } }
|
|
37017
|
+
};
|
|
37018
|
+
});
|
|
36857
37019
|
}
|
|
36858
37020
|
/** Marks a profile migrated; false when there is none. */
|
|
36859
37021
|
async markMigrated({ name: name3, migrated }) {
|
|
36860
|
-
|
|
36861
|
-
|
|
36862
|
-
|
|
36863
|
-
|
|
36864
|
-
...config2,
|
|
36865
|
-
profiles: { ...config2.profiles, [name3]: { ...profile, migrated } }
|
|
37022
|
+
return this.update((config2) => {
|
|
37023
|
+
const profile = config2.profiles[name3];
|
|
37024
|
+
if (!profile) return { result: false };
|
|
37025
|
+
const profiles2 = { ...config2.profiles, [name3]: { ...profile, migrated } };
|
|
37026
|
+
return { result: true, config: { ...config2, profiles: profiles2 } };
|
|
36866
37027
|
});
|
|
36867
|
-
return true;
|
|
36868
37028
|
}
|
|
36869
37029
|
async removeProfile({ name: name3 }) {
|
|
36870
|
-
|
|
36871
|
-
|
|
36872
|
-
|
|
36873
|
-
|
|
36874
|
-
);
|
|
36875
|
-
const bindings = Object.fromEntries(
|
|
36876
|
-
Object.entries(config2.bindings).filter(([, bound]) => bound !== name3)
|
|
36877
|
-
);
|
|
36878
|
-
const sessions = Object.fromEntries(
|
|
36879
|
-
Object.entries(config2.sessions ?? {}).filter(([, bound]) => bound !== name3)
|
|
36880
|
-
);
|
|
36881
|
-
const usable = Object.keys(profiles2).find((key) => profiles2[key]?.kind !== "request");
|
|
36882
|
-
const current3 = config2.current === name3 ? usable : config2.current;
|
|
36883
|
-
await this.write({ current: current3, profiles: profiles2, bindings, sessions });
|
|
36884
|
-
return true;
|
|
37030
|
+
return this.update((config2) => {
|
|
37031
|
+
const removed = withoutProfile({ config: config2, name: name3 });
|
|
37032
|
+
return removed ? { result: true, config: removed } : { result: false };
|
|
37033
|
+
});
|
|
36885
37034
|
}
|
|
36886
37035
|
};
|
|
37036
|
+
function withoutProfile({ config: config2, name: name3 }) {
|
|
37037
|
+
if (!config2.profiles[name3]) return void 0;
|
|
37038
|
+
const profiles2 = Object.fromEntries(
|
|
37039
|
+
Object.entries(config2.profiles).filter(([key]) => key !== name3)
|
|
37040
|
+
);
|
|
37041
|
+
const bindings = Object.fromEntries(
|
|
37042
|
+
Object.entries(config2.bindings).filter(([, bound]) => bound !== name3)
|
|
37043
|
+
);
|
|
37044
|
+
const sessions = Object.fromEntries(
|
|
37045
|
+
Object.entries(config2.sessions ?? {}).filter(([, bound]) => bound !== name3)
|
|
37046
|
+
);
|
|
37047
|
+
const usable = Object.keys(profiles2).find((key) => profiles2[key]?.kind !== "request");
|
|
37048
|
+
const current3 = config2.current === name3 ? usable : config2.current;
|
|
37049
|
+
return { current: current3, profiles: profiles2, bindings, sessions };
|
|
37050
|
+
}
|
|
36887
37051
|
function chooseProfile({
|
|
36888
37052
|
config: config2,
|
|
36889
37053
|
flag: flag2,
|
|
@@ -36896,9 +37060,9 @@ function chooseProfile({
|
|
|
36896
37060
|
return name3 && profile ? { name: name3, profile } : { name: void 0, profile: void 0 };
|
|
36897
37061
|
}
|
|
36898
37062
|
function isWorktreeRoot({ directory }) {
|
|
36899
|
-
const parent =
|
|
36900
|
-
if (
|
|
36901
|
-
return
|
|
37063
|
+
const parent = dirname2(directory);
|
|
37064
|
+
if (basename2(parent) === ".worktrees") return true;
|
|
37065
|
+
return basename2(parent) === "worktrees" && basename2(dirname2(parent)) === ".claude";
|
|
36902
37066
|
}
|
|
36903
37067
|
function boundProfileOf({
|
|
36904
37068
|
bindings,
|
|
@@ -36908,7 +37072,7 @@ function boundProfileOf({
|
|
|
36908
37072
|
for (let depth = 0; depth < 64; depth += 1) {
|
|
36909
37073
|
const bound = bindings[directory];
|
|
36910
37074
|
if (bound) return bound;
|
|
36911
|
-
const parent =
|
|
37075
|
+
const parent = dirname2(directory);
|
|
36912
37076
|
if (parent === directory || isWorktreeRoot({ directory })) return void 0;
|
|
36913
37077
|
directory = parent;
|
|
36914
37078
|
}
|
|
@@ -36990,7 +37154,7 @@ function flagText({
|
|
|
36990
37154
|
}
|
|
36991
37155
|
|
|
36992
37156
|
// src/rules/cli-version.rules.ts
|
|
36993
|
-
var STAMPED = "0.1.
|
|
37157
|
+
var STAMPED = "0.1.88";
|
|
36994
37158
|
function cliVersionOf({ stamped = STAMPED } = {}) {
|
|
36995
37159
|
return stamped.startsWith("__") ? "dev" : stamped;
|
|
36996
37160
|
}
|
|
@@ -42189,7 +42353,7 @@ function bucketFor(state, inst) {
|
|
|
42189
42353
|
return bucket;
|
|
42190
42354
|
}
|
|
42191
42355
|
var handoff;
|
|
42192
|
-
var
|
|
42356
|
+
var open2 = [];
|
|
42193
42357
|
var memo = {
|
|
42194
42358
|
alloc(_inst, payload, empty) {
|
|
42195
42359
|
const bucket = handoff;
|
|
@@ -42198,7 +42362,7 @@ var memo = {
|
|
|
42198
42362
|
handoff = void 0;
|
|
42199
42363
|
const entry = { value: empty, issues: null };
|
|
42200
42364
|
bucket.set(payload.value, entry);
|
|
42201
|
-
|
|
42365
|
+
open2.push(entry);
|
|
42202
42366
|
return empty;
|
|
42203
42367
|
},
|
|
42204
42368
|
guard(inst) {
|
|
@@ -42269,10 +42433,10 @@ var memo = {
|
|
|
42269
42433
|
return payload;
|
|
42270
42434
|
}
|
|
42271
42435
|
handoff = bucket;
|
|
42272
|
-
const depth =
|
|
42436
|
+
const depth = open2.length;
|
|
42273
42437
|
const result2 = base(payload, ctx);
|
|
42274
42438
|
handoff = void 0;
|
|
42275
|
-
const entry =
|
|
42439
|
+
const entry = open2.length > depth ? open2.pop() : void 0;
|
|
42276
42440
|
if (result2 instanceof Promise) {
|
|
42277
42441
|
return result2.then((r) => {
|
|
42278
42442
|
if (entry)
|
|
@@ -60239,6 +60403,8 @@ var vaultUseInputSchemaDefinition = external_exports.object({
|
|
|
60239
60403
|
requiredScopes: external_exports.array(external_exports.string().min(1)).default([]),
|
|
60240
60404
|
/** A floor on the connection's sensitivity, for a tool its owner marked more guarded. */
|
|
60241
60405
|
atLeast: vaultSensitivitySchema.optional(),
|
|
60406
|
+
/** The tool `atLeast` is for: when that floor alone asks, Allow for a set time covers it. */
|
|
60407
|
+
leaseScope: external_exports.string().min(1).max(200).optional(),
|
|
60242
60408
|
/** The caller knows the use only reads, such as an MCP tool marked read-only. */
|
|
60243
60409
|
readOnly: external_exports.boolean().default(false),
|
|
60244
60410
|
/** A use that would ask comes back denied with no card: a lookup made only for another card. */
|
|
@@ -61170,11 +61336,11 @@ var FENCE = /^\s*(?:>\s?)*(`{3,}|~{3,})/;
|
|
|
61170
61336
|
var BLANK = /^\s*(?:>\s*)*$/;
|
|
61171
61337
|
function segmentsOf({ lines: lines2 }) {
|
|
61172
61338
|
const out = [];
|
|
61173
|
-
let
|
|
61339
|
+
let open6 = null;
|
|
61174
61340
|
let fence = null;
|
|
61175
61341
|
const close = (end) => {
|
|
61176
|
-
if (
|
|
61177
|
-
|
|
61342
|
+
if (open6 && end >= open6.start) out.push({ start: open6.start, end, fenced: open6.fenced });
|
|
61343
|
+
open6 = null;
|
|
61178
61344
|
};
|
|
61179
61345
|
lines2.forEach((line, index) => {
|
|
61180
61346
|
const marker = FENCE.exec(line)?.[1];
|
|
@@ -61182,7 +61348,7 @@ function segmentsOf({ lines: lines2 }) {
|
|
|
61182
61348
|
if (marker && marker[0] === fence[0] && marker.length >= fence.length) {
|
|
61183
61349
|
close(index - 1);
|
|
61184
61350
|
fence = null;
|
|
61185
|
-
} else if (!
|
|
61351
|
+
} else if (!open6) open6 = { start: index, fenced: true };
|
|
61186
61352
|
return;
|
|
61187
61353
|
}
|
|
61188
61354
|
if (marker) {
|
|
@@ -61191,7 +61357,7 @@ function segmentsOf({ lines: lines2 }) {
|
|
|
61191
61357
|
return;
|
|
61192
61358
|
}
|
|
61193
61359
|
if (BLANK.test(line)) close(index - 1);
|
|
61194
|
-
else if (!
|
|
61360
|
+
else if (!open6) open6 = { start: index, fenced: false };
|
|
61195
61361
|
});
|
|
61196
61362
|
close(lines2.length - 1);
|
|
61197
61363
|
return out;
|
|
@@ -62208,6 +62374,7 @@ var mirrorSourceSchema = external_exports.enum([
|
|
|
62208
62374
|
"laze"
|
|
62209
62375
|
]);
|
|
62210
62376
|
var mirrorDeliverySchema = external_exports.enum(["waiting", "failed"]);
|
|
62377
|
+
var mirrorDeliveryStateSchema = external_exports.enum(["waiting", "failed", "edit_kept"]);
|
|
62211
62378
|
var messageOriginSchemaDefinition = external_exports.object({
|
|
62212
62379
|
source: mirrorSourceSchema,
|
|
62213
62380
|
/** The message's key at the source, unique in the workspace (e.g. `slack:T1:C1:1792.0001`). */
|
|
@@ -62608,6 +62775,8 @@ var messageSchemaDefinition = external_exports.object({
|
|
|
62608
62775
|
images: external_exports.record(external_exports.string().max(2e3), external_exports.string().max(5e3)).optional(),
|
|
62609
62776
|
/** A message written in Laze that its mirror is still waiting to send, or could not send. */
|
|
62610
62777
|
mirrorDelivery: mirrorDeliverySchema.nullable().optional(),
|
|
62778
|
+
/** Set when the source would not take the last edit of this sent message: it is only in Laze. */
|
|
62779
|
+
mirrorEditKept: external_exports.boolean().optional(),
|
|
62611
62780
|
/** A thread reply also sent to its conversation: it shows in the thread and the channel. */
|
|
62612
62781
|
alsoInChannel: external_exports.boolean().optional(),
|
|
62613
62782
|
/** For a reply also sent to the channel: its root's text, for the "replied to a thread" line. */
|
|
@@ -63089,7 +63258,7 @@ var pinMirroredInputSchemaDefinition = external_exports.object({
|
|
|
63089
63258
|
var setMirrorDeliveryInputSchemaDefinition = external_exports.object({
|
|
63090
63259
|
workspaceId: workspaceIdSchema,
|
|
63091
63260
|
messageId: idSchema4,
|
|
63092
|
-
state:
|
|
63261
|
+
state: mirrorDeliveryStateSchema.nullable()
|
|
63093
63262
|
});
|
|
63094
63263
|
var reactMirroredInputSchemaDefinition = external_exports.object({
|
|
63095
63264
|
workspaceId: workspaceIdSchema,
|
|
@@ -70008,13 +70177,11 @@ function errorOf({ status: status11, body }) {
|
|
|
70008
70177
|
|
|
70009
70178
|
// src/services/machine-report.service.ts
|
|
70010
70179
|
import { createHash } from "node:crypto";
|
|
70011
|
-
import {
|
|
70180
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
70012
70181
|
import { hostname as hostname3 } from "node:os";
|
|
70013
|
-
import { dirname as dirname3 } from "node:path";
|
|
70014
70182
|
|
|
70015
70183
|
// src/services/inbox-spool.service.ts
|
|
70016
|
-
import {
|
|
70017
|
-
import { dirname as dirname2, join as join2 } from "node:path";
|
|
70184
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
70018
70185
|
var PUSH_GRACE_MS = 3 * 6e4;
|
|
70019
70186
|
var IN_FLIGHT_MS = 35e3;
|
|
70020
70187
|
function fileNameOf({ profile }) {
|
|
@@ -70026,20 +70193,14 @@ function statePathOf({
|
|
|
70026
70193
|
profile,
|
|
70027
70194
|
extension: extension2 = "json"
|
|
70028
70195
|
}) {
|
|
70029
|
-
const directory =
|
|
70030
|
-
return
|
|
70196
|
+
const directory = join3(dirname3(context.environment.configPath), kind2);
|
|
70197
|
+
return join3(directory, `${fileNameOf({ profile })}.${extension2}`);
|
|
70031
70198
|
}
|
|
70032
70199
|
async function readSpool({ path }) {
|
|
70033
|
-
return
|
|
70034
|
-
(text3) => JSON.parse(text3),
|
|
70035
|
-
() => []
|
|
70036
|
-
);
|
|
70200
|
+
return await readStateJson({ path }) ?? [];
|
|
70037
70201
|
}
|
|
70038
70202
|
async function writeSpool({ path, entries }) {
|
|
70039
|
-
await
|
|
70040
|
-
const temporary = `${path}.${process.pid}.tmp`;
|
|
70041
|
-
await writeFile2(temporary, JSON.stringify(entries), { mode: 384 });
|
|
70042
|
-
await rename2(temporary, path);
|
|
70203
|
+
await writeStateJson({ path, value: entries });
|
|
70043
70204
|
}
|
|
70044
70205
|
async function keepTaken({
|
|
70045
70206
|
context,
|
|
@@ -70106,11 +70267,11 @@ async function reportMachine({
|
|
|
70106
70267
|
if (!host2) return;
|
|
70107
70268
|
const stamp = createHash("sha256").update(`${token2}:${host2}`).digest("hex");
|
|
70108
70269
|
const path = statePathOf({ context, kind: "machine", profile });
|
|
70109
|
-
|
|
70270
|
+
const noted = await readFile3(path, "utf8").catch(() => "");
|
|
70271
|
+
if (noted === JSON.stringify(stamp) || noted === stamp) return;
|
|
70110
70272
|
try {
|
|
70111
70273
|
await client.post("/api/agents/me/machine", { host: host2 });
|
|
70112
|
-
await
|
|
70113
|
-
await writeFile3(path, stamp, { mode: 384 });
|
|
70274
|
+
await writeStateText({ path, text: JSON.stringify(stamp) });
|
|
70114
70275
|
} catch {
|
|
70115
70276
|
return;
|
|
70116
70277
|
}
|
|
@@ -70403,8 +70564,8 @@ async function copyAgent({
|
|
|
70403
70564
|
}
|
|
70404
70565
|
|
|
70405
70566
|
// src/services/agent-commands.service.ts
|
|
70406
|
-
import { mkdir as
|
|
70407
|
-
import { join as
|
|
70567
|
+
import { mkdir as mkdir5, readFile as readFile11, writeFile as writeFile3 } from "node:fs/promises";
|
|
70568
|
+
import { join as join19, resolve as resolve5 } from "node:path";
|
|
70408
70569
|
|
|
70409
70570
|
// src/rules/agent-profile.rules.ts
|
|
70410
70571
|
var HARNESS_NAMES = {
|
|
@@ -71694,13 +71855,13 @@ function formatSearch({
|
|
|
71694
71855
|
}
|
|
71695
71856
|
|
|
71696
71857
|
// src/services/claude-turn.service.ts
|
|
71697
|
-
import {
|
|
71698
|
-
import { dirname as dirname5, join as
|
|
71858
|
+
import { rm as rm2 } from "node:fs/promises";
|
|
71859
|
+
import { dirname as dirname5, join as join6 } from "node:path";
|
|
71699
71860
|
|
|
71700
71861
|
// src/services/harness-session.service.ts
|
|
71701
|
-
import {
|
|
71862
|
+
import { open as open3, readdir, readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
71702
71863
|
import { homedir as homedir2, hostname as hostname4 } from "node:os";
|
|
71703
|
-
import { dirname as dirname4, join as
|
|
71864
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
71704
71865
|
|
|
71705
71866
|
// src/rules/claude-subagent.rules.ts
|
|
71706
71867
|
function lastCallAtOf({ text: text3, command }) {
|
|
@@ -71794,9 +71955,9 @@ function launchEnvOf({
|
|
|
71794
71955
|
}
|
|
71795
71956
|
|
|
71796
71957
|
// src/services/claude-project.service.ts
|
|
71797
|
-
import { basename as
|
|
71958
|
+
import { basename as basename3, isAbsolute, relative as relative2, resolve as resolve2 } from "node:path";
|
|
71798
71959
|
function harnessIn({ words }) {
|
|
71799
|
-
const names = words.slice(0, 2).map((word3) =>
|
|
71960
|
+
const names = words.slice(0, 2).map((word3) => basename3(word3).replace(/\.(js|mjs|cjs)$/, ""));
|
|
71800
71961
|
if (names.includes("codex")) return "codex";
|
|
71801
71962
|
if (words.some((word3) => word3.includes("@openai/codex"))) return "codex";
|
|
71802
71963
|
const claude = words.some((word3) => word3.includes("@anthropic-ai/claude-code"));
|
|
@@ -71861,9 +72022,8 @@ async function rememberSession({
|
|
|
71861
72022
|
}) {
|
|
71862
72023
|
if (!session || !claudePid) return;
|
|
71863
72024
|
const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
|
|
71864
|
-
await mkdir4(dirname4(path), { recursive: true, mode: 448 });
|
|
71865
72025
|
const launch = launchEnvOf({ inherited: context.environment.inherited });
|
|
71866
|
-
await
|
|
72026
|
+
await writeStateJson({ path, value: { ...session, launch } });
|
|
71867
72027
|
}
|
|
71868
72028
|
async function currentSessionOf({
|
|
71869
72029
|
context,
|
|
@@ -71882,10 +72042,7 @@ async function currentSessionOf({
|
|
|
71882
72042
|
const nearest = await nearestHarnessOf({ context });
|
|
71883
72043
|
if (!nearest) return void 0;
|
|
71884
72044
|
const path = statePathOf({ context, kind: "sessions", profile: String(nearest.pid) });
|
|
71885
|
-
return
|
|
71886
|
-
(text3) => JSON.parse(text3),
|
|
71887
|
-
() => void 0
|
|
71888
|
-
);
|
|
72045
|
+
return readStateJson({ path });
|
|
71889
72046
|
}
|
|
71890
72047
|
async function sessionProfileArgs({
|
|
71891
72048
|
context,
|
|
@@ -71939,10 +72096,7 @@ async function liveElsewhere({
|
|
|
71939
72096
|
for (const file4 of await readdir(folder).catch(() => [])) {
|
|
71940
72097
|
const pid = Number(file4.replace(/\.json$/, ""));
|
|
71941
72098
|
if (!pid || pid === claudePid || !context.processes.alive(pid)) continue;
|
|
71942
|
-
const noted = await
|
|
71943
|
-
(text3) => JSON.parse(text3),
|
|
71944
|
-
() => void 0
|
|
71945
|
-
);
|
|
72099
|
+
const noted = await readStateJson({ path: join4(folder, file4) });
|
|
71946
72100
|
if (noted && sessionKeyOf({ session: noted }) === key) return true;
|
|
71947
72101
|
}
|
|
71948
72102
|
return false;
|
|
@@ -71952,15 +72106,15 @@ async function claudeTranscriptOf({
|
|
|
71952
72106
|
sessionId
|
|
71953
72107
|
}) {
|
|
71954
72108
|
const inherited = context.environment.inherited;
|
|
71955
|
-
const root =
|
|
71956
|
-
inherited.CLAUDE_CONFIG_DIR ||
|
|
72109
|
+
const root = join4(
|
|
72110
|
+
inherited.CLAUDE_CONFIG_DIR || join4(inherited.HOME || homedir2(), ".claude"),
|
|
71957
72111
|
"projects"
|
|
71958
72112
|
);
|
|
71959
72113
|
const folders = await readdir(root).catch(() => []);
|
|
71960
72114
|
const found = await Promise.all(
|
|
71961
72115
|
folders.map(async (folder) => {
|
|
71962
|
-
const path =
|
|
71963
|
-
return
|
|
72116
|
+
const path = join4(root, folder, `${sessionId}.jsonl`);
|
|
72117
|
+
return stat2(path).then(
|
|
71964
72118
|
(info) => info.isFile() ? [{ path, at: info.mtimeMs }] : [],
|
|
71965
72119
|
() => []
|
|
71966
72120
|
);
|
|
@@ -71970,7 +72124,7 @@ async function claudeTranscriptOf({
|
|
|
71970
72124
|
}
|
|
71971
72125
|
var TAIL_BYTES = 512 * 1024;
|
|
71972
72126
|
async function tailOf({ path }) {
|
|
71973
|
-
const handle = await
|
|
72127
|
+
const handle = await open3(path, "r").catch(() => void 0);
|
|
71974
72128
|
if (!handle) return "";
|
|
71975
72129
|
try {
|
|
71976
72130
|
const { size } = await handle.stat();
|
|
@@ -71987,11 +72141,11 @@ async function runsInSubagent({ context, command }) {
|
|
|
71987
72141
|
if (!sessionId) return false;
|
|
71988
72142
|
const { path } = await claudeTranscriptOf({ context, sessionId });
|
|
71989
72143
|
if (!path) return false;
|
|
71990
|
-
const folder =
|
|
72144
|
+
const folder = join4(dirname4(path), sessionId, "subagents");
|
|
71991
72145
|
const files2 = await readdir(folder).catch(() => []);
|
|
71992
72146
|
const subagents = await Promise.all(
|
|
71993
72147
|
files2.filter((file4) => file4.endsWith(".jsonl")).map(
|
|
71994
|
-
async (file4) => lastCallAtOf({ text: await tailOf({ path:
|
|
72148
|
+
async (file4) => lastCallAtOf({ text: await tailOf({ path: join4(folder, file4) }), command })
|
|
71995
72149
|
)
|
|
71996
72150
|
);
|
|
71997
72151
|
const session = lastCallAtOf({ text: await tailOf({ path }), command });
|
|
@@ -72056,8 +72210,7 @@ async function notBoundNotice({
|
|
|
72056
72210
|
() => false
|
|
72057
72211
|
);
|
|
72058
72212
|
if (told) return { notice: void 0 };
|
|
72059
|
-
await
|
|
72060
|
-
await writeFile4(path, String(context.nowMs()), { mode: 384 });
|
|
72213
|
+
await writeStateText({ path, text: String(context.nowMs()) });
|
|
72061
72214
|
const agent3 = (await context.store.read()).profiles[profile]?.name;
|
|
72062
72215
|
return {
|
|
72063
72216
|
notice: notBoundText({ meta: meta3, agent: agent3, configPath: context.environment.configPath })
|
|
@@ -72066,7 +72219,7 @@ async function notBoundNotice({
|
|
|
72066
72219
|
|
|
72067
72220
|
// src/services/plugin-hook.service.ts
|
|
72068
72221
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
72069
|
-
import { join as
|
|
72222
|
+
import { join as join5 } from "node:path";
|
|
72070
72223
|
async function agentProfileHere({
|
|
72071
72224
|
context,
|
|
72072
72225
|
args,
|
|
@@ -72087,11 +72240,8 @@ async function agentProfileHere({
|
|
|
72087
72240
|
}
|
|
72088
72241
|
async function projectHooksHere({ context }) {
|
|
72089
72242
|
const directory = context.environment.inherited.CLAUDE_PROJECT_DIR || context.cwd;
|
|
72090
|
-
const path =
|
|
72091
|
-
return readFile6(path, "utf8").then(
|
|
72092
|
-
(text3) => hasLazeHooks({ settings: JSON.parse(text3) }),
|
|
72093
|
-
() => false
|
|
72094
|
-
);
|
|
72243
|
+
const path = join5(directory, ".claude", "settings.local.json");
|
|
72244
|
+
return readFile6(path, "utf8").then((text3) => hasLazeHooks({ settings: JSON.parse(text3) })).catch(() => false);
|
|
72095
72245
|
}
|
|
72096
72246
|
async function pluginHookArgs({
|
|
72097
72247
|
context,
|
|
@@ -72109,13 +72259,10 @@ async function pluginHookArgs({
|
|
|
72109
72259
|
var PRE_TOOL_TIMEOUT_MS = 3e3;
|
|
72110
72260
|
function statePath({ context, agent: agent3 }) {
|
|
72111
72261
|
const safe = agent3.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
72112
|
-
return
|
|
72262
|
+
return join6(dirname5(context.environment.configPath), "turns", `${safe}.json`);
|
|
72113
72263
|
}
|
|
72114
72264
|
async function readState({ context, agent: agent3 }) {
|
|
72115
|
-
return
|
|
72116
|
-
(text3) => JSON.parse(text3),
|
|
72117
|
-
() => void 0
|
|
72118
|
-
);
|
|
72265
|
+
return readStateJson({ path: statePath({ context, agent: agent3 }) });
|
|
72119
72266
|
}
|
|
72120
72267
|
function beat({
|
|
72121
72268
|
client,
|
|
@@ -72167,8 +72314,7 @@ async function turnStarted({
|
|
|
72167
72314
|
await beat({ client, state: opened, working: true }).catch(() => void 0);
|
|
72168
72315
|
}
|
|
72169
72316
|
const path = statePath({ context, agent: agent3 });
|
|
72170
|
-
await
|
|
72171
|
-
await writeFile5(path, JSON.stringify(state));
|
|
72317
|
+
await writeStateJson({ path, value: state });
|
|
72172
72318
|
await beat({ client, state, working: true }).catch(() => void 0);
|
|
72173
72319
|
}
|
|
72174
72320
|
async function turnEnded({
|
|
@@ -72178,7 +72324,7 @@ async function turnEnded({
|
|
|
72178
72324
|
}) {
|
|
72179
72325
|
const state = await readState({ context, agent: agent3 });
|
|
72180
72326
|
if (!state) return;
|
|
72181
|
-
await
|
|
72327
|
+
await rm2(statePath({ context, agent: agent3 }), { force: true });
|
|
72182
72328
|
await beat({ client, state, working: false }).catch(() => void 0);
|
|
72183
72329
|
}
|
|
72184
72330
|
async function preToolHook({ context, args }) {
|
|
@@ -72226,8 +72372,8 @@ async function preToolHook({ context, args }) {
|
|
|
72226
72372
|
}
|
|
72227
72373
|
|
|
72228
72374
|
// src/services/message-files.service.ts
|
|
72229
|
-
import { readFile as
|
|
72230
|
-
import { basename as
|
|
72375
|
+
import { readFile as readFile7, stat as stat3 } from "node:fs/promises";
|
|
72376
|
+
import { basename as basename4, resolve as resolve3 } from "node:path";
|
|
72231
72377
|
|
|
72232
72378
|
// src/rules/file-types.rules.ts
|
|
72233
72379
|
var TYPES = {
|
|
@@ -72325,7 +72471,7 @@ async function readyOf({ context, source }) {
|
|
|
72325
72471
|
return asBytes({ source, file: await downloaded({ context, url: value }) });
|
|
72326
72472
|
}
|
|
72327
72473
|
const full = resolve3(context.cwd, value);
|
|
72328
|
-
const found = await
|
|
72474
|
+
const found = await stat3(full).catch(() => void 0);
|
|
72329
72475
|
if (found?.isFile()) return asBytes({ source, file: await local({ full }) });
|
|
72330
72476
|
const marked = fileMarkerIdsIn(value)[0] ?? (UPLOADED_ID.test(value) ? value : void 0);
|
|
72331
72477
|
if (marked) return { kind: "id", id: marked };
|
|
@@ -72342,7 +72488,7 @@ function asBytes({ source, file: file4 }) {
|
|
|
72342
72488
|
async function downloaded({ context, url: url2 }) {
|
|
72343
72489
|
const response = await context.fetcher(url2);
|
|
72344
72490
|
if (!response.ok) throw new CliUsageError(`${url2} answered ${response.status}`);
|
|
72345
|
-
const fileName =
|
|
72491
|
+
const fileName = basename4(new URL(url2).pathname) || "file";
|
|
72346
72492
|
const header = (response.headers.get("content-type") ?? "").split(";")[0]?.trim();
|
|
72347
72493
|
return {
|
|
72348
72494
|
fileName,
|
|
@@ -72351,11 +72497,11 @@ async function downloaded({ context, url: url2 }) {
|
|
|
72351
72497
|
};
|
|
72352
72498
|
}
|
|
72353
72499
|
async function local({ full }) {
|
|
72354
|
-
const fileName =
|
|
72500
|
+
const fileName = basename4(full);
|
|
72355
72501
|
return {
|
|
72356
72502
|
fileName,
|
|
72357
72503
|
contentType: contentTypeOf(fileName),
|
|
72358
|
-
bytes: new Uint8Array(await
|
|
72504
|
+
bytes: new Uint8Array(await readFile7(full))
|
|
72359
72505
|
};
|
|
72360
72506
|
}
|
|
72361
72507
|
async function attachmentIdsOf({
|
|
@@ -72978,13 +73124,12 @@ function channelLabelIn(channel) {
|
|
|
72978
73124
|
}
|
|
72979
73125
|
|
|
72980
73126
|
// src/services/claude-wait.service.ts
|
|
72981
|
-
import { readFile as
|
|
72982
|
-
import { dirname as dirname13 } from "node:path";
|
|
73127
|
+
import { readFile as readFile8, rm as rm5 } from "node:fs/promises";
|
|
72983
73128
|
|
|
72984
73129
|
// src/services/connect-service.service.ts
|
|
72985
73130
|
import { createHash as createHash2 } from "node:crypto";
|
|
72986
|
-
import { mkdir as
|
|
72987
|
-
import { dirname as dirname12, join as
|
|
73131
|
+
import { mkdir as mkdir3, rm as rm4, writeFile } from "node:fs/promises";
|
|
73132
|
+
import { dirname as dirname12, join as join14 } from "node:path";
|
|
72988
73133
|
|
|
72989
73134
|
// src/rules/connect-service.rules.ts
|
|
72990
73135
|
function systemdWordOf(word3) {
|
|
@@ -73106,31 +73251,31 @@ function rolloutEventOf({
|
|
|
73106
73251
|
}
|
|
73107
73252
|
|
|
73108
73253
|
// src/services/connect-delivery.service.ts
|
|
73109
|
-
import {
|
|
73254
|
+
import { rm as rm3, stat as stat5 } from "node:fs/promises";
|
|
73110
73255
|
import { homedir as homedir3, hostname as hostname5 } from "node:os";
|
|
73111
|
-
import { dirname as dirname11, join as
|
|
73256
|
+
import { dirname as dirname11, join as join13 } from "node:path";
|
|
73112
73257
|
|
|
73113
73258
|
// src/services/codex-turn-watch.service.ts
|
|
73114
|
-
import { open as
|
|
73115
|
-
import { basename as
|
|
73259
|
+
import { open as open4, readdir as readdir2 } from "node:fs/promises";
|
|
73260
|
+
import { basename as basename5, join as join7 } from "node:path";
|
|
73116
73261
|
var READ_MS = 1500;
|
|
73117
73262
|
var KEEP_WORKING_MS = 3e4;
|
|
73118
73263
|
async function codexRolloutPathOf({
|
|
73119
73264
|
codexHome,
|
|
73120
73265
|
threadId
|
|
73121
73266
|
}) {
|
|
73122
|
-
const root =
|
|
73267
|
+
const root = join7(codexHome, "sessions");
|
|
73123
73268
|
const files2 = await readdir2(root, { recursive: true }).catch(() => []);
|
|
73124
73269
|
const file4 = files2.find(
|
|
73125
|
-
(name3) =>
|
|
73270
|
+
(name3) => basename5(name3).startsWith("rollout-") && name3.endsWith(`-${threadId}.jsonl`)
|
|
73126
73271
|
);
|
|
73127
|
-
return file4 ?
|
|
73272
|
+
return file4 ? join7(root, file4) : void 0;
|
|
73128
73273
|
}
|
|
73129
73274
|
function rolloutPathOf({ delivery }) {
|
|
73130
73275
|
return codexRolloutPathOf({ codexHome: delivery.codexHome, threadId: delivery.threadId });
|
|
73131
73276
|
}
|
|
73132
73277
|
async function readFrom({ path, offset }) {
|
|
73133
|
-
const handle = await
|
|
73278
|
+
const handle = await open4(path, "r");
|
|
73134
73279
|
try {
|
|
73135
73280
|
const { size } = await handle.stat();
|
|
73136
73281
|
if (size <= offset) return { text: "", size };
|
|
@@ -73213,8 +73358,7 @@ var CodexTurnWatch = class _CodexTurnWatch {
|
|
|
73213
73358
|
};
|
|
73214
73359
|
|
|
73215
73360
|
// src/services/mcp-relay.service.ts
|
|
73216
|
-
import {
|
|
73217
|
-
import { dirname as dirname6, join as join7 } from "node:path";
|
|
73361
|
+
import { dirname as dirname6, join as join8 } from "node:path";
|
|
73218
73362
|
|
|
73219
73363
|
// ../../node_modules/.pnpm/ws@8.21.3_bufferutil@4.1.0/node_modules/ws/wrapper.mjs
|
|
73220
73364
|
var import_stream = __toESM(require_stream(), 1);
|
|
@@ -73550,24 +73694,17 @@ var STOPS = /* @__PURE__ */ new Map([
|
|
|
73550
73694
|
[CONNECTOR_RELAY_CLOSE.replaced.code, "another relay for this server took over"]
|
|
73551
73695
|
]);
|
|
73552
73696
|
function mcpRelaysPathOf({ context }) {
|
|
73553
|
-
return
|
|
73697
|
+
return join8(dirname6(context.environment.configPath), "connect", "mcp-relays.json");
|
|
73554
73698
|
}
|
|
73555
73699
|
async function readMcpRelays({ context }) {
|
|
73556
|
-
|
|
73557
|
-
return JSON.parse(await readFile9(mcpRelaysPathOf({ context }), "utf8"));
|
|
73558
|
-
} catch {
|
|
73559
|
-
return {};
|
|
73560
|
-
}
|
|
73700
|
+
return await readStateJson({ path: mcpRelaysPathOf({ context }) }) ?? {};
|
|
73561
73701
|
}
|
|
73562
73702
|
async function saveMcpRelays({
|
|
73563
73703
|
context,
|
|
73564
73704
|
relays
|
|
73565
73705
|
}) {
|
|
73566
73706
|
const path = mcpRelaysPathOf({ context });
|
|
73567
|
-
await
|
|
73568
|
-
await writeFile6(path, `${JSON.stringify(relays, null, 2)}
|
|
73569
|
-
`, { mode: 384 });
|
|
73570
|
-
await chmod2(path, 384);
|
|
73707
|
+
await writeStateJson({ path, value: relays, pretty: true });
|
|
73571
73708
|
}
|
|
73572
73709
|
function mcpRelaySocketUrlOf(url2) {
|
|
73573
73710
|
const parsed = new URL(CONNECTOR_RELAY_PATH, url2);
|
|
@@ -73717,8 +73854,7 @@ var McpRelayLoops = class _McpRelayLoops {
|
|
|
73717
73854
|
};
|
|
73718
73855
|
|
|
73719
73856
|
// src/services/openclaw-relay.service.ts
|
|
73720
|
-
import {
|
|
73721
|
-
import { dirname as dirname7, join as join8 } from "node:path";
|
|
73857
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
73722
73858
|
|
|
73723
73859
|
// ../../modules/openclaw/contract/src/openclaw.ts
|
|
73724
73860
|
var workspaceIdSchema18 = external_exports.string().min(1);
|
|
@@ -73939,24 +74075,17 @@ var STOPS2 = /* @__PURE__ */ new Map([
|
|
|
73939
74075
|
[OPENCLAW_RELAY_CLOSE.replaced.code, "another relay for this gateway took over"]
|
|
73940
74076
|
]);
|
|
73941
74077
|
function relaysPathOf({ context }) {
|
|
73942
|
-
return
|
|
74078
|
+
return join9(dirname7(context.environment.configPath), "connect", "openclaw-relays.json");
|
|
73943
74079
|
}
|
|
73944
74080
|
async function readRelays({ context }) {
|
|
73945
|
-
|
|
73946
|
-
return JSON.parse(await readFile10(relaysPathOf({ context }), "utf8"));
|
|
73947
|
-
} catch {
|
|
73948
|
-
return {};
|
|
73949
|
-
}
|
|
74081
|
+
return await readStateJson({ path: relaysPathOf({ context }) }) ?? {};
|
|
73950
74082
|
}
|
|
73951
74083
|
async function saveRelays({
|
|
73952
74084
|
context,
|
|
73953
74085
|
relays
|
|
73954
74086
|
}) {
|
|
73955
74087
|
const path = relaysPathOf({ context });
|
|
73956
|
-
await
|
|
73957
|
-
await writeFile7(path, `${JSON.stringify(relays, null, 2)}
|
|
73958
|
-
`, { mode: 384 });
|
|
73959
|
-
await chmod3(path, 384);
|
|
74088
|
+
await writeStateJson({ path, value: relays, pretty: true });
|
|
73960
74089
|
}
|
|
73961
74090
|
function relaySocketUrlOf(url2) {
|
|
73962
74091
|
const parsed = new URL(OPENCLAW_RELAY_PATH, url2);
|
|
@@ -74034,18 +74163,18 @@ var RelaySession = class {
|
|
|
74034
74163
|
if (!envelope) return;
|
|
74035
74164
|
const { line, payload } = envelope;
|
|
74036
74165
|
if (envelope.kind === "open") return this.dial(relay2, line);
|
|
74037
|
-
const
|
|
74038
|
-
if (!
|
|
74166
|
+
const open6 = this.#lines.get(line);
|
|
74167
|
+
if (!open6) return;
|
|
74039
74168
|
if (envelope.kind === "close") {
|
|
74040
74169
|
this.#lines.delete(line);
|
|
74041
|
-
|
|
74170
|
+
open6.socket.close(1e3);
|
|
74042
74171
|
return;
|
|
74043
74172
|
}
|
|
74044
74173
|
if (envelope.kind !== "text" && envelope.kind !== "binary") return;
|
|
74045
74174
|
const frame = { data: Buffer.from(payload), binary: envelope.kind === "binary" };
|
|
74046
|
-
if (
|
|
74047
|
-
|
|
74048
|
-
} else
|
|
74175
|
+
if (open6.socket.readyState === wrapper_default.OPEN) {
|
|
74176
|
+
open6.socket.send(frame.data, { binary: frame.binary });
|
|
74177
|
+
} else open6.waiting.push(frame);
|
|
74049
74178
|
}
|
|
74050
74179
|
/** Dials the gateway for a line; its frames go back to Laze as they came. */
|
|
74051
74180
|
dial(relay2, line) {
|
|
@@ -74139,12 +74268,11 @@ var RelayLoops = class _RelayLoops {
|
|
|
74139
74268
|
};
|
|
74140
74269
|
|
|
74141
74270
|
// src/services/rush-listeners.service.ts
|
|
74142
|
-
import {
|
|
74143
|
-
import { dirname as dirname9, join as
|
|
74271
|
+
import { readdir as readdir3, stat as stat4 } from "node:fs/promises";
|
|
74272
|
+
import { dirname as dirname9, join as join11 } from "node:path";
|
|
74144
74273
|
|
|
74145
74274
|
// src/services/rush-host.service.ts
|
|
74146
|
-
import {
|
|
74147
|
-
import { dirname as dirname8, join as join9 } from "node:path";
|
|
74275
|
+
import { dirname as dirname8, join as join10 } from "node:path";
|
|
74148
74276
|
async function rushAboveOf({
|
|
74149
74277
|
context,
|
|
74150
74278
|
from = context.processes.pid
|
|
@@ -74158,7 +74286,7 @@ async function rushAboveOf({
|
|
|
74158
74286
|
return void 0;
|
|
74159
74287
|
}
|
|
74160
74288
|
function guardPathOf({ context, claudePid }) {
|
|
74161
|
-
return
|
|
74289
|
+
return join10(dirname8(context.environment.configPath), "rush-guards", `${claudePid}.json`);
|
|
74162
74290
|
}
|
|
74163
74291
|
async function startRushGuard({
|
|
74164
74292
|
context,
|
|
@@ -74171,7 +74299,7 @@ async function startRushGuard({
|
|
|
74171
74299
|
if (holder && context.processes.alive(holder.pid)) return;
|
|
74172
74300
|
const flags2 = ["--profile", profile, "--claude-pid", String(claudePid), "--rush-id", rush.id];
|
|
74173
74301
|
const argv = [...context.program, "hook", "rush-wake", ...flags2, "--rush-program", rush.program];
|
|
74174
|
-
const logPath =
|
|
74302
|
+
const logPath = join10(dirname8(context.environment.configPath), "rush-guards", "guard.log");
|
|
74175
74303
|
context.processes.spawnDetached({ argv: ["sh", "-c", '"$@" &', "sh", ...argv], logPath });
|
|
74176
74304
|
}
|
|
74177
74305
|
async function claimRushGuard({
|
|
@@ -74179,26 +74307,24 @@ async function claimRushGuard({
|
|
|
74179
74307
|
claudePid
|
|
74180
74308
|
}) {
|
|
74181
74309
|
const path = guardPathOf({ context, claudePid });
|
|
74182
|
-
|
|
74183
|
-
|
|
74184
|
-
|
|
74185
|
-
|
|
74186
|
-
|
|
74187
|
-
|
|
74310
|
+
return withStateLock({
|
|
74311
|
+
path,
|
|
74312
|
+
work: async () => {
|
|
74313
|
+
const holder = await guardHolderOf({ path });
|
|
74314
|
+
const self2 = context.processes.pid;
|
|
74315
|
+
if (holder && holder.pid !== self2 && context.processes.alive(holder.pid)) return false;
|
|
74316
|
+
await writeStateJson({ path, value: { pid: self2, claudePid } });
|
|
74317
|
+
return true;
|
|
74318
|
+
}
|
|
74319
|
+
});
|
|
74188
74320
|
}
|
|
74189
74321
|
function guardHolderOf({ path }) {
|
|
74190
|
-
return
|
|
74191
|
-
(text3) => JSON.parse(text3),
|
|
74192
|
-
() => void 0
|
|
74193
|
-
);
|
|
74322
|
+
return readStateJson({ path });
|
|
74194
74323
|
}
|
|
74195
74324
|
|
|
74196
74325
|
// src/services/rush-listeners.service.ts
|
|
74197
74326
|
async function jsonOf(path) {
|
|
74198
|
-
return
|
|
74199
|
-
(text3) => JSON.parse(text3),
|
|
74200
|
-
() => void 0
|
|
74201
|
-
);
|
|
74327
|
+
return readStateJson({ path });
|
|
74202
74328
|
}
|
|
74203
74329
|
async function notesOf({ context }) {
|
|
74204
74330
|
const folder = dirname9(statePathOf({ context, kind: "sessions", profile: "x" }));
|
|
@@ -74206,8 +74332,8 @@ async function notesOf({ context }) {
|
|
|
74206
74332
|
const notes = await Promise.all(
|
|
74207
74333
|
files2.map(async (file4) => {
|
|
74208
74334
|
const pid = Number(file4.replace(/\.json$/, ""));
|
|
74209
|
-
const note = await jsonOf(
|
|
74210
|
-
const at = await
|
|
74335
|
+
const note = await jsonOf(join11(folder, file4));
|
|
74336
|
+
const at = await stat4(join11(folder, file4)).then(
|
|
74211
74337
|
(info) => info.mtimeMs,
|
|
74212
74338
|
() => 0
|
|
74213
74339
|
);
|
|
@@ -74287,8 +74413,8 @@ async function rearmRushGuards({ context }) {
|
|
|
74287
74413
|
}
|
|
74288
74414
|
|
|
74289
74415
|
// src/services/rush-watchdog.service.ts
|
|
74290
|
-
import { appendFile, mkdir as
|
|
74291
|
-
import { dirname as dirname10, join as
|
|
74416
|
+
import { appendFile, mkdir as mkdir2 } from "node:fs/promises";
|
|
74417
|
+
import { dirname as dirname10, join as join12 } from "node:path";
|
|
74292
74418
|
var UNDELIVERED_AFTER_MS = 6e4;
|
|
74293
74419
|
var CHECK_TIMEOUT_MS = 5e3;
|
|
74294
74420
|
function clientOf({ context, profile }) {
|
|
@@ -74307,9 +74433,9 @@ async function waitingOf({ context, profile }) {
|
|
|
74307
74433
|
const client = await clientOf({ context, profile });
|
|
74308
74434
|
return client?.get("/api/agents/me/inbox/waiting").catch(() => void 0);
|
|
74309
74435
|
}
|
|
74310
|
-
function waitedMsOf({ waiting, nowMs }) {
|
|
74436
|
+
function waitedMsOf({ waiting, nowMs: nowMs2 }) {
|
|
74311
74437
|
if (waiting.count === 0 || !waiting.oldestPostedAt) return 0;
|
|
74312
|
-
return Math.max(0,
|
|
74438
|
+
return Math.max(0, nowMs2 - Temporal3.Instant.from(waiting.oldestPostedAt).epochMilliseconds);
|
|
74313
74439
|
}
|
|
74314
74440
|
function boundAwayOf({ waiting, key }) {
|
|
74315
74441
|
const bound = waiting.session;
|
|
@@ -74317,13 +74443,13 @@ function boundAwayOf({ waiting, key }) {
|
|
|
74317
74443
|
return `${sessionLabelOf(bound)} (${bound.harness}:${bound.sessionId})`;
|
|
74318
74444
|
}
|
|
74319
74445
|
async function logDelivery({ context, line }) {
|
|
74320
|
-
const folder =
|
|
74446
|
+
const folder = join12(dirname10(context.environment.configPath), "connect");
|
|
74321
74447
|
const at = Temporal3.Instant.fromEpochMilliseconds(context.nowMs());
|
|
74322
74448
|
const stamped = `${at.toString({ smallestUnit: "second" })} ${line}
|
|
74323
74449
|
`;
|
|
74324
74450
|
context.out(stamped);
|
|
74325
|
-
await
|
|
74326
|
-
await appendFile(
|
|
74451
|
+
await mkdir2(folder, { recursive: true, mode: 448 });
|
|
74452
|
+
await appendFile(join12(folder, "delivery.log"), stamped, { mode: 384 });
|
|
74327
74453
|
}
|
|
74328
74454
|
async function claimFor({
|
|
74329
74455
|
context,
|
|
@@ -74399,17 +74525,13 @@ async function watchRushDelivery({
|
|
|
74399
74525
|
|
|
74400
74526
|
// src/services/connect-delivery.service.ts
|
|
74401
74527
|
function connectFolderOf({ context }) {
|
|
74402
|
-
return
|
|
74528
|
+
return join13(dirname11(context.environment.configPath), "connect");
|
|
74403
74529
|
}
|
|
74404
74530
|
function runStatePathOf({ context }) {
|
|
74405
|
-
return
|
|
74531
|
+
return join13(connectFolderOf({ context }), "run.json");
|
|
74406
74532
|
}
|
|
74407
74533
|
async function readJson({ path }) {
|
|
74408
|
-
|
|
74409
|
-
return JSON.parse(await readFile13(path, "utf8"));
|
|
74410
|
-
} catch {
|
|
74411
|
-
return void 0;
|
|
74412
|
-
}
|
|
74534
|
+
return readStateJson({ path });
|
|
74413
74535
|
}
|
|
74414
74536
|
async function runStateOf({ context }) {
|
|
74415
74537
|
return readJson({ path: runStatePathOf({ context }) });
|
|
@@ -74421,7 +74543,7 @@ var CLI_CHANGED_EXIT = 75;
|
|
|
74421
74543
|
async function cliStampOf({ context }) {
|
|
74422
74544
|
const file4 = context.program.at(-1);
|
|
74423
74545
|
if (!file4) return "";
|
|
74424
|
-
return
|
|
74546
|
+
return stat5(file4).then(
|
|
74425
74547
|
(info) => `${info.mtimeMs}:${info.size}`,
|
|
74426
74548
|
() => ""
|
|
74427
74549
|
);
|
|
@@ -74572,12 +74694,8 @@ async function serveRounds({
|
|
|
74572
74694
|
}
|
|
74573
74695
|
}
|
|
74574
74696
|
}
|
|
74575
|
-
var saves = 0;
|
|
74576
74697
|
async function save(run4) {
|
|
74577
|
-
await
|
|
74578
|
-
const temporary = `${run4.path}.${run4.self}.${saves += 1}.tmp`;
|
|
74579
|
-
await writeFile9(temporary, JSON.stringify(run4.state));
|
|
74580
|
-
await rename3(temporary, run4.path);
|
|
74698
|
+
await writeStateJson({ path: run4.path, value: run4.state });
|
|
74581
74699
|
}
|
|
74582
74700
|
async function holdsLock(run4) {
|
|
74583
74701
|
return (await runStateOf({ context: run4.context }))?.pid === run4.self;
|
|
@@ -74675,7 +74793,7 @@ async function runConnectLoop({ context }) {
|
|
|
74675
74793
|
await mcpRelays.stopAll();
|
|
74676
74794
|
for (const current3 of run4.served.values()) current3.stop.abort();
|
|
74677
74795
|
await Promise.all([...run4.served.values()].map((current3) => current3.done));
|
|
74678
|
-
if (await holdsLock(run4)) await
|
|
74796
|
+
if (await holdsLock(run4)) await rm3(run4.path, { force: true });
|
|
74679
74797
|
}
|
|
74680
74798
|
return 0;
|
|
74681
74799
|
}
|
|
@@ -74693,17 +74811,17 @@ var CONNECT_SERVICE_USAGE = `laze connect install|status|stop|uninstall|run: the
|
|
|
74693
74811
|
\`laze openclaw connect --local\` and \`laze kanban connect\`, whose relays it also runs.
|
|
74694
74812
|
`;
|
|
74695
74813
|
function installedPathOf({ context }) {
|
|
74696
|
-
return
|
|
74814
|
+
return join14(connectFolderOf({ context }), "service.json");
|
|
74697
74815
|
}
|
|
74698
74816
|
function logPathOf({ context }) {
|
|
74699
|
-
return
|
|
74817
|
+
return join14(connectFolderOf({ context }), "connect.log");
|
|
74700
74818
|
}
|
|
74701
74819
|
function homeOf({ context }) {
|
|
74702
74820
|
return context.environment.inherited.HOME ?? dirname12(dirname12(context.environment.configPath));
|
|
74703
74821
|
}
|
|
74704
74822
|
function serviceNameOf({ context }) {
|
|
74705
74823
|
const { configPath } = context.environment;
|
|
74706
|
-
if (configPath ===
|
|
74824
|
+
if (configPath === join14(homeOf({ context }), ".laze", "config.json")) return "laze-connect";
|
|
74707
74825
|
return `laze-connect-${createHash2("sha256").update(configPath).digest("hex").slice(0, 8)}`;
|
|
74708
74826
|
}
|
|
74709
74827
|
function serviceEnvOf({ context }) {
|
|
@@ -74726,10 +74844,10 @@ async function run({ context, command }) {
|
|
|
74726
74844
|
async function installSystemd({ context }) {
|
|
74727
74845
|
const name3 = serviceNameOf({ context });
|
|
74728
74846
|
const env = context.environment.inherited;
|
|
74729
|
-
const base = env.XDG_CONFIG_HOME ||
|
|
74730
|
-
const file4 =
|
|
74731
|
-
await
|
|
74732
|
-
await
|
|
74847
|
+
const base = env.XDG_CONFIG_HOME || join14(homeOf({ context }), ".config");
|
|
74848
|
+
const file4 = join14(base, "systemd", "user", `${name3}.service`);
|
|
74849
|
+
await mkdir3(dirname12(file4), { recursive: true });
|
|
74850
|
+
await writeFile(
|
|
74733
74851
|
file4,
|
|
74734
74852
|
systemdUnitOf({ argv: runArgvOf({ context }), env: serviceEnvOf({ context }) })
|
|
74735
74853
|
);
|
|
@@ -74742,10 +74860,10 @@ async function installSystemd({ context }) {
|
|
|
74742
74860
|
async function installLaunchd({ context }) {
|
|
74743
74861
|
const name3 = serviceNameOf({ context });
|
|
74744
74862
|
const label3 = `ai.laze.${name3}`;
|
|
74745
|
-
const file4 =
|
|
74863
|
+
const file4 = join14(homeOf({ context }), "Library", "LaunchAgents", `${label3}.plist`);
|
|
74746
74864
|
const log = logPathOf({ context });
|
|
74747
|
-
await
|
|
74748
|
-
await
|
|
74865
|
+
await mkdir3(dirname12(file4), { recursive: true });
|
|
74866
|
+
await writeFile(
|
|
74749
74867
|
file4,
|
|
74750
74868
|
launchAgentOf({
|
|
74751
74869
|
label: label3,
|
|
@@ -74764,7 +74882,8 @@ async function installLaunchd({ context }) {
|
|
|
74764
74882
|
}
|
|
74765
74883
|
async function installDetached({ context }) {
|
|
74766
74884
|
const log = logPathOf({ context });
|
|
74767
|
-
const
|
|
74885
|
+
const argv = runArgvOf({ context });
|
|
74886
|
+
const pid = context.processes.spawnDetached({ argv, logPath: log, orphan: true });
|
|
74768
74887
|
return { manager: "detached", name: serviceNameOf({ context }), pid, log };
|
|
74769
74888
|
}
|
|
74770
74889
|
async function managerOf({ context }) {
|
|
@@ -74797,8 +74916,7 @@ async function installConnectService({ context }) {
|
|
|
74797
74916
|
const manager = await managerOf({ context });
|
|
74798
74917
|
const install = { systemd: installSystemd, launchd: installLaunchd, detached: installDetached };
|
|
74799
74918
|
const installed = await install[manager]({ context });
|
|
74800
|
-
await
|
|
74801
|
-
await writeFile10(path, JSON.stringify(installed));
|
|
74919
|
+
await writeStateJson({ path, value: installed });
|
|
74802
74920
|
return describeInstalled({ installed });
|
|
74803
74921
|
}
|
|
74804
74922
|
async function ensureConnectService({ context }) {
|
|
@@ -74845,15 +74963,14 @@ async function status2({ context }) {
|
|
|
74845
74963
|
}
|
|
74846
74964
|
const config2 = await context.store.read();
|
|
74847
74965
|
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
|
-
}
|
|
74966
|
+
if (linked.length === 0) context.out("No Codex agent is linked on this machine.\n");
|
|
74852
74967
|
for (const [profile, { name: name3, delivery }] of linked) {
|
|
74853
74968
|
const state = live ? running.agents[profile]?.state ?? "starting" : "not served";
|
|
74854
74969
|
context.out(`${profile} ${name3} Codex thread ${delivery?.threadId} ${state}
|
|
74855
74970
|
`);
|
|
74856
74971
|
}
|
|
74972
|
+
for (const line of await repairDamagedStateFiles()) context.out(`${line}
|
|
74973
|
+
`);
|
|
74857
74974
|
}
|
|
74858
74975
|
async function mcpRelayLinesOf({ context }) {
|
|
74859
74976
|
const running = await runStateOf({ context });
|
|
@@ -74878,12 +74995,12 @@ function rushLineOf({ row }) {
|
|
|
74878
74995
|
function inLazeOf({
|
|
74879
74996
|
row,
|
|
74880
74997
|
waiting,
|
|
74881
|
-
nowMs
|
|
74998
|
+
nowMs: nowMs2
|
|
74882
74999
|
}) {
|
|
74883
75000
|
if (!waiting) return "; Laze could not say what waits";
|
|
74884
75001
|
const away = boundAwayOf({ waiting, key: row.key });
|
|
74885
75002
|
const bound = away ? `; Laze binds the agent to ${away}, not this session` : "";
|
|
74886
|
-
const waited = waitedMsOf({ waiting, nowMs });
|
|
75003
|
+
const waited = waitedMsOf({ waiting, nowMs: nowMs2 });
|
|
74887
75004
|
if (waiting.count === 0) return bound;
|
|
74888
75005
|
const age = `the oldest for ${Math.round(waited / 1e3)}s`;
|
|
74889
75006
|
if (waited > UNDELIVERED_AFTER_MS)
|
|
@@ -74914,11 +75031,11 @@ async function uninstall({ context }) {
|
|
|
74914
75031
|
command: ["systemctl", "--user", "disable", `${installed.name}.service`]
|
|
74915
75032
|
});
|
|
74916
75033
|
}
|
|
74917
|
-
if (installed.file) await
|
|
75034
|
+
if (installed.file) await rm4(installed.file, { force: true });
|
|
74918
75035
|
if (installed.manager === "systemd") {
|
|
74919
75036
|
await run({ context, command: ["systemctl", "--user", "daemon-reload"] });
|
|
74920
75037
|
}
|
|
74921
|
-
await
|
|
75038
|
+
await rm4(path, { force: true });
|
|
74922
75039
|
context.out(
|
|
74923
75040
|
`Removed the connect service (${installed.manager}, ${installed.name}). Linked Codex agents get no messages until \`laze connect install\`.
|
|
74924
75041
|
`
|
|
@@ -74948,10 +75065,7 @@ var ROUND_SECONDS2 = 50;
|
|
|
74948
75065
|
var WATCH_MS = 2e3;
|
|
74949
75066
|
var CHANNEL_CHECK_MS = 5e3;
|
|
74950
75067
|
async function holderOf({ path }) {
|
|
74951
|
-
return
|
|
74952
|
-
(text3) => JSON.parse(text3),
|
|
74953
|
-
() => void 0
|
|
74954
|
-
);
|
|
75068
|
+
return readStateJson({ path });
|
|
74955
75069
|
}
|
|
74956
75070
|
async function holderClaudeOf({ context, holder }) {
|
|
74957
75071
|
if (holder.claudePid) return holder.claudePid;
|
|
@@ -74964,25 +75078,27 @@ async function takeLock({
|
|
|
74964
75078
|
claudePid,
|
|
74965
75079
|
preempt = false
|
|
74966
75080
|
}) {
|
|
74967
|
-
|
|
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(
|
|
75081
|
+
return withStateLock({
|
|
74977
75082
|
path,
|
|
74978
|
-
|
|
74979
|
-
|
|
74980
|
-
|
|
74981
|
-
|
|
74982
|
-
|
|
74983
|
-
|
|
74984
|
-
|
|
74985
|
-
|
|
75083
|
+
work: async () => {
|
|
75084
|
+
const holder = await holderOf({ path });
|
|
75085
|
+
const self2 = context.processes.pid;
|
|
75086
|
+
if (holder && holder.pid !== self2 && context.processes.alive(holder.pid)) {
|
|
75087
|
+
const served = await holderClaudeOf({ context, holder });
|
|
75088
|
+
const mine4 = preempt && served === claudePid && !holder.monitor;
|
|
75089
|
+
if (served && context.processes.alive(served) && !mine4) return false;
|
|
75090
|
+
context.processes.stop(holder.pid);
|
|
75091
|
+
}
|
|
75092
|
+
const value = {
|
|
75093
|
+
pid: self2,
|
|
75094
|
+
claudePid,
|
|
75095
|
+
...sessionId ? { sessionId } : {},
|
|
75096
|
+
...preempt ? { monitor: true } : {}
|
|
75097
|
+
};
|
|
75098
|
+
await writeStateJson({ path, value });
|
|
75099
|
+
return true;
|
|
75100
|
+
}
|
|
75101
|
+
});
|
|
74986
75102
|
}
|
|
74987
75103
|
async function channelLive({ context, profile }) {
|
|
74988
75104
|
const holder = await holderOf({ path: statePathOf({ context, kind: "channels", profile }) });
|
|
@@ -75102,7 +75218,7 @@ async function waitForMessages({ context, args }) {
|
|
|
75102
75218
|
if (rush) await healRushDelivery({ context });
|
|
75103
75219
|
const lock = statePathOf({ context, kind: "waiters", profile: name3 });
|
|
75104
75220
|
if (!await takeLock({ context, path: lock, sessionId: input2.session_id, claudePid })) return 0;
|
|
75105
|
-
const seen = () => input2.transcript_path ?
|
|
75221
|
+
const seen = () => input2.transcript_path ? readFile8(input2.transcript_path, "utf8") : Promise.resolve("");
|
|
75106
75222
|
const deadline = context.nowMs() + (WAIT_HOOK_TIMEOUT_SECONDS - 60) * 1e3;
|
|
75107
75223
|
try {
|
|
75108
75224
|
while (context.nowMs() < deadline) {
|
|
@@ -75113,7 +75229,7 @@ async function waitForMessages({ context, args }) {
|
|
|
75113
75229
|
return 0;
|
|
75114
75230
|
} finally {
|
|
75115
75231
|
if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
|
|
75116
|
-
await
|
|
75232
|
+
await rm5(lock, { force: true });
|
|
75117
75233
|
}
|
|
75118
75234
|
}
|
|
75119
75235
|
async function healRushDelivery({ context }) {
|
|
@@ -75154,14 +75270,14 @@ async function monitorServes({
|
|
|
75154
75270
|
|
|
75155
75271
|
// src/services/codex-link.service.ts
|
|
75156
75272
|
import { createReadStream } from "node:fs";
|
|
75157
|
-
import { readdir as readdir5, rm as
|
|
75158
|
-
import { join as
|
|
75273
|
+
import { readdir as readdir5, rm as rm7, stat as stat7 } from "node:fs/promises";
|
|
75274
|
+
import { join as join16, resolve as resolve4 } from "node:path";
|
|
75159
75275
|
import { createInterface as createInterface2 } from "node:readline";
|
|
75160
75276
|
|
|
75161
75277
|
// src/services/codex-adopt.service.ts
|
|
75162
75278
|
import { spawn as spawn2 } from "node:child_process";
|
|
75163
|
-
import {
|
|
75164
|
-
import {
|
|
75279
|
+
import { readdir as readdir4, rm as rm6, stat as stat6 } from "node:fs/promises";
|
|
75280
|
+
import { join as join15 } from "node:path";
|
|
75165
75281
|
import { createInterface } from "node:readline";
|
|
75166
75282
|
|
|
75167
75283
|
// src/rules/codex-requests.rules.ts
|
|
@@ -75281,11 +75397,11 @@ var CodexAppServer = class _CodexAppServer {
|
|
|
75281
75397
|
}
|
|
75282
75398
|
};
|
|
75283
75399
|
async function newestThreadId({ codexHome }) {
|
|
75284
|
-
const root =
|
|
75400
|
+
const root = join15(codexHome, "sessions");
|
|
75285
75401
|
const files2 = await readdir4(root, { recursive: true }).catch(() => []);
|
|
75286
75402
|
const rollouts = files2.filter((file4) => /rollout-.*\.jsonl$/.test(file4));
|
|
75287
75403
|
const dated = await Promise.all(
|
|
75288
|
-
rollouts.map(async (file4) => ({ file: file4, at: (await
|
|
75404
|
+
rollouts.map(async (file4) => ({ file: file4, at: (await stat6(join15(root, file4))).mtimeMs }))
|
|
75289
75405
|
);
|
|
75290
75406
|
const newest = dated.toSorted((a, b) => b.at - a.at)[0]?.file ?? "";
|
|
75291
75407
|
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 +75476,7 @@ async function answer2({
|
|
|
75360
75476
|
var MAX_RESTART_WAIT_SECONDS = 60;
|
|
75361
75477
|
var HEALTHY_RUN_MS = 6e4;
|
|
75362
75478
|
async function recordOf({ path }) {
|
|
75363
|
-
return
|
|
75364
|
-
(text3) => JSON.parse(text3),
|
|
75365
|
-
() => void 0
|
|
75366
|
-
);
|
|
75479
|
+
return readStateJson({ path });
|
|
75367
75480
|
}
|
|
75368
75481
|
function threadFlag({ thread: thread2 }) {
|
|
75369
75482
|
return thread2 ? ["--thread", thread2] : [];
|
|
@@ -75382,8 +75495,7 @@ async function startAdoptInBackground({
|
|
|
75382
75495
|
const adopt = ["adopt", "codex", "--profile", profile, ...threadFlag({ thread: thread2 })];
|
|
75383
75496
|
const argv = [...context.program, ...adopt, "--supervise"];
|
|
75384
75497
|
const pid = context.processes.spawnDetached({ argv, logPath: log });
|
|
75385
|
-
await
|
|
75386
|
-
await writeFile12(path, JSON.stringify({ pid, thread: thread2, log, startedAt: context.nowMs() }));
|
|
75498
|
+
await writeStateJson({ path, value: { pid, thread: thread2, log, startedAt: context.nowMs() } });
|
|
75387
75499
|
return [
|
|
75388
75500
|
`Started \`${laze} adopt codex\` in the background (pid ${pid}). It answers each Laze message`,
|
|
75389
75501
|
`as a turn in ${thread2 ? `this Codex thread (${thread2})` : "the newest Codex thread"}, and starts again if it stops.`,
|
|
@@ -75442,7 +75554,7 @@ Log: ${record4.log}
|
|
|
75442
75554
|
async function adoptStop({ context, profile }) {
|
|
75443
75555
|
const path = statePathOf({ context, kind: "adopt", profile });
|
|
75444
75556
|
const record4 = await recordOf({ path });
|
|
75445
|
-
await
|
|
75557
|
+
await rm6(path, { force: true });
|
|
75446
75558
|
if (!record4 || !context.processes.stop(record4.pid)) {
|
|
75447
75559
|
context.out(`laze adopt codex was not running in the background for profile "${profile}".
|
|
75448
75560
|
`);
|
|
@@ -75467,10 +75579,7 @@ async function adoptedThreadOf({
|
|
|
75467
75579
|
);
|
|
75468
75580
|
if (!held) return threadId;
|
|
75469
75581
|
const path = statePathOf({ context, kind: "adopt", profile, extension: "forks.json" });
|
|
75470
|
-
const forks = await
|
|
75471
|
-
(text3) => JSON.parse(text3),
|
|
75472
|
-
() => ({})
|
|
75473
|
-
);
|
|
75582
|
+
const forks = await readStateJson({ path }) ?? {};
|
|
75474
75583
|
const known = forks[threadId];
|
|
75475
75584
|
if (known && await codex.call("thread/resume", { threadId: known }).then(
|
|
75476
75585
|
() => true,
|
|
@@ -75482,8 +75591,7 @@ async function adoptedThreadOf({
|
|
|
75482
75591
|
}
|
|
75483
75592
|
const forked = record3((await codex.call("thread/fork", { threadId })).thread).id;
|
|
75484
75593
|
if (typeof forked !== "string") throw new Error("thread/fork answered no thread id");
|
|
75485
|
-
await
|
|
75486
|
-
await writeFile12(path, JSON.stringify({ ...forks, [threadId]: forked }));
|
|
75594
|
+
await writeStateJson({ path, value: { ...forks, [threadId]: forked } });
|
|
75487
75595
|
context.out(
|
|
75488
75596
|
`Codex holds thread ${threadId} open elsewhere; answering in its new fork ${forked}.
|
|
75489
75597
|
`
|
|
@@ -75554,13 +75662,13 @@ async function newestThreadIn({
|
|
|
75554
75662
|
codexHome,
|
|
75555
75663
|
directory
|
|
75556
75664
|
}) {
|
|
75557
|
-
const root =
|
|
75665
|
+
const root = join16(codexHome, "sessions");
|
|
75558
75666
|
const files2 = await readdir5(root, { recursive: true }).catch(() => []);
|
|
75559
75667
|
const rollouts = files2.filter((file4) => /rollout-.*\.jsonl$/.test(file4));
|
|
75560
75668
|
const dated = await Promise.all(
|
|
75561
75669
|
rollouts.map(async (file4) => ({
|
|
75562
|
-
path:
|
|
75563
|
-
at: await
|
|
75670
|
+
path: join16(root, file4),
|
|
75671
|
+
at: await stat7(join16(root, file4)).then(
|
|
75564
75672
|
(info) => info.mtimeMs,
|
|
75565
75673
|
() => 0
|
|
75566
75674
|
)
|
|
@@ -75591,7 +75699,7 @@ async function stopAdopt({ context, profile }) {
|
|
|
75591
75699
|
const running = await readJson({ path });
|
|
75592
75700
|
if (!running) return;
|
|
75593
75701
|
context.processes.stop(running.pid);
|
|
75594
|
-
await
|
|
75702
|
+
await rm7(path, { force: true });
|
|
75595
75703
|
}
|
|
75596
75704
|
async function linkCodexSession({
|
|
75597
75705
|
context,
|
|
@@ -75630,16 +75738,16 @@ async function linkCodexSession({
|
|
|
75630
75738
|
}
|
|
75631
75739
|
|
|
75632
75740
|
// src/services/laze-plugin.service.ts
|
|
75633
|
-
import { mkdir as
|
|
75741
|
+
import { mkdir as mkdir4, readFile as readFile9, rm as rm8, writeFile as writeFile2 } from "node:fs/promises";
|
|
75634
75742
|
import { homedir as homedir4 } from "node:os";
|
|
75635
|
-
import { dirname as
|
|
75743
|
+
import { dirname as dirname13, join as join18 } from "node:path";
|
|
75636
75744
|
|
|
75637
75745
|
// src/rules/laze-plugin.rules.ts
|
|
75638
75746
|
import { createHash as createHash3 } from "node:crypto";
|
|
75639
|
-
import { join as
|
|
75747
|
+
import { join as join17 } from "node:path";
|
|
75640
75748
|
var LAZE_PLUGIN = "laze";
|
|
75641
75749
|
function pluginNameOf({ configPath, home }) {
|
|
75642
|
-
if (configPath ===
|
|
75750
|
+
if (configPath === join17(home, ".laze", "config.json")) return LAZE_PLUGIN;
|
|
75643
75751
|
return `${LAZE_PLUGIN}-${createHash3("sha256").update(configPath).digest("hex").slice(0, 8)}`;
|
|
75644
75752
|
}
|
|
75645
75753
|
var NPX_CLI = ["npx", "-y", "@lazehq/cli@latest"];
|
|
@@ -75881,14 +75989,11 @@ function installedNameOf({ context }) {
|
|
|
75881
75989
|
return `${name3}@${name3}`;
|
|
75882
75990
|
}
|
|
75883
75991
|
function pluginFolderOf({ context }) {
|
|
75884
|
-
return
|
|
75992
|
+
return join18(dirname13(context.environment.configPath), "plugins");
|
|
75885
75993
|
}
|
|
75886
75994
|
async function pluginIsCurrent({ context }) {
|
|
75887
|
-
const manifest =
|
|
75888
|
-
const written = await
|
|
75889
|
-
(text3) => JSON.parse(text3).version,
|
|
75890
|
-
() => void 0
|
|
75891
|
-
);
|
|
75995
|
+
const manifest = join18(pluginFolderOf({ context }), LAZE_PLUGIN, ".claude-plugin", "plugin.json");
|
|
75996
|
+
const written = await readFile9(manifest, "utf8").then((text3) => JSON.parse(text3).version).catch(() => void 0);
|
|
75892
75997
|
return written === cliVersionOf();
|
|
75893
75998
|
}
|
|
75894
75999
|
async function writeLazePlugin({ context }) {
|
|
@@ -75900,9 +76005,9 @@ async function writeLazePlugin({ context }) {
|
|
|
75900
76005
|
configPath: context.environment.configPath
|
|
75901
76006
|
});
|
|
75902
76007
|
for (const [path, text3] of Object.entries(files2)) {
|
|
75903
|
-
const target =
|
|
75904
|
-
await
|
|
75905
|
-
await
|
|
76008
|
+
const target = join18(folder, path);
|
|
76009
|
+
await mkdir4(dirname13(target), { recursive: true });
|
|
76010
|
+
await writeFile2(target, text3);
|
|
75906
76011
|
}
|
|
75907
76012
|
return folder;
|
|
75908
76013
|
}
|
|
@@ -75931,7 +76036,7 @@ async function registerWithClaude({ context, folder }) {
|
|
|
75931
76036
|
return claudeScript({ context, script });
|
|
75932
76037
|
}
|
|
75933
76038
|
function claudeDirOf({ context }) {
|
|
75934
|
-
return context.environment.inherited.CLAUDE_CONFIG_DIR ||
|
|
76039
|
+
return context.environment.inherited.CLAUDE_CONFIG_DIR || join18(homeOf2({ context }), ".claude");
|
|
75935
76040
|
}
|
|
75936
76041
|
function unregisterAs({ context, name: name3 }) {
|
|
75937
76042
|
const script = [
|
|
@@ -75942,8 +76047,8 @@ function unregisterAs({ context, name: name3 }) {
|
|
|
75942
76047
|
}
|
|
75943
76048
|
async function dropOwnLeftover({ context, folder }) {
|
|
75944
76049
|
if (pluginNameHere({ context }) === LAZE_PLUGIN) return;
|
|
75945
|
-
const known = await
|
|
75946
|
-
|
|
76050
|
+
const known = await readFile9(
|
|
76051
|
+
join18(claudeDirOf({ context }), "plugins", "known_marketplaces.json"),
|
|
75947
76052
|
"utf8"
|
|
75948
76053
|
).then((text3) => JSON.parse(text3)).catch(() => void 0);
|
|
75949
76054
|
if (known?.[LAZE_PLUGIN]?.source?.path !== folder) return;
|
|
@@ -75951,20 +76056,17 @@ async function dropOwnLeftover({ context, folder }) {
|
|
|
75951
76056
|
}
|
|
75952
76057
|
var RUN_FILES = ["hooks/hooks.json", "monitors/monitors.json"];
|
|
75953
76058
|
async function cachedPluginOf({ context }) {
|
|
75954
|
-
const path =
|
|
75955
|
-
const listed = await
|
|
75956
|
-
(text3) => JSON.parse(text3),
|
|
75957
|
-
() => void 0
|
|
75958
|
-
);
|
|
76059
|
+
const path = join18(claudeDirOf({ context }), "plugins", "installed_plugins.json");
|
|
76060
|
+
const listed = await readFile9(path, "utf8").then((text3) => JSON.parse(text3)).catch(() => void 0);
|
|
75959
76061
|
return listed?.plugins?.[installedNameOf({ context })]?.[0]?.installPath;
|
|
75960
76062
|
}
|
|
75961
76063
|
async function refreshStaleCache({ context, folder }) {
|
|
75962
76064
|
const cached2 = await cachedPluginOf({ context });
|
|
75963
76065
|
if (!cached2) return true;
|
|
75964
|
-
const read4 = (path) =>
|
|
76066
|
+
const read4 = (path) => readFile9(path, "utf8").catch(() => "");
|
|
75965
76067
|
for (const file4 of RUN_FILES) {
|
|
75966
|
-
const ours = await read4(
|
|
75967
|
-
if (ours === await read4(
|
|
76068
|
+
const ours = await read4(join18(folder, LAZE_PLUGIN, file4));
|
|
76069
|
+
if (ours === await read4(join18(cached2, file4))) continue;
|
|
75968
76070
|
const plugin2 = installedNameOf({ context });
|
|
75969
76071
|
const script = [
|
|
75970
76072
|
`claude plugin uninstall ${plugin2} --scope user ${QUIET}`,
|
|
@@ -75975,10 +76077,10 @@ async function refreshStaleCache({ context, folder }) {
|
|
|
75975
76077
|
return true;
|
|
75976
76078
|
}
|
|
75977
76079
|
function registeredMarkOf({ context }) {
|
|
75978
|
-
return
|
|
76080
|
+
return join18(pluginFolderOf({ context }), "registered");
|
|
75979
76081
|
}
|
|
75980
76082
|
async function pluginRegistered({ context }) {
|
|
75981
|
-
return
|
|
76083
|
+
return readFile9(registeredMarkOf({ context }), "utf8").then(
|
|
75982
76084
|
() => true,
|
|
75983
76085
|
() => false
|
|
75984
76086
|
);
|
|
@@ -75987,20 +76089,20 @@ async function installLazePlugin({ context }) {
|
|
|
75987
76089
|
const folder = await writeLazePlugin({ context });
|
|
75988
76090
|
await dropOwnLeftover({ context, folder });
|
|
75989
76091
|
const registered = await registerWithClaude({ context, folder }) && await refreshStaleCache({ context, folder });
|
|
75990
|
-
if (registered) await
|
|
76092
|
+
if (registered) await writeFile2(registeredMarkOf({ context }), cliVersionOf());
|
|
75991
76093
|
return { folder, registered };
|
|
75992
76094
|
}
|
|
75993
76095
|
async function plugin({ context, args }) {
|
|
75994
76096
|
const action = args.words[1] ?? "install";
|
|
75995
76097
|
if (action === "path") {
|
|
75996
|
-
context.out(`${
|
|
76098
|
+
context.out(`${join18(pluginFolderOf({ context }), LAZE_PLUGIN)}
|
|
75997
76099
|
`);
|
|
75998
76100
|
return 0;
|
|
75999
76101
|
}
|
|
76000
76102
|
if (action === "uninstall") {
|
|
76001
76103
|
const name3 = pluginNameHere({ context });
|
|
76002
76104
|
const removed = await unregisterAs({ context, name: name3 });
|
|
76003
|
-
await
|
|
76105
|
+
await rm8(registeredMarkOf({ context }), { force: true });
|
|
76004
76106
|
context.out(
|
|
76005
76107
|
removed ? `Removed the Laze plugin ${name3}@${name3} from Claude Code.
|
|
76006
76108
|
` : `Claude Code did not remove it; run: claude plugin uninstall ${name3}@${name3} && claude plugin marketplace remove ${name3}
|
|
@@ -76022,8 +76124,7 @@ async function plugin({ context, args }) {
|
|
|
76022
76124
|
}
|
|
76023
76125
|
|
|
76024
76126
|
// src/services/mcp-channel.service.ts
|
|
76025
|
-
import {
|
|
76026
|
-
import { dirname as dirname16 } from "node:path";
|
|
76127
|
+
import { rm as rm9 } from "node:fs/promises";
|
|
76027
76128
|
var LAZE_MCP_SERVER = "laze";
|
|
76028
76129
|
var DEV_CHANNELS_FLAG = "--dangerously-load-development-channels";
|
|
76029
76130
|
var ROUND_SECONDS3 = 50;
|
|
@@ -76113,8 +76214,7 @@ async function pushInbox({
|
|
|
76113
76214
|
signal
|
|
76114
76215
|
}) {
|
|
76115
76216
|
const marker = statePathOf({ context, kind: "channels", profile });
|
|
76116
|
-
await
|
|
76117
|
-
await writeFile14(marker, JSON.stringify({ pid: context.processes.pid }));
|
|
76217
|
+
await writeStateJson({ path: marker, value: { pid: context.processes.pid } });
|
|
76118
76218
|
try {
|
|
76119
76219
|
while (!signal.aborted) {
|
|
76120
76220
|
const messages = await client.post("/api/agents/me/inbox", { waitSeconds: ROUND_SECONDS3 }, { signal }).catch(async (error63) => {
|
|
@@ -76143,13 +76243,12 @@ async function pushInbox({
|
|
|
76143
76243
|
`);
|
|
76144
76244
|
}
|
|
76145
76245
|
} finally {
|
|
76146
|
-
await
|
|
76246
|
+
await rm9(marker, { force: true });
|
|
76147
76247
|
}
|
|
76148
76248
|
}
|
|
76149
76249
|
|
|
76150
76250
|
// src/services/plugin-tip.service.ts
|
|
76151
|
-
import {
|
|
76152
|
-
import { dirname as dirname17 } from "node:path";
|
|
76251
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
76153
76252
|
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
76253
|
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
76254
|
function monitorsRunHere({ context }) {
|
|
@@ -76183,8 +76282,7 @@ async function markReloadTipTold({
|
|
|
76183
76282
|
}) {
|
|
76184
76283
|
if (!session) return;
|
|
76185
76284
|
const path = toldPathOf({ context, session });
|
|
76186
|
-
await
|
|
76187
|
-
await writeFile15(path, String(context.nowMs()), { mode: 384 });
|
|
76285
|
+
await writeStateText({ path, text: String(context.nowMs()) });
|
|
76188
76286
|
}
|
|
76189
76287
|
async function reloadTipOnce({
|
|
76190
76288
|
context,
|
|
@@ -76192,7 +76290,7 @@ async function reloadTipOnce({
|
|
|
76192
76290
|
}) {
|
|
76193
76291
|
if (!session || !monitorsRunHere({ context })) return void 0;
|
|
76194
76292
|
if (!await pluginRegistered({ context })) return void 0;
|
|
76195
|
-
const told = await
|
|
76293
|
+
const told = await readFile10(toldPathOf({ context, session }), "utf8").then(
|
|
76196
76294
|
() => true,
|
|
76197
76295
|
() => false
|
|
76198
76296
|
);
|
|
@@ -76253,17 +76351,22 @@ async function harnessOf2({ context, args }) {
|
|
|
76253
76351
|
function slugOf(name3) {
|
|
76254
76352
|
return name3.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "agent";
|
|
76255
76353
|
}
|
|
76354
|
+
function settingsOf({ path, text: text3 }) {
|
|
76355
|
+
try {
|
|
76356
|
+
return JSON.parse(text3);
|
|
76357
|
+
} catch {
|
|
76358
|
+
throw new CliUsageError(`${path} is not valid JSON; fix it, then link again.`);
|
|
76359
|
+
}
|
|
76360
|
+
}
|
|
76256
76361
|
async function installHooks({
|
|
76257
76362
|
context,
|
|
76258
76363
|
directory,
|
|
76259
76364
|
profile
|
|
76260
76365
|
}) {
|
|
76261
|
-
const folder =
|
|
76262
|
-
const path =
|
|
76263
|
-
const
|
|
76264
|
-
|
|
76265
|
-
() => ({})
|
|
76266
|
-
);
|
|
76366
|
+
const folder = join19(directory, ".claude");
|
|
76367
|
+
const path = join19(folder, "settings.local.json");
|
|
76368
|
+
const text3 = await readFile11(path, "utf8").catch(() => "{}");
|
|
76369
|
+
const current3 = settingsOf({ path, text: text3 });
|
|
76267
76370
|
const command = (hook) => hookCommand({ program: context.program, profile, hook });
|
|
76268
76371
|
const settings3 = withLazeHooks({
|
|
76269
76372
|
settings: current3,
|
|
@@ -76271,8 +76374,8 @@ async function installHooks({
|
|
|
76271
76374
|
waitCommand: command("wait"),
|
|
76272
76375
|
preToolCommand: command("pre-tool")
|
|
76273
76376
|
});
|
|
76274
|
-
await
|
|
76275
|
-
await
|
|
76377
|
+
await mkdir5(folder, { recursive: true });
|
|
76378
|
+
await writeFile3(path, `${JSON.stringify(settings3, null, 2)}
|
|
76276
76379
|
`);
|
|
76277
76380
|
return path;
|
|
76278
76381
|
}
|
|
@@ -76499,7 +76602,7 @@ async function reportTranscript({
|
|
|
76499
76602
|
input: input2
|
|
76500
76603
|
}) {
|
|
76501
76604
|
if (!input2.transcript_path || !input2.session_id) return;
|
|
76502
|
-
const lines2 = (await
|
|
76605
|
+
const lines2 = (await readFile11(input2.transcript_path, "utf8")).split("\n");
|
|
76503
76606
|
const context = readTranscript({ lines: lines2 });
|
|
76504
76607
|
await client.post("/api/agents/me/activity", {
|
|
76505
76608
|
sessionId: input2.session_id,
|
|
@@ -76538,7 +76641,7 @@ async function handOver({ context, args }) {
|
|
|
76538
76641
|
const kept = await dueFromSpool({
|
|
76539
76642
|
context,
|
|
76540
76643
|
profile: agent3,
|
|
76541
|
-
seen: () => input2.transcript_path ?
|
|
76644
|
+
seen: () => input2.transcript_path ? readFile11(input2.transcript_path, "utf8") : Promise.resolve(""),
|
|
76542
76645
|
pushedToo: false,
|
|
76543
76646
|
settledOnly: true
|
|
76544
76647
|
});
|
|
@@ -76579,17 +76682,14 @@ async function addSessionStartWaiter({ context, args }) {
|
|
|
76579
76682
|
const directory = context.environment.inherited.CLAUDE_PROJECT_DIR;
|
|
76580
76683
|
const profile = flagText({ args, name: "profile" });
|
|
76581
76684
|
if (!directory || !profile) return;
|
|
76582
|
-
const path =
|
|
76583
|
-
const settings3 = await
|
|
76584
|
-
(text3) => JSON.parse(text3),
|
|
76585
|
-
() => void 0
|
|
76586
|
-
);
|
|
76685
|
+
const path = join19(directory, ".claude", "settings.local.json");
|
|
76686
|
+
const settings3 = await readFile11(path, "utf8").then((text3) => JSON.parse(text3)).catch(() => void 0);
|
|
76587
76687
|
if (!settings3 || !lacksSessionStartWaiter({ settings: settings3 })) return;
|
|
76588
76688
|
await installHooks({ context, directory, profile });
|
|
76589
76689
|
}
|
|
76590
76690
|
async function refreshPlugin({ context }) {
|
|
76591
76691
|
if (await pluginIsCurrent({ context })) return;
|
|
76592
|
-
const logPath =
|
|
76692
|
+
const logPath = join19(pluginFolderOf({ context }), "install.log");
|
|
76593
76693
|
context.processes.spawnDetached({ argv: [...context.program, "plugin", "install"], logPath });
|
|
76594
76694
|
}
|
|
76595
76695
|
async function stopHook({ context, args }) {
|
|
@@ -76610,7 +76710,7 @@ async function stopHook({ context, args }) {
|
|
|
76610
76710
|
}
|
|
76611
76711
|
|
|
76612
76712
|
// src/services/agent-manage-commands.service.ts
|
|
76613
|
-
import { readFile as
|
|
76713
|
+
import { readFile as readFile12 } from "node:fs/promises";
|
|
76614
76714
|
import { extname, resolve as resolve6 } from "node:path";
|
|
76615
76715
|
|
|
76616
76716
|
// src/rules/login-format.rules.ts
|
|
@@ -76618,31 +76718,31 @@ var HARNESS_NAMES2 = {
|
|
|
76618
76718
|
"claude-code": "Claude",
|
|
76619
76719
|
codex: "Codex"
|
|
76620
76720
|
};
|
|
76621
|
-
function ahead({ iso: iso3, nowMs }) {
|
|
76622
|
-
return iso3 !== null && Temporal3.Instant.from(iso3).epochMilliseconds >
|
|
76721
|
+
function ahead({ iso: iso3, nowMs: nowMs2 }) {
|
|
76722
|
+
return iso3 !== null && Temporal3.Instant.from(iso3).epochMilliseconds > nowMs2 ? iso3 : null;
|
|
76623
76723
|
}
|
|
76624
76724
|
function usageOf2({
|
|
76625
76725
|
usedPercent,
|
|
76626
76726
|
resetsAt,
|
|
76627
76727
|
limitedUntil,
|
|
76628
|
-
nowMs
|
|
76728
|
+
nowMs: nowMs2
|
|
76629
76729
|
}) {
|
|
76630
|
-
const limited2 = ahead({ iso: limitedUntil, nowMs });
|
|
76730
|
+
const limited2 = ahead({ iso: limitedUntil, nowMs: nowMs2 });
|
|
76631
76731
|
if (limited2) return `out of usage until ${utcTimeOf(limited2)}`;
|
|
76632
76732
|
if (usedPercent === null) return "no usage reading yet";
|
|
76633
|
-
const resets = ahead({ iso: resetsAt, nowMs });
|
|
76733
|
+
const resets = ahead({ iso: resetsAt, nowMs: nowMs2 });
|
|
76634
76734
|
const used = `${Math.round(usedPercent)}% used`;
|
|
76635
76735
|
return resets ? `${used}, resets ${utcTimeOf(resets)}` : used;
|
|
76636
76736
|
}
|
|
76637
76737
|
var INVALID2 = "signed out: its provider refused this token, sign in again with a new one";
|
|
76638
76738
|
var EXPIRES_SOON = " expires within hours: run claude setup-token for a token that lasts a year";
|
|
76639
|
-
function formatLogins({ list: list12, nowMs }) {
|
|
76739
|
+
function formatLogins({ list: list12, nowMs: nowMs2 }) {
|
|
76640
76740
|
if (list12.logins.length === 0) {
|
|
76641
76741
|
return "No logins yet. Add one with: laze agent logins add --harness claude-code --name <name> < token-file\n";
|
|
76642
76742
|
}
|
|
76643
76743
|
const lines2 = list12.logins.map((login2) => {
|
|
76644
76744
|
const state = login2.agentsOnIt > 0 ? `in use by ${login2.agentsOnIt} ${login2.agentsOnIt === 1 ? "agent" : "agents"}` : "ready";
|
|
76645
|
-
const usage = usageOf2({ ...login2, nowMs });
|
|
76745
|
+
const usage = usageOf2({ ...login2, nowMs: nowMs2 });
|
|
76646
76746
|
let shown2 = usage.startsWith("out of usage") ? usage : `${state}, ${usage}`;
|
|
76647
76747
|
if (login2.state === "invalid") shown2 = INVALID2;
|
|
76648
76748
|
const line = `${HARNESS_NAMES2[login2.harness]} ${login2.name} (${shown2}) ${login2.id}`;
|
|
@@ -76652,13 +76752,13 @@ ${EXPIRES_SOON}` : line;
|
|
|
76652
76752
|
return `${lines2.join("\n")}
|
|
76653
76753
|
`;
|
|
76654
76754
|
}
|
|
76655
|
-
function formatPool({ pool, nowMs }) {
|
|
76755
|
+
function formatPool({ pool, nowMs: nowMs2 }) {
|
|
76656
76756
|
const role2 = pool.myRole ?? "admin view";
|
|
76657
76757
|
const lines2 = [`${pool.name} (you: ${role2}) ${pool.id}`];
|
|
76658
76758
|
lines2.push(
|
|
76659
76759
|
pool.logins.length === 0 ? " Logins: none yet" : " Logins:",
|
|
76660
76760
|
...pool.logins.map((login2) => {
|
|
76661
|
-
const usage = login2.invalid ? INVALID2 : usageOf2({ ...login2, nowMs });
|
|
76761
|
+
const usage = login2.invalid ? INVALID2 : usageOf2({ ...login2, nowMs: nowMs2 });
|
|
76662
76762
|
const use = login2.inUse && !login2.invalid ? "in use, " : "";
|
|
76663
76763
|
const line = ` ${HARNESS_NAMES2[login2.harness]} ${login2.name} added by ${login2.contributedByName} (${use}${usage})`;
|
|
76664
76764
|
return login2.expiresSoon ? `${line}
|
|
@@ -76674,8 +76774,8 @@ function formatPool({ pool, nowMs }) {
|
|
|
76674
76774
|
}
|
|
76675
76775
|
return lines2.join("\n");
|
|
76676
76776
|
}
|
|
76677
|
-
function formatOnePool({ pool, nowMs }) {
|
|
76678
|
-
return `${formatPool({ pool, nowMs })}
|
|
76777
|
+
function formatOnePool({ pool, nowMs: nowMs2 }) {
|
|
76778
|
+
return `${formatPool({ pool, nowMs: nowMs2 })}
|
|
76679
76779
|
`;
|
|
76680
76780
|
}
|
|
76681
76781
|
function formatUsageCheck({ check: check3 }) {
|
|
@@ -76686,11 +76786,11 @@ function formatUsageCheck({ check: check3 }) {
|
|
|
76686
76786
|
return `${checked}, ${check3.skipped} skipped (checked in the last ${minutes} minutes).
|
|
76687
76787
|
`;
|
|
76688
76788
|
}
|
|
76689
|
-
function formatPools({ pools, nowMs }) {
|
|
76789
|
+
function formatPools({ pools, nowMs: nowMs2 }) {
|
|
76690
76790
|
if (pools.pools.length === 0) {
|
|
76691
76791
|
return 'You are in no login pool. Create one with: laze agent pools create "<name>"\n';
|
|
76692
76792
|
}
|
|
76693
|
-
return `${pools.pools.map((pool) => formatPool({ pool, nowMs })).join("\n\n")}
|
|
76793
|
+
return `${pools.pools.map((pool) => formatPool({ pool, nowMs: nowMs2 })).join("\n\n")}
|
|
76694
76794
|
`;
|
|
76695
76795
|
}
|
|
76696
76796
|
function refusalLine({ code, message: message2 }) {
|
|
@@ -76748,7 +76848,7 @@ async function avatarOf({
|
|
|
76748
76848
|
return emoji4;
|
|
76749
76849
|
}
|
|
76750
76850
|
if (!path) return void 0;
|
|
76751
|
-
const bytes = await
|
|
76851
|
+
const bytes = await readFile12(resolve6(context.cwd, path)).catch(() => {
|
|
76752
76852
|
throw new CliUsageError(`laze: cannot read the avatar file ${path}.`);
|
|
76753
76853
|
});
|
|
76754
76854
|
const uploaded = await client.post("/api/agents/avatars", {
|
|
@@ -77164,7 +77264,7 @@ var LOGIN_ACTIONS = {
|
|
|
77164
77264
|
PATHS.checkLogins,
|
|
77165
77265
|
wanted ? { poolId: wanted } : {}
|
|
77166
77266
|
);
|
|
77167
|
-
const
|
|
77267
|
+
const nowMs2 = step.context.nowMs();
|
|
77168
77268
|
if (wanted) {
|
|
77169
77269
|
const pools = await step.client.get(PATHS.pools);
|
|
77170
77270
|
const pool = poolNamed({ pools: pools.pools, wanted });
|
|
@@ -77172,14 +77272,14 @@ var LOGIN_ACTIONS = {
|
|
|
77172
77272
|
return step.context.out(`${JSON.stringify({ ...check3, pool }, null, 2)}
|
|
77173
77273
|
`);
|
|
77174
77274
|
}
|
|
77175
|
-
return step.context.out(`${formatUsageCheck({ check: check3 })}${formatOnePool({ pool, nowMs })}`);
|
|
77275
|
+
return step.context.out(`${formatUsageCheck({ check: check3 })}${formatOnePool({ pool, nowMs: nowMs2 })}`);
|
|
77176
77276
|
}
|
|
77177
77277
|
const list12 = await step.client.get(PATHS.logins);
|
|
77178
77278
|
if (step.args.flags.json) {
|
|
77179
77279
|
return step.context.out(`${JSON.stringify({ ...check3, ...list12 }, null, 2)}
|
|
77180
77280
|
`);
|
|
77181
77281
|
}
|
|
77182
|
-
step.context.out(`${formatUsageCheck({ check: check3 })}${formatLogins({ list: list12, nowMs })}`);
|
|
77282
|
+
step.context.out(`${formatUsageCheck({ check: check3 })}${formatLogins({ list: list12, nowMs: nowMs2 })}`);
|
|
77183
77283
|
}
|
|
77184
77284
|
},
|
|
77185
77285
|
history: {
|
|
@@ -77464,8 +77564,8 @@ async function setAgentRunsOn({
|
|
|
77464
77564
|
}
|
|
77465
77565
|
|
|
77466
77566
|
// src/services/agent-migrate-commands.service.ts
|
|
77467
|
-
import { readFile as
|
|
77468
|
-
import { basename as
|
|
77567
|
+
import { readFile as readFile13, stat as stat8 } from "node:fs/promises";
|
|
77568
|
+
import { basename as basename6, join as join20, resolve as resolve7 } from "node:path";
|
|
77469
77569
|
|
|
77470
77570
|
// src/rules/migration-upload.rules.ts
|
|
77471
77571
|
import { createHash as createHash4 } from "node:crypto";
|
|
@@ -77676,13 +77776,13 @@ async function chosenTranscriptOf({
|
|
|
77676
77776
|
file: file4
|
|
77677
77777
|
}) {
|
|
77678
77778
|
const path = resolve7(context.cwd, file4);
|
|
77679
|
-
const sessionId =
|
|
77779
|
+
const sessionId = basename6(path).replace(/\.jsonl$/, "");
|
|
77680
77780
|
if (ticket.source !== "claude-code" || !SESSION_ID.test(sessionId)) {
|
|
77681
77781
|
throw new CliUsageError(
|
|
77682
77782
|
"--transcript takes a Claude Code transcript named <session id>.jsonl. Nothing was uploaded."
|
|
77683
77783
|
);
|
|
77684
77784
|
}
|
|
77685
|
-
const found = await
|
|
77785
|
+
const found = await stat8(path).then(
|
|
77686
77786
|
(info) => info.isFile(),
|
|
77687
77787
|
() => false
|
|
77688
77788
|
);
|
|
@@ -77702,7 +77802,7 @@ async function transcriptOf({ context, args, ticket }) {
|
|
|
77702
77802
|
if (ticket.source === "codex") {
|
|
77703
77803
|
const codexHome = context.environment.codexHome;
|
|
77704
77804
|
const path2 = await codexRolloutPathOf({ codexHome, threadId: sessionId });
|
|
77705
|
-
return { sessionId, path: path2, where:
|
|
77805
|
+
return { sessionId, path: path2, where: join20(codexHome, "sessions") };
|
|
77706
77806
|
}
|
|
77707
77807
|
const { root, path } = await claudeTranscriptOf({ context, sessionId });
|
|
77708
77808
|
return { sessionId, path, where: root };
|
|
@@ -77754,7 +77854,7 @@ async function uploadTranscript({ context, args, client }) {
|
|
|
77754
77854
|
`The transcript of session ${found.sessionId} was not found under ${found.where}; nothing was uploaded.`
|
|
77755
77855
|
);
|
|
77756
77856
|
}
|
|
77757
|
-
const raw = await
|
|
77857
|
+
const raw = await readFile13(found.path, "utf8");
|
|
77758
77858
|
if (!raw.trim()) throw new CliUsageError(`${found.path} is empty; nothing was uploaded.`);
|
|
77759
77859
|
const redacted = await redactTranscript({ text: raw });
|
|
77760
77860
|
const { parts, truncated } = transcriptPartsOf({
|
|
@@ -77764,7 +77864,7 @@ async function uploadTranscript({ context, args, client }) {
|
|
|
77764
77864
|
});
|
|
77765
77865
|
const upload = { parts, truncated, redactions: redacted.redactions };
|
|
77766
77866
|
await uploadParts({ client, migrationId: id4, upload });
|
|
77767
|
-
const fileName =
|
|
77867
|
+
const fileName = basename6(found.path);
|
|
77768
77868
|
const completed = await client.post(
|
|
77769
77869
|
`/api/agents/me/migrations/${id4}/complete`,
|
|
77770
77870
|
{
|
|
@@ -78008,8 +78108,8 @@ async function requestAgent({ context, args }) {
|
|
|
78008
78108
|
}
|
|
78009
78109
|
|
|
78010
78110
|
// src/services/app-commands.service.ts
|
|
78011
|
-
import { mkdir as
|
|
78012
|
-
import { dirname as
|
|
78111
|
+
import { mkdir as mkdir6, readdir as readdir6, readFile as readFile15, writeFile as writeFile5 } from "node:fs/promises";
|
|
78112
|
+
import { dirname as dirname14, join as join23, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
78013
78113
|
|
|
78014
78114
|
// ../../modules/app/contract/src/app.connections.ts
|
|
78015
78115
|
var appFunctionNameSchema = external_exports.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/);
|
|
@@ -80148,16 +80248,16 @@ function print({
|
|
|
80148
80248
|
async function appConnections({
|
|
80149
80249
|
context,
|
|
80150
80250
|
args,
|
|
80151
|
-
open:
|
|
80251
|
+
open: open6
|
|
80152
80252
|
}) {
|
|
80153
|
-
const { client, appId, name: name3 } = await
|
|
80253
|
+
const { client, appId, name: name3 } = await open6();
|
|
80154
80254
|
const listed = await client.post("/api/apps/connections", { appId });
|
|
80155
80255
|
print({ context, args, value: listed, text: connectionsText({ name: name3, listed }) });
|
|
80156
80256
|
}
|
|
80157
80257
|
async function appConnection({
|
|
80158
80258
|
context,
|
|
80159
80259
|
args,
|
|
80160
|
-
open:
|
|
80260
|
+
open: open6
|
|
80161
80261
|
}) {
|
|
80162
80262
|
const [, , verb, connection] = args.words;
|
|
80163
80263
|
if (verb !== "allow" && verb !== "revoke" || !connection) {
|
|
@@ -80166,7 +80266,7 @@ async function appConnection({
|
|
|
80166
80266
|
if (verb) throw new CliUsageError(USAGE2);
|
|
80167
80267
|
return;
|
|
80168
80268
|
}
|
|
80169
|
-
const { client, appId, name: name3 } = await
|
|
80269
|
+
const { client, appId, name: name3 } = await open6();
|
|
80170
80270
|
const listed = await client.post(`/api/apps/connections/${verb}`, { appId, connection }).catch((error63) => {
|
|
80171
80271
|
if (!(error63 instanceof LazeApiError) || error63.code !== "permission_denied") throw error63;
|
|
80172
80272
|
throw new CliUsageError(
|
|
@@ -80195,40 +80295,40 @@ function appAndWord({ args, usage }) {
|
|
|
80195
80295
|
if (!word3) throw new CliUsageError(usage);
|
|
80196
80296
|
return { app: app2, word: word3 };
|
|
80197
80297
|
}
|
|
80198
|
-
var
|
|
80298
|
+
var rename2 = async ({ context, args, open: open6 }) => {
|
|
80199
80299
|
const { app: app2, word: word3 } = appAndWord({ args, usage: "Usage: laze app rename [app] <new name>" });
|
|
80200
|
-
const { client, appId, name: name3 } = await
|
|
80300
|
+
const { client, appId, name: name3 } = await open6(app2);
|
|
80201
80301
|
const renamed = await client.post("/api/apps/rename", { appId, name: word3 });
|
|
80202
80302
|
print2({ context, args, value: renamed, text: `${name3} is now called ${renamed.name}.
|
|
80203
80303
|
` });
|
|
80204
80304
|
};
|
|
80205
|
-
var archive = async ({ context, args, open:
|
|
80206
|
-
const { client, appId } = await
|
|
80305
|
+
var archive = async ({ context, args, open: open6 }) => {
|
|
80306
|
+
const { client, appId } = await open6(args.words[2]);
|
|
80207
80307
|
const archived = await client.post("/api/apps/archive", { appId });
|
|
80208
80308
|
const text3 = `Archived ${archived.name}: it serves nothing and keeps its versions and data. laze app unarchive brings it back.
|
|
80209
80309
|
`;
|
|
80210
80310
|
print2({ context, args, value: archived, text: text3 });
|
|
80211
80311
|
};
|
|
80212
|
-
var unarchive = async ({ context, args, open:
|
|
80213
|
-
const { client, appId } = await
|
|
80312
|
+
var unarchive = async ({ context, args, open: open6 }) => {
|
|
80313
|
+
const { client, appId } = await open6(args.words[2]);
|
|
80214
80314
|
const back = await client.post("/api/apps/unarchive", { appId });
|
|
80215
80315
|
const text3 = `${back.name} is back at the same addresses.
|
|
80216
80316
|
`;
|
|
80217
80317
|
print2({ context, args, value: back, text: text3 });
|
|
80218
80318
|
};
|
|
80219
|
-
var remove = async ({ context, args, open:
|
|
80319
|
+
var remove = async ({ context, args, open: open6 }) => {
|
|
80220
80320
|
const confirmName = flagText({ args, name: "confirm" });
|
|
80221
80321
|
if (!confirmName) {
|
|
80222
80322
|
throw new CliUsageError("Usage: laze app delete [app] --confirm <the app's name>");
|
|
80223
80323
|
}
|
|
80224
|
-
const { client, appId, name: name3 } = await
|
|
80324
|
+
const { client, appId, name: name3 } = await open6(args.words[2]);
|
|
80225
80325
|
await client.post("/api/apps/delete", { appId, confirmName });
|
|
80226
80326
|
const text3 = `Deleted ${name3}: it stopped serving and is gone from the workspace.
|
|
80227
80327
|
`;
|
|
80228
80328
|
print2({ context, args, value: { deleted: appId }, text: text3 });
|
|
80229
80329
|
};
|
|
80230
|
-
var revokeLease = async ({ context, args, open:
|
|
80231
|
-
const { client, appId, name: name3 } = await
|
|
80330
|
+
var revokeLease = async ({ context, args, open: open6 }) => {
|
|
80331
|
+
const { client, appId, name: name3 } = await open6(args.words[2]);
|
|
80232
80332
|
const app2 = await client.post("/api/apps/publish/revoke-lease", { appId });
|
|
80233
80333
|
const text3 = `${name3}'s builder asks for an approval again before its next public publish.
|
|
80234
80334
|
`;
|
|
@@ -80289,18 +80389,18 @@ function backupsText({ name: name3, status: status11 }) {
|
|
|
80289
80389
|
return `${name3}: ${replicating} ${window2}
|
|
80290
80390
|
${restores.join("")}`;
|
|
80291
80391
|
}
|
|
80292
|
-
var backups = async ({ context, args, open:
|
|
80293
|
-
const { client, appId, name: name3 } = await
|
|
80392
|
+
var backups = async ({ context, args, open: open6 }) => {
|
|
80393
|
+
const { client, appId, name: name3 } = await open6(args.words[2]);
|
|
80294
80394
|
const status11 = await client.post("/api/apps/backups", { appId });
|
|
80295
80395
|
print2({ context, args, value: status11, text: backupsText({ name: name3, status: status11 }) });
|
|
80296
80396
|
};
|
|
80297
|
-
var restore = async ({ context, args, open:
|
|
80397
|
+
var restore = async ({ context, args, open: open6 }) => {
|
|
80298
80398
|
const to = flagText({ args, name: "to" });
|
|
80299
80399
|
const undo = flagText({ args, name: "undo" });
|
|
80300
80400
|
if (Boolean(to) === Boolean(undo)) {
|
|
80301
80401
|
throw new CliUsageError("Usage: laze app restore [app] --to <ISO time> | --undo <restore-id>");
|
|
80302
80402
|
}
|
|
80303
|
-
const { client, appId, name: name3 } = await
|
|
80403
|
+
const { client, appId, name: name3 } = await open6(args.words[2]);
|
|
80304
80404
|
const done = await client.post("/api/apps/backups/restore", {
|
|
80305
80405
|
appId,
|
|
80306
80406
|
...to ? { to } : { undo }
|
|
@@ -80326,16 +80426,16 @@ function usersText({ name: name3, users: users2 }) {
|
|
|
80326
80426
|
return `${name3}'s app users:
|
|
80327
80427
|
${lines2.join("")}`;
|
|
80328
80428
|
}
|
|
80329
|
-
var users = async ({ context, args, open:
|
|
80330
|
-
const { client, appId, name: name3 } = await
|
|
80429
|
+
var users = async ({ context, args, open: open6 }) => {
|
|
80430
|
+
const { client, appId, name: name3 } = await open6(args.words[2]);
|
|
80331
80431
|
const listed = await client.post("/api/apps/users", { appId });
|
|
80332
80432
|
print2({ context, args, value: listed, text: usersText({ name: name3, users: listed }) });
|
|
80333
80433
|
};
|
|
80334
80434
|
function blocking(blocked) {
|
|
80335
|
-
return async ({ context, args, open:
|
|
80435
|
+
return async ({ context, args, open: open6 }) => {
|
|
80336
80436
|
const verb = blocked ? "block-user" : "unblock-user";
|
|
80337
80437
|
const { app: app2, word: word3 } = appAndWord({ args, usage: `Usage: laze app ${verb} [app] <user-id>` });
|
|
80338
|
-
const { client, appId, name: name3 } = await
|
|
80438
|
+
const { client, appId, name: name3 } = await open6(app2);
|
|
80339
80439
|
const listed = await client.post("/api/apps/users/block", {
|
|
80340
80440
|
appId,
|
|
80341
80441
|
userId: word3,
|
|
@@ -80344,16 +80444,16 @@ function blocking(blocked) {
|
|
|
80344
80444
|
print2({ context, args, value: listed, text: usersText({ name: name3, users: listed }) });
|
|
80345
80445
|
};
|
|
80346
80446
|
}
|
|
80347
|
-
var deleteUser = async ({ context, args, open:
|
|
80447
|
+
var deleteUser = async ({ context, args, open: open6 }) => {
|
|
80348
80448
|
const { app: app2, word: word3 } = appAndWord({ args, usage: "Usage: laze app delete-user [app] <user-id>" });
|
|
80349
|
-
const { client, appId, name: name3 } = await
|
|
80449
|
+
const { client, appId, name: name3 } = await open6(app2);
|
|
80350
80450
|
const gone = await client.post("/api/apps/users/delete", { appId, userId: word3 });
|
|
80351
80451
|
const text3 = `Deleted ${gone.userId} from ${name3} with the ${gone.removedRecords.toString()} records they owned.
|
|
80352
80452
|
`;
|
|
80353
80453
|
print2({ context, args, value: gone, text: text3 });
|
|
80354
80454
|
};
|
|
80355
80455
|
var appManageCommands = {
|
|
80356
|
-
rename:
|
|
80456
|
+
rename: rename2,
|
|
80357
80457
|
archive,
|
|
80358
80458
|
unarchive,
|
|
80359
80459
|
delete: remove,
|
|
@@ -80422,10 +80522,10 @@ async function appPinCommand({
|
|
|
80422
80522
|
context,
|
|
80423
80523
|
args,
|
|
80424
80524
|
verb,
|
|
80425
|
-
open:
|
|
80525
|
+
open: open6
|
|
80426
80526
|
}) {
|
|
80427
80527
|
const channel = flagText({ args, name: "channel" });
|
|
80428
|
-
const { client, appId, name: name3 } = await
|
|
80528
|
+
const { client, appId, name: name3 } = await open6();
|
|
80429
80529
|
const role2 = verb === "pin" ? pinRoleOf(args) : void 0;
|
|
80430
80530
|
const listed = await client.post(`/api/apps/${verb}`, {
|
|
80431
80531
|
appId,
|
|
@@ -80459,9 +80559,9 @@ async function appPinsCommand({
|
|
|
80459
80559
|
|
|
80460
80560
|
// src/services/app-script-check.service.ts
|
|
80461
80561
|
import { execFile } from "node:child_process";
|
|
80462
|
-
import { mkdtemp, rm as
|
|
80562
|
+
import { mkdtemp, rm as rm10, writeFile as writeFile4 } from "node:fs/promises";
|
|
80463
80563
|
import { tmpdir } from "node:os";
|
|
80464
|
-
import { join as
|
|
80564
|
+
import { join as join21 } from "node:path";
|
|
80465
80565
|
import { promisify } from "node:util";
|
|
80466
80566
|
var run2 = promisify(execFile);
|
|
80467
80567
|
var MODULE_SYNTAX = /^\s*(import|export)\s/m;
|
|
@@ -80490,12 +80590,12 @@ async function scriptErrorsOf({
|
|
|
80490
80590
|
const unknown2 = unknownCollectionsOf({ files: files2, collections });
|
|
80491
80591
|
const scripts = files2.flatMap(scriptsOf);
|
|
80492
80592
|
if (scripts.length === 0) return unknown2;
|
|
80493
|
-
const dir = await mkdtemp(
|
|
80593
|
+
const dir = await mkdtemp(join21(tmpdir(), "laze-app-check-"));
|
|
80494
80594
|
try {
|
|
80495
80595
|
const errors = await Promise.all(
|
|
80496
80596
|
scripts.map(async (script, index) => {
|
|
80497
|
-
const file4 =
|
|
80498
|
-
await
|
|
80597
|
+
const file4 = join21(dir, `${index}.${script.module ? "mjs" : "cjs"}`);
|
|
80598
|
+
await writeFile4(file4, script.code);
|
|
80499
80599
|
try {
|
|
80500
80600
|
await run2(process.execPath, ["--check", file4]);
|
|
80501
80601
|
return null;
|
|
@@ -80507,14 +80607,14 @@ async function scriptErrorsOf({
|
|
|
80507
80607
|
);
|
|
80508
80608
|
return [...errors.filter((error63) => error63 !== null), ...unknown2];
|
|
80509
80609
|
} finally {
|
|
80510
|
-
await
|
|
80610
|
+
await rm10(dir, { recursive: true, force: true });
|
|
80511
80611
|
}
|
|
80512
80612
|
}
|
|
80513
80613
|
|
|
80514
80614
|
// src/services/app-serve.service.ts
|
|
80515
|
-
import { readFile as
|
|
80615
|
+
import { readFile as readFile14, stat as stat9 } from "node:fs/promises";
|
|
80516
80616
|
import { createServer } from "node:http";
|
|
80517
|
-
import { extname as extname2, join as
|
|
80617
|
+
import { extname as extname2, join as join22, normalize, sep as sep2 } from "node:path";
|
|
80518
80618
|
var TYPES2 = {
|
|
80519
80619
|
".html": "text/html; charset=utf-8",
|
|
80520
80620
|
".js": "text/javascript; charset=utf-8",
|
|
@@ -80565,13 +80665,13 @@ async function staticFile({
|
|
|
80565
80665
|
if (clean.startsWith("..") || hidden) {
|
|
80566
80666
|
return json2({ response, status: 404, value: { code: "not_found", message: "Not found" } });
|
|
80567
80667
|
}
|
|
80568
|
-
const candidates = [
|
|
80569
|
-
if (!extname2(clean)) candidates.push(
|
|
80668
|
+
const candidates = [join22(folder, clean), join22(folder, clean, "index.html")];
|
|
80669
|
+
if (!extname2(clean)) candidates.push(join22(folder, "index.html"));
|
|
80570
80670
|
for (const target of candidates) {
|
|
80571
|
-
const info = await
|
|
80671
|
+
const info = await stat9(target).catch(() => void 0);
|
|
80572
80672
|
if (!info?.isFile()) continue;
|
|
80573
80673
|
const type = TYPES2[extname2(target).toLowerCase()] ?? "application/octet-stream";
|
|
80574
|
-
const body = await
|
|
80674
|
+
const body = await readFile14(target);
|
|
80575
80675
|
if (extname2(target) === ".html") {
|
|
80576
80676
|
return send2({ response, status: 200, type, body: withServeThemeScript(body.toString()) });
|
|
80577
80677
|
}
|
|
@@ -80717,26 +80817,26 @@ function print4({
|
|
|
80717
80817
|
context.out(args.flags.json ? `${JSON.stringify(value, null, 2)}
|
|
80718
80818
|
` : text3);
|
|
80719
80819
|
}
|
|
80720
|
-
async function add({ context, args, open:
|
|
80820
|
+
async function add({ context, args, open: open6, word: word3 }) {
|
|
80721
80821
|
const prompt = flagText({ args, name: "prompt" }).trim();
|
|
80722
80822
|
if (!prompt) throw new CliUsageError("--prompt says what the agent does with the records");
|
|
80723
80823
|
const body = { collection: word3, on: onOf(args), where: whereOf3(args), prompt };
|
|
80724
|
-
const { client, appId, name: name3 } = await
|
|
80824
|
+
const { client, appId, name: name3 } = await open6();
|
|
80725
80825
|
const trigger = await client.post("/api/apps/triggers/add", { appId, ...body });
|
|
80726
80826
|
const text3 = `Added a trigger on ${name3}:
|
|
80727
80827
|
${triggerLine(trigger)}Matching changes to ${word3} records wake ${trigger.agentName} in ${trigger.channelName}.
|
|
80728
80828
|
`;
|
|
80729
80829
|
print4({ context, args, value: trigger, text: text3 });
|
|
80730
80830
|
}
|
|
80731
|
-
async function list({ context, args, open:
|
|
80732
|
-
const { client, appId, name: name3 } = await
|
|
80831
|
+
async function list({ context, args, open: open6 }) {
|
|
80832
|
+
const { client, appId, name: name3 } = await open6();
|
|
80733
80833
|
const listed = await client.post("/api/apps/triggers", { appId });
|
|
80734
80834
|
const text3 = listed.triggers.length === 0 ? `${name3} has no triggers. laze app trigger add <collection> adds one.
|
|
80735
80835
|
` : listed.triggers.map(triggerLine).join("");
|
|
80736
80836
|
print4({ context, args, value: listed, text: text3 });
|
|
80737
80837
|
}
|
|
80738
|
-
async function setPaused({ context, args, open:
|
|
80739
|
-
const { client, appId } = await
|
|
80838
|
+
async function setPaused({ context, args, open: open6, word: word3, paused }) {
|
|
80839
|
+
const { client, appId } = await open6();
|
|
80740
80840
|
const trigger = await client.post("/api/apps/triggers/pause", {
|
|
80741
80841
|
appId,
|
|
80742
80842
|
triggerId: word3,
|
|
@@ -80744,8 +80844,8 @@ async function setPaused({ context, args, open: open5, word: word3, paused }) {
|
|
|
80744
80844
|
});
|
|
80745
80845
|
print4({ context, args, value: trigger, text: triggerLine(trigger) });
|
|
80746
80846
|
}
|
|
80747
|
-
async function remove2({ context, args, open:
|
|
80748
|
-
const { client, appId } = await
|
|
80847
|
+
async function remove2({ context, args, open: open6, word: word3 }) {
|
|
80848
|
+
const { client, appId } = await open6();
|
|
80749
80849
|
await client.post("/api/apps/triggers/remove", { appId, triggerId: word3 });
|
|
80750
80850
|
print4({ context, args, value: { removed: word3 }, text: `Removed trigger ${word3}.
|
|
80751
80851
|
` });
|
|
@@ -80753,14 +80853,14 @@ async function remove2({ context, args, open: open5, word: word3 }) {
|
|
|
80753
80853
|
async function appTrigger({
|
|
80754
80854
|
context,
|
|
80755
80855
|
args,
|
|
80756
|
-
open:
|
|
80856
|
+
open: open6
|
|
80757
80857
|
}) {
|
|
80758
80858
|
const [, , verb, word3] = args.words;
|
|
80759
|
-
if (verb === "list") return list({ context, args, open:
|
|
80859
|
+
if (verb === "list") return list({ context, args, open: open6 });
|
|
80760
80860
|
const known = verb === "add" || verb === "pause" || verb === "resume" || verb === "remove";
|
|
80761
80861
|
if (known && !word3) throw new CliUsageError(USAGE4);
|
|
80762
80862
|
if (known && word3) {
|
|
80763
|
-
const run4 = { context, args, open:
|
|
80863
|
+
const run4 = { context, args, open: open6, word: word3 };
|
|
80764
80864
|
if (verb === "add") return add(run4);
|
|
80765
80865
|
if (verb === "remove") return remove2(run4);
|
|
80766
80866
|
return setPaused({ ...run4, paused: verb === "pause" });
|
|
@@ -80804,7 +80904,7 @@ async function turnTokenOf2({
|
|
|
80804
80904
|
const pinned = env.LAZE_TURN_TOKEN?.trim();
|
|
80805
80905
|
if (pinned) return pinned;
|
|
80806
80906
|
if (env.LAZE_TURN_FILE) {
|
|
80807
|
-
return
|
|
80907
|
+
return readFile15(env.LAZE_TURN_FILE, "utf8").then(
|
|
80808
80908
|
(text3) => text3.trim(),
|
|
80809
80909
|
() => ""
|
|
80810
80910
|
);
|
|
@@ -80834,7 +80934,7 @@ function folderOf({ context, word: word3 }) {
|
|
|
80834
80934
|
return resolve8(context.cwd, word3 ?? ".");
|
|
80835
80935
|
}
|
|
80836
80936
|
async function readManifest(folder) {
|
|
80837
|
-
const text3 = await
|
|
80937
|
+
const text3 = await readFile15(join23(folder, APP_MANIFEST_FILE), "utf8").catch(() => void 0);
|
|
80838
80938
|
if (text3 === void 0) return void 0;
|
|
80839
80939
|
const parsed = appManifestSchema.safeParse(JSON.parse(text3));
|
|
80840
80940
|
if (!parsed.success) {
|
|
@@ -80869,7 +80969,7 @@ async function jsonFlag({
|
|
|
80869
80969
|
}) {
|
|
80870
80970
|
const raw = flagText({ args, name: name3 });
|
|
80871
80971
|
if (!raw) return void 0;
|
|
80872
|
-
const text3 = raw.startsWith("@") ? await
|
|
80972
|
+
const text3 = raw.startsWith("@") ? await readFile15(resolve8(context.cwd, raw.slice(1)), "utf8") : raw;
|
|
80873
80973
|
try {
|
|
80874
80974
|
return JSON.parse(text3);
|
|
80875
80975
|
} catch {
|
|
@@ -80882,7 +80982,7 @@ async function listFiles(folder) {
|
|
|
80882
80982
|
while (pending2.length > 0 && found.length <= MAX_FILES) {
|
|
80883
80983
|
const current3 = pending2.pop() ?? folder;
|
|
80884
80984
|
for (const entry of await readdir6(current3, { withFileTypes: true })) {
|
|
80885
|
-
const path =
|
|
80985
|
+
const path = join23(current3, entry.name);
|
|
80886
80986
|
const rel = relative3(folder, path).split(sep3).join("/");
|
|
80887
80987
|
if (isSkippedPath({ path: rel })) continue;
|
|
80888
80988
|
if (entry.isDirectory()) pending2.push(path);
|
|
@@ -80918,12 +81018,12 @@ var appCreate = async ({ context, args }) => {
|
|
|
80918
81018
|
...template ? { template } : {}
|
|
80919
81019
|
});
|
|
80920
81020
|
const folder = resolve8(context.cwd, flagText({ args, name: "dir", fallback: app2.slug }));
|
|
80921
|
-
await
|
|
81021
|
+
await mkdir6(folder, { recursive: true });
|
|
80922
81022
|
const start2 = template ? await templateStart({ client, appId: app2.id, template }) : null;
|
|
80923
81023
|
for (const file4 of start2?.files ?? []) {
|
|
80924
|
-
const target =
|
|
80925
|
-
await
|
|
80926
|
-
await
|
|
81024
|
+
const target = join23(folder, ...file4.path.split("/"));
|
|
81025
|
+
await mkdir6(dirname14(target), { recursive: true });
|
|
81026
|
+
await writeFile5(
|
|
80927
81027
|
target,
|
|
80928
81028
|
file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
|
|
80929
81029
|
);
|
|
@@ -80934,7 +81034,7 @@ var appCreate = async ({ context, args }) => {
|
|
|
80934
81034
|
views: [...start2?.template.views ?? []],
|
|
80935
81035
|
seed: { ...start2?.template.seed }
|
|
80936
81036
|
};
|
|
80937
|
-
await
|
|
81037
|
+
await writeFile5(join23(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
|
|
80938
81038
|
`);
|
|
80939
81039
|
const where = relative3(context.cwd, folder) || ".";
|
|
80940
81040
|
print5({
|
|
@@ -81006,7 +81106,7 @@ var appPush = async ({ context, args }) => {
|
|
|
81006
81106
|
paths.map(
|
|
81007
81107
|
async (path) => buildFileOf({
|
|
81008
81108
|
path: relative3(folder, path).split(sep3).join("/"),
|
|
81009
|
-
bytes: await
|
|
81109
|
+
bytes: await readFile15(path)
|
|
81010
81110
|
})
|
|
81011
81111
|
)
|
|
81012
81112
|
);
|
|
@@ -81076,7 +81176,7 @@ var appWrite = async ({ context, args }) => {
|
|
|
81076
81176
|
const path = resolve8(context.cwd, word3);
|
|
81077
81177
|
const { bytes: _bytes, ...file4 } = buildFileOf({
|
|
81078
81178
|
path: relative3(folder, path).split(sep3).join("/"),
|
|
81079
|
-
bytes: await
|
|
81179
|
+
bytes: await readFile15(path)
|
|
81080
81180
|
});
|
|
81081
81181
|
return file4;
|
|
81082
81182
|
})
|
|
@@ -81203,9 +81303,9 @@ var appPull = async ({ context, args }) => {
|
|
|
81203
81303
|
);
|
|
81204
81304
|
}
|
|
81205
81305
|
for (const file4 of pulled.files) {
|
|
81206
|
-
const target =
|
|
81207
|
-
await
|
|
81208
|
-
await
|
|
81306
|
+
const target = join23(folder, ...file4.path.split("/"));
|
|
81307
|
+
await mkdir6(dirname14(target), { recursive: true });
|
|
81308
|
+
await writeFile5(
|
|
81209
81309
|
target,
|
|
81210
81310
|
file4.encoding === "base64" ? Buffer.from(file4.content, "base64") : file4.content
|
|
81211
81311
|
);
|
|
@@ -81222,7 +81322,7 @@ var appPull = async ({ context, args }) => {
|
|
|
81222
81322
|
])
|
|
81223
81323
|
)
|
|
81224
81324
|
};
|
|
81225
|
-
await
|
|
81325
|
+
await writeFile5(join23(folder, APP_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
|
|
81226
81326
|
`);
|
|
81227
81327
|
const names = pulled.collections.map((collection) => collection.name);
|
|
81228
81328
|
const where = relative3(context.cwd, folder) || ".";
|
|
@@ -81529,7 +81629,7 @@ var appExport = async ({ context, args }) => {
|
|
|
81529
81629
|
const out = flagText({ args, name: "out" });
|
|
81530
81630
|
if (!out) return context.out(exported.body);
|
|
81531
81631
|
const target = resolve8(context.cwd, out);
|
|
81532
|
-
await
|
|
81632
|
+
await writeFile5(target, exported.body);
|
|
81533
81633
|
context.out(`Wrote ${exported.rows} records to ${relative3(context.cwd, target)}
|
|
81534
81634
|
`);
|
|
81535
81635
|
};
|
|
@@ -81537,7 +81637,7 @@ var appImport = async ({ context, args }) => {
|
|
|
81537
81637
|
const words = args.words.slice(2);
|
|
81538
81638
|
const [named, collection, file4] = words.length >= 3 ? words : [void 0, ...words];
|
|
81539
81639
|
if (!collection || !file4) throw new CliUsageError(USAGE5);
|
|
81540
|
-
const csv = await
|
|
81640
|
+
const csv = await readFile15(resolve8(context.cwd, file4), "utf8").catch(() => {
|
|
81541
81641
|
throw new CliUsageError(`Cannot read ${file4}`);
|
|
81542
81642
|
});
|
|
81543
81643
|
const scoped = named ? { ...args, flags: { ...args.flags, app: named } } : args;
|
|
@@ -81555,7 +81655,7 @@ var appImport = async ({ context, args }) => {
|
|
|
81555
81655
|
});
|
|
81556
81656
|
const refusedOut = flagText({ args, name: "refused" });
|
|
81557
81657
|
if (refusedOut && result2.refusedCsv) {
|
|
81558
|
-
await
|
|
81658
|
+
await writeFile5(resolve8(context.cwd, refusedOut), result2.refusedCsv);
|
|
81559
81659
|
}
|
|
81560
81660
|
const fitting = result2.rows - result2.refused.length;
|
|
81561
81661
|
const skipped = result2.refused.slice(0, 20).map((row) => ` line ${row.line}: ${row.reason}
|
|
@@ -81951,7 +82051,7 @@ async function app({ context, args }) {
|
|
|
81951
82051
|
import { hostname as hostname6 } from "node:os";
|
|
81952
82052
|
|
|
81953
82053
|
// src/rules/machine-proof.rules.ts
|
|
81954
|
-
import { createHash as createHash5, randomBytes } from "node:crypto";
|
|
82054
|
+
import { createHash as createHash5, randomBytes as randomBytes2 } from "node:crypto";
|
|
81955
82055
|
var b64url3 = (bytes) => Buffer.from(bytes).toString("base64url");
|
|
81956
82056
|
function thumbprintOf({ jwk }) {
|
|
81957
82057
|
const canonical = JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y });
|
|
@@ -81968,16 +82068,16 @@ function machineProofOf({
|
|
|
81968
82068
|
method,
|
|
81969
82069
|
url: url2,
|
|
81970
82070
|
credential,
|
|
81971
|
-
nowMs,
|
|
82071
|
+
nowMs: nowMs2,
|
|
81972
82072
|
tailscaleNodeId,
|
|
81973
|
-
jti = b64url3(
|
|
82073
|
+
jti = b64url3(randomBytes2(18))
|
|
81974
82074
|
}) {
|
|
81975
82075
|
const header = b64url3(JSON.stringify({ typ: "dpop+jwt", alg: "ES256", jwk }));
|
|
81976
82076
|
const payload = b64url3(
|
|
81977
82077
|
JSON.stringify({
|
|
81978
82078
|
htm: method.toUpperCase(),
|
|
81979
82079
|
htu: url2,
|
|
81980
|
-
iat: Math.floor(
|
|
82080
|
+
iat: Math.floor(nowMs2 / 1e3),
|
|
81981
82081
|
jti,
|
|
81982
82082
|
ath: b64url3(createHash5("sha256").update(credential).digest()),
|
|
81983
82083
|
lz_tier: tier,
|
|
@@ -82395,14 +82495,14 @@ async function billing({ context, args }) {
|
|
|
82395
82495
|
}
|
|
82396
82496
|
|
|
82397
82497
|
// src/services/browser-commands.service.ts
|
|
82398
|
-
import { randomBytes as
|
|
82399
|
-
import {
|
|
82400
|
-
import { dirname as
|
|
82498
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
82499
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
82500
|
+
import { dirname as dirname16, join as join26 } from "node:path";
|
|
82401
82501
|
|
|
82402
82502
|
// src/services/browser-tab-commands.service.ts
|
|
82403
|
-
import { mkdir as
|
|
82503
|
+
import { mkdir as mkdir7, writeFile as writeFile6 } from "node:fs/promises";
|
|
82404
82504
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
82405
|
-
import { join as
|
|
82505
|
+
import { join as join25 } from "node:path";
|
|
82406
82506
|
|
|
82407
82507
|
// src/rules/browser-login.rules.ts
|
|
82408
82508
|
var PASSWORD_NAME = /pass|pwd/i;
|
|
@@ -82433,9 +82533,9 @@ function loginValuesOf({
|
|
|
82433
82533
|
|
|
82434
82534
|
// src/services/vault-commands.service.ts
|
|
82435
82535
|
import { createHash as createHash6 } from "node:crypto";
|
|
82436
|
-
import {
|
|
82536
|
+
import { readFile as readFile16, rm as rm11 } from "node:fs/promises";
|
|
82437
82537
|
import { hostname as hostname7, tmpdir as tmpdir2 } from "node:os";
|
|
82438
|
-
import { dirname as
|
|
82538
|
+
import { dirname as dirname15, join as join24 } from "node:path";
|
|
82439
82539
|
|
|
82440
82540
|
// src/rules/vault-session.rules.ts
|
|
82441
82541
|
function vaultSessionOf({
|
|
@@ -82500,7 +82600,7 @@ async function turnTokenOf3({
|
|
|
82500
82600
|
if (pinned) return pinned;
|
|
82501
82601
|
if (!turnFile) throw new CliUsageError(`${command} works only during an agent's turn`);
|
|
82502
82602
|
try {
|
|
82503
|
-
return (await
|
|
82603
|
+
return (await readFile16(turnFile, "utf8")).trim();
|
|
82504
82604
|
} catch {
|
|
82505
82605
|
throw new CliUsageError(`${command} works only during an agent's turn`);
|
|
82506
82606
|
}
|
|
@@ -82511,24 +82611,20 @@ function runKeyPathOf({
|
|
|
82511
82611
|
profile = ""
|
|
82512
82612
|
}) {
|
|
82513
82613
|
const name3 = createHash6("sha256").update(connection).digest("hex");
|
|
82514
|
-
const base = turnFile ?
|
|
82515
|
-
return
|
|
82614
|
+
const base = turnFile ? dirname15(turnFile) : join24(tmpdir2(), "laze-vault", profile);
|
|
82615
|
+
return join24(base, "vault-run-keys", `${name3}.json`);
|
|
82516
82616
|
}
|
|
82517
82617
|
async function runKeyAt({ path }) {
|
|
82518
|
-
const saved3 = await
|
|
82519
|
-
|
|
82520
|
-
|
|
82521
|
-
);
|
|
82618
|
+
const saved3 = await readStateJson({
|
|
82619
|
+
path
|
|
82620
|
+
});
|
|
82522
82621
|
if (saved3 && typeof saved3.publicKey === "string" && saved3.privateKey) {
|
|
82523
82622
|
const privateKey = await globalThis.crypto.subtle.importKey("jwk", saved3.privateKey, P2562, false, ["deriveBits"]).catch(() => void 0);
|
|
82524
82623
|
if (privateKey) return { privateKey, publicKey: saved3.publicKey };
|
|
82525
82624
|
}
|
|
82526
82625
|
const fresh = await generateEcdhKeys();
|
|
82527
82626
|
const jwk = await globalThis.crypto.subtle.exportKey("jwk", fresh.privateKey);
|
|
82528
|
-
await
|
|
82529
|
-
await writeFile19(path, JSON.stringify({ publicKey: fresh.publicKey, privateKey: jwk }), {
|
|
82530
|
-
mode: 384
|
|
82531
|
-
});
|
|
82627
|
+
await writeStateJson({ path, value: { publicKey: fresh.publicKey, privateKey: jwk } });
|
|
82532
82628
|
return fresh;
|
|
82533
82629
|
}
|
|
82534
82630
|
function connectionRefused(error63) {
|
|
@@ -82602,12 +82698,12 @@ async function envOf({
|
|
|
82602
82698
|
});
|
|
82603
82699
|
return { ...release2.env, ...sealed };
|
|
82604
82700
|
}
|
|
82605
|
-
function deadlineOf({ args, nowMs }) {
|
|
82701
|
+
function deadlineOf({ args, nowMs: nowMs2 }) {
|
|
82606
82702
|
const wait = flagText({ args, name: "wait" }) || (args.flags.wait === true ? args.words[3] : "");
|
|
82607
82703
|
if (!wait) return Infinity;
|
|
82608
82704
|
if (!(Number(wait) >= 0)) throw new CliUsageError(`--wait takes a number of seconds
|
|
82609
82705
|
${USAGE6}`);
|
|
82610
|
-
return
|
|
82706
|
+
return nowMs2 + Number(wait) * 1e3;
|
|
82611
82707
|
}
|
|
82612
82708
|
async function untilAnswered({
|
|
82613
82709
|
context,
|
|
@@ -82633,10 +82729,10 @@ async function untilAnswered({
|
|
|
82633
82729
|
}
|
|
82634
82730
|
function leaseHolds({
|
|
82635
82731
|
release: release2,
|
|
82636
|
-
nowMs
|
|
82732
|
+
nowMs: nowMs2
|
|
82637
82733
|
}) {
|
|
82638
82734
|
const ends = release2.sealed?.leaseEndsAt;
|
|
82639
|
-
return ends !== void 0 && Temporal3.Instant.from(ends).epochMilliseconds >
|
|
82735
|
+
return ends !== void 0 && Temporal3.Instant.from(ends).epochMilliseconds > nowMs2;
|
|
82640
82736
|
}
|
|
82641
82737
|
async function vaultRelease({
|
|
82642
82738
|
context,
|
|
@@ -82690,13 +82786,13 @@ async function settled({
|
|
|
82690
82786
|
}) {
|
|
82691
82787
|
if (release2 === "capped") return { exitCode: 75 };
|
|
82692
82788
|
if (release2.outcome === "deny") {
|
|
82693
|
-
await
|
|
82789
|
+
await rm11(keyPath, { force: true });
|
|
82694
82790
|
context.err(`${release2.message}
|
|
82695
82791
|
`);
|
|
82696
82792
|
return { exitCode: release2.exitCode || 1 };
|
|
82697
82793
|
}
|
|
82698
82794
|
const values = await envOf({ release: release2, run: run4 });
|
|
82699
|
-
if (!leaseHolds({ release: release2, nowMs: context.nowMs() })) await
|
|
82795
|
+
if (!leaseHolds({ release: release2, nowMs: context.nowMs() })) await rm11(keyPath, { force: true });
|
|
82700
82796
|
if (release2.message) context.err(`${release2.message}
|
|
82701
82797
|
`);
|
|
82702
82798
|
return { env: values };
|
|
@@ -83039,12 +83135,12 @@ ${page}${shot}`;
|
|
|
83039
83135
|
async function savedScreenshot({
|
|
83040
83136
|
tabId,
|
|
83041
83137
|
data,
|
|
83042
|
-
nowMs
|
|
83138
|
+
nowMs: nowMs2
|
|
83043
83139
|
}) {
|
|
83044
|
-
const folder =
|
|
83045
|
-
await
|
|
83046
|
-
const path =
|
|
83047
|
-
await
|
|
83140
|
+
const folder = join25(tmpdir3(), "laze-browser");
|
|
83141
|
+
await mkdir7(folder, { recursive: true, mode: 448 });
|
|
83142
|
+
const path = join25(folder, `${tabId.replace(/[^a-zA-Z0-9_-]/g, "_")}-login-${nowMs2}.jpg`);
|
|
83143
|
+
await writeFile6(path, Buffer.from(data, "base64"), { mode: 384 });
|
|
83048
83144
|
return path;
|
|
83049
83145
|
}
|
|
83050
83146
|
async function shareTab({ args, client, channel, print: print9 }) {
|
|
@@ -83520,7 +83616,7 @@ async function turnTokenOf4({
|
|
|
83520
83616
|
const pinned = env.LAZE_TURN_TOKEN?.trim();
|
|
83521
83617
|
if (pinned) return pinned;
|
|
83522
83618
|
if (env.LAZE_TURN_FILE) {
|
|
83523
|
-
return
|
|
83619
|
+
return readFile17(env.LAZE_TURN_FILE, "utf8").then(
|
|
83524
83620
|
(text3) => text3.trim(),
|
|
83525
83621
|
() => ""
|
|
83526
83622
|
);
|
|
@@ -83610,7 +83706,7 @@ async function answering({
|
|
|
83610
83706
|
}
|
|
83611
83707
|
function bridgeStatePath({ context, machine: machine2 }) {
|
|
83612
83708
|
const safe = machine2.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
83613
|
-
return
|
|
83709
|
+
return join26(dirname16(context.environment.configPath), "bridges", `${safe}.json`);
|
|
83614
83710
|
}
|
|
83615
83711
|
async function bridgePort({
|
|
83616
83712
|
context,
|
|
@@ -83618,21 +83714,17 @@ async function bridgePort({
|
|
|
83618
83714
|
access
|
|
83619
83715
|
}) {
|
|
83620
83716
|
const path = bridgeStatePath({ context, machine: machine2 });
|
|
83621
|
-
const live = await
|
|
83622
|
-
(text3) => JSON.parse(text3),
|
|
83623
|
-
() => void 0
|
|
83624
|
-
);
|
|
83717
|
+
const live = await readStateJson({ path });
|
|
83625
83718
|
const target = { target: access.url, expiresAt: access.expiresAt };
|
|
83626
83719
|
if (live && await retargetCdpBridge({ ...live, ...target })) return live.port;
|
|
83627
|
-
const key =
|
|
83720
|
+
const key = randomBytes3(24).toString("hex");
|
|
83628
83721
|
const port = await launchCdpBridge({
|
|
83629
83722
|
program: context.program,
|
|
83630
83723
|
env: context.environment.inherited,
|
|
83631
83724
|
key,
|
|
83632
83725
|
...target
|
|
83633
83726
|
});
|
|
83634
|
-
await
|
|
83635
|
-
await writeFile21(path, JSON.stringify({ port, key }), { mode: 384 });
|
|
83727
|
+
await writeStateJson({ path, value: { port, key } });
|
|
83636
83728
|
return port;
|
|
83637
83729
|
}
|
|
83638
83730
|
async function bridge({ context }) {
|
|
@@ -84328,13 +84420,13 @@ async function channelSettings({ context, args }) {
|
|
|
84328
84420
|
}
|
|
84329
84421
|
|
|
84330
84422
|
// src/services/chat-actions-commands.service.ts
|
|
84331
|
-
import { readFile as
|
|
84332
|
-
import { basename as
|
|
84423
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
84424
|
+
import { basename as basename8, isAbsolute as isAbsolute2, relative as relative4, resolve as resolve10 } from "node:path";
|
|
84333
84425
|
|
|
84334
84426
|
// src/services/file-download.service.ts
|
|
84335
84427
|
import { createWriteStream } from "node:fs";
|
|
84336
|
-
import { mkdir as
|
|
84337
|
-
import { basename as
|
|
84428
|
+
import { mkdir as mkdir8, rename as rename3, rm as rm12, stat as stat10, truncate } from "node:fs/promises";
|
|
84429
|
+
import { basename as basename7, dirname as dirname17, resolve as resolve9 } from "node:path";
|
|
84338
84430
|
import { Readable, Transform } from "node:stream";
|
|
84339
84431
|
import { pipeline } from "node:stream/promises";
|
|
84340
84432
|
var NOT_READY_WAIT_MS = 5e3;
|
|
@@ -84362,7 +84454,7 @@ function nameFrom({ response, attachmentId }) {
|
|
|
84362
84454
|
const encoded = /filename\*=UTF-8''([^;]+)/i.exec(header)?.[1];
|
|
84363
84455
|
const plain3 = /filename="?([^";]+)"?/i.exec(header)?.[1];
|
|
84364
84456
|
const name3 = encoded ? decodeURIComponent(encoded) : plain3;
|
|
84365
|
-
const safe = name3 ?
|
|
84457
|
+
const safe = name3 ? basename7(name3.replaceAll("\\", "/")) : "";
|
|
84366
84458
|
return safe && safe !== "." && safe !== ".." ? safe : attachmentId;
|
|
84367
84459
|
}
|
|
84368
84460
|
function limited({ start: start2 }) {
|
|
@@ -84382,7 +84474,7 @@ function totalOf({ response, start: start2 }) {
|
|
|
84382
84474
|
if (length === null) return void 0;
|
|
84383
84475
|
return Number(length) + (response.status === 206 ? start2 : 0);
|
|
84384
84476
|
}
|
|
84385
|
-
var sizeOnDisk = (path) =>
|
|
84477
|
+
var sizeOnDisk = (path) => stat10(path).then(
|
|
84386
84478
|
(found) => found.size,
|
|
84387
84479
|
() => 0
|
|
84388
84480
|
);
|
|
@@ -84454,17 +84546,17 @@ async function downloadFile({
|
|
|
84454
84546
|
out
|
|
84455
84547
|
}) {
|
|
84456
84548
|
const asked = out ? resolve9(context.cwd, out) : void 0;
|
|
84457
|
-
const part = resolve9(asked ?
|
|
84458
|
-
await
|
|
84549
|
+
const part = resolve9(asked ? dirname17(asked) : context.cwd, `.${attachmentId}.part`);
|
|
84550
|
+
await mkdir8(dirname17(part), { recursive: true });
|
|
84459
84551
|
const named = await fetchWhole({ context, client, attachmentId, part, out }).catch(
|
|
84460
84552
|
async (error63) => {
|
|
84461
|
-
await
|
|
84553
|
+
await rm12(part, { force: true });
|
|
84462
84554
|
if (!isDiskError(error63)) throw error63;
|
|
84463
84555
|
throw new CliUsageError(`Could not write ${attachmentId} to disk: ${String(error63)}`);
|
|
84464
84556
|
}
|
|
84465
84557
|
);
|
|
84466
84558
|
const path = asked ?? resolve9(context.cwd, named ?? attachmentId);
|
|
84467
|
-
await
|
|
84559
|
+
await rename3(part, path);
|
|
84468
84560
|
return { path, sizeBytes: await sizeOnDisk(path) };
|
|
84469
84561
|
}
|
|
84470
84562
|
|
|
@@ -84722,11 +84814,11 @@ var files = async ({ context, args, client }) => {
|
|
|
84722
84814
|
};
|
|
84723
84815
|
function uploadNameOf({ cwd, path }) {
|
|
84724
84816
|
const inside = relative4(cwd, path);
|
|
84725
|
-
return inside && !inside.startsWith("..") && !isAbsolute2(inside) ? inside :
|
|
84817
|
+
return inside && !inside.startsWith("..") && !isAbsolute2(inside) ? inside : basename8(path);
|
|
84726
84818
|
}
|
|
84727
84819
|
var fileUpload = async ({ context, args, client }) => {
|
|
84728
84820
|
const path = resolve10(context.cwd, wordAt(args, 3));
|
|
84729
|
-
const bytes = new Uint8Array(await
|
|
84821
|
+
const bytes = new Uint8Array(await readFile18(path));
|
|
84730
84822
|
const answer6 = await uploadFile({
|
|
84731
84823
|
context,
|
|
84732
84824
|
client,
|
|
@@ -84910,7 +85002,7 @@ async function chatActions({
|
|
|
84910
85002
|
}
|
|
84911
85003
|
|
|
84912
85004
|
// src/services/claude-monitor.service.ts
|
|
84913
|
-
import {
|
|
85005
|
+
import { rm as rm13 } from "node:fs/promises";
|
|
84914
85006
|
var MONITOR_IDLE_MS = 3e4;
|
|
84915
85007
|
var MONITOR_OUTRANKED_MS = 3e3;
|
|
84916
85008
|
async function deliverOnce({
|
|
@@ -84978,7 +85070,7 @@ async function monitorRound(turn) {
|
|
|
84978
85070
|
async function release({ context, profile }) {
|
|
84979
85071
|
const lock = statePathOf({ context, kind: "waiters", profile });
|
|
84980
85072
|
if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
|
|
84981
|
-
await
|
|
85073
|
+
await rm13(lock, { force: true });
|
|
84982
85074
|
}
|
|
84983
85075
|
async function monitorHook({ context, args }) {
|
|
84984
85076
|
const claudePid = await claudePidOf({ context });
|
|
@@ -85017,10 +85109,7 @@ async function monitorSessionOf({
|
|
|
85017
85109
|
const fromEnv = sessionOf({ context, harness: "claude-code", sessionId });
|
|
85018
85110
|
if (fromEnv || !claudePid) return fromEnv;
|
|
85019
85111
|
const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
|
|
85020
|
-
return
|
|
85021
|
-
(text3) => JSON.parse(text3),
|
|
85022
|
-
() => void 0
|
|
85023
|
-
);
|
|
85112
|
+
return readStateJson({ path });
|
|
85024
85113
|
}
|
|
85025
85114
|
|
|
85026
85115
|
// ../../modules/compute/contract/src/browser-tab.ts
|
|
@@ -86796,7 +86885,12 @@ var openLoginTerminalDefinition = external_exports.object({
|
|
|
86796
86885
|
});
|
|
86797
86886
|
var openLoginTerminalInputSchema = openLoginTerminalDefinition;
|
|
86798
86887
|
var loginTerminalDefinition = external_exports.discriminatedUnion("status", [
|
|
86799
|
-
external_exports.object({
|
|
86888
|
+
external_exports.object({
|
|
86889
|
+
status: external_exports.literal("starting"),
|
|
86890
|
+
retryAfterSeconds: external_exports.number().int().positive(),
|
|
86891
|
+
/** The computer is awake and only its link is coming back, e.g. after a deploy. */
|
|
86892
|
+
reconnecting: external_exports.boolean().optional()
|
|
86893
|
+
}),
|
|
86800
86894
|
external_exports.object({
|
|
86801
86895
|
status: external_exports.literal("ready"),
|
|
86802
86896
|
/** The WebSocket path of the terminal, token included; add `cols` and `rows`. */
|
|
@@ -87008,9 +87102,9 @@ var restSettleComputerCopyInputDefinition = settleComputerCopyInputDefinition.om
|
|
|
87008
87102
|
});
|
|
87009
87103
|
|
|
87010
87104
|
// src/services/computer-copy-commands.service.ts
|
|
87011
|
-
import { mkdtemp as mkdtemp2, open as
|
|
87105
|
+
import { mkdtemp as mkdtemp2, open as open5, rm as rm14, stat as stat11 } from "node:fs/promises";
|
|
87012
87106
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
87013
|
-
import { basename as
|
|
87107
|
+
import { basename as basename9, dirname as dirname18, resolve as resolve11 } from "node:path";
|
|
87014
87108
|
var COMPUTER_COPY_USAGE = ` laze computer copy <path> --agent <agent> [--to <folder>] [--json]
|
|
87015
87109
|
copy a local file or folder into your hosted agent's work folder
|
|
87016
87110
|
(its owner only, up to 2 GiB packed); <folder> is relative to the
|
|
@@ -87025,8 +87119,8 @@ function stringFlag(args, name3) {
|
|
|
87025
87119
|
function packingOf({ path, isDirectory }) {
|
|
87026
87120
|
const contents = isDirectory && path.endsWith("/");
|
|
87027
87121
|
const absolute = resolve11(path);
|
|
87028
|
-
const name3 =
|
|
87029
|
-
return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent:
|
|
87122
|
+
const name3 = basename9(absolute);
|
|
87123
|
+
return contents ? { name: name3, parent: absolute, entry: "." } : { name: name3, parent: dirname18(absolute), entry: name3 };
|
|
87030
87124
|
}
|
|
87031
87125
|
async function sendParts2({
|
|
87032
87126
|
context,
|
|
@@ -87035,7 +87129,7 @@ async function sendParts2({
|
|
|
87035
87129
|
}) {
|
|
87036
87130
|
const { upload } = started;
|
|
87037
87131
|
const parts = [];
|
|
87038
|
-
const file4 = await
|
|
87132
|
+
const file4 = await open5(archive2, "r");
|
|
87039
87133
|
try {
|
|
87040
87134
|
for (const part of upload.parts) {
|
|
87041
87135
|
const length = part.end - part.start;
|
|
@@ -87071,7 +87165,7 @@ async function copy({ context, args }) {
|
|
|
87071
87165
|
${COMPUTER_COPY_USAGE}`);
|
|
87072
87166
|
const to = stringFlag(args, "to") ?? ".";
|
|
87073
87167
|
const full = resolve11(context.cwd, path);
|
|
87074
|
-
const found = await
|
|
87168
|
+
const found = await stat11(full).catch(() => void 0);
|
|
87075
87169
|
if (!found) throw new CliUsageError(`${path} does not exist`);
|
|
87076
87170
|
const { name: name3, parent, entry } = packingOf({
|
|
87077
87171
|
path: path.endsWith("/") ? `${full}/` : full,
|
|
@@ -87085,7 +87179,7 @@ ${COMPUTER_COPY_USAGE}`);
|
|
|
87085
87179
|
env: { COPYFILE_DISABLE: "1" }
|
|
87086
87180
|
});
|
|
87087
87181
|
if (code !== 0) throw new CliUsageError(`tar could not pack ${path} (exit ${code})`);
|
|
87088
|
-
const sizeBytes = (await
|
|
87182
|
+
const sizeBytes = (await stat11(archive2)).size;
|
|
87089
87183
|
if (sizeBytes > COMPUTER_COPY_MAX_BYTES)
|
|
87090
87184
|
throw new CliUsageError(`${path} packs to ${mb(sizeBytes)}; a copy holds at most 2 GiB`);
|
|
87091
87185
|
const client = await computeClient({ context, args });
|
|
@@ -87109,7 +87203,7 @@ It lands before ${done.agentName}'s next turn.
|
|
|
87109
87203
|
`
|
|
87110
87204
|
);
|
|
87111
87205
|
} finally {
|
|
87112
|
-
await
|
|
87206
|
+
await rm14(dir, { recursive: true, force: true });
|
|
87113
87207
|
}
|
|
87114
87208
|
}
|
|
87115
87209
|
|
|
@@ -87400,11 +87494,11 @@ async function computer({ context, args }) {
|
|
|
87400
87494
|
}
|
|
87401
87495
|
|
|
87402
87496
|
// src/services/connect-commands.service.ts
|
|
87403
|
-
import { readFile as
|
|
87497
|
+
import { readFile as readFile20 } from "node:fs/promises";
|
|
87404
87498
|
|
|
87405
87499
|
// src/services/mcp-gateway.service.ts
|
|
87406
|
-
import { mkdir as
|
|
87407
|
-
import { basename as
|
|
87500
|
+
import { mkdir as mkdir9, readFile as readFile19, writeFile as writeFile7 } from "node:fs/promises";
|
|
87501
|
+
import { basename as basename10, join as join27, resolve as resolve12 } from "node:path";
|
|
87408
87502
|
import { createInterface as createInterface3 } from "node:readline";
|
|
87409
87503
|
var TURN_HEADER = "x-laze-turn";
|
|
87410
87504
|
function serveMcpGateway({
|
|
@@ -87447,7 +87541,7 @@ async function relayMcpLines({
|
|
|
87447
87541
|
const github3 = env.LAZE_GITHUB_CONNECTION;
|
|
87448
87542
|
const url2 = `${profile.url.replace(/\/+$/, "")}/api/connectors/mcp/${encodeURIComponent(profile.agentId)}${github3 ? `?github=${encodeURIComponent(github3)}` : ""}`;
|
|
87449
87543
|
const turnFile = env.LAZE_TURN_FILE;
|
|
87450
|
-
const readTurn = () =>
|
|
87544
|
+
const readTurn = () => readFile19(turnFile, "utf8").then(
|
|
87451
87545
|
(text3) => text3.trim(),
|
|
87452
87546
|
() => ""
|
|
87453
87547
|
);
|
|
@@ -87485,14 +87579,14 @@ var SAVES_FILES_META = "laze/files";
|
|
|
87485
87579
|
var FILE_META = "laze/file";
|
|
87486
87580
|
function safeName(name3, fallback) {
|
|
87487
87581
|
const printable = name3.replace(new RegExp("\\p{Cc}", "gu"), "");
|
|
87488
|
-
const last =
|
|
87582
|
+
const last = basename10(printable.replaceAll("\\", "/"));
|
|
87489
87583
|
return last && last !== "." && last !== ".." ? last : fallback;
|
|
87490
87584
|
}
|
|
87491
87585
|
async function saveMailFile({ root, file: file4 }) {
|
|
87492
|
-
const dir =
|
|
87493
|
-
const path =
|
|
87494
|
-
await
|
|
87495
|
-
await
|
|
87586
|
+
const dir = join27(root, safeName(file4.messageId, "message"));
|
|
87587
|
+
const path = join27(dir, safeName(file4.fileName, "attachment"));
|
|
87588
|
+
await mkdir9(dir, { recursive: true });
|
|
87589
|
+
await writeFile7(path, Buffer.from(file4.base64, "base64"));
|
|
87496
87590
|
return path;
|
|
87497
87591
|
}
|
|
87498
87592
|
function markSavesFiles(line) {
|
|
@@ -87609,7 +87703,7 @@ async function turnOf({ context }) {
|
|
|
87609
87703
|
const pinned = env.LAZE_TURN_TOKEN?.trim();
|
|
87610
87704
|
if (pinned) return pinned;
|
|
87611
87705
|
const file4 = env.LAZE_TURN_FILE;
|
|
87612
|
-
const turn = file4 ? await
|
|
87706
|
+
const turn = file4 ? await readFile20(file4, "utf8").then(
|
|
87613
87707
|
(text3) => text3.trim(),
|
|
87614
87708
|
() => ""
|
|
87615
87709
|
) : "";
|
|
@@ -87667,11 +87761,11 @@ async function connect({
|
|
|
87667
87761
|
}
|
|
87668
87762
|
|
|
87669
87763
|
// src/services/connector-commands.service.ts
|
|
87670
|
-
import { readFile as
|
|
87764
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
87671
87765
|
import { resolve as resolve13 } from "node:path";
|
|
87672
87766
|
|
|
87673
87767
|
// src/services/vault-keychain-commands.service.ts
|
|
87674
|
-
import { readFile as
|
|
87768
|
+
import { readFile as readFile21 } from "node:fs/promises";
|
|
87675
87769
|
|
|
87676
87770
|
// src/rules/vault-input.rules.ts
|
|
87677
87771
|
function secondsOf(text3) {
|
|
@@ -88089,7 +88183,7 @@ async function secretText({ context, args }) {
|
|
|
88089
88183
|
);
|
|
88090
88184
|
}
|
|
88091
88185
|
const file4 = flagText({ args, name: "from-file" });
|
|
88092
|
-
const text3 = file4 ? await
|
|
88186
|
+
const text3 = file4 ? await readFile21(file4, "utf8") : await context.readStdin();
|
|
88093
88187
|
const trimmed = text3.replace(/\r?\n$/, "");
|
|
88094
88188
|
if (!trimmed.trim()) throw new CliUsageError("No value: pipe it on stdin or use --from-file.");
|
|
88095
88189
|
return trimmed;
|
|
@@ -88103,7 +88197,7 @@ async function keychainOf2({ client, args }) {
|
|
|
88103
88197
|
const me = await client.get("/api/agents/me");
|
|
88104
88198
|
return { kind: "personal", ownerUserId: me.id };
|
|
88105
88199
|
}
|
|
88106
|
-
function
|
|
88200
|
+
function settingsOf2(args) {
|
|
88107
88201
|
const lease = flagText({ args, name: "lease" }) || flagText({ args, name: "max-lease" });
|
|
88108
88202
|
const approvers = args.lists.approver;
|
|
88109
88203
|
const everyUseAsks = yesNoOf({ args, name: "every-use-asks" });
|
|
@@ -88145,7 +88239,7 @@ var add3 = async ({ context, args }) => {
|
|
|
88145
88239
|
name: name3,
|
|
88146
88240
|
keychain: await keychainOf2({ client, args }),
|
|
88147
88241
|
sensitivity: levelOf2(args) ?? "checked",
|
|
88148
|
-
...
|
|
88242
|
+
...settingsOf2(args),
|
|
88149
88243
|
secret
|
|
88150
88244
|
});
|
|
88151
88245
|
if (args.flags.json) return printJson4({ context, data: created });
|
|
@@ -88155,7 +88249,7 @@ var add3 = async ({ context, args }) => {
|
|
|
88155
88249
|
);
|
|
88156
88250
|
};
|
|
88157
88251
|
var update = async ({ context, args }) => {
|
|
88158
|
-
const settings3 = { ...
|
|
88252
|
+
const settings3 = { ...settingsOf2(args), ...deviceApprovalOf(args) };
|
|
88159
88253
|
const { client, profile } = await signedIn({ context, args });
|
|
88160
88254
|
if (Object.keys(settings3).length === 0) throw new CliUsageError(VAULT_USAGE);
|
|
88161
88255
|
const word3 = args.words[2];
|
|
@@ -88322,7 +88416,7 @@ async function keyText({ context, args }) {
|
|
|
88322
88416
|
throw new CliUsageError("A key never goes in a flag: pipe it on stdin or use --from-file.");
|
|
88323
88417
|
}
|
|
88324
88418
|
const file4 = flagText({ args, name: "from-file" });
|
|
88325
|
-
const text3 = file4 ? await
|
|
88419
|
+
const text3 = file4 ? await readFile22(resolve13(context.cwd, file4), "utf8") : await context.readStdin();
|
|
88326
88420
|
const trimmed = text3.trim();
|
|
88327
88421
|
if (!trimmed) throw new CliUsageError("No key: pipe it on stdin or use --from-file.");
|
|
88328
88422
|
return trimmed;
|
|
@@ -88643,7 +88737,7 @@ async function conversationDelete({ context, args }) {
|
|
|
88643
88737
|
}
|
|
88644
88738
|
|
|
88645
88739
|
// src/services/discord-commands.service.ts
|
|
88646
|
-
import { readFile as
|
|
88740
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
88647
88741
|
import { resolve as resolve14 } from "node:path";
|
|
88648
88742
|
|
|
88649
88743
|
// ../../modules/discord/contract/src/discord.ts
|
|
@@ -88965,7 +89059,7 @@ async function secretsOf({ context, args }) {
|
|
|
88965
89059
|
const fromConnection = flagText({ args, name: "from-vault" });
|
|
88966
89060
|
if (fromConnection) return { fromConnection };
|
|
88967
89061
|
const file4 = flagText({ args, name: "from-file" });
|
|
88968
|
-
const text3 = file4 ? await
|
|
89062
|
+
const text3 = file4 ? await readFile23(resolve14(context.cwd, file4), "utf8") : await context.readStdin();
|
|
88969
89063
|
const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
88970
89064
|
if (lines2.length !== 2) {
|
|
88971
89065
|
throw new CliUsageError(
|
|
@@ -89235,8 +89329,8 @@ var DOMAINS_USAGE = `Usage:
|
|
|
89235
89329
|
var printJson5 = (context, data) => context.out(`${JSON.stringify(data, null, 2)}
|
|
89236
89330
|
`);
|
|
89237
89331
|
function printDomain(context, row) {
|
|
89238
|
-
const
|
|
89239
|
-
context.out(`${row.domain} ${
|
|
89332
|
+
const join35 = row.autoJoin ? "auto-join on" : "auto-join off";
|
|
89333
|
+
context.out(`${row.domain} ${join35}${row.enforced ? " single sign-on enforced" : ""}
|
|
89240
89334
|
`);
|
|
89241
89335
|
}
|
|
89242
89336
|
async function list4({ context, args }) {
|
|
@@ -89268,7 +89362,7 @@ async function domains({ context, args }) {
|
|
|
89268
89362
|
}
|
|
89269
89363
|
|
|
89270
89364
|
// src/services/emoji-commands.service.ts
|
|
89271
|
-
import { readFile as
|
|
89365
|
+
import { readFile as readFile24 } from "node:fs/promises";
|
|
89272
89366
|
import { resolve as resolve15 } from "node:path";
|
|
89273
89367
|
var EMOJI_USAGE = `Usage:
|
|
89274
89368
|
laze emoji list [--json] the workspace's custom emoji, aliases and who added each
|
|
@@ -89309,7 +89403,7 @@ async function addEmoji({ context, args, client }) {
|
|
|
89309
89403
|
const file4 = wordAt4(args, 3);
|
|
89310
89404
|
let bytes;
|
|
89311
89405
|
try {
|
|
89312
|
-
bytes = new Uint8Array(await
|
|
89406
|
+
bytes = new Uint8Array(await readFile24(resolve15(context.cwd, file4)));
|
|
89313
89407
|
} catch {
|
|
89314
89408
|
throw new CliUsageError(`Cannot read ${file4}.`);
|
|
89315
89409
|
}
|
|
@@ -89625,7 +89719,7 @@ var ExternalChannelBannerSlot = externalUi.component("channel-banner");
|
|
|
89625
89719
|
var ExternalSharingHooksToken = externalUi.hooks("sharing");
|
|
89626
89720
|
|
|
89627
89721
|
// src/services/workspace-commands.service.ts
|
|
89628
|
-
import { readFile as
|
|
89722
|
+
import { readFile as readFile25 } from "node:fs/promises";
|
|
89629
89723
|
import { resolve as resolve16 } from "node:path";
|
|
89630
89724
|
var ROLE_NAMES2 = {
|
|
89631
89725
|
OWNER: "Owner",
|
|
@@ -89669,7 +89763,7 @@ async function mine2({ context, args }) {
|
|
|
89669
89763
|
`).join("") || "No workspaces.\n"
|
|
89670
89764
|
});
|
|
89671
89765
|
}
|
|
89672
|
-
async function
|
|
89766
|
+
async function rename4({ context, args }) {
|
|
89673
89767
|
const name3 = args.words.slice(2).join(" ").trim();
|
|
89674
89768
|
if (!name3) throw new CliUsageError("Usage: laze workspace rename <name>");
|
|
89675
89769
|
const { client } = await signedIn({ context, args });
|
|
@@ -89787,7 +89881,7 @@ async function switchTo({ context, args }) {
|
|
|
89787
89881
|
`Not signed in to ${target.name} on this machine: run laze login --profile <name> and pick ${target.name} when you approve it.`
|
|
89788
89882
|
);
|
|
89789
89883
|
}
|
|
89790
|
-
await context.store.
|
|
89884
|
+
await context.store.setCurrent({ name: chosen });
|
|
89791
89885
|
print7({
|
|
89792
89886
|
context,
|
|
89793
89887
|
args,
|
|
@@ -89808,7 +89902,7 @@ var LOGO_USAGE = "Usage: laze workspace logo set <file.png|jpg|webp> | laze work
|
|
|
89808
89902
|
async function readLogo({ context, file: file4 }) {
|
|
89809
89903
|
let bytes;
|
|
89810
89904
|
try {
|
|
89811
|
-
bytes = new Uint8Array(await
|
|
89905
|
+
bytes = new Uint8Array(await readFile25(resolve16(context.cwd, file4)));
|
|
89812
89906
|
} catch {
|
|
89813
89907
|
throw new CliUsageError(`No file to read at ${file4}.`);
|
|
89814
89908
|
}
|
|
@@ -89848,7 +89942,7 @@ var WORKSPACE_COMMANDS = {
|
|
|
89848
89942
|
switch: switchTo,
|
|
89849
89943
|
logo,
|
|
89850
89944
|
mine: mine2,
|
|
89851
|
-
rename:
|
|
89945
|
+
rename: rename4,
|
|
89852
89946
|
create,
|
|
89853
89947
|
leave,
|
|
89854
89948
|
delete: scheduleDeletion,
|
|
@@ -90408,7 +90502,7 @@ async function agentFeedAccess({
|
|
|
90408
90502
|
}
|
|
90409
90503
|
|
|
90410
90504
|
// src/services/feed-commands.service.ts
|
|
90411
|
-
import { readFile as
|
|
90505
|
+
import { readFile as readFile26 } from "node:fs/promises";
|
|
90412
90506
|
import { resolve as resolve17 } from "node:path";
|
|
90413
90507
|
|
|
90414
90508
|
// ../../modules/feed/contract/src/feed.delegate.ts
|
|
@@ -90730,6 +90824,11 @@ var feedViewerStateSchemaDefinition = external_exports.object({
|
|
|
90730
90824
|
unread: external_exports.boolean(),
|
|
90731
90825
|
/** Back from a snooze or a show-at date, not yet touched. */
|
|
90732
90826
|
woke: external_exports.enum(["snooze", "show_at"]).nullable(),
|
|
90827
|
+
/** Why a woke card came back and who brought it; `by` is null on the reader's own snooze. */
|
|
90828
|
+
wake: external_exports.object({
|
|
90829
|
+
cause: external_exports.enum(["snooze", "show_at", "urgent_reply"]),
|
|
90830
|
+
by: feedAuthorSchema.nullable()
|
|
90831
|
+
}).optional(),
|
|
90733
90832
|
snoozedUntil: external_exports.iso.datetime().nullable(),
|
|
90734
90833
|
/** The agent that snoozed it for the person, when it was not the person. */
|
|
90735
90834
|
snoozedBy: feedAuthorSchema.nullable(),
|
|
@@ -91500,7 +91599,7 @@ async function feedTurnOf({
|
|
|
91500
91599
|
const read4 = async () => {
|
|
91501
91600
|
const pinned = env.LAZE_TURN_TOKEN?.trim();
|
|
91502
91601
|
if (pinned) return pinned;
|
|
91503
|
-
if (env.LAZE_TURN_FILE) return (await
|
|
91602
|
+
if (env.LAZE_TURN_FILE) return (await readFile26(env.LAZE_TURN_FILE, "utf8")).trim();
|
|
91504
91603
|
return agent3 ? connectedTurnTokenOf({ client, channelId: channel }) : "";
|
|
91505
91604
|
};
|
|
91506
91605
|
const turn = await read4().catch(() => "");
|
|
@@ -91574,7 +91673,7 @@ async function bodyOf2({
|
|
|
91574
91673
|
flags: flags2
|
|
91575
91674
|
}) {
|
|
91576
91675
|
const body = { ...flags2.fields };
|
|
91577
|
-
const read4 = (source) => "file" in source ?
|
|
91676
|
+
const read4 = (source) => "file" in source ? readFile26(resolve17(context.cwd, source.file), "utf8") : source.text;
|
|
91578
91677
|
for (const [field, source] of Object.entries(flags2.texts)) body[field] = await read4(source);
|
|
91579
91678
|
if (flags2.rich) {
|
|
91580
91679
|
const text3 = await read4(flags2.rich.source);
|
|
@@ -91837,7 +91936,7 @@ async function textFlag({
|
|
|
91837
91936
|
}) {
|
|
91838
91937
|
const value = flagText({ args, name: name3 });
|
|
91839
91938
|
if (!value.startsWith("@")) return value;
|
|
91840
|
-
return
|
|
91939
|
+
return readFile26(resolve17(context.cwd, value.slice(1)), "utf8");
|
|
91841
91940
|
}
|
|
91842
91941
|
async function feedList({ context, args }) {
|
|
91843
91942
|
const { client } = await signedIn({ context, args });
|
|
@@ -91927,7 +92026,7 @@ async function ranksOf({
|
|
|
91927
92026
|
}) {
|
|
91928
92027
|
const file4 = flagText({ args, name: "file" });
|
|
91929
92028
|
if (file4) {
|
|
91930
|
-
const parsed = JSON.parse(await
|
|
92029
|
+
const parsed = JSON.parse(await readFile26(resolve17(context.cwd, file4), "utf8"));
|
|
91931
92030
|
if (Array.isArray(parsed)) return parsed;
|
|
91932
92031
|
throw new CliUsageError("--file holds a list of {itemId, priority}");
|
|
91933
92032
|
}
|
|
@@ -92040,7 +92139,7 @@ async function feed({ context, args }) {
|
|
|
92040
92139
|
}
|
|
92041
92140
|
|
|
92042
92141
|
// src/services/github-commands.service.ts
|
|
92043
|
-
import { readFile as
|
|
92142
|
+
import { readFile as readFile27 } from "node:fs/promises";
|
|
92044
92143
|
|
|
92045
92144
|
// src/rules/github-signature.rules.ts
|
|
92046
92145
|
var TURN_SEPARATOR = "~";
|
|
@@ -92110,7 +92209,7 @@ var REAL_GH = "/usr/bin/gh";
|
|
|
92110
92209
|
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
92210
|
async function turnFileToken({ env }) {
|
|
92112
92211
|
if (!env.LAZE_TURN_FILE) return "";
|
|
92113
|
-
return
|
|
92212
|
+
return readFile27(env.LAZE_TURN_FILE, "utf8").then(
|
|
92114
92213
|
(text3) => text3.trim(),
|
|
92115
92214
|
() => ""
|
|
92116
92215
|
);
|
|
@@ -92144,7 +92243,7 @@ async function githubGh({
|
|
|
92144
92243
|
args: args.rest,
|
|
92145
92244
|
agentName: profile.name ?? "An agent",
|
|
92146
92245
|
threadUrl: threadUrlOf({ env, workspaceId: profile.workspaceId }),
|
|
92147
|
-
readBodyFile: (path) => path === "-" ? context.readStdin() :
|
|
92246
|
+
readBodyFile: (path) => path === "-" ? context.readStdin() : readFile27(path, "utf8")
|
|
92148
92247
|
});
|
|
92149
92248
|
return context.runCommand({
|
|
92150
92249
|
command: [REAL_GH, ...ghArgs],
|
|
@@ -92307,7 +92406,7 @@ async function create2({ context, args }) {
|
|
|
92307
92406
|
});
|
|
92308
92407
|
printGroup({ context, args, group });
|
|
92309
92408
|
}
|
|
92310
|
-
async function
|
|
92409
|
+
async function rename5({ context, args }) {
|
|
92311
92410
|
const group = wordAt6({ args, at: 2 });
|
|
92312
92411
|
const name3 = wordAt6({ args, at: 3 });
|
|
92313
92412
|
const { client } = await signedIn({ context, args });
|
|
@@ -92346,7 +92445,7 @@ function changing3(key) {
|
|
|
92346
92445
|
var COMMANDS = {
|
|
92347
92446
|
list: list7,
|
|
92348
92447
|
create: create2,
|
|
92349
|
-
rename:
|
|
92448
|
+
rename: rename5,
|
|
92350
92449
|
delete: remove5,
|
|
92351
92450
|
add: changing3("add"),
|
|
92352
92451
|
remove: changing3("remove")
|
|
@@ -92754,35 +92853,28 @@ async function ip({ context, args }) {
|
|
|
92754
92853
|
}
|
|
92755
92854
|
|
|
92756
92855
|
// src/services/join-commands.service.ts
|
|
92757
|
-
import {
|
|
92758
|
-
import { dirname as
|
|
92856
|
+
import { rm as rm15 } from "node:fs/promises";
|
|
92857
|
+
import { dirname as dirname19, join as join28 } from "node:path";
|
|
92759
92858
|
var DEFAULT_WAIT_SECONDS2 = 100;
|
|
92760
92859
|
var JOIN_USAGE = "Usage: laze join [--workspace <name|id|invite link>] [--for <email>] [--name <name>] [--note <text>] [--timeout <seconds>] [--project <folder>]";
|
|
92761
92860
|
function pendingPathOf({ context }) {
|
|
92762
|
-
return
|
|
92861
|
+
return join28(dirname19(context.environment.configPath), "join", "pending.json");
|
|
92763
92862
|
}
|
|
92764
92863
|
async function readPending({
|
|
92765
92864
|
context,
|
|
92766
92865
|
url: url2,
|
|
92767
92866
|
args
|
|
92768
92867
|
}) {
|
|
92769
|
-
const pending2 = await
|
|
92770
|
-
(text3) => JSON.parse(text3),
|
|
92771
|
-
() => void 0
|
|
92772
|
-
);
|
|
92868
|
+
const pending2 = await readStateJson({ path: pendingPathOf({ context }) });
|
|
92773
92869
|
if (!pending2 || pending2.url !== url2) return void 0;
|
|
92774
92870
|
if (args && !asksTheSame({ pending: pending2, flags: flaggedOf({ args }) })) return void 0;
|
|
92775
92871
|
return Temporal3.Instant.from(pending2.expiresAt).epochMilliseconds > context.nowMs() ? pending2 : void 0;
|
|
92776
92872
|
}
|
|
92777
92873
|
async function keepPending({ context, pending: pending2 }) {
|
|
92778
|
-
|
|
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);
|
|
92874
|
+
await writeStateJson({ path: pendingPathOf({ context }), value: pending2 });
|
|
92783
92875
|
}
|
|
92784
92876
|
async function dropPending({ context }) {
|
|
92785
|
-
await
|
|
92877
|
+
await rm15(pendingPathOf({ context }), { force: true });
|
|
92786
92878
|
}
|
|
92787
92879
|
function waitSecondsOf3({ args }) {
|
|
92788
92880
|
const raw = flagText({ args, name: "timeout" });
|
|
@@ -93350,7 +93442,7 @@ async function get({ context, args }) {
|
|
|
93350
93442
|
machine: await client.post(COMPUTE_REST_PATHS.get, { machine: machine2 })
|
|
93351
93443
|
});
|
|
93352
93444
|
}
|
|
93353
|
-
async function
|
|
93445
|
+
async function rename6({ context, args }) {
|
|
93354
93446
|
const machine2 = wordAt7({ args, at: 2 });
|
|
93355
93447
|
const name3 = wordAt7({ args, at: 3 });
|
|
93356
93448
|
const client = await computeClient({ context, args });
|
|
@@ -93396,7 +93488,7 @@ ${MACHINE_ACCESS_USAGE}`);
|
|
|
93396
93488
|
});
|
|
93397
93489
|
printMachine({ context, args, machine: changed });
|
|
93398
93490
|
}
|
|
93399
|
-
var COMMANDS2 = { status: status8, get, rename:
|
|
93491
|
+
var COMMANDS2 = { status: status8, get, rename: rename6, grant: share2, revoke: share2, budget };
|
|
93400
93492
|
function machineAccessCommand(name3) {
|
|
93401
93493
|
return name3 && Object.hasOwn(COMMANDS2, name3) ? COMMANDS2[name3] : void 0;
|
|
93402
93494
|
}
|
|
@@ -93916,18 +94008,18 @@ async function serveMcp({
|
|
|
93916
94008
|
}
|
|
93917
94009
|
|
|
93918
94010
|
// src/services/memory-commands.service.ts
|
|
93919
|
-
import { readdir as readdir7, readFile as
|
|
93920
|
-
import { join as
|
|
94011
|
+
import { readdir as readdir7, readFile as readFile29 } from "node:fs/promises";
|
|
94012
|
+
import { join as join29, resolve as resolve19 } from "node:path";
|
|
93921
94013
|
|
|
93922
94014
|
// src/services/mount-files.service.ts
|
|
93923
|
-
import { mkdir as
|
|
93924
|
-
import { dirname as
|
|
94015
|
+
import { mkdir as mkdir10, readFile as readFile28, rm as rm16, writeFile as writeFile8 } from "node:fs/promises";
|
|
94016
|
+
import { dirname as dirname20, relative as relative5, resolve as resolve18 } from "node:path";
|
|
93925
94017
|
async function textArgument({
|
|
93926
94018
|
context,
|
|
93927
94019
|
value
|
|
93928
94020
|
}) {
|
|
93929
94021
|
if (value === "-") return context.readStdin();
|
|
93930
|
-
if (value.startsWith("@")) return
|
|
94022
|
+
if (value.startsWith("@")) return readFile28(resolve18(context.cwd, value.slice(1)), "utf8");
|
|
93931
94023
|
return value;
|
|
93932
94024
|
}
|
|
93933
94025
|
function turnChannel({ context, args }) {
|
|
@@ -93940,15 +94032,15 @@ async function writeMount({
|
|
|
93940
94032
|
files: files2
|
|
93941
94033
|
}) {
|
|
93942
94034
|
const root = resolve18(context.cwd, flagText({ args, name: "dir", fallback: ".laze" }), folder);
|
|
93943
|
-
await
|
|
93944
|
-
await
|
|
94035
|
+
await rm16(root, { recursive: true, force: true });
|
|
94036
|
+
await mkdir10(root, { recursive: true });
|
|
93945
94037
|
for (const file4 of files2) {
|
|
93946
94038
|
const target = resolve18(root, file4.path);
|
|
93947
94039
|
const inside = relative5(root, target);
|
|
93948
94040
|
if (!inside || inside.startsWith(".."))
|
|
93949
94041
|
throw new Error(`Refusing to write outside ${root}: ${file4.path}`);
|
|
93950
|
-
await
|
|
93951
|
-
await
|
|
94042
|
+
await mkdir10(dirname20(target), { recursive: true });
|
|
94043
|
+
await writeFile8(target, file4.content);
|
|
93952
94044
|
}
|
|
93953
94045
|
return root;
|
|
93954
94046
|
}
|
|
@@ -94074,7 +94166,7 @@ async function turnTokenOf5({ context }) {
|
|
|
94074
94166
|
const pinned = env.LAZE_TURN_TOKEN?.trim();
|
|
94075
94167
|
if (pinned) return pinned;
|
|
94076
94168
|
if (!env.LAZE_TURN_FILE) return "";
|
|
94077
|
-
return
|
|
94169
|
+
return readFile29(env.LAZE_TURN_FILE, "utf8").then(
|
|
94078
94170
|
(text3) => text3.trim(),
|
|
94079
94171
|
() => ""
|
|
94080
94172
|
);
|
|
@@ -94204,15 +94296,15 @@ async function siestaImport({
|
|
|
94204
94296
|
dir
|
|
94205
94297
|
}) {
|
|
94206
94298
|
const root = resolve19(context.cwd, dir);
|
|
94207
|
-
const log = await
|
|
94208
|
-
const names = (await readdir7(
|
|
94299
|
+
const log = await readFile29(join29(root, "LOG.md"));
|
|
94300
|
+
const names = (await readdir7(join29(root, "tree")).catch(() => [])).filter(
|
|
94209
94301
|
(name3) => /^\d{1,6}-\d{1,6}\.md$/.test(name3)
|
|
94210
94302
|
);
|
|
94211
94303
|
const tree = Object.fromEntries(
|
|
94212
94304
|
await Promise.all(
|
|
94213
94305
|
names.map(async (name3) => [
|
|
94214
94306
|
name3.slice(0, -3),
|
|
94215
|
-
(await
|
|
94307
|
+
(await readFile29(join29(root, "tree", name3))).toString("base64")
|
|
94216
94308
|
])
|
|
94217
94309
|
)
|
|
94218
94310
|
);
|
|
@@ -94232,15 +94324,15 @@ async function memoryImport({ context, args }) {
|
|
|
94232
94324
|
const dir = flagText({ args, name: "optmem" });
|
|
94233
94325
|
if (!dir) throw new CliUsageError(USAGE13);
|
|
94234
94326
|
const root = resolve19(context.cwd, dir);
|
|
94235
|
-
const log = await
|
|
94236
|
-
const sizes2 = (await readdir7(
|
|
94327
|
+
const log = await readFile29(join29(root, "LOG.txt"));
|
|
94328
|
+
const sizes2 = (await readdir7(join29(root, "TREE")).catch(() => [])).filter(
|
|
94237
94329
|
(name3) => /^\d{1,4}$/.test(name3)
|
|
94238
94330
|
);
|
|
94239
94331
|
const tree = Object.fromEntries(
|
|
94240
94332
|
await Promise.all(
|
|
94241
94333
|
sizes2.map(async (size) => [
|
|
94242
94334
|
size,
|
|
94243
|
-
(await
|
|
94335
|
+
(await readFile29(join29(root, "TREE", size))).toString("base64")
|
|
94244
94336
|
])
|
|
94245
94337
|
)
|
|
94246
94338
|
);
|
|
@@ -94804,9 +94896,9 @@ async function openclaw({
|
|
|
94804
94896
|
}
|
|
94805
94897
|
|
|
94806
94898
|
// src/services/operator-key-commands.service.ts
|
|
94807
|
-
import { createHash as createHash7, randomBytes as
|
|
94808
|
-
import { mkdir as
|
|
94809
|
-
import { dirname as
|
|
94899
|
+
import { createHash as createHash7, randomBytes as randomBytes4 } from "node:crypto";
|
|
94900
|
+
import { mkdir as mkdir11, readFile as readFile30, rm as rm17, writeFile as writeFile9 } from "node:fs/promises";
|
|
94901
|
+
import { dirname as dirname21, join as join30 } from "node:path";
|
|
94810
94902
|
|
|
94811
94903
|
// ../../modules/audit-log/contract/src/audit-log.api.ts
|
|
94812
94904
|
var auditEntrySchemaDefinition = external_exports.object({
|
|
@@ -96151,15 +96243,15 @@ var OPERATOR_KEY_USAGE = `Temporary operator keys (ask, an operator approves wit
|
|
|
96151
96243
|
laze ops status <key> waiting, approved or ended
|
|
96152
96244
|
laze ops use <key> run the approved action and print the answer`;
|
|
96153
96245
|
var POLL_MS3 = 5e3;
|
|
96154
|
-
var keyFile = ({ context, keyId }) =>
|
|
96246
|
+
var keyFile = ({ context, keyId }) => join30(dirname21(context.environment.configPath), "operator-keys", keyId.replaceAll("/", "_"));
|
|
96155
96247
|
async function saveSecret({
|
|
96156
96248
|
context,
|
|
96157
96249
|
keyId,
|
|
96158
96250
|
secret
|
|
96159
96251
|
}) {
|
|
96160
96252
|
const path = keyFile({ context, keyId });
|
|
96161
|
-
await
|
|
96162
|
-
await
|
|
96253
|
+
await mkdir11(dirname21(path), { recursive: true, mode: 448 });
|
|
96254
|
+
await writeFile9(path, secret, { mode: 384 });
|
|
96163
96255
|
}
|
|
96164
96256
|
function typedArg(text3) {
|
|
96165
96257
|
if (["true", "false", "null"].includes(text3)) return JSON.parse(text3);
|
|
@@ -96176,12 +96268,12 @@ ${OPERATOR_KEY_USAGE}`);
|
|
|
96176
96268
|
return Object.fromEntries(pairs);
|
|
96177
96269
|
}
|
|
96178
96270
|
var EXPIRED_LINE = `Expired: nobody answered within ${OPERATOR_KEY.pendingMinutes} minutes. Nothing ran. Ask again with laze ops request.`;
|
|
96179
|
-
function statusLine2({ key, nowMs }) {
|
|
96271
|
+
function statusLine2({ key, nowMs: nowMs2 }) {
|
|
96180
96272
|
switch (key.status) {
|
|
96181
96273
|
case "approved":
|
|
96182
96274
|
return `Approved until ${key.endsAt}. Run: laze ops use ${key.id}`;
|
|
96183
96275
|
case "pending":
|
|
96184
|
-
return Temporal3.Instant.from(key.pendingUntil).epochMilliseconds <=
|
|
96276
|
+
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
96277
|
case "expired":
|
|
96186
96278
|
return EXPIRED_LINE;
|
|
96187
96279
|
case "denied":
|
|
@@ -96210,7 +96302,7 @@ async function requestKey({ context, args }) {
|
|
|
96210
96302
|
const reason2 = flagText({ args, name: "reason" });
|
|
96211
96303
|
if (!action || !target || !reason2.trim()) throw new CliUsageError(OPERATOR_KEY_USAGE);
|
|
96212
96304
|
const { client } = await signedIn({ context, args });
|
|
96213
|
-
const secret =
|
|
96305
|
+
const secret = randomBytes4(32).toString("hex");
|
|
96214
96306
|
const key = await client.post(OPERATOR_KEY_REST_PATHS.request, {
|
|
96215
96307
|
action,
|
|
96216
96308
|
target,
|
|
@@ -96243,7 +96335,7 @@ async function forgetIfOver({
|
|
|
96243
96335
|
const key = await client.post(OPERATOR_KEY_REST_PATHS.status, { keyId });
|
|
96244
96336
|
const windowOver = key.endsAt !== null && Temporal3.Instant.from(key.endsAt).epochMilliseconds <= context.nowMs();
|
|
96245
96337
|
if (key.status !== "pending" && (key.status !== "approved" || windowOver || key.spentAt)) {
|
|
96246
|
-
await
|
|
96338
|
+
await rm17(keyFile({ context, keyId }), { force: true });
|
|
96247
96339
|
}
|
|
96248
96340
|
return key;
|
|
96249
96341
|
}
|
|
@@ -96252,7 +96344,7 @@ async function useKey({ context, args }) {
|
|
|
96252
96344
|
if (!keyId) throw new CliUsageError(OPERATOR_KEY_USAGE);
|
|
96253
96345
|
const { client } = await signedIn({ context, args });
|
|
96254
96346
|
const path = keyFile({ context, keyId });
|
|
96255
|
-
const secret = await
|
|
96347
|
+
const secret = await readFile30(path, "utf8").catch(() => null);
|
|
96256
96348
|
if (secret === null) {
|
|
96257
96349
|
throw new CliUsageError(`No operator key ${keyId} is kept on this machine.`);
|
|
96258
96350
|
}
|
|
@@ -96317,8 +96409,8 @@ ${OPS_USAGE}`);
|
|
|
96317
96409
|
}
|
|
96318
96410
|
|
|
96319
96411
|
// src/services/release-watch.service.ts
|
|
96320
|
-
import {
|
|
96321
|
-
import { dirname as
|
|
96412
|
+
import { realpath } from "node:fs/promises";
|
|
96413
|
+
import { dirname as dirname22, join as join31 } from "node:path";
|
|
96322
96414
|
|
|
96323
96415
|
// src/rules/cli-update.rules.ts
|
|
96324
96416
|
var CLI_PACKAGE = "@lazehq/cli";
|
|
@@ -96464,16 +96556,15 @@ async function startedUpdate({
|
|
|
96464
96556
|
if (context.environment.inherited.LAZE_AUTO_UPDATE === "0") return null;
|
|
96465
96557
|
const plan2 = updatePlanOf({ script: await scriptOf(context) });
|
|
96466
96558
|
if (plan2.kind !== "install") return null;
|
|
96467
|
-
const folder =
|
|
96468
|
-
const stamp =
|
|
96469
|
-
const last = await
|
|
96559
|
+
const folder = dirname22(context.environment.configPath);
|
|
96560
|
+
const stamp = join31(folder, "auto-update.json");
|
|
96561
|
+
const last = await readStateJson({ path: stamp }) ?? null;
|
|
96470
96562
|
const now = context.nowMs();
|
|
96471
96563
|
if (last?.server === server && now - last.atMs < RETRY_AFTER_MS) return null;
|
|
96472
|
-
await
|
|
96473
|
-
await writeFile26(stamp, JSON.stringify({ server, atMs: now }), { mode: 384 });
|
|
96564
|
+
await writeStateJson({ path: stamp, value: { server, atMs: now } });
|
|
96474
96565
|
context.processes.spawnDetached({
|
|
96475
96566
|
argv: [...context.program, "update"],
|
|
96476
|
-
logPath:
|
|
96567
|
+
logPath: join31(folder, "auto-update.log")
|
|
96477
96568
|
});
|
|
96478
96569
|
return { manager: plan2.manager };
|
|
96479
96570
|
}
|
|
@@ -96510,7 +96601,7 @@ function watchingRelease({
|
|
|
96510
96601
|
}
|
|
96511
96602
|
|
|
96512
96603
|
// src/services/rush-guard.service.ts
|
|
96513
|
-
import {
|
|
96604
|
+
import { rm as rm18 } from "node:fs/promises";
|
|
96514
96605
|
var WATCH_MS3 = 2e3;
|
|
96515
96606
|
var RETRY_MS2 = 3e4;
|
|
96516
96607
|
async function guardRound(guard) {
|
|
@@ -96553,10 +96644,7 @@ async function rushWakeHook({ context, args }) {
|
|
|
96553
96644
|
while (context.processes.alive(claudePid)) await context.sleep(WATCH_MS3);
|
|
96554
96645
|
const { client, name: name3 } = await signedIn({ context, args });
|
|
96555
96646
|
const noted = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
|
|
96556
|
-
const note = await
|
|
96557
|
-
(text3) => JSON.parse(text3),
|
|
96558
|
-
() => void 0
|
|
96559
|
-
);
|
|
96647
|
+
const note = await readStateJson({ path: noted });
|
|
96560
96648
|
const { launch = {}, ...session } = note ?? {};
|
|
96561
96649
|
const lock = statePathOf({ context, kind: "waiters", profile: name3 });
|
|
96562
96650
|
const rush = { id: id4, program };
|
|
@@ -96582,10 +96670,10 @@ async function rushWakeHook({ context, args }) {
|
|
|
96582
96670
|
return 0;
|
|
96583
96671
|
} finally {
|
|
96584
96672
|
if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
|
|
96585
|
-
await
|
|
96673
|
+
await rm18(lock, { force: true });
|
|
96586
96674
|
}
|
|
96587
96675
|
} finally {
|
|
96588
|
-
await
|
|
96676
|
+
await rm18(path, { force: true });
|
|
96589
96677
|
}
|
|
96590
96678
|
}
|
|
96591
96679
|
|
|
@@ -96751,8 +96839,8 @@ async function schedule({ context, args }) {
|
|
|
96751
96839
|
}
|
|
96752
96840
|
|
|
96753
96841
|
// src/services/skill-commands.service.ts
|
|
96754
|
-
import { readdir as readdir8, readFile as
|
|
96755
|
-
import { join as
|
|
96842
|
+
import { readdir as readdir8, readFile as readFile31 } from "node:fs/promises";
|
|
96843
|
+
import { join as join32, relative as relative6, resolve as resolve21 } from "node:path";
|
|
96756
96844
|
var USAGE17 = `Usage:
|
|
96757
96845
|
laze skill list [--agent <agentId>]
|
|
96758
96846
|
laze skill install <catalogue-id> [--as <name>] [--agent <agentId>]
|
|
@@ -96773,8 +96861,8 @@ async function folderFiles({ root }) {
|
|
|
96773
96861
|
const files2 = [];
|
|
96774
96862
|
for (const entry of entries) {
|
|
96775
96863
|
if (!entry.isFile()) continue;
|
|
96776
|
-
const full =
|
|
96777
|
-
files2.push({ path: relative6(root, full), content: await
|
|
96864
|
+
const full = join32(entry.parentPath, entry.name);
|
|
96865
|
+
files2.push({ path: relative6(root, full), content: await readFile31(full, "utf8") });
|
|
96778
96866
|
}
|
|
96779
96867
|
return files2.toSorted((a, b) => a.path.localeCompare(b.path));
|
|
96780
96868
|
}
|
|
@@ -96872,7 +96960,7 @@ async function skillUpdate({ context, args }) {
|
|
|
96872
96960
|
if (!name3 || !newName && description === void 0 && !skillMdFile) {
|
|
96873
96961
|
throw new CliUsageError(USAGE17);
|
|
96874
96962
|
}
|
|
96875
|
-
const skillMd = skillMdFile ? await
|
|
96963
|
+
const skillMd = skillMdFile ? await readFile31(resolve21(context.cwd, skillMdFile), "utf8") : void 0;
|
|
96876
96964
|
const { client } = await signedIn({ context, args });
|
|
96877
96965
|
const updated = await client.post("/api/skills/update", {
|
|
96878
96966
|
name: name3,
|
|
@@ -96918,7 +97006,7 @@ async function skill({ context, args }) {
|
|
|
96918
97006
|
}
|
|
96919
97007
|
|
|
96920
97008
|
// src/services/slack-commands.service.ts
|
|
96921
|
-
import { readFile as
|
|
97009
|
+
import { readFile as readFile32 } from "node:fs/promises";
|
|
96922
97010
|
import { resolve as resolve22 } from "node:path";
|
|
96923
97011
|
var SLACK_USAGE = `Usage (a person's key; Slack stays the source, the bot joins no channel by itself):
|
|
96924
97012
|
laze slack overview connected Slack workspaces, mirrors, your link
|
|
@@ -96966,7 +97054,7 @@ async function secretLines({ context, args }) {
|
|
|
96966
97054
|
throw new CliUsageError("A secret never goes in a flag: pipe it on stdin or use --from-file.");
|
|
96967
97055
|
}
|
|
96968
97056
|
const file4 = flagText({ args, name: "from-file" });
|
|
96969
|
-
const text3 = file4 ? await
|
|
97057
|
+
const text3 = file4 ? await readFile32(resolve22(context.cwd, file4), "utf8") : await context.readStdin();
|
|
96970
97058
|
return text3.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
96971
97059
|
}
|
|
96972
97060
|
async function secretsOf2({
|
|
@@ -97270,7 +97358,7 @@ async function slack({
|
|
|
97270
97358
|
}
|
|
97271
97359
|
|
|
97272
97360
|
// src/services/sso-commands.service.ts
|
|
97273
|
-
import { readFile as
|
|
97361
|
+
import { readFile as readFile33 } from "node:fs/promises";
|
|
97274
97362
|
var SSO_USAGE = `Usage:
|
|
97275
97363
|
laze sso domains claimed domains and how each signs in (admins)
|
|
97276
97364
|
laze sso claim <domain> the TXT record that proves the domain
|
|
@@ -97357,7 +97445,7 @@ function refuseSecretFlags({ args }) {
|
|
|
97357
97445
|
}
|
|
97358
97446
|
async function clientSecretOf({ context, args }) {
|
|
97359
97447
|
const file4 = flagText({ args, name: "from-file" });
|
|
97360
|
-
const text3 = file4 ? await
|
|
97448
|
+
const text3 = file4 ? await readFile33(file4, "utf8") : await context.readStdin();
|
|
97361
97449
|
const secret = text3.trim();
|
|
97362
97450
|
if (!secret) throw new CliUsageError("No client secret: pipe it on stdin or use --from-file.");
|
|
97363
97451
|
return secret;
|
|
@@ -97689,8 +97777,8 @@ async function update2({
|
|
|
97689
97777
|
}
|
|
97690
97778
|
|
|
97691
97779
|
// src/services/vault-env-commands.service.ts
|
|
97692
|
-
import { readFile as
|
|
97693
|
-
import { dirname as
|
|
97780
|
+
import { readFile as readFile34, stat as stat12 } from "node:fs/promises";
|
|
97781
|
+
import { dirname as dirname23, join as join33, resolve as resolve23 } from "node:path";
|
|
97694
97782
|
|
|
97695
97783
|
// src/rules/vault-manifest.rules.ts
|
|
97696
97784
|
var VARIABLE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
@@ -97778,7 +97866,7 @@ function credentialProcessJson(fields) {
|
|
|
97778
97866
|
}
|
|
97779
97867
|
|
|
97780
97868
|
// src/services/vault-batch.service.ts
|
|
97781
|
-
import { rm as
|
|
97869
|
+
import { rm as rm19 } from "node:fs/promises";
|
|
97782
97870
|
async function batchOf({ response }) {
|
|
97783
97871
|
const text3 = await response.text();
|
|
97784
97872
|
if (!response.ok) {
|
|
@@ -97960,7 +98048,7 @@ async function valuesOf({
|
|
|
97960
98048
|
}) {
|
|
97961
98049
|
const refused = refusalOf({ context, settled: settled2 });
|
|
97962
98050
|
if (refused !== 0) {
|
|
97963
|
-
await
|
|
98051
|
+
await rm19(keyPath, { force: true });
|
|
97964
98052
|
return { exitCode: refused };
|
|
97965
98053
|
}
|
|
97966
98054
|
const opened = /* @__PURE__ */ new Map();
|
|
@@ -97972,7 +98060,7 @@ async function valuesOf({
|
|
|
97972
98060
|
if (release2.message) context.err(`${release2.message}
|
|
97973
98061
|
`);
|
|
97974
98062
|
}
|
|
97975
|
-
if (!keep2) await
|
|
98063
|
+
if (!keep2) await rm19(keyPath, { force: true });
|
|
97976
98064
|
const released = /* @__PURE__ */ new Map();
|
|
97977
98065
|
for (const entry of entries) {
|
|
97978
98066
|
const fields = opened.get(keyOf(entry));
|
|
@@ -98025,7 +98113,7 @@ function refusedReason({
|
|
|
98025
98113
|
return VAULT_EXIT_BAD_REASON;
|
|
98026
98114
|
}
|
|
98027
98115
|
async function isFile(path) {
|
|
98028
|
-
return
|
|
98116
|
+
return stat12(path).then(
|
|
98029
98117
|
(found) => found.isFile(),
|
|
98030
98118
|
() => false
|
|
98031
98119
|
);
|
|
@@ -98038,9 +98126,9 @@ async function manifestPathOf({
|
|
|
98038
98126
|
if (named) return resolve23(context.cwd, named);
|
|
98039
98127
|
const environment = flagText({ args, name: "env" });
|
|
98040
98128
|
const file4 = environment ? `.env.${environment}.vault` : ".env.vault";
|
|
98041
|
-
for (let dir = resolve23(context.cwd); ; dir =
|
|
98042
|
-
if (await isFile(
|
|
98043
|
-
if (
|
|
98129
|
+
for (let dir = resolve23(context.cwd); ; dir = dirname23(dir)) {
|
|
98130
|
+
if (await isFile(join33(dir, file4))) return join33(dir, file4);
|
|
98131
|
+
if (dirname23(dir) === dir) break;
|
|
98044
98132
|
}
|
|
98045
98133
|
throw new CliUsageError(`laze vault: no ${file4} here or in a parent folder
|
|
98046
98134
|
${ENV_USAGE}`);
|
|
@@ -98050,7 +98138,7 @@ async function manifestOf({
|
|
|
98050
98138
|
args
|
|
98051
98139
|
}) {
|
|
98052
98140
|
const file4 = await manifestPathOf({ context, args });
|
|
98053
|
-
const text3 = await
|
|
98141
|
+
const text3 = await readFile34(file4, "utf8").catch(() => {
|
|
98054
98142
|
throw new CliUsageError(`laze vault: cannot read ${file4}`);
|
|
98055
98143
|
});
|
|
98056
98144
|
return { file: file4, lines: parseManifest({ text: text3, file: file4 }) };
|
|
@@ -98365,7 +98453,7 @@ async function vaultScrub({ context, args }) {
|
|
|
98365
98453
|
}
|
|
98366
98454
|
|
|
98367
98455
|
// src/services/whatsapp-business-commands.service.ts
|
|
98368
|
-
import { readFile as
|
|
98456
|
+
import { readFile as readFile35 } from "node:fs/promises";
|
|
98369
98457
|
import { resolve as resolve24 } from "node:path";
|
|
98370
98458
|
|
|
98371
98459
|
// ../../modules/whatsapp-business/contract/src/whatsapp-business.prices.ts
|
|
@@ -98785,7 +98873,7 @@ async function secretsOf3({ context, args }) {
|
|
|
98785
98873
|
const fromConnection = flagText({ args, name: "from-vault" });
|
|
98786
98874
|
if (fromConnection) return { fromConnection };
|
|
98787
98875
|
const file4 = flagText({ args, name: "from-file" });
|
|
98788
|
-
const text3 = file4 ? await
|
|
98876
|
+
const text3 = file4 ? await readFile35(resolve24(context.cwd, file4), "utf8") : await context.readStdin();
|
|
98789
98877
|
const lines2 = text3.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
98790
98878
|
if (lines2.length !== 2) {
|
|
98791
98879
|
throw new CliUsageError(
|
|
@@ -98986,8 +99074,8 @@ async function whatsappBusiness({
|
|
|
98986
99074
|
}
|
|
98987
99075
|
|
|
98988
99076
|
// src/services/whatsapp-commands.service.ts
|
|
98989
|
-
import { writeFile as
|
|
98990
|
-
import { basename as
|
|
99077
|
+
import { writeFile as writeFile10 } from "node:fs/promises";
|
|
99078
|
+
import { basename as basename11, resolve as resolve25 } from "node:path";
|
|
98991
99079
|
|
|
98992
99080
|
// src/services/whatsapp-pairing-commands.service.ts
|
|
98993
99081
|
var WHATSAPP_PAIRING_USAGE = " laze whatsapp unpair <machine> unlink WhatsApp from the machine (owner)";
|
|
@@ -99127,10 +99215,10 @@ async function file3({ context, args }) {
|
|
|
99127
99215
|
},
|
|
99128
99216
|
args
|
|
99129
99217
|
});
|
|
99130
|
-
const out = resolve25(context.cwd, flagText({ args, name: "out" }) ??
|
|
99218
|
+
const out = resolve25(context.cwd, flagText({ args, name: "out" }) ?? basename11(answer6.fileName));
|
|
99131
99219
|
const response = await context.fetcher(answer6.url);
|
|
99132
99220
|
if (!response.ok) throw new Error(`The file link answered ${response.status}`);
|
|
99133
|
-
await
|
|
99221
|
+
await writeFile10(out, new Uint8Array(await response.arrayBuffer()));
|
|
99134
99222
|
if (args.flags.json) return context.out(`${JSON.stringify({ ...answer6, path: out }, null, 2)}
|
|
99135
99223
|
`);
|
|
99136
99224
|
context.out(`${out}
|
|
@@ -99942,11 +100030,11 @@ import {
|
|
|
99942
100030
|
createHash as createHash8,
|
|
99943
100031
|
createPrivateKey,
|
|
99944
100032
|
generateKeyPairSync,
|
|
99945
|
-
randomBytes as
|
|
100033
|
+
randomBytes as randomBytes5,
|
|
99946
100034
|
sign
|
|
99947
100035
|
} from "node:crypto";
|
|
99948
|
-
import { chmod
|
|
99949
|
-
import { dirname as
|
|
100036
|
+
import { chmod, link, mkdir as mkdir12, readFile as readFile36, rm as rm20, writeFile as writeFile11 } from "node:fs/promises";
|
|
100037
|
+
import { dirname as dirname24, join as join34 } from "node:path";
|
|
99950
100038
|
var KEYCHAIN_SERVICE = "laze-cli-machine-key";
|
|
99951
100039
|
var runProgram = ({ program, args, stdin: stdin2, timeoutMs }) => new Promise((resolve26, reject) => {
|
|
99952
100040
|
const child = execFile2(
|
|
@@ -99986,11 +100074,11 @@ var MachineKeyStore = class _MachineKeyStore {
|
|
|
99986
100074
|
});
|
|
99987
100075
|
}
|
|
99988
100076
|
get metaPath() {
|
|
99989
|
-
return
|
|
100077
|
+
return join34(dirname24(this.options.configPath), "machine-key.json");
|
|
99990
100078
|
}
|
|
99991
100079
|
/** Named by the key, so two CLIs making a key at once never overwrite each other's. */
|
|
99992
100080
|
pemPathOf(jwk) {
|
|
99993
|
-
return
|
|
100081
|
+
return join34(dirname24(this.options.configPath), `machine-key-${shortOf(jwk)}.pem`);
|
|
99994
100082
|
}
|
|
99995
100083
|
/** The Keychain item's account: one per config file and key. */
|
|
99996
100084
|
accountOf(jwk) {
|
|
@@ -100018,7 +100106,7 @@ var MachineKeyStore = class _MachineKeyStore {
|
|
|
100018
100106
|
async read() {
|
|
100019
100107
|
let meta3;
|
|
100020
100108
|
try {
|
|
100021
|
-
meta3 = machineKeyRegistrationSchema.parse(JSON.parse(await
|
|
100109
|
+
meta3 = machineKeyRegistrationSchema.parse(JSON.parse(await readFile36(this.metaPath, "utf8")));
|
|
100022
100110
|
} catch {
|
|
100023
100111
|
return null;
|
|
100024
100112
|
}
|
|
@@ -100033,7 +100121,7 @@ var MachineKeyStore = class _MachineKeyStore {
|
|
|
100033
100121
|
"-w"
|
|
100034
100122
|
],
|
|
100035
100123
|
timeoutMs: 1e4
|
|
100036
|
-
}) : await
|
|
100124
|
+
}) : await readFile36(this.pemPathOf(meta3.jwk), "utf8");
|
|
100037
100125
|
return keyOf2({ meta: meta3, privateKey: createPrivateKey(pemOf(pem)) });
|
|
100038
100126
|
}
|
|
100039
100127
|
async make() {
|
|
@@ -100057,7 +100145,7 @@ var MachineKeyStore = class _MachineKeyStore {
|
|
|
100057
100145
|
return kept;
|
|
100058
100146
|
}
|
|
100059
100147
|
async drop({ tier, jwk }) {
|
|
100060
|
-
if (tier === "file") return
|
|
100148
|
+
if (tier === "file") return rm20(this.pemPathOf(jwk), { force: true });
|
|
100061
100149
|
await this.options.run({
|
|
100062
100150
|
program: "security",
|
|
100063
100151
|
args: ["delete-generic-password", "-s", KEYCHAIN_SERVICE, "-a", this.accountOf(jwk)],
|
|
@@ -100104,7 +100192,7 @@ function keyOf2({ meta: meta3, privateKey }) {
|
|
|
100104
100192
|
}
|
|
100105
100193
|
var shortOf = (jwk) => thumbprintOf({ jwk }).slice(0, 12);
|
|
100106
100194
|
async function writeOnce({ path, text: text3 }) {
|
|
100107
|
-
const temporary = `${path}.${process.pid}.${
|
|
100195
|
+
const temporary = `${path}.${process.pid}.${randomBytes5(6).toString("hex")}.tmp`;
|
|
100108
100196
|
await writePrivate({ path: temporary, text: text3 });
|
|
100109
100197
|
try {
|
|
100110
100198
|
await link(temporary, path);
|
|
@@ -100113,13 +100201,13 @@ async function writeOnce({ path, text: text3 }) {
|
|
|
100113
100201
|
if (error63.code === "EEXIST") return false;
|
|
100114
100202
|
throw error63;
|
|
100115
100203
|
} finally {
|
|
100116
|
-
await
|
|
100204
|
+
await rm20(temporary, { force: true });
|
|
100117
100205
|
}
|
|
100118
100206
|
}
|
|
100119
100207
|
async function writePrivate({ path, text: text3 }) {
|
|
100120
|
-
await
|
|
100121
|
-
await
|
|
100122
|
-
await
|
|
100208
|
+
await mkdir12(dirname24(path), { recursive: true, mode: 448 });
|
|
100209
|
+
await writeFile11(path, text3, { mode: 384 });
|
|
100210
|
+
await chmod(path, 384);
|
|
100123
100211
|
}
|
|
100124
100212
|
|
|
100125
100213
|
// src/services/machine-proof-fetch.service.ts
|
|
@@ -100141,7 +100229,7 @@ function machineProofFetch({
|
|
|
100141
100229
|
fetcher,
|
|
100142
100230
|
store,
|
|
100143
100231
|
keys: keys2,
|
|
100144
|
-
nowMs,
|
|
100232
|
+
nowMs: nowMs2,
|
|
100145
100233
|
warn
|
|
100146
100234
|
}) {
|
|
100147
100235
|
const warned = /* @__PURE__ */ new Set();
|
|
@@ -100157,7 +100245,7 @@ function machineProofFetch({
|
|
|
100157
100245
|
method: init?.method ?? "GET",
|
|
100158
100246
|
url: input2,
|
|
100159
100247
|
credential: token2,
|
|
100160
|
-
nowMs:
|
|
100248
|
+
nowMs: nowMs2(),
|
|
100161
100249
|
tailscaleNodeId: key.tailscale?.nodeId ?? null
|
|
100162
100250
|
});
|
|
100163
100251
|
}
|
|
@@ -100173,10 +100261,10 @@ function machineProofFetch({
|
|
|
100173
100261
|
}
|
|
100174
100262
|
|
|
100175
100263
|
// src/services/processes.service.ts
|
|
100176
|
-
import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
|
|
100177
|
-
import { mkdirSync, openSync } from "node:fs";
|
|
100178
|
-
import { readFile as
|
|
100179
|
-
import { dirname as
|
|
100264
|
+
import { execFile as execFile3, spawn as spawn4, spawnSync } from "node:child_process";
|
|
100265
|
+
import { closeSync, mkdirSync, openSync } from "node:fs";
|
|
100266
|
+
import { readFile as readFile37, readlink } from "node:fs/promises";
|
|
100267
|
+
import { dirname as dirname25 } from "node:path";
|
|
100180
100268
|
import { promisify as promisify2 } from "node:util";
|
|
100181
100269
|
var run3 = promisify2(execFile3);
|
|
100182
100270
|
function alive(pid) {
|
|
@@ -100189,15 +100277,15 @@ function alive(pid) {
|
|
|
100189
100277
|
}
|
|
100190
100278
|
}
|
|
100191
100279
|
async function argsOf2(pid) {
|
|
100192
|
-
const raw = await
|
|
100280
|
+
const raw = await readFile37(`/proc/${pid}/cmdline`, "utf8").catch(() => void 0);
|
|
100193
100281
|
if (raw) return raw.split("\0").filter(Boolean);
|
|
100194
100282
|
const listed = await run3("ps", ["-o", "args=", "-p", String(pid)]).catch(() => void 0);
|
|
100195
100283
|
const line = listed?.stdout.trim();
|
|
100196
100284
|
return line ? line.split(/\s+/) : void 0;
|
|
100197
100285
|
}
|
|
100198
100286
|
async function parentOf(pid) {
|
|
100199
|
-
const
|
|
100200
|
-
const fromStat =
|
|
100287
|
+
const stat13 = await readFile37(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
|
|
100288
|
+
const fromStat = stat13 ? Number(stat13.slice(stat13.lastIndexOf(")") + 2).split(" ")[1]) : NaN;
|
|
100201
100289
|
if (fromStat > 0) return fromStat;
|
|
100202
100290
|
const listed = await run3("ps", ["-o", "ppid=", "-p", String(pid)]).catch(() => void 0);
|
|
100203
100291
|
const parent = Number(listed?.stdout.trim());
|
|
@@ -100212,9 +100300,35 @@ async function cwdOf(pid) {
|
|
|
100212
100300
|
const line = listed?.stdout.split("\n").find((each) => each.startsWith("n"));
|
|
100213
100301
|
return line ? line.slice(1) : void 0;
|
|
100214
100302
|
}
|
|
100215
|
-
|
|
100216
|
-
|
|
100303
|
+
var ORPHAN_SCRIPT = [
|
|
100304
|
+
"if command -v setsid >/dev/null 2>&1; then",
|
|
100305
|
+
' setsid "$@" </dev/null >&3 2>&3 &',
|
|
100306
|
+
"else",
|
|
100307
|
+
' "$@" </dev/null >&3 2>&3 &',
|
|
100308
|
+
"fi",
|
|
100309
|
+
'echo "$!"'
|
|
100310
|
+
].join("\n");
|
|
100311
|
+
function spawnOrphan({ argv, log }) {
|
|
100312
|
+
const shell = spawnSync("sh", ["-c", ORPHAN_SCRIPT, "sh", ...argv], {
|
|
100313
|
+
stdio: ["ignore", "pipe", "ignore", log],
|
|
100314
|
+
encoding: "utf8"
|
|
100315
|
+
});
|
|
100316
|
+
return Number(shell.stdout.trim()) || 0;
|
|
100317
|
+
}
|
|
100318
|
+
function spawnDetached({
|
|
100319
|
+
argv,
|
|
100320
|
+
logPath,
|
|
100321
|
+
orphan = false
|
|
100322
|
+
}) {
|
|
100323
|
+
mkdirSync(dirname25(logPath), { recursive: true, mode: 448 });
|
|
100217
100324
|
const log = openSync(logPath, "a", 384);
|
|
100325
|
+
if (orphan) {
|
|
100326
|
+
try {
|
|
100327
|
+
return spawnOrphan({ argv, log });
|
|
100328
|
+
} finally {
|
|
100329
|
+
closeSync(log);
|
|
100330
|
+
}
|
|
100331
|
+
}
|
|
100218
100332
|
const [program = "", ...rest] = argv;
|
|
100219
100333
|
const child = spawn4(program, rest, { detached: true, stdio: ["ignore", log, log] });
|
|
100220
100334
|
child.unref();
|
|
@@ -100335,7 +100449,7 @@ if (true) {
|
|
|
100335
100449
|
configPath: environment.configPath,
|
|
100336
100450
|
tier: environment.machineKeyTier
|
|
100337
100451
|
});
|
|
100338
|
-
const
|
|
100452
|
+
const nowMs2 = () => nowInstant().epochMilliseconds;
|
|
100339
100453
|
process.exitCode = await runCli({
|
|
100340
100454
|
argv: process.argv.slice(2),
|
|
100341
100455
|
context: {
|
|
@@ -100348,7 +100462,7 @@ if (true) {
|
|
|
100348
100462
|
fetcher: proxiedFetch(environment.inherited),
|
|
100349
100463
|
store,
|
|
100350
100464
|
keys: machineKeys,
|
|
100351
|
-
nowMs,
|
|
100465
|
+
nowMs: nowMs2,
|
|
100352
100466
|
warn: (text3) => void process.stderr.write(text3)
|
|
100353
100467
|
}),
|
|
100354
100468
|
out: (text3) => void process.stdout.write(text3),
|
|
@@ -100357,7 +100471,7 @@ if (true) {
|
|
|
100357
100471
|
stdoutIsTerminal: process.stdout.isTTY === true,
|
|
100358
100472
|
...ask ? { ask } : {},
|
|
100359
100473
|
sleep,
|
|
100360
|
-
nowMs,
|
|
100474
|
+
nowMs: nowMs2,
|
|
100361
100475
|
processes: nodeProcesses(),
|
|
100362
100476
|
runCommand: (input2) => runCommand({ ...input2, inherited: environment.inherited })
|
|
100363
100477
|
}
|