@bongos/core 1.19.184 → 1.19.186
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bongos-core.json +68 -63
- package/clients/bongos-client/bongos-client.global.js +19 -19
- package/clients/bongos-client/index.cjs +19 -19
- package/clients/bongos-client/index.d.ts +29 -29
- package/clients/bongos-client/index.mjs +19 -19
- package/docs/adr/0157-archon-is-rank-and-identity-only.md +2 -2
- package/docs/api/openapi.json +121 -121
- package/docs/api-reference.md +10 -10
- package/docs/canonical-permissions.md +6 -6
- package/modules/dev-box/app/src/vendor/bongos-client.cjs +19 -19
- package/modules/government/catalog.js +9 -9
- package/modules/government/db.js +9 -9
- package/modules/government/migrations/government_002_rename_permission_keys.sql +112 -0
- package/modules/government/module.json +1 -1
- package/modules/government/protected-surfaces.json +0 -1
- package/modules/government/ranks.js +13 -13
- package/modules/government/routes/{governance.js → government.js} +109 -84
- package/modules/government/routes/rank-sync.js +2 -2
- package/modules/hall-ui/public/gate.js +3 -3
- package/modules/hall-ui/public/{governance.css → government.css} +10 -10
- package/modules/hall-ui/public/{governance.html → government.html} +14 -14
- package/modules/hall-ui/public/{governance.js → government.js} +117 -117
- package/modules/hall-ui/public/harbor.js +3 -3
- package/modules/hall-ui/public/shell.js +21 -17
- package/modules/hall-ui/public/watch.js +2 -2
- package/modules/lifecycle/routes/gate-approvals.js +1 -1
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/scripts/gds/publish-manifest.js +0 -2
- package/scripts/gds/seed-governance-tasks.js +1 -1
- package/scripts/hall-preview/server.js +1 -1
- package/src/bongos/auth.js +13 -13
- package/src/bongos/module-scope-map.js +7 -22
- package/src/bongos/route-rank-check.js +12 -18
- package/src/bongos/serve-internal.js +10 -10
- package/src/module-api.js +6 -2
- package/tests/auth_resolve_failure.mjs +4 -4
- package/tests/governance_abuse_matrix.mjs +35 -35
- package/tests/governance_catalog.mjs +3 -3
- package/tests/governance_fold.mjs +2 -2
- package/tests/governance_fold_bench.mjs +2 -2
- package/tests/governance_live_proof.mjs +4 -4
- package/tests/governance_ownership_scope.mjs +1 -1
- package/tests/governance_page_gates.mjs +12 -12
- package/tests/governance_principals.mjs +2 -2
- package/tests/governance_protected_surfaces.mjs +41 -16
- package/tests/governance_require_permission.mjs +5 -5
- package/tests/governance_resolver.mjs +2 -2
- package/tests/governance_role_sync.mjs +23 -23
- package/tests/governance_routes.mjs +96 -96
- package/tests/governance_seed.mjs +24 -9
- package/tests/governance_session_scope.mjs +4 -4
- package/tests/hall_nav.mjs +8 -7
- package/tests/hall_page_gate_map.mjs +8 -8
|
@@ -97,7 +97,7 @@ function registerSeams() {
|
|
|
97
97
|
selectFragment: `,
|
|
98
98
|
(SELECT COALESCE(array_agg(DISTINCT rp.permission_key), '{}')
|
|
99
99
|
FROM government_builder_ranks br
|
|
100
|
-
JOIN government_rank_permissions rp ON rp.
|
|
100
|
+
JOIN government_rank_permissions rp ON rp.rank_key = br.rank_key
|
|
101
101
|
WHERE br.builder_id = s.builder_id) AS raw_permission_keys`,
|
|
102
102
|
});
|
|
103
103
|
}
|
|
@@ -105,7 +105,7 @@ function registerSeams() {
|
|
|
105
105
|
|
|
106
106
|
// ── the R110 CRUD surface (ADR 0151 §2 — the governance tab's server half) ────
|
|
107
107
|
//
|
|
108
|
-
// Every route — the three reads included — gates on the `
|
|
108
|
+
// Every route — the three reads included — gates on the `government.manage`
|
|
109
109
|
// atom (system, floor archon): this surface EDITS the role/permission graph
|
|
110
110
|
// itself, the meta-escalation the catalog flags non-grantable, and even listing
|
|
111
111
|
// it exposes the full authority map. The invariants are enforced HERE, against
|
|
@@ -131,37 +131,37 @@ function registerSeams() {
|
|
|
131
131
|
// SUBSTRATE keys stay non-grantable to everything, rank-roles included, because a
|
|
132
132
|
// grant row for one delegates nothing (ADR 0043 enforces them out of band).
|
|
133
133
|
const { validateOrRespond, LIMITS, parseId } = api;
|
|
134
|
-
const
|
|
135
|
-
const
|
|
134
|
+
const RANK_KEY_RE = /^[a-z][a-z0-9-]*$/;
|
|
135
|
+
const RANK_KEY_MAX = 64;
|
|
136
136
|
|
|
137
137
|
module.exports = function buildGovernanceRouter() {
|
|
138
138
|
registerSeams();
|
|
139
139
|
const router = express.Router();
|
|
140
140
|
|
|
141
|
-
// Param guard for :
|
|
141
|
+
// Param guard for :rankKey. Responds bad_rank_key and returns null on a
|
|
142
142
|
// malformed slug (seeded keys like 'metic' pass shape and are refused later,
|
|
143
143
|
// by policy, with the honest code).
|
|
144
|
-
function
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
res.fail('
|
|
144
|
+
function rankKeyParam(req, res) {
|
|
145
|
+
const rankKey = req.params.rankKey;
|
|
146
|
+
if (rankKey.length > RANK_KEY_MAX || !RANK_KEY_RE.test(rankKey)) {
|
|
147
|
+
res.fail('bad_rank_key', 400, { rank_key: rankKey, expected: 'a kebab-case slug (^[a-z][a-z0-9-]*$)' });
|
|
148
148
|
return null;
|
|
149
149
|
}
|
|
150
|
-
return
|
|
150
|
+
return rankKey;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
// Load a role whose GRANTS this API may edit (ADR 0172): 404 on a missing role,
|
|
154
154
|
// refuse only the Archon rank-role. Every other role — the three sub-Archon
|
|
155
155
|
// rank-roles and every custom one — is grant-editable; WHICH keys is then
|
|
156
156
|
// `catalog.isGrantableTo(key, role)`, per role. Returns null after responding.
|
|
157
|
-
async function loadGrantEditableRole(res,
|
|
158
|
-
const role = await db.getRoleByKey(
|
|
157
|
+
async function loadGrantEditableRole(res, rankKey) {
|
|
158
|
+
const role = await db.getRoleByKey(rankKey);
|
|
159
159
|
if (!role) {
|
|
160
|
-
res.fail('
|
|
160
|
+
res.fail('rank_not_found', 404, { rank_key: rankKey });
|
|
161
161
|
return null;
|
|
162
162
|
}
|
|
163
163
|
if (role.is_system && role.seeded_rank === ARCHON) {
|
|
164
|
-
res.fail('
|
|
164
|
+
res.fail('archon_rank_immutable', 403, { rank_key: rankKey, reason: ARCHON_REASON });
|
|
165
165
|
return null;
|
|
166
166
|
}
|
|
167
167
|
return role;
|
|
@@ -169,14 +169,14 @@ module.exports = function buildGovernanceRouter() {
|
|
|
169
169
|
|
|
170
170
|
// Load a role this API may ASSIGN. Unchanged from R110: every seeded rank-role is
|
|
171
171
|
// refused, because assignment derives from builders.rank via the R95b sync.
|
|
172
|
-
async function loadAssignableRole(res,
|
|
173
|
-
const role = await db.getRoleByKey(
|
|
172
|
+
async function loadAssignableRole(res, rankKey) {
|
|
173
|
+
const role = await db.getRoleByKey(rankKey);
|
|
174
174
|
if (!role) {
|
|
175
|
-
res.fail('
|
|
175
|
+
res.fail('rank_not_found', 404, { rank_key: rankKey });
|
|
176
176
|
return null;
|
|
177
177
|
}
|
|
178
178
|
if (role.is_system) {
|
|
179
|
-
res.fail('
|
|
179
|
+
res.fail('seeded_rank_assignment_forbidden', 403, { rank_key: rankKey, reason: ASSIGN_REASON });
|
|
180
180
|
return null;
|
|
181
181
|
}
|
|
182
182
|
return role;
|
|
@@ -185,18 +185,43 @@ module.exports = function buildGovernanceRouter() {
|
|
|
185
185
|
const ARCHON_REASON = 'the Archon rank-role holds every permission and is immutable — it is the role that can never be locked out of this tab (ADR 0172)';
|
|
186
186
|
const ASSIGN_REASON = 'a seeded rank-role is assigned by rank (R95b sync); change the builder\'s rank instead';
|
|
187
187
|
|
|
188
|
-
//
|
|
189
|
-
|
|
188
|
+
// ── one-release compatibility aliases: /governance/* -> /government/* ──────
|
|
189
|
+
// ADR 0174 committed to keeping the pre-rename paths answering for exactly one
|
|
190
|
+
// release. The case this actually protects is narrow but real: a browser that
|
|
191
|
+
// still has the OLD hall page open when the instance upgrades will keep calling
|
|
192
|
+
// /governance/* against the new server. Everything else that consumed these
|
|
193
|
+
// paths (the hall bundle, the generated client) ships INSIDE the same core
|
|
194
|
+
// package and moves in lockstep.
|
|
195
|
+
//
|
|
196
|
+
// A 308 preserves the method and body, so a PUT/DELETE grant toggle survives
|
|
197
|
+
// the hop. The alias carries NO gate of its own — it redirects, and the real
|
|
198
|
+
// route re-runs requireBuilder + requirePermission on the followed request, so
|
|
199
|
+
// this cannot become a way around the wall.
|
|
200
|
+
//
|
|
201
|
+
// REMOVE THIS BLOCK one release after the rename ships (goal 1000068 follow-up).
|
|
202
|
+
// The `alias` counter in the log line is how we tell whether anything still
|
|
203
|
+
// calls them before deleting.
|
|
204
|
+
const LEGACY_PATH_PREFIX = '/governance';
|
|
205
|
+
router.all(`${LEGACY_PATH_PREFIX}/*rest`, (req, res, next) => {
|
|
206
|
+
const rest = req.originalUrl.slice(req.originalUrl.indexOf(LEGACY_PATH_PREFIX) + LEGACY_PATH_PREFIX.length);
|
|
207
|
+
if (!rest) return next();
|
|
208
|
+
const target = `/government${rest.replace(/^\/roles(?=\/|$)/, '/ranks')}`;
|
|
209
|
+
console.warn(`[government] legacy path hit: ${req.method} ${req.originalUrl} -> ${target} (ADR 0174 alias; remove one release after the rename)`);
|
|
210
|
+
return res.redirect(308, target);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// rank: perm government.manage — the full role list with each role's grants.
|
|
214
|
+
router.get('/government/ranks', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
190
215
|
try {
|
|
191
|
-
const
|
|
192
|
-
res.json({
|
|
216
|
+
const ranks = await db.listRolesWithGrants();
|
|
217
|
+
res.json({ ranks });
|
|
193
218
|
} catch (err) {
|
|
194
|
-
console.error('[gds] GET /
|
|
219
|
+
console.error('[gds] GET /government/ranks', err);
|
|
195
220
|
res.fail('roles_list_failed', { status: 500, message: 'internal error' });
|
|
196
221
|
}
|
|
197
222
|
});
|
|
198
223
|
|
|
199
|
-
// rank: perm
|
|
224
|
+
// rank: perm government.manage — the permission catalog + principals, straight
|
|
200
225
|
// from code (the catalog is CODE, not a table); no DB read. Principals are
|
|
201
226
|
// read-only by construction. Three flags the tab renders its locks from, and the
|
|
202
227
|
// tab must read all three rather than just `grantable`, because since ADR 0172
|
|
@@ -205,7 +230,7 @@ module.exports = function buildGovernanceRouter() {
|
|
|
205
230
|
// • `system` — an in-app Archon power: locked on a custom role, togglable on
|
|
206
231
|
// a sub-Archon rank-role.
|
|
207
232
|
// • `substrate` — locked EVERYWHERE, on every role, forever (ADR 0043).
|
|
208
|
-
router.get('/
|
|
233
|
+
router.get('/government/permissions', api.requireBuilder, api.requirePermission('government.manage'), (req, res) => {
|
|
209
234
|
const permissions = catalog.PERMISSIONS.map((p) => ({
|
|
210
235
|
key: p.key,
|
|
211
236
|
system: p.system,
|
|
@@ -219,56 +244,56 @@ module.exports = function buildGovernanceRouter() {
|
|
|
219
244
|
res.json({ permissions, principals: catalog.principals() });
|
|
220
245
|
});
|
|
221
246
|
|
|
222
|
-
// rank: perm
|
|
223
|
-
router.get('/
|
|
247
|
+
// rank: perm government.manage — every builder↔role assignment row.
|
|
248
|
+
router.get('/government/assignments', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
224
249
|
try {
|
|
225
250
|
const assignments = await db.listAssignments();
|
|
226
251
|
res.json({ assignments });
|
|
227
252
|
} catch (err) {
|
|
228
|
-
console.error('[gds] GET /
|
|
253
|
+
console.error('[gds] GET /government/assignments', err);
|
|
229
254
|
res.fail('assignments_list_failed', { status: 500, message: 'internal error' });
|
|
230
255
|
}
|
|
231
256
|
});
|
|
232
257
|
|
|
233
|
-
// rank: perm
|
|
258
|
+
// rank: perm government.manage — create a CUSTOM role (is_system false, no
|
|
234
259
|
// seeded_rank — the seeded four exist only via governance_002). Grants are
|
|
235
260
|
// added one at a time via the toggle below, so creation carries none.
|
|
236
|
-
router.post('/
|
|
261
|
+
router.post('/government/ranks', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
237
262
|
if (validateOrRespond(req, res, {
|
|
238
|
-
|
|
263
|
+
rank_key: { required: true, type: 'string', minLength: 2, maxLength: RANK_KEY_MAX },
|
|
239
264
|
label: { required: true, type: 'string', minLength: 1, maxLength: LIMITS.TITLE },
|
|
240
265
|
description: { type: 'string', maxLength: 2000 },
|
|
241
266
|
})) return;
|
|
242
|
-
const
|
|
243
|
-
if (!
|
|
244
|
-
return res.fail('
|
|
267
|
+
const rankKey = req.body.rank_key;
|
|
268
|
+
if (!RANK_KEY_RE.test(rankKey)) {
|
|
269
|
+
return res.fail('bad_rank_key', 400, { rank_key: rankKey, expected: 'a kebab-case slug (^[a-z][a-z0-9-]*$)' });
|
|
245
270
|
}
|
|
246
271
|
try {
|
|
247
|
-
const
|
|
248
|
-
|
|
272
|
+
const rank = await db.createRole({
|
|
273
|
+
rankKey,
|
|
249
274
|
label: req.body.label,
|
|
250
275
|
description: req.body.description ?? null,
|
|
251
276
|
createdBy: req.builder.id,
|
|
252
277
|
});
|
|
253
|
-
res.status(201).json({
|
|
278
|
+
res.status(201).json({ rank: { ...rank, permissions: [] } });
|
|
254
279
|
} catch (err) {
|
|
255
280
|
if (err && err.code === '23505') {
|
|
256
|
-
return res.fail('
|
|
281
|
+
return res.fail('rank_exists', 409, { rank_key: rankKey });
|
|
257
282
|
}
|
|
258
|
-
console.error('[gds] POST /
|
|
283
|
+
console.error('[gds] POST /government/ranks', err);
|
|
259
284
|
res.fail('role_create_failed', { status: 500, message: 'internal error' });
|
|
260
285
|
}
|
|
261
286
|
});
|
|
262
287
|
|
|
263
|
-
// rank: perm
|
|
288
|
+
// rank: perm government.manage — grant one permission to a role (the toggle's ON
|
|
264
289
|
// half). The order of refusals is the authority order: role exists → role is not
|
|
265
290
|
// the Archon one → the key exists → the key is grantable TO THIS ROLE.
|
|
266
|
-
router.put('/
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
291
|
+
router.put('/government/ranks/:rankKey/permissions/:permissionKey', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
292
|
+
const rankKey = rankKeyParam(req, res);
|
|
293
|
+
if (rankKey === null) return;
|
|
269
294
|
const permissionKey = req.params.permissionKey;
|
|
270
295
|
try {
|
|
271
|
-
const role = await loadGrantEditableRole(res,
|
|
296
|
+
const role = await loadGrantEditableRole(res, rankKey);
|
|
272
297
|
if (role === null) return;
|
|
273
298
|
if (!catalog.byKey(permissionKey)) {
|
|
274
299
|
return res.fail('unknown_permission', 400, { permission_key: permissionKey });
|
|
@@ -276,7 +301,7 @@ module.exports = function buildGovernanceRouter() {
|
|
|
276
301
|
if (!catalog.isGrantableTo(permissionKey, role)) {
|
|
277
302
|
return res.fail('permission_not_grantable', 400, {
|
|
278
303
|
permission_key: permissionKey,
|
|
279
|
-
|
|
304
|
+
rank_key: rankKey,
|
|
280
305
|
// Name the ACTUAL wall. "Not grantable" now has three distinct causes and
|
|
281
306
|
// a caller that cannot tell them apart cannot tell a policy choice
|
|
282
307
|
// (widen the role) from a structural one (nothing will ever work).
|
|
@@ -287,34 +312,34 @@ module.exports = function buildGovernanceRouter() {
|
|
|
287
312
|
: 'a system (trust-boundary) permission is non-grantable to a CUSTOM role; only a sub-Archon rank-role may carry one (ADR 0172)',
|
|
288
313
|
});
|
|
289
314
|
}
|
|
290
|
-
const granted = await db.grantRolePermission({
|
|
291
|
-
res.json({ ok: true,
|
|
315
|
+
const granted = await db.grantRolePermission({ rankKey, permissionKey });
|
|
316
|
+
res.json({ ok: true, rank_key: rankKey, permission_key: permissionKey, granted });
|
|
292
317
|
} catch (err) {
|
|
293
|
-
console.error('[gds] PUT /
|
|
318
|
+
console.error('[gds] PUT /government/ranks/:rankKey/permissions/:permissionKey', err);
|
|
294
319
|
res.fail('grant_failed', { status: 500, message: 'internal error' });
|
|
295
320
|
}
|
|
296
321
|
});
|
|
297
322
|
|
|
298
|
-
// rank: perm
|
|
323
|
+
// rank: perm government.manage — revoke a grant (the toggle's OFF half).
|
|
299
324
|
// Deliberately NOT validated against the catalog: a grant whose key the
|
|
300
325
|
// catalog since retired is exactly the row an Archon most needs to remove
|
|
301
326
|
// (the resolver already drops it — this is hygiene, not authority).
|
|
302
|
-
router.delete('/
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
327
|
+
router.delete('/government/ranks/:rankKey/permissions/:permissionKey', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
328
|
+
const rankKey = rankKeyParam(req, res);
|
|
329
|
+
if (rankKey === null) return;
|
|
305
330
|
const permissionKey = req.params.permissionKey;
|
|
306
331
|
try {
|
|
307
|
-
const role = await loadGrantEditableRole(res,
|
|
332
|
+
const role = await loadGrantEditableRole(res, rankKey);
|
|
308
333
|
if (role === null) return;
|
|
309
|
-
const removed = await db.revokeRolePermission({
|
|
310
|
-
res.json({ ok: true,
|
|
334
|
+
const removed = await db.revokeRolePermission({ rankKey, permissionKey });
|
|
335
|
+
res.json({ ok: true, rank_key: rankKey, permission_key: permissionKey, removed });
|
|
311
336
|
} catch (err) {
|
|
312
|
-
console.error('[gds] DELETE /
|
|
337
|
+
console.error('[gds] DELETE /government/ranks/:rankKey/permissions/:permissionKey', err);
|
|
313
338
|
res.fail('revoke_failed', { status: 500, message: 'internal error' });
|
|
314
339
|
}
|
|
315
340
|
});
|
|
316
341
|
|
|
317
|
-
// rank: perm
|
|
342
|
+
// rank: perm government.manage — restore a SEEDED rank-role to its catalog
|
|
318
343
|
// default (ADR 0172). The counterweight to making the rank-roles editable: a
|
|
319
344
|
// rank's grant set is ~60 rows, so an owner who drifts one has no practical way
|
|
320
345
|
// back by clicking, and "what does Trusted mean by default" is a question only
|
|
@@ -325,15 +350,15 @@ module.exports = function buildGovernanceRouter() {
|
|
|
325
350
|
// Deliberately NOT offered for a CUSTOM role: a custom role has no catalog
|
|
326
351
|
// default to return to (its "default" is the empty set it was created with), so
|
|
327
352
|
// the honest verb there is revoking the grants, which the toggle already does.
|
|
328
|
-
router.post('/
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
353
|
+
router.post('/government/ranks/:rankKey/reset', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
354
|
+
const rankKey = rankKeyParam(req, res);
|
|
355
|
+
if (rankKey === null) return;
|
|
331
356
|
try {
|
|
332
|
-
const role = await loadGrantEditableRole(res,
|
|
357
|
+
const role = await loadGrantEditableRole(res, rankKey);
|
|
333
358
|
if (role === null) return;
|
|
334
359
|
if (!role.is_system || !catalog.RANK_ORDER.includes(role.seeded_rank)) {
|
|
335
|
-
return res.fail('
|
|
336
|
-
|
|
360
|
+
return res.fail('rank_has_no_default', 400, {
|
|
361
|
+
rank_key: rankKey,
|
|
337
362
|
reason: 'only a seeded rank-role has a catalog default to reset to; revoke a custom role\'s grants instead',
|
|
338
363
|
});
|
|
339
364
|
}
|
|
@@ -341,58 +366,58 @@ module.exports = function buildGovernanceRouter() {
|
|
|
341
366
|
// — below archon — never a system one. Filtering by isGrantableTo anyway keeps
|
|
342
367
|
// reset from being a back door that writes what the toggle refuses.
|
|
343
368
|
const keys = catalog.seedForRank(role.seeded_rank).filter((k) => catalog.isGrantableTo(k, role));
|
|
344
|
-
const count = await db.resetRoleGrants({
|
|
345
|
-
res.json({ ok: true,
|
|
369
|
+
const count = await db.resetRoleGrants({ rankKey, permissionKeys: keys });
|
|
370
|
+
res.json({ ok: true, rank_key: rankKey, seeded_rank: role.seeded_rank, permission_count: count });
|
|
346
371
|
} catch (err) {
|
|
347
|
-
console.error('[gds] POST /
|
|
372
|
+
console.error('[gds] POST /government/ranks/:rankKey/reset', err);
|
|
348
373
|
res.fail('reset_failed', { status: 500, message: 'internal error' });
|
|
349
374
|
}
|
|
350
375
|
});
|
|
351
376
|
|
|
352
|
-
// rank: perm
|
|
377
|
+
// rank: perm government.manage — assign a CUSTOM role to a builder.
|
|
353
378
|
// assigned_by is ALWAYS the session builder, never input (the audit trail's
|
|
354
379
|
// "who did this" must be the authenticated actor).
|
|
355
|
-
router.post('/
|
|
380
|
+
router.post('/government/assignments', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
356
381
|
if (validateOrRespond(req, res, {
|
|
357
382
|
builder_id: { required: true, type: 'integer', min: 1 },
|
|
358
|
-
|
|
383
|
+
rank_key: { required: true, type: 'string', minLength: 2, maxLength: RANK_KEY_MAX },
|
|
359
384
|
})) return;
|
|
360
|
-
const
|
|
361
|
-
if (!
|
|
362
|
-
return res.fail('
|
|
385
|
+
const rankKey = req.body.rank_key;
|
|
386
|
+
if (!RANK_KEY_RE.test(rankKey)) {
|
|
387
|
+
return res.fail('bad_rank_key', 400, { rank_key: rankKey, expected: 'a kebab-case slug (^[a-z][a-z0-9-]*$)' });
|
|
363
388
|
}
|
|
364
389
|
try {
|
|
365
|
-
const role = await loadAssignableRole(res,
|
|
390
|
+
const role = await loadAssignableRole(res, rankKey);
|
|
366
391
|
if (role === null) return;
|
|
367
392
|
const assigned = await db.assignRole({
|
|
368
393
|
builderId: req.body.builder_id,
|
|
369
|
-
|
|
394
|
+
rankKey,
|
|
370
395
|
assignedBy: req.builder.id,
|
|
371
396
|
});
|
|
372
|
-
res.status(assigned ? 201 : 200).json({ ok: true, builder_id: req.body.builder_id,
|
|
397
|
+
res.status(assigned ? 201 : 200).json({ ok: true, builder_id: req.body.builder_id, rank_key: rankKey, assigned });
|
|
373
398
|
} catch (err) {
|
|
374
399
|
if (err && err.code === '23503') {
|
|
375
400
|
return res.fail('builder_not_found', 404, { builder_id: req.body.builder_id });
|
|
376
401
|
}
|
|
377
|
-
console.error('[gds] POST /
|
|
402
|
+
console.error('[gds] POST /government/assignments', err);
|
|
378
403
|
res.fail('assign_failed', { status: 500, message: 'internal error' });
|
|
379
404
|
}
|
|
380
405
|
});
|
|
381
406
|
|
|
382
|
-
// rank: perm
|
|
407
|
+
// rank: perm government.manage — remove a custom-role assignment. Idempotent:
|
|
383
408
|
// `removed` says whether a row went away.
|
|
384
|
-
router.delete('/
|
|
409
|
+
router.delete('/government/assignments/:builderId/:rankKey', api.requireBuilder, api.requirePermission('government.manage'), async (req, res) => {
|
|
385
410
|
const builderId = parseId(req, res, { param: 'builderId', code: 'bad_builder_id', positiveInt: true });
|
|
386
411
|
if (builderId === null) return;
|
|
387
|
-
const
|
|
388
|
-
if (
|
|
412
|
+
const rankKey = rankKeyParam(req, res);
|
|
413
|
+
if (rankKey === null) return;
|
|
389
414
|
try {
|
|
390
|
-
const role = await loadAssignableRole(res,
|
|
415
|
+
const role = await loadAssignableRole(res, rankKey);
|
|
391
416
|
if (role === null) return;
|
|
392
|
-
const removed = await db.unassignRole({ builderId,
|
|
393
|
-
res.json({ ok: true, builder_id: builderId,
|
|
417
|
+
const removed = await db.unassignRole({ builderId, rankKey });
|
|
418
|
+
res.json({ ok: true, builder_id: builderId, rank_key: rankKey, removed });
|
|
394
419
|
} catch (err) {
|
|
395
|
-
console.error('[gds] DELETE /
|
|
420
|
+
console.error('[gds] DELETE /government/assignments/:builderId/:rankKey', err);
|
|
396
421
|
res.fail('unassign_failed', { status: 500, message: 'internal error' });
|
|
397
422
|
}
|
|
398
423
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// The governance module's rank-role SYNC port (ADR 0151, BV1.R95b).
|
|
4
4
|
//
|
|
5
|
-
// A second, deliberately tiny kernel port beside `
|
|
5
|
+
// A second, deliberately tiny kernel port beside `government` (routes/government.js).
|
|
6
6
|
// `governance` is the READ surface every gate resolves on every request; this is the
|
|
7
7
|
// single WRITE core needs — "this builder's rank is now X, make their seeded
|
|
8
8
|
// rank-role match". They are kept apart on purpose:
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// The port name is namespaced (`government.rankSync`) like the `ideas.capture` /
|
|
15
15
|
// `art.getBuilderGeminiKeyRow` / `grade.builderRollingAvgGrade` ports.
|
|
16
16
|
//
|
|
17
|
-
// Registered from a route factory for the same reason routes/
|
|
17
|
+
// Registered from a route factory for the same reason routes/government.js is:
|
|
18
18
|
// mountModuleRoutes is the one boot hook that runs BOTH in the live server and
|
|
19
19
|
// whenever a test rebuilds the router, and registration is hasProvider-guarded so a
|
|
20
20
|
// rebuild never trips the seam's single-provider duplicate guard.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// Like The Watch + The Harbor, this reads /api/bongos/me to show a Sealed notice for
|
|
11
11
|
// non-Archons — DEFENCE IN DEPTH only. GET /gate-approvals + POST
|
|
12
12
|
// /gate-approvals/:pr/approve are ALSO archon-gated server-side (ADR 0016), and
|
|
13
|
-
// the page itself is gated by server.js
|
|
13
|
+
// the page itself is gated by server.js requireGovernmentPage. On 401 → web sign-in.
|
|
14
14
|
|
|
15
15
|
(() => {
|
|
16
16
|
'use strict';
|
|
@@ -217,8 +217,8 @@
|
|
|
217
217
|
me = null;
|
|
218
218
|
}
|
|
219
219
|
const rank = (me && (me.builder || me).rank || '').toLowerCase();
|
|
220
|
-
// ADR 0157: the Gate page sits at the `page.view.
|
|
221
|
-
// server's
|
|
220
|
+
// ADR 0157: the Gate page sits at the `page.view.government` floor (metic). The
|
|
221
|
+
// server's requireGovernmentPage is the wall — this only decides whether to render the
|
|
222
222
|
// body or the sealed notice, so it must agree or a Metic sees "sealed" on a page
|
|
223
223
|
// they were just admitted to.
|
|
224
224
|
if (rank !== 'metic' && rank !== 'archon') { showSealed(); return; }
|
|
@@ -6,28 +6,28 @@
|
|
|
6
6
|
.gov-h { color: var(--ink); font-size: 16px; font-weight: 600; margin: 22px 0 8px; }
|
|
7
7
|
.gov-h--minor { font-size: 13px; margin: 18px 0 6px; }
|
|
8
8
|
.gov-grid-note { color: var(--ink-soft); font-size: 12.5px; margin: 0 0 12px; }
|
|
9
|
-
/* Holds the rank
|
|
9
|
+
/* Holds the ladder-rank reset button. Empty for every other rank, so it collapses
|
|
10
10
|
rather than reserving a gap — hence no margin on the empty box itself. */
|
|
11
11
|
.gov-grid-actions:not(:empty) { margin: 0 0 14px; }
|
|
12
12
|
.gov-sealed, .gov-empty { color: var(--ink-soft); padding: 16px 0; }
|
|
13
13
|
|
|
14
|
-
/* Two columns on wide screens:
|
|
14
|
+
/* Two columns on wide screens: rank rail left, permission grid right. */
|
|
15
15
|
.gov-layout { display: grid; grid-template-columns: 260px 1fr; gap: 22px; align-items: start; }
|
|
16
16
|
@media (max-width: 760px) { .gov-layout { grid-template-columns: 1fr; } }
|
|
17
17
|
|
|
18
|
-
/* ----
|
|
19
|
-
.gov-
|
|
20
|
-
.gov-
|
|
18
|
+
/* ---- rank list ---------------------------------------------------------- */
|
|
19
|
+
.gov-rank-list { display: flex; flex-direction: column; gap: 8px; }
|
|
20
|
+
.gov-rank {
|
|
21
21
|
text-align: left; font: inherit; cursor: pointer;
|
|
22
22
|
border: 1px solid var(--border); border-radius: var(--radius-sm);
|
|
23
23
|
background: var(--surface); padding: 10px 12px;
|
|
24
24
|
display: flex; flex-direction: column; gap: 4px;
|
|
25
25
|
}
|
|
26
|
-
.gov-
|
|
27
|
-
.gov-
|
|
28
|
-
.gov-
|
|
29
|
-
.gov-
|
|
30
|
-
.gov-
|
|
26
|
+
.gov-rank:hover { background: var(--surface-2); }
|
|
27
|
+
.gov-rank[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
|
|
28
|
+
.gov-rank__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
|
29
|
+
.gov-rank__label { font-weight: 600; color: var(--ink); font-size: 13.5px; }
|
|
30
|
+
.gov-rank__meta { color: var(--ink-faint); font-size: 11.5px; }
|
|
31
31
|
|
|
32
32
|
.gov-pill {
|
|
33
33
|
font-size: 10.5px; font-weight: 600;
|
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>
|
|
7
|
-
<meta name="description" content="
|
|
6
|
+
<title>Government — {{worldName}}</title>
|
|
7
|
+
<meta name="description" content="Ranks and permissions — create a custom rank, grant everyday permissions, assign it to a builder. Trust-boundary powers stay locked.">
|
|
8
8
|
<link rel="icon" href="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><text x='16' y='24' font-size='24' text-anchor='middle' font-family='sans-serif'>⌂</text></svg>">
|
|
9
9
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
10
10
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
11
11
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
12
12
|
<link rel="stylesheet" href="/builders/style.css?v=2026-07-02-shell1">
|
|
13
|
-
<link rel="stylesheet" href="/builders/
|
|
13
|
+
<link rel="stylesheet" href="/builders/government.css">
|
|
14
14
|
</head>
|
|
15
|
-
<body data-page="
|
|
15
|
+
<body data-page="government" data-page-title="Government">
|
|
16
16
|
|
|
17
17
|
<div class="app">
|
|
18
18
|
<aside class="app-sidebar" id="app-sidebar" aria-label="Primary"></aside>
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
|
|
28
28
|
<section id="gov-body" hidden>
|
|
29
29
|
<div class="gov-layout">
|
|
30
|
-
<div class="gov-
|
|
31
|
-
<h2 class="gov-h">
|
|
32
|
-
<div class="gov-
|
|
30
|
+
<div class="gov-ranks-col">
|
|
31
|
+
<h2 class="gov-h">Ranks</h2>
|
|
32
|
+
<div class="gov-rank-list" id="gov-rank-list"></div>
|
|
33
33
|
<form class="gov-create" id="gov-create-form" autocomplete="off">
|
|
34
|
-
<h3 class="gov-h gov-h--minor">New custom
|
|
35
|
-
<input class="gov-input" id="gov-create-key" placeholder="
|
|
34
|
+
<h3 class="gov-h gov-h--minor">New custom rank</h3>
|
|
35
|
+
<input class="gov-input" id="gov-create-key" placeholder="rank-key (kebab-case)" maxlength="64" required>
|
|
36
36
|
<input class="gov-input" id="gov-create-label" placeholder="Label" maxlength="200" required>
|
|
37
37
|
<input class="gov-input" id="gov-create-desc" placeholder="Description (optional)" maxlength="2000">
|
|
38
|
-
<button class="gov-btn" type="submit">Create
|
|
38
|
+
<button class="gov-btn" type="submit">Create rank</button>
|
|
39
39
|
</form>
|
|
40
40
|
</div>
|
|
41
41
|
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
</div>
|
|
49
49
|
|
|
50
50
|
<h2 class="gov-h">Assignments</h2>
|
|
51
|
-
<p class="gov-grid-note">Hand a custom
|
|
51
|
+
<p class="gov-grid-note">Hand a custom rank to a builder. The four ladder ranks are assigned by rank itself and cannot be granted here.</p>
|
|
52
52
|
<form class="gov-assign" id="gov-assign-form" autocomplete="off">
|
|
53
53
|
<input class="gov-input gov-input--id" id="gov-assign-builder" type="number" min="1" placeholder="Builder id" required>
|
|
54
|
-
<select class="gov-input" id="gov-assign-
|
|
54
|
+
<select class="gov-input" id="gov-assign-rank" required></select>
|
|
55
55
|
<button class="gov-btn" type="submit">Assign</button>
|
|
56
56
|
</form>
|
|
57
57
|
<div id="gov-assignments"></div>
|
|
58
58
|
|
|
59
59
|
<h2 class="gov-h">Machine principals</h2>
|
|
60
|
-
<p class="gov-grid-note">Capabilities held by a machine identity, never by a person or a
|
|
60
|
+
<p class="gov-grid-note">Capabilities held by a machine identity, never by a person or a rank. Shown for completeness — nothing here can be granted.</p>
|
|
61
61
|
<div id="gov-principals"></div>
|
|
62
62
|
</section>
|
|
63
63
|
</main>
|
|
@@ -73,6 +73,6 @@
|
|
|
73
73
|
<!-- jump palette (Ctrl/Cmd-K). Optional by design: without it the shell's slot stays hidden. -->
|
|
74
74
|
<script src="/builders/palette.js" defer></script>
|
|
75
75
|
<script src="/builders/dom-utils.js?v=2026-06-16-gate"></script>
|
|
76
|
-
<script src="/builders/
|
|
76
|
+
<script src="/builders/government.js?v=2026-08-06-governance"></script>
|
|
77
77
|
</body>
|
|
78
78
|
</html>
|