@sjawhar/claude-envoy 2.18.0 → 2.19.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.
@@ -2,5 +2,5 @@
2
2
  "name": "claude-envoy",
3
3
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
4
4
  "mcpServers": "./.mcp.json",
5
- "version": "2.18.0"
5
+ "version": "2.19.0"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "2.18.0",
3
+ "version": "2.19.0",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
@@ -53953,6 +53953,19 @@ function pushedBranch(bookmark) {
53953
53953
  return `remote_bookmarks(exact:${JSON.stringify(bookmark)}, exact:"origin")`;
53954
53954
  }
53955
53955
  var STANDING = ["log", "-r", "@-", "--no-graph", "-T", "commit_id"];
53956
+ var RECORD_HEAD = /^[0-9a-f]{40}$/;
53957
+ function recordHead(body) {
53958
+ let parsed;
53959
+ try {
53960
+ parsed = JSON.parse(body);
53961
+ } catch {
53962
+ return;
53963
+ }
53964
+ if (parsed === null || typeof parsed !== "object" || !("head" in parsed))
53965
+ return;
53966
+ const head = parsed.head;
53967
+ return typeof head === "string" && RECORD_HEAD.test(head) ? head : undefined;
53968
+ }
53956
53969
  async function findPushedBranchHead(input) {
53957
53970
  const { env } = input;
53958
53971
  const jj = input.jj ?? pathJj;
@@ -53961,35 +53974,70 @@ async function findPushedBranchHead(input) {
53961
53974
  const { bookmark } = issueBranch(env, purpose);
53962
53975
  return jj(["log", "-r", pushedBranch(bookmark), "--no-graph", "-T", "commit_id"], workspace);
53963
53976
  }
53977
+ function completedPhase(role, at) {
53978
+ switch (role) {
53979
+ case "planner":
53980
+ return "planning";
53981
+ case "tester":
53982
+ return "testing";
53983
+ case "reviewer":
53984
+ return "reviewing";
53985
+ case "merger":
53986
+ return "merging";
53987
+ case "implementer":
53988
+ if (at === "implementing" || at === "retro")
53989
+ return at;
53990
+ return at === "merging" ? "retro" : "implementing";
53991
+ case "architect":
53992
+ return at;
53993
+ }
53994
+ }
53995
+ async function standingReport(env, jj) {
53996
+ return { commit: await jj(STANDING, requiredVariable(env, "LEGION_WORKSPACE", FOR_HANDOFF)) };
53997
+ }
53964
53998
  async function findHandoffReport(input) {
53965
- const { phase, role, env } = input;
53999
+ const { role, env } = input;
53966
54000
  const jj = input.jj ?? pathJj;
53967
- const handoff = FILE_BACKED[phase];
53968
- if (handoff === undefined || handoff.role !== role) {
53969
- return { commit: await jj(STANDING, requiredVariable(env, "LEGION_WORKSPACE", FOR_HANDOFF)) };
53970
- }
54001
+ const of = completedPhase(role, input.phase);
54002
+ const handoff = FILE_BACKED[of];
54003
+ if (handoff === undefined || handoff.role !== role)
54004
+ return standingReport(env, jj);
54005
+ const works = of === input.phase;
53971
54006
  const { issue, bookmark } = issueBranch(env, FOR_HANDOFF);
53972
54007
  let record;
53973
54008
  try {
53974
54009
  record = await input.latestHandoff(issue, handoff.word);
53975
54010
  } catch (error) {
53976
54011
  if (error instanceof DispatchServiceError && error.fromDispatch && error.code === "HANDOFF_NOT_FOUND") {
54012
+ if (!works)
54013
+ return standingReport(env, jj);
53977
54014
  throw new Error(`${issue} has no ${handoff.word} handoff in Dispatch: write it with \`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`, then complete again`);
53978
54015
  }
53979
54016
  const answer = error instanceof DispatchServiceError && error.fromDispatch ? `${error.status} ${error.code}: ${error.message}` : messageFor(error);
53980
54017
  throw new Error(`handoff_complete could not read ${issue}'s newest ${handoff.word} handoff from Dispatch: ${answer}; complete again once Dispatch answers`);
53981
54018
  }
53982
54019
  const report = { handoffId: record.id, handoffVersion: record.version };
53983
- if (role !== "implementer")
53984
- return report;
54020
+ const head = recordHead(record.body);
54021
+ if (role !== "implementer" || !works) {
54022
+ if (head !== undefined)
54023
+ return { commit: head, ...report };
54024
+ if (role !== "implementer")
54025
+ return report;
54026
+ return standingReport(env, jj);
54027
+ }
54028
+ if (head === undefined) {
54029
+ throw new Error(`the newest ${handoff.word} handoff of ${issue} (version ${record.version}) names no head: write the handoff again with \`head\` set to the 40-character lower-case commit you pushed as \`@-\`, as \`jj -R "$LEGION_WORKSPACE" log -r @- --no-graph -T commit_id\` prints it once the push succeeded (\`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`), then complete again`);
54030
+ }
53985
54031
  const workspace = requiredVariable(env, "LEGION_WORKSPACE", FOR_HANDOFF);
53986
- const remote = pushedBranch(bookmark);
53987
54032
  const stands = await jj(STANDING, workspace);
53988
- const tip = await jj(["log", "-r", `${remote} & ${stands}::`, "--no-graph", "-T", "commit_id"], workspace);
54033
+ const tip = await jj(["log", "-r", `${pushedBranch(bookmark)} & ${stands}::`, "--no-graph", "-T", "commit_id"], workspace);
53989
54034
  if (tip === "") {
53990
- throw new Error(`the commit this workspace stands on, ${stands}, is not on ${bookmark}@origin: push it with \`jj bookmark set ${bookmark} -r @- && jj git push --bookmark ${bookmark}\`, then complete again`);
54035
+ throw new Error(`the commit this workspace stands on, ${stands}, is not on ${bookmark}@origin: push it with \`jj bookmark set ${bookmark} -r @- && jj git push --bookmark ${bookmark}\`; the handoff's \`head\` must name that pushed commit, and the newest ${handoff.word} handoff of ${issue} (version ${record.version}) names ${head}, so when that is another commit, write the handoff again with \`head\` set to ${stands} (\`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`); then complete again`);
54036
+ }
54037
+ if (head !== stands) {
54038
+ throw new Error(`the newest ${handoff.word} handoff of ${issue} (version ${record.version}) names ${head} as its head, not the commit this workspace stands on, ${stands}, which ${bookmark}@origin carries: write the handoff again with \`head\` set to ${stands} (\`dispatch handoff-write --issue ${issue} --phase ${handoff.word} --body-file <file>\`), then complete again`);
53991
54039
  }
53992
- return { commit: tip, ...report };
54040
+ return { commit: head, ...report };
53993
54041
  }
53994
54042
  // ../../node_modules/.bun/@modelcontextprotocol+sdk@1.30.0/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
53995
54043
  function isZ4Schema(s) {
@@ -56348,9 +56396,9 @@ var import_nats2 = __toESM(require_mod4(), 1);
56348
56396
 
56349
56397
  // package.json
56350
56398
  var name = "@sjawhar/claude-envoy";
56351
- var version2 = "2.18.0";
56399
+ var version2 = "2.19.0";
56352
56400
  var legion = {
56353
- daemonApiVersion: 111
56401
+ daemonApiVersion: 123
56354
56402
  };
56355
56403
 
56356
56404
  // ../pi-shared/src/agent-stream.ts
@@ -58647,7 +58695,7 @@ var PHASE_OP_SENTENCES = {
58647
58695
  };
58648
58696
  var STALE_ENTRY_INSTRUCTION = "End this turn without completing. The task of the entry the phase is on is owed to this claim, and the daemon sends it by itself. " + "That task is work of its own: do what it asks at the head it names and complete it with a handoff of its own, never this completion's " + "record, commit or verdict";
58649
58697
  function legionToolDescription(host) {
58650
- 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 and sub-architects; the daemon accepts a completion only from the role working the issue's current phase, " + "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). 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 the phase's newest record from Dispatch and reports it; the implementer's round also reports the commit " + "`legion/<issue>@origin` names, so push the branch first; retro and the merger's completion report the commit the workspace stands on. It " + "refuses, posting nothing, a phase with no record, a Dispatch that does not answer, or an implementer's `@-` not yet on " + "`legion/<issue>@origin`, 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 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. Push every commit you want kept to the issue branch " + "first. The daemon replaces the pod and its disk when the round ends: at the moment the message names, or earlier when every " + "role has answered and no turn runs. No answer delays that moment, and the end of a turn is no answer. 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}.`;
58698
+ 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 and sub-architects; 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). 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 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. Push every commit you want kept to the issue branch " + "first. The daemon replaces the pod and its disk when the round ends: at the moment the message names, or earlier when every " + "role has answered and no turn runs. No answer delays that moment, and the end of a turn is no answer. 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}.`;
58651
58699
  }
58652
58700
  async function mintClaimGrant(daemon, claim) {
58653
58701
  const { grantId } = await daemon.grant({
@@ -15,6 +15,7 @@ You work one phase of one issue in a jj workspace every role of the issue shares
15
15
  2. **Commit only your phase's work**, with `jj -R "$LEGION_WORKSPACE" split -m "<message>" <paths…>`, each commit holding only your phase's paths, so the next phase sees what you changed.
16
16
  3. **Put back what you copied in.** Before you write the handoff, run `jj -R "$LEGION_WORKSPACE" status` and remove or restore every file you copied or fetched in that is not your phase's work, such as another branch's test rig. With jj the working copy is the commit: the next role's first commit builds on what you left, and its push ships it.
17
17
  4. **Write the handoff** your role prompt names, with the `write` tool to `$TMPDIR/<issue>-<word>.json`, outside the workspace (jj snapshots every file in the workspace into the working-copy commit), then record it with `dispatch handoff-write --issue <issue> --phase <word> --body-file "$TMPDIR/<issue>-<word>.json"`. A handoff is never a commit, and no handoff carries the evidence: what you ran is a result you record against one of the issue's checks with `dispatch result`, and `skill://legion-worker/references/pr-body.md#what-a-result-is` defines a check and a result. To change a handoff already recorded, read it with `dispatch handoff-read`, edit the body, and record it whole again: each `dispatch handoff-write` adds a version, and `handoff_complete` reports the newest.
18
+ Every handoff body holds `head`, the 40-character lower-case commit the work it reports was done against — the commit the planner's workspace stood on, the commit the implementer pushed as `@-`, the commit the tester's recorded results name (the `--commit` it gave `dispatch result`), the `commit_id` of the review the reviewer submits — and your completion carries that head to the daemon, which takes a completion of an earlier entry of your phase only at the head the record holds. The tester and the reviewer never fill it with a read of the pull request's head made when they write the handoff: a push that landed while they worked names a head their work was not done against.
18
19
  5. **Push any work, then complete**, as the push section below says. `handoff_complete` is your only way to end a phase: add no label, keep no status of your own and run no loop of your own, since the daemon owns the issue's state and the architect its decomposition and gates.
19
20
 
20
21
  ## Stop rules
@@ -159,6 +159,8 @@ and decides there, the only gate on such an issue.
159
159
  PR body, because the reviewer and the merger verify facts on GitHub and never from a handoff.
160
160
  The `implement` handoff carries none: Dispatch holds them, and the tester reads them with
161
161
  `dispatch results`.
162
+ What a handoff does carry is `head`, the 40-character lower-case commit its work was done
163
+ against, which the completion sends to the daemon.
162
164
  - **The tester judges the implementer's results and records its own.** It runs and records no
163
165
  check with `ci_check`, whose result `dispatch results` derives. A derived fail, or a run that
164
166
  concluded `skipped`, `neutral` or `cancelled`, is a test failure. A run still going, or GitHub
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "2.18.0",
3
+ "version": "2.19.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "AGENTS.md"
20
20
  ],
21
21
  "legion": {
22
- "daemonApiVersion": 111
22
+ "daemonApiVersion": 123
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
@@ -33,9 +33,13 @@ export interface LegionToolRuntime {
33
33
  readonly daemon: LegionDaemonClient
34
34
  /** The pane's registered claim, or undefined while its boot is still registering. */
35
35
  readonly claim: () => ClaimCapability | undefined
36
- /** What a completion of `phase` by `role` reports beside its summary (`findHandoffReport` with
37
- * the pane's environment and Dispatch): throws naming the remedy when the phase has no handoff
38
- * record, Dispatch does not answer, or the implementer's work is not pushed. */
36
+ /** What a completion by `role` reports beside its summary while the issue stands at `phase`
37
+ * (`findHandoffReport` with the pane's environment and Dispatch): the newest record of the
38
+ * phase the role works or, once the issue has moved on, of the phase it left, or `@-` alone where
39
+ * that left phase has none or the implementer's left record names no head. Throws naming the remedy when the phase the role works has no
40
+ * handoff record, Dispatch does not answer, or, while the issue stands in implementing, the
41
+ * implementer's record names no head, the commit its workspace stands on is not pushed, or its
42
+ * record's head is not that pushed commit. */
39
43
  readonly handoffReport: (phase: LegionPhase, role: LegionRole) => Promise<HandoffReport>
40
44
  /** The head of `legion/<issue>@origin` a `ready_for_update` signal reports
41
45
  * (`findPushedBranchHead` with the pane's environment): `""` when the branch is not there. */