@sjawhar/claude-envoy 5.29.0 → 5.31.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 +10 -3
- package/dist/dispatch.js +10 -3
- package/dist/envoy-channel.js +125 -123
- package/dist/session-hook.js +10 -3
- package/legion/skills/legion-architect/references/plan.md +1 -1
- package/package.json +4 -4
- package/scripts/build.ts +45 -2
- package/src/legion-claim.ts +14 -8
- package/src/legion-tool.ts +3 -2
package/.omp-plugin/plugin.json
CHANGED
package/dist/codex-hook.js
CHANGED
|
@@ -15154,7 +15154,7 @@ var dispatchToolSpecs = [
|
|
|
15154
15154
|
{
|
|
15155
15155
|
name: "dispatch_steps",
|
|
15156
15156
|
example: { issue: "DSP-1" },
|
|
15157
|
-
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end. The first line is `<KEY>: <n> steps in <m> tasks`.
|
|
15157
|
+
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end, and the experiment and the variant the issue was drawn into, where " + "its records name one. The first line is `<KEY>: <n> steps in <m> tasks`. Where the " + "records of the issue's newest run name an experiment, the next line is `Experiment " + "<experiment>: variant <variant>.`, and an issue whose newest run's records name none " + "prints no such line. Then each run of a step prints one line, task by task, in the order " + "each task first ran: `<task> " + "<step> <kind> <role> <type> attempt <attempt> <agent> <model> <started_at> <ended_at> " + "<result>`. kind is step, retro or merge. step is the step's place in its task, from 1, " + "and 0 for a retro or a merge. attempt counts the runs of the same task, step and kind, " + "from 1. agent is the claim of the role that ran the step, and model is the model that " + "answered it, as provider/model. result is passed, failed or stopped. A field with no " + "value prints -, and a run that has not ended prints running for its end and its result. " + "A closed issue's steps read too. An issue that no step ran on prints 0 steps in 0 tasks, " + "and a key Dispatch does not hold fails as dispatch read fails for it, NOT_FOUND: not " + `found. ${ISSUE_REFERENCE}`,
|
|
15158
15158
|
arguments: (z) => ({
|
|
15159
15159
|
issue: z.string().describe(ISSUE_REFERENCE)
|
|
15160
15160
|
}),
|
|
@@ -15163,7 +15163,7 @@ var dispatchToolSpecs = [
|
|
|
15163
15163
|
{
|
|
15164
15164
|
name: "dispatch_plans",
|
|
15165
15165
|
example: { project: "INFRA" },
|
|
15166
|
-
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time
|
|
15166
|
+
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time, its count of " + "failed steps, and the experiment and the variant it was drawn into, where its records " + "name one. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>[ variant <experiment>/<variant>]\`. ` + "The line ends with variant <experiment>/<variant> where the records of the issue's " + "newest run name an experiment, and at failed steps <n> where they name none. " + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
|
|
15167
15167
|
arguments: (z) => ({
|
|
15168
15168
|
project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
|
|
15169
15169
|
since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
|
|
@@ -28566,7 +28566,8 @@ function issueLine(issue) {
|
|
|
28566
28566
|
ratingsText(issue.ratings),
|
|
28567
28567
|
timeText(issue.duration_seconds),
|
|
28568
28568
|
"failed steps",
|
|
28569
|
-
issue.failed_steps
|
|
28569
|
+
issue.failed_steps,
|
|
28570
|
+
...issue.experiment == null || issue.variant == null ? [] : [`variant ${issue.experiment}/${issue.variant}`]
|
|
28570
28571
|
].join(" ");
|
|
28571
28572
|
}
|
|
28572
28573
|
async function plansCommand(context) {
|
|
@@ -29595,6 +29596,11 @@ function stepLine(record) {
|
|
|
29595
29596
|
...record.ended_at === null ? ["running", "running"] : [record.ended_at, orDash(record.result)]
|
|
29596
29597
|
].join(" ");
|
|
29597
29598
|
}
|
|
29599
|
+
function variantLines(records) {
|
|
29600
|
+
const newest = Math.max(...records.map((record) => record.generation));
|
|
29601
|
+
const named = records.find((record) => record.generation === newest && record.experiment != null && record.variant != null);
|
|
29602
|
+
return named === undefined ? [] : [`Experiment ${named.experiment}: variant ${named.variant}.`];
|
|
29603
|
+
}
|
|
29598
29604
|
async function stepsCommand(context) {
|
|
29599
29605
|
const { client, issue } = context;
|
|
29600
29606
|
const read = await client.listSteps(issue());
|
|
@@ -29603,6 +29609,7 @@ async function stepsCommand(context) {
|
|
|
29603
29609
|
return {
|
|
29604
29610
|
text: [
|
|
29605
29611
|
`${read.issue}: ${records.length} steps in ${tasks.length} tasks`,
|
|
29612
|
+
...variantLines(records),
|
|
29606
29613
|
...records.map(stepLine)
|
|
29607
29614
|
].join(`
|
|
29608
29615
|
`),
|
package/dist/dispatch.js
CHANGED
|
@@ -15760,7 +15760,7 @@ var dispatchToolSpecs = [
|
|
|
15760
15760
|
{
|
|
15761
15761
|
name: "dispatch_steps",
|
|
15762
15762
|
example: { issue: "DSP-1" },
|
|
15763
|
-
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end. The first line is `<KEY>: <n> steps in <m> tasks`.
|
|
15763
|
+
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end, and the experiment and the variant the issue was drawn into, where " + "its records name one. The first line is `<KEY>: <n> steps in <m> tasks`. Where the " + "records of the issue's newest run name an experiment, the next line is `Experiment " + "<experiment>: variant <variant>.`, and an issue whose newest run's records name none " + "prints no such line. Then each run of a step prints one line, task by task, in the order " + "each task first ran: `<task> " + "<step> <kind> <role> <type> attempt <attempt> <agent> <model> <started_at> <ended_at> " + "<result>`. kind is step, retro or merge. step is the step's place in its task, from 1, " + "and 0 for a retro or a merge. attempt counts the runs of the same task, step and kind, " + "from 1. agent is the claim of the role that ran the step, and model is the model that " + "answered it, as provider/model. result is passed, failed or stopped. A field with no " + "value prints -, and a run that has not ended prints running for its end and its result. " + "A closed issue's steps read too. An issue that no step ran on prints 0 steps in 0 tasks, " + "and a key Dispatch does not hold fails as dispatch read fails for it, NOT_FOUND: not " + `found. ${ISSUE_REFERENCE}`,
|
|
15764
15764
|
arguments: (z) => ({
|
|
15765
15765
|
issue: z.string().describe(ISSUE_REFERENCE)
|
|
15766
15766
|
}),
|
|
@@ -15769,7 +15769,7 @@ var dispatchToolSpecs = [
|
|
|
15769
15769
|
{
|
|
15770
15770
|
name: "dispatch_plans",
|
|
15771
15771
|
example: { project: "INFRA" },
|
|
15772
|
-
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time
|
|
15772
|
+
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time, its count of " + "failed steps, and the experiment and the variant it was drawn into, where its records " + "name one. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>[ variant <experiment>/<variant>]\`. ` + "The line ends with variant <experiment>/<variant> where the records of the issue's " + "newest run name an experiment, and at failed steps <n> where they name none. " + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
|
|
15773
15773
|
arguments: (z) => ({
|
|
15774
15774
|
project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
|
|
15775
15775
|
since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
|
|
@@ -34053,7 +34053,8 @@ function issueLine(issue) {
|
|
|
34053
34053
|
ratingsText(issue.ratings),
|
|
34054
34054
|
timeText(issue.duration_seconds),
|
|
34055
34055
|
"failed steps",
|
|
34056
|
-
issue.failed_steps
|
|
34056
|
+
issue.failed_steps,
|
|
34057
|
+
...issue.experiment == null || issue.variant == null ? [] : [`variant ${issue.experiment}/${issue.variant}`]
|
|
34057
34058
|
].join(" ");
|
|
34058
34059
|
}
|
|
34059
34060
|
async function plansCommand(context) {
|
|
@@ -35082,6 +35083,11 @@ function stepLine(record) {
|
|
|
35082
35083
|
...record.ended_at === null ? ["running", "running"] : [record.ended_at, orDash(record.result)]
|
|
35083
35084
|
].join(" ");
|
|
35084
35085
|
}
|
|
35086
|
+
function variantLines(records) {
|
|
35087
|
+
const newest = Math.max(...records.map((record) => record.generation));
|
|
35088
|
+
const named = records.find((record) => record.generation === newest && record.experiment != null && record.variant != null);
|
|
35089
|
+
return named === undefined ? [] : [`Experiment ${named.experiment}: variant ${named.variant}.`];
|
|
35090
|
+
}
|
|
35085
35091
|
async function stepsCommand(context) {
|
|
35086
35092
|
const { client, issue } = context;
|
|
35087
35093
|
const read = await client.listSteps(issue());
|
|
@@ -35090,6 +35096,7 @@ async function stepsCommand(context) {
|
|
|
35090
35096
|
return {
|
|
35091
35097
|
text: [
|
|
35092
35098
|
`${read.issue}: ${records.length} steps in ${tasks.length} tasks`,
|
|
35099
|
+
...variantLines(records),
|
|
35093
35100
|
...records.map(stepLine)
|
|
35094
35101
|
].join(`
|
|
35095
35102
|
`),
|
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 join23, resolve as resolve4 } 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"
|
|
@@ -37954,7 +37954,7 @@ var dispatchToolSpecs = [
|
|
|
37954
37954
|
{
|
|
37955
37955
|
name: "dispatch_steps",
|
|
37956
37956
|
example: { issue: "DSP-1" },
|
|
37957
|
-
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end. The first line is `<KEY>: <n> steps in <m> tasks`.
|
|
37957
|
+
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end, and the experiment and the variant the issue was drawn into, where " + "its records name one. The first line is `<KEY>: <n> steps in <m> tasks`. Where the " + "records of the issue's newest run name an experiment, the next line is `Experiment " + "<experiment>: variant <variant>.`, and an issue whose newest run's records name none " + "prints no such line. Then each run of a step prints one line, task by task, in the order " + "each task first ran: `<task> " + "<step> <kind> <role> <type> attempt <attempt> <agent> <model> <started_at> <ended_at> " + "<result>`. kind is step, retro or merge. step is the step's place in its task, from 1, " + "and 0 for a retro or a merge. attempt counts the runs of the same task, step and kind, " + "from 1. agent is the claim of the role that ran the step, and model is the model that " + "answered it, as provider/model. result is passed, failed or stopped. A field with no " + "value prints -, and a run that has not ended prints running for its end and its result. " + "A closed issue's steps read too. An issue that no step ran on prints 0 steps in 0 tasks, " + "and a key Dispatch does not hold fails as dispatch read fails for it, NOT_FOUND: not " + `found. ${ISSUE_REFERENCE}`,
|
|
37958
37958
|
arguments: (z) => ({
|
|
37959
37959
|
issue: z.string().describe(ISSUE_REFERENCE)
|
|
37960
37960
|
}),
|
|
@@ -37963,7 +37963,7 @@ var dispatchToolSpecs = [
|
|
|
37963
37963
|
{
|
|
37964
37964
|
name: "dispatch_plans",
|
|
37965
37965
|
example: { project: "INFRA" },
|
|
37966
|
-
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time
|
|
37966
|
+
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time, its count of " + "failed steps, and the experiment and the variant it was drawn into, where its records " + "name one. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>[ variant <experiment>/<variant>]\`. ` + "The line ends with variant <experiment>/<variant> where the records of the issue's " + "newest run name an experiment, and at failed steps <n> where they name none. " + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
|
|
37967
37967
|
arguments: (z) => ({
|
|
37968
37968
|
project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
|
|
37969
37969
|
since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
|
|
@@ -56051,7 +56051,8 @@ function issueLine(issue) {
|
|
|
56051
56051
|
ratingsText(issue.ratings),
|
|
56052
56052
|
timeText(issue.duration_seconds),
|
|
56053
56053
|
"failed steps",
|
|
56054
|
-
issue.failed_steps
|
|
56054
|
+
issue.failed_steps,
|
|
56055
|
+
...issue.experiment == null || issue.variant == null ? [] : [`variant ${issue.experiment}/${issue.variant}`]
|
|
56055
56056
|
].join(" ");
|
|
56056
56057
|
}
|
|
56057
56058
|
async function plansCommand(context) {
|
|
@@ -57050,6 +57051,11 @@ function stepLine(record) {
|
|
|
57050
57051
|
...record.ended_at === null ? ["running", "running"] : [record.ended_at, orDash(record.result)]
|
|
57051
57052
|
].join(" ");
|
|
57052
57053
|
}
|
|
57054
|
+
function variantLines(records) {
|
|
57055
|
+
const newest = Math.max(...records.map((record) => record.generation));
|
|
57056
|
+
const named = records.find((record) => record.generation === newest && record.experiment != null && record.variant != null);
|
|
57057
|
+
return named === undefined ? [] : [`Experiment ${named.experiment}: variant ${named.variant}.`];
|
|
57058
|
+
}
|
|
57053
57059
|
async function stepsCommand(context) {
|
|
57054
57060
|
const { client, issue } = context;
|
|
57055
57061
|
const read = await client.listSteps(issue());
|
|
@@ -57058,6 +57064,7 @@ async function stepsCommand(context) {
|
|
|
57058
57064
|
return {
|
|
57059
57065
|
text: [
|
|
57060
57066
|
`${read.issue}: ${records.length} steps in ${tasks.length} tasks`,
|
|
57067
|
+
...variantLines(records),
|
|
57061
57068
|
...records.map(stepLine)
|
|
57062
57069
|
].join(`
|
|
57063
57070
|
`),
|
|
@@ -63507,57 +63514,18 @@ var import_nats5 = __toESM(require_mod4(), 1);
|
|
|
63507
63514
|
|
|
63508
63515
|
// package.json
|
|
63509
63516
|
var name2 = "@sjawhar/claude-envoy";
|
|
63510
|
-
var version2 = "5.
|
|
63511
|
-
var legion = {
|
|
63512
|
-
daemonApiVersion: 275
|
|
63513
|
-
};
|
|
63517
|
+
var version2 = "5.31.0";
|
|
63514
63518
|
var package_default = {
|
|
63515
63519
|
name: name2,
|
|
63516
63520
|
version: version2,
|
|
63517
63521
|
license: "Apache-2.0",
|
|
63518
63522
|
description: "Claude Code plugin for Legion's Envoy bus",
|
|
63519
63523
|
type: "module",
|
|
63520
|
-
files: [
|
|
63521
|
-
|
|
63522
|
-
|
|
63523
|
-
|
|
63524
|
-
|
|
63525
|
-
"dist/**",
|
|
63526
|
-
"hooks/**",
|
|
63527
|
-
"legion/**",
|
|
63528
|
-
"scripts/**",
|
|
63529
|
-
"skills/**",
|
|
63530
|
-
"src/**",
|
|
63531
|
-
"README.md",
|
|
63532
|
-
"AGENTS.md"
|
|
63533
|
-
],
|
|
63534
|
-
legion,
|
|
63535
|
-
repository: {
|
|
63536
|
-
type: "git",
|
|
63537
|
-
url: "https://github.com/cybermonklabs/legion"
|
|
63538
|
-
},
|
|
63539
|
-
scripts: {
|
|
63540
|
-
channel: "bun bin/envoy-channel.ts",
|
|
63541
|
-
"verify-build": "bash scripts/verify-build.sh",
|
|
63542
|
-
prepack: "bash scripts/pack-skills.sh",
|
|
63543
|
-
postpack: "bash scripts/pack-skills.sh --restore",
|
|
63544
|
-
typecheck: "bunx tsc --noEmit",
|
|
63545
|
-
test: "bun test --timeout=60000",
|
|
63546
|
-
lint: "bunx biome check src/ hooks/ scripts/"
|
|
63547
|
-
},
|
|
63548
|
-
devDependencies: {
|
|
63549
|
-
"@biomejs/biome": "^2.3.14",
|
|
63550
|
-
"@legion/cipher-client": "workspace:*",
|
|
63551
|
-
"@legion/contracts": "workspace:*",
|
|
63552
|
-
"@legion/envoy-client": "workspace:*",
|
|
63553
|
-
"@legion/pi-shared": "workspace:*",
|
|
63554
|
-
"@legion/test-fixtures": "workspace:*",
|
|
63555
|
-
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
63556
|
-
"bun-types": "latest",
|
|
63557
|
-
nats: "^2.29.2",
|
|
63558
|
-
typescript: "^5.3.0",
|
|
63559
|
-
zod: "4.3.6"
|
|
63560
|
-
}
|
|
63524
|
+
files: [".claude-plugin/**", ".mcp.json", ".omp-plugin/**", "bin/**", "dist/**", "hooks/**", "legion/**", "scripts/**", "skills/**", "src/**", "README.md", "AGENTS.md"],
|
|
63525
|
+
repository: { type: "git", url: "https://github.com/cybermonklabs/legion" },
|
|
63526
|
+
scripts: { channel: "bun bin/envoy-channel.ts", "verify-build": "bash scripts/verify-build.sh", prepack: "bash scripts/pack-skills.sh", postpack: "bash scripts/pack-skills.sh --restore", typecheck: "bunx tsc --noEmit", test: "bun test --timeout=60000", lint: "bunx biome check src/ hooks/ scripts/" },
|
|
63527
|
+
devDependencies: { "@biomejs/biome": "^2.3.14", "@legion/cipher-client": "workspace:*", "@legion/contracts": "workspace:*", "@legion/envoy-client": "workspace:*", "@legion/pi-shared": "workspace:*", "@legion/test-fixtures": "workspace:*", "@modelcontextprotocol/sdk": "^1.30.0", "bun-types": "latest", nats: "^2.29.2", typescript: "^5.3.0", zod: "4.3.6" },
|
|
63528
|
+
legion: { daemonApiVersion: 275 }
|
|
63561
63529
|
};
|
|
63562
63530
|
|
|
63563
63531
|
// ../envoy-client/src/inbound-card.ts
|
|
@@ -64941,9 +64909,42 @@ function channelConnectionName(name, bundlePath, packageName) {
|
|
|
64941
64909
|
|
|
64942
64910
|
// src/legion-claim.ts
|
|
64943
64911
|
import { readdir as readdir4, stat as stat5 } from "fs/promises";
|
|
64944
|
-
import { join as
|
|
64912
|
+
import { join as join15 } from "path";
|
|
64945
64913
|
import { setTimeout as delay2 } from "timers/promises";
|
|
64946
64914
|
|
|
64915
|
+
// ../contracts/src/daemon-contract.ts
|
|
64916
|
+
import { existsSync, readdirSync as readdirSync3, readFileSync as readFileSync7 } from "fs";
|
|
64917
|
+
import { dirname as dirname6, join as join13, resolve as resolve3 } from "path";
|
|
64918
|
+
var ENTRY_FIXTURE_NAME = /^[0-9]{14}_.+\.json$/;
|
|
64919
|
+
var DAEMON_API_FIXTURES = join13("packages", "contracts", "fixtures", "daemon-api");
|
|
64920
|
+
function daemonContract(manifest, from) {
|
|
64921
|
+
const declared = manifest.legion?.daemonApiVersion;
|
|
64922
|
+
if (declared !== undefined)
|
|
64923
|
+
return declared;
|
|
64924
|
+
for (let dir = resolve3(from);; dir = dirname6(dir)) {
|
|
64925
|
+
const fixtures = join13(dir, DAEMON_API_FIXTURES);
|
|
64926
|
+
const releasedFile = join13(fixtures, "released-contracts.json");
|
|
64927
|
+
if (existsSync(releasedFile)) {
|
|
64928
|
+
return lastReleased(releasedFile) + entryFixtures(join13(fixtures, "contracts"));
|
|
64929
|
+
}
|
|
64930
|
+
if (dirname6(dir) === dir)
|
|
64931
|
+
break;
|
|
64932
|
+
}
|
|
64933
|
+
throw new Error(`the plugin's package.json holds no legion.daemonApiVersion, which every pack writes, and ${from} is in no checkout: no directory from it up holds ${join13(DAEMON_API_FIXTURES, "released-contracts.json")}`);
|
|
64934
|
+
}
|
|
64935
|
+
function lastReleased(file) {
|
|
64936
|
+
const released = JSON.parse(readFileSync7(file, "utf8"));
|
|
64937
|
+
if (!Array.isArray(released) || released.length === 0 || !released.every((contract, at) => Number.isInteger(contract) && (at === 0 || contract > released[at - 1]))) {
|
|
64938
|
+
throw new Error(`${file} is not a list of contract numbers in strictly ascending order`);
|
|
64939
|
+
}
|
|
64940
|
+
return released[released.length - 1];
|
|
64941
|
+
}
|
|
64942
|
+
function entryFixtures(dir) {
|
|
64943
|
+
if (!existsSync(dir))
|
|
64944
|
+
return 0;
|
|
64945
|
+
return readdirSync3(dir).filter((name) => ENTRY_FIXTURE_NAME.test(name)).length;
|
|
64946
|
+
}
|
|
64947
|
+
|
|
64947
64948
|
// ../pi-shared/src/stall-limits.ts
|
|
64948
64949
|
var DEFAULT_STALL_LIMITS = {
|
|
64949
64950
|
reminderMs: 300000,
|
|
@@ -66434,8 +66435,8 @@ function listenerAskedToClaimAgain(error) {
|
|
|
66434
66435
|
|
|
66435
66436
|
// src/legion-phase-hook.ts
|
|
66436
66437
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
66437
|
-
import { readFileSync as
|
|
66438
|
-
import { dirname as
|
|
66438
|
+
import { readFileSync as readFileSync8, renameSync as renameSync3, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
66439
|
+
import { dirname as dirname7, join as join14 } from "path";
|
|
66439
66440
|
|
|
66440
66441
|
// ../pi-shared/src/phase-reminder.ts
|
|
66441
66442
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
@@ -66900,7 +66901,7 @@ function phaseHookToolDefinition() {
|
|
|
66900
66901
|
};
|
|
66901
66902
|
}
|
|
66902
66903
|
function phaseStallFile(configDir, sessionID) {
|
|
66903
|
-
return
|
|
66904
|
+
return join14(configDir, `legion-phase-stall-${sessionID}.json`);
|
|
66904
66905
|
}
|
|
66905
66906
|
function paneReminderLog(write) {
|
|
66906
66907
|
const line = (level, message, context) => {
|
|
@@ -66915,7 +66916,7 @@ var NO_RECORD = { entry: undefined, recreatedNoticeSent: false };
|
|
|
66915
66916
|
function readPhaseStallRecord(file, log) {
|
|
66916
66917
|
let raw;
|
|
66917
66918
|
try {
|
|
66918
|
-
raw =
|
|
66919
|
+
raw = readFileSync8(file, "utf8");
|
|
66919
66920
|
} catch (error) {
|
|
66920
66921
|
const missing = typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
66921
66922
|
if (!missing) {
|
|
@@ -66953,7 +66954,7 @@ function readPhaseStallRecord(file, log) {
|
|
|
66953
66954
|
};
|
|
66954
66955
|
}
|
|
66955
66956
|
function writePhaseStallRecord(file, entry, recreatedNoticeSent, log) {
|
|
66956
|
-
const temporary =
|
|
66957
|
+
const temporary = join14(dirname7(file), `.legion-phase-stall-${randomUUID7()}`);
|
|
66957
66958
|
try {
|
|
66958
66959
|
writeFileSync4(temporary, JSON.stringify({ ...entry, ...recreatedNoticeSent ? { recreatedNoticeSent } : {} }), { mode: 384 });
|
|
66959
66960
|
renameSync3(temporary, file);
|
|
@@ -67127,6 +67128,7 @@ function createPhaseHookEndpoint(deps) {
|
|
|
67127
67128
|
}
|
|
67128
67129
|
|
|
67129
67130
|
// src/legion-claim.ts
|
|
67131
|
+
var PLUGIN_CONTRACT = daemonContract(package_default, import.meta.dir);
|
|
67130
67132
|
async function legionPane(env) {
|
|
67131
67133
|
const pointer = env["LEGION_BOOT_TOKEN_FILE"];
|
|
67132
67134
|
if (pointer === undefined && configuredValue(env["LEGION_BOOT_TOKEN"]) === undefined) {
|
|
@@ -67147,7 +67149,7 @@ async function legionPane(env) {
|
|
|
67147
67149
|
};
|
|
67148
67150
|
}
|
|
67149
67151
|
function paneDaemonClient(daemonUrl) {
|
|
67150
|
-
return createLegionDaemonClient(daemonUrl, { pluginContract:
|
|
67152
|
+
return createLegionDaemonClient(daemonUrl, { pluginContract: PLUGIN_CONTRACT });
|
|
67151
67153
|
}
|
|
67152
67154
|
function logLegion(line) {
|
|
67153
67155
|
process.stderr.write(`[legion] ${line}
|
|
@@ -67161,12 +67163,12 @@ function stopPane(why) {
|
|
|
67161
67163
|
endPane();
|
|
67162
67164
|
}
|
|
67163
67165
|
async function waitForTranscript(configDir, sessionID, signal, pollMs = 100) {
|
|
67164
|
-
const projects =
|
|
67166
|
+
const projects = join15(configDir, "projects");
|
|
67165
67167
|
const name = `${sessionID}.jsonl`;
|
|
67166
67168
|
for (;; ) {
|
|
67167
67169
|
signal.throwIfAborted();
|
|
67168
67170
|
for (const directory of await readdir4(projects).catch(() => [])) {
|
|
67169
|
-
const file =
|
|
67171
|
+
const file = join15(projects, directory, name);
|
|
67170
67172
|
if (await isFile(file))
|
|
67171
67173
|
return file;
|
|
67172
67174
|
}
|
|
@@ -67205,7 +67207,7 @@ function startLegionClaim(deps) {
|
|
|
67205
67207
|
sessionId: sessionID,
|
|
67206
67208
|
ompSessionFile: transcript,
|
|
67207
67209
|
agentId: sessionID,
|
|
67208
|
-
pluginContract:
|
|
67210
|
+
pluginContract: PLUGIN_CONTRACT
|
|
67209
67211
|
},
|
|
67210
67212
|
setCapability: (registered) => {
|
|
67211
67213
|
capability = registered;
|
|
@@ -67446,11 +67448,11 @@ var STALE_ENTRY_INSTRUCTION = "End this turn without completing. The task of the
|
|
|
67446
67448
|
function legionToolDescription(host) {
|
|
67447
67449
|
return "Perform the workflow operation the Legion daemon assigned this role. The daemon advances phases; this tool cannot spawn workers. " + (host.before ?? "") + "handoff_complete (phase workers alone: the daemon refuses an architect's completion, with ACCEPTANCE_IS_SIGN_OFF where nothing else refuses it first, since an architect accepts with sign_off; " + "the daemon accepts a completion only from the role working the issue's current phase, " + "or a role's first completion of the phase it left, which it records and which moves nothing, " + "and the checking role's report on a look of its closed issue's production check) reports this phase complete: `summary` (two sentences for the " + "architect), `verdict` pass|fail from the tester alone on a phase completion (the daemon refuses a verdict from " + "any other role there) and pass|pending|fail on a production check report (pending: production does not carry the merge " + "yet, or carries it with a requirement only the deploy can show still unobserved and a look still to follow; on the check's last look, only for an issue with no such requirement). " + "A tester's fail may name `return_to`, the place of a step of the task its issue runs, 1 for its first: the step the task goes back " + "to; without it, the task goes back to the first implementation step before the step that failed. Only a completion with the verdict " + "fail names it (RETURN_TO_NEEDS_FAIL), a place below 1 is refused (INVALID_RETURN_TO), and so is a step the task cannot go back to " + "(RETURN_REFUSED). " + "A planning, implementing, testing or reviewing phase ends with a handoff record on the " + "Dispatch issue: write it with `dispatch handoff-write --issue <issue> --phase <plan|implement|test|review> --body-file <file>` before " + "calling. This call reads from Dispatch the newest record of the phase your role works or, once the issue has moved on, of the phase it left, " + "and reports it with `commit`, the head that record's body names " + "(`head`, the 40-character lower-case commit the work it reports was done against); in implementing, the implementer's must be the commit its " + "workspace stands on, `@-`, pushed to `legion/<issue>@origin`, so push the branch first; retro, the merger's completion and a phase you left with no record, or with an implement record naming no head, report the commit the workspace stands on. It " + "refuses, posting nothing, a phase you work with no record, a Dispatch that does not answer, and, in implementing, an implement record naming no head, an " + "implementer's `@-` not yet on `legion/<issue>@origin`, or an implement record whose head is not that pushed `@-`, each naming the remedy. A production check report " + "(the task whose first line is `Production check of <KEY>`, handed once the merge closed the issue to the role the check records) needs no " + "handoff and no commit: it carries its verdict and summary alone. A pending report also names `wake_at`, an RFC 3339 time: when you want the " + "next look. A pass, a fail, and a pending on the check's last look end the check, so none of them carries `wake_at` " + "(CHECK_WAKE_UNEXPECTED), and a pending on any other look is refused without one (CHECK_WAKE_REQUIRED). A report on an issue whose check is " + "closed or never opened is refused (CHECK_NOT_OPEN), and so is one from a role the check does not record (CHECK_ROLE_MISMATCH). " + `The completion that ends the retro carries \`plan_rating\` (${LEGION_PLAN_RATING_LEAST} to ${LEGION_PLAN_RATING_MOST}) and \`plan_reason\`, as ` + "skill://legion-retro says, and the daemon refuses a completion that breaks that skill's rating rule " + "(PLAN_RATING_REQUIRED, PLAN_RATING_UNEXPECTED or PLAN_RATING_INPUT). " + "The daemon refuses " + "HANDOFF_SESSION_MISMATCH (another session wrote the record), HANDOFF_NOT_NEW (the record is the one you named for your previous phase: " + "write this phase's handoff), " + "HANDOFF_STALE_ENTRY (this completion is of a phase entry behind the one your role's phases row names, because the phase was entered " + `again while your turn ran, and nothing was recorded. ${STALE_ENTRY_INSTRUCTION}), the implementer's completion of implementing with no open ` + "pull request on `legion/<issue>` and none recorded " + "merged (HANDOFF_NO_PULL_REQUEST: open it; one naming a closed pull request is the architect's to decide); a refused completion changed " + "nothing, so fix what it names and complete again. " + "ready_for_update answers the daemon's update message on this issue's pod: `round` is the round id that message names, and the " + "daemon takes your answer for that round alone. The reviewer creates no commit and pushes nothing, so each commit " + "and push this description names is not its own, and the merger pushes the merge of the base it made. Push every commit you want kept to the issue branch " + "first. Then let each subagent and each background job that you started finish, or stop it. Commit and push what it made " + "before you answer. The daemon replaces the pod and its disk when the round ends. The round ends at the moment the message " + "names. It can end earlier, once every role has answered, no role is in a turn and each role's last report names no running " + "subagent or background job. No answer delays that moment, and the end of a turn is no answer. If a subagent or a background " + "job finishes after you answer, commit and push what it made. Then call ready_for_update again with the same round. " + "The call ends no phase. The daemon holds your next task until your process comes back on the new pod, in this same session. " + (host.after ?? "") + `What a later phase needs goes in your handoff; a question for another live role goes to its role topic with ${host.envoyPublish}.`;
|
|
67448
67450
|
}
|
|
67449
|
-
function pluginBuildOf(manifest) {
|
|
67451
|
+
function pluginBuildOf(manifest, from) {
|
|
67450
67452
|
return {
|
|
67451
67453
|
name: manifest.name,
|
|
67452
67454
|
version: manifest.version,
|
|
67453
|
-
pluginContract: manifest
|
|
67455
|
+
pluginContract: daemonContract(manifest, from)
|
|
67454
67456
|
};
|
|
67455
67457
|
}
|
|
67456
67458
|
async function mintClaimGrant(daemon, claim) {
|
|
@@ -67718,7 +67720,7 @@ async function completeHandoff(runtime, args, rating) {
|
|
|
67718
67720
|
}
|
|
67719
67721
|
|
|
67720
67722
|
// src/legion-tool.ts
|
|
67721
|
-
var BUILD = pluginBuildOf(package_default);
|
|
67723
|
+
var BUILD = pluginBuildOf(package_default, import.meta.dir);
|
|
67722
67724
|
var LEGION_TOOL_NAME = "legion";
|
|
67723
67725
|
function legionToolDefinition() {
|
|
67724
67726
|
return {
|
|
@@ -67753,7 +67755,7 @@ import {
|
|
|
67753
67755
|
createServer,
|
|
67754
67756
|
request as httpRequest
|
|
67755
67757
|
} from "http";
|
|
67756
|
-
import { dirname as
|
|
67758
|
+
import { dirname as dirname8 } from "path";
|
|
67757
67759
|
|
|
67758
67760
|
// hooks/mod-protocol.ts
|
|
67759
67761
|
var MOD_HEALTH_MARKER = "claude-envoy-mod";
|
|
@@ -67975,7 +67977,7 @@ async function privateDirectory(path) {
|
|
|
67975
67977
|
}
|
|
67976
67978
|
}
|
|
67977
67979
|
async function bind(server, socketPath) {
|
|
67978
|
-
await privateDirectory(
|
|
67980
|
+
await privateDirectory(dirname8(socketPath));
|
|
67979
67981
|
if (await exists2(socketPath)) {
|
|
67980
67982
|
if (await probeHealth(socketPath, MOD_PROBE_TIMEOUT_MS)) {
|
|
67981
67983
|
throw new Error(`another claude-envoy server already serves this session at ${socketPath}`);
|
|
@@ -68366,7 +68368,7 @@ function modSession(options) {
|
|
|
68366
68368
|
}
|
|
68367
68369
|
|
|
68368
68370
|
// src/replay-state.ts
|
|
68369
|
-
import { join as
|
|
68371
|
+
import { join as join16 } from "path";
|
|
68370
68372
|
|
|
68371
68373
|
// src/state-file.ts
|
|
68372
68374
|
import { readFile as readFile8 } from "fs/promises";
|
|
@@ -68396,7 +68398,7 @@ var ReplayStateFileSchema = LedgerSnapshotSchema.extend({
|
|
|
68396
68398
|
consumer: ConsumerDeliverySnapshotSchema.optional()
|
|
68397
68399
|
});
|
|
68398
68400
|
function replayStateFile(stateDirectory, sessionId) {
|
|
68399
|
-
return
|
|
68401
|
+
return join16(stateDirectory, `replay-${encodeURIComponent(sessionId)}.json`);
|
|
68400
68402
|
}
|
|
68401
68403
|
async function readReplayState(file) {
|
|
68402
68404
|
return await readStateFile(file, ReplayStateFileSchema, { ledger: [] }, "holds no delivery state");
|
|
@@ -68428,12 +68430,12 @@ import { basename as basename4 } from "path";
|
|
|
68428
68430
|
|
|
68429
68431
|
// ../envoy-client/src/process-ancestry.ts
|
|
68430
68432
|
import { execFileSync } from "child_process";
|
|
68431
|
-
import { readFileSync as
|
|
68433
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
68432
68434
|
var MAX_ANCESTORS = 64;
|
|
68433
68435
|
var PARENT_LOOKUP_MS = 1000;
|
|
68434
68436
|
function procParentPid(pid) {
|
|
68435
68437
|
try {
|
|
68436
|
-
const stat =
|
|
68438
|
+
const stat = readFileSync9(`/proc/${pid}/stat`, "utf8");
|
|
68437
68439
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
68438
68440
|
return Number.isInteger(parent) ? parent : undefined;
|
|
68439
68441
|
} catch {
|
|
@@ -68475,7 +68477,7 @@ function isAncestor(candidate, pid = process.pid) {
|
|
|
68475
68477
|
}
|
|
68476
68478
|
function procCommand(pid) {
|
|
68477
68479
|
try {
|
|
68478
|
-
return
|
|
68480
|
+
return readFileSync9(`/proc/${pid}/comm`, "utf8").trim();
|
|
68479
68481
|
} catch {
|
|
68480
68482
|
return;
|
|
68481
68483
|
}
|
|
@@ -68944,7 +68946,7 @@ function createUserTurnRouter(options) {
|
|
|
68944
68946
|
}
|
|
68945
68947
|
|
|
68946
68948
|
// src/user-turn-state.ts
|
|
68947
|
-
import { join as
|
|
68949
|
+
import { join as join17 } from "path";
|
|
68948
68950
|
var TURNS_DIRECTORY = "turns";
|
|
68949
68951
|
var HANDLED_ATTEMPTS_MAX = 1000;
|
|
68950
68952
|
var DELIVERED_ROWS_MAX = 1000;
|
|
@@ -68954,7 +68956,7 @@ var UserTurnStateSchema = object({
|
|
|
68954
68956
|
rows: array(DeliveredRowSchema).default([])
|
|
68955
68957
|
});
|
|
68956
68958
|
function userTurnStateFile(stateDirectory, sessionId) {
|
|
68957
|
-
return
|
|
68959
|
+
return join17(stateDirectory, TURNS_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
|
|
68958
68960
|
}
|
|
68959
68961
|
async function readUserTurnState(file) {
|
|
68960
68962
|
return await readStateFile(file, UserTurnStateSchema, { handled: [], rows: [] }, "holds no record of this session's turns");
|
|
@@ -68992,7 +68994,7 @@ function userTurnState(file, restored) {
|
|
|
68992
68994
|
};
|
|
68993
68995
|
}
|
|
68994
68996
|
async function pruneStaleSessionTurns(stateDirectory) {
|
|
68995
|
-
await pruneStateDirectory(
|
|
68997
|
+
await pruneStateDirectory(join17(stateDirectory, TURNS_DIRECTORY), writtenLongAgo);
|
|
68996
68998
|
}
|
|
68997
68999
|
|
|
68998
69000
|
// src/envoy-channel-server.ts
|
|
@@ -70726,10 +70728,10 @@ function startCodexAgentStream(options) {
|
|
|
70726
70728
|
// src/codex/codex-cli.ts
|
|
70727
70729
|
import { spawn } from "child_process";
|
|
70728
70730
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
70729
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
70730
|
-
import { join as
|
|
70731
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync10, writeFileSync as writeFileSync5 } from "fs";
|
|
70732
|
+
import { join as join18 } from "path";
|
|
70731
70733
|
var QUEUE_TIMEOUT_MS = 30000;
|
|
70732
|
-
function codexProcessEnv(pid, fallback, read = (path) =>
|
|
70734
|
+
function codexProcessEnv(pid, fallback, read = (path) => readFileSync10(path, "utf8")) {
|
|
70733
70735
|
let raw;
|
|
70734
70736
|
try {
|
|
70735
70737
|
raw = read(`/proc/${pid}/environ`);
|
|
@@ -70796,7 +70798,7 @@ function fitArgument(text, spillDirectory) {
|
|
|
70796
70798
|
throw new Error(`the message is ${Buffer.byteLength(text)} bytes, over what codex queue takes`);
|
|
70797
70799
|
}
|
|
70798
70800
|
mkdirSync4(spillDirectory, { mode: 448, recursive: true });
|
|
70799
|
-
const file =
|
|
70801
|
+
const file = join18(spillDirectory, `${Date.now()}-${randomBytes2(4).toString("hex")}.txt`);
|
|
70800
70802
|
writeFileSync5(file, text, { mode: 384 });
|
|
70801
70803
|
return `${text.slice(0, QUEUE_HEAD_CHARS)}
|
|
70802
70804
|
|
|
@@ -70922,10 +70924,10 @@ function askSideQuestion(command, threadId, question, timeoutMs = SIDE_QUESTION_
|
|
|
70922
70924
|
// src/codex/codex-inbox.ts
|
|
70923
70925
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
70924
70926
|
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
|
|
70927
|
+
import { join as join19 } from "path";
|
|
70926
70928
|
var TAKEN_DIRECTORY = { hook: "taken", server: "queued" };
|
|
70927
70929
|
function codexInboxDirectory(stateDirectory, sessionId) {
|
|
70928
|
-
return
|
|
70930
|
+
return join19(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
|
|
70929
70931
|
}
|
|
70930
70932
|
var lastOrder = 0;
|
|
70931
70933
|
function inboxItemName() {
|
|
@@ -70934,17 +70936,17 @@ function inboxItemName() {
|
|
|
70934
70936
|
return `${String(order).padStart(15, "0")}-${randomBytes3(4).toString("hex")}.json`;
|
|
70935
70937
|
}
|
|
70936
70938
|
async function putInbox(directory, item, name = inboxItemName()) {
|
|
70937
|
-
const waiting =
|
|
70939
|
+
const waiting = join19(directory, "waiting");
|
|
70938
70940
|
await mkdir4(waiting, { recursive: true, mode: 448 });
|
|
70939
|
-
const temporary =
|
|
70941
|
+
const temporary = join19(directory, `.${name}.tmp`);
|
|
70940
70942
|
await writeFile2(temporary, JSON.stringify(item), { mode: 384 });
|
|
70941
|
-
await rename4(temporary,
|
|
70943
|
+
await rename4(temporary, join19(waiting, name));
|
|
70942
70944
|
return name;
|
|
70943
70945
|
}
|
|
70944
70946
|
async function takenBy(directory, name) {
|
|
70945
70947
|
for (const taker of ["hook", "server"]) {
|
|
70946
70948
|
try {
|
|
70947
|
-
await readFile9(
|
|
70949
|
+
await readFile9(join19(directory, TAKEN_DIRECTORY[taker], name));
|
|
70948
70950
|
return taker;
|
|
70949
70951
|
} catch {}
|
|
70950
70952
|
}
|
|
@@ -70952,14 +70954,14 @@ async function takenBy(directory, name) {
|
|
|
70952
70954
|
}
|
|
70953
70955
|
async function withdrawWaiting(directory, name) {
|
|
70954
70956
|
try {
|
|
70955
|
-
await rm6(
|
|
70957
|
+
await rm6(join19(directory, "waiting", name));
|
|
70956
70958
|
return true;
|
|
70957
70959
|
} catch {
|
|
70958
70960
|
return false;
|
|
70959
70961
|
}
|
|
70960
70962
|
}
|
|
70961
70963
|
async function discardWaiting(directory, keep = () => false) {
|
|
70962
|
-
const waiting =
|
|
70964
|
+
const waiting = join19(directory, "waiting");
|
|
70963
70965
|
let names;
|
|
70964
70966
|
try {
|
|
70965
70967
|
names = await readdir5(waiting);
|
|
@@ -70971,7 +70973,7 @@ async function discardWaiting(directory, keep = () => false) {
|
|
|
70971
70973
|
if (!name.endsWith(".json") || keep(name))
|
|
70972
70974
|
continue;
|
|
70973
70975
|
try {
|
|
70974
|
-
await rm6(
|
|
70976
|
+
await rm6(join19(waiting, name));
|
|
70975
70977
|
removed++;
|
|
70976
70978
|
} catch {}
|
|
70977
70979
|
}
|
|
@@ -70979,7 +70981,7 @@ async function discardWaiting(directory, keep = () => false) {
|
|
|
70979
70981
|
}
|
|
70980
70982
|
var HOOK_CONTEXT_MAX_BYTES = 8000;
|
|
70981
70983
|
async function takeInbox(directory, taker, maxContextBytes) {
|
|
70982
|
-
const waiting =
|
|
70984
|
+
const waiting = join19(directory, "waiting");
|
|
70983
70985
|
let names;
|
|
70984
70986
|
try {
|
|
70985
70987
|
names = (await readdir5(waiting)).filter((name) => name.endsWith(".json")).sort();
|
|
@@ -70988,14 +70990,14 @@ async function takeInbox(directory, taker, maxContextBytes) {
|
|
|
70988
70990
|
}
|
|
70989
70991
|
if (names.length === 0)
|
|
70990
70992
|
return [];
|
|
70991
|
-
const destination =
|
|
70993
|
+
const destination = join19(directory, TAKEN_DIRECTORY[taker]);
|
|
70992
70994
|
await mkdir4(destination, { recursive: true, mode: 448 });
|
|
70993
70995
|
const taken = [];
|
|
70994
70996
|
for (const name of names) {
|
|
70995
70997
|
if (maxContextBytes !== undefined) {
|
|
70996
70998
|
let waitingItem;
|
|
70997
70999
|
try {
|
|
70998
|
-
waitingItem = JSON.parse(await readFile9(
|
|
71000
|
+
waitingItem = JSON.parse(await readFile9(join19(waiting, name), "utf8"));
|
|
70999
71001
|
} catch {
|
|
71000
71002
|
continue;
|
|
71001
71003
|
}
|
|
@@ -71006,12 +71008,12 @@ async function takeInbox(directory, taker, maxContextBytes) {
|
|
|
71006
71008
|
break;
|
|
71007
71009
|
}
|
|
71008
71010
|
try {
|
|
71009
|
-
await rename4(
|
|
71011
|
+
await rename4(join19(waiting, name), join19(destination, name));
|
|
71010
71012
|
} catch {
|
|
71011
71013
|
continue;
|
|
71012
71014
|
}
|
|
71013
71015
|
try {
|
|
71014
|
-
const parsed = JSON.parse(await readFile9(
|
|
71016
|
+
const parsed = JSON.parse(await readFile9(join19(destination, name), "utf8"));
|
|
71015
71017
|
if (typeof parsed === "object" && parsed !== null && typeof parsed.content === "string") {
|
|
71016
71018
|
taken.push({ item: parsed, name });
|
|
71017
71019
|
}
|
|
@@ -71169,14 +71171,14 @@ function createCodexDelivery(options) {
|
|
|
71169
71171
|
|
|
71170
71172
|
// src/codex/codex-owner.ts
|
|
71171
71173
|
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
|
|
71174
|
+
import { join as join21 } from "path";
|
|
71173
71175
|
|
|
71174
71176
|
// src/codex/codex-session-record.ts
|
|
71175
71177
|
import { spawnSync } from "child_process";
|
|
71176
|
-
import { readFileSync as
|
|
71178
|
+
import { readFileSync as readFileSync11, readlinkSync as readlinkSync2, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
|
|
71177
71179
|
import { mkdir as mkdir5, readFile as readFile10, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
|
|
71178
71180
|
import { homedir as homedir3 } from "os";
|
|
71179
|
-
import { basename as basename5, dirname as
|
|
71181
|
+
import { basename as basename5, dirname as dirname9, join as join20 } from "path";
|
|
71180
71182
|
var CodexSessionRecord = object({
|
|
71181
71183
|
session_id: string2().min(1),
|
|
71182
71184
|
transcript_path: string2().nullable(),
|
|
@@ -71187,14 +71189,14 @@ var CodexSessionRecord = object({
|
|
|
71187
71189
|
codex_started: string2().nullable().default(null)
|
|
71188
71190
|
});
|
|
71189
71191
|
function codexSessionRecordFile(stateDirectory, pid) {
|
|
71190
|
-
return
|
|
71192
|
+
return join20(stateDirectory, "codex-sessions", `${pid}.json`);
|
|
71191
71193
|
}
|
|
71192
71194
|
function codexEndedFile(stateDirectory, pid, sessionId) {
|
|
71193
|
-
return
|
|
71195
|
+
return join20(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
|
|
71194
71196
|
}
|
|
71195
71197
|
async function markSessionEnded(stateDirectory, pid, sessionId) {
|
|
71196
71198
|
const marker = codexEndedFile(stateDirectory, pid, sessionId);
|
|
71197
|
-
await mkdir5(
|
|
71199
|
+
await mkdir5(dirname9(marker), { mode: 448, recursive: true });
|
|
71198
71200
|
await writeFile3(marker, "", { mode: 384 });
|
|
71199
71201
|
const now = new Date;
|
|
71200
71202
|
await utimes3(codexSessionRecordFile(stateDirectory, pid), now, now);
|
|
@@ -71220,7 +71222,7 @@ async function sessionEnded(file) {
|
|
|
71220
71222
|
}
|
|
71221
71223
|
}
|
|
71222
71224
|
async function writeCodexSessionRecord(file, value) {
|
|
71223
|
-
await mkdir5(
|
|
71225
|
+
await mkdir5(dirname9(file), { recursive: true, mode: 448 });
|
|
71224
71226
|
const temporary = `${file}.${process.pid}.tmp`;
|
|
71225
71227
|
await writeFile3(temporary, JSON.stringify(value), { mode: 384 });
|
|
71226
71228
|
await rename5(temporary, file);
|
|
@@ -71235,17 +71237,17 @@ async function readCodexSessionRecord(file) {
|
|
|
71235
71237
|
}
|
|
71236
71238
|
function codexHome(env) {
|
|
71237
71239
|
const set = env["CODEX_HOME"];
|
|
71238
|
-
return set !== undefined && set !== "" ? set :
|
|
71240
|
+
return set !== undefined && set !== "" ? set : join20(env["HOME"] || homedir3(), ".codex");
|
|
71239
71241
|
}
|
|
71240
71242
|
function codexPluginDataDirectory(pluginRoot) {
|
|
71241
71243
|
const version = pluginRoot;
|
|
71242
|
-
const plugin =
|
|
71243
|
-
const marketplace =
|
|
71244
|
-
const cache =
|
|
71245
|
-
const plugins =
|
|
71244
|
+
const plugin = dirname9(version);
|
|
71245
|
+
const marketplace = dirname9(plugin);
|
|
71246
|
+
const cache = dirname9(marketplace);
|
|
71247
|
+
const plugins = dirname9(cache);
|
|
71246
71248
|
if (basename5(cache) !== "cache" || basename5(plugins) !== "plugins")
|
|
71247
71249
|
return;
|
|
71248
|
-
return
|
|
71250
|
+
return join20(plugins, "data", `${basename5(plugin)}-${basename5(marketplace)}`);
|
|
71249
71251
|
}
|
|
71250
71252
|
var MAX_ANCESTORS2 = 16;
|
|
71251
71253
|
function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
@@ -71259,14 +71261,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
|
|
|
71259
71261
|
}
|
|
71260
71262
|
function procComm(pid) {
|
|
71261
71263
|
try {
|
|
71262
|
-
return
|
|
71264
|
+
return readFileSync11(`/proc/${pid}/comm`, "utf8").trim();
|
|
71263
71265
|
} catch {
|
|
71264
71266
|
return;
|
|
71265
71267
|
}
|
|
71266
71268
|
}
|
|
71267
71269
|
function procParent(pid) {
|
|
71268
71270
|
try {
|
|
71269
|
-
const stat =
|
|
71271
|
+
const stat = readFileSync11(`/proc/${pid}/stat`, "utf8");
|
|
71270
71272
|
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
71271
71273
|
return Number.isInteger(parent) ? parent : undefined;
|
|
71272
71274
|
} catch {
|
|
@@ -71280,7 +71282,7 @@ var PS_OPTIONS = {
|
|
|
71280
71282
|
};
|
|
71281
71283
|
function procStarted(pid) {
|
|
71282
71284
|
try {
|
|
71283
|
-
const stat =
|
|
71285
|
+
const stat = readFileSync11(`/proc/${pid}/stat`, "utf8");
|
|
71284
71286
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
71285
71287
|
} catch {
|
|
71286
71288
|
return;
|
|
@@ -71301,7 +71303,7 @@ function recordOfProcess(record, pid) {
|
|
|
71301
71303
|
function sharedAppServer(pid) {
|
|
71302
71304
|
let argv;
|
|
71303
71305
|
try {
|
|
71304
|
-
argv =
|
|
71306
|
+
argv = readFileSync11(`/proc/${pid}/cmdline`, "utf8").split("\x00");
|
|
71305
71307
|
} catch {
|
|
71306
71308
|
const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
|
|
71307
71309
|
if (ps.status !== 0)
|
|
@@ -71347,11 +71349,11 @@ function codexSubcommand(args) {
|
|
|
71347
71349
|
}
|
|
71348
71350
|
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.";
|
|
71349
71351
|
async function pruneCodexSessionRecords(stateDirectory) {
|
|
71350
|
-
await pruneStateDirectory(
|
|
71352
|
+
await pruneStateDirectory(join20(stateDirectory, "codex-sessions"), (file) => {
|
|
71351
71353
|
const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename5(file));
|
|
71352
71354
|
return match !== null && !processExists(Number(match[1]));
|
|
71353
71355
|
});
|
|
71354
|
-
await pruneStateDirectory(
|
|
71356
|
+
await pruneStateDirectory(join20(stateDirectory, "codex-servers"), (file) => {
|
|
71355
71357
|
const name = basename5(file);
|
|
71356
71358
|
return /^\d+$/.test(name) && !processExists(Number(name));
|
|
71357
71359
|
});
|
|
@@ -71366,7 +71368,7 @@ function codexExecutable(pid) {
|
|
|
71366
71368
|
|
|
71367
71369
|
// src/codex/codex-owner.ts
|
|
71368
71370
|
function codexServersDirectory(stateDirectory, codexPid) {
|
|
71369
|
-
return
|
|
71371
|
+
return join21(stateDirectory, "codex-servers", String(codexPid));
|
|
71370
71372
|
}
|
|
71371
71373
|
var ENTRY_NAME = /^(\d+)\.json$/;
|
|
71372
71374
|
var TEMPORARY_NAME = /^\.\d+\.\d+\.tmp$/;
|
|
@@ -71375,13 +71377,13 @@ function entryName(entry) {
|
|
|
71375
71377
|
}
|
|
71376
71378
|
async function registerServer(directory, pid, started, list = (path) => readdir6(path)) {
|
|
71377
71379
|
await mkdir6(directory, { mode: 448, recursive: true });
|
|
71378
|
-
const temporary =
|
|
71380
|
+
const temporary = join21(directory, `.${pid}.${process.hrtime.bigint()}.tmp`);
|
|
71379
71381
|
await writeFile4(temporary, JSON.stringify({ pid, started }), { mode: 384 });
|
|
71380
71382
|
try {
|
|
71381
71383
|
let seq = Math.max(0, ...numbered(await list(directory)).map(({ seq: taken }) => taken)) + 1;
|
|
71382
71384
|
for (;; ) {
|
|
71383
71385
|
try {
|
|
71384
|
-
await place(temporary,
|
|
71386
|
+
await place(temporary, join21(directory, entryName({ seq })), pid, started);
|
|
71385
71387
|
return { pid, seq, started };
|
|
71386
71388
|
} catch (error) {
|
|
71387
71389
|
if (error.code !== "EEXIST")
|
|
@@ -71409,7 +71411,7 @@ async function place(temporary, target, pid, started) {
|
|
|
71409
71411
|
await writeFile4(target, JSON.stringify({ pid, started }), { flag: "wx", mode: 384 });
|
|
71410
71412
|
}
|
|
71411
71413
|
async function unregisterServer(directory, self2) {
|
|
71412
|
-
const file =
|
|
71414
|
+
const file = join21(directory, entryName(self2));
|
|
71413
71415
|
const named = await readFile11(file, "utf8").then(serverOf, () => {
|
|
71414
71416
|
return;
|
|
71415
71417
|
});
|
|
@@ -71473,7 +71475,7 @@ async function readEntries(directory, probe, now = Date.now) {
|
|
|
71473
71475
|
for (const name of names.filter((each) => TEMPORARY_NAME.test(each))) {
|
|
71474
71476
|
let text;
|
|
71475
71477
|
try {
|
|
71476
|
-
text = await readFile11(
|
|
71478
|
+
text = await readFile11(join21(directory, name), "utf8");
|
|
71477
71479
|
} catch {
|
|
71478
71480
|
publishing = true;
|
|
71479
71481
|
break;
|
|
@@ -71489,13 +71491,13 @@ async function readEntries(directory, probe, now = Date.now) {
|
|
|
71489
71491
|
for (const { name, seq } of numbered(names)) {
|
|
71490
71492
|
let text;
|
|
71491
71493
|
try {
|
|
71492
|
-
text = await readFile11(
|
|
71494
|
+
text = await readFile11(join21(directory, name), "utf8");
|
|
71493
71495
|
} catch {
|
|
71494
71496
|
continue;
|
|
71495
71497
|
}
|
|
71496
71498
|
const server = serverOf(text);
|
|
71497
71499
|
if (server === undefined) {
|
|
71498
|
-
const written = await stat7(
|
|
71500
|
+
const written = await stat7(join21(directory, name)).then((info) => info.mtimeMs, () => {
|
|
71499
71501
|
return;
|
|
71500
71502
|
});
|
|
71501
71503
|
if (written === undefined)
|
|
@@ -71523,7 +71525,7 @@ async function currentOwner(directory, probe = SYSTEM_PROBE) {
|
|
|
71523
71525
|
const text = seen.held.get(seq);
|
|
71524
71526
|
if (text === undefined)
|
|
71525
71527
|
return;
|
|
71526
|
-
const now = await readFile11(
|
|
71528
|
+
const now = await readFile11(join21(directory, entryName({ seq })), "utf8").catch(() => {
|
|
71527
71529
|
return;
|
|
71528
71530
|
});
|
|
71529
71531
|
if (now !== text)
|
|
@@ -71584,7 +71586,7 @@ async function stillOwner(directory, self2, probe = SYSTEM_PROBE) {
|
|
|
71584
71586
|
// src/codex/codex-transcript.ts
|
|
71585
71587
|
import { watch } from "fs";
|
|
71586
71588
|
import { open as open4 } from "fs/promises";
|
|
71587
|
-
import { join as
|
|
71589
|
+
import { join as join22 } from "path";
|
|
71588
71590
|
function record3(value) {
|
|
71589
71591
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
71590
71592
|
}
|
|
@@ -71854,7 +71856,7 @@ async function findTranscript(home, threadId) {
|
|
|
71854
71856
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
71855
71857
|
const found = [];
|
|
71856
71858
|
try {
|
|
71857
|
-
for await (const file of glob.scan({ absolute: true, cwd:
|
|
71859
|
+
for await (const file of glob.scan({ absolute: true, cwd: join22(home, "sessions") })) {
|
|
71858
71860
|
found.push(file);
|
|
71859
71861
|
}
|
|
71860
71862
|
} catch {
|
|
@@ -71995,7 +71997,7 @@ function runDispatchCommand(script, args, stdin, options) {
|
|
|
71995
71997
|
});
|
|
71996
71998
|
}
|
|
71997
71999
|
function stateDirectoryFor(pluginRoot) {
|
|
71998
|
-
return configuredValue(process.env["PLUGIN_DATA"]) ?? codexPluginDataDirectory(pluginRoot) ??
|
|
72000
|
+
return configuredValue(process.env["PLUGIN_DATA"]) ?? codexPluginDataDirectory(pluginRoot) ?? join23(configuredValue(process.env["XDG_STATE_HOME"]) ?? join23(homedir4(), ".local", "state"), "claude-envoy", "codex");
|
|
71999
72001
|
}
|
|
72000
72002
|
function waitForRecord(file, pid, signal, ended) {
|
|
72001
72003
|
return new Promise((done) => {
|
|
@@ -72033,7 +72035,7 @@ async function runCodexEnvoyServer() {
|
|
|
72033
72035
|
const configFile = sessionConfigFile("codex", process.env);
|
|
72034
72036
|
const warn = (text) => void process.stderr.write(`envoy-channel: ${text}
|
|
72035
72037
|
`);
|
|
72036
|
-
const bundlePath =
|
|
72038
|
+
const bundlePath = resolve4(pluginRoot, process.argv[1] ?? "");
|
|
72037
72039
|
let record;
|
|
72038
72040
|
let runtime;
|
|
72039
72041
|
let notReady = "this session's Envoy side starts at its first prompt";
|
|
@@ -72083,7 +72085,7 @@ async function runCodexEnvoyServer() {
|
|
|
72083
72085
|
env["DISPATCH_HOST"] = "codex";
|
|
72084
72086
|
if (configFile.path !== null)
|
|
72085
72087
|
env["ENVOY_CONFIG_FILE"] = configFile.path;
|
|
72086
|
-
const { code, output } = await runDispatchCommand(
|
|
72088
|
+
const { code, output } = await runDispatchCommand(join23(pluginRoot, "dist", "dispatch.js"), parsed.data.args, parsed.data.stdin ?? "", { cwd: await latestTurnCwd(transcript) ?? own?.cwd ?? current?.cwd ?? homedir4(), env });
|
|
72087
72089
|
return `${output}${output.endsWith(`
|
|
72088
72090
|
`) || output === "" ? "" : `
|
|
72089
72091
|
`}[exit ${code}]`;
|
|
@@ -72223,7 +72225,7 @@ async function runCodexEnvoyServer() {
|
|
|
72223
72225
|
const runningSession = () => record?.session_id ?? bound.session_id;
|
|
72224
72226
|
const codexDelivery = createCodexDelivery({
|
|
72225
72227
|
inboxDirectory: (sessionId) => codexInboxDirectory(stateDirectory, sessionId),
|
|
72226
|
-
queue: (text) => queueMessage(command(), runningSession(), text,
|
|
72228
|
+
queue: (text) => queueMessage(command(), runningSession(), text, join23(stateDirectory, "codex-long-messages")),
|
|
72227
72229
|
sessionId: runningSession,
|
|
72228
72230
|
taken: (item) => stream?.delivered(item.content, item.dispatchMessageId),
|
|
72229
72231
|
warn
|
package/dist/session-hook.js
CHANGED
|
@@ -18656,7 +18656,7 @@ var dispatchToolSpecs = [
|
|
|
18656
18656
|
{
|
|
18657
18657
|
name: "dispatch_steps",
|
|
18658
18658
|
example: { issue: "DSP-1" },
|
|
18659
|
-
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end. The first line is `<KEY>: <n> steps in <m> tasks`.
|
|
18659
|
+
description: "Print each step that ran on an issue, as the Legion daemon recorded it at the step's " + "start and at its end, and the experiment and the variant the issue was drawn into, where " + "its records name one. The first line is `<KEY>: <n> steps in <m> tasks`. Where the " + "records of the issue's newest run name an experiment, the next line is `Experiment " + "<experiment>: variant <variant>.`, and an issue whose newest run's records name none " + "prints no such line. Then each run of a step prints one line, task by task, in the order " + "each task first ran: `<task> " + "<step> <kind> <role> <type> attempt <attempt> <agent> <model> <started_at> <ended_at> " + "<result>`. kind is step, retro or merge. step is the step's place in its task, from 1, " + "and 0 for a retro or a merge. attempt counts the runs of the same task, step and kind, " + "from 1. agent is the claim of the role that ran the step, and model is the model that " + "answered it, as provider/model. result is passed, failed or stopped. A field with no " + "value prints -, and a run that has not ended prints running for its end and its result. " + "A closed issue's steps read too. An issue that no step ran on prints 0 steps in 0 tasks, " + "and a key Dispatch does not hold fails as dispatch read fails for it, NOT_FOUND: not " + `found. ${ISSUE_REFERENCE}`,
|
|
18660
18660
|
arguments: (z) => ({
|
|
18661
18661
|
issue: z.string().describe(ISSUE_REFERENCE)
|
|
18662
18662
|
}),
|
|
@@ -18665,7 +18665,7 @@ var dispatchToolSpecs = [
|
|
|
18665
18665
|
{
|
|
18666
18666
|
name: "dispatch_plans",
|
|
18667
18667
|
example: { project: "INFRA" },
|
|
18668
|
-
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time
|
|
18668
|
+
description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time, its count of " + "failed steps, and the experiment and the variant it was drawn into, where its records " + "name one. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>[ variant <experiment>/<variant>]\`. ` + "The line ends with variant <experiment>/<variant> where the records of the issue's " + "newest run name an experiment, and at failed steps <n> where they name none. " + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
|
|
18669
18669
|
arguments: (z) => ({
|
|
18670
18670
|
project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
|
|
18671
18671
|
since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
|
|
@@ -31400,7 +31400,8 @@ function issueLine(issue) {
|
|
|
31400
31400
|
ratingsText(issue.ratings),
|
|
31401
31401
|
timeText(issue.duration_seconds),
|
|
31402
31402
|
"failed steps",
|
|
31403
|
-
issue.failed_steps
|
|
31403
|
+
issue.failed_steps,
|
|
31404
|
+
...issue.experiment == null || issue.variant == null ? [] : [`variant ${issue.experiment}/${issue.variant}`]
|
|
31404
31405
|
].join(" ");
|
|
31405
31406
|
}
|
|
31406
31407
|
async function plansCommand(context) {
|
|
@@ -32429,6 +32430,11 @@ function stepLine(record) {
|
|
|
32429
32430
|
...record.ended_at === null ? ["running", "running"] : [record.ended_at, orDash(record.result)]
|
|
32430
32431
|
].join(" ");
|
|
32431
32432
|
}
|
|
32433
|
+
function variantLines(records) {
|
|
32434
|
+
const newest = Math.max(...records.map((record) => record.generation));
|
|
32435
|
+
const named = records.find((record) => record.generation === newest && record.experiment != null && record.variant != null);
|
|
32436
|
+
return named === undefined ? [] : [`Experiment ${named.experiment}: variant ${named.variant}.`];
|
|
32437
|
+
}
|
|
32432
32438
|
async function stepsCommand(context) {
|
|
32433
32439
|
const { client, issue } = context;
|
|
32434
32440
|
const read = await client.listSteps(issue());
|
|
@@ -32437,6 +32443,7 @@ async function stepsCommand(context) {
|
|
|
32437
32443
|
return {
|
|
32438
32444
|
text: [
|
|
32439
32445
|
`${read.issue}: ${records.length} steps in ${tasks.length} tasks`,
|
|
32446
|
+
...variantLines(records),
|
|
32440
32447
|
...records.map(stepLine)
|
|
32441
32448
|
].join(`
|
|
32442
32449
|
`),
|
|
@@ -74,5 +74,5 @@ The version you give replaces them with your own one block: delete theirs, and p
|
|
|
74
74
|
## Reading how plans went
|
|
75
75
|
|
|
76
76
|
`dispatch steps --issue <KEY>` lists each run of each step of an issue and how it ended.
|
|
77
|
-
|
|
77
|
+
`dispatch plans --project <KEY>` lists each finished issue of a project with its plan and how that plan went.
|
|
78
78
|
Read it before you choose the steps of an issue like one that finished.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sjawhar/claude-envoy",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.31.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Claude Code plugin for Legion's Envoy bus",
|
|
6
6
|
"type": "module",
|
|
@@ -18,9 +18,6 @@
|
|
|
18
18
|
"README.md",
|
|
19
19
|
"AGENTS.md"
|
|
20
20
|
],
|
|
21
|
-
"legion": {
|
|
22
|
-
"daemonApiVersion": 275
|
|
23
|
-
},
|
|
24
21
|
"repository": {
|
|
25
22
|
"type": "git",
|
|
26
23
|
"url": "https://github.com/cybermonklabs/legion"
|
|
@@ -46,5 +43,8 @@
|
|
|
46
43
|
"nats": "^2.29.2",
|
|
47
44
|
"typescript": "^5.3.0",
|
|
48
45
|
"zod": "4.3.6"
|
|
46
|
+
},
|
|
47
|
+
"legion": {
|
|
48
|
+
"daemonApiVersion": 275
|
|
49
49
|
}
|
|
50
50
|
}
|
package/scripts/build.ts
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// package. The one mode builds only on the Bun the repo-root `.bun-version`
|
|
12
12
|
// pins, because bundler output depends on the exact Bun build (LEGION-568):
|
|
13
13
|
// --out <dir> make <dir>, a new or empty directory outside the repository, a
|
|
14
|
-
// runnable copy of the plugin built from this tree.
|
|
14
|
+
// runnable copy of the plugin built from this tree, whose package.json
|
|
15
|
+
// and bundles declare the tree's daemon API contract (`pluginManifest`).
|
|
15
16
|
//
|
|
16
17
|
// scripts/build-inputs.txt must name every file this build reads, since
|
|
17
18
|
// release.yaml's $CLAUDE_ENVOY_VERSION_ARGS covers that list and a build input missing from it is
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
// scripts it runs) is listed by hand.
|
|
22
23
|
import { chmod, cp, lstat, mkdir, readdir, readFile, realpath, writeFile } from "node:fs/promises"
|
|
23
24
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path"
|
|
25
|
+
import { daemonContract, type PluginManifest } from "@legion/contracts/daemon-contract"
|
|
24
26
|
import { thirdPartyNotices } from "../../../scripts/third-party-notices"
|
|
25
27
|
import { PHASE_HOOK_TOOL_NAME } from "../src/legion-phase-hook"
|
|
26
28
|
|
|
@@ -31,6 +33,23 @@ const repoRoot = resolve(packageRoot, "..", "..")
|
|
|
31
33
|
* itself without needing a real file on disk. */
|
|
32
34
|
const pinnedBunVersion = (await readFile(join(repoRoot, ".bun-version"), "utf8")).trim()
|
|
33
35
|
|
|
36
|
+
/** The package's manifest as the plugin carries it: the committed one with this tree's daemon API
|
|
37
|
+
* contract as `legion.daemonApiVersion` (`daemonContract`), the number the daemon's boot gate
|
|
38
|
+
* holds the installed manifest to. The committed manifest names none; where the package's
|
|
39
|
+
* manifest holds one, as release.yaml's claude_envoy_build writes it before it builds
|
|
40
|
+
* (.github/scripts/release-claude-envoy-version.sh), that one is kept. `--out` writes this as the
|
|
41
|
+
* plugin's package.json, and every bundle inlines it in place of the committed one, so the code a
|
|
42
|
+
* pane runs states the contract its manifest declares. */
|
|
43
|
+
async function pluginManifest(): Promise<PluginManifest> {
|
|
44
|
+
const manifest = JSON.parse(
|
|
45
|
+
await readFile(join(packageRoot, "package.json"), "utf8"),
|
|
46
|
+
) as PluginManifest
|
|
47
|
+
return {
|
|
48
|
+
...manifest,
|
|
49
|
+
legion: { ...manifest.legion, daemonApiVersion: daemonContract(manifest, packageRoot) },
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
34
53
|
/** Output name -> source entrypoint, relative to the package root. `dispatch` is the `dispatch`
|
|
35
54
|
* CLI that `bin/dispatch` runs, built from the shared library's entry. `session-title-hook` is a
|
|
36
55
|
* bundle of its own rather than a mode of `session-hook`, because Claude Code blocks the user's
|
|
@@ -310,6 +329,9 @@ export async function buildBundles(outdir: string): Promise<string[]> {
|
|
|
310
329
|
}
|
|
311
330
|
|
|
312
331
|
async function bundleFromPackageRoot(outdir: string): Promise<string[]> {
|
|
332
|
+
const manifestPath = join(packageRoot, "package.json")
|
|
333
|
+
const manifest = JSON.stringify(await pluginManifest())
|
|
334
|
+
let manifestInlined = false
|
|
313
335
|
const result = await Bun.build({
|
|
314
336
|
entrypoints: Object.values(BUNDLE_ENTRYPOINTS).map((entry) => join(packageRoot, entry)),
|
|
315
337
|
outdir,
|
|
@@ -333,11 +355,30 @@ async function bundleFromPackageRoot(outdir: string): Promise<string[]> {
|
|
|
333
355
|
sourcemap: "none",
|
|
334
356
|
naming: "[name].[ext]",
|
|
335
357
|
metafile: true,
|
|
358
|
+
// A bundle that imports the package's manifest inlines `pluginManifest()` in its place, so it
|
|
359
|
+
// states the contract the committed manifest leaves out; any other manifest loads as it is.
|
|
360
|
+
plugins: [
|
|
361
|
+
{
|
|
362
|
+
name: "plugin-manifest",
|
|
363
|
+
setup(build) {
|
|
364
|
+
build.onLoad({ filter: /[\\/]package\.json$/ }, async ({ path }) => {
|
|
365
|
+
if (path !== manifestPath) {
|
|
366
|
+
return { contents: await readFile(path, "utf8"), loader: "json" }
|
|
367
|
+
}
|
|
368
|
+
manifestInlined = true
|
|
369
|
+
return { contents: manifest, loader: "json" }
|
|
370
|
+
})
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
],
|
|
336
374
|
})
|
|
337
375
|
if (!result.success) {
|
|
338
376
|
throw new AggregateError(result.logs, "bundle build failed")
|
|
339
377
|
}
|
|
340
378
|
if (!result.metafile) throw new Error("Bun.build returned no metafile")
|
|
379
|
+
if (!manifestInlined) {
|
|
380
|
+
throw new Error(`no bundle imported ${manifestPath}, so none states this tree's contract`)
|
|
381
|
+
}
|
|
341
382
|
// The metafile's keys are relative to the working directory, the package root.
|
|
342
383
|
const inputs = Object.keys(result.metafile.inputs)
|
|
343
384
|
await writeFile(join(outdir, "THIRD_PARTY_NOTICES"), await thirdPartyNotices(inputs, packageRoot))
|
|
@@ -393,12 +434,14 @@ async function outRefusal(out: string): Promise<string | null> {
|
|
|
393
434
|
|
|
394
435
|
/** `out` as a runnable plugin directory: the package's plugin files, with each `skills/<name>`
|
|
395
436
|
* link to the repository's skill copied as the files it points at (file modes kept, so
|
|
396
|
-
* `bin/dispatch` stays executable)
|
|
437
|
+
* `bin/dispatch` stays executable) and its package.json as `pluginManifest()`, then a fresh
|
|
438
|
+
* `dist/` and `legion/`. */
|
|
397
439
|
async function buildOut(out: string): Promise<void> {
|
|
398
440
|
await mkdir(out, { recursive: true })
|
|
399
441
|
for (const source of PLUGIN_SOURCES) {
|
|
400
442
|
await cp(join(packageRoot, source), join(out, source), { recursive: true, dereference: true })
|
|
401
443
|
}
|
|
444
|
+
await writeFile(join(out, "package.json"), `${JSON.stringify(await pluginManifest(), null, 2)}\n`)
|
|
402
445
|
await buildBundles(join(out, "dist"))
|
|
403
446
|
await buildLegionPlugin(join(out, "legion"))
|
|
404
447
|
}
|
package/src/legion-claim.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { readdir, stat } from "node:fs/promises"
|
|
|
2
2
|
import { join } from "node:path"
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises"
|
|
4
4
|
import { SESSION_LIVE_WINDOW_MS } from "@legion/contracts"
|
|
5
|
+
import { daemonContract } from "@legion/contracts/daemon-contract"
|
|
5
6
|
import { messageFor } from "@legion/envoy-client/errors"
|
|
6
7
|
import { readSecretFile } from "@legion/envoy-client/secret-file"
|
|
7
8
|
import type { EnvoyClient } from "@legion/envoy-client/transport"
|
|
@@ -9,7 +10,7 @@ import { claimFirstTurnBoundMs } from "@legion/pi-shared/claim-first-turn-bound"
|
|
|
9
10
|
import { createLegionDaemonClient, type LegionDaemonClient } from "@legion/pi-shared/daemon-client"
|
|
10
11
|
import { bootLegionClaim, type LegionClaimBoot } from "@legion/pi-shared/legion-claim-core"
|
|
11
12
|
import type { ClaimCapability } from "@legion/pi-shared/legion-phase-ops"
|
|
12
|
-
import
|
|
13
|
+
import pkg from "../package.json" with { type: "json" }
|
|
13
14
|
import { configuredValue } from "./claude-session"
|
|
14
15
|
import type { ChannelSession } from "./envoy-channel-server"
|
|
15
16
|
import { paneReminderLog } from "./legion-phase-hook"
|
|
@@ -21,6 +22,12 @@ import { paneReminderLog } from "./legion-phase-hook"
|
|
|
21
22
|
* its boot token (`LEGION_BOOT_TOKEN_FILE`) and its address (`LEGION_DAEMON_URL`).
|
|
22
23
|
*/
|
|
23
24
|
|
|
25
|
+
/** The daemon API contract this build speaks, read once as the module loads (`daemonContract`):
|
|
26
|
+
* the manifest of the module this process loaded names it once a pack or `scripts/build.ts --out`
|
|
27
|
+
* has written it, and a checkout's own fixtures decide it for code run from the checkout. A
|
|
28
|
+
* bundle installed with neither refuses to load here rather than speak a number it guessed. */
|
|
29
|
+
const PLUGIN_CONTRACT = daemonContract(pkg, import.meta.dir)
|
|
30
|
+
|
|
24
31
|
/** What the daemon put on a Legion pane: its address, the boot token the registration spends, the
|
|
25
32
|
* claim's own Claude Code directory (`CLAUDE_CONFIG_DIR`), which holds the transcript, and whether
|
|
26
33
|
* its pod's launcher keeps that transcript in the session table (`LEGION_CLAUDE_SESSION_ID`, which
|
|
@@ -62,13 +69,12 @@ export async function legionPane(env: NodeJS.ProcessEnv): Promise<LegionPane | u
|
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
/**
|
|
65
|
-
* The pane's client for the daemon. It states this build's own
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* caller states describes, so a pane an older or newer daemon answers still reads its answers.
|
|
72
|
+
* The pane's client for the daemon. It states this build's own contract on every request, as the
|
|
73
|
+
* claim's registration below states it: the daemon serves each answer in the shape the contract
|
|
74
|
+
* the caller states describes, so a pane an older or newer daemon answers still reads its answers.
|
|
69
75
|
*/
|
|
70
76
|
export function paneDaemonClient(daemonUrl: string): LegionDaemonClient {
|
|
71
|
-
return createLegionDaemonClient(daemonUrl, { pluginContract:
|
|
77
|
+
return createLegionDaemonClient(daemonUrl, { pluginContract: PLUGIN_CONTRACT })
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
/** Writes one line to the pane's log, the server's stderr. */
|
|
@@ -200,7 +206,7 @@ export interface LegionClaim {
|
|
|
200
206
|
* Boots the pane's claim in the background of the server (`bootLegionClaim`): waits for the
|
|
201
207
|
* transcript, and in a pod whose launcher keeps it (`launcherSaves`) for the launcher's first save
|
|
202
208
|
* of it too, registers with it as the session file (`agentId` is the session id,
|
|
203
|
-
* `pluginContract` this
|
|
209
|
+
* `pluginContract` this build's own contract), sends `claims/ready` with no
|
|
204
210
|
* capability report, again each time the heartbeat regains the role, and claims the claim
|
|
205
211
|
* token's Envoy role soft last of all — at this session's first turn (`onFirstTurn`) or at the
|
|
206
212
|
* bound this pane's environment names, whichever comes first — recording it with the channel
|
|
@@ -275,7 +281,7 @@ export function startLegionClaim(deps: {
|
|
|
275
281
|
sessionId: sessionID,
|
|
276
282
|
ompSessionFile: transcript,
|
|
277
283
|
agentId: sessionID,
|
|
278
|
-
pluginContract:
|
|
284
|
+
pluginContract: PLUGIN_CONTRACT,
|
|
279
285
|
},
|
|
280
286
|
setCapability: (registered) => {
|
|
281
287
|
capability = registered
|
package/src/legion-tool.ts
CHANGED
|
@@ -18,8 +18,9 @@ import pkg from "../package.json" with { type: "json" }
|
|
|
18
18
|
* process loaded, never a path read anywhere else. In a pod a Claude Code role installs no plugin
|
|
19
19
|
* (the daemon's `NoPluginInstall`) and loads its image's own claude-envoy, so a relaunch keeps
|
|
20
20
|
* this build and only the update round over the pod brings another. It is an Oh My Pi role's
|
|
21
|
-
* relaunch that installs its plugin pair fresh under the role's state home.
|
|
22
|
-
|
|
21
|
+
* relaunch that installs its plugin pair fresh under the role's state home. Its contract is
|
|
22
|
+
* `daemonContract`'s, read as the module loads. */
|
|
23
|
+
const BUILD = pluginBuildOf(pkg, import.meta.dir)
|
|
23
24
|
|
|
24
25
|
/** The tool's name: Claude Code shows it as `mcp__legion__legion`, under the pane's one server. */
|
|
25
26
|
export const LEGION_TOOL_NAME = "legion"
|