@sjawhar/claude-envoy 5.27.2 → 5.28.0

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/dist/dispatch.js CHANGED
@@ -1208,17 +1208,19 @@ function errorClass(error) {
1208
1208
  }
1209
1209
 
1210
1210
  // ../envoy-client/src/errors.ts
1211
- function dispatchCode(error) {
1212
- if (!("fromDispatch" in error) || !("code" in error))
1211
+ function dispatchField(error, field) {
1212
+ if (!("fromDispatch" in error))
1213
1213
  return;
1214
- const code = error.code;
1215
- return typeof code === "string" && code !== "" ? code : undefined;
1214
+ const value = Reflect.get(error, field);
1215
+ return typeof value === "string" && value !== "" ? value : undefined;
1216
1216
  }
1217
1217
  function messageFor(error) {
1218
1218
  if (!(error instanceof Error))
1219
1219
  return scrub(String(error));
1220
- const code = dispatchCode(error);
1221
- return scrub(code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`);
1220
+ const code = dispatchField(error, "code");
1221
+ const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
1222
+ const hint = dispatchField(error, "hint");
1223
+ return scrub(hint === undefined ? message : `${message}; ${hint}`);
1222
1224
  }
1223
1225
  function hasErrnoCode(error, code) {
1224
1226
  return error instanceof Error && "code" in error && error.code === code;
@@ -15089,6 +15091,25 @@ var projectKeyValidation = {
15089
15091
  message: `project is not a project key: ${PROJECT_KEY_RULE}`
15090
15092
  };
15091
15093
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
15094
+ var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
15095
+ var API_PATH_RULE = "path is a route under /api/v1: it begins /api/v1 and names no scheme or host, every character is printable ASCII other than a space, a backslash and #, and no segment before the query is . or ..";
15096
+ function apiPathProblem(value) {
15097
+ const { path } = value;
15098
+ if (typeof path !== "string")
15099
+ return;
15100
+ const named = JSON.stringify(path);
15101
+ if (!API_ROUTE_PATTERN.test(path)) {
15102
+ return `path ${named} is no route under /api/v1: give the route alone, beginning /api/v1, with no scheme or host (dispatch api --path /api/v1 lists every route).`;
15103
+ }
15104
+ if (!/^[!-~]*$/.test(path) || /[\\#]/.test(path)) {
15105
+ return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
15106
+ }
15107
+ const route = path.split("?", 1)[0] ?? "";
15108
+ if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
15109
+ return `path ${named} holds a . or .. segment: name the route itself.`;
15110
+ }
15111
+ return;
15112
+ }
15092
15113
  var ISSUE_STATUSES = [
15093
15114
  "triage",
15094
15115
  "icebox",
@@ -15694,6 +15715,20 @@ var dispatchToolSpecs = [
15694
15715
  arguments: () => ({}),
15695
15716
  strict: true
15696
15717
  },
15718
+ {
15719
+ name: "dispatch_api",
15720
+ example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
15721
+ description: "Read one route of Dispatch's HTTP API that no other command reads, with this session's own credential, and print Dispatch's JSON answer, for jq to read. It sends one GET of path: a route beginning /api/v1, with its query after ?; dispatch api --path /api/v1 lists every route. It only reads: it takes no method and no body, and every write goes through the command named for it (dispatch --help lists them). When Dispatch refuses the read, the command prints Dispatch's error with its code and, where Dispatch gives one, its hint, and exits 1. Under Claude Code, an answer longer than the output limit is written to a file the output names.",
15722
+ arguments: (z) => ({
15723
+ path: z.string({ min: 1 }).describe("The route to read, beginning /api/v1, with its query after ?, such as /api/v1/issues/ACME-12/events?limit=200. No scheme or host, and no . or .. segment.")
15724
+ }),
15725
+ validation: {
15726
+ check: (value) => apiPathProblem(value) === undefined,
15727
+ message: API_PATH_RULE,
15728
+ refusal: (value) => apiPathProblem(value) ?? API_PATH_RULE
15729
+ },
15730
+ strict: true
15731
+ },
15697
15732
  {
15698
15733
  name: "dispatch_handoff_write",
15699
15734
  example: {
@@ -20436,6 +20471,7 @@ class DispatchServiceError extends Error {
20436
20471
  mismatches;
20437
20472
  issues;
20438
20473
  changed;
20474
+ hint;
20439
20475
  constructor(code, status, message, details = {}) {
20440
20476
  super(message);
20441
20477
  this.code = code;
@@ -20445,6 +20481,7 @@ class DispatchServiceError extends Error {
20445
20481
  this.mismatches = details.mismatches;
20446
20482
  this.issues = details.issues;
20447
20483
  this.changed = details.changed;
20484
+ this.hint = details.hint;
20448
20485
  }
20449
20486
  }
20450
20487
 
@@ -20934,6 +20971,10 @@ class DispatchClient {
20934
20971
  async limits() {
20935
20972
  return this.#json("GET", ["api", "v1", "limits"]);
20936
20973
  }
20974
+ async readRoute(path) {
20975
+ const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
20976
+ return this.#response("GET", url, await this.#send("GET", url));
20977
+ }
20937
20978
  async inbox(assignee) {
20938
20979
  return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
20939
20980
  }
@@ -21622,7 +21663,7 @@ class DispatchClient {
21622
21663
  if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
21623
21664
  throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
21624
21665
  }
21625
- throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
21666
+ throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, { ...error, hint: typeof error.hint === "string" ? error.hint : undefined });
21626
21667
  }
21627
21668
  throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
21628
21669
  }
@@ -25922,6 +25963,7 @@ var issueFreeTools = {
25922
25963
  dispatch_answers: true,
25923
25964
  dispatch_whoami: true,
25924
25965
  dispatch_limits: true,
25966
+ dispatch_api: true,
25925
25967
  dispatch_inbox: true,
25926
25968
  dispatch_send_to_agent: true,
25927
25969
  dispatch_architecture_sync: true
@@ -31252,6 +31294,10 @@ async function refreshDeviceLogin(path, login, options) {
31252
31294
  return next;
31253
31295
  }
31254
31296
 
31297
+ // ../cipher-client/src/environment.ts
31298
+ import { readFile as readFile6 } from "fs/promises";
31299
+ import { join as join6 } from "path";
31300
+
31255
31301
  // ../cipher-client/src/metadata-identity.ts
31256
31302
  import { Agent, request } from "http";
31257
31303
  var METADATA_HOST_VAR = "GCE_METADATA_HOST";
@@ -31561,6 +31607,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
31561
31607
  var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
31562
31608
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
31563
31609
  var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
31610
+ var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
31611
+ var ROLE_KEY_FILE = "key.pem";
31564
31612
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
31565
31613
  var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
31566
31614
  var MAX_PROJECTS = 16;
@@ -31574,6 +31622,7 @@ var BROKER_VARIABLES = [
31574
31622
  BROKER_URL_VAR,
31575
31623
  IDENTITY_VAR,
31576
31624
  MACHINE_TOKEN_FILE_VAR,
31625
+ KEY_DIR_VAR,
31577
31626
  MACHINE_AUDIENCE_VAR,
31578
31627
  SESSION_VAR,
31579
31628
  PROJECTS_VAR,
@@ -31649,6 +31698,21 @@ function tradeProjects(env) {
31649
31698
  }
31650
31699
  return sorted;
31651
31700
  }
31701
+ async function machineKey(env) {
31702
+ const dir = value(env, KEY_DIR_VAR);
31703
+ if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
31704
+ return await newDpopKey();
31705
+ const path = join6(dir, ROLE_KEY_FILE);
31706
+ let pem;
31707
+ try {
31708
+ pem = await readFile6(path, "utf8");
31709
+ } catch (error) {
31710
+ throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
31711
+ cause: error
31712
+ });
31713
+ }
31714
+ return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
31715
+ }
31652
31716
  async function brokerTokenClient(env, own = "", read) {
31653
31717
  const brokerUrl = value(env, BROKER_URL_VAR);
31654
31718
  const machine = machineIdentity(env);
@@ -31676,7 +31740,7 @@ async function brokerTokenClient(env, own = "", read) {
31676
31740
  if (record === undefined) {
31677
31741
  const client = new BrokerTokenClient({
31678
31742
  brokerUrl,
31679
- key: await newDpopKey(),
31743
+ key: await machineKey(env),
31680
31744
  subject: machine,
31681
31745
  session: tradeSession(env, own),
31682
31746
  launcherCredential: false,
@@ -32343,6 +32407,16 @@ async function commandContext(session) {
32343
32407
  };
32344
32408
  }
32345
32409
 
32410
+ // ../envoy-client/src/dispatch-commands/api.ts
32411
+ async function apiCommand(context) {
32412
+ const path = stringArg(context.args, "path");
32413
+ const answer = await context.newClient().readRoute(path);
32414
+ return {
32415
+ text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
32416
+ details: { path }
32417
+ };
32418
+ }
32419
+
32346
32420
  // ../envoy-client/src/dispatch-commands/render-item.ts
32347
32421
  function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
32348
32422
  const answer = ask.answer;
@@ -34420,26 +34494,26 @@ async function reviewCommand(context) {
34420
34494
 
34421
34495
  // ../envoy-client/src/session-answers.ts
34422
34496
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
34423
- import { join as join7 } from "path";
34497
+ import { join as join8 } from "path";
34424
34498
 
34425
34499
  // ../envoy-client/src/dispatch-session-directory.ts
34426
34500
  import { randomUUID as randomUUID5 } from "crypto";
34427
34501
  import { renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
34428
34502
  import { homedir as homedir2 } from "os";
34429
- import { join as join6 } from "path";
34503
+ import { join as join7 } from "path";
34430
34504
  var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
34431
34505
  var PRIVATE_FILE = 384;
34432
34506
  function sessionStateRoot(env) {
34433
34507
  const stateDir = env["DISPATCH_STATE_DIR"];
34434
34508
  if (stateDir)
34435
34509
  return stateDir;
34436
- return join6(env["XDG_STATE_HOME"] || join6(homedir2(), ".local", "state"), "dispatch");
34510
+ return join7(env["XDG_STATE_HOME"] || join7(homedir2(), ".local", "state"), "dispatch");
34437
34511
  }
34438
34512
  function sessionDirectory(env, sessionId) {
34439
34513
  if (!SESSION_ID_PATH_SEGMENT.test(sessionId) || sessionId === "." || sessionId === "..") {
34440
34514
  throw new Error(`dispatch: the session id ${JSON.stringify(sessionId)} is not 1-128 letters, digits, ".", "_" or "-"`);
34441
34515
  }
34442
- return join6(sessionStateRoot(env), "sessions", sessionId);
34516
+ return join7(sessionStateRoot(env), "sessions", sessionId);
34443
34517
  }
34444
34518
  function writeAtomically(path, text) {
34445
34519
  const temporary = `${path}.${process.pid}.${randomUUID5()}.tmp`;
@@ -34590,7 +34664,7 @@ processGlobal2[STATE_KEY] = state;
34590
34664
  var CACHE_FILE = "answers.json";
34591
34665
  function readCacheFile(directory, url) {
34592
34666
  try {
34593
- const value = JSON.parse(readFileSync3(join7(directory, CACHE_FILE), "utf-8"));
34667
+ const value = JSON.parse(readFileSync3(join8(directory, CACHE_FILE), "utf-8"));
34594
34668
  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)) {
34595
34669
  return {
34596
34670
  dispatch_url: value.dispatch_url,
@@ -34711,7 +34785,7 @@ async function readSessionAnswers(options) {
34711
34785
  if (directory !== undefined) {
34712
34786
  try {
34713
34787
  mkdirSync2(directory, { recursive: true, mode: 448 });
34714
- writeAtomically(join7(directory, CACHE_FILE), JSON.stringify(cache));
34788
+ writeAtomically(join8(directory, CACHE_FILE), JSON.stringify(cache));
34715
34789
  } catch {}
34716
34790
  }
34717
34791
  return { cache };
@@ -35062,6 +35136,7 @@ var dispatchCommands = {
35062
35136
  dispatch_answers: onSession(answersCommand),
35063
35137
  dispatch_whoami: onSession(whoamiCommand),
35064
35138
  dispatch_limits: onSession(limitsCommand),
35139
+ dispatch_api: onSession(apiCommand),
35065
35140
  dispatch_inbox: onSession(inboxCommand)
35066
35141
  };
35067
35142
  // ../envoy-client/src/dispatch-execute.ts
@@ -35097,7 +35172,7 @@ import {
35097
35172
  statSync as statSync2,
35098
35173
  writeFileSync as writeFileSync3
35099
35174
  } from "fs";
35100
- import { join as join8 } from "path";
35175
+ import { join as join9 } from "path";
35101
35176
  var PRIVATE_DIR = 448;
35102
35177
  var PRIVATE_FILE2 = 384;
35103
35178
  var IDLE_SESSION_MS = 14 * 86400000;
@@ -35125,7 +35200,7 @@ function stringList(value) {
35125
35200
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
35126
35201
  }
35127
35202
  function loadSessionMemory(dir, sessionId) {
35128
- const path = join8(dir, "state.json");
35203
+ const path = join9(dir, "state.json");
35129
35204
  const text = readIfPresent(path);
35130
35205
  if (text === undefined)
35131
35206
  return new Set;
@@ -35149,7 +35224,7 @@ function writeMemory(dir, sessionId, follows) {
35149
35224
  pictures: [...shownPictures(sessionId)],
35150
35225
  follows: [...follows]
35151
35226
  };
35152
- writeAtomically(join8(dir, "state.json"), `${JSON.stringify(state)}
35227
+ writeAtomically(join9(dir, "state.json"), `${JSON.stringify(state)}
35153
35228
  `);
35154
35229
  }
35155
35230
  function appendResult(dir, entry) {
@@ -35158,7 +35233,7 @@ function appendResult(dir, entry) {
35158
35233
  }
35159
35234
  function writeResult(dir, entry) {
35160
35235
  const line = { at: new Date().toISOString(), ...entry };
35161
- appendFileSync2(join8(dir, "results.jsonl"), `${JSON.stringify(line)}
35236
+ appendFileSync2(join9(dir, "results.jsonl"), `${JSON.stringify(line)}
35162
35237
  `, { mode: PRIVATE_FILE2 });
35163
35238
  }
35164
35239
  function recordOutcome(dir, sessionId, follows, entry) {
@@ -35169,8 +35244,8 @@ function recordOutcome(dir, sessionId, follows, entry) {
35169
35244
  function writePicture(dir, image) {
35170
35245
  const bytes = Buffer.from(image.data, "base64");
35171
35246
  const name = createHash3("sha256").update(bytes).digest("hex").slice(0, 16);
35172
- const pictures = join8(dir, "pictures");
35173
- const path = join8(pictures, `${name}.${PICTURE_EXTENSIONS[image.mimeType]}`);
35247
+ const pictures = join9(dir, "pictures");
35248
+ const path = join9(pictures, `${name}.${PICTURE_EXTENSIONS[image.mimeType]}`);
35174
35249
  ensureDirectory(pictures);
35175
35250
  try {
35176
35251
  writeFileSync3(path, bytes, { mode: PRIVATE_FILE2, flag: "wx" });
@@ -35181,21 +35256,21 @@ function writePicture(dir, image) {
35181
35256
  return { path, bytes: bytes.length };
35182
35257
  }
35183
35258
  function writeLongOutput(dir, text) {
35184
- const out = join8(dir, "out");
35259
+ const out = join9(dir, "out");
35185
35260
  ensureDirectory(out);
35186
- const path = join8(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
35261
+ const path = join9(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
35187
35262
  writeFileSync3(path, text, { mode: PRIVATE_FILE2 });
35188
35263
  return path;
35189
35264
  }
35190
35265
  function writeSessionTitle(dir, title) {
35191
35266
  ensureDirectory(dir);
35192
- writeAtomically(join8(dir, "title"), title);
35267
+ writeAtomically(join9(dir, "title"), title);
35193
35268
  }
35194
35269
  function readSessionTitle(dir) {
35195
- return readIfPresent(join8(dir, "title")) || undefined;
35270
+ return readIfPresent(join9(dir, "title")) || undefined;
35196
35271
  }
35197
35272
  function pruneSessions(root, now) {
35198
- const stamp = join8(root, PRUNED_STAMP);
35273
+ const stamp = join9(root, PRUNED_STAMP);
35199
35274
  try {
35200
35275
  if (now - statSync2(stamp).mtimeMs < PRUNE_INTERVAL_MS)
35201
35276
  return;
@@ -35203,7 +35278,7 @@ function pruneSessions(root, now) {
35203
35278
  if (!hasErrnoCode(error, "ENOENT"))
35204
35279
  throw error;
35205
35280
  }
35206
- const sessions = join8(root, "sessions");
35281
+ const sessions = join9(root, "sessions");
35207
35282
  let entries = [];
35208
35283
  try {
35209
35284
  entries = readdirSync2(sessions, { withFileTypes: true });
@@ -35214,7 +35289,7 @@ function pruneSessions(root, now) {
35214
35289
  for (const entry of entries) {
35215
35290
  if (!entry.isDirectory())
35216
35291
  continue;
35217
- const dir = join8(sessions, entry.name);
35292
+ const dir = join9(sessions, entry.name);
35218
35293
  try {
35219
35294
  const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
35220
35295
  if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {