ex-workflow 1.2.0 → 1.3.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 +25 -0
- package/README.md +145 -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-VXOZIP77.cjs → chunk-2FBA7RBS.cjs} +2 -2
- package/dist/{chunk-VXOZIP77.cjs.map → chunk-2FBA7RBS.cjs.map} +1 -1
- package/dist/chunk-3S7F5QXK.mjs +2 -0
- package/dist/{chunk-BYPFTO7P.mjs.map → chunk-3S7F5QXK.mjs.map} +1 -1
- package/dist/{chunk-K4VSMIJZ.cjs → chunk-3ZUBCA7Q.cjs} +2 -2
- package/dist/{chunk-K4VSMIJZ.cjs.map → chunk-3ZUBCA7Q.cjs.map} +1 -1
- package/dist/chunk-4F5HZLKD.cjs +2 -0
- package/dist/{chunk-SFYUJQYW.cjs.map → chunk-4F5HZLKD.cjs.map} +1 -1
- package/dist/{chunk-4HG6A3SF.mjs → chunk-5DCOXGRW.mjs} +2 -2
- package/dist/{chunk-4HG6A3SF.mjs.map → chunk-5DCOXGRW.mjs.map} +1 -1
- package/dist/chunk-5GXB6GMX.mjs +2 -0
- package/dist/chunk-5GXB6GMX.mjs.map +1 -0
- package/dist/chunk-5ZGNEY2I.mjs +2 -0
- package/dist/{chunk-32NVJV5C.mjs.map → chunk-5ZGNEY2I.mjs.map} +1 -1
- package/dist/chunk-6PFJYRM7.cjs +2 -0
- package/dist/chunk-6PFJYRM7.cjs.map +1 -0
- package/dist/{chunk-W2P27645.cjs → chunk-BANKVCYY.cjs} +2 -2
- package/dist/{chunk-W2P27645.cjs.map → chunk-BANKVCYY.cjs.map} +1 -1
- package/dist/chunk-BD665RYK.mjs +2 -0
- package/dist/chunk-BD665RYK.mjs.map +1 -0
- package/dist/chunk-COPYGMHE.mjs +2 -0
- package/dist/chunk-COPYGMHE.mjs.map +1 -0
- package/dist/{chunk-3O5MPAJT.cjs → chunk-CVGEIXW6.cjs} +2 -2
- package/dist/{chunk-3O5MPAJT.cjs.map → chunk-CVGEIXW6.cjs.map} +1 -1
- package/dist/chunk-CX2E7ZTQ.mjs +2 -0
- package/dist/{chunk-JNLWI4JM.mjs.map → chunk-CX2E7ZTQ.mjs.map} +1 -1
- package/dist/chunk-DVFTTBCT.cjs +3 -0
- package/dist/chunk-DVFTTBCT.cjs.map +1 -0
- package/dist/{chunk-U3RU5LOF.cjs → chunk-EQXYFHHD.cjs} +2 -2
- package/dist/{chunk-U3RU5LOF.cjs.map → chunk-EQXYFHHD.cjs.map} +1 -1
- package/dist/{chunk-OVR5CK3R.cjs → chunk-H26KXQ3I.cjs} +2 -2
- package/dist/{chunk-OVR5CK3R.cjs.map → chunk-H26KXQ3I.cjs.map} +1 -1
- package/dist/chunk-ILDXZWEL.mjs +2 -0
- package/dist/{chunk-OZAYOPLB.mjs.map → chunk-ILDXZWEL.mjs.map} +1 -1
- 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-WPVL27G4.mjs → chunk-LG23WXAP.mjs} +2 -2
- package/dist/{chunk-WPVL27G4.mjs.map → chunk-LG23WXAP.mjs.map} +1 -1
- package/dist/chunk-MU26QW32.cjs +2 -0
- package/dist/chunk-MU26QW32.cjs.map +1 -0
- package/dist/chunk-OEHVWRJG.mjs +2 -0
- package/dist/{chunk-7EF47R2J.mjs.map → chunk-OEHVWRJG.mjs.map} +1 -1
- 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-LIATP6LY.mjs → chunk-PFHVB2WT.mjs} +2 -2
- package/dist/{chunk-LIATP6LY.mjs.map → chunk-PFHVB2WT.mjs.map} +1 -1
- package/dist/chunk-QJMOCISZ.mjs +3 -0
- package/dist/chunk-QJMOCISZ.mjs.map +1 -0
- package/dist/chunk-RGHM3JJM.cjs +2 -0
- package/dist/chunk-RGHM3JJM.cjs.map +1 -0
- package/dist/chunk-UMG3WOD7.cjs +2 -0
- package/dist/{chunk-QAENYYU6.cjs.map → chunk-UMG3WOD7.cjs.map} +1 -1
- package/dist/{chunk-6D6FL3XK.mjs → chunk-UT7QV6CE.mjs} +2 -2
- package/dist/{chunk-6D6FL3XK.mjs.map → chunk-UT7QV6CE.mjs.map} +1 -1
- package/dist/chunk-WU5JELOM.mjs +2 -0
- package/dist/chunk-WU5JELOM.mjs.map +1 -0
- package/dist/{chunk-IIEKK2S3.cjs → chunk-YGCNLXPJ.cjs} +2 -2
- package/dist/{chunk-IIEKK2S3.cjs.map → chunk-YGCNLXPJ.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 +8 -6
- package/dist/index.d.ts +8 -6
- 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 +199 -0
- package/dist/policies/index.d.ts +199 -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-43GLYYA2.cjs +0 -3
- package/dist/chunk-43GLYYA2.cjs.map +0 -1
- package/dist/chunk-7EF47R2J.mjs +0 -2
- 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-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-Z43GUETW.cjs +0 -2
- package/dist/chunk-Z43GUETW.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0 (2026-11-06)
|
|
4
|
+
|
|
5
|
+
Composable policies: three opt-in policies a host adds to any methodology by wrapping it, risk-adaptive gates (#35), context-grounded entry (#36) and run comparison (#34), shipped from the new entry `ex-workflow/policies`; core gains only optional hooks that do nothing when unused. The decisions are in the design spec, section 27. Every change is additive.
|
|
6
|
+
|
|
7
|
+
- Entry point: `ex-workflow/policies` (ESM, CommonJS, `.d.ts`) exports `withRiskGate`, `recordRiskAssessment`, `riskEscalation`, `DEFAULT_RISK_TABLE`, `withContextGrounding`, `recordContextSnapshot`, `recordRepoChange`, `contextOf`, `contextGroundedViolations` and `compareRuns`, with the types `RiskLevel`, `RiskTable`, `RiskAssessmentData`, `RiskAssessmentInput`, `RiskGateOptions`, `ContextGroundingOptions`, `ContextSnapshotInput`, `RepoChangeInput`, `CompareRunsOptions`, `RunRecord`, `RunMetrics`, `VariantResult` and `RunComparison`. The root entry exports no new runtime name, so core plus one methodology does not carry the policies. The policies are SDK-only; the CLI is unchanged.
|
|
8
|
+
- Core hooks: `Methodology` gains three optional members, `escalateGate(state, item, gate)` (returns a `GateEscalation`), `customPolicy(state, item, policy)` (answers a `custom` stage policy) and `briefContext(state, item)` (fills the new optional `Brief.context`). `Evidence` gains the optional `data` (structured content a policy reads). `evaluatePolicies` and `assertPolicies` take an optional trailing methodology; their 1.1 signature stays the last overload. New root types `GateEscalation`, `BriefContext`, `ContextAssumption`, `ContextSnapshotData` (type-only).
|
|
9
|
+
- Risk-adaptive gates (#35): `recordRiskAssessment` records evidence `risk-assessment` (`data: { level, factors, subject? }`, action `risk.assess`) by `human` or an independent role with `verify`. `withRiskGate(m, { gates, table? })` makes the listed gates add the requirements of the strictest valid fresh assessment's level (`DEFAULT_RISK_TABLE`: `high` and `critical` add `"human"`; a missing, invalid or non-independent assessment counts as `critical`); a custom table must be monotone. Escalation only ever appends to the static gate (principles rule 17). `complete()` appends the new event **`gate.resolved`** `{ item, gate, requires, evidence, reason }` before `gate.passed` or `pending.raised`, and `decide()` (also `exwf decide`) judges a pending against the resolution recorded with it, so a role cannot approve a pending escalated to a human. `riskEscalation` is the resolver on its own.
|
|
10
|
+
- Context-grounded entry (#36): `recordContextSnapshot` records evidence `context-snapshot` (`data: { revision, assumptions }`, each assumption a `claim` with optional `required` and `source { path, lines?, hash }`, action `context.snapshot`); `recordRepoChange({ revision, paths })` appends the new event **`repo.changed`** (action `repo.change`) and warns `context-stale` for each in-flight item whose snapshot it made stale. `withContextGrounding(m, { entry, exit? })` adds the custom policy `context-grounded` to those stages: an item needs a fresh, non-stale qualifying snapshot (at least one sourced assumption, recorded by `human` or a registered role that did not work on the item) with every `required` claim sourced; `next` skips it otherwise with reason `entry-policy`, and its brief carries `context` (what was verified, what went stale, what is unverified). `contextOf` and `contextGroundedViolations` answer on their own. Paths are repository-relative POSIX paths as Git lists them (`git diff --name-only -z`), matched exactly.
|
|
11
|
+
- Run comparison (#34): `compareRuns(runs, { baseline, mustPass?, passTolerance?, costTolerance? })` derives per run tokens, duration, turns, human interventions, reworks, escalations and items done, ranks the variants (scenario-weighted pass rate, then cost) and names a winner only when an eligible variant beats the baseline beyond the tolerances, else `winner: null` with the reason. Scenario suites, running variants and scoring stay host-side.
|
|
12
|
+
- Principles: rule 5 adds the snapshot stale rule (a later `repo.changed` citing a source path, by event order); new rule 17 "Gate escalation only tightens".
|
|
13
|
+
- Tests: 1.2.0 compatibility fixtures (all five methodologies) load unchanged.
|
|
14
|
+
- Size: owner approved 2026-11-06 (spec 27), measured: `core+scrum` 61031 → 61884 B, `core+kanban` 68951 → 69804 B, `core+waterfall` 69379 → 70232 B, `core+investigation` 53566 → 54419 B, `core+experimentation` 57058 → 57911 B, `core+registry` 159765 → 160618 B (+853 B each: the three core hooks, `gate.resolved` and the `decide` lookup), `schema` 28942 → 28987 B (`Evidence.data`), `dist/index.mjs` 1330 → 1364 B, `dist/{investigation,experimentation,registry}/index.mjs` +30 B each (one more shared chunk import); `dist/policies/index.mjs` (19820 B) and `core+policies` (56597 B) seeded at measured size. The version bump changed no size.
|
|
15
|
+
|
|
16
|
+
Fixed (release gate of 1.3.0, spec 27 rows F1/F2), in code new in this release:
|
|
17
|
+
|
|
18
|
+
- Independence: both policies compare the assessor or snapshot recorder with every role dispatched on the item since its last rework, its `role` and its author (G1-1, G2-12), counting the transitions blockers append (G5-1); a snapshot qualifies only with a sourced assumption and a non-worker `human` or registered recorder, at record and at read time (G1-2, G2-1, G2-2).
|
|
19
|
+
- `decide` reads the `gate.resolved` recorded with its pending in one backward scan, so a resolution appended later cannot relax it and a long log costs no more than in 1.2 (G3-1, G2-5); a malformed requirement is skipped, never a `TypeError` (G1-7, G2-4).
|
|
20
|
+
- `recordRepoChange`, `contextOf` and the planner read the log through a cached per-log index: 10,000 in-flight items 9.6 s → 24 ms (G3-2 to G3-5, G2-6); `contextOf` returns copies (G2-9).
|
|
21
|
+
- Paths: control, bidirectional and non-NFC characters, surrounding whitespace and paths over 4096 characters are refused (G2-8, G4-4, G4-5).
|
|
22
|
+
- Risk options: one validator for `withRiskGate` and `riskEscalation` (no `TypeError` on `{}`), a monotone table required with requirements and evidence kinds compared apart, own properties only (G1-4, G1-6, G2-10, G5-4, G5-5).
|
|
23
|
+
- `compareRuns`: scenario-weighted pass rate (G1-3), non-finite totals refused and inputs read as own properties only (G2-7, G4-8).
|
|
24
|
+
- The `ex-workflow/policies` barrel is `src/policies/index.ts` (G4-3); 1.2.0 compatibility fixtures added (G4-2).
|
|
25
|
+
|
|
26
|
+
Compatibility: additive. `state.json` gains one optional field, `Evidence.data`, written only by the policy recorders; a `.workflow/state.json` written by any earlier release loads unchanged (`test/compat.test.ts` replays the fixtures through 1.2.0). No downgrade: 1.2.x cannot load a state carrying `Evidence.data`, because its schema closes `Evidence` (README Known limitations). Schema documents: still ten; `workflowStateSchema` gains the optional open `data` on `Evidence`. Event kinds: 69 → 71 (`gate.resolved`, `repo.changed`); existing payloads unchanged. Exports: the new entry `ex-workflow/policies` (ten runtime exports above); the root entry and `ex-workflow/types` gain the types `GateEscalation`, `BriefContext`, `ContextAssumption` and `ContextSnapshotData`; `Methodology` gains the optional `escalateGate`, `customPolicy` and `briefContext`, `Brief` the optional `context`; `evaluatePolicies` and `assertPolicies` an optional trailing parameter (1.1 signature last); nothing is removed (`test/api-surface.json` gains rows only). CLI: unchanged (`USAGE`, commands, flags); `exwf decide` honours an escalation an SDK run recorded, `exwf complete` checks the static gate, and without the wrapper a `context-grounded` stage falls back to the 1.2 `policy:context-grounded` evidence check. Error codes: unchanged (the recorders and options refuse with `invalid-input`; an unmet widened gate fails `gate-unmet`). Behaviour changes: none for a methodology without the hooks, so none for the built-ins and the CLI on states they wrote; `decide` on a pending raised under an escalation requires what the escalation added. Runtime dependencies: unchanged (`ex-flow`, `exsorted`). `VERSION` is `"1.3.0"`.
|
|
27
|
+
|
|
3
28
|
## 1.2.0 (2026-11-03)
|
|
4
29
|
|
|
5
30
|
Layered architecture: the engine is split into four code layers (core → common → interface → methodologies) under one written set of principles, so a methodology, built-in or custom, is a composition of shared pieces; the decisions are in the design spec, section 26. Every change is additive.
|
package/README.md
CHANGED
|
@@ -20,17 +20,18 @@
|
|
|
20
20
|
6. [Standalone investigation and experimentation](#standalone-investigation-and-experimentation)
|
|
21
21
|
7. [Persisting state](#persisting-state)
|
|
22
22
|
8. [Custom methodologies and extension state](#custom-methodologies-and-extension-state)
|
|
23
|
-
9. [
|
|
24
|
-
10. [
|
|
25
|
-
11. [
|
|
26
|
-
12. [
|
|
27
|
-
13. [
|
|
28
|
-
14. [
|
|
29
|
-
15. [
|
|
30
|
-
16. [
|
|
31
|
-
17. [
|
|
32
|
-
18. [
|
|
33
|
-
19. [
|
|
23
|
+
9. [Composable policies](#composable-policies)
|
|
24
|
+
10. [CLI reference (`exwf`)](#cli-reference-exwf)
|
|
25
|
+
11. [Configuration](#configuration)
|
|
26
|
+
12. [Ceremonies](#ceremonies)
|
|
27
|
+
13. [Items, briefs, handoffs, accounting](#items-briefs-handoffs-accounting)
|
|
28
|
+
14. [Errors](#errors)
|
|
29
|
+
15. [JSON Schema](#json-schema)
|
|
30
|
+
16. [Package entry points](#package-entry-points)
|
|
31
|
+
17. [Compatibility and versioning](#compatibility-and-versioning)
|
|
32
|
+
18. [Known limitations](#known-limitations)
|
|
33
|
+
19. [Contributing](#contributing)
|
|
34
|
+
20. [License](#license)
|
|
34
35
|
|
|
35
36
|
## Pick a methodology
|
|
36
37
|
|
|
@@ -243,6 +244,129 @@ state = writeExt(state, "triage", [...queue, "T-1"]); // returns a new state; un
|
|
|
243
244
|
|
|
244
245
|
Investigation and Experimentation store their record under `ext.investigation` / `ext.experimentation` and mirror it to the deprecated top-level `state.investigation` / `state.experimentation` in memory, so SDK code that reads those fields keeps working. On disk only `ext` is stored: `saveState` leaves the mirror out and `loadState` sets it back to the same record (if a hand-edited `state.json` carries both, `ext` wins). The mirrors are read-only: once `ext.<name>` exists the engine reads only it, and a write to the legacy field is ignored; write through `writeExt`. `readExt(state, "investigation")` (or `"experimentation"`) is typed, and on a state written before 1.2, which has no `ext`, it reads the legacy field.
|
|
245
246
|
|
|
247
|
+
## Composable policies
|
|
248
|
+
|
|
249
|
+
`ex-workflow/policies` holds policies you opt into per run by wrapping a methodology. A wrapped methodology keeps every other member, its `name` included, so it runs on the same core and its state persists through the file adapter like the plain one's. The policies are SDK-only: `exwf` runs the plain built-in factory (see [Known limitations](#known-limitations)).
|
|
250
|
+
|
|
251
|
+
### Risk-adaptive gates
|
|
252
|
+
|
|
253
|
+
A gate's requirements are static: the same approval for a typo fix and a production change. `withRiskGate` lets the item's recorded risk add to them, never take away:
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
import { addItem, complete, decide, init, next } from "ex-workflow";
|
|
257
|
+
import { kanban } from "ex-workflow/kanban";
|
|
258
|
+
import { recordRiskAssessment, withRiskGate } from "ex-workflow/policies";
|
|
259
|
+
|
|
260
|
+
const m = withRiskGate(kanban(), { gates: ["code-review"] }); // only these gate ids escalate
|
|
261
|
+
// ... init with a review stage carrying gate { id: "code-review", requires: [{ capability: "review" }], ... }
|
|
262
|
+
|
|
263
|
+
// after the work, an independent role with capability verify (or "human") assesses the item
|
|
264
|
+
state = recordRiskAssessment(state, m, {
|
|
265
|
+
item: "CART-12",
|
|
266
|
+
level: "high", // "low" | "medium" | "high" | "critical"
|
|
267
|
+
factors: ["prod-infra", "secrets"], // free strings
|
|
268
|
+
ref: "risk/CART-12.md", // the host's assessment artifact
|
|
269
|
+
subject: "3f2c1e0", // optional: the SHA or ref assessed
|
|
270
|
+
by: "risk-reviewer",
|
|
271
|
+
}).state;
|
|
272
|
+
|
|
273
|
+
// the reviewer completes as usual: low passes on the static gate, high raises a human pending
|
|
274
|
+
const done = complete(state, m, handoff, accounting);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
- **The assessment** is evidence `risk-assessment` with `data: { level, factors, subject? }`, recorded through `applyAction` (action `risk.assess`, so your rules see it). `recordRiskAssessment` refuses `invalid-input` for an unknown key or level, a non-string factor, an empty `ref`, an assessor that is neither `human` nor a role with capability `verify`, and an assessor that worked on the item: any role that dispatched it since its last rework (every stage, not only the last), its assigned role, or its author.
|
|
278
|
+
- **Which assessment counts:** only fresh ones (recorded after the item's last rework), with well-formed `data`, by a qualified and independent assessor (re-checked when the gate is resolved). The strictest one wins, so a later, lower assessment does not relax an earlier one; only rework does. With none, the level is `critical`.
|
|
279
|
+
- **The table** says what each level adds to the static gate. `DEFAULT_RISK_TABLE`:
|
|
280
|
+
|
|
281
|
+
| Level | Adds |
|
|
282
|
+
|---|---|
|
|
283
|
+
| `low`, `medium` | nothing |
|
|
284
|
+
| `high`, `critical` | `"human"` |
|
|
285
|
+
|
|
286
|
+
Pass your own as `withRiskGate(m, { gates, table })`: every level needs a row `{ requires: GateRequirement[]; evidence?: string[] }`, and a stricter level must include everything the level below it adds, so a missing or rejected assessment (`critical`) never asks for less than a `low` one. E.g. `medium: { requires: [{ capability: "security-review" }], evidence: ["sbom"] }` with `high` and `critical` both `{ requires: [{ capability: "security-review" }, "human"], evidence: ["sbom"] }`. Invalid options fail `invalid-input` when you wrap.
|
|
287
|
+
- **`gate.resolved`**: on a gated completion, `complete()` appends `gate.resolved { item, gate, requires, evidence, reason }` before `gate.passed` or `pending.raised`, with the requirements actually checked and `reason: { level, why, assessment, by }` (`why` is `assessed`, `missing`, `invalid` or `not-independent`). A gate the policy does not name records the static gate with `reason: {}`.
|
|
288
|
+
- **`decide`** judges a pending gate against the `gate.resolved` that `complete()` recorded with that pending (a resolution appended later does not apply; with none, the static gate applies), so a role cannot approve an escalation to a human, also through `exwf decide`.
|
|
289
|
+
- **Any methodology** may implement the hook itself: `Methodology.escalateGate(state, item, gate)` returns `{ requires, evidence, reason }` or `undefined`. Core only appends what it returns to the static gate, so a hook can tighten a gate but never loosen it. `withRiskGate` keeps an existing hook and widens with both.
|
|
290
|
+
- `riskEscalation(state, item, gate, options)` is the resolver on its own, for hosts that want the answer without wrapping; it validates `options` the same way (`invalid-input`).
|
|
291
|
+
|
|
292
|
+
### Context-grounded entry
|
|
293
|
+
|
|
294
|
+
A worker that starts from a stale picture of the repository builds on assumptions nobody checked. `withContextGrounding` lets an item enter a stage only with a fresh context snapshot that cites at least one source and that `human` or a registered role other than the item's workers recorded:
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
import { next } from "ex-workflow";
|
|
298
|
+
import { kanban } from "ex-workflow/kanban";
|
|
299
|
+
import {
|
|
300
|
+
recordContextSnapshot,
|
|
301
|
+
recordRepoChange,
|
|
302
|
+
withContextGrounding,
|
|
303
|
+
} from "ex-workflow/policies";
|
|
304
|
+
|
|
305
|
+
const m = withContextGrounding(kanban(), { entry: ["dev"] }); // optional: exit: ["dev"]
|
|
306
|
+
// init with m: the dev column's entry policies gain { kind: "custom", id: "context-grounded" }
|
|
307
|
+
|
|
308
|
+
// a scout (a registered role that does not work on the item, or "human") records what it verified
|
|
309
|
+
state = recordContextSnapshot(state, m, {
|
|
310
|
+
item: "CART-12",
|
|
311
|
+
revision: "4f2c1e0",
|
|
312
|
+
assumptions: [
|
|
313
|
+
{
|
|
314
|
+
claim: "cart totals are integer cents",
|
|
315
|
+
required: true,
|
|
316
|
+
source: { path: "src/cart.ts", lines: [10, 24], hash: "9b1d…" },
|
|
317
|
+
},
|
|
318
|
+
{ claim: "no caching layer in front of the cart" }, // no source: unverified
|
|
319
|
+
],
|
|
320
|
+
ref: "ctx/CART-12.json", // the host's snapshot artifact
|
|
321
|
+
by: "scout", // a role registered in the state
|
|
322
|
+
}).state;
|
|
323
|
+
|
|
324
|
+
const { briefs } = next(state, m); // brief.context: what was verified, where, what went stale
|
|
325
|
+
|
|
326
|
+
// the host reports what each new revision changed
|
|
327
|
+
const changed = recordRepoChange(state, m, {
|
|
328
|
+
revision: "a71b2d9",
|
|
329
|
+
paths: ["src/cart.ts"], // as `git diff --name-only -z` lists them
|
|
330
|
+
by: "ci",
|
|
331
|
+
});
|
|
332
|
+
changed.warnings; // context-stale for each in-flight item whose snapshot cites a changed path
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
- **The snapshot** is evidence `context-snapshot` with `data: { revision, assumptions }`, recorded through `applyAction` (action `context.snapshot`). An assumption is `{ claim, required?, source?: { path, lines?: [from, to], hash } }`; one without a `source` is unverified. `recordContextSnapshot` refuses `invalid-input` for a snapshot with no sourced assumption and for a `by` that is neither `human` nor a registered role, or that worked on the item (dispatched it since its last rework, is assigned to it, or authored it). The engine compares paths and hashes, it never reads a file.
|
|
336
|
+
- **Paths** are repository-relative POSIX paths as Git lists them, compared exactly (case included): `src/cart.ts`, not `./src/cart.ts`, `/src/cart.ts` or `src\cart.ts`. They must also be Unicode NFC (macOS file systems may hand you NFD), at most 4096 characters, with no control or bidirectional formatting character and no leading or trailing whitespace. Read them from `git diff --name-only -z` (NUL-separated and unquoted) or with `git -c core.quotePath=false`: by default Git prints a non-ASCII name quoted and escaped (`"caf\303\251.ts"`), which is refused. Both recorders refuse any other spelling with `invalid-input`.
|
|
337
|
+
- **`repo.changed`**: `recordRepoChange` (action `repo.change`) appends `repo.changed { revision, paths }`. A snapshot is stale when a later `repo.changed` lists a path it cites (event order, not timestamps; the revision alone does not decide). No item status changes: an item in `in_progress`, `review` or `awaiting_human` gets a `context-stale` warning in `ApplyResult.warnings` when this change made its snapshot stale, and a `todo` item is re-checked by its entry policy when the planner reaches it.
|
|
338
|
+
- **The policy** (`contextGroundedViolations`, rule `policy:custom:context-grounded`) fails an item with no qualifying fresh snapshot, with a stale one, or with a `required` assumption that has no source. A snapshot qualifies when its data is valid, it has at least one sourced assumption and `human` or a registered role that does not work on the item recorded it; the latest qualifying one counts, so a snapshot a worker wrote into the state by hand never replaces an independent one, and one recorded by a role that later works on the item stops counting. Rework drops every snapshot. `next` reports such a `todo` item under `skipped` with reason `entry-policy` and the message. A qualifying snapshot whose required claims are all sourced passes; unverified optional claims are listed in `brief.context.unverified`.
|
|
339
|
+
- **`brief.context`** is `contextOf(state, item)`: `{ revision, assumptions, snapshot, by, stale, unverified }`.
|
|
340
|
+
- **Any methodology** may answer custom policies itself: `Methodology.customPolicy(state, item, policy)` returns the violations, or `undefined` for the default check (evidence `policy:<id>`); `Methodology.briefContext(state, item)` fills `brief.context`. `withContextGrounding` keeps existing hooks for every other policy id and composes with `withRiskGate` in either order.
|
|
341
|
+
|
|
342
|
+
### Comparing runs
|
|
343
|
+
|
|
344
|
+
`compareRuns` compares finished runs of two or more variants (a variant is whatever the host changed: a role's model tier, a config, a methodology). It is a pure function over `WorkflowState` values; the scenario suite, running each variant and scoring stay with the host.
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
import { loadState } from "ex-workflow/adapters";
|
|
348
|
+
import { compareRuns } from "ex-workflow/policies";
|
|
349
|
+
|
|
350
|
+
const result = compareRuns(
|
|
351
|
+
[
|
|
352
|
+
{ variant: "V0", scenario: "bug-fix-1", passed: true, state: await loadState(dirV0Bug1) },
|
|
353
|
+
{ variant: "V1", scenario: "bug-fix-1", passed: true, state: await loadState(dirV1Bug1) },
|
|
354
|
+
// ... one record per variant and scenario run; a scenario may run more than once
|
|
355
|
+
],
|
|
356
|
+
{ baseline: "V0", mustPass: ["bug-fix-1"], passTolerance: 0.1, costTolerance: 0.05 },
|
|
357
|
+
);
|
|
358
|
+
result.winner; // "V1", or null when no eligible variant beats the baseline beyond the tolerances
|
|
359
|
+
result.reason; // why
|
|
360
|
+
result.variants; // ranked VariantResult[]: { variant, runs, passed, passRate, mean, regressions, missing, eligible }
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
- **`passed`** is your scorer's verdict for that run. The engine derives the rest from the state: `mean` holds, per variant, the mean of `tokens` (accounting `tokensIn + tokensOut`, after corrections), `durationMs`, `turns` (accounting lines), `humanInterventions` (`pending.raised` plus `blocker.cleared` events), `reworks`, `escalations` and `itemsDone`.
|
|
364
|
+
- **`passRate`** weighs each scenario once: the mean over the scenarios the variant ran of the share of that scenario's runs that passed, so more runs of an easy scenario do not raise it; `runs` and `passed` count runs.
|
|
365
|
+
- **Eligible** means no `mustPass` scenario has a failing run (`regressions`) and the variant ran every scenario the baseline ran and every `mustPass` one (`missing`).
|
|
366
|
+
- **Ranking**: eligible first, then `passRate` descending, then mean tokens, mean duration and mean human interventions ascending, then the variant id in code-unit order. The input order of `runs` never changes the result.
|
|
367
|
+
- **Winner**: the first ranked eligible variant other than the baseline whose `passRate` is at least the baseline's minus `passTolerance` and that is better, by a `passRate` above the baseline's plus `passTolerance` or by mean tokens below the baseline's times `1 - costTolerance`. Tolerances are fractions in `[0, 1]`, default `0`.
|
|
368
|
+
- **Refused with `invalid-input`**: no runs, a non-array `runs`, an id that is not a valid id (`__proto__`, `toString` and the like included), a baseline or `mustPass` scenario no run names, a tolerance outside `[0, 1]`, a non-boolean `passed`, a state without `events`, `accounting` and `items`, a non-finite or negative token or duration figure, and token or duration totals or means that overflow to infinity. Only own properties of the options, run records and states are read (an inherited `{ __proto__: … }` value counts as absent). Variants of different methodologies compare on the same metrics.
|
|
369
|
+
|
|
246
370
|
## CLI reference (`exwf`)
|
|
247
371
|
|
|
248
372
|
Run from the directory that holds `.workflow/`. Every command prints JSON on stdout. Exit 0 = ok, exit 1 = `{ ok: false, error }`, exit 2 = usage. `--by` defaults to `human`. Flags take `--flag value` (not `--flag=value`); a value that starts with `--` must come through a JSON input file.
|
|
@@ -382,7 +506,8 @@ Every config is validated at `init` (`config-invalid` names the key and an examp
|
|
|
382
506
|
{ item, role, modelTier, invariants, do_not, acceptance,
|
|
383
507
|
upstream, // results of the items this one depends on
|
|
384
508
|
priorHandoffs, // earlier attempts at this item (rework feedback)
|
|
385
|
-
relatedBugs, budgetRemaining, gateAhead
|
|
509
|
+
relatedBugs, budgetRemaining, gateAhead,
|
|
510
|
+
context } // with withContextGrounding: the item's context snapshot
|
|
386
511
|
```
|
|
387
512
|
|
|
388
513
|
**Handoff** (what your agent gives back):
|
|
@@ -436,6 +561,7 @@ The CLI validates state, role manifests, items, patches and handoffs with these
|
|
|
436
561
|
| `ex-workflow/investigation` | `investigation()`, `validateInvestigationConfig`; types `InvestigationConfig`, `InvestigationState`, `InvestigationRound`, `InvestigationConclusion`, `Hypothesis`, `Experiment`, `Observation`, `BeliefUpdate` |
|
|
437
562
|
| `ex-workflow/experimentation` | `experimentation()`, `validateExperimentationConfig`, `experimentationCeremonies`, `experimentationMetrics`, `experimentationReport`, `experimentationRoles`, `experimentationRules`, `experimentationStages`; types `ExperimentationConfig`, `ExperimentationState`, `ExperimentCandidate` |
|
|
438
563
|
| `ex-workflow/registry` | `registerMethodology`, `methodologyFactory`, `registeredMethodologies` (five built-ins pre-registered); types `MethodologyFactory`, `MethodologyRegistry` |
|
|
564
|
+
| `ex-workflow/policies` | `withRiskGate`, `recordRiskAssessment`, `riskEscalation`, `DEFAULT_RISK_TABLE`, `withContextGrounding`, `recordContextSnapshot`, `recordRepoChange`, `contextOf`, `contextGroundedViolations`, `compareRuns`; types `RiskLevel`, `RiskTable`, `RiskAssessmentData`, `RiskAssessmentInput`, `RiskGateOptions`, `ContextGroundingOptions`, `ContextSnapshotInput`, `RepoChangeInput`, `CompareRunsOptions`, `RunRecord`, `RunMetrics`, `VariantResult`, `RunComparison` (`ContextAssumption`, `ContextSnapshotData` and `BriefContext` come from the root entry) |
|
|
439
565
|
| `ex-workflow/adapters` | `loadState`, `saveState`, `saveBrief`, `saveHandoff`, `withStateLock`, `WORKFLOW_DIR` |
|
|
440
566
|
| `ex-workflow/schema` | the ten schema documents, `validate`, `assertValid` |
|
|
441
567
|
| `ex-workflow/cli` | `runCommand`, `parseArgs`, `USAGE`: the `exwf` command as a library |
|
|
@@ -445,7 +571,7 @@ Each entry ships ESM, CommonJS and `.d.ts`. Core plus one methodology is about 5
|
|
|
445
571
|
|
|
446
572
|
## Compatibility and versioning
|
|
447
573
|
|
|
448
|
-
- Semver from 1.0.0. The public surface (exports of every entry point, the CLI commands, the ten schema documents, the
|
|
574
|
+
- Semver from 1.0.0. The public surface (exports of every entry point, the CLI commands, the ten schema documents, the 71 event kinds) is frozen by test: a removal is a major version, an addition a minor one.
|
|
449
575
|
- A `.workflow/state.json` written by any earlier release loads unchanged; the test suite replays state files from every published pre-release.
|
|
450
576
|
- **Deprecated in 1.2:** the top-level `state.investigation` and `state.experimentation` fields. They are still set in memory and for SDK readers, as read-only mirrors of `ext.investigation` / `ext.experimentation` (on disk only `ext` is written; `loadState` restores the mirror), so SDK code reading `state.investigation` / `state.experimentation` sees the same record; once `ext.<name>` exists a write to the legacy field is ignored. Read with `readExt` and write with `writeExt` instead. The mirrors do not make a 1.2 state loadable by 1.1.x (see [Known limitations](#known-limitations)). 2.0 removes the mirrors.
|
|
451
577
|
- Behaviour changes are listed per release in [CHANGELOG.md](CHANGELOG.md).
|
|
@@ -456,6 +582,12 @@ Deliberate, documented, and stable within 1.x.
|
|
|
456
582
|
|
|
457
583
|
- **A custom methodology's state cannot go through the file adapter or the CLI.** The state schema accepts only the five built-in names in `methodology`, so `saveState`, `loadState` and every `exwf` command refuse it. Keep such a state through the SDK and persist it yourself.
|
|
458
584
|
- **No downgrade for Investigation and Experimentation.** 1.1.x cannot load a state that 1.2 wrote for those two methodologies: the 1.1 state schema rejects the `ext` field, and the legacy mirrors do not change that. Keep a run on 1.2 once 1.2 has saved it.
|
|
585
|
+
- **No downgrade for a state with evidence `data`.** 1.2.x cannot load a state carrying `Evidence.data` (a risk assessment or context snapshot recorded by `ex-workflow/policies`): its schema closes `Evidence`. Keep such a run on 1.3.
|
|
586
|
+
- **Policies are SDK-only.** `exwf` runs the plain built-in methodology, so `exwf complete` checks a gate's static requirements only. `exwf decide` does honour an escalation the SDK recorded (`gate.resolved`). Run completions of a risk-gated run through the SDK. There is no CLI command for snapshots or repository changes.
|
|
587
|
+
- **Without the wrapper, `context-grounded` is only as strong as the 1.2 custom-policy check.** On a stage carrying the policy, `exwf next` and `exwf complete` (and any SDK call with the plain methodology) fall back to the default check: the item passes when it carries fresh evidence of kind `policy:context-grounded`. That evidence is not tied to a snapshot, and `complete()` records every `handoff.produced` entry as evidence, so a worker can attest the policy for its own item by listing `{ kind: "policy:context-grounded", ref }` in a handoff. An item without that evidence is skipped. Plan and complete a grounded run through the SDK with `withContextGrounding`, which ignores such evidence and checks the snapshot.
|
|
588
|
+
- **Context grounding on an existing state, and Kanban policy changes.** `withContextGrounding` adds its policy through `defaultStages`, so it reaches a state at `init`; for a state created before wrapping, add `{ kind: "custom", id: "context-grounded", description }` to the stage's `entryPolicy` yourself. A Kanban `operations-review` that changes the commitment column's policies rewrites the next column's entry policies and drops it; add it back the same way.
|
|
589
|
+
- **Independence at entry needs a known worker.** The policy compares the snapshot's recorder with the roles that worked on the item. A `todo` item never dispatched and without a `role` has no worker yet (the planner picks one after the entry check), so a snapshot by the role the planner then picks passes the entry check. Once that role is dispatched its snapshot stops counting: `contextOf` falls back to the latest earlier qualifying snapshot, which may be stale (the brief carries it with its `stale` paths, and an `exit` policy fails on it), or, with none, the brief has no `context` and an `exit` policy fails. For the same reason, before dispatch that future worker can record a weaker sourced snapshot (its `required` claims dropped) that supersedes a stale independent one, and the item is then dispatched to it. Set `role` on the item, or also pass `exit`, to have the check apply before the work.
|
|
590
|
+
- **`checkGate` alone sees the static gate.** The risk escalation is applied by `complete()` and `decide()`; a host calling `checkGate` directly gets the 1.2 answer.
|
|
459
591
|
|
|
460
592
|
- **Stale lock takeover** narrows the race to the gap between the stat and the unlink; no portable call closes it. On file systems without inodes (FAT, exFAT, some shares) only the mtime is compared. If a stale lock cannot be unlinked (read-only directory, EPERM), the command gives up after its retries with `invalid-input` naming the lock file; delete it by hand.
|
|
461
593
|
- **Item ids that differ only in letter case cannot both get a brief file.** On macOS and Windows `briefs/A.json` and `briefs/a.json` are one file, so `exwf next` checks every brief name of the batch first and, when an item's id differs from another item's (in the same batch, or with an existing brief) only in case, refuses the whole dispatch with `invalid-input` naming both: no brief is written and the state is unchanged. `saveBrief` refuses such an id the same way. Give ids that differ by more than case (re-add one item under a new id).
|
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkKA6DVHO5_cjs=require('../chunk-KA6DVHO5.cjs');require('../chunk-BBI7AKJK.cjs'),require('../chunk-DVFTTBCT.cjs'),require('../chunk-OSHBJIYD.cjs');Object.defineProperty(exports,"WORKFLOW_DIR",{enumerable:true,get:function(){return chunkKA6DVHO5_cjs.a}});Object.defineProperty(exports,"loadState",{enumerable:true,get:function(){return chunkKA6DVHO5_cjs.e}});Object.defineProperty(exports,"saveBrief",{enumerable:true,get:function(){return chunkKA6DVHO5_cjs.g}});Object.defineProperty(exports,"saveHandoff",{enumerable:true,get:function(){return chunkKA6DVHO5_cjs.h}});Object.defineProperty(exports,"saveState",{enumerable:true,get:function(){return chunkKA6DVHO5_cjs.d}});Object.defineProperty(exports,"statePath",{enumerable:true,get:function(){return chunkKA6DVHO5_cjs.b}});Object.defineProperty(exports,"withStateLock",{enumerable:true,get:function(){return chunkKA6DVHO5_cjs.c}});//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/adapters/index.d.ts
CHANGED
package/dist/adapters/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as WORKFLOW_DIR,e as loadState,g as saveBrief,h as saveHandoff,d as saveState,b as statePath,c as withStateLock}from'../chunk-
|
|
1
|
+
export{a as WORKFLOW_DIR,e as loadState,g as saveBrief,h as saveHandoff,d as saveState,b as statePath,c as withStateLock}from'../chunk-ONVAUZOD.mjs';import'../chunk-TQR3VFZU.mjs';import'../chunk-QJMOCISZ.mjs';import'../chunk-YS6CXERQ.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as WorkflowState, C as Capability, R as Role, a as Budget, A as Accounting } from './types-
|
|
1
|
+
import { W as WorkflowState, C as Capability, R as Role, a as Budget, A as Accounting } from './types-DLOtndDY.js';
|
|
2
2
|
|
|
3
3
|
declare function requireCapabilities(state: WorkflowState<string>, required: Capability[], exclusive: Capability[]): void;
|
|
4
4
|
declare function requireCapabilities(state: WorkflowState, required: Capability[], exclusive: Capability[]): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as WorkflowState, C as Capability, R as Role, a as Budget, A as Accounting } from './types-
|
|
1
|
+
import { W as WorkflowState, C as Capability, R as Role, a as Budget, A as Accounting } from './types-DLOtndDY.cjs';
|
|
2
2
|
|
|
3
3
|
declare function requireCapabilities(state: WorkflowState<string>, required: Capability[], exclusive: Capability[]): void;
|
|
4
4
|
declare function requireCapabilities(state: WorkflowState, required: Capability[], exclusive: Capability[]): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var chunkGKN5M4B7_cjs=require('./chunk-GKN5M4B7.cjs'),chunkW2P27645_cjs=require('./chunk-W2P27645.cjs'),chunkZ43GUETW_cjs=require('./chunk-Z43GUETW.cjs'),chunkOSHBJIYD_cjs=require('./chunk-OSHBJIYD.cjs'),exsorted=require('exsorted');var Be=chunkGKN5M4B7_cjs.a(["requirements","design","implementation","verification","deployment","maintenance"]),ae=chunkGKN5M4B7_cjs.a({requirements:["srs"],design:["design-doc","interface-spec"],implementation:["code-baseline"],verification:["test-report","traceability-matrix"],deployment:["release-notes","deployment-record"],maintenance:["change-log"]}),oe=chunkGKN5M4B7_cjs.a({requirements:"business-analyst",design:"architect",deployment:"release-manager"}),me=e=>`${e}-gate`,ge="change-control",Ee=["order-backlog","define-acceptance","facilitate","deliver","review","verify","approve-gate","manage-flow","control-change","escalate"],Me=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ge(){return Be.map(e=>{let t={id:e,name:Me(e),deliverables:[...ae[e]??[]],gate:{id:me(e),requires:[{capability:"approve-gate"}],evidence:[],onFail:{action:"block"}}},n=oe[e];return n!==void 0&&(t.deliverBy=n),t})}function w(e){return e.config}var G=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),se=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&t.trim()!=="");function Je(e,t){if(e===void 0)return;G(e)||chunkOSHBJIYD_cjs.b("config-invalid",`${t}.budget must be an object`,'e.g. { "tokens": 400000 }');let n={};for(let a of ["tokens","turns","wallclockMs"]){let p=e[a];p!==void 0&&((typeof p!="number"||!Number.isFinite(p)||p<0)&&chunkOSHBJIYD_cjs.b("config-invalid",`${t}.budget.${a} must be a non-negative number`,"omit it for no limit"),n[a]=p);}return n}function _e(e,t){return (!Array.isArray(e)||e.length===0)&&chunkOSHBJIYD_cjs.b("config-invalid",`${t} must be a non-empty array of "human" | { capability }`,'e.g. ["human", { "capability": "approve-gate" }]'),e.map(n=>n==="human"?"human":G(n)&&typeof n.capability=="string"&&Ee.includes(n.capability)?{capability:n.capability}:chunkOSHBJIYD_cjs.b("config-invalid",`${t} entry ${JSON.stringify(n)} is not "human" or a known capability`,`use "human" or { "capability": one of ${Ee.join(", ")} }`))}function De(e,t,n){let a=`waterfall config.phases[${t}]`;G(e)||chunkOSHBJIYD_cjs.b("config-invalid",`${a} must be an object`,'e.g. { "id": "design" }'),chunkOSHBJIYD_cjs.c(e.id,`${a}.id`);let p=e.id,d=e.deliverables??(Object.hasOwn(ae,p)?ae[p]:void 0)??[];se(d)||chunkOSHBJIYD_cjs.b("config-invalid",`${a}.deliverables must be a string[] of evidence kinds`,'e.g. ["srs"]');let o;if(e.gate===void 0)o={id:me(p),requires:[{capability:"approve-gate"}],evidence:[],onFail:{action:"block"}};else {let l=e.gate;(!G(l)||typeof l.id!="string"||l.id.trim()==="")&&chunkOSHBJIYD_cjs.b("config-invalid",`${a}.gate must be a Gate with an id`,'e.g. { "id": "design-gate", "requires": [{ "capability": "approve-gate" }], "evidence": [] }');let f=l.evidence??[];se(f)||chunkOSHBJIYD_cjs.b("config-invalid",`${a}.gate.evidence must be a string[]`,"list evidence kinds or omit it"),o={id:l.id,requires:_e(l.requires??[{capability:"approve-gate"}],`${a}.gate.requires`),evidence:[...f],onFail:{action:"block"}};}n(p)&&!o.requires.includes("human")&&(o.requires=["human",...o.requires]);let c={id:p,name:typeof e.name=="string"&&e.name.trim()!==""?e.name:Me(p),deliverables:[...d],gate:o},i=Je(e.budget,a);i!==void 0&&(c.budget=i);let s=e.deliverBy??(Object.hasOwn(oe,p)?oe[p]:void 0);return s!==void 0&&((typeof s!="string"||s.trim()==="")&&chunkOSHBJIYD_cjs.b("config-invalid",`${a}.deliverBy must be a role id`,"name the role that delivers this phase or omit it"),c.deliverBy=s),c}function he(e){let t=e??{};t.phases!==void 0&&!Array.isArray(t.phases)&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.phases must be an array of phases","omit phases for the six classic phases");let n=t.humanGates??"all";n!=="all"&&!se(n)&&chunkOSHBJIYD_cjs.b("config-invalid",'waterfall config.humanGates must be "all" or a string[] of phase ids','omit it for "all"');let a=n==="all"?()=>true:r=>n.includes(r),p=t.phases===void 0?Ge().map((r,m)=>De(r,m,a)):t.phases.map((r,m)=>De(r,m,a));p.length===0&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.phases needs at least one phase",'e.g. [{ "id": "requirements" }]');let d=p.map(r=>r.id),o=d.find((r,m)=>d.indexOf(r)!==m);if(o!==void 0&&chunkOSHBJIYD_cjs.b("config-invalid",`duplicate phase id "${o}"`,"give every phase a unique id"),n!=="all")for(let r of n)d.includes(r)||chunkOSHBJIYD_cjs.b("config-invalid",`waterfall config.humanGates names unknown phase "${r}"`,`phases are: ${d.join(", ")}`);let c=t.changeControl??{};G(c)||chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.changeControl must be an object",'e.g. { "requiresImpactAnalysis": true, "approvers": ["human"] }'),c.requiresImpactAnalysis!==void 0&&typeof c.requiresImpactAnalysis!="boolean"&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.changeControl.requiresImpactAnalysis must be a boolean","omit it for true");let i={requiresImpactAnalysis:c.requiresImpactAnalysis===void 0?true:c.requiresImpactAnalysis,approvers:_e(c.approvers??["human",{capability:"control-change"}],"waterfall config.changeControl.approvers")},s=t.traceability,l;if(s===void 0)l=d.includes("requirements")&&d.includes("design")&&d.includes("verification")?{from:"requirements",to:["design","verification"]}:{from:d[0],to:[]};else {(!G(s)||typeof s.from!="string"||!d.includes(s.from))&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.traceability.from must be a phase id",`phases are: ${d.join(", ")}`);let r=s.to??[];se(r)||chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.traceability.to must be a string[] of phase ids",`phases are: ${d.join(", ")}`);for(let m of r)d.includes(m)||chunkOSHBJIYD_cjs.b("config-invalid",`waterfall config.traceability.to names unknown phase "${m}"`,`phases are: ${d.join(", ")}`),d.indexOf(m)<=d.indexOf(s.from)&&chunkOSHBJIYD_cjs.b("config-invalid",`waterfall config.traceability.to phase "${m}" must come after "${s.from}"`,"trace forward only: from an earlier phase to later ones");l={from:s.from,to:[...r]};}let f=t.fallbackTokensPerWeight;f!==void 0&&(typeof f!="number"||!Number.isFinite(f)||f<=0)&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.fallbackTokensPerWeight must be a positive finite number","omit it for the default 20000");let u={phases:p,changeControl:i,traceability:l,humanGates:n==="all"?"all":[...n]};return f!==void 0&&(u.fallbackTokensPerWeight=f),u}var L="work",V="review",z="done";function b(e){return e.phases?e.phases:w(e).phases.map(t=>{let n={id:t.id,name:t.name,deliverables:[...t.deliverables],gate:t.gate,status:"pending"};return t.budget&&(n.budget=t.budget),n})}function T(e,t){return {...e,phases:t}}function E(e,t){let n=b(e).findIndex(a=>a.id===t);return n<0&&chunkOSHBJIYD_cjs.b("config-invalid",`unknown phase "${t}"`,`phases are: ${b(e).map(a=>a.id).join(" \u2192 ")}`),n}function _(e,t){return b(e)[E(e,t)]}function q(e,t){let n=new Set,a=t;for(;a&&!n.has(a.id);){if(a.phase!==void 0)return a.phase;n.add(a.id),a=a.parent!==void 0&&Object.hasOwn(e.items,a.parent)?e.items[a.parent]:void 0;}}function P(e,t){return Object.values(e.items).filter(n=>n.status!=="dropped"&&q(e,n)===t)}function D(e){return b(e).find(t=>t.status==="open")}function ye(e){return b(e).find(t=>t.status!=="baselined")}function Qe(e,t){let n=q(e,t);return n!==void 0&&b(e).find(a=>a.id===n)?.status==="baselined"}function Fe(e,t){let n=new Set((t.produced??[]).map(a=>a.kind));for(let a of P(e,t.id))for(let p of a.evidence)n.add(p.kind);return n}function H(e,t,n=[]){let a=Fe(e,t);for(let d of n)a.add(d);let p=[];for(let d of [...t.deliverables,...t.gate.evidence])p.includes(d)||p.push(d);return p.filter(d=>!a.has(d))}function B(e){let t=b(e).map(a=>a.id),n=w(e).traceability.to.filter(a=>t.includes(a));if(n.length!==0)return n.reduce((a,p)=>t.indexOf(a)>=t.indexOf(p)?a:p)}function Ne(e,t,n,a){let p=chunkZ43GUETW_cjs.N(e);return !p||!p.id.startsWith(`${t}#`)?e:{...e,iterations:e.iterations.map(d=>d.id===p.id?{...d,endedAt:a,outcome:n}:d)}}function ce(e,t,n,a){let p=_(e,t);p.status!=="open"&&chunkOSHBJIYD_cjs.b("invalid-transition",`phase "${t}" is ${p.status}, not open`,p.status==="baselined"?"it is already baselined; a change-request reopens it":"kickoff the phase first");let d=P(e,t),o={};for(let l of d)o[l.id]=l;let c=(e.baselines??[]).filter(l=>l.phase===t).length,i={phase:t,version:c+1,at:a,approvedBy:n,itemSnapshot:o},s=T(e,b(e).map(l=>l.id===t?{...l,status:"baselined"}:l));return s={...s,baseline:i,baselines:[...s.baselines??[],i]},s=Ne(s,t,"completed",a),chunkZ43GUETW_cjs.c(s,"phase.baselined",n[n.length-1]??"system",{phase:t,version:i.version,approvedBy:n,items:d.map(l=>l.id)},a)}function be(e,t,n){let a=[];for(let c of t){let i=_(e,c);i.status==="pending"&&chunkOSHBJIYD_cjs.b("invalid-input",`phase "${c}" was never baselined; there is nothing to reopen`,"remove it from impactAnalysis.reopen"),i.status==="baselined"&&!a.includes(c)&&a.push(c);}let p=b(e).map(c=>a.includes(c.id)?{...c,status:"reopened"}:c),d=null,o=e;if(a.length){let c=Math.min(...a.map(s=>E(e,s))),i=p.find((s,l)=>s.status==="open"&&l>c);i&&(d=i.id,p=p.map(s=>s.id===i.id?{...s,status:"reopened"}:s),o=Ne(o,i.id,"cancelled",n));}return {state:T(o,p),reopened:a,suspended:d}}function U(e,t,n,a,p){let d=chunkZ43GUETW_cjs.r(e,t),o=d.impactAnalysis,c=be(e,o?.reopen??[],p),i=chunkZ43GUETW_cjs.u(c.state,t,{stage:z,status:"done"},n,p);for(let s of c.reopened)i=chunkZ43GUETW_cjs.c(i,"phase.reopened",n,{phase:s,change:t},p);return c.suspended!==null&&(i=chunkZ43GUETW_cjs.c(i,"phase.suspended",n,{phase:c.suspended,change:t},p)),chunkZ43GUETW_cjs.c(i,"change.decided",n,{change:t,decision:"approve",by:n,note:a,reopened:c.reopened,suspended:c.suspended,weight:o?.weight??0,affects:d.affects??[]},p)}function K(e,t,n,a,p){let d=chunkZ43GUETW_cjs.r(e,t),o=chunkZ43GUETW_cjs.u(e,t,{status:"dropped"},n,p);return chunkZ43GUETW_cjs.c(o,"change.decided",n,{change:t,decision:"reject",by:n,note:a,reopened:[],suspended:null,weight:0,affects:d.affects??[]},p)}function Le(e){return (t,n)=>{chunkZ43GUETW_cjs.m(t,n.by,"facilitate");let a=n.phase===void 0?void 0:Y(t,n,"phaseRetrospective"),p=chunkW2P27645_cjs.a(t,n,"phaseRetrospective");return chunkZ43GUETW_cjs.U(t,e(),{type:"ceremony.phaseRetrospective",by:n.by,payload:n},d=>{let o=d,c=chunkZ43GUETW_cjs.a(n.now),i=chunkW2P27645_cjs.b(o,p,n.by,c);return o=i.state,chunkZ43GUETW_cjs.c(o,"phase.retrospective",n.by,{phase:a?.id??null,lessons:i.created,adopted:i.adopted.slice(i.created.length),dismissed:i.dismissed,agreements:i.agreements,retired:i.retired},c)})}}var Xe=(e,t)=>e.id<t.id?-1:e.id>t.id?1:0,Ve=(e,t)=>exsorted.timSort(P(e,t).filter(n=>n.type!=="question"&&n.type!=="change-request"),Xe),et=(e,t)=>(e.traces??[]).includes(t.id)||(t.traces??[]).includes(e.id);function I(e){let t=w(e).traceability,n=b(e).map(o=>o.id),a=t.to.filter(o=>n.includes(o)),p=Ve(e,t.from).map(o=>{let c={};for(let i of a)c[i]=Ve(e,i).filter(s=>et(o,s)).map(s=>s.id);return {item:o.id,links:c}}),d=p.map(o=>({item:o.item,phases:a.filter(c=>o.links[c].length===0)})).filter(o=>o.phases.length>0);return {from:t.from,to:a,rows:p,missing:d,coverage:{traced:p.length-d.length,total:p.length}}}function J(e,t){return I(e).rows.filter(n=>(n.links[t]??[]).length===0).map(n=>n.item)}var tt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Y(e,t,n){let a=t.phase;return (typeof a!="string"||a.trim()==="")&&chunkOSHBJIYD_cjs.b("invalid-input",`${n} needs phase: string`,`pass one of: ${b(e).map(p=>p.id).join(", ")}`),_(e,a)}function ze(e,t,n,a,p,d){let o=T(e,b(e).map(c=>c.id===t?{...c,produced:[...c.produced??[],{kind:n,ref:a,by:p,at:d}]}:c));return chunkZ43GUETW_cjs.c(o,"phase.deliverable",p,{phase:t,kind:n,ref:a},d)}function ve(e){let t=(d,o,c,i)=>chunkZ43GUETW_cjs.U(d,e(),{type:o,by:c.by,payload:c},s=>i(s,chunkZ43GUETW_cjs.a(c.now)));return {kickoff:(d,o)=>{chunkZ43GUETW_cjs.m(d,o.by,"facilitate");let c=Y(d,o,"kickoff");return t(d,"ceremony.kickoff",o,(i,s)=>{let l=i.events.filter(r=>r.type==="phase.opened"&&r.payload.phase===c.id).length+1,f=P(i,c.id).filter(r=>r.status!=="done").map(r=>r.id);i=T(i,b(i).map(r=>r.id===c.id?{...r,status:"open"}:r));let u=c.budget??{};return i={...i,iterations:[...i.iterations,{id:`${c.id}#${l}`,goal:c.name,budget:u,spent:{...chunkZ43GUETW_cjs.I},startedAt:s,committed:f,carryover:[]}]},chunkZ43GUETW_cjs.c(i,"phase.opened",o.by,{phase:c.id,version:l,items:f,budget:u},s)})},gateReview:(d,o)=>{let c=Y(d,o,"gateReview");c.status!=="open"&&chunkOSHBJIYD_cjs.b("invalid-transition",`phase "${c.id}" is ${c.status}, not open`,c.status==="baselined"?"it is already baselined; a change-request reopens it":`kickoff "${c.id}" first`);let i=c.gate,s=chunkZ43GUETW_cjs.h(d,i.id,"approve-gate");o.by!=="human"&&!s.includes(o.by)&&chunkOSHBJIYD_cjs.b("gate-unmet",`"${o.by}" may not review gate "${i.id}"`,`review as one of: human${s.map(r=>`, ${r}`).join("")}`,{rule:"gate"});let l=d.pending.find(r=>r.kind==="gate"&&r.item===void 0&&r.gate===i.id);l&&chunkOSHBJIYD_cjs.b("no-op",`gate "${i.id}" is already awaiting a decision (${l.id})`,`decide ${l.id} approve|reject`);let f=o.deliverables??[];(!Array.isArray(f)||!f.every(r=>tt(r)&&typeof r.kind=="string"&&r.kind.trim()!==""&&typeof r.ref=="string"))&&chunkOSHBJIYD_cjs.b("invalid-input","gateReview.deliverables must be [{ kind, ref }]",'e.g. { "deliverables": [{ "kind": "srs", "ref": "docs/srs.md" }] }');let u=f;return t(d,"ceremony.gateReview",o,(r,m)=>{for(let h of u)r=ze(r,c.id,h.kind,h.ref,o.by,m);if(w(r).traceability.to.includes(c.id)){let h=I(r);r=chunkZ43GUETW_cjs.c(r,"traceability.computed",o.by,{phase:c.id,from:h.from,to:h.to,coverage:h.coverage,missing:h.missing,rows:h.rows},m),c.id===B(r)&&h.missing.length===0&&(r=ze(r,c.id,"traceability-matrix",`traceability.computed#${r.events[r.events.length-1].seq}`,o.by,m));}if(i.requires.includes("human")&&o.by!=="human"){r=chunkZ43GUETW_cjs.G(r,{kind:"gate",gate:i.id,question:`Approve gate "${i.id}" and baseline phase "${c.name}"?`},m);let h=r.pending[r.pending.length-1].id;return chunkZ43GUETW_cjs.c(r,"phase.gate-pending",o.by,{phase:c.id,gate:i.id,by:o.by,pending:h},m)}return ce(r,c.id,[o.by],m)})},changeControlBoard:(d,o)=>{chunkZ43GUETW_cjs.m(d,o.by,"control-change");let c=o.change;(typeof c!="string"||c.trim()==="")&&chunkOSHBJIYD_cjs.b("invalid-input","changeControlBoard needs change: string (a change-request id)",'e.g. { "change": "CR-1", "decision": "approve", "note": "why" }');let i=chunkZ43GUETW_cjs.r(d,c);if(i.type!=="change-request"&&chunkOSHBJIYD_cjs.b("invalid-input",`item "${c}" is a ${i.type}, not a change-request`,"only change-request items go through the board",{items:[c]}),(i.status==="done"||i.status==="dropped")&&chunkOSHBJIYD_cjs.b("invalid-transition",`change "${c}" is already ${i.status==="done"?"approved":"rejected"}`,"raise a new change-request",{items:[c]}),i.status==="awaiting_human"){let r=d.pending.find(m=>m.item===c);chunkOSHBJIYD_cjs.b("no-op",`change "${c}" is awaiting the human decision${r?` (${r.id})`:""}`,`decide ${r?.id??"<pending id>"} approve|reject`,{items:[c]});}let s=o.decision;s!=="approve"&&s!=="reject"&&chunkOSHBJIYD_cjs.b("invalid-input",'changeControlBoard.decision must be "approve" or "reject"',"state the board's decision");let l=typeof o.note=="string"?o.note:"",f=w(d).changeControl.approvers;for(let r of f)r==="human"||o.by==="human"||chunkZ43GUETW_cjs.l(d,o.by,r.capability)||chunkOSHBJIYD_cjs.b("gate-unmet",`"${o.by}" lacks capability "${r.capability}" required by change control`,`decide as one of: human${chunkZ43GUETW_cjs.g(d,r.capability).map(m=>`, ${m.id}`).join("")}`,{rule:"change-control",items:[c]});let u=f.includes("human")&&o.by!=="human";return t(d,"ceremony.changeControlBoard",o,(r,m)=>{if(u){r=chunkZ43GUETW_cjs.G(r,{kind:"decision",item:c,question:`Change "${c}" (${i.title}): the board (${o.by}) recommends ${s}${l?`: ${l}`:""}. Approve or reject the change?`},m);let h=r.pending[r.pending.length-1].id;return chunkZ43GUETW_cjs.c(r,"change.recommended",o.by,{change:c,decision:s,note:l,pending:h},m)}return s==="approve"?U(r,c,o.by,l,m):K(r,c,o.by,l,m)})},phaseRetrospective:Le(e)}}function ke(e,t,n,a,p,d){if(t.kind==="gate"&&t.item===void 0&&t.gate!==void 0){let o=b(e).find(s=>s.gate.id===t.gate);if(!o)return e;a!=="human"&&chunkOSHBJIYD_cjs.b("gate-unmet",`"${a}" may not decide phase gate "${t.gate}" (${t.id}); it awaits a human`,`decide ${t.id} as human`,{rule:"gate"});let c;for(let s=e.events.length-1;s>=0;s--){let l=e.events[s];if(l.type==="phase.gate-pending"&&l.payload.pending===t.id){c=l.by;break}}let i=c!==void 0&&c!==a?[c,a]:[a];return n==="approve"?ce(e,o.id,i,d):chunkZ43GUETW_cjs.c(e,"phase.gate-failed",a,{phase:o.id,gate:t.gate,note:p},d)}if(t.kind==="decision"&&t.item!==void 0&&Object.hasOwn(e.items,t.item)){let o=e.items[t.item];return o.type!=="change-request"?e:(a!=="human"&&chunkOSHBJIYD_cjs.b("gate-unmet",`"${a}" may not decide change "${o.id}" (${t.id}); change control awaits a human`,`decide ${t.id} as human`,{rule:"change-control",items:[o.id]}),n==="approve"?U(e,o.id,a,p,d):K(e,o.id,a,p,d))}return e}function we(e){let t=w(e).phases.map($=>$.id),n=()=>Object.fromEntries(t.map($=>[$,0])),a=n(),p=n(),d=n(),o=n(),c=n(),i=new Map,s=new Map,l=new Map,f=0,u=0,r=0,m=0,h=0,v=$=>{let W=s.get($),y=i.get($);return W!=="question"&&W!=="change-request"&&y!==void 0&&Object.hasOwn(a,y)};for(let $ of e.events){let W=$.payload??{};switch($.type){case "item.added":{let y=W,j=y.phase??(y.parent!==null?i.get(y.parent):void 0);i.set(y.id,j),s.set(y.id,y.type),l.set(y.id,"todo"),y.type==="change-request"&&(f+=1),v(y.id)&&(a[j]+=1,y.type==="bug"&&(c[j]+=1));break}case "item.transition":{let y=W.id,j=W.to.status,qe=l.get(y);if(l.set(y,j),!v(y))break;let pe=i.get(y);j==="done"&&qe!=="done"&&(p[pe]+=1),j==="dropped"&&(a[pe]-=1,qe==="done"&&(p[pe]-=1));break}case "item.completed":{let y=i.get(W.id);y!==void 0&&Object.hasOwn(o,y)&&(o[y]+=W.tokens??0);break}case "phase.opened":{let y=W.phase;Object.hasOwn(d,y)&&(d[y]=(W.budget??{}).tokens??0);break}case "change.decided":{W.decision==="approve"?(u+=1,m+=W.weight??0,h+=(W.reopened??[]).length):r+=1;break}}}let Z=n(),O=n();for(let $ of t){let W=a[$]??0;Z[$]=W===0?0:(p[$]??0)/W*100,O[$]=o[$]-d[$];}let{traced:x,total:le}=I(e).coverage,Pe=u+r;return {phaseCompletion:Z,budgetPlanned:d,budgetSpent:o,scheduleVariance:O,requirementCoverage:le===0?0:x/le,requirementsTraced:x,requirementsTotal:le,defectsPerPhase:c,changeRequests:f,changesApproved:u,changesRejected:r,changeApprovalRate:Pe===0?0:u/Pe,reworkWeight:m,phasesReopened:h}}function $e(e){let t=e.phases.map(n=>n.gate.id);return [{id:"project-manager",name:"Project Manager",modelTier:"large",capabilities:["facilitate","control-change","approve-gate","escalate"],canApprove:[...t,ge],inputs:["phase-plan","deliverables","change-requests"],outputs:["gate-decisions","baselines","change-decisions"],do_not:["do not implement items yourself","do not reopen a phase without an approved change-request"]},{id:"developer",name:"Developer",modelTier:"small",capabilities:["deliver"],canApprove:[],inputs:["design-doc","interface-spec","brief"],outputs:["code","code-baseline","test-output"],do_not:["do not change requirements or designs; raise a change-request","do not approve your own work"]},{id:"business-analyst",name:"Business Analyst",modelTier:"medium",capabilities:["define-acceptance","deliver"],canApprove:[],inputs:["stakeholder-needs"],outputs:["srs","acceptance-criteria"],do_not:["do not design or implement","do not edit a baselined requirement; raise a change-request"]},{id:"architect",name:"Architect",modelTier:"medium",capabilities:["deliver"],canApprove:[],inputs:["srs"],outputs:["design-doc","interface-spec"],do_not:["do not change requirements; raise a change-request","do not implement"]},{id:"qa",name:"QA",modelTier:"small",capabilities:["verify","review"],canApprove:[],inputs:["srs","design-doc","code-baseline"],outputs:["test-report","review-notes"],do_not:["do not fix defects yourself; raise bugs","do not approve phase gates"]},{id:"release-manager",name:"Release Manager",modelTier:"small",capabilities:["deliver"],canApprove:[],inputs:["code-baseline","test-report"],outputs:["release-notes","deployment-record"],do_not:["do not deploy an unbaselined verification phase"]}]}var k=(e,t,n,a)=>a?{rule:e,severity:"error",item:a,message:t,fix:n}:{rule:e,severity:"error",message:t,fix:n},R=e=>e.payload??{},C=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Q=e=>{let t=R(e).phase;return typeof t=="string"?t:void 0},S=(e,t)=>b(e).find(n=>n.id===t),de=e=>b(e).map(t=>t.id).join(", "),M=(e,t)=>typeof t=="string"&&Object.hasOwn(e.items,t)?e.items[t]:void 0;function He(e,t){if(t.phase!==void 0)return t.phase;let n=M(e,t.parent);return n?q(e,n):void 0}var Ue=e=>e.type!=="change-request"&&e.type!=="question",Ke=(e,t)=>`raise a change-request: addItem({ type: "change-request", affects: ["${e}"], impactAnalysis: { summary, reopen: ["${t}"], weight } }) and decide it in changeControlBoard`;function Ye(e,t){let n=M(e,R(t).change);return n&&n.type==="change-request"?n:void 0}function We(e,t,n){let a="change-needs-impact-analysis",p=`editItem("${t}", { impactAnalysis: { summary: "what changes and why", reopen: ["<phase>"], weight: <points> } })`;if(n===void 0)return w(e).changeControl.requiresImpactAnalysis?[k(a,`change "${t}" has no impact analysis`,p,t)]:[];let d=[],o=C(n)?n:{};return (typeof o.summary!="string"||o.summary.trim()==="")&&d.push(k(a,`change "${t}" impactAnalysis.summary is empty`,p,t)),(!Array.isArray(o.reopen)||!o.reopen.every(c=>typeof c=="string"))&&d.push(k(a,`change "${t}" impactAnalysis.reopen must be a string[] of phase ids`,p,t)),(typeof o.weight!="number"||!Number.isFinite(o.weight)||o.weight<0)&&d.push(k(a,`change "${t}" impactAnalysis.weight must be a non-negative number`,p,t)),d}function Ae(){return [{id:"phase-sequential",severity:"error",check(i,s){let l=[];if(s.type==="ceremony.kickoff"){let f=Q(s),u=f===void 0?void 0:S(i,f);if(!u)return [];u.status==="open"&&l.push(k("phase-sequential",`phase "${u.id}" is already open`,`gateReview "${u.id}" when its work is done`)),u.status==="baselined"&&l.push(k("phase-sequential",`phase "${u.id}" is baselined`,"only an approved change-request reopens a baselined phase"));let r=D(i);r&&r.id!==u.id&&l.push(k("phase-sequential",`phase "${r.id}" is still open`,`pass its gate (gateReview "${r.id}") before opening "${u.id}"`));}else if(s.type==="item.add"){let f=R(s).item;if(!C(f)||!Ue(f))return [];let u=He(i,f);u===void 0?l.push(k("phase-sequential",`item "${f.id}" belongs to no phase`,`set phase to one of: ${de(i)}`,f.id)):S(i,u)||l.push(k("phase-sequential",`item "${f.id}" names unknown phase "${u}"`,`phases are: ${de(i)}`,f.id));}else if(s.type==="item.edit"){let f=R(s).id,u=R(s).patch,r=M(i,f);if(!r||!C(u)||u.phase===void 0||u.phase===r.phase)return [];l.push(k("phase-sequential",`item "${r.id}" cannot move from phase "${r.phase??"(none)"}" to "${String(u.phase)}"`,`drop "${r.id}" and add a new item in phase "${String(u.phase)}"`,r.id));}return l}},{id:"gate-before-next-phase",severity:"error",check(i,s){if(s.type!=="ceremony.kickoff")return [];let l=Q(s),f=b(i),u=l===void 0?-1:f.findIndex(m=>m.id===l);if(u<0)return [];let r=f.slice(0,u).filter(m=>m.status!=="baselined").map(m=>m.id);return r.length===0?[]:[k("gate-before-next-phase",`phase(s) ${r.join(", ")} before "${l}" are not baselined`,`kickoff and gateReview them in order, starting with "${r[0]}"`)]}},{id:"baseline-immutable",severity:"error",check(i,s){let l=f=>(i.baselines??[]).filter(u=>u.phase===f).length||1;if(s.type==="item.edit"){let f=M(i,R(s).id);if(!f)return [];let u=q(i,f);return u===void 0||S(i,u)?.status!=="baselined"?[]:[k("baseline-immutable",`item "${f.id}" is frozen: phase "${u}" is baselined (v${l(u)})`,Ke(f.id,u),f.id)]}if(s.type==="item.add"){let f=R(s).item;if(!C(f)||!Ue(f))return [];let u=He(i,f);return u===void 0||S(i,u)?.status!=="baselined"?[]:[k("baseline-immutable",`cannot add "${f.id}" to baselined phase "${u}" (v${l(u)})`,Ke(f.id,u),f.id)]}return []}},{id:"change-needs-impact-analysis",severity:"error",check(i,s){if(s.type==="item.add"){let r=R(s).item;return !C(r)||r.type!=="change-request"?[]:We(i,String(r.id),r.impactAnalysis)}if(s.type==="item.edit"){let r=R(s).patch,m=M(i,R(s).id);return !m||m.type!=="change-request"||!C(r)||!("impactAnalysis"in r)?[]:We(i,m.id,r.impactAnalysis)}if(s.type!=="ceremony.changeControlBoard")return [];let l=Ye(i,s);if(!l)return [];let f=We(i,l.id,l.impactAnalysis);if(f.length||l.impactAnalysis===void 0)return f;let u=R(s).decision==="approve";for(let r of l.impactAnalysis.reopen){let m=S(i,r);m?u&&m.status==="pending"&&f.push(k("change-needs-impact-analysis",`phase "${r}" was never baselined; it cannot be reopened`,`remove "${r}" from impactAnalysis.reopen`,l.id)):f.push(k("change-needs-impact-analysis",`change "${l.id}" impactAnalysis.reopen names unknown phase "${r}"`,`phases are: ${de(i)}`,l.id));}return f}},{id:"requirement-traced",severity:"error",check(i,s){if(s.type!=="ceremony.gateReview")return [];let l=Q(s),f=w(i).traceability;return l===void 0||!f.to.includes(l)||!S(i,l)?[]:J(i,l).map(u=>k("requirement-traced",`item "${u}" of phase "${f.from}" has no trace into "${l}"`,`editItem a "${l}" item with traces: ["${u}"] (or editItem("${u}", { traces: [...] }) while "${f.from}" is not baselined)`,u))}},{id:"deliverables-present",severity:"error",check(i,s){if(s.type!=="ceremony.gateReview")return [];let l=Q(s),f=l===void 0?void 0:S(i,l);if(!f)return [];let u=[],r=P(i,f.id).filter(v=>v.status!=="done").map(v=>v.id);r.length&&u.push(k("deliverables-present",`${r.length} item(s) in phase "${f.id}" are not done: ${r.join(", ")}`,"finish them (next/complete) or drop them before the gate"));let m=R(s).deliverables,h=Array.isArray(m)?m.filter(v=>C(v)&&typeof v.kind=="string").map(v=>v.kind):[];f.id===B(i)&&h.push("traceability-matrix");for(let v of H(i,f,h))u.push(k("deliverables-present",`phase "${f.id}" has no deliverable "${v}"`,`pass deliverables: [{ "kind": "${v}", "ref": "<where it lives>" }] to gateReview, or attach evidence of kind "${v}" on an item of the phase`));return u}},{id:"approver-not-author",severity:"error",check(i,s){if(s.by==="human")return [];if(s.type==="ceremony.gateReview"){let l=Q(s),f=l===void 0?void 0:S(i,l);if(!f)return [];let u=P(i,f.id).filter(m=>chunkZ43GUETW_cjs.E(i,m)===s.by).map(m=>m.id);if(u.length===0)return [];let r=chunkZ43GUETW_cjs.h(i,f.gate.id,"approve-gate",s.by);return [k("approver-not-author",`"${s.by}" authored ${u.join(", ")} in phase "${f.id}" and may not approve its gate`,`review the gate as one of: human${r.map(m=>`, ${m}`).join("")}`)]}if(s.type==="ceremony.changeControlBoard"){let l=Ye(i,s);if(!l)return [];let f=i.events.find(r=>r.type==="item.added"&&r.payload.id===l.id);if(!f||f.by!==s.by)return [];let u=chunkZ43GUETW_cjs.g(i,"control-change").map(r=>r.id).filter(r=>r!==s.by);return [k("approver-not-author",`"${s.by}" raised change "${l.id}" and may not decide it`,`decide as human${u.map(r=>`, ${r}`).join("")}`,l.id)]}return []}},{id:"trace-ids-valid",severity:"error",check(i,s){let l,f,u,r;if(s.type==="item.add"){let h=R(s).item;if(!C(h))return [];l=String(h.id),f=h.traces,u=h.impactAnalysis,r=h.type==="change-request";}else if(s.type==="item.edit"){let h=M(i,R(s).id),v=R(s).patch;if(!h||!C(v))return [];l=h.id,f=v.traces,u=v.impactAnalysis,r=h.type==="change-request";}else return [];let m=[];if(Array.isArray(f)){let h=w(i).traceability,v=[h.from,...h.to].flatMap(O=>P(i,O).filter(x=>x.type!=="question"&&x.type!=="change-request").map(x=>x.id)),Z=`traceable items: ${v.length?v.join(", "):"(none yet)"}`;for(let O of f){if(typeof O!="string")continue;let x=M(i,O);(!x||x.status==="dropped")&&m.push(k("trace-ids-valid",`item "${l}" traces unknown item "${O}"`,Z,l));}}if(r&&C(u)&&Array.isArray(u.reopen))for(let h of u.reopen)typeof h=="string"&&!S(i,h)&&m.push(k("trace-ids-valid",`change "${l}" impactAnalysis.reopen names unknown phase "${h}"`,`phases are: ${de(i)}`,l));return m}}]}function Re(e){return [{id:L,name:"Work",entryPolicy:[{kind:"dependencies-done"}],exitPolicy:[]},{id:V,name:"Review",entryPolicy:[],exitPolicy:[{kind:"no-open-blockers"}],review:true},{id:z,name:"Done",entryPolicy:[],exitPolicy:[]}]}var nt=Object.freeze({backlog:"Requirements Baseline",item:"Work Package",stage:"Step",iteration:"Phase",increment:"Deliverable",ceremony:"Review",gate:"Phase Gate"});function it(e,t){let n=q(e,t);if(n!==void 0)return w(e).phases.find(a=>a.id===n)?.deliverBy}function rt(e){return {phases:b(e).map(n=>{let a=P(e,n.id),p=a.filter(s=>s.status==="done").length,o=w(e).traceability.to.includes(n.id)?J(e,n.id):[],c=n.id===B(e)&&o.length===0?["traceability-matrix"]:[],i=H(e,n,c);return {id:n.id,name:n.name,status:n.status,items:a.length,done:p,missingDeliverables:i,missingTraces:o,readyForGate:n.status==="open"&&p===a.length&&i.length===0&&o.length===0}}),current:ye(e)?.id??null,open:D(e)?.id??null,pendingGates:e.pending.filter(n=>n.kind==="gate"&&n.item===void 0&&n.gate!==void 0).map(n=>({pending:n.id,gate:n.gate}))}}function at(){return {name:"waterfall",vocabulary:nt,validateConfig:he,defaultStages:Re,defaultRoles:$e,requiredCapabilities:["facilitate","control-change","approve-gate","deliver","verify"],exclusiveCapabilities:[],plannerOptions(e){let t={schedulerMode:"level",roleFor:a=>a.status==="todo"&&a.type!=="question"?it(e,a):void 0},n=w(e).fallbackTokensPerWeight;return n!==void 0&&(t.fallbackTokensPerWeight=n),t},candidates(e){let t=D(e);return t?Object.values(e.items).filter(n=>(n.status==="todo"||n.status==="review")&&(n.stage===L||n.stage===V)&&n.type!=="change-request"&&q(e,n)===t.id):[]},invariants(e,t){let n=w(e),a=b(e),p=q(e,t),d=p===void 0?void 0:a[E(e,p)],o=a.filter(i=>i.status==="baselined").map(i=>i.id),c=d?.gate.requires.includes("human");return [d?`Phase "${d.name}" (${E(e,d.id)+1}/${a.length}); deliverables: ${d.deliverables.join(", ")||"(none)"}; gate "${d.gate.id}"${c?" needs human approval":""}`:"This item belongs to no phase; it is dispatched only through its parent's phase",`Baselined phases are frozen: ${o.join(", ")||"(none yet)"}; to change their items, raise a change-request with an impact analysis`,n.traceability.to.length?`Traceability: every item of phase "${n.traceability.from}" must trace to an item in ${n.traceability.to.join(", ")} (set traces on either side)`:"Traceability: none configured",`Do not change the scope of "${t.id}" or its acceptance criteria; raise open_questions instead`]},ceremonies:ve(at),rules:Ae(),metrics:e=>({...we(e)}),humanDefaults:{gates:"all"},lockedConfigKeys:["phases","traceability","humanGates"],report:e=>({...rt(e),coverage:I(e).coverage}),afterDecide:ke,afterComplete(e,t,n){let a=chunkZ43GUETW_cjs.N(e),p=D(e);if(!a||!p||a.committed.includes(t))return e;let d=e.items[t];if(!d||q(e,d)!==p.id)return e;let o=e.accounting[e.accounting.length-1];return !o||o.item!==t?e:{...e,iterations:e.iterations.map(c=>c.id===a.id?{...c,committed:[...c.committed,t],spent:chunkZ43GUETW_cjs.J(c.spent,o)}:c)}}}}exports.A=K;exports.B=I;exports.C=J;exports.D=Y;exports.E=ve;exports.F=ke;exports.G=we;exports.H=$e;exports.I=Ae;exports.J=Re;exports.K=nt;exports.L=it;exports.M=rt;exports.N=at;exports.a=Be;exports.b=ae;exports.c=oe;exports.d=me;exports.e=ge;exports.f=Ge;exports.g=w;exports.h=he;exports.i=L;exports.j=V;exports.k=z;exports.l=b;exports.m=T;exports.n=E;exports.o=_;exports.p=q;exports.q=P;exports.r=D;exports.s=ye;exports.t=Qe;exports.u=Fe;exports.v=H;exports.w=B;exports.x=ce;exports.y=be;exports.z=U;//# sourceMappingURL=chunk-VXOZIP77.cjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
'use strict';var chunkGKN5M4B7_cjs=require('./chunk-GKN5M4B7.cjs'),chunkBANKVCYY_cjs=require('./chunk-BANKVCYY.cjs'),chunkMU26QW32_cjs=require('./chunk-MU26QW32.cjs'),chunkOSHBJIYD_cjs=require('./chunk-OSHBJIYD.cjs'),exsorted=require('exsorted');var Be=chunkGKN5M4B7_cjs.a(["requirements","design","implementation","verification","deployment","maintenance"]),ae=chunkGKN5M4B7_cjs.a({requirements:["srs"],design:["design-doc","interface-spec"],implementation:["code-baseline"],verification:["test-report","traceability-matrix"],deployment:["release-notes","deployment-record"],maintenance:["change-log"]}),oe=chunkGKN5M4B7_cjs.a({requirements:"business-analyst",design:"architect",deployment:"release-manager"}),me=e=>`${e}-gate`,ge="change-control",Ee=["order-backlog","define-acceptance","facilitate","deliver","review","verify","approve-gate","manage-flow","control-change","escalate"],Me=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ge(){return Be.map(e=>{let t={id:e,name:Me(e),deliverables:[...ae[e]??[]],gate:{id:me(e),requires:[{capability:"approve-gate"}],evidence:[],onFail:{action:"block"}}},n=oe[e];return n!==void 0&&(t.deliverBy=n),t})}function w(e){return e.config}var G=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),se=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&t.trim()!=="");function Je(e,t){if(e===void 0)return;G(e)||chunkOSHBJIYD_cjs.b("config-invalid",`${t}.budget must be an object`,'e.g. { "tokens": 400000 }');let n={};for(let a of ["tokens","turns","wallclockMs"]){let p=e[a];p!==void 0&&((typeof p!="number"||!Number.isFinite(p)||p<0)&&chunkOSHBJIYD_cjs.b("config-invalid",`${t}.budget.${a} must be a non-negative number`,"omit it for no limit"),n[a]=p);}return n}function _e(e,t){return (!Array.isArray(e)||e.length===0)&&chunkOSHBJIYD_cjs.b("config-invalid",`${t} must be a non-empty array of "human" | { capability }`,'e.g. ["human", { "capability": "approve-gate" }]'),e.map(n=>n==="human"?"human":G(n)&&typeof n.capability=="string"&&Ee.includes(n.capability)?{capability:n.capability}:chunkOSHBJIYD_cjs.b("config-invalid",`${t} entry ${JSON.stringify(n)} is not "human" or a known capability`,`use "human" or { "capability": one of ${Ee.join(", ")} }`))}function De(e,t,n){let a=`waterfall config.phases[${t}]`;G(e)||chunkOSHBJIYD_cjs.b("config-invalid",`${a} must be an object`,'e.g. { "id": "design" }'),chunkOSHBJIYD_cjs.c(e.id,`${a}.id`);let p=e.id,d=e.deliverables??(Object.hasOwn(ae,p)?ae[p]:void 0)??[];se(d)||chunkOSHBJIYD_cjs.b("config-invalid",`${a}.deliverables must be a string[] of evidence kinds`,'e.g. ["srs"]');let o;if(e.gate===void 0)o={id:me(p),requires:[{capability:"approve-gate"}],evidence:[],onFail:{action:"block"}};else {let l=e.gate;(!G(l)||typeof l.id!="string"||l.id.trim()==="")&&chunkOSHBJIYD_cjs.b("config-invalid",`${a}.gate must be a Gate with an id`,'e.g. { "id": "design-gate", "requires": [{ "capability": "approve-gate" }], "evidence": [] }');let f=l.evidence??[];se(f)||chunkOSHBJIYD_cjs.b("config-invalid",`${a}.gate.evidence must be a string[]`,"list evidence kinds or omit it"),o={id:l.id,requires:_e(l.requires??[{capability:"approve-gate"}],`${a}.gate.requires`),evidence:[...f],onFail:{action:"block"}};}n(p)&&!o.requires.includes("human")&&(o.requires=["human",...o.requires]);let c={id:p,name:typeof e.name=="string"&&e.name.trim()!==""?e.name:Me(p),deliverables:[...d],gate:o},i=Je(e.budget,a);i!==void 0&&(c.budget=i);let s=e.deliverBy??(Object.hasOwn(oe,p)?oe[p]:void 0);return s!==void 0&&((typeof s!="string"||s.trim()==="")&&chunkOSHBJIYD_cjs.b("config-invalid",`${a}.deliverBy must be a role id`,"name the role that delivers this phase or omit it"),c.deliverBy=s),c}function he(e){let t=e??{};t.phases!==void 0&&!Array.isArray(t.phases)&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.phases must be an array of phases","omit phases for the six classic phases");let n=t.humanGates??"all";n!=="all"&&!se(n)&&chunkOSHBJIYD_cjs.b("config-invalid",'waterfall config.humanGates must be "all" or a string[] of phase ids','omit it for "all"');let a=n==="all"?()=>true:r=>n.includes(r),p=t.phases===void 0?Ge().map((r,m)=>De(r,m,a)):t.phases.map((r,m)=>De(r,m,a));p.length===0&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.phases needs at least one phase",'e.g. [{ "id": "requirements" }]');let d=p.map(r=>r.id),o=d.find((r,m)=>d.indexOf(r)!==m);if(o!==void 0&&chunkOSHBJIYD_cjs.b("config-invalid",`duplicate phase id "${o}"`,"give every phase a unique id"),n!=="all")for(let r of n)d.includes(r)||chunkOSHBJIYD_cjs.b("config-invalid",`waterfall config.humanGates names unknown phase "${r}"`,`phases are: ${d.join(", ")}`);let c=t.changeControl??{};G(c)||chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.changeControl must be an object",'e.g. { "requiresImpactAnalysis": true, "approvers": ["human"] }'),c.requiresImpactAnalysis!==void 0&&typeof c.requiresImpactAnalysis!="boolean"&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.changeControl.requiresImpactAnalysis must be a boolean","omit it for true");let i={requiresImpactAnalysis:c.requiresImpactAnalysis===void 0?true:c.requiresImpactAnalysis,approvers:_e(c.approvers??["human",{capability:"control-change"}],"waterfall config.changeControl.approvers")},s=t.traceability,l;if(s===void 0)l=d.includes("requirements")&&d.includes("design")&&d.includes("verification")?{from:"requirements",to:["design","verification"]}:{from:d[0],to:[]};else {(!G(s)||typeof s.from!="string"||!d.includes(s.from))&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.traceability.from must be a phase id",`phases are: ${d.join(", ")}`);let r=s.to??[];se(r)||chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.traceability.to must be a string[] of phase ids",`phases are: ${d.join(", ")}`);for(let m of r)d.includes(m)||chunkOSHBJIYD_cjs.b("config-invalid",`waterfall config.traceability.to names unknown phase "${m}"`,`phases are: ${d.join(", ")}`),d.indexOf(m)<=d.indexOf(s.from)&&chunkOSHBJIYD_cjs.b("config-invalid",`waterfall config.traceability.to phase "${m}" must come after "${s.from}"`,"trace forward only: from an earlier phase to later ones");l={from:s.from,to:[...r]};}let f=t.fallbackTokensPerWeight;f!==void 0&&(typeof f!="number"||!Number.isFinite(f)||f<=0)&&chunkOSHBJIYD_cjs.b("config-invalid","waterfall config.fallbackTokensPerWeight must be a positive finite number","omit it for the default 20000");let u={phases:p,changeControl:i,traceability:l,humanGates:n==="all"?"all":[...n]};return f!==void 0&&(u.fallbackTokensPerWeight=f),u}var L="work",V="review",z="done";function b(e){return e.phases?e.phases:w(e).phases.map(t=>{let n={id:t.id,name:t.name,deliverables:[...t.deliverables],gate:t.gate,status:"pending"};return t.budget&&(n.budget=t.budget),n})}function T(e,t){return {...e,phases:t}}function E(e,t){let n=b(e).findIndex(a=>a.id===t);return n<0&&chunkOSHBJIYD_cjs.b("config-invalid",`unknown phase "${t}"`,`phases are: ${b(e).map(a=>a.id).join(" \u2192 ")}`),n}function _(e,t){return b(e)[E(e,t)]}function q(e,t){let n=new Set,a=t;for(;a&&!n.has(a.id);){if(a.phase!==void 0)return a.phase;n.add(a.id),a=a.parent!==void 0&&Object.hasOwn(e.items,a.parent)?e.items[a.parent]:void 0;}}function P(e,t){return Object.values(e.items).filter(n=>n.status!=="dropped"&&q(e,n)===t)}function D(e){return b(e).find(t=>t.status==="open")}function ye(e){return b(e).find(t=>t.status!=="baselined")}function Qe(e,t){let n=q(e,t);return n!==void 0&&b(e).find(a=>a.id===n)?.status==="baselined"}function Fe(e,t){let n=new Set((t.produced??[]).map(a=>a.kind));for(let a of P(e,t.id))for(let p of a.evidence)n.add(p.kind);return n}function H(e,t,n=[]){let a=Fe(e,t);for(let d of n)a.add(d);let p=[];for(let d of [...t.deliverables,...t.gate.evidence])p.includes(d)||p.push(d);return p.filter(d=>!a.has(d))}function B(e){let t=b(e).map(a=>a.id),n=w(e).traceability.to.filter(a=>t.includes(a));if(n.length!==0)return n.reduce((a,p)=>t.indexOf(a)>=t.indexOf(p)?a:p)}function Ne(e,t,n,a){let p=chunkMU26QW32_cjs.P(e);return !p||!p.id.startsWith(`${t}#`)?e:{...e,iterations:e.iterations.map(d=>d.id===p.id?{...d,endedAt:a,outcome:n}:d)}}function ce(e,t,n,a){let p=_(e,t);p.status!=="open"&&chunkOSHBJIYD_cjs.b("invalid-transition",`phase "${t}" is ${p.status}, not open`,p.status==="baselined"?"it is already baselined; a change-request reopens it":"kickoff the phase first");let d=P(e,t),o={};for(let l of d)o[l.id]=l;let c=(e.baselines??[]).filter(l=>l.phase===t).length,i={phase:t,version:c+1,at:a,approvedBy:n,itemSnapshot:o},s=T(e,b(e).map(l=>l.id===t?{...l,status:"baselined"}:l));return s={...s,baseline:i,baselines:[...s.baselines??[],i]},s=Ne(s,t,"completed",a),chunkMU26QW32_cjs.c(s,"phase.baselined",n[n.length-1]??"system",{phase:t,version:i.version,approvedBy:n,items:d.map(l=>l.id)},a)}function be(e,t,n){let a=[];for(let c of t){let i=_(e,c);i.status==="pending"&&chunkOSHBJIYD_cjs.b("invalid-input",`phase "${c}" was never baselined; there is nothing to reopen`,"remove it from impactAnalysis.reopen"),i.status==="baselined"&&!a.includes(c)&&a.push(c);}let p=b(e).map(c=>a.includes(c.id)?{...c,status:"reopened"}:c),d=null,o=e;if(a.length){let c=Math.min(...a.map(s=>E(e,s))),i=p.find((s,l)=>s.status==="open"&&l>c);i&&(d=i.id,p=p.map(s=>s.id===i.id?{...s,status:"reopened"}:s),o=Ne(o,i.id,"cancelled",n));}return {state:T(o,p),reopened:a,suspended:d}}function U(e,t,n,a,p){let d=chunkMU26QW32_cjs.r(e,t),o=d.impactAnalysis,c=be(e,o?.reopen??[],p),i=chunkMU26QW32_cjs.u(c.state,t,{stage:z,status:"done"},n,p);for(let s of c.reopened)i=chunkMU26QW32_cjs.c(i,"phase.reopened",n,{phase:s,change:t},p);return c.suspended!==null&&(i=chunkMU26QW32_cjs.c(i,"phase.suspended",n,{phase:c.suspended,change:t},p)),chunkMU26QW32_cjs.c(i,"change.decided",n,{change:t,decision:"approve",by:n,note:a,reopened:c.reopened,suspended:c.suspended,weight:o?.weight??0,affects:d.affects??[]},p)}function K(e,t,n,a,p){let d=chunkMU26QW32_cjs.r(e,t),o=chunkMU26QW32_cjs.u(e,t,{status:"dropped"},n,p);return chunkMU26QW32_cjs.c(o,"change.decided",n,{change:t,decision:"reject",by:n,note:a,reopened:[],suspended:null,weight:0,affects:d.affects??[]},p)}function Le(e){return (t,n)=>{chunkMU26QW32_cjs.m(t,n.by,"facilitate");let a=n.phase===void 0?void 0:Y(t,n,"phaseRetrospective"),p=chunkBANKVCYY_cjs.a(t,n,"phaseRetrospective");return chunkMU26QW32_cjs.W(t,e(),{type:"ceremony.phaseRetrospective",by:n.by,payload:n},d=>{let o=d,c=chunkMU26QW32_cjs.a(n.now),i=chunkBANKVCYY_cjs.b(o,p,n.by,c);return o=i.state,chunkMU26QW32_cjs.c(o,"phase.retrospective",n.by,{phase:a?.id??null,lessons:i.created,adopted:i.adopted.slice(i.created.length),dismissed:i.dismissed,agreements:i.agreements,retired:i.retired},c)})}}var Xe=(e,t)=>e.id<t.id?-1:e.id>t.id?1:0,Ve=(e,t)=>exsorted.timSort(P(e,t).filter(n=>n.type!=="question"&&n.type!=="change-request"),Xe),et=(e,t)=>(e.traces??[]).includes(t.id)||(t.traces??[]).includes(e.id);function I(e){let t=w(e).traceability,n=b(e).map(o=>o.id),a=t.to.filter(o=>n.includes(o)),p=Ve(e,t.from).map(o=>{let c={};for(let i of a)c[i]=Ve(e,i).filter(s=>et(o,s)).map(s=>s.id);return {item:o.id,links:c}}),d=p.map(o=>({item:o.item,phases:a.filter(c=>o.links[c].length===0)})).filter(o=>o.phases.length>0);return {from:t.from,to:a,rows:p,missing:d,coverage:{traced:p.length-d.length,total:p.length}}}function J(e,t){return I(e).rows.filter(n=>(n.links[t]??[]).length===0).map(n=>n.item)}var tt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Y(e,t,n){let a=t.phase;return (typeof a!="string"||a.trim()==="")&&chunkOSHBJIYD_cjs.b("invalid-input",`${n} needs phase: string`,`pass one of: ${b(e).map(p=>p.id).join(", ")}`),_(e,a)}function ze(e,t,n,a,p,d){let o=T(e,b(e).map(c=>c.id===t?{...c,produced:[...c.produced??[],{kind:n,ref:a,by:p,at:d}]}:c));return chunkMU26QW32_cjs.c(o,"phase.deliverable",p,{phase:t,kind:n,ref:a},d)}function ve(e){let t=(d,o,c,i)=>chunkMU26QW32_cjs.W(d,e(),{type:o,by:c.by,payload:c},s=>i(s,chunkMU26QW32_cjs.a(c.now)));return {kickoff:(d,o)=>{chunkMU26QW32_cjs.m(d,o.by,"facilitate");let c=Y(d,o,"kickoff");return t(d,"ceremony.kickoff",o,(i,s)=>{let l=i.events.filter(r=>r.type==="phase.opened"&&r.payload.phase===c.id).length+1,f=P(i,c.id).filter(r=>r.status!=="done").map(r=>r.id);i=T(i,b(i).map(r=>r.id===c.id?{...r,status:"open"}:r));let u=c.budget??{};return i={...i,iterations:[...i.iterations,{id:`${c.id}#${l}`,goal:c.name,budget:u,spent:{...chunkMU26QW32_cjs.K},startedAt:s,committed:f,carryover:[]}]},chunkMU26QW32_cjs.c(i,"phase.opened",o.by,{phase:c.id,version:l,items:f,budget:u},s)})},gateReview:(d,o)=>{let c=Y(d,o,"gateReview");c.status!=="open"&&chunkOSHBJIYD_cjs.b("invalid-transition",`phase "${c.id}" is ${c.status}, not open`,c.status==="baselined"?"it is already baselined; a change-request reopens it":`kickoff "${c.id}" first`);let i=c.gate,s=chunkMU26QW32_cjs.h(d,i.id,"approve-gate");o.by!=="human"&&!s.includes(o.by)&&chunkOSHBJIYD_cjs.b("gate-unmet",`"${o.by}" may not review gate "${i.id}"`,`review as one of: human${s.map(r=>`, ${r}`).join("")}`,{rule:"gate"});let l=d.pending.find(r=>r.kind==="gate"&&r.item===void 0&&r.gate===i.id);l&&chunkOSHBJIYD_cjs.b("no-op",`gate "${i.id}" is already awaiting a decision (${l.id})`,`decide ${l.id} approve|reject`);let f=o.deliverables??[];(!Array.isArray(f)||!f.every(r=>tt(r)&&typeof r.kind=="string"&&r.kind.trim()!==""&&typeof r.ref=="string"))&&chunkOSHBJIYD_cjs.b("invalid-input","gateReview.deliverables must be [{ kind, ref }]",'e.g. { "deliverables": [{ "kind": "srs", "ref": "docs/srs.md" }] }');let u=f;return t(d,"ceremony.gateReview",o,(r,m)=>{for(let h of u)r=ze(r,c.id,h.kind,h.ref,o.by,m);if(w(r).traceability.to.includes(c.id)){let h=I(r);r=chunkMU26QW32_cjs.c(r,"traceability.computed",o.by,{phase:c.id,from:h.from,to:h.to,coverage:h.coverage,missing:h.missing,rows:h.rows},m),c.id===B(r)&&h.missing.length===0&&(r=ze(r,c.id,"traceability-matrix",`traceability.computed#${r.events[r.events.length-1].seq}`,o.by,m));}if(i.requires.includes("human")&&o.by!=="human"){r=chunkMU26QW32_cjs.I(r,{kind:"gate",gate:i.id,question:`Approve gate "${i.id}" and baseline phase "${c.name}"?`},m);let h=r.pending[r.pending.length-1].id;return chunkMU26QW32_cjs.c(r,"phase.gate-pending",o.by,{phase:c.id,gate:i.id,by:o.by,pending:h},m)}return ce(r,c.id,[o.by],m)})},changeControlBoard:(d,o)=>{chunkMU26QW32_cjs.m(d,o.by,"control-change");let c=o.change;(typeof c!="string"||c.trim()==="")&&chunkOSHBJIYD_cjs.b("invalid-input","changeControlBoard needs change: string (a change-request id)",'e.g. { "change": "CR-1", "decision": "approve", "note": "why" }');let i=chunkMU26QW32_cjs.r(d,c);if(i.type!=="change-request"&&chunkOSHBJIYD_cjs.b("invalid-input",`item "${c}" is a ${i.type}, not a change-request`,"only change-request items go through the board",{items:[c]}),(i.status==="done"||i.status==="dropped")&&chunkOSHBJIYD_cjs.b("invalid-transition",`change "${c}" is already ${i.status==="done"?"approved":"rejected"}`,"raise a new change-request",{items:[c]}),i.status==="awaiting_human"){let r=d.pending.find(m=>m.item===c);chunkOSHBJIYD_cjs.b("no-op",`change "${c}" is awaiting the human decision${r?` (${r.id})`:""}`,`decide ${r?.id??"<pending id>"} approve|reject`,{items:[c]});}let s=o.decision;s!=="approve"&&s!=="reject"&&chunkOSHBJIYD_cjs.b("invalid-input",'changeControlBoard.decision must be "approve" or "reject"',"state the board's decision");let l=typeof o.note=="string"?o.note:"",f=w(d).changeControl.approvers;for(let r of f)r==="human"||o.by==="human"||chunkMU26QW32_cjs.l(d,o.by,r.capability)||chunkOSHBJIYD_cjs.b("gate-unmet",`"${o.by}" lacks capability "${r.capability}" required by change control`,`decide as one of: human${chunkMU26QW32_cjs.g(d,r.capability).map(m=>`, ${m.id}`).join("")}`,{rule:"change-control",items:[c]});let u=f.includes("human")&&o.by!=="human";return t(d,"ceremony.changeControlBoard",o,(r,m)=>{if(u){r=chunkMU26QW32_cjs.I(r,{kind:"decision",item:c,question:`Change "${c}" (${i.title}): the board (${o.by}) recommends ${s}${l?`: ${l}`:""}. Approve or reject the change?`},m);let h=r.pending[r.pending.length-1].id;return chunkMU26QW32_cjs.c(r,"change.recommended",o.by,{change:c,decision:s,note:l,pending:h},m)}return s==="approve"?U(r,c,o.by,l,m):K(r,c,o.by,l,m)})},phaseRetrospective:Le(e)}}function ke(e,t,n,a,p,d){if(t.kind==="gate"&&t.item===void 0&&t.gate!==void 0){let o=b(e).find(s=>s.gate.id===t.gate);if(!o)return e;a!=="human"&&chunkOSHBJIYD_cjs.b("gate-unmet",`"${a}" may not decide phase gate "${t.gate}" (${t.id}); it awaits a human`,`decide ${t.id} as human`,{rule:"gate"});let c;for(let s=e.events.length-1;s>=0;s--){let l=e.events[s];if(l.type==="phase.gate-pending"&&l.payload.pending===t.id){c=l.by;break}}let i=c!==void 0&&c!==a?[c,a]:[a];return n==="approve"?ce(e,o.id,i,d):chunkMU26QW32_cjs.c(e,"phase.gate-failed",a,{phase:o.id,gate:t.gate,note:p},d)}if(t.kind==="decision"&&t.item!==void 0&&Object.hasOwn(e.items,t.item)){let o=e.items[t.item];return o.type!=="change-request"?e:(a!=="human"&&chunkOSHBJIYD_cjs.b("gate-unmet",`"${a}" may not decide change "${o.id}" (${t.id}); change control awaits a human`,`decide ${t.id} as human`,{rule:"change-control",items:[o.id]}),n==="approve"?U(e,o.id,a,p,d):K(e,o.id,a,p,d))}return e}function we(e){let t=w(e).phases.map($=>$.id),n=()=>Object.fromEntries(t.map($=>[$,0])),a=n(),p=n(),d=n(),o=n(),c=n(),i=new Map,s=new Map,l=new Map,f=0,u=0,r=0,m=0,h=0,v=$=>{let W=s.get($),y=i.get($);return W!=="question"&&W!=="change-request"&&y!==void 0&&Object.hasOwn(a,y)};for(let $ of e.events){let W=$.payload??{};switch($.type){case "item.added":{let y=W,j=y.phase??(y.parent!==null?i.get(y.parent):void 0);i.set(y.id,j),s.set(y.id,y.type),l.set(y.id,"todo"),y.type==="change-request"&&(f+=1),v(y.id)&&(a[j]+=1,y.type==="bug"&&(c[j]+=1));break}case "item.transition":{let y=W.id,j=W.to.status,qe=l.get(y);if(l.set(y,j),!v(y))break;let pe=i.get(y);j==="done"&&qe!=="done"&&(p[pe]+=1),j==="dropped"&&(a[pe]-=1,qe==="done"&&(p[pe]-=1));break}case "item.completed":{let y=i.get(W.id);y!==void 0&&Object.hasOwn(o,y)&&(o[y]+=W.tokens??0);break}case "phase.opened":{let y=W.phase;Object.hasOwn(d,y)&&(d[y]=(W.budget??{}).tokens??0);break}case "change.decided":{W.decision==="approve"?(u+=1,m+=W.weight??0,h+=(W.reopened??[]).length):r+=1;break}}}let Z=n(),O=n();for(let $ of t){let W=a[$]??0;Z[$]=W===0?0:(p[$]??0)/W*100,O[$]=o[$]-d[$];}let{traced:x,total:le}=I(e).coverage,Pe=u+r;return {phaseCompletion:Z,budgetPlanned:d,budgetSpent:o,scheduleVariance:O,requirementCoverage:le===0?0:x/le,requirementsTraced:x,requirementsTotal:le,defectsPerPhase:c,changeRequests:f,changesApproved:u,changesRejected:r,changeApprovalRate:Pe===0?0:u/Pe,reworkWeight:m,phasesReopened:h}}function $e(e){let t=e.phases.map(n=>n.gate.id);return [{id:"project-manager",name:"Project Manager",modelTier:"large",capabilities:["facilitate","control-change","approve-gate","escalate"],canApprove:[...t,ge],inputs:["phase-plan","deliverables","change-requests"],outputs:["gate-decisions","baselines","change-decisions"],do_not:["do not implement items yourself","do not reopen a phase without an approved change-request"]},{id:"developer",name:"Developer",modelTier:"small",capabilities:["deliver"],canApprove:[],inputs:["design-doc","interface-spec","brief"],outputs:["code","code-baseline","test-output"],do_not:["do not change requirements or designs; raise a change-request","do not approve your own work"]},{id:"business-analyst",name:"Business Analyst",modelTier:"medium",capabilities:["define-acceptance","deliver"],canApprove:[],inputs:["stakeholder-needs"],outputs:["srs","acceptance-criteria"],do_not:["do not design or implement","do not edit a baselined requirement; raise a change-request"]},{id:"architect",name:"Architect",modelTier:"medium",capabilities:["deliver"],canApprove:[],inputs:["srs"],outputs:["design-doc","interface-spec"],do_not:["do not change requirements; raise a change-request","do not implement"]},{id:"qa",name:"QA",modelTier:"small",capabilities:["verify","review"],canApprove:[],inputs:["srs","design-doc","code-baseline"],outputs:["test-report","review-notes"],do_not:["do not fix defects yourself; raise bugs","do not approve phase gates"]},{id:"release-manager",name:"Release Manager",modelTier:"small",capabilities:["deliver"],canApprove:[],inputs:["code-baseline","test-report"],outputs:["release-notes","deployment-record"],do_not:["do not deploy an unbaselined verification phase"]}]}var k=(e,t,n,a)=>a?{rule:e,severity:"error",item:a,message:t,fix:n}:{rule:e,severity:"error",message:t,fix:n},R=e=>e.payload??{},C=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Q=e=>{let t=R(e).phase;return typeof t=="string"?t:void 0},S=(e,t)=>b(e).find(n=>n.id===t),de=e=>b(e).map(t=>t.id).join(", "),M=(e,t)=>typeof t=="string"&&Object.hasOwn(e.items,t)?e.items[t]:void 0;function He(e,t){if(t.phase!==void 0)return t.phase;let n=M(e,t.parent);return n?q(e,n):void 0}var Ue=e=>e.type!=="change-request"&&e.type!=="question",Ke=(e,t)=>`raise a change-request: addItem({ type: "change-request", affects: ["${e}"], impactAnalysis: { summary, reopen: ["${t}"], weight } }) and decide it in changeControlBoard`;function Ye(e,t){let n=M(e,R(t).change);return n&&n.type==="change-request"?n:void 0}function We(e,t,n){let a="change-needs-impact-analysis",p=`editItem("${t}", { impactAnalysis: { summary: "what changes and why", reopen: ["<phase>"], weight: <points> } })`;if(n===void 0)return w(e).changeControl.requiresImpactAnalysis?[k(a,`change "${t}" has no impact analysis`,p,t)]:[];let d=[],o=C(n)?n:{};return (typeof o.summary!="string"||o.summary.trim()==="")&&d.push(k(a,`change "${t}" impactAnalysis.summary is empty`,p,t)),(!Array.isArray(o.reopen)||!o.reopen.every(c=>typeof c=="string"))&&d.push(k(a,`change "${t}" impactAnalysis.reopen must be a string[] of phase ids`,p,t)),(typeof o.weight!="number"||!Number.isFinite(o.weight)||o.weight<0)&&d.push(k(a,`change "${t}" impactAnalysis.weight must be a non-negative number`,p,t)),d}function Ae(){return [{id:"phase-sequential",severity:"error",check(i,s){let l=[];if(s.type==="ceremony.kickoff"){let f=Q(s),u=f===void 0?void 0:S(i,f);if(!u)return [];u.status==="open"&&l.push(k("phase-sequential",`phase "${u.id}" is already open`,`gateReview "${u.id}" when its work is done`)),u.status==="baselined"&&l.push(k("phase-sequential",`phase "${u.id}" is baselined`,"only an approved change-request reopens a baselined phase"));let r=D(i);r&&r.id!==u.id&&l.push(k("phase-sequential",`phase "${r.id}" is still open`,`pass its gate (gateReview "${r.id}") before opening "${u.id}"`));}else if(s.type==="item.add"){let f=R(s).item;if(!C(f)||!Ue(f))return [];let u=He(i,f);u===void 0?l.push(k("phase-sequential",`item "${f.id}" belongs to no phase`,`set phase to one of: ${de(i)}`,f.id)):S(i,u)||l.push(k("phase-sequential",`item "${f.id}" names unknown phase "${u}"`,`phases are: ${de(i)}`,f.id));}else if(s.type==="item.edit"){let f=R(s).id,u=R(s).patch,r=M(i,f);if(!r||!C(u)||u.phase===void 0||u.phase===r.phase)return [];l.push(k("phase-sequential",`item "${r.id}" cannot move from phase "${r.phase??"(none)"}" to "${String(u.phase)}"`,`drop "${r.id}" and add a new item in phase "${String(u.phase)}"`,r.id));}return l}},{id:"gate-before-next-phase",severity:"error",check(i,s){if(s.type!=="ceremony.kickoff")return [];let l=Q(s),f=b(i),u=l===void 0?-1:f.findIndex(m=>m.id===l);if(u<0)return [];let r=f.slice(0,u).filter(m=>m.status!=="baselined").map(m=>m.id);return r.length===0?[]:[k("gate-before-next-phase",`phase(s) ${r.join(", ")} before "${l}" are not baselined`,`kickoff and gateReview them in order, starting with "${r[0]}"`)]}},{id:"baseline-immutable",severity:"error",check(i,s){let l=f=>(i.baselines??[]).filter(u=>u.phase===f).length||1;if(s.type==="item.edit"){let f=M(i,R(s).id);if(!f)return [];let u=q(i,f);return u===void 0||S(i,u)?.status!=="baselined"?[]:[k("baseline-immutable",`item "${f.id}" is frozen: phase "${u}" is baselined (v${l(u)})`,Ke(f.id,u),f.id)]}if(s.type==="item.add"){let f=R(s).item;if(!C(f)||!Ue(f))return [];let u=He(i,f);return u===void 0||S(i,u)?.status!=="baselined"?[]:[k("baseline-immutable",`cannot add "${f.id}" to baselined phase "${u}" (v${l(u)})`,Ke(f.id,u),f.id)]}return []}},{id:"change-needs-impact-analysis",severity:"error",check(i,s){if(s.type==="item.add"){let r=R(s).item;return !C(r)||r.type!=="change-request"?[]:We(i,String(r.id),r.impactAnalysis)}if(s.type==="item.edit"){let r=R(s).patch,m=M(i,R(s).id);return !m||m.type!=="change-request"||!C(r)||!("impactAnalysis"in r)?[]:We(i,m.id,r.impactAnalysis)}if(s.type!=="ceremony.changeControlBoard")return [];let l=Ye(i,s);if(!l)return [];let f=We(i,l.id,l.impactAnalysis);if(f.length||l.impactAnalysis===void 0)return f;let u=R(s).decision==="approve";for(let r of l.impactAnalysis.reopen){let m=S(i,r);m?u&&m.status==="pending"&&f.push(k("change-needs-impact-analysis",`phase "${r}" was never baselined; it cannot be reopened`,`remove "${r}" from impactAnalysis.reopen`,l.id)):f.push(k("change-needs-impact-analysis",`change "${l.id}" impactAnalysis.reopen names unknown phase "${r}"`,`phases are: ${de(i)}`,l.id));}return f}},{id:"requirement-traced",severity:"error",check(i,s){if(s.type!=="ceremony.gateReview")return [];let l=Q(s),f=w(i).traceability;return l===void 0||!f.to.includes(l)||!S(i,l)?[]:J(i,l).map(u=>k("requirement-traced",`item "${u}" of phase "${f.from}" has no trace into "${l}"`,`editItem a "${l}" item with traces: ["${u}"] (or editItem("${u}", { traces: [...] }) while "${f.from}" is not baselined)`,u))}},{id:"deliverables-present",severity:"error",check(i,s){if(s.type!=="ceremony.gateReview")return [];let l=Q(s),f=l===void 0?void 0:S(i,l);if(!f)return [];let u=[],r=P(i,f.id).filter(v=>v.status!=="done").map(v=>v.id);r.length&&u.push(k("deliverables-present",`${r.length} item(s) in phase "${f.id}" are not done: ${r.join(", ")}`,"finish them (next/complete) or drop them before the gate"));let m=R(s).deliverables,h=Array.isArray(m)?m.filter(v=>C(v)&&typeof v.kind=="string").map(v=>v.kind):[];f.id===B(i)&&h.push("traceability-matrix");for(let v of H(i,f,h))u.push(k("deliverables-present",`phase "${f.id}" has no deliverable "${v}"`,`pass deliverables: [{ "kind": "${v}", "ref": "<where it lives>" }] to gateReview, or attach evidence of kind "${v}" on an item of the phase`));return u}},{id:"approver-not-author",severity:"error",check(i,s){if(s.by==="human")return [];if(s.type==="ceremony.gateReview"){let l=Q(s),f=l===void 0?void 0:S(i,l);if(!f)return [];let u=P(i,f.id).filter(m=>chunkMU26QW32_cjs.G(i,m)===s.by).map(m=>m.id);if(u.length===0)return [];let r=chunkMU26QW32_cjs.h(i,f.gate.id,"approve-gate",s.by);return [k("approver-not-author",`"${s.by}" authored ${u.join(", ")} in phase "${f.id}" and may not approve its gate`,`review the gate as one of: human${r.map(m=>`, ${m}`).join("")}`)]}if(s.type==="ceremony.changeControlBoard"){let l=Ye(i,s);if(!l)return [];let f=i.events.find(r=>r.type==="item.added"&&r.payload.id===l.id);if(!f||f.by!==s.by)return [];let u=chunkMU26QW32_cjs.g(i,"control-change").map(r=>r.id).filter(r=>r!==s.by);return [k("approver-not-author",`"${s.by}" raised change "${l.id}" and may not decide it`,`decide as human${u.map(r=>`, ${r}`).join("")}`,l.id)]}return []}},{id:"trace-ids-valid",severity:"error",check(i,s){let l,f,u,r;if(s.type==="item.add"){let h=R(s).item;if(!C(h))return [];l=String(h.id),f=h.traces,u=h.impactAnalysis,r=h.type==="change-request";}else if(s.type==="item.edit"){let h=M(i,R(s).id),v=R(s).patch;if(!h||!C(v))return [];l=h.id,f=v.traces,u=v.impactAnalysis,r=h.type==="change-request";}else return [];let m=[];if(Array.isArray(f)){let h=w(i).traceability,v=[h.from,...h.to].flatMap(O=>P(i,O).filter(x=>x.type!=="question"&&x.type!=="change-request").map(x=>x.id)),Z=`traceable items: ${v.length?v.join(", "):"(none yet)"}`;for(let O of f){if(typeof O!="string")continue;let x=M(i,O);(!x||x.status==="dropped")&&m.push(k("trace-ids-valid",`item "${l}" traces unknown item "${O}"`,Z,l));}}if(r&&C(u)&&Array.isArray(u.reopen))for(let h of u.reopen)typeof h=="string"&&!S(i,h)&&m.push(k("trace-ids-valid",`change "${l}" impactAnalysis.reopen names unknown phase "${h}"`,`phases are: ${de(i)}`,l));return m}}]}function Re(e){return [{id:L,name:"Work",entryPolicy:[{kind:"dependencies-done"}],exitPolicy:[]},{id:V,name:"Review",entryPolicy:[],exitPolicy:[{kind:"no-open-blockers"}],review:true},{id:z,name:"Done",entryPolicy:[],exitPolicy:[]}]}var nt=Object.freeze({backlog:"Requirements Baseline",item:"Work Package",stage:"Step",iteration:"Phase",increment:"Deliverable",ceremony:"Review",gate:"Phase Gate"});function it(e,t){let n=q(e,t);if(n!==void 0)return w(e).phases.find(a=>a.id===n)?.deliverBy}function rt(e){return {phases:b(e).map(n=>{let a=P(e,n.id),p=a.filter(s=>s.status==="done").length,o=w(e).traceability.to.includes(n.id)?J(e,n.id):[],c=n.id===B(e)&&o.length===0?["traceability-matrix"]:[],i=H(e,n,c);return {id:n.id,name:n.name,status:n.status,items:a.length,done:p,missingDeliverables:i,missingTraces:o,readyForGate:n.status==="open"&&p===a.length&&i.length===0&&o.length===0}}),current:ye(e)?.id??null,open:D(e)?.id??null,pendingGates:e.pending.filter(n=>n.kind==="gate"&&n.item===void 0&&n.gate!==void 0).map(n=>({pending:n.id,gate:n.gate}))}}function at(){return {name:"waterfall",vocabulary:nt,validateConfig:he,defaultStages:Re,defaultRoles:$e,requiredCapabilities:["facilitate","control-change","approve-gate","deliver","verify"],exclusiveCapabilities:[],plannerOptions(e){let t={schedulerMode:"level",roleFor:a=>a.status==="todo"&&a.type!=="question"?it(e,a):void 0},n=w(e).fallbackTokensPerWeight;return n!==void 0&&(t.fallbackTokensPerWeight=n),t},candidates(e){let t=D(e);return t?Object.values(e.items).filter(n=>(n.status==="todo"||n.status==="review")&&(n.stage===L||n.stage===V)&&n.type!=="change-request"&&q(e,n)===t.id):[]},invariants(e,t){let n=w(e),a=b(e),p=q(e,t),d=p===void 0?void 0:a[E(e,p)],o=a.filter(i=>i.status==="baselined").map(i=>i.id),c=d?.gate.requires.includes("human");return [d?`Phase "${d.name}" (${E(e,d.id)+1}/${a.length}); deliverables: ${d.deliverables.join(", ")||"(none)"}; gate "${d.gate.id}"${c?" needs human approval":""}`:"This item belongs to no phase; it is dispatched only through its parent's phase",`Baselined phases are frozen: ${o.join(", ")||"(none yet)"}; to change their items, raise a change-request with an impact analysis`,n.traceability.to.length?`Traceability: every item of phase "${n.traceability.from}" must trace to an item in ${n.traceability.to.join(", ")} (set traces on either side)`:"Traceability: none configured",`Do not change the scope of "${t.id}" or its acceptance criteria; raise open_questions instead`]},ceremonies:ve(at),rules:Ae(),metrics:e=>({...we(e)}),humanDefaults:{gates:"all"},lockedConfigKeys:["phases","traceability","humanGates"],report:e=>({...rt(e),coverage:I(e).coverage}),afterDecide:ke,afterComplete(e,t,n){let a=chunkMU26QW32_cjs.P(e),p=D(e);if(!a||!p||a.committed.includes(t))return e;let d=e.items[t];if(!d||q(e,d)!==p.id)return e;let o=e.accounting[e.accounting.length-1];return !o||o.item!==t?e:{...e,iterations:e.iterations.map(c=>c.id===a.id?{...c,committed:[...c.committed,t],spent:chunkMU26QW32_cjs.L(c.spent,o)}:c)}}}}exports.A=K;exports.B=I;exports.C=J;exports.D=Y;exports.E=ve;exports.F=ke;exports.G=we;exports.H=$e;exports.I=Ae;exports.J=Re;exports.K=nt;exports.L=it;exports.M=rt;exports.N=at;exports.a=Be;exports.b=ae;exports.c=oe;exports.d=me;exports.e=ge;exports.f=Ge;exports.g=w;exports.h=he;exports.i=L;exports.j=V;exports.k=z;exports.l=b;exports.m=T;exports.n=E;exports.o=_;exports.p=q;exports.q=P;exports.r=D;exports.s=ye;exports.t=Qe;exports.u=Fe;exports.v=H;exports.w=B;exports.x=ce;exports.y=be;exports.z=U;//# sourceMappingURL=chunk-2FBA7RBS.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-2FBA7RBS.cjs.map
|