@sjawhar/codex-envoy 5.1.1 → 5.1.2

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-envoy",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "Put Envoy and Dispatch messages into the Codex session's own conversation, show it on Dispatch's Agents page, and expose the Envoy and dispatch tools.",
5
5
  "author": {
6
6
  "name": "Legion",
@@ -15419,6 +15419,20 @@ var DispatchEventSchema = object({
15419
15419
  actor: object({ kind: string2(), id: string2().optional() }).passthrough(),
15420
15420
  payload: object({}).passthrough()
15421
15421
  });
15422
+ // ../contracts/src/dispatch-api-graph.ts
15423
+ function graphNodeKey(node) {
15424
+ return node.ref ?? `${node.kind} ${node.id}`;
15425
+ }
15426
+ function issueReferenceSections(answer) {
15427
+ const links = answer.links ?? [];
15428
+ const linkedFrom = answer.linked_from ?? [];
15429
+ const linked = new Set(links.map((row) => graphNodeKey(row.node)));
15430
+ const linking = new Set(linkedFrom.map((row) => graphNodeKey(row.node)));
15431
+ return {
15432
+ references: links.map((row) => ({ row, alsoReferences: linking.has(graphNodeKey(row.node)) })),
15433
+ referencedBy: linkedFrom.filter((row) => !linked.has(graphNodeKey(row.node)))
15434
+ };
15435
+ }
15422
15436
  // ../contracts/src/dispatch-api-inbox.ts
15423
15437
  function inboxThreadRow(row) {
15424
15438
  return row.kind === "agent" ? row : row;
@@ -23478,6 +23492,124 @@ async function otherAdviceLines(render) {
23478
23492
  }
23479
23493
  }
23480
23494
 
23495
+ // ../envoy-client/src/dispatch-commands/render-graph.ts
23496
+ function referenceLines(read) {
23497
+ if (typeof read === "string")
23498
+ return [`- ${read}`];
23499
+ const edges = read.edges ?? [];
23500
+ if (edges.length === 0)
23501
+ return ["- none"];
23502
+ return edges.map(edgeLine);
23503
+ }
23504
+ function isItemKind(kind) {
23505
+ return ITEM_KINDS.some((item) => item === kind);
23506
+ }
23507
+ function edgeLine(edge) {
23508
+ const { node } = edge;
23509
+ const excerpt = edge.excerpt === undefined ? "" : `${textHead(edge.excerpt.text)} \xB7 `;
23510
+ const block = edge.block === undefined ? "" : ` (block ${edge.block.ref ?? edge.block.id})`;
23511
+ const parent = node.parent ?? undefined;
23512
+ const item = node.kind === "block" && node.document === undefined && isItemKind(parent?.kind) ? parent : undefined;
23513
+ const source = item === undefined ? `${node.kind} ${node.ref ?? node.id}` : `${item.kind} ${item.ref ?? item.id} block ${node.block_id ?? node.id}`;
23514
+ return `- ${edge.kind} ${source} (${excerpt}${edge.created_at})${block}`;
23515
+ }
23516
+ function unavailableReason(error) {
23517
+ return dispatchAnswered(error, 404) ? "unavailable" : `unavailable: ${messageFor(error)}`;
23518
+ }
23519
+ async function graphReferences(client, query) {
23520
+ try {
23521
+ return await client.getReferences(query);
23522
+ } catch (error) {
23523
+ return unavailableReason(error);
23524
+ }
23525
+ }
23526
+ async function issueReferencesOrUnavailable(client, key) {
23527
+ try {
23528
+ return await client.getIssueReferences(key);
23529
+ } catch (error) {
23530
+ return unavailableReason(error);
23531
+ }
23532
+ }
23533
+ async function issueCoverageOrReason(client, key) {
23534
+ try {
23535
+ return await client.issueCoverage(key);
23536
+ } catch (error) {
23537
+ return unavailableReason(error);
23538
+ }
23539
+ }
23540
+ async function graphSections(client, ref) {
23541
+ const [incoming, outgoing] = await Promise.all([
23542
+ graphReferences(client, { to: ref }),
23543
+ graphReferences(client, { from: ref })
23544
+ ]);
23545
+ return graphSectionLines(incoming, outgoing);
23546
+ }
23547
+ function graphSectionLines(incoming, outgoing, referencedBy = referenceLines(incoming)) {
23548
+ return [
23549
+ ...typeof incoming === "string" ? [] : nodeLine(incoming.node),
23550
+ "Referenced by:",
23551
+ ...referencedBy,
23552
+ "Links:",
23553
+ ...referenceLines(outgoing)
23554
+ ];
23555
+ }
23556
+ function nodeLine(node) {
23557
+ if (node.made_by === undefined)
23558
+ return [];
23559
+ const fact = (by, time) => `${by == null || by.length === 0 ? "nobody recorded" : by.map(actorText).join(", ")}${time == null ? "" : ` at ${time}`}`;
23560
+ const made = fact(node.made_by, node.made_at);
23561
+ const changed = fact(node.changed_by, node.changed_at);
23562
+ const { parent } = node;
23563
+ const partOf = parent == null ? "" : ` \xB7 part of ${parent.ref ?? `${parent.kind} ${parent.id}`}${node.parent_version == null ? "" : ` (${isItemKind(parent.kind) ? "revision" : "version"} ${node.parent_version})`}`;
23564
+ return [
23565
+ `Node: ${node.kind} ${node.ref ?? node.id} \xB7 made by ${made} \xB7 changed by ${changed}${partOf}`
23566
+ ];
23567
+ }
23568
+ function blockLines(node, ref, typed, noun = "Block") {
23569
+ const unit = ref.item === undefined ? "version" : "revision";
23570
+ const blockID = node.block_id ?? ref.block;
23571
+ const head = ref.item === undefined ? [
23572
+ `Block: ${blockID}`,
23573
+ ...typed === undefined ? [] : [`Type: ${typed.type}`],
23574
+ `Document: ${node.document ?? ref.document}`,
23575
+ ...(typed?.attributes ?? []).map((attribute) => `${attribute.name}: ${attribute.value === "" ? "(empty)" : attribute.value}`),
23576
+ ...node.changed_version === undefined ? [] : [`Changed in version: ${node.changed_version}`],
23577
+ ...node.text === undefined ? [] : ["Text:", node.text]
23578
+ ] : [
23579
+ `${noun} ${blockID} of ${ref.item.kind} ${ref.item.id}${node.changed_version === undefined ? "" : ` (changed in revision ${node.changed_version})`}:`,
23580
+ ...node.text === undefined ? [] : [node.text]
23581
+ ];
23582
+ const { pin } = node;
23583
+ if (pin === undefined)
23584
+ return head;
23585
+ const state = pin.state === "unchanged" ? `Unchanged since ${unit} ${pin.version}.` : pin.state === "changed" ? `Changed since ${unit} ${pin.version}; last changed in ${unit} ${node.changed_version}.` : `Removed in ${unit} ${pin.removed_version}.`;
23586
+ return [
23587
+ ...head,
23588
+ `Pinned to ${unit}: ${pin.version}`,
23589
+ state,
23590
+ `Text at ${unit} ${pin.version}:`,
23591
+ pin.text
23592
+ ];
23593
+ }
23594
+ async function typedBlockOf(client, ref) {
23595
+ if (ref.item !== undefined || ref.block === undefined)
23596
+ return;
23597
+ try {
23598
+ const blocks = ref.owner.kind === "project" ? await client.projectArtifactBlocks(ref.owner.project, ref.id) : await client.issueArtifactBlocks(ref.owner.issue, ref.id);
23599
+ return blocks.find((block) => block.id === ref.block);
23600
+ } catch {
23601
+ return;
23602
+ }
23603
+ }
23604
+ function askPartNoun(ask, node, blockID) {
23605
+ if (ask.answer?.id === blockID)
23606
+ return "Answer";
23607
+ if ((ask.options ?? []).some((option) => option.id === blockID))
23608
+ return "Option";
23609
+ const placed = (ask.revision ?? 0) > 0 && (ask.options ?? []).every((option) => option.id !== undefined) && (ask.answer === null || ask.answer.id !== undefined);
23610
+ return placed && node.pin?.state !== "removed" ? "Question" : "Part";
23611
+ }
23612
+
23481
23613
  // ../envoy-client/src/dispatch-commands/render-issue.ts
23482
23614
  function componentsLine(components) {
23483
23615
  const ids = components.ids ?? [];
@@ -23605,11 +23737,44 @@ function olderServerWarnings(issue) {
23605
23737
  ];
23606
23738
  return warnings.length === 0 ? {} : { warnings };
23607
23739
  }
23608
- function issueSummary(issue, events, references, graph, linkBase, coverage, agents) {
23740
+ var STRUCTURAL_EDGES_IN = ["child_of", "blocked_by"];
23741
+ function referenceLinkLine({ kinds, node, via }, near) {
23742
+ return `- ${(kinds ?? []).join(",")} ${node.kind} ${node.ref ?? node.id} \xB7 ${near} ${via.kind} ${via.id}`;
23743
+ }
23744
+ function memberLines(references) {
23745
+ const members = references.members ?? [];
23746
+ return [
23747
+ ...members.length === 0 ? ["- none"] : members.map(({ artifact, depth, via }) => `- ${artifact.project}/${artifact.slug} \xB7 depth ${depth} via ${via.kind} ${via.id}`),
23748
+ ...references.truncated ? ["- more references beyond 8 hops"] : []
23749
+ ];
23750
+ }
23751
+ function referenceSections(references, incoming, outgoing) {
23752
+ if (typeof references === "string")
23753
+ return { references: [`- ${references}`] };
23754
+ if (references.links === undefined)
23755
+ return { references: memberLines(references) };
23756
+ const sections = issueReferenceSections(references);
23757
+ const structural = typeof incoming === "string" ? [] : (incoming.edges ?? []).filter((edge) => STRUCTURAL_EDGES_IN.includes(edge.kind));
23758
+ const outgoingEdges = typeof outgoing === "string" ? [] : outgoing.edges ?? [];
23759
+ const elsewhere = new Set([...outgoingEdges, ...structural].map((edge) => graphNodeKey(edge.node)));
23760
+ const referencesLines = sections.references.filter(({ row }) => !elsewhere.has(graphNodeKey(row.node))).map(({ alsoReferences, row }) => {
23761
+ const also = alsoReferences ? " \xB7 also references this issue" : "";
23762
+ return `${referenceLinkLine(row, "via")}${also}`;
23763
+ });
23764
+ const referencedBy = [
23765
+ ...sections.referencedBy.map((row) => referenceLinkLine(row, "to")),
23766
+ ...typeof incoming === "string" ? [`- ${incoming}`] : structural.map(edgeLine)
23767
+ ];
23768
+ return {
23769
+ references: referencesLines.length === 0 ? ["- none"] : referencesLines,
23770
+ referencedBy: referencedBy.length === 0 ? ["- none"] : referencedBy
23771
+ };
23772
+ }
23773
+ function issueSummary(issue, events, references, pictures, graph, linkBase, coverage, agents) {
23609
23774
  const asks = issue.open_asks ?? [];
23610
23775
  const labels = issue.labels ?? [];
23611
23776
  const links = issue.external_links ?? [];
23612
- const members = typeof references === "string" ? [] : references.members ?? [];
23777
+ const sections = referenceSections(references, graph.incoming, graph.outgoing);
23613
23778
  const spec = issue.artifacts?.find((artifact) => artifact.primary);
23614
23779
  const specApproval = spec === undefined ? undefined : approvalLine(spec, typeof issue.closed_at === "string");
23615
23780
  if (issue.priority === undefined)
@@ -23646,11 +23811,11 @@ function issueSummary(issue, events, references, graph, linkBase, coverage, agen
23646
23811
  "Open asks:",
23647
23812
  ...asks.length === 0 ? ["- none"] : asks.map((ask) => `- ${ask.id}: ${ask.question}`),
23648
23813
  "References:",
23649
- ...typeof references === "string" ? [`- ${references}`] : members.length === 0 ? ["- none"] : members.map(({ artifact, depth, via }) => `- ${artifact.project}/${artifact.slug} \xB7 depth ${depth} via ${via.kind} ${via.id}`),
23650
- ...typeof references === "string" || !references.truncated ? [] : ["- more references beyond 8 hops"],
23814
+ ...sections.references,
23651
23815
  "Events:",
23652
23816
  ...events.length === 0 ? ["- none"] : events.map(eventLine),
23653
- ...graph
23817
+ ...pictures,
23818
+ ...graphSectionLines(graph.incoming, graph.outgoing, sections.referencedBy)
23654
23819
  ].join(`
23655
23820
  `);
23656
23821
  }
@@ -24501,124 +24666,6 @@ async function resultsCommand(context) {
24501
24666
  };
24502
24667
  }
24503
24668
 
24504
- // ../envoy-client/src/dispatch-commands/render-graph.ts
24505
- function referenceLines(read) {
24506
- if (typeof read === "string")
24507
- return [`- ${read}`];
24508
- const edges = read.edges ?? [];
24509
- if (edges.length === 0)
24510
- return ["- none"];
24511
- return edges.map(edgeLine);
24512
- }
24513
- function isItemKind(kind) {
24514
- return ITEM_KINDS.some((item) => item === kind);
24515
- }
24516
- function edgeLine(edge) {
24517
- const { node } = edge;
24518
- const excerpt = edge.excerpt === undefined ? "" : `${textHead(edge.excerpt.text)} \xB7 `;
24519
- const block = edge.block === undefined ? "" : ` (block ${edge.block.ref ?? edge.block.id})`;
24520
- const parent = node.parent ?? undefined;
24521
- const item = node.kind === "block" && node.document === undefined && isItemKind(parent?.kind) ? parent : undefined;
24522
- const source = item === undefined ? `${node.kind} ${node.ref ?? node.id}` : `${item.kind} ${item.ref ?? item.id} block ${node.block_id ?? node.id}`;
24523
- return `- ${edge.kind} ${source} (${excerpt}${edge.created_at})${block}`;
24524
- }
24525
- function unavailableReason(error) {
24526
- return dispatchAnswered(error, 404) ? "unavailable" : `unavailable: ${messageFor(error)}`;
24527
- }
24528
- async function graphReferences(client, query) {
24529
- try {
24530
- return await client.getReferences(query);
24531
- } catch (error) {
24532
- return unavailableReason(error);
24533
- }
24534
- }
24535
- async function issueReferencesOrUnavailable(client, key) {
24536
- try {
24537
- return await client.getIssueReferences(key);
24538
- } catch (error) {
24539
- return unavailableReason(error);
24540
- }
24541
- }
24542
- async function issueCoverageOrReason(client, key) {
24543
- try {
24544
- return await client.issueCoverage(key);
24545
- } catch (error) {
24546
- return unavailableReason(error);
24547
- }
24548
- }
24549
- async function graphSections(client, ref) {
24550
- const [incoming, outgoing] = await Promise.all([
24551
- graphReferences(client, { to: ref }),
24552
- graphReferences(client, { from: ref })
24553
- ]);
24554
- return graphSectionLines(incoming, outgoing);
24555
- }
24556
- function graphSectionLines(incoming, outgoing) {
24557
- return [
24558
- ...typeof incoming === "string" ? [] : nodeLine(incoming.node),
24559
- "Referenced by:",
24560
- ...referenceLines(incoming),
24561
- "Links:",
24562
- ...referenceLines(outgoing)
24563
- ];
24564
- }
24565
- function nodeLine(node) {
24566
- if (node.made_by === undefined)
24567
- return [];
24568
- const fact = (by, time) => `${by == null || by.length === 0 ? "nobody recorded" : by.map(actorText).join(", ")}${time == null ? "" : ` at ${time}`}`;
24569
- const made = fact(node.made_by, node.made_at);
24570
- const changed = fact(node.changed_by, node.changed_at);
24571
- const { parent } = node;
24572
- const partOf = parent == null ? "" : ` \xB7 part of ${parent.ref ?? `${parent.kind} ${parent.id}`}${node.parent_version == null ? "" : ` (${isItemKind(parent.kind) ? "revision" : "version"} ${node.parent_version})`}`;
24573
- return [
24574
- `Node: ${node.kind} ${node.ref ?? node.id} \xB7 made by ${made} \xB7 changed by ${changed}${partOf}`
24575
- ];
24576
- }
24577
- function blockLines(node, ref, typed, noun = "Block") {
24578
- const unit = ref.item === undefined ? "version" : "revision";
24579
- const blockID = node.block_id ?? ref.block;
24580
- const head = ref.item === undefined ? [
24581
- `Block: ${blockID}`,
24582
- ...typed === undefined ? [] : [`Type: ${typed.type}`],
24583
- `Document: ${node.document ?? ref.document}`,
24584
- ...(typed?.attributes ?? []).map((attribute) => `${attribute.name}: ${attribute.value === "" ? "(empty)" : attribute.value}`),
24585
- ...node.changed_version === undefined ? [] : [`Changed in version: ${node.changed_version}`],
24586
- ...node.text === undefined ? [] : ["Text:", node.text]
24587
- ] : [
24588
- `${noun} ${blockID} of ${ref.item.kind} ${ref.item.id}${node.changed_version === undefined ? "" : ` (changed in revision ${node.changed_version})`}:`,
24589
- ...node.text === undefined ? [] : [node.text]
24590
- ];
24591
- const { pin } = node;
24592
- if (pin === undefined)
24593
- return head;
24594
- const state = pin.state === "unchanged" ? `Unchanged since ${unit} ${pin.version}.` : pin.state === "changed" ? `Changed since ${unit} ${pin.version}; last changed in ${unit} ${node.changed_version}.` : `Removed in ${unit} ${pin.removed_version}.`;
24595
- return [
24596
- ...head,
24597
- `Pinned to ${unit}: ${pin.version}`,
24598
- state,
24599
- `Text at ${unit} ${pin.version}:`,
24600
- pin.text
24601
- ];
24602
- }
24603
- async function typedBlockOf(client, ref) {
24604
- if (ref.item !== undefined || ref.block === undefined)
24605
- return;
24606
- try {
24607
- const blocks = ref.owner.kind === "project" ? await client.projectArtifactBlocks(ref.owner.project, ref.id) : await client.issueArtifactBlocks(ref.owner.issue, ref.id);
24608
- return blocks.find((block) => block.id === ref.block);
24609
- } catch {
24610
- return;
24611
- }
24612
- }
24613
- function askPartNoun(ask, node, blockID) {
24614
- if (ask.answer?.id === blockID)
24615
- return "Answer";
24616
- if ((ask.options ?? []).some((option) => option.id === blockID))
24617
- return "Option";
24618
- const placed = (ask.revision ?? 0) > 0 && (ask.options ?? []).every((option) => option.id !== undefined) && (ask.answer === null || ask.answer.id !== undefined);
24619
- return placed && node.pin?.state !== "removed" ? "Question" : "Part";
24620
- }
24621
-
24622
24669
  // ../envoy-client/src/dispatch-commands/render-item.ts
24623
24670
  function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
24624
24671
  const answer = ask.answer;
@@ -26287,9 +26334,11 @@ async function readCommand(context) {
26287
26334
  const readPromise = client.read(issueKey, readEvents);
26288
26335
  const referencesPromise = issueReferencesOrUnavailable(client, issueKey);
26289
26336
  const read = await readPromise;
26290
- const [references, graph, agents, pictures, coverage] = await Promise.all([
26337
+ const issueRef = dispatchIssueRef(read.issue.key);
26338
+ const [references, incoming, outgoing, agents, pictures, coverage] = await Promise.all([
26291
26339
  referencesPromise,
26292
- graphSections(client, dispatchIssueRef(read.issue.key)),
26340
+ graphReferences(client, { to: issueRef }),
26341
+ graphReferences(client, { from: issueRef }),
26293
26342
  liveAgents(client, holdsSession(read.issue.claim) || routeHeldBySession(read.issue)),
26294
26343
  picturesOf([
26295
26344
  ...(read.issue.open_asks ?? []).map((ask) => ({ text: ask.question, at: ask.created_at })),
@@ -26298,7 +26347,7 @@ async function readCommand(context) {
26298
26347
  issueCoverageOrReason(client, read.issue.key)
26299
26348
  ]);
26300
26349
  return {
26301
- text: issueSummary(read.issue, read.events, references, [...pictures.lines, ...graph], linkBase, coverage, agents),
26350
+ text: issueSummary(read.issue, read.events, references, pictures.lines, { incoming, outgoing }, linkBase, coverage, agents),
26302
26351
  details: { issue: read.issue.key },
26303
26352
  ...showImages(pictures),
26304
26353
  ...olderServerWarnings(read.issue)