@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/heartbeat.ts
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* So STALE is its own CANON state and carries no `suspension` — a stale session
|
|
10
10
|
* has no cause to record, only an absence.
|
|
11
11
|
*
|
|
12
|
-
* The heartbeat is the **last
|
|
12
|
+
* The heartbeat is the **last record commit**, not a liveness ping. Nothing
|
|
13
13
|
* separate has to be running: if the record has not moved, nothing happened,
|
|
14
14
|
* and a proceeding in which nothing happens is by definition not proceeding.
|
|
15
15
|
*
|
|
16
16
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { appendEntry, parseEntries, type
|
|
19
|
+
import { appendEntry, parseEntries, type RecordEntry } from './log.ts';
|
|
20
20
|
import { createState, type SessionStateFile } from './state.ts';
|
|
21
21
|
|
|
22
22
|
/* -------------------------------------------------------------------------- */
|
|
@@ -25,7 +25,7 @@ import { createState, type SessionStateFile } from './state.ts';
|
|
|
25
25
|
|
|
26
26
|
export interface HeartbeatCheck {
|
|
27
27
|
readonly stale: boolean;
|
|
28
|
-
/** Last
|
|
28
|
+
/** Last record entry timestamp, or null for an empty record. */
|
|
29
29
|
readonly last_beat: string | null;
|
|
30
30
|
readonly hours_since: number | null;
|
|
31
31
|
readonly timeout_hours: number;
|
|
@@ -38,16 +38,16 @@ export interface HeartbeatCheck {
|
|
|
38
38
|
* `now` is supplied by the caller — this module reads no clock, so a check is
|
|
39
39
|
* reproducible and a test does not have to wait four hours.
|
|
40
40
|
*
|
|
41
|
-
* A session with an empty
|
|
41
|
+
* A session with an empty record is never stale: it has not gone quiet, it has
|
|
42
42
|
* not started. Treating "no record yet" as staleness would suspend every
|
|
43
|
-
* session at the moment of its
|
|
43
|
+
* session at the moment of its session opening.
|
|
44
44
|
*/
|
|
45
45
|
export const checkHeartbeat = (
|
|
46
|
-
|
|
46
|
+
log: string,
|
|
47
47
|
timeoutHours: number,
|
|
48
48
|
now: string,
|
|
49
49
|
): HeartbeatCheck => {
|
|
50
|
-
const entries = parseEntries(
|
|
50
|
+
const entries = parseEntries(log);
|
|
51
51
|
const last = entries.at(-1);
|
|
52
52
|
|
|
53
53
|
if (last === undefined) {
|
|
@@ -56,7 +56,7 @@ export const checkHeartbeat = (
|
|
|
56
56
|
last_beat: null,
|
|
57
57
|
hours_since: null,
|
|
58
58
|
timeout_hours: timeoutHours,
|
|
59
|
-
reason: 'no
|
|
59
|
+
reason: 'no record entries yet — the proceeding has not started',
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -81,7 +81,7 @@ export const checkHeartbeat = (
|
|
|
81
81
|
hours_since: hours,
|
|
82
82
|
timeout_hours: timeoutHours,
|
|
83
83
|
reason: stale
|
|
84
|
-
? `no
|
|
84
|
+
? `no record commit in ${hours.toFixed(1)}h (timeout ${timeoutHours}h)`
|
|
85
85
|
: `last beat ${hours.toFixed(1)}h ago, within the ${timeoutHours}h window`,
|
|
86
86
|
};
|
|
87
87
|
};
|
|
@@ -107,10 +107,10 @@ export const markStale = (
|
|
|
107
107
|
check: HeartbeatCheck,
|
|
108
108
|
at: string,
|
|
109
109
|
state: SessionStateFile,
|
|
110
|
-
|
|
110
|
+
log: string,
|
|
111
111
|
): {
|
|
112
|
-
readonly entry:
|
|
113
|
-
readonly
|
|
112
|
+
readonly entry: RecordEntry;
|
|
113
|
+
readonly log: string;
|
|
114
114
|
readonly state: SessionStateFile;
|
|
115
115
|
} => {
|
|
116
116
|
if (!check.stale) throw new HeartbeatError(`not stale — ${check.reason}`);
|
|
@@ -118,7 +118,7 @@ export const markStale = (
|
|
|
118
118
|
throw new HeartbeatError(`only a CONVENED proceeding can go stale — this is ${state.state}`);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const entry:
|
|
121
|
+
const entry: RecordEntry = {
|
|
122
122
|
type: 'SESSION_STALE',
|
|
123
123
|
at,
|
|
124
124
|
actor: 'RECORD',
|
|
@@ -129,19 +129,19 @@ export const markStale = (
|
|
|
129
129
|
Timeout: `${check.timeout_hours}h`,
|
|
130
130
|
'Session status': 'STALE — auto-suspended, resumable',
|
|
131
131
|
},
|
|
132
|
-
body: 'No
|
|
132
|
+
body: 'No record commit within the heartbeat window. The proceeding is resumable: nothing is lost, and committed work stands.',
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
return {
|
|
136
136
|
entry,
|
|
137
|
-
|
|
137
|
+
log: appendEntry(log, entry),
|
|
138
138
|
state: createState({
|
|
139
139
|
session_guid: state.session_guid,
|
|
140
140
|
protocol: state.protocol,
|
|
141
141
|
// STALE is a state, not a suspension cause — hence no `suspension` here.
|
|
142
142
|
state: 'STALE',
|
|
143
143
|
quorum: state.quorum,
|
|
144
|
-
|
|
144
|
+
log_head: state.log_head,
|
|
145
145
|
updated_at: at,
|
|
146
146
|
}),
|
|
147
147
|
};
|
|
@@ -177,14 +177,14 @@ const section = (title: string, items: readonly string[]): string[] =>
|
|
|
177
177
|
*
|
|
178
178
|
* This is what makes a proceeding survivable. Agents are stateless and
|
|
179
179
|
* disposable; the snapshot is what a *new* agent is given so it can continue
|
|
180
|
-
* work it never started. The
|
|
180
|
+
* work it never started. The record is the session, not the agent process.
|
|
181
181
|
*/
|
|
182
182
|
export const snapshot = (
|
|
183
183
|
data: Snapshot,
|
|
184
184
|
at: string,
|
|
185
185
|
state: SessionStateFile,
|
|
186
|
-
|
|
187
|
-
): { readonly entry:
|
|
186
|
+
log: string,
|
|
187
|
+
): { readonly entry: RecordEntry; readonly log: string } => {
|
|
188
188
|
const body = [
|
|
189
189
|
...section('Completed', data.completed),
|
|
190
190
|
...section('In flight', data.in_flight),
|
|
@@ -198,7 +198,7 @@ export const snapshot = (
|
|
|
198
198
|
`- Motions: ${data.motions}${data.max_motions === null ? '' : ` of ${data.max_motions}`}`,
|
|
199
199
|
].join('\n');
|
|
200
200
|
|
|
201
|
-
const entry:
|
|
201
|
+
const entry: RecordEntry = {
|
|
202
202
|
type: 'STATE_SNAPSHOT',
|
|
203
203
|
at,
|
|
204
204
|
actor: 'RECORD',
|
|
@@ -213,12 +213,12 @@ export const snapshot = (
|
|
|
213
213
|
body,
|
|
214
214
|
};
|
|
215
215
|
|
|
216
|
-
return { entry,
|
|
216
|
+
return { entry, log: appendEntry(log, entry) };
|
|
217
217
|
};
|
|
218
218
|
|
|
219
219
|
/** The most recent STATE_SNAPSHOT, as raw markdown. Null if none exists. */
|
|
220
|
-
export const lastSnapshot = (
|
|
221
|
-
const blocks =
|
|
220
|
+
export const lastSnapshot = (log: string): string | null => {
|
|
221
|
+
const blocks = log.split(/^## /m).slice(1);
|
|
222
222
|
const snapshots = blocks.filter((b) => b.includes('— STATE_SNAPSHOT'));
|
|
223
223
|
const latest = snapshots.at(-1);
|
|
224
224
|
return latest === undefined ? null : `## ${latest.trim()}`;
|
|
@@ -232,7 +232,7 @@ export const lastSnapshot = (hansard: string): string | null => {
|
|
|
232
232
|
* Resume a stale proceeding.
|
|
233
233
|
*
|
|
234
234
|
* Only STALE resumes this way. A SUSPENDED session was stopped by a decision —
|
|
235
|
-
*
|
|
235
|
+
* an escalation, an owner order, a misconduct — and each of
|
|
236
236
|
* those has its own resolution path. Letting `resume` lift them would route
|
|
237
237
|
* around the governance that stopped the session in the first place, which is
|
|
238
238
|
* the single most dangerous shortcut this codebase could offer.
|
|
@@ -241,10 +241,10 @@ export const resume = (
|
|
|
241
241
|
at: string,
|
|
242
242
|
actor: 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 (state.state !== 'STALE') {
|
|
@@ -255,27 +255,27 @@ export const resume = (
|
|
|
255
255
|
);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
const entry:
|
|
258
|
+
const entry: RecordEntry = {
|
|
259
259
|
type: 'SESSION_RESUMED',
|
|
260
260
|
at,
|
|
261
261
|
actor,
|
|
262
262
|
role: 'AUTHORITY',
|
|
263
263
|
fields: {
|
|
264
|
-
'Session status': 'CONVENED — the
|
|
265
|
-
'Resumed from': lastSnapshot(
|
|
264
|
+
'Session status': 'CONVENED — the session resumes',
|
|
265
|
+
'Resumed from': lastSnapshot(log) === null ? 'the record' : 'the last STATE_SNAPSHOT',
|
|
266
266
|
},
|
|
267
267
|
body: 'Agents are stateless; the record is the context. Committed work stands.',
|
|
268
268
|
};
|
|
269
269
|
|
|
270
270
|
return {
|
|
271
271
|
entry,
|
|
272
|
-
|
|
272
|
+
log: appendEntry(log, entry),
|
|
273
273
|
state: createState({
|
|
274
274
|
session_guid: state.session_guid,
|
|
275
275
|
protocol: state.protocol,
|
|
276
276
|
state: 'CONVENED',
|
|
277
277
|
quorum: state.quorum,
|
|
278
|
-
|
|
278
|
+
log_head: state.log_head,
|
|
279
279
|
updated_at: at,
|
|
280
280
|
}),
|
|
281
281
|
};
|
package/src/index.ts
CHANGED
|
@@ -10,26 +10,26 @@ export * from './canon.ts';
|
|
|
10
10
|
export * from './capability.ts';
|
|
11
11
|
export * from './conflict.ts';
|
|
12
12
|
export * from './containment.ts';
|
|
13
|
-
export * from './
|
|
13
|
+
export * from './ballot.ts';
|
|
14
14
|
export * from './doctor.ts';
|
|
15
15
|
export * from './escalation.ts';
|
|
16
16
|
export * from './protocol.ts';
|
|
17
17
|
export * from './protocol-sdk.ts';
|
|
18
18
|
export * from './runner.ts';
|
|
19
19
|
export * from './projection.ts';
|
|
20
|
-
export * from './
|
|
21
|
-
export * from './templates/
|
|
20
|
+
export * from './closing.ts';
|
|
21
|
+
export * from './templates/session.ts';
|
|
22
22
|
export * from './quorum.ts';
|
|
23
23
|
export * from './integrity.ts';
|
|
24
24
|
export * from './election.ts';
|
|
25
25
|
export * from './envelope.ts';
|
|
26
26
|
export * from './fault.ts';
|
|
27
27
|
export * from './git.ts';
|
|
28
|
-
export * from './
|
|
28
|
+
export * from './log.ts';
|
|
29
29
|
export * from './heartbeat.ts';
|
|
30
30
|
export * from './lockfs.ts';
|
|
31
31
|
export * from './charter.ts';
|
|
32
|
-
export * from './
|
|
32
|
+
export * from './misconduct.ts';
|
|
33
33
|
export * from './init.ts';
|
|
34
34
|
export * from './ledger.ts';
|
|
35
35
|
export * from './scm.ts';
|
package/src/init.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session repo initializer — the
|
|
2
|
+
* Session repo initializer — the session opening.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
4
|
+
* The owner drops the Opening; this module produces the initial file set that
|
|
5
5
|
* makes a git repository a Politik session. It is pure: it returns files to be
|
|
6
6
|
* written, and performs no I/O itself. The caller commits them through an
|
|
7
7
|
* ScmProvider, so the same initializer serves GitHub, a local scratch repo, or
|
|
8
8
|
* a test.
|
|
9
9
|
*
|
|
10
10
|
* Layout follows POLITIK-ARCHITECTURE.md § SESSION REPO STRUCTURE. Validation
|
|
11
|
-
* is ADR-0002's
|
|
11
|
+
* is ADR-0002's session opening rules, delegated to the charter module: a Charter
|
|
12
12
|
* that fails opens nothing, and yields an INVALID state file recording why.
|
|
13
13
|
*
|
|
14
14
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
type CharterIssue,
|
|
24
24
|
type ProtocolContext,
|
|
25
25
|
} from './charter.ts';
|
|
26
|
-
import { RECORD_TYPES, appendEntry } from './
|
|
26
|
+
import { RECORD_TYPES, appendEntry } from './log.ts';
|
|
27
27
|
import { LEDGER_HEADER } from './ledger.ts';
|
|
28
28
|
import type { FileWrite } from './scm.ts';
|
|
29
29
|
import { createState, serializeState, type SessionStateFile } from './state.ts';
|
|
@@ -32,25 +32,25 @@ import { createState, serializeState, type SessionStateFile } from './state.ts';
|
|
|
32
32
|
/* Inputs and results */
|
|
33
33
|
/* -------------------------------------------------------------------------- */
|
|
34
34
|
|
|
35
|
-
export interface
|
|
36
|
-
/** Raw CHARTER.md source, as authored by the
|
|
35
|
+
export interface OpenSessionInput {
|
|
36
|
+
/** Raw CHARTER.md source, as authored by the owner. */
|
|
37
37
|
readonly charter_source: string;
|
|
38
38
|
/** Stable session identifier. Supplied by the caller — this module is pure. */
|
|
39
39
|
readonly session_guid: string;
|
|
40
|
-
/** ISO-8601 UTC timestamp for the
|
|
40
|
+
/** ISO-8601 UTC timestamp for the Opening. Supplied by the caller. */
|
|
41
41
|
readonly now: string;
|
|
42
|
-
/** Human handle of the AUTHORITY dropping the
|
|
43
|
-
readonly
|
|
42
|
+
/** Human handle of the AUTHORITY dropping the Opening. */
|
|
43
|
+
readonly owner: string;
|
|
44
44
|
/** Resolved protocol, when available. Enables ADR-0002 rules 2 and 5. */
|
|
45
45
|
readonly protocol?: ProtocolContext;
|
|
46
46
|
/**
|
|
47
|
-
* The session's instruction files present at
|
|
48
|
-
* onto the
|
|
47
|
+
* The session's instruction files present at session opening (ADR-0010 §4). Sealed
|
|
48
|
+
* onto the SESSION_OPENED entry so a later rewrite is detected.
|
|
49
49
|
*/
|
|
50
50
|
readonly instruction_files?: ReadonlyArray<{ readonly path: string; readonly content: string }>;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export type
|
|
53
|
+
export type OpenSessionResult =
|
|
54
54
|
| {
|
|
55
55
|
readonly ok: true;
|
|
56
56
|
readonly charter: Charter;
|
|
@@ -69,15 +69,15 @@ export type WritDropResult =
|
|
|
69
69
|
/* Templates */
|
|
70
70
|
/* -------------------------------------------------------------------------- */
|
|
71
71
|
|
|
72
|
-
const
|
|
72
|
+
const openingDoc = (input: OpenSessionInput, charter: Charter | null, guid: string): string => {
|
|
73
73
|
const lines = [
|
|
74
|
-
'#
|
|
74
|
+
'# OPENING',
|
|
75
75
|
'',
|
|
76
|
-
'Session identity and
|
|
76
|
+
'Session identity and session opening record.',
|
|
77
77
|
'',
|
|
78
78
|
`- **Session GUID:** ${guid}`,
|
|
79
79
|
`- **Protocol:** ${charter?.protocol ?? 'unresolved'}`,
|
|
80
|
-
`- **Dropped by:** ${input.
|
|
80
|
+
`- **Dropped by:** ${input.owner} (AUTHORITY)`,
|
|
81
81
|
`- **Dropped at:** ${input.now}`,
|
|
82
82
|
`- **Inherits from:** ${charter?.inherits_from ?? 'none (root node)'}`,
|
|
83
83
|
'',
|
|
@@ -85,8 +85,8 @@ const writ = (input: WritDropInput, charter: Charter | null, guid: string): stri
|
|
|
85
85
|
return `${lines.join('\n')}\n`;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
const
|
|
89
|
-
'#
|
|
88
|
+
const LOG_PREAMBLE = [
|
|
89
|
+
'# LOG',
|
|
90
90
|
'',
|
|
91
91
|
'Append-only attributed record of this proceeding. The RECORD agent writes;',
|
|
92
92
|
'no actor edits an entry once committed.',
|
|
@@ -95,33 +95,34 @@ const HANSARD_PREAMBLE = [
|
|
|
95
95
|
'',
|
|
96
96
|
].join('\n');
|
|
97
97
|
|
|
98
|
-
const
|
|
99
|
-
appendEntry(
|
|
100
|
-
type: RECORD_TYPES.
|
|
98
|
+
const log = (input: OpenSessionInput, charter: Charter, guid: string): string =>
|
|
99
|
+
appendEntry(LOG_PREAMBLE, {
|
|
100
|
+
type: RECORD_TYPES.SESSION_OPENED,
|
|
101
101
|
at: input.now,
|
|
102
|
-
actor: input.
|
|
102
|
+
actor: input.owner,
|
|
103
103
|
role: 'AUTHORITY',
|
|
104
104
|
fields: {
|
|
105
105
|
'Charter SHA256': charterFingerprint(input.charter_source),
|
|
106
|
+
'Charter locked': charter.session.immutable_charter ? 'yes' : 'no',
|
|
106
107
|
...(input.instruction_files === undefined || input.instruction_files.length === 0
|
|
107
108
|
? {}
|
|
108
109
|
: { 'Instructions SHA256': instructionsFingerprint(input.instruction_files) }),
|
|
109
110
|
},
|
|
110
|
-
body: `
|
|
111
|
+
body: `Session opened. Session ${guid} convened under the attached Charter.`,
|
|
111
112
|
});
|
|
112
113
|
|
|
113
|
-
const
|
|
114
|
-
input:
|
|
114
|
+
const invalidLog = (
|
|
115
|
+
input: OpenSessionInput,
|
|
115
116
|
guid: string,
|
|
116
117
|
issues: readonly CharterIssue[],
|
|
117
118
|
): string =>
|
|
118
|
-
appendEntry(
|
|
119
|
+
appendEntry(LOG_PREAMBLE, {
|
|
119
120
|
type: RECORD_TYPES.SESSION_INVALID,
|
|
120
121
|
at: input.now,
|
|
121
|
-
actor: input.
|
|
122
|
+
actor: input.owner,
|
|
122
123
|
role: 'AUTHORITY',
|
|
123
124
|
body: [
|
|
124
|
-
`
|
|
125
|
+
`session opening failed validation. Session ${guid} never opened.`,
|
|
125
126
|
'',
|
|
126
127
|
...issues.map(
|
|
127
128
|
(i) =>
|
|
@@ -148,24 +149,24 @@ const ledger = (charter: Charter): string =>
|
|
|
148
149
|
const keep = (purpose: string): string => `${purpose}\n`;
|
|
149
150
|
|
|
150
151
|
/**
|
|
151
|
-
*
|
|
152
|
+
* Owner notification workflow, per RUNTIME.md § escalation Workflow.
|
|
152
153
|
*
|
|
153
154
|
* Written into the session repo — this is the Clerk automation the escalation
|
|
154
|
-
* flow depends on: a push under `escalations/` emails the
|
|
155
|
+
* flow depends on: a push under `escalations/` emails the owner and tells
|
|
155
156
|
* them where to commit their ruling.
|
|
156
157
|
*
|
|
157
|
-
* The path filter deliberately excludes rulings. A ruling is the
|
|
158
|
+
* The path filter deliberately excludes rulings. A ruling is the owner's
|
|
158
159
|
* answer; notifying them of their own reply would loop.
|
|
159
160
|
*
|
|
160
161
|
* Requires three repository secrets. Absent them the workflow fails loudly
|
|
161
162
|
* rather than silently dropping the notification — an escalation nobody hears
|
|
162
163
|
* is the failure mode this whole flow exists to prevent.
|
|
163
164
|
*/
|
|
164
|
-
const
|
|
165
|
-
`name:
|
|
165
|
+
const escalationWorkflow = (): string =>
|
|
166
|
+
`name: escalation — Owner Notification
|
|
166
167
|
|
|
167
|
-
# Requires repository secrets: MAIL_USERNAME, MAIL_PASSWORD,
|
|
168
|
-
# See RUNTIME.md
|
|
168
|
+
# Requires repository secrets: MAIL_USERNAME, MAIL_PASSWORD, OWNER_EMAIL
|
|
169
|
+
# See RUNTIME.md — the escalation flow
|
|
169
170
|
|
|
170
171
|
on:
|
|
171
172
|
push:
|
|
@@ -173,7 +174,7 @@ on:
|
|
|
173
174
|
- 'escalations/[0-9]*.md'
|
|
174
175
|
|
|
175
176
|
jobs:
|
|
176
|
-
notify-
|
|
177
|
+
notify-owner:
|
|
177
178
|
runs-on: ubuntu-latest
|
|
178
179
|
steps:
|
|
179
180
|
- uses: actions/checkout@v4
|
|
@@ -189,18 +190,18 @@ jobs:
|
|
|
189
190
|
echo "POLITIK_EOF"
|
|
190
191
|
} >> "$GITHUB_OUTPUT"
|
|
191
192
|
|
|
192
|
-
- name: Email
|
|
193
|
+
- name: Email Owner
|
|
193
194
|
uses: dawidd6/action-send-mail@v3
|
|
194
195
|
with:
|
|
195
196
|
server_address: smtp.gmail.com
|
|
196
197
|
server_port: 465
|
|
197
198
|
username: \${{ secrets.MAIL_USERNAME }}
|
|
198
199
|
password: \${{ secrets.MAIL_PASSWORD }}
|
|
199
|
-
to: \${{ secrets.
|
|
200
|
+
to: \${{ secrets.OWNER_EMAIL }}
|
|
200
201
|
from: Politik Clerk
|
|
201
|
-
subject: "
|
|
202
|
+
subject: "escalation — \${{ github.repository }}"
|
|
202
203
|
body: |
|
|
203
|
-
|
|
204
|
+
An escalation has been raised.
|
|
204
205
|
|
|
205
206
|
\${{ steps.esc.outputs.content }}
|
|
206
207
|
|
|
@@ -215,7 +216,7 @@ jobs:
|
|
|
215
216
|
/**
|
|
216
217
|
* Heartbeat workflow — scheduled staleness detection.
|
|
217
218
|
*
|
|
218
|
-
* RUNTIME.md § Session Heartbeat: an hourly job checks the last
|
|
219
|
+
* RUNTIME.md § Session Heartbeat: an hourly job checks the last record commit
|
|
219
220
|
* and suspends the proceeding if nothing has happened within
|
|
220
221
|
* `heartbeat_timeout_hours`.
|
|
221
222
|
*
|
|
@@ -252,7 +253,7 @@ jobs:
|
|
|
252
253
|
steps:
|
|
253
254
|
- uses: actions/checkout@v4
|
|
254
255
|
with:
|
|
255
|
-
fetch-depth: 0 # the heartbeat is the last
|
|
256
|
+
fetch-depth: 0 # the heartbeat is the last record commit
|
|
256
257
|
|
|
257
258
|
- uses: actions/setup-node@v4
|
|
258
259
|
with:
|
|
@@ -264,10 +265,10 @@ jobs:
|
|
|
264
265
|
|
|
265
266
|
- name: Commit a suspension, if one was recorded
|
|
266
267
|
run: |
|
|
267
|
-
if [ -n "$(git status --porcelain
|
|
268
|
+
if [ -n "$(git status --porcelain LOG.md STATE.json)" ]; then
|
|
268
269
|
git config user.name 'Politik Clerk'
|
|
269
270
|
git config user.email 'clerk@politik.local'
|
|
270
|
-
git add
|
|
271
|
+
git add LOG.md STATE.json
|
|
271
272
|
git commit -m 'SESSION_STALE — heartbeat window elapsed'
|
|
272
273
|
git push
|
|
273
274
|
else
|
|
@@ -278,16 +279,16 @@ jobs:
|
|
|
278
279
|
/**
|
|
279
280
|
* Ruling workflow — resume on a committed ruling.
|
|
280
281
|
*
|
|
281
|
-
* RUNTIME.md §
|
|
282
|
-
* resumes".
|
|
283
|
-
* than through the CLI, should not also have to remember to resume the
|
|
282
|
+
* RUNTIME.md § escalation: "GitHub Actions detects ruling commit → session
|
|
283
|
+
* resumes". An owner who commits \`escalations/ruling-NNN.md\` directly, rather
|
|
284
|
+
* than through the CLI, should not also have to remember to resume the session.
|
|
284
285
|
*
|
|
285
286
|
* The path filter matches only rulings. Matching the whole \`escalations/\`
|
|
286
287
|
* directory would fire on the escalation that caused the suspension and resume
|
|
287
288
|
* a session nobody had ruled on.
|
|
288
289
|
*/
|
|
289
290
|
const rulingWorkflow = (): string =>
|
|
290
|
-
`name: Ruling — resume the
|
|
291
|
+
`name: Ruling — resume the session
|
|
291
292
|
|
|
292
293
|
# NOTE — these jobs run \`npx --yes @cordfuse/politik\`, which requires the
|
|
293
294
|
# package to be published to npm. Until it is, they will fail on the runner.
|
|
@@ -313,16 +314,16 @@ jobs:
|
|
|
313
314
|
with:
|
|
314
315
|
node-version: '22'
|
|
315
316
|
|
|
316
|
-
- name: Resume, if the session is suspended for
|
|
317
|
+
- name: Resume, if the session is suspended for an escalation
|
|
317
318
|
run: |
|
|
318
319
|
STATE=$(node -e "console.log(JSON.parse(require('fs').readFileSync('STATE.json','utf8')).state)")
|
|
319
320
|
CAUSE=$(node -e "const s=JSON.parse(require('fs').readFileSync('STATE.json','utf8'));console.log(s.suspension?.cause ?? '')")
|
|
320
321
|
|
|
321
|
-
# Only
|
|
322
|
-
# requires external review, and
|
|
322
|
+
# Only an escalation resumes this way. A misconduct
|
|
323
|
+
# requires external review, and an owner order is the owner's to
|
|
323
324
|
# lift — resuming around either would route past the governance that
|
|
324
325
|
# stopped the session.
|
|
325
|
-
if [ "$STATE" = "SUSPENDED" ] && [ "$CAUSE" = "
|
|
326
|
+
if [ "$STATE" = "SUSPENDED" ] && [ "$CAUSE" = "ESCALATION" ]; then
|
|
326
327
|
npx --yes @cordfuse/politik rule \\
|
|
327
328
|
--dir . --actor "$GITHUB_ACTOR" --role AUTHORITY \\
|
|
328
329
|
--outcome NOTED \\
|
|
@@ -330,8 +331,8 @@ jobs:
|
|
|
330
331
|
|
|
331
332
|
git config user.name 'Politik Clerk'
|
|
332
333
|
git config user.email 'clerk@politik.local'
|
|
333
|
-
git add
|
|
334
|
-
git commit -m 'RULING —
|
|
334
|
+
git add LOG.md STATE.json escalations/
|
|
335
|
+
git commit -m 'RULING — session resumes' || true
|
|
335
336
|
git push
|
|
336
337
|
else
|
|
337
338
|
echo "state=$STATE cause=$CAUSE — nothing to resume"
|
|
@@ -339,20 +340,20 @@ jobs:
|
|
|
339
340
|
`;
|
|
340
341
|
|
|
341
342
|
/* -------------------------------------------------------------------------- */
|
|
342
|
-
/*
|
|
343
|
+
/* session opening */
|
|
343
344
|
/* -------------------------------------------------------------------------- */
|
|
344
345
|
|
|
345
346
|
/**
|
|
346
|
-
* Execute the
|
|
347
|
+
* Execute the session opening.
|
|
347
348
|
*
|
|
348
349
|
* On pass: the full session file set with `STATE.json.state = CONVENED`
|
|
349
|
-
* (ADR-0002 rule 8). On failure: an INVALID state file plus a
|
|
350
|
+
* (ADR-0002 rule 8). On failure: an INVALID state file plus a record entry
|
|
350
351
|
* naming every violated rule, so the refusal is itself on the record.
|
|
351
352
|
*/
|
|
352
|
-
export const
|
|
353
|
+
export const openSession = (input: OpenSessionInput): OpenSessionResult => {
|
|
353
354
|
const parsed = parseCharter(input.charter_source);
|
|
354
355
|
|
|
355
|
-
const invalid = (issues: readonly CharterIssue[], charter: Charter | null):
|
|
356
|
+
const invalid = (issues: readonly CharterIssue[], charter: Charter | null): OpenSessionResult => {
|
|
356
357
|
const state = createState({
|
|
357
358
|
session_guid: input.session_guid,
|
|
358
359
|
protocol: charter?.protocol ?? '',
|
|
@@ -367,8 +368,8 @@ export const dropWrit = (input: WritDropInput): WritDropResult => {
|
|
|
367
368
|
files: [
|
|
368
369
|
{ path: 'CHARTER.md', content: input.charter_source },
|
|
369
370
|
{ path: 'STATE.json', content: serializeState(state) },
|
|
370
|
-
{ path: '
|
|
371
|
-
{ path: '
|
|
371
|
+
{ path: 'LOG.md', content: invalidLog(input, input.session_guid, issues) },
|
|
372
|
+
{ path: 'OPENING.md', content: openingDoc(input, charter, input.session_guid) },
|
|
372
373
|
],
|
|
373
374
|
};
|
|
374
375
|
};
|
|
@@ -390,13 +391,13 @@ export const dropWrit = (input: WritDropInput): WritDropResult => {
|
|
|
390
391
|
const files: FileWrite[] = [
|
|
391
392
|
{ path: 'CHARTER.md', content: input.charter_source },
|
|
392
393
|
{ path: 'STATE.json', content: serializeState(state) },
|
|
393
|
-
{ path: '
|
|
394
|
-
{ path: '
|
|
394
|
+
{ path: 'LOG.md', content: log(input, charter, input.session_guid) },
|
|
395
|
+
{ path: 'OPENING.md', content: openingDoc(input, charter, input.session_guid) },
|
|
395
396
|
{ path: 'roles/.gitkeep', content: keep('Role capability definitions.') },
|
|
396
397
|
{ path: 'actors/.gitkeep', content: keep('Actor profiles — who plays each role.') },
|
|
397
398
|
{ path: 'motions/.gitkeep', content: keep('Tabled business.') },
|
|
398
|
-
{ path: 'escalations/.gitkeep', content: keep('
|
|
399
|
-
{ path: '.github/workflows/
|
|
399
|
+
{ path: 'escalations/.gitkeep', content: keep('escalations and rulings.') },
|
|
400
|
+
{ path: '.github/workflows/escalation.yml', content: escalationWorkflow() },
|
|
400
401
|
{ path: '.github/workflows/heartbeat.yml', content: heartbeatWorkflow() },
|
|
401
402
|
{ path: '.github/workflows/ruling.yml', content: rulingWorkflow() },
|
|
402
403
|
];
|