@sjawhar/claude-envoy 2.1.0 → 2.3.0

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.
@@ -14113,8 +14113,14 @@ function brokenParts(parts) {
14113
14113
  var CONTENT_IS_MARKDOWN = "content is stored as a Markdown document, which rewrites other text (a JSONL file's lines come back joined into one paragraph)";
14114
14114
  var PATH_KEEPS_BYTES = "path (--path <file>), which stores a file whose path does not end in .md or .markdown as its bytes, unchanged";
14115
14115
  var ARTIFACT_CONTENT_NAME_RULE = `${CONTENT_IS_MARKDOWN}, so with content the name ends in .md or .markdown or has no extension; upload any other file (.jsonl, .tsv, .json, .txt) with ${PATH_KEEPS_BYTES}.`;
14116
+ var ARTIFACT_NAME_EXISTS_RULE = "An upload under the name of a document the owner already holds is refused: it writes that document's next version, over the text it holds. Change a document with dispatch doc-edit. Send the upload again with force (--force) to write the next version.";
14117
+ var ARTIFACT_STORED_TEXT_RULE = `content and content-file hold text Dispatch stores as Markdown, and a text the store would write under another spelling is refused. The refusal prints the text Dispatch stores: send that text. A name that does not end in .md or .markdown has a second way out, which keeps the text as it was written: send it as a file with ${PATH_KEEPS_BYTES}.`;
14116
14118
  var NAME_EXTENSION = /\.([^\s.]+)$/u;
14117
14119
  var MARKDOWN_EXTENSION = /^(md|markdown)$/i;
14120
+ function pathKeepsBytesOf(name) {
14121
+ const extension = NAME_EXTENSION.exec(name.trim())?.[1];
14122
+ return extension === undefined || !MARKDOWN_EXTENSION.test(extension);
14123
+ }
14118
14124
  var artifactOwner = documentOwnerValidation(false);
14119
14125
  function artifactProblem(value) {
14120
14126
  const input = value;
@@ -14256,6 +14262,42 @@ var handoffValidation = {
14256
14262
  message: HANDOFF_RULE,
14257
14263
  refusal: (value) => handoffProblem(value) ?? HANDOFF_RULE
14258
14264
  };
14265
+ var RESULT_REQUIRED_FIELDS = ["issue", "check", "role", "verdict", "commit"];
14266
+ var RESULT_RECORD_FIELDS = [
14267
+ ...RESULT_REQUIRED_FIELDS,
14268
+ "surface",
14269
+ "run",
14270
+ "observed",
14271
+ "negative_control",
14272
+ "failed",
14273
+ "skipped",
14274
+ "excluded",
14275
+ "screenshots"
14276
+ ];
14277
+ var RESULT_RETRACT_RULE = "Pass retract with the id of a result recorded before, and reason with why that result is " + "wrong, to retract it.";
14278
+ var RESULT_SHAPE_RULE = `${RESULT_RETRACT_RULE} A call with retract takes reason and no other argument. A call ` + "without retract records a result, and it takes issue, check, role, verdict and commit.";
14279
+ function resultProblem(value) {
14280
+ const input = value;
14281
+ const carried = RESULT_RECORD_FIELDS.filter((field) => input[field] !== undefined);
14282
+ if (typeof input["retract"] === "string") {
14283
+ const reason = input["reason"];
14284
+ if (typeof reason !== "string" || reason.trim() === "") {
14285
+ return "retract needs reason, the words that say why the result is wrong.";
14286
+ }
14287
+ if (carried.length > 0) {
14288
+ return `retract takes reason alone, and this call also carries ${carried.join(", ")}. Retract the result, then record a new one with a call of its own.`;
14289
+ }
14290
+ return;
14291
+ }
14292
+ if (input["reason"] !== undefined) {
14293
+ return "reason goes with retract, and this call carries no retract. Name the result to retract, or drop reason.";
14294
+ }
14295
+ const missing = RESULT_REQUIRED_FIELDS.filter((field) => input[field] === undefined);
14296
+ if (missing.length > 0) {
14297
+ return `recording a result needs ${missing.join(", ")}. ${RESULT_RETRACT_RULE}`;
14298
+ }
14299
+ return;
14300
+ }
14259
14301
  var SEARCH_QUERY_MAX = 1000;
14260
14302
  var SEARCH_QUERY_HINT = "search with a short phrase of a few words, not a passage";
14261
14303
  var SEARCH_KIND_DEPTH = 100;
@@ -14609,13 +14651,13 @@ var dispatchToolSpecs = [
14609
14651
  verdict: "pass",
14610
14652
  commit: "1111111111111111111111111111111111111111"
14611
14653
  },
14612
- description: "Record one result of one check of an issue's Verification document, and print the " + "pull-request body line it implies. The check is named by its block id, or, when two " + "Verification documents in reach share that id, by its canonical reference " + "(dispatch://KEY/artifact/verification-md#b-<id>); 409 CHECK_AMBIGUOUS names them, and an " + "id no Verification document of the issue or of an issue above it holds is 400 " + "UNKNOWN_CHECK. A pass counting any failed, skipped or excluded case contradicts itself " + "and is 400 RESULT_CONTRADICTS. Dispatch asks GitHub whether the repository of the " + "check's issue holds the commit: one it does not hold is 400 RESULT_COMMIT_UNKNOWN, " + "naming the commit and that owner/repo, so record the result after the commit is pushed. " + "A repository Dispatch cannot read records the result as before. " + "The result is recorded against the check's own issue, so " + "a child's run of a parent's check appears under that check. A closed issue takes a " + "result only for a check whose when is after_merge or default_branch \u2014 the production " + "check after the merge \u2014 and refuses every other one with 409 ISSUE_CLOSED, as it refuses " + "every other write. Write the printed line into the pull-request body unchanged: it is " + "the one grammar every writer uses, and it carries no link to Dispatch. " + ISSUE_REFERENCE,
14654
+ description: "Record one result of one check of an issue's Verification document, or retract a result " + "recorded before. A record prints the pull-request body line it implies. Write that line " + "into the pull-request body unchanged: it is the one grammar every writer uses, and it " + "carries no link to Dispatch. " + "Name the check by its block id. Where two Verification documents in reach hold that id, " + "name it by its canonical reference (dispatch://KEY/artifact/verification-md#b-<id>). " + "409 CHECK_AMBIGUOUS names both documents. An id no Verification document of the issue " + "or of an issue above it holds is 400 UNKNOWN_CHECK. " + "A pass that counts a failed, a skipped or an excluded case contradicts itself, and is " + "400 RESULT_CONTRADICTS. " + "Dispatch asks GitHub whether the repository of the check's issue holds the commit. A " + "commit that repository does not hold is 400 RESULT_COMMIT_UNKNOWN, which names the " + "commit and that owner/repo. Record the result after the commit is pushed. A repository " + "Dispatch cannot read records the result as before. " + "The result is recorded against the check's own issue, so a child's run of a parent's " + "check appears under that check. A closed issue takes a result only for a check whose " + "when is after_merge or default_branch, the production check after the merge. It refuses " + "every other record with 409 ISSUE_CLOSED, as it refuses every other write. " + RESULT_RETRACT_RULE + " The retraction keeps both records: the result stays readable, and it proves nothing " + "from then on. Record a new result where the check still needs one. A retraction is " + "taken on a closed issue and for a check of any when. Three callers may retract: the " + "session that recorded the result, a session that holds the Dispatch claim of the issue " + "the result was recorded on, and a caller whose credential carries a person. Every other " + "caller is 403 RETRACTION_FORBIDDEN. A result retracted already is 409 RESULT_RETRACTED. " + ISSUE_REFERENCE,
14613
14655
  arguments: (z) => ({
14614
- issue: z.string().describe(ISSUE_REFERENCE),
14615
- check: z.string().describe("The check block's id, or its canonical reference dispatch://KEY/artifact/verification-md#b-<id> when the id is not unique among the issue's Verification document and those of the issues above it."),
14616
- role: z.string({ max: 32 }).describe("Who ran it: implementer, tester, reviewer. At most 32 characters of a-z and -, printed in the pull-request line."),
14617
- verdict: z.enum(["pass", "fail"]).describe("Whether the check passed."),
14618
- commit: z.string().describe("The 40-character lowercase hex commit the check ran at."),
14656
+ issue: z.string().describe(ISSUE_REFERENCE).optional(),
14657
+ check: z.string().describe("The check block's id, or its canonical reference dispatch://KEY/artifact/verification-md#b-<id> when the id is not unique among the issue's Verification document and those of the issues above it.").optional(),
14658
+ role: z.string({ max: 32 }).describe("Who ran it: implementer, tester, reviewer. At most 32 characters of a-z and -, printed in the pull-request line.").optional(),
14659
+ verdict: z.enum(["pass", "fail"]).describe("Whether the check passed.").optional(),
14660
+ commit: z.string().describe("The 40-character lowercase hex commit the check ran at.").optional(),
14619
14661
  surface: z.string().describe("Where a person reaches the change.").optional(),
14620
14662
  run: z.string().describe("The command that proved it.").optional(),
14621
14663
  observed: z.string().describe("What the command printed.").optional(),
@@ -14623,28 +14665,38 @@ var dispatchToolSpecs = [
14623
14665
  failed: z.number({ int: true, min: 0 }).describe("Cases the run failed; 0 by default.").optional(),
14624
14666
  skipped: z.number({ int: true, min: 0 }).describe("Cases the run skipped; 0 by default.").optional(),
14625
14667
  excluded: z.number({ int: true, min: 0 }).describe("Cases the run excluded; 0 by default.").optional(),
14626
- screenshots: z.array(z.string()).describe("dispatch:// references to image documents of this issue or of the check's issue.").optional()
14627
- })
14668
+ screenshots: z.array(z.string()).describe("dispatch:// references to image documents of this issue or of the check's issue.").optional(),
14669
+ retract: z.string().describe("The id of a result recorded before. It records that the result is wrong, and it takes reason alone beside it.").optional(),
14670
+ reason: z.string().describe("Why the retracted result is wrong. It goes with retract and with nothing else.").optional()
14671
+ }),
14672
+ validation: {
14673
+ check: (value) => resultProblem(value) === undefined,
14674
+ message: RESULT_SHAPE_RULE,
14675
+ refusal: (value) => resultProblem(value) ?? RESULT_SHAPE_RULE
14676
+ }
14628
14677
  },
14629
14678
  {
14630
14679
  name: "dispatch_results",
14631
14680
  example: { issue: "DSP-1" },
14632
- description: "Print each check of an issue's Verification document with its latest result and whether " + "that result is current. A result is current when it ran at the commit the work stands at " + "\u2014 the head of an open pull request of the check's issue, the final head of a merged one, " + "for an after_merge check a commit on the branch that issue's pull request merged into or " + "on the repository's default branch (which answers alone where Dispatch holds no merge of " + "that issue), or for a default_branch check a commit on the repository's default branch, " + "whatever branch the pull request merged into \u2014 and the check's words have not changed " + "since; older otherwise, and unknown when Dispatch cannot read the repository. On an " + "after_merge check's base branch a read GitHub refused \u2014 a 403 or 404, which a branch it " + "no longer holds answers with \u2014 says the commit is not on that branch and leaves the " + "default branch to decide; every other failure of that read, a rate limit or a 5xx " + "among them, leaves the result unknown and never older. A push that moves the " + "pull request's head makes a result older with no write of anyone's: record it again at " + "the new head. " + ISSUE_REFERENCE,
14681
+ description: "Print each check of an issue's Verification document with every result recorded against " + "it, newest first. " + "Each check prints what Dispatch compared its results with. A before_merge check is " + "compared with the head of each pull request Dispatch holds for the check's issue, open " + "or merged. An after_merge check is compared with the branch that issue's pull request " + "merged into and with the repository's default branch, and with the default branch alone " + "where Dispatch holds no merge of the issue. A default_branch check is compared with the " + "repository's default branch alone, whatever branch the pull request merged into. Where " + "a check compared with nothing, it says which of three things happened: the issue has no " + "pull request and no branch to compare with, Dispatch cannot read the repository, or a " + "read Dispatch made did not answer. " + "Each check then prints one line that answers the gate: whether a pass of it stands, and " + "from which roles. A pass stands when its commit is one of the commits the check " + "compared with, the check's words did not move after the result was recorded, and no " + "retraction stands against it. " + "The check's own words print once, under the check. Each result then prints its verdict, " + "its role, its whole 40-character commit, where that commit stands, whether the check's " + "words moved after it was recorded, the time, its id, and the reading the role recorded. " + "A result nobody gave a reading says so. A retracted result prints as retracted, with " + "the reason and the caller that retracted it. A check with no result says so. " + "A push that moves a pull request's head leaves a result at the commit before it, with " + "no write of anyone's: record the check again at the new head. " + ISSUE_REFERENCE,
14633
14682
  arguments: (z) => ({
14634
- issue: z.string().describe(ISSUE_REFERENCE)
14683
+ issue: z.string().describe(ISSUE_REFERENCE),
14684
+ at: z.string().describe("One commit of 40 lowercase hex characters. It becomes the only thing every check is compared with, and Dispatch reads GitHub for none of it.").optional(),
14685
+ brief: z.boolean().describe("Cut each reading whose result stands at none of the compared commits to its first 200 characters. Every other reading prints whole.").optional()
14635
14686
  })
14636
14687
  },
14637
14688
  {
14638
14689
  name: "dispatch_artifact",
14639
14690
  example: { issue: "DSP-1", name: "design.md", content: `# Design
14640
14691
  ` },
14641
- description: "Attach a local file or inline text as an issue artifact or project document. Do not use it to edit a live document; use " + "dispatch doc-edit instead. Never upload a document's own name to change it (spec.md replaces the spec whole); edit it with dispatch doc-edit. Uploading the same name again makes its next version, and so does uploading a document's slug (plan-md for plan.md). Exactly one of path or content is required; a markdown document is at most 1 MiB and any other file at most 25 MiB. " + `${ARTIFACT_CONTENT_NAME_RULE} ` + "Markdown is also refused with 413 CAP_EXCEEDED when it makes more than 65,536 elements (a block weighs 3, and an empty list item, quote, footnote definition or typed block 3 more for the empty paragraph it holds; a table cell 4, a hard line break 3, an image 3, a piece of inline HTML 2, an autolink 2, a footnote reference 2; inline syntax, marks, lines of text and backslash escapes or character references 1 each), or when a new version would leave the document's stored markdown (what its text reads back as) longer than 1 MiB or making more than 65,536 elements, and longer or heavier than before; shorten it or split it across documents. " + "In a table row, write every | in a cell as \\|, in code too: a | after two backslashes ends the cell, and a row with more cells than its table is refused. " + "Markdown holding an ask block whose body breaks its content rule (one or more question paragraphs, then at most one bullet list of options, last) is refused with 400 INVALID_ASK_BLOCK; a new version of a document is held to it only for the asks it writes or changes. " + `${OWNER_REFERENCE}`,
14692
+ description: "Attach a local file or inline text as an issue artifact or project document. Do not use it to edit a live document; use " + "dispatch doc-edit instead. Never upload a document's own name to change it (spec.md replaces the spec whole); edit it with dispatch doc-edit. Exactly one of path or content is required; a markdown document is at most 1 MiB and any other file at most 25 MiB. " + `${ARTIFACT_NAME_EXISTS_RULE} ` + `${ARTIFACT_CONTENT_NAME_RULE} ${ARTIFACT_STORED_TEXT_RULE} ` + "Markdown is also refused with 413 CAP_EXCEEDED when it makes more than 65,536 elements (a block weighs 3, and an empty list item, quote, footnote definition or typed block 3 more for the empty paragraph it holds; a table cell 4, a hard line break 3, an image 3, a piece of inline HTML 2, an autolink 2, a footnote reference 2; inline syntax, marks, lines of text and backslash escapes or character references 1 each), or when a new version would leave the document's stored markdown (what its text reads back as) longer than 1 MiB or making more than 65,536 elements, and longer or heavier than before; shorten it or split it across documents. " + "In a table row, write every | in a cell as \\|, in code too: a | after two backslashes ends the cell, and a row with more cells than its table is refused. " + "Markdown holding an ask block whose body breaks its content rule (one or more question paragraphs, then at most one bullet list of options, last) is refused with 400 INVALID_ASK_BLOCK; a new version of a document is held to it only for the asks it writes or changes. " + `${OWNER_REFERENCE}`,
14642
14693
  arguments: (z) => ({
14643
14694
  issue: z.string().describe(ISSUE_REFERENCE).optional(),
14644
14695
  project: z.string().describe("Project key for an unlinked document.").optional(),
14645
14696
  name: z.string().describe("Artifact filename shown in Dispatch."),
14646
14697
  path: z.string().describe("Local path to the file to upload.").optional(),
14647
- content: z.string().describe("Inline text to store as a Markdown document, under a name ending in .md or .markdown or with no extension; a CR LF or a lone carriage return in it is stored as a line feed.").optional(),
14698
+ content: z.string().describe("Inline text to store as a Markdown document, under a name ending in .md or .markdown or with no extension. The command refuses a text the store would write under another spelling, a CR LF or a lone carriage return among them, which Dispatch stores as a line feed. A missing line feed at the end is not such a text: Dispatch adds one, and the upload goes on. The refusal prints the text Dispatch stores, which is the text to send.").optional(),
14699
+ force: z.boolean().describe("Write the next version of a document the owner already holds under this name; without it the upload of a name that exists is refused.").optional(),
14648
14700
  summary: z.string().describe("Optional version summary.").optional()
14649
14701
  }),
14650
14702
  validation: {
@@ -16114,8 +16166,17 @@ function askAnswerText(answer) {
16114
16166
  }
16115
16167
 
16116
16168
  // ../envoy-client/src/errors.ts
16169
+ function dispatchCode(error) {
16170
+ if (!("fromDispatch" in error) || !("code" in error))
16171
+ return;
16172
+ const code = error.code;
16173
+ return typeof code === "string" && code !== "" ? code : undefined;
16174
+ }
16117
16175
  function messageFor(error) {
16118
- return error instanceof Error ? error.message : String(error);
16176
+ if (!(error instanceof Error))
16177
+ return String(error);
16178
+ const code = dispatchCode(error);
16179
+ return code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
16119
16180
  }
16120
16181
  function hasErrnoCode(error, code) {
16121
16182
  return error instanceof Error && "code" in error && error.code === code;
@@ -17084,6 +17145,13 @@ class DispatchClient {
17084
17145
  return answer;
17085
17146
  throw new Error(`GET ${this.#url(path, query)} asked for the unpaged listing and got ${whyNotAnArray(answer)}.`);
17086
17147
  }
17148
+ async listIssueArtifacts(issue) {
17149
+ return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "artifacts"]);
17150
+ }
17151
+ async markdownRoundTrip(markdown) {
17152
+ const answer = await this.#json("POST", ["api", "v1", "markdown", "round-trip"], { markdown });
17153
+ return answer.markdown;
17154
+ }
17087
17155
  async listProjectArtifacts(project, unlinked = false) {
17088
17156
  return this.#json("GET", ["api", "v1", "projects", project, "artifacts"], undefined, unlinked ? { unlinked: "true" } : undefined);
17089
17157
  }
@@ -17271,8 +17339,11 @@ class DispatchClient {
17271
17339
  async recordResult(issue, input) {
17272
17340
  return this.#json("POST", ["api", "v1", "issues", await this.#resolveIssue(issue), "results"], input);
17273
17341
  }
17274
- async issueResults(issue) {
17275
- return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "results"]);
17342
+ async issueResults(issue, at) {
17343
+ return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "results"], undefined, at === undefined ? undefined : { at });
17344
+ }
17345
+ async retractResult(resultID, input) {
17346
+ return this.#json("POST", ["api", "v1", "results", resultID, "retract"], input);
17276
17347
  }
17277
17348
  async editAsk(id, input) {
17278
17349
  return this.#json("PATCH", ["api", "v1", "asks", id], input);
@@ -17347,6 +17418,9 @@ class DispatchClient {
17347
17418
  async docRead(id, version) {
17348
17419
  return version === undefined ? this.#json("GET", ["api", "v1", "artifacts", id, "text"]) : this.#json("GET", ["api", "v1", "artifacts", id, "versions", String(version)]);
17349
17420
  }
17421
+ async docReadWithBlocks(id) {
17422
+ return this.#json("GET", ["api", "v1", "artifacts", id, "text"], undefined, { blocks: true });
17423
+ }
17350
17424
  async fileVersion(id, version) {
17351
17425
  const url = this.#url(["api", "v1", "artifacts", id, "versions", String(version)]);
17352
17426
  const response = await this.#send("GET", url, undefined, "*/*");
@@ -20132,11 +20206,11 @@ async function sessionAnswersSettled(session) {
20132
20206
  class ToolInputError extends Error {
20133
20207
  tool;
20134
20208
  problems;
20135
- constructor(tool, problems) {
20209
+ constructor(tool, problems, options) {
20136
20210
  const count = problems.length;
20137
20211
  const cli = isDispatchTool(tool);
20138
20212
  const help = cli ? [
20139
- `Allowed flags: ${commandFlags(tool).join(", ")}`,
20213
+ ...options?.aboutAFlag === false ? [] : [`Allowed flags: ${commandFlags(tool).join(", ")}`],
20140
20214
  `Example: ${commandLine(tool, exampleFor(tool))}`
20141
20215
  ] : [];
20142
20216
  super([
@@ -20294,6 +20368,17 @@ var triageAdviceShown = new Set;
20294
20368
  function adviceMemory() {
20295
20369
  return triageAdviceShown;
20296
20370
  }
20371
+ function handBackApprovalCommand(request) {
20372
+ const owner = request.owner.kind === "project" ? `--project ${request.owner.key} --artifact ${request.artifactID}` : request.primary ? `--issue ${request.owner.key}` : `--issue ${request.owner.key} --artifact ${request.artifactID}`;
20373
+ const verification = request.owner.kind === "issue" && request.primary && request.verification ? " --include-verification" : "";
20374
+ return `dispatch request-approval ${owner}${verification} ` + `--summary '<what changed since version ${request.summaryVersion}>'`;
20375
+ }
20376
+ function movedApprovalClauses(documents) {
20377
+ return documents.map((document) => `${document.name} asked about version ${document.requested_version} and is now version ${document.version}`).join("; ");
20378
+ }
20379
+ function movedApprovalDocuments(documents) {
20380
+ return documents.filter((document) => document.requested_version < document.version);
20381
+ }
20297
20382
  function renderAdvice(tool, key, advice, opts) {
20298
20383
  if (advice === undefined)
20299
20384
  return [];
@@ -20324,6 +20409,24 @@ function renderAdvice(tool, key, advice, opts) {
20324
20409
  lines.push(`You still have an open ask on ${key}: "${ask.question.slice(0, 80)}" (${ask.id}). Still needed? See the \`dispatch\` skill, "Close what you opened".`);
20325
20410
  }
20326
20411
  }
20412
+ const movedApproval = advice.moved_approval_request;
20413
+ if (movedApproval !== undefined && (tool === "dispatch_doc_edit" || tool === "dispatch_artifact")) {
20414
+ const documents = movedApproval.documents ?? [];
20415
+ const moved = movedApprovalDocuments(documents);
20416
+ const movedOwner = movedApproval.issue !== undefined && movedApproval.issue !== "" ? { kind: "issue", key: movedApproval.issue } : movedApproval.project !== undefined && movedApproval.project !== "" ? { kind: "project", key: movedApproval.project } : undefined;
20417
+ const first = documents[0];
20418
+ const firstMoved = moved[0];
20419
+ if (moved.length > 0 && movedOwner !== undefined && first !== undefined && firstMoved !== undefined) {
20420
+ const command = handBackApprovalCommand({
20421
+ owner: movedOwner,
20422
+ artifactID: first.artifact_id,
20423
+ primary: first.primary,
20424
+ verification: documents.slice(1).some((document) => document.role === "verification"),
20425
+ summaryVersion: firstMoved.requested_version
20426
+ });
20427
+ lines.push(`This write moved the open approval request (ask ${movedApproval.ask_id}): it waits on ` + "an agent now, not on the person, and nothing tells the person. " + `${movedApprovalClauses(moved)}. Once the human has agreed to every point in it, hand ` + `the same request back: ${command}. Not yours to hand back? Tell the issue's architect.`);
20428
+ }
20429
+ }
20327
20430
  const superseded = advice.superseded_approval;
20328
20431
  if (superseded !== undefined && (tool === "dispatch_doc_edit" || tool === "dispatch_artifact")) {
20329
20432
  const gates = Array.isArray(superseded.design_gates) ? superseded.design_gates : [];
@@ -20630,7 +20733,7 @@ async function refuseItemOffRef(tool, kind, ref, refText, item, documentId) {
20630
20733
  `${refText} names ${kind} ${item.id} on ${refOwnerName(ref)}, but it is on ${where}`
20631
20734
  ]);
20632
20735
  }
20633
- async function resolveIdPrefix(tool, kind, id, ownerName, list) {
20736
+ async function resolveIdPrefix(tool, kind, id, ownerName, list, candidates) {
20634
20737
  const fullID = normalizeUUID(id);
20635
20738
  if (fullID !== undefined)
20636
20739
  return fullID;
@@ -20640,9 +20743,13 @@ async function resolveIdPrefix(tool, kind, id, ownerName, list) {
20640
20743
  ]);
20641
20744
  }
20642
20745
  const prefix = id.toLowerCase();
20643
- const matches = (await list()).filter((item) => item.id.toLowerCase().startsWith(prefix));
20746
+ const all = await list();
20747
+ const matches = all.filter((item) => item.id.toLowerCase().startsWith(prefix));
20644
20748
  if (matches.length === 1 && matches[0] !== undefined)
20645
20749
  return matches[0].id;
20750
+ if (candidates !== undefined) {
20751
+ throw new ToolInputError(tool, [candidates.refusal(matches, all)], { aboutAFlag: false });
20752
+ }
20646
20753
  throw new ToolInputError(tool, [
20647
20754
  matches.length === 0 ? `${kind} id ${id} matches none of the ${kind}s on ${ownerName}; use the full id` : `${kind} id ${id} matches ${matches.length} ${kind}s on ${ownerName}; use the full id`
20648
20755
  ]);
@@ -21093,6 +21200,9 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
21093
21200
  if (tool === "dispatch_read" && typeof args.message === "string") {
21094
21201
  return { args, ref, owner: null };
21095
21202
  }
21203
+ if (tool === "dispatch_result" && typeof args["retract"] === "string") {
21204
+ return { args, ref, owner: null };
21205
+ }
21096
21206
  const legionIssue = env.LEGION_ISSUE;
21097
21207
  if (!legionIssue) {
21098
21208
  problems.push(ownerRequiredProblem);
@@ -21251,9 +21361,14 @@ function boundedEditDistance(a, b, limit) {
21251
21361
  return Math.min(previous[b.length], limit + 1);
21252
21362
  }
21253
21363
  var askHintLimit = 8;
21254
- function askIDInputProblem(asks, scope) {
21364
+ function openAskChoices(asks, owner) {
21365
+ if (asks.length === 0)
21366
+ return `${owner} holds no open ask.`;
21255
21367
  const hints = asks.slice(0, askHintLimit).map((ask) => `${ask.id.slice(0, 8)}\u2026 ${textHead(ask.question)}`);
21256
- return `ask IDs are UUIDs; use the full ask ID; ${scope} open asks: ${hints.length === 0 ? "none" : hints.join(", ")}`;
21368
+ return `The open asks of ${owner} are: ${hints.join(", ")}.`;
21369
+ }
21370
+ function askIDInputProblem(asks, owner) {
21371
+ return `ask ids are uuids. Write the whole id, or at least its first 8 characters. ${openAskChoices(asks, owner)}`;
21257
21372
  }
21258
21373
  async function movedApprovalLine(client, askID) {
21259
21374
  const ask = (await client.getAsk(askID).catch(() => {
@@ -21262,19 +21377,52 @@ async function movedApprovalLine(client, askID) {
21262
21377
  const approval = ask?.approval;
21263
21378
  if (ask?.kind !== "approval" || approval === undefined)
21264
21379
  return;
21265
- if (approval.requested_version >= approval.version)
21380
+ const listed = approval.documents ?? [];
21381
+ const documents = listed.length > 0 ? listed : [
21382
+ {
21383
+ name: approval.name,
21384
+ requested_version: approval.requested_version,
21385
+ version: approval.version
21386
+ }
21387
+ ];
21388
+ const moved = movedApprovalDocuments(documents);
21389
+ if (moved.length === 0)
21266
21390
  return;
21267
- const owner = ask.issue_key === null ? `--project ${ask.approval_artifact?.project ?? "<project>"} --artifact ${approval.artifact_id}` : ask.approval_artifact?.primary === true ? `--issue ${ask.issue_key}` : `--issue ${ask.issue_key} --artifact ${approval.artifact_id}`;
21268
- return `The reply did not hand the ask to the human: it is the approval request for ${approval.name} ` + `at version ${approval.requested_version}, and ${approval.name} is now version ${approval.version}. ` + "No reply hands a moved approval request back. Once the human has agreed to every point in " + `version ${approval.version}, run: dispatch request-approval ${owner} --summary ` + `'<what changed since version ${approval.requested_version}>'`;
21391
+ const firstMoved = moved[0];
21392
+ if (firstMoved === undefined)
21393
+ return;
21394
+ const command = handBackApprovalCommand({
21395
+ owner: ask.issue_key === null ? { kind: "project", key: ask.approval_artifact?.project ?? "<project>" } : { kind: "issue", key: ask.issue_key },
21396
+ artifactID: approval.artifact_id,
21397
+ primary: ask.approval_artifact?.primary === true,
21398
+ verification: documents.length > 1 && ask.approval_artifact?.primary === true,
21399
+ summaryVersion: firstMoved.requested_version
21400
+ });
21401
+ return "The reply did not hand the ask to the human: it is an open approval request, and " + `${movedApprovalClauses(moved)}. No reply hands a moved approval request back. Once the ` + `human has agreed to every point in it, run: ${command}`;
21269
21402
  }
21270
- async function invalidReplyToAskProblem(client, owner, resolved) {
21403
+ async function replyToAskCandidates(client, owner, resolved) {
21271
21404
  if (owner.kind === "issue") {
21272
21405
  const issue = resolved?.issue ?? await client.getIssue(owner.issue);
21273
- return askIDInputProblem(issue.open_asks ?? [], "this issue's");
21406
+ return { asks: issue.open_asks ?? [], owner: "this issue" };
21274
21407
  }
21275
21408
  if (resolved === undefined)
21276
21409
  throw new Error("project document is missing its resolved artifact");
21277
- return askIDInputProblem(await client.getArtifactAsks(resolved.artifact.id, "open"), "this document's");
21410
+ return {
21411
+ asks: await client.getArtifactAsks(resolved.artifact.id, "open"),
21412
+ owner: "this document"
21413
+ };
21414
+ }
21415
+ async function resolveReplyToAsk(tool, client, target, resolved, id) {
21416
+ const whole = normalizeUUID(id);
21417
+ if (whole !== undefined)
21418
+ return whole;
21419
+ const { asks, owner } = await replyToAskCandidates(client, target, resolved);
21420
+ if (!isIdPrefix(id)) {
21421
+ throw new ToolInputError(tool, [askIDInputProblem(asks, owner)], { aboutAFlag: false });
21422
+ }
21423
+ return resolveIdPrefix(tool, "ask", id, owner, async () => asks, {
21424
+ refusal: (found, all) => found.length === 0 ? `reply_to_ask ${id} names no open ask of ${owner}. ${openAskChoices(all, owner)}` : `reply_to_ask ${id} names ${found.length} open asks of ${owner}. Write more of the id. ${openAskChoices(all, owner)}`
21425
+ });
21278
21426
  }
21279
21427
  function anchor(artifact, args) {
21280
21428
  const quote = optionalString(args, "quote");
@@ -21314,6 +21462,89 @@ function approvalLine(artifact) {
21314
21462
  return `Approval: ${approval.state} on v${approval.version}${content}`;
21315
21463
  }
21316
21464
  }
21465
+ function artifactUnderName(artifacts, name) {
21466
+ const written = name.trim();
21467
+ return artifacts.find((held) => held.slug === written) ?? artifacts.find((held) => held.name === written);
21468
+ }
21469
+ function artifactNameExistsProblem(held, owner) {
21470
+ const versions = held.versions ?? [];
21471
+ const newest = versions[versions.length - 1];
21472
+ if (newest === undefined) {
21473
+ return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}), which has no version yet and which ${actorText(held.created_by)} created. ${ARTIFACT_NAME_EXISTS_RULE}`;
21474
+ }
21475
+ const authors = (newest.authors ?? []).map(actorText);
21476
+ const wroteIt = authors.length === 0 ? actorText(held.created_by) : authors.join(" and ");
21477
+ return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}) at version ${newest.number}, which ${wroteIt} wrote. ${ARTIFACT_NAME_EXISTS_RULE}`;
21478
+ }
21479
+ var STORED_LINE_QUOTED = 200;
21480
+ function quotedStoredLine(line) {
21481
+ if (line.length <= STORED_LINE_QUOTED)
21482
+ return JSON.stringify(line);
21483
+ const head = JSON.stringify(line.slice(0, STORED_LINE_QUOTED));
21484
+ return `${head} (cut after ${STORED_LINE_QUOTED} of its ${line.length} characters)`;
21485
+ }
21486
+ function firstStoredDifference(given, stored) {
21487
+ const written = given.split(`
21488
+ `);
21489
+ const holds = stored.split(`
21490
+ `);
21491
+ for (let line = 0;line < Math.max(written.length, holds.length); line += 1) {
21492
+ const wrote = written[line];
21493
+ const held = holds[line];
21494
+ if (wrote === held)
21495
+ continue;
21496
+ if (wrote === undefined && held !== undefined) {
21497
+ return `the store writes a line ${line + 1}, ${quotedStoredLine(held)}`;
21498
+ }
21499
+ if (held === undefined && wrote !== undefined) {
21500
+ return `the store drops line ${line + 1}, ${quotedStoredLine(wrote)}`;
21501
+ }
21502
+ if (wrote !== undefined && held !== undefined) {
21503
+ return `line ${line + 1} reads ${quotedStoredLine(wrote)} and is stored as ${quotedStoredLine(held)}`;
21504
+ }
21505
+ }
21506
+ return "the stored text differs from the text given";
21507
+ }
21508
+ var STORED_TEXT_PRINTED = 2000;
21509
+ function storedTextPrinted(stored) {
21510
+ if (stored.length <= STORED_TEXT_PRINTED)
21511
+ return { text: stored, cut: "" };
21512
+ const head = stored.slice(0, STORED_TEXT_PRINTED);
21513
+ const lastLineFeed = head.lastIndexOf(`
21514
+ `);
21515
+ const text = lastLineFeed === -1 ? head : head.slice(0, lastLineFeed + 1);
21516
+ return {
21517
+ text,
21518
+ cut: ` The text below is cut after ${text.length} of its ${stored.length} characters: change the line named above and send the text again.`
21519
+ };
21520
+ }
21521
+ function storedTextProblem(given, stored, name) {
21522
+ const asBytes = pathKeepsBytesOf(name) ? ` To keep the text as you wrote it, send it as a file with ${PATH_KEEPS_BYTES}.` : "";
21523
+ const printed = storedTextPrinted(stored);
21524
+ return [
21525
+ `Dispatch stores this text under another spelling: ${firstStoredDifference(given, stored)}.`,
21526
+ ` Send the text Dispatch stores, which is between the two marker lines below.${asBytes}`,
21527
+ `${printed.cut}
21528
+ --- the text Dispatch stores ---
21529
+ ${printed.text}`,
21530
+ "--- end of the text Dispatch stores ---"
21531
+ ].join("");
21532
+ }
21533
+ function storedTextCheckFailed(error, name) {
21534
+ const failure = `Dispatch could not say how it would store this text, so nothing was uploaded: POST /api/v1/markdown/round-trip failed with ${messageFor(error)}.`;
21535
+ if (!dispatchAnswered(error, 413)) {
21536
+ return `${failure} Send the upload again once that call is answered.`;
21537
+ }
21538
+ const asBytes = pathKeepsBytesOf(name) ? ` Send it as a file with ${PATH_KEEPS_BYTES}, which asks this check nothing.` : "";
21539
+ return `${failure} This text is longer than the check reads, and sending the upload again does not change that: a markdown document is at most 1 MiB, so shorten it or split it across documents of at most that.${asBytes}`;
21540
+ }
21541
+ function roundTripRouteAbsent(error) {
21542
+ return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
21543
+ }
21544
+ function withoutFinalLineFeed(text) {
21545
+ return text.endsWith(`
21546
+ `) ? text.slice(0, -1) : text;
21547
+ }
21317
21548
  function componentsLine(components) {
21318
21549
  const ids = components.ids ?? [];
21319
21550
  const unknown = components.unknown ?? [];
@@ -21407,7 +21638,96 @@ function progressText(progress, sep) {
21407
21638
  }
21408
21639
  return parts.join(sep);
21409
21640
  }
21410
- function formatCheckResults(results) {
21641
+ var BRIEF_READING_CHARACTERS = 200;
21642
+ var COMPARISON_REASONS = {
21643
+ no_pull_request_or_branch: "the issue has no pull request and no branch to compare with",
21644
+ repository_unreadable: "Dispatch cannot read the repository",
21645
+ read_failed: "a read Dispatch made did not answer"
21646
+ };
21647
+ function learnedText(learned) {
21648
+ if (learned.kind === "read_at")
21649
+ return `Dispatch read it ${learned.at}`;
21650
+ return `GitHub updated it ${learned.at}`;
21651
+ }
21652
+ function basisText(basis) {
21653
+ const learned = basis.learned_at === undefined ? "" : ` (${learnedText(basis.learned_at)})`;
21654
+ if (basis.kind === "pull_request") {
21655
+ const number = basis.pull_request === undefined ? "" : `#${basis.pull_request} `;
21656
+ return `the head of pull request ${number}at ${basis.commit ?? "an unnamed commit"}${learned}`;
21657
+ }
21658
+ if (basis.kind === "branch")
21659
+ return `branch ${basis.branch ?? "unnamed"}${learned}`;
21660
+ return `the commit you named, ${basis.commit ?? ""}${learned}`;
21661
+ }
21662
+ function basisPlace(basis) {
21663
+ if (basis.kind === "pull_request") {
21664
+ return basis.pull_request === undefined ? "the head of a pull request" : `the head of pull request #${basis.pull_request}`;
21665
+ }
21666
+ if (basis.kind === "branch")
21667
+ return `on branch ${basis.branch ?? "unnamed"}`;
21668
+ return "the commit you named";
21669
+ }
21670
+ function commitStandsText(stands) {
21671
+ if (stands === undefined) {
21672
+ return "Where that commit stands is not known: this Dispatch server does not say";
21673
+ }
21674
+ if (stands.answer === "at_basis") {
21675
+ return stands.basis === undefined ? "That commit is one of the compared commits" : `That commit is ${basisPlace(stands.basis)}`;
21676
+ }
21677
+ if (stands.answer === "other_commit")
21678
+ return "That commit is none of the compared commits";
21679
+ return stands.reason === undefined ? "Where that commit stands is not known" : `Where that commit stands is not known: ${COMPARISON_REASONS[stands.reason]}`;
21680
+ }
21681
+ function checkWordsText(check, result) {
21682
+ const versions = `result version ${result.check_version}, check version ${check.version}`;
21683
+ if (result.check_words_moved === undefined) {
21684
+ return `Whether the check's words moved is not known (${versions})`;
21685
+ }
21686
+ return result.check_words_moved ? `The check's words moved after this result (${versions})` : `The check's words did not move after this result (${versions})`;
21687
+ }
21688
+ function passStandsText(pass) {
21689
+ if (pass === undefined)
21690
+ return "Whether a pass stands is not known: this Dispatch server does not say";
21691
+ if (pass.answer === "yes") {
21692
+ const roles = pass.roles ?? [];
21693
+ return roles.length === 0 ? "A pass stands: yes" : `A pass stands: yes, from ${roles.join(", ")}`;
21694
+ }
21695
+ if (pass.answer === "no")
21696
+ return "A pass stands: no";
21697
+ return "A pass stands: not known";
21698
+ }
21699
+ function readingLines(result, brief) {
21700
+ const observed = result.observed;
21701
+ if (observed === "")
21702
+ return [" The role recorded no reading."];
21703
+ const cut = brief && result.commit_stands?.answer !== "at_basis";
21704
+ if (cut && observed.length > BRIEF_READING_CHARACTERS) {
21705
+ return [` Reading: ${observed.slice(0, BRIEF_READING_CHARACTERS)}\u2026 (result ${result.id})`];
21706
+ }
21707
+ return [` Reading: ${observed}`];
21708
+ }
21709
+ function resultLines(check, result, brief) {
21710
+ const lines = [
21711
+ ` - ${result.verdict} by ${result.role} at ${result.commit_sha}. ${commitStandsText(result.commit_stands)}. ${checkWordsText(check, result)}. Recorded ${result.created_at}. Result ${result.id}.`
21712
+ ];
21713
+ const retracted = result.retracted;
21714
+ if (retracted !== undefined) {
21715
+ lines.push(` Retracted by ${actorText(retracted.actor)} at ${retracted.created_at}. The reason: ${retracted.reason}`);
21716
+ }
21717
+ return [...lines, ...readingLines(result, brief)];
21718
+ }
21719
+ function checkLines(check, brief) {
21720
+ const bases = check.compared_with ?? [];
21721
+ const reason = check.compared_nothing;
21722
+ const compared = bases.length > 0 ? `Compared with ${bases.map(basisText).join(", ")}` : reason === undefined ? "Compared with nothing, and this Dispatch server does not say why" : `Compared with nothing: ${COMPARISON_REASONS[reason]}`;
21723
+ const results = check.results ?? [];
21724
+ return [
21725
+ `- ${check.block_id} (${check.when}). ${compared}. ${passStandsText(check.pass_stands)}.`,
21726
+ ` The check's words: ${check.text}`,
21727
+ ...results.length === 0 ? [" No result is recorded for this check."] : results.flatMap((result) => resultLines(check, result, brief))
21728
+ ];
21729
+ }
21730
+ function formatCheckResults(results, brief = false) {
21411
21731
  if (results.verification_artifact_id === "") {
21412
21732
  return `${results.issue} has no Verification document, so it has no checks. Write one (verification.md) with a check block per thing that must be proved.`;
21413
21733
  }
@@ -21415,15 +21735,10 @@ function formatCheckResults(results) {
21415
21735
  if (checks.length === 0) {
21416
21736
  return `${results.issue}'s Verification document holds no check blocks.`;
21417
21737
  }
21418
- const lines = checks.map((check) => {
21419
- const head = `- ${check.block_id} (${check.when}): `;
21420
- const latest = (check.results ?? [])[0];
21421
- if (latest === undefined) {
21422
- return `${head}no result yet. ${check.text}`;
21423
- }
21424
- return `${head}${latest.verdict} at ${latest.commit_sha} by ${latest.role}, ${latest.currency ?? "unknown"}. ${check.text}`;
21425
- });
21426
- return [`Checks of ${results.issue}:`, ...lines].join(`
21738
+ const blocks = checks.map((check) => checkLines(check, brief).join(`
21739
+ `));
21740
+ return [`Checks of ${results.issue}:`, ...blocks].join(`
21741
+
21427
21742
  `);
21428
21743
  }
21429
21744
  function repositoryLine(issue) {
@@ -22090,9 +22405,6 @@ ${text}`,
22090
22405
  var BLOCK_OPENING_CHARS = 60;
22091
22406
  async function listDocumentBlocks(client, artifact) {
22092
22407
  const live = await liveBlocks(client, artifact);
22093
- if (live === undefined) {
22094
- throw new Error(`${artifact.name} changed while dispatch doc-read --blocks read it, so the opening words could name the wrong text; nothing is listed. Run it again.`);
22095
- }
22096
22408
  const { bytes, blocks } = live;
22097
22409
  const decoder = new TextDecoder;
22098
22410
  const lines = [
@@ -22129,15 +22441,19 @@ async function listDocumentBlocks(client, artifact) {
22129
22441
  holders.push(block);
22130
22442
  }
22131
22443
  return { text: lines.join(`
22132
- `), token: live.token };
22444
+ `), token: live.token, version: live.version };
22133
22445
  }
22134
22446
  async function liveBlocks(client, artifact) {
22135
- const before = await client.docRead(artifact.id);
22136
- const blocks = await client.artifactBlocks(artifact.id);
22137
- const after = await client.docRead(artifact.id);
22138
- if (before.token !== after.token || before.markdown !== after.markdown)
22139
- return;
22140
- return { bytes: new TextEncoder().encode(before.markdown), token: before.token, blocks };
22447
+ const read = await client.docReadWithBlocks(artifact.id);
22448
+ if (read.blocks === undefined) {
22449
+ throw new Error(`${artifact.name} was read from a Dispatch older than this command: it serves a document's blocks only on their own route, not beside the text they index, so nothing was listed.`);
22450
+ }
22451
+ return {
22452
+ bytes: new TextEncoder().encode(read.markdown),
22453
+ token: read.token,
22454
+ version: read.version ?? null,
22455
+ blocks: read.blocks
22456
+ };
22141
22457
  }
22142
22458
  async function refuseOpenDecisionBlocks(client, tool, resolved) {
22143
22459
  const artifact = resolved.artifact;
@@ -22920,12 +23236,7 @@ async function executeDispatchTool(input) {
22920
23236
  const anchored = resolved ? anchor(resolved.artifact, args) : undefined;
22921
23237
  const replyTo = itemReplyTo(args, "reply_to");
22922
23238
  const replyToAskTarget = itemReplyTo(args, "reply_to_ask");
22923
- const replyToAsk = replyToAskTarget === undefined ? undefined : normalizeUUID(replyToAskTarget.id);
22924
- if (replyToAskTarget !== undefined && replyToAsk === undefined) {
22925
- throw new ToolInputError(input.tool, [
22926
- await invalidReplyToAskProblem(client, owner, resolved)
22927
- ]);
22928
- }
23239
+ const replyToAsk = replyToAskTarget === undefined ? undefined : await resolveReplyToAsk(input.tool, client, owner, resolved, replyToAskTarget.id);
22929
23240
  const replyToBlock = replyTo?.block ?? replyToAskTarget?.block;
22930
23241
  const requestedTurn = optionalString(args, "turn");
22931
23242
  const body = await writePictures(resolved, stringArg(args, "body"));
@@ -23146,10 +23457,15 @@ async function executeDispatchTool(input) {
23146
23457
  throw new Error(`${resolved.artifact.name} is an uploaded ${resolved.artifact.kind}, not a document, so it has no blocks. Read it with dispatch doc-read without --blocks.`);
23147
23458
  }
23148
23459
  const listed = await listDocumentBlocks(client, resolved.artifact);
23460
+ const trailer = [
23461
+ ...listed.token === undefined ? [] : [`Document token: ${listed.token}`],
23462
+ `Document version: ${listed.version === null ? "none yet" : listed.version}`
23463
+ ];
23149
23464
  return {
23150
- text: listed.token === undefined ? listed.text : `${listed.text}
23465
+ text: `${listed.text}
23151
23466
 
23152
- Document token: ${listed.token}`,
23467
+ ${trailer.join(`
23468
+ `)}`,
23153
23469
  details: resolved.owner.kind === "project" ? {
23154
23470
  project: resolved.artifact.project,
23155
23471
  document: documentLabel(resolved.artifact.project, resolved.artifact.slug)
@@ -23250,6 +23566,23 @@ Document token: ${listed.token}`,
23250
23566
  };
23251
23567
  }
23252
23568
  case "dispatch_result": {
23569
+ const retract = optionalString(args, "retract");
23570
+ if (retract !== undefined) {
23571
+ const retraction = await client.retractResult(retract, {
23572
+ actor,
23573
+ reason: stringArg(args, "reason")
23574
+ });
23575
+ return {
23576
+ text: `Retracted result ${retraction.result_id}. ${actorText(retraction.actor)} retracted it at ${retraction.created_at}. The reason: ${retraction.reason}
23577
+
23578
+ The result stays readable, and it proves nothing from now on. Record a new result where the check still needs one.`,
23579
+ details: {
23580
+ result: retraction.result_id,
23581
+ reason: retraction.reason,
23582
+ created_at: retraction.created_at
23583
+ }
23584
+ };
23585
+ }
23253
23586
  const issue = stringArg(args, "issue");
23254
23587
  const optional = {
23255
23588
  ...defined("surface", optionalString(args, "surface")),
@@ -23285,16 +23618,45 @@ ${recorded.line}`,
23285
23618
  }
23286
23619
  case "dispatch_results": {
23287
23620
  const issue = stringArg(args, "issue");
23288
- const results = await client.issueResults(issue);
23621
+ const at = optionalString(args, "at");
23622
+ const brief = optionalBoolean(args, "brief") === true;
23623
+ const results = await client.issueResults(issue, at);
23624
+ const checks = results.checks ?? [];
23289
23625
  return {
23290
- text: formatCheckResults(results),
23291
- details: { issue, checks: (results.checks ?? []).length }
23626
+ text: formatCheckResults(results, brief),
23627
+ details: {
23628
+ issue,
23629
+ checks: checks.length,
23630
+ results: checks.reduce((total, check) => total + (check.results ?? []).length, 0)
23631
+ }
23292
23632
  };
23293
23633
  }
23294
23634
  case "dispatch_artifact": {
23295
23635
  const summary = optionalString(args, "summary");
23296
23636
  const name = stringArg(args, "name");
23297
23637
  const content = optionalString(args, "content");
23638
+ const artifactOwner = documentOwner();
23639
+ if (optionalBoolean(args, "force") !== true) {
23640
+ const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
23641
+ if (held !== undefined) {
23642
+ throw new ToolInputError(input.tool, [
23643
+ artifactNameExistsProblem(held, artifactOwner.kind === "project" ? `project ${artifactOwner.project}` : `issue ${issue()}`)
23644
+ ]);
23645
+ }
23646
+ }
23647
+ if (content !== undefined) {
23648
+ let stored;
23649
+ try {
23650
+ stored = await client.markdownRoundTrip(content);
23651
+ } catch (error) {
23652
+ if (!roundTripRouteAbsent(error)) {
23653
+ throw new Error(storedTextCheckFailed(error, name), { cause: error });
23654
+ }
23655
+ }
23656
+ if (stored !== undefined && withoutFinalLineFeed(stored) !== withoutFinalLineFeed(content)) {
23657
+ throw new ToolInputError(input.tool, [storedTextProblem(content, stored, name)]);
23658
+ }
23659
+ }
23298
23660
  const artifactInput = content === undefined ? {
23299
23661
  name,
23300
23662
  file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd, stringArg(args, "path"))) : new Blob([new Uint8Array(input.uploadBytes)], {
@@ -23308,7 +23670,6 @@ ${recorded.line}`,
23308
23670
  ...summary === undefined ? {} : { summary },
23309
23671
  actor
23310
23672
  };
23311
- const artifactOwner = documentOwner();
23312
23673
  const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
23313
23674
  const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
23314
23675
  const uploadOwner = artifactOwner.kind === "project" ? documentTopic(result.artifact) : issueTopic(issue());