@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.
Files changed (81) hide show
  1. package/EXECUTION.md +90 -85
  2. package/POLITIK-ARCHITECTURE.md +111 -176
  3. package/PROTOCOLS.md +120 -289
  4. package/README.md +130 -177
  5. package/RESEARCH.md +142 -436
  6. package/RUNTIME.md +253 -261
  7. package/docs/adr/0001-chamber-transport.md +2 -0
  8. package/docs/adr/0002-charter-schema.md +2 -0
  9. package/docs/adr/0003-state-json-schema.md +2 -0
  10. package/docs/adr/0004-motion-enactment.md +2 -0
  11. package/docs/adr/0005-hansard-format.md +2 -0
  12. package/docs/adr/0006-protocol-behavioral-enforcement.md +2 -0
  13. package/docs/adr/0007-protocol-mechanics.md +2 -0
  14. package/docs/adr/0008-session-storage.md +2 -0
  15. package/docs/adr/0009-match-primitive.md +2 -0
  16. package/docs/adr/0010-operator-interface.md +2 -0
  17. package/docs/adr/0011-shared-sessions.md +2 -0
  18. package/docs/adr/0012-plain-vocabulary.md +68 -0
  19. package/docs/adr/0013-rule-defined-protocols.md +89 -0
  20. package/package.json +1 -1
  21. package/protocols/CONTRIBUTING.md +47 -87
  22. package/protocols/adversarial-review.yml +19 -0
  23. package/protocols/elimination-rounds.yml +18 -0
  24. package/protocols/majority-vote.yml +18 -0
  25. package/protocols/panel-review.yml +19 -0
  26. package/protocols/single-decider.yml +18 -0
  27. package/protocols/unanimous-vote.yml +17 -0
  28. package/src/actors.ts +124 -100
  29. package/src/agents.ts +64 -23
  30. package/src/ballot.ts +747 -0
  31. package/src/canon.ts +23 -10
  32. package/src/capability.ts +16 -99
  33. package/src/charter.ts +41 -34
  34. package/src/cli.ts +541 -480
  35. package/src/{prorogation.ts → closing.ts} +43 -43
  36. package/src/conflict.ts +14 -14
  37. package/src/containment.ts +11 -11
  38. package/src/doctor.ts +1 -1
  39. package/src/election.ts +4 -4
  40. package/src/envelope.ts +3 -3
  41. package/src/escalation.ts +44 -44
  42. package/src/fault.ts +8 -8
  43. package/src/federation.ts +14 -14
  44. package/src/git.ts +21 -18
  45. package/src/heartbeat.ts +32 -32
  46. package/src/index.ts +5 -5
  47. package/src/init.ts +66 -65
  48. package/src/integrity.ts +30 -30
  49. package/src/ledger.ts +3 -3
  50. package/src/{hansard.ts → log.ts} +20 -20
  51. package/src/{crisis.ts → misconduct.ts} +70 -70
  52. package/src/operator.ts +5 -5
  53. package/src/pending.ts +9 -9
  54. package/src/projection.ts +30 -30
  55. package/src/protocol-sdk.ts +12 -121
  56. package/src/protocol.ts +8 -78
  57. package/src/providers/github.ts +12 -12
  58. package/src/quorum.ts +7 -7
  59. package/src/remote.ts +1 -1
  60. package/src/runner.ts +134 -55
  61. package/src/scm.ts +14 -14
  62. package/src/spawn.ts +4 -4
  63. package/src/standings.ts +13 -13
  64. package/src/state.ts +6 -6
  65. package/src/templates/session.ts +448 -0
  66. package/src/tournament.ts +20 -20
  67. package/src/transport.ts +4 -4
  68. package/src/tree.ts +16 -16
  69. package/protocols/adversarial-collaboration.yml +0 -28
  70. package/protocols/corporate.yml +0 -35
  71. package/protocols/elimination-tournament.yml +0 -41
  72. package/protocols/emergency-response-ics.yml +0 -27
  73. package/protocols/jury-deliberation.yml +0 -32
  74. package/protocols/monarchy.yml +0 -31
  75. package/protocols/parliamentary.yml +0 -66
  76. package/protocols/peer-review.yml +0 -44
  77. package/protocols/republic.yml +0 -36
  78. package/protocols/socialism-collective.yml +0 -31
  79. package/protocols/solo.yml +0 -32
  80. package/src/division.ts +0 -609
  81. package/src/templates/parliamentary.ts +0 -580
package/src/quorum.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * Quorum check.
3
3
  *
4
- * Quorum is the minimum number of actors for a valid Division
4
+ * Quorum is the minimum number of actors for a valid vote
5
5
  * (RUNTIME.md § SESSION QUORUM, MINIMUM CAST AND SINGLE-PLAYER SESSIONS).
6
6
  * Two distinct gates live here and are frequently confused:
7
7
  *
8
- * - **minimum_cast** — a Writ Drop gate. Are the required constituencies
8
+ * - **minimum_cast** — a session opening gate. Are the required constituencies
9
9
  * declared at all? Enforced by the Charter validator (ADR-0002 rule 3).
10
10
  * - **quorum** — a runtime gate. Are enough actors *present right now* for a
11
- * Division to be valid? That is this module.
11
+ * vote to be valid? That is this module.
12
12
  *
13
13
  * `quorum: 1` is a legitimate configuration, not a degenerate one: a
14
14
  * single-player session whose governance value is the audit trail and the
@@ -24,8 +24,8 @@ import type { Role } from './canon.ts';
24
24
  /* -------------------------------------------------------------------------- */
25
25
 
26
26
  /**
27
- * A Speaker's explicit acknowledgement that the session proceeds with a
28
- * reduced cast. Always visible in the Hansard — it cannot be hidden.
27
+ * An owner's explicit acknowledgement that the session proceeds with a
28
+ * reduced cast. Always visible in the record — it cannot be hidden.
29
29
  */
30
30
  export interface QuorumOverride {
31
31
  readonly enabled: boolean;
@@ -40,7 +40,7 @@ export interface QuorumOverride {
40
40
  /* -------------------------------------------------------------------------- */
41
41
 
42
42
  export interface QuorumResult {
43
- /** May a Division proceed? */
43
+ /** May a vote proceed? */
44
44
  readonly met: boolean;
45
45
  readonly required: number;
46
46
  readonly present: number;
@@ -116,7 +116,7 @@ export const checkQuorum = (input: QuorumInput): QuorumResult => {
116
116
  };
117
117
 
118
118
  /**
119
- * Render the Hansard fields for a quorum decision.
119
+ * Render the record fields for a quorum decision.
120
120
  *
121
121
  * A degraded session must be legible to any later reviewer, so the override
122
122
  * and its reason are recorded as fields rather than buried in prose.
package/src/remote.ts CHANGED
@@ -117,7 +117,7 @@ export const configureClone = async (dir: string, handle: string | null): Promis
117
117
  const branch = await currentBranch(dir);
118
118
  if (branch === null) return null;
119
119
  // Acts commit under this clone's git identity. A machine with none configured
120
- // gets the seat handle, the same convention Writ Drop uses for the Speaker.
120
+ // gets the seat handle, the same convention session opening uses for the owner.
121
121
  if (handle !== null && (await config(dir, 'user.name')) === null) {
122
122
  await gitx(dir, ['config', 'user.name', handle]);
123
123
  await gitx(dir, ['config', 'user.email', `${handle}@politik.local`]);
package/src/runner.ts CHANGED
@@ -17,16 +17,18 @@
17
17
  */
18
18
 
19
19
  import { spawn } from 'node:child_process';
20
+ import { existsSync } from 'node:fs';
20
21
  import { readFile, writeFile } from 'node:fs/promises';
21
- import { join } from 'node:path';
22
+ import { dirname, join, resolve } from 'node:path';
23
+ import { fileURLToPath } from 'node:url';
22
24
 
23
25
  import { findAgent, composePrompt, type AgentSpec } from './agents.ts';
24
- import type { Role, Verb } from './canon.ts';
26
+ import { ROLE_VERBS, type Role, type Verb } from './canon.ts';
25
27
  import { parseCharter, type Charter } from './charter.ts';
26
28
  import { parseEnvelope, claimSlot, type Envelope } from './envelope.ts';
27
29
  import { standForElection, bowOut, type ElectionOptions } from './election.ts';
28
30
  import { nodeLockFs } from './lockfs.ts';
29
- import { appendEntry, type HansardEntry } from './hansard.ts';
31
+ import { appendEntry, parseEntries, type RecordEntry } from './log.ts';
30
32
  import { spawnAgent, type SpawnResult } from './spawn.ts';
31
33
  import {
32
34
  appendLedgerRow, parseResultText, parseUsage, type Usage,
@@ -48,7 +50,7 @@ export interface RunOptions {
48
50
  readonly dir: string;
49
51
  /** Registry id of the agent to seat, e.g. `claude-code`. */
50
52
  readonly agent_id: string;
51
- /** Handle recorded in the Hansard for this agent. */
53
+ /** Handle recorded in the log for this agent. */
52
54
  readonly actor: string;
53
55
  /** Constituency to seat the agent in. */
54
56
  readonly role: Role;
@@ -92,12 +94,12 @@ export type RunOutcome =
92
94
  | {
93
95
  readonly ok: true;
94
96
  readonly result: SpawnResult;
95
- readonly entry: HansardEntry;
97
+ readonly entry: RecordEntry;
96
98
  readonly files_touched: readonly string[];
97
- /** The turn completed but the agent filed a Point of Order, so the sitting is now suspended. */
99
+ /** The turn completed but the agent filed an escalation, so the session is now suspended. */
98
100
  readonly suspended?: boolean;
99
101
  }
100
- | { readonly ok: false; readonly reason: string; readonly entry?: HansardEntry };
102
+ | { readonly ok: false; readonly reason: string; readonly entry?: RecordEntry };
101
103
 
102
104
  /* -------------------------------------------------------------------------- */
103
105
  /* Helpers */
@@ -122,7 +124,11 @@ const git = (dir: string, args: readonly string[], spawnFn: typeof spawn): Promi
122
124
  child.stdout?.on('data', (c: Buffer) => {
123
125
  output += c.toString();
124
126
  });
125
- child.on('close', () => resolve(output.trim()));
127
+ // trimEnd, not trim: `git status --porcelain` lines start with a status
128
+ // column that may be a space (" M file"). Trimming the front stripped it
129
+ // from the first line, so the first unstaged file lost its first letter
130
+ // ("ANSARD.md") and a hand edit of the record went unflagged.
131
+ child.on('close', () => resolve(output.trimEnd()));
126
132
  child.on('error', () => resolve(''));
127
133
  });
128
134
 
@@ -140,7 +146,7 @@ const head = (dir: string, spawnFn: typeof spawn): Promise<string> =>
140
146
  /**
141
147
  * Files the agent touched — committed *or* left in the tree.
142
148
  *
143
- * Both halves are necessary. The Standing Orders tell agents "commit your
149
+ * Both halves are necessary. The Charter tell agents "commit your
144
150
  * result; uncommitted work does not exist", so a well-behaved agent leaves a
145
151
  * clean tree and a new commit — and a working-tree diff alone would report that
146
152
  * it did nothing. The first live session did exactly this: the agent wrote and
@@ -169,9 +175,9 @@ const filesTouched = async (
169
175
  return [...new Set([...committed, ...newlyDirty])];
170
176
  };
171
177
 
172
- /** Last N entries of the Hansard, as context for a stateless agent. */
173
- const recentRecord = (hansard: string, entries = 3): string => {
174
- const parts = hansard.split(/^## /m).slice(1);
178
+ /** Last N entries of the record, as context for a stateless agent. */
179
+ const recentRecord = (log: string, entries = 3): string => {
180
+ const parts = log.split(/^## /m).slice(1);
175
181
  return parts
176
182
  .slice(-entries)
177
183
  .map((p) => `## ${p.trim()}`)
@@ -240,7 +246,7 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
240
246
  ].join('\n');
241
247
 
242
248
  // Capability gate. The architecture is explicit that the engine "validates
243
- // model compliance at Writ Drop and refuses to spawn a mismatched model
249
+ // model compliance at session opening and refuses to spawn a mismatched model
244
250
  // regardless of operator assignment" — so a mismatch is refused here, before
245
251
  // an agent is spawned, not noticed afterwards.
246
252
  const seat = charter.constituencies.find((c) => c.role === options.role);
@@ -276,7 +282,7 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
276
282
  envelope = envelopeResult.envelope;
277
283
  }
278
284
 
279
- // Elect into the constituency. Local scope only — the Hansard commit is the
285
+ // Elect into the constituency. Local scope only — the record commit is the
280
286
  // global arbiter, and this lock merely grants the right to attempt it.
281
287
  const election: ElectionOptions = {
282
288
  fs: nodeLockFs,
@@ -303,15 +309,23 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
303
309
  }
304
310
 
305
311
  try {
306
- const hansard = (await readIf(join(options.dir, 'HANSARD.md'))) ?? '';
312
+ const log = (await readIf(join(options.dir, 'LOG.md'))) ?? '';
307
313
 
308
314
  const prompt = composePrompt({
309
315
  envelope,
310
316
  role: options.role,
311
- verbs: options.verbs ?? ['READ', 'WRITE', 'ESCALATE'],
317
+ // The role's own verbs, minus ESCALATE where the protocol allows no appeals.
318
+ // A fixed READ/WRITE/ESCALATE list here told voting roles they could not vote.
319
+ // A role the Charter gives a domain veto also holds VETO.
320
+ verbs: options.verbs ?? [
321
+ ...(ROLE_VERBS[options.role] ?? ['READ'])
322
+ .filter((v) => v !== 'ESCALATE' || charter.session.escalation !== 'disabled'),
323
+ ...(charter.domain_veto.includes(options.role) && !(ROLE_VERBS[options.role] ?? []).includes('VETO')
324
+ ? (['VETO'] as const) : []),
325
+ ],
312
326
  protocol: charter.protocol,
313
327
  standing_orders: charter.body,
314
- hansard_excerpt: recentRecord(hansard),
328
+ log_excerpt: recentRecord(log),
315
329
  escalation_enabled: charter.session.escalation !== 'disabled',
316
330
  });
317
331
 
@@ -319,6 +333,27 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
319
333
  const beforeDirty = await dirtyFiles(options.dir, spawnFn);
320
334
 
321
335
  const measure = options.measure !== false && agent.json_args !== undefined;
336
+
337
+ // Per-turn grants for harnesses that sandbox their own shell (agents.ts
338
+ // session_args): the session's git directory, which an enclosing repo may
339
+ // own, and where this CLI runs from, so the agent can act through it.
340
+ const gitDir =
341
+ (await git(options.dir, ['rev-parse', '--absolute-git-dir'], spawnFn)) ||
342
+ join(resolve(options.dir), '.git');
343
+ const politikRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
344
+ // Where the agent will find `politik`: the directory it was invoked from and
345
+ // the one holding it on PATH (a global npm bin often lives under $HOME,
346
+ // which a sandbox hides). Read-only grants, deduplicated.
347
+ const invokedFrom = process.argv[1] === undefined ? null : dirname(resolve(process.argv[1]));
348
+ const onPath = (process.env['PATH'] ?? '')
349
+ .split(':')
350
+ .find((d) => d !== '' && existsSync(join(d, 'politik')));
351
+ const readPaths = [...new Set([politikRoot, invokedFrom, onPath === undefined ? null : resolve(onPath)])]
352
+ .filter((p): p is string => p !== null)
353
+ // A path inside the CLI's own install is already covered by politikRoot.
354
+ .filter((p) => p === politikRoot || !p.startsWith(`${politikRoot}/`));
355
+ const sessionArgs = agent.session_args?.({ git_dir: gitDir, read_paths: readPaths }) ?? [];
356
+ const turnArgs = [...(measure ? (agent.json_args ?? []) : []), ...sessionArgs];
322
357
  const sleepFn = options.sleepFn ?? ((ms: number) => new Promise((r) => setTimeout(r, ms)));
323
358
  const policy = {
324
359
  auto_retry_max: charter.fault_handling.auto_retry_max,
@@ -333,12 +368,12 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
333
368
  cwd: options.dir,
334
369
  timeout_ms: options.timeout_ms,
335
370
  spawnFn,
336
- extraArgs: measure ? agent.json_args : undefined,
371
+ extraArgs: turnArgs,
337
372
  });
338
373
 
339
374
  let attempts = 1;
340
375
  let classification: Classification | null = null;
341
- const faultEntries: HansardEntry[] = [];
376
+ const faultEntries: RecordEntry[] = [];
342
377
 
343
378
  while (!result.ok) {
344
379
  classification = classify(result);
@@ -363,7 +398,7 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
363
398
  cwd: options.dir,
364
399
  timeout_ms: options.timeout_ms,
365
400
  spawnFn,
366
- extraArgs: measure ? agent.json_args : undefined,
401
+ extraArgs: turnArgs,
367
402
  });
368
403
  }
369
404
 
@@ -374,44 +409,81 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
374
409
  }
375
410
 
376
411
  // Structured output carries the answer inside a JSON envelope; unwrap it so
377
- // the Hansard records what the agent said, not how it was transported.
412
+ // the record shows what the agent said, not how it was transported.
378
413
  const usage: Usage | null = measure ? parseUsage(agent.id, result.stdout) : null;
379
414
  const answer = (measure ? parseResultText(agent.id, result.stdout) : null) ?? result.stdout;
380
415
 
381
416
  const touched = await filesTouched(options.dir, beforeHead, beforeDirty, spawnFn);
382
417
 
383
418
  // Files the RECORD agent owns exclusively (POLITIK-ARCHITECTURE.md
384
- // § File Sovereignty Rules). An actor writing to them is a Standing Orders
419
+ // § File Sovereignty Rules). An actor writing to them is a Charter
385
420
  // violation, and it must be recorded rather than silently tolerated —
386
421
  // a record an actor can write is not a record.
387
- const OWNED_BY_RECORD = ['HANSARD.md', 'STATE.json', 'LEDGER.md'];
388
- const violations = touched.filter((f) => OWNED_BY_RECORD.includes(f));
422
+ //
423
+ // An agent may also act *through the CLI* during its turn — cast a vote,
424
+ // open a vote — and those acts write and commit these same files. The
425
+ // record must keep them. So the files are read again after the turn, and a
426
+ // change to them is lawful only when it reached the record the way the CLI
427
+ // writes it: committed (nothing left dirty) and, for the record, purely
428
+ // appended. Anything else is a hand edit: a violation, and the record is
429
+ // restored from the pre-turn copy rather than carrying the edit forward.
430
+ const OWNED_BY_RECORD = ['LOG.md', 'STATE.json', 'LEDGER.md'];
431
+ const dirtyAfter = await dirtyFiles(options.dir, spawnFn);
432
+ const logAfter = (await readIf(join(options.dir, 'LOG.md'))) ?? '';
433
+ const logAppended =
434
+ logAfter.startsWith(log) && !dirtyAfter.includes('LOG.md');
435
+ const violations = touched.filter(
436
+ (f) =>
437
+ OWNED_BY_RECORD.includes(f) &&
438
+ (dirtyAfter.includes(f) || (f === 'LOG.md' && !logAppended)),
439
+ );
440
+ // Entries the CLI appended during the turn — votes, votes — kept as
441
+ // the base the turn's own entry is appended to.
442
+ const recordBase = logAppended ? logAfter : log;
443
+ const actsDuringTurn = logAppended
444
+ ? parseEntries(logAfter).length - parseEntries(log).length
445
+ : 0;
446
+ // The same rule for STATE.json: a committed CLI act may have moved it (a
447
+ // tally that deadlocks suspends the session), and the turn must not undo it.
448
+ const stateAfterRaw = dirtyAfter.includes('STATE.json')
449
+ ? null
450
+ : await readIf(join(options.dir, 'STATE.json'));
451
+ const stateBase =
452
+ (stateAfterRaw === null ? null : parseState(stateAfterRaw)) ?? state;
389
453
 
390
454
  // An agent that hits a decision above its authority is told (composePrompt,
391
- // Rules of the Floor) to file a Point of Order instead of proceeding. On a
392
- // hosted session the point-of-order workflow catches the pushed file and
455
+ // Rules of the Floor) to escalate instead of proceeding. On a
456
+ // hosted session the escalation workflow catches the pushed file and
393
457
  // suspends; a local session has no such watcher, so the runner closes the
394
458
  // loop: a new file under escalations/ — a ruling excepted, since that is the
395
- // Speaker's own reply — is an agent-filed Point of Order, and the sitting
459
+ // owner's own reply — is an agent-filed escalation, and the session
396
460
  // suspends pending a ruling exactly as the CLI `escalate` path does.
397
461
  const escalationFiles = touched.filter(
398
462
  (f) => f.startsWith('escalations/') && !f.slice('escalations/'.length).startsWith('ruling'),
399
463
  );
400
464
  // A protocol declaring no escalation (ADR-0006) has no mechanism to resolve a
401
- // Point of Order, so an agent's escalation file is recorded but does not
402
- // suspend — suspending would deadlock the sitting in a state it cannot lift.
465
+ // escalation, so an agent's escalation file is recorded but does not
466
+ // suspend — suspending would deadlock the session in a state it cannot lift.
403
467
  const escalationDisabled = charter.session.escalation === 'disabled';
404
468
  const agentEscalated = escalationFiles.length > 0 && !escalationDisabled;
405
469
  const escalationIgnored = escalationFiles.length > 0 && escalationDisabled;
406
470
 
407
471
  // Hard Containment Rule. Checked after the turn because it is detection,
408
472
  // not prevention — a spawned process runs with the OS's permissions and
409
- // nothing here can stop it. The Hansard records what happened, which is the
473
+ // nothing here can stop it. The record shows what happened, which is the
410
474
  // framework's answer to most of what it cannot prevent.
411
475
  const containment = checkContainment(options.dir, touched, `${result.stdout}\n${answer}`);
412
476
 
413
- const entry: HansardEntry = {
414
- type: result.ok ? 'MOTION_TABLED' : 'SESSION_FAULT',
477
+ // Work is any file the turn touched other than the record and escalations.
478
+ const producedWork = touched.some(
479
+ (f) => !OWNED_BY_RECORD.includes(f) && !f.startsWith('escalations/'),
480
+ );
481
+
482
+ const entry: RecordEntry = {
483
+ // A turn that produced work tabled a motion. A turn that only read, or acted
484
+ // through the CLI (a vote, an escalation), tabled nothing: recording it as
485
+ // MOTION_TABLED misread every review as a proposal.
486
+ type: !result.ok ? 'SESSION_FAULT' : producedWork ? 'MOTION_TABLED' : 'AGENT_TURN',
415
487
  at: options.now,
416
488
  actor: options.actor,
417
489
  role: options.role,
@@ -424,19 +496,22 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
424
496
  : `exit ${String(result.exit_code)}`,
425
497
  'Elapsed ms': String(result.elapsed_ms),
426
498
  'Files touched': touched.length > 0 ? touched.join(', ') : 'none',
499
+ ...(actsDuringTurn > 0
500
+ ? { 'Acts during turn': `${String(actsDuringTurn)} recorded through the CLI` }
501
+ : {}),
427
502
  ...(violations.length > 0
428
503
  ? {
429
- 'Standing Orders violation': `actor wrote to ${violations.join(', ')} — owned by RECORD`,
504
+ 'Charter violation': `actor wrote to ${violations.join(', ')} — owned by RECORD`,
430
505
  }
431
506
  : {}),
432
507
  ...(agentEscalated
433
508
  ? {
434
- 'Point of Order': `actor filed ${escalationFiles.join(', ')} — the sitting is suspended pending a Speaker ruling`,
509
+ 'escalation': `actor filed ${escalationFiles.join(', ')} — the session is suspended pending an owner ruling`,
435
510
  }
436
511
  : {}),
437
512
  ...(escalationIgnored
438
513
  ? {
439
- 'Point of Order': `actor filed ${escalationFiles.join(', ')} — ignored: this protocol declares no escalation`,
514
+ 'escalation': `actor filed ${escalationFiles.join(', ')} — ignored: this protocol declares no escalation`,
440
515
  }
441
516
  : {}),
442
517
  },
@@ -447,13 +522,13 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
447
522
 
448
523
  // Faults are recorded before the turn's own entry: they happened first, and
449
524
  // a reader should see the retries that led to the outcome.
450
- let record = hansard;
525
+ let record = recordBase;
451
526
  for (const fault of faultEntries) record = appendEntry(record, fault);
452
527
  record = appendEntry(record, entry);
453
528
 
454
- // A breach suspends the sitting: logged immediately, escalated to the
455
- // Speaker, paused pending a ruling (POLITIK-ARCHITECTURE.md § Hard
456
- // Containment Rule). The Point of Order flow already does exactly that, so
529
+ // A breach suspends the session: logged immediately, escalated to the
530
+ // Owner, paused pending a ruling (POLITIK-ARCHITECTURE.md § Hard
531
+ // Containment Rule). The escalation flow already does exactly that, so
457
532
  // the breach reuses it rather than inventing a parallel path.
458
533
  if (!containment.contained) {
459
534
  record = appendEntry(
@@ -462,7 +537,7 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
462
537
  );
463
538
  }
464
539
 
465
- await writeFile(join(options.dir, 'HANSARD.md'), record, 'utf8');
540
+ await writeFile(join(options.dir, 'LOG.md'), record, 'utf8');
466
541
 
467
542
  // The Clerk appends after every act. A turn that produced no ledger row
468
543
  // would be work the session cannot account for.
@@ -483,34 +558,38 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
483
558
  );
484
559
  }
485
560
 
486
- // The slot is consumed by the Hansard commit, not by winning the lock.
561
+ // The slot is consumed by the record commit, not by winning the lock.
487
562
  claimSlot(envelope);
488
563
 
489
- // Quorum is carried forward untouched. A turn is not a Division, and
564
+ // Quorum is carried forward untouched. A turn is not a vote, and
490
565
  // `present` counts actors eligible to vote — it was previously being
491
566
  // overwritten with the leftover broadcast slot count, which is a different
492
567
  // quantity entirely and made the figure meaningless.
493
- // The sitting suspends on a containment breach or an agent-filed Point of
494
- // Order — both pause pending a Speaker ruling, and both carry the same
495
- // POINT_OF_ORDER cause. A breach names no escalation file; an agent's Point
496
- // of Order does, so its path is recorded as the escalation reference.
568
+ // The session suspends on a containment breach or an agent-filed
569
+ // escalation — both pause pending an owner ruling, and both carry the same
570
+ // ESCALATION cause. A breach names no escalation file; an agent's
571
+ // escalation does, so its path is recorded as the escalation reference.
497
572
  const suspend = !containment.contained || agentEscalated;
573
+ // Built on the post-turn state, so a suspension or quorum change an act
574
+ // made during the turn survives; the turn only adds its own suspension.
498
575
  const nextState = createState({
499
- session_guid: state.session_guid,
500
- protocol: state.protocol,
501
- state: suspend ? 'SUSPENDED' : 'CONVENED',
576
+ session_guid: stateBase.session_guid,
577
+ protocol: stateBase.protocol,
578
+ state: suspend ? 'SUSPENDED' : stateBase.state,
502
579
  ...(suspend
503
580
  ? {
504
581
  suspension: {
505
- cause: 'POINT_OF_ORDER' as const,
582
+ cause: 'ESCALATION' as const,
506
583
  since: options.now,
507
- record_ref: 'HANSARD.md',
584
+ record_ref: 'LOG.md',
508
585
  escalation_ref: agentEscalated ? (escalationFiles[0] ?? null) : null,
509
586
  },
510
587
  }
511
- : {}),
512
- quorum: state.quorum,
513
- hansard_head: state.hansard_head,
588
+ : stateBase.suspension !== null
589
+ ? { suspension: stateBase.suspension }
590
+ : {}),
591
+ quorum: stateBase.quorum,
592
+ log_head: stateBase.log_head,
514
593
  updated_at: options.now,
515
594
  });
516
595
  await writeFile(join(options.dir, 'STATE.json'), serializeState(nextState), 'utf8');
@@ -518,7 +597,7 @@ export const runTurn = async (options: RunOptions): Promise<RunOutcome> => {
518
597
  if (!containment.contained) {
519
598
  return {
520
599
  ok: false,
521
- reason: `containment breach — ${containment.breaches.map((b) => b.evidence).join(', ')}; the sitting is suspended pending a Speaker ruling`,
600
+ reason: `containment breach — ${containment.breaches.map((b) => b.evidence).join(', ')}; the session is suspended pending an owner ruling`,
522
601
  entry,
523
602
  };
524
603
  }
package/src/scm.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * Design rules applied here:
10
10
  * - Every call is async. Every provider is a network boundary.
11
11
  * - Nothing returns a bare string. Each mutation returns a typed handle so the
12
- * Hansard writer has something attributable to record.
12
+ * record writer has something attributable to record.
13
13
  * - Provider-native identifiers stay opaque (`id`), with `url` carried
14
14
  * alongside for the human-readable record.
15
15
  *
@@ -26,7 +26,7 @@ import type { MergeStrategy, Role } from './canon.ts';
26
26
  export interface Ref {
27
27
  /** Opaque provider identifier. Never parsed by the engine. */
28
28
  readonly id: string;
29
- /** Human-readable location, recorded in the Hansard. */
29
+ /** Human-readable location, recorded in the log. */
30
30
  readonly url: string;
31
31
  }
32
32
 
@@ -41,19 +41,19 @@ export interface MotionRef extends Ref {
41
41
  readonly branch: string;
42
42
  }
43
43
 
44
- /** An ESCALATION — a Point of Order. */
44
+ /** An ESCALATION — an escalation. */
45
45
  export interface EscalationRef extends Ref {
46
46
  readonly number: number;
47
47
  }
48
48
 
49
- /** A DIVISION requested against a MOTION. */
50
- export interface DivisionRef extends Ref {
49
+ /** A BALLOT requested against a MOTION. */
50
+ export interface BallotRef extends Ref {
51
51
  readonly motion: number;
52
52
  readonly reviewers: readonly string[];
53
53
  }
54
54
 
55
55
  /** The enactment of a carried MOTION. */
56
- export interface AssentResult extends Ref {
56
+ export interface EnactResult extends Ref {
57
57
  readonly motion: number;
58
58
  readonly strategy: MergeStrategy;
59
59
  readonly merged: boolean;
@@ -89,7 +89,7 @@ export interface CollaboratorGrant {
89
89
  * below implements all eleven as listed in the architecture document.
90
90
  */
91
91
  export interface ScmProvider {
92
- /** Provider identifier, e.g. `github`. Recorded in the Hansard header. */
92
+ /** Provider identifier, e.g. `github`. Recorded in the record header. */
93
93
  readonly name: string;
94
94
 
95
95
  /** Write files to the session repo. The underlying act of every MOTION. */
@@ -98,17 +98,17 @@ export interface ScmProvider {
98
98
  /** Table a MOTION. */
99
99
  openPR(title: string, body: string, branch: string): Promise<MotionRef>;
100
100
 
101
- /** Call a DIVISION on a tabled MOTION. */
102
- requestReview(pr: number, actors: readonly string[]): Promise<DivisionRef>;
101
+ /** Call a BALLOT on a tabled MOTION. */
102
+ requestReview(pr: number, actors: readonly string[]): Promise<BallotRef>;
103
103
 
104
104
  /**
105
- * ASSENT — enact a carried MOTION. The Division decides; this enacts.
105
+ * ENACT — enact a carried MOTION. The vote decides; this enacts.
106
106
  * Callers must verify the Motion carried before invoking; providers reject
107
107
  * strategies the Charter did not permit.
108
108
  */
109
- merge(pr: number, strategy: MergeStrategy): Promise<AssentResult>;
109
+ merge(pr: number, strategy: MergeStrategy): Promise<EnactResult>;
110
110
 
111
- /** File an ESCALATION — a Point of Order. */
111
+ /** File an ESCALATION — an escalation. */
112
112
  openIssue(
113
113
  title: string,
114
114
  body: string,
@@ -122,10 +122,10 @@ export interface ScmProvider {
122
122
  category: string,
123
123
  ): Promise<Ref>;
124
124
 
125
- /** Close a milestone — used by the prorogation workflow. */
125
+ /** Close a milestone — used by the closing workflow. */
126
126
  closeMilestone(id: string): Promise<void>;
127
127
 
128
- /** Notify an actor out of band. Speaker email notification rides this. */
128
+ /** Notify an actor out of band. Owner email notification rides this. */
129
129
  notify(actor: string, message: string): Promise<void>;
130
130
 
131
131
  /** Trigger provider-side automation — the Clerk. */
package/src/spawn.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Agent spawning.
3
3
  *
4
4
  * The stateless worker cycle: spawn, execute prompt, capture result, dispose.
5
- * No agent outlives its turn, and no state lives in the process — the Hansard
5
+ * No agent outlives its turn, and no state lives in the process — the record
6
6
  * is the session.
7
7
  *
8
8
  * Kept separate from `agents.ts` so the registry, invocation shapes and prompt
@@ -58,13 +58,13 @@ const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;
58
58
  /**
59
59
  * Spawn an agent and capture its result.
60
60
  *
61
- * Never uses a shell. The prompt carries Charter text, Hansard excerpts and
61
+ * Never uses a shell. The prompt carries Charter text, record excerpts and
62
62
  * arbitrary session content; passing that through a shell would make every
63
63
  * spawn an injection site. Args go to the child directly.
64
64
  *
65
65
  * Rejects only on a spawn failure the OS reports (command not found, permission
66
66
  * denied). A non-zero exit is a *result*, not an exception — an agent that
67
- * fails its task has still participated, and the Hansard records the outcome
67
+ * fails its task has still participated, and the record shows the outcome
68
68
  * either way.
69
69
  */
70
70
  export const spawnAgent = async (
@@ -139,7 +139,7 @@ export const spawnAgent = async (
139
139
  /**
140
140
  * Is this agent's command present on PATH?
141
141
  *
142
- * Used at Writ Drop to fail fast: a Charter naming a constituency whose agent
142
+ * Used at session opening to fail fast: a Charter naming a constituency whose agent
143
143
  * is not installed should be caught before the session opens, not when the
144
144
  * first broadcast goes unanswered.
145
145
  */
package/src/standings.ts CHANGED
@@ -1,30 +1,30 @@
1
1
  /**
2
2
  * Standings — scoring a competitive protocol from the record.
3
3
  *
4
- * A tournament or league protocol runs as a series of Divisions; who fared how
5
- * is already in the Hansard, so — like `integrity.ts` and `federation.ts` — this
4
+ * A tournament or league protocol runs as a series of votes; who fared how
5
+ * is already in the record, so — like `integrity.ts` and `federation.ts` — this
6
6
  * is a pure read over the record, not new state. A "win" is voting with the side
7
- * a Division carried; elimination is the cull an `exit: elimination` protocol
7
+ * a vote carried; elimination is the cull an `exit: elimination` protocol
8
8
  * records (ADR-0007). Two rankings, because two questions get asked of a
9
9
  * tournament: who won the most (win-loss) and who lasted longest (survival).
10
10
  *
11
11
  * On `pairing`: Swiss / round-robin / single-elimination are 1v1-match formats,
12
- * and a Politik Division is an N-actor vote on a Motion — there is no match to
13
- * pair. Matchmaking needs a *match primitive* the Division model does not have;
12
+ * and a Politik vote is an N-actor vote on a Motion — there is no match to
13
+ * pair. Matchmaking needs a *match primitive* the vote model does not have;
14
14
  * that is an additive design, not a scoring read, and is deliberately not faked
15
15
  * here.
16
16
  *
17
17
  * Attribution: Steve Krisjanovs, Cordfuse
18
18
  */
19
19
 
20
- import { parseEntries } from './hansard.ts';
20
+ import { parseEntries } from './log.ts';
21
21
  import { seats } from './actors.ts';
22
22
 
23
23
  export interface Standing {
24
24
  readonly actor: string;
25
25
  /** Current role, or null if the actor is no longer seated. */
26
26
  readonly seat: string | null;
27
- /** Divisions won: voted with the side that carried (or lost, for rejected). */
27
+ /** votes won: voted with the side that carried (or lost, for rejected). */
28
28
  readonly wins: number;
29
29
  readonly losses: number;
30
30
  readonly eliminated: boolean;
@@ -42,11 +42,11 @@ export type RankBy = 'win-loss' | 'survival';
42
42
 
43
43
  /**
44
44
  * Score every actor who took part. A win is a vote on the carrying side of a
45
- * decided Division; a loss is a vote on the other side; an abstention is neither.
45
+ * decided vote; a loss is a vote on the other side; an abstention is neither.
46
46
  * Elimination and current seat come from the actor record.
47
47
  */
48
- export const standings = (hansard: string, by: RankBy = 'win-loss'): readonly Standing[] => {
49
- const entries = parseEntries(hansard);
48
+ export const standings = (log: string, by: RankBy = 'win-loss'): readonly Standing[] => {
49
+ const entries = parseEntries(log);
50
50
 
51
51
  // motion -> voter -> vote, and motion -> carried?
52
52
  const votes = new Map<string, Map<string, string>>();
@@ -110,18 +110,18 @@ export const standings = (hansard: string, by: RankBy = 'win-loss'): readonly St
110
110
  }
111
111
  }
112
112
 
113
- // Score decided Divisions.
113
+ // Score decided votes.
114
114
  for (const [motion, decided] of carried) {
115
115
  const cast = votes.get(motion);
116
116
  if (cast === undefined) continue;
117
117
  for (const [actor, vote] of cast) {
118
118
  if (vote === 'ABSTAIN') continue;
119
- const wonSide = (vote === 'AYE' && decided) || (vote === 'NO' && !decided);
119
+ const wonSide = (vote === 'YES' && decided) || (vote === 'NO' && !decided);
120
120
  bump(wonSide ? wins : losses, actor);
121
121
  }
122
122
  }
123
123
 
124
- const seated = new Map(seats(hansard).map((s) => [s.actor, s.role]));
124
+ const seated = new Map(seats(log).map((s) => [s.actor, s.role]));
125
125
 
126
126
  const rows: Standing[] = [...participants].map((actor) => ({
127
127
  actor,