@sjawhar/claude-envoy 5.27.2 → 5.29.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 +132 -48
- package/dist/dispatch.js +128 -44
- package/dist/envoy-channel.js +232 -139
- package/dist/session-hook.js +138 -54
- package/dist/session-title-hook.js +8 -6
- package/legion/skills/legion-controller/references/triage.md +1 -1
- package/package.json +2 -2
- package/skills/dispatch/SKILL.md +2 -2
- package/src/envoy-channel-server.ts +25 -10
package/.omp-plugin/plugin.json
CHANGED
package/dist/codex-hook.js
CHANGED
|
@@ -14485,6 +14485,25 @@ var projectKeyValidation = {
|
|
|
14485
14485
|
message: `project is not a project key: ${PROJECT_KEY_RULE}`
|
|
14486
14486
|
};
|
|
14487
14487
|
var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
|
|
14488
|
+
var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
|
|
14489
|
+
var API_PATH_RULE = "path is a route under /api/v1: it begins /api/v1 and names no scheme or host, every character is printable ASCII other than a space, a backslash and #, and no segment before the query is . or ..";
|
|
14490
|
+
function apiPathProblem(value) {
|
|
14491
|
+
const { path } = value;
|
|
14492
|
+
if (typeof path !== "string")
|
|
14493
|
+
return;
|
|
14494
|
+
const named = JSON.stringify(path);
|
|
14495
|
+
if (!API_ROUTE_PATTERN.test(path)) {
|
|
14496
|
+
return `path ${named} is no route under /api/v1: give the route alone, beginning /api/v1, with no scheme or host (dispatch api --path /api/v1 lists every route).`;
|
|
14497
|
+
}
|
|
14498
|
+
if (!/^[!-~]*$/.test(path) || /[\\#]/.test(path)) {
|
|
14499
|
+
return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
|
|
14500
|
+
}
|
|
14501
|
+
const route = path.split("?", 1)[0] ?? "";
|
|
14502
|
+
if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
|
|
14503
|
+
return `path ${named} holds a . or .. segment: name the route itself.`;
|
|
14504
|
+
}
|
|
14505
|
+
return;
|
|
14506
|
+
}
|
|
14488
14507
|
var ISSUE_STATUSES = [
|
|
14489
14508
|
"triage",
|
|
14490
14509
|
"icebox",
|
|
@@ -14557,8 +14576,8 @@ var dispatchToolSpecs = [
|
|
|
14557
14576
|
route: z.string().describe("Route the issue to role:<name> or session:<id>; an empty string clears it.").optional(),
|
|
14558
14577
|
parent: z.string().describe("Parent issue key, in any project; an empty string clears the parent. A parent in another project passes on no repository, components or legion label.").optional(),
|
|
14559
14578
|
blocked_by: z.array(z.string({ min: 1 }), { max: MAX_ISSUE_BLOCKERS }).describe("Replacement list of issue keys this issue waits on, of any project; [] clears it. Dispatch refuses a dependency cycle.").optional(),
|
|
14560
|
-
advances: z.array(z.string({ min: 1 }), { max: MAX_ISSUE_ADVANCES }).describe("Replacement list of priority ids this issue advances, which dispatch priorities lists; [] clears the issue's own, leaving every priority it inherits from the issues above it.
|
|
14561
|
-
advances_revision: z.number().describe("The
|
|
14579
|
+
advances: z.array(z.string({ min: 1 }), { max: MAX_ISSUE_ADVANCES }).describe("Replacement list of priority ids this issue advances, which dispatch priorities lists; [] clears the issue's own, leaving every priority it inherits from the issues above it. Without advances_revision, Dispatch takes a list that adds or removes one priority, and refuses a list that changes two or more with 409 ADVANCES_REVISION, which names the issue's revision.").optional(),
|
|
14580
|
+
advances_revision: z.number().describe("The issue's advances revision, which the Advances line of dispatch read --issue <KEY> prints and a 409 ADVANCES_REVISION names. To change two or more priorities, read the issue, then send this revision with the whole list you mean. Alone it changes nothing.").optional(),
|
|
14562
14581
|
components: componentsArgument(z).optional(),
|
|
14563
14582
|
repo: z.string().describe("The repository the issue targets, owner/name. An empty string clears it, so the issue takes the nearest ancestor's in its own project, or the project's default, again.").optional(),
|
|
14564
14583
|
before: z.string().describe(`Move the issue above this issue on its project's board: an issue key in the same project. With after, the issue lands between the two. ${BOARD_NEIGHBOUR_REFUSAL}`).optional(),
|
|
@@ -15090,6 +15109,20 @@ var dispatchToolSpecs = [
|
|
|
15090
15109
|
arguments: () => ({}),
|
|
15091
15110
|
strict: true
|
|
15092
15111
|
},
|
|
15112
|
+
{
|
|
15113
|
+
name: "dispatch_api",
|
|
15114
|
+
example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
|
|
15115
|
+
description: "Read one route of Dispatch's HTTP API that no other command reads, with this session's own credential, and print Dispatch's JSON answer, for jq to read. It sends one GET of path: a route beginning /api/v1, with its query after ?; dispatch api --path /api/v1 lists every route. It only reads: it takes no method and no body, and every write goes through the command named for it (dispatch --help lists them). When Dispatch refuses the read, the command prints Dispatch's error with its code and, where Dispatch gives one, its hint, and exits 1. Under Claude Code, an answer longer than the output limit is written to a file the output names.",
|
|
15116
|
+
arguments: (z) => ({
|
|
15117
|
+
path: z.string({ min: 1 }).describe("The route to read, beginning /api/v1, with its query after ?, such as /api/v1/issues/ACME-12/events?limit=200. No scheme or host, and no . or .. segment.")
|
|
15118
|
+
}),
|
|
15119
|
+
validation: {
|
|
15120
|
+
check: (value) => apiPathProblem(value) === undefined,
|
|
15121
|
+
message: API_PATH_RULE,
|
|
15122
|
+
refusal: (value) => apiPathProblem(value) ?? API_PATH_RULE
|
|
15123
|
+
},
|
|
15124
|
+
strict: true
|
|
15125
|
+
},
|
|
15093
15126
|
{
|
|
15094
15127
|
name: "dispatch_handoff_write",
|
|
15095
15128
|
example: {
|
|
@@ -17509,17 +17542,19 @@ function errorClass(error) {
|
|
|
17509
17542
|
}
|
|
17510
17543
|
|
|
17511
17544
|
// ../envoy-client/src/errors.ts
|
|
17512
|
-
function
|
|
17513
|
-
if (!("fromDispatch" in error)
|
|
17545
|
+
function dispatchField(error, field) {
|
|
17546
|
+
if (!("fromDispatch" in error))
|
|
17514
17547
|
return;
|
|
17515
|
-
const
|
|
17516
|
-
return typeof
|
|
17548
|
+
const value = Reflect.get(error, field);
|
|
17549
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
17517
17550
|
}
|
|
17518
17551
|
function messageFor(error) {
|
|
17519
17552
|
if (!(error instanceof Error))
|
|
17520
17553
|
return scrub(String(error));
|
|
17521
|
-
const code =
|
|
17522
|
-
|
|
17554
|
+
const code = dispatchField(error, "code");
|
|
17555
|
+
const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
|
|
17556
|
+
const hint = dispatchField(error, "hint");
|
|
17557
|
+
return scrub(hint === undefined ? message : `${message}; ${hint}`);
|
|
17523
17558
|
}
|
|
17524
17559
|
function hasErrnoCode(error, code) {
|
|
17525
17560
|
return error instanceof Error && "code" in error && error.code === code;
|
|
@@ -21342,6 +21377,7 @@ class DispatchServiceError extends Error {
|
|
|
21342
21377
|
mismatches;
|
|
21343
21378
|
issues;
|
|
21344
21379
|
changed;
|
|
21380
|
+
hint;
|
|
21345
21381
|
constructor(code, status, message, details = {}) {
|
|
21346
21382
|
super(message);
|
|
21347
21383
|
this.code = code;
|
|
@@ -21351,6 +21387,7 @@ class DispatchServiceError extends Error {
|
|
|
21351
21387
|
this.mismatches = details.mismatches;
|
|
21352
21388
|
this.issues = details.issues;
|
|
21353
21389
|
this.changed = details.changed;
|
|
21390
|
+
this.hint = details.hint;
|
|
21354
21391
|
}
|
|
21355
21392
|
}
|
|
21356
21393
|
|
|
@@ -21840,6 +21877,10 @@ class DispatchClient {
|
|
|
21840
21877
|
async limits() {
|
|
21841
21878
|
return this.#json("GET", ["api", "v1", "limits"]);
|
|
21842
21879
|
}
|
|
21880
|
+
async readRoute(path) {
|
|
21881
|
+
const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
|
|
21882
|
+
return this.#response("GET", url, await this.#send("GET", url));
|
|
21883
|
+
}
|
|
21843
21884
|
async inbox(assignee) {
|
|
21844
21885
|
return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
|
|
21845
21886
|
}
|
|
@@ -22528,7 +22569,7 @@ class DispatchClient {
|
|
|
22528
22569
|
if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
22529
22570
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
22530
22571
|
}
|
|
22531
|
-
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
|
|
22572
|
+
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, { ...error, hint: typeof error.hint === "string" ? error.hint : undefined });
|
|
22532
22573
|
}
|
|
22533
22574
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
22534
22575
|
}
|
|
@@ -24302,6 +24343,7 @@ var issueFreeTools = {
|
|
|
24302
24343
|
dispatch_answers: true,
|
|
24303
24344
|
dispatch_whoami: true,
|
|
24304
24345
|
dispatch_limits: true,
|
|
24346
|
+
dispatch_api: true,
|
|
24305
24347
|
dispatch_inbox: true,
|
|
24306
24348
|
dispatch_send_to_agent: true,
|
|
24307
24349
|
dispatch_architecture_sync: true
|
|
@@ -25574,9 +25616,9 @@ function advancesLine(issue) {
|
|
|
25574
25616
|
return "Advances: unknown (this Dispatch server predates priorities; upgrade it)";
|
|
25575
25617
|
}
|
|
25576
25618
|
const advances = issue.advances ?? [];
|
|
25577
|
-
|
|
25578
|
-
|
|
25579
|
-
return `Advances: ${
|
|
25619
|
+
const set = advances.length === 0 ? "no priority" : advances.map(advanceText).join(", ");
|
|
25620
|
+
const revision = issue.advances_revision === undefined ? "" : `; revision ${issue.advances_revision}`;
|
|
25621
|
+
return `Advances: ${set}${revision}`;
|
|
25580
25622
|
}
|
|
25581
25623
|
function claimText(claim, agents, read = {}) {
|
|
25582
25624
|
const titles = agents?.titles;
|
|
@@ -26250,11 +26292,16 @@ function refuseUnsavedRepository(verb, issue, repo) {
|
|
|
26250
26292
|
const lost = repo === "" ? "the repository was not cleared" : `${repo} was not saved`;
|
|
26251
26293
|
throw new Error(`Dispatch ${verb} ${issue.key} without its repository: this Dispatch server predates repository fields, so ${lost}; upgrade the server`);
|
|
26252
26294
|
}
|
|
26253
|
-
function
|
|
26254
|
-
if (issue.advances_revision
|
|
26255
|
-
|
|
26256
|
-
}
|
|
26257
|
-
|
|
26295
|
+
function refuseServerWithoutAdvances(issue) {
|
|
26296
|
+
if (issue.advances_revision !== undefined)
|
|
26297
|
+
return;
|
|
26298
|
+
throw new Error(`Dispatch read ${issue.key} without its advances: this Dispatch server predates priorities, so nothing was sent; upgrade the server`);
|
|
26299
|
+
}
|
|
26300
|
+
function advancesRevisionAnswer(issueKey, error) {
|
|
26301
|
+
if (!dispatchAnswered(error, 409) || error.code !== "ADVANCES_REVISION")
|
|
26302
|
+
return "";
|
|
26303
|
+
const held = /(\d+)\D*$/.exec(error.message)?.[1] ?? "<the revision named above>";
|
|
26304
|
+
return `read the issue with ${commandLine("dispatch_read", { issue: issueKey })}, then send the whole set you mean with ${fieldFlag("dispatch_issue_update", "advances_revision")} ${held}`;
|
|
26258
26305
|
}
|
|
26259
26306
|
async function issueCommand(context) {
|
|
26260
26307
|
const { args, client, actor, input, linkBase } = context;
|
|
@@ -26365,7 +26412,9 @@ async function issueUpdateCommand(context) {
|
|
|
26365
26412
|
} catch (error) {
|
|
26366
26413
|
throw refusalWithCode(error);
|
|
26367
26414
|
}
|
|
26368
|
-
|
|
26415
|
+
if (advances !== undefined)
|
|
26416
|
+
refuseServerWithoutAdvances(before);
|
|
26417
|
+
const advancesWrite = advances === undefined ? undefined : { advances, ...defined("advances_revision", advancesRevision) };
|
|
26369
26418
|
if (status === "done" && typeof before.closed_at === "string") {
|
|
26370
26419
|
throw refusalWithCode(new DispatchServiceError("ISSUE_CLOSED", 409, "issue is closed"), `${issueKey} closed at ${before.closed_at}, so the reason was not posted and the close was not sent`);
|
|
26371
26420
|
}
|
|
@@ -26423,15 +26472,17 @@ async function issueUpdateCommand(context) {
|
|
|
26423
26472
|
throw error;
|
|
26424
26473
|
const answered = error instanceof DispatchWriteUnsettledError ? error.last : error;
|
|
26425
26474
|
const taken = dispatchAnswered(answered, 500) && newLinks.length > 0 ? `one of ${newLinks.join(", ")} may already be linked from another issue (a URL links exactly one issue)` : "";
|
|
26475
|
+
const revisionClause = advancesRevisionAnswer(issueKey, error);
|
|
26426
26476
|
if (closingNote === undefined) {
|
|
26427
26477
|
if (taken !== "" && !(error instanceof DispatchServiceError)) {
|
|
26428
26478
|
throw withAccount(error, taken);
|
|
26429
26479
|
}
|
|
26430
|
-
throw refusalWithCode(error, taken);
|
|
26480
|
+
throw refusalWithCode(error, taken, revisionClause);
|
|
26431
26481
|
}
|
|
26432
26482
|
const landed = closeAccount(error, closingNote);
|
|
26433
|
-
if (error instanceof DispatchServiceError)
|
|
26434
|
-
throw refusalWithCode(error, taken, landed);
|
|
26483
|
+
if (error instanceof DispatchServiceError) {
|
|
26484
|
+
throw refusalWithCode(error, taken, revisionClause, landed);
|
|
26485
|
+
}
|
|
26435
26486
|
throw withAccount(error, [taken, landed].filter((clause) => clause !== "").join("; "));
|
|
26436
26487
|
}
|
|
26437
26488
|
refuseUnsavedRepository("updated", after, repo);
|
|
@@ -26708,6 +26759,16 @@ async function resultsCommand(context) {
|
|
|
26708
26759
|
};
|
|
26709
26760
|
}
|
|
26710
26761
|
|
|
26762
|
+
// ../envoy-client/src/dispatch-commands/api.ts
|
|
26763
|
+
async function apiCommand(context) {
|
|
26764
|
+
const path = stringArg(context.args, "path");
|
|
26765
|
+
const answer = await context.newClient().readRoute(path);
|
|
26766
|
+
return {
|
|
26767
|
+
text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
|
|
26768
|
+
details: { path }
|
|
26769
|
+
};
|
|
26770
|
+
}
|
|
26771
|
+
|
|
26711
26772
|
// ../envoy-client/src/dispatch-commands/render-item.ts
|
|
26712
26773
|
function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
|
|
26713
26774
|
const answer = ask.answer;
|
|
@@ -28540,7 +28601,7 @@ function priorityWorkLine(work) {
|
|
|
28540
28601
|
}
|
|
28541
28602
|
function priorityIssueLine(issue, agents) {
|
|
28542
28603
|
const advances = issue.advances ?? [];
|
|
28543
|
-
const moved = issue.moved_at === null ? "" : ` \xB7
|
|
28604
|
+
const moved = issue.moved_at === null ? "" : ` \xB7 moved to ${issue.status} ${issue.moved_at}${issue.moved_by === null ? "" : ` by ${actorLabel(issue.moved_by, agents?.titles)}`}`;
|
|
28544
28605
|
return `- ${issue.key} [${issue.status}] ${issue.title} \xB7 ${issue.project}` + (issue.assignee === null ? "" : ` \xB7 ${issue.assignee}`) + (issue.claim === null ? "" : ` \xB7 claimed by ${claimText(issue.claim, agents)}`) + (advances.length === 0 ? "" : ` \xB7 advances ${advances.map(advanceText).join(", ")}`) + moved + ` \xB7 changed ${issue.changed_at}`;
|
|
28545
28606
|
}
|
|
28546
28607
|
function priorityFaultLines(heading, fault, agents) {
|
|
@@ -28556,7 +28617,7 @@ function priorityFaultLines(heading, fault, agents) {
|
|
|
28556
28617
|
}
|
|
28557
28618
|
function formatPriorities(response, agents) {
|
|
28558
28619
|
const priorities = response.priorities ?? [];
|
|
28559
|
-
const
|
|
28620
|
+
const backlog = response.priority_work_parked;
|
|
28560
28621
|
const unplaced = response.work_under_no_priority;
|
|
28561
28622
|
if (response.empty !== undefined)
|
|
28562
28623
|
return response.empty;
|
|
@@ -28569,7 +28630,7 @@ function formatPriorities(response, agents) {
|
|
|
28569
28630
|
"",
|
|
28570
28631
|
...priorityFaultLines("Work under no priority", { count: unplaced.count, issues: unplaced.issues, by: unplaced.by_project }, agents),
|
|
28571
28632
|
"",
|
|
28572
|
-
...priorityFaultLines("Priority work
|
|
28633
|
+
...priorityFaultLines("Priority work in backlog or icebox", { count: backlog.count, issues: backlog.issues, by: backlog.by_priority }, agents)
|
|
28573
28634
|
].join(`
|
|
28574
28635
|
`);
|
|
28575
28636
|
}
|
|
@@ -29597,6 +29658,7 @@ var dispatchCommands = {
|
|
|
29597
29658
|
dispatch_answers: onSession(answersCommand),
|
|
29598
29659
|
dispatch_whoami: onSession(whoamiCommand),
|
|
29599
29660
|
dispatch_limits: onSession(limitsCommand),
|
|
29661
|
+
dispatch_api: onSession(apiCommand),
|
|
29600
29662
|
dispatch_inbox: onSession(inboxCommand)
|
|
29601
29663
|
};
|
|
29602
29664
|
// ../envoy-client/src/dispatch-execute.ts
|
|
@@ -29617,6 +29679,10 @@ async function executeDispatchTool(input) {
|
|
|
29617
29679
|
return command.origin === "none" ? command.run(session) : command.run(await commandContext(session));
|
|
29618
29680
|
}
|
|
29619
29681
|
|
|
29682
|
+
// ../cipher-client/src/environment.ts
|
|
29683
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
29684
|
+
import { join as join7 } from "path";
|
|
29685
|
+
|
|
29620
29686
|
// ../cipher-client/src/device-login.ts
|
|
29621
29687
|
import { generateKeyPairSync as generateKeyPairSync2, randomUUID as randomUUID5 } from "crypto";
|
|
29622
29688
|
|
|
@@ -33413,6 +33479,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
|
|
|
33413
33479
|
var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
|
|
33414
33480
|
var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
|
|
33415
33481
|
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
33482
|
+
var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
|
|
33483
|
+
var ROLE_KEY_FILE = "key.pem";
|
|
33416
33484
|
var SESSION_VAR = "AGENT_SECRETS_SESSION";
|
|
33417
33485
|
var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
|
|
33418
33486
|
var MAX_PROJECTS = 16;
|
|
@@ -33426,6 +33494,7 @@ var BROKER_VARIABLES = [
|
|
|
33426
33494
|
BROKER_URL_VAR,
|
|
33427
33495
|
IDENTITY_VAR,
|
|
33428
33496
|
MACHINE_TOKEN_FILE_VAR,
|
|
33497
|
+
KEY_DIR_VAR,
|
|
33429
33498
|
MACHINE_AUDIENCE_VAR,
|
|
33430
33499
|
SESSION_VAR,
|
|
33431
33500
|
PROJECTS_VAR,
|
|
@@ -33501,6 +33570,21 @@ function tradeProjects(env) {
|
|
|
33501
33570
|
}
|
|
33502
33571
|
return sorted;
|
|
33503
33572
|
}
|
|
33573
|
+
async function machineKey(env) {
|
|
33574
|
+
const dir = value(env, KEY_DIR_VAR);
|
|
33575
|
+
if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
|
|
33576
|
+
return await newDpopKey();
|
|
33577
|
+
const path = join7(dir, ROLE_KEY_FILE);
|
|
33578
|
+
let pem;
|
|
33579
|
+
try {
|
|
33580
|
+
pem = await readFile6(path, "utf8");
|
|
33581
|
+
} catch (error) {
|
|
33582
|
+
throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
|
|
33583
|
+
cause: error
|
|
33584
|
+
});
|
|
33585
|
+
}
|
|
33586
|
+
return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
|
|
33587
|
+
}
|
|
33504
33588
|
async function brokerTokenClient(env, own = "", read) {
|
|
33505
33589
|
const brokerUrl = value(env, BROKER_URL_VAR);
|
|
33506
33590
|
const machine = machineIdentity(env);
|
|
@@ -33528,7 +33612,7 @@ async function brokerTokenClient(env, own = "", read) {
|
|
|
33528
33612
|
if (record === undefined) {
|
|
33529
33613
|
const client = new BrokerTokenClient({
|
|
33530
33614
|
brokerUrl,
|
|
33531
|
-
key: await
|
|
33615
|
+
key: await machineKey(env),
|
|
33532
33616
|
subject: machine,
|
|
33533
33617
|
session: tradeSession(env, own),
|
|
33534
33618
|
launcherCredential: false,
|
|
@@ -34723,18 +34807,18 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
34723
34807
|
// src/codex/codex-session-record.ts
|
|
34724
34808
|
import { spawnSync } from "child_process";
|
|
34725
34809
|
import { readFileSync as readFileSync4, readlinkSync, unwatchFile, watchFile } from "fs";
|
|
34726
|
-
import { mkdir as mkdir3, readFile as
|
|
34810
|
+
import { mkdir as mkdir3, readFile as readFile8, rename as rename4, utimes as utimes3, writeFile as writeFile2 } from "fs/promises";
|
|
34727
34811
|
import { homedir as homedir3 } from "os";
|
|
34728
|
-
import { basename as basename4, dirname as dirname5, join as
|
|
34812
|
+
import { basename as basename4, dirname as dirname5, join as join10 } from "path";
|
|
34729
34813
|
|
|
34730
34814
|
// src/session-identity.ts
|
|
34731
|
-
import { readFile as
|
|
34732
|
-
import { basename as basename3, join as
|
|
34815
|
+
import { readFile as readFile7 } from "fs/promises";
|
|
34816
|
+
import { basename as basename3, join as join9 } from "path";
|
|
34733
34817
|
|
|
34734
34818
|
// src/session-state.ts
|
|
34735
34819
|
import { readFileSync as readFileSync3 } from "fs";
|
|
34736
34820
|
import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
|
|
34737
|
-
import { dirname as dirname4, join as
|
|
34821
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
34738
34822
|
async function writeAtomicStateFile(file, contents) {
|
|
34739
34823
|
await mkdir2(dirname4(file), { recursive: true, mode: 448 });
|
|
34740
34824
|
const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
@@ -34752,7 +34836,7 @@ async function pruneStateDirectory(directory, isStale) {
|
|
|
34752
34836
|
throw error;
|
|
34753
34837
|
});
|
|
34754
34838
|
for (const entry of entries) {
|
|
34755
|
-
const file =
|
|
34839
|
+
const file = join8(directory, entry);
|
|
34756
34840
|
if (!await isStale(file))
|
|
34757
34841
|
continue;
|
|
34758
34842
|
await rm4(file, { recursive: true, force: true });
|
|
@@ -34767,7 +34851,7 @@ async function writtenLongAgo(file) {
|
|
|
34767
34851
|
}
|
|
34768
34852
|
var TITLES_DIRECTORY = "titles";
|
|
34769
34853
|
function sessionTitleFile(stateDirectory, sessionId) {
|
|
34770
|
-
return
|
|
34854
|
+
return join8(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
|
|
34771
34855
|
}
|
|
34772
34856
|
async function writeChosenTitle(file, title) {
|
|
34773
34857
|
await writeAtomicStateFile(file, `${title}
|
|
@@ -34795,7 +34879,7 @@ async function recordChosenTitle(sessionId, title) {
|
|
|
34795
34879
|
await writeChosenTitle(file, chosen);
|
|
34796
34880
|
}
|
|
34797
34881
|
async function pruneStaleSessionTitles(stateDirectory) {
|
|
34798
|
-
await pruneStateDirectory(
|
|
34882
|
+
await pruneStateDirectory(join8(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
|
|
34799
34883
|
}
|
|
34800
34884
|
|
|
34801
34885
|
// src/session-identity.ts
|
|
@@ -34820,14 +34904,14 @@ class SessionIdentity {
|
|
|
34820
34904
|
}
|
|
34821
34905
|
}
|
|
34822
34906
|
function sessionHandoffDirectory(stateDirectory, claudePid) {
|
|
34823
|
-
return
|
|
34907
|
+
return join9(stateDirectory, "sessions", String(claudePid));
|
|
34824
34908
|
}
|
|
34825
34909
|
function sessionHandoffFile(stateDirectory, claudePid) {
|
|
34826
|
-
return
|
|
34910
|
+
return join9(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
|
|
34827
34911
|
}
|
|
34828
34912
|
var ROLES_DIRECTORY = "roles";
|
|
34829
34913
|
function roleStateFile(stateDirectory, sessionId) {
|
|
34830
|
-
return
|
|
34914
|
+
return join9(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
|
|
34831
34915
|
}
|
|
34832
34916
|
|
|
34833
34917
|
class UnparseableRoleRecordError extends Error {
|
|
@@ -34839,7 +34923,7 @@ class UnparseableRoleRecordError extends Error {
|
|
|
34839
34923
|
async function readPersistedRole(roleFile) {
|
|
34840
34924
|
let bytes;
|
|
34841
34925
|
try {
|
|
34842
|
-
bytes = await
|
|
34926
|
+
bytes = await readFile7(roleFile, "utf8");
|
|
34843
34927
|
} catch (error) {
|
|
34844
34928
|
if (hasErrnoCode(error, "ENOENT"))
|
|
34845
34929
|
return;
|
|
@@ -34861,7 +34945,7 @@ async function writeSessionHandoff(file, sessionId) {
|
|
|
34861
34945
|
}
|
|
34862
34946
|
async function readSessionHandoff(file) {
|
|
34863
34947
|
try {
|
|
34864
|
-
const id = (await
|
|
34948
|
+
const id = (await readFile7(file, "utf8")).trim();
|
|
34865
34949
|
return id.length === 0 ? undefined : id;
|
|
34866
34950
|
} catch (error) {
|
|
34867
34951
|
if (hasErrnoCode(error, "ENOENT"))
|
|
@@ -34878,14 +34962,14 @@ function processExists(pid) {
|
|
|
34878
34962
|
}
|
|
34879
34963
|
}
|
|
34880
34964
|
async function pruneStaleSessionHandoffs(stateDirectory) {
|
|
34881
|
-
await pruneStateDirectory(
|
|
34965
|
+
await pruneStateDirectory(join9(stateDirectory, "sessions"), (file) => {
|
|
34882
34966
|
const pid = basename3(file);
|
|
34883
34967
|
return /^\d+$/.test(pid) && !processExists(Number(pid));
|
|
34884
34968
|
});
|
|
34885
34969
|
}
|
|
34886
34970
|
async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
|
|
34887
34971
|
const own = roleStateFile(stateDirectory, currentSessionId);
|
|
34888
|
-
await pruneStateDirectory(
|
|
34972
|
+
await pruneStateDirectory(join9(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
|
|
34889
34973
|
}
|
|
34890
34974
|
|
|
34891
34975
|
// src/codex/codex-session-record.ts
|
|
@@ -34899,10 +34983,10 @@ var CodexSessionRecord = object({
|
|
|
34899
34983
|
codex_started: string2().nullable().default(null)
|
|
34900
34984
|
});
|
|
34901
34985
|
function codexSessionRecordFile(stateDirectory, pid) {
|
|
34902
|
-
return
|
|
34986
|
+
return join10(stateDirectory, "codex-sessions", `${pid}.json`);
|
|
34903
34987
|
}
|
|
34904
34988
|
function codexEndedFile(stateDirectory, pid, sessionId) {
|
|
34905
|
-
return
|
|
34989
|
+
return join10(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
|
|
34906
34990
|
}
|
|
34907
34991
|
async function markSessionEnded(stateDirectory, pid, sessionId) {
|
|
34908
34992
|
const marker = codexEndedFile(stateDirectory, pid, sessionId);
|
|
@@ -34925,7 +35009,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
|
|
|
34925
35009
|
}
|
|
34926
35010
|
async function sessionEnded(file) {
|
|
34927
35011
|
try {
|
|
34928
|
-
await
|
|
35012
|
+
await readFile8(file);
|
|
34929
35013
|
return true;
|
|
34930
35014
|
} catch {
|
|
34931
35015
|
return false;
|
|
@@ -34939,7 +35023,7 @@ async function writeCodexSessionRecord(file, value) {
|
|
|
34939
35023
|
}
|
|
34940
35024
|
async function readCodexSessionRecord(file) {
|
|
34941
35025
|
try {
|
|
34942
|
-
const parsed = CodexSessionRecord.safeParse(JSON.parse(await
|
|
35026
|
+
const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile8(file, "utf8")));
|
|
34943
35027
|
return parsed.success ? parsed.data : undefined;
|
|
34944
35028
|
} catch {
|
|
34945
35029
|
return;
|
|
@@ -34947,7 +35031,7 @@ async function readCodexSessionRecord(file) {
|
|
|
34947
35031
|
}
|
|
34948
35032
|
function codexHome(env) {
|
|
34949
35033
|
const set = env["CODEX_HOME"];
|
|
34950
|
-
return set !== undefined && set !== "" ? set :
|
|
35034
|
+
return set !== undefined && set !== "" ? set : join10(env["HOME"] || homedir3(), ".codex");
|
|
34951
35035
|
}
|
|
34952
35036
|
function codexPluginDataDirectory(pluginRoot) {
|
|
34953
35037
|
const version = pluginRoot;
|
|
@@ -34957,7 +35041,7 @@ function codexPluginDataDirectory(pluginRoot) {
|
|
|
34957
35041
|
const plugins = dirname5(cache);
|
|
34958
35042
|
if (basename4(cache) !== "cache" || basename4(plugins) !== "plugins")
|
|
34959
35043
|
return;
|
|
34960
|
-
return
|
|
35044
|
+
return join10(plugins, "data", `${basename4(plugin)}-${basename4(marketplace)}`);
|
|
34961
35045
|
}
|
|
34962
35046
|
var MAX_ANCESTORS = 16;
|
|
34963
35047
|
function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
@@ -35059,11 +35143,11 @@ function codexSubcommand(args) {
|
|
|
35059
35143
|
}
|
|
35060
35144
|
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.";
|
|
35061
35145
|
async function pruneCodexSessionRecords(stateDirectory) {
|
|
35062
|
-
await pruneStateDirectory(
|
|
35146
|
+
await pruneStateDirectory(join10(stateDirectory, "codex-sessions"), (file) => {
|
|
35063
35147
|
const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename4(file));
|
|
35064
35148
|
return match !== null && !processExists(Number(match[1]));
|
|
35065
35149
|
});
|
|
35066
|
-
await pruneStateDirectory(
|
|
35150
|
+
await pruneStateDirectory(join10(stateDirectory, "codex-servers"), (file) => {
|
|
35067
35151
|
const name = basename4(file);
|
|
35068
35152
|
return /^\d+$/.test(name) && !processExists(Number(name));
|
|
35069
35153
|
});
|