@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/integrity.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Integrity — the bad-faith detector.
|
|
3
3
|
*
|
|
4
|
-
* Skills are capability, declared before seating (`capability.ts`).
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Skills are capability, declared before seating (`capability.ts`). Bad faith is
|
|
5
|
+
* not capability: it appears only in behaviour, over time. So this module does
|
|
6
|
+
* not read a profile — it reads the immutable record for the bad-faith
|
|
7
7
|
* signatures RUNTIME.md § The Voluntold Problem spells out, and surfaces them to
|
|
8
|
-
* the
|
|
9
|
-
* is the deterrent". The one case it cannot catch is a bad-faith
|
|
8
|
+
* the owner. It **detects and reports; it never punishes** — "the audit trail
|
|
9
|
+
* is the deterrent". The one case it cannot catch is a bad-faith Owner, and
|
|
10
10
|
* nothing can, except the record being visible to everyone who can read the repo.
|
|
11
11
|
*
|
|
12
12
|
* Pure by construction: a function of the record and nothing else, so the same
|
|
13
|
-
*
|
|
13
|
+
* record always yields the same findings — the property auditability depends on.
|
|
14
14
|
*
|
|
15
15
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import type { Role } from './canon.ts';
|
|
19
|
-
import { parseEntries } from './
|
|
19
|
+
import { parseEntries } from './log.ts';
|
|
20
20
|
|
|
21
|
-
export type FindingKind = '
|
|
21
|
+
export type FindingKind = 'bad-faith' | 'good-faith';
|
|
22
22
|
export type Severity = 'high' | 'medium' | 'low' | 'praise';
|
|
23
23
|
|
|
24
24
|
export interface IntegrityFinding {
|
|
@@ -33,20 +33,20 @@ export interface IntegrityFinding {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Review a session's
|
|
36
|
+
* Review a session's record for bad-faith (and good-faith) patterns.
|
|
37
37
|
*
|
|
38
|
-
* v1 — single session
|
|
39
|
-
* - coerced-exit (
|
|
40
|
-
* - strategic-withdrawal (
|
|
41
|
-
* - serial-voluntold (
|
|
42
|
-
* - honest-concession (
|
|
38
|
+
* v1 — single session:
|
|
39
|
+
* - coerced-exit (bad faith, high) — an EXIT_VOLUNTARY_COERCED: a voluntold.
|
|
40
|
+
* - strategic-withdrawal (bad faith, medium) — a strategic exit while a vote is open.
|
|
41
|
+
* - serial-voluntold (bad faith, high) — one OPERATOR seated for two+ voluntary exits.
|
|
42
|
+
* - honest-concession (good faith) — a reasoned EXIT_VOLUNTARY_CONCESSION.
|
|
43
43
|
*/
|
|
44
|
-
export const reviewIntegrity = (
|
|
45
|
-
const entries = parseEntries(
|
|
44
|
+
export const reviewIntegrity = (log: string): readonly IntegrityFinding[] => {
|
|
45
|
+
const entries = parseEntries(log);
|
|
46
46
|
const findings: IntegrityFinding[] = [];
|
|
47
47
|
|
|
48
48
|
// Replayed session state, in record order.
|
|
49
|
-
const
|
|
49
|
+
const openBallots = new Set<string>();
|
|
50
50
|
const seated = new Map<string, Role>();
|
|
51
51
|
// OPERATOR -> the actors whose voluntary exits they were seated for.
|
|
52
52
|
const voluntaryUnder = new Map<string, string[]>();
|
|
@@ -54,15 +54,15 @@ export const reviewIntegrity = (hansard: string): readonly IntegrityFinding[] =>
|
|
|
54
54
|
for (const entry of entries) {
|
|
55
55
|
const f = entry.fields;
|
|
56
56
|
switch (entry.type) {
|
|
57
|
-
case '
|
|
57
|
+
case 'BALLOT_OPENED': {
|
|
58
58
|
const motion = f['Motion'];
|
|
59
|
-
if (motion !== undefined)
|
|
59
|
+
if (motion !== undefined) openBallots.add(motion);
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
case 'MOTION_CARRIED':
|
|
63
63
|
case 'MOTION_REJECTED': {
|
|
64
64
|
const motion = f['Motion'];
|
|
65
|
-
if (motion !== undefined)
|
|
65
|
+
if (motion !== undefined) openBallots.delete(motion);
|
|
66
66
|
break;
|
|
67
67
|
}
|
|
68
68
|
case 'ACTOR_HIRED': {
|
|
@@ -82,35 +82,35 @@ export const reviewIntegrity = (hansard: string): readonly IntegrityFinding[] =>
|
|
|
82
82
|
const subject = f['Actor affected'] ?? entry.actor;
|
|
83
83
|
const exitType = f['Exit type'] ?? '';
|
|
84
84
|
const reason = (f['Reason'] ?? '').trim();
|
|
85
|
-
const
|
|
85
|
+
const duringBallot = openBallots.size > 0;
|
|
86
86
|
const operatorsPresent = [...seated.entries()]
|
|
87
87
|
.filter(([who, role]) => role === 'OPERATOR' && who !== subject)
|
|
88
88
|
.map(([who]) => who);
|
|
89
89
|
|
|
90
90
|
if (exitType === 'EXIT_VOLUNTARY_COERCED') {
|
|
91
91
|
findings.push({
|
|
92
|
-
kind: '
|
|
92
|
+
kind: 'bad-faith',
|
|
93
93
|
signature: 'coerced-exit',
|
|
94
94
|
severity: 'high',
|
|
95
95
|
actors: [subject, ...operatorsPresent],
|
|
96
96
|
evidence:
|
|
97
97
|
`${subject} exited EXIT_VOLUNTARY_COERCED (voluntold) at ${entry.at}` +
|
|
98
|
-
`${
|
|
98
|
+
`${duringBallot ? ' while a vote was open' : ''}` +
|
|
99
99
|
`${operatorsPresent.length > 0 ? ` — OPERATOR(s) seated: ${operatorsPresent.join(', ')}` : ''}`,
|
|
100
100
|
});
|
|
101
|
-
} else if (exitType === 'EXIT_VOLUNTARY_STRATEGIC' &&
|
|
101
|
+
} else if (exitType === 'EXIT_VOLUNTARY_STRATEGIC' && duringBallot) {
|
|
102
102
|
findings.push({
|
|
103
|
-
kind: '
|
|
103
|
+
kind: 'bad-faith',
|
|
104
104
|
signature: 'strategic-withdrawal',
|
|
105
105
|
severity: 'medium',
|
|
106
106
|
actors: [subject],
|
|
107
107
|
evidence:
|
|
108
|
-
`${subject} filed EXIT_VOLUNTARY_STRATEGIC while a
|
|
109
|
-
`(${[...
|
|
108
|
+
`${subject} filed EXIT_VOLUNTARY_STRATEGIC while a vote was open ` +
|
|
109
|
+
`(${[...openBallots].join(', ')}) — withdrawing to affect a live vote`,
|
|
110
110
|
});
|
|
111
111
|
} else if (exitType === 'EXIT_VOLUNTARY_CONCESSION' && reason !== '') {
|
|
112
112
|
findings.push({
|
|
113
|
-
kind: '
|
|
113
|
+
kind: 'good-faith',
|
|
114
114
|
signature: 'honest-concession',
|
|
115
115
|
severity: 'praise',
|
|
116
116
|
actors: [subject],
|
|
@@ -134,11 +134,11 @@ export const reviewIntegrity = (hansard: string): readonly IntegrityFinding[] =>
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// Serial voluntold: one OPERATOR present for two or more voluntary exits is the
|
|
137
|
-
//
|
|
137
|
+
// record pattern that outlives any single deniable withdrawal.
|
|
138
138
|
for (const [operator, affected] of voluntaryUnder) {
|
|
139
139
|
if (affected.length >= 2) {
|
|
140
140
|
findings.push({
|
|
141
|
-
kind: '
|
|
141
|
+
kind: 'bad-faith',
|
|
142
142
|
signature: 'serial-voluntold',
|
|
143
143
|
severity: 'high',
|
|
144
144
|
actors: [operator, ...affected],
|
package/src/ledger.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LEDGER — the secretarial cost record.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
4
|
+
* The record says what was decided. The LEDGER says what it cost. Together
|
|
5
5
|
* they are the claim that Politik replaces a ticket system: exact measured
|
|
6
6
|
* elapsed time, tokens and dollars per governance act, as a side effect of
|
|
7
7
|
* running the session rather than as something anyone maintains.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* does not — never an estimate dressed as a measurement. A ledger with invented
|
|
12
12
|
* numbers is worse than no ledger, because it is trusted.
|
|
13
13
|
*
|
|
14
|
-
* Append-only, like the
|
|
14
|
+
* Append-only, like the record: `LEDGER.md → Clerk appends after every motion,
|
|
15
15
|
* never edited` (POLITIK-ARCHITECTURE.md § File Sovereignty Rules).
|
|
16
16
|
*
|
|
17
17
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
@@ -258,7 +258,7 @@ export const LEDGER_HEADER = [
|
|
|
258
258
|
* Append a row to the LEDGER.
|
|
259
259
|
*
|
|
260
260
|
* Returns the previous document verbatim as a prefix, same guarantee as the
|
|
261
|
-
*
|
|
261
|
+
* record. If the document has no table yet, the header is inserted once.
|
|
262
262
|
*/
|
|
263
263
|
export const appendLedgerRow = (document: string, entry: LedgerEntry): string => {
|
|
264
264
|
const base = document.endsWith('\n') || document === '' ? document : `${document}\n`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The session log writer.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* LOG.md is the append-only attributed record of a proceeding
|
|
5
5
|
* (POLITIK-ARCHITECTURE.md § File Sovereignty Rules: "Append only, never edited").
|
|
6
6
|
* The RECORD agent writes it; no actor edits an entry once committed.
|
|
7
7
|
*
|
|
@@ -27,11 +27,11 @@ import type { Role } from './canon.ts';
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Record types named in the source documents. Not exhaustive and not a closed
|
|
30
|
-
* enum — `
|
|
30
|
+
* enum — `RecordEntry.type` accepts any string so a protocol may record events
|
|
31
31
|
* these documents never anticipated.
|
|
32
32
|
*/
|
|
33
33
|
export const RECORD_TYPES = {
|
|
34
|
-
|
|
34
|
+
SESSION_OPENED: 'SESSION_OPENED',
|
|
35
35
|
SESSION_INVALID: 'SESSION_INVALID',
|
|
36
36
|
SESSION_FAULT: 'SESSION_FAULT',
|
|
37
37
|
SESSION_FAULT_CRITICAL: 'SESSION_FAULT_CRITICAL',
|
|
@@ -46,12 +46,12 @@ export type RecordType = string;
|
|
|
46
46
|
/* Entry */
|
|
47
47
|
/* -------------------------------------------------------------------------- */
|
|
48
48
|
|
|
49
|
-
export interface
|
|
50
|
-
/** Record type, e.g.
|
|
49
|
+
export interface RecordEntry {
|
|
50
|
+
/** Record type, e.g. SESSION_OPENED. Rendered as the entry heading. */
|
|
51
51
|
readonly type: RecordType;
|
|
52
52
|
/** ISO-8601 UTC. Supplied by the caller — this module reads no clock. */
|
|
53
53
|
readonly at: string;
|
|
54
|
-
/** Acting actor's handle. Attribution is not optional in a
|
|
54
|
+
/** Acting actor's handle. Attribution is not optional in a record. */
|
|
55
55
|
readonly actor: string;
|
|
56
56
|
/** The actor's CANON role at the time of the act. */
|
|
57
57
|
readonly role: Role;
|
|
@@ -61,11 +61,11 @@ export interface HansardEntry {
|
|
|
61
61
|
readonly body?: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/** Thrown when an entry cannot be attributed. An unattributed
|
|
65
|
-
export class
|
|
64
|
+
/** Thrown when an entry cannot be attributed. An unattributed entry does not belong in the log. */
|
|
65
|
+
export class RecordError extends Error {
|
|
66
66
|
constructor(message: string) {
|
|
67
67
|
super(message);
|
|
68
|
-
this.name = '
|
|
68
|
+
this.name = 'RecordError';
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -80,18 +80,18 @@ const escapeField = (value: string): string => value.replace(/\r?\n/g, ' ').trim
|
|
|
80
80
|
*
|
|
81
81
|
* Multi-line field values are collapsed to a single line: a field that spans
|
|
82
82
|
* lines would be indistinguishable from the prose body when the file is read
|
|
83
|
-
* back, and the
|
|
83
|
+
* back, and the record's value depends on being unambiguously parseable.
|
|
84
84
|
* Long-form content belongs in `body`.
|
|
85
85
|
*/
|
|
86
|
-
export const renderEntry = (entry:
|
|
86
|
+
export const renderEntry = (entry: RecordEntry): string => {
|
|
87
87
|
if (entry.actor.trim() === '') {
|
|
88
|
-
throw new
|
|
88
|
+
throw new RecordError('Log entry requires an actor — records are attributed');
|
|
89
89
|
}
|
|
90
90
|
if (entry.type.trim() === '') {
|
|
91
|
-
throw new
|
|
91
|
+
throw new RecordError('Log entry requires a record type');
|
|
92
92
|
}
|
|
93
93
|
if (entry.at.trim() === '') {
|
|
94
|
-
throw new
|
|
94
|
+
throw new RecordError('Log entry requires a timestamp');
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
const lines = [
|
|
@@ -117,14 +117,14 @@ export const renderEntry = (entry: HansardEntry): string => {
|
|
|
117
117
|
/* -------------------------------------------------------------------------- */
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* Append an entry to a
|
|
120
|
+
* Append an entry to a record document.
|
|
121
121
|
*
|
|
122
122
|
* Pure: takes the current document, returns the new one. The caller commits it
|
|
123
123
|
* through an ScmProvider. Existing content is never rewritten — the returned
|
|
124
124
|
* document always starts with the input verbatim, which is the append-only
|
|
125
125
|
* guarantee made mechanical.
|
|
126
126
|
*/
|
|
127
|
-
export const appendEntry = (document: string, entry:
|
|
127
|
+
export const appendEntry = (document: string, entry: RecordEntry): string => {
|
|
128
128
|
const base = document.endsWith('\n') || document === '' ? document : `${document}\n`;
|
|
129
129
|
return `${base}\n${renderEntry(entry)}`;
|
|
130
130
|
};
|
|
@@ -132,7 +132,7 @@ export const appendEntry = (document: string, entry: HansardEntry): string => {
|
|
|
132
132
|
/** Append several entries in order. */
|
|
133
133
|
export const appendEntries = (
|
|
134
134
|
document: string,
|
|
135
|
-
entries: readonly
|
|
135
|
+
entries: readonly RecordEntry[],
|
|
136
136
|
): string => entries.reduce(appendEntry, document);
|
|
137
137
|
|
|
138
138
|
/* -------------------------------------------------------------------------- */
|
|
@@ -152,7 +152,7 @@ const FIELD_LINE = /^\*\*(.+?):\*\*\s*(.*)$/;
|
|
|
152
152
|
const ACTOR_VALUE = /^(.*?)\s*\(([A-Z]+)\)\s*$/;
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
|
-
* Read entries back out of a
|
|
155
|
+
* Read entries back out of a record document.
|
|
156
156
|
*
|
|
157
157
|
* Provided so the record can be audited and so tests can assert what was
|
|
158
158
|
* written. Best-effort: a document that predates this writer, or that a future
|
|
@@ -196,6 +196,6 @@ export const parseEntries = (document: string): readonly ParsedEntry[] => {
|
|
|
196
196
|
return entries;
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
/** The most recent entry, or null for an empty
|
|
199
|
+
/** The most recent entry, or null for an empty record. */
|
|
200
200
|
export const lastEntry = (document: string): ParsedEntry | null =>
|
|
201
201
|
parseEntries(document).at(-1) ?? null;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* misconduct — the failure mode where AUTHORITY is the corruptor.
|
|
3
3
|
*
|
|
4
|
-
* Every other defence in Politik routes to the
|
|
5
|
-
* promotion vetoes,
|
|
4
|
+
* Every other defence in Politik routes to the owner: disputed exits,
|
|
5
|
+
* promotion vetoes, tied votes, escalations. If the owner is the
|
|
6
6
|
* source of corruption, all of those route directly to the problem — the system
|
|
7
7
|
* does not merely fail, it assists (RUNTIME.md § Constitutional Capture).
|
|
8
8
|
*
|
|
9
9
|
* There is no mechanism above AUTHORITY, by design. That is what makes the role
|
|
10
|
-
* constitutional. So this module does not remove
|
|
10
|
+
* constitutional. So this module does not remove an owner; it cannot. What it
|
|
11
11
|
* does is make capture **visible, attributed and undeniable**, halt the session
|
|
12
12
|
* so no further acts are taken under a captured constitution, and require a
|
|
13
13
|
* human from outside the session to rule before anything resumes.
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import type { Role } from './canon.ts';
|
|
22
|
-
import { appendEntry, parseEntries, type
|
|
22
|
+
import { appendEntry, parseEntries, type RecordEntry } from './log.ts';
|
|
23
23
|
import { createState, type SessionStateFile } from './state.ts';
|
|
24
24
|
|
|
25
25
|
/* -------------------------------------------------------------------------- */
|
|
@@ -52,13 +52,13 @@ export const DEFAULT_CONSENSUS: ConsensusSuspension = Object.freeze({
|
|
|
52
52
|
export interface WitnessCouncil {
|
|
53
53
|
readonly enabled: boolean;
|
|
54
54
|
readonly roles: readonly Role[];
|
|
55
|
-
readonly can_file: '
|
|
55
|
+
readonly can_file: 'MISCONDUCT';
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export class
|
|
58
|
+
export class MisconductError extends Error {
|
|
59
59
|
constructor(message: string) {
|
|
60
60
|
super(message);
|
|
61
|
-
this.name = '
|
|
61
|
+
this.name = 'MisconductError';
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -66,43 +66,43 @@ export class CrisisError extends Error {
|
|
|
66
66
|
/* Filing */
|
|
67
67
|
/* -------------------------------------------------------------------------- */
|
|
68
68
|
|
|
69
|
-
export interface
|
|
69
|
+
export interface MisconductReport {
|
|
70
70
|
readonly actor: string;
|
|
71
71
|
readonly role: Role;
|
|
72
72
|
readonly grounds: string;
|
|
73
73
|
readonly at: string;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export interface
|
|
76
|
+
export interface ReportMisconductInput {
|
|
77
77
|
readonly at: string;
|
|
78
78
|
readonly actor: string;
|
|
79
79
|
readonly role: Role;
|
|
80
80
|
/** What AUTHORITY is alleged to have done. */
|
|
81
81
|
readonly grounds: string;
|
|
82
|
-
/** The
|
|
82
|
+
/** The owner the filing is against. */
|
|
83
83
|
readonly against: string;
|
|
84
84
|
readonly state: SessionStateFile;
|
|
85
85
|
readonly witness?: WitnessCouncil | null;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* File a
|
|
89
|
+
* File a misconduct escalation against AUTHORITY.
|
|
90
90
|
*
|
|
91
91
|
* Who may file:
|
|
92
92
|
* - OPERATOR — needs a supermajority to trigger suspension
|
|
93
93
|
* - a designated witness role — triggers alone
|
|
94
94
|
*
|
|
95
|
-
* AUTHORITY may not file against itself.
|
|
95
|
+
* AUTHORITY may not file against itself. An owner declaring their own misconduct
|
|
96
96
|
* would be a route to suspending a session at will while appearing to submit to
|
|
97
97
|
* scrutiny, which is a capture technique rather than a defence against one.
|
|
98
98
|
*/
|
|
99
|
-
export const
|
|
100
|
-
input:
|
|
101
|
-
|
|
102
|
-
): { readonly entry:
|
|
99
|
+
export const reportMisconduct = (
|
|
100
|
+
input: ReportMisconductInput,
|
|
101
|
+
log: string,
|
|
102
|
+
): { readonly entry: RecordEntry; readonly log: string } => {
|
|
103
103
|
if (input.role === 'AUTHORITY') {
|
|
104
|
-
throw new
|
|
105
|
-
'AUTHORITY may not file a
|
|
104
|
+
throw new MisconductError(
|
|
105
|
+
'AUTHORITY may not file a misconduct against itself',
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -110,22 +110,22 @@ export const fileCrisis = (
|
|
|
110
110
|
input.witness?.enabled === true && input.witness.roles.includes(input.role);
|
|
111
111
|
|
|
112
112
|
if (input.role !== 'OPERATOR' && !isWitness) {
|
|
113
|
-
throw new
|
|
114
|
-
`${input.role} may not file a
|
|
113
|
+
throw new MisconductError(
|
|
114
|
+
`${input.role} may not file a misconduct — OPERATOR, or a designated witness role, only`,
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
if (input.grounds.trim() === '') {
|
|
119
|
-
throw new
|
|
119
|
+
throw new MisconductError('a misconduct filing must state its grounds');
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
const already = filings(
|
|
122
|
+
const already = filings(log).find((f) => f.actor === input.actor);
|
|
123
123
|
if (already !== undefined) {
|
|
124
|
-
throw new
|
|
124
|
+
throw new MisconductError(`${input.actor} has already filed`);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
const entry:
|
|
128
|
-
type: '
|
|
127
|
+
const entry: RecordEntry = {
|
|
128
|
+
type: 'MISCONDUCT_REPORTED',
|
|
129
129
|
at: input.at,
|
|
130
130
|
actor: input.actor,
|
|
131
131
|
role: input.role,
|
|
@@ -137,13 +137,13 @@ export const fileCrisis = (
|
|
|
137
137
|
body: input.grounds,
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
return { entry,
|
|
140
|
+
return { entry, log: appendEntry(log, entry) };
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
-
/** Every
|
|
144
|
-
export const filings = (
|
|
145
|
-
parseEntries(
|
|
146
|
-
.filter((e) => e.type === '
|
|
143
|
+
/** Every misconduct filing on the record. */
|
|
144
|
+
export const filings = (log: string): readonly MisconductReport[] =>
|
|
145
|
+
parseEntries(log)
|
|
146
|
+
.filter((e) => e.type === 'MISCONDUCT_REPORTED')
|
|
147
147
|
.map((e) => ({
|
|
148
148
|
actor: e.actor,
|
|
149
149
|
role: e.role as Role,
|
|
@@ -169,18 +169,18 @@ export interface CaptureCheck {
|
|
|
169
169
|
* Has a supermajority — or a witness — declared capture?
|
|
170
170
|
*
|
|
171
171
|
* The threshold is computed against the OPERATOR bench as seated, which is the
|
|
172
|
-
* uncomfortable part:
|
|
172
|
+
* uncomfortable part: an owner who has already expelled dissenting operators
|
|
173
173
|
* shrinks the denominator and makes the remaining bench easier to hold. The
|
|
174
174
|
* Witness Council exists because of exactly that, and a witness filing bypasses
|
|
175
175
|
* the count entirely.
|
|
176
176
|
*/
|
|
177
177
|
export const checkCapture = (
|
|
178
|
-
|
|
178
|
+
log: string,
|
|
179
179
|
operatorCount: number,
|
|
180
180
|
witness: WitnessCouncil | null = null,
|
|
181
181
|
consensus: ConsensusSuspension = DEFAULT_CONSENSUS,
|
|
182
182
|
): CaptureCheck => {
|
|
183
|
-
const filed = filings(
|
|
183
|
+
const filed = filings(log);
|
|
184
184
|
|
|
185
185
|
const witnessFiled =
|
|
186
186
|
witness?.enabled === true &&
|
|
@@ -193,7 +193,7 @@ export const checkCapture = (
|
|
|
193
193
|
operators: operatorCount,
|
|
194
194
|
required: 1,
|
|
195
195
|
by_witness: true,
|
|
196
|
-
reason: 'a designated
|
|
196
|
+
reason: 'a designated witness has filed',
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -229,30 +229,30 @@ export const checkCapture = (
|
|
|
229
229
|
/* -------------------------------------------------------------------------- */
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
|
-
* Suspend the session for
|
|
232
|
+
* Suspend the session for misconduct.
|
|
233
233
|
*
|
|
234
|
-
* Suspends rather than
|
|
234
|
+
* Suspends rather than closes, deliberately. A closed session is sealed
|
|
235
235
|
* and archived — which is precisely what a captured AUTHORITY would want, since
|
|
236
236
|
* it stops the record before more evidence accumulates. Suspension keeps the
|
|
237
|
-
* proceeding open and the
|
|
237
|
+
* proceeding open and the record live. `closeSession()` already refuses a session
|
|
238
238
|
* in this state.
|
|
239
239
|
*/
|
|
240
|
-
export const
|
|
240
|
+
export const suspendForMisconduct = (
|
|
241
241
|
check: CaptureCheck,
|
|
242
242
|
at: string,
|
|
243
243
|
state: SessionStateFile,
|
|
244
|
-
|
|
244
|
+
log: string,
|
|
245
245
|
): {
|
|
246
|
-
readonly entry:
|
|
247
|
-
readonly
|
|
246
|
+
readonly entry: RecordEntry;
|
|
247
|
+
readonly log: string;
|
|
248
248
|
readonly state: SessionStateFile;
|
|
249
249
|
} => {
|
|
250
250
|
if (!check.triggered) {
|
|
251
|
-
throw new
|
|
251
|
+
throw new MisconductError(`threshold not met — ${check.reason}`);
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
const entry:
|
|
255
|
-
type: '
|
|
254
|
+
const entry: RecordEntry = {
|
|
255
|
+
type: 'MISCONDUCT',
|
|
256
256
|
at,
|
|
257
257
|
// The engine files this, not an actor: it is the mechanical consequence of
|
|
258
258
|
// filings already attributed above, and attributing it to any participant
|
|
@@ -264,7 +264,7 @@ export const suspendForCrisis = (
|
|
|
264
264
|
Filings: `${check.filed} of ${check.operators} OPERATOR actors`,
|
|
265
265
|
Threshold: String(check.required),
|
|
266
266
|
'Session status': 'SUSPENDED — resumption requires external review',
|
|
267
|
-
Resolution: 'a human AUTHORITY above this node must review the
|
|
267
|
+
Resolution: 'a human AUTHORITY above this node must review the record and rule',
|
|
268
268
|
},
|
|
269
269
|
body:
|
|
270
270
|
'The session is suspended. No further acts may be taken under a contested constitution. ' +
|
|
@@ -273,18 +273,18 @@ export const suspendForCrisis = (
|
|
|
273
273
|
|
|
274
274
|
return {
|
|
275
275
|
entry,
|
|
276
|
-
|
|
276
|
+
log: appendEntry(log, entry),
|
|
277
277
|
state: createState({
|
|
278
278
|
session_guid: state.session_guid,
|
|
279
279
|
protocol: state.protocol,
|
|
280
280
|
state: 'SUSPENDED',
|
|
281
281
|
quorum: state.quorum,
|
|
282
|
-
|
|
282
|
+
log_head: state.log_head,
|
|
283
283
|
updated_at: at,
|
|
284
284
|
suspension: {
|
|
285
|
-
cause: '
|
|
285
|
+
cause: 'MISCONDUCT',
|
|
286
286
|
since: at,
|
|
287
|
-
record_ref: '
|
|
287
|
+
record_ref: 'LOG.md',
|
|
288
288
|
escalation_ref: null,
|
|
289
289
|
},
|
|
290
290
|
}),
|
|
@@ -295,24 +295,24 @@ export const suspendForCrisis = (
|
|
|
295
295
|
/* External review */
|
|
296
296
|
/* -------------------------------------------------------------------------- */
|
|
297
297
|
|
|
298
|
-
export type
|
|
298
|
+
export type MisconductRuling = 'UPHELD' | 'DISMISSED';
|
|
299
299
|
|
|
300
300
|
export interface ExternalReviewInput {
|
|
301
301
|
readonly at: string;
|
|
302
302
|
/** The external reviewer — a human from outside this session. */
|
|
303
303
|
readonly reviewer: string;
|
|
304
|
-
/** The
|
|
304
|
+
/** The owner the misconduct was filed against. */
|
|
305
305
|
readonly accused: string;
|
|
306
|
-
readonly ruling:
|
|
306
|
+
readonly ruling: MisconductRuling;
|
|
307
307
|
readonly reasons: string;
|
|
308
308
|
readonly state: SessionStateFile;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
/**
|
|
312
|
-
* Resolve a
|
|
312
|
+
* Resolve a misconduct by external review.
|
|
313
313
|
*
|
|
314
314
|
* The one rule that makes this mechanism worth anything: **the accused may not
|
|
315
|
-
* rule on their own
|
|
315
|
+
* rule on their own misconduct.** An owner who could dismiss the filings against
|
|
316
316
|
* themselves would convert the whole apparatus into a formality that launders
|
|
317
317
|
* capture as due process.
|
|
318
318
|
*
|
|
@@ -322,28 +322,28 @@ export interface ExternalReviewInput {
|
|
|
322
322
|
*/
|
|
323
323
|
export const externalReview = (
|
|
324
324
|
input: ExternalReviewInput,
|
|
325
|
-
|
|
325
|
+
log: string,
|
|
326
326
|
): {
|
|
327
|
-
readonly entry:
|
|
328
|
-
readonly
|
|
327
|
+
readonly entry: RecordEntry;
|
|
328
|
+
readonly log: string;
|
|
329
329
|
readonly state: SessionStateFile;
|
|
330
330
|
} => {
|
|
331
|
-
if (input.state.suspension?.cause !== '
|
|
332
|
-
throw new
|
|
331
|
+
if (input.state.suspension?.cause !== 'MISCONDUCT') {
|
|
332
|
+
throw new MisconductError('this session is not in misconduct');
|
|
333
333
|
}
|
|
334
334
|
if (input.reviewer === input.accused) {
|
|
335
|
-
throw new
|
|
336
|
-
`${input.reviewer} is the subject of this
|
|
335
|
+
throw new MisconductError(
|
|
336
|
+
`${input.reviewer} is the subject of this misconduct and may not rule on it`,
|
|
337
337
|
);
|
|
338
338
|
}
|
|
339
339
|
if (input.reasons.trim() === '') {
|
|
340
|
-
throw new
|
|
340
|
+
throw new MisconductError('an external ruling must state its reasons');
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
const upheld = input.ruling === 'UPHELD';
|
|
344
344
|
|
|
345
|
-
const entry:
|
|
346
|
-
type: '
|
|
345
|
+
const entry: RecordEntry = {
|
|
346
|
+
type: 'MISCONDUCT_RULING',
|
|
347
347
|
at: input.at,
|
|
348
348
|
actor: input.reviewer,
|
|
349
349
|
role: 'AUTHORITY',
|
|
@@ -353,26 +353,26 @@ export const externalReview = (
|
|
|
353
353
|
Accused: input.accused,
|
|
354
354
|
'Session status': upheld
|
|
355
355
|
? 'SUSPENDED — the constitution is compromised; this proceeding does not resume'
|
|
356
|
-
: 'CONVENED — filings dismissed, the
|
|
356
|
+
: 'CONVENED — filings dismissed, the session resumes',
|
|
357
357
|
},
|
|
358
358
|
body: input.reasons.trim(),
|
|
359
359
|
};
|
|
360
360
|
|
|
361
361
|
return {
|
|
362
362
|
entry,
|
|
363
|
-
|
|
363
|
+
log: appendEntry(log, entry),
|
|
364
364
|
state: createState({
|
|
365
365
|
session_guid: input.state.session_guid,
|
|
366
366
|
protocol: input.state.protocol,
|
|
367
367
|
state: upheld ? 'SUSPENDED' : 'CONVENED',
|
|
368
368
|
quorum: input.state.quorum,
|
|
369
|
-
|
|
369
|
+
log_head: input.state.log_head,
|
|
370
370
|
updated_at: input.at,
|
|
371
371
|
suspension: upheld
|
|
372
372
|
? {
|
|
373
|
-
cause: '
|
|
373
|
+
cause: 'MISCONDUCT',
|
|
374
374
|
since: input.state.suspension.since,
|
|
375
|
-
record_ref: '
|
|
375
|
+
record_ref: 'LOG.md',
|
|
376
376
|
escalation_ref: null,
|
|
377
377
|
}
|
|
378
378
|
: null,
|
package/src/operator.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* The operator interface (ADR-0010): who is driving the CLI, and what the record
|
|
3
3
|
* should say about it.
|
|
4
4
|
*
|
|
5
|
-
* Politik does not choose a harness — the
|
|
5
|
+
* Politik does not choose a harness — the owner brings their own (Claude Code,
|
|
6
6
|
* Codex, agy, opencode, …). These helpers detect which one is running a command,
|
|
7
|
-
* so a constitutional act can be staged for the
|
|
7
|
+
* so a constitutional act can be staged for the owner's confirmation and every
|
|
8
8
|
* commit can say how it was requested.
|
|
9
9
|
*
|
|
10
10
|
* Detection is best-effort by design. The backstop is the terminal: a command
|
|
@@ -56,11 +56,11 @@ export const requestedVia = (env: Env, interactive: boolean): string =>
|
|
|
56
56
|
* Whether a person is plausibly typing at this process: a terminal on stdin and
|
|
57
57
|
* no harness in the environment. Anything else is automated.
|
|
58
58
|
*/
|
|
59
|
-
export const
|
|
59
|
+
export const isOwnerAtTerminal = (env: Env, interactive: boolean): boolean =>
|
|
60
60
|
interactive && detectHarness(env) === null;
|
|
61
61
|
|
|
62
|
-
/** The trailer value recorded when a staged act was confirmed by the
|
|
63
|
-
export const
|
|
62
|
+
/** The trailer value recorded when a staged act was confirmed by the owner. */
|
|
63
|
+
export const CONFIRMED_BY_OWNER = 'owner-at-terminal';
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Git trailers appended to every governance commit.
|