@cordfuse/politik 0.3.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 +766 -0
- package/LICENSE +21 -0
- package/POLITIK-ARCHITECTURE.md +676 -0
- package/PROTOCOLS.md +1106 -0
- package/README.md +193 -0
- package/RESEARCH.md +475 -0
- package/RUNTIME.md +1355 -0
- package/bin/politik.js +31 -0
- package/docs/adr/0001-chamber-transport.md +67 -0
- package/docs/adr/0002-charter-schema.md +142 -0
- package/docs/adr/0003-state-json-schema.md +134 -0
- package/docs/adr/0004-motion-enactment.md +215 -0
- package/docs/adr/0005-hansard-format.md +171 -0
- package/docs/adr/0006-protocol-behavioral-enforcement.md +89 -0
- package/docs/adr/0007-protocol-mechanics.md +100 -0
- package/docs/adr/0008-session-storage.md +108 -0
- package/docs/adr/0009-match-primitive.md +74 -0
- package/package.json +55 -0
- package/protocols/CONTRIBUTING.md +130 -0
- package/protocols/adversarial-collaboration.yml +28 -0
- package/protocols/corporate.yml +35 -0
- package/protocols/elimination-tournament.yml +41 -0
- package/protocols/emergency-response-ics.yml +27 -0
- package/protocols/jury-deliberation.yml +32 -0
- package/protocols/monarchy.yml +31 -0
- package/protocols/parliamentary.yml +66 -0
- package/protocols/peer-review.yml +44 -0
- package/protocols/republic.yml +36 -0
- package/protocols/socialism-collective.yml +31 -0
- package/protocols/solo.yml +32 -0
- package/src/actors.ts +742 -0
- package/src/agents.ts +318 -0
- package/src/canon.ts +173 -0
- package/src/capability.ts +336 -0
- package/src/charter.ts +545 -0
- package/src/cli.ts +2174 -0
- package/src/conflict.ts +211 -0
- package/src/containment.ts +155 -0
- package/src/crisis.ts +381 -0
- package/src/division.ts +609 -0
- package/src/doctor.ts +168 -0
- package/src/election.ts +233 -0
- package/src/envelope.ts +223 -0
- package/src/escalation.ts +320 -0
- package/src/fault.ts +241 -0
- package/src/federation.ts +299 -0
- package/src/git.ts +163 -0
- package/src/hansard.ts +201 -0
- package/src/heartbeat.ts +282 -0
- package/src/index.ts +43 -0
- package/src/init.ts +396 -0
- package/src/integrity.ts +153 -0
- package/src/ledger.ts +341 -0
- package/src/lockfs.ts +58 -0
- package/src/projection.ts +293 -0
- package/src/prorogation.ts +307 -0
- package/src/protocol-sdk.ts +248 -0
- package/src/protocol.ts +241 -0
- package/src/providers/github.ts +347 -0
- package/src/quorum.ts +137 -0
- package/src/runner.ts +534 -0
- package/src/scm.ts +142 -0
- package/src/spawn.ts +160 -0
- package/src/standings.ts +143 -0
- package/src/state.ts +179 -0
- package/src/templates/parliamentary.ts +359 -0
- package/src/tournament.ts +200 -0
- package/src/transport.ts +190 -0
- package/src/tree.ts +371 -0
package/src/agents.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent compatibility layer.
|
|
3
|
+
*
|
|
4
|
+
* Politik spawns stateless CLI agents: broadcast received, agent spawned,
|
|
5
|
+
* prompt executed, result committed, agent disposed. This module owns the two
|
|
6
|
+
* things that differ per agent — how you invoke it headlessly, and how you hand
|
|
7
|
+
* it a prompt — and nothing else.
|
|
8
|
+
*
|
|
9
|
+
* The registry is a data table transcribed from RUNTIME.md § Politik Compatible
|
|
10
|
+
* rather than a class per agent. Agents differ only in their argv shape and
|
|
11
|
+
* auth story; encoding that as data keeps the whole layer testable without a
|
|
12
|
+
* single CLI installed, and makes adding an agent a one-line change.
|
|
13
|
+
*
|
|
14
|
+
* Attribution: Steve Krisjanovs, Cordfuse
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { Role, Verb } from './canon.ts';
|
|
18
|
+
import type { Envelope } from './envelope.ts';
|
|
19
|
+
|
|
20
|
+
/* -------------------------------------------------------------------------- */
|
|
21
|
+
/* Registry */
|
|
22
|
+
/* -------------------------------------------------------------------------- */
|
|
23
|
+
|
|
24
|
+
/** How an agent takes its prompt on the command line. */
|
|
25
|
+
export type PromptStyle =
|
|
26
|
+
/** Prompt follows a flag, e.g. `claude -p "..."`. */
|
|
27
|
+
| { readonly kind: 'flag'; readonly flag: string }
|
|
28
|
+
/** Prompt follows a subcommand, e.g. `opencode run "..."`. */
|
|
29
|
+
| { readonly kind: 'subcommand'; readonly subcommand: string }
|
|
30
|
+
/** Prompt is the first bare argument, e.g. `codex "..."`. */
|
|
31
|
+
| { readonly kind: 'positional' };
|
|
32
|
+
|
|
33
|
+
export type AuthMode = 'oauth' | 'api_key' | 'aws';
|
|
34
|
+
|
|
35
|
+
export interface AgentSpec {
|
|
36
|
+
/** Registry key. Stable; used in Charters and Hansard attribution. */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly label: string;
|
|
39
|
+
readonly command: string;
|
|
40
|
+
readonly prompt: PromptStyle;
|
|
41
|
+
/**
|
|
42
|
+
* Args this agent requires to run non-interactively at all — not user
|
|
43
|
+
* preferences. Always injected before the prompt.
|
|
44
|
+
*/
|
|
45
|
+
readonly headless_args?: readonly string[];
|
|
46
|
+
/** Auth available when running on a developer machine. */
|
|
47
|
+
readonly auth_local: AuthMode;
|
|
48
|
+
/** Auth available when running headless (CI, VPS, container). */
|
|
49
|
+
readonly auth_headless: AuthMode;
|
|
50
|
+
/** Supports structured JSON over stdio. */
|
|
51
|
+
readonly stdio_json: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Args that make the agent emit structured output carrying usage data.
|
|
54
|
+
* Without these the LEDGER can record elapsed time but not tokens or cost.
|
|
55
|
+
*/
|
|
56
|
+
readonly json_args?: readonly string[];
|
|
57
|
+
readonly notes: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Agents Politik can spawn as constituencies.
|
|
62
|
+
*
|
|
63
|
+
* Transcribed from RUNTIME.md § Politik Compatible. IDE-primary tools (Cursor,
|
|
64
|
+
* Windsurf, Roo, Continue) are deliberately absent: they expose no headless
|
|
65
|
+
* prompt, so they cannot be a constituency. A developer using one is an OPERATOR
|
|
66
|
+
* in the session, not an agent of it. GitHub Copilot's agentic CLI (`copilot -p`)
|
|
67
|
+
* DOES expose a headless prompt, so it is now included (auth is a persisted
|
|
68
|
+
* OAuth login, same as the other subscription CLIs).
|
|
69
|
+
*/
|
|
70
|
+
export const AGENTS: readonly AgentSpec[] = Object.freeze([
|
|
71
|
+
{
|
|
72
|
+
id: 'claude-code',
|
|
73
|
+
label: 'Claude Code',
|
|
74
|
+
command: 'claude',
|
|
75
|
+
prompt: { kind: 'flag', flag: '-p' },
|
|
76
|
+
auth_local: 'oauth',
|
|
77
|
+
auth_headless: 'oauth',
|
|
78
|
+
stdio_json: true,
|
|
79
|
+
json_args: ['--output-format', 'json'],
|
|
80
|
+
notes: 'Primary target. --output-format json reports exact tokens and cost.',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'gemini-cli',
|
|
84
|
+
label: 'Gemini CLI',
|
|
85
|
+
command: 'gemini',
|
|
86
|
+
prompt: { kind: 'flag', flag: '-p' },
|
|
87
|
+
headless_args: ['--skip-trust'],
|
|
88
|
+
json_args: ['-o', 'json'],
|
|
89
|
+
auth_local: 'oauth',
|
|
90
|
+
auth_headless: 'oauth',
|
|
91
|
+
stdio_json: true,
|
|
92
|
+
notes: '1M context. Refuses an untrusted directory without --skip-trust. Reports tokens, not cost.',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'opencode',
|
|
96
|
+
label: 'OpenCode',
|
|
97
|
+
command: 'opencode',
|
|
98
|
+
prompt: { kind: 'subcommand', subcommand: 'run' },
|
|
99
|
+
json_args: ['--format', 'json'],
|
|
100
|
+
auth_local: 'oauth',
|
|
101
|
+
auth_headless: 'oauth',
|
|
102
|
+
stdio_json: true,
|
|
103
|
+
notes: '75+ providers, Ollama. Reports tokens and cost.',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'qwen-code',
|
|
107
|
+
label: 'Qwen Code',
|
|
108
|
+
command: 'qwen',
|
|
109
|
+
prompt: { kind: 'flag', flag: '-p' },
|
|
110
|
+
json_args: ['-o', 'json'],
|
|
111
|
+
auth_local: 'oauth',
|
|
112
|
+
auth_headless: 'oauth',
|
|
113
|
+
stdio_json: true,
|
|
114
|
+
notes: 'stream-json, Apache 2.0.',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'codex-cli',
|
|
118
|
+
label: 'Codex CLI',
|
|
119
|
+
command: 'codex',
|
|
120
|
+
prompt: { kind: 'subcommand', subcommand: 'exec' },
|
|
121
|
+
json_args: ['--json'],
|
|
122
|
+
auth_local: 'oauth',
|
|
123
|
+
auth_headless: 'oauth',
|
|
124
|
+
stdio_json: true,
|
|
125
|
+
notes:
|
|
126
|
+
'OpenAI, Rust-based. Bare `codex` is an interactive TUI; `exec` is headless. ' +
|
|
127
|
+
'Requires cwd to be a git repo — always true of a session repo.',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: 'antigravity',
|
|
131
|
+
label: 'Antigravity',
|
|
132
|
+
command: 'agy',
|
|
133
|
+
prompt: { kind: 'flag', flag: '-p' },
|
|
134
|
+
auth_local: 'oauth',
|
|
135
|
+
auth_headless: 'oauth',
|
|
136
|
+
stdio_json: false,
|
|
137
|
+
notes: 'Google. -p/--print for headless.',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: 'aider',
|
|
141
|
+
label: 'Aider',
|
|
142
|
+
command: 'aider',
|
|
143
|
+
prompt: { kind: 'flag', flag: '--message' },
|
|
144
|
+
auth_local: 'api_key',
|
|
145
|
+
auth_headless: 'api_key',
|
|
146
|
+
stdio_json: false,
|
|
147
|
+
notes: 'Strong git integration.',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: 'goose',
|
|
151
|
+
label: 'Goose',
|
|
152
|
+
command: 'goose',
|
|
153
|
+
prompt: { kind: 'subcommand', subcommand: 'run' },
|
|
154
|
+
auth_local: 'api_key',
|
|
155
|
+
auth_headless: 'api_key',
|
|
156
|
+
stdio_json: false,
|
|
157
|
+
notes: 'MCP-native, Block.',
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: 'copilot',
|
|
161
|
+
label: 'GitHub Copilot CLI',
|
|
162
|
+
command: 'copilot',
|
|
163
|
+
prompt: { kind: 'flag', flag: '-p' },
|
|
164
|
+
headless_args: ['--allow-all-tools'],
|
|
165
|
+
auth_local: 'oauth',
|
|
166
|
+
auth_headless: 'oauth',
|
|
167
|
+
stdio_json: false,
|
|
168
|
+
notes:
|
|
169
|
+
'GitHub, agentic CLI (v1+). `-p --allow-all-tools` is headless. Auth is the ' +
|
|
170
|
+
'persisted GitHub Copilot login; running headless needs an active Copilot ' +
|
|
171
|
+
'subscription with the CLI policy enabled. Usage/cost shape not yet captured.',
|
|
172
|
+
},
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
export const findAgent = (id: string): AgentSpec | null =>
|
|
176
|
+
AGENTS.find((a) => a.id === id) ?? null;
|
|
177
|
+
|
|
178
|
+
/* -------------------------------------------------------------------------- */
|
|
179
|
+
/* Invocation */
|
|
180
|
+
/* -------------------------------------------------------------------------- */
|
|
181
|
+
|
|
182
|
+
export interface Invocation {
|
|
183
|
+
readonly command: string;
|
|
184
|
+
readonly args: readonly string[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Build the headless invocation for an agent.
|
|
189
|
+
*
|
|
190
|
+
* Returns command and args separately, never a shell string. The prompt carries
|
|
191
|
+
* a Charter, a Hansard excerpt and arbitrary session text; interpolating that
|
|
192
|
+
* into a shell would be an injection vector on every spawn. Callers must pass
|
|
193
|
+
* this to a non-shell spawn.
|
|
194
|
+
*/
|
|
195
|
+
export const buildInvocation = (
|
|
196
|
+
agent: AgentSpec,
|
|
197
|
+
prompt: string,
|
|
198
|
+
extraArgs: readonly string[] = [],
|
|
199
|
+
): Invocation => {
|
|
200
|
+
// Required headless args come first: without them the agent will not run
|
|
201
|
+
// non-interactively at all, so a caller must not be able to displace them.
|
|
202
|
+
const args = [...(agent.headless_args ?? []), ...extraArgs];
|
|
203
|
+
|
|
204
|
+
switch (agent.prompt.kind) {
|
|
205
|
+
case 'flag':
|
|
206
|
+
return { command: agent.command, args: [...args, agent.prompt.flag, prompt] };
|
|
207
|
+
case 'subcommand':
|
|
208
|
+
return {
|
|
209
|
+
command: agent.command,
|
|
210
|
+
args: [agent.prompt.subcommand, ...args, prompt],
|
|
211
|
+
};
|
|
212
|
+
case 'positional':
|
|
213
|
+
return { command: agent.command, args: [...args, prompt] };
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** Whether an agent can run in the given environment without interactive auth. */
|
|
218
|
+
// Headless-capable = the agent has a non-interactive credential path. What a
|
|
219
|
+
// headless run cannot do is the one-time interactive *login*; ongoing invocation
|
|
220
|
+
// is fine once a credential persists. A stored OAuth token counts — `claude -p`,
|
|
221
|
+
// `codex exec`, `opencode run`, `agy -p` all ran unattended on their subscription
|
|
222
|
+
// logins with no API key (proven live), refreshing the token non-interactively —
|
|
223
|
+
// as do an API key and AWS auth. All three modes qualify; only an interactive-
|
|
224
|
+
// only tool with no persistence can't, and those are excluded from the registry.
|
|
225
|
+
export const canRunHeadless = (agent: AgentSpec): boolean =>
|
|
226
|
+
agent.auth_headless === 'oauth' ||
|
|
227
|
+
agent.auth_headless === 'api_key' ||
|
|
228
|
+
agent.auth_headless === 'aws';
|
|
229
|
+
|
|
230
|
+
/* -------------------------------------------------------------------------- */
|
|
231
|
+
/* Prompt injection */
|
|
232
|
+
/* -------------------------------------------------------------------------- */
|
|
233
|
+
|
|
234
|
+
export interface PromptContext {
|
|
235
|
+
readonly envelope: Envelope;
|
|
236
|
+
/** The constituency this agent is seated in. */
|
|
237
|
+
readonly role: Role;
|
|
238
|
+
/** Verbs the Charter grants this role. */
|
|
239
|
+
readonly verbs: readonly Verb[];
|
|
240
|
+
/** Protocol vocabulary name, e.g. parliamentary. */
|
|
241
|
+
readonly protocol: string;
|
|
242
|
+
/** Recent Hansard, so a fresh agent has session context. */
|
|
243
|
+
readonly hansard_excerpt?: string;
|
|
244
|
+
/** Standing Orders prose from the Charter. */
|
|
245
|
+
readonly standing_orders?: string;
|
|
246
|
+
/**
|
|
247
|
+
* Whether the protocol permits escalation (ADR-0006). Defaults to true. When
|
|
248
|
+
* false — a Darwinist chamber — the agent is told there is no Point of Order:
|
|
249
|
+
* it decides within its mandate or exits, since an appeal has no resolver.
|
|
250
|
+
*/
|
|
251
|
+
readonly escalation_enabled?: boolean;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Compose the prompt handed to a spawned agent.
|
|
256
|
+
*
|
|
257
|
+
* This is the Politik→agent contract, and it is deliberately uniform across
|
|
258
|
+
* agents: the same text goes to Claude Code and to Goose. Per-agent prompt
|
|
259
|
+
* tuning would make cross-protocol comparisons meaningless, and comparing
|
|
260
|
+
* behaviour under identical conditions is the entire point of the research
|
|
261
|
+
* layer (RESEARCH.md § Human Flaw thesis).
|
|
262
|
+
*
|
|
263
|
+
* Structure: who you are, what you may do, what has happened, what to do now.
|
|
264
|
+
*/
|
|
265
|
+
export const composePrompt = (context: PromptContext): string => {
|
|
266
|
+
const sections: string[] = [
|
|
267
|
+
'# POLITIK SESSION',
|
|
268
|
+
'',
|
|
269
|
+
`You are a **${context.role}** in a governed multi-agent session running the`,
|
|
270
|
+
`**${context.protocol}** protocol. Session: \`${context.envelope.session_guid}\`.`,
|
|
271
|
+
'',
|
|
272
|
+
'## Your mandate',
|
|
273
|
+
'',
|
|
274
|
+
`Verbs granted to your role: ${context.verbs.length > 0 ? context.verbs.join(', ') : 'none'}.`,
|
|
275
|
+
'You may not take an action your verbs do not grant.',
|
|
276
|
+
context.escalation_enabled === false
|
|
277
|
+
? 'This protocol has no escalation: there is no Point of Order and no appeal. ' +
|
|
278
|
+
'Decide within your mandate, or exit. A decision here is final.'
|
|
279
|
+
: 'If you believe the correct action requires a verb you do not hold, file a ' +
|
|
280
|
+
'Point of Order instead of proceeding.',
|
|
281
|
+
'',
|
|
282
|
+
'## Standing Orders',
|
|
283
|
+
'',
|
|
284
|
+
context.standing_orders?.trim() || '_None supplied. Follow CANON defaults._',
|
|
285
|
+
'',
|
|
286
|
+
];
|
|
287
|
+
|
|
288
|
+
if (context.hansard_excerpt !== undefined && context.hansard_excerpt.trim() !== '') {
|
|
289
|
+
sections.push(
|
|
290
|
+
'## Record so far',
|
|
291
|
+
'',
|
|
292
|
+
'The Hansard is the session. You are stateless; this is your context.',
|
|
293
|
+
'',
|
|
294
|
+
context.hansard_excerpt.trim(),
|
|
295
|
+
'',
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
sections.push(
|
|
300
|
+
'## Business before you',
|
|
301
|
+
'',
|
|
302
|
+
context.envelope.prompt.trim(),
|
|
303
|
+
'',
|
|
304
|
+
'## Rules of the floor',
|
|
305
|
+
'',
|
|
306
|
+
'- Commit your result. Uncommitted work does not exist.',
|
|
307
|
+
'- Do not traverse above the working directory. Doing so is a Standing',
|
|
308
|
+
' Orders violation, logged to the Hansard and escalated to the Speaker.',
|
|
309
|
+
'- **Do not write to HANSARD.md, STATE.json or LEDGER.md at all** — not even',
|
|
310
|
+
' to append. The RECORD agent owns them exclusively, and writing to them is',
|
|
311
|
+
' a Standing Orders violation. Your work is recorded for you; state your',
|
|
312
|
+
' result in your reply and it will be entered in the record.',
|
|
313
|
+
'- When your task is complete, stop. You are disposed after this turn.',
|
|
314
|
+
'',
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
return sections.join('\n');
|
|
318
|
+
};
|
package/src/canon.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CANON — the canonical primitive layer.
|
|
3
|
+
*
|
|
4
|
+
* The engine speaks these terms. Protocols translate them to industry
|
|
5
|
+
* vocabulary; nothing below this layer knows what "Speaker" or "Sprint" means.
|
|
6
|
+
*
|
|
7
|
+
* This module is types and frozen constants only — no logic, no I/O. It is the
|
|
8
|
+
* single source of truth for CANON in code, so that any drift from
|
|
9
|
+
* POLITIK-ARCHITECTURE.md becomes a compile error rather than a runtime
|
|
10
|
+
* surprise.
|
|
11
|
+
*
|
|
12
|
+
* Attribution: Steve Krisjanovs, Cordfuse
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/* -------------------------------------------------------------------------- */
|
|
16
|
+
/* Roles */
|
|
17
|
+
/* -------------------------------------------------------------------------- */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Trust level and mandate — not species. Any role except AUTHORITY may be held
|
|
21
|
+
* by a human or a machine agent.
|
|
22
|
+
*/
|
|
23
|
+
export const ROLES = [
|
|
24
|
+
'AUTHORITY',
|
|
25
|
+
'DELEGATE',
|
|
26
|
+
'OPERATOR',
|
|
27
|
+
'MEMBER',
|
|
28
|
+
'OBSERVER',
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
export type Role = (typeof ROLES)[number];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The one hard constitutional rule: AUTHORITY is always human. A Charter
|
|
35
|
+
* declaring a machine as AUTHORITY is invalid and fails Writ Drop validation.
|
|
36
|
+
*/
|
|
37
|
+
export const HUMAN_ONLY_ROLES: readonly Role[] = Object.freeze(['AUTHORITY']);
|
|
38
|
+
|
|
39
|
+
/** Descending trust order. Index 0 is the highest trust tier. */
|
|
40
|
+
export const ROLE_PRECEDENCE: readonly Role[] = Object.freeze([
|
|
41
|
+
'AUTHORITY',
|
|
42
|
+
'DELEGATE',
|
|
43
|
+
'OPERATOR',
|
|
44
|
+
'MEMBER',
|
|
45
|
+
'OBSERVER',
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
/* -------------------------------------------------------------------------- */
|
|
49
|
+
/* Session primitives */
|
|
50
|
+
/* -------------------------------------------------------------------------- */
|
|
51
|
+
|
|
52
|
+
export const PRIMITIVES = [
|
|
53
|
+
'SESSION',
|
|
54
|
+
'PROCEEDING',
|
|
55
|
+
'CHARTER',
|
|
56
|
+
'RECORD',
|
|
57
|
+
'MOTION',
|
|
58
|
+
'DIVISION',
|
|
59
|
+
'MATCH',
|
|
60
|
+
'ESCALATION',
|
|
61
|
+
'SUSPENSION',
|
|
62
|
+
'QUORUM',
|
|
63
|
+
'CONFLICT',
|
|
64
|
+
'DEADLOCK',
|
|
65
|
+
] as const;
|
|
66
|
+
|
|
67
|
+
export type Primitive = (typeof PRIMITIVES)[number];
|
|
68
|
+
|
|
69
|
+
/* -------------------------------------------------------------------------- */
|
|
70
|
+
/* Verbs */
|
|
71
|
+
/* -------------------------------------------------------------------------- */
|
|
72
|
+
|
|
73
|
+
export const VERBS = [
|
|
74
|
+
'READ',
|
|
75
|
+
'WRITE',
|
|
76
|
+
'VOTE',
|
|
77
|
+
'ASSENT',
|
|
78
|
+
'ESCALATE',
|
|
79
|
+
'PROMOTE',
|
|
80
|
+
'DEMOTE',
|
|
81
|
+
'HIRE',
|
|
82
|
+
'FIRE',
|
|
83
|
+
'SUSPEND',
|
|
84
|
+
'EXPEL',
|
|
85
|
+
'VETO',
|
|
86
|
+
'SPAWN',
|
|
87
|
+
'DISSOLVE',
|
|
88
|
+
'EXIT',
|
|
89
|
+
] as const;
|
|
90
|
+
|
|
91
|
+
export type Verb = (typeof VERBS)[number];
|
|
92
|
+
|
|
93
|
+
/* -------------------------------------------------------------------------- */
|
|
94
|
+
/* States */
|
|
95
|
+
/* -------------------------------------------------------------------------- */
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The five valid states of a proceeding. CONSTITUTIONAL_CRISIS is deliberately
|
|
99
|
+
* absent — it is a *cause of suspension*, not a state (ADR-0003).
|
|
100
|
+
*/
|
|
101
|
+
export const STATES = [
|
|
102
|
+
'STATE_CONVENED',
|
|
103
|
+
'STATE_SUSPENDED',
|
|
104
|
+
'STATE_PROROGUED',
|
|
105
|
+
'STATE_STALE',
|
|
106
|
+
'STATE_INVALID',
|
|
107
|
+
] as const;
|
|
108
|
+
|
|
109
|
+
export type State = (typeof STATES)[number];
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Why a proceeding was suspended. Carried alongside SUSPENDED. Enum is fixed by
|
|
113
|
+
* ADR-0003 § Decision; DEADLOCK added per ADR-0004.
|
|
114
|
+
*
|
|
115
|
+
* Two deliberate absences:
|
|
116
|
+
* - CONFLICT is mechanical and routine — never a suspension cause.
|
|
117
|
+
* - Heartbeat expiry is its own CANON state (STALE), not a suspension cause,
|
|
118
|
+
* so that "a human paused it" stays distinguishable from "the agents went
|
|
119
|
+
* quiet".
|
|
120
|
+
*/
|
|
121
|
+
export const SUSPENSION_CAUSES = [
|
|
122
|
+
'POINT_OF_ORDER',
|
|
123
|
+
'SPEAKER_ORDER',
|
|
124
|
+
'DISPUTED_EXIT',
|
|
125
|
+
'CONSTITUTIONAL_CRISIS',
|
|
126
|
+
'DEADLOCK',
|
|
127
|
+
] as const;
|
|
128
|
+
|
|
129
|
+
export type SuspensionCause = (typeof SUSPENSION_CAUSES)[number];
|
|
130
|
+
|
|
131
|
+
/* -------------------------------------------------------------------------- */
|
|
132
|
+
/* Merge strategy */
|
|
133
|
+
/* -------------------------------------------------------------------------- */
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* How a carried Motion is enacted on ASSENT. Declared in the Charter; Writ Drop
|
|
137
|
+
* enforces the squash/fast_forward constraints (ADR-0002).
|
|
138
|
+
*/
|
|
139
|
+
export const MERGE_STRATEGIES = [
|
|
140
|
+
'merge_commit',
|
|
141
|
+
'squash',
|
|
142
|
+
'fast_forward',
|
|
143
|
+
] as const;
|
|
144
|
+
|
|
145
|
+
export type MergeStrategy = (typeof MERGE_STRATEGIES)[number];
|
|
146
|
+
|
|
147
|
+
/* -------------------------------------------------------------------------- */
|
|
148
|
+
/* Guards */
|
|
149
|
+
/* -------------------------------------------------------------------------- */
|
|
150
|
+
|
|
151
|
+
const includes = <T extends string>(
|
|
152
|
+
haystack: readonly T[],
|
|
153
|
+
value: unknown,
|
|
154
|
+
): value is T => typeof value === 'string' && (haystack as readonly string[]).includes(value);
|
|
155
|
+
|
|
156
|
+
export const isRole = (v: unknown): v is Role => includes(ROLES, v);
|
|
157
|
+
export const isPrimitive = (v: unknown): v is Primitive => includes(PRIMITIVES, v);
|
|
158
|
+
export const isVerb = (v: unknown): v is Verb => includes(VERBS, v);
|
|
159
|
+
export const isState = (v: unknown): v is State => includes(STATES, v);
|
|
160
|
+
export const isSuspensionCause = (v: unknown): v is SuspensionCause =>
|
|
161
|
+
includes(SUSPENSION_CAUSES, v);
|
|
162
|
+
export const isMergeStrategy = (v: unknown): v is MergeStrategy =>
|
|
163
|
+
includes(MERGE_STRATEGIES, v);
|
|
164
|
+
|
|
165
|
+
/** True if the role may only ever be held by a human actor. */
|
|
166
|
+
export const isHumanOnlyRole = (role: Role): boolean => HUMAN_ONLY_ROLES.includes(role);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Compare two roles by trust. Returns a negative number if `a` outranks `b`,
|
|
170
|
+
* positive if `b` outranks `a`, zero if equal.
|
|
171
|
+
*/
|
|
172
|
+
export const compareRoles = (a: Role, b: Role): number =>
|
|
173
|
+
ROLE_PRECEDENCE.indexOf(a) - ROLE_PRECEDENCE.indexOf(b);
|