@lazehq/cli 0.1.18 → 0.1.20
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 +91 -9
- package/package.json +1 -1
package/dist/laze.mjs
CHANGED
|
@@ -31497,7 +31497,8 @@ function runRedacted({
|
|
|
31497
31497
|
baseEnv,
|
|
31498
31498
|
stdout: stdout2,
|
|
31499
31499
|
stderr: stderr2,
|
|
31500
|
-
cwd
|
|
31500
|
+
cwd,
|
|
31501
|
+
signal
|
|
31501
31502
|
}) {
|
|
31502
31503
|
const values = Object.values(env);
|
|
31503
31504
|
return new Promise((resolve17, reject) => {
|
|
@@ -31505,8 +31506,12 @@ function runRedacted({
|
|
|
31505
31506
|
const child = spawn(file3, args, {
|
|
31506
31507
|
env: { ...baseEnv, ...env },
|
|
31507
31508
|
stdio: ["inherit", "pipe", "pipe"],
|
|
31508
|
-
...cwd ? { cwd } : {}
|
|
31509
|
+
...cwd ? { cwd } : {},
|
|
31510
|
+
...signal ? { detached: true } : {}
|
|
31509
31511
|
});
|
|
31512
|
+
const killGroup = () => killProcessGroup({ child });
|
|
31513
|
+
if (signal?.aborted) killGroup();
|
|
31514
|
+
signal?.addEventListener("abort", killGroup, { once: true });
|
|
31510
31515
|
const pipe2 = (stream, sink) => {
|
|
31511
31516
|
const decoder2 = new StringDecoder("utf8");
|
|
31512
31517
|
const redactor = createRedactor({ values });
|
|
@@ -31520,11 +31525,20 @@ function runRedacted({
|
|
|
31520
31525
|
};
|
|
31521
31526
|
const drained = Promise.all([pipe2(child.stdout, stdout2), pipe2(child.stderr, stderr2)]);
|
|
31522
31527
|
child.on("error", reject);
|
|
31523
|
-
child.on("close", (code,
|
|
31524
|
-
|
|
31528
|
+
child.on("close", (code, ended) => {
|
|
31529
|
+
signal?.removeEventListener("abort", killGroup);
|
|
31530
|
+
void drained.then(() => resolve17(code ?? (ended ? 128 + signalNumber(ended) : 1)));
|
|
31525
31531
|
});
|
|
31526
31532
|
});
|
|
31527
31533
|
}
|
|
31534
|
+
function killProcessGroup({ child }) {
|
|
31535
|
+
if (child.pid === void 0) return;
|
|
31536
|
+
try {
|
|
31537
|
+
process.kill(-child.pid, "SIGKILL");
|
|
31538
|
+
} catch {
|
|
31539
|
+
child.kill("SIGKILL");
|
|
31540
|
+
}
|
|
31541
|
+
}
|
|
31528
31542
|
function signalNumber(signal) {
|
|
31529
31543
|
const numbers = { SIGINT: 2, SIGKILL: 9, SIGTERM: 15 };
|
|
31530
31544
|
return numbers[signal] ?? 1;
|
|
@@ -35606,7 +35620,7 @@ function flagText({
|
|
|
35606
35620
|
}
|
|
35607
35621
|
|
|
35608
35622
|
// src/rules/cli-version.rules.ts
|
|
35609
|
-
var STAMPED = "0.1.
|
|
35623
|
+
var STAMPED = "0.1.20";
|
|
35610
35624
|
function cliVersionOf({ stamped = STAMPED } = {}) {
|
|
35611
35625
|
return stamped.startsWith("__") ? "dev" : stamped;
|
|
35612
35626
|
}
|
|
@@ -67466,8 +67480,23 @@ function channelLabelIn(channel) {
|
|
|
67466
67480
|
// src/services/claude-wait.service.ts
|
|
67467
67481
|
import { readFile as readFile6, rm as rm2, writeFile as writeFile5, mkdir as mkdir5 } from "node:fs/promises";
|
|
67468
67482
|
import { dirname as dirname5 } from "node:path";
|
|
67483
|
+
|
|
67484
|
+
// src/rules/rush-host.rules.ts
|
|
67485
|
+
function rushSessionOf({ parentArgs }) {
|
|
67486
|
+
if (!parentArgs) return void 0;
|
|
67487
|
+
const [program = "", verb, action, id] = parentArgs;
|
|
67488
|
+
const isRush = program === "rush" || program.endsWith("/rush");
|
|
67489
|
+
if (!isRush || verb !== "host" || action !== "run" || !id) return void 0;
|
|
67490
|
+
return { id, program };
|
|
67491
|
+
}
|
|
67492
|
+
function rushSendCommand({ program, id }) {
|
|
67493
|
+
return ["sh", "-c", 'printf "%s\\n" "$LAZE_WAKE_TEXT" | "$0" session send "$1"', program, id];
|
|
67494
|
+
}
|
|
67495
|
+
|
|
67496
|
+
// src/services/claude-wait.service.ts
|
|
67469
67497
|
var ROUND_SECONDS = 50;
|
|
67470
67498
|
var WATCH_MS = 2e3;
|
|
67499
|
+
var RUSH_RETRY_MS = 3e4;
|
|
67471
67500
|
var CHANNEL_CHECK_MS = 5e3;
|
|
67472
67501
|
async function holderOf({ path }) {
|
|
67473
67502
|
return readFile6(path, "utf8").then(
|
|
@@ -67603,10 +67632,24 @@ async function waitForMessages({ context, args }) {
|
|
|
67603
67632
|
if (!await takeLock({ context, path: lock, sessionId: input2.session_id, claudePid })) return 0;
|
|
67604
67633
|
const seen = () => input2.transcript_path ? readFile6(input2.transcript_path, "utf8") : Promise.resolve("");
|
|
67605
67634
|
const deadline = context.nowMs() + (WAIT_HOOK_TIMEOUT_SECONDS - 60) * 1e3;
|
|
67635
|
+
const rush = rushSessionOf({
|
|
67636
|
+
parentArgs: await context.processes.argsOf(await context.processes.parentOf(claudePid) ?? 0)
|
|
67637
|
+
});
|
|
67606
67638
|
try {
|
|
67607
67639
|
while (context.nowMs() < deadline) {
|
|
67608
67640
|
const code = await settleRound({ context, client, name: name2, lock, claudePid, session, seen });
|
|
67609
|
-
if (code
|
|
67641
|
+
if (code === "again") continue;
|
|
67642
|
+
if (code !== 0 || !rush || context.processes.alive(claudePid)) return code;
|
|
67643
|
+
return await wakeThroughRush({
|
|
67644
|
+
context,
|
|
67645
|
+
client,
|
|
67646
|
+
name: name2,
|
|
67647
|
+
lock,
|
|
67648
|
+
claudePid,
|
|
67649
|
+
session,
|
|
67650
|
+
rush,
|
|
67651
|
+
deadline
|
|
67652
|
+
});
|
|
67610
67653
|
}
|
|
67611
67654
|
return 0;
|
|
67612
67655
|
} finally {
|
|
@@ -67614,6 +67657,40 @@ async function waitForMessages({ context, args }) {
|
|
|
67614
67657
|
await rm2(lock, { force: true });
|
|
67615
67658
|
}
|
|
67616
67659
|
}
|
|
67660
|
+
async function rushRound({
|
|
67661
|
+
context,
|
|
67662
|
+
client,
|
|
67663
|
+
name: name2,
|
|
67664
|
+
lock,
|
|
67665
|
+
claudePid,
|
|
67666
|
+
session,
|
|
67667
|
+
rush
|
|
67668
|
+
}) {
|
|
67669
|
+
if ((await holderOf({ path: lock }))?.pid !== context.processes.pid) return true;
|
|
67670
|
+
const key = session ? sessionKeyOf({ session }) : void 0;
|
|
67671
|
+
if (key && await liveElsewhere({ context, key, claudePid })) return true;
|
|
67672
|
+
const due = await dueFromSpool({ context, profile: name2, seen: async () => "", pushedToo: true });
|
|
67673
|
+
const messages = due.length > 0 ? due : await takeRound({ context, client, claudePid: 0, session });
|
|
67674
|
+
if (messages.length === 0) return false;
|
|
67675
|
+
await keepTaken({ context, profile: name2, messages });
|
|
67676
|
+
const self2 = await currentNameOf({ context, client, profile: name2 });
|
|
67677
|
+
const command = rushSendCommand(rush);
|
|
67678
|
+
const env = { LAZE_WAKE_TEXT: hookContextOf({ messages, self: self2 }) };
|
|
67679
|
+
const quiet = { write: () => true };
|
|
67680
|
+
const sent = await context.runCommand({ command, env, stdout: quiet, stderr: quiet });
|
|
67681
|
+
if (sent !== 0) return false;
|
|
67682
|
+
await turnStarted({ context, client, agent: name2, messages }).catch(() => void 0);
|
|
67683
|
+
await dropFromSpool({ context, profile: name2, messageIds: messages.map((m) => m.messageId) });
|
|
67684
|
+
return true;
|
|
67685
|
+
}
|
|
67686
|
+
async function wakeThroughRush(round) {
|
|
67687
|
+
while (round.context.nowMs() < round.deadline) {
|
|
67688
|
+
const done = await rushRound(round).catch(() => "failed");
|
|
67689
|
+
if (done === true) return 0;
|
|
67690
|
+
await round.context.sleep(done === "failed" ? RUSH_RETRY_MS : 1e3);
|
|
67691
|
+
}
|
|
67692
|
+
return 0;
|
|
67693
|
+
}
|
|
67617
67694
|
async function waitHook({ context, args }) {
|
|
67618
67695
|
try {
|
|
67619
67696
|
return await waitForMessages({ context, args });
|
|
@@ -69352,11 +69429,14 @@ async function registerWithClaude({ context, folder }) {
|
|
|
69352
69429
|
`claude plugin marketplace update ${LAZE_PLUGIN} ${quiet}`,
|
|
69353
69430
|
`{ claude plugin install ${LAZE_PLUGIN}@${LAZE_PLUGIN} --scope user ${quiet} || claude plugin update ${LAZE_PLUGIN}@${LAZE_PLUGIN} ${quiet}; }`
|
|
69354
69431
|
].join("; ");
|
|
69355
|
-
const
|
|
69432
|
+
const stop3 = new AbortController();
|
|
69433
|
+
const command = ["sh", "-c", script];
|
|
69434
|
+
const run4 = context.runCommand({ command, env: {}, signal: stop3.signal }).catch(() => 1);
|
|
69356
69435
|
const done = new AbortController();
|
|
69357
69436
|
const gaveUp = context.sleep(REGISTER_LIMIT_MS, done.signal).then(() => -1);
|
|
69358
69437
|
const code = await Promise.race([run4, gaveUp]);
|
|
69359
69438
|
done.abort();
|
|
69439
|
+
stop3.abort();
|
|
69360
69440
|
return code === 0;
|
|
69361
69441
|
}
|
|
69362
69442
|
function registeredMarkOf({ context }) {
|
|
@@ -85312,7 +85392,8 @@ async function runCommand({
|
|
|
85312
85392
|
inherited,
|
|
85313
85393
|
env,
|
|
85314
85394
|
stdout: stdout2 = process.stdout,
|
|
85315
|
-
stderr: stderr2 = process.stderr
|
|
85395
|
+
stderr: stderr2 = process.stderr,
|
|
85396
|
+
signal
|
|
85316
85397
|
}) {
|
|
85317
85398
|
const [program = "", ...rest] = command;
|
|
85318
85399
|
try {
|
|
@@ -85321,7 +85402,8 @@ async function runCommand({
|
|
|
85321
85402
|
env,
|
|
85322
85403
|
baseEnv: inherited,
|
|
85323
85404
|
stdout: stdout2,
|
|
85324
|
-
stderr: stderr2
|
|
85405
|
+
stderr: stderr2,
|
|
85406
|
+
...signal ? { signal } : {}
|
|
85325
85407
|
});
|
|
85326
85408
|
} catch (error62) {
|
|
85327
85409
|
stderr2.write(`laze vault: ${error62 instanceof Error ? error62.message : String(error62)}
|
package/package.json
CHANGED