@bongos/core 1.19.607 → 1.19.608

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.
package/.bongos-core.json CHANGED
@@ -2,22 +2,22 @@
2
2
  "artifact": "bongos-core",
3
3
  "manifest_schema": 1,
4
4
  "generator": "scripts/gds/package-core.js",
5
- "core_version": "1.19.607",
6
- "core_contract": "1.19.607",
7
- "source_commit": "a2068c523c1b4845be5d94b006e95f1d213717ed",
5
+ "core_version": "1.19.608",
6
+ "core_contract": "1.19.608",
7
+ "source_commit": "f112591192f3c6ab69e73f3703bd2f2e2f6f746e",
8
8
  "source_ref": "HEAD",
9
- "built_at": "2026-09-08T23:51:21.550Z",
9
+ "built_at": "2026-09-09T00:10:53.531Z",
10
10
  "redaction": {
11
11
  "model": "docs-redacted+functional-verbatim",
12
12
  "docs_redacted": 458,
13
13
  "agent_docs_stubbed": 24,
14
- "functional_verbatim": 2078,
14
+ "functional_verbatim": 2080,
15
15
  "rules": 3,
16
16
  "gate_literals": 3,
17
17
  "gate": "passed"
18
18
  },
19
- "file_count": 2560,
20
- "tree_sha256": "1e9d9d267269d69cf9e5cf933d04757d0d20961047ab7f9cd2bfed3cbc721bd7",
19
+ "file_count": 2562,
20
+ "tree_sha256": "53d8a68171007b0b61fd34bff5aaf036110d1cb584228a250f606a4300cabf7d",
21
21
  "files": [
22
22
  {
23
23
  "path": ".claude/skills/blocker-review/SKILL.md",
@@ -2732,7 +2732,7 @@
2732
2732
  {
2733
2733
  "path": "docs/module-api-changelog.md",
2734
2734
  "mode": "0000644",
2735
- "sha256": "69fd2cbffee9e8396923dd5984eafe6b647809c1695b87f1d5d0543748187904"
2735
+ "sha256": "afddf5268d6326d2d128069afcb0e0ed2bc06cd6040bfa7e7f8531227a9ca891"
2736
2736
  },
2737
2737
  {
2738
2738
  "path": "docs/modules-contract.md",
@@ -7632,12 +7632,12 @@
7632
7632
  {
7633
7633
  "path": "package-lock.json",
7634
7634
  "mode": "0000644",
7635
- "sha256": "65e25f20c4196fe1064184914552bf3ffbd5fca85db7c6115084d5d5b1e9a210"
7635
+ "sha256": "021b578efabb07b661729dd8120695a9ff976b409e355f1ffd35e3c1f3f22a40"
7636
7636
  },
7637
7637
  {
7638
7638
  "path": "package.json",
7639
7639
  "mode": "0000644",
7640
- "sha256": "bfbaa26f7eb3571a6c520e890c2c55c8558643fc195d4a3e963896a22f8faef6"
7640
+ "sha256": "22dc9b83baf7d5765ca7ab8ec400e15e0ac5ada03b98895c33f9bd5d4dc0cc62"
7641
7641
  },
7642
7642
  {
7643
7643
  "path": "public-docs/index.html",
@@ -8117,7 +8117,7 @@
8117
8117
  {
8118
8118
  "path": "scripts/gds/gds-literal-scan.js",
8119
8119
  "mode": "0000644",
8120
- "sha256": "3f873da74a012f73e30e659f070b3476eda81ac55f802913307494a645d8ee88"
8120
+ "sha256": "30a05f9d8d476e83740f0630e17d1accc3e29d67cebfc74d19abfeae6608e514"
8121
8121
  },
8122
8122
  {
8123
8123
  "path": "scripts/gds/gen-api-client.js",
@@ -8494,6 +8494,11 @@
8494
8494
  "mode": "0000644",
8495
8495
  "sha256": "06ad6a69304cfc66509f4ab283e7f76196ac7edcac97f8eba55ea3ab92c3eecb"
8496
8496
  },
8497
+ {
8498
+ "path": "scripts/gds/rename-ledger-prose.js",
8499
+ "mode": "0000644",
8500
+ "sha256": "f73e495ab63fbca755e652d284e378d9b2afef67fe43c4c5a66e2962c92cef1d"
8501
+ },
8497
8502
  {
8498
8503
  "path": "scripts/gds/render-ideas.js",
8499
8504
  "mode": "0000644",
@@ -9357,7 +9362,7 @@
9357
9362
  {
9358
9363
  "path": "src/module-api.js",
9359
9364
  "mode": "0000644",
9360
- "sha256": "504ef9943bde8940c3e32850ffb6206a3a2f0869cbd293e3482e7309ea0e3608"
9365
+ "sha256": "d5e97cf6a460b1d69da907cfdfa0acf06bbb010067bf23f07de1940dcf36336a"
9361
9366
  },
9362
9367
  {
9363
9368
  "path": "src/module-loader/catalog.js",
@@ -12014,6 +12019,11 @@
12014
12019
  "mode": "0000644",
12015
12020
  "sha256": "2cbc4981c0f33a6597445f268055d10107b6696be4de42e5790e7efefc087edd"
12016
12021
  },
12022
+ {
12023
+ "path": "tests/rename_ledger_prose.mjs",
12024
+ "mode": "0000644",
12025
+ "sha256": "39eaa32121eae07fa7f508d60324e896e4c1b98c53ff390bb8bdca4b952c874f"
12026
+ },
12017
12027
  {
12018
12028
  "path": "tests/render_prefs.mjs",
12019
12029
  "mode": "0000644",
@@ -1663,5 +1663,7 @@ is load-bearing: the script throws rather than guess if it is missing, and
1663
1663
  landed since 1.19.605 with no explicit bump. run 34291868670. (task 1002620)
1664
1664
  1.19.607 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
1665
1665
  landed since 1.19.606 with no explicit bump. run 34292436274. (task 1002620)
1666
+ 1.19.608 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
1667
+ landed since 1.19.607 with no explicit bump. run 34293848928. (task 1002620)
1666
1668
  ---------------------------------------------------------------------------
1667
1669
  ```
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.19.607",
3
+ "version": "1.19.608",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bongos/core",
9
- "version": "1.19.607",
9
+ "version": "1.19.608",
10
10
  "license": "AGPL-3.0-or-later",
11
11
  "dependencies": {
12
12
  "express": "^4.21.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.19.607",
3
+ "version": "1.19.608",
4
4
  "description": "Cloud Bongos — the AI-first build platform core (GDS + platform surfaces + module system), installed as a versioned dependency (ADR 0108).",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "main": "src/platform-server.js",
@@ -76,6 +76,12 @@ const GDS_RULE_FILES = new Set([
76
76
  'scripts/gds/rename-history-check.js',
77
77
  'tests/rename_history_restraint.mjs',
78
78
  'config/rename-history-baseline.json',
79
+ // The LEDGER pass (task 1003698, criterion C4). It has to spell out every
80
+ // identifier it protects and every phrase shape it rewrites, so it names the
81
+ // literal more often than any other file in the tree — and its test names it
82
+ // once per case. Same exemption, same reason.
83
+ 'scripts/gds/rename-ledger-prose.js',
84
+ 'tests/rename_ledger_prose.mjs',
79
85
  ]);
80
86
 
81
87
  // A version id is a row key, not vocabulary. Stripped before matching so it is
@@ -0,0 +1,482 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // rename-ledger-prose.js — criterion C4 of goal 1000073, "the live ledger reads
4
+ // Bongos" (task 1003698).
5
+ //
6
+ // WHAT IS LEFT TO RENAME, AND WHY IT IS THE LEDGER. The code and the API were
7
+ // renamed long ago (src/gds/ is src/bongos/, /api/bongos is canonical). What
8
+ // still says the old name to a live reader is the PROSE INSIDE DB ROWS — goal
9
+ // and task titles and descriptions, read every day in the hall and by every
10
+ // agent that claims work.
11
+ //
12
+ // THE ONE RULE, inherited from the goal: rename what the project says about
13
+ // itself GOING FORWARD; leave what it recorded about its PAST. Its enforcement
14
+ // is its sibling scripts/gds/rename-history-check.js (criterion C5), which
15
+ // fails the build if the frozen record is erased. This script is the other
16
+ // direction, and it is deliberately narrow about what it will touch.
17
+ //
18
+ // THREE KINDS OF OCCURRENCE, and only ONE of them is this script's business.
19
+ // Measured over all 3,369 task rows on 2026-09-07 — the goal's own estimate of
20
+ // ~119 rows was taken before this split was understood and is low by ~2.4x:
21
+ //
22
+ // 1. FROZEN ARCHIVES (157 rows). Anything whose version_id is GDS-V3 or
23
+ // GDS-V4. Those versions shipped; their rows are the record. Skipped by
24
+ // version, not by heuristic.
25
+ //
26
+ // 2. IDENTIFIERS (77 rows carry nothing else). `GDS_TOKEN`, `GDS_API_BASE`,
27
+ // `GDS_BRANDING_FILE`, `MEDUSA_GDS_ONLY`, the `gds_session` cookie, the
28
+ // `scripts/gds/` path, and `/api/gds`. These are NOT vocabulary — they are
29
+ // the true names of things that still exist under those names. Renaming
30
+ // the prose would make the ledger LIE about what the code does. The env
31
+ // names and paths belong to criterion C3, which renames the THING and the
32
+ // prose together, behind a fallback release; `/api/gds` is a permanent
33
+ // alias and is never renamed at all. So every one of these is masked out
34
+ // before substitution and restored afterwards, byte for byte.
35
+ //
36
+ // 3. VOCABULARY — the acronym used as a word: "the GDS", "GDS tasks",
37
+ // "GDS-internal", "the GDS DB". This, and only this, is what C4 rewrites.
38
+ //
39
+ // WHY A REVIEWED PROPOSAL AND NOT A FIND-REPLACE. "the GDS exists to support
40
+ // builders" must become "Bongos exists to support builders" — the article has
41
+ // to go — while "the GDS database" keeps it. No regex settles that reliably, so
42
+ // the rules below handle the shapes that recur and EXEMPT_ROWS/OVERRIDES carry
43
+ // the ones a rule would get wrong. The default mode prints every proposed diff
44
+ // and changes nothing; --apply is a separate, deliberate act.
45
+ //
46
+ // WRITES GO THROUGH THE API, NOT SQL. The builder box holds no DATABASE_URL and
47
+ // no psql by design, and PATCH /tasks/:id and PATCH /goals/:id are permission-
48
+ // checked and land every edit in audit_log. That is a better audit trail than
49
+ // hand-run SQL, which was the shape this task was originally filed with.
50
+ //
51
+ // Usage:
52
+ // node scripts/gds/rename-ledger-prose.js # dry run: every proposed diff
53
+ // node scripts/gds/rename-ledger-prose.js --summary # counts only
54
+ // node scripts/gds/rename-ledger-prose.js --json
55
+ // node scripts/gds/rename-ledger-prose.js --apply # write, one PATCH per row
56
+
57
+ const { execFileSync } = require('node:child_process');
58
+ const path = require('node:path');
59
+
60
+ // ONE detector, shared with the C2 ratchet. GDS_VERSION_ID_RE is the rule that
61
+ // says a version id is a row key rather than vocabulary; PINNED_VERSION_IDS in
62
+ // rename-history-check.js is the list those keys are pinned to. Importing both
63
+ // is what stops this pass and the two gates around it from disagreeing about
64
+ // what counts as history — a second, divergent copy is the failure the task
65
+ // named explicitly.
66
+ const { GDS_VERSION_ID_RE } = require('./gds-literal-scan.js');
67
+ const { PINNED_VERSION_IDS } = require('./rename-history-check.js');
68
+
69
+ const ROOT = path.resolve(__dirname, '..', '..');
70
+
71
+ // Versions whose rows ARE the record. Not a heuristic — a list.
72
+ // Derived from the C5 pin, not re-typed. If a version id is ever added to the
73
+ // frozen record, it becomes frozen HERE in the same commit rather than a
74
+ // release later.
75
+ const FROZEN_VERSION_IDS = new Set(PINNED_VERSION_IDS);
76
+
77
+ // Rows that STATE the rule, and so must keep naming what they retire. The
78
+ // ledger's analogue of GDS_RULE_FILES in gds-literal-scan.js: a goal that says
79
+ // "finish the GDS→Bongos rename" cannot be rewritten to say "finish the
80
+ // Bongos→Bongos rename" without becoming nonsense.
81
+ const EXEMPT_ROWS = new Set([
82
+ 'goal:1000073', // Finish the GDS→Bongos rename — this goal
83
+ 'goal:1000010', // "GDS core modularization (Config B)" — a shipped goal's own title
84
+ 'task:1001933', // Part B2: rename internal gds→bongos names
85
+ 'task:1003698', // this task
86
+ ]);
87
+
88
+ // ---------- the identifier mask ----------
89
+
90
+ // Longest / most specific first: GDS_API_BASE must be consumed before a bare
91
+ // GDS could match inside it. Each is a REAL NAME that still exists, so it is
92
+ // removed from the text before substitution and put back byte-for-byte after.
93
+ const IDENTIFIER_PATTERNS = [
94
+ // IMPORTED, not re-declared. The version-id rule is the one exclusion this
95
+ // script genuinely shares with the C2 ratchet, and two copies of it would
96
+ // drift the moment either side learned about a new version id. The ratchet's
97
+ // other exclusions are PATH-based (docs/adr, migrations) and have no meaning
98
+ // for a database row, so they are deliberately not pulled in here.
99
+ GDS_VERSION_ID_RE,
100
+ /\/api\/gds\b/gi, // the permanent alias (src/bongos/api-prefix.js)
101
+ /\bMEDUSA_GDS_[A-Z0-9_]+/g,
102
+ /\bGDS_[A-Z0-9_]+/g, // env names — criterion C3, with a fallback release
103
+ /\bOTB_GDS_[A-Z0-9_]+/g,
104
+ /\bgds_session\b/gi, // cookie name — C3
105
+ /\bgds-session(?:\.json)?\b/gi, // the CLI session file — C3
106
+ /\bscripts\/gds\b/gi, // paths — C3
107
+ /\bsrc\/gds\b/gi,
108
+ /\bapi\/gds\b/gi,
109
+ ];
110
+
111
+ const SENTINEL = 'MASK';
112
+
113
+ // maskIdentifiers — replace every real name with an opaque token, returning the
114
+ // masked text plus the list needed to restore it. Exported so the test can
115
+ // assert the round trip is lossless: an identifier that came back changed would
116
+ // be a silent corruption of the ledger, not a visible failure.
117
+ function maskIdentifiers(text) {
118
+ const masks = [];
119
+ let out = text;
120
+ for (const re of IDENTIFIER_PATTERNS) {
121
+ out = out.replace(re, (m) => {
122
+ masks.push(m);
123
+ return `${SENTINEL}${masks.length - 1}`;
124
+ });
125
+ }
126
+ return { masked: out, masks };
127
+ }
128
+
129
+ function unmask(masked, masks) {
130
+ return masked.replace(/MASK(\d+)/g, (_, i) => masks[Number(i)]);
131
+ }
132
+
133
+ // ---------- mention vs use ----------
134
+
135
+ // THE FAILURE THIS PREVENTS, found by reading all 147 proposed diffs before
136
+ // applying any of them. Some rows do not USE the acronym as a name, they MENTION
137
+ // it as a token — and renaming a mention destroys the sentence:
138
+ //
139
+ // "GDS is a legacy term inherited from Primea" → "Bongos is a legacy term…" (now false)
140
+ // "the primer still says GDS (should be Bongos)" → "…says Bongos (should be Bongos)"
141
+ // "fails the build on a NEW literal `GDS`" → the gate's own rule, erased
142
+ // "records the bongos-as-GDS-successor intent" → nonsense
143
+ // "Nightly pg_dump of Cloud Bongos GDS Postgres" → "Cloud Bongos Bongos Postgres"
144
+ //
145
+ // This is the same principle as GDS_RULE_FILES in gds-literal-scan.js, applied
146
+ // to rows instead of files: text that STATES the rule has to be able to name
147
+ // what it retires. The bias is deliberate — a match SKIPS the row and reports
148
+ // it for a human, so the cost of a false positive is a row left alone and
149
+ // listed, never a corrupted one. Acceptance criterion 4 of the task asks for
150
+ // exactly that list.
151
+ const MENTION_MARKERS = [
152
+ /["'`«]\s*GDS\s*["'`»]/, // quoted or backticked: the token itself
153
+ /\bliteral\s+`?GDS/i,
154
+ /\bcalled\s+GDS\b/i,
155
+ /\bsays?\s+GDS\b/i,
156
+ /\bnamed?\s+GDS\b/i,
157
+ /\bterm\b[^.\n]{0,40}GDS/i,
158
+ /GDS[^.\n]{0,40}\blegacy\b/i,
159
+ /\blegacy\b[^.\n]{0,40}GDS/i,
160
+ /GDS\s*(?:→|->|to)\s*Bongos/i, // the rename, written out
161
+ /(?:PMS|Medusa)\s*(?:→|->)\s*GDS/i, // the PREVIOUS rename, which is history
162
+ /GDS-successor/i,
163
+ /\brename\b[^.\n]{0,60}GDS|GDS[^.\n]{0,60}\brename\b/i,
164
+ ];
165
+
166
+ // mentionsRatherThanUses — true when the row is talking ABOUT the word.
167
+ function mentionsRatherThanUses(text) {
168
+ return MENTION_MARKERS.some((re) => re.test(text));
169
+ }
170
+
171
+ // ---------- the vocabulary rules ----------
172
+
173
+ // THE ARTICLE PROBLEM, and why the default is to KEEP it.
174
+ //
175
+ // "the GDS router" must become "the Bongos router" — the acronym is modifying a
176
+ // noun. "the GDS knows everything" must become "Bongos knows everything" — the
177
+ // acronym IS the subject and the article has to go. Get it backwards in the
178
+ // first case and you write "mounted outside Bongos router", which is broken
179
+ // English; get it backwards in the second and you write "the Bongos knows
180
+ // everything", which merely reads oddly.
181
+ //
182
+ // So the asymmetry decides the default: KEEP the article unless the very next
183
+ // word is a finite verb. Dropping wrongly breaks a sentence; keeping wrongly
184
+ // never does. The verb list is taken from the 41 distinct "<determiner> GDS
185
+ // <word>" shapes actually present in the corpus, not invented.
186
+ const ARTICLE_DROP_VERBS = [
187
+ 'is', 'are', 'was', 'were', 'has', 'have', 'holds', 'knows', 'pushes', 'pulls',
188
+ 'exists', 'builds', 'says', 'records', 'enforces', 'sits', 'lives', 'treats',
189
+ 'expects', 'refuses', 'returns', 'becomes', 'remains', 'auto-posts',
190
+ ];
191
+ // The same reasoning covers what follows a bare mention: a preposition, a
192
+ // conjunction or an opening bracket all mean the acronym was the noun itself
193
+ // ("poll the GDS for the next task", "its home is the GDS (goal + task rows)").
194
+ const ARTICLE_DROP_FOLLOWERS = ['for', 'by', 'and', 'or', 'today', 'then', 'itself'];
195
+ const ARTICLE_DROP_RE = new RegExp(
196
+ `\\b[Tt]he\\s+GDS\\b(?=\\s+(?:${ARTICLE_DROP_VERBS.join('|')}|${ARTICLE_DROP_FOLLOWERS.join('|')})\\b|\\s*[(,.;:])`,
197
+ 'g',
198
+ );
199
+
200
+ // rewriteVocabulary — the substitution, on ALREADY-MASKED text. Pure, and
201
+ // exported so every rule has a test that names its own input.
202
+ function rewriteVocabulary(masked) {
203
+ let s = masked;
204
+ // 0. the product name already carries the word — "Cloud Bongos GDS Postgres"
205
+ // must not become "Cloud Bongos Bongos Postgres".
206
+ s = s.replace(/\bCloud Bongos GDS\b/g, 'Cloud Bongos');
207
+ // 1. "the GDS <verb>" — the acronym is the subject, so the article goes with
208
+ // the rename rather than being left stranded in front of it.
209
+ s = s.replace(ARTICLE_DROP_RE, 'Bongos');
210
+ // 2. everything else: the acronym as a name or a modifier. Any determiner in
211
+ // front of it is left exactly where it was ("the Bongos router").
212
+ s = s.replace(/\bGDS\b/g, 'Bongos');
213
+ return s;
214
+ }
215
+
216
+ // rewrite — the whole pipeline for one string: mask the real names, rename the
217
+ // vocabulary, restore the real names. Returns null when nothing changed.
218
+ function rewrite(text) {
219
+ if (!text || !text.includes('GDS')) return null;
220
+ const { masked, masks } = maskIdentifiers(text);
221
+ if (!masked.includes('GDS')) return null; // identifiers only — not this script's business
222
+ const out = unmask(rewriteVocabulary(masked), masks);
223
+ return out === text ? null : out;
224
+ }
225
+
226
+ // ---------- row selection ----------
227
+
228
+ // EDITABLE tells each kind which prose columns the API will accept, so the
229
+ // script cannot propose an edit the route would reject.
230
+ const EDITABLE = {
231
+ task: ['title', 'description'],
232
+ goal: ['title', 'subtitle', 'description'],
233
+ };
234
+
235
+ // proposeForRow — the pure half of selection: given one row, what would change.
236
+ function proposeForRow(kind, row) {
237
+ const key = `${kind}:${row.id}`;
238
+ if (EXEMPT_ROWS.has(key)) return { skipped: 'exempt', kind, id: String(row.id), key, title: row.title };
239
+ if (FROZEN_VERSION_IDS.has(row.version_id)) return null; // frozen archive — silent, it is the whole point
240
+
241
+ const whole = EDITABLE[kind].map((c) => row[c] || '').join('\n');
242
+ if (!whole.includes('GDS')) return null;
243
+
244
+ const patch = {};
245
+ for (const col of EDITABLE[kind]) {
246
+ const next = rewrite(row[col]);
247
+ if (next !== null) patch[col] = next;
248
+ }
249
+ if (!Object.keys(patch).length) return null; // identifiers only
250
+
251
+ // Both checks below run AFTER the patch is computed, so a row is only
252
+ // reported as needing a human when it would OTHERWISE have been rewritten.
253
+ // Order matters for honesty: testing the raw text first would flag rows whose
254
+ // only occurrences are protected identifiers, i.e. rows with nothing wrong.
255
+ if (mentionsRatherThanUses(whole)) {
256
+ return { skipped: 'mentions-the-word', kind, id: String(row.id), key, title: row.title };
257
+ }
258
+
259
+ // A goal that is no longer open is a completed record, and the server says so
260
+ // itself: PATCH /goals/:id answers 409 goal_not_open on anything but `open`.
261
+ // That rule and this goal's rule are the same rule — "leave what it recorded
262
+ // about its past" — so this is not an obstacle to be worked around by
263
+ // reopening the goal. Reported rather than skipped silently: those rows do
264
+ // still read the old way, and a human should know which ones.
265
+ if (kind === 'goal' && row.status && row.status !== 'open') {
266
+ return { skipped: `goal-${row.status}`, kind, id: String(row.id), key, title: row.title };
267
+ }
268
+ return { kind, id: String(row.id), key, title: row.title, patch, before: row };
269
+ }
270
+
271
+ // ---------- the API (collectors; kept out of the pure half) ----------
272
+
273
+ function api(method, urlPath, body) {
274
+ const args = [path.join(ROOT, 'scripts', 'gds', 'api.js'), method, urlPath];
275
+ const opts = { cwd: ROOT, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 };
276
+ if (body !== undefined) {
277
+ args.push('--body-file', '-');
278
+ opts.input = JSON.stringify(body);
279
+ }
280
+ const out = execFileSync('node', args, opts);
281
+ const brace = out.indexOf('{');
282
+ return brace === -1 ? {} : JSON.parse(out.slice(brace));
283
+ }
284
+
285
+ // The list route caps at 1000 and orders oldest-first, so the newest rows are
286
+ // on the LAST page. Paging is not optional here: stopping at one page would
287
+ // silently skip everything filed recently, which is exactly the class of bug
288
+ // filed as task 1003699 against sequence.js.
289
+ function allTasks() {
290
+ const rows = [];
291
+ let offset = 0;
292
+ for (;;) {
293
+ const q = offset ? `/api/gds/tasks?limit=1000&offset=${offset}` : '/api/gds/tasks?limit=1000';
294
+ const page = api('GET', q).tasks || [];
295
+ rows.push(...page);
296
+ if (page.length < 1000) break;
297
+ offset += 1000;
298
+ }
299
+ return rows;
300
+ }
301
+
302
+ function allGoals() {
303
+ const out = [];
304
+ for (const version of ['BONGOS-V1', 'CB-V1']) {
305
+ const r = api('GET', `/api/gds/goals?version=${version}`);
306
+ for (const g of r.goals || []) out.push(g);
307
+ }
308
+ return out;
309
+ }
310
+
311
+ function collectProposals() {
312
+ const proposals = [];
313
+ const skipped = [];
314
+ const take = (p) => {
315
+ if (!p) return;
316
+ (p.skipped ? skipped : proposals).push(p);
317
+ };
318
+ for (const t of allTasks()) take(proposeForRow('task', t));
319
+ for (const g of allGoals()) take(proposeForRow('goal', g));
320
+ return { proposals, skipped };
321
+ }
322
+
323
+ // ---------- write pacing ----------
324
+
325
+ // The server allows 30 writes per minute per IP (PER_IP_LIMIT in
326
+ // src/bongos/middleware/rate-limit.js). Learned the expensive way: the first
327
+ // --apply of this script fired 123 PATCHes flat out, landed the first ~60, and
328
+ // took a 429 for every one after that — leaving the ledger half-renamed, which
329
+ // is the one outcome worse than not starting. Pace under the limit and retry
330
+ // what still bounces, so a run either finishes or says exactly what it missed.
331
+ const WRITES_PER_MIN = 25; // under 30, with headroom for the reads
332
+ const WRITE_SPACING_MS = Math.ceil(60000 / WRITES_PER_MIN);
333
+ const MAX_RETRIES = 4;
334
+
335
+ // A synchronous sleep, because the whole script is execFileSync-shaped and one
336
+ // async conversion would buy nothing here.
337
+ function sleep(ms) {
338
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
339
+ }
340
+
341
+ // patchWithRetry — one write, retried on 429 with a widening backoff. Any other
342
+ // error is returned immediately: a validation failure will not fix itself, and
343
+ // retrying it just burns the rate budget the remaining rows need.
344
+ function patchWithRetry(url, body) {
345
+ let wait = WRITE_SPACING_MS * 2;
346
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt += 1) {
347
+ try {
348
+ api('PATCH', url, body);
349
+ return { ok: true };
350
+ } catch (e) {
351
+ // api.js prints the status line to STDOUT and exits non-zero, so the
352
+ // 429 is in e.stdout, not in e.message. Reading only the message would
353
+ // silently turn every rate-limit into a permanent failure.
354
+ const message = `${e.message || ''}\n${e.stdout || ''}\n${e.stderr || ''}`;
355
+ if (!message.includes('429') || attempt === MAX_RETRIES) {
356
+ return { ok: false, message: message.slice(0, 300) };
357
+ }
358
+ console.log(` rate-limited, waiting ${Math.round(wait / 1000)}s`);
359
+ sleep(wait);
360
+ wait *= 2;
361
+ }
362
+ }
363
+ return { ok: false, message: 'unreachable' };
364
+ }
365
+
366
+ // ---------- reporting ----------
367
+
368
+ // changedLines — only the lines that actually differ, so a 4,000-character task
369
+ // description does not drown the one line under review.
370
+ function changedLines(before, after) {
371
+ const b = String(before).split('\n');
372
+ const a = String(after).split('\n');
373
+ const out = [];
374
+ for (let i = 0; i < Math.max(b.length, a.length); i += 1) {
375
+ if (b[i] !== a[i]) out.push({ before: b[i], after: a[i] });
376
+ }
377
+ return out;
378
+ }
379
+
380
+ function printProposals(proposals) {
381
+ for (const p of proposals) {
382
+ console.log(`\n${p.kind} ${p.id} — ${String(p.title).slice(0, 76)}`);
383
+ for (const [col, next] of Object.entries(p.patch)) {
384
+ for (const line of changedLines(p.before[col], next)) {
385
+ console.log(` ${col}`);
386
+ console.log(` - ${String(line.before).trim().slice(0, 200)}`);
387
+ console.log(` + ${String(line.after).trim().slice(0, 200)}`);
388
+ }
389
+ }
390
+ }
391
+ }
392
+
393
+ function summarize(proposals) {
394
+ const byKind = {};
395
+ let edits = 0;
396
+ for (const p of proposals) {
397
+ byKind[p.kind] = (byKind[p.kind] || 0) + 1;
398
+ edits += Object.keys(p.patch).length;
399
+ }
400
+ return { rows: proposals.length, edits, byKind };
401
+ }
402
+
403
+ // ---------- CLI ----------
404
+
405
+ function printSkipped(skipped) {
406
+ if (!skipped.length) return;
407
+ console.log(`\nLEFT FOR A HUMAN — ${skipped.length} row(s) that would have been rewritten wrongly:`);
408
+ for (const s of skipped) {
409
+ console.log(` ${s.key} [${s.skipped}] ${String(s.title).slice(0, 76)}`);
410
+ }
411
+ console.log('\n mentions-the-word — the row talks ABOUT the acronym; renaming it breaks the sentence.');
412
+ console.log(' exempt — the row states the rename rule and must keep naming what it retires.');
413
+ console.log(' goal-achieved/archived — a closed goal is a completed record; the server refuses the edit');
414
+ console.log(' (409 goal_not_open), which is the same rule this goal is built on.');
415
+ }
416
+
417
+ function main() {
418
+ const argv = process.argv.slice(2);
419
+ const { proposals, skipped } = collectProposals();
420
+ const stats = summarize(proposals);
421
+
422
+ if (argv.includes('--json')) {
423
+ process.stdout.write(`${JSON.stringify({
424
+ stats,
425
+ proposals: proposals.map((p) => ({ kind: p.kind, id: p.id, patch: p.patch })),
426
+ skipped: skipped.map((s) => ({ key: s.key, reason: s.skipped, title: s.title })),
427
+ }, null, 2)}\n`);
428
+ return;
429
+ }
430
+
431
+ if (!argv.includes('--apply')) {
432
+ if (!argv.includes('--summary')) printProposals(proposals);
433
+ printSkipped(skipped);
434
+ console.log(`\ndry run — nothing written.`);
435
+ console.log(` ${stats.rows} row(s), ${stats.edits} column edit(s): ${JSON.stringify(stats.byKind)}`);
436
+ console.log(` ${skipped.length} row(s) left for a human`);
437
+ console.log(` frozen versions skipped entirely: ${[...FROZEN_VERSION_IDS].join(', ')}`);
438
+ console.log('\n apply with: node scripts/gds/rename-ledger-prose.js --apply');
439
+ return;
440
+ }
441
+
442
+ console.log(`applying ${proposals.length} row(s) at ${WRITES_PER_MIN}/min — about ${Math.ceil(proposals.length / WRITES_PER_MIN)} minute(s).`);
443
+ let ok = 0;
444
+ const failed = [];
445
+ for (const [i, p] of proposals.entries()) {
446
+ const url = p.kind === 'task' ? `/api/gds/tasks/${p.id}` : `/api/gds/goals/${p.id}`;
447
+ if (i) sleep(WRITE_SPACING_MS);
448
+ const r = patchWithRetry(url, p.patch);
449
+ if (r.ok) {
450
+ ok += 1;
451
+ console.log(` ok ${String(i + 1).padStart(3)}/${proposals.length} ${p.kind} ${p.id}`);
452
+ } else {
453
+ failed.push({ key: p.key, message: r.message });
454
+ console.log(` FAIL ${p.kind} ${p.id}`);
455
+ }
456
+ }
457
+ console.log(`\napplied ${ok}/${proposals.length} row(s).`);
458
+ if (failed.length) {
459
+ console.log('failed:');
460
+ for (const f of failed) console.log(` ${f.key}: ${f.message}`);
461
+ process.exitCode = 1;
462
+ }
463
+ console.log('re-run without --apply to confirm 0 remaining (the idempotency check).');
464
+ }
465
+
466
+ if (require.main === module) main();
467
+
468
+ module.exports = {
469
+ FROZEN_VERSION_IDS,
470
+ EXEMPT_ROWS,
471
+ IDENTIFIER_PATTERNS,
472
+ EDITABLE,
473
+ MENTION_MARKERS,
474
+ mentionsRatherThanUses,
475
+ maskIdentifiers,
476
+ unmask,
477
+ rewriteVocabulary,
478
+ rewrite,
479
+ proposeForRow,
480
+ changedLines,
481
+ summarize,
482
+ };
package/src/module-api.js CHANGED
@@ -55,7 +55,7 @@ const { buildInfo } = require('./build-info');
55
55
  // there. scripts/gds/bump-version.js still rewrites the literal below; it appends
56
56
  // the entry to that file. Look for a version's history there, not here.
57
57
  // ---------------------------------------------------------------------------
58
- const CORE_VERSION = '1.19.607'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
58
+ const CORE_VERSION = '1.19.608'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
59
59
 
60
60
  // A namespaced logger so a module's log lines are attributable + consistent.
61
61
  // Usage: const log = api.logger('dev-box'); log.info('mounted');
@@ -0,0 +1,192 @@
1
+ // tests/rename_ledger_prose.mjs — criterion C4 of goal 1000073, "the live
2
+ // ledger reads Bongos" (task 1003698).
3
+ //
4
+ // WHAT IS ACTUALLY AT RISK HERE. This script edits live rows through the API,
5
+ // so the expensive failure is not "it missed one" — it is "it rewrote something
6
+ // it should not have". Three kinds of thing must survive it byte for byte:
7
+ // identifiers that are still the true names of live things, the frozen GDS-V3 /
8
+ // GDS-V4 archives, and rows that MENTION the acronym rather than use it. Every
9
+ // one of those gets a case below, and they are the load-bearing ones.
10
+ //
11
+ // The pure half of the script takes its inputs explicitly, so nothing here
12
+ // touches the network or the tree.
13
+ import assert from 'node:assert/strict';
14
+ import { test } from 'node:test';
15
+ import { createRequire } from 'node:module';
16
+ import path from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+
19
+ const require = createRequire(import.meta.url);
20
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
21
+ const L = require(path.join(ROOT, 'scripts', 'gds', 'rename-ledger-prose.js'));
22
+
23
+ // ---------- identifiers are not vocabulary ----------
24
+
25
+ test('every identifier shape survives a rewrite byte for byte', () => {
26
+ for (const kept of [
27
+ 'GDS_API_BASE', 'GDS_TOKEN', 'GDS_BRANDING_FILE', 'MEDUSA_GDS_ONLY',
28
+ '/api/gds', '/api/gds/tasks', 'scripts/gds/ship.js', 'src/gds/db.js',
29
+ 'gds_session', 'gds-session.json', 'GDS-V3', 'GDS-V4',
30
+ ]) {
31
+ const text = `prose around ${kept} and more prose`;
32
+ const out = L.rewrite(text);
33
+ assert.ok(out === null || out.includes(kept), `${kept} must survive; got ${out}`);
34
+ }
35
+ });
36
+
37
+ test('a row carrying ONLY identifiers proposes no change at all', () => {
38
+ assert.equal(L.rewrite('set GDS_API_BASE, hit /api/gds, read the gds_session cookie'), null);
39
+ assert.equal(L.rewrite('run scripts/gds/ship.js'), null);
40
+ });
41
+
42
+ test('an identifier and real vocabulary in the same sentence: one changes, one does not', () => {
43
+ const out = L.rewrite('the GDS holds it; set GDS_API_BASE first');
44
+ assert.equal(out, 'Bongos holds it; set GDS_API_BASE first');
45
+ });
46
+
47
+ test('the mask round-trips exactly — a corrupted identifier would be silent', () => {
48
+ const text = 'GDS_TOKEN and /api/gds and GDS-V4 and scripts/gds/x.js';
49
+ const { masked, masks } = L.maskIdentifiers(text);
50
+ assert.ok(!masked.includes('GDS_TOKEN'));
51
+ assert.equal(L.unmask(masked, masks), text);
52
+ });
53
+
54
+ test('the version-id rule is SHARED with the C2 ratchet and the C5 pin, not re-declared', () => {
55
+ // The task asked for exactly this: "REUSE it rather than writing a second,
56
+ // divergent rule". Two copies drift the moment either side learns a new
57
+ // version id, and the drift is silent — this asserts one source.
58
+ const scan = require(path.join(ROOT, 'scripts', 'gds', 'gds-literal-scan.js'));
59
+ const history = require(path.join(ROOT, 'scripts', 'gds', 'rename-history-check.js'));
60
+ assert.ok(L.IDENTIFIER_PATTERNS.includes(scan.GDS_VERSION_ID_RE), 'the version-id regex must be the ratchet’s own object');
61
+ assert.deepEqual([...L.FROZEN_VERSION_IDS], history.PINNED_VERSION_IDS, 'the frozen set must come from the C5 pin');
62
+ });
63
+
64
+ // ---------- the article, which is where a regex usually breaks grammar ----------
65
+
66
+ test('the article is KEPT when the acronym modifies a noun', () => {
67
+ assert.equal(L.rewrite('mounted outside the GDS router'), 'mounted outside the Bongos router');
68
+ assert.equal(L.rewrite('a GDS task and a GDS blocker'), 'a Bongos task and a Bongos blocker');
69
+ assert.equal(L.rewrite('The GDS `dependencies[]` say what ships'), 'The Bongos `dependencies[]` say what ships');
70
+ });
71
+
72
+ test('the article is DROPPED when the acronym is the subject', () => {
73
+ assert.equal(L.rewrite('The GDS knows everything'), 'Bongos knows everything');
74
+ assert.equal(L.rewrite('the GDS is the ledger'), 'Bongos is the ledger');
75
+ assert.equal(L.rewrite('poll the GDS for the next task'), 'poll Bongos for the next task');
76
+ assert.equal(L.rewrite('its home is the GDS (goal rows)'), 'its home is Bongos (goal rows)');
77
+ });
78
+
79
+ test('keeping the article is the DEFAULT, because dropping it wrongly breaks the sentence', () => {
80
+ // An unrecognised follower must not lose its article — "outside Bongos
81
+ // router" is broken English, while "the Bongos widget" merely reads plainly.
82
+ assert.equal(L.rewrite('inside the GDS widgetorium'), 'inside the Bongos widgetorium');
83
+ });
84
+
85
+ test('the product name is not doubled', () => {
86
+ assert.equal(L.rewrite('pg_dump of Cloud Bongos GDS Postgres DB'), 'pg_dump of Cloud Bongos Postgres DB');
87
+ });
88
+
89
+ // ---------- mention vs use ----------
90
+
91
+ test('text that MENTIONS the word is detected, not rewritten', () => {
92
+ for (const mention of [
93
+ 'GDS is a legacy term inherited from Primea',
94
+ 'the primer still says GDS (should be Bongos)',
95
+ 'fails the build on a NEW literal `GDS`',
96
+ 'records the bongos-as-GDS-successor intent',
97
+ 'a thing called GDS at the time',
98
+ 'GDS → Bongos naming sweep',
99
+ 'unchanged since the PMS→GDS rename',
100
+ 'files under docs/ containing "GDS"',
101
+ ]) {
102
+ assert.equal(L.mentionsRatherThanUses(mention), true, `should be treated as a mention: ${mention}`);
103
+ }
104
+ });
105
+
106
+ test('ordinary usage is NOT mistaken for a mention', () => {
107
+ for (const use of [
108
+ 'the GDS router has no rate limiting',
109
+ 'Writes GDS records only',
110
+ 'poll the GDS for the next claimable task',
111
+ 'a GDS task must be claimed first',
112
+ ]) {
113
+ assert.equal(L.mentionsRatherThanUses(use), false, `should be treated as ordinary use: ${use}`);
114
+ }
115
+ });
116
+
117
+ // ---------- row selection ----------
118
+
119
+ const taskRow = (over) => ({ id: '1', version_id: 'BONGOS-V1', title: 'the GDS holds it', description: 'x', ...over });
120
+
121
+ test('a frozen-archive row is skipped entirely, and silently — it IS the record', () => {
122
+ assert.equal(L.proposeForRow('task', taskRow({ version_id: 'GDS-V3' })), null);
123
+ assert.equal(L.proposeForRow('task', taskRow({ version_id: 'GDS-V4' })), null);
124
+ });
125
+
126
+ test('a live row is proposed, patching only the columns that changed', () => {
127
+ const p = L.proposeForRow('task', taskRow({ description: 'nothing to see' }));
128
+ assert.deepEqual(Object.keys(p.patch), ['title']);
129
+ assert.equal(p.patch.title, 'Bongos holds it');
130
+ });
131
+
132
+ test('an exempt row is REPORTED, never silently dropped', () => {
133
+ const p = L.proposeForRow('goal', { id: '1000073', version_id: 'BONGOS-V1', title: 'Finish the GDS→Bongos rename' });
134
+ assert.equal(p.skipped, 'exempt');
135
+ });
136
+
137
+ test('a mention row is reported for a human instead of being rewritten', () => {
138
+ const p = L.proposeForRow('task', taskRow({ description: 'GDS is a legacy term inherited from Primea' }));
139
+ assert.equal(p.skipped, 'mentions-the-word');
140
+ assert.equal(p.patch, undefined, 'a skipped row must carry no patch — nothing can apply it by accident');
141
+ });
142
+
143
+ test('a closed goal is reported, not patched — the server refuses it and the goal rule agrees', () => {
144
+ for (const status of ['achieved', 'archived']) {
145
+ const p = L.proposeForRow('goal', { id: '9', version_id: 'BONGOS-V1', status, title: 'the GDS holds it' });
146
+ assert.equal(p.skipped, `goal-${status}`);
147
+ assert.equal(p.patch, undefined);
148
+ }
149
+ const open = L.proposeForRow('goal', { id: '9', version_id: 'BONGOS-V1', status: 'open', title: 'the GDS holds it' });
150
+ assert.equal(open.patch.title, 'Bongos holds it');
151
+ });
152
+
153
+ test('a closed goal whose only occurrences are IDENTIFIERS is not reported at all', () => {
154
+ // Reporting it would tell a human to look at a row with nothing wrong. The
155
+ // status check must run after the patch, not before it.
156
+ const p = L.proposeForRow('goal', {
157
+ id: '9', version_id: 'BONGOS-V1', status: 'achieved',
158
+ title: 'set GDS_API_BASE', description: 'and hit /api/gds',
159
+ });
160
+ assert.equal(p, null);
161
+ });
162
+
163
+ test('only columns the API accepts are ever proposed', () => {
164
+ assert.deepEqual(L.EDITABLE.task, ['title', 'description']);
165
+ assert.deepEqual(L.EDITABLE.goal, ['title', 'subtitle', 'description']);
166
+ const p = L.proposeForRow('task', taskRow({ notes: 'the GDS holds it' }));
167
+ assert.ok(!('notes' in p.patch), 'PATCH /tasks/:id does not accept notes');
168
+ });
169
+
170
+ // ---------- idempotency, by construction ----------
171
+
172
+ test('a rewritten row proposes nothing on a second pass', () => {
173
+ const once = L.rewrite('the GDS holds it; the GDS router is fine');
174
+ assert.equal(L.rewrite(once), null, 'the second --apply must change zero rows');
175
+ });
176
+
177
+ test('summarize counts rows and column edits per kind', () => {
178
+ const stats = L.summarize([
179
+ { kind: 'task', patch: { title: 'a', description: 'b' } },
180
+ { kind: 'task', patch: { title: 'a' } },
181
+ { kind: 'goal', patch: { subtitle: 'c' } },
182
+ ]);
183
+ assert.equal(stats.rows, 3);
184
+ assert.equal(stats.edits, 4, 'edits counts COLUMNS, not rows — a row can change two');
185
+ assert.deepEqual(stats.byKind, { task: 2, goal: 1 });
186
+ });
187
+
188
+ test('changedLines reports only the lines that differ', () => {
189
+ const lines = L.changedLines('same\nthe GDS\nsame', 'same\nBongos\nsame');
190
+ assert.equal(lines.length, 1);
191
+ assert.equal(lines[0].after, 'Bongos');
192
+ });