@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/pending.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pending acts — the
|
|
2
|
+
* Pending acts — the owner's confirmation (ADR-0010 §2).
|
|
3
3
|
*
|
|
4
|
-
* Under `
|
|
5
|
-
*
|
|
6
|
-
* here, and only `politik confirm <id>`, run by the
|
|
4
|
+
* Under `owner_confirmation: required`, a constitutional act (enact, rule,
|
|
5
|
+
* close) requested by an AI harness or a script is not executed. It is staged
|
|
6
|
+
* here, and only `politik confirm <id>`, run by the owner at a terminal,
|
|
7
7
|
* executes it. Nothing staged ever reaches the record: these files live under
|
|
8
8
|
* `.politik/pending/`, which no governance commit stages, and are deleted once
|
|
9
9
|
* confirmed or rejected.
|
|
@@ -16,15 +16,15 @@ import { mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/promise
|
|
|
16
16
|
import { join } from 'node:path';
|
|
17
17
|
import { deletePendingRef, readPendingRefs, syncConfig, writePendingRef } from './remote.ts';
|
|
18
18
|
|
|
19
|
-
/** The acts that exercise the
|
|
20
|
-
export const CONSTITUTIONAL_ACTS = ['
|
|
19
|
+
/** The acts that exercise the owner's constitutional authority. */
|
|
20
|
+
export const CONSTITUTIONAL_ACTS = ['enact', 'rule', 'close'] as const;
|
|
21
21
|
export type ConstitutionalAct = (typeof CONSTITUTIONAL_ACTS)[number];
|
|
22
22
|
|
|
23
23
|
export const isConstitutionalAct = (name: string): name is ConstitutionalAct =>
|
|
24
24
|
(CONSTITUTIONAL_ACTS as readonly string[]).includes(name);
|
|
25
25
|
|
|
26
26
|
export interface PendingAct {
|
|
27
|
-
/** Short id the
|
|
27
|
+
/** Short id the owner types to confirm, e.g. `enact-3f9a2c`. */
|
|
28
28
|
readonly id: string;
|
|
29
29
|
readonly act: ConstitutionalAct;
|
|
30
30
|
/** The exact arguments, replayed verbatim by `politik confirm`. */
|
|
@@ -58,8 +58,8 @@ const newId = (act: ConstitutionalAct): string => `${act}-${randomBytes(3).toStr
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Stage an act. In a shared session (ADR-0011) it is pushed as a pending ref so
|
|
61
|
-
* the
|
|
62
|
-
* is never staged where the
|
|
61
|
+
* the owner sees it from any machine; throws if it cannot be shared, so an act
|
|
62
|
+
* is never staged where the owner cannot reach it. Otherwise it is written
|
|
63
63
|
* atomically to `.politik/pending/`.
|
|
64
64
|
*/
|
|
65
65
|
export const stagePending = async (
|
package/src/projection.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* SCM projection — governance acts projected onto a hosting platform.
|
|
3
3
|
*
|
|
4
4
|
* A Politik session is a git repository. That much is mandatory: the Charter,
|
|
5
|
-
* the
|
|
5
|
+
* the record, STATE.json and the audit trail all live there, and a session
|
|
6
6
|
* without git has no substrate.
|
|
7
7
|
*
|
|
8
8
|
* A **provider** is optional, and this module is the seam. When one is
|
|
9
9
|
* configured, governance acts are additionally projected onto the platform —
|
|
10
|
-
* a Motion becomes a Pull Request, a
|
|
10
|
+
* a Motion becomes a Pull Request, a vote becomes a review request, an
|
|
11
11
|
* Escalation becomes an Issue. When none is configured the session is complete
|
|
12
12
|
* and correct without them.
|
|
13
13
|
*
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
*
|
|
21
21
|
* Both hold under this split: git is the session, the platform is a projection
|
|
22
22
|
* of it. Local sessions get the whole governance model; hosted sessions also
|
|
23
|
-
* get the platform objects. Nothing about a
|
|
23
|
+
* get the platform objects. Nothing about a vote changes because it was
|
|
24
24
|
* mirrored to a review.
|
|
25
25
|
*
|
|
26
26
|
* ## The rule this module exists to keep
|
|
27
27
|
*
|
|
28
|
-
* **A projection failure must never invalidate a governance act.** The
|
|
28
|
+
* **A projection failure must never invalidate a governance act.** The record
|
|
29
29
|
* is the record. If a Motion carried and the merge call fails, the Motion still
|
|
30
30
|
* carried — the projection is behind, not the decision. Every function here
|
|
31
31
|
* therefore reports what happened and refuses to throw its caller's governance
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
37
|
import type { MergeStrategy } from './canon.ts';
|
|
38
|
-
import { parseEntries, type
|
|
38
|
+
import { parseEntries, type RecordEntry } from './log.ts';
|
|
39
39
|
import { GitHubProvider } from './providers/github.ts';
|
|
40
40
|
import type { ScmProvider } from './scm.ts';
|
|
41
41
|
|
|
@@ -103,14 +103,14 @@ export const resolveProvider = (
|
|
|
103
103
|
/**
|
|
104
104
|
* The platform object a Motion is projected onto.
|
|
105
105
|
*
|
|
106
|
-
* Read back from the
|
|
106
|
+
* Read back from the record rather than held in a side table: the record is
|
|
107
107
|
* the register, exactly as it is for actor seats. A Motion tabled before a
|
|
108
108
|
* provider was configured simply has no link, which is a legitimate state.
|
|
109
109
|
*/
|
|
110
|
-
export const motionPr = (
|
|
110
|
+
export const motionPr = (log: string, motion: string): number | null => {
|
|
111
111
|
// Latest link wins: a Motion re-projected after a branch was recreated should
|
|
112
112
|
// resolve to its current pull request, not its first.
|
|
113
|
-
for (const entry of [...parseEntries(
|
|
113
|
+
for (const entry of [...parseEntries(log)].reverse()) {
|
|
114
114
|
if (entry.fields['Motion'] !== motion) continue;
|
|
115
115
|
const pr = entry.fields['Pull request'];
|
|
116
116
|
if (pr === undefined) continue;
|
|
@@ -126,7 +126,7 @@ export const linkEntry = (
|
|
|
126
126
|
pr: number,
|
|
127
127
|
url: string,
|
|
128
128
|
at: string,
|
|
129
|
-
):
|
|
129
|
+
): RecordEntry => ({
|
|
130
130
|
type: 'MOTION_PROJECTED',
|
|
131
131
|
at,
|
|
132
132
|
actor: 'RECORD',
|
|
@@ -136,7 +136,7 @@ export const linkEntry = (
|
|
|
136
136
|
'Pull request': `#${pr}`,
|
|
137
137
|
Location: url,
|
|
138
138
|
},
|
|
139
|
-
body: 'The Motion is projected onto the hosting platform. The
|
|
139
|
+
body: 'The Motion is projected onto the hosting platform. The record remains the record.',
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
/* -------------------------------------------------------------------------- */
|
|
@@ -164,7 +164,7 @@ const skipped = (reason: string): ProjectionResult => ({
|
|
|
164
164
|
* Deliberately swallows the error. A governance act has already been decided
|
|
165
165
|
* and recorded by the time a projection runs; letting a network fault propagate
|
|
166
166
|
* would abort a caller that has nothing left to undo, and would make the
|
|
167
|
-
*
|
|
167
|
+
* record's correctness depend on GitHub being reachable.
|
|
168
168
|
*/
|
|
169
169
|
const attempt = async (
|
|
170
170
|
what: string,
|
|
@@ -182,39 +182,39 @@ const attempt = async (
|
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
184
|
|
|
185
|
-
/** Project a called
|
|
186
|
-
export const
|
|
185
|
+
/** Project a called vote onto a review request. */
|
|
186
|
+
export const projectBallot = async (
|
|
187
187
|
provider: ScmProvider | null,
|
|
188
|
-
|
|
188
|
+
log: string,
|
|
189
189
|
motion: string,
|
|
190
190
|
reviewers: readonly string[],
|
|
191
191
|
): Promise<ProjectionResult> => {
|
|
192
192
|
if (provider === null) return skipped('local-only — no review requested');
|
|
193
|
-
const pr = motionPr(
|
|
193
|
+
const pr = motionPr(log, motion);
|
|
194
194
|
if (pr === null) return skipped(`${motion} is not projected onto a pull request`);
|
|
195
195
|
if (reviewers.length === 0) return skipped('no reviewers named');
|
|
196
196
|
|
|
197
197
|
return attempt('requestReview', async () => {
|
|
198
|
-
const
|
|
199
|
-
return { ref:
|
|
198
|
+
const vote = await provider.requestReview(pr, reviewers);
|
|
199
|
+
return { ref: vote.url, detail: `review requested on #${pr}` };
|
|
200
200
|
});
|
|
201
201
|
};
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
|
-
* Project an
|
|
204
|
+
* Project an enactment onto a merge — the act ADR-0004 defines Enactment as.
|
|
205
205
|
*
|
|
206
|
-
* The
|
|
207
|
-
* reaches the world. Until it was wired, `politik
|
|
206
|
+
* The vote decides and the enactment enacts; this is where enactment actually
|
|
207
|
+
* reaches the world. Until it was wired, `politik enact` recorded a decision
|
|
208
208
|
* that changed nothing.
|
|
209
209
|
*/
|
|
210
|
-
export const
|
|
210
|
+
export const projectEnactment = async (
|
|
211
211
|
provider: ScmProvider | null,
|
|
212
|
-
|
|
212
|
+
log: string,
|
|
213
213
|
motion: string,
|
|
214
214
|
strategy: MergeStrategy,
|
|
215
215
|
): Promise<ProjectionResult> => {
|
|
216
216
|
if (provider === null) return skipped('local-only — nothing to merge');
|
|
217
|
-
const pr = motionPr(
|
|
217
|
+
const pr = motionPr(log, motion);
|
|
218
218
|
if (pr === null) return skipped(`${motion} is not projected onto a pull request`);
|
|
219
219
|
|
|
220
220
|
return attempt('merge', async () => {
|
|
@@ -233,7 +233,7 @@ export const projectEscalation = async (
|
|
|
233
233
|
provider: ScmProvider | null,
|
|
234
234
|
title: string,
|
|
235
235
|
body: string,
|
|
236
|
-
labels: readonly string[] = ['
|
|
236
|
+
labels: readonly string[] = ['escalation'],
|
|
237
237
|
): Promise<ProjectionResult> => {
|
|
238
238
|
if (provider === null) return skipped('local-only — no issue opened');
|
|
239
239
|
|
|
@@ -243,7 +243,7 @@ export const projectEscalation = async (
|
|
|
243
243
|
});
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
-
/** Notify the
|
|
246
|
+
/** Notify the owner out of band. */
|
|
247
247
|
export const projectNotification = async (
|
|
248
248
|
provider: ScmProvider | null,
|
|
249
249
|
actor: string,
|
|
@@ -256,13 +256,13 @@ export const projectNotification = async (
|
|
|
256
256
|
});
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
-
/** Close the
|
|
260
|
-
export const
|
|
259
|
+
/** Close the session's milestone as part of closing. */
|
|
260
|
+
export const projectClose = async (
|
|
261
261
|
provider: ScmProvider | null,
|
|
262
262
|
milestoneId: string | null,
|
|
263
263
|
): Promise<ProjectionResult> => {
|
|
264
264
|
if (provider === null) return skipped('local-only — no milestone closed');
|
|
265
|
-
if (milestoneId === null) return skipped('no milestone declared for this
|
|
265
|
+
if (milestoneId === null) return skipped('no milestone declared for this session');
|
|
266
266
|
return attempt('closeMilestone', async () => {
|
|
267
267
|
await provider.closeMilestone(milestoneId);
|
|
268
268
|
return { ref: milestoneId, detail: `milestone ${milestoneId} closed` };
|
|
@@ -270,7 +270,7 @@ export const projectProrogation = async (
|
|
|
270
270
|
};
|
|
271
271
|
|
|
272
272
|
/**
|
|
273
|
-
* Record a projection outcome in the
|
|
273
|
+
* Record a projection outcome in the record.
|
|
274
274
|
*
|
|
275
275
|
* Both outcomes are recorded, including failures. A reader must be able to see
|
|
276
276
|
* that a Motion carried and its merge did not land — the gap between decision
|
|
@@ -280,7 +280,7 @@ export const projectionEntry = (
|
|
|
280
280
|
act: string,
|
|
281
281
|
result: ProjectionResult,
|
|
282
282
|
at: string,
|
|
283
|
-
):
|
|
283
|
+
): RecordEntry => ({
|
|
284
284
|
type: result.projected ? 'PROJECTION' : 'PROJECTION_SKIPPED',
|
|
285
285
|
at,
|
|
286
286
|
actor: 'RECORD',
|
package/src/protocol-sdk.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `parseProtocol` answers "is this manifest loadable?". The linter answers a
|
|
5
5
|
* different and stricter question: "is this manifest *coherent*?" — does it
|
|
6
6
|
* translate terms CANON actually has, are its behavioural flags consistent with
|
|
7
|
-
* its declared mode, and will a Charter written against it survive
|
|
7
|
+
* its declared mode, and will a Charter written against it survive session opening.
|
|
8
8
|
*
|
|
9
9
|
* A loadable manifest can still be incoherent. `mode: darwinist` with
|
|
10
10
|
* `no_escalation: false` loads cleanly and then produces a session that accepts
|
|
@@ -17,7 +17,6 @@ import { PRIMITIVES, ROLES, VERBS, type Role } from './canon.ts';
|
|
|
17
17
|
import {
|
|
18
18
|
parseProtocol,
|
|
19
19
|
type Protocol,
|
|
20
|
-
type ProtocolMode,
|
|
21
20
|
} from './protocol.ts';
|
|
22
21
|
|
|
23
22
|
/* -------------------------------------------------------------------------- */
|
|
@@ -37,27 +36,6 @@ export interface LintResult {
|
|
|
37
36
|
readonly findings: readonly LintFinding[];
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
/** Every CANON term a protocol may legitimately translate. */
|
|
41
|
-
const TRANSLATABLE: readonly string[] = Object.freeze([...PRIMITIVES, ...VERBS]);
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Behavioural expectations implied by each mode.
|
|
45
|
-
*
|
|
46
|
-
* These are *warnings*, not errors: the architecture describes modes as
|
|
47
|
-
* families, not as constraints, and a protocol author may have a reason. But a
|
|
48
|
-
* mismatch is nearly always a mistake, and silently shipping one produces
|
|
49
|
-
* sessions that behave unlike every sibling protocol in their family.
|
|
50
|
-
*/
|
|
51
|
-
const MODE_EXPECTATIONS: Readonly<
|
|
52
|
-
Record<ProtocolMode, { no_escalation?: boolean; no_record?: boolean; immutable_charter?: boolean }>
|
|
53
|
-
> = Object.freeze({
|
|
54
|
-
constitutional: { no_escalation: false, no_record: false },
|
|
55
|
-
authoritarian: { no_record: false },
|
|
56
|
-
darwinist: { no_record: false },
|
|
57
|
-
ephemeral: { no_record: true },
|
|
58
|
-
immutable: { immutable_charter: true },
|
|
59
|
-
});
|
|
60
|
-
|
|
61
39
|
/**
|
|
62
40
|
* Lint a protocol manifest against CANON.
|
|
63
41
|
*
|
|
@@ -82,74 +60,7 @@ export const lintProtocol = (protocol: Protocol): LintResult => {
|
|
|
82
60
|
});
|
|
83
61
|
}
|
|
84
62
|
|
|
85
|
-
// Translating a term CANON does not have is always an error: it will never be
|
|
86
|
-
// looked up, so it is dead vocabulary that misleads whoever reads the file.
|
|
87
|
-
for (const key of Object.keys(protocol.primitives)) {
|
|
88
|
-
if (!TRANSLATABLE.includes(key)) {
|
|
89
|
-
findings.push({
|
|
90
|
-
severity: 'error',
|
|
91
|
-
field: `primitives.${key}`,
|
|
92
|
-
message: 'not a CANON primitive or verb — this term will never be used',
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
for (const role of ROLES) {
|
|
98
|
-
if (protocol.roles[role] === undefined) {
|
|
99
|
-
findings.push({
|
|
100
|
-
severity: 'warning',
|
|
101
|
-
field: `roles.${role}`,
|
|
102
|
-
message: 'unmapped — falls back to the CANON term',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Duplicate role terms make the interface ambiguous: two constituencies would
|
|
108
|
-
// render identically and a human could not tell which one acted.
|
|
109
|
-
const seen = new Map<string, Role>();
|
|
110
|
-
for (const role of ROLES) {
|
|
111
|
-
const label = protocol.roles[role];
|
|
112
|
-
if (label === undefined) continue;
|
|
113
|
-
const prior = seen.get(label.toLowerCase());
|
|
114
|
-
if (prior !== undefined) {
|
|
115
|
-
findings.push({
|
|
116
|
-
severity: 'error',
|
|
117
|
-
field: `roles.${role}`,
|
|
118
|
-
message: `duplicate term "${label}" — already maps ${prior}`,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
seen.set(label.toLowerCase(), role);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const expectations = MODE_EXPECTATIONS[protocol.mode];
|
|
125
|
-
for (const [flag, expected] of Object.entries(expectations)) {
|
|
126
|
-
const actual = protocol[flag as 'no_escalation' | 'no_record' | 'immutable_charter'];
|
|
127
|
-
if (actual !== expected) {
|
|
128
|
-
findings.push({
|
|
129
|
-
severity: 'warning',
|
|
130
|
-
field: flag,
|
|
131
|
-
message: `${protocol.mode} protocols normally set ${flag}: ${String(expected)}`,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
63
|
// A recording protocol whose record evaporates is self-contradictory.
|
|
137
|
-
if (protocol.record_mode === 'ephemeral' && !protocol.no_record) {
|
|
138
|
-
findings.push({
|
|
139
|
-
severity: 'error',
|
|
140
|
-
field: 'record_mode',
|
|
141
|
-
message: 'ephemeral record_mode requires no_record: true — the record cannot both persist and not',
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (protocol.no_record && protocol.record_mode !== 'ephemeral') {
|
|
146
|
-
findings.push({
|
|
147
|
-
severity: 'warning',
|
|
148
|
-
field: 'no_record',
|
|
149
|
-
message: `no_record: true with record_mode: ${protocol.record_mode} — expected ephemeral`,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
64
|
// AUTHORITY holding a domain veto is redundant: AUTHORITY already holds VETO
|
|
154
65
|
// as a constitutional power. Declaring it says less than it appears to.
|
|
155
66
|
if (protocol.domain_veto.includes('AUTHORITY')) {
|
|
@@ -185,7 +96,7 @@ export const lintSource = (source: string): LintResult => {
|
|
|
185
96
|
field: w.field,
|
|
186
97
|
message: w.message,
|
|
187
98
|
})),
|
|
188
|
-
...result.findings
|
|
99
|
+
...result.findings,
|
|
189
100
|
],
|
|
190
101
|
};
|
|
191
102
|
};
|
|
@@ -196,53 +107,33 @@ export const lintSource = (source: string): LintResult => {
|
|
|
196
107
|
|
|
197
108
|
export interface GenerateOptions {
|
|
198
109
|
readonly name: string;
|
|
199
|
-
readonly mode?: ProtocolMode;
|
|
200
|
-
readonly roles?: Readonly<Partial<Record<Role, string>>>;
|
|
201
110
|
}
|
|
202
111
|
|
|
203
112
|
/**
|
|
204
113
|
* Generate a protocol manifest skeleton.
|
|
205
114
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* file rather than something to be discovered from documentation.
|
|
115
|
+
* A protocol is its rules: mechanics and behavioural flags. There is no
|
|
116
|
+
* vocabulary to translate — every protocol speaks CANON.
|
|
209
117
|
*/
|
|
210
118
|
export const generateProtocol = (options: GenerateOptions): string => {
|
|
211
|
-
const mode = options.mode ?? 'constitutional';
|
|
212
|
-
const expectations = MODE_EXPECTATIONS[mode];
|
|
213
|
-
|
|
214
|
-
const roleLines = ROLES.map(
|
|
215
|
-
(role) => ` ${role}: ${options.roles?.[role] ?? role}`,
|
|
216
|
-
).join('\n');
|
|
217
|
-
|
|
218
|
-
const primitiveLines = PRIMITIVES.map((p) => ` ${p}: ${p}`).join('\n');
|
|
219
|
-
const verbLines = VERBS.map((v) => ` ${v}: ${v}`).join('\n');
|
|
220
|
-
|
|
221
119
|
return `# ${options.name} — protocol manifest.
|
|
222
120
|
#
|
|
223
|
-
# Generated skeleton.
|
|
224
|
-
# domain's vocabulary; delete any line you want to fall back to the CANON term.
|
|
121
|
+
# Generated skeleton. Set the rules; a protocol has no vocabulary of its own.
|
|
225
122
|
#
|
|
226
123
|
# Lint before shipping: politik protocol lint protocols/${options.name}.yml
|
|
227
124
|
|
|
228
125
|
protocol:
|
|
229
126
|
name: ${options.name}
|
|
230
127
|
version: 0.1.0
|
|
231
|
-
mode: ${mode}
|
|
232
128
|
record_mode: anchored
|
|
233
129
|
|
|
234
|
-
roles:
|
|
235
|
-
${roleLines}
|
|
236
|
-
|
|
237
|
-
primitives:
|
|
238
|
-
${primitiveLines}
|
|
239
|
-
|
|
240
|
-
# Verbs
|
|
241
|
-
${verbLines}
|
|
242
|
-
|
|
243
130
|
domain_veto: []
|
|
244
|
-
no_escalation:
|
|
245
|
-
|
|
246
|
-
|
|
131
|
+
no_escalation: false
|
|
132
|
+
immutable_charter: false
|
|
133
|
+
|
|
134
|
+
mechanics:
|
|
135
|
+
resolution: majority # majority | supermajority | unanimity | owner | both-sides
|
|
136
|
+
exit: vote # owner | vote | elimination | none
|
|
137
|
+
termination: objective # objective | last-standing | verdict
|
|
247
138
|
`;
|
|
248
139
|
};
|
package/src/protocol.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* (POLITIK-ARCHITECTURE.md § Protocol Schema Format).
|
|
12
12
|
*
|
|
13
13
|
* Translation is presentation only. Nothing here changes engine behaviour: a
|
|
14
|
-
*
|
|
14
|
+
* BALLOT is a BALLOT whether it renders as "vote" or "Sprint Review".
|
|
15
15
|
* The four behavioural flags below are the sole exception, and they are
|
|
16
16
|
* declared, never inferred.
|
|
17
17
|
*
|
|
@@ -26,41 +26,24 @@ import { isRole, ROLES, type Primitive, type Role, type Verb } from './canon.ts'
|
|
|
26
26
|
/* Schema */
|
|
27
27
|
/* -------------------------------------------------------------------------- */
|
|
28
28
|
|
|
29
|
-
export const
|
|
30
|
-
'constitutional',
|
|
31
|
-
'authoritarian',
|
|
32
|
-
'darwinist',
|
|
33
|
-
'ephemeral',
|
|
34
|
-
'immutable',
|
|
35
|
-
] as const;
|
|
36
|
-
|
|
37
|
-
export type ProtocolMode = (typeof PROTOCOL_MODES)[number];
|
|
38
|
-
|
|
39
|
-
export const RECORD_MODES = ['distributed', 'anchored', 'ephemeral'] as const;
|
|
29
|
+
export const RECORD_MODES = ['distributed', 'anchored'] as const;
|
|
40
30
|
|
|
41
31
|
export type ProtocolRecordMode = (typeof RECORD_MODES)[number];
|
|
42
32
|
|
|
43
33
|
export interface Protocol {
|
|
44
34
|
readonly name: string;
|
|
45
35
|
readonly version: string;
|
|
46
|
-
readonly mode: ProtocolMode;
|
|
47
36
|
readonly record_mode: ProtocolRecordMode;
|
|
48
|
-
/** CANON role -> industry term. Every role should be mapped. */
|
|
49
|
-
readonly roles: Readonly<Partial<Record<Role, string>>>;
|
|
50
|
-
/** CANON primitive or verb -> industry term. Partial by design. */
|
|
51
|
-
readonly primitives: Readonly<Record<string, string>>;
|
|
52
37
|
readonly domain_veto: readonly Role[];
|
|
53
|
-
/** True
|
|
38
|
+
/** True when the protocol allows no appeals: escalation is refused. */
|
|
54
39
|
readonly no_escalation: boolean;
|
|
55
|
-
/** True
|
|
56
|
-
readonly no_record: boolean;
|
|
57
|
-
/** True when Standing Orders cannot be amended mid-session. */
|
|
40
|
+
/** True when Charter cannot be amended mid-session. */
|
|
58
41
|
readonly immutable_charter: boolean;
|
|
59
42
|
/**
|
|
60
43
|
* Protocol override points (ADR-0007), declared so a Charter can inherit them.
|
|
61
44
|
* Kept as plain strings here: the manifest declares a protocol's default
|
|
62
|
-
* behavior, and the Charter — validated strictly at
|
|
63
|
-
* authority. Defaults
|
|
45
|
+
* behavior, and the Charter — validated strictly at session opening — is the runtime
|
|
46
|
+
* authority. Defaults are the default protocol's rules.
|
|
64
47
|
*/
|
|
65
48
|
readonly mechanics: {
|
|
66
49
|
readonly resolution: string;
|
|
@@ -131,14 +114,6 @@ export const parseProtocol = (source: string): ProtocolParseResult => {
|
|
|
131
114
|
const name = typeof block['name'] === 'string' ? block['name'] : '';
|
|
132
115
|
if (name === '') issues.push({ field: 'name', message: 'required' });
|
|
133
116
|
|
|
134
|
-
const mode = block['mode'];
|
|
135
|
-
if (!(PROTOCOL_MODES as readonly unknown[]).includes(mode)) {
|
|
136
|
-
issues.push({
|
|
137
|
-
field: 'mode',
|
|
138
|
-
message: `must be one of ${PROTOCOL_MODES.join(' | ')}`,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
117
|
const recordMode = block['record_mode'];
|
|
143
118
|
if (!(RECORD_MODES as readonly unknown[]).includes(recordMode)) {
|
|
144
119
|
issues.push({
|
|
@@ -147,18 +122,6 @@ export const parseProtocol = (source: string): ProtocolParseResult => {
|
|
|
147
122
|
});
|
|
148
123
|
}
|
|
149
124
|
|
|
150
|
-
const roleMap = stringMap(block['roles']);
|
|
151
|
-
const roles: Partial<Record<Role, string>> = {};
|
|
152
|
-
for (const [key, value] of Object.entries(roleMap)) {
|
|
153
|
-
if (isRole(key)) roles[key] = value;
|
|
154
|
-
else issues.push({ field: `roles.${key}`, message: 'not a CANON role' });
|
|
155
|
-
}
|
|
156
|
-
for (const role of ROLES) {
|
|
157
|
-
if (roles[role] === undefined) {
|
|
158
|
-
warnings.push({ field: `roles.${role}`, message: 'unmapped — falls back to the CANON term' });
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
125
|
const domain_veto: Role[] = [];
|
|
163
126
|
if (Array.isArray(block['domain_veto'])) {
|
|
164
127
|
for (const entry of block['domain_veto']) {
|
|
@@ -167,17 +130,6 @@ export const parseProtocol = (source: string): ProtocolParseResult => {
|
|
|
167
130
|
}
|
|
168
131
|
}
|
|
169
132
|
|
|
170
|
-
const no_record = block['no_record'] === true;
|
|
171
|
-
|
|
172
|
-
// An ephemeral record mode and a recording protocol are contradictory. The
|
|
173
|
-
// Hansard either exists or it does not; a manifest cannot have it both ways.
|
|
174
|
-
if (recordMode === 'ephemeral' && !no_record) {
|
|
175
|
-
warnings.push({
|
|
176
|
-
field: 'record_mode',
|
|
177
|
-
message: 'ephemeral record_mode with no_record: false — the record will not persist',
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
133
|
if (issues.length > 0) return { ok: false, issues };
|
|
182
134
|
|
|
183
135
|
return {
|
|
@@ -186,13 +138,9 @@ export const parseProtocol = (source: string): ProtocolParseResult => {
|
|
|
186
138
|
protocol: {
|
|
187
139
|
name,
|
|
188
140
|
version: typeof block['version'] === 'string' ? block['version'] : '0.0.0',
|
|
189
|
-
mode: mode as ProtocolMode,
|
|
190
141
|
record_mode: recordMode as ProtocolRecordMode,
|
|
191
|
-
roles,
|
|
192
|
-
primitives: stringMap(block['primitives']),
|
|
193
142
|
domain_veto,
|
|
194
143
|
no_escalation: block['no_escalation'] === true,
|
|
195
|
-
no_record,
|
|
196
144
|
immutable_charter: block['immutable_charter'] === true,
|
|
197
145
|
mechanics: (() => {
|
|
198
146
|
const m = (typeof block['mechanics'] === 'object' && block['mechanics'] !== null
|
|
@@ -200,7 +148,7 @@ export const parseProtocol = (source: string): ProtocolParseResult => {
|
|
|
200
148
|
: {}) as Record<string, unknown>;
|
|
201
149
|
return {
|
|
202
150
|
resolution: typeof m['resolution'] === 'string' ? m['resolution'] : 'majority',
|
|
203
|
-
exit: typeof m['exit'] === 'string' ? m['exit'] : '
|
|
151
|
+
exit: typeof m['exit'] === 'string' ? m['exit'] : 'vote',
|
|
204
152
|
termination: typeof m['termination'] === 'string' ? m['termination'] : 'objective',
|
|
205
153
|
};
|
|
206
154
|
})(),
|
|
@@ -208,34 +156,16 @@ export const parseProtocol = (source: string): ProtocolParseResult => {
|
|
|
208
156
|
};
|
|
209
157
|
};
|
|
210
158
|
|
|
211
|
-
/* -------------------------------------------------------------------------- */
|
|
212
|
-
/* Translation */
|
|
213
|
-
/* -------------------------------------------------------------------------- */
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Render a CANON role in the protocol's vocabulary.
|
|
217
|
-
* Falls back to the CANON term, which is always readable by design.
|
|
218
|
-
*/
|
|
219
|
-
export const roleTerm = (protocol: Protocol, role: Role): string =>
|
|
220
|
-
protocol.roles[role] ?? role;
|
|
221
|
-
|
|
222
|
-
/** Render a CANON primitive or verb in the protocol's vocabulary. */
|
|
223
|
-
export const term = (protocol: Protocol, canon: Primitive | Verb | string): string =>
|
|
224
|
-
protocol.primitives[canon] ?? canon;
|
|
225
|
-
|
|
226
159
|
/**
|
|
227
160
|
* Does this protocol permit escalation?
|
|
228
161
|
*
|
|
229
|
-
*
|
|
162
|
+
* A protocol with no appeals sets `no_escalation`. An escalation
|
|
230
163
|
* filed under one of those is not a governance event — it is a category error,
|
|
231
164
|
* and the engine must refuse it rather than suspend a session that has no
|
|
232
165
|
* appeal mechanism to resume from.
|
|
233
166
|
*/
|
|
234
167
|
export const allowsEscalation = (protocol: Protocol): boolean => !protocol.no_escalation;
|
|
235
168
|
|
|
236
|
-
/** Does this protocol keep a Hansard? False only for Ephemeral protocols. */
|
|
237
|
-
export const keepsRecord = (protocol: Protocol): boolean => !protocol.no_record;
|
|
238
|
-
|
|
239
169
|
/** May the Charter be amended mid-session? */
|
|
240
170
|
export const allowsCharterAmendment = (protocol: Protocol): boolean =>
|
|
241
171
|
!protocol.immutable_charter;
|
package/src/providers/github.ts
CHANGED
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
|
|
16
16
|
import type { MergeStrategy, Role } from '../canon.ts';
|
|
17
17
|
import type {
|
|
18
|
-
|
|
18
|
+
EnactResult,
|
|
19
19
|
CollaboratorGrant,
|
|
20
20
|
CommitRef,
|
|
21
|
-
|
|
21
|
+
BallotRef,
|
|
22
22
|
EscalationRef,
|
|
23
23
|
FileWrite,
|
|
24
24
|
MotionRef,
|
|
@@ -52,7 +52,7 @@ export interface GitHubProviderOptions {
|
|
|
52
52
|
* GitHub describes repository capability, and they are not the same axis.
|
|
53
53
|
* The mapping is deliberately conservative — OPERATOR and MEMBER both receive
|
|
54
54
|
* `push` because the Charter, not the SCM ACL, is what separates their verbs.
|
|
55
|
-
* Governance is enforced in the
|
|
55
|
+
* Governance is enforced in the record; this is only the coarse outer gate.
|
|
56
56
|
*/
|
|
57
57
|
export const ROLE_PERMISSIONS: Readonly<Record<Role, string>> = Object.freeze({
|
|
58
58
|
AUTHORITY: 'admin',
|
|
@@ -147,8 +147,8 @@ export class GitHubProvider implements ScmProvider {
|
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
149
|
* Write files as a single commit via the git data API: blobs -> tree ->
|
|
150
|
-
* commit -> ref update. One commit for the whole file set, because a
|
|
151
|
-
* Drop that lands as eight separate commits is eight
|
|
150
|
+
* commit -> ref update. One commit for the whole file set, because a Opening
|
|
151
|
+
* Drop that lands as eight separate commits is eight record-visible events
|
|
152
152
|
* for one governance act.
|
|
153
153
|
*/
|
|
154
154
|
async commit(message: string, files: readonly FileWrite[]): Promise<CommitRef> {
|
|
@@ -194,7 +194,7 @@ export class GitHubProvider implements ScmProvider {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
/* ---------------------------------------------------------------------- */
|
|
197
|
-
/* Motions and
|
|
197
|
+
/* Motions and votes */
|
|
198
198
|
/* ---------------------------------------------------------------------- */
|
|
199
199
|
|
|
200
200
|
async openPR(title: string, body: string, branch: string): Promise<MotionRef> {
|
|
@@ -211,7 +211,7 @@ export class GitHubProvider implements ScmProvider {
|
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
async requestReview(pr: number, actors: readonly string[]): Promise<
|
|
214
|
+
async requestReview(pr: number, actors: readonly string[]): Promise<BallotRef> {
|
|
215
215
|
const result = await this.#request<{ html_url: string; id: number }>(
|
|
216
216
|
'POST',
|
|
217
217
|
`${this.#repoPath}/pulls/${pr}/requested_reviewers`,
|
|
@@ -226,13 +226,13 @@ export class GitHubProvider implements ScmProvider {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
/**
|
|
229
|
-
*
|
|
229
|
+
* ENACT — enact a carried Motion.
|
|
230
230
|
*
|
|
231
231
|
* Note: `fast_forward` maps to GitHub's `rebase` method, the closest
|
|
232
232
|
* available behaviour (no merge node). Charter rule 6 already restricts
|
|
233
|
-
* fast_forward to quorum-1 sessions, where no
|
|
233
|
+
* fast_forward to quorum-1 sessions, where no vote needs evidencing.
|
|
234
234
|
*/
|
|
235
|
-
async merge(pr: number, strategy: MergeStrategy): Promise<
|
|
235
|
+
async merge(pr: number, strategy: MergeStrategy): Promise<EnactResult> {
|
|
236
236
|
const result = await this.#request<{ sha: string; merged: boolean; message: string }>(
|
|
237
237
|
'PUT',
|
|
238
238
|
`${this.#repoPath}/pulls/${pr}/merge`,
|
|
@@ -301,8 +301,8 @@ export class GitHubProvider implements ScmProvider {
|
|
|
301
301
|
*
|
|
302
302
|
* GitHub has no direct-message API, so this opens a labelled issue
|
|
303
303
|
* @-mentioning the actor. GitHub's own notification settings turn that into
|
|
304
|
-
* the
|
|
305
|
-
* ("Receives
|
|
304
|
+
* the owner's email — which is the delivery path the architecture assumes
|
|
305
|
+
* ("Receives escalations — SCM Issues + email").
|
|
306
306
|
*/
|
|
307
307
|
async notify(actor: string, message: string): Promise<void> {
|
|
308
308
|
await this.#request('POST', `${this.#repoPath}/issues`, {
|