@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/codex-hook.js
CHANGED
|
@@ -13599,6 +13599,14 @@ var wholeIdPattern = /^(?:[0-9a-f]{32}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a
|
|
|
13599
13599
|
function isIdPrefix(value) {
|
|
13600
13600
|
return idPrefixPattern.test(value) && !wholeIdPattern.test(value);
|
|
13601
13601
|
}
|
|
13602
|
+
function utf8Bytes(value) {
|
|
13603
|
+
let bytes = 0;
|
|
13604
|
+
for (const character of value) {
|
|
13605
|
+
const code = character.codePointAt(0) ?? 0;
|
|
13606
|
+
bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
|
|
13607
|
+
}
|
|
13608
|
+
return bytes;
|
|
13609
|
+
}
|
|
13602
13610
|
var PLAIN_ISSUE_TABS = [
|
|
13603
13611
|
"verification",
|
|
13604
13612
|
"plan",
|
|
@@ -13861,6 +13869,9 @@ var ISSUE_LABEL_MAX = 40;
|
|
|
13861
13869
|
var MAX_ISSUE_COMPONENTS = 50;
|
|
13862
13870
|
var ISSUE_TITLE_MAX = 1000;
|
|
13863
13871
|
var PROJECT_NAME_MAX = 80;
|
|
13872
|
+
var MARKDOWN_DOCUMENT_MAX_BYTES = 1 << 20;
|
|
13873
|
+
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`;
|
|
13874
|
+
var TEXT_REFUSAL_HEADER = "Dispatch-Text-Refusal";
|
|
13864
13875
|
var MAX_ISSUE_PAGE_LIMIT = 250;
|
|
13865
13876
|
var DEFAULT_ISSUE_PAGE_LIMIT = 50;
|
|
13866
13877
|
var DEFAULT_ISSUE_READ_EVENTS = 10;
|
|
@@ -14157,6 +14168,7 @@ function artifactKindConflictRule(held, upload) {
|
|
|
14157
14168
|
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.`;
|
|
14158
14169
|
}
|
|
14159
14170
|
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}.`;
|
|
14171
|
+
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.`;
|
|
14160
14172
|
var NAME_EXTENSION = /\.([^\s.]+)$/u;
|
|
14161
14173
|
var MARKDOWN_EXTENSION = /^(md|markdown)$/i;
|
|
14162
14174
|
function preconditionArgument(z) {
|
|
@@ -14944,6 +14956,7 @@ var dispatchToolSpecs = [
|
|
|
14944
14956
|
},
|
|
14945
14957
|
{
|
|
14946
14958
|
name: "dispatch_result",
|
|
14959
|
+
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.",
|
|
14947
14960
|
example: {
|
|
14948
14961
|
issue: "DSP-1",
|
|
14949
14962
|
check: "k1",
|
|
@@ -14989,14 +15002,15 @@ var dispatchToolSpecs = [
|
|
|
14989
15002
|
name: "dispatch_artifact",
|
|
14990
15003
|
example: { issue: "DSP-1", name: "design.md", content: `# Design
|
|
14991
15004
|
` },
|
|
14992
|
-
|
|
15005
|
+
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.`,
|
|
15006
|
+
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}`,
|
|
14993
15007
|
arguments: (z) => ({
|
|
14994
15008
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
14995
15009
|
project: z.string().describe("Project key for an unlinked document.").optional(),
|
|
14996
15010
|
name: z.string().describe("Artifact filename shown in Dispatch."),
|
|
14997
15011
|
path: z.string().describe("Local path to the file to upload.").optional(),
|
|
14998
15012
|
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(),
|
|
14999
|
-
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(),
|
|
15013
|
+
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(),
|
|
15000
15014
|
precondition: uploadPreconditionArgument(z),
|
|
15001
15015
|
summary: z.string().describe("Optional version summary.").optional()
|
|
15002
15016
|
}),
|
|
@@ -19213,6 +19227,94 @@ function zodSchemaApi(zod) {
|
|
|
19213
19227
|
}
|
|
19214
19228
|
};
|
|
19215
19229
|
}
|
|
19230
|
+
// ../envoy-client/src/dispatch-file-text.ts
|
|
19231
|
+
import { isUtf8 } from "buffer";
|
|
19232
|
+
import { readFileSync } from "fs";
|
|
19233
|
+
var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
19234
|
+
var encoder2 = new TextEncoder;
|
|
19235
|
+
function byteText(byte) {
|
|
19236
|
+
return `0x${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
19237
|
+
}
|
|
19238
|
+
|
|
19239
|
+
class NotUtf8Error extends Error {
|
|
19240
|
+
bytes;
|
|
19241
|
+
name = "NotUtf8Error";
|
|
19242
|
+
constructor(bytes) {
|
|
19243
|
+
super("the bytes are not UTF-8");
|
|
19244
|
+
this.bytes = bytes;
|
|
19245
|
+
}
|
|
19246
|
+
}
|
|
19247
|
+
function firstNotUtf8(bytes) {
|
|
19248
|
+
for (let at = 0;at < bytes.length; ) {
|
|
19249
|
+
const lead = bytes[at];
|
|
19250
|
+
if (lead < 128) {
|
|
19251
|
+
at += 1;
|
|
19252
|
+
continue;
|
|
19253
|
+
}
|
|
19254
|
+
let width;
|
|
19255
|
+
let low = 128;
|
|
19256
|
+
let high = 191;
|
|
19257
|
+
if (lead >= 194 && lead <= 223) {
|
|
19258
|
+
width = 2;
|
|
19259
|
+
} else if (lead >= 224 && lead <= 239) {
|
|
19260
|
+
width = 3;
|
|
19261
|
+
if (lead === 224)
|
|
19262
|
+
low = 160;
|
|
19263
|
+
if (lead === 237)
|
|
19264
|
+
high = 159;
|
|
19265
|
+
} else if (lead >= 240 && lead <= 244) {
|
|
19266
|
+
width = 4;
|
|
19267
|
+
if (lead === 240)
|
|
19268
|
+
low = 144;
|
|
19269
|
+
if (lead === 244)
|
|
19270
|
+
high = 143;
|
|
19271
|
+
} else {
|
|
19272
|
+
return at;
|
|
19273
|
+
}
|
|
19274
|
+
if (at + width > bytes.length)
|
|
19275
|
+
return at;
|
|
19276
|
+
const second = bytes[at + 1];
|
|
19277
|
+
if (second < low || second > high)
|
|
19278
|
+
return at;
|
|
19279
|
+
for (let next = at + 2;next < at + width; next += 1) {
|
|
19280
|
+
if ((bytes[next] & 192) !== 128)
|
|
19281
|
+
return at;
|
|
19282
|
+
}
|
|
19283
|
+
at += width;
|
|
19284
|
+
}
|
|
19285
|
+
return -1;
|
|
19286
|
+
}
|
|
19287
|
+
function firstUnstorable(bytes) {
|
|
19288
|
+
const notUtf8 = isUtf8(bytes) ? -1 : firstNotUtf8(bytes);
|
|
19289
|
+
const nul = bytes.indexOf(0);
|
|
19290
|
+
const at = nul !== -1 && (notUtf8 === -1 || nul < notUtf8) ? nul : notUtf8;
|
|
19291
|
+
if (at === -1)
|
|
19292
|
+
return;
|
|
19293
|
+
return { byte: bytes[at], character: decoder.decode(bytes.subarray(0, at)).length + 1 };
|
|
19294
|
+
}
|
|
19295
|
+
function unstorableBytes(field, bytes) {
|
|
19296
|
+
const first = firstUnstorable(bytes);
|
|
19297
|
+
if (first === undefined)
|
|
19298
|
+
return;
|
|
19299
|
+
const { byte, character } = first;
|
|
19300
|
+
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`);
|
|
19301
|
+
}
|
|
19302
|
+
function utf8Text(bytes) {
|
|
19303
|
+
try {
|
|
19304
|
+
return decoder.decode(bytes);
|
|
19305
|
+
} catch (error) {
|
|
19306
|
+
if (isUtf8(bytes))
|
|
19307
|
+
throw error;
|
|
19308
|
+
throw new NotUtf8Error(bytes);
|
|
19309
|
+
}
|
|
19310
|
+
}
|
|
19311
|
+
function readFileText(path, readStdin = () => readFileSync(0)) {
|
|
19312
|
+
return utf8Text(path === "-" ? readStdin() : readFileSync(path));
|
|
19313
|
+
}
|
|
19314
|
+
function fileTextBytes(text) {
|
|
19315
|
+
return encoder2.encode(text);
|
|
19316
|
+
}
|
|
19317
|
+
|
|
19216
19318
|
// ../contracts/src/held-secrets.ts
|
|
19217
19319
|
var WITHHELD = "<withheld>";
|
|
19218
19320
|
var SCRUB_RUN = 10;
|
|
@@ -19491,6 +19593,7 @@ var PREFIXED_FLAGS = [
|
|
|
19491
19593
|
}
|
|
19492
19594
|
];
|
|
19493
19595
|
var STDIN = "-";
|
|
19596
|
+
var FILE_BYTES_RULE = "Bytes that are not UTF-8 are refused in Dispatch's own words, and nothing is sent.";
|
|
19494
19597
|
var BARE_WORD = /^[A-Za-z0-9_./:@%+=,-]+$/;
|
|
19495
19598
|
var OPTION_SEPARATOR = ": ";
|
|
19496
19599
|
var LOCAL_FILE_FIELD = { tool: "dispatch_artifact", field: "path" };
|
|
@@ -19533,7 +19636,7 @@ function surfaceFor(tool) {
|
|
|
19533
19636
|
spec,
|
|
19534
19637
|
command: commandName(spec.name),
|
|
19535
19638
|
fields,
|
|
19536
|
-
flags: flagTable(spec
|
|
19639
|
+
flags: flagTable(spec, fields)
|
|
19537
19640
|
};
|
|
19538
19641
|
surfaces.set(tool, surface);
|
|
19539
19642
|
return surface;
|
|
@@ -19654,11 +19757,11 @@ function placeholder(info) {
|
|
|
19654
19757
|
return info.kind.array === "string" ? "<text>" : "<n>";
|
|
19655
19758
|
return "<text>";
|
|
19656
19759
|
}
|
|
19657
|
-
function flagTable(
|
|
19760
|
+
function flagTable(spec, fields) {
|
|
19658
19761
|
const flags = new Map;
|
|
19659
19762
|
const add = (flag, entry) => {
|
|
19660
19763
|
if (flags.has(flag))
|
|
19661
|
-
throw new Error(`${
|
|
19764
|
+
throw new Error(`${spec.name}: two fields claim the flag ${flag}`);
|
|
19662
19765
|
flags.set(flag, entry);
|
|
19663
19766
|
};
|
|
19664
19767
|
for (const [field, info] of fields) {
|
|
@@ -19671,7 +19774,7 @@ function flagTable(tool, fields) {
|
|
|
19671
19774
|
field,
|
|
19672
19775
|
action: "file",
|
|
19673
19776
|
value: "<path>",
|
|
19674
|
-
text: `--${name} read from a file; - reads stdin
|
|
19777
|
+
text: `--${name} read from a file; - reads stdin. ${FILE_BYTES_RULE}`
|
|
19675
19778
|
});
|
|
19676
19779
|
} else if (kind === "number") {
|
|
19677
19780
|
add(`--${name}`, { field, action: "set", value: "<n>", text: about });
|
|
@@ -19704,7 +19807,7 @@ function flagTable(tool, fields) {
|
|
|
19704
19807
|
field,
|
|
19705
19808
|
action: "json-file",
|
|
19706
19809
|
value: "<path>",
|
|
19707
|
-
text: `--${name}-json read from a file; - reads stdin
|
|
19810
|
+
text: `--${name}-json read from a file; - reads stdin. ${FILE_BYTES_RULE}`
|
|
19708
19811
|
});
|
|
19709
19812
|
} else {
|
|
19710
19813
|
const none = kind.array === "number-or-null" ? " none is null." : "";
|
|
@@ -19715,10 +19818,10 @@ function flagTable(tool, fields) {
|
|
|
19715
19818
|
text: `${about} One item per flag, repeated.${none}`.trim()
|
|
19716
19819
|
});
|
|
19717
19820
|
for (const prefixed of PREFIXED_FLAGS) {
|
|
19718
|
-
if (prefixed.tool !==
|
|
19821
|
+
if (prefixed.tool !== spec.name || prefixed.field !== field)
|
|
19719
19822
|
continue;
|
|
19720
19823
|
if (kind.array !== "string") {
|
|
19721
|
-
throw new Error(`${
|
|
19824
|
+
throw new Error(`${spec.name}: ${prefixed.flag} needs ${field} to be a list of text`);
|
|
19722
19825
|
}
|
|
19723
19826
|
add(prefixed.flag, {
|
|
19724
19827
|
field,
|
|
@@ -19740,7 +19843,7 @@ function flagTable(tool, fields) {
|
|
|
19740
19843
|
add("--help", { action: "help", text: "Prints this help." });
|
|
19741
19844
|
add("--dry-run", {
|
|
19742
19845
|
action: "dry-run",
|
|
19743
|
-
text:
|
|
19846
|
+
text: spec.dryRunHelp ?? "Checks the arguments as the call would, then prints them as JSON and sends nothing."
|
|
19744
19847
|
});
|
|
19745
19848
|
return flags;
|
|
19746
19849
|
}
|
|
@@ -19764,7 +19867,8 @@ function parseCommand(argv, io) {
|
|
|
19764
19867
|
let help = false;
|
|
19765
19868
|
let dryRun = false;
|
|
19766
19869
|
let stdinFlag;
|
|
19767
|
-
|
|
19870
|
+
let unstorable;
|
|
19871
|
+
const read = (flag, field, path) => {
|
|
19768
19872
|
if (path === STDIN) {
|
|
19769
19873
|
if (stdinFlag !== undefined) {
|
|
19770
19874
|
problems.push(`${stdinFlag} and ${flag} both read stdin (-); only one flag can`);
|
|
@@ -19775,6 +19879,11 @@ function parseCommand(argv, io) {
|
|
|
19775
19879
|
try {
|
|
19776
19880
|
return io.readText(path);
|
|
19777
19881
|
} catch (error) {
|
|
19882
|
+
if (error instanceof NotUtf8Error) {
|
|
19883
|
+
claim(field, flag, false);
|
|
19884
|
+
unstorable ??= { field, bytes: error.bytes };
|
|
19885
|
+
return;
|
|
19886
|
+
}
|
|
19778
19887
|
problems.push(`${flag} could not read ${path === STDIN ? "stdin" : path}: ${messageFor(error)}`);
|
|
19779
19888
|
return;
|
|
19780
19889
|
}
|
|
@@ -19885,14 +19994,14 @@ function parseCommand(argv, io) {
|
|
|
19885
19994
|
break;
|
|
19886
19995
|
}
|
|
19887
19996
|
case "file": {
|
|
19888
|
-
const text = read(flag, value);
|
|
19997
|
+
const text = read(flag, field, value);
|
|
19889
19998
|
if (text !== undefined && claim(field, flag, false))
|
|
19890
19999
|
args[field] = text;
|
|
19891
20000
|
break;
|
|
19892
20001
|
}
|
|
19893
20002
|
case "json":
|
|
19894
20003
|
case "json-file": {
|
|
19895
|
-
const text = action === "json" ? value : read(flag, value);
|
|
20004
|
+
const text = action === "json" ? value : read(flag, field, value);
|
|
19896
20005
|
const parsed = text === undefined ? undefined : json(flag, text);
|
|
19897
20006
|
if (parsed !== undefined && claim(field, flag, false))
|
|
19898
20007
|
args[field] = parsed.value;
|
|
@@ -19928,6 +20037,8 @@ function parseCommand(argv, io) {
|
|
|
19928
20037
|
if (problems.length > 0) {
|
|
19929
20038
|
return problems.length === bareDashes.size ? { kind: "refused", tool, problems, aboutAFlag: false } : { kind: "refused", tool, problems };
|
|
19930
20039
|
}
|
|
20040
|
+
if (unstorable !== undefined)
|
|
20041
|
+
return { kind: "unstorable", tool, ...unstorable };
|
|
19931
20042
|
return { kind: "call", tool, args, dryRun };
|
|
19932
20043
|
}
|
|
19933
20044
|
function appendedItem(kind, flag, value, number) {
|
|
@@ -20027,7 +20138,7 @@ function commandsHelp() {
|
|
|
20027
20138
|
return ` ${commandName(spec.name).padEnd(width)} ${sentence}`;
|
|
20028
20139
|
}),
|
|
20029
20140
|
"",
|
|
20030
|
-
"Run dispatch <command> --help for its flags and an example
|
|
20141
|
+
"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.",
|
|
20031
20142
|
"",
|
|
20032
20143
|
"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).",
|
|
20033
20144
|
""
|
|
@@ -22111,13 +22222,13 @@ var customFetch = Symbol();
|
|
|
22111
22222
|
var modifyAssertion = Symbol();
|
|
22112
22223
|
var jweDecrypt = Symbol();
|
|
22113
22224
|
var jwksCache = Symbol();
|
|
22114
|
-
var
|
|
22115
|
-
var
|
|
22225
|
+
var encoder3 = new TextEncoder;
|
|
22226
|
+
var decoder2 = new TextDecoder;
|
|
22116
22227
|
function buf(input) {
|
|
22117
22228
|
if (typeof input === "string") {
|
|
22118
|
-
return
|
|
22229
|
+
return encoder3.encode(input);
|
|
22119
22230
|
}
|
|
22120
|
-
return
|
|
22231
|
+
return decoder2.decode(input);
|
|
22121
22232
|
}
|
|
22122
22233
|
var encodeBase64Url;
|
|
22123
22234
|
if (Uint8Array.prototype.toBase64) {
|
|
@@ -22985,8 +23096,8 @@ var _nodiscoverycheck = Symbol();
|
|
|
22985
23096
|
var _expectedIssuer = Symbol();
|
|
22986
23097
|
|
|
22987
23098
|
// ../../node_modules/.bun/jose@6.2.9/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
22988
|
-
var
|
|
22989
|
-
var
|
|
23099
|
+
var encoder4 = new TextEncoder;
|
|
23100
|
+
var decoder3 = new TextDecoder;
|
|
22990
23101
|
var strictDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
22991
23102
|
var MAX_INT32 = 2 ** 32;
|
|
22992
23103
|
function concat(...buffers) {
|
|
@@ -23130,7 +23241,7 @@ var invalid = "The input to be decoded is not correctly encoded.";
|
|
|
23130
23241
|
function decode4(input) {
|
|
23131
23242
|
if (Uint8Array.fromBase64) {
|
|
23132
23243
|
try {
|
|
23133
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input :
|
|
23244
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder3.decode(input), {
|
|
23134
23245
|
alphabet: "base64url"
|
|
23135
23246
|
});
|
|
23136
23247
|
} catch (cause) {
|
|
@@ -23139,7 +23250,7 @@ function decode4(input) {
|
|
|
23139
23250
|
}
|
|
23140
23251
|
let encoded = input;
|
|
23141
23252
|
if (encoded instanceof Uint8Array) {
|
|
23142
|
-
encoded =
|
|
23253
|
+
encoded = decoder3.decode(encoded);
|
|
23143
23254
|
}
|
|
23144
23255
|
if (encoded.includes("+") || encoded.includes("/")) {
|
|
23145
23256
|
throw new TypeError(invalid);
|
|
@@ -23154,7 +23265,7 @@ function decode4(input) {
|
|
|
23154
23265
|
function encode5(input) {
|
|
23155
23266
|
let unencoded = input;
|
|
23156
23267
|
if (typeof unencoded === "string") {
|
|
23157
|
-
unencoded =
|
|
23268
|
+
unencoded = encoder4.encode(unencoded);
|
|
23158
23269
|
}
|
|
23159
23270
|
if (Uint8Array.prototype.toBase64) {
|
|
23160
23271
|
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
@@ -23443,7 +23554,7 @@ class ClientError extends Error {
|
|
|
23443
23554
|
Error.captureStackTrace?.(this, this.constructor);
|
|
23444
23555
|
}
|
|
23445
23556
|
}
|
|
23446
|
-
var
|
|
23557
|
+
var decoder4 = new TextDecoder;
|
|
23447
23558
|
function e(msg, cause, code) {
|
|
23448
23559
|
return new ClientError(msg, { cause, code });
|
|
23449
23560
|
}
|
|
@@ -24964,6 +25075,7 @@ class DispatchServiceError extends Error {
|
|
|
24964
25075
|
mismatches;
|
|
24965
25076
|
issues;
|
|
24966
25077
|
changed;
|
|
25078
|
+
textRefusal;
|
|
24967
25079
|
hint;
|
|
24968
25080
|
constructor(code, status, message, details = {}) {
|
|
24969
25081
|
super(message);
|
|
@@ -24974,6 +25086,7 @@ class DispatchServiceError extends Error {
|
|
|
24974
25086
|
this.mismatches = details.mismatches;
|
|
24975
25087
|
this.issues = details.issues;
|
|
24976
25088
|
this.changed = details.changed;
|
|
25089
|
+
this.textRefusal = details.textRefusal ?? false;
|
|
24977
25090
|
this.hint = details.hint;
|
|
24978
25091
|
}
|
|
24979
25092
|
}
|
|
@@ -25254,7 +25367,8 @@ function answerEvent(answer, requestKey, keyEchoed, canTellDeadToken) {
|
|
|
25254
25367
|
if (status === 404 && answer.code === "NOT_FOUND" && answer.error?.startsWith(NO_ROUTE_MESSAGE_PREFIX) === true) {
|
|
25255
25368
|
return "no-route";
|
|
25256
25369
|
}
|
|
25257
|
-
|
|
25370
|
+
const textRefusal = answer.error !== undefined && answer.response.headers.has(TEXT_REFUSAL_HEADER);
|
|
25371
|
+
if (!textRefusal && retriesUnderKey(status, answer.code)) {
|
|
25258
25372
|
if (status === 409)
|
|
25259
25373
|
return "in-flight";
|
|
25260
25374
|
return status >= 500 ? "server-error" : "try-later";
|
|
@@ -25403,8 +25517,15 @@ class DispatchClient {
|
|
|
25403
25517
|
async listIssueArtifacts(issue) {
|
|
25404
25518
|
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "artifacts"]);
|
|
25405
25519
|
}
|
|
25406
|
-
async markdownRoundTrip(markdown) {
|
|
25407
|
-
|
|
25520
|
+
async markdownRoundTrip(markdown, newDocument) {
|
|
25521
|
+
return this.#roundTrip(["api", "v1", "markdown", "round-trip"], { markdown }, newDocument);
|
|
25522
|
+
}
|
|
25523
|
+
async fileRoundTrip(bytes, newDocument) {
|
|
25524
|
+
const file = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
25525
|
+
return this.#roundTrip(["api", "v1", "markdown", "file-round-trip"], { file }, newDocument);
|
|
25526
|
+
}
|
|
25527
|
+
async#roundTrip(path, body, newDocument) {
|
|
25528
|
+
const answer = await this.#writingNothing(path, newDocument ? { ...body, new_document: true } : body, { writes: false });
|
|
25408
25529
|
return answer.markdown;
|
|
25409
25530
|
}
|
|
25410
25531
|
async listProjectArtifacts(project, unlinked = false) {
|
|
@@ -26258,7 +26379,10 @@ class DispatchClient {
|
|
|
26258
26379
|
if (response.status === 409 && refusal.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
26259
26380
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
26260
26381
|
}
|
|
26261
|
-
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error,
|
|
26382
|
+
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error, {
|
|
26383
|
+
...refusal,
|
|
26384
|
+
textRefusal: response.headers.has(TEXT_REFUSAL_HEADER)
|
|
26385
|
+
});
|
|
26262
26386
|
}
|
|
26263
26387
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
26264
26388
|
}
|
|
@@ -26898,7 +27022,7 @@ var DISPATCH_BOOKKEEPING = new Set([
|
|
|
26898
27022
|
"references_changed_truncated_kinds",
|
|
26899
27023
|
"rank"
|
|
26900
27024
|
]);
|
|
26901
|
-
function dispatchPayloadForReader(event, sessionID, issuedAt) {
|
|
27025
|
+
function dispatchPayloadForReader(event, sessionID, issuedAt, toReader) {
|
|
26902
27026
|
const whole = dispatchPayload(event);
|
|
26903
27027
|
const changed = event.type !== "issue.created" && isObject3(whole) && Array.isArray(whole["changed"]) ? whole["changed"] : [];
|
|
26904
27028
|
const payload = withoutEmptyFields(whole, (key, item) => changed.includes(key) || (key === "suggestion" || key === "forced") && item !== null && item !== undefined);
|
|
@@ -26911,6 +27035,7 @@ function dispatchPayloadForReader(event, sessionID, issuedAt) {
|
|
|
26911
27035
|
case "issue_key":
|
|
26912
27036
|
return value === event.issue_key;
|
|
26913
27037
|
case "author":
|
|
27038
|
+
case "actor":
|
|
26914
27039
|
return isObject3(value) && Object.entries(value).every(([field, held]) => isDeepStrictEqual(held, actor[field]));
|
|
26915
27040
|
case "created_at": {
|
|
26916
27041
|
if (typeof value !== "string")
|
|
@@ -26921,6 +27046,8 @@ function dispatchPayloadForReader(event, sessionID, issuedAt) {
|
|
|
26921
27046
|
case "thread_root_id":
|
|
26922
27047
|
case "answers":
|
|
26923
27048
|
return typeof replyTo === "string" && value === replyTo;
|
|
27049
|
+
case "target":
|
|
27050
|
+
return toReader && value === `session:${sessionID}`;
|
|
26924
27051
|
default:
|
|
26925
27052
|
return DISPATCH_BOOKKEEPING.has(key);
|
|
26926
27053
|
}
|
|
@@ -27120,6 +27247,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27120
27247
|
let payloadSessions = [];
|
|
27121
27248
|
let trailer = "";
|
|
27122
27249
|
const at = inboundTimestamp(envelope.issued_at);
|
|
27250
|
+
const toReader = envelope.topic !== undefined && topicForms(envelope.topic).includes(legacyAgentSubject(sessionID));
|
|
27123
27251
|
const dispatchRendered = envelope.source === "dispatch" && envelope.payload !== undefined;
|
|
27124
27252
|
if (envelope.source === "dispatch") {
|
|
27125
27253
|
const topic = subject ?? envelope.topic;
|
|
@@ -27225,15 +27353,16 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27225
27353
|
ask: dispatchReplyRef(frame.event, topic, compact.askId, commentPayload),
|
|
27226
27354
|
...compact.record
|
|
27227
27355
|
};
|
|
27228
|
-
const payload = compactRecord === undefined ? dispatchPayloadForReader(frame.event, sessionID, envelope.issued_at) : undefined;
|
|
27356
|
+
const payload = compactRecord === undefined ? dispatchPayloadForReader(frame.event, sessionID, envelope.issued_at, toReader) : undefined;
|
|
27229
27357
|
let actor = frame.event.actor;
|
|
27230
27358
|
if ("origin" in frame.event.actor) {
|
|
27231
27359
|
const { origin, ...rest } = frame.event.actor;
|
|
27232
27360
|
const title = isObject3(origin) ? origin["session_title"] : undefined;
|
|
27233
27361
|
actor = typeof title === "string" && title !== "" ? { ...rest, origin: { session_title: title } } : rest;
|
|
27234
27362
|
}
|
|
27363
|
+
const owner = dispatchOwner(frame.event, topic);
|
|
27235
27364
|
dispatchEvent = {
|
|
27236
|
-
owner:
|
|
27365
|
+
...owner === "unknown" ? {} : { owner },
|
|
27237
27366
|
type: frame.event.type,
|
|
27238
27367
|
actor,
|
|
27239
27368
|
...relation === undefined ? {} : { relation },
|
|
@@ -27288,7 +27417,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
27288
27417
|
...dispatchIssue === undefined ? [] : [dispatchIssue]
|
|
27289
27418
|
].join(", ") || undefined;
|
|
27290
27419
|
const rendered = {
|
|
27291
|
-
...
|
|
27420
|
+
...toReader ? { to: `you (${sessionID})` } : {},
|
|
27292
27421
|
from: senderLabel(envelope),
|
|
27293
27422
|
at,
|
|
27294
27423
|
id: envelope.event_id ?? "unknown",
|
|
@@ -27833,6 +27962,10 @@ function linkFor(href, linkBase) {
|
|
|
27833
27962
|
}
|
|
27834
27963
|
|
|
27835
27964
|
// ../envoy-client/src/dispatch-commands/context.ts
|
|
27965
|
+
var DRY_RUN_DEADLINE_MS = 5000;
|
|
27966
|
+
function askOnceWithinDryRun(deadlineMs = DRY_RUN_DEADLINE_MS) {
|
|
27967
|
+
return { deadlineMs, retryNoRoute: false, writeRetry: { ...DISPATCH_WRITE_RETRY, pausesMs: [] } };
|
|
27968
|
+
}
|
|
27836
27969
|
function stringArg(args, name) {
|
|
27837
27970
|
const value = args[name];
|
|
27838
27971
|
if (typeof value !== "string")
|
|
@@ -27910,10 +28043,11 @@ function sessionContext(input, checked) {
|
|
|
27910
28043
|
configUrl,
|
|
27911
28044
|
linkBase: linkBaseOf(input.config.publicUrl ?? url),
|
|
27912
28045
|
hostSession: input.sessionId?.trim(),
|
|
27913
|
-
newClient: () => new DispatchClient(url, credential, fetchImpl, {
|
|
28046
|
+
newClient: (options = {}) => new DispatchClient(url, credential, fetchImpl, {
|
|
27914
28047
|
signal: input.signal,
|
|
27915
28048
|
writeRetry: input.writeRetry,
|
|
27916
|
-
sleep: input.sleep
|
|
28049
|
+
sleep: input.sleep,
|
|
28050
|
+
...options
|
|
27917
28051
|
})
|
|
27918
28052
|
};
|
|
27919
28053
|
}
|
|
@@ -30541,7 +30675,7 @@ import {
|
|
|
30541
30675
|
mkdirSync,
|
|
30542
30676
|
openSync,
|
|
30543
30677
|
readdirSync,
|
|
30544
|
-
readFileSync,
|
|
30678
|
+
readFileSync as readFileSync2,
|
|
30545
30679
|
readlinkSync,
|
|
30546
30680
|
renameSync,
|
|
30547
30681
|
rmSync,
|
|
@@ -30616,7 +30750,7 @@ function bytesDigest(bytes) {
|
|
|
30616
30750
|
}
|
|
30617
30751
|
function processStart(pid) {
|
|
30618
30752
|
try {
|
|
30619
|
-
const stat =
|
|
30753
|
+
const stat = readFileSync2(`/proc/${pid}/stat`, "utf-8");
|
|
30620
30754
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19] ?? null;
|
|
30621
30755
|
} catch {
|
|
30622
30756
|
return null;
|
|
@@ -30721,7 +30855,7 @@ function recordNamesStore(dir) {
|
|
|
30721
30855
|
if (!name.endsWith(OWNER_FILE))
|
|
30722
30856
|
continue;
|
|
30723
30857
|
try {
|
|
30724
|
-
const parsed = parseOwner(
|
|
30858
|
+
const parsed = parseOwner(readFileSync2(join3(record, name), "utf-8"));
|
|
30725
30859
|
if (parsed === undefined)
|
|
30726
30860
|
return true;
|
|
30727
30861
|
statSync(parsed.owner.store);
|
|
@@ -30750,7 +30884,7 @@ function askgateState(dir, now = Date.now()) {
|
|
|
30750
30884
|
const file = join3(record, name);
|
|
30751
30885
|
let text;
|
|
30752
30886
|
try {
|
|
30753
|
-
text =
|
|
30887
|
+
text = readFileSync2(file, "utf-8");
|
|
30754
30888
|
} catch (error) {
|
|
30755
30889
|
if (hasErrnoCode(error, "ENOENT"))
|
|
30756
30890
|
continue;
|
|
@@ -30788,7 +30922,7 @@ function readMarker(file) {
|
|
|
30788
30922
|
try {
|
|
30789
30923
|
const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
30790
30924
|
try {
|
|
30791
|
-
text =
|
|
30925
|
+
text = readFileSync2(fd, "utf-8");
|
|
30792
30926
|
} finally {
|
|
30793
30927
|
closeSync(fd);
|
|
30794
30928
|
}
|
|
@@ -30953,6 +31087,7 @@ var WRITE_ROUTES = [
|
|
|
30953
31087
|
{ method: "POST", pattern: "/api/v1/issues/{key}/artifacts", commands: ["artifact"] },
|
|
30954
31088
|
{ method: "POST", pattern: "/api/v1/projects/{key}/artifacts", commands: ["artifact"] },
|
|
30955
31089
|
{ method: "POST", pattern: "/api/v1/markdown/round-trip", commands: ["artifact"] },
|
|
31090
|
+
{ method: "POST", pattern: "/api/v1/markdown/file-round-trip", commands: ["artifact"] },
|
|
30956
31091
|
{ method: "POST", pattern: "/api/v1/projects", commands: ["project"] },
|
|
30957
31092
|
{
|
|
30958
31093
|
method: "PUT",
|
|
@@ -31890,6 +32025,9 @@ async function sendToAgentCommand(context) {
|
|
|
31890
32025
|
}
|
|
31891
32026
|
|
|
31892
32027
|
// ../envoy-client/src/dispatch-commands/documents.ts
|
|
32028
|
+
import { resolve as resolvePath3 } from "path";
|
|
32029
|
+
|
|
32030
|
+
// ../envoy-client/src/dispatch-commands/stored-text.ts
|
|
31893
32031
|
import { resolve as resolvePath2 } from "path";
|
|
31894
32032
|
|
|
31895
32033
|
// ../envoy-client/src/typed-block-opener.ts
|
|
@@ -32277,6 +32415,126 @@ function storedUpload(given, stored, name) {
|
|
|
32277
32415
|
return reordered === undefined ? { refusal: storedTextProblem(given, stored, name) } : { sent: stored, reordered };
|
|
32278
32416
|
}
|
|
32279
32417
|
|
|
32418
|
+
// ../envoy-client/src/dispatch-commands/stored-text.ts
|
|
32419
|
+
var MARKDOWN_ROUND_TRIP = "POST /api/v1/markdown/round-trip";
|
|
32420
|
+
var FILE_ROUND_TRIP = "POST /api/v1/markdown/file-round-trip";
|
|
32421
|
+
function storedTextCheckFailed(failed) {
|
|
32422
|
+
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.";
|
|
32423
|
+
return new Error(`Dispatch could not say how it would store this text, so nothing was uploaded: ${failed.failure}. ${again}`, { cause: failed.error });
|
|
32424
|
+
}
|
|
32425
|
+
function roundTripRouteAbsent(error) {
|
|
32426
|
+
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
32427
|
+
}
|
|
32428
|
+
function documentTooLarge(measured) {
|
|
32429
|
+
const bytes = typeof measured === "number" ? measured : typeof measured === "string" ? utf8Bytes(measured) : measured.byteLength;
|
|
32430
|
+
return bytes > MARKDOWN_DOCUMENT_MAX_BYTES ? new Error(`CAP_EXCEEDED: ${MARKDOWN_DOCUMENT_TOO_LARGE}`) : undefined;
|
|
32431
|
+
}
|
|
32432
|
+
function documentBytesRefusal(field, bytes) {
|
|
32433
|
+
return documentTooLarge(bytes) ?? unstorableBytes(field, bytes);
|
|
32434
|
+
}
|
|
32435
|
+
function documentFieldRefusal(field, text) {
|
|
32436
|
+
return Buffer.byteLength(text, "utf8") > MARKDOWN_DOCUMENT_MAX_BYTES || text.includes("\x00") ? documentBytesRefusal(field, fileTextBytes(text)) : undefined;
|
|
32437
|
+
}
|
|
32438
|
+
function uploadedFile(cwd, path) {
|
|
32439
|
+
return Bun.file(resolvePath2(cwd, path));
|
|
32440
|
+
}
|
|
32441
|
+
async function documentFileRead(file, held) {
|
|
32442
|
+
if (file.type.split(";", 1)[0]?.trim().toLowerCase() !== "text/markdown") {
|
|
32443
|
+
return { kind: "passed", bytes: undefined };
|
|
32444
|
+
}
|
|
32445
|
+
let bytes = held;
|
|
32446
|
+
if (bytes === undefined) {
|
|
32447
|
+
const stats = await file.stat().catch(() => {
|
|
32448
|
+
return;
|
|
32449
|
+
});
|
|
32450
|
+
if (stats !== undefined && !stats.isFile() && !stats.isDirectory()) {
|
|
32451
|
+
return { kind: "passed", bytes: undefined };
|
|
32452
|
+
}
|
|
32453
|
+
const tooLarge = stats === undefined ? undefined : documentTooLarge(stats.size);
|
|
32454
|
+
if (tooLarge !== undefined)
|
|
32455
|
+
return { kind: "refused", refusal: tooLarge };
|
|
32456
|
+
try {
|
|
32457
|
+
bytes = await file.bytes();
|
|
32458
|
+
} catch (error) {
|
|
32459
|
+
return { kind: "unread", error };
|
|
32460
|
+
}
|
|
32461
|
+
}
|
|
32462
|
+
const refusal = documentBytesRefusal("file", bytes);
|
|
32463
|
+
return refusal === undefined ? { kind: "passed", bytes } : { kind: "refused", refusal };
|
|
32464
|
+
}
|
|
32465
|
+
async function documentFileBytes(file, held) {
|
|
32466
|
+
const read = await documentFileRead(file, held);
|
|
32467
|
+
if (read.kind === "refused")
|
|
32468
|
+
throw read.refusal;
|
|
32469
|
+
if (read.kind === "unread")
|
|
32470
|
+
throw read.error;
|
|
32471
|
+
return read.bytes;
|
|
32472
|
+
}
|
|
32473
|
+
function unchecked(answer) {
|
|
32474
|
+
return { kind: "unchecked", failure: answer.failure, routeAbsent: answer.routeAbsent };
|
|
32475
|
+
}
|
|
32476
|
+
async function askRoundTrip(client, route, ask) {
|
|
32477
|
+
const dispatch = client();
|
|
32478
|
+
try {
|
|
32479
|
+
return { kind: "stored", stored: await ask(dispatch) };
|
|
32480
|
+
} catch (error) {
|
|
32481
|
+
const routeAbsent = roundTripRouteAbsent(error);
|
|
32482
|
+
if (!routeAbsent && error instanceof DispatchServiceError && error.textRefusal) {
|
|
32483
|
+
return { kind: "refused", refusal: error };
|
|
32484
|
+
}
|
|
32485
|
+
return {
|
|
32486
|
+
kind: "unanswered",
|
|
32487
|
+
failure: error instanceof DispatchAnswerNotKeptError ? `${route} wrote nothing, and Dispatch kept no copy of its answer (${error.code})` : `${route} failed with ${messageFor(error)}`,
|
|
32488
|
+
error,
|
|
32489
|
+
routeAbsent
|
|
32490
|
+
};
|
|
32491
|
+
}
|
|
32492
|
+
}
|
|
32493
|
+
async function storedTextCheck(client, tool, name, content, force) {
|
|
32494
|
+
const tooLarge = documentTooLarge(content);
|
|
32495
|
+
if (tooLarge !== undefined)
|
|
32496
|
+
return { kind: "refused", refusal: tooLarge };
|
|
32497
|
+
if (content === "")
|
|
32498
|
+
return { kind: "kept" };
|
|
32499
|
+
const answer = await askRoundTrip(client, MARKDOWN_ROUND_TRIP, (dispatch) => dispatch.markdownRoundTrip(content, !force));
|
|
32500
|
+
const blank = goBlankPattern.test(content);
|
|
32501
|
+
switch (answer.kind) {
|
|
32502
|
+
case "refused":
|
|
32503
|
+
return answer;
|
|
32504
|
+
case "unanswered":
|
|
32505
|
+
return blank || answer.routeAbsent ? unchecked(answer) : { kind: "failed", failure: answer.failure, error: answer.error };
|
|
32506
|
+
case "stored": {
|
|
32507
|
+
if (blank)
|
|
32508
|
+
return { kind: "kept" };
|
|
32509
|
+
const upload = storedUpload(content, answer.stored, name);
|
|
32510
|
+
if ("refusal" in upload) {
|
|
32511
|
+
return { kind: "refused", refusal: new ToolInputError(tool, [upload.refusal]) };
|
|
32512
|
+
}
|
|
32513
|
+
return upload.reordered.length === 0 ? { kind: "kept" } : { kind: "reordered", sent: upload.sent, lines: upload.reordered };
|
|
32514
|
+
}
|
|
32515
|
+
}
|
|
32516
|
+
}
|
|
32517
|
+
async function storedFileCheck(client, bytes, force) {
|
|
32518
|
+
const answer = await askRoundTrip(client, FILE_ROUND_TRIP, (dispatch) => dispatch.fileRoundTrip(bytes, !force));
|
|
32519
|
+
switch (answer.kind) {
|
|
32520
|
+
case "stored":
|
|
32521
|
+
return { kind: "kept" };
|
|
32522
|
+
case "refused":
|
|
32523
|
+
return answer;
|
|
32524
|
+
case "unanswered":
|
|
32525
|
+
return unchecked(answer);
|
|
32526
|
+
}
|
|
32527
|
+
}
|
|
32528
|
+
function artifactTextCheck(upload) {
|
|
32529
|
+
const { tool, name, content, bytes, force } = upload;
|
|
32530
|
+
if (content !== undefined) {
|
|
32531
|
+
return () => storedTextCheck(upload.textClient, tool, name, content, force);
|
|
32532
|
+
}
|
|
32533
|
+
if (bytes !== undefined)
|
|
32534
|
+
return () => storedFileCheck(upload.fileClient, bytes, force);
|
|
32535
|
+
return;
|
|
32536
|
+
}
|
|
32537
|
+
|
|
32280
32538
|
// ../envoy-client/src/dispatch-commands/upload-checks.ts
|
|
32281
32539
|
function artifactUnderName(artifacts, name) {
|
|
32282
32540
|
const written = name.trim();
|
|
@@ -32298,20 +32556,6 @@ function artifactNameExistsProblem(held, owner, upload) {
|
|
|
32298
32556
|
const wroteIt = authors.length === 0 ? actorText(held.created_by) : authors.join(" and ");
|
|
32299
32557
|
return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}) at version ${newest.number}, which ${wroteIt} wrote. ${rule}`;
|
|
32300
32558
|
}
|
|
32301
|
-
function storedTextCheckFailed(error, name) {
|
|
32302
|
-
if (error instanceof DispatchAnswerNotKeptError) {
|
|
32303
|
-
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.`;
|
|
32304
|
-
}
|
|
32305
|
-
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)}.`;
|
|
32306
|
-
if (!dispatchAnswered(error, 413)) {
|
|
32307
|
-
return `${failure} Send the upload again once that call is answered.`;
|
|
32308
|
-
}
|
|
32309
|
-
const asBytes = pathKeepsBytesOf(name) ? ` Send it as a file with ${PATH_KEEPS_BYTES}, which asks this check nothing.` : "";
|
|
32310
|
-
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}`;
|
|
32311
|
-
}
|
|
32312
|
-
function roundTripRouteAbsent(error) {
|
|
32313
|
-
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
32314
|
-
}
|
|
32315
32559
|
|
|
32316
32560
|
// ../envoy-client/src/dispatch-commands/documents.ts
|
|
32317
32561
|
async function blockAsks(client, resolved, state) {
|
|
@@ -32676,7 +32920,7 @@ async function planApproveCommand(context) {
|
|
|
32676
32920
|
};
|
|
32677
32921
|
}
|
|
32678
32922
|
async function artifactCommand(context) {
|
|
32679
|
-
const { args, client, actor, input, documentOwner, issue } = context;
|
|
32923
|
+
const { args, client, actor, input, documentOwner, issue, newClient } = context;
|
|
32680
32924
|
const summary = optionalString(args, "summary");
|
|
32681
32925
|
const name = stringArg(args, "name");
|
|
32682
32926
|
const content = optionalString(args, "content");
|
|
@@ -32689,40 +32933,40 @@ async function artifactCommand(context) {
|
|
|
32689
32933
|
actor
|
|
32690
32934
|
};
|
|
32691
32935
|
const artifactOwner = documentOwner();
|
|
32936
|
+
const force = optionalBoolean(args, "force") === true;
|
|
32692
32937
|
const blank = content === undefined || goBlankPattern.test(content);
|
|
32693
|
-
|
|
32938
|
+
const file = path === undefined ? undefined : uploadedFile(input.cwd, path);
|
|
32939
|
+
const heldBytes = input.uploadBytes === undefined ? undefined : new Uint8Array(input.uploadBytes);
|
|
32940
|
+
const documentBytes = file === undefined ? undefined : await documentFileBytes(file, heldBytes);
|
|
32941
|
+
const check = artifactTextCheck({
|
|
32942
|
+
tool: input.tool,
|
|
32943
|
+
name,
|
|
32944
|
+
content,
|
|
32945
|
+
bytes: documentBytes,
|
|
32946
|
+
force,
|
|
32947
|
+
textClient: () => client,
|
|
32948
|
+
fileClient: () => newClient(askOnceWithinDryRun())
|
|
32949
|
+
});
|
|
32950
|
+
const stored = await check?.();
|
|
32951
|
+
if (stored?.kind === "refused")
|
|
32952
|
+
throw stored.refusal;
|
|
32953
|
+
if (stored?.kind === "failed")
|
|
32954
|
+
throw storedTextCheckFailed(stored);
|
|
32955
|
+
if ((path !== undefined || !blank) && !force) {
|
|
32694
32956
|
const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
|
|
32695
32957
|
if (held !== undefined) {
|
|
32696
|
-
const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(
|
|
32958
|
+
const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(resolvePath3(input.cwd, named)) : Promise.resolve(input.uploadBytes.subarray(0, PICTURE_SNIFF_BYTES)));
|
|
32697
32959
|
throw new ToolInputError(input.tool, [
|
|
32698
32960
|
artifactNameExistsProblem(held, artifactOwner.kind === "project" ? `project ${artifactOwner.project}` : `issue ${issue()}`, kind)
|
|
32699
32961
|
]);
|
|
32700
32962
|
}
|
|
32701
32963
|
}
|
|
32702
|
-
|
|
32703
|
-
|
|
32704
|
-
|
|
32705
|
-
|
|
32706
|
-
try {
|
|
32707
|
-
stored = await client.markdownRoundTrip(content);
|
|
32708
|
-
} catch (error) {
|
|
32709
|
-
if (!roundTripRouteAbsent(error)) {
|
|
32710
|
-
throw new Error(storedTextCheckFailed(error, name), { cause: error });
|
|
32711
|
-
}
|
|
32712
|
-
}
|
|
32713
|
-
if (stored !== undefined) {
|
|
32714
|
-
const upload = storedUpload(content, stored, name);
|
|
32715
|
-
if ("refusal" in upload)
|
|
32716
|
-
throw new ToolInputError(input.tool, [upload.refusal]);
|
|
32717
|
-
sent = upload.sent;
|
|
32718
|
-
reordered = upload.reordered;
|
|
32719
|
-
}
|
|
32720
|
-
}
|
|
32721
|
-
const artifactInput = path !== undefined ? {
|
|
32964
|
+
const fileBytes = documentBytes ?? heldBytes;
|
|
32965
|
+
const sent = stored?.kind === "reordered" ? stored.sent : content;
|
|
32966
|
+
const reordered = stored?.kind === "reordered" ? stored.lines : [];
|
|
32967
|
+
const artifactInput = file !== undefined ? {
|
|
32722
32968
|
...options,
|
|
32723
|
-
file:
|
|
32724
|
-
type: Bun.file(resolvePath2(input.cwd, path)).type
|
|
32725
|
-
})
|
|
32969
|
+
file: fileBytes === undefined ? file : new Blob([fileBytes], { type: file.type })
|
|
32726
32970
|
} : sent !== undefined ? { ...options, content: sent } : options;
|
|
32727
32971
|
const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
|
|
32728
32972
|
const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
|
|
@@ -32750,6 +32994,59 @@ async function artifactCommand(context) {
|
|
|
32750
32994
|
}
|
|
32751
32995
|
};
|
|
32752
32996
|
}
|
|
32997
|
+
function endedSentence(text) {
|
|
32998
|
+
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
32999
|
+
}
|
|
33000
|
+
async function artifactDryRun(context) {
|
|
33001
|
+
const { tool, args, cwd, uploadBytes, client, deadline, deadlineMs } = context;
|
|
33002
|
+
const content = optionalString(args, "content");
|
|
33003
|
+
const path = optionalString(args, "path");
|
|
33004
|
+
let bytes;
|
|
33005
|
+
if (content === undefined && path !== undefined) {
|
|
33006
|
+
try {
|
|
33007
|
+
bytes = await documentFileBytes(uploadedFile(cwd, path), uploadBytes);
|
|
33008
|
+
} catch (error) {
|
|
33009
|
+
return {
|
|
33010
|
+
kind: "refused",
|
|
33011
|
+
refusal: error instanceof Error ? error : new Error(messageFor(error))
|
|
33012
|
+
};
|
|
33013
|
+
}
|
|
33014
|
+
}
|
|
33015
|
+
const check = artifactTextCheck({
|
|
33016
|
+
tool,
|
|
33017
|
+
name: stringArg(args, "name"),
|
|
33018
|
+
content,
|
|
33019
|
+
bytes,
|
|
33020
|
+
force: optionalBoolean(args, "force") === true,
|
|
33021
|
+
textClient: client,
|
|
33022
|
+
fileClient: client
|
|
33023
|
+
});
|
|
33024
|
+
if (check === undefined)
|
|
33025
|
+
return { kind: "passed" };
|
|
33026
|
+
const subject = content === undefined ? "the file" : "the text";
|
|
33027
|
+
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.";
|
|
33028
|
+
const unasked = (why, then) => ({
|
|
33029
|
+
kind: "passed",
|
|
33030
|
+
warning: `dispatch: warning: the dry run could not ask Dispatch about ${subject}: ${endedSentence(why)} ${then}`
|
|
33031
|
+
});
|
|
33032
|
+
let stored;
|
|
33033
|
+
try {
|
|
33034
|
+
stored = await check();
|
|
33035
|
+
} catch (error) {
|
|
33036
|
+
return unasked(messageFor(error), "The call is refused for the same reason.");
|
|
33037
|
+
}
|
|
33038
|
+
if (stored.kind === "kept" || stored.kind === "reordered")
|
|
33039
|
+
return { kind: "passed" };
|
|
33040
|
+
if (stored.kind === "refused")
|
|
33041
|
+
return { kind: "refused", refusal: stored.refusal };
|
|
33042
|
+
if (stored.kind === "unchecked" && stored.routeAbsent) {
|
|
33043
|
+
return {
|
|
33044
|
+
kind: "passed",
|
|
33045
|
+
warning: `dispatch: warning: this Dispatch cannot check ${subject}: ${endedSentence(stored.failure)} ${uploadsUnchecked}`
|
|
33046
|
+
};
|
|
33047
|
+
}
|
|
33048
|
+
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.");
|
|
33049
|
+
}
|
|
32753
33050
|
|
|
32754
33051
|
// ../envoy-client/src/dispatch-commands/handoffs.ts
|
|
32755
33052
|
async function handoffWriteCommand(context) {
|
|
@@ -33308,7 +33605,7 @@ async function reviewCommand(context) {
|
|
|
33308
33605
|
}
|
|
33309
33606
|
|
|
33310
33607
|
// ../envoy-client/src/session-answers.ts
|
|
33311
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
33608
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
|
|
33312
33609
|
import { join as join5 } from "path";
|
|
33313
33610
|
|
|
33314
33611
|
// ../envoy-client/src/json-line-record.ts
|
|
@@ -33449,7 +33746,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
33449
33746
|
var CACHE_FILE = "answers.json";
|
|
33450
33747
|
function readCacheFile(directory, url) {
|
|
33451
33748
|
try {
|
|
33452
|
-
const value = JSON.parse(
|
|
33749
|
+
const value = JSON.parse(readFileSync3(join5(directory, CACHE_FILE), "utf-8"));
|
|
33453
33750
|
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)) {
|
|
33454
33751
|
return {
|
|
33455
33752
|
dispatch_url: value.dispatch_url,
|
|
@@ -33924,7 +34221,12 @@ var dispatchCommands = {
|
|
|
33924
34221
|
dispatch_review: acting(reviewCommand),
|
|
33925
34222
|
dispatch_result: acting(resultCommand),
|
|
33926
34223
|
dispatch_results: acting(resultsCommand),
|
|
33927
|
-
dispatch_artifact:
|
|
34224
|
+
dispatch_artifact: {
|
|
34225
|
+
...acting(artifactCommand),
|
|
34226
|
+
dryRun: artifactDryRun,
|
|
34227
|
+
documentFields: ["content"],
|
|
34228
|
+
documentPathField: "path"
|
|
34229
|
+
},
|
|
33928
34230
|
dispatch_handoff_write: acting(handoffWriteCommand),
|
|
33929
34231
|
dispatch_handoff_read: acting(handoffReadCommand),
|
|
33930
34232
|
dispatch_steps: acting(stepsCommand),
|
|
@@ -33945,7 +34247,7 @@ async function executeDispatchTool(input) {
|
|
|
33945
34247
|
if (checked.problems.length > 0)
|
|
33946
34248
|
throw new ToolInputError(input.tool, checked.problems);
|
|
33947
34249
|
if (input.dryRun === true && !dryRunAsksDispatch(input.tool, checked.args)) {
|
|
33948
|
-
throw new Error(`dispatch ${input.tool}'s dry run
|
|
34250
|
+
throw new Error(`dispatch ${input.tool}'s dry run runs no command`);
|
|
33949
34251
|
}
|
|
33950
34252
|
const command = dispatchCommands[input.tool];
|
|
33951
34253
|
if (command === undefined)
|
|
@@ -36558,14 +36860,14 @@ function brokerCredential(env, session, read) {
|
|
|
36558
36860
|
}
|
|
36559
36861
|
|
|
36560
36862
|
// ../envoy-client/src/file-token-credential.ts
|
|
36561
|
-
import { readFileSync as
|
|
36863
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
36562
36864
|
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
36563
36865
|
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
36564
36866
|
var PKCS8_LABEL = "PRIVATE KEY";
|
|
36565
36867
|
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
36566
36868
|
function readNamed(variable, filePath) {
|
|
36567
36869
|
try {
|
|
36568
|
-
return
|
|
36870
|
+
return readFileSync4(filePath, "utf8");
|
|
36569
36871
|
} catch (error) {
|
|
36570
36872
|
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
36571
36873
|
}
|
|
@@ -37570,7 +37872,7 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
37570
37872
|
|
|
37571
37873
|
// src/codex/codex-session-record.ts
|
|
37572
37874
|
import { spawnSync } from "child_process";
|
|
37573
|
-
import { readFileSync as
|
|
37875
|
+
import { readFileSync as readFileSync6, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
|
|
37574
37876
|
import { mkdir as mkdir3, readFile as readFile8, rename as rename4, utimes as utimes3, writeFile as writeFile2 } from "fs/promises";
|
|
37575
37877
|
import { homedir as homedir3 } from "os";
|
|
37576
37878
|
import { basename as basename4, dirname as dirname5, join as join11 } from "path";
|
|
@@ -37580,7 +37882,7 @@ import { readFile as readFile7 } from "fs/promises";
|
|
|
37580
37882
|
import { basename as basename3, join as join10 } from "path";
|
|
37581
37883
|
|
|
37582
37884
|
// src/session-state.ts
|
|
37583
|
-
import { readFileSync as
|
|
37885
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
37584
37886
|
import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
|
|
37585
37887
|
import { dirname as dirname4, join as join9 } from "path";
|
|
37586
37888
|
async function writeAtomicStateFile(file, contents) {
|
|
@@ -37626,7 +37928,7 @@ async function removeChosenTitle(file) {
|
|
|
37626
37928
|
}
|
|
37627
37929
|
function readChosenTitleSync(file) {
|
|
37628
37930
|
try {
|
|
37629
|
-
return
|
|
37931
|
+
return readFileSync5(file, "utf8");
|
|
37630
37932
|
} catch {
|
|
37631
37933
|
return;
|
|
37632
37934
|
}
|
|
@@ -37819,14 +38121,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
37819
38121
|
}
|
|
37820
38122
|
function procComm(pid) {
|
|
37821
38123
|
try {
|
|
37822
|
-
return
|
|
38124
|
+
return readFileSync6(`/proc/${pid}/comm`, "utf8").trim();
|
|
37823
38125
|
} catch {
|
|
37824
38126
|
return;
|
|
37825
38127
|
}
|
|
37826
38128
|
}
|
|
37827
38129
|
function procParent(pid) {
|
|
37828
38130
|
try {
|
|
37829
|
-
const stat =
|
|
38131
|
+
const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
|
|
37830
38132
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
37831
38133
|
return Number.isInteger(parent) ? parent : undefined;
|
|
37832
38134
|
} catch {
|
|
@@ -37840,7 +38142,7 @@ var PS_OPTIONS = {
|
|
|
37840
38142
|
};
|
|
37841
38143
|
function procStarted(pid) {
|
|
37842
38144
|
try {
|
|
37843
|
-
const stat =
|
|
38145
|
+
const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
|
|
37844
38146
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
37845
38147
|
} catch {
|
|
37846
38148
|
return;
|
|
@@ -37861,7 +38163,7 @@ function recordOfProcess(record, pid) {
|
|
|
37861
38163
|
function sharedAppServer(pid) {
|
|
37862
38164
|
let argv;
|
|
37863
38165
|
try {
|
|
37864
|
-
argv =
|
|
38166
|
+
argv = readFileSync6(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
37865
38167
|
} catch {
|
|
37866
38168
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
37867
38169
|
if (ps.status !== 0)
|