@cordfuse/politik 0.4.0 → 0.6.0
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/EXECUTION.md +90 -85
- package/POLITIK-ARCHITECTURE.md +111 -176
- package/PROTOCOLS.md +120 -289
- package/README.md +130 -177
- package/RESEARCH.md +142 -436
- package/RUNTIME.md +253 -261
- package/docs/adr/0001-chamber-transport.md +2 -0
- package/docs/adr/0002-charter-schema.md +2 -0
- package/docs/adr/0003-state-json-schema.md +2 -0
- package/docs/adr/0004-motion-enactment.md +2 -0
- package/docs/adr/0005-hansard-format.md +2 -0
- package/docs/adr/0006-protocol-behavioral-enforcement.md +2 -0
- package/docs/adr/0007-protocol-mechanics.md +2 -0
- package/docs/adr/0008-session-storage.md +2 -0
- package/docs/adr/0009-match-primitive.md +2 -0
- package/docs/adr/0010-operator-interface.md +2 -0
- package/docs/adr/0011-shared-sessions.md +2 -0
- package/docs/adr/0012-plain-vocabulary.md +68 -0
- package/docs/adr/0013-rule-defined-protocols.md +89 -0
- package/package.json +1 -1
- package/protocols/CONTRIBUTING.md +47 -87
- package/protocols/adversarial-review.yml +19 -0
- package/protocols/elimination-rounds.yml +18 -0
- package/protocols/majority-vote.yml +18 -0
- package/protocols/panel-review.yml +19 -0
- package/protocols/single-decider.yml +18 -0
- package/protocols/unanimous-vote.yml +17 -0
- package/src/actors.ts +124 -100
- package/src/agents.ts +64 -23
- package/src/ballot.ts +747 -0
- package/src/canon.ts +23 -10
- package/src/capability.ts +16 -99
- package/src/charter.ts +41 -34
- package/src/cli.ts +541 -480
- package/src/{prorogation.ts → closing.ts} +43 -43
- package/src/conflict.ts +14 -14
- package/src/containment.ts +11 -11
- package/src/doctor.ts +1 -1
- package/src/election.ts +4 -4
- package/src/envelope.ts +3 -3
- package/src/escalation.ts +44 -44
- package/src/fault.ts +8 -8
- package/src/federation.ts +14 -14
- package/src/git.ts +21 -18
- package/src/heartbeat.ts +32 -32
- package/src/index.ts +5 -5
- package/src/init.ts +66 -65
- package/src/integrity.ts +30 -30
- package/src/ledger.ts +3 -3
- package/src/{hansard.ts → log.ts} +20 -20
- package/src/{crisis.ts → misconduct.ts} +70 -70
- package/src/operator.ts +5 -5
- package/src/pending.ts +9 -9
- package/src/projection.ts +30 -30
- package/src/protocol-sdk.ts +12 -121
- package/src/protocol.ts +8 -78
- package/src/providers/github.ts +12 -12
- package/src/quorum.ts +7 -7
- package/src/remote.ts +1 -1
- package/src/runner.ts +134 -55
- package/src/scm.ts +14 -14
- package/src/spawn.ts +4 -4
- package/src/standings.ts +13 -13
- package/src/state.ts +6 -6
- package/src/templates/session.ts +448 -0
- package/src/tournament.ts +20 -20
- package/src/transport.ts +4 -4
- package/src/tree.ts +16 -16
- package/protocols/adversarial-collaboration.yml +0 -28
- package/protocols/corporate.yml +0 -35
- package/protocols/elimination-tournament.yml +0 -41
- package/protocols/emergency-response-ics.yml +0 -27
- package/protocols/jury-deliberation.yml +0 -32
- package/protocols/monarchy.yml +0 -31
- package/protocols/parliamentary.yml +0 -66
- package/protocols/peer-review.yml +0 -44
- package/protocols/republic.yml +0 -36
- package/protocols/socialism-collective.yml +0 -31
- package/protocols/solo.yml +0 -32
- package/src/division.ts +0 -609
- package/src/templates/parliamentary.ts +0 -580
package/src/division.ts
DELETED
|
@@ -1,609 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Division and Assent — deciding a Motion, then enacting it.
|
|
3
|
-
*
|
|
4
|
-
* ADR-0004 draws the line this module implements: **the Division decides, the
|
|
5
|
-
* Assent enacts.** They are separate verbs held by different roles. A Motion
|
|
6
|
-
* can carry and still not take effect, because carrying is an outcome and
|
|
7
|
-
* enacting is an act.
|
|
8
|
-
*
|
|
9
|
-
* Pure, like the rest of the governance layer: these functions produce Hansard
|
|
10
|
-
* entries and next-states. The caller commits them.
|
|
11
|
-
*
|
|
12
|
-
* Attribution: Steve Krisjanovs, Cordfuse
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { isRole, type Role } from './canon.ts';
|
|
16
|
-
import { appendEntry, parseEntries, type HansardEntry } from './hansard.ts';
|
|
17
|
-
import { checkQuorum, type QuorumOverride } from './quorum.ts';
|
|
18
|
-
import { createState, type SessionStateFile } from './state.ts';
|
|
19
|
-
import { darwinistExit, seatOf } from './actors.ts';
|
|
20
|
-
|
|
21
|
-
/* -------------------------------------------------------------------------- */
|
|
22
|
-
/* Votes */
|
|
23
|
-
/* -------------------------------------------------------------------------- */
|
|
24
|
-
|
|
25
|
-
export const VOTES = ['AYE', 'NO', 'ABSTAIN'] as const;
|
|
26
|
-
|
|
27
|
-
export type Vote = (typeof VOTES)[number];
|
|
28
|
-
|
|
29
|
-
export const isVote = (v: unknown): v is Vote =>
|
|
30
|
-
typeof v === 'string' && (VOTES as readonly string[]).includes(v);
|
|
31
|
-
|
|
32
|
-
export interface CastVote {
|
|
33
|
-
readonly actor: string;
|
|
34
|
-
readonly role: Role;
|
|
35
|
-
readonly vote: Vote;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class DivisionError extends Error {
|
|
39
|
-
constructor(message: string) {
|
|
40
|
-
super(message);
|
|
41
|
-
this.name = 'DivisionError';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/* -------------------------------------------------------------------------- */
|
|
46
|
-
/* Calling a Division */
|
|
47
|
-
/* -------------------------------------------------------------------------- */
|
|
48
|
-
|
|
49
|
-
export interface CallDivisionInput {
|
|
50
|
-
readonly motion: string;
|
|
51
|
-
readonly at: string;
|
|
52
|
-
readonly actor: string;
|
|
53
|
-
readonly role: Role;
|
|
54
|
-
readonly reviewers: readonly string[];
|
|
55
|
-
readonly state: SessionStateFile;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Open a Division on a tabled Motion. */
|
|
59
|
-
export const callDivision = (input: CallDivisionInput, hansard: string): {
|
|
60
|
-
readonly entry: HansardEntry;
|
|
61
|
-
readonly hansard: string;
|
|
62
|
-
} => {
|
|
63
|
-
if (!isRole(input.role)) {
|
|
64
|
-
throw new DivisionError(`not a CANON role: ${String(input.role)}`);
|
|
65
|
-
}
|
|
66
|
-
if (input.state.state !== 'CONVENED') {
|
|
67
|
-
throw new DivisionError(
|
|
68
|
-
`cannot call a Division while the session is ${input.state.state}`,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
// One Division per Motion. Re-calling would open a second vote on a Motion
|
|
72
|
-
// that may already be decided, letting a settled outcome be overturned. A
|
|
73
|
-
// genuinely new question is a new Motion.
|
|
74
|
-
if (divisionCalled(hansard, input.motion)) {
|
|
75
|
-
throw new DivisionError(`a Division has already been called on ${input.motion}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const entry: HansardEntry = {
|
|
79
|
-
type: 'DIVISION_CALLED',
|
|
80
|
-
at: input.at,
|
|
81
|
-
actor: input.actor,
|
|
82
|
-
role: input.role,
|
|
83
|
-
fields: {
|
|
84
|
-
Motion: input.motion,
|
|
85
|
-
Reviewers: input.reviewers.join(', '),
|
|
86
|
-
},
|
|
87
|
-
body: `A Division is called on ${input.motion}.`,
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return { entry, hansard: appendEntry(hansard, entry) };
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/* -------------------------------------------------------------------------- */
|
|
94
|
-
/* Casting a vote */
|
|
95
|
-
/* -------------------------------------------------------------------------- */
|
|
96
|
-
|
|
97
|
-
export interface CastVoteInput {
|
|
98
|
-
readonly motion: string;
|
|
99
|
-
readonly at: string;
|
|
100
|
-
readonly actor: string;
|
|
101
|
-
readonly role: Role;
|
|
102
|
-
readonly vote: Vote;
|
|
103
|
-
readonly state: SessionStateFile;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Record a vote.
|
|
108
|
-
*
|
|
109
|
-
* OBSERVER is refused: the role is defined as read-only with no floor rights. A
|
|
110
|
-
* protocol that wants an observer-class actor to decide something declares a
|
|
111
|
-
* DOMAIN_VETO instead — that is exactly the power inversion CANON models, and
|
|
112
|
-
* it is declared in the Charter rather than smuggled in through a vote.
|
|
113
|
-
*/
|
|
114
|
-
export const castVote = (input: CastVoteInput, hansard: string): {
|
|
115
|
-
readonly entry: HansardEntry;
|
|
116
|
-
readonly hansard: string;
|
|
117
|
-
} => {
|
|
118
|
-
if (!isRole(input.role)) {
|
|
119
|
-
throw new DivisionError(`not a CANON role: ${String(input.role)}`);
|
|
120
|
-
}
|
|
121
|
-
if (input.state.state !== 'CONVENED') {
|
|
122
|
-
throw new DivisionError(`cannot vote while the session is ${input.state.state}`);
|
|
123
|
-
}
|
|
124
|
-
if (input.role === 'OBSERVER') {
|
|
125
|
-
throw new DivisionError('OBSERVER holds no floor rights and may not vote');
|
|
126
|
-
}
|
|
127
|
-
if (!isVote(input.vote)) {
|
|
128
|
-
throw new DivisionError(`not a valid vote: ${String(input.vote)}`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// A vote only exists inside a Division. Without this a vote could be cast on a
|
|
132
|
-
// Motion no Division was ever called on, and enough such phantom votes would
|
|
133
|
-
// let a tally "carry" a Motion that never reached the floor.
|
|
134
|
-
if (!divisionCalled(hansard, input.motion)) {
|
|
135
|
-
throw new DivisionError(`no Division has been called on ${input.motion}`);
|
|
136
|
-
}
|
|
137
|
-
// A decided Division is closed. Without this a late vote could be cast after
|
|
138
|
-
// the outcome was recorded and a re-tally would overturn a settled decision —
|
|
139
|
-
// the record is append-only, but the decision it carries must be final.
|
|
140
|
-
if (divisionDecided(hansard, input.motion)) {
|
|
141
|
-
throw new DivisionError(`the Division on ${input.motion} has closed — its outcome is on the record`);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// One vote per actor per Motion. A second vote is not an amendment — it is an
|
|
145
|
-
// attempt to rewrite a record that is append-only by construction.
|
|
146
|
-
const already = votesFor(hansard, input.motion).find((v) => v.actor === input.actor);
|
|
147
|
-
if (already !== undefined) {
|
|
148
|
-
throw new DivisionError(
|
|
149
|
-
`${input.actor} has already voted ${already.vote} on ${input.motion}`,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const entry: HansardEntry = {
|
|
154
|
-
type: 'VOTE_CAST',
|
|
155
|
-
at: input.at,
|
|
156
|
-
actor: input.actor,
|
|
157
|
-
role: input.role,
|
|
158
|
-
fields: { Motion: input.motion, Vote: input.vote },
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
return { entry, hansard: appendEntry(hansard, entry) };
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/** Whether a Division was ever called on this Motion. */
|
|
165
|
-
export const divisionCalled = (hansard: string, motion: string): boolean =>
|
|
166
|
-
parseEntries(hansard).some(
|
|
167
|
-
(e) => e.type === 'DIVISION_CALLED' && e.fields['Motion'] === motion,
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
/** Whether a Division on this Motion has been decided — its outcome recorded.
|
|
171
|
-
* A DEADLOCK records MOTION_REJECTED, so it too closes the Division. */
|
|
172
|
-
export const divisionDecided = (hansard: string, motion: string): boolean =>
|
|
173
|
-
parseEntries(hansard).some(
|
|
174
|
-
(e) =>
|
|
175
|
-
(e.type === 'MOTION_CARRIED' || e.type === 'MOTION_REJECTED') &&
|
|
176
|
-
e.fields['Motion'] === motion,
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* How an actor leaves — the second protocol override point (ADR-0007).
|
|
181
|
-
* `division` (default) removes an actor only through the normal exit/expel path;
|
|
182
|
-
* `elimination` culls the losing side of a Division; `none` keeps everyone until
|
|
183
|
-
* the session terminates (a Jury cannot lose a member mid-deliberation).
|
|
184
|
-
*/
|
|
185
|
-
export type ExitPolicy = 'division' | 'elimination' | 'none';
|
|
186
|
-
|
|
187
|
-
export const EXIT_POLICIES: readonly ExitPolicy[] = Object.freeze([
|
|
188
|
-
'division',
|
|
189
|
-
'elimination',
|
|
190
|
-
'none',
|
|
191
|
-
]);
|
|
192
|
-
|
|
193
|
-
export const isExitPolicy = (v: unknown): v is ExitPolicy =>
|
|
194
|
-
typeof v === 'string' && (EXIT_POLICIES as readonly string[]).includes(v);
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* The elimination cull: under `exit: elimination`, the actors on the losing side
|
|
198
|
-
* of a decided Division are removed (EXIT_DARWINIST). The minority is culled; a
|
|
199
|
-
* tie culls no one; abstainers took no side and survive. Only seated actors are
|
|
200
|
-
* culled, so AUTHORITY — which holds no seat in the register — is never touched.
|
|
201
|
-
* Returns the exit entries to append; empty under any other policy.
|
|
202
|
-
*/
|
|
203
|
-
export const cull = (
|
|
204
|
-
hansard: string,
|
|
205
|
-
motion: string,
|
|
206
|
-
policy: ExitPolicy,
|
|
207
|
-
at: string,
|
|
208
|
-
): readonly HansardEntry[] => {
|
|
209
|
-
if (policy !== 'elimination') return [];
|
|
210
|
-
const votes = votesFor(hansard, motion);
|
|
211
|
-
const ayes = votes.filter((v) => v.vote === 'AYE');
|
|
212
|
-
const noes = votes.filter((v) => v.vote === 'NO');
|
|
213
|
-
const losers = ayes.length > noes.length ? noes : noes.length > ayes.length ? ayes : [];
|
|
214
|
-
const entries: HansardEntry[] = [];
|
|
215
|
-
for (const loser of losers) {
|
|
216
|
-
const seat = seatOf(hansard, loser.actor);
|
|
217
|
-
if (seat !== null) entries.push(darwinistExit(loser.actor, seat.role, at));
|
|
218
|
-
}
|
|
219
|
-
return entries;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
/** Every vote recorded against a Motion, read back from the Hansard. */
|
|
223
|
-
export const votesFor = (hansard: string, motion: string): readonly CastVote[] =>
|
|
224
|
-
parseEntries(hansard)
|
|
225
|
-
.filter((e) => e.type === 'VOTE_CAST' && e.fields['Motion'] === motion)
|
|
226
|
-
.map((e) => ({
|
|
227
|
-
actor: e.actor,
|
|
228
|
-
role: e.role as Role,
|
|
229
|
-
vote: (e.fields['Vote'] ?? 'ABSTAIN') as Vote,
|
|
230
|
-
}));
|
|
231
|
-
|
|
232
|
-
/* -------------------------------------------------------------------------- */
|
|
233
|
-
/* Outcome */
|
|
234
|
-
/* -------------------------------------------------------------------------- */
|
|
235
|
-
|
|
236
|
-
export interface DivisionOutcome {
|
|
237
|
-
readonly motion: string;
|
|
238
|
-
readonly ayes: number;
|
|
239
|
-
readonly noes: number;
|
|
240
|
-
readonly abstentions: number;
|
|
241
|
-
/** Did the Motion carry? */
|
|
242
|
-
readonly carried: boolean;
|
|
243
|
-
/** Quorum is counted on votes cast, abstentions excluded. */
|
|
244
|
-
readonly quorum_met: boolean;
|
|
245
|
-
/**
|
|
246
|
-
* The quorum threshold in force when this Division was tallied.
|
|
247
|
-
*
|
|
248
|
-
* Recorded so a Division entry is auditable on its own terms. Without it,
|
|
249
|
-
* "quorum met" only means something to a reader willing to recover the
|
|
250
|
-
* Charter as it stood at that commit — and a record that requires
|
|
251
|
-
* cross-referencing to interpret is doing less work than a record should.
|
|
252
|
-
*
|
|
253
|
-
* Enacted by motion-001 of session clean-001, which observed that the
|
|
254
|
-
* validity of a carried Motion was "unverifiable after the fact".
|
|
255
|
-
*/
|
|
256
|
-
readonly quorum_required: number;
|
|
257
|
-
readonly reason: string;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Tally a Division.
|
|
262
|
-
*
|
|
263
|
-
* Abstentions are recorded but do not count toward quorum: an abstention is a
|
|
264
|
-
* declared non-participation, and counting it would let a Division reach quorum
|
|
265
|
-
* without anyone actually deciding anything.
|
|
266
|
-
*
|
|
267
|
-
* A tie does not carry. Without a majority there is no decision, and a Motion
|
|
268
|
-
* that cannot be decided is a DEADLOCK for AUTHORITY to rule on — not a silent
|
|
269
|
-
* pass.
|
|
270
|
-
*/
|
|
271
|
-
/**
|
|
272
|
-
* How a Division resolves — the first protocol override point (ADR-0007). The
|
|
273
|
-
* engine is single and shared; a protocol picks which rule decides the outcome.
|
|
274
|
-
* `majority` is the default and reproduces the original behavior exactly.
|
|
275
|
-
*/
|
|
276
|
-
export type Resolution = 'majority' | 'supermajority' | 'unanimity';
|
|
277
|
-
|
|
278
|
-
export const RESOLUTIONS: readonly Resolution[] = Object.freeze([
|
|
279
|
-
'majority',
|
|
280
|
-
'supermajority',
|
|
281
|
-
'unanimity',
|
|
282
|
-
]);
|
|
283
|
-
|
|
284
|
-
export const isResolution = (v: unknown): v is Resolution =>
|
|
285
|
-
typeof v === 'string' && (RESOLUTIONS as readonly string[]).includes(v);
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Each strategy is a pure function of the ballot and nothing else, so the same
|
|
289
|
-
* votes and the same rule always yield the same verdict — the property the
|
|
290
|
-
* Hansard's auditability depends on (ADR-0007).
|
|
291
|
-
*/
|
|
292
|
-
const RESOLUTION_RULES: Readonly<
|
|
293
|
-
Record<Resolution, (ayes: number, noes: number, abstentions: number) => { carried: boolean; reason: string }>
|
|
294
|
-
> = Object.freeze({
|
|
295
|
-
majority: (ayes, noes) =>
|
|
296
|
-
ayes > noes
|
|
297
|
-
? { carried: true, reason: `carried ${ayes} to ${noes}` }
|
|
298
|
-
: {
|
|
299
|
-
carried: false,
|
|
300
|
-
reason: ayes === noes ? `tied ${ayes} all — no majority, DEADLOCK` : `rejected ${ayes} to ${noes}`,
|
|
301
|
-
},
|
|
302
|
-
supermajority: (ayes, noes) => {
|
|
303
|
-
// Two-thirds of the decisive votes, abstentions excluded.
|
|
304
|
-
const carried = ayes > 0 && ayes * 3 >= (ayes + noes) * 2 && ayes > noes;
|
|
305
|
-
return carried
|
|
306
|
-
? { carried: true, reason: `carried ${ayes} to ${noes} — two-thirds supermajority met` }
|
|
307
|
-
: { carried: false, reason: `rejected ${ayes} to ${noes} — a two-thirds supermajority was required` };
|
|
308
|
-
},
|
|
309
|
-
unanimity: (ayes, noes, abstentions) => {
|
|
310
|
-
// Every seated voter must assent; a single dissent or abstention hangs it.
|
|
311
|
-
const carried = ayes > 0 && noes === 0 && abstentions === 0;
|
|
312
|
-
if (carried) return { carried: true, reason: `carried unanimously, ${ayes} to 0` };
|
|
313
|
-
return {
|
|
314
|
-
carried: false,
|
|
315
|
-
reason:
|
|
316
|
-
noes > 0
|
|
317
|
-
? `rejected — unanimity required, ${noes} against`
|
|
318
|
-
: `no verdict — unanimity required, ${abstentions} abstained`,
|
|
319
|
-
};
|
|
320
|
-
},
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
export const tallyDivision = (
|
|
324
|
-
hansard: string,
|
|
325
|
-
motion: string,
|
|
326
|
-
quorumRequired: number,
|
|
327
|
-
override?: QuorumOverride | null,
|
|
328
|
-
resolution: Resolution = 'majority',
|
|
329
|
-
): DivisionOutcome => {
|
|
330
|
-
const votes = votesFor(hansard, motion);
|
|
331
|
-
const ayes = votes.filter((v) => v.vote === 'AYE').length;
|
|
332
|
-
const noes = votes.filter((v) => v.vote === 'NO').length;
|
|
333
|
-
const abstentions = votes.filter((v) => v.vote === 'ABSTAIN').length;
|
|
334
|
-
|
|
335
|
-
const quorum = checkQuorum({
|
|
336
|
-
required: quorumRequired,
|
|
337
|
-
present: ayes + noes,
|
|
338
|
-
override,
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
if (!quorum.met) {
|
|
342
|
-
return {
|
|
343
|
-
motion,
|
|
344
|
-
ayes,
|
|
345
|
-
noes,
|
|
346
|
-
abstentions,
|
|
347
|
-
carried: false,
|
|
348
|
-
quorum_met: false,
|
|
349
|
-
quorum_required: quorumRequired,
|
|
350
|
-
reason: quorum.reason ?? 'quorum not met',
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const decision = RESOLUTION_RULES[resolution](ayes, noes, abstentions);
|
|
355
|
-
return {
|
|
356
|
-
motion, ayes, noes, abstentions,
|
|
357
|
-
carried: decision.carried,
|
|
358
|
-
quorum_met: true,
|
|
359
|
-
quorum_required: quorumRequired,
|
|
360
|
-
reason:
|
|
361
|
-
decision.carried && quorum.degraded ? `${decision.reason} (degraded quorum)` : decision.reason,
|
|
362
|
-
};
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
/** Record the outcome of a Division. */
|
|
366
|
-
export const recordOutcome = (
|
|
367
|
-
outcome: DivisionOutcome,
|
|
368
|
-
at: string,
|
|
369
|
-
actor: string,
|
|
370
|
-
role: Role,
|
|
371
|
-
hansard: string,
|
|
372
|
-
): { readonly entry: HansardEntry; readonly hansard: string } => {
|
|
373
|
-
const entry: HansardEntry = {
|
|
374
|
-
type: outcome.carried ? 'MOTION_CARRIED' : 'MOTION_REJECTED',
|
|
375
|
-
at,
|
|
376
|
-
actor,
|
|
377
|
-
role,
|
|
378
|
-
fields: {
|
|
379
|
-
Motion: outcome.motion,
|
|
380
|
-
Ayes: String(outcome.ayes),
|
|
381
|
-
Noes: String(outcome.noes),
|
|
382
|
-
Abstentions: String(outcome.abstentions),
|
|
383
|
-
Quorum: `${outcome.quorum_met ? 'met' : 'NOT MET'} (${outcome.quorum_required} required)`,
|
|
384
|
-
Outcome: outcome.reason,
|
|
385
|
-
},
|
|
386
|
-
};
|
|
387
|
-
return { entry, hansard: appendEntry(hansard, entry) };
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
/* -------------------------------------------------------------------------- */
|
|
391
|
-
/* Assent */
|
|
392
|
-
/* -------------------------------------------------------------------------- */
|
|
393
|
-
|
|
394
|
-
export interface AssentInput {
|
|
395
|
-
readonly motion: string;
|
|
396
|
-
readonly at: string;
|
|
397
|
-
readonly actor: string;
|
|
398
|
-
readonly role: Role;
|
|
399
|
-
/** Role the Charter grants ASSENT. Defaults to AUTHORITY (ADR-0004). */
|
|
400
|
-
readonly assent_role: Role;
|
|
401
|
-
readonly outcome: DivisionOutcome;
|
|
402
|
-
readonly state: SessionStateFile;
|
|
403
|
-
/**
|
|
404
|
-
* Is a veto standing against this Motion? ADR-0004 makes Assent invalid while
|
|
405
|
-
* one is outstanding — the fourth condition, and the one a caller is most
|
|
406
|
-
* likely to forget, so it is explicit rather than inferred.
|
|
407
|
-
*/
|
|
408
|
-
readonly veto_outstanding?: boolean;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Grant Assent — enact a carried Motion.
|
|
413
|
-
*
|
|
414
|
-
* Four conditions, all from ADR-0004. Every one is checked rather than assumed,
|
|
415
|
-
* because Assent is the moment a decision becomes an effect and it is the last
|
|
416
|
-
* point at which the constitution can refuse.
|
|
417
|
-
*/
|
|
418
|
-
export const grantAssent = (input: AssentInput, hansard: string): {
|
|
419
|
-
readonly entry: HansardEntry;
|
|
420
|
-
readonly hansard: string;
|
|
421
|
-
readonly state: SessionStateFile;
|
|
422
|
-
} => {
|
|
423
|
-
if (input.role !== input.assent_role) {
|
|
424
|
-
throw new DivisionError(
|
|
425
|
-
`ASSENT is held by ${input.assent_role} — ${input.actor} is ${input.role}`,
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
if (input.state.state !== 'CONVENED') {
|
|
429
|
-
throw new DivisionError(`cannot grant Assent while the session is ${input.state.state}`);
|
|
430
|
-
}
|
|
431
|
-
if (!input.outcome.carried) {
|
|
432
|
-
throw new DivisionError(
|
|
433
|
-
`${input.motion} did not carry (${input.outcome.reason}) — there is nothing to enact`,
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
if (alreadyEnacted(hansard, input.motion)) {
|
|
437
|
-
throw new DivisionError(`${input.motion} has already received Assent`);
|
|
438
|
-
}
|
|
439
|
-
if (input.veto_outstanding === true) {
|
|
440
|
-
throw new DivisionError(
|
|
441
|
-
`a veto stands against ${input.motion} — it may not receive Assent while that veto is outstanding`,
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const entry: HansardEntry = {
|
|
446
|
-
type: 'ASSENT_GRANTED',
|
|
447
|
-
at: input.at,
|
|
448
|
-
actor: input.actor,
|
|
449
|
-
role: input.role,
|
|
450
|
-
fields: {
|
|
451
|
-
Motion: input.motion,
|
|
452
|
-
Division: input.outcome.reason,
|
|
453
|
-
Effect: 'enacted',
|
|
454
|
-
},
|
|
455
|
-
body: `Assent granted. ${input.motion} is enacted.`,
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
return {
|
|
459
|
-
entry,
|
|
460
|
-
hansard: appendEntry(hansard, entry),
|
|
461
|
-
state: createState({
|
|
462
|
-
session_guid: input.state.session_guid,
|
|
463
|
-
protocol: input.state.protocol,
|
|
464
|
-
state: 'CONVENED',
|
|
465
|
-
quorum: input.state.quorum,
|
|
466
|
-
hansard_head: input.state.hansard_head,
|
|
467
|
-
updated_at: input.at,
|
|
468
|
-
}),
|
|
469
|
-
};
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
/** Has this Motion already been enacted? */
|
|
473
|
-
export const alreadyEnacted = (hansard: string, motion: string): boolean =>
|
|
474
|
-
parseEntries(hansard).some(
|
|
475
|
-
(e) => e.type === 'ASSENT_GRANTED' && e.fields['Motion'] === motion,
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
/* -------------------------------------------------------------------------- */
|
|
479
|
-
/* Deadlock */
|
|
480
|
-
/* -------------------------------------------------------------------------- */
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Suspend a proceeding on an undecidable Division.
|
|
484
|
-
*
|
|
485
|
-
* ADR-0004 Proposal 4 adds `DEADLOCK` to the suspension causes: a Division that
|
|
486
|
-
* yields no valid outcome is a governance failure, not a silent pass. Until
|
|
487
|
-
* this existed the tally wrote the word "DEADLOCK" into free text and the
|
|
488
|
-
* session carried on as though nothing had happened.
|
|
489
|
-
*
|
|
490
|
-
* Suspends rather than rejects, because a tie is not a decision against the
|
|
491
|
-
* Motion — it is the absence of one, and only AUTHORITY can supply what the
|
|
492
|
-
* House could not.
|
|
493
|
-
*/
|
|
494
|
-
export const suspendForDeadlock = (
|
|
495
|
-
outcome: DivisionOutcome,
|
|
496
|
-
at: string,
|
|
497
|
-
state: SessionStateFile,
|
|
498
|
-
hansard: string,
|
|
499
|
-
): {
|
|
500
|
-
readonly entry: HansardEntry;
|
|
501
|
-
readonly hansard: string;
|
|
502
|
-
readonly state: SessionStateFile;
|
|
503
|
-
} => {
|
|
504
|
-
if (outcome.carried || outcome.ayes !== outcome.noes || !outcome.quorum_met) {
|
|
505
|
-
throw new DivisionError(
|
|
506
|
-
`${outcome.motion} is not deadlocked — ${outcome.reason}`,
|
|
507
|
-
);
|
|
508
|
-
}
|
|
509
|
-
if (state.state !== 'CONVENED') {
|
|
510
|
-
throw new DivisionError(`cannot declare a deadlock while the session is ${state.state}`);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
const entry: HansardEntry = {
|
|
514
|
-
type: 'DEADLOCK',
|
|
515
|
-
at,
|
|
516
|
-
actor: 'RECORD',
|
|
517
|
-
role: 'OPERATOR',
|
|
518
|
-
fields: {
|
|
519
|
-
Motion: outcome.motion,
|
|
520
|
-
Division: outcome.reason,
|
|
521
|
-
'Session status': 'SUSPENDED — no valid Division outcome',
|
|
522
|
-
Resolution: 'AUTHORITY must rule; the House could not decide',
|
|
523
|
-
},
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
return {
|
|
527
|
-
entry,
|
|
528
|
-
hansard: appendEntry(hansard, entry),
|
|
529
|
-
state: createState({
|
|
530
|
-
session_guid: state.session_guid,
|
|
531
|
-
protocol: state.protocol,
|
|
532
|
-
state: 'SUSPENDED',
|
|
533
|
-
quorum: state.quorum,
|
|
534
|
-
hansard_head: state.hansard_head,
|
|
535
|
-
updated_at: at,
|
|
536
|
-
suspension: {
|
|
537
|
-
cause: 'DEADLOCK',
|
|
538
|
-
since: at,
|
|
539
|
-
record_ref: 'HANSARD.md',
|
|
540
|
-
escalation_ref: null,
|
|
541
|
-
},
|
|
542
|
-
}),
|
|
543
|
-
};
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* AUTHORITY breaks a DEADLOCK with a casting vote.
|
|
548
|
-
*
|
|
549
|
-
* The tie suspended the sitting because the House could not decide; only
|
|
550
|
-
* AUTHORITY can supply the decision it could not reach (suspendForDeadlock:
|
|
551
|
-
* "AUTHORITY must rule; the House could not decide"). The casting vote decides
|
|
552
|
-
* the Motion — carried or rejected — and the sitting resumes. Refuses unless the
|
|
553
|
-
* session is actually deadlocked, so a casting vote can never override a Division
|
|
554
|
-
* the House did decide.
|
|
555
|
-
*/
|
|
556
|
-
export const breakDeadlock = (
|
|
557
|
-
motion: string,
|
|
558
|
-
decision: 'carry' | 'reject',
|
|
559
|
-
at: string,
|
|
560
|
-
authority: string,
|
|
561
|
-
state: SessionStateFile,
|
|
562
|
-
hansard: string,
|
|
563
|
-
quorumRequired: number,
|
|
564
|
-
resolution: Resolution = 'majority',
|
|
565
|
-
): {
|
|
566
|
-
/** The casting vote, then the outcome it produces. */
|
|
567
|
-
readonly entries: readonly HansardEntry[];
|
|
568
|
-
readonly hansard: string;
|
|
569
|
-
readonly outcome: DivisionOutcome;
|
|
570
|
-
readonly state: SessionStateFile;
|
|
571
|
-
} => {
|
|
572
|
-
if (state.state !== 'SUSPENDED' || state.suspension?.cause !== 'DEADLOCK') {
|
|
573
|
-
throw new DivisionError('the session is not deadlocked — there is no tie for a casting vote to break');
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// The casting vote is a real vote: AYE to carry, NO to reject. It flows through
|
|
577
|
-
// the ordinary tally, so every downstream reader (Assent included) sees a
|
|
578
|
-
// decided Division, not a special case only this command understands.
|
|
579
|
-
const casting: HansardEntry = {
|
|
580
|
-
type: 'VOTE_CAST',
|
|
581
|
-
at,
|
|
582
|
-
actor: authority,
|
|
583
|
-
role: 'AUTHORITY',
|
|
584
|
-
fields: {
|
|
585
|
-
Motion: motion,
|
|
586
|
-
Vote: decision === 'carry' ? 'AYE' : 'NO',
|
|
587
|
-
Note: 'AUTHORITY casting vote to break a DEADLOCK',
|
|
588
|
-
},
|
|
589
|
-
};
|
|
590
|
-
const withVote = appendEntry(hansard, casting);
|
|
591
|
-
const outcome = tallyDivision(withVote, motion, quorumRequired, null, resolution);
|
|
592
|
-
const recorded = recordOutcome(outcome, at, authority, 'AUTHORITY', withVote);
|
|
593
|
-
|
|
594
|
-
return {
|
|
595
|
-
entries: [casting, recorded.entry],
|
|
596
|
-
hansard: recorded.hansard,
|
|
597
|
-
outcome,
|
|
598
|
-
state: createState({
|
|
599
|
-
session_guid: state.session_guid,
|
|
600
|
-
protocol: state.protocol,
|
|
601
|
-
state: 'CONVENED',
|
|
602
|
-
quorum: state.quorum,
|
|
603
|
-
hansard_head: state.hansard_head,
|
|
604
|
-
updated_at: at,
|
|
605
|
-
updated_by: authority,
|
|
606
|
-
suspension: null,
|
|
607
|
-
}),
|
|
608
|
-
};
|
|
609
|
-
};
|