@bongos/core 1.23.2 → 1.23.3

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,11 +2,11 @@
2
2
  "artifact": "bongos-core",
3
3
  "manifest_schema": 1,
4
4
  "generator": "scripts/bongos/package-core.js",
5
- "core_version": "1.23.2",
6
- "core_contract": "1.23.2",
7
- "source_commit": "ceece568fbbcb8fc2b0ae26fb797c4e25cc561e8",
5
+ "core_version": "1.23.3",
6
+ "core_contract": "1.23.3",
7
+ "source_commit": "a0b45cd71b45f91da068da6eb3e6afef687897c6",
8
8
  "source_ref": "HEAD",
9
- "built_at": "2026-10-26T20:56:59.821Z",
9
+ "built_at": "2026-10-26T21:16:36.258Z",
10
10
  "redaction": {
11
11
  "model": "docs-redacted+functional-verbatim",
12
12
  "docs_redacted": 616,
@@ -17,7 +17,7 @@
17
17
  "gate": "passed"
18
18
  },
19
19
  "file_count": 4197,
20
- "tree_sha256": "b7044ab9489376d2235032b4c477d00a80eaff992b0e4b7ef85e006ac4ab4a44",
20
+ "tree_sha256": "929094e8d49dd75a5e74b18f58a1b869fc50dbc5df600af9e861981227cdb40c",
21
21
  "files": [
22
22
  {
23
23
  "path": ".claude/skills/ask-for-help/SKILL.md",
@@ -2937,12 +2937,12 @@
2937
2937
  {
2938
2938
  "path": "docs/module-api-changelog.md",
2939
2939
  "mode": "0000644",
2940
- "sha256": "dab88b77e92556a8ee38cf29f1c0651b03948fb64f84218de31deb29dd88a427"
2940
+ "sha256": "298fea75cd1590bf6dbb3ad5baedf0ec6c81d2eb811cf59a3d138bd15144c021"
2941
2941
  },
2942
2942
  {
2943
2943
  "path": "docs/modules-contract.md",
2944
2944
  "mode": "0000644",
2945
- "sha256": "c060a917d9a2e7ec3d0a982cdd4ea766fb169b60af48fe051b677de5e4c176ff"
2945
+ "sha256": "28cbf7f3d10bd67ef74880112746d182fac27a7659c52694c315b17efe5cb325"
2946
2946
  },
2947
2947
  {
2948
2948
  "path": "docs/onboarding/diagrams/01-task-lifecycle.mmd",
@@ -10832,12 +10832,12 @@
10832
10832
  {
10833
10833
  "path": "package-lock.json",
10834
10834
  "mode": "0000644",
10835
- "sha256": "18afbb380a19b9cd590be01531be1be017361ae8e983737c21a4447fbdbf1fae"
10835
+ "sha256": "4a12dc099ad30270a9f2144f9f243b7183b968c6f9761736c2a10a4471ca08ee"
10836
10836
  },
10837
10837
  {
10838
10838
  "path": "package.json",
10839
10839
  "mode": "0000644",
10840
- "sha256": "ce17d8a6be52178ed3a90d897f8967eb1c7dd0f8a662cc9c15d0c32e20534e68"
10840
+ "sha256": "975226f43368c946a43c0ae434ba6132e404175ba6b4960c45fb72b6d109e715"
10841
10841
  },
10842
10842
  {
10843
10843
  "path": "public-docs/index.html",
@@ -10857,7 +10857,7 @@
10857
10857
  {
10858
10858
  "path": "release-notes.json",
10859
10859
  "mode": "0000644",
10860
- "sha256": "e3e8007ba8a4bb814329fc41bd3d9bb7a0d48821b8bc2bc4a83ae23ea213037f"
10860
+ "sha256": "de9343583c3ac62144354a65b34a4a44bb4d9442c4abd1b77fafc16558c70f9c"
10861
10861
  },
10862
10862
  {
10863
10863
  "path": "scripts/bongos/CLAUDE.md",
@@ -14427,7 +14427,7 @@
14427
14427
  {
14428
14428
  "path": "src/bongos/module-listing.js",
14429
14429
  "mode": "0000644",
14430
- "sha256": "f0edc88d351578171d9b4e28fc4f54fb7a2fa3b3f75a2c4d9ca790d242fd902b"
14430
+ "sha256": "3f7013b4e59f72fc89663461d6d5457e412624ae3d4c1df1d2a3b9a8d9168d02"
14431
14431
  },
14432
14432
  {
14433
14433
  "path": "src/bongos/module-overrides.js",
@@ -14712,7 +14712,7 @@
14712
14712
  {
14713
14713
  "path": "src/module-api.js",
14714
14714
  "mode": "0000644",
14715
- "sha256": "63527f7ed1ef461762b9fb39edd735fc5361d94f5c3ecdc0c3a8bae4518418f3"
14715
+ "sha256": "f87d7162b505fb241f2c33e6dfeaa86cb97d085c6f822384b2b7d923d4eadd1a"
14716
14716
  },
14717
14717
  {
14718
14718
  "path": "src/module-loader/catalog.js",
@@ -18502,7 +18502,7 @@
18502
18502
  {
18503
18503
  "path": "tests/module_store_listing.mjs",
18504
18504
  "mode": "0000644",
18505
- "sha256": "5ff78feca75178ee59114da484a6746e4aa13aa0d1e080f838f18548e5c6b3e6"
18505
+ "sha256": "5f0cb9cb6e3faf90d342e1d9e1767699b677b8630d874f1c2af9cb7f713ef530"
18506
18506
  },
18507
18507
  {
18508
18508
  "path": "tests/module_store_publish.mjs",
@@ -3221,5 +3221,7 @@ is load-bearing: the script throws rather than guess if it is missing, and
3221
3221
  landed since 1.23.0 with no explicit bump. run 40270556091. (task 1002620)
3222
3222
  1.23.2 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
3223
3223
  landed since 1.23.1 with no explicit bump. run 40399986777. (task 1002620)
3224
+ 1.23.3 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
3225
+ landed since 1.23.2 with no explicit bump. run 40402796050. (task 1002620)
3224
3226
  ---------------------------------------------------------------------------
3225
3227
  ```
@@ -398,7 +398,8 @@ Run `bongos upgrade` to confirm coreVersion compatibility, then `node scripts/bo
398
398
  - **What a module is strong and weak at** (task 1003799, ADR 0343 D4). Each catalog entry also carries `parts` (the current result of Tests, Clean installs, Reliability, Tester feedback and How-to) and a reading of them: `strengths` (a part scored **80 or more**), `weaknesses` (a part scored **below the floor**) and `unmeasured` (a part with no score yet, which is never counted as weak). Each strength and weakness has a one-sentence `detail` saying what the number rests on. Security is not among them: every listed version has passed it. The reading is `readParts` in `src/bongos/module-listing.js`; the hall's Modules tab shows it in its "In the store" group, so two modules with the same overall score can be told apart.
399
399
  - **Sorting by a part** (task 1003800). `GET /store/modules?sort=<part>` orders the listed modules by one part a buyer cares about: `tests`, `install`, `reliability`, `tester_feedback` or `docs` (the response lists them as `sort_parts`, and says which one it applied as `sort`). Modules with a score for that part come first, highest first; a tie goes to the higher overall score, then the module key. A module with no score for that part goes last, so missing data never wins or loses a place on its own. New modules are not sorted: they are never ranked. Any other `sort` value is refused with a 400. Without `sort`, the listed modules are in the ranking below; New stays in key order. The rule is `sortByPart` in `src/bongos/module-listing.js`.
400
400
  - **The ranking, and a maximum price** (task 1003808, owner decision 2026-10-23). Without `sort`, listed modules are ranked **quality first**: highest overall score first; between equal scores, free modules first, then the lowest cash price, then the lowest credit price, then the module key. Price never buys a better place, it only orders modules the score could not tell apart (and it is never an input to the score, ADR 0343 D6). The response states the rule as `ranking`, and each entry carries its current `price` (`cents`, `credits`, `free`). A buyer may add `?max_cents=` and/or `?max_credits=` (whole numbers, 0 or more): modules that cost more are left out of both lists, free modules always stay, and a priced module stays when it is offered at or under a cap the buyer set. The applied caps come back as `max_price`. The rules are `rankListed` and `withinMaxPrice` in `src/bongos/module-listing.js`.
401
- - **Why a module is not listed** (task 1003810). `GET /store/modules/:key/listing` says where one module stands, judging the same newest version the catalog does: `listed` (true or false), a `reason` (`not_assessed`, `security_not_passed`, `no_score`, `below_floor`, `delisted`, `no_version`, `new` or `at_or_above_floor`), `why` in a sentence and `next_step` saying what would change it. A failed Security gate is told apart from one that has not finished, and names what it found to the module's author only (to anyone else it would point at a weakness not fixed yet); below the floor names the score, the floor and the weakest parts. It carries the same `parts`, `strengths`, `weaknesses` and `unmeasured` as the catalog, plus `security`. Any signed-in builder can read it. Being past the cap of ten per category will be a reason of its own once the cap exists (task 1003809). The rule is `explainPlacement` in `src/bongos/module-listing.js`.
401
+ - **The cap: at most ten per sub-category** (task 1003809, [ADR 0342](adr/0342-module-categories-are-eight-parents-with-approved-sub-categories.md) D2). Above the floor, at most **ten** modules are listed in each approved sub-category: the first ten in the ranking above, so a buyer's `sort` or maximum price reorders or narrows those ten but never lets the eleventh in. The cap is never applied to a parent. A module whose sub-category is only proposed is listed under its parent and counts toward no cap, and a New module is not ranked, so it neither takes a slot nor is held by one. The catalog returns the cap as `cap`. The rule is `applyCap` in `src/bongos/module-listing.js`.
402
+ - **Why a module is not listed** (task 1003810). `GET /store/modules/:key/listing` says where one module stands, judging the same newest version the catalog does: `listed` (true or false), a `reason` (`not_assessed`, `security_not_passed`, `no_score`, `below_floor`, `delisted`, `no_version`, `over_cap`, `new` or `at_or_above_floor`), `why` in a sentence and `next_step` saying what would change it. A failed Security gate is told apart from one that has not finished, and names what it found to the module's author only (to anyone else it would point at a weakness not fixed yet); below the floor names the score, the floor and the weakest parts. It carries the same `parts`, `strengths`, `weaknesses` and `unmeasured` as the catalog, plus `security`. Any signed-in builder can read it. Past the cap it is `over_cap`, which names the score, the module's place in its sub-category and the cap, so an author can tell being eleventh apart from being below the floor. Both responses carry the module's `category` (`parent`, `parent_title`, and `sub` and `label` once its sub-category is approved). The rule is `explainPlacement` in `src/bongos/module-listing.js`.
402
403
  - **Sub-categories are approved before they count** (task 1004355, ADR 0342 D3). A module names `category: { parent, sub }` in `module.json`; `GET /store/subcategories` lists the approved ones under each of the eight parents. A `sub` the store has not seen under that parent is **proposed** at publish (labelled from its key) and the publish answer's `category` says so (`status: "proposed"`, `live: false`): until a Metic+ person decides, the module sits under its parent only and counts toward no cap. The review queue (`GET /store/subcategories/queue`, atom `module.subcategory.review`, metic + archon via `government_033`) shows each proposal with the modules that named it and its near-duplicate names; `POST /store/subcategories/:id/approve { label?, sub_key? }` makes it live, renamed first if asked (a rename onto an existing key is refused — merge instead), and `POST /store/subcategories/:id/merge { into }` folds it into an approved one and moves its modules there. A later publish naming a merged key lands on its target. Where a module sits is `store_module_categories` (core_278), apart from the manifest; `readModuleCategories` in `src/bongos/module-subcategories.js` is the read the cap uses.
403
404
  - **Testing new versions first** (task 1003802, [ADR 0344](adr/0344-a-tester-is-a-project-that-opts-in-once.md) D1). A project can choose to get each new version of its modules before everyone else. It is the project that opts in, never one builder for someone else's project, and never by default. `GET /modules/testing` returns `{ tester, general_only, updated_at, updated_by }` to anyone signed in. `POST /modules/testing { tester: true|false }` switches it, and `POST /modules/:key/general-only { general_only: true|false }` keeps one module on the versions everyone gets while the rest are tested. Both writes take the `module.enable` permission, the same one that turns modules on and off. Both are reversible: switching testing off puts the project back on general versions from its next update, and a module's "general only" mark is kept if testing is switched off and on again. The choice is stored in the project's own settings (`modules.tester`, `modules.general_only`); anything that cannot be read counts as not testing. `testsVersionsOf` in `src/bongos/module-testing.js` is the one answer to "does this project get the tester version of this module", which installs and updates use (task 1003805). The hall's Modules tab has the switch in its "Testing new versions" group, and the general-only control in each module's details.
404
405
 
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.23.2",
3
+ "version": "1.23.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bongos/core",
9
- "version": "1.23.2",
9
+ "version": "1.23.3",
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.23.2",
3
+ "version": "1.23.3",
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",
@@ -10395,5 +10395,11 @@
10395
10395
  "id": "1004355",
10396
10396
  "text": "Module authors can now propose a new store sub-category when they publish, and Metic+ reviewers approve, rename or merge it, with look-alike names shown side by side so duplicates don't split the rankings."
10397
10397
  }
10398
+ ],
10399
+ "1.23.3": [
10400
+ {
10401
+ "id": "1003809",
10402
+ "text": "The module store now shows at most ten modules in each sub-category, and a module that lands eleventh tells its author why."
10403
+ }
10398
10404
  ]
10399
10405
  }
@@ -17,6 +17,7 @@
17
17
  // A delisted module (ADR 0338 D2) is never in the catalog, whatever its score.
18
18
 
19
19
  const { parseVersion, cmp } = require('../module-loader/semver');
20
+ const { readModuleCategories } = require('./module-subcategories');
20
21
 
21
22
  // The quality floor, 0-100. It lives here and nowhere else: it is part of Bongos
22
23
  // itself, not a live setting, so no author, builder or instance can move it.
@@ -106,9 +107,9 @@ function readParts(signals = [], { floor = QUALITY_FLOOR } = {}) {
106
107
  // last, in key order: a missing part is never a zero, and never a first place.
107
108
  //
108
109
  // Only `listed` is sorted. A "New" version is never ranked (owner decision,
109
- // 2026-10-01), so `new` keeps key order whatever the buyer picks. Today this runs
110
- // over the whole store; once approved sub-categories exist (task 1004355) the same
111
- // rule orders each one (ADR 0342 D2).
110
+ // 2026-10-01), so `new` keeps key order whatever the buyer picks. The cap of ten
111
+ // per approved sub-category (applyCap) is drawn from the default ranking before any
112
+ // sort, so a buyer's sort never changes who is listed.
112
113
  const SORT_PARTS = PARTS.map(({ part, title }) => ({ part, title }));
113
114
 
114
115
  // `entries` carry `parts` as readParts builds them. Returns a new array. Pure.
@@ -174,6 +175,44 @@ function rankListed(entries) {
174
175
  });
175
176
  }
176
177
 
178
+ // ---------------------------------------------------------------------------
179
+ // The cap: at most ten listed per sub-category (task 1003809, ADR 0342 D2)
180
+ // ---------------------------------------------------------------------------
181
+ //
182
+ // The owner's rule: fifteen Stripe modules all scoring above 94% still show only the
183
+ // top ten. The comparable set is an APPROVED sub-category, never a parent (D2): a
184
+ // module whose sub-category is only proposed is listed under its parent and counts
185
+ // toward no cap (D3). The ten are the first ten in the default ranking (RANKING), so
186
+ // a buyer's sort or maximum price reorders or narrows the ten, never changes who they
187
+ // are. A New version is not ranked, so it neither takes a slot nor is held by one.
188
+ const CAP_PER_SUBCATEGORY = 10;
189
+
190
+ // `ranked` in rankListed order; `cats` a Map of key -> readModuleCategories entry.
191
+ // Returns { kept, held }: `kept` keeps the order, `held` maps each key past the cap
192
+ // to { rank, cap, label } (its place in its sub-category). Pure.
193
+ function applyCap(ranked, cats, cap = CAP_PER_SUBCATEGORY) {
194
+ const seen = new Map();
195
+ const kept = [];
196
+ const held = new Map();
197
+ for (const e of ranked) {
198
+ const c = cats.get(e.key);
199
+ if (!c || !c.live) { kept.push(e); continue; }
200
+ const set = `${c.parent}/${c.sub}`;
201
+ const rank = (seen.get(set) || 0) + 1;
202
+ seen.set(set, rank);
203
+ if (rank <= cap) kept.push(e);
204
+ else held.set(e.key, { rank, cap, label: c.label || c.sub });
205
+ }
206
+ return { kept, held };
207
+ }
208
+
209
+ // Where a module sits, as the catalog shows it: its parent, and its sub-category
210
+ // only once approved. A proposed one is not shown: it is not live yet (D3).
211
+ function categoryOf(c) {
212
+ if (!c) return null;
213
+ return { parent: c.parent, parent_title: c.parent_title, sub: c.live ? c.sub : null, label: c.live ? c.label : null };
214
+ }
215
+
177
216
  // The newest version row per module key, in semver order (a version that does not
178
217
  // parse is skipped, as latestVersions does in module-store.js).
179
218
  function newestPerModule(rows) {
@@ -188,19 +227,28 @@ function newestPerModule(rows) {
188
227
  return [...out.values()];
189
228
  }
190
229
 
191
- // The catalog: { floor, ranking, sort, sort_parts, max_price, listed: [...], new: [...] },
192
- // each entry { key, title, version, published_at, price, overall, is_new, parts,
193
- // strengths, weaknesses, unmeasured } (the last four from readParts). Excluded
194
- // versions are left out entirely: a module below the bar is not listed at all, and
195
- // neither is one over the buyer's `maxPrice`. `listed` is in rankListed order unless
196
- // `sort` names a part, which orders it by sortByPart; `new` is never ranked and
197
- // stays in key order.
198
- async function listCatalog({ db, floor = QUALITY_FLOOR, sort = null, maxPrice = null } = {}) {
230
+ // The catalog: { floor, cap, ranking, sort, sort_parts, max_price, listed: [...], new: [...] },
231
+ // each entry { key, title, version, published_at, price, category, overall, is_new,
232
+ // parts, strengths, weaknesses, unmeasured } (the last four from readParts). Excluded
233
+ // versions are left out entirely: a module below the bar is not listed at all, nor
234
+ // is one past the cap of its sub-category, nor one over the buyer's `maxPrice`.
235
+ // `listed` is in rankListed order unless `sort` names a part, which orders it by
236
+ // sortByPart; `new` is never ranked and stays in key order.
237
+ async function listCatalog(opts = {}) {
238
+ return (await buildCatalog(opts)).catalog;
239
+ }
240
+
241
+ // listCatalog's work, plus `held`: the keys the cap left out, with their place
242
+ // (applyCap). readListing reads `held` to tell an author they are eleventh, and
243
+ // passes `keys` — one sub-category's modules — so one module's check reads only
244
+ // the set it competes in, never the whole store. The cap counts within a
245
+ // sub-category, so that subset ranks exactly as it does in the full catalog.
246
+ async function buildCatalog({ db, floor = QUALITY_FLOOR, sort = null, maxPrice = null, keys = null } = {}) {
199
247
  const pool = db || require('./pool').pool;
200
248
  const { rows: versions } = await pool.query(
201
249
  `SELECT m.module_key, m.title, v.id AS version_id, v.version, v.published_at
202
250
  FROM store_modules m JOIN store_module_versions v ON v.module_key = m.module_key
203
- WHERE m.status = 'listed'`);
251
+ WHERE m.status = 'listed'${keys ? ' AND m.module_key = ANY($1)' : ''}`, keys ? [keys] : []);
204
252
  const newest = newestPerModule(versions);
205
253
  const scores = new Map();
206
254
  if (newest.length) {
@@ -237,21 +285,26 @@ async function listCatalog({ db, floor = QUALITY_FLOOR, sort = null, maxPrice =
237
285
  }
238
286
  const max = maxPrice && (maxPrice.cents != null || maxPrice.credits != null)
239
287
  ? { cents: maxPrice.cents ?? null, credits: maxPrice.credits ?? null } : null;
240
- const out = { floor, ranking: RANKING, sort: sort || null, sort_parts: SORT_PARTS, max_price: max, listed: [], new: [] };
288
+ const cats = await readModuleCategories(newest.map((r) => r.module_key), { db: pool });
289
+ const out = { floor, cap: CAP_PER_SUBCATEGORY, ranking: RANKING, sort: sort || null, sort_parts: SORT_PARTS, max_price: max, listed: [], new: [] };
241
290
  for (const r of newest.sort((a, b) => a.module_key.localeCompare(b.module_key))) {
242
291
  const score = scores.get(String(r.version_id)) || null;
243
292
  const { placement } = placeVersion(score, floor);
244
293
  if (placement === 'excluded') continue;
245
- const price = priceOf(prices.get(r.module_key));
246
- if (!withinMaxPrice(price, max)) continue;
247
294
  out[placement].push({
248
- key: r.module_key, title: r.title, version: r.version, published_at: r.published_at, price,
295
+ key: r.module_key, title: r.title, version: r.version, published_at: r.published_at,
296
+ price: priceOf(prices.get(r.module_key)), category: categoryOf(cats.get(r.module_key)),
249
297
  overall: placement === 'new' ? null : score.overall, is_new: placement === 'new',
250
298
  ...readParts(signals.get(String(r.version_id)) || [], { floor }),
251
299
  });
252
300
  }
253
- out.listed = sort ? sortByPart(out.listed, sort) : rankListed(out.listed);
254
- return out;
301
+ // The cap first, over the default ranking; then the buyer's filter and order.
302
+ const { kept, held } = applyCap(rankListed(out.listed), cats);
303
+ const affordable = (e) => withinMaxPrice(e.price, max);
304
+ out.listed = kept.filter(affordable);
305
+ out.new = out.new.filter(affordable);
306
+ if (sort) out.listed = sortByPart(out.listed, sort);
307
+ return { catalog: out, held };
255
308
  }
256
309
 
257
310
  // ---------------------------------------------------------------------------
@@ -263,9 +316,10 @@ async function listCatalog({ db, floor = QUALITY_FLOOR, sort = null, maxPrice =
263
316
  // names the reason in a sentence, says what would change it, and carries the same
264
317
  // parts reading the catalog shows (the weakest parts first). The reasons are
265
318
  // placeVersion's, plus two the catalog drops before it gets that far: `delisted`
266
- // and `no_version`. Being past the cap of ten per category is a reason of its own
267
- // once the cap exists (task 1003809); it is not one yet.
268
- function explainPlacement({ placement, reason }, { overall = null, floor = QUALITY_FLOOR, security = null, weaknesses = [] } = {}) {
319
+ // and `no_version`, and `over_cap`: above the floor but past the top ten of its
320
+ // sub-category (task 1003809). From outside, being eleventh looks the same as being
321
+ // below the floor, so the author is told which it is.
322
+ function explainPlacement({ placement, reason }, { overall = null, floor = QUALITY_FLOOR, security = null, weaknesses = [], held = null } = {}) {
269
323
  const weakest = weaknesses.slice(0, 3).map((w) => `${w.title} (${w.score})`).join(', ');
270
324
  const say = (why, nextStep) => ({ listed: placement !== 'excluded', placement, reason, why, next_step: nextStep });
271
325
  switch (reason) {
@@ -291,6 +345,9 @@ function explainPlacement({ placement, reason }, { overall = null, floor = QUALI
291
345
  case 'below_floor':
292
346
  return say(`This version scored ${overall} out of 100. The store lists modules that score at least ${floor}.${weakest ? ` Its weakest parts: ${weakest}.` : ''}`,
293
347
  'Improve its weakest parts and publish a new version. The newest version is the one judged.');
348
+ case 'over_cap':
349
+ return say(`This version scored ${overall} out of 100, above the floor of ${floor}, but it ranks ${held.rank} in ${held.label}. The store lists the top ${held.cap} in each sub-category.`,
350
+ `Score higher than the module in place ${held.cap} and publish a new version. Between equal scores, the cheaper module ranks higher.`);
294
351
  case 'new':
295
352
  return say('This version is listed with a New label. It is not ranked until it has real install and reliability data.',
296
353
  'Nothing to do: it is ranked once projects have installed and used it.');
@@ -301,7 +358,7 @@ function explainPlacement({ placement, reason }, { overall = null, floor = QUALI
301
358
  }
302
359
 
303
360
  // Where one module stands in the catalog, and why: null for a key the store does not
304
- // know, else { module_key, title, status, version, version_id, floor, overall,
361
+ // know, else { module_key, title, status, category, version, version_id, floor, overall,
305
362
  // listed, placement, reason, why, next_step, security, parts, strengths, weaknesses,
306
363
  // unmeasured }. Judges the same version the catalog does: the newest published one.
307
364
  // What the Security gate found is told only to the module's author (`viewerId`): to
@@ -312,7 +369,8 @@ async function readListing(key, { db, floor = QUALITY_FLOOR, viewerId = null } =
312
369
  'SELECT module_key, title, status, author_id FROM store_modules WHERE module_key = $1', [key]);
313
370
  const mod = mods[0];
314
371
  if (!mod) return null;
315
- const head = { module_key: mod.module_key, title: mod.title, status: mod.status, floor };
372
+ const cat = (await readModuleCategories([key], { db: pool })).get(key);
373
+ const head = { module_key: mod.module_key, title: mod.title, status: mod.status, floor, category: categoryOf(cat) };
316
374
  const { rows: versions } = await pool.query(
317
375
  'SELECT module_key, id AS version_id, version, published_at FROM store_module_versions WHERE module_key = $1', [key]);
318
376
  const newest = newestPerModule(versions)[0];
@@ -337,16 +395,30 @@ async function readListing(key, { db, floor = QUALITY_FLOOR, viewerId = null } =
337
395
  const isAuthor = viewerId != null && String(mod.author_id) === String(viewerId);
338
396
  const security = sec ? { outcome: sec.outcome, reason: (isAuthor && sec.reason) || null } : null;
339
397
  const reading = readParts(signals, { floor });
340
- const placed = placeVersion(score, floor);
398
+ let placed = placeVersion(score, floor);
399
+ // Above the floor in a live sub-category, the cap decides, over the same ranking
400
+ // the catalog uses, so the two never disagree. Only that sub-category is read:
401
+ // `self` is found by store_module_categories' primary key (module_key) and `peer`
402
+ // by idx_store_module_categories_sub (subcategory_id), both in core_280.
403
+ let held = null;
404
+ if (placed.placement === 'listed' && cat && cat.live) {
405
+ const { rows: peers } = await pool.query(
406
+ `SELECT peer.module_key
407
+ FROM store_module_categories self
408
+ JOIN store_module_categories peer ON peer.subcategory_id = self.subcategory_id
409
+ WHERE self.module_key = $1`, [key]);
410
+ held = (await buildCatalog({ db: pool, floor, keys: peers.map((p) => p.module_key) })).held.get(key) || null;
411
+ if (held) placed = { placement: 'excluded', reason: 'over_cap' };
412
+ }
341
413
  const overall = score && placed.placement !== 'new' ? score.overall : null;
342
414
  return {
343
415
  ...head, version: newest.version, version_id: newest.version_id, overall,
344
- ...explainPlacement(placed, { overall, floor, security, weaknesses: reading.weaknesses }),
416
+ ...explainPlacement(placed, { overall, floor, security, weaknesses: reading.weaknesses, held }),
345
417
  security, ...reading,
346
418
  };
347
419
  }
348
420
 
349
421
  module.exports = {
350
- QUALITY_FLOOR, STRONG_AT, SORT_PARTS, RANKING, placeVersion, readParts, sortByPart,
351
- priceOf, withinMaxPrice, rankListed, listCatalog, explainPlacement, readListing,
422
+ QUALITY_FLOOR, STRONG_AT, SORT_PARTS, RANKING, CAP_PER_SUBCATEGORY, placeVersion, readParts,
423
+ sortByPart, priceOf, withinMaxPrice, rankListed, applyCap, listCatalog, explainPlacement, readListing,
352
424
  };
package/src/module-api.js CHANGED
@@ -81,7 +81,7 @@ const { sleep } = require('./sleep');
81
81
  // MAJOR (see allowBoxScope below): passes the request through untouched.
82
82
  function deprecatedNoopMiddleware(_req, _res, next) { next(); }
83
83
 
84
- const CORE_VERSION = '1.23.2'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
84
+ const CORE_VERSION = '1.23.3'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
85
85
 
86
86
  // A namespaced logger so a module's log lines are attributable + consistent.
87
87
  // Usage: const log = api.logger('discord'); log.info('mounted');
@@ -6,6 +6,8 @@
6
6
  // - the route: the real GET /store/modules handler off the real router, with
7
7
  // pool.js replaced in the require cache (the module_upgrade_updates.mjs harness).
8
8
  //
9
+ // The cap of ten per approved sub-category (task 1003809) rides the same harness.
10
+ //
9
11
  // Run: node tests/module_store_listing.mjs
10
12
 
11
13
  import { strict as assert } from 'node:assert';
@@ -15,7 +17,7 @@ import { createRequire } from 'node:module';
15
17
  const require = createRequire(import.meta.url);
16
18
 
17
19
  // ---- the fake registry the route reads ----
18
- const state = { modules: {}, versions: [], scores: [], signals: [], prices: [] };
20
+ const state = { modules: {}, versions: [], scores: [], signals: [], prices: [], categories: {}, versionReads: [] };
19
21
  const pool = {
20
22
  async query(sql, params = []) {
21
23
  if (/FROM store_module_prices/.test(sql)) {
@@ -27,10 +29,27 @@ const pool = {
27
29
  }
28
30
  return { rows: [...newest.values()] };
29
31
  }
32
+ if (/FROM store_module_categories self/.test(sql)) {
33
+ state.peerReads = (state.peerReads || 0) + 1;
34
+ const mine = state.categories[params[0]];
35
+ return {
36
+ rows: Object.keys(state.categories)
37
+ .filter((k) => mine && state.categories[k].sub_key === mine.sub_key && state.categories[k].parent === mine.parent)
38
+ .map((k) => ({ module_key: k })),
39
+ };
40
+ }
41
+ if (/FROM store_module_categories c\b/.test(sql)) {
42
+ return {
43
+ rows: params[0].filter((k) => state.categories[k])
44
+ .map((k) => ({ module_key: k, sub_key: null, label: null, status: null, ...state.categories[k] })),
45
+ };
46
+ }
30
47
  if (/FROM store_modules m JOIN store_module_versions v/.test(sql)) {
48
+ state.versionReads.push(params[0] ? [...params[0]] : null);
31
49
  return {
32
50
  rows: state.versions
33
51
  .filter((v) => state.modules[v.module_key] && state.modules[v.module_key].status === 'listed')
52
+ .filter((v) => !params[0] || params[0].includes(v.module_key))
34
53
  .map((v) => ({ ...v, version_id: v.id, title: state.modules[v.module_key].title })),
35
54
  };
36
55
  }
@@ -69,7 +88,7 @@ const poolPath = require.resolve('../src/bongos/pool.js');
69
88
  require.cache[poolPath] = { id: poolPath, filename: poolPath, loaded: true, exports: { pool: { connect: async () => ({ ...pool, release() {} }), query: pool.query } } };
70
89
 
71
90
  const buildModulesRouter = require('../src/bongos/routes/modules.js');
72
- const { QUALITY_FLOOR, SORT_PARTS, RANKING, placeVersion, sortByPart, priceOf, withinMaxPrice, rankListed, explainPlacement } = require('../src/bongos/module-listing.js');
91
+ const { QUALITY_FLOOR, SORT_PARTS, RANKING, CAP_PER_SUBCATEGORY, placeVersion, sortByPart, priceOf, withinMaxPrice, rankListed, applyCap, explainPlacement } = require('../src/bongos/module-listing.js');
73
92
 
74
93
  function handlerFor(router, method, p) {
75
94
  const layer = router.stack.find((l) => l.route && l.route.path === p && l.route.methods[method]);
@@ -179,7 +198,7 @@ test('GET /store/modules: an empty store answers empty lists and the floor', asy
179
198
  state.modules = {}; state.versions = []; state.scores = [];
180
199
  const { handle } = handlerFor(buildModulesRouter(), 'get', '/store/modules');
181
200
  const res = await invoke(handle, {});
182
- assert.deepEqual(res.body, { floor: 50, ranking: RANKING, sort: null, sort_parts: SORT_PARTS, max_price: null, listed: [], new: [] });
201
+ assert.deepEqual(res.body, { floor: 50, cap: 10, ranking: RANKING, sort: null, sort_parts: SORT_PARTS, max_price: null, listed: [], new: [] });
183
202
  });
184
203
 
185
204
  // ---------------------------------------------------------------------------
@@ -430,6 +449,7 @@ test('explainPlacement: every reason says why in a sentence and what would chang
430
449
  [{ placement: 'excluded', reason: 'delisted' }, {}],
431
450
  [{ placement: 'excluded', reason: 'no_version' }, {}],
432
451
  [{ placement: 'new', reason: 'new' }, {}],
452
+ [{ placement: 'excluded', reason: 'over_cap' }, { overall: 95, held: { rank: 11, cap: 10, label: 'Stripe payments' } }],
433
453
  ]) {
434
454
  const e = explainPlacement(placed, ctx);
435
455
  assert.equal(e.reason, placed.reason);
@@ -544,3 +564,112 @@ test('the listing read and the catalog agree on every module', async () => {
544
564
  assert.equal(r.body.listed, shown.has(key), key);
545
565
  }
546
566
  });
567
+
568
+ // ---------------------------------------------------------------------------
569
+ // the cap: at most ten per approved sub-category (task 1003809, ADR 0342 D2/D3)
570
+ // ---------------------------------------------------------------------------
571
+
572
+ const live = (parent, sub, label) => ({ parent, parent_title: parent, sub, label, status: 'approved', live: true });
573
+
574
+ test('the cap is ten (owner decision, 2026-09-10)', () => {
575
+ assert.equal(CAP_PER_SUBCATEGORY, 10);
576
+ });
577
+
578
+ test('applyCap: ten per approved sub-category, counted in ranking order; a proposed one or none is never capped', () => {
579
+ const ranked = Array.from({ length: 12 }, (_, i) => ({ key: `s${String(i).padStart(2, '0')}` }))
580
+ .concat([{ key: 'other' }, { key: 'proposed' }, { key: 'loose' }]);
581
+ const cats = new Map(ranked.slice(0, 12).map((e) => [e.key, live('money', 'stripe', 'Stripe payments')]));
582
+ cats.set('other', live('money', 'invoices', 'Invoices'));
583
+ cats.set('proposed', { parent: 'money', sub: 'stripe', label: 'Stripe', status: 'proposed', live: false });
584
+ const { kept, held } = applyCap(ranked, cats);
585
+ assert.deepEqual(kept.map((e) => e.key), [...ranked.slice(0, 10).map((e) => e.key), 'other', 'proposed', 'loose']);
586
+ assert.deepEqual(held.get('s10'), { rank: 11, cap: 10, label: 'Stripe payments' });
587
+ assert.deepEqual(held.get('s11'), { rank: 12, cap: 10, label: 'Stripe payments' });
588
+ assert.equal(held.size, 2);
589
+ });
590
+
591
+ test('applyCap: the same sub key under two parents is two comparable sets', () => {
592
+ const ranked = Array.from({ length: 11 }, (_, i) => ({ key: `a${i}` })).concat(Array.from({ length: 2 }, (_, i) => ({ key: `b${i}` })));
593
+ const cats = new Map(ranked.map((e) => [e.key, e.key.startsWith('a') ? live('money', 'general', 'General') : live('work', 'general', 'General')]));
594
+ const { held } = applyCap(ranked, cats);
595
+ assert.deepEqual([...held.keys()], ['a10']);
596
+ });
597
+
598
+ // The owner's example, verbatim: fifteen Stripe modules all scoring above 94% still
599
+ // show only the top ten.
600
+ function fifteenStripeModules() {
601
+ state.versionReads = [];
602
+ state.modules = {}; state.versions = []; state.scores = []; state.signals = []; state.prices = []; state.categories = {};
603
+ for (let i = 0; i < 15; i++) {
604
+ const key = `stripe-${String(i).padStart(2, '0')}`;
605
+ state.modules[key] = { status: 'listed', title: key };
606
+ state.versions.push({ id: 100 + i, module_key: key, version: '1.0.0', published_at: 't' });
607
+ state.scores.push({ id: 100 + i, version_id: 100 + i, computed_at: 1, ...score({ overall: 99 - i }) });
608
+ state.categories[key] = { parent: 'money', sub_key: 'stripe-payments', label: 'Stripe payments', status: 'approved' };
609
+ // The lowest scorers are best on Tests, so a sort by Tests would put them first.
610
+ state.signals.push({ id: 100 + i, version_id: 100 + i, part: 'tests', outcome: 'scored', score: 50 + i, sample_size: 10, measured_at: 1 });
611
+ }
612
+ state.modules.waiting = { status: 'listed', title: 'Waiting' };
613
+ state.versions.push({ id: 200, module_key: 'waiting', version: '1.0.0', published_at: 't' });
614
+ state.scores.push({ id: 200, version_id: 200, computed_at: 1, ...score({ overall: 60 }) });
615
+ state.categories.waiting = { parent: 'money', sub_key: 'stripe-billing', label: 'Stripe billing', status: 'proposed' };
616
+ }
617
+
618
+ test('GET /store/modules: fifteen Stripe modules above 94 show only the top ten; a proposed sub-category is not capped', async () => {
619
+ fifteenStripeModules();
620
+ const { handle } = handlerFor(buildModulesRouter(), 'get', '/store/modules');
621
+ const res = await invoke(handle, { query: {} });
622
+ assert.equal(res.body.cap, 10);
623
+ const stripe = res.body.listed.filter((m) => m.category && m.category.sub === 'stripe-payments');
624
+ assert.deepEqual(stripe.map((m) => m.overall), [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]);
625
+ assert.deepEqual(stripe[0].category, { parent: 'money', parent_title: 'Money', sub: 'stripe-payments', label: 'Stripe payments' });
626
+ const waiting = res.body.listed.find((m) => m.key === 'waiting');
627
+ assert.ok(waiting, 'a module in a proposed sub-category is listed under its parent');
628
+ assert.deepEqual(waiting.category, { parent: 'money', parent_title: 'Money', sub: null, label: null }, 'a proposed sub-category is not shown');
629
+ });
630
+
631
+ test('GET /store/modules: a sort or a maximum price reorders or narrows the ten, never lets the eleventh in', async () => {
632
+ fifteenStripeModules();
633
+ state.prices = [{ module_key: 'stripe-00', price_cents: 5000, price_credits: null, set_at: 1 }];
634
+ const { handle } = handlerFor(buildModulesRouter(), 'get', '/store/modules');
635
+ const sorted = await invoke(handle, { query: { sort: 'tests' } });
636
+ const keys = (b) => b.listed.filter((m) => m.key.startsWith('stripe-')).map((m) => m.key);
637
+ assert.deepEqual(new Set(keys(sorted.body)), new Set(Array.from({ length: 10 }, (_, i) => `stripe-0${i}`)));
638
+ assert.equal(keys(sorted.body)[0], 'stripe-09', 'the best on Tests among the ten leads');
639
+ const cheap = await invoke(handle, { query: { max_cents: '1000' } });
640
+ assert.equal(keys(cheap.body).length, 9, 'the priced one drops out and nobody takes its slot');
641
+ assert.ok(!keys(cheap.body).includes('stripe-10'));
642
+ state.prices = [];
643
+ });
644
+
645
+ test('GET /store/modules/:key/listing: the eleventh is told it is past the cap, not below the floor', async () => {
646
+ fifteenStripeModules();
647
+ const { handle } = handlerFor(buildModulesRouter(), 'get', '/store/modules/:key/listing');
648
+ const eleventh = await invoke(handle, { params: { key: 'stripe-10' } });
649
+ assert.equal(eleventh.body.listed, false);
650
+ assert.equal(eleventh.body.reason, 'over_cap');
651
+ assert.equal(eleventh.body.overall, 89);
652
+ assert.match(eleventh.body.why, /scored 89 out of 100, above the floor of 50, but it ranks 11 in Stripe payments/);
653
+ assert.match(eleventh.body.why, /top 10 in each sub-category/);
654
+ assert.ok(eleventh.body.next_step);
655
+ // One module's check reads only its own sub-category, never the whole store.
656
+ const scoped = state.versionReads.filter((r) => r);
657
+ assert.ok(scoped.length, 'the cap check reads a scoped set');
658
+ for (const r of scoped) assert.ok(!r.includes('waiting'), 'a module outside the sub-category is not read');
659
+ assert.equal(state.versionReads.filter((r) => r === null).length, 0, 'the whole store is never read for one module');
660
+ const tenth = await invoke(handle, { params: { key: 'stripe-09' } });
661
+ assert.equal(tenth.body.listed, true);
662
+ assert.equal(tenth.body.reason, 'at_or_above_floor');
663
+ });
664
+
665
+ test('the cap: the listing read and the catalog agree on every module', async () => {
666
+ fifteenStripeModules();
667
+ const catalog = (await invoke(handlerFor(buildModulesRouter(), 'get', '/store/modules').handle, { query: {} })).body;
668
+ const shown = new Set([...catalog.listed, ...catalog.new].map((m) => m.key));
669
+ const { handle } = handlerFor(buildModulesRouter(), 'get', '/store/modules/:key/listing');
670
+ for (const key of Object.keys(state.modules)) {
671
+ const r = await invoke(handle, { params: { key } });
672
+ assert.equal(r.body.listed, shown.has(key), key);
673
+ }
674
+ state.categories = {}; state.signals = [];
675
+ });