@lazehq/cli 0.1.87 → 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 +110 -58
- package/package.json +1 -1
package/dist/laze.mjs
CHANGED
|
@@ -36892,14 +36892,12 @@ async function repairDamagedStateFiles() {
|
|
|
36892
36892
|
}
|
|
36893
36893
|
var LOCK_STALE_MS = 5e3;
|
|
36894
36894
|
var nowMs = () => nowInstant().epochMilliseconds;
|
|
36895
|
-
var LOCK_WAIT_MS = 3e3;
|
|
36896
36895
|
async function withStateLock({
|
|
36897
36896
|
path,
|
|
36898
36897
|
work
|
|
36899
36898
|
}) {
|
|
36900
36899
|
const lock = `${path}.lock`;
|
|
36901
36900
|
await mkdir(dirname(lock), { recursive: true, mode: 448 });
|
|
36902
|
-
const deadline = nowMs() + LOCK_WAIT_MS;
|
|
36903
36901
|
for (; ; ) {
|
|
36904
36902
|
const handle = await open(lock, "wx", 384).catch((error63) => {
|
|
36905
36903
|
if (error63.code === "EEXIST") return void 0;
|
|
@@ -36913,7 +36911,7 @@ async function withStateLock({
|
|
|
36913
36911
|
(info) => nowMs() - info.mtimeMs,
|
|
36914
36912
|
() => 0
|
|
36915
36913
|
);
|
|
36916
|
-
if (since > LOCK_STALE_MS
|
|
36914
|
+
if (since > LOCK_STALE_MS) await rm(lock, { force: true });
|
|
36917
36915
|
else await new Promise((resolve26) => setTimeout(resolve26, 15 + Math.random() * 20));
|
|
36918
36916
|
}
|
|
36919
36917
|
try {
|
|
@@ -36945,8 +36943,24 @@ var ConfigStore = class _ConfigStore {
|
|
|
36945
36943
|
}
|
|
36946
36944
|
return { ...EMPTY, ...read4.value };
|
|
36947
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
|
+
});
|
|
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. */
|
|
36948
36962
|
async write(config2) {
|
|
36949
|
-
await
|
|
36963
|
+
await this.update(() => ({ config: config2, result: void 0 }));
|
|
36950
36964
|
}
|
|
36951
36965
|
async saveProfile({
|
|
36952
36966
|
name: name3,
|
|
@@ -36954,32 +36968,37 @@ var ConfigStore = class _ConfigStore {
|
|
|
36954
36968
|
bindDirectory,
|
|
36955
36969
|
onlyThere = false
|
|
36956
36970
|
}) {
|
|
36957
|
-
|
|
36958
|
-
|
|
36959
|
-
|
|
36960
|
-
|
|
36961
|
-
|
|
36962
|
-
|
|
36963
|
-
|
|
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
|
+
}));
|
|
36964
36980
|
}
|
|
36965
36981
|
/** Keeps a profile beside the others: never the current one, bound to no folder. */
|
|
36966
36982
|
async keepProfile({ name: name3, profile }) {
|
|
36967
|
-
|
|
36968
|
-
|
|
36983
|
+
await this.update((config2) => ({
|
|
36984
|
+
result: void 0,
|
|
36985
|
+
config: { ...config2, profiles: { ...config2.profiles, [name3]: profile } }
|
|
36986
|
+
}));
|
|
36969
36987
|
}
|
|
36970
36988
|
/** Binds a harness session to a profile, so its hooks use it whatever the folder says. */
|
|
36971
36989
|
async bindSession({ session, profile }) {
|
|
36972
|
-
|
|
36973
|
-
|
|
36990
|
+
await this.update((config2) => ({
|
|
36991
|
+
result: void 0,
|
|
36992
|
+
config: { ...config2, sessions: { ...config2.sessions, [session]: profile } }
|
|
36993
|
+
}));
|
|
36974
36994
|
}
|
|
36975
36995
|
/** Keeps a profile's agent name in step with Laze; a missing or unchanged profile stays. */
|
|
36976
36996
|
async renameProfileAgent({ name: name3, agentName }) {
|
|
36977
|
-
|
|
36978
|
-
|
|
36979
|
-
|
|
36980
|
-
|
|
36981
|
-
...config2,
|
|
36982
|
-
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 } };
|
|
36983
37002
|
});
|
|
36984
37003
|
}
|
|
36985
37004
|
/** Sets or clears how the connect service delivers to a profile; false when there is none. */
|
|
@@ -36987,43 +37006,48 @@ var ConfigStore = class _ConfigStore {
|
|
|
36987
37006
|
name: name3,
|
|
36988
37007
|
delivery
|
|
36989
37008
|
}) {
|
|
36990
|
-
|
|
36991
|
-
|
|
36992
|
-
|
|
36993
|
-
|
|
36994
|
-
|
|
36995
|
-
|
|
36996
|
-
|
|
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
|
+
});
|
|
36997
37019
|
}
|
|
36998
37020
|
/** Marks a profile migrated; false when there is none. */
|
|
36999
37021
|
async markMigrated({ name: name3, migrated }) {
|
|
37000
|
-
|
|
37001
|
-
|
|
37002
|
-
|
|
37003
|
-
|
|
37004
|
-
...config2,
|
|
37005
|
-
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 } };
|
|
37006
37027
|
});
|
|
37007
|
-
return true;
|
|
37008
37028
|
}
|
|
37009
37029
|
async removeProfile({ name: name3 }) {
|
|
37010
|
-
|
|
37011
|
-
|
|
37012
|
-
|
|
37013
|
-
|
|
37014
|
-
);
|
|
37015
|
-
const bindings = Object.fromEntries(
|
|
37016
|
-
Object.entries(config2.bindings).filter(([, bound]) => bound !== name3)
|
|
37017
|
-
);
|
|
37018
|
-
const sessions = Object.fromEntries(
|
|
37019
|
-
Object.entries(config2.sessions ?? {}).filter(([, bound]) => bound !== name3)
|
|
37020
|
-
);
|
|
37021
|
-
const usable = Object.keys(profiles2).find((key) => profiles2[key]?.kind !== "request");
|
|
37022
|
-
const current3 = config2.current === name3 ? usable : config2.current;
|
|
37023
|
-
await this.write({ current: current3, profiles: profiles2, bindings, sessions });
|
|
37024
|
-
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
|
+
});
|
|
37025
37034
|
}
|
|
37026
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
|
+
}
|
|
37027
37051
|
function chooseProfile({
|
|
37028
37052
|
config: config2,
|
|
37029
37053
|
flag: flag2,
|
|
@@ -37130,7 +37154,7 @@ function flagText({
|
|
|
37130
37154
|
}
|
|
37131
37155
|
|
|
37132
37156
|
// src/rules/cli-version.rules.ts
|
|
37133
|
-
var STAMPED = "0.1.
|
|
37157
|
+
var STAMPED = "0.1.88";
|
|
37134
37158
|
function cliVersionOf({ stamped = STAMPED } = {}) {
|
|
37135
37159
|
return stamped.startsWith("__") ? "dev" : stamped;
|
|
37136
37160
|
}
|
|
@@ -70243,10 +70267,11 @@ async function reportMachine({
|
|
|
70243
70267
|
if (!host2) return;
|
|
70244
70268
|
const stamp = createHash("sha256").update(`${token2}:${host2}`).digest("hex");
|
|
70245
70269
|
const path = statePathOf({ context, kind: "machine", profile });
|
|
70246
|
-
|
|
70270
|
+
const noted = await readFile3(path, "utf8").catch(() => "");
|
|
70271
|
+
if (noted === JSON.stringify(stamp) || noted === stamp) return;
|
|
70247
70272
|
try {
|
|
70248
70273
|
await client.post("/api/agents/me/machine", { host: host2 });
|
|
70249
|
-
await writeStateText({ path, text: stamp });
|
|
70274
|
+
await writeStateText({ path, text: JSON.stringify(stamp) });
|
|
70250
70275
|
} catch {
|
|
70251
70276
|
return;
|
|
70252
70277
|
}
|
|
@@ -74857,7 +74882,8 @@ async function installLaunchd({ context }) {
|
|
|
74857
74882
|
}
|
|
74858
74883
|
async function installDetached({ context }) {
|
|
74859
74884
|
const log = logPathOf({ context });
|
|
74860
|
-
const
|
|
74885
|
+
const argv = runArgvOf({ context });
|
|
74886
|
+
const pid = context.processes.spawnDetached({ argv, logPath: log, orphan: true });
|
|
74861
74887
|
return { manager: "detached", name: serviceNameOf({ context }), pid, log };
|
|
74862
74888
|
}
|
|
74863
74889
|
async function managerOf({ context }) {
|
|
@@ -89855,7 +89881,7 @@ async function switchTo({ context, args }) {
|
|
|
89855
89881
|
`Not signed in to ${target.name} on this machine: run laze login --profile <name> and pick ${target.name} when you approve it.`
|
|
89856
89882
|
);
|
|
89857
89883
|
}
|
|
89858
|
-
await context.store.
|
|
89884
|
+
await context.store.setCurrent({ name: chosen });
|
|
89859
89885
|
print7({
|
|
89860
89886
|
context,
|
|
89861
89887
|
args,
|
|
@@ -100235,8 +100261,8 @@ function machineProofFetch({
|
|
|
100235
100261
|
}
|
|
100236
100262
|
|
|
100237
100263
|
// src/services/processes.service.ts
|
|
100238
|
-
import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
|
|
100239
|
-
import { mkdirSync, openSync } from "node:fs";
|
|
100264
|
+
import { execFile as execFile3, spawn as spawn4, spawnSync } from "node:child_process";
|
|
100265
|
+
import { closeSync, mkdirSync, openSync } from "node:fs";
|
|
100240
100266
|
import { readFile as readFile37, readlink } from "node:fs/promises";
|
|
100241
100267
|
import { dirname as dirname25 } from "node:path";
|
|
100242
100268
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -100274,9 +100300,35 @@ async function cwdOf(pid) {
|
|
|
100274
100300
|
const line = listed?.stdout.split("\n").find((each) => each.startsWith("n"));
|
|
100275
100301
|
return line ? line.slice(1) : void 0;
|
|
100276
100302
|
}
|
|
100277
|
-
|
|
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
|
+
}) {
|
|
100278
100323
|
mkdirSync(dirname25(logPath), { recursive: true, mode: 448 });
|
|
100279
100324
|
const log = openSync(logPath, "a", 384);
|
|
100325
|
+
if (orphan) {
|
|
100326
|
+
try {
|
|
100327
|
+
return spawnOrphan({ argv, log });
|
|
100328
|
+
} finally {
|
|
100329
|
+
closeSync(log);
|
|
100330
|
+
}
|
|
100331
|
+
}
|
|
100280
100332
|
const [program = "", ...rest] = argv;
|
|
100281
100333
|
const child = spawn4(program, rest, { detached: true, stdio: ["ignore", log, log] });
|
|
100282
100334
|
child.unref();
|
package/package.json
CHANGED