@seasonkoh/webaz 0.1.26 → 0.1.27
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/LICENSE +2 -2
- package/NOTICE +24 -3
- package/README.md +74 -330
- package/README.zh-CN.md +419 -0
- package/dist/layer0-foundation/L0-2-state-machine/genuine-sale.js +21 -0
- package/dist/layer0-foundation/L0-5-manifest/manifest.js +8 -3
- package/dist/layer1-agent/L1-1-mcp-server/auth.js +13 -1
- package/dist/layer1-agent/L1-1-mcp-server/server.js +36 -28
- package/dist/layer2-business/L2-9-contribution/admin-coordination-ingestion-engine.js +181 -0
- package/dist/layer2-business/L2-9-contribution/admin-coordination-resolver.js +114 -0
- package/dist/layer2-business/L2-9-contribution/admin-coordination-store.js +251 -0
- package/dist/layer2-business/L2-9-contribution/admin-operator-claim-workflow.js +390 -0
- package/dist/layer2-business/L2-9-contribution/build-task-agent-metadata-store.js +24 -0
- package/dist/layer2-business/L2-9-contribution/build-task-participation.js +6 -2
- package/dist/layer2-business/L2-9-contribution/build-task-quota.js +337 -0
- package/dist/layer2-business/L2-9-contribution/build-task-read.js +25 -2
- package/dist/layer2-business/L2-9-contribution/build-tasks-engine.js +57 -7
- package/dist/layer2-business/L2-9-contribution/canonical-contribution-target.js +1 -1
- package/dist/layer2-business/L2-9-contribution/contribution-facts-read.js +66 -0
- package/dist/layer2-business/L2-9-contribution/task-proposal-draft.js +187 -18
- package/dist/layer2-business/L2-9-contribution/task-proposal-store.js +29 -4
- package/dist/ledger.js +1 -1
- package/dist/pwa/admin-audit.js +38 -0
- package/dist/pwa/anti-abuse-thresholds.js +135 -0
- package/dist/pwa/cf-origin-guard.js +33 -0
- package/dist/pwa/contract-fingerprint.js +1 -0
- package/dist/pwa/data/onboarding-cases.js +2 -2
- package/dist/pwa/data/onboarding-quiz.js +1 -1
- package/dist/pwa/economic-participation.js +2 -2
- package/dist/pwa/integration-contract.js +46 -4
- package/dist/pwa/internal/pv-settlement.js +12 -0
- package/dist/pwa/internal/wallet-signer.js +26 -0
- package/dist/pwa/public/app.js +679 -679
- package/dist/pwa/public/i18n.js +15 -28
- package/dist/pwa/public/index.html +1 -1
- package/dist/pwa/public/openapi.json +4760 -2769
- package/dist/pwa/pv-kill-switch.js +31 -0
- package/dist/pwa/routes/admin-admins.js +48 -1
- package/dist/pwa/routes/admin-analytics.js +1 -10
- package/dist/pwa/routes/admin-atomic.js +4 -17
- package/dist/pwa/routes/admin-operator-claims.js +280 -0
- package/dist/pwa/routes/admin-reports.js +4 -26
- package/dist/pwa/routes/admin-tokenomics.js +2 -76
- package/dist/pwa/routes/admin-users-lifecycle.js +1 -14
- package/dist/pwa/routes/admin-users-query.js +23 -1
- package/dist/pwa/routes/admin-wallet-ops.js +1 -1
- package/dist/pwa/routes/auth-read.js +1 -5
- package/dist/pwa/routes/auth-register.js +3 -13
- package/dist/pwa/routes/build-task-quota.js +113 -0
- package/dist/pwa/routes/claim-verify.js +15 -11
- package/dist/pwa/routes/contribution-facts.js +18 -0
- package/dist/pwa/routes/dispute-cases.js +5 -4
- package/dist/pwa/routes/growth.js +3 -3
- package/dist/pwa/routes/orders-action.js +27 -10
- package/dist/pwa/routes/orders-create.js +1 -1
- package/dist/pwa/routes/products-meta.js +19 -6
- package/dist/pwa/routes/profile-placement.js +1 -1
- package/dist/pwa/routes/promoter.js +10 -29
- package/dist/pwa/routes/public-build-tasks.js +5 -1
- package/dist/pwa/routes/public-utils.js +9 -12
- package/dist/pwa/routes/referral.js +5 -26
- package/dist/pwa/routes/rewards-apply.js +3 -2
- package/dist/pwa/routes/share-redirects.js +1 -1
- package/dist/pwa/routes/shareables-interactions.js +2 -1
- package/dist/pwa/routes/task-proposals.js +85 -9
- package/dist/pwa/routes/users-public.js +1 -4
- package/dist/pwa/routes/wallet-read.js +2 -14
- package/dist/pwa/routes/webauthn.js +1 -1
- package/dist/pwa/server.js +156 -469
- package/dist/settlement-math.js +3 -3
- package/dist/version.js +6 -4
- package/package.json +33 -7
- package/dist/index.js +0 -182
- package/dist/pwa/public/docs/ECONOMIC-MODEL.md +0 -287
- package/dist/pwa/public/docs/INTEGRATOR.md +0 -67
- package/dist/pwa/public/docs/META-RULES-FULL.md +0 -543
- package/dist/test-dispute.js +0 -153
- package/dist/test-manifest.js +0 -61
- package/dist/test-mcp-tools.js +0 -135
- package/dist/test-reputation.js +0 -116
- package/dist/test-skill-market.js +0 -101
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
const COORD_TABLES = ['admin_coordination_fact_sources', 'admin_operator_claim_confirmations', 'admin_operator_unlink_requests', 'admin_operator_claim_marking_corrections', 'admin_operator_claim_events', 'agent_execution_mandate_events'];
|
|
2
|
+
const CREATE_OPERATOR_CLAIM_EVENTS = `
|
|
3
|
+
CREATE TABLE IF NOT EXISTS admin_operator_claim_events (
|
|
4
|
+
event_id TEXT PRIMARY KEY,
|
|
5
|
+
event_type TEXT NOT NULL CHECK (event_type IN ('claimed','approved','revoked','superseded')),
|
|
6
|
+
admin_account_id TEXT NOT NULL REFERENCES users(id),
|
|
7
|
+
contributor_account_id TEXT NOT NULL REFERENCES users(id),
|
|
8
|
+
approval_kind TEXT CHECK (approval_kind IS NULL OR approval_kind IN ('independent_governance','root_approval','founder_bootstrap_override')),
|
|
9
|
+
approved_by TEXT REFERENCES users(id),
|
|
10
|
+
conflict_disclosure TEXT NOT NULL DEFAULT 'unknown' CHECK (conflict_disclosure IN ('none','self_or_related','unknown')),
|
|
11
|
+
effective_from TEXT,
|
|
12
|
+
effective_to TEXT,
|
|
13
|
+
rationale TEXT,
|
|
14
|
+
supersedes_event_id TEXT REFERENCES admin_operator_claim_events(event_id),
|
|
15
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16
|
+
immutable INTEGER NOT NULL DEFAULT 1 CHECK (immutable = 1),
|
|
17
|
+
CHECK (event_type <> 'approved' OR (approval_kind IS NOT NULL AND approved_by IS NOT NULL AND conflict_disclosure IN ('none','self_or_related') AND (admin_account_id <> contributor_account_id OR (approval_kind IN ('root_approval','founder_bootstrap_override') AND conflict_disclosure = 'self_or_related'))))
|
|
18
|
+
)
|
|
19
|
+
`;
|
|
20
|
+
const CREATE_MANDATE_EVENTS = `
|
|
21
|
+
CREATE TABLE IF NOT EXISTS agent_execution_mandate_events (
|
|
22
|
+
event_id TEXT PRIMARY KEY,
|
|
23
|
+
event_type TEXT NOT NULL CHECK (event_type IN ('granted','revoked','superseded')),
|
|
24
|
+
mandate_id TEXT NOT NULL,
|
|
25
|
+
owner_contributor_account_id TEXT NOT NULL REFERENCES users(id),
|
|
26
|
+
agent_ref TEXT NOT NULL,
|
|
27
|
+
passport_ref TEXT,
|
|
28
|
+
scope TEXT,
|
|
29
|
+
allowed_actions TEXT NOT NULL DEFAULT '[]',
|
|
30
|
+
risk_limit TEXT,
|
|
31
|
+
cost_bearer_account_id TEXT REFERENCES users(id),
|
|
32
|
+
human_confirmation_points TEXT NOT NULL DEFAULT '[]',
|
|
33
|
+
effective_from TEXT,
|
|
34
|
+
expires_at TEXT,
|
|
35
|
+
revoked_at TEXT,
|
|
36
|
+
value_state TEXT NOT NULL DEFAULT 'uncommitted' CHECK (value_state = 'uncommitted'),
|
|
37
|
+
created_by TEXT REFERENCES users(id),
|
|
38
|
+
approved_by TEXT REFERENCES users(id),
|
|
39
|
+
rationale TEXT,
|
|
40
|
+
supersedes_event_id TEXT REFERENCES agent_execution_mandate_events(event_id),
|
|
41
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
42
|
+
immutable INTEGER NOT NULL DEFAULT 1 CHECK (immutable = 1),
|
|
43
|
+
CHECK (event_type <> 'granted' OR (cost_bearer_account_id IS NOT NULL AND approved_by IS NOT NULL AND allowed_actions <> '[]' AND allowed_actions <> ''))
|
|
44
|
+
)
|
|
45
|
+
`;
|
|
46
|
+
const CREATE_CLAIM_CONFIRMATIONS = `
|
|
47
|
+
CREATE TABLE IF NOT EXISTS admin_operator_claim_confirmations (
|
|
48
|
+
confirmation_id TEXT PRIMARY KEY,
|
|
49
|
+
claimed_event_id TEXT NOT NULL REFERENCES admin_operator_claim_events(event_id),
|
|
50
|
+
admin_account_id TEXT NOT NULL REFERENCES users(id),
|
|
51
|
+
contributor_account_id TEXT NOT NULL REFERENCES users(id),
|
|
52
|
+
decision TEXT NOT NULL CHECK (decision IN ('accepted','rejected')),
|
|
53
|
+
decided_by TEXT NOT NULL REFERENCES users(id),
|
|
54
|
+
rationale TEXT,
|
|
55
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
56
|
+
immutable INTEGER NOT NULL DEFAULT 1 CHECK (immutable = 1),
|
|
57
|
+
CHECK (decided_by = contributor_account_id),
|
|
58
|
+
UNIQUE (claimed_event_id)
|
|
59
|
+
)
|
|
60
|
+
`;
|
|
61
|
+
const CREATE_FACT_SOURCES = `
|
|
62
|
+
CREATE TABLE IF NOT EXISTS admin_coordination_fact_sources (
|
|
63
|
+
fact_id TEXT PRIMARY KEY REFERENCES contribution_facts(fact_id),
|
|
64
|
+
admin_audit_log_id TEXT NOT NULL UNIQUE REFERENCES admin_audit_log(id),
|
|
65
|
+
source_type TEXT NOT NULL,
|
|
66
|
+
source_id TEXT,
|
|
67
|
+
visibility TEXT NOT NULL DEFAULT 'governance_only' CHECK (visibility IN ('private','governance_only','public')),
|
|
68
|
+
redaction_summary TEXT,
|
|
69
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
70
|
+
)
|
|
71
|
+
`;
|
|
72
|
+
// Unlink (解除) requests — admin-seat owner OR contributor asks to sever an ACTIVE approved claim;
|
|
73
|
+
// only ROOT may approve, which then revokes the claim. Append-only event log: 'requested' → 'approved'
|
|
74
|
+
// | 'rejected' (decision supersedes the request via supersedes_request_id). NEVER touches
|
|
75
|
+
// contribution_facts. requester_role distinguishes who asked; human_auth_ref records the passkey gate.
|
|
76
|
+
const CREATE_UNLINK_REQUESTS = `
|
|
77
|
+
CREATE TABLE IF NOT EXISTS admin_operator_unlink_requests (
|
|
78
|
+
request_event_id TEXT PRIMARY KEY,
|
|
79
|
+
event_type TEXT NOT NULL CHECK (event_type IN ('requested','approved','rejected')),
|
|
80
|
+
approved_event_id TEXT NOT NULL REFERENCES admin_operator_claim_events(event_id),
|
|
81
|
+
claimed_event_id TEXT NOT NULL,
|
|
82
|
+
admin_account_id TEXT NOT NULL REFERENCES users(id),
|
|
83
|
+
contributor_account_id TEXT NOT NULL REFERENCES users(id),
|
|
84
|
+
requested_by TEXT REFERENCES users(id),
|
|
85
|
+
requester_role TEXT CHECK (requester_role IS NULL OR requester_role IN ('admin_seat','contributor')),
|
|
86
|
+
decided_by TEXT REFERENCES users(id),
|
|
87
|
+
approval_kind TEXT CHECK (approval_kind IS NULL OR approval_kind IN ('independent_governance','root_approval','founder_bootstrap_override')),
|
|
88
|
+
conflict_disclosure TEXT CHECK (conflict_disclosure IS NULL OR conflict_disclosure IN ('none','self_or_related','unknown')),
|
|
89
|
+
reason TEXT,
|
|
90
|
+
human_auth_ref TEXT,
|
|
91
|
+
supersedes_request_id TEXT REFERENCES admin_operator_unlink_requests(request_event_id),
|
|
92
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
93
|
+
immutable INTEGER NOT NULL DEFAULT 1 CHECK (immutable = 1),
|
|
94
|
+
CHECK (event_type <> 'requested' OR (requested_by IS NOT NULL AND requester_role IN ('admin_seat','contributor'))),
|
|
95
|
+
CHECK (event_type = 'requested' OR decided_by IS NOT NULL)
|
|
96
|
+
)
|
|
97
|
+
`;
|
|
98
|
+
// Additive migration: add the decision-marking columns to an EXISTING unlink table (it may already
|
|
99
|
+
// exist from the lifecycle deploy; CREATE IF NOT EXISTS won't add columns). Guarded → idempotent.
|
|
100
|
+
const ALTER_UNLINK_MARKING = [
|
|
101
|
+
`ALTER TABLE admin_operator_unlink_requests ADD COLUMN approval_kind TEXT`,
|
|
102
|
+
`ALTER TABLE admin_operator_unlink_requests ADD COLUMN conflict_disclosure TEXT`,
|
|
103
|
+
];
|
|
104
|
+
// Append-only GOVERNANCE-MARKING CORRECTION overlay. An already-approved claim's disclosure label can be
|
|
105
|
+
// wrong (e.g. a founder/root self/related bootstrap recorded as 'independent_governance' / 'none'). We do
|
|
106
|
+
// NOT UPDATE/backdate the original approved event (that would corrupt the as-of interval); instead a root
|
|
107
|
+
// admin appends a correction that REFERENCES the approved event and supplies the honest marking. The
|
|
108
|
+
// resolver overlays the latest correction at read time. Only honest markings are storable: approval_kind
|
|
109
|
+
// must be root_approval|founder_bootstrap_override (NEVER independent_governance) and conflict_disclosure
|
|
110
|
+
// must be self_or_related; correction_reason is required. Append-only (BEFORE UPDATE/DELETE → ABORT).
|
|
111
|
+
const CREATE_MARKING_CORRECTIONS = `
|
|
112
|
+
CREATE TABLE IF NOT EXISTS admin_operator_claim_marking_corrections (
|
|
113
|
+
correction_event_id TEXT PRIMARY KEY,
|
|
114
|
+
approved_event_id TEXT NOT NULL REFERENCES admin_operator_claim_events(event_id),
|
|
115
|
+
approval_kind TEXT NOT NULL CHECK (approval_kind IN ('root_approval','founder_bootstrap_override')),
|
|
116
|
+
conflict_disclosure TEXT NOT NULL CHECK (conflict_disclosure IN ('self_or_related')),
|
|
117
|
+
correction_reason TEXT NOT NULL CHECK (length(trim(correction_reason)) > 0),
|
|
118
|
+
corrected_by_root_admin_id TEXT NOT NULL REFERENCES users(id),
|
|
119
|
+
corrected_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
120
|
+
immutable INTEGER NOT NULL DEFAULT 1 CHECK (immutable = 1)
|
|
121
|
+
)
|
|
122
|
+
`;
|
|
123
|
+
const CREATE_INDEXES = [
|
|
124
|
+
`CREATE INDEX IF NOT EXISTS idx_aoce_admin ON admin_operator_claim_events(admin_account_id)`,
|
|
125
|
+
`CREATE INDEX IF NOT EXISTS idx_aoce_supersedes ON admin_operator_claim_events(supersedes_event_id)`,
|
|
126
|
+
`CREATE INDEX IF NOT EXISTS idx_aeme_agent ON agent_execution_mandate_events(agent_ref)`,
|
|
127
|
+
`CREATE INDEX IF NOT EXISTS idx_aocc_claimed ON admin_operator_claim_confirmations(claimed_event_id)`,
|
|
128
|
+
`CREATE INDEX IF NOT EXISTS idx_aocc_contributor ON admin_operator_claim_confirmations(contributor_account_id)`,
|
|
129
|
+
`CREATE INDEX IF NOT EXISTS idx_aour_approved ON admin_operator_unlink_requests(approved_event_id)`,
|
|
130
|
+
`CREATE INDEX IF NOT EXISTS idx_aour_supersedes ON admin_operator_unlink_requests(supersedes_request_id)`,
|
|
131
|
+
`CREATE INDEX IF NOT EXISTS idx_aocmc_approved ON admin_operator_claim_marking_corrections(approved_event_id)`,
|
|
132
|
+
];
|
|
133
|
+
const TRIGGER_AOCE_NO_UPDATE = `CREATE TRIGGER IF NOT EXISTS trg_aoce_no_update BEFORE UPDATE ON admin_operator_claim_events BEGIN SELECT RAISE(ABORT, 'admin_operator_claim_events is append-only (UPDATE forbidden)'); END`;
|
|
134
|
+
const TRIGGER_AOCE_NO_DELETE = `CREATE TRIGGER IF NOT EXISTS trg_aoce_no_delete BEFORE DELETE ON admin_operator_claim_events BEGIN SELECT RAISE(ABORT, 'admin_operator_claim_events is append-only (DELETE forbidden)'); END`;
|
|
135
|
+
const TRIGGER_AEME_NO_UPDATE = `CREATE TRIGGER IF NOT EXISTS trg_aeme_no_update BEFORE UPDATE ON agent_execution_mandate_events BEGIN SELECT RAISE(ABORT, 'agent_execution_mandate_events is append-only (UPDATE forbidden)'); END`;
|
|
136
|
+
const TRIGGER_AEME_NO_DELETE = `CREATE TRIGGER IF NOT EXISTS trg_aeme_no_delete BEFORE DELETE ON agent_execution_mandate_events BEGIN SELECT RAISE(ABORT, 'agent_execution_mandate_events is append-only (DELETE forbidden)'); END`;
|
|
137
|
+
const TRIGGER_ACFS_NO_UPDATE = `CREATE TRIGGER IF NOT EXISTS trg_acfs_no_update BEFORE UPDATE ON admin_coordination_fact_sources BEGIN SELECT RAISE(ABORT, 'admin_coordination_fact_sources is append-only (UPDATE forbidden)'); END`;
|
|
138
|
+
const TRIGGER_ACFS_NO_DELETE = `CREATE TRIGGER IF NOT EXISTS trg_acfs_no_delete BEFORE DELETE ON admin_coordination_fact_sources BEGIN SELECT RAISE(ABORT, 'admin_coordination_fact_sources is append-only (DELETE forbidden)'); END`;
|
|
139
|
+
// Once an admin_audit_log row is referenced as contribution evidence, it IS evidence truth — freeze it.
|
|
140
|
+
// The FK already blocks DELETE of a referenced row; these scoped triggers additionally block UPDATE (and
|
|
141
|
+
// re-block DELETE defensively). Non-referenced audit rows stay fully mutable. (gen-pg-schema emits the
|
|
142
|
+
// equivalent conditional plpgsql guard.)
|
|
143
|
+
const TRIGGER_AAL_FREEZE_UPDATE = `CREATE TRIGGER IF NOT EXISTS trg_aal_freeze_evidence_update BEFORE UPDATE ON admin_audit_log WHEN EXISTS (SELECT 1 FROM admin_coordination_fact_sources WHERE admin_audit_log_id = OLD.id) BEGIN SELECT RAISE(ABORT, 'admin_audit_log row is referenced as contribution evidence — immutable (UPDATE forbidden)'); END`;
|
|
144
|
+
const TRIGGER_AAL_FREEZE_DELETE = `CREATE TRIGGER IF NOT EXISTS trg_aal_freeze_evidence_delete BEFORE DELETE ON admin_audit_log WHEN EXISTS (SELECT 1 FROM admin_coordination_fact_sources WHERE admin_audit_log_id = OLD.id) BEGIN SELECT RAISE(ABORT, 'admin_audit_log row is referenced as contribution evidence — immutable (DELETE forbidden)'); END`;
|
|
145
|
+
const TRIGGER_AOCC_NO_UPDATE = `CREATE TRIGGER IF NOT EXISTS trg_aocc_no_update BEFORE UPDATE ON admin_operator_claim_confirmations BEGIN SELECT RAISE(ABORT, 'admin_operator_claim_confirmations is append-only (UPDATE forbidden)'); END`;
|
|
146
|
+
const TRIGGER_AOCC_NO_DELETE = `CREATE TRIGGER IF NOT EXISTS trg_aocc_no_delete BEFORE DELETE ON admin_operator_claim_confirmations BEGIN SELECT RAISE(ABORT, 'admin_operator_claim_confirmations is append-only (DELETE forbidden)'); END`;
|
|
147
|
+
// A confirmation MUST reference a real 'claimed' event whose admin+contributor match this row — a
|
|
148
|
+
// confirmation can never be attached to a mismatched/forged (admin,contributor) pair. (gen-pg-schema
|
|
149
|
+
// emits the equivalent conditional plpgsql BEFORE INSERT guard.)
|
|
150
|
+
const TRIGGER_AOCC_MATCH = `CREATE TRIGGER IF NOT EXISTS trg_aocc_match_claim BEFORE INSERT ON admin_operator_claim_confirmations WHEN NOT EXISTS (SELECT 1 FROM admin_operator_claim_events e WHERE e.event_id = NEW.claimed_event_id AND e.event_type = 'claimed' AND e.admin_account_id = NEW.admin_account_id AND e.contributor_account_id = NEW.contributor_account_id) BEGIN SELECT RAISE(ABORT, 'confirmation admin/contributor must match its claimed event'); END`;
|
|
151
|
+
const TRIGGER_AOUR_NO_UPDATE = `CREATE TRIGGER IF NOT EXISTS trg_aour_no_update BEFORE UPDATE ON admin_operator_unlink_requests BEGIN SELECT RAISE(ABORT, 'admin_operator_unlink_requests is append-only (UPDATE forbidden)'); END`;
|
|
152
|
+
const TRIGGER_AOUR_NO_DELETE = `CREATE TRIGGER IF NOT EXISTS trg_aour_no_delete BEFORE DELETE ON admin_operator_unlink_requests BEGIN SELECT RAISE(ABORT, 'admin_operator_unlink_requests is append-only (DELETE forbidden)'); END`;
|
|
153
|
+
const TRIGGER_AOCMC_NO_UPDATE = `CREATE TRIGGER IF NOT EXISTS trg_aocmc_no_update BEFORE UPDATE ON admin_operator_claim_marking_corrections BEGIN SELECT RAISE(ABORT, 'admin_operator_claim_marking_corrections is append-only (UPDATE forbidden)'); END`;
|
|
154
|
+
const TRIGGER_AOCMC_NO_DELETE = `CREATE TRIGGER IF NOT EXISTS trg_aocmc_no_delete BEFORE DELETE ON admin_operator_claim_marking_corrections BEGIN SELECT RAISE(ABORT, 'admin_operator_claim_marking_corrections is append-only (DELETE forbidden)'); END`;
|
|
155
|
+
function tableExists(db, name) {
|
|
156
|
+
return db.prepare(`SELECT 1 FROM sqlite_master WHERE type='table' AND name=?`).get(name) !== undefined;
|
|
157
|
+
}
|
|
158
|
+
export function initAdminCoordinationSchema(db) {
|
|
159
|
+
const apply = db.transaction(() => {
|
|
160
|
+
db.exec(CREATE_OPERATOR_CLAIM_EVENTS);
|
|
161
|
+
db.exec(CREATE_MANDATE_EVENTS);
|
|
162
|
+
db.exec(CREATE_CLAIM_CONFIRMATIONS);
|
|
163
|
+
db.exec(CREATE_FACT_SOURCES);
|
|
164
|
+
db.exec(CREATE_UNLINK_REQUESTS);
|
|
165
|
+
db.exec(CREATE_MARKING_CORRECTIONS);
|
|
166
|
+
// Additive: backfill marking columns onto an unlink table created by an earlier deploy.
|
|
167
|
+
const aourCols = new Set(db.prepare(`PRAGMA table_info(admin_operator_unlink_requests)`).all().map((c) => c.name));
|
|
168
|
+
if (!aourCols.has('approval_kind') || !aourCols.has('conflict_disclosure')) {
|
|
169
|
+
for (const stmt of ALTER_UNLINK_MARKING) {
|
|
170
|
+
const col = stmt.includes('approval_kind') ? 'approval_kind' : 'conflict_disclosure';
|
|
171
|
+
if (!aourCols.has(col))
|
|
172
|
+
db.exec(stmt);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const idx of CREATE_INDEXES)
|
|
176
|
+
db.exec(idx);
|
|
177
|
+
db.exec(TRIGGER_AOCE_NO_UPDATE);
|
|
178
|
+
db.exec(TRIGGER_AOCE_NO_DELETE);
|
|
179
|
+
db.exec(TRIGGER_AEME_NO_UPDATE);
|
|
180
|
+
db.exec(TRIGGER_AEME_NO_DELETE);
|
|
181
|
+
db.exec(TRIGGER_ACFS_NO_UPDATE);
|
|
182
|
+
db.exec(TRIGGER_ACFS_NO_DELETE);
|
|
183
|
+
db.exec(TRIGGER_AAL_FREEZE_UPDATE);
|
|
184
|
+
db.exec(TRIGGER_AAL_FREEZE_DELETE);
|
|
185
|
+
db.exec(TRIGGER_AOCC_NO_UPDATE);
|
|
186
|
+
db.exec(TRIGGER_AOCC_NO_DELETE);
|
|
187
|
+
db.exec(TRIGGER_AOCC_MATCH);
|
|
188
|
+
db.exec(TRIGGER_AOUR_NO_UPDATE);
|
|
189
|
+
db.exec(TRIGGER_AOUR_NO_DELETE);
|
|
190
|
+
db.exec(TRIGGER_AOCMC_NO_UPDATE);
|
|
191
|
+
db.exec(TRIGGER_AOCMC_NO_DELETE);
|
|
192
|
+
});
|
|
193
|
+
apply.immediate();
|
|
194
|
+
void tableExists;
|
|
195
|
+
void COORD_TABLES;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* ALLOWLIST-ONLY action catalog. Only actions listed here may be ingested as a coordination
|
|
199
|
+
* contribution candidate. Each maps to the RFC-017 `contribution_facts` (source, type). ANY action not
|
|
200
|
+
* present here fails closed (audit only, no fact). Login / viewing / permission-config / `root creates
|
|
201
|
+
* admin` / routine risk-control are deliberately absent.
|
|
202
|
+
*/
|
|
203
|
+
export const ADMIN_COORDINATION_ACTIONS = {
|
|
204
|
+
// ── REAL production audit actions (the FIRST live pipeline). These are the exact `action` strings that
|
|
205
|
+
// logAdminAction writes from the operator-claim workflow routes (admin-operator-claims.ts) — the only
|
|
206
|
+
// coordination/governance admin actions currently audited with a stable, explicit action name. All map
|
|
207
|
+
// to (governance, governance): operating the contribution-attribution machinery IS governance work.
|
|
208
|
+
// (factType ∈ RFC-017 taxonomy: code|tests|audit|maintenance|governance|usage|transaction|referral.) ──
|
|
209
|
+
'operator_claim.propose': { factSource: 'governance', factType: 'governance' },
|
|
210
|
+
'operator_claim.confirm': { factSource: 'governance', factType: 'governance' },
|
|
211
|
+
'operator_claim.approve': { factSource: 'governance', factType: 'governance' },
|
|
212
|
+
'operator_claim.reject': { factSource: 'governance', factType: 'governance' },
|
|
213
|
+
'operator_claim.revoke': { factSource: 'governance', factType: 'governance' },
|
|
214
|
+
'operator_claim.unlink_request': { factSource: 'governance', factType: 'governance' },
|
|
215
|
+
'operator_claim.unlink_approve': { factSource: 'governance', factType: 'governance' },
|
|
216
|
+
'operator_claim.unlink_reject': { factSource: 'governance', factType: 'governance' },
|
|
217
|
+
// ── Reserved CONCEPT names (no route emits these yet → no production effect). Kept as the representative
|
|
218
|
+
// catalog for build-task-quota / task-proposal / dispute / release work, to be mapped to their real
|
|
219
|
+
// audited action strings (and added above) ONLY once those routes log a stable, explicit action name.
|
|
220
|
+
// Until then they stay fail-closed in practice (nothing produces them). ──
|
|
221
|
+
proposal_review: { factSource: 'governance', factType: 'governance' },
|
|
222
|
+
task_review: { factSource: 'in_protocol', factType: 'audit' },
|
|
223
|
+
dispute_coordination: { factSource: 'governance', factType: 'governance' },
|
|
224
|
+
release_coordination: { factSource: 'in_protocol', factType: 'maintenance' },
|
|
225
|
+
maintenance_action: { factSource: 'in_protocol', factType: 'maintenance' },
|
|
226
|
+
governance_review: { factSource: 'governance', factType: 'governance' },
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* The LIVE production set — the only actions the bounded batch / operator CLI selects from. These are
|
|
230
|
+
* the real `operator_claim.*` audit action strings emitted by routes today. The reserved CONCEPT names
|
|
231
|
+
* in ADMIN_COORDINATION_ACTIONS stay ingestible by the SINGLE-row engine (an operator can target a
|
|
232
|
+
* specific auditId), but they are deliberately EXCLUDED from batch live selection so the first pipeline
|
|
233
|
+
* only ever scans/auto-ingests real operator-claim work. Add a concept name here only when a real route
|
|
234
|
+
* begins emitting it as a stable action string.
|
|
235
|
+
*/
|
|
236
|
+
export const LIVE_ADMIN_COORDINATION_AUDIT_ACTIONS = [
|
|
237
|
+
'operator_claim.propose', 'operator_claim.confirm', 'operator_claim.approve', 'operator_claim.reject',
|
|
238
|
+
'operator_claim.revoke', 'operator_claim.unlink_request', 'operator_claim.unlink_approve', 'operator_claim.unlink_reject',
|
|
239
|
+
];
|
|
240
|
+
// invariant: every live action MUST have a spec in the allowlist (else the batch would select a row the
|
|
241
|
+
// single-row engine then refuses as unknown_action). Fail LOUD at module load if they ever drift apart.
|
|
242
|
+
for (const a of LIVE_ADMIN_COORDINATION_AUDIT_ACTIONS) {
|
|
243
|
+
if (!Object.prototype.hasOwnProperty.call(ADMIN_COORDINATION_ACTIONS, a)) {
|
|
244
|
+
throw new Error(`LIVE_ADMIN_COORDINATION_AUDIT_ACTIONS contains '${a}' with no ADMIN_COORDINATION_ACTIONS spec`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
export function coordinationActionSpec(action) {
|
|
248
|
+
return Object.prototype.hasOwnProperty.call(ADMIN_COORDINATION_ACTIONS, action)
|
|
249
|
+
? ADMIN_COORDINATION_ACTIONS[action]
|
|
250
|
+
: null;
|
|
251
|
+
}
|