@sjawhar/claude-envoy 5.27.2 → 5.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/dist/codex-hook.js +106 -31
- package/dist/dispatch.js +102 -27
- package/dist/envoy-channel.js +206 -122
- package/dist/session-hook.js +112 -37
- package/dist/session-title-hook.js +8 -6
- package/package.json +2 -2
- package/src/envoy-channel-server.ts +25 -10
package/dist/session-hook.js
CHANGED
|
@@ -981,7 +981,7 @@ __export(exports_coerce, {
|
|
|
981
981
|
|
|
982
982
|
// hooks/session-hook.ts
|
|
983
983
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync6, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
984
|
-
import { join as
|
|
984
|
+
import { join as join12 } from "path";
|
|
985
985
|
|
|
986
986
|
// ../cipher-client/src/device-login-file.ts
|
|
987
987
|
import { createPrivateKey, randomUUID as randomUUID2 } from "crypto";
|
|
@@ -17987,6 +17987,25 @@ var projectKeyValidation = {
|
|
|
17987
17987
|
message: `project is not a project key: ${PROJECT_KEY_RULE}`
|
|
17988
17988
|
};
|
|
17989
17989
|
var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
|
|
17990
|
+
var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
|
|
17991
|
+
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 ..";
|
|
17992
|
+
function apiPathProblem(value) {
|
|
17993
|
+
const { path } = value;
|
|
17994
|
+
if (typeof path !== "string")
|
|
17995
|
+
return;
|
|
17996
|
+
const named = JSON.stringify(path);
|
|
17997
|
+
if (!API_ROUTE_PATTERN.test(path)) {
|
|
17998
|
+
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).`;
|
|
17999
|
+
}
|
|
18000
|
+
if (!/^[!-~]*$/.test(path) || /[\\#]/.test(path)) {
|
|
18001
|
+
return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
|
|
18002
|
+
}
|
|
18003
|
+
const route = path.split("?", 1)[0] ?? "";
|
|
18004
|
+
if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
|
|
18005
|
+
return `path ${named} holds a . or .. segment: name the route itself.`;
|
|
18006
|
+
}
|
|
18007
|
+
return;
|
|
18008
|
+
}
|
|
17990
18009
|
var ISSUE_STATUSES = [
|
|
17991
18010
|
"triage",
|
|
17992
18011
|
"icebox",
|
|
@@ -18592,6 +18611,20 @@ var dispatchToolSpecs = [
|
|
|
18592
18611
|
arguments: () => ({}),
|
|
18593
18612
|
strict: true
|
|
18594
18613
|
},
|
|
18614
|
+
{
|
|
18615
|
+
name: "dispatch_api",
|
|
18616
|
+
example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
|
|
18617
|
+
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.",
|
|
18618
|
+
arguments: (z) => ({
|
|
18619
|
+
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.")
|
|
18620
|
+
}),
|
|
18621
|
+
validation: {
|
|
18622
|
+
check: (value) => apiPathProblem(value) === undefined,
|
|
18623
|
+
message: API_PATH_RULE,
|
|
18624
|
+
refusal: (value) => apiPathProblem(value) ?? API_PATH_RULE
|
|
18625
|
+
},
|
|
18626
|
+
strict: true
|
|
18627
|
+
},
|
|
18595
18628
|
{
|
|
18596
18629
|
name: "dispatch_handoff_write",
|
|
18597
18630
|
example: {
|
|
@@ -20808,17 +20841,19 @@ function zodSchemaApi(zod) {
|
|
|
20808
20841
|
};
|
|
20809
20842
|
}
|
|
20810
20843
|
// ../envoy-client/src/errors.ts
|
|
20811
|
-
function
|
|
20812
|
-
if (!("fromDispatch" in error)
|
|
20844
|
+
function dispatchField(error, field) {
|
|
20845
|
+
if (!("fromDispatch" in error))
|
|
20813
20846
|
return;
|
|
20814
|
-
const
|
|
20815
|
-
return typeof
|
|
20847
|
+
const value = Reflect.get(error, field);
|
|
20848
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
20816
20849
|
}
|
|
20817
20850
|
function messageFor(error) {
|
|
20818
20851
|
if (!(error instanceof Error))
|
|
20819
20852
|
return scrub(String(error));
|
|
20820
|
-
const code =
|
|
20821
|
-
|
|
20853
|
+
const code = dispatchField(error, "code");
|
|
20854
|
+
const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
|
|
20855
|
+
const hint = dispatchField(error, "hint");
|
|
20856
|
+
return scrub(hint === undefined ? message : `${message}; ${hint}`);
|
|
20822
20857
|
}
|
|
20823
20858
|
function hasErrnoCode(error, code) {
|
|
20824
20859
|
return error instanceof Error && "code" in error && error.code === code;
|
|
@@ -24176,6 +24211,7 @@ class DispatchServiceError extends Error {
|
|
|
24176
24211
|
mismatches;
|
|
24177
24212
|
issues;
|
|
24178
24213
|
changed;
|
|
24214
|
+
hint;
|
|
24179
24215
|
constructor(code, status, message, details = {}) {
|
|
24180
24216
|
super(message);
|
|
24181
24217
|
this.code = code;
|
|
@@ -24185,6 +24221,7 @@ class DispatchServiceError extends Error {
|
|
|
24185
24221
|
this.mismatches = details.mismatches;
|
|
24186
24222
|
this.issues = details.issues;
|
|
24187
24223
|
this.changed = details.changed;
|
|
24224
|
+
this.hint = details.hint;
|
|
24188
24225
|
}
|
|
24189
24226
|
}
|
|
24190
24227
|
|
|
@@ -24674,6 +24711,10 @@ class DispatchClient {
|
|
|
24674
24711
|
async limits() {
|
|
24675
24712
|
return this.#json("GET", ["api", "v1", "limits"]);
|
|
24676
24713
|
}
|
|
24714
|
+
async readRoute(path) {
|
|
24715
|
+
const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
|
|
24716
|
+
return this.#response("GET", url, await this.#send("GET", url));
|
|
24717
|
+
}
|
|
24677
24718
|
async inbox(assignee) {
|
|
24678
24719
|
return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
|
|
24679
24720
|
}
|
|
@@ -25362,7 +25403,7 @@ class DispatchClient {
|
|
|
25362
25403
|
if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
|
|
25363
25404
|
throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
|
|
25364
25405
|
}
|
|
25365
|
-
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
|
|
25406
|
+
throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, { ...error, hint: typeof error.hint === "string" ? error.hint : undefined });
|
|
25366
25407
|
}
|
|
25367
25408
|
throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
|
|
25368
25409
|
}
|
|
@@ -27136,6 +27177,7 @@ var issueFreeTools = {
|
|
|
27136
27177
|
dispatch_answers: true,
|
|
27137
27178
|
dispatch_whoami: true,
|
|
27138
27179
|
dispatch_limits: true,
|
|
27180
|
+
dispatch_api: true,
|
|
27139
27181
|
dispatch_inbox: true,
|
|
27140
27182
|
dispatch_send_to_agent: true,
|
|
27141
27183
|
dispatch_architecture_sync: true
|
|
@@ -29542,6 +29584,16 @@ async function resultsCommand(context) {
|
|
|
29542
29584
|
};
|
|
29543
29585
|
}
|
|
29544
29586
|
|
|
29587
|
+
// ../envoy-client/src/dispatch-commands/api.ts
|
|
29588
|
+
async function apiCommand(context) {
|
|
29589
|
+
const path = stringArg(context.args, "path");
|
|
29590
|
+
const answer = await context.newClient().readRoute(path);
|
|
29591
|
+
return {
|
|
29592
|
+
text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
|
|
29593
|
+
details: { path }
|
|
29594
|
+
};
|
|
29595
|
+
}
|
|
29596
|
+
|
|
29545
29597
|
// ../envoy-client/src/dispatch-commands/render-item.ts
|
|
29546
29598
|
function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
|
|
29547
29599
|
const answer = ask.answer;
|
|
@@ -32431,6 +32483,7 @@ var dispatchCommands = {
|
|
|
32431
32483
|
dispatch_answers: onSession(answersCommand),
|
|
32432
32484
|
dispatch_whoami: onSession(whoamiCommand),
|
|
32433
32485
|
dispatch_limits: onSession(limitsCommand),
|
|
32486
|
+
dispatch_api: onSession(apiCommand),
|
|
32434
32487
|
dispatch_inbox: onSession(inboxCommand)
|
|
32435
32488
|
};
|
|
32436
32489
|
// ../envoy-client/src/dispatch-execute.ts
|
|
@@ -32476,6 +32529,10 @@ function readDispatchFirstContext(skillFile) {
|
|
|
32476
32529
|
`);
|
|
32477
32530
|
}
|
|
32478
32531
|
|
|
32532
|
+
// ../cipher-client/src/environment.ts
|
|
32533
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
32534
|
+
import { join as join8 } from "path";
|
|
32535
|
+
|
|
32479
32536
|
// ../cipher-client/src/device-login.ts
|
|
32480
32537
|
import { generateKeyPairSync as generateKeyPairSync2, randomUUID as randomUUID5 } from "crypto";
|
|
32481
32538
|
|
|
@@ -33437,6 +33494,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
|
|
|
33437
33494
|
var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
|
|
33438
33495
|
var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
|
|
33439
33496
|
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
33497
|
+
var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
|
|
33498
|
+
var ROLE_KEY_FILE = "key.pem";
|
|
33440
33499
|
var SESSION_VAR = "AGENT_SECRETS_SESSION";
|
|
33441
33500
|
var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
|
|
33442
33501
|
var MAX_PROJECTS = 16;
|
|
@@ -33450,6 +33509,7 @@ var BROKER_VARIABLES = [
|
|
|
33450
33509
|
BROKER_URL_VAR,
|
|
33451
33510
|
IDENTITY_VAR,
|
|
33452
33511
|
MACHINE_TOKEN_FILE_VAR,
|
|
33512
|
+
KEY_DIR_VAR,
|
|
33453
33513
|
MACHINE_AUDIENCE_VAR,
|
|
33454
33514
|
SESSION_VAR,
|
|
33455
33515
|
PROJECTS_VAR,
|
|
@@ -33525,6 +33585,21 @@ function tradeProjects(env) {
|
|
|
33525
33585
|
}
|
|
33526
33586
|
return sorted;
|
|
33527
33587
|
}
|
|
33588
|
+
async function machineKey(env) {
|
|
33589
|
+
const dir = value(env, KEY_DIR_VAR);
|
|
33590
|
+
if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
|
|
33591
|
+
return await newDpopKey();
|
|
33592
|
+
const path = join8(dir, ROLE_KEY_FILE);
|
|
33593
|
+
let pem;
|
|
33594
|
+
try {
|
|
33595
|
+
pem = await readFile6(path, "utf8");
|
|
33596
|
+
} catch (error) {
|
|
33597
|
+
throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
|
|
33598
|
+
cause: error
|
|
33599
|
+
});
|
|
33600
|
+
}
|
|
33601
|
+
return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
|
|
33602
|
+
}
|
|
33528
33603
|
async function brokerTokenClient(env, own = "", read) {
|
|
33529
33604
|
const brokerUrl = value(env, BROKER_URL_VAR);
|
|
33530
33605
|
const machine = machineIdentity(env);
|
|
@@ -33552,7 +33627,7 @@ async function brokerTokenClient(env, own = "", read) {
|
|
|
33552
33627
|
if (record === undefined) {
|
|
33553
33628
|
const client = new BrokerTokenClient({
|
|
33554
33629
|
brokerUrl,
|
|
33555
|
-
key: await
|
|
33630
|
+
key: await machineKey(env),
|
|
33556
33631
|
subject: machine,
|
|
33557
33632
|
session: tradeSession(env, own),
|
|
33558
33633
|
launcherCredential: false,
|
|
@@ -34913,18 +34988,18 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
34913
34988
|
// src/codex/codex-session-record.ts
|
|
34914
34989
|
import { spawnSync } from "child_process";
|
|
34915
34990
|
import { readFileSync as readFileSync5, readlinkSync, unwatchFile, watchFile } from "fs";
|
|
34916
|
-
import { mkdir as mkdir4, readFile as
|
|
34991
|
+
import { mkdir as mkdir4, readFile as readFile8, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
34917
34992
|
import { homedir as homedir3 } from "os";
|
|
34918
|
-
import { basename as basename4, dirname as dirname5, join as
|
|
34993
|
+
import { basename as basename4, dirname as dirname5, join as join11 } from "path";
|
|
34919
34994
|
|
|
34920
34995
|
// src/session-identity.ts
|
|
34921
|
-
import { readFile as
|
|
34922
|
-
import { basename as basename3, join as
|
|
34996
|
+
import { readFile as readFile7 } from "fs/promises";
|
|
34997
|
+
import { basename as basename3, join as join10 } from "path";
|
|
34923
34998
|
|
|
34924
34999
|
// src/session-state.ts
|
|
34925
35000
|
import { readFileSync as readFileSync4 } from "fs";
|
|
34926
35001
|
import { mkdir as mkdir3, readdir as readdir3, rename as rename4, rm as rm4, stat as stat4, utimes as utimes2, writeFile as writeFile2 } from "fs/promises";
|
|
34927
|
-
import { dirname as dirname4, join as
|
|
35002
|
+
import { dirname as dirname4, join as join9 } from "path";
|
|
34928
35003
|
async function writeAtomicStateFile(file, contents) {
|
|
34929
35004
|
await mkdir3(dirname4(file), { recursive: true, mode: 448 });
|
|
34930
35005
|
const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
@@ -34942,7 +35017,7 @@ async function pruneStateDirectory(directory, isStale) {
|
|
|
34942
35017
|
throw error;
|
|
34943
35018
|
});
|
|
34944
35019
|
for (const entry of entries) {
|
|
34945
|
-
const file =
|
|
35020
|
+
const file = join9(directory, entry);
|
|
34946
35021
|
if (!await isStale(file))
|
|
34947
35022
|
continue;
|
|
34948
35023
|
await rm4(file, { recursive: true, force: true });
|
|
@@ -34957,7 +35032,7 @@ async function writtenLongAgo(file) {
|
|
|
34957
35032
|
}
|
|
34958
35033
|
var TITLES_DIRECTORY = "titles";
|
|
34959
35034
|
function sessionTitleFile(stateDirectory, sessionId) {
|
|
34960
|
-
return
|
|
35035
|
+
return join9(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
|
|
34961
35036
|
}
|
|
34962
35037
|
async function writeChosenTitle(file, title) {
|
|
34963
35038
|
await writeAtomicStateFile(file, `${title}
|
|
@@ -34985,7 +35060,7 @@ async function recordChosenTitle(sessionId, title) {
|
|
|
34985
35060
|
await writeChosenTitle(file, chosen);
|
|
34986
35061
|
}
|
|
34987
35062
|
async function pruneStaleSessionTitles(stateDirectory) {
|
|
34988
|
-
await pruneStateDirectory(
|
|
35063
|
+
await pruneStateDirectory(join9(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
|
|
34989
35064
|
}
|
|
34990
35065
|
|
|
34991
35066
|
// src/session-identity.ts
|
|
@@ -35010,14 +35085,14 @@ class SessionIdentity {
|
|
|
35010
35085
|
}
|
|
35011
35086
|
}
|
|
35012
35087
|
function sessionHandoffDirectory(stateDirectory, claudePid) {
|
|
35013
|
-
return
|
|
35088
|
+
return join10(stateDirectory, "sessions", String(claudePid));
|
|
35014
35089
|
}
|
|
35015
35090
|
function sessionHandoffFile(stateDirectory, claudePid) {
|
|
35016
|
-
return
|
|
35091
|
+
return join10(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
|
|
35017
35092
|
}
|
|
35018
35093
|
var ROLES_DIRECTORY = "roles";
|
|
35019
35094
|
function roleStateFile(stateDirectory, sessionId) {
|
|
35020
|
-
return
|
|
35095
|
+
return join10(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
|
|
35021
35096
|
}
|
|
35022
35097
|
|
|
35023
35098
|
class UnparseableRoleRecordError extends Error {
|
|
@@ -35029,7 +35104,7 @@ class UnparseableRoleRecordError extends Error {
|
|
|
35029
35104
|
async function readPersistedRole(roleFile) {
|
|
35030
35105
|
let bytes;
|
|
35031
35106
|
try {
|
|
35032
|
-
bytes = await
|
|
35107
|
+
bytes = await readFile7(roleFile, "utf8");
|
|
35033
35108
|
} catch (error) {
|
|
35034
35109
|
if (hasErrnoCode(error, "ENOENT"))
|
|
35035
35110
|
return;
|
|
@@ -35051,7 +35126,7 @@ async function writeSessionHandoff(file, sessionId) {
|
|
|
35051
35126
|
}
|
|
35052
35127
|
async function readSessionHandoff(file) {
|
|
35053
35128
|
try {
|
|
35054
|
-
const id = (await
|
|
35129
|
+
const id = (await readFile7(file, "utf8")).trim();
|
|
35055
35130
|
return id.length === 0 ? undefined : id;
|
|
35056
35131
|
} catch (error) {
|
|
35057
35132
|
if (hasErrnoCode(error, "ENOENT"))
|
|
@@ -35068,14 +35143,14 @@ function processExists(pid) {
|
|
|
35068
35143
|
}
|
|
35069
35144
|
}
|
|
35070
35145
|
async function pruneStaleSessionHandoffs(stateDirectory) {
|
|
35071
|
-
await pruneStateDirectory(
|
|
35146
|
+
await pruneStateDirectory(join10(stateDirectory, "sessions"), (file) => {
|
|
35072
35147
|
const pid = basename3(file);
|
|
35073
35148
|
return /^\d+$/.test(pid) && !processExists(Number(pid));
|
|
35074
35149
|
});
|
|
35075
35150
|
}
|
|
35076
35151
|
async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
|
|
35077
35152
|
const own = roleStateFile(stateDirectory, currentSessionId);
|
|
35078
|
-
await pruneStateDirectory(
|
|
35153
|
+
await pruneStateDirectory(join10(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
|
|
35079
35154
|
}
|
|
35080
35155
|
|
|
35081
35156
|
// src/codex/codex-session-record.ts
|
|
@@ -35089,10 +35164,10 @@ var CodexSessionRecord = object({
|
|
|
35089
35164
|
codex_started: string2().nullable().default(null)
|
|
35090
35165
|
});
|
|
35091
35166
|
function codexSessionRecordFile(stateDirectory, pid) {
|
|
35092
|
-
return
|
|
35167
|
+
return join11(stateDirectory, "codex-sessions", `${pid}.json`);
|
|
35093
35168
|
}
|
|
35094
35169
|
function codexEndedFile(stateDirectory, pid, sessionId) {
|
|
35095
|
-
return
|
|
35170
|
+
return join11(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
|
|
35096
35171
|
}
|
|
35097
35172
|
async function markSessionEnded(stateDirectory, pid, sessionId) {
|
|
35098
35173
|
const marker = codexEndedFile(stateDirectory, pid, sessionId);
|
|
@@ -35115,7 +35190,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
|
|
|
35115
35190
|
}
|
|
35116
35191
|
async function sessionEnded(file) {
|
|
35117
35192
|
try {
|
|
35118
|
-
await
|
|
35193
|
+
await readFile8(file);
|
|
35119
35194
|
return true;
|
|
35120
35195
|
} catch {
|
|
35121
35196
|
return false;
|
|
@@ -35129,7 +35204,7 @@ async function writeCodexSessionRecord(file, value) {
|
|
|
35129
35204
|
}
|
|
35130
35205
|
async function readCodexSessionRecord(file) {
|
|
35131
35206
|
try {
|
|
35132
|
-
const parsed = CodexSessionRecord.safeParse(JSON.parse(await
|
|
35207
|
+
const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile8(file, "utf8")));
|
|
35133
35208
|
return parsed.success ? parsed.data : undefined;
|
|
35134
35209
|
} catch {
|
|
35135
35210
|
return;
|
|
@@ -35137,7 +35212,7 @@ async function readCodexSessionRecord(file) {
|
|
|
35137
35212
|
}
|
|
35138
35213
|
function codexHome(env) {
|
|
35139
35214
|
const set = env["CODEX_HOME"];
|
|
35140
|
-
return set !== undefined && set !== "" ? set :
|
|
35215
|
+
return set !== undefined && set !== "" ? set : join11(env["HOME"] || homedir3(), ".codex");
|
|
35141
35216
|
}
|
|
35142
35217
|
function codexPluginDataDirectory(pluginRoot) {
|
|
35143
35218
|
const version = pluginRoot;
|
|
@@ -35147,7 +35222,7 @@ function codexPluginDataDirectory(pluginRoot) {
|
|
|
35147
35222
|
const plugins = dirname5(cache);
|
|
35148
35223
|
if (basename4(cache) !== "cache" || basename4(plugins) !== "plugins")
|
|
35149
35224
|
return;
|
|
35150
|
-
return
|
|
35225
|
+
return join11(plugins, "data", `${basename4(plugin)}-${basename4(marketplace)}`);
|
|
35151
35226
|
}
|
|
35152
35227
|
var MAX_ANCESTORS = 16;
|
|
35153
35228
|
function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
@@ -35249,11 +35324,11 @@ function codexSubcommand(args) {
|
|
|
35249
35324
|
}
|
|
35250
35325
|
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.";
|
|
35251
35326
|
async function pruneCodexSessionRecords(stateDirectory) {
|
|
35252
|
-
await pruneStateDirectory(
|
|
35327
|
+
await pruneStateDirectory(join11(stateDirectory, "codex-sessions"), (file) => {
|
|
35253
35328
|
const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename4(file));
|
|
35254
35329
|
return match !== null && !processExists(Number(match[1]));
|
|
35255
35330
|
});
|
|
35256
|
-
await pruneStateDirectory(
|
|
35331
|
+
await pruneStateDirectory(join11(stateDirectory, "codex-servers"), (file) => {
|
|
35257
35332
|
const name = basename4(file);
|
|
35258
35333
|
return /^\d+$/.test(name) && !processExists(Number(name));
|
|
35259
35334
|
});
|
|
@@ -35474,7 +35549,7 @@ async function dispatchFirst(raw) {
|
|
|
35474
35549
|
process.stdout.write(JSON.stringify({
|
|
35475
35550
|
hookSpecificOutput: {
|
|
35476
35551
|
hookEventName: input.hook_event_name,
|
|
35477
|
-
additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(
|
|
35552
|
+
additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(join12(pluginRoot, "skills")))
|
|
35478
35553
|
}
|
|
35479
35554
|
}));
|
|
35480
35555
|
}
|
|
@@ -35533,13 +35608,13 @@ async function refreshedAnswers(session, cwd, dispatchUrl, startedAt, by) {
|
|
|
35533
35608
|
} catch (error) {
|
|
35534
35609
|
return { reason: messageFor(error) };
|
|
35535
35610
|
}
|
|
35536
|
-
const lock =
|
|
35611
|
+
const lock = join12(directory, REFRESH_LOCK);
|
|
35537
35612
|
if (!refreshLockHeld(lock)) {
|
|
35538
35613
|
const refresher = Bun.spawn([process.execPath, Bun.main, "answers-refresh", session, cwd, "--host", HOST], { stdin: "ignore", stdout: "ignore", stderr: "ignore", detached: true });
|
|
35539
35614
|
refresher.unref();
|
|
35540
35615
|
nameRefresher(refresher.pid);
|
|
35541
35616
|
}
|
|
35542
|
-
const file =
|
|
35617
|
+
const file = join12(directory, REFRESH_OUTCOME);
|
|
35543
35618
|
for (;; ) {
|
|
35544
35619
|
const outcome = refreshOutcome(file, startedAt);
|
|
35545
35620
|
if (outcome !== undefined) {
|
|
@@ -35620,7 +35695,7 @@ async function answers(text) {
|
|
|
35620
35695
|
async function answersRefresh(session, cwd) {
|
|
35621
35696
|
const directory = sessionDirectory(process.env, session);
|
|
35622
35697
|
mkdirSync2(directory, { recursive: true, mode: 448 });
|
|
35623
|
-
const lock =
|
|
35698
|
+
const lock = join12(directory, REFRESH_LOCK);
|
|
35624
35699
|
if (takeRefreshLock(lock)) {
|
|
35625
35700
|
try {
|
|
35626
35701
|
const file = sessionConfigFile(HOST, process.env);
|
|
@@ -35638,7 +35713,7 @@ async function answersRefresh(session, cwd) {
|
|
|
35638
35713
|
text: read.text ?? null,
|
|
35639
35714
|
notice: read.notice ?? null
|
|
35640
35715
|
};
|
|
35641
|
-
writeAtomically(
|
|
35716
|
+
writeAtomically(join12(directory, REFRESH_OUTCOME), JSON.stringify(outcome));
|
|
35642
35717
|
} finally {
|
|
35643
35718
|
rmSync2(lock, { force: true });
|
|
35644
35719
|
}
|
|
@@ -203,17 +203,19 @@ function errorClass(error) {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
// ../envoy-client/src/errors.ts
|
|
206
|
-
function
|
|
207
|
-
if (!("fromDispatch" in error)
|
|
206
|
+
function dispatchField(error, field) {
|
|
207
|
+
if (!("fromDispatch" in error))
|
|
208
208
|
return;
|
|
209
|
-
const
|
|
210
|
-
return typeof
|
|
209
|
+
const value = Reflect.get(error, field);
|
|
210
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
211
211
|
}
|
|
212
212
|
function messageFor(error) {
|
|
213
213
|
if (!(error instanceof Error))
|
|
214
214
|
return scrub(String(error));
|
|
215
|
-
const code =
|
|
216
|
-
|
|
215
|
+
const code = dispatchField(error, "code");
|
|
216
|
+
const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
|
|
217
|
+
const hint = dispatchField(error, "hint");
|
|
218
|
+
return scrub(hint === undefined ? message : `${message}; ${hint}`);
|
|
217
219
|
}
|
|
218
220
|
function hasErrnoCode(error, code) {
|
|
219
221
|
return error instanceof Error && "code" in error && error.code === code;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sjawhar/claude-envoy",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.28.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Claude Code plugin for Legion's Envoy bus",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"AGENTS.md"
|
|
20
20
|
],
|
|
21
21
|
"legion": {
|
|
22
|
-
"daemonApiVersion":
|
|
22
|
+
"daemonApiVersion": 275
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
@@ -523,6 +523,30 @@ export async function postDispatchReply(
|
|
|
523
523
|
await postDeliveryReply(config, identity.id, delivery, result)
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
/**
|
|
527
|
+
* The Dispatch client a person's message, command, pick or BTW is accepted and read through
|
|
528
|
+
* (`UserTurnRouterOptions.dispatch`), bounded to `ms`, or undefined while nothing configures
|
|
529
|
+
* Dispatch. It trades under this session's id, as `postDispatchReply` does: no pod sets
|
|
530
|
+
* `AGENT_SECRETS_SESSION`, so a trade that named no session would write under none.
|
|
531
|
+
*/
|
|
532
|
+
export async function userTurnDispatchClient(
|
|
533
|
+
identity: SessionIdentity,
|
|
534
|
+
configFile: SessionConfigFile,
|
|
535
|
+
ms: number,
|
|
536
|
+
): Promise<DispatchClient | undefined> {
|
|
537
|
+
const active = activeDispatchSettings(
|
|
538
|
+
(
|
|
539
|
+
await sessionDispatchSettings(configFile, process.env, {
|
|
540
|
+
cwd: identity.directory,
|
|
541
|
+
session: () => identity.id,
|
|
542
|
+
})
|
|
543
|
+
).dispatch,
|
|
544
|
+
)
|
|
545
|
+
return active === null
|
|
546
|
+
? undefined
|
|
547
|
+
: new DispatchClient(active.url, active.credential, fetch, { deadlineMs: ms })
|
|
548
|
+
}
|
|
549
|
+
|
|
526
550
|
/**
|
|
527
551
|
* Render inbound Envoy envelopes through the shared renderer and hand each one to the session,
|
|
528
552
|
* one at a time, in the order they were queued.
|
|
@@ -2798,16 +2822,7 @@ export async function runEnvoyChannelServer(): Promise<void> {
|
|
|
2798
2822
|
*/
|
|
2799
2823
|
const router = (state: UserTurnState): UserTurnRouter => {
|
|
2800
2824
|
const options: UserTurnRouterOptions = {
|
|
2801
|
-
dispatch:
|
|
2802
|
-
const active = activeDispatchSettings(
|
|
2803
|
-
(await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch,
|
|
2804
|
-
)
|
|
2805
|
-
return active === null
|
|
2806
|
-
? undefined
|
|
2807
|
-
: new DispatchClient(active.url, active.credential, fetch, {
|
|
2808
|
-
deadlineMs: ms,
|
|
2809
|
-
})
|
|
2810
|
-
},
|
|
2825
|
+
dispatch: (ms) => userTurnDispatchClient(identity, configFile, ms),
|
|
2811
2826
|
effortPicked: (effort) => agentStream?.pickedEffort(effort),
|
|
2812
2827
|
refreshSettings: () => agentStream?.refresh(),
|
|
2813
2828
|
reply: (delivery, result) => postDispatchReply(identity, configFile, delivery, result),
|