@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.
Files changed (69) hide show
  1. package/EXECUTION.md +766 -0
  2. package/LICENSE +21 -0
  3. package/POLITIK-ARCHITECTURE.md +676 -0
  4. package/PROTOCOLS.md +1106 -0
  5. package/README.md +193 -0
  6. package/RESEARCH.md +475 -0
  7. package/RUNTIME.md +1355 -0
  8. package/bin/politik.js +31 -0
  9. package/docs/adr/0001-chamber-transport.md +67 -0
  10. package/docs/adr/0002-charter-schema.md +142 -0
  11. package/docs/adr/0003-state-json-schema.md +134 -0
  12. package/docs/adr/0004-motion-enactment.md +215 -0
  13. package/docs/adr/0005-hansard-format.md +171 -0
  14. package/docs/adr/0006-protocol-behavioral-enforcement.md +89 -0
  15. package/docs/adr/0007-protocol-mechanics.md +100 -0
  16. package/docs/adr/0008-session-storage.md +108 -0
  17. package/docs/adr/0009-match-primitive.md +74 -0
  18. package/package.json +55 -0
  19. package/protocols/CONTRIBUTING.md +130 -0
  20. package/protocols/adversarial-collaboration.yml +28 -0
  21. package/protocols/corporate.yml +35 -0
  22. package/protocols/elimination-tournament.yml +41 -0
  23. package/protocols/emergency-response-ics.yml +27 -0
  24. package/protocols/jury-deliberation.yml +32 -0
  25. package/protocols/monarchy.yml +31 -0
  26. package/protocols/parliamentary.yml +66 -0
  27. package/protocols/peer-review.yml +44 -0
  28. package/protocols/republic.yml +36 -0
  29. package/protocols/socialism-collective.yml +31 -0
  30. package/protocols/solo.yml +32 -0
  31. package/src/actors.ts +742 -0
  32. package/src/agents.ts +318 -0
  33. package/src/canon.ts +173 -0
  34. package/src/capability.ts +336 -0
  35. package/src/charter.ts +545 -0
  36. package/src/cli.ts +2174 -0
  37. package/src/conflict.ts +211 -0
  38. package/src/containment.ts +155 -0
  39. package/src/crisis.ts +381 -0
  40. package/src/division.ts +609 -0
  41. package/src/doctor.ts +168 -0
  42. package/src/election.ts +233 -0
  43. package/src/envelope.ts +223 -0
  44. package/src/escalation.ts +320 -0
  45. package/src/fault.ts +241 -0
  46. package/src/federation.ts +299 -0
  47. package/src/git.ts +163 -0
  48. package/src/hansard.ts +201 -0
  49. package/src/heartbeat.ts +282 -0
  50. package/src/index.ts +43 -0
  51. package/src/init.ts +396 -0
  52. package/src/integrity.ts +153 -0
  53. package/src/ledger.ts +341 -0
  54. package/src/lockfs.ts +58 -0
  55. package/src/projection.ts +293 -0
  56. package/src/prorogation.ts +307 -0
  57. package/src/protocol-sdk.ts +248 -0
  58. package/src/protocol.ts +241 -0
  59. package/src/providers/github.ts +347 -0
  60. package/src/quorum.ts +137 -0
  61. package/src/runner.ts +534 -0
  62. package/src/scm.ts +142 -0
  63. package/src/spawn.ts +160 -0
  64. package/src/standings.ts +143 -0
  65. package/src/state.ts +179 -0
  66. package/src/templates/parliamentary.ts +359 -0
  67. package/src/tournament.ts +200 -0
  68. package/src/transport.ts +190 -0
  69. package/src/tree.ts +371 -0
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Protocol layer — vocabulary translation manifests over CANON.
3
+ *
4
+ * The engine is protocol-agnostic. It speaks CANON; a protocol translates CANON
5
+ * terms into an industry vocabulary for the user interface and the record.
6
+ *
7
+ * CANON (engine) -> protocol schema (manifest) -> user interface
8
+ *
9
+ * Parliamentary is not a privileged mode. It is protocol #1 — the reference
10
+ * implementation — and every industry is equally a protocol
11
+ * (POLITIK-ARCHITECTURE.md § Protocol Schema Format).
12
+ *
13
+ * Translation is presentation only. Nothing here changes engine behaviour: a
14
+ * DIVISION is a DIVISION whether it renders as "Division" or "Sprint Review".
15
+ * The four behavioural flags below are the sole exception, and they are
16
+ * declared, never inferred.
17
+ *
18
+ * Attribution: Steve Krisjanovs, Cordfuse
19
+ */
20
+
21
+ import { parse as parseYaml } from 'yaml';
22
+
23
+ import { isRole, ROLES, type Primitive, type Role, type Verb } from './canon.ts';
24
+
25
+ /* -------------------------------------------------------------------------- */
26
+ /* Schema */
27
+ /* -------------------------------------------------------------------------- */
28
+
29
+ export const PROTOCOL_MODES = [
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;
40
+
41
+ export type ProtocolRecordMode = (typeof RECORD_MODES)[number];
42
+
43
+ export interface Protocol {
44
+ readonly name: string;
45
+ readonly version: string;
46
+ readonly mode: ProtocolMode;
47
+ 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
+ readonly domain_veto: readonly Role[];
53
+ /** True for Darwinist/Authoritarian — no appeals. */
54
+ readonly no_escalation: boolean;
55
+ /** True for Ephemeral — no RECORD by design. */
56
+ readonly no_record: boolean;
57
+ /** True when Standing Orders cannot be amended mid-session. */
58
+ readonly immutable_charter: boolean;
59
+ /**
60
+ * Protocol override points (ADR-0007), declared so a Charter can inherit them.
61
+ * Kept as plain strings here: the manifest declares a protocol's default
62
+ * behavior, and the Charter — validated strictly at Writ Drop — is the runtime
63
+ * authority. Defaults reproduce Parliament.
64
+ */
65
+ readonly mechanics: {
66
+ readonly resolution: string;
67
+ readonly exit: string;
68
+ readonly termination: string;
69
+ };
70
+ }
71
+
72
+ export interface ProtocolIssue {
73
+ readonly field: string;
74
+ readonly message: string;
75
+ }
76
+
77
+ export type ProtocolParseResult =
78
+ | { readonly ok: true; readonly protocol: Protocol; readonly warnings: readonly ProtocolIssue[] }
79
+ | { readonly ok: false; readonly issues: readonly ProtocolIssue[] };
80
+
81
+ /* -------------------------------------------------------------------------- */
82
+ /* Parse */
83
+ /* -------------------------------------------------------------------------- */
84
+
85
+ const isObject = (v: unknown): v is Record<string, unknown> =>
86
+ typeof v === 'object' && v !== null && !Array.isArray(v);
87
+
88
+ const stringMap = (v: unknown): Record<string, string> => {
89
+ const out: Record<string, string> = {};
90
+ if (isObject(v)) {
91
+ for (const [key, value] of Object.entries(v)) {
92
+ if (typeof value === 'string') out[key] = value;
93
+ }
94
+ }
95
+ return out;
96
+ };
97
+
98
+ /**
99
+ * Parse a `.politik/protocol.yml` manifest.
100
+ *
101
+ * Unmapped roles are a *warning*, not an error: a protocol that omits a term
102
+ * simply falls back to the CANON word, which is always readable. Refusing to
103
+ * load an incomplete manifest would make authoring a protocol needlessly
104
+ * brittle.
105
+ */
106
+ export const parseProtocol = (source: string): ProtocolParseResult => {
107
+ let raw: unknown;
108
+ try {
109
+ raw = parseYaml(source);
110
+ } catch (err) {
111
+ return {
112
+ ok: false,
113
+ issues: [
114
+ {
115
+ field: 'protocol',
116
+ message: `malformed YAML: ${err instanceof Error ? err.message : String(err)}`,
117
+ },
118
+ ],
119
+ };
120
+ }
121
+
122
+ // The manifest nests everything under a `protocol:` key.
123
+ const block = isObject(raw) && isObject(raw['protocol']) ? raw['protocol'] : raw;
124
+ if (!isObject(block)) {
125
+ return { ok: false, issues: [{ field: 'protocol', message: 'expected a YAML mapping' }] };
126
+ }
127
+
128
+ const issues: ProtocolIssue[] = [];
129
+ const warnings: ProtocolIssue[] = [];
130
+
131
+ const name = typeof block['name'] === 'string' ? block['name'] : '';
132
+ if (name === '') issues.push({ field: 'name', message: 'required' });
133
+
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
+ const recordMode = block['record_mode'];
143
+ if (!(RECORD_MODES as readonly unknown[]).includes(recordMode)) {
144
+ issues.push({
145
+ field: 'record_mode',
146
+ message: `must be one of ${RECORD_MODES.join(' | ')}`,
147
+ });
148
+ }
149
+
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
+ const domain_veto: Role[] = [];
163
+ if (Array.isArray(block['domain_veto'])) {
164
+ for (const entry of block['domain_veto']) {
165
+ if (isRole(entry)) domain_veto.push(entry);
166
+ else issues.push({ field: 'domain_veto', message: `not a CANON role: ${String(entry)}` });
167
+ }
168
+ }
169
+
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
+ if (issues.length > 0) return { ok: false, issues };
182
+
183
+ return {
184
+ ok: true,
185
+ warnings,
186
+ protocol: {
187
+ name,
188
+ version: typeof block['version'] === 'string' ? block['version'] : '0.0.0',
189
+ mode: mode as ProtocolMode,
190
+ record_mode: recordMode as ProtocolRecordMode,
191
+ roles,
192
+ primitives: stringMap(block['primitives']),
193
+ domain_veto,
194
+ no_escalation: block['no_escalation'] === true,
195
+ no_record,
196
+ immutable_charter: block['immutable_charter'] === true,
197
+ mechanics: (() => {
198
+ const m = (typeof block['mechanics'] === 'object' && block['mechanics'] !== null
199
+ ? block['mechanics']
200
+ : {}) as Record<string, unknown>;
201
+ return {
202
+ resolution: typeof m['resolution'] === 'string' ? m['resolution'] : 'majority',
203
+ exit: typeof m['exit'] === 'string' ? m['exit'] : 'division',
204
+ termination: typeof m['termination'] === 'string' ? m['termination'] : 'objective',
205
+ };
206
+ })(),
207
+ },
208
+ };
209
+ };
210
+
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
+ /**
227
+ * Does this protocol permit escalation?
228
+ *
229
+ * Darwinist and Authoritarian protocols set `no_escalation`. A Point of Order
230
+ * filed under one of those is not a governance event — it is a category error,
231
+ * and the engine must refuse it rather than suspend a session that has no
232
+ * appeal mechanism to resume from.
233
+ */
234
+ export const allowsEscalation = (protocol: Protocol): boolean => !protocol.no_escalation;
235
+
236
+ /** Does this protocol keep a Hansard? False only for Ephemeral protocols. */
237
+ export const keepsRecord = (protocol: Protocol): boolean => !protocol.no_record;
238
+
239
+ /** May the Charter be amended mid-session? */
240
+ export const allowsCharterAmendment = (protocol: Protocol): boolean =>
241
+ !protocol.immutable_charter;
@@ -0,0 +1,347 @@
1
+ /**
2
+ * GitHub SCM provider — the reference implementation of ScmProvider.
3
+ *
4
+ * Implemented against the GitHub REST API with the platform `fetch`, rather
5
+ * than an SDK: the interface is eleven methods, Node 20 ships fetch, and a
6
+ * governance framework benefits from a shallow dependency tree.
7
+ *
8
+ * REST only. `openDiscussion` is deliberately unimplemented — see the method.
9
+ *
10
+ * This module performs I/O. Everything above it (canon, charter, state, init)
11
+ * stays pure, so a session can be validated and initialized with no network.
12
+ *
13
+ * Attribution: Steve Krisjanovs, Cordfuse
14
+ */
15
+
16
+ import type { MergeStrategy, Role } from '../canon.ts';
17
+ import type {
18
+ AssentResult,
19
+ CollaboratorGrant,
20
+ CommitRef,
21
+ DivisionRef,
22
+ EscalationRef,
23
+ FileWrite,
24
+ MotionRef,
25
+ Ref,
26
+ ScmProvider,
27
+ } from '../scm.ts';
28
+
29
+ /* -------------------------------------------------------------------------- */
30
+ /* Configuration */
31
+ /* -------------------------------------------------------------------------- */
32
+
33
+ export interface GitHubProviderOptions {
34
+ /** Repository owner — user or org. */
35
+ readonly owner: string;
36
+ /** Repository name. This repo IS the session. */
37
+ readonly repo: string;
38
+ /** Token with repo scope. Never logged, never committed. */
39
+ readonly token: string;
40
+ /** Default branch commits target. */
41
+ readonly baseBranch?: string;
42
+ /** Override for GitHub Enterprise. */
43
+ readonly apiBase?: string;
44
+ /** Injectable for tests. Defaults to the platform fetch. */
45
+ readonly fetch?: typeof globalThis.fetch;
46
+ }
47
+
48
+ /**
49
+ * CANON role -> GitHub collaborator permission.
50
+ *
51
+ * A design decision, not a spec quotation: CANON describes governance trust,
52
+ * GitHub describes repository capability, and they are not the same axis.
53
+ * The mapping is deliberately conservative — OPERATOR and MEMBER both receive
54
+ * `push` because the Charter, not the SCM ACL, is what separates their verbs.
55
+ * Governance is enforced in the Hansard; this is only the coarse outer gate.
56
+ */
57
+ export const ROLE_PERMISSIONS: Readonly<Record<Role, string>> = Object.freeze({
58
+ AUTHORITY: 'admin',
59
+ DELEGATE: 'maintain',
60
+ OPERATOR: 'push',
61
+ MEMBER: 'push',
62
+ OBSERVER: 'pull',
63
+ });
64
+
65
+ /** CANON merge strategy -> GitHub merge method. */
66
+ const MERGE_METHODS: Readonly<Record<MergeStrategy, string>> = Object.freeze({
67
+ merge_commit: 'merge',
68
+ squash: 'squash',
69
+ fast_forward: 'rebase',
70
+ });
71
+
72
+ /* -------------------------------------------------------------------------- */
73
+ /* Errors */
74
+ /* -------------------------------------------------------------------------- */
75
+
76
+ export class ScmError extends Error {
77
+ constructor(
78
+ message: string,
79
+ readonly status: number,
80
+ readonly endpoint: string,
81
+ ) {
82
+ super(message);
83
+ this.name = 'ScmError';
84
+ }
85
+ }
86
+
87
+ /* -------------------------------------------------------------------------- */
88
+ /* Provider */
89
+ /* -------------------------------------------------------------------------- */
90
+
91
+ export class GitHubProvider implements ScmProvider {
92
+ readonly name = 'github';
93
+
94
+ readonly #owner: string;
95
+ readonly #repo: string;
96
+ readonly #token: string;
97
+ readonly #base: string;
98
+ readonly #apiBase: string;
99
+ readonly #fetch: typeof globalThis.fetch;
100
+
101
+ constructor(options: GitHubProviderOptions) {
102
+ this.#owner = options.owner;
103
+ this.#repo = options.repo;
104
+ this.#token = options.token;
105
+ this.#base = options.baseBranch ?? 'main';
106
+ this.#apiBase = options.apiBase ?? 'https://api.github.com';
107
+ this.#fetch = options.fetch ?? globalThis.fetch;
108
+ }
109
+
110
+ get #repoPath(): string {
111
+ return `repos/${this.#owner}/${this.#repo}`;
112
+ }
113
+
114
+ async #request<T>(
115
+ method: string,
116
+ endpoint: string,
117
+ body?: unknown,
118
+ ): Promise<T> {
119
+ const response = await this.#fetch(`${this.#apiBase}/${endpoint}`, {
120
+ method,
121
+ headers: {
122
+ accept: 'application/vnd.github+json',
123
+ authorization: `Bearer ${this.#token}`,
124
+ 'x-github-api-version': '2022-11-28',
125
+ ...(body === undefined ? {} : { 'content-type': 'application/json' }),
126
+ },
127
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
128
+ });
129
+
130
+ if (!response.ok) {
131
+ // Body may carry GitHub's error detail; never include request headers.
132
+ const detail = await response.text().catch(() => '');
133
+ throw new ScmError(
134
+ `${method} ${endpoint} failed: ${response.status}${detail ? ` — ${detail.slice(0, 500)}` : ''}`,
135
+ response.status,
136
+ endpoint,
137
+ );
138
+ }
139
+
140
+ if (response.status === 204) return undefined as T;
141
+ return (await response.json()) as T;
142
+ }
143
+
144
+ /* ---------------------------------------------------------------------- */
145
+ /* Commit */
146
+ /* ---------------------------------------------------------------------- */
147
+
148
+ /**
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 Writ
151
+ * Drop that lands as eight separate commits is eight Hansard-visible events
152
+ * for one governance act.
153
+ */
154
+ async commit(message: string, files: readonly FileWrite[]): Promise<CommitRef> {
155
+ const ref = await this.#request<{ object: { sha: string } }>(
156
+ 'GET',
157
+ `${this.#repoPath}/git/ref/heads/${this.#base}`,
158
+ );
159
+ const headSha = ref.object.sha;
160
+
161
+ const head = await this.#request<{ tree: { sha: string } }>(
162
+ 'GET',
163
+ `${this.#repoPath}/git/commits/${headSha}`,
164
+ );
165
+
166
+ const blobs = await Promise.all(
167
+ files.map(async (file) => {
168
+ const blob = await this.#request<{ sha: string }>(
169
+ 'POST',
170
+ `${this.#repoPath}/git/blobs`,
171
+ { content: file.content, encoding: 'utf-8' },
172
+ );
173
+ return { path: file.path, mode: '100644', type: 'blob', sha: blob.sha };
174
+ }),
175
+ );
176
+
177
+ const tree = await this.#request<{ sha: string }>(
178
+ 'POST',
179
+ `${this.#repoPath}/git/trees`,
180
+ { base_tree: head.tree.sha, tree: blobs },
181
+ );
182
+
183
+ const commit = await this.#request<{ sha: string; html_url: string }>(
184
+ 'POST',
185
+ `${this.#repoPath}/git/commits`,
186
+ { message, tree: tree.sha, parents: [headSha] },
187
+ );
188
+
189
+ await this.#request('PATCH', `${this.#repoPath}/git/refs/heads/${this.#base}`, {
190
+ sha: commit.sha,
191
+ });
192
+
193
+ return { id: commit.sha, sha: commit.sha, url: commit.html_url };
194
+ }
195
+
196
+ /* ---------------------------------------------------------------------- */
197
+ /* Motions and Divisions */
198
+ /* ---------------------------------------------------------------------- */
199
+
200
+ async openPR(title: string, body: string, branch: string): Promise<MotionRef> {
201
+ const pr = await this.#request<{ number: number; html_url: string; id: number }>(
202
+ 'POST',
203
+ `${this.#repoPath}/pulls`,
204
+ { title, body, head: branch, base: this.#base },
205
+ );
206
+ return {
207
+ id: String(pr.id),
208
+ number: pr.number,
209
+ branch,
210
+ url: pr.html_url,
211
+ };
212
+ }
213
+
214
+ async requestReview(pr: number, actors: readonly string[]): Promise<DivisionRef> {
215
+ const result = await this.#request<{ html_url: string; id: number }>(
216
+ 'POST',
217
+ `${this.#repoPath}/pulls/${pr}/requested_reviewers`,
218
+ { reviewers: [...actors] },
219
+ );
220
+ return {
221
+ id: String(result.id),
222
+ url: result.html_url,
223
+ motion: pr,
224
+ reviewers: [...actors],
225
+ };
226
+ }
227
+
228
+ /**
229
+ * ASSENT — enact a carried Motion.
230
+ *
231
+ * Note: `fast_forward` maps to GitHub's `rebase` method, the closest
232
+ * available behaviour (no merge node). Charter rule 6 already restricts
233
+ * fast_forward to quorum-1 sessions, where no Division needs evidencing.
234
+ */
235
+ async merge(pr: number, strategy: MergeStrategy): Promise<AssentResult> {
236
+ const result = await this.#request<{ sha: string; merged: boolean; message: string }>(
237
+ 'PUT',
238
+ `${this.#repoPath}/pulls/${pr}/merge`,
239
+ { merge_method: MERGE_METHODS[strategy] },
240
+ );
241
+ return {
242
+ id: result.sha,
243
+ sha: result.sha,
244
+ url: `https://github.com/${this.#owner}/${this.#repo}/pull/${pr}`,
245
+ motion: pr,
246
+ strategy,
247
+ merged: result.merged,
248
+ };
249
+ }
250
+
251
+ /* ---------------------------------------------------------------------- */
252
+ /* Escalations and deliberation */
253
+ /* ---------------------------------------------------------------------- */
254
+
255
+ async openIssue(
256
+ title: string,
257
+ body: string,
258
+ labels: readonly string[],
259
+ ): Promise<EscalationRef> {
260
+ const issue = await this.#request<{ number: number; html_url: string; id: number }>(
261
+ 'POST',
262
+ `${this.#repoPath}/issues`,
263
+ { title, body, labels: [...labels] },
264
+ );
265
+ return { id: String(issue.id), number: issue.number, url: issue.html_url };
266
+ }
267
+
268
+ /**
269
+ * Not implemented.
270
+ *
271
+ * GitHub exposes discussion creation only through GraphQL — there is no REST
272
+ * endpoint. Adopting it would put a second protocol, a second auth path, and
273
+ * a second failure mode inside an otherwise REST-only provider, and GraphQL
274
+ * requires a category *ID* where the interface specifies a category. Neither
275
+ * change is sanctioned by POLITIK-ARCHITECTURE.md.
276
+ *
277
+ * Nothing in Phase 2 exercises the debate floor; Discussions first matter in
278
+ * Phase 4. Deferred until then rather than bending the interface to a
279
+ * platform detail.
280
+ */
281
+ async openDiscussion(_title: string, _body: string, _category: string): Promise<Ref> {
282
+ throw new ScmError(
283
+ 'openDiscussion is not implemented for the GitHub provider — GitHub Discussions are GraphQL-only. Deferred to Phase 4.',
284
+ 501,
285
+ 'openDiscussion',
286
+ );
287
+ }
288
+
289
+ /* ---------------------------------------------------------------------- */
290
+ /* Session lifecycle and admin */
291
+ /* ---------------------------------------------------------------------- */
292
+
293
+ async closeMilestone(id: string): Promise<void> {
294
+ await this.#request('PATCH', `${this.#repoPath}/milestones/${id}`, {
295
+ state: 'closed',
296
+ });
297
+ }
298
+
299
+ /**
300
+ * Out-of-band notification.
301
+ *
302
+ * GitHub has no direct-message API, so this opens a labelled issue
303
+ * @-mentioning the actor. GitHub's own notification settings turn that into
304
+ * the Speaker's email — which is the delivery path the architecture assumes
305
+ * ("Receives Points of Order — SCM Issues + email").
306
+ */
307
+ async notify(actor: string, message: string): Promise<void> {
308
+ await this.#request('POST', `${this.#repoPath}/issues`, {
309
+ title: `Notification: ${actor}`,
310
+ body: `@${actor}\n\n${message}`,
311
+ labels: ['politik:notification'],
312
+ });
313
+ }
314
+
315
+ async triggerWorkflow(
316
+ name: string,
317
+ inputs: Readonly<Record<string, string>>,
318
+ ): Promise<Ref> {
319
+ await this.#request(
320
+ 'POST',
321
+ `${this.#repoPath}/actions/workflows/${name}/dispatches`,
322
+ { ref: this.#base, inputs },
323
+ );
324
+ // Dispatch returns 204 with no body; the run is addressed by workflow name.
325
+ return {
326
+ id: name,
327
+ url: `https://github.com/${this.#owner}/${this.#repo}/actions/workflows/${name}`,
328
+ };
329
+ }
330
+
331
+ async createLabel(name: string, color: string): Promise<Ref> {
332
+ const label = await this.#request<{ id: number; url: string }>(
333
+ 'POST',
334
+ `${this.#repoPath}/labels`,
335
+ { name, color: color.replace(/^#/, '') },
336
+ );
337
+ return { id: String(label.id), url: label.url };
338
+ }
339
+
340
+ async addCollaborator(grant: CollaboratorGrant): Promise<void> {
341
+ await this.#request(
342
+ 'PUT',
343
+ `${this.#repoPath}/collaborators/${grant.handle}`,
344
+ { permission: ROLE_PERMISSIONS[grant.role] },
345
+ );
346
+ }
347
+ }