@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.
- package/EXECUTION.md +90 -85
- package/POLITIK-ARCHITECTURE.md +111 -176
- package/PROTOCOLS.md +120 -289
- package/README.md +130 -177
- package/RESEARCH.md +142 -436
- package/RUNTIME.md +253 -261
- package/docs/adr/0001-chamber-transport.md +2 -0
- package/docs/adr/0002-charter-schema.md +2 -0
- package/docs/adr/0003-state-json-schema.md +2 -0
- package/docs/adr/0004-motion-enactment.md +2 -0
- package/docs/adr/0005-hansard-format.md +2 -0
- package/docs/adr/0006-protocol-behavioral-enforcement.md +2 -0
- package/docs/adr/0007-protocol-mechanics.md +2 -0
- package/docs/adr/0008-session-storage.md +2 -0
- package/docs/adr/0009-match-primitive.md +2 -0
- package/docs/adr/0010-operator-interface.md +2 -0
- package/docs/adr/0011-shared-sessions.md +2 -0
- package/docs/adr/0012-plain-vocabulary.md +68 -0
- package/docs/adr/0013-rule-defined-protocols.md +89 -0
- package/package.json +1 -1
- package/protocols/CONTRIBUTING.md +47 -87
- package/protocols/adversarial-review.yml +19 -0
- package/protocols/elimination-rounds.yml +18 -0
- package/protocols/majority-vote.yml +18 -0
- package/protocols/panel-review.yml +19 -0
- package/protocols/single-decider.yml +18 -0
- package/protocols/unanimous-vote.yml +17 -0
- package/src/actors.ts +124 -100
- package/src/agents.ts +64 -23
- package/src/ballot.ts +747 -0
- package/src/canon.ts +23 -10
- package/src/capability.ts +16 -99
- package/src/charter.ts +41 -34
- package/src/cli.ts +541 -480
- package/src/{prorogation.ts → closing.ts} +43 -43
- package/src/conflict.ts +14 -14
- package/src/containment.ts +11 -11
- package/src/doctor.ts +1 -1
- package/src/election.ts +4 -4
- package/src/envelope.ts +3 -3
- package/src/escalation.ts +44 -44
- package/src/fault.ts +8 -8
- package/src/federation.ts +14 -14
- package/src/git.ts +21 -18
- package/src/heartbeat.ts +32 -32
- package/src/index.ts +5 -5
- package/src/init.ts +66 -65
- package/src/integrity.ts +30 -30
- package/src/ledger.ts +3 -3
- package/src/{hansard.ts → log.ts} +20 -20
- package/src/{crisis.ts → misconduct.ts} +70 -70
- package/src/operator.ts +5 -5
- package/src/pending.ts +9 -9
- package/src/projection.ts +30 -30
- package/src/protocol-sdk.ts +12 -121
- package/src/protocol.ts +8 -78
- package/src/providers/github.ts +12 -12
- package/src/quorum.ts +7 -7
- package/src/remote.ts +1 -1
- package/src/runner.ts +134 -55
- package/src/scm.ts +14 -14
- package/src/spawn.ts +4 -4
- package/src/standings.ts +13 -13
- package/src/state.ts +6 -6
- package/src/templates/session.ts +448 -0
- package/src/tournament.ts +20 -20
- package/src/transport.ts +4 -4
- package/src/tree.ts +16 -16
- package/protocols/adversarial-collaboration.yml +0 -28
- package/protocols/corporate.yml +0 -35
- package/protocols/elimination-tournament.yml +0 -41
- package/protocols/emergency-response-ics.yml +0 -27
- package/protocols/jury-deliberation.yml +0 -32
- package/protocols/monarchy.yml +0 -31
- package/protocols/parliamentary.yml +0 -66
- package/protocols/peer-review.yml +0 -44
- package/protocols/republic.yml +0 -36
- package/protocols/socialism-collective.yml +0 -31
- package/protocols/solo.yml +0 -32
- package/src/division.ts +0 -609
- package/src/templates/parliamentary.ts +0 -580
package/src/agents.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type PromptStyle =
|
|
|
33
33
|
export type AuthMode = 'oauth' | 'api_key' | 'aws';
|
|
34
34
|
|
|
35
35
|
export interface AgentSpec {
|
|
36
|
-
/** Registry key. Stable; used in Charters and
|
|
36
|
+
/** Registry key. Stable; used in Charters and record attribution. */
|
|
37
37
|
readonly id: string;
|
|
38
38
|
readonly label: string;
|
|
39
39
|
readonly command: string;
|
|
@@ -54,9 +54,24 @@ export interface AgentSpec {
|
|
|
54
54
|
* Without these the LEDGER can record elapsed time but not tokens or cost.
|
|
55
55
|
*/
|
|
56
56
|
readonly json_args?: readonly string[];
|
|
57
|
+
/**
|
|
58
|
+
* Args computed per turn from the session being governed. For a harness
|
|
59
|
+
* that sandboxes its own shell, this is where a turn is granted exactly what
|
|
60
|
+
* governing the session needs — no more, and never saved to the user's
|
|
61
|
+
* settings.
|
|
62
|
+
*/
|
|
63
|
+
readonly session_args?: (ctx: SessionContext) => readonly string[];
|
|
57
64
|
readonly notes: string;
|
|
58
65
|
}
|
|
59
66
|
|
|
67
|
+
/** What a turn's harness must be able to reach to act on the record. */
|
|
68
|
+
export interface SessionContext {
|
|
69
|
+
/** Absolute git directory of the session: acts commit here. */
|
|
70
|
+
readonly git_dir: string;
|
|
71
|
+
/** Absolute paths the `politik` CLI runs from: read-only is enough. */
|
|
72
|
+
readonly read_paths: readonly string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
60
75
|
/**
|
|
61
76
|
* Agents Politik can spawn as constituencies.
|
|
62
77
|
*
|
|
@@ -122,6 +137,11 @@ export const AGENTS: readonly AgentSpec[] = Object.freeze([
|
|
|
122
137
|
auth_local: 'oauth',
|
|
123
138
|
auth_headless: 'oauth',
|
|
124
139
|
stdio_json: true,
|
|
140
|
+
// `codex exec` defaults to a read-only sandbox, so a seated agent could read
|
|
141
|
+
// the session but not act through the CLI (found dogfooding: no vote could be
|
|
142
|
+
// cast). Per turn only: workspace-write, plus the session's git directory,
|
|
143
|
+
// which an enclosing repo may hold outside the workspace. Nothing is saved.
|
|
144
|
+
session_args: (ctx) => ['--sandbox', 'workspace-write', '--add-dir', ctx.git_dir],
|
|
125
145
|
notes:
|
|
126
146
|
'OpenAI, Rust-based. Bare `codex` is an interactive TUI; `exec` is headless. ' +
|
|
127
147
|
'Requires cwd to be a git repo — always true of a session repo.',
|
|
@@ -134,7 +154,24 @@ export const AGENTS: readonly AgentSpec[] = Object.freeze([
|
|
|
134
154
|
auth_local: 'oauth',
|
|
135
155
|
auth_headless: 'oauth',
|
|
136
156
|
stdio_json: false,
|
|
137
|
-
|
|
157
|
+
// agy's default mode sandboxes the commands it runs: paths outside the
|
|
158
|
+
// workspace are invisible and .git is read-only. An agent that votes
|
|
159
|
+
// through `politik` from inside its turn then cannot load the CLI or
|
|
160
|
+
// commit the act (Scrum UAT, PR #38). `--settings` applies to this run
|
|
161
|
+
// only and is never saved; the grant is the session's own .git (write)
|
|
162
|
+
// and the CLI's install (read). The sandbox otherwise stays on.
|
|
163
|
+
session_args: (ctx) => [
|
|
164
|
+
'--settings',
|
|
165
|
+
JSON.stringify({
|
|
166
|
+
permissions: {
|
|
167
|
+
allow: [
|
|
168
|
+
`write_file(${ctx.git_dir})`,
|
|
169
|
+
...ctx.read_paths.map((p) => `read_file(${p})`),
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
],
|
|
174
|
+
notes: 'Google. -p/--print for headless. Sandboxed shell: granted the session .git per turn.',
|
|
138
175
|
},
|
|
139
176
|
{
|
|
140
177
|
id: 'aider',
|
|
@@ -188,7 +225,7 @@ export interface Invocation {
|
|
|
188
225
|
* Build the headless invocation for an agent.
|
|
189
226
|
*
|
|
190
227
|
* Returns command and args separately, never a shell string. The prompt carries
|
|
191
|
-
* a Charter, a
|
|
228
|
+
* a Charter, a record excerpt and arbitrary session text; interpolating that
|
|
192
229
|
* into a shell would be an injection vector on every spawn. Callers must pass
|
|
193
230
|
* this to a non-shell spawn.
|
|
194
231
|
*/
|
|
@@ -237,15 +274,15 @@ export interface PromptContext {
|
|
|
237
274
|
readonly role: Role;
|
|
238
275
|
/** Verbs the Charter grants this role. */
|
|
239
276
|
readonly verbs: readonly Verb[];
|
|
240
|
-
/** Protocol vocabulary name, e.g.
|
|
277
|
+
/** Protocol vocabulary name, e.g. majority-vote. */
|
|
241
278
|
readonly protocol: string;
|
|
242
|
-
/** Recent
|
|
243
|
-
readonly
|
|
244
|
-
/**
|
|
279
|
+
/** Recent record, so a fresh agent has session context. */
|
|
280
|
+
readonly log_excerpt?: string;
|
|
281
|
+
/** Charter prose from the Charter. */
|
|
245
282
|
readonly standing_orders?: string;
|
|
246
283
|
/**
|
|
247
284
|
* Whether the protocol permits escalation (ADR-0006). Defaults to true. When
|
|
248
|
-
* false — a Darwinist chamber — the agent is told there is no
|
|
285
|
+
* false — a Darwinist chamber — the agent is told there is no escalation:
|
|
249
286
|
* it decides within its mandate or exits, since an appeal has no resolver.
|
|
250
287
|
*/
|
|
251
288
|
readonly escalation_enabled?: boolean;
|
|
@@ -266,7 +303,7 @@ export const composePrompt = (context: PromptContext): string => {
|
|
|
266
303
|
const sections: string[] = [
|
|
267
304
|
'# POLITIK SESSION',
|
|
268
305
|
'',
|
|
269
|
-
`You are a **${context.role}** in a governed multi-agent session running the`,
|
|
306
|
+
`You are ${/^[AEIOU]/.test(context.role) ? 'an' : 'a'} **${context.role}** in a governed multi-agent session running the`,
|
|
270
307
|
`**${context.protocol}** protocol. Session: \`${context.envelope.session_guid}\`.`,
|
|
271
308
|
'',
|
|
272
309
|
'## Your mandate',
|
|
@@ -274,24 +311,24 @@ export const composePrompt = (context: PromptContext): string => {
|
|
|
274
311
|
`Verbs granted to your role: ${context.verbs.length > 0 ? context.verbs.join(', ') : 'none'}.`,
|
|
275
312
|
'You may not take an action your verbs do not grant.',
|
|
276
313
|
context.escalation_enabled === false
|
|
277
|
-
? 'This protocol has no escalation: there is no
|
|
314
|
+
? 'This protocol has no escalation: there is no escalation and no appeal. ' +
|
|
278
315
|
'Decide within your mandate, or exit. A decision here is final.'
|
|
279
|
-
: 'If you believe the correct action requires a verb you do not hold,
|
|
280
|
-
'
|
|
316
|
+
: 'If you believe the correct action requires a verb you do not hold, raise an ' +
|
|
317
|
+
'escalation instead of proceeding.',
|
|
281
318
|
'',
|
|
282
|
-
'##
|
|
319
|
+
'## Charter',
|
|
283
320
|
'',
|
|
284
321
|
context.standing_orders?.trim() || '_None supplied. Follow CANON defaults._',
|
|
285
322
|
'',
|
|
286
323
|
];
|
|
287
324
|
|
|
288
|
-
if (context.
|
|
325
|
+
if (context.log_excerpt !== undefined && context.log_excerpt.trim() !== '') {
|
|
289
326
|
sections.push(
|
|
290
327
|
'## Record so far',
|
|
291
328
|
'',
|
|
292
|
-
'The
|
|
329
|
+
'The record is the session. You are stateless; this is your context.',
|
|
293
330
|
'',
|
|
294
|
-
context.
|
|
331
|
+
context.log_excerpt.trim(),
|
|
295
332
|
'',
|
|
296
333
|
);
|
|
297
334
|
}
|
|
@@ -301,15 +338,19 @@ export const composePrompt = (context: PromptContext): string => {
|
|
|
301
338
|
'',
|
|
302
339
|
context.envelope.prompt.trim(),
|
|
303
340
|
'',
|
|
304
|
-
'## Rules of the
|
|
341
|
+
'## Rules of the session',
|
|
305
342
|
'',
|
|
306
343
|
'- Commit your result. Uncommitted work does not exist.',
|
|
307
|
-
'- Do not traverse above the working directory. Doing so is a
|
|
308
|
-
'
|
|
309
|
-
'- **
|
|
310
|
-
'
|
|
311
|
-
'
|
|
312
|
-
'
|
|
344
|
+
'- Do not traverse above the working directory. Doing so is a Charter',
|
|
345
|
+
' violation, logged to the record and escalated to the owner.',
|
|
346
|
+
'- **Act through the `politik` CLI.** Voting, vetoing, escalating and every',
|
|
347
|
+
' other governance act is a `politik` command; the command records the act',
|
|
348
|
+
' for you. Running it is how you act — it is not writing the record yourself.',
|
|
349
|
+
'- **Do not write to LOG.md, STATE.json or LEDGER.md at all** — not even',
|
|
350
|
+
' to append, and not by any means other than a `politik` command.',
|
|
351
|
+
' The RECORD agent owns them exclusively, and editing them directly is a',
|
|
352
|
+
' Charter violation. Your work is recorded for you; state your result in',
|
|
353
|
+
' your reply and it will be entered in the record.',
|
|
313
354
|
'- When your task is complete, stop. You are disposed after this turn.',
|
|
314
355
|
'',
|
|
315
356
|
);
|