@sjawhar/pi-envoy 17.18.0 → 17.18.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/README.md CHANGED
@@ -383,10 +383,11 @@ a path that reaches a file descriptor of whichever process opens it (`/dev/stdin
383
383
  `/proc/self/fd/N`, `/proc/thread-self/fd/N`, `/proc/<n>/fd/N`, and any link to one): AskGate
384
384
  would open it in Oh My Pi's process and the command in its shell. For text from standard input,
385
385
  use `--<field>-file -` with a quoted here-document. For an upload, that is `--content-file -`:
386
- the CLI reads `--path -` as a file named `-`. The gate cuts all arguments at 64 KiB as one JSON
387
- block, so it reviews only part of a long document. It judges an upload against content failure
388
- 10 alone: a plan or a report is long by nature. An upload of any other file is not reviewed. A
389
- `task` subagent is not reviewed.
386
+ the CLI reads `--path -` as a file named `-`. Only one flag of a call may read standard input.
387
+ The CLI refuses `--<field> -` for each text flag except an upload's `--path`. The gate cuts all
388
+ arguments at 64 KiB as one JSON block, so it reviews only part of a long document. It judges an
389
+ upload against content failure 10 alone: a plan or a report is long by nature. An upload of any
390
+ other file is not reviewed. A `task` subagent is not reviewed.
390
391
 
391
392
  **A file a call of the same message writes.** Oh My Pi runs the gate for every call of a message
392
393
  before any call of that message runs. So the gate reads a file before an earlier call of the same
package/dist/dispatch.js CHANGED
@@ -17633,6 +17633,7 @@ function zodSchemaApi(zod) {
17633
17633
  var STDIN = "-";
17634
17634
  var BARE_WORD = /^[A-Za-z0-9_./:@%+=,-]+$/;
17635
17635
  var OPTION_SEPARATOR = ": ";
17636
+ var LOCAL_FILE_FIELD = { tool: "dispatch_artifact", field: "path" };
17636
17637
  function commandName(tool) {
17637
17638
  return tool.replace(/^dispatch_/, "").replaceAll("_", "-");
17638
17639
  }
@@ -17885,6 +17886,7 @@ function parseCommand(argv, io) {
17885
17886
  const args = {};
17886
17887
  const setBy = new Map;
17887
17888
  const problems = [];
17889
+ const bareDashes = new Set;
17888
17890
  let help = false;
17889
17891
  let dryRun = false;
17890
17892
  let stdinFlag;
@@ -18001,6 +18003,10 @@ function parseCommand(argv, io) {
18001
18003
  const parsed = info.kind === "number" ? number(flag, value) : value;
18002
18004
  if (claimed && parsed !== undefined)
18003
18005
  args[field] = parsed;
18006
+ if (info.kind === "string" && value === STDIN && !(tool === LOCAL_FILE_FIELD.tool && field === LOCAL_FILE_FIELD.field) && !bareDashes.has(flag)) {
18007
+ bareDashes.add(flag);
18008
+ problems.push(`${flag} - sends the one character "-". ${flag}-file <path> reads ${flag} from a file, and ${flag}-file - reads it from stdin. One flag of a call may read stdin.`);
18009
+ }
18004
18010
  break;
18005
18011
  }
18006
18012
  case "file": {
@@ -18032,8 +18038,9 @@ function parseCommand(argv, io) {
18032
18038
  }
18033
18039
  if (help)
18034
18040
  return { kind: "help", tool };
18035
- if (problems.length > 0)
18036
- return { kind: "refused", tool, problems };
18041
+ if (problems.length > 0) {
18042
+ return problems.length === bareDashes.size ? { kind: "refused", tool, problems, aboutAFlag: false } : { kind: "refused", tool, problems };
18043
+ }
18037
18044
  return { kind: "call", tool, args, dryRun };
18038
18045
  }
18039
18046
  function appendedItem(kind, flag, value, number) {
@@ -18139,238 +18146,14 @@ function commandsHelp() {
18139
18146
  `);
18140
18147
  }
18141
18148
 
18142
- // ../envoy-client/src/dispatch-cwd.ts
18143
- import { execFile } from "child_process";
18144
- import { promisify } from "util";
18145
-
18146
- // ../envoy-client/src/machine.ts
18147
- import { hostname as hostname3 } from "os";
18148
- function machineID() {
18149
- return process.env["ENVOY_MACHINE_ID"] || process.env["AGENTBOX_HOST"] || hostname3();
18150
- }
18151
-
18152
- // ../envoy-client/src/dispatch-cwd.ts
18153
- var execFileAsync = promisify(execFile);
18154
- var defaultExec = (file, args, { cwd, signal }) => {
18155
- const call = execFileAsync(file, args, { cwd, signal });
18156
- const kill = () => call.child.kill("SIGKILL");
18157
- if (signal.aborted)
18158
- kill();
18159
- else
18160
- signal.addEventListener("abort", kill, { once: true });
18161
- return call;
18162
- };
18163
- var REMOTE_LOOKUP_MS = 5000;
18164
- var TMUX_PANE_LOOKUP_MS = 1000;
18165
- async function tryExec(exec, file, args, cwd, limitMs) {
18166
- const controller = new AbortController;
18167
- const expired = Promise.withResolvers();
18168
- const timer = setTimeout(() => {
18169
- controller.abort();
18170
- expired.resolve(null);
18171
- }, limitMs);
18172
- try {
18173
- const answer = await Promise.race([
18174
- exec(file, args, { cwd, signal: controller.signal }),
18175
- expired.promise
18176
- ]);
18177
- if (answer === null) {
18178
- return { failure: "timedOut", ok: false };
18179
- }
18180
- return { ok: true, stdout: answer.stdout };
18181
- } catch {
18182
- return { failure: "refused", ok: false };
18183
- } finally {
18184
- clearTimeout(timer);
18185
- }
18186
- }
18187
- function parseRemoteList(stdout) {
18188
- const remotes = new Map;
18189
- for (const line of stdout.split(`
18190
- `)) {
18191
- const trimmed = line.trim();
18192
- if (!trimmed)
18193
- continue;
18194
- const match = trimmed.match(/^(\S+)\s+(\S+)/);
18195
- const [, name, url] = match ?? [];
18196
- if (name && url)
18197
- remotes.set(name, url);
18198
- }
18199
- return remotes;
18200
- }
18201
- function selectRemoteUrl(remotes) {
18202
- const origin = remotes.get("origin");
18203
- if (origin)
18204
- return origin;
18205
- const candidates = [...remotes.entries()].filter(([name]) => name !== "upstream");
18206
- return candidates.length === 1 ? candidates[0]?.[1] ?? null : null;
18207
- }
18208
- var GITHUB_REMOTE_PATTERNS = [
18209
- /^https:\/\/(?:[^@/\s]+@)?github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
18210
- /^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
18211
- /^ssh:\/\/git@github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i
18212
- ];
18213
- function parseGitHubRemoteUrl(url) {
18214
- const trimmed = url.trim();
18215
- for (const pattern of GITHUB_REMOTE_PATTERNS) {
18216
- const match = trimmed.match(pattern);
18217
- if (match)
18218
- return canonicalRepo(match[1] ?? "", match[2] ?? "");
18219
- }
18220
- return null;
18221
- }
18222
- async function resolveCwdRepo(cwd, exec) {
18223
- const remoteList = await tryExec(exec, "jj", ["git", "remote", "list"], cwd, REMOTE_LOOKUP_MS);
18224
- if (remoteList.ok) {
18225
- const url = selectRemoteUrl(parseRemoteList(remoteList.stdout));
18226
- return url ? parseGitHubRemoteUrl(url) : null;
18227
- }
18228
- const originRemote = await tryExec(exec, "git", ["remote", "get-url", "origin"], cwd, REMOTE_LOOKUP_MS);
18229
- return originRemote.ok ? parseGitHubRemoteUrl(originRemote.stdout) : null;
18230
- }
18231
- async function resolveOrigin(env, exec, cwd) {
18232
- const origin = {
18233
- cwd,
18234
- machine: machineID()
18235
- };
18236
- const pane = env.TMUX_PANE;
18237
- if (pane) {
18238
- const answer = await tryExec(exec, "tmux", ["display-message", "-p", "-t", pane, "#S:#I.#P #{pane_id}"], cwd, TMUX_PANE_LOOKUP_MS);
18239
- const [target, paneId] = answer.ok ? answer.stdout.trim().split(" ") : [];
18240
- if (target)
18241
- origin.tmux = target;
18242
- if (paneId)
18243
- origin.pane = paneId;
18244
- }
18245
- return origin;
18246
- }
18247
-
18248
- // ../envoy-client/src/dispatch-owner.ts
18249
- function documentLabel(project, slug) {
18250
- return `${project}/${slug}`;
18251
- }
18252
- function ownerTitle(owner) {
18253
- const { issue, document } = owner;
18254
- if (issue !== undefined)
18255
- return `${issue.key}: ${issue.title}`;
18256
- if (document !== undefined)
18257
- return `${document.project} / ${document.name}`;
18258
- return "";
18259
- }
18260
- function issueTopic(key) {
18261
- return { label: key, topic: dispatchIssueSubject(key, ">") };
18262
- }
18263
- function documentTopicOf(project, slug) {
18264
- return {
18265
- label: documentLabel(project, slug),
18266
- topic: dispatchDocumentSubject(project, slug, ">")
18267
- };
18268
- }
18269
- function dispatchIssueRef(key) {
18270
- return `dispatch://${key}`;
18271
- }
18272
- function dispatchDocumentRef(owner, slug) {
18273
- return `dispatch://${owner}/artifact/${slug}`;
18274
- }
18275
- var ITEM_KINDS = ["ask", "comment", "message"];
18276
- function dispatchChildRef(ownerRef, kind, id) {
18277
- return `${ownerRef}/${kind}/${id}`;
18278
- }
18279
- function parseBlockRef(holder, fragment) {
18280
- const target = holder.includes("@") ? undefined : parseBlockFragment(fragment);
18281
- const parsed = parseDispatchRef(holder);
18282
- if (target === undefined || parsed === null) {
18283
- return null;
18284
- }
18285
- const pin = target.pin === undefined ? {} : { pin: target.pin };
18286
- const artifact = parsed.artifact === undefined ? {} : { artifact: parsed.artifact };
18287
- if (parsed.kind === "ask" || parsed.kind === "comment" || parsed.kind === "message" && target.pin === undefined) {
18288
- return {
18289
- owner: parsed.owner,
18290
- kind: "block",
18291
- id: parsed.id,
18292
- block: target.block,
18293
- item: { kind: parsed.kind, id: parsed.id },
18294
- ...artifact,
18295
- ...pin
18296
- };
18297
- }
18298
- if (parsed.kind !== "spec" && parsed.kind !== "artifact") {
18299
- return null;
18300
- }
18301
- return {
18302
- owner: parsed.owner,
18303
- kind: "block",
18304
- id: parsed.id,
18305
- block: target.block,
18306
- document: holder,
18307
- ...parsed.owner.kind === "project" ? { artifact: parsed.id } : {},
18308
- ...pin
18309
- };
18310
- }
18311
- function parseDispatchRef(ref) {
18312
- const hash = ref.indexOf("#");
18313
- if (hash !== -1 && ref.startsWith("b-", hash + 1)) {
18314
- return parseBlockRef(ref.slice(0, hash), ref.slice(hash + 3));
18315
- }
18316
- const projectDocument = ref.match(/^dispatch:\/\/([A-Z][A-Z0-9]{1,9})\/artifact\/([^/@]+)(?:@v(\d+))?(?:\/(ask|comment)\/([^/]+))?$/);
18317
- if (projectDocument) {
18318
- const [, project, artifact, version, targetKind, targetID] = projectDocument;
18319
- if (project === undefined || artifact === undefined || version !== undefined && Number(version) < 1) {
18320
- return null;
18321
- }
18322
- if (targetKind === undefined) {
18323
- return {
18324
- owner: { kind: "project", project },
18325
- kind: "artifact",
18326
- id: artifact,
18327
- ...version === undefined ? {} : { version: Number(version) }
18328
- };
18329
- }
18330
- if (version !== undefined)
18331
- return null;
18332
- if (targetID === undefined || targetKind !== "ask" && targetKind !== "comment")
18333
- return null;
18334
- return {
18335
- owner: { kind: "project", project },
18336
- kind: targetKind,
18337
- id: targetID,
18338
- artifact
18339
- };
18340
- }
18341
- const issueReference = ref.match(/^dispatch:\/\/([A-Z][A-Z0-9]{1,9}-[1-9][0-9]*)(?:\/(spec)|\/(log|activity)|\/(children)|\/artifact\/([^/@]+)(?:@v(\d+))?|\/ask\/([^/]+)|\/comment\/([^/]+)|\/message\/([^/]+))?$/);
18342
- if (!issueReference)
18343
- return null;
18344
- const [, issue, spec, log, children, artifact, version, ask, comment, message] = issueReference;
18345
- if (!issue || version !== undefined && Number(version) < 1)
18346
- return null;
18347
- const owner = { kind: "issue", issue };
18348
- if (spec)
18349
- return { owner, kind: "spec", id: spec };
18350
- if (log)
18351
- return { owner, kind: "log", id: log };
18352
- if (children)
18353
- return { owner, kind: "children", id: children };
18354
- if (artifact) {
18355
- return {
18356
- owner,
18357
- kind: "artifact",
18358
- id: artifact,
18359
- ...version === undefined ? {} : { version: Number(version) }
18360
- };
18361
- }
18362
- if (ask)
18363
- return { owner, kind: "ask", id: ask };
18364
- if (comment)
18365
- return { owner, kind: "comment", id: comment };
18366
- if (message)
18367
- return { owner, kind: "message", id: message };
18368
- return { owner, kind: "issue", id: issue };
18149
+ // ../contracts/src/trailing-slash.ts
18150
+ function withoutTrailingSlashes(url) {
18151
+ let end = url.length;
18152
+ while (end > 0 && url[end - 1] === "/")
18153
+ end -= 1;
18154
+ return url.slice(0, end);
18369
18155
  }
18370
18156
 
18371
- // ../envoy-client/src/dispatch-picture-tools.ts
18372
- import { basename, resolve as resolvePath } from "path";
18373
-
18374
18157
  // ../envoy-client/src/ask-answer.ts
18375
18158
  var HEAD_LENGTH = 120;
18376
18159
  function textHead(text, length = HEAD_LENGTH) {
@@ -18396,14 +18179,6 @@ function askAnswerText(answer) {
18396
18179
  return `${selected} - ${text}`;
18397
18180
  }
18398
18181
 
18399
- // ../contracts/src/trailing-slash.ts
18400
- function withoutTrailingSlashes(url) {
18401
- let end = url.length;
18402
- while (end > 0 && url[end - 1] === "/")
18403
- end -= 1;
18404
- return url.slice(0, end);
18405
- }
18406
-
18407
18182
  // ../envoy-client/src/dispatch-http.ts
18408
18183
  class DispatchServiceError extends Error {
18409
18184
  code;
@@ -19366,16 +19141,335 @@ class DispatchClient {
19366
19141
  }
19367
19142
  }
19368
19143
 
19369
- // ../envoy-client/src/dispatch-pictures.ts
19370
- var PICTURE_UPLOAD_MAX_BYTES = 25 * 1024 * 1024;
19371
- var PICTURE_SHOWN_MAX_BYTES = 3750000;
19372
- var pictureShownMaxText = `${PICTURE_SHOWN_MAX_BYTES.toLocaleString("en-US")} bytes (5 MB of base64)`;
19373
- function oversizePictureText(name, bytes) {
19374
- return `${name} is ${bytes.toLocaleString("en-US")} bytes, over the ${pictureShownMaxText} a model is shown`;
19375
- }
19376
- var PICTURES_SHOWN_MAX = 8;
19377
- var PICTURES_SHOWN_MAX_BYTES = 10 * 1024 * 1024;
19378
- var PICTURE_SNIFF_BYTES = 12;
19144
+ // ../envoy-client/src/dispatch-commands/context.ts
19145
+ function stringArg(args, name) {
19146
+ const value = args[name];
19147
+ if (typeof value !== "string")
19148
+ throw new Error(`${name} is required`);
19149
+ return value;
19150
+ }
19151
+ function numberArg(args, name) {
19152
+ const value = args[name];
19153
+ if (typeof value !== "number")
19154
+ throw new Error(`${name} is required`);
19155
+ return value;
19156
+ }
19157
+ function optionalString(args, name) {
19158
+ const value = args[name];
19159
+ return typeof value === "string" ? value : undefined;
19160
+ }
19161
+ function optionalNullableString(args, name) {
19162
+ const value = args[name];
19163
+ if (value === null)
19164
+ return null;
19165
+ return typeof value === "string" ? value : undefined;
19166
+ }
19167
+ function optionalBoolean(args, name) {
19168
+ const value = args[name];
19169
+ return typeof value === "boolean" ? value : undefined;
19170
+ }
19171
+ function optionalNumber(args, name) {
19172
+ const value = args[name];
19173
+ return typeof value === "number" ? value : undefined;
19174
+ }
19175
+ function defined(name, value) {
19176
+ return value === undefined ? {} : { [name]: value };
19177
+ }
19178
+ function optionalStringArray(args, name) {
19179
+ const value = args[name];
19180
+ return Array.isArray(value) ? value : undefined;
19181
+ }
19182
+ function optionalPriority(args, name) {
19183
+ const value = args[name];
19184
+ if (value === null)
19185
+ return null;
19186
+ return typeof value === "number" ? value : undefined;
19187
+ }
19188
+ function optionalPriorityFilter(args, name) {
19189
+ const value = args[name];
19190
+ return Array.isArray(value) ? value.map((item) => item ?? "none") : undefined;
19191
+ }
19192
+ function optionalComponents(args, name) {
19193
+ const value = args[name];
19194
+ if (typeof value !== "object" || value === null)
19195
+ return;
19196
+ const input = value;
19197
+ return {
19198
+ mode: input.mode,
19199
+ ...input.ids === undefined ? {} : { ids: input.ids },
19200
+ ...input.reason === undefined ? {} : { reason: input.reason }
19201
+ };
19202
+ }
19203
+ function asObject(value) {
19204
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
19205
+ }
19206
+ function sessionContext(input, checked) {
19207
+ const { url: configUrl, credential } = input.config;
19208
+ const baseFetch = input.fetchImpl ?? fetch;
19209
+ const fetchImpl = Object.assign(async (...args) => {
19210
+ try {
19211
+ return await baseFetch(...args);
19212
+ } catch (error) {
19213
+ if (error instanceof TypeError) {
19214
+ throw new Error(`Dispatch at ${configUrl} is unreachable: ${error.message}. If the Dispatch URL changed, restart this agent process so it picks up the new configuration.`);
19215
+ }
19216
+ throw error;
19217
+ }
19218
+ }, { preconnect: baseFetch.preconnect });
19219
+ return {
19220
+ input,
19221
+ args: checked.args,
19222
+ ownerArguments: checked.owner,
19223
+ pictures: checked.pictures,
19224
+ configUrl,
19225
+ linkBase: input.config.publicUrl ?? configUrl,
19226
+ hostSession: input.sessionId?.trim(),
19227
+ newClient: () => new DispatchClient(configUrl, credential, fetchImpl, input.signal, input.writeRetry)
19228
+ };
19229
+ }
19230
+
19231
+ // ../envoy-client/src/dispatch-cwd.ts
19232
+ import { execFile } from "child_process";
19233
+ import { promisify } from "util";
19234
+
19235
+ // ../envoy-client/src/machine.ts
19236
+ import { hostname as hostname3 } from "os";
19237
+ function machineID() {
19238
+ return process.env["ENVOY_MACHINE_ID"] || process.env["AGENTBOX_HOST"] || hostname3();
19239
+ }
19240
+
19241
+ // ../envoy-client/src/dispatch-cwd.ts
19242
+ var execFileAsync = promisify(execFile);
19243
+ var defaultExec = (file, args, { cwd, signal }) => {
19244
+ const call = execFileAsync(file, args, { cwd, signal });
19245
+ const kill = () => call.child.kill("SIGKILL");
19246
+ if (signal.aborted)
19247
+ kill();
19248
+ else
19249
+ signal.addEventListener("abort", kill, { once: true });
19250
+ return call;
19251
+ };
19252
+ var REMOTE_LOOKUP_MS = 5000;
19253
+ var TMUX_PANE_LOOKUP_MS = 1000;
19254
+ async function tryExec(exec, file, args, cwd, limitMs) {
19255
+ const controller = new AbortController;
19256
+ const expired = Promise.withResolvers();
19257
+ const timer = setTimeout(() => {
19258
+ controller.abort();
19259
+ expired.resolve(null);
19260
+ }, limitMs);
19261
+ try {
19262
+ const answer = await Promise.race([
19263
+ exec(file, args, { cwd, signal: controller.signal }),
19264
+ expired.promise
19265
+ ]);
19266
+ if (answer === null) {
19267
+ return { failure: "timedOut", ok: false };
19268
+ }
19269
+ return { ok: true, stdout: answer.stdout };
19270
+ } catch {
19271
+ return { failure: "refused", ok: false };
19272
+ } finally {
19273
+ clearTimeout(timer);
19274
+ }
19275
+ }
19276
+ function parseRemoteList(stdout) {
19277
+ const remotes = new Map;
19278
+ for (const line of stdout.split(`
19279
+ `)) {
19280
+ const trimmed = line.trim();
19281
+ if (!trimmed)
19282
+ continue;
19283
+ const match = trimmed.match(/^(\S+)\s+(\S+)/);
19284
+ const [, name, url] = match ?? [];
19285
+ if (name && url)
19286
+ remotes.set(name, url);
19287
+ }
19288
+ return remotes;
19289
+ }
19290
+ function selectRemoteUrl(remotes) {
19291
+ const origin = remotes.get("origin");
19292
+ if (origin)
19293
+ return origin;
19294
+ const candidates = [...remotes.entries()].filter(([name]) => name !== "upstream");
19295
+ return candidates.length === 1 ? candidates[0]?.[1] ?? null : null;
19296
+ }
19297
+ var GITHUB_REMOTE_PATTERNS = [
19298
+ /^https:\/\/(?:[^@/\s]+@)?github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
19299
+ /^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?\/?$/i,
19300
+ /^ssh:\/\/git@github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i
19301
+ ];
19302
+ function parseGitHubRemoteUrl(url) {
19303
+ const trimmed = url.trim();
19304
+ for (const pattern of GITHUB_REMOTE_PATTERNS) {
19305
+ const match = trimmed.match(pattern);
19306
+ if (match)
19307
+ return canonicalRepo(match[1] ?? "", match[2] ?? "");
19308
+ }
19309
+ return null;
19310
+ }
19311
+ async function resolveCwdRepo(cwd, exec) {
19312
+ const remoteList = await tryExec(exec, "jj", ["git", "remote", "list"], cwd, REMOTE_LOOKUP_MS);
19313
+ if (remoteList.ok) {
19314
+ const url = selectRemoteUrl(parseRemoteList(remoteList.stdout));
19315
+ return url ? parseGitHubRemoteUrl(url) : null;
19316
+ }
19317
+ const originRemote = await tryExec(exec, "git", ["remote", "get-url", "origin"], cwd, REMOTE_LOOKUP_MS);
19318
+ return originRemote.ok ? parseGitHubRemoteUrl(originRemote.stdout) : null;
19319
+ }
19320
+ async function resolveOrigin(env, exec, cwd) {
19321
+ const origin = {
19322
+ cwd,
19323
+ machine: machineID()
19324
+ };
19325
+ const pane = env.TMUX_PANE;
19326
+ if (pane) {
19327
+ const answer = await tryExec(exec, "tmux", ["display-message", "-p", "-t", pane, "#S:#I.#P #{pane_id}"], cwd, TMUX_PANE_LOOKUP_MS);
19328
+ const [target, paneId] = answer.ok ? answer.stdout.trim().split(" ") : [];
19329
+ if (target)
19330
+ origin.tmux = target;
19331
+ if (paneId)
19332
+ origin.pane = paneId;
19333
+ }
19334
+ return origin;
19335
+ }
19336
+
19337
+ // ../envoy-client/src/dispatch-owner.ts
19338
+ function documentLabel(project, slug) {
19339
+ return `${project}/${slug}`;
19340
+ }
19341
+ function ownerTitle(owner) {
19342
+ const { issue, document } = owner;
19343
+ if (issue !== undefined)
19344
+ return `${issue.key}: ${issue.title}`;
19345
+ if (document !== undefined)
19346
+ return `${document.project} / ${document.name}`;
19347
+ return "";
19348
+ }
19349
+ function issueTopic(key) {
19350
+ return { label: key, topic: dispatchIssueSubject(key, ">") };
19351
+ }
19352
+ function documentTopicOf(project, slug) {
19353
+ return {
19354
+ label: documentLabel(project, slug),
19355
+ topic: dispatchDocumentSubject(project, slug, ">")
19356
+ };
19357
+ }
19358
+ function dispatchIssueRef(key) {
19359
+ return `dispatch://${key}`;
19360
+ }
19361
+ function dispatchDocumentRef(owner, slug) {
19362
+ return `dispatch://${owner}/artifact/${slug}`;
19363
+ }
19364
+ var ITEM_KINDS = ["ask", "comment", "message"];
19365
+ function dispatchChildRef(ownerRef, kind, id) {
19366
+ return `${ownerRef}/${kind}/${id}`;
19367
+ }
19368
+ function parseBlockRef(holder, fragment) {
19369
+ const target = holder.includes("@") ? undefined : parseBlockFragment(fragment);
19370
+ const parsed = parseDispatchRef(holder);
19371
+ if (target === undefined || parsed === null) {
19372
+ return null;
19373
+ }
19374
+ const pin = target.pin === undefined ? {} : { pin: target.pin };
19375
+ const artifact = parsed.artifact === undefined ? {} : { artifact: parsed.artifact };
19376
+ if (parsed.kind === "ask" || parsed.kind === "comment" || parsed.kind === "message" && target.pin === undefined) {
19377
+ return {
19378
+ owner: parsed.owner,
19379
+ kind: "block",
19380
+ id: parsed.id,
19381
+ block: target.block,
19382
+ item: { kind: parsed.kind, id: parsed.id },
19383
+ ...artifact,
19384
+ ...pin
19385
+ };
19386
+ }
19387
+ if (parsed.kind !== "spec" && parsed.kind !== "artifact") {
19388
+ return null;
19389
+ }
19390
+ return {
19391
+ owner: parsed.owner,
19392
+ kind: "block",
19393
+ id: parsed.id,
19394
+ block: target.block,
19395
+ document: holder,
19396
+ ...parsed.owner.kind === "project" ? { artifact: parsed.id } : {},
19397
+ ...pin
19398
+ };
19399
+ }
19400
+ function parseDispatchRef(ref) {
19401
+ const hash = ref.indexOf("#");
19402
+ if (hash !== -1 && ref.startsWith("b-", hash + 1)) {
19403
+ return parseBlockRef(ref.slice(0, hash), ref.slice(hash + 3));
19404
+ }
19405
+ const projectDocument = ref.match(/^dispatch:\/\/([A-Z][A-Z0-9]{1,9})\/artifact\/([^/@]+)(?:@v(\d+))?(?:\/(ask|comment)\/([^/]+))?$/);
19406
+ if (projectDocument) {
19407
+ const [, project, artifact, version, targetKind, targetID] = projectDocument;
19408
+ if (project === undefined || artifact === undefined || version !== undefined && Number(version) < 1) {
19409
+ return null;
19410
+ }
19411
+ if (targetKind === undefined) {
19412
+ return {
19413
+ owner: { kind: "project", project },
19414
+ kind: "artifact",
19415
+ id: artifact,
19416
+ ...version === undefined ? {} : { version: Number(version) }
19417
+ };
19418
+ }
19419
+ if (version !== undefined)
19420
+ return null;
19421
+ if (targetID === undefined || targetKind !== "ask" && targetKind !== "comment")
19422
+ return null;
19423
+ return {
19424
+ owner: { kind: "project", project },
19425
+ kind: targetKind,
19426
+ id: targetID,
19427
+ artifact
19428
+ };
19429
+ }
19430
+ const issueReference = ref.match(/^dispatch:\/\/([A-Z][A-Z0-9]{1,9}-[1-9][0-9]*)(?:\/(spec)|\/(log|activity)|\/(children)|\/artifact\/([^/@]+)(?:@v(\d+))?|\/ask\/([^/]+)|\/comment\/([^/]+)|\/message\/([^/]+))?$/);
19431
+ if (!issueReference)
19432
+ return null;
19433
+ const [, issue, spec, log, children, artifact, version, ask, comment, message] = issueReference;
19434
+ if (!issue || version !== undefined && Number(version) < 1)
19435
+ return null;
19436
+ const owner = { kind: "issue", issue };
19437
+ if (spec)
19438
+ return { owner, kind: "spec", id: spec };
19439
+ if (log)
19440
+ return { owner, kind: "log", id: log };
19441
+ if (children)
19442
+ return { owner, kind: "children", id: children };
19443
+ if (artifact) {
19444
+ return {
19445
+ owner,
19446
+ kind: "artifact",
19447
+ id: artifact,
19448
+ ...version === undefined ? {} : { version: Number(version) }
19449
+ };
19450
+ }
19451
+ if (ask)
19452
+ return { owner, kind: "ask", id: ask };
19453
+ if (comment)
19454
+ return { owner, kind: "comment", id: comment };
19455
+ if (message)
19456
+ return { owner, kind: "message", id: message };
19457
+ return { owner, kind: "issue", id: issue };
19458
+ }
19459
+
19460
+ // ../envoy-client/src/dispatch-picture-tools.ts
19461
+ import { basename, resolve as resolvePath } from "path";
19462
+
19463
+ // ../envoy-client/src/dispatch-pictures.ts
19464
+ var PICTURE_UPLOAD_MAX_BYTES = 25 * 1024 * 1024;
19465
+ var PICTURE_SHOWN_MAX_BYTES = 3750000;
19466
+ var pictureShownMaxText = `${PICTURE_SHOWN_MAX_BYTES.toLocaleString("en-US")} bytes (5 MB of base64)`;
19467
+ function oversizePictureText(name, bytes) {
19468
+ return `${name} is ${bytes.toLocaleString("en-US")} bytes, over the ${pictureShownMaxText} a model is shown`;
19469
+ }
19470
+ var PICTURES_SHOWN_MAX = 8;
19471
+ var PICTURES_SHOWN_MAX_BYTES = 10 * 1024 * 1024;
19472
+ var PICTURE_SNIFF_BYTES = 12;
19379
19473
  function bytesAt(bytes, offset, expected) {
19380
19474
  return expected.every((byte, index) => bytes[offset + index] === byte);
19381
19475
  }
@@ -19913,93 +20007,6 @@ function formatZodIssues(issues, schema, tool) {
19913
20007
  });
19914
20008
  }
19915
20009
 
19916
- // ../envoy-client/src/dispatch-commands/context.ts
19917
- function stringArg(args, name) {
19918
- const value = args[name];
19919
- if (typeof value !== "string")
19920
- throw new Error(`${name} is required`);
19921
- return value;
19922
- }
19923
- function numberArg(args, name) {
19924
- const value = args[name];
19925
- if (typeof value !== "number")
19926
- throw new Error(`${name} is required`);
19927
- return value;
19928
- }
19929
- function optionalString(args, name) {
19930
- const value = args[name];
19931
- return typeof value === "string" ? value : undefined;
19932
- }
19933
- function optionalNullableString(args, name) {
19934
- const value = args[name];
19935
- if (value === null)
19936
- return null;
19937
- return typeof value === "string" ? value : undefined;
19938
- }
19939
- function optionalBoolean(args, name) {
19940
- const value = args[name];
19941
- return typeof value === "boolean" ? value : undefined;
19942
- }
19943
- function optionalNumber(args, name) {
19944
- const value = args[name];
19945
- return typeof value === "number" ? value : undefined;
19946
- }
19947
- function defined(name, value) {
19948
- return value === undefined ? {} : { [name]: value };
19949
- }
19950
- function optionalStringArray(args, name) {
19951
- const value = args[name];
19952
- return Array.isArray(value) ? value : undefined;
19953
- }
19954
- function optionalPriority(args, name) {
19955
- const value = args[name];
19956
- if (value === null)
19957
- return null;
19958
- return typeof value === "number" ? value : undefined;
19959
- }
19960
- function optionalPriorityFilter(args, name) {
19961
- const value = args[name];
19962
- return Array.isArray(value) ? value.map((item) => item ?? "none") : undefined;
19963
- }
19964
- function optionalComponents(args, name) {
19965
- const value = args[name];
19966
- if (typeof value !== "object" || value === null)
19967
- return;
19968
- const input = value;
19969
- return {
19970
- mode: input.mode,
19971
- ...input.ids === undefined ? {} : { ids: input.ids },
19972
- ...input.reason === undefined ? {} : { reason: input.reason }
19973
- };
19974
- }
19975
- function asObject(value) {
19976
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
19977
- }
19978
- function sessionContext(input, checked) {
19979
- const { url: configUrl, credential } = input.config;
19980
- const baseFetch = input.fetchImpl ?? fetch;
19981
- const fetchImpl = Object.assign(async (...args) => {
19982
- try {
19983
- return await baseFetch(...args);
19984
- } catch (error) {
19985
- if (error instanceof TypeError) {
19986
- throw new Error(`Dispatch at ${configUrl} is unreachable: ${error.message}. If the Dispatch URL changed, restart this agent process so it picks up the new configuration.`);
19987
- }
19988
- throw error;
19989
- }
19990
- }, { preconnect: baseFetch.preconnect });
19991
- return {
19992
- input,
19993
- args: checked.args,
19994
- ownerArguments: checked.owner,
19995
- pictures: checked.pictures,
19996
- configUrl,
19997
- linkBase: input.config.publicUrl ?? configUrl,
19998
- hostSession: input.sessionId?.trim(),
19999
- newClient: () => new DispatchClient(configUrl, credential, fetchImpl, input.signal, input.writeRetry)
20000
- };
20001
- }
20002
-
20003
20010
  // ../envoy-client/src/dispatch-commands/refs.ts
20004
20011
  var canonicalUUIDPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
20005
20012
  var compactUUIDPattern = /^[0-9a-f]{32}$/i;
@@ -28086,7 +28093,7 @@ async function runDispatchCli(argv, rawEnv, io) {
28086
28093
  if (parsed.kind === "refused") {
28087
28094
  return parsed.tool === undefined ? refuse([`dispatch: ${parsed.problems.join(`
28088
28095
  `)}`, "Run dispatch --help."].join(`
28089
- `), USAGE) : refuse(new ToolInputError(parsed.tool, parsed.problems).message, USAGE, parsed.tool);
28096
+ `), USAGE) : refuse(new ToolInputError(parsed.tool, parsed.problems, defined("aboutAFlag", parsed.aboutAFlag)).message, USAGE, parsed.tool);
28090
28097
  }
28091
28098
  const hostName = env.DISPATCH_HOST ?? (env.CLAUDE_CODE_CHILD_SESSION === "1" ? "claude" : undefined);
28092
28099
  const host = HOSTS.find((name) => name === hostName);
package/dist/envoy.js CHANGED
@@ -46663,7 +46663,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
46663
46663
 
46664
46664
  // package.json
46665
46665
  var name = "@sjawhar/pi-envoy";
46666
- var version2 = "17.18.0";
46666
+ var version2 = "17.18.1";
46667
46667
  var package_default = {
46668
46668
  name,
46669
46669
  version: version2,
@@ -8,7 +8,7 @@ description: "Use before your first dispatch command in a session: a message, co
8
8
  Dispatch is a record for the people who decide, never a log of your work.
9
9
 
10
10
  - Use the `dispatch` command; the HTTP API only for what no command does. `dispatch <command> --help` gives its rules and an example.
11
- - Put long text on stdin: `--<field>-file -` with a quoted here-document (`<<'EOF'`); give object and list fields as JSON.
11
+ - Put long text on stdin, one flag per call: `--<field>-file -` with `<<'EOF'`; objects and lists take JSON.
12
12
  - Exit 1 is a refusal, 2 a usage error. A refusal lists every problem: fix all, call once.
13
13
  - Never work around a hard-to-use command, or one storing or losing something wrongly: open an issue in the owning project and tell its controller. A Legion role tells its architect (`skill://legion-worker/references/findings.md`).
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-envoy",
3
- "version": "17.18.0",
3
+ "version": "17.18.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {