@sjawhar/claude-envoy 6.2.0 → 6.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/dist/codex-hook.js +394 -92
- package/dist/dispatch.js +721 -364
- package/dist/envoy-channel.js +406 -102
- package/dist/session-hook.js +390 -88
- package/package.json +2 -2
package/dist/dispatch.js
CHANGED
|
@@ -979,11 +979,8 @@ __export(exports_coerce, {
|
|
|
979
979
|
string: () => string3
|
|
980
980
|
});
|
|
981
981
|
|
|
982
|
-
// ../envoy-client/bin/dispatch.ts
|
|
983
|
-
import { readFileSync as readFileSync7 } from "fs";
|
|
984
|
-
|
|
985
982
|
// ../envoy-client/src/dispatch-cli.ts
|
|
986
|
-
import { closeSync as closeSync4, constants as constants4, fstatSync as fstatSync3, openSync as openSync4, readFileSync as
|
|
983
|
+
import { closeSync as closeSync4, constants as constants4, fstatSync as fstatSync3, openSync as openSync4, readFileSync as readFileSync7 } from "fs";
|
|
987
984
|
|
|
988
985
|
// ../envoy-client/src/askgate-marker.ts
|
|
989
986
|
import { createHash, randomBytes } from "crypto";
|
|
@@ -14205,6 +14202,14 @@ var wholeIdPattern = /^(?:[0-9a-f]{32}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a
|
|
|
14205
14202
|
function isIdPrefix(value) {
|
|
14206
14203
|
return idPrefixPattern.test(value) && !wholeIdPattern.test(value);
|
|
14207
14204
|
}
|
|
14205
|
+
function utf8Bytes(value) {
|
|
14206
|
+
let bytes = 0;
|
|
14207
|
+
for (const character of value) {
|
|
14208
|
+
const code = character.codePointAt(0) ?? 0;
|
|
14209
|
+
bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
|
|
14210
|
+
}
|
|
14211
|
+
return bytes;
|
|
14212
|
+
}
|
|
14208
14213
|
var PLAIN_ISSUE_TABS = [
|
|
14209
14214
|
"verification",
|
|
14210
14215
|
"plan",
|
|
@@ -14467,6 +14472,9 @@ var ISSUE_LABEL_MAX = 40;
|
|
|
14467
14472
|
var MAX_ISSUE_COMPONENTS = 50;
|
|
14468
14473
|
var ISSUE_TITLE_MAX = 1000;
|
|
14469
14474
|
var PROJECT_NAME_MAX = 80;
|
|
14475
|
+
var MARKDOWN_DOCUMENT_MAX_BYTES = 1 << 20;
|
|
14476
|
+
var MARKDOWN_DOCUMENT_TOO_LARGE = `a markdown document is at most ${MARKDOWN_DOCUMENT_MAX_BYTES / (1 << 20)} MiB; a larger file is stored as a binary artifact under another content type`;
|
|
14477
|
+
var TEXT_REFUSAL_HEADER = "Dispatch-Text-Refusal";
|
|
14470
14478
|
var MAX_ISSUE_PAGE_LIMIT = 250;
|
|
14471
14479
|
var DEFAULT_ISSUE_PAGE_LIMIT = 50;
|
|
14472
14480
|
var DEFAULT_ISSUE_READ_EVENTS = 10;
|
|
@@ -14763,6 +14771,7 @@ function artifactKindConflictRule(held, upload) {
|
|
|
14763
14771
|
return `This upload is a ${artifactKindWord(upload)}, and the name holds a ${artifactKindWord(held)}: Dispatch keeps one kind under one name, so this upload cannot be its next version, with force or without. Give the upload another name.`;
|
|
14764
14772
|
}
|
|
14765
14773
|
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. A typed block whose attributes differ from Dispatch's only in their order is not refused: the command uploads it with them in Dispatch's order and names each such block. A refusal names the first difference: a changed line by the attribute or the word that differs, a word of more than 200 characters by a window from its first character that differs, and a line the store adds or drops by a quote cut at 200 characters, each cut named. 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}.`;
|
|
14774
|
+
var ARTIFACT_DOCUMENT_BYTES_ORDER = `in the order its upload refuses a Markdown file in: past ${MARKDOWN_DOCUMENT_MAX_BYTES / (1 << 20)} MiB with CAP_EXCEEDED, and otherwise at the first NUL character or byte that is not UTF-8, with NUL_CHARACTER or INVALID_UTF8, Dispatch's own refusal of it, naming the field (content, or file for path), the character and where it stands.`;
|
|
14766
14775
|
var NAME_EXTENSION = /\.([^\s.]+)$/u;
|
|
14767
14776
|
var MARKDOWN_EXTENSION = /^(md|markdown)$/i;
|
|
14768
14777
|
function preconditionArgument(z) {
|
|
@@ -15550,6 +15559,7 @@ var dispatchToolSpecs = [
|
|
|
15550
15559
|
},
|
|
15551
15560
|
{
|
|
15552
15561
|
name: "dispatch_result",
|
|
15562
|
+
dryRunHelp: "Checks the arguments as the call would and prints them as JSON. A record's dry run then asks Dispatch for the pull-request body line the record would print, and prints it; Dispatch records nothing. A retraction's dry run sends nothing.",
|
|
15553
15563
|
example: {
|
|
15554
15564
|
issue: "DSP-1",
|
|
15555
15565
|
check: "k1",
|
|
@@ -15595,14 +15605,15 @@ var dispatchToolSpecs = [
|
|
|
15595
15605
|
name: "dispatch_artifact",
|
|
15596
15606
|
example: { issue: "DSP-1", name: "design.md", content: `# Design
|
|
15597
15607
|
` },
|
|
15598
|
-
|
|
15608
|
+
dryRunHelp: `Before it asks Dispatch anything, and with Dispatch off too, it refuses with exit 1 a text past ${MARKDOWN_DOCUMENT_MAX_BYTES / (1 << 20)} MiB, or holding a NUL character or a byte that is not UTF-8, whether it is read from --content-file, from stdin (--content-file -) or from a --path file ending in .md or .markdown, a file Dispatch stores as a Markdown document, ${ARTIFACT_DOCUMENT_BYTES_ORDER} It refuses such a text once the flags are read, before it checks the arguments as the call would and before anything that needs Dispatch, as the call does. Then, for text given inline, read from --content-file or from stdin, it asks Dispatch how it would store the text (POST /api/v1/markdown/round-trip), and refuses, with the call's own refusal and exit code, a text that Dispatch would store under another spelling, but for typed blocks' attributes in another order, which the call uploads in Dispatch's order, or that the call refuses for the text alone: one past ${MARKDOWN_DOCUMENT_MAX_BYTES / (1 << 20)} MiB of UTF-8, which it refuses without asking, or one Dispatch refuses as its upload would, such as one making more elements than one write may, or holding markdown the parser refuses. For a Markdown --path file, it then sends Dispatch the file's bytes (POST /api/v1/markdown/file-round-trip), as the call does before it uploads them, and refuses, with the call's own refusal and exit code, what Dispatch refuses of them as their upload would, but never their spelling. Without force it also refuses what Dispatch refuses only of a new document, such as an ask block that breaks its content rule, a block id written twice, a check proved by CI that breaks its rules, or a rendering past the bytes one document holds; with force (--force), which may replace a document Dispatch judges by looser rules, it asks for none of those and checks the spelling Dispatch answers as for any text, so it passes with no warning a text the call can then refuse for one of those: under a name the owner does not hold, because the call uploads a new document; under a name the owner holds, because a replacement holds those rules for the blocks it adds or changes, and refuses a rendering that grows past the bytes one document holds over the version it replaces. It does not read whether the owner holds the name, which the call reads only after it checks the text: a text this check refuses is refused alike under a held name, and a text it passes the call without force still refuses under a held name, though the dry run passes it. Otherwise it prints the arguments as JSON. It stores nothing. For any other text but an empty one given inline, read from --content-file or from stdin, which it asks Dispatch nothing about and passes with no warning, when Dispatch cannot answer, or cannot check the text or the file, it says so on stderr and passes.`,
|
|
15609
|
+
description: "Attach a local file or inline text as an issue artifact or project document, or make an empty document from its name alone. 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. " + `${ARTIFACT_SOURCE_RULE} ` + `${ARTIFACT_NAME_EXISTS_RULE} A call that stores nothing - no path, and content absent or blank - is refused under a held name even with force and a token, so a title typed twice never empties the document that holds it; that refusal names no token, since no token makes such a call one Dispatch takes. ` + `A markdown document is at most ${MARKDOWN_DOCUMENT_MAX_BYTES / (1 << 20)} MiB and any other file at most 25 MiB. ` + "An upload that replaces a document the owner already holds under that name says which version it replaces: precondition.document takes the document token dispatch doc-read prints as `Document token: sha256:\u2026`, and Dispatch checks it under the write's own lock. An upload that names none is taken for now without a check, since older dispatch commands cannot name one; name the token wherever the command can, because a later release refuses an upload naming none with 400 PRECONDITION_REQUIRED. A token behind the live document is refused with 409 PRECONDITION_FAILED. The refusal tells you to read the document again with dispatch doc-read, which prints the token the document carries now, and to upload again naming that token. An upload that replaces a file or a picture names the token of the version it replaces the same way, the `Document token:` line dispatch doc-read prints for its latest version, and any other token is refused with 409 PRECONDITION_FAILED; one naming none is taken unchecked. The command's refusal of a name the owner holds prints no token: for a file or a picture it names --force with the token your own dispatch doc-read printed, or --force alone where Dispatch states no token for the file, since such a Dispatch refuses a token on a file's upload; for an upload of another kind than the name holds (a declared Markdown upload is a document, PNG, JPEG, GIF or WebP bytes a picture, anything else a file) it names another name, since Dispatch refuses it under that name with 400 ARTIFACT_KIND_MISMATCH. A first upload under a name replaces no version, so it names none. " + `${ARTIFACT_CONTENT_NAME_RULE} ${ARTIFACT_STORED_TEXT_RULE} ` + `A text past ${MARKDOWN_DOCUMENT_MAX_BYTES / (1 << 20)} MiB, or holding a NUL character or a byte that is not UTF-8, read from content-file, from stdin or from a Markdown path file, is refused once the flags are read, before the arguments are checked and before anything that needs Dispatch, by the call and its dry run alike, with Dispatch on or off, ${ARTIFACT_DOCUMENT_BYTES_ORDER} ` + `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 ${MARKDOWN_DOCUMENT_MAX_BYTES / (1 << 20)} 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. " + `${CI_CHECK_RULE} ` + `${OWNER_REFERENCE}`,
|
|
15599
15610
|
arguments: (z) => ({
|
|
15600
15611
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15601
15612
|
project: z.string().describe("Project key for an unlinked document.").optional(),
|
|
15602
15613
|
name: z.string().describe("Artifact filename shown in Dispatch."),
|
|
15603
15614
|
path: z.string().describe("Local path to the file to upload.").optional(),
|
|
15604
15615
|
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. Nor is a typed block whose attributes differ only in their order: the upload puts them in Dispatch's order. The refusal names the first difference: a changed line by the attribute or the word that differs, a word of more than 200 characters by a window from its first character that differs, and a line the store adds or drops by a quote cut at 200 characters, each cut named. It prints the text Dispatch stores, which is the text to send.").optional(),
|
|
15605
|
-
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(),
|
|
15616
|
+
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. The command checks the text first, so a text it refuses for the text alone gets that refusal, not this one.").optional(),
|
|
15606
15617
|
precondition: uploadPreconditionArgument(z),
|
|
15607
15618
|
summary: z.string().describe("Optional version summary.").optional()
|
|
15608
15619
|
}),
|
|
@@ -20590,6 +20601,94 @@ function fenceColons(text) {
|
|
|
20590
20601
|
return /^:+$/.test(trimmed) ? trimmed.length : 0;
|
|
20591
20602
|
}
|
|
20592
20603
|
|
|
20604
|
+
// ../envoy-client/src/dispatch-file-text.ts
|
|
20605
|
+
import { isUtf8 } from "buffer";
|
|
20606
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
20607
|
+
var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
20608
|
+
var encoder2 = new TextEncoder;
|
|
20609
|
+
function byteText(byte) {
|
|
20610
|
+
return `0x${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
20611
|
+
}
|
|
20612
|
+
|
|
20613
|
+
class NotUtf8Error extends Error {
|
|
20614
|
+
bytes;
|
|
20615
|
+
name = "NotUtf8Error";
|
|
20616
|
+
constructor(bytes) {
|
|
20617
|
+
super("the bytes are not UTF-8");
|
|
20618
|
+
this.bytes = bytes;
|
|
20619
|
+
}
|
|
20620
|
+
}
|
|
20621
|
+
function firstNotUtf8(bytes) {
|
|
20622
|
+
for (let at = 0;at < bytes.length; ) {
|
|
20623
|
+
const lead = bytes[at];
|
|
20624
|
+
if (lead < 128) {
|
|
20625
|
+
at += 1;
|
|
20626
|
+
continue;
|
|
20627
|
+
}
|
|
20628
|
+
let width;
|
|
20629
|
+
let low = 128;
|
|
20630
|
+
let high = 191;
|
|
20631
|
+
if (lead >= 194 && lead <= 223) {
|
|
20632
|
+
width = 2;
|
|
20633
|
+
} else if (lead >= 224 && lead <= 239) {
|
|
20634
|
+
width = 3;
|
|
20635
|
+
if (lead === 224)
|
|
20636
|
+
low = 160;
|
|
20637
|
+
if (lead === 237)
|
|
20638
|
+
high = 159;
|
|
20639
|
+
} else if (lead >= 240 && lead <= 244) {
|
|
20640
|
+
width = 4;
|
|
20641
|
+
if (lead === 240)
|
|
20642
|
+
low = 144;
|
|
20643
|
+
if (lead === 244)
|
|
20644
|
+
high = 143;
|
|
20645
|
+
} else {
|
|
20646
|
+
return at;
|
|
20647
|
+
}
|
|
20648
|
+
if (at + width > bytes.length)
|
|
20649
|
+
return at;
|
|
20650
|
+
const second = bytes[at + 1];
|
|
20651
|
+
if (second < low || second > high)
|
|
20652
|
+
return at;
|
|
20653
|
+
for (let next = at + 2;next < at + width; next += 1) {
|
|
20654
|
+
if ((bytes[next] & 192) !== 128)
|
|
20655
|
+
return at;
|
|
20656
|
+
}
|
|
20657
|
+
at += width;
|
|
20658
|
+
}
|
|
20659
|
+
return -1;
|
|
20660
|
+
}
|
|
20661
|
+
function firstUnstorable(bytes) {
|
|
20662
|
+
const notUtf8 = isUtf8(bytes) ? -1 : firstNotUtf8(bytes);
|
|
20663
|
+
const nul = bytes.indexOf(0);
|
|
20664
|
+
const at = nul !== -1 && (notUtf8 === -1 || nul < notUtf8) ? nul : notUtf8;
|
|
20665
|
+
if (at === -1)
|
|
20666
|
+
return;
|
|
20667
|
+
return { byte: bytes[at], character: decoder.decode(bytes.subarray(0, at)).length + 1 };
|
|
20668
|
+
}
|
|
20669
|
+
function unstorableBytes(field, bytes) {
|
|
20670
|
+
const first = firstUnstorable(bytes);
|
|
20671
|
+
if (first === undefined)
|
|
20672
|
+
return;
|
|
20673
|
+
const { byte, character } = first;
|
|
20674
|
+
return new Error(byte === 0 ? `NUL_CHARACTER: ${field} holds a NUL character (U+0000) at character ${character}, which Dispatch cannot store` : `INVALID_UTF8: ${field} holds a byte that is not UTF-8 (${byteText(byte)}) at character ${character}, which Dispatch cannot store`);
|
|
20675
|
+
}
|
|
20676
|
+
function utf8Text(bytes) {
|
|
20677
|
+
try {
|
|
20678
|
+
return decoder.decode(bytes);
|
|
20679
|
+
} catch (error) {
|
|
20680
|
+
if (isUtf8(bytes))
|
|
20681
|
+
throw error;
|
|
20682
|
+
throw new NotUtf8Error(bytes);
|
|
20683
|
+
}
|
|
20684
|
+
}
|
|
20685
|
+
function readFileText(path, readStdin = () => readFileSync2(0)) {
|
|
20686
|
+
return utf8Text(path === "-" ? readStdin() : readFileSync2(path));
|
|
20687
|
+
}
|
|
20688
|
+
function fileTextBytes(text) {
|
|
20689
|
+
return encoder2.encode(text);
|
|
20690
|
+
}
|
|
20691
|
+
|
|
20593
20692
|
// ../envoy-client/src/dispatch-command.ts
|
|
20594
20693
|
var PREFIXED_FLAGS = [
|
|
20595
20694
|
{
|
|
@@ -20602,6 +20701,7 @@ var PREFIXED_FLAGS = [
|
|
|
20602
20701
|
}
|
|
20603
20702
|
];
|
|
20604
20703
|
var STDIN = "-";
|
|
20704
|
+
var FILE_BYTES_RULE = "Bytes that are not UTF-8 are refused in Dispatch's own words, and nothing is sent.";
|
|
20605
20705
|
var BARE_WORD = /^[A-Za-z0-9_./:@%+=,-]+$/;
|
|
20606
20706
|
var OPTION_SEPARATOR = ": ";
|
|
20607
20707
|
var LOCAL_FILE_FIELD = { tool: "dispatch_artifact", field: "path" };
|
|
@@ -20644,7 +20744,7 @@ function surfaceFor(tool) {
|
|
|
20644
20744
|
spec,
|
|
20645
20745
|
command: commandName(spec.name),
|
|
20646
20746
|
fields,
|
|
20647
|
-
flags: flagTable(spec
|
|
20747
|
+
flags: flagTable(spec, fields)
|
|
20648
20748
|
};
|
|
20649
20749
|
surfaces.set(tool, surface);
|
|
20650
20750
|
return surface;
|
|
@@ -20765,11 +20865,11 @@ function placeholder(info) {
|
|
|
20765
20865
|
return info.kind.array === "string" ? "<text>" : "<n>";
|
|
20766
20866
|
return "<text>";
|
|
20767
20867
|
}
|
|
20768
|
-
function flagTable(
|
|
20868
|
+
function flagTable(spec, fields) {
|
|
20769
20869
|
const flags = new Map;
|
|
20770
20870
|
const add = (flag, entry) => {
|
|
20771
20871
|
if (flags.has(flag))
|
|
20772
|
-
throw new Error(`${
|
|
20872
|
+
throw new Error(`${spec.name}: two fields claim the flag ${flag}`);
|
|
20773
20873
|
flags.set(flag, entry);
|
|
20774
20874
|
};
|
|
20775
20875
|
for (const [field, info] of fields) {
|
|
@@ -20782,7 +20882,7 @@ function flagTable(tool, fields) {
|
|
|
20782
20882
|
field,
|
|
20783
20883
|
action: "file",
|
|
20784
20884
|
value: "<path>",
|
|
20785
|
-
text: `--${name} read from a file; - reads stdin
|
|
20885
|
+
text: `--${name} read from a file; - reads stdin. ${FILE_BYTES_RULE}`
|
|
20786
20886
|
});
|
|
20787
20887
|
} else if (kind === "number") {
|
|
20788
20888
|
add(`--${name}`, { field, action: "set", value: "<n>", text: about });
|
|
@@ -20815,7 +20915,7 @@ function flagTable(tool, fields) {
|
|
|
20815
20915
|
field,
|
|
20816
20916
|
action: "json-file",
|
|
20817
20917
|
value: "<path>",
|
|
20818
|
-
text: `--${name}-json read from a file; - reads stdin
|
|
20918
|
+
text: `--${name}-json read from a file; - reads stdin. ${FILE_BYTES_RULE}`
|
|
20819
20919
|
});
|
|
20820
20920
|
} else {
|
|
20821
20921
|
const none = kind.array === "number-or-null" ? " none is null." : "";
|
|
@@ -20826,10 +20926,10 @@ function flagTable(tool, fields) {
|
|
|
20826
20926
|
text: `${about} One item per flag, repeated.${none}`.trim()
|
|
20827
20927
|
});
|
|
20828
20928
|
for (const prefixed of PREFIXED_FLAGS) {
|
|
20829
|
-
if (prefixed.tool !==
|
|
20929
|
+
if (prefixed.tool !== spec.name || prefixed.field !== field)
|
|
20830
20930
|
continue;
|
|
20831
20931
|
if (kind.array !== "string") {
|
|
20832
|
-
throw new Error(`${
|
|
20932
|
+
throw new Error(`${spec.name}: ${prefixed.flag} needs ${field} to be a list of text`);
|
|
20833
20933
|
}
|
|
20834
20934
|
add(prefixed.flag, {
|
|
20835
20935
|
field,
|
|
@@ -20851,7 +20951,7 @@ function flagTable(tool, fields) {
|
|
|
20851
20951
|
add("--help", { action: "help", text: "Prints this help." });
|
|
20852
20952
|
add("--dry-run", {
|
|
20853
20953
|
action: "dry-run",
|
|
20854
|
-
text:
|
|
20954
|
+
text: spec.dryRunHelp ?? "Checks the arguments as the call would, then prints them as JSON and sends nothing."
|
|
20855
20955
|
});
|
|
20856
20956
|
return flags;
|
|
20857
20957
|
}
|
|
@@ -20875,7 +20975,8 @@ function parseCommand(argv, io) {
|
|
|
20875
20975
|
let help = false;
|
|
20876
20976
|
let dryRun = false;
|
|
20877
20977
|
let stdinFlag;
|
|
20878
|
-
|
|
20978
|
+
let unstorable;
|
|
20979
|
+
const read = (flag, field, path) => {
|
|
20879
20980
|
if (path === STDIN) {
|
|
20880
20981
|
if (stdinFlag !== undefined) {
|
|
20881
20982
|
problems.push(`${stdinFlag} and ${flag} both read stdin (-); only one flag can`);
|
|
@@ -20886,6 +20987,11 @@ function parseCommand(argv, io) {
|
|
|
20886
20987
|
try {
|
|
20887
20988
|
return io.readText(path);
|
|
20888
20989
|
} catch (error) {
|
|
20990
|
+
if (error instanceof NotUtf8Error) {
|
|
20991
|
+
claim(field, flag, false);
|
|
20992
|
+
unstorable ??= { field, bytes: error.bytes };
|
|
20993
|
+
return;
|
|
20994
|
+
}
|
|
20889
20995
|
problems.push(`${flag} could not read ${path === STDIN ? "stdin" : path}: ${messageFor(error)}`);
|
|
20890
20996
|
return;
|
|
20891
20997
|
}
|
|
@@ -20996,14 +21102,14 @@ function parseCommand(argv, io) {
|
|
|
20996
21102
|
break;
|
|
20997
21103
|
}
|
|
20998
21104
|
case "file": {
|
|
20999
|
-
const text = read(flag, value);
|
|
21105
|
+
const text = read(flag, field, value);
|
|
21000
21106
|
if (text !== undefined && claim(field, flag, false))
|
|
21001
21107
|
args[field] = text;
|
|
21002
21108
|
break;
|
|
21003
21109
|
}
|
|
21004
21110
|
case "json":
|
|
21005
21111
|
case "json-file": {
|
|
21006
|
-
const text = action === "json" ? value : read(flag, value);
|
|
21112
|
+
const text = action === "json" ? value : read(flag, field, value);
|
|
21007
21113
|
const parsed = text === undefined ? undefined : json(flag, text);
|
|
21008
21114
|
if (parsed !== undefined && claim(field, flag, false))
|
|
21009
21115
|
args[field] = parsed.value;
|
|
@@ -21039,6 +21145,8 @@ function parseCommand(argv, io) {
|
|
|
21039
21145
|
if (problems.length > 0) {
|
|
21040
21146
|
return problems.length === bareDashes.size ? { kind: "refused", tool, problems, aboutAFlag: false } : { kind: "refused", tool, problems };
|
|
21041
21147
|
}
|
|
21148
|
+
if (unstorable !== undefined)
|
|
21149
|
+
return { kind: "unstorable", tool, ...unstorable };
|
|
21042
21150
|
return { kind: "call", tool, args, dryRun };
|
|
21043
21151
|
}
|
|
21044
21152
|
function appendedItem(kind, flag, value, number) {
|
|
@@ -21138,7 +21246,7 @@ function commandsHelp() {
|
|
|
21138
21246
|
return ` ${commandName(spec.name).padEnd(width)} ${sentence}`;
|
|
21139
21247
|
}),
|
|
21140
21248
|
"",
|
|
21141
|
-
"Run dispatch <command> --help for its flags and an example
|
|
21249
|
+
"Run dispatch <command> --help for its flags and an example. --dry-run checks a command's arguments as the call would and prints them as given. It stores nothing. A command whose dry run asks Dispatch something past that check (dispatch artifact: how Dispatch would store its text; dispatch result: the pull-request body line the record would print) says so in its --help.",
|
|
21142
21250
|
"",
|
|
21143
21251
|
"dispatch login --device logs a machine with no identity of its own, such as a laptop, in at the secrets broker, once per machine; it is no Dispatch call, and needs no host or session (dispatch login --help).",
|
|
21144
21252
|
""
|
|
@@ -21355,13 +21463,13 @@ var customFetch = Symbol();
|
|
|
21355
21463
|
var modifyAssertion = Symbol();
|
|
21356
21464
|
var jweDecrypt = Symbol();
|
|
21357
21465
|
var jwksCache = Symbol();
|
|
21358
|
-
var
|
|
21359
|
-
var
|
|
21466
|
+
var encoder3 = new TextEncoder;
|
|
21467
|
+
var decoder2 = new TextDecoder;
|
|
21360
21468
|
function buf(input) {
|
|
21361
21469
|
if (typeof input === "string") {
|
|
21362
|
-
return
|
|
21470
|
+
return encoder3.encode(input);
|
|
21363
21471
|
}
|
|
21364
|
-
return
|
|
21472
|
+
return decoder2.decode(input);
|
|
21365
21473
|
}
|
|
21366
21474
|
var encodeBase64Url;
|
|
21367
21475
|
if (Uint8Array.prototype.toBase64) {
|
|
@@ -22229,8 +22337,8 @@ var _nodiscoverycheck = Symbol();
|
|
|
22229
22337
|
var _expectedIssuer = Symbol();
|
|
22230
22338
|
|
|
22231
22339
|
// ../../node_modules/.bun/jose@6.2.9/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
22232
|
-
var
|
|
22233
|
-
var
|
|
22340
|
+
var encoder4 = new TextEncoder;
|
|
22341
|
+
var decoder3 = new TextDecoder;
|
|
22234
22342
|
var strictDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
22235
22343
|
var MAX_INT32 = 2 ** 32;
|
|
22236
22344
|
function concat(...buffers) {
|
|
@@ -22374,7 +22482,7 @@ var invalid = "The input to be decoded is not correctly encoded.";
|
|
|
22374
22482
|
function decode3(input) {
|
|
22375
22483
|
if (Uint8Array.fromBase64) {
|
|
22376
22484
|
try {
|
|
22377
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input :
|
|
22485
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder3.decode(input), {
|
|
22378
22486
|
alphabet: "base64url"
|
|
22379
22487
|
});
|
|
22380
22488
|
} catch (cause) {
|
|
@@ -22383,7 +22491,7 @@ function decode3(input) {
|
|
|
22383
22491
|
}
|
|
22384
22492
|
let encoded = input;
|
|
22385
22493
|
if (encoded instanceof Uint8Array) {
|
|
22386
|
-
encoded =
|
|
22494
|
+
encoded = decoder3.decode(encoded);
|
|
22387
22495
|
}
|
|
22388
22496
|
if (encoded.includes("+") || encoded.includes("/")) {
|
|
22389
22497
|
throw new TypeError(invalid);
|
|
@@ -22398,7 +22506,7 @@ function decode3(input) {
|
|
|
22398
22506
|
function encode4(input) {
|
|
22399
22507
|
let unencoded = input;
|
|
22400
22508
|
if (typeof unencoded === "string") {
|
|
22401
|
-
unencoded =
|
|
22509
|
+
unencoded = encoder4.encode(unencoded);
|
|
22402
22510
|
}
|
|
22403
22511
|
if (Uint8Array.prototype.toBase64) {
|
|
22404
22512
|
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
@@ -22687,7 +22795,7 @@ class ClientError extends Error {
|
|
|
22687
22795
|
Error.captureStackTrace?.(this, this.constructor);
|
|
22688
22796
|
}
|
|
22689
22797
|
}
|
|
22690
|
-
var
|
|
22798
|
+
var decoder4 = new TextDecoder;
|
|
22691
22799
|
function e(msg, cause, code) {
|
|
22692
22800
|
return new ClientError(msg, { cause, code });
|
|
22693
22801
|
}
|
|
@@ -24233,6 +24341,7 @@ class DispatchServiceError extends Error {
|
|
|
24233
24341
|
mismatches;
|
|
24234
24342
|
issues;
|
|
24235
24343
|
changed;
|
|
24344
|
+
textRefusal;
|
|
24236
24345
|
hint;
|
|
24237
24346
|
constructor(code, status, message, details = {}) {
|
|
24238
24347
|
super(message);
|
|
@@ -24243,6 +24352,7 @@ class DispatchServiceError extends Error {
|
|
|
24243
24352
|
this.mismatches = details.mismatches;
|
|
24244
24353
|
this.issues = details.issues;
|
|
24245
24354
|
this.changed = details.changed;
|
|
24355
|
+
this.textRefusal = details.textRefusal ?? false;
|
|
24246
24356
|
this.hint = details.hint;
|
|
24247
24357
|
}
|
|
24248
24358
|
}
|
|
@@ -24523,7 +24633,8 @@ function answerEvent(answer, requestKey, keyEchoed, canTellDeadToken) {
|
|
|
24523
24633
|
if (status === 404 && answer.code === "NOT_FOUND" && answer.error?.startsWith(NO_ROUTE_MESSAGE_PREFIX) === true) {
|
|
24524
24634
|
return "no-route";
|
|
24525
24635
|
}
|
|
24526
|
-
|
|
24636
|
+
const textRefusal = answer.error !== undefined && answer.response.headers.has(TEXT_REFUSAL_HEADER);
|
|
24637
|
+
if (!textRefusal && retriesUnderKey(status, answer.code)) {
|
|
24527
24638
|
if (status === 409)
|
|
24528
24639
|
return "in-flight";
|
|
24529
24640
|
return status >= 500 ? "server-error" : "try-later";
|
|
@@ -24672,8 +24783,15 @@ class DispatchClient {
|
|
|
24672
24783
|
async listIssueArtifacts(issue) {
|
|
24673
24784
|
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "artifacts"]);
|
|
24674
24785
|
}
|
|
24675
|
-
async markdownRoundTrip(markdown) {
|
|
24676
|
-
|
|
24786
|
+
async markdownRoundTrip(markdown, newDocument) {
|
|
24787
|
+
return this.#roundTrip(["api", "v1", "markdown", "round-trip"], { markdown }, newDocument);
|
|
24788
|
+
}
|
|
24789
|
+
async fileRoundTrip(bytes, newDocument) {
|
|
24790
|
+
const file = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
24791
|
+
return this.#roundTrip(["api", "v1", "markdown", "file-round-trip"], { file }, newDocument);
|
|
24792
|
+
}
|
|
24793
|
+
async#roundTrip(path, body, newDocument) {
|
|
24794
|
+
const answer = await this.#writingNothing(path, newDocument ? { ...body, new_document: true } : body, { writes: false });
|
|
24677
24795
|
return answer.markdown;
|
|
24678
24796
|
}
|
|
24679
24797
|
async listProjectArtifacts(project, unlinked = false) {
|
|
@@ -25527,7 +25645,10 @@ class DispatchClient {
|
|
|
25527
25645
|
if (response.status === 409 && refusal.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
25528
25646
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
25529
25647
|
}
|
|
25530
|
-
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error,
|
|
25648
|
+
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error, {
|
|
25649
|
+
...refusal,
|
|
25650
|
+
textRefusal: response.headers.has(TEXT_REFUSAL_HEADER)
|
|
25651
|
+
});
|
|
25531
25652
|
}
|
|
25532
25653
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
25533
25654
|
}
|
|
@@ -25652,6 +25773,10 @@ function linkFor(href, linkBase) {
|
|
|
25652
25773
|
}
|
|
25653
25774
|
|
|
25654
25775
|
// ../envoy-client/src/dispatch-commands/context.ts
|
|
25776
|
+
var DRY_RUN_DEADLINE_MS = 5000;
|
|
25777
|
+
function askOnceWithinDryRun(deadlineMs = DRY_RUN_DEADLINE_MS) {
|
|
25778
|
+
return { deadlineMs, retryNoRoute: false, writeRetry: { ...DISPATCH_WRITE_RETRY, pausesMs: [] } };
|
|
25779
|
+
}
|
|
25655
25780
|
function stringArg(args, name) {
|
|
25656
25781
|
const value = args[name];
|
|
25657
25782
|
if (typeof value !== "string")
|
|
@@ -25729,10 +25854,11 @@ function sessionContext(input, checked) {
|
|
|
25729
25854
|
configUrl,
|
|
25730
25855
|
linkBase: linkBaseOf(input.config.publicUrl ?? url),
|
|
25731
25856
|
hostSession: input.sessionId?.trim(),
|
|
25732
|
-
newClient: () => new DispatchClient(url, credential, fetchImpl, {
|
|
25857
|
+
newClient: (options = {}) => new DispatchClient(url, credential, fetchImpl, {
|
|
25733
25858
|
signal: input.signal,
|
|
25734
25859
|
writeRetry: input.writeRetry,
|
|
25735
|
-
sleep: input.sleep
|
|
25860
|
+
sleep: input.sleep,
|
|
25861
|
+
...options
|
|
25736
25862
|
})
|
|
25737
25863
|
};
|
|
25738
25864
|
}
|
|
@@ -25786,6 +25912,7 @@ var WRITE_ROUTES = [
|
|
|
25786
25912
|
{ method: "POST", pattern: "/api/v1/issues/{key}/artifacts", commands: ["artifact"] },
|
|
25787
25913
|
{ method: "POST", pattern: "/api/v1/projects/{key}/artifacts", commands: ["artifact"] },
|
|
25788
25914
|
{ method: "POST", pattern: "/api/v1/markdown/round-trip", commands: ["artifact"] },
|
|
25915
|
+
{ method: "POST", pattern: "/api/v1/markdown/file-round-trip", commands: ["artifact"] },
|
|
25789
25916
|
{ method: "POST", pattern: "/api/v1/projects", commands: ["project"] },
|
|
25790
25917
|
{
|
|
25791
25918
|
method: "PUT",
|
|
@@ -28625,14 +28752,14 @@ function brokerCredential(env, session, read) {
|
|
|
28625
28752
|
}
|
|
28626
28753
|
|
|
28627
28754
|
// ../envoy-client/src/file-token-credential.ts
|
|
28628
|
-
import { readFileSync as
|
|
28755
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
28629
28756
|
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
28630
28757
|
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
28631
28758
|
var PKCS8_LABEL = "PRIVATE KEY";
|
|
28632
28759
|
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
28633
28760
|
function readNamed(variable, filePath) {
|
|
28634
28761
|
try {
|
|
28635
|
-
return
|
|
28762
|
+
return readFileSync3(filePath, "utf8");
|
|
28636
28763
|
} catch (error) {
|
|
28637
28764
|
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
28638
28765
|
}
|
|
@@ -32685,7 +32812,7 @@ var DISPATCH_BOOKKEEPING = new Set([
|
|
|
32685
32812
|
"references_changed_truncated_kinds",
|
|
32686
32813
|
"rank"
|
|
32687
32814
|
]);
|
|
32688
|
-
function dispatchPayloadForReader(event, sessionID, issuedAt) {
|
|
32815
|
+
function dispatchPayloadForReader(event, sessionID, issuedAt, toReader) {
|
|
32689
32816
|
const whole = dispatchPayload(event);
|
|
32690
32817
|
const changed = event.type !== "issue.created" && isObject3(whole) && Array.isArray(whole["changed"]) ? whole["changed"] : [];
|
|
32691
32818
|
const payload = withoutEmptyFields(whole, (key, item) => changed.includes(key) || (key === "suggestion" || key === "forced") && item !== null && item !== undefined);
|
|
@@ -32698,6 +32825,7 @@ function dispatchPayloadForReader(event, sessionID, issuedAt) {
|
|
|
32698
32825
|
case "issue_key":
|
|
32699
32826
|
return value === event.issue_key;
|
|
32700
32827
|
case "author":
|
|
32828
|
+
case "actor":
|
|
32701
32829
|
return isObject3(value) && Object.entries(value).every(([field, held]) => isDeepStrictEqual(held, actor[field]));
|
|
32702
32830
|
case "created_at": {
|
|
32703
32831
|
if (typeof value !== "string")
|
|
@@ -32708,6 +32836,8 @@ function dispatchPayloadForReader(event, sessionID, issuedAt) {
|
|
|
32708
32836
|
case "thread_root_id":
|
|
32709
32837
|
case "answers":
|
|
32710
32838
|
return typeof replyTo === "string" && value === replyTo;
|
|
32839
|
+
case "target":
|
|
32840
|
+
return toReader && value === `session:${sessionID}`;
|
|
32711
32841
|
default:
|
|
32712
32842
|
return DISPATCH_BOOKKEEPING.has(key);
|
|
32713
32843
|
}
|
|
@@ -32907,6 +33037,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
32907
33037
|
let payloadSessions = [];
|
|
32908
33038
|
let trailer = "";
|
|
32909
33039
|
const at = inboundTimestamp(envelope.issued_at);
|
|
33040
|
+
const toReader = envelope.topic !== undefined && topicForms(envelope.topic).includes(legacyAgentSubject(sessionID));
|
|
32910
33041
|
const dispatchRendered = envelope.source === "dispatch" && envelope.payload !== undefined;
|
|
32911
33042
|
if (envelope.source === "dispatch") {
|
|
32912
33043
|
const topic = subject ?? envelope.topic;
|
|
@@ -33012,15 +33143,16 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
33012
33143
|
ask: dispatchReplyRef(frame.event, topic, compact.askId, commentPayload),
|
|
33013
33144
|
...compact.record
|
|
33014
33145
|
};
|
|
33015
|
-
const payload = compactRecord === undefined ? dispatchPayloadForReader(frame.event, sessionID, envelope.issued_at) : undefined;
|
|
33146
|
+
const payload = compactRecord === undefined ? dispatchPayloadForReader(frame.event, sessionID, envelope.issued_at, toReader) : undefined;
|
|
33016
33147
|
let actor = frame.event.actor;
|
|
33017
33148
|
if ("origin" in frame.event.actor) {
|
|
33018
33149
|
const { origin, ...rest } = frame.event.actor;
|
|
33019
33150
|
const title = isObject3(origin) ? origin["session_title"] : undefined;
|
|
33020
33151
|
actor = typeof title === "string" && title !== "" ? { ...rest, origin: { session_title: title } } : rest;
|
|
33021
33152
|
}
|
|
33153
|
+
const owner = dispatchOwner(frame.event, topic);
|
|
33022
33154
|
dispatchEvent = {
|
|
33023
|
-
owner:
|
|
33155
|
+
...owner === "unknown" ? {} : { owner },
|
|
33024
33156
|
type: frame.event.type,
|
|
33025
33157
|
actor,
|
|
33026
33158
|
...relation === undefined ? {} : { relation },
|
|
@@ -33075,7 +33207,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
33075
33207
|
...dispatchIssue === undefined ? [] : [dispatchIssue]
|
|
33076
33208
|
].join(", ") || undefined;
|
|
33077
33209
|
const rendered = {
|
|
33078
|
-
...
|
|
33210
|
+
...toReader ? { to: `you (${sessionID})` } : {},
|
|
33079
33211
|
from: senderLabel(envelope),
|
|
33080
33212
|
at,
|
|
33081
33213
|
id: envelope.event_id ?? "unknown",
|
|
@@ -35549,62 +35681,343 @@ async function loginCommand(argv, env, io) {
|
|
|
35549
35681
|
}
|
|
35550
35682
|
}
|
|
35551
35683
|
|
|
35552
|
-
// ../envoy-client/src/dispatch-commands/
|
|
35553
|
-
|
|
35554
|
-
|
|
35555
|
-
|
|
35556
|
-
|
|
35557
|
-
|
|
35558
|
-
|
|
35559
|
-
|
|
35560
|
-
|
|
35684
|
+
// ../envoy-client/src/dispatch-commands/stored-text.ts
|
|
35685
|
+
import { resolve as resolvePath2 } from "path";
|
|
35686
|
+
|
|
35687
|
+
// ../envoy-client/src/dispatch-commands/stored-spelling.ts
|
|
35688
|
+
function headedOpener(line) {
|
|
35689
|
+
for (let at = 0;at < line.length; at += Math.max(1, runOf(line, at, ":"))) {
|
|
35690
|
+
const brace = typedFenceBrace(line, at);
|
|
35691
|
+
if (brace === -1)
|
|
35692
|
+
continue;
|
|
35693
|
+
const opener = typedOpenerAt(line, at);
|
|
35694
|
+
return opener === undefined ? undefined : { ...opener, head: line.slice(0, brace + 1) };
|
|
35695
|
+
}
|
|
35696
|
+
return;
|
|
35697
|
+
}
|
|
35698
|
+
function attributesByName(attributes) {
|
|
35699
|
+
const byName = new Map(attributes.map((attribute) => [attribute.name, attribute.text]));
|
|
35700
|
+
return byName.size === attributes.length ? byName : undefined;
|
|
35701
|
+
}
|
|
35702
|
+
function inStoredOrder(given, stored) {
|
|
35703
|
+
const written = attributesByName(given.attributes);
|
|
35704
|
+
if (written === undefined || attributesByName(stored.attributes) === undefined || stored.attributes.length !== given.attributes.length) {
|
|
35705
|
+
return;
|
|
35706
|
+
}
|
|
35707
|
+
let line = `${given.head}${given.gaps[0] ?? ""}`;
|
|
35708
|
+
for (const [index, attribute] of stored.attributes.entries()) {
|
|
35709
|
+
const text = written.get(attribute.name);
|
|
35710
|
+
if (text === undefined)
|
|
35711
|
+
return;
|
|
35712
|
+
line += `${text}${given.gaps[index + 1] ?? ""}`;
|
|
35713
|
+
}
|
|
35714
|
+
return `${line}}`;
|
|
35715
|
+
}
|
|
35716
|
+
function onlyReordered(given, held, stored) {
|
|
35717
|
+
return given !== undefined && stored !== undefined && inStoredOrder(given, stored) === held;
|
|
35718
|
+
}
|
|
35719
|
+
function reorderedBlockLine(line, opener) {
|
|
35720
|
+
const named = `${opener.name} block${opener.id === undefined ? "" : ` ${opener.id}`}`;
|
|
35721
|
+
const order = opener.attributes.map((attribute) => attribute.name).join(", ");
|
|
35722
|
+
return `This upload put the attributes of ${named} (line ${line}) in the order Dispatch stores: ${order}.`;
|
|
35723
|
+
}
|
|
35724
|
+
function attributesReordered(given, stored) {
|
|
35725
|
+
const written = withoutFinalLineFeed(given).split(`
|
|
35726
|
+
`);
|
|
35727
|
+
const holds = withoutFinalLineFeed(stored).split(`
|
|
35728
|
+
`);
|
|
35729
|
+
if (written.length !== holds.length)
|
|
35730
|
+
return;
|
|
35731
|
+
const lines = [];
|
|
35732
|
+
for (const [index, held] of holds.entries()) {
|
|
35733
|
+
const wrote = written[index];
|
|
35734
|
+
if (wrote === held)
|
|
35735
|
+
continue;
|
|
35736
|
+
const opener = headedOpener(held);
|
|
35737
|
+
if (wrote === undefined || opener === undefined || !onlyReordered(headedOpener(wrote), held, opener)) {
|
|
35738
|
+
return;
|
|
35561
35739
|
}
|
|
35562
|
-
|
|
35740
|
+
lines.push(reorderedBlockLine(index + 1, opener));
|
|
35741
|
+
}
|
|
35742
|
+
return lines;
|
|
35563
35743
|
}
|
|
35564
|
-
|
|
35565
|
-
|
|
35566
|
-
const
|
|
35567
|
-
const
|
|
35568
|
-
const
|
|
35569
|
-
|
|
35570
|
-
|
|
35571
|
-
|
|
35572
|
-
|
|
35573
|
-
|
|
35574
|
-
|
|
35744
|
+
var STORED_LINE_QUOTED = 200;
|
|
35745
|
+
function quotedStoredLine(characters, from) {
|
|
35746
|
+
const shown = characters.slice(from, from + STORED_LINE_QUOTED);
|
|
35747
|
+
const quote = JSON.stringify(shown.join(""));
|
|
35748
|
+
const cutAfter = from + shown.length < characters.length;
|
|
35749
|
+
if (from === 0 && !cutAfter)
|
|
35750
|
+
return quote;
|
|
35751
|
+
const cut = from === 0 ? "after" : cutAfter ? "before and after" : "before the last";
|
|
35752
|
+
return `${quote} (cut ${cut} ${shown.length} of its ${characters.length} characters)`;
|
|
35753
|
+
}
|
|
35754
|
+
function lineWords(line, opener) {
|
|
35755
|
+
const plain = (text) => (text.match(/\s+|\S+/g) ?? []).map((word) => ({ text: word, attribute: false }));
|
|
35756
|
+
if (opener === undefined)
|
|
35757
|
+
return plain(line);
|
|
35758
|
+
const words = plain(opener.head);
|
|
35759
|
+
for (const [index, gap] of opener.gaps.entries()) {
|
|
35760
|
+
if (gap !== "")
|
|
35761
|
+
words.push({ text: gap, attribute: false });
|
|
35762
|
+
const attribute = opener.attributes[index];
|
|
35763
|
+
if (attribute !== undefined)
|
|
35764
|
+
words.push({ text: attribute.text, attribute: true });
|
|
35575
35765
|
}
|
|
35576
|
-
|
|
35577
|
-
|
|
35578
|
-
|
|
35579
|
-
|
|
35580
|
-
|
|
35581
|
-
|
|
35582
|
-
|
|
35583
|
-
|
|
35584
|
-
|
|
35585
|
-
|
|
35586
|
-
|
|
35587
|
-
|
|
35588
|
-
|
|
35589
|
-
|
|
35766
|
+
words.push({ text: "}", attribute: false });
|
|
35767
|
+
return words;
|
|
35768
|
+
}
|
|
35769
|
+
function wordText(word, from = 0, characters = Array.from(word.text)) {
|
|
35770
|
+
if (word.attribute)
|
|
35771
|
+
return `the attribute ${word.text}`;
|
|
35772
|
+
return `${/\S/.test(word.text) ? "the word" : "the space"} ${quotedStoredLine(characters, from)}`;
|
|
35773
|
+
}
|
|
35774
|
+
function wordDifference(written, holds) {
|
|
35775
|
+
let before = 0;
|
|
35776
|
+
for (let index = 0;index < Math.max(written.length, holds.length); index += 1) {
|
|
35777
|
+
const given = written[index];
|
|
35778
|
+
const stored = holds[index];
|
|
35779
|
+
if (given !== undefined && stored !== undefined && given.text === stored.text) {
|
|
35780
|
+
before += Array.from(given.text).length;
|
|
35781
|
+
continue;
|
|
35590
35782
|
}
|
|
35591
|
-
|
|
35592
|
-
|
|
35593
|
-
|
|
35594
|
-
|
|
35783
|
+
if (given === undefined && stored !== undefined) {
|
|
35784
|
+
return `ends after character ${before}, where Dispatch goes on with ${wordText(stored)}`;
|
|
35785
|
+
}
|
|
35786
|
+
if (given !== undefined && stored === undefined) {
|
|
35787
|
+
return `reads ${wordText(given)} at character ${before + 1}, where Dispatch ends the line`;
|
|
35788
|
+
}
|
|
35789
|
+
if (given !== undefined && stored !== undefined) {
|
|
35790
|
+
const wrote = Array.from(given.text);
|
|
35791
|
+
const held = Array.from(stored.text);
|
|
35792
|
+
let from = 0;
|
|
35793
|
+
if (!given.attribute && !stored.attribute && Math.max(wrote.length, held.length) > STORED_LINE_QUOTED) {
|
|
35794
|
+
while (from < wrote.length && wrote[from] === held[from])
|
|
35795
|
+
from += 1;
|
|
35796
|
+
const tail = Math.max(0, from - STORED_LINE_QUOTED);
|
|
35797
|
+
if (from === wrote.length) {
|
|
35798
|
+
return `ends ${wordText(given, tail, wrote)} after character ${before + from}, where Dispatch goes on with ${wordText(stored, from, held)}`;
|
|
35799
|
+
}
|
|
35800
|
+
if (from === held.length) {
|
|
35801
|
+
return `reads ${wordText(given, from, wrote)} at character ${before + from + 1}, where Dispatch ends ${wordText(stored, tail, held)}`;
|
|
35802
|
+
}
|
|
35803
|
+
}
|
|
35804
|
+
return `reads ${wordText(given, from, wrote)} at character ${before + from + 1}, where Dispatch stores ${wordText(stored, from, held)}`;
|
|
35805
|
+
}
|
|
35806
|
+
}
|
|
35807
|
+
return "differs from the line Dispatch stores";
|
|
35808
|
+
}
|
|
35809
|
+
function attributeDifference(line, given, stored) {
|
|
35810
|
+
const written = attributesByName(given.attributes);
|
|
35811
|
+
if (written === undefined)
|
|
35812
|
+
return;
|
|
35813
|
+
for (const attribute of stored.attributes) {
|
|
35814
|
+
const text = written.get(attribute.name);
|
|
35815
|
+
if (text === undefined)
|
|
35816
|
+
return `Dispatch adds the attribute ${attribute.text} to line ${line}`;
|
|
35817
|
+
if (text !== attribute.text) {
|
|
35818
|
+
return `line ${line} holds the attribute ${text}, which Dispatch stores as ${attribute.text}`;
|
|
35819
|
+
}
|
|
35820
|
+
}
|
|
35821
|
+
const held = new Set(stored.attributes.map((attribute) => attribute.name));
|
|
35822
|
+
const dropped = given.attributes.find((attribute) => !held.has(attribute.name));
|
|
35823
|
+
return dropped === undefined ? undefined : `line ${line} holds the attribute ${dropped.text}, which Dispatch drops`;
|
|
35824
|
+
}
|
|
35825
|
+
function lineDifference(line, wrote, given, held, stored) {
|
|
35826
|
+
if (given === undefined || stored === undefined) {
|
|
35827
|
+
return `line ${line} ${wordDifference(lineWords(wrote, undefined), lineWords(held, undefined))}`;
|
|
35828
|
+
}
|
|
35829
|
+
const attribute = attributeDifference(line, given, stored);
|
|
35830
|
+
if (attribute !== undefined)
|
|
35831
|
+
return attribute;
|
|
35832
|
+
const reordered = inStoredOrder(given, stored);
|
|
35833
|
+
if (reordered !== undefined && reordered !== wrote) {
|
|
35834
|
+
const words = lineWords(reordered, headedOpener(reordered));
|
|
35835
|
+
return `line ${line}, with its attributes put in the order Dispatch stores, ${wordDifference(words, lineWords(held, stored))}`;
|
|
35836
|
+
}
|
|
35837
|
+
return `line ${line} ${wordDifference(lineWords(wrote, given), lineWords(held, stored))}`;
|
|
35838
|
+
}
|
|
35839
|
+
function firstStoredDifference(given, stored) {
|
|
35840
|
+
const written = given.split(`
|
|
35841
|
+
`);
|
|
35842
|
+
const holds = stored.split(`
|
|
35843
|
+
`);
|
|
35844
|
+
for (let line = 0;line < Math.max(written.length, holds.length); line += 1) {
|
|
35845
|
+
const wrote = written[line];
|
|
35846
|
+
const held = holds[line];
|
|
35847
|
+
if (wrote === held)
|
|
35848
|
+
continue;
|
|
35849
|
+
if (wrote === undefined && held !== undefined) {
|
|
35850
|
+
return `the store writes a line ${line + 1}, ${quotedStoredLine(Array.from(held), 0)}`;
|
|
35851
|
+
}
|
|
35852
|
+
if (held === undefined && wrote !== undefined) {
|
|
35853
|
+
return `the store drops line ${line + 1}, ${quotedStoredLine(Array.from(wrote), 0)}`;
|
|
35854
|
+
}
|
|
35855
|
+
if (wrote !== undefined && held !== undefined) {
|
|
35856
|
+
const givenOpener = headedOpener(wrote);
|
|
35857
|
+
const storedOpener = headedOpener(held);
|
|
35858
|
+
if (onlyReordered(givenOpener, held, storedOpener))
|
|
35859
|
+
continue;
|
|
35860
|
+
return lineDifference(line + 1, wrote, givenOpener, held, storedOpener);
|
|
35861
|
+
}
|
|
35862
|
+
}
|
|
35863
|
+
return "the stored text differs from the text given";
|
|
35864
|
+
}
|
|
35865
|
+
var STORED_TEXT_PRINTED = 2000;
|
|
35866
|
+
function storedTextPrinted(stored) {
|
|
35867
|
+
if (stored.length <= STORED_TEXT_PRINTED)
|
|
35868
|
+
return { text: stored, cut: "" };
|
|
35869
|
+
const head = stored.slice(0, STORED_TEXT_PRINTED);
|
|
35870
|
+
const lastLineFeed = head.lastIndexOf(`
|
|
35871
|
+
`);
|
|
35872
|
+
const text = lastLineFeed === -1 ? head : head.slice(0, lastLineFeed + 1);
|
|
35595
35873
|
return {
|
|
35596
|
-
|
|
35597
|
-
|
|
35598
|
-
actor,
|
|
35599
|
-
owner,
|
|
35600
|
-
documentOwner,
|
|
35601
|
-
resolveDocument,
|
|
35602
|
-
issue,
|
|
35603
|
-
postWithPictures,
|
|
35604
|
-
writePictures,
|
|
35605
|
-
shown: hostSession ? shownPictures(hostSession) : undefined
|
|
35874
|
+
text,
|
|
35875
|
+
cut: ` The text below is cut after ${text.length} of its ${stored.length} characters: change the line named above and send the text again.`
|
|
35606
35876
|
};
|
|
35607
35877
|
}
|
|
35878
|
+
function storedTextProblem(given, stored, name) {
|
|
35879
|
+
const asBytes = pathKeepsBytesOf(name) ? ` To keep the text as you wrote it, send it as a file with ${PATH_KEEPS_BYTES}.` : "";
|
|
35880
|
+
const printed = storedTextPrinted(stored);
|
|
35881
|
+
return [
|
|
35882
|
+
`Dispatch stores this text under another spelling: ${firstStoredDifference(given, stored)}.`,
|
|
35883
|
+
` Send the text Dispatch stores, which is between the two marker lines below.${asBytes}`,
|
|
35884
|
+
`${printed.cut}
|
|
35885
|
+
--- the text Dispatch stores ---
|
|
35886
|
+
${printed.text}`,
|
|
35887
|
+
"--- end of the text Dispatch stores ---"
|
|
35888
|
+
].join("");
|
|
35889
|
+
}
|
|
35890
|
+
function withoutFinalLineFeed(text) {
|
|
35891
|
+
return text.endsWith(`
|
|
35892
|
+
`) ? text.slice(0, -1) : text;
|
|
35893
|
+
}
|
|
35894
|
+
function storedUpload(given, stored, name) {
|
|
35895
|
+
if (withoutFinalLineFeed(stored) === withoutFinalLineFeed(given)) {
|
|
35896
|
+
return { sent: given, reordered: [] };
|
|
35897
|
+
}
|
|
35898
|
+
const reordered = attributesReordered(given, stored);
|
|
35899
|
+
return reordered === undefined ? { refusal: storedTextProblem(given, stored, name) } : { sent: stored, reordered };
|
|
35900
|
+
}
|
|
35901
|
+
|
|
35902
|
+
// ../envoy-client/src/dispatch-commands/stored-text.ts
|
|
35903
|
+
var MARKDOWN_ROUND_TRIP = "POST /api/v1/markdown/round-trip";
|
|
35904
|
+
var FILE_ROUND_TRIP = "POST /api/v1/markdown/file-round-trip";
|
|
35905
|
+
function storedTextCheckFailed(failed) {
|
|
35906
|
+
const again = failed.error instanceof DispatchAnswerNotKeptError ? "Send the upload again, which asks it under a new key." : "Send the upload again once that call is answered.";
|
|
35907
|
+
return new Error(`Dispatch could not say how it would store this text, so nothing was uploaded: ${failed.failure}. ${again}`, { cause: failed.error });
|
|
35908
|
+
}
|
|
35909
|
+
function roundTripRouteAbsent(error) {
|
|
35910
|
+
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
35911
|
+
}
|
|
35912
|
+
function documentTooLarge(measured) {
|
|
35913
|
+
const bytes = typeof measured === "number" ? measured : typeof measured === "string" ? utf8Bytes(measured) : measured.byteLength;
|
|
35914
|
+
return bytes > MARKDOWN_DOCUMENT_MAX_BYTES ? new Error(`CAP_EXCEEDED: ${MARKDOWN_DOCUMENT_TOO_LARGE}`) : undefined;
|
|
35915
|
+
}
|
|
35916
|
+
function documentBytesRefusal(field, bytes) {
|
|
35917
|
+
return documentTooLarge(bytes) ?? unstorableBytes(field, bytes);
|
|
35918
|
+
}
|
|
35919
|
+
function documentFieldRefusal(field, text) {
|
|
35920
|
+
return Buffer.byteLength(text, "utf8") > MARKDOWN_DOCUMENT_MAX_BYTES || text.includes("\x00") ? documentBytesRefusal(field, fileTextBytes(text)) : undefined;
|
|
35921
|
+
}
|
|
35922
|
+
function uploadedFile(cwd, path) {
|
|
35923
|
+
return Bun.file(resolvePath2(cwd, path));
|
|
35924
|
+
}
|
|
35925
|
+
async function documentFileRead(file, held) {
|
|
35926
|
+
if (file.type.split(";", 1)[0]?.trim().toLowerCase() !== "text/markdown") {
|
|
35927
|
+
return { kind: "passed", bytes: undefined };
|
|
35928
|
+
}
|
|
35929
|
+
let bytes = held;
|
|
35930
|
+
if (bytes === undefined) {
|
|
35931
|
+
const stats = await file.stat().catch(() => {
|
|
35932
|
+
return;
|
|
35933
|
+
});
|
|
35934
|
+
if (stats !== undefined && !stats.isFile() && !stats.isDirectory()) {
|
|
35935
|
+
return { kind: "passed", bytes: undefined };
|
|
35936
|
+
}
|
|
35937
|
+
const tooLarge = stats === undefined ? undefined : documentTooLarge(stats.size);
|
|
35938
|
+
if (tooLarge !== undefined)
|
|
35939
|
+
return { kind: "refused", refusal: tooLarge };
|
|
35940
|
+
try {
|
|
35941
|
+
bytes = await file.bytes();
|
|
35942
|
+
} catch (error) {
|
|
35943
|
+
return { kind: "unread", error };
|
|
35944
|
+
}
|
|
35945
|
+
}
|
|
35946
|
+
const refusal = documentBytesRefusal("file", bytes);
|
|
35947
|
+
return refusal === undefined ? { kind: "passed", bytes } : { kind: "refused", refusal };
|
|
35948
|
+
}
|
|
35949
|
+
async function documentFileBytes(file, held) {
|
|
35950
|
+
const read = await documentFileRead(file, held);
|
|
35951
|
+
if (read.kind === "refused")
|
|
35952
|
+
throw read.refusal;
|
|
35953
|
+
if (read.kind === "unread")
|
|
35954
|
+
throw read.error;
|
|
35955
|
+
return read.bytes;
|
|
35956
|
+
}
|
|
35957
|
+
function unchecked(answer) {
|
|
35958
|
+
return { kind: "unchecked", failure: answer.failure, routeAbsent: answer.routeAbsent };
|
|
35959
|
+
}
|
|
35960
|
+
async function askRoundTrip(client, route, ask) {
|
|
35961
|
+
const dispatch = client();
|
|
35962
|
+
try {
|
|
35963
|
+
return { kind: "stored", stored: await ask(dispatch) };
|
|
35964
|
+
} catch (error) {
|
|
35965
|
+
const routeAbsent = roundTripRouteAbsent(error);
|
|
35966
|
+
if (!routeAbsent && error instanceof DispatchServiceError && error.textRefusal) {
|
|
35967
|
+
return { kind: "refused", refusal: error };
|
|
35968
|
+
}
|
|
35969
|
+
return {
|
|
35970
|
+
kind: "unanswered",
|
|
35971
|
+
failure: error instanceof DispatchAnswerNotKeptError ? `${route} wrote nothing, and Dispatch kept no copy of its answer (${error.code})` : `${route} failed with ${messageFor(error)}`,
|
|
35972
|
+
error,
|
|
35973
|
+
routeAbsent
|
|
35974
|
+
};
|
|
35975
|
+
}
|
|
35976
|
+
}
|
|
35977
|
+
async function storedTextCheck(client, tool, name, content, force) {
|
|
35978
|
+
const tooLarge = documentTooLarge(content);
|
|
35979
|
+
if (tooLarge !== undefined)
|
|
35980
|
+
return { kind: "refused", refusal: tooLarge };
|
|
35981
|
+
if (content === "")
|
|
35982
|
+
return { kind: "kept" };
|
|
35983
|
+
const answer = await askRoundTrip(client, MARKDOWN_ROUND_TRIP, (dispatch) => dispatch.markdownRoundTrip(content, !force));
|
|
35984
|
+
const blank = goBlankPattern.test(content);
|
|
35985
|
+
switch (answer.kind) {
|
|
35986
|
+
case "refused":
|
|
35987
|
+
return answer;
|
|
35988
|
+
case "unanswered":
|
|
35989
|
+
return blank || answer.routeAbsent ? unchecked(answer) : { kind: "failed", failure: answer.failure, error: answer.error };
|
|
35990
|
+
case "stored": {
|
|
35991
|
+
if (blank)
|
|
35992
|
+
return { kind: "kept" };
|
|
35993
|
+
const upload = storedUpload(content, answer.stored, name);
|
|
35994
|
+
if ("refusal" in upload) {
|
|
35995
|
+
return { kind: "refused", refusal: new ToolInputError(tool, [upload.refusal]) };
|
|
35996
|
+
}
|
|
35997
|
+
return upload.reordered.length === 0 ? { kind: "kept" } : { kind: "reordered", sent: upload.sent, lines: upload.reordered };
|
|
35998
|
+
}
|
|
35999
|
+
}
|
|
36000
|
+
}
|
|
36001
|
+
async function storedFileCheck(client, bytes, force) {
|
|
36002
|
+
const answer = await askRoundTrip(client, FILE_ROUND_TRIP, (dispatch) => dispatch.fileRoundTrip(bytes, !force));
|
|
36003
|
+
switch (answer.kind) {
|
|
36004
|
+
case "stored":
|
|
36005
|
+
return { kind: "kept" };
|
|
36006
|
+
case "refused":
|
|
36007
|
+
return answer;
|
|
36008
|
+
case "unanswered":
|
|
36009
|
+
return unchecked(answer);
|
|
36010
|
+
}
|
|
36011
|
+
}
|
|
36012
|
+
function artifactTextCheck(upload) {
|
|
36013
|
+
const { tool, name, content, bytes, force } = upload;
|
|
36014
|
+
if (content !== undefined) {
|
|
36015
|
+
return () => storedTextCheck(upload.textClient, tool, name, content, force);
|
|
36016
|
+
}
|
|
36017
|
+
if (bytes !== undefined)
|
|
36018
|
+
return () => storedFileCheck(upload.fileClient, bytes, force);
|
|
36019
|
+
return;
|
|
36020
|
+
}
|
|
35608
36021
|
|
|
35609
36022
|
// ../envoy-client/src/dispatch-commands/render-item.ts
|
|
35610
36023
|
function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
|
|
@@ -36451,222 +36864,7 @@ async function sendToAgentCommand(context) {
|
|
|
36451
36864
|
}
|
|
36452
36865
|
|
|
36453
36866
|
// ../envoy-client/src/dispatch-commands/documents.ts
|
|
36454
|
-
import { resolve as
|
|
36455
|
-
|
|
36456
|
-
// ../envoy-client/src/dispatch-commands/stored-spelling.ts
|
|
36457
|
-
function headedOpener(line) {
|
|
36458
|
-
for (let at = 0;at < line.length; at += Math.max(1, runOf(line, at, ":"))) {
|
|
36459
|
-
const brace = typedFenceBrace(line, at);
|
|
36460
|
-
if (brace === -1)
|
|
36461
|
-
continue;
|
|
36462
|
-
const opener = typedOpenerAt(line, at);
|
|
36463
|
-
return opener === undefined ? undefined : { ...opener, head: line.slice(0, brace + 1) };
|
|
36464
|
-
}
|
|
36465
|
-
return;
|
|
36466
|
-
}
|
|
36467
|
-
function attributesByName(attributes) {
|
|
36468
|
-
const byName = new Map(attributes.map((attribute) => [attribute.name, attribute.text]));
|
|
36469
|
-
return byName.size === attributes.length ? byName : undefined;
|
|
36470
|
-
}
|
|
36471
|
-
function inStoredOrder(given, stored) {
|
|
36472
|
-
const written = attributesByName(given.attributes);
|
|
36473
|
-
if (written === undefined || attributesByName(stored.attributes) === undefined || stored.attributes.length !== given.attributes.length) {
|
|
36474
|
-
return;
|
|
36475
|
-
}
|
|
36476
|
-
let line = `${given.head}${given.gaps[0] ?? ""}`;
|
|
36477
|
-
for (const [index, attribute] of stored.attributes.entries()) {
|
|
36478
|
-
const text = written.get(attribute.name);
|
|
36479
|
-
if (text === undefined)
|
|
36480
|
-
return;
|
|
36481
|
-
line += `${text}${given.gaps[index + 1] ?? ""}`;
|
|
36482
|
-
}
|
|
36483
|
-
return `${line}}`;
|
|
36484
|
-
}
|
|
36485
|
-
function onlyReordered(given, held, stored) {
|
|
36486
|
-
return given !== undefined && stored !== undefined && inStoredOrder(given, stored) === held;
|
|
36487
|
-
}
|
|
36488
|
-
function reorderedBlockLine(line, opener) {
|
|
36489
|
-
const named = `${opener.name} block${opener.id === undefined ? "" : ` ${opener.id}`}`;
|
|
36490
|
-
const order = opener.attributes.map((attribute) => attribute.name).join(", ");
|
|
36491
|
-
return `This upload put the attributes of ${named} (line ${line}) in the order Dispatch stores: ${order}.`;
|
|
36492
|
-
}
|
|
36493
|
-
function attributesReordered(given, stored) {
|
|
36494
|
-
const written = withoutFinalLineFeed(given).split(`
|
|
36495
|
-
`);
|
|
36496
|
-
const holds = withoutFinalLineFeed(stored).split(`
|
|
36497
|
-
`);
|
|
36498
|
-
if (written.length !== holds.length)
|
|
36499
|
-
return;
|
|
36500
|
-
const lines = [];
|
|
36501
|
-
for (const [index, held] of holds.entries()) {
|
|
36502
|
-
const wrote = written[index];
|
|
36503
|
-
if (wrote === held)
|
|
36504
|
-
continue;
|
|
36505
|
-
const opener = headedOpener(held);
|
|
36506
|
-
if (wrote === undefined || opener === undefined || !onlyReordered(headedOpener(wrote), held, opener)) {
|
|
36507
|
-
return;
|
|
36508
|
-
}
|
|
36509
|
-
lines.push(reorderedBlockLine(index + 1, opener));
|
|
36510
|
-
}
|
|
36511
|
-
return lines;
|
|
36512
|
-
}
|
|
36513
|
-
var STORED_LINE_QUOTED = 200;
|
|
36514
|
-
function quotedStoredLine(characters, from) {
|
|
36515
|
-
const shown = characters.slice(from, from + STORED_LINE_QUOTED);
|
|
36516
|
-
const quote = JSON.stringify(shown.join(""));
|
|
36517
|
-
const cutAfter = from + shown.length < characters.length;
|
|
36518
|
-
if (from === 0 && !cutAfter)
|
|
36519
|
-
return quote;
|
|
36520
|
-
const cut = from === 0 ? "after" : cutAfter ? "before and after" : "before the last";
|
|
36521
|
-
return `${quote} (cut ${cut} ${shown.length} of its ${characters.length} characters)`;
|
|
36522
|
-
}
|
|
36523
|
-
function lineWords(line, opener) {
|
|
36524
|
-
const plain = (text) => (text.match(/\s+|\S+/g) ?? []).map((word) => ({ text: word, attribute: false }));
|
|
36525
|
-
if (opener === undefined)
|
|
36526
|
-
return plain(line);
|
|
36527
|
-
const words = plain(opener.head);
|
|
36528
|
-
for (const [index, gap] of opener.gaps.entries()) {
|
|
36529
|
-
if (gap !== "")
|
|
36530
|
-
words.push({ text: gap, attribute: false });
|
|
36531
|
-
const attribute = opener.attributes[index];
|
|
36532
|
-
if (attribute !== undefined)
|
|
36533
|
-
words.push({ text: attribute.text, attribute: true });
|
|
36534
|
-
}
|
|
36535
|
-
words.push({ text: "}", attribute: false });
|
|
36536
|
-
return words;
|
|
36537
|
-
}
|
|
36538
|
-
function wordText(word, from = 0, characters = Array.from(word.text)) {
|
|
36539
|
-
if (word.attribute)
|
|
36540
|
-
return `the attribute ${word.text}`;
|
|
36541
|
-
return `${/\S/.test(word.text) ? "the word" : "the space"} ${quotedStoredLine(characters, from)}`;
|
|
36542
|
-
}
|
|
36543
|
-
function wordDifference(written, holds) {
|
|
36544
|
-
let before = 0;
|
|
36545
|
-
for (let index = 0;index < Math.max(written.length, holds.length); index += 1) {
|
|
36546
|
-
const given = written[index];
|
|
36547
|
-
const stored = holds[index];
|
|
36548
|
-
if (given !== undefined && stored !== undefined && given.text === stored.text) {
|
|
36549
|
-
before += Array.from(given.text).length;
|
|
36550
|
-
continue;
|
|
36551
|
-
}
|
|
36552
|
-
if (given === undefined && stored !== undefined) {
|
|
36553
|
-
return `ends after character ${before}, where Dispatch goes on with ${wordText(stored)}`;
|
|
36554
|
-
}
|
|
36555
|
-
if (given !== undefined && stored === undefined) {
|
|
36556
|
-
return `reads ${wordText(given)} at character ${before + 1}, where Dispatch ends the line`;
|
|
36557
|
-
}
|
|
36558
|
-
if (given !== undefined && stored !== undefined) {
|
|
36559
|
-
const wrote = Array.from(given.text);
|
|
36560
|
-
const held = Array.from(stored.text);
|
|
36561
|
-
let from = 0;
|
|
36562
|
-
if (!given.attribute && !stored.attribute && Math.max(wrote.length, held.length) > STORED_LINE_QUOTED) {
|
|
36563
|
-
while (from < wrote.length && wrote[from] === held[from])
|
|
36564
|
-
from += 1;
|
|
36565
|
-
const tail = Math.max(0, from - STORED_LINE_QUOTED);
|
|
36566
|
-
if (from === wrote.length) {
|
|
36567
|
-
return `ends ${wordText(given, tail, wrote)} after character ${before + from}, where Dispatch goes on with ${wordText(stored, from, held)}`;
|
|
36568
|
-
}
|
|
36569
|
-
if (from === held.length) {
|
|
36570
|
-
return `reads ${wordText(given, from, wrote)} at character ${before + from + 1}, where Dispatch ends ${wordText(stored, tail, held)}`;
|
|
36571
|
-
}
|
|
36572
|
-
}
|
|
36573
|
-
return `reads ${wordText(given, from, wrote)} at character ${before + from + 1}, where Dispatch stores ${wordText(stored, from, held)}`;
|
|
36574
|
-
}
|
|
36575
|
-
}
|
|
36576
|
-
return "differs from the line Dispatch stores";
|
|
36577
|
-
}
|
|
36578
|
-
function attributeDifference(line, given, stored) {
|
|
36579
|
-
const written = attributesByName(given.attributes);
|
|
36580
|
-
if (written === undefined)
|
|
36581
|
-
return;
|
|
36582
|
-
for (const attribute of stored.attributes) {
|
|
36583
|
-
const text = written.get(attribute.name);
|
|
36584
|
-
if (text === undefined)
|
|
36585
|
-
return `Dispatch adds the attribute ${attribute.text} to line ${line}`;
|
|
36586
|
-
if (text !== attribute.text) {
|
|
36587
|
-
return `line ${line} holds the attribute ${text}, which Dispatch stores as ${attribute.text}`;
|
|
36588
|
-
}
|
|
36589
|
-
}
|
|
36590
|
-
const held = new Set(stored.attributes.map((attribute) => attribute.name));
|
|
36591
|
-
const dropped = given.attributes.find((attribute) => !held.has(attribute.name));
|
|
36592
|
-
return dropped === undefined ? undefined : `line ${line} holds the attribute ${dropped.text}, which Dispatch drops`;
|
|
36593
|
-
}
|
|
36594
|
-
function lineDifference(line, wrote, given, held, stored) {
|
|
36595
|
-
if (given === undefined || stored === undefined) {
|
|
36596
|
-
return `line ${line} ${wordDifference(lineWords(wrote, undefined), lineWords(held, undefined))}`;
|
|
36597
|
-
}
|
|
36598
|
-
const attribute = attributeDifference(line, given, stored);
|
|
36599
|
-
if (attribute !== undefined)
|
|
36600
|
-
return attribute;
|
|
36601
|
-
const reordered = inStoredOrder(given, stored);
|
|
36602
|
-
if (reordered !== undefined && reordered !== wrote) {
|
|
36603
|
-
const words = lineWords(reordered, headedOpener(reordered));
|
|
36604
|
-
return `line ${line}, with its attributes put in the order Dispatch stores, ${wordDifference(words, lineWords(held, stored))}`;
|
|
36605
|
-
}
|
|
36606
|
-
return `line ${line} ${wordDifference(lineWords(wrote, given), lineWords(held, stored))}`;
|
|
36607
|
-
}
|
|
36608
|
-
function firstStoredDifference(given, stored) {
|
|
36609
|
-
const written = given.split(`
|
|
36610
|
-
`);
|
|
36611
|
-
const holds = stored.split(`
|
|
36612
|
-
`);
|
|
36613
|
-
for (let line = 0;line < Math.max(written.length, holds.length); line += 1) {
|
|
36614
|
-
const wrote = written[line];
|
|
36615
|
-
const held = holds[line];
|
|
36616
|
-
if (wrote === held)
|
|
36617
|
-
continue;
|
|
36618
|
-
if (wrote === undefined && held !== undefined) {
|
|
36619
|
-
return `the store writes a line ${line + 1}, ${quotedStoredLine(Array.from(held), 0)}`;
|
|
36620
|
-
}
|
|
36621
|
-
if (held === undefined && wrote !== undefined) {
|
|
36622
|
-
return `the store drops line ${line + 1}, ${quotedStoredLine(Array.from(wrote), 0)}`;
|
|
36623
|
-
}
|
|
36624
|
-
if (wrote !== undefined && held !== undefined) {
|
|
36625
|
-
const givenOpener = headedOpener(wrote);
|
|
36626
|
-
const storedOpener = headedOpener(held);
|
|
36627
|
-
if (onlyReordered(givenOpener, held, storedOpener))
|
|
36628
|
-
continue;
|
|
36629
|
-
return lineDifference(line + 1, wrote, givenOpener, held, storedOpener);
|
|
36630
|
-
}
|
|
36631
|
-
}
|
|
36632
|
-
return "the stored text differs from the text given";
|
|
36633
|
-
}
|
|
36634
|
-
var STORED_TEXT_PRINTED = 2000;
|
|
36635
|
-
function storedTextPrinted(stored) {
|
|
36636
|
-
if (stored.length <= STORED_TEXT_PRINTED)
|
|
36637
|
-
return { text: stored, cut: "" };
|
|
36638
|
-
const head = stored.slice(0, STORED_TEXT_PRINTED);
|
|
36639
|
-
const lastLineFeed = head.lastIndexOf(`
|
|
36640
|
-
`);
|
|
36641
|
-
const text = lastLineFeed === -1 ? head : head.slice(0, lastLineFeed + 1);
|
|
36642
|
-
return {
|
|
36643
|
-
text,
|
|
36644
|
-
cut: ` The text below is cut after ${text.length} of its ${stored.length} characters: change the line named above and send the text again.`
|
|
36645
|
-
};
|
|
36646
|
-
}
|
|
36647
|
-
function storedTextProblem(given, stored, name) {
|
|
36648
|
-
const asBytes = pathKeepsBytesOf(name) ? ` To keep the text as you wrote it, send it as a file with ${PATH_KEEPS_BYTES}.` : "";
|
|
36649
|
-
const printed = storedTextPrinted(stored);
|
|
36650
|
-
return [
|
|
36651
|
-
`Dispatch stores this text under another spelling: ${firstStoredDifference(given, stored)}.`,
|
|
36652
|
-
` Send the text Dispatch stores, which is between the two marker lines below.${asBytes}`,
|
|
36653
|
-
`${printed.cut}
|
|
36654
|
-
--- the text Dispatch stores ---
|
|
36655
|
-
${printed.text}`,
|
|
36656
|
-
"--- end of the text Dispatch stores ---"
|
|
36657
|
-
].join("");
|
|
36658
|
-
}
|
|
36659
|
-
function withoutFinalLineFeed(text) {
|
|
36660
|
-
return text.endsWith(`
|
|
36661
|
-
`) ? text.slice(0, -1) : text;
|
|
36662
|
-
}
|
|
36663
|
-
function storedUpload(given, stored, name) {
|
|
36664
|
-
if (withoutFinalLineFeed(stored) === withoutFinalLineFeed(given)) {
|
|
36665
|
-
return { sent: given, reordered: [] };
|
|
36666
|
-
}
|
|
36667
|
-
const reordered = attributesReordered(given, stored);
|
|
36668
|
-
return reordered === undefined ? { refusal: storedTextProblem(given, stored, name) } : { sent: stored, reordered };
|
|
36669
|
-
}
|
|
36867
|
+
import { resolve as resolvePath3 } from "path";
|
|
36670
36868
|
|
|
36671
36869
|
// ../envoy-client/src/dispatch-commands/upload-checks.ts
|
|
36672
36870
|
function artifactUnderName(artifacts, name) {
|
|
@@ -36689,20 +36887,6 @@ function artifactNameExistsProblem(held, owner, upload) {
|
|
|
36689
36887
|
const wroteIt = authors.length === 0 ? actorText(held.created_by) : authors.join(" and ");
|
|
36690
36888
|
return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}) at version ${newest.number}, which ${wroteIt} wrote. ${rule}`;
|
|
36691
36889
|
}
|
|
36692
|
-
function storedTextCheckFailed(error, name) {
|
|
36693
|
-
if (error instanceof DispatchAnswerNotKeptError) {
|
|
36694
|
-
return `Dispatch could not say how it would store this text, so nothing was uploaded: POST /api/v1/markdown/round-trip wrote nothing, and Dispatch kept no copy of its answer (${error.code}). Send the upload again, which asks it under a new key.`;
|
|
36695
|
-
}
|
|
36696
|
-
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)}.`;
|
|
36697
|
-
if (!dispatchAnswered(error, 413)) {
|
|
36698
|
-
return `${failure} Send the upload again once that call is answered.`;
|
|
36699
|
-
}
|
|
36700
|
-
const asBytes = pathKeepsBytesOf(name) ? ` Send it as a file with ${PATH_KEEPS_BYTES}, which asks this check nothing.` : "";
|
|
36701
|
-
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}`;
|
|
36702
|
-
}
|
|
36703
|
-
function roundTripRouteAbsent(error) {
|
|
36704
|
-
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
36705
|
-
}
|
|
36706
36890
|
|
|
36707
36891
|
// ../envoy-client/src/dispatch-commands/documents.ts
|
|
36708
36892
|
async function blockAsks(client, resolved, state) {
|
|
@@ -37067,7 +37251,7 @@ async function planApproveCommand(context) {
|
|
|
37067
37251
|
};
|
|
37068
37252
|
}
|
|
37069
37253
|
async function artifactCommand(context) {
|
|
37070
|
-
const { args, client, actor, input, documentOwner, issue } = context;
|
|
37254
|
+
const { args, client, actor, input, documentOwner, issue, newClient } = context;
|
|
37071
37255
|
const summary = optionalString(args, "summary");
|
|
37072
37256
|
const name = stringArg(args, "name");
|
|
37073
37257
|
const content = optionalString(args, "content");
|
|
@@ -37080,40 +37264,40 @@ async function artifactCommand(context) {
|
|
|
37080
37264
|
actor
|
|
37081
37265
|
};
|
|
37082
37266
|
const artifactOwner = documentOwner();
|
|
37267
|
+
const force = optionalBoolean(args, "force") === true;
|
|
37083
37268
|
const blank = content === undefined || goBlankPattern.test(content);
|
|
37084
|
-
|
|
37269
|
+
const file = path === undefined ? undefined : uploadedFile(input.cwd, path);
|
|
37270
|
+
const heldBytes = input.uploadBytes === undefined ? undefined : new Uint8Array(input.uploadBytes);
|
|
37271
|
+
const documentBytes = file === undefined ? undefined : await documentFileBytes(file, heldBytes);
|
|
37272
|
+
const check = artifactTextCheck({
|
|
37273
|
+
tool: input.tool,
|
|
37274
|
+
name,
|
|
37275
|
+
content,
|
|
37276
|
+
bytes: documentBytes,
|
|
37277
|
+
force,
|
|
37278
|
+
textClient: () => client,
|
|
37279
|
+
fileClient: () => newClient(askOnceWithinDryRun())
|
|
37280
|
+
});
|
|
37281
|
+
const stored = await check?.();
|
|
37282
|
+
if (stored?.kind === "refused")
|
|
37283
|
+
throw stored.refusal;
|
|
37284
|
+
if (stored?.kind === "failed")
|
|
37285
|
+
throw storedTextCheckFailed(stored);
|
|
37286
|
+
if ((path !== undefined || !blank) && !force) {
|
|
37085
37287
|
const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
|
|
37086
37288
|
if (held !== undefined) {
|
|
37087
|
-
const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(
|
|
37289
|
+
const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(resolvePath3(input.cwd, named)) : Promise.resolve(input.uploadBytes.subarray(0, PICTURE_SNIFF_BYTES)));
|
|
37088
37290
|
throw new ToolInputError(input.tool, [
|
|
37089
37291
|
artifactNameExistsProblem(held, artifactOwner.kind === "project" ? `project ${artifactOwner.project}` : `issue ${issue()}`, kind)
|
|
37090
37292
|
]);
|
|
37091
37293
|
}
|
|
37092
37294
|
}
|
|
37093
|
-
|
|
37094
|
-
|
|
37095
|
-
|
|
37096
|
-
|
|
37097
|
-
try {
|
|
37098
|
-
stored = await client.markdownRoundTrip(content);
|
|
37099
|
-
} catch (error) {
|
|
37100
|
-
if (!roundTripRouteAbsent(error)) {
|
|
37101
|
-
throw new Error(storedTextCheckFailed(error, name), { cause: error });
|
|
37102
|
-
}
|
|
37103
|
-
}
|
|
37104
|
-
if (stored !== undefined) {
|
|
37105
|
-
const upload = storedUpload(content, stored, name);
|
|
37106
|
-
if ("refusal" in upload)
|
|
37107
|
-
throw new ToolInputError(input.tool, [upload.refusal]);
|
|
37108
|
-
sent = upload.sent;
|
|
37109
|
-
reordered = upload.reordered;
|
|
37110
|
-
}
|
|
37111
|
-
}
|
|
37112
|
-
const artifactInput = path !== undefined ? {
|
|
37295
|
+
const fileBytes = documentBytes ?? heldBytes;
|
|
37296
|
+
const sent = stored?.kind === "reordered" ? stored.sent : content;
|
|
37297
|
+
const reordered = stored?.kind === "reordered" ? stored.lines : [];
|
|
37298
|
+
const artifactInput = file !== undefined ? {
|
|
37113
37299
|
...options,
|
|
37114
|
-
file:
|
|
37115
|
-
type: Bun.file(resolvePath2(input.cwd, path)).type
|
|
37116
|
-
})
|
|
37300
|
+
file: fileBytes === undefined ? file : new Blob([fileBytes], { type: file.type })
|
|
37117
37301
|
} : sent !== undefined ? { ...options, content: sent } : options;
|
|
37118
37302
|
const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
|
|
37119
37303
|
const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
|
|
@@ -37141,6 +37325,59 @@ async function artifactCommand(context) {
|
|
|
37141
37325
|
}
|
|
37142
37326
|
};
|
|
37143
37327
|
}
|
|
37328
|
+
function endedSentence(text) {
|
|
37329
|
+
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
37330
|
+
}
|
|
37331
|
+
async function artifactDryRun(context) {
|
|
37332
|
+
const { tool, args, cwd, uploadBytes, client, deadline, deadlineMs } = context;
|
|
37333
|
+
const content = optionalString(args, "content");
|
|
37334
|
+
const path = optionalString(args, "path");
|
|
37335
|
+
let bytes;
|
|
37336
|
+
if (content === undefined && path !== undefined) {
|
|
37337
|
+
try {
|
|
37338
|
+
bytes = await documentFileBytes(uploadedFile(cwd, path), uploadBytes);
|
|
37339
|
+
} catch (error) {
|
|
37340
|
+
return {
|
|
37341
|
+
kind: "refused",
|
|
37342
|
+
refusal: error instanceof Error ? error : new Error(messageFor(error))
|
|
37343
|
+
};
|
|
37344
|
+
}
|
|
37345
|
+
}
|
|
37346
|
+
const check = artifactTextCheck({
|
|
37347
|
+
tool,
|
|
37348
|
+
name: stringArg(args, "name"),
|
|
37349
|
+
content,
|
|
37350
|
+
bytes,
|
|
37351
|
+
force: optionalBoolean(args, "force") === true,
|
|
37352
|
+
textClient: client,
|
|
37353
|
+
fileClient: client
|
|
37354
|
+
});
|
|
37355
|
+
if (check === undefined)
|
|
37356
|
+
return { kind: "passed" };
|
|
37357
|
+
const subject = content === undefined ? "the file" : "the text";
|
|
37358
|
+
const uploadsUnchecked = content === undefined ? "The call asks once more, and uploads the file unchecked if it gets no answer either." : "The call uploads the text unchecked.";
|
|
37359
|
+
const unasked = (why, then) => ({
|
|
37360
|
+
kind: "passed",
|
|
37361
|
+
warning: `dispatch: warning: the dry run could not ask Dispatch about ${subject}: ${endedSentence(why)} ${then}`
|
|
37362
|
+
});
|
|
37363
|
+
let stored;
|
|
37364
|
+
try {
|
|
37365
|
+
stored = await check();
|
|
37366
|
+
} catch (error) {
|
|
37367
|
+
return unasked(messageFor(error), "The call is refused for the same reason.");
|
|
37368
|
+
}
|
|
37369
|
+
if (stored.kind === "kept" || stored.kind === "reordered")
|
|
37370
|
+
return { kind: "passed" };
|
|
37371
|
+
if (stored.kind === "refused")
|
|
37372
|
+
return { kind: "refused", refusal: stored.refusal };
|
|
37373
|
+
if (stored.kind === "unchecked" && stored.routeAbsent) {
|
|
37374
|
+
return {
|
|
37375
|
+
kind: "passed",
|
|
37376
|
+
warning: `dispatch: warning: this Dispatch cannot check ${subject}: ${endedSentence(stored.failure)} ${uploadsUnchecked}`
|
|
37377
|
+
};
|
|
37378
|
+
}
|
|
37379
|
+
return unasked(deadline.aborted ? `Dispatch gave no answer within ${deadlineMs / 1000} s` : stored.failure, stored.kind === "unchecked" ? uploadsUnchecked : "The call refuses the upload until Dispatch answers.");
|
|
37380
|
+
}
|
|
37144
37381
|
|
|
37145
37382
|
// ../envoy-client/src/dispatch-commands/handoffs.ts
|
|
37146
37383
|
async function handoffWriteCommand(context) {
|
|
@@ -37699,7 +37936,7 @@ async function reviewCommand(context) {
|
|
|
37699
37936
|
}
|
|
37700
37937
|
|
|
37701
37938
|
// ../envoy-client/src/session-answers.ts
|
|
37702
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
37939
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync4 } from "fs";
|
|
37703
37940
|
import { join as join8 } from "path";
|
|
37704
37941
|
|
|
37705
37942
|
// ../envoy-client/src/json-line-record.ts
|
|
@@ -37840,7 +38077,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
37840
38077
|
var CACHE_FILE = "answers.json";
|
|
37841
38078
|
function readCacheFile(directory, url) {
|
|
37842
38079
|
try {
|
|
37843
|
-
const value = JSON.parse(
|
|
38080
|
+
const value = JSON.parse(readFileSync4(join8(directory, CACHE_FILE), "utf-8"));
|
|
37844
38081
|
if (typeof value === "object" && value !== null && "dispatch_url" in value && typeof value.dispatch_url === "string" && value.dispatch_url === url && "read_at" in value && typeof value.read_at === "string" && "total" in value && typeof value.total === "number" && "items" in value && Array.isArray(value.items)) {
|
|
37845
38082
|
return {
|
|
37846
38083
|
dispatch_url: value.dispatch_url,
|
|
@@ -38315,7 +38552,12 @@ var dispatchCommands = {
|
|
|
38315
38552
|
dispatch_review: acting(reviewCommand),
|
|
38316
38553
|
dispatch_result: acting(resultCommand),
|
|
38317
38554
|
dispatch_results: acting(resultsCommand),
|
|
38318
|
-
dispatch_artifact:
|
|
38555
|
+
dispatch_artifact: {
|
|
38556
|
+
...acting(artifactCommand),
|
|
38557
|
+
dryRun: artifactDryRun,
|
|
38558
|
+
documentFields: ["content"],
|
|
38559
|
+
documentPathField: "path"
|
|
38560
|
+
},
|
|
38319
38561
|
dispatch_handoff_write: acting(handoffWriteCommand),
|
|
38320
38562
|
dispatch_handoff_read: acting(handoffReadCommand),
|
|
38321
38563
|
dispatch_steps: acting(stepsCommand),
|
|
@@ -38327,6 +38569,63 @@ var dispatchCommands = {
|
|
|
38327
38569
|
dispatch_api: onSession(apiCommand),
|
|
38328
38570
|
dispatch_inbox: onSession(inboxCommand)
|
|
38329
38571
|
};
|
|
38572
|
+
|
|
38573
|
+
// ../envoy-client/src/dispatch-commands/command-context.ts
|
|
38574
|
+
function toolActor(origin, input) {
|
|
38575
|
+
return {
|
|
38576
|
+
kind: "session",
|
|
38577
|
+
id: input.sessionId ?? "unknown",
|
|
38578
|
+
origin: {
|
|
38579
|
+
...origin,
|
|
38580
|
+
host: input.host,
|
|
38581
|
+
...input.sessionTitle === undefined ? {} : { session_title: input.sessionTitle }
|
|
38582
|
+
}
|
|
38583
|
+
};
|
|
38584
|
+
}
|
|
38585
|
+
async function commandContext(session) {
|
|
38586
|
+
const { input, ownerArguments, pictures } = session;
|
|
38587
|
+
const actor = toolActor(await resolveOrigin(input.env ?? process.env, input.exec ?? defaultExec, input.cwd), input);
|
|
38588
|
+
const client = session.newClient();
|
|
38589
|
+
const { owner, documentOwner, resolveDocument } = await documentTargets(client, ownerArguments);
|
|
38590
|
+
const issueArgument = optionalString(input.args, "issue");
|
|
38591
|
+
const refText = optionalString(ownerArguments.args, "ref");
|
|
38592
|
+
if (input.tool !== "dispatch_ask" && owner?.kind === "issue" && issueArgument !== undefined && refText !== undefined && ownerArguments.ref?.owner.kind === "issue" && owner.issue !== ownerArguments.ref.owner.issue) {
|
|
38593
|
+
throw new ToolInputError(input.tool, [
|
|
38594
|
+
`issue ${issueArgument} and ref ${refText} name two owners; --ref ${refText} alone acts on ${ownerArguments.ref.owner.issue}, and --issue ${issueArgument} alone acts on ${owner.issue}`
|
|
38595
|
+
]);
|
|
38596
|
+
}
|
|
38597
|
+
const issue = () => {
|
|
38598
|
+
if (owner?.kind !== "issue")
|
|
38599
|
+
throw new Error("issue is required");
|
|
38600
|
+
return owner.issue;
|
|
38601
|
+
};
|
|
38602
|
+
const postWithPictures = (text, owner, upload) => textWithPictures(text, pictures, owner, (picture) => upload(picture).catch((error) => {
|
|
38603
|
+
if (!(error instanceof DispatchWriteLandedError))
|
|
38604
|
+
throw error;
|
|
38605
|
+
throw new Error(`${error.message} That was a picture uploaded before this call's own write, so nothing else was written: run the call again, which uploads it as its next version.`, { cause: error });
|
|
38606
|
+
}), actor);
|
|
38607
|
+
const writePictures = (resolved, text) => {
|
|
38608
|
+
if (resolved?.owner.kind === "project") {
|
|
38609
|
+
const { project } = resolved.owner;
|
|
38610
|
+
return postWithPictures(text, project, (upload) => client.projectArtifact(project, upload));
|
|
38611
|
+
}
|
|
38612
|
+
const issueKey = issue();
|
|
38613
|
+
return postWithPictures(text, issueKey, (upload) => client.artifact(issueKey, upload));
|
|
38614
|
+
};
|
|
38615
|
+
const { hostSession } = session;
|
|
38616
|
+
return {
|
|
38617
|
+
...session,
|
|
38618
|
+
client,
|
|
38619
|
+
actor,
|
|
38620
|
+
owner,
|
|
38621
|
+
documentOwner,
|
|
38622
|
+
resolveDocument,
|
|
38623
|
+
issue,
|
|
38624
|
+
postWithPictures,
|
|
38625
|
+
writePictures,
|
|
38626
|
+
shown: hostSession ? shownPictures(hostSession) : undefined
|
|
38627
|
+
};
|
|
38628
|
+
}
|
|
38330
38629
|
// ../envoy-client/src/dispatch-execute.ts
|
|
38331
38630
|
async function executeDispatchTool(input) {
|
|
38332
38631
|
const checked = await checkDispatchCall({
|
|
@@ -38336,7 +38635,7 @@ async function executeDispatchTool(input) {
|
|
|
38336
38635
|
if (checked.problems.length > 0)
|
|
38337
38636
|
throw new ToolInputError(input.tool, checked.problems);
|
|
38338
38637
|
if (input.dryRun === true && !dryRunAsksDispatch(input.tool, checked.args)) {
|
|
38339
|
-
throw new Error(`dispatch ${input.tool}'s dry run
|
|
38638
|
+
throw new Error(`dispatch ${input.tool}'s dry run runs no command`);
|
|
38340
38639
|
}
|
|
38341
38640
|
const command = dispatchCommands[input.tool];
|
|
38342
38641
|
if (command === undefined)
|
|
@@ -38354,7 +38653,7 @@ import {
|
|
|
38354
38653
|
mkdirSync as mkdirSync3,
|
|
38355
38654
|
openSync as openSync3,
|
|
38356
38655
|
readdirSync as readdirSync2,
|
|
38357
|
-
readFileSync as
|
|
38656
|
+
readFileSync as readFileSync5,
|
|
38358
38657
|
readSync as readSync2,
|
|
38359
38658
|
rmSync as rmSync3,
|
|
38360
38659
|
statSync as statSync2,
|
|
@@ -38377,7 +38676,7 @@ function ensureDirectory(dir) {
|
|
|
38377
38676
|
}
|
|
38378
38677
|
function readIfPresent(path) {
|
|
38379
38678
|
try {
|
|
38380
|
-
return
|
|
38679
|
+
return readFileSync5(path, "utf-8");
|
|
38381
38680
|
} catch (error) {
|
|
38382
38681
|
if (hasErrnoCode(error, "ENOENT"))
|
|
38383
38682
|
return;
|
|
@@ -38495,12 +38794,12 @@ function pruneSessions(root, now) {
|
|
|
38495
38794
|
|
|
38496
38795
|
// ../envoy-client/src/process-ancestry.ts
|
|
38497
38796
|
import { execFileSync } from "child_process";
|
|
38498
|
-
import { readFileSync as
|
|
38797
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
38499
38798
|
var MAX_ANCESTORS = 64;
|
|
38500
38799
|
var PARENT_LOOKUP_MS = 1000;
|
|
38501
38800
|
function procParentPid(pid) {
|
|
38502
38801
|
try {
|
|
38503
|
-
const stat =
|
|
38802
|
+
const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
|
|
38504
38803
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
38505
38804
|
return Number.isInteger(parent) ? parent : undefined;
|
|
38506
38805
|
} catch {
|
|
@@ -38542,7 +38841,7 @@ function isAncestor(candidate, pid = process.pid) {
|
|
|
38542
38841
|
}
|
|
38543
38842
|
function procCommand(pid) {
|
|
38544
38843
|
try {
|
|
38545
|
-
return
|
|
38844
|
+
return readFileSync6(`/proc/${pid}/comm`, "utf8").trim();
|
|
38546
38845
|
} catch {
|
|
38547
38846
|
return;
|
|
38548
38847
|
}
|
|
@@ -39199,6 +39498,9 @@ function stateWriteFailed(problem) {
|
|
|
39199
39498
|
}
|
|
39200
39499
|
var LITERAL_FORM = "AskGate reviews a Dispatch write, and lets it post, only when it is sent as one bash call of literal words: `dispatch <command> <words\u2026>`. Each word is plain text, text in single quotes (also over more than one line), or text in double quotes with no `$`, backtick or `\\`. A `\\` at the end of a line continues the command. Before it, one `cd <path> &&` is permitted; after it, one `2>&1`, one here-document opened with a quoted delimiter (`<<'EOF'`) and one `| head -n N` or `| tail -n N`. For text with `$` or a backtick in it, use `--<field>-file - <<'EOF'`. A variable, `~`, a glob, an assignment, another redirect (`2>/dev/null`, `> file`), another pipe, another command (`;`, `&&`, `||`), a loop, xargs, `bash -c`, a script, an alias, or a process that a program or an eval cell starts carries no marker.";
|
|
39201
39500
|
var SUBSCRIPTIONS_TIMEOUT_MS = 1500;
|
|
39501
|
+
function dispatchOffText(off) {
|
|
39502
|
+
return off.error === null ? off.notice : `dispatch config: ${off.error}`;
|
|
39503
|
+
}
|
|
39202
39504
|
function fitOutput(text, pictures, kept, limit, writeFull) {
|
|
39203
39505
|
const whole = [text, ...pictures, ...kept].join(`
|
|
39204
39506
|
`);
|
|
@@ -39313,6 +39615,30 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
39313
39615
|
`)}`, "Run dispatch --help."].join(`
|
|
39314
39616
|
`), USAGE) : refuse(new ToolInputError(parsed.tool, parsed.problems, defined("aboutAFlag", parsed.aboutAFlag)).message, USAGE, parsed.tool);
|
|
39315
39617
|
}
|
|
39618
|
+
const command = dispatchCommands[parsed.tool];
|
|
39619
|
+
const documentFields = command?.documentFields ?? [];
|
|
39620
|
+
if (parsed.kind === "unstorable") {
|
|
39621
|
+
const { tool, field, bytes } = parsed;
|
|
39622
|
+
const refusal = (documentFields.includes(field) ? documentBytesRefusal : unstorableBytes)(field, bytes);
|
|
39623
|
+
return refuse(messageFor(refusal), REFUSED, tool);
|
|
39624
|
+
}
|
|
39625
|
+
for (const field of documentFields) {
|
|
39626
|
+
const text = parsed.args[field];
|
|
39627
|
+
if (typeof text !== "string")
|
|
39628
|
+
continue;
|
|
39629
|
+
const refusal = documentFieldRefusal(field, text);
|
|
39630
|
+
if (refusal !== undefined)
|
|
39631
|
+
return refuse(messageFor(refusal), REFUSED, parsed.tool);
|
|
39632
|
+
}
|
|
39633
|
+
const uploadPath = command?.documentPathField === undefined ? undefined : parsed.args[command.documentPathField];
|
|
39634
|
+
let pathBytes;
|
|
39635
|
+
if (typeof uploadPath === "string") {
|
|
39636
|
+
const read = await documentFileRead(uploadedFile(io.cwd, uploadPath));
|
|
39637
|
+
if (read.kind === "refused")
|
|
39638
|
+
return refuse(messageFor(read.refusal), REFUSED, parsed.tool);
|
|
39639
|
+
if (read.kind === "passed")
|
|
39640
|
+
pathBytes = read.bytes;
|
|
39641
|
+
}
|
|
39316
39642
|
if (parsed.tool === "dispatch_api" && ledgerHost() === undefined) {
|
|
39317
39643
|
const { problems, args } = await checkDispatchCall({
|
|
39318
39644
|
tool: parsed.tool,
|
|
@@ -39361,20 +39687,52 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
39361
39687
|
return refuse(messageFor(error), USAGE, parsed.tool);
|
|
39362
39688
|
}
|
|
39363
39689
|
if (parsed.dryRun && !dryRunAsksDispatch(parsed.tool, parsed.args)) {
|
|
39364
|
-
const
|
|
39690
|
+
const resolved = await sessionDispatchSettings(file, env, {
|
|
39365
39691
|
cwd: io.cwd,
|
|
39366
39692
|
session: sessionId,
|
|
39367
39693
|
tokenFiles: true
|
|
39368
|
-
})
|
|
39369
|
-
const
|
|
39694
|
+
});
|
|
39695
|
+
const settings = resolved.dispatch;
|
|
39696
|
+
const checked = await checkDispatchCall({
|
|
39370
39697
|
tool: parsed.tool,
|
|
39371
39698
|
args: parsed.args,
|
|
39372
39699
|
cwd: io.cwd,
|
|
39373
39700
|
env,
|
|
39374
|
-
serverUrls: settings
|
|
39701
|
+
serverUrls: settings.enabled ? dispatchServerUrls(settings) : []
|
|
39375
39702
|
});
|
|
39376
|
-
if (problems.length > 0) {
|
|
39377
|
-
return refuse(new ToolInputError(parsed.tool, problems).message, USAGE, parsed.tool);
|
|
39703
|
+
if (checked.problems.length > 0) {
|
|
39704
|
+
return refuse(new ToolInputError(parsed.tool, checked.problems).message, USAGE, parsed.tool);
|
|
39705
|
+
}
|
|
39706
|
+
const step = command?.dryRun;
|
|
39707
|
+
if (step !== undefined && env.DISPATCH_DRY_RUN_LOCAL !== "1") {
|
|
39708
|
+
const deadlineMs = io.dryRunDeadlineMs ?? DRY_RUN_DEADLINE_MS;
|
|
39709
|
+
const deadline = AbortSignal.timeout(deadlineMs);
|
|
39710
|
+
const verdict = await step({
|
|
39711
|
+
tool: parsed.tool,
|
|
39712
|
+
args: checked.args,
|
|
39713
|
+
cwd: io.cwd,
|
|
39714
|
+
...defined("uploadBytes", pathBytes),
|
|
39715
|
+
deadline,
|
|
39716
|
+
deadlineMs,
|
|
39717
|
+
client: () => {
|
|
39718
|
+
for (const warning of resolved.warnings)
|
|
39719
|
+
io.stderr(`dispatch: ${warning}
|
|
39720
|
+
`);
|
|
39721
|
+
if (!settings.enabled) {
|
|
39722
|
+
throw new Error(file.path === null ? file.error : dispatchOffText(settings));
|
|
39723
|
+
}
|
|
39724
|
+
return new DispatchClient(settings.url, settings.credential, io.fetchImpl ?? fetch, {
|
|
39725
|
+
signal: deadline,
|
|
39726
|
+
...askOnceWithinDryRun(deadlineMs)
|
|
39727
|
+
});
|
|
39728
|
+
}
|
|
39729
|
+
});
|
|
39730
|
+
if (verdict.kind === "refused") {
|
|
39731
|
+
return refuse(messageFor(verdict.refusal), verdict.refusal instanceof ToolInputError ? USAGE : REFUSED, parsed.tool);
|
|
39732
|
+
}
|
|
39733
|
+
if (verdict.warning !== undefined)
|
|
39734
|
+
io.stderr(`${verdict.warning}
|
|
39735
|
+
`);
|
|
39378
39736
|
}
|
|
39379
39737
|
print(JSON.stringify(parsed.args, null, 2));
|
|
39380
39738
|
return OK;
|
|
@@ -39433,7 +39791,7 @@ ${result.text}`);
|
|
|
39433
39791
|
const fd = openSync4(operandPath(io.cwd, file), constants4.O_RDONLY | constants4.O_NONBLOCK);
|
|
39434
39792
|
try {
|
|
39435
39793
|
if (fstatSync3(fd).isFile())
|
|
39436
|
-
bytes =
|
|
39794
|
+
bytes = readFileSync7(fd);
|
|
39437
39795
|
} finally {
|
|
39438
39796
|
closeSync4(fd);
|
|
39439
39797
|
}
|
|
@@ -39509,7 +39867,7 @@ ${result.text}`);
|
|
|
39509
39867
|
tool,
|
|
39510
39868
|
args,
|
|
39511
39869
|
cwd: io.cwd,
|
|
39512
|
-
...uploadBytes
|
|
39870
|
+
...defined("uploadBytes", uploadBytes ?? pathBytes),
|
|
39513
39871
|
host,
|
|
39514
39872
|
sessionId,
|
|
39515
39873
|
sessionTitle: env.DISPATCH_SESSION_TITLE ?? readSessionTitle(dir),
|
|
@@ -39579,7 +39937,6 @@ ${result.text}`);
|
|
|
39579
39937
|
}
|
|
39580
39938
|
|
|
39581
39939
|
// ../envoy-client/bin/dispatch.ts
|
|
39582
|
-
var readText = (path) => readFileSync7(path === "-" ? 0 : path, "utf-8");
|
|
39583
39940
|
var pending = [];
|
|
39584
39941
|
var writeTo = (stream) => (chunk) => {
|
|
39585
39942
|
const { promise, resolve } = Promise.withResolvers();
|
|
@@ -39590,7 +39947,7 @@ var code = await runDispatchCli(Bun.argv.slice(2), process.env, {
|
|
|
39590
39947
|
stdout: writeTo(process.stdout),
|
|
39591
39948
|
stdoutBytes: writeTo(process.stdout),
|
|
39592
39949
|
stderr: writeTo(process.stderr),
|
|
39593
|
-
readText,
|
|
39950
|
+
readText: readFileText,
|
|
39594
39951
|
cwd: process.cwd()
|
|
39595
39952
|
});
|
|
39596
39953
|
await Promise.all(pending);
|