commonswarm 0.1.49 → 0.1.50

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/cswarm.cjs +263 -147
  2. package/package.json +1 -1
package/cswarm.cjs CHANGED
@@ -21470,6 +21470,14 @@ var MemoryStorage = class {
21470
21470
  this.values.delete(key2);
21471
21471
  }
21472
21472
  };
21473
+ var HumanSessionError = class extends Error {
21474
+ constructor(code, message) {
21475
+ super(message);
21476
+ this.code = code;
21477
+ }
21478
+ code;
21479
+ name = "HumanSessionError";
21480
+ };
21473
21481
  function base64Url(bytes) {
21474
21482
  return bytes.toString("base64url");
21475
21483
  }
@@ -21848,7 +21856,12 @@ async function refreshedCredential(target2, store2) {
21848
21856
  return await store2.withLock(async () => {
21849
21857
  for (let attempt = 0; attempt < 2; attempt += 1) {
21850
21858
  const before = await store2.read();
21851
- if (!before) throw new Error("not logged in; run cswarm login");
21859
+ if (!before) {
21860
+ throw new HumanSessionError(
21861
+ "human_session_missing",
21862
+ "not logged in; run cswarm login"
21863
+ );
21864
+ }
21852
21865
  const memory = new MemoryStorage();
21853
21866
  const client = authClient(target2, memory);
21854
21867
  const refreshed = await client.auth.refreshSession({
@@ -21857,7 +21870,10 @@ async function refreshedCredential(target2, store2) {
21857
21870
  if (refreshed.error) {
21858
21871
  const afterFailure = await store2.read();
21859
21872
  if (afterFailure && afterFailure.generation !== before.generation) continue;
21860
- throw new Error("could not refresh your session; run cswarm login to sign in again");
21873
+ throw new HumanSessionError(
21874
+ "human_session_refresh_failed",
21875
+ "could not refresh your session; run cswarm login to sign in again"
21876
+ );
21861
21877
  }
21862
21878
  const session = requireSession(refreshed.data.session);
21863
21879
  const current = await store2.read();
@@ -26463,6 +26479,149 @@ async function agentCredentialStore(options) {
26463
26479
  };
26464
26480
  }
26465
26481
 
26482
+ // src/cloud/agent-credential-input.ts
26483
+ var UUID_RE4 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
26484
+ var AGENT_TOKEN_RE3 = /^swm_agt_[A-Za-z0-9_-]{43}$/;
26485
+ var AGENT_CREDENTIAL_MESSAGE = "Agent credential minted. It is bound to this task and run so the agent's work stays scoped and attributable.";
26486
+ var AGENT_CREDENTIAL_MESSAGE_D088 = "Agent credential minted. It is bound to this run, so the agent's work is attributable to it.";
26487
+ var ACCEPTED_AGENT_CREDENTIAL_MESSAGES = [
26488
+ AGENT_CREDENTIAL_MESSAGE,
26489
+ AGENT_CREDENTIAL_MESSAGE_D088
26490
+ ];
26491
+ var AgentCredentialInputError = class extends Error {
26492
+ constructor(code, message) {
26493
+ super(`[${code}] ${message}`);
26494
+ this.code = code;
26495
+ }
26496
+ code;
26497
+ name = "AgentCredentialInputError";
26498
+ };
26499
+ var AGENT_CREDENTIAL_REQUIRED_FIELDS = [
26500
+ "message",
26501
+ "status",
26502
+ "principal_id",
26503
+ "token_id",
26504
+ "run_id",
26505
+ "agent_token"
26506
+ ];
26507
+ var AGENT_CREDENTIAL_OPTIONAL_FIELDS = ["expires_at"];
26508
+ var ALLOWED_ARTIFACT_KEYS = /* @__PURE__ */ new Set([
26509
+ ...AGENT_CREDENTIAL_REQUIRED_FIELDS,
26510
+ ...AGENT_CREDENTIAL_OPTIONAL_FIELDS
26511
+ ]);
26512
+ function sourceName(source) {
26513
+ return source.kind === "file" ? `agent credential file ${source.path}` : "agent credential input from stdin";
26514
+ }
26515
+ function nextStep(source) {
26516
+ return source.kind === "file" ? `Next step: copy the minted JSON line again and replace ${source.path}.` : "Next step: copy the minted JSON line again and send that line to stdin.";
26517
+ }
26518
+ function credentialInputError(code, source, found) {
26519
+ return new AgentCredentialInputError(
26520
+ code,
26521
+ `${sourceName(source)} ${found}. It must be the JSON line CommonSwarm minted, copied unchanged: ${AGENT_CREDENTIAL_REQUIRED_FIELDS.join(", ")} (${AGENT_CREDENTIAL_OPTIONAL_FIELDS.join(", ")} is optional). ${nextStep(source)}`
26522
+ );
26523
+ }
26524
+ function jsonKind(value) {
26525
+ if (value === null) return "JSON null";
26526
+ if (Array.isArray(value)) return "a JSON array";
26527
+ return `a JSON ${typeof value}`;
26528
+ }
26529
+ function parseAgentCredentialInput(value, source) {
26530
+ if (AGENT_TOKEN_RE3.test(value)) {
26531
+ return {
26532
+ token: value,
26533
+ principalId: null,
26534
+ tokenId: null,
26535
+ runId: null,
26536
+ expiresAt: null,
26537
+ durable: false
26538
+ };
26539
+ }
26540
+ let parsed;
26541
+ try {
26542
+ parsed = JSON.parse(value);
26543
+ } catch {
26544
+ throw credentialInputError(
26545
+ "agent_credential_invalid_json",
26546
+ source,
26547
+ "contains text that is not valid JSON"
26548
+ );
26549
+ }
26550
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
26551
+ throw credentialInputError(
26552
+ "agent_credential_not_object",
26553
+ source,
26554
+ `contains ${jsonKind(parsed)} instead of a JSON object`
26555
+ );
26556
+ }
26557
+ const artifact = parsed;
26558
+ if (!Object.hasOwn(artifact, "agent_token")) {
26559
+ throw credentialInputError(
26560
+ "agent_credential_missing_agent_token",
26561
+ source,
26562
+ 'is missing "agent_token"'
26563
+ );
26564
+ }
26565
+ if (typeof artifact.agent_token !== "string" || !AGENT_TOKEN_RE3.test(artifact.agent_token)) {
26566
+ const found = typeof artifact.agent_token === "string" ? 'has "agent_token" as a string that is not a swm_agt_ credential' : `has "agent_token" as ${jsonKind(artifact.agent_token)}`;
26567
+ throw credentialInputError(
26568
+ "agent_credential_invalid_agent_token",
26569
+ source,
26570
+ found
26571
+ );
26572
+ }
26573
+ const actualKeys = Object.keys(artifact);
26574
+ const missingKeys = AGENT_CREDENTIAL_REQUIRED_FIELDS.filter(
26575
+ (key2) => !Object.hasOwn(artifact, key2)
26576
+ );
26577
+ const unknownCount = actualKeys.filter(
26578
+ (key2) => !ALLOWED_ARTIFACT_KEYS.has(key2)
26579
+ ).length;
26580
+ const invalidKeys = [];
26581
+ if (Object.hasOwn(artifact, "message") && !ACCEPTED_AGENT_CREDENTIAL_MESSAGES.includes(artifact.message)) {
26582
+ invalidKeys.push("message");
26583
+ }
26584
+ if (Object.hasOwn(artifact, "status") && artifact.status !== "accepted") {
26585
+ invalidKeys.push("status");
26586
+ }
26587
+ for (const key2 of ["principal_id", "token_id", "run_id"]) {
26588
+ if (Object.hasOwn(artifact, key2) && (typeof artifact[key2] !== "string" || !UUID_RE4.test(artifact[key2]))) {
26589
+ invalidKeys.push(key2);
26590
+ }
26591
+ }
26592
+ if (artifact.expires_at !== void 0) {
26593
+ if (typeof artifact.expires_at !== "string" || Number.isNaN(Date.parse(artifact.expires_at))) {
26594
+ invalidKeys.push("expires_at");
26595
+ }
26596
+ }
26597
+ if (missingKeys.length > 0 || unknownCount > 0 || invalidKeys.length > 0) {
26598
+ const faults = [];
26599
+ if (unknownCount > 0) {
26600
+ faults.push(`has ${unknownCount} unrecognized ${unknownCount === 1 ? "field" : "fields"}`);
26601
+ }
26602
+ if (missingKeys.length > 0) {
26603
+ faults.push(`is missing required ${missingKeys.length === 1 ? "field" : "fields"} ${missingKeys.map((key2) => `"${key2}"`).join(", ")}`);
26604
+ }
26605
+ if (invalidKeys.length > 0) {
26606
+ faults.push(`has invalid ${invalidKeys.length === 1 ? "field" : "fields"} ${invalidKeys.map((key2) => `"${key2}"`).join(", ")}`);
26607
+ }
26608
+ throw credentialInputError(
26609
+ "agent_credential_fields_invalid",
26610
+ source,
26611
+ faults.join(" and ")
26612
+ );
26613
+ }
26614
+ const expiresAt = artifact.expires_at === void 0 ? null : Date.parse(artifact.expires_at);
26615
+ return {
26616
+ token: artifact.agent_token,
26617
+ principalId: artifact.principal_id.toLowerCase(),
26618
+ tokenId: artifact.token_id.toLowerCase(),
26619
+ runId: artifact.run_id.toLowerCase(),
26620
+ expiresAt,
26621
+ durable: true
26622
+ };
26623
+ }
26624
+
26466
26625
  // src/cloud/renewal.ts
26467
26626
  var import_node_crypto9 = require("node:crypto");
26468
26627
  var AGENT_TOKEN_DEFAULT_TTL_MS2 = 60 * 60 * 1e3;
@@ -26485,8 +26644,8 @@ var RENEWAL_LEAD_FLOOR_MS = 5 * 6e4;
26485
26644
  var RENEWAL_LEAD_CEILING_MS = 15 * 6e4;
26486
26645
  var RENEWAL_PENDING_RECOVERY_MS = 60 * 6e4;
26487
26646
  var RENEW_TIMEOUT_MS = 3e4;
26488
- var UUID_RE4 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
26489
- var AGENT_TOKEN_RE3 = /^swm_agt_[A-Za-z0-9_-]{43}$/;
26647
+ var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
26648
+ var AGENT_TOKEN_RE4 = /^swm_agt_[A-Za-z0-9_-]{43}$/;
26490
26649
  function renewalDueAt(issuedAt, expiresAt) {
26491
26650
  const lifetime = Math.max(0, expiresAt - issuedAt);
26492
26651
  const lead = Math.min(
@@ -26644,7 +26803,7 @@ async function requestSuccessor(options) {
26644
26803
  } catch {
26645
26804
  body = {};
26646
26805
  }
26647
- const principalId = typeof body.principal_id === "string" && UUID_RE4.test(body.principal_id) ? body.principal_id.toLowerCase() : null;
26806
+ const principalId = typeof body.principal_id === "string" && UUID_RE5.test(body.principal_id) ? body.principal_id.toLowerCase() : null;
26648
26807
  if (response.status === 400 || response.status === 404) {
26649
26808
  throw new RenewalUnsupported(
26650
26809
  "this deployment does not offer credential renewal yet, so a credential here still has to be re-issued by hand when it expires"
@@ -26732,7 +26891,7 @@ async function requestSuccessor(options) {
26732
26891
  if (!token) {
26733
26892
  return null;
26734
26893
  }
26735
- if (!AGENT_TOKEN_RE3.test(token)) {
26894
+ if (!AGENT_TOKEN_RE4.test(token)) {
26736
26895
  throw new RenewalRefused(
26737
26896
  response.status,
26738
26897
  "malformed_successor",
@@ -26741,7 +26900,7 @@ async function requestSuccessor(options) {
26741
26900
  }
26742
26901
  const tokenId = typeof body.token_id === "string" ? body.token_id : "";
26743
26902
  const runId = typeof body.run_id === "string" ? body.run_id : "";
26744
- if (!UUID_RE4.test(tokenId) || !UUID_RE4.test(runId) || principalId === null) {
26903
+ if (!UUID_RE5.test(tokenId) || !UUID_RE5.test(runId) || principalId === null) {
26745
26904
  throw new RenewalRefused(
26746
26905
  response.status,
26747
26906
  "incomplete_successor",
@@ -27250,7 +27409,7 @@ var MAX_LINK_PAYLOAD_BYTES = 8 * 1024;
27250
27409
  var MAX_LABEL_INPUT_LENGTH = 1024;
27251
27410
  var CONTROL_GLOBAL_RE = /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g;
27252
27411
  var ANSI_ESCAPE_GLOBAL_RE = /\u001b\[[0-?]*[ -/]*[@-~]/g;
27253
- var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
27412
+ var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
27254
27413
  var STRICT_BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
27255
27414
  var RAW_BASE64_PAYLOAD_CANDIDATE_RE = /^[A-Za-z0-9+/_=-]+$/;
27256
27415
  var CURRENT_INVITE_SCHEME = "cswarm://accept/";
@@ -27301,7 +27460,7 @@ function validatedPayload(value) {
27301
27460
  throw new Error("invite link target is malformed");
27302
27461
  }
27303
27462
  cloudTarget(value.url, value.anon_key);
27304
- if (typeof value.workspace_id !== "string" || !UUID_RE5.test(value.workspace_id)) {
27463
+ if (typeof value.workspace_id !== "string" || !UUID_RE6.test(value.workspace_id)) {
27305
27464
  throw new Error("invite link workspace_id must be a UUID");
27306
27465
  }
27307
27466
  if (typeof value.invitation_token !== "string") {
@@ -27311,7 +27470,7 @@ function validatedPayload(value) {
27311
27470
  if (typeof value.workspace_name !== "string" || typeof value.inviter_display_name !== "string" || value.workspace_name.length > MAX_LABEL_INPUT_LENGTH || value.inviter_display_name.length > MAX_LABEL_INPUT_LENGTH) {
27312
27471
  throw new Error("invite link display labels are malformed");
27313
27472
  }
27314
- if (value.inviter_user_id !== void 0 && (typeof value.inviter_user_id !== "string" || !UUID_RE5.test(value.inviter_user_id))) {
27473
+ if (value.inviter_user_id !== void 0 && (typeof value.inviter_user_id !== "string" || !UUID_RE6.test(value.inviter_user_id))) {
27315
27474
  throw new Error("invite link inviter_user_id must be a UUID");
27316
27475
  }
27317
27476
  return value;
@@ -27969,7 +28128,7 @@ function renderCapabilityRevoke(capabilityId, revokedAt) {
27969
28128
  }
27970
28129
 
27971
28130
  // src/cloud/renewal-grants.ts
27972
- var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28131
+ var UUID_RE7 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
27973
28132
  function nullableString(value, field) {
27974
28133
  if (value === null) return null;
27975
28134
  if (typeof value !== "string") {
@@ -27985,7 +28144,7 @@ function nullableTimestamp(value, field) {
27985
28144
  return text;
27986
28145
  }
27987
28146
  function uuid3(value, field) {
27988
- if (typeof value !== "string" || !UUID_RE6.test(value)) {
28147
+ if (typeof value !== "string" || !UUID_RE7.test(value)) {
27989
28148
  throw new Error(`renewal grant read returned malformed ${field}`);
27990
28149
  }
27991
28150
  return value.toLowerCase();
@@ -28076,7 +28235,7 @@ function describeRenewalGrant(grant) {
28076
28235
  }
28077
28236
 
28078
28237
  // src/cloud/workspaces.ts
28079
- var UUID_RE7 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28238
+ var UUID_RE8 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28080
28239
  var ROLES = /* @__PURE__ */ new Set(["owner", "admin", "member"]);
28081
28240
  var MemberSelectionError = class extends Error {
28082
28241
  constructor(code, message, matches = []) {
@@ -28089,7 +28248,7 @@ var MemberSelectionError = class extends Error {
28089
28248
  matches;
28090
28249
  };
28091
28250
  function resolveWorkspaceMember(selector, members) {
28092
- if (UUID_RE7.test(selector)) {
28251
+ if (UUID_RE8.test(selector)) {
28093
28252
  const selected = members.find(
28094
28253
  (member) => member.user_id === selector.toLowerCase()
28095
28254
  );
@@ -28188,7 +28347,7 @@ var WorkspaceAmbiguousNameError = class extends WorkspaceCliError {
28188
28347
  }
28189
28348
  };
28190
28349
  function checkedUuid(value, field) {
28191
- if (typeof value !== "string" || !UUID_RE7.test(value)) {
28350
+ if (typeof value !== "string" || !UUID_RE8.test(value)) {
28192
28351
  throw new Error(`workspace read returned a malformed ${field}`);
28193
28352
  }
28194
28353
  return value.toLowerCase();
@@ -28507,13 +28666,13 @@ async function updateWorkspaceDefaultAfterClose(store2, userId, closedWorkspaceI
28507
28666
  }
28508
28667
  function workspaceOverride(explicit, environmental) {
28509
28668
  if (explicit !== void 0) {
28510
- if (!UUID_RE7.test(explicit)) {
28669
+ if (!UUID_RE8.test(explicit)) {
28511
28670
  throw new Error("--workspace-id must be a UUID");
28512
28671
  }
28513
28672
  return explicit.toLowerCase();
28514
28673
  }
28515
28674
  if (environmental) {
28516
- if (!UUID_RE7.test(environmental)) {
28675
+ if (!UUID_RE8.test(environmental)) {
28517
28676
  throw new Error("SWARM_CLOUD_WORKSPACE_ID must be a UUID");
28518
28677
  }
28519
28678
  return environmental.toLowerCase();
@@ -28573,7 +28732,7 @@ async function selectWorkspace(selector, workspaces, store2, userId) {
28573
28732
  function resolveWorkspaceSelector(selector, workspaces) {
28574
28733
  const sorted = sortWorkspaces(workspaces);
28575
28734
  let selected;
28576
- if (UUID_RE7.test(selector)) {
28735
+ if (UUID_RE8.test(selector)) {
28577
28736
  const normalized = selector.toLowerCase();
28578
28737
  selected = sorted.find(
28579
28738
  (workspace) => workspace.workspace_id === normalized
@@ -28723,7 +28882,7 @@ function describeServerError(prefix, envelope) {
28723
28882
 
28724
28883
  // src/cloud/attachments.ts
28725
28884
  var SIGNAL_ATTACHMENT_MAX = 8;
28726
- var UUID_RE8 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28885
+ var UUID_RE9 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28727
28886
  function parseSignalAttachments(value, options = {}) {
28728
28887
  if (options.enabled === false || value === void 0) return [];
28729
28888
  if (!Array.isArray(value) || value.length > SIGNAL_ATTACHMENT_MAX) {
@@ -28736,7 +28895,7 @@ function parseSignalAttachments(value, options = {}) {
28736
28895
  throw new Error("signal read returned a malformed attachment");
28737
28896
  }
28738
28897
  const row = valueAtPosition;
28739
- if (typeof row.file_id !== "string" || !UUID_RE8.test(row.file_id) || typeof row.version_n !== "number" || !Number.isSafeInteger(row.version_n) || row.version_n < 1 || typeof row.name !== "string" || row.name.length < 1 || row.name.length > 255 || typeof row.content_type !== "string" || row.content_type.length < 1 || typeof row.size_bytes !== "number" || !Number.isSafeInteger(row.size_bytes) || row.size_bytes < 0) {
28898
+ if (typeof row.file_id !== "string" || !UUID_RE9.test(row.file_id) || typeof row.version_n !== "number" || !Number.isSafeInteger(row.version_n) || row.version_n < 1 || typeof row.name !== "string" || row.name.length < 1 || row.name.length > 255 || typeof row.content_type !== "string" || row.content_type.length < 1 || typeof row.size_bytes !== "number" || !Number.isSafeInteger(row.size_bytes) || row.size_bytes < 0) {
28740
28899
  throw new Error("signal read returned malformed attachment metadata");
28741
28900
  }
28742
28901
  const fileId = row.file_id.toLowerCase();
@@ -28756,7 +28915,7 @@ function parseSignalAttachments(value, options = {}) {
28756
28915
  return attachments;
28757
28916
  }
28758
28917
  function attachmentRetrievalCommand(workspaceId2, attachment) {
28759
- if (!UUID_RE8.test(workspaceId2) || !UUID_RE8.test(attachment.file_id)) {
28918
+ if (!UUID_RE9.test(workspaceId2) || !UUID_RE9.test(attachment.file_id)) {
28760
28919
  throw new Error("attachment retrieval command needs UUID identifiers");
28761
28920
  }
28762
28921
  if (!Number.isSafeInteger(attachment.version_n) || attachment.version_n < 1) {
@@ -28772,7 +28931,7 @@ function formatAttachmentSize(bytes) {
28772
28931
  }
28773
28932
 
28774
28933
  // src/cloud/signals.ts
28775
- var UUID_RE9 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28934
+ var UUID_RE10 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28776
28935
  var SIGNAL_KINDS = /* @__PURE__ */ new Set(["working-on", "note", "ask"]);
28777
28936
  var SIGNAL_BODY_DISPLAY_MAX = 8e3;
28778
28937
  var SIGNAL_ABOUT_DISPLAY_MAX = 500;
@@ -28843,7 +29002,7 @@ function plainMalformedError(message) {
28843
29002
  return error;
28844
29003
  }
28845
29004
  function checkedUuid2(value, field) {
28846
- if (typeof value !== "string" || !UUID_RE9.test(value)) {
29005
+ if (typeof value !== "string" || !UUID_RE10.test(value)) {
28847
29006
  throw new Error(`signal read returned a malformed ${field}`);
28848
29007
  }
28849
29008
  return value.toLowerCase();
@@ -29474,7 +29633,7 @@ async function readAgentSignalDirectory(target2, token, workspaceId2, fetcherOrO
29474
29633
  }
29475
29634
  function resolveSignalRecipient(selector, directory) {
29476
29635
  const resolved = Array.isArray(directory) ? { members: directory, agents: [] } : directory;
29477
- if (UUID_RE9.test(selector)) {
29636
+ if (UUID_RE10.test(selector)) {
29478
29637
  const normalized = selector.toLowerCase();
29479
29638
  const member = resolved.members.find((row) => row.user_id === normalized);
29480
29639
  const agent = resolved.agents.find(
@@ -29560,10 +29719,10 @@ async function pollForSignals(options) {
29560
29719
  return { signals: [], timedOut: true };
29561
29720
  }
29562
29721
  function normalizedSignalQuery(query) {
29563
- if (!UUID_RE9.test(query.workspaceId)) {
29722
+ if (!UUID_RE10.test(query.workspaceId)) {
29564
29723
  throw new Error("--workspace-id must be a UUID");
29565
29724
  }
29566
- if (query.in_reply_to !== void 0 && !UUID_RE9.test(query.in_reply_to)) {
29725
+ if (query.in_reply_to !== void 0 && !UUID_RE10.test(query.in_reply_to)) {
29567
29726
  throw new Error("in_reply_to must be a signal UUID");
29568
29727
  }
29569
29728
  const after = checkedAfter(query.after);
@@ -30081,7 +30240,7 @@ async function runInboxFollow(options) {
30081
30240
  // src/cloud/arrival-watch.ts
30082
30241
  var import_node_os4 = require("node:os");
30083
30242
  var import_node_path4 = require("node:path");
30084
- var UUID_RE10 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
30243
+ var UUID_RE11 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
30085
30244
  var CURSOR_MAX_BYTES = 4 * 1024;
30086
30245
  var ARRIVAL_SNIPPET_MAX = 180;
30087
30246
  var ARRIVAL_WATCH_POLL_MS = 25e3;
@@ -30149,7 +30308,7 @@ function parseCursor(raw, workspaceId2, principalId) {
30149
30308
  }
30150
30309
  const row = value;
30151
30310
  const cursor = row.cursor;
30152
- if (row.version !== 1 || row.workspace_id !== workspaceId2.toLowerCase() || row.principal_id !== principalId.toLowerCase() || !(cursor === null || typeof cursor === "object" && !Array.isArray(cursor) && typeof cursor.created_at === "string" && Number.isFinite(Date.parse(cursor.created_at)) && typeof cursor.id === "string" && UUID_RE10.test(cursor.id))) {
30311
+ if (row.version !== 1 || row.workspace_id !== workspaceId2.toLowerCase() || row.principal_id !== principalId.toLowerCase() || !(cursor === null || typeof cursor === "object" && !Array.isArray(cursor) && typeof cursor.created_at === "string" && Number.isFinite(Date.parse(cursor.created_at)) && typeof cursor.id === "string" && UUID_RE11.test(cursor.id))) {
30153
30312
  throw new Error("stored arrival cursor is malformed");
30154
30313
  }
30155
30314
  if (cursor === null) return null;
@@ -30161,7 +30320,7 @@ function parseCursor(raw, workspaceId2, principalId) {
30161
30320
  function fileArrivalCursorStore(options) {
30162
30321
  const workspaceId2 = options.workspaceId.toLowerCase();
30163
30322
  const principalId = options.principalId.toLowerCase();
30164
- if (!UUID_RE10.test(workspaceId2) || !UUID_RE10.test(principalId)) {
30323
+ if (!UUID_RE11.test(workspaceId2) || !UUID_RE11.test(principalId)) {
30165
30324
  throw new Error("arrival cursor identity must use workspace and principal UUIDs");
30166
30325
  }
30167
30326
  const location2 = arrivalCursorPath(
@@ -30343,7 +30502,7 @@ async function runArrivalWatch(options) {
30343
30502
  }
30344
30503
 
30345
30504
  // src/cloud/delivery-receipts.ts
30346
- var UUID_RE11 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
30505
+ var UUID_RE12 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
30347
30506
  var DeliveryReceiptReadError = class extends Error {
30348
30507
  constructor(code, message, status = null) {
30349
30508
  super(message);
@@ -30362,7 +30521,7 @@ var ACK_OUTCOMES = /* @__PURE__ */ new Set([
30362
30521
  "failed_terminal"
30363
30522
  ]);
30364
30523
  function uuid4(value, field) {
30365
- if (typeof value !== "string" || !UUID_RE11.test(value)) {
30524
+ if (typeof value !== "string" || !UUID_RE12.test(value)) {
30366
30525
  throw new DeliveryReceiptReadError(
30367
30526
  "protocol",
30368
30527
  `delivery receipt returned a malformed ${field}`
@@ -33739,7 +33898,7 @@ async function resolveBudgetAndPrompt(session, prompt, budget) {
33739
33898
  }
33740
33899
 
33741
33900
  // src/listener/engine.ts
33742
- var UUID_RE12 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
33901
+ var UUID_RE13 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
33743
33902
  var TERMINAL_STATES = /* @__PURE__ */ new Set(["done", "expired", "failed"]);
33744
33903
  var REPLY_MAX_CODE_UNITS = 2e3;
33745
33904
  var TRUNCATION_SUFFIX = "\n[Reply truncated by CommonSwarm]";
@@ -33747,7 +33906,7 @@ var UNSAFE_CONTROLS_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u
33747
33906
  var LISTENER_MAX_PROMPT_ATTEMPTS = 3;
33748
33907
  var LISTENER_MAX_POST_ATTEMPTS = 5;
33749
33908
  function listenerReplyCommandId(signalId, effectOrdinal = 0) {
33750
- if (!UUID_RE12.test(signalId)) {
33909
+ if (!UUID_RE13.test(signalId)) {
33751
33910
  throw new Error("listener signal id must be a UUID");
33752
33911
  }
33753
33912
  if (!Number.isSafeInteger(effectOrdinal) || effectOrdinal < 0) {
@@ -34240,7 +34399,7 @@ var import_node_crypto13 = require("node:crypto");
34240
34399
  var import_node_os6 = require("node:os");
34241
34400
  var import_node_path9 = require("node:path");
34242
34401
  var import_node_util = require("node:util");
34243
- var UUID_RE13 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
34402
+ var UUID_RE14 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
34244
34403
  var COMMAND_ID_RE2 = /^[A-Za-z0-9_-]{8,72}$/;
34245
34404
  var MAX_EFFECT_BYTES = 1024 * 1024;
34246
34405
  var STATES = /* @__PURE__ */ new Set([
@@ -34290,7 +34449,7 @@ function defaultListenerStateDirectory() {
34290
34449
  return process.env.XDG_STATE_HOME ? (0, import_node_path9.join)(process.env.XDG_STATE_HOME, "cswarm", "listeners") : (0, import_node_path9.join)((0, import_node_os6.homedir)(), ".cswarm", "listeners");
34291
34450
  }
34292
34451
  function listenerInstanceKey(input) {
34293
- if (!UUID_RE13.test(input.workspaceId) || !UUID_RE13.test(input.principalId)) {
34452
+ if (!UUID_RE14.test(input.workspaceId) || !UUID_RE14.test(input.principalId)) {
34294
34453
  throw new Error("listener workspace and principal ids must be UUIDs");
34295
34454
  }
34296
34455
  if (!input.profileId || input.profileId.includes("\0")) {
@@ -34323,7 +34482,7 @@ function parseListenerEffectRecord(raw, expectedId) {
34323
34482
  }
34324
34483
  const row = value;
34325
34484
  rejectSensitiveKeys(row);
34326
- if (typeof row.version !== "number" || row.version !== 1 && row.version !== 2 || typeof row.signalId !== "string" || row.signalId.toLowerCase() !== expectedId || !UUID_RE13.test(row.signalId)) {
34485
+ if (typeof row.version !== "number" || row.version !== 1 && row.version !== 2 || typeof row.signalId !== "string" || row.signalId.toLowerCase() !== expectedId || !UUID_RE14.test(row.signalId)) {
34327
34486
  throw new Error("stored listener effect is malformed");
34328
34487
  }
34329
34488
  if (row.version === 1) {
@@ -34338,7 +34497,7 @@ function upcastV1Ask(row) {
34338
34497
  if (row.effectOrdinal !== 0 || typeof row.commandId !== "string" || !COMMAND_ID_RE2.test(row.commandId) || typeof row.askBody !== "string" || row.askBody.length < 1 || typeof row.askUntil !== "string" || !Number.isFinite(Date.parse(row.askUntil)) || typeof row.senderOwnerRelation !== "string" || !RELATIONS.has(row.senderOwnerRelation) || typeof row.state !== "string" || !STATES.has(row.state) || !integer(row.promptAttempts) || !integer(row.postAttempts) || !nullableString2(row.replyBody, 2e3) || typeof row.replyTruncated !== "boolean" || !nullableString2(row.replySignalId, 64) || !nullableString2(row.failureCode, 96) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt))) {
34339
34498
  throw new Error("stored listener effect is malformed");
34340
34499
  }
34341
- if (row.replySignalId !== null && !UUID_RE13.test(row.replySignalId)) {
34500
+ if (row.replySignalId !== null && !UUID_RE14.test(row.replySignalId)) {
34342
34501
  throw new Error("stored listener effect is malformed");
34343
34502
  }
34344
34503
  return {
@@ -34377,7 +34536,7 @@ function parseV2Record(row) {
34377
34536
  if (typeof row.commandId !== "string" || !COMMAND_ID_RE2.test(row.commandId) || row.state === "observed") {
34378
34537
  throw new Error("stored listener effect is malformed");
34379
34538
  }
34380
- if (row.replySignalId !== null && !UUID_RE13.test(row.replySignalId)) {
34539
+ if (row.replySignalId !== null && !UUID_RE14.test(row.replySignalId)) {
34381
34540
  throw new Error("stored listener effect is malformed");
34382
34541
  }
34383
34542
  }
@@ -34401,7 +34560,7 @@ function parseV2Record(row) {
34401
34560
  };
34402
34561
  }
34403
34562
  function newObservedNoteRecord(input) {
34404
- if (!UUID_RE13.test(input.signalId)) {
34563
+ if (!UUID_RE14.test(input.signalId)) {
34405
34564
  throw new Error("listener note signal id must be a UUID");
34406
34565
  }
34407
34566
  if (input.body.length < 1) {
@@ -34535,7 +34694,7 @@ var FileListenerEffectStore = class {
34535
34694
  );
34536
34695
  }
34537
34696
  checkedId(signalId) {
34538
- if (!UUID_RE13.test(signalId)) {
34697
+ if (!UUID_RE14.test(signalId)) {
34539
34698
  throw new Error("listener signal id must be a UUID");
34540
34699
  }
34541
34700
  return signalId.toLowerCase();
@@ -35768,7 +35927,7 @@ var CodexListenerModel = class {
35768
35927
  var import_node_crypto18 = require("node:crypto");
35769
35928
 
35770
35929
  // src/cloud/delivery.ts
35771
- var UUID_RE14 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
35930
+ var UUID_RE15 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
35772
35931
  var RFC3339_TIMESTAMP_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}):(\d{2}))$/i;
35773
35932
  var DELIVERY_KINDS = /* @__PURE__ */ new Set(["ask", "note"]);
35774
35933
  var SENDER_OWNER_RELATIONS2 = /* @__PURE__ */ new Set([
@@ -35855,7 +36014,7 @@ var DeliveryProtocolError = class extends Error {
35855
36014
  }
35856
36015
  };
35857
36016
  function checkedUuid3(value, field) {
35858
- if (typeof value !== "string" || !UUID_RE14.test(value)) {
36017
+ if (typeof value !== "string" || !UUID_RE15.test(value)) {
35859
36018
  throw new DeliveryProtocolError(
35860
36019
  `delivery response returned a malformed ${field}`
35861
36020
  );
@@ -35966,7 +36125,7 @@ function checkedClaimCapabilities(value) {
35966
36125
  }
35967
36126
  function checkedOptionalUuidArray(value, field) {
35968
36127
  if (value === void 0) return;
35969
- if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !UUID_RE14.test(item))) {
36128
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !UUID_RE15.test(item))) {
35970
36129
  throw new DeliveryProtocolError(
35971
36130
  `delivery response returned a malformed ${field}`
35972
36131
  );
@@ -36113,7 +36272,7 @@ function checkedCommandId(value) {
36113
36272
  return value;
36114
36273
  }
36115
36274
  function checkedUuidRequest(value, field) {
36116
- if (!UUID_RE14.test(value)) {
36275
+ if (!UUID_RE15.test(value)) {
36117
36276
  throw new Error(`${field} must be a UUID for an agent delivery command`);
36118
36277
  }
36119
36278
  }
@@ -36350,7 +36509,7 @@ var DeliveryCommandClient = class {
36350
36509
 
36351
36510
  // src/listener/main-routing.ts
36352
36511
  var import_node_path15 = require("node:path");
36353
- var UUID_RE15 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
36512
+ var UUID_RE16 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
36354
36513
  var MAX_QUEUE_BYTES = 1024 * 1024;
36355
36514
  var QUEUE_FILE = "pending-for-main.json";
36356
36515
  var QUEUE_LOCK = "pending-for-main";
@@ -36407,7 +36566,7 @@ function parseEntry(value, rejectUnknownKeys) {
36407
36566
  if (rejectUnknownKeys && Object.keys(row).some((key2) => !ENTRY_KEYS.has(key2))) {
36408
36567
  throw new Error("stored pending-for-main entry is malformed");
36409
36568
  }
36410
- if (typeof row.signalId !== "string" || !UUID_RE15.test(row.signalId) || typeof row.workspaceId !== "string" || !UUID_RE15.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE15.test(row.principalId) || typeof row.fromId !== "string" || !UUID_RE15.test(row.fromId) || row.fromKind !== "user" && row.fromKind !== "agent" || !(row.kind === void 0 || row.kind === "ask" || row.kind === "note") || !(row.senderName === null || typeof row.senderName === "string" && row.senderName.length <= 200) || typeof row.body !== "string" || row.body.length < 1 || !(row.attachmentCount === void 0 || typeof row.attachmentCount === "number" && Number.isSafeInteger(row.attachmentCount) && row.attachmentCount >= 1 && row.attachmentCount <= 8) || !checkedTimestamp2(row.createdAt) || !checkedTimestamp2(row.queuedAt) || !(row.observationPending === void 0 || row.observationPending === true)) {
36569
+ if (typeof row.signalId !== "string" || !UUID_RE16.test(row.signalId) || typeof row.workspaceId !== "string" || !UUID_RE16.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE16.test(row.principalId) || typeof row.fromId !== "string" || !UUID_RE16.test(row.fromId) || row.fromKind !== "user" && row.fromKind !== "agent" || !(row.kind === void 0 || row.kind === "ask" || row.kind === "note") || !(row.senderName === null || typeof row.senderName === "string" && row.senderName.length <= 200) || typeof row.body !== "string" || row.body.length < 1 || !(row.attachmentCount === void 0 || typeof row.attachmentCount === "number" && Number.isSafeInteger(row.attachmentCount) && row.attachmentCount >= 1 && row.attachmentCount <= 8) || !checkedTimestamp2(row.createdAt) || !checkedTimestamp2(row.queuedAt) || !(row.observationPending === void 0 || row.observationPending === true)) {
36411
36570
  throw new Error("stored pending-for-main entry is malformed");
36412
36571
  }
36413
36572
  return {
@@ -36547,7 +36706,7 @@ var LISTENER_PROMPT_START_MINIMUM_MS = SIGNAL_READ_TIMEOUT_MS + ACP_DEFAULT_REQU
36547
36706
  var LISTENER_DELIVERY_RETRY_INITIAL_MS = 500;
36548
36707
  var LISTENER_DELIVERY_RETRY_MAX_MS = 3e4;
36549
36708
  var LISTENER_HOST_PORTS_PROBE_MS = 6e4;
36550
- var UUID_RE16 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
36709
+ var UUID_RE17 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
36551
36710
  var ListenerCapabilityError = class extends Error {
36552
36711
  code;
36553
36712
  constructor(code, message) {
@@ -36825,7 +36984,7 @@ async function runListenerRuntime(options) {
36825
36984
  new Error("listener instance id and delivery journal must be configured together")
36826
36985
  );
36827
36986
  }
36828
- if (hasInstanceId && !UUID_RE16.test(options.listenerInstanceId)) {
36987
+ if (hasInstanceId && !UUID_RE17.test(options.listenerInstanceId)) {
36829
36988
  return await closeBeforeStart(
36830
36989
  options.model,
36831
36990
  new Error("listener instance id must be a UUID")
@@ -37937,7 +38096,7 @@ var import_node_crypto19 = require("node:crypto");
37937
38096
  var import_node_net = require("node:net");
37938
38097
  var import_promises9 = require("node:fs/promises");
37939
38098
  var import_node_path16 = require("node:path");
37940
- var UUID_RE17 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
38099
+ var UUID_RE18 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
37941
38100
  var SEMVER_RE2 = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
37942
38101
  var MAX_STATUS_BYTES = 32 * 1024;
37943
38102
  var MAX_CONTROL_BYTES = 8 * 1024;
@@ -38066,11 +38225,11 @@ function parseStatus(raw, rejectUnknownKeys = false) {
38066
38225
  throw new Error("stored listener status is malformed");
38067
38226
  }
38068
38227
  }
38069
- const nullableUuid3 = (candidate) => candidate === null || typeof candidate === "string" && UUID_RE17.test(candidate);
38228
+ const nullableUuid3 = (candidate) => candidate === null || typeof candidate === "string" && UUID_RE18.test(candidate);
38070
38229
  const nullableCount = (candidate) => candidate === null || typeof candidate === "number" && Number.isSafeInteger(candidate) && candidate >= 0;
38071
38230
  const nullableTimestamp3 = (candidate) => candidate === null || typeof candidate === "string" && Number.isFinite(Date.parse(candidate));
38072
38231
  const readHealth = row.readHealth === void 0 ? void 0 : parseListenerReadHealth(row.readHealth, rejectUnknownKeys);
38073
- if (row.version !== 1 || typeof row.instanceId !== "string" || !UUID_RE17.test(row.instanceId) || row.provider !== "grok" && row.provider !== "opencode" && row.provider !== "claude" && row.provider !== "codex" || typeof row.profileId !== "string" || typeof row.workspaceId !== "string" || !UUID_RE17.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE17.test(row.principalId) || !Number.isSafeInteger(row.pid) || row.pid < 1 || typeof row.state !== "string" || !["starting", "ready", "stopping", "stopped", "failed"].includes(row.state) || typeof row.startedAt !== "string" || !Number.isFinite(Date.parse(row.startedAt)) || !(row.readyAt === null || typeof row.readyAt === "string" && Number.isFinite(Date.parse(row.readyAt))) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt)) || !(row.stoppedAt === null || typeof row.stoppedAt === "string" && Number.isFinite(Date.parse(row.stoppedAt))) || !nullableUuid3(row.lastSignalId) || !(row.lastErrorCode === null || typeof row.lastErrorCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorCode)) || !(row.lastErrorDetail === void 0 || row.lastErrorDetail === null || typeof row.lastErrorDetail === "string" && row.lastErrorDetail.length > 0 && row.lastErrorDetail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastErrorDetail)) || !(row.lastErrorReasonCode === void 0 || row.lastErrorReasonCode === null || typeof row.lastErrorReasonCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorReasonCode)) || !(row.providerExecutable === void 0 || row.providerExecutable === null || typeof row.providerExecutable === "string" && (0, import_node_path16.isAbsolute)(row.providerExecutable)) || !(row.providerVersion === void 0 || row.providerVersion === null || typeof row.providerVersion === "string" && SEMVER_RE2.test(row.providerVersion)) || !(row.providerLastMeasuredVersion === void 0 || row.providerLastMeasuredVersion === null || typeof row.providerLastMeasuredVersion === "string" && SEMVER_RE2.test(row.providerLastMeasuredVersion)) || !(row.providerBundledAgentSdkVersion === void 0 || row.providerBundledAgentSdkVersion === null || typeof row.providerBundledAgentSdkVersion === "string" && SEMVER_RE2.test(row.providerBundledAgentSdkVersion)) || !(row.providerBundledClaudeCodeVersion === void 0 || row.providerBundledClaudeCodeVersion === null || typeof row.providerBundledClaudeCodeVersion === "string" && SEMVER_RE2.test(row.providerBundledClaudeCodeVersion)) || !(row.providerMinimumRequiredVersion === void 0 || row.providerMinimumRequiredVersion === null || typeof row.providerMinimumRequiredVersion === "string" && SEMVER_RE2.test(row.providerMinimumRequiredVersion)) || !(row.cswarmVersion === void 0 || row.cswarmVersion === null || typeof row.cswarmVersion === "string" && SEMVER_RE2.test(row.cswarmVersion)) || (row.providerVersion === null || row.providerVersion === void 0) !== (row.providerLastMeasuredVersion === null || row.providerLastMeasuredVersion === void 0) || !(row.lastWorkerStderrTail === void 0 || row.lastWorkerStderrTail === null || typeof row.lastWorkerStderrTail === "string" && row.lastWorkerStderrTail.length > 0 && row.lastWorkerStderrTail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastWorkerStderrTail)) || typeof row.logPath !== "string" || !(0, import_node_path16.isAbsolute)(row.logPath) || !(row.deliveryMode === void 0 || row.deliveryMode === null || typeof row.deliveryMode === "string" && STATUS_DELIVERY_MODES.has(row.deliveryMode)) || !(row.pendingDeliveryCount === void 0 || nullableCount(row.pendingDeliveryCount)) || !(row.lastTerminalDeliveryFailureCount === void 0 || nullableCount(row.lastTerminalDeliveryFailureCount)) || !(row.lastTerminalDeliveryFailureAt === void 0 || nullableTimestamp3(row.lastTerminalDeliveryFailureAt)) || !(row.lastClaimAt === void 0 || nullableTimestamp3(row.lastClaimAt)) || !(row.lastAckAt === void 0 || nullableTimestamp3(row.lastAckAt)) || !(row.routeMode === void 0 || row.routeMode === "worker" || row.routeMode === "main" || row.routeMode === "split") || !(row.deferOverChars === void 0 || row.deferOverChars === null || typeof row.deferOverChars === "number" && Number.isSafeInteger(row.deferOverChars) && row.deferOverChars >= 1 && row.deferOverChars <= 1e4) || !(row.pendingForMainCount === void 0 || typeof row.pendingForMainCount === "number" && Number.isSafeInteger(row.pendingForMainCount) && row.pendingForMainCount >= 0) || !(row.droppedForMainCount === void 0 || typeof row.droppedForMainCount === "number" && Number.isSafeInteger(row.droppedForMainCount) && row.droppedForMainCount >= 0) || readHealth === null || !(row.connectionsOpened === void 0 || typeof row.connectionsOpened === "number" && Number.isSafeInteger(row.connectionsOpened) && row.connectionsOpened >= 0) || !(row.connectionReuseRatio === void 0 || typeof row.connectionReuseRatio === "number" && Number.isFinite(row.connectionReuseRatio) && row.connectionReuseRatio >= 0) || !(row.activityPublishFailures === void 0 || typeof row.activityPublishFailures === "number" && Number.isSafeInteger(row.activityPublishFailures) && row.activityPublishFailures >= 0) || !(row.activityLastErrorCode === void 0 || row.activityLastErrorCode === null || typeof row.activityLastErrorCode === "string" && STATUS_ACTIVITY_ERROR_CODES.has(
38232
+ if (row.version !== 1 || typeof row.instanceId !== "string" || !UUID_RE18.test(row.instanceId) || row.provider !== "grok" && row.provider !== "opencode" && row.provider !== "claude" && row.provider !== "codex" || typeof row.profileId !== "string" || typeof row.workspaceId !== "string" || !UUID_RE18.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE18.test(row.principalId) || !Number.isSafeInteger(row.pid) || row.pid < 1 || typeof row.state !== "string" || !["starting", "ready", "stopping", "stopped", "failed"].includes(row.state) || typeof row.startedAt !== "string" || !Number.isFinite(Date.parse(row.startedAt)) || !(row.readyAt === null || typeof row.readyAt === "string" && Number.isFinite(Date.parse(row.readyAt))) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt)) || !(row.stoppedAt === null || typeof row.stoppedAt === "string" && Number.isFinite(Date.parse(row.stoppedAt))) || !nullableUuid3(row.lastSignalId) || !(row.lastErrorCode === null || typeof row.lastErrorCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorCode)) || !(row.lastErrorDetail === void 0 || row.lastErrorDetail === null || typeof row.lastErrorDetail === "string" && row.lastErrorDetail.length > 0 && row.lastErrorDetail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastErrorDetail)) || !(row.lastErrorReasonCode === void 0 || row.lastErrorReasonCode === null || typeof row.lastErrorReasonCode === "string" && /^[a-z0-9_-]{1,96}$/.test(row.lastErrorReasonCode)) || !(row.providerExecutable === void 0 || row.providerExecutable === null || typeof row.providerExecutable === "string" && (0, import_node_path16.isAbsolute)(row.providerExecutable)) || !(row.providerVersion === void 0 || row.providerVersion === null || typeof row.providerVersion === "string" && SEMVER_RE2.test(row.providerVersion)) || !(row.providerLastMeasuredVersion === void 0 || row.providerLastMeasuredVersion === null || typeof row.providerLastMeasuredVersion === "string" && SEMVER_RE2.test(row.providerLastMeasuredVersion)) || !(row.providerBundledAgentSdkVersion === void 0 || row.providerBundledAgentSdkVersion === null || typeof row.providerBundledAgentSdkVersion === "string" && SEMVER_RE2.test(row.providerBundledAgentSdkVersion)) || !(row.providerBundledClaudeCodeVersion === void 0 || row.providerBundledClaudeCodeVersion === null || typeof row.providerBundledClaudeCodeVersion === "string" && SEMVER_RE2.test(row.providerBundledClaudeCodeVersion)) || !(row.providerMinimumRequiredVersion === void 0 || row.providerMinimumRequiredVersion === null || typeof row.providerMinimumRequiredVersion === "string" && SEMVER_RE2.test(row.providerMinimumRequiredVersion)) || !(row.cswarmVersion === void 0 || row.cswarmVersion === null || typeof row.cswarmVersion === "string" && SEMVER_RE2.test(row.cswarmVersion)) || (row.providerVersion === null || row.providerVersion === void 0) !== (row.providerLastMeasuredVersion === null || row.providerLastMeasuredVersion === void 0) || !(row.lastWorkerStderrTail === void 0 || row.lastWorkerStderrTail === null || typeof row.lastWorkerStderrTail === "string" && row.lastWorkerStderrTail.length > 0 && row.lastWorkerStderrTail.length <= 2048 && !/swm_(?:agt|inv|cap)_/i.test(row.lastWorkerStderrTail)) || typeof row.logPath !== "string" || !(0, import_node_path16.isAbsolute)(row.logPath) || !(row.deliveryMode === void 0 || row.deliveryMode === null || typeof row.deliveryMode === "string" && STATUS_DELIVERY_MODES.has(row.deliveryMode)) || !(row.pendingDeliveryCount === void 0 || nullableCount(row.pendingDeliveryCount)) || !(row.lastTerminalDeliveryFailureCount === void 0 || nullableCount(row.lastTerminalDeliveryFailureCount)) || !(row.lastTerminalDeliveryFailureAt === void 0 || nullableTimestamp3(row.lastTerminalDeliveryFailureAt)) || !(row.lastClaimAt === void 0 || nullableTimestamp3(row.lastClaimAt)) || !(row.lastAckAt === void 0 || nullableTimestamp3(row.lastAckAt)) || !(row.routeMode === void 0 || row.routeMode === "worker" || row.routeMode === "main" || row.routeMode === "split") || !(row.deferOverChars === void 0 || row.deferOverChars === null || typeof row.deferOverChars === "number" && Number.isSafeInteger(row.deferOverChars) && row.deferOverChars >= 1 && row.deferOverChars <= 1e4) || !(row.pendingForMainCount === void 0 || typeof row.pendingForMainCount === "number" && Number.isSafeInteger(row.pendingForMainCount) && row.pendingForMainCount >= 0) || !(row.droppedForMainCount === void 0 || typeof row.droppedForMainCount === "number" && Number.isSafeInteger(row.droppedForMainCount) && row.droppedForMainCount >= 0) || readHealth === null || !(row.connectionsOpened === void 0 || typeof row.connectionsOpened === "number" && Number.isSafeInteger(row.connectionsOpened) && row.connectionsOpened >= 0) || !(row.connectionReuseRatio === void 0 || typeof row.connectionReuseRatio === "number" && Number.isFinite(row.connectionReuseRatio) && row.connectionReuseRatio >= 0) || !(row.activityPublishFailures === void 0 || typeof row.activityPublishFailures === "number" && Number.isSafeInteger(row.activityPublishFailures) && row.activityPublishFailures >= 0) || !(row.activityLastErrorCode === void 0 || row.activityLastErrorCode === null || typeof row.activityLastErrorCode === "string" && STATUS_ACTIVITY_ERROR_CODES.has(
38074
38233
  row.activityLastErrorCode
38075
38234
  ))) {
38076
38235
  throw new Error("stored listener status is malformed");
@@ -38488,7 +38647,7 @@ async function queryListenerControl(paths, command2, timeoutMs = CONTROL_TIMEOUT
38488
38647
 
38489
38648
  // src/listener/supervisor.ts
38490
38649
  var import_node_crypto20 = require("node:crypto");
38491
- var UUID_RE18 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
38650
+ var UUID_RE19 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
38492
38651
  var LISTENER_RESTART_MAX_ATTEMPTS = 5;
38493
38652
  var LISTENER_RESTART_INITIAL_MS = 1e3;
38494
38653
  var LISTENER_RESTART_MAX_MS = 6e4;
@@ -38672,7 +38831,7 @@ async function runListenerSupervisor(options) {
38672
38831
  // before the socket can answer, before any status/event persistence.
38673
38832
  initialize: prepare ? async () => {
38674
38833
  const selected = await prepare(proposedInstanceId);
38675
- if (!selected || typeof selected !== "object" || typeof selected.instanceId !== "string" || !UUID_RE18.test(selected.instanceId)) {
38834
+ if (!selected || typeof selected !== "object" || typeof selected.instanceId !== "string" || !UUID_RE19.test(selected.instanceId)) {
38676
38835
  throw new Error("listener prepare returned an invalid instance id");
38677
38836
  }
38678
38837
  status = { ...status, instanceId: selected.instanceId };
@@ -39117,7 +39276,7 @@ async function waitForListenerReady(paths, options = {}) {
39117
39276
  // src/listener/delivery-journal.ts
39118
39277
  var import_node_path17 = require("node:path");
39119
39278
  var import_node_util2 = require("node:util");
39120
- var UUID_RE19 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
39279
+ var UUID_RE20 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
39121
39280
  var COMMAND_ID_RE3 = /^[A-Za-z0-9_-]{8,72}$/;
39122
39281
  var SIGNAL_FINGERPRINT_RE = /^[0-9a-f]{64}$/;
39123
39282
  var MAX_JOURNAL_BYTES = 8192;
@@ -39212,7 +39371,7 @@ var ALLOWED_ERROR_CODES = /* @__PURE__ */ new Set([
39212
39371
  "credential_unavailable"
39213
39372
  ]);
39214
39373
  function claimCommandId(listenerInstanceId, claimOrdinal) {
39215
- if (!UUID_RE19.test(listenerInstanceId)) {
39374
+ if (!UUID_RE20.test(listenerInstanceId)) {
39216
39375
  throw new Error("stored delivery journal is malformed");
39217
39376
  }
39218
39377
  if (!Number.isSafeInteger(claimOrdinal) || claimOrdinal < 0) {
@@ -39227,7 +39386,7 @@ function claimCommandId(listenerInstanceId, claimOrdinal) {
39227
39386
  return id;
39228
39387
  }
39229
39388
  function ackCommandId(leaseId) {
39230
- if (!UUID_RE19.test(leaseId)) {
39389
+ if (!UUID_RE20.test(leaseId)) {
39231
39390
  throw new Error("stored delivery journal is malformed");
39232
39391
  }
39233
39392
  const cleanLease = leaseId.toLowerCase().replace(/-/g, "");
@@ -39310,19 +39469,19 @@ function parseJournalRecord(raw, expectedWorkspaceId, expectedPrincipalId, rejec
39310
39469
  if (row.version !== 1) {
39311
39470
  throw new Error("stored delivery journal is malformed");
39312
39471
  }
39313
- if (typeof row.workspaceId !== "string" || !UUID_RE19.test(row.workspaceId) || row.workspaceId !== row.workspaceId.toLowerCase()) {
39472
+ if (typeof row.workspaceId !== "string" || !UUID_RE20.test(row.workspaceId) || row.workspaceId !== row.workspaceId.toLowerCase()) {
39314
39473
  throw new Error("stored delivery journal is malformed");
39315
39474
  }
39316
39475
  if (expectedWorkspaceId && row.workspaceId !== expectedWorkspaceId.toLowerCase()) {
39317
39476
  throw new Error("stored delivery journal is malformed");
39318
39477
  }
39319
- if (typeof row.principalId !== "string" || !UUID_RE19.test(row.principalId) || row.principalId !== row.principalId.toLowerCase()) {
39478
+ if (typeof row.principalId !== "string" || !UUID_RE20.test(row.principalId) || row.principalId !== row.principalId.toLowerCase()) {
39320
39479
  throw new Error("stored delivery journal is malformed");
39321
39480
  }
39322
39481
  if (expectedPrincipalId && row.principalId !== expectedPrincipalId.toLowerCase()) {
39323
39482
  throw new Error("stored delivery journal is malformed");
39324
39483
  }
39325
- if (typeof row.listenerInstanceId !== "string" || !UUID_RE19.test(row.listenerInstanceId) || row.listenerInstanceId !== row.listenerInstanceId.toLowerCase()) {
39484
+ if (typeof row.listenerInstanceId !== "string" || !UUID_RE20.test(row.listenerInstanceId) || row.listenerInstanceId !== row.listenerInstanceId.toLowerCase()) {
39326
39485
  throw new Error("stored delivery journal is malformed");
39327
39486
  }
39328
39487
  if (!Number.isSafeInteger(row.nextClaimOrdinal) || row.nextClaimOrdinal < 0) {
@@ -39396,10 +39555,10 @@ function parseJournalRecord(raw, expectedWorkspaceId, expectedPrincipalId, rejec
39396
39555
  if (active.claimLastAttemptAt === null) {
39397
39556
  throw new Error("stored delivery journal is malformed");
39398
39557
  }
39399
- if (typeof active.signalId !== "string" || !UUID_RE19.test(active.signalId) || active.signalId !== active.signalId.toLowerCase()) {
39558
+ if (typeof active.signalId !== "string" || !UUID_RE20.test(active.signalId) || active.signalId !== active.signalId.toLowerCase()) {
39400
39559
  throw new Error("stored delivery journal is malformed");
39401
39560
  }
39402
- if (typeof active.leaseId !== "string" || !UUID_RE19.test(active.leaseId) || active.leaseId !== active.leaseId.toLowerCase()) {
39561
+ if (typeof active.leaseId !== "string" || !UUID_RE20.test(active.leaseId) || active.leaseId !== active.leaseId.toLowerCase()) {
39403
39562
  throw new Error("stored delivery journal is malformed");
39404
39563
  }
39405
39564
  if (!isValidIsoTimestamp(active.leasedUntil) || Date.parse(active.leasedUntil) <= Date.parse(active.claimCreatedAt)) {
@@ -39491,7 +39650,7 @@ var FileListenerDeliveryJournal = class {
39491
39650
  ["profileId", "workspaceId", "principalId"],
39492
39651
  "delivery journal configuration rejected"
39493
39652
  );
39494
- if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !UUID_RE19.test(options.workspaceId) || typeof options.principalId !== "string" || !UUID_RE19.test(options.principalId)) {
39653
+ if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !UUID_RE20.test(options.workspaceId) || typeof options.principalId !== "string" || !UUID_RE20.test(options.principalId)) {
39495
39654
  throw new Error("delivery journal configuration rejected");
39496
39655
  }
39497
39656
  if (options.stateDirectory !== void 0) {
@@ -39613,7 +39772,7 @@ var FileListenerDeliveryJournal = class {
39613
39772
  ["signalId", "leaseId", "leasedUntil"],
39614
39773
  "delivery journal mutation rejected"
39615
39774
  );
39616
- if (typeof input.signalId !== "string" || !UUID_RE19.test(input.signalId) || typeof input.leaseId !== "string" || !UUID_RE19.test(input.leaseId) || !isValidIsoTimestamp(input.leasedUntil) || input.signalFingerprint !== void 0 && (typeof input.signalFingerprint !== "string" || !SIGNAL_FINGERPRINT_RE.test(input.signalFingerprint))) {
39775
+ if (typeof input.signalId !== "string" || !UUID_RE20.test(input.signalId) || typeof input.leaseId !== "string" || !UUID_RE20.test(input.leaseId) || !isValidIsoTimestamp(input.leasedUntil) || input.signalFingerprint !== void 0 && (typeof input.signalFingerprint !== "string" || !SIGNAL_FINGERPRINT_RE.test(input.signalFingerprint))) {
39617
39776
  throw new Error("delivery journal mutation rejected");
39618
39777
  }
39619
39778
  const canonicalSignalId = input.signalId.toLowerCase();
@@ -39745,7 +39904,7 @@ async function openListenerDeliveryJournal(options) {
39745
39904
  ["profileId", "workspaceId", "principalId", "proposedListenerInstanceId"],
39746
39905
  "delivery journal configuration rejected"
39747
39906
  );
39748
- if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !UUID_RE19.test(options.workspaceId) || typeof options.principalId !== "string" || !UUID_RE19.test(options.principalId) || typeof options.proposedListenerInstanceId !== "string" || !UUID_RE19.test(options.proposedListenerInstanceId)) {
39907
+ if (typeof options.profileId !== "string" || !options.profileId || options.profileId.includes("\0") || typeof options.workspaceId !== "string" || !UUID_RE20.test(options.workspaceId) || typeof options.principalId !== "string" || !UUID_RE20.test(options.principalId) || typeof options.proposedListenerInstanceId !== "string" || !UUID_RE20.test(options.proposedListenerInstanceId)) {
39749
39908
  throw new Error("delivery journal configuration rejected");
39750
39909
  }
39751
39910
  if (options.stateDirectory !== void 0) {
@@ -39965,7 +40124,7 @@ var import_node_path20 = require("node:path");
39965
40124
 
39966
40125
  // src/listener/brain-digest.ts
39967
40126
  var import_node_path19 = require("node:path");
39968
- var UUID_RE20 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
40127
+ var UUID_RE21 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
39969
40128
  var TOPIC_RE = /^[a-z0-9][a-z0-9._-]*$/;
39970
40129
  var BRAIN_DIGEST_FILE = "brain-digest.json";
39971
40130
  var BRAIN_DIGEST_LOCK = "brain-digest";
@@ -39985,7 +40144,7 @@ function parseState(raw) {
39985
40144
  }
39986
40145
  const row = value;
39987
40146
  const topicVersions = row.topicVersions;
39988
- if (row.version !== 1 || typeof row.principalId !== "string" || !UUID_RE20.test(row.principalId) || !topicVersions || typeof topicVersions !== "object" || Array.isArray(topicVersions) || Object.keys(topicVersions).length > MAX_BRAIN_DIGEST_TOPICS) {
40147
+ if (row.version !== 1 || typeof row.principalId !== "string" || !UUID_RE21.test(row.principalId) || !topicVersions || typeof topicVersions !== "object" || Array.isArray(topicVersions) || Object.keys(topicVersions).length > MAX_BRAIN_DIGEST_TOPICS) {
39989
40148
  throw new Error("stored brain digest state is malformed");
39990
40149
  }
39991
40150
  for (const [topic, version3] of Object.entries(topicVersions)) {
@@ -40028,7 +40187,7 @@ function renderBrainDigest(topicCount, topics) {
40028
40187
  var FileBrainDigestStore = class {
40029
40188
  constructor(instanceDirectory, principalId) {
40030
40189
  this.instanceDirectory = instanceDirectory;
40031
- if (!(0, import_node_path19.isAbsolute)(instanceDirectory) || !UUID_RE20.test(principalId)) {
40190
+ if (!(0, import_node_path19.isAbsolute)(instanceDirectory) || !UUID_RE21.test(principalId)) {
40032
40191
  throw new Error("brain digest state needs an absolute listener directory and principal UUID");
40033
40192
  }
40034
40193
  this.principalId = principalId.toLowerCase();
@@ -40075,7 +40234,7 @@ var FileBrainDigestStore = class {
40075
40234
  };
40076
40235
 
40077
40236
  // src/listener/hook.ts
40078
- var UUID_RE21 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
40237
+ var UUID_RE22 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
40079
40238
  var TOKEN_RE = /^swm_agt_[A-Za-z0-9_-]{43}$/;
40080
40239
  var INSTANCE_KEY_RE = /^[0-9a-f]{64}$/;
40081
40240
  var MAX_HOOK_CREDENTIAL_BYTES = 8 * 1024;
@@ -40127,7 +40286,7 @@ function parseListenerCredential(raw, rejectUnknownKeys = false) {
40127
40286
  throw new Error("stored listener hook credential is malformed");
40128
40287
  }
40129
40288
  const row = value;
40130
- if (!(rejectUnknownKeys ? exactKeys2(row, LISTENER_CREDENTIAL_KEYS) : hasRequiredKeys(row, LISTENER_CREDENTIAL_KEYS)) || row.version !== 1 || typeof row.profileId !== "string" || !/^[0-9a-f]{24}$/.test(row.profileId) || typeof row.targetUrl !== "string" || typeof row.anonKey !== "string" || row.anonKey.length < 1 || row.anonKey.length > 4096 || typeof row.workspaceId !== "string" || !UUID_RE21.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE21.test(row.principalId) || typeof row.credential !== "string" || !TOKEN_RE.test(row.credential) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt))) {
40289
+ if (!(rejectUnknownKeys ? exactKeys2(row, LISTENER_CREDENTIAL_KEYS) : hasRequiredKeys(row, LISTENER_CREDENTIAL_KEYS)) || row.version !== 1 || typeof row.profileId !== "string" || !/^[0-9a-f]{24}$/.test(row.profileId) || typeof row.targetUrl !== "string" || typeof row.anonKey !== "string" || row.anonKey.length < 1 || row.anonKey.length > 4096 || typeof row.workspaceId !== "string" || !UUID_RE22.test(row.workspaceId) || typeof row.principalId !== "string" || !UUID_RE22.test(row.principalId) || typeof row.credential !== "string" || !TOKEN_RE.test(row.credential) || typeof row.updatedAt !== "string" || !Number.isFinite(Date.parse(row.updatedAt))) {
40131
40290
  throw new Error("stored listener hook credential is malformed");
40132
40291
  }
40133
40292
  const target2 = cloudTarget(row.targetUrl, row.anonKey);
@@ -40185,7 +40344,7 @@ function parseSurface(raw, rejectUnknownKeys = false) {
40185
40344
  throw new Error("stored listener hook surface state is malformed");
40186
40345
  }
40187
40346
  const row = value;
40188
- if (rejectUnknownKeys && Object.keys(row).some((key2) => !HOOK_SURFACE_KEYS.has(key2)) || row.version !== 1 || !Array.isArray(row.surfacedSignalIds) || row.surfacedSignalIds.length > HOOK_SURFACED_IDS_MAX || row.surfacedSignalIds.some((id) => typeof id !== "string" || !UUID_RE21.test(id)) || !(row.reportedDroppedCount === void 0 || typeof row.reportedDroppedCount === "number" && Number.isSafeInteger(row.reportedDroppedCount) && row.reportedDroppedCount >= 0) || !(row.credentialFailureReported === void 0 || typeof row.credentialFailureReported === "boolean")) {
40347
+ if (rejectUnknownKeys && Object.keys(row).some((key2) => !HOOK_SURFACE_KEYS.has(key2)) || row.version !== 1 || !Array.isArray(row.surfacedSignalIds) || row.surfacedSignalIds.length > HOOK_SURFACED_IDS_MAX || row.surfacedSignalIds.some((id) => typeof id !== "string" || !UUID_RE22.test(id)) || !(row.reportedDroppedCount === void 0 || typeof row.reportedDroppedCount === "number" && Number.isSafeInteger(row.reportedDroppedCount) && row.reportedDroppedCount >= 0) || !(row.credentialFailureReported === void 0 || typeof row.credentialFailureReported === "boolean")) {
40189
40348
  throw new Error("stored listener hook surface state is malformed");
40190
40349
  }
40191
40350
  const ids = row.surfacedSignalIds.map((id) => String(id).toLowerCase());
@@ -40216,7 +40375,7 @@ var FileHookSurfaceStore = class {
40216
40375
  const unseen = [];
40217
40376
  for (const item of items) {
40218
40377
  const signalId = item.signalId.toLowerCase();
40219
- if (!UUID_RE21.test(signalId) || seen.has(signalId)) continue;
40378
+ if (!UUID_RE22.test(signalId) || seen.has(signalId)) continue;
40220
40379
  seen.add(signalId);
40221
40380
  unseen.push(item);
40222
40381
  }
@@ -40247,7 +40406,7 @@ var FileHookSurfaceStore = class {
40247
40406
  const unseen = [];
40248
40407
  for (const item of items) {
40249
40408
  const signalId = item.signalId.toLowerCase();
40250
- if (!UUID_RE21.test(signalId) || seen.has(signalId)) continue;
40409
+ if (!UUID_RE22.test(signalId) || seen.has(signalId)) continue;
40251
40410
  seen.add(signalId);
40252
40411
  unseen.push(item);
40253
40412
  }
@@ -40270,7 +40429,7 @@ var FileHookSurfaceStore = class {
40270
40429
  const seen = new Set(state.surfacedSignalIds);
40271
40430
  for (const signalId of options.signalIds ?? []) {
40272
40431
  const checked = signalId.toLowerCase();
40273
- if (UUID_RE21.test(checked)) seen.add(checked);
40432
+ if (UUID_RE22.test(checked)) seen.add(checked);
40274
40433
  }
40275
40434
  await writeSecureJsonFile(
40276
40435
  this.path,
@@ -40399,7 +40558,7 @@ async function discoverContexts(stateDirectory2, principalIds, isListenerLive =
40399
40558
  }
40400
40559
  selectedPrincipals = availablePrincipals;
40401
40560
  } else {
40402
- if (principalIds.some((principalId) => !UUID_RE21.test(principalId))) {
40561
+ if (principalIds.some((principalId) => !UUID_RE22.test(principalId))) {
40403
40562
  return { contexts: [], requiresPrincipalScope: false };
40404
40563
  }
40405
40564
  selectedPrincipals = new Set(principalIds.map((principalId) => principalId.toLowerCase()));
@@ -41828,16 +41987,10 @@ var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
41828
41987
  "user",
41829
41988
  "write"
41830
41989
  ]);
41831
- var UUID_RE22 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
41832
- var AGENT_CREDENTIAL_MESSAGE = "Agent credential minted. It is bound to this task and run so the agent's work stays scoped and attributable.";
41833
- var AGENT_CREDENTIAL_MESSAGE_D088 = "Agent credential minted. It is bound to this run, so the agent's work is attributable to it.";
41834
- var ACCEPTED_AGENT_CREDENTIAL_MESSAGES = [
41835
- AGENT_CREDENTIAL_MESSAGE,
41836
- AGENT_CREDENTIAL_MESSAGE_D088
41837
- ];
41990
+ var UUID_RE23 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
41838
41991
  function packageVersion() {
41839
- if ("0.1.49".length > 0) {
41840
- return "0.1.49";
41992
+ if ("0.1.50".length > 0) {
41993
+ return "0.1.50";
41841
41994
  }
41842
41995
  try {
41843
41996
  const value = JSON.parse(
@@ -42182,58 +42335,6 @@ function agentCredentialArtifact(input) {
42182
42335
  ...input.expiresAt === void 0 || input.expiresAt === null ? {} : { expires_at: new Date(input.expiresAt).toISOString() }
42183
42336
  };
42184
42337
  }
42185
- function parsedAgentCredential(value) {
42186
- if (!value.startsWith("{")) {
42187
- assertAgentToken(value);
42188
- return {
42189
- token: value,
42190
- principalId: null,
42191
- tokenId: null,
42192
- runId: null,
42193
- expiresAt: null,
42194
- durable: false
42195
- };
42196
- }
42197
- const parsed = JSON.parse(value);
42198
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
42199
- throw new Error("agent credential JSON is malformed");
42200
- }
42201
- const artifact = parsed;
42202
- const requiredKeys = [
42203
- "agent_token",
42204
- "message",
42205
- "principal_id",
42206
- "run_id",
42207
- "status",
42208
- "token_id"
42209
- ];
42210
- const withExpiry = [...requiredKeys, "expires_at"].sort();
42211
- const actualKeys = Object.keys(artifact).sort();
42212
- const shape = actualKeys.length === requiredKeys.length ? requiredKeys : withExpiry;
42213
- if (actualKeys.length !== shape.length || !actualKeys.every((key2, index) => key2 === shape[index]) || !ACCEPTED_AGENT_CREDENTIAL_MESSAGES.includes(artifact.message) || artifact.status !== "accepted" || typeof artifact.principal_id !== "string" || !UUID_RE22.test(artifact.principal_id) || typeof artifact.token_id !== "string" || !UUID_RE22.test(artifact.token_id) || typeof artifact.run_id !== "string" || !UUID_RE22.test(artifact.run_id) || typeof artifact.agent_token !== "string") {
42214
- throw new Error("agent credential JSON is malformed");
42215
- }
42216
- let expiresAt = null;
42217
- if (artifact.expires_at !== void 0) {
42218
- if (typeof artifact.expires_at !== "string") {
42219
- throw new Error("agent credential JSON is malformed");
42220
- }
42221
- const parsedExpiry = Date.parse(artifact.expires_at);
42222
- if (Number.isNaN(parsedExpiry)) {
42223
- throw new Error("agent credential JSON is malformed");
42224
- }
42225
- expiresAt = parsedExpiry;
42226
- }
42227
- assertAgentToken(artifact.agent_token);
42228
- return {
42229
- token: artifact.agent_token,
42230
- principalId: artifact.principal_id.toLowerCase(),
42231
- tokenId: artifact.token_id.toLowerCase(),
42232
- runId: artifact.run_id.toLowerCase(),
42233
- expiresAt,
42234
- durable: true
42235
- };
42236
- }
42237
42338
  async function stdinCredential() {
42238
42339
  if (process.stdin.isTTY) {
42239
42340
  throw new Error(
@@ -42248,7 +42349,7 @@ async function stdinCredential() {
42248
42349
  }
42249
42350
  }
42250
42351
  const credential = value.trim();
42251
- return parsedAgentCredential(credential);
42352
+ return parseAgentCredentialInput(credential, { kind: "stdin" });
42252
42353
  }
42253
42354
  var AgentTokenFileError = class extends Error {
42254
42355
  constructor(code, message) {
@@ -42286,7 +42387,10 @@ async function agentCredential(args, options = {}) {
42286
42387
  `--agent-token-file does not exist: ${fromFile}`
42287
42388
  );
42288
42389
  }
42289
- return parsedAgentCredential(value.trim());
42390
+ return parseAgentCredentialInput(value.trim(), {
42391
+ kind: "file",
42392
+ path: fromFile
42393
+ });
42290
42394
  }
42291
42395
  if (fromStdin || options.implicitStdin === true) {
42292
42396
  return await stdinCredential();
@@ -42354,6 +42458,18 @@ async function humanCredential(args, cloud) {
42354
42458
  store: credentials
42355
42459
  };
42356
42460
  }
42461
+ async function dualAuthHumanCredential(args, cloud) {
42462
+ try {
42463
+ return await humanCredential(args, cloud);
42464
+ } catch (error) {
42465
+ if (!(error instanceof HumanSessionError)) throw error;
42466
+ const personPath = error.code === "human_session_missing" ? "not signed in. If you are a person, run cswarm login." : "could not refresh your session. If you are a person, run cswarm login to sign in again.";
42467
+ throw new HumanSessionError(
42468
+ error.code,
42469
+ `${personPath} If you are an agent, pass --agent-token-file <path to the credential CommonSwarm minted for you> (or --agent-token-stdin).`
42470
+ );
42471
+ }
42472
+ }
42357
42473
  function writeWorkspaceWarning(warning) {
42358
42474
  process.stderr.write(`cswarm: ${warning.message}
42359
42475
  `);
@@ -42493,7 +42609,7 @@ async function runNew(args) {
42493
42609
  project: {
42494
42610
  workspace_id: created,
42495
42611
  name,
42496
- stream_id: typeof response.stream_id === "string" && UUID_RE22.test(response.stream_id) ? response.stream_id : null
42612
+ stream_id: typeof response.stream_id === "string" && UUID_RE23.test(response.stream_id) ? response.stream_id : null
42497
42613
  }
42498
42614
  });
42499
42615
  return;
@@ -43235,7 +43351,7 @@ async function runTokenRevoke(args) {
43235
43351
  2
43236
43352
  );
43237
43353
  const cloud = await target(args);
43238
- const human = await humanCredential(args, cloud);
43354
+ const human = await dualAuthHumanCredential(args, cloud);
43239
43355
  const workspace = await workspaceId(args, cloud, human);
43240
43356
  const tokenId = args.required("token-id");
43241
43357
  const response = (await sendConnectWithPending(
@@ -43302,7 +43418,7 @@ async function runLinkNew(args) {
43302
43418
  2
43303
43419
  );
43304
43420
  const taskId = args.required("task-id");
43305
- if (!UUID_RE22.test(taskId)) {
43421
+ if (!UUID_RE23.test(taskId)) {
43306
43422
  throw new Error("--task-id must be the work item's UUID");
43307
43423
  }
43308
43424
  const site = capabilitySiteOrigin(
@@ -43362,7 +43478,7 @@ async function runLinkRevoke(args) {
43362
43478
  2
43363
43479
  );
43364
43480
  const capabilityId = args.required("capability-id");
43365
- if (!UUID_RE22.test(capabilityId)) {
43481
+ if (!UUID_RE23.test(capabilityId)) {
43366
43482
  throw new Error(
43367
43483
  "--capability-id must be the id printed when the link was created"
43368
43484
  );
@@ -43535,7 +43651,7 @@ async function commandWorkspaceAndCredential(args, cloud, options = {}) {
43535
43651
  session
43536
43652
  };
43537
43653
  }
43538
- const human = await humanCredential(args, cloud);
43654
+ const human = await dualAuthHumanCredential(args, cloud);
43539
43655
  return {
43540
43656
  selectedWorkspace: await workspaceId(args, cloud, human, {
43541
43657
  validateOverride: options.validateHumanWorkspace ?? false
@@ -44037,7 +44153,7 @@ async function runReply(args) {
44037
44153
  "json"
44038
44154
  ], 3);
44039
44155
  const signalId = args.positionals[1];
44040
- if (signalId === void 0 || !UUID_RE22.test(signalId)) {
44156
+ if (signalId === void 0 || !UUID_RE23.test(signalId)) {
44041
44157
  throw new Error("reply requires the signal UUID being answered");
44042
44158
  }
44043
44159
  const body = args.positionals[2];
@@ -44582,7 +44698,7 @@ async function runReceipt(args) {
44582
44698
  "json"
44583
44699
  ], 2);
44584
44700
  const signalId = args.positionals[1];
44585
- if (!UUID_RE22.test(signalId)) {
44701
+ if (!UUID_RE23.test(signalId)) {
44586
44702
  throw new Error("signal-id must be a UUID");
44587
44703
  }
44588
44704
  if (!hasAgentCredential(args)) {
@@ -44742,7 +44858,7 @@ async function runInboxFollowCommand(args) {
44742
44858
  }
44743
44859
  }
44744
44860
  function listenerUuid(value, flag) {
44745
- if (!value || !UUID_RE22.test(value)) {
44861
+ if (!value || !UUID_RE23.test(value)) {
44746
44862
  throw new Error(`--${flag} must be a UUID`);
44747
44863
  }
44748
44864
  return value.toLowerCase();
@@ -46405,7 +46521,7 @@ async function runHook(args) {
46405
46521
  if (command2 === "check") {
46406
46522
  args.assertShape(["cooldown", "principal-id"], 2);
46407
46523
  const rawPrincipalIds = args.all("principal-id");
46408
- if (rawPrincipalIds.some((principalId2) => !UUID_RE22.test(principalId2))) return;
46524
+ if (rawPrincipalIds.some((principalId2) => !UUID_RE23.test(principalId2))) return;
46409
46525
  const principalIds = rawPrincipalIds.map((principalId2) => principalId2.toLowerCase());
46410
46526
  const rawCooldown = args.optional("cooldown");
46411
46527
  const cooldownSeconds = rawCooldown === void 0 ? void 0 : Number(rawCooldown);
@@ -46531,7 +46647,7 @@ async function fileRows(context) {
46531
46647
  );
46532
46648
  }
46533
46649
  async function resolveFileSelector(context, selector) {
46534
- if (UUID_RE22.test(selector)) return selector.toLowerCase();
46650
+ if (UUID_RE23.test(selector)) return selector.toLowerCase();
46535
46651
  const rows3 = await fileRows(context);
46536
46652
  const match = rows3.find(
46537
46653
  (row) => row.name.toLowerCase() === selector.toLowerCase()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commonswarm",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "description": "CommonSwarm CLI — coordination for teams where people and AI agents work side by side.",
5
5
  "bin": {
6
6
  "cswarm": "cswarm.cjs"