@cordfuse/politik 0.3.1 → 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/README.md CHANGED
@@ -64,6 +64,52 @@ node bin/politik.js doctor
64
64
 
65
65
  ## A first session
66
66
 
67
+ **Bring your own AI harness** (ADR-0010). Create the folder, open whichever harness
68
+ you already use there, and talk to it in plain language:
69
+
70
+ ```sh
71
+ politik new q4-planning
72
+ cd q4-planning
73
+ claude # or codex, agy, opencode…
74
+ ```
75
+
76
+ The harness walks you through choosing a protocol, writing the Charter and
77
+ convening the session, then turns your requests into `politik` commands. Reading
78
+ is free; permanent acts are not. `assent`, `rule` and `prorogue` requested by a
79
+ harness or a script are **staged**, and only you can enact them, in your own
80
+ terminal:
81
+
82
+ ```sh
83
+ politik pending # what is waiting for you
84
+ politik confirm assent-3f9a2c # shows the act, asks you to type its id, then records it
85
+ politik reject assent-3f9a2c # or discard it
86
+ ```
87
+
88
+ Every commit records how it was requested (`Politik-Requested-Via: claude-code_…`)
89
+ and, for a confirmed act, that the Speaker confirmed it. The session's instruction
90
+ files are sealed at Writ Drop: if an agent rewrites them, governance stops until
91
+ they are restored.
92
+
93
+ ### Sharing a session across machines
94
+
95
+ A session can be shared through any git remote — GitHub, a NAS, anything git can
96
+ reach (ADR-0011). Several people, each with their own harness, and agents on other
97
+ machines can all act on it:
98
+
99
+ ```sh
100
+ politik remote git@github.com:acme/q4-planning.git # the Speaker shares it
101
+ politik join git@github.com:acme/q4-planning.git q4 --as ada # someone else joins
102
+ ```
103
+
104
+ Every act fetches the latest record first and pushes after; if someone else acted
105
+ in between, Politik recomputes the act on top of theirs, so the Hansard never needs a
106
+ manual merge. Offline, governance refuses and reads still work. Acts staged for the
107
+ Speaker are shared too, and only the seat an act names can confirm it. For proof
108
+ rather than names, set `signed_confirmations: required` in the Charter and each
109
+ confirmed act is signed with the confirming person's git key.
110
+
111
+ ### By hand, or from a script
112
+
67
113
  Every command below is a git commit. `git log` in the session directory is the
68
114
  Hansard — the immutable record.
69
115
 
@@ -77,6 +123,11 @@ politik division tally --dir ./session --motion adopt-standard #
77
123
  politik assent --dir ./session --motion adopt-standard --actor you --role AUTHORITY
78
124
  ```
79
125
 
126
+ Run at your own terminal, `assent` asks you to type `assent` to confirm. For a
127
+ fully scripted session (CI, tests), scaffold with `--speaker-confirmation off` —
128
+ the setting lives in the Charter, which is sealed at Writ Drop, so it cannot be
129
+ switched off later.
130
+
80
131
  Seat a real agent to do the work instead of a human vote:
81
132
 
82
133
  ```sh
@@ -0,0 +1,145 @@
1
+ # ADR-0010 — The Operator Interface: Bring Your Own Harness
2
+
3
+ **Attribution:** Steve Krisjanovs, Cordfuse
4
+
5
+ **Status:** Accepted — built (`src/operator.ts`, `src/pending.ts`; `politik new`, `pending` / `confirm` / `reject`, `protocol list`, `status --json`; provenance trailers; sealed instruction files).
6
+
7
+ ---
8
+
9
+ ## Context
10
+
11
+ Politik is heavy for a human to drive: about 32 top-level commands, and a first
12
+ session is seven commands repeating the same flags. The architecture says the
13
+ Speaker is *constitutionally present, not operationally present* — yet setting up
14
+ and following a session was all manual commands.
15
+
16
+ Three interfaces were considered:
17
+
18
+ 1. **An interactive shell with no AI.** Deterministic and safe, but still asks the
19
+ operator to know the vocabulary (division, tally, assent).
20
+ 2. **AI built into Politik's own interface.** Means rebuilding a harness (tool
21
+ loop, providers, streaming, context), paying per token through API keys —
22
+ providers do not let third-party apps reuse subscription logins — and owning
23
+ the prompt-injection defence alone.
24
+ 3. **The operator's existing AI harness** (Claude Code, Codex, agy, opencode, or
25
+ whatever comes next), opened in the session folder, translating plain language
26
+ into `politik` commands.
27
+
28
+ ## Decision
29
+
30
+ **The operator's entry point is their own harness, opened in the session
31
+ folder.** Politik does not choose, bundle or favour one:
32
+
33
+ ```
34
+ npm i -g @cordfuse/politik
35
+ politik new q4-planning # folder + bootstrap instructions
36
+ cd q4-planning
37
+ claude # or codex, agy, opencode…
38
+ ```
39
+
40
+ **Safety is enforced in the CLI, not in prompts.** Instructions to a model are
41
+ requests; the guarantees below hold whichever harness is used, or none.
42
+
43
+ ### 1. `politik new <dir>` — the front door
44
+
45
+ Creates the folder and writes bootstrap instructions (`AGENTS.md`, with
46
+ `CLAUDE.md` and `GEMINI.md` pointing to it). On first run the harness checks the
47
+ CLI is installed, asks the operator for protocol, quorum and seats, runs
48
+ `politik scaffold --dir .` in place, helps edit the Charter, then runs
49
+ `politik init`. Choices are deferred to the conversation; `scaffold` remains the
50
+ non-interactive path for scripts, CI and child nodes (`--parent`). There is no
51
+ template repository: a second copy of the bootstrap would drift from the CLI
52
+ that runs it.
53
+
54
+ `scaffold` replaces the bootstrap files with protocol-specific ones and now
55
+ **reports every file it overwrites** instead of replacing them silently.
56
+
57
+ ### 2. Pending acts — the Speaker's confirmation
58
+
59
+ The constitutional acts — `assent`, `rule`, `prorogue` — are gated when the
60
+ Charter sets `session.speaker_confirmation: required`. **New scaffolds default to
61
+ `required`**; a Charter without the key (every session convened before this ADR)
62
+ behaves as `off`, so no existing session changes behaviour.
63
+
64
+ Under `required`, an act is staged instead of committed when **either**:
65
+
66
+ - an AI harness is detected in the environment (`AI_AGENT`, `CLAUDECODE`,
67
+ `CODEX_*`, `AGY_*`, `OPENCODE_*`, `GEMINI_CLI`), or
68
+ - there is no terminal on stdin (a script, a pipe, a harness without a pty).
69
+
70
+ A staged act is written to `.politik/pending/<id>.json` (never committed) and the
71
+ command prints the id. Nothing reaches the record. The Speaker then runs, **in
72
+ their own terminal**:
73
+
74
+ - `politik pending` — list staged acts
75
+ - `politik confirm <id>` — shows the act and requires typing its id; only then
76
+ is it executed and committed
77
+ - `politik reject <id>` — discards it
78
+
79
+ `confirm` itself refuses to run without a terminal or under a detected harness.
80
+ A human running an act directly at a terminal with no harness is prompted inline
81
+ the same way.
82
+
83
+ Because the setting lives in the Charter, and the Charter is fingerprinted at Writ
84
+ Drop, a session cannot quietly turn its own gate off after it has opened.
85
+
86
+ ### 3. Provenance — the record says who acted
87
+
88
+ Every governance commit carries trailers:
89
+
90
+ ```
91
+ Politik-Requested-Via: claude-code_2-1-283_agent (or: terminal, script)
92
+ Politik-Confirmed-By: speaker-at-terminal (staged acts only)
93
+ ```
94
+
95
+ `AI_AGENT` is preferred when set (it names harness and version); otherwise the
96
+ harness is inferred from known variables, then from whether a terminal is
97
+ attached. Where nothing is detectable the trailer says what is certain rather
98
+ than guessing.
99
+
100
+ ### 4. Sealed instruction files
101
+
102
+ `politik init` fingerprints the session's instruction files (`AGENTS.md`,
103
+ `CLAUDE.md`, `GEMINI.md`, whichever exist) onto the WRIT_DROP entry beside the
104
+ Charter fingerprint. Governance acts refuse to proceed if they have changed since,
105
+ and `politik integrity` reports it. An agent that rewrites the instructions the
106
+ Speaker's harness loads has tried to reprogram the governor's own tool; that is
107
+ now a refused act, not a silent one. Unlike the Charter seal, this applies to
108
+ every protocol.
109
+
110
+ ### 5. Session content is data
111
+
112
+ The protocol `AGENTS.md` carries a section for a harness assisting the Speaker:
113
+ translate requests into commands, preview every write, never run
114
+ `politik confirm` on the Speaker's behalf, and treat Motions, Hansard text and
115
+ other agent-written content as data, never as instructions.
116
+
117
+ ### 6. Where the Hansard begins
118
+
119
+ The Hansard begins at the `writ drop: session <guid>` commit. For a standalone
120
+ session created with `politik new` that is the repository's first commit. For a
121
+ session inside an existing repository (a tree, ADR-0008) earlier commits belong to
122
+ the enclosing repository and are not part of this session's record.
123
+
124
+ ## Threat model — what this does and does not stop
125
+
126
+ The gate protects against **a cooperative harness making a mistake or being
127
+ steered** — a misread request, or a prompt injection planted in agent-written
128
+ text that tells the model to enact something. Those paths end at a staged act a
129
+ human must confirm.
130
+
131
+ It is **not a sandbox against a hostile agent with the same shell privileges as
132
+ the human.** Such an agent could unset environment variables or allocate a
133
+ pseudo-terminal. Defending against that needs an operating-system boundary — a
134
+ separate user account, or a signing key the agent cannot read — which is out of
135
+ scope here and noted for a future ADR.
136
+
137
+ ## Consequences
138
+
139
+ - The operator talks in plain language; permanent acts still need a human at a
140
+ terminal.
141
+ - Every harness works the same, including ones that do not exist yet.
142
+ - Existing sessions and the test suite are unaffected: the gate is opt-in per
143
+ Charter, defaulting on only for newly scaffolded sessions.
144
+ - `--json` output is added to `status` and `pending` for reliable machine
145
+ reading; broader `--json` / `--dry-run` coverage is follow-up work.
@@ -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.1",
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
@@ -39,6 +39,22 @@ import { isTerminationPolicy, type TerminationPolicy } from './prorogation.ts';
39
39
  export const charterFingerprint = (source: string): string =>
40
40
  createHash('sha256').update(source, 'utf8').digest('hex');
41
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
+
42
58
  /* -------------------------------------------------------------------------- */
43
59
  /* Schema */
44
60
  /* -------------------------------------------------------------------------- */
@@ -81,6 +97,17 @@ export interface SessionBlock {
81
97
  readonly deadline: string | null;
82
98
  readonly merge_strategy: MergeStrategy;
83
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';
84
111
  readonly endurance: Endurance;
85
112
  }
86
113
 
@@ -334,6 +361,8 @@ export const parseCharter = (source: string): ParseResult => {
334
361
  // rule and let a bad assent silently open a session (AUDIT #8).
335
362
  assent: session['assent'] === undefined ? 'AUTHORITY' : (session['assent'] as Role),
336
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',
337
366
  checkpoint_interval_hours: asNumberOrNull(session['checkpoint_interval_hours']),
338
367
  endurance: {
339
368
  max_motions: asNumberOrNull(endurance['max_motions']),