@sjawhar/claude-envoy 6.5.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.
@@ -17922,21 +17922,22 @@ var ISSUE_UPDATE_OPTIONS_RULE = "include_children, unlink_children and include_p
17922
17922
  var ISSUE_UPDATE_RULE = `${ISSUE_UPDATE_FIELDS_RULE} ${ISSUE_UPDATE_DONE_RULE}; ${ISSUE_UPDATE_REASON_RULE}; ${ISSUE_UPDATE_LABELS_RULE}. ${ISSUE_UPDATE_OPTIONS_RULE}`;
17923
17923
  function issueStatusOptionsProblem(input) {
17924
17924
  const options = issueStatusOptionsOf(input);
17925
+ const optionInput = input;
17925
17926
  if (options.length === 0)
17926
17927
  return;
17927
17928
  const named = options.join(", ").replace(/, ([^,]*)$/, " and $1");
17928
17929
  const others = ISSUE_UPDATE_PATCH_FIELDS.filter((field) => input[field] !== undefined);
17929
17930
  return brokenParts([
17930
17931
  [
17931
- !(input["include_children"] === true && input["unlink_children"] === true),
17932
+ !(optionInput.include_children === true && optionInput.unlink_children === true),
17932
17933
  "include_children does not go with unlink_children. The open children move with the issue or leave it, so name one of the two."
17933
17934
  ],
17934
17935
  [
17935
- !(input["include_children"] === true && input["status"] === "done"),
17936
+ !(optionInput.include_children === true && optionInput.status === "done"),
17936
17937
  "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."
17937
17938
  ],
17938
17939
  [
17939
- typeof input["status"] === "string",
17940
+ typeof optionInput.status === "string",
17940
17941
  `status is required with ${named}. Add status, or drop ${named}.`
17941
17942
  ],
17942
17943
  [
@@ -18089,8 +18090,8 @@ var RESULT_SHAPE_RULE = `${RESULT_RETRACT_RULE} A call with retract takes reason
18089
18090
  function resultProblem(value) {
18090
18091
  const input = value;
18091
18092
  const carried = RESULT_RECORD_FIELDS.filter((field) => input[field] !== undefined);
18092
- if (typeof input["retract"] === "string") {
18093
- const reason = input["reason"];
18093
+ if (typeof input.retract === "string") {
18094
+ const reason = input.reason;
18094
18095
  if (typeof reason !== "string" || reason.trim() === "") {
18095
18096
  return "retract needs reason, the words that say why the result is wrong.";
18096
18097
  }
@@ -18099,7 +18100,7 @@ function resultProblem(value) {
18099
18100
  }
18100
18101
  return;
18101
18102
  }
18102
- if (input["reason"] !== undefined) {
18103
+ if (input.reason !== undefined) {
18103
18104
  return "reason goes with retract, and this call carries no retract. Name the result to retract, or drop reason.";
18104
18105
  }
18105
18106
  const missing = RESULT_REQUIRED_FIELDS.filter((field) => input[field] === undefined);
@@ -19568,6 +19569,52 @@ var DispatchTargetedDeliverySchema = union([
19568
19569
  DispatchTargetedCommentDeliverySchema,
19569
19570
  DispatchTargetedMessageDeliverySchema
19570
19571
  ]);
19572
+ function isCommentTargetedDelivery(delivery) {
19573
+ return "comment_id" in delivery;
19574
+ }
19575
+ var DispatchTargetedFrameSchema = object({
19576
+ event: DispatchEventSchema,
19577
+ delivery: DispatchTargetedDeliverySchema
19578
+ }).superRefine(({ event, delivery }, context) => {
19579
+ if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
19580
+ return;
19581
+ }
19582
+ if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
19583
+ return;
19584
+ }
19585
+ context.addIssue({
19586
+ code: "custom",
19587
+ message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
19588
+ });
19589
+ });
19590
+ var RecoverableDispatchDeliveryFailureSchema = object({
19591
+ event: object({
19592
+ type: _enum2(["message.created", "comment.created"]),
19593
+ issue_key: string2().nullable(),
19594
+ payload: object({ id: string2(), body: string2().optional() }).passthrough()
19595
+ }).passthrough(),
19596
+ delivery: DispatchTargetedDeliverySchema
19597
+ }).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" });
19598
+ function readDispatchPayload(value) {
19599
+ if (typeof value === "object" && value !== null && "delivery" in value) {
19600
+ const targeted = DispatchTargetedFrameSchema.safeParse(value);
19601
+ if (targeted.success) {
19602
+ const { event: wireEvent } = value;
19603
+ return {
19604
+ kind: "event",
19605
+ event: targeted.data.event,
19606
+ wireEvent,
19607
+ delivery: targeted.data.delivery
19608
+ };
19609
+ }
19610
+ const recovered = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
19611
+ if (recovered.success)
19612
+ return { kind: "recovered", failure: recovered.data };
19613
+ return { kind: "raw", targeted: true };
19614
+ }
19615
+ const parsed = DispatchEventSchema.safeParse(value);
19616
+ return parsed.success ? { kind: "event", event: parsed.data, wireEvent: value } : { kind: "raw", targeted: false };
19617
+ }
19571
19618
  // ../contracts/src/dispatch-api-user.ts
19572
19619
  var UserIssueStateSchema = strictObject({
19573
19620
  pinned: boolean2(),
@@ -22941,9 +22988,6 @@ function reachedNothing(error) {
22941
22988
  }
22942
22989
 
22943
22990
  class LoggableError extends Error {
22944
- constructor(message) {
22945
- super(message);
22946
- }
22947
22991
  }
22948
22992
  var SERVER_REFUSALS = [
22949
22993
  "Authorization Violation",
@@ -27784,7 +27828,7 @@ function parseFrameJSON(text) {
27784
27828
  const containers = typeof value === "object" && value !== null ? [value] : [];
27785
27829
  for (let next = containers.pop();next !== undefined; next = containers.pop()) {
27786
27830
  const members = next;
27787
- delete members["__proto__"];
27831
+ Reflect.deleteProperty(members, "__proto__");
27788
27832
  let names = Object.keys(members);
27789
27833
  if (names.some((name) => name.search(LONE_SURROGATE) !== -1)) {
27790
27834
  const held = names.map((name) => members[name]);
@@ -28016,32 +28060,6 @@ function createDeliveryDedupe(now = Date.now) {
28016
28060
  }
28017
28061
  };
28018
28062
  }
28019
- function isCommentTargetedDelivery(delivery) {
28020
- return "comment_id" in delivery;
28021
- }
28022
- var DispatchTargetedFrameSchema = object({
28023
- event: DispatchEventSchema,
28024
- delivery: DispatchTargetedDeliverySchema
28025
- }).superRefine(({ event, delivery }, context) => {
28026
- if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
28027
- return;
28028
- }
28029
- if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
28030
- return;
28031
- }
28032
- context.addIssue({
28033
- code: "custom",
28034
- message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
28035
- });
28036
- });
28037
- var RecoverableDispatchDeliveryFailureSchema = object({
28038
- event: object({
28039
- type: _enum2(["message.created", "comment.created"]),
28040
- issue_key: string2().nullable(),
28041
- payload: object({ id: string2(), body: string2().optional() }).passthrough()
28042
- }).passthrough(),
28043
- delivery: DispatchTargetedDeliverySchema
28044
- }).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" });
28045
28063
  function eventPictures(event) {
28046
28064
  let text;
28047
28065
  if (event.type.startsWith("message.")) {
@@ -28073,16 +28091,22 @@ function carriedItem(event) {
28073
28091
  const resource = event.type.startsWith("comment.") || event.type.startsWith("suggestion.") ? "comment" : event.type.startsWith("message.") ? "message" : undefined;
28074
28092
  if (resource === undefined || !isObject3(event.payload))
28075
28093
  return;
28076
- const id = event.payload["id"];
28094
+ const { id } = event.payload;
28077
28095
  if (typeof id !== "string" || id === "")
28078
28096
  return;
28079
28097
  return { resource, id, issueKey: event.issue_key };
28080
28098
  }
28081
28099
  function payloadWasOmitted(payload) {
28082
- return isObject3(payload) && payload["payload_omitted"] === true;
28100
+ if (!isObject3(payload))
28101
+ return false;
28102
+ const { payload_omitted } = payload;
28103
+ return payload_omitted === true;
28083
28104
  }
28084
28105
  function bodyWasCut(payload) {
28085
- return isObject3(payload) && payload["body_truncated"] === true || payloadWasOmitted(payload);
28106
+ if (!isObject3(payload))
28107
+ return false;
28108
+ const { body_truncated } = payload;
28109
+ return body_truncated === true || payloadWasOmitted(payload);
28086
28110
  }
28087
28111
  function wholeItemRoute(item) {
28088
28112
  return `GET /api/v1/${item.resource === "comment" ? "comments" : "messages"}/${item.id}`;
@@ -28327,7 +28351,10 @@ var DISPATCH_BOOKKEEPING = new Set([
28327
28351
  ]);
28328
28352
  function dispatchPayloadForReader(event, sessionID, issuedAt, toReader) {
28329
28353
  const whole = dispatchPayload(event);
28330
- const changed = event.type !== "issue.created" && isObject3(whole) && Array.isArray(whole["changed"]) ? whole["changed"] : [];
28354
+ let changedField;
28355
+ if (event.type !== "issue.created" && isObject3(whole))
28356
+ ({ changed: changedField } = whole);
28357
+ const changed = Array.isArray(changedField) ? changedField : [];
28331
28358
  const payload = withoutEmptyFields(whole, (key, item) => changed.includes(key) || (key === "suggestion" || key === "forced") && item !== null && item !== undefined);
28332
28359
  if (!isObject3(payload) || Array.isArray(payload))
28333
28360
  return payload;
@@ -28442,27 +28469,25 @@ function parseDispatchFrame(rawPayload, wholeBody) {
28442
28469
  try {
28443
28470
  value = parseFrameJSON(rawPayload);
28444
28471
  } catch {
28445
- return { raw: rawPayload };
28472
+ return {};
28446
28473
  }
28447
- if (isObject3(value) && "delivery" in value) {
28448
- const targeted = DispatchTargetedFrameSchema.safeParse(value);
28449
- if (targeted.success) {
28450
- const wireFrame = value;
28474
+ const reading = readDispatchPayload(value);
28475
+ switch (reading.kind) {
28476
+ case "event": {
28477
+ const { notify, quiet } = reading.wireEvent;
28451
28478
  return {
28452
- event: withWholeBody(targeted.data.event, wholeBody),
28453
- notify: wireFrame.event.notify,
28454
- quiet: wireFrame.event.quiet,
28455
- delivery: targeted.data.delivery
28479
+ event: withWholeBody(reading.event, wholeBody),
28480
+ notify,
28481
+ quiet,
28482
+ delivery: reading.delivery
28456
28483
  };
28457
28484
  }
28458
- const recoverable = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
28459
- if (recoverable.success) {
28460
- const delivery = recoverable.data.delivery;
28485
+ case "recovered": {
28486
+ const { delivery, event } = reading.failure;
28461
28487
  const commentDelivery = isCommentTargetedDelivery(delivery);
28462
28488
  const resource = commentDelivery ? "comment" : "message";
28463
- const id = commentDelivery ? delivery.comment_id : recoverable.data.event.payload.id;
28489
+ const id = commentDelivery ? delivery.comment_id : event.payload.id;
28464
28490
  return {
28465
- raw: value,
28466
28491
  rejectedDelivery: {
28467
28492
  resource,
28468
28493
  id,
@@ -28470,24 +28495,15 @@ function parseDispatchFrame(rawPayload, wholeBody) {
28470
28495
  mode: delivery.mode,
28471
28496
  replyPath: dispatchReplyPath(resource, id),
28472
28497
  replyFields: commentDelivery ? { target: delivery.target } : {},
28473
- issueKey: recoverable.data.event.issue_key,
28474
- body: recoverable.data.event.payload.body ?? ""
28498
+ issueKey: event.issue_key,
28499
+ body: event.payload.body ?? ""
28475
28500
  },
28476
28501
  malformedDelivery: true
28477
28502
  };
28478
28503
  }
28479
- return { raw: value, malformedDelivery: true };
28504
+ case "raw":
28505
+ return reading.targeted ? { malformedDelivery: true } : {};
28480
28506
  }
28481
- const parsed = DispatchEventSchema.safeParse(value);
28482
- if (!parsed.success)
28483
- return { raw: value };
28484
- const wireEvent = value;
28485
- return {
28486
- event: withWholeBody(parsed.data, wholeBody),
28487
- notify: wireEvent.notify,
28488
- quiet: wireEvent.quiet,
28489
- delivery: undefined
28490
- };
28491
28507
  }
28492
28508
  var INBOUND_CARD_MAX_BYTES = 1 << 20;
28493
28509
  function encodeWithin(value, maxBytes) {
@@ -28502,6 +28518,28 @@ function encodeWithin(value, maxBytes) {
28502
28518
  return lines.join(`
28503
28519
  `);
28504
28520
  }
28521
+ function headerActor(actor) {
28522
+ const { kind, id, act, service } = actor;
28523
+ return {
28524
+ kind,
28525
+ ...id === undefined ? {} : { id },
28526
+ ...act === undefined ? {} : { act: ActorActSchema.safeParse(act).data ?? "not shown" },
28527
+ ...kind !== "session" || service === undefined ? {} : { service: typeof service === "string" ? service : "not shown" }
28528
+ };
28529
+ }
28530
+ function dispatchCardAsText(rendered, event, reason, bound) {
28531
+ let text;
28532
+ try {
28533
+ text = JSON.stringify(event);
28534
+ } catch {}
28535
+ const asText = text === undefined ? undefined : encodeWithin({ envoy: { ...rendered, dispatch: text } }, bound);
28536
+ if (asText !== undefined)
28537
+ return asText;
28538
+ const notShown = `not shown: ${reason}`;
28539
+ const owner = event.owner === undefined ? {} : { owner: event.owner };
28540
+ const header = { type: event.type, actor: headerActor(event.actor), payload: notShown };
28541
+ return encodeWithin({ envoy: { ...rendered, dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: header } }, bound) ?? encode5({ envoy: { dispatch: { payload: notShown } } });
28542
+ }
28505
28543
  function inboundTimestamp(milliseconds) {
28506
28544
  if (milliseconds === undefined)
28507
28545
  return "unknown";
@@ -28609,13 +28647,13 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
28609
28647
  dispatchReply = dispatchCommentReplyWith(frame.event, topic, commentPayload);
28610
28648
  if (frame.event.type === "message.created") {
28611
28649
  const message = DispatchTargetedMessagePayloadSchema.safeParse(frame.event.payload);
28612
- const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
28613
- if (message.success && requested.success && !isCommentTargetedDelivery(requested.data)) {
28650
+ const requested = frame.delivery;
28651
+ if (message.success && requested !== undefined && !isCommentTargetedDelivery(requested)) {
28614
28652
  delivery = {
28615
28653
  resource: "message",
28616
28654
  id: message.data.id,
28617
- attempt: requested.data.attempt,
28618
- mode: requested.data.mode,
28655
+ attempt: requested.attempt,
28656
+ mode: requested.mode,
28619
28657
  replyPath: dispatchReplyPath("message", message.data.id),
28620
28658
  replyFields: {},
28621
28659
  issueKey: frame.event.issue_key,
@@ -28633,15 +28671,15 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
28633
28671
  }
28634
28672
  } else if (frame.event.type === "comment.created") {
28635
28673
  const comment = DispatchTargetedCommentPayloadSchema.safeParse(frame.event.payload);
28636
- const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
28637
- if (comment.success && requested.success && isCommentTargetedDelivery(requested.data)) {
28674
+ const requested = frame.delivery;
28675
+ if (comment.success && requested !== undefined && isCommentTargetedDelivery(requested)) {
28638
28676
  delivery = {
28639
28677
  resource: "comment",
28640
- id: requested.data.comment_id,
28641
- attempt: requested.data.attempt,
28642
- mode: requested.data.mode,
28643
- replyPath: dispatchReplyPath("comment", requested.data.comment_id),
28644
- replyFields: { target: requested.data.target },
28678
+ id: requested.comment_id,
28679
+ attempt: requested.attempt,
28680
+ mode: requested.mode,
28681
+ replyPath: dispatchReplyPath("comment", requested.comment_id),
28682
+ replyFields: { target: requested.target },
28645
28683
  issueKey: frame.event.issue_key,
28646
28684
  body: comment.data.body,
28647
28685
  ...comment.data.body_truncated === true ? { bodyTruncated: true } : {}
@@ -28660,7 +28698,9 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
28660
28698
  let actor = frame.event.actor;
28661
28699
  if ("origin" in frame.event.actor) {
28662
28700
  const { origin, ...rest } = frame.event.actor;
28663
- const title = isObject3(origin) ? origin["session_title"] : undefined;
28701
+ let title;
28702
+ if (isObject3(origin))
28703
+ ({ session_title: title } = origin);
28664
28704
  actor = typeof title === "string" && title !== "" ? { ...rest, origin: { session_title: title } } : rest;
28665
28705
  }
28666
28706
  const owner = dispatchOwner(frame.event, topic);
@@ -28682,7 +28722,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
28682
28722
  trailer = humanEditDiffBlock(edit.data.diff, edit.data.diff_truncated);
28683
28723
  }
28684
28724
  } else {
28685
- dispatchEvent = frame.raw;
28725
+ dispatchIssue = "payload";
28686
28726
  rejectedDelivery = frame.rejectedDelivery;
28687
28727
  malformedDelivery = frame.malformedDelivery === true;
28688
28728
  }
@@ -28737,7 +28777,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
28737
28777
  args: { topic: `notifications.role.${role}`, message: "..." }
28738
28778
  }
28739
28779
  },
28740
- ...dispatchRendered ? { dispatch: dispatchEvent } : {
28780
+ ...dispatchRendered ? dispatchEvent === undefined ? {} : { dispatch: dispatchEvent } : {
28741
28781
  ...summaryIsHead ? {} : { summary: payloadSummary },
28742
28782
  ...message === undefined ? {} : { message }
28743
28783
  },
@@ -28747,7 +28787,6 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
28747
28787
  },
28748
28788
  ...unrecognised === undefined ? {} : { unrecognised }
28749
28789
  };
28750
- const payloadKey = dispatchRendered ? "dispatch" : "message";
28751
28790
  const payloadValue = dispatchRendered ? dispatchEvent : message;
28752
28791
  const cardBound = Math.max(INBOUND_CARD_MAX_BYTES, 2 * (Buffer.byteLength(raw) + (wholeBody === undefined ? 0 : Buffer.byteLength(escapeString(wholeBody)))));
28753
28792
  let card;
@@ -28761,7 +28800,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
28761
28800
  }
28762
28801
  if (card === undefined) {
28763
28802
  payloadShownAsText ??= `its layout is larger than the ${cardBound} bytes a card holds`;
28764
- card = encode5({ envoy: { ...rendered, [payloadKey]: envelope.payload } });
28803
+ card = dispatchEvent === undefined ? encode5({ envoy: { ...rendered, message: envelope.payload } }) : dispatchCardAsText(rendered, dispatchEvent, payloadShownAsText, cardBound);
28765
28804
  }
28766
28805
  return {
28767
28806
  skip: false,
@@ -29855,7 +29894,8 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
29855
29894
  if (tool === "dispatch_read" && typeof args.message === "string") {
29856
29895
  return { args, ref, owner: null };
29857
29896
  }
29858
- if (tool === "dispatch_result" && typeof args["retract"] === "string") {
29897
+ const { retract } = args;
29898
+ if (tool === "dispatch_result" && typeof retract === "string") {
29859
29899
  return { args, ref, owner: null };
29860
29900
  }
29861
29901
  const legionIssue = env.LEGION_ISSUE;
@@ -31814,7 +31854,8 @@ async function relatedCommand(context) {
31814
31854
  };
31815
31855
  }
31816
31856
  function printsJson(tool, args) {
31817
- return tool === "dispatch_issues" && args["json"] === true;
31857
+ const { json } = args;
31858
+ return tool === "dispatch_issues" && json === true;
31818
31859
  }
31819
31860
  async function issuesCommand(context) {
31820
31861
  const { args, client, input } = context;
@@ -31880,7 +31921,8 @@ async function issuesCommand(context) {
31880
31921
  };
31881
31922
  }
31882
31923
  function dryRunAsksDispatch(tool, args) {
31883
- return tool === "dispatch_result" && args["retract"] === undefined;
31924
+ const { retract } = args;
31925
+ return tool === "dispatch_result" && retract === undefined;
31884
31926
  }
31885
31927
  async function resultCommand(context) {
31886
31928
  const { args, client, actor } = context;
@@ -229,9 +229,6 @@ function reachedNothing(error) {
229
229
  }
230
230
 
231
231
  class LoggableError extends Error {
232
- constructor(message) {
233
- super(message);
234
- }
235
232
  }
236
233
  var SERVER_REFUSALS = [
237
234
  "Authorization Violation",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "6.5.0",
3
+ "version": "6.5.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",