@bongos/core 1.24.4 → 1.24.6
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 +99 -59
- package/clients/bongos-client/README.md +1 -1
- package/clients/bongos-client/bongos-client.global.js +6 -0
- package/clients/bongos-client/index.cjs +6 -0
- package/clients/bongos-client/index.d.ts +7 -0
- package/clients/bongos-client/index.mjs +6 -0
- package/docs/adr/0396-google-sign-in-a-stand-in-login-and-a-browser-approved-cli-sign-in.md +8 -0
- package/docs/api/openapi.json +110 -5
- package/docs/api-reference.md +6 -3
- package/docs/copy-inventory.md +47 -43
- package/docs/copy-registry.json +81 -45
- package/docs/file-map.md +3 -2
- package/docs/module-api-changelog.md +4 -2
- package/docs/page-inventory.json +2 -1
- package/docs/page-readings.json +64 -56
- package/migrations/core_286_credit_log_no_spend.sql +128 -0
- package/modules/copy-desk/auto-close.js +51 -11
- package/modules/copy-desk/page-status.js +18 -6
- package/modules/copy-desk/tests/copy_no_cms.mjs +8 -1
- package/modules/copy-desk/tests/copy_page_auto_close.mjs +68 -6
- package/modules/copy-desk/tests/copy_page_status.mjs +5 -1
- package/modules/hall-ui/public/tweak-editor.js +2 -1
- package/modules/lifecycle/db-claims.js +2 -2
- package/modules/lifecycle/db-ship.js +2 -2
- package/modules/lifecycle/routes/claims.js +7 -1
- package/modules/platform-identity/account-logins.js +131 -0
- package/modules/platform-identity/migrations/platform_identity_035_account_login_email_idx.sql +19 -0
- package/modules/platform-identity/routes/profile.js +29 -1
- package/modules/platform-identity/routes/sso.js +25 -3
- package/modules/public-landing/public/account.html +114 -0
- package/modules/public-landing/public/account.states.json +1 -0
- package/modules/ui-design/kit/serve.js +24 -0
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/release-notes.json +39 -1
- package/scripts/bongos/codemod-rename-scripts-gds.js +1 -3
- package/scripts/bongos/dev-box-guard.js +0 -1
- package/scripts/bongos/publish-manifest.js +1 -1
- package/scripts/bongos/run-unit-tests.js +4 -0
- package/src/bongos/agent-standing-rules.js +44 -0
- package/src/bongos/auth-github.js +24 -7
- package/src/bongos/module-scope-map.js +3 -2
- package/src/bongos/routes/auth-google.js +71 -5
- package/src/bongos/routes/auth-link.js +132 -0
- package/src/bongos/routes/me.js +4 -1
- package/src/bongos/routes.js +2 -0
- package/src/bongos/sign-in-pages.js +20 -1
- package/src/module-api.js +1 -1
- package/tests/account_linking.mjs +289 -0
- package/tests/account_logins_db.mjs +56 -0
- package/tests/agent_standing_rules.mjs +142 -0
- package/tests/claims_batch_routes.mjs +115 -25
- package/tests/copy_desk_page_release.mjs +20 -0
- package/tests/copy_stuck_page_tweaks.mjs +5 -3
- package/tests/credit_log_no_spend_db.mjs +160 -0
- package/tests/effective_visibility_predicate.mjs +8 -0
- package/tests/government_laws_session.mjs +2 -1
- package/tests/hall_tweak_editor.mjs +11 -0
- package/tests/host_topology_skips.mjs +2 -0
- package/tests/hub_account_page.mjs +91 -5
- package/tests/run_node_reroute.mjs +136 -0
package/docs/page-readings.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"adr": "0341 D3",
|
|
6
6
|
"reread": "node scripts/bongos/page-reader.js --stale",
|
|
7
7
|
"how": ["Generated by node scripts/bongos/page-reader.js (BV2.TW04, task 1004315; ADR 0341 D3). Do not hand-edit.","One entry per page of docs/page-inventory.json. Lines are in page order: the default state first, and a line only another state shows sits where that state shows it, with its state named.","placement: placed = a docs/copy-registry.json row renders it (file, line, string_id); shared = shell text every page of the surface carries (top bar, sidebar, footer), with its row when the registry has one; unplaced = the registry cannot place it (a rewrite becomes an engineer task, ADR 0341 D4).","text keeps {…} where the registry row has a hole, or where a value the page read from its API was filled in. A string that is only such data is counted under omitted.data, not listed.","reading_hash is over the non-shared lines (key, section, text); files_hash is over the page's inventory files. --check compares files_hash only and never opens a browser.","Rendered through the hall-preview harness (hall) and the ui-design kit stub (landing, status), at 1280x800 with the clock pinned, so a reading is the fixture world's page."],
|
|
8
|
-
"counts": {"pages":48,"lines":
|
|
8
|
+
"counts": {"pages":48,"lines":5464,"placed":1686,"shared":427,"unplaced":3351,"omitted_data":3732},
|
|
9
9
|
"pages": [
|
|
10
10
|
{
|
|
11
11
|
"id": "builders:ai-studio",
|
|
@@ -4300,7 +4300,7 @@
|
|
|
4300
4300
|
"surface": "builders",
|
|
4301
4301
|
"title": "Tweak a page",
|
|
4302
4302
|
"states_read": ["doc","typed","chrome","submitted","picking","out"],
|
|
4303
|
-
"files_hash": "
|
|
4303
|
+
"files_hash": "6ea8b7ad13d0121d",
|
|
4304
4304
|
"reading_hash": "711c540ebc7ef977",
|
|
4305
4305
|
"counts": {"lines":23,"placed":15,"shared":1,"unplaced":7},
|
|
4306
4306
|
"omitted": {"data":35},
|
|
@@ -4568,11 +4568,11 @@
|
|
|
4568
4568
|
"id": "landing:account",
|
|
4569
4569
|
"surface": "landing",
|
|
4570
4570
|
"title": "{{productName}} — Your account",
|
|
4571
|
-
"states_read": ["out","in","in-projects-band","in-profile-band","in-building","in-privacy","in-private"],
|
|
4572
|
-
"files_hash": "
|
|
4573
|
-
"reading_hash": "
|
|
4574
|
-
"counts": {"lines":
|
|
4575
|
-
"omitted": {"data":
|
|
4571
|
+
"states_read": ["out","in","in-projects-band","in-profile-band","in-building","in-ways","in-privacy","in-private"],
|
|
4572
|
+
"files_hash": "62466bd448aefdf7",
|
|
4573
|
+
"reading_hash": "a50818bf29267425",
|
|
4574
|
+
"counts": {"lines":100,"placed":46,"shared":12,"unplaced":42},
|
|
4575
|
+
"omitted": {"data":10},
|
|
4576
4576
|
"notes": [],
|
|
4577
4577
|
"lines": [
|
|
4578
4578
|
{"key":"L0001","section":"top bar","text":"Community","placement":"shared"},
|
|
@@ -4618,55 +4618,63 @@
|
|
|
4618
4618
|
{"key":"L0041","section":"your handle","text":"your-handle","placement":"unplaced","attr":"placeholder","state":"in"},
|
|
4619
4619
|
{"key":"L0042","section":"your handle","text":"Lowercase letters, numbers and hyphens, up to 39. You can change it once a week, and your old handle keeps leading to you until you change it again.","placement":"placed","file":"modules/public-landing/public/account.html","line":211,"string_id":"5ceffa7b9d7e","state":"in"},
|
|
4620
4620
|
{"key":"L0043","section":"your handle","text":"change handle","placement":"placed","file":"modules/public-landing/public/account.html","line":212,"string_id":"0a22c9a537b4","state":"in"},
|
|
4621
|
-
{"key":"L0044","section":"
|
|
4622
|
-
{"key":"L0045","section":"
|
|
4623
|
-
{"key":"L0046","section":"
|
|
4624
|
-
{"key":"L0047","section":"
|
|
4625
|
-
{"key":"L0048","section":"
|
|
4626
|
-
{"key":"L0049","section":"
|
|
4627
|
-
{"key":"L0050","section":"
|
|
4628
|
-
{"key":"L0051","section":"
|
|
4629
|
-
{"key":"L0052","section":"who can find you","text":"
|
|
4630
|
-
{"key":"L0053","section":"who can find you","text":"
|
|
4631
|
-
{"key":"L0054","section":"who can find you","text":"
|
|
4632
|
-
{"key":"L0055","section":"who can find you","text":"
|
|
4633
|
-
{"key":"L0056","section":"who can find you","text":"
|
|
4634
|
-
{"key":"L0057","section":"who can find you","text":"
|
|
4635
|
-
{"key":"L0058","section":"who can find you","text":"
|
|
4636
|
-
{"key":"L0059","section":"who can find you","text":"
|
|
4637
|
-
{"key":"L0060","section":"who can find you","text":"
|
|
4638
|
-
{"key":"L0061","section":"who can find you","text":"
|
|
4639
|
-
{"key":"L0062","section":"who can find you","text":"
|
|
4640
|
-
{"key":"L0063","section":"who can find you","text":"
|
|
4641
|
-
{"key":"L0064","section":"who can find you","text":"
|
|
4642
|
-
{"key":"L0065","section":"
|
|
4643
|
-
{"key":"L0066","section":"
|
|
4644
|
-
{"key":"L0067","section":"
|
|
4645
|
-
{"key":"L0068","section":"
|
|
4646
|
-
{"key":"L0069","section":"
|
|
4647
|
-
{"key":"L0070","section":"
|
|
4648
|
-
{"key":"L0071","section":"
|
|
4649
|
-
{"key":"L0072","section":"
|
|
4650
|
-
{"key":"L0073","section":"your record","text":"
|
|
4651
|
-
{"key":"L0074","section":"your record","text":"
|
|
4652
|
-
{"key":"L0075","section":"your record","text":"
|
|
4653
|
-
{"key":"L0076","section":"your record","text":"·
|
|
4654
|
-
{"key":"L0077","section":"your record","text":"
|
|
4655
|
-
{"key":"L0078","section":"
|
|
4656
|
-
{"key":"L0079","section":"
|
|
4657
|
-
{"key":"L0080","section":"
|
|
4658
|
-
{"key":"L0081","section":"
|
|
4659
|
-
{"key":"L0082","section":"
|
|
4660
|
-
{"key":"L0083","section":"
|
|
4661
|
-
{"key":"L0084","section":"
|
|
4662
|
-
{"key":"L0085","section":"
|
|
4663
|
-
{"key":"L0086","section":"
|
|
4664
|
-
{"key":"L0087","section":"
|
|
4665
|
-
{"key":"L0088","section":"
|
|
4666
|
-
{"key":"L0089","section":"
|
|
4667
|
-
{"key":"L0090","section":"
|
|
4668
|
-
{"key":"L0091","section":"
|
|
4669
|
-
{"key":"L0092","section":"
|
|
4621
|
+
{"key":"L0044","section":"ways to sign in","text":"ways to sign in","placement":"placed","file":"modules/public-landing/public/account.html","line":223,"string_id":"667fd4617840","state":"in"},
|
|
4622
|
+
{"key":"L0045","section":"ways to sign in","text":"GitHub, Google or both. Each one opens this same account, with the same credits, ranks and history.","placement":"placed","file":"modules/public-landing/public/account.html","line":224,"string_id":"8c815a28df30","state":"in"},
|
|
4623
|
+
{"key":"L0046","section":"ways to sign in","text":"GitHub","placement":"unplaced","state":"in"},
|
|
4624
|
+
{"key":"L0047","section":"ways to sign in","text":"linked","placement":"unplaced","state":"in"},
|
|
4625
|
+
{"key":"L0048","section":"ways to sign in","text":"Your account was made with GitHub, so GitHub stays linked.","placement":"unplaced","state":"in"},
|
|
4626
|
+
{"key":"L0049","section":"ways to sign in","text":"Google","placement":"unplaced","state":"in"},
|
|
4627
|
+
{"key":"L0050","section":"ways to sign in","text":"Remove","placement":"unplaced","state":"in"},
|
|
4628
|
+
{"key":"L0051","section":"ways to sign in","text":"Linking never joins two accounts. If the other one already has its own account here, we say so and change nothing.","placement":"placed","file":"modules/public-landing/public/account.html","line":228,"string_id":"62bf4cd7f215","state":"in"},
|
|
4629
|
+
{"key":"L0052","section":"who can find you","text":"who can find you","placement":"placed","file":"modules/public-landing/public/account.html","line":240,"string_id":"7322eee6b8b4","state":"in"},
|
|
4630
|
+
{"key":"L0053","section":"who can find you","text":"Your profile page can be public or private, and recruiters are let in separately — so a private profile can still be reachable for work, and a public one can stay out of recruiting entirely.","placement":"placed","file":"modules/public-landing/public/account.html","line":241,"string_id":"38f40fb26117","state":"in"},
|
|
4631
|
+
{"key":"L0054","section":"who can find you","text":"Your profile page","placement":"placed","file":"modules/public-landing/public/account.html","line":244,"string_id":"2df3e63e4761","state":"in"},
|
|
4632
|
+
{"key":"L0055","section":"who can find you","text":"Public","placement":"unplaced","state":"in"},
|
|
4633
|
+
{"key":"L0056","section":"who can find you","text":"Anyone find you.","placement":"placed","file":"modules/public-landing/public/account.html","line":246,"string_id":"525a9aa1dd71","state":"in"},
|
|
4634
|
+
{"key":"L0057","section":"who can find you","text":"Private","placement":"unplaced","state":"in"},
|
|
4635
|
+
{"key":"L0058","section":"who can find you","text":"you are a ninja. Private hides the page from everyone — including you. You see your record here.","placement":"placed","file":"modules/public-landing/public/account.html","line":247,"string_id":"8caf52240833","state":"in"},
|
|
4636
|
+
{"key":"L0059","section":"who can find you","text":"Every guild you belong to counts your numbers in its rounded totals unless you leave them out — even while your profile page is {…}. They are never shown on their own: only inside totals rounded down to a band (10+, 20+, 50+ …) and counted once a week. Each guild’s page has the switch:","placement":"unplaced","state":"in-privacy"},
|
|
4637
|
+
{"key":"L0060","section":"who can find you","text":"· counted","placement":"unplaced","state":"in-privacy"},
|
|
4638
|
+
{"key":"L0061","section":"who can find you","text":"· left out","placement":"unplaced","state":"in-privacy"},
|
|
4639
|
+
{"key":"L0062","section":"who can find you","text":"Recruiters","placement":"unplaced","state":"in"},
|
|
4640
|
+
{"key":"L0063","section":"who can find you","text":"Can find me","placement":"placed","file":"modules/public-landing/public/account.html","line":254,"string_id":"50d493f08964","state":"in"},
|
|
4641
|
+
{"key":"L0064","section":"who can find you","text":"Recruiters looking for builders can find you.","placement":"placed","file":"modules/public-landing/public/account.html","line":254,"string_id":"604f5274ae98","state":"in"},
|
|
4642
|
+
{"key":"L0065","section":"who can find you","text":"Can’t find me","placement":"placed","file":"modules/public-landing/public/account.html","line":255,"string_id":"48d721eb2ed7","state":"in"},
|
|
4643
|
+
{"key":"L0066","section":"who can find you","text":"You stay out of the recruiting directory and a recruiter’s look-up.","placement":"placed","file":"modules/public-landing/public/account.html","line":255,"string_id":"af2177106d7c","state":"in"},
|
|
4644
|
+
{"key":"L0067","section":"who can find you","text":"Because your cross-project record is hidden, they will see your name and your picture, and nothing else. This is the one thing a recruiter can see while your profile page is {…}. Turning this off removes you from both recruiting surfaces — the recruiting directory, and a recruiter’s look-up of one {…} — straight away.","placement":"unplaced","state":"in-private"},
|
|
4645
|
+
{"key":"L0068","section":"who can find you","text":"They will see your name, your picture, your roles, and whether you have been {…} in the last 30 days — never your {…}, works shipped, karma, or the projects you build on. This is the one thing a recruiter can see while your profile page is {…}. Turning this off removes you from both recruiting surfaces — the recruiting directory, and a recruiter’s look-up of one {…} — straight away.","placement":"unplaced","state":"in-privacy"},
|
|
4646
|
+
{"key":"L0069","section":"who can find you","text":"They will see your name, your picture, your roles, and whether you have been {…} in the last 30 days — never your {…}, works shipped, karma, or the projects you build on. Turning this off removes you from both recruiting surfaces — the recruiting directory, and a recruiter’s look-up of one {…} — straight away.","placement":"unplaced","state":"in"},
|
|
4647
|
+
{"key":"L0070","section":"who can find you","text":"· For now this follows your profile page setting.","placement":"unplaced","state":"in"},
|
|
4648
|
+
{"key":"L0071","section":"who can find you","text":"Your profile page setting applies now — private already answers “not found” everywhere your profile is read. Recruiter discoverability applies now too — switching it off removes you from both recruiting surfaces immediately, and back on puts you there again.","placement":"placed","file":"modules/public-landing/public/account.html","line":259,"string_id":"e0d6e4196161","state":"in"},
|
|
4649
|
+
{"key":"L0072","section":"who can find you","text":"save","placement":"unplaced","state":"in"},
|
|
4650
|
+
{"key":"L0073","section":"your record","text":"your record","placement":"placed","file":"modules/public-landing/public/account.html","line":271,"string_id":"b494287ce724","state":"in"},
|
|
4651
|
+
{"key":"L0074","section":"your record","text":"Your track record across every project you build on. Hiding it takes effect immediately everywhere — your profile, the recruiting directory, and a recruiter’s look-up of one builder.","placement":"placed","file":"modules/public-landing/public/account.html","line":272,"string_id":"f18600e9cff1","state":"in"},
|
|
4652
|
+
{"key":"L0075","section":"your record","text":"No cross-project activity reported yet. Your profile is not published yet; it publishes after your next sign-in.","placement":"unplaced","state":"in-private"},
|
|
4653
|
+
{"key":"L0076","section":"your record","text":"Your record: 3 projects · 1000 {…} · 19 works shipped · 10 karma.","placement":"unplaced","state":"in"},
|
|
4654
|
+
{"key":"L0077","section":"your record","text":"Cross-project Record","placement":"placed","file":"modules/public-landing/public/account.html","line":276,"string_id":"d5c4a0e0f864","state":"in"},
|
|
4655
|
+
{"key":"L0078","section":"your record","text":"Show it","placement":"placed","file":"modules/public-landing/public/account.html","line":278,"string_id":"960b894c0ea1","state":"in"},
|
|
4656
|
+
{"key":"L0079","section":"your record","text":"Your stats appear on your profile and in the directories.","placement":"placed","file":"modules/public-landing/public/account.html","line":278,"string_id":"edf1c4f5e0c5","state":"in"},
|
|
4657
|
+
{"key":"L0080","section":"your record","text":"Hide it","placement":"placed","file":"modules/public-landing/public/account.html","line":279,"string_id":"ccd4861996eb","state":"in"},
|
|
4658
|
+
{"key":"L0081","section":"your record","text":"Your stats are hidden.","placement":"placed","file":"modules/public-landing/public/account.html","line":279,"string_id":"44c8b76631bf","state":"in"},
|
|
4659
|
+
{"key":"L0082","section":"your record","text":"Every guild you belong to counts your numbers in its rounded totals unless you leave them out — even while your record is hidden. They are never shown on their own: only inside totals rounded down to a band (10+, 20+, 50+ …) and counted once a week. Each guild’s page has the switch:","placement":"unplaced","state":"in-private"},
|
|
4660
|
+
{"key":"L0083","section":"your record","text":"· counted","placement":"unplaced","state":"in-private"},
|
|
4661
|
+
{"key":"L0084","section":"your record","text":"· left out","placement":"unplaced","state":"in-private"},
|
|
4662
|
+
{"key":"L0085","section":"your record","text":"save","placement":"unplaced","state":"in"},
|
|
4663
|
+
{"key":"L0086","section":"projects you build on","text":"projects you build on","placement":"placed","file":"modules/public-landing/public/account.html","line":296,"string_id":"f8aa3ff34a10","state":"in"},
|
|
4664
|
+
{"key":"L0087","section":"projects you build on","text":"The projects you have joined as a builder. Only you see this list.","placement":"placed","file":"modules/public-landing/public/account.html","line":297,"string_id":"d466ee6b6e30","state":"in"},
|
|
4665
|
+
{"key":"L0088","section":"projects you build on","text":"example.com","placement":"unplaced","state":"in"},
|
|
4666
|
+
{"key":"L0089","section":"projects you build on","text":"Leave","placement":"unplaced","state":"in","occurrences":2},
|
|
4667
|
+
{"key":"L0090","section":"projects you build on","text":"{…}-circles.cloudbongos.com","placement":"unplaced","state":"in"},
|
|
4668
|
+
{"key":"L0091","section":"footer","text":"A non-profit, capture-resistant commons.","placement":"shared","file":"modules/public-landing/public/account.html","line":308,"string_id":"afe83bbbd0d4","state":"in","occurrences":2},
|
|
4669
|
+
{"key":"L0092","section":"footer","text":"Built by agents, on Cloud Bongos.","placement":"shared","file":"modules/public-landing/public/account.html","line":308,"string_id":"bd315dd71ea7","state":"in","occurrences":2},
|
|
4670
|
+
{"key":"L0093","section":"footer","text":"Open source","placement":"shared","file":"modules/public-landing/public/account.html","line":308,"string_id":"d6314ddcc1d0","state":"in","occurrences":2},
|
|
4671
|
+
{"key":"L0094","section":"footer","text":"AGPL-3.0","placement":"shared","state":"in","occurrences":2},
|
|
4672
|
+
{"key":"L0095","section":"navigation","text":"Privacy","placement":"shared","state":"in","occurrences":2},
|
|
4673
|
+
{"key":"L0096","section":"navigation","text":"Terms","placement":"shared","state":"in","occurrences":2},
|
|
4674
|
+
{"key":"L0097","section":"navigation","text":"Contact","placement":"shared","state":"in","occurrences":2},
|
|
4675
|
+
{"key":"L0098","section":"navigation","text":"Builders' hall","placement":"shared","file":"modules/public-landing/public/account.html","line":308,"string_id":"90a128c97eae","state":"in","occurrences":2},
|
|
4676
|
+
{"key":"L0099","section":"your account","text":"Sign in to change your handle, your bio and links, and who can find you.","placement":"placed","file":"modules/public-landing/public/account.html","line":159,"string_id":"d9eefaa86565"},
|
|
4677
|
+
{"key":"L0100","section":"your account","text":"Sign in","placement":"placed","file":"modules/public-landing/public/account.html","line":113,"string_id":"ad80586f802a"}
|
|
4670
4678
|
]
|
|
4671
4679
|
},
|
|
4672
4680
|
{
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
-- core_286_credit_log_no_spend.sql — task 1004988 (goal 1000092; ADR 0385
|
|
2
|
+
-- decision 2, ADR 0387).
|
|
3
|
+
--
|
|
4
|
+
-- Credits measure contribution. They are never spent, transferred or redeemed,
|
|
5
|
+
-- so the ledger has no row that takes credits away for something in return.
|
|
6
|
+
-- Until now that was a convention: credit_log's own column notes listed
|
|
7
|
+
-- 'redemption' as a reason and called a negative delta "spent (future)", and
|
|
8
|
+
-- nothing in Postgres stopped a negative spend row. This makes the DATABASE
|
|
9
|
+
-- refuse it, so no code path — present or future, ours or a module's — can
|
|
10
|
+
-- book one.
|
|
11
|
+
--
|
|
12
|
+
-- WHAT IS ADMITTED. A row with delta >= 0 is admitted as before (earning, and the
|
|
13
|
+
-- delta-0 audit rows rank changes and builder exits write). A NEGATIVE row is
|
|
14
|
+
-- admitted only as a REVERSAL of an existing positive row, in one of two shapes:
|
|
15
|
+
--
|
|
16
|
+
-- 1. reason = 'reversal:<credit_log id>' — the general shape. The named row
|
|
17
|
+
-- must exist, belong to the same builder and be positive, and all the
|
|
18
|
+
-- reversals of it together may not exceed it.
|
|
19
|
+
-- 2. reason = '<original reason>_reversal' with task_id set — the shape
|
|
20
|
+
-- core_194 (ADR 0120's one-time clawback, reason 'task.confirmed_reversal')
|
|
21
|
+
-- already wrote. The reference is the (builder, task, original reason)
|
|
22
|
+
-- rows, which must exist and sum positive; reversals may not exceed them.
|
|
23
|
+
-- Kept so that migration, and the integration test that re-runs it, stay
|
|
24
|
+
-- valid on a database that carries this trigger.
|
|
25
|
+
--
|
|
26
|
+
-- Any other negative row is refused. A row whose reason names a spend,
|
|
27
|
+
-- redemption or transfer is refused at any sign: a positive "transfer in" is
|
|
28
|
+
-- the other half of a transfer, and decision 2 forbids the transfer itself.
|
|
29
|
+
--
|
|
30
|
+
-- WHAT IS NOT CHANGED (ADR 0387). No column is added and no existing row is
|
|
31
|
+
-- read, converted or rewritten: the trigger is BEFORE INSERT only, so history —
|
|
32
|
+
-- including core_194's reversal rows — stays exactly as booked. This does not
|
|
33
|
+
-- contradict ADR 0387's "the only schema change is the money record": that
|
|
34
|
+
-- sentence is about the SHAPE of credit_log (no money column, no backfill), and
|
|
35
|
+
-- this adds none. It enforces ADR 0387 decision 1 ("never redeemable") in the
|
|
36
|
+
-- database rather than in the code that writes the ledger.
|
|
37
|
+
--
|
|
38
|
+
-- Concurrency: the reversed row(s) are locked FOR UPDATE before the reversal
|
|
39
|
+
-- total is summed, so two reversals racing for the same row cannot both pass
|
|
40
|
+
-- the "may not exceed" check.
|
|
41
|
+
--
|
|
42
|
+
-- Cost: a positive row (every normal earning) pays one regex test and returns.
|
|
43
|
+
-- Only a negative row reads the ledger, and every read is indexed: the reversed
|
|
44
|
+
-- row by its primary key (shape 1), the original rows by idx_credit_log_task
|
|
45
|
+
-- (core_189, shape 2), and the reversals already booked by the PARTIAL index
|
|
46
|
+
-- below, which holds negative rows only — so it stays as small as the number of
|
|
47
|
+
-- reversals ever made, not the size of the ledger.
|
|
48
|
+
--
|
|
49
|
+
-- The refused names match as whole words: the name, then a separator (. _ : -)
|
|
50
|
+
-- or the end. So 'spend', 'spend.x' and 'transfer:3' are refused, and a reason
|
|
51
|
+
-- that merely starts with the letters ('spender-of-the-month') is not.
|
|
52
|
+
|
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_credit_log_reversals
|
|
54
|
+
ON credit_log (builder_id, reason) WHERE delta < 0;
|
|
55
|
+
|
|
56
|
+
CREATE OR REPLACE FUNCTION credit_log_refuse_spend() RETURNS trigger AS $$
|
|
57
|
+
DECLARE
|
|
58
|
+
ref_id bigint;
|
|
59
|
+
orig_rec record;
|
|
60
|
+
orig_reason text;
|
|
61
|
+
orig_total bigint;
|
|
62
|
+
reversed bigint;
|
|
63
|
+
BEGIN
|
|
64
|
+
IF NEW.reason ~* '^(redemption|redeem|spend|spent|transfer)([._:-]|$)' THEN
|
|
65
|
+
RAISE EXCEPTION 'credit_log refuses %: credits are never spent, transferred or redeemed (ADR 0385 decision 2)', NEW.reason
|
|
66
|
+
USING ERRCODE = 'check_violation';
|
|
67
|
+
END IF;
|
|
68
|
+
|
|
69
|
+
IF NEW.delta >= 0 THEN
|
|
70
|
+
RETURN NEW;
|
|
71
|
+
END IF;
|
|
72
|
+
|
|
73
|
+
-- Shape 1: 'reversal:<credit_log id>'.
|
|
74
|
+
IF NEW.reason ~ '^reversal:[0-9]{1,18}$' THEN
|
|
75
|
+
ref_id := substring(NEW.reason FROM 10)::bigint;
|
|
76
|
+
SELECT id, builder_id, delta INTO orig_rec FROM credit_log WHERE id = ref_id FOR UPDATE;
|
|
77
|
+
-- Two IFs, not one OR: plpgsql does not promise to short-circuit, and the
|
|
78
|
+
-- fields of a record no row was selected into must not be read.
|
|
79
|
+
IF NOT FOUND THEN
|
|
80
|
+
RAISE EXCEPTION 'credit_log refuses a reversal of row %: no such row', ref_id
|
|
81
|
+
USING ERRCODE = 'check_violation';
|
|
82
|
+
END IF;
|
|
83
|
+
IF orig_rec.builder_id <> NEW.builder_id OR orig_rec.delta <= 0 THEN
|
|
84
|
+
RAISE EXCEPTION 'credit_log refuses a reversal of row %: it must name an existing positive row of the same builder', ref_id
|
|
85
|
+
USING ERRCODE = 'check_violation';
|
|
86
|
+
END IF;
|
|
87
|
+
SELECT COALESCE(SUM(delta), 0) INTO reversed
|
|
88
|
+
FROM credit_log WHERE builder_id = NEW.builder_id AND reason = NEW.reason AND delta < 0;
|
|
89
|
+
IF orig_rec.delta + reversed + NEW.delta < 0 THEN
|
|
90
|
+
RAISE EXCEPTION 'credit_log refuses a reversal of row %: it would reverse more than the row booked', ref_id
|
|
91
|
+
USING ERRCODE = 'check_violation';
|
|
92
|
+
END IF;
|
|
93
|
+
RETURN NEW;
|
|
94
|
+
END IF;
|
|
95
|
+
|
|
96
|
+
-- Shape 2: '<original reason>_reversal' against the same builder and task.
|
|
97
|
+
IF NEW.reason ~ '^[a-z0-9_.]+_reversal$' AND NEW.task_id IS NOT NULL THEN
|
|
98
|
+
orig_reason := left(NEW.reason, length(NEW.reason) - length('_reversal'));
|
|
99
|
+
PERFORM 1 FROM credit_log
|
|
100
|
+
WHERE builder_id = NEW.builder_id AND task_id = NEW.task_id AND reason = orig_reason
|
|
101
|
+
FOR UPDATE;
|
|
102
|
+
SELECT COALESCE(SUM(delta), 0) INTO orig_total
|
|
103
|
+
FROM credit_log WHERE builder_id = NEW.builder_id AND task_id = NEW.task_id AND reason = orig_reason;
|
|
104
|
+
SELECT COALESCE(SUM(delta), 0) INTO reversed
|
|
105
|
+
FROM credit_log WHERE builder_id = NEW.builder_id AND task_id = NEW.task_id AND reason = NEW.reason AND delta < 0;
|
|
106
|
+
IF orig_total <= 0 OR orig_total + reversed + NEW.delta < 0 THEN
|
|
107
|
+
RAISE EXCEPTION 'credit_log refuses %: it must reverse existing % credit on the same task, and no more than was booked', NEW.reason, orig_reason
|
|
108
|
+
USING ERRCODE = 'check_violation';
|
|
109
|
+
END IF;
|
|
110
|
+
RETURN NEW;
|
|
111
|
+
END IF;
|
|
112
|
+
|
|
113
|
+
RAISE EXCEPTION 'credit_log refuses a negative row (reason %): credits are never spent or redeemed; only a reversal of an existing row may be negative (ADR 0385 decision 2)', NEW.reason
|
|
114
|
+
USING ERRCODE = 'check_violation';
|
|
115
|
+
END;
|
|
116
|
+
$$ LANGUAGE plpgsql;
|
|
117
|
+
|
|
118
|
+
DROP TRIGGER IF EXISTS trg_credit_log_refuse_spend ON credit_log;
|
|
119
|
+
CREATE TRIGGER trg_credit_log_refuse_spend
|
|
120
|
+
BEFORE INSERT ON credit_log
|
|
121
|
+
FOR EACH ROW EXECUTE FUNCTION credit_log_refuse_spend();
|
|
122
|
+
|
|
123
|
+
COMMENT ON TABLE credit_log IS
|
|
124
|
+
'Append-only contribution ledger (ADR 0385, ADR 0387). Credits measure work: they are never money, never spent, transferred or redeemed. builders.total_credits is a cache kept by trg_credit_log_apply.';
|
|
125
|
+
COMMENT ON COLUMN credit_log.delta IS
|
|
126
|
+
'Credits earned (positive), an audit row (0), or a reversal of an earlier row (negative). The trigger trg_credit_log_refuse_spend refuses every other negative row.';
|
|
127
|
+
COMMENT ON COLUMN credit_log.reason IS
|
|
128
|
+
'What earned the credits, e.g. task.shipped, session.token_reward, idea.credit.*. A negative row must read reversal:<credit_log id> or <original reason>_reversal with its task_id set.';
|
|
@@ -8,14 +8,20 @@
|
|
|
8
8
|
// hand. Two shapes hold nothing:
|
|
9
9
|
//
|
|
10
10
|
// blank `ready`, no draft and no frozen batch: opened in the
|
|
11
|
-
// studio, nothing written, the claim dropped.
|
|
11
|
+
// studio, nothing written, the claim dropped. Closes once
|
|
12
|
+
// untouched for page-status's BLANK_CLOSES_AFTER (1 day, the
|
|
13
|
+
// owner's answer on task 1004971; task 1004972). Until then
|
|
14
|
+
// it reads `blank` ("Opened, nothing written yet"), never
|
|
15
|
+
// `unknown`.
|
|
12
16
|
// nothing_to_apply `ready` with a frozen batch whose `lines` is empty: every
|
|
13
17
|
// rewrite left the batch for an engineer task at submit
|
|
14
18
|
// (unplaced, shared or removed lines), so /tweak has no line
|
|
15
19
|
// to apply and the round can never move on its own.
|
|
16
20
|
// draft_expired `ready` with a draft and no batch, untouched for
|
|
17
|
-
// page-status's DRAFT_EXPIRES_AFTER (
|
|
18
|
-
//
|
|
21
|
+
// page-status's DRAFT_EXPIRES_AFTER (task 1004901; one day
|
|
22
|
+
// since task 1004976, the owner's answer on task 1004971,
|
|
23
|
+
// with no reminder step first). The draft text stays on
|
|
24
|
+
// the task: no compose, so the description is not touched.
|
|
19
25
|
//
|
|
20
26
|
// All three are abandoned through the lifecycle port's releaseStuckTweak (no compose,
|
|
21
27
|
// so the note is the reason and nothing is written to the description). The
|
|
@@ -32,18 +38,47 @@ const pageStatus = require('./page-status');
|
|
|
32
38
|
const GRACE_MS = Number(process.env.COPY_AUTO_CLOSE_GRACE_MS) || 60 * 60_000;
|
|
33
39
|
|
|
34
40
|
const NOTES = Object.freeze({
|
|
35
|
-
blank: 'Closed
|
|
41
|
+
blank: 'Closed: nothing was written. The round was opened and left blank for a day; claim the page again to start one.',
|
|
36
42
|
nothing_to_apply: 'Closed by itself: every rewritten line went to an engineer task, so nothing was left to apply on the page.',
|
|
37
|
-
draft_expired: 'Closed by itself: the draft sat untouched for
|
|
43
|
+
draft_expired: 'Closed by itself: the draft sat untouched for a day. Its words stay on this task; claim the page again to start over.',
|
|
44
|
+
orphaned_apply: 'Released: the apply stopped without finishing. Nobody holds this round any more, so it is back in the queue.',
|
|
38
45
|
});
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
// task 1004972 T2 (task 1004973): an ORPHANED round is `active` with no open
|
|
48
|
+
// claim. The applier's claim was released (the runner's reconcile, a crashed
|
|
49
|
+
// worker, a dropped session) but the status never moved, so it read `unknown`
|
|
50
|
+
// and nothing ever picked it up again. A round someone still holds, a live and
|
|
51
|
+
// heartbeating apply, is never touched: holder_id is the open claim, and the
|
|
52
|
+
// lifecycle port re-checks that no claim was taken under its row lock.
|
|
53
|
+
function orphanReason(task, { now = Date.now(), graceMs = GRACE_MS } = {}) {
|
|
54
|
+
if (!task || task.status !== 'active' || task.holder_id != null) return null;
|
|
55
|
+
const touched = Date.parse(task.updated_at || task.created_at || '');
|
|
56
|
+
if (!Number.isFinite(touched) || now - touched < graceMs) return null;
|
|
57
|
+
return 'orphaned_apply';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The orphan goes back to `ready` with its description kept whole plus the
|
|
61
|
+
// reason, as a sent-back block (pages.appendSentBack, the one writer of that
|
|
62
|
+
// block, which only APPENDS). A frozen batch then reads `submitted` again and the
|
|
63
|
+
// next applier reads why; a draft stays a draft. No word of the draft or the
|
|
64
|
+
// batch is changed.
|
|
65
|
+
function releaseKeeping(note, at, by) {
|
|
66
|
+
return (task) => pages.appendSentBack(task.description, { at, by, note });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function closeReason(task, {
|
|
70
|
+
now = Date.now(), graceMs = GRACE_MS,
|
|
71
|
+
draftExpiresMs = pageStatus.DRAFT_EXPIRES_AFTER, blankClosesMs = pageStatus.BLANK_CLOSES_AFTER,
|
|
72
|
+
} = {}) {
|
|
41
73
|
if (!task || task.status !== 'ready' || task.holder_id != null) return null;
|
|
42
74
|
const touched = Date.parse(task.updated_at || task.created_at || '');
|
|
43
75
|
if (!Number.isFinite(touched) || now - touched < graceMs) return null;
|
|
44
76
|
const p = pages.blockPresence(task.description);
|
|
45
|
-
|
|
46
|
-
|
|
77
|
+
const age = now - touched;
|
|
78
|
+
// task 1004901: a draft its artist left untouched expires. task 1004972: a
|
|
79
|
+
// blank round closes after a day. A batch with lines is never touched here,
|
|
80
|
+
// and a draft only by its own expiry.
|
|
81
|
+
if (!p.batch) return p.draft ? (age >= draftExpiresMs ? 'draft_expired' : null) : (age >= blankClosesMs ? 'blank' : null);
|
|
47
82
|
const b = pages.parseBatchBlock(task.description);
|
|
48
83
|
if (b.ok && b.batch.lines.length === 0) return 'nothing_to_apply';
|
|
49
84
|
return null;
|
|
@@ -58,16 +93,21 @@ async function runAutoClose({ now = Date.now(), resolve = (k) => (api.resolveOpt
|
|
|
58
93
|
return { closed: [], skipped: 'no_lifecycle' };
|
|
59
94
|
}
|
|
60
95
|
const tasks = await lifecycle.listPageTweakTasks();
|
|
61
|
-
const due = tasks.map((t) => ({ t, why: closeReason(t, { now }) })).filter((x) => x.why);
|
|
96
|
+
const due = tasks.map((t) => ({ t, why: closeReason(t, { now }) || orphanReason(t, { now }) })).filter((x) => x.why);
|
|
62
97
|
if (!due.length) return { closed: [] };
|
|
63
98
|
const owner = await founder();
|
|
64
99
|
if (!owner) return { closed: [], skipped: 'no_owner' };
|
|
65
100
|
const closed = [];
|
|
101
|
+
const at = new Date(now).toISOString();
|
|
66
102
|
for (const { t, why } of due) {
|
|
67
|
-
const
|
|
103
|
+
const orphan = why === 'orphaned_apply';
|
|
104
|
+
const r = await lifecycle.releaseStuckTweak({
|
|
105
|
+
taskId: t.id, builderId: owner.id, expectedStatus: orphan ? 'active' : 'ready', note: NOTES[why],
|
|
106
|
+
...(orphan ? { compose: releaseKeeping(NOTES[why], at, String(owner.id)) } : {}),
|
|
107
|
+
});
|
|
68
108
|
closed.push({ task_id: String(t.id), why, outcome: r.outcome });
|
|
69
109
|
}
|
|
70
110
|
return { closed };
|
|
71
111
|
}
|
|
72
112
|
|
|
73
|
-
module.exports = { closeReason, runAutoClose };
|
|
113
|
+
module.exports = { closeReason, orphanReason, runAutoClose };
|
|
@@ -193,7 +193,11 @@ function roundState(round) {
|
|
|
193
193
|
if (p.last_sent_back_at && (!p.applied_at || p.applied_at <= p.last_sent_back_at)) return 'submitted';
|
|
194
194
|
return 'unknown';
|
|
195
195
|
}
|
|
196
|
-
|
|
196
|
+
// task 1004972: opened and nothing written is a state of its own, not one
|
|
197
|
+
// the reads cannot name. It waits on its artist and closes itself after
|
|
198
|
+
// BLANK_CLOSES_AFTER (the auto-close sweep), so it never reads "Needs to be
|
|
199
|
+
// reviewed" or asks an applier to release it.
|
|
200
|
+
return p.draft ? 'draft' : 'blank';
|
|
197
201
|
case 'completed':
|
|
198
202
|
// A held pass waits for the artist; a failed grade stays with the applier.
|
|
199
203
|
return round.grade_passed === true ? 'waiting_for_artist' : 'applying';
|
|
@@ -307,8 +311,8 @@ function orderedSurfaces(inventory) {
|
|
|
307
311
|
// This is every page with an open round, where it is, since when (the round's
|
|
308
312
|
// last update), and whether it has sat there too long. Waiting for review is
|
|
309
313
|
// the artist's own move and a draft is theirs to finish: a draft or a page
|
|
310
|
-
// being written is stuck after 7 days and a draft expires after
|
|
311
|
-
// 1004901); a review is stuck after 3 days (task 1004777, so its artist is
|
|
314
|
+
// being written is stuck after 7 days, and a draft left untouched expires after
|
|
315
|
+
// one day (task 1004901, shortened by task 1004976); a review is stuck after 3 days (task 1004777, so its artist is
|
|
312
316
|
// told); a state the reads cannot name always needs to be reviewed.
|
|
313
317
|
// ---------------------------------------------------------------------------
|
|
314
318
|
|
|
@@ -318,9 +322,15 @@ const DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
318
322
|
// work) and WHEN it is overdue (stuck_after: then it is pushed to that person on
|
|
319
323
|
// Home and in the daily digest). A draft nobody touches also EXPIRES
|
|
320
324
|
// (expires_after): the auto-close sweep abandons it, its words kept on the task.
|
|
321
|
-
|
|
325
|
+
// task 1004976 (owner, task 1004971): a draft expires after ONE day, and there
|
|
326
|
+
// is no separate reminder step at that length, so the draft is due when it
|
|
327
|
+
// expires (stuck_after = expires_after), not reminded a week before.
|
|
328
|
+
const DRAFT_EXPIRES_AFTER = DAY_MS;
|
|
329
|
+
// task 1004972 (owner, task 1004971): a round opened and left blank closes after a day.
|
|
330
|
+
const BLANK_CLOSES_AFTER = DAY_MS;
|
|
322
331
|
const IN_FLIGHT = Object.freeze({
|
|
323
|
-
|
|
332
|
+
blank: { word: 'Opened, nothing written yet', stuck_after: BLANK_CLOSES_AFTER, waits_on: 'artist', expires_after: BLANK_CLOSES_AFTER },
|
|
333
|
+
draft: { word: 'Being written', stuck_after: DRAFT_EXPIRES_AFTER, waits_on: 'artist', expires_after: DRAFT_EXPIRES_AFTER },
|
|
324
334
|
writing: { word: 'Being written', stuck_after: 7 * DAY_MS, waits_on: 'artist' },
|
|
325
335
|
words_review: { word: 'Words waiting for review', stuck_after: 3 * DAY_MS, waits_on: 'artist' },
|
|
326
336
|
submitted: { word: 'Approved, waiting to be applied', stuck_after: 3 * DAY_MS, waits_on: 'appliers' },
|
|
@@ -330,7 +340,7 @@ const IN_FLIGHT = Object.freeze({
|
|
|
330
340
|
landing: { word: 'Approved, going live', stuck_after: DAY_MS, waits_on: 'appliers' },
|
|
331
341
|
unknown: { word: 'Needs to be reviewed', stuck_after: 0, waits_on: 'appliers' },
|
|
332
342
|
});
|
|
333
|
-
const IN_FLIGHT_ORDER = ['unknown', 'landing', 'applying', 'submitted', 'waiting_for_artist', 'words_review', 'writing', 'draft'];
|
|
343
|
+
const IN_FLIGHT_ORDER = ['unknown', 'landing', 'applying', 'submitted', 'waiting_for_artist', 'words_review', 'writing', 'draft', 'blank'];
|
|
334
344
|
|
|
335
345
|
function inFlightFor(list, byPage, nowMs) {
|
|
336
346
|
const out = [];
|
|
@@ -980,4 +990,6 @@ module.exports = {
|
|
|
980
990
|
stuckDigestText,
|
|
981
991
|
// task 1004901: when an untouched draft expires (the auto-close sweep reads it).
|
|
982
992
|
DRAFT_EXPIRES_AFTER,
|
|
993
|
+
// task 1004972: when a blank round closes (the auto-close sweep reads it).
|
|
994
|
+
BLANK_CLOSES_AFTER,
|
|
983
995
|
};
|
|
@@ -312,8 +312,15 @@ await test('the module manifest declares no seam another module could write copy
|
|
|
312
312
|
assert.equal(/writeFile|\.query\(|UPDATE |INSERT /.test(stuckSrc), false, 'the stuck-tweaks port writes nothing');
|
|
313
313
|
// task 1004899: the auto-close sweep only ABANDONS an empty round through the
|
|
314
314
|
// lifecycle port; it never hands a compose, so it cannot write a description.
|
|
315
|
+
// task 1004973: it may hand ONE compose, for an orphaned apply released back to
|
|
316
|
+
// the queue, and that compose is pages.appendSentBack: it appends the reason and
|
|
317
|
+
// changes no word (copy_page_auto_close.mjs proves the description is kept whole).
|
|
315
318
|
const closeSrc = stripComments(read('auto-close.js'));
|
|
316
|
-
assert.equal(/writeFile|\.query\(|UPDATE |INSERT
|
|
319
|
+
assert.equal(/writeFile|\.query\(|UPDATE |INSERT /.test(closeSrc), false, 'the auto-close sweep writes nothing itself');
|
|
320
|
+
const composes = closeSrc.match(/\bcompose\b[^\n]*/g) || [];
|
|
321
|
+
assert.deepEqual(composes.length, 1, 'one compose, for the orphan release');
|
|
322
|
+
assert.match(closeSrc, /\(task\) => pages\.appendSentBack\(task\.description, \{ at, by, note \}\)/, 'and it only appends the sent-back note');
|
|
323
|
+
assert.equal(/composeDraftBlock|composeBatchBlock|saveDraftInto|replaceBlock/.test(closeSrc), false, 'no draft or batch writer');
|
|
317
324
|
const stats = read('artist-stats.js');
|
|
318
325
|
assert.equal(/\b(pool|query|writeFile|appendFile|INSERT|UPDATE|DELETE)\b/.test(stats.replace(/\/\/.*$/gm, '')), false,
|
|
319
326
|
'the artist-stats port reads through other ports and writes nothing');
|