@sjawhar/claude-envoy 4.7.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,5 +2,5 @@
2
2
  "name": "claude-envoy",
3
3
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
4
4
  "mcpServers": "./.mcp.json",
5
- "version": "4.7.0"
5
+ "version": "4.9.0"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "4.7.0",
3
+ "version": "4.9.0",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
@@ -13661,6 +13661,9 @@ var LEGION_ROLES = [
13661
13661
  "merger"
13662
13662
  ];
13663
13663
  var GATED_STEPS = ["decisions", "criteria", "spec"];
13664
+ var LEGION_PLAN_RATING_LEAST = 1;
13665
+ var LEGION_PLAN_RATING_MOST = 5;
13666
+ var LEGION_PLAN_REASON_MAX = 2000;
13664
13667
  var PROJECT_TOKEN = /^[a-z0-9]+$/;
13665
13668
  var DISPATCH_KEY_PATTERN = /^([A-Z][A-Z0-9]*)-([0-9]+)$/;
13666
13669
  function isLegionRole(role) {
@@ -14260,6 +14263,13 @@ var SEARCH_QUERY_HINT = "search with a short phrase of a few words, not a passag
14260
14263
  var SEARCH_KIND_DEPTH = 100;
14261
14264
  var PROJECT_KEY_PATTERN = /^[A-Z][A-Z0-9]{1,9}$/;
14262
14265
  var PROJECT_KEY_RULE = "an uppercase letter, then 1 to 9 uppercase letters or digits, such as CORE";
14266
+ var projectKeyValidation = {
14267
+ check: (value) => {
14268
+ const { project } = value;
14269
+ return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
14270
+ },
14271
+ message: `project is not a project key: ${PROJECT_KEY_RULE}`
14272
+ };
14263
14273
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
14264
14274
  var ISSUE_STATUSES = [
14265
14275
  "triage",
@@ -14711,9 +14721,9 @@ var dispatchToolSpecs = [
14711
14721
  validation: {
14712
14722
  check: (value) => {
14713
14723
  const { project } = value;
14714
- return typeof project !== "string" || project === "" || PROJECT_KEY_PATTERN.test(project);
14724
+ return project === "" || projectKeyValidation.check(value);
14715
14725
  },
14716
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
14726
+ message: projectKeyValidation.message
14717
14727
  }
14718
14728
  },
14719
14729
  {
@@ -14727,13 +14737,7 @@ var dispatchToolSpecs = [
14727
14737
  exclude_issues: z.array(z.string()).describe("Optional issue keys in the project whose own items are left out of the results; at most 50.").optional(),
14728
14738
  keywords_only: z.boolean().describe("Search by keywords only, skipping meaning search.").optional()
14729
14739
  }),
14730
- validation: {
14731
- check: (value) => {
14732
- const { project } = value;
14733
- return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
14734
- },
14735
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
14736
- }
14740
+ validation: projectKeyValidation
14737
14741
  },
14738
14742
  {
14739
14743
  name: "dispatch_issues",
@@ -14863,6 +14867,18 @@ var dispatchToolSpecs = [
14863
14867
  }),
14864
14868
  strict: true
14865
14869
  },
14870
+ {
14871
+ name: "dispatch_plans",
14872
+ example: { project: "INFRA" },
14873
+ description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time and its count of " + "failed steps. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>\`. ` + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
14874
+ arguments: (z) => ({
14875
+ project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
14876
+ since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
14877
+ until: z.string().describe("Optional RFC 3339 time; only issues closed before it.").optional()
14878
+ }),
14879
+ validation: projectKeyValidation,
14880
+ strict: true
14881
+ },
14866
14882
  {
14867
14883
  name: "dispatch_inbox",
14868
14884
  example: {},
@@ -20295,6 +20311,9 @@ class DispatchClient {
20295
20311
  async listSteps(issue) {
20296
20312
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "steps"]);
20297
20313
  }
20314
+ async listProjectPlans(project, window = {}) {
20315
+ return this.#json("GET", ["api", "v1", "projects", project, "plans"], undefined, window);
20316
+ }
20298
20317
  async getIssueReferences(issue) {
20299
20318
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "references"], undefined, { versions: "latest" });
20300
20319
  }
@@ -22368,6 +22387,7 @@ var issueFreeTools = {
22368
22387
  dispatch_search: true,
22369
22388
  dispatch_related: true,
22370
22389
  dispatch_issues: true,
22390
+ dispatch_plans: true,
22371
22391
  dispatch_project: true,
22372
22392
  dispatch_projects: true,
22373
22393
  dispatch_priorities: true,
@@ -24314,6 +24334,11 @@ async function sendToAgentCommand(context) {
24314
24334
 
24315
24335
  // ../envoy-client/src/dispatch-commands/documents.ts
24316
24336
  import { resolve as resolvePath2 } from "path";
24337
+
24338
+ // ../contracts/src/go-blank.ts
24339
+ var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
24340
+
24341
+ // ../envoy-client/src/dispatch-commands/documents.ts
24317
24342
  async function blockAsks(client, resolved, state) {
24318
24343
  const asks = await (resolved.issue === undefined ? client.getArtifactAsks(resolved.artifact.id, state) : client.listIssueAsks(resolved.issue.key, state));
24319
24344
  return asks.filter((ask) => typeof ask.block_id === "string" && ask.block_artifact?.id === resolved.artifact.id);
@@ -24756,7 +24781,6 @@ function withoutFinalLineFeed(text) {
24756
24781
  return text.endsWith(`
24757
24782
  `) ? text.slice(0, -1) : text;
24758
24783
  }
24759
- var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
24760
24784
  async function artifactCommand(context) {
24761
24785
  const { args, client, actor, input, documentOwner, issue } = context;
24762
24786
  const summary = optionalString(args, "summary");
@@ -25739,6 +25763,55 @@ async function resultsCommand(context) {
25739
25763
  };
25740
25764
  }
25741
25765
 
25766
+ // ../envoy-client/src/dispatch-commands/plans.ts
25767
+ function planText(plan) {
25768
+ if (plan === null)
25769
+ return "plan none";
25770
+ const tasks = plan.tasks ?? [];
25771
+ const first = tasks[0]?.steps ?? [];
25772
+ return `plan ${plan.source} (${tasks.length} tasks: ${first.length === 0 ? "-" : first.join(" ")})`;
25773
+ }
25774
+ var unescapedLineBreaks = /[\u0085\u2028\u2029]/g;
25775
+ function oneLineJson(text) {
25776
+ return JSON.stringify(text).replace(unescapedLineBreaks, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
25777
+ }
25778
+ function ratingsText(ratings) {
25779
+ if (ratings === null || ratings.length === 0)
25780
+ return "ratings none";
25781
+ return `ratings ${ratings.map((rating) => `${rating.rating}/${LEGION_PLAN_RATING_MOST} ${oneLineJson(rating.reason)}`).join(", ")}`;
25782
+ }
25783
+ function timeText(seconds) {
25784
+ if (seconds === null)
25785
+ return "time -";
25786
+ const minutes = Math.floor(seconds / 60);
25787
+ return `time ${Math.floor(minutes / 60)}h${minutes % 60}m`;
25788
+ }
25789
+ function issueLine(issue) {
25790
+ return [
25791
+ issue.issue,
25792
+ "closed",
25793
+ issue.closed_at,
25794
+ planText(issue.plan),
25795
+ ratingsText(issue.ratings),
25796
+ timeText(issue.duration_seconds),
25797
+ "failed steps",
25798
+ issue.failed_steps
25799
+ ].join(" ");
25800
+ }
25801
+ async function plansCommand(context) {
25802
+ const { args, client } = context;
25803
+ const read = await client.listProjectPlans(stringArg(args, "project"), {
25804
+ since: optionalString(args, "since"),
25805
+ until: optionalString(args, "until")
25806
+ });
25807
+ const issues = read.issues ?? [];
25808
+ return {
25809
+ text: [`${read.project}: ${issues.length} finished issues`, ...issues.map(issueLine)].join(`
25810
+ `),
25811
+ details: { project: read.project, issues }
25812
+ };
25813
+ }
25814
+
25742
25815
  // ../envoy-client/src/dispatch-commands/priorities.ts
25743
25816
  function priorityWorkLine(work) {
25744
25817
  const place = (status) => {
@@ -26712,6 +26785,7 @@ var dispatchCommands = {
26712
26785
  dispatch_handoff_write: acting(handoffWriteCommand),
26713
26786
  dispatch_handoff_read: acting(handoffReadCommand),
26714
26787
  dispatch_steps: acting(stepsCommand),
26788
+ dispatch_plans: acting(plansCommand),
26715
26789
  dispatch_read: acting(readCommand),
26716
26790
  dispatch_answers: onSession(answersCommand),
26717
26791
  dispatch_whoami: onSession(whoamiCommand),
package/dist/dispatch.js CHANGED
@@ -14958,6 +14958,9 @@ var LEGION_ROLES = [
14958
14958
  "merger"
14959
14959
  ];
14960
14960
  var GATED_STEPS = ["decisions", "criteria", "spec"];
14961
+ var LEGION_PLAN_RATING_LEAST = 1;
14962
+ var LEGION_PLAN_RATING_MOST = 5;
14963
+ var LEGION_PLAN_REASON_MAX = 2000;
14961
14964
  var PROJECT_TOKEN = /^[a-z0-9]+$/;
14962
14965
  var DISPATCH_KEY_PATTERN = /^([A-Z][A-Z0-9]*)-([0-9]+)$/;
14963
14966
  function isLegionRole(role) {
@@ -15557,6 +15560,13 @@ var SEARCH_QUERY_HINT = "search with a short phrase of a few words, not a passag
15557
15560
  var SEARCH_KIND_DEPTH = 100;
15558
15561
  var PROJECT_KEY_PATTERN = /^[A-Z][A-Z0-9]{1,9}$/;
15559
15562
  var PROJECT_KEY_RULE = "an uppercase letter, then 1 to 9 uppercase letters or digits, such as CORE";
15563
+ var projectKeyValidation = {
15564
+ check: (value) => {
15565
+ const { project } = value;
15566
+ return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
15567
+ },
15568
+ message: `project is not a project key: ${PROJECT_KEY_RULE}`
15569
+ };
15560
15570
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
15561
15571
  var ISSUE_STATUSES = [
15562
15572
  "triage",
@@ -16008,9 +16018,9 @@ var dispatchToolSpecs = [
16008
16018
  validation: {
16009
16019
  check: (value) => {
16010
16020
  const { project } = value;
16011
- return typeof project !== "string" || project === "" || PROJECT_KEY_PATTERN.test(project);
16021
+ return project === "" || projectKeyValidation.check(value);
16012
16022
  },
16013
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
16023
+ message: projectKeyValidation.message
16014
16024
  }
16015
16025
  },
16016
16026
  {
@@ -16024,13 +16034,7 @@ var dispatchToolSpecs = [
16024
16034
  exclude_issues: z.array(z.string()).describe("Optional issue keys in the project whose own items are left out of the results; at most 50.").optional(),
16025
16035
  keywords_only: z.boolean().describe("Search by keywords only, skipping meaning search.").optional()
16026
16036
  }),
16027
- validation: {
16028
- check: (value) => {
16029
- const { project } = value;
16030
- return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
16031
- },
16032
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
16033
- }
16037
+ validation: projectKeyValidation
16034
16038
  },
16035
16039
  {
16036
16040
  name: "dispatch_issues",
@@ -16160,6 +16164,18 @@ var dispatchToolSpecs = [
16160
16164
  }),
16161
16165
  strict: true
16162
16166
  },
16167
+ {
16168
+ name: "dispatch_plans",
16169
+ example: { project: "INFRA" },
16170
+ description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time and its count of " + "failed steps. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>\`. ` + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
16171
+ arguments: (z) => ({
16172
+ project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
16173
+ since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
16174
+ until: z.string().describe("Optional RFC 3339 time; only issues closed before it.").optional()
16175
+ }),
16176
+ validation: projectKeyValidation,
16177
+ strict: true
16178
+ },
16163
16179
  {
16164
16180
  name: "dispatch_inbox",
16165
16181
  example: {},
@@ -20573,6 +20589,9 @@ class DispatchClient {
20573
20589
  async listSteps(issue) {
20574
20590
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "steps"]);
20575
20591
  }
20592
+ async listProjectPlans(project, window = {}) {
20593
+ return this.#json("GET", ["api", "v1", "projects", project, "plans"], undefined, window);
20594
+ }
20576
20595
  async getIssueReferences(issue) {
20577
20596
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "references"], undefined, { versions: "latest" });
20578
20597
  }
@@ -23401,6 +23420,7 @@ var issueFreeTools = {
23401
23420
  dispatch_search: true,
23402
23421
  dispatch_related: true,
23403
23422
  dispatch_issues: true,
23423
+ dispatch_plans: true,
23404
23424
  dispatch_project: true,
23405
23425
  dispatch_projects: true,
23406
23426
  dispatch_priorities: true,
@@ -25347,6 +25367,11 @@ async function sendToAgentCommand(context) {
25347
25367
 
25348
25368
  // ../envoy-client/src/dispatch-commands/documents.ts
25349
25369
  import { resolve as resolvePath2 } from "path";
25370
+
25371
+ // ../contracts/src/go-blank.ts
25372
+ var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
25373
+
25374
+ // ../envoy-client/src/dispatch-commands/documents.ts
25350
25375
  async function blockAsks(client, resolved, state) {
25351
25376
  const asks = await (resolved.issue === undefined ? client.getArtifactAsks(resolved.artifact.id, state) : client.listIssueAsks(resolved.issue.key, state));
25352
25377
  return asks.filter((ask) => typeof ask.block_id === "string" && ask.block_artifact?.id === resolved.artifact.id);
@@ -25789,7 +25814,6 @@ function withoutFinalLineFeed(text) {
25789
25814
  return text.endsWith(`
25790
25815
  `) ? text.slice(0, -1) : text;
25791
25816
  }
25792
- var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
25793
25817
  async function artifactCommand(context) {
25794
25818
  const { args, client, actor, input, documentOwner, issue } = context;
25795
25819
  const summary = optionalString(args, "summary");
@@ -26772,6 +26796,55 @@ async function resultsCommand(context) {
26772
26796
  };
26773
26797
  }
26774
26798
 
26799
+ // ../envoy-client/src/dispatch-commands/plans.ts
26800
+ function planText(plan) {
26801
+ if (plan === null)
26802
+ return "plan none";
26803
+ const tasks = plan.tasks ?? [];
26804
+ const first = tasks[0]?.steps ?? [];
26805
+ return `plan ${plan.source} (${tasks.length} tasks: ${first.length === 0 ? "-" : first.join(" ")})`;
26806
+ }
26807
+ var unescapedLineBreaks = /[\u0085\u2028\u2029]/g;
26808
+ function oneLineJson(text) {
26809
+ return JSON.stringify(text).replace(unescapedLineBreaks, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
26810
+ }
26811
+ function ratingsText(ratings) {
26812
+ if (ratings === null || ratings.length === 0)
26813
+ return "ratings none";
26814
+ return `ratings ${ratings.map((rating) => `${rating.rating}/${LEGION_PLAN_RATING_MOST} ${oneLineJson(rating.reason)}`).join(", ")}`;
26815
+ }
26816
+ function timeText(seconds) {
26817
+ if (seconds === null)
26818
+ return "time -";
26819
+ const minutes = Math.floor(seconds / 60);
26820
+ return `time ${Math.floor(minutes / 60)}h${minutes % 60}m`;
26821
+ }
26822
+ function issueLine(issue) {
26823
+ return [
26824
+ issue.issue,
26825
+ "closed",
26826
+ issue.closed_at,
26827
+ planText(issue.plan),
26828
+ ratingsText(issue.ratings),
26829
+ timeText(issue.duration_seconds),
26830
+ "failed steps",
26831
+ issue.failed_steps
26832
+ ].join(" ");
26833
+ }
26834
+ async function plansCommand(context) {
26835
+ const { args, client } = context;
26836
+ const read = await client.listProjectPlans(stringArg(args, "project"), {
26837
+ since: optionalString(args, "since"),
26838
+ until: optionalString(args, "until")
26839
+ });
26840
+ const issues = read.issues ?? [];
26841
+ return {
26842
+ text: [`${read.project}: ${issues.length} finished issues`, ...issues.map(issueLine)].join(`
26843
+ `),
26844
+ details: { project: read.project, issues }
26845
+ };
26846
+ }
26847
+
26775
26848
  // ../envoy-client/src/dispatch-commands/priorities.ts
26776
26849
  function priorityWorkLine(work) {
26777
26850
  const place = (status) => {
@@ -27745,6 +27818,7 @@ var dispatchCommands = {
27745
27818
  dispatch_handoff_write: acting(handoffWriteCommand),
27746
27819
  dispatch_handoff_read: acting(handoffReadCommand),
27747
27820
  dispatch_steps: acting(stepsCommand),
27821
+ dispatch_plans: acting(plansCommand),
27748
27822
  dispatch_read: acting(readCommand),
27749
27823
  dispatch_answers: onSession(answersCommand),
27750
27824
  dispatch_whoami: onSession(whoamiCommand),
@@ -36440,6 +36440,9 @@ var LEGION_ROLES = [
36440
36440
  "merger"
36441
36441
  ];
36442
36442
  var GATED_STEPS = ["decisions", "criteria", "spec"];
36443
+ var LEGION_PLAN_RATING_LEAST = 1;
36444
+ var LEGION_PLAN_RATING_MOST = 5;
36445
+ var LEGION_PLAN_REASON_MAX = 2000;
36443
36446
  var PROJECT_TOKEN = /^[a-z0-9]+$/;
36444
36447
  var DISPATCH_KEY_PATTERN = /^([A-Z][A-Z0-9]*)-([0-9]+)$/;
36445
36448
  function isLegionRole(role) {
@@ -37039,6 +37042,13 @@ var SEARCH_QUERY_HINT = "search with a short phrase of a few words, not a passag
37039
37042
  var SEARCH_KIND_DEPTH = 100;
37040
37043
  var PROJECT_KEY_PATTERN = /^[A-Z][A-Z0-9]{1,9}$/;
37041
37044
  var PROJECT_KEY_RULE = "an uppercase letter, then 1 to 9 uppercase letters or digits, such as CORE";
37045
+ var projectKeyValidation = {
37046
+ check: (value) => {
37047
+ const { project } = value;
37048
+ return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
37049
+ },
37050
+ message: `project is not a project key: ${PROJECT_KEY_RULE}`
37051
+ };
37042
37052
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
37043
37053
  var ISSUE_STATUSES = [
37044
37054
  "triage",
@@ -37490,9 +37500,9 @@ var dispatchToolSpecs = [
37490
37500
  validation: {
37491
37501
  check: (value) => {
37492
37502
  const { project } = value;
37493
- return typeof project !== "string" || project === "" || PROJECT_KEY_PATTERN.test(project);
37503
+ return project === "" || projectKeyValidation.check(value);
37494
37504
  },
37495
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
37505
+ message: projectKeyValidation.message
37496
37506
  }
37497
37507
  },
37498
37508
  {
@@ -37506,13 +37516,7 @@ var dispatchToolSpecs = [
37506
37516
  exclude_issues: z.array(z.string()).describe("Optional issue keys in the project whose own items are left out of the results; at most 50.").optional(),
37507
37517
  keywords_only: z.boolean().describe("Search by keywords only, skipping meaning search.").optional()
37508
37518
  }),
37509
- validation: {
37510
- check: (value) => {
37511
- const { project } = value;
37512
- return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
37513
- },
37514
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
37515
- }
37519
+ validation: projectKeyValidation
37516
37520
  },
37517
37521
  {
37518
37522
  name: "dispatch_issues",
@@ -37642,6 +37646,18 @@ var dispatchToolSpecs = [
37642
37646
  }),
37643
37647
  strict: true
37644
37648
  },
37649
+ {
37650
+ name: "dispatch_plans",
37651
+ example: { project: "INFRA" },
37652
+ description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time and its count of " + "failed steps. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>\`. ` + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
37653
+ arguments: (z) => ({
37654
+ project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
37655
+ since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
37656
+ until: z.string().describe("Optional RFC 3339 time; only issues closed before it.").optional()
37657
+ }),
37658
+ validation: projectKeyValidation,
37659
+ strict: true
37660
+ },
37645
37661
  {
37646
37662
  name: "dispatch_inbox",
37647
37663
  example: {},
@@ -44134,6 +44150,9 @@ class DispatchClient {
44134
44150
  async listSteps(issue) {
44135
44151
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "steps"]);
44136
44152
  }
44153
+ async listProjectPlans(project, window2 = {}) {
44154
+ return this.#json("GET", ["api", "v1", "projects", project, "plans"], undefined, window2);
44155
+ }
44137
44156
  async getIssueReferences(issue) {
44138
44157
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "references"], undefined, { versions: "latest" });
44139
44158
  }
@@ -47857,6 +47876,7 @@ var issueFreeTools = {
47857
47876
  dispatch_search: true,
47858
47877
  dispatch_related: true,
47859
47878
  dispatch_issues: true,
47879
+ dispatch_plans: true,
47860
47880
  dispatch_project: true,
47861
47881
  dispatch_projects: true,
47862
47882
  dispatch_priorities: true,
@@ -49803,6 +49823,11 @@ async function sendToAgentCommand(context) {
49803
49823
 
49804
49824
  // ../envoy-client/src/dispatch-commands/documents.ts
49805
49825
  import { resolve as resolvePath2 } from "path";
49826
+
49827
+ // ../contracts/src/go-blank.ts
49828
+ var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
49829
+
49830
+ // ../envoy-client/src/dispatch-commands/documents.ts
49806
49831
  async function blockAsks(client, resolved, state) {
49807
49832
  const asks = await (resolved.issue === undefined ? client.getArtifactAsks(resolved.artifact.id, state) : client.listIssueAsks(resolved.issue.key, state));
49808
49833
  return asks.filter((ask) => typeof ask.block_id === "string" && ask.block_artifact?.id === resolved.artifact.id);
@@ -50245,7 +50270,6 @@ function withoutFinalLineFeed(text) {
50245
50270
  return text.endsWith(`
50246
50271
  `) ? text.slice(0, -1) : text;
50247
50272
  }
50248
- var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
50249
50273
  async function artifactCommand(context) {
50250
50274
  const { args, client, actor, input, documentOwner, issue } = context;
50251
50275
  const summary = optionalString(args, "summary");
@@ -51228,6 +51252,55 @@ async function resultsCommand(context) {
51228
51252
  };
51229
51253
  }
51230
51254
 
51255
+ // ../envoy-client/src/dispatch-commands/plans.ts
51256
+ function planText(plan) {
51257
+ if (plan === null)
51258
+ return "plan none";
51259
+ const tasks = plan.tasks ?? [];
51260
+ const first = tasks[0]?.steps ?? [];
51261
+ return `plan ${plan.source} (${tasks.length} tasks: ${first.length === 0 ? "-" : first.join(" ")})`;
51262
+ }
51263
+ var unescapedLineBreaks = /[\u0085\u2028\u2029]/g;
51264
+ function oneLineJson(text) {
51265
+ return JSON.stringify(text).replace(unescapedLineBreaks, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
51266
+ }
51267
+ function ratingsText(ratings) {
51268
+ if (ratings === null || ratings.length === 0)
51269
+ return "ratings none";
51270
+ return `ratings ${ratings.map((rating) => `${rating.rating}/${LEGION_PLAN_RATING_MOST} ${oneLineJson(rating.reason)}`).join(", ")}`;
51271
+ }
51272
+ function timeText(seconds) {
51273
+ if (seconds === null)
51274
+ return "time -";
51275
+ const minutes = Math.floor(seconds / 60);
51276
+ return `time ${Math.floor(minutes / 60)}h${minutes % 60}m`;
51277
+ }
51278
+ function issueLine(issue) {
51279
+ return [
51280
+ issue.issue,
51281
+ "closed",
51282
+ issue.closed_at,
51283
+ planText(issue.plan),
51284
+ ratingsText(issue.ratings),
51285
+ timeText(issue.duration_seconds),
51286
+ "failed steps",
51287
+ issue.failed_steps
51288
+ ].join(" ");
51289
+ }
51290
+ async function plansCommand(context) {
51291
+ const { args, client } = context;
51292
+ const read = await client.listProjectPlans(stringArg(args, "project"), {
51293
+ since: optionalString(args, "since"),
51294
+ until: optionalString(args, "until")
51295
+ });
51296
+ const issues = read.issues ?? [];
51297
+ return {
51298
+ text: [`${read.project}: ${issues.length} finished issues`, ...issues.map(issueLine)].join(`
51299
+ `),
51300
+ details: { project: read.project, issues }
51301
+ };
51302
+ }
51303
+
51231
51304
  // ../envoy-client/src/dispatch-commands/priorities.ts
51232
51305
  function priorityWorkLine(work) {
51233
51306
  const place = (status) => {
@@ -52169,6 +52242,7 @@ var dispatchCommands = {
52169
52242
  dispatch_handoff_write: acting(handoffWriteCommand),
52170
52243
  dispatch_handoff_read: acting(handoffReadCommand),
52171
52244
  dispatch_steps: acting(stepsCommand),
52245
+ dispatch_plans: acting(plansCommand),
52172
52246
  dispatch_read: acting(readCommand),
52173
52247
  dispatch_answers: onSession(answersCommand),
52174
52248
  dispatch_whoami: onSession(whoamiCommand),
@@ -57838,6 +57912,24 @@ var LegionControllerGrantRequest = strictObject({
57838
57912
  sessionId: nonEmptyString2,
57839
57913
  secret: nonEmptyString2
57840
57914
  });
57915
+ function legionPlanRatingScale(rating, refusal) {
57916
+ const error = refusal === undefined ? undefined : { error: refusal };
57917
+ return rating.int(error).min(LEGION_PLAN_RATING_LEAST, error).max(LEGION_PLAN_RATING_MOST, error);
57918
+ }
57919
+ function legionPlanReasonRules(reason, refusals) {
57920
+ return reason.refine((text) => !goBlankPattern.test(text), { error: refusals.blank, abort: true }).refine((text) => [...text].length <= LEGION_PLAN_REASON_MAX, { error: refusals.long });
57921
+ }
57922
+ var legionPlanReason = legionPlanReasonRules(string2(), {
57923
+ blank: "planReason says why",
57924
+ long: `planReason holds at most ${LEGION_PLAN_REASON_MAX} characters`
57925
+ });
57926
+ function legionPlanRatingLoneField(rating, reason) {
57927
+ if (rating !== undefined && reason === undefined)
57928
+ return "rating";
57929
+ if (reason !== undefined && rating === undefined)
57930
+ return "reason";
57931
+ return;
57932
+ }
57841
57933
  var LegionHandoffCompleteRequest = strictObject({
57842
57934
  grantId: nonEmptyString2,
57843
57935
  summary: nonEmptyString2,
@@ -57845,8 +57937,10 @@ var LegionHandoffCompleteRequest = strictObject({
57845
57937
  commit: nonEmptyString2.optional(),
57846
57938
  handoffId: nonEmptyString2.optional(),
57847
57939
  handoffVersion: number2().int().positive().optional(),
57848
- wakeAt: LegionInstant.optional()
57849
- });
57940
+ wakeAt: LegionInstant.optional(),
57941
+ planRating: legionPlanRatingScale(number2()).optional(),
57942
+ planReason: legionPlanReason.optional()
57943
+ }).refine((request) => legionPlanRatingLoneField(request.planRating, request.planReason) === undefined, { message: "planRating and planReason appear together" });
57850
57944
  var LegionIssueStatusRequest = strictObject({
57851
57945
  grantId: nonEmptyString2,
57852
57946
  issue: nonEmptyString2,
@@ -58286,9 +58380,9 @@ var import_nats2 = __toESM(require_mod4(), 1);
58286
58380
 
58287
58381
  // package.json
58288
58382
  var name2 = "@sjawhar/claude-envoy";
58289
- var version2 = "4.7.0";
58383
+ var version2 = "4.9.0";
58290
58384
  var legion = {
58291
- daemonApiVersion: 160
58385
+ daemonApiVersion: 168
58292
58386
  };
58293
58387
 
58294
58388
  // ../pi-shared/src/agent-stream.ts
@@ -60523,6 +60617,14 @@ var requiredString = (op, field) => {
60523
60617
  var rfc3339String = (op, field, message) => requiredString(op, field).refine((value) => value.trim() === "" || LegionInstant.safeParse(value).success, { error: message });
60524
60618
  var windowStart = rfc3339String("read_release_records", "since", "read_release_records' since is an RFC 3339 time, as 2026-11-02T09:00:00Z is");
60525
60619
  var nextLook = rfc3339String("handoff_complete", "wake_at", "handoff_complete's wake_at is an RFC 3339 time, as 2026-11-02T09:00:00Z is");
60620
+ var PLAN_RATING_REFUSAL = `handoff_complete's plan_rating is a whole number from ${LEGION_PLAN_RATING_LEAST} to ${LEGION_PLAN_RATING_MOST}`;
60621
+ var planRating = legionPlanRatingScale(number2({ error: PLAN_RATING_REFUSAL }), PLAN_RATING_REFUSAL);
60622
+ var PLAN_REASON_MOST = LEGION_PLAN_REASON_MAX.toLocaleString("en-US");
60623
+ var PLAN_REASON_REQUIRED = "handoff_complete requires plan_reason";
60624
+ var planReason = legionPlanReasonRules(string2({ error: PLAN_REASON_REQUIRED }), {
60625
+ blank: PLAN_REASON_REQUIRED,
60626
+ long: `handoff_complete's plan_reason holds at most ${PLAN_REASON_MOST} characters`
60627
+ });
60526
60628
  var unknownFieldsRefusal = (op, refused, takes) => [
60527
60629
  ...refused.map((field) => `${op} does not accept field "${field}"`),
60528
60630
  `it takes ${takes.length === 0 ? "none" : takes.join(", ")}`
@@ -60543,7 +60645,13 @@ var PhaseOpArguments = discriminatedUnion("op", [
60543
60645
  verdict: _enum2(["pass", "pending", "fail"], {
60544
60646
  error: "handoff_complete's verdict is pass, pending or fail"
60545
60647
  }).optional(),
60546
- wake_at: nextLook.optional()
60648
+ wake_at: nextLook.optional(),
60649
+ plan_rating: planRating.optional(),
60650
+ plan_reason: planReason.optional()
60651
+ }).refine((args) => legionPlanRatingLoneField(args.plan_rating, args.plan_reason) !== "rating", {
60652
+ error: "handoff_complete names plan_rating without plan_reason: send the rating of the plan with one sentence of why, the two together"
60653
+ }).refine((args) => legionPlanRatingLoneField(args.plan_rating, args.plan_reason) !== "reason", {
60654
+ error: `handoff_complete names plan_reason without plan_rating: send the reason with the rating of the plan, a whole number from ${LEGION_PLAN_RATING_LEAST} to ${LEGION_PLAN_RATING_MOST}, the two together`
60547
60655
  }),
60548
60656
  operation("request_backward_move", {
60549
60657
  issue: string2({ error: "request_backward_move's issue is an issue key, as LEGION-208 is" }).optional(),
@@ -60566,7 +60674,14 @@ function phaseOpParameters(zod) {
60566
60674
  const field = declared instanceof ZodOptional ? declared.unwrap() : declared;
60567
60675
  if (field instanceof ZodString)
60568
60676
  fields[name] = api.string().optional();
60569
- else if (field instanceof ZodBoolean)
60677
+ else if (field instanceof ZodNumber) {
60678
+ const { isInt, minValue, maxValue } = field;
60679
+ fields[name] = api.number({
60680
+ int: isInt,
60681
+ ...minValue !== null && Number.isFinite(minValue) ? { min: minValue } : {},
60682
+ ...maxValue !== null && Number.isFinite(maxValue) ? { max: maxValue } : {}
60683
+ }).optional();
60684
+ } else if (field instanceof ZodBoolean)
60570
60685
  fields[name] = api.boolean().optional();
60571
60686
  else if (field instanceof ZodEnum) {
60572
60687
  const [first, ...rest] = field.options.map(String);
@@ -60587,7 +60702,7 @@ var PHASE_OP_SENTENCES = {
60587
60702
  };
60588
60703
  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";
60589
60704
  function legionToolDescription(host) {
60590
- 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). " + "A planning, implementing, testing or reviewing phase ends with a handoff record on the " + "Dispatch issue: write it with `dispatch handoff-write --issue <issue> --phase <plan|implement|test|review> --body-file <file>` before " + "calling. This call reads from Dispatch the newest record of the phase your role works or, once the issue has moved on, of the phase it left, " + "and reports it with `commit`, the head that record's body names " + "(`head`, the 40-character lower-case commit the work it reports was done against); in implementing, the implementer's must be the commit its " + "workspace stands on, `@-`, pushed to `legion/<issue>@origin`, so push the branch first; retro, the merger's completion and a phase you left with no record, or with an implement record naming no head, report the commit the workspace stands on. It " + "refuses, posting nothing, a phase you work with no record, a Dispatch that does not answer, and, in implementing, an implement record naming no head, an " + "implementer's `@-` not yet on `legion/<issue>@origin`, or an implement record whose head is not that pushed `@-`, each naming the remedy. A production check report " + "(the task whose first line is `Production check of <KEY>`, handed once the merge closed the issue to the role the check records) needs no " + "handoff and no commit: it carries its verdict and summary alone. A pending report also names `wake_at`, an RFC 3339 time: when you want the " + "next look. A pass, a fail, and a pending on the check's last look end the check, so none of them carries `wake_at` " + "(CHECK_WAKE_UNEXPECTED), and a pending on any other look is refused without one (CHECK_WAKE_REQUIRED). A report on an issue whose check is " + "closed or never opened is refused (CHECK_NOT_OPEN), and so is one from a role the check does not record (CHECK_ROLE_MISMATCH). " + "The daemon refuses " + "HANDOFF_SESSION_MISMATCH (another session wrote the record), HANDOFF_NOT_NEW (the record is the one you named for your previous phase: " + "write this phase's handoff), " + "HANDOFF_STALE_ENTRY (this completion is of a phase entry behind the one your role's phases row names, because the phase was entered " + `again while your turn ran, and nothing was recorded. ${STALE_ENTRY_INSTRUCTION}), the implementer's completion of implementing with no open ` + "pull request on `legion/<issue>` and none recorded " + "merged (HANDOFF_NO_PULL_REQUEST: open it; one naming a closed pull request is the architect's to decide); a refused completion changed " + "nothing, so fix what it names and complete again. " + "ready_for_update answers the daemon's update message on this issue's pod: `round` is the round id that message names, and the " + "daemon takes your answer for that round alone. Push every commit you want kept to the issue branch " + "first. The daemon replaces the pod and its disk when the round ends: at the moment the message names, or earlier when every " + "role has answered and no turn runs. No answer delays that moment, and the end of a turn is no answer. The call ends no phase. The " + "daemon holds your next task until your process comes back on the new pod, in this same session. " + (host.after ?? "") + `What a later phase needs goes in your handoff; a question for another live role goes to its role topic with ${host.envoyPublish}.`;
60705
+ 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). " + "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. Push every commit you want kept to the issue branch " + "first. The daemon replaces the pod and its disk when the round ends: at the moment the message names, or earlier when every " + "role has answered and no turn runs. No answer delays that moment, and the end of a turn is no answer. The call ends no phase. The " + "daemon holds your next task until your process comes back on the new pod, in this same session. " + (host.after ?? "") + `What a later phase needs goes in your handoff; a question for another live role goes to its role topic with ${host.envoyPublish}.`;
60591
60706
  }
60592
60707
  async function mintClaimGrant(daemon, claim) {
60593
60708
  const { grantId } = await daemon.grant({
@@ -60632,7 +60747,9 @@ async function executePhaseOp(runtime, input) {
60632
60747
  if (named !== "" && named !== claim.issue) {
60633
60748
  throw new Error(`handoff_complete reports this session's own issue ${claim.issue}; leave issue out, or name ${claim.issue}, not ${named}`);
60634
60749
  }
60635
- return retryWhileDaemonRestarts("handoff_complete", () => completeHandoff(runtime, args), runtime.restart);
60750
+ const { plan_rating: planRating, plan_reason: planReason } = args;
60751
+ const rating = planRating === undefined || planReason === undefined ? undefined : { planRating, planReason };
60752
+ return retryWhileDaemonRestarts("handoff_complete", () => completeHandoff(runtime, args, rating), runtime.restart);
60636
60753
  }
60637
60754
  case "request_backward_move": {
60638
60755
  let issue;
@@ -60748,7 +60865,7 @@ async function releaseRecords(runtime, since) {
60748
60865
  }
60749
60866
  };
60750
60867
  }
60751
- async function completeHandoff(runtime, args) {
60868
+ async function completeHandoff(runtime, args, rating) {
60752
60869
  const { daemon, claim } = runtime;
60753
60870
  const record = recordFrom(await daemon.state(), claim.issue);
60754
60871
  if (record.phase === "done") {
@@ -60772,7 +60889,8 @@ async function completeHandoff(runtime, args) {
60772
60889
  grantId: await mintClaimGrant(daemon, claim),
60773
60890
  summary: args.summary,
60774
60891
  verdict: args.verdict ?? "",
60775
- ...args.wake_at === undefined ? {} : { wakeAt: args.wake_at }
60892
+ ...args.wake_at === undefined ? {} : { wakeAt: args.wake_at },
60893
+ ...rating
60776
60894
  });
60777
60895
  }
60778
60896
  if (args.verdict === "pending") {
@@ -60786,7 +60904,8 @@ async function completeHandoff(runtime, args) {
60786
60904
  grantId: await mintClaimGrant(daemon, claim),
60787
60905
  summary: args.summary,
60788
60906
  verdict: args.verdict ?? "",
60789
- ...report
60907
+ ...report,
60908
+ ...rating
60790
60909
  });
60791
60910
  }
60792
60911
 
@@ -13865,6 +13865,9 @@ var LEGION_ROLES = [
13865
13865
  "merger"
13866
13866
  ];
13867
13867
  var GATED_STEPS = ["decisions", "criteria", "spec"];
13868
+ var LEGION_PLAN_RATING_LEAST = 1;
13869
+ var LEGION_PLAN_RATING_MOST = 5;
13870
+ var LEGION_PLAN_REASON_MAX = 2000;
13868
13871
  var PROJECT_TOKEN = /^[a-z0-9]+$/;
13869
13872
  var DISPATCH_KEY_PATTERN = /^([A-Z][A-Z0-9]*)-([0-9]+)$/;
13870
13873
  function isLegionRole(role) {
@@ -14464,6 +14467,13 @@ var SEARCH_QUERY_HINT = "search with a short phrase of a few words, not a passag
14464
14467
  var SEARCH_KIND_DEPTH = 100;
14465
14468
  var PROJECT_KEY_PATTERN = /^[A-Z][A-Z0-9]{1,9}$/;
14466
14469
  var PROJECT_KEY_RULE = "an uppercase letter, then 1 to 9 uppercase letters or digits, such as CORE";
14470
+ var projectKeyValidation = {
14471
+ check: (value) => {
14472
+ const { project } = value;
14473
+ return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
14474
+ },
14475
+ message: `project is not a project key: ${PROJECT_KEY_RULE}`
14476
+ };
14467
14477
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
14468
14478
  var ISSUE_STATUSES = [
14469
14479
  "triage",
@@ -14915,9 +14925,9 @@ var dispatchToolSpecs = [
14915
14925
  validation: {
14916
14926
  check: (value) => {
14917
14927
  const { project } = value;
14918
- return typeof project !== "string" || project === "" || PROJECT_KEY_PATTERN.test(project);
14928
+ return project === "" || projectKeyValidation.check(value);
14919
14929
  },
14920
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
14930
+ message: projectKeyValidation.message
14921
14931
  }
14922
14932
  },
14923
14933
  {
@@ -14931,13 +14941,7 @@ var dispatchToolSpecs = [
14931
14941
  exclude_issues: z.array(z.string()).describe("Optional issue keys in the project whose own items are left out of the results; at most 50.").optional(),
14932
14942
  keywords_only: z.boolean().describe("Search by keywords only, skipping meaning search.").optional()
14933
14943
  }),
14934
- validation: {
14935
- check: (value) => {
14936
- const { project } = value;
14937
- return typeof project !== "string" || PROJECT_KEY_PATTERN.test(project);
14938
- },
14939
- message: `project is not a project key: ${PROJECT_KEY_RULE}`
14940
- }
14944
+ validation: projectKeyValidation
14941
14945
  },
14942
14946
  {
14943
14947
  name: "dispatch_issues",
@@ -15067,6 +15071,18 @@ var dispatchToolSpecs = [
15067
15071
  }),
15068
15072
  strict: true
15069
15073
  },
15074
+ {
15075
+ name: "dispatch_plans",
15076
+ example: { project: "INFRA" },
15077
+ description: "Print each finished issue of a project, newest close first, with the plan Legion ran it " + "from, the rating each retro gave that plan with its reason, its time and its count of " + "failed steps. An issue is finished when its status is done and Dispatch closed it. The " + "first line is `<PROJECT>: <n> finished issues`. Then each issue prints one line: `<KEY> " + "closed <closed_at> plan <source> (<n> tasks: <steps of the first task>) ratings " + `<rating>/${LEGION_PLAN_RATING_MOST} "<reason>"[, <rating>/${LEGION_PLAN_RATING_MOST} "<reason>" ...] time <h>h<m>m failed steps <n>\`. ` + "source is default (Legion's default steps) or owner (the plan the issue's owner wrote), " + `and the plan is the one of the issue's newest run. A rating is ${LEGION_PLAN_RATING_LEAST} (the plan cost the ` + `work) to ${LEGION_PLAN_RATING_MOST} (the plan fit the work), one for each retro in the order the retros ran, and ` + "its reason prints as a JSON string. time runs from the first start of the issue's steps " + "to the last end, in whole hours and minutes rounded down. failed steps counts the runs " + "of a step that failed, retros and merges left out. An issue with no plan prints plan " + "none, one with no rating prints ratings none, and one whose time is not known prints " + "time -: an issue Legion never ran prints all three. since and until, each an RFC 3339 " + "time, keep the issues closed at or after since and before until.",
15078
+ arguments: (z) => ({
15079
+ project: z.string().describe("Project key whose finished issues to list, such as INFRA."),
15080
+ since: z.string().describe("Optional RFC 3339 time; only issues closed at or after it.").optional(),
15081
+ until: z.string().describe("Optional RFC 3339 time; only issues closed before it.").optional()
15082
+ }),
15083
+ validation: projectKeyValidation,
15084
+ strict: true
15085
+ },
15070
15086
  {
15071
15087
  name: "dispatch_inbox",
15072
15088
  example: {},
@@ -20296,6 +20312,9 @@ class DispatchClient {
20296
20312
  async listSteps(issue) {
20297
20313
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "steps"]);
20298
20314
  }
20315
+ async listProjectPlans(project, window = {}) {
20316
+ return this.#json("GET", ["api", "v1", "projects", project, "plans"], undefined, window);
20317
+ }
20299
20318
  async getIssueReferences(issue) {
20300
20319
  return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "references"], undefined, { versions: "latest" });
20301
20320
  }
@@ -22369,6 +22388,7 @@ var issueFreeTools = {
22369
22388
  dispatch_search: true,
22370
22389
  dispatch_related: true,
22371
22390
  dispatch_issues: true,
22391
+ dispatch_plans: true,
22372
22392
  dispatch_project: true,
22373
22393
  dispatch_projects: true,
22374
22394
  dispatch_priorities: true,
@@ -24315,6 +24335,11 @@ async function sendToAgentCommand(context) {
24315
24335
 
24316
24336
  // ../envoy-client/src/dispatch-commands/documents.ts
24317
24337
  import { resolve as resolvePath2 } from "path";
24338
+
24339
+ // ../contracts/src/go-blank.ts
24340
+ var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
24341
+
24342
+ // ../envoy-client/src/dispatch-commands/documents.ts
24318
24343
  async function blockAsks(client, resolved, state) {
24319
24344
  const asks = await (resolved.issue === undefined ? client.getArtifactAsks(resolved.artifact.id, state) : client.listIssueAsks(resolved.issue.key, state));
24320
24345
  return asks.filter((ask) => typeof ask.block_id === "string" && ask.block_artifact?.id === resolved.artifact.id);
@@ -24757,7 +24782,6 @@ function withoutFinalLineFeed(text) {
24757
24782
  return text.endsWith(`
24758
24783
  `) ? text.slice(0, -1) : text;
24759
24784
  }
24760
- var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
24761
24785
  async function artifactCommand(context) {
24762
24786
  const { args, client, actor, input, documentOwner, issue } = context;
24763
24787
  const summary = optionalString(args, "summary");
@@ -25740,6 +25764,55 @@ async function resultsCommand(context) {
25740
25764
  };
25741
25765
  }
25742
25766
 
25767
+ // ../envoy-client/src/dispatch-commands/plans.ts
25768
+ function planText(plan) {
25769
+ if (plan === null)
25770
+ return "plan none";
25771
+ const tasks = plan.tasks ?? [];
25772
+ const first = tasks[0]?.steps ?? [];
25773
+ return `plan ${plan.source} (${tasks.length} tasks: ${first.length === 0 ? "-" : first.join(" ")})`;
25774
+ }
25775
+ var unescapedLineBreaks = /[\u0085\u2028\u2029]/g;
25776
+ function oneLineJson(text) {
25777
+ return JSON.stringify(text).replace(unescapedLineBreaks, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
25778
+ }
25779
+ function ratingsText(ratings) {
25780
+ if (ratings === null || ratings.length === 0)
25781
+ return "ratings none";
25782
+ return `ratings ${ratings.map((rating) => `${rating.rating}/${LEGION_PLAN_RATING_MOST} ${oneLineJson(rating.reason)}`).join(", ")}`;
25783
+ }
25784
+ function timeText(seconds) {
25785
+ if (seconds === null)
25786
+ return "time -";
25787
+ const minutes = Math.floor(seconds / 60);
25788
+ return `time ${Math.floor(minutes / 60)}h${minutes % 60}m`;
25789
+ }
25790
+ function issueLine(issue) {
25791
+ return [
25792
+ issue.issue,
25793
+ "closed",
25794
+ issue.closed_at,
25795
+ planText(issue.plan),
25796
+ ratingsText(issue.ratings),
25797
+ timeText(issue.duration_seconds),
25798
+ "failed steps",
25799
+ issue.failed_steps
25800
+ ].join(" ");
25801
+ }
25802
+ async function plansCommand(context) {
25803
+ const { args, client } = context;
25804
+ const read = await client.listProjectPlans(stringArg(args, "project"), {
25805
+ since: optionalString(args, "since"),
25806
+ until: optionalString(args, "until")
25807
+ });
25808
+ const issues = read.issues ?? [];
25809
+ return {
25810
+ text: [`${read.project}: ${issues.length} finished issues`, ...issues.map(issueLine)].join(`
25811
+ `),
25812
+ details: { project: read.project, issues }
25813
+ };
25814
+ }
25815
+
25743
25816
  // ../envoy-client/src/dispatch-commands/priorities.ts
25744
25817
  function priorityWorkLine(work) {
25745
25818
  const place = (status) => {
@@ -26713,6 +26786,7 @@ var dispatchCommands = {
26713
26786
  dispatch_handoff_write: acting(handoffWriteCommand),
26714
26787
  dispatch_handoff_read: acting(handoffReadCommand),
26715
26788
  dispatch_steps: acting(stepsCommand),
26789
+ dispatch_plans: acting(plansCommand),
26716
26790
  dispatch_read: acting(readCommand),
26717
26791
  dispatch_answers: onSession(answersCommand),
26718
26792
  dispatch_whoami: onSession(whoamiCommand),
@@ -112,6 +112,14 @@ Dispatch message (step 5) is for a finished retro only.
112
112
  writes no handoff and makes no commit. In the workspace retro changes nothing; outside it, it
113
113
  writes only step 4's `mktemp -d` directory, the PR body and the Dispatch comment and message.
114
114
  It sets no GitHub or Dispatch label: Legion keeps phase state in the daemon, not in labels.
115
+ In the same call, rate the plan the issue ran: its steps and the role that worked each, not the
116
+ planner's `plan.md`. Send both or neither of `plan_rating`, a whole number from 1 (the plan cost
117
+ the work) to 5 (the plan fit the work), and `plan_reason`, one sentence of why from step 1's
118
+ evidence. The daemon refuses this completion without them (`PLAN_RATING_REQUIRED`), one alone,
119
+ a rating off that scale or a reason blank or over 2,000 characters (`PLAN_RATING_INPUT`), and
120
+ both on any other completion (`PLAN_RATING_UNEXPECTED`). A refusal records nothing, so complete
121
+ again. A `legion` tool whose `handoff_complete` takes neither field is the release before the
122
+ rating: send neither.
115
123
 
116
124
  ## Before you complete
117
125
 
@@ -121,3 +129,5 @@ Dispatch message (step 5) is for a finished retro only.
121
129
  - Each body line you added or changed that says work was done names work this pull request did.
122
130
  - The Dispatch comment and the Dispatch message are posted, and the pull request's head is the
123
131
  head you found.
132
+ - Your `handoff_complete` carries `plan_rating` and `plan_reason` (step 6), or neither where your
133
+ `legion` tool's `handoff_complete` takes neither.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "4.7.0",
3
+ "version": "4.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "AGENTS.md"
20
20
  ],
21
21
  "legion": {
22
- "daemonApiVersion": 160
22
+ "daemonApiVersion": 168
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",