@lazehq/cli 0.1.92 → 0.1.93
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 +189 -47
- package/package.json +1 -1
package/dist/laze.mjs
CHANGED
|
@@ -37171,7 +37171,7 @@ function flagText({
|
|
|
37171
37171
|
}
|
|
37172
37172
|
|
|
37173
37173
|
// src/rules/cli-version.rules.ts
|
|
37174
|
-
var STAMPED = "0.1.
|
|
37174
|
+
var STAMPED = "0.1.93";
|
|
37175
37175
|
function cliVersionOf({ stamped = STAMPED } = {}) {
|
|
37176
37176
|
return stamped.startsWith("__") ? "dev" : stamped;
|
|
37177
37177
|
}
|
|
@@ -70239,13 +70239,12 @@ var LazeClient = class _LazeClient {
|
|
|
70239
70239
|
...signal ? { signal } : {}
|
|
70240
70240
|
});
|
|
70241
70241
|
const text3 = await response.text();
|
|
70242
|
-
const parsed = text3 ? JSON.parse(text3) : void 0;
|
|
70243
70242
|
if (!response.ok) {
|
|
70244
|
-
const error63 =
|
|
70243
|
+
const error63 = apiErrorOf({ status: response.status, text: text3 });
|
|
70245
70244
|
await this.toldMigrated(error63);
|
|
70246
70245
|
throw error63;
|
|
70247
70246
|
}
|
|
70248
|
-
return
|
|
70247
|
+
return text3 ? JSON.parse(text3) : void 0;
|
|
70249
70248
|
}
|
|
70250
70249
|
};
|
|
70251
70250
|
function apiErrorOf({ status: status11, text: text3 }) {
|
|
@@ -73331,6 +73330,40 @@ function channelLabelIn(channel) {
|
|
|
73331
73330
|
// src/services/claude-wait.service.ts
|
|
73332
73331
|
import { readFile as readFile8, rm as rm6 } from "node:fs/promises";
|
|
73333
73332
|
|
|
73333
|
+
// src/rules/listener-retry.rules.ts
|
|
73334
|
+
var FIRST_MS = 1e3;
|
|
73335
|
+
var LISTENER_RETRY_CAP_MS = 5 * 60 * 1e3;
|
|
73336
|
+
var LISTENER_GIVE_UP_MS = 3 * 24 * 60 * 60 * 1e3;
|
|
73337
|
+
function refusedForGood(error63) {
|
|
73338
|
+
return error63 instanceof LazeApiError && (error63.status === 401 || error63.status === 403);
|
|
73339
|
+
}
|
|
73340
|
+
function listenerDelayMs({ failures, random }) {
|
|
73341
|
+
const ceiling = Math.min(LISTENER_RETRY_CAP_MS, FIRST_MS * 2 ** Math.max(0, failures - 1));
|
|
73342
|
+
return Math.round(ceiling * (0.5 + 0.5 * random));
|
|
73343
|
+
}
|
|
73344
|
+
var ListenerBackoff = class {
|
|
73345
|
+
failures = 0;
|
|
73346
|
+
firstAt;
|
|
73347
|
+
/** The next wait after a failure at `nowMs`; "give up" once failures have lasted 3 days. */
|
|
73348
|
+
failed({ nowMs: nowMs2, random = Math.random() }) {
|
|
73349
|
+
this.firstAt ??= nowMs2;
|
|
73350
|
+
this.failures += 1;
|
|
73351
|
+
if (nowMs2 - this.firstAt >= LISTENER_GIVE_UP_MS) return { giveUp: true };
|
|
73352
|
+
return { delayMs: listenerDelayMs({ failures: this.failures, random }) };
|
|
73353
|
+
}
|
|
73354
|
+
/** Failed tries in the current run. */
|
|
73355
|
+
tries() {
|
|
73356
|
+
return this.failures;
|
|
73357
|
+
}
|
|
73358
|
+
/** How many tries failed in the run that just ended, then a fresh run. */
|
|
73359
|
+
answered() {
|
|
73360
|
+
const failures = this.failures;
|
|
73361
|
+
this.failures = 0;
|
|
73362
|
+
this.firstAt = void 0;
|
|
73363
|
+
return failures;
|
|
73364
|
+
}
|
|
73365
|
+
};
|
|
73366
|
+
|
|
73334
73367
|
// src/services/connect-service.service.ts
|
|
73335
73368
|
import { createHash as createHash2 } from "node:crypto";
|
|
73336
73369
|
import { mkdir as mkdir3, rm as rm5, writeFile } from "node:fs/promises";
|
|
@@ -74749,7 +74782,6 @@ async function runStateOf({ context }) {
|
|
|
74749
74782
|
}
|
|
74750
74783
|
var ROUND_SECONDS = 50;
|
|
74751
74784
|
var REFRESH_MS = 3e4;
|
|
74752
|
-
var MAX_RETRY_SECONDS3 = 60;
|
|
74753
74785
|
var CLI_CHANGED_EXIT = 75;
|
|
74754
74786
|
async function cliStampOf({ context }) {
|
|
74755
74787
|
const file4 = context.program.at(-1);
|
|
@@ -74868,7 +74900,7 @@ async function serveRounds({
|
|
|
74868
74900
|
report: report3,
|
|
74869
74901
|
watch
|
|
74870
74902
|
}) {
|
|
74871
|
-
|
|
74903
|
+
const backoff = new ListenerBackoff();
|
|
74872
74904
|
await report3(profile, "listening");
|
|
74873
74905
|
while (!signal.aborted) {
|
|
74874
74906
|
try {
|
|
@@ -74880,31 +74912,46 @@ async function serveRounds({
|
|
|
74880
74912
|
signal,
|
|
74881
74913
|
watch
|
|
74882
74914
|
});
|
|
74883
|
-
if (
|
|
74884
|
-
wait = 1;
|
|
74915
|
+
if (backoff.answered() > 0) await report3(profile, "listening");
|
|
74885
74916
|
if (delivered === 0) await context.sleep(1e3, signal);
|
|
74886
74917
|
} catch (error63) {
|
|
74887
|
-
const
|
|
74888
|
-
if (
|
|
74889
|
-
|
|
74890
|
-
|
|
74891
|
-
|
|
74892
|
-
|
|
74893
|
-
|
|
74894
|
-
|
|
74895
|
-
|
|
74896
|
-
|
|
74918
|
+
const go = await afterRoundError({ context, profile, entry, report: report3, error: error63, backoff });
|
|
74919
|
+
if (go === "stop") return;
|
|
74920
|
+
await context.sleep(go.delayMs, signal);
|
|
74921
|
+
}
|
|
74922
|
+
}
|
|
74923
|
+
}
|
|
74924
|
+
async function afterRoundError({
|
|
74925
|
+
context,
|
|
74926
|
+
profile,
|
|
74927
|
+
entry,
|
|
74928
|
+
report: report3,
|
|
74929
|
+
error: error63,
|
|
74930
|
+
backoff
|
|
74931
|
+
}) {
|
|
74932
|
+
const migrated = migratedNoticeOf(error63);
|
|
74933
|
+
if (migrated) {
|
|
74934
|
+
await report3(profile, "stopped: the agent moved into Laze");
|
|
74935
|
+
context.err(`${profile}: ${migrated.notice}
|
|
74897
74936
|
`);
|
|
74898
|
-
|
|
74899
|
-
|
|
74900
|
-
|
|
74901
|
-
|
|
74902
|
-
|
|
74937
|
+
return "stop";
|
|
74938
|
+
}
|
|
74939
|
+
if (refusedForGood(error63)) {
|
|
74940
|
+
await report3(profile, "stopped: Laze refused the agent's key; link the session again");
|
|
74941
|
+
context.err(`${profile}: Laze refused the key; this agent is no longer served
|
|
74903
74942
|
`);
|
|
74904
|
-
|
|
74905
|
-
wait = Math.min(MAX_RETRY_SECONDS3, wait * 2);
|
|
74906
|
-
}
|
|
74943
|
+
return "stop";
|
|
74907
74944
|
}
|
|
74945
|
+
const next = backoff.failed({ nowMs: context.nowMs() });
|
|
74946
|
+
if ("giveUp" in next) {
|
|
74947
|
+
await report3(profile, "stopped: Laze has not answered for 3 days");
|
|
74948
|
+
return "stop";
|
|
74949
|
+
}
|
|
74950
|
+
const state = stateOfError({ error: error63, delivery: entry.delivery });
|
|
74951
|
+
await report3(profile, state);
|
|
74952
|
+
context.err(`${profile}: ${state}; trying again in ${Math.ceil(next.delayMs / 1e3)}s
|
|
74953
|
+
`);
|
|
74954
|
+
return next;
|
|
74908
74955
|
}
|
|
74909
74956
|
async function save(run4) {
|
|
74910
74957
|
await writeStateJson({ path: run4.path, value: run4.state });
|
|
@@ -75356,8 +75403,12 @@ async function takeRound2({
|
|
|
75356
75403
|
}
|
|
75357
75404
|
}
|
|
75358
75405
|
async function roundOf({ context, client, name: name3, lock, claudePid, session, seen }) {
|
|
75359
|
-
if ((await holderOf({ path: lock }))?.pid !== context.processes.pid)
|
|
75360
|
-
|
|
75406
|
+
if ((await holderOf({ path: lock }))?.pid !== context.processes.pid) {
|
|
75407
|
+
return void 0;
|
|
75408
|
+
}
|
|
75409
|
+
if (claudePid && !context.processes.alive(claudePid)) {
|
|
75410
|
+
return void 0;
|
|
75411
|
+
}
|
|
75361
75412
|
const due = await dueFromSpool({
|
|
75362
75413
|
context,
|
|
75363
75414
|
profile: name3,
|
|
@@ -75444,9 +75495,10 @@ async function waitForMessages({ context, args }) {
|
|
|
75444
75495
|
const seen = () => input2.transcript_path ? readFile8(input2.transcript_path, "utf8") : Promise.resolve("");
|
|
75445
75496
|
const deadline = context.nowMs() + (WAIT_HOOK_TIMEOUT_SECONDS - 60) * 1e3;
|
|
75446
75497
|
try {
|
|
75498
|
+
const backoff = new ListenerBackoff();
|
|
75447
75499
|
while (context.nowMs() < deadline) {
|
|
75448
75500
|
const round = { context, client, name: name3, lock, claudePid, session, seen, rush };
|
|
75449
|
-
const code = await
|
|
75501
|
+
const code = await retryingRound({ round, backoff });
|
|
75450
75502
|
if (code !== "again") return code;
|
|
75451
75503
|
}
|
|
75452
75504
|
return 0;
|
|
@@ -75455,6 +75507,60 @@ async function waitForMessages({ context, args }) {
|
|
|
75455
75507
|
await rm6(lock, { force: true });
|
|
75456
75508
|
}
|
|
75457
75509
|
}
|
|
75510
|
+
async function retryingRound({ round, backoff }) {
|
|
75511
|
+
const { context, name: name3, claudePid } = round;
|
|
75512
|
+
const code = await settleRound(round).catch((error63) => {
|
|
75513
|
+
if (refusedForGood(error63) || migratedNoticeOf(error63)) throw error63;
|
|
75514
|
+
return { failed: error63 };
|
|
75515
|
+
});
|
|
75516
|
+
if (typeof code !== "object") {
|
|
75517
|
+
const failures = backoff.answered();
|
|
75518
|
+
if (failures > 0) {
|
|
75519
|
+
await logWaiter({
|
|
75520
|
+
context,
|
|
75521
|
+
line: `${name3}: reconnected to Laze after ${failures} failed ${failures === 1 ? "try" : "tries"}`
|
|
75522
|
+
});
|
|
75523
|
+
}
|
|
75524
|
+
return code;
|
|
75525
|
+
}
|
|
75526
|
+
if (claudePid && !context.processes.alive(claudePid)) return 0;
|
|
75527
|
+
const next = backoff.failed({ nowMs: context.nowMs() });
|
|
75528
|
+
if ("giveUp" in next) {
|
|
75529
|
+
context.err("laze: Laze has not answered for 3 days; the waiter stopped.\n");
|
|
75530
|
+
return 2;
|
|
75531
|
+
}
|
|
75532
|
+
if (backoff.tries() === 1) {
|
|
75533
|
+
const line = `${name3}: Laze did not answer (${String(code.failed)}), trying again`;
|
|
75534
|
+
await logWaiter({ context, line });
|
|
75535
|
+
}
|
|
75536
|
+
await context.sleep(next.delayMs);
|
|
75537
|
+
return "again";
|
|
75538
|
+
}
|
|
75539
|
+
async function refusedOnce({
|
|
75540
|
+
context,
|
|
75541
|
+
args,
|
|
75542
|
+
error: error63
|
|
75543
|
+
}) {
|
|
75544
|
+
const profile = String(args.flags.profile ?? "default");
|
|
75545
|
+
const path = statePathOf({ context, kind: "told", profile: `refused-${profile}` });
|
|
75546
|
+
const told = await readFile8(path, "utf8").then(
|
|
75547
|
+
() => true,
|
|
75548
|
+
() => false
|
|
75549
|
+
);
|
|
75550
|
+
if (told) return 0;
|
|
75551
|
+
await writeStateText({ path, text: String(context.nowMs()) });
|
|
75552
|
+
context.err(
|
|
75553
|
+
`Laze: Laze refused this agent's key (${String(error63)}), so messages no longer reach this session. Link it again: laze agent link.
|
|
75554
|
+
`
|
|
75555
|
+
);
|
|
75556
|
+
return 2;
|
|
75557
|
+
}
|
|
75558
|
+
async function logWaiter({ context, line }) {
|
|
75559
|
+
await logDelivery({
|
|
75560
|
+
context: { ...context, out: () => void 0 },
|
|
75561
|
+
line: `waiter ${line}`
|
|
75562
|
+
}).catch(() => void 0);
|
|
75563
|
+
}
|
|
75458
75564
|
async function healRushDelivery({ context }) {
|
|
75459
75565
|
await rearmRushGuards({ context }).catch((error63) => {
|
|
75460
75566
|
context.err(`laze: could not check the other rush sessions: ${String(error63)}
|
|
@@ -75476,7 +75582,7 @@ async function waitHook({ context, args }) {
|
|
|
75476
75582
|
`);
|
|
75477
75583
|
return 2;
|
|
75478
75584
|
}
|
|
75479
|
-
if (error63
|
|
75585
|
+
if (refusedForGood(error63)) return refusedOnce({ context, args, error: error63 });
|
|
75480
75586
|
context.err(`laze: the background waiter stopped: ${String(error63)}
|
|
75481
75587
|
`);
|
|
75482
75588
|
return 0;
|
|
@@ -76376,7 +76482,6 @@ import { rm as rm10 } from "node:fs/promises";
|
|
|
76376
76482
|
var LAZE_MCP_SERVER = "laze";
|
|
76377
76483
|
var DEV_CHANNELS_FLAG = "--dangerously-load-development-channels";
|
|
76378
76484
|
var ROUND_SECONDS3 = 50;
|
|
76379
|
-
var RETRY_MS = 5e3;
|
|
76380
76485
|
function channelInstructionsOf({ server }) {
|
|
76381
76486
|
return [
|
|
76382
76487
|
`Messages from the Laze workspace arrive as <channel source="${server}" message_id="..." channel="..." author="...">text</channel>.`,
|
|
@@ -76455,6 +76560,44 @@ function notificationOf({
|
|
|
76455
76560
|
${answerHintOf({ message: message2, self: self2 })}`, meta: meta3 }
|
|
76456
76561
|
});
|
|
76457
76562
|
}
|
|
76563
|
+
async function inboxRound({
|
|
76564
|
+
context,
|
|
76565
|
+
client,
|
|
76566
|
+
signal,
|
|
76567
|
+
backoff
|
|
76568
|
+
}) {
|
|
76569
|
+
try {
|
|
76570
|
+
const taken = await client.post(
|
|
76571
|
+
"/api/agents/me/inbox",
|
|
76572
|
+
{ waitSeconds: ROUND_SECONDS3 },
|
|
76573
|
+
{ signal }
|
|
76574
|
+
);
|
|
76575
|
+
if (backoff.answered() > 0) context.err("laze mcp: reached Laze again\n");
|
|
76576
|
+
return taken;
|
|
76577
|
+
} catch (error63) {
|
|
76578
|
+
if (signal.aborted) return [];
|
|
76579
|
+
const migrated = migratedNoticeOf(error63);
|
|
76580
|
+
if (migrated) {
|
|
76581
|
+
context.err(`${migrated.notice}
|
|
76582
|
+
`);
|
|
76583
|
+
return void 0;
|
|
76584
|
+
}
|
|
76585
|
+
if (refusedForGood(error63)) {
|
|
76586
|
+
context.err(`laze mcp: Laze refused this agent's key: ${String(error63)}
|
|
76587
|
+
`);
|
|
76588
|
+
return void 0;
|
|
76589
|
+
}
|
|
76590
|
+
const next = backoff.failed({ nowMs: context.nowMs() });
|
|
76591
|
+
if ("giveUp" in next) {
|
|
76592
|
+
context.err("laze mcp: Laze has not answered for 3 days; stopped listening\n");
|
|
76593
|
+
return void 0;
|
|
76594
|
+
}
|
|
76595
|
+
context.err(`laze mcp: could not read the inbox: ${String(error63)}
|
|
76596
|
+
`);
|
|
76597
|
+
await context.sleep(next.delayMs, signal);
|
|
76598
|
+
return [];
|
|
76599
|
+
}
|
|
76600
|
+
}
|
|
76458
76601
|
async function pushInbox({
|
|
76459
76602
|
context,
|
|
76460
76603
|
client,
|
|
@@ -76464,20 +76607,9 @@ async function pushInbox({
|
|
|
76464
76607
|
const marker = statePathOf({ context, kind: "channels", profile });
|
|
76465
76608
|
await writeStateJson({ path: marker, value: { pid: context.processes.pid } });
|
|
76466
76609
|
try {
|
|
76610
|
+
const backoff = new ListenerBackoff();
|
|
76467
76611
|
while (!signal.aborted) {
|
|
76468
|
-
const messages = await
|
|
76469
|
-
if (signal.aborted) return [];
|
|
76470
|
-
const migrated = migratedNoticeOf(error63);
|
|
76471
|
-
if (migrated) {
|
|
76472
|
-
context.err(`${migrated.notice}
|
|
76473
|
-
`);
|
|
76474
|
-
return void 0;
|
|
76475
|
-
}
|
|
76476
|
-
context.err(`laze mcp: could not read the inbox: ${String(error63)}
|
|
76477
|
-
`);
|
|
76478
|
-
await context.sleep(RETRY_MS, signal);
|
|
76479
|
-
return [];
|
|
76480
|
-
});
|
|
76612
|
+
const messages = await inboxRound({ context, client, signal, backoff });
|
|
76481
76613
|
if (messages === void 0) break;
|
|
76482
76614
|
if (messages.length === 0) {
|
|
76483
76615
|
await context.sleep(1e3, signal);
|
|
@@ -96839,7 +96971,6 @@ function watchingRelease({
|
|
|
96839
96971
|
// src/services/rush-guard.service.ts
|
|
96840
96972
|
import { rm as rm19 } from "node:fs/promises";
|
|
96841
96973
|
var WATCH_MS3 = 2e3;
|
|
96842
|
-
var RETRY_MS2 = 3e4;
|
|
96843
96974
|
async function guardRound(guard) {
|
|
96844
96975
|
const { context, client, name: name3, lock, claudePid, session, rush, launch } = guard;
|
|
96845
96976
|
const key = session ? sessionKeyOf({ session }) : void 0;
|
|
@@ -96873,7 +97004,7 @@ function afterFailure({ context, error: error63 }) {
|
|
|
96873
97004
|
`);
|
|
96874
97005
|
return true;
|
|
96875
97006
|
}
|
|
96876
|
-
if (error63
|
|
97007
|
+
if (refusedForGood(error63)) return true;
|
|
96877
97008
|
context.err(`laze: the rush guard will try again: ${String(error63)}
|
|
96878
97009
|
`);
|
|
96879
97010
|
return "failed";
|
|
@@ -96881,12 +97012,23 @@ function afterFailure({ context, error: error63 }) {
|
|
|
96881
97012
|
async function guardRounds(guard) {
|
|
96882
97013
|
const { context } = guard;
|
|
96883
97014
|
const deadline = context.nowMs() + WAIT_HOOK_TIMEOUT_SECONDS * 1e3;
|
|
97015
|
+
const backoff = new ListenerBackoff();
|
|
96884
97016
|
while (context.nowMs() < deadline) {
|
|
96885
97017
|
const done = await guardRound(guard).catch(
|
|
96886
97018
|
(error63) => afterFailure({ context, error: error63 })
|
|
96887
97019
|
);
|
|
96888
97020
|
if (done === true) return 0;
|
|
96889
|
-
|
|
97021
|
+
if (done !== "failed") {
|
|
97022
|
+
if (backoff.answered() > 0) context.err("laze: the rush guard reached Laze again\n");
|
|
97023
|
+
await context.sleep(1e3);
|
|
97024
|
+
continue;
|
|
97025
|
+
}
|
|
97026
|
+
const next = backoff.failed({ nowMs: context.nowMs() });
|
|
97027
|
+
if ("giveUp" in next) {
|
|
97028
|
+
context.err("laze: Laze has not answered for 3 days; the rush guard stopped\n");
|
|
97029
|
+
return 0;
|
|
97030
|
+
}
|
|
97031
|
+
await context.sleep(next.delayMs);
|
|
96890
97032
|
}
|
|
96891
97033
|
return 0;
|
|
96892
97034
|
}
|
package/package.json
CHANGED