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