@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
@@ -66,7 +66,7 @@
66
66
 
67
67
  import { spawnSync } from "node:child_process";
68
68
  import { CHANT_EXIT } from "../../exit-codes";
69
- import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf, type LockGrain } from "../../lifecycle/lock-rows";
69
+ import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf, queueRowsOfLocks, type LockGrain } from "../../lifecycle/lock-rows";
70
70
  import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
71
71
  import { dirname, join, relative, resolve, sep } from "node:path";
72
72
  import { loadChantConfig, resolveAutoReleaseDisabled, type ChantConfig } from "../../config";
@@ -617,18 +617,42 @@ async function leaseSetRows(p: Prepared, set: Pick<PrPlanSet, "locks">): Promise
617
617
  */
618
618
  export async function leaseRowsOf(p: Pick<Prepared, "gate">, set: Pick<PrPlanSet, "locks">, label = "this apply"): Promise<{ release(): Promise<boolean> } | { held: string } | { failed: string }> {
619
619
  const rows = leaseRowsOfLocks(set.locks);
620
- if (rows.length === 0) return { release: () => Promise.resolve(true) };
621
- const { leaseLockRows } = await import("../../lifecycle/resource-lock");
622
- let leased;
623
- try {
624
- leased = await leaseLockRows(p.gate, rows);
625
- } catch (err) {
626
- 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)}` };
620
+ // The ruling for ci-products (2026-10-28): the target and repo grains wait for their rows first, oldest commit first.
621
+ const queue = queueRowsOfLocks(set.locks);
622
+ if (rows.length === 0 && queue.length === 0) return { release: () => Promise.resolve(true) };
623
+ const { commitTimeOf, leaseLockRows, lockPollMs, lockWaitSeconds } = await import("../../lifecycle/resource-lock");
624
+ const held: Array<{ release(): Promise<boolean> }> = [];
625
+ const releaseAll = async () => {
626
+ let ok = true;
627
+ for (const l of held.reverse()) ok = (await l.release()) && ok;
628
+ return ok;
629
+ };
630
+ for (const [wanted, wait] of [[queue, true], [rows, false]] as const) {
631
+ if (wanted.length === 0) continue;
632
+ let leased;
633
+ try {
634
+ const commitAt = wait ? await commitTimeOf(process.env.GITHUB_SHA || process.env.CI_COMMIT_SHA || "HEAD") : undefined;
635
+ leased = await leaseLockRows(
636
+ p.gate,
637
+ wanted,
638
+ wait
639
+ ? { wait: { deadline: Date.now() + lockWaitSeconds(process.env) * 1000, pollMs: lockPollMs(process.env), log: (line) => console.error(formatInfo(`${label} ${line}`)), ...(commitAt ? { commitAt } : {}) } }
640
+ : {},
641
+ );
642
+ } catch (err) {
643
+ await releaseAll();
644
+ 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)}` };
645
+ }
646
+ if (!leased.ok) {
647
+ await releaseAll();
648
+ if (leased.timedOut) return { held: `LockWaitTimeoutError: ${leased.message}, so nothing of ${label} was applied.` };
649
+ 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.` };
650
+ }
651
+ for (const h of leased.tookOver) console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
652
+ 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`));
653
+ held.push(leased.lease);
627
654
  }
628
- if (!leased.ok) 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.` };
629
- for (const h of leased.tookOver) console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
630
- console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate} while it applies`));
631
- return leased.lease;
655
+ return { release: releaseAll };
632
656
  }
633
657
 
634
658
  /** `applyPrSet`'s `leaseRound` (#4594): a round after the first leases the rows its own plan locks. */
@@ -1333,8 +1357,8 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1333
1357
  : applied.leaseFailed
1334
1358
  ? 1
1335
1359
  : failedRunExitCode(applied.run.results);
1336
- if (green && applied.status === "applied") await recordGreenApplied(p, green, set.doc.digest, approval, via);
1337
- const code = await stop(report, exit, applied.run.status === "gated" ? "gated" : undefined);
1360
+ const lost = green && applied.status === "applied" ? await recordGreenApplied(p, green, set.doc.digest, approval, via) : false;
1361
+ const code = await stop(report, lost && exit === 0 ? 1 : exit, applied.run.status === "gated" ? "gated" : undefined);
1338
1362
  if (applied.status === "applied" && !afterFailed) console.error(formatSuccess(`applied the plan ${report.digest} approved by ${(approval.approvedBy ?? []).join(", ")}`));
1339
1363
  // #4636: an update before merge that applied every member merges the pull request, never the other way round.
1340
1364
  if (code === 0 && beforeMerge && pr !== null && args.merge === "auto" && applied.status === "applied" && !afterFailed) return mergeAfterUpdate(ctx, p, pr);
@@ -1364,7 +1388,7 @@ async function mergeArgsProblem(args: CommandContext["args"]): Promise<string |
1364
1388
  */
1365
1389
  async function mergeAfterUpdate(ctx: CommandContext, p: Prepared, pr: number): Promise<number> {
1366
1390
  const { mergeAfterApply, mergeTokenEnv } = await import("../../pr-merge");
1367
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1391
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1368
1392
  const kind = p.forge?.kind ?? (ctx.args.forge as ForgeKind | undefined);
1369
1393
  if (!kind) return fail("--merge auto needs --forge <kind> to merge on");
1370
1394
  const env = mergeTokenEnv(ctx.args.mergeTokenEnv!);
@@ -1379,7 +1403,17 @@ async function mergeAfterUpdate(ctx: CommandContext, p: Prepared, pr: number): P
1379
1403
  console.error(formatWarning({ message: `the pull request was not merged: ${err instanceof Error ? err.message : String(err)}` }));
1380
1404
  return CHANT_EXIT.waiting;
1381
1405
  }
1382
- const pushed = await pushLifecycleReport();
1406
+ // A refused push fetches, replays the apply's records on the remote's tip and pushes again (#4551).
1407
+ let pushed: { pushed: boolean; pushWarning?: string };
1408
+ let lost = false;
1409
+ try {
1410
+ pushed = await pushLifecycleRebasing();
1411
+ } catch (err) {
1412
+ if (!(err instanceof LifecyclePushLostError)) throw err;
1413
+ console.error(formatError({ message: err.message }));
1414
+ pushed = { pushed: false, pushWarning: err.message };
1415
+ lost = true;
1416
+ }
1383
1417
  const merged = await mergeAfterApply({
1384
1418
  forge,
1385
1419
  pr,
@@ -1392,7 +1426,7 @@ async function mergeAfterUpdate(ctx: CommandContext, p: Prepared, pr: number): P
1392
1426
  return 0;
1393
1427
  }
1394
1428
  console.error(formatWarning({ message: `the pull request was not merged: ${merged.reason}${merged.posted ? "; the reason is posted on it" : ""}` }));
1395
- return CHANT_EXIT.waiting;
1429
+ return lost ? 1 : CHANT_EXIT.waiting;
1396
1430
  }
1397
1431
 
1398
1432
  /**
@@ -1601,7 +1635,10 @@ async function prRecord(ctx: CommandContext, stage: StageEvents): Promise<number
1601
1635
  });
1602
1636
 
1603
1637
  const { mergeSourceOf, writeMergeRecord, MERGE_RECORD_SCHEMA_ID, MERGE_RECORD_CONTRACT } = await import("../../lifecycle/merge-record");
1604
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1638
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1639
+ // Set when the merge record never reached the remote: the job fails rather than warns, since a record kept only
1640
+ // in this job's checkout is lost with it (#4551).
1641
+ let lost = false;
1605
1642
  // #4292: a member another branch applies has no merge on this one, so no record says it planned nothing here.
1606
1643
  if (!p.routedAway) {
1607
1644
  try {
@@ -1624,16 +1661,21 @@ async function prRecord(ctx: CommandContext, stage: StageEvents): Promise<number
1624
1661
  recordedAt: new Date().toISOString(),
1625
1662
  });
1626
1663
  if (written.written) {
1627
- const pushed = await pushLifecycleReport();
1664
+ const pushed = await pushLifecycleRebasing();
1628
1665
  if (pushed.pushWarning) console.error(formatWarning({ message: pushed.pushWarning }));
1629
1666
  }
1630
1667
  } catch (err) {
1631
- console.error(formatWarning({ message: `could not write the merge record for ${p.head}: ${err instanceof Error ? err.message : String(err)}` }));
1668
+ if (err instanceof LifecyclePushLostError) {
1669
+ console.error(formatError({ message: `the merge record for ${p.head} was written but not pushed: ${err.message}` }));
1670
+ lost = true;
1671
+ } else {
1672
+ console.error(formatWarning({ message: `could not write the merge record for ${p.head}: ${err instanceof Error ? err.message : String(err)}` }));
1673
+ }
1632
1674
  }
1633
1675
  }
1634
1676
 
1635
1677
  const stop = stopper(ctx, p, events, upload);
1636
- return stop(report, status === "plan-failed" ? 1 : 0);
1678
+ return stop(report, status === "plan-failed" || lost ? 1 : 0);
1637
1679
  }
1638
1680
 
1639
1681
  /** What a gate's description and messages call the change: the pull request, or the green commit (#4168 step 9). */
@@ -1730,10 +1772,15 @@ function reviewFor(args: CommandContext["args"], p: Prepared, pr: number | null,
1730
1772
  };
1731
1773
  }
1732
1774
 
1733
- /** Record the green commit as applied to the environment (#4168 step 9), and push `chant/lifecycle`. A failure warns. */
1734
- async function recordGreenApplied(p: Prepared, green: GreenTarget, digest: string, approval: PrApproval, via: "merges" | "gate"): Promise<void> {
1775
+ /**
1776
+ * Record the green commit as applied to the environment (#4168 step 9), and
1777
+ * push `chant/lifecycle`, fetching and replaying on a refused push. A record
1778
+ * that never reaches the remote is an error and returns true, so the stage
1779
+ * fails; any other failure warns.
1780
+ */
1781
+ async function recordGreenApplied(p: Prepared, green: GreenTarget, digest: string, approval: PrApproval, via: "merges" | "gate"): Promise<boolean> {
1735
1782
  const { writeGreenApply, GREEN_APPLY_CONTRACT } = await import("../../lifecycle/green-apply");
1736
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1783
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1737
1784
  try {
1738
1785
  await writeGreenApply({
1739
1786
  contract: GREEN_APPLY_CONTRACT,
@@ -1747,11 +1794,16 @@ async function recordGreenApplied(p: Prepared, green: GreenTarget, digest: strin
1747
1794
  merges: green.merges,
1748
1795
  appliedAt: new Date().toISOString(),
1749
1796
  });
1750
- const pushed = await pushLifecycleReport();
1797
+ const pushed = await pushLifecycleRebasing();
1751
1798
  if (pushed.pushWarning) console.error(formatWarning({ message: pushed.pushWarning }));
1752
1799
  } catch (err) {
1800
+ if (err instanceof LifecyclePushLostError) {
1801
+ console.error(formatError({ message: `the record of ${green.commit.slice(0, 12)} as applied to ${p.env} was written but not pushed: ${err.message}` }));
1802
+ return true;
1803
+ }
1753
1804
  console.error(formatWarning({ message: `could not record ${green.commit.slice(0, 12)} as applied to ${p.env}: ${err instanceof Error ? err.message : String(err)}` }));
1754
1805
  }
1806
+ return false;
1755
1807
  }
1756
1808
 
1757
1809
  /** How a stage stops: settle its events, write and publish the report, say how it ended, and return `code`. */
@@ -1903,12 +1955,14 @@ function emitReviewStop(events: RunEventStream | undefined, message: string): vo
1903
1955
 
1904
1956
  /**
1905
1957
  * Store `doc` under its digest with its entries mapped onto the member's
1906
- * graph (`storeGateChangeSet`), and push. A failure is a warning: the gate
1907
- * decides the same either way.
1958
+ * graph (`storeGateChangeSet`), and push, fetching and replaying on a refused
1959
+ * push. A failure to store is a warning: the gate decides the same either
1960
+ * way. A change set that never reaches the remote throws
1961
+ * `LifecyclePushLostError`, which stops the stage.
1908
1962
  */
1909
1963
  async function storeChangeSetForGate(ctx: CommandContext, p: Prepared, doc: PrPlanSet["doc"]): Promise<void> {
1910
1964
  const { storeGateChangeSet, gateGraphReader } = await import("../../lifecycle/gate-change-set");
1911
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1965
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1912
1966
  const graphArgs = [
1913
1967
  ...(ctx.args.param ?? []).flatMap((kv) => ["--param", kv]),
1914
1968
  ...(ctx.args.paramsFile ? ["--params-file", ctx.args.paramsFile] : []),
@@ -1918,8 +1972,9 @@ async function storeChangeSetForGate(ctx: CommandContext, p: Prepared, doc: PrPl
1918
1972
  if (stored.warning) console.error(formatWarning({ message: stored.warning }));
1919
1973
  // The push's own outcome is said by the gate's pending fact, or by the
1920
1974
  // release records the apply writes, which push the same branch.
1921
- if (stored.written) await pushLifecycleReport();
1975
+ if (stored.written) await pushLifecycleRebasing();
1922
1976
  } catch (err) {
1977
+ if (err instanceof LifecyclePushLostError) throw err;
1923
1978
  console.error(formatWarning({ message: `could not store the change set ${doc.digest}: ${err instanceof Error ? err.message : String(err)}` }));
1924
1979
  }
1925
1980
  }
@@ -2339,8 +2394,8 @@ async function prApplyWaves(
2339
2394
  }
2340
2395
 
2341
2396
  const done = p.plan.order.every((name) => completed.has(name));
2342
- if (green && done) await recordGreenApplied(p, green, approvedSet.doc.digest, approval, via);
2343
- return stop(report({ status: done ? "applied" : "wave-applied" }), 0);
2397
+ const lost = green && done ? await recordGreenApplied(p, green, approvedSet.doc.digest, approval, via) : false;
2398
+ return stop(report({ status: done ? "applied" : "wave-applied" }), lost ? 1 : 0);
2344
2399
  }
2345
2400
 
2346
2401
  // ── The component plan-wave and apply-wave steps (#4588) ─────────────────────
@@ -10,6 +10,14 @@ export async function runServeLsp(ctx: CommandContext): Promise<number> {
10
10
  }
11
11
 
12
12
  export async function runServeMcp(ctx: CommandContext): Promise<number> {
13
+ // chant#4655 — --propose is a tier of the read-only server, never of the ordinary one.
14
+ if (ctx.args.propose === true && ctx.args.readOnly !== true) {
15
+ console.error(formatError({
16
+ message: "chant serve mcp --propose needs --read-only",
17
+ hint: "Usage: chant serve mcp --read-only --propose (serves the read tools and a product's tools that open pull requests)",
18
+ }));
19
+ return 1;
20
+ }
13
21
  const { McpServer } = await import("../mcp/server");
14
22
  // #2700 — main() hands over no plugins only at a workspace root with no
15
23
  // lexicon of its own (anywhere else it refuses first). There the lexicons
@@ -29,6 +37,7 @@ export async function runServeMcp(ctx: CommandContext): Promise<number> {
29
37
  instructions,
30
38
  workspace: { cwd: process.cwd() },
31
39
  ...(ctx.args.readOnly === true ? { readOnly: true } : {}),
40
+ ...(ctx.args.propose === true ? { propose: true } : {}),
32
41
  ...(product ? { product } : {}),
33
42
  });
34
43
  await server.start();
package/src/cli/main.ts CHANGED
@@ -1362,7 +1362,9 @@ Local:
1362
1362
  Servers:
1363
1363
  serve lsp Start the LSP server (stdio)
1364
1364
  serve mcp Start the MCP server (stdio); --read-only serves only
1365
- the tools that read (ledger, graph, runs) and run nothing
1365
+ the tools that read (ledger, graph, runs) and run nothing;
1366
+ --read-only --propose also serves a product's tools that
1367
+ open pull requests and comments, and nothing that approves
1366
1368
 
1367
1369
  Project:
1368
1370
  update (alias: sync) Sync lexicon types into .chant/types/ (does not install
@@ -1389,7 +1391,9 @@ Options:
1389
1391
  records its lineage in .chant/workspace.lock.json
1390
1392
  --skill <name> Init: install only this skill from the lexicon
1391
1393
  --skip-mcp Init: scaffold without writing the project's .mcp.json
1392
- --mcp-read-only Init: register \`chant serve mcp --read-only\` in .mcp.json
1394
+ --mcp-read-only Init: register \`chant serve mcp --read-only\` in .mcp.json;
1395
+ with --propose, \`chant serve mcp --read-only --propose\`.
1396
+ Init --dry-run prints that .mcp.json and writes nothing
1393
1397
  --fix Auto-fix fixable issues (lint command)
1394
1398
  --force Force overwrite existing files (import command)
1395
1399
  -w, --watch Watch for changes and rebuild/re-lint (build, lint)
@@ -10,7 +10,11 @@ import { join } from "node:path";
10
10
  import { tmpdir } from "node:os";
11
11
  import { pathToFileURL } from "node:url";
12
12
  import { McpServer } from "./server";
13
- import { productToolWriteWord, ProductToolRefusedError, type ProductMcpHook } from "./product-tools";
13
+ import { PRODUCT_MCP_PROPOSE_FLOOR, productToolWriteWord, ProductToolRefusedError, type ProductMcpHook } from "./product-tools";
14
+ import { PROPOSE_INSTRUCTIONS } from "./server";
15
+ import { READ_ONLY_CORE_TOOLS } from "./read-only";
16
+ import { NEXT_RELEASE } from "../../release-floors";
17
+ import * as ciProduct from "../../ci-product";
14
18
  import { reportReader, reportToolKey, safeReportKey } from "./report-tools";
15
19
  import type { ToolDefinition } from "./types";
16
20
  import type { McpToolContribution } from "../../mcp/types";
@@ -105,6 +109,58 @@ describe("the product tool hook (#4555)", () => {
105
109
  });
106
110
  });
107
111
 
112
+ describe("the --propose tier (#4655)", () => {
113
+ const forge = (name: string, handler: McpToolContribution["handler"] = async () => ({ opened: name })): McpToolContribution => ({ ...tool(name, undefined, handler), forgeWrite: true });
114
+ const hook = (tools: McpToolContribution[], extra: Partial<ProductMcpHook> = {}): ProductMcpHook => ({ product: "terragucci", tools: () => tools, ...extra });
115
+
116
+ test("serves the read tools, the readOnly product tools and the forgeWrite ones, and no op, signal, apply or approve tool", async () => {
117
+ const server = new McpServer([], { readOnly: true, propose: true, product: hook([forge("request_from_template"), tool("templates", true), tool("drift_scan")]) });
118
+ expect(server.readOnly).toBe(true);
119
+ expect(server.propose).toBe(true);
120
+ const names = await listed(server);
121
+ expect(names.filter((n) => n.startsWith("terragucci:")).sort()).toEqual(["terragucci:request_from_template", "terragucci:templates"]);
122
+ expect(names.filter((n) => !n.startsWith("terragucci:")).every((n) => READ_ONLY_CORE_TOOLS.has(n))).toBe(true);
123
+ for (const name of ["op-run", "op-signal", "op-approve", "apply", "lifecycle-snapshot"]) expect(names, name).not.toContain(name);
124
+ expect(JSON.parse((await call(server, "terragucci:request_from_template")).text)).toEqual({ opened: "request_from_template" });
125
+ const res = await server.handleRequest({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} });
126
+ const instructions = (res.result as { instructions: string }).instructions;
127
+ expect(instructions).toContain(PROPOSE_INSTRUCTIONS);
128
+ expect(instructions).toMatch(/open pull requests and comments only/);
129
+ expect(instructions).toMatch(/belong to a person/);
130
+ });
131
+
132
+ test("the read-only server without propose refuses to start, naming the forgeWrite tool", () => {
133
+ const tools = [forge("request_from_template"), tool("templates", true)];
134
+ expect(() => new McpServer([], { readOnly: true, product: hook(tools) })).toThrow(ProductToolRefusedError);
135
+ expect(() => new McpServer([], { readOnly: true, product: hook(tools) })).toThrow(/terragucci:request_from_template|request_from_template/);
136
+ expect(() => new McpServer([], { product: hook(tools) })).toThrow(/request_from_template.*--propose/);
137
+ });
138
+
139
+ test("a forgeWrite tool named with a strong word refuses the start, naming the word", () => {
140
+ for (const [name, word] of [["approve_request", "approve"], ["merge_request", "merge"], ["request_override", "override"], ["apply_template", "apply"], ["create_request", "create"]] as const) {
141
+ const start = () => new McpServer([], { readOnly: true, propose: true, product: hook([forge(name)]) });
142
+ expect(start, name).toThrow(ProductToolRefusedError);
143
+ expect(start, name).toThrow(new RegExp(`${name} would ${word}`));
144
+ }
145
+ expect(productToolWriteWord("propose_change", ["request", "propose"])).toBeUndefined();
146
+ expect(productToolWriteWord("request_from_template", ["request", "propose"])).toBeUndefined();
147
+ });
148
+
149
+ test("propose on the hook turns the tier on, and an ordinary server refuses it", async () => {
150
+ const tools = [forge("request_from_template"), tool("templates", true)];
151
+ expect(await listed(new McpServer([], { product: hook(tools, { propose: true }) }))).toContain("terragucci:request_from_template");
152
+ expect(() => new McpServer([], { product: hook(tools, { readOnly: false, propose: true }) })).toThrow(/--read-only --propose/);
153
+ // The ordinary server serves a forgeWrite tool as any other.
154
+ expect(await listed(new McpServer([], { product: hook(tools, { readOnly: false }) }))).toContain("terragucci:request_from_template");
155
+ });
156
+
157
+ test("the tier's floor is on @intentius/chant/ci-product for a product to feature-detect", () => {
158
+ expect(PRODUCT_MCP_PROPOSE_FLOOR).toBe(NEXT_RELEASE);
159
+ expect(ciProduct.PRODUCT_MCP_PROPOSE_FLOOR).toBe(PRODUCT_MCP_PROPOSE_FLOOR);
160
+ expect(ciProduct.PRODUCT_TOOL_PROPOSE_WORDS).toEqual(["request", "propose"]);
161
+ });
162
+ });
163
+
108
164
  describe("the report tool's keys (#4555)", () => {
109
165
  test("take a pull request, a commit, an optional member and one of the stage files", () => {
110
166
  expect(reportToolKey({ pr: "12", commit: "a".repeat(40), file: "change-set.json" })).toBe(`12/${"a".repeat(40)}/change-set.json`);
@@ -20,10 +20,20 @@
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
 
25
35
  import type { McpToolContribution } from "../../mcp/types";
26
- import { servesContributedTool } from "./read-only";
36
+ import { NEXT_RELEASE } from "../../release-floors";
27
37
  import { reportReader, reportUrlFor, type ReportReader } from "./report-tools";
28
38
 
29
39
  /** What a product's tools are handed. */
@@ -32,6 +42,8 @@ export interface ProductMcpContext {
32
42
  cwd: string;
33
43
  /** Whether the server is read-only. */
34
44
  readOnly: boolean;
45
+ /** Whether the read-only server also serves the product's `forgeWrite` tools (`--propose`, chant#4655). */
46
+ propose: boolean;
35
47
  /**
36
48
  * The report store, read-only: the hook's `reportUrl`, else the declared
37
49
  * `ci.reportUrl`. Resolves undefined when neither names one.
@@ -49,10 +61,27 @@ export interface ProductMcpHook {
49
61
  reportUrl?: string;
50
62
  /** `false` starts an ordinary server through the hook. Default: read-only. */
51
63
  readOnly?: boolean;
64
+ /**
65
+ * `true` serves the product's `forgeWrite` tools on the read-only server,
66
+ * as `--propose` does (chant#4655). It needs the server read-only: with
67
+ * `readOnly: false` the server refuses to start.
68
+ */
69
+ propose?: boolean;
52
70
  /** Text added to the server's `initialize` instructions. */
53
71
  instructions?: string;
54
72
  }
55
73
 
74
+ /**
75
+ * The first chant whose `chant serve mcp` has the `--propose` tier and serves
76
+ * `forgeWrite` product tools on it (chant#4655). A product checks this before
77
+ * it passes `--propose` or `propose: true`, and refuses naming this release
78
+ * when its chant is older.
79
+ */
80
+ export const PRODUCT_MCP_PROPOSE_FLOOR = NEXT_RELEASE;
81
+
82
+ /** The words a `forgeWrite` tool's name may hold on the `--propose` tier, which the write-word check passes over (chant#4655). */
83
+ export const PRODUCT_TOOL_PROPOSE_WORDS = ["request", "propose"] as const;
84
+
56
85
  /** Words that say a tool would change something; a read-only server will not serve a tool named with one. terragucci's list. */
57
86
  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"] as const;
58
87
 
@@ -65,16 +94,26 @@ export const PRODUCT_TOOL_STRONG_WORDS = ["approve", "override", "revoke", "unlo
65
94
  * strong one anywhere: `last_apply` reads, `apply_wave` and `wave_approve`
66
95
  * do not.
67
96
  */
68
- export function productToolWriteWord(name: string): string | undefined {
97
+ export function productToolWriteWord(name: string, exempt: readonly string[] = []): string | undefined {
69
98
  const parts = name.toLowerCase().split(/[^a-z]+/).filter(Boolean);
70
99
  const first = parts[0] ?? "";
71
- return PRODUCT_TOOL_WRITE_WORDS.find((w) => first.startsWith(w)) ?? PRODUCT_TOOL_STRONG_WORDS.find((w) => parts.some((p) => p.startsWith(w)));
100
+ const words = (list: readonly string[]) => list.filter((w) => !exempt.includes(w));
101
+ return words(PRODUCT_TOOL_WRITE_WORDS).find((w) => first.startsWith(w)) ?? words(PRODUCT_TOOL_STRONG_WORDS).find((w) => parts.some((p) => p.startsWith(w)));
72
102
  }
73
103
 
74
- /** A read-only server refused a product tool named as a write. */
104
+ /**
105
+ * A read-only server refused a product tool: one named as a write, or a
106
+ * `forgeWrite` tool on a server started without `--propose` (chant#4655).
107
+ */
75
108
  export class ProductToolRefusedError extends Error {
76
- constructor(product: string, name: string, word: string) {
77
- super(`chant serve mcp is read-only for ${product}, and the tool ${name} would ${word}; the server does not start with it`);
109
+ constructor(product: string, name: string, word: string, tier: "read-only" | "propose" | "forge-write" = "read-only") {
110
+ super(
111
+ tier === "forge-write"
112
+ ? `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`
113
+ : tier === "propose"
114
+ ? `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`
115
+ : `chant serve mcp is read-only for ${product}, and the tool ${name} would ${word}; the server does not start with it`,
116
+ );
78
117
  this.name = "ProductToolRefusedError";
79
118
  }
80
119
  }
@@ -82,28 +121,41 @@ export class ProductToolRefusedError extends Error {
82
121
  const PRODUCT = /^[a-z0-9][a-z0-9-]*$/;
83
122
 
84
123
  /**
85
- * The product tools a server serves: on a read-only server only those that
86
- * declare `readOnly: true`, and none named as a write (a throw, so the server
87
- * does not start). On an ordinary server every tool.
124
+ * The product tools a server serves. On an ordinary server every tool. On a
125
+ * read-only server those that declare `readOnly: true`, none named as a
126
+ * write, and no `forgeWrite` tool (each a throw, so the server does not
127
+ * start). On the `--propose` tier the `readOnly: true` tools under the same
128
+ * check, plus the `forgeWrite` tools, whose names may hold `request` or
129
+ * `propose` but no other write word (chant#4655).
88
130
  */
89
131
  export function productToolsServed(hook: ProductMcpHook, ctx: ProductMcpContext): McpToolContribution[] {
90
132
  if (!PRODUCT.test(hook.product)) throw new Error(`the product tool hook's product ${JSON.stringify(hook.product)} is not a product name ([a-z0-9-])`);
91
- const served = hook.tools(ctx).filter((t) => servesContributedTool(t, ctx.readOnly));
92
- if (ctx.readOnly) {
93
- for (const t of served) {
94
- const word = productToolWriteWord(t.name.startsWith(`${hook.product}:`) ? t.name.slice(hook.product.length + 1) : t.name);
95
- if (word) throw new ProductToolRefusedError(hook.product, t.name, word);
133
+ const tools = hook.tools(ctx);
134
+ if (!ctx.readOnly) return tools;
135
+ const served: McpToolContribution[] = [];
136
+ for (const t of tools) {
137
+ const short = t.name.startsWith(`${hook.product}:`) ? t.name.slice(hook.product.length + 1) : t.name;
138
+ if (t.forgeWrite === true) {
139
+ if (!ctx.propose) throw new ProductToolRefusedError(hook.product, t.name, "open a pull request", "forge-write");
140
+ const word = productToolWriteWord(short, PRODUCT_TOOL_PROPOSE_WORDS);
141
+ if (word) throw new ProductToolRefusedError(hook.product, t.name, word, "propose");
142
+ served.push(t);
143
+ } else if (t.readOnly === true) {
144
+ const word = productToolWriteWord(short);
145
+ if (word) throw new ProductToolRefusedError(hook.product, t.name, word, ctx.propose ? "propose" : "read-only");
146
+ served.push(t);
96
147
  }
97
148
  }
98
149
  return served;
99
150
  }
100
151
 
101
152
  /** The context a hook's tools get on a server at `cwd`. The store is opened on first read. */
102
- export function productMcpContext(hook: ProductMcpHook, cwd: string, readOnly: boolean): ProductMcpContext {
153
+ export function productMcpContext(hook: ProductMcpHook, cwd: string, readOnly: boolean, propose = false): ProductMcpContext {
103
154
  let opened: Promise<ReportReader | undefined> | undefined;
104
155
  return {
105
156
  cwd,
106
157
  readOnly,
158
+ propose,
107
159
  reports: () =>
108
160
  (opened ??= reportUrlFor(hook.reportUrl, cwd).then((url) => (url ? reportReader(url) : undefined))),
109
161
  };
@@ -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
  import { workspaceReadTools, workspaceWriteTools } from "./workspace-tools";
@@ -102,6 +102,10 @@ export function namespacedResourceUri(lexicon: string, uri: string): string {
102
102
  export const READ_ONLY_INSTRUCTIONS =
103
103
  "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.";
104
104
 
105
+ /** The `initialize` instructions of the `--propose` tier (chant#4655), in place of {@link READ_ONLY_INSTRUCTIONS}. */
106
+ export const PROPOSE_INSTRUCTIONS =
107
+ "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.";
108
+
105
109
  /** The `lint` a read-only server serves: the same tool with no `fix` (chant#4543). */
106
110
  const readOnlyLintTool: ToolDefinition = {
107
111
  ...lintTool,
@@ -127,6 +131,8 @@ export class McpServer {
127
131
  private clientInfo: McpClientInfo | undefined;
128
132
  /** `chant serve mcp --read-only` (chant#4543): only tools that change nothing are registered. */
129
133
  readonly readOnly: boolean;
134
+ /** `chant serve mcp --read-only --propose` (chant#4655): the read-only server plus the product's `forgeWrite` tools. */
135
+ readonly propose: boolean;
130
136
 
131
137
  /**
132
138
  * `options.instructions` is sent as the `initialize` result's
@@ -149,14 +155,21 @@ export class McpServer {
149
155
  * under the same read-only rule as a plugin's, and a read-only server
150
156
  * refuses to start with one named as a write. With a hook and no
151
157
  * `readOnly`, the server is read-only unless the hook says otherwise.
158
+ *
159
+ * `options.propose` (`--propose`, chant#4655), or `propose: true` on the
160
+ * hook, is a tier of the read-only server: the same core and plugin tools,
161
+ * plus the product tools that declare `forgeWrite: true`. It needs
162
+ * `readOnly`; an ordinary server with it refuses to start.
152
163
  */
153
- constructor(plugins?: LexiconPlugin[], options: { instructions?: string; workspace?: WorkspaceToolsOptions; readOnly?: boolean; product?: ProductMcpHook } = {}) {
164
+ constructor(plugins?: LexiconPlugin[], options: { instructions?: string; workspace?: WorkspaceToolsOptions; readOnly?: boolean; propose?: boolean; product?: ProductMcpHook } = {}) {
154
165
  this.plugins = plugins ?? [];
155
166
  const product = options.product;
156
167
  this.readOnly = options.readOnly ?? (product ? product.readOnly !== false : false);
168
+ this.propose = options.propose === true || product?.propose === true;
169
+ if (this.propose && !this.readOnly) throw new Error("chant serve mcp --propose is a tier of the read-only server: start it with --read-only --propose");
157
170
  const said = [options.instructions, product?.instructions].filter((s): s is string => s !== undefined);
158
171
  this.instructions = this.readOnly
159
- ? [...said, READ_ONLY_INSTRUCTIONS].join("\n\n")
172
+ ? [...said, this.propose ? PROPOSE_INSTRUCTIONS : READ_ONLY_INSTRUCTIONS].join("\n\n")
160
173
  : said.length > 0 ? said.join("\n\n") : undefined;
161
174
  const cwd = options.workspace?.cwd ?? process.cwd();
162
175
  // Register core tools
@@ -203,9 +216,10 @@ export class McpServer {
203
216
  }
204
217
  }
205
218
 
206
- // A CI product's tools (chant#4555), read-only by default as chant#4543 rules for contributed tools.
219
+ // A CI product's tools (chant#4555), read-only by default as chant#4543 rules for contributed tools,
220
+ // and its forgeWrite tools on the --propose tier (chant#4655).
207
221
  if (product) {
208
- for (const tool of productToolsServed(product, productMcpContext(product, cwd, this.readOnly))) {
222
+ for (const tool of productToolsServed(product, productMcpContext(product, cwd, this.readOnly, this.propose))) {
209
223
  this.registerTool({ name: namespacedToolName(product.product, tool.name), description: tool.description, inputSchema: tool.inputSchema }, tool.handler);
210
224
  }
211
225
  }
@@ -459,7 +473,7 @@ export class McpServer {
459
473
  /**
460
474
  * Start MCP server, loading plugins from the project
461
475
  */
462
- export async function startMcpServer(options: { readOnly?: boolean } = {}): Promise<void> {
476
+ export async function startMcpServer(options: { readOnly?: boolean; propose?: boolean } = {}): Promise<void> {
463
477
  let plugins: LexiconPlugin[] = [];
464
478
  try {
465
479
  const { resolveProjectLexicons, loadPlugins } = await import("../plugins");
@@ -473,6 +487,7 @@ export async function startMcpServer(options: { readOnly?: boolean } = {}): Prom
473
487
  const server = new McpServer(plugins, {
474
488
  workspace: { cwd: process.cwd() },
475
489
  ...(options.readOnly ? { readOnly: true } : {}),
490
+ ...(options.propose ? { propose: true } : {}),
476
491
  ...(product ? { product } : {}),
477
492
  });
478
493
  server.start();
@@ -1,4 +1,4 @@
1
- import { describe, test, expect } from "vitest";
1
+ import { describe, test, expect, vi } from "vitest";
2
2
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
3
3
  import { join } from "path";
4
4
  import { homedir } from "os";
@@ -7,7 +7,10 @@ import { initCommand } from "./commands/init";
7
7
  import { doctorCommand } from "./commands/doctor";
8
8
  import { updateCommand } from "./commands/update";
9
9
  import { parseArgs, commandRegistry } from "./main";
10
- import { MCP_CONFIG_FILENAME, MCP_SETUP_COMMAND, mcpConfigPath } from "./mcp-config";
10
+ import { generateMcpConfig, MCP_CONFIG_FILENAME, MCP_SETUP_COMMAND, mcpConfigPath } from "./mcp-config";
11
+ import { runServeMcp } from "./handlers/serve";
12
+ import { runInit } from "./handlers/init";
13
+ import type { CommandContext } from "./registry";
11
14
 
12
15
  /**
13
16
  * chant #2383. `chant init` used to write `mcp.json` into the user's home
@@ -166,3 +169,50 @@ describe("MCP config: one location, three agreeing sites (#2383)", () => {
166
169
  }
167
170
  });
168
171
  });
172
+
173
+ describe("the --propose tier on the command line (#4655)", () => {
174
+ const ctx = (argv: string[]): CommandContext => ({ args: parseArgs(argv), plugins: [], serializers: [] });
175
+
176
+ async function captured(run: () => Promise<number>): Promise<{ code: number; out: string; err: string }> {
177
+ const out: string[] = [];
178
+ const err: string[] = [];
179
+ const log = vi.spyOn(console, "log").mockImplementation((...a: unknown[]) => void out.push(a.join(" ")));
180
+ const error = vi.spyOn(console, "error").mockImplementation((...a: unknown[]) => void err.push(a.join(" ")));
181
+ try {
182
+ return { code: await run(), out: out.join("\n"), err: err.join("\n") };
183
+ } finally {
184
+ log.mockRestore();
185
+ error.mockRestore();
186
+ }
187
+ }
188
+
189
+ test("chant serve mcp --propose without --read-only exits 1 with a usage message", async () => {
190
+ const args = parseArgs(["serve", "mcp", "--propose"]);
191
+ expect(args.propose).toBe(true);
192
+ const got = await captured(() => runServeMcp(ctx(["serve", "mcp", "--propose"])));
193
+ expect(got.code).toBe(1);
194
+ expect(got.err).toMatch(/--propose needs --read-only/);
195
+ expect(got.err).toMatch(/Usage: chant serve mcp --read-only --propose/);
196
+ });
197
+
198
+ test("chant init --mcp-read-only --propose --dry-run prints the .mcp.json it would write, and writes nothing", async () => {
199
+ await withTestDir(async (dir) => {
200
+ const got = await captured(() => runInit(ctx(["init", dir, "--mcp-read-only", "--propose", "--dry-run"])));
201
+ expect(got.code).toBe(0);
202
+ expect(JSON.parse(got.out).mcpServers.chant.args).toEqual(["chant", "serve", "mcp", "--read-only", "--propose"]);
203
+ expect(existsSync(mcpConfigPath(dir))).toBe(false);
204
+ });
205
+ const refused = await captured(() => runInit(ctx(["init", "--propose", "--dry-run"])));
206
+ expect(refused.code).toBe(1);
207
+ expect(refused.err).toMatch(/--propose needs --mcp-read-only/);
208
+ });
209
+
210
+ test("init --mcp-read-only --propose registers the tier, and propose alone is refused", async () => {
211
+ await withTestDir(async (testDir) => {
212
+ await initCommand({ path: testDir, lexicon: "aws", skipInstall: true, mcpReadOnly: true, mcpPropose: true });
213
+ const config = JSON.parse(readFileSync(mcpConfigPath(testDir), "utf-8"));
214
+ expect(config.mcpServers.chant.args).toEqual(["chant", "serve", "mcp", "--read-only", "--propose"]);
215
+ });
216
+ expect(() => generateMcpConfig("npm", { propose: true })).toThrow(/--mcp-read-only --propose/);
217
+ });
218
+ });