@aragon-agent/cli 0.6.44 → 0.6.45
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/CHANGELOG.md +44 -0
- package/README.md +69 -2
- package/dist/agent/controller.d.ts +69 -0
- package/dist/agent/controller.js +224 -11
- package/dist/agent/governance-view.d.ts +40 -0
- package/dist/agent/governance-view.js +40 -0
- package/dist/agent/governance-wiring.d.ts +162 -0
- package/dist/agent/governance-wiring.js +470 -0
- package/dist/agent/plan-prompt.d.ts +7 -0
- package/dist/agent/plan-prompt.js +2 -1
- package/dist/agent/reducer.d.ts +33 -1
- package/dist/agent/reducer.js +45 -9
- package/dist/agent/system-prompt.d.ts +19 -0
- package/dist/agent/system-prompt.js +9 -1
- package/dist/cli.js +45 -1
- package/dist/commands/builtins.js +10 -4
- package/dist/commands/governance-command.d.ts +35 -0
- package/dist/commands/governance-command.js +292 -0
- package/dist/commands/governance-runs-table.d.ts +40 -0
- package/dist/commands/governance-runs-table.js +130 -0
- package/dist/commands/registry.d.ts +12 -0
- package/dist/config/app-paths.d.ts +10 -0
- package/dist/config/app-paths.js +12 -0
- package/dist/config/cli-commands.d.ts +18 -0
- package/dist/config/cli-commands.js +47 -1
- package/dist/config/env.d.ts +2 -1
- package/dist/config/env.js +10 -1
- package/dist/config/governance-config.d.ts +125 -0
- package/dist/config/governance-config.js +164 -0
- package/dist/config/governance-launch.d.ts +71 -0
- package/dist/config/governance-launch.js +58 -0
- package/dist/config/load.d.ts +15 -0
- package/dist/config/load.js +26 -1
- package/dist/config/model-profile-store.d.ts +4 -2
- package/dist/config/schema.d.ts +22 -0
- package/dist/config/schema.js +6 -0
- package/dist/config/store.js +14 -1
- package/dist/config/ui-state.d.ts +11 -0
- package/dist/config/ui-state.js +11 -0
- package/dist/diagnostics/doctor.js +20 -0
- package/dist/governance/card-normalize.d.ts +24 -0
- package/dist/governance/card-normalize.js +76 -0
- package/dist/governance/copy.d.ts +109 -0
- package/dist/governance/copy.js +223 -0
- package/dist/governance/engine/aftermath.d.ts +49 -0
- package/dist/governance/engine/aftermath.js +134 -0
- package/dist/governance/engine/artifact-persist.d.ts +35 -0
- package/dist/governance/engine/artifact-persist.js +86 -0
- package/dist/governance/engine/budget.d.ts +52 -0
- package/dist/governance/engine/budget.js +112 -0
- package/dist/governance/engine/cards.d.ts +18 -0
- package/dist/governance/engine/cards.js +186 -0
- package/dist/governance/engine/digest.d.ts +32 -0
- package/dist/governance/engine/digest.js +63 -0
- package/dist/governance/engine/engine-core.d.ts +219 -0
- package/dist/governance/engine/engine-core.js +562 -0
- package/dist/governance/engine/engine.d.ts +68 -0
- package/dist/governance/engine/engine.js +314 -0
- package/dist/governance/engine/estimate.d.ts +38 -0
- package/dist/governance/engine/estimate.js +46 -0
- package/dist/governance/engine/inspector.d.ts +16 -0
- package/dist/governance/engine/inspector.js +396 -0
- package/dist/governance/engine/integration.d.ts +35 -0
- package/dist/governance/engine/integration.js +220 -0
- package/dist/governance/engine/lifecycle.d.ts +29 -0
- package/dist/governance/engine/lifecycle.js +656 -0
- package/dist/governance/engine/pause.d.ts +56 -0
- package/dist/governance/engine/pause.js +107 -0
- package/dist/governance/engine/phase-members.d.ts +15 -0
- package/dist/governance/engine/phase-members.js +34 -0
- package/dist/governance/engine/phase-planner.d.ts +53 -0
- package/dist/governance/engine/phase-planner.js +282 -0
- package/dist/governance/engine/rebuild.d.ts +27 -0
- package/dist/governance/engine/rebuild.js +57 -0
- package/dist/governance/engine/report.d.ts +66 -0
- package/dist/governance/engine/report.js +220 -0
- package/dist/governance/engine/run-digest.d.ts +20 -0
- package/dist/governance/engine/run-digest.js +42 -0
- package/dist/governance/engine/spec-builder.d.ts +117 -0
- package/dist/governance/engine/spec-builder.js +321 -0
- package/dist/governance/engine/stage-runner.d.ts +22 -0
- package/dist/governance/engine/stage-runner.js +664 -0
- package/dist/governance/engine/start-input.d.ts +19 -0
- package/dist/governance/engine/start-input.js +111 -0
- package/dist/governance/engine/state-machine.d.ts +101 -0
- package/dist/governance/engine/state-machine.js +586 -0
- package/dist/governance/engine/submission-queries.d.ts +42 -0
- package/dist/governance/engine/submission-queries.js +97 -0
- package/dist/governance/engine/submission-render.d.ts +12 -0
- package/dist/governance/engine/submission-render.js +92 -0
- package/dist/governance/engine/submissions.d.ts +27 -0
- package/dist/governance/engine/submissions.js +455 -0
- package/dist/governance/engine/visibility.d.ts +104 -0
- package/dist/governance/engine/visibility.js +223 -0
- package/dist/governance/governed-dispatch.d.ts +19 -0
- package/dist/governance/governed-dispatch.js +17 -0
- package/dist/governance/limits.d.ts +107 -0
- package/dist/governance/limits.js +131 -0
- package/dist/governance/posture-transition.d.ts +38 -0
- package/dist/governance/posture-transition.js +44 -0
- package/dist/governance/posture.d.ts +35 -0
- package/dist/governance/posture.js +59 -0
- package/dist/governance/profiles.d.ts +48 -0
- package/dist/governance/profiles.js +140 -0
- package/dist/governance/prompts/orchestrator-block.d.ts +40 -0
- package/dist/governance/prompts/orchestrator-block.js +128 -0
- package/dist/governance/prompts/plan-addendum.d.ts +22 -0
- package/dist/governance/prompts/plan-addendum.js +60 -0
- package/dist/governance/prompts/refusals.d.ts +48 -0
- package/dist/governance/prompts/refusals.js +82 -0
- package/dist/governance/prompts/role-blocks.d.ts +40 -0
- package/dist/governance/prompts/role-blocks.js +255 -0
- package/dist/governance/report-reader.d.ts +31 -0
- package/dist/governance/report-reader.js +57 -0
- package/dist/governance/roles.d.ts +83 -0
- package/dist/governance/roles.js +142 -0
- package/dist/governance/rules/claims.d.ts +83 -0
- package/dist/governance/rules/claims.js +250 -0
- package/dist/governance/rules/elimination.d.ts +66 -0
- package/dist/governance/rules/elimination.js +105 -0
- package/dist/governance/rules/events-table.d.ts +46 -0
- package/dist/governance/rules/events-table.js +94 -0
- package/dist/governance/rules/failure-analysis.d.ts +28 -0
- package/dist/governance/rules/failure-analysis.js +93 -0
- package/dist/governance/rules/ledger-replay.d.ts +53 -0
- package/dist/governance/rules/ledger-replay.js +53 -0
- package/dist/governance/rules/ledger-state.d.ts +85 -0
- package/dist/governance/rules/ledger-state.js +175 -0
- package/dist/governance/rules/ledger.d.ts +228 -0
- package/dist/governance/rules/ledger.js +560 -0
- package/dist/governance/rules/rca.d.ts +68 -0
- package/dist/governance/rules/rca.js +220 -0
- package/dist/governance/rules/settlement.d.ts +129 -0
- package/dist/governance/rules/settlement.js +363 -0
- package/dist/governance/rules/suspicion.d.ts +66 -0
- package/dist/governance/rules/suspicion.js +169 -0
- package/dist/governance/store/artifacts.d.ts +81 -0
- package/dist/governance/store/artifacts.js +173 -0
- package/dist/governance/store/atomic.d.ts +79 -0
- package/dist/governance/store/atomic.js +119 -0
- package/dist/governance/store/events-log.d.ts +35 -0
- package/dist/governance/store/events-log.js +86 -0
- package/dist/governance/store/run-lock.d.ts +51 -0
- package/dist/governance/store/run-lock.js +122 -0
- package/dist/governance/store/run-store.d.ts +229 -0
- package/dist/governance/store/run-store.js +644 -0
- package/dist/governance/store/scoreboard-export.d.ts +53 -0
- package/dist/governance/store/scoreboard-export.js +65 -0
- package/dist/governance/tools/child-tools.d.ts +31 -0
- package/dist/governance/tools/child-tools.js +65 -0
- package/dist/governance/tools/guard.d.ts +71 -0
- package/dist/governance/tools/guard.js +194 -0
- package/dist/governance/tools/inspector-tools.d.ts +63 -0
- package/dist/governance/tools/inspector-tools.js +424 -0
- package/dist/governance/tools/lead-tools.d.ts +42 -0
- package/dist/governance/tools/lead-tools.js +226 -0
- package/dist/governance/tools/normalize-util.d.ts +101 -0
- package/dist/governance/tools/normalize-util.js +230 -0
- package/dist/governance/tools/scan-incomplete.d.ts +79 -0
- package/dist/governance/tools/scan-incomplete.js +486 -0
- package/dist/governance/tools/shared-tools.d.ts +44 -0
- package/dist/governance/tools/shared-tools.js +125 -0
- package/dist/governance/tools/submit-normalizers.d.ts +28 -0
- package/dist/governance/tools/submit-normalizers.js +474 -0
- package/dist/governance/tools/submit-tools.d.ts +26 -0
- package/dist/governance/tools/submit-tools.js +171 -0
- package/dist/governance/types.d.ts +661 -0
- package/dist/governance/types.js +27 -0
- package/dist/session/validate-session.js +32 -1
- package/dist/team/runtime.d.ts +8 -0
- package/dist/team/runtime.js +9 -0
- package/dist/team/subagent.d.ts +23 -0
- package/dist/team/subagent.js +14 -3
- package/dist/team/types.d.ts +6 -0
- package/dist/tools/index.d.ts +30 -7
- package/dist/tools/index.js +14 -0
- package/dist/tools/plan-tools.d.ts +14 -2
- package/dist/tools/plan-tools.js +5 -2
- package/dist/ui/App.js +145 -25
- package/dist/ui/BottomStatusRow.js +1 -1
- package/dist/ui/Composer.d.ts +7 -1
- package/dist/ui/Composer.js +9 -6
- package/dist/ui/GovernancePanel.d.ts +50 -0
- package/dist/ui/GovernancePanel.js +77 -0
- package/dist/ui/GovernanceRun.d.ts +18 -0
- package/dist/ui/GovernanceRun.js +11 -0
- package/dist/ui/StatusBar.d.ts +15 -2
- package/dist/ui/StatusBar.js +10 -4
- package/dist/ui/Transcript.js +3 -0
- package/dist/ui/entries/GovernanceCard.d.ts +30 -0
- package/dist/ui/entries/GovernanceCard.js +32 -0
- package/dist/ui/governance-copy.d.ts +69 -0
- package/dist/ui/governance-copy.js +104 -0
- package/dist/ui/governance-status.d.ts +145 -0
- package/dist/ui/governance-status.js +326 -0
- package/dist/ui/interaction-copy.d.ts +4 -0
- package/dist/ui/interaction-copy.js +5 -0
- package/dist/ui/interaction-hints.d.ts +17 -0
- package/dist/ui/interaction-hints.js +14 -2
- package/dist/ui/layout/governance-board.d.ts +121 -0
- package/dist/ui/layout/governance-board.js +382 -0
- package/dist/ui/layout/governance-card.d.ts +53 -0
- package/dist/ui/layout/governance-card.js +134 -0
- package/dist/ui/layout/governance-chip.d.ts +38 -0
- package/dist/ui/layout/governance-chip.js +64 -0
- package/dist/ui/layout/governance-panel.d.ts +85 -0
- package/dist/ui/layout/governance-panel.js +358 -0
- package/dist/ui/layout/governance-roster.d.ts +65 -0
- package/dist/ui/layout/governance-roster.js +275 -0
- package/dist/ui/layout/status-detail-layout.js +3 -3
- package/dist/ui/layout/status-layout.d.ts +5 -2
- package/dist/ui/layout/status-layout.js +10 -6
- package/dist/ui/layout/virtual-window.js +11 -0
- package/dist/ui/overlays/GovernanceBoardOverlay.d.ts +41 -0
- package/dist/ui/overlays/GovernanceBoardOverlay.js +76 -0
- package/dist/ui/overlays/GovernanceSettingsPage.d.ts +48 -0
- package/dist/ui/overlays/GovernanceSettingsPage.js +93 -0
- package/dist/ui/overlays/HelpOverlay.js +4 -3
- package/dist/ui/overlays/QuestionOverlay.d.ts +9 -1
- package/dist/ui/overlays/QuestionOverlay.js +4 -2
- package/dist/ui/overlays/SettingsScreen.d.ts +7 -0
- package/dist/ui/overlays/SettingsScreen.js +21 -1
- package/dist/ui/overlays/governance-settings.d.ts +79 -0
- package/dist/ui/overlays/governance-settings.js +140 -0
- package/dist/ui/overlays/model-profile-state.d.ts +6 -1
- package/dist/ui/overlays/model-profile-state.js +10 -0
- package/dist/ui/palettes.d.ts +17 -0
- package/dist/ui/palettes.js +9 -0
- package/dist/ui/scrollback/live-preview.js +2 -0
- package/dist/ui/scrollback/settled-boundary.js +3 -0
- package/dist/ui/shortcuts.js +2 -2
- package/dist/ui/theme.d.ts +7 -0
- package/dist/ui/theme.js +1 -0
- package/dist/ui/transcript-text.js +9 -0
- package/dist/ui/use-wheel-routing.js +3 -1
- package/package.json +2 -2
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root-cause attribution -> ledger events (governance-mode 5.7).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY (`governance/` is glyph-scanned).
|
|
5
|
+
*
|
|
6
|
+
* The inspector reports WHO and HOW (a structured `RcaInput`); the engine owns the
|
|
7
|
+
* ARITHMETIC. That split is the point: the model supplies judgement it can justify from
|
|
8
|
+
* the code, and cannot mistype a figure, forget the C2 relief or double-count a cap.
|
|
9
|
+
* `expandRca` is pure - it returns events plus clawback requests in priority order, and
|
|
10
|
+
* the caller books them through `applyIncident` so the single-incident -50 cap truncates
|
|
11
|
+
* the right row (D13 -> D14/D15 -> C2/C3/C4 -> clawback).
|
|
12
|
+
*/
|
|
13
|
+
import { eventDef } from './events-table.js';
|
|
14
|
+
import { INSPECTOR_ID, activeAgents } from './ledger-state.js';
|
|
15
|
+
/** Recorded in the report; contributing agents carry weight but no event of their own. */
|
|
16
|
+
export const RCA_WEIGHTS = {
|
|
17
|
+
primary: 0.6,
|
|
18
|
+
contributing: 0.3,
|
|
19
|
+
oversight: 0.1,
|
|
20
|
+
};
|
|
21
|
+
/** Higher wins when one agent is attributed twice. */
|
|
22
|
+
const LEVEL_RANK = { primary: 3, oversight: 2, contributing: 1 };
|
|
23
|
+
const INDIVIDUAL_DEFECT_TEXT = 'Individual defect, no integration events: route the work back to its developer.';
|
|
24
|
+
/** Validate attributions against the roster; one entry per agent, highest level wins. */
|
|
25
|
+
function acceptAttributions(ctx, attributions, skipped) {
|
|
26
|
+
const byAgent = new Map();
|
|
27
|
+
for (const attribution of attributions) {
|
|
28
|
+
const id = attribution.agentId;
|
|
29
|
+
const agent = ctx.state.agents[id];
|
|
30
|
+
if (id === INSPECTOR_ID)
|
|
31
|
+
skipped.push(`${id}: the inspector is not scored (I-G5).`);
|
|
32
|
+
else if (agent === undefined)
|
|
33
|
+
skipped.push(`${id}: unknown agent.`);
|
|
34
|
+
else if (agent.status !== 'active')
|
|
35
|
+
skipped.push(`${id}: already eliminated.`);
|
|
36
|
+
else {
|
|
37
|
+
const known = byAgent.get(id);
|
|
38
|
+
const outranks = known !== undefined && LEVEL_RANK[attribution.level] > LEVEL_RANK[known.attribution.level];
|
|
39
|
+
if (known === undefined || outranks) {
|
|
40
|
+
byAgent.set(id, { attribution, role: agent.role });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [...byAgent.values()];
|
|
45
|
+
}
|
|
46
|
+
function incidentEvent(ctx, code, agentId, note) {
|
|
47
|
+
const event = {
|
|
48
|
+
code,
|
|
49
|
+
agentId,
|
|
50
|
+
at: ctx.at,
|
|
51
|
+
phase: ctx.phase,
|
|
52
|
+
by: ctx.by,
|
|
53
|
+
reason: `RCA ${ctx.incidentId}: ${eventDef(code).title}${note === '' ? '' : ` - ${note}`}`,
|
|
54
|
+
incidentId: ctx.incidentId,
|
|
55
|
+
};
|
|
56
|
+
if (ctx.wpId !== undefined)
|
|
57
|
+
event.wpId = ctx.wpId;
|
|
58
|
+
return event;
|
|
59
|
+
}
|
|
60
|
+
/** Oversight code by the stated miss, defaulting by role (REV -> R9, TEST -> T10). */
|
|
61
|
+
function oversightCode(attribution, role) {
|
|
62
|
+
switch (attribution.miss) {
|
|
63
|
+
case 'review_integration':
|
|
64
|
+
return role === 'REV' ? 'R9' : null;
|
|
65
|
+
case 'test_defect':
|
|
66
|
+
return role === 'TEST' ? 'T4' : null;
|
|
67
|
+
case 'test_boundary':
|
|
68
|
+
return role === 'TEST' ? 'T10' : null;
|
|
69
|
+
default:
|
|
70
|
+
if (role === 'REV')
|
|
71
|
+
return 'R9';
|
|
72
|
+
if (role === 'TEST')
|
|
73
|
+
return 'T10';
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function primaryDevCodes(attribution) {
|
|
78
|
+
const codes = ['D13'];
|
|
79
|
+
if (attribution.contract === 'producer')
|
|
80
|
+
codes.push('D14');
|
|
81
|
+
if (attribution.contract === 'consumer_unverified')
|
|
82
|
+
codes.push('D15');
|
|
83
|
+
return codes;
|
|
84
|
+
}
|
|
85
|
+
/** Individual events for one accepted attribution; empty for report-only contributions. */
|
|
86
|
+
function individualCodes(accepted, notes) {
|
|
87
|
+
const { attribution, role } = accepted;
|
|
88
|
+
if (attribution.level === 'contributing')
|
|
89
|
+
return [];
|
|
90
|
+
if (attribution.level === 'primary' && role === 'DEV')
|
|
91
|
+
return primaryDevCodes(attribution);
|
|
92
|
+
const code = oversightCode(attribution, role);
|
|
93
|
+
if (code === null) {
|
|
94
|
+
notes.push(`${attribution.agentId} (${role}): no ${attribution.level} event applies.`);
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return [code];
|
|
98
|
+
}
|
|
99
|
+
function collectiveEvents(ctx, rca, primaryIds) {
|
|
100
|
+
const only = ctx.participants === undefined ? undefined : new Set(ctx.participants);
|
|
101
|
+
const members = activeAgents(ctx.state).filter((a) => only === undefined || only.has(a.id));
|
|
102
|
+
const events = [];
|
|
103
|
+
const first = rca.systemic ? 'C4' : 'C2';
|
|
104
|
+
for (const agent of members) {
|
|
105
|
+
const event = incidentEvent(ctx, first, agent.id, rca.systemic ? 'systemic failure' : '');
|
|
106
|
+
if (first === 'C2' && !primaryIds.has(agent.id))
|
|
107
|
+
event.relief = true;
|
|
108
|
+
events.push(event);
|
|
109
|
+
}
|
|
110
|
+
if (ctx.fixCycles >= 3) {
|
|
111
|
+
for (const agent of members) {
|
|
112
|
+
events.push(incidentEvent(ctx, 'C3', agent.id, `${ctx.fixCycles} fix cycles`));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return events;
|
|
116
|
+
}
|
|
117
|
+
function describeIndividual(accepted, codes) {
|
|
118
|
+
const { attribution } = accepted;
|
|
119
|
+
const weight = RCA_WEIGHTS[attribution.level];
|
|
120
|
+
const what = codes.length > 0
|
|
121
|
+
? codes.map((c) => `${c} ${eventDef(c).delta}`).join(', ')
|
|
122
|
+
: 'report only (no event)';
|
|
123
|
+
return `${attribution.agentId} (${attribution.level}, weight ${weight}): ${what}`;
|
|
124
|
+
}
|
|
125
|
+
function describeCollective(rca, fixCycles, hasPrimary) {
|
|
126
|
+
const lines = [];
|
|
127
|
+
if (rca.systemic)
|
|
128
|
+
lines.push('Collective: C4 -15 for every active agent (replaces C2).');
|
|
129
|
+
else if (hasPrimary)
|
|
130
|
+
lines.push('Collective: C2 -5 for primary agents, -2 for everyone else.');
|
|
131
|
+
else
|
|
132
|
+
lines.push('Collective: C2 -2 for everyone (no primary attribution).');
|
|
133
|
+
if (fixCycles >= 3) {
|
|
134
|
+
lines.push(`Collective: C3 -10 for every active agent (${fixCycles} fix cycles).`);
|
|
135
|
+
}
|
|
136
|
+
return lines;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Expand a structured RCA into ledger events (5.7 step 3):
|
|
140
|
+
*
|
|
141
|
+
* - primary DEV -> D13 -25, plus D14 -20 (producer) and/or D15 -10 (consumer_unverified);
|
|
142
|
+
* - oversight -> R9 -20 (review_integration), T4 -15 (test_defect), T10 -15
|
|
143
|
+
* (test_boundary); a missing `miss` defaults by role (REV R9, TEST T10);
|
|
144
|
+
* - contributing -> reported with weight 0.3, no event of its own;
|
|
145
|
+
* - everyone active -> C2 -5 (-2 for non-primary) or, when systemic, C4 -15 instead;
|
|
146
|
+
* - fix cycles >= 3 -> C3 -10 for everyone;
|
|
147
|
+
* - every primary has the phase's escrow clawed back.
|
|
148
|
+
*
|
|
149
|
+
* `boundary = false` is an individual bug: nothing is booked.
|
|
150
|
+
*/
|
|
151
|
+
export function expandRca(rca, ctx) {
|
|
152
|
+
const result = {
|
|
153
|
+
individualDefect: !rca.boundary,
|
|
154
|
+
events: [],
|
|
155
|
+
clawbacks: [],
|
|
156
|
+
weights: [],
|
|
157
|
+
skipped: [],
|
|
158
|
+
breakdown: [],
|
|
159
|
+
};
|
|
160
|
+
if (!rca.boundary) {
|
|
161
|
+
result.breakdown.push(INDIVIDUAL_DEFECT_TEXT);
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
const accepted = acceptAttributions(ctx, rca.attributions, result.skipped);
|
|
165
|
+
const primaryIds = new Set();
|
|
166
|
+
for (const item of accepted) {
|
|
167
|
+
const { agentId, level } = item.attribution;
|
|
168
|
+
result.weights.push({ agentId, level, weight: RCA_WEIGHTS[level] });
|
|
169
|
+
const codes = individualCodes(item, result.skipped);
|
|
170
|
+
for (const code of codes) {
|
|
171
|
+
result.events.push(incidentEvent(ctx, code, agentId, item.attribution.note));
|
|
172
|
+
}
|
|
173
|
+
if (level === 'primary') {
|
|
174
|
+
primaryIds.add(agentId);
|
|
175
|
+
result.clawbacks.push({
|
|
176
|
+
agentId,
|
|
177
|
+
phase: ctx.phase,
|
|
178
|
+
reason: `RCA ${ctx.incidentId}: primary cause, escrow clawed back`,
|
|
179
|
+
incidentId: ctx.incidentId,
|
|
180
|
+
at: ctx.at,
|
|
181
|
+
by: ctx.by,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
result.breakdown.push(describeIndividual(item, codes));
|
|
185
|
+
}
|
|
186
|
+
result.events.push(...collectiveEvents(ctx, rca, primaryIds));
|
|
187
|
+
result.breakdown.push(...describeCollective(rca, ctx.fixCycles, primaryIds.size > 0));
|
|
188
|
+
if (primaryIds.size > 0) {
|
|
189
|
+
result.breakdown.push(`Clawback of phase escrow: ${[...primaryIds].join(', ')}.`);
|
|
190
|
+
}
|
|
191
|
+
for (const line of result.skipped)
|
|
192
|
+
result.breakdown.push(`Skipped - ${line}`);
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Report lines AFTER booking: what the cap actually did. The inspector must state any
|
|
197
|
+
* `capped` row in the settle summary (AC-17), so the engine hands it ready-made text.
|
|
198
|
+
*/
|
|
199
|
+
export function summarizeIncident(outcome) {
|
|
200
|
+
const lines = [];
|
|
201
|
+
for (const o of outcome.outcomes) {
|
|
202
|
+
const entry = o.entry;
|
|
203
|
+
if (entry?.capped !== undefined) {
|
|
204
|
+
const { requested, applied } = entry.capped;
|
|
205
|
+
lines.push(`CAPPED ${entry.code}: requested ${requested}, applied ${applied}.`);
|
|
206
|
+
}
|
|
207
|
+
if (o.rejected !== undefined)
|
|
208
|
+
lines.push(`REJECTED: ${o.rejected.message}`);
|
|
209
|
+
if (o.eliminated)
|
|
210
|
+
lines.push('An agent was eliminated by this incident (confirmed reached 0).');
|
|
211
|
+
}
|
|
212
|
+
for (const c of outcome.clawbacks) {
|
|
213
|
+
if (c.requested > 0) {
|
|
214
|
+
lines.push(c.capped
|
|
215
|
+
? `CAPPED CLAWBACK: ${c.clawed} of ${c.requested} reclaimed.`
|
|
216
|
+
: `Clawback: ${c.clawed} reclaimed.`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return lines;
|
|
220
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mechanical settlement - structured verdicts -> automatic bookings and routing
|
|
3
|
+
* (governance-mode 5.5).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY (`governance/` is glyph-scanned).
|
|
6
|
+
*
|
|
7
|
+
* Every function here is a PURE DECISION: it returns the events to book, the next route
|
|
8
|
+
* for the work package and any claims to open, and touches no state. The engine books the
|
|
9
|
+
* events through the ledger (I-G7: one accounting path) and applies the route.
|
|
10
|
+
*
|
|
11
|
+
* VALIDATION BEFORE ACCOUNTING (D-15). A submission that is incomplete or contradicts
|
|
12
|
+
* itself comes back as a `refusal` with NOTHING booked and no route - the child fixes the
|
|
13
|
+
* submission and tries again. A refusal text starts with `NOT ACCEPTED:` and says what is
|
|
14
|
+
* wrong and how to fix it; it is plain text, never an error, because an error would trip
|
|
15
|
+
* the model's retry loop. The tool layer decides how many refusals a child gets.
|
|
16
|
+
*/
|
|
17
|
+
import type { Claim, Contract, LedgerState, ReviewFinding, ReviewSubmission, TestSubmission, WorkPackage, WorkSubmission } from '../types.js';
|
|
18
|
+
import { type EventCode } from './events-table.js';
|
|
19
|
+
import { type LedgerEvent } from './ledger.js';
|
|
20
|
+
export interface SettlementContext {
|
|
21
|
+
wp: Pick<WorkPackage, 'id' | 'assignee' | 'reviewer' | 'tester' | 'rejections' | 'files'>;
|
|
22
|
+
contracts: readonly Contract[];
|
|
23
|
+
phase: number;
|
|
24
|
+
/** Time of the submission; events carry it so replay never reads a clock. */
|
|
25
|
+
at: number;
|
|
26
|
+
/** Finding ids the DEV appealed last round: the reviewer MUST answer each (L1). */
|
|
27
|
+
appealFindingIds?: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
export interface RequiredChange {
|
|
30
|
+
file: string;
|
|
31
|
+
issue: string;
|
|
32
|
+
change: string;
|
|
33
|
+
}
|
|
34
|
+
/** Where the work package goes next. */
|
|
35
|
+
export type WpRoute = {
|
|
36
|
+
to: 'review';
|
|
37
|
+
} | {
|
|
38
|
+
to: 'test';
|
|
39
|
+
} | {
|
|
40
|
+
to: 'passed';
|
|
41
|
+
} | {
|
|
42
|
+
to: 'dev';
|
|
43
|
+
requiredChanges: RequiredChange[];
|
|
44
|
+
};
|
|
45
|
+
/** Strike a previously booked deduction (an upheld-then-withdrawn D5). */
|
|
46
|
+
export interface ReversalRequest {
|
|
47
|
+
agentId: string;
|
|
48
|
+
code: EventCode;
|
|
49
|
+
wpId: string;
|
|
50
|
+
reason: string;
|
|
51
|
+
}
|
|
52
|
+
/** One rejection (a NEEDS_REWORK review), kept so R2 can be paid at settle time. */
|
|
53
|
+
export interface RejectionRecord {
|
|
54
|
+
id: string;
|
|
55
|
+
wpId: string;
|
|
56
|
+
reviewer: string;
|
|
57
|
+
hasBlockerOrMajor: boolean;
|
|
58
|
+
withdrawn: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface SettlementResult {
|
|
61
|
+
/** False => a validation refusal: nothing is booked, no route. */
|
|
62
|
+
ok: boolean;
|
|
63
|
+
refusal: string | null;
|
|
64
|
+
events: LedgerEvent[];
|
|
65
|
+
route: WpRoute | null;
|
|
66
|
+
claims: Claim[];
|
|
67
|
+
reversals: ReversalRequest[];
|
|
68
|
+
/** Fingerprints to append to `wp.rejections` (D8 detection on the next rejection). */
|
|
69
|
+
newRejections: string[];
|
|
70
|
+
rejection: RejectionRecord | null;
|
|
71
|
+
notes: string[];
|
|
72
|
+
}
|
|
73
|
+
/** The findings that make a rework mandatory: blocker, major or flagged `mustFix`. */
|
|
74
|
+
export declare function blockingFindings(findings: readonly ReviewFinding[]): ReviewFinding[];
|
|
75
|
+
/** The only feedback surface a DEV sees (D-7): one row per blocking finding. */
|
|
76
|
+
export declare function deriveRequiredChanges(findings: readonly ReviewFinding[]): RequiredChange[];
|
|
77
|
+
/**
|
|
78
|
+
* A DEV submission: route to review, flag D17 (scope narrowing) on the mechanical
|
|
79
|
+
* signature, and report files touched outside the WP's ownership (evidence only).
|
|
80
|
+
* D17 is appealable once; the booking carries that in its reason.
|
|
81
|
+
*/
|
|
82
|
+
export declare function settleWork(ctx: SettlementContext, submission: WorkSubmission): SettlementResult;
|
|
83
|
+
/**
|
|
84
|
+
* A REVIEW submission. PASS -> D1 (+15 P) -> test; PASS_WITH_FIXES -> D2 (+5 P) -> test;
|
|
85
|
+
* NEEDS_REWORK -> D5 (-20) -> dev, plus D8 (-30) when a blocking finding repeats an
|
|
86
|
+
* earlier rejection. A withdrawn appeal finding books R5 on the reviewer and strikes the
|
|
87
|
+
* earlier D5 (one R5 per submission, not per finding, so withdrawing is not a punishment
|
|
88
|
+
* multiplier). R12 is checked on every verdict.
|
|
89
|
+
*/
|
|
90
|
+
export declare function settleReview(ctx: SettlementContext, sub: ReviewSubmission): SettlementResult;
|
|
91
|
+
/** True when a traceability row names a real requirement (not a placeholder). */
|
|
92
|
+
export declare function isConcreteRequirement(text: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* A TEST submission. ALL_PASS -> D3, and when every traceability row is covered D4 + T1;
|
|
95
|
+
* SPEC_MISMATCH -> D7 (needs a real `gap` row); INCOMPLETE_IMPL -> D9, or D11 instead when
|
|
96
|
+
* the skeleton ratio is above 0.30 with evidence; ISSUES_FOUND books nothing itself. Any
|
|
97
|
+
* `unverified` row books T6 on the tester. Claims are opened, never booked here.
|
|
98
|
+
*/
|
|
99
|
+
export declare function settleTest(ctx: SettlementContext, sub: TestSubmission): SettlementResult;
|
|
100
|
+
export interface PhaseSettleInput {
|
|
101
|
+
/** Used only to make the stage idempotent (a re-run books nothing twice). */
|
|
102
|
+
state: LedgerState;
|
|
103
|
+
phase: number;
|
|
104
|
+
at: number;
|
|
105
|
+
/** WPs whose review passed, with the reviewer who passed them. */
|
|
106
|
+
reviewedWps: ReadonlyArray<{
|
|
107
|
+
wpId: string;
|
|
108
|
+
reviewer: string;
|
|
109
|
+
}>;
|
|
110
|
+
/** WPs that reached ALL_PASS. */
|
|
111
|
+
testedOkWpIds: readonly string[];
|
|
112
|
+
/** Every claim of the run; only this phase's are considered. */
|
|
113
|
+
claims: readonly Claim[];
|
|
114
|
+
rejections: readonly RejectionRecord[];
|
|
115
|
+
}
|
|
116
|
+
export interface PhaseSettleResult {
|
|
117
|
+
events: LedgerEvent[];
|
|
118
|
+
notes: string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* R1 and R2, which can only be decided once the phase's claims are ruled.
|
|
122
|
+
*
|
|
123
|
+
* - R1 +10 (P): a WP passed review and no missed-defect / incomplete-impl claim against
|
|
124
|
+
* that review was upheld. A still-open claim defers R1 (never pay before the ruling).
|
|
125
|
+
* - R2 +10: a rejection with a blocker/major finding that was not withdrawn or overturned,
|
|
126
|
+
* and whose WP later reached ALL_PASS - rework confirmed the problem was real. Paid
|
|
127
|
+
* once per rejection (`r2:<review id>`), which is what stops a reviewer farming it.
|
|
128
|
+
*/
|
|
129
|
+
export declare function settlePhaseR1R2(input: PhaseSettleInput): PhaseSettleResult;
|