@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.
- package/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/dist/dispatch.js +420 -59
- package/dist/envoy-channel.js +421 -60
- package/dist/session-hook.js +420 -59
- package/dist/session-title-hook.js +10 -1
- package/legion/skills/legion-architect/SKILL.md +5 -5
- package/legion/skills/legion-architect/references/acceptance.md +5 -5
- package/legion/skills/legion-architect/references/design-gate.md +15 -6
- package/legion/skills/legion-architect/references/wake-routing.md +1 -1
- package/legion/skills/legion-retro/SKILL.md +4 -4
- package/legion/skills/legion-worker/SKILL.md +1 -1
- package/legion/skills/legion-worker/references/merge-gate.md +6 -5
- package/legion/skills/legion-worker/references/pr-body.md +18 -18
- package/package.json +1 -1
package/dist/dispatch.js
CHANGED
|
@@ -1005,8 +1005,17 @@ import {
|
|
|
1005
1005
|
import { isAbsolute, join, resolve } from "path";
|
|
1006
1006
|
|
|
1007
1007
|
// ../envoy-client/src/errors.ts
|
|
1008
|
+
function dispatchCode(error) {
|
|
1009
|
+
if (!("fromDispatch" in error) || !("code" in error))
|
|
1010
|
+
return;
|
|
1011
|
+
const code = error.code;
|
|
1012
|
+
return typeof code === "string" && code !== "" ? code : undefined;
|
|
1013
|
+
}
|
|
1008
1014
|
function messageFor(error) {
|
|
1009
|
-
|
|
1015
|
+
if (!(error instanceof Error))
|
|
1016
|
+
return String(error);
|
|
1017
|
+
const code = dispatchCode(error);
|
|
1018
|
+
return code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
|
|
1010
1019
|
}
|
|
1011
1020
|
function hasErrnoCode(error, code) {
|
|
1012
1021
|
return error instanceof Error && "code" in error && error.code === code;
|
|
@@ -15114,8 +15123,14 @@ function brokenParts(parts) {
|
|
|
15114
15123
|
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)";
|
|
15115
15124
|
var PATH_KEEPS_BYTES = "path (--path <file>), which stores a file whose path does not end in .md or .markdown as its bytes, unchanged";
|
|
15116
15125
|
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}.`;
|
|
15126
|
+
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.";
|
|
15127
|
+
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}.`;
|
|
15117
15128
|
var NAME_EXTENSION = /\.([^\s.]+)$/u;
|
|
15118
15129
|
var MARKDOWN_EXTENSION = /^(md|markdown)$/i;
|
|
15130
|
+
function pathKeepsBytesOf(name) {
|
|
15131
|
+
const extension = NAME_EXTENSION.exec(name.trim())?.[1];
|
|
15132
|
+
return extension === undefined || !MARKDOWN_EXTENSION.test(extension);
|
|
15133
|
+
}
|
|
15119
15134
|
var artifactOwner = documentOwnerValidation(false);
|
|
15120
15135
|
function artifactProblem(value) {
|
|
15121
15136
|
const input = value;
|
|
@@ -15257,6 +15272,42 @@ var handoffValidation = {
|
|
|
15257
15272
|
message: HANDOFF_RULE,
|
|
15258
15273
|
refusal: (value) => handoffProblem(value) ?? HANDOFF_RULE
|
|
15259
15274
|
};
|
|
15275
|
+
var RESULT_REQUIRED_FIELDS = ["issue", "check", "role", "verdict", "commit"];
|
|
15276
|
+
var RESULT_RECORD_FIELDS = [
|
|
15277
|
+
...RESULT_REQUIRED_FIELDS,
|
|
15278
|
+
"surface",
|
|
15279
|
+
"run",
|
|
15280
|
+
"observed",
|
|
15281
|
+
"negative_control",
|
|
15282
|
+
"failed",
|
|
15283
|
+
"skipped",
|
|
15284
|
+
"excluded",
|
|
15285
|
+
"screenshots"
|
|
15286
|
+
];
|
|
15287
|
+
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.";
|
|
15288
|
+
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.";
|
|
15289
|
+
function resultProblem(value) {
|
|
15290
|
+
const input = value;
|
|
15291
|
+
const carried = RESULT_RECORD_FIELDS.filter((field) => input[field] !== undefined);
|
|
15292
|
+
if (typeof input["retract"] === "string") {
|
|
15293
|
+
const reason = input["reason"];
|
|
15294
|
+
if (typeof reason !== "string" || reason.trim() === "") {
|
|
15295
|
+
return "retract needs reason, the words that say why the result is wrong.";
|
|
15296
|
+
}
|
|
15297
|
+
if (carried.length > 0) {
|
|
15298
|
+
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.`;
|
|
15299
|
+
}
|
|
15300
|
+
return;
|
|
15301
|
+
}
|
|
15302
|
+
if (input["reason"] !== undefined) {
|
|
15303
|
+
return "reason goes with retract, and this call carries no retract. Name the result to retract, or drop reason.";
|
|
15304
|
+
}
|
|
15305
|
+
const missing = RESULT_REQUIRED_FIELDS.filter((field) => input[field] === undefined);
|
|
15306
|
+
if (missing.length > 0) {
|
|
15307
|
+
return `recording a result needs ${missing.join(", ")}. ${RESULT_RETRACT_RULE}`;
|
|
15308
|
+
}
|
|
15309
|
+
return;
|
|
15310
|
+
}
|
|
15260
15311
|
var SEARCH_QUERY_MAX = 1000;
|
|
15261
15312
|
var SEARCH_QUERY_HINT = "search with a short phrase of a few words, not a passage";
|
|
15262
15313
|
var SEARCH_KIND_DEPTH = 100;
|
|
@@ -15610,13 +15661,13 @@ var dispatchToolSpecs = [
|
|
|
15610
15661
|
verdict: "pass",
|
|
15611
15662
|
commit: "1111111111111111111111111111111111111111"
|
|
15612
15663
|
},
|
|
15613
|
-
description: "Record one result of one check of an issue's Verification document,
|
|
15664
|
+
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,
|
|
15614
15665
|
arguments: (z) => ({
|
|
15615
|
-
issue: z.string().describe(ISSUE_REFERENCE),
|
|
15616
|
-
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."),
|
|
15617
|
-
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."),
|
|
15618
|
-
verdict: z.enum(["pass", "fail"]).describe("Whether the check passed."),
|
|
15619
|
-
commit: z.string().describe("The 40-character lowercase hex commit the check ran at."),
|
|
15666
|
+
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15667
|
+
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(),
|
|
15668
|
+
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(),
|
|
15669
|
+
verdict: z.enum(["pass", "fail"]).describe("Whether the check passed.").optional(),
|
|
15670
|
+
commit: z.string().describe("The 40-character lowercase hex commit the check ran at.").optional(),
|
|
15620
15671
|
surface: z.string().describe("Where a person reaches the change.").optional(),
|
|
15621
15672
|
run: z.string().describe("The command that proved it.").optional(),
|
|
15622
15673
|
observed: z.string().describe("What the command printed.").optional(),
|
|
@@ -15624,28 +15675,38 @@ var dispatchToolSpecs = [
|
|
|
15624
15675
|
failed: z.number({ int: true, min: 0 }).describe("Cases the run failed; 0 by default.").optional(),
|
|
15625
15676
|
skipped: z.number({ int: true, min: 0 }).describe("Cases the run skipped; 0 by default.").optional(),
|
|
15626
15677
|
excluded: z.number({ int: true, min: 0 }).describe("Cases the run excluded; 0 by default.").optional(),
|
|
15627
|
-
screenshots: z.array(z.string()).describe("dispatch:// references to image documents of this issue or of the check's issue.").optional()
|
|
15628
|
-
|
|
15678
|
+
screenshots: z.array(z.string()).describe("dispatch:// references to image documents of this issue or of the check's issue.").optional(),
|
|
15679
|
+
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(),
|
|
15680
|
+
reason: z.string().describe("Why the retracted result is wrong. It goes with retract and with nothing else.").optional()
|
|
15681
|
+
}),
|
|
15682
|
+
validation: {
|
|
15683
|
+
check: (value) => resultProblem(value) === undefined,
|
|
15684
|
+
message: RESULT_SHAPE_RULE,
|
|
15685
|
+
refusal: (value) => resultProblem(value) ?? RESULT_SHAPE_RULE
|
|
15686
|
+
}
|
|
15629
15687
|
},
|
|
15630
15688
|
{
|
|
15631
15689
|
name: "dispatch_results",
|
|
15632
15690
|
example: { issue: "DSP-1" },
|
|
15633
|
-
description: "Print each check of an issue's Verification document with
|
|
15691
|
+
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,
|
|
15634
15692
|
arguments: (z) => ({
|
|
15635
|
-
issue: z.string().describe(ISSUE_REFERENCE)
|
|
15693
|
+
issue: z.string().describe(ISSUE_REFERENCE),
|
|
15694
|
+
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(),
|
|
15695
|
+
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()
|
|
15636
15696
|
})
|
|
15637
15697
|
},
|
|
15638
15698
|
{
|
|
15639
15699
|
name: "dispatch_artifact",
|
|
15640
15700
|
example: { issue: "DSP-1", name: "design.md", content: `# Design
|
|
15641
15701
|
` },
|
|
15642
|
-
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.
|
|
15702
|
+
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}`,
|
|
15643
15703
|
arguments: (z) => ({
|
|
15644
15704
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15645
15705
|
project: z.string().describe("Project key for an unlinked document.").optional(),
|
|
15646
15706
|
name: z.string().describe("Artifact filename shown in Dispatch."),
|
|
15647
15707
|
path: z.string().describe("Local path to the file to upload.").optional(),
|
|
15648
|
-
content: z.string().describe("Inline text to store as a Markdown document, under a name ending in .md or .markdown or with no extension
|
|
15708
|
+
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(),
|
|
15709
|
+
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(),
|
|
15649
15710
|
summary: z.string().describe("Optional version summary.").optional()
|
|
15650
15711
|
}),
|
|
15651
15712
|
validation: {
|
|
@@ -18080,6 +18141,13 @@ class DispatchClient {
|
|
|
18080
18141
|
return answer;
|
|
18081
18142
|
throw new Error(`GET ${this.#url(path, query)} asked for the unpaged listing and got ${whyNotAnArray(answer)}.`);
|
|
18082
18143
|
}
|
|
18144
|
+
async listIssueArtifacts(issue) {
|
|
18145
|
+
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "artifacts"]);
|
|
18146
|
+
}
|
|
18147
|
+
async markdownRoundTrip(markdown) {
|
|
18148
|
+
const answer = await this.#json("POST", ["api", "v1", "markdown", "round-trip"], { markdown });
|
|
18149
|
+
return answer.markdown;
|
|
18150
|
+
}
|
|
18083
18151
|
async listProjectArtifacts(project, unlinked = false) {
|
|
18084
18152
|
return this.#json("GET", ["api", "v1", "projects", project, "artifacts"], undefined, unlinked ? { unlinked: "true" } : undefined);
|
|
18085
18153
|
}
|
|
@@ -18267,8 +18335,11 @@ class DispatchClient {
|
|
|
18267
18335
|
async recordResult(issue, input) {
|
|
18268
18336
|
return this.#json("POST", ["api", "v1", "issues", await this.#resolveIssue(issue), "results"], input);
|
|
18269
18337
|
}
|
|
18270
|
-
async issueResults(issue) {
|
|
18271
|
-
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "results"]);
|
|
18338
|
+
async issueResults(issue, at) {
|
|
18339
|
+
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "results"], undefined, at === undefined ? undefined : { at });
|
|
18340
|
+
}
|
|
18341
|
+
async retractResult(resultID, input) {
|
|
18342
|
+
return this.#json("POST", ["api", "v1", "results", resultID, "retract"], input);
|
|
18272
18343
|
}
|
|
18273
18344
|
async editAsk(id, input) {
|
|
18274
18345
|
return this.#json("PATCH", ["api", "v1", "asks", id], input);
|
|
@@ -18343,6 +18414,9 @@ class DispatchClient {
|
|
|
18343
18414
|
async docRead(id, version) {
|
|
18344
18415
|
return version === undefined ? this.#json("GET", ["api", "v1", "artifacts", id, "text"]) : this.#json("GET", ["api", "v1", "artifacts", id, "versions", String(version)]);
|
|
18345
18416
|
}
|
|
18417
|
+
async docReadWithBlocks(id) {
|
|
18418
|
+
return this.#json("GET", ["api", "v1", "artifacts", id, "text"], undefined, { blocks: true });
|
|
18419
|
+
}
|
|
18346
18420
|
async fileVersion(id, version) {
|
|
18347
18421
|
const url = this.#url(["api", "v1", "artifacts", id, "versions", String(version)]);
|
|
18348
18422
|
const response = await this.#send("GET", url, undefined, "*/*");
|
|
@@ -21128,11 +21202,11 @@ async function sessionAnswersSettled(session) {
|
|
|
21128
21202
|
class ToolInputError extends Error {
|
|
21129
21203
|
tool;
|
|
21130
21204
|
problems;
|
|
21131
|
-
constructor(tool, problems) {
|
|
21205
|
+
constructor(tool, problems, options) {
|
|
21132
21206
|
const count = problems.length;
|
|
21133
21207
|
const cli = isDispatchTool(tool);
|
|
21134
21208
|
const help = cli ? [
|
|
21135
|
-
`Allowed flags: ${commandFlags(tool).join(", ")}
|
|
21209
|
+
...options?.aboutAFlag === false ? [] : [`Allowed flags: ${commandFlags(tool).join(", ")}`],
|
|
21136
21210
|
`Example: ${commandLine(tool, exampleFor(tool))}`
|
|
21137
21211
|
] : [];
|
|
21138
21212
|
super([
|
|
@@ -21290,6 +21364,17 @@ var triageAdviceShown = new Set;
|
|
|
21290
21364
|
function adviceMemory() {
|
|
21291
21365
|
return triageAdviceShown;
|
|
21292
21366
|
}
|
|
21367
|
+
function handBackApprovalCommand(request) {
|
|
21368
|
+
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}`;
|
|
21369
|
+
const verification = request.owner.kind === "issue" && request.primary && request.verification ? " --include-verification" : "";
|
|
21370
|
+
return `dispatch request-approval ${owner}${verification} ` + `--summary '<what changed since version ${request.summaryVersion}>'`;
|
|
21371
|
+
}
|
|
21372
|
+
function movedApprovalClauses(documents) {
|
|
21373
|
+
return documents.map((document) => `${document.name} asked about version ${document.requested_version} and is now version ${document.version}`).join("; ");
|
|
21374
|
+
}
|
|
21375
|
+
function movedApprovalDocuments(documents) {
|
|
21376
|
+
return documents.filter((document) => document.requested_version < document.version);
|
|
21377
|
+
}
|
|
21293
21378
|
function renderAdvice(tool, key, advice, opts) {
|
|
21294
21379
|
if (advice === undefined)
|
|
21295
21380
|
return [];
|
|
@@ -21320,6 +21405,24 @@ function renderAdvice(tool, key, advice, opts) {
|
|
|
21320
21405
|
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".`);
|
|
21321
21406
|
}
|
|
21322
21407
|
}
|
|
21408
|
+
const movedApproval = advice.moved_approval_request;
|
|
21409
|
+
if (movedApproval !== undefined && (tool === "dispatch_doc_edit" || tool === "dispatch_artifact")) {
|
|
21410
|
+
const documents = movedApproval.documents ?? [];
|
|
21411
|
+
const moved = movedApprovalDocuments(documents);
|
|
21412
|
+
const movedOwner = movedApproval.issue !== undefined && movedApproval.issue !== "" ? { kind: "issue", key: movedApproval.issue } : movedApproval.project !== undefined && movedApproval.project !== "" ? { kind: "project", key: movedApproval.project } : undefined;
|
|
21413
|
+
const first = documents[0];
|
|
21414
|
+
const firstMoved = moved[0];
|
|
21415
|
+
if (moved.length > 0 && movedOwner !== undefined && first !== undefined && firstMoved !== undefined) {
|
|
21416
|
+
const command = handBackApprovalCommand({
|
|
21417
|
+
owner: movedOwner,
|
|
21418
|
+
artifactID: first.artifact_id,
|
|
21419
|
+
primary: first.primary,
|
|
21420
|
+
verification: documents.slice(1).some((document) => document.role === "verification"),
|
|
21421
|
+
summaryVersion: firstMoved.requested_version
|
|
21422
|
+
});
|
|
21423
|
+
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.`);
|
|
21424
|
+
}
|
|
21425
|
+
}
|
|
21323
21426
|
const superseded = advice.superseded_approval;
|
|
21324
21427
|
if (superseded !== undefined && (tool === "dispatch_doc_edit" || tool === "dispatch_artifact")) {
|
|
21325
21428
|
const gates = Array.isArray(superseded.design_gates) ? superseded.design_gates : [];
|
|
@@ -21626,7 +21729,7 @@ async function refuseItemOffRef(tool, kind, ref, refText, item, documentId) {
|
|
|
21626
21729
|
`${refText} names ${kind} ${item.id} on ${refOwnerName(ref)}, but it is on ${where}`
|
|
21627
21730
|
]);
|
|
21628
21731
|
}
|
|
21629
|
-
async function resolveIdPrefix(tool, kind, id, ownerName, list) {
|
|
21732
|
+
async function resolveIdPrefix(tool, kind, id, ownerName, list, candidates) {
|
|
21630
21733
|
const fullID = normalizeUUID(id);
|
|
21631
21734
|
if (fullID !== undefined)
|
|
21632
21735
|
return fullID;
|
|
@@ -21636,9 +21739,13 @@ async function resolveIdPrefix(tool, kind, id, ownerName, list) {
|
|
|
21636
21739
|
]);
|
|
21637
21740
|
}
|
|
21638
21741
|
const prefix = id.toLowerCase();
|
|
21639
|
-
const
|
|
21742
|
+
const all = await list();
|
|
21743
|
+
const matches = all.filter((item) => item.id.toLowerCase().startsWith(prefix));
|
|
21640
21744
|
if (matches.length === 1 && matches[0] !== undefined)
|
|
21641
21745
|
return matches[0].id;
|
|
21746
|
+
if (candidates !== undefined) {
|
|
21747
|
+
throw new ToolInputError(tool, [candidates.refusal(matches, all)], { aboutAFlag: false });
|
|
21748
|
+
}
|
|
21642
21749
|
throw new ToolInputError(tool, [
|
|
21643
21750
|
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`
|
|
21644
21751
|
]);
|
|
@@ -22089,6 +22196,9 @@ async function resolveOwnerArguments(tool, input, cwd, env, exec, dashboardUrls,
|
|
|
22089
22196
|
if (tool === "dispatch_read" && typeof args.message === "string") {
|
|
22090
22197
|
return { args, ref, owner: null };
|
|
22091
22198
|
}
|
|
22199
|
+
if (tool === "dispatch_result" && typeof args["retract"] === "string") {
|
|
22200
|
+
return { args, ref, owner: null };
|
|
22201
|
+
}
|
|
22092
22202
|
const legionIssue = env.LEGION_ISSUE;
|
|
22093
22203
|
if (!legionIssue) {
|
|
22094
22204
|
problems.push(ownerRequiredProblem);
|
|
@@ -22247,9 +22357,14 @@ function boundedEditDistance(a, b, limit) {
|
|
|
22247
22357
|
return Math.min(previous[b.length], limit + 1);
|
|
22248
22358
|
}
|
|
22249
22359
|
var askHintLimit = 8;
|
|
22250
|
-
function
|
|
22360
|
+
function openAskChoices(asks, owner) {
|
|
22361
|
+
if (asks.length === 0)
|
|
22362
|
+
return `${owner} holds no open ask.`;
|
|
22251
22363
|
const hints = asks.slice(0, askHintLimit).map((ask) => `${ask.id.slice(0, 8)}\u2026 ${textHead(ask.question)}`);
|
|
22252
|
-
return `
|
|
22364
|
+
return `The open asks of ${owner} are: ${hints.join(", ")}.`;
|
|
22365
|
+
}
|
|
22366
|
+
function askIDInputProblem(asks, owner) {
|
|
22367
|
+
return `ask ids are uuids. Write the whole id, or at least its first 8 characters. ${openAskChoices(asks, owner)}`;
|
|
22253
22368
|
}
|
|
22254
22369
|
async function movedApprovalLine(client, askID) {
|
|
22255
22370
|
const ask = (await client.getAsk(askID).catch(() => {
|
|
@@ -22258,19 +22373,52 @@ async function movedApprovalLine(client, askID) {
|
|
|
22258
22373
|
const approval = ask?.approval;
|
|
22259
22374
|
if (ask?.kind !== "approval" || approval === undefined)
|
|
22260
22375
|
return;
|
|
22261
|
-
|
|
22376
|
+
const listed = approval.documents ?? [];
|
|
22377
|
+
const documents = listed.length > 0 ? listed : [
|
|
22378
|
+
{
|
|
22379
|
+
name: approval.name,
|
|
22380
|
+
requested_version: approval.requested_version,
|
|
22381
|
+
version: approval.version
|
|
22382
|
+
}
|
|
22383
|
+
];
|
|
22384
|
+
const moved = movedApprovalDocuments(documents);
|
|
22385
|
+
if (moved.length === 0)
|
|
22262
22386
|
return;
|
|
22263
|
-
const
|
|
22264
|
-
|
|
22387
|
+
const firstMoved = moved[0];
|
|
22388
|
+
if (firstMoved === undefined)
|
|
22389
|
+
return;
|
|
22390
|
+
const command = handBackApprovalCommand({
|
|
22391
|
+
owner: ask.issue_key === null ? { kind: "project", key: ask.approval_artifact?.project ?? "<project>" } : { kind: "issue", key: ask.issue_key },
|
|
22392
|
+
artifactID: approval.artifact_id,
|
|
22393
|
+
primary: ask.approval_artifact?.primary === true,
|
|
22394
|
+
verification: documents.length > 1 && ask.approval_artifact?.primary === true,
|
|
22395
|
+
summaryVersion: firstMoved.requested_version
|
|
22396
|
+
});
|
|
22397
|
+
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}`;
|
|
22265
22398
|
}
|
|
22266
|
-
async function
|
|
22399
|
+
async function replyToAskCandidates(client, owner, resolved) {
|
|
22267
22400
|
if (owner.kind === "issue") {
|
|
22268
22401
|
const issue = resolved?.issue ?? await client.getIssue(owner.issue);
|
|
22269
|
-
return
|
|
22402
|
+
return { asks: issue.open_asks ?? [], owner: "this issue" };
|
|
22270
22403
|
}
|
|
22271
22404
|
if (resolved === undefined)
|
|
22272
22405
|
throw new Error("project document is missing its resolved artifact");
|
|
22273
|
-
return
|
|
22406
|
+
return {
|
|
22407
|
+
asks: await client.getArtifactAsks(resolved.artifact.id, "open"),
|
|
22408
|
+
owner: "this document"
|
|
22409
|
+
};
|
|
22410
|
+
}
|
|
22411
|
+
async function resolveReplyToAsk(tool, client, target, resolved, id) {
|
|
22412
|
+
const whole = normalizeUUID(id);
|
|
22413
|
+
if (whole !== undefined)
|
|
22414
|
+
return whole;
|
|
22415
|
+
const { asks, owner } = await replyToAskCandidates(client, target, resolved);
|
|
22416
|
+
if (!isIdPrefix(id)) {
|
|
22417
|
+
throw new ToolInputError(tool, [askIDInputProblem(asks, owner)], { aboutAFlag: false });
|
|
22418
|
+
}
|
|
22419
|
+
return resolveIdPrefix(tool, "ask", id, owner, async () => asks, {
|
|
22420
|
+
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)}`
|
|
22421
|
+
});
|
|
22274
22422
|
}
|
|
22275
22423
|
function anchor(artifact, args) {
|
|
22276
22424
|
const quote = optionalString(args, "quote");
|
|
@@ -22310,6 +22458,89 @@ function approvalLine(artifact) {
|
|
|
22310
22458
|
return `Approval: ${approval.state} on v${approval.version}${content}`;
|
|
22311
22459
|
}
|
|
22312
22460
|
}
|
|
22461
|
+
function artifactUnderName(artifacts, name) {
|
|
22462
|
+
const written = name.trim();
|
|
22463
|
+
return artifacts.find((held) => held.slug === written) ?? artifacts.find((held) => held.name === written);
|
|
22464
|
+
}
|
|
22465
|
+
function artifactNameExistsProblem(held, owner) {
|
|
22466
|
+
const versions = held.versions ?? [];
|
|
22467
|
+
const newest = versions[versions.length - 1];
|
|
22468
|
+
if (newest === undefined) {
|
|
22469
|
+
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}`;
|
|
22470
|
+
}
|
|
22471
|
+
const authors = (newest.authors ?? []).map(actorText);
|
|
22472
|
+
const wroteIt = authors.length === 0 ? actorText(held.created_by) : authors.join(" and ");
|
|
22473
|
+
return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}) at version ${newest.number}, which ${wroteIt} wrote. ${ARTIFACT_NAME_EXISTS_RULE}`;
|
|
22474
|
+
}
|
|
22475
|
+
var STORED_LINE_QUOTED = 200;
|
|
22476
|
+
function quotedStoredLine(line) {
|
|
22477
|
+
if (line.length <= STORED_LINE_QUOTED)
|
|
22478
|
+
return JSON.stringify(line);
|
|
22479
|
+
const head = JSON.stringify(line.slice(0, STORED_LINE_QUOTED));
|
|
22480
|
+
return `${head} (cut after ${STORED_LINE_QUOTED} of its ${line.length} characters)`;
|
|
22481
|
+
}
|
|
22482
|
+
function firstStoredDifference(given, stored) {
|
|
22483
|
+
const written = given.split(`
|
|
22484
|
+
`);
|
|
22485
|
+
const holds = stored.split(`
|
|
22486
|
+
`);
|
|
22487
|
+
for (let line = 0;line < Math.max(written.length, holds.length); line += 1) {
|
|
22488
|
+
const wrote = written[line];
|
|
22489
|
+
const held = holds[line];
|
|
22490
|
+
if (wrote === held)
|
|
22491
|
+
continue;
|
|
22492
|
+
if (wrote === undefined && held !== undefined) {
|
|
22493
|
+
return `the store writes a line ${line + 1}, ${quotedStoredLine(held)}`;
|
|
22494
|
+
}
|
|
22495
|
+
if (held === undefined && wrote !== undefined) {
|
|
22496
|
+
return `the store drops line ${line + 1}, ${quotedStoredLine(wrote)}`;
|
|
22497
|
+
}
|
|
22498
|
+
if (wrote !== undefined && held !== undefined) {
|
|
22499
|
+
return `line ${line + 1} reads ${quotedStoredLine(wrote)} and is stored as ${quotedStoredLine(held)}`;
|
|
22500
|
+
}
|
|
22501
|
+
}
|
|
22502
|
+
return "the stored text differs from the text given";
|
|
22503
|
+
}
|
|
22504
|
+
var STORED_TEXT_PRINTED = 2000;
|
|
22505
|
+
function storedTextPrinted(stored) {
|
|
22506
|
+
if (stored.length <= STORED_TEXT_PRINTED)
|
|
22507
|
+
return { text: stored, cut: "" };
|
|
22508
|
+
const head = stored.slice(0, STORED_TEXT_PRINTED);
|
|
22509
|
+
const lastLineFeed = head.lastIndexOf(`
|
|
22510
|
+
`);
|
|
22511
|
+
const text = lastLineFeed === -1 ? head : head.slice(0, lastLineFeed + 1);
|
|
22512
|
+
return {
|
|
22513
|
+
text,
|
|
22514
|
+
cut: ` The text below is cut after ${text.length} of its ${stored.length} characters: change the line named above and send the text again.`
|
|
22515
|
+
};
|
|
22516
|
+
}
|
|
22517
|
+
function storedTextProblem(given, stored, name) {
|
|
22518
|
+
const asBytes = pathKeepsBytesOf(name) ? ` To keep the text as you wrote it, send it as a file with ${PATH_KEEPS_BYTES}.` : "";
|
|
22519
|
+
const printed = storedTextPrinted(stored);
|
|
22520
|
+
return [
|
|
22521
|
+
`Dispatch stores this text under another spelling: ${firstStoredDifference(given, stored)}.`,
|
|
22522
|
+
` Send the text Dispatch stores, which is between the two marker lines below.${asBytes}`,
|
|
22523
|
+
`${printed.cut}
|
|
22524
|
+
--- the text Dispatch stores ---
|
|
22525
|
+
${printed.text}`,
|
|
22526
|
+
"--- end of the text Dispatch stores ---"
|
|
22527
|
+
].join("");
|
|
22528
|
+
}
|
|
22529
|
+
function storedTextCheckFailed(error, name) {
|
|
22530
|
+
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)}.`;
|
|
22531
|
+
if (!dispatchAnswered(error, 413)) {
|
|
22532
|
+
return `${failure} Send the upload again once that call is answered.`;
|
|
22533
|
+
}
|
|
22534
|
+
const asBytes = pathKeepsBytesOf(name) ? ` Send it as a file with ${PATH_KEEPS_BYTES}, which asks this check nothing.` : "";
|
|
22535
|
+
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}`;
|
|
22536
|
+
}
|
|
22537
|
+
function roundTripRouteAbsent(error) {
|
|
22538
|
+
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
22539
|
+
}
|
|
22540
|
+
function withoutFinalLineFeed(text) {
|
|
22541
|
+
return text.endsWith(`
|
|
22542
|
+
`) ? text.slice(0, -1) : text;
|
|
22543
|
+
}
|
|
22313
22544
|
function componentsLine(components) {
|
|
22314
22545
|
const ids = components.ids ?? [];
|
|
22315
22546
|
const unknown = components.unknown ?? [];
|
|
@@ -22403,7 +22634,96 @@ function progressText(progress, sep) {
|
|
|
22403
22634
|
}
|
|
22404
22635
|
return parts.join(sep);
|
|
22405
22636
|
}
|
|
22406
|
-
|
|
22637
|
+
var BRIEF_READING_CHARACTERS = 200;
|
|
22638
|
+
var COMPARISON_REASONS = {
|
|
22639
|
+
no_pull_request_or_branch: "the issue has no pull request and no branch to compare with",
|
|
22640
|
+
repository_unreadable: "Dispatch cannot read the repository",
|
|
22641
|
+
read_failed: "a read Dispatch made did not answer"
|
|
22642
|
+
};
|
|
22643
|
+
function learnedText(learned) {
|
|
22644
|
+
if (learned.kind === "read_at")
|
|
22645
|
+
return `Dispatch read it ${learned.at}`;
|
|
22646
|
+
return `GitHub updated it ${learned.at}`;
|
|
22647
|
+
}
|
|
22648
|
+
function basisText(basis) {
|
|
22649
|
+
const learned = basis.learned_at === undefined ? "" : ` (${learnedText(basis.learned_at)})`;
|
|
22650
|
+
if (basis.kind === "pull_request") {
|
|
22651
|
+
const number = basis.pull_request === undefined ? "" : `#${basis.pull_request} `;
|
|
22652
|
+
return `the head of pull request ${number}at ${basis.commit ?? "an unnamed commit"}${learned}`;
|
|
22653
|
+
}
|
|
22654
|
+
if (basis.kind === "branch")
|
|
22655
|
+
return `branch ${basis.branch ?? "unnamed"}${learned}`;
|
|
22656
|
+
return `the commit you named, ${basis.commit ?? ""}${learned}`;
|
|
22657
|
+
}
|
|
22658
|
+
function basisPlace(basis) {
|
|
22659
|
+
if (basis.kind === "pull_request") {
|
|
22660
|
+
return basis.pull_request === undefined ? "the head of a pull request" : `the head of pull request #${basis.pull_request}`;
|
|
22661
|
+
}
|
|
22662
|
+
if (basis.kind === "branch")
|
|
22663
|
+
return `on branch ${basis.branch ?? "unnamed"}`;
|
|
22664
|
+
return "the commit you named";
|
|
22665
|
+
}
|
|
22666
|
+
function commitStandsText(stands) {
|
|
22667
|
+
if (stands === undefined) {
|
|
22668
|
+
return "Where that commit stands is not known: this Dispatch server does not say";
|
|
22669
|
+
}
|
|
22670
|
+
if (stands.answer === "at_basis") {
|
|
22671
|
+
return stands.basis === undefined ? "That commit is one of the compared commits" : `That commit is ${basisPlace(stands.basis)}`;
|
|
22672
|
+
}
|
|
22673
|
+
if (stands.answer === "other_commit")
|
|
22674
|
+
return "That commit is none of the compared commits";
|
|
22675
|
+
return stands.reason === undefined ? "Where that commit stands is not known" : `Where that commit stands is not known: ${COMPARISON_REASONS[stands.reason]}`;
|
|
22676
|
+
}
|
|
22677
|
+
function checkWordsText(check, result) {
|
|
22678
|
+
const versions = `result version ${result.check_version}, check version ${check.version}`;
|
|
22679
|
+
if (result.check_words_moved === undefined) {
|
|
22680
|
+
return `Whether the check's words moved is not known (${versions})`;
|
|
22681
|
+
}
|
|
22682
|
+
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})`;
|
|
22683
|
+
}
|
|
22684
|
+
function passStandsText(pass) {
|
|
22685
|
+
if (pass === undefined)
|
|
22686
|
+
return "Whether a pass stands is not known: this Dispatch server does not say";
|
|
22687
|
+
if (pass.answer === "yes") {
|
|
22688
|
+
const roles = pass.roles ?? [];
|
|
22689
|
+
return roles.length === 0 ? "A pass stands: yes" : `A pass stands: yes, from ${roles.join(", ")}`;
|
|
22690
|
+
}
|
|
22691
|
+
if (pass.answer === "no")
|
|
22692
|
+
return "A pass stands: no";
|
|
22693
|
+
return "A pass stands: not known";
|
|
22694
|
+
}
|
|
22695
|
+
function readingLines(result, brief) {
|
|
22696
|
+
const observed = result.observed;
|
|
22697
|
+
if (observed === "")
|
|
22698
|
+
return [" The role recorded no reading."];
|
|
22699
|
+
const cut = brief && result.commit_stands?.answer !== "at_basis";
|
|
22700
|
+
if (cut && observed.length > BRIEF_READING_CHARACTERS) {
|
|
22701
|
+
return [` Reading: ${observed.slice(0, BRIEF_READING_CHARACTERS)}\u2026 (result ${result.id})`];
|
|
22702
|
+
}
|
|
22703
|
+
return [` Reading: ${observed}`];
|
|
22704
|
+
}
|
|
22705
|
+
function resultLines(check, result, brief) {
|
|
22706
|
+
const lines = [
|
|
22707
|
+
` - ${result.verdict} by ${result.role} at ${result.commit_sha}. ${commitStandsText(result.commit_stands)}. ${checkWordsText(check, result)}. Recorded ${result.created_at}. Result ${result.id}.`
|
|
22708
|
+
];
|
|
22709
|
+
const retracted = result.retracted;
|
|
22710
|
+
if (retracted !== undefined) {
|
|
22711
|
+
lines.push(` Retracted by ${actorText(retracted.actor)} at ${retracted.created_at}. The reason: ${retracted.reason}`);
|
|
22712
|
+
}
|
|
22713
|
+
return [...lines, ...readingLines(result, brief)];
|
|
22714
|
+
}
|
|
22715
|
+
function checkLines(check, brief) {
|
|
22716
|
+
const bases = check.compared_with ?? [];
|
|
22717
|
+
const reason = check.compared_nothing;
|
|
22718
|
+
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]}`;
|
|
22719
|
+
const results = check.results ?? [];
|
|
22720
|
+
return [
|
|
22721
|
+
`- ${check.block_id} (${check.when}). ${compared}. ${passStandsText(check.pass_stands)}.`,
|
|
22722
|
+
` The check's words: ${check.text}`,
|
|
22723
|
+
...results.length === 0 ? [" No result is recorded for this check."] : results.flatMap((result) => resultLines(check, result, brief))
|
|
22724
|
+
];
|
|
22725
|
+
}
|
|
22726
|
+
function formatCheckResults(results, brief = false) {
|
|
22407
22727
|
if (results.verification_artifact_id === "") {
|
|
22408
22728
|
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.`;
|
|
22409
22729
|
}
|
|
@@ -22411,15 +22731,10 @@ function formatCheckResults(results) {
|
|
|
22411
22731
|
if (checks.length === 0) {
|
|
22412
22732
|
return `${results.issue}'s Verification document holds no check blocks.`;
|
|
22413
22733
|
}
|
|
22414
|
-
const
|
|
22415
|
-
|
|
22416
|
-
|
|
22417
|
-
|
|
22418
|
-
return `${head}no result yet. ${check.text}`;
|
|
22419
|
-
}
|
|
22420
|
-
return `${head}${latest.verdict} at ${latest.commit_sha} by ${latest.role}, ${latest.currency ?? "unknown"}. ${check.text}`;
|
|
22421
|
-
});
|
|
22422
|
-
return [`Checks of ${results.issue}:`, ...lines].join(`
|
|
22734
|
+
const blocks = checks.map((check) => checkLines(check, brief).join(`
|
|
22735
|
+
`));
|
|
22736
|
+
return [`Checks of ${results.issue}:`, ...blocks].join(`
|
|
22737
|
+
|
|
22423
22738
|
`);
|
|
22424
22739
|
}
|
|
22425
22740
|
function repositoryLine(issue) {
|
|
@@ -23086,9 +23401,6 @@ ${text}`,
|
|
|
23086
23401
|
var BLOCK_OPENING_CHARS = 60;
|
|
23087
23402
|
async function listDocumentBlocks(client, artifact) {
|
|
23088
23403
|
const live = await liveBlocks(client, artifact);
|
|
23089
|
-
if (live === undefined) {
|
|
23090
|
-
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.`);
|
|
23091
|
-
}
|
|
23092
23404
|
const { bytes, blocks } = live;
|
|
23093
23405
|
const decoder = new TextDecoder;
|
|
23094
23406
|
const lines = [
|
|
@@ -23125,15 +23437,19 @@ async function listDocumentBlocks(client, artifact) {
|
|
|
23125
23437
|
holders.push(block);
|
|
23126
23438
|
}
|
|
23127
23439
|
return { text: lines.join(`
|
|
23128
|
-
`), token: live.token };
|
|
23440
|
+
`), token: live.token, version: live.version };
|
|
23129
23441
|
}
|
|
23130
23442
|
async function liveBlocks(client, artifact) {
|
|
23131
|
-
const
|
|
23132
|
-
|
|
23133
|
-
|
|
23134
|
-
|
|
23135
|
-
|
|
23136
|
-
|
|
23443
|
+
const read = await client.docReadWithBlocks(artifact.id);
|
|
23444
|
+
if (read.blocks === undefined) {
|
|
23445
|
+
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.`);
|
|
23446
|
+
}
|
|
23447
|
+
return {
|
|
23448
|
+
bytes: new TextEncoder().encode(read.markdown),
|
|
23449
|
+
token: read.token,
|
|
23450
|
+
version: read.version ?? null,
|
|
23451
|
+
blocks: read.blocks
|
|
23452
|
+
};
|
|
23137
23453
|
}
|
|
23138
23454
|
async function refuseOpenDecisionBlocks(client, tool, resolved) {
|
|
23139
23455
|
const artifact = resolved.artifact;
|
|
@@ -23916,12 +24232,7 @@ async function executeDispatchTool(input) {
|
|
|
23916
24232
|
const anchored = resolved ? anchor(resolved.artifact, args) : undefined;
|
|
23917
24233
|
const replyTo = itemReplyTo(args, "reply_to");
|
|
23918
24234
|
const replyToAskTarget = itemReplyTo(args, "reply_to_ask");
|
|
23919
|
-
const replyToAsk = replyToAskTarget === undefined ? undefined :
|
|
23920
|
-
if (replyToAskTarget !== undefined && replyToAsk === undefined) {
|
|
23921
|
-
throw new ToolInputError(input.tool, [
|
|
23922
|
-
await invalidReplyToAskProblem(client, owner, resolved)
|
|
23923
|
-
]);
|
|
23924
|
-
}
|
|
24235
|
+
const replyToAsk = replyToAskTarget === undefined ? undefined : await resolveReplyToAsk(input.tool, client, owner, resolved, replyToAskTarget.id);
|
|
23925
24236
|
const replyToBlock = replyTo?.block ?? replyToAskTarget?.block;
|
|
23926
24237
|
const requestedTurn = optionalString(args, "turn");
|
|
23927
24238
|
const body = await writePictures(resolved, stringArg(args, "body"));
|
|
@@ -24142,10 +24453,15 @@ async function executeDispatchTool(input) {
|
|
|
24142
24453
|
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.`);
|
|
24143
24454
|
}
|
|
24144
24455
|
const listed = await listDocumentBlocks(client, resolved.artifact);
|
|
24456
|
+
const trailer = [
|
|
24457
|
+
...listed.token === undefined ? [] : [`Document token: ${listed.token}`],
|
|
24458
|
+
`Document version: ${listed.version === null ? "none yet" : listed.version}`
|
|
24459
|
+
];
|
|
24145
24460
|
return {
|
|
24146
|
-
text:
|
|
24461
|
+
text: `${listed.text}
|
|
24147
24462
|
|
|
24148
|
-
|
|
24463
|
+
${trailer.join(`
|
|
24464
|
+
`)}`,
|
|
24149
24465
|
details: resolved.owner.kind === "project" ? {
|
|
24150
24466
|
project: resolved.artifact.project,
|
|
24151
24467
|
document: documentLabel(resolved.artifact.project, resolved.artifact.slug)
|
|
@@ -24246,6 +24562,23 @@ Document token: ${listed.token}`,
|
|
|
24246
24562
|
};
|
|
24247
24563
|
}
|
|
24248
24564
|
case "dispatch_result": {
|
|
24565
|
+
const retract = optionalString(args, "retract");
|
|
24566
|
+
if (retract !== undefined) {
|
|
24567
|
+
const retraction = await client.retractResult(retract, {
|
|
24568
|
+
actor,
|
|
24569
|
+
reason: stringArg(args, "reason")
|
|
24570
|
+
});
|
|
24571
|
+
return {
|
|
24572
|
+
text: `Retracted result ${retraction.result_id}. ${actorText(retraction.actor)} retracted it at ${retraction.created_at}. The reason: ${retraction.reason}
|
|
24573
|
+
|
|
24574
|
+
The result stays readable, and it proves nothing from now on. Record a new result where the check still needs one.`,
|
|
24575
|
+
details: {
|
|
24576
|
+
result: retraction.result_id,
|
|
24577
|
+
reason: retraction.reason,
|
|
24578
|
+
created_at: retraction.created_at
|
|
24579
|
+
}
|
|
24580
|
+
};
|
|
24581
|
+
}
|
|
24249
24582
|
const issue = stringArg(args, "issue");
|
|
24250
24583
|
const optional = {
|
|
24251
24584
|
...defined("surface", optionalString(args, "surface")),
|
|
@@ -24281,16 +24614,45 @@ ${recorded.line}`,
|
|
|
24281
24614
|
}
|
|
24282
24615
|
case "dispatch_results": {
|
|
24283
24616
|
const issue = stringArg(args, "issue");
|
|
24284
|
-
const
|
|
24617
|
+
const at = optionalString(args, "at");
|
|
24618
|
+
const brief = optionalBoolean(args, "brief") === true;
|
|
24619
|
+
const results = await client.issueResults(issue, at);
|
|
24620
|
+
const checks = results.checks ?? [];
|
|
24285
24621
|
return {
|
|
24286
|
-
text: formatCheckResults(results),
|
|
24287
|
-
details: {
|
|
24622
|
+
text: formatCheckResults(results, brief),
|
|
24623
|
+
details: {
|
|
24624
|
+
issue,
|
|
24625
|
+
checks: checks.length,
|
|
24626
|
+
results: checks.reduce((total, check) => total + (check.results ?? []).length, 0)
|
|
24627
|
+
}
|
|
24288
24628
|
};
|
|
24289
24629
|
}
|
|
24290
24630
|
case "dispatch_artifact": {
|
|
24291
24631
|
const summary = optionalString(args, "summary");
|
|
24292
24632
|
const name = stringArg(args, "name");
|
|
24293
24633
|
const content = optionalString(args, "content");
|
|
24634
|
+
const artifactOwner = documentOwner();
|
|
24635
|
+
if (optionalBoolean(args, "force") !== true) {
|
|
24636
|
+
const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
|
|
24637
|
+
if (held !== undefined) {
|
|
24638
|
+
throw new ToolInputError(input.tool, [
|
|
24639
|
+
artifactNameExistsProblem(held, artifactOwner.kind === "project" ? `project ${artifactOwner.project}` : `issue ${issue()}`)
|
|
24640
|
+
]);
|
|
24641
|
+
}
|
|
24642
|
+
}
|
|
24643
|
+
if (content !== undefined) {
|
|
24644
|
+
let stored;
|
|
24645
|
+
try {
|
|
24646
|
+
stored = await client.markdownRoundTrip(content);
|
|
24647
|
+
} catch (error) {
|
|
24648
|
+
if (!roundTripRouteAbsent(error)) {
|
|
24649
|
+
throw new Error(storedTextCheckFailed(error, name), { cause: error });
|
|
24650
|
+
}
|
|
24651
|
+
}
|
|
24652
|
+
if (stored !== undefined && withoutFinalLineFeed(stored) !== withoutFinalLineFeed(content)) {
|
|
24653
|
+
throw new ToolInputError(input.tool, [storedTextProblem(content, stored, name)]);
|
|
24654
|
+
}
|
|
24655
|
+
}
|
|
24294
24656
|
const artifactInput = content === undefined ? {
|
|
24295
24657
|
name,
|
|
24296
24658
|
file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd, stringArg(args, "path"))) : new Blob([new Uint8Array(input.uploadBytes)], {
|
|
@@ -24304,7 +24666,6 @@ ${recorded.line}`,
|
|
|
24304
24666
|
...summary === undefined ? {} : { summary },
|
|
24305
24667
|
actor
|
|
24306
24668
|
};
|
|
24307
|
-
const artifactOwner = documentOwner();
|
|
24308
24669
|
const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
|
|
24309
24670
|
const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
|
|
24310
24671
|
const uploadOwner = artifactOwner.kind === "project" ? documentTopic(result.artifact) : issueTopic(issue());
|