ex-workflow 1.2.0 → 1.4.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/CHANGELOG.md +46 -0
- package/README.md +147 -13
- package/dist/adapters/index.cjs +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.mjs +1 -1
- package/dist/{budget-Gckmqj74.d.ts → budget-BuQ9GWsg.d.ts} +1 -1
- package/dist/{budget-Bm839Qw0.d.cts → budget-DDqQQIgp.d.cts} +1 -1
- package/dist/{chunk-LIATP6LY.mjs → chunk-3QUIRAXO.mjs} +2 -2
- package/dist/{chunk-LIATP6LY.mjs.map → chunk-3QUIRAXO.mjs.map} +1 -1
- package/dist/chunk-3RJ4RNPG.cjs +2 -0
- package/dist/chunk-3RJ4RNPG.cjs.map +1 -0
- package/dist/chunk-66BO7JFR.cjs +2 -0
- package/dist/chunk-66BO7JFR.cjs.map +1 -0
- package/dist/chunk-6PFJYRM7.cjs +2 -0
- package/dist/chunk-6PFJYRM7.cjs.map +1 -0
- package/dist/chunk-76ITDJDM.cjs +2 -0
- package/dist/{chunk-QAENYYU6.cjs.map → chunk-76ITDJDM.cjs.map} +1 -1
- package/dist/chunk-AWFR3Q4M.mjs +2 -0
- package/dist/{chunk-32NVJV5C.mjs.map → chunk-AWFR3Q4M.mjs.map} +1 -1
- package/dist/chunk-BD665RYK.mjs +2 -0
- package/dist/chunk-BD665RYK.mjs.map +1 -0
- package/dist/chunk-BGKXIRGS.mjs +2 -0
- package/dist/chunk-BGKXIRGS.mjs.map +1 -0
- package/dist/chunk-BNKKOAMP.mjs +2 -0
- package/dist/{chunk-OZAYOPLB.mjs.map → chunk-BNKKOAMP.mjs.map} +1 -1
- package/dist/{chunk-IIEKK2S3.cjs → chunk-CPM2SPDX.cjs} +2 -2
- package/dist/{chunk-IIEKK2S3.cjs.map → chunk-CPM2SPDX.cjs.map} +1 -1
- package/dist/chunk-DVFTTBCT.cjs +3 -0
- package/dist/chunk-DVFTTBCT.cjs.map +1 -0
- package/dist/{chunk-U3RU5LOF.cjs → chunk-G6QELJRL.cjs} +2 -2
- package/dist/{chunk-U3RU5LOF.cjs.map → chunk-G6QELJRL.cjs.map} +1 -1
- package/dist/{chunk-6D6FL3XK.mjs → chunk-HXEJP6KF.mjs} +2 -2
- package/dist/{chunk-6D6FL3XK.mjs.map → chunk-HXEJP6KF.mjs.map} +1 -1
- package/dist/chunk-ILNSTPPV.mjs +2 -0
- package/dist/chunk-ILNSTPPV.mjs.map +1 -0
- package/dist/{chunk-RXY434DX.cjs → chunk-KA6DVHO5.cjs} +4 -4
- package/dist/{chunk-RXY434DX.cjs.map → chunk-KA6DVHO5.cjs.map} +1 -1
- package/dist/chunk-KLOSFZFK.cjs +2 -0
- package/dist/chunk-KLOSFZFK.cjs.map +1 -0
- package/dist/chunk-LQJPLXFR.cjs +2 -0
- package/dist/chunk-LQJPLXFR.cjs.map +1 -0
- package/dist/chunk-MUQ4FKVH.mjs +2 -0
- package/dist/chunk-MUQ4FKVH.mjs.map +1 -0
- package/dist/chunk-N2NANHRW.mjs +2 -0
- package/dist/{chunk-4HG6A3SF.mjs.map → chunk-N2NANHRW.mjs.map} +1 -1
- package/dist/chunk-NNQ3RHDP.mjs +2 -0
- package/dist/chunk-NNQ3RHDP.mjs.map +1 -0
- package/dist/chunk-OAJ4KV4F.mjs +2 -0
- package/dist/{chunk-BYPFTO7P.mjs.map → chunk-OAJ4KV4F.mjs.map} +1 -1
- package/dist/chunk-OFFQTZEY.cjs +2 -0
- package/dist/chunk-OFFQTZEY.cjs.map +1 -0
- package/dist/{chunk-3GKYL6VB.mjs → chunk-ONVAUZOD.mjs} +3 -3
- package/dist/{chunk-3GKYL6VB.mjs.map → chunk-ONVAUZOD.mjs.map} +1 -1
- package/dist/chunk-QJMOCISZ.mjs +3 -0
- package/dist/chunk-QJMOCISZ.mjs.map +1 -0
- package/dist/chunk-QKW26EV2.mjs +2 -0
- package/dist/chunk-QKW26EV2.mjs.map +1 -0
- package/dist/{chunk-W2P27645.cjs → chunk-RMXEQ5HN.cjs} +2 -2
- package/dist/{chunk-W2P27645.cjs.map → chunk-RMXEQ5HN.cjs.map} +1 -1
- package/dist/chunk-TBLIZIWH.cjs +2 -0
- package/dist/chunk-TBLIZIWH.cjs.map +1 -0
- package/dist/chunk-U23IRPFF.cjs +2 -0
- package/dist/{chunk-SFYUJQYW.cjs.map → chunk-U23IRPFF.cjs.map} +1 -1
- package/dist/chunk-WM3JM3H7.mjs +2 -0
- package/dist/chunk-WM3JM3H7.mjs.map +1 -0
- package/dist/chunk-WU5JELOM.mjs +2 -0
- package/dist/chunk-WU5JELOM.mjs.map +1 -0
- package/dist/chunk-YNYIHJOC.mjs +2 -0
- package/dist/chunk-YNYIHJOC.mjs.map +1 -0
- package/dist/chunk-YRXFEM3F.cjs +2 -0
- package/dist/chunk-YRXFEM3F.cjs.map +1 -0
- package/dist/{chunk-K4VSMIJZ.cjs → chunk-ZDT2BZGU.cjs} +2 -2
- package/dist/{chunk-K4VSMIJZ.cjs.map → chunk-ZDT2BZGU.cjs.map} +1 -1
- package/dist/{chunk-OVR5CK3R.cjs → chunk-ZK3V66NC.cjs} +2 -2
- package/dist/{chunk-OVR5CK3R.cjs.map → chunk-ZK3V66NC.cjs.map} +1 -1
- package/dist/cli/bin.cjs +1 -1
- package/dist/cli/bin.cjs.map +1 -1
- package/dist/cli/bin.mjs +1 -1
- package/dist/cli/bin.mjs.map +1 -1
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/experimentation/index.cjs +1 -1
- package/dist/experimentation/index.d.cts +2 -2
- package/dist/experimentation/index.d.ts +2 -2
- package/dist/experimentation/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -12
- package/dist/index.d.ts +15 -12
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/investigation/index.cjs +1 -1
- package/dist/investigation/index.d.cts +2 -2
- package/dist/investigation/index.d.ts +2 -2
- package/dist/investigation/index.mjs +1 -1
- package/dist/kanban/index.cjs +1 -1
- package/dist/kanban/index.d.cts +1 -1
- package/dist/kanban/index.d.ts +1 -1
- package/dist/kanban/index.mjs +1 -1
- package/dist/policies/index.cjs +2 -0
- package/dist/policies/index.cjs.map +1 -0
- package/dist/policies/index.d.cts +202 -0
- package/dist/policies/index.d.ts +202 -0
- package/dist/policies/index.mjs +2 -0
- package/dist/policies/index.mjs.map +1 -0
- package/dist/registry/index.cjs +1 -1
- package/dist/registry/index.d.cts +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.mjs +1 -1
- package/dist/schema/index.cjs +1 -1
- package/dist/schema/index.mjs +1 -1
- package/dist/scrum/index.cjs +1 -1
- package/dist/scrum/index.d.cts +3 -3
- package/dist/scrum/index.d.ts +3 -3
- package/dist/scrum/index.mjs +1 -1
- package/dist/{types-DjePDfms.d.cts → types-DLOtndDY.d.cts} +61 -1
- package/dist/{types-DjePDfms.d.ts → types-DLOtndDY.d.ts} +61 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/waterfall/index.cjs +1 -1
- package/dist/waterfall/index.d.cts +1 -1
- package/dist/waterfall/index.d.ts +1 -1
- package/dist/waterfall/index.mjs +1 -1
- package/package.json +14 -1
- package/dist/chunk-32NVJV5C.mjs +0 -2
- package/dist/chunk-3O5MPAJT.cjs +0 -2
- package/dist/chunk-3O5MPAJT.cjs.map +0 -1
- package/dist/chunk-43GLYYA2.cjs +0 -3
- package/dist/chunk-43GLYYA2.cjs.map +0 -1
- package/dist/chunk-4HG6A3SF.mjs +0 -2
- package/dist/chunk-7EF47R2J.mjs +0 -2
- package/dist/chunk-7EF47R2J.mjs.map +0 -1
- package/dist/chunk-BD76VFI4.mjs +0 -3
- package/dist/chunk-BD76VFI4.mjs.map +0 -1
- package/dist/chunk-BHAEPYRJ.cjs +0 -2
- package/dist/chunk-BHAEPYRJ.cjs.map +0 -1
- package/dist/chunk-BYPFTO7P.mjs +0 -2
- package/dist/chunk-FDZB73PH.mjs +0 -2
- package/dist/chunk-FDZB73PH.mjs.map +0 -1
- package/dist/chunk-JNLWI4JM.mjs +0 -2
- package/dist/chunk-JNLWI4JM.mjs.map +0 -1
- package/dist/chunk-LCN4UNYK.cjs +0 -2
- package/dist/chunk-LCN4UNYK.cjs.map +0 -1
- package/dist/chunk-MB465DI4.mjs +0 -2
- package/dist/chunk-MB465DI4.mjs.map +0 -1
- package/dist/chunk-OZAYOPLB.mjs +0 -2
- package/dist/chunk-QAENYYU6.cjs +0 -2
- package/dist/chunk-SFYUJQYW.cjs +0 -2
- package/dist/chunk-UUWDQVIJ.mjs +0 -2
- package/dist/chunk-UUWDQVIJ.mjs.map +0 -1
- package/dist/chunk-VXOZIP77.cjs +0 -2
- package/dist/chunk-VXOZIP77.cjs.map +0 -1
- package/dist/chunk-WPVL27G4.mjs +0 -2
- package/dist/chunk-WPVL27G4.mjs.map +0 -1
- package/dist/chunk-Z43GUETW.cjs +0 -2
- package/dist/chunk-Z43GUETW.cjs.map +0 -1
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { G as GateRequirement, W as WorkflowState, l as WorkItem, m as Gate, n as GateEscalation, M as Methodology, o as ApplyResult, p as ContextAssumption, q as BriefContext, V as Violation } from '../types-DLOtndDY.cjs';
|
|
2
|
+
|
|
3
|
+
type RiskLevel = "low" | "medium" | "high" | "critical";
|
|
4
|
+
/** `data` of a `risk-assessment` evidence entry. */
|
|
5
|
+
interface RiskAssessmentData {
|
|
6
|
+
level: RiskLevel;
|
|
7
|
+
/** Free strings naming what drives the risk, e.g. `ci-cd`, `prod-infra`, `secrets`, `blast-radius`, `irreversible`. */
|
|
8
|
+
factors: string[];
|
|
9
|
+
/** The item SHA or ref that was assessed. */
|
|
10
|
+
subject?: string;
|
|
11
|
+
}
|
|
12
|
+
/** What each level ADDS to the static gate. */
|
|
13
|
+
type RiskTable = Record<RiskLevel, {
|
|
14
|
+
requires: GateRequirement[];
|
|
15
|
+
evidence?: string[];
|
|
16
|
+
}>;
|
|
17
|
+
interface RiskGateOptions {
|
|
18
|
+
/** Ids of the gates the policy applies to; every other gate stays static. */
|
|
19
|
+
gates: string[];
|
|
20
|
+
/** Default `DEFAULT_RISK_TABLE`. */
|
|
21
|
+
table?: RiskTable;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `low` and `medium` add nothing; `high` and `critical` add a human approval. Deeply frozen. */
|
|
25
|
+
declare const DEFAULT_RISK_TABLE: RiskTable;
|
|
26
|
+
/**
|
|
27
|
+
* The escalation of `gate` for `item` under `options` (the `escalateGate` hook `withRiskGate`
|
|
28
|
+
* installs): `undefined` for a gate not in `options.gates`, else the table row of the resolved
|
|
29
|
+
* level. The resolved level is the strictest fresh (post-rework) valid assessment, so a later,
|
|
30
|
+
* lower assessment never relaxes an earlier one; with none it is `critical`, and `reason.why` says
|
|
31
|
+
* whether assessments were `missing`, `invalid` or `not-independent` (the latest rejected one).
|
|
32
|
+
* Invalid options fail `invalid-input` as in `withRiskGate`, never a `TypeError`. Pure: no clock,
|
|
33
|
+
* no randomness; the same state gives the same answer.
|
|
34
|
+
*/
|
|
35
|
+
declare function riskEscalation(state: WorkflowState<string>, item: WorkItem, gate: Gate, options: RiskGateOptions): GateEscalation | undefined;
|
|
36
|
+
|
|
37
|
+
interface RiskAssessmentInput {
|
|
38
|
+
item: string;
|
|
39
|
+
level: RiskLevel;
|
|
40
|
+
factors: string[];
|
|
41
|
+
/** The host's assessment artifact. */
|
|
42
|
+
ref: string;
|
|
43
|
+
/** The item SHA or ref that was assessed. */
|
|
44
|
+
subject?: string;
|
|
45
|
+
/** The assessor: `human` or a role with capability `verify` that did not do the work. */
|
|
46
|
+
by: string;
|
|
47
|
+
now?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Records a risk assessment of an item as evidence `risk-assessment` with `data: { level, factors,
|
|
51
|
+
* subject? }` (design spec section 27, #35), through `applyAction` (action `risk.assess`) so the
|
|
52
|
+
* methodology's rules see it. Refuses `invalid-input` for an unknown key, an unknown level, a
|
|
53
|
+
* non-string factor, an empty ref, an assessor that is neither `human` nor a role with `verify`, and
|
|
54
|
+
* an assessor that is the item's author or assigned role.
|
|
55
|
+
*/
|
|
56
|
+
declare function recordRiskAssessment<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: RiskAssessmentInput): ApplyResult<N>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `methodology` with the risk-adaptive gate policy (design spec section 27, #35): for each gate in
|
|
60
|
+
* `options.gates`, `complete()` adds the requirements of the row of `options.table` (default
|
|
61
|
+
* `DEFAULT_RISK_TABLE`) that the item's strictest fresh, valid, independent risk assessment picks,
|
|
62
|
+
* `critical` when there is none. An `escalateGate` the methodology already has is kept: both widen
|
|
63
|
+
* the gate. Invalid options fail `invalid-input` here, once.
|
|
64
|
+
*/
|
|
65
|
+
declare function withRiskGate<C, N extends string>(methodology: Methodology<C, N>, options: RiskGateOptions): Methodology<C, N>;
|
|
66
|
+
interface ContextGroundingOptions {
|
|
67
|
+
/** Stage ids whose entry policies gain the custom policy `context-grounded`. */
|
|
68
|
+
entry: string[];
|
|
69
|
+
/** Stage ids whose exit policies gain it. */
|
|
70
|
+
exit?: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* `methodology` with the context-grounded policy (design spec section 27, #36): `defaultStages`
|
|
74
|
+
* adds the custom policy `context-grounded` to the entry policies of the `entry` stages and the
|
|
75
|
+
* exit policies of the `exit` stages (an unknown stage id fails `invalid-input` there), and
|
|
76
|
+
* `plan()`/`complete()` answer it with `contextGroundedViolations`; `synthesizeBrief` carries
|
|
77
|
+
* `contextOf` as `Brief.context`. Hooks the methodology already has answer every other policy id
|
|
78
|
+
* and a brief with no snapshot. Invalid options fail `invalid-input` here, once.
|
|
79
|
+
*/
|
|
80
|
+
declare function withContextGrounding<C, N extends string>(methodology: Methodology<C, N>, options: ContextGroundingOptions): Methodology<C, N>;
|
|
81
|
+
|
|
82
|
+
interface ContextSnapshotInput {
|
|
83
|
+
item: string;
|
|
84
|
+
/** The repository revision the snapshot was taken at. */
|
|
85
|
+
revision: string;
|
|
86
|
+
assumptions: ContextAssumption[];
|
|
87
|
+
/** The host's snapshot artifact. */
|
|
88
|
+
ref: string;
|
|
89
|
+
/** Who recorded it: `human` or a registered role that did not work on the item. */
|
|
90
|
+
by: string;
|
|
91
|
+
now?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The item's current context (design spec section 27, #36): its latest fresh (post-rework)
|
|
95
|
+
* qualifying `context-snapshot` evidence (valid data with at least one sourced assumption,
|
|
96
|
+
* recorded by `human` or a registered role that did not work on the item, `workersOf`), with
|
|
97
|
+
* `stale` the cited source paths a later `repo.changed` event listed (exact match, in event order)
|
|
98
|
+
* and `unverified` the claims with no source; `undefined` when there is none. The `required`
|
|
99
|
+
* claims of every other valid fresh snapshot (earlier or later, whoever recorded it) carry (spec 28, #49): reported
|
|
100
|
+
* `required: true` when the latest has the claim, appended as `{ claim, required: true }` (no
|
|
101
|
+
* source, so unverified) when it lacks it; claims compare by exact text. The answer is a
|
|
102
|
+
* copy. Each evidence entry is located at its own `item.evidence` event, matched from the end as
|
|
103
|
+
* `freshEvidence` does; an entry with no event counts as older than every event.
|
|
104
|
+
*/
|
|
105
|
+
declare function contextOf(state: WorkflowState<string>, item: WorkItem): BriefContext | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Records a context snapshot of an item as evidence `context-snapshot` with `data: { revision,
|
|
108
|
+
* assumptions }` (design spec section 27, #36), through `applyAction` (action `context.snapshot`)
|
|
109
|
+
* so the methodology's rules see it. Refuses `invalid-input` for an unknown key, an empty revision,
|
|
110
|
+
* claim or ref, a source with a path that is not repository-relative POSIX or an empty hash,
|
|
111
|
+
* `lines` that are not two integers `1 <= from <= to`, no assumption with a source, and a `by`
|
|
112
|
+
* that is neither `human` nor a registered role or that worked on the item. The input is copied.
|
|
113
|
+
*/
|
|
114
|
+
declare function recordContextSnapshot<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: ContextSnapshotInput): ApplyResult<N>;
|
|
115
|
+
|
|
116
|
+
interface RepoChangeInput {
|
|
117
|
+
/** The new repository revision. */
|
|
118
|
+
revision: string;
|
|
119
|
+
/** Repository-relative POSIX paths the revision changed, as Git lists them. */
|
|
120
|
+
paths: string[];
|
|
121
|
+
by: string;
|
|
122
|
+
now?: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Records that `revision` changed `paths` (design spec section 27, #36): action `repo.change`
|
|
126
|
+
* through `applyAction`, event `repo.changed { revision, paths }` with the paths deduplicated in
|
|
127
|
+
* input order. No item status changes; `warnings` carries one `context-stale` warning per item in
|
|
128
|
+
* `in_progress`, `review` or `awaiting_human` whose context snapshot this change made stale (a
|
|
129
|
+
* cited path it changed that was not stale already). Refuses `invalid-input` for an unknown key,
|
|
130
|
+
* an empty revision, and paths that are not a non-empty array of repository-relative POSIX paths.
|
|
131
|
+
*/
|
|
132
|
+
declare function recordRepoChange<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: RepoChangeInput): ApplyResult<N>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Violations of the custom policy `context-grounded` for `item` (rule
|
|
136
|
+
* `policy:custom:context-grounded`, the 1.2 rule id of a custom policy): no qualifying fresh
|
|
137
|
+
* context snapshot (`contextOf`: valid, at least one sourced assumption, recorded by `human` or a
|
|
138
|
+
* registered role that did not work on the item); a stale one (names the changed paths); a
|
|
139
|
+
* `required` assumption without a source (names the claims). Empty when the item is grounded.
|
|
140
|
+
* Pure: the same state gives the same answer.
|
|
141
|
+
*/
|
|
142
|
+
declare function contextGroundedViolations(state: WorkflowState<string>, item: WorkItem): Violation[];
|
|
143
|
+
|
|
144
|
+
/** One finished run of one variant on one scenario. */
|
|
145
|
+
interface RunRecord {
|
|
146
|
+
variant: string;
|
|
147
|
+
scenario: string;
|
|
148
|
+
state: WorkflowState<string>;
|
|
149
|
+
/** The host scorer's verdict for this scenario run. */
|
|
150
|
+
passed: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface CompareRunsOptions {
|
|
153
|
+
/** The variant every other one is compared with. */
|
|
154
|
+
baseline: string;
|
|
155
|
+
/** Scenarios any failing run of which makes a variant ineligible. */
|
|
156
|
+
mustPass?: string[];
|
|
157
|
+
/** Pass-rate noise, a fraction in `[0, 1]` (default `0`). */
|
|
158
|
+
passTolerance?: number;
|
|
159
|
+
/** Token-cost noise, a fraction in `[0, 1]` (default `0`). */
|
|
160
|
+
costTolerance?: number;
|
|
161
|
+
}
|
|
162
|
+
interface RunMetrics {
|
|
163
|
+
tokens: number;
|
|
164
|
+
durationMs: number;
|
|
165
|
+
turns: number;
|
|
166
|
+
humanInterventions: number;
|
|
167
|
+
reworks: number;
|
|
168
|
+
escalations: number;
|
|
169
|
+
itemsDone: number;
|
|
170
|
+
}
|
|
171
|
+
interface VariantResult {
|
|
172
|
+
variant: string;
|
|
173
|
+
runs: number;
|
|
174
|
+
passed: number;
|
|
175
|
+
passRate: number;
|
|
176
|
+
mean: RunMetrics;
|
|
177
|
+
/** Must-pass scenarios with at least one failing run. */
|
|
178
|
+
regressions: string[];
|
|
179
|
+
/** Baseline or must-pass scenarios the variant never ran. */
|
|
180
|
+
missing: string[];
|
|
181
|
+
eligible: boolean;
|
|
182
|
+
}
|
|
183
|
+
interface RunComparison {
|
|
184
|
+
baseline: string;
|
|
185
|
+
/** Ranked: eligible first, then pass rate, tokens, duration, interventions, id. */
|
|
186
|
+
variants: VariantResult[];
|
|
187
|
+
winner: string | null;
|
|
188
|
+
reason: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Compares finished runs (design spec section 27, #34). Pure: reads only its arguments and
|
|
192
|
+
* returns fresh objects. Each variant gets a metric vector (the mean over its runs of tokens,
|
|
193
|
+
* duration, turns, human interventions, reworks, escalations and done items), a pass rate (the
|
|
194
|
+
* mean over its scenarios of each scenario's passing share, so every scenario weighs the same) and an
|
|
195
|
+
* eligibility (no must-pass regression, nothing missing). The winner is the first ranked eligible
|
|
196
|
+
* non-baseline variant that is not worse than the baseline on pass rate and better on pass rate
|
|
197
|
+
* or tokens, beyond the tolerances; otherwise `null` with the reason. Refuses `invalid-input`
|
|
198
|
+
* naming the offending value for malformed input, never a `TypeError`.
|
|
199
|
+
*/
|
|
200
|
+
declare function compareRuns(runs: readonly RunRecord[], options: CompareRunsOptions): RunComparison;
|
|
201
|
+
|
|
202
|
+
export { type CompareRunsOptions, type ContextGroundingOptions, type ContextSnapshotInput, DEFAULT_RISK_TABLE, type RepoChangeInput, type RiskAssessmentData, type RiskAssessmentInput, type RiskGateOptions, type RiskLevel, type RiskTable, type RunComparison, type RunMetrics, type RunRecord, type VariantResult, compareRuns, contextGroundedViolations, contextOf, recordContextSnapshot, recordRepoChange, recordRiskAssessment, riskEscalation, withContextGrounding, withRiskGate };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { G as GateRequirement, W as WorkflowState, l as WorkItem, m as Gate, n as GateEscalation, M as Methodology, o as ApplyResult, p as ContextAssumption, q as BriefContext, V as Violation } from '../types-DLOtndDY.js';
|
|
2
|
+
|
|
3
|
+
type RiskLevel = "low" | "medium" | "high" | "critical";
|
|
4
|
+
/** `data` of a `risk-assessment` evidence entry. */
|
|
5
|
+
interface RiskAssessmentData {
|
|
6
|
+
level: RiskLevel;
|
|
7
|
+
/** Free strings naming what drives the risk, e.g. `ci-cd`, `prod-infra`, `secrets`, `blast-radius`, `irreversible`. */
|
|
8
|
+
factors: string[];
|
|
9
|
+
/** The item SHA or ref that was assessed. */
|
|
10
|
+
subject?: string;
|
|
11
|
+
}
|
|
12
|
+
/** What each level ADDS to the static gate. */
|
|
13
|
+
type RiskTable = Record<RiskLevel, {
|
|
14
|
+
requires: GateRequirement[];
|
|
15
|
+
evidence?: string[];
|
|
16
|
+
}>;
|
|
17
|
+
interface RiskGateOptions {
|
|
18
|
+
/** Ids of the gates the policy applies to; every other gate stays static. */
|
|
19
|
+
gates: string[];
|
|
20
|
+
/** Default `DEFAULT_RISK_TABLE`. */
|
|
21
|
+
table?: RiskTable;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `low` and `medium` add nothing; `high` and `critical` add a human approval. Deeply frozen. */
|
|
25
|
+
declare const DEFAULT_RISK_TABLE: RiskTable;
|
|
26
|
+
/**
|
|
27
|
+
* The escalation of `gate` for `item` under `options` (the `escalateGate` hook `withRiskGate`
|
|
28
|
+
* installs): `undefined` for a gate not in `options.gates`, else the table row of the resolved
|
|
29
|
+
* level. The resolved level is the strictest fresh (post-rework) valid assessment, so a later,
|
|
30
|
+
* lower assessment never relaxes an earlier one; with none it is `critical`, and `reason.why` says
|
|
31
|
+
* whether assessments were `missing`, `invalid` or `not-independent` (the latest rejected one).
|
|
32
|
+
* Invalid options fail `invalid-input` as in `withRiskGate`, never a `TypeError`. Pure: no clock,
|
|
33
|
+
* no randomness; the same state gives the same answer.
|
|
34
|
+
*/
|
|
35
|
+
declare function riskEscalation(state: WorkflowState<string>, item: WorkItem, gate: Gate, options: RiskGateOptions): GateEscalation | undefined;
|
|
36
|
+
|
|
37
|
+
interface RiskAssessmentInput {
|
|
38
|
+
item: string;
|
|
39
|
+
level: RiskLevel;
|
|
40
|
+
factors: string[];
|
|
41
|
+
/** The host's assessment artifact. */
|
|
42
|
+
ref: string;
|
|
43
|
+
/** The item SHA or ref that was assessed. */
|
|
44
|
+
subject?: string;
|
|
45
|
+
/** The assessor: `human` or a role with capability `verify` that did not do the work. */
|
|
46
|
+
by: string;
|
|
47
|
+
now?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Records a risk assessment of an item as evidence `risk-assessment` with `data: { level, factors,
|
|
51
|
+
* subject? }` (design spec section 27, #35), through `applyAction` (action `risk.assess`) so the
|
|
52
|
+
* methodology's rules see it. Refuses `invalid-input` for an unknown key, an unknown level, a
|
|
53
|
+
* non-string factor, an empty ref, an assessor that is neither `human` nor a role with `verify`, and
|
|
54
|
+
* an assessor that is the item's author or assigned role.
|
|
55
|
+
*/
|
|
56
|
+
declare function recordRiskAssessment<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: RiskAssessmentInput): ApplyResult<N>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `methodology` with the risk-adaptive gate policy (design spec section 27, #35): for each gate in
|
|
60
|
+
* `options.gates`, `complete()` adds the requirements of the row of `options.table` (default
|
|
61
|
+
* `DEFAULT_RISK_TABLE`) that the item's strictest fresh, valid, independent risk assessment picks,
|
|
62
|
+
* `critical` when there is none. An `escalateGate` the methodology already has is kept: both widen
|
|
63
|
+
* the gate. Invalid options fail `invalid-input` here, once.
|
|
64
|
+
*/
|
|
65
|
+
declare function withRiskGate<C, N extends string>(methodology: Methodology<C, N>, options: RiskGateOptions): Methodology<C, N>;
|
|
66
|
+
interface ContextGroundingOptions {
|
|
67
|
+
/** Stage ids whose entry policies gain the custom policy `context-grounded`. */
|
|
68
|
+
entry: string[];
|
|
69
|
+
/** Stage ids whose exit policies gain it. */
|
|
70
|
+
exit?: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* `methodology` with the context-grounded policy (design spec section 27, #36): `defaultStages`
|
|
74
|
+
* adds the custom policy `context-grounded` to the entry policies of the `entry` stages and the
|
|
75
|
+
* exit policies of the `exit` stages (an unknown stage id fails `invalid-input` there), and
|
|
76
|
+
* `plan()`/`complete()` answer it with `contextGroundedViolations`; `synthesizeBrief` carries
|
|
77
|
+
* `contextOf` as `Brief.context`. Hooks the methodology already has answer every other policy id
|
|
78
|
+
* and a brief with no snapshot. Invalid options fail `invalid-input` here, once.
|
|
79
|
+
*/
|
|
80
|
+
declare function withContextGrounding<C, N extends string>(methodology: Methodology<C, N>, options: ContextGroundingOptions): Methodology<C, N>;
|
|
81
|
+
|
|
82
|
+
interface ContextSnapshotInput {
|
|
83
|
+
item: string;
|
|
84
|
+
/** The repository revision the snapshot was taken at. */
|
|
85
|
+
revision: string;
|
|
86
|
+
assumptions: ContextAssumption[];
|
|
87
|
+
/** The host's snapshot artifact. */
|
|
88
|
+
ref: string;
|
|
89
|
+
/** Who recorded it: `human` or a registered role that did not work on the item. */
|
|
90
|
+
by: string;
|
|
91
|
+
now?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The item's current context (design spec section 27, #36): its latest fresh (post-rework)
|
|
95
|
+
* qualifying `context-snapshot` evidence (valid data with at least one sourced assumption,
|
|
96
|
+
* recorded by `human` or a registered role that did not work on the item, `workersOf`), with
|
|
97
|
+
* `stale` the cited source paths a later `repo.changed` event listed (exact match, in event order)
|
|
98
|
+
* and `unverified` the claims with no source; `undefined` when there is none. The `required`
|
|
99
|
+
* claims of every other valid fresh snapshot (earlier or later, whoever recorded it) carry (spec 28, #49): reported
|
|
100
|
+
* `required: true` when the latest has the claim, appended as `{ claim, required: true }` (no
|
|
101
|
+
* source, so unverified) when it lacks it; claims compare by exact text. The answer is a
|
|
102
|
+
* copy. Each evidence entry is located at its own `item.evidence` event, matched from the end as
|
|
103
|
+
* `freshEvidence` does; an entry with no event counts as older than every event.
|
|
104
|
+
*/
|
|
105
|
+
declare function contextOf(state: WorkflowState<string>, item: WorkItem): BriefContext | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Records a context snapshot of an item as evidence `context-snapshot` with `data: { revision,
|
|
108
|
+
* assumptions }` (design spec section 27, #36), through `applyAction` (action `context.snapshot`)
|
|
109
|
+
* so the methodology's rules see it. Refuses `invalid-input` for an unknown key, an empty revision,
|
|
110
|
+
* claim or ref, a source with a path that is not repository-relative POSIX or an empty hash,
|
|
111
|
+
* `lines` that are not two integers `1 <= from <= to`, no assumption with a source, and a `by`
|
|
112
|
+
* that is neither `human` nor a registered role or that worked on the item. The input is copied.
|
|
113
|
+
*/
|
|
114
|
+
declare function recordContextSnapshot<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: ContextSnapshotInput): ApplyResult<N>;
|
|
115
|
+
|
|
116
|
+
interface RepoChangeInput {
|
|
117
|
+
/** The new repository revision. */
|
|
118
|
+
revision: string;
|
|
119
|
+
/** Repository-relative POSIX paths the revision changed, as Git lists them. */
|
|
120
|
+
paths: string[];
|
|
121
|
+
by: string;
|
|
122
|
+
now?: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Records that `revision` changed `paths` (design spec section 27, #36): action `repo.change`
|
|
126
|
+
* through `applyAction`, event `repo.changed { revision, paths }` with the paths deduplicated in
|
|
127
|
+
* input order. No item status changes; `warnings` carries one `context-stale` warning per item in
|
|
128
|
+
* `in_progress`, `review` or `awaiting_human` whose context snapshot this change made stale (a
|
|
129
|
+
* cited path it changed that was not stale already). Refuses `invalid-input` for an unknown key,
|
|
130
|
+
* an empty revision, and paths that are not a non-empty array of repository-relative POSIX paths.
|
|
131
|
+
*/
|
|
132
|
+
declare function recordRepoChange<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: RepoChangeInput): ApplyResult<N>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Violations of the custom policy `context-grounded` for `item` (rule
|
|
136
|
+
* `policy:custom:context-grounded`, the 1.2 rule id of a custom policy): no qualifying fresh
|
|
137
|
+
* context snapshot (`contextOf`: valid, at least one sourced assumption, recorded by `human` or a
|
|
138
|
+
* registered role that did not work on the item); a stale one (names the changed paths); a
|
|
139
|
+
* `required` assumption without a source (names the claims). Empty when the item is grounded.
|
|
140
|
+
* Pure: the same state gives the same answer.
|
|
141
|
+
*/
|
|
142
|
+
declare function contextGroundedViolations(state: WorkflowState<string>, item: WorkItem): Violation[];
|
|
143
|
+
|
|
144
|
+
/** One finished run of one variant on one scenario. */
|
|
145
|
+
interface RunRecord {
|
|
146
|
+
variant: string;
|
|
147
|
+
scenario: string;
|
|
148
|
+
state: WorkflowState<string>;
|
|
149
|
+
/** The host scorer's verdict for this scenario run. */
|
|
150
|
+
passed: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface CompareRunsOptions {
|
|
153
|
+
/** The variant every other one is compared with. */
|
|
154
|
+
baseline: string;
|
|
155
|
+
/** Scenarios any failing run of which makes a variant ineligible. */
|
|
156
|
+
mustPass?: string[];
|
|
157
|
+
/** Pass-rate noise, a fraction in `[0, 1]` (default `0`). */
|
|
158
|
+
passTolerance?: number;
|
|
159
|
+
/** Token-cost noise, a fraction in `[0, 1]` (default `0`). */
|
|
160
|
+
costTolerance?: number;
|
|
161
|
+
}
|
|
162
|
+
interface RunMetrics {
|
|
163
|
+
tokens: number;
|
|
164
|
+
durationMs: number;
|
|
165
|
+
turns: number;
|
|
166
|
+
humanInterventions: number;
|
|
167
|
+
reworks: number;
|
|
168
|
+
escalations: number;
|
|
169
|
+
itemsDone: number;
|
|
170
|
+
}
|
|
171
|
+
interface VariantResult {
|
|
172
|
+
variant: string;
|
|
173
|
+
runs: number;
|
|
174
|
+
passed: number;
|
|
175
|
+
passRate: number;
|
|
176
|
+
mean: RunMetrics;
|
|
177
|
+
/** Must-pass scenarios with at least one failing run. */
|
|
178
|
+
regressions: string[];
|
|
179
|
+
/** Baseline or must-pass scenarios the variant never ran. */
|
|
180
|
+
missing: string[];
|
|
181
|
+
eligible: boolean;
|
|
182
|
+
}
|
|
183
|
+
interface RunComparison {
|
|
184
|
+
baseline: string;
|
|
185
|
+
/** Ranked: eligible first, then pass rate, tokens, duration, interventions, id. */
|
|
186
|
+
variants: VariantResult[];
|
|
187
|
+
winner: string | null;
|
|
188
|
+
reason: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Compares finished runs (design spec section 27, #34). Pure: reads only its arguments and
|
|
192
|
+
* returns fresh objects. Each variant gets a metric vector (the mean over its runs of tokens,
|
|
193
|
+
* duration, turns, human interventions, reworks, escalations and done items), a pass rate (the
|
|
194
|
+
* mean over its scenarios of each scenario's passing share, so every scenario weighs the same) and an
|
|
195
|
+
* eligibility (no must-pass regression, nothing missing). The winner is the first ranked eligible
|
|
196
|
+
* non-baseline variant that is not worse than the baseline on pass rate and better on pass rate
|
|
197
|
+
* or tokens, beyond the tolerances; otherwise `null` with the reason. Refuses `invalid-input`
|
|
198
|
+
* naming the offending value for malformed input, never a `TypeError`.
|
|
199
|
+
*/
|
|
200
|
+
declare function compareRuns(runs: readonly RunRecord[], options: CompareRunsOptions): RunComparison;
|
|
201
|
+
|
|
202
|
+
export { type CompareRunsOptions, type ContextGroundingOptions, type ContextSnapshotInput, DEFAULT_RISK_TABLE, type RepoChangeInput, type RiskAssessmentData, type RiskAssessmentInput, type RiskGateOptions, type RiskLevel, type RiskTable, type RunComparison, type RunMetrics, type RunRecord, type VariantResult, compareRuns, contextGroundedViolations, contextOf, recordContextSnapshot, recordRepoChange, recordRiskAssessment, riskEscalation, withContextGrounding, withRiskGate };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a,c,e,f}from'../chunk-QKW26EV2.mjs';export{b as DEFAULT_RISK_TABLE,h as contextGroundedViolations,f as contextOf,g as recordContextSnapshot,d as riskEscalation,j as withContextGrounding,i as withRiskGate}from'../chunk-QKW26EV2.mjs';import'../chunk-C4ISBUZR.mjs';import'../chunk-WU5JELOM.mjs';import {s,g,V,A,c as c$1,a as a$1}from'../chunk-NNQ3RHDP.mjs';import {b as b$1,c as c$2}from'../chunk-YS6CXERQ.mjs';var L=["item","level","factors","ref","subject","by","now"],w=(s,e)=>b$1("invalid-input",`risk assessment: ${s}`,e);function os(s$1,e,a$1){(typeof a$1!="object"||a$1===null||Array.isArray(a$1))&&w("input must be an object",`pass { ${L.join(", ")} }`);for(let f of Object.keys(a$1))L.includes(f)||w(`unknown key "${f}"`,`use only: ${L.join(", ")}`);let{item:o,level:m,factors:i,ref:t,subject:l,by:r,now:d}=a$1;typeof o!="string"&&w("item must be an item id",'e.g. "item": "CART-12"');let p=s(s$1,o);a.includes(m)||w(`unknown level ${JSON.stringify(m)}`,`use one of: ${a.join(", ")}`),(!Array.isArray(i)||!i.every(f=>typeof f=="string"))&&w("factors must be an array of strings",'e.g. "factors": ["ci-cd", "secrets"]'),(typeof t!="string"||t.trim()==="")&&w("ref must be a non-empty string",'name the assessment artifact, e.g. "risk/CART-12.md"'),l!==void 0&&typeof l!="string"&&w("subject must be a string","pass the assessed SHA or ref, or omit it"),d!==void 0&&typeof d!="string"&&w("now must be an ISO timestamp string","omit now to use the clock"),(typeof r!="string"||r==="")&&w("by must name the assessor",'e.g. "by": "human"');let h=c(s$1,p,r);h==="invalid"&&w(`"${r}" may not assess risk (needs capability "verify")`,`assess as human or one of: ${g(s$1,"verify").map(f=>f.id).join(", ")||"(no role has verify; register one)"}`),h&&w(`"${r}" did the work on "${o}" and may not assess its risk`,"assess as human or an independent role with capability verify");let g$1={level:m,factors:[...i]};return l!==void 0&&(g$1.subject=l),V(s$1,e,{type:"risk.assess",by:r,payload:{item:o,ref:t,...g$1}},f=>A(f,o,{kind:"risk-assessment",ref:t,by:r,data:g$1},d))}var W=["revision","paths","by","now"],rs=["in_progress","review","awaiting_human"],S=(s,e)=>b$1("invalid-input",`repo change: ${s}`,e);function as(s,e$1,a){(typeof a!="object"||a===null||Array.isArray(a))&&S("input must be an object",`pass { ${W.join(", ")} }`);for(let p of Object.keys(a))W.includes(p)||S(`unknown key "${p}"`,`use only: ${W.join(", ")}`);let{revision:o,paths:m,by:i,now:t}=a;(typeof o!="string"||o.trim()==="")&&S("revision must be a non-empty string",'e.g. "revision": "4f2c1e0"'),(!Array.isArray(m)||m.length===0)&&S("paths must be a non-empty array of paths",'e.g. "paths": ["src/cart.ts"]'),m.forEach((p,h)=>{let g=e(p);g&&S(`paths[${h}] ${g}`,'send paths as `git diff --name-only -z` lists them (NUL-separated, unquoted; or with `-c core.quotePath=false`), e.g. "src/cart.ts"');}),(typeof i!="string"||i==="")&&S("by must name the reporter",'e.g. "by": "ci"'),t!==void 0&&typeof t!="string"&&S("now must be an ISO timestamp string","omit now to use the clock");let l=[...new Set(m)],r=V(s,e$1,{type:"repo.change",by:i,payload:{revision:o,paths:l}},p=>c$1(p,"repo.changed",i,{revision:o,paths:l},a$1(t))),d=[];for(let p of Object.values(r.state.items)){if(!rs.includes(p.status))continue;let h=f(s,p);if(!h)continue;let g=new Set(h.assumptions.map(R=>R.source?.path)),f$1=new Set(h.stale),v=l.filter(R=>g.has(R)&&!f$1.has(R));v.length&&d.push({rule:"context-stale",severity:"warning",item:p.id,message:`context snapshot "${h.snapshot}" of "${p.id}" is stale: ${v.join(", ")} changed at ${o}`,fix:`re-verify and record a fresh snapshot of "${p.id}" with recordContextSnapshot`});}return {state:r.state,warnings:[...r.warnings,...d]}}var z=["baseline","mustPass","passTolerance","costTolerance"],is=["tokens","durationMs","turns","humanInterventions","reworks","escalations","itemsDone"],u=(s,e)=>b$1("invalid-input",`compareRuns: ${s}`,e),b=s=>typeof s=="string"?JSON.stringify(s):typeof s=="object"&&s!==null?Array.isArray(s)?"an array":"an object":typeof s=="function"||typeof s=="symbol"?typeof s:String(s),j=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),y=(s,e)=>Object.hasOwn(s,e)?s[e]:void 0,D=(s,e)=>Number.isFinite(s)?s:u(`${e} is not finite (${s})`,"pass the host's measured usage figures"),T=(s,e)=>(typeof s!="string"&&u(`${e} is ${b(s)}, not an id`,'pass a string id such as "V0"'),c$2(s,e),s),B=(s,e)=>s===void 0?0:((typeof s!="number"||!Number.isFinite(s)||s<0||s>1)&&u(`${e} is ${b(s)}, not a fraction in [0, 1]`,`pass e.g. "${e}": 0.05`),s);function cs(s,e){if(!j(s))return u(`${e}.state is ${b(s)}, not a workflow state`,"pass the finished state.json");let[a,o,m]=["events","accounting","items"].map(t=>y(s,t));if(!Array.isArray(a)||!Array.isArray(o))return u(`${e}.state has no events and accounting arrays`,"pass a WorkflowState as loaded by loadState");if(!j(m))return u(`${e}.state.items is ${b(m)}, not an object`,"pass a WorkflowState as loaded by loadState");let i={tokens:0,durationMs:0,turns:o.length,humanInterventions:0,reworks:0,escalations:0,itemsDone:0};o.forEach((t,l)=>{if(!j(t))return u(`${e}.state.accounting[${l}] is ${b(t)}`,"pass accounting lines as recorded by complete");for(let r of ["tokensIn","tokensOut","durationMs"]){let d=y(t,r);(typeof d!="number"||!Number.isFinite(d)||d<0)&&u(`${e}.state.accounting[${l}].${r} is ${b(d)}, not a finite non-negative number`,"pass the host's measured usage figures");}i.tokens+=t.tokensIn+t.tokensOut,i.durationMs+=t.durationMs;}),D(i.tokens,`${e}.state token total`),D(i.durationMs,`${e}.state duration total`),a.forEach((t,l)=>{if(!j(t)||typeof y(t,"type")!="string")return u(`${e}.state.events[${l}] is ${b(t)}, not an event`,"pass events as recorded by the engine");let r=t.type;r==="pending.raised"||r==="blocker.cleared"?i.humanInterventions++:r==="item.rework"?i.reworks++:r==="item.escalated"&&i.escalations++;});for(let t of Object.values(m))j(t)&&y(t,"status")==="done"&&i.itemsDone++;return i}var Q=s=>s.sort((e,a)=>e-a).reduce((e,a)=>e+a,0)/s.length,_=(s,e)=>s<e?-1:s>e?1:0;function us(s,e){if(Array.isArray(s)||u(`runs is ${b(s)}, not an array`,"pass an array of { variant, scenario, state, passed }"),s.length===0&&u("no runs to compare","pass at least the baseline's finished runs"),!j(e))return u(`options is ${b(e)}, not an object`,'pass { baseline: "V0" }');for(let n of Object.keys(e))z.includes(n)||u(`unknown option "${n}"`,`use only: ${z.join(", ")}`);let a=e,o=T(y(a,"baseline"),"baseline"),m=y(a,"mustPass");m!==void 0&&!Array.isArray(m)&&u(`mustPass is ${b(m)}, not an array`,'pass e.g. "mustPass": ["s1"]');let i=[...new Set((m??[]).map(n=>T(n,"mustPass scenario")))],t=B(y(a,"passTolerance"),"passTolerance"),l=B(y(a,"costTolerance"),"costTolerance"),r=new Map,d=new Set;s.forEach((n,c)=>{let A=`runs[${c}]`;if(!j(n))return u(`${A} is ${b(n)}, not a run record`,"pass { variant, scenario, state, passed }");let M=T(y(n,"variant"),`${A}.variant`),x=T(y(n,"scenario"),`${A}.scenario`),I=y(n,"passed");typeof I!="boolean"&&u(`${A}.passed is ${b(I)}, not a boolean`,"pass the scorer's verdict as true or false");let k=cs(y(n,"state"),A),$=r.get(M);$||r.set(M,$={metrics:[],passed:0,ran:new Map,failed:new Set}),$.metrics.push(k);let E=$.ran.get(x)??[0,0];$.ran.set(x,E),E[1]++,d.add(x),I?($.passed++,E[0]++):$.failed.add(x);});let p=r.get(o);p||u(`baseline "${o}" has no run`,"name a variant that appears in runs");for(let n of i)d.has(n)||u(`mustPass scenario "${n}" has no run`,"name a scenario that appears in runs");let h=[...new Set([...p.ran.keys(),...i])].sort(_),g=[...r].map(([n,c])=>{let A=c.metrics.length,M={};for(let k of is)M[k]=D(Q(c.metrics.map($=>$[k])),`variant ${n} mean ${k}`);let x=i.filter(k=>c.failed.has(k)).sort(_),I=h.filter(k=>!c.ran.has(k));return {variant:n,runs:A,passed:c.passed,passRate:Q([...c.ran.values()].map(([k,$])=>k/$)),mean:M,regressions:x,missing:I,eligible:x.length===0&&I.length===0}});g.sort((n,c)=>Number(c.eligible)-Number(n.eligible)||c.passRate-n.passRate||n.mean.tokens-c.mean.tokens||n.mean.durationMs-c.mean.durationMs||n.mean.humanInterventions-c.mean.humanInterventions||_(n.variant,c.variant));let f=g.find(n=>n.variant===o),v=g.find(n=>n.variant!==o&&n.eligible&&n.passRate>=f.passRate-t&&(n.passRate>f.passRate+t||n.mean.tokens<f.mean.tokens*(1-l)));if(v)return {baseline:o,variants:g,winner:v.variant,reason:`${v.variant} beats baseline ${o}: pass rate ${v.passRate} vs ${f.passRate}, mean tokens ${v.mean.tokens} vs ${f.mean.tokens}`};let R=g.filter(n=>n.variant!==o),C;if(R.length===0)C=`no variant to compare with baseline ${o}`;else if(R.some(n=>n.eligible))C=`within noise: no eligible variant beats baseline ${o} beyond the tolerances`;else {let n=R.map(c=>`${c.variant} (${(c.regressions.length?c.regressions:c.missing).join(", ")})`).join("; ");C=`${R.some(c=>c.regressions.length)?"must-pass regression":"no eligible variant, missing runs"}: ${n}`;}return {baseline:o,variants:g,winner:null,reason:C}}export{us as compareRuns,as as recordRepoChange,os as recordRiskAssessment};//# sourceMappingURL=index.mjs.map
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/risk/assessment.ts","../../src/common/context/repo-change.ts","../../src/common/compare-runs.ts"],"names":["KEYS","bad","what","fix","fail","recordRiskAssessment","state","methodology","input","k","id","level","factors","ref","subject","by","now","item","getItem","RISK_LEVELS","issue","assessorIssue","rolesWith","r","data","applyAction","s","addEvidence","IN_FLIGHT","recordRepoChange","revision","paths","i","repoPathIssue","changed","res","appendEvent","nowOf","warnings","ctx","contextOf","cited","a","was","hit","p","OPTION_KEYS","METRICS","show","v","isObject","own","o","finite","idOf","assertId","tolerance","key","metricsOf","where","events","accounting","items","m","line","ev","t","it","meanOf","xs","b","x","byId","compareRuns","runs","options","baseline","must","mustPass","passTol","costTol","groups","named","variant","scenario","passed","metrics","g","tally","base","required","results","n","mean","regressions","missing","win","others","reason","why"],"mappings":"gaAsBA,IAAMA,CAAAA,CAAO,CAAC,MAAA,CAAQ,OAAA,CAAS,UAAW,KAAA,CAAO,SAAA,CAAW,KAAM,KAAK,CAAA,CACjEC,EAAM,CAACC,CAAAA,CAAcC,IACzBC,GAAAA,CAAK,eAAA,CAAiB,oBAAoBF,CAAI,CAAA,CAAA,CAAIC,CAAG,CAAA,CAShD,SAASE,EAAAA,CACdC,IACAC,CAAAA,CACAC,GAAAA,CACgB,EACZ,OAAOA,GAAAA,EAAU,UAAYA,GAAAA,GAAU,IAAA,EAAQ,MAAM,OAAA,CAAQA,GAAK,IACpEP,CAAAA,CAAI,yBAAA,CAA2B,UAAUD,CAAAA,CAAK,IAAA,CAAK,IAAI,CAAC,CAAA,EAAA,CAAI,CAAA,CAC9D,IAAA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AAE,WAAA,CAAcA,CAAAA,CAAE,SAAS,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,CAAA,CAC5F,IAAA,CAAK,IAAI,CAAA,CACZiD,CAAAA,CAAS,GAAGD,CAAAA,CAAO,IAAA,CAAMhD,GAAMA,CAAAA,CAAE,WAAA,CAAY,MAAM,CAAA,CAAI,sBAAA,CAAyB,mCAAmC,CAAA,EAAA,EAAKkD,CAAG,CAAA,EAC7H,CACA,OAAO,CAAE,SAAAvB,CAAAA,CAAU,QAAA,CAAUe,EAAS,MAAA,CAAQ,IAAA,CAAM,MAAA,CAAAO,CAAO,CAC7D","file":"index.mjs","sourcesContent":["import { fail } from \"../../core/errors.ts\";\nimport { addEvidence } from \"../../core/items/evidence.ts\";\nimport { getItem } from \"../../core/items/record.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport { rolesWith } from \"../../core/roles/lookup.ts\";\nimport type { ApplyResult, Methodology, WorkflowState } from \"../../core/types.ts\";\nimport { assessorIssue, type RiskLevel } from \"./escalation.ts\";\nimport { RISK_LEVELS } from \"./options.ts\";\n\nexport interface RiskAssessmentInput {\n item: string;\n level: RiskLevel;\n factors: string[];\n /** The host's assessment artifact. */\n ref: string;\n /** The item SHA or ref that was assessed. */\n subject?: string;\n /** The assessor: `human` or a role with capability `verify` that did not do the work. */\n by: string;\n now?: string;\n}\n\nconst KEYS = [\"item\", \"level\", \"factors\", \"ref\", \"subject\", \"by\", \"now\"];\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `risk assessment: ${what}`, fix);\n\n/**\n * Records a risk assessment of an item as evidence `risk-assessment` with `data: { level, factors,\n * subject? }` (design spec section 27, #35), through `applyAction` (action `risk.assess`) so the\n * methodology's rules see it. Refuses `invalid-input` for an unknown key, an unknown level, a\n * non-string factor, an empty ref, an assessor that is neither `human` nor a role with `verify`, and\n * an assessor that is the item's author or assigned role.\n */\nexport function recordRiskAssessment<N extends string>(\n state: WorkflowState<N>,\n methodology: Methodology<unknown, N>,\n input: RiskAssessmentInput,\n): ApplyResult<N> {\n if (typeof input !== \"object\" || input === null || Array.isArray(input))\n bad(\"input must be an object\", `pass { ${KEYS.join(\", \")} }`);\n for (const k of Object.keys(input))\n if (!KEYS.includes(k)) bad(`unknown key \"${k}\"`, `use only: ${KEYS.join(\", \")}`);\n const { item: id, level, factors, ref, subject, by, now } = input;\n if (typeof id !== \"string\") bad(\"item must be an item id\", 'e.g. \"item\": \"CART-12\"');\n const item = getItem(state, id);\n if (!RISK_LEVELS.includes(level))\n bad(`unknown level ${JSON.stringify(level)}`, `use one of: ${RISK_LEVELS.join(\", \")}`);\n if (!Array.isArray(factors) || !factors.every((f) => typeof f === \"string\"))\n bad(\"factors must be an array of strings\", 'e.g. \"factors\": [\"ci-cd\", \"secrets\"]');\n if (typeof ref !== \"string\" || ref.trim() === \"\")\n bad(\"ref must be a non-empty string\", 'name the assessment artifact, e.g. \"risk/CART-12.md\"');\n if (subject !== undefined && typeof subject !== \"string\")\n bad(\"subject must be a string\", \"pass the assessed SHA or ref, or omit it\");\n if (now !== undefined && typeof now !== \"string\")\n bad(\"now must be an ISO timestamp string\", \"omit now to use the clock\");\n if (typeof by !== \"string\" || by === \"\") bad(\"by must name the assessor\", 'e.g. \"by\": \"human\"');\n const issue = assessorIssue(state, item, by);\n if (issue === \"invalid\")\n bad(\n `\"${by}\" may not assess risk (needs capability \"verify\")`,\n `assess as human or one of: ${\n rolesWith(state, \"verify\")\n .map((r) => r.id)\n .join(\", \") || \"(no role has verify; register one)\"\n }`,\n );\n if (issue)\n bad(\n `\"${by}\" did the work on \"${id}\" and may not assess its risk`,\n \"assess as human or an independent role with capability verify\",\n );\n const data: Record<string, unknown> = { level, factors: [...factors] };\n if (subject !== undefined) data[\"subject\"] = subject;\n return applyAction(\n state,\n methodology,\n { type: \"risk.assess\", by, payload: { item: id, ref, ...data } },\n (s) => addEvidence(s, id, { kind: \"risk-assessment\", ref, by, data }, now),\n );\n}\n","// `repo.changed` (design spec section 27, #36): the host reports which repository paths a new\n// revision changed; context snapshots citing one of them go stale (see contextOf).\nimport { fail } from \"../../core/errors.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport { appendEvent, nowOf } from \"../../core/state.ts\";\nimport type { ApplyResult, Methodology, Violation, WorkflowState } from \"../../core/types.ts\";\nimport { contextOf, repoPathIssue } from \"./snapshot.ts\";\n\nexport interface RepoChangeInput {\n /** The new repository revision. */\n revision: string;\n /** Repository-relative POSIX paths the revision changed, as Git lists them. */\n paths: string[];\n by: string;\n now?: string;\n}\n\nconst KEYS = [\"revision\", \"paths\", \"by\", \"now\"];\nconst IN_FLIGHT = [\"in_progress\", \"review\", \"awaiting_human\"];\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `repo change: ${what}`, fix);\n\n/**\n * Records that `revision` changed `paths` (design spec section 27, #36): action `repo.change`\n * through `applyAction`, event `repo.changed { revision, paths }` with the paths deduplicated in\n * input order. No item status changes; `warnings` carries one `context-stale` warning per item in\n * `in_progress`, `review` or `awaiting_human` whose context snapshot this change made stale (a\n * cited path it changed that was not stale already). Refuses `invalid-input` for an unknown key,\n * an empty revision, and paths that are not a non-empty array of repository-relative POSIX paths.\n */\nexport function recordRepoChange<N extends string>(\n state: WorkflowState<N>,\n methodology: Methodology<unknown, N>,\n input: RepoChangeInput,\n): ApplyResult<N> {\n if (typeof input !== \"object\" || input === null || Array.isArray(input))\n bad(\"input must be an object\", `pass { ${KEYS.join(\", \")} }`);\n for (const k of Object.keys(input))\n if (!KEYS.includes(k)) bad(`unknown key \"${k}\"`, `use only: ${KEYS.join(\", \")}`);\n const { revision, paths, by, now } = input;\n if (typeof revision !== \"string\" || revision.trim() === \"\")\n bad(\"revision must be a non-empty string\", 'e.g. \"revision\": \"4f2c1e0\"');\n if (!Array.isArray(paths) || paths.length === 0)\n bad(\"paths must be a non-empty array of paths\", 'e.g. \"paths\": [\"src/cart.ts\"]');\n paths.forEach((p, i) => {\n const issue = repoPathIssue(p);\n if (issue)\n bad(\n `paths[${i}] ${issue}`,\n 'send paths as `git diff --name-only -z` lists them (NUL-separated, unquoted; or with `-c core.quotePath=false`), e.g. \"src/cart.ts\"',\n );\n });\n if (typeof by !== \"string\" || by === \"\") bad(\"by must name the reporter\", 'e.g. \"by\": \"ci\"');\n if (now !== undefined && typeof now !== \"string\")\n bad(\"now must be an ISO timestamp string\", \"omit now to use the clock\");\n const changed = [...new Set(paths)];\n const res = applyAction(\n state,\n methodology,\n { type: \"repo.change\", by, payload: { revision, paths: changed } },\n (s) => appendEvent(s, \"repo.changed\", by, { revision, paths: changed }, nowOf(now)),\n );\n const warnings: Violation[] = [];\n for (const item of Object.values(res.state.items)) {\n if (!IN_FLIGHT.includes(item.status)) continue;\n // the new event is the last one, so the paths it made stale are the cited changed paths that\n // were not stale before it, in its order: one indexed read of the earlier log per item\n const ctx = contextOf(state, item);\n if (!ctx) continue;\n const cited = new Set(ctx.assumptions.map((a) => a.source?.path));\n const was = new Set(ctx.stale);\n const hit = changed.filter((p) => cited.has(p) && !was.has(p));\n if (hit.length)\n warnings.push({\n rule: \"context-stale\",\n severity: \"warning\",\n item: item.id,\n message: `context snapshot \"${ctx.snapshot}\" of \"${item.id}\" is stale: ${hit.join(\", \")} changed at ${revision}`,\n fix: `re-verify and record a fresh snapshot of \"${item.id}\" with recordContextSnapshot`,\n });\n }\n return { state: res.state, warnings: [...res.warnings, ...warnings] };\n}\n","// `compareRuns` (design spec section 27, #34): a pure comparison of finished runs, one metric\n// vector per variant, a deterministic ranking and a winner or no winner. Scoring, the scenario\n// suite and running the variants stay with the host.\nimport { assertId, fail } from \"../core/errors.ts\";\nimport type { WorkflowState } from \"../core/types.ts\";\n\n/** One finished run of one variant on one scenario. */\nexport interface RunRecord {\n variant: string;\n scenario: string;\n state: WorkflowState<string>;\n /** The host scorer's verdict for this scenario run. */\n passed: boolean;\n}\n\nexport interface CompareRunsOptions {\n /** The variant every other one is compared with. */\n baseline: string;\n /** Scenarios any failing run of which makes a variant ineligible. */\n mustPass?: string[];\n /** Pass-rate noise, a fraction in `[0, 1]` (default `0`). */\n passTolerance?: number;\n /** Token-cost noise, a fraction in `[0, 1]` (default `0`). */\n costTolerance?: number;\n}\n\nexport interface RunMetrics {\n tokens: number;\n durationMs: number;\n turns: number;\n humanInterventions: number;\n reworks: number;\n escalations: number;\n itemsDone: number;\n}\n\nexport interface VariantResult {\n variant: string;\n runs: number;\n passed: number;\n passRate: number;\n mean: RunMetrics;\n /** Must-pass scenarios with at least one failing run. */\n regressions: string[];\n /** Baseline or must-pass scenarios the variant never ran. */\n missing: string[];\n eligible: boolean;\n}\n\nexport interface RunComparison {\n baseline: string;\n /** Ranked: eligible first, then pass rate, tokens, duration, interventions, id. */\n variants: VariantResult[];\n winner: string | null;\n reason: string;\n}\n\nconst OPTION_KEYS = [\"baseline\", \"mustPass\", \"passTolerance\", \"costTolerance\"];\nconst METRICS = [\n \"tokens\",\n \"durationMs\",\n \"turns\",\n \"humanInterventions\",\n \"reworks\",\n \"escalations\",\n \"itemsDone\",\n] as const;\n\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `compareRuns: ${what}`, fix);\nconst show = (v: unknown): string =>\n typeof v === \"string\"\n ? JSON.stringify(v)\n : typeof v === \"object\" && v !== null\n ? Array.isArray(v)\n ? \"an array\"\n : \"an object\"\n : typeof v === \"function\" || typeof v === \"symbol\"\n ? typeof v\n : String(v);\nconst isObject = (v: unknown): v is Record<string, unknown> =>\n typeof v === \"object\" && v !== null && !Array.isArray(v);\n/** `o[k]` when `o` has it as an own property: inherited values (a `{ __proto__: … }` literal) are not read. */\nconst own = (o: Record<string, unknown>, k: string): unknown =>\n Object.hasOwn(o, k) ? o[k] : undefined;\nconst finite = (v: number, what: string): number =>\n Number.isFinite(v)\n ? v\n : bad(`${what} is not finite (${v})`, \"pass the host's measured usage figures\");\nconst idOf = (v: unknown, what: string): string => {\n if (typeof v !== \"string\")\n bad(`${what} is ${show(v)}, not an id`, `pass a string id such as \"V0\"`);\n assertId(v, what);\n return v as string;\n};\nconst tolerance = (v: unknown, key: string): number => {\n if (v === undefined) return 0;\n if (typeof v !== \"number\" || !Number.isFinite(v) || v < 0 || v > 1)\n bad(`${key} is ${show(v)}, not a fraction in [0, 1]`, `pass e.g. \"${key}\": 0.05`);\n return v as number;\n};\n\nfunction metricsOf(state: unknown, where: string): RunMetrics {\n if (!isObject(state))\n return bad(\n `${where}.state is ${show(state)}, not a workflow state`,\n \"pass the finished state.json\",\n );\n const [events, accounting, items] = [\"events\", \"accounting\", \"items\"].map((k) => own(state, k));\n if (!Array.isArray(events) || !Array.isArray(accounting))\n return bad(\n `${where}.state has no events and accounting arrays`,\n \"pass a WorkflowState as loaded by loadState\",\n );\n if (!isObject(items))\n return bad(\n `${where}.state.items is ${show(items)}, not an object`,\n \"pass a WorkflowState as loaded by loadState\",\n );\n const m: RunMetrics = {\n tokens: 0,\n durationMs: 0,\n turns: accounting.length,\n humanInterventions: 0,\n reworks: 0,\n escalations: 0,\n itemsDone: 0,\n };\n accounting.forEach((line: unknown, i) => {\n if (!isObject(line))\n return bad(\n `${where}.state.accounting[${i}] is ${show(line)}`,\n \"pass accounting lines as recorded by complete\",\n );\n for (const k of [\"tokensIn\", \"tokensOut\", \"durationMs\"]) {\n const v = own(line, k);\n if (typeof v !== \"number\" || !Number.isFinite(v) || v < 0)\n bad(\n `${where}.state.accounting[${i}].${k} is ${show(v)}, not a finite non-negative number`,\n \"pass the host's measured usage figures\",\n );\n }\n m.tokens += (line[\"tokensIn\"] as number) + (line[\"tokensOut\"] as number);\n m.durationMs += line[\"durationMs\"] as number;\n });\n // finite figures can still sum to Infinity (G2-7)\n finite(m.tokens, `${where}.state token total`);\n finite(m.durationMs, `${where}.state duration total`);\n events.forEach((ev: unknown, i) => {\n if (!isObject(ev) || typeof own(ev, \"type\") !== \"string\")\n return bad(\n `${where}.state.events[${i}] is ${show(ev)}, not an event`,\n \"pass events as recorded by the engine\",\n );\n const t = ev[\"type\"];\n if (t === \"pending.raised\" || t === \"blocker.cleared\") m.humanInterventions++;\n else if (t === \"item.rework\") m.reworks++;\n else if (t === \"item.escalated\") m.escalations++;\n });\n for (const it of Object.values(items))\n if (isObject(it) && own(it, \"status\") === \"done\") m.itemsDone++;\n return m;\n}\n\n// summed in ascending order so the order of `runs` never changes a float result\nconst meanOf = (xs: number[]): number =>\n xs.sort((a, b) => a - b).reduce((s, x) => s + x, 0) / xs.length;\nconst byId = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\n\n/**\n * Compares finished runs (design spec section 27, #34). Pure: reads only its arguments and\n * returns fresh objects. Each variant gets a metric vector (the mean over its runs of tokens,\n * duration, turns, human interventions, reworks, escalations and done items), a pass rate (the\n * mean over its scenarios of each scenario's passing share, so every scenario weighs the same) and an\n * eligibility (no must-pass regression, nothing missing). The winner is the first ranked eligible\n * non-baseline variant that is not worse than the baseline on pass rate and better on pass rate\n * or tokens, beyond the tolerances; otherwise `null` with the reason. Refuses `invalid-input`\n * naming the offending value for malformed input, never a `TypeError`.\n */\nexport function compareRuns(\n runs: readonly RunRecord[],\n options: CompareRunsOptions,\n): RunComparison {\n if (!Array.isArray(runs))\n bad(\n `runs is ${show(runs)}, not an array`,\n \"pass an array of { variant, scenario, state, passed }\",\n );\n if (runs.length === 0) bad(\"no runs to compare\", \"pass at least the baseline's finished runs\");\n if (!isObject(options))\n return bad(`options is ${show(options)}, not an object`, 'pass { baseline: \"V0\" }');\n for (const k of Object.keys(options))\n if (!OPTION_KEYS.includes(k))\n bad(`unknown option \"${k}\"`, `use only: ${OPTION_KEYS.join(\", \")}`);\n const o = options as unknown as Record<string, unknown>;\n const baseline = idOf(own(o, \"baseline\"), \"baseline\");\n const must = own(o, \"mustPass\");\n if (must !== undefined && !Array.isArray(must))\n bad(`mustPass is ${show(must)}, not an array`, 'pass e.g. \"mustPass\": [\"s1\"]');\n const mustPass = [\n ...new Set(((must ?? []) as unknown[]).map((s) => idOf(s, \"mustPass scenario\"))),\n ];\n const passTol = tolerance(own(o, \"passTolerance\"), \"passTolerance\");\n const costTol = tolerance(own(o, \"costTolerance\"), \"costTolerance\");\n\n interface Acc {\n metrics: RunMetrics[];\n passed: number;\n /** scenario -> [passing runs, runs] */\n ran: Map<string, [number, number]>;\n failed: Set<string>;\n }\n const groups = new Map<string, Acc>();\n const named = new Set<string>();\n runs.forEach((r: unknown, i) => {\n const where = `runs[${i}]`;\n if (!isObject(r))\n return bad(\n `${where} is ${show(r)}, not a run record`,\n \"pass { variant, scenario, state, passed }\",\n );\n const variant = idOf(own(r, \"variant\"), `${where}.variant`);\n const scenario = idOf(own(r, \"scenario\"), `${where}.scenario`);\n const passed = own(r, \"passed\");\n if (typeof passed !== \"boolean\")\n bad(\n `${where}.passed is ${show(passed)}, not a boolean`,\n \"pass the scorer's verdict as true or false\",\n );\n const metrics = metricsOf(own(r, \"state\"), where);\n let g = groups.get(variant);\n if (!g)\n groups.set(variant, (g = { metrics: [], passed: 0, ran: new Map(), failed: new Set() }));\n g.metrics.push(metrics);\n const tally = g.ran.get(scenario) ?? [0, 0];\n g.ran.set(scenario, tally);\n tally[1]++;\n named.add(scenario);\n if (passed) {\n g.passed++;\n tally[0]++;\n } else g.failed.add(scenario);\n });\n const base = groups.get(baseline);\n if (!base) bad(`baseline \"${baseline}\" has no run`, \"name a variant that appears in runs\");\n for (const s of mustPass)\n if (!named.has(s))\n bad(`mustPass scenario \"${s}\" has no run`, \"name a scenario that appears in runs\");\n const required = [...new Set([...base!.ran.keys(), ...mustPass])].sort(byId);\n\n const results: VariantResult[] = [...groups].map(([variant, g]) => {\n const n = g.metrics.length;\n const mean = {} as RunMetrics;\n for (const k of METRICS)\n mean[k] = finite(meanOf(g.metrics.map((m) => m[k])), `variant ${variant} mean ${k}`);\n const regressions = mustPass.filter((s) => g.failed.has(s)).sort(byId);\n const missing = required.filter((s) => !g.ran.has(s));\n return {\n variant,\n runs: n,\n passed: g.passed,\n // scenario-weighted: each scenario counts once, whatever its number of runs (G1-3)\n passRate: meanOf([...g.ran.values()].map(([p, k]) => p / k)),\n mean,\n regressions,\n missing,\n eligible: regressions.length === 0 && missing.length === 0,\n };\n });\n results.sort(\n (a, b) =>\n Number(b.eligible) - Number(a.eligible) ||\n b.passRate - a.passRate ||\n a.mean.tokens - b.mean.tokens ||\n a.mean.durationMs - b.mean.durationMs ||\n a.mean.humanInterventions - b.mean.humanInterventions ||\n byId(a.variant, b.variant),\n );\n\n const ref = results.find((v) => v.variant === baseline)!;\n const win = results.find(\n (v) =>\n v.variant !== baseline &&\n v.eligible &&\n v.passRate >= ref.passRate - passTol &&\n (v.passRate > ref.passRate + passTol || v.mean.tokens < ref.mean.tokens * (1 - costTol)),\n );\n if (win)\n return {\n baseline,\n variants: results,\n winner: win.variant,\n reason: `${win.variant} beats baseline ${baseline}: pass rate ${win.passRate} vs ${ref.passRate}, mean tokens ${win.mean.tokens} vs ${ref.mean.tokens}`,\n };\n const others = results.filter((v) => v.variant !== baseline);\n let reason: string;\n if (others.length === 0) reason = `no variant to compare with baseline ${baseline}`;\n else if (others.some((v) => v.eligible))\n reason = `within noise: no eligible variant beats baseline ${baseline} beyond the tolerances`;\n else {\n const why = others\n .map((v) => `${v.variant} (${(v.regressions.length ? v.regressions : v.missing).join(\", \")})`)\n .join(\"; \");\n reason = `${others.some((v) => v.regressions.length) ? \"must-pass regression\" : \"no eligible variant, missing runs\"}: ${why}`;\n }\n return { baseline, variants: results, winner: null, reason };\n}\n"]}
|
package/dist/registry/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkG6QELJRL_cjs=require('../chunk-G6QELJRL.cjs');require('../chunk-ZDT2BZGU.cjs'),require('../chunk-CPM2SPDX.cjs'),require('../chunk-OFFQTZEY.cjs'),require('../chunk-YRXFEM3F.cjs'),require('../chunk-GKN5M4B7.cjs'),require('../chunk-RMXEQ5HN.cjs'),require('../chunk-ZK3V66NC.cjs'),require('../chunk-76ITDJDM.cjs'),require('../chunk-U23IRPFF.cjs'),require('../chunk-KLOSFZFK.cjs'),require('../chunk-6PFJYRM7.cjs'),require('../chunk-BBI7AKJK.cjs'),require('../chunk-TBLIZIWH.cjs'),require('../chunk-OSHBJIYD.cjs');Object.defineProperty(exports,"methodologyFactory",{enumerable:true,get:function(){return chunkG6QELJRL_cjs.b}});Object.defineProperty(exports,"registerMethodology",{enumerable:true,get:function(){return chunkG6QELJRL_cjs.a}});Object.defineProperty(exports,"registeredMethodologies",{enumerable:true,get:function(){return chunkG6QELJRL_cjs.c}});//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Methodology } from '../types-
|
|
1
|
+
import { M as Methodology } from '../types-DLOtndDY.cjs';
|
|
2
2
|
|
|
3
3
|
/** A methodology factory, as the built-in entries export them (`scrum`, `kanban`, ...). */
|
|
4
4
|
type MethodologyFactory<N extends string = string> = () => Methodology<unknown, N>;
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Methodology } from '../types-
|
|
1
|
+
import { M as Methodology } from '../types-DLOtndDY.js';
|
|
2
2
|
|
|
3
3
|
/** A methodology factory, as the built-in entries export them (`scrum`, `kanban`, ...). */
|
|
4
4
|
type MethodologyFactory<N extends string = string> = () => Methodology<unknown, N>;
|
package/dist/registry/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{b as methodologyFactory,a as registerMethodology,c as registeredMethodologies}from'../chunk-
|
|
1
|
+
export{b as methodologyFactory,a as registerMethodology,c as registeredMethodologies}from'../chunk-HXEJP6KF.mjs';import'../chunk-AWFR3Q4M.mjs';import'../chunk-OAJ4KV4F.mjs';import'../chunk-BGKXIRGS.mjs';import'../chunk-MUQ4FKVH.mjs';import'../chunk-C4ISBUZR.mjs';import'../chunk-N2NANHRW.mjs';import'../chunk-3QUIRAXO.mjs';import'../chunk-ILNSTPPV.mjs';import'../chunk-BNKKOAMP.mjs';import'../chunk-BD665RYK.mjs';import'../chunk-WU5JELOM.mjs';import'../chunk-TQR3VFZU.mjs';import'../chunk-NNQ3RHDP.mjs';import'../chunk-YS6CXERQ.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/schema/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkDVFTTBCT_cjs=require('../chunk-DVFTTBCT.cjs');require('../chunk-OSHBJIYD.cjs');Object.defineProperty(exports,"DRAFT_07",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.c}});Object.defineProperty(exports,"assertValid",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.b}});Object.defineProperty(exports,"experimentationConfigSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.m}});Object.defineProperty(exports,"handoffSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.h}});Object.defineProperty(exports,"investigationConfigSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.l}});Object.defineProperty(exports,"itemPatchSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.g}});Object.defineProperty(exports,"kanbanConfigSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.j}});Object.defineProperty(exports,"newItemSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.f}});Object.defineProperty(exports,"roleSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.e}});Object.defineProperty(exports,"scrumConfigSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.i}});Object.defineProperty(exports,"validate",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.a}});Object.defineProperty(exports,"waterfallConfigSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.k}});Object.defineProperty(exports,"workflowStateSchema",{enumerable:true,get:function(){return chunkDVFTTBCT_cjs.d}});//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/schema/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{c as DRAFT_07,b as assertValid,m as experimentationConfigSchema,h as handoffSchema,l as investigationConfigSchema,g as itemPatchSchema,j as kanbanConfigSchema,f as newItemSchema,e as roleSchema,i as scrumConfigSchema,a as validate,k as waterfallConfigSchema,d as workflowStateSchema}from'../chunk-
|
|
1
|
+
export{c as DRAFT_07,b as assertValid,m as experimentationConfigSchema,h as handoffSchema,l as investigationConfigSchema,g as itemPatchSchema,j as kanbanConfigSchema,f as newItemSchema,e as roleSchema,i as scrumConfigSchema,a as validate,k as waterfallConfigSchema,d as workflowStateSchema}from'../chunk-QJMOCISZ.mjs';import'../chunk-YS6CXERQ.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/scrum/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkZDT2BZGU_cjs=require('../chunk-ZDT2BZGU.cjs');require('../chunk-RMXEQ5HN.cjs'),require('../chunk-ZK3V66NC.cjs');var chunkTBLIZIWH_cjs=require('../chunk-TBLIZIWH.cjs');require('../chunk-OSHBJIYD.cjs');Object.defineProperty(exports,"SCRUM_VOCABULARY",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.h}});Object.defineProperty(exports,"closeSprint",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.k}});Object.defineProperty(exports,"configOf",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.i}});Object.defineProperty(exports,"dailyReport",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.a}});Object.defineProperty(exports,"resumeStageOf",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.j}});Object.defineProperty(exports,"scrum",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.l}});Object.defineProperty(exports,"scrumCeremonies",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.b}});Object.defineProperty(exports,"scrumMetrics",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.d}});Object.defineProperty(exports,"scrumRoles",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.e}});Object.defineProperty(exports,"scrumRules",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.f}});Object.defineProperty(exports,"scrumStages",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.g}});Object.defineProperty(exports,"validateScrumConfig",{enumerable:true,get:function(){return chunkZDT2BZGU_cjs.c}});Object.defineProperty(exports,"canDo",{enumerable:true,get:function(){return chunkTBLIZIWH_cjs.l}});//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/scrum/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as Budget, P as Policy, W as WorkflowState, R as Role, g as Rule, S as Stage, j as ItemStatus, M as Methodology, f as Ceremony, k as CoreTerm, l as WorkItem } from '../types-
|
|
2
|
-
import { E as EstimateMode } from '../budget-
|
|
3
|
-
export { c as canDo } from '../budget-
|
|
1
|
+
import { a as Budget, P as Policy, W as WorkflowState, R as Role, g as Rule, S as Stage, j as ItemStatus, M as Methodology, f as Ceremony, k as CoreTerm, l as WorkItem } from '../types-DLOtndDY.cjs';
|
|
2
|
+
import { E as EstimateMode } from '../budget-DDqQQIgp.cjs';
|
|
3
|
+
export { c as canDo } from '../budget-DDqQQIgp.cjs';
|
|
4
4
|
|
|
5
5
|
interface ScrumConfig {
|
|
6
6
|
sprintBudget: Budget;
|
package/dist/scrum/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as Budget, P as Policy, W as WorkflowState, R as Role, g as Rule, S as Stage, j as ItemStatus, M as Methodology, f as Ceremony, k as CoreTerm, l as WorkItem } from '../types-
|
|
2
|
-
import { E as EstimateMode } from '../budget-
|
|
3
|
-
export { c as canDo } from '../budget-
|
|
1
|
+
import { a as Budget, P as Policy, W as WorkflowState, R as Role, g as Rule, S as Stage, j as ItemStatus, M as Methodology, f as Ceremony, k as CoreTerm, l as WorkItem } from '../types-DLOtndDY.js';
|
|
2
|
+
import { E as EstimateMode } from '../budget-BuQ9GWsg.js';
|
|
3
|
+
export { c as canDo } from '../budget-BuQ9GWsg.js';
|
|
4
4
|
|
|
5
5
|
interface ScrumConfig {
|
|
6
6
|
sprintBudget: Budget;
|
package/dist/scrum/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{h as SCRUM_VOCABULARY,k as closeSprint,i as configOf,a as dailyReport,j as resumeStageOf,l as scrum,b as scrumCeremonies,d as scrumMetrics,e as scrumRoles,f as scrumRules,g as scrumStages,c as validateScrumConfig}from'../chunk-
|
|
1
|
+
export{h as SCRUM_VOCABULARY,k as closeSprint,i as configOf,a as dailyReport,j as resumeStageOf,l as scrum,b as scrumCeremonies,d as scrumMetrics,e as scrumRoles,f as scrumRules,g as scrumStages,c as validateScrumConfig}from'../chunk-AWFR3Q4M.mjs';import'../chunk-N2NANHRW.mjs';import'../chunk-3QUIRAXO.mjs';export{l as canDo}from'../chunk-NNQ3RHDP.mjs';import'../chunk-YS6CXERQ.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|