@bongos/core 1.24.8 → 1.24.10

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 (88) hide show
  1. package/.bongos-core.json +131 -86
  2. package/clients/bongos-client/README.md +1 -1
  3. package/clients/bongos-client/bongos-client.global.js +8 -0
  4. package/clients/bongos-client/index.cjs +8 -0
  5. package/clients/bongos-client/index.d.ts +11 -1
  6. package/clients/bongos-client/index.mjs +8 -0
  7. package/docs/adr/0385-money-lives-with-a-processor-credits-stay-a-project-meter.md +1 -1
  8. package/docs/api/openapi.json +185 -6
  9. package/docs/api-reference.md +7 -3
  10. package/docs/architecture.md +2 -2
  11. package/docs/copy-inventory.md +58 -28
  12. package/docs/copy-registry.json +333 -33
  13. package/docs/module-api-changelog.md +4 -0
  14. package/docs/modules-contract.md +3 -3
  15. package/docs/page-inventory.json +34 -4
  16. package/docs/page-readings.json +294 -237
  17. package/migrations/core_287_module_prices_cash_only.sql +24 -0
  18. package/modules/hall-ui/public/ai-studio.html +2 -2
  19. package/modules/hall-ui/public/atlas.html +2 -2
  20. package/modules/hall-ui/public/blockers.html +2 -2
  21. package/modules/hall-ui/public/board-room.html +2 -2
  22. package/modules/hall-ui/public/city.html +2 -2
  23. package/modules/hall-ui/public/collab.html +2 -2
  24. package/modules/hall-ui/public/commands.html +2 -2
  25. package/modules/hall-ui/public/copy-desk.html +2 -2
  26. package/modules/hall-ui/public/craft-mode.js +1 -1
  27. package/modules/hall-ui/public/deploy.html +2 -2
  28. package/modules/hall-ui/public/diagrams.html +2 -2
  29. package/modules/hall-ui/public/drachmae.html +2 -2
  30. package/modules/hall-ui/public/fleet.html +2 -2
  31. package/modules/hall-ui/public/gate.html +2 -2
  32. package/modules/hall-ui/public/goal-map.html +2 -2
  33. package/modules/hall-ui/public/goals.html +2 -2
  34. package/modules/hall-ui/public/government.html +2 -2
  35. package/modules/hall-ui/public/idea.html +2 -2
  36. package/modules/hall-ui/public/ideas.html +2 -2
  37. package/modules/hall-ui/public/index.html +2 -2
  38. package/modules/hall-ui/public/market-watch-rules.html +2 -2
  39. package/modules/hall-ui/public/market-watch-settings.css +217 -0
  40. package/modules/hall-ui/public/market-watch-settings.html +113 -0
  41. package/modules/hall-ui/public/market-watch-settings.js +230 -0
  42. package/modules/hall-ui/public/market-watch-settings.states.json +14 -0
  43. package/modules/hall-ui/public/modules.html +2 -2
  44. package/modules/hall-ui/public/modules.js +5 -0
  45. package/modules/hall-ui/public/my-agents.html +2 -2
  46. package/modules/hall-ui/public/primer.html +2 -2
  47. package/modules/hall-ui/public/profile.html +2 -2
  48. package/modules/hall-ui/public/project-settings.html +2 -2
  49. package/modules/hall-ui/public/ranks.html +2 -2
  50. package/modules/hall-ui/public/roadmap.html +2 -2
  51. package/modules/hall-ui/public/roster.html +2 -2
  52. package/modules/hall-ui/public/sessions.html +2 -2
  53. package/modules/hall-ui/public/settings.html +2 -2
  54. package/modules/hall-ui/public/shell.js +3 -0
  55. package/modules/hall-ui/public/street.html +2 -2
  56. package/modules/hall-ui/public/studio.html +2 -2
  57. package/modules/hall-ui/public/task.html +2 -2
  58. package/modules/hall-ui/public/thinking.html +2 -2
  59. package/modules/hall-ui/public/tweak-editor.html +2 -2
  60. package/modules/hall-ui/public/watch.html +2 -2
  61. package/modules/hall-ui/public/work.html +2 -2
  62. package/modules/hall-ui/records/market-watch-settings.md +11 -0
  63. package/modules/market-watch/module.json +3 -2
  64. package/modules/market-watch/routes/settings.js +128 -0
  65. package/modules/market-watch/settings.js +207 -0
  66. package/modules/provisioning/starter-bundles.js +11 -6
  67. package/modules/ui-design/kit/serve.js +1 -0
  68. package/package-lock.json +2 -2
  69. package/package.json +1 -1
  70. package/release-notes.json +12 -0
  71. package/scripts/bongos/module-store-cli.js +21 -21
  72. package/scripts/bongos/module.js +8 -8
  73. package/src/bongos/module-listing.js +47 -20
  74. package/src/bongos/module-scope-map.js +1 -0
  75. package/src/bongos/module-store.js +20 -12
  76. package/src/bongos/routes/modules.js +31 -21
  77. package/src/bongos/serve-internal.js +2 -2
  78. package/src/module-api.js +1 -1
  79. package/tests/hall_nav.mjs +4 -2
  80. package/tests/hall_page_gate_map.mjs +4 -0
  81. package/tests/market_watch_data_db.mjs +27 -0
  82. package/tests/market_watch_module.mjs +8 -4
  83. package/tests/market_watch_settings.mjs +392 -0
  84. package/tests/module_store_cli.mjs +14 -3
  85. package/tests/module_store_listing.mjs +65 -14
  86. package/tests/module_store_price.mjs +97 -26
  87. package/tests/module_store_registry_migration.mjs +11 -0
  88. package/tests/nav_permission_atoms.mjs +3 -2
@@ -135,39 +135,57 @@ function sortByPart(entries, part) {
135
135
  // can both check in one sentence:
136
136
  //
137
137
  // highest overall score first; between equal scores the cheaper module first
138
- // (free first, then the lowest cash price, then the lowest credit price); then
139
- // the key.
138
+ // (free first, then the lowest cash price, a module whose cash price is still
139
+ // coming last); then the key.
140
140
  //
141
141
  // Price never buys a better place: it only orders modules the score could not tell
142
142
  // apart (price is never an input to the score, ADR 0343 D6). A buyer may also set a
143
143
  // maximum price, which leaves out what costs more — a filter, not a ranking.
144
144
  const RANKING = 'Highest overall score first; between equal scores, free modules and then the cheapest come first.';
145
145
 
146
- // A module's current price row ({ price_cents, price_credits } or none) as the
147
- // catalog shows it. No row is free (isFreePrice, module-store.js); 0 in either
148
- // currency is free; null means not offered in that currency (core_257). Pure.
146
+ // CREDITS NEVER PRICE A MODULE (task 1004989, ADR 0385 decision 2). Credits are a
147
+ // contribution meter: a credit price would make them stored value. New price rows
148
+ // carry cents only (core_287 refuses price_credits). An OLD row may still carry a
149
+ // credit price; the owner's ruling (2026-10-29) is that such a module stays
150
+ // VISIBLE with a "price coming" note and can NOT be bought with credits, while
151
+ // its author is asked to set a cash price.
152
+ //
153
+ // A module's current price row as the catalog shows it: { cents, free, coming }.
154
+ // Never a credit amount. No row is free (isFreePrice, module-store.js); a cash
155
+ // price of 0 is free. An old row that offered it at 0 credits stays free, as it
156
+ // was: its author offered it at nothing, and no credit moves to have it. An old row whose
157
+ // only price was a positive number of credits is `coming` — no cash price yet,
158
+ // so not free and not buyable. Pure.
149
159
  function priceOf(row) {
150
160
  const cents = row && row.price_cents != null ? Number(row.price_cents) : null;
151
- const credits = row && row.price_credits != null ? Number(row.price_credits) : null;
152
- return { cents, credits, free: !row || cents === 0 || credits === 0 };
161
+ const legacyCredits = row && row.price_credits != null ? Number(row.price_credits) : null;
162
+ const free = !row || cents === 0 || legacyCredits === 0;
163
+ return { cents, free, coming: !free && cents == null };
153
164
  }
154
165
 
155
- // Whether a module can be bought today. Buying arrives with task 1003788 (area 8's
156
- // wallet); until then only a free module can be had, and a paid one is listed with
157
- // its price and marked not yet buyable (owner, 2026-10-26). Flip BUYING_OPEN when
158
- // the buy action ships, and nothing else needs to change. Pure.
166
+ // What the author of a "price coming" module is asked (task 1004989). One string,
167
+ // so the listing read, the CLI and the hall say the same thing.
168
+ const PRICE_COMING_PROMPT = 'This module still has a price in credits, and credits can no longer price or buy a module. '
169
+ + 'It stays listed with "price coming" until you set a cash price: bongos module price <key> --cents N (0 makes it free).';
170
+
171
+ // Whether a module can be bought today. Buying arrives with task 1003788; until
172
+ // then only a free module can be had, and a paid one is listed with its price and
173
+ // marked not yet buyable (owner, 2026-10-26). Flip BUYING_OPEN when the buy action
174
+ // ships. A module whose cash price is still coming stays unbuyable even then:
175
+ // there is nothing to pay in but credits, and credits do not buy. Pure.
159
176
  const BUYING_OPEN = false;
160
177
  function buyableNow(price) {
161
- return !!(price && (price.free || BUYING_OPEN));
178
+ return !!(price && (price.free || (BUYING_OPEN && price.cents != null)));
162
179
  }
163
180
 
164
- // Within a buyer's maximum ({ cents, credits }, either may be null): a free module
165
- // always is; a priced one is when it is offered at or under a cap the buyer set. Pure.
181
+ // Within a buyer's maximum cash price ({ cents }, or null for no cap): a free
182
+ // module always is; a priced one is when its cash price is at or under the cap.
183
+ // A module whose price is still coming has no cash price to compare, so a cap
184
+ // leaves it out. Pure.
166
185
  function withinMaxPrice(price, max) {
167
- if (!max || (max.cents == null && max.credits == null)) return true;
186
+ if (!max || max.cents == null) return true;
168
187
  if (price.free) return true;
169
- return (max.cents != null && price.cents != null && price.cents <= max.cents)
170
- || (max.credits != null && price.credits != null && price.credits <= max.credits);
188
+ return price.cents != null && price.cents <= max.cents;
171
189
  }
172
190
 
173
191
  // The default order of `listed`, per RANKING. Returns a new array. Pure.
@@ -179,7 +197,6 @@ function rankListed(entries) {
179
197
  return ((b.overall ?? -1) - (a.overall ?? -1))
180
198
  || (Number(pb.free) - Number(pa.free))
181
199
  || (cheap(pa.cents) - cheap(pb.cents))
182
- || (cheap(pa.credits) - cheap(pb.credits))
183
200
  || a.key.localeCompare(b.key);
184
201
  });
185
202
  }
@@ -292,8 +309,8 @@ async function buildCatalog({ db, floor = QUALITY_FLOOR, sort = null, maxPrice =
292
309
  signals.get(k).push(s);
293
310
  }
294
311
  }
295
- const max = maxPrice && (maxPrice.cents != null || maxPrice.credits != null)
296
- ? { cents: maxPrice.cents ?? null, credits: maxPrice.credits ?? null } : null;
312
+ // A cash cap only (task 1004989): credits are never a price, so never a cap.
313
+ const max = maxPrice && maxPrice.cents != null ? { cents: maxPrice.cents } : null;
297
314
  const cats = await readModuleCategories(newest.map((r) => r.module_key), { db: pool });
298
315
  const out = { floor, cap: CAP_PER_SUBCATEGORY, ranking: RANKING, sort: sort || null, sort_parts: SORT_PARTS, max_price: max, listed: [], new: [] };
299
316
  for (const r of newest.sort((a, b) => a.module_key.localeCompare(b.module_key))) {
@@ -421,14 +438,24 @@ async function readListing(key, { db, floor = QUALITY_FLOOR, viewerId = null } =
421
438
  if (held) placed = { placement: 'excluded', reason: 'over_cap' };
422
439
  }
423
440
  const overall = score && placed.placement !== 'new' ? score.overall : null;
441
+ // The price as the catalog shows it, and — to the author only — the ask to set a
442
+ // cash price when the module still carries only an old credit price (task
443
+ // 1004989; the owner's ruling, 2026-10-29). Read by idx_store_module_prices_current.
444
+ const { rows: [priceRow] } = await pool.query(
445
+ `SELECT price_cents, price_credits FROM store_module_prices
446
+ WHERE module_key = $1 ORDER BY set_at DESC, id DESC LIMIT 1`, [key]);
447
+ const price = priceOf(priceRow || null);
424
448
  return {
425
449
  ...head, version: newest.version, version_id: newest.version_id, overall,
426
450
  ...explainPlacement(placed, { overall, floor, security, weaknesses: reading.weaknesses, held }),
427
451
  security, ...reading,
452
+ price, buyable: buyableNow(price),
453
+ price_prompt: isAuthor && price.coming ? PRICE_COMING_PROMPT : null,
428
454
  };
429
455
  }
430
456
 
431
457
  module.exports = {
432
458
  QUALITY_FLOOR, STRONG_AT, SORT_PARTS, RANKING, CAP_PER_SUBCATEGORY, placeVersion, readParts,
433
459
  sortByPart, priceOf, withinMaxPrice, rankListed, applyCap, listCatalog, explainPlacement, readListing,
460
+ PRICE_COMING_PROMPT,
434
461
  };
@@ -201,6 +201,7 @@ const MODULE_GLOBS = {
201
201
  // task 1004941: the rules page (proposals, decisions, the run's prompt fence)
202
202
  'tests/market_watch_rules.mjs', 'tests/market_watch_rules_db.mjs',
203
203
  'tests/market_watch_ask.mjs', 'tests/market_watch_ask_db.mjs',
204
+ 'tests/market_watch_settings.mjs',
204
205
  ],
205
206
  // --- builder prefs (wandering/skill/sound/render) + builder-needs ---
206
207
  // Carved into modules/builder-settings/ (BV1.R80 / ADR 0093 §1): the five pref
@@ -254,8 +254,11 @@ async function publishVersion(input, { db, beforeCommit } = {}) {
254
254
  // A module with NO price row is free. The owner decided this (2026-09-29): nothing
255
255
  // sets a price yet and who may sell is still open, so an unpriced module is
256
256
  // acquirable at no cost, and an entitlement taken then is kept if a price is added
257
- // later (ADR 0338 D2). A priced module is free when either currency it is offered in
258
- // is zero (0 = free, NULL = not offered in that currency; core_257).
257
+ // later (ADR 0338 D2). A priced module is free when its cash price is zero. An old
258
+ // row that offered it at 0 credits also stays free, as it was — its author offered
259
+ // it at nothing and no credit moves to have it (task 1004989; module-listing.js priceOf
260
+ // reads the same rule). An old row priced only in credits above 0 is NOT free:
261
+ // its cash price is still coming, and credits never buy a module.
259
262
  function isFreePrice(priceRow) {
260
263
  if (!priceRow) return true;
261
264
  return priceRow.price_cents === 0 || priceRow.price_credits === 0;
@@ -387,20 +390,25 @@ async function latestVersions(keys, { db, channelsFor = null } = {}) {
387
390
  // author may, and a delisted module takes no new price (it can no longer be
388
391
  // acquired). The price is a HISTORY: each change appends a row and the newest is
389
392
  // current, which is what the catalog (module-listing.js priceOf) and acquire
390
- // (isFreePrice above) already read. `cents` / `credits`: a whole number of 0 or
391
- // more, or null for "not offered in that currency"; at least one must be given
392
- // (core_257's CHECK), and 0 in either is free. A paid price may be set before
393
+ // (isFreePrice above) already read. `cents`: a whole number of 0 or more; 0 is
394
+ // free. A paid price may be set before
393
395
  // buying exists (owner, 2026-10-26): the module is listed with it and marked not yet
394
396
  // buyable, and acquire keeps refusing it without an entitlement. Price is never an
395
397
  // input to the score (ADR 0343 D6). The history IS the audit of price changes:
396
398
  // every row names who set it and when, and the row before it is what it changed
397
399
  // from (the audit middleware also logs the request). One transaction, the module row
398
400
  // locked FOR UPDATE as publishVersion does, so two changes at once each report the
399
- // price they really replaced. Returns { ok: true, previous, price } (each
400
- // { cents, credits } or null) or { ok: false, status, code, message }.
401
- async function setPrice({ key, cents = null, credits = null, builderId }, { db } = {}) {
401
+ // price they really replaced. Returns { ok: true, previous, price } or
402
+ // { ok: false, status, code, message }.
403
+ //
404
+ // CASH ONLY (task 1004989, ADR 0385 decision 2): credits never price a module, so
405
+ // a new row carries cents and nothing else (core_287 refuses price_credits in the
406
+ // database too). `previous` reports the replaced row's cash price, and `coming:
407
+ // true` when that row priced the module in credits only.
408
+ async function setPrice({ key, cents, builderId }, { db } = {}) {
402
409
  const pool = db || require('./pool').pool;
403
410
  const refuse = (status, code, message) => ({ ok: false, status, code, message });
411
+ if (!Number.isInteger(cents) || cents < 0) return refuse(400, 'bad_price', 'A price is a whole number of cents, 0 or more. 0 makes the module free.');
404
412
  const client = await pool.connect();
405
413
  try {
406
414
  await client.query('BEGIN');
@@ -415,13 +423,13 @@ async function setPrice({ key, cents = null, credits = null, builderId }, { db }
415
423
  `SELECT price_cents, price_credits FROM store_module_prices
416
424
  WHERE module_key = $1 ORDER BY set_at DESC, id DESC LIMIT 1`, [key]);
417
425
  await client.query(
418
- 'INSERT INTO store_module_prices (module_key, price_cents, price_credits, set_by) VALUES ($1, $2, $3, $4)',
419
- [key, cents, credits, builderId]);
426
+ 'INSERT INTO store_module_prices (module_key, price_cents, set_by) VALUES ($1, $2, $3)',
427
+ [key, cents, builderId]);
420
428
  await client.query('COMMIT');
421
429
  return {
422
430
  ok: true,
423
- previous: prev ? { cents: prev.price_cents, credits: prev.price_credits } : null,
424
- price: { cents, credits },
431
+ previous: prev ? { cents: prev.price_cents, coming: prev.price_cents == null && Number(prev.price_credits) > 0 } : null,
432
+ price: { cents },
425
433
  };
426
434
  } catch (e) {
427
435
  try { await client.query('ROLLBACK'); } catch { /* the connection may be gone */ }
@@ -576,9 +576,9 @@ module.exports = function buildModulesRouter() {
576
576
  }));
577
577
 
578
578
  // POST /api/bongos/store/modules/:key/price — the module's author sets its price
579
- // (task 1004894, criterion wa5-module-economy). Body: { cents?, credits? }, each a
580
- // whole number of 0 or more, or null for "not offered in that currency"; at least
581
- // one is given, and 0 in either is free. Appends a row to the price history; the
579
+ // (task 1004894, criterion wa5-module-economy). Body: { cents }, a whole number of
580
+ // 0 or more; 0 is free. A credit price is refused (task 1004989, ADR 0385
581
+ // decision 2: credits never price or buy a module). Appends a row to the price history; the
582
582
  // newest is what the catalog shows and what acquire charges. A paid price may be
583
583
  // set before buying exists (owner, 2026-10-26): the catalog marks it not yet
584
584
  // buyable. Price never moves the score (ADR 0343 D6). The audit middleware records
@@ -588,21 +588,24 @@ module.exports = function buildModulesRouter() {
588
588
  // author check inside setPrice: only the person who published the module prices it.
589
589
  router.post('/store/modules/:key/price', auth.requireBuilder, auth.requirePermission('module.submit'),
590
590
  asyncHandler('POST /store/modules/:key/price', async (req, res) => {
591
- const AMOUNT = { type: 'integer', min: 0, max: 100000000 };
592
- if (validateOrRespond(req, res, { cents: AMOUNT, credits: AMOUNT })) return;
591
+ const body = req.body || {};
592
+ // Refused before anything else, by name, so an older CLI that still sends
593
+ // credits is told why rather than seeing a generic validation error.
594
+ if (body.credits != null) {
595
+ return res.fail('credit_price_refused', { status: 400, message: 'Credits cannot price a module: they measure contribution and are never spent. Set a cash price in cents (0 makes it free).' });
596
+ }
597
+ if (validateOrRespond(req, res, { cents: { type: 'integer', min: 0, max: 100000000 } })) return;
593
598
  const { key } = req.params;
594
599
  if (!KEY_RE.test(key)) {
595
600
  return res.fail('bad_module_key', { status: 400, message: 'A module key is lowercase kebab-case.' });
596
601
  }
597
- const body = req.body || {};
598
602
  const cents = body.cents ?? null;
599
- const credits = body.credits ?? null;
600
- if (cents === null && credits === null) {
601
- return res.fail('bad_price', { status: 400, message: 'Give a price in cents, credits or both. 0 in either makes the module free.' });
603
+ if (cents === null) {
604
+ return res.fail('bad_price', { status: 400, message: 'Give a price in cents. 0 makes the module free.' });
602
605
  }
603
- const out = await setPrice({ key, cents, credits, builderId: req.builder.id });
606
+ const out = await setPrice({ key, cents, builderId: req.builder.id });
604
607
  if (!out.ok) return res.fail(out.code, { status: out.status, message: out.message });
605
- log.info({ key, builderId: req.builder.id, cents, credits }, `${key} price set`);
608
+ log.info({ key, builderId: req.builder.id, cents }, `${key} price set`);
606
609
  res.json({ ok: true, module_key: key, previous: out.previous, price: out.price });
607
610
  }));
608
611
 
@@ -772,9 +775,14 @@ module.exports = function buildModulesRouter() {
772
775
  let held = await checkEntitlement(holder);
773
776
  if (!held.entitled) {
774
777
  if (!r.free) {
778
+ // Never "pay with credits" (task 1004989): credits are never spent. A
779
+ // module still carrying only an old credit price has no cash price yet.
780
+ const coming = r.price && r.price.price_cents == null;
775
781
  return res.fail('payment_required', {
776
782
  status: 402,
777
- message: `"${key}" is priced, and buying a module is not available yet (it arrives with the credit economy, area 8).`,
783
+ message: coming
784
+ ? `"${key}" has no cash price yet: its author has been asked to set one. Credits cannot buy a module.`
785
+ : `"${key}" is priced, and buying a module is not available yet.`,
778
786
  });
779
787
  }
780
788
  const g = await grantEntitlement({ ...holder, source: 'free', grantedBy: req.builder.id });
@@ -917,8 +925,7 @@ module.exports = function buildModulesRouter() {
917
925
  // `?sort=<part>` orders the listed modules by the part a buyer cares about
918
926
  // (task 1003800, sortByPart); the parts it accepts come back as sort_parts.
919
927
  // Without it the listed modules are ranked quality first, price breaking ties
920
- // (task 1003808, rankListed); `?max_cents=` / `?max_credits=` leave out modules
921
- // that cost more.
928
+ // (task 1003808, rankListed); `?max_cents=` leaves out modules that cost more.
922
929
  //
923
930
  // rank: any-builder — a read of public store metadata, like /store/modules/latest:
924
931
  // no entitlement taken, nothing changed.
@@ -930,16 +937,19 @@ module.exports = function buildModulesRouter() {
930
937
  const names = SORT_PARTS.map((p) => `${p.title} (${p.part})`).join(', ');
931
938
  return res.fail('bad_request', { status: 400, message: `The store can be sorted by one part of the score: ${names}.` });
932
939
  }
933
- // An optional maximum price (task 1003808): ?max_cents= and/or ?max_credits=,
934
- // each a whole number of at least 0. Free modules always pass.
940
+ // An optional maximum price (task 1003808): ?max_cents=, a whole number of at
941
+ // least 0. Free modules always pass. There is no credit cap (task 1004989):
942
+ // credits never price a module, so ?max_credits= is refused by name.
943
+ if (req.query && req.query.max_credits != null) {
944
+ return res.fail('bad_request', { status: 400, message: 'Credits do not price modules, so there is no maximum in credits. Use max_cents.' });
945
+ }
935
946
  const maxPrice = {};
936
- for (const [param, field] of [['max_cents', 'cents'], ['max_credits', 'credits']]) {
937
- const v = req.query && req.query[param];
938
- if (v == null || v === '') continue;
947
+ const v = req.query && req.query.max_cents;
948
+ if (v != null && v !== '') {
939
949
  if (typeof v !== 'string' || !/^\d{1,9}$/.test(v)) {
940
- return res.fail('bad_request', { status: 400, message: `${param} is a maximum price: a whole number, 0 or more.` });
950
+ return res.fail('bad_request', { status: 400, message: 'max_cents is a maximum price: a whole number, 0 or more.' });
941
951
  }
942
- maxPrice[field] = Number(v);
952
+ maxPrice.cents = Number(v);
943
953
  }
944
954
  const listing = await listCatalog({ sort, maxPrice });
945
955
  res.set('Cache-Control', 'no-store');
@@ -1323,9 +1323,9 @@ function mountInternalSurfaces(app) {
1323
1323
  // Claude works for them. Every read behind it is the viewer's own and
1324
1324
  // requireBuilder (GET /me and its /me/* prefs, /specialities), so sign-in is the
1325
1325
  // whole gate; the governing reads it adds are gated by their own routes.
1326
- // task 1004921: `ai-studio`, the studio's AI pages; every route behind it is the viewer's own.
1326
+ // tasks 1004921 `ai-studio` (the viewer's own routes), 1004938 `market-watch-settings` (no data; owner-only routes).
1327
1327
  const SIGNEDIN_BUILDERS_PAGE_RE =
1328
- /^\/builders\/(?:work|settings|atlas|modules|goals|goal-map|roadmap|copy-desk|studio|ai-studio|tweak-editor|ideas|thinking|collab|task|idea|primer(?:\.md)?|diagrams|my-agents|commands)(?:\.html)?\/?$/;
1328
+ /^\/builders\/(?:work|settings|atlas|modules|goals|goal-map|roadmap|copy-desk|studio|ai-studio|tweak-editor|ideas|thinking|collab|task|idea|primer(?:\.md)?|diagrams|my-agents|market-watch-settings|commands)(?:\.html)?\/?$/;
1329
1329
  // The diagram image assets under /builders/diagrams/ ride the same tier as the
1330
1330
  // page that embeds them.
1331
1331
  const SIGNEDIN_BUILDERS_PREFIX_RE = /^\/builders\/diagrams\//;
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.24.8'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
84
+ const CORE_VERSION = '1.24.10'; // 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');
@@ -318,7 +318,9 @@ test('sidebar groups read by audience, in order', () => {
318
318
  // the steering surfaces because that is what it is — the owner's third release gate.
319
319
  // 'fleet' (task 1001949) follows it at the metic floor of `provisioning.fleet.manage`:
320
320
  // what each hosted project costs is an operator surface, like the rest of this group.
321
- assert.deepEqual(nav[4].items.map((i) => i.id), ['watch', 'gate', 'sessions', 'project-settings', 'deploy', 'fleet', 'government']);
321
+ // 'market-watch-settings' (task 1004938) is the owner's Market Watch switch and AI cap,
322
+ // archon like its four routes, and dropped where the market-watch module is off.
323
+ assert.deepEqual(nav[4].items.map((i) => i.id), ['watch', 'gate', 'sessions', 'project-settings', 'deploy', 'fleet', 'market-watch-settings', 'government']);
322
324
  });
323
325
 
324
326
  test('Economy lives in Docs and points at the reward-schedule page', () => {
@@ -750,7 +752,7 @@ test('no glyph path data reads as an IP address to the release leak scan', () =>
750
752
  // block (task 1004713). These drive the real shell and the real gov-positions.js.
751
753
 
752
754
  const tick = () => new Promise((resolve) => setImmediate(resolve));
753
- const GOVERNING = ['board-room', 'city', 'watch', 'gate', 'sessions', 'project-settings', 'deploy', 'fleet', 'government'];
755
+ const GOVERNING = ['board-room', 'city', 'watch', 'gate', 'sessions', 'project-settings', 'deploy', 'fleet', 'market-watch-settings', 'government'];
754
756
  const lead = (building, title) => ({ kind: 'lead', seat: 'lead:' + building, building, title });
755
757
  const block = (held) => ({ held, title: held.length ? held[0].title : null, has_position: held.length > 0 });
756
758
 
@@ -56,6 +56,10 @@ const ORACLE = {
56
56
  // settings. Every read behind it is the viewer's own (GET /me, /me/* prefs,
57
57
  // /specialities) and requireBuilder, so sign-in is the whole gate.
58
58
  '/builders/my-agents': 'requireBuilderPage',
59
+ // task 1004938: the owner's Market Watch settings. Its read and writes are
60
+ // owner-only (atom + owner seat) (tests/market_watch_settings.mjs proves the 403s), and the
61
+ // shell carries no data, so sign-in is the page tier and the routes are the wall.
62
+ '/builders/market-watch-settings': 'requireBuilderPage',
59
63
  '/builders/goals': 'requireBuilderPage',
60
64
  // task 1003479: the goal map, on the goal board's tier. task 1004232 (sky part 4):
61
65
  // the URL now serves THE PROJECT SKY (the same page as /thinking, in its whole-project
@@ -31,6 +31,8 @@ const MIGRATION_002 = readFileSync(new URL('../modules/market-watch/migrations/m
31
31
  const MIGRATION_003 = readFileSync(new URL('../modules/market-watch/migrations/market_watch_003_ask_pool.sql', import.meta.url), 'utf8');
32
32
  const run = require('../modules/market-watch/run.js');
33
33
  const store = require('../modules/market-watch/store.js');
34
+ const settings = require('../modules/market-watch/settings.js');
35
+ const key = require('../modules/market-watch/key.js');
34
36
 
35
37
  const pool = new Pool({ connectionString: process.env.DATABASE_URL || undefined });
36
38
  try {
@@ -295,6 +297,31 @@ try {
295
297
  assert.equal(await store.openRun(pool, P), null);
296
298
  });
297
299
 
300
+ // task 1004938: the owner's settings writes, on the real table, read back by the run's
301
+ // own readers (store.readSettings, key.readProjectKey).
302
+ await check('the settings page writes what the run reads: switch, cap, cadence and the sealed key', async () => {
303
+ const box = { encrypt: (s) => `v1.iv.tag.${Buffer.from(s).toString('base64url')}`, decrypt: (b) => Buffer.from(b.split('.')[3], 'base64url').toString() };
304
+ await q(`DELETE FROM market_watch_settings WHERE project = $1`, [OTHER]);
305
+ // A first write of one field creates the row with the defaults for the rest.
306
+ assert.deepEqual(await settings.writeSettings(pool, OTHER, { cadence: 'monthly' }, ALICE), { enabled: false, monthly_cap_usd: 20, cadence: 'monthly' });
307
+ assert.deepEqual(await settings.writeSettings(pool, OTHER, { enabled: true, monthly_cap_usd: 35.5 }, ALICE), { enabled: true, monthly_cap_usd: 35.5, cadence: 'monthly' });
308
+ const st = store.createStore(pool);
309
+ assert.equal((await st.readSettings(OTHER)).enabled, true);
310
+ await settings.writeSettings(pool, OTHER, { enabled: false }, BOB);
311
+ assert.deepEqual(await st.readSettings(OTHER), { enabled: false, monthly_cap_usd: 35.5, cadence: 'monthly', configured: true });
312
+ assert.deepEqual(await settings.setKey(pool, OTHER, 'sk-ant-api03-db-test-key-LMNO', ALICE, { encrypt: box.encrypt }), { key_set: true });
313
+ assert.equal(await key.readProjectKey(pool, OTHER, { decrypt: box.decrypt }), 'sk-ant-api03-db-test-key-LMNO');
314
+ const view = await settings.readView(pool, OTHER, { ceilingUsd: 0.27, storageConfigured: true });
315
+ assert.equal(view.key_set, true);
316
+ assert.ok(!JSON.stringify(view).includes('LMNO'), 'the view never carries the key or its last four');
317
+ assert.deepEqual(await settings.clearKey(pool, OTHER, ALICE), { key_set: false, removed: true });
318
+ assert.deepEqual(await settings.clearKey(pool, OTHER, ALICE), { key_set: false, removed: false });
319
+ assert.equal(await key.readProjectKey(pool, OTHER, { decrypt: box.decrypt }), null);
320
+ // P's row was never touched by OTHER's writes.
321
+ assert.notEqual((await st.readSettings(P)).monthly_cap_usd, 35.5);
322
+ await q(`DELETE FROM market_watch_settings WHERE project = $1`, [OTHER]);
323
+ });
324
+
298
325
  await check('one open run per project, and the key must be a secret-box blob', async () => {
299
326
  await q(`INSERT INTO market_watch_runs (project, status, trigger) VALUES ($1, 'queued', 'manual')`, [OTHER]);
300
327
  await refused(`INSERT INTO market_watch_runs (project, status, trigger) VALUES ($1, 'running', 'poller')`, [OTHER], 'a second open run');
@@ -2,7 +2,7 @@
2
2
  // the loader, and an instance boots with it present and DISABLED (task 1004935, goal
3
3
  // 1000137). DB-free, so it runs in the unit lane.
4
4
  //
5
- // Task 1004940 mounted its first routes (the weekly ask); task 1004936 gave it its tables and a one-shot hub seed
5
+ // Task 1004940 mounted its first routes (the weekly ask), task 1004938 the owner settings routes; task 1004936 gave it its tables and a one-shot hub seed
6
6
  // poller (tests/market_watch_data.mjs covers those). What this file
7
7
  // pins is everything the later Market Watch tasks will stand on:
8
8
  // 1. the manifest validates, ships default:false, and declares spend.requiresPayer;
@@ -40,6 +40,7 @@ test('the manifest validates, ships disabled, declares a payer, and contributes
40
40
  assert.equal(c.migrations, true);
41
41
  for (const p of ['hub-seed', 'weekly-run', 'weekly-ask']) assert.ok(c.pollers.includes(p), `poller ${p}`);
42
42
  assert.ok(c.routes.includes('ask'), 'the weekly ask routes');
43
+ assert.ok(c.routes.includes('settings'), 'the owner settings routes (task 1004938, tests/market_watch_settings.mjs)');
43
44
  assert.ok(c.uiSections.includes('weekly-ask'), 'the weekly ask hall slice (hallWidgetScripts needs a uiSection)');
44
45
  assert.ok(c.routes.includes('rules'), 'the rules page routes (task 1004941)');
45
46
  });
@@ -72,14 +73,17 @@ test('the spend guard bites it: an open door with no payer cannot enable it; a c
72
73
  assert.equal(mods.resolveModules({ instance: on, registry, spendGuard: { joinDoorOpen: false, payer: null }, warn: silent })[KEY], true);
73
74
  });
74
75
 
75
- test('it has a scope-roster key, and the creation picker does not offer it while it is empty', () => {
76
+ test('it has a scope-roster key, and the creation picker offers it, off, now its switch exists', () => {
76
77
  assert.ok(Array.isArray(scopeMap.MODULE_GLOBS[KEY]) && scopeMap.MODULE_GLOBS[KEY].includes('modules/market-watch/'));
77
78
  // Every entry is an exact path or a dir prefix (the touches[] convention has no
78
79
  // wildcards), and this test's own path resolves to the module's scope.
79
80
  for (const g of scopeMap.MODULE_GLOBS[KEY]) assert.ok(!g.includes('*'), `wildcard glob never matches: ${g}`);
80
81
  assert.ok(scopeMap.MODULE_GLOBS[KEY].includes('tests/market_watch_module.mjs'));
81
- assert.ok(bundles.HUB_ONLY_MODULES.includes(KEY));
82
- assert.ok(!bundles.OPTIONAL_MODULES.some((m) => m.key === KEY));
82
+ // Task 1004938 shipped the owner's switch (routes/settings.js), so it left the hub-only
83
+ // list for the opt-in catalog, with owner-facing copy. Opt-in, never always-on.
84
+ assert.ok(!bundles.HUB_ONLY_MODULES.includes(KEY));
85
+ const offered = bundles.OPTIONAL_MODULES.find((m) => m.key === KEY);
86
+ assert.ok(offered && offered.label && offered.summary, 'offered with copy an owner can read');
83
87
  assert.ok(!bundles.ALWAYS_ON_CORE.includes(KEY));
84
88
  });
85
89