@sjawhar/claude-envoy 6.0.2 → 6.1.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/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/dist/codex-hook.js +818 -141
- package/dist/dispatch.js +11949 -11485
- package/dist/envoy-channel.js +402 -60
- package/dist/session-hook.js +821 -144
- package/package.json +1 -1
package/dist/envoy-channel.js
CHANGED
|
@@ -37312,7 +37312,11 @@ var projectKeyValidation = {
|
|
|
37312
37312
|
};
|
|
37313
37313
|
var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
|
|
37314
37314
|
var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
|
|
37315
|
-
var
|
|
37315
|
+
var API_ROUTE_REWRITTEN = /["<>^`{}]/;
|
|
37316
|
+
var DISPATCH_API_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
37317
|
+
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 #, no character before the query is ", <, >, ^, `, { or }, and no segment before the query is . or ..';
|
|
37318
|
+
var API_BODY_RULE = "body goes only with method: a call that names no method is a GET, which sends no body.";
|
|
37319
|
+
var API_CALL_RULE = `${API_PATH_RULE}; ${API_BODY_RULE}`;
|
|
37316
37320
|
function apiPathProblem(value) {
|
|
37317
37321
|
const { path } = value;
|
|
37318
37322
|
if (typeof path !== "string")
|
|
@@ -37325,11 +37329,21 @@ function apiPathProblem(value) {
|
|
|
37325
37329
|
return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
|
|
37326
37330
|
}
|
|
37327
37331
|
const route = path.split("?", 1)[0] ?? "";
|
|
37332
|
+
if (API_ROUTE_REWRITTEN.test(route)) {
|
|
37333
|
+
return `path ${named} holds before its query a character a URL parser rewrites in a path (", <, >, ^, \`, { or }): percent-encode it.`;
|
|
37334
|
+
}
|
|
37328
37335
|
if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
|
|
37329
37336
|
return `path ${named} holds a . or .. segment: name the route itself.`;
|
|
37330
37337
|
}
|
|
37331
37338
|
return;
|
|
37332
37339
|
}
|
|
37340
|
+
function apiCallProblem(value) {
|
|
37341
|
+
const pathProblem = apiPathProblem(value);
|
|
37342
|
+
if (pathProblem !== undefined)
|
|
37343
|
+
return pathProblem;
|
|
37344
|
+
const { method, body } = value;
|
|
37345
|
+
return body !== undefined && method === undefined ? API_BODY_RULE : undefined;
|
|
37346
|
+
}
|
|
37333
37347
|
var ISSUE_STATUSES = [
|
|
37334
37348
|
"triage",
|
|
37335
37349
|
"icebox",
|
|
@@ -37936,7 +37950,7 @@ var dispatchToolSpecs = [
|
|
|
37936
37950
|
{
|
|
37937
37951
|
name: "dispatch_whoami",
|
|
37938
37952
|
example: {},
|
|
37939
|
-
description: "Who Dispatch takes this session for: {session, owner, service, project}. session is the session Dispatch records your writes as. It is the session your credential proved, and the tool says so when that is not the session you run in. owner is the lowercase email of the person you act for, and is the first choice of assignee for issues you create. owner is null under the shared token and under a broker token that names a service and no person. With a null owner, a create with no assignee falls back to the parent's assignee, when the parent is in the issue's own project, and then to the project's default assignee, which every project names, so every issue you create has an assignee. A question on an issue reaches the person it was handed to, else the issue's assignee, else the project's default assignee. service is the subject of the verified service-account token that authenticated you, or
|
|
37953
|
+
description: "Who Dispatch takes this session for: {session, owner, service, project, project_scope}. session is the session Dispatch records your writes as. It is the session your credential proved, and the tool says so when that is not the session you run in. owner is the lowercase email of the person you act for, and is the first choice of assignee for issues you create. owner is null under the shared token and under a broker token that names a service and no person. With a null owner, a create with no assignee falls back to the parent's assignee, when the parent is in the issue's own project, and then to the project's default assignee, which every project names, so every issue you create has an assignee. A question on an issue reaches the person it was handed to, else the issue's assignee, else the project's default assignee. service is the subject of the verified service-account token that authenticated you, or the service a broker token naming no person names: a job's identity as its job entry lists it, the Kubernetes account an exchange entry lists, or the fleet of a machine nobody has signed in on; else null. project_scope is a broker token's project scope, and null for every other credential. A job's broker token has the project scope named or public, holds no OAuth scope and writes as its service: a route that needs an OAuth scope refuses it with 403 OAUTH_SCOPE_REQUIRED before Dispatch's project check runs. named may write its one project, and that check judges its write to another project as it judges a person's named token's for the same project: 403 PROJECT_SCOPE until dispatch://INFRA-4799 changes that answer for both. public names no one project, so it may write wherever a token that names no project may. An exchange entry's broker token that names its account has the project scope named and no project, and writes as that account wherever a token that names no project may. A machine's broker token that names a service has the project scope person; it may read and is refused every write with SIGN_IN_REQUIRED, which names the command a person signs in on that machine with. project is the one project key your credential may write, or null when it names none.",
|
|
37940
37954
|
arguments: () => ({}),
|
|
37941
37955
|
strict: true
|
|
37942
37956
|
},
|
|
@@ -37950,14 +37964,16 @@ var dispatchToolSpecs = [
|
|
|
37950
37964
|
{
|
|
37951
37965
|
name: "dispatch_api",
|
|
37952
37966
|
example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
|
|
37953
|
-
description: "
|
|
37967
|
+
description: "Send one request of a route of Dispatch's HTTP API under /api/v1, with this session's own credential, and print the answer's body: Dispatch's JSON, indented, for jq to read; any other body of a 2xx, such as a file version's bytes or a document version's Markdown, as it came. It sends a GET of path unless method names another: path is a route beginning /api/v1, with its query after ?; dispatch api --path /api/v1 lists every route. With method it sends POST, PUT, PATCH or DELETE instead, and body, when given, as the request's JSON body (Content-Type: application/json), read from a file with --body-file <file> or from stdin with --body-file -; a body goes only with a method. A write that a named dispatch command makes goes through that command (dispatch --help lists them): dispatch api is for a route no command sends. In a session whose AskGate reviews Dispatch writes it sends GET alone, and refuses each method, naming the dispatch command that makes that write, and exits 1. It sends the request once, and once more only after Dispatch answers that the token it presented is not live (Dispatch then authenticated nothing, so nothing ran), with no redirect followed and no Idempotency-Key. On a 2xx answer it exits 0 and prints Dispatch's JSON as above, and any other body unchanged, with nothing added: an answer with Content-Disposition: attachment (a file version, a ?download=true read) is stored content, printed byte for byte whatever its type, JSON included. A 2xx whose body holds a credential the command presented (its token or its request's DPoP proof) is not printed: it exits 1 with CREDENTIAL_ECHOED, naming the status and saying a write may have been made. Any other answer exits 1 with its code: when Dispatch refuses the request, the command prints Dispatch's error with its code and, where Dispatch gives one, its hint; an answer that is neither a 2xx nor Dispatch's JSON, such as a proxy's page, is named by its status. A usage error, such as a path outside /api/v1 or a body with no method, exits 2. Where no host runs the command, as in a GitHub Actions job, it reads Dispatch from the environment alone, and a broker trade names the session of DISPATCH_SESSION_ID, else of AGENT_SECRETS_SESSION. Under Claude Code, a JSON answer longer than the output limit is written to a file the output names; a body printed as it came is written whole.",
|
|
37954
37968
|
arguments: (z) => ({
|
|
37955
|
-
path: z.string({ min: 1 }).describe(
|
|
37969
|
+
path: z.string({ min: 1 }).describe('The route, beginning /api/v1, with its query after ?, such as /api/v1/issues/ACME-12/events?limit=200. No scheme or host, no . or .. segment, and no ", <, >, ^, `, { or } before the query: percent-encode them.'),
|
|
37970
|
+
method: z.enum(DISPATCH_API_METHODS).describe("The method sent in place of GET: POST, PUT, PATCH or DELETE. Omit it to send a GET.").optional(),
|
|
37971
|
+
body: z.string().describe("The request's JSON body, sent as written with Content-Type: application/json; only with method. Write it to a file and pass it with --body-file, or --body-file - for stdin.").optional()
|
|
37956
37972
|
}),
|
|
37957
37973
|
validation: {
|
|
37958
|
-
check: (value) =>
|
|
37959
|
-
message:
|
|
37960
|
-
refusal: (value) =>
|
|
37974
|
+
check: (value) => apiCallProblem(value) === undefined,
|
|
37975
|
+
message: API_CALL_RULE,
|
|
37976
|
+
refusal: (value) => apiCallProblem(value) ?? API_CALL_RULE
|
|
37961
37977
|
},
|
|
37962
37978
|
strict: true
|
|
37963
37979
|
},
|
|
@@ -44104,6 +44120,7 @@ var FORM_AS_OF = "as_of";
|
|
|
44104
44120
|
var HEADER_DPOP_HOLDER = "DPoP-Holder";
|
|
44105
44121
|
var SUBJECT_TOKEN_TYPE_KUBERNETES = "urn:envoy:params:oauth:token-type:kubernetes-service-account";
|
|
44106
44122
|
var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identity";
|
|
44123
|
+
var SUBJECT_TOKEN_TYPE_GITHUB = "urn:envoy:params:oauth:token-type:github-workflow-run";
|
|
44107
44124
|
var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
|
|
44108
44125
|
var ACTOR_TOKEN_TYPE_MACHINE = "urn:envoy:params:oauth:token-type:machine-google-identity";
|
|
44109
44126
|
var TOKEN_TYPE_DPOP = "DPoP";
|
|
@@ -44137,6 +44154,7 @@ var WORKFLOW_REF = "[A-Za-z0-9_./@-]{1,400}";
|
|
|
44137
44154
|
var IDENTITY = `(?:${K8S_ACCOUNT}|${REPOSITORY}/${WORKFLOW_PATH}|${EMAIL})`;
|
|
44138
44155
|
var FIXED_SESSION = "[A-Za-z0-9._:@/+-]{1,200}";
|
|
44139
44156
|
var PROJECT_LIST = `${PROJECT_SLOT}(?: ${PROJECT_SLOT}){0,31}`;
|
|
44157
|
+
var JOB_LIST = `(?:public(?:,${PROJECT_SLOT}){0,16}|${PROJECT_SLOT})`;
|
|
44140
44158
|
var SERVICE = "[A-Za-z0-9._-]{1,100}";
|
|
44141
44159
|
var CLOUD_PROJECT = "[a-z][a-z0-9-]{4,29}";
|
|
44142
44160
|
var INSTANCE = "[a-z0-9][a-z0-9-]{0,62}";
|
|
@@ -44206,6 +44224,7 @@ var POLICY_REFUSAL_PATTERNS = [
|
|
|
44206
44224
|
policy("claimMissing", "the subject token's %s claim is not a non-empty string", CLAIM),
|
|
44207
44225
|
policy("projectsFixed", "%s's entry names no project, and the request named %s", IDENTITY, PROJECT_LIST),
|
|
44208
44226
|
policy("projectsFixed", "%s writes the project %s that its entry names, and the request named %s", IDENTITY, PROJECT_SLOT, PROJECT_LIST),
|
|
44227
|
+
policy("projectsFixed", "%s's entry gives its token the projects %s, and the request named %s, which that list does not name", IDENTITY, JOB_LIST, PROJECT_SLOT),
|
|
44209
44228
|
`${escapeRegExp("The subject token was refused: ")}${formatPattern("the subject token was not minted for %s, which is the audience this broker accepts from %s", [URI, URI])}\\.`
|
|
44210
44229
|
];
|
|
44211
44230
|
var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
@@ -44231,6 +44250,7 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
|
44231
44250
|
"The 'as_of' parameter is not an RFC 3339 time with at most six fractional digits\\.",
|
|
44232
44251
|
"The 'as_of' parameter names the zero time, which is no cut: a trade that reads the present names no cut\\.",
|
|
44233
44252
|
"The 'as_of' parameter names a time later than this trade, and a cut is a time that has passed\\.",
|
|
44253
|
+
"The scope 'read' narrows a token to reading, and a job entry's token is minted whole, with no scope: ask for it without that scope\\.",
|
|
44234
44254
|
"A read trade makes or moves no launcher credential, so it cannot send launcher_credential=true\\. Trade for read without the parameter\\.",
|
|
44235
44255
|
`${PERSON_SLOT}'s sign-in on this machine holds no launcher credential yet, and a read trade makes none\\. Sign in with \`agent-secrets login\` first\\.`,
|
|
44236
44256
|
`${PERSON_SLOT}'s sign-in on this machine holds a launcher credential that has lapsed, and a read trade renews none\\. One ordinary trade of the sign-in renews it, as \`agent-secrets\` makes; then trade for read again\\.`,
|
|
@@ -45832,6 +45852,9 @@ async function importDpopKey(pkcs8Pem, name) {
|
|
|
45832
45852
|
return dpopKey(privateKey, publicJwkOf(privateKey, name));
|
|
45833
45853
|
}
|
|
45834
45854
|
|
|
45855
|
+
// ../cipher-client/src/loopback.ts
|
|
45856
|
+
var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
|
|
45857
|
+
|
|
45835
45858
|
// ../cipher-client/src/device-login.ts
|
|
45836
45859
|
var BROKER_SETTING = "AGENT_SECRETS_URL";
|
|
45837
45860
|
var ACCESS_MARGIN_MS = 2 * TRADE_ATTEMPT_MS;
|
|
@@ -45841,7 +45864,6 @@ function leastAccessLifeMs(leastLifeMs, lifeSeconds) {
|
|
|
45841
45864
|
return Math.max(ACCESS_MARGIN_MS, Math.min(leastLifeMs, lifeSeconds * 1000 / 2));
|
|
45842
45865
|
}
|
|
45843
45866
|
var BROKER_REQUEST_MS = TRADE_ATTEMPT_MS / 2;
|
|
45844
|
-
var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
|
|
45845
45867
|
var UNPRINTABLE = /[\p{Cc}\p{Cf}]/u;
|
|
45846
45868
|
function deviceLoginSessionName(thumbprint) {
|
|
45847
45869
|
return `device-login-${thumbprint.slice(0, 12)}`;
|
|
@@ -46147,13 +46169,107 @@ async function refreshDeviceLogin(path, login, options) {
|
|
|
46147
46169
|
return next;
|
|
46148
46170
|
}
|
|
46149
46171
|
|
|
46172
|
+
// ../cipher-client/src/answer-text.ts
|
|
46173
|
+
var MAX_ANSWER_BYTES = 1 << 20;
|
|
46174
|
+
async function answerText(answer) {
|
|
46175
|
+
const reader = answer.body?.getReader();
|
|
46176
|
+
if (reader === undefined)
|
|
46177
|
+
return "";
|
|
46178
|
+
const chunks = [];
|
|
46179
|
+
let read = 0;
|
|
46180
|
+
while (read < MAX_ANSWER_BYTES) {
|
|
46181
|
+
const { done, value } = await reader.read();
|
|
46182
|
+
if (done)
|
|
46183
|
+
break;
|
|
46184
|
+
const kept = value.subarray(0, MAX_ANSWER_BYTES - read);
|
|
46185
|
+
chunks.push(kept);
|
|
46186
|
+
read += kept.length;
|
|
46187
|
+
}
|
|
46188
|
+
await reader.cancel().catch(() => {
|
|
46189
|
+
return;
|
|
46190
|
+
});
|
|
46191
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
46192
|
+
}
|
|
46193
|
+
|
|
46194
|
+
// ../cipher-client/src/machine-audience.ts
|
|
46195
|
+
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
46196
|
+
|
|
46197
|
+
// ../cipher-client/src/github-actions-identity.ts
|
|
46198
|
+
var ACTIONS_ID_TOKEN_REQUEST_URL_VAR = "ACTIONS_ID_TOKEN_REQUEST_URL";
|
|
46199
|
+
var ACTIONS_ID_TOKEN_REQUEST_TOKEN_VAR = "ACTIONS_ID_TOKEN_REQUEST_TOKEN";
|
|
46200
|
+
var TIMEOUT_MS = 20000;
|
|
46201
|
+
var ASKING = `ask GitHub for this run's OIDC token at the URL ${ACTIONS_ID_TOKEN_REQUEST_URL_VAR} names`;
|
|
46202
|
+
var NOT_HTTPS = `${ACTIONS_ID_TOKEN_REQUEST_URL_VAR} is not an https URL: the request token is sent there, so it takes https, or http to 127.0.0.1, ::1 or localhost`;
|
|
46203
|
+
function requestEndpoint(requestUrl, audience) {
|
|
46204
|
+
let endpoint;
|
|
46205
|
+
try {
|
|
46206
|
+
endpoint = new URL(requestUrl);
|
|
46207
|
+
} catch {
|
|
46208
|
+
throw new Error(NOT_HTTPS);
|
|
46209
|
+
}
|
|
46210
|
+
const loopback = endpoint.protocol === "http:" && LOOPBACK_HOST.test(endpoint.hostname);
|
|
46211
|
+
if (endpoint.protocol !== "https:" && !loopback)
|
|
46212
|
+
throw new Error(NOT_HTTPS);
|
|
46213
|
+
endpoint.searchParams.set("audience", audience);
|
|
46214
|
+
return endpoint.href;
|
|
46215
|
+
}
|
|
46216
|
+
function githubActionsIdentity(options) {
|
|
46217
|
+
holdSecret(options.requestToken);
|
|
46218
|
+
holdUrlUserinfo(options.requestUrl);
|
|
46219
|
+
const send = options.fetch ?? fetch;
|
|
46220
|
+
return {
|
|
46221
|
+
async read(signal) {
|
|
46222
|
+
const endpoint = requestEndpoint(options.requestUrl, options.audience);
|
|
46223
|
+
const signals = [AbortSignal.timeout(TIMEOUT_MS), signal].filter((one) => one !== undefined);
|
|
46224
|
+
let answer;
|
|
46225
|
+
try {
|
|
46226
|
+
answer = await send(endpoint, {
|
|
46227
|
+
method: "GET",
|
|
46228
|
+
headers: { Authorization: `bearer ${options.requestToken}` },
|
|
46229
|
+
signal: AbortSignal.any(signals),
|
|
46230
|
+
redirect: "manual"
|
|
46231
|
+
});
|
|
46232
|
+
} catch (error) {
|
|
46233
|
+
throw new Error(`${ASKING}: no answer: ${errorClass(error)}`);
|
|
46234
|
+
}
|
|
46235
|
+
if (answer.status < 200 || answer.status > 299) {
|
|
46236
|
+
await answer.body?.cancel().catch(() => {
|
|
46237
|
+
return;
|
|
46238
|
+
});
|
|
46239
|
+
throw new Error(`${ASKING}: HTTP ${answer.status}`);
|
|
46240
|
+
}
|
|
46241
|
+
let text;
|
|
46242
|
+
try {
|
|
46243
|
+
text = await answerText(answer);
|
|
46244
|
+
} catch (error) {
|
|
46245
|
+
throw new Error(`${ASKING}: no answer: ${errorClass(error)}`);
|
|
46246
|
+
}
|
|
46247
|
+
let parsed;
|
|
46248
|
+
try {
|
|
46249
|
+
parsed = JSON.parse(text);
|
|
46250
|
+
} catch {
|
|
46251
|
+
throw new Error(`${ASKING}: HTTP ${answer.status}: the answer is not JSON`);
|
|
46252
|
+
}
|
|
46253
|
+
const value = typeof parsed === "object" && parsed !== null && "value" in parsed ? parsed.value : undefined;
|
|
46254
|
+
if (typeof value !== "string" || value === "") {
|
|
46255
|
+
throw new Error(`${ASKING}: the answer holds no value`);
|
|
46256
|
+
}
|
|
46257
|
+
return { token: value, tokenType: SUBJECT_TOKEN_TYPE_GITHUB };
|
|
46258
|
+
},
|
|
46259
|
+
describe: () => {
|
|
46260
|
+
const audience = isCleanUrl(options.audience) ? `${options.audience} (${MACHINE_AUDIENCE_VAR})` : `the audience ${MACHINE_AUDIENCE_VAR} names`;
|
|
46261
|
+
return `this GitHub Actions run's OIDC token for ${audience}, asked for at the URL ${ACTIONS_ID_TOKEN_REQUEST_URL_VAR} names with the token ${ACTIONS_ID_TOKEN_REQUEST_TOKEN_VAR} names`;
|
|
46262
|
+
}
|
|
46263
|
+
};
|
|
46264
|
+
}
|
|
46265
|
+
|
|
46150
46266
|
// ../cipher-client/src/metadata-identity.ts
|
|
46151
46267
|
import { Agent, request } from "http";
|
|
46152
46268
|
var METADATA_HOST_VAR = "GCE_METADATA_HOST";
|
|
46153
46269
|
var DEFAULT_METADATA_HOST = "metadata.google.internal";
|
|
46154
46270
|
var IDENTITY_PATH = "/computeMetadata/v1/instance/service-accounts/default/identity";
|
|
46155
|
-
var
|
|
46156
|
-
var
|
|
46271
|
+
var TIMEOUT_MS2 = 1e4;
|
|
46272
|
+
var MAX_ANSWER_BYTES2 = 1 << 20;
|
|
46157
46273
|
var agent = new Agent({ keepAlive: false });
|
|
46158
46274
|
function tokenUrl(audience, env) {
|
|
46159
46275
|
const host = (env[METADATA_HOST_VAR] ?? "").trim() || DEFAULT_METADATA_HOST;
|
|
@@ -46168,7 +46284,7 @@ function get(url, signal, lookup) {
|
|
|
46168
46284
|
agent,
|
|
46169
46285
|
method: "GET",
|
|
46170
46286
|
headers: { "Metadata-Flavor": "Google" },
|
|
46171
|
-
timeout:
|
|
46287
|
+
timeout: TIMEOUT_MS2,
|
|
46172
46288
|
...signal === undefined ? {} : { signal },
|
|
46173
46289
|
...lookup === undefined ? {} : { lookup }
|
|
46174
46290
|
}, (answer) => {
|
|
@@ -46176,13 +46292,13 @@ function get(url, signal, lookup) {
|
|
|
46176
46292
|
let read = 0;
|
|
46177
46293
|
answer.on("data", (chunk) => {
|
|
46178
46294
|
read += chunk.length;
|
|
46179
|
-
if (read <=
|
|
46295
|
+
if (read <= MAX_ANSWER_BYTES2)
|
|
46180
46296
|
chunks.push(chunk);
|
|
46181
46297
|
});
|
|
46182
46298
|
answer.on("end", () => resolve({ status: answer.statusCode ?? 0, body: Buffer.concat(chunks).toString("utf8") }));
|
|
46183
46299
|
answer.on("error", reject);
|
|
46184
46300
|
});
|
|
46185
|
-
call.on("timeout", () => call.destroy(Object.assign(new Error(`no answer within ${
|
|
46301
|
+
call.on("timeout", () => call.destroy(Object.assign(new Error(`no answer within ${TIMEOUT_MS2} ms`), { code: "ETIMEDOUT" })));
|
|
46186
46302
|
call.on("error", reject);
|
|
46187
46303
|
call.end();
|
|
46188
46304
|
return promise;
|
|
@@ -46295,7 +46411,6 @@ var REQUESTED_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:access_token";
|
|
|
46295
46411
|
var SCOPE = "https://www.googleapis.com/auth/cloud-platform";
|
|
46296
46412
|
var SUBJECT_TOKEN_TYPE_JWT = "urn:ietf:params:oauth:token-type:jwt";
|
|
46297
46413
|
var POOL_TIMEOUT_MS = 20000;
|
|
46298
|
-
var MAX_ANSWER_BYTES2 = 1 << 20;
|
|
46299
46414
|
var STS_SETTING = "securityTokenServiceUrl";
|
|
46300
46415
|
var IAM_SETTING = "iamCredentialsUrl";
|
|
46301
46416
|
function poolSubjectTokenType(brokerType) {
|
|
@@ -46304,25 +46419,6 @@ function poolSubjectTokenType(brokerType) {
|
|
|
46304
46419
|
function pathEscape(segment) {
|
|
46305
46420
|
return encodeURIComponent(segment).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(?:24|26|2B|3A|3D|40)/g, decodeURIComponent);
|
|
46306
46421
|
}
|
|
46307
|
-
async function answerText(answer) {
|
|
46308
|
-
const reader = answer.body?.getReader();
|
|
46309
|
-
if (reader === undefined)
|
|
46310
|
-
return "";
|
|
46311
|
-
const chunks = [];
|
|
46312
|
-
let read = 0;
|
|
46313
|
-
while (read < MAX_ANSWER_BYTES2) {
|
|
46314
|
-
const { done, value } = await reader.read();
|
|
46315
|
-
if (done)
|
|
46316
|
-
break;
|
|
46317
|
-
const kept = value.subarray(0, MAX_ANSWER_BYTES2 - read);
|
|
46318
|
-
chunks.push(kept);
|
|
46319
|
-
read += kept.length;
|
|
46320
|
-
}
|
|
46321
|
-
await reader.cancel().catch(() => {
|
|
46322
|
-
return;
|
|
46323
|
-
});
|
|
46324
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
46325
|
-
}
|
|
46326
46422
|
var GOOGLE_ERROR_CODE = /^[A-Za-z_]{1,64}$/;
|
|
46327
46423
|
function googleErrorCode(text) {
|
|
46328
46424
|
let parsed;
|
|
@@ -46451,7 +46547,6 @@ function projectedToken(path, variable) {
|
|
|
46451
46547
|
var BROKER_URL_VAR = "AGENT_SECRETS_URL";
|
|
46452
46548
|
var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
|
|
46453
46549
|
var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
|
|
46454
|
-
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
46455
46550
|
var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
|
|
46456
46551
|
var ROLE_KEY_FILE = "key.pem";
|
|
46457
46552
|
var SESSION_VAR = "AGENT_SECRETS_SESSION";
|
|
@@ -46462,6 +46557,7 @@ var POOL_ACCOUNT_VAR = "AGENT_SECRETS_POOL_ACCOUNT";
|
|
|
46462
46557
|
var IDENTITY_KUBERNETES = "kubernetes";
|
|
46463
46558
|
var IDENTITY_METADATA = "metadata";
|
|
46464
46559
|
var IDENTITY_POOL = "pool";
|
|
46560
|
+
var IDENTITY_GITHUB_ACTIONS = "github-actions";
|
|
46465
46561
|
var IDENTITY_DEVICE_LOGIN = "device-login";
|
|
46466
46562
|
var BROKER_VARIABLES = [
|
|
46467
46563
|
BROKER_URL_VAR,
|
|
@@ -46473,6 +46569,8 @@ var BROKER_VARIABLES = [
|
|
|
46473
46569
|
PROJECTS_VAR,
|
|
46474
46570
|
POOL_AUDIENCE_VAR,
|
|
46475
46571
|
POOL_ACCOUNT_VAR,
|
|
46572
|
+
ACTIONS_ID_TOKEN_REQUEST_URL_VAR,
|
|
46573
|
+
ACTIONS_ID_TOKEN_REQUEST_TOKEN_VAR,
|
|
46476
46574
|
DEVICE_LOGIN_FILE_VAR,
|
|
46477
46575
|
SIGNIN_DIR_VAR,
|
|
46478
46576
|
"XDG_STATE_HOME",
|
|
@@ -46513,12 +46611,18 @@ function machineIdentity(env) {
|
|
|
46513
46611
|
tokenAudience
|
|
46514
46612
|
});
|
|
46515
46613
|
}
|
|
46614
|
+
case IDENTITY_GITHUB_ACTIONS: {
|
|
46615
|
+
const requestUrl = required2(env, ACTIONS_ID_TOKEN_REQUEST_URL_VAR, kind);
|
|
46616
|
+
const requestToken = required2(env, ACTIONS_ID_TOKEN_REQUEST_TOKEN_VAR, kind);
|
|
46617
|
+
const audience = required2(env, MACHINE_AUDIENCE_VAR, kind);
|
|
46618
|
+
return githubActionsIdentity({ requestUrl, requestToken, audience });
|
|
46619
|
+
}
|
|
46516
46620
|
case IDENTITY_DEVICE_LOGIN: {
|
|
46517
46621
|
const brokerUrl = required2(env, BROKER_URL_VAR, kind);
|
|
46518
46622
|
return new DeviceLoginIdentity({ path: deviceLoginFile(env), brokerUrl });
|
|
46519
46623
|
}
|
|
46520
46624
|
default:
|
|
46521
|
-
throw new Error(`${IDENTITY_VAR} names no identity this machine can prove; it takes ${IDENTITY_KUBERNETES}, ${IDENTITY_METADATA}, ${IDENTITY_POOL} or ${IDENTITY_DEVICE_LOGIN}`);
|
|
46625
|
+
throw new Error(`${IDENTITY_VAR} names no identity this machine can prove; it takes ${IDENTITY_KUBERNETES}, ${IDENTITY_METADATA}, ${IDENTITY_POOL}, ${IDENTITY_GITHUB_ACTIONS} or ${IDENTITY_DEVICE_LOGIN}`);
|
|
46522
46626
|
}
|
|
46523
46627
|
}
|
|
46524
46628
|
function tradeSession(env, own = "") {
|
|
@@ -47904,6 +48008,14 @@ class DispatchGatewayError extends DispatchServiceError {
|
|
|
47904
48008
|
this.mayHaveReachedDispatch = reachesDispatch(status);
|
|
47905
48009
|
}
|
|
47906
48010
|
}
|
|
48011
|
+
var CREDENTIAL_ECHOED = "CREDENTIAL_ECHOED";
|
|
48012
|
+
|
|
48013
|
+
class DispatchCredentialEchoError extends DispatchServiceError {
|
|
48014
|
+
fromDispatch = false;
|
|
48015
|
+
constructor(status) {
|
|
48016
|
+
super(CREDENTIAL_ECHOED, status, `The answer had HTTP status ${status} (2xx), so a write may have been made. The body held a credential this command presented. It is not printed. Something in Dispatch's place appears to have echoed the request. Check whether any write took effect before sending it again.`);
|
|
48017
|
+
}
|
|
48018
|
+
}
|
|
47907
48019
|
|
|
47908
48020
|
class DispatchWriteUnsettledError extends Error {
|
|
47909
48021
|
last;
|
|
@@ -47962,6 +48074,34 @@ function isJson(response) {
|
|
|
47962
48074
|
const mediaType = type.trim().toLowerCase();
|
|
47963
48075
|
return mediaType === "application/json" || mediaType.length > "+json".length && mediaType.endsWith("+json");
|
|
47964
48076
|
}
|
|
48077
|
+
function isAttachment(response) {
|
|
48078
|
+
const [type = ""] = (response.headers.get("content-disposition") ?? "").split(";");
|
|
48079
|
+
return type.trim().toLowerCase() === "attachment";
|
|
48080
|
+
}
|
|
48081
|
+
function jsonHoldsCredential(payload, credentials) {
|
|
48082
|
+
const pending = [payload];
|
|
48083
|
+
while (pending.length > 0) {
|
|
48084
|
+
const value = pending.pop();
|
|
48085
|
+
if (typeof value === "string") {
|
|
48086
|
+
for (const credential of credentials) {
|
|
48087
|
+
if (value.includes(credential))
|
|
48088
|
+
return true;
|
|
48089
|
+
}
|
|
48090
|
+
} else if (value !== null && typeof value === "object") {
|
|
48091
|
+
const members = value;
|
|
48092
|
+
for (const key in members) {
|
|
48093
|
+
if (!Object.hasOwn(members, key))
|
|
48094
|
+
continue;
|
|
48095
|
+
for (const credential of credentials) {
|
|
48096
|
+
if (key.includes(credential))
|
|
48097
|
+
return true;
|
|
48098
|
+
}
|
|
48099
|
+
pending.push(members[key]);
|
|
48100
|
+
}
|
|
48101
|
+
}
|
|
48102
|
+
}
|
|
48103
|
+
return false;
|
|
48104
|
+
}
|
|
47965
48105
|
function isNoRoute(error) {
|
|
47966
48106
|
return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith(NO_ROUTE_MESSAGE_PREFIX);
|
|
47967
48107
|
}
|
|
@@ -48064,6 +48204,21 @@ function parsedJson(response, text) {
|
|
|
48064
48204
|
return;
|
|
48065
48205
|
}
|
|
48066
48206
|
}
|
|
48207
|
+
function refusalIn(json) {
|
|
48208
|
+
const shape = asErrorShape(json?.value);
|
|
48209
|
+
if (typeof shape.error !== "string")
|
|
48210
|
+
return;
|
|
48211
|
+
return {
|
|
48212
|
+
code: typeof shape.code === "string" ? shape.code : undefined,
|
|
48213
|
+
error: shape.error,
|
|
48214
|
+
candidates: shape.candidates,
|
|
48215
|
+
changed: shape.changed,
|
|
48216
|
+
current: shape.current,
|
|
48217
|
+
hint: typeof shape.hint === "string" ? shape.hint : undefined,
|
|
48218
|
+
issues: shape.issues,
|
|
48219
|
+
mismatches: shape.mismatches
|
|
48220
|
+
};
|
|
48221
|
+
}
|
|
48067
48222
|
var NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);
|
|
48068
48223
|
async function writeAnswer(response) {
|
|
48069
48224
|
if (NULL_BODY_STATUSES.has(response.status)) {
|
|
@@ -48082,16 +48237,15 @@ async function writeAnswer(response) {
|
|
|
48082
48237
|
const text = await response.text();
|
|
48083
48238
|
const typed = isJson(response);
|
|
48084
48239
|
const json = parsedJson(response, text);
|
|
48085
|
-
const
|
|
48086
|
-
const own = typeof shape.error === "string";
|
|
48240
|
+
const refusal = response.ok ? undefined : refusalIn(json);
|
|
48087
48241
|
return {
|
|
48088
48242
|
response,
|
|
48089
48243
|
malformed: text !== "" && typed && json === undefined,
|
|
48090
48244
|
notJson: text === "" || !typed,
|
|
48091
48245
|
text,
|
|
48092
48246
|
json,
|
|
48093
|
-
code:
|
|
48094
|
-
error:
|
|
48247
|
+
code: refusal?.code,
|
|
48248
|
+
error: refusal?.error,
|
|
48095
48249
|
replayed: response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1",
|
|
48096
48250
|
keyEcho: response.headers.get(IDEMPOTENCY_KEY_HEADER) ?? undefined
|
|
48097
48251
|
};
|
|
@@ -48377,8 +48531,10 @@ class DispatchClient {
|
|
|
48377
48531
|
return this.#json("GET", ["api", "v1", "limits"]);
|
|
48378
48532
|
}
|
|
48379
48533
|
async readRoute(path) {
|
|
48380
|
-
|
|
48381
|
-
|
|
48534
|
+
return this.#route("GET", path);
|
|
48535
|
+
}
|
|
48536
|
+
async sendRoute(method, path, body) {
|
|
48537
|
+
return this.#route(method, path, body);
|
|
48382
48538
|
}
|
|
48383
48539
|
async inbox(assignee) {
|
|
48384
48540
|
return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
|
|
@@ -48591,7 +48747,7 @@ class DispatchClient {
|
|
|
48591
48747
|
async fileVersion(id, version) {
|
|
48592
48748
|
const url = this.#url(["api", "v1", "artifacts", id, "versions", String(version)]);
|
|
48593
48749
|
return this.#noRoute(async () => {
|
|
48594
|
-
const response = await this.#send("GET", url, undefined, "*/*");
|
|
48750
|
+
const { answer: response } = await this.#send("GET", url, undefined, "*/*");
|
|
48595
48751
|
if (!response.ok)
|
|
48596
48752
|
return this.#response("GET", url, response);
|
|
48597
48753
|
return {
|
|
@@ -48723,7 +48879,7 @@ class DispatchClient {
|
|
|
48723
48879
|
return { status: answer.response.status, payload: this.#payloadOf(method, url, answer) };
|
|
48724
48880
|
}
|
|
48725
48881
|
return this.#noRoute(async () => {
|
|
48726
|
-
const response = await this.#send(method, url, encoded, undefined, signal);
|
|
48882
|
+
const { answer: response } = await this.#send(method, url, encoded, undefined, signal);
|
|
48727
48883
|
return { status: response.status, payload: await this.#response(method, url, response) };
|
|
48728
48884
|
}, signal);
|
|
48729
48885
|
}
|
|
@@ -48776,7 +48932,7 @@ class DispatchClient {
|
|
|
48776
48932
|
const answer = await this.#write(method, url, body, "application/json", undefined, write);
|
|
48777
48933
|
return this.#payloadOf(method, url, answer);
|
|
48778
48934
|
}
|
|
48779
|
-
return this.#noRoute(async () => this.#response(method, url, await this.#send(method, url, body)));
|
|
48935
|
+
return this.#noRoute(async () => this.#response(method, url, (await this.#send(method, url, body)).answer));
|
|
48780
48936
|
}
|
|
48781
48937
|
async#writingNothing(path, body, options = {}) {
|
|
48782
48938
|
for (let keys = 1;; keys++) {
|
|
@@ -48792,13 +48948,57 @@ class DispatchClient {
|
|
|
48792
48948
|
}
|
|
48793
48949
|
}
|
|
48794
48950
|
}
|
|
48951
|
+
async#route(method, path, body) {
|
|
48952
|
+
const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
|
|
48953
|
+
const encoded = body === undefined ? undefined : { content: body, type: "application/json" };
|
|
48954
|
+
const {
|
|
48955
|
+
answer: response,
|
|
48956
|
+
presented,
|
|
48957
|
+
stalePresentation
|
|
48958
|
+
} = await this.#send(method, url, encoded);
|
|
48959
|
+
if (!response.ok)
|
|
48960
|
+
return { payload: await this.#response(method, url, response) };
|
|
48961
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
48962
|
+
const credentials = new Set(this.#sent.with(this.token));
|
|
48963
|
+
for (const headers of [presented, stalePresentation]) {
|
|
48964
|
+
if (headers === undefined)
|
|
48965
|
+
continue;
|
|
48966
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
48967
|
+
const header = name.toLowerCase();
|
|
48968
|
+
if (header !== "authorization" && header !== "dpop")
|
|
48969
|
+
continue;
|
|
48970
|
+
const credential = value.trim();
|
|
48971
|
+
if (credential !== "")
|
|
48972
|
+
credentials.add(credential);
|
|
48973
|
+
}
|
|
48974
|
+
}
|
|
48975
|
+
const raw = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
48976
|
+
for (const credential of credentials) {
|
|
48977
|
+
if (raw.includes(credential))
|
|
48978
|
+
throw new DispatchCredentialEchoError(response.status);
|
|
48979
|
+
}
|
|
48980
|
+
if (!isAttachment(response) && isJson(response)) {
|
|
48981
|
+
const text = new TextDecoder().decode(bytes);
|
|
48982
|
+
const json = parsedJson(response, text);
|
|
48983
|
+
if (json !== undefined) {
|
|
48984
|
+
if (text.includes("\\") && jsonHoldsCredential(json.value, credentials)) {
|
|
48985
|
+
throw new DispatchCredentialEchoError(response.status);
|
|
48986
|
+
}
|
|
48987
|
+
return { payload: this.#payloadOf(method, url, { response, text, json }) };
|
|
48988
|
+
}
|
|
48989
|
+
}
|
|
48990
|
+
return { body: bytes, type: response.headers.get("Content-Type") ?? undefined };
|
|
48991
|
+
}
|
|
48795
48992
|
async#send(method, url, body, accept = "application/json", signal) {
|
|
48796
48993
|
const sent = await this.#sendOnce(method, url, body, accept, signal);
|
|
48797
48994
|
if (this.#credential.stale === undefined || !await tokenNotLive(sent.answer)) {
|
|
48798
|
-
return sent
|
|
48995
|
+
return sent;
|
|
48799
48996
|
}
|
|
48800
48997
|
this.#credential.stale(undefined, sent.presented);
|
|
48801
|
-
return
|
|
48998
|
+
return {
|
|
48999
|
+
...await this.#sendOnce(method, url, body, accept, signal),
|
|
49000
|
+
stalePresentation: sent.presented
|
|
49001
|
+
};
|
|
48802
49002
|
}
|
|
48803
49003
|
async#sendOnce(method, url, body, accept, signal) {
|
|
48804
49004
|
const limit = signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]);
|
|
@@ -49069,12 +49269,12 @@ class DispatchClient {
|
|
|
49069
49269
|
const { response, text, json } = answer;
|
|
49070
49270
|
const payload = json === undefined ? text : json.value;
|
|
49071
49271
|
if (!response.ok) {
|
|
49072
|
-
const
|
|
49073
|
-
if (
|
|
49074
|
-
if (response.status === 409 &&
|
|
49272
|
+
const refusal = refusalIn(json);
|
|
49273
|
+
if (refusal !== undefined) {
|
|
49274
|
+
if (response.status === 409 && refusal.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
49075
49275
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
49076
49276
|
}
|
|
49077
|
-
throw new DispatchServiceError(
|
|
49277
|
+
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error, refusal);
|
|
49078
49278
|
}
|
|
49079
49279
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
49080
49280
|
}
|
|
@@ -49113,6 +49313,12 @@ import { homedir as homedir2 } from "os";
|
|
|
49113
49313
|
import { join as join6 } from "path";
|
|
49114
49314
|
var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
|
|
49115
49315
|
var PRIVATE_FILE = 384;
|
|
49316
|
+
var SESSION_VARIABLES = [
|
|
49317
|
+
"ENVOY_SESSION_ID",
|
|
49318
|
+
"CLAUDE_CODE_SESSION_ID",
|
|
49319
|
+
"DISPATCH_SESSION_ID",
|
|
49320
|
+
"CODEX_THREAD_ID"
|
|
49321
|
+
];
|
|
49116
49322
|
function sessionStateRoot(env) {
|
|
49117
49323
|
const stateDir = env["DISPATCH_STATE_DIR"];
|
|
49118
49324
|
if (stateDir)
|
|
@@ -56308,13 +56514,144 @@ async function resultsCommand(context) {
|
|
|
56308
56514
|
}
|
|
56309
56515
|
|
|
56310
56516
|
// ../envoy-client/src/dispatch-commands/api.ts
|
|
56517
|
+
var GATED_WHY = "this session's AskGate reviews Dispatch writes, so dispatch api sends only GET here";
|
|
56518
|
+
var NO_ROW = "the dispatch command that makes it (dispatch --help lists them)";
|
|
56519
|
+
var WRITE_ROUTES = [
|
|
56520
|
+
{ method: "POST", pattern: "/api/v1/issues", commands: ["issue"] },
|
|
56521
|
+
{ method: "PATCH", pattern: "/api/v1/issues/{key}", commands: ["issue-update"] },
|
|
56522
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/status-change", commands: ["issue-update"] },
|
|
56523
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/claim", commands: ["claim"] },
|
|
56524
|
+
{ method: "DELETE", pattern: "/api/v1/issues/{key}/claim", commands: ["claim"] },
|
|
56525
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/asks", commands: ["ask"] },
|
|
56526
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/asks", commands: ["ask"] },
|
|
56527
|
+
{ method: "PATCH", pattern: "/api/v1/asks/{id}", commands: ["edit-ask"] },
|
|
56528
|
+
{ method: "POST", pattern: "/api/v1/asks/{id}/resolve", commands: ["resolve-ask"] },
|
|
56529
|
+
{ method: "PUT", pattern: "/api/v1/asks/{id}/followers/{session}", commands: ["follow"] },
|
|
56530
|
+
{ method: "DELETE", pattern: "/api/v1/asks/{id}/followers/{session}", commands: ["follow"] },
|
|
56531
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/comments", commands: ["comment", "suggest"] },
|
|
56532
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/comments", commands: ["comment", "suggest"] },
|
|
56533
|
+
{ method: "POST", pattern: "/api/v1/comments/{id}/resolve", commands: ["resolve-comment"] },
|
|
56534
|
+
{ method: "PATCH", pattern: "/api/v1/comments/{id}", commands: ["edit-comment"] },
|
|
56535
|
+
{ method: "DELETE", pattern: "/api/v1/comments/{id}", commands: ["delete-comment"] },
|
|
56536
|
+
{ method: "PATCH", pattern: "/api/v1/messages/{id}", commands: ["edit-message"] },
|
|
56537
|
+
{ method: "DELETE", pattern: "/api/v1/messages/{id}", commands: ["delete-message"] },
|
|
56538
|
+
{
|
|
56539
|
+
method: "POST",
|
|
56540
|
+
pattern: "/api/v1/issues/{key}/messages",
|
|
56541
|
+
commands: ["message", "issue-update"]
|
|
56542
|
+
},
|
|
56543
|
+
{ method: "POST", pattern: "/api/v1/messages/{id}/reply", commands: ["message"] },
|
|
56544
|
+
{ method: "POST", pattern: "/api/v1/agents/{session}/artifacts", commands: ["message"] },
|
|
56545
|
+
{ method: "POST", pattern: "/api/v1/agents/{session}/messages", commands: ["send-to-agent"] },
|
|
56546
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/edits", commands: ["doc-edit"] },
|
|
56547
|
+
{
|
|
56548
|
+
method: "POST",
|
|
56549
|
+
pattern: "/api/v1/artifacts/{id}/approval-requests",
|
|
56550
|
+
commands: ["request-approval"]
|
|
56551
|
+
},
|
|
56552
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/plan-reviews", commands: ["plan-approve"] },
|
|
56553
|
+
{
|
|
56554
|
+
method: "POST",
|
|
56555
|
+
pattern: "/api/v1/artifacts/{id}/versions/{number}/reviews",
|
|
56556
|
+
commands: ["review"]
|
|
56557
|
+
},
|
|
56558
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/results", commands: ["result"] },
|
|
56559
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/results/dry-run", commands: ["result"] },
|
|
56560
|
+
{ method: "POST", pattern: "/api/v1/results/{id}/retract", commands: ["result"] },
|
|
56561
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/handoffs/{phase}", commands: ["handoff-write"] },
|
|
56562
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/artifacts", commands: ["artifact"] },
|
|
56563
|
+
{ method: "POST", pattern: "/api/v1/projects/{key}/artifacts", commands: ["artifact"] },
|
|
56564
|
+
{ method: "POST", pattern: "/api/v1/markdown/round-trip", commands: ["artifact"] },
|
|
56565
|
+
{ method: "POST", pattern: "/api/v1/projects", commands: ["project"] },
|
|
56566
|
+
{
|
|
56567
|
+
method: "PUT",
|
|
56568
|
+
pattern: "/api/v1/projects/{key}/proven-sessions",
|
|
56569
|
+
commands: ["project-update"]
|
|
56570
|
+
},
|
|
56571
|
+
{
|
|
56572
|
+
method: "DELETE",
|
|
56573
|
+
pattern: "/api/v1/projects/{key}/proven-sessions",
|
|
56574
|
+
commands: ["project-update"]
|
|
56575
|
+
},
|
|
56576
|
+
{ method: "POST", pattern: "/api/v1/projects/{key}/related", commands: ["related"] },
|
|
56577
|
+
{
|
|
56578
|
+
method: "POST",
|
|
56579
|
+
pattern: "/api/v1/projects/{key}/architecture-sources/sync",
|
|
56580
|
+
commands: ["architecture-sync"]
|
|
56581
|
+
},
|
|
56582
|
+
{
|
|
56583
|
+
method: "POST",
|
|
56584
|
+
pattern: "/api/v1/projects/{key}/architecture-source/sync",
|
|
56585
|
+
commands: ["architecture-sync"]
|
|
56586
|
+
},
|
|
56587
|
+
{
|
|
56588
|
+
method: "POST",
|
|
56589
|
+
pattern: "/api/v1/projects/{key}/architecture-sources/{owner}/{repo}/sync",
|
|
56590
|
+
commands: ["architecture-sync"]
|
|
56591
|
+
}
|
|
56592
|
+
];
|
|
56593
|
+
function writeRoute(method, path) {
|
|
56594
|
+
const segments = path.split("/");
|
|
56595
|
+
return WRITE_ROUTES.find((row) => {
|
|
56596
|
+
const pattern = row.pattern.split("/");
|
|
56597
|
+
return row.method === method && pattern.length === segments.length && pattern.every((part, at) => part.startsWith("{") ? segments[at] !== "" : part === segments[at]);
|
|
56598
|
+
});
|
|
56599
|
+
}
|
|
56600
|
+
|
|
56601
|
+
class ApiGateRefusal extends Error {
|
|
56602
|
+
askgate;
|
|
56603
|
+
name = "ApiGateRefusal";
|
|
56604
|
+
constructor(message, askgate) {
|
|
56605
|
+
super(message);
|
|
56606
|
+
this.askgate = askgate;
|
|
56607
|
+
}
|
|
56608
|
+
}
|
|
56609
|
+
function gatedWriteRefusal(method, path, env) {
|
|
56610
|
+
const gates = [];
|
|
56611
|
+
for (const variable of SESSION_VARIABLES) {
|
|
56612
|
+
const id = env[variable];
|
|
56613
|
+
if (id === undefined || id === "")
|
|
56614
|
+
continue;
|
|
56615
|
+
let dir;
|
|
56616
|
+
try {
|
|
56617
|
+
dir = sessionDirectory(env, id);
|
|
56618
|
+
} catch {
|
|
56619
|
+
return new ToolInputError("dispatch_api", [
|
|
56620
|
+
`${variable} holds no session id whose AskGate record can be read: an id is 1-128 letters, digits, ".", "_" or "-". Unset ${variable}, or set it to the id of your own session.`
|
|
56621
|
+
], { aboutAFlag: false });
|
|
56622
|
+
}
|
|
56623
|
+
gates.push(askgateState(dir));
|
|
56624
|
+
}
|
|
56625
|
+
const broken = gates.find((gate) => gate.kind === "broken");
|
|
56626
|
+
const gated = gates.some((gate) => gate.kind === "on");
|
|
56627
|
+
if (!gated && broken === undefined)
|
|
56628
|
+
return;
|
|
56629
|
+
const row = writeRoute(method, path.split("?", 1)[0] ?? "");
|
|
56630
|
+
const command = row === undefined ? NO_ROW : row.commands.map((name) => `dispatch ${name}`).join(" or ");
|
|
56631
|
+
return gated || broken === undefined ? new ApiGateRefusal(`dispatch api was not called: ${GATED_WHY}; make this write with ${command}`, { mode: "block", why: GATED_WHY }) : new ApiGateRefusal(`dispatch api was not called: AskGate's record for this session, ${broken.problem}, so whether AskGate reviews this session's Dispatch writes cannot be told, and dispatch api sends only GET here; make this write with ${command}`, { mode: "block", why: broken.problem });
|
|
56632
|
+
}
|
|
56633
|
+
async function sendApiCall(args, env, client) {
|
|
56634
|
+
const path = stringArg(args, "path");
|
|
56635
|
+
const method = optionalString(args, "method");
|
|
56636
|
+
if (method !== undefined) {
|
|
56637
|
+
const refusal = gatedWriteRefusal(method, path, env);
|
|
56638
|
+
if (refusal !== undefined)
|
|
56639
|
+
throw refusal;
|
|
56640
|
+
}
|
|
56641
|
+
const answer = method === undefined ? await client.readRoute(path) : await client.sendRoute(method, path, optionalString(args, "body"));
|
|
56642
|
+
const details = { path, ...defined("method", method) };
|
|
56643
|
+
if ("body" in answer) {
|
|
56644
|
+
const { body, type } = answer;
|
|
56645
|
+
return {
|
|
56646
|
+
text: `the answer's body as it came: ${body.byteLength} bytes (${type ?? "no Content-Type"})`,
|
|
56647
|
+
body,
|
|
56648
|
+
details: { ...details, ...defined("content_type", type), bytes: body.byteLength }
|
|
56649
|
+
};
|
|
56650
|
+
}
|
|
56651
|
+
return { text: JSON.stringify(answer.payload, null, 2), details };
|
|
56652
|
+
}
|
|
56311
56653
|
async function apiCommand(context) {
|
|
56312
|
-
|
|
56313
|
-
const answer = await context.newClient().readRoute(path);
|
|
56314
|
-
return {
|
|
56315
|
-
text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
|
|
56316
|
-
details: { path }
|
|
56317
|
-
};
|
|
56654
|
+
return await sendApiCall(context.args, context.input.env ?? {}, context.newClient());
|
|
56318
56655
|
}
|
|
56319
56656
|
|
|
56320
56657
|
// ../envoy-client/src/dispatch-commands/render-item.ts
|
|
@@ -58922,12 +59259,15 @@ async function whoamiCommand(context) {
|
|
|
58922
59259
|
const service = identity.kind === "agent" ? identity.service ?? null : null;
|
|
58923
59260
|
const proved = identity.kind === "agent" ? identity.session ?? null : null;
|
|
58924
59261
|
const project = identity.kind === "agent" ? identity.project ?? null : null;
|
|
59262
|
+
const projectScope = identity.kind === "agent" ? identity.project_scope ?? null : null;
|
|
58925
59263
|
const readOnly = identity.scopes?.includes("read") === true;
|
|
58926
59264
|
const cut = identity.kind === "agent" ? identity.cut ?? null : null;
|
|
58927
59265
|
const session = proved ?? sessionId;
|
|
58928
59266
|
const unowned = "no owner, so an issue you create without an assignee takes its parent's assignee when the parent is in the same project, else the project's default assignee, which every project names, so the issue always has one.";
|
|
59267
|
+
const brokerService = owner === null && service !== null && proved !== null;
|
|
58929
59268
|
const answered = identity.kind === "agent" ? identity.sign_in_required : undefined;
|
|
58930
|
-
const signInNeeded = answered ??
|
|
59269
|
+
const signInNeeded = answered ?? brokerService;
|
|
59270
|
+
const writesAsService = brokerService && !signInNeeded;
|
|
58931
59271
|
const who = owner !== null ? `acts for ${owner}` : service !== null ? `runs as service ${serviceSubjectLabel(service)}` : "runs";
|
|
58932
59272
|
const named = proved !== null && proved !== sessionId ? ` Your credential names session ${proved}, which is not this host session (${sessionId})` : "";
|
|
58933
59273
|
let acting;
|
|
@@ -58939,15 +59279,17 @@ async function whoamiCommand(context) {
|
|
|
58939
59279
|
acting = `Session ${session} ${who}: issues you create without an assignee are assigned to ${owner}.`;
|
|
58940
59280
|
} else if (signInNeeded) {
|
|
58941
59281
|
acting = `Session ${session} ${who} and no person, so it may read but Dispatch refuses every write it makes: run \`agent-secrets login\` on this machine to write as yourself.`;
|
|
59282
|
+
} else if (writesAsService) {
|
|
59283
|
+
acting = `Session ${session} ${who} and no person, and writes as that service with ${unowned}`;
|
|
58942
59284
|
} else if (service !== null) {
|
|
58943
59285
|
acting = `Session ${session} ${who}: ${unowned}`;
|
|
58944
59286
|
} else {
|
|
58945
59287
|
acting = `Session ${session} runs under the shared token: ${unowned}`;
|
|
58946
59288
|
}
|
|
58947
|
-
const writable = project !== null
|
|
59289
|
+
const writable = readOnly ? "" : project !== null ? ` It may write project ${project} and no other.` : writesAsService ? " It names no one project, so it may write wherever a token that names no project may." : "";
|
|
58948
59290
|
return {
|
|
58949
59291
|
text: acting + elsewhere + writable,
|
|
58950
|
-
details: { session, owner, service, project }
|
|
59292
|
+
details: { session, owner, service, project, project_scope: projectScope }
|
|
58951
59293
|
};
|
|
58952
59294
|
}
|
|
58953
59295
|
async function limitsCommand(context) {
|
|
@@ -65594,7 +65936,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
|
|
|
65594
65936
|
|
|
65595
65937
|
// package.json
|
|
65596
65938
|
var name2 = "@sjawhar/claude-envoy";
|
|
65597
|
-
var version2 = "6.0
|
|
65939
|
+
var version2 = "6.1.0";
|
|
65598
65940
|
var package_default = {
|
|
65599
65941
|
name: name2,
|
|
65600
65942
|
version: version2,
|