@sjawhar/opencode-legion-envoy 1.42.0 → 1.42.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.
Files changed (2) hide show
  1. package/dist/src/server.js +55 -33
  2. package/package.json +1 -1
@@ -13659,13 +13659,20 @@ var CommentEventPayloadSchema = object({
13659
13659
  ask_state: _enum2(["open", "answered", "resolved"]).optional(),
13660
13660
  ask_waiting_on: _enum2(ASK_TURNS).optional(),
13661
13661
  turn: _enum2(ASK_TURNS).nullish(),
13662
- anchor: object({ block_id: string2().nullable().optional(), quote: string2().optional() }).nullish(),
13662
+ anchor: object({
13663
+ artifact_id: string2().optional(),
13664
+ block_id: string2().nullable().optional(),
13665
+ mark_id: string2().optional(),
13666
+ orphaned: boolean2().optional(),
13667
+ quote: string2().optional(),
13668
+ version: number2().int().optional()
13669
+ }).nullish(),
13663
13670
  suggestion: object({ replace_with: string2().optional() }).nullish(),
13664
13671
  author: object({ kind: string2(), id: string2() }).optional(),
13665
13672
  created_at: string2().optional(),
13666
13673
  mentions: array(CommentMentionSchema).optional(),
13667
13674
  deliveries: array(CommentDeliverySchema).optional()
13668
- });
13675
+ }).passthrough();
13669
13676
  var MessageEventPayloadSchema = object({
13670
13677
  id: string2().optional(),
13671
13678
  body: string2().optional(),
@@ -15825,6 +15832,20 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, serverUrl, pro
15825
15832
  const issue = `${repo}#${legionIssue}`;
15826
15833
  return { args: { ...args, issue }, ref, owner: { kind: "issue", issue } };
15827
15834
  }
15835
+ function artifactByReference(artifacts, artifactReference, owner) {
15836
+ const byIdOrSlug = artifacts.find((candidate) => candidate.id === artifactReference) ?? artifacts.find((candidate) => candidate.slug === artifactReference);
15837
+ if (byIdOrSlug !== undefined)
15838
+ return byIdOrSlug;
15839
+ const byName = artifacts.filter((candidate) => candidate.name === artifactReference);
15840
+ if (byName.length > 1) {
15841
+ throw new Error(documentReferenceProblem(artifactReference, byName, owner, true));
15842
+ }
15843
+ const [artifact] = byName;
15844
+ if (artifact === undefined) {
15845
+ throw new Error(documentReferenceProblem(artifactReference, artifacts, owner));
15846
+ }
15847
+ return artifact;
15848
+ }
15828
15849
  async function resolveArtifact(client, owner, artifactReference) {
15829
15850
  if (owner.kind === "project") {
15830
15851
  if (artifactReference === undefined) {
@@ -15839,17 +15860,10 @@ async function resolveArtifact(client, owner, artifactReference) {
15839
15860
  if (!(error instanceof DispatchServiceError) || error.status !== 404)
15840
15861
  throw error;
15841
15862
  const artifacts = await client.listProjectArtifacts(owner.project, true);
15842
- const artifact = artifacts.find((candidate) => candidate.id === artifactReference) ?? artifacts.find((candidate) => candidate.slug === artifactReference);
15843
- if (artifact)
15844
- return { owner, artifact };
15845
- const names = artifacts.filter((candidate) => candidate.name === artifactReference);
15846
- if (names.length > 1) {
15847
- throw new Error(documentReferenceProblem(artifactReference, names, "project", true));
15848
- }
15849
- if (names[0] === undefined) {
15850
- throw new Error(documentReferenceProblem(artifactReference, artifacts, "project"));
15851
- }
15852
- return { owner, artifact: names[0] };
15863
+ return {
15864
+ owner,
15865
+ artifact: artifactByReference(artifacts, artifactReference, "project")
15866
+ };
15853
15867
  }
15854
15868
  }
15855
15869
  const issue = await client.getIssue(owner.issue);
@@ -15857,14 +15871,7 @@ async function resolveArtifact(client, owner, artifactReference) {
15857
15871
  if (artifactReference === undefined || artifactReference === "spec") {
15858
15872
  artifact = issue.artifacts.find((candidate) => candidate.primary || candidate.id === issue.primary_artifact_id);
15859
15873
  } else {
15860
- artifact = issue.artifacts.find((candidate) => candidate.id === artifactReference || candidate.slug === artifactReference);
15861
- if (artifact === undefined) {
15862
- const names = issue.artifacts.filter((candidate) => candidate.name === artifactReference);
15863
- if (names.length > 1) {
15864
- throw new Error(documentReferenceProblem(artifactReference, names, "issue", true));
15865
- }
15866
- artifact = names[0];
15867
- }
15874
+ artifact = artifactByReference(issue.artifacts, artifactReference, "issue");
15868
15875
  }
15869
15876
  if (!artifact) {
15870
15877
  throw new Error(documentReferenceProblem(artifactReference ?? "spec", issue.artifacts, "issue"));
@@ -16012,12 +16019,14 @@ function logSummary(issue, events) {
16012
16019
  function eventHead(event) {
16013
16020
  switch (event.type) {
16014
16021
  case "ask.opened":
16022
+ case "ask.anchor_refreshed":
16015
16023
  case "ask.edited":
16016
16024
  case "ask.resolved":
16017
16025
  return textHead(event.payload.question);
16018
16026
  case "ask.answered":
16019
16027
  return `${textHead(event.payload.question)} -> ${textHead(askAnswerText(event.payload.answer))}`;
16020
16028
  case "comment.created":
16029
+ case "comment.anchor_refreshed":
16021
16030
  case "comment.edited":
16022
16031
  case "comment.resolved":
16023
16032
  case "comment.reopened":
@@ -16155,19 +16164,21 @@ function messageSummary({ message, replies }, graph) {
16155
16164
  `);
16156
16165
  }
16157
16166
  async function openArtifactMarks(client, resolved) {
16158
- const asks = resolved.owner.kind === "project" ? await client.getArtifactAsks(resolved.artifact.id) : resolved.issue?.open_asks ?? [];
16167
+ const asksPromise = resolved.owner.kind === "project" ? client.getArtifactAsks(resolved.artifact.id) : Promise.resolve(resolved.issue?.open_asks ?? []);
16168
+ const commentsPromise = resolved.owner.kind === "project" ? client.getArtifactComments(resolved.artifact.id) : client.getComments(resolved.issue?.key ?? "", resolved.artifact.id);
16169
+ const commentsResultPromise = commentsPromise.then((value) => ({ status: "fulfilled", value }), (reason) => ({ status: "rejected", reason }));
16170
+ const asks = await asksPromise;
16159
16171
  const marks = asks.filter((ask) => ask.state === "open" && ask.anchor?.artifact_id === resolved.artifact.id).map((ask) => `ask ${ask.id}`);
16160
- let comments;
16161
- try {
16162
- comments = resolved.owner.kind === "project" ? await client.getArtifactComments(resolved.artifact.id) : await client.getComments(resolved.issue?.key ?? "", resolved.artifact.id);
16163
- } catch (error) {
16164
- if (error instanceof DispatchServiceError && error.status === 404)
16172
+ const commentsResult = await commentsResultPromise;
16173
+ if (commentsResult.status === "rejected") {
16174
+ if (commentsResult.reason instanceof DispatchServiceError && commentsResult.reason.status === 404) {
16165
16175
  return marks;
16166
- throw error;
16176
+ }
16177
+ throw commentsResult.reason;
16167
16178
  }
16168
16179
  return [
16169
16180
  ...marks,
16170
- ...comments.filter((comment) => !comment.resolved && comment.anchor?.artifact_id === resolved.artifact.id).map((comment) => `comment ${comment.id}`)
16181
+ ...commentsResult.value.filter((comment) => !comment.resolved && comment.anchor?.artifact_id === resolved.artifact.id).map((comment) => `comment ${comment.id}`)
16171
16182
  ];
16172
16183
  }
16173
16184
  async function executeDispatchTool(input) {
@@ -16586,8 +16597,14 @@ ${followsAsk(askOwner)}`,
16586
16597
  const artifactReference = optionalString(args, "artifact") ?? (ownerArguments.ref?.kind === "spec" || ownerArguments.ref?.kind === "artifact" ? ownerArguments.ref.id : undefined);
16587
16598
  const resolved = await resolveArtifact(client, documentOwner(), artifactReference);
16588
16599
  const version = optionalNumber(args, "version") ?? ownerArguments.ref?.version;
16589
- const document = await client.docRead(resolved.artifact.id, version);
16590
- const marks = await openArtifactMarks(client, resolved);
16600
+ const documentPromise = client.docRead(resolved.artifact.id, version);
16601
+ const marksPromise = openArtifactMarks(client, resolved);
16602
+ const marksResultPromise = marksPromise.then((value) => ({ status: "fulfilled", value }), (reason) => ({ status: "rejected", reason }));
16603
+ const document = await documentPromise;
16604
+ const marksResult = await marksResultPromise;
16605
+ if (marksResult.status === "rejected")
16606
+ throw marksResult.reason;
16607
+ const marks = marksResult.value;
16591
16608
  const approval = approvalLine(resolved.artifact);
16592
16609
  const trailer = [
16593
16610
  ...marks.length === 0 ? [] : [`Open anchored asks/comments: ${marks.join(", ")}`],
@@ -16722,21 +16739,26 @@ ${trailer.join(`
16722
16739
  }
16723
16740
  };
16724
16741
  }
16725
- const read = await client.read(issue());
16742
+ const issueKey = issue();
16726
16743
  if (ownerArguments.ref?.kind === "log") {
16744
+ const read = await client.read(issueKey);
16727
16745
  return {
16728
16746
  text: logSummary(read.issue, read.events),
16729
16747
  details: { issue: read.issue.key }
16730
16748
  };
16731
16749
  }
16732
16750
  if (ownerArguments.ref?.kind === "children") {
16751
+ const read = await client.read(issueKey);
16733
16752
  return {
16734
16753
  text: childrenSummary(read.issue),
16735
16754
  details: { issue: read.issue.key }
16736
16755
  };
16737
16756
  }
16757
+ const readPromise = client.read(issueKey);
16758
+ const referencesPromise = issueReferencesOrUnavailable(client, issueKey);
16759
+ const read = await readPromise;
16738
16760
  const [references, graph] = await Promise.all([
16739
- issueReferencesOrUnavailable(client, read.issue.key),
16761
+ referencesPromise,
16740
16762
  graphSections(client, dispatchIssueRef(read.issue.key))
16741
16763
  ]);
16742
16764
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/opencode-legion-envoy",
3
- "version": "1.42.0",
3
+ "version": "1.42.2",
4
4
  "type": "module",
5
5
  "main": "dist/src/server.js",
6
6
  "exports": {