@sjawhar/claude-envoy 5.25.0 → 5.25.2

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.
@@ -127,7 +127,7 @@ async function sessionStart(raw: unknown): Promise<void> {
127
127
  }
128
128
 
129
129
  const chosen = sessionConfigFile("codex", process.env)
130
- const { dispatch, warnings } = sessionDispatchSettings(chosen, process.env, {
130
+ const { dispatch, warnings } = await sessionDispatchSettings(chosen, process.env, {
131
131
  cwd: input.cwd,
132
132
  session: input.session_id,
133
133
  })
@@ -369,7 +369,7 @@ async function openAsks(raw: unknown): Promise<void> {
369
369
  { CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] },
370
370
  input.cwd ?? process.cwd(),
371
371
  )
372
- const { dispatch, warnings, missing } = sessionDispatchSettings(chosen, process.env, {
372
+ const { dispatch, warnings, missing } = await sessionDispatchSettings(chosen, process.env, {
373
373
  cwd: directory,
374
374
  session: input.session_id,
375
375
  })
@@ -397,14 +397,16 @@ async function openAsks(raw: unknown): Promise<void> {
397
397
  }
398
398
  }
399
399
 
400
- function dispatchFirst(raw: unknown): void {
400
+ async function dispatchFirst(raw: unknown): Promise<void> {
401
401
  const input = DispatchFirstInput.parse(raw)
402
402
  const directory = claudeProjectDirectory(
403
403
  { CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] },
404
404
  input.cwd ?? process.cwd(),
405
405
  )
406
406
  const chosen = sessionConfigFile(HOST, process.env)
407
- if (!sessionDispatchSettings(chosen, process.env, { cwd: directory }).dispatch.enabled) return
407
+ if (!(await sessionDispatchSettings(chosen, process.env, { cwd: directory })).dispatch.enabled) {
408
+ return
409
+ }
408
410
  const pluginRoot = configuredValue(process.env["CLAUDE_PLUGIN_ROOT"])
409
411
  if (pluginRoot === undefined) {
410
412
  throw new Error("CLAUDE_PLUGIN_ROOT is unset; Claude Code sets it for every plugin hook")
@@ -547,7 +549,7 @@ async function answersMessage(
547
549
  by: number,
548
550
  ): Promise<{ readonly text: string | undefined; readonly notice?: string | undefined }> {
549
551
  const file = sessionConfigFile(HOST, process.env)
550
- let { dispatch } = sessionDispatchSettings(file, process.env, {
552
+ let { dispatch } = await sessionDispatchSettings(file, process.env, {
551
553
  cwd,
552
554
  commands: "kept",
553
555
  session,
@@ -557,7 +559,7 @@ async function answersMessage(
557
559
  // The configured URL alone, no command run. With none (envoy.json unreadable, Dispatch off or
558
560
  // no URL), no token command can name one either: the hook starts no refresher and carries the
559
561
  // failure line naming why, never a list read for some URL.
560
- dispatchUrl = sessionDispatchUrl(file, process.env, { cwd })
562
+ dispatchUrl = await sessionDispatchUrl(file, process.env, { cwd })
561
563
  if (dispatchUrl !== undefined) {
562
564
  const refreshed = await refreshedAnswers(session, cwd, dispatchUrl, startedAt, by)
563
565
  if ("text" in refreshed) return refreshed
@@ -637,8 +639,8 @@ async function answersRefresh(session: string, cwd: string): Promise<never> {
637
639
  // before any command runs: when envoy.json moved on since the hook started this refresher, no
638
640
  // hook carries what it read, and when the token command fails, the hook for the same URL
639
641
  // carries this refresher's failure line naming why.
640
- const dispatchUrl = sessionDispatchUrl(file, process.env, { cwd }) ?? null
641
- const { dispatch } = sessionDispatchSettings(file, process.env, { cwd, session })
642
+ const dispatchUrl = (await sessionDispatchUrl(file, process.env, { cwd })) ?? null
643
+ const { dispatch } = await sessionDispatchSettings(file, process.env, { cwd, session })
642
644
  const read = await readSessionAnswers({
643
645
  session,
644
646
  dispatch,
@@ -695,4 +697,4 @@ if (mode === "open-asks") {
695
697
  await endOnceWritten([process.stdout, process.stderr], holdsDeviceLoginLock, (code) =>
696
698
  process.exit(code),
697
699
  )
698
- } else dispatchFirst(input)
700
+ } else await dispatchFirst(input)
@@ -97,7 +97,7 @@ read, against the goal, every check and requirement in `skill://legion-architect
97
97
  Run `task(agent="goal-red-team")` as your role prompt says, then `wait` for its report.
98
98
  Accept only when a pass stands for every `before_merge` check at the head the step before your acceptance passed, every requirement has a check (with no `before_merge` check, your comment says how each is proven), and none is unmet or read narrower than written:
99
99
  post a `dispatch comment` naming each check and its result, then `legion({ op: "sign_off", issue: "<KEY>" })`.
100
- Wait for a `ci_check` run still going; a name no run answers is yours to correct in the check.
100
+ Wait for a `ci_check` run still going; a name no run answers is yours to correct in the check, unless it names a job held back without its label, which has no pass standing until the implementer adds the label.
101
101
  Finding asks, refusals and what follows: `skill://legion-architect/references/acceptance.md`.
102
102
 
103
103
  ## 7. Close
@@ -23,18 +23,19 @@ Read this before you write a root spec, before any edit to an approved one, and
23
23
 
24
24
  ## A check CI proves
25
25
 
26
- A check carrying `ci_check` is CI's: `ci_check` names the GitHub check run that proves it at the
27
- head; it takes no `run`, its `when` is `before_merge`, and no role runs it or records its result
28
- (`skill://legion-worker/references/ci-checks.md`). Where a CI job that runs on an ordinary pull
29
- request already makes a check's proof, write that check as `ci_check` rather than as a command. A
30
- `run` that names tests names specific tests or files; a whole suite is the CI job that runs it.
26
+ A check carrying `ci_check` is CI's (`skill://legion-worker/references/ci-checks.md`): it names
27
+ the check run that proves it at the head, takes no `run`, its `when` is `before_merge`, and no
28
+ role runs or records it. Where a CI job already makes a check's proof, write that check as
29
+ `ci_check` rather than as a command. A `run` that names tests names specific tests or files; a
30
+ whole suite is the CI job that runs it.
31
31
 
32
32
  1. Name the check run of the job that runs the proof, never a roll-up. On cybermonklabs/legion
33
- never `ci-ok`, which passes when the jobs it did not select were skipped
33
+ never `ci-ok`, which passes when jobs it did not select were skipped
34
34
  (`.github/scripts/ci-ok.sh`).
35
- 2. A job held back from ordinary pull requests needs its label on the pull request for as long as
36
- a check names it (`full-ci` on cybermonklabs/legion); without it the job reads `skipped`.
37
- 3. Write in `negative_control` the case inside that job that fails when the property breaks: a
35
+ 2. Name it as GitHub writes it: `<caller> / <job>` for a job of a called workflow (`test / test`).
36
+ 3. A held-back job needs its label (`full-ci` or `lane:<output>`) on the pull request while a
37
+ check names it; without it the check reads `absent` or `skipped`.
38
+ 4. Write in `negative_control` the case inside that job that fails when the property breaks: a
38
39
  step with `continue-on-error` keeps its job green.
39
40
 
40
41
  ## Which steps are gated
@@ -34,10 +34,10 @@ End each turn of that hold with a WAITING line naming the defect and the answer
34
34
  A pass must stand at the last worker step's head for every `before_merge` check, and the body's `Checks` block carries each.
35
35
 
36
36
  - A check carrying `ci_check` is CI's: its derived result is the pass it needs (`skill://legion-worker/references/ci-checks.md`).
37
- A `ci_check` check has no pass standing at that head when its derived result is a fail, or its run concluded `skipped`, `neutral` or `cancelled`.
37
+ A `ci_check` check has no pass standing at that head when its derived result is a fail, its run concluded `skipped`, `neutral` or `cancelled`, or it names a job held back without its label, whose run is `absent` or `skipped` until the label is on.
38
38
  A run that has not concluded, or one GitHub could not be read for, is neither a pass nor a fail yet: never wait for, watch or poll it, as your role prompt says of CI.
39
39
  Name each run that has not concluded, with the time you read it, in step 5's `Runs still going` line, and go on; when CI settles, the daemon tells the architect and the worker of the phase the issue then stands in.
40
- Send a name that no run answers (`absent`) to the architect as a finding, since the check's words are wrong, and the same for a check whose `run` is a whole test suite.
40
+ Send any other name that no run answers (`absent`) to the architect as a finding, since the check's words are wrong, and the same for a check whose `run` is a whole test suite.
41
41
  Neither that run nor that finding moves the issue back.
42
42
 
43
43
  - A `ci_check` check whose derived result is a fail is the merger's: the change passed every step of its task, and the merger decides at the merge whether the base or the change broke it.
@@ -6,7 +6,7 @@ A repository can require body lines derived from the changed paths, read by a re
6
6
  the body written earlier may not cover every path the pull request now changes, and the merger reports a stale body rather than rewriting it.
7
7
  `<owner>/<repo>` and `<n>` are the pull request's repository and number.
8
8
 
9
- 1. Read your deployment instructions, the repository's agent guide (`AGENTS.md`, `CLAUDE.md`), its pull request template where it has one (`.github/pull_request_template.md` or `.github/PULL_REQUEST_TEMPLATE/`) and the workflow under `.github/workflows/` that reads the body, for lines they require per changed path.
9
+ 1. Read your deployment instructions, the repository's agent guide (`AGENTS.md`, `CLAUDE.md`), its contributing guide (`CONTRIBUTING.md`), its pull request template where it has one (`.github/pull_request_template.md` or `.github/PULL_REQUEST_TEMPLATE/`) and the workflow under `.github/workflows/` that reads the body, for lines they require per changed path.
10
10
  When they require none, skip step 2, and stop here unless the task has no reviewer step (step 4 of `skill://legion-retro`).
11
11
 
12
12
  2. List the paths the pull request changes at `<head>`, the head the task's last step passed (step 1 of `skill://legion-retro`):
@@ -4,7 +4,7 @@ Read it when a check of the issue's Verification document carries `ci_check`, be
4
4
 
5
5
  ## What it is
6
6
 
7
- `ci_check` names the GitHub check run that proves the check at the head.
7
+ `ci_check` names the GitHub check run that proves the check at the head, as GitHub writes it: Dispatch matches the name exactly, and a job of a called workflow writes its check run as `<caller> / <job>` (on cybermonklabs/legion, `test / test` or `dispatch-browser-pr / merge`).
8
8
  Such a check has no `run`, its `when` is `before_merge`, and it names its `negative_control`.
9
9
  The architect writes it as `skill://legion-architect/references/design-gate.md` says.
10
10
 
@@ -38,14 +38,17 @@ When the run gives no result, the line reads `CI run <name> has no result (<case
38
38
  The next role that writes the body reads `dispatch results` again and replaces a no-result line.
39
39
 
40
40
  - The tester runs and records only the checks with no `ci_check`.
41
- A `ci_check` check goes in `failures` only when its derived result is a fail, or its run concluded `skipped`, `neutral` or `cancelled`.
41
+ A `ci_check` check goes in `failures` only when its derived result is a fail, its run concluded `skipped`, `neutral` or `cancelled`, or it names a job held back without its label, whose run is `absent` until the label is on (the last bullet below).
42
42
  A run still going fails no round: say so in `implementerProof.how`.
43
43
 
44
44
  - The reviewer waits for a run still going by its name, and neither approves nor requests changes for that check until it concludes.
45
45
 
46
- - A job the repository runs on a pull request only under the label `full-ci` (on cybermonklabs/legion, the slow suites and the full browser lane) reads `skipped` without it.
47
- The implementer adds the label, then pushes, because the workflow starts on a push and not on a label.
46
+ - A job the repository runs on a pull request only under a label (on cybermonklabs/legion, the slow suites) does not run without it.
47
+ A job that holds its own steps then has a run concluded `skipped`; a job that calls a workflow, as each such job on cybermonklabs/legion does, has only its own run, under its bare name (`test`), concluded `skipped`, and no job of the called file starts, so the run a check names (`test / test`) is `absent`.
48
+ The implementer adds the label, `full-ci` or that job's own `lane:<output>`, then pushes, because the workflow starts on a push and not on a label.
48
49
  The label stays on while a `ci_check` of the issue names such a job.
50
+ No job runs on a pull request in part: on cybermonklabs/legion test, pi-legion and envoy-infra-go are held back, while tooling-checks, pi-legion-build and envoy-infra-build, their builds and checks, run on every pull request, each job's check named `<job> / <job>` (`test / test`, `tooling-checks / tooling-checks`); the browser suite's pull-request lane is dispatch-browser-pr, whose checks are named `dispatch-browser-pr / <job>`, and its full lane, dispatch-browser, is held back (`lane:dispatch_browser`).
51
+ On cybermonklabs/legion a check of the edited-migrations, gofmt, OpenAPI or pmdoc steps names `envoy-go-build / envoy-go-build`, which every pull request runs; envoy-go-checks is envoy's script tests, a held-back slow suite, and a check naming it for those steps passes under its label with none of them run.
49
52
 
50
53
  ## A name that no run answers
51
54
 
@@ -53,9 +56,10 @@ When the head's checks have settled and no run of the name answers:
53
56
 
54
57
  1. Read the merge state first (`gh pr view <n> --json mergeStateStatus`): a `DIRTY` head gets no `pull_request` run, and the forward merge cures it.
55
58
 
56
- 2. A held-back job reads `skipped`, not absent: the label cures it.
59
+ 2. A held-back job's check is `absent`, not `skipped`, on a pull request without the job's label when the job calls a workflow, as each held-back job on cybermonklabs/legion does (`test / test`, `dispatch-browser / merge`): the calling job concludes `skipped` under its bare name, and no job of the called file starts.
60
+ The check's words are right: the implementer adds the label and pushes, and each other role sends the issue back to the implementer for it, as for any check with no pass.
57
61
 
58
- 3. Otherwise the check's words are wrong.
62
+ 3. Otherwise the check's words are wrong, as a called workflow's job named without its caller is (`test` for `test / test`).
59
63
  Each tester and reviewer step sends it to the architect as a finding with `envoy_publish`; with neither step, the implementer sends it during retro.
60
64
  No role fails the round or requests changes for it.
61
65
 
@@ -18,4 +18,4 @@ An install of your own (an interpreter, a browser, a second toolchain, an extrac
18
18
 
19
19
  ## The Dispatch browser suite
20
20
 
21
- A spec you add or change in `packages/dispatch` runs in the pod one spec a command (`bun run e2e -- e2e/<spec file>`), against the pod's own Postgres (*The database your tests use* in `skill://legion-worker/references/tools.md`). The change's proof is CI's `dispatch-browser` run at the head: an unlabelled pull request runs only the rows tagged `@pr`, and every other row runs under the label `full-ci`.
21
+ A spec you add or change in `packages/dispatch` runs in the pod one spec a command (`bun run e2e -- e2e/<spec file>`), against the pod's own Postgres (*The database your tests use* in `skill://legion-worker/references/tools.md`). The change's proof is CI at the head: a pull request runs the rows tagged `@pr` in the `dispatch-browser-pr` checks, and every other row runs in the `dispatch-browser` checks, which the merge queue runs and a pull request runs only under the label `full-ci` or `lane:dispatch_browser`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "5.25.0",
3
+ "version": "5.25.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -452,7 +452,7 @@ export async function runCodexEnvoyServer(): Promise<void> {
452
452
  RECORD_POLL_MS,
453
453
  )
454
454
  const id = new SessionIdentity(bound.session_id, bound.cwd)
455
- const { dispatch, envoy, notice } = sessionSettings(configFile, process.env, {
455
+ const { dispatch, envoy, notice } = await sessionSettings(configFile, process.env, {
456
456
  cwd: bound.cwd,
457
457
  session: () => id.id,
458
458
  })
@@ -612,9 +612,10 @@ export async function runCodexEnvoyServer(): Promise<void> {
612
612
  createCodexUserTurnRouter({
613
613
  ask: (question) => askSideQuestion(command(), id.id, question),
614
614
  deliver: (item) => codexDelivery.deliver(item),
615
- dispatch: (ms) => {
615
+ dispatch: async (ms) => {
616
616
  const active = activeDispatchSettings(
617
- sessionDispatchSettings(configFile, process.env, { cwd: bound.cwd }).dispatch,
617
+ (await sessionDispatchSettings(configFile, process.env, { cwd: bound.cwd }))
618
+ .dispatch,
618
619
  )
619
620
  return active === null
620
621
  ? undefined
@@ -28,7 +28,9 @@ import type { CodexInboxItem } from "./codex-inbox"
28
28
  export interface CodexUserTurnOptions {
29
29
  readonly sessionId: () => string
30
30
  readonly state: UserTurnState
31
- readonly dispatch: (ms: number) => DispatchClient | undefined
31
+ /** The session's Dispatch for one request, with `ms` to answer; undefined when Dispatch is not
32
+ * configured, and a rejection when its configuration cannot be read. */
33
+ readonly dispatch: (ms: number) => Promise<DispatchClient | undefined>
32
34
  readonly reply: (
33
35
  delivery: DispatchDelivery,
34
36
  result: { readonly body?: string; readonly error?: string },
@@ -513,10 +513,12 @@ export async function postDispatchReply(
513
513
  delivery: DispatchDelivery,
514
514
  result: { readonly body?: string; readonly error?: string; readonly followUp?: boolean },
515
515
  ): Promise<void> {
516
- const config = sessionDispatchSettings(configFile, process.env, {
517
- cwd: identity.directory,
518
- session: () => identity.id,
519
- }).dispatch
516
+ const config = (
517
+ await sessionDispatchSettings(configFile, process.env, {
518
+ cwd: identity.directory,
519
+ session: () => identity.id,
520
+ })
521
+ ).dispatch
520
522
  if (!config.enabled) throw new Error(config.error ?? config.notice)
521
523
  await postDeliveryReply(config, identity.id, delivery, result)
522
524
  }
@@ -2478,7 +2480,7 @@ function pluginStateDirectory(): string {
2478
2480
  * notifications (`./legion-inbox`). */
2479
2481
  export async function runEnvoyChannelServer(): Promise<void> {
2480
2482
  const directory = projectDirectory()
2481
- const pane = legionPane(process.env)
2483
+ const pane = await legionPane(process.env)
2482
2484
  // The session's envoy.json, by Claude Code's rule (`$CLAUDE_CONFIG_DIR/envoy.json` when that is
2483
2485
  // set), worked out once as the server starts; Dispatch's URL and token are re-read from it on each
2484
2486
  // use, so a file that moved its server takes effect without a restart.
@@ -2486,7 +2488,7 @@ export async function runEnvoyChannelServer(): Promise<void> {
2486
2488
  // The session this server drives, read at every broker trade: Claude Code mints a new id on
2487
2489
  // /clear and `identity` is set to it, so a token this session presents names this session.
2488
2490
  const currentSessionId = (): string => identity.id
2489
- const { dispatch, envoy, notice } = sessionSettings(configFile, process.env, {
2491
+ const { dispatch, envoy, notice } = await sessionSettings(configFile, process.env, {
2490
2492
  cwd: directory,
2491
2493
  session: currentSessionId,
2492
2494
  })
@@ -2796,9 +2798,9 @@ export async function runEnvoyChannelServer(): Promise<void> {
2796
2798
  */
2797
2799
  const router = (state: UserTurnState): UserTurnRouter => {
2798
2800
  const options: UserTurnRouterOptions = {
2799
- dispatch: (ms) => {
2801
+ dispatch: async (ms) => {
2800
2802
  const active = activeDispatchSettings(
2801
- sessionDispatchSettings(configFile, process.env, { cwd: directory }).dispatch,
2803
+ (await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch,
2802
2804
  )
2803
2805
  return active === null
2804
2806
  ? undefined
@@ -35,10 +35,10 @@ export interface LegionPane {
35
35
  /**
36
36
  * The Legion pane this server runs in, or undefined when no boot token is on its environment (a
37
37
  * Claude Code session outside Legion). A set `LEGION_BOOT_TOKEN_FILE` is authoritative, as in
38
- * every pane: a missing or blank file throws naming it. A pane without `LEGION_DAEMON_URL` or
39
- * `CLAUDE_CONFIG_DIR` throws naming the variable.
38
+ * every pane, and read without holding the event loop: a missing or blank file rejects naming it.
39
+ * A pane without `LEGION_DAEMON_URL` or `CLAUDE_CONFIG_DIR` rejects naming the variable.
40
40
  */
41
- export function legionPane(env: NodeJS.ProcessEnv): LegionPane | undefined {
41
+ export async function legionPane(env: NodeJS.ProcessEnv): Promise<LegionPane | undefined> {
42
42
  const pointer = env["LEGION_BOOT_TOKEN_FILE"]
43
43
  if (pointer === undefined && configuredValue(env["LEGION_BOOT_TOKEN"]) === undefined) {
44
44
  return undefined
@@ -56,7 +56,7 @@ export function legionPane(env: NodeJS.ProcessEnv): LegionPane | undefined {
56
56
  bootToken:
57
57
  pointer === undefined
58
58
  ? required("LEGION_BOOT_TOKEN")
59
- : readSecretFile("LEGION_BOOT_TOKEN_FILE", pointer),
59
+ : await readSecretFile("LEGION_BOOT_TOKEN_FILE", pointer),
60
60
  launcherSaves: configuredValue(env["LEGION_CLAUDE_SESSION_ID"]) !== undefined,
61
61
  }
62
62
  }
@@ -419,7 +419,7 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
419
419
  // The server's own listener client, so the notice reaches the one this session already talks
420
420
  // to; Envoy off for the session leaves it undefined, the runner says so once at debug, and
421
421
  // the reminder keeps coming without a notice.
422
- publisher: () => deps.publish,
422
+ publisher: async () => deps.publish,
423
423
  project: configuredValue(deps.env["LEGION_PROJECT"]),
424
424
  limits,
425
425
  log: deps.log,
@@ -197,8 +197,8 @@ export interface UserTurnRouterOptions {
197
197
  /** The Claude Code session itself (`./mod-session`). */
198
198
  readonly session: ModSession
199
199
  /** The session's Dispatch for one request, with `ms` to answer; undefined when Dispatch is not
200
- * configured, and a throw when its configuration cannot be read. */
201
- readonly dispatch: (ms: number) => DispatchClient | undefined
200
+ * configured, and a rejection when its configuration cannot be read. */
201
+ readonly dispatch: (ms: number) => Promise<DispatchClient | undefined>
202
202
  /** Answers a delivery on Dispatch: the reply the person reads, or the error that stopped it.
203
203
  * `followUp` is the ask that Dispatch post this answer although the attempt is already
204
204
  * answered, which every answer to a delivery after the first carries (`post`). */