@sjawhar/claude-envoy 6.2.0 → 6.2.1
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 +385 -88
- package/dist/dispatch.js +712 -360
- package/dist/envoy-channel.js +393 -96
- package/dist/session-hook.js +381 -84
- package/package.json +1 -1
package/dist/session-hook.js
CHANGED
|
@@ -980,7 +980,7 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// hooks/session-hook.ts
|
|
983
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as
|
|
983
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync8, rmSync as rmSync3, statSync as statSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
984
984
|
import { join as join13 } from "path";
|
|
985
985
|
|
|
986
986
|
// ../cipher-client/src/device-login-file.ts
|
|
@@ -17124,6 +17124,14 @@ var wholeIdPattern = /^(?:[0-9a-f]{32}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a
|
|
|
17124
17124
|
function isIdPrefix(value) {
|
|
17125
17125
|
return idPrefixPattern.test(value) && !wholeIdPattern.test(value);
|
|
17126
17126
|
}
|
|
17127
|
+
function utf8Bytes(value) {
|
|
17128
|
+
let bytes = 0;
|
|
17129
|
+
for (const character of value) {
|
|
17130
|
+
const code = character.codePointAt(0) ?? 0;
|
|
17131
|
+
bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
|
|
17132
|
+
}
|
|
17133
|
+
return bytes;
|
|
17134
|
+
}
|
|
17127
17135
|
var PLAIN_ISSUE_TABS = [
|
|
17128
17136
|
"verification",
|
|
17129
17137
|
"plan",
|
|
@@ -17386,6 +17394,9 @@ var ISSUE_LABEL_MAX = 40;
|
|
|
17386
17394
|
var MAX_ISSUE_COMPONENTS = 50;
|
|
17387
17395
|
var ISSUE_TITLE_MAX = 1000;
|
|
17388
17396
|
var PROJECT_NAME_MAX = 80;
|
|
17397
|
+
var MARKDOWN_DOCUMENT_MAX_BYTES = 1 << 20;
|
|
17398
|
+
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`;
|
|
17399
|
+
var TEXT_REFUSAL_HEADER = "Dispatch-Text-Refusal";
|
|
17389
17400
|
var MAX_ISSUE_PAGE_LIMIT = 250;
|
|
17390
17401
|
var DEFAULT_ISSUE_PAGE_LIMIT = 50;
|
|
17391
17402
|
var DEFAULT_ISSUE_READ_EVENTS = 10;
|
|
@@ -17682,6 +17693,7 @@ function artifactKindConflictRule(held, upload) {
|
|
|
17682
17693
|
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.`;
|
|
17683
17694
|
}
|
|
17684
17695
|
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}.`;
|
|
17696
|
+
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.`;
|
|
17685
17697
|
var NAME_EXTENSION = /\.([^\s.]+)$/u;
|
|
17686
17698
|
var MARKDOWN_EXTENSION = /^(md|markdown)$/i;
|
|
17687
17699
|
function preconditionArgument(z) {
|
|
@@ -18469,6 +18481,7 @@ var dispatchToolSpecs = [
|
|
|
18469
18481
|
},
|
|
18470
18482
|
{
|
|
18471
18483
|
name: "dispatch_result",
|
|
18484
|
+
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.",
|
|
18472
18485
|
example: {
|
|
18473
18486
|
issue: "DSP-1",
|
|
18474
18487
|
check: "k1",
|
|
@@ -18514,14 +18527,15 @@ var dispatchToolSpecs = [
|
|
|
18514
18527
|
name: "dispatch_artifact",
|
|
18515
18528
|
example: { issue: "DSP-1", name: "design.md", content: `# Design
|
|
18516
18529
|
` },
|
|
18517
|
-
|
|
18530
|
+
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.`,
|
|
18531
|
+
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}`,
|
|
18518
18532
|
arguments: (z) => ({
|
|
18519
18533
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
18520
18534
|
project: z.string().describe("Project key for an unlinked document.").optional(),
|
|
18521
18535
|
name: z.string().describe("Artifact filename shown in Dispatch."),
|
|
18522
18536
|
path: z.string().describe("Local path to the file to upload.").optional(),
|
|
18523
18537
|
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(),
|
|
18524
|
-
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(),
|
|
18538
|
+
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(),
|
|
18525
18539
|
precondition: uploadPreconditionArgument(z),
|
|
18526
18540
|
summary: z.string().describe("Optional version summary.").optional()
|
|
18527
18541
|
}),
|
|
@@ -22738,6 +22752,94 @@ function zodSchemaApi(zod) {
|
|
|
22738
22752
|
}
|
|
22739
22753
|
};
|
|
22740
22754
|
}
|
|
22755
|
+
// ../envoy-client/src/dispatch-file-text.ts
|
|
22756
|
+
import { isUtf8 } from "buffer";
|
|
22757
|
+
import { readFileSync } from "fs";
|
|
22758
|
+
var decoder4 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
22759
|
+
var encoder4 = new TextEncoder;
|
|
22760
|
+
function byteText(byte) {
|
|
22761
|
+
return `0x${byte.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
22762
|
+
}
|
|
22763
|
+
|
|
22764
|
+
class NotUtf8Error extends Error {
|
|
22765
|
+
bytes;
|
|
22766
|
+
name = "NotUtf8Error";
|
|
22767
|
+
constructor(bytes) {
|
|
22768
|
+
super("the bytes are not UTF-8");
|
|
22769
|
+
this.bytes = bytes;
|
|
22770
|
+
}
|
|
22771
|
+
}
|
|
22772
|
+
function firstNotUtf8(bytes) {
|
|
22773
|
+
for (let at = 0;at < bytes.length; ) {
|
|
22774
|
+
const lead = bytes[at];
|
|
22775
|
+
if (lead < 128) {
|
|
22776
|
+
at += 1;
|
|
22777
|
+
continue;
|
|
22778
|
+
}
|
|
22779
|
+
let width;
|
|
22780
|
+
let low = 128;
|
|
22781
|
+
let high = 191;
|
|
22782
|
+
if (lead >= 194 && lead <= 223) {
|
|
22783
|
+
width = 2;
|
|
22784
|
+
} else if (lead >= 224 && lead <= 239) {
|
|
22785
|
+
width = 3;
|
|
22786
|
+
if (lead === 224)
|
|
22787
|
+
low = 160;
|
|
22788
|
+
if (lead === 237)
|
|
22789
|
+
high = 159;
|
|
22790
|
+
} else if (lead >= 240 && lead <= 244) {
|
|
22791
|
+
width = 4;
|
|
22792
|
+
if (lead === 240)
|
|
22793
|
+
low = 144;
|
|
22794
|
+
if (lead === 244)
|
|
22795
|
+
high = 143;
|
|
22796
|
+
} else {
|
|
22797
|
+
return at;
|
|
22798
|
+
}
|
|
22799
|
+
if (at + width > bytes.length)
|
|
22800
|
+
return at;
|
|
22801
|
+
const second = bytes[at + 1];
|
|
22802
|
+
if (second < low || second > high)
|
|
22803
|
+
return at;
|
|
22804
|
+
for (let next = at + 2;next < at + width; next += 1) {
|
|
22805
|
+
if ((bytes[next] & 192) !== 128)
|
|
22806
|
+
return at;
|
|
22807
|
+
}
|
|
22808
|
+
at += width;
|
|
22809
|
+
}
|
|
22810
|
+
return -1;
|
|
22811
|
+
}
|
|
22812
|
+
function firstUnstorable(bytes) {
|
|
22813
|
+
const notUtf8 = isUtf8(bytes) ? -1 : firstNotUtf8(bytes);
|
|
22814
|
+
const nul = bytes.indexOf(0);
|
|
22815
|
+
const at = nul !== -1 && (notUtf8 === -1 || nul < notUtf8) ? nul : notUtf8;
|
|
22816
|
+
if (at === -1)
|
|
22817
|
+
return;
|
|
22818
|
+
return { byte: bytes[at], character: decoder4.decode(bytes.subarray(0, at)).length + 1 };
|
|
22819
|
+
}
|
|
22820
|
+
function unstorableBytes(field, bytes) {
|
|
22821
|
+
const first = firstUnstorable(bytes);
|
|
22822
|
+
if (first === undefined)
|
|
22823
|
+
return;
|
|
22824
|
+
const { byte, character } = first;
|
|
22825
|
+
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`);
|
|
22826
|
+
}
|
|
22827
|
+
function utf8Text(bytes) {
|
|
22828
|
+
try {
|
|
22829
|
+
return decoder4.decode(bytes);
|
|
22830
|
+
} catch (error) {
|
|
22831
|
+
if (isUtf8(bytes))
|
|
22832
|
+
throw error;
|
|
22833
|
+
throw new NotUtf8Error(bytes);
|
|
22834
|
+
}
|
|
22835
|
+
}
|
|
22836
|
+
function readFileText(path, readStdin = () => readFileSync(0)) {
|
|
22837
|
+
return utf8Text(path === "-" ? readStdin() : readFileSync(path));
|
|
22838
|
+
}
|
|
22839
|
+
function fileTextBytes(text) {
|
|
22840
|
+
return encoder4.encode(text);
|
|
22841
|
+
}
|
|
22842
|
+
|
|
22741
22843
|
// ../envoy-client/src/errors.ts
|
|
22742
22844
|
function dispatchField(error, field) {
|
|
22743
22845
|
if (!("fromDispatch" in error))
|
|
@@ -22813,6 +22915,7 @@ var PREFIXED_FLAGS = [
|
|
|
22813
22915
|
}
|
|
22814
22916
|
];
|
|
22815
22917
|
var STDIN = "-";
|
|
22918
|
+
var FILE_BYTES_RULE = "Bytes that are not UTF-8 are refused in Dispatch's own words, and nothing is sent.";
|
|
22816
22919
|
var BARE_WORD = /^[A-Za-z0-9_./:@%+=,-]+$/;
|
|
22817
22920
|
var OPTION_SEPARATOR = ": ";
|
|
22818
22921
|
var LOCAL_FILE_FIELD = { tool: "dispatch_artifact", field: "path" };
|
|
@@ -22855,7 +22958,7 @@ function surfaceFor(tool) {
|
|
|
22855
22958
|
spec,
|
|
22856
22959
|
command: commandName(spec.name),
|
|
22857
22960
|
fields,
|
|
22858
|
-
flags: flagTable(spec
|
|
22961
|
+
flags: flagTable(spec, fields)
|
|
22859
22962
|
};
|
|
22860
22963
|
surfaces.set(tool, surface);
|
|
22861
22964
|
return surface;
|
|
@@ -22976,11 +23079,11 @@ function placeholder(info) {
|
|
|
22976
23079
|
return info.kind.array === "string" ? "<text>" : "<n>";
|
|
22977
23080
|
return "<text>";
|
|
22978
23081
|
}
|
|
22979
|
-
function flagTable(
|
|
23082
|
+
function flagTable(spec, fields) {
|
|
22980
23083
|
const flags = new Map;
|
|
22981
23084
|
const add = (flag, entry) => {
|
|
22982
23085
|
if (flags.has(flag))
|
|
22983
|
-
throw new Error(`${
|
|
23086
|
+
throw new Error(`${spec.name}: two fields claim the flag ${flag}`);
|
|
22984
23087
|
flags.set(flag, entry);
|
|
22985
23088
|
};
|
|
22986
23089
|
for (const [field, info] of fields) {
|
|
@@ -22993,7 +23096,7 @@ function flagTable(tool, fields) {
|
|
|
22993
23096
|
field,
|
|
22994
23097
|
action: "file",
|
|
22995
23098
|
value: "<path>",
|
|
22996
|
-
text: `--${name} read from a file; - reads stdin
|
|
23099
|
+
text: `--${name} read from a file; - reads stdin. ${FILE_BYTES_RULE}`
|
|
22997
23100
|
});
|
|
22998
23101
|
} else if (kind === "number") {
|
|
22999
23102
|
add(`--${name}`, { field, action: "set", value: "<n>", text: about });
|
|
@@ -23026,7 +23129,7 @@ function flagTable(tool, fields) {
|
|
|
23026
23129
|
field,
|
|
23027
23130
|
action: "json-file",
|
|
23028
23131
|
value: "<path>",
|
|
23029
|
-
text: `--${name}-json read from a file; - reads stdin
|
|
23132
|
+
text: `--${name}-json read from a file; - reads stdin. ${FILE_BYTES_RULE}`
|
|
23030
23133
|
});
|
|
23031
23134
|
} else {
|
|
23032
23135
|
const none = kind.array === "number-or-null" ? " none is null." : "";
|
|
@@ -23037,10 +23140,10 @@ function flagTable(tool, fields) {
|
|
|
23037
23140
|
text: `${about} One item per flag, repeated.${none}`.trim()
|
|
23038
23141
|
});
|
|
23039
23142
|
for (const prefixed of PREFIXED_FLAGS) {
|
|
23040
|
-
if (prefixed.tool !==
|
|
23143
|
+
if (prefixed.tool !== spec.name || prefixed.field !== field)
|
|
23041
23144
|
continue;
|
|
23042
23145
|
if (kind.array !== "string") {
|
|
23043
|
-
throw new Error(`${
|
|
23146
|
+
throw new Error(`${spec.name}: ${prefixed.flag} needs ${field} to be a list of text`);
|
|
23044
23147
|
}
|
|
23045
23148
|
add(prefixed.flag, {
|
|
23046
23149
|
field,
|
|
@@ -23062,7 +23165,7 @@ function flagTable(tool, fields) {
|
|
|
23062
23165
|
add("--help", { action: "help", text: "Prints this help." });
|
|
23063
23166
|
add("--dry-run", {
|
|
23064
23167
|
action: "dry-run",
|
|
23065
|
-
text:
|
|
23168
|
+
text: spec.dryRunHelp ?? "Checks the arguments as the call would, then prints them as JSON and sends nothing."
|
|
23066
23169
|
});
|
|
23067
23170
|
return flags;
|
|
23068
23171
|
}
|
|
@@ -23086,7 +23189,8 @@ function parseCommand(argv, io) {
|
|
|
23086
23189
|
let help = false;
|
|
23087
23190
|
let dryRun = false;
|
|
23088
23191
|
let stdinFlag;
|
|
23089
|
-
|
|
23192
|
+
let unstorable;
|
|
23193
|
+
const read = (flag, field, path) => {
|
|
23090
23194
|
if (path === STDIN) {
|
|
23091
23195
|
if (stdinFlag !== undefined) {
|
|
23092
23196
|
problems.push(`${stdinFlag} and ${flag} both read stdin (-); only one flag can`);
|
|
@@ -23097,6 +23201,11 @@ function parseCommand(argv, io) {
|
|
|
23097
23201
|
try {
|
|
23098
23202
|
return io.readText(path);
|
|
23099
23203
|
} catch (error) {
|
|
23204
|
+
if (error instanceof NotUtf8Error) {
|
|
23205
|
+
claim(field, flag, false);
|
|
23206
|
+
unstorable ??= { field, bytes: error.bytes };
|
|
23207
|
+
return;
|
|
23208
|
+
}
|
|
23100
23209
|
problems.push(`${flag} could not read ${path === STDIN ? "stdin" : path}: ${messageFor(error)}`);
|
|
23101
23210
|
return;
|
|
23102
23211
|
}
|
|
@@ -23207,14 +23316,14 @@ function parseCommand(argv, io) {
|
|
|
23207
23316
|
break;
|
|
23208
23317
|
}
|
|
23209
23318
|
case "file": {
|
|
23210
|
-
const text = read(flag, value);
|
|
23319
|
+
const text = read(flag, field, value);
|
|
23211
23320
|
if (text !== undefined && claim(field, flag, false))
|
|
23212
23321
|
args[field] = text;
|
|
23213
23322
|
break;
|
|
23214
23323
|
}
|
|
23215
23324
|
case "json":
|
|
23216
23325
|
case "json-file": {
|
|
23217
|
-
const text = action === "json" ? value : read(flag, value);
|
|
23326
|
+
const text = action === "json" ? value : read(flag, field, value);
|
|
23218
23327
|
const parsed = text === undefined ? undefined : json(flag, text);
|
|
23219
23328
|
if (parsed !== undefined && claim(field, flag, false))
|
|
23220
23329
|
args[field] = parsed.value;
|
|
@@ -23250,6 +23359,8 @@ function parseCommand(argv, io) {
|
|
|
23250
23359
|
if (problems.length > 0) {
|
|
23251
23360
|
return problems.length === bareDashes.size ? { kind: "refused", tool, problems, aboutAFlag: false } : { kind: "refused", tool, problems };
|
|
23252
23361
|
}
|
|
23362
|
+
if (unstorable !== undefined)
|
|
23363
|
+
return { kind: "unstorable", tool, ...unstorable };
|
|
23253
23364
|
return { kind: "call", tool, args, dryRun };
|
|
23254
23365
|
}
|
|
23255
23366
|
function appendedItem(kind, flag, value, number) {
|
|
@@ -23349,7 +23460,7 @@ function commandsHelp() {
|
|
|
23349
23460
|
return ` ${commandName(spec.name).padEnd(width)} ${sentence}`;
|
|
23350
23461
|
}),
|
|
23351
23462
|
"",
|
|
23352
|
-
"Run dispatch <command> --help for its flags and an example
|
|
23463
|
+
"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.",
|
|
23353
23464
|
"",
|
|
23354
23465
|
"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).",
|
|
23355
23466
|
""
|
|
@@ -26112,6 +26223,7 @@ class DispatchServiceError extends Error {
|
|
|
26112
26223
|
mismatches;
|
|
26113
26224
|
issues;
|
|
26114
26225
|
changed;
|
|
26226
|
+
textRefusal;
|
|
26115
26227
|
hint;
|
|
26116
26228
|
constructor(code, status, message, details = {}) {
|
|
26117
26229
|
super(message);
|
|
@@ -26122,6 +26234,7 @@ class DispatchServiceError extends Error {
|
|
|
26122
26234
|
this.mismatches = details.mismatches;
|
|
26123
26235
|
this.issues = details.issues;
|
|
26124
26236
|
this.changed = details.changed;
|
|
26237
|
+
this.textRefusal = details.textRefusal ?? false;
|
|
26125
26238
|
this.hint = details.hint;
|
|
26126
26239
|
}
|
|
26127
26240
|
}
|
|
@@ -26402,7 +26515,8 @@ function answerEvent(answer, requestKey, keyEchoed, canTellDeadToken) {
|
|
|
26402
26515
|
if (status === 404 && answer.code === "NOT_FOUND" && answer.error?.startsWith(NO_ROUTE_MESSAGE_PREFIX) === true) {
|
|
26403
26516
|
return "no-route";
|
|
26404
26517
|
}
|
|
26405
|
-
|
|
26518
|
+
const textRefusal = answer.error !== undefined && answer.response.headers.has(TEXT_REFUSAL_HEADER);
|
|
26519
|
+
if (!textRefusal && retriesUnderKey(status, answer.code)) {
|
|
26406
26520
|
if (status === 409)
|
|
26407
26521
|
return "in-flight";
|
|
26408
26522
|
return status >= 500 ? "server-error" : "try-later";
|
|
@@ -26551,8 +26665,15 @@ class DispatchClient {
|
|
|
26551
26665
|
async listIssueArtifacts(issue) {
|
|
26552
26666
|
return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "artifacts"]);
|
|
26553
26667
|
}
|
|
26554
|
-
async markdownRoundTrip(markdown) {
|
|
26555
|
-
|
|
26668
|
+
async markdownRoundTrip(markdown, newDocument) {
|
|
26669
|
+
return this.#roundTrip(["api", "v1", "markdown", "round-trip"], { markdown }, newDocument);
|
|
26670
|
+
}
|
|
26671
|
+
async fileRoundTrip(bytes, newDocument) {
|
|
26672
|
+
const file = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
26673
|
+
return this.#roundTrip(["api", "v1", "markdown", "file-round-trip"], { file }, newDocument);
|
|
26674
|
+
}
|
|
26675
|
+
async#roundTrip(path, body, newDocument) {
|
|
26676
|
+
const answer = await this.#writingNothing(path, newDocument ? { ...body, new_document: true } : body, { writes: false });
|
|
26556
26677
|
return answer.markdown;
|
|
26557
26678
|
}
|
|
26558
26679
|
async listProjectArtifacts(project, unlinked = false) {
|
|
@@ -27406,7 +27527,10 @@ class DispatchClient {
|
|
|
27406
27527
|
if (response.status === 409 && refusal.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
27407
27528
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
27408
27529
|
}
|
|
27409
|
-
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error,
|
|
27530
|
+
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error, {
|
|
27531
|
+
...refusal,
|
|
27532
|
+
textRefusal: response.headers.has(TEXT_REFUSAL_HEADER)
|
|
27533
|
+
});
|
|
27410
27534
|
}
|
|
27411
27535
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
27412
27536
|
}
|
|
@@ -28981,6 +29105,10 @@ function linkFor(href, linkBase) {
|
|
|
28981
29105
|
}
|
|
28982
29106
|
|
|
28983
29107
|
// ../envoy-client/src/dispatch-commands/context.ts
|
|
29108
|
+
var DRY_RUN_DEADLINE_MS = 5000;
|
|
29109
|
+
function askOnceWithinDryRun(deadlineMs = DRY_RUN_DEADLINE_MS) {
|
|
29110
|
+
return { deadlineMs, retryNoRoute: false, writeRetry: { ...DISPATCH_WRITE_RETRY, pausesMs: [] } };
|
|
29111
|
+
}
|
|
28984
29112
|
function stringArg(args, name) {
|
|
28985
29113
|
const value = args[name];
|
|
28986
29114
|
if (typeof value !== "string")
|
|
@@ -29058,10 +29186,11 @@ function sessionContext(input, checked) {
|
|
|
29058
29186
|
configUrl,
|
|
29059
29187
|
linkBase: linkBaseOf(input.config.publicUrl ?? url),
|
|
29060
29188
|
hostSession: input.sessionId?.trim(),
|
|
29061
|
-
newClient: () => new DispatchClient(url, credential, fetchImpl, {
|
|
29189
|
+
newClient: (options = {}) => new DispatchClient(url, credential, fetchImpl, {
|
|
29062
29190
|
signal: input.signal,
|
|
29063
29191
|
writeRetry: input.writeRetry,
|
|
29064
|
-
sleep: input.sleep
|
|
29192
|
+
sleep: input.sleep,
|
|
29193
|
+
...options
|
|
29065
29194
|
})
|
|
29066
29195
|
};
|
|
29067
29196
|
}
|
|
@@ -31689,7 +31818,7 @@ import {
|
|
|
31689
31818
|
mkdirSync,
|
|
31690
31819
|
openSync as openSync2,
|
|
31691
31820
|
readdirSync,
|
|
31692
|
-
readFileSync,
|
|
31821
|
+
readFileSync as readFileSync2,
|
|
31693
31822
|
readlinkSync,
|
|
31694
31823
|
renameSync,
|
|
31695
31824
|
rmSync,
|
|
@@ -31764,7 +31893,7 @@ function bytesDigest(bytes) {
|
|
|
31764
31893
|
}
|
|
31765
31894
|
function processStart(pid) {
|
|
31766
31895
|
try {
|
|
31767
|
-
const stat =
|
|
31896
|
+
const stat = readFileSync2(`/proc/${pid}/stat`, "utf-8");
|
|
31768
31897
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19] ?? null;
|
|
31769
31898
|
} catch {
|
|
31770
31899
|
return null;
|
|
@@ -31869,7 +31998,7 @@ function recordNamesStore(dir) {
|
|
|
31869
31998
|
if (!name.endsWith(OWNER_FILE))
|
|
31870
31999
|
continue;
|
|
31871
32000
|
try {
|
|
31872
|
-
const parsed = parseOwner(
|
|
32001
|
+
const parsed = parseOwner(readFileSync2(join5(record, name), "utf-8"));
|
|
31873
32002
|
if (parsed === undefined)
|
|
31874
32003
|
return true;
|
|
31875
32004
|
statSync(parsed.owner.store);
|
|
@@ -31898,7 +32027,7 @@ function askgateState(dir, now = Date.now()) {
|
|
|
31898
32027
|
const file = join5(record, name);
|
|
31899
32028
|
let text;
|
|
31900
32029
|
try {
|
|
31901
|
-
text =
|
|
32030
|
+
text = readFileSync2(file, "utf-8");
|
|
31902
32031
|
} catch (error) {
|
|
31903
32032
|
if (hasErrnoCode(error, "ENOENT"))
|
|
31904
32033
|
continue;
|
|
@@ -31936,7 +32065,7 @@ function readMarker(file) {
|
|
|
31936
32065
|
try {
|
|
31937
32066
|
const fd = openSync2(file, constants3.O_RDONLY | constants3.O_NOFOLLOW);
|
|
31938
32067
|
try {
|
|
31939
|
-
text =
|
|
32068
|
+
text = readFileSync2(fd, "utf-8");
|
|
31940
32069
|
} finally {
|
|
31941
32070
|
closeSync2(fd);
|
|
31942
32071
|
}
|
|
@@ -32101,6 +32230,7 @@ var WRITE_ROUTES = [
|
|
|
32101
32230
|
{ method: "POST", pattern: "/api/v1/issues/{key}/artifacts", commands: ["artifact"] },
|
|
32102
32231
|
{ method: "POST", pattern: "/api/v1/projects/{key}/artifacts", commands: ["artifact"] },
|
|
32103
32232
|
{ method: "POST", pattern: "/api/v1/markdown/round-trip", commands: ["artifact"] },
|
|
32233
|
+
{ method: "POST", pattern: "/api/v1/markdown/file-round-trip", commands: ["artifact"] },
|
|
32104
32234
|
{ method: "POST", pattern: "/api/v1/projects", commands: ["project"] },
|
|
32105
32235
|
{
|
|
32106
32236
|
method: "PUT",
|
|
@@ -33038,6 +33168,9 @@ async function sendToAgentCommand(context) {
|
|
|
33038
33168
|
}
|
|
33039
33169
|
|
|
33040
33170
|
// ../envoy-client/src/dispatch-commands/documents.ts
|
|
33171
|
+
import { resolve as resolvePath3 } from "path";
|
|
33172
|
+
|
|
33173
|
+
// ../envoy-client/src/dispatch-commands/stored-text.ts
|
|
33041
33174
|
import { resolve as resolvePath2 } from "path";
|
|
33042
33175
|
|
|
33043
33176
|
// ../envoy-client/src/typed-block-opener.ts
|
|
@@ -33425,6 +33558,126 @@ function storedUpload(given, stored, name) {
|
|
|
33425
33558
|
return reordered === undefined ? { refusal: storedTextProblem(given, stored, name) } : { sent: stored, reordered };
|
|
33426
33559
|
}
|
|
33427
33560
|
|
|
33561
|
+
// ../envoy-client/src/dispatch-commands/stored-text.ts
|
|
33562
|
+
var MARKDOWN_ROUND_TRIP = "POST /api/v1/markdown/round-trip";
|
|
33563
|
+
var FILE_ROUND_TRIP = "POST /api/v1/markdown/file-round-trip";
|
|
33564
|
+
function storedTextCheckFailed(failed) {
|
|
33565
|
+
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.";
|
|
33566
|
+
return new Error(`Dispatch could not say how it would store this text, so nothing was uploaded: ${failed.failure}. ${again}`, { cause: failed.error });
|
|
33567
|
+
}
|
|
33568
|
+
function roundTripRouteAbsent(error) {
|
|
33569
|
+
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
33570
|
+
}
|
|
33571
|
+
function documentTooLarge(measured) {
|
|
33572
|
+
const bytes = typeof measured === "number" ? measured : typeof measured === "string" ? utf8Bytes(measured) : measured.byteLength;
|
|
33573
|
+
return bytes > MARKDOWN_DOCUMENT_MAX_BYTES ? new Error(`CAP_EXCEEDED: ${MARKDOWN_DOCUMENT_TOO_LARGE}`) : undefined;
|
|
33574
|
+
}
|
|
33575
|
+
function documentBytesRefusal(field, bytes) {
|
|
33576
|
+
return documentTooLarge(bytes) ?? unstorableBytes(field, bytes);
|
|
33577
|
+
}
|
|
33578
|
+
function documentFieldRefusal(field, text) {
|
|
33579
|
+
return Buffer.byteLength(text, "utf8") > MARKDOWN_DOCUMENT_MAX_BYTES || text.includes("\x00") ? documentBytesRefusal(field, fileTextBytes(text)) : undefined;
|
|
33580
|
+
}
|
|
33581
|
+
function uploadedFile(cwd, path) {
|
|
33582
|
+
return Bun.file(resolvePath2(cwd, path));
|
|
33583
|
+
}
|
|
33584
|
+
async function documentFileRead(file, held) {
|
|
33585
|
+
if (file.type.split(";", 1)[0]?.trim().toLowerCase() !== "text/markdown") {
|
|
33586
|
+
return { kind: "passed", bytes: undefined };
|
|
33587
|
+
}
|
|
33588
|
+
let bytes = held;
|
|
33589
|
+
if (bytes === undefined) {
|
|
33590
|
+
const stats = await file.stat().catch(() => {
|
|
33591
|
+
return;
|
|
33592
|
+
});
|
|
33593
|
+
if (stats !== undefined && !stats.isFile() && !stats.isDirectory()) {
|
|
33594
|
+
return { kind: "passed", bytes: undefined };
|
|
33595
|
+
}
|
|
33596
|
+
const tooLarge = stats === undefined ? undefined : documentTooLarge(stats.size);
|
|
33597
|
+
if (tooLarge !== undefined)
|
|
33598
|
+
return { kind: "refused", refusal: tooLarge };
|
|
33599
|
+
try {
|
|
33600
|
+
bytes = await file.bytes();
|
|
33601
|
+
} catch (error) {
|
|
33602
|
+
return { kind: "unread", error };
|
|
33603
|
+
}
|
|
33604
|
+
}
|
|
33605
|
+
const refusal = documentBytesRefusal("file", bytes);
|
|
33606
|
+
return refusal === undefined ? { kind: "passed", bytes } : { kind: "refused", refusal };
|
|
33607
|
+
}
|
|
33608
|
+
async function documentFileBytes(file, held) {
|
|
33609
|
+
const read = await documentFileRead(file, held);
|
|
33610
|
+
if (read.kind === "refused")
|
|
33611
|
+
throw read.refusal;
|
|
33612
|
+
if (read.kind === "unread")
|
|
33613
|
+
throw read.error;
|
|
33614
|
+
return read.bytes;
|
|
33615
|
+
}
|
|
33616
|
+
function unchecked(answer) {
|
|
33617
|
+
return { kind: "unchecked", failure: answer.failure, routeAbsent: answer.routeAbsent };
|
|
33618
|
+
}
|
|
33619
|
+
async function askRoundTrip(client, route, ask) {
|
|
33620
|
+
const dispatch = client();
|
|
33621
|
+
try {
|
|
33622
|
+
return { kind: "stored", stored: await ask(dispatch) };
|
|
33623
|
+
} catch (error) {
|
|
33624
|
+
const routeAbsent = roundTripRouteAbsent(error);
|
|
33625
|
+
if (!routeAbsent && error instanceof DispatchServiceError && error.textRefusal) {
|
|
33626
|
+
return { kind: "refused", refusal: error };
|
|
33627
|
+
}
|
|
33628
|
+
return {
|
|
33629
|
+
kind: "unanswered",
|
|
33630
|
+
failure: error instanceof DispatchAnswerNotKeptError ? `${route} wrote nothing, and Dispatch kept no copy of its answer (${error.code})` : `${route} failed with ${messageFor(error)}`,
|
|
33631
|
+
error,
|
|
33632
|
+
routeAbsent
|
|
33633
|
+
};
|
|
33634
|
+
}
|
|
33635
|
+
}
|
|
33636
|
+
async function storedTextCheck(client, tool, name, content, force) {
|
|
33637
|
+
const tooLarge = documentTooLarge(content);
|
|
33638
|
+
if (tooLarge !== undefined)
|
|
33639
|
+
return { kind: "refused", refusal: tooLarge };
|
|
33640
|
+
if (content === "")
|
|
33641
|
+
return { kind: "kept" };
|
|
33642
|
+
const answer = await askRoundTrip(client, MARKDOWN_ROUND_TRIP, (dispatch) => dispatch.markdownRoundTrip(content, !force));
|
|
33643
|
+
const blank = goBlankPattern.test(content);
|
|
33644
|
+
switch (answer.kind) {
|
|
33645
|
+
case "refused":
|
|
33646
|
+
return answer;
|
|
33647
|
+
case "unanswered":
|
|
33648
|
+
return blank || answer.routeAbsent ? unchecked(answer) : { kind: "failed", failure: answer.failure, error: answer.error };
|
|
33649
|
+
case "stored": {
|
|
33650
|
+
if (blank)
|
|
33651
|
+
return { kind: "kept" };
|
|
33652
|
+
const upload = storedUpload(content, answer.stored, name);
|
|
33653
|
+
if ("refusal" in upload) {
|
|
33654
|
+
return { kind: "refused", refusal: new ToolInputError(tool, [upload.refusal]) };
|
|
33655
|
+
}
|
|
33656
|
+
return upload.reordered.length === 0 ? { kind: "kept" } : { kind: "reordered", sent: upload.sent, lines: upload.reordered };
|
|
33657
|
+
}
|
|
33658
|
+
}
|
|
33659
|
+
}
|
|
33660
|
+
async function storedFileCheck(client, bytes, force) {
|
|
33661
|
+
const answer = await askRoundTrip(client, FILE_ROUND_TRIP, (dispatch) => dispatch.fileRoundTrip(bytes, !force));
|
|
33662
|
+
switch (answer.kind) {
|
|
33663
|
+
case "stored":
|
|
33664
|
+
return { kind: "kept" };
|
|
33665
|
+
case "refused":
|
|
33666
|
+
return answer;
|
|
33667
|
+
case "unanswered":
|
|
33668
|
+
return unchecked(answer);
|
|
33669
|
+
}
|
|
33670
|
+
}
|
|
33671
|
+
function artifactTextCheck(upload) {
|
|
33672
|
+
const { tool, name, content, bytes, force } = upload;
|
|
33673
|
+
if (content !== undefined) {
|
|
33674
|
+
return () => storedTextCheck(upload.textClient, tool, name, content, force);
|
|
33675
|
+
}
|
|
33676
|
+
if (bytes !== undefined)
|
|
33677
|
+
return () => storedFileCheck(upload.fileClient, bytes, force);
|
|
33678
|
+
return;
|
|
33679
|
+
}
|
|
33680
|
+
|
|
33428
33681
|
// ../envoy-client/src/dispatch-commands/upload-checks.ts
|
|
33429
33682
|
function artifactUnderName(artifacts, name) {
|
|
33430
33683
|
const written = name.trim();
|
|
@@ -33446,20 +33699,6 @@ function artifactNameExistsProblem(held, owner, upload) {
|
|
|
33446
33699
|
const wroteIt = authors.length === 0 ? actorText(held.created_by) : authors.join(" and ");
|
|
33447
33700
|
return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}) at version ${newest.number}, which ${wroteIt} wrote. ${rule}`;
|
|
33448
33701
|
}
|
|
33449
|
-
function storedTextCheckFailed(error, name) {
|
|
33450
|
-
if (error instanceof DispatchAnswerNotKeptError) {
|
|
33451
|
-
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.`;
|
|
33452
|
-
}
|
|
33453
|
-
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)}.`;
|
|
33454
|
-
if (!dispatchAnswered(error, 413)) {
|
|
33455
|
-
return `${failure} Send the upload again once that call is answered.`;
|
|
33456
|
-
}
|
|
33457
|
-
const asBytes = pathKeepsBytesOf(name) ? ` Send it as a file with ${PATH_KEEPS_BYTES}, which asks this check nothing.` : "";
|
|
33458
|
-
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}`;
|
|
33459
|
-
}
|
|
33460
|
-
function roundTripRouteAbsent(error) {
|
|
33461
|
-
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
33462
|
-
}
|
|
33463
33702
|
|
|
33464
33703
|
// ../envoy-client/src/dispatch-commands/documents.ts
|
|
33465
33704
|
async function blockAsks(client, resolved, state) {
|
|
@@ -33824,7 +34063,7 @@ async function planApproveCommand(context) {
|
|
|
33824
34063
|
};
|
|
33825
34064
|
}
|
|
33826
34065
|
async function artifactCommand(context) {
|
|
33827
|
-
const { args, client, actor, input, documentOwner, issue } = context;
|
|
34066
|
+
const { args, client, actor, input, documentOwner, issue, newClient } = context;
|
|
33828
34067
|
const summary = optionalString(args, "summary");
|
|
33829
34068
|
const name = stringArg(args, "name");
|
|
33830
34069
|
const content = optionalString(args, "content");
|
|
@@ -33837,40 +34076,40 @@ async function artifactCommand(context) {
|
|
|
33837
34076
|
actor
|
|
33838
34077
|
};
|
|
33839
34078
|
const artifactOwner = documentOwner();
|
|
34079
|
+
const force = optionalBoolean(args, "force") === true;
|
|
33840
34080
|
const blank = content === undefined || goBlankPattern.test(content);
|
|
33841
|
-
|
|
34081
|
+
const file = path === undefined ? undefined : uploadedFile(input.cwd, path);
|
|
34082
|
+
const heldBytes = input.uploadBytes === undefined ? undefined : new Uint8Array(input.uploadBytes);
|
|
34083
|
+
const documentBytes = file === undefined ? undefined : await documentFileBytes(file, heldBytes);
|
|
34084
|
+
const check = artifactTextCheck({
|
|
34085
|
+
tool: input.tool,
|
|
34086
|
+
name,
|
|
34087
|
+
content,
|
|
34088
|
+
bytes: documentBytes,
|
|
34089
|
+
force,
|
|
34090
|
+
textClient: () => client,
|
|
34091
|
+
fileClient: () => newClient(askOnceWithinDryRun())
|
|
34092
|
+
});
|
|
34093
|
+
const stored = await check?.();
|
|
34094
|
+
if (stored?.kind === "refused")
|
|
34095
|
+
throw stored.refusal;
|
|
34096
|
+
if (stored?.kind === "failed")
|
|
34097
|
+
throw storedTextCheckFailed(stored);
|
|
34098
|
+
if ((path !== undefined || !blank) && !force) {
|
|
33842
34099
|
const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
|
|
33843
34100
|
if (held !== undefined) {
|
|
33844
|
-
const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(
|
|
34101
|
+
const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(resolvePath3(input.cwd, named)) : Promise.resolve(input.uploadBytes.subarray(0, PICTURE_SNIFF_BYTES)));
|
|
33845
34102
|
throw new ToolInputError(input.tool, [
|
|
33846
34103
|
artifactNameExistsProblem(held, artifactOwner.kind === "project" ? `project ${artifactOwner.project}` : `issue ${issue()}`, kind)
|
|
33847
34104
|
]);
|
|
33848
34105
|
}
|
|
33849
34106
|
}
|
|
33850
|
-
|
|
33851
|
-
|
|
33852
|
-
|
|
33853
|
-
|
|
33854
|
-
try {
|
|
33855
|
-
stored = await client.markdownRoundTrip(content);
|
|
33856
|
-
} catch (error) {
|
|
33857
|
-
if (!roundTripRouteAbsent(error)) {
|
|
33858
|
-
throw new Error(storedTextCheckFailed(error, name), { cause: error });
|
|
33859
|
-
}
|
|
33860
|
-
}
|
|
33861
|
-
if (stored !== undefined) {
|
|
33862
|
-
const upload = storedUpload(content, stored, name);
|
|
33863
|
-
if ("refusal" in upload)
|
|
33864
|
-
throw new ToolInputError(input.tool, [upload.refusal]);
|
|
33865
|
-
sent = upload.sent;
|
|
33866
|
-
reordered = upload.reordered;
|
|
33867
|
-
}
|
|
33868
|
-
}
|
|
33869
|
-
const artifactInput = path !== undefined ? {
|
|
34107
|
+
const fileBytes = documentBytes ?? heldBytes;
|
|
34108
|
+
const sent = stored?.kind === "reordered" ? stored.sent : content;
|
|
34109
|
+
const reordered = stored?.kind === "reordered" ? stored.lines : [];
|
|
34110
|
+
const artifactInput = file !== undefined ? {
|
|
33870
34111
|
...options,
|
|
33871
|
-
file:
|
|
33872
|
-
type: Bun.file(resolvePath2(input.cwd, path)).type
|
|
33873
|
-
})
|
|
34112
|
+
file: fileBytes === undefined ? file : new Blob([fileBytes], { type: file.type })
|
|
33874
34113
|
} : sent !== undefined ? { ...options, content: sent } : options;
|
|
33875
34114
|
const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
|
|
33876
34115
|
const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
|
|
@@ -33898,6 +34137,59 @@ async function artifactCommand(context) {
|
|
|
33898
34137
|
}
|
|
33899
34138
|
};
|
|
33900
34139
|
}
|
|
34140
|
+
function endedSentence(text) {
|
|
34141
|
+
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
34142
|
+
}
|
|
34143
|
+
async function artifactDryRun(context) {
|
|
34144
|
+
const { tool, args, cwd, uploadBytes, client, deadline, deadlineMs } = context;
|
|
34145
|
+
const content = optionalString(args, "content");
|
|
34146
|
+
const path = optionalString(args, "path");
|
|
34147
|
+
let bytes;
|
|
34148
|
+
if (content === undefined && path !== undefined) {
|
|
34149
|
+
try {
|
|
34150
|
+
bytes = await documentFileBytes(uploadedFile(cwd, path), uploadBytes);
|
|
34151
|
+
} catch (error) {
|
|
34152
|
+
return {
|
|
34153
|
+
kind: "refused",
|
|
34154
|
+
refusal: error instanceof Error ? error : new Error(messageFor(error))
|
|
34155
|
+
};
|
|
34156
|
+
}
|
|
34157
|
+
}
|
|
34158
|
+
const check = artifactTextCheck({
|
|
34159
|
+
tool,
|
|
34160
|
+
name: stringArg(args, "name"),
|
|
34161
|
+
content,
|
|
34162
|
+
bytes,
|
|
34163
|
+
force: optionalBoolean(args, "force") === true,
|
|
34164
|
+
textClient: client,
|
|
34165
|
+
fileClient: client
|
|
34166
|
+
});
|
|
34167
|
+
if (check === undefined)
|
|
34168
|
+
return { kind: "passed" };
|
|
34169
|
+
const subject = content === undefined ? "the file" : "the text";
|
|
34170
|
+
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.";
|
|
34171
|
+
const unasked = (why, then) => ({
|
|
34172
|
+
kind: "passed",
|
|
34173
|
+
warning: `dispatch: warning: the dry run could not ask Dispatch about ${subject}: ${endedSentence(why)} ${then}`
|
|
34174
|
+
});
|
|
34175
|
+
let stored;
|
|
34176
|
+
try {
|
|
34177
|
+
stored = await check();
|
|
34178
|
+
} catch (error) {
|
|
34179
|
+
return unasked(messageFor(error), "The call is refused for the same reason.");
|
|
34180
|
+
}
|
|
34181
|
+
if (stored.kind === "kept" || stored.kind === "reordered")
|
|
34182
|
+
return { kind: "passed" };
|
|
34183
|
+
if (stored.kind === "refused")
|
|
34184
|
+
return { kind: "refused", refusal: stored.refusal };
|
|
34185
|
+
if (stored.kind === "unchecked" && stored.routeAbsent) {
|
|
34186
|
+
return {
|
|
34187
|
+
kind: "passed",
|
|
34188
|
+
warning: `dispatch: warning: this Dispatch cannot check ${subject}: ${endedSentence(stored.failure)} ${uploadsUnchecked}`
|
|
34189
|
+
};
|
|
34190
|
+
}
|
|
34191
|
+
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.");
|
|
34192
|
+
}
|
|
33901
34193
|
|
|
33902
34194
|
// ../envoy-client/src/dispatch-commands/handoffs.ts
|
|
33903
34195
|
async function handoffWriteCommand(context) {
|
|
@@ -34456,7 +34748,7 @@ async function reviewCommand(context) {
|
|
|
34456
34748
|
}
|
|
34457
34749
|
|
|
34458
34750
|
// ../envoy-client/src/session-answers.ts
|
|
34459
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
34751
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
|
|
34460
34752
|
import { join as join7 } from "path";
|
|
34461
34753
|
|
|
34462
34754
|
// ../envoy-client/src/json-line-record.ts
|
|
@@ -34597,7 +34889,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
34597
34889
|
var CACHE_FILE = "answers.json";
|
|
34598
34890
|
function readCacheFile(directory, url) {
|
|
34599
34891
|
try {
|
|
34600
|
-
const value = JSON.parse(
|
|
34892
|
+
const value = JSON.parse(readFileSync3(join7(directory, CACHE_FILE), "utf-8"));
|
|
34601
34893
|
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)) {
|
|
34602
34894
|
return {
|
|
34603
34895
|
dispatch_url: value.dispatch_url,
|
|
@@ -35072,7 +35364,12 @@ var dispatchCommands = {
|
|
|
35072
35364
|
dispatch_review: acting(reviewCommand),
|
|
35073
35365
|
dispatch_result: acting(resultCommand),
|
|
35074
35366
|
dispatch_results: acting(resultsCommand),
|
|
35075
|
-
dispatch_artifact:
|
|
35367
|
+
dispatch_artifact: {
|
|
35368
|
+
...acting(artifactCommand),
|
|
35369
|
+
dryRun: artifactDryRun,
|
|
35370
|
+
documentFields: ["content"],
|
|
35371
|
+
documentPathField: "path"
|
|
35372
|
+
},
|
|
35076
35373
|
dispatch_handoff_write: acting(handoffWriteCommand),
|
|
35077
35374
|
dispatch_handoff_read: acting(handoffReadCommand),
|
|
35078
35375
|
dispatch_steps: acting(stepsCommand),
|
|
@@ -35093,7 +35390,7 @@ async function executeDispatchTool(input) {
|
|
|
35093
35390
|
if (checked.problems.length > 0)
|
|
35094
35391
|
throw new ToolInputError(input.tool, checked.problems);
|
|
35095
35392
|
if (input.dryRun === true && !dryRunAsksDispatch(input.tool, checked.args)) {
|
|
35096
|
-
throw new Error(`dispatch ${input.tool}'s dry run
|
|
35393
|
+
throw new Error(`dispatch ${input.tool}'s dry run runs no command`);
|
|
35097
35394
|
}
|
|
35098
35395
|
const command = dispatchCommands[input.tool];
|
|
35099
35396
|
if (command === undefined)
|
|
@@ -35103,7 +35400,7 @@ async function executeDispatchTool(input) {
|
|
|
35103
35400
|
}
|
|
35104
35401
|
|
|
35105
35402
|
// ../envoy-client/src/dispatch-first.ts
|
|
35106
|
-
import { readFileSync as
|
|
35403
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
35107
35404
|
import { join as join8 } from "path";
|
|
35108
35405
|
var DISPATCH_FIRST_MARKER = "<dispatch-first-skill>";
|
|
35109
35406
|
function dispatchFirstSkillFile(skillsDirectory) {
|
|
@@ -35112,7 +35409,7 @@ function dispatchFirstSkillFile(skillsDirectory) {
|
|
|
35112
35409
|
function readDispatchFirstContext(skillFile) {
|
|
35113
35410
|
let skill;
|
|
35114
35411
|
try {
|
|
35115
|
-
skill =
|
|
35412
|
+
skill = readFileSync4(skillFile, "utf8");
|
|
35116
35413
|
} catch (error) {
|
|
35117
35414
|
throw new Error(`the dispatch-first skill ${skillFile} could not be read: ${messageFor(error)}`);
|
|
35118
35415
|
}
|
|
@@ -36582,14 +36879,14 @@ function brokerCredential(env, session, read) {
|
|
|
36582
36879
|
}
|
|
36583
36880
|
|
|
36584
36881
|
// ../envoy-client/src/file-token-credential.ts
|
|
36585
|
-
import { readFileSync as
|
|
36882
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
36586
36883
|
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
36587
36884
|
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
36588
36885
|
var PKCS8_LABEL = "PRIVATE KEY";
|
|
36589
36886
|
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
36590
36887
|
function readNamed(variable, filePath) {
|
|
36591
36888
|
try {
|
|
36592
|
-
return
|
|
36889
|
+
return readFileSync5(filePath, "utf8");
|
|
36593
36890
|
} catch (error) {
|
|
36594
36891
|
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
36595
36892
|
}
|
|
@@ -37760,7 +38057,7 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
37760
38057
|
|
|
37761
38058
|
// src/codex/codex-session-record.ts
|
|
37762
38059
|
import { spawnSync } from "child_process";
|
|
37763
|
-
import { readFileSync as
|
|
38060
|
+
import { readFileSync as readFileSync7, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
|
|
37764
38061
|
import { mkdir as mkdir4, readFile as readFile8, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
37765
38062
|
import { homedir as homedir3 } from "os";
|
|
37766
38063
|
import { basename as basename4, dirname as dirname5, join as join12 } from "path";
|
|
@@ -37770,7 +38067,7 @@ import { readFile as readFile7 } from "fs/promises";
|
|
|
37770
38067
|
import { basename as basename3, join as join11 } from "path";
|
|
37771
38068
|
|
|
37772
38069
|
// src/session-state.ts
|
|
37773
|
-
import { readFileSync as
|
|
38070
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
37774
38071
|
import { mkdir as mkdir3, readdir as readdir3, rename as rename4, rm as rm4, stat as stat4, utimes as utimes2, writeFile as writeFile2 } from "fs/promises";
|
|
37775
38072
|
import { dirname as dirname4, join as join10 } from "path";
|
|
37776
38073
|
async function writeAtomicStateFile(file, contents) {
|
|
@@ -37816,7 +38113,7 @@ async function removeChosenTitle(file) {
|
|
|
37816
38113
|
}
|
|
37817
38114
|
function readChosenTitleSync(file) {
|
|
37818
38115
|
try {
|
|
37819
|
-
return
|
|
38116
|
+
return readFileSync6(file, "utf8");
|
|
37820
38117
|
} catch {
|
|
37821
38118
|
return;
|
|
37822
38119
|
}
|
|
@@ -38009,14 +38306,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
38009
38306
|
}
|
|
38010
38307
|
function procComm(pid) {
|
|
38011
38308
|
try {
|
|
38012
|
-
return
|
|
38309
|
+
return readFileSync7(`/proc/${pid}/comm`, "utf8").trim();
|
|
38013
38310
|
} catch {
|
|
38014
38311
|
return;
|
|
38015
38312
|
}
|
|
38016
38313
|
}
|
|
38017
38314
|
function procParent(pid) {
|
|
38018
38315
|
try {
|
|
38019
|
-
const stat =
|
|
38316
|
+
const stat = readFileSync7(`/proc/${pid}/stat`, "utf8");
|
|
38020
38317
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
38021
38318
|
return Number.isInteger(parent) ? parent : undefined;
|
|
38022
38319
|
} catch {
|
|
@@ -38030,7 +38327,7 @@ var PS_OPTIONS = {
|
|
|
38030
38327
|
};
|
|
38031
38328
|
function procStarted(pid) {
|
|
38032
38329
|
try {
|
|
38033
|
-
const stat =
|
|
38330
|
+
const stat = readFileSync7(`/proc/${pid}/stat`, "utf8");
|
|
38034
38331
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
38035
38332
|
} catch {
|
|
38036
38333
|
return;
|
|
@@ -38051,7 +38348,7 @@ function recordOfProcess(record, pid) {
|
|
|
38051
38348
|
function sharedAppServer(pid) {
|
|
38052
38349
|
let argv;
|
|
38053
38350
|
try {
|
|
38054
|
-
argv =
|
|
38351
|
+
argv = readFileSync7(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
38055
38352
|
} catch {
|
|
38056
38353
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
38057
38354
|
if (ps.status !== 0)
|
|
@@ -38204,7 +38501,7 @@ function singleQuoted(value) {
|
|
|
38204
38501
|
}
|
|
38205
38502
|
function envFileText(envFile) {
|
|
38206
38503
|
try {
|
|
38207
|
-
return
|
|
38504
|
+
return readFileSync8(envFile, "utf8");
|
|
38208
38505
|
} catch (error) {
|
|
38209
38506
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
38210
38507
|
throw error;
|
|
@@ -38331,7 +38628,7 @@ function refreshLockHeld(lock) {
|
|
|
38331
38628
|
let text;
|
|
38332
38629
|
try {
|
|
38333
38630
|
age = Date.now() - statSync2(lock).mtimeMs;
|
|
38334
|
-
text =
|
|
38631
|
+
text = readFileSync8(lock, "utf8");
|
|
38335
38632
|
} catch (error) {
|
|
38336
38633
|
if (hasErrnoCode(error, "ENOENT"))
|
|
38337
38634
|
return false;
|
|
@@ -38367,7 +38664,7 @@ function takeRefreshLock(lock) {
|
|
|
38367
38664
|
function refreshOutcome(file, since) {
|
|
38368
38665
|
let value;
|
|
38369
38666
|
try {
|
|
38370
|
-
value = JSON.parse(
|
|
38667
|
+
value = JSON.parse(readFileSync8(file, "utf8"));
|
|
38371
38668
|
} catch {
|
|
38372
38669
|
return;
|
|
38373
38670
|
}
|