@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/cli.ts
CHANGED
|
@@ -16,10 +16,10 @@ import { parseArgs } from 'node:util';
|
|
|
16
16
|
|
|
17
17
|
import { isRole, type Role } from './canon.ts';
|
|
18
18
|
import { charterFingerprint, instructionsFingerprint, parseCharter, validateCharter } from './charter.ts';
|
|
19
|
-
import {
|
|
19
|
+
import { openSession } from './init.ts';
|
|
20
20
|
import { initSessionRepo } from './git.ts';
|
|
21
21
|
import { parseState, serializeState, type SessionStateFile } from './state.ts';
|
|
22
|
-
import { INSTRUCTION_FILES, bootstrapTemplate, pointerFiles, scaffoldTemplates } from './templates/
|
|
22
|
+
import { INSTRUCTION_FILES, bootstrapTemplate, pointerFiles, scaffoldTemplates } from './templates/session.ts';
|
|
23
23
|
import { generateProtocol, lintSource } from './protocol-sdk.ts';
|
|
24
24
|
import { diagnose } from './doctor.ts';
|
|
25
25
|
import {
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
operatorHandle, operatorIdentity, pushRecord, syncConfig, syncNow,
|
|
33
33
|
} from './remote.ts';
|
|
34
34
|
import {
|
|
35
|
-
|
|
35
|
+
CONFIRMED_BY_OWNER, detectHarness, isOwnerAtTerminal, provenanceTrailers, requestedVia,
|
|
36
36
|
} from './operator.ts';
|
|
37
37
|
import { runTurn } from './runner.ts';
|
|
38
38
|
import { GitTransport } from './transport.ts';
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
} from './tournament.ts';
|
|
47
47
|
import { cascadeAlerts, cascadeEntry, recordOnNode } from './tree.ts';
|
|
48
48
|
import {
|
|
49
|
-
linkEntry,
|
|
49
|
+
linkEntry, projectEnactment, projectBallot, projectEscalation,
|
|
50
50
|
projectionEntry, resolveProvider,
|
|
51
51
|
} from './projection.ts';
|
|
52
52
|
import { appendLedgerRow, checkCostCeiling, totals } from './ledger.ts';
|
|
@@ -57,20 +57,20 @@ import {
|
|
|
57
57
|
spawnChild, veto, vetoOutstanding, type ExitType,
|
|
58
58
|
} from './actors.ts';
|
|
59
59
|
import {
|
|
60
|
-
checkCapture, externalReview,
|
|
61
|
-
type
|
|
62
|
-
} from './
|
|
60
|
+
checkCapture, externalReview, reportMisconduct, suspendForMisconduct,
|
|
61
|
+
type MisconductRuling,
|
|
62
|
+
} from './misconduct.ts';
|
|
63
63
|
import {
|
|
64
|
-
breakDeadlock,
|
|
65
|
-
isExitPolicy, isResolution, recordOutcome, suspendForDeadlock,
|
|
66
|
-
} from './
|
|
64
|
+
breakDeadlock, openBallot, castVote, cull, ballotOpened, ballotDecided, enactMotion,
|
|
65
|
+
applyVeto, isExitPolicy, isResolution, ownerDecision, recordOutcome, recordedOutcome, removalTarget, removeByVote, suspendForDeadlock, tallyBallot, type Vote,
|
|
66
|
+
} from './ballot.ts';
|
|
67
67
|
import {
|
|
68
|
-
|
|
69
|
-
type Protocol,
|
|
68
|
+
parseProtocol,
|
|
69
|
+
type Protocol,
|
|
70
70
|
} from './protocol.ts';
|
|
71
71
|
import { reviewIntegrity } from './integrity.ts';
|
|
72
|
-
import { checkTermination, isTerminationPolicy, lastStanding,
|
|
73
|
-
import { RECORD_TYPES, appendEntry, parseEntries } from './
|
|
72
|
+
import { TRIGGERS, checkTermination, isTerminationPolicy, lastStanding, closeSession, type Trigger } from './closing.ts';
|
|
73
|
+
import { RECORD_TYPES, appendEntry, parseEntries, type RecordEntry } from './log.ts';
|
|
74
74
|
import type { FileWrite } from './scm.ts';
|
|
75
75
|
|
|
76
76
|
/**
|
|
@@ -91,35 +91,35 @@ const USAGE = `politik — governed multi-agent sessions on git
|
|
|
91
91
|
Usage
|
|
92
92
|
politik version
|
|
93
93
|
politik new <dir> # start here: folder + instructions for your AI harness
|
|
94
|
-
politik scaffold [--dir <dir>] [--protocol
|
|
95
|
-
[--
|
|
94
|
+
politik scaffold [--dir <dir>] [--protocol majority-vote] [--quorum <n>] [--parent <dir>]
|
|
95
|
+
[--owner-confirmation required|off]
|
|
96
96
|
politik doctor
|
|
97
|
-
politik pending [--dir <dir>] [--json] #
|
|
98
|
-
politik confirm <id> [--dir <dir>] # the
|
|
97
|
+
politik pending [--dir <dir>] [--json] # permanent acts staged for the owner
|
|
98
|
+
politik confirm <id> [--dir <dir>] # the owner, at a terminal: execute a staged act
|
|
99
99
|
politik reject <id> [--dir <dir>] # discard a staged act
|
|
100
100
|
politik remote [<url>] [--as <handle>] [--off] # share this session through a git remote
|
|
101
101
|
politik join <url> [<dir>] --as <handle> # take a seat in a shared session from this machine
|
|
102
102
|
politik sync [--dir <dir>] # reconcile this clone with the shared record
|
|
103
103
|
politik protocol list # the shipped protocols
|
|
104
104
|
politik protocol lint <manifest.yml>
|
|
105
|
-
politik protocol new <name> [--
|
|
105
|
+
politik protocol new <name> [--out <dir>]
|
|
106
106
|
politik validate <charter.md> [--protocol <name>]
|
|
107
|
-
politik init --charter <path> --
|
|
107
|
+
politik init --charter <path> --owner <handle> [--dir <dir>] [--guid <id>] [--standalone] [--remote <url>]
|
|
108
108
|
politik run --agent <id> --actor <h> --role <ROLE> (--task <text> | --claim)
|
|
109
|
-
politik
|
|
110
|
-
politik
|
|
111
|
-
politik
|
|
112
|
-
politik
|
|
113
|
-
politik
|
|
114
|
-
politik
|
|
115
|
-
politik
|
|
116
|
-
politik
|
|
109
|
+
politik vote open --motion <id> --actor <h> --role <ROLE> [--reviewers a,b] [--removes <handle>]
|
|
110
|
+
politik vote cast --motion <id> --actor <h> --role <ROLE> --vote YES|NO|ABSTAIN
|
|
111
|
+
politik vote tally --motion <id>
|
|
112
|
+
politik vote break --motion <id> --actor <handle> --decide carry|reject # break a DEADLOCK
|
|
113
|
+
politik enact --motion <id> --actor <h> --role AUTHORITY
|
|
114
|
+
politik misconduct report --actor <h> --role <ROLE> --grounds <text>
|
|
115
|
+
politik misconduct status
|
|
116
|
+
politik misconduct rule --reviewer <h> [--accused <owner>] --ruling UPHELD|DISMISSED --reasons <text>
|
|
117
117
|
politik escalate --actor <h> --role <ROLE> --title <t> --body <text> [--seq <n>]
|
|
118
118
|
politik rule --seq <n> --actor <h> --outcome UPHELD|REVERSED|NOTED --body <text>
|
|
119
119
|
politik challenge --actor <delegate> --against <action> --grounds <text> [--window <min>]
|
|
120
120
|
politik actor hire|promote|demote|exit|veto|spawn ... (see below)
|
|
121
121
|
politik actor dispute --actor <removed> --grounds <text> # challenge one's own removal
|
|
122
|
-
politik actor reinstate --subject <h> --actor <
|
|
122
|
+
politik actor reinstate --subject <h> --actor <owner> --ruling UPHELD|REVERSED
|
|
123
123
|
politik actor list
|
|
124
124
|
politik heartbeat [--dir <dir>] [--suspend]
|
|
125
125
|
politik snapshot [--dir <dir>] [--completed a,b] [--in-flight a] [--pending a]
|
|
@@ -130,9 +130,9 @@ Usage
|
|
|
130
130
|
politik motion link --motion <id> --pr <n> [--url <u>]
|
|
131
131
|
politik ledger [--dir <dir>]
|
|
132
132
|
politik status [--dir <dir>] [--json]
|
|
133
|
-
politik
|
|
133
|
+
politik log [--dir <dir>] # every act so far, in order
|
|
134
134
|
politik integrity [--dir <dir>] # scan the record for bad-faith patterns
|
|
135
|
-
politik
|
|
135
|
+
politik close [--dir <dir>] --actor <handle> --role <ROLE> --trigger <TRIGGER>
|
|
136
136
|
politik standings [--dir <dir>] [--by win-loss|survival] # score a competitive protocol
|
|
137
137
|
politik pair --format swiss|round-robin|single-elim [--dir <dir>] # pair the next round of MATCHes
|
|
138
138
|
politik match report --match <id> --winner <contestant> [--actor <referee>]
|
|
@@ -142,28 +142,28 @@ Usage
|
|
|
142
142
|
|
|
143
143
|
Commands
|
|
144
144
|
version Print the version.
|
|
145
|
-
scaffold Write a protocol's Charter, roles and
|
|
145
|
+
scaffold Write a protocol's Charter, roles and agenda for editing.
|
|
146
146
|
doctor Probe this host: can it run a session, and with which agents?
|
|
147
147
|
protocol Lint a protocol manifest, or generate a new one.
|
|
148
|
-
validate Parse a CHARTER.md and run the
|
|
149
|
-
init
|
|
150
|
-
run Seat an agent, give it
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
escalate Raise
|
|
155
|
-
rule Rule on
|
|
148
|
+
validate Parse a CHARTER.md and run the session opening rules. Writes nothing.
|
|
149
|
+
init Open a session — seal the Charter and make the first commit.
|
|
150
|
+
run Seat an agent, give it a task, record what it did.
|
|
151
|
+
vote Open a vote, cast one, tally the result, or break a tie.
|
|
152
|
+
enact Enact a carried motion. The vote decides; enact carries it out.
|
|
153
|
+
misconduct Report the owner's misconduct, check its status, or record an outside ruling.
|
|
154
|
+
escalate Raise an escalation. Suspends the session.
|
|
155
|
+
rule Rule on an escalation as AUTHORITY. Resumes the session.
|
|
156
156
|
challenge A DELEGATE disputes an AUTHORITY action — recorded, attributable, non-binding.
|
|
157
157
|
actor Seat, move or remove actors; exercise a veto; refer to committee.
|
|
158
158
|
heartbeat Has the proceeding gone quiet? --suspend marks it STALE.
|
|
159
159
|
snapshot Commit a STATE_SNAPSHOT so a new agent can continue the work.
|
|
160
160
|
resume Resume a STALE proceeding.
|
|
161
161
|
conflict Find or resolve Motions touching the same files. Routine, not a fault.
|
|
162
|
-
broadcast Put
|
|
163
|
-
motion Bind a Motion to a pull request so
|
|
162
|
+
broadcast Put a task on the bus for peers to claim.
|
|
163
|
+
motion Bind a Motion to a pull request so enacting it merges the pull request.
|
|
164
164
|
ledger Total the session's measured cost.
|
|
165
165
|
status Read STATE.json and summarise the proceeding.
|
|
166
|
-
|
|
166
|
+
close Close a session permanently and seal the log.
|
|
167
167
|
standings Score a competitive protocol from the record (win-loss or survival).
|
|
168
168
|
pair Pair the next round of MATCHes by format (swiss, round-robin, single-elim).
|
|
169
169
|
match Report a MATCH result, or list the bracket.
|
|
@@ -195,15 +195,15 @@ const flushOutput = (lines: ReadonlyArray<readonly ['out' | 'err', string]>): vo
|
|
|
195
195
|
|
|
196
196
|
/**
|
|
197
197
|
* A supplied --role/--target must name a CANON role; an absent one falls back to
|
|
198
|
-
* a default downstream. Governance-critical commands (
|
|
198
|
+
* a default downstream. Governance-critical commands (vote, actors) already
|
|
199
199
|
* reject a bad role in their pure layer; this guards the record-writing commands
|
|
200
200
|
* that only carry the role as attribution, so a garbage string never reaches the
|
|
201
|
-
* immutable
|
|
201
|
+
* immutable record.
|
|
202
202
|
*/
|
|
203
203
|
const badRole = (value: string | undefined): boolean => value !== undefined && !isRole(value);
|
|
204
204
|
|
|
205
205
|
/** Exit codes: 0 success, 1 refusal (invalid input), 2 usage error. */
|
|
206
|
-
/** PENDING (ADR-0010): the act was staged for the
|
|
206
|
+
/** PENDING (ADR-0010): the act was staged for the owner's confirmation, not recorded. */
|
|
207
207
|
const EXIT = { OK: 0, REFUSED: 1, USAGE: 2, PENDING: 3 } as const;
|
|
208
208
|
|
|
209
209
|
/* -------------------------------------------------------------------------- */
|
|
@@ -233,8 +233,8 @@ const readIfPresent = async (path: string): Promise<string | null> => {
|
|
|
233
233
|
/**
|
|
234
234
|
* Scaffold a protocol's editable documents.
|
|
235
235
|
*
|
|
236
|
-
* Deliberately separate from `init`: scaffolding produces prose for
|
|
237
|
-
* edit, while `init` drops the
|
|
236
|
+
* Deliberately separate from `init`: scaffolding produces prose for an owner to
|
|
237
|
+
* edit, while `init` drops the Opening and opens the session. Conflating them would
|
|
238
238
|
* mean a session convened on an unread template.
|
|
239
239
|
*/
|
|
240
240
|
const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
@@ -250,7 +250,7 @@ const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
|
250
250
|
termination: { type: 'string' },
|
|
251
251
|
escalation: { type: 'string' },
|
|
252
252
|
parent: { type: 'string' },
|
|
253
|
-
'
|
|
253
|
+
'owner-confirmation': { type: 'string' },
|
|
254
254
|
},
|
|
255
255
|
});
|
|
256
256
|
|
|
@@ -258,7 +258,7 @@ const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
|
258
258
|
// and escalation flag are inherited into the Charter. Explicit flags below
|
|
259
259
|
// still override. This is what makes `scaffold --protocol battle-royale`
|
|
260
260
|
// produce a Charter that actually behaves like one.
|
|
261
|
-
const protocol = values.protocol ?? '
|
|
261
|
+
const protocol = values.protocol ?? 'majority-vote';
|
|
262
262
|
const manifestPath = join(
|
|
263
263
|
dirname(fileURLToPath(import.meta.url)), '..', 'protocols', `${protocol}.yml`,
|
|
264
264
|
);
|
|
@@ -273,9 +273,9 @@ const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
|
273
273
|
return EXIT.USAGE;
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
err('scaffold: --
|
|
276
|
+
const ownerConfirmation = values['owner-confirmation'] ?? 'required';
|
|
277
|
+
if (ownerConfirmation !== 'required' && ownerConfirmation !== 'off') {
|
|
278
|
+
err('scaffold: --owner-confirmation must be required | off');
|
|
279
279
|
return EXIT.USAGE;
|
|
280
280
|
}
|
|
281
281
|
const quorum = values.quorum === undefined ? undefined : Number(values.quorum);
|
|
@@ -285,13 +285,13 @@ const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
// Mechanics flags (ADR-0007) — validate up front so a typo does not silently
|
|
288
|
-
// default to
|
|
288
|
+
// default to the default protocol's rules.
|
|
289
289
|
if (values.resolution !== undefined && !isResolution(values.resolution)) {
|
|
290
|
-
err(`scaffold: --resolution must be majority | supermajority | unanimity`);
|
|
290
|
+
err(`scaffold: --resolution must be majority | supermajority | unanimity | owner | both-sides`);
|
|
291
291
|
return EXIT.USAGE;
|
|
292
292
|
}
|
|
293
293
|
if (values.exit !== undefined && !isExitPolicy(values.exit)) {
|
|
294
|
-
err(`scaffold: --exit must be
|
|
294
|
+
err(`scaffold: --exit must be owner | vote | elimination | none`);
|
|
295
295
|
return EXIT.USAGE;
|
|
296
296
|
}
|
|
297
297
|
if (values.termination !== undefined && !isTerminationPolicy(values.termination)) {
|
|
@@ -312,7 +312,7 @@ const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
|
312
312
|
// Monorepo placement (ADR-0008): --parent nests this session under a parent
|
|
313
313
|
// node in the same tree. inherits_from is the child->parent relative path, so
|
|
314
314
|
// the lineage resolves from within the session's own directory. init detects
|
|
315
|
-
// the enclosing repo and commits the
|
|
315
|
+
// the enclosing repo and commits the session opening there rather than nesting a repo.
|
|
316
316
|
const inherits_from = values.parent === undefined ? null : (relative(dir, values.parent) || '.');
|
|
317
317
|
const files = scaffoldTemplates(manifest.protocol, {
|
|
318
318
|
protocol,
|
|
@@ -322,7 +322,9 @@ const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
|
322
322
|
exit: values.exit ?? m.exit,
|
|
323
323
|
termination: values.termination ?? m.termination,
|
|
324
324
|
escalation: values.escalation ?? (manifest.protocol.no_escalation ? 'disabled' : 'enabled'),
|
|
325
|
-
|
|
325
|
+
immutable_charter: manifest.protocol.immutable_charter,
|
|
326
|
+
domain_veto: manifest.protocol.domain_veto,
|
|
327
|
+
owner_confirmation: ownerConfirmation,
|
|
326
328
|
});
|
|
327
329
|
// Scaffold writes over same-named files (ADR-0010: it replaces the bootstrap
|
|
328
330
|
// instructions `politik new` leaves). Say so, rather than doing it silently.
|
|
@@ -332,7 +334,7 @@ const cmdScaffold = async (argv: readonly string[]): Promise<number> => {
|
|
|
332
334
|
out(`SCAFFOLDED ${protocol}`);
|
|
333
335
|
for (const file of files) out(` ${file.path}${replaced.has(file.path) ? ' (replaced existing file)' : ''}`);
|
|
334
336
|
out('');
|
|
335
|
-
out(`Edit the
|
|
337
|
+
out(`Edit the Charter, then: politik init --charter ${join(dir, 'CHARTER.md')} --owner <handle>`);
|
|
336
338
|
return EXIT.OK;
|
|
337
339
|
};
|
|
338
340
|
|
|
@@ -474,7 +476,7 @@ const cmdRemote = async (argv: readonly string[]): Promise<number> => {
|
|
|
474
476
|
err(`remote: ${dir} is not a convened session — run politik init first`);
|
|
475
477
|
return EXIT.USAGE;
|
|
476
478
|
}
|
|
477
|
-
const handle = values.as ?? (await
|
|
479
|
+
const handle = values.as ?? (await openingOwner(dir));
|
|
478
480
|
const result = await enableSync(dir, url, { remote: values.name ?? 'origin', handle });
|
|
479
481
|
if (!result.ok) { err(`remote: ${result.message}`); return EXIT.REFUSED; }
|
|
480
482
|
out(`SHARED — ${result.message}`);
|
|
@@ -483,11 +485,11 @@ const cmdRemote = async (argv: readonly string[]): Promise<number> => {
|
|
|
483
485
|
return EXIT.OK;
|
|
484
486
|
};
|
|
485
487
|
|
|
486
|
-
/** The
|
|
487
|
-
const
|
|
488
|
-
const
|
|
489
|
-
for (const entry of parseEntries(
|
|
490
|
-
if (entry.type === RECORD_TYPES.
|
|
488
|
+
/** The owner named on the SESSION_OPENED entry. */
|
|
489
|
+
const openingOwner = async (dir: string): Promise<string | null> => {
|
|
490
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
491
|
+
for (const entry of parseEntries(log)) {
|
|
492
|
+
if (entry.type === RECORD_TYPES.SESSION_OPENED) return entry.actor;
|
|
491
493
|
}
|
|
492
494
|
return null;
|
|
493
495
|
};
|
|
@@ -550,18 +552,18 @@ const cmdSync = async (argv: readonly string[]): Promise<number> => {
|
|
|
550
552
|
};
|
|
551
553
|
|
|
552
554
|
/* -------------------------------------------------------------------------- */
|
|
553
|
-
/* The
|
|
555
|
+
/* The owner's confirmation (ADR-0010 §2) */
|
|
554
556
|
/* -------------------------------------------------------------------------- */
|
|
555
557
|
|
|
556
558
|
/**
|
|
557
|
-
* Set only by `politik confirm`, in-process, after the
|
|
559
|
+
* Set only by `politik confirm`, in-process, after the owner has typed the act's
|
|
558
560
|
* id at a terminal. There is deliberately no flag or environment variable that
|
|
559
561
|
* sets it: a harness cannot pass its way past the gate.
|
|
560
562
|
*/
|
|
561
|
-
let
|
|
563
|
+
let ownerConfirmed = false;
|
|
562
564
|
|
|
563
565
|
/** Read one line from the terminal. Only ever called when stdin is a TTY. */
|
|
564
|
-
const
|
|
566
|
+
const askOwner = async (prompt: string): Promise<string> => {
|
|
565
567
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
566
568
|
try { return (await rl.question(prompt)).trim(); } finally { rl.close(); }
|
|
567
569
|
};
|
|
@@ -570,27 +572,27 @@ const askSpeaker = async (prompt: string): Promise<string> => {
|
|
|
570
572
|
* Gate a constitutional act. Returns null when it may proceed, or an exit code
|
|
571
573
|
* when it must not run now.
|
|
572
574
|
*
|
|
573
|
-
* Under `
|
|
575
|
+
* Under `owner_confirmation: required`: a person at a terminal (no harness
|
|
574
576
|
* detected) is asked inline; anything else — an AI harness, a script, a pipe — has
|
|
575
577
|
* the act staged for `politik confirm` and nothing reaches the record. A Charter
|
|
576
578
|
* without the setting (every pre-ADR-0010 session) is never gated.
|
|
577
579
|
*/
|
|
578
|
-
const
|
|
580
|
+
const awaitOwner = async (
|
|
579
581
|
act: ConstitutionalAct,
|
|
580
582
|
argv: readonly string[],
|
|
581
583
|
dir: string,
|
|
582
584
|
summary: string,
|
|
583
585
|
): Promise<number | null> => {
|
|
584
|
-
if (
|
|
586
|
+
if (ownerConfirmed) return null;
|
|
585
587
|
const charterRaw = await readIfPresent(join(dir, 'CHARTER.md'));
|
|
586
588
|
const parsed = charterRaw === null ? null : parseCharter(charterRaw);
|
|
587
|
-
if (parsed === null || !parsed.ok || parsed.charter.session.
|
|
589
|
+
if (parsed === null || !parsed.ok || parsed.charter.session.owner_confirmation !== 'required') return null;
|
|
588
590
|
|
|
589
591
|
const interactive = process.stdin.isTTY === true;
|
|
590
|
-
if (
|
|
591
|
-
out(`
|
|
592
|
+
if (isOwnerAtTerminal(process.env, interactive)) {
|
|
593
|
+
out(`Permanent act — this will be recorded in the log for good:`);
|
|
592
594
|
out(` ${summary}`);
|
|
593
|
-
const typed = await
|
|
595
|
+
const typed = await askOwner(`Type "${act}" to confirm: `);
|
|
594
596
|
if (typed === act) return null;
|
|
595
597
|
err('Not confirmed — nothing was recorded.');
|
|
596
598
|
return EXIT.REFUSED;
|
|
@@ -612,14 +614,14 @@ const awaitSpeaker = async (
|
|
|
612
614
|
}
|
|
613
615
|
out(`STAGED — ${summary}`);
|
|
614
616
|
out(` pending act: ${pending.id}`);
|
|
615
|
-
out(' Nothing is recorded yet. This is the
|
|
617
|
+
out(' Nothing is recorded yet. This is the owner\'s decision: they confirm it in');
|
|
616
618
|
out(' their own terminal (not through an AI harness):');
|
|
617
619
|
out(` politik confirm ${pending.id}${dir === '.' ? '' : ` --dir ${dir}`}`);
|
|
618
620
|
out(` To discard it instead: politik reject ${pending.id}${dir === '.' ? '' : ` --dir ${dir}`}`);
|
|
619
621
|
return EXIT.PENDING;
|
|
620
622
|
};
|
|
621
623
|
|
|
622
|
-
/** `politik pending [--dir] [--json]` — staged acts awaiting the
|
|
624
|
+
/** `politik pending [--dir] [--json]` — staged acts awaiting the owner. */
|
|
623
625
|
const cmdPending = async (argv: readonly string[]): Promise<number> => {
|
|
624
626
|
const { values } = parseArgs({ args: [...argv], options: { dir: { type: 'string' }, json: { type: 'boolean' } } });
|
|
625
627
|
await refreshForRead(values.dir ?? '.');
|
|
@@ -641,11 +643,11 @@ const actorOf = (argv: readonly string[]): string | null => {
|
|
|
641
643
|
};
|
|
642
644
|
|
|
643
645
|
/**
|
|
644
|
-
* `politik confirm <id>` — the
|
|
646
|
+
* `politik confirm <id>` — the owner executes a staged act.
|
|
645
647
|
*
|
|
646
648
|
* Refuses without a terminal or under a detected harness, shows exactly what will
|
|
647
649
|
* run, and requires the act's id to be typed back. Only then is the act replayed
|
|
648
|
-
* and committed, with provenance naming who requested it and that the
|
|
650
|
+
* and committed, with provenance naming who requested it and that the owner
|
|
649
651
|
* confirmed it.
|
|
650
652
|
*/
|
|
651
653
|
const cmdConfirm = async (argv: readonly string[]): Promise<number> => {
|
|
@@ -656,8 +658,8 @@ const cmdConfirm = async (argv: readonly string[]): Promise<number> => {
|
|
|
656
658
|
if (id === undefined || !isPendingId(id)) { err('confirm: a pending act id is required — see: politik pending'); return EXIT.USAGE; }
|
|
657
659
|
|
|
658
660
|
const harness = detectHarness(process.env);
|
|
659
|
-
if (!
|
|
660
|
-
err(`confirm: refused — this must be run by the
|
|
661
|
+
if (!isOwnerAtTerminal(process.env, process.stdin.isTTY === true)) {
|
|
662
|
+
err(`confirm: refused — this must be run by the owner at a terminal, not by ${harness ?? 'a script or pipe'}.`);
|
|
661
663
|
err(` Open your own terminal and run: politik confirm ${id}${values.dir === undefined ? '' : ` --dir ${values.dir}`}`);
|
|
662
664
|
return EXIT.REFUSED;
|
|
663
665
|
}
|
|
@@ -678,15 +680,15 @@ const cmdConfirm = async (argv: readonly string[]): Promise<number> => {
|
|
|
678
680
|
}
|
|
679
681
|
}
|
|
680
682
|
|
|
681
|
-
out(`
|
|
683
|
+
out(`Permanent act — this will be recorded in the log for good:`);
|
|
682
684
|
out(` ${pending.summary}`);
|
|
683
685
|
out(` command: politik ${pending.act} ${withDir(pending.argv, sessionDir).join(' ')}`);
|
|
684
686
|
out(` requested via: ${pending.requested_via} at ${pending.requested_at}`);
|
|
685
|
-
const typed = await
|
|
687
|
+
const typed = await askOwner(`Type ${id} to confirm: `);
|
|
686
688
|
if (typed !== id) { err('Not confirmed — nothing was recorded. The act is still pending.'); return EXIT.REFUSED; }
|
|
687
689
|
|
|
688
|
-
|
|
689
|
-
actProvenance = { via: pending.requested_via, confirmedBy:
|
|
690
|
+
ownerConfirmed = true;
|
|
691
|
+
actProvenance = { via: pending.requested_via, confirmedBy: CONFIRMED_BY_OWNER };
|
|
690
692
|
try {
|
|
691
693
|
// Replay against this machine's copy of the session: a pending act shared from
|
|
692
694
|
// another machine names that machine's path (ADR-0011 §4).
|
|
@@ -700,7 +702,7 @@ const cmdConfirm = async (argv: readonly string[]): Promise<number> => {
|
|
|
700
702
|
}
|
|
701
703
|
return code;
|
|
702
704
|
} finally {
|
|
703
|
-
|
|
705
|
+
ownerConfirmed = false;
|
|
704
706
|
actProvenance = null;
|
|
705
707
|
}
|
|
706
708
|
};
|
|
@@ -782,7 +784,7 @@ const cmdProtocol = async (argv: readonly string[]): Promise<number> => {
|
|
|
782
784
|
if (verb === 'new') {
|
|
783
785
|
const { values, positionals } = parseArgs({
|
|
784
786
|
args: rest,
|
|
785
|
-
options: {
|
|
787
|
+
options: { out: { type: 'string' } },
|
|
786
788
|
allowPositionals: true,
|
|
787
789
|
});
|
|
788
790
|
const name = positionals[0];
|
|
@@ -790,13 +792,7 @@ const cmdProtocol = async (argv: readonly string[]): Promise<number> => {
|
|
|
790
792
|
err('protocol new: a protocol name is required');
|
|
791
793
|
return EXIT.USAGE;
|
|
792
794
|
}
|
|
793
|
-
const
|
|
794
|
-
if (!(PROTOCOL_MODES as readonly string[]).includes(mode)) {
|
|
795
|
-
err(`protocol new: --mode must be one of ${PROTOCOL_MODES.join(' | ')}`);
|
|
796
|
-
return EXIT.USAGE;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
const manifest = generateProtocol({ name, mode });
|
|
795
|
+
const manifest = generateProtocol({ name });
|
|
800
796
|
if (values.out === undefined) {
|
|
801
797
|
out(manifest);
|
|
802
798
|
} else {
|
|
@@ -855,7 +851,7 @@ const cmdValidate = async (argv: readonly string[]): Promise<number> => {
|
|
|
855
851
|
out(` protocol ${parsed.charter.protocol}`);
|
|
856
852
|
out(` quorum ${parsed.charter.session.quorum}`);
|
|
857
853
|
out(` merge strategy ${parsed.charter.session.merge_strategy}`);
|
|
858
|
-
out(`
|
|
854
|
+
out(` enact ${parsed.charter.session.enact}`);
|
|
859
855
|
out(` constituencies ${parsed.charter.constituencies.length}`);
|
|
860
856
|
return EXIT.OK;
|
|
861
857
|
};
|
|
@@ -865,7 +861,7 @@ const cmdInit = async (argv: readonly string[]): Promise<number> => {
|
|
|
865
861
|
args: [...argv],
|
|
866
862
|
options: {
|
|
867
863
|
charter: { type: 'string' },
|
|
868
|
-
|
|
864
|
+
owner: { type: 'string' },
|
|
869
865
|
dir: { type: 'string' },
|
|
870
866
|
out: { type: 'string' },
|
|
871
867
|
guid: { type: 'string' },
|
|
@@ -875,8 +871,8 @@ const cmdInit = async (argv: readonly string[]): Promise<number> => {
|
|
|
875
871
|
},
|
|
876
872
|
});
|
|
877
873
|
|
|
878
|
-
if (values.charter === undefined || values.
|
|
879
|
-
err('init: --charter and --
|
|
874
|
+
if (values.charter === undefined || values.owner === undefined) {
|
|
875
|
+
err('init: --charter and --owner are required');
|
|
880
876
|
return EXIT.USAGE;
|
|
881
877
|
}
|
|
882
878
|
|
|
@@ -889,45 +885,45 @@ const cmdInit = async (argv: readonly string[]): Promise<number> => {
|
|
|
889
885
|
// `--dir` is the standard flag; `--out` stays an accepted alias here.
|
|
890
886
|
const dir = values.dir ?? values.out ?? '.';
|
|
891
887
|
|
|
892
|
-
const result =
|
|
888
|
+
const result = openSession({
|
|
893
889
|
charter_source: source,
|
|
894
890
|
session_guid: values.guid ?? crypto.randomUUID(),
|
|
895
891
|
now: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z'),
|
|
896
|
-
|
|
892
|
+
owner: values.owner,
|
|
897
893
|
protocol: values.protocol === undefined ? undefined : { name: values.protocol },
|
|
898
894
|
instruction_files: await readInstructionFiles(dir),
|
|
899
895
|
});
|
|
900
896
|
await writeFiles(dir, result.files);
|
|
901
897
|
|
|
902
898
|
if (!result.ok) {
|
|
903
|
-
err('
|
|
899
|
+
err('OPEN REFUSED — session did not open');
|
|
904
900
|
for (const issue of result.issues) {
|
|
905
901
|
const rule = issue.rule === undefined ? '' : ` (rule ${issue.rule})`;
|
|
906
902
|
err(` ${issue.field}: ${issue.message}${rule}`);
|
|
907
903
|
}
|
|
908
904
|
err('');
|
|
909
|
-
err(`The refusal is on the record in ${join(dir, '
|
|
905
|
+
err(`The refusal is on the record in ${join(dir, 'LOG.md')}`);
|
|
910
906
|
return EXIT.REFUSED;
|
|
911
907
|
}
|
|
912
908
|
|
|
913
|
-
//
|
|
909
|
+
// session opening creates the session repo. On a local session that means making
|
|
914
910
|
// `dir` a git repo, or the record silently never commits. Idempotent — an
|
|
915
911
|
// existing (e.g. cloned GitHub) repo is left alone.
|
|
916
|
-
const repo = await initSessionRepo(dir, values.
|
|
912
|
+
const repo = await initSessionRepo(dir, values.owner, result.state.session_guid, undefined, {
|
|
917
913
|
standalone: values.standalone === true,
|
|
918
914
|
});
|
|
919
915
|
|
|
920
|
-
out('
|
|
916
|
+
out('SESSION OPENED');
|
|
921
917
|
out(` session ${result.state.session_guid}`);
|
|
922
918
|
out(` protocol ${result.charter.protocol}`);
|
|
923
919
|
out(` state ${result.state.state}`);
|
|
924
920
|
out(` files ${result.files.length} written to ${dir}`);
|
|
925
921
|
out(` git ${repo.reason}${repo.sha ? ` (${repo.sha.slice(0, 7)})` : ''}`);
|
|
926
922
|
|
|
927
|
-
// ADR-0011: share the session from the
|
|
923
|
+
// ADR-0011: share the session from the session opening, with the owner as this
|
|
928
924
|
// clone's seat. The session is open either way; a failed publish is reported.
|
|
929
925
|
if (values.remote !== undefined) {
|
|
930
|
-
const shared = await enableSync(dir, values.remote, { handle: values.
|
|
926
|
+
const shared = await enableSync(dir, values.remote, { handle: values.owner });
|
|
931
927
|
if (shared.ok) out(` shared ${shared.message}`);
|
|
932
928
|
else { err(` shared NOT shared — ${shared.message}. Retry with: politik remote ${values.remote}`); return EXIT.REFUSED; }
|
|
933
929
|
}
|
|
@@ -936,7 +932,7 @@ const cmdInit = async (argv: readonly string[]): Promise<number> => {
|
|
|
936
932
|
|
|
937
933
|
|
|
938
934
|
/* -------------------------------------------------------------------------- */
|
|
939
|
-
/*
|
|
935
|
+
/* vote helpers */
|
|
940
936
|
/* -------------------------------------------------------------------------- */
|
|
941
937
|
|
|
942
938
|
/**
|
|
@@ -954,65 +950,61 @@ const sessionProtocol = async (protocolName: string): Promise<Protocol | null> =
|
|
|
954
950
|
return parsed.ok ? parsed.protocol : null;
|
|
955
951
|
};
|
|
956
952
|
|
|
957
|
-
/** Render a CANON role in the session protocol's vocabulary, or CANON if none. */
|
|
958
|
-
const asRoleTerm = (protocol: Protocol | null, role: string): string =>
|
|
959
|
-
protocol === null ? role : roleTerm(protocol, role as never);
|
|
960
|
-
|
|
961
|
-
/** Render a CANON primitive/verb in the session protocol's vocabulary. */
|
|
962
|
-
const asTerm = (protocol: Protocol | null, canon: string): string =>
|
|
963
|
-
protocol === null ? canon : term(protocol, canon);
|
|
964
953
|
|
|
965
954
|
const loadSession = async (dir: string) => {
|
|
966
955
|
const stateRaw = await readIfPresent(join(dir, 'STATE.json'));
|
|
967
956
|
const state = stateRaw === null ? null : parseState(stateRaw);
|
|
968
|
-
const
|
|
957
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
969
958
|
const charterRaw = await readIfPresent(join(dir, 'CHARTER.md'));
|
|
970
959
|
const charter = charterRaw === null ? null : parseCharter(charterRaw);
|
|
971
|
-
return { state,
|
|
960
|
+
return { state, log, charter: charter?.ok === true ? charter.charter : null };
|
|
972
961
|
};
|
|
973
962
|
|
|
974
|
-
/** The Charter fingerprint recorded on the
|
|
975
|
-
const
|
|
976
|
-
for (const entry of parseEntries(
|
|
977
|
-
if (entry.type === RECORD_TYPES.
|
|
963
|
+
/** The Charter fingerprint recorded on the SESSION_OPENED entry, or null if none. */
|
|
964
|
+
const openingFingerprint = (log: string): string | null => {
|
|
965
|
+
for (const entry of parseEntries(log)) {
|
|
966
|
+
if (entry.type === RECORD_TYPES.SESSION_OPENED) {
|
|
978
967
|
return entry.fields['Charter SHA256'] ?? null;
|
|
979
968
|
}
|
|
980
969
|
}
|
|
981
970
|
return null;
|
|
982
971
|
};
|
|
983
972
|
|
|
973
|
+
/** Whether the SESSION_OPENED entry locked the Charter. The log, not CHARTER.md, decides. */
|
|
974
|
+
const openingLocked = (log: string): boolean => {
|
|
975
|
+
for (const entry of parseEntries(log)) {
|
|
976
|
+
if (entry.type === RECORD_TYPES.SESSION_OPENED) return entry.fields['Charter locked'] === 'yes';
|
|
977
|
+
}
|
|
978
|
+
return false;
|
|
979
|
+
};
|
|
980
|
+
|
|
984
981
|
/**
|
|
985
982
|
* Refuse a governance act when an immutable-charter protocol's Charter has been
|
|
986
|
-
* edited since
|
|
983
|
+
* edited since session opening.
|
|
987
984
|
*
|
|
988
|
-
* A
|
|
989
|
-
*
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
*
|
|
993
|
-
*
|
|
994
|
-
*
|
|
995
|
-
* enforced retroactively), or an intact Charter.
|
|
985
|
+
* A session whose Charter sets `session.immutable_charter: true` records, on its
|
|
986
|
+
* SESSION_OPENED entry, the Charter's fingerprint and that it is locked. If
|
|
987
|
+
* CHARTER.md no longer matches, the rules were changed after the session opened,
|
|
988
|
+
* which a locked Charter forbids. The lock is read from the log, never from
|
|
989
|
+
* CHARTER.md, so editing the Charter cannot unlock it. Returns an operator-facing
|
|
990
|
+
* refusal, or null when the act may proceed: an unlocked session or an intact
|
|
991
|
+
* Charter.
|
|
996
992
|
*/
|
|
997
|
-
const immutableCharterViolation = async (
|
|
998
|
-
dir
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
const protocol = await sessionProtocol(protocolName);
|
|
1002
|
-
if (protocol === null || allowsCharterAmendment(protocol)) return null;
|
|
1003
|
-
const hansard = (await readIfPresent(join(dir, 'HANSARD.md'))) ?? '';
|
|
1004
|
-
const recorded = writDropFingerprint(hansard);
|
|
993
|
+
const immutableCharterViolation = async (dir: string): Promise<string | null> => {
|
|
994
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
995
|
+
if (!openingLocked(log)) return null;
|
|
996
|
+
const recorded = openingFingerprint(log);
|
|
1005
997
|
if (recorded === null) return null;
|
|
1006
998
|
const current = await readIfPresent(join(dir, 'CHARTER.md'));
|
|
1007
999
|
if (current === null) return null;
|
|
1008
1000
|
const now = charterFingerprint(current);
|
|
1009
1001
|
if (now === recorded) return null;
|
|
1010
1002
|
return [
|
|
1011
|
-
|
|
1012
|
-
'
|
|
1003
|
+
'Refused: this session locked its Charter when it opened — the rules',
|
|
1004
|
+
'cannot be changed mid-session,',
|
|
1013
1005
|
'yet CHARTER.md has changed since',
|
|
1014
1006
|
`(${recorded.slice(0, 12)} → ${now.slice(0, 12)}).`,
|
|
1015
|
-
'Revert CHARTER.md to its
|
|
1007
|
+
'Revert CHARTER.md to its session opening text, or close this session and',
|
|
1016
1008
|
'convene a new one under the amended Charter.',
|
|
1017
1009
|
].join(' ');
|
|
1018
1010
|
};
|
|
@@ -1030,20 +1022,20 @@ const readInstructionFiles = async (
|
|
|
1030
1022
|
};
|
|
1031
1023
|
|
|
1032
1024
|
/**
|
|
1033
|
-
* Refuse governance when the session's instruction files have changed since
|
|
1025
|
+
* Refuse governance when the session's instruction files have changed since Opening
|
|
1034
1026
|
* Drop (ADR-0010 §4).
|
|
1035
1027
|
*
|
|
1036
|
-
* These are the files the
|
|
1028
|
+
* These are the files the owner's own harness loads on entering the session. An
|
|
1037
1029
|
* agent that rewrites — or plants — one has tried to reprogram the governor's
|
|
1038
1030
|
* tool, so this applies under every protocol, not only immutable-charter ones.
|
|
1039
1031
|
* Null when the act may proceed: an intact set, or a session sealed before
|
|
1040
1032
|
* ADR-0010 (no fingerprint to compare against).
|
|
1041
1033
|
*/
|
|
1042
1034
|
const instructionsViolation = async (dir: string): Promise<string | null> => {
|
|
1043
|
-
const
|
|
1035
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
1044
1036
|
let recorded: string | null = null;
|
|
1045
|
-
for (const entry of parseEntries(
|
|
1046
|
-
if (entry.type === RECORD_TYPES.
|
|
1037
|
+
for (const entry of parseEntries(log)) {
|
|
1038
|
+
if (entry.type === RECORD_TYPES.SESSION_OPENED) { recorded = entry.fields['Instructions SHA256'] ?? null; break; }
|
|
1047
1039
|
}
|
|
1048
1040
|
if (recorded === null) return null;
|
|
1049
1041
|
const files = await readInstructionFiles(dir);
|
|
@@ -1051,29 +1043,29 @@ const instructionsViolation = async (dir: string): Promise<string | null> => {
|
|
|
1051
1043
|
if (now === recorded) return null;
|
|
1052
1044
|
return [
|
|
1053
1045
|
`Refused: this session's instruction files (${INSTRUCTION_FILES.join(', ')}) have changed since`,
|
|
1054
|
-
`
|
|
1046
|
+
`session opening (${recorded.slice(0, 12)} → ${now.slice(0, 12)}). These are the instructions the owner's`,
|
|
1055
1047
|
'own AI harness loads here; an agent may have tried to rewrite them. Inspect with `git diff`',
|
|
1056
|
-
'and restore them from the
|
|
1048
|
+
'and restore them from the session opening commit before continuing.',
|
|
1057
1049
|
].join(' ');
|
|
1058
1050
|
};
|
|
1059
1051
|
|
|
1060
1052
|
/**
|
|
1061
|
-
* Commands that only read, or that set a session up before
|
|
1053
|
+
* Commands that only read, or that set a session up before session opening. Every other
|
|
1062
1054
|
* command is governance and refuses to run while the instruction files are
|
|
1063
|
-
* tampered (ADR-0010 §4); these stay available so the
|
|
1055
|
+
* tampered (ADR-0010 §4); these stay available so the owner can see what
|
|
1064
1056
|
* happened and repair it.
|
|
1065
1057
|
*/
|
|
1066
1058
|
const UNGUARDED_COMMANDS: ReadonlySet<string | undefined> = new Set([
|
|
1067
1059
|
undefined, '-h', '--help', 'help', 'version', '--version',
|
|
1068
1060
|
'new', 'scaffold', 'init', 'doctor', 'protocol', 'validate',
|
|
1069
|
-
'status', '
|
|
1061
|
+
'status', 'log', 'ledger', 'integrity', 'pending', 'reject',
|
|
1070
1062
|
'registry', 'cascade', 'standings',
|
|
1071
1063
|
'remote', 'join', 'sync',
|
|
1072
1064
|
]);
|
|
1073
1065
|
|
|
1074
1066
|
/** Read-only commands that catch up with a shared record first (ADR-0011 §2). */
|
|
1075
1067
|
const REFRESH_BEFORE: ReadonlySet<string | undefined> = new Set([
|
|
1076
|
-
'status', '
|
|
1068
|
+
'status', 'log', 'ledger', 'integrity', 'standings',
|
|
1077
1069
|
]);
|
|
1078
1070
|
|
|
1079
1071
|
/** Governance commands not retried on a rejected push: re-running them has effects. */
|
|
@@ -1093,8 +1085,8 @@ const dirArg = (argv: readonly string[]): string => {
|
|
|
1093
1085
|
* Guard a governance write: prints the refusal and returns false if an
|
|
1094
1086
|
* immutable Charter has been tampered with, true when the act may proceed.
|
|
1095
1087
|
*/
|
|
1096
|
-
const charterIsIntact = async (dir: string,
|
|
1097
|
-
const violation = await immutableCharterViolation(dir
|
|
1088
|
+
const charterIsIntact = async (dir: string, _protocolName?: string): Promise<boolean> => {
|
|
1089
|
+
const violation = await immutableCharterViolation(dir);
|
|
1098
1090
|
if (violation === null) return true;
|
|
1099
1091
|
err(violation);
|
|
1100
1092
|
return false;
|
|
@@ -1103,14 +1095,14 @@ const charterIsIntact = async (dir: string, protocolName: string): Promise<boole
|
|
|
1103
1095
|
/**
|
|
1104
1096
|
* Atomic file write: land a complete temp file, then rename it over the target.
|
|
1105
1097
|
*
|
|
1106
|
-
* The
|
|
1098
|
+
* The record is the immutable record — the whole point of Politik — and a
|
|
1107
1099
|
* half-written record is worse than none. A plain writeFile opens with O_TRUNC:
|
|
1108
1100
|
* an interrupt between the truncate and the write (SIGPIPE from a closed `| head`,
|
|
1109
1101
|
* Ctrl-C, SIGTERM, a crash) leaves the file at zero bytes, and the operator has
|
|
1110
1102
|
* already been told the act succeeded. rename(2) is atomic on a POSIX filesystem,
|
|
1111
1103
|
* so the target is only ever replaced by a fully-written file; an interrupted
|
|
1112
1104
|
* write orphans a `.tmp` and leaves the record intact. This is the durability the
|
|
1113
|
-
*
|
|
1105
|
+
* Charter assume when they say the record is the source of truth.
|
|
1114
1106
|
*/
|
|
1115
1107
|
const atomicWrite = async (path: string, content: string): Promise<void> => {
|
|
1116
1108
|
const tmp = `${path}.tmp`;
|
|
@@ -1118,8 +1110,8 @@ const atomicWrite = async (path: string, content: string): Promise<void> => {
|
|
|
1118
1110
|
await rename(tmp, path);
|
|
1119
1111
|
};
|
|
1120
1112
|
|
|
1121
|
-
const
|
|
1122
|
-
atomicWrite(join(dir, '
|
|
1113
|
+
const writeLog = (dir: string, log: string) =>
|
|
1114
|
+
atomicWrite(join(dir, 'LOG.md'), log);
|
|
1123
1115
|
|
|
1124
1116
|
const writeState = (dir: string, state: SessionStateFile) =>
|
|
1125
1117
|
atomicWrite(join(dir, 'STATE.json'), serializeState(state));
|
|
@@ -1127,7 +1119,7 @@ const writeState = (dir: string, state: SessionStateFile) =>
|
|
|
1127
1119
|
/**
|
|
1128
1120
|
* Persist a governance act to the record.
|
|
1129
1121
|
*
|
|
1130
|
-
* Writing the file is not enough: the
|
|
1122
|
+
* Writing the file is not enough: the Charter this framework ships say
|
|
1131
1123
|
* uncommitted work does not exist, and that binds the engine as much as an
|
|
1132
1124
|
* actor. Reports what happened rather than failing silently — a session run
|
|
1133
1125
|
* outside git is legitimate, but the operator should know the record is not
|
|
@@ -1164,7 +1156,7 @@ const logAct = async (dir: string, actor: string, role: Role, item: string): Pro
|
|
|
1164
1156
|
/**
|
|
1165
1157
|
* Provenance for the act in flight (ADR-0010 §3). Normally derived from this
|
|
1166
1158
|
* process; `politik confirm` overrides it so a staged act records who originally
|
|
1167
|
-
* requested it and that the
|
|
1159
|
+
* requested it and that the owner confirmed it.
|
|
1168
1160
|
*/
|
|
1169
1161
|
let actProvenance: { readonly via: string; readonly confirmedBy: string | null } | null = null;
|
|
1170
1162
|
|
|
@@ -1181,7 +1173,7 @@ const commitAct = async (
|
|
|
1181
1173
|
// ADR-0011 §5: a confirmed act is signed with the confirming person's key when
|
|
1182
1174
|
// the Charter requires it, so confirmation cannot be forged without that key.
|
|
1183
1175
|
const sign = confirmedBy !== null && (await charterRequiresSignedConfirmations(dir));
|
|
1184
|
-
const paths = ['
|
|
1176
|
+
const paths = ['LOG.md', 'STATE.json', 'LEDGER.md', '.politik/LEDGER.md', ...extra];
|
|
1185
1177
|
const result = await commitRecord(dir, `${message}\n\n${provenanceTrailers(via, confirmedBy, operator)}`, paths, undefined, { sign });
|
|
1186
1178
|
if (sign && !result.committed && result.reason === 'signing failed') {
|
|
1187
1179
|
// The act must not survive unsigned (ADR-0011 §5): put every record file back
|
|
@@ -1199,14 +1191,14 @@ const commitAct = async (
|
|
|
1199
1191
|
};
|
|
1200
1192
|
|
|
1201
1193
|
/**
|
|
1202
|
-
* Commits in this session that record
|
|
1194
|
+
* Commits in this session that record an owner confirmation but whose signature
|
|
1203
1195
|
* does not verify (`%G?` other than G or U). Verification uses the clone's git
|
|
1204
1196
|
* configuration — for SSH signatures, `gpg.ssh.allowedSignersFile`.
|
|
1205
1197
|
*/
|
|
1206
1198
|
const unverifiedConfirmations = async (dir: string): Promise<readonly string[]> => {
|
|
1207
|
-
const
|
|
1208
|
-
if (
|
|
1209
|
-
return
|
|
1199
|
+
const gitLog = await gitx(dir, ['log', '--format=%H%x09%G?%x09%(trailers:key=Politik-Confirmed-By,valueonly,separator=%x2C)', '--', '.']);
|
|
1200
|
+
if (gitLog.code !== 0 || gitLog.out === '') return [];
|
|
1201
|
+
return gitLog.out.split('\n')
|
|
1210
1202
|
.map((line) => line.split('\t'))
|
|
1211
1203
|
.filter(([, status, confirmed]) => (confirmed ?? '').trim() !== '' && status !== 'G' && status !== 'U')
|
|
1212
1204
|
.map(([sha]) => sha ?? '');
|
|
@@ -1223,6 +1215,12 @@ const reportCommit = (result: CommitResult): void => {
|
|
|
1223
1215
|
if (result.committed) out(` recorded ${result.sha?.slice(0, 8) ?? ''}`);
|
|
1224
1216
|
else if (result.reason === 'not a git repository') {
|
|
1225
1217
|
out(' [WARN] not a git repository — the record is not durable');
|
|
1218
|
+
} else if (result.reason === 'git add failed' || result.reason === 'commit failed') {
|
|
1219
|
+
// Loud, on stderr: the act was written to the working tree but git refused
|
|
1220
|
+
// the commit, so it is NOT on the record. Printing success here told an
|
|
1221
|
+
// agent in a sandbox (read-only .git) that its vote counted when it did not.
|
|
1222
|
+
err(` [ERROR] ${result.reason} — the act was written but NOT committed, so it is not on the record`);
|
|
1223
|
+
err(' Check that this process can write to .git, then repeat the act.');
|
|
1226
1224
|
}
|
|
1227
1225
|
};
|
|
1228
1226
|
|
|
@@ -1252,125 +1250,110 @@ const applyProjection = async (
|
|
|
1252
1250
|
dir: string,
|
|
1253
1251
|
act: string,
|
|
1254
1252
|
result: { projected: boolean; detail: string; ref: string | null },
|
|
1255
|
-
|
|
1253
|
+
log: string,
|
|
1256
1254
|
): Promise<string> => {
|
|
1257
|
-
await
|
|
1255
|
+
await writeLog(dir, appendEntry(log, projectionEntry(act, result, nowStamp())));
|
|
1258
1256
|
return ` ${result.projected ? 'projected' : 'not projected'} — ${result.detail}`;
|
|
1259
1257
|
};
|
|
1260
1258
|
|
|
1261
|
-
/** `politik
|
|
1262
|
-
const
|
|
1259
|
+
/** `politik vote open|cast|tally`. */
|
|
1260
|
+
const cmdVote = async (argv: readonly string[]): Promise<number> => {
|
|
1263
1261
|
const [verb, ...rest] = argv;
|
|
1264
1262
|
const { values } = parseArgs({
|
|
1265
1263
|
args: rest,
|
|
1266
1264
|
options: {
|
|
1267
1265
|
dir: { type: 'string' }, motion: { type: 'string' }, actor: { type: 'string' },
|
|
1268
1266
|
role: { type: 'string' }, vote: { type: 'string' }, reviewers: { type: 'string' },
|
|
1269
|
-
decide: { type: 'string' },
|
|
1267
|
+
decide: { type: 'string' }, removes: { type: 'string' },
|
|
1270
1268
|
...PROVIDER_OPTS,
|
|
1271
1269
|
},
|
|
1272
1270
|
});
|
|
1273
1271
|
|
|
1274
1272
|
const dir = values.dir ?? '.';
|
|
1275
|
-
const { state,
|
|
1273
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1276
1274
|
if (state === null || charter === null) {
|
|
1277
|
-
err(`
|
|
1275
|
+
err(`vote: ${dir} is not a session repo`);
|
|
1278
1276
|
return EXIT.USAGE;
|
|
1279
1277
|
}
|
|
1280
1278
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
1281
1279
|
if (values.motion === undefined) {
|
|
1282
|
-
err('
|
|
1280
|
+
err('vote: --motion is required');
|
|
1283
1281
|
return EXIT.USAGE;
|
|
1284
1282
|
}
|
|
1285
1283
|
const protocol = await sessionProtocol(charter.protocol);
|
|
1286
1284
|
|
|
1287
1285
|
try {
|
|
1288
|
-
if (verb === '
|
|
1289
|
-
if (values.actor === undefined) { err('
|
|
1290
|
-
const result =
|
|
1286
|
+
if (verb === 'open') {
|
|
1287
|
+
if (values.actor === undefined) { err('vote open: --actor is required'); return EXIT.USAGE; }
|
|
1288
|
+
const result = openBallot({
|
|
1291
1289
|
motion: values.motion, at: nowStamp(), actor: values.actor,
|
|
1292
1290
|
role: (values.role ?? 'OPERATOR') as never,
|
|
1293
1291
|
reviewers: (values.reviewers ?? '').split(',').filter((r) => r.length > 0),
|
|
1294
1292
|
state,
|
|
1295
|
-
|
|
1296
|
-
|
|
1293
|
+
exit_policy: charter.mechanics.exit,
|
|
1294
|
+
resolution: charter.mechanics.resolution,
|
|
1295
|
+
...(values.removes === undefined ? {} : { removes: values.removes }),
|
|
1296
|
+
}, log);
|
|
1297
|
+
await writeLog(dir, result.log);
|
|
1297
1298
|
const { provider } = resolveProvider({ repo: values.repo, token: values.token });
|
|
1298
1299
|
const reviewers = (values.reviewers ?? '').split(',').filter((r) => r.length > 0);
|
|
1299
|
-
const projected = await
|
|
1300
|
-
const projMsg = await applyProjection(dir, `
|
|
1300
|
+
const projected = await projectBallot(provider, result.log, values.motion, reviewers);
|
|
1301
|
+
const projMsg = await applyProjection(dir, `BALLOT_OPENED ${values.motion}`, projected, result.log);
|
|
1301
1302
|
|
|
1302
|
-
const rec = await commitAct(dir, `
|
|
1303
|
-
out(
|
|
1303
|
+
const rec = await commitAct(dir, `BALLOT_OPENED — ${values.motion}`);
|
|
1304
|
+
out(values.removes === undefined ? `Vote opened on ${values.motion}` : `Removal vote opened on ${values.motion}: remove ${values.removes}`);
|
|
1304
1305
|
out(projMsg);
|
|
1305
1306
|
reportCommit(rec);
|
|
1306
1307
|
return EXIT.OK;
|
|
1307
1308
|
}
|
|
1308
1309
|
|
|
1309
|
-
if (verb === '
|
|
1310
|
+
if (verb === 'cast') {
|
|
1310
1311
|
if (values.actor === undefined || values.vote === undefined) {
|
|
1311
|
-
err('
|
|
1312
|
+
err('vote cast: --actor and --vote are required'); return EXIT.USAGE;
|
|
1312
1313
|
}
|
|
1313
1314
|
const result = castVote({
|
|
1314
1315
|
motion: values.motion, at: nowStamp(), actor: values.actor,
|
|
1315
1316
|
role: (values.role ?? 'OPERATOR') as never,
|
|
1316
1317
|
vote: values.vote.toUpperCase() as Vote, state,
|
|
1317
|
-
},
|
|
1318
|
-
await
|
|
1318
|
+
}, log);
|
|
1319
|
+
await writeLog(dir, result.log);
|
|
1319
1320
|
const rec = await commitAct(dir, `VOTE_CAST — ${values.actor} on ${values.motion}`);
|
|
1320
|
-
out(
|
|
1321
|
+
out(`Vote recorded — ${values.actor}: ${values.vote.toUpperCase()}`);
|
|
1321
1322
|
reportCommit(rec);
|
|
1322
1323
|
return EXIT.OK;
|
|
1323
1324
|
}
|
|
1324
1325
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
const outcome = tallyDivision(
|
|
1335
|
-
hansard, values.motion, charter.session.quorum, null, charter.mechanics.resolution,
|
|
1336
|
-
);
|
|
1337
|
-
|
|
1338
|
-
// A tie with quorum is a DEADLOCK, not a rejection (ADR-0004 Proposal 4):
|
|
1339
|
-
// the House could not decide, so the sitting suspends for AUTHORITY to
|
|
1340
|
-
// break rather than silently recording a loss. Only genuine ties suspend;
|
|
1341
|
-
// a majority either way falls through to the ordinary outcome below.
|
|
1342
|
-
if (!outcome.carried && outcome.ayes === outcome.noes && outcome.quorum_met) {
|
|
1343
|
-
const deadlock = suspendForDeadlock(outcome, nowStamp(), state, hansard);
|
|
1344
|
-
await writeHansard(dir, deadlock.hansard);
|
|
1345
|
-
await writeState(dir, deadlock.state);
|
|
1346
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `DEADLOCK ${values.motion}`);
|
|
1347
|
-
const rec = await commitAct(dir, `DEADLOCK — ${values.motion}`);
|
|
1348
|
-
out(`${asTerm(protocol, 'MOTION')} DEADLOCKED — tied ${outcome.ayes} all, no majority`);
|
|
1349
|
-
out(' the session is SUSPENDED — AUTHORITY must break the tie:');
|
|
1350
|
-
out(` politik division break --motion ${values.motion} --actor <speaker> --decide carry|reject`);
|
|
1351
|
-
reportCommit(rec);
|
|
1352
|
-
return EXIT.REFUSED;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
const result = recordOutcome(outcome, nowStamp(), values.actor ?? 'RECORD',
|
|
1356
|
-
(values.role ?? 'OPERATOR') as never, hansard);
|
|
1326
|
+
/**
|
|
1327
|
+
* What a decided vote sets off, the same whether a tally or the owner's tie
|
|
1328
|
+
* break decided it: the elimination cull, a carried removal vote, and the
|
|
1329
|
+
* termination rule. Breaking a tie used to skip all three, so an elimination
|
|
1330
|
+
* session stuck at two actors could never reach its last one standing.
|
|
1331
|
+
*/
|
|
1332
|
+
const afterOutcome = async (
|
|
1333
|
+
decided: string, carried: boolean, motion: string, current: SessionStateFile,
|
|
1334
|
+
): Promise<{ doc: string; eliminated: readonly RecordEntry[]; removed: RecordEntry | null; terminationMsg: string | null }> => {
|
|
1357
1335
|
// exit: elimination culls the losing side (ADR-0007). The outcome is
|
|
1358
1336
|
// recorded first, then the cull it triggers, so the record reads in order.
|
|
1359
|
-
let doc =
|
|
1360
|
-
const eliminated = cull(doc,
|
|
1337
|
+
let doc = decided;
|
|
1338
|
+
const eliminated = cull(doc, motion, charter.mechanics.exit, nowStamp());
|
|
1361
1339
|
for (const entry of eliminated) doc = appendEntry(doc, entry);
|
|
1340
|
+
// A carried removal vote removes its target. It is not a verdict: the
|
|
1341
|
+
// session carries on, whatever the termination rule.
|
|
1342
|
+
const removalVote = removalTarget(doc, motion) !== null;
|
|
1343
|
+
const removed = carried ? removeByVote(doc, motion, nowStamp()) : null;
|
|
1344
|
+
if (removed !== null) doc = appendEntry(doc, removed);
|
|
1362
1345
|
|
|
1363
1346
|
// termination override point (ADR-0007). last-standing seals the moment a
|
|
1364
1347
|
// cull leaves one seated actor — checked only after an actual elimination,
|
|
1365
1348
|
// so a fresh session is never mistaken for a finished one. verdict seals the
|
|
1366
|
-
// moment a
|
|
1349
|
+
// moment a vote carries: a decision has been reached and the session ends.
|
|
1367
1350
|
let terminationMsg: string | null = null;
|
|
1368
1351
|
const seal = async (trigger: Trigger, summary: string, msg: string) => {
|
|
1369
|
-
const end =
|
|
1370
|
-
{ at: nowStamp(), actor: 'RECORD', role: 'OPERATOR' as never, trigger, state, summary },
|
|
1352
|
+
const end = closeSession(
|
|
1353
|
+
{ at: nowStamp(), actor: 'RECORD', role: 'OPERATOR' as never, trigger, state: current, summary },
|
|
1371
1354
|
doc,
|
|
1372
1355
|
);
|
|
1373
|
-
doc = end.
|
|
1356
|
+
doc = end.log;
|
|
1374
1357
|
await writeState(dir, end.state);
|
|
1375
1358
|
terminationMsg = msg;
|
|
1376
1359
|
};
|
|
@@ -1383,28 +1366,74 @@ const cmdDivision = async (argv: readonly string[]): Promise<number> => {
|
|
|
1383
1366
|
`last standing: ${standing.survivor ?? 'none'}`,
|
|
1384
1367
|
);
|
|
1385
1368
|
}
|
|
1386
|
-
} else if (charter.mechanics.termination === 'verdict' &&
|
|
1387
|
-
await seal(
|
|
1388
|
-
'TRIGGER_VERDICT' as Trigger,
|
|
1389
|
-
`Verdict reached on ${values.motion}`,
|
|
1390
|
-
`verdict reached on ${values.motion}`,
|
|
1391
|
-
);
|
|
1369
|
+
} else if (charter.mechanics.termination === 'verdict' && carried && !removalVote) {
|
|
1370
|
+
await seal('TRIGGER_VERDICT' as Trigger, `Verdict reached on ${motion}`, `verdict reached on ${motion}`);
|
|
1392
1371
|
}
|
|
1372
|
+
return { doc, eliminated, removed, terminationMsg };
|
|
1373
|
+
};
|
|
1393
1374
|
|
|
1394
|
-
|
|
1375
|
+
if (verb === 'tally') {
|
|
1376
|
+
// A vote is decided only while the session runs. Tallying during a suspension
|
|
1377
|
+
// closed a ballot before the owner's ruling, so votes cast after it were
|
|
1378
|
+
// refused (found dogfooding: a Codex panelist caught it and escalated).
|
|
1379
|
+
if (state.state !== 'CONVENED') {
|
|
1380
|
+
err(`vote refused: cannot tally while the session is ${state.state}`);
|
|
1381
|
+
return EXIT.REFUSED;
|
|
1382
|
+
}
|
|
1383
|
+
if (!ballotOpened(log, values.motion)) {
|
|
1384
|
+
err(`vote refused: no vote has been opened on ${values.motion}`);
|
|
1385
|
+
return EXIT.REFUSED;
|
|
1386
|
+
}
|
|
1387
|
+
if (ballotDecided(log, values.motion)) {
|
|
1388
|
+
err(`vote refused: the vote on ${values.motion} is already decided — its outcome is on the record`);
|
|
1389
|
+
return EXIT.REFUSED;
|
|
1390
|
+
}
|
|
1391
|
+
const outcome = applyVeto(
|
|
1392
|
+
tallyBallot(log, values.motion, charter.session.quorum, null, charter.mechanics.resolution),
|
|
1393
|
+
vetoOutstanding(log, values.motion),
|
|
1394
|
+
);
|
|
1395
|
+
const vetoed = vetoOutstanding(log, values.motion);
|
|
1396
|
+
|
|
1397
|
+
// A tie with quorum is a DEADLOCK, not a rejection (ADR-0004 Proposal 4):
|
|
1398
|
+
// the vote could not decide, so the session suspends for AUTHORITY to
|
|
1399
|
+
// break rather than silently recording a loss. Only genuine ties suspend;
|
|
1400
|
+
// a majority either way falls through to the ordinary outcome below.
|
|
1401
|
+
// Only a majority-type rule can deadlock on a tie. Under unanimity or both-sides
|
|
1402
|
+
// the rule has already decided: the motion fails.
|
|
1403
|
+
const tieIsDeadlock = charter.mechanics.resolution === 'majority' || charter.mechanics.resolution === 'supermajority';
|
|
1404
|
+
// A vetoed motion is rejected outright; there is no tie for the owner to break.
|
|
1405
|
+
if (tieIsDeadlock && !vetoed && !outcome.carried && outcome.yes === outcome.no && outcome.quorum_met) {
|
|
1406
|
+
const deadlock = suspendForDeadlock(outcome, nowStamp(), state, log);
|
|
1407
|
+
await writeLog(dir, deadlock.log);
|
|
1408
|
+
await writeState(dir, deadlock.state);
|
|
1409
|
+
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `DEADLOCK ${values.motion}`);
|
|
1410
|
+
const rec = await commitAct(dir, `DEADLOCK — ${values.motion}`);
|
|
1411
|
+
out(`Motion DEADLOCKED — tied ${outcome.yes} all, no majority`);
|
|
1412
|
+
out(' the session is SUSPENDED — AUTHORITY must break the tie:');
|
|
1413
|
+
out(` politik vote break --motion ${values.motion} --actor <owner> --decide carry|reject`);
|
|
1414
|
+
reportCommit(rec);
|
|
1415
|
+
return EXIT.REFUSED;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
const result = recordOutcome(outcome, nowStamp(), values.actor ?? 'RECORD',
|
|
1419
|
+
(values.role ?? 'OPERATOR') as never, log);
|
|
1420
|
+
const { doc, eliminated, removed, terminationMsg } =
|
|
1421
|
+
await afterOutcome(result.log, outcome.carried, values.motion, state);
|
|
1422
|
+
await writeLog(dir, doc);
|
|
1395
1423
|
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never,
|
|
1396
1424
|
`${outcome.carried ? 'MOTION_CARRIED' : 'MOTION_REJECTED'} ${values.motion}`);
|
|
1397
1425
|
const rec = await commitAct(dir, `${outcome.carried ? 'MOTION_CARRIED' : 'MOTION_REJECTED'} — ${values.motion}`);
|
|
1398
1426
|
|
|
1399
|
-
out(outcome.carried ?
|
|
1400
|
-
out(`
|
|
1427
|
+
out(outcome.carried ? 'Motion CARRIED' : 'Motion NOT CARRIED');
|
|
1428
|
+
out(` yes ${outcome.yes} no ${outcome.no} abstentions ${outcome.abstentions}`);
|
|
1401
1429
|
out(` quorum ${outcome.quorum_met ? 'met' : 'NOT MET'}`);
|
|
1402
1430
|
out(` ${outcome.reason}`);
|
|
1431
|
+
if (removed !== null) out(` removed ${removed.fields?.['Actor affected'] ?? ''} — voted out`);
|
|
1403
1432
|
if (eliminated.length > 0) {
|
|
1404
1433
|
out(` eliminated ${eliminated.length}: ${eliminated.map((e) => e.fields?.['Actor affected']).join(', ')}`);
|
|
1405
1434
|
}
|
|
1406
1435
|
if (terminationMsg !== null) {
|
|
1407
|
-
out(` TERMINATED — ${terminationMsg} — the
|
|
1436
|
+
out(` TERMINATED — ${terminationMsg} — the record is sealed`);
|
|
1408
1437
|
}
|
|
1409
1438
|
reportCommit(rec);
|
|
1410
1439
|
return outcome.carried ? EXIT.OK : EXIT.REFUSED;
|
|
@@ -1412,35 +1441,42 @@ const cmdDivision = async (argv: readonly string[]): Promise<number> => {
|
|
|
1412
1441
|
|
|
1413
1442
|
if (verb === 'break') {
|
|
1414
1443
|
if (values.actor === undefined || values.decide === undefined) {
|
|
1415
|
-
err('
|
|
1444
|
+
err('vote break: --actor and --decide (carry|reject) are required'); return EXIT.USAGE;
|
|
1416
1445
|
}
|
|
1417
1446
|
const decision = values.decide.toLowerCase();
|
|
1418
1447
|
if (decision !== 'carry' && decision !== 'reject') {
|
|
1419
|
-
err('
|
|
1448
|
+
err('vote break: --decide must be carry or reject'); return EXIT.USAGE;
|
|
1420
1449
|
}
|
|
1421
|
-
const result = breakDeadlock(values.motion, decision, nowStamp(), values.actor, state,
|
|
1450
|
+
const result = breakDeadlock(values.motion, decision, nowStamp(), values.actor, state, log,
|
|
1422
1451
|
charter.session.quorum, charter.mechanics.resolution);
|
|
1423
|
-
|
|
1452
|
+
// The resumed state first; afterOutcome overwrites it if the decision ends the session.
|
|
1424
1453
|
await writeState(dir, result.state);
|
|
1454
|
+
const { doc, eliminated, removed, terminationMsg } =
|
|
1455
|
+
await afterOutcome(result.log, result.outcome.carried, values.motion, result.state);
|
|
1456
|
+
await writeLog(dir, doc);
|
|
1425
1457
|
await logAct(dir, values.actor, 'AUTHORITY' as never, `DEADLOCK_BROKEN ${values.motion} ${decision}`);
|
|
1426
1458
|
const rec = await commitAct(dir, `DEADLOCK_BROKEN — ${values.motion} ${decision}`);
|
|
1427
|
-
out(
|
|
1428
|
-
out(` casting vote ${decision === 'carry' ? '
|
|
1429
|
-
out(
|
|
1459
|
+
out(`Motion ${result.outcome.carried ? 'CARRIED' : 'NOT CARRIED'} — AUTHORITY broke the deadlock`);
|
|
1460
|
+
out(` casting vote ${decision === 'carry' ? 'YES' : 'NO'} — ${result.outcome.reason}`);
|
|
1461
|
+
if (removed !== null) out(` removed ${removed.fields?.['Actor affected'] ?? ''} — voted out`);
|
|
1462
|
+
if (eliminated.length > 0) {
|
|
1463
|
+
out(` eliminated ${eliminated.length}: ${eliminated.map((e) => e.fields?.['Actor affected']).join(', ')}`);
|
|
1464
|
+
}
|
|
1465
|
+
out(terminationMsg === null ? ' the session resumes' : ` TERMINATED — ${terminationMsg} — the record is sealed`);
|
|
1430
1466
|
reportCommit(rec);
|
|
1431
1467
|
return result.outcome.carried ? EXIT.OK : EXIT.REFUSED;
|
|
1432
1468
|
}
|
|
1433
1469
|
|
|
1434
|
-
err(`
|
|
1470
|
+
err(`vote: unknown verb "${verb ?? ''}" — expected open | cast | tally | break`);
|
|
1435
1471
|
return EXIT.USAGE;
|
|
1436
1472
|
} catch (error) {
|
|
1437
|
-
err(`
|
|
1473
|
+
err(`vote refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
1438
1474
|
return EXIT.REFUSED;
|
|
1439
1475
|
}
|
|
1440
1476
|
};
|
|
1441
1477
|
|
|
1442
|
-
/** `politik
|
|
1443
|
-
const
|
|
1478
|
+
/** `politik enact` — enact a carried Motion. */
|
|
1479
|
+
const cmdEnact = async (argv: readonly string[]): Promise<number> => {
|
|
1444
1480
|
const { values } = parseArgs({
|
|
1445
1481
|
args: [...argv],
|
|
1446
1482
|
options: {
|
|
@@ -1451,66 +1487,81 @@ const cmdAssent = async (argv: readonly string[]): Promise<number> => {
|
|
|
1451
1487
|
});
|
|
1452
1488
|
|
|
1453
1489
|
const dir = values.dir ?? '.';
|
|
1454
|
-
const { state,
|
|
1455
|
-
if (state === null || charter === null) { err(`
|
|
1490
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1491
|
+
if (state === null || charter === null) { err(`enact: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
1456
1492
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
1457
1493
|
if (values.motion === undefined || values.actor === undefined) {
|
|
1458
|
-
err('
|
|
1494
|
+
err('enact: --motion and --actor are required'); return EXIT.USAGE;
|
|
1459
1495
|
}
|
|
1460
|
-
const gated = await
|
|
1461
|
-
`
|
|
1496
|
+
const gated = await awaitOwner('enact', argv, dir,
|
|
1497
|
+
`Enact motion "${values.motion}" as ${values.actor} — enact it`);
|
|
1462
1498
|
if (gated !== null) return gated;
|
|
1463
1499
|
|
|
1464
1500
|
try {
|
|
1465
|
-
|
|
1466
|
-
|
|
1501
|
+
// Enact what the tally recorded, never a recompute: recomputing used the
|
|
1502
|
+
// default majority rule and let a motion rejected under unanimity be enacted.
|
|
1503
|
+
// Under resolution: owner there is no vote: the owner's enactment is the decision.
|
|
1504
|
+
const ownerDecides = charter.mechanics.resolution === 'owner';
|
|
1505
|
+
const recorded = ownerDecides ? true : recordedOutcome(log, values.motion);
|
|
1506
|
+
if (recorded === null) {
|
|
1507
|
+
err(`enact refused: no vote on ${values.motion} has been tallied — run politik vote tally first`);
|
|
1508
|
+
return EXIT.REFUSED;
|
|
1509
|
+
}
|
|
1510
|
+
if (!recorded) {
|
|
1511
|
+
err(`enact refused: ${values.motion} did not carry — there is nothing to enact`);
|
|
1512
|
+
return EXIT.REFUSED;
|
|
1513
|
+
}
|
|
1514
|
+
const outcome = ownerDecides
|
|
1515
|
+
? ownerDecision(values.motion)
|
|
1516
|
+
: tallyBallot(log, values.motion, charter.session.quorum, null, charter.mechanics.resolution);
|
|
1517
|
+
const result = enactMotion({
|
|
1467
1518
|
motion: values.motion, at: nowStamp(), actor: values.actor,
|
|
1468
1519
|
role: (values.role ?? 'AUTHORITY') as never,
|
|
1469
|
-
|
|
1470
|
-
veto_outstanding: vetoOutstanding(
|
|
1471
|
-
},
|
|
1472
|
-
await
|
|
1520
|
+
enact_role: charter.session.enact, outcome, state,
|
|
1521
|
+
veto_outstanding: vetoOutstanding(log, values.motion),
|
|
1522
|
+
}, log);
|
|
1523
|
+
await writeLog(dir, result.log);
|
|
1473
1524
|
await writeState(dir, result.state);
|
|
1474
1525
|
|
|
1475
|
-
// ADR-0004 defines
|
|
1476
|
-
// reaches the world; until it was wired,
|
|
1526
|
+
// ADR-0004 defines ENACT as merging the Motion. This is where the decision
|
|
1527
|
+
// reaches the world; until it was wired, enact recorded a decision that
|
|
1477
1528
|
// changed nothing.
|
|
1478
1529
|
const { provider } = resolveProvider({ repo: values.repo, token: values.token });
|
|
1479
|
-
const merged = await
|
|
1480
|
-
provider, result.
|
|
1530
|
+
const merged = await projectEnactment(
|
|
1531
|
+
provider, result.log, values.motion, charter.session.merge_strategy,
|
|
1481
1532
|
);
|
|
1482
|
-
const projMsg = await applyProjection(dir, `
|
|
1533
|
+
const projMsg = await applyProjection(dir, `ENACT ${values.motion}`, merged, result.log);
|
|
1483
1534
|
|
|
1484
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'AUTHORITY') as never, `
|
|
1485
|
-
const rec = await commitAct(dir, `
|
|
1486
|
-
out(
|
|
1535
|
+
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'AUTHORITY') as never, `ENACT ${values.motion}`);
|
|
1536
|
+
const rec = await commitAct(dir, `MOTION_ENACTED — ${values.motion} enacted`);
|
|
1537
|
+
out(`ENACTED — ${values.motion}`);
|
|
1487
1538
|
out(projMsg);
|
|
1488
1539
|
reportCommit(rec);
|
|
1489
1540
|
return EXIT.OK;
|
|
1490
1541
|
} catch (error) {
|
|
1491
|
-
err(`
|
|
1542
|
+
err(`enact refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
1492
1543
|
return EXIT.REFUSED;
|
|
1493
1544
|
}
|
|
1494
1545
|
};
|
|
1495
1546
|
|
|
1496
1547
|
|
|
1497
|
-
/** `politik
|
|
1498
|
-
const
|
|
1548
|
+
/** `politik misconduct report|status|rule`. */
|
|
1549
|
+
const cmdMisconduct = async (argv: readonly string[]): Promise<number> => {
|
|
1499
1550
|
const [verb, ...rest] = argv;
|
|
1500
1551
|
const { values } = parseArgs({
|
|
1501
1552
|
args: rest,
|
|
1502
1553
|
options: {
|
|
1503
1554
|
dir: { type: 'string' }, actor: { type: 'string' }, role: { type: 'string' },
|
|
1504
|
-
|
|
1555
|
+
grounds: { type: 'string' },
|
|
1505
1556
|
reviewer: { type: 'string' }, accused: { type: 'string' },
|
|
1506
1557
|
ruling: { type: 'string' }, reasons: { type: 'string' },
|
|
1507
1558
|
},
|
|
1508
1559
|
});
|
|
1509
1560
|
|
|
1510
1561
|
const dir = values.dir ?? '.';
|
|
1511
|
-
const { state,
|
|
1562
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1512
1563
|
if (state === null || charter === null) {
|
|
1513
|
-
err(`
|
|
1564
|
+
err(`misconduct: ${dir} is not a session repo`);
|
|
1514
1565
|
return EXIT.USAGE;
|
|
1515
1566
|
}
|
|
1516
1567
|
|
|
@@ -1519,43 +1570,45 @@ const cmdCrisis = async (argv: readonly string[]): Promise<number> => {
|
|
|
1519
1570
|
.reduce((n, c) => n + c.slots, 0);
|
|
1520
1571
|
|
|
1521
1572
|
try {
|
|
1522
|
-
if (verb === '
|
|
1523
|
-
if (values.actor === undefined || values.
|
|
1524
|
-
err('
|
|
1573
|
+
if (verb === 'report') {
|
|
1574
|
+
if (values.actor === undefined || values.grounds === undefined) {
|
|
1575
|
+
err('misconduct report: --actor and --grounds are required');
|
|
1525
1576
|
return EXIT.USAGE;
|
|
1526
1577
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1578
|
+
const against = await openingOwner(dir);
|
|
1579
|
+
if (against === null) { err('misconduct report: no owner on the record — the session never opened'); return EXIT.USAGE; }
|
|
1580
|
+
if (badRole(values.role)) { err(`misconduct report: "${values.role}" is not a CANON role`); return EXIT.USAGE; }
|
|
1581
|
+
const result = reportMisconduct({
|
|
1529
1582
|
at: nowStamp(), actor: values.actor, role: (values.role ?? 'OPERATOR') as never,
|
|
1530
|
-
grounds: values.grounds, against
|
|
1583
|
+
grounds: values.grounds, against, state,
|
|
1531
1584
|
witness: charter.governance.witness_council.enabled
|
|
1532
|
-
? { ...charter.governance.witness_council, can_file: '
|
|
1585
|
+
? { ...charter.governance.witness_council, can_file: 'MISCONDUCT' as const }
|
|
1533
1586
|
: null,
|
|
1534
|
-
},
|
|
1535
|
-
await
|
|
1536
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `
|
|
1537
|
-
const rec = await commitAct(dir, `
|
|
1538
|
-
out(`
|
|
1587
|
+
}, log);
|
|
1588
|
+
await writeLog(dir, result.log);
|
|
1589
|
+
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `MISCONDUCT_REPORTED against ${against}`);
|
|
1590
|
+
const rec = await commitAct(dir, `MISCONDUCT_REPORTED — ${values.actor}`);
|
|
1591
|
+
out(`MISCONDUCT REPORTED by ${values.actor} against the owner, ${against}`);
|
|
1539
1592
|
reportCommit(rec);
|
|
1540
1593
|
|
|
1541
1594
|
// The Charter's own declaration, not a hardcoded default. Until these
|
|
1542
|
-
// were parsed,
|
|
1595
|
+
// were parsed, an owner could declare a Witness Council and get nothing.
|
|
1543
1596
|
const check = checkCapture(
|
|
1544
|
-
result.
|
|
1597
|
+
result.log,
|
|
1545
1598
|
operators,
|
|
1546
1599
|
charter.governance.witness_council.enabled
|
|
1547
|
-
? { ...charter.governance.witness_council, can_file: '
|
|
1600
|
+
? { ...charter.governance.witness_council, can_file: 'MISCONDUCT' as const }
|
|
1548
1601
|
: null,
|
|
1549
1602
|
{ ...charter.governance.consensus_suspension, resume_requires: 'external_review' as const },
|
|
1550
1603
|
);
|
|
1551
1604
|
if (check.triggered) {
|
|
1552
|
-
const suspended =
|
|
1553
|
-
await
|
|
1605
|
+
const suspended = suspendForMisconduct(check, nowStamp(), state, result.log);
|
|
1606
|
+
await writeLog(dir, suspended.log);
|
|
1554
1607
|
await writeState(dir, suspended.state);
|
|
1555
|
-
const sealed = await commitAct(dir, '
|
|
1608
|
+
const sealed = await commitAct(dir, 'MISCONDUCT — session suspended');
|
|
1556
1609
|
out(` ${check.reason}`);
|
|
1557
1610
|
out('');
|
|
1558
|
-
out('
|
|
1611
|
+
out(' MISCONDUCT — the session is SUSPENDED');
|
|
1559
1612
|
out(' Resumption requires review by a human outside this session.');
|
|
1560
1613
|
reportCommit(sealed);
|
|
1561
1614
|
} else {
|
|
@@ -1564,12 +1617,12 @@ const cmdCrisis = async (argv: readonly string[]): Promise<number> => {
|
|
|
1564
1617
|
return EXIT.OK;
|
|
1565
1618
|
}
|
|
1566
1619
|
|
|
1567
|
-
if (verb === '
|
|
1620
|
+
if (verb === 'status') {
|
|
1568
1621
|
const check = checkCapture(
|
|
1569
|
-
|
|
1622
|
+
log,
|
|
1570
1623
|
operators,
|
|
1571
1624
|
charter.governance.witness_council.enabled
|
|
1572
|
-
? { ...charter.governance.witness_council, can_file: '
|
|
1625
|
+
? { ...charter.governance.witness_council, can_file: 'MISCONDUCT' as const }
|
|
1573
1626
|
: null,
|
|
1574
1627
|
{ ...charter.governance.consensus_suspension, resume_requires: 'external_review' as const },
|
|
1575
1628
|
);
|
|
@@ -1580,30 +1633,32 @@ const cmdCrisis = async (argv: readonly string[]): Promise<number> => {
|
|
|
1580
1633
|
return check.triggered ? EXIT.REFUSED : EXIT.OK;
|
|
1581
1634
|
}
|
|
1582
1635
|
|
|
1583
|
-
if (verb === '
|
|
1584
|
-
if (values.reviewer === undefined || values.
|
|
1585
|
-
err('
|
|
1636
|
+
if (verb === 'rule') {
|
|
1637
|
+
if (values.reviewer === undefined || values.reasons === undefined) {
|
|
1638
|
+
err('misconduct rule: --reviewer and --reasons are required');
|
|
1586
1639
|
return EXIT.USAGE;
|
|
1587
1640
|
}
|
|
1641
|
+
const accused = values.accused ?? await openingOwner(dir);
|
|
1642
|
+
if (accused === null) { err('misconduct rule: no owner on the record — pass --accused'); return EXIT.USAGE; }
|
|
1588
1643
|
const result = externalReview({
|
|
1589
|
-
at: nowStamp(), reviewer: values.reviewer, accused
|
|
1590
|
-
ruling: ((values.ruling ?? 'UPHELD').toUpperCase()) as
|
|
1644
|
+
at: nowStamp(), reviewer: values.reviewer, accused,
|
|
1645
|
+
ruling: ((values.ruling ?? 'UPHELD').toUpperCase()) as MisconductRuling,
|
|
1591
1646
|
reasons: values.reasons, state,
|
|
1592
|
-
},
|
|
1593
|
-
await
|
|
1647
|
+
}, log);
|
|
1648
|
+
await writeLog(dir, result.log);
|
|
1594
1649
|
await writeState(dir, result.state);
|
|
1595
|
-
await logAct(dir, values.reviewer ?? 'RECORD', 'OBSERVER' as never, `
|
|
1596
|
-
const rec = await commitAct(dir, `
|
|
1650
|
+
await logAct(dir, values.reviewer ?? 'RECORD', 'OBSERVER' as never, `MISCONDUCT_RULING ${values.ruling?.toUpperCase() ?? 'UPHELD'}`);
|
|
1651
|
+
const rec = await commitAct(dir, `MISCONDUCT_RULING — ${values.ruling?.toUpperCase() ?? 'UPHELD'}`);
|
|
1597
1652
|
out(`EXTERNAL RULING — ${values.ruling?.toUpperCase() ?? 'UPHELD'}`);
|
|
1598
1653
|
out(` session is now ${result.state.state}`);
|
|
1599
1654
|
reportCommit(rec);
|
|
1600
1655
|
return EXIT.OK;
|
|
1601
1656
|
}
|
|
1602
1657
|
|
|
1603
|
-
err(`
|
|
1658
|
+
err(`misconduct: unknown verb "${verb ?? ''}" — expected report | status | rule`);
|
|
1604
1659
|
return EXIT.USAGE;
|
|
1605
1660
|
} catch (error) {
|
|
1606
|
-
err(`
|
|
1661
|
+
err(`misconduct refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
1607
1662
|
return EXIT.REFUSED;
|
|
1608
1663
|
}
|
|
1609
1664
|
};
|
|
@@ -1618,18 +1673,18 @@ const cmdHeartbeat = async (argv: readonly string[]): Promise<number> => {
|
|
|
1618
1673
|
options: { dir: { type: 'string' }, suspend: { type: 'boolean' } },
|
|
1619
1674
|
});
|
|
1620
1675
|
const dir = values.dir ?? '.';
|
|
1621
|
-
const { state,
|
|
1676
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1622
1677
|
if (state === null || charter === null) { err(`heartbeat: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
1623
1678
|
|
|
1624
|
-
const check = checkHeartbeat(
|
|
1679
|
+
const check = checkHeartbeat(log, charter.session.heartbeat_timeout_hours, nowStamp());
|
|
1625
1680
|
out(check.stale ? 'STALE' : 'beating');
|
|
1626
1681
|
out(` last beat ${check.last_beat ?? 'none'}`);
|
|
1627
1682
|
out(` ${check.reason}`);
|
|
1628
1683
|
|
|
1629
1684
|
if (check.stale && values.suspend === true) {
|
|
1630
1685
|
try {
|
|
1631
|
-
const result = markStale(check, nowStamp(), state,
|
|
1632
|
-
await
|
|
1686
|
+
const result = markStale(check, nowStamp(), state, log);
|
|
1687
|
+
await writeLog(dir, result.log);
|
|
1633
1688
|
await writeState(dir, result.state);
|
|
1634
1689
|
const rec = await commitAct(dir, 'SESSION_STALE — heartbeat window elapsed');
|
|
1635
1690
|
out(` session marked STALE — resumable, nothing lost (stale_action: ${charter.session.stale_action})`);
|
|
@@ -1656,13 +1711,13 @@ const cmdSnapshot = async (argv: readonly string[]): Promise<number> => {
|
|
|
1656
1711
|
},
|
|
1657
1712
|
});
|
|
1658
1713
|
const dir = values.dir ?? '.';
|
|
1659
|
-
const { state,
|
|
1714
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1660
1715
|
if (state === null || charter === null) { err(`snapshot: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
1661
1716
|
// A checkpoint records live business (completed/in-flight/pending) so a STALE
|
|
1662
|
-
//
|
|
1663
|
-
// appending to a
|
|
1664
|
-
if (state.state === '
|
|
1665
|
-
err(`snapshot refused: the session is ${state.state} — its
|
|
1717
|
+
// session can resume from it — meaningless on a sealed or dead session, and
|
|
1718
|
+
// appending to a record closing sealed would break the seal.
|
|
1719
|
+
if (state.state === 'CLOSED' || state.state === 'INVALID') {
|
|
1720
|
+
err(`snapshot refused: the session is ${state.state} — its record is sealed`);
|
|
1666
1721
|
return EXIT.REFUSED;
|
|
1667
1722
|
}
|
|
1668
1723
|
|
|
@@ -1678,9 +1733,9 @@ const cmdSnapshot = async (argv: readonly string[]): Promise<number> => {
|
|
|
1678
1733
|
max_cost_usd: charter.session.endurance.max_cost_usd,
|
|
1679
1734
|
motions: spent.rows,
|
|
1680
1735
|
max_motions: charter.session.endurance.max_motions,
|
|
1681
|
-
}, nowStamp(), state,
|
|
1736
|
+
}, nowStamp(), state, log);
|
|
1682
1737
|
|
|
1683
|
-
await
|
|
1738
|
+
await writeLog(dir, result.log);
|
|
1684
1739
|
const rec = await commitAct(dir, 'STATE_SNAPSHOT');
|
|
1685
1740
|
out('STATE_SNAPSHOT committed');
|
|
1686
1741
|
out(` spent $${spent.cost_usd.toFixed(4)} over ${spent.rows} act(s)`);
|
|
@@ -1697,17 +1752,17 @@ const cmdResume = async (argv: readonly string[]): Promise<number> => {
|
|
|
1697
1752
|
const dir = values.dir ?? '.';
|
|
1698
1753
|
if (values.actor === undefined) { err('resume: --actor is required'); return EXIT.USAGE; }
|
|
1699
1754
|
|
|
1700
|
-
const { state,
|
|
1755
|
+
const { state, log } = await loadSession(dir);
|
|
1701
1756
|
if (state === null) { err(`resume: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
1702
1757
|
|
|
1703
1758
|
try {
|
|
1704
|
-
const result = resume(nowStamp(), values.actor, state,
|
|
1705
|
-
await
|
|
1759
|
+
const result = resume(nowStamp(), values.actor, state, log);
|
|
1760
|
+
await writeLog(dir, result.log);
|
|
1706
1761
|
await writeState(dir, result.state);
|
|
1707
1762
|
const rec = await commitAct(dir, 'SESSION_RESUMED');
|
|
1708
|
-
out('RESUMED — the
|
|
1709
|
-
const snap = lastSnapshot(result.
|
|
1710
|
-
out(snap === null ? ' no snapshot; agents resume from the
|
|
1763
|
+
out('RESUMED — the session continues');
|
|
1764
|
+
const snap = lastSnapshot(result.log);
|
|
1765
|
+
out(snap === null ? ' no snapshot; agents resume from the record' : ' agents resume from the last STATE_SNAPSHOT');
|
|
1711
1766
|
reportCommit(rec);
|
|
1712
1767
|
return EXIT.OK;
|
|
1713
1768
|
} catch (error) {
|
|
@@ -1731,7 +1786,7 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1731
1786
|
});
|
|
1732
1787
|
|
|
1733
1788
|
const dir = values.dir ?? '.';
|
|
1734
|
-
const { state,
|
|
1789
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1735
1790
|
if (state === null || charter === null) {
|
|
1736
1791
|
err(`actor: ${dir} is not a session repo`);
|
|
1737
1792
|
return EXIT.USAGE;
|
|
@@ -1742,9 +1797,9 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1742
1797
|
|
|
1743
1798
|
if (verb === 'list') {
|
|
1744
1799
|
const protocol = await sessionProtocol(charter.protocol);
|
|
1745
|
-
const held = seats(
|
|
1800
|
+
const held = seats(log);
|
|
1746
1801
|
if (held.length === 0) out('no actors seated');
|
|
1747
|
-
for (const seat of held) out(` ${
|
|
1802
|
+
for (const seat of held) out(` ${seat.role.padEnd(16)} ${seat.actor}`);
|
|
1748
1803
|
return EXIT.OK;
|
|
1749
1804
|
}
|
|
1750
1805
|
|
|
@@ -1763,14 +1818,14 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1763
1818
|
// write STATE.json and return here rather than falling through the shared tail.
|
|
1764
1819
|
if (verb === 'dispute') {
|
|
1765
1820
|
if (values.grounds === undefined) { err('actor dispute: --grounds is required'); return EXIT.USAGE; }
|
|
1766
|
-
const disputed = disputeExit(nowStamp(), by.actor, values.grounds, state,
|
|
1767
|
-
await
|
|
1821
|
+
const disputed = disputeExit(nowStamp(), by.actor, values.grounds, state, log);
|
|
1822
|
+
await writeLog(dir, disputed.log);
|
|
1768
1823
|
await writeState(dir, disputed.state);
|
|
1769
1824
|
await logAct(dir, by.actor, by.role, `EXIT_DISPUTED ${by.actor}`);
|
|
1770
1825
|
const rec = await commitAct(dir, `EXIT_DISPUTED — ${by.actor}`);
|
|
1771
1826
|
out(`EXIT DISPUTED by ${by.actor}`);
|
|
1772
|
-
out(' the
|
|
1773
|
-
out(` politik actor reinstate --subject ${by.actor} --actor <
|
|
1827
|
+
out(' the session is SUSPENDED pending an owner ruling:');
|
|
1828
|
+
out(` politik actor reinstate --subject ${by.actor} --actor <owner> --ruling UPHELD|REVERSED`);
|
|
1774
1829
|
reportCommit(rec);
|
|
1775
1830
|
return EXIT.OK;
|
|
1776
1831
|
}
|
|
@@ -1783,33 +1838,33 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1783
1838
|
if (ruling !== 'UPHELD' && ruling !== 'REVERSED') {
|
|
1784
1839
|
err('actor reinstate: --ruling must be UPHELD or REVERSED'); return EXIT.USAGE;
|
|
1785
1840
|
}
|
|
1786
|
-
const resolved = resolveDispute(nowStamp(), by.actor, ruling, values.subject, state,
|
|
1787
|
-
await
|
|
1841
|
+
const resolved = resolveDispute(nowStamp(), by.actor, ruling, values.subject, state, log);
|
|
1842
|
+
await writeLog(dir, resolved.log);
|
|
1788
1843
|
await writeState(dir, resolved.state);
|
|
1789
1844
|
await logAct(dir, by.actor, by.role, `EXIT_RULING ${ruling} ${values.subject}`);
|
|
1790
1845
|
const rec = await commitAct(dir, `EXIT_RULING — ${ruling} on ${values.subject}`);
|
|
1791
1846
|
out(`DISPUTED EXIT ${ruling} — ${resolved.reinstated ? `${values.subject} reinstated` : 'the removal stands'}`);
|
|
1792
|
-
out(' the
|
|
1847
|
+
out(' the session resumes');
|
|
1793
1848
|
reportCommit(rec);
|
|
1794
1849
|
return EXIT.OK;
|
|
1795
1850
|
}
|
|
1796
1851
|
|
|
1797
|
-
let result: {
|
|
1852
|
+
let result: { log: string } | null = null;
|
|
1798
1853
|
let message = '';
|
|
1799
1854
|
|
|
1800
1855
|
if (verb === 'hire') {
|
|
1801
1856
|
if (values.subject === undefined || values.seat === undefined) {
|
|
1802
1857
|
err('actor hire: --subject and --seat are required'); return EXIT.USAGE;
|
|
1803
1858
|
}
|
|
1804
|
-
result = hire({ ...by, subject: values.subject, seat: values.seat as never, reason: values.reason ?? 'seated' },
|
|
1805
|
-
message = `HIRED ${values.subject} as ${
|
|
1859
|
+
result = hire({ ...by, subject: values.subject, seat: values.seat as never, reason: values.reason ?? 'seated' }, log);
|
|
1860
|
+
message = `HIRED ${values.subject} as ${values.seat}`;
|
|
1806
1861
|
} else if (verb === 'promote' || verb === 'demote') {
|
|
1807
1862
|
if (values.subject === undefined || values.to === undefined) {
|
|
1808
1863
|
err(`actor ${verb}: --subject and --to are required`); return EXIT.USAGE;
|
|
1809
1864
|
}
|
|
1810
1865
|
const move = verb === 'promote' ? promote : demote;
|
|
1811
|
-
result = move({ ...by, subject: values.subject, to: values.to as never, reason: values.reason ?? '' },
|
|
1812
|
-
message = `${verb.toUpperCase()}D ${values.subject} to ${
|
|
1866
|
+
result = move({ ...by, subject: values.subject, to: values.to as never, reason: values.reason ?? '' }, log);
|
|
1867
|
+
message = `${verb.toUpperCase()}D ${values.subject} to ${values.to}`;
|
|
1813
1868
|
} else if (verb === 'exit') {
|
|
1814
1869
|
if (values.subject === undefined || values.type === undefined) {
|
|
1815
1870
|
err('actor exit: --subject and --type are required'); return EXIT.USAGE;
|
|
@@ -1817,25 +1872,26 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1817
1872
|
result = exitActor({
|
|
1818
1873
|
...by, subject: values.subject, exit_type: values.type as ExitType,
|
|
1819
1874
|
reason: values.reason ?? '',
|
|
1820
|
-
|
|
1875
|
+
exit_policy: charter.mechanics.exit,
|
|
1876
|
+
}, log);
|
|
1821
1877
|
message = `EXITED ${values.subject} — ${values.type}`;
|
|
1822
1878
|
} else if (verb === 'veto') {
|
|
1823
1879
|
if (values.motion === undefined) { err('actor veto: --motion is required'); return EXIT.USAGE; }
|
|
1824
1880
|
result = veto({
|
|
1825
1881
|
...by, motion: values.motion, reason: values.reason ?? '',
|
|
1826
1882
|
domain_veto: charter.domain_veto,
|
|
1827
|
-
},
|
|
1883
|
+
}, log);
|
|
1828
1884
|
message = `VETO EXERCISED against ${values.motion}`;
|
|
1829
1885
|
} else if (verb === 'spawn') {
|
|
1830
1886
|
if (values.child === undefined) { err('actor spawn: --child is required'); return EXIT.USAGE; }
|
|
1831
|
-
result = spawnChild({ ...by, child: values.child, mandate: values.mandate ?? '' },
|
|
1887
|
+
result = spawnChild({ ...by, child: values.child, mandate: values.mandate ?? '' }, log);
|
|
1832
1888
|
message = `REFERRED to committee ${values.child}`;
|
|
1833
1889
|
} else {
|
|
1834
1890
|
err(`actor: unknown verb "${verb ?? ''}" — expected hire | promote | demote | exit | veto | spawn | dispute | reinstate | list`);
|
|
1835
1891
|
return EXIT.USAGE;
|
|
1836
1892
|
}
|
|
1837
1893
|
|
|
1838
|
-
await
|
|
1894
|
+
await writeLog(dir, result.log);
|
|
1839
1895
|
await logAct(dir, by.actor, by.role as never, message);
|
|
1840
1896
|
const rec = await commitAct(dir, `${message} — by ${by.actor}`);
|
|
1841
1897
|
out(message);
|
|
@@ -1847,7 +1903,7 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1847
1903
|
}
|
|
1848
1904
|
};
|
|
1849
1905
|
|
|
1850
|
-
/** `politik escalate` — raise
|
|
1906
|
+
/** `politik escalate` — raise an escalation. */
|
|
1851
1907
|
const cmdEscalate = async (argv: readonly string[]): Promise<number> => {
|
|
1852
1908
|
const { values } = parseArgs({
|
|
1853
1909
|
args: [...argv],
|
|
@@ -1867,21 +1923,21 @@ const cmdEscalate = async (argv: readonly string[]): Promise<number> => {
|
|
|
1867
1923
|
return EXIT.USAGE;
|
|
1868
1924
|
}
|
|
1869
1925
|
if (badRole(values.role)) { err(`escalate: "${values.role}" is not a CANON role`); return EXIT.USAGE; }
|
|
1870
|
-
// A protocol that declares no escalation refuses
|
|
1926
|
+
// A protocol that declares no escalation refuses an escalation outright
|
|
1871
1927
|
// (ADR-0006) — there is no mechanism to resolve one.
|
|
1872
1928
|
if (charter?.session.escalation === 'disabled') {
|
|
1873
|
-
err('escalate refused: this protocol declares no escalation —
|
|
1929
|
+
err('escalate refused: this protocol declares no escalation — an escalation cannot be raised');
|
|
1874
1930
|
return EXIT.REFUSED;
|
|
1875
1931
|
}
|
|
1876
|
-
//
|
|
1877
|
-
// sealed (
|
|
1878
|
-
// clobbered. Mirrors
|
|
1932
|
+
// An escalation suspends a live session; refuse from any other state so a
|
|
1933
|
+
// sealed (CLOSED) session is never reopened and a pending ruling is never
|
|
1934
|
+
// clobbered. Mirrors vote/enact.
|
|
1879
1935
|
if (state.state !== 'CONVENED') {
|
|
1880
|
-
err(`escalate refused: cannot raise
|
|
1936
|
+
err(`escalate refused: cannot raise an escalation while the session is ${state.state}`);
|
|
1881
1937
|
return EXIT.REFUSED;
|
|
1882
1938
|
}
|
|
1883
1939
|
|
|
1884
|
-
const
|
|
1940
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
1885
1941
|
const filed = fileEscalation({
|
|
1886
1942
|
sequence: values.seq === undefined ? 1 : Number(values.seq),
|
|
1887
1943
|
at: nowStamp(),
|
|
@@ -1892,37 +1948,37 @@ const cmdEscalate = async (argv: readonly string[]): Promise<number> => {
|
|
|
1892
1948
|
state,
|
|
1893
1949
|
// The escalation-disabled case already returned above, so it cannot be
|
|
1894
1950
|
// disabled here; fileEscalation's own guard covers non-CLI callers.
|
|
1895
|
-
},
|
|
1951
|
+
}, log);
|
|
1896
1952
|
|
|
1897
1953
|
await writeFiles(dir, filed.files);
|
|
1898
|
-
await
|
|
1954
|
+
await writeLog(dir, filed.log);
|
|
1899
1955
|
await writeState(dir, filed.state);
|
|
1900
1956
|
|
|
1901
1957
|
const { provider } = resolveProvider({ repo: values.repo, token: values.token });
|
|
1902
1958
|
const opened = await projectEscalation(
|
|
1903
|
-
provider, `
|
|
1959
|
+
provider, `ESCALATION — ${values.title}`, filed.notification,
|
|
1904
1960
|
);
|
|
1905
|
-
const projMsg = await applyProjection(dir, `ESCALATION ${values.title}`, opened, filed.
|
|
1961
|
+
const projMsg = await applyProjection(dir, `ESCALATION ${values.title}`, opened, filed.log);
|
|
1906
1962
|
|
|
1907
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `
|
|
1908
|
-
// The
|
|
1909
|
-
// the substance of the
|
|
1910
|
-
const rec = await commitAct(dir, `
|
|
1911
|
-
out(
|
|
1963
|
+
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `ESCALATION ${values.title}`);
|
|
1964
|
+
// The record cites the escalation file by path as the record; commit it, or
|
|
1965
|
+
// the substance of the escalation lives only in an untracked file.
|
|
1966
|
+
const rec = await commitAct(dir, `ESCALATION — ${values.actor}: ${values.title}`, [filed.escalation_path]);
|
|
1967
|
+
out('Escalation raised');
|
|
1912
1968
|
out(` escalation ${filed.escalation_path}`);
|
|
1913
1969
|
out(` ruling due ${filed.ruling_path}`);
|
|
1914
|
-
out(' session is SUSPENDED pending
|
|
1970
|
+
out(' session is SUSPENDED pending an owner ruling');
|
|
1915
1971
|
out(projMsg);
|
|
1916
1972
|
reportCommit(rec);
|
|
1917
1973
|
|
|
1918
1974
|
// The notification body is built here; delivery is the provider's job.
|
|
1919
1975
|
out('');
|
|
1920
|
-
out(' ---
|
|
1976
|
+
out(' --- Owner notification ---');
|
|
1921
1977
|
for (const line of filed.notification.split('\n')) out(` ${line}`);
|
|
1922
1978
|
return EXIT.OK;
|
|
1923
1979
|
};
|
|
1924
1980
|
|
|
1925
|
-
/** `politik rule` — the
|
|
1981
|
+
/** `politik rule` — the owner rules, and the session resumes. */
|
|
1926
1982
|
const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
1927
1983
|
const { values } = parseArgs({
|
|
1928
1984
|
args: [...argv],
|
|
@@ -1940,11 +1996,11 @@ const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
|
1940
1996
|
return EXIT.USAGE;
|
|
1941
1997
|
}
|
|
1942
1998
|
if (badRole(values.role)) { err(`rule: "${values.role}" is not a CANON role`); return EXIT.USAGE; }
|
|
1943
|
-
const gated = await
|
|
1944
|
-
`Rule ${(values.outcome ?? 'UPHELD').toUpperCase()} on
|
|
1999
|
+
const gated = await awaitOwner('rule', argv, dir,
|
|
2000
|
+
`Rule ${(values.outcome ?? 'UPHELD').toUpperCase()} on escalation #${values.seq ?? '1'} as ${values.actor}: "${values.body}"`);
|
|
1945
2001
|
if (gated !== null) return gated;
|
|
1946
2002
|
|
|
1947
|
-
const
|
|
2003
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
1948
2004
|
|
|
1949
2005
|
try {
|
|
1950
2006
|
const ruling = commitRuling({
|
|
@@ -1956,20 +2012,20 @@ const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
|
1956
2012
|
body: values.body,
|
|
1957
2013
|
escalation_path: state.suspension?.escalation_ref ?? 'escalations/',
|
|
1958
2014
|
state,
|
|
1959
|
-
},
|
|
2015
|
+
}, log);
|
|
1960
2016
|
|
|
1961
2017
|
await writeFiles(dir, ruling.files);
|
|
1962
|
-
await
|
|
2018
|
+
await writeLog(dir, ruling.log);
|
|
1963
2019
|
await writeState(dir, ruling.state);
|
|
1964
2020
|
|
|
1965
2021
|
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'AUTHORITY') as never,
|
|
1966
2022
|
`RULING ${(values.outcome ?? 'UPHELD').toUpperCase()}`);
|
|
1967
|
-
// The
|
|
2023
|
+
// The record cites the ruling file by path; commit it so the ruling's
|
|
1968
2024
|
// reasoning is in the immutable record, not just an untracked file.
|
|
1969
2025
|
const rec = await commitAct(dir, `RULING — ${(values.outcome ?? 'UPHELD').toUpperCase()}`, [ruling.ruling_path]);
|
|
1970
2026
|
out(`RULING COMMITTED — ${(values.outcome ?? 'UPHELD').toUpperCase()}`);
|
|
1971
2027
|
out(` ${ruling.ruling_path}`);
|
|
1972
|
-
out(` session is ${ruling.state.state} — the
|
|
2028
|
+
out(` session is ${ruling.state.state} — the session resumes`);
|
|
1973
2029
|
reportCommit(rec);
|
|
1974
2030
|
return EXIT.OK;
|
|
1975
2031
|
} catch (error) {
|
|
@@ -1985,7 +2041,7 @@ const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
|
1985
2041
|
*
|
|
1986
2042
|
* Nothing here suspends the session or reaches for AUTHORITY: a merge conflict
|
|
1987
2043
|
* is ordinary concurrent work, and treating it as a fault would train actors to
|
|
1988
|
-
* escalate things two
|
|
2044
|
+
* escalate things two operators can settle themselves.
|
|
1989
2045
|
*/
|
|
1990
2046
|
const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
1991
2047
|
const [verb, ...rest] = argv;
|
|
@@ -1998,22 +2054,22 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
1998
2054
|
});
|
|
1999
2055
|
|
|
2000
2056
|
const dir = values.dir ?? '.';
|
|
2001
|
-
const
|
|
2057
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
2002
2058
|
|
|
2003
2059
|
if (verb === 'check') {
|
|
2004
2060
|
// Motions are files under motions/; a conflict is an overlap in what the
|
|
2005
2061
|
// Motions themselves touch, read from the record.
|
|
2006
|
-
const conflicts = detectRecordConflicts(
|
|
2062
|
+
const conflicts = detectRecordConflicts(log);
|
|
2007
2063
|
|
|
2008
2064
|
if (conflicts.length === 0) {
|
|
2009
2065
|
out('no conflicts');
|
|
2010
2066
|
} else {
|
|
2011
2067
|
// Accumulate every conflict entry into one document before writing — a
|
|
2012
|
-
// per-iteration `appendEntry(
|
|
2068
|
+
// per-iteration `appendEntry(log, …)` against the original would keep
|
|
2013
2069
|
// only the last conflict on the record.
|
|
2014
|
-
let doc =
|
|
2070
|
+
let doc = log;
|
|
2015
2071
|
for (const c of conflicts) doc = appendEntry(doc, conflictEntry(c, nowStamp(), 'RECORD', 'OPERATOR'));
|
|
2016
|
-
await
|
|
2072
|
+
await writeLog(dir, doc);
|
|
2017
2073
|
const rec = await commitAct(dir, `CONFLICT — ${conflicts.length} detected`);
|
|
2018
2074
|
for (const c of conflicts) {
|
|
2019
2075
|
out(`CONFLICT ${c.motions.join(' <-> ')}`);
|
|
@@ -2022,7 +2078,7 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
2022
2078
|
reportCommit(rec);
|
|
2023
2079
|
}
|
|
2024
2080
|
|
|
2025
|
-
const open = openConflicts(
|
|
2081
|
+
const open = openConflicts(log);
|
|
2026
2082
|
if (open.length > 0) out(` ${open.length} unresolved`);
|
|
2027
2083
|
// A conflict is not a failure, so this never exits non-zero.
|
|
2028
2084
|
return EXIT.OK;
|
|
@@ -2041,12 +2097,12 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
2041
2097
|
verbs: (values.verbs ?? 'READ,WRITE').split(',').map((v) => v.trim()) as never,
|
|
2042
2098
|
motions: values.motions.split(',').map((m) => m.trim()).filter((m) => m.length > 0),
|
|
2043
2099
|
resolution: values.resolution,
|
|
2044
|
-
},
|
|
2100
|
+
}, log);
|
|
2045
2101
|
|
|
2046
|
-
await
|
|
2102
|
+
await writeLog(dir, result.log);
|
|
2047
2103
|
const rec = await commitAct(dir, `CONFLICT_RESOLVED — ${values.motions}`);
|
|
2048
2104
|
out(`CONFLICT RESOLVED — ${values.motions}`);
|
|
2049
|
-
out(' no
|
|
2105
|
+
out(' no Owner intervention required');
|
|
2050
2106
|
reportCommit(rec);
|
|
2051
2107
|
return EXIT.OK;
|
|
2052
2108
|
} catch (error) {
|
|
@@ -2062,7 +2118,7 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
2062
2118
|
/**
|
|
2063
2119
|
* `politik broadcast` — put business on the bus.
|
|
2064
2120
|
*
|
|
2065
|
-
* The chamber transport carries the ephemeral nudge; the
|
|
2121
|
+
* The chamber transport carries the ephemeral nudge; the record remains the
|
|
2066
2122
|
* record. A broadcast nobody hears loses nothing, because a peer that hears
|
|
2067
2123
|
* nothing falls back to reading the repo.
|
|
2068
2124
|
*/
|
|
@@ -2085,7 +2141,7 @@ const cmdBroadcast = async (argv: readonly string[]): Promise<number> => {
|
|
|
2085
2141
|
err('broadcast: --task is required');
|
|
2086
2142
|
return EXIT.USAGE;
|
|
2087
2143
|
}
|
|
2088
|
-
// Opening the floor dispatches work to agents; only a live
|
|
2144
|
+
// Opening the floor dispatches work to agents; only a live session may do so.
|
|
2089
2145
|
// A sealed or suspended session must not be sending out fresh business.
|
|
2090
2146
|
if (state.state !== 'CONVENED') {
|
|
2091
2147
|
err(`broadcast refused: cannot open the floor while the session is ${state.state}`);
|
|
@@ -2135,7 +2191,7 @@ const cmdBroadcast = async (argv: readonly string[]): Promise<number> => {
|
|
|
2135
2191
|
/**
|
|
2136
2192
|
* `politik motion link` — bind a Motion to its platform object.
|
|
2137
2193
|
*
|
|
2138
|
-
* Without a link,
|
|
2194
|
+
* Without a link, enacting has no pull request to merge and degrades to a
|
|
2139
2195
|
* local-only record. Kept explicit rather than inferred: guessing which PR a
|
|
2140
2196
|
* Motion means would risk merging the wrong branch on the strength of a
|
|
2141
2197
|
* filename match.
|
|
@@ -2166,9 +2222,9 @@ const cmdMotion = async (argv: readonly string[]): Promise<number> => {
|
|
|
2166
2222
|
return EXIT.USAGE;
|
|
2167
2223
|
}
|
|
2168
2224
|
|
|
2169
|
-
const
|
|
2170
|
-
const updated = appendEntry(
|
|
2171
|
-
await
|
|
2225
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
2226
|
+
const updated = appendEntry(log, linkEntry(values.motion, pr, values.url ?? '', nowStamp()));
|
|
2227
|
+
await writeLog(dir, updated);
|
|
2172
2228
|
const rec = await commitAct(dir, `MOTION_PROJECTED — ${values.motion} -> #${pr}`);
|
|
2173
2229
|
out(`LINKED ${values.motion} -> #${pr}`);
|
|
2174
2230
|
reportCommit(rec);
|
|
@@ -2287,50 +2343,50 @@ const cmdRun = async (argv: readonly string[]): Promise<number> => {
|
|
|
2287
2343
|
out(` agent ${outcome.result.agent}`);
|
|
2288
2344
|
out(` elapsed ${outcome.result.elapsed_ms}ms`);
|
|
2289
2345
|
out(` files ${outcome.files_touched.length > 0 ? outcome.files_touched.join(', ') : 'none'}`);
|
|
2290
|
-
out(' recorded in
|
|
2346
|
+
out(' recorded in LOG.md');
|
|
2291
2347
|
if (outcome.suspended === true) {
|
|
2292
|
-
out('
|
|
2348
|
+
out(' ESCALATION — the agent escalated; the session is SUSPENDED pending an owner ruling');
|
|
2293
2349
|
}
|
|
2294
2350
|
reportCommit(rec);
|
|
2295
2351
|
return EXIT.OK;
|
|
2296
2352
|
};
|
|
2297
2353
|
|
|
2298
2354
|
/**
|
|
2299
|
-
* Render a
|
|
2300
|
-
* CANON (the engine parses it); this is only for the human-facing `hansard` view.
|
|
2355
|
+
* Render a log entry type as a readable heading for the `log` view.
|
|
2301
2356
|
* Unknown types humanise gracefully rather than showing a raw token.
|
|
2302
2357
|
*/
|
|
2303
|
-
const translateEntryType = (
|
|
2304
|
-
const t = (canon: string) => asTerm(protocol, canon);
|
|
2358
|
+
const translateEntryType = (type: string): string => {
|
|
2305
2359
|
const map: Record<string, string> = {
|
|
2306
|
-
|
|
2307
|
-
MOTION_TABLED:
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2360
|
+
SESSION_OPENED: 'Session opened',
|
|
2361
|
+
MOTION_TABLED: 'Motion tabled',
|
|
2362
|
+
AGENT_TURN: 'Agent turn',
|
|
2363
|
+
MOTION_CARRIED: 'Motion carried',
|
|
2364
|
+
MOTION_REJECTED: 'Motion rejected',
|
|
2365
|
+
VOTE_CAST: 'Vote cast',
|
|
2366
|
+
BALLOT_OPENED: 'Vote opened',
|
|
2367
|
+
ESCALATION: 'Escalation raised',
|
|
2313
2368
|
RULING: 'Ruling',
|
|
2314
|
-
|
|
2369
|
+
MOTION_ENACTED: 'Motion enacted',
|
|
2315
2370
|
ACTOR_HIRED: 'Seated',
|
|
2316
|
-
ACTOR_EXITED:
|
|
2317
|
-
ACTOR_PROMOTED:
|
|
2318
|
-
ACTOR_DEMOTED:
|
|
2371
|
+
ACTOR_EXITED: 'Exited',
|
|
2372
|
+
ACTOR_PROMOTED: 'Promoted',
|
|
2373
|
+
ACTOR_DEMOTED: 'Demoted',
|
|
2319
2374
|
STATE_SNAPSHOT: 'Checkpoint',
|
|
2320
|
-
|
|
2375
|
+
SESSION_CLOSED: 'Session closed',
|
|
2321
2376
|
};
|
|
2322
|
-
|
|
2377
|
+
const plain = type.toLowerCase().replace(/_/g, ' ');
|
|
2378
|
+
return map[type] ?? plain.charAt(0).toUpperCase() + plain.slice(1);
|
|
2323
2379
|
};
|
|
2324
2380
|
|
|
2325
2381
|
/** `politik integrity` — read the record for bad-faith patterns (integrity.ts). */
|
|
2326
2382
|
const cmdIntegrity = async (argv: readonly string[]): Promise<number> => {
|
|
2327
2383
|
const { values } = parseArgs({ args: [...argv], options: { dir: { type: 'string' } } });
|
|
2328
2384
|
const dir = values.dir ?? '.';
|
|
2329
|
-
const { state,
|
|
2385
|
+
const { state, log } = await loadSession(dir);
|
|
2330
2386
|
if (state === null) { err(`integrity: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2331
2387
|
|
|
2332
2388
|
// ADR-0010 §4: a tampered instruction set is the most serious finding there is
|
|
2333
|
-
// — it targets the
|
|
2389
|
+
// — it targets the owner's own harness — so it leads, and fails the check.
|
|
2334
2390
|
const tampered = await instructionsViolation(dir);
|
|
2335
2391
|
if (tampered !== null) out(` [HIGH] instructions-tampered — ${tampered}`);
|
|
2336
2392
|
|
|
@@ -2338,40 +2394,40 @@ const cmdIntegrity = async (argv: readonly string[]): Promise<number> => {
|
|
|
2338
2394
|
// signature that verifies. Report each one that does not.
|
|
2339
2395
|
const unsigned = (await charterRequiresSignedConfirmations(dir)) ? await unverifiedConfirmations(dir) : [];
|
|
2340
2396
|
for (const sha of unsigned) {
|
|
2341
|
-
out(` [HIGH] confirmation-unsigned — ${sha.slice(0, 8)} records
|
|
2397
|
+
out(` [HIGH] confirmation-unsigned — ${sha.slice(0, 8)} records an owner confirmation without a verifying signature`);
|
|
2342
2398
|
}
|
|
2343
2399
|
const failedSeal = tampered !== null || unsigned.length > 0;
|
|
2344
2400
|
|
|
2345
|
-
const findings = reviewIntegrity(
|
|
2401
|
+
const findings = reviewIntegrity(log);
|
|
2346
2402
|
if (findings.length === 0) {
|
|
2347
2403
|
if (failedSeal) return EXIT.REFUSED;
|
|
2348
2404
|
out('no bad-faith patterns detected — the record is clean');
|
|
2349
2405
|
return EXIT.OK;
|
|
2350
2406
|
}
|
|
2351
|
-
const
|
|
2352
|
-
const
|
|
2353
|
-
for (const f of
|
|
2354
|
-
for (const f of
|
|
2407
|
+
const badFaith = findings.filter((f) => f.kind === 'bad-faith');
|
|
2408
|
+
const goodFaith = findings.filter((f) => f.kind === 'good-faith');
|
|
2409
|
+
for (const f of badFaith) out(` [${f.severity.toUpperCase()}] ${f.signature} — ${f.evidence}`);
|
|
2410
|
+
for (const f of goodFaith) out(` [good faith] ${f.signature} — ${f.evidence}`);
|
|
2355
2411
|
out('');
|
|
2356
|
-
out(`${
|
|
2357
|
-
// A high-severity
|
|
2358
|
-
return failedSeal ||
|
|
2412
|
+
out(`${badFaith.length} bad-faith finding(s), ${goodFaith.length} good-faith finding(s). Surfaced to the owner; no action taken — the owner rules.`);
|
|
2413
|
+
// A high-severity bad-faith finding exits non-zero so a watching owner or CI is alerted.
|
|
2414
|
+
return failedSeal || badFaith.some((f) => f.severity === 'high') ? EXIT.REFUSED : EXIT.OK;
|
|
2359
2415
|
};
|
|
2360
2416
|
|
|
2361
|
-
/** `politik
|
|
2362
|
-
const
|
|
2417
|
+
/** `politik log` — the record, rendered in the protocol's vocabulary. */
|
|
2418
|
+
const cmdLog = async (argv: readonly string[]): Promise<number> => {
|
|
2363
2419
|
const { values } = parseArgs({ args: [...argv], options: { dir: { type: 'string' } } });
|
|
2364
2420
|
const dir = values.dir ?? '.';
|
|
2365
|
-
const { state,
|
|
2366
|
-
if (state === null) { err(`
|
|
2421
|
+
const { state, log, charter } = await loadSession(dir);
|
|
2422
|
+
if (state === null) { err(`log: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2367
2423
|
|
|
2368
2424
|
const protocol = charter === null ? null : await sessionProtocol(charter.protocol);
|
|
2369
|
-
const entries = parseEntries(
|
|
2425
|
+
const entries = parseEntries(log);
|
|
2370
2426
|
out(`RECORD — ${charter?.protocol ?? 'session'} (${entries.length} entr${entries.length === 1 ? 'y' : 'ies'})`);
|
|
2371
2427
|
out('');
|
|
2372
2428
|
for (const entry of entries) {
|
|
2373
|
-
out(`${entry.at} ${translateEntryType(
|
|
2374
|
-
out(` by ${entry.actor} (${
|
|
2429
|
+
out(`${entry.at} ${translateEntryType(entry.type)}`);
|
|
2430
|
+
out(` by ${entry.actor} (${entry.role})`);
|
|
2375
2431
|
const body = (entry.fields['Body'] ?? '').trim();
|
|
2376
2432
|
if (body !== '') out(` ${body}`);
|
|
2377
2433
|
}
|
|
@@ -2395,10 +2451,10 @@ const cmdStatus = async (argv: readonly string[]): Promise<number> => {
|
|
|
2395
2451
|
}
|
|
2396
2452
|
|
|
2397
2453
|
const pending = await listPending(resolve(dir));
|
|
2398
|
-
const
|
|
2399
|
-
const entries =
|
|
2454
|
+
const logRaw = await readIfPresent(join(dir, 'LOG.md'));
|
|
2455
|
+
const entries = logRaw === null ? [] : parseEntries(logRaw);
|
|
2400
2456
|
|
|
2401
|
-
// ADR-0010: a stable machine-readable view, so a harness answering the
|
|
2457
|
+
// ADR-0010: a stable machine-readable view, so a harness answering the owner
|
|
2402
2458
|
// reads fields rather than scraping text.
|
|
2403
2459
|
if (values.json === true) {
|
|
2404
2460
|
const last = entries.at(-1);
|
|
@@ -2428,18 +2484,18 @@ const cmdStatus = async (argv: readonly string[]): Promise<number> => {
|
|
|
2428
2484
|
out(`quorum ${state.quorum.present} of ${state.quorum.required}`);
|
|
2429
2485
|
out(`updated ${state.updated_at} by ${state.updated_by}`);
|
|
2430
2486
|
|
|
2431
|
-
if (
|
|
2487
|
+
if (logRaw !== null) {
|
|
2432
2488
|
out(`record ${entries.length} entr${entries.length === 1 ? 'y' : 'ies'}`);
|
|
2433
2489
|
const last = entries.at(-1);
|
|
2434
2490
|
if (last !== undefined) out(`last ${last.type} by ${last.actor} at ${last.at}`);
|
|
2435
2491
|
}
|
|
2436
2492
|
if (pending.length > 0) {
|
|
2437
|
-
out(`pending ${pending.length} act${pending.length === 1 ? '' : 's'} awaiting the
|
|
2493
|
+
out(`pending ${pending.length} act${pending.length === 1 ? '' : 's'} awaiting the owner — politik pending`);
|
|
2438
2494
|
}
|
|
2439
2495
|
return EXIT.OK;
|
|
2440
2496
|
};
|
|
2441
2497
|
|
|
2442
|
-
const
|
|
2498
|
+
const cmdClose = async (argv: readonly string[]): Promise<number> => {
|
|
2443
2499
|
const { values } = parseArgs({
|
|
2444
2500
|
args: [...argv],
|
|
2445
2501
|
options: {
|
|
@@ -2453,29 +2509,34 @@ const cmdProrogue = async (argv: readonly string[]): Promise<number> => {
|
|
|
2453
2509
|
|
|
2454
2510
|
const dir = values.dir ?? '.';
|
|
2455
2511
|
if (values.actor === undefined || values.role === undefined) {
|
|
2456
|
-
err('
|
|
2512
|
+
err('close: --actor and --role are required');
|
|
2457
2513
|
return EXIT.USAGE;
|
|
2458
2514
|
}
|
|
2459
2515
|
if (badRole(values.role)) {
|
|
2460
|
-
err(`
|
|
2516
|
+
err(`close: "${values.role}" is not a CANON role`);
|
|
2461
2517
|
return EXIT.USAGE;
|
|
2462
2518
|
}
|
|
2463
2519
|
|
|
2464
2520
|
const rawState = await readIfPresent(join(dir, 'STATE.json'));
|
|
2465
2521
|
const state = rawState === null ? null : parseState(rawState);
|
|
2466
2522
|
if (state === null) {
|
|
2467
|
-
err(`
|
|
2523
|
+
err(`close: no readable STATE.json in ${dir}`);
|
|
2524
|
+
return EXIT.USAGE;
|
|
2525
|
+
}
|
|
2526
|
+
// Checked before staging, so an invalid trigger is never staged for confirmation.
|
|
2527
|
+
const trigger = (values.trigger ?? 'TRIGGER_OWNER') as Trigger;
|
|
2528
|
+
if (!(TRIGGERS as readonly string[]).includes(trigger)) {
|
|
2529
|
+
err(`close: --trigger must be one of ${TRIGGERS.join(' | ')}`);
|
|
2468
2530
|
return EXIT.USAGE;
|
|
2469
2531
|
}
|
|
2470
|
-
const gated = await
|
|
2471
|
-
`
|
|
2532
|
+
const gated = await awaitOwner('close', argv, dir,
|
|
2533
|
+
`Close the session as ${values.actor} (trigger: ${trigger}) — seal the record`);
|
|
2472
2534
|
if (gated !== null) return gated;
|
|
2473
2535
|
|
|
2474
|
-
const
|
|
2475
|
-
const trigger = (values.trigger ?? 'TRIGGER_SPEAKER') as Trigger;
|
|
2536
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
2476
2537
|
|
|
2477
2538
|
try {
|
|
2478
|
-
const result =
|
|
2539
|
+
const result = closeSession(
|
|
2479
2540
|
{
|
|
2480
2541
|
at: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z'),
|
|
2481
2542
|
actor: values.actor,
|
|
@@ -2485,32 +2546,32 @@ const cmdProrogue = async (argv: readonly string[]): Promise<number> => {
|
|
|
2485
2546
|
check: checkTermination(
|
|
2486
2547
|
{ max_motions: null, deadline: null, max_cost_usd: null },
|
|
2487
2548
|
{ motions: 0, total_cost_usd: 0, now: new Date().toISOString() },
|
|
2488
|
-
trigger === '
|
|
2549
|
+
trigger === 'TRIGGER_OWNER',
|
|
2489
2550
|
),
|
|
2490
2551
|
summary: values.summary,
|
|
2491
2552
|
},
|
|
2492
|
-
|
|
2553
|
+
log,
|
|
2493
2554
|
);
|
|
2494
2555
|
|
|
2495
|
-
await logAct(dir, values.actor, values.role as never, `
|
|
2556
|
+
await logAct(dir, values.actor, values.role as never, `CLOSED ${trigger}`);
|
|
2496
2557
|
await writeState(dir, result.state);
|
|
2497
|
-
await
|
|
2558
|
+
await writeLog(dir, result.log);
|
|
2498
2559
|
await writeFiles(dir, result.files);
|
|
2499
2560
|
// The seal is the one act that most needs to be in the immutable record —
|
|
2500
|
-
// "the
|
|
2561
|
+
// "the record is sealed" must be true on git, not just in the working tree.
|
|
2501
2562
|
// Commit the record and the rendered summary the seal produces.
|
|
2502
|
-
const rec = await commitAct(dir, `
|
|
2563
|
+
const rec = await commitAct(dir, `CLOSED — ${trigger}`, ['SUMMARY.md']);
|
|
2503
2564
|
|
|
2504
|
-
out('
|
|
2565
|
+
out('CLOSED');
|
|
2505
2566
|
out(` trigger ${trigger}`);
|
|
2506
|
-
out(' the
|
|
2567
|
+
out(' the record is sealed');
|
|
2507
2568
|
if (result.milestone_to_close !== null) {
|
|
2508
2569
|
out(` milestone ${result.milestone_to_close} must be closed on the SCM`);
|
|
2509
2570
|
}
|
|
2510
2571
|
reportCommit(rec);
|
|
2511
2572
|
return EXIT.OK;
|
|
2512
2573
|
} catch (error) {
|
|
2513
|
-
err(`
|
|
2574
|
+
err(`close refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
2514
2575
|
return EXIT.REFUSED;
|
|
2515
2576
|
}
|
|
2516
2577
|
};
|
|
@@ -2531,7 +2592,7 @@ const cmdChallenge = async (argv: readonly string[]): Promise<number> => {
|
|
|
2531
2592
|
},
|
|
2532
2593
|
});
|
|
2533
2594
|
const dir = values.dir ?? '.';
|
|
2534
|
-
const {
|
|
2595
|
+
const { log, charter } = await loadSession(dir);
|
|
2535
2596
|
if (charter === null) { err(`challenge: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2536
2597
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
2537
2598
|
if (values.actor === undefined || values.against === undefined || values.grounds === undefined) {
|
|
@@ -2542,8 +2603,8 @@ const cmdChallenge = async (argv: readonly string[]): Promise<number> => {
|
|
|
2542
2603
|
|
|
2543
2604
|
try {
|
|
2544
2605
|
const result = challengeAction(nowStamp(), values.actor, (values.role ?? 'DELEGATE') as never,
|
|
2545
|
-
values.against, values.grounds, windowMinutes,
|
|
2546
|
-
await
|
|
2606
|
+
values.against, values.grounds, windowMinutes, log);
|
|
2607
|
+
await writeLog(dir, result.log);
|
|
2547
2608
|
await logAct(dir, values.actor, (values.role ?? 'DELEGATE') as never, `DELEGATE_CHALLENGE against ${values.against}`);
|
|
2548
2609
|
const rec = await commitAct(dir, `DELEGATE_CHALLENGE — ${values.actor} vs ${values.against}`);
|
|
2549
2610
|
out(`CHALLENGE recorded — ${values.actor} disputes ${values.against}`);
|
|
@@ -2559,9 +2620,9 @@ const cmdChallenge = async (argv: readonly string[]): Promise<number> => {
|
|
|
2559
2620
|
/**
|
|
2560
2621
|
* `politik standings` — score a competitive protocol from the record.
|
|
2561
2622
|
*
|
|
2562
|
-
* A read over the
|
|
2623
|
+
* A read over the record (like `integrity`): who won the most votes
|
|
2563
2624
|
* (win-loss) or who lasted longest (survival). Neutral on protocol — a
|
|
2564
|
-
*
|
|
2625
|
+
* majority-vote session simply shows how each actor's votes fared.
|
|
2565
2626
|
*/
|
|
2566
2627
|
const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
2567
2628
|
const { values } = parseArgs({
|
|
@@ -2569,11 +2630,11 @@ const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
|
2569
2630
|
options: { dir: { type: 'string' }, by: { type: 'string' } },
|
|
2570
2631
|
});
|
|
2571
2632
|
const dir = values.dir ?? '.';
|
|
2572
|
-
const {
|
|
2633
|
+
const { log, charter } = await loadSession(dir);
|
|
2573
2634
|
if (charter === null) { err(`standings: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2574
2635
|
|
|
2575
2636
|
const by: RankBy = values.by === 'survival' ? 'survival' : 'win-loss';
|
|
2576
|
-
const table = standings(
|
|
2637
|
+
const table = standings(log, by);
|
|
2577
2638
|
if (table.length === 0) { out('no standings — no actor has taken part yet'); return EXIT.OK; }
|
|
2578
2639
|
|
|
2579
2640
|
const protocol = await sessionProtocol(charter.protocol);
|
|
@@ -2586,7 +2647,7 @@ const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
|
2586
2647
|
rankNo += 1;
|
|
2587
2648
|
const seat = row.seat === null
|
|
2588
2649
|
? (row.eliminated ? 'eliminated' : 'out')
|
|
2589
|
-
:
|
|
2650
|
+
: row.seat;
|
|
2590
2651
|
const buch = showBuchholz ? ` · B ${row.buchholz}` : '';
|
|
2591
2652
|
out(` ${String(rankNo).padStart(2)}. ${row.actor.padEnd(14)} ${row.wins}–${row.losses}${buch} · ${seat}`);
|
|
2592
2653
|
}
|
|
@@ -2598,7 +2659,7 @@ const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
|
2598
2659
|
*
|
|
2599
2660
|
* The field is the seated actors; the format decides who faces whom (swiss by
|
|
2600
2661
|
* score, round-robin by unplayed pair, single-elim among the undefeated). A bye
|
|
2601
|
-
* is created already decided. The
|
|
2662
|
+
* is created already decided. The owner then reports each result with
|
|
2602
2663
|
* `politik match report`.
|
|
2603
2664
|
*/
|
|
2604
2665
|
const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
@@ -2610,7 +2671,7 @@ const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
|
2610
2671
|
},
|
|
2611
2672
|
});
|
|
2612
2673
|
const dir = values.dir ?? '.';
|
|
2613
|
-
const {
|
|
2674
|
+
const { log, charter } = await loadSession(dir);
|
|
2614
2675
|
if (charter === null) { err(`pair: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2615
2676
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
2616
2677
|
if (!isPairingFormat(values.format)) {
|
|
@@ -2622,20 +2683,20 @@ const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
|
2622
2683
|
}
|
|
2623
2684
|
const seed = (values.seed ?? '').split(',').map((s) => s.trim()).filter((s) => s.length > 0);
|
|
2624
2685
|
|
|
2625
|
-
const contestants = seats(
|
|
2686
|
+
const contestants = seats(log).map((s) => s.actor);
|
|
2626
2687
|
if (contestants.length < 2) { err('pair: fewer than two contestants are seated'); return EXIT.REFUSED; }
|
|
2627
|
-
const played = matches(
|
|
2688
|
+
const played = matches(log);
|
|
2628
2689
|
const round = values.round !== undefined
|
|
2629
2690
|
? Number(values.round)
|
|
2630
2691
|
: Math.max(0, ...played.map((m) => m.round)) + 1;
|
|
2631
2692
|
|
|
2632
|
-
const pairings = pairRound(contestants, standings(
|
|
2693
|
+
const pairings = pairRound(contestants, standings(log), values.format, round, played, seed);
|
|
2633
2694
|
if (pairings.length === 0) {
|
|
2634
2695
|
out(`no pairings for round ${round} — the ${values.format} field is decided`);
|
|
2635
2696
|
return EXIT.OK;
|
|
2636
2697
|
}
|
|
2637
2698
|
|
|
2638
|
-
let doc =
|
|
2699
|
+
let doc = log;
|
|
2639
2700
|
for (const pairing of pairings) {
|
|
2640
2701
|
const created = matchCreatedEntry(pairing, round, nowStamp(), bestOf);
|
|
2641
2702
|
doc = appendEntry(doc, created);
|
|
@@ -2645,7 +2706,7 @@ const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
|
2645
2706
|
created.fields?.['Match'] ?? '', round, pairing.a, null, nowStamp(), values.actor ?? 'RECORD'));
|
|
2646
2707
|
}
|
|
2647
2708
|
}
|
|
2648
|
-
await
|
|
2709
|
+
await writeLog(dir, doc);
|
|
2649
2710
|
await logAct(dir, values.actor ?? 'RECORD', 'OPERATOR' as never, `PAIRED round ${round} (${values.format})`);
|
|
2650
2711
|
const rec = await commitAct(dir, `MATCH_PAIRING — round ${round} (${values.format})`);
|
|
2651
2712
|
const suffix = bestOf > 1 ? `, best of ${bestOf}` : '';
|
|
@@ -2667,14 +2728,14 @@ const cmdMatch = async (argv: readonly string[]): Promise<number> => {
|
|
|
2667
2728
|
options: { dir: { type: 'string' }, match: { type: 'string' }, winner: { type: 'string' }, actor: { type: 'string' } },
|
|
2668
2729
|
});
|
|
2669
2730
|
const dir = values.dir ?? '.';
|
|
2670
|
-
const {
|
|
2731
|
+
const { log, charter } = await loadSession(dir);
|
|
2671
2732
|
if (charter === null) { err(`match: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2672
2733
|
if (verb !== 'list' && !(await charterIsIntact(dir, charter.protocol))) {
|
|
2673
2734
|
return EXIT.REFUSED;
|
|
2674
2735
|
}
|
|
2675
2736
|
|
|
2676
2737
|
if (verb === 'list') {
|
|
2677
|
-
const all = matches(
|
|
2738
|
+
const all = matches(log);
|
|
2678
2739
|
if (all.length === 0) { out('no matches yet — pair a round first'); return EXIT.OK; }
|
|
2679
2740
|
for (const m of all) {
|
|
2680
2741
|
const status = m.winner === null ? 'open' : `${m.winner} won`;
|
|
@@ -2689,8 +2750,8 @@ const cmdMatch = async (argv: readonly string[]): Promise<number> => {
|
|
|
2689
2750
|
err('match report: --match and --winner are required'); return EXIT.USAGE;
|
|
2690
2751
|
}
|
|
2691
2752
|
try {
|
|
2692
|
-
const result = reportMatch(values.match, values.winner, nowStamp(), values.actor ?? 'RECORD',
|
|
2693
|
-
await
|
|
2753
|
+
const result = reportMatch(values.match, values.winner, nowStamp(), values.actor ?? 'RECORD', log);
|
|
2754
|
+
await writeLog(dir, result.log);
|
|
2694
2755
|
const kind = result.decided ? 'MATCH_DECIDED' : 'MATCH_GAME';
|
|
2695
2756
|
await logAct(dir, values.actor ?? 'RECORD', 'AUTHORITY' as never, `${kind} ${values.match} -> ${values.winner}`);
|
|
2696
2757
|
const rec = await commitAct(dir, `${kind} — ${values.match}: ${values.winner}`);
|
|
@@ -2718,7 +2779,7 @@ const stateMark = (state: string): string => {
|
|
|
2718
2779
|
switch (state) {
|
|
2719
2780
|
case 'CONVENED': return '[OK]';
|
|
2720
2781
|
case 'SUSPENDED': return '[!!]';
|
|
2721
|
-
case '
|
|
2782
|
+
case 'CLOSED': return '[--]';
|
|
2722
2783
|
case 'STALE': return '[~~]';
|
|
2723
2784
|
case 'INVALID': return '[XX]';
|
|
2724
2785
|
default: return '[??]';
|
|
@@ -2762,7 +2823,7 @@ const cmdRegistry = async (argv: readonly string[]): Promise<number> => {
|
|
|
2762
2823
|
out(' -- roll-up (whole tree) --');
|
|
2763
2824
|
out(` nodes ${summary.nodes}`);
|
|
2764
2825
|
out(` by state ${Object.entries(summary.by_state).map(([s, c]) => `${s} ${c}`).join(' ')}`);
|
|
2765
|
-
out(` open motions ${summary.
|
|
2826
|
+
out(` open motions ${summary.open_ballots}`);
|
|
2766
2827
|
out(` total cost $${summary.total_cost_usd.toFixed(4)}`);
|
|
2767
2828
|
out(` total tokens ${summary.total_tokens.toLocaleString()}`);
|
|
2768
2829
|
return EXIT.OK;
|
|
@@ -2772,7 +2833,7 @@ const cmdRegistry = async (argv: readonly string[]): Promise<number> => {
|
|
|
2772
2833
|
* `politik cascade` — a fault repeating across siblings is a signal, not a
|
|
2773
2834
|
* coincidence. Walks the tree, and where enough siblings share a suspension
|
|
2774
2835
|
* cause within the window (tree.ts checkCascade), records a CASCADE_ALERT on
|
|
2775
|
-
* their parent so
|
|
2836
|
+
* their parent so an owner chartering the same configuration is warned. Idempotent:
|
|
2776
2837
|
* a parent already carrying the alert is left alone.
|
|
2777
2838
|
*/
|
|
2778
2839
|
const cmdCascade = async (argv: readonly string[]): Promise<number> => {
|
|
@@ -2787,12 +2848,12 @@ const cmdCascade = async (argv: readonly string[]): Promise<number> => {
|
|
|
2787
2848
|
|
|
2788
2849
|
for (const finding of findings) {
|
|
2789
2850
|
const signature = finding.alert.signature ?? 'unknown';
|
|
2790
|
-
if (cascadeAlerts(finding.parent.
|
|
2851
|
+
if (cascadeAlerts(finding.parent.log).includes(signature)) {
|
|
2791
2852
|
out(`${finding.parent.rel}: cascade on ${signature} already recorded`);
|
|
2792
2853
|
continue;
|
|
2793
2854
|
}
|
|
2794
|
-
const updated = recordOnNode(finding.parent.
|
|
2795
|
-
await
|
|
2855
|
+
const updated = recordOnNode(finding.parent.log, cascadeEntry(finding.alert, nowStamp()));
|
|
2856
|
+
await writeLog(finding.parent.dir, updated);
|
|
2796
2857
|
const rec = await commitAct(finding.parent.dir,
|
|
2797
2858
|
`CASCADE_ALERT — ${signature} across ${finding.alert.nodes.length} siblings`);
|
|
2798
2859
|
out(`CASCADE — ${signature} across ${finding.alert.nodes.length} siblings`);
|
|
@@ -2815,7 +2876,7 @@ export const run = async (argv: readonly string[]): Promise<number> => {
|
|
|
2815
2876
|
}
|
|
2816
2877
|
|
|
2817
2878
|
// ADR-0011: governance on a shared session syncs around the act. `confirm`
|
|
2818
|
-
// syncs around its own replay (after the
|
|
2879
|
+
// syncs around its own replay (after the owner has typed the id), so it is
|
|
2819
2880
|
// not wrapped here.
|
|
2820
2881
|
if (REFRESH_BEFORE.has(command)) await refreshForRead(dirArg(rest));
|
|
2821
2882
|
if (!UNGUARDED_COMMANDS.has(command) && command !== 'confirm') {
|
|
@@ -2861,12 +2922,12 @@ const dispatch = async (command: string | undefined, rest: readonly string[]): P
|
|
|
2861
2922
|
return cmdValidate(rest);
|
|
2862
2923
|
case 'init':
|
|
2863
2924
|
return cmdInit(rest);
|
|
2864
|
-
case '
|
|
2865
|
-
return
|
|
2866
|
-
case '
|
|
2867
|
-
return
|
|
2868
|
-
case '
|
|
2869
|
-
return
|
|
2925
|
+
case 'misconduct':
|
|
2926
|
+
return cmdMisconduct(rest);
|
|
2927
|
+
case 'vote':
|
|
2928
|
+
return cmdVote(rest);
|
|
2929
|
+
case 'enact':
|
|
2930
|
+
return cmdEnact(rest);
|
|
2870
2931
|
case 'heartbeat':
|
|
2871
2932
|
return cmdHeartbeat(rest);
|
|
2872
2933
|
case 'snapshot':
|
|
@@ -2889,14 +2950,14 @@ const dispatch = async (command: string | undefined, rest: readonly string[]): P
|
|
|
2889
2950
|
return cmdLedger(rest);
|
|
2890
2951
|
case 'run':
|
|
2891
2952
|
return cmdRun(rest);
|
|
2892
|
-
case '
|
|
2893
|
-
return
|
|
2953
|
+
case 'log':
|
|
2954
|
+
return cmdLog(rest);
|
|
2894
2955
|
case 'integrity':
|
|
2895
2956
|
return cmdIntegrity(rest);
|
|
2896
2957
|
case 'status':
|
|
2897
2958
|
return cmdStatus(rest);
|
|
2898
|
-
case '
|
|
2899
|
-
return
|
|
2959
|
+
case 'close':
|
|
2960
|
+
return cmdClose(rest);
|
|
2900
2961
|
case 'registry':
|
|
2901
2962
|
return cmdRegistry(rest);
|
|
2902
2963
|
case 'cascade':
|