@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.
package/dist/dispatch.js CHANGED
@@ -1231,9 +1231,6 @@ function reachedNothing(error) {
1231
1231
  }
1232
1232
 
1233
1233
  class LoggableError extends Error {
1234
- constructor(message) {
1235
- super(message);
1236
- }
1237
1234
  }
1238
1235
  var SERVER_REFUSALS = [
1239
1236
  "Authorization Violation",
@@ -14926,21 +14923,22 @@ var ISSUE_UPDATE_OPTIONS_RULE = "include_children, unlink_children and include_p
14926
14923
  var ISSUE_UPDATE_RULE = `${ISSUE_UPDATE_FIELDS_RULE} ${ISSUE_UPDATE_DONE_RULE}; ${ISSUE_UPDATE_REASON_RULE}; ${ISSUE_UPDATE_LABELS_RULE}. ${ISSUE_UPDATE_OPTIONS_RULE}`;
14927
14924
  function issueStatusOptionsProblem(input) {
14928
14925
  const options = issueStatusOptionsOf(input);
14926
+ const optionInput = input;
14929
14927
  if (options.length === 0)
14930
14928
  return;
14931
14929
  const named = options.join(", ").replace(/, ([^,]*)$/, " and $1");
14932
14930
  const others = ISSUE_UPDATE_PATCH_FIELDS.filter((field) => input[field] !== undefined);
14933
14931
  return brokenParts([
14934
14932
  [
14935
- !(input["include_children"] === true && input["unlink_children"] === true),
14933
+ !(optionInput.include_children === true && optionInput.unlink_children === true),
14936
14934
  "include_children does not go with unlink_children. The open children move with the issue or leave it, so name one of the two."
14937
14935
  ],
14938
14936
  [
14939
- !(input["include_children"] === true && input["status"] === "done"),
14937
+ !(optionInput.include_children === true && optionInput.status === "done"),
14940
14938
  "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."
14941
14939
  ],
14942
14940
  [
14943
- typeof input["status"] === "string",
14941
+ typeof optionInput.status === "string",
14944
14942
  `status is required with ${named}. Add status, or drop ${named}.`
14945
14943
  ],
14946
14944
  [
@@ -15093,8 +15091,8 @@ var RESULT_SHAPE_RULE = `${RESULT_RETRACT_RULE} A call with retract takes reason
15093
15091
  function resultProblem(value) {
15094
15092
  const input = value;
15095
15093
  const carried = RESULT_RECORD_FIELDS.filter((field) => input[field] !== undefined);
15096
- if (typeof input["retract"] === "string") {
15097
- const reason = input["reason"];
15094
+ if (typeof input.retract === "string") {
15095
+ const reason = input.reason;
15098
15096
  if (typeof reason !== "string" || reason.trim() === "") {
15099
15097
  return "retract needs reason, the words that say why the result is wrong.";
15100
15098
  }
@@ -15103,7 +15101,7 @@ function resultProblem(value) {
15103
15101
  }
15104
15102
  return;
15105
15103
  }
15106
- if (input["reason"] !== undefined) {
15104
+ if (input.reason !== undefined) {
15107
15105
  return "reason goes with retract, and this call carries no retract. Name the result to retract, or drop reason.";
15108
15106
  }
15109
15107
  const missing = RESULT_REQUIRED_FIELDS.filter((field) => input[field] === undefined);
@@ -16572,6 +16570,52 @@ var DispatchTargetedDeliverySchema = union([
16572
16570
  DispatchTargetedCommentDeliverySchema,
16573
16571
  DispatchTargetedMessageDeliverySchema
16574
16572
  ]);
16573
+ function isCommentTargetedDelivery(delivery) {
16574
+ return "comment_id" in delivery;
16575
+ }
16576
+ var DispatchTargetedFrameSchema = object({
16577
+ event: DispatchEventSchema,
16578
+ delivery: DispatchTargetedDeliverySchema
16579
+ }).superRefine(({ event, delivery }, context) => {
16580
+ if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
16581
+ return;
16582
+ }
16583
+ if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
16584
+ return;
16585
+ }
16586
+ context.addIssue({
16587
+ code: "custom",
16588
+ message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
16589
+ });
16590
+ });
16591
+ var RecoverableDispatchDeliveryFailureSchema = object({
16592
+ event: object({
16593
+ type: _enum2(["message.created", "comment.created"]),
16594
+ issue_key: string2().nullable(),
16595
+ payload: object({ id: string2(), body: string2().optional() }).passthrough()
16596
+ }).passthrough(),
16597
+ delivery: DispatchTargetedDeliverySchema
16598
+ }).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" });
16599
+ function readDispatchPayload(value) {
16600
+ if (typeof value === "object" && value !== null && "delivery" in value) {
16601
+ const targeted = DispatchTargetedFrameSchema.safeParse(value);
16602
+ if (targeted.success) {
16603
+ const { event: wireEvent } = value;
16604
+ return {
16605
+ kind: "event",
16606
+ event: targeted.data.event,
16607
+ wireEvent,
16608
+ delivery: targeted.data.delivery
16609
+ };
16610
+ }
16611
+ const recovered = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
16612
+ if (recovered.success)
16613
+ return { kind: "recovered", failure: recovered.data };
16614
+ return { kind: "raw", targeted: true };
16615
+ }
16616
+ const parsed = DispatchEventSchema.safeParse(value);
16617
+ return parsed.success ? { kind: "event", event: parsed.data, wireEvent: value } : { kind: "raw", targeted: false };
16618
+ }
16575
16619
  // ../contracts/src/dispatch-api-user.ts
16576
16620
  var UserIssueStateSchema = strictObject({
16577
16621
  pinned: boolean2(),
@@ -32483,7 +32527,7 @@ function parseFrameJSON(text) {
32483
32527
  const containers = typeof value === "object" && value !== null ? [value] : [];
32484
32528
  for (let next = containers.pop();next !== undefined; next = containers.pop()) {
32485
32529
  const members = next;
32486
- delete members["__proto__"];
32530
+ Reflect.deleteProperty(members, "__proto__");
32487
32531
  let names = Object.keys(members);
32488
32532
  if (names.some((name) => name.search(LONE_SURROGATE) !== -1)) {
32489
32533
  const held = names.map((name) => members[name]);
@@ -32674,32 +32718,6 @@ function createDeliveryDedupe(now = Date.now) {
32674
32718
  }
32675
32719
  };
32676
32720
  }
32677
- function isCommentTargetedDelivery(delivery) {
32678
- return "comment_id" in delivery;
32679
- }
32680
- var DispatchTargetedFrameSchema = object({
32681
- event: DispatchEventSchema,
32682
- delivery: DispatchTargetedDeliverySchema
32683
- }).superRefine(({ event, delivery }, context) => {
32684
- if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
32685
- return;
32686
- }
32687
- if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
32688
- return;
32689
- }
32690
- context.addIssue({
32691
- code: "custom",
32692
- message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
32693
- });
32694
- });
32695
- var RecoverableDispatchDeliveryFailureSchema = object({
32696
- event: object({
32697
- type: _enum2(["message.created", "comment.created"]),
32698
- issue_key: string2().nullable(),
32699
- payload: object({ id: string2(), body: string2().optional() }).passthrough()
32700
- }).passthrough(),
32701
- delivery: DispatchTargetedDeliverySchema
32702
- }).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" });
32703
32721
  function eventPictures(event) {
32704
32722
  let text;
32705
32723
  if (event.type.startsWith("message.")) {
@@ -32731,16 +32749,22 @@ function carriedItem(event) {
32731
32749
  const resource = event.type.startsWith("comment.") || event.type.startsWith("suggestion.") ? "comment" : event.type.startsWith("message.") ? "message" : undefined;
32732
32750
  if (resource === undefined || !isObject3(event.payload))
32733
32751
  return;
32734
- const id = event.payload["id"];
32752
+ const { id } = event.payload;
32735
32753
  if (typeof id !== "string" || id === "")
32736
32754
  return;
32737
32755
  return { resource, id, issueKey: event.issue_key };
32738
32756
  }
32739
32757
  function payloadWasOmitted(payload) {
32740
- return isObject3(payload) && payload["payload_omitted"] === true;
32758
+ if (!isObject3(payload))
32759
+ return false;
32760
+ const { payload_omitted } = payload;
32761
+ return payload_omitted === true;
32741
32762
  }
32742
32763
  function bodyWasCut(payload) {
32743
- return isObject3(payload) && payload["body_truncated"] === true || payloadWasOmitted(payload);
32764
+ if (!isObject3(payload))
32765
+ return false;
32766
+ const { body_truncated } = payload;
32767
+ return body_truncated === true || payloadWasOmitted(payload);
32744
32768
  }
32745
32769
  function wholeItemRoute(item) {
32746
32770
  return `GET /api/v1/${item.resource === "comment" ? "comments" : "messages"}/${item.id}`;
@@ -32985,7 +33009,10 @@ var DISPATCH_BOOKKEEPING = new Set([
32985
33009
  ]);
32986
33010
  function dispatchPayloadForReader(event, sessionID, issuedAt, toReader) {
32987
33011
  const whole = dispatchPayload(event);
32988
- const changed = event.type !== "issue.created" && isObject3(whole) && Array.isArray(whole["changed"]) ? whole["changed"] : [];
33012
+ let changedField;
33013
+ if (event.type !== "issue.created" && isObject3(whole))
33014
+ ({ changed: changedField } = whole);
33015
+ const changed = Array.isArray(changedField) ? changedField : [];
32989
33016
  const payload = withoutEmptyFields(whole, (key, item) => changed.includes(key) || (key === "suggestion" || key === "forced") && item !== null && item !== undefined);
32990
33017
  if (!isObject3(payload) || Array.isArray(payload))
32991
33018
  return payload;
@@ -33100,27 +33127,25 @@ function parseDispatchFrame(rawPayload, wholeBody) {
33100
33127
  try {
33101
33128
  value = parseFrameJSON(rawPayload);
33102
33129
  } catch {
33103
- return { raw: rawPayload };
33130
+ return {};
33104
33131
  }
33105
- if (isObject3(value) && "delivery" in value) {
33106
- const targeted = DispatchTargetedFrameSchema.safeParse(value);
33107
- if (targeted.success) {
33108
- const wireFrame = value;
33132
+ const reading = readDispatchPayload(value);
33133
+ switch (reading.kind) {
33134
+ case "event": {
33135
+ const { notify, quiet } = reading.wireEvent;
33109
33136
  return {
33110
- event: withWholeBody(targeted.data.event, wholeBody),
33111
- notify: wireFrame.event.notify,
33112
- quiet: wireFrame.event.quiet,
33113
- delivery: targeted.data.delivery
33137
+ event: withWholeBody(reading.event, wholeBody),
33138
+ notify,
33139
+ quiet,
33140
+ delivery: reading.delivery
33114
33141
  };
33115
33142
  }
33116
- const recoverable = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
33117
- if (recoverable.success) {
33118
- const delivery = recoverable.data.delivery;
33143
+ case "recovered": {
33144
+ const { delivery, event } = reading.failure;
33119
33145
  const commentDelivery = isCommentTargetedDelivery(delivery);
33120
33146
  const resource = commentDelivery ? "comment" : "message";
33121
- const id = commentDelivery ? delivery.comment_id : recoverable.data.event.payload.id;
33147
+ const id = commentDelivery ? delivery.comment_id : event.payload.id;
33122
33148
  return {
33123
- raw: value,
33124
33149
  rejectedDelivery: {
33125
33150
  resource,
33126
33151
  id,
@@ -33128,24 +33153,15 @@ function parseDispatchFrame(rawPayload, wholeBody) {
33128
33153
  mode: delivery.mode,
33129
33154
  replyPath: dispatchReplyPath(resource, id),
33130
33155
  replyFields: commentDelivery ? { target: delivery.target } : {},
33131
- issueKey: recoverable.data.event.issue_key,
33132
- body: recoverable.data.event.payload.body ?? ""
33156
+ issueKey: event.issue_key,
33157
+ body: event.payload.body ?? ""
33133
33158
  },
33134
33159
  malformedDelivery: true
33135
33160
  };
33136
33161
  }
33137
- return { raw: value, malformedDelivery: true };
33162
+ case "raw":
33163
+ return reading.targeted ? { malformedDelivery: true } : {};
33138
33164
  }
33139
- const parsed = DispatchEventSchema.safeParse(value);
33140
- if (!parsed.success)
33141
- return { raw: value };
33142
- const wireEvent = value;
33143
- return {
33144
- event: withWholeBody(parsed.data, wholeBody),
33145
- notify: wireEvent.notify,
33146
- quiet: wireEvent.quiet,
33147
- delivery: undefined
33148
- };
33149
33165
  }
33150
33166
  var INBOUND_CARD_MAX_BYTES = 1 << 20;
33151
33167
  function encodeWithin(value, maxBytes) {
@@ -33160,6 +33176,28 @@ function encodeWithin(value, maxBytes) {
33160
33176
  return lines.join(`
33161
33177
  `);
33162
33178
  }
33179
+ function headerActor(actor) {
33180
+ const { kind, id, act, service } = actor;
33181
+ return {
33182
+ kind,
33183
+ ...id === undefined ? {} : { id },
33184
+ ...act === undefined ? {} : { act: ActorActSchema.safeParse(act).data ?? "not shown" },
33185
+ ...kind !== "session" || service === undefined ? {} : { service: typeof service === "string" ? service : "not shown" }
33186
+ };
33187
+ }
33188
+ function dispatchCardAsText(rendered, event, reason, bound) {
33189
+ let text;
33190
+ try {
33191
+ text = JSON.stringify(event);
33192
+ } catch {}
33193
+ const asText = text === undefined ? undefined : encodeWithin({ envoy: { ...rendered, dispatch: text } }, bound);
33194
+ if (asText !== undefined)
33195
+ return asText;
33196
+ const notShown = `not shown: ${reason}`;
33197
+ const owner = event.owner === undefined ? {} : { owner: event.owner };
33198
+ const header = { type: event.type, actor: headerActor(event.actor), payload: notShown };
33199
+ return encodeWithin({ envoy: { ...rendered, dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: { ...owner, ...header } } }, bound) ?? encodeWithin({ envoy: { dispatch: header } }, bound) ?? encode5({ envoy: { dispatch: { payload: notShown } } });
33200
+ }
33163
33201
  function inboundTimestamp(milliseconds) {
33164
33202
  if (milliseconds === undefined)
33165
33203
  return "unknown";
@@ -33267,13 +33305,13 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
33267
33305
  dispatchReply = dispatchCommentReplyWith(frame.event, topic, commentPayload);
33268
33306
  if (frame.event.type === "message.created") {
33269
33307
  const message = DispatchTargetedMessagePayloadSchema.safeParse(frame.event.payload);
33270
- const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
33271
- if (message.success && requested.success && !isCommentTargetedDelivery(requested.data)) {
33308
+ const requested = frame.delivery;
33309
+ if (message.success && requested !== undefined && !isCommentTargetedDelivery(requested)) {
33272
33310
  delivery = {
33273
33311
  resource: "message",
33274
33312
  id: message.data.id,
33275
- attempt: requested.data.attempt,
33276
- mode: requested.data.mode,
33313
+ attempt: requested.attempt,
33314
+ mode: requested.mode,
33277
33315
  replyPath: dispatchReplyPath("message", message.data.id),
33278
33316
  replyFields: {},
33279
33317
  issueKey: frame.event.issue_key,
@@ -33291,15 +33329,15 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
33291
33329
  }
33292
33330
  } else if (frame.event.type === "comment.created") {
33293
33331
  const comment = DispatchTargetedCommentPayloadSchema.safeParse(frame.event.payload);
33294
- const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
33295
- if (comment.success && requested.success && isCommentTargetedDelivery(requested.data)) {
33332
+ const requested = frame.delivery;
33333
+ if (comment.success && requested !== undefined && isCommentTargetedDelivery(requested)) {
33296
33334
  delivery = {
33297
33335
  resource: "comment",
33298
- id: requested.data.comment_id,
33299
- attempt: requested.data.attempt,
33300
- mode: requested.data.mode,
33301
- replyPath: dispatchReplyPath("comment", requested.data.comment_id),
33302
- replyFields: { target: requested.data.target },
33336
+ id: requested.comment_id,
33337
+ attempt: requested.attempt,
33338
+ mode: requested.mode,
33339
+ replyPath: dispatchReplyPath("comment", requested.comment_id),
33340
+ replyFields: { target: requested.target },
33303
33341
  issueKey: frame.event.issue_key,
33304
33342
  body: comment.data.body,
33305
33343
  ...comment.data.body_truncated === true ? { bodyTruncated: true } : {}
@@ -33318,7 +33356,9 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
33318
33356
  let actor = frame.event.actor;
33319
33357
  if ("origin" in frame.event.actor) {
33320
33358
  const { origin, ...rest } = frame.event.actor;
33321
- const title = isObject3(origin) ? origin["session_title"] : undefined;
33359
+ let title;
33360
+ if (isObject3(origin))
33361
+ ({ session_title: title } = origin);
33322
33362
  actor = typeof title === "string" && title !== "" ? { ...rest, origin: { session_title: title } } : rest;
33323
33363
  }
33324
33364
  const owner = dispatchOwner(frame.event, topic);
@@ -33340,7 +33380,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
33340
33380
  trailer = humanEditDiffBlock(edit.data.diff, edit.data.diff_truncated);
33341
33381
  }
33342
33382
  } else {
33343
- dispatchEvent = frame.raw;
33383
+ dispatchIssue = "payload";
33344
33384
  rejectedDelivery = frame.rejectedDelivery;
33345
33385
  malformedDelivery = frame.malformedDelivery === true;
33346
33386
  }
@@ -33395,7 +33435,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
33395
33435
  args: { topic: `notifications.role.${role}`, message: "..." }
33396
33436
  }
33397
33437
  },
33398
- ...dispatchRendered ? { dispatch: dispatchEvent } : {
33438
+ ...dispatchRendered ? dispatchEvent === undefined ? {} : { dispatch: dispatchEvent } : {
33399
33439
  ...summaryIsHead ? {} : { summary: payloadSummary },
33400
33440
  ...message === undefined ? {} : { message }
33401
33441
  },
@@ -33405,7 +33445,6 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
33405
33445
  },
33406
33446
  ...unrecognised === undefined ? {} : { unrecognised }
33407
33447
  };
33408
- const payloadKey = dispatchRendered ? "dispatch" : "message";
33409
33448
  const payloadValue = dispatchRendered ? dispatchEvent : message;
33410
33449
  const cardBound = Math.max(INBOUND_CARD_MAX_BYTES, 2 * (Buffer.byteLength(raw) + (wholeBody === undefined ? 0 : Buffer.byteLength(escapeString(wholeBody)))));
33411
33450
  let card;
@@ -33419,7 +33458,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
33419
33458
  }
33420
33459
  if (card === undefined) {
33421
33460
  payloadShownAsText ??= `its layout is larger than the ${cardBound} bytes a card holds`;
33422
- card = encode5({ envoy: { ...rendered, [payloadKey]: envelope.payload } });
33461
+ card = dispatchEvent === undefined ? encode5({ envoy: { ...rendered, message: envelope.payload } }) : dispatchCardAsText(rendered, dispatchEvent, payloadShownAsText, cardBound);
33423
33462
  }
33424
33463
  return {
33425
33464
  skip: false,
@@ -34188,7 +34227,8 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
34188
34227
  if (tool === "dispatch_read" && typeof args.message === "string") {
34189
34228
  return { args, ref, owner: null };
34190
34229
  }
34191
- if (tool === "dispatch_result" && typeof args["retract"] === "string") {
34230
+ const { retract } = args;
34231
+ if (tool === "dispatch_result" && typeof retract === "string") {
34192
34232
  return { args, ref, owner: null };
34193
34233
  }
34194
34234
  const legionIssue = env.LEGION_ISSUE;
@@ -35581,7 +35621,8 @@ async function relatedCommand(context) {
35581
35621
  };
35582
35622
  }
35583
35623
  function printsJson(tool, args) {
35584
- return tool === "dispatch_issues" && args["json"] === true;
35624
+ const { json } = args;
35625
+ return tool === "dispatch_issues" && json === true;
35585
35626
  }
35586
35627
  async function issuesCommand(context) {
35587
35628
  const { args, client, input } = context;
@@ -35647,7 +35688,8 @@ async function issuesCommand(context) {
35647
35688
  };
35648
35689
  }
35649
35690
  function dryRunAsksDispatch(tool, args) {
35650
- return tool === "dispatch_result" && args["retract"] === undefined;
35691
+ const { retract } = args;
35692
+ return tool === "dispatch_result" && retract === undefined;
35651
35693
  }
35652
35694
  async function resultCommand(context) {
35653
35695
  const { args, client, actor } = context;