@cordfuse/politik 0.5.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 +86 -83
- package/POLITIK-ARCHITECTURE.md +111 -176
- package/PROTOCOLS.md +120 -325
- package/README.md +130 -188
- package/RESEARCH.md +142 -438
- 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 +31 -22
- 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 +535 -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 +17 -17
- 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 +71 -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/scrum.yml +0 -87
- 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 -581
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 ?? '');
|
|
@@ -1258,125 +1250,110 @@ const applyProjection = async (
|
|
|
1258
1250
|
dir: string,
|
|
1259
1251
|
act: string,
|
|
1260
1252
|
result: { projected: boolean; detail: string; ref: string | null },
|
|
1261
|
-
|
|
1253
|
+
log: string,
|
|
1262
1254
|
): Promise<string> => {
|
|
1263
|
-
await
|
|
1255
|
+
await writeLog(dir, appendEntry(log, projectionEntry(act, result, nowStamp())));
|
|
1264
1256
|
return ` ${result.projected ? 'projected' : 'not projected'} — ${result.detail}`;
|
|
1265
1257
|
};
|
|
1266
1258
|
|
|
1267
|
-
/** `politik
|
|
1268
|
-
const
|
|
1259
|
+
/** `politik vote open|cast|tally`. */
|
|
1260
|
+
const cmdVote = async (argv: readonly string[]): Promise<number> => {
|
|
1269
1261
|
const [verb, ...rest] = argv;
|
|
1270
1262
|
const { values } = parseArgs({
|
|
1271
1263
|
args: rest,
|
|
1272
1264
|
options: {
|
|
1273
1265
|
dir: { type: 'string' }, motion: { type: 'string' }, actor: { type: 'string' },
|
|
1274
1266
|
role: { type: 'string' }, vote: { type: 'string' }, reviewers: { type: 'string' },
|
|
1275
|
-
decide: { type: 'string' },
|
|
1267
|
+
decide: { type: 'string' }, removes: { type: 'string' },
|
|
1276
1268
|
...PROVIDER_OPTS,
|
|
1277
1269
|
},
|
|
1278
1270
|
});
|
|
1279
1271
|
|
|
1280
1272
|
const dir = values.dir ?? '.';
|
|
1281
|
-
const { state,
|
|
1273
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1282
1274
|
if (state === null || charter === null) {
|
|
1283
|
-
err(`
|
|
1275
|
+
err(`vote: ${dir} is not a session repo`);
|
|
1284
1276
|
return EXIT.USAGE;
|
|
1285
1277
|
}
|
|
1286
1278
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
1287
1279
|
if (values.motion === undefined) {
|
|
1288
|
-
err('
|
|
1280
|
+
err('vote: --motion is required');
|
|
1289
1281
|
return EXIT.USAGE;
|
|
1290
1282
|
}
|
|
1291
1283
|
const protocol = await sessionProtocol(charter.protocol);
|
|
1292
1284
|
|
|
1293
1285
|
try {
|
|
1294
|
-
if (verb === '
|
|
1295
|
-
if (values.actor === undefined) { err('
|
|
1296
|
-
const result =
|
|
1286
|
+
if (verb === 'open') {
|
|
1287
|
+
if (values.actor === undefined) { err('vote open: --actor is required'); return EXIT.USAGE; }
|
|
1288
|
+
const result = openBallot({
|
|
1297
1289
|
motion: values.motion, at: nowStamp(), actor: values.actor,
|
|
1298
1290
|
role: (values.role ?? 'OPERATOR') as never,
|
|
1299
1291
|
reviewers: (values.reviewers ?? '').split(',').filter((r) => r.length > 0),
|
|
1300
1292
|
state,
|
|
1301
|
-
|
|
1302
|
-
|
|
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);
|
|
1303
1298
|
const { provider } = resolveProvider({ repo: values.repo, token: values.token });
|
|
1304
1299
|
const reviewers = (values.reviewers ?? '').split(',').filter((r) => r.length > 0);
|
|
1305
|
-
const projected = await
|
|
1306
|
-
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);
|
|
1307
1302
|
|
|
1308
|
-
const rec = await commitAct(dir, `
|
|
1309
|
-
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}`);
|
|
1310
1305
|
out(projMsg);
|
|
1311
1306
|
reportCommit(rec);
|
|
1312
1307
|
return EXIT.OK;
|
|
1313
1308
|
}
|
|
1314
1309
|
|
|
1315
|
-
if (verb === '
|
|
1310
|
+
if (verb === 'cast') {
|
|
1316
1311
|
if (values.actor === undefined || values.vote === undefined) {
|
|
1317
|
-
err('
|
|
1312
|
+
err('vote cast: --actor and --vote are required'); return EXIT.USAGE;
|
|
1318
1313
|
}
|
|
1319
1314
|
const result = castVote({
|
|
1320
1315
|
motion: values.motion, at: nowStamp(), actor: values.actor,
|
|
1321
1316
|
role: (values.role ?? 'OPERATOR') as never,
|
|
1322
1317
|
vote: values.vote.toUpperCase() as Vote, state,
|
|
1323
|
-
},
|
|
1324
|
-
await
|
|
1318
|
+
}, log);
|
|
1319
|
+
await writeLog(dir, result.log);
|
|
1325
1320
|
const rec = await commitAct(dir, `VOTE_CAST — ${values.actor} on ${values.motion}`);
|
|
1326
|
-
out(
|
|
1321
|
+
out(`Vote recorded — ${values.actor}: ${values.vote.toUpperCase()}`);
|
|
1327
1322
|
reportCommit(rec);
|
|
1328
1323
|
return EXIT.OK;
|
|
1329
1324
|
}
|
|
1330
1325
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
const outcome = tallyDivision(
|
|
1341
|
-
hansard, values.motion, charter.session.quorum, null, charter.mechanics.resolution,
|
|
1342
|
-
);
|
|
1343
|
-
|
|
1344
|
-
// A tie with quorum is a DEADLOCK, not a rejection (ADR-0004 Proposal 4):
|
|
1345
|
-
// the House could not decide, so the sitting suspends for AUTHORITY to
|
|
1346
|
-
// break rather than silently recording a loss. Only genuine ties suspend;
|
|
1347
|
-
// a majority either way falls through to the ordinary outcome below.
|
|
1348
|
-
if (!outcome.carried && outcome.ayes === outcome.noes && outcome.quorum_met) {
|
|
1349
|
-
const deadlock = suspendForDeadlock(outcome, nowStamp(), state, hansard);
|
|
1350
|
-
await writeHansard(dir, deadlock.hansard);
|
|
1351
|
-
await writeState(dir, deadlock.state);
|
|
1352
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `DEADLOCK ${values.motion}`);
|
|
1353
|
-
const rec = await commitAct(dir, `DEADLOCK — ${values.motion}`);
|
|
1354
|
-
out(`${asTerm(protocol, 'MOTION')} DEADLOCKED — tied ${outcome.ayes} all, no majority`);
|
|
1355
|
-
out(' the session is SUSPENDED — AUTHORITY must break the tie:');
|
|
1356
|
-
out(` politik division break --motion ${values.motion} --actor <speaker> --decide carry|reject`);
|
|
1357
|
-
reportCommit(rec);
|
|
1358
|
-
return EXIT.REFUSED;
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
const result = recordOutcome(outcome, nowStamp(), values.actor ?? 'RECORD',
|
|
1362
|
-
(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 }> => {
|
|
1363
1335
|
// exit: elimination culls the losing side (ADR-0007). The outcome is
|
|
1364
1336
|
// recorded first, then the cull it triggers, so the record reads in order.
|
|
1365
|
-
let doc =
|
|
1366
|
-
const eliminated = cull(doc,
|
|
1337
|
+
let doc = decided;
|
|
1338
|
+
const eliminated = cull(doc, motion, charter.mechanics.exit, nowStamp());
|
|
1367
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);
|
|
1368
1345
|
|
|
1369
1346
|
// termination override point (ADR-0007). last-standing seals the moment a
|
|
1370
1347
|
// cull leaves one seated actor — checked only after an actual elimination,
|
|
1371
1348
|
// so a fresh session is never mistaken for a finished one. verdict seals the
|
|
1372
|
-
// moment a
|
|
1349
|
+
// moment a vote carries: a decision has been reached and the session ends.
|
|
1373
1350
|
let terminationMsg: string | null = null;
|
|
1374
1351
|
const seal = async (trigger: Trigger, summary: string, msg: string) => {
|
|
1375
|
-
const end =
|
|
1376
|
-
{ 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 },
|
|
1377
1354
|
doc,
|
|
1378
1355
|
);
|
|
1379
|
-
doc = end.
|
|
1356
|
+
doc = end.log;
|
|
1380
1357
|
await writeState(dir, end.state);
|
|
1381
1358
|
terminationMsg = msg;
|
|
1382
1359
|
};
|
|
@@ -1389,28 +1366,74 @@ const cmdDivision = async (argv: readonly string[]): Promise<number> => {
|
|
|
1389
1366
|
`last standing: ${standing.survivor ?? 'none'}`,
|
|
1390
1367
|
);
|
|
1391
1368
|
}
|
|
1392
|
-
} else if (charter.mechanics.termination === 'verdict' &&
|
|
1393
|
-
await seal(
|
|
1394
|
-
'TRIGGER_VERDICT' as Trigger,
|
|
1395
|
-
`Verdict reached on ${values.motion}`,
|
|
1396
|
-
`verdict reached on ${values.motion}`,
|
|
1397
|
-
);
|
|
1369
|
+
} else if (charter.mechanics.termination === 'verdict' && carried && !removalVote) {
|
|
1370
|
+
await seal('TRIGGER_VERDICT' as Trigger, `Verdict reached on ${motion}`, `verdict reached on ${motion}`);
|
|
1398
1371
|
}
|
|
1372
|
+
return { doc, eliminated, removed, terminationMsg };
|
|
1373
|
+
};
|
|
1399
1374
|
|
|
1400
|
-
|
|
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);
|
|
1401
1423
|
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never,
|
|
1402
1424
|
`${outcome.carried ? 'MOTION_CARRIED' : 'MOTION_REJECTED'} ${values.motion}`);
|
|
1403
1425
|
const rec = await commitAct(dir, `${outcome.carried ? 'MOTION_CARRIED' : 'MOTION_REJECTED'} — ${values.motion}`);
|
|
1404
1426
|
|
|
1405
|
-
out(outcome.carried ?
|
|
1406
|
-
out(`
|
|
1427
|
+
out(outcome.carried ? 'Motion CARRIED' : 'Motion NOT CARRIED');
|
|
1428
|
+
out(` yes ${outcome.yes} no ${outcome.no} abstentions ${outcome.abstentions}`);
|
|
1407
1429
|
out(` quorum ${outcome.quorum_met ? 'met' : 'NOT MET'}`);
|
|
1408
1430
|
out(` ${outcome.reason}`);
|
|
1431
|
+
if (removed !== null) out(` removed ${removed.fields?.['Actor affected'] ?? ''} — voted out`);
|
|
1409
1432
|
if (eliminated.length > 0) {
|
|
1410
1433
|
out(` eliminated ${eliminated.length}: ${eliminated.map((e) => e.fields?.['Actor affected']).join(', ')}`);
|
|
1411
1434
|
}
|
|
1412
1435
|
if (terminationMsg !== null) {
|
|
1413
|
-
out(` TERMINATED — ${terminationMsg} — the
|
|
1436
|
+
out(` TERMINATED — ${terminationMsg} — the record is sealed`);
|
|
1414
1437
|
}
|
|
1415
1438
|
reportCommit(rec);
|
|
1416
1439
|
return outcome.carried ? EXIT.OK : EXIT.REFUSED;
|
|
@@ -1418,35 +1441,42 @@ const cmdDivision = async (argv: readonly string[]): Promise<number> => {
|
|
|
1418
1441
|
|
|
1419
1442
|
if (verb === 'break') {
|
|
1420
1443
|
if (values.actor === undefined || values.decide === undefined) {
|
|
1421
|
-
err('
|
|
1444
|
+
err('vote break: --actor and --decide (carry|reject) are required'); return EXIT.USAGE;
|
|
1422
1445
|
}
|
|
1423
1446
|
const decision = values.decide.toLowerCase();
|
|
1424
1447
|
if (decision !== 'carry' && decision !== 'reject') {
|
|
1425
|
-
err('
|
|
1448
|
+
err('vote break: --decide must be carry or reject'); return EXIT.USAGE;
|
|
1426
1449
|
}
|
|
1427
|
-
const result = breakDeadlock(values.motion, decision, nowStamp(), values.actor, state,
|
|
1450
|
+
const result = breakDeadlock(values.motion, decision, nowStamp(), values.actor, state, log,
|
|
1428
1451
|
charter.session.quorum, charter.mechanics.resolution);
|
|
1429
|
-
|
|
1452
|
+
// The resumed state first; afterOutcome overwrites it if the decision ends the session.
|
|
1430
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);
|
|
1431
1457
|
await logAct(dir, values.actor, 'AUTHORITY' as never, `DEADLOCK_BROKEN ${values.motion} ${decision}`);
|
|
1432
1458
|
const rec = await commitAct(dir, `DEADLOCK_BROKEN — ${values.motion} ${decision}`);
|
|
1433
|
-
out(
|
|
1434
|
-
out(` casting vote ${decision === 'carry' ? '
|
|
1435
|
-
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`);
|
|
1436
1466
|
reportCommit(rec);
|
|
1437
1467
|
return result.outcome.carried ? EXIT.OK : EXIT.REFUSED;
|
|
1438
1468
|
}
|
|
1439
1469
|
|
|
1440
|
-
err(`
|
|
1470
|
+
err(`vote: unknown verb "${verb ?? ''}" — expected open | cast | tally | break`);
|
|
1441
1471
|
return EXIT.USAGE;
|
|
1442
1472
|
} catch (error) {
|
|
1443
|
-
err(`
|
|
1473
|
+
err(`vote refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
1444
1474
|
return EXIT.REFUSED;
|
|
1445
1475
|
}
|
|
1446
1476
|
};
|
|
1447
1477
|
|
|
1448
|
-
/** `politik
|
|
1449
|
-
const
|
|
1478
|
+
/** `politik enact` — enact a carried Motion. */
|
|
1479
|
+
const cmdEnact = async (argv: readonly string[]): Promise<number> => {
|
|
1450
1480
|
const { values } = parseArgs({
|
|
1451
1481
|
args: [...argv],
|
|
1452
1482
|
options: {
|
|
@@ -1457,66 +1487,81 @@ const cmdAssent = async (argv: readonly string[]): Promise<number> => {
|
|
|
1457
1487
|
});
|
|
1458
1488
|
|
|
1459
1489
|
const dir = values.dir ?? '.';
|
|
1460
|
-
const { state,
|
|
1461
|
-
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; }
|
|
1462
1492
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
1463
1493
|
if (values.motion === undefined || values.actor === undefined) {
|
|
1464
|
-
err('
|
|
1494
|
+
err('enact: --motion and --actor are required'); return EXIT.USAGE;
|
|
1465
1495
|
}
|
|
1466
|
-
const gated = await
|
|
1467
|
-
`
|
|
1496
|
+
const gated = await awaitOwner('enact', argv, dir,
|
|
1497
|
+
`Enact motion "${values.motion}" as ${values.actor} — enact it`);
|
|
1468
1498
|
if (gated !== null) return gated;
|
|
1469
1499
|
|
|
1470
1500
|
try {
|
|
1471
|
-
|
|
1472
|
-
|
|
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({
|
|
1473
1518
|
motion: values.motion, at: nowStamp(), actor: values.actor,
|
|
1474
1519
|
role: (values.role ?? 'AUTHORITY') as never,
|
|
1475
|
-
|
|
1476
|
-
veto_outstanding: vetoOutstanding(
|
|
1477
|
-
},
|
|
1478
|
-
await
|
|
1520
|
+
enact_role: charter.session.enact, outcome, state,
|
|
1521
|
+
veto_outstanding: vetoOutstanding(log, values.motion),
|
|
1522
|
+
}, log);
|
|
1523
|
+
await writeLog(dir, result.log);
|
|
1479
1524
|
await writeState(dir, result.state);
|
|
1480
1525
|
|
|
1481
|
-
// ADR-0004 defines
|
|
1482
|
-
// 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
|
|
1483
1528
|
// changed nothing.
|
|
1484
1529
|
const { provider } = resolveProvider({ repo: values.repo, token: values.token });
|
|
1485
|
-
const merged = await
|
|
1486
|
-
provider, result.
|
|
1530
|
+
const merged = await projectEnactment(
|
|
1531
|
+
provider, result.log, values.motion, charter.session.merge_strategy,
|
|
1487
1532
|
);
|
|
1488
|
-
const projMsg = await applyProjection(dir, `
|
|
1533
|
+
const projMsg = await applyProjection(dir, `ENACT ${values.motion}`, merged, result.log);
|
|
1489
1534
|
|
|
1490
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'AUTHORITY') as never, `
|
|
1491
|
-
const rec = await commitAct(dir, `
|
|
1492
|
-
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}`);
|
|
1493
1538
|
out(projMsg);
|
|
1494
1539
|
reportCommit(rec);
|
|
1495
1540
|
return EXIT.OK;
|
|
1496
1541
|
} catch (error) {
|
|
1497
|
-
err(`
|
|
1542
|
+
err(`enact refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
1498
1543
|
return EXIT.REFUSED;
|
|
1499
1544
|
}
|
|
1500
1545
|
};
|
|
1501
1546
|
|
|
1502
1547
|
|
|
1503
|
-
/** `politik
|
|
1504
|
-
const
|
|
1548
|
+
/** `politik misconduct report|status|rule`. */
|
|
1549
|
+
const cmdMisconduct = async (argv: readonly string[]): Promise<number> => {
|
|
1505
1550
|
const [verb, ...rest] = argv;
|
|
1506
1551
|
const { values } = parseArgs({
|
|
1507
1552
|
args: rest,
|
|
1508
1553
|
options: {
|
|
1509
1554
|
dir: { type: 'string' }, actor: { type: 'string' }, role: { type: 'string' },
|
|
1510
|
-
|
|
1555
|
+
grounds: { type: 'string' },
|
|
1511
1556
|
reviewer: { type: 'string' }, accused: { type: 'string' },
|
|
1512
1557
|
ruling: { type: 'string' }, reasons: { type: 'string' },
|
|
1513
1558
|
},
|
|
1514
1559
|
});
|
|
1515
1560
|
|
|
1516
1561
|
const dir = values.dir ?? '.';
|
|
1517
|
-
const { state,
|
|
1562
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1518
1563
|
if (state === null || charter === null) {
|
|
1519
|
-
err(`
|
|
1564
|
+
err(`misconduct: ${dir} is not a session repo`);
|
|
1520
1565
|
return EXIT.USAGE;
|
|
1521
1566
|
}
|
|
1522
1567
|
|
|
@@ -1525,43 +1570,45 @@ const cmdCrisis = async (argv: readonly string[]): Promise<number> => {
|
|
|
1525
1570
|
.reduce((n, c) => n + c.slots, 0);
|
|
1526
1571
|
|
|
1527
1572
|
try {
|
|
1528
|
-
if (verb === '
|
|
1529
|
-
if (values.actor === undefined || values.
|
|
1530
|
-
err('
|
|
1573
|
+
if (verb === 'report') {
|
|
1574
|
+
if (values.actor === undefined || values.grounds === undefined) {
|
|
1575
|
+
err('misconduct report: --actor and --grounds are required');
|
|
1531
1576
|
return EXIT.USAGE;
|
|
1532
1577
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
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({
|
|
1535
1582
|
at: nowStamp(), actor: values.actor, role: (values.role ?? 'OPERATOR') as never,
|
|
1536
|
-
grounds: values.grounds, against
|
|
1583
|
+
grounds: values.grounds, against, state,
|
|
1537
1584
|
witness: charter.governance.witness_council.enabled
|
|
1538
|
-
? { ...charter.governance.witness_council, can_file: '
|
|
1585
|
+
? { ...charter.governance.witness_council, can_file: 'MISCONDUCT' as const }
|
|
1539
1586
|
: null,
|
|
1540
|
-
},
|
|
1541
|
-
await
|
|
1542
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `
|
|
1543
|
-
const rec = await commitAct(dir, `
|
|
1544
|
-
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}`);
|
|
1545
1592
|
reportCommit(rec);
|
|
1546
1593
|
|
|
1547
1594
|
// The Charter's own declaration, not a hardcoded default. Until these
|
|
1548
|
-
// were parsed,
|
|
1595
|
+
// were parsed, an owner could declare a Witness Council and get nothing.
|
|
1549
1596
|
const check = checkCapture(
|
|
1550
|
-
result.
|
|
1597
|
+
result.log,
|
|
1551
1598
|
operators,
|
|
1552
1599
|
charter.governance.witness_council.enabled
|
|
1553
|
-
? { ...charter.governance.witness_council, can_file: '
|
|
1600
|
+
? { ...charter.governance.witness_council, can_file: 'MISCONDUCT' as const }
|
|
1554
1601
|
: null,
|
|
1555
1602
|
{ ...charter.governance.consensus_suspension, resume_requires: 'external_review' as const },
|
|
1556
1603
|
);
|
|
1557
1604
|
if (check.triggered) {
|
|
1558
|
-
const suspended =
|
|
1559
|
-
await
|
|
1605
|
+
const suspended = suspendForMisconduct(check, nowStamp(), state, result.log);
|
|
1606
|
+
await writeLog(dir, suspended.log);
|
|
1560
1607
|
await writeState(dir, suspended.state);
|
|
1561
|
-
const sealed = await commitAct(dir, '
|
|
1608
|
+
const sealed = await commitAct(dir, 'MISCONDUCT — session suspended');
|
|
1562
1609
|
out(` ${check.reason}`);
|
|
1563
1610
|
out('');
|
|
1564
|
-
out('
|
|
1611
|
+
out(' MISCONDUCT — the session is SUSPENDED');
|
|
1565
1612
|
out(' Resumption requires review by a human outside this session.');
|
|
1566
1613
|
reportCommit(sealed);
|
|
1567
1614
|
} else {
|
|
@@ -1570,12 +1617,12 @@ const cmdCrisis = async (argv: readonly string[]): Promise<number> => {
|
|
|
1570
1617
|
return EXIT.OK;
|
|
1571
1618
|
}
|
|
1572
1619
|
|
|
1573
|
-
if (verb === '
|
|
1620
|
+
if (verb === 'status') {
|
|
1574
1621
|
const check = checkCapture(
|
|
1575
|
-
|
|
1622
|
+
log,
|
|
1576
1623
|
operators,
|
|
1577
1624
|
charter.governance.witness_council.enabled
|
|
1578
|
-
? { ...charter.governance.witness_council, can_file: '
|
|
1625
|
+
? { ...charter.governance.witness_council, can_file: 'MISCONDUCT' as const }
|
|
1579
1626
|
: null,
|
|
1580
1627
|
{ ...charter.governance.consensus_suspension, resume_requires: 'external_review' as const },
|
|
1581
1628
|
);
|
|
@@ -1586,30 +1633,32 @@ const cmdCrisis = async (argv: readonly string[]): Promise<number> => {
|
|
|
1586
1633
|
return check.triggered ? EXIT.REFUSED : EXIT.OK;
|
|
1587
1634
|
}
|
|
1588
1635
|
|
|
1589
|
-
if (verb === '
|
|
1590
|
-
if (values.reviewer === undefined || values.
|
|
1591
|
-
err('
|
|
1636
|
+
if (verb === 'rule') {
|
|
1637
|
+
if (values.reviewer === undefined || values.reasons === undefined) {
|
|
1638
|
+
err('misconduct rule: --reviewer and --reasons are required');
|
|
1592
1639
|
return EXIT.USAGE;
|
|
1593
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; }
|
|
1594
1643
|
const result = externalReview({
|
|
1595
|
-
at: nowStamp(), reviewer: values.reviewer, accused
|
|
1596
|
-
ruling: ((values.ruling ?? 'UPHELD').toUpperCase()) as
|
|
1644
|
+
at: nowStamp(), reviewer: values.reviewer, accused,
|
|
1645
|
+
ruling: ((values.ruling ?? 'UPHELD').toUpperCase()) as MisconductRuling,
|
|
1597
1646
|
reasons: values.reasons, state,
|
|
1598
|
-
},
|
|
1599
|
-
await
|
|
1647
|
+
}, log);
|
|
1648
|
+
await writeLog(dir, result.log);
|
|
1600
1649
|
await writeState(dir, result.state);
|
|
1601
|
-
await logAct(dir, values.reviewer ?? 'RECORD', 'OBSERVER' as never, `
|
|
1602
|
-
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'}`);
|
|
1603
1652
|
out(`EXTERNAL RULING — ${values.ruling?.toUpperCase() ?? 'UPHELD'}`);
|
|
1604
1653
|
out(` session is now ${result.state.state}`);
|
|
1605
1654
|
reportCommit(rec);
|
|
1606
1655
|
return EXIT.OK;
|
|
1607
1656
|
}
|
|
1608
1657
|
|
|
1609
|
-
err(`
|
|
1658
|
+
err(`misconduct: unknown verb "${verb ?? ''}" — expected report | status | rule`);
|
|
1610
1659
|
return EXIT.USAGE;
|
|
1611
1660
|
} catch (error) {
|
|
1612
|
-
err(`
|
|
1661
|
+
err(`misconduct refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
1613
1662
|
return EXIT.REFUSED;
|
|
1614
1663
|
}
|
|
1615
1664
|
};
|
|
@@ -1624,18 +1673,18 @@ const cmdHeartbeat = async (argv: readonly string[]): Promise<number> => {
|
|
|
1624
1673
|
options: { dir: { type: 'string' }, suspend: { type: 'boolean' } },
|
|
1625
1674
|
});
|
|
1626
1675
|
const dir = values.dir ?? '.';
|
|
1627
|
-
const { state,
|
|
1676
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1628
1677
|
if (state === null || charter === null) { err(`heartbeat: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
1629
1678
|
|
|
1630
|
-
const check = checkHeartbeat(
|
|
1679
|
+
const check = checkHeartbeat(log, charter.session.heartbeat_timeout_hours, nowStamp());
|
|
1631
1680
|
out(check.stale ? 'STALE' : 'beating');
|
|
1632
1681
|
out(` last beat ${check.last_beat ?? 'none'}`);
|
|
1633
1682
|
out(` ${check.reason}`);
|
|
1634
1683
|
|
|
1635
1684
|
if (check.stale && values.suspend === true) {
|
|
1636
1685
|
try {
|
|
1637
|
-
const result = markStale(check, nowStamp(), state,
|
|
1638
|
-
await
|
|
1686
|
+
const result = markStale(check, nowStamp(), state, log);
|
|
1687
|
+
await writeLog(dir, result.log);
|
|
1639
1688
|
await writeState(dir, result.state);
|
|
1640
1689
|
const rec = await commitAct(dir, 'SESSION_STALE — heartbeat window elapsed');
|
|
1641
1690
|
out(` session marked STALE — resumable, nothing lost (stale_action: ${charter.session.stale_action})`);
|
|
@@ -1662,13 +1711,13 @@ const cmdSnapshot = async (argv: readonly string[]): Promise<number> => {
|
|
|
1662
1711
|
},
|
|
1663
1712
|
});
|
|
1664
1713
|
const dir = values.dir ?? '.';
|
|
1665
|
-
const { state,
|
|
1714
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1666
1715
|
if (state === null || charter === null) { err(`snapshot: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
1667
1716
|
// A checkpoint records live business (completed/in-flight/pending) so a STALE
|
|
1668
|
-
//
|
|
1669
|
-
// appending to a
|
|
1670
|
-
if (state.state === '
|
|
1671
|
-
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`);
|
|
1672
1721
|
return EXIT.REFUSED;
|
|
1673
1722
|
}
|
|
1674
1723
|
|
|
@@ -1684,9 +1733,9 @@ const cmdSnapshot = async (argv: readonly string[]): Promise<number> => {
|
|
|
1684
1733
|
max_cost_usd: charter.session.endurance.max_cost_usd,
|
|
1685
1734
|
motions: spent.rows,
|
|
1686
1735
|
max_motions: charter.session.endurance.max_motions,
|
|
1687
|
-
}, nowStamp(), state,
|
|
1736
|
+
}, nowStamp(), state, log);
|
|
1688
1737
|
|
|
1689
|
-
await
|
|
1738
|
+
await writeLog(dir, result.log);
|
|
1690
1739
|
const rec = await commitAct(dir, 'STATE_SNAPSHOT');
|
|
1691
1740
|
out('STATE_SNAPSHOT committed');
|
|
1692
1741
|
out(` spent $${spent.cost_usd.toFixed(4)} over ${spent.rows} act(s)`);
|
|
@@ -1703,17 +1752,17 @@ const cmdResume = async (argv: readonly string[]): Promise<number> => {
|
|
|
1703
1752
|
const dir = values.dir ?? '.';
|
|
1704
1753
|
if (values.actor === undefined) { err('resume: --actor is required'); return EXIT.USAGE; }
|
|
1705
1754
|
|
|
1706
|
-
const { state,
|
|
1755
|
+
const { state, log } = await loadSession(dir);
|
|
1707
1756
|
if (state === null) { err(`resume: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
1708
1757
|
|
|
1709
1758
|
try {
|
|
1710
|
-
const result = resume(nowStamp(), values.actor, state,
|
|
1711
|
-
await
|
|
1759
|
+
const result = resume(nowStamp(), values.actor, state, log);
|
|
1760
|
+
await writeLog(dir, result.log);
|
|
1712
1761
|
await writeState(dir, result.state);
|
|
1713
1762
|
const rec = await commitAct(dir, 'SESSION_RESUMED');
|
|
1714
|
-
out('RESUMED — the
|
|
1715
|
-
const snap = lastSnapshot(result.
|
|
1716
|
-
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');
|
|
1717
1766
|
reportCommit(rec);
|
|
1718
1767
|
return EXIT.OK;
|
|
1719
1768
|
} catch (error) {
|
|
@@ -1737,7 +1786,7 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1737
1786
|
});
|
|
1738
1787
|
|
|
1739
1788
|
const dir = values.dir ?? '.';
|
|
1740
|
-
const { state,
|
|
1789
|
+
const { state, log, charter } = await loadSession(dir);
|
|
1741
1790
|
if (state === null || charter === null) {
|
|
1742
1791
|
err(`actor: ${dir} is not a session repo`);
|
|
1743
1792
|
return EXIT.USAGE;
|
|
@@ -1748,9 +1797,9 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1748
1797
|
|
|
1749
1798
|
if (verb === 'list') {
|
|
1750
1799
|
const protocol = await sessionProtocol(charter.protocol);
|
|
1751
|
-
const held = seats(
|
|
1800
|
+
const held = seats(log);
|
|
1752
1801
|
if (held.length === 0) out('no actors seated');
|
|
1753
|
-
for (const seat of held) out(` ${
|
|
1802
|
+
for (const seat of held) out(` ${seat.role.padEnd(16)} ${seat.actor}`);
|
|
1754
1803
|
return EXIT.OK;
|
|
1755
1804
|
}
|
|
1756
1805
|
|
|
@@ -1769,14 +1818,14 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1769
1818
|
// write STATE.json and return here rather than falling through the shared tail.
|
|
1770
1819
|
if (verb === 'dispute') {
|
|
1771
1820
|
if (values.grounds === undefined) { err('actor dispute: --grounds is required'); return EXIT.USAGE; }
|
|
1772
|
-
const disputed = disputeExit(nowStamp(), by.actor, values.grounds, state,
|
|
1773
|
-
await
|
|
1821
|
+
const disputed = disputeExit(nowStamp(), by.actor, values.grounds, state, log);
|
|
1822
|
+
await writeLog(dir, disputed.log);
|
|
1774
1823
|
await writeState(dir, disputed.state);
|
|
1775
1824
|
await logAct(dir, by.actor, by.role, `EXIT_DISPUTED ${by.actor}`);
|
|
1776
1825
|
const rec = await commitAct(dir, `EXIT_DISPUTED — ${by.actor}`);
|
|
1777
1826
|
out(`EXIT DISPUTED by ${by.actor}`);
|
|
1778
|
-
out(' the
|
|
1779
|
-
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`);
|
|
1780
1829
|
reportCommit(rec);
|
|
1781
1830
|
return EXIT.OK;
|
|
1782
1831
|
}
|
|
@@ -1789,33 +1838,33 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1789
1838
|
if (ruling !== 'UPHELD' && ruling !== 'REVERSED') {
|
|
1790
1839
|
err('actor reinstate: --ruling must be UPHELD or REVERSED'); return EXIT.USAGE;
|
|
1791
1840
|
}
|
|
1792
|
-
const resolved = resolveDispute(nowStamp(), by.actor, ruling, values.subject, state,
|
|
1793
|
-
await
|
|
1841
|
+
const resolved = resolveDispute(nowStamp(), by.actor, ruling, values.subject, state, log);
|
|
1842
|
+
await writeLog(dir, resolved.log);
|
|
1794
1843
|
await writeState(dir, resolved.state);
|
|
1795
1844
|
await logAct(dir, by.actor, by.role, `EXIT_RULING ${ruling} ${values.subject}`);
|
|
1796
1845
|
const rec = await commitAct(dir, `EXIT_RULING — ${ruling} on ${values.subject}`);
|
|
1797
1846
|
out(`DISPUTED EXIT ${ruling} — ${resolved.reinstated ? `${values.subject} reinstated` : 'the removal stands'}`);
|
|
1798
|
-
out(' the
|
|
1847
|
+
out(' the session resumes');
|
|
1799
1848
|
reportCommit(rec);
|
|
1800
1849
|
return EXIT.OK;
|
|
1801
1850
|
}
|
|
1802
1851
|
|
|
1803
|
-
let result: {
|
|
1852
|
+
let result: { log: string } | null = null;
|
|
1804
1853
|
let message = '';
|
|
1805
1854
|
|
|
1806
1855
|
if (verb === 'hire') {
|
|
1807
1856
|
if (values.subject === undefined || values.seat === undefined) {
|
|
1808
1857
|
err('actor hire: --subject and --seat are required'); return EXIT.USAGE;
|
|
1809
1858
|
}
|
|
1810
|
-
result = hire({ ...by, subject: values.subject, seat: values.seat as never, reason: values.reason ?? 'seated' },
|
|
1811
|
-
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}`;
|
|
1812
1861
|
} else if (verb === 'promote' || verb === 'demote') {
|
|
1813
1862
|
if (values.subject === undefined || values.to === undefined) {
|
|
1814
1863
|
err(`actor ${verb}: --subject and --to are required`); return EXIT.USAGE;
|
|
1815
1864
|
}
|
|
1816
1865
|
const move = verb === 'promote' ? promote : demote;
|
|
1817
|
-
result = move({ ...by, subject: values.subject, to: values.to as never, reason: values.reason ?? '' },
|
|
1818
|
-
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}`;
|
|
1819
1868
|
} else if (verb === 'exit') {
|
|
1820
1869
|
if (values.subject === undefined || values.type === undefined) {
|
|
1821
1870
|
err('actor exit: --subject and --type are required'); return EXIT.USAGE;
|
|
@@ -1823,25 +1872,26 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1823
1872
|
result = exitActor({
|
|
1824
1873
|
...by, subject: values.subject, exit_type: values.type as ExitType,
|
|
1825
1874
|
reason: values.reason ?? '',
|
|
1826
|
-
|
|
1875
|
+
exit_policy: charter.mechanics.exit,
|
|
1876
|
+
}, log);
|
|
1827
1877
|
message = `EXITED ${values.subject} — ${values.type}`;
|
|
1828
1878
|
} else if (verb === 'veto') {
|
|
1829
1879
|
if (values.motion === undefined) { err('actor veto: --motion is required'); return EXIT.USAGE; }
|
|
1830
1880
|
result = veto({
|
|
1831
1881
|
...by, motion: values.motion, reason: values.reason ?? '',
|
|
1832
1882
|
domain_veto: charter.domain_veto,
|
|
1833
|
-
},
|
|
1883
|
+
}, log);
|
|
1834
1884
|
message = `VETO EXERCISED against ${values.motion}`;
|
|
1835
1885
|
} else if (verb === 'spawn') {
|
|
1836
1886
|
if (values.child === undefined) { err('actor spawn: --child is required'); return EXIT.USAGE; }
|
|
1837
|
-
result = spawnChild({ ...by, child: values.child, mandate: values.mandate ?? '' },
|
|
1887
|
+
result = spawnChild({ ...by, child: values.child, mandate: values.mandate ?? '' }, log);
|
|
1838
1888
|
message = `REFERRED to committee ${values.child}`;
|
|
1839
1889
|
} else {
|
|
1840
1890
|
err(`actor: unknown verb "${verb ?? ''}" — expected hire | promote | demote | exit | veto | spawn | dispute | reinstate | list`);
|
|
1841
1891
|
return EXIT.USAGE;
|
|
1842
1892
|
}
|
|
1843
1893
|
|
|
1844
|
-
await
|
|
1894
|
+
await writeLog(dir, result.log);
|
|
1845
1895
|
await logAct(dir, by.actor, by.role as never, message);
|
|
1846
1896
|
const rec = await commitAct(dir, `${message} — by ${by.actor}`);
|
|
1847
1897
|
out(message);
|
|
@@ -1853,7 +1903,7 @@ const cmdActor = async (argv: readonly string[]): Promise<number> => {
|
|
|
1853
1903
|
}
|
|
1854
1904
|
};
|
|
1855
1905
|
|
|
1856
|
-
/** `politik escalate` — raise
|
|
1906
|
+
/** `politik escalate` — raise an escalation. */
|
|
1857
1907
|
const cmdEscalate = async (argv: readonly string[]): Promise<number> => {
|
|
1858
1908
|
const { values } = parseArgs({
|
|
1859
1909
|
args: [...argv],
|
|
@@ -1873,21 +1923,21 @@ const cmdEscalate = async (argv: readonly string[]): Promise<number> => {
|
|
|
1873
1923
|
return EXIT.USAGE;
|
|
1874
1924
|
}
|
|
1875
1925
|
if (badRole(values.role)) { err(`escalate: "${values.role}" is not a CANON role`); return EXIT.USAGE; }
|
|
1876
|
-
// A protocol that declares no escalation refuses
|
|
1926
|
+
// A protocol that declares no escalation refuses an escalation outright
|
|
1877
1927
|
// (ADR-0006) — there is no mechanism to resolve one.
|
|
1878
1928
|
if (charter?.session.escalation === 'disabled') {
|
|
1879
|
-
err('escalate refused: this protocol declares no escalation —
|
|
1929
|
+
err('escalate refused: this protocol declares no escalation — an escalation cannot be raised');
|
|
1880
1930
|
return EXIT.REFUSED;
|
|
1881
1931
|
}
|
|
1882
|
-
//
|
|
1883
|
-
// sealed (
|
|
1884
|
-
// 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.
|
|
1885
1935
|
if (state.state !== 'CONVENED') {
|
|
1886
|
-
err(`escalate refused: cannot raise
|
|
1936
|
+
err(`escalate refused: cannot raise an escalation while the session is ${state.state}`);
|
|
1887
1937
|
return EXIT.REFUSED;
|
|
1888
1938
|
}
|
|
1889
1939
|
|
|
1890
|
-
const
|
|
1940
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
1891
1941
|
const filed = fileEscalation({
|
|
1892
1942
|
sequence: values.seq === undefined ? 1 : Number(values.seq),
|
|
1893
1943
|
at: nowStamp(),
|
|
@@ -1898,37 +1948,37 @@ const cmdEscalate = async (argv: readonly string[]): Promise<number> => {
|
|
|
1898
1948
|
state,
|
|
1899
1949
|
// The escalation-disabled case already returned above, so it cannot be
|
|
1900
1950
|
// disabled here; fileEscalation's own guard covers non-CLI callers.
|
|
1901
|
-
},
|
|
1951
|
+
}, log);
|
|
1902
1952
|
|
|
1903
1953
|
await writeFiles(dir, filed.files);
|
|
1904
|
-
await
|
|
1954
|
+
await writeLog(dir, filed.log);
|
|
1905
1955
|
await writeState(dir, filed.state);
|
|
1906
1956
|
|
|
1907
1957
|
const { provider } = resolveProvider({ repo: values.repo, token: values.token });
|
|
1908
1958
|
const opened = await projectEscalation(
|
|
1909
|
-
provider, `
|
|
1959
|
+
provider, `ESCALATION — ${values.title}`, filed.notification,
|
|
1910
1960
|
);
|
|
1911
|
-
const projMsg = await applyProjection(dir, `ESCALATION ${values.title}`, opened, filed.
|
|
1961
|
+
const projMsg = await applyProjection(dir, `ESCALATION ${values.title}`, opened, filed.log);
|
|
1912
1962
|
|
|
1913
|
-
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'OPERATOR') as never, `
|
|
1914
|
-
// The
|
|
1915
|
-
// the substance of the
|
|
1916
|
-
const rec = await commitAct(dir, `
|
|
1917
|
-
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');
|
|
1918
1968
|
out(` escalation ${filed.escalation_path}`);
|
|
1919
1969
|
out(` ruling due ${filed.ruling_path}`);
|
|
1920
|
-
out(' session is SUSPENDED pending
|
|
1970
|
+
out(' session is SUSPENDED pending an owner ruling');
|
|
1921
1971
|
out(projMsg);
|
|
1922
1972
|
reportCommit(rec);
|
|
1923
1973
|
|
|
1924
1974
|
// The notification body is built here; delivery is the provider's job.
|
|
1925
1975
|
out('');
|
|
1926
|
-
out(' ---
|
|
1976
|
+
out(' --- Owner notification ---');
|
|
1927
1977
|
for (const line of filed.notification.split('\n')) out(` ${line}`);
|
|
1928
1978
|
return EXIT.OK;
|
|
1929
1979
|
};
|
|
1930
1980
|
|
|
1931
|
-
/** `politik rule` — the
|
|
1981
|
+
/** `politik rule` — the owner rules, and the session resumes. */
|
|
1932
1982
|
const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
1933
1983
|
const { values } = parseArgs({
|
|
1934
1984
|
args: [...argv],
|
|
@@ -1946,11 +1996,11 @@ const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
|
1946
1996
|
return EXIT.USAGE;
|
|
1947
1997
|
}
|
|
1948
1998
|
if (badRole(values.role)) { err(`rule: "${values.role}" is not a CANON role`); return EXIT.USAGE; }
|
|
1949
|
-
const gated = await
|
|
1950
|
-
`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}"`);
|
|
1951
2001
|
if (gated !== null) return gated;
|
|
1952
2002
|
|
|
1953
|
-
const
|
|
2003
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
1954
2004
|
|
|
1955
2005
|
try {
|
|
1956
2006
|
const ruling = commitRuling({
|
|
@@ -1962,20 +2012,20 @@ const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
|
1962
2012
|
body: values.body,
|
|
1963
2013
|
escalation_path: state.suspension?.escalation_ref ?? 'escalations/',
|
|
1964
2014
|
state,
|
|
1965
|
-
},
|
|
2015
|
+
}, log);
|
|
1966
2016
|
|
|
1967
2017
|
await writeFiles(dir, ruling.files);
|
|
1968
|
-
await
|
|
2018
|
+
await writeLog(dir, ruling.log);
|
|
1969
2019
|
await writeState(dir, ruling.state);
|
|
1970
2020
|
|
|
1971
2021
|
await logAct(dir, values.actor ?? 'RECORD', (values.role ?? 'AUTHORITY') as never,
|
|
1972
2022
|
`RULING ${(values.outcome ?? 'UPHELD').toUpperCase()}`);
|
|
1973
|
-
// The
|
|
2023
|
+
// The record cites the ruling file by path; commit it so the ruling's
|
|
1974
2024
|
// reasoning is in the immutable record, not just an untracked file.
|
|
1975
2025
|
const rec = await commitAct(dir, `RULING — ${(values.outcome ?? 'UPHELD').toUpperCase()}`, [ruling.ruling_path]);
|
|
1976
2026
|
out(`RULING COMMITTED — ${(values.outcome ?? 'UPHELD').toUpperCase()}`);
|
|
1977
2027
|
out(` ${ruling.ruling_path}`);
|
|
1978
|
-
out(` session is ${ruling.state.state} — the
|
|
2028
|
+
out(` session is ${ruling.state.state} — the session resumes`);
|
|
1979
2029
|
reportCommit(rec);
|
|
1980
2030
|
return EXIT.OK;
|
|
1981
2031
|
} catch (error) {
|
|
@@ -1991,7 +2041,7 @@ const cmdRule = async (argv: readonly string[]): Promise<number> => {
|
|
|
1991
2041
|
*
|
|
1992
2042
|
* Nothing here suspends the session or reaches for AUTHORITY: a merge conflict
|
|
1993
2043
|
* is ordinary concurrent work, and treating it as a fault would train actors to
|
|
1994
|
-
* escalate things two
|
|
2044
|
+
* escalate things two operators can settle themselves.
|
|
1995
2045
|
*/
|
|
1996
2046
|
const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
1997
2047
|
const [verb, ...rest] = argv;
|
|
@@ -2004,22 +2054,22 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
2004
2054
|
});
|
|
2005
2055
|
|
|
2006
2056
|
const dir = values.dir ?? '.';
|
|
2007
|
-
const
|
|
2057
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
2008
2058
|
|
|
2009
2059
|
if (verb === 'check') {
|
|
2010
2060
|
// Motions are files under motions/; a conflict is an overlap in what the
|
|
2011
2061
|
// Motions themselves touch, read from the record.
|
|
2012
|
-
const conflicts = detectRecordConflicts(
|
|
2062
|
+
const conflicts = detectRecordConflicts(log);
|
|
2013
2063
|
|
|
2014
2064
|
if (conflicts.length === 0) {
|
|
2015
2065
|
out('no conflicts');
|
|
2016
2066
|
} else {
|
|
2017
2067
|
// Accumulate every conflict entry into one document before writing — a
|
|
2018
|
-
// per-iteration `appendEntry(
|
|
2068
|
+
// per-iteration `appendEntry(log, …)` against the original would keep
|
|
2019
2069
|
// only the last conflict on the record.
|
|
2020
|
-
let doc =
|
|
2070
|
+
let doc = log;
|
|
2021
2071
|
for (const c of conflicts) doc = appendEntry(doc, conflictEntry(c, nowStamp(), 'RECORD', 'OPERATOR'));
|
|
2022
|
-
await
|
|
2072
|
+
await writeLog(dir, doc);
|
|
2023
2073
|
const rec = await commitAct(dir, `CONFLICT — ${conflicts.length} detected`);
|
|
2024
2074
|
for (const c of conflicts) {
|
|
2025
2075
|
out(`CONFLICT ${c.motions.join(' <-> ')}`);
|
|
@@ -2028,7 +2078,7 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
2028
2078
|
reportCommit(rec);
|
|
2029
2079
|
}
|
|
2030
2080
|
|
|
2031
|
-
const open = openConflicts(
|
|
2081
|
+
const open = openConflicts(log);
|
|
2032
2082
|
if (open.length > 0) out(` ${open.length} unresolved`);
|
|
2033
2083
|
// A conflict is not a failure, so this never exits non-zero.
|
|
2034
2084
|
return EXIT.OK;
|
|
@@ -2047,12 +2097,12 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
2047
2097
|
verbs: (values.verbs ?? 'READ,WRITE').split(',').map((v) => v.trim()) as never,
|
|
2048
2098
|
motions: values.motions.split(',').map((m) => m.trim()).filter((m) => m.length > 0),
|
|
2049
2099
|
resolution: values.resolution,
|
|
2050
|
-
},
|
|
2100
|
+
}, log);
|
|
2051
2101
|
|
|
2052
|
-
await
|
|
2102
|
+
await writeLog(dir, result.log);
|
|
2053
2103
|
const rec = await commitAct(dir, `CONFLICT_RESOLVED — ${values.motions}`);
|
|
2054
2104
|
out(`CONFLICT RESOLVED — ${values.motions}`);
|
|
2055
|
-
out(' no
|
|
2105
|
+
out(' no Owner intervention required');
|
|
2056
2106
|
reportCommit(rec);
|
|
2057
2107
|
return EXIT.OK;
|
|
2058
2108
|
} catch (error) {
|
|
@@ -2068,7 +2118,7 @@ const cmdConflict = async (argv: readonly string[]): Promise<number> => {
|
|
|
2068
2118
|
/**
|
|
2069
2119
|
* `politik broadcast` — put business on the bus.
|
|
2070
2120
|
*
|
|
2071
|
-
* The chamber transport carries the ephemeral nudge; the
|
|
2121
|
+
* The chamber transport carries the ephemeral nudge; the record remains the
|
|
2072
2122
|
* record. A broadcast nobody hears loses nothing, because a peer that hears
|
|
2073
2123
|
* nothing falls back to reading the repo.
|
|
2074
2124
|
*/
|
|
@@ -2091,7 +2141,7 @@ const cmdBroadcast = async (argv: readonly string[]): Promise<number> => {
|
|
|
2091
2141
|
err('broadcast: --task is required');
|
|
2092
2142
|
return EXIT.USAGE;
|
|
2093
2143
|
}
|
|
2094
|
-
// 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.
|
|
2095
2145
|
// A sealed or suspended session must not be sending out fresh business.
|
|
2096
2146
|
if (state.state !== 'CONVENED') {
|
|
2097
2147
|
err(`broadcast refused: cannot open the floor while the session is ${state.state}`);
|
|
@@ -2141,7 +2191,7 @@ const cmdBroadcast = async (argv: readonly string[]): Promise<number> => {
|
|
|
2141
2191
|
/**
|
|
2142
2192
|
* `politik motion link` — bind a Motion to its platform object.
|
|
2143
2193
|
*
|
|
2144
|
-
* Without a link,
|
|
2194
|
+
* Without a link, enacting has no pull request to merge and degrades to a
|
|
2145
2195
|
* local-only record. Kept explicit rather than inferred: guessing which PR a
|
|
2146
2196
|
* Motion means would risk merging the wrong branch on the strength of a
|
|
2147
2197
|
* filename match.
|
|
@@ -2172,9 +2222,9 @@ const cmdMotion = async (argv: readonly string[]): Promise<number> => {
|
|
|
2172
2222
|
return EXIT.USAGE;
|
|
2173
2223
|
}
|
|
2174
2224
|
|
|
2175
|
-
const
|
|
2176
|
-
const updated = appendEntry(
|
|
2177
|
-
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);
|
|
2178
2228
|
const rec = await commitAct(dir, `MOTION_PROJECTED — ${values.motion} -> #${pr}`);
|
|
2179
2229
|
out(`LINKED ${values.motion} -> #${pr}`);
|
|
2180
2230
|
reportCommit(rec);
|
|
@@ -2293,50 +2343,50 @@ const cmdRun = async (argv: readonly string[]): Promise<number> => {
|
|
|
2293
2343
|
out(` agent ${outcome.result.agent}`);
|
|
2294
2344
|
out(` elapsed ${outcome.result.elapsed_ms}ms`);
|
|
2295
2345
|
out(` files ${outcome.files_touched.length > 0 ? outcome.files_touched.join(', ') : 'none'}`);
|
|
2296
|
-
out(' recorded in
|
|
2346
|
+
out(' recorded in LOG.md');
|
|
2297
2347
|
if (outcome.suspended === true) {
|
|
2298
|
-
out('
|
|
2348
|
+
out(' ESCALATION — the agent escalated; the session is SUSPENDED pending an owner ruling');
|
|
2299
2349
|
}
|
|
2300
2350
|
reportCommit(rec);
|
|
2301
2351
|
return EXIT.OK;
|
|
2302
2352
|
};
|
|
2303
2353
|
|
|
2304
2354
|
/**
|
|
2305
|
-
* Render a
|
|
2306
|
-
* 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.
|
|
2307
2356
|
* Unknown types humanise gracefully rather than showing a raw token.
|
|
2308
2357
|
*/
|
|
2309
|
-
const translateEntryType = (
|
|
2310
|
-
const t = (canon: string) => asTerm(protocol, canon);
|
|
2358
|
+
const translateEntryType = (type: string): string => {
|
|
2311
2359
|
const map: Record<string, string> = {
|
|
2312
|
-
|
|
2313
|
-
MOTION_TABLED:
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
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',
|
|
2319
2368
|
RULING: 'Ruling',
|
|
2320
|
-
|
|
2369
|
+
MOTION_ENACTED: 'Motion enacted',
|
|
2321
2370
|
ACTOR_HIRED: 'Seated',
|
|
2322
|
-
ACTOR_EXITED:
|
|
2323
|
-
ACTOR_PROMOTED:
|
|
2324
|
-
ACTOR_DEMOTED:
|
|
2371
|
+
ACTOR_EXITED: 'Exited',
|
|
2372
|
+
ACTOR_PROMOTED: 'Promoted',
|
|
2373
|
+
ACTOR_DEMOTED: 'Demoted',
|
|
2325
2374
|
STATE_SNAPSHOT: 'Checkpoint',
|
|
2326
|
-
|
|
2375
|
+
SESSION_CLOSED: 'Session closed',
|
|
2327
2376
|
};
|
|
2328
|
-
|
|
2377
|
+
const plain = type.toLowerCase().replace(/_/g, ' ');
|
|
2378
|
+
return map[type] ?? plain.charAt(0).toUpperCase() + plain.slice(1);
|
|
2329
2379
|
};
|
|
2330
2380
|
|
|
2331
2381
|
/** `politik integrity` — read the record for bad-faith patterns (integrity.ts). */
|
|
2332
2382
|
const cmdIntegrity = async (argv: readonly string[]): Promise<number> => {
|
|
2333
2383
|
const { values } = parseArgs({ args: [...argv], options: { dir: { type: 'string' } } });
|
|
2334
2384
|
const dir = values.dir ?? '.';
|
|
2335
|
-
const { state,
|
|
2385
|
+
const { state, log } = await loadSession(dir);
|
|
2336
2386
|
if (state === null) { err(`integrity: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2337
2387
|
|
|
2338
2388
|
// ADR-0010 §4: a tampered instruction set is the most serious finding there is
|
|
2339
|
-
// — it targets the
|
|
2389
|
+
// — it targets the owner's own harness — so it leads, and fails the check.
|
|
2340
2390
|
const tampered = await instructionsViolation(dir);
|
|
2341
2391
|
if (tampered !== null) out(` [HIGH] instructions-tampered — ${tampered}`);
|
|
2342
2392
|
|
|
@@ -2344,40 +2394,40 @@ const cmdIntegrity = async (argv: readonly string[]): Promise<number> => {
|
|
|
2344
2394
|
// signature that verifies. Report each one that does not.
|
|
2345
2395
|
const unsigned = (await charterRequiresSignedConfirmations(dir)) ? await unverifiedConfirmations(dir) : [];
|
|
2346
2396
|
for (const sha of unsigned) {
|
|
2347
|
-
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`);
|
|
2348
2398
|
}
|
|
2349
2399
|
const failedSeal = tampered !== null || unsigned.length > 0;
|
|
2350
2400
|
|
|
2351
|
-
const findings = reviewIntegrity(
|
|
2401
|
+
const findings = reviewIntegrity(log);
|
|
2352
2402
|
if (findings.length === 0) {
|
|
2353
2403
|
if (failedSeal) return EXIT.REFUSED;
|
|
2354
2404
|
out('no bad-faith patterns detected — the record is clean');
|
|
2355
2405
|
return EXIT.OK;
|
|
2356
2406
|
}
|
|
2357
|
-
const
|
|
2358
|
-
const
|
|
2359
|
-
for (const f of
|
|
2360
|
-
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}`);
|
|
2361
2411
|
out('');
|
|
2362
|
-
out(`${
|
|
2363
|
-
// A high-severity
|
|
2364
|
-
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;
|
|
2365
2415
|
};
|
|
2366
2416
|
|
|
2367
|
-
/** `politik
|
|
2368
|
-
const
|
|
2417
|
+
/** `politik log` — the record, rendered in the protocol's vocabulary. */
|
|
2418
|
+
const cmdLog = async (argv: readonly string[]): Promise<number> => {
|
|
2369
2419
|
const { values } = parseArgs({ args: [...argv], options: { dir: { type: 'string' } } });
|
|
2370
2420
|
const dir = values.dir ?? '.';
|
|
2371
|
-
const { state,
|
|
2372
|
-
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; }
|
|
2373
2423
|
|
|
2374
2424
|
const protocol = charter === null ? null : await sessionProtocol(charter.protocol);
|
|
2375
|
-
const entries = parseEntries(
|
|
2425
|
+
const entries = parseEntries(log);
|
|
2376
2426
|
out(`RECORD — ${charter?.protocol ?? 'session'} (${entries.length} entr${entries.length === 1 ? 'y' : 'ies'})`);
|
|
2377
2427
|
out('');
|
|
2378
2428
|
for (const entry of entries) {
|
|
2379
|
-
out(`${entry.at} ${translateEntryType(
|
|
2380
|
-
out(` by ${entry.actor} (${
|
|
2429
|
+
out(`${entry.at} ${translateEntryType(entry.type)}`);
|
|
2430
|
+
out(` by ${entry.actor} (${entry.role})`);
|
|
2381
2431
|
const body = (entry.fields['Body'] ?? '').trim();
|
|
2382
2432
|
if (body !== '') out(` ${body}`);
|
|
2383
2433
|
}
|
|
@@ -2401,10 +2451,10 @@ const cmdStatus = async (argv: readonly string[]): Promise<number> => {
|
|
|
2401
2451
|
}
|
|
2402
2452
|
|
|
2403
2453
|
const pending = await listPending(resolve(dir));
|
|
2404
|
-
const
|
|
2405
|
-
const entries =
|
|
2454
|
+
const logRaw = await readIfPresent(join(dir, 'LOG.md'));
|
|
2455
|
+
const entries = logRaw === null ? [] : parseEntries(logRaw);
|
|
2406
2456
|
|
|
2407
|
-
// 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
|
|
2408
2458
|
// reads fields rather than scraping text.
|
|
2409
2459
|
if (values.json === true) {
|
|
2410
2460
|
const last = entries.at(-1);
|
|
@@ -2434,18 +2484,18 @@ const cmdStatus = async (argv: readonly string[]): Promise<number> => {
|
|
|
2434
2484
|
out(`quorum ${state.quorum.present} of ${state.quorum.required}`);
|
|
2435
2485
|
out(`updated ${state.updated_at} by ${state.updated_by}`);
|
|
2436
2486
|
|
|
2437
|
-
if (
|
|
2487
|
+
if (logRaw !== null) {
|
|
2438
2488
|
out(`record ${entries.length} entr${entries.length === 1 ? 'y' : 'ies'}`);
|
|
2439
2489
|
const last = entries.at(-1);
|
|
2440
2490
|
if (last !== undefined) out(`last ${last.type} by ${last.actor} at ${last.at}`);
|
|
2441
2491
|
}
|
|
2442
2492
|
if (pending.length > 0) {
|
|
2443
|
-
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`);
|
|
2444
2494
|
}
|
|
2445
2495
|
return EXIT.OK;
|
|
2446
2496
|
};
|
|
2447
2497
|
|
|
2448
|
-
const
|
|
2498
|
+
const cmdClose = async (argv: readonly string[]): Promise<number> => {
|
|
2449
2499
|
const { values } = parseArgs({
|
|
2450
2500
|
args: [...argv],
|
|
2451
2501
|
options: {
|
|
@@ -2459,29 +2509,34 @@ const cmdProrogue = async (argv: readonly string[]): Promise<number> => {
|
|
|
2459
2509
|
|
|
2460
2510
|
const dir = values.dir ?? '.';
|
|
2461
2511
|
if (values.actor === undefined || values.role === undefined) {
|
|
2462
|
-
err('
|
|
2512
|
+
err('close: --actor and --role are required');
|
|
2463
2513
|
return EXIT.USAGE;
|
|
2464
2514
|
}
|
|
2465
2515
|
if (badRole(values.role)) {
|
|
2466
|
-
err(`
|
|
2516
|
+
err(`close: "${values.role}" is not a CANON role`);
|
|
2467
2517
|
return EXIT.USAGE;
|
|
2468
2518
|
}
|
|
2469
2519
|
|
|
2470
2520
|
const rawState = await readIfPresent(join(dir, 'STATE.json'));
|
|
2471
2521
|
const state = rawState === null ? null : parseState(rawState);
|
|
2472
2522
|
if (state === null) {
|
|
2473
|
-
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(' | ')}`);
|
|
2474
2530
|
return EXIT.USAGE;
|
|
2475
2531
|
}
|
|
2476
|
-
const gated = await
|
|
2477
|
-
`
|
|
2532
|
+
const gated = await awaitOwner('close', argv, dir,
|
|
2533
|
+
`Close the session as ${values.actor} (trigger: ${trigger}) — seal the record`);
|
|
2478
2534
|
if (gated !== null) return gated;
|
|
2479
2535
|
|
|
2480
|
-
const
|
|
2481
|
-
const trigger = (values.trigger ?? 'TRIGGER_SPEAKER') as Trigger;
|
|
2536
|
+
const log = (await readIfPresent(join(dir, 'LOG.md'))) ?? '';
|
|
2482
2537
|
|
|
2483
2538
|
try {
|
|
2484
|
-
const result =
|
|
2539
|
+
const result = closeSession(
|
|
2485
2540
|
{
|
|
2486
2541
|
at: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z'),
|
|
2487
2542
|
actor: values.actor,
|
|
@@ -2491,32 +2546,32 @@ const cmdProrogue = async (argv: readonly string[]): Promise<number> => {
|
|
|
2491
2546
|
check: checkTermination(
|
|
2492
2547
|
{ max_motions: null, deadline: null, max_cost_usd: null },
|
|
2493
2548
|
{ motions: 0, total_cost_usd: 0, now: new Date().toISOString() },
|
|
2494
|
-
trigger === '
|
|
2549
|
+
trigger === 'TRIGGER_OWNER',
|
|
2495
2550
|
),
|
|
2496
2551
|
summary: values.summary,
|
|
2497
2552
|
},
|
|
2498
|
-
|
|
2553
|
+
log,
|
|
2499
2554
|
);
|
|
2500
2555
|
|
|
2501
|
-
await logAct(dir, values.actor, values.role as never, `
|
|
2556
|
+
await logAct(dir, values.actor, values.role as never, `CLOSED ${trigger}`);
|
|
2502
2557
|
await writeState(dir, result.state);
|
|
2503
|
-
await
|
|
2558
|
+
await writeLog(dir, result.log);
|
|
2504
2559
|
await writeFiles(dir, result.files);
|
|
2505
2560
|
// The seal is the one act that most needs to be in the immutable record —
|
|
2506
|
-
// "the
|
|
2561
|
+
// "the record is sealed" must be true on git, not just in the working tree.
|
|
2507
2562
|
// Commit the record and the rendered summary the seal produces.
|
|
2508
|
-
const rec = await commitAct(dir, `
|
|
2563
|
+
const rec = await commitAct(dir, `CLOSED — ${trigger}`, ['SUMMARY.md']);
|
|
2509
2564
|
|
|
2510
|
-
out('
|
|
2565
|
+
out('CLOSED');
|
|
2511
2566
|
out(` trigger ${trigger}`);
|
|
2512
|
-
out(' the
|
|
2567
|
+
out(' the record is sealed');
|
|
2513
2568
|
if (result.milestone_to_close !== null) {
|
|
2514
2569
|
out(` milestone ${result.milestone_to_close} must be closed on the SCM`);
|
|
2515
2570
|
}
|
|
2516
2571
|
reportCommit(rec);
|
|
2517
2572
|
return EXIT.OK;
|
|
2518
2573
|
} catch (error) {
|
|
2519
|
-
err(`
|
|
2574
|
+
err(`close refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
2520
2575
|
return EXIT.REFUSED;
|
|
2521
2576
|
}
|
|
2522
2577
|
};
|
|
@@ -2537,7 +2592,7 @@ const cmdChallenge = async (argv: readonly string[]): Promise<number> => {
|
|
|
2537
2592
|
},
|
|
2538
2593
|
});
|
|
2539
2594
|
const dir = values.dir ?? '.';
|
|
2540
|
-
const {
|
|
2595
|
+
const { log, charter } = await loadSession(dir);
|
|
2541
2596
|
if (charter === null) { err(`challenge: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2542
2597
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
2543
2598
|
if (values.actor === undefined || values.against === undefined || values.grounds === undefined) {
|
|
@@ -2548,8 +2603,8 @@ const cmdChallenge = async (argv: readonly string[]): Promise<number> => {
|
|
|
2548
2603
|
|
|
2549
2604
|
try {
|
|
2550
2605
|
const result = challengeAction(nowStamp(), values.actor, (values.role ?? 'DELEGATE') as never,
|
|
2551
|
-
values.against, values.grounds, windowMinutes,
|
|
2552
|
-
await
|
|
2606
|
+
values.against, values.grounds, windowMinutes, log);
|
|
2607
|
+
await writeLog(dir, result.log);
|
|
2553
2608
|
await logAct(dir, values.actor, (values.role ?? 'DELEGATE') as never, `DELEGATE_CHALLENGE against ${values.against}`);
|
|
2554
2609
|
const rec = await commitAct(dir, `DELEGATE_CHALLENGE — ${values.actor} vs ${values.against}`);
|
|
2555
2610
|
out(`CHALLENGE recorded — ${values.actor} disputes ${values.against}`);
|
|
@@ -2565,9 +2620,9 @@ const cmdChallenge = async (argv: readonly string[]): Promise<number> => {
|
|
|
2565
2620
|
/**
|
|
2566
2621
|
* `politik standings` — score a competitive protocol from the record.
|
|
2567
2622
|
*
|
|
2568
|
-
* A read over the
|
|
2623
|
+
* A read over the record (like `integrity`): who won the most votes
|
|
2569
2624
|
* (win-loss) or who lasted longest (survival). Neutral on protocol — a
|
|
2570
|
-
*
|
|
2625
|
+
* majority-vote session simply shows how each actor's votes fared.
|
|
2571
2626
|
*/
|
|
2572
2627
|
const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
2573
2628
|
const { values } = parseArgs({
|
|
@@ -2575,11 +2630,11 @@ const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
|
2575
2630
|
options: { dir: { type: 'string' }, by: { type: 'string' } },
|
|
2576
2631
|
});
|
|
2577
2632
|
const dir = values.dir ?? '.';
|
|
2578
|
-
const {
|
|
2633
|
+
const { log, charter } = await loadSession(dir);
|
|
2579
2634
|
if (charter === null) { err(`standings: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2580
2635
|
|
|
2581
2636
|
const by: RankBy = values.by === 'survival' ? 'survival' : 'win-loss';
|
|
2582
|
-
const table = standings(
|
|
2637
|
+
const table = standings(log, by);
|
|
2583
2638
|
if (table.length === 0) { out('no standings — no actor has taken part yet'); return EXIT.OK; }
|
|
2584
2639
|
|
|
2585
2640
|
const protocol = await sessionProtocol(charter.protocol);
|
|
@@ -2592,7 +2647,7 @@ const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
|
2592
2647
|
rankNo += 1;
|
|
2593
2648
|
const seat = row.seat === null
|
|
2594
2649
|
? (row.eliminated ? 'eliminated' : 'out')
|
|
2595
|
-
:
|
|
2650
|
+
: row.seat;
|
|
2596
2651
|
const buch = showBuchholz ? ` · B ${row.buchholz}` : '';
|
|
2597
2652
|
out(` ${String(rankNo).padStart(2)}. ${row.actor.padEnd(14)} ${row.wins}–${row.losses}${buch} · ${seat}`);
|
|
2598
2653
|
}
|
|
@@ -2604,7 +2659,7 @@ const cmdStandings = async (argv: readonly string[]): Promise<number> => {
|
|
|
2604
2659
|
*
|
|
2605
2660
|
* The field is the seated actors; the format decides who faces whom (swiss by
|
|
2606
2661
|
* score, round-robin by unplayed pair, single-elim among the undefeated). A bye
|
|
2607
|
-
* is created already decided. The
|
|
2662
|
+
* is created already decided. The owner then reports each result with
|
|
2608
2663
|
* `politik match report`.
|
|
2609
2664
|
*/
|
|
2610
2665
|
const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
@@ -2616,7 +2671,7 @@ const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
|
2616
2671
|
},
|
|
2617
2672
|
});
|
|
2618
2673
|
const dir = values.dir ?? '.';
|
|
2619
|
-
const {
|
|
2674
|
+
const { log, charter } = await loadSession(dir);
|
|
2620
2675
|
if (charter === null) { err(`pair: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2621
2676
|
if (!(await charterIsIntact(dir, charter.protocol))) return EXIT.REFUSED;
|
|
2622
2677
|
if (!isPairingFormat(values.format)) {
|
|
@@ -2628,20 +2683,20 @@ const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
|
2628
2683
|
}
|
|
2629
2684
|
const seed = (values.seed ?? '').split(',').map((s) => s.trim()).filter((s) => s.length > 0);
|
|
2630
2685
|
|
|
2631
|
-
const contestants = seats(
|
|
2686
|
+
const contestants = seats(log).map((s) => s.actor);
|
|
2632
2687
|
if (contestants.length < 2) { err('pair: fewer than two contestants are seated'); return EXIT.REFUSED; }
|
|
2633
|
-
const played = matches(
|
|
2688
|
+
const played = matches(log);
|
|
2634
2689
|
const round = values.round !== undefined
|
|
2635
2690
|
? Number(values.round)
|
|
2636
2691
|
: Math.max(0, ...played.map((m) => m.round)) + 1;
|
|
2637
2692
|
|
|
2638
|
-
const pairings = pairRound(contestants, standings(
|
|
2693
|
+
const pairings = pairRound(contestants, standings(log), values.format, round, played, seed);
|
|
2639
2694
|
if (pairings.length === 0) {
|
|
2640
2695
|
out(`no pairings for round ${round} — the ${values.format} field is decided`);
|
|
2641
2696
|
return EXIT.OK;
|
|
2642
2697
|
}
|
|
2643
2698
|
|
|
2644
|
-
let doc =
|
|
2699
|
+
let doc = log;
|
|
2645
2700
|
for (const pairing of pairings) {
|
|
2646
2701
|
const created = matchCreatedEntry(pairing, round, nowStamp(), bestOf);
|
|
2647
2702
|
doc = appendEntry(doc, created);
|
|
@@ -2651,7 +2706,7 @@ const cmdPair = async (argv: readonly string[]): Promise<number> => {
|
|
|
2651
2706
|
created.fields?.['Match'] ?? '', round, pairing.a, null, nowStamp(), values.actor ?? 'RECORD'));
|
|
2652
2707
|
}
|
|
2653
2708
|
}
|
|
2654
|
-
await
|
|
2709
|
+
await writeLog(dir, doc);
|
|
2655
2710
|
await logAct(dir, values.actor ?? 'RECORD', 'OPERATOR' as never, `PAIRED round ${round} (${values.format})`);
|
|
2656
2711
|
const rec = await commitAct(dir, `MATCH_PAIRING — round ${round} (${values.format})`);
|
|
2657
2712
|
const suffix = bestOf > 1 ? `, best of ${bestOf}` : '';
|
|
@@ -2673,14 +2728,14 @@ const cmdMatch = async (argv: readonly string[]): Promise<number> => {
|
|
|
2673
2728
|
options: { dir: { type: 'string' }, match: { type: 'string' }, winner: { type: 'string' }, actor: { type: 'string' } },
|
|
2674
2729
|
});
|
|
2675
2730
|
const dir = values.dir ?? '.';
|
|
2676
|
-
const {
|
|
2731
|
+
const { log, charter } = await loadSession(dir);
|
|
2677
2732
|
if (charter === null) { err(`match: ${dir} is not a session repo`); return EXIT.USAGE; }
|
|
2678
2733
|
if (verb !== 'list' && !(await charterIsIntact(dir, charter.protocol))) {
|
|
2679
2734
|
return EXIT.REFUSED;
|
|
2680
2735
|
}
|
|
2681
2736
|
|
|
2682
2737
|
if (verb === 'list') {
|
|
2683
|
-
const all = matches(
|
|
2738
|
+
const all = matches(log);
|
|
2684
2739
|
if (all.length === 0) { out('no matches yet — pair a round first'); return EXIT.OK; }
|
|
2685
2740
|
for (const m of all) {
|
|
2686
2741
|
const status = m.winner === null ? 'open' : `${m.winner} won`;
|
|
@@ -2695,8 +2750,8 @@ const cmdMatch = async (argv: readonly string[]): Promise<number> => {
|
|
|
2695
2750
|
err('match report: --match and --winner are required'); return EXIT.USAGE;
|
|
2696
2751
|
}
|
|
2697
2752
|
try {
|
|
2698
|
-
const result = reportMatch(values.match, values.winner, nowStamp(), values.actor ?? 'RECORD',
|
|
2699
|
-
await
|
|
2753
|
+
const result = reportMatch(values.match, values.winner, nowStamp(), values.actor ?? 'RECORD', log);
|
|
2754
|
+
await writeLog(dir, result.log);
|
|
2700
2755
|
const kind = result.decided ? 'MATCH_DECIDED' : 'MATCH_GAME';
|
|
2701
2756
|
await logAct(dir, values.actor ?? 'RECORD', 'AUTHORITY' as never, `${kind} ${values.match} -> ${values.winner}`);
|
|
2702
2757
|
const rec = await commitAct(dir, `${kind} — ${values.match}: ${values.winner}`);
|
|
@@ -2724,7 +2779,7 @@ const stateMark = (state: string): string => {
|
|
|
2724
2779
|
switch (state) {
|
|
2725
2780
|
case 'CONVENED': return '[OK]';
|
|
2726
2781
|
case 'SUSPENDED': return '[!!]';
|
|
2727
|
-
case '
|
|
2782
|
+
case 'CLOSED': return '[--]';
|
|
2728
2783
|
case 'STALE': return '[~~]';
|
|
2729
2784
|
case 'INVALID': return '[XX]';
|
|
2730
2785
|
default: return '[??]';
|
|
@@ -2768,7 +2823,7 @@ const cmdRegistry = async (argv: readonly string[]): Promise<number> => {
|
|
|
2768
2823
|
out(' -- roll-up (whole tree) --');
|
|
2769
2824
|
out(` nodes ${summary.nodes}`);
|
|
2770
2825
|
out(` by state ${Object.entries(summary.by_state).map(([s, c]) => `${s} ${c}`).join(' ')}`);
|
|
2771
|
-
out(` open motions ${summary.
|
|
2826
|
+
out(` open motions ${summary.open_ballots}`);
|
|
2772
2827
|
out(` total cost $${summary.total_cost_usd.toFixed(4)}`);
|
|
2773
2828
|
out(` total tokens ${summary.total_tokens.toLocaleString()}`);
|
|
2774
2829
|
return EXIT.OK;
|
|
@@ -2778,7 +2833,7 @@ const cmdRegistry = async (argv: readonly string[]): Promise<number> => {
|
|
|
2778
2833
|
* `politik cascade` — a fault repeating across siblings is a signal, not a
|
|
2779
2834
|
* coincidence. Walks the tree, and where enough siblings share a suspension
|
|
2780
2835
|
* cause within the window (tree.ts checkCascade), records a CASCADE_ALERT on
|
|
2781
|
-
* their parent so
|
|
2836
|
+
* their parent so an owner chartering the same configuration is warned. Idempotent:
|
|
2782
2837
|
* a parent already carrying the alert is left alone.
|
|
2783
2838
|
*/
|
|
2784
2839
|
const cmdCascade = async (argv: readonly string[]): Promise<number> => {
|
|
@@ -2793,12 +2848,12 @@ const cmdCascade = async (argv: readonly string[]): Promise<number> => {
|
|
|
2793
2848
|
|
|
2794
2849
|
for (const finding of findings) {
|
|
2795
2850
|
const signature = finding.alert.signature ?? 'unknown';
|
|
2796
|
-
if (cascadeAlerts(finding.parent.
|
|
2851
|
+
if (cascadeAlerts(finding.parent.log).includes(signature)) {
|
|
2797
2852
|
out(`${finding.parent.rel}: cascade on ${signature} already recorded`);
|
|
2798
2853
|
continue;
|
|
2799
2854
|
}
|
|
2800
|
-
const updated = recordOnNode(finding.parent.
|
|
2801
|
-
await
|
|
2855
|
+
const updated = recordOnNode(finding.parent.log, cascadeEntry(finding.alert, nowStamp()));
|
|
2856
|
+
await writeLog(finding.parent.dir, updated);
|
|
2802
2857
|
const rec = await commitAct(finding.parent.dir,
|
|
2803
2858
|
`CASCADE_ALERT — ${signature} across ${finding.alert.nodes.length} siblings`);
|
|
2804
2859
|
out(`CASCADE — ${signature} across ${finding.alert.nodes.length} siblings`);
|
|
@@ -2821,7 +2876,7 @@ export const run = async (argv: readonly string[]): Promise<number> => {
|
|
|
2821
2876
|
}
|
|
2822
2877
|
|
|
2823
2878
|
// ADR-0011: governance on a shared session syncs around the act. `confirm`
|
|
2824
|
-
// syncs around its own replay (after the
|
|
2879
|
+
// syncs around its own replay (after the owner has typed the id), so it is
|
|
2825
2880
|
// not wrapped here.
|
|
2826
2881
|
if (REFRESH_BEFORE.has(command)) await refreshForRead(dirArg(rest));
|
|
2827
2882
|
if (!UNGUARDED_COMMANDS.has(command) && command !== 'confirm') {
|
|
@@ -2867,12 +2922,12 @@ const dispatch = async (command: string | undefined, rest: readonly string[]): P
|
|
|
2867
2922
|
return cmdValidate(rest);
|
|
2868
2923
|
case 'init':
|
|
2869
2924
|
return cmdInit(rest);
|
|
2870
|
-
case '
|
|
2871
|
-
return
|
|
2872
|
-
case '
|
|
2873
|
-
return
|
|
2874
|
-
case '
|
|
2875
|
-
return
|
|
2925
|
+
case 'misconduct':
|
|
2926
|
+
return cmdMisconduct(rest);
|
|
2927
|
+
case 'vote':
|
|
2928
|
+
return cmdVote(rest);
|
|
2929
|
+
case 'enact':
|
|
2930
|
+
return cmdEnact(rest);
|
|
2876
2931
|
case 'heartbeat':
|
|
2877
2932
|
return cmdHeartbeat(rest);
|
|
2878
2933
|
case 'snapshot':
|
|
@@ -2895,14 +2950,14 @@ const dispatch = async (command: string | undefined, rest: readonly string[]): P
|
|
|
2895
2950
|
return cmdLedger(rest);
|
|
2896
2951
|
case 'run':
|
|
2897
2952
|
return cmdRun(rest);
|
|
2898
|
-
case '
|
|
2899
|
-
return
|
|
2953
|
+
case 'log':
|
|
2954
|
+
return cmdLog(rest);
|
|
2900
2955
|
case 'integrity':
|
|
2901
2956
|
return cmdIntegrity(rest);
|
|
2902
2957
|
case 'status':
|
|
2903
2958
|
return cmdStatus(rest);
|
|
2904
|
-
case '
|
|
2905
|
-
return
|
|
2959
|
+
case 'close':
|
|
2960
|
+
return cmdClose(rest);
|
|
2906
2961
|
case 'registry':
|
|
2907
2962
|
return cmdRegistry(rest);
|
|
2908
2963
|
case 'cascade':
|