@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/dist/envoy-channel.js
CHANGED
|
@@ -23780,7 +23780,7 @@ function scrubProcessStreams() {
|
|
|
23780
23780
|
import { spawn as spawn2 } from "child_process";
|
|
23781
23781
|
import { unwatchFile as unwatchFile3, watchFile as watchFile3 } from "fs";
|
|
23782
23782
|
import { homedir as homedir4 } from "os";
|
|
23783
|
-
import { join as
|
|
23783
|
+
import { join as join22, resolve as resolve3 } from "path";
|
|
23784
23784
|
// ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/core/core.js
|
|
23785
23785
|
var NEVER = Object.freeze({
|
|
23786
23786
|
status: "aborted"
|
|
@@ -37285,6 +37285,25 @@ var projectKeyValidation = {
|
|
|
37285
37285
|
message: `project is not a project key: ${PROJECT_KEY_RULE}`
|
|
37286
37286
|
};
|
|
37287
37287
|
var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
|
|
37288
|
+
var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
|
|
37289
|
+
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 ..";
|
|
37290
|
+
function apiPathProblem(value) {
|
|
37291
|
+
const { path } = value;
|
|
37292
|
+
if (typeof path !== "string")
|
|
37293
|
+
return;
|
|
37294
|
+
const named = JSON.stringify(path);
|
|
37295
|
+
if (!API_ROUTE_PATTERN.test(path)) {
|
|
37296
|
+
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).`;
|
|
37297
|
+
}
|
|
37298
|
+
if (!/^[!-~]*$/.test(path) || /[\\#]/.test(path)) {
|
|
37299
|
+
return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
|
|
37300
|
+
}
|
|
37301
|
+
const route = path.split("?", 1)[0] ?? "";
|
|
37302
|
+
if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
|
|
37303
|
+
return `path ${named} holds a . or .. segment: name the route itself.`;
|
|
37304
|
+
}
|
|
37305
|
+
return;
|
|
37306
|
+
}
|
|
37288
37307
|
var ISSUE_STATUSES = [
|
|
37289
37308
|
"triage",
|
|
37290
37309
|
"icebox",
|
|
@@ -37357,8 +37376,8 @@ var dispatchToolSpecs = [
|
|
|
37357
37376
|
route: z.string().describe("Route the issue to role:<name> or session:<id>; an empty string clears it.").optional(),
|
|
37358
37377
|
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(),
|
|
37359
37378
|
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(),
|
|
37360
|
-
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.
|
|
37361
|
-
advances_revision: z.number().describe("The
|
|
37379
|
+
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(),
|
|
37380
|
+
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(),
|
|
37362
37381
|
components: componentsArgument(z).optional(),
|
|
37363
37382
|
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(),
|
|
37364
37383
|
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(),
|
|
@@ -37890,6 +37909,20 @@ var dispatchToolSpecs = [
|
|
|
37890
37909
|
arguments: () => ({}),
|
|
37891
37910
|
strict: true
|
|
37892
37911
|
},
|
|
37912
|
+
{
|
|
37913
|
+
name: "dispatch_api",
|
|
37914
|
+
example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
|
|
37915
|
+
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.",
|
|
37916
|
+
arguments: (z) => ({
|
|
37917
|
+
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.")
|
|
37918
|
+
}),
|
|
37919
|
+
validation: {
|
|
37920
|
+
check: (value) => apiPathProblem(value) === undefined,
|
|
37921
|
+
message: API_PATH_RULE,
|
|
37922
|
+
refusal: (value) => apiPathProblem(value) ?? API_PATH_RULE
|
|
37923
|
+
},
|
|
37924
|
+
strict: true
|
|
37925
|
+
},
|
|
37893
37926
|
{
|
|
37894
37927
|
name: "dispatch_handoff_write",
|
|
37895
37928
|
example: {
|
|
@@ -40105,6 +40138,10 @@ function zodSchemaApi(zod) {
|
|
|
40105
40138
|
}
|
|
40106
40139
|
};
|
|
40107
40140
|
}
|
|
40141
|
+
// ../cipher-client/src/environment.ts
|
|
40142
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
40143
|
+
import { join as join4 } from "path";
|
|
40144
|
+
|
|
40108
40145
|
// ../contracts/src/log-text.ts
|
|
40109
40146
|
var URL_NOT_PRINTED = "(not printed: it carries a credential or is not a plain http(s) URL)";
|
|
40110
40147
|
function isCleanUrl(raw) {
|
|
@@ -44446,6 +44483,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
|
|
|
44446
44483
|
var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
|
|
44447
44484
|
var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
|
|
44448
44485
|
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
44486
|
+
var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
|
|
44487
|
+
var ROLE_KEY_FILE = "key.pem";
|
|
44449
44488
|
var SESSION_VAR = "AGENT_SECRETS_SESSION";
|
|
44450
44489
|
var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
|
|
44451
44490
|
var MAX_PROJECTS = 16;
|
|
@@ -44459,6 +44498,7 @@ var BROKER_VARIABLES = [
|
|
|
44459
44498
|
BROKER_URL_VAR,
|
|
44460
44499
|
IDENTITY_VAR,
|
|
44461
44500
|
MACHINE_TOKEN_FILE_VAR,
|
|
44501
|
+
KEY_DIR_VAR,
|
|
44462
44502
|
MACHINE_AUDIENCE_VAR,
|
|
44463
44503
|
SESSION_VAR,
|
|
44464
44504
|
PROJECTS_VAR,
|
|
@@ -44534,6 +44574,21 @@ function tradeProjects(env) {
|
|
|
44534
44574
|
}
|
|
44535
44575
|
return sorted;
|
|
44536
44576
|
}
|
|
44577
|
+
async function machineKey(env) {
|
|
44578
|
+
const dir = value(env, KEY_DIR_VAR);
|
|
44579
|
+
if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
|
|
44580
|
+
return await newDpopKey();
|
|
44581
|
+
const path = join4(dir, ROLE_KEY_FILE);
|
|
44582
|
+
let pem;
|
|
44583
|
+
try {
|
|
44584
|
+
pem = await readFile4(path, "utf8");
|
|
44585
|
+
} catch (error) {
|
|
44586
|
+
throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
|
|
44587
|
+
cause: error
|
|
44588
|
+
});
|
|
44589
|
+
}
|
|
44590
|
+
return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
|
|
44591
|
+
}
|
|
44537
44592
|
async function brokerTokenClient(env, own = "", read) {
|
|
44538
44593
|
const brokerUrl = value(env, BROKER_URL_VAR);
|
|
44539
44594
|
const machine = machineIdentity(env);
|
|
@@ -44561,7 +44616,7 @@ async function brokerTokenClient(env, own = "", read) {
|
|
|
44561
44616
|
if (record === undefined) {
|
|
44562
44617
|
const client = new BrokerTokenClient({
|
|
44563
44618
|
brokerUrl,
|
|
44564
|
-
key: await
|
|
44619
|
+
key: await machineKey(env),
|
|
44565
44620
|
subject: machine,
|
|
44566
44621
|
session: tradeSession(env, own),
|
|
44567
44622
|
launcherCredential: false,
|
|
@@ -44592,7 +44647,7 @@ import {
|
|
|
44592
44647
|
lstat as lstat3,
|
|
44593
44648
|
mkdtemp,
|
|
44594
44649
|
open as open3,
|
|
44595
|
-
readFile as
|
|
44650
|
+
readFile as readFile6,
|
|
44596
44651
|
readlink as readlink2,
|
|
44597
44652
|
rm as rm3,
|
|
44598
44653
|
stat as stat3
|
|
@@ -44601,17 +44656,19 @@ import { homedir, tmpdir } from "os";
|
|
|
44601
44656
|
import * as path from "path";
|
|
44602
44657
|
|
|
44603
44658
|
// ../envoy-client/src/errors.ts
|
|
44604
|
-
function
|
|
44605
|
-
if (!("fromDispatch" in error)
|
|
44659
|
+
function dispatchField(error, field) {
|
|
44660
|
+
if (!("fromDispatch" in error))
|
|
44606
44661
|
return;
|
|
44607
|
-
const
|
|
44608
|
-
return typeof
|
|
44662
|
+
const value = Reflect.get(error, field);
|
|
44663
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
44609
44664
|
}
|
|
44610
44665
|
function messageFor(error) {
|
|
44611
44666
|
if (!(error instanceof Error))
|
|
44612
44667
|
return scrub(String(error));
|
|
44613
|
-
const code =
|
|
44614
|
-
|
|
44668
|
+
const code = dispatchField(error, "code");
|
|
44669
|
+
const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
|
|
44670
|
+
const hint = dispatchField(error, "hint");
|
|
44671
|
+
return scrub(hint === undefined ? message : `${message}; ${hint}`);
|
|
44615
44672
|
}
|
|
44616
44673
|
function hasErrnoCode(error, code) {
|
|
44617
44674
|
return error instanceof Error && "code" in error && error.code === code;
|
|
@@ -44777,14 +44834,14 @@ function spawnWatched(argv, options) {
|
|
|
44777
44834
|
}
|
|
44778
44835
|
|
|
44779
44836
|
// ../envoy-client/src/secret-file.ts
|
|
44780
|
-
import { readFile as
|
|
44837
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
44781
44838
|
function sendable(value) {
|
|
44782
44839
|
return !/[\s\p{Cc}]/u.test(value);
|
|
44783
44840
|
}
|
|
44784
44841
|
async function readSecretFile(variable, filePath) {
|
|
44785
44842
|
let contents;
|
|
44786
44843
|
try {
|
|
44787
|
-
contents = await
|
|
44844
|
+
contents = await readFile5(filePath, "utf8");
|
|
44788
44845
|
} catch (error) {
|
|
44789
44846
|
throw new Error(`${variable} names a file that could not be read (${readErrorCode(error)})`);
|
|
44790
44847
|
}
|
|
@@ -44937,7 +44994,7 @@ async function exists(file) {
|
|
|
44937
44994
|
async function parseFile(filePath, schema, checkout) {
|
|
44938
44995
|
let raw;
|
|
44939
44996
|
try {
|
|
44940
|
-
raw = await
|
|
44997
|
+
raw = await readFile6(filePath, "utf-8");
|
|
44941
44998
|
} catch (error) {
|
|
44942
44999
|
if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
|
|
44943
45000
|
return { kind: "absent", link: checkout ? null : await danglingLink(filePath) };
|
|
@@ -45850,6 +45907,7 @@ class DispatchServiceError extends Error {
|
|
|
45850
45907
|
mismatches;
|
|
45851
45908
|
issues;
|
|
45852
45909
|
changed;
|
|
45910
|
+
hint;
|
|
45853
45911
|
constructor(code, status, message, details = {}) {
|
|
45854
45912
|
super(message);
|
|
45855
45913
|
this.code = code;
|
|
@@ -45859,6 +45917,7 @@ class DispatchServiceError extends Error {
|
|
|
45859
45917
|
this.mismatches = details.mismatches;
|
|
45860
45918
|
this.issues = details.issues;
|
|
45861
45919
|
this.changed = details.changed;
|
|
45920
|
+
this.hint = details.hint;
|
|
45862
45921
|
}
|
|
45863
45922
|
}
|
|
45864
45923
|
|
|
@@ -46348,6 +46407,10 @@ class DispatchClient {
|
|
|
46348
46407
|
async limits() {
|
|
46349
46408
|
return this.#json("GET", ["api", "v1", "limits"]);
|
|
46350
46409
|
}
|
|
46410
|
+
async readRoute(path) {
|
|
46411
|
+
const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
|
|
46412
|
+
return this.#response("GET", url, await this.#send("GET", url));
|
|
46413
|
+
}
|
|
46351
46414
|
async inbox(assignee) {
|
|
46352
46415
|
return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
|
|
46353
46416
|
}
|
|
@@ -47036,7 +47099,7 @@ class DispatchClient {
|
|
|
47036
47099
|
if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
47037
47100
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
47038
47101
|
}
|
|
47039
|
-
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
|
|
47102
|
+
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, { ...error, hint: typeof error.hint === "string" ? error.hint : undefined });
|
|
47040
47103
|
}
|
|
47041
47104
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
47042
47105
|
}
|
|
@@ -47072,20 +47135,20 @@ class DispatchClient {
|
|
|
47072
47135
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
47073
47136
|
import { renameSync, rmSync, writeFileSync } from "fs";
|
|
47074
47137
|
import { homedir as homedir2 } from "os";
|
|
47075
|
-
import { join as
|
|
47138
|
+
import { join as join6 } from "path";
|
|
47076
47139
|
var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
|
|
47077
47140
|
var PRIVATE_FILE = 384;
|
|
47078
47141
|
function sessionStateRoot(env) {
|
|
47079
47142
|
const stateDir = env["DISPATCH_STATE_DIR"];
|
|
47080
47143
|
if (stateDir)
|
|
47081
47144
|
return stateDir;
|
|
47082
|
-
return
|
|
47145
|
+
return join6(env["XDG_STATE_HOME"] || join6(homedir2(), ".local", "state"), "dispatch");
|
|
47083
47146
|
}
|
|
47084
47147
|
function sessionDirectory(env, sessionId) {
|
|
47085
47148
|
if (!SESSION_ID_PATH_SEGMENT.test(sessionId) || sessionId === "." || sessionId === "..") {
|
|
47086
47149
|
throw new Error(`dispatch: the session id ${JSON.stringify(sessionId)} is not 1-128 letters, digits, ".", "_" or "-"`);
|
|
47087
47150
|
}
|
|
47088
|
-
return
|
|
47151
|
+
return join6(sessionStateRoot(env), "sessions", sessionId);
|
|
47089
47152
|
}
|
|
47090
47153
|
function writeAtomically(path, text) {
|
|
47091
47154
|
const temporary = `${path}.${process.pid}.${randomUUID5()}.tmp`;
|
|
@@ -47113,7 +47176,7 @@ import {
|
|
|
47113
47176
|
statSync as statSync2,
|
|
47114
47177
|
writeFileSync as writeFileSync3
|
|
47115
47178
|
} from "fs";
|
|
47116
|
-
import { join as
|
|
47179
|
+
import { join as join9 } from "path";
|
|
47117
47180
|
|
|
47118
47181
|
// ../envoy-client/src/askgate-marker.ts
|
|
47119
47182
|
import { createHash as createHash2, randomBytes } from "crypto";
|
|
@@ -47132,7 +47195,7 @@ import {
|
|
|
47132
47195
|
utimesSync,
|
|
47133
47196
|
writeFileSync as writeFileSync2
|
|
47134
47197
|
} from "fs";
|
|
47135
|
-
import { isAbsolute as isAbsolute3, join as
|
|
47198
|
+
import { isAbsolute as isAbsolute3, join as join7, resolve as resolve2 } from "path";
|
|
47136
47199
|
var ASKGATE_RECORD = "askgate";
|
|
47137
47200
|
var MARKER_MAX_AGE_MS = 2 * 60 * 60000;
|
|
47138
47201
|
var STORE_BEAT_MS = 10 * 60000;
|
|
@@ -47258,7 +47321,7 @@ var STORE_NAME = /^([1-9][0-9]*)(?:-([0-9]+)(?:-([0-9]+))?)?$/;
|
|
|
47258
47321
|
function storeTouched(store) {
|
|
47259
47322
|
const own = statSync(store).mtimeMs;
|
|
47260
47323
|
try {
|
|
47261
|
-
return Math.max(own, statSync(
|
|
47324
|
+
return Math.max(own, statSync(join7(store, MARKERS)).mtimeMs);
|
|
47262
47325
|
} catch (error) {
|
|
47263
47326
|
if (hasErrnoCode(error, "ENOENT"))
|
|
47264
47327
|
return own;
|
|
@@ -47267,7 +47330,7 @@ function storeTouched(store) {
|
|
|
47267
47330
|
}
|
|
47268
47331
|
var UNNAMESPACED_STORE_MAX_AGE_MS = 14 * 86400000;
|
|
47269
47332
|
function sweepStores(root, now) {
|
|
47270
|
-
const parent =
|
|
47333
|
+
const parent = join7(root, "askgate");
|
|
47271
47334
|
let names;
|
|
47272
47335
|
try {
|
|
47273
47336
|
names = readdirSync(parent);
|
|
@@ -47278,7 +47341,7 @@ function sweepStores(root, now) {
|
|
|
47278
47341
|
const match = STORE_NAME.exec(name);
|
|
47279
47342
|
if (match === null)
|
|
47280
47343
|
continue;
|
|
47281
|
-
const store =
|
|
47344
|
+
const store = join7(parent, name);
|
|
47282
47345
|
try {
|
|
47283
47346
|
const owner = { pid: Number(match[1]), start: match[2] ?? null, ns: match[3] ?? null, store };
|
|
47284
47347
|
if (ownerLive(owner, now))
|
|
@@ -47292,7 +47355,7 @@ function sweepStores(root, now) {
|
|
|
47292
47355
|
}
|
|
47293
47356
|
}
|
|
47294
47357
|
function recordNamesStore(dir) {
|
|
47295
|
-
const record =
|
|
47358
|
+
const record = join7(dir, ASKGATE_RECORD);
|
|
47296
47359
|
let names;
|
|
47297
47360
|
try {
|
|
47298
47361
|
names = readdirSync(record);
|
|
@@ -47303,7 +47366,7 @@ function recordNamesStore(dir) {
|
|
|
47303
47366
|
if (!name.endsWith(OWNER_FILE))
|
|
47304
47367
|
continue;
|
|
47305
47368
|
try {
|
|
47306
|
-
const parsed = parseOwner(readFileSync2(
|
|
47369
|
+
const parsed = parseOwner(readFileSync2(join7(record, name), "utf-8"));
|
|
47307
47370
|
if (parsed === undefined)
|
|
47308
47371
|
return true;
|
|
47309
47372
|
statSync(parsed.owner.store);
|
|
@@ -47316,7 +47379,7 @@ function recordNamesStore(dir) {
|
|
|
47316
47379
|
return false;
|
|
47317
47380
|
}
|
|
47318
47381
|
function askgateState(dir, now = Date.now()) {
|
|
47319
|
-
const record =
|
|
47382
|
+
const record = join7(dir, ASKGATE_RECORD);
|
|
47320
47383
|
let names;
|
|
47321
47384
|
try {
|
|
47322
47385
|
names = readdirSync(record);
|
|
@@ -47329,7 +47392,7 @@ function askgateState(dir, now = Date.now()) {
|
|
|
47329
47392
|
for (const name of names) {
|
|
47330
47393
|
if (!name.endsWith(OWNER_FILE))
|
|
47331
47394
|
continue;
|
|
47332
|
-
const file =
|
|
47395
|
+
const file = join7(record, name);
|
|
47333
47396
|
let text;
|
|
47334
47397
|
try {
|
|
47335
47398
|
text = readFileSync2(file, "utf-8");
|
|
@@ -47349,7 +47412,7 @@ function askgateState(dir, now = Date.now()) {
|
|
|
47349
47412
|
return { kind: "off" };
|
|
47350
47413
|
for (const { file, store } of live) {
|
|
47351
47414
|
try {
|
|
47352
|
-
if (!statSync(
|
|
47415
|
+
if (!statSync(join7(store, MARKERS)).isDirectory())
|
|
47353
47416
|
throw new Error("not a directory");
|
|
47354
47417
|
} catch (error) {
|
|
47355
47418
|
return {
|
|
@@ -47401,11 +47464,11 @@ function consumeMarker(stores, argv, args, files, now) {
|
|
|
47401
47464
|
let expired = false;
|
|
47402
47465
|
const usable = [];
|
|
47403
47466
|
for (const store of stores) {
|
|
47404
|
-
const dir =
|
|
47467
|
+
const dir = join7(store, MARKERS);
|
|
47405
47468
|
for (const name of readdirSync(dir)) {
|
|
47406
47469
|
if (!name.startsWith(`${key}.`))
|
|
47407
47470
|
continue;
|
|
47408
|
-
const file =
|
|
47471
|
+
const file = join7(dir, name);
|
|
47409
47472
|
const marker = readMarker(file);
|
|
47410
47473
|
if (marker === undefined || marker.argv !== key)
|
|
47411
47474
|
continue;
|
|
@@ -51765,6 +51828,7 @@ var issueFreeTools = {
|
|
|
51765
51828
|
dispatch_answers: true,
|
|
51766
51829
|
dispatch_whoami: true,
|
|
51767
51830
|
dispatch_limits: true,
|
|
51831
|
+
dispatch_api: true,
|
|
51768
51832
|
dispatch_inbox: true,
|
|
51769
51833
|
dispatch_send_to_agent: true,
|
|
51770
51834
|
dispatch_architecture_sync: true
|
|
@@ -53037,9 +53101,9 @@ function advancesLine(issue) {
|
|
|
53037
53101
|
return "Advances: unknown (this Dispatch server predates priorities; upgrade it)";
|
|
53038
53102
|
}
|
|
53039
53103
|
const advances = issue.advances ?? [];
|
|
53040
|
-
|
|
53041
|
-
|
|
53042
|
-
return `Advances: ${
|
|
53104
|
+
const set = advances.length === 0 ? "no priority" : advances.map(advanceText).join(", ");
|
|
53105
|
+
const revision = issue.advances_revision === undefined ? "" : `; revision ${issue.advances_revision}`;
|
|
53106
|
+
return `Advances: ${set}${revision}`;
|
|
53043
53107
|
}
|
|
53044
53108
|
function claimText(claim, agents, read = {}) {
|
|
53045
53109
|
const titles = agents?.titles;
|
|
@@ -53713,11 +53777,16 @@ function refuseUnsavedRepository(verb, issue, repo) {
|
|
|
53713
53777
|
const lost = repo === "" ? "the repository was not cleared" : `${repo} was not saved`;
|
|
53714
53778
|
throw new Error(`Dispatch ${verb} ${issue.key} without its repository: this Dispatch server predates repository fields, so ${lost}; upgrade the server`);
|
|
53715
53779
|
}
|
|
53716
|
-
function
|
|
53717
|
-
if (issue.advances_revision
|
|
53718
|
-
|
|
53719
|
-
}
|
|
53720
|
-
|
|
53780
|
+
function refuseServerWithoutAdvances(issue) {
|
|
53781
|
+
if (issue.advances_revision !== undefined)
|
|
53782
|
+
return;
|
|
53783
|
+
throw new Error(`Dispatch read ${issue.key} without its advances: this Dispatch server predates priorities, so nothing was sent; upgrade the server`);
|
|
53784
|
+
}
|
|
53785
|
+
function advancesRevisionAnswer(issueKey, error) {
|
|
53786
|
+
if (!dispatchAnswered(error, 409) || error.code !== "ADVANCES_REVISION")
|
|
53787
|
+
return "";
|
|
53788
|
+
const held = /(\d+)\D*$/.exec(error.message)?.[1] ?? "<the revision named above>";
|
|
53789
|
+
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}`;
|
|
53721
53790
|
}
|
|
53722
53791
|
async function issueCommand(context) {
|
|
53723
53792
|
const { args, client, actor, input, linkBase } = context;
|
|
@@ -53828,7 +53897,9 @@ async function issueUpdateCommand(context) {
|
|
|
53828
53897
|
} catch (error) {
|
|
53829
53898
|
throw refusalWithCode(error);
|
|
53830
53899
|
}
|
|
53831
|
-
|
|
53900
|
+
if (advances !== undefined)
|
|
53901
|
+
refuseServerWithoutAdvances(before);
|
|
53902
|
+
const advancesWrite = advances === undefined ? undefined : { advances, ...defined("advances_revision", advancesRevision) };
|
|
53832
53903
|
if (status === "done" && typeof before.closed_at === "string") {
|
|
53833
53904
|
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`);
|
|
53834
53905
|
}
|
|
@@ -53886,15 +53957,17 @@ async function issueUpdateCommand(context) {
|
|
|
53886
53957
|
throw error;
|
|
53887
53958
|
const answered = error instanceof DispatchWriteUnsettledError ? error.last : error;
|
|
53888
53959
|
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)` : "";
|
|
53960
|
+
const revisionClause = advancesRevisionAnswer(issueKey, error);
|
|
53889
53961
|
if (closingNote === undefined) {
|
|
53890
53962
|
if (taken !== "" && !(error instanceof DispatchServiceError)) {
|
|
53891
53963
|
throw withAccount(error, taken);
|
|
53892
53964
|
}
|
|
53893
|
-
throw refusalWithCode(error, taken);
|
|
53965
|
+
throw refusalWithCode(error, taken, revisionClause);
|
|
53894
53966
|
}
|
|
53895
53967
|
const landed = closeAccount(error, closingNote);
|
|
53896
|
-
if (error instanceof DispatchServiceError)
|
|
53897
|
-
throw refusalWithCode(error, taken, landed);
|
|
53968
|
+
if (error instanceof DispatchServiceError) {
|
|
53969
|
+
throw refusalWithCode(error, taken, revisionClause, landed);
|
|
53970
|
+
}
|
|
53898
53971
|
throw withAccount(error, [taken, landed].filter((clause) => clause !== "").join("; "));
|
|
53899
53972
|
}
|
|
53900
53973
|
refuseUnsavedRepository("updated", after, repo);
|
|
@@ -54171,6 +54244,16 @@ async function resultsCommand(context) {
|
|
|
54171
54244
|
};
|
|
54172
54245
|
}
|
|
54173
54246
|
|
|
54247
|
+
// ../envoy-client/src/dispatch-commands/api.ts
|
|
54248
|
+
async function apiCommand(context) {
|
|
54249
|
+
const path = stringArg(context.args, "path");
|
|
54250
|
+
const answer = await context.newClient().readRoute(path);
|
|
54251
|
+
return {
|
|
54252
|
+
text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
|
|
54253
|
+
details: { path }
|
|
54254
|
+
};
|
|
54255
|
+
}
|
|
54256
|
+
|
|
54174
54257
|
// ../envoy-client/src/dispatch-commands/render-item.ts
|
|
54175
54258
|
function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
|
|
54176
54259
|
const answer = ask.answer;
|
|
@@ -56003,7 +56086,7 @@ function priorityWorkLine(work) {
|
|
|
56003
56086
|
}
|
|
56004
56087
|
function priorityIssueLine(issue, agents) {
|
|
56005
56088
|
const advances = issue.advances ?? [];
|
|
56006
|
-
const moved = issue.moved_at === null ? "" : ` \xB7
|
|
56089
|
+
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)}`}`;
|
|
56007
56090
|
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}`;
|
|
56008
56091
|
}
|
|
56009
56092
|
function priorityFaultLines(heading, fault, agents) {
|
|
@@ -56019,7 +56102,7 @@ function priorityFaultLines(heading, fault, agents) {
|
|
|
56019
56102
|
}
|
|
56020
56103
|
function formatPriorities(response, agents) {
|
|
56021
56104
|
const priorities = response.priorities ?? [];
|
|
56022
|
-
const
|
|
56105
|
+
const backlog = response.priority_work_parked;
|
|
56023
56106
|
const unplaced = response.work_under_no_priority;
|
|
56024
56107
|
if (response.empty !== undefined)
|
|
56025
56108
|
return response.empty;
|
|
@@ -56032,7 +56115,7 @@ function formatPriorities(response, agents) {
|
|
|
56032
56115
|
"",
|
|
56033
56116
|
...priorityFaultLines("Work under no priority", { count: unplaced.count, issues: unplaced.issues, by: unplaced.by_project }, agents),
|
|
56034
56117
|
"",
|
|
56035
|
-
...priorityFaultLines("Priority work
|
|
56118
|
+
...priorityFaultLines("Priority work in backlog or icebox", { count: backlog.count, issues: backlog.issues, by: backlog.by_priority }, agents)
|
|
56036
56119
|
].join(`
|
|
56037
56120
|
`);
|
|
56038
56121
|
}
|
|
@@ -56418,7 +56501,7 @@ async function reviewCommand(context) {
|
|
|
56418
56501
|
|
|
56419
56502
|
// ../envoy-client/src/session-answers.ts
|
|
56420
56503
|
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
|
|
56421
|
-
import { join as
|
|
56504
|
+
import { join as join8 } from "path";
|
|
56422
56505
|
|
|
56423
56506
|
// ../envoy-client/src/json-line-record.ts
|
|
56424
56507
|
import { appendFileSync } from "fs";
|
|
@@ -56558,7 +56641,7 @@ processGlobal2[STATE_KEY] = state;
|
|
|
56558
56641
|
var CACHE_FILE = "answers.json";
|
|
56559
56642
|
function readCacheFile(directory, url) {
|
|
56560
56643
|
try {
|
|
56561
|
-
const value = JSON.parse(readFileSync3(
|
|
56644
|
+
const value = JSON.parse(readFileSync3(join8(directory, CACHE_FILE), "utf-8"));
|
|
56562
56645
|
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)) {
|
|
56563
56646
|
return {
|
|
56564
56647
|
dispatch_url: value.dispatch_url,
|
|
@@ -56679,7 +56762,7 @@ async function readSessionAnswers(options) {
|
|
|
56679
56762
|
if (directory !== undefined) {
|
|
56680
56763
|
try {
|
|
56681
56764
|
mkdirSync2(directory, { recursive: true, mode: 448 });
|
|
56682
|
-
writeAtomically(
|
|
56765
|
+
writeAtomically(join8(directory, CACHE_FILE), JSON.stringify(cache));
|
|
56683
56766
|
} catch {}
|
|
56684
56767
|
}
|
|
56685
56768
|
return { cache };
|
|
@@ -57030,6 +57113,7 @@ var dispatchCommands = {
|
|
|
57030
57113
|
dispatch_answers: onSession(answersCommand),
|
|
57031
57114
|
dispatch_whoami: onSession(whoamiCommand),
|
|
57032
57115
|
dispatch_limits: onSession(limitsCommand),
|
|
57116
|
+
dispatch_api: onSession(apiCommand),
|
|
57033
57117
|
dispatch_inbox: onSession(inboxCommand)
|
|
57034
57118
|
};
|
|
57035
57119
|
// ../envoy-client/src/dispatch-execute.ts
|
|
@@ -57078,7 +57162,7 @@ function stringList(value) {
|
|
|
57078
57162
|
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
57079
57163
|
}
|
|
57080
57164
|
function loadSessionMemory(dir, sessionId) {
|
|
57081
|
-
const path =
|
|
57165
|
+
const path = join9(dir, "state.json");
|
|
57082
57166
|
const text = readIfPresent(path);
|
|
57083
57167
|
if (text === undefined)
|
|
57084
57168
|
return new Set;
|
|
@@ -57102,7 +57186,7 @@ function writeMemory(dir, sessionId, follows) {
|
|
|
57102
57186
|
pictures: [...shownPictures(sessionId)],
|
|
57103
57187
|
follows: [...follows]
|
|
57104
57188
|
};
|
|
57105
|
-
writeAtomically(
|
|
57189
|
+
writeAtomically(join9(dir, "state.json"), `${JSON.stringify(state)}
|
|
57106
57190
|
`);
|
|
57107
57191
|
}
|
|
57108
57192
|
function appendResult(dir, entry) {
|
|
@@ -57111,7 +57195,7 @@ function appendResult(dir, entry) {
|
|
|
57111
57195
|
}
|
|
57112
57196
|
function writeResult(dir, entry) {
|
|
57113
57197
|
const line = { at: new Date().toISOString(), ...entry };
|
|
57114
|
-
appendFileSync2(
|
|
57198
|
+
appendFileSync2(join9(dir, "results.jsonl"), `${JSON.stringify(line)}
|
|
57115
57199
|
`, { mode: PRIVATE_FILE2 });
|
|
57116
57200
|
}
|
|
57117
57201
|
function recordOutcome(dir, sessionId, follows, entry) {
|
|
@@ -57122,8 +57206,8 @@ function recordOutcome(dir, sessionId, follows, entry) {
|
|
|
57122
57206
|
function writePicture(dir, image) {
|
|
57123
57207
|
const bytes = Buffer.from(image.data, "base64");
|
|
57124
57208
|
const name = createHash3("sha256").update(bytes).digest("hex").slice(0, 16);
|
|
57125
|
-
const pictures =
|
|
57126
|
-
const path =
|
|
57209
|
+
const pictures = join9(dir, "pictures");
|
|
57210
|
+
const path = join9(pictures, `${name}.${PICTURE_EXTENSIONS[image.mimeType]}`);
|
|
57127
57211
|
ensureDirectory(pictures);
|
|
57128
57212
|
try {
|
|
57129
57213
|
writeFileSync3(path, bytes, { mode: PRIVATE_FILE2, flag: "wx" });
|
|
@@ -57134,21 +57218,21 @@ function writePicture(dir, image) {
|
|
|
57134
57218
|
return { path, bytes: bytes.length };
|
|
57135
57219
|
}
|
|
57136
57220
|
function writeLongOutput(dir, text) {
|
|
57137
|
-
const out =
|
|
57221
|
+
const out = join9(dir, "out");
|
|
57138
57222
|
ensureDirectory(out);
|
|
57139
|
-
const path =
|
|
57223
|
+
const path = join9(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
|
|
57140
57224
|
writeFileSync3(path, text, { mode: PRIVATE_FILE2 });
|
|
57141
57225
|
return path;
|
|
57142
57226
|
}
|
|
57143
57227
|
function writeSessionTitle(dir, title) {
|
|
57144
57228
|
ensureDirectory(dir);
|
|
57145
|
-
writeAtomically(
|
|
57229
|
+
writeAtomically(join9(dir, "title"), title);
|
|
57146
57230
|
}
|
|
57147
57231
|
function readSessionTitle(dir) {
|
|
57148
|
-
return readIfPresent(
|
|
57232
|
+
return readIfPresent(join9(dir, "title")) || undefined;
|
|
57149
57233
|
}
|
|
57150
57234
|
function pruneSessions(root, now) {
|
|
57151
|
-
const stamp =
|
|
57235
|
+
const stamp = join9(root, PRUNED_STAMP);
|
|
57152
57236
|
try {
|
|
57153
57237
|
if (now - statSync2(stamp).mtimeMs < PRUNE_INTERVAL_MS)
|
|
57154
57238
|
return;
|
|
@@ -57156,7 +57240,7 @@ function pruneSessions(root, now) {
|
|
|
57156
57240
|
if (!hasErrnoCode(error, "ENOENT"))
|
|
57157
57241
|
throw error;
|
|
57158
57242
|
}
|
|
57159
|
-
const sessions =
|
|
57243
|
+
const sessions = join9(root, "sessions");
|
|
57160
57244
|
let entries = [];
|
|
57161
57245
|
try {
|
|
57162
57246
|
entries = readdirSync2(sessions, { withFileTypes: true });
|
|
@@ -57167,7 +57251,7 @@ function pruneSessions(root, now) {
|
|
|
57167
57251
|
for (const entry of entries) {
|
|
57168
57252
|
if (!entry.isDirectory())
|
|
57169
57253
|
continue;
|
|
57170
|
-
const dir =
|
|
57254
|
+
const dir = join9(sessions, entry.name);
|
|
57171
57255
|
try {
|
|
57172
57256
|
const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
|
|
57173
57257
|
if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {
|
|
@@ -63423,9 +63507,9 @@ var import_nats5 = __toESM(require_mod4(), 1);
|
|
|
63423
63507
|
|
|
63424
63508
|
// package.json
|
|
63425
63509
|
var name2 = "@sjawhar/claude-envoy";
|
|
63426
|
-
var version2 = "5.
|
|
63510
|
+
var version2 = "5.29.0";
|
|
63427
63511
|
var legion = {
|
|
63428
|
-
daemonApiVersion:
|
|
63512
|
+
daemonApiVersion: 275
|
|
63429
63513
|
};
|
|
63430
63514
|
var package_default = {
|
|
63431
63515
|
name: name2,
|
|
@@ -64623,13 +64707,13 @@ function createChannelTopics(connection, options = {}) {
|
|
|
64623
64707
|
}
|
|
64624
64708
|
|
|
64625
64709
|
// src/session-identity.ts
|
|
64626
|
-
import { readFile as
|
|
64627
|
-
import { basename as basename3, join as
|
|
64710
|
+
import { readFile as readFile7 } from "fs/promises";
|
|
64711
|
+
import { basename as basename3, join as join11 } from "path";
|
|
64628
64712
|
|
|
64629
64713
|
// src/session-state.ts
|
|
64630
64714
|
import { readFileSync as readFileSync6 } from "fs";
|
|
64631
64715
|
import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
|
|
64632
|
-
import { dirname as dirname4, join as
|
|
64716
|
+
import { dirname as dirname4, join as join10 } from "path";
|
|
64633
64717
|
async function writeAtomicStateFile(file, contents) {
|
|
64634
64718
|
await mkdir2(dirname4(file), { recursive: true, mode: 448 });
|
|
64635
64719
|
const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
@@ -64647,7 +64731,7 @@ async function pruneStateDirectory(directory, isStale) {
|
|
|
64647
64731
|
throw error;
|
|
64648
64732
|
});
|
|
64649
64733
|
for (const entry of entries) {
|
|
64650
|
-
const file =
|
|
64734
|
+
const file = join10(directory, entry);
|
|
64651
64735
|
if (!await isStale(file))
|
|
64652
64736
|
continue;
|
|
64653
64737
|
await rm4(file, { recursive: true, force: true });
|
|
@@ -64662,7 +64746,7 @@ async function writtenLongAgo(file) {
|
|
|
64662
64746
|
}
|
|
64663
64747
|
var TITLES_DIRECTORY = "titles";
|
|
64664
64748
|
function sessionTitleFile(stateDirectory, sessionId) {
|
|
64665
|
-
return
|
|
64749
|
+
return join10(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
|
|
64666
64750
|
}
|
|
64667
64751
|
async function writeChosenTitle(file, title) {
|
|
64668
64752
|
await writeAtomicStateFile(file, `${title}
|
|
@@ -64690,7 +64774,7 @@ async function recordChosenTitle(sessionId, title) {
|
|
|
64690
64774
|
await writeChosenTitle(file, chosen);
|
|
64691
64775
|
}
|
|
64692
64776
|
async function pruneStaleSessionTitles(stateDirectory) {
|
|
64693
|
-
await pruneStateDirectory(
|
|
64777
|
+
await pruneStateDirectory(join10(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
|
|
64694
64778
|
}
|
|
64695
64779
|
|
|
64696
64780
|
// src/session-identity.ts
|
|
@@ -64715,14 +64799,14 @@ class SessionIdentity {
|
|
|
64715
64799
|
}
|
|
64716
64800
|
}
|
|
64717
64801
|
function sessionHandoffDirectory(stateDirectory, claudePid) {
|
|
64718
|
-
return
|
|
64802
|
+
return join11(stateDirectory, "sessions", String(claudePid));
|
|
64719
64803
|
}
|
|
64720
64804
|
function sessionHandoffFile(stateDirectory, claudePid) {
|
|
64721
|
-
return
|
|
64805
|
+
return join11(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
|
|
64722
64806
|
}
|
|
64723
64807
|
var ROLES_DIRECTORY = "roles";
|
|
64724
64808
|
function roleStateFile(stateDirectory, sessionId) {
|
|
64725
|
-
return
|
|
64809
|
+
return join11(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
|
|
64726
64810
|
}
|
|
64727
64811
|
|
|
64728
64812
|
class UnparseableRoleRecordError extends Error {
|
|
@@ -64734,7 +64818,7 @@ class UnparseableRoleRecordError extends Error {
|
|
|
64734
64818
|
async function readPersistedRole(roleFile) {
|
|
64735
64819
|
let bytes;
|
|
64736
64820
|
try {
|
|
64737
|
-
bytes = await
|
|
64821
|
+
bytes = await readFile7(roleFile, "utf8");
|
|
64738
64822
|
} catch (error) {
|
|
64739
64823
|
if (hasErrnoCode(error, "ENOENT"))
|
|
64740
64824
|
return;
|
|
@@ -64756,7 +64840,7 @@ async function writeSessionHandoff(file, sessionId) {
|
|
|
64756
64840
|
}
|
|
64757
64841
|
async function readSessionHandoff(file) {
|
|
64758
64842
|
try {
|
|
64759
|
-
const id = (await
|
|
64843
|
+
const id = (await readFile7(file, "utf8")).trim();
|
|
64760
64844
|
return id.length === 0 ? undefined : id;
|
|
64761
64845
|
} catch (error) {
|
|
64762
64846
|
if (hasErrnoCode(error, "ENOENT"))
|
|
@@ -64773,14 +64857,14 @@ function processExists(pid) {
|
|
|
64773
64857
|
}
|
|
64774
64858
|
}
|
|
64775
64859
|
async function pruneStaleSessionHandoffs(stateDirectory) {
|
|
64776
|
-
await pruneStateDirectory(
|
|
64860
|
+
await pruneStateDirectory(join11(stateDirectory, "sessions"), (file) => {
|
|
64777
64861
|
const pid = basename3(file);
|
|
64778
64862
|
return /^\d+$/.test(pid) && !processExists(Number(pid));
|
|
64779
64863
|
});
|
|
64780
64864
|
}
|
|
64781
64865
|
async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
|
|
64782
64866
|
const own = roleStateFile(stateDirectory, currentSessionId);
|
|
64783
|
-
await pruneStateDirectory(
|
|
64867
|
+
await pruneStateDirectory(join11(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
|
|
64784
64868
|
}
|
|
64785
64869
|
|
|
64786
64870
|
// src/envoy-off.ts
|
|
@@ -64838,7 +64922,7 @@ async function serveEnvoyOff(serverInfo, refusal) {
|
|
|
64838
64922
|
}
|
|
64839
64923
|
|
|
64840
64924
|
// src/installed-build.ts
|
|
64841
|
-
import { dirname as dirname5, join as
|
|
64925
|
+
import { dirname as dirname5, join as join12, sep } from "path";
|
|
64842
64926
|
function pluginCacheSegments(bundlePath) {
|
|
64843
64927
|
const parts = bundlePath.split(sep);
|
|
64844
64928
|
for (let index = 0;index + 1 < parts.length; index++) {
|
|
@@ -64852,12 +64936,12 @@ function installedPluginVersion(bundlePath) {
|
|
|
64852
64936
|
}
|
|
64853
64937
|
function channelConnectionName(name, bundlePath, packageName) {
|
|
64854
64938
|
const version = installedPluginVersion(bundlePath);
|
|
64855
|
-
return clientConnectionName(name, clientBuild(
|
|
64939
|
+
return clientConnectionName(name, clientBuild(join12(dirname5(bundlePath), "build-commit"), version === undefined ? undefined : { name: packageName, version }));
|
|
64856
64940
|
}
|
|
64857
64941
|
|
|
64858
64942
|
// src/legion-claim.ts
|
|
64859
64943
|
import { readdir as readdir4, stat as stat5 } from "fs/promises";
|
|
64860
|
-
import { join as
|
|
64944
|
+
import { join as join14 } from "path";
|
|
64861
64945
|
import { setTimeout as delay2 } from "timers/promises";
|
|
64862
64946
|
|
|
64863
64947
|
// ../pi-shared/src/stall-limits.ts
|
|
@@ -65315,6 +65399,12 @@ var legionControllerLocator = object({
|
|
|
65315
65399
|
var legionAgentSecretsLoginView = object({
|
|
65316
65400
|
state: string2().optional()
|
|
65317
65401
|
});
|
|
65402
|
+
var legionDispatchCredentialView = object({
|
|
65403
|
+
session: nonEmptyString2.optional(),
|
|
65404
|
+
transitionLaunches: number2().int().nonnegative().optional(),
|
|
65405
|
+
lastTransitionLaunchAt: timestamp.nullable().optional(),
|
|
65406
|
+
liveLaunchesWithDispatchToken: number2().int().nonnegative().optional()
|
|
65407
|
+
});
|
|
65318
65408
|
var legionCapabilityState = object({
|
|
65319
65409
|
name: nonEmptyString2.optional(),
|
|
65320
65410
|
status: _enum2(["present", "unchecked", "withheld", "decided", "open"]).optional(),
|
|
@@ -65449,6 +65539,7 @@ var LegionStateResponse = object({
|
|
|
65449
65539
|
lastPause: legionEndedPause.optional(),
|
|
65450
65540
|
controllerLocator: legionControllerLocator.optional(),
|
|
65451
65541
|
agentSecretsLogin: legionAgentSecretsLoginView.optional(),
|
|
65542
|
+
dispatchCredential: legionDispatchCredentialView.optional(),
|
|
65452
65543
|
capabilities: array(legionCapabilityState).optional(),
|
|
65453
65544
|
repositories: legionRepositories.optional(),
|
|
65454
65545
|
settings: legionSettings.optional(),
|
|
@@ -66344,7 +66435,7 @@ function listenerAskedToClaimAgain(error) {
|
|
|
66344
66435
|
// src/legion-phase-hook.ts
|
|
66345
66436
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
66346
66437
|
import { readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
66347
|
-
import { dirname as dirname6, join as
|
|
66438
|
+
import { dirname as dirname6, join as join13 } from "path";
|
|
66348
66439
|
|
|
66349
66440
|
// ../pi-shared/src/phase-reminder.ts
|
|
66350
66441
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
@@ -66809,7 +66900,7 @@ function phaseHookToolDefinition() {
|
|
|
66809
66900
|
};
|
|
66810
66901
|
}
|
|
66811
66902
|
function phaseStallFile(configDir, sessionID) {
|
|
66812
|
-
return
|
|
66903
|
+
return join13(configDir, `legion-phase-stall-${sessionID}.json`);
|
|
66813
66904
|
}
|
|
66814
66905
|
function paneReminderLog(write) {
|
|
66815
66906
|
const line = (level, message, context) => {
|
|
@@ -66862,7 +66953,7 @@ function readPhaseStallRecord(file, log) {
|
|
|
66862
66953
|
};
|
|
66863
66954
|
}
|
|
66864
66955
|
function writePhaseStallRecord(file, entry, recreatedNoticeSent, log) {
|
|
66865
|
-
const temporary =
|
|
66956
|
+
const temporary = join13(dirname6(file), `.legion-phase-stall-${randomUUID7()}`);
|
|
66866
66957
|
try {
|
|
66867
66958
|
writeFileSync4(temporary, JSON.stringify({ ...entry, ...recreatedNoticeSent ? { recreatedNoticeSent } : {} }), { mode: 384 });
|
|
66868
66959
|
renameSync3(temporary, file);
|
|
@@ -67070,12 +67161,12 @@ function stopPane(why) {
|
|
|
67070
67161
|
endPane();
|
|
67071
67162
|
}
|
|
67072
67163
|
async function waitForTranscript(configDir, sessionID, signal, pollMs = 100) {
|
|
67073
|
-
const projects =
|
|
67164
|
+
const projects = join14(configDir, "projects");
|
|
67074
67165
|
const name = `${sessionID}.jsonl`;
|
|
67075
67166
|
for (;; ) {
|
|
67076
67167
|
signal.throwIfAborted();
|
|
67077
67168
|
for (const directory of await readdir4(projects).catch(() => [])) {
|
|
67078
|
-
const file =
|
|
67169
|
+
const file = join14(projects, directory, name);
|
|
67079
67170
|
if (await isFile(file))
|
|
67080
67171
|
return file;
|
|
67081
67172
|
}
|
|
@@ -68275,14 +68366,14 @@ function modSession(options) {
|
|
|
68275
68366
|
}
|
|
68276
68367
|
|
|
68277
68368
|
// src/replay-state.ts
|
|
68278
|
-
import { join as
|
|
68369
|
+
import { join as join15 } from "path";
|
|
68279
68370
|
|
|
68280
68371
|
// src/state-file.ts
|
|
68281
|
-
import { readFile as
|
|
68372
|
+
import { readFile as readFile8 } from "fs/promises";
|
|
68282
68373
|
async function readStateFile(file, schema, empty, refusal) {
|
|
68283
68374
|
let text;
|
|
68284
68375
|
try {
|
|
68285
|
-
text = await
|
|
68376
|
+
text = await readFile8(file, "utf8");
|
|
68286
68377
|
} catch (error) {
|
|
68287
68378
|
if (hasErrnoCode(error, "ENOENT"))
|
|
68288
68379
|
return empty;
|
|
@@ -68305,7 +68396,7 @@ var ReplayStateFileSchema = LedgerSnapshotSchema.extend({
|
|
|
68305
68396
|
consumer: ConsumerDeliverySnapshotSchema.optional()
|
|
68306
68397
|
});
|
|
68307
68398
|
function replayStateFile(stateDirectory, sessionId) {
|
|
68308
|
-
return
|
|
68399
|
+
return join15(stateDirectory, `replay-${encodeURIComponent(sessionId)}.json`);
|
|
68309
68400
|
}
|
|
68310
68401
|
async function readReplayState(file) {
|
|
68311
68402
|
return await readStateFile(file, ReplayStateFileSchema, { ledger: [] }, "holds no delivery state");
|
|
@@ -68853,7 +68944,7 @@ function createUserTurnRouter(options) {
|
|
|
68853
68944
|
}
|
|
68854
68945
|
|
|
68855
68946
|
// src/user-turn-state.ts
|
|
68856
|
-
import { join as
|
|
68947
|
+
import { join as join16 } from "path";
|
|
68857
68948
|
var TURNS_DIRECTORY = "turns";
|
|
68858
68949
|
var HANDLED_ATTEMPTS_MAX = 1000;
|
|
68859
68950
|
var DELIVERED_ROWS_MAX = 1000;
|
|
@@ -68863,7 +68954,7 @@ var UserTurnStateSchema = object({
|
|
|
68863
68954
|
rows: array(DeliveredRowSchema).default([])
|
|
68864
68955
|
});
|
|
68865
68956
|
function userTurnStateFile(stateDirectory, sessionId) {
|
|
68866
|
-
return
|
|
68957
|
+
return join16(stateDirectory, TURNS_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
|
|
68867
68958
|
}
|
|
68868
68959
|
async function readUserTurnState(file) {
|
|
68869
68960
|
return await readStateFile(file, UserTurnStateSchema, { handled: [], rows: [] }, "holds no record of this session's turns");
|
|
@@ -68901,7 +68992,7 @@ function userTurnState(file, restored) {
|
|
|
68901
68992
|
};
|
|
68902
68993
|
}
|
|
68903
68994
|
async function pruneStaleSessionTurns(stateDirectory) {
|
|
68904
|
-
await pruneStateDirectory(
|
|
68995
|
+
await pruneStateDirectory(join16(stateDirectory, TURNS_DIRECTORY), writtenLongAgo);
|
|
68905
68996
|
}
|
|
68906
68997
|
|
|
68907
68998
|
// src/envoy-channel-server.ts
|
|
@@ -68975,6 +69066,13 @@ async function postDispatchReply(identity, configFile, delivery, result) {
|
|
|
68975
69066
|
throw new Error(config.error ?? config.notice);
|
|
68976
69067
|
await postDeliveryReply(config, identity.id, delivery, result);
|
|
68977
69068
|
}
|
|
69069
|
+
async function userTurnDispatchClient(identity, configFile, ms) {
|
|
69070
|
+
const active = activeDispatchSettings((await sessionDispatchSettings(configFile, process.env, {
|
|
69071
|
+
cwd: identity.directory,
|
|
69072
|
+
session: () => identity.id
|
|
69073
|
+
})).dispatch);
|
|
69074
|
+
return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, { deadlineMs: ms });
|
|
69075
|
+
}
|
|
68978
69076
|
function createChannelDelivery(input) {
|
|
68979
69077
|
const inbox = [];
|
|
68980
69078
|
let tail = Promise.resolve();
|
|
@@ -70314,12 +70412,7 @@ async function runEnvoyChannelServer() {
|
|
|
70314
70412
|
});
|
|
70315
70413
|
const router = (state) => {
|
|
70316
70414
|
const options = {
|
|
70317
|
-
dispatch:
|
|
70318
|
-
const active = activeDispatchSettings((await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch);
|
|
70319
|
-
return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, {
|
|
70320
|
-
deadlineMs: ms
|
|
70321
|
-
});
|
|
70322
|
-
},
|
|
70415
|
+
dispatch: (ms) => userTurnDispatchClient(identity, configFile, ms),
|
|
70323
70416
|
effortPicked: (effort) => agentStream?.pickedEffort(effort),
|
|
70324
70417
|
refreshSettings: () => agentStream?.refresh(),
|
|
70325
70418
|
reply: (delivery, result) => postDispatchReply(identity, configFile, delivery, result),
|
|
@@ -70634,7 +70727,7 @@ function startCodexAgentStream(options) {
|
|
|
70634
70727
|
import { spawn } from "child_process";
|
|
70635
70728
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
70636
70729
|
import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
|
|
70637
|
-
import { join as
|
|
70730
|
+
import { join as join17 } from "path";
|
|
70638
70731
|
var QUEUE_TIMEOUT_MS = 30000;
|
|
70639
70732
|
function codexProcessEnv(pid, fallback, read = (path) => readFileSync9(path, "utf8")) {
|
|
70640
70733
|
let raw;
|
|
@@ -70703,7 +70796,7 @@ function fitArgument(text, spillDirectory) {
|
|
|
70703
70796
|
throw new Error(`the message is ${Buffer.byteLength(text)} bytes, over what codex queue takes`);
|
|
70704
70797
|
}
|
|
70705
70798
|
mkdirSync4(spillDirectory, { mode: 448, recursive: true });
|
|
70706
|
-
const file =
|
|
70799
|
+
const file = join17(spillDirectory, `${Date.now()}-${randomBytes2(4).toString("hex")}.txt`);
|
|
70707
70800
|
writeFileSync5(file, text, { mode: 384 });
|
|
70708
70801
|
return `${text.slice(0, QUEUE_HEAD_CHARS)}
|
|
70709
70802
|
|
|
@@ -70828,11 +70921,11 @@ function askSideQuestion(command, threadId, question, timeoutMs = SIDE_QUESTION_
|
|
|
70828
70921
|
|
|
70829
70922
|
// src/codex/codex-inbox.ts
|
|
70830
70923
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
70831
|
-
import { mkdir as mkdir4, readdir as readdir5, readFile as
|
|
70832
|
-
import { join as
|
|
70924
|
+
import { mkdir as mkdir4, readdir as readdir5, readFile as readFile9, rename as rename4, rm as rm6, writeFile as writeFile2 } from "fs/promises";
|
|
70925
|
+
import { join as join18 } from "path";
|
|
70833
70926
|
var TAKEN_DIRECTORY = { hook: "taken", server: "queued" };
|
|
70834
70927
|
function codexInboxDirectory(stateDirectory, sessionId) {
|
|
70835
|
-
return
|
|
70928
|
+
return join18(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
|
|
70836
70929
|
}
|
|
70837
70930
|
var lastOrder = 0;
|
|
70838
70931
|
function inboxItemName() {
|
|
@@ -70841,17 +70934,17 @@ function inboxItemName() {
|
|
|
70841
70934
|
return `${String(order).padStart(15, "0")}-${randomBytes3(4).toString("hex")}.json`;
|
|
70842
70935
|
}
|
|
70843
70936
|
async function putInbox(directory, item, name = inboxItemName()) {
|
|
70844
|
-
const waiting =
|
|
70937
|
+
const waiting = join18(directory, "waiting");
|
|
70845
70938
|
await mkdir4(waiting, { recursive: true, mode: 448 });
|
|
70846
|
-
const temporary =
|
|
70939
|
+
const temporary = join18(directory, `.${name}.tmp`);
|
|
70847
70940
|
await writeFile2(temporary, JSON.stringify(item), { mode: 384 });
|
|
70848
|
-
await rename4(temporary,
|
|
70941
|
+
await rename4(temporary, join18(waiting, name));
|
|
70849
70942
|
return name;
|
|
70850
70943
|
}
|
|
70851
70944
|
async function takenBy(directory, name) {
|
|
70852
70945
|
for (const taker of ["hook", "server"]) {
|
|
70853
70946
|
try {
|
|
70854
|
-
await
|
|
70947
|
+
await readFile9(join18(directory, TAKEN_DIRECTORY[taker], name));
|
|
70855
70948
|
return taker;
|
|
70856
70949
|
} catch {}
|
|
70857
70950
|
}
|
|
@@ -70859,14 +70952,14 @@ async function takenBy(directory, name) {
|
|
|
70859
70952
|
}
|
|
70860
70953
|
async function withdrawWaiting(directory, name) {
|
|
70861
70954
|
try {
|
|
70862
|
-
await rm6(
|
|
70955
|
+
await rm6(join18(directory, "waiting", name));
|
|
70863
70956
|
return true;
|
|
70864
70957
|
} catch {
|
|
70865
70958
|
return false;
|
|
70866
70959
|
}
|
|
70867
70960
|
}
|
|
70868
70961
|
async function discardWaiting(directory, keep = () => false) {
|
|
70869
|
-
const waiting =
|
|
70962
|
+
const waiting = join18(directory, "waiting");
|
|
70870
70963
|
let names;
|
|
70871
70964
|
try {
|
|
70872
70965
|
names = await readdir5(waiting);
|
|
@@ -70878,7 +70971,7 @@ async function discardWaiting(directory, keep = () => false) {
|
|
|
70878
70971
|
if (!name.endsWith(".json") || keep(name))
|
|
70879
70972
|
continue;
|
|
70880
70973
|
try {
|
|
70881
|
-
await rm6(
|
|
70974
|
+
await rm6(join18(waiting, name));
|
|
70882
70975
|
removed++;
|
|
70883
70976
|
} catch {}
|
|
70884
70977
|
}
|
|
@@ -70886,7 +70979,7 @@ async function discardWaiting(directory, keep = () => false) {
|
|
|
70886
70979
|
}
|
|
70887
70980
|
var HOOK_CONTEXT_MAX_BYTES = 8000;
|
|
70888
70981
|
async function takeInbox(directory, taker, maxContextBytes) {
|
|
70889
|
-
const waiting =
|
|
70982
|
+
const waiting = join18(directory, "waiting");
|
|
70890
70983
|
let names;
|
|
70891
70984
|
try {
|
|
70892
70985
|
names = (await readdir5(waiting)).filter((name) => name.endsWith(".json")).sort();
|
|
@@ -70895,14 +70988,14 @@ async function takeInbox(directory, taker, maxContextBytes) {
|
|
|
70895
70988
|
}
|
|
70896
70989
|
if (names.length === 0)
|
|
70897
70990
|
return [];
|
|
70898
|
-
const destination =
|
|
70991
|
+
const destination = join18(directory, TAKEN_DIRECTORY[taker]);
|
|
70899
70992
|
await mkdir4(destination, { recursive: true, mode: 448 });
|
|
70900
70993
|
const taken = [];
|
|
70901
70994
|
for (const name of names) {
|
|
70902
70995
|
if (maxContextBytes !== undefined) {
|
|
70903
70996
|
let waitingItem;
|
|
70904
70997
|
try {
|
|
70905
|
-
waitingItem = JSON.parse(await
|
|
70998
|
+
waitingItem = JSON.parse(await readFile9(join18(waiting, name), "utf8"));
|
|
70906
70999
|
} catch {
|
|
70907
71000
|
continue;
|
|
70908
71001
|
}
|
|
@@ -70913,12 +71006,12 @@ async function takeInbox(directory, taker, maxContextBytes) {
|
|
|
70913
71006
|
break;
|
|
70914
71007
|
}
|
|
70915
71008
|
try {
|
|
70916
|
-
await rename4(
|
|
71009
|
+
await rename4(join18(waiting, name), join18(destination, name));
|
|
70917
71010
|
} catch {
|
|
70918
71011
|
continue;
|
|
70919
71012
|
}
|
|
70920
71013
|
try {
|
|
70921
|
-
const parsed = JSON.parse(await
|
|
71014
|
+
const parsed = JSON.parse(await readFile9(join18(destination, name), "utf8"));
|
|
70922
71015
|
if (typeof parsed === "object" && parsed !== null && typeof parsed.content === "string") {
|
|
70923
71016
|
taken.push({ item: parsed, name });
|
|
70924
71017
|
}
|
|
@@ -71075,15 +71168,15 @@ function createCodexDelivery(options) {
|
|
|
71075
71168
|
}
|
|
71076
71169
|
|
|
71077
71170
|
// src/codex/codex-owner.ts
|
|
71078
|
-
import { link as link2, mkdir as mkdir6, readdir as readdir6, readFile as
|
|
71079
|
-
import { join as
|
|
71171
|
+
import { link as link2, mkdir as mkdir6, readdir as readdir6, readFile as readFile11, rm as rm7, stat as stat7, writeFile as writeFile4 } from "fs/promises";
|
|
71172
|
+
import { join as join20 } from "path";
|
|
71080
71173
|
|
|
71081
71174
|
// src/codex/codex-session-record.ts
|
|
71082
71175
|
import { spawnSync } from "child_process";
|
|
71083
71176
|
import { readFileSync as readFileSync10, readlinkSync as readlinkSync2, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
|
|
71084
|
-
import { mkdir as mkdir5, readFile as
|
|
71177
|
+
import { mkdir as mkdir5, readFile as readFile10, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
71085
71178
|
import { homedir as homedir3 } from "os";
|
|
71086
|
-
import { basename as basename5, dirname as dirname8, join as
|
|
71179
|
+
import { basename as basename5, dirname as dirname8, join as join19 } from "path";
|
|
71087
71180
|
var CodexSessionRecord = object({
|
|
71088
71181
|
session_id: string2().min(1),
|
|
71089
71182
|
transcript_path: string2().nullable(),
|
|
@@ -71094,10 +71187,10 @@ var CodexSessionRecord = object({
|
|
|
71094
71187
|
codex_started: string2().nullable().default(null)
|
|
71095
71188
|
});
|
|
71096
71189
|
function codexSessionRecordFile(stateDirectory, pid) {
|
|
71097
|
-
return
|
|
71190
|
+
return join19(stateDirectory, "codex-sessions", `${pid}.json`);
|
|
71098
71191
|
}
|
|
71099
71192
|
function codexEndedFile(stateDirectory, pid, sessionId) {
|
|
71100
|
-
return
|
|
71193
|
+
return join19(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
|
|
71101
71194
|
}
|
|
71102
71195
|
async function markSessionEnded(stateDirectory, pid, sessionId) {
|
|
71103
71196
|
const marker = codexEndedFile(stateDirectory, pid, sessionId);
|
|
@@ -71120,7 +71213,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
|
|
|
71120
71213
|
}
|
|
71121
71214
|
async function sessionEnded(file) {
|
|
71122
71215
|
try {
|
|
71123
|
-
await
|
|
71216
|
+
await readFile10(file);
|
|
71124
71217
|
return true;
|
|
71125
71218
|
} catch {
|
|
71126
71219
|
return false;
|
|
@@ -71134,7 +71227,7 @@ async function writeCodexSessionRecord(file, value) {
|
|
|
71134
71227
|
}
|
|
71135
71228
|
async function readCodexSessionRecord(file) {
|
|
71136
71229
|
try {
|
|
71137
|
-
const parsed = CodexSessionRecord.safeParse(JSON.parse(await
|
|
71230
|
+
const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile10(file, "utf8")));
|
|
71138
71231
|
return parsed.success ? parsed.data : undefined;
|
|
71139
71232
|
} catch {
|
|
71140
71233
|
return;
|
|
@@ -71142,7 +71235,7 @@ async function readCodexSessionRecord(file) {
|
|
|
71142
71235
|
}
|
|
71143
71236
|
function codexHome(env) {
|
|
71144
71237
|
const set = env["CODEX_HOME"];
|
|
71145
|
-
return set !== undefined && set !== "" ? set :
|
|
71238
|
+
return set !== undefined && set !== "" ? set : join19(env["HOME"] || homedir3(), ".codex");
|
|
71146
71239
|
}
|
|
71147
71240
|
function codexPluginDataDirectory(pluginRoot) {
|
|
71148
71241
|
const version = pluginRoot;
|
|
@@ -71152,7 +71245,7 @@ function codexPluginDataDirectory(pluginRoot) {
|
|
|
71152
71245
|
const plugins = dirname8(cache);
|
|
71153
71246
|
if (basename5(cache) !== "cache" || basename5(plugins) !== "plugins")
|
|
71154
71247
|
return;
|
|
71155
|
-
return
|
|
71248
|
+
return join19(plugins, "data", `${basename5(plugin)}-${basename5(marketplace)}`);
|
|
71156
71249
|
}
|
|
71157
71250
|
var MAX_ANCESTORS2 = 16;
|
|
71158
71251
|
function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
@@ -71254,11 +71347,11 @@ function codexSubcommand(args) {
|
|
|
71254
71347
|
}
|
|
71255
71348
|
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.";
|
|
71256
71349
|
async function pruneCodexSessionRecords(stateDirectory) {
|
|
71257
|
-
await pruneStateDirectory(
|
|
71350
|
+
await pruneStateDirectory(join19(stateDirectory, "codex-sessions"), (file) => {
|
|
71258
71351
|
const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename5(file));
|
|
71259
71352
|
return match !== null && !processExists(Number(match[1]));
|
|
71260
71353
|
});
|
|
71261
|
-
await pruneStateDirectory(
|
|
71354
|
+
await pruneStateDirectory(join19(stateDirectory, "codex-servers"), (file) => {
|
|
71262
71355
|
const name = basename5(file);
|
|
71263
71356
|
return /^\d+$/.test(name) && !processExists(Number(name));
|
|
71264
71357
|
});
|
|
@@ -71273,7 +71366,7 @@ function codexExecutable(pid) {
|
|
|
71273
71366
|
|
|
71274
71367
|
// src/codex/codex-owner.ts
|
|
71275
71368
|
function codexServersDirectory(stateDirectory, codexPid) {
|
|
71276
|
-
return
|
|
71369
|
+
return join20(stateDirectory, "codex-servers", String(codexPid));
|
|
71277
71370
|
}
|
|
71278
71371
|
var ENTRY_NAME = /^(\d+)\.json$/;
|
|
71279
71372
|
var TEMPORARY_NAME = /^\.\d+\.\d+\.tmp$/;
|
|
@@ -71282,13 +71375,13 @@ function entryName(entry) {
|
|
|
71282
71375
|
}
|
|
71283
71376
|
async function registerServer(directory, pid, started, list = (path) => readdir6(path)) {
|
|
71284
71377
|
await mkdir6(directory, { mode: 448, recursive: true });
|
|
71285
|
-
const temporary =
|
|
71378
|
+
const temporary = join20(directory, `.${pid}.${process.hrtime.bigint()}.tmp`);
|
|
71286
71379
|
await writeFile4(temporary, JSON.stringify({ pid, started }), { mode: 384 });
|
|
71287
71380
|
try {
|
|
71288
71381
|
let seq = Math.max(0, ...numbered(await list(directory)).map(({ seq: taken }) => taken)) + 1;
|
|
71289
71382
|
for (;; ) {
|
|
71290
71383
|
try {
|
|
71291
|
-
await place(temporary,
|
|
71384
|
+
await place(temporary, join20(directory, entryName({ seq })), pid, started);
|
|
71292
71385
|
return { pid, seq, started };
|
|
71293
71386
|
} catch (error) {
|
|
71294
71387
|
if (error.code !== "EEXIST")
|
|
@@ -71316,8 +71409,8 @@ async function place(temporary, target, pid, started) {
|
|
|
71316
71409
|
await writeFile4(target, JSON.stringify({ pid, started }), { flag: "wx", mode: 384 });
|
|
71317
71410
|
}
|
|
71318
71411
|
async function unregisterServer(directory, self2) {
|
|
71319
|
-
const file =
|
|
71320
|
-
const named = await
|
|
71412
|
+
const file = join20(directory, entryName(self2));
|
|
71413
|
+
const named = await readFile11(file, "utf8").then(serverOf, () => {
|
|
71321
71414
|
return;
|
|
71322
71415
|
});
|
|
71323
71416
|
if (named?.pid === self2.pid && named.started === self2.started)
|
|
@@ -71380,7 +71473,7 @@ async function readEntries(directory, probe, now = Date.now) {
|
|
|
71380
71473
|
for (const name of names.filter((each) => TEMPORARY_NAME.test(each))) {
|
|
71381
71474
|
let text;
|
|
71382
71475
|
try {
|
|
71383
|
-
text = await
|
|
71476
|
+
text = await readFile11(join20(directory, name), "utf8");
|
|
71384
71477
|
} catch {
|
|
71385
71478
|
publishing = true;
|
|
71386
71479
|
break;
|
|
@@ -71396,13 +71489,13 @@ async function readEntries(directory, probe, now = Date.now) {
|
|
|
71396
71489
|
for (const { name, seq } of numbered(names)) {
|
|
71397
71490
|
let text;
|
|
71398
71491
|
try {
|
|
71399
|
-
text = await
|
|
71492
|
+
text = await readFile11(join20(directory, name), "utf8");
|
|
71400
71493
|
} catch {
|
|
71401
71494
|
continue;
|
|
71402
71495
|
}
|
|
71403
71496
|
const server = serverOf(text);
|
|
71404
71497
|
if (server === undefined) {
|
|
71405
|
-
const written = await stat7(
|
|
71498
|
+
const written = await stat7(join20(directory, name)).then((info) => info.mtimeMs, () => {
|
|
71406
71499
|
return;
|
|
71407
71500
|
});
|
|
71408
71501
|
if (written === undefined)
|
|
@@ -71430,7 +71523,7 @@ async function currentOwner(directory, probe = SYSTEM_PROBE) {
|
|
|
71430
71523
|
const text = seen.held.get(seq);
|
|
71431
71524
|
if (text === undefined)
|
|
71432
71525
|
return;
|
|
71433
|
-
const now = await
|
|
71526
|
+
const now = await readFile11(join20(directory, entryName({ seq })), "utf8").catch(() => {
|
|
71434
71527
|
return;
|
|
71435
71528
|
});
|
|
71436
71529
|
if (now !== text)
|
|
@@ -71491,7 +71584,7 @@ async function stillOwner(directory, self2, probe = SYSTEM_PROBE) {
|
|
|
71491
71584
|
// src/codex/codex-transcript.ts
|
|
71492
71585
|
import { watch } from "fs";
|
|
71493
71586
|
import { open as open4 } from "fs/promises";
|
|
71494
|
-
import { join as
|
|
71587
|
+
import { join as join21 } from "path";
|
|
71495
71588
|
function record3(value) {
|
|
71496
71589
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
71497
71590
|
}
|
|
@@ -71761,7 +71854,7 @@ async function findTranscript(home, threadId) {
|
|
|
71761
71854
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
71762
71855
|
const found = [];
|
|
71763
71856
|
try {
|
|
71764
|
-
for await (const file of glob.scan({ absolute: true, cwd:
|
|
71857
|
+
for await (const file of glob.scan({ absolute: true, cwd: join21(home, "sessions") })) {
|
|
71765
71858
|
found.push(file);
|
|
71766
71859
|
}
|
|
71767
71860
|
} catch {
|
|
@@ -71902,7 +71995,7 @@ function runDispatchCommand(script, args, stdin, options) {
|
|
|
71902
71995
|
});
|
|
71903
71996
|
}
|
|
71904
71997
|
function stateDirectoryFor(pluginRoot) {
|
|
71905
|
-
return configuredValue(process.env["PLUGIN_DATA"]) ?? codexPluginDataDirectory(pluginRoot) ??
|
|
71998
|
+
return configuredValue(process.env["PLUGIN_DATA"]) ?? codexPluginDataDirectory(pluginRoot) ?? join22(configuredValue(process.env["XDG_STATE_HOME"]) ?? join22(homedir4(), ".local", "state"), "claude-envoy", "codex");
|
|
71906
71999
|
}
|
|
71907
72000
|
function waitForRecord(file, pid, signal, ended) {
|
|
71908
72001
|
return new Promise((done) => {
|
|
@@ -71990,7 +72083,7 @@ async function runCodexEnvoyServer() {
|
|
|
71990
72083
|
env["DISPATCH_HOST"] = "codex";
|
|
71991
72084
|
if (configFile.path !== null)
|
|
71992
72085
|
env["ENVOY_CONFIG_FILE"] = configFile.path;
|
|
71993
|
-
const { code, output } = await runDispatchCommand(
|
|
72086
|
+
const { code, output } = await runDispatchCommand(join22(pluginRoot, "dist", "dispatch.js"), parsed.data.args, parsed.data.stdin ?? "", { cwd: await latestTurnCwd(transcript) ?? own?.cwd ?? current?.cwd ?? homedir4(), env });
|
|
71994
72087
|
return `${output}${output.endsWith(`
|
|
71995
72088
|
`) || output === "" ? "" : `
|
|
71996
72089
|
`}[exit ${code}]`;
|
|
@@ -72130,7 +72223,7 @@ async function runCodexEnvoyServer() {
|
|
|
72130
72223
|
const runningSession = () => record?.session_id ?? bound.session_id;
|
|
72131
72224
|
const codexDelivery = createCodexDelivery({
|
|
72132
72225
|
inboxDirectory: (sessionId) => codexInboxDirectory(stateDirectory, sessionId),
|
|
72133
|
-
queue: (text) => queueMessage(command(), runningSession(), text,
|
|
72226
|
+
queue: (text) => queueMessage(command(), runningSession(), text, join22(stateDirectory, "codex-long-messages")),
|
|
72134
72227
|
sessionId: runningSession,
|
|
72135
72228
|
taken: (item) => stream?.delivered(item.content, item.dispatchMessageId),
|
|
72136
72229
|
warn
|