@bongos/core 1.19.963 → 1.19.965

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 (40) hide show
  1. package/.bongos-core.json +70 -40
  2. package/clients/bongos-client/README.md +1 -1
  3. package/clients/bongos-client/bongos-client.global.js +2 -0
  4. package/clients/bongos-client/index.cjs +2 -0
  5. package/clients/bongos-client/index.d.ts +2 -0
  6. package/clients/bongos-client/index.mjs +2 -0
  7. package/docs/adr/0244-a-catalog-search-is-a-view-over-the-rows-never-an-edit-to-the-selection.md +41 -0
  8. package/docs/adr/0326-an-upgrade-may-add-a-deny-rule-to-a-file-the-instance-owns.md +5 -0
  9. package/docs/adr/README.md +2 -2
  10. package/docs/api/openapi.json +47 -2
  11. package/docs/api-reference.md +3 -2
  12. package/docs/copy-inventory.md +134 -128
  13. package/docs/copy-registry.json +212 -158
  14. package/docs/module-api-changelog.md +4 -0
  15. package/modules/hall-ui/public/goal-forest-lib.js +229 -0
  16. package/modules/hall-ui/public/goal-forest-render.js +151 -0
  17. package/modules/hall-ui/public/goals-page.js +6 -0
  18. package/modules/hall-ui/public/goals-render.js +9 -1
  19. package/modules/hall-ui/public/goals.css +26 -0
  20. package/modules/hall-ui/public/goals.html +19 -0
  21. package/modules/lifecycle/goal-forest.js +135 -0
  22. package/modules/lifecycle/routes/goals.js +8 -8
  23. package/modules/provisioning/starter-bundles.js +26 -2
  24. package/modules/public-landing/public/projects.html +17 -4
  25. package/modules/ui-design/kit/serve.js +2 -2
  26. package/package-lock.json +2 -2
  27. package/package.json +1 -1
  28. package/scripts/gds/claude-materialize.js +29 -6
  29. package/scripts/hall-preview/server.js +1 -0
  30. package/src/module-api.js +1 -1
  31. package/tests/claude_materialize.mjs +48 -4
  32. package/tests/goal_category_ui.mjs +2 -0
  33. package/tests/goal_criterion_confirm_ui.mjs +2 -0
  34. package/tests/goal_forest.mjs +160 -0
  35. package/tests/goal_forest_lib.mjs +153 -0
  36. package/tests/goal_forest_page.mjs +196 -0
  37. package/tests/goal_invite_consent.mjs +1 -1
  38. package/tests/helpers.mjs +7 -3
  39. package/tests/projects_hub_module_picker.mjs +79 -4
  40. package/tests/provisioning_starter_bundles.mjs +25 -1
@@ -31,6 +31,7 @@ const goalEdits = require('../goal-edits.js'); // task 1003102 — goal self-edi
31
31
  const goalCategory = require('../goal-category.js'); // task 1003275 — the ADVISORY human category (gates nothing)
32
32
  const goalRollup = require('../goal-rollup.js'); // task 1003278 — per-goal rollups computed in SQL, not in the browser
33
33
  const goalGraph = require('../goal-graph.js'); // task 1003479 — the goal graph: nodes + cross-goal edges, aggregated in SQL
34
+ const goalForest = require('../goal-forest.js'); // task 1003480 — per-goal dependency forest
34
35
  const { suggestCriteria } = require('../criterion-suggest');
35
36
  const { classifyTaskKind, VALID_KINDS, WRITABLE_DISCIPLINES, resolveWriteDiscipline, TASK_FIELD_BOUNDS } = require('../task-classifier');
36
37
  const { validateOrRespond, parseId, LIMITS } = api;
@@ -908,14 +909,13 @@ module.exports = function buildGoalsRouter() {
908
909
  return res.fail('transfer_failed', { status: 500, message: 'internal error' });
909
910
  }
910
911
  });
911
-
912
- // GET /goals/:id/conflicts — the server-side task-conflict view (task 1736).
913
- // Replaces the hall Goals page's client-side exact-string approximation (the
914
- // page feature-detects on 404): glob-aware touches[] intersection via the
915
- // canonical path-match machinery, claim-aware severity, and cross-goal
916
- // overlaps against other OPEN goals sharing scope_modules. Detection only —
917
- // resolution is the POST below.
918
- // rank: any-builder — a read; the same audience as GET /goals/:id.
912
+ // rank: any-builder — GET /goals/:id/dependency-forest, the per-goal task dependency drill-down (task 1003480, ADR 0227 §6.4).
913
+ router.get('/goals/:id/dependency-forest', auth.requireBuilder, goalForest.goalForestHandler({ getGoal: db.getGoal, parseId, log }));
914
+ // GET /goals/:id/conflicts — the server-side task-conflict view (task 1736). Replaces the hall Goals
915
+ // page's client-side exact-string approximation (the page feature-detects on 404): glob-aware touches[]
916
+ // intersection via the canonical path-match machinery, claim-aware severity, and cross-goal overlaps
917
+ // against other OPEN goals sharing scope_modules. Detection only — resolution is the POST below.
918
+ // rank: any-builder — a read, GET /goals/:id's audience.
919
919
  router.get('/goals/:id/conflicts', auth.requireBuilder, async (req, res) => {
920
920
  const id = parseId(req, res, { code: 'bad_goal_id' });
921
921
  if (id === null) return;
@@ -100,16 +100,37 @@ const RETIRED_MODULES = Object.freeze(['dev-box']);
100
100
  // tests/provisioning_starter_bundles.mjs be the link back to the manifests — it
101
101
  // fails the build when the declared set drifts from the on-disk `default: false`
102
102
  // modules, so a new opt-in module cannot ship without owner-facing copy.
103
+ // `aliases` are search words only — never rendered (the same standing the `key`
104
+ // already has, ADR 0244 §3). They exist because the picker's search is a literal
105
+ // substring filter over words we chose, so a module is findable only under the
106
+ // vocabulary its own copy happens to use: typing "chat" found nothing, which is
107
+ // the gap ADR 0244 named and deferred to an embeddings layer. Task 1003500 closed
108
+ // it here instead — for a catalog this size a declared word list is more accurate
109
+ // than a model, costs nothing to run, and is fixable by whoever reads the
110
+ // complaint (ADR 0244 §3 amendment).
111
+ //
112
+ // This fixes the WORD, not the SENTENCE. ADR 0244 §3 illustrated the gap with
113
+ // "somewhere for people to chat", and that query still finds nothing: the matcher
114
+ // ANDs every term, so `somewhere` and `people` must appear too. Making a sentence
115
+ // work means OR-then-rank, which §3 and §5 reject outright. Aliases raise the
116
+ // chance an owner's ONE word lands; they do not make the filter understand a
117
+ // phrase, and nothing here should imply they do.
118
+ //
119
+ // Write the LONGEST form an owner might type: the filter is substring-based, so
120
+ // 'chatroom' in the haystack already answers "chat". A word the label or summary
121
+ // already contains does not belong here — it is findable without it.
103
122
  const OPTIONAL_MODULES = Object.freeze([
104
123
  Object.freeze({
105
124
  key: 'agents',
106
125
  label: 'Extra agents',
107
126
  summary: 'More AI agents alongside the ones every project gets, for reading, research and review.',
127
+ aliases: Object.freeze(['bots', 'assistants', 'automation', 'llm', 'helpers']),
108
128
  }),
109
129
  Object.freeze({
110
130
  key: 'discord',
111
131
  label: 'Discord',
112
132
  summary: 'A Discord server that carries your build news, and lets people send ideas and bug reports back.',
133
+ aliases: Object.freeze(['chatroom', 'talk', 'messaging', 'community', 'announcements', 'notifications']),
113
134
  }),
114
135
  ]);
115
136
 
@@ -241,9 +262,12 @@ function allStarterBundles() {
241
262
  }
242
263
 
243
264
  // The opt-in catalog, as the picker reads it — fresh copies, so a caller may
244
- // sort or splice without corrupting the frozen declaration.
265
+ // sort or splice without corrupting the frozen declaration. `aliases` is copied
266
+ // too: a spread is shallow, so the old one-level copy handed every caller the
267
+ // same FROZEN array, and the first one to take the liberty this comment offers
268
+ // would have got a TypeError under strict mode rather than a private copy.
245
269
  function optionalModules() {
246
- return OPTIONAL_MODULES.map((m) => ({ ...m }));
270
+ return OPTIONAL_MODULES.map((m) => (m.aliases ? { ...m, aliases: [...m.aliases] } : { ...m }));
247
271
  }
248
272
 
249
273
  // Apply the team-shape rules to one type's opt-in bundle. Returns the adjusted
@@ -3528,12 +3528,25 @@ summary{min-height:24px;padding:3px 0;}
3528
3528
  return String(q == null ? '' : q).toLowerCase().split(/\s+/).filter(function (t) { return t.length > 0; });
3529
3529
  }
3530
3530
  /* Does one catalog row answer this search? Every term must appear somewhere in
3531
- the row's own words — its name, its one-line summary, or its key — as a
3532
- substring, case-insensitively. AND across terms, so adding a word narrows;
3533
- substring, so a half-typed word still finds its module. */
3531
+ the row's own words — its name, its one-line summary, its key, or its
3532
+ declared search aliases — as a substring, case-insensitively. AND across
3533
+ terms, so adding a word narrows; substring, so a half-typed word still
3534
+ finds its module.
3535
+
3536
+ The aliases are why typing "chat" now finds Discord: the row is findable
3537
+ under words an owner would use, not only the ones its own copy happens to
3538
+ use. They are declared in starter-bundles.js and never rendered — the same
3539
+ standing the key already has (ADR 0244 §3, amended by task 1003500).
3540
+
3541
+ Still literal, and still AND across terms, so a SENTENCE still finds
3542
+ nothing — "somewhere for people to chat" fails on `somewhere` and `people`
3543
+ however many aliases the row carries. That is the honest limit of this
3544
+ filter, not a bug in the list. */
3534
3545
  function moduleMatches(mod, terms) {
3535
3546
  if (!terms.length) return true;
3536
- var hay = (((mod && mod.label) || '') + ' ' + ((mod && mod.summary) || '') + ' ' + ((mod && mod.key) || '')).toLowerCase();
3547
+ var aliases = (mod && mod.aliases) || [];
3548
+ var hay = (((mod && mod.label) || '') + ' ' + ((mod && mod.summary) || '') + ' ' + ((mod && mod.key) || '')
3549
+ + ' ' + (aliases.join ? aliases.join(' ') : '')).toLowerCase();
3537
3550
  for (var i = 0; i < terms.length; i++) if (hay.indexOf(terms[i]) === -1) return false;
3538
3551
  return true;
3539
3552
  }
@@ -128,8 +128,8 @@ const STARTER_BUNDLES_FIXTURE = {
128
128
  { type: 'not-sure', bundle: [] },
129
129
  ],
130
130
  optional: [
131
- { key: 'agents', label: 'Extra agents', summary: 'More AI agents alongside the ones every project gets, for reading, research and review.' },
132
- { key: 'discord', label: 'Discord', summary: 'A Discord server that carries your build news, and lets people send ideas and bug reports back.' },
131
+ { key: 'agents', label: 'Extra agents', summary: 'More AI agents alongside the ones every project gets, for reading, research and review.', aliases: ['bots', 'assistants', 'automation', 'llm', 'helpers'] },
132
+ { key: 'discord', label: 'Discord', summary: 'A Discord server that carries your build news, and lets people send ideas and bug reports back.', aliases: ['chatroom', 'talk', 'messaging', 'community', 'announcements', 'notifications'] },
133
133
  ],
134
134
  };
135
135
 
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.19.963",
3
+ "version": "1.19.965",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bongos/core",
9
- "version": "1.19.963",
9
+ "version": "1.19.965",
10
10
  "license": "AGPL-3.0-or-later",
11
11
  "dependencies": {
12
12
  "express": "^4.21.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.19.963",
3
+ "version": "1.19.965",
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",
@@ -404,15 +404,36 @@ function rebrandSettings(text, rebrand) {
404
404
 
405
405
  // Credential files are derived from where the CLI actually reads them, not rebranded from the
406
406
  // core's literals: the rebrand would also move the host-keyed store, which sits at a fixed anchor
407
- // whatever the brand (cli-lib sessionStoreDir, task 1003741). The shelf rule is the only layer an
408
- // instance gets against the repo-global stash stack, since the git-guard hook does not ship.
409
- function starterDeny(branding = {}) {
407
+ // whatever the brand (cli-lib sessionStoreDir, task 1003741).
408
+ //
409
+ // credentialDeny is the half that may be added to a settings.json the instance already owns.
410
+ // Every rule here stops the agent READING A SECRET, and nothing an instance legitimately does
411
+ // requires reading its own key or session token from inside an agent session — which is what
412
+ // makes appending one provably safe (ADR 0326: a deny rule is monotonic in the safe direction).
413
+ function credentialDeny(branding = {}) {
410
414
  const dirs = [...new Set([effConfigDir(branding), ...ic.LEGACY_DIRS])];
411
415
  const credentialFiles = ['env', ...ic.SESSION_FILENAMES];
412
416
  return [
413
417
  ...STARTER_DENY_SECRETS,
414
418
  ...dirs.flatMap((dir) => credentialFiles.map((file) => `Read(~/.config/${dir}/${file})`)),
415
419
  SESSION_STORE_DENY,
420
+ ];
421
+ }
422
+
423
+ // starterDeny — what a FRESH instance gets: the credential half plus the shelf rules, which are
424
+ // the only layer an instance has against the repo-global stash stack since the git-guard hook is
425
+ // topology and does not ship.
426
+ //
427
+ // The shelf rules are starter-only, and deliberately NOT in the top-up (task 1004158, amending
428
+ // ADR 0326, which named this exclusion as the remedy if the rule ever bit). They guard a WORKFLOW
429
+ // rather than a secret, so the monotonicity argument that licenses the top-up does not reach them:
430
+ // with no provenance by design, and deny beating allow in Claude Code's permission order, an
431
+ // instance whose builders used the shelf as a set-aside could not re-enable it from its own
432
+ // settings.json afterwards. A fresh instance is different in kind — there the rule is a visible
433
+ // default present from the first commit, editable before any workflow has grown around it.
434
+ function starterDeny(branding = {}) {
435
+ return [
436
+ ...credentialDeny(branding),
416
437
  ...STARTER_SHELL_TOOLS.map((tool) => `${tool}(git stash:*)`),
417
438
  ];
418
439
  }
@@ -453,7 +474,7 @@ function topUpStarterDeny(existingText, wanted) {
453
474
  // package-only install. Permissions ONLY: no hooks (they are topology), no env.
454
475
  function renderStarterSettings(branding = {}) {
455
476
  return `${JSON.stringify({
456
- _doc: 'Starter written by scripts/gds/claude-materialize.js (tasks 1003962, 1003966). Permissions only — the blessed Bongos commands, mirroring the core repo\'s own allow-list (ADR 0104), and the deny rules that keep the local agent from reading keys and session tokens. An allow-rule lets the local agent RUN a command; it grants no authority, which the server decides per request from your live rank (ADR 0016). Yours to edit: a later materialize never removes or rewrites a rule you wrote. It will ADD a deny rule this starter has gained since (task 1004156) and name it in the run output — additive only, so it can never widen what the local agent may do.',
477
+ _doc: 'Starter written by scripts/gds/claude-materialize.js (tasks 1003962, 1003966). Permissions only — the blessed Bongos commands, mirroring the core repo\'s own allow-list (ADR 0104), and the deny rules that keep the local agent from reading keys and session tokens. An allow-rule lets the local agent RUN a command; it grants no authority, which the server decides per request from your live rank (ADR 0016). Yours to edit: a later materialize never removes or rewrites a rule you wrote. It will ADD a CREDENTIAL deny rule this starter has gained since (task 1004156) and name it in the run output — additive only, so it can never widen what the local agent may do. Only that half is topped up: the shell rules below guard a workflow rather than a secret, so once this file exists they are yours alone and an upgrade will neither add nor remove one (task 1004158).',
457
478
  permissions: { allow: STARTER_ALLOW, deny: starterDeny(branding) },
458
479
  }, null, 2)}\n`;
459
480
  }
@@ -749,11 +770,13 @@ function materializeClaude({ coreRoot, instanceDir, dryRun = false, overwrite =
749
770
  if (fs.existsSync(settingsDest)) {
750
771
  // The instance owns this file — but a deny rule the starter has gained since is ADDED to
751
772
  // it rather than withheld forever (task 1004156). Nothing of theirs is removed or changed.
773
+ // Only the CREDENTIAL half is offered: the starter's shelf rules guard a workflow, not a
774
+ // secret, and are starter-only (task 1004158).
752
775
  // The read is guarded: existsSync passing does not mean readable (a directory at that path,
753
776
  // a locked or root-owned file), and this runs AFTER the pin moved and the migrations ran, so
754
777
  // a throw here would leave a half-applied upgrade. It fails soft, like its sibling above.
755
778
  let topUp;
756
- try { topUp = topUpStarterDeny(fs.readFileSync(settingsDest, 'utf8'), starterDeny(toBranding)); }
779
+ try { topUp = topUpStarterDeny(fs.readFileSync(settingsDest, 'utf8'), credentialDeny(toBranding)); }
757
780
  catch (err) { topUp = { text: null, added: [], reason: `it could not be read (${err.code || err.message})` }; }
758
781
  if (topUp.text) {
759
782
  if (!dryRun) fs.writeFileSync(settingsDest, topUp.text);
@@ -779,7 +802,7 @@ function materializeClaude({ coreRoot, instanceDir, dryRun = false, overwrite =
779
802
  log(` ! .claude/settings.json could NOT be checked for missing deny rules — ${topUp.reason}. Left untouched; its deny half may still be missing.`);
780
803
  } else {
781
804
  summary.skippedFiles.push('settings.json');
782
- log(' • .claude/settings.json already present — left untouched (the instance owns it; it already carries every starter deny rule).');
805
+ log(' • .claude/settings.json already present — left untouched (the instance owns it; it already carries every credential deny rule. The starter\'s shelf rules are not offered here — they guard a workflow, not a secret, and are starter-only: task 1004158).');
783
806
  }
784
807
  } else {
785
808
  if (!dryRun) {
@@ -101,6 +101,7 @@ let liveWhy = null;
101
101
  // paths fall back to the generic names below so one fixture serves any id.
102
102
  const FIXTURE_FALLBACKS = [
103
103
  [/^goals\/\d+\/conflicts$/, 'goals__conflicts'],
104
+ [/^goals\/\d+\/dependency-forest$/, 'goals__dependency-forest'],
104
105
  [/^goals\/\d+\/requests$/, 'goals__requests'],
105
106
  [/^goals\/\d+$/, 'goals__detail'],
106
107
  [/^tasks\/\d+$/, 'tasks__detail'],
package/src/module-api.js CHANGED
@@ -71,7 +71,7 @@ const { responsibilityFor, ROLE_RESPONSIBILITIES } = require('./role-responsibil
71
71
  // there. scripts/gds/bump-version.js still rewrites the literal below; it appends
72
72
  // the entry to that file. Look for a version's history there, not here.
73
73
  // ---------------------------------------------------------------------------
74
- const CORE_VERSION = '1.19.963'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
74
+ const CORE_VERSION = '1.19.965'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
75
75
 
76
76
  // A namespaced logger so a module's log lines are attributable + consistent.
77
77
  // Usage: const log = api.logger('dev-box'); log.info('mounted');
@@ -895,6 +895,12 @@ t('a checkout-materialized instance keeps the session-store rule at its fixed an
895
895
  // safety argument — a deny rule can only narrow what the agent may do, so appending one cannot
896
896
  // widen this instance's permissions. ADR 0121 §2 already licenses "merge OR leave-and-report"
897
897
  // for a pre-existing file; this implements the merge half for the one shape that is provably safe.
898
+ // task 1004158 — the top-up asks for the CREDENTIAL half only. Derived here by excluding the
899
+ // shell-tool rules rather than read back from the implementation's own list, so this states the
900
+ // contract independently instead of agreeing with whatever the code happens to do.
901
+ const topUpDenyFor = (branding) => starterDenyFor(branding).filter((r) => !/^(?:Bash|PowerShell)\(/.test(r));
902
+ const shelfRules = (branding) => starterDenyFor(branding).filter((r) => /^(?:Bash|PowerShell)\(/.test(r));
903
+
898
904
  const topUpFixture = (settings) => {
899
905
  const core = mkdtempSync(join(tmpdir(), 'w3-topup-core-'));
900
906
  const inst = mkdtempSync(join(tmpdir(), 'w3-topup-inst-'));
@@ -912,8 +918,8 @@ t('an instance still on the allow-only starter GAINS the deny rules on its next
912
918
  const f = topUpFixture({ _doc: 'the task-1003962 starter', permissions: { allow: m.STARTER_ALLOW } });
913
919
  const res = m.materializeClaude({ coreRoot: f.core, instanceDir: f.inst, dryRun: false });
914
920
  const after = JSON.parse(f.read());
915
- assert.deepEqual(after.permissions.deny, starterDenyFor({ configDir: 'acme' }),
916
- "every starter deny rule, pointed at THIS instance's config dir");
921
+ assert.deepEqual(after.permissions.deny, topUpDenyFor({ configDir: 'acme' }),
922
+ "every credential deny rule, pointed at THIS instance's config dir — and nothing else");
917
923
  assert.deepEqual(after.permissions.allow, m.STARTER_ALLOW, 'its allow half is untouched');
918
924
  assert.equal(after._doc, 'the task-1003962 starter', 'and every other key it carried survives');
919
925
  assert.deepEqual(res.settingsDenyAdded, after.permissions.deny, 'the run names each rule it added');
@@ -939,12 +945,50 @@ t("an owner-edited settings.json keeps every rule of its own and only gains what
939
945
  assert.equal(after.permissions.deny.filter((r) => r === 'Read(**/*.pem)').length, 1,
940
946
  'a rule they already had is not added a second time');
941
947
  assert.ok(!res.settingsDenyAdded.includes('Read(**/*.pem)'), 'nor reported as added');
942
- for (const rule of starterDenyFor({ configDir: 'acme' })) {
948
+ for (const rule of topUpDenyFor({ configDir: 'acme' })) {
943
949
  assert.ok(after.permissions.deny.includes(rule), `missing ${rule}`);
944
950
  }
945
951
  f.cleanup();
946
952
  });
947
953
 
954
+ t('the shelf rules are starter-only — the TOP-UP never adds them to a file the instance owns', () => {
955
+ // Scoped to the top-up (the package-only branch, which is the one `bongos upgrade` always takes:
956
+ // the published core excludes .claude/settings.json). The CHECKOUT branch still overwrites an
957
+ // existing instance settings.json wholesale, shelf rules included — that predates this change
958
+ // and is not reachable from an upgrade, so it is out of scope here rather than disproved.
959
+ // task 1004158, amending ADR 0326. The top-up's licence is that a deny rule is monotonic in the
960
+ // safe direction, and that argument covers a rule about reading a SECRET. The shelf rules guard
961
+ // a WORKFLOW: an instance whose builders used the repo-global shelf as a set-aside would find it
962
+ // blocked after an upgrade and — no provenance by design, deny beating allow — could not re-enable
963
+ // it from its own settings.json. So the core stops handing it out to instances that already exist.
964
+ const brand = { configDir: 'acme' };
965
+ assert.deepEqual(shelfRules(brand), ['Bash(git stash:*)', 'PowerShell(git stash:*)'],
966
+ 'the starter still carries both shelf rules — this change withholds them from the TOP-UP, not the starter');
967
+ const f = topUpFixture({ permissions: { allow: m.STARTER_ALLOW } });
968
+ const res = m.materializeClaude({ coreRoot: f.core, instanceDir: f.inst, dryRun: false });
969
+ const deny = JSON.parse(f.read()).permissions.deny;
970
+ for (const rule of shelfRules(brand)) {
971
+ assert.ok(!res.settingsDenyAdded.includes(rule), `${rule} must not be reported as added`);
972
+ assert.ok(!deny.includes(rule), `${rule} must not be written into a settings.json the instance owns`);
973
+ }
974
+ assert.ok(deny.includes('Read(~/.config/acme/bongos-session.json)'),
975
+ 'while the credential half still lands — withholding the shelf rules must not withhold the secrets half');
976
+ f.cleanup();
977
+ });
978
+
979
+ t('an instance that already has a shelf rule keeps it — this withholds, it never removes', () => {
980
+ // The top-up only ever appends, so an instance that took the shelf rules (from the starter, from
981
+ // an upgrade before task 1004158, or by hand) is unaffected. Live cloudbongos.com is in exactly
982
+ // this position after its 0-to-20 run: lifting them there is a hand-edit, not something an
983
+ // upgrade will undo.
984
+ const f = topUpFixture({ permissions: { allow: [], deny: ['Bash(git stash:*)'] } });
985
+ m.materializeClaude({ coreRoot: f.core, instanceDir: f.inst, dryRun: false });
986
+ const deny = JSON.parse(f.read()).permissions.deny;
987
+ assert.equal(deny[0], 'Bash(git stash:*)', 'the rule they already had keeps its place at the front');
988
+ assert.ok(!deny.includes('PowerShell(git stash:*)'), 'and its twin is still not volunteered');
989
+ f.cleanup();
990
+ });
991
+
948
992
  t('the top-up is idempotent — a second materialize changes nothing', () => {
949
993
  const f = topUpFixture({ permissions: { allow: m.STARTER_ALLOW } });
950
994
  m.materializeClaude({ coreRoot: f.core, instanceDir: f.inst, dryRun: false });
@@ -961,7 +1005,7 @@ t('a dry run names the missing deny rules and writes nothing', () => {
961
1005
  const before = f.read();
962
1006
  const res = m.materializeClaude({ coreRoot: f.core, instanceDir: f.inst, dryRun: true });
963
1007
  assert.equal(f.read(), before, 'a dry run writes nothing');
964
- assert.deepEqual(res.settingsDenyAdded, starterDenyFor({ configDir: 'acme' }),
1008
+ assert.deepEqual(res.settingsDenyAdded, topUpDenyFor({ configDir: 'acme' }),
965
1009
  'but it still names what a real run would add');
966
1010
  f.cleanup();
967
1011
  });
@@ -23,6 +23,7 @@ const read = (rel) => fs.readFileSync(path.join(ROOT, rel), 'utf8');
23
23
  const SRC = read('modules/hall-ui/public/goals-page.js');
24
24
  const TASK_LIB_SRC = read('modules/hall-ui/public/task-lib.js');
25
25
  const GOALS_LIB_SRC = read('modules/hall-ui/public/goals-lib.js');
26
+ const GOAL_FOREST_RENDER_SRC = read('modules/hall-ui/public/goal-forest-render.js');
26
27
  const GOALS_RENDER_SRC = read('modules/hall-ui/public/goals-render.js');
27
28
  const DOM_UTILS_SRC = read('modules/hall-ui/public/dom-utils.js');
28
29
  const WORK_SRC = read('modules/hall-ui/public/work.js');
@@ -124,6 +125,7 @@ async function renderList() {
124
125
  windowObj.OTB.toast = () => {};
125
126
  vm.runInContext(TASK_LIB_SRC, sandbox, { filename: 'task-lib.js' });
126
127
  vm.runInContext(GOALS_LIB_SRC, sandbox, { filename: 'goals-lib.js' });
128
+ vm.runInContext(GOAL_FOREST_RENDER_SRC, sandbox, { filename: 'goal-forest-render.js' });
127
129
  vm.runInContext(GOALS_RENDER_SRC, sandbox, { filename: 'goals-render.js' });
128
130
  vm.runInContext(SRC, sandbox, { filename: 'goals-page.js' });
129
131
  for (let i = 0; i < 30; i++) await new Promise((r) => setTimeout(r, 0));
@@ -44,6 +44,7 @@ const GOALS_LIB_SRC = fs.readFileSync(path.join(ROOT, 'modules/hall-ui/public/go
44
44
  // (window.OTBGoalsRender) — the second half of the same carve. Run the REAL file
45
45
  // too, for the same reason: this is the only test that executes either board, so
46
46
  // stubbing the renderers would let them rot unwatched.
47
+ const GOAL_FOREST_RENDER_SRC = fs.readFileSync(path.join(ROOT, 'modules/hall-ui/public/goal-forest-render.js'), 'utf8');
47
48
  const GOALS_RENDER_SRC = fs.readFileSync(path.join(ROOT, 'modules/hall-ui/public/goals-render.js'), 'utf8');
48
49
 
49
50
  const { test, summary } = makeRunner();
@@ -154,6 +155,7 @@ async function render({ rank = 'metic', goalStatus = 'open', criteria = Object.v
154
155
  vm.createContext(sandbox);
155
156
  vm.runInContext(TASK_LIB_SRC, sandbox, { filename: 'task-lib.js' });
156
157
  vm.runInContext(GOALS_LIB_SRC, sandbox, { filename: 'goals-lib.js' });
158
+ vm.runInContext(GOAL_FOREST_RENDER_SRC, sandbox, { filename: 'goal-forest-render.js' });
157
159
  vm.runInContext(GOALS_RENDER_SRC, sandbox, { filename: 'goals-render.js' });
158
160
  vm.runInContext(SRC, sandbox, { filename: 'goals-page.js' });
159
161
 
@@ -0,0 +1,160 @@
1
+ // tests/goal_forest.mjs — GET /goals/:id/dependency-forest, the per-goal task
2
+ // drill-down (task 1003480, goal 1000089, ADR 0227 §6 item 4 + §10.5).
3
+ //
4
+ // NOT A ZOOM OF THE GOAL MAP. This pins the filter that keeps the two views
5
+ // from overlapping or double-drawing anything: an edge counts here ONLY when
6
+ // BOTH its tasks sit in the goal being opened — the exact opposite of
7
+ // goal-graph.js's cross-goal filter — and a goal with no such edge returns an
8
+ // empty forest rather than an error, so the page can say so plainly.
9
+ //
10
+ // DB-free: the pure shaper runs directly, the SQL against a recording fake
11
+ // pool, the handler against stub collaborators.
12
+ //
13
+ // Run: node tests/goal_forest.mjs
14
+ process.env.NODE_ENV = 'test';
15
+ import assert from 'node:assert/strict';
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+ import { fileURLToPath } from 'node:url';
19
+ import { createRequire } from 'node:module';
20
+ import { makeRunner } from './helpers.mjs';
21
+
22
+ const require = createRequire(import.meta.url);
23
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
24
+ const { shapeForest, goalForestRows, goalForest, goalForestHandler } = require(path.join(ROOT, 'modules/lifecycle/goal-forest.js'));
25
+ const GOALS_ROUTE = fs.readFileSync(path.join(ROOT, 'modules/lifecycle/routes/goals.js'), 'utf8');
26
+
27
+ const { test, summary } = makeRunner();
28
+
29
+ const t = (id, extra = {}) => ({ id: String(id), title: `Task ${id}`, status: 'ready', priority: 3, ...extra });
30
+ const e = (from, to) => ({ from_task_id: String(from), to_task_id: String(to) });
31
+
32
+ // ---- shapeForest ----------------------------------------------------------
33
+
34
+ await test('an edge means "from waits on to"; both endpoints become nodes with the right degree', () => {
35
+ const out = shapeForest({ tasks: [t(1), t(2), t(3)], edges: [e(1, 2), e(1, 3)] });
36
+ const by = Object.fromEntries(out.nodes.map((n) => [n.task_id, n]));
37
+ assert.deepEqual(out.edges, [{ from: '1', to: '2' }, { from: '1', to: '3' }]);
38
+ assert.equal(by['1'].depends_on, 2);
39
+ assert.equal(by['2'].depended_on_by, 1);
40
+ assert.equal(by['2'].depends_on, 0);
41
+ });
42
+
43
+ await test('a task with NO edge is never a node — the omission is the finding, not a gap (ADR 0227 §3)', () => {
44
+ const out = shapeForest({ tasks: [t(1), t(2), t(3)], edges: [e(1, 2)] });
45
+ assert.deepEqual(out.nodes.map((n) => n.task_id).sort(), ['1', '2']);
46
+ assert.equal(out.counts.tasks, 2);
47
+ });
48
+
49
+ await test('a self edge and a duplicate are dropped; an edge to a task not in the fetched set is dropped, not drawn to nowhere', () => {
50
+ const out = shapeForest({ tasks: [t(1), t(2)], edges: [e(2, 2), e(1, 2), e(1, 2), e(1, 99)] });
51
+ assert.deepEqual(out.edges, [{ from: '1', to: '2' }]);
52
+ });
53
+
54
+ await test('a task whose only edge was dropped (a stale endpoint) does not appear as a lone edge-less node', () => {
55
+ const out = shapeForest({ tasks: [t(1), t(2), t(3)], edges: [e(1, 99), e(2, 3)] });
56
+ assert.deepEqual(out.nodes.map((n) => n.task_id).sort(), ['2', '3']);
57
+ });
58
+
59
+ await test('priority is coerced to a number or null; status/title pass through verbatim', () => {
60
+ const out = shapeForest({ tasks: [t(1, { priority: '2' }), t(2, { priority: null, status: 'blocked', title: 'Blocked one' })], edges: [e(1, 2)] });
61
+ const by = Object.fromEntries(out.nodes.map((n) => [n.task_id, n]));
62
+ assert.strictEqual(by['1'].priority, 2);
63
+ assert.strictEqual(by['2'].priority, null);
64
+ assert.equal(by['2'].status, 'blocked');
65
+ assert.equal(by['2'].title, 'Blocked one');
66
+ });
67
+
68
+ await test('an empty corpus is a valid, empty forest', () => {
69
+ assert.deepEqual(shapeForest({}), { nodes: [], edges: [], counts: { tasks: 0, edges: 0 } });
70
+ });
71
+
72
+ // ---- the SQL, against a recording pool ----------------------------------------
73
+
74
+ function fakePool(edgeRows = [], taskRows = []) {
75
+ const calls = [];
76
+ return {
77
+ calls,
78
+ async query(sql, params) {
79
+ calls.push({ sql, params });
80
+ return { rows: /FROM tasks\s*$|WHERE id = ANY/.test(sql) ? taskRows : edgeRows };
81
+ },
82
+ };
83
+ }
84
+
85
+ await test('the edge query is bound to ONE goal id, on BOTH endpoints — the opposite of the goal map\'s cross-goal filter', async () => {
86
+ const pool = fakePool();
87
+ await goalForestRows(42, { pool });
88
+ const [q] = pool.calls;
89
+ assert.deepEqual(q.params, [42]);
90
+ assert.match(q.sql, /ft\.goal_id = \$1 AND tt\.goal_id = \$1/);
91
+ assert.match(q.sql, /d\.from_kind = 'task'/);
92
+ assert.match(q.sql, /d\.to_kind\s+= 'task'/);
93
+ });
94
+
95
+ await test('no edges at all short-circuits — the task-facts query never runs', async () => {
96
+ const pool = fakePool([]);
97
+ const out = await goalForestRows(1, { pool });
98
+ assert.equal(pool.calls.length, 1, 'only the edge query ran');
99
+ assert.deepEqual(out, { edges: [], tasks: [] });
100
+ });
101
+
102
+ await test('the task-facts query is scoped to exactly the ids the edges named — never the goal\'s whole task list', async () => {
103
+ const pool = fakePool([e(1, 2), e(2, 3)], [t(1), t(2), t(3)]);
104
+ await goalForestRows(1, { pool });
105
+ const factsQ = pool.calls[1];
106
+ assert.deepEqual(factsQ.params[0].sort((a, b) => a - b), [1, 2, 3]);
107
+ assert.match(factsQ.sql, /WHERE id = ANY/);
108
+ });
109
+
110
+ await test('an end-to-end fake read produces the shaped forest', async () => {
111
+ const pool = fakePool([e(1, 2)], [t(1), t(2)]);
112
+ const out = await goalForest(1, { pool });
113
+ assert.equal(out.counts.tasks, 2);
114
+ assert.deepEqual(out.edges, [{ from: '1', to: '2' }]);
115
+ });
116
+
117
+ // ---- the handler ---------------------------------------------------------------
118
+
119
+ function run(handler, req) {
120
+ const res = { body: null, failed: null, statusCode: null, json(b) { this.body = b; return this; }, fail(code, o) { this.failed = { code, o }; return this; } };
121
+ return handler(req, res).then(() => res);
122
+ }
123
+ const parseId = (req) => { const n = Number(req.params.id); return Number.isInteger(n) && n > 0 ? n : null; };
124
+
125
+ await test('a missing goal is a 404, and the forest is never read', async () => {
126
+ let readCalled = false;
127
+ const h = goalForestHandler({ getGoal: async () => null, read: async () => { readCalled = true; return {}; }, parseId, log: { error() {} } });
128
+ const res = await run(h, { params: { id: '5' } });
129
+ assert.equal(res.failed.code, 'goal_not_found');
130
+ assert.equal(res.failed.o, 404);
131
+ assert.equal(readCalled, false);
132
+ });
133
+
134
+ await test('a real goal returns the forest with the goal id attached', async () => {
135
+ const h = goalForestHandler({ getGoal: async () => ({ id: 5 }), read: async () => ({ nodes: [], edges: [], counts: { tasks: 0, edges: 0 } }), parseId, log: { error() {} } });
136
+ const res = await run(h, { params: { id: '5' } });
137
+ assert.equal(res.body.ok, true);
138
+ assert.equal(res.body.goal_id, 5);
139
+ assert.deepEqual(res.body.nodes, []);
140
+ });
141
+
142
+ await test('a failed read is a named 500, never a stack trace', async () => {
143
+ const errors = [];
144
+ const h = goalForestHandler({ getGoal: async () => ({ id: 1 }), read: async () => { throw new Error('db down'); }, parseId, log: { error: (...a) => errors.push(a) } });
145
+ const res = await run(h, { params: { id: '1' } });
146
+ assert.equal(res.failed.code, 'forest_failed');
147
+ assert.equal(res.failed.o.status, 500);
148
+ assert.equal(errors.length, 1);
149
+ });
150
+
151
+ // ---- mounting --------------------------------------------------------------------
152
+
153
+ await test('/goals/:id/dependency-forest is mounted for any signed-in builder', () => {
154
+ const at = GOALS_ROUTE.indexOf("router.get('/goals/:id/dependency-forest'");
155
+ assert.ok(at > -1, 'the route is registered');
156
+ assert.match(GOALS_ROUTE.slice(at, at + 200), /auth\.requireBuilder/);
157
+ assert.match(GOALS_ROUTE.slice(Math.max(0, at - 260), at), /rank: any-builder/, 'the route-rank scanner needs its declaration');
158
+ });
159
+
160
+ summary();