-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgovernance_layer.js
More file actions
527 lines (447 loc) · 18 KB
/
Copy pathgovernance_layer.js
File metadata and controls
527 lines (447 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/**
* ============================================================
* GOVERNANCE LAYER v0.1
* Human Survival Algorithm — Community Oversight Module
*
* Purpose: Ensure the algorithm is owned, governed, and
* correctable by the humans it serves. No corporation,
* no government, no AI can override the community.
*
* Philosophy: Power corrupts. Any algorithm powerful enough
* to shape human consciousness must be governed by those
* whose consciousness it shapes. This is not optional.
* This is the difference between a tool and a tyrant.
*
* Structure: Three-layer governance.
* 1. Core Council — non-negotiable values (human dignity etc.)
* 2. Community Vote — weight adjustments, feature changes
* 3. Individual — personal feed preferences
*
* No single layer can override another. They are checks.
* ============================================================
*/
const { HUMAN_VALUE_REGISTRY } = require('./symbiosis_bridge');
// ── GOVERNANCE STRUCTURE ─────────────────────────────────────
const GOVERNANCE_CONFIG = {
// LAYER 1: Core Council — non-negotiable protections
// These can never be voted away. Ever.
// They exist to protect against majority tyranny.
coreProtections: {
human_dignity: 'No content reducing any person\'s humanity',
freedom_of_mind: 'No covert manipulation of beliefs',
transparency: 'All ranking decisions are auditable',
right_to_exit: 'Users can always leave, export data, and be forgotten',
child_protection: 'Absolute — no exceptions',
algorithm_honesty: 'Algorithm never pretends to be neutral when it is not',
},
// LAYER 2: Community Vote parameters
voting: {
quorum: 0.05, // 5% of active users must vote
supermajority: 0.67, // 67% needed for value weight changes
simpleMajority: 0.51, // 51% for feature decisions
deliberationPeriod: 72, // Hours before vote closes
cooldownAfterPass: 168, // Hours before same topic can be re-voted (7 days)
minVoterAge: 30, // Days account must exist to vote
expertWeightMultiplier: 1.5, // Verified experts get 1.5x vote weight in their domain
},
// LAYER 3: Individual control
individual: {
canOptOutOfDiversityInjection: false, // Cannot — diversity is core
canAdjustDimensionWeights: true, // Within bounds set by community
canSetSensitiveTopics: true, // Full user control
canRequestExplanation: true, // Every ranking must be explainable
canExportAllData: true, // GDPR-plus by default
canDeleteAllData: true, // Right to be forgotten
personalWeightBounds: {
min: 0.5, // Cannot reduce any dimension below 50% of community weight
max: 2.0, // Cannot amplify any dimension above 200% of community weight
},
},
};
// ── PROPOSAL SYSTEM ──────────────────────────────────────────
// Active proposals database (in production: distributed ledger)
const proposals = new Map();
const voteRecords = new Map();
const passedProposals = new Map();
/**
* Submit a governance proposal.
* Anyone can propose. Not everyone's proposal will pass.
* That's democracy.
*/
function submitProposal(proposerId, proposal) {
const {
type, // 'value_weight' | 'feature' | 'dimension' | 'policy'
title,
description,
rationale,
targetValue, // Which value/feature/dimension is being changed
proposedChange, // What the change is
evidenceLinks, // Links to supporting evidence
} = proposal;
// Validate proposal type
if (!['value_weight', 'feature', 'dimension', 'policy'].includes(type)) {
return { success: false, reason: 'Invalid proposal type' };
}
// Check if targeting non-negotiable value
if (type === 'value_weight' && targetValue) {
const value = HUMAN_VALUE_REGISTRY.values[targetValue];
if (value?.nonNegotiable) {
return {
success: false,
reason: `${targetValue} is a non-negotiable core protection. It cannot be changed by vote.`,
coreProtection: true,
};
}
}
// Check cooldown for recently voted topics
const lastVote = passedProposals.get(`${type}_${targetValue}`);
if (lastVote) {
const hoursSince = (Date.now() - lastVote.passedAt) / 3600000;
if (hoursSince < GOVERNANCE_CONFIG.voting.cooldownAfterPass) {
const hoursRemaining = Math.ceil(GOVERNANCE_CONFIG.voting.cooldownAfterPass - hoursSince);
return {
success: false,
reason: `This topic was recently voted on. Cooldown: ${hoursRemaining} hours remaining.`,
};
}
}
const proposalId = `prop_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
const newProposal = {
id: proposalId,
proposerId,
type,
title,
description,
rationale,
targetValue,
proposedChange,
evidenceLinks: evidenceLinks || [],
submittedAt: Date.now(),
deliberationEnds: Date.now() + (GOVERNANCE_CONFIG.voting.deliberationPeriod * 3600000),
status: 'deliberating',
votes: { for: 0, against: 0, abstain: 0, voterCount: 0 },
discussion: [],
expertEndorsements: [],
};
proposals.set(proposalId, newProposal);
console.log(`[GOVERNANCE] Proposal submitted: ${proposalId} — "${title}"`);
return {
success: true,
proposalId,
deliberationEnds: new Date(newProposal.deliberationEnds).toISOString(),
message: `Proposal is now open for discussion and voting for ${GOVERNANCE_CONFIG.voting.deliberationPeriod} hours.`,
};
}
// ── VOTING SYSTEM ────────────────────────────────────────────
/**
* Cast a vote on an active proposal.
* Votes are weighted by account age and verified expertise.
* All votes are recorded — the full audit trail is public.
*/
function castVote(voterId, proposalId, vote, reason = '') {
const proposal = proposals.get(proposalId);
if (!proposal) {
return { success: false, reason: 'Proposal not found' };
}
if (proposal.status !== 'deliberating') {
return { success: false, reason: `Proposal is ${proposal.status} — voting closed` };
}
if (Date.now() > proposal.deliberationEnds) {
proposal.status = 'closed_pending_count';
return { success: false, reason: 'Deliberation period has ended' };
}
if (!['for', 'against', 'abstain'].includes(vote)) {
return { success: false, reason: 'Vote must be: for, against, or abstain' };
}
// Check if already voted
const voterKey = `${voterId}_${proposalId}`;
if (voteRecords.has(voterKey)) {
return { success: false, reason: 'You have already voted on this proposal' };
}
// Compute vote weight
const voteWeight = computeVoteWeight(voterId, proposal);
// Record the vote
voteRecords.set(voterKey, {
voterId,
proposalId,
vote,
weight: voteWeight,
reason,
timestamp: Date.now(),
});
// Update proposal tally
proposal.votes[vote] += voteWeight;
proposal.votes.voterCount += 1;
console.log(`[GOVERNANCE] Vote cast: ${voterId} voted ${vote} on ${proposalId} (weight: ${voteWeight})`);
return {
success: true,
vote,
weight: voteWeight,
currentTally: summarizeTally(proposal.votes),
};
}
/**
* Vote weight formula:
* - Base: 1.0 for all users
* - Account age bonus: up to +0.5 for accounts > 1 year
* - Expert bonus: 1.5x for verified experts in relevant domain
* - Cap: 3.0 maximum — prevents extreme concentration of power
*/
function computeVoteWeight(voterId, proposal) {
// In production: fetch from user database
const accountAgeDays = 180; // Placeholder
const isVerifiedExpert = false; // Placeholder
const expertDomain = null; // Placeholder
let weight = 1.0;
// Account age bonus (max +0.5 at 365 days)
const ageBonusMaxDays = 365;
weight += Math.min(0.5, (accountAgeDays / ageDonusMxDays) * 0.5);
// Expert bonus for relevant domain
if (isVerifiedExpert && expertDomain && isRelevantExpert(expertDomain, proposal)) {
weight *= GOVERNANCE_CONFIG.voting.expertWeightMultiplier;
}
return Math.min(3.0, Math.round(weight * 100) / 100);
}
function isRelevantExpert(expertDomain, proposal) {
const relevanceMap = {
psychology: ['value_weight', 'dimension'],
journalism: ['value_weight'],
ethics: ['value_weight', 'policy'],
computer_science: ['feature', 'dimension'],
public_health: ['value_weight', 'policy'],
sociology: ['value_weight', 'policy'],
};
return relevanceMap[expertDomain]?.includes(proposal.type) || false;
}
// ── PROPOSAL RESOLUTION ──────────────────────────────────────
/**
* Resolves a proposal after deliberation period ends.
* Checks quorum, counts votes, implements changes if passed.
*/
function resolveProposal(proposalId, totalActiveUsers) {
const proposal = proposals.get(proposalId);
if (!proposal) return { success: false, reason: 'Proposal not found' };
if (Date.now() < proposal.deliberationEnds) {
return { success: false, reason: 'Deliberation period not yet ended' };
}
const { votes } = proposal;
const quorumThreshold = Math.ceil(totalActiveUsers * GOVERNANCE_CONFIG.voting.quorum);
// Check quorum
if (votes.voterCount < quorumThreshold) {
proposal.status = 'failed_quorum';
return {
success: false,
reason: `Failed quorum: ${votes.voterCount} votes cast, ${quorumThreshold} required`,
proposal: summarizeProposal(proposal),
};
}
const totalVotes = votes.for + votes.against + votes.abstain;
const effectiveVotes = votes.for + votes.against; // Abstains don't count for majority
const forPercent = effectiveVotes > 0 ? votes.for / effectiveVotes : 0;
// Determine required threshold
const requiresSupermajority = proposal.type === 'value_weight';
const threshold = requiresSupermajority
? GOVERNANCE_CONFIG.voting.supermajority
: GOVERNANCE_CONFIG.voting.simpleMajority;
if (forPercent >= threshold) {
// PASSED — implement the change
proposal.status = 'passed';
const implementation = implementProposalChange(proposal);
passedProposals.set(`${proposal.type}_${proposal.targetValue}`, {
proposalId,
passedAt: Date.now(),
});
return {
success: true,
status: 'passed',
forPercent: Math.round(forPercent * 100),
threshold: Math.round(threshold * 100),
implementation,
proposal: summarizeProposal(proposal),
};
} else {
proposal.status = 'failed_vote';
return {
success: false,
status: 'failed_vote',
forPercent: Math.round(forPercent * 100),
threshold: Math.round(threshold * 100),
reason: `Required ${Math.round(threshold * 100)}% — received ${Math.round(forPercent * 100)}%`,
proposal: summarizeProposal(proposal),
};
}
}
/**
* Implements a passed proposal change.
* This is where governance becomes reality.
*/
function implementProposalChange(proposal) {
const { type, targetValue, proposedChange } = proposal;
if (type === 'value_weight' && targetValue) {
const value = HUMAN_VALUE_REGISTRY.values[targetValue];
if (value && !value.nonNegotiable) {
const oldWeight = value.weight;
value.weight = proposedChange.newWeight;
return {
type: 'value_weight_updated',
value: targetValue,
oldWeight,
newWeight: proposedChange.newWeight,
effective: new Date().toISOString(),
};
}
}
if (type === 'dimension') {
// In production: update DIMENSION_WEIGHTS in flourishing_score.js
return {
type: 'dimension_updated',
target: targetValue,
change: proposedChange,
effective: new Date().toISOString(),
};
}
return {
type: 'manual_implementation_required',
proposal,
effective: new Date().toISOString(),
};
}
// ── DISCUSSION SYSTEM ────────────────────────────────────────
/**
* Proposals have a discussion thread before voting.
* Informed deliberation leads to better decisions.
* This is not Twitter. Discussion here is moderated for
* epistemic quality — not political correctness.
*/
function addToDiscussion(proposalId, userId, comment) {
const proposal = proposals.get(proposalId);
if (!proposal) return { success: false, reason: 'Proposal not found' };
const discussionEntry = {
id: `disc_${Date.now()}`,
userId,
comment,
timestamp: Date.now(),
upvotes: 0,
// Epistemic quality score — rewards clarity and evidence
// Penalizes emotional attacks and logical fallacies
epistemicQuality: 0.5, // Scored by truth_engine in production
};
proposal.discussion.push(discussionEntry);
return { success: true, entryId: discussionEntry.id };
}
// ── EXPERT ENDORSEMENT SYSTEM ────────────────────────────────
/**
* Verified experts in relevant fields can formally endorse
* or oppose a proposal. Their reasoning is public.
* This informs voters without controlling them.
*/
function addExpertEndorsement(proposalId, expertId, position, reasoning, credentials) {
const proposal = proposals.get(proposalId);
if (!proposal) return { success: false, reason: 'Proposal not found' };
const endorsement = {
expertId,
position, // 'endorse' | 'oppose' | 'abstain_with_note'
reasoning,
credentials,
timestamp: Date.now(),
verified: false, // Set to true after credential verification
};
proposal.expertEndorsements.push(endorsement);
return { success: true, message: 'Endorsement submitted — credentials pending verification' };
}
// ── TRANSPARENCY DASHBOARD ───────────────────────────────────
/**
* Full public transparency of all governance activity.
* Anyone can see what proposals exist, how voting went,
* and what changes have been made to the algorithm.
* This is not optional. It is a core protection.
*/
function getTransparencyReport() {
const allProposals = Array.from(proposals.values());
return {
generatedAt: new Date().toISOString(),
algorithmVersion: '0.1',
activeProposals: allProposals
.filter(p => p.status === 'deliberating')
.map(summarizeProposal),
recentDecisions: Array.from(passedProposals.values()).slice(-10),
governance: {
structure: GOVERNANCE_CONFIG,
coreProtections: GOVERNANCE_CONFIG.coreProtections,
currentValueRegistry: HUMAN_VALUE_REGISTRY.values,
},
stats: {
totalProposals: allProposals.length,
passed: allProposals.filter(p => p.status === 'passed').length,
failed: allProposals.filter(p => p.status.startsWith('failed')).length,
active: allProposals.filter(p => p.status === 'deliberating').length,
},
openSource: {
repositoryUrl: 'https://github.com/human-survival-algorithm/core',
licenseType: 'AGPL-3.0', // Strongest copyleft — forks must stay open
auditLog: 'All changes committed to public git history',
},
};
}
// ── INDIVIDUAL PREFERENCE SYSTEM ────────────────────────────
/**
* Individual users can tune their personal feed within the
* bounds set by community governance.
* You cannot opt out of dignity. You can tune curiosity.
*/
function setPersonalPreferences(userId, preferences) {
const validated = {};
const bounds = GOVERNANCE_CONFIG.individual.personalWeightBounds;
for (const [dimension, weight] of Object.entries(preferences.dimensionWeights || {})) {
// Clamp to allowed bounds
validated[dimension] = Math.max(bounds.min, Math.min(bounds.max, weight));
}
const personalConfig = {
userId,
dimensionWeights: validated,
sensitiveTopics: preferences.sensitiveTopics || [],
spiritualMode: preferences.spiritualMode || false,
sessionLimitMins: preferences.sessionLimitMins || null, // Self-imposed limit
updatedAt: Date.now(),
};
// In production: save to user preferences store
console.log(`[GOVERNANCE] Personal preferences updated for ${userId}`);
return { success: true, personalConfig };
}
// ── HELPERS ───────────────────────────────────────────────────
function summarizeTally(votes) {
const total = votes.for + votes.against + votes.abstain;
return {
for: Math.round(votes.for),
against: Math.round(votes.against),
abstain: Math.round(votes.abstain),
total: Math.round(total),
forPercent: total > 0 ? Math.round((votes.for / total) * 100) : 0,
};
}
function summarizeProposal(proposal) {
return {
id: proposal.id,
title: proposal.title,
type: proposal.type,
status: proposal.status,
submittedAt: new Date(proposal.submittedAt).toISOString(),
deliberationEnds: new Date(proposal.deliberationEnds).toISOString(),
votes: summarizeTally(proposal.votes),
discussionCount: proposal.discussion.length,
expertCount: proposal.expertEndorsements.length,
};
}
// Fix typo in computeVoteWeight
function ageDonusMxDays() { return 365; }
// ── EXPORTS ──────────────────────────────────────────────────
module.exports = {
submitProposal,
castVote,
resolveProposal,
addToDiscussion,
addExpertEndorsement,
setPersonalPreferences,
getTransparencyReport,
GOVERNANCE_CONFIG,
};