@sjawhar/claude-envoy 6.4.0 → 6.5.1

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.
@@ -37123,21 +37123,22 @@ var ISSUE_UPDATE_OPTIONS_RULE = "include_children, unlink_children and include_p
37123
37123
  var ISSUE_UPDATE_RULE = `${ISSUE_UPDATE_FIELDS_RULE} ${ISSUE_UPDATE_DONE_RULE}; ${ISSUE_UPDATE_REASON_RULE}; ${ISSUE_UPDATE_LABELS_RULE}. ${ISSUE_UPDATE_OPTIONS_RULE}`;
37124
37124
  function issueStatusOptionsProblem(input) {
37125
37125
  const options = issueStatusOptionsOf(input);
37126
+ const optionInput = input;
37126
37127
  if (options.length === 0)
37127
37128
  return;
37128
37129
  const named = options.join(", ").replace(/, ([^,]*)$/, " and $1");
37129
37130
  const others = ISSUE_UPDATE_PATCH_FIELDS.filter((field) => input[field] !== undefined);
37130
37131
  return brokenParts([
37131
37132
  [
37132
- !(input["include_children"] === true && input["unlink_children"] === true),
37133
+ !(optionInput.include_children === true && optionInput.unlink_children === true),
37133
37134
  "include_children does not go with unlink_children. The open children move with the issue or leave it, so name one of the two."
37134
37135
  ],
37135
37136
  [
37136
- !(input["include_children"] === true && input["status"] === "done"),
37137
+ !(optionInput.include_children === true && optionInput.status === "done"),
37137
37138
  "include_children does not go with status done. Only a person who is signed in at a browser can close the open issues under an issue together with it, and this call presents a token. That person does it on the issue's page in Dispatch: Close issue, then Move them with it."
37138
37139
  ],
37139
37140
  [
37140
- typeof input["status"] === "string",
37141
+ typeof optionInput.status === "string",
37141
37142
  `status is required with ${named}. Add status, or drop ${named}.`
37142
37143
  ],
37143
37144
  [
@@ -37290,8 +37291,8 @@ var RESULT_SHAPE_RULE = `${RESULT_RETRACT_RULE} A call with retract takes reason
37290
37291
  function resultProblem(value) {
37291
37292
  const input = value;
37292
37293
  const carried = RESULT_RECORD_FIELDS.filter((field) => input[field] !== undefined);
37293
- if (typeof input["retract"] === "string") {
37294
- const reason = input["reason"];
37294
+ if (typeof input.retract === "string") {
37295
+ const reason = input.reason;
37295
37296
  if (typeof reason !== "string" || reason.trim() === "") {
37296
37297
  return "retract needs reason, the words that say why the result is wrong.";
37297
37298
  }
@@ -37300,7 +37301,7 @@ function resultProblem(value) {
37300
37301
  }
37301
37302
  return;
37302
37303
  }
37303
- if (input["reason"] !== undefined) {
37304
+ if (input.reason !== undefined) {
37304
37305
  return "reason goes with retract, and this call carries no retract. Name the result to retract, or drop reason.";
37305
37306
  }
37306
37307
  const missing = RESULT_REQUIRED_FIELDS.filter((field) => input[field] === undefined);
@@ -38769,6 +38770,52 @@ var DispatchTargetedDeliverySchema = union([
38769
38770
  DispatchTargetedCommentDeliverySchema,
38770
38771
  DispatchTargetedMessageDeliverySchema
38771
38772
  ]);
38773
+ function isCommentTargetedDelivery(delivery) {
38774
+ return "comment_id" in delivery;
38775
+ }
38776
+ var DispatchTargetedFrameSchema = object({
38777
+ event: DispatchEventSchema,
38778
+ delivery: DispatchTargetedDeliverySchema
38779
+ }).superRefine(({ event, delivery }, context) => {
38780
+ if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
38781
+ return;
38782
+ }
38783
+ if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
38784
+ return;
38785
+ }
38786
+ context.addIssue({
38787
+ code: "custom",
38788
+ message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
38789
+ });
38790
+ });
38791
+ var RecoverableDispatchDeliveryFailureSchema = object({
38792
+ event: object({
38793
+ type: _enum2(["message.created", "comment.created"]),
38794
+ issue_key: string2().nullable(),
38795
+ payload: object({ id: string2(), body: string2().optional() }).passthrough()
38796
+ }).passthrough(),
38797
+ delivery: DispatchTargetedDeliverySchema
38798
+ }).refine(({ event, delivery }) => event.type === "comment.created" ? isCommentTargetedDelivery(delivery) : !isCommentTargetedDelivery(delivery) && DispatchTargetedResourceIDSchema.safeParse(event.payload.id).success, { message: "delivery resource must match its event type" });
38799
+ function readDispatchPayload(value) {
38800
+ if (typeof value === "object" && value !== null && "delivery" in value) {
38801
+ const targeted = DispatchTargetedFrameSchema.safeParse(value);
38802
+ if (targeted.success) {
38803
+ const { event: wireEvent } = value;
38804
+ return {
38805
+ kind: "event",
38806
+ event: targeted.data.event,
38807
+ wireEvent,
38808
+ delivery: targeted.data.delivery
38809
+ };
38810
+ }
38811
+ const recovered = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
38812
+ if (recovered.success)
38813
+ return { kind: "recovered", failure: recovered.data };
38814
+ return { kind: "raw", targeted: true };
38815
+ }
38816
+ const parsed = DispatchEventSchema.safeParse(value);
38817
+ return parsed.success ? { kind: "event", event: parsed.data, wireEvent: value } : { kind: "raw", targeted: false };
38818
+ }
38772
38819
  // ../contracts/src/dispatch-api-user.ts
38773
38820
  var UserIssueStateSchema = strictObject({
38774
38821
  pinned: boolean2(),
@@ -46843,9 +46890,6 @@ function reachedNothing(error) {
46843
46890
  }
46844
46891
 
46845
46892
  class LoggableError extends Error {
46846
- constructor(message) {
46847
- super(message);
46848
- }
46849
46893
  }
46850
46894
  var SERVER_REFUSALS = [
46851
46895
  "Authorization Violation",
@@ -52632,7 +52676,7 @@ function parseFrameJSON(text) {
52632
52676
  const containers = typeof value === "object" && value !== null ? [value] : [];
52633
52677
  for (let next = containers.pop();next !== undefined; next = containers.pop()) {
52634
52678
  const members = next;
52635
- delete members["__proto__"];
52679
+ Reflect.deleteProperty(members, "__proto__");
52636
52680
  let names = Object.keys(members);
52637
52681
  if (names.some((name) => name.search(LONE_SURROGATE) !== -1)) {
52638
52682
  const held = names.map((name) => members[name]);
@@ -52864,32 +52908,6 @@ function createDeliveryDedupe(now = Date.now) {
52864
52908
  }
52865
52909
  };
52866
52910
  }
52867
- function isCommentTargetedDelivery(delivery) {
52868
- return "comment_id" in delivery;
52869
- }
52870
- var DispatchTargetedFrameSchema = object({
52871
- event: DispatchEventSchema,
52872
- delivery: DispatchTargetedDeliverySchema
52873
- }).superRefine(({ event, delivery }, context) => {
52874
- if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
52875
- return;
52876
- }
52877
- if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
52878
- return;
52879
- }
52880
- context.addIssue({
52881
- code: "custom",
52882
- message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
52883
- });
52884
- });
52885
- var RecoverableDispatchDeliveryFailureSchema = object({
52886
- event: object({
52887
- type: _enum2(["message.created", "comment.created"]),
52888
- issue_key: string2().nullable(),
52889
- payload: object({ id: string2(), body: string2().optional() }).passthrough()
52890
- }).passthrough(),
52891
- delivery: DispatchTargetedDeliverySchema
52892
- }).refine(({ event, delivery }) => event.type === "comment.created" ? isCommentTargetedDelivery(delivery) : !isCommentTargetedDelivery(delivery) && DispatchTargetedResourceIDSchema.safeParse(event.payload.id).success, { message: "delivery resource must match its event type" });
52893
52911
  function eventPictures(event) {
52894
52912
  let text;
52895
52913
  if (event.type.startsWith("message.")) {
@@ -52921,16 +52939,22 @@ function carriedItem(event) {
52921
52939
  const resource = event.type.startsWith("comment.") || event.type.startsWith("suggestion.") ? "comment" : event.type.startsWith("message.") ? "message" : undefined;
52922
52940
  if (resource === undefined || !isObject3(event.payload))
52923
52941
  return;
52924
- const id = event.payload["id"];
52942
+ const { id } = event.payload;
52925
52943
  if (typeof id !== "string" || id === "")
52926
52944
  return;
52927
52945
  return { resource, id, issueKey: event.issue_key };
52928
52946
  }
52929
52947
  function payloadWasOmitted(payload) {
52930
- return isObject3(payload) && payload["payload_omitted"] === true;
52948
+ if (!isObject3(payload))
52949
+ return false;
52950
+ const { payload_omitted } = payload;
52951
+ return payload_omitted === true;
52931
52952
  }
52932
52953
  function bodyWasCut(payload) {
52933
- return isObject3(payload) && payload["body_truncated"] === true || payloadWasOmitted(payload);
52954
+ if (!isObject3(payload))
52955
+ return false;
52956
+ const { body_truncated } = payload;
52957
+ return body_truncated === true || payloadWasOmitted(payload);
52934
52958
  }
52935
52959
  function wholeItemRoute(item) {
52936
52960
  return `GET /api/v1/${item.resource === "comment" ? "comments" : "messages"}/${item.id}`;
@@ -53175,7 +53199,10 @@ var DISPATCH_BOOKKEEPING = new Set([
53175
53199
  ]);
53176
53200
  function dispatchPayloadForReader(event, sessionID, issuedAt, toReader) {
53177
53201
  const whole = dispatchPayload(event);
53178
- const changed = event.type !== "issue.created" && isObject3(whole) && Array.isArray(whole["changed"]) ? whole["changed"] : [];
53202
+ let changedField;
53203
+ if (event.type !== "issue.created" && isObject3(whole))
53204
+ ({ changed: changedField } = whole);
53205
+ const changed = Array.isArray(changedField) ? changedField : [];
53179
53206
  const payload = withoutEmptyFields(whole, (key, item) => changed.includes(key) || (key === "suggestion" || key === "forced") && item !== null && item !== undefined);
53180
53207
  if (!isObject3(payload) || Array.isArray(payload))
53181
53208
  return payload;
@@ -53290,27 +53317,25 @@ function parseDispatchFrame(rawPayload, wholeBody) {
53290
53317
  try {
53291
53318
  value = parseFrameJSON(rawPayload);
53292
53319
  } catch {
53293
- return { raw: rawPayload };
53320
+ return {};
53294
53321
  }
53295
- if (isObject3(value) && "delivery" in value) {
53296
- const targeted = DispatchTargetedFrameSchema.safeParse(value);
53297
- if (targeted.success) {
53298
- const wireFrame = value;
53322
+ const reading = readDispatchPayload(value);
53323
+ switch (reading.kind) {
53324
+ case "event": {
53325
+ const { notify, quiet } = reading.wireEvent;
53299
53326
  return {
53300
- event: withWholeBody(targeted.data.event, wholeBody),
53301
- notify: wireFrame.event.notify,
53302
- quiet: wireFrame.event.quiet,
53303
- delivery: targeted.data.delivery
53327
+ event: withWholeBody(reading.event, wholeBody),
53328
+ notify,
53329
+ quiet,
53330
+ delivery: reading.delivery
53304
53331
  };
53305
53332
  }
53306
- const recoverable = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
53307
- if (recoverable.success) {
53308
- const delivery = recoverable.data.delivery;
53333
+ case "recovered": {
53334
+ const { delivery, event } = reading.failure;
53309
53335
  const commentDelivery = isCommentTargetedDelivery(delivery);
53310
53336
  const resource = commentDelivery ? "comment" : "message";
53311
- const id = commentDelivery ? delivery.comment_id : recoverable.data.event.payload.id;
53337
+ const id = commentDelivery ? delivery.comment_id : event.payload.id;
53312
53338
  return {
53313
- raw: value,
53314
53339
  rejectedDelivery: {
53315
53340
  resource,
53316
53341
  id,
@@ -53318,24 +53343,15 @@ function parseDispatchFrame(rawPayload, wholeBody) {
53318
53343
  mode: delivery.mode,
53319
53344
  replyPath: dispatchReplyPath(resource, id),
53320
53345
  replyFields: commentDelivery ? { target: delivery.target } : {},
53321
- issueKey: recoverable.data.event.issue_key,
53322
- body: recoverable.data.event.payload.body ?? ""
53346
+ issueKey: event.issue_key,
53347
+ body: event.payload.body ?? ""
53323
53348
  },
53324
53349
  malformedDelivery: true
53325
53350
  };
53326
53351
  }
53327
- return { raw: value, malformedDelivery: true };
53352
+ case "raw":
53353
+ return reading.targeted ? { malformedDelivery: true } : {};
53328
53354
  }
53329
- const parsed = DispatchEventSchema.safeParse(value);
53330
- if (!parsed.success)
53331
- return { raw: value };
53332
- const wireEvent = value;
53333
- return {
53334
- event: withWholeBody(parsed.data, wholeBody),
53335
- notify: wireEvent.notify,
53336
- quiet: wireEvent.quiet,
53337
- delivery: undefined
53338
- };
53339
53355
  }
53340
53356
  var INBOUND_CARD_MAX_BYTES = 1 << 20;
53341
53357
  function encodeWithin(value, maxBytes) {
@@ -53350,6 +53366,28 @@ function encodeWithin(value, maxBytes) {
53350
53366
  return lines.join(`
53351
53367
  `);
53352
53368
  }
53369
+ function headerActor(actor) {
53370
+ const { kind, id, act, service } = actor;
53371
+ return {
53372
+ kind,
53373
+ ...id === undefined ? {} : { id },
53374
+ ...act === undefined ? {} : { act: ActorActSchema.safeParse(act).data ?? "not shown" },
53375
+ ...kind !== "session" || service === undefined ? {} : { service: typeof service === "string" ? service : "not shown" }
53376
+ };
53377
+ }
53378
+ function dispatchCardAsText(rendered, event, reason, bound) {
53379
+ let text;
53380
+ try {
53381
+ text = JSON.stringify(event);
53382
+ } catch {}
53383
+ const asText = text === undefined ? undefined : encodeWithin({ envoy: { ...rendered, dispatch: text } }, bound);
53384
+ if (asText !== undefined)
53385
+ return asText;
53386
+ const notShown = `not shown: ${reason}`;
53387
+ const owner = event.owner === undefined ? {} : { owner: event.owner };
53388
+ const header = { type: event.type, actor: headerActor(event.actor), payload: notShown };
53389
+ return encodeWithin({ envoy: { ...rendered, dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: header } }, bound) ?? encode5({ envoy: { dispatch: { payload: notShown } } });
53390
+ }
53353
53391
  function inboundTimestamp(milliseconds) {
53354
53392
  if (milliseconds === undefined)
53355
53393
  return "unknown";
@@ -53457,13 +53495,13 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
53457
53495
  dispatchReply = dispatchCommentReplyWith(frame.event, topic, commentPayload);
53458
53496
  if (frame.event.type === "message.created") {
53459
53497
  const message = DispatchTargetedMessagePayloadSchema.safeParse(frame.event.payload);
53460
- const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
53461
- if (message.success && requested.success && !isCommentTargetedDelivery(requested.data)) {
53498
+ const requested = frame.delivery;
53499
+ if (message.success && requested !== undefined && !isCommentTargetedDelivery(requested)) {
53462
53500
  delivery = {
53463
53501
  resource: "message",
53464
53502
  id: message.data.id,
53465
- attempt: requested.data.attempt,
53466
- mode: requested.data.mode,
53503
+ attempt: requested.attempt,
53504
+ mode: requested.mode,
53467
53505
  replyPath: dispatchReplyPath("message", message.data.id),
53468
53506
  replyFields: {},
53469
53507
  issueKey: frame.event.issue_key,
@@ -53481,15 +53519,15 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
53481
53519
  }
53482
53520
  } else if (frame.event.type === "comment.created") {
53483
53521
  const comment = DispatchTargetedCommentPayloadSchema.safeParse(frame.event.payload);
53484
- const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
53485
- if (comment.success && requested.success && isCommentTargetedDelivery(requested.data)) {
53522
+ const requested = frame.delivery;
53523
+ if (comment.success && requested !== undefined && isCommentTargetedDelivery(requested)) {
53486
53524
  delivery = {
53487
53525
  resource: "comment",
53488
- id: requested.data.comment_id,
53489
- attempt: requested.data.attempt,
53490
- mode: requested.data.mode,
53491
- replyPath: dispatchReplyPath("comment", requested.data.comment_id),
53492
- replyFields: { target: requested.data.target },
53526
+ id: requested.comment_id,
53527
+ attempt: requested.attempt,
53528
+ mode: requested.mode,
53529
+ replyPath: dispatchReplyPath("comment", requested.comment_id),
53530
+ replyFields: { target: requested.target },
53493
53531
  issueKey: frame.event.issue_key,
53494
53532
  body: comment.data.body,
53495
53533
  ...comment.data.body_truncated === true ? { bodyTruncated: true } : {}
@@ -53508,7 +53546,9 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
53508
53546
  let actor = frame.event.actor;
53509
53547
  if ("origin" in frame.event.actor) {
53510
53548
  const { origin, ...rest } = frame.event.actor;
53511
- const title = isObject3(origin) ? origin["session_title"] : undefined;
53549
+ let title;
53550
+ if (isObject3(origin))
53551
+ ({ session_title: title } = origin);
53512
53552
  actor = typeof title === "string" && title !== "" ? { ...rest, origin: { session_title: title } } : rest;
53513
53553
  }
53514
53554
  const owner = dispatchOwner(frame.event, topic);
@@ -53530,7 +53570,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
53530
53570
  trailer = humanEditDiffBlock(edit.data.diff, edit.data.diff_truncated);
53531
53571
  }
53532
53572
  } else {
53533
- dispatchEvent = frame.raw;
53573
+ dispatchIssue = "payload";
53534
53574
  rejectedDelivery = frame.rejectedDelivery;
53535
53575
  malformedDelivery = frame.malformedDelivery === true;
53536
53576
  }
@@ -53585,7 +53625,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
53585
53625
  args: { topic: `notifications.role.${role}`, message: "..." }
53586
53626
  }
53587
53627
  },
53588
- ...dispatchRendered ? { dispatch: dispatchEvent } : {
53628
+ ...dispatchRendered ? dispatchEvent === undefined ? {} : { dispatch: dispatchEvent } : {
53589
53629
  ...summaryIsHead ? {} : { summary: payloadSummary },
53590
53630
  ...message === undefined ? {} : { message }
53591
53631
  },
@@ -53595,7 +53635,6 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
53595
53635
  },
53596
53636
  ...unrecognised === undefined ? {} : { unrecognised }
53597
53637
  };
53598
- const payloadKey = dispatchRendered ? "dispatch" : "message";
53599
53638
  const payloadValue = dispatchRendered ? dispatchEvent : message;
53600
53639
  const cardBound = Math.max(INBOUND_CARD_MAX_BYTES, 2 * (Buffer.byteLength(raw) + (wholeBody === undefined ? 0 : Buffer.byteLength(escapeString(wholeBody)))));
53601
53640
  let card;
@@ -53609,7 +53648,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
53609
53648
  }
53610
53649
  if (card === undefined) {
53611
53650
  payloadShownAsText ??= `its layout is larger than the ${cardBound} bytes a card holds`;
53612
- card = encode5({ envoy: { ...rendered, [payloadKey]: envelope.payload } });
53651
+ card = dispatchEvent === undefined ? encode5({ envoy: { ...rendered, message: envelope.payload } }) : dispatchCardAsText(rendered, dispatchEvent, payloadShownAsText, cardBound);
53613
53652
  }
53614
53653
  return {
53615
53654
  skip: false,
@@ -54703,7 +54742,8 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
54703
54742
  if (tool === "dispatch_read" && typeof args.message === "string") {
54704
54743
  return { args, ref, owner: null };
54705
54744
  }
54706
- if (tool === "dispatch_result" && typeof args["retract"] === "string") {
54745
+ const { retract } = args;
54746
+ if (tool === "dispatch_result" && typeof retract === "string") {
54707
54747
  return { args, ref, owner: null };
54708
54748
  }
54709
54749
  const legionIssue = env.LEGION_ISSUE;
@@ -56662,7 +56702,8 @@ async function relatedCommand(context) {
56662
56702
  };
56663
56703
  }
56664
56704
  function printsJson(tool, args) {
56665
- return tool === "dispatch_issues" && args["json"] === true;
56705
+ const { json } = args;
56706
+ return tool === "dispatch_issues" && json === true;
56666
56707
  }
56667
56708
  async function issuesCommand(context) {
56668
56709
  const { args, client, input } = context;
@@ -56728,7 +56769,8 @@ async function issuesCommand(context) {
56728
56769
  };
56729
56770
  }
56730
56771
  function dryRunAsksDispatch(tool, args) {
56731
- return tool === "dispatch_result" && args["retract"] === undefined;
56772
+ const { retract } = args;
56773
+ return tool === "dispatch_result" && retract === undefined;
56732
56774
  }
56733
56775
  async function resultCommand(context) {
56734
56776
  const { args, client, actor } = context;
@@ -66426,7 +66468,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
66426
66468
 
66427
66469
  // package.json
66428
66470
  var name2 = "@sjawhar/claude-envoy";
66429
- var version2 = "6.4.0";
66471
+ var version2 = "6.5.1";
66430
66472
  var package_default = {
66431
66473
  name: name2,
66432
66474
  version: version2,