@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.
@@ -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
- 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 1 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} ` + "Markdown is also refused with 413 CAP_EXCEEDED when it makes more than 65,536 elements (a block weighs 3, and an empty list item, quote, footnote definition or typed block 3 more for the empty paragraph it holds; a table cell 4, a hard line break 3, an image 3, a piece of inline HTML 2, an autolink 2, a footnote reference 2; inline syntax, marks, lines of text and backslash escapes or character references 1 each), or when a new version would leave the document's stored markdown (what its text reads back as) longer than 1 MiB or making more than 65,536 elements, and longer or heavier than before; shorten it or split it across documents. " + "In a table row, write every | in a cell as \\|, in code too: a | after two backslashes ends the cell, and a row with more cells than its table is refused. " + "Markdown holding an ask block whose body breaks its content rule (one or more question paragraphs, then at most one bullet list of options, last) is refused with 400 INVALID_ASK_BLOCK; a new version of a document is held to it only for the asks it writes or changes. " + `${CI_CHECK_RULE} ` + `${OWNER_REFERENCE}`,
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.name, fields)
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(tool, fields) {
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(`${tool}: two fields claim the flag ${flag}`);
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 !== tool || prefixed.field !== field)
19821
+ if (prefixed.tool !== spec.name || prefixed.field !== field)
19719
19822
  continue;
19720
19823
  if (kind.array !== "string") {
19721
- throw new Error(`${tool}: ${prefixed.flag} needs ${field} to be a list of text`);
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: tool === "dispatch_result" ? "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." : "Checks the arguments as the call would, then prints them as JSON and sends nothing."
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
- const read = (flag, path) => {
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; --dry-run checks a command's arguments as the call would and prints them as given, sending nothing, except that dispatch result's dry run of a record also prints the pull-request body line Dispatch would write for it, recording nothing.",
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 encoder2 = new TextEncoder;
22115
- var decoder = new TextDecoder;
22225
+ var encoder3 = new TextEncoder;
22226
+ var decoder2 = new TextDecoder;
22116
22227
  function buf(input) {
22117
22228
  if (typeof input === "string") {
22118
- return encoder2.encode(input);
22229
+ return encoder3.encode(input);
22119
22230
  }
22120
- return decoder.decode(input);
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 encoder3 = new TextEncoder;
22989
- var decoder2 = new TextDecoder;
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 : decoder2.decode(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 = decoder2.decode(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 = encoder3.encode(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 decoder3 = new TextDecoder;
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
- if (retriesUnderKey(status, answer.code)) {
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
- const answer = await this.#writingNothing(["api", "v1", "markdown", "round-trip"], { markdown }, { writes: false });
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, refusal);
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
  }
@@ -27833,6 +27957,10 @@ function linkFor(href, linkBase) {
27833
27957
  }
27834
27958
 
27835
27959
  // ../envoy-client/src/dispatch-commands/context.ts
27960
+ var DRY_RUN_DEADLINE_MS = 5000;
27961
+ function askOnceWithinDryRun(deadlineMs = DRY_RUN_DEADLINE_MS) {
27962
+ return { deadlineMs, retryNoRoute: false, writeRetry: { ...DISPATCH_WRITE_RETRY, pausesMs: [] } };
27963
+ }
27836
27964
  function stringArg(args, name) {
27837
27965
  const value = args[name];
27838
27966
  if (typeof value !== "string")
@@ -27910,10 +28038,11 @@ function sessionContext(input, checked) {
27910
28038
  configUrl,
27911
28039
  linkBase: linkBaseOf(input.config.publicUrl ?? url),
27912
28040
  hostSession: input.sessionId?.trim(),
27913
- newClient: () => new DispatchClient(url, credential, fetchImpl, {
28041
+ newClient: (options = {}) => new DispatchClient(url, credential, fetchImpl, {
27914
28042
  signal: input.signal,
27915
28043
  writeRetry: input.writeRetry,
27916
- sleep: input.sleep
28044
+ sleep: input.sleep,
28045
+ ...options
27917
28046
  })
27918
28047
  };
27919
28048
  }
@@ -30541,7 +30670,7 @@ import {
30541
30670
  mkdirSync,
30542
30671
  openSync,
30543
30672
  readdirSync,
30544
- readFileSync,
30673
+ readFileSync as readFileSync2,
30545
30674
  readlinkSync,
30546
30675
  renameSync,
30547
30676
  rmSync,
@@ -30616,7 +30745,7 @@ function bytesDigest(bytes) {
30616
30745
  }
30617
30746
  function processStart(pid) {
30618
30747
  try {
30619
- const stat = readFileSync(`/proc/${pid}/stat`, "utf-8");
30748
+ const stat = readFileSync2(`/proc/${pid}/stat`, "utf-8");
30620
30749
  return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19] ?? null;
30621
30750
  } catch {
30622
30751
  return null;
@@ -30721,7 +30850,7 @@ function recordNamesStore(dir) {
30721
30850
  if (!name.endsWith(OWNER_FILE))
30722
30851
  continue;
30723
30852
  try {
30724
- const parsed = parseOwner(readFileSync(join3(record, name), "utf-8"));
30853
+ const parsed = parseOwner(readFileSync2(join3(record, name), "utf-8"));
30725
30854
  if (parsed === undefined)
30726
30855
  return true;
30727
30856
  statSync(parsed.owner.store);
@@ -30750,7 +30879,7 @@ function askgateState(dir, now = Date.now()) {
30750
30879
  const file = join3(record, name);
30751
30880
  let text;
30752
30881
  try {
30753
- text = readFileSync(file, "utf-8");
30882
+ text = readFileSync2(file, "utf-8");
30754
30883
  } catch (error) {
30755
30884
  if (hasErrnoCode(error, "ENOENT"))
30756
30885
  continue;
@@ -30788,7 +30917,7 @@ function readMarker(file) {
30788
30917
  try {
30789
30918
  const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
30790
30919
  try {
30791
- text = readFileSync(fd, "utf-8");
30920
+ text = readFileSync2(fd, "utf-8");
30792
30921
  } finally {
30793
30922
  closeSync(fd);
30794
30923
  }
@@ -30953,6 +31082,7 @@ var WRITE_ROUTES = [
30953
31082
  { method: "POST", pattern: "/api/v1/issues/{key}/artifacts", commands: ["artifact"] },
30954
31083
  { method: "POST", pattern: "/api/v1/projects/{key}/artifacts", commands: ["artifact"] },
30955
31084
  { method: "POST", pattern: "/api/v1/markdown/round-trip", commands: ["artifact"] },
31085
+ { method: "POST", pattern: "/api/v1/markdown/file-round-trip", commands: ["artifact"] },
30956
31086
  { method: "POST", pattern: "/api/v1/projects", commands: ["project"] },
30957
31087
  {
30958
31088
  method: "PUT",
@@ -31890,6 +32020,9 @@ async function sendToAgentCommand(context) {
31890
32020
  }
31891
32021
 
31892
32022
  // ../envoy-client/src/dispatch-commands/documents.ts
32023
+ import { resolve as resolvePath3 } from "path";
32024
+
32025
+ // ../envoy-client/src/dispatch-commands/stored-text.ts
31893
32026
  import { resolve as resolvePath2 } from "path";
31894
32027
 
31895
32028
  // ../envoy-client/src/typed-block-opener.ts
@@ -32277,6 +32410,126 @@ function storedUpload(given, stored, name) {
32277
32410
  return reordered === undefined ? { refusal: storedTextProblem(given, stored, name) } : { sent: stored, reordered };
32278
32411
  }
32279
32412
 
32413
+ // ../envoy-client/src/dispatch-commands/stored-text.ts
32414
+ var MARKDOWN_ROUND_TRIP = "POST /api/v1/markdown/round-trip";
32415
+ var FILE_ROUND_TRIP = "POST /api/v1/markdown/file-round-trip";
32416
+ function storedTextCheckFailed(failed) {
32417
+ 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.";
32418
+ return new Error(`Dispatch could not say how it would store this text, so nothing was uploaded: ${failed.failure}. ${again}`, { cause: failed.error });
32419
+ }
32420
+ function roundTripRouteAbsent(error) {
32421
+ return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
32422
+ }
32423
+ function documentTooLarge(measured) {
32424
+ const bytes = typeof measured === "number" ? measured : typeof measured === "string" ? utf8Bytes(measured) : measured.byteLength;
32425
+ return bytes > MARKDOWN_DOCUMENT_MAX_BYTES ? new Error(`CAP_EXCEEDED: ${MARKDOWN_DOCUMENT_TOO_LARGE}`) : undefined;
32426
+ }
32427
+ function documentBytesRefusal(field, bytes) {
32428
+ return documentTooLarge(bytes) ?? unstorableBytes(field, bytes);
32429
+ }
32430
+ function documentFieldRefusal(field, text) {
32431
+ return Buffer.byteLength(text, "utf8") > MARKDOWN_DOCUMENT_MAX_BYTES || text.includes("\x00") ? documentBytesRefusal(field, fileTextBytes(text)) : undefined;
32432
+ }
32433
+ function uploadedFile(cwd, path) {
32434
+ return Bun.file(resolvePath2(cwd, path));
32435
+ }
32436
+ async function documentFileRead(file, held) {
32437
+ if (file.type.split(";", 1)[0]?.trim().toLowerCase() !== "text/markdown") {
32438
+ return { kind: "passed", bytes: undefined };
32439
+ }
32440
+ let bytes = held;
32441
+ if (bytes === undefined) {
32442
+ const stats = await file.stat().catch(() => {
32443
+ return;
32444
+ });
32445
+ if (stats !== undefined && !stats.isFile() && !stats.isDirectory()) {
32446
+ return { kind: "passed", bytes: undefined };
32447
+ }
32448
+ const tooLarge = stats === undefined ? undefined : documentTooLarge(stats.size);
32449
+ if (tooLarge !== undefined)
32450
+ return { kind: "refused", refusal: tooLarge };
32451
+ try {
32452
+ bytes = await file.bytes();
32453
+ } catch (error) {
32454
+ return { kind: "unread", error };
32455
+ }
32456
+ }
32457
+ const refusal = documentBytesRefusal("file", bytes);
32458
+ return refusal === undefined ? { kind: "passed", bytes } : { kind: "refused", refusal };
32459
+ }
32460
+ async function documentFileBytes(file, held) {
32461
+ const read = await documentFileRead(file, held);
32462
+ if (read.kind === "refused")
32463
+ throw read.refusal;
32464
+ if (read.kind === "unread")
32465
+ throw read.error;
32466
+ return read.bytes;
32467
+ }
32468
+ function unchecked(answer) {
32469
+ return { kind: "unchecked", failure: answer.failure, routeAbsent: answer.routeAbsent };
32470
+ }
32471
+ async function askRoundTrip(client, route, ask) {
32472
+ const dispatch = client();
32473
+ try {
32474
+ return { kind: "stored", stored: await ask(dispatch) };
32475
+ } catch (error) {
32476
+ const routeAbsent = roundTripRouteAbsent(error);
32477
+ if (!routeAbsent && error instanceof DispatchServiceError && error.textRefusal) {
32478
+ return { kind: "refused", refusal: error };
32479
+ }
32480
+ return {
32481
+ kind: "unanswered",
32482
+ failure: error instanceof DispatchAnswerNotKeptError ? `${route} wrote nothing, and Dispatch kept no copy of its answer (${error.code})` : `${route} failed with ${messageFor(error)}`,
32483
+ error,
32484
+ routeAbsent
32485
+ };
32486
+ }
32487
+ }
32488
+ async function storedTextCheck(client, tool, name, content, force) {
32489
+ const tooLarge = documentTooLarge(content);
32490
+ if (tooLarge !== undefined)
32491
+ return { kind: "refused", refusal: tooLarge };
32492
+ if (content === "")
32493
+ return { kind: "kept" };
32494
+ const answer = await askRoundTrip(client, MARKDOWN_ROUND_TRIP, (dispatch) => dispatch.markdownRoundTrip(content, !force));
32495
+ const blank = goBlankPattern.test(content);
32496
+ switch (answer.kind) {
32497
+ case "refused":
32498
+ return answer;
32499
+ case "unanswered":
32500
+ return blank || answer.routeAbsent ? unchecked(answer) : { kind: "failed", failure: answer.failure, error: answer.error };
32501
+ case "stored": {
32502
+ if (blank)
32503
+ return { kind: "kept" };
32504
+ const upload = storedUpload(content, answer.stored, name);
32505
+ if ("refusal" in upload) {
32506
+ return { kind: "refused", refusal: new ToolInputError(tool, [upload.refusal]) };
32507
+ }
32508
+ return upload.reordered.length === 0 ? { kind: "kept" } : { kind: "reordered", sent: upload.sent, lines: upload.reordered };
32509
+ }
32510
+ }
32511
+ }
32512
+ async function storedFileCheck(client, bytes, force) {
32513
+ const answer = await askRoundTrip(client, FILE_ROUND_TRIP, (dispatch) => dispatch.fileRoundTrip(bytes, !force));
32514
+ switch (answer.kind) {
32515
+ case "stored":
32516
+ return { kind: "kept" };
32517
+ case "refused":
32518
+ return answer;
32519
+ case "unanswered":
32520
+ return unchecked(answer);
32521
+ }
32522
+ }
32523
+ function artifactTextCheck(upload) {
32524
+ const { tool, name, content, bytes, force } = upload;
32525
+ if (content !== undefined) {
32526
+ return () => storedTextCheck(upload.textClient, tool, name, content, force);
32527
+ }
32528
+ if (bytes !== undefined)
32529
+ return () => storedFileCheck(upload.fileClient, bytes, force);
32530
+ return;
32531
+ }
32532
+
32280
32533
  // ../envoy-client/src/dispatch-commands/upload-checks.ts
32281
32534
  function artifactUnderName(artifacts, name) {
32282
32535
  const written = name.trim();
@@ -32298,20 +32551,6 @@ function artifactNameExistsProblem(held, owner, upload) {
32298
32551
  const wroteIt = authors.length === 0 ? actorText(held.created_by) : authors.join(" and ");
32299
32552
  return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}) at version ${newest.number}, which ${wroteIt} wrote. ${rule}`;
32300
32553
  }
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
32554
 
32316
32555
  // ../envoy-client/src/dispatch-commands/documents.ts
32317
32556
  async function blockAsks(client, resolved, state) {
@@ -32676,7 +32915,7 @@ async function planApproveCommand(context) {
32676
32915
  };
32677
32916
  }
32678
32917
  async function artifactCommand(context) {
32679
- const { args, client, actor, input, documentOwner, issue } = context;
32918
+ const { args, client, actor, input, documentOwner, issue, newClient } = context;
32680
32919
  const summary = optionalString(args, "summary");
32681
32920
  const name = stringArg(args, "name");
32682
32921
  const content = optionalString(args, "content");
@@ -32689,40 +32928,40 @@ async function artifactCommand(context) {
32689
32928
  actor
32690
32929
  };
32691
32930
  const artifactOwner = documentOwner();
32931
+ const force = optionalBoolean(args, "force") === true;
32692
32932
  const blank = content === undefined || goBlankPattern.test(content);
32693
- if ((path !== undefined || !blank) && optionalBoolean(args, "force") !== true) {
32933
+ const file = path === undefined ? undefined : uploadedFile(input.cwd, path);
32934
+ const heldBytes = input.uploadBytes === undefined ? undefined : new Uint8Array(input.uploadBytes);
32935
+ const documentBytes = file === undefined ? undefined : await documentFileBytes(file, heldBytes);
32936
+ const check = artifactTextCheck({
32937
+ tool: input.tool,
32938
+ name,
32939
+ content,
32940
+ bytes: documentBytes,
32941
+ force,
32942
+ textClient: () => client,
32943
+ fileClient: () => newClient(askOnceWithinDryRun())
32944
+ });
32945
+ const stored = await check?.();
32946
+ if (stored?.kind === "refused")
32947
+ throw stored.refusal;
32948
+ if (stored?.kind === "failed")
32949
+ throw storedTextCheckFailed(stored);
32950
+ if ((path !== undefined || !blank) && !force) {
32694
32951
  const held = artifactUnderName(artifactOwner.kind === "project" ? await client.listProjectArtifacts(artifactOwner.project, true) : await client.listIssueArtifacts(issue()), name);
32695
32952
  if (held !== undefined) {
32696
- const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(resolvePath2(input.cwd, named)) : Promise.resolve(input.uploadBytes.subarray(0, PICTURE_SNIFF_BYTES)));
32953
+ const kind = await uploadKindOf(path, (named) => input.uploadBytes === undefined ? readPictureHead(resolvePath3(input.cwd, named)) : Promise.resolve(input.uploadBytes.subarray(0, PICTURE_SNIFF_BYTES)));
32697
32954
  throw new ToolInputError(input.tool, [
32698
32955
  artifactNameExistsProblem(held, artifactOwner.kind === "project" ? `project ${artifactOwner.project}` : `issue ${issue()}`, kind)
32699
32956
  ]);
32700
32957
  }
32701
32958
  }
32702
- let sent = content;
32703
- let reordered = [];
32704
- if (!blank) {
32705
- let stored;
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 ? {
32959
+ const fileBytes = documentBytes ?? heldBytes;
32960
+ const sent = stored?.kind === "reordered" ? stored.sent : content;
32961
+ const reordered = stored?.kind === "reordered" ? stored.lines : [];
32962
+ const artifactInput = file !== undefined ? {
32722
32963
  ...options,
32723
- file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd, path)) : new Blob([new Uint8Array(input.uploadBytes)], {
32724
- type: Bun.file(resolvePath2(input.cwd, path)).type
32725
- })
32964
+ file: fileBytes === undefined ? file : new Blob([fileBytes], { type: file.type })
32726
32965
  } : sent !== undefined ? { ...options, content: sent } : options;
32727
32966
  const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
32728
32967
  const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
@@ -32750,6 +32989,59 @@ async function artifactCommand(context) {
32750
32989
  }
32751
32990
  };
32752
32991
  }
32992
+ function endedSentence(text) {
32993
+ return /[.!?]$/.test(text) ? text : `${text}.`;
32994
+ }
32995
+ async function artifactDryRun(context) {
32996
+ const { tool, args, cwd, uploadBytes, client, deadline, deadlineMs } = context;
32997
+ const content = optionalString(args, "content");
32998
+ const path = optionalString(args, "path");
32999
+ let bytes;
33000
+ if (content === undefined && path !== undefined) {
33001
+ try {
33002
+ bytes = await documentFileBytes(uploadedFile(cwd, path), uploadBytes);
33003
+ } catch (error) {
33004
+ return {
33005
+ kind: "refused",
33006
+ refusal: error instanceof Error ? error : new Error(messageFor(error))
33007
+ };
33008
+ }
33009
+ }
33010
+ const check = artifactTextCheck({
33011
+ tool,
33012
+ name: stringArg(args, "name"),
33013
+ content,
33014
+ bytes,
33015
+ force: optionalBoolean(args, "force") === true,
33016
+ textClient: client,
33017
+ fileClient: client
33018
+ });
33019
+ if (check === undefined)
33020
+ return { kind: "passed" };
33021
+ const subject = content === undefined ? "the file" : "the text";
33022
+ 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.";
33023
+ const unasked = (why, then) => ({
33024
+ kind: "passed",
33025
+ warning: `dispatch: warning: the dry run could not ask Dispatch about ${subject}: ${endedSentence(why)} ${then}`
33026
+ });
33027
+ let stored;
33028
+ try {
33029
+ stored = await check();
33030
+ } catch (error) {
33031
+ return unasked(messageFor(error), "The call is refused for the same reason.");
33032
+ }
33033
+ if (stored.kind === "kept" || stored.kind === "reordered")
33034
+ return { kind: "passed" };
33035
+ if (stored.kind === "refused")
33036
+ return { kind: "refused", refusal: stored.refusal };
33037
+ if (stored.kind === "unchecked" && stored.routeAbsent) {
33038
+ return {
33039
+ kind: "passed",
33040
+ warning: `dispatch: warning: this Dispatch cannot check ${subject}: ${endedSentence(stored.failure)} ${uploadsUnchecked}`
33041
+ };
33042
+ }
33043
+ 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.");
33044
+ }
32753
33045
 
32754
33046
  // ../envoy-client/src/dispatch-commands/handoffs.ts
32755
33047
  async function handoffWriteCommand(context) {
@@ -33308,7 +33600,7 @@ async function reviewCommand(context) {
33308
33600
  }
33309
33601
 
33310
33602
  // ../envoy-client/src/session-answers.ts
33311
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync2 } from "fs";
33603
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
33312
33604
  import { join as join5 } from "path";
33313
33605
 
33314
33606
  // ../envoy-client/src/json-line-record.ts
@@ -33449,7 +33741,7 @@ processGlobal2[STATE_KEY] = state;
33449
33741
  var CACHE_FILE = "answers.json";
33450
33742
  function readCacheFile(directory, url) {
33451
33743
  try {
33452
- const value = JSON.parse(readFileSync2(join5(directory, CACHE_FILE), "utf-8"));
33744
+ const value = JSON.parse(readFileSync3(join5(directory, CACHE_FILE), "utf-8"));
33453
33745
  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
33746
  return {
33455
33747
  dispatch_url: value.dispatch_url,
@@ -33924,7 +34216,12 @@ var dispatchCommands = {
33924
34216
  dispatch_review: acting(reviewCommand),
33925
34217
  dispatch_result: acting(resultCommand),
33926
34218
  dispatch_results: acting(resultsCommand),
33927
- dispatch_artifact: acting(artifactCommand),
34219
+ dispatch_artifact: {
34220
+ ...acting(artifactCommand),
34221
+ dryRun: artifactDryRun,
34222
+ documentFields: ["content"],
34223
+ documentPathField: "path"
34224
+ },
33928
34225
  dispatch_handoff_write: acting(handoffWriteCommand),
33929
34226
  dispatch_handoff_read: acting(handoffReadCommand),
33930
34227
  dispatch_steps: acting(stepsCommand),
@@ -33945,7 +34242,7 @@ async function executeDispatchTool(input) {
33945
34242
  if (checked.problems.length > 0)
33946
34243
  throw new ToolInputError(input.tool, checked.problems);
33947
34244
  if (input.dryRun === true && !dryRunAsksDispatch(input.tool, checked.args)) {
33948
- throw new Error(`dispatch ${input.tool}'s dry run asks Dispatch nothing`);
34245
+ throw new Error(`dispatch ${input.tool}'s dry run runs no command`);
33949
34246
  }
33950
34247
  const command = dispatchCommands[input.tool];
33951
34248
  if (command === undefined)
@@ -36558,14 +36855,14 @@ function brokerCredential(env, session, read) {
36558
36855
  }
36559
36856
 
36560
36857
  // ../envoy-client/src/file-token-credential.ts
36561
- import { readFileSync as readFileSync3 } from "fs";
36858
+ import { readFileSync as readFileSync4 } from "fs";
36562
36859
  var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
36563
36860
  var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
36564
36861
  var PKCS8_LABEL = "PRIVATE KEY";
36565
36862
  var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
36566
36863
  function readNamed(variable, filePath) {
36567
36864
  try {
36568
- return readFileSync3(filePath, "utf8");
36865
+ return readFileSync4(filePath, "utf8");
36569
36866
  } catch (error) {
36570
36867
  throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
36571
36868
  }
@@ -37570,7 +37867,7 @@ function claudeProjectDirectory(environment, fallback) {
37570
37867
 
37571
37868
  // src/codex/codex-session-record.ts
37572
37869
  import { spawnSync } from "child_process";
37573
- import { readFileSync as readFileSync5, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
37870
+ import { readFileSync as readFileSync6, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
37574
37871
  import { mkdir as mkdir3, readFile as readFile8, rename as rename4, utimes as utimes3, writeFile as writeFile2 } from "fs/promises";
37575
37872
  import { homedir as homedir3 } from "os";
37576
37873
  import { basename as basename4, dirname as dirname5, join as join11 } from "path";
@@ -37580,7 +37877,7 @@ import { readFile as readFile7 } from "fs/promises";
37580
37877
  import { basename as basename3, join as join10 } from "path";
37581
37878
 
37582
37879
  // src/session-state.ts
37583
- import { readFileSync as readFileSync4 } from "fs";
37880
+ import { readFileSync as readFileSync5 } from "fs";
37584
37881
  import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
37585
37882
  import { dirname as dirname4, join as join9 } from "path";
37586
37883
  async function writeAtomicStateFile(file, contents) {
@@ -37626,7 +37923,7 @@ async function removeChosenTitle(file) {
37626
37923
  }
37627
37924
  function readChosenTitleSync(file) {
37628
37925
  try {
37629
- return readFileSync4(file, "utf8");
37926
+ return readFileSync5(file, "utf8");
37630
37927
  } catch {
37631
37928
  return;
37632
37929
  }
@@ -37819,14 +38116,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
37819
38116
  }
37820
38117
  function procComm(pid) {
37821
38118
  try {
37822
- return readFileSync5(`/proc/${pid}/comm`, "utf8").trim();
38119
+ return readFileSync6(`/proc/${pid}/comm`, "utf8").trim();
37823
38120
  } catch {
37824
38121
  return;
37825
38122
  }
37826
38123
  }
37827
38124
  function procParent(pid) {
37828
38125
  try {
37829
- const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
38126
+ const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
37830
38127
  const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
37831
38128
  return Number.isInteger(parent) ? parent : undefined;
37832
38129
  } catch {
@@ -37840,7 +38137,7 @@ var PS_OPTIONS = {
37840
38137
  };
37841
38138
  function procStarted(pid) {
37842
38139
  try {
37843
- const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
38140
+ const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
37844
38141
  return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
37845
38142
  } catch {
37846
38143
  return;
@@ -37861,7 +38158,7 @@ function recordOfProcess(record, pid) {
37861
38158
  function sharedAppServer(pid) {
37862
38159
  let argv;
37863
38160
  try {
37864
- argv = readFileSync5(`/proc/${pid}/cmdline`, "utf8").split("\x00");
38161
+ argv = readFileSync6(`/proc/${pid}/cmdline`, "utf8").split("\x00");
37865
38162
  } catch {
37866
38163
  const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
37867
38164
  if (ps.status !== 0)