@sjawhar/claude-envoy 6.17.2 → 6.18.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.
@@ -17290,26 +17290,6 @@ var DISPATCH_KEY_PATTERN = /^([A-Z][A-Z0-9]*)-([0-9]+)$/;
17290
17290
  function isLegionRole(role) {
17291
17291
  return LEGION_ROLES.some((candidate) => candidate === role);
17292
17292
  }
17293
- function roleForPhase(phase) {
17294
- switch (phase) {
17295
- case "planning":
17296
- return "planner";
17297
- case "implementing":
17298
- case "retro":
17299
- return "implementer";
17300
- case "testing":
17301
- return "tester";
17302
- case "reviewing":
17303
- return "reviewer";
17304
- case "admitted":
17305
- case "accepting":
17306
- return "architect";
17307
- case "merging":
17308
- return "merger";
17309
- default:
17310
- return;
17311
- }
17312
- }
17313
17293
  function isLegionProjectToken(project) {
17314
17294
  return PROJECT_TOKEN.test(project);
17315
17295
  }
@@ -17326,6 +17306,9 @@ function roleToken(project, issue, role) {
17326
17306
  const [, dispatchProject, number] = dispatchMatch;
17327
17307
  return `legion-${project}-${dispatchProject?.toLowerCase()}-${number}-${role}`;
17328
17308
  }
17309
+ function roleTopic(token) {
17310
+ return `${ROLE_TOPIC_PREFIX}${token}`;
17311
+ }
17329
17312
 
17330
17313
  // ../contracts/src/dispatch-api-core.ts
17331
17314
  var DisplayTreeSchema = looseObject({ type: string2() });
@@ -20474,21 +20457,21 @@ var DISPATCH_READING_SURFACES = [
20474
20457
  surface: "approval-review-reason"
20475
20458
  },
20476
20459
  {
20477
- files: ["packages/dispatch/web/src/features/inbox/AskCard.tsx"],
20460
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
20478
20461
  reach: "/, an ask card's question",
20479
20462
  record: true,
20480
20463
  rendered: true,
20481
20464
  surface: "ask-card-question"
20482
20465
  },
20483
20466
  {
20484
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
20467
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
20485
20468
  reach: "/, an ask card's edit history",
20486
20469
  record: true,
20487
20470
  rendered: true,
20488
20471
  surface: "ask-edit-history"
20489
20472
  },
20490
20473
  {
20491
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
20474
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
20492
20475
  reach: "/, an ask card's earlier answers",
20493
20476
  record: true,
20494
20477
  rendered: true,
@@ -20496,7 +20479,7 @@ var DISPATCH_READING_SURFACES = [
20496
20479
  },
20497
20480
  {
20498
20481
  files: [
20499
- "packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx",
20482
+ "packages/dispatch/web/src/features/ask-body/ask-text.tsx",
20500
20483
  "packages/dispatch/web/src/features/activity/EventBody.tsx"
20501
20484
  ],
20502
20485
  reach: "/, an ask card's earlier answers, an option one chose; /issues/<ISSUE>/activity, a pinned changed answer's `was:` line",
@@ -20505,14 +20488,14 @@ var DISPATCH_READING_SURFACES = [
20505
20488
  surface: "earlier-chosen-option"
20506
20489
  },
20507
20490
  {
20508
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
20491
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
20509
20492
  reach: "/, an answered ask's question and answer",
20510
20493
  record: true,
20511
20494
  rendered: true,
20512
20495
  surface: "answered-ask"
20513
20496
  },
20514
20497
  {
20515
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
20498
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
20516
20499
  reach: "/, a resolved ask's question and resolution reason",
20517
20500
  record: true,
20518
20501
  rendered: true,
@@ -20520,7 +20503,7 @@ var DISPATCH_READING_SURFACES = [
20520
20503
  },
20521
20504
  {
20522
20505
  files: [
20523
- "packages/dispatch/web/src/features/inbox/AskOptionRow.tsx",
20506
+ "packages/dispatch/web/src/features/ask-body/ask-text.tsx",
20524
20507
  "packages/dispatch/web/src/features/issue-page/NodeRow.tsx"
20525
20508
  ],
20526
20509
  reach: "/, an ask option's label and description",
@@ -20657,6 +20640,22 @@ var DISPATCH_READING_SURFACES = [
20657
20640
  rendered: false,
20658
20641
  surface: "decision-change-quote"
20659
20642
  },
20643
+ {
20644
+ cannotCarry: {
20645
+ forms: ["question-id"],
20646
+ why: "The card is handed the statement's block and none of its document, so no question map is read for the line and a `#id` in it is drawn as written."
20647
+ },
20648
+ files: ["packages/dispatch/web/src/features/decision-card/DecisionCard.tsx"],
20649
+ proof: {
20650
+ file: "packages/dispatch/web/src/features/decision-card/DecisionCard.test.tsx",
20651
+ test: "a statement's link reads its first line as plain words"
20652
+ },
20653
+ reach: "/issues/<ISSUE>/decisions, a decision's statement link; /issues/<ISSUE>/spec, a margin decision card's statement link",
20654
+ reason: `A statement a decision shaped is a link, worded with the first line of the block's text. ${PLAIN_WORDS_REASON} ${LOAD_STATE_REASON}`,
20655
+ record: true,
20656
+ rendered: false,
20657
+ surface: "decision-statement-line"
20658
+ },
20660
20659
  {
20661
20660
  files: ["packages/dispatch/web/src/features/issue/SpecRequirements.tsx"],
20662
20661
  reach: "/issues/<ISSUE>/spec, a requirement's line under Requirements",
@@ -20686,7 +20685,7 @@ var DISPATCH_READING_SURFACES = [
20686
20685
  "packages/dispatch/web/src/features/doc/ChangeView.tsx",
20687
20686
  "packages/dispatch/web/src/features/artifacts/ArtifactDetails.tsx",
20688
20687
  "packages/dispatch/web/src/features/doc/ProofDocument.tsx",
20689
- "packages/dispatch/web/src/features/inbox/EarlierApproval.tsx"
20688
+ "packages/dispatch/web/src/features/ask-body/EarlierApproval.tsx"
20690
20689
  ],
20691
20690
  reach: "/projects/<PROJECT>/documents/<SLUG>, Compare between two versions",
20692
20691
  reason: "A diff shows the exact characters a change swaps, the removed beside the added, so it is drawn as the characters each version holds rather than rendered (R6): a rendered `**` or `[` would hide the change it is. Each version itself is drawn by the document's editor (`document-body`, `document-version-body`).",
@@ -20751,16 +20750,16 @@ var DISPATCH_READING_SURFACES = [
20751
20750
  {
20752
20751
  files: [
20753
20752
  "packages/dispatch/web/src/features/margin/ThreadCard.tsx",
20754
- "packages/dispatch/web/src/features/inbox/AskAnchorLink.tsx",
20753
+ "packages/dispatch/web/src/features/ask-body/AskAnchorLink.tsx",
20755
20754
  "packages/dispatch/web/src/features/inbox/ThreadBody.tsx",
20756
20755
  "packages/dispatch/web/src/features/conversation/MentionComposer.tsx",
20757
20756
  "packages/dispatch/web/src/features/conversation/KeptDraftOffers.tsx",
20758
20757
  "packages/dispatch/web/src/features/margin/CommentsTab.tsx",
20759
- "packages/dispatch/web/src/features/issue/DecisionsPanel.tsx",
20758
+ "packages/dispatch/web/src/features/decision-card/DecisionCard.tsx",
20760
20759
  "packages/dispatch/web/src/features/activity/activity-model.ts"
20761
20760
  ],
20762
20761
  reach: "/projects/<PROJECT>/documents/<SLUG>, the quote over a thread card's comment",
20763
- reason: "An anchor's quote is the document's own words at the place a comment or an ask was left, not a text anyone wrote for this surface: the server matches and stores it as the document's flattened text, never its markdown (`pmdoc.FindQuote`), so a mention in the document is already the words it reads as there, and nothing in the quote is markdown to render. It is shown as the characters it is. One quote is not those words: a decision the Decisions panel draws from an answer that carried no reading of its text, during a rolling deploy, quotes its first block's markdown, which the server finds only where that block holds no markup, and a Change sent with a quote it cannot find is refused and stores nothing.",
20762
+ reason: "An anchor's quote is the document's own words at the place a comment or an ask was left, not a text anyone wrote for this surface: the server matches and stores it as the document's flattened text, never its markdown (`pmdoc.FindQuote`), so a mention in the document is already the words it reads as there, and nothing in the quote is markdown to render. It is shown as the characters it is. A decision's quote is the words of its first block's reading, whichever reading it was read by, so it is those words here too.",
20764
20763
  record: false,
20765
20764
  rendered: false,
20766
20765
  surface: "anchor-quote"
@@ -21047,7 +21046,7 @@ var DISPATCH_READING_SURFACES = [
21047
21046
  "packages/dispatch/web/src/features/inbox/question-label.ts",
21048
21047
  "packages/dispatch/web/src/features/inbox/useAskAnswerForm.ts",
21049
21048
  "packages/dispatch/web/src/features/inbox/AskThread.tsx",
21050
- "packages/dispatch/web/src/features/inbox/DeclineControl.tsx",
21049
+ "packages/dispatch/web/src/features/ask-body/DeclineControl.tsx",
21051
21050
  "packages/dispatch/web/src/features/issue/CreateIssueDialog.tsx"
21052
21051
  ],
21053
21052
  proof: {
@@ -22478,7 +22477,10 @@ var WRITING_BOXES = [
22478
22477
  box: "inbox-thread-reply",
22479
22478
  covered: true,
22480
22479
  delivers: true,
22481
- files: ["packages/dispatch/web/src/features/inbox/ThreadBody.tsx"],
22480
+ files: [
22481
+ "packages/dispatch/web/src/features/dashboard/ThreadItem.tsx",
22482
+ "packages/dispatch/web/src/features/inbox/ThreadBody.tsx"
22483
+ ],
22482
22484
  issueRows: true,
22483
22485
  reach: "Reply",
22484
22486
  write: "comment"
@@ -22487,7 +22489,10 @@ var WRITING_BOXES = [
22487
22489
  box: "inbox-thread-reply",
22488
22490
  covered: true,
22489
22491
  delivers: false,
22490
- files: ["packages/dispatch/web/src/features/inbox/ThreadBody.tsx"],
22492
+ files: [
22493
+ "packages/dispatch/web/src/features/dashboard/ThreadItem.tsx",
22494
+ "packages/dispatch/web/src/features/inbox/ThreadBody.tsx"
22495
+ ],
22491
22496
  issueRows: true,
22492
22497
  reach: "Reply",
22493
22498
  write: "message-reply"
@@ -22619,7 +22624,7 @@ var WRITING_BOXES = [
22619
22624
  box: "ask-answer",
22620
22625
  covered: true,
22621
22626
  delivers: false,
22622
- files: ["packages/dispatch/web/src/features/inbox/AskCard.tsx"],
22627
+ files: ["packages/dispatch/web/src/features/ask-body/AskBody.tsx"],
22623
22628
  issueRows: true,
22624
22629
  reach: "[data-ask-answer]",
22625
22630
  write: "ask-answer"
@@ -22628,7 +22633,7 @@ var WRITING_BOXES = [
22628
22633
  box: "ask-answer",
22629
22634
  covered: true,
22630
22635
  delivers: true,
22631
- files: ["packages/dispatch/web/src/features/inbox/AskCard.tsx"],
22636
+ files: ["packages/dispatch/web/src/features/ask-body/AskBody.tsx"],
22632
22637
  issueRows: true,
22633
22638
  reach: "[data-ask-answer]",
22634
22639
  write: "ask-back"
@@ -22637,7 +22642,7 @@ var WRITING_BOXES = [
22637
22642
  box: "ask-decline-note",
22638
22643
  covered: true,
22639
22644
  delivers: false,
22640
- files: ["packages/dispatch/web/src/features/inbox/DeclineControl.tsx"],
22645
+ files: ["packages/dispatch/web/src/features/ask-body/DeclineControl.tsx"],
22641
22646
  issueRows: true,
22642
22647
  reach: "Note (optional)",
22643
22648
  write: "ask-decline"
@@ -22656,7 +22661,7 @@ var WRITING_BOXES = [
22656
22661
  covered: true,
22657
22662
  delivers: true,
22658
22663
  files: [
22659
- "packages/dispatch/web/src/features/issue/DecisionsPanel.tsx",
22664
+ "packages/dispatch/web/src/features/decision-card/DecisionCard.tsx",
22660
22665
  "packages/dispatch/web/src/features/issue-page/DecisionActions.tsx"
22661
22666
  ],
22662
22667
  issueRows: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "6.17.2",
3
+ "version": "6.18.0",
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": 287
48
+ "daemonApiVersion": 288
49
49
  }
50
50
  }
package/scripts/build.ts CHANGED
@@ -164,8 +164,8 @@ const LEGION_HOOKS: readonly {
164
164
  // woken by it rather than a stalled one, and earns no reminder.
165
165
  backgroundTasks: "${background_tasks}",
166
166
  },
167
- // The `Stop` answer waits on the reminder's record check, which bounds its own daemon read at
168
- // 5 s (RECORD_READ_BOUND_MS, packages/pi-shared/src/phase-reminder.ts); the others answer from
167
+ // The `Stop` answer waits on the reminder's owed check, which bounds its own daemon read at
168
+ // 3 s (OWED_READ_BOUND_MS, packages/pi-shared/src/phase-reminder.ts); the others answer from
169
169
  // memory and the state file alone.
170
170
  timeout: 30,
171
171
  },
@@ -2836,7 +2836,7 @@ export async function runEnvoyChannelServer(): Promise<void> {
2836
2836
  claim: () => claim?.capability(),
2837
2837
  booted: claimBooted.promise,
2838
2838
  firstTurnStarted: () => reportFirstTurn?.(),
2839
- readRecord: (issue, signal) => daemon.record(issue, { signal }),
2839
+ readOwed: (input, signal) => daemon.owed(input, { signal }),
2840
2840
  reportActivity: (input) => daemon.activity(input),
2841
2841
  inbox: inbox === undefined ? undefined : (text) => inbox.notification({ content: text }),
2842
2842
  publish: client.publish,
@@ -2863,13 +2863,13 @@ export async function runEnvoyChannelServer(): Promise<void> {
2863
2863
  }
2864
2864
  // The request's signal aborts on the client's notifications/cancelled, which ends a wait
2865
2865
  // for a restarting daemon.
2866
+ // A `ready_for_update` that answered blocks no `Stop` of its turn (`answerLegionTool`), as
2867
+ // the Oh My Pi host's `onUpdateAnswered` does (`createLegionTool` in
2868
+ // `packages/pi-legion/src/tools.ts`).
2866
2869
  const answer = await answerLegionTool(
2867
2870
  legionRuntime,
2868
2871
  request.params.arguments ?? {},
2869
- {
2870
- phaseClosed: () => phaseHook?.phaseClosed(),
2871
- updateAnswered: () => phaseHook?.updateAnswered(),
2872
- },
2872
+ { updateAnswered: () => phaseHook?.updateAnswered() },
2873
2873
  extra.signal,
2874
2874
  )
2875
2875
  return mcpResult(answer)
@@ -2915,11 +2915,8 @@ export async function runEnvoyChannelServer(): Promise<void> {
2915
2915
  // Every line this server writes into the session: the bridge's inbox in a Legion pane, and the
2916
2916
  // mod's own write in a terminal session, which is a row of the turn running and the prompt of
2917
2917
  // a new turn while the session is idle (`ModSession.show`), since an appended row an idle
2918
- // session never reads would wait for the person to type. The endpoint is told every line
2919
- // written for a delivery: the `UserPromptSubmit` that carries one back is that delivery's
2920
- // turn, not a fresh assignment, and this server, which writes them all, is the only place
2921
- // that knows.
2922
- const writer: ChannelNotifier = inbox ?? {
2918
+ // session never reads would wait for the person to type.
2919
+ const notifier: ChannelNotifier = inbox ?? {
2923
2920
  notification: async ({ content, blocks, eventId }) => {
2924
2921
  await claude.show({
2925
2922
  content: blocks ?? [{ type: "text", text: content }],
@@ -2930,15 +2927,6 @@ export async function runEnvoyChannelServer(): Promise<void> {
2930
2927
  })
2931
2928
  },
2932
2929
  }
2933
- const notifier: ChannelNotifier =
2934
- phaseHook === undefined
2935
- ? writer
2936
- : {
2937
- notification: async (notification) => {
2938
- phaseHook.deliveryWritten(notification.content)
2939
- await writer.notification(notification)
2940
- },
2941
- }
2942
2930
  const capabilities = (): readonly DeliveryCapability[] =>
2943
2931
  sessionCapabilities({ pane: inboxSocket !== undefined, mod: modLink?.connected() === true })
2944
2932
  const booting = new AbortController()
@@ -3014,8 +3002,7 @@ export async function runEnvoyChannelServer(): Promise<void> {
3014
3002
  sessionId: () => identity.id,
3015
3003
  state,
3016
3004
  warn: (text) => serverStderr(`envoy-channel: ${text}\n`),
3017
- // A pane's person message is a line of the bridge's inbox, which makes it a user turn;
3018
- // the phase endpoint is told of it as it is told of every line this server writes.
3005
+ // A pane's person message is a line of the bridge's inbox, which makes it a user turn.
3019
3006
  ...(inboxSocket === undefined ? {} : { inbox: (input) => notifier.notification(input) }),
3020
3007
  }
3021
3008
  return createUserTurnRouter(options)
@@ -1,9 +1,9 @@
1
1
  import { randomUUID } from "node:crypto"
2
2
  import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs"
3
3
  import { dirname, join } from "node:path"
4
- import type { LegionIssue } from "@legion/contracts/legion-api"
4
+ import type { LegionOwed } from "@legion/contracts/legion-api"
5
5
  import { messageFor } from "@legion/envoy-client/errors"
6
- import type { ActivityInput } from "@legion/pi-shared/daemon-client"
6
+ import type { ActivityInput, OwedInput } from "@legion/pi-shared/daemon-client"
7
7
  import type { ClaimCapability } from "@legion/pi-shared/legion-phase-ops"
8
8
  import {
9
9
  createPhaseReminder,
@@ -47,14 +47,14 @@ import { configuredValue } from "./claude-session"
47
47
  * another turn at once and the provider would refuse that one the same way. It does arm one
48
48
  * timer, because the task that refused turn carried ended with it and nothing else would wake
49
49
  * this worker, so a single transient refusal would otherwise leave the issue idle. What stops
50
- * the reminding for good is the runner's record check, which drops every reminder once the
51
- * daemon has failed this role's claim. The bridge reports each turn's outcome to the daemon, with
52
- * the status Claude Code named, and marks a turn no prompt of the daemon's ran — a reminder
53
- * written over the inbox — so the daemon judges that turn from the report (dispatch://INFRA-4508):
54
- * a refusal whose status cannot clear fails the claim at once and holds the issue, and a
55
- * refusal that can clear fails nothing, so the reminders keep their pace. At six such turns in
56
- * a row the daemon sends the `provider-errors` notice once (`providerErrorRunReached` in the
57
- * daemon's `workflow.go` says to whom).
50
+ * the reminding for good is the runner's owed check: once the daemon has failed this role's
51
+ * claim it answers that the claim owes nothing, and every reminder is dropped. The bridge reports
52
+ * each turn's outcome to the daemon, with the status Claude Code named, and marks a turn no prompt
53
+ * of the daemon's ran — a reminder written over the inbox — so the daemon judges that turn from
54
+ * the report (dispatch://INFRA-4508): a refusal whose status cannot clear fails the claim at once
55
+ * and holds the issue, and a refusal that can clear fails nothing, so the reminders keep their
56
+ * pace. At six such turns in a row the daemon sends the `provider-errors` notice once
57
+ * (`providerErrorRunReached` in the daemon's `workflow.go` says to whom).
58
58
  */
59
59
 
60
60
  /** The tool's name: Claude Code shows it as `mcp__legion__legion_phase_hook`, and a hook entry
@@ -78,17 +78,6 @@ const HOOK_EVENTS = [
78
78
  "UserPromptSubmit",
79
79
  ] as const
80
80
 
81
- /**
82
- * How many inbox lines this server wrote are kept waiting for the prompt that carries them back.
83
- * Each is dropped as its prompt arrives, so the set stays at the one or two lines in flight; the
84
- * cap is what bounds it when a line never comes back at all, because the bridge handed two of
85
- * them to one turn. A turn whose line was dropped by the cap counts as an assignment rather than
86
- * an inbound event: both put the count back to 0, but an assignment reopens a phase an inbound
87
- * event would leave closed, so the mistake is the unsafe direction and the record check is all
88
- * that bounds it. The cap is high enough that only a bridge that lost a line reaches it.
89
- */
90
- const WRITTEN_LINES_KEPT = 32
91
-
92
81
  /** One hook call's arguments: the event, and that event's own fields. Claude Code substitutes
93
82
  * `${…}` as strings, so every field is one — `stopHookActive` ("true"/"false") and
94
83
  * `backgroundTasks` (the JSON array, as text) included. */
@@ -151,19 +140,11 @@ export interface PhaseHookAnswer {
151
140
  export interface PhaseHookEndpoint {
152
141
  /** Answers one hook call, with the record written before the answer. */
153
142
  readonly handle: (input: unknown) => Promise<PhaseHookAnswer>
154
- /** One line this server has just written into the bridge's inbox for an Envoy delivery. The
155
- * prompt that carries it back is that delivery's turn, not a fresh assignment, and this is the
156
- * only way the endpoint can tell the two apart: the server writes every delivery itself. */
157
- readonly deliveryWritten: (content: string) => void
158
- /** The `legion` tool's `handoff_complete`, or its `request_backward_move`, returned without
159
- * throwing: this session's phase is no longer open. The CallTool handler of the same server
160
- * calls it (`./envoy-channel-server`), as `onPhaseCompleted` does on the Oh My Pi host. */
161
- readonly phaseClosed: () => void
162
143
  /** The `legion` tool's `ready_for_update` returned without throwing: the worker has pushed
163
- * what it wants kept and waits for the process its claim runs in to be replaced. Its phase
164
- * stays open, and the `Stop` of the turn it answered in must block nothing: the work a
165
- * continuation did would go with the pod, and the daemon would see no turn end. The same
166
- * CallTool handler calls it, as `onUpdateAnswered` does on the Oh My Pi host. */
144
+ * what it wants kept and waits for the process its claim runs in to be replaced, and the `Stop`
145
+ * of the turn it answered in must block nothing: the work a continuation did would go with the
146
+ * pod, and the daemon would see no turn end. The CallTool handler of the same server calls it
147
+ * (`./envoy-channel-server`), as `onUpdateAnswered` does on the Oh My Pi host. */
167
148
  readonly updateAnswered: () => void
168
149
  /** Drops the armed timer, so a 15-minute WAITING wait never holds a shutting-down server
169
150
  * open (the server's own `stop`). */
@@ -187,10 +168,11 @@ export interface PhaseHookDeps {
187
168
  * registered its step — the bridge's seeding `/rename` — signals nothing, and one after the
188
169
  * name is taken costs nothing. */
189
170
  readonly firstTurnStarted: () => void
190
- /** One issue's record, for the reminder's record check, aborted with `signal` once the
191
- * check's bound passes (`PhaseReminderDeps.readRecord`): the record, or `undefined` for an
192
- * issue the daemon records nothing of. */
193
- readonly readRecord: (issue: string, signal: AbortSignal) => Promise<LegionIssue | undefined>
171
+ /** What this session's claim owes now (`LegionDaemonClient.owed`), the one answer that decides
172
+ * whether a reminder goes out, aborted with `signal` once the check's bound passes
173
+ * (`PhaseReminderDeps.readOwed`). An answer that does not arrive is the shared reminder's to
174
+ * decide (`UNREAD_CHECK`, `@legion/pi-shared/phase-reminder`), as it is on Oh My Pi. */
175
+ readonly readOwed: (input: OwedInput, signal: AbortSignal) => Promise<LegionOwed>
194
176
  /** Sends this session's activity report to the daemon (`LegionDaemonClient.activity`), so the
195
177
  * idle rule can decide whether the pane's pod may be released (INFRA-945). */
196
178
  readonly reportActivity: (input: ActivityInput) => Promise<void>
@@ -237,7 +219,8 @@ export function paneReminderLog(write: (line: string) => void): PhaseReminderLog
237
219
  * left behind, which has no such key, still reads.
238
220
  */
239
221
  export interface PhaseStallRecord {
240
- /** The phase and count the file holds, or undefined when it holds none this build knows. */
222
+ /** The reminder's rhythm and count the file holds, or undefined when it holds none this build
223
+ * knows. */
241
224
  readonly entry: PhaseStallEntry | undefined
242
225
  /** Whether this launch's recreated-workspace notice has already been written into the session
243
226
  * (`recreatedNoticeSent` in the file); false for a record that names no such key. It outlives
@@ -253,10 +236,11 @@ const NO_RECORD: PhaseStallRecord = { entry: undefined, recreatedNoticeSent: fal
253
236
  /**
254
237
  * The record `file` holds: a missing file is no record at all, so a fresh session restores
255
238
  * nothing. The entry itself is assembled where the Oh My Pi host's is
256
- * (`phaseStallEntryFrom`), so a record written by the build now in the pods —
257
- * `{"state":"quiet"}` or `{"state":"text-call"}` — reads as an open phase with no reminders yet
258
- * here too, and a missing `count`, `reported` or `reportKey` reads as 0, false and absent. This
259
- * host adds the warning for a record it understands none of, and its own `recreatedNoticeSent`.
239
+ * (`phaseStallEntryFrom`), so a record an earlier build wrote — `{"state":"open"}` or
240
+ * `{"state":"closed"}` with its count, `{"state":"quiet"}` or `{"state":"text-call"}` — reads as
241
+ * the rhythm's `active` here too, and a missing `count`, `reported` or `reportKey` reads as 0,
242
+ * false and absent. This host adds the warning for a record it understands none of, and its own
243
+ * `recreatedNoticeSent`.
260
244
  */
261
245
  export function readPhaseStallRecord(file: string, log: PhaseReminderLog): PhaseStallRecord {
262
246
  let raw: string
@@ -338,7 +322,7 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
338
322
  const restored = readPhaseStallRecord(deps.stateFile, deps.log)
339
323
  // The machine's entry and this host's own key are one record, so the last entry written is kept
340
324
  // for the write the notice makes.
341
- let entry: PhaseStallEntry = restored.entry ?? { state: "closed", count: 0, reported: false }
325
+ let entry: PhaseStallEntry = restored.entry ?? { state: "active", count: 0, reported: false }
342
326
  let recreatedNoticeSent = restored.recreatedNoticeSent
343
327
  const saveRecord = (next: PhaseStallEntry): void => {
344
328
  entry = next
@@ -372,18 +356,6 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
372
356
  /** The reminder last written to the inbox: the prompt that carries it back is this endpoint's
373
357
  * own reminder, and a reminder must never reset the count it just moved. */
374
358
  let lastReminder: string | undefined
375
- /** The lines this server wrote into the inbox for something that is not a reminder — an Envoy
376
- * delivery, the recreated-workspace notice — whose prompt has not arrived yet. Each is dropped
377
- * as its prompt arrives (`WRITTEN_LINES_KEPT` bounds the rest). */
378
- const written = new Set<string>()
379
- const noteWritten = (content: string): void => {
380
- written.add(content)
381
- for (const oldest of written) {
382
- if (written.size <= WRITTEN_LINES_KEPT) break
383
- written.delete(oldest)
384
- }
385
- }
386
-
387
359
  /** Writes `text` into the session over the bridge's inbox, and settles as the inbox does: it
388
360
  * rejects when the bridge did not queue the line. A session with no inbox says so and writes
389
361
  * nothing, and that is no failure: no later attempt could reach the worker either. */
@@ -416,7 +388,7 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
416
388
  // count was never recorded is what the count exists to catch.
417
389
  saveEntry: saveRecord,
418
390
  claim: deps.claim,
419
- readRecord: deps.readRecord,
391
+ readOwed: deps.readOwed,
420
392
  // The server's own listener client, so the notice reaches the one this session already talks
421
393
  // to; Envoy off for the session leaves it undefined, the runner says so once at debug, and
422
394
  // the reminder keeps coming without a notice.
@@ -460,11 +432,11 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
460
432
  /**
461
433
  * D29: a worker whose launcher recreated its workspace is told so, as an Oh My Pi one is, over
462
434
  * the same inbox the reminders use. Once per launch: the record it is written in is the one the
463
- * phase and count live in, so a server Claude Code restarts inside the same `claude` process
464
- * does not repeat it, and a launch that recreated nothing clears it again. The record lands
465
- * before the line does — a notice a broken socket loses is one notice lost, while one written
466
- * twice is the thing it must not be — and the line is noted as written, so the turn it starts
467
- * counts as an inbound event and leaves a closed phase closed.
435
+ * reminder's rhythm and count live in, so a server Claude Code restarts inside the same
436
+ * `claude` process does not repeat it, and a launch that recreated nothing clears it again. The
437
+ * record lands before the line does — a notice a broken socket loses is one notice lost, while
438
+ * one written twice is the thing it must not be — and the turn it starts is an inbound message
439
+ * like any other, which says nothing of what the claim owes.
468
440
  */
469
441
  const sendRecreatedNotice = (issue: string): void => {
470
442
  if (recreatedNoticeSent) return
@@ -472,7 +444,6 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
472
444
  if (notice === undefined) return
473
445
  recreatedNoticeSent = true
474
446
  saveRecord(entry)
475
- noteWritten(notice.content)
476
447
  void writeToSession(notice.content, "the recreated-workspace notice").catch(
477
448
  (error: unknown) => {
478
449
  deps.log.warn("legion: the recreated-workspace notice did not reach this worker", {
@@ -486,16 +457,14 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
486
457
  const claim = deps.claim()
487
458
  if (claim === undefined) return
488
459
  sendRecreatedNotice(claim.issue)
489
- // D10: a worker the daemon relaunched into an open phase is reminded from a timer, since
490
- // nothing else would wake it. The guard drops that timer when a turn started meanwhile, which
491
- // is exactly the case to drop — the daemon re-sending an interrupted task arrives as a
492
- // `UserPromptSubmit`.
460
+ // D10: a worker the daemon relaunched is reminded from a timer, since nothing else would wake
461
+ // it, and the daemon's answer when it is due says whether anything is owed. The guard drops
462
+ // that timer when a turn started meanwhile, which is exactly the case to drop — the daemon
463
+ // re-sending an interrupted task arrives as a `UserPromptSubmit`.
493
464
  if (claim.role !== "architect") reminder.armResumeReminder()
494
465
  })
495
466
 
496
467
  return {
497
- deliveryWritten: noteWritten,
498
- phaseClosed: () => reminder.apply({ kind: "phase-closed" }),
499
468
  updateAnswered: () => reminder.apply({ kind: "update-answered" }),
500
469
  stop: dropTimer,
501
470
  handle: async (input) => {
@@ -549,11 +518,12 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
549
518
  // refusing the turn, and the machine takes it as one: it earns no continuation, because
550
519
  // the next turn would be refused the same way, and one timer, because nothing else would
551
520
  // wake this worker once the task that turn carried ended with it. What ends the reminding
552
- // is the daemon failing the claim, which the timer's own record check reads: it does at
553
- // once for a refusal whose status cannot clear, the status the bridge reports beside the
554
- // turn's outcome, a reminder's own turn included, and never for a refusal that can clear,
555
- // of which the daemon sends the `provider-errors` notice at six in a row
556
- // (dispatch://INFRA-4508; `providerErrorRunReached` in the daemon says to whom).
521
+ // is the daemon failing the claim, after which the timer's own owed check is answered
522
+ // that the claim owes nothing: it fails one at once for a refusal whose status cannot
523
+ // clear, the status the bridge reports beside the turn's outcome, a reminder's own turn
524
+ // included, and never for a refusal that can clear, of which the daemon sends the
525
+ // `provider-errors` notice at six in a row (dispatch://INFRA-4508;
526
+ // `providerErrorRunReached` in the daemon says to whom).
557
527
  // Claude Code ignores whatever this hook returns, which costs nothing now that there
558
528
  // is nothing to return.
559
529
  await reminder.settle({ kind: "refused", message: event.lastAssistantMessage ?? "" })
@@ -571,19 +541,17 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
571
541
  }
572
542
  case "UserPromptSubmit": {
573
543
  // D7: the only sight this server has of an inbound turn. The daemon's task reaches
574
- // Claude Code's stdin from the bridge and never this process, so what a turn means is
575
- // read from the prompt itself. The turn is declared first, which makes every armed
576
- // timer stale, and the pending one is dropped outright: the runner's generation guard
577
- // answers the same for the timers it armed, and dropping the one timer this server
578
- // holds is the plainest way to say the same thing.
544
+ // Claude Code's stdin from the bridge and never this process, so a turn is read from the
545
+ // prompt itself: this endpoint's own reminder, or an inbound message, which starts the
546
+ // count again and says nothing of what the claim owes. The turn is declared first,
547
+ // which makes every armed timer stale, and the pending one is dropped outright: the
548
+ // runner's generation guard answers the same for the timers it armed, and dropping the
549
+ // one timer this server holds is the plainest way to say the same thing.
579
550
  reminder.turnStarted()
580
551
  dropTimer()
581
552
  const prompt = event.prompt ?? ""
582
553
  if (prompt === lastReminder) return {}
583
- // A line this server wrote is dropped as its prompt arrives, so a later turn carrying
584
- // the same text is an assignment, which is what a repeat of it would be.
585
- const delivered = written.delete(prompt)
586
- reminder.apply({ kind: delivered ? "inbound-event" : "assignment" })
554
+ reminder.apply({ kind: "inbound" })
587
555
  return {}
588
556
  }
589
557
  }
@@ -8,7 +8,6 @@ import {
8
8
  legionToolDescription,
9
9
  PHASE_OP_SENTENCES,
10
10
  PHASE_OPS,
11
- phaseInputAfter,
12
11
  phaseOpParameters,
13
12
  pluginBuildOf,
14
13
  } from "@legion/pi-shared/legion-phase-ops"
@@ -84,19 +83,18 @@ export async function executeLegionTool(
84
83
  )
85
84
  }
86
85
 
87
- /** Runs a successful call through the host's input hooks; a refusal changes no input gate. */
86
+ /** Runs one call of the `legion` tool, as executeLegionTool does, and tells the host once a
87
+ * `ready_for_update` it ran answered the pod's update message: the worker then waits for its
88
+ * process to be replaced, so the `Stop` of the turn it answered in blocks nothing
89
+ * (`updateAnswered`, `./legion-phase-hook`). A completion and a look's report tell the host
90
+ * nothing: the reminder asks the daemon what the claim owes. A refusal throws before any hook. */
88
91
  export async function answerLegionTool(
89
92
  runtime: LegionToolRuntime,
90
93
  args: Record<string, unknown>,
91
- hooks: {
92
- readonly phaseClosed: () => void | Promise<void>
93
- readonly updateAnswered: () => void | Promise<void>
94
- },
94
+ hooks: { readonly updateAnswered: () => void | Promise<void> },
95
95
  signal?: AbortSignal,
96
96
  ): Promise<unknown> {
97
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()
98
+ if (args["op"] === "ready_for_update") await hooks.updateAnswered()
101
99
  return answer
102
100
  }