@bongos/core 1.20.57 → 1.20.59
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 +188 -53
- package/clients/bongos-client/README.md +1 -1
- package/clients/bongos-client/bongos-client.global.js +10 -0
- package/clients/bongos-client/index.cjs +10 -0
- package/clients/bongos-client/index.d.ts +14 -4
- package/clients/bongos-client/index.mjs +10 -0
- package/docs/api/openapi.json +220 -20
- package/docs/api-reference.md +8 -3
- package/docs/architecture.md +1 -0
- package/docs/copy-inventory.md +21 -5
- package/docs/copy-registry.json +169 -15
- package/docs/module-api-changelog.md +4 -0
- package/docs/page-inventory.json +8 -3
- package/docs/page-readings.json +72 -72
- package/migrations/core_268_builders_main_discipline.sql +35 -0
- package/modules/copy-desk/artist-stats.js +56 -0
- package/modules/copy-desk/module.json +1 -1
- package/modules/copy-desk/page-status.js +39 -0
- package/modules/copy-desk/routes/copy-desk.js +7 -16
- package/modules/copy-desk/tests/copy_no_cms.mjs +10 -1
- package/modules/economy/credits-by-craft.js +208 -0
- package/modules/economy/reward.js +8 -0
- package/modules/hall-ui/public/genesis/r5-life-1-primordial-sea-cut.webp +0 -0
- package/modules/hall-ui/public/genesis/r5-life-1-primordial-sea.jpg +0 -0
- package/modules/hall-ui/public/genesis/r5-life-2-first-cells-cut.webp +0 -0
- package/modules/hall-ui/public/genesis/r5-life-2-first-cells.jpg +0 -0
- package/modules/hall-ui/public/genesis/r5-life-3-genome-cut.webp +0 -0
- package/modules/hall-ui/public/genesis/r5-life-3-genome.jpg +0 -0
- package/modules/hall-ui/public/genesis/r5-life-4-membrane-cut.webp +0 -0
- package/modules/hall-ui/public/genesis/r5-life-4-membrane.jpg +0 -0
- package/modules/hall-ui/public/genesis/r5-life-5-nervous-system-cut.webp +0 -0
- package/modules/hall-ui/public/genesis/r5-life-5-nervous-system.jpg +0 -0
- package/modules/hall-ui/public/genesis-home.js +349 -0
- package/modules/hall-ui/public/hall-render.js +2 -2
- package/modules/hall-ui/public/index-genesis-decide.states.json +13 -0
- package/modules/hall-ui/public/index-genesis.states.json +13 -0
- package/modules/hall-ui/public/index.html +2 -0
- package/modules/hall-ui/public/profile.js +1 -1
- package/modules/hall-ui/public/style.css +65 -0
- package/modules/hall-ui/records/genesis-home.md +18 -0
- package/modules/ideas/ideator-stats.js +149 -0
- package/modules/ideas/module.json +2 -1
- package/modules/ideas/routes/inbox.js +7 -0
- package/modules/lifecycle/activity.js +5 -2
- package/modules/lifecycle/db-analytics.js +4 -2
- package/modules/lifecycle/db-tasks.js +49 -1
- package/modules/lifecycle/db.js +3 -2
- package/modules/lifecycle/kickoff-checklist.js +54 -1
- package/modules/lifecycle/kickoff-seed.js +61 -2
- package/modules/lifecycle/page-tweak-reads.js +23 -5
- package/modules/lifecycle/routes/kickoff-seed.js +7 -1
- package/modules/onboarding/genesis-home.js +274 -0
- package/modules/onboarding/routes/onboarding.js +56 -0
- package/modules/ui-design/kit/fixtures/founding-genesis-decide.json +108 -0
- package/modules/ui-design/kit/fixtures/founding-genesis-stage.json +162 -0
- package/modules/ui-design/kit/fixtures/government-constitution-sample.json +205 -0
- package/modules/ui-design/kit/serve.js +7 -1
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/release-notes.json +12 -0
- package/scripts/gds/run-unit-tests.js +5 -0
- package/src/bongos/db.js +44 -6
- package/src/bongos/role-stats.js +155 -0
- package/src/bongos/routes/builders.js +15 -2
- package/src/bongos/routes/me.js +11 -3
- package/src/module-api.js +1 -1
- package/tests/copy_desk_page_reads.mjs +1 -1
- package/tests/fixtures/page-ledger.mjs +1 -1
- package/tests/genesis_home.mjs +288 -0
- package/tests/main_discipline.mjs +81 -0
- package/tests/profile_role_stats.mjs +416 -0
- package/tests/role_stats_db.mjs +237 -0
- package/tests/tweak_replaces_artist_review.mjs +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// modules/ideas/ideator-stats.js — THE IDEATOR'S NUMBERS for the profile
|
|
4
|
+
// (task 1004433 / WA6.RP03, goal 1000095, criterion wa6-roles-read-true-in-public;
|
|
5
|
+
// the owner-approved mock is docs/design/mocks/profile-roles/, task 1004431).
|
|
6
|
+
//
|
|
7
|
+
// The profile's header and "By the numbers" lead with each person's own craft.
|
|
8
|
+
// For an ideator that is six numbers, and every one of them is a COUNT or a SUM
|
|
9
|
+
// over the sky's own derivation, never a second one:
|
|
10
|
+
//
|
|
11
|
+
// filed thoughts filed (the person's trail, skill-friction rows left out)
|
|
12
|
+
// ignited thoughts that became paid work (state.hasWork, the sky's ignition)
|
|
13
|
+
// full Full Ideas (grade 'full')
|
|
14
|
+
// ratified Full Ideas the Board Room carried (government.boardPassForIdea)
|
|
15
|
+
// size credits earned from ideas across EVERY idea stream, plus the
|
|
16
|
+
// historical estimate, with the marker that says so
|
|
17
|
+
// alive the share of the work their thoughts caused that is still alive
|
|
18
|
+
//
|
|
19
|
+
// WHERE EACH COMES FROM. The trail is `readSkyMine` (./sky-mine.js), which walks
|
|
20
|
+
// the whole trail and runs the three attachers in the trail route's order, so a
|
|
21
|
+
// thought's size, brightness and state here are the ones the sky draws. Nothing
|
|
22
|
+
// in this file derives a state.
|
|
23
|
+
//
|
|
24
|
+
// SIZE IS EVERY STREAM, NOT STREAM 1. A thought's drawn size is its stream-1
|
|
25
|
+
// payout (economy/idea-size.js: the work it caused). The PERSON's total is a
|
|
26
|
+
// different question, "what has thinking earned you", and the owner's mock
|
|
27
|
+
// answers it across every way ideas are paid: the task ship and its descent, the
|
|
28
|
+
// Full Idea pass, the board pass and the spark/developer split. That is the
|
|
29
|
+
// ledger's ideator column (economy/credits-by-craft.js, through the `reward`
|
|
30
|
+
// port), so the headline agrees with the earnings chart to the credit. The
|
|
31
|
+
// historical estimate (spec decision 17) rides on top, from the per-thought
|
|
32
|
+
// sizes the sky already priced: money the ledger was never there to pay, so it
|
|
33
|
+
// is reported apart as `size.estimated` and marked, never folded in silently.
|
|
34
|
+
//
|
|
35
|
+
// ALIVE IS WEIGHTED BY SIZE, like a single thought's brightness: the live
|
|
36
|
+
// credits over all credits, across every thought that ignited. A thought that
|
|
37
|
+
// could not be read (`attributable: false`) makes the whole share unknown
|
|
38
|
+
// (null) rather than quietly counting it as alive, and a person whose thoughts
|
|
39
|
+
// caused nothing yet has no share at all (null, `has_work: false`): zero over
|
|
40
|
+
// zero is not "nothing survived". The two nulls are told apart by `has_work`.
|
|
41
|
+
//
|
|
42
|
+
// PUBLIC BY THE OWNER'S DECISION (a) of 2026-09-30: the identity band, the
|
|
43
|
+
// tally and "By the numbers" stay public, the trail itself does not. So these
|
|
44
|
+
// are counts and sums only. No title, no id, no triage note leaves this file,
|
|
45
|
+
// and the read is the same for every viewer: the skill-friction gate is applied
|
|
46
|
+
// at the least-privileged real rank, because those rows are a routine's
|
|
47
|
+
// filings, not a person's thoughts, and a count must not change with who looks.
|
|
48
|
+
|
|
49
|
+
const api = require('../../src/module-api');
|
|
50
|
+
const { readSkyMine } = require('./sky-mine');
|
|
51
|
+
|
|
52
|
+
// The rank the counts are read at. xenos is the one rank the skill-friction gate
|
|
53
|
+
// hides those rows from (./skill-friction.js); reading at it makes the public
|
|
54
|
+
// count the count of the person's own thoughts.
|
|
55
|
+
const PUBLIC_VIEWER_RANK = 'xenos';
|
|
56
|
+
|
|
57
|
+
function int(v) {
|
|
58
|
+
const n = Number(v);
|
|
59
|
+
return Number.isFinite(n) ? Math.round(n) : 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// summarizeIdeatorTrail — the six numbers from a trail that already carries
|
|
63
|
+
// size and state. Pure. `ideatorCredits` is the ledger's ideator column (null
|
|
64
|
+
// when economy could not be asked), `ratifiedIds` the set of idea ids the board
|
|
65
|
+
// carried (null when the government port is absent).
|
|
66
|
+
function summarizeIdeatorTrail(ideas, { ideatorCredits = null, ratifiedIds = null, truncated = false, total = null } = {}) {
|
|
67
|
+
const list = Array.isArray(ideas) ? ideas : [];
|
|
68
|
+
let ignited = 0;
|
|
69
|
+
let full = 0;
|
|
70
|
+
let ratified = 0;
|
|
71
|
+
let estimated = 0;
|
|
72
|
+
let estimateKnown = true;
|
|
73
|
+
let credits = 0;
|
|
74
|
+
let live = 0;
|
|
75
|
+
let attributable = true;
|
|
76
|
+
for (const idea of list) {
|
|
77
|
+
if (!idea) continue;
|
|
78
|
+
const st = idea.state || {};
|
|
79
|
+
if (st.hasWork === true) ignited++;
|
|
80
|
+
if (idea.grade === 'full') {
|
|
81
|
+
full++;
|
|
82
|
+
if (ratifiedIds && ratifiedIds.has(String(idea.id))) ratified++;
|
|
83
|
+
}
|
|
84
|
+
const size = idea.size;
|
|
85
|
+
if (!size) { estimateKnown = false; continue; }
|
|
86
|
+
if (size.estimated == null) estimateKnown = false;
|
|
87
|
+
else estimated += int(size.estimated);
|
|
88
|
+
if (st.hasWork === true) {
|
|
89
|
+
const c = Number(size.credits) || 0;
|
|
90
|
+
credits += c;
|
|
91
|
+
if (st.attributable !== true || st.brightness == null) attributable = false;
|
|
92
|
+
else live += c * Number(st.brightness);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const paid = ideatorCredits == null ? null : int(ideatorCredits);
|
|
96
|
+
const est = estimateKnown ? estimated : null;
|
|
97
|
+
return {
|
|
98
|
+
// The trail's own count, not the page in hand: past the sky's cap the list
|
|
99
|
+
// is the newest thousand and `truncated` says the other numbers are partial.
|
|
100
|
+
filed: Number.isInteger(total) ? total : list.length,
|
|
101
|
+
ignited,
|
|
102
|
+
full_ideas: full,
|
|
103
|
+
ratified: ratifiedIds ? ratified : null,
|
|
104
|
+
size: {
|
|
105
|
+
total: paid == null ? null : paid + (est || 0),
|
|
106
|
+
paid,
|
|
107
|
+
estimated: est,
|
|
108
|
+
historical: est == null ? null : est > 0,
|
|
109
|
+
},
|
|
110
|
+
alive: {
|
|
111
|
+
share: credits > 0 && attributable ? live / credits : null,
|
|
112
|
+
has_work: credits > 0,
|
|
113
|
+
attributable: credits > 0 ? attributable : null,
|
|
114
|
+
},
|
|
115
|
+
truncated: truncated === true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// readIdeatorStats — the async half: the trail, the ledger column, the board.
|
|
120
|
+
// `deps` lets a test hand in each port; production resolves them optionally, so
|
|
121
|
+
// an instance without economy or the board reads `null` for those numbers
|
|
122
|
+
// (could not ask) rather than 0 (asked, and nothing was there).
|
|
123
|
+
async function readIdeatorStats(builderId, deps = {}) {
|
|
124
|
+
const read = deps.readSkyMine || readSkyMine;
|
|
125
|
+
const reward = 'reward' in deps ? deps.reward : (api.resolveOptional && api.resolveOptional('reward'));
|
|
126
|
+
const government = 'government' in deps ? deps.government : (api.resolveOptional && api.resolveOptional('government'));
|
|
127
|
+
|
|
128
|
+
const sky = await read({ builderId, viewerRank: PUBLIC_VIEWER_RANK });
|
|
129
|
+
const ideas = (sky && sky.ideas) || [];
|
|
130
|
+
|
|
131
|
+
let ideatorCredits = null;
|
|
132
|
+
if (reward && typeof reward.creditsByCraft === 'function') {
|
|
133
|
+
const byCraft = await reward.creditsByCraft([builderId]);
|
|
134
|
+
const row = byCraft.get(String(builderId));
|
|
135
|
+
ideatorCredits = row ? row.ideator : 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let ratifiedIds = null;
|
|
139
|
+
if (government && typeof government.boardPassForIdea === 'function') {
|
|
140
|
+
ratifiedIds = new Set();
|
|
141
|
+
const fulls = ideas.filter((i) => i && i.grade === 'full');
|
|
142
|
+
const passes = await Promise.all(fulls.map((i) => government.boardPassForIdea(i.id)));
|
|
143
|
+
fulls.forEach((i, k) => { if (passes[k]) ratifiedIds.add(String(i.id)); });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return summarizeIdeatorTrail(ideas, { ideatorCredits, ratifiedIds, truncated: sky && sky.truncated, total: sky && sky.total });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = { readIdeatorStats, summarizeIdeatorTrail, PUBLIC_VIEWER_RANK };
|
|
@@ -36,6 +36,7 @@ const express = require('express');
|
|
|
36
36
|
const api = require('../../../src/module-api');
|
|
37
37
|
const inbox = require('../inbox');
|
|
38
38
|
const bornOf = require('../born-of');
|
|
39
|
+
const ideatorStats = require('../ideator-stats');
|
|
39
40
|
// The trail read to the FULL depth of the descent (task 1004089, BV2.R09). Its
|
|
40
41
|
// own file because inbox.js is AT the size ratchet and because a task->task
|
|
41
42
|
// walk is a different relation from the idea->task trail.
|
|
@@ -108,6 +109,12 @@ function registerSeams() {
|
|
|
108
109
|
descendantsOfTask: descent.descendantsOfTask,
|
|
109
110
|
});
|
|
110
111
|
}
|
|
112
|
+
// task 1004433 (WA6.RP03): the ideator's numbers for the profile, counts and
|
|
113
|
+
// sums only, so core's profile route can show them without reading an ideas_
|
|
114
|
+
// table or deriving a state (../ideator-stats.js).
|
|
115
|
+
if (!api.hasProvider('ideas.ideatorStats')) {
|
|
116
|
+
api.registerProvider('ideas.ideatorStats', ideatorStats.readIdeatorStats);
|
|
117
|
+
}
|
|
111
118
|
}
|
|
112
119
|
|
|
113
120
|
// The author-facing shape of a ratification window this request just opened —
|
|
@@ -36,7 +36,10 @@
|
|
|
36
36
|
const api = require('../../src/module-api');
|
|
37
37
|
const { pool } = api;
|
|
38
38
|
const { SMOKE_NOT_LIKE } = require('./db-shared.js');
|
|
39
|
-
|
|
39
|
+
// What THIS person was paid for each row, not the task's whole payout (task
|
|
40
|
+
// 1004433): on a page tweak the artist and the applier are two people's pay, and
|
|
41
|
+
// under cost-plus-only the per-task estimate books nothing at all.
|
|
42
|
+
const { creditsEarnedBySql } = require('./db-tasks.js');
|
|
40
43
|
|
|
41
44
|
// The craft vocabulary this read accepts. Mirrors tasks_discipline_check
|
|
42
45
|
// (migrations 086 + 176). Anything else is treated as "no filter" rather than
|
|
@@ -97,7 +100,7 @@ async function activityTasksByBuilder(builderId, { role = null, limit = DEFAULT_
|
|
|
97
100
|
`SELECT t.id, t.title, t.value_summary, t.visual_url, t.visual_alt,
|
|
98
101
|
t.version_id, t.goal_id, t.kind, t.status, t.shipped_at,
|
|
99
102
|
COALESCE(t.discipline, 'unclassified') AS discipline,
|
|
100
|
-
t.credits_reward, ${
|
|
103
|
+
t.credits_reward, ${creditsEarnedBySql('$1')} AS credits_awarded
|
|
101
104
|
FROM tasks t
|
|
102
105
|
WHERE ${where}
|
|
103
106
|
ORDER BY t.shipped_at DESC NULLS LAST, t.id DESC
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
const api = require('../../src/module-api');
|
|
14
14
|
const { pool, withTx } = api;
|
|
15
15
|
const { SMOKE_NOT_LIKE, gradePassCount, gradeQualityWhere, median } = require('./db-shared.js');
|
|
16
|
-
const { CREDITS_AWARDED_SUBQUERY } = require('./db-tasks.js');
|
|
16
|
+
const { CREDITS_AWARDED_SUBQUERY, creditsEarnedBySql } = require('./db-tasks.js');
|
|
17
17
|
const { helperJoinSql } = require('./page-tweak-artist.js');
|
|
18
18
|
|
|
19
19
|
// -------------------------------------------------------------------------
|
|
@@ -137,8 +137,10 @@ async function estimationDriftSummary() {
|
|
|
137
137
|
|
|
138
138
|
async function recentShippedTasksByBuilder(builderId, limit = 10) {
|
|
139
139
|
const { rows } = await pool.query(
|
|
140
|
+
// task 1004433: the profile's recent works show what THIS builder was paid
|
|
141
|
+
// (creditsEarnedBySql), not the task's whole payout across everyone.
|
|
140
142
|
`SELECT t.id, t.title, t.value_summary, t.visual_url, t.visual_alt, t.version_id, t.status, t.shipped_at, t.credits_reward,
|
|
141
|
-
${
|
|
143
|
+
${creditsEarnedBySql('$1')} AS credits_awarded
|
|
142
144
|
FROM tasks t
|
|
143
145
|
WHERE t.shipped_by = $1
|
|
144
146
|
AND t.status = 'shipped'
|
|
@@ -676,14 +676,61 @@ async function updateTaskModuleKey(id, moduleKey) { return updateTaskColumn(id,
|
|
|
676
676
|
// CASE still short-circuits to 0 for unsettled tasks; note a 'confirmed' task
|
|
677
677
|
// now shows 0 until it LANDS (the credit no longer exists at confirm) — the UI
|
|
678
678
|
// renders the "Est." label until the 'task.shipped' row books at land.
|
|
679
|
+
//
|
|
680
|
+
// task 1004433 (WA6.RP03): the allowlist missed two of the per-task streams, so
|
|
681
|
+
// an approved page read "0 credits" and an idea's payout for the task it caused
|
|
682
|
+
// never counted. Both are booked against the task's own id and are payment FOR
|
|
683
|
+
// that task: `tweak.page_approved:<task>` (the artist lane, ADR 0341 D10, paid
|
|
684
|
+
// INSTEAD of the per-task estimate) and every `idea.credit.*` row carrying this
|
|
685
|
+
// task_id (stream 1 and its descent, ADR 0172 / 0312). Streams 2 and 3 carry no
|
|
686
|
+
// task_id and stay out, as they pay for the thought, not for any task. Matched
|
|
687
|
+
// as prefixes, never by equality: each key embeds the ids it was paid for.
|
|
688
|
+
const TASK_PAYOUT_REASON_SQL =
|
|
689
|
+
`(cl.reason IN ('task.confirmed', 'task.shipped', 'idea_promotion_bonus', 'ship.net_negative')
|
|
690
|
+
OR cl.reason LIKE 'tweak.page\\_approved:%'
|
|
691
|
+
OR cl.reason LIKE 'idea.credit.%')`;
|
|
679
692
|
const CREDITS_AWARDED_SUBQUERY =
|
|
680
693
|
`CASE WHEN t.status IN ('confirmed', 'shipped')
|
|
681
694
|
THEN (SELECT COALESCE(SUM(cl.delta), 0)::int
|
|
682
695
|
FROM credit_log cl
|
|
683
696
|
WHERE cl.task_id = t.id
|
|
684
|
-
AND
|
|
697
|
+
AND ${TASK_PAYOUT_REASON_SQL})
|
|
685
698
|
ELSE 0 END`;
|
|
686
699
|
|
|
700
|
+
// creditsEarnedBySql — what ONE person earned for a task, for the lists that
|
|
701
|
+
// say "this is what <person> was paid" (the profile's recent works and its
|
|
702
|
+
// Activity tab). CREDITS_AWARDED_SUBQUERY above is the TASK's payout across
|
|
703
|
+
// everyone, which was the wrong number there twice over: on a page tweak the
|
|
704
|
+
// artist's page credit and the applier's session reward are two people's pay,
|
|
705
|
+
// and under cost-plus-only (ADR 0146) the per-task estimate books nothing, so a
|
|
706
|
+
// builder who was paid normally read 0 on every row.
|
|
707
|
+
//
|
|
708
|
+
// Two halves, the two attribution keys sumSessionEarnings names (task 1003634):
|
|
709
|
+
// • every per-task payout row this builder holds against the task;
|
|
710
|
+
// • the cost-plus SESSION reward (task_id NULL, keyed by session) for each of
|
|
711
|
+
// this builder's sessions that shipped the task, split evenly across the
|
|
712
|
+
// tasks that session shipped. The session pays for its whole token spend,
|
|
713
|
+
// not for one task, so an even share is the honest per-task figure.
|
|
714
|
+
// `builderRef` is a bound parameter reference such as '$1', never a value.
|
|
715
|
+
// session_records is read through idx_session_records_builder.
|
|
716
|
+
function creditsEarnedBySql(builderRef) {
|
|
717
|
+
if (!/^\$\d+$/.test(builderRef)) throw new Error('creditsEarnedBySql: builderRef must be a bind parameter like $1');
|
|
718
|
+
return `CASE WHEN t.status IN ('confirmed', 'shipped')
|
|
719
|
+
THEN (COALESCE((SELECT SUM(cl.delta)
|
|
720
|
+
FROM credit_log cl
|
|
721
|
+
WHERE cl.task_id = t.id
|
|
722
|
+
AND cl.builder_id = ${builderRef}
|
|
723
|
+
AND ${TASK_PAYOUT_REASON_SQL}), 0)
|
|
724
|
+
+ COALESCE((SELECT ROUND(SUM(cl.delta::numeric / GREATEST(cardinality(sr.task_ids), 1)))
|
|
725
|
+
FROM session_records sr
|
|
726
|
+
JOIN credit_log cl ON cl.session_id = sr.session_id
|
|
727
|
+
AND cl.reason = 'session.token_reward'
|
|
728
|
+
AND cl.builder_id = ${builderRef}
|
|
729
|
+
WHERE sr.builder_id = ${builderRef}
|
|
730
|
+
AND t.id = ANY(sr.task_ids)), 0))::int
|
|
731
|
+
ELSE 0 END`;
|
|
732
|
+
}
|
|
733
|
+
|
|
687
734
|
async function getTask(id) {
|
|
688
735
|
const { rows } = await pool.query(
|
|
689
736
|
`SELECT t.*, ${CREDITS_AWARDED_SUBQUERY} AS credits_awarded,
|
|
@@ -1343,6 +1390,7 @@ async function listOpenArtistReviews({ source, refPrefix, resolvedStatuses = [],
|
|
|
1343
1390
|
|
|
1344
1391
|
module.exports = {
|
|
1345
1392
|
CREDITS_AWARDED_SUBQUERY,
|
|
1393
|
+
creditsEarnedBySql,
|
|
1346
1394
|
REWARD_SUGGESTION_CAP,
|
|
1347
1395
|
createCriterion,
|
|
1348
1396
|
createTask,
|
package/modules/lifecycle/db.js
CHANGED
|
@@ -123,15 +123,16 @@ const {
|
|
|
123
123
|
// the next setter costs nothing.
|
|
124
124
|
//
|
|
125
125
|
// TASK_FACADE_OMIT is what keeps this surface-PRESERVING rather than quietly
|
|
126
|
-
// wider.
|
|
126
|
+
// wider. Three of db-tasks.js's 34 exports were deliberately never re-exported
|
|
127
127
|
// here, and a bare spread would publish them — which ADR 0091 §3 treats as a
|
|
128
128
|
// real surface change, not a tidy-up. Naming them means dropping one has to be
|
|
129
129
|
// somebody's decision. tests/lifecycle_facade_surface.mjs pins the resulting key
|
|
130
130
|
// set, so this can never silently widen or narrow.
|
|
131
131
|
const dbTasks = require('./db-tasks.js');
|
|
132
132
|
const TASK_FACADE_OMIT = new Set([
|
|
133
|
-
// Internal to
|
|
133
|
+
// Internal to the lifecycle's own queries — SQL fragments, not callables.
|
|
134
134
|
'CREDITS_AWARDED_SUBQUERY',
|
|
135
|
+
'creditsEarnedBySql',
|
|
135
136
|
// The version-gate predicate; routes reach it through db-versions, not here.
|
|
136
137
|
'versionAcceptsNewWork',
|
|
137
138
|
]);
|
|
@@ -131,4 +131,57 @@ function kickoffChecklist(spec = {}, { provisioned = false, firstSignIn = false
|
|
|
131
131
|
return tasks.map((t) => ({ ...t }));
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
// ── genesis (task 1004423 / BV2.PS08) ───────────────────────────────────────
|
|
135
|
+
// The five genesis stages are worked as REAL tasks on the new project's board, filed
|
|
136
|
+
// by the same seeder as the kickoff checklist (kickoff-seed.js seedGenesisStages) the
|
|
137
|
+
// moment the founder settles the plan. Each stage closes only when its tasks are
|
|
138
|
+
// finished AND the constitution in force decides it (spec D7), so these are the tasks
|
|
139
|
+
// the Board Room's genesis-stage sitting checks. Ideator decisions, because a stage is
|
|
140
|
+
// a decision written down; an AI session can draft each one the way it drafts any task.
|
|
141
|
+
//
|
|
142
|
+
// A project that already exists (the brownfield path) is asked for what it has first,
|
|
143
|
+
// so its scope stage opens with gathering the existing documents.
|
|
144
|
+
const GENESIS_STEPS = Object.freeze({
|
|
145
|
+
scope: [
|
|
146
|
+
{ title: 'Write the project scope: what we are making, for whom, and what is out of scope',
|
|
147
|
+
description: 'Genesis stage 1 (scope). One page the whole team can read: the thing being made, who it is for, what done looks like for the first version, and what is deliberately left out. When it is written, Goals and the Roadmap wake.' },
|
|
148
|
+
],
|
|
149
|
+
strategize: [
|
|
150
|
+
{ title: 'Write out the strategy, or link the one you already have',
|
|
151
|
+
description: 'Genesis stage 2 (strategize). How the project gets from here to its first version: the order of the big pieces, the risks, and what gets tried first. A strategy that already exists can be linked instead. When it is done, Tasks wake.' },
|
|
152
|
+
],
|
|
153
|
+
charter: [
|
|
154
|
+
{ title: 'Choose the starting government and write the bylaws',
|
|
155
|
+
description: 'Genesis stage 3 (charter). Pick the form of government the project starts under (the genesis plan recommends one from the team size) and write the short bylaws and code of conduct it runs by. When it is done, the Board Room wakes.' },
|
|
156
|
+
],
|
|
157
|
+
legalize: [
|
|
158
|
+
{ title: 'Decide how contributors are rewarded and who can be paid',
|
|
159
|
+
description: 'Genesis stage 4 (legalize). Whether builders earn credits, money or nothing, and the limits that apply (age, country, the entity behind the project). When it is done, the Economy wakes.' },
|
|
160
|
+
],
|
|
161
|
+
legislation: [
|
|
162
|
+
{ title: 'Set the voting rules: who votes and how many must agree',
|
|
163
|
+
description: 'Genesis stage 5 (legislation). Who has a say, and the rule a decision passes by. When it is done, Ranks wake, and the project can come alive.' },
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
const GENESIS_EXISTING_FIRST = {
|
|
167
|
+
title: 'Gather what already exists: link the documents, code and notes the project has',
|
|
168
|
+
description: 'Genesis stage 1 (scope), for a project that already exists. Before writing anything new, link what is already there, so the scope is written from it rather than beside it.',
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// genesisChecklist({ existing }) → { stageKey: [{ title, description, kind, discipline, ref }] }
|
|
172
|
+
// in genesis order. `ref` is the stable per-task key the seeder dedups on, so filing
|
|
173
|
+
// twice files nothing new. Pure — no I/O.
|
|
174
|
+
function genesisChecklist({ existing = false } = {}) {
|
|
175
|
+
const out = {};
|
|
176
|
+
for (const [stage, steps] of Object.entries(GENESIS_STEPS)) {
|
|
177
|
+
const list = stage === 'scope' && existing ? [GENESIS_EXISTING_FIRST, ...steps] : steps;
|
|
178
|
+
// The ref names the step, never its position, so the brownfield step slotting in
|
|
179
|
+
// ahead of scope's own cannot re-key it into a duplicate.
|
|
180
|
+
out[stage] = list.map((t) => ({
|
|
181
|
+
...t, kind: 'decision', discipline: 'ideator', ref: t === GENESIS_EXISTING_FIRST ? 'genesis:scope:existing' : `genesis:${stage}`,
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
module.exports = { kickoffChecklist, productionTopologyKickoff, genesisChecklist };
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
const api = require('../../src/module-api');
|
|
22
22
|
const db = require('./db');
|
|
23
|
-
const { kickoffChecklist } = require('./kickoff-checklist');
|
|
23
|
+
const { kickoffChecklist, genesisChecklist } = require('./kickoff-checklist');
|
|
24
24
|
|
|
25
25
|
// The spec the checklist reads, from the instance's own branding pack. `modules` is
|
|
26
26
|
// empty on purpose: a hub-provisioned project is scaffolded with every optional module
|
|
@@ -71,4 +71,63 @@ async function seedKickoffIfEmpty({ builderId = null } = {}, deps = {}) {
|
|
|
71
71
|
return { seeded, versionId };
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
// ── genesis (task 1004423 / BV2.PS08) ───────────────────────────────────────
|
|
75
|
+
// The same seeder files the five genesis stages as real tasks when the founder settles
|
|
76
|
+
// the genesis plan — one seeder, not a second one (spec reuse table). The kickoff seed
|
|
77
|
+
// is idempotent by emptiness, which cannot work here: by genesis the board already
|
|
78
|
+
// holds the kickoff checklist. So each genesis task carries source 'genesis' and a
|
|
79
|
+
// stable source_ref per step (genesisChecklist's `ref`), and a step already filed is
|
|
80
|
+
// skipped. Filing twice files nothing new.
|
|
81
|
+
const GENESIS_SOURCE = 'genesis';
|
|
82
|
+
|
|
83
|
+
// seedGenesisStages({ builderId, existing }, deps) → { seeded, versionId } | { seeded: 0, skipped }
|
|
84
|
+
async function seedGenesisStages({ builderId = null, existing = false } = {}, deps = {}) {
|
|
85
|
+
const pool = deps.pool || api.pool;
|
|
86
|
+
const insert = deps.createTask || ((row) => db.createTask(row));
|
|
87
|
+
const find = deps.findTaskBySourceRef || ((q) => db.findTaskBySourceRef(q));
|
|
88
|
+
const { rows: versions } = await pool.query(FIRST_VERSION_SQL);
|
|
89
|
+
if (!versions.length) return { seeded: 0, skipped: 'no_version' };
|
|
90
|
+
const versionId = versions[0].id;
|
|
91
|
+
let seeded = 0;
|
|
92
|
+
for (const steps of Object.values(genesisChecklist({ existing }))) {
|
|
93
|
+
for (const t of steps) {
|
|
94
|
+
if (await find({ source: GENESIS_SOURCE, sourceRef: t.ref })) continue;
|
|
95
|
+
await insert({
|
|
96
|
+
versionId,
|
|
97
|
+
title: t.title,
|
|
98
|
+
description: t.description,
|
|
99
|
+
status: 'ready',
|
|
100
|
+
kind: t.kind,
|
|
101
|
+
discipline: t.discipline,
|
|
102
|
+
source: GENESIS_SOURCE,
|
|
103
|
+
sourceRef: t.ref,
|
|
104
|
+
createdBy: builderId,
|
|
105
|
+
// As the kickoff checklist: a project in genesis has no goals yet (Goals wake
|
|
106
|
+
// only when scope is done), so the catch-all is the honest home.
|
|
107
|
+
allowCatchAll: true,
|
|
108
|
+
});
|
|
109
|
+
seeded += 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { seeded, versionId };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// genesisStageTasks(deps) → { stageKey: [{ id, title, status }] } for every genesis
|
|
116
|
+
// task on the board, grouped by the stage its source_ref names. The genesis home lists
|
|
117
|
+
// them, and a stage close hands their ids to the Board Room's finished-tasks gate.
|
|
118
|
+
async function genesisStageTasks(deps = {}) {
|
|
119
|
+
const pool = deps.pool || api.pool;
|
|
120
|
+
const { rows } = await pool.query(
|
|
121
|
+
`SELECT id, title, status, source_ref FROM tasks WHERE source = $1 ORDER BY id ASC`,
|
|
122
|
+
[GENESIS_SOURCE],
|
|
123
|
+
);
|
|
124
|
+
const out = {};
|
|
125
|
+
for (const r of rows) {
|
|
126
|
+
const stage = String(r.source_ref || '').split(':')[1];
|
|
127
|
+
if (!stage) continue;
|
|
128
|
+
(out[stage] = out[stage] || []).push({ id: String(r.id), title: r.title, status: r.status });
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = { seedKickoffIfEmpty, specFromBranding, FIRST_VERSION_SQL, seedGenesisStages, genesisStageTasks, GENESIS_SOURCE };
|
|
@@ -45,11 +45,27 @@ const artistRule = require('./page-tweak-artist');
|
|
|
45
45
|
// autosave runs this on every debounced save, and a page's rounds are a handful
|
|
46
46
|
// while the instance's grow without bound. The prefix is matched with left(),
|
|
47
47
|
// not LIKE, the page claim's own rule (an `_` in an id is never a wildcard).
|
|
48
|
-
|
|
48
|
+
//
|
|
49
|
+
// `artistId` narrows it to ONE artist's rounds (task 1004433 / WA6.RP03): the
|
|
50
|
+
// profile's artist numbers read this on a public page, and an artist's rounds
|
|
51
|
+
// are a handful while the instance's grow without bound. The rounds are found
|
|
52
|
+
// FROM that builder's own web claims (claims by builder_id), never by listing
|
|
53
|
+
// every round and filtering, and a round counts only while its LATEST web
|
|
54
|
+
// claim is still theirs: the D10 payee rule the unscoped read applies.
|
|
55
|
+
// `client` lets a caller run it inside its own transaction (tests/role_stats_db.mjs
|
|
56
|
+
// runs the artist branch against real Postgres, rolled back); default the pool.
|
|
57
|
+
async function listPageTweakTasks({ pageId = null, artistId = null, client = null } = {}) {
|
|
49
58
|
const prefix = pageId ? `page-tweak/${pageId}/` : null;
|
|
50
|
-
const
|
|
59
|
+
const artist = artistId == null ? null : String(artistId);
|
|
60
|
+
const { rows } = await (client || api.pool).query(
|
|
51
61
|
`WITH pt AS (
|
|
52
|
-
SELECT t.id FROM tasks t WHERE t.source = 'page-tweak'
|
|
62
|
+
SELECT t.id FROM tasks t WHERE $2::bigint IS NULL AND t.source = 'page-tweak'
|
|
63
|
+
AND ($1::text IS NULL OR left(t.source_ref, length($1::text)) = $1::text)
|
|
64
|
+
UNION
|
|
65
|
+
SELECT t.id FROM claims c JOIN tasks t ON t.id = c.task_id
|
|
66
|
+
WHERE $2::bigint IS NOT NULL AND c.builder_id = $2::bigint
|
|
67
|
+
AND ${artistRule.webClaimPredicate('c')}
|
|
68
|
+
AND t.source = 'page-tweak'
|
|
53
69
|
AND ($1::text IS NULL OR left(t.source_ref, length($1::text)) = $1::text)
|
|
54
70
|
), web AS (
|
|
55
71
|
SELECT DISTINCT ON (c.task_id) c.task_id, c.builder_id
|
|
@@ -63,7 +79,8 @@ async function listPageTweakTasks({ pageId = null } = {}) {
|
|
|
63
79
|
ac.builder_id AS holder_id, hb.github_login AS holder_login,
|
|
64
80
|
(ac.worktree_name IS NOT NULL) AS holder_worktree,
|
|
65
81
|
wc.builder_id AS artist_id, ab.github_login AS artist_login
|
|
66
|
-
FROM
|
|
82
|
+
FROM pt
|
|
83
|
+
JOIN tasks t ON t.id = pt.id
|
|
67
84
|
LEFT JOIN task_grades g ON g.task_id = t.id
|
|
68
85
|
LEFT JOIN claims ac ON ac.task_id = t.id AND ac.released_at IS NULL
|
|
69
86
|
LEFT JOIN builders hb ON hb.id = ac.builder_id
|
|
@@ -71,8 +88,9 @@ async function listPageTweakTasks({ pageId = null } = {}) {
|
|
|
71
88
|
LEFT JOIN builders ab ON ab.id = wc.builder_id
|
|
72
89
|
WHERE t.source = 'page-tweak'
|
|
73
90
|
AND ($1::text IS NULL OR left(t.source_ref, length($1::text)) = $1::text)
|
|
91
|
+
AND ($2::bigint IS NULL OR wc.builder_id = $2::bigint)
|
|
74
92
|
ORDER BY t.id ASC`,
|
|
75
|
-
[prefix]
|
|
93
|
+
[prefix, artist]
|
|
76
94
|
);
|
|
77
95
|
return rows;
|
|
78
96
|
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// modules/lifecycle/routes/kickoff-seed.js — registers the `lifecycle.kickoffSeed` port
|
|
4
4
|
// (task 1003239): the founder's first board, filed the moment the kernel seats them.
|
|
5
5
|
//
|
|
6
|
-
// Resolved by
|
|
6
|
+
// Resolved by two callers — the first-admin bootstrap in src/bongos/auth-admission.js
|
|
7
|
+
// (seedIfEmpty) and the genesis home in modules/onboarding (seedGenesis, genesisTasks) —
|
|
7
8
|
// through resolveOptional, so an instance without this module signs in exactly as
|
|
8
9
|
// before. A route factory for a routeless capability, for the reason routes/lifecycle.js
|
|
9
10
|
// and routes/rank-sync.js give: mountModuleRoutes is the boot hook that runs in the live
|
|
@@ -17,6 +18,11 @@ const seed = require('../kickoff-seed');
|
|
|
17
18
|
// Delegates at call time (never spreads) so a stubbed seed still bites.
|
|
18
19
|
const kickoffSeedPort = {
|
|
19
20
|
seedIfEmpty: (...a) => seed.seedKickoffIfEmpty(...a),
|
|
21
|
+
// task 1004423: the genesis home files the five stages through the same seeder, and
|
|
22
|
+
// reads them back by stage. Still no HTTP surface here: the genesis home's own routes
|
|
23
|
+
// (modules/onboarding) gate who may file them.
|
|
24
|
+
seedGenesis: (...a) => seed.seedGenesisStages(...a),
|
|
25
|
+
genesisTasks: (...a) => seed.genesisStageTasks(...a),
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
module.exports = function buildLifecycleKickoffSeedRouter() {
|