@bongos/core 1.24.29 → 1.24.30

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 (39) hide show
  1. package/.bongos-core.json +78 -38
  2. package/clients/bongos-client/README.md +1 -1
  3. package/clients/bongos-client/bongos-client.global.js +4 -0
  4. package/clients/bongos-client/index.cjs +4 -0
  5. package/clients/bongos-client/index.d.ts +4 -0
  6. package/clients/bongos-client/index.mjs +4 -0
  7. package/docs/api/openapi.json +36 -1
  8. package/docs/api-reference.md +7 -1
  9. package/docs/copy-inventory.md +86 -89
  10. package/docs/copy-registry.json +137 -175
  11. package/docs/module-api-changelog.md +2 -0
  12. package/docs/page-inventory.json +3 -2
  13. package/docs/page-readings.json +89 -107
  14. package/modules/government/db.js +29 -0
  15. package/modules/government/docket.js +61 -4
  16. package/modules/government/routes/government.js +2 -0
  17. package/modules/hall-ui/public/builders.js +3 -79
  18. package/modules/hall-ui/public/hall-render.js +6 -81
  19. package/modules/hall-ui/public/hall-widgets.js +4 -45
  20. package/modules/hall-ui/public/home-city-draw.js +275 -0
  21. package/modules/hall-ui/public/home-city.css +66 -0
  22. package/modules/hall-ui/public/home-city.js +223 -0
  23. package/modules/hall-ui/public/index.html +5 -6
  24. package/modules/hall-ui/public/index.states.json +73 -8
  25. package/modules/hall-ui/records/home-city.md +66 -0
  26. package/modules/lifecycle/home-city.js +340 -0
  27. package/modules/lifecycle/module.json +1 -0
  28. package/modules/lifecycle/routes/home-city.js +29 -0
  29. package/package-lock.json +2 -2
  30. package/package.json +1 -1
  31. package/release-notes.json +10 -0
  32. package/src/module-api.js +1 -1
  33. package/tests/claim_from_task_and_home.mjs +8 -43
  34. package/tests/hall_board_world.mjs +10 -12
  35. package/tests/hall_home_ships_bounded.mjs +4 -3
  36. package/tests/home_bounded_reads.mjs +16 -31
  37. package/tests/home_city.mjs +385 -0
  38. package/tests/home_city_widget.mjs +120 -0
  39. package/tests/leaderboard_roles.mjs +3 -2
@@ -0,0 +1,340 @@
1
+ 'use strict';
2
+
3
+ // modules/lifecycle/home-city.js — the weekly summary behind Home's project city
4
+ // (task 1005054, the owner's Home redesign).
5
+ //
6
+ // WHY. Home became one scene (modules/hall-ui/public/home-city.js): a tower per
7
+ // working area as tall as what has shipped there, a ladder of the week's builders,
8
+ // and a slider that replays the last few weeks. Drawing that from the browser would
9
+ // mean downloading every shipped task, idea and vote and slicing it — the read the
10
+ // hall's bounded-reads rule forbids (modules/hall-ui/CLAUDE.md: a Home card asks
11
+ // the server for what it draws). So it is counted here, in SQL, grouped by week:
12
+ // the response grows with the number of areas, builders and weeks, never with the
13
+ // corpus.
14
+ //
15
+ // WHAT IT ANSWERS, for the last N weeks (Monday-start, UTC; the last is this week):
16
+ // areas — each open, non-maintenance goal of the version being built (the focus
17
+ // version, else the newest one building): what it had shipped before the
18
+ // window, then per week, split into art (artist and ui work — economy's
19
+ // credits-by-craft rule) and build, and the builder who shipped most there.
20
+ // people — per builder per week: tasks shipped (build / art), ideas filed, and
21
+ // govern acts (board votes cast, blockers resolved).
22
+ // ideas — the window's ideas for the sky, newest first, bounded, each with the
23
+ // goal of the task it became.
24
+ // now — who holds an open claim in each area (an Autobongos runner working it
25
+ // marks the site as an agent's), and how many matters in each area
26
+ // wait on THIS viewer.
27
+ //
28
+ // "WAITS ON YOU" IS THE DOCKET'S OWN ANSWER (task 1005056). The government port's
29
+ // yoursByGoal(viewer) routes the docket's goal-shaped matters (blockers, criteria
30
+ // awaiting sign-off, goal join requests) with modules/government/routing.js and
31
+ // counts, per goal, those whose route is the viewer's — so a seated Lead, a board
32
+ // member or an access holder sees their own dots, and the city never disagrees
33
+ // with the docket. The port is resolved optionally (not declared in `consumes`):
34
+ // with government switched off, an older government without the method, or seats
35
+ // it could not read, the city falls back to the old approximation — open blockers
36
+ // whose stored ask waits on `owner` (or that carry none), shown only to an Archon.
37
+ //
38
+ // MODULE BOUNDARY: reaches core only through the published doorway. The ideas,
39
+ // blockers, government and autonomy tables are READ in SQL (a cross-table read
40
+ // crosses the wall, a cross-module require does not — modules/ideas/CLAUDE.md);
41
+ // the two module tables are probed with to_regclass first, so a project with
42
+ // government or autonomy switched off answers without them rather than failing.
43
+
44
+ const api = require('../../src/module-api');
45
+
46
+ const log = api.logger('lifecycle');
47
+
48
+ const MIN_WEEKS = 4;
49
+ const MAX_WEEKS = 26;
50
+ const DEFAULT_WEEKS = 10;
51
+ const MAX_AREAS = 30;
52
+ const MAX_IDEAS = 120;
53
+ const ART_DISCIPLINES = Object.freeze(['artist', 'ui']);
54
+ // modules/ideas/skill-friction.js holds the original; a module may not require a
55
+ // sibling, so the two markers are mirrored here (an Xenos viewer never sees them).
56
+ const SKILL_FRICTION_KIND = 'skill-friction';
57
+ const SKILL_FRICTION_TAG = '[skill-friction]';
58
+ const SMOKE_TITLE = '\\_\\_smoke\\_\\_%';
59
+
60
+ function clampWeeks(v) {
61
+ const n = Number.parseInt(v, 10);
62
+ if (!Number.isFinite(n)) return DEFAULT_WEEKS;
63
+ return Math.max(MIN_WEEKS, Math.min(MAX_WEEKS, n));
64
+ }
65
+
66
+ // week index of a timestamp column against the window start ($ref), as SQL
67
+ const wk = (col, ref) => `floor(extract(epoch FROM (${col} - ${ref}::timestamptz)) / 604800)::int`;
68
+
69
+ async function tableExists(pool, name) {
70
+ const { rows } = await pool.query('SELECT to_regclass($1) IS NOT NULL AS ok', [`public.${name}`]);
71
+ return !!(rows[0] && rows[0].ok);
72
+ }
73
+
74
+ // The project's focus version when one is set, else db-versions.js
75
+ // currentBuildingVersionId's rule (building only, newest started first, id breaks a
76
+ // tie) — the version the roadmap and Goals already lead with.
77
+ async function versionBeingBuilt(pool, deps) {
78
+ const focus = await (deps.getFocusVersionId || api.projectSettings.getFocusVersionId)().catch(() => null);
79
+ const { rows } = await pool.query(
80
+ `SELECT id, name FROM versions
81
+ WHERE ($1::text IS NOT NULL AND id = $1) OR ($1::text IS NULL AND status = 'building')
82
+ ORDER BY started_at DESC NULLS LAST, id
83
+ LIMIT 1`,
84
+ [focus],
85
+ );
86
+ return rows[0] || null;
87
+ }
88
+
89
+ // The docket's answer, held per viewer for WAITING_TTL_MS. Home is the most-loaded
90
+ // page and the docket's routing is several reads deep, so a reload inside the
91
+ // window costs no reads. The dots are a display count that gates nothing, so the
92
+ // uncached-authority rule (ADR 0016) is untouched; the docket itself stays live.
93
+ // Keyed by port so a swapped port (a test, a reload) never sees another's answers.
94
+ const WAITING_TTL_MS = 30 * 1000;
95
+ const WAITING_MAX = 500;
96
+ const waitingMemo = new WeakMap();
97
+ async function yoursByGoalHeld(gov, viewer, now) {
98
+ const memo = waitingMemo.get(gov) || new Map();
99
+ waitingMemo.set(gov, memo);
100
+ const key = `${viewer.id}:${String(viewer.rank || '').toLowerCase()}`;
101
+ const hit = memo.get(key);
102
+ if (hit && now - hit.at < WAITING_TTL_MS) return hit.r;
103
+ const r = await Promise.resolve().then(() => gov.yoursByGoal(viewer)).catch((err) => {
104
+ log.warn({ err: err && err.message }, 'home city: the docket could not say what waits on the viewer');
105
+ return null;
106
+ });
107
+ if (r && r.available === true) {
108
+ if (memo.size >= WAITING_MAX) memo.delete(memo.keys().next().value);
109
+ memo.set(key, { at: now, r });
110
+ }
111
+ return r;
112
+ }
113
+
114
+ // Per area, how many matters wait on the viewer → [{ goal_id, n }]. The docket's
115
+ // routing through the government port when it answers; else the approximation
116
+ // (Archon only), so Home never loses its dots to a missing or failing port.
117
+ async function waitingOnViewer(pool, goalIds, viewer, deps) {
118
+ if (!viewer || viewer.id == null) return [];
119
+ const gov = deps.government !== undefined ? deps.government : api.resolveOptional('government');
120
+ if (gov && typeof gov.yoursByGoal === 'function') {
121
+ const r = await yoursByGoalHeld(gov, viewer, deps.now ? deps.now() : Date.now());
122
+ if (r && r.available === true) {
123
+ const areas = new Set(goalIds);
124
+ return Object.entries(r.goals || {})
125
+ .filter(([goalId, n]) => areas.has(String(goalId)) && Number(n) > 0)
126
+ .map(([goalId, n]) => ({ goal_id: String(goalId), n: Number(n) }));
127
+ }
128
+ }
129
+ if (String(viewer.rank || '').toLowerCase() !== 'archon') return [];
130
+ const hasAsks = await tableExists(pool, 'government_asks');
131
+ return (await pool.query(
132
+ `SELECT t.goal_id::text AS goal_id, count(DISTINCT b.id)::int AS n
133
+ FROM blockers b
134
+ JOIN task_blockers tb ON tb.blocker_id = b.id
135
+ JOIN tasks t ON t.id = tb.task_id
136
+ ${hasAsks ? `LEFT JOIN government_asks a ON a.matter_id = 'blockers:' || b.id` : ''}
137
+ WHERE b.status = 'open' AND t.goal_id = ANY($1::bigint[])
138
+ ${hasAsks ? `AND (a.matter_id IS NULL OR a.waits_on = 'owner')` : ''}
139
+ GROUP BY 1`,
140
+ [goalIds],
141
+ )).rows;
142
+ }
143
+
144
+ // → the raw rows, every query bounded by the window, the areas or a LIMIT.
145
+ // The reads that do not depend on each other run together (Promise.all): the
146
+ // window and the version first, then the areas, then everything else at once.
147
+ async function readCity({ weeks, viewer }, deps = {}) {
148
+ const pool = (deps.pool && process.env.NODE_ENV === 'test') ? deps.pool : api.pool;
149
+ const N = clampWeeks(weeks);
150
+ const rank = viewer ? String(viewer.rank || '').toLowerCase() : '';
151
+ const isArchon = rank === 'archon';
152
+ const viewerId = viewer && viewer.id != null ? String(viewer.id) : null;
153
+ const [{ rows: [win] }, version, hasVotes, hasRunners] = await Promise.all([
154
+ pool.query(
155
+ `SELECT ((date_trunc('week', now() AT TIME ZONE 'UTC') AT TIME ZONE 'UTC') - make_interval(weeks => $1 - 1)) AS start`,
156
+ [N],
157
+ ),
158
+ versionBeingBuilt(pool, deps),
159
+ tableExists(pool, 'government_board_votes'),
160
+ tableExists(pool, 'autonomy_runner_heartbeat'),
161
+ ]);
162
+ const start = win.start;
163
+ const out = { N, start, version, areas: [], areaWeeks: [], leads: [], peopleWeeks: [], ideaCounts: [], ideas: [], gov: [], builders: [], sites: [], waiting: [] };
164
+
165
+ // VISIBILITY (ADR 0112's leak rule, as goal-graph.js applies it): a private
166
+ // goal the viewer is neither a member of nor an Archon over stays a tower (its
167
+ // counts are structure) but its title, and the titles of ideas tied to it, are
168
+ // dropped in shapeCity. Visibility comes from the signed-in viewer, never the query.
169
+ if (version) {
170
+ out.areas = (await pool.query(
171
+ `SELECT g.id::text AS goal_id, g.title,
172
+ (g.visibility IS DISTINCT FROM 'private'
173
+ OR $2::boolean
174
+ OR EXISTS (SELECT 1 FROM goal_members gm WHERE gm.goal_id = g.id AND gm.builder_id = $3::bigint)) AS visible
175
+ FROM goals g
176
+ WHERE g.version_id = $1 AND g.status = 'open' AND NOT g.is_maintenance
177
+ ORDER BY g.sort_order, g.id
178
+ LIMIT ${MAX_AREAS}`,
179
+ [version.id, isArchon, viewerId],
180
+ )).rows;
181
+ }
182
+ const goalIds = out.areas.map((a) => a.goal_id);
183
+ const none = Promise.resolve({ rows: [] });
184
+ const friction = rank === 'xenos' ? `AND i.kind <> '${SKILL_FRICTION_KIND}' AND i.title NOT LIKE '${SKILL_FRICTION_TAG}%'` : '';
185
+
186
+ const [areaWeeks, leads, peopleWeeks, ideaCounts, ideas, gov, sites, waiting] = await Promise.all([
187
+ goalIds.length ? pool.query(
188
+ `SELECT t.goal_id::text AS goal_id,
189
+ CASE WHEN t.shipped_at < $2 THEN -1 ELSE ${wk('t.shipped_at', '$2')} END AS wk,
190
+ (t.discipline = ANY($3::text[])) AS art,
191
+ count(*)::int AS n
192
+ FROM tasks t
193
+ WHERE t.status = 'shipped' AND t.shipped_at IS NOT NULL
194
+ AND t.goal_id = ANY($1::bigint[])
195
+ AND t.title NOT LIKE '${SMOKE_TITLE}' ESCAPE '\\'
196
+ GROUP BY 1, 2, 3`,
197
+ [goalIds, start, ART_DISCIPLINES],
198
+ ) : none,
199
+ goalIds.length ? pool.query(
200
+ `SELECT DISTINCT ON (goal_id, wk) goal_id, wk, shipped_by
201
+ FROM (SELECT t.goal_id::text AS goal_id, ${wk('t.shipped_at', '$2')} AS wk, t.shipped_by::text AS shipped_by, count(*) AS n
202
+ FROM tasks t
203
+ WHERE t.status = 'shipped' AND t.shipped_at >= $2 AND t.shipped_by IS NOT NULL
204
+ AND t.goal_id = ANY($1::bigint[])
205
+ GROUP BY 1, 2, 3) x
206
+ ORDER BY goal_id, wk, n DESC, shipped_by`,
207
+ [goalIds, start],
208
+ ) : none,
209
+ pool.query(
210
+ `SELECT t.shipped_by::text AS id, ${wk('t.shipped_at', '$1')} AS wk, (t.discipline = ANY($2::text[])) AS art, count(*)::int AS n
211
+ FROM tasks t
212
+ WHERE t.status = 'shipped' AND t.shipped_at >= $1 AND t.shipped_by IS NOT NULL
213
+ AND t.title NOT LIKE '${SMOKE_TITLE}' ESCAPE '\\'
214
+ GROUP BY 1, 2, 3`,
215
+ [start, ART_DISCIPLINES],
216
+ ),
217
+ pool.query(
218
+ `SELECT i.captured_by::text AS id, ${wk('i.captured_at', '$1')} AS wk, count(*)::int AS n
219
+ FROM idea_inbox i
220
+ WHERE i.captured_at >= $1 AND i.captured_by IS NOT NULL ${friction}
221
+ GROUP BY 1, 2`,
222
+ [start],
223
+ ),
224
+ pool.query(
225
+ `SELECT i.id::text AS id, i.title, i.captured_by::text AS by, ${wk('i.captured_at', '$1')} AS wk, pt.goal_id::text AS goal_id
226
+ FROM idea_inbox i
227
+ LEFT JOIN tasks pt ON pt.id = i.promoted_to_task_id
228
+ WHERE i.captured_at >= $1 ${friction}
229
+ ORDER BY i.captured_at DESC
230
+ LIMIT ${MAX_IDEAS}`,
231
+ [start],
232
+ ),
233
+ pool.query(
234
+ `SELECT id, wk, sum(n)::int AS n FROM (
235
+ ${hasVotes ? `SELECT v.voter_id::text AS id, ${wk('v.cast_at', '$1')} AS wk, count(*) AS n
236
+ FROM government_board_votes v WHERE v.cast_at >= $1 GROUP BY 1, 2
237
+ UNION ALL` : ''}
238
+ SELECT b.resolved_by::text AS id, ${wk('b.resolved_at', '$1')} AS wk, count(*) AS n
239
+ FROM blockers b WHERE b.status = 'resolved' AND b.resolved_at >= $1 AND b.resolved_by IS NOT NULL GROUP BY 1, 2
240
+ ) x GROUP BY 1, 2`,
241
+ [start],
242
+ ),
243
+ goalIds.length ? pool.query(
244
+ `SELECT DISTINCT ON (t.goal_id) t.goal_id::text AS goal_id, c.builder_id::text AS builder_id,
245
+ ${hasRunners ? `EXISTS (SELECT 1 FROM autonomy_runner_heartbeat h
246
+ WHERE h.working_task_id = t.id AND h.last_seen_at > now() - interval '15 minutes')` : 'false'} AS agent
247
+ FROM claims c
248
+ JOIN tasks t ON t.id = c.task_id
249
+ WHERE c.released_at IS NULL AND t.goal_id = ANY($1::bigint[])
250
+ ORDER BY t.goal_id, c.claimed_at DESC`,
251
+ [goalIds],
252
+ ) : none,
253
+ goalIds.length ? waitingOnViewer(pool, goalIds, viewer, deps) : Promise.resolve([]),
254
+ ]);
255
+ Object.assign(out, {
256
+ areaWeeks: areaWeeks.rows, leads: leads.rows, peopleWeeks: peopleWeeks.rows, ideaCounts: ideaCounts.rows,
257
+ ideas: ideas.rows, gov: gov.rows, sites: sites.rows, waiting,
258
+ });
259
+
260
+ const ids = new Set();
261
+ [out.leads.map((r) => r.shipped_by), out.peopleWeeks.map((r) => r.id), out.ideaCounts.map((r) => r.id), out.ideas.map((r) => r.by), out.gov.map((r) => r.id), out.sites.map((r) => r.builder_id)]
262
+ .forEach((list) => list.forEach((id) => { if (id != null) ids.add(String(id)); }));
263
+ if (viewerId) ids.add(viewerId);
264
+ if (ids.size) {
265
+ out.builders = (await pool.query(
266
+ `SELECT b.id::text AS id, b.github_login, b.display_name, b.avatar_url
267
+ FROM builders b
268
+ WHERE b.id = ANY($1::bigint[]) AND b.system_role IS NULL`,
269
+ [[...ids]],
270
+ )).rows;
271
+ }
272
+ return out;
273
+ }
274
+
275
+ // The raw rows → the response Home draws. Pure: a test feeds it rows with no
276
+ // database. Rows outside the window (a clock skew, a bad week index) are dropped,
277
+ // never counted at the edge.
278
+ function shapeCity(raw, viewer) {
279
+ const N = raw.N;
280
+ const inWeek = (w) => Number.isInteger(w) && w >= 0 && w < N;
281
+ const zeros = () => Array(N).fill(0);
282
+ const start = raw.start instanceof Date ? raw.start : new Date(raw.start);
283
+ const weeks = Array.from({ length: N }, (_, i) => ({ start: new Date(start.getTime() + i * 7 * 864e5).toISOString().slice(0, 10) }));
284
+
285
+ const areas = raw.areas.map((a) => ({ goal_id: a.goal_id, title: a.visible === false ? null : a.title, base_build: 0, base_art: 0, build: zeros(), art: zeros(), lead: Array(N).fill(null) }));
286
+ const byGoal = new Map(areas.map((a) => [a.goal_id, a]));
287
+ const hiddenGoals = new Set(raw.areas.filter((a) => a.visible === false).map((a) => String(a.goal_id)));
288
+ raw.areaWeeks.forEach((r) => {
289
+ const a = byGoal.get(String(r.goal_id)); if (!a) return;
290
+ const n = Number(r.n) || 0;
291
+ if (r.wk === -1) { if (r.art) a.base_art += n; else a.base_build += n; return; }
292
+ if (inWeek(r.wk)) (r.art ? a.art : a.build)[r.wk] += n;
293
+ });
294
+ raw.leads.forEach((r) => { const a = byGoal.get(String(r.goal_id)); if (a && inWeek(r.wk)) a.lead[r.wk] = String(r.shipped_by); });
295
+
296
+ const known = new Map(raw.builders.map((b) => [String(b.id), b]));
297
+ const people = new Map();
298
+ const person = (id) => {
299
+ const key = String(id);
300
+ if (!known.has(key)) return null; // a machine principal or a deleted builder is never drawn
301
+ if (!people.has(key)) {
302
+ const b = known.get(key);
303
+ people.set(key, { id: key, login: b.github_login || '', name: b.display_name || b.github_login || 'Builder', avatar_url: b.avatar_url || null, agent: false, build: zeros(), art: zeros(), idea: zeros(), gov: zeros() });
304
+ }
305
+ return people.get(key);
306
+ };
307
+ raw.peopleWeeks.forEach((r) => { const p = person(r.id); if (p && inWeek(r.wk)) (r.art ? p.art : p.build)[r.wk] += Number(r.n) || 0; });
308
+ raw.ideaCounts.forEach((r) => { const p = person(r.id); if (p && inWeek(r.wk)) p.idea[r.wk] += Number(r.n) || 0; });
309
+ raw.gov.forEach((r) => { const p = person(r.id); if (p && inWeek(r.wk)) p.gov[r.wk] += Number(r.n) || 0; });
310
+ if (viewer && viewer.id != null) person(viewer.id);
311
+ areas.forEach((a) => { a.lead = a.lead.map((id) => (id && known.has(id) ? id : null)); });
312
+
313
+ const ideas = raw.ideas.filter((r) => inWeek(r.wk)).map((r) => ({ id: String(r.id), week: r.wk, by: r.by && known.has(String(r.by)) ? String(r.by) : null, title: hiddenGoals.has(String(r.goal_id)) ? null : (r.title || ''), goal_id: r.goal_id && byGoal.has(String(r.goal_id)) ? String(r.goal_id) : null }));
314
+ const sites = raw.sites.filter((s) => byGoal.has(String(s.goal_id)) && known.has(String(s.builder_id)))
315
+ .map((s) => { person(s.builder_id); return { goal_id: String(s.goal_id), builder_id: String(s.builder_id), agent: !!s.agent }; });
316
+ const waiting = raw.waiting.filter((w) => byGoal.has(String(w.goal_id)) && Number(w.n) > 0).map((w) => ({ goal_id: String(w.goal_id), count: Number(w.n) }));
317
+
318
+ return {
319
+ viewer: viewer && viewer.id != null ? { id: String(viewer.id) } : null,
320
+ version: raw.version ? { id: raw.version.id, name: raw.version.name || raw.version.id } : null,
321
+ weeks, areas, people: [...people.values()], ideas, now: { sites, waiting },
322
+ };
323
+ }
324
+
325
+ // The GET /home/city handler, injectable so a test drives it with no express.
326
+ function homeCityHandler({ log, read = readCity } = {}) {
327
+ return async function homeCityRoute(req, res) {
328
+ try {
329
+ const viewer = req.builder ? { id: req.builder.id, rank: req.builder.rank } : null;
330
+ const raw = await read({ weeks: req.query && req.query.weeks, viewer });
331
+ res.set('Cache-Control', 'private, max-age=60');
332
+ res.json(shapeCity(raw, viewer));
333
+ } catch (err) {
334
+ if (log) log.error('GET /home/city', err);
335
+ res.fail('home_city_failed', { status: 500, message: 'internal error' });
336
+ }
337
+ };
338
+ }
339
+
340
+ module.exports = { WAITING_TTL_MS, DEFAULT_WEEKS, MAX_AREAS, MAX_IDEAS, clampWeeks, readCity, shapeCity, homeCityHandler };
@@ -35,6 +35,7 @@
35
35
  "sky",
36
36
  "goal-task-relevance",
37
37
  "moving",
38
+ "home-city",
38
39
  "task-votes",
39
40
  "notes"
40
41
  ],
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ // modules/lifecycle/routes/home-city.js — GET /home/city, the weekly summary behind
4
+ // Home's project city (task 1005054).
5
+ //
6
+ // WHY ITS OWN ROUTE FILE. routes/tasks.js and routes/goals.js sit at the 1,500-line
7
+ // ratchet, and the path is top-level `/home/city`, never under `/tasks` or `/goals`,
8
+ // whose `/:id` routes would swallow a literal segment (the `/inbox/awaiting-nod`
9
+ // trap; route-shadow-guard). The reads and the handler live in ../home-city.js so a
10
+ // test drives them with no express and no database (routes/moving.js precedent).
11
+ //
12
+ // MODULE BOUNDARY: reaches core only through the published doorway
13
+ // `../../../src/module-api`; `../home-city` is this module's own read.
14
+
15
+ const express = require('express');
16
+ const api = require('../../../src/module-api');
17
+ const homeCity = require('../home-city');
18
+
19
+ const log = api.logger('lifecycle');
20
+
21
+ module.exports = function buildHomeCityRouter() {
22
+ const router = express.Router();
23
+ // rank: any-builder — GET /home/city, the counts Home's city draws. Every number in
24
+ // it is a count of rows a signed-in builder can already list (shipped tasks, ideas,
25
+ // votes, open claims); the per-area "waits on you" half is the docket's routing for
26
+ // this viewer (task 1005056), computed inside the read. Nothing here is writable.
27
+ router.get('/home/city', api.requireBuilder, homeCity.homeCityHandler({ log }));
28
+ return router;
29
+ };
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.24.29",
3
+ "version": "1.24.30",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bongos/core",
9
- "version": "1.24.29",
9
+ "version": "1.24.30",
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.24.29",
3
+ "version": "1.24.30",
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",
@@ -11107,5 +11107,15 @@
11107
11107
  "id": "1005044",
11108
11108
  "text": "Your agent settings now live in one place, My agents: Settings shows a short link there instead of repeating them, and every old Settings link to them opens My agents."
11109
11109
  }
11110
+ ],
11111
+ "1.24.30": [
11112
+ {
11113
+ "id": "1005056",
11114
+ "text": "The \"waiting on you\" dots on Home's project city now show every person the matters actually wait on, not just the owner."
11115
+ },
11116
+ {
11117
+ "id": "1005054",
11118
+ "text": "Home now shows the whole project as a living city: towers that grow as work ships, the people building them, and a slider to replay the last ten weeks."
11119
+ }
11110
11120
  ]
11111
11121
  }
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.29'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
84
+ const CORE_VERSION = '1.24.30'; // 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');
@@ -86,16 +86,10 @@ await test('task.html\'s cache-bust moved for task.js', () => {
86
86
  assert.match(taskHtml, /task\.js\?v=2026-09-28-taskclaim/);
87
87
  });
88
88
 
89
- // == Home's "Next up" rows ====================================================
90
-
91
- await test('hall-render.js constructs the shared claim action for Home\'s Next-up row', () => {
92
- // Lives in hall-render.js, not builders.js: builders.js sits at the
93
- // 1,500-line fitness ratchet (hall-ui/CLAUDE.md — growth goes in the
94
- // lib/renderer, not the page).
95
- assert.match(hallRenderJs, /function wireNextUpClaim\(\)/);
96
- assert.match(hallRenderJs, /makeClaimAction\(\{/);
97
- assert.match(hallRenderJs, /window\.OTBClaimAction/);
98
- });
89
+ // == Home ====================================================================
90
+ // task 1005054: Home's "Next up" rows left with the "Your work" card (the project
91
+ // city took its place), so Home carries no claim button and no claim action.
92
+ // Claiming lives on the task page above and on the Work board.
99
93
 
100
94
  await test('the shared postJSON carries { status, data } — the contract claim-action.js reads', () => {
101
95
  const m = buildersJs.match(/async function postJSON\(path, body\) \{[\s\S]*?\n {2}\}/);
@@ -103,46 +97,17 @@ await test('the shared postJSON carries { status, data } — the contract claim-
103
97
  assert.match(m[0], /err\.data\s*=/, 'postJSON must set err.data or every refusal here falls through to the generic line');
104
98
  });
105
99
 
106
- await test('each Next-up row renders a Claim button carrying its task id', () => {
107
- const m = buildersJs.match(/list\.innerHTML = rows\.map\(\(t\) => \{[\s\S]*?\n {6}\}\)\.join\(''\);/);
108
- assert.ok(m, 'loadNextUp row template not found');
109
- assert.match(m[0], /class="[^"]*next-up__claim[^"]*"/);
110
- assert.match(m[0], /data-task-id="\$\{escapeHtml\(String\(t\.id\)\)\}"/);
111
- });
112
-
113
- await test('the Next-up Claim button routes through claimAction.claim, not a raw POST', () => {
114
- const m = hallRenderJs.match(/function wireNextUpClaim\(\) \{[\s\S]*?\n {2}\}/);
115
- assert.ok(m, 'wireNextUpClaim not found');
116
- assert.match(m[0], /\$\('#home-next-list'\)\?\.addEventListener\('click'/);
117
- assert.match(m[0], /claimAction\.claim\(taskId\)/);
118
- });
119
-
120
- await test('builders.js wires the Next-up claim action rather than hand-rolling it', () => {
100
+ await test('Home hand-rolls no claim: no POST /claims, no leftover Next-up wiring', () => {
121
101
  assert.doesNotMatch(buildersJs, /postJSON\(\s*`\$\{API\}\/claims/);
122
- assert.match(buildersJs, /wireNextUpClaim\(\)/, 'builders.js must call the renderer\'s wiring');
102
+ assert.doesNotMatch(buildersJs + hallRenderJs, /wireNextUpClaim|home-next-list|next-up__claim/);
103
+ assert.doesNotMatch(indexHtml, /claim-action\.js/, 'Home has no claim button, so it loads no claim action');
123
104
  });
124
105
 
125
- await test('the claim wiring landed in the renderer, not back over the 1,500-line ratchet', () => {
126
- // Not a second copy of fitness.js's own gate (scripts/bongos/fitness-ratchets.js)
127
- // — this is the reason wireNextUpClaim moved to hall-render.js in the first
128
- // place (see its own comment): a regression here explains WHY that file grew,
129
- // not just THAT some file grew.
106
+ await test('the page halves stay under the 1,500-line ratchet', () => {
130
107
  for (const [name, src] of [['builders.js', buildersJs], ['hall-render.js', hallRenderJs]]) {
131
108
  const lines = src.split('\n').length;
132
109
  assert.ok(lines <= 1500, `${name} is ${lines} lines — over the fitness ratchet`);
133
110
  }
134
111
  });
135
112
 
136
- await test('index.html loads claim-action.js before builders.js', () => {
137
- const shared = indexHtml.indexOf('claim-action.js');
138
- const after = indexHtml.indexOf('builders.js?v=');
139
- assert.ok(shared > -1, 'index.html must load claim-action.js');
140
- assert.ok(after > shared, 'builders.js must load AFTER claim-action.js');
141
- });
142
-
143
- await test('index.html\'s cache-bust moved for builders.js', () => {
144
- assert.doesNotMatch(indexHtml, /builders\.js\?v=2026-06-27-r75/, 'the old bust is still there');
145
- assert.match(indexHtml, /builders\.js\?v=2026-09-28-nextupclaim/);
146
- });
147
-
148
113
  summary();
@@ -303,13 +303,14 @@ test('the system notices are inbox LINES, first in the card, and counted by its
303
303
  }
304
304
  });
305
305
 
306
- test('the greeting reads /me and the public progress (for the version tab), and builders.js feeds both', () => {
307
- assert.match(buildersJs, /getJSON\(`\$\{API\}\/public\/progress`\)/, 'Home fetches the public progress once');
306
+ test('the greeting reads /me only; the version tab and its progress read left Home', () => {
307
+ // task 1005054: the version tab left with the stats strip, so Home no longer
308
+ // fetches /public/progress; the project city (home-city.js) draws how far it is.
309
+ assert.doesNotMatch(buildersJs, /\/public\/progress/, 'Home no longer fetches the public progress');
308
310
  assert.doesNotMatch(buildersJs, /getJSON\(`\$\{API\}\/tasks\/claimable`/,
309
311
  'no unbounded claimable fetch on Home');
310
- assert.match(buildersJs, /get lastProgressState\(\)/, 'the renderer reads progress through a getter, so it cannot freeze at boot');
311
- assert.doesNotMatch(buildersJs, /lastClaimableCount/, 'the greeting no longer needs the claimable count (task 1004780)');
312
- assert.equal((buildersJs.match(/renderGreeting\(\)/g) || []).length, 2, 'rendered after /me and after progress — each as it lands');
312
+ assert.doesNotMatch(buildersJs, /lastProgressState|lastClaimableCount/, 'the greeting needs neither the progress nor the claimable count');
313
+ assert.equal((buildersJs.match(/renderGreeting\(\)/g) || []).length, 1, 'rendered once, as soon as /me answers');
313
314
  });
314
315
 
315
316
  // Boot hall-render.js against a stub DOM and a ctx of getters (the way
@@ -368,16 +369,13 @@ const ME = {
368
369
  const LEADERBOARD = [{ github_login: 'a', total_credits: 20000 }, { github_login: 'percy', total_credits: 14441 }, { github_login: 'b', total_credits: 3 }, { github_login: 'c', total_credits: 1 }];
369
370
  const PROGRESS = { progress: [{ version_id: 'BONGOS-V1', status: 'building', total_count: 605, percent_complete: 75 }, { version_id: 'V2', status: 'planning', total_count: 9000, percent_complete: 0 }] };
370
371
 
371
- test('RUN: the greeting names the builder, and the version tab carries how far the version is', () => {
372
+ test('RUN: the greeting names the builder, and writes nothing else', () => {
373
+ // task 1005054: the version tab left Home with the stats strip; how far the
374
+ // project has come is the city under the greeting (home-city.js).
372
375
  const { api, el } = bootHallRender({ me: ME, progress: PROGRESS });
373
376
  api.renderGreeting();
374
377
  assert.match(el('hall-h1').textContent, /^Good (morning|afternoon|evening), Percy Jackson$/);
375
- assert.equal(el('home-version-name').textContent, 'BONGOS-V1', 'the building version, not the bigger planning one');
376
- assert.equal(el('home-version-pct').textContent, '75% complete');
377
- assert.equal(el('home-version').hidden, false);
378
- const none = bootHallRender({ me: ME });
379
- none.api.renderGreeting();
380
- assert.equal(none.el('home-version').hidden, true, 'no progress yet: no tab');
378
+ assert.equal(el('home-version').textContent || '', '', 'no version tab is drawn');
381
379
  });
382
380
 
383
381
  test('RUN: the Standing card carries the three facts, the place as "2nd of 4", and no banner', () => {
@@ -122,14 +122,15 @@ function loadRender({ view = 'home' } = {}) {
122
122
 
123
123
  const homePage = (total, firstId = 3000) => ({ ships: [ship(firstId), ship(firstId - 1)], total });
124
124
 
125
- test('Home: the count and the five-row table come from the small page, with no ledger fetch', async () => {
125
+ test('Home: the Standing chip\'s count comes from the small page, with no ledger fetch', async () => {
126
+ // task 1005054: the Shipped tile and the five-row table left Home with the stats
127
+ // strip and "Your work"; the small page still feeds the Standing chip's count.
126
128
  const { r, el, fetched } = loadRender();
127
129
  assert.equal(r.HOME_SHIPS_LIMIT, 5);
128
130
  r.setRecentShips(homePage(3000));
129
131
  await new Promise((done) => setTimeout(done, 0));
130
132
  assert.deepEqual(fetched, [], 'Home never asks for the full history');
131
- assert.equal(el('stat-shipped').textContent, '3000', 'the Shipped tile shows the server total, not rows held');
132
- assert.match(el('home-recent-table tbody').innerHTML, /#3000[\s\S]*#2999/);
133
+ assert.equal(el('standing-shipped').textContent, '3000', 'the chip shows the server total, not rows held');
133
134
  assert.equal(el('recent-ships tbody').innerHTML, '', 'the ledger is untouched until its view opens');
134
135
  });
135
136
 
@@ -28,7 +28,6 @@ const require = createRequire(import.meta.url);
28
28
  const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
29
29
  const read = (rel) => fs.readFileSync(path.join(ROOT, rel), 'utf8');
30
30
  const BUILDERS_JS = read('modules/hall-ui/public/builders.js');
31
- const WIDGETS_JS = read('modules/hall-ui/public/hall-widgets.js');
32
31
  const ROUTE = read('modules/lifecycle/routes/tasks.js');
33
32
  const DB_TASKS = read('modules/lifecycle/db-tasks.js');
34
33
 
@@ -48,26 +47,24 @@ await test('no Home read downloads a feed and slices it in the browser', () => {
48
47
  // DISPLAYED is fine; narrowing what was FETCHED is the bug, and the two look
49
48
  // identical at the call site — which is why this is a test and not a code review.
50
49
  const src = noComments(BUILDERS_JS);
51
- for (const fn of ['loadNextUp', 'loadTriageInbox']) {
52
- const from = src.indexOf(`function ${fn}(`);
53
- assert.ok(from > 0, `${fn} must exist`);
54
- const body = src.slice(from, src.indexOf('\n }\n', from));
55
- const name = fn;
56
- const url = body.match(/\$\{API\}\/[^`'"]+/);
57
- assert.ok(url, `${name} must issue a request`);
58
- assert.match(url[0], /[?&]limit=\d+/, `${name} must ask the server for its page size`);
59
- }
50
+ const from = src.indexOf('function loadTriageInbox(');
51
+ assert.ok(from > 0, 'loadTriageInbox must exist');
52
+ const body = src.slice(from, src.indexOf('\n }\n', from));
53
+ const url = body.match(/\$\{API\}\/[^`'"]+/);
54
+ assert.ok(url, 'loadTriageInbox must issue a request');
55
+ assert.match(url[0], /[?&]limit=\d+/, 'loadTriageInbox must ask the server for its page size');
60
56
  });
61
57
 
62
- await test('the two cards ask for exactly the rows they draw', () => {
63
- assert.match(BUILDERS_JS, /\$\{API\}\/tasks\/claimable\?limit=5/, 'Next up draws five rows, level with Recently shipped');
64
- assert.match(BUILDERS_JS, /\$\{API\}\/inbox\?limit=5/, 'the triage card draws five');
65
- // …and no longer re-slices what came back.
66
- const src = noComments(BUILDERS_JS);
67
- const from = src.indexOf('function loadNextUp(');
68
- const body = src.slice(from, src.indexOf('\n }\n', from));
69
- assert.ok(body.length > 0, 'loadNextUp body found');
70
- assert.doesNotMatch(body, /\.slice\(0,\s*2\)/, 'the client-side slice is gone');
58
+ await test('the project city asks for ONE weekly summary, and the Next-up read left with its card', () => {
59
+ // task 1005054: Home's body is the project city. It draws from one bounded read
60
+ // the server counts per week (modules/lifecycle/home-city.js), never a task feed;
61
+ // the Next-up card and its GET /tasks/claimable read left Home with "Your work".
62
+ const CITY_JS = noComments(read('modules/hall-ui/public/home-city.js'));
63
+ const reads = [...CITY_JS.matchAll(/api\.request\('GET',\s*`([^`]+)`/g)].map((m) => m[1]);
64
+ assert.deepEqual(reads, ['${API}/home/city?weeks=${WEEKS}'], 'one read, asked for its window');
65
+ assert.doesNotMatch(CITY_JS, /\/tasks|claimable|recent-ships/, 'the city never downloads a feed');
66
+ assert.doesNotMatch(noComments(BUILDERS_JS), /function loadNextUp\(|tasks\/claimable/, 'Home no longer reads the claimable feed');
67
+ assert.match(BUILDERS_JS, /\$\{API\}\/inbox\?limit=5/, 'the triage card still draws five');
71
68
  });
72
69
 
73
70
  // ---------------------------------------------------------------------------
@@ -153,16 +150,4 @@ await test('the limit is applied AFTER the JS post-filters, not as a SQL LIMIT',
153
150
  assert.match(routeBody, /feed\.slice\(0, claimLimit\)/, 'the slice happens on the finished feed');
154
151
  });
155
152
 
156
- // ---------------------------------------------------------------------------
157
- // 4. what the reader sees
158
- // ---------------------------------------------------------------------------
159
-
160
- await test('the foot names the queue the two rows came off', () => {
161
- assert.match(WIDGETS_JS, /id="home-next-foot"/, 'the link has an id to write into');
162
- assert.match(BUILDERS_JS, /See all \$\{fmtNum\(total\)\} ready work/);
163
- // Silent rather than wrong when the count is missing or not larger than what is
164
- // shown: "See all 2" under two rows is noise, and a guessed number is worse.
165
- assert.match(BUILDERS_JS, /Number\.isFinite\(total\) && total > rows\.length/);
166
- });
167
-
168
153
  summary();