@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.
@@ -36488,26 +36488,6 @@ var DISPATCH_KEY_PATTERN = /^([A-Z][A-Z0-9]*)-([0-9]+)$/;
36488
36488
  function isLegionRole(role) {
36489
36489
  return LEGION_ROLES.some((candidate) => candidate === role);
36490
36490
  }
36491
- function roleForPhase(phase) {
36492
- switch (phase) {
36493
- case "planning":
36494
- return "planner";
36495
- case "implementing":
36496
- case "retro":
36497
- return "implementer";
36498
- case "testing":
36499
- return "tester";
36500
- case "reviewing":
36501
- return "reviewer";
36502
- case "admitted":
36503
- case "accepting":
36504
- return "architect";
36505
- case "merging":
36506
- return "merger";
36507
- default:
36508
- return;
36509
- }
36510
- }
36511
36491
  function isLegionProjectToken(project) {
36512
36492
  return PROJECT_TOKEN.test(project);
36513
36493
  }
@@ -36524,6 +36504,9 @@ function roleToken(project, issue, role) {
36524
36504
  const [, dispatchProject, number] = dispatchMatch;
36525
36505
  return `legion-${project}-${dispatchProject?.toLowerCase()}-${number}-${role}`;
36526
36506
  }
36507
+ function roleTopic(token) {
36508
+ return `${ROLE_TOPIC_PREFIX}${token}`;
36509
+ }
36527
36510
 
36528
36511
  // ../contracts/src/dispatch-api-core.ts
36529
36512
  var DisplayTreeSchema = looseObject({ type: string2() });
@@ -39687,21 +39670,21 @@ var DISPATCH_READING_SURFACES = [
39687
39670
  surface: "approval-review-reason"
39688
39671
  },
39689
39672
  {
39690
- files: ["packages/dispatch/web/src/features/inbox/AskCard.tsx"],
39673
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
39691
39674
  reach: "/, an ask card's question",
39692
39675
  record: true,
39693
39676
  rendered: true,
39694
39677
  surface: "ask-card-question"
39695
39678
  },
39696
39679
  {
39697
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
39680
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
39698
39681
  reach: "/, an ask card's edit history",
39699
39682
  record: true,
39700
39683
  rendered: true,
39701
39684
  surface: "ask-edit-history"
39702
39685
  },
39703
39686
  {
39704
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
39687
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
39705
39688
  reach: "/, an ask card's earlier answers",
39706
39689
  record: true,
39707
39690
  rendered: true,
@@ -39709,7 +39692,7 @@ var DISPATCH_READING_SURFACES = [
39709
39692
  },
39710
39693
  {
39711
39694
  files: [
39712
- "packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx",
39695
+ "packages/dispatch/web/src/features/ask-body/ask-text.tsx",
39713
39696
  "packages/dispatch/web/src/features/activity/EventBody.tsx"
39714
39697
  ],
39715
39698
  reach: "/, an ask card's earlier answers, an option one chose; /issues/<ISSUE>/activity, a pinned changed answer's `was:` line",
@@ -39718,14 +39701,14 @@ var DISPATCH_READING_SURFACES = [
39718
39701
  surface: "earlier-chosen-option"
39719
39702
  },
39720
39703
  {
39721
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
39704
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
39722
39705
  reach: "/, an answered ask's question and answer",
39723
39706
  record: true,
39724
39707
  rendered: true,
39725
39708
  surface: "answered-ask"
39726
39709
  },
39727
39710
  {
39728
- files: ["packages/dispatch/web/src/features/inbox/AskCompletionCard.tsx"],
39711
+ files: ["packages/dispatch/web/src/features/ask-body/ask-text.tsx"],
39729
39712
  reach: "/, a resolved ask's question and resolution reason",
39730
39713
  record: true,
39731
39714
  rendered: true,
@@ -39733,7 +39716,7 @@ var DISPATCH_READING_SURFACES = [
39733
39716
  },
39734
39717
  {
39735
39718
  files: [
39736
- "packages/dispatch/web/src/features/inbox/AskOptionRow.tsx",
39719
+ "packages/dispatch/web/src/features/ask-body/ask-text.tsx",
39737
39720
  "packages/dispatch/web/src/features/issue-page/NodeRow.tsx"
39738
39721
  ],
39739
39722
  reach: "/, an ask option's label and description",
@@ -39870,6 +39853,22 @@ var DISPATCH_READING_SURFACES = [
39870
39853
  rendered: false,
39871
39854
  surface: "decision-change-quote"
39872
39855
  },
39856
+ {
39857
+ cannotCarry: {
39858
+ forms: ["question-id"],
39859
+ 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."
39860
+ },
39861
+ files: ["packages/dispatch/web/src/features/decision-card/DecisionCard.tsx"],
39862
+ proof: {
39863
+ file: "packages/dispatch/web/src/features/decision-card/DecisionCard.test.tsx",
39864
+ test: "a statement's link reads its first line as plain words"
39865
+ },
39866
+ reach: "/issues/<ISSUE>/decisions, a decision's statement link; /issues/<ISSUE>/spec, a margin decision card's statement link",
39867
+ 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}`,
39868
+ record: true,
39869
+ rendered: false,
39870
+ surface: "decision-statement-line"
39871
+ },
39873
39872
  {
39874
39873
  files: ["packages/dispatch/web/src/features/issue/SpecRequirements.tsx"],
39875
39874
  reach: "/issues/<ISSUE>/spec, a requirement's line under Requirements",
@@ -39899,7 +39898,7 @@ var DISPATCH_READING_SURFACES = [
39899
39898
  "packages/dispatch/web/src/features/doc/ChangeView.tsx",
39900
39899
  "packages/dispatch/web/src/features/artifacts/ArtifactDetails.tsx",
39901
39900
  "packages/dispatch/web/src/features/doc/ProofDocument.tsx",
39902
- "packages/dispatch/web/src/features/inbox/EarlierApproval.tsx"
39901
+ "packages/dispatch/web/src/features/ask-body/EarlierApproval.tsx"
39903
39902
  ],
39904
39903
  reach: "/projects/<PROJECT>/documents/<SLUG>, Compare between two versions",
39905
39904
  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`).",
@@ -39964,16 +39963,16 @@ var DISPATCH_READING_SURFACES = [
39964
39963
  {
39965
39964
  files: [
39966
39965
  "packages/dispatch/web/src/features/margin/ThreadCard.tsx",
39967
- "packages/dispatch/web/src/features/inbox/AskAnchorLink.tsx",
39966
+ "packages/dispatch/web/src/features/ask-body/AskAnchorLink.tsx",
39968
39967
  "packages/dispatch/web/src/features/inbox/ThreadBody.tsx",
39969
39968
  "packages/dispatch/web/src/features/conversation/MentionComposer.tsx",
39970
39969
  "packages/dispatch/web/src/features/conversation/KeptDraftOffers.tsx",
39971
39970
  "packages/dispatch/web/src/features/margin/CommentsTab.tsx",
39972
- "packages/dispatch/web/src/features/issue/DecisionsPanel.tsx",
39971
+ "packages/dispatch/web/src/features/decision-card/DecisionCard.tsx",
39973
39972
  "packages/dispatch/web/src/features/activity/activity-model.ts"
39974
39973
  ],
39975
39974
  reach: "/projects/<PROJECT>/documents/<SLUG>, the quote over a thread card's comment",
39976
- 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.",
39975
+ 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.",
39977
39976
  record: false,
39978
39977
  rendered: false,
39979
39978
  surface: "anchor-quote"
@@ -40260,7 +40259,7 @@ var DISPATCH_READING_SURFACES = [
40260
40259
  "packages/dispatch/web/src/features/inbox/question-label.ts",
40261
40260
  "packages/dispatch/web/src/features/inbox/useAskAnswerForm.ts",
40262
40261
  "packages/dispatch/web/src/features/inbox/AskThread.tsx",
40263
- "packages/dispatch/web/src/features/inbox/DeclineControl.tsx",
40262
+ "packages/dispatch/web/src/features/ask-body/DeclineControl.tsx",
40264
40263
  "packages/dispatch/web/src/features/issue/CreateIssueDialog.tsx"
40265
40264
  ],
40266
40265
  proof: {
@@ -41691,7 +41690,10 @@ var WRITING_BOXES = [
41691
41690
  box: "inbox-thread-reply",
41692
41691
  covered: true,
41693
41692
  delivers: true,
41694
- files: ["packages/dispatch/web/src/features/inbox/ThreadBody.tsx"],
41693
+ files: [
41694
+ "packages/dispatch/web/src/features/dashboard/ThreadItem.tsx",
41695
+ "packages/dispatch/web/src/features/inbox/ThreadBody.tsx"
41696
+ ],
41695
41697
  issueRows: true,
41696
41698
  reach: "Reply",
41697
41699
  write: "comment"
@@ -41700,7 +41702,10 @@ var WRITING_BOXES = [
41700
41702
  box: "inbox-thread-reply",
41701
41703
  covered: true,
41702
41704
  delivers: false,
41703
- files: ["packages/dispatch/web/src/features/inbox/ThreadBody.tsx"],
41705
+ files: [
41706
+ "packages/dispatch/web/src/features/dashboard/ThreadItem.tsx",
41707
+ "packages/dispatch/web/src/features/inbox/ThreadBody.tsx"
41708
+ ],
41704
41709
  issueRows: true,
41705
41710
  reach: "Reply",
41706
41711
  write: "message-reply"
@@ -41832,7 +41837,7 @@ var WRITING_BOXES = [
41832
41837
  box: "ask-answer",
41833
41838
  covered: true,
41834
41839
  delivers: false,
41835
- files: ["packages/dispatch/web/src/features/inbox/AskCard.tsx"],
41840
+ files: ["packages/dispatch/web/src/features/ask-body/AskBody.tsx"],
41836
41841
  issueRows: true,
41837
41842
  reach: "[data-ask-answer]",
41838
41843
  write: "ask-answer"
@@ -41841,7 +41846,7 @@ var WRITING_BOXES = [
41841
41846
  box: "ask-answer",
41842
41847
  covered: true,
41843
41848
  delivers: true,
41844
- files: ["packages/dispatch/web/src/features/inbox/AskCard.tsx"],
41849
+ files: ["packages/dispatch/web/src/features/ask-body/AskBody.tsx"],
41845
41850
  issueRows: true,
41846
41851
  reach: "[data-ask-answer]",
41847
41852
  write: "ask-back"
@@ -41850,7 +41855,7 @@ var WRITING_BOXES = [
41850
41855
  box: "ask-decline-note",
41851
41856
  covered: true,
41852
41857
  delivers: false,
41853
- files: ["packages/dispatch/web/src/features/inbox/DeclineControl.tsx"],
41858
+ files: ["packages/dispatch/web/src/features/ask-body/DeclineControl.tsx"],
41854
41859
  issueRows: true,
41855
41860
  reach: "Note (optional)",
41856
41861
  write: "ask-decline"
@@ -41869,7 +41874,7 @@ var WRITING_BOXES = [
41869
41874
  covered: true,
41870
41875
  delivers: true,
41871
41876
  files: [
41872
- "packages/dispatch/web/src/features/issue/DecisionsPanel.tsx",
41877
+ "packages/dispatch/web/src/features/decision-card/DecisionCard.tsx",
41873
41878
  "packages/dispatch/web/src/features/issue-page/DecisionActions.tsx"
41874
41879
  ],
41875
41880
  issueRows: true,
@@ -67086,7 +67091,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
67086
67091
 
67087
67092
  // package.json
67088
67093
  var name2 = "@sjawhar/claude-envoy";
67089
- var version2 = "6.17.2";
67094
+ var version2 = "6.18.0";
67090
67095
  var package_default = {
67091
67096
  name: name2,
67092
67097
  version: version2,
@@ -67097,7 +67102,7 @@ var package_default = {
67097
67102
  repository: { type: "git", url: "https://github.com/cybermonklabs/legion" },
67098
67103
  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/" },
67099
67104
  devDependencies: { "@biomejs/biome": "2.5.15", "@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" },
67100
- legion: { daemonApiVersion: 287 }
67105
+ legion: { daemonApiVersion: 288 }
67101
67106
  };
67102
67107
 
67103
67108
  // ../pi-shared/src/agent-stream.ts
@@ -69002,6 +69007,10 @@ var legionIssue = object({
69002
69007
  treeRuns: boolean2().optional(),
69003
69008
  repo: nonEmptyString2.optional(),
69004
69009
  defaultBranch: nonEmptyString2.optional(),
69010
+ repoBefore: nonEmptyString2.optional(),
69011
+ repoCorrectedAt: timestamp.optional(),
69012
+ repoChangePending: nonEmptyString2.optional(),
69013
+ repoChangeReason: nonEmptyString2.optional(),
69005
69014
  holdReason: _enum2(["escalated", "task-stopped", "children"]).optional(),
69006
69015
  heldFrom: _enum2(LEGION_WORKFLOW_PHASES).optional(),
69007
69016
  lingerUntil: timestamp.optional(),
@@ -69407,6 +69416,18 @@ var LegionActivityRequest = strictObject({
69407
69416
  secret: nonEmptyString2,
69408
69417
  activity: LegionSessionActivity
69409
69418
  });
69419
+ var LegionOwedRequest = strictObject({
69420
+ claimToken: nonEmptyString2,
69421
+ sessionId: nonEmptyString2,
69422
+ secret: nonEmptyString2
69423
+ });
69424
+ var LegionOwedResponse = object({
69425
+ owes: boolean2(),
69426
+ work: string2(),
69427
+ architect: nonEmptyString2.optional()
69428
+ }).refine((body) => body.owes === (body.work !== ""), {
69429
+ message: "work names the owed work exactly when owes is true"
69430
+ });
69410
69431
  var legionReleaseRecord = object({
69411
69432
  id: number2().int().positive(),
69412
69433
  issue: issueKey,
@@ -69911,7 +69932,8 @@ var LEGION_ANSWER_READS = {
69911
69932
  "pause.endedBy|1.kind",
69912
69933
  "pause.endedBy|0.session"
69913
69934
  ],
69914
- LegionTurnOutcomeResponse: ["refusedRun", "failed"]
69935
+ LegionTurnOutcomeResponse: ["refusedRun", "failed"],
69936
+ LegionOwedResponse: ["owes", "work", "architect"]
69915
69937
  };
69916
69938
 
69917
69939
  // ../pi-shared/src/daemon-client.ts
@@ -70139,7 +70161,7 @@ function createLegionDaemonClient(baseUrl, options) {
70139
70161
  }
70140
70162
  return parsed.value;
70141
70163
  };
70142
- const post = (path, request, response, body) => read("POST", path, response, request.parse(body));
70164
+ const post = (path, request, response, body, signal) => read("POST", path, response, request.parse(body), signal);
70143
70165
  const acknowledge = async (path, body, signal) => {
70144
70166
  const { status, text, daemonContract } = await call("POST", path, body, signal);
70145
70167
  if (status !== 204 || text !== "") {
@@ -70147,7 +70169,7 @@ function createLegionDaemonClient(baseUrl, options) {
70147
70169
  }
70148
70170
  };
70149
70171
  return {
70150
- state: (reading) => read("GET", "/legion/v1/state", LegionStateResponse, undefined, reading?.signal),
70172
+ state: () => read("GET", "/legion/v1/state", LegionStateResponse),
70151
70173
  record: async (issue, reading) => {
70152
70174
  try {
70153
70175
  return await read("GET", `/legion/v1/issues/${encodeURIComponent(issue)}/record`, LegionIssueRecordResponse, undefined, reading?.signal);
@@ -70167,6 +70189,7 @@ function createLegionDaemonClient(baseUrl, options) {
70167
70189
  exit: (input) => acknowledge("/legion/v1/claims/exit", input),
70168
70190
  turnOutcome: (input) => post("/legion/v1/claims/turn-outcome", LegionTurnOutcomeRequest, LegionTurnOutcomeResponse, input),
70169
70191
  activity: (input) => acknowledge("/legion/v1/claims/activity", input),
70192
+ owed: async (input, options) => post("/legion/v1/claims/owed", LegionOwedRequest, LegionOwedResponse, input, options?.signal),
70170
70193
  releaseRecords: (input) => post("/legion/v1/claims/release-records", LegionReleaseRecordsRequest, LegionReleaseRecordsResponse, input),
70171
70194
  grant: (input) => post("/legion/v1/grants", LegionGrantRequest, LegionGrantResponse, input),
70172
70195
  controllerGrant: (input) => post("/legion/v1/grants", LegionControllerGrantRequest, LegionGrantResponse, input),
@@ -70363,34 +70386,34 @@ import { randomUUID as randomUUID6 } from "crypto";
70363
70386
  // ../pi-shared/src/phase-stall.ts
70364
70387
  var WAITING_REPLY = /^\W*WAITING\b/m;
70365
70388
  var TOOL_CALL_SHAPED = /<(?:[\w-]+:)?(?:function_calls\b|invoke\s+name\s*=|parameter\s+name\s*=)/;
70366
- var REMINDER = "Your turn ended with your Legion phase still open: the `legion` tool's `handoff_complete` has " + "not succeeded since your assignment. If your phase's work is done, call the `legion` tool now " + "with op `handoff_complete` and the fields your role's instructions give. If you are waiting on " + "something (CI, a review, a person), reply with a line starting WAITING that names what you are " + "waiting on: that buys a quiet wait, and then this reminder comes again. This reminder repeats " + "at the end of every turn for as long as your phase is open.";
70389
+ function owedReminder(work) {
70390
+ return `Your turn ended with ${work} still owed: the Legion daemon's record holds it open for your ` + "role. If that work is done, call the `legion` tool now with op `handoff_complete` and the " + "fields your role's instructions give. If you are waiting on something (CI, a review, a " + "person), reply with a line starting WAITING that names what you are waiting on: that buys a " + "quiet wait, and then this reminder comes again. This reminder repeats at the end of every " + "turn for as long as the daemon's record holds that work open.";
70391
+ }
70392
+ var UNREAD_REMINDER = "Your turn ended, and this reminder could not read the Legion daemon's record of what your " + "role owes, so it cannot say whether any work is still yours. If your role's instructions " + "leave work of yours unfinished, finish it now with a real tool call. If you are waiting on " + "something (CI, a review, a person), reply with a line starting WAITING that names what you " + "are waiting on: that buys a quiet wait, and then this reminder comes again. This reminder " + "repeats at the end of every turn for as long as the record cannot be read.";
70367
70393
  var TEXT_TOOL_CALL = "Your last message holds a tool call written as text, so it did not run: make it a real tool call. ";
70368
- function reminderText(lastAssistantText) {
70369
- return TOOL_CALL_SHAPED.test(lastAssistantText) ? TEXT_TOOL_CALL + REMINDER : REMINDER;
70394
+ function reminderText(lastAssistantText, work) {
70395
+ const reminder = work === undefined ? UNREAD_REMINDER : owedReminder(work);
70396
+ return TOOL_CALL_SHAPED.test(lastAssistantText) ? TEXT_TOOL_CALL + reminder : reminder;
70370
70397
  }
70371
70398
  function stepPhaseStall(state, input) {
70372
70399
  switch (input.kind) {
70373
- case "assignment":
70374
- return { state: { state: "open", count: 0 } };
70375
- case "phase-closed":
70376
- return { state: { state: "closed", count: 0 } };
70400
+ case "inbound":
70401
+ return { state: { state: "active", count: 0 } };
70377
70402
  case "update-answered":
70378
- return state.state === "closed" ? { state } : { state: { state: "awaiting-update", count: 0 } };
70379
- case "inbound-event":
70380
- return state.state === "closed" ? { state } : { state: { state: "open", count: 0 } };
70403
+ return { state: { state: "awaiting-update", count: 0 } };
70381
70404
  case "tool-call":
70382
70405
  return { state: { state: state.state, count: 0 } };
70383
70406
  case "refused":
70384
70407
  return { state };
70385
70408
  case "reminded":
70386
- return state.state === "closed" ? { state } : { state: { state: "open", count: state.count + 1 } };
70409
+ return { state: { state: "active", count: state.count + 1 } };
70387
70410
  case "settle": {
70388
- if (state.state !== "open")
70411
+ if (state.state !== "active")
70389
70412
  return { state };
70390
70413
  if (input.backgroundWork === true || WAITING_REPLY.test(input.lastAssistantText)) {
70391
70414
  return { state: { state: "waiting", count: state.count } };
70392
70415
  }
70393
- return { state, reminder: reminderText(input.lastAssistantText) };
70416
+ return { state, remind: true };
70394
70417
  }
70395
70418
  }
70396
70419
  }
@@ -70403,13 +70426,15 @@ function phaseStallFrom(data) {
70403
70426
  const recorded = "count" in data ? data.count : undefined;
70404
70427
  const count = typeof recorded === "number" && Number.isInteger(recorded) && recorded >= 0 ? recorded : 0;
70405
70428
  switch (data.state) {
70406
- case "closed":
70407
- case "open":
70429
+ case "active":
70408
70430
  case "waiting":
70409
70431
  return { state: data.state, count };
70432
+ case "open":
70433
+ case "closed":
70434
+ return { state: "active", count };
70410
70435
  case "quiet":
70411
70436
  case "text-call":
70412
- return { state: "open", count: 0 };
70437
+ return { state: "active", count: 0 };
70413
70438
  default:
70414
70439
  return;
70415
70440
  }
@@ -70438,7 +70463,7 @@ function phaseStallEntryFrom(data) {
70438
70463
  }
70439
70464
 
70440
70465
  // ../pi-shared/src/phase-reminder.ts
70441
- var RECORD_READ_BOUND_MS = 5000;
70466
+ var OWED_READ_BOUND_MS = 3000;
70442
70467
  function roleUnheld(error) {
70443
70468
  if (!(error instanceof EnvoyApiError) || error.details.status !== 404)
70444
70469
  return false;
@@ -70466,13 +70491,13 @@ async function withBound(work, ms) {
70466
70491
  clearTimeout(timer);
70467
70492
  }
70468
70493
  }
70469
- function architectLive(record) {
70470
- const architect = record?.architect;
70471
- return architect !== undefined && architect.state !== "retired" && architect.state !== "failed";
70494
+ function readOwedWithin(readOwed, claim, ms) {
70495
+ return withBound((signal) => readOwed({ claimToken: claim.claimToken, sessionId: claim.sessionID, secret: claim.secret }, signal), ms);
70472
70496
  }
70497
+ var UNREAD_CHECK = { reminds: true, work: undefined };
70473
70498
  function createPhaseReminder(deps) {
70474
- const boundMs = deps.recordBoundMs ?? RECORD_READ_BOUND_MS;
70475
- let stall = { state: "closed", count: 0 };
70499
+ const boundMs = deps.owedBoundMs ?? OWED_READ_BOUND_MS;
70500
+ let stall = { state: "active", count: 0 };
70476
70501
  let reported = false;
70477
70502
  let reportKey;
70478
70503
  let generation = 0;
@@ -70481,6 +70506,7 @@ function createPhaseReminder(deps) {
70481
70506
  let lastMessage = "";
70482
70507
  let recorded = "";
70483
70508
  let armed;
70509
+ let owner;
70484
70510
  const entryOf = () => ({
70485
70511
  state: recordedPhaseStall(stall.state),
70486
70512
  count: stall.count,
@@ -70505,48 +70531,35 @@ function createPhaseReminder(deps) {
70505
70531
  reportKey = undefined;
70506
70532
  }
70507
70533
  writeEntry();
70508
- return step.reminder;
70534
+ return step.remind === true;
70509
70535
  };
70510
- const recordCheck = async () => {
70536
+ const owedCheck = async () => {
70511
70537
  const claim = deps.claim();
70512
70538
  if (claim === undefined)
70513
- return { reminds: true };
70514
- let record;
70539
+ return UNREAD_CHECK;
70540
+ let answer;
70515
70541
  try {
70516
- record = await withBound((signal) => deps.readRecord(claim.issue, signal), boundMs);
70542
+ answer = await readOwedWithin(deps.readOwed, claim, boundMs);
70517
70543
  } catch (error) {
70518
- deps.log.debug("legion: the daemon did not answer the phase reminder's record check", {
70544
+ deps.log.debug("legion: the daemon did not say what this claim owes", {
70519
70545
  issue: claim.issue,
70520
70546
  error: messageFor(error)
70521
70547
  });
70522
- return { reminds: true };
70523
- }
70524
- if (record === undefined) {
70525
- deps.log.debug("legion: the daemon holds no record for this phase reminder's issue", {
70526
- issue: claim.issue
70527
- });
70528
- return { reminds: true };
70548
+ return UNREAD_CHECK;
70529
70549
  }
70530
- if (roleForPhase(record.phase) !== claim.role) {
70531
- deps.log.debug("legion: this role no longer works this phase; no reminder is sent", {
70550
+ if (answer.architect !== undefined)
70551
+ owner = answer.architect;
70552
+ if (!answer.owes) {
70553
+ deps.log.debug("legion: the daemon says this claim owes nothing; no reminder is sent", {
70532
70554
  issue: claim.issue,
70533
- phase: record.phase,
70534
70555
  role: claim.role
70535
70556
  });
70536
- return { reminds: false, record };
70557
+ return { reminds: false };
70537
70558
  }
70538
- const state = record.workers?.[claim.role]?.claim?.state;
70539
- if (state === "failed") {
70540
- deps.log.debug("legion: the daemon has failed this claim; no reminder is sent", {
70541
- issue: claim.issue,
70542
- role: claim.role
70543
- });
70544
- return { reminds: false, record };
70545
- }
70546
- return { reminds: true, record };
70559
+ return { reminds: true, work: answer.work };
70547
70560
  };
70548
70561
  const architectDue = () => !reported && stall.count >= deps.limits.architectAfter;
70549
- const tellArchitect = async (record) => {
70562
+ const tellArchitect = async (work) => {
70550
70563
  if (deps.claim() === undefined)
70551
70564
  return;
70552
70565
  const publish = await deps.publisher();
@@ -70565,18 +70578,17 @@ function createPhaseReminder(deps) {
70565
70578
  reportKey ??= randomUUID6();
70566
70579
  const key = reportKey;
70567
70580
  writeEntry();
70568
- const phase = record?.phase ?? "unknown";
70569
70581
  const reminders = stall.count;
70582
+ const owed = work === undefined ? "its turns keep ending while the daemon's record of what it owes cannot be read" : `its turns keep ending with ${work} still owed`;
70570
70583
  try {
70571
- const live = architectLive(record);
70572
- const topic = ROLE_TOPIC_PREFIX + roleToken(deps.project ?? "", live ? claim.issue : claim.tree, "architect");
70584
+ const topic = roleTopic(owner ?? roleToken(deps.project ?? "", claim.tree, "architect"));
70573
70585
  const answer = await publish({
70574
70586
  topic,
70575
- message: `The ${claim.role} of ${claim.issue} has let ${reminders} phase reminders go unanswered: ` + `its turns keep ending with the phase ${phase} still open and no successful ` + `handoff_complete, and nothing it does clears the reminder. ` + `What it last said was: ${lastMessage}`,
70587
+ message: `The ${claim.role} of ${claim.issue} has let ${reminders} reminders go unanswered: ` + `${owed}, and nothing it does clears the reminder. ` + `What it last said was: ${lastMessage}`,
70576
70588
  payload: JSON.stringify({
70577
70589
  issue: claim.issue,
70578
70590
  role: claim.role,
70579
- phase,
70591
+ ...work === undefined ? {} : { work },
70580
70592
  reminders,
70581
70593
  lastMessage
70582
70594
  }),
@@ -70623,14 +70635,14 @@ function createPhaseReminder(deps) {
70623
70635
  });
70624
70636
  }
70625
70637
  };
70626
- const deliver = async (reminder, record) => {
70638
+ const deliver = async (lastText, work) => {
70627
70639
  const uncounted = stall;
70628
70640
  advance({ kind: "reminded" });
70629
70641
  const counted = stall;
70630
70642
  generation += 1;
70631
70643
  const sentAt = generation;
70632
70644
  try {
70633
- await deps.sendReminder(reminder);
70645
+ await deps.sendReminder(reminderText(lastText, work));
70634
70646
  } catch (error) {
70635
70647
  deps.log.warn("legion: a phase reminder did not reach this worker; it comes again later", {
70636
70648
  error: messageFor(error)
@@ -70640,47 +70652,43 @@ function createPhaseReminder(deps) {
70640
70652
  writeEntry();
70641
70653
  }
70642
70654
  if (generation === sentAt)
70643
- armReminder(reminder, deps.limits.reminderMs);
70655
+ armReminder(lastText, deps.limits.reminderMs);
70644
70656
  return;
70645
70657
  }
70646
70658
  if (!architectDue())
70647
70659
  return;
70648
- await tellArchitect(record);
70660
+ await tellArchitect(work);
70649
70661
  };
70650
- const armReminder = (reminder, delayMs) => {
70662
+ const armReminder = (lastText, delayMs) => {
70651
70663
  const armedAt = generation;
70652
70664
  armed = { at: Date.now() + delayMs, generation: armedAt };
70653
70665
  deps.armTimer(async () => {
70654
- if (generation !== armedAt || stall.state === "closed" || turnRunning)
70666
+ if (generation !== armedAt || turnRunning)
70655
70667
  return;
70656
- const check = await recordCheck();
70668
+ const check = await owedCheck();
70657
70669
  if (!check.reminds)
70658
70670
  return;
70659
70671
  if (generation !== armedAt || turnRunning)
70660
70672
  return;
70661
- await deliver(reminder, check.record);
70673
+ await deliver(lastText, check.work);
70662
70674
  }, delayMs);
70663
70675
  };
70664
70676
  return {
70665
70677
  restore: (entry) => {
70666
- stall = entry === undefined ? { state: "closed", count: 0 } : { state: entry.state, count: entry.count };
70678
+ stall = entry === undefined ? { state: "active", count: 0 } : { state: entry.state, count: entry.count };
70667
70679
  reported = entry?.reported ?? false;
70668
70680
  reportKey = entry?.reportKey;
70669
70681
  lastMessage = entry?.lastMessage ?? "";
70670
70682
  recorded = JSON.stringify(entryOf());
70671
70683
  },
70672
70684
  armResumeReminder: () => {
70673
- if (stall.state === "closed")
70674
- return;
70675
- armReminder(reminderText(""), deps.limits.resumeMs);
70685
+ armReminder("", deps.limits.resumeMs);
70676
70686
  },
70677
70687
  turnStarted: () => {
70678
70688
  generation += 1;
70679
70689
  turnRunning = true;
70680
70690
  },
70681
70691
  apply: (input) => {
70682
- if (input.kind === "phase-closed")
70683
- generation += 1;
70684
70692
  advance(input);
70685
70693
  },
70686
70694
  settle: async (turn) => {
@@ -70689,46 +70697,39 @@ function createPhaseReminder(deps) {
70689
70697
  if (turn.kind === "refused") {
70690
70698
  advance(turn);
70691
70699
  continued = false;
70692
- armReminder(reminderText(""), deps.limits.reminderMs);
70700
+ armReminder("", deps.limits.reminderMs);
70693
70701
  return;
70694
70702
  }
70695
70703
  const text = turn.lastAssistantText;
70696
- if (stall.state !== "closed")
70697
- lastMessage = text.slice(0, LAST_MESSAGE_LIMIT);
70704
+ lastMessage = text.slice(0, LAST_MESSAGE_LIMIT);
70698
70705
  const before = stall.count;
70699
- const reminder = advance(turn);
70700
- if (stall.state === "awaiting-update") {
70701
- continued = false;
70702
- return;
70703
- }
70704
- if (stall.state === "waiting") {
70705
- continued = false;
70706
- armReminder(reminderText(text), deps.limits.waitingMs);
70707
- return;
70708
- }
70709
- if (reminder === undefined) {
70706
+ const remind = advance(turn);
70707
+ if (!remind) {
70710
70708
  continued = false;
70709
+ if (stall.state === "waiting")
70710
+ armReminder(text, deps.limits.waitingMs);
70711
70711
  return;
70712
70712
  }
70713
70713
  if (before !== 0 || continued) {
70714
70714
  continued = false;
70715
- armReminder(reminder, deps.limits.reminderMs);
70715
+ armReminder(text, deps.limits.reminderMs);
70716
70716
  return;
70717
70717
  }
70718
- if (!(await recordCheck()).reminds) {
70718
+ const check = await owedCheck();
70719
+ if (!check.reminds) {
70719
70720
  continued = false;
70720
70721
  return;
70721
70722
  }
70722
70723
  advance({ kind: "reminded" });
70723
70724
  generation += 1;
70724
70725
  continued = true;
70725
- return reminder;
70726
+ return reminderText(text, check.work);
70726
70727
  },
70727
70728
  sessionChanged: () => {
70728
70729
  generation += 1;
70729
70730
  },
70730
70731
  phaseWake: () => {
70731
- if (stall.state === "closed" || armed === undefined || armed.generation !== generation) {
70732
+ if (armed === undefined || armed.generation !== generation) {
70732
70733
  return { nextReminderAt: null };
70733
70734
  }
70734
70735
  return { nextReminderAt: new Date(armed.at).toISOString() };
@@ -70789,7 +70790,6 @@ var HOOK_EVENTS = [
70789
70790
  "PostToolUseFailure",
70790
70791
  "UserPromptSubmit"
70791
70792
  ];
70792
- var WRITTEN_LINES_KEPT = 32;
70793
70793
  var hookArguments = object({
70794
70794
  event: _enum2(HOOK_EVENTS),
70795
70795
  lastAssistantMessage: string2().optional(),
@@ -70888,7 +70888,7 @@ function writePhaseStallRecord(file, entry, recreatedNoticeSent, log) {
70888
70888
  function createPhaseHookEndpoint(deps) {
70889
70889
  const limits = stallLimits(deps.env, deps.log, configuredValue(deps.env["LEGION_ROLE"]));
70890
70890
  const restored = readPhaseStallRecord(deps.stateFile, deps.log);
70891
- let entry = restored.entry ?? { state: "closed", count: 0, reported: false };
70891
+ let entry = restored.entry ?? { state: "active", count: 0, reported: false };
70892
70892
  let recreatedNoticeSent = restored.recreatedNoticeSent;
70893
70893
  const saveRecord = (next) => {
70894
70894
  entry = next;
@@ -70913,15 +70913,6 @@ function createPhaseHookEndpoint(deps) {
70913
70913
  }, delayMs);
70914
70914
  };
70915
70915
  let lastReminder;
70916
- const written = new Set;
70917
- const noteWritten = (content) => {
70918
- written.add(content);
70919
- for (const oldest of written) {
70920
- if (written.size <= WRITTEN_LINES_KEPT)
70921
- break;
70922
- written.delete(oldest);
70923
- }
70924
- };
70925
70916
  const writeToSession = async (text, what) => {
70926
70917
  const { inbox } = deps;
70927
70918
  if (inbox === undefined) {
@@ -70941,7 +70932,7 @@ function createPhaseHookEndpoint(deps) {
70941
70932
  armTimer,
70942
70933
  saveEntry: saveRecord,
70943
70934
  claim: deps.claim,
70944
- readRecord: deps.readRecord,
70935
+ readOwed: deps.readOwed,
70945
70936
  publisher: async () => deps.publish,
70946
70937
  project: configuredValue(deps.env["LEGION_PROJECT"]),
70947
70938
  limits,
@@ -70973,7 +70964,6 @@ function createPhaseHookEndpoint(deps) {
70973
70964
  return;
70974
70965
  recreatedNoticeSent = true;
70975
70966
  saveRecord(entry);
70976
- noteWritten(notice.content);
70977
70967
  writeToSession(notice.content, "the recreated-workspace notice").catch((error) => {
70978
70968
  deps.log.warn("legion: the recreated-workspace notice did not reach this worker", {
70979
70969
  error: messageFor(error)
@@ -70989,8 +70979,6 @@ function createPhaseHookEndpoint(deps) {
70989
70979
  reminder.armResumeReminder();
70990
70980
  });
70991
70981
  return {
70992
- deliveryWritten: noteWritten,
70993
- phaseClosed: () => reminder.apply({ kind: "phase-closed" }),
70994
70982
  updateAnswered: () => reminder.apply({ kind: "update-answered" }),
70995
70983
  stop: dropTimer,
70996
70984
  handle: async (input) => {
@@ -71037,8 +71025,7 @@ function createPhaseHookEndpoint(deps) {
71037
71025
  const prompt = event.prompt ?? "";
71038
71026
  if (prompt === lastReminder)
71039
71027
  return {};
71040
- const delivered = written.delete(prompt);
71041
- reminder.apply({ kind: delivered ? "inbound-event" : "assignment" });
71028
+ reminder.apply({ kind: "inbound" });
71042
71029
  return {};
71043
71030
  }
71044
71031
  }
@@ -71283,13 +71270,6 @@ var PHASE_OPS = [
71283
71270
  function namesCheck(args) {
71284
71271
  return args["check_opened_at"] !== undefined;
71285
71272
  }
71286
- function phaseInputAfter(op, args) {
71287
- if (op === "ready_for_update")
71288
- return "update-answered";
71289
- if (op === "request_backward_move" || op === "handoff_complete" && !namesCheck(args))
71290
- return "phase-closed";
71291
- return;
71292
- }
71293
71273
  var requiredString = (op, field) => {
71294
71274
  const message = `${op} requires ${field}`;
71295
71275
  return string2({ error: message }).refine((value) => value.trim() !== "", { error: message });
@@ -71683,10 +71663,7 @@ async function executeLegionTool(runtime, input, signal) {
71683
71663
  }
71684
71664
  async function answerLegionTool(runtime, args, hooks, signal) {
71685
71665
  const answer = await executeLegionTool(runtime, args, signal);
71686
- const effect = phaseInputAfter(String(args["op"]), args);
71687
- if (effect === "phase-closed")
71688
- await hooks.phaseClosed();
71689
- else if (effect === "update-answered")
71666
+ if (args["op"] === "ready_for_update")
71690
71667
  await hooks.updateAnswered();
71691
71668
  return answer;
71692
71669
  }
@@ -74329,7 +74306,7 @@ async function runEnvoyChannelServer() {
74329
74306
  claim: () => claim?.capability(),
74330
74307
  booted: claimBooted.promise,
74331
74308
  firstTurnStarted: () => reportFirstTurn?.(),
74332
- readRecord: (issue, signal) => daemon.record(issue, { signal }),
74309
+ readOwed: (input, signal) => daemon.owed(input, { signal }),
74333
74310
  reportActivity: (input) => daemon.activity(input),
74334
74311
  inbox: inbox === undefined ? undefined : (text) => inbox.notification({ content: text }),
74335
74312
  publish: client.publish,
@@ -74352,10 +74329,7 @@ async function runEnvoyChannelServer() {
74352
74329
  handoffReport: paneHandoffReport(configFile, process.env, directory, identity.id),
74353
74330
  branchHead: () => findPushedBranchHead({ env: process.env })
74354
74331
  };
74355
- const answer = await answerLegionTool(legionRuntime, request.params.arguments ?? {}, {
74356
- phaseClosed: () => phaseHook?.phaseClosed(),
74357
- updateAnswered: () => phaseHook?.updateAnswered()
74358
- }, extra.signal);
74332
+ const answer = await answerLegionTool(legionRuntime, request.params.arguments ?? {}, { updateAnswered: () => phaseHook?.updateAnswered() }, extra.signal);
74359
74333
  return mcpResult(answer);
74360
74334
  }
74361
74335
  if (runtime === undefined)
@@ -74385,7 +74359,7 @@ async function runEnvoyChannelServer() {
74385
74359
  warn: (text) => serverStderr(`envoy-channel: ${text}
74386
74360
  `)
74387
74361
  });
74388
- const writer = inbox ?? {
74362
+ const notifier = inbox ?? {
74389
74363
  notification: async ({ content, blocks, eventId }) => {
74390
74364
  await claude.show({
74391
74365
  content: blocks ?? [{ type: "text", text: content }],
@@ -74394,12 +74368,6 @@ async function runEnvoyChannelServer() {
74394
74368
  });
74395
74369
  }
74396
74370
  };
74397
- const notifier = phaseHook === undefined ? writer : {
74398
- notification: async (notification) => {
74399
- phaseHook.deliveryWritten(notification.content);
74400
- await writer.notification(notification);
74401
- }
74402
- };
74403
74371
  const capabilities = () => sessionCapabilities({ pane: inboxSocket !== undefined, mod: modLink?.connected() === true });
74404
74372
  const booting = new AbortController;
74405
74373
  const stopped = Promise.withResolvers();