@sjawhar/claude-envoy 6.0.3 → 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/session-hook.js
CHANGED
|
@@ -980,8 +980,8 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// hooks/session-hook.ts
|
|
983
|
-
import { appendFileSync as appendFileSync2, mkdirSync as
|
|
984
|
-
import { join as
|
|
983
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync7, rmSync as rmSync3, statSync as statSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
984
|
+
import { join as join13 } from "path";
|
|
985
985
|
|
|
986
986
|
// ../cipher-client/src/device-login-file.ts
|
|
987
987
|
import { createPrivateKey, randomUUID as randomUUID2 } from "crypto";
|
|
@@ -2956,6 +2956,7 @@ var FORM_AS_OF = "as_of";
|
|
|
2956
2956
|
var HEADER_DPOP_HOLDER = "DPoP-Holder";
|
|
2957
2957
|
var SUBJECT_TOKEN_TYPE_KUBERNETES = "urn:envoy:params:oauth:token-type:kubernetes-service-account";
|
|
2958
2958
|
var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identity";
|
|
2959
|
+
var SUBJECT_TOKEN_TYPE_GITHUB = "urn:envoy:params:oauth:token-type:github-workflow-run";
|
|
2959
2960
|
var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
|
|
2960
2961
|
var ACTOR_TOKEN_TYPE_MACHINE = "urn:envoy:params:oauth:token-type:machine-google-identity";
|
|
2961
2962
|
var TOKEN_TYPE_DPOP = "DPoP";
|
|
@@ -2989,6 +2990,7 @@ var WORKFLOW_REF = "[A-Za-z0-9_./@-]{1,400}";
|
|
|
2989
2990
|
var IDENTITY = `(?:${K8S_ACCOUNT}|${REPOSITORY}/${WORKFLOW_PATH}|${EMAIL})`;
|
|
2990
2991
|
var FIXED_SESSION = "[A-Za-z0-9._:@/+-]{1,200}";
|
|
2991
2992
|
var PROJECT_LIST = `${PROJECT_SLOT}(?: ${PROJECT_SLOT}){0,31}`;
|
|
2993
|
+
var JOB_LIST = `(?:public(?:,${PROJECT_SLOT}){0,16}|${PROJECT_SLOT})`;
|
|
2992
2994
|
var SERVICE = "[A-Za-z0-9._-]{1,100}";
|
|
2993
2995
|
var CLOUD_PROJECT = "[a-z][a-z0-9-]{4,29}";
|
|
2994
2996
|
var INSTANCE = "[a-z0-9][a-z0-9-]{0,62}";
|
|
@@ -3058,6 +3060,7 @@ var POLICY_REFUSAL_PATTERNS = [
|
|
|
3058
3060
|
policy("claimMissing", "the subject token's %s claim is not a non-empty string", CLAIM),
|
|
3059
3061
|
policy("projectsFixed", "%s's entry names no project, and the request named %s", IDENTITY, PROJECT_LIST),
|
|
3060
3062
|
policy("projectsFixed", "%s writes the project %s that its entry names, and the request named %s", IDENTITY, PROJECT_SLOT, PROJECT_LIST),
|
|
3063
|
+
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),
|
|
3061
3064
|
`${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])}\\.`
|
|
3062
3065
|
];
|
|
3063
3066
|
var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
@@ -3083,6 +3086,7 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
|
|
|
3083
3086
|
"The 'as_of' parameter is not an RFC 3339 time with at most six fractional digits\\.",
|
|
3084
3087
|
"The 'as_of' parameter names the zero time, which is no cut: a trade that reads the present names no cut\\.",
|
|
3085
3088
|
"The 'as_of' parameter names a time later than this trade, and a cut is a time that has passed\\.",
|
|
3089
|
+
"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\\.",
|
|
3086
3090
|
"A read trade makes or moves no launcher credential, so it cannot send launcher_credential=true\\. Trade for read without the parameter\\.",
|
|
3087
3091
|
`${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\\.`,
|
|
3088
3092
|
`${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\\.`,
|
|
@@ -18033,7 +18037,11 @@ var projectKeyValidation = {
|
|
|
18033
18037
|
};
|
|
18034
18038
|
var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
|
|
18035
18039
|
var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
|
|
18036
|
-
var
|
|
18040
|
+
var API_ROUTE_REWRITTEN = /["<>^`{}]/;
|
|
18041
|
+
var DISPATCH_API_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
18042
|
+
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 ..';
|
|
18043
|
+
var API_BODY_RULE = "body goes only with method: a call that names no method is a GET, which sends no body.";
|
|
18044
|
+
var API_CALL_RULE = `${API_PATH_RULE}; ${API_BODY_RULE}`;
|
|
18037
18045
|
function apiPathProblem(value) {
|
|
18038
18046
|
const { path } = value;
|
|
18039
18047
|
if (typeof path !== "string")
|
|
@@ -18046,11 +18054,21 @@ function apiPathProblem(value) {
|
|
|
18046
18054
|
return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
|
|
18047
18055
|
}
|
|
18048
18056
|
const route = path.split("?", 1)[0] ?? "";
|
|
18057
|
+
if (API_ROUTE_REWRITTEN.test(route)) {
|
|
18058
|
+
return `path ${named} holds before its query a character a URL parser rewrites in a path (", <, >, ^, \`, { or }): percent-encode it.`;
|
|
18059
|
+
}
|
|
18049
18060
|
if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
|
|
18050
18061
|
return `path ${named} holds a . or .. segment: name the route itself.`;
|
|
18051
18062
|
}
|
|
18052
18063
|
return;
|
|
18053
18064
|
}
|
|
18065
|
+
function apiCallProblem(value) {
|
|
18066
|
+
const pathProblem = apiPathProblem(value);
|
|
18067
|
+
if (pathProblem !== undefined)
|
|
18068
|
+
return pathProblem;
|
|
18069
|
+
const { method, body } = value;
|
|
18070
|
+
return body !== undefined && method === undefined ? API_BODY_RULE : undefined;
|
|
18071
|
+
}
|
|
18054
18072
|
var ISSUE_STATUSES = [
|
|
18055
18073
|
"triage",
|
|
18056
18074
|
"icebox",
|
|
@@ -18657,7 +18675,7 @@ var dispatchToolSpecs = [
|
|
|
18657
18675
|
{
|
|
18658
18676
|
name: "dispatch_whoami",
|
|
18659
18677
|
example: {},
|
|
18660
|
-
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
|
|
18678
|
+
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.",
|
|
18661
18679
|
arguments: () => ({}),
|
|
18662
18680
|
strict: true
|
|
18663
18681
|
},
|
|
@@ -18671,14 +18689,16 @@ var dispatchToolSpecs = [
|
|
|
18671
18689
|
{
|
|
18672
18690
|
name: "dispatch_api",
|
|
18673
18691
|
example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
|
|
18674
|
-
description: "
|
|
18692
|
+
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.",
|
|
18675
18693
|
arguments: (z) => ({
|
|
18676
|
-
path: z.string({ min: 1 }).describe(
|
|
18694
|
+
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.'),
|
|
18695
|
+
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(),
|
|
18696
|
+
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()
|
|
18677
18697
|
}),
|
|
18678
18698
|
validation: {
|
|
18679
|
-
check: (value) =>
|
|
18680
|
-
message:
|
|
18681
|
-
refusal: (value) =>
|
|
18699
|
+
check: (value) => apiCallProblem(value) === undefined,
|
|
18700
|
+
message: API_CALL_RULE,
|
|
18701
|
+
refusal: (value) => apiCallProblem(value) ?? API_CALL_RULE
|
|
18682
18702
|
},
|
|
18683
18703
|
strict: true
|
|
18684
18704
|
},
|
|
@@ -26120,6 +26140,14 @@ class DispatchGatewayError extends DispatchServiceError {
|
|
|
26120
26140
|
this.mayHaveReachedDispatch = reachesDispatch(status);
|
|
26121
26141
|
}
|
|
26122
26142
|
}
|
|
26143
|
+
var CREDENTIAL_ECHOED = "CREDENTIAL_ECHOED";
|
|
26144
|
+
|
|
26145
|
+
class DispatchCredentialEchoError extends DispatchServiceError {
|
|
26146
|
+
fromDispatch = false;
|
|
26147
|
+
constructor(status) {
|
|
26148
|
+
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.`);
|
|
26149
|
+
}
|
|
26150
|
+
}
|
|
26123
26151
|
|
|
26124
26152
|
class DispatchWriteUnsettledError extends Error {
|
|
26125
26153
|
last;
|
|
@@ -26178,6 +26206,34 @@ function isJson(response) {
|
|
|
26178
26206
|
const mediaType = type.trim().toLowerCase();
|
|
26179
26207
|
return mediaType === "application/json" || mediaType.length > "+json".length && mediaType.endsWith("+json");
|
|
26180
26208
|
}
|
|
26209
|
+
function isAttachment(response) {
|
|
26210
|
+
const [type = ""] = (response.headers.get("content-disposition") ?? "").split(";");
|
|
26211
|
+
return type.trim().toLowerCase() === "attachment";
|
|
26212
|
+
}
|
|
26213
|
+
function jsonHoldsCredential(payload, credentials) {
|
|
26214
|
+
const pending = [payload];
|
|
26215
|
+
while (pending.length > 0) {
|
|
26216
|
+
const value = pending.pop();
|
|
26217
|
+
if (typeof value === "string") {
|
|
26218
|
+
for (const credential of credentials) {
|
|
26219
|
+
if (value.includes(credential))
|
|
26220
|
+
return true;
|
|
26221
|
+
}
|
|
26222
|
+
} else if (value !== null && typeof value === "object") {
|
|
26223
|
+
const members = value;
|
|
26224
|
+
for (const key in members) {
|
|
26225
|
+
if (!Object.hasOwn(members, key))
|
|
26226
|
+
continue;
|
|
26227
|
+
for (const credential of credentials) {
|
|
26228
|
+
if (key.includes(credential))
|
|
26229
|
+
return true;
|
|
26230
|
+
}
|
|
26231
|
+
pending.push(members[key]);
|
|
26232
|
+
}
|
|
26233
|
+
}
|
|
26234
|
+
}
|
|
26235
|
+
return false;
|
|
26236
|
+
}
|
|
26181
26237
|
function isNoRoute(error) {
|
|
26182
26238
|
return error instanceof DispatchServiceError && error.status === 404 && error.code === "NOT_FOUND" && error.message.startsWith(NO_ROUTE_MESSAGE_PREFIX);
|
|
26183
26239
|
}
|
|
@@ -26280,6 +26336,21 @@ function parsedJson(response, text) {
|
|
|
26280
26336
|
return;
|
|
26281
26337
|
}
|
|
26282
26338
|
}
|
|
26339
|
+
function refusalIn(json) {
|
|
26340
|
+
const shape = asErrorShape(json?.value);
|
|
26341
|
+
if (typeof shape.error !== "string")
|
|
26342
|
+
return;
|
|
26343
|
+
return {
|
|
26344
|
+
code: typeof shape.code === "string" ? shape.code : undefined,
|
|
26345
|
+
error: shape.error,
|
|
26346
|
+
candidates: shape.candidates,
|
|
26347
|
+
changed: shape.changed,
|
|
26348
|
+
current: shape.current,
|
|
26349
|
+
hint: typeof shape.hint === "string" ? shape.hint : undefined,
|
|
26350
|
+
issues: shape.issues,
|
|
26351
|
+
mismatches: shape.mismatches
|
|
26352
|
+
};
|
|
26353
|
+
}
|
|
26283
26354
|
var NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);
|
|
26284
26355
|
async function writeAnswer(response) {
|
|
26285
26356
|
if (NULL_BODY_STATUSES.has(response.status)) {
|
|
@@ -26298,16 +26369,15 @@ async function writeAnswer(response) {
|
|
|
26298
26369
|
const text = await response.text();
|
|
26299
26370
|
const typed = isJson(response);
|
|
26300
26371
|
const json = parsedJson(response, text);
|
|
26301
|
-
const
|
|
26302
|
-
const own = typeof shape.error === "string";
|
|
26372
|
+
const refusal = response.ok ? undefined : refusalIn(json);
|
|
26303
26373
|
return {
|
|
26304
26374
|
response,
|
|
26305
26375
|
malformed: text !== "" && typed && json === undefined,
|
|
26306
26376
|
notJson: text === "" || !typed,
|
|
26307
26377
|
text,
|
|
26308
26378
|
json,
|
|
26309
|
-
code:
|
|
26310
|
-
error:
|
|
26379
|
+
code: refusal?.code,
|
|
26380
|
+
error: refusal?.error,
|
|
26311
26381
|
replayed: response.headers.get(IDEMPOTENCY_REPLAYED_HEADER)?.trim() === "?1",
|
|
26312
26382
|
keyEcho: response.headers.get(IDEMPOTENCY_KEY_HEADER) ?? undefined
|
|
26313
26383
|
};
|
|
@@ -26593,8 +26663,10 @@ class DispatchClient {
|
|
|
26593
26663
|
return this.#json("GET", ["api", "v1", "limits"]);
|
|
26594
26664
|
}
|
|
26595
26665
|
async readRoute(path) {
|
|
26596
|
-
|
|
26597
|
-
|
|
26666
|
+
return this.#route("GET", path);
|
|
26667
|
+
}
|
|
26668
|
+
async sendRoute(method, path, body) {
|
|
26669
|
+
return this.#route(method, path, body);
|
|
26598
26670
|
}
|
|
26599
26671
|
async inbox(assignee) {
|
|
26600
26672
|
return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
|
|
@@ -26807,7 +26879,7 @@ class DispatchClient {
|
|
|
26807
26879
|
async fileVersion(id, version) {
|
|
26808
26880
|
const url = this.#url(["api", "v1", "artifacts", id, "versions", String(version)]);
|
|
26809
26881
|
return this.#noRoute(async () => {
|
|
26810
|
-
const response = await this.#send("GET", url, undefined, "*/*");
|
|
26882
|
+
const { answer: response } = await this.#send("GET", url, undefined, "*/*");
|
|
26811
26883
|
if (!response.ok)
|
|
26812
26884
|
return this.#response("GET", url, response);
|
|
26813
26885
|
return {
|
|
@@ -26939,7 +27011,7 @@ class DispatchClient {
|
|
|
26939
27011
|
return { status: answer.response.status, payload: this.#payloadOf(method, url, answer) };
|
|
26940
27012
|
}
|
|
26941
27013
|
return this.#noRoute(async () => {
|
|
26942
|
-
const response = await this.#send(method, url, encoded, undefined, signal);
|
|
27014
|
+
const { answer: response } = await this.#send(method, url, encoded, undefined, signal);
|
|
26943
27015
|
return { status: response.status, payload: await this.#response(method, url, response) };
|
|
26944
27016
|
}, signal);
|
|
26945
27017
|
}
|
|
@@ -26992,7 +27064,7 @@ class DispatchClient {
|
|
|
26992
27064
|
const answer = await this.#write(method, url, body, "application/json", undefined, write);
|
|
26993
27065
|
return this.#payloadOf(method, url, answer);
|
|
26994
27066
|
}
|
|
26995
|
-
return this.#noRoute(async () => this.#response(method, url, await this.#send(method, url, body)));
|
|
27067
|
+
return this.#noRoute(async () => this.#response(method, url, (await this.#send(method, url, body)).answer));
|
|
26996
27068
|
}
|
|
26997
27069
|
async#writingNothing(path, body, options = {}) {
|
|
26998
27070
|
for (let keys = 1;; keys++) {
|
|
@@ -27008,13 +27080,57 @@ class DispatchClient {
|
|
|
27008
27080
|
}
|
|
27009
27081
|
}
|
|
27010
27082
|
}
|
|
27083
|
+
async#route(method, path, body) {
|
|
27084
|
+
const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
|
|
27085
|
+
const encoded = body === undefined ? undefined : { content: body, type: "application/json" };
|
|
27086
|
+
const {
|
|
27087
|
+
answer: response,
|
|
27088
|
+
presented,
|
|
27089
|
+
stalePresentation
|
|
27090
|
+
} = await this.#send(method, url, encoded);
|
|
27091
|
+
if (!response.ok)
|
|
27092
|
+
return { payload: await this.#response(method, url, response) };
|
|
27093
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
27094
|
+
const credentials = new Set(this.#sent.with(this.token));
|
|
27095
|
+
for (const headers of [presented, stalePresentation]) {
|
|
27096
|
+
if (headers === undefined)
|
|
27097
|
+
continue;
|
|
27098
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
27099
|
+
const header = name.toLowerCase();
|
|
27100
|
+
if (header !== "authorization" && header !== "dpop")
|
|
27101
|
+
continue;
|
|
27102
|
+
const credential = value.trim();
|
|
27103
|
+
if (credential !== "")
|
|
27104
|
+
credentials.add(credential);
|
|
27105
|
+
}
|
|
27106
|
+
}
|
|
27107
|
+
const raw = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
27108
|
+
for (const credential of credentials) {
|
|
27109
|
+
if (raw.includes(credential))
|
|
27110
|
+
throw new DispatchCredentialEchoError(response.status);
|
|
27111
|
+
}
|
|
27112
|
+
if (!isAttachment(response) && isJson(response)) {
|
|
27113
|
+
const text = new TextDecoder().decode(bytes);
|
|
27114
|
+
const json = parsedJson(response, text);
|
|
27115
|
+
if (json !== undefined) {
|
|
27116
|
+
if (text.includes("\\") && jsonHoldsCredential(json.value, credentials)) {
|
|
27117
|
+
throw new DispatchCredentialEchoError(response.status);
|
|
27118
|
+
}
|
|
27119
|
+
return { payload: this.#payloadOf(method, url, { response, text, json }) };
|
|
27120
|
+
}
|
|
27121
|
+
}
|
|
27122
|
+
return { body: bytes, type: response.headers.get("Content-Type") ?? undefined };
|
|
27123
|
+
}
|
|
27011
27124
|
async#send(method, url, body, accept = "application/json", signal) {
|
|
27012
27125
|
const sent = await this.#sendOnce(method, url, body, accept, signal);
|
|
27013
27126
|
if (this.#credential.stale === undefined || !await tokenNotLive(sent.answer)) {
|
|
27014
|
-
return sent
|
|
27127
|
+
return sent;
|
|
27015
27128
|
}
|
|
27016
27129
|
this.#credential.stale(undefined, sent.presented);
|
|
27017
|
-
return
|
|
27130
|
+
return {
|
|
27131
|
+
...await this.#sendOnce(method, url, body, accept, signal),
|
|
27132
|
+
stalePresentation: sent.presented
|
|
27133
|
+
};
|
|
27018
27134
|
}
|
|
27019
27135
|
async#sendOnce(method, url, body, accept, signal) {
|
|
27020
27136
|
const limit = signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]);
|
|
@@ -27285,12 +27401,12 @@ class DispatchClient {
|
|
|
27285
27401
|
const { response, text, json } = answer;
|
|
27286
27402
|
const payload = json === undefined ? text : json.value;
|
|
27287
27403
|
if (!response.ok) {
|
|
27288
|
-
const
|
|
27289
|
-
if (
|
|
27290
|
-
if (response.status === 409 &&
|
|
27404
|
+
const refusal = refusalIn(json);
|
|
27405
|
+
if (refusal !== undefined) {
|
|
27406
|
+
if (response.status === 409 && refusal.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
27291
27407
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
27292
27408
|
}
|
|
27293
|
-
throw new DispatchServiceError(
|
|
27409
|
+
throw new DispatchServiceError(refusal.code ?? `HTTP_${response.status}`, response.status, refusal.error, refusal);
|
|
27294
27410
|
}
|
|
27295
27411
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
27296
27412
|
}
|
|
@@ -31565,15 +31681,517 @@ async function resultsCommand(context) {
|
|
|
31565
31681
|
};
|
|
31566
31682
|
}
|
|
31567
31683
|
|
|
31568
|
-
// ../envoy-client/src/
|
|
31569
|
-
|
|
31570
|
-
|
|
31571
|
-
|
|
31684
|
+
// ../envoy-client/src/askgate-marker.ts
|
|
31685
|
+
import { createHash, randomBytes } from "crypto";
|
|
31686
|
+
import {
|
|
31687
|
+
closeSync as closeSync2,
|
|
31688
|
+
constants as constants3,
|
|
31689
|
+
mkdirSync,
|
|
31690
|
+
openSync as openSync2,
|
|
31691
|
+
readdirSync,
|
|
31692
|
+
readFileSync,
|
|
31693
|
+
readlinkSync,
|
|
31694
|
+
renameSync,
|
|
31695
|
+
rmSync,
|
|
31696
|
+
statSync,
|
|
31697
|
+
unlinkSync,
|
|
31698
|
+
utimesSync,
|
|
31699
|
+
writeFileSync
|
|
31700
|
+
} from "fs";
|
|
31701
|
+
import { isAbsolute as isAbsolute3, join as join5, resolve as resolve2 } from "path";
|
|
31702
|
+
var ASKGATE_RECORD = "askgate";
|
|
31703
|
+
var MARKER_MAX_AGE_MS = 2 * 60 * 60000;
|
|
31704
|
+
var STORE_BEAT_MS = 10 * 60000;
|
|
31705
|
+
var MARKERS = "markers";
|
|
31706
|
+
var ALWAYS_GATED = {
|
|
31707
|
+
dispatch_ask: true,
|
|
31708
|
+
dispatch_message: true,
|
|
31709
|
+
dispatch_edit_ask: true,
|
|
31710
|
+
dispatch_comment: true,
|
|
31711
|
+
dispatch_edit_comment: true,
|
|
31712
|
+
dispatch_delete_comment: true,
|
|
31713
|
+
dispatch_edit_message: true,
|
|
31714
|
+
dispatch_delete_message: true,
|
|
31715
|
+
dispatch_doc_edit: true,
|
|
31716
|
+
dispatch_request_approval: true
|
|
31717
|
+
};
|
|
31718
|
+
var MARKDOWN_NAME = /\.md$/i;
|
|
31719
|
+
var MARKDOWN_PATH = /\.(md|markdown)$/i;
|
|
31720
|
+
function uploadIsDocument(args) {
|
|
31721
|
+
const { content, name, path } = args;
|
|
31722
|
+
return typeof content === "string" || typeof name === "string" && MARKDOWN_NAME.test(name.trim()) || typeof path === "string" && MARKDOWN_PATH.test(path);
|
|
31723
|
+
}
|
|
31724
|
+
function gatedWrite(tool, args) {
|
|
31725
|
+
if (ALWAYS_GATED[tool] === true)
|
|
31726
|
+
return true;
|
|
31727
|
+
const { spec } = args;
|
|
31728
|
+
if (tool === "dispatch_issue")
|
|
31729
|
+
return spec !== undefined;
|
|
31730
|
+
if (tool === "dispatch_artifact")
|
|
31731
|
+
return uploadIsDocument(args);
|
|
31732
|
+
return false;
|
|
31733
|
+
}
|
|
31734
|
+
var digest2 = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
31735
|
+
function argvDigest(argv) {
|
|
31736
|
+
return digest2(argv);
|
|
31737
|
+
}
|
|
31738
|
+
function argsDigest(args) {
|
|
31739
|
+
return digest2(args);
|
|
31740
|
+
}
|
|
31741
|
+
function fileOperands(argv) {
|
|
31742
|
+
const [command, ...flags] = argv;
|
|
31743
|
+
const files = [];
|
|
31744
|
+
for (let index = 0;index < flags.length; index++) {
|
|
31745
|
+
const word = flags[index];
|
|
31746
|
+
const eq = word.indexOf("=");
|
|
31747
|
+
const flag = eq === -1 ? word : word.slice(0, eq);
|
|
31748
|
+
const named = flag.startsWith("--") && flag.endsWith("-file");
|
|
31749
|
+
if (!named && !(command === "artifact" && flag === "--path"))
|
|
31750
|
+
continue;
|
|
31751
|
+
const operand = eq === -1 ? flags[index + 1] : word.slice(eq + 1);
|
|
31752
|
+
if (operand !== undefined && operand !== "-")
|
|
31753
|
+
files.push({ flag, operand });
|
|
31754
|
+
}
|
|
31755
|
+
return files;
|
|
31756
|
+
}
|
|
31757
|
+
function operandPath(cwd, file) {
|
|
31758
|
+
if (file.flag === "--path")
|
|
31759
|
+
return resolve2(cwd, file.operand);
|
|
31760
|
+
return isAbsolute3(file.operand) ? file.operand : `${cwd}/${file.operand}`;
|
|
31761
|
+
}
|
|
31762
|
+
function bytesDigest(bytes) {
|
|
31763
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
31764
|
+
}
|
|
31765
|
+
function processStart(pid) {
|
|
31766
|
+
try {
|
|
31767
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
31768
|
+
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19] ?? null;
|
|
31769
|
+
} catch {
|
|
31770
|
+
return null;
|
|
31771
|
+
}
|
|
31772
|
+
}
|
|
31773
|
+
var ownNamespace;
|
|
31774
|
+
function pidNamespace() {
|
|
31775
|
+
if (ownNamespace === undefined) {
|
|
31776
|
+
try {
|
|
31777
|
+
ownNamespace = /^pid:\[([0-9]+)\]$/.exec(readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
|
|
31778
|
+
} catch {
|
|
31779
|
+
ownNamespace = null;
|
|
31780
|
+
}
|
|
31781
|
+
}
|
|
31782
|
+
return ownNamespace;
|
|
31783
|
+
}
|
|
31784
|
+
function ownerLive(owner, now) {
|
|
31785
|
+
if (owner.ns !== null && owner.ns !== pidNamespace()) {
|
|
31786
|
+
try {
|
|
31787
|
+
return now - storeTouched(owner.store) <= MARKER_MAX_AGE_MS;
|
|
31788
|
+
} catch {
|
|
31789
|
+
return false;
|
|
31790
|
+
}
|
|
31791
|
+
}
|
|
31792
|
+
if (owner.start !== null)
|
|
31793
|
+
return processStart(owner.pid) === owner.start;
|
|
31794
|
+
try {
|
|
31795
|
+
process.kill(owner.pid, 0);
|
|
31796
|
+
return true;
|
|
31797
|
+
} catch (error) {
|
|
31798
|
+
return !hasErrnoCode(error, "ESRCH");
|
|
31799
|
+
}
|
|
31800
|
+
}
|
|
31801
|
+
function isOwnerText(value) {
|
|
31802
|
+
if (typeof value !== "object" || value === null)
|
|
31803
|
+
return false;
|
|
31804
|
+
const { pid, start, ns, store } = value;
|
|
31805
|
+
return typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0 && (start === null || typeof start === "string") && (ns === undefined || ns === null || typeof ns === "string" && /^[0-9]+$/.test(ns)) && typeof store === "string" && store.startsWith("/");
|
|
31806
|
+
}
|
|
31807
|
+
function parseOwner(text) {
|
|
31808
|
+
let data;
|
|
31809
|
+
try {
|
|
31810
|
+
data = JSON.parse(text);
|
|
31811
|
+
} catch {
|
|
31812
|
+
return;
|
|
31813
|
+
}
|
|
31814
|
+
if (!isOwnerText(data) || data.v !== 2)
|
|
31815
|
+
return;
|
|
31816
|
+
const { pid, start, ns, store, mode } = data;
|
|
31572
31817
|
return {
|
|
31573
|
-
|
|
31574
|
-
|
|
31818
|
+
owner: { pid, start, ns: ns ?? null, store },
|
|
31819
|
+
mode: mode === "block" ? "block" : "warn"
|
|
31575
31820
|
};
|
|
31576
31821
|
}
|
|
31822
|
+
var OWNER_FILE = ".json";
|
|
31823
|
+
var STORE_NAME = /^([1-9][0-9]*)(?:-([0-9]+)(?:-([0-9]+))?)?$/;
|
|
31824
|
+
function storeTouched(store) {
|
|
31825
|
+
const own = statSync(store).mtimeMs;
|
|
31826
|
+
try {
|
|
31827
|
+
return Math.max(own, statSync(join5(store, MARKERS)).mtimeMs);
|
|
31828
|
+
} catch (error) {
|
|
31829
|
+
if (hasErrnoCode(error, "ENOENT"))
|
|
31830
|
+
return own;
|
|
31831
|
+
throw error;
|
|
31832
|
+
}
|
|
31833
|
+
}
|
|
31834
|
+
var UNNAMESPACED_STORE_MAX_AGE_MS = 14 * 86400000;
|
|
31835
|
+
function sweepStores(root, now) {
|
|
31836
|
+
const parent = join5(root, "askgate");
|
|
31837
|
+
let names;
|
|
31838
|
+
try {
|
|
31839
|
+
names = readdirSync(parent);
|
|
31840
|
+
} catch {
|
|
31841
|
+
return;
|
|
31842
|
+
}
|
|
31843
|
+
for (const name of names) {
|
|
31844
|
+
const match = STORE_NAME.exec(name);
|
|
31845
|
+
if (match === null)
|
|
31846
|
+
continue;
|
|
31847
|
+
const store = join5(parent, name);
|
|
31848
|
+
try {
|
|
31849
|
+
const owner = { pid: Number(match[1]), start: match[2] ?? null, ns: match[3] ?? null, store };
|
|
31850
|
+
if (ownerLive(owner, now))
|
|
31851
|
+
continue;
|
|
31852
|
+
const unnamespaced = owner.start !== null && owner.ns === null;
|
|
31853
|
+
const keep = unnamespaced ? UNNAMESPACED_STORE_MAX_AGE_MS : MARKER_MAX_AGE_MS;
|
|
31854
|
+
if (now - storeTouched(store) <= keep)
|
|
31855
|
+
continue;
|
|
31856
|
+
rmSync(store, { recursive: true, force: true });
|
|
31857
|
+
} catch {}
|
|
31858
|
+
}
|
|
31859
|
+
}
|
|
31860
|
+
function recordNamesStore(dir) {
|
|
31861
|
+
const record = join5(dir, ASKGATE_RECORD);
|
|
31862
|
+
let names;
|
|
31863
|
+
try {
|
|
31864
|
+
names = readdirSync(record);
|
|
31865
|
+
} catch (error) {
|
|
31866
|
+
return !hasErrnoCode(error, "ENOENT");
|
|
31867
|
+
}
|
|
31868
|
+
for (const name of names) {
|
|
31869
|
+
if (!name.endsWith(OWNER_FILE))
|
|
31870
|
+
continue;
|
|
31871
|
+
try {
|
|
31872
|
+
const parsed = parseOwner(readFileSync(join5(record, name), "utf-8"));
|
|
31873
|
+
if (parsed === undefined)
|
|
31874
|
+
return true;
|
|
31875
|
+
statSync(parsed.owner.store);
|
|
31876
|
+
return true;
|
|
31877
|
+
} catch (error) {
|
|
31878
|
+
if (!hasErrnoCode(error, "ENOENT"))
|
|
31879
|
+
return true;
|
|
31880
|
+
}
|
|
31881
|
+
}
|
|
31882
|
+
return false;
|
|
31883
|
+
}
|
|
31884
|
+
function askgateState(dir, now = Date.now()) {
|
|
31885
|
+
const record = join5(dir, ASKGATE_RECORD);
|
|
31886
|
+
let names;
|
|
31887
|
+
try {
|
|
31888
|
+
names = readdirSync(record);
|
|
31889
|
+
} catch (error) {
|
|
31890
|
+
if (hasErrnoCode(error, "ENOENT"))
|
|
31891
|
+
return { kind: "off" };
|
|
31892
|
+
return { kind: "broken", problem: `${record}, could not be read: ${messageFor(error)}` };
|
|
31893
|
+
}
|
|
31894
|
+
const live = [];
|
|
31895
|
+
for (const name of names) {
|
|
31896
|
+
if (!name.endsWith(OWNER_FILE))
|
|
31897
|
+
continue;
|
|
31898
|
+
const file = join5(record, name);
|
|
31899
|
+
let text;
|
|
31900
|
+
try {
|
|
31901
|
+
text = readFileSync(file, "utf-8");
|
|
31902
|
+
} catch (error) {
|
|
31903
|
+
if (hasErrnoCode(error, "ENOENT"))
|
|
31904
|
+
continue;
|
|
31905
|
+
return { kind: "broken", problem: `${file}, could not be read: ${messageFor(error)}` };
|
|
31906
|
+
}
|
|
31907
|
+
const parsed = parseOwner(text);
|
|
31908
|
+
if (parsed === undefined)
|
|
31909
|
+
return { kind: "broken", problem: `${file}, is not an AskGate record` };
|
|
31910
|
+
if (ownerLive(parsed.owner, now)) {
|
|
31911
|
+
live.push({ file, store: parsed.owner.store, mode: parsed.mode });
|
|
31912
|
+
}
|
|
31913
|
+
}
|
|
31914
|
+
if (live.length === 0)
|
|
31915
|
+
return { kind: "off" };
|
|
31916
|
+
for (const { file, store } of live) {
|
|
31917
|
+
try {
|
|
31918
|
+
if (!statSync(join5(store, MARKERS)).isDirectory())
|
|
31919
|
+
throw new Error("not a directory");
|
|
31920
|
+
} catch (error) {
|
|
31921
|
+
return {
|
|
31922
|
+
kind: "broken",
|
|
31923
|
+
problem: `${file}, names the marker store ${store}, which cannot be read: ${messageFor(error)}`
|
|
31924
|
+
};
|
|
31925
|
+
}
|
|
31926
|
+
}
|
|
31927
|
+
return {
|
|
31928
|
+
kind: "on",
|
|
31929
|
+
stores: live.map(({ store }) => store),
|
|
31930
|
+
mode: live.some(({ mode }) => mode === "block") ? "block" : "warn"
|
|
31931
|
+
};
|
|
31932
|
+
}
|
|
31933
|
+
var isFileDigest = (value) => typeof value === "object" && value !== null && typeof value.flag === "string" && typeof value.operand === "string" && typeof value.sha256 === "string";
|
|
31934
|
+
function readMarker(file) {
|
|
31935
|
+
let text;
|
|
31936
|
+
try {
|
|
31937
|
+
const fd = openSync2(file, constants3.O_RDONLY | constants3.O_NOFOLLOW);
|
|
31938
|
+
try {
|
|
31939
|
+
text = readFileSync(fd, "utf-8");
|
|
31940
|
+
} finally {
|
|
31941
|
+
closeSync2(fd);
|
|
31942
|
+
}
|
|
31943
|
+
} catch {
|
|
31944
|
+
return;
|
|
31945
|
+
}
|
|
31946
|
+
try {
|
|
31947
|
+
const data = JSON.parse(text);
|
|
31948
|
+
if (typeof data !== "object" || data === null)
|
|
31949
|
+
return;
|
|
31950
|
+
const { v, argv, args, files, createdAt } = data;
|
|
31951
|
+
if (v !== 2 || typeof argv !== "string" || typeof createdAt !== "number")
|
|
31952
|
+
return;
|
|
31953
|
+
if (args !== null && typeof args !== "string")
|
|
31954
|
+
return;
|
|
31955
|
+
if (!Array.isArray(files) || !files.every(isFileDigest))
|
|
31956
|
+
return;
|
|
31957
|
+
return { argv, args, files, createdAt };
|
|
31958
|
+
} catch {
|
|
31959
|
+
return;
|
|
31960
|
+
}
|
|
31961
|
+
}
|
|
31962
|
+
function consumeMarker(stores, argv, args, files, now) {
|
|
31963
|
+
const key = argvDigest(argv);
|
|
31964
|
+
const reviewed = argsDigest(args);
|
|
31965
|
+
let changed;
|
|
31966
|
+
let mismatched = false;
|
|
31967
|
+
let expired = false;
|
|
31968
|
+
const usable = [];
|
|
31969
|
+
for (const store of stores) {
|
|
31970
|
+
const dir = join5(store, MARKERS);
|
|
31971
|
+
for (const name of readdirSync(dir)) {
|
|
31972
|
+
if (!name.startsWith(`${key}.`))
|
|
31973
|
+
continue;
|
|
31974
|
+
const file = join5(dir, name);
|
|
31975
|
+
const marker = readMarker(file);
|
|
31976
|
+
if (marker === undefined || marker.argv !== key)
|
|
31977
|
+
continue;
|
|
31978
|
+
if (now - marker.createdAt > MARKER_MAX_AGE_MS) {
|
|
31979
|
+
expired = true;
|
|
31980
|
+
rmSync(file, { force: true });
|
|
31981
|
+
continue;
|
|
31982
|
+
}
|
|
31983
|
+
if (marker.args !== null) {
|
|
31984
|
+
const differs = marker.files.find((bound, index) => bound.flag !== files[index]?.flag || bound.operand !== files[index]?.operand || bound.sha256 !== files[index]?.sha256);
|
|
31985
|
+
if (differs !== undefined) {
|
|
31986
|
+
changed ??= { flag: differs.flag, operand: differs.operand };
|
|
31987
|
+
continue;
|
|
31988
|
+
}
|
|
31989
|
+
if (marker.files.length !== files.length || marker.args !== reviewed) {
|
|
31990
|
+
mismatched = true;
|
|
31991
|
+
continue;
|
|
31992
|
+
}
|
|
31993
|
+
}
|
|
31994
|
+
usable.push({ file, bound: marker.args !== null });
|
|
31995
|
+
}
|
|
31996
|
+
}
|
|
31997
|
+
usable.sort((a, b) => Number(b.bound) - Number(a.bound));
|
|
31998
|
+
for (const { file } of usable) {
|
|
31999
|
+
try {
|
|
32000
|
+
unlinkSync(file);
|
|
32001
|
+
return { ok: true };
|
|
32002
|
+
} catch (error) {
|
|
32003
|
+
if (!hasErrnoCode(error, "ENOENT"))
|
|
32004
|
+
throw error;
|
|
32005
|
+
}
|
|
32006
|
+
}
|
|
32007
|
+
if (changed !== undefined)
|
|
32008
|
+
return {
|
|
32009
|
+
ok: false,
|
|
32010
|
+
why: `a file this write posts changed after AskGate read it (\`${changed.flag} ${changed.operand}\`)`,
|
|
32011
|
+
changed
|
|
32012
|
+
};
|
|
32013
|
+
return {
|
|
32014
|
+
ok: false,
|
|
32015
|
+
why: mismatched ? "its arguments differ from the ones AskGate reviewed" : expired ? "its AskGate marker expired before it ran" : "this call carries no AskGate marker"
|
|
32016
|
+
};
|
|
32017
|
+
}
|
|
32018
|
+
|
|
32019
|
+
// ../envoy-client/src/dispatch-session-directory.ts
|
|
32020
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
32021
|
+
import { renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
32022
|
+
import { homedir as homedir2 } from "os";
|
|
32023
|
+
import { join as join6 } from "path";
|
|
32024
|
+
var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
|
|
32025
|
+
var PRIVATE_FILE = 384;
|
|
32026
|
+
var SESSION_VARIABLES = [
|
|
32027
|
+
"ENVOY_SESSION_ID",
|
|
32028
|
+
"CLAUDE_CODE_SESSION_ID",
|
|
32029
|
+
"DISPATCH_SESSION_ID",
|
|
32030
|
+
"CODEX_THREAD_ID"
|
|
32031
|
+
];
|
|
32032
|
+
function sessionStateRoot(env) {
|
|
32033
|
+
const stateDir = env["DISPATCH_STATE_DIR"];
|
|
32034
|
+
if (stateDir)
|
|
32035
|
+
return stateDir;
|
|
32036
|
+
return join6(env["XDG_STATE_HOME"] || join6(homedir2(), ".local", "state"), "dispatch");
|
|
32037
|
+
}
|
|
32038
|
+
function sessionDirectory(env, sessionId) {
|
|
32039
|
+
if (!SESSION_ID_PATH_SEGMENT.test(sessionId) || sessionId === "." || sessionId === "..") {
|
|
32040
|
+
throw new Error(`dispatch: the session id ${JSON.stringify(sessionId)} is not 1-128 letters, digits, ".", "_" or "-"`);
|
|
32041
|
+
}
|
|
32042
|
+
return join6(sessionStateRoot(env), "sessions", sessionId);
|
|
32043
|
+
}
|
|
32044
|
+
function writeAtomically(path, text) {
|
|
32045
|
+
const temporary = `${path}.${process.pid}.${randomUUID3()}.tmp`;
|
|
32046
|
+
try {
|
|
32047
|
+
writeFileSync2(temporary, text, { mode: PRIVATE_FILE });
|
|
32048
|
+
renameSync2(temporary, path);
|
|
32049
|
+
} catch (error) {
|
|
32050
|
+
rmSync2(temporary, { force: true });
|
|
32051
|
+
throw error;
|
|
32052
|
+
}
|
|
32053
|
+
}
|
|
32054
|
+
|
|
32055
|
+
// ../envoy-client/src/dispatch-commands/api.ts
|
|
32056
|
+
var GATED_WHY = "this session's AskGate reviews Dispatch writes, so dispatch api sends only GET here";
|
|
32057
|
+
var NO_ROW = "the dispatch command that makes it (dispatch --help lists them)";
|
|
32058
|
+
var WRITE_ROUTES = [
|
|
32059
|
+
{ method: "POST", pattern: "/api/v1/issues", commands: ["issue"] },
|
|
32060
|
+
{ method: "PATCH", pattern: "/api/v1/issues/{key}", commands: ["issue-update"] },
|
|
32061
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/status-change", commands: ["issue-update"] },
|
|
32062
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/claim", commands: ["claim"] },
|
|
32063
|
+
{ method: "DELETE", pattern: "/api/v1/issues/{key}/claim", commands: ["claim"] },
|
|
32064
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/asks", commands: ["ask"] },
|
|
32065
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/asks", commands: ["ask"] },
|
|
32066
|
+
{ method: "PATCH", pattern: "/api/v1/asks/{id}", commands: ["edit-ask"] },
|
|
32067
|
+
{ method: "POST", pattern: "/api/v1/asks/{id}/resolve", commands: ["resolve-ask"] },
|
|
32068
|
+
{ method: "PUT", pattern: "/api/v1/asks/{id}/followers/{session}", commands: ["follow"] },
|
|
32069
|
+
{ method: "DELETE", pattern: "/api/v1/asks/{id}/followers/{session}", commands: ["follow"] },
|
|
32070
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/comments", commands: ["comment", "suggest"] },
|
|
32071
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/comments", commands: ["comment", "suggest"] },
|
|
32072
|
+
{ method: "POST", pattern: "/api/v1/comments/{id}/resolve", commands: ["resolve-comment"] },
|
|
32073
|
+
{ method: "PATCH", pattern: "/api/v1/comments/{id}", commands: ["edit-comment"] },
|
|
32074
|
+
{ method: "DELETE", pattern: "/api/v1/comments/{id}", commands: ["delete-comment"] },
|
|
32075
|
+
{ method: "PATCH", pattern: "/api/v1/messages/{id}", commands: ["edit-message"] },
|
|
32076
|
+
{ method: "DELETE", pattern: "/api/v1/messages/{id}", commands: ["delete-message"] },
|
|
32077
|
+
{
|
|
32078
|
+
method: "POST",
|
|
32079
|
+
pattern: "/api/v1/issues/{key}/messages",
|
|
32080
|
+
commands: ["message", "issue-update"]
|
|
32081
|
+
},
|
|
32082
|
+
{ method: "POST", pattern: "/api/v1/messages/{id}/reply", commands: ["message"] },
|
|
32083
|
+
{ method: "POST", pattern: "/api/v1/agents/{session}/artifacts", commands: ["message"] },
|
|
32084
|
+
{ method: "POST", pattern: "/api/v1/agents/{session}/messages", commands: ["send-to-agent"] },
|
|
32085
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/edits", commands: ["doc-edit"] },
|
|
32086
|
+
{
|
|
32087
|
+
method: "POST",
|
|
32088
|
+
pattern: "/api/v1/artifacts/{id}/approval-requests",
|
|
32089
|
+
commands: ["request-approval"]
|
|
32090
|
+
},
|
|
32091
|
+
{ method: "POST", pattern: "/api/v1/artifacts/{id}/plan-reviews", commands: ["plan-approve"] },
|
|
32092
|
+
{
|
|
32093
|
+
method: "POST",
|
|
32094
|
+
pattern: "/api/v1/artifacts/{id}/versions/{number}/reviews",
|
|
32095
|
+
commands: ["review"]
|
|
32096
|
+
},
|
|
32097
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/results", commands: ["result"] },
|
|
32098
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/results/dry-run", commands: ["result"] },
|
|
32099
|
+
{ method: "POST", pattern: "/api/v1/results/{id}/retract", commands: ["result"] },
|
|
32100
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/handoffs/{phase}", commands: ["handoff-write"] },
|
|
32101
|
+
{ method: "POST", pattern: "/api/v1/issues/{key}/artifacts", commands: ["artifact"] },
|
|
32102
|
+
{ method: "POST", pattern: "/api/v1/projects/{key}/artifacts", commands: ["artifact"] },
|
|
32103
|
+
{ method: "POST", pattern: "/api/v1/markdown/round-trip", commands: ["artifact"] },
|
|
32104
|
+
{ method: "POST", pattern: "/api/v1/projects", commands: ["project"] },
|
|
32105
|
+
{
|
|
32106
|
+
method: "PUT",
|
|
32107
|
+
pattern: "/api/v1/projects/{key}/proven-sessions",
|
|
32108
|
+
commands: ["project-update"]
|
|
32109
|
+
},
|
|
32110
|
+
{
|
|
32111
|
+
method: "DELETE",
|
|
32112
|
+
pattern: "/api/v1/projects/{key}/proven-sessions",
|
|
32113
|
+
commands: ["project-update"]
|
|
32114
|
+
},
|
|
32115
|
+
{ method: "POST", pattern: "/api/v1/projects/{key}/related", commands: ["related"] },
|
|
32116
|
+
{
|
|
32117
|
+
method: "POST",
|
|
32118
|
+
pattern: "/api/v1/projects/{key}/architecture-sources/sync",
|
|
32119
|
+
commands: ["architecture-sync"]
|
|
32120
|
+
},
|
|
32121
|
+
{
|
|
32122
|
+
method: "POST",
|
|
32123
|
+
pattern: "/api/v1/projects/{key}/architecture-source/sync",
|
|
32124
|
+
commands: ["architecture-sync"]
|
|
32125
|
+
},
|
|
32126
|
+
{
|
|
32127
|
+
method: "POST",
|
|
32128
|
+
pattern: "/api/v1/projects/{key}/architecture-sources/{owner}/{repo}/sync",
|
|
32129
|
+
commands: ["architecture-sync"]
|
|
32130
|
+
}
|
|
32131
|
+
];
|
|
32132
|
+
function writeRoute(method, path) {
|
|
32133
|
+
const segments = path.split("/");
|
|
32134
|
+
return WRITE_ROUTES.find((row) => {
|
|
32135
|
+
const pattern = row.pattern.split("/");
|
|
32136
|
+
return row.method === method && pattern.length === segments.length && pattern.every((part, at) => part.startsWith("{") ? segments[at] !== "" : part === segments[at]);
|
|
32137
|
+
});
|
|
32138
|
+
}
|
|
32139
|
+
|
|
32140
|
+
class ApiGateRefusal extends Error {
|
|
32141
|
+
askgate;
|
|
32142
|
+
name = "ApiGateRefusal";
|
|
32143
|
+
constructor(message, askgate) {
|
|
32144
|
+
super(message);
|
|
32145
|
+
this.askgate = askgate;
|
|
32146
|
+
}
|
|
32147
|
+
}
|
|
32148
|
+
function gatedWriteRefusal(method, path, env) {
|
|
32149
|
+
const gates = [];
|
|
32150
|
+
for (const variable of SESSION_VARIABLES) {
|
|
32151
|
+
const id = env[variable];
|
|
32152
|
+
if (id === undefined || id === "")
|
|
32153
|
+
continue;
|
|
32154
|
+
let dir;
|
|
32155
|
+
try {
|
|
32156
|
+
dir = sessionDirectory(env, id);
|
|
32157
|
+
} catch {
|
|
32158
|
+
return new ToolInputError("dispatch_api", [
|
|
32159
|
+
`${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.`
|
|
32160
|
+
], { aboutAFlag: false });
|
|
32161
|
+
}
|
|
32162
|
+
gates.push(askgateState(dir));
|
|
32163
|
+
}
|
|
32164
|
+
const broken = gates.find((gate) => gate.kind === "broken");
|
|
32165
|
+
const gated = gates.some((gate) => gate.kind === "on");
|
|
32166
|
+
if (!gated && broken === undefined)
|
|
32167
|
+
return;
|
|
32168
|
+
const row = writeRoute(method, path.split("?", 1)[0] ?? "");
|
|
32169
|
+
const command = row === undefined ? NO_ROW : row.commands.map((name) => `dispatch ${name}`).join(" or ");
|
|
32170
|
+
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 });
|
|
32171
|
+
}
|
|
32172
|
+
async function sendApiCall(args, env, client) {
|
|
32173
|
+
const path = stringArg(args, "path");
|
|
32174
|
+
const method = optionalString(args, "method");
|
|
32175
|
+
if (method !== undefined) {
|
|
32176
|
+
const refusal = gatedWriteRefusal(method, path, env);
|
|
32177
|
+
if (refusal !== undefined)
|
|
32178
|
+
throw refusal;
|
|
32179
|
+
}
|
|
32180
|
+
const answer = method === undefined ? await client.readRoute(path) : await client.sendRoute(method, path, optionalString(args, "body"));
|
|
32181
|
+
const details = { path, ...defined("method", method) };
|
|
32182
|
+
if ("body" in answer) {
|
|
32183
|
+
const { body, type } = answer;
|
|
32184
|
+
return {
|
|
32185
|
+
text: `the answer's body as it came: ${body.byteLength} bytes (${type ?? "no Content-Type"})`,
|
|
32186
|
+
body,
|
|
32187
|
+
details: { ...details, ...defined("content_type", type), bytes: body.byteLength }
|
|
32188
|
+
};
|
|
32189
|
+
}
|
|
32190
|
+
return { text: JSON.stringify(answer.payload, null, 2), details };
|
|
32191
|
+
}
|
|
32192
|
+
async function apiCommand(context) {
|
|
32193
|
+
return await sendApiCall(context.args, context.input.env ?? {}, context.newClient());
|
|
32194
|
+
}
|
|
31577
32195
|
|
|
31578
32196
|
// ../envoy-client/src/dispatch-commands/render-item.ts
|
|
31579
32197
|
function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
|
|
@@ -33838,38 +34456,8 @@ async function reviewCommand(context) {
|
|
|
33838
34456
|
}
|
|
33839
34457
|
|
|
33840
34458
|
// ../envoy-client/src/session-answers.ts
|
|
33841
|
-
import { mkdirSync, readFileSync } from "fs";
|
|
33842
|
-
import { join as
|
|
33843
|
-
|
|
33844
|
-
// ../envoy-client/src/dispatch-session-directory.ts
|
|
33845
|
-
import { randomUUID as randomUUID3 } from "crypto";
|
|
33846
|
-
import { renameSync, rmSync, writeFileSync } from "fs";
|
|
33847
|
-
import { homedir as homedir2 } from "os";
|
|
33848
|
-
import { join as join5 } from "path";
|
|
33849
|
-
var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
|
|
33850
|
-
var PRIVATE_FILE = 384;
|
|
33851
|
-
function sessionStateRoot(env) {
|
|
33852
|
-
const stateDir = env["DISPATCH_STATE_DIR"];
|
|
33853
|
-
if (stateDir)
|
|
33854
|
-
return stateDir;
|
|
33855
|
-
return join5(env["XDG_STATE_HOME"] || join5(homedir2(), ".local", "state"), "dispatch");
|
|
33856
|
-
}
|
|
33857
|
-
function sessionDirectory(env, sessionId) {
|
|
33858
|
-
if (!SESSION_ID_PATH_SEGMENT.test(sessionId) || sessionId === "." || sessionId === "..") {
|
|
33859
|
-
throw new Error(`dispatch: the session id ${JSON.stringify(sessionId)} is not 1-128 letters, digits, ".", "_" or "-"`);
|
|
33860
|
-
}
|
|
33861
|
-
return join5(sessionStateRoot(env), "sessions", sessionId);
|
|
33862
|
-
}
|
|
33863
|
-
function writeAtomically(path, text) {
|
|
33864
|
-
const temporary = `${path}.${process.pid}.${randomUUID3()}.tmp`;
|
|
33865
|
-
try {
|
|
33866
|
-
writeFileSync(temporary, text, { mode: PRIVATE_FILE });
|
|
33867
|
-
renameSync(temporary, path);
|
|
33868
|
-
} catch (error) {
|
|
33869
|
-
rmSync(temporary, { force: true });
|
|
33870
|
-
throw error;
|
|
33871
|
-
}
|
|
33872
|
-
}
|
|
34459
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync2 } from "fs";
|
|
34460
|
+
import { join as join7 } from "path";
|
|
33873
34461
|
|
|
33874
34462
|
// ../envoy-client/src/json-line-record.ts
|
|
33875
34463
|
import { appendFileSync } from "fs";
|
|
@@ -34009,7 +34597,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
34009
34597
|
var CACHE_FILE = "answers.json";
|
|
34010
34598
|
function readCacheFile(directory, url) {
|
|
34011
34599
|
try {
|
|
34012
|
-
const value = JSON.parse(
|
|
34600
|
+
const value = JSON.parse(readFileSync2(join7(directory, CACHE_FILE), "utf-8"));
|
|
34013
34601
|
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)) {
|
|
34014
34602
|
return {
|
|
34015
34603
|
dispatch_url: value.dispatch_url,
|
|
@@ -34129,8 +34717,8 @@ async function readSessionAnswers(options) {
|
|
|
34129
34717
|
current.noRouteReported = false;
|
|
34130
34718
|
if (directory !== undefined) {
|
|
34131
34719
|
try {
|
|
34132
|
-
|
|
34133
|
-
writeAtomically(
|
|
34720
|
+
mkdirSync2(directory, { recursive: true, mode: 448 });
|
|
34721
|
+
writeAtomically(join7(directory, CACHE_FILE), JSON.stringify(cache));
|
|
34134
34722
|
} catch {}
|
|
34135
34723
|
}
|
|
34136
34724
|
return { cache };
|
|
@@ -34210,12 +34798,15 @@ async function whoamiCommand(context) {
|
|
|
34210
34798
|
const service = identity.kind === "agent" ? identity.service ?? null : null;
|
|
34211
34799
|
const proved = identity.kind === "agent" ? identity.session ?? null : null;
|
|
34212
34800
|
const project = identity.kind === "agent" ? identity.project ?? null : null;
|
|
34801
|
+
const projectScope = identity.kind === "agent" ? identity.project_scope ?? null : null;
|
|
34213
34802
|
const readOnly = identity.scopes?.includes("read") === true;
|
|
34214
34803
|
const cut = identity.kind === "agent" ? identity.cut ?? null : null;
|
|
34215
34804
|
const session = proved ?? sessionId;
|
|
34216
34805
|
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.";
|
|
34806
|
+
const brokerService = owner === null && service !== null && proved !== null;
|
|
34217
34807
|
const answered = identity.kind === "agent" ? identity.sign_in_required : undefined;
|
|
34218
|
-
const signInNeeded = answered ??
|
|
34808
|
+
const signInNeeded = answered ?? brokerService;
|
|
34809
|
+
const writesAsService = brokerService && !signInNeeded;
|
|
34219
34810
|
const who = owner !== null ? `acts for ${owner}` : service !== null ? `runs as service ${serviceSubjectLabel(service)}` : "runs";
|
|
34220
34811
|
const named = proved !== null && proved !== sessionId ? ` Your credential names session ${proved}, which is not this host session (${sessionId})` : "";
|
|
34221
34812
|
let acting;
|
|
@@ -34227,15 +34818,17 @@ async function whoamiCommand(context) {
|
|
|
34227
34818
|
acting = `Session ${session} ${who}: issues you create without an assignee are assigned to ${owner}.`;
|
|
34228
34819
|
} else if (signInNeeded) {
|
|
34229
34820
|
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.`;
|
|
34821
|
+
} else if (writesAsService) {
|
|
34822
|
+
acting = `Session ${session} ${who} and no person, and writes as that service with ${unowned}`;
|
|
34230
34823
|
} else if (service !== null) {
|
|
34231
34824
|
acting = `Session ${session} ${who}: ${unowned}`;
|
|
34232
34825
|
} else {
|
|
34233
34826
|
acting = `Session ${session} runs under the shared token: ${unowned}`;
|
|
34234
34827
|
}
|
|
34235
|
-
const writable = project !== null
|
|
34828
|
+
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." : "";
|
|
34236
34829
|
return {
|
|
34237
34830
|
text: acting + elsewhere + writable,
|
|
34238
|
-
details: { session, owner, service, project }
|
|
34831
|
+
details: { session, owner, service, project, project_scope: projectScope }
|
|
34239
34832
|
};
|
|
34240
34833
|
}
|
|
34241
34834
|
async function limitsCommand(context) {
|
|
@@ -34510,16 +35103,16 @@ async function executeDispatchTool(input) {
|
|
|
34510
35103
|
}
|
|
34511
35104
|
|
|
34512
35105
|
// ../envoy-client/src/dispatch-first.ts
|
|
34513
|
-
import { readFileSync as
|
|
34514
|
-
import { join as
|
|
35106
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
35107
|
+
import { join as join8 } from "path";
|
|
34515
35108
|
var DISPATCH_FIRST_MARKER = "<dispatch-first-skill>";
|
|
34516
35109
|
function dispatchFirstSkillFile(skillsDirectory) {
|
|
34517
|
-
return
|
|
35110
|
+
return join8(skillsDirectory, "dispatch-first", "SKILL.md");
|
|
34518
35111
|
}
|
|
34519
35112
|
function readDispatchFirstContext(skillFile) {
|
|
34520
35113
|
let skill;
|
|
34521
35114
|
try {
|
|
34522
|
-
skill =
|
|
35115
|
+
skill = readFileSync3(skillFile, "utf8");
|
|
34523
35116
|
} catch (error) {
|
|
34524
35117
|
throw new Error(`the dispatch-first skill ${skillFile} could not be read: ${messageFor(error)}`);
|
|
34525
35118
|
}
|
|
@@ -34536,7 +35129,7 @@ function readDispatchFirstContext(skillFile) {
|
|
|
34536
35129
|
|
|
34537
35130
|
// ../cipher-client/src/environment.ts
|
|
34538
35131
|
import { readFile as readFile6 } from "fs/promises";
|
|
34539
|
-
import { join as
|
|
35132
|
+
import { join as join9 } from "path";
|
|
34540
35133
|
|
|
34541
35134
|
// ../cipher-client/src/device-login.ts
|
|
34542
35135
|
import { generateKeyPairSync as generateKeyPairSync2, randomUUID as randomUUID5 } from "crypto";
|
|
@@ -34895,7 +35488,7 @@ function unpollableAnswer(answered, intervalSeconds, lifetimeSeconds, left) {
|
|
|
34895
35488
|
|
|
34896
35489
|
// ../cipher-client/src/dpop.ts
|
|
34897
35490
|
import {
|
|
34898
|
-
createHash,
|
|
35491
|
+
createHash as createHash2,
|
|
34899
35492
|
createPrivateKey as createPrivateKey2,
|
|
34900
35493
|
createPublicKey,
|
|
34901
35494
|
generateKeyPairSync,
|
|
@@ -34923,7 +35516,7 @@ function dpopKey(privateKey, publicJwk) {
|
|
|
34923
35516
|
if (nonce !== undefined && nonce !== "")
|
|
34924
35517
|
claims["nonce"] = nonce;
|
|
34925
35518
|
if (accessToken !== undefined && accessToken !== "") {
|
|
34926
|
-
claims["ath"] =
|
|
35519
|
+
claims["ath"] = createHash2("sha256").update(accessToken).digest("base64url");
|
|
34927
35520
|
}
|
|
34928
35521
|
const signingInput = `${header}.${Buffer.from(JSON.stringify(claims)).toString("base64url")}`;
|
|
34929
35522
|
const signature = sign2("sha256", Buffer.from(signingInput), {
|
|
@@ -34970,6 +35563,9 @@ async function importDpopKey(pkcs8Pem, name) {
|
|
|
34970
35563
|
return dpopKey(privateKey, publicJwkOf(privateKey, name));
|
|
34971
35564
|
}
|
|
34972
35565
|
|
|
35566
|
+
// ../cipher-client/src/loopback.ts
|
|
35567
|
+
var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
|
|
35568
|
+
|
|
34973
35569
|
// ../cipher-client/src/device-login.ts
|
|
34974
35570
|
var BROKER_SETTING = "AGENT_SECRETS_URL";
|
|
34975
35571
|
var ACCESS_MARGIN_MS = 2 * TRADE_ATTEMPT_MS;
|
|
@@ -34979,7 +35575,6 @@ function leastAccessLifeMs(leastLifeMs, lifeSeconds) {
|
|
|
34979
35575
|
return Math.max(ACCESS_MARGIN_MS, Math.min(leastLifeMs, lifeSeconds * 1000 / 2));
|
|
34980
35576
|
}
|
|
34981
35577
|
var BROKER_REQUEST_MS = TRADE_ATTEMPT_MS / 2;
|
|
34982
|
-
var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
|
|
34983
35578
|
var UNPRINTABLE = /[\p{Cc}\p{Cf}]/u;
|
|
34984
35579
|
function deviceLoginSessionName(thumbprint) {
|
|
34985
35580
|
return `device-login-${thumbprint.slice(0, 12)}`;
|
|
@@ -35285,13 +35880,107 @@ async function refreshDeviceLogin(path, login, options) {
|
|
|
35285
35880
|
return next;
|
|
35286
35881
|
}
|
|
35287
35882
|
|
|
35883
|
+
// ../cipher-client/src/answer-text.ts
|
|
35884
|
+
var MAX_ANSWER_BYTES = 1 << 20;
|
|
35885
|
+
async function answerText(answer) {
|
|
35886
|
+
const reader = answer.body?.getReader();
|
|
35887
|
+
if (reader === undefined)
|
|
35888
|
+
return "";
|
|
35889
|
+
const chunks = [];
|
|
35890
|
+
let read = 0;
|
|
35891
|
+
while (read < MAX_ANSWER_BYTES) {
|
|
35892
|
+
const { done, value } = await reader.read();
|
|
35893
|
+
if (done)
|
|
35894
|
+
break;
|
|
35895
|
+
const kept = value.subarray(0, MAX_ANSWER_BYTES - read);
|
|
35896
|
+
chunks.push(kept);
|
|
35897
|
+
read += kept.length;
|
|
35898
|
+
}
|
|
35899
|
+
await reader.cancel().catch(() => {
|
|
35900
|
+
return;
|
|
35901
|
+
});
|
|
35902
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
35903
|
+
}
|
|
35904
|
+
|
|
35905
|
+
// ../cipher-client/src/machine-audience.ts
|
|
35906
|
+
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
35907
|
+
|
|
35908
|
+
// ../cipher-client/src/github-actions-identity.ts
|
|
35909
|
+
var ACTIONS_ID_TOKEN_REQUEST_URL_VAR = "ACTIONS_ID_TOKEN_REQUEST_URL";
|
|
35910
|
+
var ACTIONS_ID_TOKEN_REQUEST_TOKEN_VAR = "ACTIONS_ID_TOKEN_REQUEST_TOKEN";
|
|
35911
|
+
var TIMEOUT_MS = 20000;
|
|
35912
|
+
var ASKING = `ask GitHub for this run's OIDC token at the URL ${ACTIONS_ID_TOKEN_REQUEST_URL_VAR} names`;
|
|
35913
|
+
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`;
|
|
35914
|
+
function requestEndpoint(requestUrl, audience) {
|
|
35915
|
+
let endpoint;
|
|
35916
|
+
try {
|
|
35917
|
+
endpoint = new URL(requestUrl);
|
|
35918
|
+
} catch {
|
|
35919
|
+
throw new Error(NOT_HTTPS);
|
|
35920
|
+
}
|
|
35921
|
+
const loopback = endpoint.protocol === "http:" && LOOPBACK_HOST.test(endpoint.hostname);
|
|
35922
|
+
if (endpoint.protocol !== "https:" && !loopback)
|
|
35923
|
+
throw new Error(NOT_HTTPS);
|
|
35924
|
+
endpoint.searchParams.set("audience", audience);
|
|
35925
|
+
return endpoint.href;
|
|
35926
|
+
}
|
|
35927
|
+
function githubActionsIdentity(options) {
|
|
35928
|
+
holdSecret(options.requestToken);
|
|
35929
|
+
holdUrlUserinfo(options.requestUrl);
|
|
35930
|
+
const send = options.fetch ?? fetch;
|
|
35931
|
+
return {
|
|
35932
|
+
async read(signal) {
|
|
35933
|
+
const endpoint = requestEndpoint(options.requestUrl, options.audience);
|
|
35934
|
+
const signals = [AbortSignal.timeout(TIMEOUT_MS), signal].filter((one) => one !== undefined);
|
|
35935
|
+
let answer;
|
|
35936
|
+
try {
|
|
35937
|
+
answer = await send(endpoint, {
|
|
35938
|
+
method: "GET",
|
|
35939
|
+
headers: { Authorization: `bearer ${options.requestToken}` },
|
|
35940
|
+
signal: AbortSignal.any(signals),
|
|
35941
|
+
redirect: "manual"
|
|
35942
|
+
});
|
|
35943
|
+
} catch (error) {
|
|
35944
|
+
throw new Error(`${ASKING}: no answer: ${errorClass(error)}`);
|
|
35945
|
+
}
|
|
35946
|
+
if (answer.status < 200 || answer.status > 299) {
|
|
35947
|
+
await answer.body?.cancel().catch(() => {
|
|
35948
|
+
return;
|
|
35949
|
+
});
|
|
35950
|
+
throw new Error(`${ASKING}: HTTP ${answer.status}`);
|
|
35951
|
+
}
|
|
35952
|
+
let text;
|
|
35953
|
+
try {
|
|
35954
|
+
text = await answerText(answer);
|
|
35955
|
+
} catch (error) {
|
|
35956
|
+
throw new Error(`${ASKING}: no answer: ${errorClass(error)}`);
|
|
35957
|
+
}
|
|
35958
|
+
let parsed;
|
|
35959
|
+
try {
|
|
35960
|
+
parsed = JSON.parse(text);
|
|
35961
|
+
} catch {
|
|
35962
|
+
throw new Error(`${ASKING}: HTTP ${answer.status}: the answer is not JSON`);
|
|
35963
|
+
}
|
|
35964
|
+
const value = typeof parsed === "object" && parsed !== null && "value" in parsed ? parsed.value : undefined;
|
|
35965
|
+
if (typeof value !== "string" || value === "") {
|
|
35966
|
+
throw new Error(`${ASKING}: the answer holds no value`);
|
|
35967
|
+
}
|
|
35968
|
+
return { token: value, tokenType: SUBJECT_TOKEN_TYPE_GITHUB };
|
|
35969
|
+
},
|
|
35970
|
+
describe: () => {
|
|
35971
|
+
const audience = isCleanUrl(options.audience) ? `${options.audience} (${MACHINE_AUDIENCE_VAR})` : `the audience ${MACHINE_AUDIENCE_VAR} names`;
|
|
35972
|
+
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`;
|
|
35973
|
+
}
|
|
35974
|
+
};
|
|
35975
|
+
}
|
|
35976
|
+
|
|
35288
35977
|
// ../cipher-client/src/metadata-identity.ts
|
|
35289
35978
|
import { Agent, request } from "http";
|
|
35290
35979
|
var METADATA_HOST_VAR = "GCE_METADATA_HOST";
|
|
35291
35980
|
var DEFAULT_METADATA_HOST = "metadata.google.internal";
|
|
35292
35981
|
var IDENTITY_PATH = "/computeMetadata/v1/instance/service-accounts/default/identity";
|
|
35293
|
-
var
|
|
35294
|
-
var
|
|
35982
|
+
var TIMEOUT_MS2 = 1e4;
|
|
35983
|
+
var MAX_ANSWER_BYTES2 = 1 << 20;
|
|
35295
35984
|
var agent = new Agent({ keepAlive: false });
|
|
35296
35985
|
function tokenUrl(audience, env) {
|
|
35297
35986
|
const host = (env[METADATA_HOST_VAR] ?? "").trim() || DEFAULT_METADATA_HOST;
|
|
@@ -35306,7 +35995,7 @@ function get(url, signal, lookup) {
|
|
|
35306
35995
|
agent,
|
|
35307
35996
|
method: "GET",
|
|
35308
35997
|
headers: { "Metadata-Flavor": "Google" },
|
|
35309
|
-
timeout:
|
|
35998
|
+
timeout: TIMEOUT_MS2,
|
|
35310
35999
|
...signal === undefined ? {} : { signal },
|
|
35311
36000
|
...lookup === undefined ? {} : { lookup }
|
|
35312
36001
|
}, (answer) => {
|
|
@@ -35314,13 +36003,13 @@ function get(url, signal, lookup) {
|
|
|
35314
36003
|
let read = 0;
|
|
35315
36004
|
answer.on("data", (chunk) => {
|
|
35316
36005
|
read += chunk.length;
|
|
35317
|
-
if (read <=
|
|
36006
|
+
if (read <= MAX_ANSWER_BYTES2)
|
|
35318
36007
|
chunks.push(chunk);
|
|
35319
36008
|
});
|
|
35320
36009
|
answer.on("end", () => resolve({ status: answer.statusCode ?? 0, body: Buffer.concat(chunks).toString("utf8") }));
|
|
35321
36010
|
answer.on("error", reject);
|
|
35322
36011
|
});
|
|
35323
|
-
call.on("timeout", () => call.destroy(Object.assign(new Error(`no answer within ${
|
|
36012
|
+
call.on("timeout", () => call.destroy(Object.assign(new Error(`no answer within ${TIMEOUT_MS2} ms`), { code: "ETIMEDOUT" })));
|
|
35324
36013
|
call.on("error", reject);
|
|
35325
36014
|
call.end();
|
|
35326
36015
|
return promise;
|
|
@@ -35433,7 +36122,6 @@ var REQUESTED_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:access_token";
|
|
|
35433
36122
|
var SCOPE = "https://www.googleapis.com/auth/cloud-platform";
|
|
35434
36123
|
var SUBJECT_TOKEN_TYPE_JWT = "urn:ietf:params:oauth:token-type:jwt";
|
|
35435
36124
|
var POOL_TIMEOUT_MS = 20000;
|
|
35436
|
-
var MAX_ANSWER_BYTES2 = 1 << 20;
|
|
35437
36125
|
var STS_SETTING = "securityTokenServiceUrl";
|
|
35438
36126
|
var IAM_SETTING = "iamCredentialsUrl";
|
|
35439
36127
|
function poolSubjectTokenType(brokerType) {
|
|
@@ -35442,25 +36130,6 @@ function poolSubjectTokenType(brokerType) {
|
|
|
35442
36130
|
function pathEscape(segment) {
|
|
35443
36131
|
return encodeURIComponent(segment).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(?:24|26|2B|3A|3D|40)/g, decodeURIComponent);
|
|
35444
36132
|
}
|
|
35445
|
-
async function answerText(answer) {
|
|
35446
|
-
const reader = answer.body?.getReader();
|
|
35447
|
-
if (reader === undefined)
|
|
35448
|
-
return "";
|
|
35449
|
-
const chunks = [];
|
|
35450
|
-
let read = 0;
|
|
35451
|
-
while (read < MAX_ANSWER_BYTES2) {
|
|
35452
|
-
const { done, value } = await reader.read();
|
|
35453
|
-
if (done)
|
|
35454
|
-
break;
|
|
35455
|
-
const kept = value.subarray(0, MAX_ANSWER_BYTES2 - read);
|
|
35456
|
-
chunks.push(kept);
|
|
35457
|
-
read += kept.length;
|
|
35458
|
-
}
|
|
35459
|
-
await reader.cancel().catch(() => {
|
|
35460
|
-
return;
|
|
35461
|
-
});
|
|
35462
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
35463
|
-
}
|
|
35464
36133
|
var GOOGLE_ERROR_CODE = /^[A-Za-z_]{1,64}$/;
|
|
35465
36134
|
function googleErrorCode(text) {
|
|
35466
36135
|
let parsed;
|
|
@@ -35589,7 +36258,6 @@ function projectedToken(path, variable) {
|
|
|
35589
36258
|
var BROKER_URL_VAR = "AGENT_SECRETS_URL";
|
|
35590
36259
|
var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
|
|
35591
36260
|
var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
|
|
35592
|
-
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
35593
36261
|
var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
|
|
35594
36262
|
var ROLE_KEY_FILE = "key.pem";
|
|
35595
36263
|
var SESSION_VAR = "AGENT_SECRETS_SESSION";
|
|
@@ -35600,6 +36268,7 @@ var POOL_ACCOUNT_VAR = "AGENT_SECRETS_POOL_ACCOUNT";
|
|
|
35600
36268
|
var IDENTITY_KUBERNETES = "kubernetes";
|
|
35601
36269
|
var IDENTITY_METADATA = "metadata";
|
|
35602
36270
|
var IDENTITY_POOL = "pool";
|
|
36271
|
+
var IDENTITY_GITHUB_ACTIONS = "github-actions";
|
|
35603
36272
|
var IDENTITY_DEVICE_LOGIN = "device-login";
|
|
35604
36273
|
var BROKER_VARIABLES = [
|
|
35605
36274
|
BROKER_URL_VAR,
|
|
@@ -35611,6 +36280,8 @@ var BROKER_VARIABLES = [
|
|
|
35611
36280
|
PROJECTS_VAR,
|
|
35612
36281
|
POOL_AUDIENCE_VAR,
|
|
35613
36282
|
POOL_ACCOUNT_VAR,
|
|
36283
|
+
ACTIONS_ID_TOKEN_REQUEST_URL_VAR,
|
|
36284
|
+
ACTIONS_ID_TOKEN_REQUEST_TOKEN_VAR,
|
|
35614
36285
|
DEVICE_LOGIN_FILE_VAR,
|
|
35615
36286
|
SIGNIN_DIR_VAR,
|
|
35616
36287
|
"XDG_STATE_HOME",
|
|
@@ -35651,12 +36322,18 @@ function machineIdentity(env) {
|
|
|
35651
36322
|
tokenAudience
|
|
35652
36323
|
});
|
|
35653
36324
|
}
|
|
36325
|
+
case IDENTITY_GITHUB_ACTIONS: {
|
|
36326
|
+
const requestUrl = required2(env, ACTIONS_ID_TOKEN_REQUEST_URL_VAR, kind);
|
|
36327
|
+
const requestToken = required2(env, ACTIONS_ID_TOKEN_REQUEST_TOKEN_VAR, kind);
|
|
36328
|
+
const audience = required2(env, MACHINE_AUDIENCE_VAR, kind);
|
|
36329
|
+
return githubActionsIdentity({ requestUrl, requestToken, audience });
|
|
36330
|
+
}
|
|
35654
36331
|
case IDENTITY_DEVICE_LOGIN: {
|
|
35655
36332
|
const brokerUrl = required2(env, BROKER_URL_VAR, kind);
|
|
35656
36333
|
return new DeviceLoginIdentity({ path: deviceLoginFile(env), brokerUrl });
|
|
35657
36334
|
}
|
|
35658
36335
|
default:
|
|
35659
|
-
throw new Error(`${IDENTITY_VAR} names no identity this machine can prove; it takes ${IDENTITY_KUBERNETES}, ${IDENTITY_METADATA}, ${IDENTITY_POOL} or ${IDENTITY_DEVICE_LOGIN}`);
|
|
36336
|
+
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}`);
|
|
35660
36337
|
}
|
|
35661
36338
|
}
|
|
35662
36339
|
function tradeSession(env, own = "") {
|
|
@@ -35685,7 +36362,7 @@ async function machineKey(env) {
|
|
|
35685
36362
|
const dir = value(env, KEY_DIR_VAR);
|
|
35686
36363
|
if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
|
|
35687
36364
|
return await newDpopKey();
|
|
35688
|
-
const path =
|
|
36365
|
+
const path = join9(dir, ROLE_KEY_FILE);
|
|
35689
36366
|
let pem;
|
|
35690
36367
|
try {
|
|
35691
36368
|
pem = await readFile6(path, "utf8");
|
|
@@ -35905,14 +36582,14 @@ function brokerCredential(env, session, read) {
|
|
|
35905
36582
|
}
|
|
35906
36583
|
|
|
35907
36584
|
// ../envoy-client/src/file-token-credential.ts
|
|
35908
|
-
import { readFileSync as
|
|
36585
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
35909
36586
|
var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
|
|
35910
36587
|
var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
|
|
35911
36588
|
var PKCS8_LABEL = "PRIVATE KEY";
|
|
35912
36589
|
var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
|
|
35913
36590
|
function readNamed(variable, filePath) {
|
|
35914
36591
|
try {
|
|
35915
|
-
return
|
|
36592
|
+
return readFileSync4(filePath, "utf8");
|
|
35916
36593
|
} catch (error) {
|
|
35917
36594
|
throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
|
|
35918
36595
|
}
|
|
@@ -37083,19 +37760,19 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
37083
37760
|
|
|
37084
37761
|
// src/codex/codex-session-record.ts
|
|
37085
37762
|
import { spawnSync } from "child_process";
|
|
37086
|
-
import { readFileSync as
|
|
37763
|
+
import { readFileSync as readFileSync6, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
|
|
37087
37764
|
import { mkdir as mkdir4, readFile as readFile8, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
37088
37765
|
import { homedir as homedir3 } from "os";
|
|
37089
|
-
import { basename as basename4, dirname as dirname5, join as
|
|
37766
|
+
import { basename as basename4, dirname as dirname5, join as join12 } from "path";
|
|
37090
37767
|
|
|
37091
37768
|
// src/session-identity.ts
|
|
37092
37769
|
import { readFile as readFile7 } from "fs/promises";
|
|
37093
|
-
import { basename as basename3, join as
|
|
37770
|
+
import { basename as basename3, join as join11 } from "path";
|
|
37094
37771
|
|
|
37095
37772
|
// src/session-state.ts
|
|
37096
|
-
import { readFileSync as
|
|
37773
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
37097
37774
|
import { mkdir as mkdir3, readdir as readdir3, rename as rename4, rm as rm4, stat as stat4, utimes as utimes2, writeFile as writeFile2 } from "fs/promises";
|
|
37098
|
-
import { dirname as dirname4, join as
|
|
37775
|
+
import { dirname as dirname4, join as join10 } from "path";
|
|
37099
37776
|
async function writeAtomicStateFile(file, contents) {
|
|
37100
37777
|
await mkdir3(dirname4(file), { recursive: true, mode: 448 });
|
|
37101
37778
|
const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
@@ -37113,7 +37790,7 @@ async function pruneStateDirectory(directory, isStale) {
|
|
|
37113
37790
|
throw error;
|
|
37114
37791
|
});
|
|
37115
37792
|
for (const entry of entries) {
|
|
37116
|
-
const file =
|
|
37793
|
+
const file = join10(directory, entry);
|
|
37117
37794
|
if (!await isStale(file))
|
|
37118
37795
|
continue;
|
|
37119
37796
|
await rm4(file, { recursive: true, force: true });
|
|
@@ -37128,7 +37805,7 @@ async function writtenLongAgo(file) {
|
|
|
37128
37805
|
}
|
|
37129
37806
|
var TITLES_DIRECTORY = "titles";
|
|
37130
37807
|
function sessionTitleFile(stateDirectory, sessionId) {
|
|
37131
|
-
return
|
|
37808
|
+
return join10(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
|
|
37132
37809
|
}
|
|
37133
37810
|
async function writeChosenTitle(file, title) {
|
|
37134
37811
|
await writeAtomicStateFile(file, `${title}
|
|
@@ -37139,7 +37816,7 @@ async function removeChosenTitle(file) {
|
|
|
37139
37816
|
}
|
|
37140
37817
|
function readChosenTitleSync(file) {
|
|
37141
37818
|
try {
|
|
37142
|
-
return
|
|
37819
|
+
return readFileSync5(file, "utf8");
|
|
37143
37820
|
} catch {
|
|
37144
37821
|
return;
|
|
37145
37822
|
}
|
|
@@ -37156,7 +37833,7 @@ async function recordChosenTitle(sessionId, title) {
|
|
|
37156
37833
|
await writeChosenTitle(file, chosen);
|
|
37157
37834
|
}
|
|
37158
37835
|
async function pruneStaleSessionTitles(stateDirectory) {
|
|
37159
|
-
await pruneStateDirectory(
|
|
37836
|
+
await pruneStateDirectory(join10(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
|
|
37160
37837
|
}
|
|
37161
37838
|
|
|
37162
37839
|
// src/session-identity.ts
|
|
@@ -37181,14 +37858,14 @@ class SessionIdentity {
|
|
|
37181
37858
|
}
|
|
37182
37859
|
}
|
|
37183
37860
|
function sessionHandoffDirectory(stateDirectory, claudePid) {
|
|
37184
|
-
return
|
|
37861
|
+
return join11(stateDirectory, "sessions", String(claudePid));
|
|
37185
37862
|
}
|
|
37186
37863
|
function sessionHandoffFile(stateDirectory, claudePid) {
|
|
37187
|
-
return
|
|
37864
|
+
return join11(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
|
|
37188
37865
|
}
|
|
37189
37866
|
var ROLES_DIRECTORY = "roles";
|
|
37190
37867
|
function roleStateFile(stateDirectory, sessionId) {
|
|
37191
|
-
return
|
|
37868
|
+
return join11(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
|
|
37192
37869
|
}
|
|
37193
37870
|
|
|
37194
37871
|
class UnparseableRoleRecordError extends Error {
|
|
@@ -37239,14 +37916,14 @@ function processExists(pid) {
|
|
|
37239
37916
|
}
|
|
37240
37917
|
}
|
|
37241
37918
|
async function pruneStaleSessionHandoffs(stateDirectory) {
|
|
37242
|
-
await pruneStateDirectory(
|
|
37919
|
+
await pruneStateDirectory(join11(stateDirectory, "sessions"), (file) => {
|
|
37243
37920
|
const pid = basename3(file);
|
|
37244
37921
|
return /^\d+$/.test(pid) && !processExists(Number(pid));
|
|
37245
37922
|
});
|
|
37246
37923
|
}
|
|
37247
37924
|
async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
|
|
37248
37925
|
const own = roleStateFile(stateDirectory, currentSessionId);
|
|
37249
|
-
await pruneStateDirectory(
|
|
37926
|
+
await pruneStateDirectory(join11(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
|
|
37250
37927
|
}
|
|
37251
37928
|
|
|
37252
37929
|
// src/codex/codex-session-record.ts
|
|
@@ -37260,10 +37937,10 @@ var CodexSessionRecord = object({
|
|
|
37260
37937
|
codex_started: string2().nullable().default(null)
|
|
37261
37938
|
});
|
|
37262
37939
|
function codexSessionRecordFile(stateDirectory, pid) {
|
|
37263
|
-
return
|
|
37940
|
+
return join12(stateDirectory, "codex-sessions", `${pid}.json`);
|
|
37264
37941
|
}
|
|
37265
37942
|
function codexEndedFile(stateDirectory, pid, sessionId) {
|
|
37266
|
-
return
|
|
37943
|
+
return join12(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
|
|
37267
37944
|
}
|
|
37268
37945
|
async function markSessionEnded(stateDirectory, pid, sessionId) {
|
|
37269
37946
|
const marker = codexEndedFile(stateDirectory, pid, sessionId);
|
|
@@ -37308,7 +37985,7 @@ async function readCodexSessionRecord(file) {
|
|
|
37308
37985
|
}
|
|
37309
37986
|
function codexHome(env) {
|
|
37310
37987
|
const set = env["CODEX_HOME"];
|
|
37311
|
-
return set !== undefined && set !== "" ? set :
|
|
37988
|
+
return set !== undefined && set !== "" ? set : join12(env["HOME"] || homedir3(), ".codex");
|
|
37312
37989
|
}
|
|
37313
37990
|
function codexPluginDataDirectory(pluginRoot) {
|
|
37314
37991
|
const version = pluginRoot;
|
|
@@ -37318,7 +37995,7 @@ function codexPluginDataDirectory(pluginRoot) {
|
|
|
37318
37995
|
const plugins = dirname5(cache);
|
|
37319
37996
|
if (basename4(cache) !== "cache" || basename4(plugins) !== "plugins")
|
|
37320
37997
|
return;
|
|
37321
|
-
return
|
|
37998
|
+
return join12(plugins, "data", `${basename4(plugin)}-${basename4(marketplace)}`);
|
|
37322
37999
|
}
|
|
37323
38000
|
var MAX_ANCESTORS = 16;
|
|
37324
38001
|
function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
@@ -37332,14 +38009,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
37332
38009
|
}
|
|
37333
38010
|
function procComm(pid) {
|
|
37334
38011
|
try {
|
|
37335
|
-
return
|
|
38012
|
+
return readFileSync6(`/proc/${pid}/comm`, "utf8").trim();
|
|
37336
38013
|
} catch {
|
|
37337
38014
|
return;
|
|
37338
38015
|
}
|
|
37339
38016
|
}
|
|
37340
38017
|
function procParent(pid) {
|
|
37341
38018
|
try {
|
|
37342
|
-
const stat =
|
|
38019
|
+
const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
|
|
37343
38020
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
37344
38021
|
return Number.isInteger(parent) ? parent : undefined;
|
|
37345
38022
|
} catch {
|
|
@@ -37353,7 +38030,7 @@ var PS_OPTIONS = {
|
|
|
37353
38030
|
};
|
|
37354
38031
|
function procStarted(pid) {
|
|
37355
38032
|
try {
|
|
37356
|
-
const stat =
|
|
38033
|
+
const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
|
|
37357
38034
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
37358
38035
|
} catch {
|
|
37359
38036
|
return;
|
|
@@ -37374,7 +38051,7 @@ function recordOfProcess(record, pid) {
|
|
|
37374
38051
|
function sharedAppServer(pid) {
|
|
37375
38052
|
let argv;
|
|
37376
38053
|
try {
|
|
37377
|
-
argv =
|
|
38054
|
+
argv = readFileSync6(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
37378
38055
|
} catch {
|
|
37379
38056
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
37380
38057
|
if (ps.status !== 0)
|
|
@@ -37420,18 +38097,18 @@ function codexSubcommand(args) {
|
|
|
37420
38097
|
}
|
|
37421
38098
|
var SHARED_APP_SERVER_NOTE = "Codex runs this session in its shared app server (`codex app-server`), which runs several sessions in one process, so the Envoy plugin does not register it with Envoy: it receives no Envoy messages and does not show on Dispatch's Agents page. Its `dispatch` tool works, acting as this session.";
|
|
37422
38099
|
async function pruneCodexSessionRecords(stateDirectory) {
|
|
37423
|
-
await pruneStateDirectory(
|
|
38100
|
+
await pruneStateDirectory(join12(stateDirectory, "codex-sessions"), (file) => {
|
|
37424
38101
|
const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename4(file));
|
|
37425
38102
|
return match !== null && !processExists(Number(match[1]));
|
|
37426
38103
|
});
|
|
37427
|
-
await pruneStateDirectory(
|
|
38104
|
+
await pruneStateDirectory(join12(stateDirectory, "codex-servers"), (file) => {
|
|
37428
38105
|
const name = basename4(file);
|
|
37429
38106
|
return /^\d+$/.test(name) && !processExists(Number(name));
|
|
37430
38107
|
});
|
|
37431
38108
|
}
|
|
37432
38109
|
function codexExecutable(pid) {
|
|
37433
38110
|
try {
|
|
37434
|
-
return
|
|
38111
|
+
return readlinkSync2(`/proc/${pid}/exe`);
|
|
37435
38112
|
} catch {
|
|
37436
38113
|
return;
|
|
37437
38114
|
}
|
|
@@ -37527,7 +38204,7 @@ function singleQuoted(value) {
|
|
|
37527
38204
|
}
|
|
37528
38205
|
function envFileText(envFile) {
|
|
37529
38206
|
try {
|
|
37530
|
-
return
|
|
38207
|
+
return readFileSync7(envFile, "utf8");
|
|
37531
38208
|
} catch (error) {
|
|
37532
38209
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
37533
38210
|
throw error;
|
|
@@ -37645,7 +38322,7 @@ async function dispatchFirst(raw) {
|
|
|
37645
38322
|
process.stdout.write(JSON.stringify({
|
|
37646
38323
|
hookSpecificOutput: {
|
|
37647
38324
|
hookEventName: input.hook_event_name,
|
|
37648
|
-
additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(
|
|
38325
|
+
additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(join13(pluginRoot, "skills")))
|
|
37649
38326
|
}
|
|
37650
38327
|
}));
|
|
37651
38328
|
}
|
|
@@ -37653,8 +38330,8 @@ function refreshLockHeld(lock) {
|
|
|
37653
38330
|
let age;
|
|
37654
38331
|
let text;
|
|
37655
38332
|
try {
|
|
37656
|
-
age = Date.now() -
|
|
37657
|
-
text =
|
|
38333
|
+
age = Date.now() - statSync2(lock).mtimeMs;
|
|
38334
|
+
text = readFileSync7(lock, "utf8");
|
|
37658
38335
|
} catch (error) {
|
|
37659
38336
|
if (hasErrnoCode(error, "ENOENT"))
|
|
37660
38337
|
return false;
|
|
@@ -37675,7 +38352,7 @@ function refreshLockHeld(lock) {
|
|
|
37675
38352
|
function takeRefreshLock(lock) {
|
|
37676
38353
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
37677
38354
|
try {
|
|
37678
|
-
|
|
38355
|
+
writeFileSync3(lock, String(process.pid), { flag: "wx", mode: 384 });
|
|
37679
38356
|
return true;
|
|
37680
38357
|
} catch (error) {
|
|
37681
38358
|
if (!hasErrnoCode(error, "EEXIST"))
|
|
@@ -37683,14 +38360,14 @@ function takeRefreshLock(lock) {
|
|
|
37683
38360
|
}
|
|
37684
38361
|
if (refreshLockHeld(lock))
|
|
37685
38362
|
return false;
|
|
37686
|
-
|
|
38363
|
+
rmSync3(lock, { force: true });
|
|
37687
38364
|
}
|
|
37688
38365
|
return false;
|
|
37689
38366
|
}
|
|
37690
38367
|
function refreshOutcome(file, since) {
|
|
37691
38368
|
let value;
|
|
37692
38369
|
try {
|
|
37693
|
-
value = JSON.parse(
|
|
38370
|
+
value = JSON.parse(readFileSync7(file, "utf8"));
|
|
37694
38371
|
} catch {
|
|
37695
38372
|
return;
|
|
37696
38373
|
}
|
|
@@ -37704,13 +38381,13 @@ async function refreshedAnswers(session, cwd, dispatchUrl, startedAt, by) {
|
|
|
37704
38381
|
} catch (error) {
|
|
37705
38382
|
return { reason: messageFor(error) };
|
|
37706
38383
|
}
|
|
37707
|
-
const lock =
|
|
38384
|
+
const lock = join13(directory, REFRESH_LOCK);
|
|
37708
38385
|
if (!refreshLockHeld(lock)) {
|
|
37709
38386
|
const refresher = Bun.spawn([process.execPath, Bun.main, "answers-refresh", session, cwd, "--host", HOST], { stdin: "ignore", stdout: "ignore", stderr: "ignore", detached: true });
|
|
37710
38387
|
refresher.unref();
|
|
37711
38388
|
nameRefresher(refresher.pid);
|
|
37712
38389
|
}
|
|
37713
|
-
const file =
|
|
38390
|
+
const file = join13(directory, REFRESH_OUTCOME);
|
|
37714
38391
|
for (;; ) {
|
|
37715
38392
|
const outcome = refreshOutcome(file, startedAt);
|
|
37716
38393
|
if (outcome !== undefined) {
|
|
@@ -37790,8 +38467,8 @@ async function answers(text) {
|
|
|
37790
38467
|
}
|
|
37791
38468
|
async function answersRefresh(session, cwd) {
|
|
37792
38469
|
const directory = sessionDirectory(process.env, session);
|
|
37793
|
-
|
|
37794
|
-
const lock =
|
|
38470
|
+
mkdirSync3(directory, { recursive: true, mode: 448 });
|
|
38471
|
+
const lock = join13(directory, REFRESH_LOCK);
|
|
37795
38472
|
if (takeRefreshLock(lock)) {
|
|
37796
38473
|
try {
|
|
37797
38474
|
const file = sessionConfigFile(HOST, process.env);
|
|
@@ -37809,9 +38486,9 @@ async function answersRefresh(session, cwd) {
|
|
|
37809
38486
|
text: read.text ?? null,
|
|
37810
38487
|
notice: read.notice ?? null
|
|
37811
38488
|
};
|
|
37812
|
-
writeAtomically(
|
|
38489
|
+
writeAtomically(join13(directory, REFRESH_OUTCOME), JSON.stringify(outcome));
|
|
37813
38490
|
} finally {
|
|
37814
|
-
|
|
38491
|
+
rmSync3(lock, { force: true });
|
|
37815
38492
|
}
|
|
37816
38493
|
}
|
|
37817
38494
|
process.exit(0);
|