@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/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",
|
|
@@ -18059,8 +18078,8 @@ var dispatchToolSpecs = [
|
|
|
18059
18078
|
route: z.string().describe("Route the issue to role:<name> or session:<id>; an empty string clears it.").optional(),
|
|
18060
18079
|
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(),
|
|
18061
18080
|
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(),
|
|
18062
|
-
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.
|
|
18063
|
-
advances_revision: z.number().describe("The
|
|
18081
|
+
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(),
|
|
18082
|
+
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(),
|
|
18064
18083
|
components: componentsArgument(z).optional(),
|
|
18065
18084
|
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(),
|
|
18066
18085
|
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(),
|
|
@@ -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
|
|
@@ -28408,9 +28450,9 @@ function advancesLine(issue) {
|
|
|
28408
28450
|
return "Advances: unknown (this Dispatch server predates priorities; upgrade it)";
|
|
28409
28451
|
}
|
|
28410
28452
|
const advances = issue.advances ?? [];
|
|
28411
|
-
|
|
28412
|
-
|
|
28413
|
-
return `Advances: ${
|
|
28453
|
+
const set = advances.length === 0 ? "no priority" : advances.map(advanceText).join(", ");
|
|
28454
|
+
const revision = issue.advances_revision === undefined ? "" : `; revision ${issue.advances_revision}`;
|
|
28455
|
+
return `Advances: ${set}${revision}`;
|
|
28414
28456
|
}
|
|
28415
28457
|
function claimText(claim, agents, read = {}) {
|
|
28416
28458
|
const titles = agents?.titles;
|
|
@@ -29084,11 +29126,16 @@ function refuseUnsavedRepository(verb, issue, repo) {
|
|
|
29084
29126
|
const lost = repo === "" ? "the repository was not cleared" : `${repo} was not saved`;
|
|
29085
29127
|
throw new Error(`Dispatch ${verb} ${issue.key} without its repository: this Dispatch server predates repository fields, so ${lost}; upgrade the server`);
|
|
29086
29128
|
}
|
|
29087
|
-
function
|
|
29088
|
-
if (issue.advances_revision
|
|
29089
|
-
|
|
29090
|
-
}
|
|
29091
|
-
|
|
29129
|
+
function refuseServerWithoutAdvances(issue) {
|
|
29130
|
+
if (issue.advances_revision !== undefined)
|
|
29131
|
+
return;
|
|
29132
|
+
throw new Error(`Dispatch read ${issue.key} without its advances: this Dispatch server predates priorities, so nothing was sent; upgrade the server`);
|
|
29133
|
+
}
|
|
29134
|
+
function advancesRevisionAnswer(issueKey, error) {
|
|
29135
|
+
if (!dispatchAnswered(error, 409) || error.code !== "ADVANCES_REVISION")
|
|
29136
|
+
return "";
|
|
29137
|
+
const held = /(\d+)\D*$/.exec(error.message)?.[1] ?? "<the revision named above>";
|
|
29138
|
+
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}`;
|
|
29092
29139
|
}
|
|
29093
29140
|
async function issueCommand(context) {
|
|
29094
29141
|
const { args, client, actor, input, linkBase } = context;
|
|
@@ -29199,7 +29246,9 @@ async function issueUpdateCommand(context) {
|
|
|
29199
29246
|
} catch (error) {
|
|
29200
29247
|
throw refusalWithCode(error);
|
|
29201
29248
|
}
|
|
29202
|
-
|
|
29249
|
+
if (advances !== undefined)
|
|
29250
|
+
refuseServerWithoutAdvances(before);
|
|
29251
|
+
const advancesWrite = advances === undefined ? undefined : { advances, ...defined("advances_revision", advancesRevision) };
|
|
29203
29252
|
if (status === "done" && typeof before.closed_at === "string") {
|
|
29204
29253
|
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`);
|
|
29205
29254
|
}
|
|
@@ -29257,15 +29306,17 @@ async function issueUpdateCommand(context) {
|
|
|
29257
29306
|
throw error;
|
|
29258
29307
|
const answered = error instanceof DispatchWriteUnsettledError ? error.last : error;
|
|
29259
29308
|
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)` : "";
|
|
29309
|
+
const revisionClause = advancesRevisionAnswer(issueKey, error);
|
|
29260
29310
|
if (closingNote === undefined) {
|
|
29261
29311
|
if (taken !== "" && !(error instanceof DispatchServiceError)) {
|
|
29262
29312
|
throw withAccount(error, taken);
|
|
29263
29313
|
}
|
|
29264
|
-
throw refusalWithCode(error, taken);
|
|
29314
|
+
throw refusalWithCode(error, taken, revisionClause);
|
|
29265
29315
|
}
|
|
29266
29316
|
const landed = closeAccount(error, closingNote);
|
|
29267
|
-
if (error instanceof DispatchServiceError)
|
|
29268
|
-
throw refusalWithCode(error, taken, landed);
|
|
29317
|
+
if (error instanceof DispatchServiceError) {
|
|
29318
|
+
throw refusalWithCode(error, taken, revisionClause, landed);
|
|
29319
|
+
}
|
|
29269
29320
|
throw withAccount(error, [taken, landed].filter((clause) => clause !== "").join("; "));
|
|
29270
29321
|
}
|
|
29271
29322
|
refuseUnsavedRepository("updated", after, repo);
|
|
@@ -29542,6 +29593,16 @@ async function resultsCommand(context) {
|
|
|
29542
29593
|
};
|
|
29543
29594
|
}
|
|
29544
29595
|
|
|
29596
|
+
// ../envoy-client/src/dispatch-commands/api.ts
|
|
29597
|
+
async function apiCommand(context) {
|
|
29598
|
+
const path = stringArg(context.args, "path");
|
|
29599
|
+
const answer = await context.newClient().readRoute(path);
|
|
29600
|
+
return {
|
|
29601
|
+
text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
|
|
29602
|
+
details: { path }
|
|
29603
|
+
};
|
|
29604
|
+
}
|
|
29605
|
+
|
|
29545
29606
|
// ../envoy-client/src/dispatch-commands/render-item.ts
|
|
29546
29607
|
function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
|
|
29547
29608
|
const answer = ask.answer;
|
|
@@ -31374,7 +31435,7 @@ function priorityWorkLine(work) {
|
|
|
31374
31435
|
}
|
|
31375
31436
|
function priorityIssueLine(issue, agents) {
|
|
31376
31437
|
const advances = issue.advances ?? [];
|
|
31377
|
-
const moved = issue.moved_at === null ? "" : ` \xB7
|
|
31438
|
+
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)}`}`;
|
|
31378
31439
|
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}`;
|
|
31379
31440
|
}
|
|
31380
31441
|
function priorityFaultLines(heading, fault, agents) {
|
|
@@ -31390,7 +31451,7 @@ function priorityFaultLines(heading, fault, agents) {
|
|
|
31390
31451
|
}
|
|
31391
31452
|
function formatPriorities(response, agents) {
|
|
31392
31453
|
const priorities = response.priorities ?? [];
|
|
31393
|
-
const
|
|
31454
|
+
const backlog = response.priority_work_parked;
|
|
31394
31455
|
const unplaced = response.work_under_no_priority;
|
|
31395
31456
|
if (response.empty !== undefined)
|
|
31396
31457
|
return response.empty;
|
|
@@ -31403,7 +31464,7 @@ function formatPriorities(response, agents) {
|
|
|
31403
31464
|
"",
|
|
31404
31465
|
...priorityFaultLines("Work under no priority", { count: unplaced.count, issues: unplaced.issues, by: unplaced.by_project }, agents),
|
|
31405
31466
|
"",
|
|
31406
|
-
...priorityFaultLines("Priority work
|
|
31467
|
+
...priorityFaultLines("Priority work in backlog or icebox", { count: backlog.count, issues: backlog.issues, by: backlog.by_priority }, agents)
|
|
31407
31468
|
].join(`
|
|
31408
31469
|
`);
|
|
31409
31470
|
}
|
|
@@ -32431,6 +32492,7 @@ var dispatchCommands = {
|
|
|
32431
32492
|
dispatch_answers: onSession(answersCommand),
|
|
32432
32493
|
dispatch_whoami: onSession(whoamiCommand),
|
|
32433
32494
|
dispatch_limits: onSession(limitsCommand),
|
|
32495
|
+
dispatch_api: onSession(apiCommand),
|
|
32434
32496
|
dispatch_inbox: onSession(inboxCommand)
|
|
32435
32497
|
};
|
|
32436
32498
|
// ../envoy-client/src/dispatch-execute.ts
|
|
@@ -32476,6 +32538,10 @@ function readDispatchFirstContext(skillFile) {
|
|
|
32476
32538
|
`);
|
|
32477
32539
|
}
|
|
32478
32540
|
|
|
32541
|
+
// ../cipher-client/src/environment.ts
|
|
32542
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
32543
|
+
import { join as join8 } from "path";
|
|
32544
|
+
|
|
32479
32545
|
// ../cipher-client/src/device-login.ts
|
|
32480
32546
|
import { generateKeyPairSync as generateKeyPairSync2, randomUUID as randomUUID5 } from "crypto";
|
|
32481
32547
|
|
|
@@ -33437,6 +33503,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
|
|
|
33437
33503
|
var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
|
|
33438
33504
|
var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
|
|
33439
33505
|
var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
|
|
33506
|
+
var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
|
|
33507
|
+
var ROLE_KEY_FILE = "key.pem";
|
|
33440
33508
|
var SESSION_VAR = "AGENT_SECRETS_SESSION";
|
|
33441
33509
|
var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
|
|
33442
33510
|
var MAX_PROJECTS = 16;
|
|
@@ -33450,6 +33518,7 @@ var BROKER_VARIABLES = [
|
|
|
33450
33518
|
BROKER_URL_VAR,
|
|
33451
33519
|
IDENTITY_VAR,
|
|
33452
33520
|
MACHINE_TOKEN_FILE_VAR,
|
|
33521
|
+
KEY_DIR_VAR,
|
|
33453
33522
|
MACHINE_AUDIENCE_VAR,
|
|
33454
33523
|
SESSION_VAR,
|
|
33455
33524
|
PROJECTS_VAR,
|
|
@@ -33525,6 +33594,21 @@ function tradeProjects(env) {
|
|
|
33525
33594
|
}
|
|
33526
33595
|
return sorted;
|
|
33527
33596
|
}
|
|
33597
|
+
async function machineKey(env) {
|
|
33598
|
+
const dir = value(env, KEY_DIR_VAR);
|
|
33599
|
+
if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
|
|
33600
|
+
return await newDpopKey();
|
|
33601
|
+
const path = join8(dir, ROLE_KEY_FILE);
|
|
33602
|
+
let pem;
|
|
33603
|
+
try {
|
|
33604
|
+
pem = await readFile6(path, "utf8");
|
|
33605
|
+
} catch (error) {
|
|
33606
|
+
throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
|
|
33607
|
+
cause: error
|
|
33608
|
+
});
|
|
33609
|
+
}
|
|
33610
|
+
return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
|
|
33611
|
+
}
|
|
33528
33612
|
async function brokerTokenClient(env, own = "", read) {
|
|
33529
33613
|
const brokerUrl = value(env, BROKER_URL_VAR);
|
|
33530
33614
|
const machine = machineIdentity(env);
|
|
@@ -33552,7 +33636,7 @@ async function brokerTokenClient(env, own = "", read) {
|
|
|
33552
33636
|
if (record === undefined) {
|
|
33553
33637
|
const client = new BrokerTokenClient({
|
|
33554
33638
|
brokerUrl,
|
|
33555
|
-
key: await
|
|
33639
|
+
key: await machineKey(env),
|
|
33556
33640
|
subject: machine,
|
|
33557
33641
|
session: tradeSession(env, own),
|
|
33558
33642
|
launcherCredential: false,
|
|
@@ -34913,18 +34997,18 @@ function claudeProjectDirectory(environment, fallback) {
|
|
|
34913
34997
|
// src/codex/codex-session-record.ts
|
|
34914
34998
|
import { spawnSync } from "child_process";
|
|
34915
34999
|
import { readFileSync as readFileSync5, readlinkSync, unwatchFile, watchFile } from "fs";
|
|
34916
|
-
import { mkdir as mkdir4, readFile as
|
|
35000
|
+
import { mkdir as mkdir4, readFile as readFile8, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
34917
35001
|
import { homedir as homedir3 } from "os";
|
|
34918
|
-
import { basename as basename4, dirname as dirname5, join as
|
|
35002
|
+
import { basename as basename4, dirname as dirname5, join as join11 } from "path";
|
|
34919
35003
|
|
|
34920
35004
|
// src/session-identity.ts
|
|
34921
|
-
import { readFile as
|
|
34922
|
-
import { basename as basename3, join as
|
|
35005
|
+
import { readFile as readFile7 } from "fs/promises";
|
|
35006
|
+
import { basename as basename3, join as join10 } from "path";
|
|
34923
35007
|
|
|
34924
35008
|
// src/session-state.ts
|
|
34925
35009
|
import { readFileSync as readFileSync4 } from "fs";
|
|
34926
35010
|
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
|
|
35011
|
+
import { dirname as dirname4, join as join9 } from "path";
|
|
34928
35012
|
async function writeAtomicStateFile(file, contents) {
|
|
34929
35013
|
await mkdir3(dirname4(file), { recursive: true, mode: 448 });
|
|
34930
35014
|
const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
@@ -34942,7 +35026,7 @@ async function pruneStateDirectory(directory, isStale) {
|
|
|
34942
35026
|
throw error;
|
|
34943
35027
|
});
|
|
34944
35028
|
for (const entry of entries) {
|
|
34945
|
-
const file =
|
|
35029
|
+
const file = join9(directory, entry);
|
|
34946
35030
|
if (!await isStale(file))
|
|
34947
35031
|
continue;
|
|
34948
35032
|
await rm4(file, { recursive: true, force: true });
|
|
@@ -34957,7 +35041,7 @@ async function writtenLongAgo(file) {
|
|
|
34957
35041
|
}
|
|
34958
35042
|
var TITLES_DIRECTORY = "titles";
|
|
34959
35043
|
function sessionTitleFile(stateDirectory, sessionId) {
|
|
34960
|
-
return
|
|
35044
|
+
return join9(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
|
|
34961
35045
|
}
|
|
34962
35046
|
async function writeChosenTitle(file, title) {
|
|
34963
35047
|
await writeAtomicStateFile(file, `${title}
|
|
@@ -34985,7 +35069,7 @@ async function recordChosenTitle(sessionId, title) {
|
|
|
34985
35069
|
await writeChosenTitle(file, chosen);
|
|
34986
35070
|
}
|
|
34987
35071
|
async function pruneStaleSessionTitles(stateDirectory) {
|
|
34988
|
-
await pruneStateDirectory(
|
|
35072
|
+
await pruneStateDirectory(join9(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
|
|
34989
35073
|
}
|
|
34990
35074
|
|
|
34991
35075
|
// src/session-identity.ts
|
|
@@ -35010,14 +35094,14 @@ class SessionIdentity {
|
|
|
35010
35094
|
}
|
|
35011
35095
|
}
|
|
35012
35096
|
function sessionHandoffDirectory(stateDirectory, claudePid) {
|
|
35013
|
-
return
|
|
35097
|
+
return join10(stateDirectory, "sessions", String(claudePid));
|
|
35014
35098
|
}
|
|
35015
35099
|
function sessionHandoffFile(stateDirectory, claudePid) {
|
|
35016
|
-
return
|
|
35100
|
+
return join10(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
|
|
35017
35101
|
}
|
|
35018
35102
|
var ROLES_DIRECTORY = "roles";
|
|
35019
35103
|
function roleStateFile(stateDirectory, sessionId) {
|
|
35020
|
-
return
|
|
35104
|
+
return join10(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
|
|
35021
35105
|
}
|
|
35022
35106
|
|
|
35023
35107
|
class UnparseableRoleRecordError extends Error {
|
|
@@ -35029,7 +35113,7 @@ class UnparseableRoleRecordError extends Error {
|
|
|
35029
35113
|
async function readPersistedRole(roleFile) {
|
|
35030
35114
|
let bytes;
|
|
35031
35115
|
try {
|
|
35032
|
-
bytes = await
|
|
35116
|
+
bytes = await readFile7(roleFile, "utf8");
|
|
35033
35117
|
} catch (error) {
|
|
35034
35118
|
if (hasErrnoCode(error, "ENOENT"))
|
|
35035
35119
|
return;
|
|
@@ -35051,7 +35135,7 @@ async function writeSessionHandoff(file, sessionId) {
|
|
|
35051
35135
|
}
|
|
35052
35136
|
async function readSessionHandoff(file) {
|
|
35053
35137
|
try {
|
|
35054
|
-
const id = (await
|
|
35138
|
+
const id = (await readFile7(file, "utf8")).trim();
|
|
35055
35139
|
return id.length === 0 ? undefined : id;
|
|
35056
35140
|
} catch (error) {
|
|
35057
35141
|
if (hasErrnoCode(error, "ENOENT"))
|
|
@@ -35068,14 +35152,14 @@ function processExists(pid) {
|
|
|
35068
35152
|
}
|
|
35069
35153
|
}
|
|
35070
35154
|
async function pruneStaleSessionHandoffs(stateDirectory) {
|
|
35071
|
-
await pruneStateDirectory(
|
|
35155
|
+
await pruneStateDirectory(join10(stateDirectory, "sessions"), (file) => {
|
|
35072
35156
|
const pid = basename3(file);
|
|
35073
35157
|
return /^\d+$/.test(pid) && !processExists(Number(pid));
|
|
35074
35158
|
});
|
|
35075
35159
|
}
|
|
35076
35160
|
async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
|
|
35077
35161
|
const own = roleStateFile(stateDirectory, currentSessionId);
|
|
35078
|
-
await pruneStateDirectory(
|
|
35162
|
+
await pruneStateDirectory(join10(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
|
|
35079
35163
|
}
|
|
35080
35164
|
|
|
35081
35165
|
// src/codex/codex-session-record.ts
|
|
@@ -35089,10 +35173,10 @@ var CodexSessionRecord = object({
|
|
|
35089
35173
|
codex_started: string2().nullable().default(null)
|
|
35090
35174
|
});
|
|
35091
35175
|
function codexSessionRecordFile(stateDirectory, pid) {
|
|
35092
|
-
return
|
|
35176
|
+
return join11(stateDirectory, "codex-sessions", `${pid}.json`);
|
|
35093
35177
|
}
|
|
35094
35178
|
function codexEndedFile(stateDirectory, pid, sessionId) {
|
|
35095
|
-
return
|
|
35179
|
+
return join11(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
|
|
35096
35180
|
}
|
|
35097
35181
|
async function markSessionEnded(stateDirectory, pid, sessionId) {
|
|
35098
35182
|
const marker = codexEndedFile(stateDirectory, pid, sessionId);
|
|
@@ -35115,7 +35199,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
|
|
|
35115
35199
|
}
|
|
35116
35200
|
async function sessionEnded(file) {
|
|
35117
35201
|
try {
|
|
35118
|
-
await
|
|
35202
|
+
await readFile8(file);
|
|
35119
35203
|
return true;
|
|
35120
35204
|
} catch {
|
|
35121
35205
|
return false;
|
|
@@ -35129,7 +35213,7 @@ async function writeCodexSessionRecord(file, value) {
|
|
|
35129
35213
|
}
|
|
35130
35214
|
async function readCodexSessionRecord(file) {
|
|
35131
35215
|
try {
|
|
35132
|
-
const parsed = CodexSessionRecord.safeParse(JSON.parse(await
|
|
35216
|
+
const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile8(file, "utf8")));
|
|
35133
35217
|
return parsed.success ? parsed.data : undefined;
|
|
35134
35218
|
} catch {
|
|
35135
35219
|
return;
|
|
@@ -35137,7 +35221,7 @@ async function readCodexSessionRecord(file) {
|
|
|
35137
35221
|
}
|
|
35138
35222
|
function codexHome(env) {
|
|
35139
35223
|
const set = env["CODEX_HOME"];
|
|
35140
|
-
return set !== undefined && set !== "" ? set :
|
|
35224
|
+
return set !== undefined && set !== "" ? set : join11(env["HOME"] || homedir3(), ".codex");
|
|
35141
35225
|
}
|
|
35142
35226
|
function codexPluginDataDirectory(pluginRoot) {
|
|
35143
35227
|
const version = pluginRoot;
|
|
@@ -35147,7 +35231,7 @@ function codexPluginDataDirectory(pluginRoot) {
|
|
|
35147
35231
|
const plugins = dirname5(cache);
|
|
35148
35232
|
if (basename4(cache) !== "cache" || basename4(plugins) !== "plugins")
|
|
35149
35233
|
return;
|
|
35150
|
-
return
|
|
35234
|
+
return join11(plugins, "data", `${basename4(plugin)}-${basename4(marketplace)}`);
|
|
35151
35235
|
}
|
|
35152
35236
|
var MAX_ANCESTORS = 16;
|
|
35153
35237
|
function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
@@ -35249,11 +35333,11 @@ function codexSubcommand(args) {
|
|
|
35249
35333
|
}
|
|
35250
35334
|
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
35335
|
async function pruneCodexSessionRecords(stateDirectory) {
|
|
35252
|
-
await pruneStateDirectory(
|
|
35336
|
+
await pruneStateDirectory(join11(stateDirectory, "codex-sessions"), (file) => {
|
|
35253
35337
|
const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename4(file));
|
|
35254
35338
|
return match !== null && !processExists(Number(match[1]));
|
|
35255
35339
|
});
|
|
35256
|
-
await pruneStateDirectory(
|
|
35340
|
+
await pruneStateDirectory(join11(stateDirectory, "codex-servers"), (file) => {
|
|
35257
35341
|
const name = basename4(file);
|
|
35258
35342
|
return /^\d+$/.test(name) && !processExists(Number(name));
|
|
35259
35343
|
});
|
|
@@ -35474,7 +35558,7 @@ async function dispatchFirst(raw) {
|
|
|
35474
35558
|
process.stdout.write(JSON.stringify({
|
|
35475
35559
|
hookSpecificOutput: {
|
|
35476
35560
|
hookEventName: input.hook_event_name,
|
|
35477
|
-
additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(
|
|
35561
|
+
additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(join12(pluginRoot, "skills")))
|
|
35478
35562
|
}
|
|
35479
35563
|
}));
|
|
35480
35564
|
}
|
|
@@ -35533,13 +35617,13 @@ async function refreshedAnswers(session, cwd, dispatchUrl, startedAt, by) {
|
|
|
35533
35617
|
} catch (error) {
|
|
35534
35618
|
return { reason: messageFor(error) };
|
|
35535
35619
|
}
|
|
35536
|
-
const lock =
|
|
35620
|
+
const lock = join12(directory, REFRESH_LOCK);
|
|
35537
35621
|
if (!refreshLockHeld(lock)) {
|
|
35538
35622
|
const refresher = Bun.spawn([process.execPath, Bun.main, "answers-refresh", session, cwd, "--host", HOST], { stdin: "ignore", stdout: "ignore", stderr: "ignore", detached: true });
|
|
35539
35623
|
refresher.unref();
|
|
35540
35624
|
nameRefresher(refresher.pid);
|
|
35541
35625
|
}
|
|
35542
|
-
const file =
|
|
35626
|
+
const file = join12(directory, REFRESH_OUTCOME);
|
|
35543
35627
|
for (;; ) {
|
|
35544
35628
|
const outcome = refreshOutcome(file, startedAt);
|
|
35545
35629
|
if (outcome !== undefined) {
|
|
@@ -35620,7 +35704,7 @@ async function answers(text) {
|
|
|
35620
35704
|
async function answersRefresh(session, cwd) {
|
|
35621
35705
|
const directory = sessionDirectory(process.env, session);
|
|
35622
35706
|
mkdirSync2(directory, { recursive: true, mode: 448 });
|
|
35623
|
-
const lock =
|
|
35707
|
+
const lock = join12(directory, REFRESH_LOCK);
|
|
35624
35708
|
if (takeRefreshLock(lock)) {
|
|
35625
35709
|
try {
|
|
35626
35710
|
const file = sessionConfigFile(HOST, process.env);
|
|
@@ -35638,7 +35722,7 @@ async function answersRefresh(session, cwd) {
|
|
|
35638
35722
|
text: read.text ?? null,
|
|
35639
35723
|
notice: read.notice ?? null
|
|
35640
35724
|
};
|
|
35641
|
-
writeAtomically(
|
|
35725
|
+
writeAtomically(join12(directory, REFRESH_OUTCOME), JSON.stringify(outcome));
|
|
35642
35726
|
} finally {
|
|
35643
35727
|
rmSync2(lock, { force: true });
|
|
35644
35728
|
}
|
|
@@ -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;
|
|
@@ -31,6 +31,6 @@ dispatch issue-update --issue <KEY> --label '<each current label>' --label legio
|
|
|
31
31
|
|
|
32
32
|
A label holding a `'` or a line break cannot be quoted and never goes in a command: tell the person (`<KEY>: label <label> cannot be quoted`), so they hand it over from the issue header.
|
|
33
33
|
|
|
34
|
-
The daemon queues nothing for a label a session set, so admit a `triage` root in the same turn, from step 3. In any other status, `set_status` it to `todo` only when the person asked Legion to start it now. When you file or admit an issue, name each priority it advances (`--advance <id>`; `dispatch priorities` lists them). A child needs no label: it runs in its tree.
|
|
34
|
+
The daemon queues nothing for a label a session set, so admit a `triage` root in the same turn, from step 3. In any other status, `set_status` it to `todo` only when the person asked Legion to start it now. When you file or admit an issue, name each priority it advances (`--advance <id>`; `dispatch priorities` lists them). An issue in flight that advances none is named on the priorities page, in its `Active under no priority` tab (`/priorities?tab=none`), and by `dispatch priorities`. A child needs no label: it runs in its tree.
|
|
35
35
|
|
|
36
36
|
Work that must start at a commit other than its base branch's head needs `legion/<KEY>` there before Legion starts the issue: a root before admission, a child before its first phase. You push nothing, so whoever gives you the root, or the architect that owns a child's parent, runs `gh api -X POST repos/<owner>/<name>/git/refs -f ref=refs/heads/legion/<KEY> -f sha=<commit>`. Read it back before `set_status` to `todo`: `gh api repos/<owner>/<name>/git/ref/heads/legion/<KEY>`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sjawhar/claude-envoy",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.29.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",
|
package/skills/dispatch/SKILL.md
CHANGED
|
@@ -40,9 +40,9 @@ The question and the recommendation (`skill://dispatch-writing-specs`).
|
|
|
40
40
|
- Move an issue to `backlog`, `icebox` or `triage` only when a person asked for that move, or when the work is done, folded into another issue or no longer needed, and cite that reason in a comment on the issue. An agent's directive citing no person's request is no reason.
|
|
41
41
|
- When you stop work on an issue before it is done, release your claim and say why in a comment. Set its status to the one it had when you took it (`todo` for an issue from the queue). Change no priority or board rank.
|
|
42
42
|
- Record each wait in that comment. A wait on any project's issue also goes in a `blocked_by` link.
|
|
43
|
-
- `dispatch issue-update --blocked-by` replaces the issue's whole list, so read
|
|
43
|
+
- `dispatch issue-update --blocked-by` replaces the issue's whole list, so read that list first. A one-project credential links only its own issues (`PROJECT_SCOPE`).
|
|
44
44
|
- Never reorder the board: one agent keeps each project's order (`issue-update --before`/`--after`). If the top looks wrong, tell `notifications.role.legion-<project>-controller`.
|
|
45
|
-
- Name an issue's priority: `--advance <id>`; `dispatch priorities`
|
|
45
|
+
- Name an issue's priority: `--advance <id>`; the priorities page (`/priorities?tab=none`) and `dispatch priorities` list what advances no priority.
|
|
46
46
|
|
|
47
47
|
## Issue status is yours to move
|
|
48
48
|
|
|
@@ -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),
|