@sjawhar/codex-envoy 5.1.0 → 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.
package/dist/dispatch.js CHANGED
@@ -16716,6 +16716,20 @@ var DispatchEventSchema = object({
16716
16716
  actor: object({ kind: string2(), id: string2().optional() }).passthrough(),
16717
16717
  payload: object({}).passthrough()
16718
16718
  });
16719
+ // ../contracts/src/dispatch-api-graph.ts
16720
+ function graphNodeKey(node) {
16721
+ return node.ref ?? `${node.kind} ${node.id}`;
16722
+ }
16723
+ function issueReferenceSections(answer) {
16724
+ const links = answer.links ?? [];
16725
+ const linkedFrom = answer.linked_from ?? [];
16726
+ const linked = new Set(links.map((row) => graphNodeKey(row.node)));
16727
+ const linking = new Set(linkedFrom.map((row) => graphNodeKey(row.node)));
16728
+ return {
16729
+ references: links.map((row) => ({ row, alsoReferences: linking.has(graphNodeKey(row.node)) })),
16730
+ referencedBy: linkedFrom.filter((row) => !linked.has(graphNodeKey(row.node)))
16731
+ };
16732
+ }
16719
16733
  // ../contracts/src/dispatch-api-inbox.ts
16720
16734
  function inboxThreadRow(row) {
16721
16735
  return row.kind === "agent" ? row : row;
@@ -28492,6 +28506,124 @@ async function otherAdviceLines(render) {
28492
28506
  }
28493
28507
  }
28494
28508
 
28509
+ // ../envoy-client/src/dispatch-commands/render-graph.ts
28510
+ function referenceLines(read) {
28511
+ if (typeof read === "string")
28512
+ return [`- ${read}`];
28513
+ const edges = read.edges ?? [];
28514
+ if (edges.length === 0)
28515
+ return ["- none"];
28516
+ return edges.map(edgeLine);
28517
+ }
28518
+ function isItemKind(kind) {
28519
+ return ITEM_KINDS.some((item) => item === kind);
28520
+ }
28521
+ function edgeLine(edge) {
28522
+ const { node } = edge;
28523
+ const excerpt = edge.excerpt === undefined ? "" : `${textHead(edge.excerpt.text)} \xB7 `;
28524
+ const block = edge.block === undefined ? "" : ` (block ${edge.block.ref ?? edge.block.id})`;
28525
+ const parent = node.parent ?? undefined;
28526
+ const item = node.kind === "block" && node.document === undefined && isItemKind(parent?.kind) ? parent : undefined;
28527
+ const source = item === undefined ? `${node.kind} ${node.ref ?? node.id}` : `${item.kind} ${item.ref ?? item.id} block ${node.block_id ?? node.id}`;
28528
+ return `- ${edge.kind} ${source} (${excerpt}${edge.created_at})${block}`;
28529
+ }
28530
+ function unavailableReason(error) {
28531
+ return dispatchAnswered(error, 404) ? "unavailable" : `unavailable: ${messageFor(error)}`;
28532
+ }
28533
+ async function graphReferences(client, query) {
28534
+ try {
28535
+ return await client.getReferences(query);
28536
+ } catch (error) {
28537
+ return unavailableReason(error);
28538
+ }
28539
+ }
28540
+ async function issueReferencesOrUnavailable(client, key) {
28541
+ try {
28542
+ return await client.getIssueReferences(key);
28543
+ } catch (error) {
28544
+ return unavailableReason(error);
28545
+ }
28546
+ }
28547
+ async function issueCoverageOrReason(client, key) {
28548
+ try {
28549
+ return await client.issueCoverage(key);
28550
+ } catch (error) {
28551
+ return unavailableReason(error);
28552
+ }
28553
+ }
28554
+ async function graphSections(client, ref) {
28555
+ const [incoming, outgoing] = await Promise.all([
28556
+ graphReferences(client, { to: ref }),
28557
+ graphReferences(client, { from: ref })
28558
+ ]);
28559
+ return graphSectionLines(incoming, outgoing);
28560
+ }
28561
+ function graphSectionLines(incoming, outgoing, referencedBy = referenceLines(incoming)) {
28562
+ return [
28563
+ ...typeof incoming === "string" ? [] : nodeLine(incoming.node),
28564
+ "Referenced by:",
28565
+ ...referencedBy,
28566
+ "Links:",
28567
+ ...referenceLines(outgoing)
28568
+ ];
28569
+ }
28570
+ function nodeLine(node) {
28571
+ if (node.made_by === undefined)
28572
+ return [];
28573
+ const fact = (by, time) => `${by == null || by.length === 0 ? "nobody recorded" : by.map(actorText).join(", ")}${time == null ? "" : ` at ${time}`}`;
28574
+ const made = fact(node.made_by, node.made_at);
28575
+ const changed = fact(node.changed_by, node.changed_at);
28576
+ const { parent } = node;
28577
+ 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})`}`;
28578
+ return [
28579
+ `Node: ${node.kind} ${node.ref ?? node.id} \xB7 made by ${made} \xB7 changed by ${changed}${partOf}`
28580
+ ];
28581
+ }
28582
+ function blockLines(node, ref, typed, noun = "Block") {
28583
+ const unit = ref.item === undefined ? "version" : "revision";
28584
+ const blockID = node.block_id ?? ref.block;
28585
+ const head = ref.item === undefined ? [
28586
+ `Block: ${blockID}`,
28587
+ ...typed === undefined ? [] : [`Type: ${typed.type}`],
28588
+ `Document: ${node.document ?? ref.document}`,
28589
+ ...(typed?.attributes ?? []).map((attribute) => `${attribute.name}: ${attribute.value === "" ? "(empty)" : attribute.value}`),
28590
+ ...node.changed_version === undefined ? [] : [`Changed in version: ${node.changed_version}`],
28591
+ ...node.text === undefined ? [] : ["Text:", node.text]
28592
+ ] : [
28593
+ `${noun} ${blockID} of ${ref.item.kind} ${ref.item.id}${node.changed_version === undefined ? "" : ` (changed in revision ${node.changed_version})`}:`,
28594
+ ...node.text === undefined ? [] : [node.text]
28595
+ ];
28596
+ const { pin } = node;
28597
+ if (pin === undefined)
28598
+ return head;
28599
+ 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}.`;
28600
+ return [
28601
+ ...head,
28602
+ `Pinned to ${unit}: ${pin.version}`,
28603
+ state,
28604
+ `Text at ${unit} ${pin.version}:`,
28605
+ pin.text
28606
+ ];
28607
+ }
28608
+ async function typedBlockOf(client, ref) {
28609
+ if (ref.item !== undefined || ref.block === undefined)
28610
+ return;
28611
+ try {
28612
+ const blocks = ref.owner.kind === "project" ? await client.projectArtifactBlocks(ref.owner.project, ref.id) : await client.issueArtifactBlocks(ref.owner.issue, ref.id);
28613
+ return blocks.find((block) => block.id === ref.block);
28614
+ } catch {
28615
+ return;
28616
+ }
28617
+ }
28618
+ function askPartNoun(ask, node, blockID) {
28619
+ if (ask.answer?.id === blockID)
28620
+ return "Answer";
28621
+ if ((ask.options ?? []).some((option) => option.id === blockID))
28622
+ return "Option";
28623
+ const placed = (ask.revision ?? 0) > 0 && (ask.options ?? []).every((option) => option.id !== undefined) && (ask.answer === null || ask.answer.id !== undefined);
28624
+ return placed && node.pin?.state !== "removed" ? "Question" : "Part";
28625
+ }
28626
+
28495
28627
  // ../envoy-client/src/dispatch-commands/render-issue.ts
28496
28628
  function componentsLine(components) {
28497
28629
  const ids = components.ids ?? [];
@@ -28619,11 +28751,44 @@ function olderServerWarnings(issue) {
28619
28751
  ];
28620
28752
  return warnings.length === 0 ? {} : { warnings };
28621
28753
  }
28622
- function issueSummary(issue, events, references, graph, linkBase, coverage, agents) {
28754
+ var STRUCTURAL_EDGES_IN = ["child_of", "blocked_by"];
28755
+ function referenceLinkLine({ kinds, node, via }, near) {
28756
+ return `- ${(kinds ?? []).join(",")} ${node.kind} ${node.ref ?? node.id} \xB7 ${near} ${via.kind} ${via.id}`;
28757
+ }
28758
+ function memberLines(references) {
28759
+ const members = references.members ?? [];
28760
+ return [
28761
+ ...members.length === 0 ? ["- none"] : members.map(({ artifact, depth, via }) => `- ${artifact.project}/${artifact.slug} \xB7 depth ${depth} via ${via.kind} ${via.id}`),
28762
+ ...references.truncated ? ["- more references beyond 8 hops"] : []
28763
+ ];
28764
+ }
28765
+ function referenceSections(references, incoming, outgoing) {
28766
+ if (typeof references === "string")
28767
+ return { references: [`- ${references}`] };
28768
+ if (references.links === undefined)
28769
+ return { references: memberLines(references) };
28770
+ const sections = issueReferenceSections(references);
28771
+ const structural = typeof incoming === "string" ? [] : (incoming.edges ?? []).filter((edge) => STRUCTURAL_EDGES_IN.includes(edge.kind));
28772
+ const outgoingEdges = typeof outgoing === "string" ? [] : outgoing.edges ?? [];
28773
+ const elsewhere = new Set([...outgoingEdges, ...structural].map((edge) => graphNodeKey(edge.node)));
28774
+ const referencesLines = sections.references.filter(({ row }) => !elsewhere.has(graphNodeKey(row.node))).map(({ alsoReferences, row }) => {
28775
+ const also = alsoReferences ? " \xB7 also references this issue" : "";
28776
+ return `${referenceLinkLine(row, "via")}${also}`;
28777
+ });
28778
+ const referencedBy = [
28779
+ ...sections.referencedBy.map((row) => referenceLinkLine(row, "to")),
28780
+ ...typeof incoming === "string" ? [`- ${incoming}`] : structural.map(edgeLine)
28781
+ ];
28782
+ return {
28783
+ references: referencesLines.length === 0 ? ["- none"] : referencesLines,
28784
+ referencedBy: referencedBy.length === 0 ? ["- none"] : referencedBy
28785
+ };
28786
+ }
28787
+ function issueSummary(issue, events, references, pictures, graph, linkBase, coverage, agents) {
28623
28788
  const asks = issue.open_asks ?? [];
28624
28789
  const labels = issue.labels ?? [];
28625
28790
  const links = issue.external_links ?? [];
28626
- const members = typeof references === "string" ? [] : references.members ?? [];
28791
+ const sections = referenceSections(references, graph.incoming, graph.outgoing);
28627
28792
  const spec = issue.artifacts?.find((artifact) => artifact.primary);
28628
28793
  const specApproval = spec === undefined ? undefined : approvalLine(spec, typeof issue.closed_at === "string");
28629
28794
  if (issue.priority === undefined)
@@ -28660,11 +28825,11 @@ function issueSummary(issue, events, references, graph, linkBase, coverage, agen
28660
28825
  "Open asks:",
28661
28826
  ...asks.length === 0 ? ["- none"] : asks.map((ask) => `- ${ask.id}: ${ask.question}`),
28662
28827
  "References:",
28663
- ...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}`),
28664
- ...typeof references === "string" || !references.truncated ? [] : ["- more references beyond 8 hops"],
28828
+ ...sections.references,
28665
28829
  "Events:",
28666
28830
  ...events.length === 0 ? ["- none"] : events.map(eventLine),
28667
- ...graph
28831
+ ...pictures,
28832
+ ...graphSectionLines(graph.incoming, graph.outgoing, sections.referencedBy)
28668
28833
  ].join(`
28669
28834
  `);
28670
28835
  }
@@ -29515,124 +29680,6 @@ async function resultsCommand(context) {
29515
29680
  };
29516
29681
  }
29517
29682
 
29518
- // ../envoy-client/src/dispatch-commands/render-graph.ts
29519
- function referenceLines(read) {
29520
- if (typeof read === "string")
29521
- return [`- ${read}`];
29522
- const edges = read.edges ?? [];
29523
- if (edges.length === 0)
29524
- return ["- none"];
29525
- return edges.map(edgeLine);
29526
- }
29527
- function isItemKind(kind) {
29528
- return ITEM_KINDS.some((item) => item === kind);
29529
- }
29530
- function edgeLine(edge) {
29531
- const { node } = edge;
29532
- const excerpt = edge.excerpt === undefined ? "" : `${textHead(edge.excerpt.text)} \xB7 `;
29533
- const block = edge.block === undefined ? "" : ` (block ${edge.block.ref ?? edge.block.id})`;
29534
- const parent = node.parent ?? undefined;
29535
- const item = node.kind === "block" && node.document === undefined && isItemKind(parent?.kind) ? parent : undefined;
29536
- const source = item === undefined ? `${node.kind} ${node.ref ?? node.id}` : `${item.kind} ${item.ref ?? item.id} block ${node.block_id ?? node.id}`;
29537
- return `- ${edge.kind} ${source} (${excerpt}${edge.created_at})${block}`;
29538
- }
29539
- function unavailableReason(error) {
29540
- return dispatchAnswered(error, 404) ? "unavailable" : `unavailable: ${messageFor(error)}`;
29541
- }
29542
- async function graphReferences(client, query) {
29543
- try {
29544
- return await client.getReferences(query);
29545
- } catch (error) {
29546
- return unavailableReason(error);
29547
- }
29548
- }
29549
- async function issueReferencesOrUnavailable(client, key) {
29550
- try {
29551
- return await client.getIssueReferences(key);
29552
- } catch (error) {
29553
- return unavailableReason(error);
29554
- }
29555
- }
29556
- async function issueCoverageOrReason(client, key) {
29557
- try {
29558
- return await client.issueCoverage(key);
29559
- } catch (error) {
29560
- return unavailableReason(error);
29561
- }
29562
- }
29563
- async function graphSections(client, ref) {
29564
- const [incoming, outgoing] = await Promise.all([
29565
- graphReferences(client, { to: ref }),
29566
- graphReferences(client, { from: ref })
29567
- ]);
29568
- return graphSectionLines(incoming, outgoing);
29569
- }
29570
- function graphSectionLines(incoming, outgoing) {
29571
- return [
29572
- ...typeof incoming === "string" ? [] : nodeLine(incoming.node),
29573
- "Referenced by:",
29574
- ...referenceLines(incoming),
29575
- "Links:",
29576
- ...referenceLines(outgoing)
29577
- ];
29578
- }
29579
- function nodeLine(node) {
29580
- if (node.made_by === undefined)
29581
- return [];
29582
- const fact = (by, time) => `${by == null || by.length === 0 ? "nobody recorded" : by.map(actorText).join(", ")}${time == null ? "" : ` at ${time}`}`;
29583
- const made = fact(node.made_by, node.made_at);
29584
- const changed = fact(node.changed_by, node.changed_at);
29585
- const { parent } = node;
29586
- 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})`}`;
29587
- return [
29588
- `Node: ${node.kind} ${node.ref ?? node.id} \xB7 made by ${made} \xB7 changed by ${changed}${partOf}`
29589
- ];
29590
- }
29591
- function blockLines(node, ref, typed, noun = "Block") {
29592
- const unit = ref.item === undefined ? "version" : "revision";
29593
- const blockID = node.block_id ?? ref.block;
29594
- const head = ref.item === undefined ? [
29595
- `Block: ${blockID}`,
29596
- ...typed === undefined ? [] : [`Type: ${typed.type}`],
29597
- `Document: ${node.document ?? ref.document}`,
29598
- ...(typed?.attributes ?? []).map((attribute) => `${attribute.name}: ${attribute.value === "" ? "(empty)" : attribute.value}`),
29599
- ...node.changed_version === undefined ? [] : [`Changed in version: ${node.changed_version}`],
29600
- ...node.text === undefined ? [] : ["Text:", node.text]
29601
- ] : [
29602
- `${noun} ${blockID} of ${ref.item.kind} ${ref.item.id}${node.changed_version === undefined ? "" : ` (changed in revision ${node.changed_version})`}:`,
29603
- ...node.text === undefined ? [] : [node.text]
29604
- ];
29605
- const { pin } = node;
29606
- if (pin === undefined)
29607
- return head;
29608
- 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}.`;
29609
- return [
29610
- ...head,
29611
- `Pinned to ${unit}: ${pin.version}`,
29612
- state,
29613
- `Text at ${unit} ${pin.version}:`,
29614
- pin.text
29615
- ];
29616
- }
29617
- async function typedBlockOf(client, ref) {
29618
- if (ref.item !== undefined || ref.block === undefined)
29619
- return;
29620
- try {
29621
- const blocks = ref.owner.kind === "project" ? await client.projectArtifactBlocks(ref.owner.project, ref.id) : await client.issueArtifactBlocks(ref.owner.issue, ref.id);
29622
- return blocks.find((block) => block.id === ref.block);
29623
- } catch {
29624
- return;
29625
- }
29626
- }
29627
- function askPartNoun(ask, node, blockID) {
29628
- if (ask.answer?.id === blockID)
29629
- return "Answer";
29630
- if ((ask.options ?? []).some((option) => option.id === blockID))
29631
- return "Option";
29632
- const placed = (ask.revision ?? 0) > 0 && (ask.options ?? []).every((option) => option.id !== undefined) && (ask.answer === null || ask.answer.id !== undefined);
29633
- return placed && node.pin?.state !== "removed" ? "Question" : "Part";
29634
- }
29635
-
29636
29683
  // ../envoy-client/src/dispatch-commands/render-item.ts
29637
29684
  function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
29638
29685
  const answer = ask.answer;
@@ -31301,9 +31348,11 @@ async function readCommand(context) {
31301
31348
  const readPromise = client.read(issueKey, readEvents);
31302
31349
  const referencesPromise = issueReferencesOrUnavailable(client, issueKey);
31303
31350
  const read = await readPromise;
31304
- const [references, graph, agents, pictures, coverage] = await Promise.all([
31351
+ const issueRef = dispatchIssueRef(read.issue.key);
31352
+ const [references, incoming, outgoing, agents, pictures, coverage] = await Promise.all([
31305
31353
  referencesPromise,
31306
- graphSections(client, dispatchIssueRef(read.issue.key)),
31354
+ graphReferences(client, { to: issueRef }),
31355
+ graphReferences(client, { from: issueRef }),
31307
31356
  liveAgents(client, holdsSession(read.issue.claim) || routeHeldBySession(read.issue)),
31308
31357
  picturesOf([
31309
31358
  ...(read.issue.open_asks ?? []).map((ask) => ({ text: ask.question, at: ask.created_at })),
@@ -31312,7 +31361,7 @@ async function readCommand(context) {
31312
31361
  issueCoverageOrReason(client, read.issue.key)
31313
31362
  ]);
31314
31363
  return {
31315
- text: issueSummary(read.issue, read.events, references, [...pictures.lines, ...graph], linkBase, coverage, agents),
31364
+ text: issueSummary(read.issue, read.events, references, pictures.lines, { incoming, outgoing }, linkBase, coverage, agents),
31316
31365
  details: { issue: read.issue.key },
31317
31366
  ...showImages(pictures),
31318
31367
  ...olderServerWarnings(read.issue)