@intentius/chant 0.124.77 → 0.124.78

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 (123) hide show
  1. package/dist/__fixtures__/notify-messages/events.d.ts +9 -0
  2. package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
  3. package/dist/__fixtures__/notify-messages/events.js +21 -0
  4. package/dist/__fixtures__/product-words.d.ts +14 -0
  5. package/dist/__fixtures__/product-words.d.ts.map +1 -1
  6. package/dist/__fixtures__/product-words.js +11 -0
  7. package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
  8. package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
  9. package/dist/__fixtures__/terragucci-notify.js +133 -0
  10. package/dist/action-pins.d.ts +8 -0
  11. package/dist/action-pins.d.ts.map +1 -1
  12. package/dist/action-pins.js +9 -0
  13. package/dist/agent-guard.d.ts.map +1 -1
  14. package/dist/agent-guard.js +1 -2
  15. package/dist/ci-commit.d.ts +66 -2
  16. package/dist/ci-commit.d.ts.map +1 -1
  17. package/dist/ci-commit.js +148 -19
  18. package/dist/ci-own-jobs.d.ts.map +1 -1
  19. package/dist/ci-own-jobs.js +1 -2
  20. package/dist/ci-product-words.d.ts +18 -4
  21. package/dist/ci-product-words.d.ts.map +1 -1
  22. package/dist/ci-product-words.js +26 -6
  23. package/dist/ci-product.d.ts +1 -1
  24. package/dist/ci-product.d.ts.map +1 -1
  25. package/dist/ci-product.js +3 -4
  26. package/dist/cli/handlers/release.js +4 -4
  27. package/dist/components/pr-env-components.d.ts.map +1 -1
  28. package/dist/components/pr-env-components.js +1 -2
  29. package/dist/config.d.ts +14 -8
  30. package/dist/config.d.ts.map +1 -1
  31. package/dist/config.js +16 -1
  32. package/dist/lexicon.d.ts +8 -0
  33. package/dist/lexicon.d.ts.map +1 -1
  34. package/dist/lexicon.js +9 -0
  35. package/dist/lifecycle/release-images.d.ts +77 -3
  36. package/dist/lifecycle/release-images.d.ts.map +1 -1
  37. package/dist/lifecycle/release-images.js +132 -6
  38. package/dist/notify-product.d.ts +11 -2
  39. package/dist/notify-product.d.ts.map +1 -1
  40. package/dist/notify-product.js +16 -4
  41. package/dist/notify-relay.d.ts.map +1 -1
  42. package/dist/notify-relay.js +1 -2
  43. package/dist/notify.d.ts +36 -4
  44. package/dist/notify.d.ts.map +1 -1
  45. package/dist/notify.js +31 -21
  46. package/dist/notify.schema.json +1 -0
  47. package/dist/op/activities/review-product.d.ts +111 -0
  48. package/dist/op/activities/review-product.d.ts.map +1 -0
  49. package/dist/op/activities/review-product.js +116 -0
  50. package/dist/policy-engine.d.ts.map +1 -1
  51. package/dist/policy-engine.js +1 -2
  52. package/dist/pr-forge-reads.d.ts +124 -0
  53. package/dist/pr-forge-reads.d.ts.map +1 -0
  54. package/dist/pr-forge-reads.js +322 -0
  55. package/dist/pr-forge.d.ts +14 -0
  56. package/dist/pr-forge.d.ts.map +1 -1
  57. package/dist/pr-forge.js +21 -13
  58. package/dist/pr-plan-note.d.ts +293 -0
  59. package/dist/pr-plan-note.d.ts.map +1 -0
  60. package/dist/pr-plan-note.js +362 -0
  61. package/dist/release-floors.d.ts +9 -1
  62. package/dist/release-floors.d.ts.map +1 -1
  63. package/dist/release-floors.js +9 -1
  64. package/dist/state-export.d.ts.map +1 -1
  65. package/dist/state-export.js +1 -2
  66. package/dist/state-migration.d.ts.map +1 -1
  67. package/dist/state-migration.js +1 -2
  68. package/dist/state-unlock.d.ts.map +1 -1
  69. package/dist/state-unlock.js +1 -2
  70. package/dist/wave-runtime.mjs +271 -271
  71. package/dist/workspace/release-workflow.d.ts.map +1 -1
  72. package/dist/workspace/release-workflow.js +2 -1
  73. package/package.json +1 -1
  74. package/src/__fixtures__/notify-messages/events.ts +23 -0
  75. package/src/__fixtures__/notify-messages/messages.json +50 -0
  76. package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
  77. package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
  78. package/src/__fixtures__/product-words.ts +12 -0
  79. package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
  80. package/src/__fixtures__/terragucci-notify.ts +170 -0
  81. package/src/action-pins.test.ts +12 -1
  82. package/src/action-pins.ts +11 -0
  83. package/src/agent-guard.test.ts +1 -2
  84. package/src/agent-guard.ts +1 -2
  85. package/src/ci-commit.test.ts +163 -0
  86. package/src/ci-commit.ts +168 -21
  87. package/src/ci-own-jobs.test.ts +1 -2
  88. package/src/ci-own-jobs.ts +1 -2
  89. package/src/ci-product-words.ts +35 -7
  90. package/src/ci-product.ts +3 -4
  91. package/src/cli/handlers/build-pr-loop-control.test.ts +1 -2
  92. package/src/cli/handlers/build-run-group.test.ts +1 -2
  93. package/src/cli/handlers/release.ts +5 -5
  94. package/src/components/pr-env-components.test.ts +1 -2
  95. package/src/components/pr-env-components.ts +1 -2
  96. package/src/config.ts +23 -3
  97. package/src/gate-policy-bundle.test.ts +1 -1
  98. package/src/lexicon.ts +10 -0
  99. package/src/lifecycle/release-images-dockerfile.test.ts +221 -0
  100. package/src/lifecycle/release-images.ts +167 -8
  101. package/src/notify-message-words.test.ts +186 -0
  102. package/src/notify-product.ts +17 -4
  103. package/src/notify-relay.ts +1 -2
  104. package/src/notify.schema.json +1 -0
  105. package/src/notify.ts +59 -19
  106. package/src/op/activities/review-product.test.ts +116 -0
  107. package/src/op/activities/review-product.ts +200 -0
  108. package/src/op/schedule-overdue.test.ts +26 -0
  109. package/src/policy-engine.test.ts +1 -2
  110. package/src/policy-engine.ts +1 -2
  111. package/src/pr-forge-reads.test.ts +285 -0
  112. package/src/pr-forge-reads.ts +424 -0
  113. package/src/pr-forge.ts +30 -16
  114. package/src/pr-plan-note.test.ts +105 -0
  115. package/src/pr-plan-note.ts +521 -0
  116. package/src/release-floors.ts +13 -1
  117. package/src/state-export.test.ts +1 -2
  118. package/src/state-export.ts +1 -2
  119. package/src/state-migration.test.ts +1 -2
  120. package/src/state-migration.ts +1 -2
  121. package/src/state-unlock.test.ts +1 -2
  122. package/src/state-unlock.ts +1 -2
  123. package/src/workspace/release-workflow.ts +2 -1
@@ -0,0 +1,293 @@
1
+ /**
2
+ * A product's plan note (#4810): the pull-request note for a product whose
3
+ * plan job does not run chant's pr loop, rendered from a report the product
4
+ * builds from its own plan run, in the product's words.
5
+ *
6
+ * terragucci plans each root itself and writes its own report, so it has no
7
+ * `PrReport` for `renderPrNote` (./pr-loop.ts). It hands chant a
8
+ * {@link PrPlanNote} instead: the note's rows by unit (a root, or an
9
+ * instance of one root), the totals in the binary's own counting, the named
10
+ * destroys, replacements, refusals, imports and forgets, each group with the
11
+ * diff of its first unit, each unit's whole plan, the wave table and the
12
+ * waves marker, the policy overrides and warnings, the deferred units, the
13
+ * previewed waves and the units planned on another's planned outputs, the
14
+ * report links, and the lines and sections only the product knows about
15
+ * (its notices, a cost table, a blast radius). chant lays them out, links
16
+ * them into the report, and cuts the note to the forge's limit: whole plans
17
+ * go first, then group diffs shrink to attribute names, whichever saves the
18
+ * most first, then blocks drop from the end, and a Cut line names what went.
19
+ *
20
+ * The pr loop's bundle (pr-loop-bundle.test.ts) does not carry this module,
21
+ * so a product's sections do not grow it. {@link renderPrNote} here takes
22
+ * either report and renders a `PrReport` with the pr loop's own renderer,
23
+ * so a plywood or sql-yodeler note is byte for byte what it was.
24
+ */
25
+ import { renderPrNote as renderPrLoopNote, type PrReport } from "./pr-loop.js";
26
+ import { type CiProductWords } from "./ci-product-words.js";
27
+ /** The first chant with the product plan note (#4810). */
28
+ export declare const PR_PLAN_NOTE_FLOOR = "0.124.78";
29
+ /** The read contract a {@link PrPlanNote} follows. */
30
+ export declare const PR_PLAN_NOTE_CONTRACT = 1;
31
+ /** One change line of a group, as chant's plan summary groups them. */
32
+ export interface PrPlanNoteChange {
33
+ line: string;
34
+ count: number;
35
+ differsFrom?: string;
36
+ differsIn?: string[];
37
+ }
38
+ /** A group of units with the same change. */
39
+ export interface PrPlanNoteGroup {
40
+ id: string;
41
+ units: string[];
42
+ /** The one resource an instance group is of. */
43
+ resource?: string;
44
+ outlier?: boolean;
45
+ noChanges?: boolean;
46
+ /** The group whose change this one adds to; `changes` are then what it adds. */
47
+ extends?: string;
48
+ /** Every change of the group is one on every run: the note shows its attribute names alone. */
49
+ recurring?: boolean;
50
+ /** The group's change lines (or what it adds to `extends`). */
51
+ changes: PrPlanNoteChange[];
52
+ /** The plan text of the group's first unit, as the binary printed it: the note shows it as a `diff` block. */
53
+ diff?: {
54
+ unit: string;
55
+ lines: string[];
56
+ };
57
+ /** Where values differ between the group's units, as `address.path`. */
58
+ varies?: string[];
59
+ }
60
+ /** A destroy, replacement, refusal, import or forget, kept when the note is cut. */
61
+ export interface PrPlanNoteNamed {
62
+ /** The unit it is in (a root). */
63
+ member: string;
64
+ address?: string;
65
+ deposed?: string;
66
+ action: "delete" | "replace" | "refused" | "import" | "forget";
67
+ /** The word the note shows for the action. Default: destroy, replace, refused to plan, import, forget. */
68
+ word?: string;
69
+ /** The attribute paths that forced a replacement, each joined with `.`. */
70
+ forcedBy?: string[];
71
+ reason?: string;
72
+ }
73
+ /** A wave's row. A plan names each wave's review digest; an apply names its set digest and approval. */
74
+ export interface PrPlanNoteWave {
75
+ number: number;
76
+ /** How many units it holds. */
77
+ units: number;
78
+ composed?: boolean;
79
+ /** The environments its units are in. Set on every wave when the table shows the column. */
80
+ environments?: string[];
81
+ /** The digest an approval of the wave binds. Present (even null) on any wave puts the table in review form. */
82
+ digest?: string | null;
83
+ /** Whether the gate will hold it for an approval. */
84
+ waits?: boolean;
85
+ /** The waves it plans again after. */
86
+ replansAfter?: number[];
87
+ /** Units whose plan reads a value unknown at plan time, which holds it. */
88
+ unknownBy?: string[];
89
+ /** Units whose hook asks for an approval. */
90
+ heldByHooks?: string[];
91
+ /** What the policy said of the wave: held by its rules, or allowed unattended by them. */
92
+ policy?: {
93
+ outcome: "held" | "unattended" | string;
94
+ rules: string[];
95
+ };
96
+ /** The approval rules at base, each with what it asks for in words. */
97
+ approvalRules?: {
98
+ units: string[];
99
+ asks: string;
100
+ }[];
101
+ /** An apply's set digest and approval, in the other form of the table. */
102
+ setDigest?: string;
103
+ approval?: string;
104
+ }
105
+ /** A denial a listed approver may override, or the override that stands. */
106
+ export interface PrPlanNoteOverride {
107
+ member: string;
108
+ /** The rules the override names, else those that denied. */
109
+ rules: string[];
110
+ override?: {
111
+ by: string;
112
+ at: string;
113
+ sealed?: boolean;
114
+ plan: string;
115
+ reason: string;
116
+ };
117
+ /** Who may override it; an empty list names nobody. */
118
+ overriders: string[];
119
+ }
120
+ /** A line under the counts that may link into the report. */
121
+ export interface PrPlanNoteFact {
122
+ text: string;
123
+ /** Linked to the report's anchor when the note links report.html itself; else `plain`, or the text alone. */
124
+ link?: {
125
+ text: string;
126
+ anchor: string;
127
+ plain?: string;
128
+ };
129
+ after?: string;
130
+ }
131
+ /**
132
+ * What a product hands chant for its plan note: everything the note shows,
133
+ * built from the product's own plan run.
134
+ */
135
+ export interface PrPlanNote {
136
+ kind: "plan-note";
137
+ contract: typeof PR_PLAN_NOTE_CONTRACT;
138
+ /** The stage as the heading names it, such as `tf-plan`. */
139
+ stage: string;
140
+ /** A plan of a pull request (not an apply or a drift check). */
141
+ planning?: boolean;
142
+ wave?: number;
143
+ /** The commit planned. */
144
+ head: string;
145
+ /** `instance`: the units are instances of one root. Default: the product's noun. */
146
+ unit?: "member" | "instance";
147
+ units: number;
148
+ /** The run's total in the binary's own counting: a replacement adds one and destroys one. */
149
+ totals?: {
150
+ add: number;
151
+ change: number;
152
+ destroy: number;
153
+ forget: number;
154
+ members: number;
155
+ };
156
+ /** The change reaches no unit, so nothing was planned. */
157
+ nothing?: boolean;
158
+ /** Lines about the pipeline itself, such as overdue drift checks. */
159
+ notices?: string[];
160
+ /** The product's lines under them: tips, binaries, cost, the slowest resources. */
161
+ facts?: PrPlanNoteFact[];
162
+ named: PrPlanNoteNamed[];
163
+ overrides?: PrPlanNoteOverride[];
164
+ warnings?: {
165
+ member: string;
166
+ text: string;
167
+ }[];
168
+ deferred?: {
169
+ unit: string;
170
+ after: string[];
171
+ why: string;
172
+ previewed?: boolean;
173
+ }[];
174
+ waves: PrPlanNoteWave[];
175
+ /** What the waves marker carries beside the waves. */
176
+ previews?: unknown[];
177
+ /** Waves planned at their gate against the preview a pull request showed. */
178
+ previewed?: {
179
+ wave: number;
180
+ pullRequest: number | string;
181
+ units: number;
182
+ moved: {
183
+ unit: string;
184
+ differences: string[];
185
+ }[];
186
+ }[];
187
+ /** Units planned on another unit's planned outputs. */
188
+ linked?: {
189
+ member: string;
190
+ upstream: string;
191
+ composed?: boolean;
192
+ unknown?: string[];
193
+ }[];
194
+ /** The product's own blocks: `start` before the named changes, `groups` before the groups, `end` after them. Each text as it is shown. */
195
+ sections?: {
196
+ at: "start" | "groups" | "end";
197
+ text: string;
198
+ }[];
199
+ groups: PrPlanNoteGroup[];
200
+ /** Each unit's whole plan, collapsed: its text, its totals line, and its plan file beside the report or at a link. */
201
+ plans?: {
202
+ member: string;
203
+ text: string;
204
+ totals?: string;
205
+ file?: string;
206
+ url?: string;
207
+ }[];
208
+ /**
209
+ * Where the report is: `report`, report.html or the run's page when
210
+ * `artifacts`; `run`, the run's page when the run keeps no report;
211
+ * `expires`, when presigned links stop working.
212
+ */
213
+ links?: {
214
+ report?: string;
215
+ artifacts?: boolean;
216
+ run?: string;
217
+ expires?: string;
218
+ };
219
+ /** A waiting wave's approve line and an override line ask for a signature. */
220
+ sealed?: boolean;
221
+ }
222
+ /** The plan note's own words; every slot defaults to chant's. */
223
+ export interface PrPlanNoteWords {
224
+ /** The note's last line. */
225
+ footer?: string;
226
+ /** The report page's file name. */
227
+ page?: string;
228
+ /** The artifact the run keeps the report in. */
229
+ artifact?: string;
230
+ /** The line for a run that keeps no report, over `{run}`. */
231
+ noReport?: string;
232
+ /** The waves marker's name. Default `<product>:waves`. */
233
+ marker?: string;
234
+ /** The report's anchors for a unit and a group, over `{id}`. */
235
+ anchors?: {
236
+ member?: string;
237
+ group?: string;
238
+ };
239
+ /** The setting that names who may override a denial. */
240
+ overrideKey?: string;
241
+ /** The setting that holds the approval rules. */
242
+ approvalRulesKey?: string;
243
+ /** The stage that applies the plan. */
244
+ applyStage?: string;
245
+ /** The file each unit's plan is kept in. */
246
+ planFile?: string;
247
+ /** The op an override is recorded under. */
248
+ overrideOp?: string;
249
+ }
250
+ /** Options for {@link renderPlanNote}. */
251
+ export interface PlanNoteOptions {
252
+ /** The most characters the note may hold. Default GitHub's 65,536. */
253
+ limit?: number;
254
+ words?: CiProductWords;
255
+ note?: PrPlanNoteWords;
256
+ }
257
+ /**
258
+ * The note for either report: a `PrReport` as the pr loop renders it, or a
259
+ * product's {@link PrPlanNote}.
260
+ */
261
+ export declare function renderPrNote(report: PrReport | PrPlanNote, options?: NonNullable<Parameters<typeof renderPrLoopNote>[1]> & {
262
+ note?: PrPlanNoteWords;
263
+ }): string;
264
+ /** Whether `report` is a product's plan note. */
265
+ export declare function isPlanNote(report: unknown): report is PrPlanNote;
266
+ /**
267
+ * Lines as a `diff` block wants them, as Atlantis comments a plan: each
268
+ * line's change symbol (`+`, `-`, `~`, `-/+`, `+/-`) moves to the first
269
+ * column, so the forge colours additions and removals.
270
+ */
271
+ export declare function diffLines(lines: readonly string[]): string[];
272
+ /** A fenced `diff` block whose fence is longer than any run of backticks in the text. */
273
+ export declare function diffFence(lines: readonly string[]): string;
274
+ /** The waves marker: an HTML comment with no `<` or `>` in its JSON, so nothing in it ends the comment. */
275
+ export declare function planNoteMarker(name: string, waves: {
276
+ head: string;
277
+ waves: {
278
+ number: number;
279
+ digest: string | null;
280
+ waits: boolean;
281
+ }[];
282
+ previews?: unknown[];
283
+ }): string;
284
+ /**
285
+ * A product's plan note. Each group links to its anchor in the report and
286
+ * each named change to its unit's. Destroys, replacements and refusals come
287
+ * first and are never dropped for space before a group is. Over the limit,
288
+ * the units' whole plans go and the groups' diffs shrink to their attribute
289
+ * names, whichever saves the most first; then blocks are dropped, whole,
290
+ * from the end. A Cut line names what went.
291
+ */
292
+ export declare function renderPlanNote(report: PrPlanNote, options?: PlanNoteOptions): string;
293
+ //# sourceMappingURL=pr-plan-note.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pr-plan-note.d.ts","sourceRoot":"","sources":["../src/pr-plan-note.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE5E,OAAO,EAAiD,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGxG,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,aAAe,CAAC;AAE/C,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,uEAAuE;AACvE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+DAA+D;IAC/D,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,8GAA8G;IAC9G,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACzC,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,oFA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E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU,EAAE,OAAO,GAAE,WAAW,CAAC,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,eAAe,CAAA;CAAO,GAAG,MAAM,CAElK;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,UAAU,CAEhE;AAYD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAE5D;AAED,yFAAyF;AACzF,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAK1D;AAED,2GAA2G;AAC3G,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG,MAAM,CAEtK;AAmBD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAqOxF"}
@@ -0,0 +1,362 @@
1
+ /**
2
+ * A product's plan note (#4810): the pull-request note for a product whose
3
+ * plan job does not run chant's pr loop, rendered from a report the product
4
+ * builds from its own plan run, in the product's words.
5
+ *
6
+ * terragucci plans each root itself and writes its own report, so it has no
7
+ * `PrReport` for `renderPrNote` (./pr-loop.ts). It hands chant a
8
+ * {@link PrPlanNote} instead: the note's rows by unit (a root, or an
9
+ * instance of one root), the totals in the binary's own counting, the named
10
+ * destroys, replacements, refusals, imports and forgets, each group with the
11
+ * diff of its first unit, each unit's whole plan, the wave table and the
12
+ * waves marker, the policy overrides and warnings, the deferred units, the
13
+ * previewed waves and the units planned on another's planned outputs, the
14
+ * report links, and the lines and sections only the product knows about
15
+ * (its notices, a cost table, a blast radius). chant lays them out, links
16
+ * them into the report, and cuts the note to the forge's limit: whole plans
17
+ * go first, then group diffs shrink to attribute names, whichever saves the
18
+ * most first, then blocks drop from the end, and a Cut line names what went.
19
+ *
20
+ * The pr loop's bundle (pr-loop-bundle.test.ts) does not carry this module,
21
+ * so a product's sections do not grow it. {@link renderPrNote} here takes
22
+ * either report and renders a `PrReport` with the pr loop's own renderer,
23
+ * so a plywood or sql-yodeler note is byte for byte what it was.
24
+ */
25
+ import { renderPrNote as renderPrLoopNote } from "./pr-loop.js";
26
+ import { GITHUB_COMMENT_LIMIT } from "./plan-summary.js";
27
+ import { activeProductWords, approveLine, overrideLine } from "./ci-product-words.js";
28
+ import { NEXT_RELEASE } from "./release-floors.js";
29
+ /** The first chant with the product plan note (#4810). */
30
+ export const PR_PLAN_NOTE_FLOOR = NEXT_RELEASE;
31
+ /** The read contract a {@link PrPlanNote} follows. */
32
+ export const PR_PLAN_NOTE_CONTRACT = 1;
33
+ const NOTE_WORDS = {
34
+ footer: "",
35
+ page: "report.html",
36
+ artifact: "chant-pr",
37
+ noReport: "Planned in [this run]({run}), which keeps no report artifact.",
38
+ anchors: { member: "member-{id}", group: "group-{id}" },
39
+ overrideKey: "ci.policy",
40
+ approvalRulesKey: "approval rules",
41
+ applyStage: "apply",
42
+ planFile: "plan.txt",
43
+ overrideOp: "policy-override",
44
+ };
45
+ /**
46
+ * The note for either report: a `PrReport` as the pr loop renders it, or a
47
+ * product's {@link PrPlanNote}.
48
+ */
49
+ export function renderPrNote(report, options = {}) {
50
+ return isPlanNote(report) ? renderPlanNote(report, options) : renderPrLoopNote(report, options);
51
+ }
52
+ /** Whether `report` is a product's plan note. */
53
+ export function isPlanNote(report) {
54
+ return typeof report === "object" && report !== null && report.kind === "plan-note";
55
+ }
56
+ const code = (s) => "`" + s.replaceAll("`", "'") + "`";
57
+ const codePoints = (s) => [...s].length;
58
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
59
+ const joinAnd = (xs) => (xs.length <= 1 ? (xs[0] ?? "") : `${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`);
60
+ const esc = (s) => s.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
61
+ const capital = (s) => s.charAt(0).toUpperCase() + s.slice(1);
62
+ const oneLine = (s) => s.split(/\s+/).join(" ");
63
+ /** A time as the note shows it: `2026-10-15 10:03 UTC`. */
64
+ const utc = (iso) => iso.replace("T", " ").replace(/:\d{2}(\.\d+)?Z$/, " UTC");
65
+ /**
66
+ * Lines as a `diff` block wants them, as Atlantis comments a plan: each
67
+ * line's change symbol (`+`, `-`, `~`, `-/+`, `+/-`) moves to the first
68
+ * column, so the forge colours additions and removals.
69
+ */
70
+ export function diffLines(lines) {
71
+ return lines.map((l) => l.replace(/^(\s+)(-\/\+|\+\/-|[-+~])(?= )/, "$2$1"));
72
+ }
73
+ /** A fenced `diff` block whose fence is longer than any run of backticks in the text. */
74
+ export function diffFence(lines) {
75
+ const body = lines.join("\n");
76
+ const longest = Math.max(0, ...[...body.matchAll(/`+/g)].map((m) => m[0].length));
77
+ const fence = "`".repeat(Math.max(3, longest + 1));
78
+ return `${fence}diff\n${body}\n${fence}\n`;
79
+ }
80
+ /** The waves marker: an HTML comment with no `<` or `>` in its JSON, so nothing in it ends the comment. */
81
+ export function planNoteMarker(name, waves) {
82
+ return `<!-- ${name} ${JSON.stringify(waves).replace(/</g, "\\u003c").replace(/>/g, "\\u003e")} -->`;
83
+ }
84
+ const ACTION_WORDS = { delete: "destroy", replace: "replace", refused: "refused to plan", forget: "forget", import: "import" };
85
+ function changeText(l) {
86
+ let t = l.count > 1 ? `${l.line} (x${l.count})` : l.line;
87
+ if (l.differsFrom)
88
+ t += l.differsIn?.length ? ` [differs from group ${l.differsFrom} in: ${l.differsIn.join(", ")}]` : ` [differs from group ${l.differsFrom}]`;
89
+ return t;
90
+ }
91
+ /**
92
+ * A product's plan note. Each group links to its anchor in the report and
93
+ * each named change to its unit's. Destroys, replacements and refusals come
94
+ * first and are never dropped for space before a group is. Over the limit,
95
+ * the units' whole plans go and the groups' diffs shrink to their attribute
96
+ * names, whichever saves the most first; then blocks are dropped, whole,
97
+ * from the end. A Cut line names what went.
98
+ */
99
+ export function renderPlanNote(report, options = {}) {
100
+ const words = options.words ?? activeProductWords();
101
+ const w = { ...NOTE_WORDS, ...options.note, anchors: { ...NOTE_WORDS.anchors, ...options.note?.anchors } };
102
+ const markerName = options.note?.marker ?? `${words.product}:waves`;
103
+ const [one, many] = words.noun;
104
+ const links = report.links ?? {};
105
+ const url = links.report ?? (links.run ? undefined : w.page);
106
+ const artifacts = links.artifacts === true;
107
+ const linkable = url !== undefined && !artifacts;
108
+ const to = (text, anchor) => (url === undefined ? text : `[${text}](${url}${anchor && !artifacts ? `#${anchor}` : ""})`);
109
+ const memberLink = (m) => to(code(m), w.anchors.member.replace("{id}", m));
110
+ const until = links.expires ? ` The links to the bucket work until ${utc(links.expires)}.` : "";
111
+ const full = url === undefined
112
+ ? w.noReport.replace("{run}", links.run ?? "")
113
+ : artifacts ? `The full report is \`${w.page}\` in the \`${w.artifact}\` artifact of [this run](${url}).` : `[Full report](${url})${until}`;
114
+ const fullReport = url === undefined ? "The full report" : artifacts ? `The full report, in the artifacts of [this run](${url}),` : `[The full report](${url})`;
115
+ const limit = options.limit ?? GITHUB_COMMENT_LIMIT;
116
+ const unitWord = report.unit === "instance" ? "instance" : one;
117
+ const unitWords = report.unit === "instance" ? "instances" : many;
118
+ const destroys = report.named.filter((n) => n.action === "delete" || n.action === "replace").length;
119
+ const refused = report.named.filter((n) => n.action === "refused").length;
120
+ const head = [`### ${words.product} ${report.stage}${report.wave !== undefined ? `, wave ${report.wave}` : ""}: ${code(report.head.slice(0, 12))}`, ""];
121
+ const parts = [plural(report.groups.length, "group"), plural(destroys, "destroy or replacement", "destroys or replacements")];
122
+ if (refused > 0)
123
+ parts.push(`${refused} refused`);
124
+ head.push(`${plural(report.units, unitWord, unitWords)}: ${parts.join(", ")}. ${full}`, "");
125
+ const t0 = report.totals;
126
+ if (t0 && t0.members > 0) {
127
+ const counts = [`${t0.add} to add`, `${t0.change} to change`, `${t0.destroy} to destroy`];
128
+ if (t0.forget > 0)
129
+ counts.push(`${t0.forget} to forget`);
130
+ head.push(`${counts.join(", ")} across ${plural(t0.members, one, many)}`, "");
131
+ }
132
+ if (report.nothing)
133
+ head.push(`This change reaches no ${one}, so nothing was planned.`, "");
134
+ for (const n of report.notices ?? [])
135
+ head.push(`> ${n}`, "");
136
+ for (const f of report.facts ?? []) {
137
+ const link = f.link ? (linkable ? `[${f.link.text}](${url}#${f.link.anchor})` : (f.link.plain ?? f.link.text)) : "";
138
+ head.push(`${f.text}${link}${f.after ?? ""}`, "");
139
+ }
140
+ const blocks = [];
141
+ const line = (text) => void blocks.push({ kind: "line", units: 0, text });
142
+ const sections = (at) => {
143
+ for (const s of report.sections ?? [])
144
+ if (s.at === at)
145
+ line(s.text);
146
+ };
147
+ sections("start");
148
+ if (report.named.length > 0) {
149
+ line(`**Destroys, replacements, refusals, imports and forgets (${report.named.length}):**\n\n`);
150
+ for (const n of report.named) {
151
+ const what = n.address ? `${n.member}: ${n.address}${n.deposed !== undefined ? ` (deposed ${n.deposed})` : ""}` : n.member;
152
+ const forced = n.forcedBy?.length ? `, forced by ${n.forcedBy.map(code).join(", ")}` : "";
153
+ const reason = n.reason ? `: ${oneLine(n.reason)}` : "";
154
+ line(`- ${to(code(what), w.anchors.member.replace("{id}", n.member))} (${n.word ?? ACTION_WORDS[n.action]}${forced})${reason}\n`);
155
+ }
156
+ line("\n");
157
+ }
158
+ const overrides = report.overrides ?? [];
159
+ if (overrides.length > 0) {
160
+ let t = `**Policy overrides (${overrides.filter((r) => r.override).length} of ${overrides.length} denied):**\n\n`;
161
+ for (const r of overrides) {
162
+ const o = r.override;
163
+ const rules = r.rules.map(code).join(", ") || "its rules";
164
+ t += o
165
+ ? `- ${memberLink(r.member)}: ${rules} overridden by ${o.by} at ${o.at}${o.sealed ? ", sealed" : ""}, for plan ${code(o.plan)}: ${oneLine(o.reason)}${report.planning ? `. ${w.applyStage} applies this plan; this run still fails it` : ""}\n`
166
+ : r.overriders.length === 0
167
+ ? `- ${memberLink(r.member)}: denied by ${rules}. ${w.overrideKey} names nobody who may override it\n`
168
+ : `- ${memberLink(r.member)}: denied by ${rules}. ${r.overriders.join(", ")} may override it once a ${w.applyStage} wave records the denial: ${code(overrideLine(words, { op: w.overrideOp, target: r.member, rules: r.rules, sign: report.sealed === true }))}\n`;
169
+ }
170
+ line(t + "\n");
171
+ }
172
+ const warnings = report.warnings ?? [];
173
+ if (warnings.length > 0) {
174
+ let t = `**Policy warnings (${warnings.length}), which fail nothing:**\n\n`;
175
+ for (const x of warnings)
176
+ t += `- ${memberLink(x.member)}: ${oneLine(x.text)}\n`;
177
+ line(t + "\n");
178
+ }
179
+ if (report.deferred?.length) {
180
+ let t = `**Planned once what they wait for applies (${report.deferred.length}):**\n\n`;
181
+ for (const d of report.deferred)
182
+ t += `- ${code(d.unit)}${d.after.length ? ` after ${d.after.map(code).join(", ")}` : ""}: ${d.why}${d.previewed ? " (previewed)" : ""}\n`;
183
+ line(t + "\n");
184
+ }
185
+ const envs = report.waves.some((x) => x.environments !== undefined);
186
+ const envHead = envs ? " Environments |" : "";
187
+ const envRule = envs ? "---|" : "";
188
+ const envCell = (x) => (envs ? ` ${x.environments?.length ? x.environments.join(", ") : "none"} |` : "");
189
+ const Units = capital(many);
190
+ if (report.waves.some((x) => x.digest !== undefined)) {
191
+ let t = `| Wave | ${Units} |${envHead} Digest of its changes | When it applies |\n|---|---|${envRule}---|---|\n`;
192
+ for (const x of report.waves) {
193
+ const again = x.replansAfter?.length ? `plans again once wave ${x.replansAfter.join(", ")} applies, then ` : "";
194
+ const approve = (digest) => approveLine(words, { op: words.op ?? "", gate: words.gateName.replace("{gate}", words.prGate).replace("{k}", String(x.number)), digest, sign: report.sealed === true });
195
+ const when = again
196
+ ? `${again}${x.waits ? "waits for an approval of that plan" : "applies"}`
197
+ : x.waits && x.digest ? `waits for an approval: ${code(approve(x.digest))}` : x.waits ? "waits for an approval" : "applies";
198
+ const unknownBy = x.unknownBy ?? [];
199
+ const policyRules = (x.policy?.rules ?? []).map(code).join(", ");
200
+ const by = x.waits && unknownBy.length
201
+ ? ` (since ${joinAnd(unknownBy.map(code))} ${unknownBy.length === 1 ? "reads" : "read"} a value unknown at plan time)`
202
+ : x.waits && x.heldByHooks?.length ? ` (a hook of ${x.heldByHooks.map(code).join(", ")} asks for one)`
203
+ : x.waits && x.policy?.outcome === "held" ? ` (held by ${policyRules})`
204
+ : x.policy?.outcome === "unattended" ? (x.waits ? ` (the policy allows it unattended, ${policyRules}, and something else holds it)` : ` without an approval: allowed unattended by ${policyRules}`) : "";
205
+ const rules = x.waits && x.approvalRules?.length ? `; ${w.approvalRulesKey}: ${x.approvalRules.map((r) => `${r.units.map(code).join(", ")} ${r.asks}`).join("; ")}` : "";
206
+ t += `| ${x.number} | ${x.units}${x.composed ? ", composed" : ""} |${envCell(x)} ${x.digest ? code(x.digest) : x.replansAfter?.length ? "after the re-plan" : "no change"} | ${when}${by}${rules} |\n`;
207
+ }
208
+ line(t + "\n");
209
+ const previews = report.previews ?? [];
210
+ head.push(planNoteMarker(markerName, { head: report.head, waves: report.waves.map((x) => ({ number: x.number, digest: x.digest ?? null, waits: x.waits === true })), ...(previews.length ? { previews } : {}) }), "");
211
+ }
212
+ else if (report.waves.length > 0) {
213
+ let t = `| Wave | ${Units} |${envHead} Set digest | Approval |\n|---|---|${envRule}---|---|\n`;
214
+ for (const x of report.waves)
215
+ t += `| ${x.number} | ${x.units}${x.composed ? ", composed" : ""} |${envCell(x)} ${x.replansAfter?.length ? `none yet: it plans again once wave ${x.replansAfter.join(", ")} applies` : x.setDigest ? code(x.setDigest.slice(0, 19)) : "none"} | ${x.approval ?? ""} |\n`;
216
+ line(t + "\n");
217
+ }
218
+ for (const p of report.previewed ?? []) {
219
+ const moved = p.moved.filter((u) => u.differences.length);
220
+ let t = moved.length
221
+ ? `**Wave ${p.wave} plans differently from the preview in pull request ${p.pullRequest} (${moved.length} of ${p.units}):**\n\n`
222
+ : `**Wave ${p.wave} plans as pull request ${p.pullRequest} previewed it (${plural(p.units, unitWord, unitWords)}).**\n\n`;
223
+ for (const u of moved)
224
+ for (const d of u.differences)
225
+ t += `- ${memberLink(u.unit)}: ${d}\n`;
226
+ line(t + "\n");
227
+ }
228
+ const linked = report.linked ?? [];
229
+ if (linked.length > 0) {
230
+ let t = `**Planned on the planned outputs of another ${one} (${linked.length}):**\n\n`;
231
+ for (const x of linked)
232
+ t += `- ${memberLink(x.member)} reads ${code(x.upstream)}${x.composed ? ", in the composed run" : ""}${x.unknown?.length ? `; ${x.unknown.map(code).join(", ")} known once it applies` : ""}\n`;
233
+ line(t + "\n");
234
+ }
235
+ sections("groups");
236
+ for (const g of report.groups) {
237
+ let title = `${to(`Group ${g.id}`, w.anchors.group.replace("{id}", g.id))}: ${plural(g.units.length, unitWord, unitWords)}`;
238
+ if (g.resource)
239
+ title += ` of ${code(g.resource)}`;
240
+ if (g.outlier)
241
+ title += " (outlier)";
242
+ title += g.noChanges ? ", no changes" : g.extends ? `, group ${g.extends}'s change plus` : g.units.length > 1 ? ", identical change" : ", change";
243
+ if (g.recurring)
244
+ title += ", on every run";
245
+ const heading = `#### ${title}\n\n`;
246
+ const names = g.changes.length > 0 ? "```\n" + g.changes.map(changeText).join("\n") + "\n```\n\n" : "";
247
+ const shown = g.units.slice(0, 20).map(code).join(", ");
248
+ const members = `${capital(unitWords)}: ${shown}${g.units.length > 20 ? `, and ${g.units.length - 20} more in the report` : ""}\n\n`;
249
+ const diff = g.noChanges || g.recurring ? undefined : g.diff;
250
+ if (!diff) {
251
+ blocks.push({ kind: "group", units: g.units.length, text: heading + names + members });
252
+ continue;
253
+ }
254
+ let t = heading;
255
+ if (g.units.length > 1)
256
+ t += `As ${code(diff.unit)} plans it:\n\n`;
257
+ t += diffFence(diffLines(diff.lines)) + "\n";
258
+ const differs = g.changes.filter((l) => l.differsFrom);
259
+ for (const l of differs)
260
+ t += `- ${code(l.line)} differs from group ${l.differsFrom}${l.differsIn?.length ? ` in ${l.differsIn.map(code).join(", ")}` : ""}.\n`;
261
+ const varies = g.varies ?? [];
262
+ if (varies.length > 0)
263
+ t += `${differs.length > 0 ? "- " : ""}Values differ between its ${unitWords} in ${varies.map(code).join(", ")}.\n`;
264
+ if (differs.length > 0 || varies.length > 0)
265
+ t += "\n";
266
+ blocks.push({ kind: "group", units: g.units.length, text: t + members, short: heading + names + members });
267
+ }
268
+ sections("end");
269
+ // A unit's plan file: the link given for it, else beside the report page when the note links the page itself.
270
+ const planLink = (member) => {
271
+ const p = report.plans?.find((x) => x.member === member);
272
+ if (p?.url)
273
+ return p.url;
274
+ if (!linkable || !p?.file)
275
+ return undefined;
276
+ const bare = url.split("#")[0];
277
+ if (bare.includes("?") || !(bare === w.page || bare.endsWith(`/${w.page}`)))
278
+ return undefined;
279
+ return bare.slice(0, bare.length - w.page.length) + p.file.split("/").map(encodeURIComponent).join("/");
280
+ };
281
+ let first = true;
282
+ for (const p of report.plans ?? []) {
283
+ const link = planLink(p.member);
284
+ let t = first ? `**Each ${one}'s plan:**\n\n` : "";
285
+ first = false;
286
+ t += `<details><summary><code>${esc(p.member)}</code>${p.totals ? `: ${esc(p.totals)}` : ""}</summary>\n\n`;
287
+ t += diffFence(diffLines(p.text.replace(/\r\n/g, "\n").replace(/^(\s*\n)+/, "").replace(/\s+$/, "").split("\n"))) + "\n";
288
+ if (link)
289
+ t += `[${w.planFile}](${link})\n\n`;
290
+ t += "</details>\n\n";
291
+ blocks.push({ kind: "plan", units: 0, member: p.member, text: t });
292
+ }
293
+ const top = head.join("\n") + "\n";
294
+ const foot = w.footer ? `\n${w.footer}\n` : "";
295
+ const all = top + blocks.map((b) => b.text).join("") + foot;
296
+ if (codePoints(all) <= limit)
297
+ return all;
298
+ const cut = { plans: [], diffs: 0, groups: 0, units: 0, lines: 0 };
299
+ const notice = () => {
300
+ const out = [];
301
+ if (cut.plans.length > 0) {
302
+ const named = cut.plans.slice(0, 20).map((m) => {
303
+ const link = planLink(m);
304
+ return link ? `[${code(m)}](${link})` : code(m);
305
+ });
306
+ const more = cut.plans.length - named.length;
307
+ out.push(`the whole plans of ${plural(cut.plans.length, one, many)} (${named.join(", ")}${more > 0 ? `, and ${more} more` : ""})`);
308
+ }
309
+ if (cut.groups > 0)
310
+ out.push(`${plural(cut.groups, "group")} (${plural(cut.units, unitWord, unitWords)})`);
311
+ if (cut.lines > 0)
312
+ out.push(plural(cut.lines, "line"));
313
+ const clauses = [];
314
+ if (out.length > 0)
315
+ clauses.push(`leaves out ${joinAnd(out)}`);
316
+ if (cut.diffs > 0)
317
+ clauses.push(`shows ${cut.diffs === 1 ? "one group" : `${cut.diffs} groups`} by attribute name, without the diff`);
318
+ return `**Cut:** this note ${clauses.join(" and ")}, to stay within ${limit} characters. ${fullReport} has all of it${report.plans !== undefined ? `, and each ${one}'s ${w.planFile} the whole plan` : ""}.\n`;
319
+ };
320
+ const size = (b) => codePoints(b.text);
321
+ let used = codePoints(all);
322
+ const over = () => used + codePoints(notice()) > limit;
323
+ // Whole plans and group diffs, whichever saves the most first: a whole plan before a diff that saves as much, the later of two alike first.
324
+ const candidates = blocks
325
+ .map((b, i) => ({ i, plan: b.kind === "plan", saves: b.kind === "plan" ? size(b) : b.short !== undefined ? size(b) - codePoints(b.short) : 0 }))
326
+ .filter((c) => c.saves > 0)
327
+ .sort((a, b) => b.saves - a.saves || Number(b.plan) - Number(a.plan) || b.i - a.i);
328
+ const gone = new Set();
329
+ for (const c of candidates) {
330
+ if (!over())
331
+ break;
332
+ const b = blocks[c.i];
333
+ if (c.plan) {
334
+ used -= size(b);
335
+ gone.add(c.i);
336
+ }
337
+ else {
338
+ used += codePoints(b.short) - size(b);
339
+ b.text = b.short;
340
+ b.short = undefined;
341
+ cut.diffs++;
342
+ }
343
+ }
344
+ cut.plans.push(...blocks.filter((_, i) => gone.has(i)).map((b) => b.member));
345
+ for (let i = blocks.length - 1; i >= 0; i--)
346
+ if (gone.has(i))
347
+ blocks.splice(i, 1);
348
+ // Then whole blocks from the end: groups, and last the destroys.
349
+ while (blocks.length > 0 && over()) {
350
+ const b = blocks.pop();
351
+ used -= size(b);
352
+ if (b.kind === "group") {
353
+ cut.groups++;
354
+ cut.units += b.units;
355
+ }
356
+ else if (b.kind === "plan")
357
+ cut.plans.unshift(b.member);
358
+ else
359
+ cut.lines++;
360
+ }
361
+ return top + blocks.map((b) => b.text).join("") + notice() + foot;
362
+ }