@sjawhar/claude-envoy 5.35.1 → 5.35.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.
@@ -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": "5.35.1"
5
+ "version": "5.35.2"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "5.35.1",
3
+ "version": "5.35.2",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
@@ -65509,7 +65509,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
65509
65509
 
65510
65510
  // package.json
65511
65511
  var name2 = "@sjawhar/claude-envoy";
65512
- var version2 = "5.35.1";
65512
+ var version2 = "5.35.2";
65513
65513
  var package_default = {
65514
65514
  name: name2,
65515
65515
  version: version2,
@@ -65520,7 +65520,7 @@ var package_default = {
65520
65520
  repository: { type: "git", url: "https://github.com/cybermonklabs/legion" },
65521
65521
  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: "bun ../contracts/scripts/gen-api.ts && bunx tsc --noEmit", test: "bun test --timeout=60000", lint: "bunx biome check src/ hooks/ scripts/" },
65522
65522
  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" },
65523
- legion: { daemonApiVersion: 276 }
65523
+ legion: { daemonApiVersion: 277 }
65524
65524
  };
65525
65525
 
65526
65526
  // ../envoy-client/src/inbound-card.ts
@@ -67231,12 +67231,12 @@ var legionCheckView = object({
67231
67231
  pullRequest: number2().int().positive().optional(),
67232
67232
  mergeCommit: string2().optional(),
67233
67233
  openedAt: timestamp.optional(),
67234
- role: nonEmptyString2,
67235
- looks: number2().int().nonnegative(),
67234
+ role: nonEmptyString2.optional(),
67235
+ looks: number2().int().nonnegative().optional(),
67236
67236
  lookOpen: boolean2().optional(),
67237
67237
  lastWake: legionCheckWakeView.optional(),
67238
67238
  nextWakeAt: timestamp.optional(),
67239
- last: boolean2()
67239
+ last: boolean2().optional()
67240
67240
  });
67241
67241
  var LEGION_WAIT_ANSWERS = [
67242
67242
  "ask",
@@ -67831,12 +67831,15 @@ var LegionHandoffCompleteRequest = strictObject({
67831
67831
  commit: nonEmptyString2.optional(),
67832
67832
  handoffId: nonEmptyString2.optional(),
67833
67833
  handoffVersion: number2().int().positive().optional(),
67834
+ checkOpenedAt: LegionInstant.optional(),
67834
67835
  wakeAt: LegionInstant.optional(),
67835
67836
  planRating: legionPlanRatingScale(number2()).optional(),
67836
67837
  planReason: legionPlanReason.optional(),
67837
67838
  returnTo: number2().int().positive().optional()
67838
67839
  }).refine((request) => legionPlanRatingLoneField(request.planRating, request.planReason) === undefined, { message: "planRating and planReason appear together" }).refine((request) => request.returnTo === undefined || request.verdict === "fail", {
67839
67840
  message: "returnTo is carried only by a completion with the verdict fail"
67841
+ }).refine((request) => request.checkOpenedAt === undefined || request.commit === undefined && request.handoffId === undefined && request.handoffVersion === undefined, {
67842
+ message: "a report naming checkOpenedAt carries no commit, handoffId or handoffVersion"
67840
67843
  });
67841
67844
  var LegionIssueStatusRequest = strictObject({
67842
67845
  grantId: nonEmptyString2,
@@ -67931,10 +67934,6 @@ var ISSUE_RECORD_READS = [
67931
67934
  "workers{}.claim.state",
67932
67935
  "workers{}.claim.lastTurnStart",
67933
67936
  "workers{}.claim.lastTurnEnd",
67934
- "check",
67935
- "check.role",
67936
- "check.looks",
67937
- "check.last",
67938
67937
  "designGate",
67939
67938
  "designGate.currentVersion",
67940
67939
  "designGate.approvedVersion",
@@ -69344,6 +69343,16 @@ var PHASE_OPS = [
69344
69343
  "ready_for_update",
69345
69344
  "read_build"
69346
69345
  ];
69346
+ function namesCheck(args) {
69347
+ return args["check_opened_at"] !== undefined;
69348
+ }
69349
+ function phaseInputAfter(op, args) {
69350
+ if (op === "ready_for_update")
69351
+ return "update-answered";
69352
+ if (op === "request_backward_move" || op === "handoff_complete" && !namesCheck(args))
69353
+ return "phase-closed";
69354
+ return;
69355
+ }
69347
69356
  var requiredString = (op, field) => {
69348
69357
  const message = `${op} requires ${field}`;
69349
69358
  return string2({ error: message }).refine((value) => value.trim() !== "", { error: message });
@@ -69351,6 +69360,7 @@ var requiredString = (op, field) => {
69351
69360
  var rfc3339String = (op, field, message) => requiredString(op, field).refine((value) => value.trim() === "" || LegionInstant.safeParse(value).success, { error: message });
69352
69361
  var windowStart = rfc3339String("read_release_records", "since", "read_release_records' since is an RFC 3339 time, as 2026-11-02T09:00:00Z is");
69353
69362
  var nextLook = rfc3339String("handoff_complete", "wake_at", "handoff_complete's wake_at is an RFC 3339 time, as 2026-11-02T09:00:00Z is");
69363
+ var checkOpening = rfc3339String("handoff_complete", "check_opened_at", "handoff_complete's check_opened_at is the RFC 3339 time, with seconds, its look task names");
69354
69364
  var PLAN_RATING_REFUSAL = `handoff_complete's plan_rating is a whole number from ${LEGION_PLAN_RATING_LEAST} to ${LEGION_PLAN_RATING_MOST}`;
69355
69365
  var planRating = legionPlanRatingScale(number2({ error: PLAN_RATING_REFUSAL }), PLAN_RATING_REFUSAL);
69356
69366
  var PLAN_REASON_MOST = LEGION_PLAN_REASON_MAX.toLocaleString("en-US");
@@ -69382,6 +69392,7 @@ var PhaseOpArguments = discriminatedUnion("op", [
69382
69392
  error: "handoff_complete's verdict is pass, pending or fail"
69383
69393
  }).optional(),
69384
69394
  wake_at: nextLook.optional(),
69395
+ check_opened_at: checkOpening.optional(),
69385
69396
  plan_rating: planRating.optional(),
69386
69397
  plan_reason: planReason.optional(),
69387
69398
  return_to: returnTo.optional()
@@ -69441,7 +69452,7 @@ var PHASE_OP_SENTENCES = {
69441
69452
  };
69442
69453
  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";
69443
69454
  function legionToolDescription(host) {
69444
- 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}.`;
69455
+ 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 naming its production check with `check_opened_at`) 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 " + "names `check_opened_at`, the RFC 3339 opening time in its `Production check of <KEY>` task, with its stored microseconds unchanged. " + "Only that field selects a check report, on any phase. Without it the call completes a step. A report carries its verdict and summary, " + "no handoff or commit: this tool reads no record first. A pending report names `wake_at` when it asks for another look. " + "The daemon refuses a wake on a pass, fail or last look (CHECK_WAKE_UNEXPECTED), and a pending on any other look without one " + "(CHECK_WAKE_REQUIRED). It first refuses a missing, closed or differently opened check (CHECK_NOT_OPEN), then another role " + "(CHECK_ROLE_MISMATCH), then a look the claim has not served (CHECK_LOOK_NOT_SERVED). A report ends no phase. " + `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}.`;
69445
69456
  }
69446
69457
  function pluginBuildOf(manifest, from) {
69447
69458
  return {
@@ -69668,41 +69679,32 @@ async function releaseRecords(runtime, since) {
69668
69679
  }
69669
69680
  async function completeHandoff(runtime, args, rating) {
69670
69681
  const { daemon, claim } = runtime;
69671
- const record = await recordFrom(daemon, claim.issue);
69672
- if (record.phase === "done") {
69682
+ if (namesCheck(args)) {
69683
+ if (args.verdict === undefined) {
69684
+ throw new Error("handoff_complete with check_opened_at names a verdict of pass, pending or fail");
69685
+ }
69673
69686
  if (args.return_to !== undefined) {
69674
- throw new Error("handoff_complete's return_to names the step a failed step's task returns to, and a report on a production check names none; send it again without return_to");
69687
+ throw new Error("handoff_complete's return_to names the step a failed step's task returns to; a report with check_opened_at names none");
69675
69688
  }
69676
- const check = record.check;
69677
- if (check !== undefined) {
69678
- if (args.verdict === undefined) {
69679
- throw new Error("handoff_complete on a production check names a verdict of pass, pending or fail");
69680
- }
69681
- if (claim.role !== check.role) {
69682
- throw new Error(`${claim.issue}'s production check is the ${check.role}'s, and this session is the ${claim.role}'s: only the role the check records reports on it`);
69683
- }
69684
- if (args.verdict === "pending" && args.wake_at === undefined && !check.last) {
69685
- throw new Error(`handoff_complete's pending report names wake_at, when the next look of ${claim.issue}'s production check is due`);
69686
- }
69687
- if (args.wake_at !== undefined && (args.verdict !== "pending" || check.last)) {
69688
- const why = args.verdict === "pending" ? `look ${check.looks} is the check's last, after which the check closes as not run` : `a ${args.verdict} report closes the check`;
69689
- throw new Error(`handoff_complete names wake_at and no look follows it: ${why}; send it again without a time`);
69690
- }
69689
+ if (args.wake_at !== undefined && args.verdict !== "pending") {
69690
+ throw new Error("handoff_complete names wake_at and no look follows a pass or fail; send it again without a time");
69691
69691
  }
69692
69692
  return daemon.handoffComplete({
69693
69693
  grantId: await mintClaimGrant(daemon, claim),
69694
69694
  summary: args.summary,
69695
- verdict: args.verdict ?? "",
69695
+ verdict: args.verdict,
69696
+ checkOpenedAt: args.check_opened_at,
69696
69697
  ...args.wake_at === undefined ? {} : { wakeAt: args.wake_at },
69697
69698
  ...rating
69698
69699
  });
69699
69700
  }
69700
69701
  if (args.verdict === "pending") {
69701
- throw new Error("handoff_complete's verdict is pass or fail on a phase completion; pending is a production check's");
69702
+ throw new Error("handoff_complete's pending verdict reports a production check. Send check_opened_at with the time from the look task or check.openedAt from read_record. To complete a step, send pass or fail.");
69702
69703
  }
69703
69704
  if (args.wake_at !== undefined) {
69704
- throw new Error("handoff_complete's wake_at is a production check's pending report alone; a phase completion carries none");
69705
+ throw new Error("handoff_complete's wake_at reports a production check. Send check_opened_at with the time from the look task or check.openedAt from read_record. A step's completion carries no wake.");
69705
69706
  }
69707
+ const record = await recordFrom(daemon, claim.issue);
69706
69708
  const report = await runtime.handoffReport(record.phase, claim.role);
69707
69709
  return daemon.handoffComplete({
69708
69710
  grantId: await mintClaimGrant(daemon, claim),
@@ -69742,6 +69744,15 @@ async function executeLegionTool(runtime, input, signal) {
69742
69744
  ...signal === undefined ? {} : { restart: { signal } }
69743
69745
  }, input);
69744
69746
  }
69747
+ async function answerLegionTool(runtime, args, hooks, signal) {
69748
+ const answer = await executeLegionTool(runtime, args, signal);
69749
+ const effect = phaseInputAfter(String(args["op"]), args);
69750
+ if (effect === "phase-closed")
69751
+ await hooks.phaseClosed();
69752
+ else if (effect === "update-answered")
69753
+ await hooks.updateAnswered();
69754
+ return answer;
69755
+ }
69745
69756
 
69746
69757
  // src/mod-link.ts
69747
69758
  import { randomUUID as randomUUID9 } from "crypto";
@@ -72312,12 +72323,10 @@ async function runEnvoyChannelServer() {
72312
72323
  handoffReport: paneHandoffReport(configFile, process.env, directory, identity.id),
72313
72324
  branchHead: () => findPushedBranchHead({ env: process.env })
72314
72325
  };
72315
- const answer = await executeLegionTool(legionRuntime, request.params.arguments, extra.signal);
72316
- const op = request.params.arguments?.["op"];
72317
- if (op === "handoff_complete" || op === "request_backward_move")
72318
- phaseHook?.phaseClosed();
72319
- else if (op === "ready_for_update")
72320
- phaseHook?.updateAnswered();
72326
+ const answer = await answerLegionTool(legionRuntime, request.params.arguments ?? {}, {
72327
+ phaseClosed: () => phaseHook?.phaseClosed(),
72328
+ updateAnswered: () => phaseHook?.updateAnswered()
72329
+ }, extra.signal);
72321
72330
  return mcpResult(answer);
72322
72331
  }
72323
72332
  if (runtime === undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "5.35.1",
3
+ "version": "5.35.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -45,6 +45,6 @@
45
45
  "zod": "4.3.6"
46
46
  },
47
47
  "legion": {
48
- "daemonApiVersion": 276
48
+ "daemonApiVersion": 277
49
49
  }
50
50
  }
@@ -135,7 +135,7 @@ import {
135
135
  phaseStallFile,
136
136
  } from "./legion-phase-hook"
137
137
  import {
138
- executeLegionTool,
138
+ answerLegionTool,
139
139
  LEGION_TOOL_NAME,
140
140
  type LegionToolRuntime,
141
141
  legionToolDefinition,
@@ -2676,17 +2676,15 @@ export async function runEnvoyChannelServer(): Promise<void> {
2676
2676
  }
2677
2677
  // The request's signal aborts on the client's notifications/cancelled, which ends a wait
2678
2678
  // for a restarting daemon.
2679
- const answer = await executeLegionTool(legionRuntime, request.params.arguments, extra.signal)
2680
- // A call that returned without throwing: a completion, and a backward move, which hands the
2681
- // issue to another phase. Either way this session's phase is no longer open, and the
2682
- // reminder must stop — the same two operations the Oh My Pi host closes its phase on
2683
- // (`createLegionTool` in `packages/pi-legion/src/tools.ts`). `ready_for_update` ends no
2684
- // phase: it answers the pod's update message, and the worker then waits for its process to be
2685
- // replaced, so the `Stop` of the turn it answered in blocks nothing (`updateAnswered`,
2686
- // `./legion-phase-hook`), as the Oh My Pi host's `onUpdateAnswered` does.
2687
- const op = request.params.arguments?.["op"]
2688
- if (op === "handoff_complete" || op === "request_backward_move") phaseHook?.phaseClosed()
2689
- else if (op === "ready_for_update") phaseHook?.updateAnswered()
2679
+ const answer = await answerLegionTool(
2680
+ legionRuntime,
2681
+ request.params.arguments ?? {},
2682
+ {
2683
+ phaseClosed: () => phaseHook?.phaseClosed(),
2684
+ updateAnswered: () => phaseHook?.updateAnswered(),
2685
+ },
2686
+ extra.signal,
2687
+ )
2690
2688
  return mcpResult(answer)
2691
2689
  }
2692
2690
  if (runtime === undefined)
@@ -8,6 +8,7 @@ import {
8
8
  legionToolDescription,
9
9
  PHASE_OP_SENTENCES,
10
10
  PHASE_OPS,
11
+ phaseInputAfter,
11
12
  phaseOpParameters,
12
13
  pluginBuildOf,
13
14
  } from "@legion/pi-shared/legion-phase-ops"
@@ -82,3 +83,20 @@ export async function executeLegionTool(
82
83
  input,
83
84
  )
84
85
  }
86
+
87
+ /** Runs a successful call through the host's input hooks; a refusal changes no input gate. */
88
+ export async function answerLegionTool(
89
+ runtime: LegionToolRuntime,
90
+ args: Record<string, unknown>,
91
+ hooks: {
92
+ readonly phaseClosed: () => void | Promise<void>
93
+ readonly updateAnswered: () => void | Promise<void>
94
+ },
95
+ signal?: AbortSignal,
96
+ ): Promise<unknown> {
97
+ const answer = await executeLegionTool(runtime, args, signal)
98
+ const effect = phaseInputAfter(String(args["op"]), args)
99
+ if (effect === "phase-closed") await hooks.phaseClosed()
100
+ else if (effect === "update-answered") await hooks.updateAnswered()
101
+ return answer
102
+ }