@bongos/core 1.19.332 → 1.19.333

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 (58) hide show
  1. package/.bongos-core.json +160 -40
  2. package/docs/api/openapi.json +2 -2
  3. package/docs/api-reference.md +1 -1
  4. package/docs/copy-inventory.md +202 -202
  5. package/docs/copy-registry.json +384 -384
  6. package/modules/grading/grader-config.js +98 -0
  7. package/modules/grading/grader-model.js +150 -0
  8. package/modules/grading/grader-prompt.js +139 -0
  9. package/modules/grading/grader-score.js +706 -0
  10. package/modules/grading/grader-subagent.js +328 -0
  11. package/modules/grading/grader.js +5 -1287
  12. package/modules/hall-ui/public/builders.js +19 -1182
  13. package/modules/hall-ui/public/goals-page.js +11 -997
  14. package/modules/hall-ui/public/goals-render.js +1032 -0
  15. package/modules/hall-ui/public/goals.html +4 -0
  16. package/modules/hall-ui/public/hall-render.js +1211 -0
  17. package/modules/hall-ui/public/index.html +6 -0
  18. package/modules/lifecycle/routes/goal-route-authz.js +400 -0
  19. package/modules/lifecycle/routes/goals.js +1 -367
  20. package/modules/lifecycle/routes/task-route-helpers.js +219 -0
  21. package/modules/lifecycle/routes/task-write-routes.js +542 -0
  22. package/modules/lifecycle/routes/tasks.js +3 -696
  23. package/package-lock.json +2 -2
  24. package/package.json +1 -1
  25. package/scripts/gds/box-infra.js +280 -0
  26. package/scripts/gds/box.js +1 -245
  27. package/scripts/gds/fitness-checks-identity.js +320 -0
  28. package/scripts/gds/fitness-checks-vocabulary.js +230 -0
  29. package/scripts/gds/fitness-checks-write-validation.js +144 -0
  30. package/scripts/gds/fitness-lib.js +82 -0
  31. package/scripts/gds/fitness.js +55 -668
  32. package/scripts/gds/provision-config.js +204 -0
  33. package/scripts/gds/provision-net.js +221 -0
  34. package/scripts/gds/provision-repo.js +849 -0
  35. package/scripts/gds/provision-units.js +262 -0
  36. package/scripts/gds/provision.js +4 -1395
  37. package/src/bongos/auth-admission.js +264 -0
  38. package/src/bongos/auth-config.js +151 -0
  39. package/src/bongos/auth-discord.js +198 -0
  40. package/src/bongos/auth-github.js +336 -0
  41. package/src/bongos/auth-idp.js +330 -0
  42. package/src/bongos/auth.js +5 -1100
  43. package/src/module-api.js +3 -1
  44. package/tests/auth_admission_gate.mjs +3 -1
  45. package/tests/est_advisory.mjs +3 -1
  46. package/tests/goal_advisory.mjs +3 -2
  47. package/tests/goal_criterion_confirm_ui.mjs +6 -0
  48. package/tests/goal_subtitle.mjs +5 -2
  49. package/tests/goals_card_view.mjs +10 -3
  50. package/tests/grader_generated_provenance.mjs +3 -1
  51. package/tests/hall_palette.mjs +3 -1
  52. package/tests/helpers.mjs +58 -25
  53. package/tests/lib_sh_resolution.mjs +3 -1
  54. package/tests/membership_kind_lockstep.mjs +3 -1
  55. package/tests/migration_allocation.mjs +5 -2
  56. package/tests/patch_gate_ordering.mjs +3 -1
  57. package/tests/rank_tier_single_source.mjs +16 -3
  58. package/tests/reward_gate.mjs +3 -2
@@ -0,0 +1,144 @@
1
+ // scripts/gds/fitness-checks-write-validation.js — Check 18 (BV1 R12 / task 1999,
2
+ // ADR 0118): every body-reading write route validates its body.
3
+ //
4
+ // Carved out of scripts/gds/fitness.js by task 1003206 (goal 1000079, the R03
5
+ // de-monolith plan) to bring that file under the 1,500-line ratchet. A STRUCTURAL
6
+ // move: the lines below are fitness.js's originals unchanged, and fitness.js
7
+ // imports every name straight back, so the CHECKS registry and the module's
8
+ // public surface (which the tests read heavily) are untouched.
9
+
10
+ 'use strict';
11
+
12
+ const genApiDocs = require('./gen-api-docs'); // R12 (#1999): reuse the route model (readsBody/validated) that drives the OpenAPI spec
13
+
14
+ // ============================================================================
15
+ // Check 18 — every write route validates its body (BV1 R12 / task 1999 / ADR 0118)
16
+ // ============================================================================
17
+ //
18
+ // Criterion api-validation: "the build fails on an unvalidated write route." R11
19
+ // (#1998) gave every body-reading write route a strict validateOrRespond schema
20
+ // (code-first, spec-driven — ADR 0118); this LOCKS that in. Reusing the SAME
21
+ // route model that generates the OpenAPI spec (gen-api-docs.extractModel —
22
+ // readsBody + validated), a POST/PUT/PATCH/DELETE that reads req.body must carry
23
+ // a validateOrRespond()/validate(req.body) schema. Hard-zero (no ratchet — the
24
+ // R11 sweep already reached 100%): a NEW write route that reads a body but
25
+ // declares no schema fails the build immediately, so unknown/typo'd fields can
26
+ // never again be silently dropped.
27
+ //
28
+ // EXEMPT — the builder-settings /me/*-prefs routes. Their bodies are DYNAMIC-KEY
29
+ // maps ({ "<skill|sound|event-id>": <value> }, or a single-key toggle) that a
30
+ // FIXED field schema cannot express; they validate via their module lib's
31
+ // validatePatch()/validate() (which already rejects unknown keys with a 422). A
32
+ // fixed strict schema would wrongly reject the valid dynamic keys — so these are
33
+ // validated-by-lib, not by validateOrRespond. Documented per-route below; see
34
+ // learning #133 / ADR 0118. Adding a route here is a deliberate, reviewable act.
35
+ const WRITE_VALIDATION_EXEMPT = new Set([
36
+ 'PATCH /me/skill-prefs', // { "<skill>": "<model>"|null } — dynamic keys; skillPrefs.validatePatch
37
+ 'PATCH /me/sound-prefs', // { "<sound>": <bool>|null } — dynamic keys; soundPrefs.validatePatch
38
+ 'PATCH /me/event-sound-prefs', // { "<event>": "<variant>"|null } — dynamic keys; eventSoundPrefs.validatePatch
39
+ 'PATCH /me/wandering', // { wandering: 0..3|null } — rank-capped; wanderingPrefs.validatePatch
40
+ 'PATCH /me/interaction', // interaction profile — interactionPrefs.validatePatch
41
+ 'PATCH /me/model-allocation', // per-slot tiers — modelAllocPrefs.validatePatch
42
+ 'PATCH /me/render', // { widgets: <bool>|null } — renderPrefs.validatePatch
43
+ 'PATCH /me/display-name', // { display_name } — displayName.validate
44
+ ]);
45
+
46
+ // KNOWN GAPS, NOT EXEMPTIONS (task 1002551 / BV1.R109b → tracked by task 1002552).
47
+ //
48
+ // These three are NOT validated-by-lib and do NOT belong in WRITE_VALIDATION_EXEMPT
49
+ // above — they are genuine ADR 0118 gaps that must grow a validateOrRespond schema.
50
+ // They surface here only because R109b taught route discovery to see MULTI-LINE
51
+ // `router.<method>(` declarations: this check reuses gen-api-docs.extractModel(), so
52
+ // the same regex hole that hid them from the rank auditor hid them from Check 18 too.
53
+ // They are pre-existing (never validated), not a regression.
54
+ //
55
+ // They are recorded rather than fixed because modules/*/routes/*.js was being migrated
56
+ // concurrently by BV1.R105, so editing those files would have collided. This is the
57
+ // Check-17 ratchet posture: a NAMED, non-growing baseline. The list may only ever
58
+ // SHRINK — a new unvalidated write route is not on it and still hard-fails the build,
59
+ // and a stale entry (one that HAS been fixed) also fails, so the list cannot rot.
60
+ // Delete this constant when task 1002552 lands and Check 18 returns to hard-zero.
61
+ // EMPTY as of BV1.R109c (task 1002552) — all three original entries now validate.
62
+ // Kept (rather than deleted) as the ratchet itself: an empty named baseline states
63
+ // the invariant is hard-zero, and any future entry has to be added deliberately.
64
+ const WRITE_VALIDATION_BASELINE = new Set([]);
65
+
66
+ function scanUnvalidatedWriteRoutes(model = genApiDocs.extractModel()) {
67
+ const unvalidated = [];
68
+ const baselineSeen = new Set();
69
+ for (const r of model) {
70
+ if (!['POST', 'PUT', 'PATCH', 'DELETE'].includes(r.method)) continue;
71
+ // Only routes that actually read a body have an input surface to validate;
72
+ // a write that ignores req.body has nothing to declare.
73
+ if (!r.body || !r.body.readsBody || r.body.validated) continue;
74
+ const key = `${r.method} ${r.route}`;
75
+ if (WRITE_VALIDATION_EXEMPT.has(key)) continue;
76
+ if (WRITE_VALIDATION_BASELINE.has(key)) { baselineSeen.add(key); continue; }
77
+ unvalidated.push(`${key} [${r.file}]`);
78
+ }
79
+ // A baseline entry that no longer reports as unvalidated has been FIXED — it must be
80
+ // removed, or the list would quietly license a future regression on that same route.
81
+ for (const key of WRITE_VALIDATION_BASELINE) {
82
+ if (!baselineSeen.has(key)) {
83
+ unvalidated.push(`${key} [STALE BASELINE — this route now validates; remove it from WRITE_VALIDATION_BASELINE in scripts/gds/fitness.js]`);
84
+ }
85
+ }
86
+ return unvalidated;
87
+ }
88
+
89
+ function checkWriteRoutesValidated() {
90
+ const unvalidated = scanUnvalidatedWriteRoutes();
91
+ const violations = [];
92
+ if (unvalidated.length) {
93
+ violations.push(
94
+ `${unvalidated.length} write route(s) read req.body but declare NO validateOrRespond/validate schema (ADR 0118 / R11 requires one so unknown fields are rejected via the ADR-0116 envelope): ${unvalidated.join('; ')}. Add a strict validateOrRespond(req, res, { … }) listing every field the handler reads (see learning #133). A dynamic-key body validated by a module lib belongs in WRITE_VALIDATION_EXEMPT with a one-line reason.`
95
+ );
96
+ }
97
+ return {
98
+ name: 'every write route validates its body (ADR 0118 / R12)',
99
+ ok: violations.length === 0,
100
+ hardFail: violations.length > 0,
101
+ violations,
102
+ warnings: [],
103
+ note: `body-reading POST/PUT/PATCH/DELETE routes must call validateOrRespond/validate (${WRITE_VALIDATION_EXEMPT.size} dynamic-key prefs routes validate by lib; ${WRITE_VALIDATION_BASELINE.size} known gaps tracked by task 1002552, list may only shrink); ${unvalidated.length} unvalidated.`,
104
+ };
105
+ }
106
+
107
+
108
+ // ── Check 19 — the ADR 0174 vocabulary wall (goal 1000068 R07, task 1003008) ──
109
+ //
110
+ // "Role" means ONE thing in this codebase: a craft — Artist, Ideator, or Builder.
111
+ // The permission system is the GOVERNMENT and the positions in it are RANKS.
112
+ // Before ADR 0174 the same word named both, and goal 1000066 was about to claim
113
+ // it for the crafts while modules/governance/ still used it for the ladder. This
114
+ // check is what stops that collision reforming the first time someone copies an
115
+ // old file.
116
+ //
117
+ // TWO RULES, both scoped to the GOVERNMENT SURFACE — not the whole repo. A repo-
118
+ // wide ban would be wrong: `builders.system_role` is a core column for machine
119
+ // identities, Discord's API owns its own "role" noun, and the crafts are supposed
120
+ // to use the word.
121
+ //
122
+ // 1. no "role" under modules/government/ or on the Government hall page
123
+ // 2. no "governance" there either — the old name of the same surface
124
+ //
125
+ // EXCLUDED BY CONSTRUCTION (not by allowlist):
126
+ // • modules/government/migrations/governance_*.sql — the already-applied
127
+ // migrations keep their filenames forever (schema_migrations is stem-keyed;
128
+ // renaming one re-runs it, and governance_002 is a seed/backfill). Their
129
+ // bodies necessarily name the pre-rename tables they created.
130
+ // • docs/adr/, docs/session-logs/, docs/governance/ — the historical record.
131
+ // An ADR describes a decision at a point in time; rewriting it to match
132
+ // today's vocabulary would erase the evidence that the words changed.
133
+ //
134
+ // The ALLOWLIST below is deliberately tiny and each entry carries its reason. A
135
+ // rule that passes because everything is suppressed reads as evidence while
136
+ // proving nothing — if this list grows, that is the signal to finish the rename,
137
+ // not to add a line.
138
+
139
+ module.exports = {
140
+ WRITE_VALIDATION_BASELINE,
141
+ WRITE_VALIDATION_EXEMPT,
142
+ checkWriteRoutesValidated,
143
+ scanUnvalidatedWriteRoutes,
144
+ };
@@ -0,0 +1,82 @@
1
+ // scripts/gds/fitness-lib.js — the two roots every architecture check walks, and
2
+ // the walkers themselves (ADR 0108 §1: core tree vs instance tree).
3
+ //
4
+ // Carved out of scripts/gds/fitness.js by task 1003206 (goal 1000079, the R03
5
+ // de-monolith plan) to bring that file under the 1,500-line ratchet. A STRUCTURAL
6
+ // move: the lines below are fitness.js's originals unchanged, and fitness.js
7
+ // imports every name straight back, so the CHECKS registry and the module's
8
+ // public surface (which the tests read heavily) are untouched.
9
+
10
+ 'use strict';
11
+
12
+ const fs = require('node:fs');
13
+ const path = require('node:path');
14
+ const { resolveCoreRoot, resolveInstanceRoot } = require('../../src/instance-config'); // ADR 0108 §1: configurable-root
15
+
16
+
17
+ // ADR 0108 §Consequences #4 (configurable-root W6 / task 1886) — the guardrail walks TWO trees.
18
+ // CORE code + core-owned docs (src/, server.js, scripts/, the src/bongos + scripts/gds nested docs)
19
+ // live under the core PACKAGE; INSTANCE content (the root CLAUDE.md, the .claude/ methodology
20
+ // surface, instance modules + migrations) lives under the host REPO. Modules ship from BOTH.
21
+ // Today both resolve to the same checkout, so every walk below is byte-identical; once the core
22
+ // installs from node_modules they diverge and each check inspects the CORRECT tree. A NEW
23
+ // hardcoded `path.resolve(__dirname,'..','..')` here reintroduces the bug this check exists to stop.
24
+ const CORE_ROOT = resolveCoreRoot();
25
+ const INSTANCE_ROOT = resolveInstanceRoot();
26
+ // REPO_ROOT retained as an alias to the core root for the many purely-core walks below (src/bongos,
27
+ // KERNEL_FILES, scope map, …) — those keep their exact behavior. Instance-owned reads route
28
+ // through INSTANCE_ROOT explicitly, and module reads through MODULE_ROOTS.
29
+ const REPO_ROOT = CORE_ROOT;
30
+ // Deduped module search roots — a module can ship from the core package OR the instance repo (the
31
+ // loader errors on a cross-root key collision, so a key resolves to exactly one root). Deduped so
32
+ // today's single checkout scans each module ONCE (no double-counting).
33
+ const MODULE_ROOTS = [...new Set([CORE_ROOT, INSTANCE_ROOT])];
34
+
35
+ // ---- shared fs helpers -----------------------------------------------------
36
+
37
+ function walkJs(absRoot, out = []) {
38
+ let st;
39
+ try { st = fs.statSync(absRoot); } catch { return out; }
40
+ if (st.isFile()) { if (absRoot.endsWith('.js')) out.push(absRoot); return out; }
41
+ for (const ent of fs.readdirSync(absRoot, { withFileTypes: true })) {
42
+ if (ent.name === 'node_modules' || ent.name === '.git') continue;
43
+ walkJs(path.join(absRoot, ent.name), out);
44
+ }
45
+ return out;
46
+ }
47
+ // repo-relative POSIX path for an abs file under EITHER root (core or instance). The classifier
48
+ // regexes throughout this file key on these relative strings, which are identical whichever tree
49
+ // a file lives in — so only the WALK roots change under the split, not the classification.
50
+ const rel = (abs) => {
51
+ for (const base of [CORE_ROOT, INSTANCE_ROOT]) {
52
+ const r = path.relative(base, abs);
53
+ if (r && !r.startsWith('..') && !path.isAbsolute(r)) return r.split(path.sep).join('/');
54
+ }
55
+ return path.relative(CORE_ROOT, abs).split(path.sep).join('/');
56
+ };
57
+ // Walk .js under `subpath` (e.g. 'modules') across ALL module roots, deduped by repo-relative
58
+ // path so the same file is never scanned twice when the roots coincide (today).
59
+ function walkJsAllRoots(subpath, roots = MODULE_ROOTS) {
60
+ const seen = new Set();
61
+ const out = [];
62
+ for (const root of roots) {
63
+ for (const abs of walkJs(path.join(root, subpath))) {
64
+ const r = rel(abs);
65
+ if (seen.has(r)) continue;
66
+ seen.add(r);
67
+ out.push(abs);
68
+ }
69
+ }
70
+ return out;
71
+ }
72
+
73
+
74
+ module.exports = {
75
+ CORE_ROOT,
76
+ INSTANCE_ROOT,
77
+ MODULE_ROOTS,
78
+ REPO_ROOT,
79
+ rel,
80
+ walkJs,
81
+ walkJsAllRoots,
82
+ };