@cordfuse/politik 0.3.0 → 0.4.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 +59 -58
- package/POLITIK-ARCHITECTURE.md +6 -5
- package/PROTOCOLS.md +130 -911
- package/README.md +85 -10
- package/RESEARCH.md +3 -3
- package/RUNTIME.md +52 -31
- package/docs/adr/0004-motion-enactment.md +1 -1
- package/docs/adr/0006-protocol-behavioral-enforcement.md +14 -7
- package/docs/adr/0007-protocol-mechanics.md +3 -3
- package/docs/adr/0009-match-primitive.md +17 -6
- package/docs/adr/0010-operator-interface.md +145 -0
- package/docs/adr/0011-shared-sessions.md +129 -0
- package/package.json +1 -1
- package/src/charter.ts +44 -0
- package/src/cli.ts +786 -43
- package/src/containment.ts +5 -2
- package/src/git.ts +8 -4
- package/src/init.ts +13 -0
- package/src/operator.ts +82 -0
- package/src/pending.ts +165 -0
- package/src/remote.ts +274 -0
- package/src/standings.ts +21 -1
- package/src/templates/parliamentary.ts +249 -28
- package/src/tournament.ts +124 -12
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# ADR-0011 — Shared Sessions Across Machines
|
|
2
|
+
|
|
3
|
+
**Attribution:** Steve Krisjanovs, Cordfuse
|
|
4
|
+
|
|
5
|
+
**Status:** Accepted — built (`src/remote.ts`; `politik remote` / `join` / `sync`, `init --remote`; sync-and-retry around acts; shared pending refs; `Politik-Operator` trailer; `signed_confirmations`). Stacked on ADR-0010.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Context
|
|
10
|
+
|
|
11
|
+
A session is a git repository, so anyone *could* clone it — but Politik assumed
|
|
12
|
+
one machine. Every act committed locally and nothing was ever pulled or pushed.
|
|
13
|
+
Two people acting at once on different machines each appended to `HANSARD.md`
|
|
14
|
+
and rewrote `STATE.json` from their own copy; their histories diverged and the
|
|
15
|
+
record itself became a merge conflict.
|
|
16
|
+
|
|
17
|
+
ADR-0001 covers the *nudge* between machines (git by default, NATS opt-in). It
|
|
18
|
+
never covered keeping the **record** consistent, and there was no way to say where
|
|
19
|
+
a shared session lives.
|
|
20
|
+
|
|
21
|
+
ADR-0010 made this sharper: pending acts were local files, so an act staged by a
|
|
22
|
+
harness on one machine was invisible to a Speaker on another.
|
|
23
|
+
|
|
24
|
+
Both shapes are in scope: several humans, each with their own harness, seated in
|
|
25
|
+
one session; and one Speaker with agents running elsewhere.
|
|
26
|
+
|
|
27
|
+
## Decision
|
|
28
|
+
|
|
29
|
+
**A session can be shared through any git remote. Sharing is explicit and
|
|
30
|
+
opt-in; a session that never configures it behaves exactly as before.**
|
|
31
|
+
|
|
32
|
+
### 1. Configuring and joining
|
|
33
|
+
|
|
34
|
+
- `politik remote <url>` makes a session shared: it sets the git remote, turns on
|
|
35
|
+
sync, and publishes the current history. `politik remote` alone shows the
|
|
36
|
+
configuration; `politik remote --off` stops syncing.
|
|
37
|
+
- `politik init --remote <url>` does the same at Writ Drop.
|
|
38
|
+
- `politik join <url> [dir] --as <handle>` clones a shared session, checks it is a
|
|
39
|
+
session with intact seals, turns on sync and records who the person is (their
|
|
40
|
+
seat handle, see §4). Then they open their own harness there, as in ADR-0010.
|
|
41
|
+
|
|
42
|
+
The configuration lives in the clone's git config (`politik.sync`,
|
|
43
|
+
`politik.remote`, `politik.branch`, `politik.handle`), not in the session's
|
|
44
|
+
files: it describes this machine, not the proceeding.
|
|
45
|
+
|
|
46
|
+
### 2. Sync on every act, with a safe retry
|
|
47
|
+
|
|
48
|
+
For a shared session, every governance command runs as:
|
|
49
|
+
|
|
50
|
+
1. **fetch** the remote and **fast-forward** to the latest record;
|
|
51
|
+
2. run the act, which commits locally;
|
|
52
|
+
3. **push**.
|
|
53
|
+
|
|
54
|
+
If the push is rejected because someone else acted first, the local act is
|
|
55
|
+
discarded (`reset --hard` to where it started), the record is fast-forwarded again,
|
|
56
|
+
and the act is **recomputed** against the new record — up to three attempts. This
|
|
57
|
+
is safe because every act is computed from the current record; redoing it is not
|
|
58
|
+
the same as merging it. Output from discarded attempts is withheld, so the
|
|
59
|
+
operator only ever sees the act that was actually recorded (the "record, then
|
|
60
|
+
report" rule holds across machines). Nobody hand-merges the Hansard.
|
|
61
|
+
|
|
62
|
+
**Long-running acts are not retried.** `politik run` spawns an agent; re-running it
|
|
63
|
+
would re-run the agent. If its push is rejected, the commit stays local and the
|
|
64
|
+
operator is told to run `politik sync`.
|
|
65
|
+
|
|
66
|
+
**`politik sync`** fetches, fast-forwards, pushes local commits, and refreshes
|
|
67
|
+
pending acts. If local and remote have genuinely diverged it attempts a rebase and,
|
|
68
|
+
on conflict, aborts and explains rather than guessing.
|
|
69
|
+
|
|
70
|
+
**Reads** (`status`, `hansard`, `pending`, …) fetch first when they can and quietly
|
|
71
|
+
fall back to the local copy when the remote is unreachable.
|
|
72
|
+
|
|
73
|
+
### 3. Offline: governance refuses, reads keep working
|
|
74
|
+
|
|
75
|
+
If the remote cannot be reached, governance acts on a shared session **refuse**.
|
|
76
|
+
Acting offline and pushing later lets acts land out of order — the divergence this
|
|
77
|
+
ADR exists to prevent. Reads still work from the local copy.
|
|
78
|
+
|
|
79
|
+
### 4. Shared pending acts and who may confirm them
|
|
80
|
+
|
|
81
|
+
For a shared session, a staged act (ADR-0010) is stored as a git ref,
|
|
82
|
+
`refs/politik/pending/<id>`, pointing at a commit that holds the act. These refs
|
|
83
|
+
are pushed and fetched with the session but are **never part of its history**:
|
|
84
|
+
nothing staged is the record. `politik pending` on any machine lists them;
|
|
85
|
+
`politik confirm` on any machine executes one; confirming or rejecting deletes the
|
|
86
|
+
ref everywhere.
|
|
87
|
+
|
|
88
|
+
**Only the seat the act names may confirm it.** Each clone records its person's
|
|
89
|
+
seat handle (`politik.handle`, set by `join --as`, falling back to git
|
|
90
|
+
`user.name`). `confirm` refuses unless that handle matches the act's `--actor` —
|
|
91
|
+
the Speaker confirms the Speaker's assent; nobody confirms it on their behalf.
|
|
92
|
+
|
|
93
|
+
This is identity by configuration, not proof: anyone can set a name. Where proof
|
|
94
|
+
matters, the Charter sets `session.signed_confirmations: required` (§5).
|
|
95
|
+
|
|
96
|
+
### 5. Identity on the record
|
|
97
|
+
|
|
98
|
+
Every governance commit carries a third trailer naming the person operating that
|
|
99
|
+
clone:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
Politik-Requested-Via: claude-code_2-1-283_agent
|
|
103
|
+
Politik-Confirmed-By: speaker-at-terminal
|
|
104
|
+
Politik-Operator: steve <steve@example.com>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Under `session.signed_confirmations: required`, a confirmed act's commit is
|
|
108
|
+
GPG/SSH-signed with the confirming person's git signing key, and confirmation
|
|
109
|
+
refuses if signing fails. `politik integrity` reports any confirmed commit whose
|
|
110
|
+
signature does not verify.
|
|
111
|
+
|
|
112
|
+
## Threat model
|
|
113
|
+
|
|
114
|
+
Sync makes the record consistent across machines; it does not make every machine
|
|
115
|
+
trustworthy. Who can act at all is who can push to the remote — Politik's existing
|
|
116
|
+
model ("repo access = taking a seat"), enforced by the host (branch protection,
|
|
117
|
+
access control). The handle check stops honest mistakes and casual impersonation;
|
|
118
|
+
signed confirmations stop forgery by anyone without the confirming person's key.
|
|
119
|
+
ADR-0010's limits still apply on each machine.
|
|
120
|
+
|
|
121
|
+
## Consequences
|
|
122
|
+
|
|
123
|
+
- Several people and their agents can share one session from different machines,
|
|
124
|
+
each through their own harness.
|
|
125
|
+
- The record never needs a manual merge in normal use.
|
|
126
|
+
- A shared session needs the remote to be reachable to act.
|
|
127
|
+
- Retried acts that project to an SCM provider (ADR-0004) may attempt the
|
|
128
|
+
projection again; projection is recorded either way, so a duplicate attempt is
|
|
129
|
+
visible rather than silent.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cordfuse/politik",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Politik — a governed multi-agent framework built on git. The SCM repository is the session: charter, record, state, and invite in one.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/charter.ts
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { createHash } from 'node:crypto';
|
|
16
|
+
|
|
15
17
|
import { parse as parseYaml } from 'yaml';
|
|
16
18
|
|
|
17
19
|
import {
|
|
@@ -24,6 +26,35 @@ import type { ProtocolRecordMode } from './protocol.ts';
|
|
|
24
26
|
import { isResolution, isExitPolicy, type Resolution, type ExitPolicy } from './division.ts';
|
|
25
27
|
import { isTerminationPolicy, type TerminationPolicy } from './prorogation.ts';
|
|
26
28
|
|
|
29
|
+
/**
|
|
30
|
+
* A content fingerprint of a Charter's source text.
|
|
31
|
+
*
|
|
32
|
+
* Recorded on the WRIT_DROP entry at session open so an immutable-charter
|
|
33
|
+
* protocol (ADR-0007 `immutable_charter`) can prove its constitution has not
|
|
34
|
+
* been edited since. The raw CHARTER.md bytes are hashed — not the parsed
|
|
35
|
+
* object — so any change the operator makes to the file, meaningful or not, is
|
|
36
|
+
* detectable; the immutability contract is about the text on disk, not its
|
|
37
|
+
* interpretation.
|
|
38
|
+
*/
|
|
39
|
+
export const charterFingerprint = (source: string): string =>
|
|
40
|
+
createHash('sha256').update(source, 'utf8').digest('hex');
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Fingerprint of a session's instruction files (ADR-0010 §4) — AGENTS.md and the
|
|
44
|
+
* harness pointers — as one value. Order-independent, and adding or removing a
|
|
45
|
+
* file changes it, so planting a new instruction file is caught as surely as
|
|
46
|
+
* editing an existing one.
|
|
47
|
+
*/
|
|
48
|
+
export const instructionsFingerprint = (
|
|
49
|
+
files: ReadonlyArray<{ readonly path: string; readonly content: string }>,
|
|
50
|
+
): string => {
|
|
51
|
+
const hash = createHash('sha256');
|
|
52
|
+
for (const f of [...files].sort((a, b) => a.path.localeCompare(b.path))) {
|
|
53
|
+
hash.update(f.path, 'utf8').update('\0').update(f.content, 'utf8').update('\0');
|
|
54
|
+
}
|
|
55
|
+
return hash.digest('hex');
|
|
56
|
+
};
|
|
57
|
+
|
|
27
58
|
/* -------------------------------------------------------------------------- */
|
|
28
59
|
/* Schema */
|
|
29
60
|
/* -------------------------------------------------------------------------- */
|
|
@@ -66,6 +97,17 @@ export interface SessionBlock {
|
|
|
66
97
|
readonly deadline: string | null;
|
|
67
98
|
readonly merge_strategy: MergeStrategy;
|
|
68
99
|
readonly assent: Role;
|
|
100
|
+
/**
|
|
101
|
+
* ADR-0010: whether assent, rule and prorogue requested by an AI harness or a
|
|
102
|
+
* script are staged for the Speaker's confirmation. Absent means 'off', so every
|
|
103
|
+
* session convened before ADR-0010 behaves exactly as it did.
|
|
104
|
+
*/
|
|
105
|
+
readonly speaker_confirmation: 'required' | 'off';
|
|
106
|
+
/**
|
|
107
|
+
* ADR-0011: whether a confirmed act's commit must be signed with the confirming
|
|
108
|
+
* person's git signing key. Absent means 'off'.
|
|
109
|
+
*/
|
|
110
|
+
readonly signed_confirmations: 'required' | 'off';
|
|
69
111
|
readonly endurance: Endurance;
|
|
70
112
|
}
|
|
71
113
|
|
|
@@ -319,6 +361,8 @@ export const parseCharter = (source: string): ParseResult => {
|
|
|
319
361
|
// rule and let a bad assent silently open a session (AUDIT #8).
|
|
320
362
|
assent: session['assent'] === undefined ? 'AUTHORITY' : (session['assent'] as Role),
|
|
321
363
|
stale_action: session['stale_action'] === 'dissolve' ? 'dissolve' : 'suspend',
|
|
364
|
+
speaker_confirmation: session['speaker_confirmation'] === 'required' ? 'required' : 'off',
|
|
365
|
+
signed_confirmations: session['signed_confirmations'] === 'required' ? 'required' : 'off',
|
|
322
366
|
checkpoint_interval_hours: asNumberOrNull(session['checkpoint_interval_hours']),
|
|
323
367
|
endurance: {
|
|
324
368
|
max_motions: asNumberOrNull(endurance['max_motions']),
|