@intentius/chant 0.124.56 → 0.124.58

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.
Files changed (199) hide show
  1. package/dist/ci-audit/index.d.ts.map +1 -1
  2. package/dist/ci-audit/index.js +1 -2
  3. package/dist/ci-product-words.d.ts +47 -2
  4. package/dist/ci-product-words.d.ts.map +1 -1
  5. package/dist/ci-product-words.js +59 -1
  6. package/dist/ci-product.d.ts +26 -2
  7. package/dist/ci-product.d.ts.map +1 -1
  8. package/dist/ci-product.js +30 -7
  9. package/dist/cli/commands/init.d.ts +2 -0
  10. package/dist/cli/commands/init.d.ts.map +1 -1
  11. package/dist/cli/commands/init.js +1 -1
  12. package/dist/cli/handlers/build.d.ts.map +1 -1
  13. package/dist/cli/handlers/build.js +5 -1
  14. package/dist/cli/handlers/init.d.ts.map +1 -1
  15. package/dist/cli/handlers/init.js +16 -0
  16. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  17. package/dist/cli/handlers/lifecycle.js +14 -0
  18. package/dist/cli/handlers/pr.d.ts.map +1 -1
  19. package/dist/cli/handlers/pr.js +90 -35
  20. package/dist/cli/handlers/serve.d.ts.map +1 -1
  21. package/dist/cli/handlers/serve.js +9 -0
  22. package/dist/cli/main.d.ts.map +1 -1
  23. package/dist/cli/main.js +6 -2
  24. package/dist/cli/mcp/product-tools.d.ts +40 -7
  25. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  26. package/dist/cli/mcp/product-tools.js +59 -15
  27. package/dist/cli/mcp/read-only.d.ts +2 -1
  28. package/dist/cli/mcp/read-only.d.ts.map +1 -1
  29. package/dist/cli/mcp/read-only.js +2 -1
  30. package/dist/cli/mcp/server.d.ts +11 -0
  31. package/dist/cli/mcp/server.d.ts.map +1 -1
  32. package/dist/cli/mcp/server.js +15 -3
  33. package/dist/cli/mcp-config.d.ts +4 -1
  34. package/dist/cli/mcp-config.d.ts.map +1 -1
  35. package/dist/cli/mcp-config.js +6 -2
  36. package/dist/cli/parse-args.d.ts.map +1 -1
  37. package/dist/cli/parse-args.js +9 -0
  38. package/dist/cli/registry.d.ts +8 -0
  39. package/dist/cli/registry.d.ts.map +1 -1
  40. package/dist/components/auto-release.d.ts +5 -2
  41. package/dist/components/auto-release.d.ts.map +1 -1
  42. package/dist/components/auto-release.js +9 -4
  43. package/dist/components/capability.d.ts +10 -0
  44. package/dist/components/capability.d.ts.map +1 -1
  45. package/dist/components/deploy-units.d.ts +12 -0
  46. package/dist/components/deploy-units.d.ts.map +1 -1
  47. package/dist/components/deploy-units.js +20 -1
  48. package/dist/components/pr-pipeline.d.ts +64 -2
  49. package/dist/components/pr-pipeline.d.ts.map +1 -1
  50. package/dist/components/pr-pipeline.js +66 -5
  51. package/dist/components/product-pipeline.d.ts +18 -1
  52. package/dist/components/product-pipeline.d.ts.map +1 -1
  53. package/dist/components/product-pipeline.js +8 -2
  54. package/dist/components/row-lease.d.ts +22 -1
  55. package/dist/components/row-lease.d.ts.map +1 -1
  56. package/dist/components/row-lease.js +32 -6
  57. package/dist/e2e-harness/driver.d.ts.map +1 -1
  58. package/dist/e2e-harness/driver.js +97 -0
  59. package/dist/e2e-harness/forgejo.d.ts +5 -1
  60. package/dist/e2e-harness/forgejo.d.ts.map +1 -1
  61. package/dist/e2e-harness/forgejo.js +35 -0
  62. package/dist/e2e-harness/index.d.ts +7 -0
  63. package/dist/e2e-harness/index.d.ts.map +1 -1
  64. package/dist/e2e-harness/index.js +11 -2
  65. package/dist/e2e-harness/ports.d.ts +31 -0
  66. package/dist/e2e-harness/ports.d.ts.map +1 -1
  67. package/dist/e2e-harness/scenario.d.ts.map +1 -1
  68. package/dist/e2e-harness/scenario.js +9 -5
  69. package/dist/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
  70. package/dist/e2e-harness/schemas/index.d.ts +22 -1
  71. package/dist/e2e-harness/schemas/index.d.ts.map +1 -1
  72. package/dist/e2e-harness/schemas/index.js +1 -1
  73. package/dist/e2e-harness/steps.d.ts.map +1 -1
  74. package/dist/e2e-harness/steps.js +4 -0
  75. package/dist/lexicon.d.ts +9 -0
  76. package/dist/lexicon.d.ts.map +1 -1
  77. package/dist/lifecycle/git.d.ts +39 -3
  78. package/dist/lifecycle/git.d.ts.map +1 -1
  79. package/dist/lifecycle/git.js +223 -15
  80. package/dist/lifecycle/lock-rows.d.ts +23 -0
  81. package/dist/lifecycle/lock-rows.d.ts.map +1 -1
  82. package/dist/lifecycle/lock-rows.js +47 -8
  83. package/dist/lifecycle/resource-lock.d.ts +70 -0
  84. package/dist/lifecycle/resource-lock.d.ts.map +1 -1
  85. package/dist/lifecycle/resource-lock.js +241 -5
  86. package/dist/mcp/types.d.ts +9 -0
  87. package/dist/mcp/types.d.ts.map +1 -1
  88. package/dist/op/gate.js +21 -4
  89. package/dist/op/op-waves-release-port.js +1 -1
  90. package/dist/op/op-waves-release.d.ts +2 -1
  91. package/dist/op/op-waves-release.d.ts.map +1 -1
  92. package/dist/op/op-waves-run.d.ts +8 -0
  93. package/dist/op/op-waves-run.d.ts.map +1 -1
  94. package/dist/op/op-waves-run.js +101 -29
  95. package/dist/op/op-waves.d.ts +18 -0
  96. package/dist/op/op-waves.d.ts.map +1 -1
  97. package/dist/op/op-waves.js +16 -0
  98. package/dist/pr-loop.d.ts.map +1 -1
  99. package/dist/pr-loop.js +1 -2
  100. package/dist/release-floors.d.ts +1 -1
  101. package/dist/release-floors.js +1 -1
  102. package/dist/template-request/index.d.ts +9 -0
  103. package/dist/template-request/index.d.ts.map +1 -0
  104. package/dist/template-request/index.js +8 -0
  105. package/dist/template-request/request-body.d.ts +21 -0
  106. package/dist/template-request/request-body.d.ts.map +1 -0
  107. package/dist/template-request/request-body.js +86 -0
  108. package/dist/template-request/template-request.d.ts +100 -0
  109. package/dist/template-request/template-request.d.ts.map +1 -0
  110. package/dist/template-request/template-request.js +150 -0
  111. package/dist/template-request/template-request.schema.json +100 -0
  112. package/dist/template-request/template-spec.d.ts +83 -0
  113. package/dist/template-request/template-spec.d.ts.map +1 -0
  114. package/dist/template-request/template-spec.js +146 -0
  115. package/dist/template-request/template.schema.json +114 -0
  116. package/dist/template-request/validate.d.ts +4 -0
  117. package/dist/template-request/validate.d.ts.map +1 -0
  118. package/dist/template-request/validate.js +21 -0
  119. package/dist/wave-runtime.mjs +310 -300
  120. package/package.json +8 -1
  121. package/src/ci-audit/index.ts +1 -2
  122. package/src/ci-product-words.test.ts +23 -0
  123. package/src/ci-product-words.ts +68 -3
  124. package/src/ci-product.ts +36 -6
  125. package/src/cli/commands/init.ts +3 -1
  126. package/src/cli/handlers/build.ts +5 -1
  127. package/src/cli/handlers/init.ts +18 -0
  128. package/src/cli/handlers/lifecycle.ts +13 -0
  129. package/src/cli/handlers/pr-before-merge.test.ts +1 -1
  130. package/src/cli/handlers/pr-deploy-inputs.test.ts +1 -1
  131. package/src/cli/handlers/pr-endpoint.test.ts +1 -1
  132. package/src/cli/handlers/pr-green.test.ts +1 -1
  133. package/src/cli/handlers/pr-plan-comment-targets.test.ts +1 -1
  134. package/src/cli/handlers/pr-plan-flags.test.ts +1 -1
  135. package/src/cli/handlers/pr-plan-targets.test.ts +1 -1
  136. package/src/cli/handlers/pr-record.test.ts +34 -2
  137. package/src/cli/handlers/pr-waves-blocked.test.ts +1 -1
  138. package/src/cli/handlers/pr-waves.test.ts +1 -1
  139. package/src/cli/handlers/pr.test.ts +1 -1
  140. package/src/cli/handlers/pr.ts +86 -31
  141. package/src/cli/handlers/serve.ts +9 -0
  142. package/src/cli/main.ts +6 -2
  143. package/src/cli/mcp/product-tools.test.ts +57 -1
  144. package/src/cli/mcp/product-tools.ts +67 -15
  145. package/src/cli/mcp/read-only.ts +2 -1
  146. package/src/cli/mcp/server.ts +20 -5
  147. package/src/cli/mcp-config.test.ts +52 -2
  148. package/src/cli/mcp-config.ts +6 -3
  149. package/src/cli/parse-args.ts +7 -0
  150. package/src/cli/registry.ts +8 -0
  151. package/src/components/auto-release.test.ts +4 -2
  152. package/src/components/auto-release.ts +9 -5
  153. package/src/components/capability.ts +10 -0
  154. package/src/components/deploy-units.test.ts +18 -1
  155. package/src/components/deploy-units.ts +26 -1
  156. package/src/components/pr-pipeline.ts +99 -5
  157. package/src/components/product-actions.test.ts +76 -0
  158. package/src/components/product-pipeline.ts +21 -2
  159. package/src/components/row-lease.test.ts +61 -1
  160. package/src/components/row-lease.ts +48 -7
  161. package/src/e2e-harness/driver.test.ts +163 -0
  162. package/src/e2e-harness/driver.ts +86 -1
  163. package/src/e2e-harness/forgejo.ts +42 -1
  164. package/src/e2e-harness/index.ts +12 -2
  165. package/src/e2e-harness/ports.ts +33 -0
  166. package/src/e2e-harness/scenario.ts +8 -6
  167. package/src/e2e-harness/schemas/README.md +11 -2
  168. package/src/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
  169. package/src/e2e-harness/schemas/index.ts +5 -1
  170. package/src/e2e-harness/schemas.test.ts +44 -1
  171. package/src/e2e-harness/steps.ts +4 -0
  172. package/src/lexicon.ts +9 -0
  173. package/src/lifecycle/git.test.ts +155 -0
  174. package/src/lifecycle/git.ts +213 -17
  175. package/src/lifecycle/lock-rows.test.ts +6 -1
  176. package/src/lifecycle/lock-rows.ts +58 -7
  177. package/src/lifecycle/resource-lock-wait.test.ts +292 -0
  178. package/src/lifecycle/resource-lock.ts +261 -7
  179. package/src/mcp/types.ts +9 -0
  180. package/src/op/gate.test.ts +7 -5
  181. package/src/op/gate.ts +20 -4
  182. package/src/op/op-waves-after-plan.test.ts +1 -2
  183. package/src/op/op-waves-ledger-lock.test.ts +208 -0
  184. package/src/op/op-waves-release-port.ts +1 -1
  185. package/src/op/op-waves-release.ts +1 -1
  186. package/src/op/op-waves-run.ts +104 -29
  187. package/src/op/op-waves.ts +18 -0
  188. package/src/pr-loop-bundle.test.ts +0 -2
  189. package/src/pr-loop.ts +1 -2
  190. package/src/release-floors.ts +1 -1
  191. package/src/template-request/__fixtures__/request-body.md +41 -0
  192. package/src/template-request/index.ts +8 -0
  193. package/src/template-request/request-body.ts +91 -0
  194. package/src/template-request/template-request.schema.json +100 -0
  195. package/src/template-request/template-request.test.ts +316 -0
  196. package/src/template-request/template-request.ts +235 -0
  197. package/src/template-request/template-spec.ts +176 -0
  198. package/src/template-request/template.schema.json +114 -0
  199. package/src/template-request/validate.ts +28 -0
@@ -65,7 +65,7 @@
65
65
  */
66
66
  import { spawnSync } from "node:child_process";
67
67
  import { CHANT_EXIT } from "../../exit-codes.js";
68
- import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf } from "../../lifecycle/lock-rows.js";
68
+ import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf, queueRowsOfLocks } from "../../lifecycle/lock-rows.js";
69
69
  import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
70
70
  import { dirname, join, relative, resolve, sep } from "node:path";
71
71
  import { loadChantConfig, resolveAutoReleaseDisabled } from "../../config.js";
@@ -538,22 +538,44 @@ async function leaseSetRows(p, set) {
538
538
  */
539
539
  export async function leaseRowsOf(p, set, label = "this apply") {
540
540
  const rows = leaseRowsOfLocks(set.locks);
541
- if (rows.length === 0)
541
+ // The ruling for ci-products (2026-10-28): the target and repo grains wait for their rows first, oldest commit first.
542
+ const queue = queueRowsOfLocks(set.locks);
543
+ if (rows.length === 0 && queue.length === 0)
542
544
  return { release: () => Promise.resolve(true) };
543
- const { leaseLockRows } = await import("../../lifecycle/resource-lock.js");
544
- let leased;
545
- try {
546
- leased = await leaseLockRows(p.gate, rows);
547
- }
548
- catch (err) {
549
- return { failed: `could not hold the rows ${label} changes in ${p.gate}, so nothing of it was applied: ${err instanceof Error ? err.message : String(err)}` };
545
+ const { commitTimeOf, leaseLockRows, lockPollMs, lockWaitSeconds } = await import("../../lifecycle/resource-lock.js");
546
+ const held = [];
547
+ const releaseAll = async () => {
548
+ let ok = true;
549
+ for (const l of held.reverse())
550
+ ok = (await l.release()) && ok;
551
+ return ok;
552
+ };
553
+ for (const [wanted, wait] of [[queue, true], [rows, false]]) {
554
+ if (wanted.length === 0)
555
+ continue;
556
+ let leased;
557
+ try {
558
+ const commitAt = wait ? await commitTimeOf(process.env.GITHUB_SHA || process.env.CI_COMMIT_SHA || "HEAD") : undefined;
559
+ leased = await leaseLockRows(p.gate, wanted, wait
560
+ ? { wait: { deadline: Date.now() + lockWaitSeconds(process.env) * 1000, pollMs: lockPollMs(process.env), log: (line) => console.error(formatInfo(`${label} ${line}`)), ...(commitAt ? { commitAt } : {}) } }
561
+ : {});
562
+ }
563
+ catch (err) {
564
+ await releaseAll();
565
+ return { failed: `could not hold the rows ${label} changes in ${p.gate}, so nothing of it was applied: ${err instanceof Error ? err.message : String(err)}` };
566
+ }
567
+ if (!leased.ok) {
568
+ await releaseAll();
569
+ if (leased.timedOut)
570
+ return { held: `LockWaitTimeoutError: ${leased.message}, so nothing of ${label} was applied.` };
571
+ return { held: `${leased.message}, so nothing of ${label} was applied. Apply again once that run ends; a run that is gone, or whose lease is older than CHANT_LOCK_STALE seconds, is taken over.` };
572
+ }
573
+ for (const h of leased.tookOver)
574
+ console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
575
+ console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate}${leased.waited ? ` after waiting ${leased.waitedSeconds ?? 0}s` : ""} while it applies`));
576
+ held.push(leased.lease);
550
577
  }
551
- if (!leased.ok)
552
- return { held: `${leased.message}, so nothing of ${label} was applied. Apply again once that run ends; a run that is gone, or whose lease is older than CHANT_LOCK_STALE seconds, is taken over.` };
553
- for (const h of leased.tookOver)
554
- console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
555
- console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate} while it applies`));
556
- return leased.lease;
578
+ return { release: releaseAll };
557
579
  }
558
580
  /** `applyPrSet`'s `leaseRound` (#4594): a round after the first leases the rows its own plan locks. */
559
581
  export function leaseRoundRows(p) {
@@ -1269,9 +1291,8 @@ async function prApply(ctx, stage, beforeMerge) {
1269
1291
  : applied.leaseFailed
1270
1292
  ? 1
1271
1293
  : failedRunExitCode(applied.run.results);
1272
- if (green && applied.status === "applied")
1273
- await recordGreenApplied(p, green, set.doc.digest, approval, via);
1274
- const code = await stop(report, exit, applied.run.status === "gated" ? "gated" : undefined);
1294
+ const lost = green && applied.status === "applied" ? await recordGreenApplied(p, green, set.doc.digest, approval, via) : false;
1295
+ const code = await stop(report, lost && exit === 0 ? 1 : exit, applied.run.status === "gated" ? "gated" : undefined);
1275
1296
  if (applied.status === "applied" && !afterFailed)
1276
1297
  console.error(formatSuccess(`applied the plan ${report.digest} approved by ${(approval.approvedBy ?? []).join(", ")}`));
1277
1298
  // #4636: an update before merge that applied every member merges the pull request, never the other way round.
@@ -1307,7 +1328,7 @@ async function mergeArgsProblem(args) {
1307
1328
  */
1308
1329
  async function mergeAfterUpdate(ctx, p, pr) {
1309
1330
  const { mergeAfterApply, mergeTokenEnv } = await import("../../pr-merge.js");
1310
- const { pushLifecycleReport } = await import("../../lifecycle/git.js");
1331
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git.js");
1311
1332
  const kind = p.forge?.kind ?? ctx.args.forge;
1312
1333
  if (!kind)
1313
1334
  return fail("--merge auto needs --forge <kind> to merge on");
@@ -1324,7 +1345,19 @@ async function mergeAfterUpdate(ctx, p, pr) {
1324
1345
  console.error(formatWarning({ message: `the pull request was not merged: ${err instanceof Error ? err.message : String(err)}` }));
1325
1346
  return CHANT_EXIT.waiting;
1326
1347
  }
1327
- const pushed = await pushLifecycleReport();
1348
+ // A refused push fetches, replays the apply's records on the remote's tip and pushes again (#4551).
1349
+ let pushed;
1350
+ let lost = false;
1351
+ try {
1352
+ pushed = await pushLifecycleRebasing();
1353
+ }
1354
+ catch (err) {
1355
+ if (!(err instanceof LifecyclePushLostError))
1356
+ throw err;
1357
+ console.error(formatError({ message: err.message }));
1358
+ pushed = { pushed: false, pushWarning: err.message };
1359
+ lost = true;
1360
+ }
1328
1361
  const merged = await mergeAfterApply({
1329
1362
  forge,
1330
1363
  pr,
@@ -1337,7 +1370,7 @@ async function mergeAfterUpdate(ctx, p, pr) {
1337
1370
  return 0;
1338
1371
  }
1339
1372
  console.error(formatWarning({ message: `the pull request was not merged: ${merged.reason}${merged.posted ? "; the reason is posted on it" : ""}` }));
1340
- return CHANT_EXIT.waiting;
1373
+ return lost ? 1 : CHANT_EXIT.waiting;
1341
1374
  }
1342
1375
  /**
1343
1376
  * Under `ci.locks` (#4293): the refusal when another open pull request holds
@@ -1544,7 +1577,10 @@ async function prRecord(ctx, stage) {
1544
1577
  : {}),
1545
1578
  });
1546
1579
  const { mergeSourceOf, writeMergeRecord, MERGE_RECORD_SCHEMA_ID, MERGE_RECORD_CONTRACT } = await import("../../lifecycle/merge-record.js");
1547
- const { pushLifecycleReport } = await import("../../lifecycle/git.js");
1580
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git.js");
1581
+ // Set when the merge record never reached the remote: the job fails rather than warns, since a record kept only
1582
+ // in this job's checkout is lost with it (#4551).
1583
+ let lost = false;
1548
1584
  // #4292: a member another branch applies has no merge on this one, so no record says it planned nothing here.
1549
1585
  if (!p.routedAway) {
1550
1586
  try {
@@ -1567,17 +1603,23 @@ async function prRecord(ctx, stage) {
1567
1603
  recordedAt: new Date().toISOString(),
1568
1604
  });
1569
1605
  if (written.written) {
1570
- const pushed = await pushLifecycleReport();
1606
+ const pushed = await pushLifecycleRebasing();
1571
1607
  if (pushed.pushWarning)
1572
1608
  console.error(formatWarning({ message: pushed.pushWarning }));
1573
1609
  }
1574
1610
  }
1575
1611
  catch (err) {
1576
- console.error(formatWarning({ message: `could not write the merge record for ${p.head}: ${err instanceof Error ? err.message : String(err)}` }));
1612
+ if (err instanceof LifecyclePushLostError) {
1613
+ console.error(formatError({ message: `the merge record for ${p.head} was written but not pushed: ${err.message}` }));
1614
+ lost = true;
1615
+ }
1616
+ else {
1617
+ console.error(formatWarning({ message: `could not write the merge record for ${p.head}: ${err instanceof Error ? err.message : String(err)}` }));
1618
+ }
1577
1619
  }
1578
1620
  }
1579
1621
  const stop = stopper(ctx, p, events, upload);
1580
- return stop(report, status === "plan-failed" ? 1 : 0);
1622
+ return stop(report, status === "plan-failed" || lost ? 1 : 0);
1581
1623
  }
1582
1624
  /** What a gate's description and messages call the change: the pull request, or the green commit (#4168 step 9). */
1583
1625
  function changeLabel(pr, green) {
@@ -1668,10 +1710,15 @@ function reviewFor(args, p, pr, green) {
1668
1710
  return undefined;
1669
1711
  };
1670
1712
  }
1671
- /** Record the green commit as applied to the environment (#4168 step 9), and push `chant/lifecycle`. A failure warns. */
1713
+ /**
1714
+ * Record the green commit as applied to the environment (#4168 step 9), and
1715
+ * push `chant/lifecycle`, fetching and replaying on a refused push. A record
1716
+ * that never reaches the remote is an error and returns true, so the stage
1717
+ * fails; any other failure warns.
1718
+ */
1672
1719
  async function recordGreenApplied(p, green, digest, approval, via) {
1673
1720
  const { writeGreenApply, GREEN_APPLY_CONTRACT } = await import("../../lifecycle/green-apply.js");
1674
- const { pushLifecycleReport } = await import("../../lifecycle/git.js");
1721
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git.js");
1675
1722
  try {
1676
1723
  await writeGreenApply({
1677
1724
  contract: GREEN_APPLY_CONTRACT,
@@ -1685,13 +1732,18 @@ async function recordGreenApplied(p, green, digest, approval, via) {
1685
1732
  merges: green.merges,
1686
1733
  appliedAt: new Date().toISOString(),
1687
1734
  });
1688
- const pushed = await pushLifecycleReport();
1735
+ const pushed = await pushLifecycleRebasing();
1689
1736
  if (pushed.pushWarning)
1690
1737
  console.error(formatWarning({ message: pushed.pushWarning }));
1691
1738
  }
1692
1739
  catch (err) {
1740
+ if (err instanceof LifecyclePushLostError) {
1741
+ console.error(formatError({ message: `the record of ${green.commit.slice(0, 12)} as applied to ${p.env} was written but not pushed: ${err.message}` }));
1742
+ return true;
1743
+ }
1693
1744
  console.error(formatWarning({ message: `could not record ${green.commit.slice(0, 12)} as applied to ${p.env}: ${err instanceof Error ? err.message : String(err)}` }));
1694
1745
  }
1746
+ return false;
1695
1747
  }
1696
1748
  /** How a stage stops: settle its events, write and publish the report, say how it ended, and return `code`. */
1697
1749
  function stopper(ctx, p, events, upload) {
@@ -1838,12 +1890,14 @@ function emitReviewStop(events, message) {
1838
1890
  }
1839
1891
  /**
1840
1892
  * Store `doc` under its digest with its entries mapped onto the member's
1841
- * graph (`storeGateChangeSet`), and push. A failure is a warning: the gate
1842
- * decides the same either way.
1893
+ * graph (`storeGateChangeSet`), and push, fetching and replaying on a refused
1894
+ * push. A failure to store is a warning: the gate decides the same either
1895
+ * way. A change set that never reaches the remote throws
1896
+ * `LifecyclePushLostError`, which stops the stage.
1843
1897
  */
1844
1898
  async function storeChangeSetForGate(ctx, p, doc) {
1845
1899
  const { storeGateChangeSet, gateGraphReader } = await import("../../lifecycle/gate-change-set.js");
1846
- const { pushLifecycleReport } = await import("../../lifecycle/git.js");
1900
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git.js");
1847
1901
  const graphArgs = [
1848
1902
  ...(ctx.args.param ?? []).flatMap((kv) => ["--param", kv]),
1849
1903
  ...(ctx.args.paramsFile ? ["--params-file", ctx.args.paramsFile] : []),
@@ -1855,9 +1909,11 @@ async function storeChangeSetForGate(ctx, p, doc) {
1855
1909
  // The push's own outcome is said by the gate's pending fact, or by the
1856
1910
  // release records the apply writes, which push the same branch.
1857
1911
  if (stored.written)
1858
- await pushLifecycleReport();
1912
+ await pushLifecycleRebasing();
1859
1913
  }
1860
1914
  catch (err) {
1915
+ if (err instanceof LifecyclePushLostError)
1916
+ throw err;
1861
1917
  console.error(formatWarning({ message: `could not store the change set ${doc.digest}: ${err instanceof Error ? err.message : String(err)}` }));
1862
1918
  }
1863
1919
  }
@@ -2273,9 +2329,8 @@ async function prApplyWaves(ctx, p, at) {
2273
2329
  return stop(report({ status: "failed", ...(message ? { message } : {}) }), lastFailure ? lastFailure.exitCode : 1);
2274
2330
  }
2275
2331
  const done = p.plan.order.every((name) => completed.has(name));
2276
- if (green && done)
2277
- await recordGreenApplied(p, green, approvedSet.doc.digest, approval, via);
2278
- return stop(report({ status: done ? "applied" : "wave-applied" }), 0);
2332
+ const lost = green && done ? await recordGreenApplied(p, green, approvedSet.doc.digest, approval, via) : false;
2333
+ return stop(report({ status: done ? "applied" : "wave-applied" }), lost ? 1 : 0);
2279
2334
  }
2280
2335
  // ── The component plan-wave and apply-wave steps (#4588) ─────────────────────
2281
2336
  /** The outputs earlier waves' components left, from `--wave-outputs`; empty when the file is not there yet. */
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/cli/handlers/serve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,wBAAsB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAMtE;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBtE;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAM1E"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/cli/handlers/serve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,wBAAsB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAMtE;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAkCtE;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAM1E"}
@@ -7,6 +7,14 @@ export async function runServeLsp(ctx) {
7
7
  return 0; // unreachable
8
8
  }
9
9
  export async function runServeMcp(ctx) {
10
+ // chant#4655 — --propose is a tier of the read-only server, never of the ordinary one.
11
+ if (ctx.args.propose === true && ctx.args.readOnly !== true) {
12
+ console.error(formatError({
13
+ message: "chant serve mcp --propose needs --read-only",
14
+ hint: "Usage: chant serve mcp --read-only --propose (serves the read tools and a product's tools that open pull requests)",
15
+ }));
16
+ return 1;
17
+ }
10
18
  const { McpServer } = await import("../mcp/server.js");
11
19
  // #2700 — main() hands over no plugins only at a workspace root with no
12
20
  // lexicon of its own (anywhere else it refuses first). There the lexicons
@@ -26,6 +34,7 @@ export async function runServeMcp(ctx) {
26
34
  instructions,
27
35
  workspace: { cwd: process.cwd() },
28
36
  ...(ctx.args.readOnly === true ? { readOnly: true } : {}),
37
+ ...(ctx.args.propose === true ? { propose: true } : {}),
29
38
  ...(product ? { product } : {}),
30
39
  });
31
40
  await server.start();
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AAEA,OAAO,EAAoB,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAItG,OAAO,EAAkB,KAAK,UAAU,EAAmB,MAAM,YAAY,CAAC;AAa9E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;AAumDzC;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,cAAc,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,qBAAqB,EAAE,cAAc,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,2BAA2B,EAAE,eAAe,CAAA;CAAO,GAC7K,OAAO,CAAC,MAAM,CAAC,CAuCjB;AAID;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,UAAU,EA8PvC,CAAC"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AAEA,OAAO,EAAoB,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAItG,OAAO,EAAkB,KAAK,UAAU,EAAmB,MAAM,YAAY,CAAC;AAa9E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;AA2mDzC;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,cAAc,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,qBAAqB,EAAE,cAAc,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,2BAA2B,EAAE,eAAe,CAAA;CAAO,GAC7K,OAAO,CAAC,MAAM,CAAC,CAuCjB;AAID;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,UAAU,EA8PvC,CAAC"}
package/dist/cli/main.js CHANGED
@@ -1349,7 +1349,9 @@ Local:
1349
1349
  Servers:
1350
1350
  serve lsp Start the LSP server (stdio)
1351
1351
  serve mcp Start the MCP server (stdio); --read-only serves only
1352
- the tools that read (ledger, graph, runs) and run nothing
1352
+ the tools that read (ledger, graph, runs) and run nothing;
1353
+ --read-only --propose also serves a product's tools that
1354
+ open pull requests and comments, and nothing that approves
1353
1355
 
1354
1356
  Project:
1355
1357
  update (alias: sync) Sync lexicon types into .chant/types/ (does not install
@@ -1376,7 +1378,9 @@ Options:
1376
1378
  records its lineage in .chant/workspace.lock.json
1377
1379
  --skill <name> Init: install only this skill from the lexicon
1378
1380
  --skip-mcp Init: scaffold without writing the project's .mcp.json
1379
- --mcp-read-only Init: register \`chant serve mcp --read-only\` in .mcp.json
1381
+ --mcp-read-only Init: register \`chant serve mcp --read-only\` in .mcp.json;
1382
+ with --propose, \`chant serve mcp --read-only --propose\`.
1383
+ Init --dry-run prints that .mcp.json and writes nothing
1380
1384
  --fix Auto-fix fixable issues (lint command)
1381
1385
  --force Force overwrite existing files (import command)
1382
1386
  -w, --watch Watch for changes and rebuild/re-lint (build, lint)
@@ -20,6 +20,16 @@
20
20
  * the server's own credentials, never from a tool's arguments.
21
21
  *
22
22
  * Tools are registered as `<product>:<name>`, as a lexicon's are.
23
+ *
24
+ * chant#4655 adds a tier between read-only and ordinary for a product tool
25
+ * that opens a pull request (`request_from_template`): `chant serve mcp
26
+ * --read-only --propose`, or `propose: true` on the hook. It serves what the
27
+ * read-only server serves, plus the product tools that declare `forgeWrite:
28
+ * true`, and never chant's op, approve or snapshot tools. The read-only
29
+ * server without `--propose` refuses to start with a `forgeWrite` tool. On
30
+ * the tier a `forgeWrite` tool's name is exempt from the write-word check for
31
+ * `request` and `propose` only: `approve_request` still refuses the start.
32
+ * A product feature-detects the tier on {@link PRODUCT_MCP_PROPOSE_FLOOR}.
23
33
  */
24
34
  import type { McpToolContribution } from "../../mcp/types.js";
25
35
  import { type ReportReader } from "./report-tools.js";
@@ -29,6 +39,8 @@ export interface ProductMcpContext {
29
39
  cwd: string;
30
40
  /** Whether the server is read-only. */
31
41
  readOnly: boolean;
42
+ /** Whether the read-only server also serves the product's `forgeWrite` tools (`--propose`, chant#4655). */
43
+ propose: boolean;
32
44
  /**
33
45
  * The report store, read-only: the hook's `reportUrl`, else the declared
34
46
  * `ci.reportUrl`. Resolves undefined when neither names one.
@@ -45,9 +57,24 @@ export interface ProductMcpHook {
45
57
  reportUrl?: string;
46
58
  /** `false` starts an ordinary server through the hook. Default: read-only. */
47
59
  readOnly?: boolean;
60
+ /**
61
+ * `true` serves the product's `forgeWrite` tools on the read-only server,
62
+ * as `--propose` does (chant#4655). It needs the server read-only: with
63
+ * `readOnly: false` the server refuses to start.
64
+ */
65
+ propose?: boolean;
48
66
  /** Text added to the server's `initialize` instructions. */
49
67
  instructions?: string;
50
68
  }
69
+ /**
70
+ * The first chant whose `chant serve mcp` has the `--propose` tier and serves
71
+ * `forgeWrite` product tools on it (chant#4655). A product checks this before
72
+ * it passes `--propose` or `propose: true`, and refuses naming this release
73
+ * when its chant is older.
74
+ */
75
+ export declare const PRODUCT_MCP_PROPOSE_FLOOR = "0.124.58";
76
+ /** The words a `forgeWrite` tool's name may hold on the `--propose` tier, which the write-word check passes over (chant#4655). */
77
+ export declare const PRODUCT_TOOL_PROPOSE_WORDS: readonly ["request", "propose"];
51
78
  /** Words that say a tool would change something; a read-only server will not serve a tool named with one. terragucci's list. */
52
79
  export declare const PRODUCT_TOOL_WRITE_WORDS: readonly ["approve", "apply", "override", "revoke", "unlock", "lock", "merge", "resume", "migrate", "write", "put", "delete", "push", "commit", "publish", "reconcile", "rollout", "init", "generate", "respond", "relay", "notify", "update", "create", "exec"];
53
80
  /** The words that refuse a name wherever they stand in it, not only first. */
@@ -58,19 +85,25 @@ export declare const PRODUCT_TOOL_STRONG_WORDS: readonly ["approve", "override",
58
85
  * strong one anywhere: `last_apply` reads, `apply_wave` and `wave_approve`
59
86
  * do not.
60
87
  */
61
- export declare function productToolWriteWord(name: string): string | undefined;
62
- /** A read-only server refused a product tool named as a write. */
88
+ export declare function productToolWriteWord(name: string, exempt?: readonly string[]): string | undefined;
89
+ /**
90
+ * A read-only server refused a product tool: one named as a write, or a
91
+ * `forgeWrite` tool on a server started without `--propose` (chant#4655).
92
+ */
63
93
  export declare class ProductToolRefusedError extends Error {
64
- constructor(product: string, name: string, word: string);
94
+ constructor(product: string, name: string, word: string, tier?: "read-only" | "propose" | "forge-write");
65
95
  }
66
96
  /**
67
- * The product tools a server serves: on a read-only server only those that
68
- * declare `readOnly: true`, and none named as a write (a throw, so the server
69
- * does not start). On an ordinary server every tool.
97
+ * The product tools a server serves. On an ordinary server every tool. On a
98
+ * read-only server those that declare `readOnly: true`, none named as a
99
+ * write, and no `forgeWrite` tool (each a throw, so the server does not
100
+ * start). On the `--propose` tier the `readOnly: true` tools under the same
101
+ * check, plus the `forgeWrite` tools, whose names may hold `request` or
102
+ * `propose` but no other write word (chant#4655).
70
103
  */
71
104
  export declare function productToolsServed(hook: ProductMcpHook, ctx: ProductMcpContext): McpToolContribution[];
72
105
  /** The context a hook's tools get on a server at `cwd`. The store is opened on first read. */
73
- export declare function productMcpContext(hook: ProductMcpHook, cwd: string, readOnly: boolean): ProductMcpContext;
106
+ export declare function productMcpContext(hook: ProductMcpHook, cwd: string, readOnly: boolean, propose?: boolean): ProductMcpContext;
74
107
  /** The hook the running command serves, set by a product's bin. */
75
108
  export declare function activeProductMcpHook(): ProductMcpHook | undefined;
76
109
  /** Run `fn` with `hook` active, and put the earlier one back after it settles. */
@@ -1 +1 @@
1
- {"version":3,"file":"product-tools.d.ts","sourceRoot":"","sources":["../../../src/cli/mcp/product-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAA8B,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE/E,yCAAyC;AACzC,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,uCAAuC;IACvC,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;CAC9C;AAED,+CAA+C;AAC/C,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,KAAK,CAAC,GAAG,EAAE,iBAAiB,GAAG,mBAAmB,EAAE,CAAC;IACrD,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AC,CAAC,EAAE,IAAI,EAAE,cAAc,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAS9G"}
@@ -20,9 +20,28 @@
20
20
  * the server's own credentials, never from a tool's arguments.
21
21
  *
22
22
  * Tools are registered as `<product>:<name>`, as a lexicon's are.
23
+ *
24
+ * chant#4655 adds a tier between read-only and ordinary for a product tool
25
+ * that opens a pull request (`request_from_template`): `chant serve mcp
26
+ * --read-only --propose`, or `propose: true` on the hook. It serves what the
27
+ * read-only server serves, plus the product tools that declare `forgeWrite:
28
+ * true`, and never chant's op, approve or snapshot tools. The read-only
29
+ * server without `--propose` refuses to start with a `forgeWrite` tool. On
30
+ * the tier a `forgeWrite` tool's name is exempt from the write-word check for
31
+ * `request` and `propose` only: `approve_request` still refuses the start.
32
+ * A product feature-detects the tier on {@link PRODUCT_MCP_PROPOSE_FLOOR}.
23
33
  */
24
- import { servesContributedTool } from "./read-only.js";
34
+ import { NEXT_RELEASE } from "../../release-floors.js";
25
35
  import { reportReader, reportUrlFor } from "./report-tools.js";
36
+ /**
37
+ * The first chant whose `chant serve mcp` has the `--propose` tier and serves
38
+ * `forgeWrite` product tools on it (chant#4655). A product checks this before
39
+ * it passes `--propose` or `propose: true`, and refuses naming this release
40
+ * when its chant is older.
41
+ */
42
+ export const PRODUCT_MCP_PROPOSE_FLOOR = NEXT_RELEASE;
43
+ /** The words a `forgeWrite` tool's name may hold on the `--propose` tier, which the write-word check passes over (chant#4655). */
44
+ export const PRODUCT_TOOL_PROPOSE_WORDS = ["request", "propose"];
26
45
  /** Words that say a tool would change something; a read-only server will not serve a tool named with one. terragucci's list. */
27
46
  export const PRODUCT_TOOL_WRITE_WORDS = ["approve", "apply", "override", "revoke", "unlock", "lock", "merge", "resume", "migrate", "write", "put", "delete", "push", "commit", "publish", "reconcile", "rollout", "init", "generate", "respond", "relay", "notify", "update", "create", "exec"];
28
47
  /** The words that refuse a name wherever they stand in it, not only first. */
@@ -33,43 +52,68 @@ export const PRODUCT_TOOL_STRONG_WORDS = ["approve", "override", "revoke", "unlo
33
52
  * strong one anywhere: `last_apply` reads, `apply_wave` and `wave_approve`
34
53
  * do not.
35
54
  */
36
- export function productToolWriteWord(name) {
55
+ export function productToolWriteWord(name, exempt = []) {
37
56
  const parts = name.toLowerCase().split(/[^a-z]+/).filter(Boolean);
38
57
  const first = parts[0] ?? "";
39
- return PRODUCT_TOOL_WRITE_WORDS.find((w) => first.startsWith(w)) ?? PRODUCT_TOOL_STRONG_WORDS.find((w) => parts.some((p) => p.startsWith(w)));
58
+ const words = (list) => list.filter((w) => !exempt.includes(w));
59
+ return words(PRODUCT_TOOL_WRITE_WORDS).find((w) => first.startsWith(w)) ?? words(PRODUCT_TOOL_STRONG_WORDS).find((w) => parts.some((p) => p.startsWith(w)));
40
60
  }
41
- /** A read-only server refused a product tool named as a write. */
61
+ /**
62
+ * A read-only server refused a product tool: one named as a write, or a
63
+ * `forgeWrite` tool on a server started without `--propose` (chant#4655).
64
+ */
42
65
  export class ProductToolRefusedError extends Error {
43
- constructor(product, name, word) {
44
- super(`chant serve mcp is read-only for ${product}, and the tool ${name} would ${word}; the server does not start with it`);
66
+ constructor(product, name, word, tier = "read-only") {
67
+ super(tier === "forge-write"
68
+ ? `chant serve mcp is read-only for ${product}, and the tool ${name} opens pull requests (forgeWrite); the server does not start with it. Start it with --read-only --propose to serve it`
69
+ : tier === "propose"
70
+ ? `chant serve mcp --propose serves ${product}'s tools that read or open pull requests and comments, and the tool ${name} would ${word}; the server does not start with it`
71
+ : `chant serve mcp is read-only for ${product}, and the tool ${name} would ${word}; the server does not start with it`);
45
72
  this.name = "ProductToolRefusedError";
46
73
  }
47
74
  }
48
75
  const PRODUCT = /^[a-z0-9][a-z0-9-]*$/;
49
76
  /**
50
- * The product tools a server serves: on a read-only server only those that
51
- * declare `readOnly: true`, and none named as a write (a throw, so the server
52
- * does not start). On an ordinary server every tool.
77
+ * The product tools a server serves. On an ordinary server every tool. On a
78
+ * read-only server those that declare `readOnly: true`, none named as a
79
+ * write, and no `forgeWrite` tool (each a throw, so the server does not
80
+ * start). On the `--propose` tier the `readOnly: true` tools under the same
81
+ * check, plus the `forgeWrite` tools, whose names may hold `request` or
82
+ * `propose` but no other write word (chant#4655).
53
83
  */
54
84
  export function productToolsServed(hook, ctx) {
55
85
  if (!PRODUCT.test(hook.product))
56
86
  throw new Error(`the product tool hook's product ${JSON.stringify(hook.product)} is not a product name ([a-z0-9-])`);
57
- const served = hook.tools(ctx).filter((t) => servesContributedTool(t, ctx.readOnly));
58
- if (ctx.readOnly) {
59
- for (const t of served) {
60
- const word = productToolWriteWord(t.name.startsWith(`${hook.product}:`) ? t.name.slice(hook.product.length + 1) : t.name);
87
+ const tools = hook.tools(ctx);
88
+ if (!ctx.readOnly)
89
+ return tools;
90
+ const served = [];
91
+ for (const t of tools) {
92
+ const short = t.name.startsWith(`${hook.product}:`) ? t.name.slice(hook.product.length + 1) : t.name;
93
+ if (t.forgeWrite === true) {
94
+ if (!ctx.propose)
95
+ throw new ProductToolRefusedError(hook.product, t.name, "open a pull request", "forge-write");
96
+ const word = productToolWriteWord(short, PRODUCT_TOOL_PROPOSE_WORDS);
97
+ if (word)
98
+ throw new ProductToolRefusedError(hook.product, t.name, word, "propose");
99
+ served.push(t);
100
+ }
101
+ else if (t.readOnly === true) {
102
+ const word = productToolWriteWord(short);
61
103
  if (word)
62
- throw new ProductToolRefusedError(hook.product, t.name, word);
104
+ throw new ProductToolRefusedError(hook.product, t.name, word, ctx.propose ? "propose" : "read-only");
105
+ served.push(t);
63
106
  }
64
107
  }
65
108
  return served;
66
109
  }
67
110
  /** The context a hook's tools get on a server at `cwd`. The store is opened on first read. */
68
- export function productMcpContext(hook, cwd, readOnly) {
111
+ export function productMcpContext(hook, cwd, readOnly, propose = false) {
69
112
  let opened;
70
113
  return {
71
114
  cwd,
72
115
  readOnly,
116
+ propose,
73
117
  reports: () => (opened ?? (opened = reportUrlFor(hook.reportUrl, cwd).then((url) => (url ? reportReader(url) : undefined)))),
74
118
  };
75
119
  }
@@ -10,7 +10,8 @@
10
10
  *
11
11
  * Contributed tools (a lexicon's `mcpTools()`, and a product's tools through
12
12
  * the hook chant#4555 adds, ./product-tools.ts) are served only when they
13
- * declare `readOnly: true`.
13
+ * declare `readOnly: true`. The `--propose` tier (chant#4655) keeps these
14
+ * lists and adds only a product's `forgeWrite` tools (./product-tools.ts).
14
15
  */
15
16
  /**
16
17
  * Core tools that change nothing, served in both modes.
@@ -1 +1 @@
1
- {"version":3,"file":"read-only.d.ts","sourceRoot":"","sources":["../../../src/cli/mcp/read-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAcnD,CAAC;AAEH,uFAAuF;AACvF,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAOlD,CAAC;AAEH,0JAA0J;AAC1J,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAE9F;AAED,kGAAkG;AAClG,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,IAAI,EAAE,MAAM,EAMvB;CACF"}
1
+ {"version":3,"file":"read-only.d.ts","sourceRoot":"","sources":["../../../src/cli/mcp/read-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAcnD,CAAC;AAEH,uFAAuF;AACvF,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAOlD,CAAC;AAEH,0JAA0J;AAC1J,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAE9F;AAED,kGAAkG;AAClG,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,IAAI,EAAE,MAAM,EAMvB;CACF"}
@@ -10,7 +10,8 @@
10
10
  *
11
11
  * Contributed tools (a lexicon's `mcpTools()`, and a product's tools through
12
12
  * the hook chant#4555 adds, ./product-tools.ts) are served only when they
13
- * declare `readOnly: true`.
13
+ * declare `readOnly: true`. The `--propose` tier (chant#4655) keeps these
14
+ * lists and adds only a product's `forgeWrite` tools (./product-tools.ts).
14
15
  */
15
16
  import { workspaceReadTools, workspaceWriteTools } from "./workspace-tools.js";
16
17
  import { ledgerReadTools } from "./ledger-tools.js";
@@ -53,6 +53,8 @@ export declare function namespacedToolName(lexicon: string, name: string): strin
53
53
  export declare function namespacedResourceUri(lexicon: string, uri: string): string;
54
54
  /** What a read-only server says about itself in `initialize`'s `instructions` (chant#4543). */
55
55
  export declare const READ_ONLY_INSTRUCTIONS = "This chant server is read-only: it serves the ledger, the workspace graph, runs, gates and snapshots, and no tool here runs an Op, resolves a gate or writes anything.";
56
+ /** The `initialize` instructions of the `--propose` tier (chant#4655), in place of {@link READ_ONLY_INSTRUCTIONS}. */
57
+ export declare const PROPOSE_INSTRUCTIONS = "This chant server is read-only apart from its forge tools: it serves the ledger, the workspace graph, runs, gates and snapshots, and no tool here runs an Op, resolves a gate or applies anything. The product's forge tools open pull requests and comments only. Approving, merging and applying a change belong to a person.";
56
58
  /**
57
59
  * MCP Server implementation
58
60
  */
@@ -66,6 +68,8 @@ export declare class McpServer {
66
68
  private clientInfo;
67
69
  /** `chant serve mcp --read-only` (chant#4543): only tools that change nothing are registered. */
68
70
  readonly readOnly: boolean;
71
+ /** `chant serve mcp --read-only --propose` (chant#4655): the read-only server plus the product's `forgeWrite` tools. */
72
+ readonly propose: boolean;
69
73
  /**
70
74
  * `options.instructions` is sent as the `initialize` result's
71
75
  * `instructions`, the text a client may give its model about this server.
@@ -87,11 +91,17 @@ export declare class McpServer {
87
91
  * under the same read-only rule as a plugin's, and a read-only server
88
92
  * refuses to start with one named as a write. With a hook and no
89
93
  * `readOnly`, the server is read-only unless the hook says otherwise.
94
+ *
95
+ * `options.propose` (`--propose`, chant#4655), or `propose: true` on the
96
+ * hook, is a tier of the read-only server: the same core and plugin tools,
97
+ * plus the product tools that declare `forgeWrite: true`. It needs
98
+ * `readOnly`; an ordinary server with it refuses to start.
90
99
  */
91
100
  constructor(plugins?: LexiconPlugin[], options?: {
92
101
  instructions?: string;
93
102
  workspace?: WorkspaceToolsOptions;
94
103
  readOnly?: boolean;
104
+ propose?: boolean;
95
105
  product?: ProductMcpHook;
96
106
  });
97
107
  /**
@@ -155,5 +165,6 @@ export declare class McpServer {
155
165
  */
156
166
  export declare function startMcpServer(options?: {
157
167
  readOnly?: boolean;
168
+ propose?: boolean;
158
169
  }): Promise<void>;
159
170
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/mcp/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAmE,MAAM,SAAS,CAAC;AAEvI,OAAO,EAAwB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAOrF,OAAO,EAA+D,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAInH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,2BAA2B,YAAI,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAU,CAAC;AAG3H;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAK9E;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;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