@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/escalation.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* escalation — escalation workflow.
|
|
3
3
|
*
|
|
4
|
-
* The flow (RUNTIME.md
|
|
4
|
+
* The flow (RUNTIME.md — the escalation flow):
|
|
5
5
|
*
|
|
6
6
|
* Agent hits a decision requiring human judgement
|
|
7
7
|
* -> commits escalation to escalations/[timestamp].md
|
|
8
|
-
* ->
|
|
8
|
+
* -> Owner notified
|
|
9
9
|
* -> session pauses
|
|
10
|
-
* ->
|
|
10
|
+
* -> Owner commits ruling
|
|
11
11
|
* -> session resumes
|
|
12
|
-
* -> ruling recorded permanently in
|
|
12
|
+
* -> ruling recorded permanently in record
|
|
13
13
|
*
|
|
14
14
|
* Pure, like the initializer: this module produces the files and the next state,
|
|
15
15
|
* and the caller commits them. Notification is the caller's job too — it is an
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
*
|
|
19
19
|
* Note on vocabulary: RUNTIME.md predates ADR-0003 and describes the pause as
|
|
20
20
|
* `STATE.json → paused: true`. ADR-0003 supersedes that mapping: the session
|
|
21
|
-
* becomes SUSPENDED with `suspension.cause:
|
|
21
|
+
* becomes SUSPENDED with `suspension.cause: ESCALATION`. This module
|
|
22
22
|
* implements the ADR.
|
|
23
23
|
*
|
|
24
24
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import type { Role } from './canon.ts';
|
|
28
|
-
import { RECORD_TYPES, appendEntry, type
|
|
28
|
+
import { RECORD_TYPES, appendEntry, type RecordEntry } from './log.ts';
|
|
29
29
|
import type { FileWrite } from './scm.ts';
|
|
30
30
|
import { createState, type SessionStateFile } from './state.ts';
|
|
31
31
|
|
|
@@ -48,20 +48,20 @@ export interface EscalationInput {
|
|
|
48
48
|
/**
|
|
49
49
|
* True when the Charter's protocol declares `session.escalation: disabled`
|
|
50
50
|
* (ADR-0006). A protocol with no appeals — a Darwinist chamber — has no
|
|
51
|
-
* mechanism to resolve
|
|
51
|
+
* mechanism to resolve an escalation, so it refuses to raise one at all.
|
|
52
52
|
*/
|
|
53
53
|
readonly escalation_disabled?: boolean;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export interface EscalationResult {
|
|
57
57
|
readonly escalation_path: string;
|
|
58
|
-
/** Where the
|
|
58
|
+
/** Where the owner must commit their ruling. */
|
|
59
59
|
readonly ruling_path: string;
|
|
60
|
-
/** SUSPENDED, cause
|
|
60
|
+
/** SUSPENDED, cause ESCALATION. */
|
|
61
61
|
readonly state: SessionStateFile;
|
|
62
62
|
readonly files: readonly FileWrite[];
|
|
63
|
-
readonly
|
|
64
|
-
/** Message body for the
|
|
63
|
+
readonly log_entry: RecordEntry;
|
|
64
|
+
/** Message body for the owner notification. The caller delivers it. */
|
|
65
65
|
readonly notification: string;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -73,7 +73,7 @@ export const rulingPath = (sequence: number): string =>
|
|
|
73
73
|
`escalations/ruling-${String(sequence).padStart(3, '0')}.md`;
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* File
|
|
76
|
+
* File an escalation.
|
|
77
77
|
*
|
|
78
78
|
* Suspends the session. Every actor reads STATE.json before acting, so agents
|
|
79
79
|
* halt as soon as this state is committed — the pause is a consequence of the
|
|
@@ -88,22 +88,22 @@ export class EscalationError extends Error {
|
|
|
88
88
|
|
|
89
89
|
export const fileEscalation = (
|
|
90
90
|
input: EscalationInput,
|
|
91
|
-
|
|
92
|
-
): EscalationResult & { readonly
|
|
93
|
-
// A protocol that declares no escalation has no mechanism to resolve
|
|
94
|
-
//
|
|
91
|
+
log: string,
|
|
92
|
+
): EscalationResult & { readonly log: string } => {
|
|
93
|
+
// A protocol that declares no escalation has no mechanism to resolve an
|
|
94
|
+
// escalation (ADR-0006). Refusing to raise one is what makes a no-appeals session
|
|
95
95
|
// behave like one: the decision stands, and a dissenting actor exits.
|
|
96
96
|
if (input.escalation_disabled === true) {
|
|
97
|
-
throw new EscalationError('this protocol declares no escalation —
|
|
97
|
+
throw new EscalationError('this protocol declares no escalation — an escalation cannot be raised');
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
//
|
|
101
|
-
// Without this guard it would fire on any state — reopening a
|
|
100
|
+
// An escalation suspends a live session, so it can only be raised from one.
|
|
101
|
+
// Without this guard it would fire on any state — reopening a CLOSED
|
|
102
102
|
// (sealed) session, or clobbering the pending ruling of a session already
|
|
103
|
-
// SUSPENDED for an earlier
|
|
103
|
+
// SUSPENDED for an earlier escalation. Mirrors the vote/Enactment guard.
|
|
104
104
|
if (input.state.state !== 'CONVENED') {
|
|
105
105
|
throw new EscalationError(
|
|
106
|
-
`cannot raise
|
|
106
|
+
`cannot raise an escalation while the session is ${input.state.state}`,
|
|
107
107
|
);
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -111,7 +111,7 @@ export const fileEscalation = (
|
|
|
111
111
|
const ruling_path = rulingPath(input.sequence);
|
|
112
112
|
|
|
113
113
|
const document = [
|
|
114
|
-
`#
|
|
114
|
+
`# ESCALATION — ${input.title}`,
|
|
115
115
|
'',
|
|
116
116
|
`**Filed by:** ${input.actor} (${input.role})`,
|
|
117
117
|
`**Filed at:** ${input.at}`,
|
|
@@ -128,31 +128,31 @@ export const fileEscalation = (
|
|
|
128
128
|
protocol: input.state.protocol,
|
|
129
129
|
state: 'SUSPENDED',
|
|
130
130
|
quorum: input.state.quorum,
|
|
131
|
-
|
|
131
|
+
log_head: input.state.log_head,
|
|
132
132
|
updated_at: input.at,
|
|
133
133
|
suspension: {
|
|
134
|
-
cause: '
|
|
134
|
+
cause: 'ESCALATION',
|
|
135
135
|
since: input.at,
|
|
136
136
|
record_ref: escalation_path,
|
|
137
137
|
escalation_ref: escalation_path,
|
|
138
138
|
},
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
const
|
|
142
|
-
type: '
|
|
141
|
+
const log_entry: RecordEntry = {
|
|
142
|
+
type: 'ESCALATION',
|
|
143
143
|
at: input.at,
|
|
144
144
|
actor: input.actor,
|
|
145
145
|
role: input.role,
|
|
146
146
|
fields: {
|
|
147
147
|
Escalation: escalation_path,
|
|
148
148
|
'Ruling expected': ruling_path,
|
|
149
|
-
'Session status': 'SUSPENDED — awaiting
|
|
149
|
+
'Session status': 'SUSPENDED — awaiting Owner ruling',
|
|
150
150
|
},
|
|
151
151
|
body: input.title,
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
const notification = [
|
|
155
|
-
'
|
|
155
|
+
'An escalation has been raised.',
|
|
156
156
|
'',
|
|
157
157
|
`Filed by: ${input.actor} (${input.role})`,
|
|
158
158
|
`Subject: ${input.title}`,
|
|
@@ -168,9 +168,9 @@ export const fileEscalation = (
|
|
|
168
168
|
ruling_path,
|
|
169
169
|
state,
|
|
170
170
|
files: [{ path: escalation_path, content: document }],
|
|
171
|
-
|
|
171
|
+
log_entry,
|
|
172
172
|
notification,
|
|
173
|
-
|
|
173
|
+
log: appendEntry(log, log_entry),
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
176
|
|
|
@@ -183,7 +183,7 @@ export type RulingOutcome = 'UPHELD' | 'REVERSED' | 'NOTED';
|
|
|
183
183
|
export interface RulingInput {
|
|
184
184
|
readonly sequence: number;
|
|
185
185
|
readonly at: string;
|
|
186
|
-
/** The
|
|
186
|
+
/** The owner. Only AUTHORITY may rule. */
|
|
187
187
|
readonly actor: string;
|
|
188
188
|
readonly role: Role;
|
|
189
189
|
readonly outcome: RulingOutcome;
|
|
@@ -206,23 +206,23 @@ export interface RulingResult {
|
|
|
206
206
|
/** CONVENED — the suspension is lifted. */
|
|
207
207
|
readonly state: SessionStateFile;
|
|
208
208
|
readonly files: readonly FileWrite[];
|
|
209
|
-
readonly
|
|
209
|
+
readonly log: string;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
|
-
* Commit
|
|
213
|
+
* Commit an owner's ruling and resume the session.
|
|
214
214
|
*
|
|
215
215
|
* Two constitutional constraints are enforced rather than assumed:
|
|
216
|
-
* - Only AUTHORITY may rule.
|
|
217
|
-
* machine could not make the call; letting a non-
|
|
216
|
+
* - Only AUTHORITY may rule. An escalation exists precisely because a
|
|
217
|
+
* machine could not make the call; letting a non-Owner resolve it would
|
|
218
218
|
* defeat the mechanism.
|
|
219
|
-
* - The session must actually be suspended for
|
|
219
|
+
* - The session must actually be suspended for an escalation. Resuming a
|
|
220
220
|
* session suspended by a *different* cause would silently discard that cause.
|
|
221
221
|
*/
|
|
222
|
-
export const commitRuling = (input: RulingInput,
|
|
222
|
+
export const commitRuling = (input: RulingInput, log: string): RulingResult => {
|
|
223
223
|
if (input.role !== 'AUTHORITY') {
|
|
224
224
|
throw new RulingError(
|
|
225
|
-
`only AUTHORITY may rule on
|
|
225
|
+
`only AUTHORITY may rule on an escalation — ${input.actor} is ${input.role}`,
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
if (input.state.state !== 'SUSPENDED') {
|
|
@@ -230,9 +230,9 @@ export const commitRuling = (input: RulingInput, hansard: string): RulingResult
|
|
|
230
230
|
`cannot rule on a session in state ${input.state.state} — expected SUSPENDED`,
|
|
231
231
|
);
|
|
232
232
|
}
|
|
233
|
-
if (input.state.suspension?.cause !== '
|
|
233
|
+
if (input.state.suspension?.cause !== 'ESCALATION') {
|
|
234
234
|
throw new RulingError(
|
|
235
|
-
`session is suspended for ${input.state.suspension?.cause ?? 'an unknown cause'}, not
|
|
235
|
+
`session is suspended for ${input.state.suspension?.cause ?? 'an unknown cause'}, not ESCALATION`,
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
|
|
@@ -256,7 +256,7 @@ export const commitRuling = (input: RulingInput, hansard: string): RulingResult
|
|
|
256
256
|
protocol: input.state.protocol,
|
|
257
257
|
state: 'CONVENED',
|
|
258
258
|
quorum: input.state.quorum,
|
|
259
|
-
|
|
259
|
+
log_head: input.state.log_head,
|
|
260
260
|
updated_at: input.at,
|
|
261
261
|
suspension: null,
|
|
262
262
|
});
|
|
@@ -265,7 +265,7 @@ export const commitRuling = (input: RulingInput, hansard: string): RulingResult
|
|
|
265
265
|
ruling_path,
|
|
266
266
|
state,
|
|
267
267
|
files: [{ path: ruling_path, content: document }],
|
|
268
|
-
|
|
268
|
+
log: appendEntry(log, {
|
|
269
269
|
type: 'RULING',
|
|
270
270
|
at: input.at,
|
|
271
271
|
actor: input.actor,
|
|
@@ -300,7 +300,7 @@ export interface FaultInput {
|
|
|
300
300
|
* Render a SESSION_FAULT record in the shape RUNTIME.md specifies.
|
|
301
301
|
* Critical faults (PATH_C) use the SESSION_FAULT_CRITICAL type.
|
|
302
302
|
*/
|
|
303
|
-
export const faultEntry = (input: FaultInput):
|
|
303
|
+
export const faultEntry = (input: FaultInput): RecordEntry => ({
|
|
304
304
|
type:
|
|
305
305
|
input.resolution_path === 'PATH_C'
|
|
306
306
|
? RECORD_TYPES.SESSION_FAULT_CRITICAL
|
package/src/fault.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Fault classification and auto-recovery.
|
|
3
3
|
*
|
|
4
4
|
* RUNTIME.md § Infrastructure Fault Classification states the problem exactly:
|
|
5
|
-
* a failed action looks identical in the
|
|
5
|
+
* a failed action looks identical in the record whether the agent made a bad
|
|
6
6
|
* decision or a secret expired. Without attribution an innocent actor is
|
|
7
7
|
* penalised — demotion triggers, performance record damaged — for something
|
|
8
8
|
* entirely outside their control.
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
*
|
|
13
13
|
* PATH_A — transient. Retry; no human needed.
|
|
14
14
|
* PATH_B — a human must fix it. Suspend and escalate.
|
|
15
|
-
* PATH_C — irrecoverable.
|
|
15
|
+
* PATH_C — irrecoverable. Close.
|
|
16
16
|
*
|
|
17
17
|
* ## On classifying from stderr
|
|
18
18
|
*
|
|
19
19
|
* The signals here are heuristics over vendor error text, and they will drift.
|
|
20
20
|
* That is acceptable because of which way they fail: an unrecognised fault
|
|
21
21
|
* classifies as `FAULT_AMBIGUOUS`, which does **not** penalise the actor and
|
|
22
|
-
* routes to a human. The cost of being wrong is
|
|
22
|
+
* routes to a human. The cost of being wrong is an owner reading an error
|
|
23
23
|
* message; the cost of guessing confidently would be blaming an actor for an
|
|
24
24
|
* outage.
|
|
25
25
|
*
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import type { Role } from './canon.ts';
|
|
30
|
-
import { RECORD_TYPES, type
|
|
30
|
+
import { RECORD_TYPES, type RecordEntry } from './log.ts';
|
|
31
31
|
import type { SpawnResult } from './spawn.ts';
|
|
32
32
|
|
|
33
33
|
/* -------------------------------------------------------------------------- */
|
|
@@ -128,7 +128,7 @@ export const classify = (result: SpawnResult): Classification => {
|
|
|
128
128
|
fault_type: 'FAULT_AMBIGUOUS',
|
|
129
129
|
path: 'PATH_B',
|
|
130
130
|
actor_penalised: false,
|
|
131
|
-
detail: 'cannot determine — escalated to the
|
|
131
|
+
detail: 'cannot determine — escalated to the owner for a ruling',
|
|
132
132
|
};
|
|
133
133
|
};
|
|
134
134
|
|
|
@@ -200,7 +200,7 @@ export interface FaultRecordInput {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/** Record a fault, with its attribution and resolution path. */
|
|
203
|
-
export const faultRecord = (input: FaultRecordInput):
|
|
203
|
+
export const faultRecord = (input: FaultRecordInput): RecordEntry => ({
|
|
204
204
|
type:
|
|
205
205
|
input.classification.path === 'PATH_C'
|
|
206
206
|
? RECORD_TYPES.SESSION_FAULT_CRITICAL
|
|
@@ -228,7 +228,7 @@ export const autoResolvedRecord = (
|
|
|
228
228
|
actor: string,
|
|
229
229
|
role: Role,
|
|
230
230
|
attempts: number,
|
|
231
|
-
):
|
|
231
|
+
): RecordEntry => ({
|
|
232
232
|
type: RECORD_TYPES.FAULT_RESOLVED_AUTO,
|
|
233
233
|
at,
|
|
234
234
|
actor,
|
|
@@ -236,6 +236,6 @@ export const autoResolvedRecord = (
|
|
|
236
236
|
fields: {
|
|
237
237
|
Resolution: `succeeded on attempt ${attempts}`,
|
|
238
238
|
'Actor record': 'no penalty — the fault was transient',
|
|
239
|
-
'
|
|
239
|
+
'Owner intervention': 'none required',
|
|
240
240
|
},
|
|
241
241
|
});
|
package/src/federation.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* The engine stayed storage-agnostic; nothing here changes how a session runs.
|
|
12
12
|
* Discovery walks directories; everything downstream (buildTree, rollUp,
|
|
13
|
-
* detectCascades) is pure and reuses tree.ts, ledger.ts and
|
|
13
|
+
* detectCascades) is pure and reuses tree.ts, ledger.ts and log.ts, so a
|
|
14
14
|
* node in a federated tree obeys exactly the governance a standalone one does.
|
|
15
15
|
*
|
|
16
16
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
@@ -23,7 +23,7 @@ import { join, resolve, relative } from 'node:path';
|
|
|
23
23
|
import { parseCharter } from './charter.ts';
|
|
24
24
|
import { parseState } from './state.ts';
|
|
25
25
|
import { totals } from './ledger.ts';
|
|
26
|
-
import { parseEntries } from './
|
|
26
|
+
import { parseEntries } from './log.ts';
|
|
27
27
|
import {
|
|
28
28
|
checkCascade, DEFAULT_CASCADE, type CascadeAlert, type CascadeConfig, type SiblingFault,
|
|
29
29
|
} from './tree.ts';
|
|
@@ -51,7 +51,7 @@ export interface FederationNode {
|
|
|
51
51
|
readonly children: readonly string[];
|
|
52
52
|
readonly depth: number;
|
|
53
53
|
/** Raw record, kept for fault and open-Motion scanning. */
|
|
54
|
-
readonly
|
|
54
|
+
readonly log: string;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
interface RawNode {
|
|
@@ -64,7 +64,7 @@ interface RawNode {
|
|
|
64
64
|
readonly cost_usd: number;
|
|
65
65
|
readonly tokens: number;
|
|
66
66
|
readonly parentDir: string | null;
|
|
67
|
-
readonly
|
|
67
|
+
readonly log: string;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/* -------------------------------------------------------------------------- */
|
|
@@ -113,7 +113,7 @@ export const readNode = async (dir: string): Promise<RawNode | null> => {
|
|
|
113
113
|
const charter = parsed.charter;
|
|
114
114
|
|
|
115
115
|
const ledgerDoc = await readFile(join(dir, charter.ledger.path), 'utf8').catch(() => '');
|
|
116
|
-
const
|
|
116
|
+
const log = await readFile(join(dir, 'LOG.md'), 'utf8').catch(() => '');
|
|
117
117
|
const cost = totals(ledgerDoc);
|
|
118
118
|
|
|
119
119
|
// inherits_from is relative to the child; resolve it to the parent's directory.
|
|
@@ -129,7 +129,7 @@ export const readNode = async (dir: string): Promise<RawNode | null> => {
|
|
|
129
129
|
cost_usd: cost.cost_usd,
|
|
130
130
|
tokens: cost.tokens,
|
|
131
131
|
parentDir,
|
|
132
|
-
|
|
132
|
+
log,
|
|
133
133
|
};
|
|
134
134
|
};
|
|
135
135
|
|
|
@@ -188,7 +188,7 @@ export const buildTree = (raws: readonly RawNode[], root: string): readonly Fede
|
|
|
188
188
|
parent: inTree(r.parentDir) ? r.parentDir : null,
|
|
189
189
|
children: (children.get(r.dir) ?? []).slice().sort(),
|
|
190
190
|
depth: depthOf(r.dir),
|
|
191
|
-
|
|
191
|
+
log: r.log,
|
|
192
192
|
}]),
|
|
193
193
|
);
|
|
194
194
|
|
|
@@ -222,16 +222,16 @@ export interface RollUp {
|
|
|
222
222
|
readonly by_state: Readonly<Record<string, number>>;
|
|
223
223
|
readonly total_cost_usd: number;
|
|
224
224
|
readonly total_tokens: number;
|
|
225
|
-
readonly
|
|
225
|
+
readonly open_ballots: number;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
/** Motions on the floor: a
|
|
229
|
-
export const
|
|
228
|
+
/** Motions on the floor: a vote was opened and no outcome has been recorded. */
|
|
229
|
+
export const openBallots = (log: string): number => {
|
|
230
230
|
const open = new Set<string>();
|
|
231
|
-
for (const entry of parseEntries(
|
|
231
|
+
for (const entry of parseEntries(log)) {
|
|
232
232
|
const motion = entry.fields['Motion'];
|
|
233
233
|
if (motion === undefined) continue;
|
|
234
|
-
if (entry.type === '
|
|
234
|
+
if (entry.type === 'BALLOT_OPENED') open.add(motion);
|
|
235
235
|
else if (entry.type === 'MOTION_CARRIED' || entry.type === 'MOTION_REJECTED') open.delete(motion);
|
|
236
236
|
}
|
|
237
237
|
return open.size;
|
|
@@ -246,14 +246,14 @@ export const rollUp = (nodes: readonly FederationNode[]): RollUp => {
|
|
|
246
246
|
by_state[node.state] = (by_state[node.state] ?? 0) + 1;
|
|
247
247
|
cost += node.cost_usd;
|
|
248
248
|
tokens += node.tokens;
|
|
249
|
-
open +=
|
|
249
|
+
open += openBallots(node.log);
|
|
250
250
|
}
|
|
251
251
|
return {
|
|
252
252
|
nodes: nodes.length,
|
|
253
253
|
by_state,
|
|
254
254
|
total_cost_usd: cost,
|
|
255
255
|
total_tokens: tokens,
|
|
256
|
-
|
|
256
|
+
open_ballots: open,
|
|
257
257
|
};
|
|
258
258
|
};
|
|
259
259
|
|
package/src/git.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Committing the record.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
4
|
+
* The record is the session, and this framework's own Charter tell
|
|
5
5
|
* every actor "commit your result; uncommitted work does not exist". That rule
|
|
6
6
|
* binds the engine too: a governance act written to a file but never committed
|
|
7
7
|
* has, by the framework's own definition, not happened.
|
|
8
8
|
*
|
|
9
9
|
* On a GitHub-backed session `ScmProvider.commit()` lands these writes. Local
|
|
10
|
-
* sessions had no equivalent, so the
|
|
10
|
+
* sessions had no equivalent, so the vote and Enactment cycle sat dirty in the
|
|
11
11
|
* working tree — a record that did not exist. This module closes that gap.
|
|
12
12
|
*
|
|
13
13
|
* Attribution: Steve Krisjanovs, Cordfuse
|
|
@@ -48,8 +48,8 @@ const git = (
|
|
|
48
48
|
*
|
|
49
49
|
* Deliberately narrow: only the files named are staged. A governance command
|
|
50
50
|
* must never sweep up whatever else happens to be dirty in the working tree —
|
|
51
|
-
* an actor's half-finished work is not part of the record of a
|
|
52
|
-
* committing it under the
|
|
51
|
+
* an actor's half-finished work is not part of the record of a vote, and
|
|
52
|
+
* committing it under the owner's name would misattribute it.
|
|
53
53
|
*
|
|
54
54
|
* Silent no-ops rather than failures when the directory is not a git
|
|
55
55
|
* repository: a session can legitimately be exercised outside git (tests,
|
|
@@ -58,7 +58,7 @@ const git = (
|
|
|
58
58
|
export const commitRecord = async (
|
|
59
59
|
dir: string,
|
|
60
60
|
message: string,
|
|
61
|
-
paths: readonly string[] = ['
|
|
61
|
+
paths: readonly string[] = ['LOG.md', 'STATE.json'],
|
|
62
62
|
spawnFn: typeof spawn = spawn,
|
|
63
63
|
opts: { readonly sign?: boolean } = {},
|
|
64
64
|
): Promise<CommitResult> => {
|
|
@@ -104,15 +104,15 @@ export const commitRecord = async (
|
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
* Make a session's directory record-bearing.
|
|
107
|
+
* Make a session's directory record-bearing. session opening "creates the session
|
|
108
108
|
* repo"; without a repo, `commitRecord` silently no-ops and no act is recorded.
|
|
109
109
|
*
|
|
110
110
|
* Two shapes, auto-detected (ADR-0008 — a session is a git-tracked *directory*,
|
|
111
111
|
* standalone repo or subtree of one):
|
|
112
112
|
* - **Standalone**: the directory is not yet in a repo → `git init` it and land
|
|
113
|
-
* the
|
|
113
|
+
* the session opening, attributed to the owner.
|
|
114
114
|
* - **Monorepo**: the directory already sits inside a repo (a parent tree, or a
|
|
115
|
-
* clone) → commit the
|
|
115
|
+
* clone) → commit the session opening *to that repo* rather than nesting a new one.
|
|
116
116
|
* Per-commit identity, so the enclosing repo's own config is untouched;
|
|
117
117
|
* no-ops if there is nothing to commit (e.g. a re-run on a clone).
|
|
118
118
|
*
|
|
@@ -120,7 +120,7 @@ export const commitRecord = async (
|
|
|
120
120
|
*/
|
|
121
121
|
export const initSessionRepo = async (
|
|
122
122
|
dir: string,
|
|
123
|
-
|
|
123
|
+
owner: string,
|
|
124
124
|
guid: string,
|
|
125
125
|
spawnFn: typeof spawn = spawn,
|
|
126
126
|
opts: { readonly standalone?: boolean } = {},
|
|
@@ -131,23 +131,23 @@ export const initSessionRepo = async (
|
|
|
131
131
|
// even inside an enclosing tree — for per-session GitHub projection or a
|
|
132
132
|
// per-node permission boundary, the two cases standalone mode exists for.
|
|
133
133
|
if (isRepo.code === 0 && opts.standalone !== true) {
|
|
134
|
-
// Monorepo: land the
|
|
134
|
+
// Monorepo: land the session opening in the enclosing repo. `add .` stages only
|
|
135
135
|
// this session's subtree; the per-commit identity attributes it to the
|
|
136
|
-
//
|
|
136
|
+
// Owner without rewriting the parent repo's config. Exclude `*.tmp` — an
|
|
137
137
|
// atomic write interrupted mid-flight can orphan one, and it must never enter
|
|
138
138
|
// the record.
|
|
139
139
|
await git(dir, ['add', '.', ':(exclude)*.tmp', ':(exclude).politik/pending'], spawnFn);
|
|
140
140
|
const commit = await git(
|
|
141
141
|
dir,
|
|
142
|
-
['-c', `user.name=${
|
|
143
|
-
'commit', '-m', `
|
|
142
|
+
['-c', `user.name=${owner}`, '-c', `user.email=${owner}@politik.local`,
|
|
143
|
+
'commit', '-m', `open: session ${guid}`],
|
|
144
144
|
spawnFn,
|
|
145
145
|
);
|
|
146
146
|
if (commit.code !== 0) {
|
|
147
147
|
return { committed: false, sha: null, reason: 'existing repository — nothing to commit' };
|
|
148
148
|
}
|
|
149
149
|
const sha = await git(dir, ['rev-parse', 'HEAD'], spawnFn);
|
|
150
|
-
return { committed: true, sha: sha.out || null, reason: '
|
|
150
|
+
return { committed: true, sha: sha.out || null, reason: 'session opening committed to the enclosing repo' };
|
|
151
151
|
}
|
|
152
152
|
// A forced standalone inside an enclosing repo nests a fresh repo here — a
|
|
153
153
|
// deliberate isolation boundary, not the accidental nested `.git` the
|
|
@@ -156,10 +156,10 @@ export const initSessionRepo = async (
|
|
|
156
156
|
if ((await git(dir, ['init', '-q'], spawnFn)).code !== 0) {
|
|
157
157
|
return { committed: false, sha: null, reason: 'git unavailable — local directory only' };
|
|
158
158
|
}
|
|
159
|
-
await git(dir, ['config', 'user.name',
|
|
160
|
-
await git(dir, ['config', 'user.email', `${
|
|
159
|
+
await git(dir, ['config', 'user.name', owner], spawnFn);
|
|
160
|
+
await git(dir, ['config', 'user.email', `${owner}@politik.local`], spawnFn);
|
|
161
161
|
await git(dir, ['add', '-A', '.', ':(exclude)*.tmp', ':(exclude).politik/pending'], spawnFn);
|
|
162
|
-
const commit = await git(dir, ['commit', '-m', `
|
|
162
|
+
const commit = await git(dir, ['commit', '-m', `open: session ${guid}`], spawnFn);
|
|
163
163
|
if (commit.code !== 0) return { committed: false, sha: null, reason: 'repo initialized, nothing to commit' };
|
|
164
164
|
const sha = await git(dir, ['rev-parse', 'HEAD'], spawnFn);
|
|
165
165
|
return {
|