@lazehq/cli 0.1.89 → 0.1.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/laze.mjs +452 -204
  2. package/package.json +1 -1
package/dist/laze.mjs CHANGED
@@ -37026,6 +37026,23 @@ var ConfigStore = class _ConfigStore {
37026
37026
  return { result: true, config: { ...config2, profiles: profiles2 } };
37027
37027
  });
37028
37028
  }
37029
+ /**
37030
+ * Marks the profile's key refused, or clears it, only while the profile still holds `token`;
37031
+ * true when that changed whether the profile is marked.
37032
+ */
37033
+ async markRefused({
37034
+ name: name3,
37035
+ token: token2,
37036
+ refused
37037
+ }) {
37038
+ return this.update((config2) => {
37039
+ const profile = config2.profiles[name3];
37040
+ if (profile?.token !== token2) return { result: false };
37041
+ const { refused: old, ...rest } = profile;
37042
+ const profiles2 = { ...config2.profiles, [name3]: refused ? { ...rest, refused } : rest };
37043
+ return { result: !old !== !refused, config: { ...config2, profiles: profiles2 } };
37044
+ });
37045
+ }
37029
37046
  async removeProfile({ name: name3 }) {
37030
37047
  return this.update((config2) => {
37031
37048
  const removed = withoutProfile({ config: config2, name: name3 });
@@ -37154,11 +37171,21 @@ function flagText({
37154
37171
  }
37155
37172
 
37156
37173
  // src/rules/cli-version.rules.ts
37157
- var STAMPED = "0.1.89";
37174
+ var STAMPED = "0.1.91";
37158
37175
  function cliVersionOf({ stamped = STAMPED } = {}) {
37159
37176
  return stamped.startsWith("__") ? "dev" : stamped;
37160
37177
  }
37161
37178
 
37179
+ // src/rules/refusal-format.rules.ts
37180
+ function refusalText({ code, message: message2 }) {
37181
+ const sentence = message2.trim().replace(/[.!]*$/, ".");
37182
+ return `${code}: ${sentence}`;
37183
+ }
37184
+ function refusalLine({ code, message: message2 }) {
37185
+ return `laze: ${refusalText({ code, message: message2 })}
37186
+ `;
37187
+ }
37188
+
37162
37189
  // src/services/cli-context.ts
37163
37190
  var CliUsageError = class extends Error {
37164
37191
  constructor(message2) {
@@ -37174,6 +37201,13 @@ var ProfileMigratedError = class extends Error {
37174
37201
  }
37175
37202
  profile;
37176
37203
  };
37204
+ var ProfileRefusedError = class extends ProfileMigratedError {
37205
+ constructor(profile) {
37206
+ super(profile);
37207
+ this.message = `Laze refused the key of profile "${profile}".`;
37208
+ this.name = "ProfileRefusedError";
37209
+ }
37210
+ };
37177
37211
 
37178
37212
  // src/services/session.service.ts
37179
37213
  import { readFile as readFile4 } from "node:fs/promises";
@@ -61846,7 +61880,9 @@ var customEmojiSchemaDefinition = external_exports.object({
61846
61880
  addedBy: customEmojiAuthorSchema.optional(),
61847
61881
  addedAt: external_exports.iso.datetime().optional(),
61848
61882
  /** Whether the reader may remove it: their own, or any for an admin. */
61849
- removable: external_exports.boolean().optional()
61883
+ removable: external_exports.boolean().optional(),
61884
+ /** False when pickers leave it out, such as another organisation's emoji; absent means true. */
61885
+ offered: external_exports.boolean().optional()
61850
61886
  });
61851
61887
  var customEmojiSchema = customEmojiSchemaDefinition;
61852
61888
  var customEmojiListSchemaDefinition = external_exports.object({
@@ -61860,13 +61896,17 @@ var customEmojiListSchemaDefinition = external_exports.object({
61860
61896
  var customEmojiListSchema = customEmojiListSchemaDefinition;
61861
61897
  var slackCustomEmojiSchema = external_exports.object({
61862
61898
  name: customEmojiNameSchema,
61863
- url: external_exports.string().max(2e3).regex(/^https:\/\/[^\s()<>]+$/)
61899
+ url: external_exports.string().max(2e3).regex(/^https:\/\/[^\s()<>]+$/),
61900
+ /** False for a picture only drawn, never offered, such as another organisation's emoji. */
61901
+ offered: external_exports.boolean().optional()
61864
61902
  });
61865
61903
  var saveCustomEmojiInputSchemaDefinition = external_exports.object({
61866
61904
  workspaceId: external_exports.string().min(1),
61867
61905
  emoji: external_exports.array(slackCustomEmojiSchema).max(1e4),
61868
61906
  /** Names the source no longer has, dropped from the workspace's set. */
61869
- removed: external_exports.array(customEmojiNameSchema).max(1e4).default([])
61907
+ removed: external_exports.array(customEmojiNameSchema).max(1e4).default([]),
61908
+ /** `emoji` is the source's whole list: its other Slack names stay but are no longer offered. */
61909
+ whole: external_exports.boolean().default(false)
61870
61910
  });
61871
61911
  var addCustomEmojiInputSchemaDefinition = external_exports.object({
61872
61912
  workspaceId: external_exports.string().min(1),
@@ -62374,7 +62414,13 @@ var mirrorSourceSchema = external_exports.enum([
62374
62414
  "laze"
62375
62415
  ]);
62376
62416
  var mirrorDeliverySchema = external_exports.enum(["waiting", "failed"]);
62377
- var mirrorDeliveryStateSchema = external_exports.enum(["waiting", "failed", "edit_kept"]);
62417
+ var mirrorDeliveryStateSchema = external_exports.enum([
62418
+ "waiting",
62419
+ "waking",
62420
+ "failed",
62421
+ "edit_kept",
62422
+ "reaction_kept"
62423
+ ]);
62378
62424
  var messageOriginSchemaDefinition = external_exports.object({
62379
62425
  source: mirrorSourceSchema,
62380
62426
  /** The message's key at the source, unique in the workspace (e.g. `slack:T1:C1:1792.0001`). */
@@ -62777,6 +62823,10 @@ var messageSchemaDefinition = external_exports.object({
62777
62823
  mirrorDelivery: mirrorDeliverySchema.nullable().optional(),
62778
62824
  /** Set when the source would not take the last edit of this sent message: it is only in Laze. */
62779
62825
  mirrorEditKept: external_exports.boolean().optional(),
62826
+ /** Set when the source would not take a reaction made in Laze: it is only in Laze. */
62827
+ mirrorReactionKept: external_exports.boolean().optional(),
62828
+ /** Set beside a waiting delivery while the computer that sends it is waking up. */
62829
+ mirrorDeliveryWaking: external_exports.boolean().optional(),
62780
62830
  /** A thread reply also sent to its conversation: it shows in the thread and the channel. */
62781
62831
  alsoInChannel: external_exports.boolean().optional(),
62782
62832
  /** For a reply also sent to the channel: its root's text, for the "replied to a thread" line. */
@@ -63948,7 +63998,7 @@ var chatConversationsTrpc = defineTrpcContract("chat").query("overview", { mirro
63948
63998
  var chatChannelRolesTrpc = defineTrpcContract("chat").mutation("setChannelRole").withInput(setChannelRoleInputSchema).withOutput(conversationSchema).mutation("extendChannel").withInput(extendChannelInputSchema).withOutput(conversationSchema).build();
63949
63999
  var chatMessagesTrpc = defineTrpcContract("chat").query("history", { mirrored: historyMirror }).withInput(historyInputSchema).withOutput(historyPageSchema).query("thread").withInput(messageInputSchema).withOutput(threadSchema).query("message").withInput(messageInputSchema).withOutput(messageSchema).mutation("post").withInput(postMessageInputSchema).withOutput(messageSchema).mutation("forward").withInput(forwardMessageInputSchema).withOutput(messageSchema).mutation("addMentioned").withInput(addMentionedInputSchema).withOutput(messageSchema).mutation("edit").withInput(editMessageInputSchema).withOutput(messageSchema).mutation("delete").withInput(messageInputSchema).withOutput(messageSchema).mutation("remove").withInput(messageInputSchema).withOutput(messageSchema).mutation("react").withInput(reactInputSchema).withOutput(messageSchema).mutation("signalTyping").withInput(signalTypingInputSchema).withOutput(external_exports.object({ sent: external_exports.literal(true) })).mutation("markRead").withInput(markReadInputSchema).withOutput(external_exports.object({ lastReadSeq: external_exports.number().int().nonnegative() })).mutation("markUnread").withInput(markUnreadInputSchema).withOutput(external_exports.object({ lastReadSeq: external_exports.number().int().nonnegative() })).query("search").withInput(searchInputSchema).withOutput(searchResultSchema).build();
63950
64000
  var chatFilesTrpc = defineTrpcContract("chat").mutation("startUpload").withInput(startUploadInputSchema).withOutput(uploadTicketSchema).mutation("completeUpload").withInput(completeUploadInputSchema).withOutput(attachmentSchema).mutation("transcribeVoiceSegment").withInput(transcribeVoiceSegmentInputSchema).withOutput(voiceSegmentTextSchema).mutation("abortUpload").withInput(fileInputSchema).withOutput(external_exports.object({ aborted: external_exports.literal(true) })).query("fileLink").withInput(fileLinkInputSchema).withOutput(fileLinkSchema).query("channelFiles").withInput(channelFilesInputSchema).withOutput(channelFilesSchema).mutation("renameAttachment").withInput(renameAttachmentInputSchema).withOutput(attachmentSchema).mutation("hideUnfurl").withInput(hideUnfurlInputSchema).withOutput(messageSchema).query("unfurlImage").withInput(unfurlImageInputSchema).withOutput(fileLinkSchema).query("searchGifs").withInput(searchGifsInputSchema).withOutput(gifResultsSchema).build();
63951
- var chatFollowingTrpc = defineTrpcContract("chat").mutation("setNotify").withInput(setNotifyInputSchema).withOutput(conversationSummarySchema).mutation("hideConversation").withInput(channelInputSchema).withOutput(external_exports.object({ hidden: external_exports.literal(true) })).mutation("followThread").withInput(followThreadInputSchema).withOutput(threadFollowSchema).query("threadFollow").withInput(messageInputSchema).withOutput(threadFollowSchema).query("threads", { mirrored: threadsMirror }).withInput(threadsInputSchema).withOutput(threadsPageSchema).query("threadsUnread").withInput(workspaceInputSchema).withOutput(threadsUnreadSchema).query("notificationCount").withInput(workspaceInputSchema).withOutput(external_exports.object({ count: external_exports.number().int().nonnegative() })).mutation("markThreadRead").withInput(messageInputSchema).withOutput(external_exports.object({ read: external_exports.literal(true) })).mutation("pin").withInput(pinMessageInputSchema).withOutput(messageSchema).query("pins").withInput(channelInputSchema).withOutput(pinsPageSchema).query("saved").withInput(savedInputSchema).withOutput(savedPageSchema).query("savedMarks").withInput(workspaceInputSchema).withOutput(savedMarksSchema).mutation("saveMessage").withInput(saveMessageInputSchema).withOutput(savedStatusSchema).mutation("markSavedDone").withInput(markSavedDoneInputSchema).withOutput(savedStatusSchema).mutation("setReminder").withInput(setReminderInputSchema).withOutput(savedStatusSchema).query("activity").withInput(activityInputSchema).withOutput(activityPageSchema).mutation("markActivityRead").withInput(markActivityReadInputSchema).withOutput(external_exports.object({ read: external_exports.literal(true) })).build();
64001
+ var chatFollowingTrpc = defineTrpcContract("chat").mutation("setNotify").withInput(setNotifyInputSchema).withOutput(conversationSummarySchema).mutation("hideConversation").withInput(channelInputSchema).withOutput(external_exports.object({ hidden: external_exports.literal(true) })).mutation("followThread").withInput(followThreadInputSchema).withOutput(threadFollowSchema).query("threadFollow").withInput(messageInputSchema).withOutput(threadFollowSchema).query("threads", { mirrored: threadsMirror }).withInput(threadsInputSchema).withOutput(threadsPageSchema).query("threadsUnread").withInput(workspaceInputSchema).withOutput(threadsUnreadSchema).query("notificationCount").withInput(workspaceInputSchema).withOutput(external_exports.object({ count: external_exports.number().int().nonnegative() })).mutation("markThreadRead").withInput(messageInputSchema).withOutput(external_exports.object({ read: external_exports.literal(true) })).mutation("pin").withInput(pinMessageInputSchema).withOutput(messageSchema).mutation("retryMirrorDelivery").withInput(messageInputSchema).withOutput(external_exports.object({ retried: external_exports.boolean() })).query("pins").withInput(channelInputSchema).withOutput(pinsPageSchema).query("saved").withInput(savedInputSchema).withOutput(savedPageSchema).query("savedMarks").withInput(workspaceInputSchema).withOutput(savedMarksSchema).mutation("saveMessage").withInput(saveMessageInputSchema).withOutput(savedStatusSchema).mutation("markSavedDone").withInput(markSavedDoneInputSchema).withOutput(savedStatusSchema).mutation("setReminder").withInput(setReminderInputSchema).withOutput(savedStatusSchema).query("activity").withInput(activityInputSchema).withOutput(activityPageSchema).mutation("markActivityRead").withInput(markActivityReadInputSchema).withOutput(external_exports.object({ read: external_exports.literal(true) })).build();
63952
64002
  var chatSessionTrpc = defineTrpcContract("chat").mutation("realtimeToken").withInput(workspaceInputSchema).withOutput(realtimeTokenSchema).query("drafts").withInput(workspaceInputSchema).withOutput(draftListSchema).mutation("saveDraft").withInput(saveDraftInputSchema).withOutput(draftSavedSchema).mutation("deleteDraft").withInput(deleteDraftInputSchema).withOutput(draftSavedSchema).query("sent").withInput(listSentInputSchema).withOutput(sentPageSchema).query("sidebarLayout").withInput(workspaceInputSchema).withOutput(sidebarLayoutSchema).mutation("editSidebar").withInput(editSidebarInputSchema).withOutput(sidebarLayoutSchema).query("readerPreferences").withInput(workspaceInputSchema).withOutput(readerPreferencesSchema).mutation("setReaderPreferences").withInput(setReaderPreferencesInputSchema).withOutput(readerPreferencesSchema).mutation("star").withInput(starInputSchema).withOutput(starStatusSchema).query("starred").withInput(workspaceInputSchema).withOutput(starredListSchema).mutation("scrubSecrets").withInput(scrubChatInputSchema).withOutput(chatScrubReportSchema).mutation("restoreScrubbed").withInput(messageInputSchema).withOutput(messageSchema).build();
63953
64003
  var chatScheduledTrpc = defineTrpcContract("chat").mutation("scheduleMessage").withInput(scheduleMessageInputSchema).withOutput(scheduledMessageSchema).query("scheduled").withInput(listScheduledInputSchema).withOutput(scheduledListSchema).mutation("editScheduled").withInput(editScheduledInputSchema).withOutput(scheduledMessageSchema).mutation("sendScheduledNow").withInput(scheduledInputSchema).withOutput(scheduledMessageSchema).mutation("cancelScheduled").withInput(scheduledInputSchema).withOutput(scheduledMessageSchema).build();
63954
64004
  var chatPresenceTrpc = defineTrpcContract("chat").mutation("heartbeat").withInput(workspaceInputSchema).withOutput(heartbeatSchema).query("presence").withInput(workspaceInputSchema).withOutput(presenceListSchema).mutation("setStatus").withInput(setStatusInputSchema).withOutput(personPresenceSchema).mutation("clearStatus").withInput(workspaceInputSchema).withOutput(personPresenceSchema).mutation("setAway").withInput(setAwayInputSchema).withOutput(personPresenceSchema).build();
@@ -65117,6 +65167,13 @@ var harnessModelSchemaDefinition = external_exports.object({
65117
65167
  defaultEffort: external_exports.string().max(40).nullable().default(null)
65118
65168
  });
65119
65169
  var harnessModelSchema = harnessModelSchemaDefinition;
65170
+ var pickupTimingSchema = external_exports.object({
65171
+ messageId: external_exports.string().min(1),
65172
+ beganMs: external_exports.number().int().nonnegative(),
65173
+ notesMs: external_exports.number().int().nonnegative(),
65174
+ sessionMs: external_exports.number().int().nonnegative(),
65175
+ queuedMs: external_exports.number().int().nonnegative()
65176
+ });
65120
65177
  var lazeAgentEventSchemaDefinition = external_exports.discriminatedUnion("type", [
65121
65178
  external_exports.object({
65122
65179
  type: external_exports.literal("harness_started"),
@@ -65131,7 +65188,9 @@ var lazeAgentEventSchemaDefinition = external_exports.discriminatedUnion("type",
65131
65188
  type: external_exports.literal("turn_started"),
65132
65189
  turnId: external_exports.string().min(1),
65133
65190
  /** The Laze messages this turn answers; none for a turn the harness started on its own. */
65134
- messageIds: external_exports.array(external_exports.string().min(1)).optional()
65191
+ messageIds: external_exports.array(external_exports.string().min(1)).optional(),
65192
+ /** How the supervisor spent the time from each message's arrival to this turn (ADR-201). */
65193
+ pickup: external_exports.array(pickupTimingSchema).max(50).optional()
65135
65194
  }),
65136
65195
  /** Sent to a host that (re)connects mid-turn: the turn it missed the start of, still running. */
65137
65196
  external_exports.object({
@@ -65388,11 +65447,15 @@ var deliverMessageInputSchemaDefinition = external_exports.object({
65388
65447
  attempt: external_exports.number().int().min(2).optional(),
65389
65448
  /** The vault turn of the person who asked; the CLI presents it on vault calls. */
65390
65449
  turnToken: external_exports.string().min(1).optional(),
65450
+ /** A personal agent's own turn, for its owner: what a turn the agent starts itself presents. */
65451
+ ownTurnToken: external_exports.string().min(1).optional(),
65391
65452
  /** The thread the message is in; a turn joins only messages of one channel and thread. */
65392
65453
  threadRootId: external_exports.string().min(1).optional(),
65393
65454
  /** Files staged in the sandbox before the turn; the text lists their paths. */
65394
65455
  files: external_exports.array(deliveredFileSchema).max(DELIVERED_FILES_MAX_COUNT).default([]),
65395
- session: turnSessionSchema.optional()
65456
+ session: turnSessionSchema.optional(),
65457
+ /** When the message was posted (epoch ms), for its pickup trace; never sent to the supervisor. */
65458
+ postedAtMs: external_exports.number().int().nonnegative().optional()
65396
65459
  });
65397
65460
  var sandboxStateSchema = external_exports.enum(["absent", "created", "running", "stopped"]);
65398
65461
  var sandboxStatusSchemaDefinition = external_exports.object({
@@ -65617,6 +65680,8 @@ var hostFrameSchemaDefinition = external_exports.discriminatedUnion("type", [
65617
65680
  /** Try again's count: a later attempt is new work, not a resend of a message already seen. */
65618
65681
  attempt: external_exports.number().int().min(2).optional(),
65619
65682
  turnToken: external_exports.string().min(1).optional(),
65683
+ /** The owner's turn a personal agent presents in a turn it starts itself. */
65684
+ ownTurnToken: external_exports.string().min(1).optional(),
65620
65685
  threadRootId: external_exports.string().min(1).optional(),
65621
65686
  files: external_exports.array(deliveredFileSchema).max(10).default([]),
65622
65687
  session: turnSessionSchema.optional()
@@ -66747,7 +66812,7 @@ var NAMING_FREE_CLI_COMMANDS = [
66747
66812
  "whoami",
66748
66813
  "history"
66749
66814
  ];
66750
- var NAMING_IS_SILENT = "Naming or renaming a conversation is silent: never post a message about it, and leave it out of your final text.";
66815
+ var NAMING_IS_SILENT = "Naming or renaming a conversation is silent: never post a message about it.";
66751
66816
  function namingFirstTextOf({ channelIds }) {
66752
66817
  const lines2 = channelIds.map((id4) => ` laze conversation rename ${id4} "<a few words>"`);
66753
66818
  return [
@@ -67995,7 +68060,9 @@ var harnessLoginEntrySchemaDefinition = external_exports.object({
67995
68060
  /** When its provider's usage endpoint was last asked; null before. */
67996
68061
  checkedAt: external_exports.iso.datetime().nullable(),
67997
68062
  /** The agents running on this login now. */
67998
- agentsOnIt: external_exports.number().int().nonnegative()
68063
+ agentsOnIt: external_exports.number().int().nonnegative(),
68064
+ /** `computer`: signed in on the person's own Laze computer, which keeps the token. */
68065
+ source: external_exports.enum(["keychain", "computer"]).optional()
67999
68066
  });
68000
68067
  var harnessLoginListSchemaDefinition = external_exports.object({
68001
68068
  logins: external_exports.array(harnessLoginEntrySchemaDefinition)
@@ -70040,6 +70107,29 @@ var agentProfileUi = uiTokens("agent");
70040
70107
  var AgentProfileSlot = agentProfileUi.component("profile");
70041
70108
  var AgentOwnedListSlot = agentProfileUi.component("ownedList");
70042
70109
 
70110
+ // src/rules/linked-profile.rules.ts
70111
+ function slugOf(name3) {
70112
+ return name3.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "agent";
70113
+ }
70114
+ function linkedProfileNameOf({
70115
+ args,
70116
+ linked,
70117
+ profiles: profiles2
70118
+ }) {
70119
+ const wanted = flagText({ args, name: "profile" }) || `agent-${slugOf(linked.agent.name)}`;
70120
+ const free = (name3) => {
70121
+ const held = profiles2[name3];
70122
+ return !held || held.kind === "agent" && held.agentId === linked.agent.id;
70123
+ };
70124
+ if (free(wanted)) return wanted;
70125
+ for (let number4 = 2; ; number4 += 1) {
70126
+ if (free(`${wanted}-${number4}`)) return `${wanted}-${number4}`;
70127
+ }
70128
+ }
70129
+ function revokedKeyLineOf({ profile }) {
70130
+ return `${profile}: this agent's key was revoked: run \`laze agent link\` again or remove it with \`laze logout --profile ${profile}\``;
70131
+ }
70132
+
70043
70133
  // src/services/laze-client.service.ts
70044
70134
  var CLI_VERSION_HEADER = "x-laze-cli-version";
70045
70135
  var LazeApiError = class extends Error {
@@ -70075,14 +70165,16 @@ var LazeClient = class _LazeClient {
70075
70165
  baseUrl,
70076
70166
  token: token2,
70077
70167
  fetcher,
70078
- onMigrated
70168
+ onMigrated,
70169
+ onRefused
70079
70170
  }) {
70080
70171
  return new _LazeClient({
70081
70172
  baseUrl: baseUrl.replace(/\/+$/, ""),
70082
70173
  token: token2,
70083
70174
  fetcher,
70084
70175
  headers: {},
70085
- onMigrated
70176
+ onMigrated,
70177
+ onRefused
70086
70178
  });
70087
70179
  }
70088
70180
  /** The same client, sending these headers too on every call. */
@@ -70124,6 +70216,8 @@ var LazeClient = class _LazeClient {
70124
70216
  const found = migratedNoticeOf(error63);
70125
70217
  if (found && this.options.onMigrated)
70126
70218
  await this.options.onMigrated(found).catch(() => void 0);
70219
+ else if (!found && error63.status === 401 && !error63.code.startsWith("http_") && this.options.onRefused)
70220
+ await this.options.onRefused(error63).catch(() => void 0);
70127
70221
  }
70128
70222
  async send({
70129
70223
  method,
@@ -70281,6 +70375,22 @@ async function reportMachine({
70281
70375
  function markMigratedOn({ context, profile }) {
70282
70376
  return async ({ notice, link: link2 }) => context.store.markMigrated({ name: profile, migrated: { at: context.nowMs(), link: link2, notice } });
70283
70377
  }
70378
+ var REFUSED_RECHECK_MS = 6 * 60 * 60 * 1e3;
70379
+ function markRefusedOn({
70380
+ context,
70381
+ profile,
70382
+ token: token2
70383
+ }) {
70384
+ return async (error63) => {
70385
+ const refused = { at: context.nowMs(), message: error63.message };
70386
+ const marked = await context.store.markRefused({ name: profile, token: token2, refused });
70387
+ if (marked) context.err(`${revokedKeyLineOf({ profile })}
70388
+ `);
70389
+ };
70390
+ }
70391
+ function refusedRecently({ profile, nowMs: nowMs2 }) {
70392
+ return profile.refused !== void 0 && nowMs2 - profile.refused.at < REFUSED_RECHECK_MS;
70393
+ }
70284
70394
  function quietWhenMigrated({ args }) {
70285
70395
  const [first = "", second = ""] = args.words;
70286
70396
  if (first === "hook") return true;
@@ -70313,19 +70423,24 @@ async function signedIn({
70313
70423
  throw new CliUsageError(
70314
70424
  "Not signed in: run `laze login`, or `laze agent link --token <token>` from an agent."
70315
70425
  );
70316
- if (chosen.profile.migrated && quietWhenMigrated({ args })) {
70317
- throw new ProfileMigratedError(chosen.name);
70426
+ const quiet = quietWhenMigrated({ args });
70427
+ if (chosen.profile.migrated && quiet) throw new ProfileMigratedError(chosen.name);
70428
+ if (quiet && refusedRecently({ profile: chosen.profile, nowMs: context.nowMs() })) {
70429
+ throw new ProfileRefusedError(chosen.name);
70318
70430
  }
70431
+ const turn = chosen.profile.kind === "agent" ? await turnTokenOf({ context }) : "";
70432
+ const { token: token2 } = chosen.profile;
70319
70433
  const client = LazeClient.create({
70320
70434
  baseUrl: chosen.profile.url,
70321
- token: chosen.profile.token,
70435
+ token: token2,
70322
70436
  fetcher: context.fetcher,
70323
- onMigrated: markMigratedOn({ context, profile: chosen.name })
70437
+ onMigrated: markMigratedOn({ context, profile: chosen.name }),
70438
+ ...turn ? {} : { onRefused: markRefusedOn({ context, profile: chosen.name, token: token2 }) }
70324
70439
  });
70440
+ if (quiet && chosen.profile.refused) await askedAgain({ context, name: chosen.name, client });
70325
70441
  if (chosen.profile.kind !== "agent")
70326
70442
  return { name: chosen.name, profile: chosen.profile, client };
70327
70443
  await namingFirst({ client, args });
70328
- const turn = await turnTokenOf({ context });
70329
70444
  if (!turn) {
70330
70445
  const { name: name3, profile } = chosen;
70331
70446
  await reportMachine({ context, profile: name3, token: profile.token, client });
@@ -70336,6 +70451,20 @@ async function signedIn({
70336
70451
  client: turn ? client.withHeaders({ "x-laze-turn": turn }) : client
70337
70452
  };
70338
70453
  }
70454
+ async function askedAgain({
70455
+ context,
70456
+ name: name3,
70457
+ client
70458
+ }) {
70459
+ const profile = (await context.store.read()).profiles[name3];
70460
+ try {
70461
+ await client.get("/api/agents/me");
70462
+ } catch (error63) {
70463
+ if (error63.status === 401) throw new ProfileRefusedError(name3);
70464
+ return;
70465
+ }
70466
+ if (profile) await context.store.markRefused({ name: name3, token: profile.token, refused: void 0 });
70467
+ }
70339
70468
  var ALWAYS_FREE = [
70340
70469
  "hook",
70341
70470
  "adopt",
@@ -71273,6 +71402,8 @@ var slackMessageEventSchemaDefinition = external_exports.object({
71273
71402
  latestReply: external_exports.string().nullable().default(null),
71274
71403
  /** When the message was last edited, Slack's `edited.ts`; null when it never was. */
71275
71404
  editedTs: external_exports.string().nullable().default(null),
71405
+ /** The Laze message this Slack message is the copy of, from the metadata Laze posts with it. */
71406
+ lazeMessageId: external_exports.string().min(1).optional(),
71276
71407
  /** The message's Block Kit blocks and legacy attachments as Slack sent them, until handled. */
71277
71408
  blocks: external_exports.array(external_exports.record(external_exports.string(), external_exports.unknown())).optional(),
71278
71409
  /** The message's own `text` beside its blocks; `text` above is what Slack shows, flattened. */
@@ -71857,13 +71988,13 @@ function formatSearch({
71857
71988
  }
71858
71989
 
71859
71990
  // src/services/claude-turn.service.ts
71860
- import { rm as rm2 } from "node:fs/promises";
71861
- import { dirname as dirname5, join as join6 } from "node:path";
71991
+ import { rm as rm3 } from "node:fs/promises";
71992
+ import { dirname as dirname6, join as join7 } from "node:path";
71862
71993
 
71863
71994
  // src/services/harness-session.service.ts
71864
- import { open as open3, readdir, readFile as readFile5, stat as stat2 } from "node:fs/promises";
71995
+ import { open as open3, readdir as readdir2, readFile as readFile5, stat as stat3 } from "node:fs/promises";
71865
71996
  import { homedir as homedir2, hostname as hostname4 } from "node:os";
71866
- import { dirname as dirname4, join as join4 } from "node:path";
71997
+ import { dirname as dirname5, join as join5 } from "node:path";
71867
71998
 
71868
71999
  // src/rules/claude-subagent.rules.ts
71869
72000
  function lastCallAtOf({ text: text3, command }) {
@@ -71995,6 +72126,83 @@ async function claudeProjectOf({
71995
72126
  return candidates.find((folder) => holds({ folder, inner: context.cwd })) ?? resolve2(context.cwd);
71996
72127
  }
71997
72128
 
72129
+ // src/services/session-notes.service.ts
72130
+ import { readdir, rm as rm2, stat as stat2 } from "node:fs/promises";
72131
+ import { dirname as dirname4, join as join4 } from "node:path";
72132
+ function notePathOf({ context, pid }) {
72133
+ return statePathOf({ context, kind: "sessions", profile: String(pid) });
72134
+ }
72135
+ async function processOf({ context, pid }) {
72136
+ const start2 = await context.processes.startOf(pid);
72137
+ const command = (await context.processes.argsOf(pid))?.[0];
72138
+ return { ...start2 ? { start: start2 } : {}, ...command ? { command } : {} };
72139
+ }
72140
+ async function writeSessionNote({
72141
+ context,
72142
+ pid,
72143
+ note
72144
+ }) {
72145
+ const process2 = await processOf({ context, pid });
72146
+ await writeStateJson({ path: notePathOf({ context, pid }), value: { ...note, process: process2 } });
72147
+ }
72148
+ async function standingOf({
72149
+ context,
72150
+ pid,
72151
+ note
72152
+ }) {
72153
+ if (!context.processes.alive(pid)) return "gone";
72154
+ const now = await processOf({ context, pid });
72155
+ const was = note.process;
72156
+ if (was?.start && now.start) return was.start === now.start ? "live" : "stale";
72157
+ if (was?.command && now.command) return was.command === now.command ? "live" : "stale";
72158
+ if (was || !now.command) return "live";
72159
+ const args = await context.processes.argsOf(pid) ?? [];
72160
+ return args.some((word3) => /claude/i.test(word3)) ? "live" : "stale";
72161
+ }
72162
+ async function dropStale({
72163
+ context,
72164
+ pid,
72165
+ path,
72166
+ tell
72167
+ }) {
72168
+ await rm2(path, { force: true });
72169
+ const line = `Removed the stale session note ${path}: pid ${pid} is another process now.`;
72170
+ if (tell) context.err(`laze: ${line}
72171
+ `);
72172
+ return line;
72173
+ }
72174
+ async function sessionNotesOf({
72175
+ context,
72176
+ tell = true
72177
+ }) {
72178
+ const folder = dirname4(notePathOf({ context, pid: 1 }));
72179
+ const files2 = await readdir(folder).catch(() => []);
72180
+ const notes = [];
72181
+ const dropped = [];
72182
+ for (const file4 of files2) {
72183
+ const pid = Number(file4.replace(/\.json$/, ""));
72184
+ const path = join4(folder, file4);
72185
+ const note = pid ? await readStateJson({ path }) : void 0;
72186
+ if (!note) continue;
72187
+ const standing = await standingOf({ context, pid, note });
72188
+ if (standing === "stale") {
72189
+ dropped.push(await dropStale({ context, pid, path, tell }));
72190
+ continue;
72191
+ }
72192
+ const at = await stat2(path).then(
72193
+ (info) => info.mtimeMs,
72194
+ () => 0
72195
+ );
72196
+ notes.push({ pid, note, standing, at });
72197
+ }
72198
+ return { notes: notes.toSorted((a, b) => b.at - a.at), dropped };
72199
+ }
72200
+ async function noteProcessRuns({ context, pid }) {
72201
+ const note = await readStateJson({ path: notePathOf({ context, pid }) });
72202
+ if (!note) return context.processes.alive(pid);
72203
+ return await standingOf({ context, pid, note }) === "live";
72204
+ }
72205
+
71998
72206
  // src/services/harness-session.service.ts
71999
72207
  function sessionOf({
72000
72208
  context,
@@ -72023,9 +72231,8 @@ async function rememberSession({
72023
72231
  session
72024
72232
  }) {
72025
72233
  if (!session || !claudePid) return;
72026
- const path = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
72027
72234
  const launch = launchEnvOf({ inherited: context.environment.inherited });
72028
- await writeStateJson({ path, value: { ...session, launch } });
72235
+ await writeSessionNote({ context, pid: claudePid, note: { ...session, launch } });
72029
72236
  }
72030
72237
  async function currentSessionOf({
72031
72238
  context,
@@ -72094,29 +72301,25 @@ async function liveElsewhere({
72094
72301
  asleepCounts = true
72095
72302
  }) {
72096
72303
  if (await rushKeeps({ context, key, claudePid, asleepCounts })) return true;
72097
- const folder = dirname4(statePathOf({ context, kind: "sessions", profile: "x" }));
72098
- for (const file4 of await readdir(folder).catch(() => [])) {
72099
- const pid = Number(file4.replace(/\.json$/, ""));
72100
- if (!pid || pid === claudePid || !context.processes.alive(pid)) continue;
72101
- const noted = await readStateJson({ path: join4(folder, file4) });
72102
- if (noted && sessionKeyOf({ session: noted }) === key) return true;
72103
- }
72104
- return false;
72304
+ const { notes } = await sessionNotesOf({ context });
72305
+ return notes.some(
72306
+ ({ pid, note, standing }) => standing === "live" && pid !== claudePid && sessionKeyOf({ session: note }) === key
72307
+ );
72105
72308
  }
72106
72309
  async function claudeTranscriptOf({
72107
72310
  context,
72108
72311
  sessionId
72109
72312
  }) {
72110
72313
  const inherited = context.environment.inherited;
72111
- const root = join4(
72112
- inherited.CLAUDE_CONFIG_DIR || join4(inherited.HOME || homedir2(), ".claude"),
72314
+ const root = join5(
72315
+ inherited.CLAUDE_CONFIG_DIR || join5(inherited.HOME || homedir2(), ".claude"),
72113
72316
  "projects"
72114
72317
  );
72115
- const folders = await readdir(root).catch(() => []);
72318
+ const folders = await readdir2(root).catch(() => []);
72116
72319
  const found = await Promise.all(
72117
72320
  folders.map(async (folder) => {
72118
- const path = join4(root, folder, `${sessionId}.jsonl`);
72119
- return stat2(path).then(
72321
+ const path = join5(root, folder, `${sessionId}.jsonl`);
72322
+ return stat3(path).then(
72120
72323
  (info) => info.isFile() ? [{ path, at: info.mtimeMs }] : [],
72121
72324
  () => []
72122
72325
  );
@@ -72143,11 +72346,11 @@ async function runsInSubagent({ context, command }) {
72143
72346
  if (!sessionId) return false;
72144
72347
  const { path } = await claudeTranscriptOf({ context, sessionId });
72145
72348
  if (!path) return false;
72146
- const folder = join4(dirname4(path), sessionId, "subagents");
72147
- const files2 = await readdir(folder).catch(() => []);
72349
+ const folder = join5(dirname5(path), sessionId, "subagents");
72350
+ const files2 = await readdir2(folder).catch(() => []);
72148
72351
  const subagents = await Promise.all(
72149
72352
  files2.filter((file4) => file4.endsWith(".jsonl")).map(
72150
- async (file4) => lastCallAtOf({ text: await tailOf({ path: join4(folder, file4) }), command })
72353
+ async (file4) => lastCallAtOf({ text: await tailOf({ path: join5(folder, file4) }), command })
72151
72354
  )
72152
72355
  );
72153
72356
  const session = lastCallAtOf({ text: await tailOf({ path }), command });
@@ -72221,7 +72424,7 @@ async function notBoundNotice({
72221
72424
 
72222
72425
  // src/services/plugin-hook.service.ts
72223
72426
  import { readFile as readFile6 } from "node:fs/promises";
72224
- import { join as join5 } from "node:path";
72427
+ import { join as join6 } from "node:path";
72225
72428
  async function agentProfileHere({
72226
72429
  context,
72227
72430
  args,
@@ -72242,7 +72445,7 @@ async function agentProfileHere({
72242
72445
  }
72243
72446
  async function projectHooksHere({ context }) {
72244
72447
  const directory = context.environment.inherited.CLAUDE_PROJECT_DIR || context.cwd;
72245
- const path = join5(directory, ".claude", "settings.local.json");
72448
+ const path = join6(directory, ".claude", "settings.local.json");
72246
72449
  return readFile6(path, "utf8").then((text3) => hasLazeHooks({ settings: JSON.parse(text3) })).catch(() => false);
72247
72450
  }
72248
72451
  async function pluginHookArgs({
@@ -72261,7 +72464,7 @@ async function pluginHookArgs({
72261
72464
  var PRE_TOOL_TIMEOUT_MS = 3e3;
72262
72465
  function statePath({ context, agent: agent3 }) {
72263
72466
  const safe = agent3.replace(/[^a-zA-Z0-9_-]/g, "_");
72264
- return join6(dirname5(context.environment.configPath), "turns", `${safe}.json`);
72467
+ return join7(dirname6(context.environment.configPath), "turns", `${safe}.json`);
72265
72468
  }
72266
72469
  async function readState({ context, agent: agent3 }) {
72267
72470
  return readStateJson({ path: statePath({ context, agent: agent3 }) });
@@ -72326,7 +72529,7 @@ async function turnEnded({
72326
72529
  }) {
72327
72530
  const state = await readState({ context, agent: agent3 });
72328
72531
  if (!state) return;
72329
- await rm2(statePath({ context, agent: agent3 }), { force: true });
72532
+ await rm3(statePath({ context, agent: agent3 }), { force: true });
72330
72533
  await beat({ client, state, working: false }).catch(() => void 0);
72331
72534
  }
72332
72535
  async function preToolHook({ context, args }) {
@@ -72374,7 +72577,7 @@ async function preToolHook({ context, args }) {
72374
72577
  }
72375
72578
 
72376
72579
  // src/services/message-files.service.ts
72377
- import { readFile as readFile7, stat as stat3 } from "node:fs/promises";
72580
+ import { readFile as readFile7, stat as stat4 } from "node:fs/promises";
72378
72581
  import { basename as basename4, resolve as resolve3 } from "node:path";
72379
72582
 
72380
72583
  // src/rules/file-types.rules.ts
@@ -72473,7 +72676,7 @@ async function readyOf({ context, source }) {
72473
72676
  return asBytes({ source, file: await downloaded({ context, url: value }) });
72474
72677
  }
72475
72678
  const full = resolve3(context.cwd, value);
72476
- const found = await stat3(full).catch(() => void 0);
72679
+ const found = await stat4(full).catch(() => void 0);
72477
72680
  if (found?.isFile()) return asBytes({ source, file: await local({ full }) });
72478
72681
  const marked = fileMarkerIdsIn(value)[0] ?? (UPLOADED_ID.test(value) ? value : void 0);
72479
72682
  if (marked) return { kind: "id", id: marked };
@@ -73098,7 +73301,7 @@ async function slackOf({
73098
73301
  if (!(error63 instanceof LazeApiError)) throw error63;
73099
73302
  if (error63.code === "slack_search_person_only") return { answer: null, note: AGENT_NOTE };
73100
73303
  if (error63.status === 404) return { answer: null, note: null };
73101
- return { answer: null, note: `From Slack: ${error63.message} (${error63.code}).` };
73304
+ return { answer: null, note: `From Slack: ${refusalText(error63)}` };
73102
73305
  }
73103
73306
  }
73104
73307
  async function search({ context, args }) {
@@ -73126,11 +73329,11 @@ function channelLabelIn(channel) {
73126
73329
  }
73127
73330
 
73128
73331
  // src/services/claude-wait.service.ts
73129
- import { readFile as readFile8, rm as rm5 } from "node:fs/promises";
73332
+ import { readFile as readFile8, rm as rm6 } from "node:fs/promises";
73130
73333
 
73131
73334
  // src/services/connect-service.service.ts
73132
73335
  import { createHash as createHash2 } from "node:crypto";
73133
- import { mkdir as mkdir3, rm as rm4, writeFile } from "node:fs/promises";
73336
+ import { mkdir as mkdir3, rm as rm5, writeFile } from "node:fs/promises";
73134
73337
  import { dirname as dirname12, join as join14 } from "node:path";
73135
73338
 
73136
73339
  // src/rules/connect-service.rules.ts
@@ -73253,25 +73456,25 @@ function rolloutEventOf({
73253
73456
  }
73254
73457
 
73255
73458
  // src/services/connect-delivery.service.ts
73256
- import { rm as rm3, stat as stat5 } from "node:fs/promises";
73459
+ import { rm as rm4, stat as stat5 } from "node:fs/promises";
73257
73460
  import { homedir as homedir3, hostname as hostname5 } from "node:os";
73258
73461
  import { dirname as dirname11, join as join13 } from "node:path";
73259
73462
 
73260
73463
  // src/services/codex-turn-watch.service.ts
73261
- import { open as open4, readdir as readdir2 } from "node:fs/promises";
73262
- import { basename as basename5, join as join7 } from "node:path";
73464
+ import { open as open4, readdir as readdir3 } from "node:fs/promises";
73465
+ import { basename as basename5, join as join8 } from "node:path";
73263
73466
  var READ_MS = 1500;
73264
73467
  var KEEP_WORKING_MS = 3e4;
73265
73468
  async function codexRolloutPathOf({
73266
73469
  codexHome,
73267
73470
  threadId
73268
73471
  }) {
73269
- const root = join7(codexHome, "sessions");
73270
- const files2 = await readdir2(root, { recursive: true }).catch(() => []);
73472
+ const root = join8(codexHome, "sessions");
73473
+ const files2 = await readdir3(root, { recursive: true }).catch(() => []);
73271
73474
  const file4 = files2.find(
73272
73475
  (name3) => basename5(name3).startsWith("rollout-") && name3.endsWith(`-${threadId}.jsonl`)
73273
73476
  );
73274
- return file4 ? join7(root, file4) : void 0;
73477
+ return file4 ? join8(root, file4) : void 0;
73275
73478
  }
73276
73479
  function rolloutPathOf({ delivery }) {
73277
73480
  return codexRolloutPathOf({ codexHome: delivery.codexHome, threadId: delivery.threadId });
@@ -73360,7 +73563,7 @@ var CodexTurnWatch = class _CodexTurnWatch {
73360
73563
  };
73361
73564
 
73362
73565
  // src/services/mcp-relay.service.ts
73363
- import { dirname as dirname6, join as join8 } from "node:path";
73566
+ import { dirname as dirname7, join as join9 } from "node:path";
73364
73567
 
73365
73568
  // ../../node_modules/.pnpm/ws@8.21.3_bufferutil@4.1.0/node_modules/ws/wrapper.mjs
73366
73569
  var import_stream = __toESM(require_stream(), 1);
@@ -73696,7 +73899,7 @@ var STOPS = /* @__PURE__ */ new Map([
73696
73899
  [CONNECTOR_RELAY_CLOSE.replaced.code, "another relay for this server took over"]
73697
73900
  ]);
73698
73901
  function mcpRelaysPathOf({ context }) {
73699
- return join8(dirname6(context.environment.configPath), "connect", "mcp-relays.json");
73902
+ return join9(dirname7(context.environment.configPath), "connect", "mcp-relays.json");
73700
73903
  }
73701
73904
  async function readMcpRelays({ context }) {
73702
73905
  return await readStateJson({ path: mcpRelaysPathOf({ context }) }) ?? {};
@@ -73856,7 +74059,7 @@ var McpRelayLoops = class _McpRelayLoops {
73856
74059
  };
73857
74060
 
73858
74061
  // src/services/openclaw-relay.service.ts
73859
- import { dirname as dirname7, join as join9 } from "node:path";
74062
+ import { dirname as dirname8, join as join10 } from "node:path";
73860
74063
 
73861
74064
  // ../../modules/openclaw/contract/src/openclaw.ts
73862
74065
  var workspaceIdSchema18 = external_exports.string().min(1);
@@ -74077,7 +74280,7 @@ var STOPS2 = /* @__PURE__ */ new Map([
74077
74280
  [OPENCLAW_RELAY_CLOSE.replaced.code, "another relay for this gateway took over"]
74078
74281
  ]);
74079
74282
  function relaysPathOf({ context }) {
74080
- return join9(dirname7(context.environment.configPath), "connect", "openclaw-relays.json");
74283
+ return join10(dirname8(context.environment.configPath), "connect", "openclaw-relays.json");
74081
74284
  }
74082
74285
  async function readRelays({ context }) {
74083
74286
  return await readStateJson({ path: relaysPathOf({ context }) }) ?? {};
@@ -74269,12 +74472,8 @@ var RelayLoops = class _RelayLoops {
74269
74472
  }
74270
74473
  };
74271
74474
 
74272
- // src/services/rush-listeners.service.ts
74273
- import { readdir as readdir3, stat as stat4 } from "node:fs/promises";
74274
- import { dirname as dirname9, join as join11 } from "node:path";
74275
-
74276
74475
  // src/services/rush-host.service.ts
74277
- import { dirname as dirname8, join as join10 } from "node:path";
74476
+ import { dirname as dirname9, join as join11 } from "node:path";
74278
74477
  async function rushAboveOf({
74279
74478
  context,
74280
74479
  from = context.processes.pid
@@ -74288,7 +74487,7 @@ async function rushAboveOf({
74288
74487
  return void 0;
74289
74488
  }
74290
74489
  function guardPathOf({ context, claudePid }) {
74291
- return join10(dirname8(context.environment.configPath), "rush-guards", `${claudePid}.json`);
74490
+ return join11(dirname9(context.environment.configPath), "rush-guards", `${claudePid}.json`);
74292
74491
  }
74293
74492
  async function startRushGuard({
74294
74493
  context,
@@ -74301,7 +74500,7 @@ async function startRushGuard({
74301
74500
  if (holder && context.processes.alive(holder.pid)) return;
74302
74501
  const flags2 = ["--profile", profile, "--claude-pid", String(claudePid), "--rush-id", rush.id];
74303
74502
  const argv = [...context.program, "hook", "rush-wake", ...flags2, "--rush-program", rush.program];
74304
- const logPath = join10(dirname8(context.environment.configPath), "rush-guards", "guard.log");
74503
+ const logPath = join11(dirname9(context.environment.configPath), "rush-guards", "guard.log");
74305
74504
  context.processes.spawnDetached({ argv: ["sh", "-c", '"$@" &', "sh", ...argv], logPath });
74306
74505
  }
74307
74506
  async function claimRushGuard({
@@ -74329,22 +74528,11 @@ async function jsonOf(path) {
74329
74528
  return readStateJson({ path });
74330
74529
  }
74331
74530
  async function notesOf({ context }) {
74332
- const folder = dirname9(statePathOf({ context, kind: "sessions", profile: "x" }));
74333
- const files2 = await readdir3(folder).catch(() => []);
74334
- const notes = await Promise.all(
74335
- files2.map(async (file4) => {
74336
- const pid = Number(file4.replace(/\.json$/, ""));
74337
- const note = await jsonOf(join11(folder, file4));
74338
- const at = await stat4(join11(folder, file4)).then(
74339
- (info) => info.mtimeMs,
74340
- () => 0
74341
- );
74342
- if (!pid || !note) return [];
74343
- const { launch = {}, ...session } = note;
74344
- return [{ pid, key: sessionKeyOf({ session }), at, session, launch }];
74345
- })
74346
- );
74347
- return notes.flat().toSorted((a, b) => b.at - a.at);
74531
+ const { notes } = await sessionNotesOf({ context });
74532
+ return notes.map(({ pid, note, standing }) => {
74533
+ const { launch = {}, process: _process, ...session } = note;
74534
+ return { pid, key: sessionKeyOf({ session }), session, launch, gone: standing === "gone" };
74535
+ });
74348
74536
  }
74349
74537
  async function rushListenersOf({
74350
74538
  context
@@ -74362,25 +74550,39 @@ async function rushListenersOf({
74362
74550
  for (const [key, profile] of bound) {
74363
74551
  const one = sessions.find((each) => `claude-code:${each.sessionId}` === key);
74364
74552
  if (!one?.id) continue;
74553
+ const entry = config2.profiles[profile];
74554
+ const refused = entry ? refusedRecently({ profile: entry, nowMs: context.nowMs() }) : false;
74365
74555
  const own2 = notes.filter((note) => note.key === key);
74366
- const pids = own2.map((note) => note.pid);
74367
- const listenerPid = await listenerOf({ context, key, profile, pids });
74368
- const waiterPid = await waiterOf({ context, key, profile });
74369
- const lastClaudePid = pids.find((pid) => !context.processes.alive(pid));
74370
- const newest = own2[0];
74371
- rows.push({
74372
- profile,
74373
- rushId: one.id,
74374
- key,
74375
- standing: rushStandingOf({ one }),
74376
- ...listenerPid ? { listenerPid } : {},
74377
- ...waiterPid ? { waiterPid } : {},
74378
- ...lastClaudePid ? { lastClaudePid } : {},
74379
- ...newest ? { noted: { session: newest.session, launch: newest.launch } } : {}
74380
- });
74556
+ rows.push(await rowOf({ context, key, profile, rushId: one.id, one, own: own2, refused }));
74381
74557
  }
74382
74558
  return rows;
74383
74559
  }
74560
+ async function rowOf({
74561
+ context,
74562
+ key,
74563
+ profile,
74564
+ rushId,
74565
+ one,
74566
+ own: own2,
74567
+ refused
74568
+ }) {
74569
+ const pids = own2.map((note) => note.pid);
74570
+ const listenerPid = await listenerOf({ context, key, profile, pids });
74571
+ const waiterPid = await waiterOf({ context, key, profile });
74572
+ const lastClaudePid = own2.find((note) => note.gone)?.pid;
74573
+ const newest = own2[0];
74574
+ return {
74575
+ profile,
74576
+ rushId,
74577
+ key,
74578
+ standing: rushStandingOf({ one }),
74579
+ ...listenerPid ? { listenerPid } : {},
74580
+ ...waiterPid ? { waiterPid } : {},
74581
+ ...lastClaudePid ? { lastClaudePid } : {},
74582
+ ...newest ? { noted: { session: newest.session, launch: newest.launch } } : {},
74583
+ ...refused ? { refused: true } : {}
74584
+ };
74585
+ }
74384
74586
  async function listenerOf({
74385
74587
  context,
74386
74588
  key,
@@ -74406,7 +74608,7 @@ async function waiterOf({
74406
74608
  async function rearmRushGuards({ context }) {
74407
74609
  let started = 0;
74408
74610
  for (const row of await rushListenersOf({ context })) {
74409
- if (row.standing !== "asleep" || row.listenerPid || !row.lastClaudePid) continue;
74611
+ if (row.standing !== "asleep" || row.listenerPid || !row.lastClaudePid || row.refused) continue;
74410
74612
  const rush = { id: row.rushId, program: "rush" };
74411
74613
  await startRushGuard({ context, profile: row.profile, claudePid: row.lastClaudePid, rush });
74412
74614
  started += 1;
@@ -74423,17 +74625,24 @@ function clientOf({ context, profile }) {
74423
74625
  return context.store.read().then((config2) => {
74424
74626
  const entry = config2.profiles[profile];
74425
74627
  if (!entry || entry.migrated) return void 0;
74628
+ if (refusedRecently({ profile: entry, nowMs: context.nowMs() })) return void 0;
74426
74629
  return LazeClient.create({
74427
74630
  baseUrl: entry.url,
74428
74631
  token: entry.token,
74429
74632
  fetcher: (input2, init) => context.fetcher(input2, { ...init, signal: AbortSignal.timeout(CHECK_TIMEOUT_MS) }),
74430
- onMigrated: markMigratedOn({ context, profile })
74633
+ onMigrated: markMigratedOn({ context, profile }),
74634
+ onRefused: markRefusedOn({ context, profile, token: entry.token })
74431
74635
  });
74432
74636
  });
74433
74637
  }
74434
- async function waitingOf({ context, profile }) {
74638
+ async function waitingOf({
74639
+ context,
74640
+ profile
74641
+ }) {
74435
74642
  const client = await clientOf({ context, profile });
74436
- return client?.get("/api/agents/me/inbox/waiting").catch(() => void 0);
74643
+ return client?.get("/api/agents/me/inbox/waiting").catch(
74644
+ (error63) => error63 instanceof LazeApiError && error63.status === 401 ? "refused" : void 0
74645
+ );
74437
74646
  }
74438
74647
  function waitedMsOf({ waiting, nowMs: nowMs2 }) {
74439
74648
  if (waiting.count === 0 || !waiting.oldestPostedAt) return 0;
@@ -74637,7 +74846,8 @@ async function serveAgent({
74637
74846
  baseUrl: entry.url,
74638
74847
  token: entry.token,
74639
74848
  fetcher: context.fetcher,
74640
- onMigrated: markMigratedOn({ context, profile })
74849
+ onMigrated: markMigratedOn({ context, profile }),
74850
+ onRefused: markRefusedOn({ context, profile, token: entry.token })
74641
74851
  });
74642
74852
  const watch = CodexTurnWatch.create({ context, client, profile, delivery: entry.delivery });
74643
74853
  const ended = new AbortController();
@@ -74795,7 +75005,7 @@ async function runConnectLoop({ context }) {
74795
75005
  await mcpRelays.stopAll();
74796
75006
  for (const current3 of run4.served.values()) current3.stop.abort();
74797
75007
  await Promise.all([...run4.served.values()].map((current3) => current3.done));
74798
- if (await holdsLock(run4)) await rm3(run4.path, { force: true });
75008
+ if (await holdsLock(run4)) await rm4(run4.path, { force: true });
74799
75009
  }
74800
75010
  return 0;
74801
75011
  }
@@ -74958,11 +75168,8 @@ async function status2({ context }) {
74958
75168
  }
74959
75169
  for (const line of await mcpRelayLinesOf({ context })) context.out(`${line}
74960
75170
  `);
74961
- for (const row of await rushListenersOf({ context })) {
74962
- const waiting = await waitingOf({ context, profile: row.profile });
74963
- context.out(`${rushLineOf({ row })}${inLazeOf({ row, waiting, nowMs: context.nowMs() })}
75171
+ for (const line of await rushLinesOf({ context })) context.out(`${line}
74964
75172
  `);
74965
- }
74966
75173
  const config2 = await context.store.read();
74967
75174
  const linked = Object.entries(config2.profiles).filter(([, profile]) => profile.delivery);
74968
75175
  if (linked.length === 0) context.out("No Codex agent is linked on this machine.\n");
@@ -74982,6 +75189,20 @@ async function mcpRelayLinesOf({ context }) {
74982
75189
  return `${connectionId} ${relay2.label} ${targetLineOf({ target: relay2.target })} ${state}`;
74983
75190
  });
74984
75191
  }
75192
+ async function rushLinesOf({ context }) {
75193
+ const lines2 = [...(await sessionNotesOf({ context, tell: false })).dropped];
75194
+ const refused = /* @__PURE__ */ new Set();
75195
+ for (const row of await rushListenersOf({ context })) {
75196
+ if (refused.has(row.profile)) continue;
75197
+ const waiting = row.refused ? "refused" : await waitingOf({ context, profile: row.profile });
75198
+ if (waiting === "refused") {
75199
+ refused.add(row.profile);
75200
+ lines2.push(revokedKeyLineOf({ profile: row.profile }));
75201
+ } else
75202
+ lines2.push(`${rushLineOf({ row })}${inLazeOf({ row, waiting, nowMs: context.nowMs() })}`);
75203
+ }
75204
+ return lines2;
75205
+ }
74985
75206
  function rushLineOf({ row }) {
74986
75207
  const head = `${row.profile} Claude Code in rush ${row.rushId} ${row.standing}`;
74987
75208
  if (row.standing === "awake" && row.waiterPid) {
@@ -75033,11 +75254,11 @@ async function uninstall({ context }) {
75033
75254
  command: ["systemctl", "--user", "disable", `${installed.name}.service`]
75034
75255
  });
75035
75256
  }
75036
- if (installed.file) await rm4(installed.file, { force: true });
75257
+ if (installed.file) await rm5(installed.file, { force: true });
75037
75258
  if (installed.manager === "systemd") {
75038
75259
  await run({ context, command: ["systemctl", "--user", "daemon-reload"] });
75039
75260
  }
75040
- await rm4(path, { force: true });
75261
+ await rm5(path, { force: true });
75041
75262
  context.out(
75042
75263
  `Removed the connect service (${installed.manager}, ${installed.name}). Linked Codex agents get no messages until \`laze connect install\`.
75043
75264
  `
@@ -75231,7 +75452,7 @@ async function waitForMessages({ context, args }) {
75231
75452
  return 0;
75232
75453
  } finally {
75233
75454
  if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
75234
- await rm5(lock, { force: true });
75455
+ await rm6(lock, { force: true });
75235
75456
  }
75236
75457
  }
75237
75458
  async function healRushDelivery({ context }) {
@@ -75255,6 +75476,7 @@ async function waitHook({ context, args }) {
75255
75476
  `);
75256
75477
  return 2;
75257
75478
  }
75479
+ if (error63 instanceof LazeApiError && error63.status === 401) return 0;
75258
75480
  context.err(`laze: the background waiter stopped: ${String(error63)}
75259
75481
  `);
75260
75482
  return 0;
@@ -75272,13 +75494,13 @@ async function monitorServes({
75272
75494
 
75273
75495
  // src/services/codex-link.service.ts
75274
75496
  import { createReadStream } from "node:fs";
75275
- import { readdir as readdir5, rm as rm7, stat as stat7 } from "node:fs/promises";
75497
+ import { readdir as readdir5, rm as rm8, stat as stat7 } from "node:fs/promises";
75276
75498
  import { join as join16, resolve as resolve4 } from "node:path";
75277
75499
  import { createInterface as createInterface2 } from "node:readline";
75278
75500
 
75279
75501
  // src/services/codex-adopt.service.ts
75280
75502
  import { spawn as spawn2 } from "node:child_process";
75281
- import { readdir as readdir4, rm as rm6, stat as stat6 } from "node:fs/promises";
75503
+ import { readdir as readdir4, rm as rm7, stat as stat6 } from "node:fs/promises";
75282
75504
  import { join as join15 } from "node:path";
75283
75505
  import { createInterface } from "node:readline";
75284
75506
 
@@ -75556,7 +75778,7 @@ Log: ${record4.log}
75556
75778
  async function adoptStop({ context, profile }) {
75557
75779
  const path = statePathOf({ context, kind: "adopt", profile });
75558
75780
  const record4 = await recordOf({ path });
75559
- await rm6(path, { force: true });
75781
+ await rm7(path, { force: true });
75560
75782
  if (!record4 || !context.processes.stop(record4.pid)) {
75561
75783
  context.out(`laze adopt codex was not running in the background for profile "${profile}".
75562
75784
  `);
@@ -75701,7 +75923,7 @@ async function stopAdopt({ context, profile }) {
75701
75923
  const running = await readJson({ path });
75702
75924
  if (!running) return;
75703
75925
  context.processes.stop(running.pid);
75704
- await rm7(path, { force: true });
75926
+ await rm8(path, { force: true });
75705
75927
  }
75706
75928
  async function linkCodexSession({
75707
75929
  context,
@@ -75740,7 +75962,7 @@ async function linkCodexSession({
75740
75962
  }
75741
75963
 
75742
75964
  // src/services/laze-plugin.service.ts
75743
- import { mkdir as mkdir4, readFile as readFile9, rm as rm8, writeFile as writeFile2 } from "node:fs/promises";
75965
+ import { mkdir as mkdir4, readFile as readFile9, rm as rm9, writeFile as writeFile2 } from "node:fs/promises";
75744
75966
  import { homedir as homedir4 } from "node:os";
75745
75967
  import { dirname as dirname13, join as join18 } from "node:path";
75746
75968
 
@@ -75879,7 +76101,9 @@ guide first: https://laze.so/docs/agents/apps.md. The short version:
75879
76101
  an attachment means exactly that: do it, do not ask.
75880
76102
  - Slides, a deck or a talk: start from \`laze app create <name> --template slides\`. Each slide
75881
76103
  is a file in slides/, listed in order in slides/deck.json; the deck presents full screen and
75882
- exports PDF and HTML on its own.
76104
+ exports PDF and HTML on its own. Write only \`slides/NN-name.html\` (one \`<section>\` each) and
76105
+ \`slides/deck.json\`; never read or change \`deck.js\` or \`index.html\`. Do it yourself in one
76106
+ turn, with no subagent. README.md lists the classes; \`laze app serve\` shows slide N at \`#N\`.
75883
76107
  An app that already exists goes in with \`laze app pin <app> --channel <channel>\`, never as a
75884
76108
  pinned message with a link. A pin opens it to everyone there, and their agents may build on it.
75885
76109
  - A new app is Restricted. Do not share it with only the person who asked when they asked in a
@@ -75893,8 +76117,8 @@ guide first: https://laze.so/docs/agents/apps.md. The short version:
75893
76117
  - Use the Laze kit's classes and colour tokens; never hex colours or a copied kit. One job per
75894
76118
  screen; tables, cards, stat tiles, charts and numbered steps over paragraphs; real data; an
75895
76119
  empty state; it must read well in dark mode and 390 px wide.
75896
- - Before you push, run \`laze app serve\` and screenshot it light, dark (\`?theme=dark\`) and
75897
- 390 px wide. Fix what looks off, then push and say in one line what the app does.
76120
+ - Before you push an app (not a deck), run \`laze app serve\` and screenshot it light, dark
76121
+ (\`?theme=dark\`) and 390 px wide. Fix what looks off, then push and say in one line what the app does.
75898
76122
 
75899
76123
  ## When Laze refused something
75900
76124
 
@@ -76108,7 +76332,7 @@ async function plugin({ context, args }) {
76108
76332
  if (action === "uninstall") {
76109
76333
  const name3 = pluginNameHere({ context });
76110
76334
  const removed = await unregisterAs({ context, name: name3 });
76111
- await rm8(registeredMarkOf({ context }), { force: true });
76335
+ await rm9(registeredMarkOf({ context }), { force: true });
76112
76336
  context.out(
76113
76337
  removed ? `Removed the Laze plugin ${name3}@${name3} from Claude Code.
76114
76338
  ` : `Claude Code did not remove it; run: claude plugin uninstall ${name3}@${name3} && claude plugin marketplace remove ${name3}
@@ -76129,8 +76353,28 @@ async function plugin({ context, args }) {
76129
76353
  return 0;
76130
76354
  }
76131
76355
 
76356
+ // src/services/link-listener.service.ts
76357
+ async function listenAfterLink({
76358
+ context,
76359
+ args,
76360
+ profile,
76361
+ claudePid
76362
+ }) {
76363
+ if (!claudePid) return;
76364
+ const parent = await context.processes.parentOf(claudePid) ?? 0;
76365
+ const rush = rushSessionOf({ parentArgs: await context.processes.argsOf(parent) });
76366
+ if (!rush) return;
76367
+ const session = await currentSessionOf({ context, args });
76368
+ await rememberSession({ context, claudePid, session });
76369
+ await startRushGuard({ context, profile, claudePid, rush });
76370
+ await ensureConnectService({ context }).catch((error63) => {
76371
+ context.err(`laze: could not start the connect service: ${String(error63)}
76372
+ `);
76373
+ });
76374
+ }
76375
+
76132
76376
  // src/services/mcp-channel.service.ts
76133
- import { rm as rm9 } from "node:fs/promises";
76377
+ import { rm as rm10 } from "node:fs/promises";
76134
76378
  var LAZE_MCP_SERVER = "laze";
76135
76379
  var DEV_CHANNELS_FLAG = "--dangerously-load-development-channels";
76136
76380
  var ROUND_SECONDS3 = 50;
@@ -76249,7 +76493,7 @@ async function pushInbox({
76249
76493
  `);
76250
76494
  }
76251
76495
  } finally {
76252
- await rm9(marker, { force: true });
76496
+ await rm10(marker, { force: true });
76253
76497
  }
76254
76498
  }
76255
76499
 
@@ -76354,9 +76598,6 @@ async function harnessOf2({ context, args }) {
76354
76598
  const nearest = await nearestHarnessOf({ context });
76355
76599
  return nearest ?? { harness: context.environment.harness, pid: void 0 };
76356
76600
  }
76357
- function slugOf(name3) {
76358
- return name3.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "agent";
76359
- }
76360
76601
  function settingsOf({ path, text: text3 }) {
76361
76602
  try {
76362
76603
  return JSON.parse(text3);
@@ -76524,6 +76765,7 @@ async function settleLinked({
76524
76765
  }
76525
76766
  const hooked = claude && !args.flags["no-hook"];
76526
76767
  const hookPath = hooked ? await installHooks({ context, directory, profile: name3 }) : void 0;
76768
+ if (hooked) await listenAfterLink({ context, args, profile: name3, claudePid: pid });
76527
76769
  const laze = lazeCommandOf({ program: context.program });
76528
76770
  const steps = await nextStepsFor({
76529
76771
  context,
@@ -76545,21 +76787,6 @@ async function settleLinked({
76545
76787
  );
76546
76788
  return name3;
76547
76789
  }
76548
- function linkedProfileNameOf({
76549
- args,
76550
- linked,
76551
- profiles: profiles2
76552
- }) {
76553
- const wanted = flagText({ args, name: "profile" }) || `agent-${slugOf(linked.agent.name)}`;
76554
- const free = (name3) => {
76555
- const held = profiles2[name3];
76556
- return !held || held.kind === "agent" && held.agentId === linked.agent.id;
76557
- };
76558
- if (free(wanted)) return wanted;
76559
- for (let number4 = 2; ; number4 += 1) {
76560
- if (free(`${wanted}-${number4}`)) return `${wanted}-${number4}`;
76561
- }
76562
- }
76563
76790
  function requestProfileNameOf({ profile }) {
76564
76791
  return `${profile}-request`;
76565
76792
  }
@@ -76799,11 +77026,6 @@ function formatPools({ pools, nowMs: nowMs2 }) {
76799
77026
  return `${pools.pools.map((pool) => formatPool({ pool, nowMs: nowMs2 })).join("\n\n")}
76800
77027
  `;
76801
77028
  }
76802
- function refusalLine({ code, message: message2 }) {
76803
- const sentence = message2.trim().replace(/[.!]*$/, ".");
76804
- return `laze: ${code}: ${sentence}
76805
- `;
76806
- }
76807
77029
  var SWITCH_REASONS = {
76808
77030
  out_of_usage: "out of usage",
76809
77031
  login_removed: "login removed",
@@ -77836,7 +78058,7 @@ async function uploadParts({
77836
78058
  await client.put(`/api/agents/me/migrations/${migrationId}/parts/${index}`, { text: text3 });
77837
78059
  } catch (error63) {
77838
78060
  if (migratedNoticeOf(error63)) throw error63;
77839
- const why = error63 instanceof Error ? error63.message : String(error63);
78061
+ const why = whyOf(error63);
77840
78062
  throw new CliUsageError(
77841
78063
  `Part ${index + 1} of ${upload.parts.length} did not upload (${why}). Nothing moved yet: run \`${again}\` again.`
77842
78064
  );
@@ -77927,6 +78149,10 @@ async function agentMigrate({ context, args }) {
77927
78149
  if (sub || !args.words[2]) throw new CliUsageError(`Usage: ${MIGRATE_USAGE}`);
77928
78150
  return migrate({ context, args });
77929
78151
  }
78152
+ function whyOf(error63) {
78153
+ if (error63 instanceof LazeApiError) return refusalText(error63);
78154
+ return error63 instanceof Error ? error63.message : String(error63);
78155
+ }
77930
78156
 
77931
78157
  // src/services/agent-session-commands.service.ts
77932
78158
  var NO_SESSION = "Run this inside the Claude Code or Codex session the agent should listen in, or pass --session <id>.";
@@ -80566,7 +80792,7 @@ async function appPinsCommand({
80566
80792
 
80567
80793
  // src/services/app-script-check.service.ts
80568
80794
  import { execFile } from "node:child_process";
80569
- import { mkdtemp, rm as rm10, writeFile as writeFile4 } from "node:fs/promises";
80795
+ import { mkdtemp, rm as rm11, writeFile as writeFile4 } from "node:fs/promises";
80570
80796
  import { tmpdir } from "node:os";
80571
80797
  import { join as join21 } from "node:path";
80572
80798
  import { promisify } from "node:util";
@@ -80614,7 +80840,7 @@ async function scriptErrorsOf({
80614
80840
  );
80615
80841
  return [...errors.filter((error63) => error63 !== null), ...unknown2];
80616
80842
  } finally {
80617
- await rm10(dir, { recursive: true, force: true });
80843
+ await rm11(dir, { recursive: true, force: true });
80618
80844
  }
80619
80845
  }
80620
80846
 
@@ -81052,7 +81278,8 @@ var appCreate = async ({ context, args }) => {
81052
81278
  value: { app: app2, folder },
81053
81279
  text: start2 ? `Created ${app2.name} (${app2.id}) from the ${template} template in ${where}; its first version is live at ${app2.publishedUrl}.
81054
81280
  Next: change the files in ${where} (start with README.md when there is one), then laze app push -m "<what changed>"
81055
- ` : `Created ${app2.name} (${app2.id}) in ${where}.
81281
+ ` + (start2.template.guide ? `${start2.template.guide}
81282
+ ` : "") : `Created ${app2.name} (${app2.id}) in ${where}.
81056
81283
  Next: cd ${where} && laze app push -m "First version" --seed
81057
81284
  `
81058
81285
  });
@@ -82542,7 +82769,7 @@ function loginValuesOf({
82542
82769
 
82543
82770
  // src/services/vault-commands.service.ts
82544
82771
  import { createHash as createHash6 } from "node:crypto";
82545
- import { readFile as readFile16, rm as rm11 } from "node:fs/promises";
82772
+ import { readFile as readFile16, rm as rm12 } from "node:fs/promises";
82546
82773
  import { hostname as hostname7, tmpdir as tmpdir2 } from "node:os";
82547
82774
  import { dirname as dirname15, join as join24 } from "node:path";
82548
82775
 
@@ -82795,13 +83022,13 @@ async function settled({
82795
83022
  }) {
82796
83023
  if (release2 === "capped") return { exitCode: 75 };
82797
83024
  if (release2.outcome === "deny") {
82798
- await rm11(keyPath, { force: true });
83025
+ await rm12(keyPath, { force: true });
82799
83026
  context.err(`${release2.message}
82800
83027
  `);
82801
83028
  return { exitCode: release2.exitCode || 1 };
82802
83029
  }
82803
83030
  const values = await envOf({ release: release2, run: run4 });
82804
- if (!leaseHolds({ release: release2, nowMs: context.nowMs() })) await rm11(keyPath, { force: true });
83031
+ if (!leaseHolds({ release: release2, nowMs: context.nowMs() })) await rm12(keyPath, { force: true });
82805
83032
  if (release2.message) context.err(`${release2.message}
82806
83033
  `);
82807
83034
  return { env: values };
@@ -82811,7 +83038,7 @@ function refusedRelease(error63) {
82811
83038
  return {
82812
83039
  outcome: "deny",
82813
83040
  exitCode: 1,
82814
- message: `laze vault: the release was refused: ${error63.message} (${error63.code})`
83041
+ message: `laze vault: the release was refused: ${refusalText(error63)}`
82815
83042
  };
82816
83043
  }
82817
83044
  var WHERE = "works only on a Laze agent's computer, on a machine it runs on, or signed in with `laze login` (as yourself or as a connected agent)";
@@ -83975,8 +84202,7 @@ async function changing({
83975
84202
  } catch (error63) {
83976
84203
  const refused = error63 instanceof LazeApiError && profile.kind === "agent" && ["agent_restricted", "permission_denied", "channel_admin_required"].includes(error63.code);
83977
84204
  if (!refused) throw error63;
83978
- context.err(`laze: ${error63.message} (${error63.code})
83979
- ${AGENT_HINT}`);
84205
+ context.err(`${refusalLine(error63)}${AGENT_HINT}`);
83980
84206
  return 1;
83981
84207
  }
83982
84208
  }
@@ -84138,8 +84364,7 @@ async function changing2({
84138
84364
  } catch (error63) {
84139
84365
  const refused = error63 instanceof LazeApiError && profile.kind === "agent" && ["agent_restricted", "permission_denied", "channel_admin_required"].includes(error63.code);
84140
84366
  if (!refused) throw error63;
84141
- context.err(`laze: ${error63.message} (${error63.code})
84142
- ${AGENT_HINT2}`);
84367
+ context.err(`${refusalLine(error63)}${AGENT_HINT2}`);
84143
84368
  return 1;
84144
84369
  }
84145
84370
  }
@@ -84434,7 +84659,7 @@ import { basename as basename8, isAbsolute as isAbsolute2, relative as relative4
84434
84659
 
84435
84660
  // src/services/file-download.service.ts
84436
84661
  import { createWriteStream } from "node:fs";
84437
- import { mkdir as mkdir8, rename as rename3, rm as rm12, stat as stat10, truncate } from "node:fs/promises";
84662
+ import { mkdir as mkdir8, rename as rename3, rm as rm13, stat as stat10, truncate } from "node:fs/promises";
84438
84663
  import { basename as basename7, dirname as dirname17, resolve as resolve9 } from "node:path";
84439
84664
  import { Readable, Transform } from "node:stream";
84440
84665
  import { pipeline } from "node:stream/promises";
@@ -84559,7 +84784,7 @@ async function downloadFile({
84559
84784
  await mkdir8(dirname17(part), { recursive: true });
84560
84785
  const named = await fetchWhole({ context, client, attachmentId, part, out }).catch(
84561
84786
  async (error63) => {
84562
- await rm12(part, { force: true });
84787
+ await rm13(part, { force: true });
84563
84788
  if (!isDiskError(error63)) throw error63;
84564
84789
  throw new CliUsageError(`Could not write ${attachmentId} to disk: ${String(error63)}`);
84565
84790
  }
@@ -85011,7 +85236,7 @@ async function chatActions({
85011
85236
  }
85012
85237
 
85013
85238
  // src/services/claude-monitor.service.ts
85014
- import { rm as rm13 } from "node:fs/promises";
85239
+ import { rm as rm14 } from "node:fs/promises";
85015
85240
  var MONITOR_IDLE_MS = 3e4;
85016
85241
  var MONITOR_OUTRANKED_MS = 3e3;
85017
85242
  async function deliverOnce({
@@ -85079,7 +85304,7 @@ async function monitorRound(turn) {
85079
85304
  async function release({ context, profile }) {
85080
85305
  const lock = statePathOf({ context, kind: "waiters", profile });
85081
85306
  if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
85082
- await rm13(lock, { force: true });
85307
+ await rm14(lock, { force: true });
85083
85308
  }
85084
85309
  async function monitorHook({ context, args }) {
85085
85310
  const claudePid = await claudePidOf({ context });
@@ -86588,7 +86813,13 @@ var whatsappChangeDefinition = external_exports.object({
86588
86813
  /** Fetched with a "media" request while the store is open; absent from older connectors. */
86589
86814
  media: whatsappChangeMediaDefinition.optional(),
86590
86815
  /** The chat's other ids, such as the hidden id it was first seen under; new in Nov 2026. */
86591
- aliases: external_exports.array(external_exports.string().min(1).max(200)).max(16).optional()
86816
+ aliases: external_exports.array(external_exports.string().min(1).max(200)).max(16).optional(),
86817
+ /** The message this one replies to, its sender's name and text; absent from older connectors. */
86818
+ quote: external_exports.object({
86819
+ id: external_exports.string().min(1).max(200),
86820
+ sender: external_exports.string().max(500),
86821
+ text: external_exports.string().max(1e3)
86822
+ }).optional()
86592
86823
  });
86593
86824
  var whatsappReadDefinition = external_exports.object({
86594
86825
  chat: external_exports.string().min(1).max(200),
@@ -87111,7 +87342,7 @@ var restSettleComputerCopyInputDefinition = settleComputerCopyInputDefinition.om
87111
87342
  });
87112
87343
 
87113
87344
  // src/services/computer-copy-commands.service.ts
87114
- import { mkdtemp as mkdtemp2, open as open5, rm as rm14, stat as stat11 } from "node:fs/promises";
87345
+ import { mkdtemp as mkdtemp2, open as open5, rm as rm15, stat as stat11 } from "node:fs/promises";
87115
87346
  import { tmpdir as tmpdir4 } from "node:os";
87116
87347
  import { basename as basename9, dirname as dirname18, resolve as resolve11 } from "node:path";
87117
87348
  var COMPUTER_COPY_USAGE = ` laze computer copy <path> --agent <agent> [--to <folder>] [--json]
@@ -87212,7 +87443,7 @@ It lands before ${done.agentName}'s next turn.
87212
87443
  `
87213
87444
  );
87214
87445
  } finally {
87215
- await rm14(dir, { recursive: true, force: true });
87446
+ await rm15(dir, { recursive: true, force: true });
87216
87447
  }
87217
87448
  }
87218
87449
 
@@ -92596,8 +92827,7 @@ async function history2({
92596
92827
  `);
92597
92828
  } else context.out(formatHistory(output2));
92598
92829
  if (!refused) return void 0;
92599
- context.err(`laze: ${refused.message} (${refused.code})
92600
- `);
92830
+ context.err(refusalLine(refused));
92601
92831
  return 1;
92602
92832
  }
92603
92833
 
@@ -92862,7 +93092,7 @@ async function ip({ context, args }) {
92862
93092
  }
92863
93093
 
92864
93094
  // src/services/join-commands.service.ts
92865
- import { rm as rm15 } from "node:fs/promises";
93095
+ import { rm as rm16 } from "node:fs/promises";
92866
93096
  import { dirname as dirname19, join as join28 } from "node:path";
92867
93097
  var DEFAULT_WAIT_SECONDS2 = 100;
92868
93098
  var JOIN_USAGE = "Usage: laze join [--workspace <name|id|invite link>] [--for <email>] [--name <name>] [--note <text>] [--timeout <seconds>] [--project <folder>]";
@@ -92883,7 +93113,7 @@ async function keepPending({ context, pending: pending2 }) {
92883
93113
  await writeStateJson({ path: pendingPathOf({ context }), value: pending2 });
92884
93114
  }
92885
93115
  async function dropPending({ context }) {
92886
- await rm15(pendingPathOf({ context }), { force: true });
93116
+ await rm16(pendingPathOf({ context }), { force: true });
92887
93117
  }
92888
93118
  function waitSecondsOf3({ args }) {
92889
93119
  const raw = flagText({ args, name: "timeout" });
@@ -94021,7 +94251,7 @@ import { readdir as readdir7, readFile as readFile29 } from "node:fs/promises";
94021
94251
  import { join as join29, resolve as resolve19 } from "node:path";
94022
94252
 
94023
94253
  // src/services/mount-files.service.ts
94024
- import { mkdir as mkdir10, readFile as readFile28, rm as rm16, writeFile as writeFile8 } from "node:fs/promises";
94254
+ import { mkdir as mkdir10, readFile as readFile28, rm as rm17, writeFile as writeFile8 } from "node:fs/promises";
94025
94255
  import { dirname as dirname20, relative as relative5, resolve as resolve18 } from "node:path";
94026
94256
  async function textArgument({
94027
94257
  context,
@@ -94041,7 +94271,7 @@ async function writeMount({
94041
94271
  files: files2
94042
94272
  }) {
94043
94273
  const root = resolve18(context.cwd, flagText({ args, name: "dir", fallback: ".laze" }), folder);
94044
- await rm16(root, { recursive: true, force: true });
94274
+ await rm17(root, { recursive: true, force: true });
94045
94275
  await mkdir10(root, { recursive: true });
94046
94276
  for (const file4 of files2) {
94047
94277
  const target = resolve18(root, file4.path);
@@ -94906,7 +95136,7 @@ async function openclaw({
94906
95136
 
94907
95137
  // src/services/operator-key-commands.service.ts
94908
95138
  import { createHash as createHash7, randomBytes as randomBytes4 } from "node:crypto";
94909
- import { mkdir as mkdir11, readFile as readFile30, rm as rm17, writeFile as writeFile9 } from "node:fs/promises";
95139
+ import { mkdir as mkdir11, readFile as readFile30, rm as rm18, writeFile as writeFile9 } from "node:fs/promises";
94910
95140
  import { dirname as dirname21, join as join30 } from "node:path";
94911
95141
 
94912
95142
  // ../../modules/audit-log/contract/src/audit-log.api.ts
@@ -96344,7 +96574,7 @@ async function forgetIfOver({
96344
96574
  const key = await client.post(OPERATOR_KEY_REST_PATHS.status, { keyId });
96345
96575
  const windowOver = key.endsAt !== null && Temporal3.Instant.from(key.endsAt).epochMilliseconds <= context.nowMs();
96346
96576
  if (key.status !== "pending" && (key.status !== "approved" || windowOver || key.spentAt)) {
96347
- await rm17(keyFile({ context, keyId }), { force: true });
96577
+ await rm18(keyFile({ context, keyId }), { force: true });
96348
96578
  }
96349
96579
  return key;
96350
96580
  }
@@ -96610,7 +96840,7 @@ function watchingRelease({
96610
96840
  }
96611
96841
 
96612
96842
  // src/services/rush-guard.service.ts
96613
- import { rm as rm18 } from "node:fs/promises";
96843
+ import { rm as rm19 } from "node:fs/promises";
96614
96844
  var WATCH_MS3 = 2e3;
96615
96845
  var RETRY_MS2 = 3e4;
96616
96846
  async function guardRound(guard) {
@@ -96639,6 +96869,30 @@ async function guardRound(guard) {
96639
96869
  await dropFromSpool({ context, profile: name3, messageIds: messages.map((m) => m.messageId) });
96640
96870
  return true;
96641
96871
  }
96872
+ function afterFailure({ context, error: error63 }) {
96873
+ const migrated = migratedNoticeOf(error63);
96874
+ if (migrated) {
96875
+ context.err(`${migrated.notice}
96876
+ `);
96877
+ return true;
96878
+ }
96879
+ if (error63 instanceof LazeApiError && error63.status === 401) return true;
96880
+ context.err(`laze: the rush guard will try again: ${String(error63)}
96881
+ `);
96882
+ return "failed";
96883
+ }
96884
+ async function guardRounds(guard) {
96885
+ const { context } = guard;
96886
+ const deadline = context.nowMs() + WAIT_HOOK_TIMEOUT_SECONDS * 1e3;
96887
+ while (context.nowMs() < deadline) {
96888
+ const done = await guardRound(guard).catch(
96889
+ (error63) => afterFailure({ context, error: error63 })
96890
+ );
96891
+ if (done === true) return 0;
96892
+ await context.sleep(done === "failed" ? RETRY_MS2 : 1e3);
96893
+ }
96894
+ return 0;
96895
+ }
96642
96896
  function sessionIdOf({ session }) {
96643
96897
  return session ? { sessionId: session.sessionId } : {};
96644
96898
  }
@@ -96650,7 +96904,7 @@ async function rushWakeHook({ context, args }) {
96650
96904
  if (!await claimRushGuard({ context, claudePid })) return 0;
96651
96905
  const path = guardPathOf({ context, claudePid });
96652
96906
  try {
96653
- while (context.processes.alive(claudePid)) await context.sleep(WATCH_MS3);
96907
+ while (await noteProcessRuns({ context, pid: claudePid })) await context.sleep(WATCH_MS3);
96654
96908
  const { client, name: name3 } = await signedIn({ context, args });
96655
96909
  const noted = statePathOf({ context, kind: "sessions", profile: String(claudePid) });
96656
96910
  const note = await readStateJson({ path: noted });
@@ -96659,30 +96913,14 @@ async function rushWakeHook({ context, args }) {
96659
96913
  const rush = { id: id4, program };
96660
96914
  const known = note ? session : void 0;
96661
96915
  const guard = { context, client, name: name3, lock, claudePid, session: known, rush, launch };
96662
- const deadline = context.nowMs() + WAIT_HOOK_TIMEOUT_SECONDS * 1e3;
96663
96916
  try {
96664
- while (context.nowMs() < deadline) {
96665
- const done = await guardRound(guard).catch((error63) => {
96666
- const migrated = migratedNoticeOf(error63);
96667
- if (migrated) {
96668
- context.err(`${migrated.notice}
96669
- `);
96670
- return true;
96671
- }
96672
- context.err(`laze: the rush guard will try again: ${String(error63)}
96673
- `);
96674
- return "failed";
96675
- });
96676
- if (done === true) return 0;
96677
- await context.sleep(done === "failed" ? RETRY_MS2 : 1e3);
96678
- }
96679
- return 0;
96917
+ return await guardRounds(guard);
96680
96918
  } finally {
96681
96919
  if ((await holderOf({ path: lock }))?.pid === context.processes.pid)
96682
- await rm18(lock, { force: true });
96920
+ await rm19(lock, { force: true });
96683
96921
  }
96684
96922
  } finally {
96685
- await rm18(path, { force: true });
96923
+ await rm19(path, { force: true });
96686
96924
  }
96687
96925
  }
96688
96926
 
@@ -97875,7 +98113,7 @@ function credentialProcessJson(fields) {
97875
98113
  }
97876
98114
 
97877
98115
  // src/services/vault-batch.service.ts
97878
- import { rm as rm19 } from "node:fs/promises";
98116
+ import { rm as rm20 } from "node:fs/promises";
97879
98117
  async function batchOf({ response }) {
97880
98118
  const text3 = await response.text();
97881
98119
  if (!response.ok) {
@@ -97942,9 +98180,7 @@ async function doorOf({
97942
98180
  return await client.post(door.ask, { ...body, ...door.extra });
97943
98181
  } catch (error63) {
97944
98182
  if (!(error63 instanceof LazeApiError)) throw error63;
97945
- throw new CliUsageError(
97946
- `laze vault: the batch was refused: ${error63.message} (${error63.code})`
97947
- );
98183
+ throw new CliUsageError(`laze vault: the batch was refused: ${refusalText(error63)}`);
97948
98184
  }
97949
98185
  },
97950
98186
  status: (requestId) => client.post(door.status, { requestId, ...door.extra }).catch(refusedRelease)
@@ -98057,7 +98293,7 @@ async function valuesOf({
98057
98293
  }) {
98058
98294
  const refused = refusalOf({ context, settled: settled2 });
98059
98295
  if (refused !== 0) {
98060
- await rm19(keyPath, { force: true });
98296
+ await rm20(keyPath, { force: true });
98061
98297
  return { exitCode: refused };
98062
98298
  }
98063
98299
  const opened = /* @__PURE__ */ new Map();
@@ -98069,7 +98305,7 @@ async function valuesOf({
98069
98305
  if (release2.message) context.err(`${release2.message}
98070
98306
  `);
98071
98307
  }
98072
- if (!keep2) await rm19(keyPath, { force: true });
98308
+ if (!keep2) await rm20(keyPath, { force: true });
98073
98309
  const released = /* @__PURE__ */ new Map();
98074
98310
  for (const entry of entries) {
98075
98311
  const fields = opened.get(keyOf(entry));
@@ -100023,8 +100259,7 @@ function exitCodeOf({ context, error: error63 }) {
100023
100259
  `);
100024
100260
  else if (error63 instanceof CliUsageError) context.err(`${error63.message}
100025
100261
  `);
100026
- else if (error63 instanceof LazeApiError) context.err(`laze: ${error63.message} (${error63.code})
100027
- `);
100262
+ else if (error63 instanceof LazeApiError) context.err(refusalLine(error63));
100028
100263
  else {
100029
100264
  const unreachable = unreachableReasonOf(error63);
100030
100265
  if (unreachable === void 0) throw error63;
@@ -100043,7 +100278,7 @@ import {
100043
100278
  randomBytes as randomBytes5,
100044
100279
  sign
100045
100280
  } from "node:crypto";
100046
- import { chmod, link, mkdir as mkdir12, readFile as readFile36, rm as rm20, writeFile as writeFile11 } from "node:fs/promises";
100281
+ import { chmod, link, mkdir as mkdir12, readFile as readFile36, rm as rm21, writeFile as writeFile11 } from "node:fs/promises";
100047
100282
  import { dirname as dirname24, join as join34 } from "node:path";
100048
100283
  var KEYCHAIN_SERVICE = "laze-cli-machine-key";
100049
100284
  var runProgram = ({ program, args, stdin: stdin2, timeoutMs }) => new Promise((resolve26, reject) => {
@@ -100155,7 +100390,7 @@ var MachineKeyStore = class _MachineKeyStore {
100155
100390
  return kept;
100156
100391
  }
100157
100392
  async drop({ tier, jwk }) {
100158
- if (tier === "file") return rm20(this.pemPathOf(jwk), { force: true });
100393
+ if (tier === "file") return rm21(this.pemPathOf(jwk), { force: true });
100159
100394
  await this.options.run({
100160
100395
  program: "security",
100161
100396
  args: ["delete-generic-password", "-s", KEYCHAIN_SERVICE, "-a", this.accountOf(jwk)],
@@ -100211,7 +100446,7 @@ async function writeOnce({ path, text: text3 }) {
100211
100446
  if (error63.code === "EEXIST") return false;
100212
100447
  throw error63;
100213
100448
  } finally {
100214
- await rm20(temporary, { force: true });
100449
+ await rm21(temporary, { force: true });
100215
100450
  }
100216
100451
  }
100217
100452
  async function writePrivate({ path, text: text3 }) {
@@ -100272,7 +100507,7 @@ function machineProofFetch({
100272
100507
 
100273
100508
  // src/services/processes.service.ts
100274
100509
  import { execFile as execFile3, spawn as spawn4, spawnSync } from "node:child_process";
100275
- import { closeSync, mkdirSync, openSync } from "node:fs";
100510
+ import { closeSync, mkdirSync, openSync, renameSync, statSync } from "node:fs";
100276
100511
  import { readFile as readFile37, readlink } from "node:fs/promises";
100277
100512
  import { dirname as dirname25 } from "node:path";
100278
100513
  import { promisify as promisify2 } from "node:util";
@@ -100301,6 +100536,13 @@ async function parentOf(pid) {
100301
100536
  const parent = Number(listed?.stdout.trim());
100302
100537
  return parent > 0 ? parent : void 0;
100303
100538
  }
100539
+ async function startOf(pid) {
100540
+ const stat13 = await readFile37(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
100541
+ const ticks = stat13 ? stat13.slice(stat13.lastIndexOf(")") + 2).split(" ")[19] : void 0;
100542
+ if (ticks) return ticks;
100543
+ const listed = await run3("ps", ["-o", "lstart=", "-p", String(pid)]).catch(() => void 0);
100544
+ return listed?.stdout.trim() || void 0;
100545
+ }
100304
100546
  async function cwdOf(pid) {
100305
100547
  const linked = await readlink(`/proc/${pid}/cwd`).catch(() => void 0);
100306
100548
  if (linked) return linked;
@@ -100325,12 +100567,18 @@ function spawnOrphan({ argv, log }) {
100325
100567
  });
100326
100568
  return Number(shell.stdout.trim()) || 0;
100327
100569
  }
100570
+ var LOG_LIMIT_BYTES = 1024 * 1024;
100571
+ function keepLogSmall({ logPath }) {
100572
+ const size = statSync(logPath, { throwIfNoEntry: false })?.size ?? 0;
100573
+ if (size > LOG_LIMIT_BYTES) renameSync(logPath, `${logPath}.1`);
100574
+ }
100328
100575
  function spawnDetached({
100329
100576
  argv,
100330
100577
  logPath,
100331
100578
  orphan = false
100332
100579
  }) {
100333
100580
  mkdirSync(dirname25(logPath), { recursive: true, mode: 448 });
100581
+ keepLogSmall({ logPath });
100334
100582
  const log = openSync(logPath, "a", 384);
100335
100583
  if (orphan) {
100336
100584
  try {
@@ -100354,7 +100602,7 @@ function stop2(pid) {
100354
100602
  return true;
100355
100603
  }
100356
100604
  function nodeProcesses() {
100357
- return { pid: process.pid, alive, argsOf: argsOf2, parentOf, cwdOf, spawnDetached, stop: stop2 };
100605
+ return { pid: process.pid, alive, argsOf: argsOf2, startOf, parentOf, cwdOf, spawnDetached, stop: stop2 };
100358
100606
  }
100359
100607
 
100360
100608
  // src/services/proxied-fetch.service.ts