@jam-overture/loom 0.1.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/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/catalogue.d.ts +70 -0
- package/dist/catalogue.js +88 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +83 -0
- package/dist/cli/filesystem.d.ts +15 -0
- package/dist/cli/filesystem.js +31 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +30 -0
- package/dist/cli/namespace.d.ts +40 -0
- package/dist/cli/namespace.js +40 -0
- package/dist/cli/plan.d.ts +84 -0
- package/dist/cli/plan.js +113 -0
- package/dist/cli/run.d.ts +17 -0
- package/dist/cli/run.js +75 -0
- package/dist/cli/templates.d.ts +43 -0
- package/dist/cli/templates.js +134 -0
- package/dist/closed-set.d.ts +34 -0
- package/dist/closed-set.js +34 -0
- package/dist/data/adapter.d.ts +123 -0
- package/dist/data/adapter.js +91 -0
- package/dist/data/binding.d.ts +48 -0
- package/dist/data/binding.js +39 -0
- package/dist/data/catalogue.d.ts +26 -0
- package/dist/data/catalogue.js +6 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.js +14 -0
- package/dist/data/plan.d.ts +58 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +91 -0
- package/dist/data/resolution.js +96 -0
- package/dist/data/resolve.d.ts +46 -0
- package/dist/data/resolve.js +37 -0
- package/dist/data/source.d.ts +40 -0
- package/dist/data/source.js +45 -0
- package/dist/deadline.d.ts +57 -0
- package/dist/deadline.js +78 -0
- package/dist/frame/catalogue.d.ts +24 -0
- package/dist/frame/catalogue.js +5 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/frame/origin.d.ts +87 -0
- package/dist/frame/origin.js +114 -0
- package/dist/frame/resolution.d.ts +85 -0
- package/dist/frame/resolution.js +79 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.js +28 -0
- package/dist/ids.d.ts +57 -0
- package/dist/ids.js +104 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/interactivity.d.ts +50 -0
- package/dist/interactivity.js +22 -0
- package/dist/interpretation/anthropic.d.ts +22 -0
- package/dist/interpretation/anthropic.js +76 -0
- package/dist/interpretation/client.d.ts +83 -0
- package/dist/interpretation/client.js +2 -0
- package/dist/interpretation/draft.d.ts +234 -0
- package/dist/interpretation/draft.js +84 -0
- package/dist/interpretation/index.d.ts +15 -0
- package/dist/interpretation/index.js +15 -0
- package/dist/interpretation/interpreter.d.ts +62 -0
- package/dist/interpretation/interpreter.js +151 -0
- package/dist/interpretation/materialize.d.ts +42 -0
- package/dist/interpretation/materialize.js +107 -0
- package/dist/interpretation/prompt.d.ts +229 -0
- package/dist/interpretation/prompt.js +285 -0
- package/dist/interpretation/render.d.ts +76 -0
- package/dist/interpretation/render.js +272 -0
- package/dist/interpretation/schema.d.ts +49 -0
- package/dist/interpretation/schema.js +131 -0
- package/dist/json.d.ts +35 -0
- package/dist/json.js +11 -0
- package/dist/paging.d.ts +60 -0
- package/dist/paging.js +49 -0
- package/dist/primitive-type.d.ts +32 -0
- package/dist/primitive-type.js +39 -0
- package/dist/render/addressing.d.ts +59 -0
- package/dist/render/addressing.js +60 -0
- package/dist/render/anchor.d.ts +105 -0
- package/dist/render/anchor.js +84 -0
- package/dist/render/behaviour-adjust.d.ts +62 -0
- package/dist/render/behaviour-adjust.js +78 -0
- package/dist/render/behaviour-copy.d.ts +53 -0
- package/dist/render/behaviour-copy.js +75 -0
- package/dist/render/behaviour-disclose.d.ts +74 -0
- package/dist/render/behaviour-disclose.js +77 -0
- package/dist/render/behaviour-present.d.ts +123 -0
- package/dist/render/behaviour-present.js +173 -0
- package/dist/render/behaviour.d.ts +243 -0
- package/dist/render/behaviour.js +284 -0
- package/dist/render/control.d.ts +81 -0
- package/dist/render/control.js +80 -0
- package/dist/render/decorative.d.ts +62 -0
- package/dist/render/decorative.js +2 -0
- package/dist/render/diagnostics.d.ts +260 -0
- package/dist/render/diagnostics.js +61 -0
- package/dist/render/disclosed.d.ts +37 -0
- package/dist/render/disclosed.js +37 -0
- package/dist/render/editable.d.ts +34 -0
- package/dist/render/editable.js +35 -0
- package/dist/render/frame.d.ts +42 -0
- package/dist/render/frame.js +31 -0
- package/dist/render/index.d.ts +35 -0
- package/dist/render/index.js +35 -0
- package/dist/render/inline-variables.d.ts +77 -0
- package/dist/render/inline-variables.js +220 -0
- package/dist/render/presented.d.ts +82 -0
- package/dist/render/presented.js +82 -0
- package/dist/render/primitive.d.ts +228 -0
- package/dist/render/primitive.js +36 -0
- package/dist/render/props.d.ts +48 -0
- package/dist/render/props.js +2 -0
- package/dist/render/reads.d.ts +73 -0
- package/dist/render/reads.js +45 -0
- package/dist/render/render.d.ts +164 -0
- package/dist/render/render.js +571 -0
- package/dist/render/request.d.ts +111 -0
- package/dist/render/request.js +60 -0
- package/dist/render/text.d.ts +91 -0
- package/dist/render/text.js +44 -0
- package/dist/render/theme.d.ts +61 -0
- package/dist/render/theme.js +52 -0
- package/dist/reserved-props.d.ts +35 -0
- package/dist/reserved-props.js +45 -0
- package/dist/result.d.ts +27 -0
- package/dist/result.js +30 -0
- package/dist/role.d.ts +71 -0
- package/dist/role.js +22 -0
- package/dist/runtime/analysis.d.ts +149 -0
- package/dist/runtime/analysis.js +187 -0
- package/dist/runtime/assessment.d.ts +35 -0
- package/dist/runtime/assessment.js +13 -0
- package/dist/runtime/disposition.d.ts +102 -0
- package/dist/runtime/disposition.js +59 -0
- package/dist/runtime/events.d.ts +187 -0
- package/dist/runtime/events.js +7 -0
- package/dist/runtime/gate.d.ts +43 -0
- package/dist/runtime/gate.js +169 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/intent.d.ts +60 -0
- package/dist/runtime/intent.js +36 -0
- package/dist/runtime/interpreter.d.ts +117 -0
- package/dist/runtime/interpreter.js +46 -0
- package/dist/runtime/inverse-interpreter.d.ts +90 -0
- package/dist/runtime/inverse-interpreter.js +56 -0
- package/dist/runtime/inverse.d.ts +87 -0
- package/dist/runtime/inverse.js +48 -0
- package/dist/runtime/narration.d.ts +24 -0
- package/dist/runtime/narration.js +36 -0
- package/dist/runtime/nesting.d.ts +31 -0
- package/dist/runtime/nesting.js +46 -0
- package/dist/runtime/pipeline.d.ts +124 -0
- package/dist/runtime/pipeline.js +178 -0
- package/dist/runtime/policy-fingerprint.d.ts +29 -0
- package/dist/runtime/policy-fingerprint.js +119 -0
- package/dist/runtime/policy-source.d.ts +42 -0
- package/dist/runtime/policy-source.js +8 -0
- package/dist/runtime/policy.d.ts +156 -0
- package/dist/runtime/policy.js +107 -0
- package/dist/runtime/proposal.d.ts +423 -0
- package/dist/runtime/proposal.js +109 -0
- package/dist/runtime/redirection.d.ts +53 -0
- package/dist/runtime/redirection.js +38 -0
- package/dist/runtime/repointing.d.ts +71 -0
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +36 -0
- package/dist/runtime/reversibility.js +39 -0
- package/dist/runtime/stake-level.d.ts +33 -0
- package/dist/runtime/stake-level.js +58 -0
- package/dist/runtime/stakes.d.ts +47 -0
- package/dist/runtime/stakes.js +305 -0
- package/dist/runtime/vocabulary.d.ts +122 -0
- package/dist/runtime/vocabulary.js +87 -0
- package/dist/sdk/audit.d.ts +195 -0
- package/dist/sdk/audit.js +128 -0
- package/dist/sdk/catalogue.d.ts +37 -0
- package/dist/sdk/catalogue.js +16 -0
- package/dist/sdk/conformance.d.ts +342 -0
- package/dist/sdk/conformance.js +494 -0
- package/dist/sdk/copy.d.ts +105 -0
- package/dist/sdk/copy.js +90 -0
- package/dist/sdk/definition.d.ts +242 -0
- package/dist/sdk/definition.js +64 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/interactivity.d.ts +29 -0
- package/dist/sdk/interactivity.js +34 -0
- package/dist/sdk/pairings.d.ts +124 -0
- package/dist/sdk/pairings.js +81 -0
- package/dist/sdk/registry.d.ts +162 -0
- package/dist/sdk/registry.js +329 -0
- package/dist/sdk/selection.d.ts +46 -0
- package/dist/sdk/selection.js +24 -0
- package/dist/sdk/text.d.ts +100 -0
- package/dist/sdk/text.js +105 -0
- package/dist/sdk/vocabulary.d.ts +39 -0
- package/dist/sdk/vocabulary.js +36 -0
- package/dist/signals/broadcast.d.ts +134 -0
- package/dist/signals/broadcast.js +451 -0
- package/dist/signals/collect.d.ts +184 -0
- package/dist/signals/collect.js +196 -0
- package/dist/signals/deliver.d.ts +64 -0
- package/dist/signals/deliver.js +85 -0
- package/dist/signals/fold.d.ts +112 -0
- package/dist/signals/fold.js +76 -0
- package/dist/signals/index.d.ts +31 -0
- package/dist/signals/index.js +31 -0
- package/dist/signals/ingest.d.ts +51 -0
- package/dist/signals/ingest.js +70 -0
- package/dist/signals/intake.d.ts +149 -0
- package/dist/signals/intake.js +154 -0
- package/dist/signals/journal.d.ts +94 -0
- package/dist/signals/journal.js +11 -0
- package/dist/signals/kinds.d.ts +22 -0
- package/dist/signals/kinds.js +22 -0
- package/dist/signals/ledger.d.ts +46 -0
- package/dist/signals/ledger.js +81 -0
- package/dist/signals/memory.d.ts +17 -0
- package/dist/signals/memory.js +99 -0
- package/dist/signals/migrate.d.ts +27 -0
- package/dist/signals/migrate.js +78 -0
- package/dist/signals/postgres.d.ts +7 -0
- package/dist/signals/postgres.js +295 -0
- package/dist/signals/rollup.d.ts +142 -0
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +534 -0
- package/dist/signals/schema.js +92 -0
- package/dist/signals/signal.d.ts +381 -0
- package/dist/signals/signal.js +150 -0
- package/dist/signals/tally.d.ts +70 -0
- package/dist/signals/tally.js +2 -0
- package/dist/signals/view.d.ts +51 -0
- package/dist/signals/view.js +54 -0
- package/dist/store/attribution.d.ts +125 -0
- package/dist/store/attribution.js +116 -0
- package/dist/store/database.d.ts +14 -0
- package/dist/store/database.js +2 -0
- package/dist/store/driver.d.ts +29 -0
- package/dist/store/driver.js +39 -0
- package/dist/store/errors.d.ts +56 -0
- package/dist/store/errors.js +37 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +16 -0
- package/dist/store/memory.d.ts +3 -0
- package/dist/store/memory.js +115 -0
- package/dist/store/migrate.d.ts +54 -0
- package/dist/store/migrate.js +122 -0
- package/dist/store/postgres-holds.d.ts +4 -0
- package/dist/store/postgres-holds.js +192 -0
- package/dist/store/postgres.d.ts +8 -0
- package/dist/store/postgres.js +262 -0
- package/dist/store/replay.d.ts +94 -0
- package/dist/store/replay.js +82 -0
- package/dist/store/revert.d.ts +116 -0
- package/dist/store/revert.js +243 -0
- package/dist/store/schema.d.ts +371 -0
- package/dist/store/schema.js +78 -0
- package/dist/store/source.d.ts +23 -0
- package/dist/store/source.js +37 -0
- package/dist/store/store.d.ts +231 -0
- package/dist/store/store.js +52 -0
- package/dist/store/undone.d.ts +18 -0
- package/dist/store/undone.js +89 -0
- package/dist/submit/catalogue.d.ts +20 -0
- package/dist/submit/catalogue.js +5 -0
- package/dist/submit/declaration.d.ts +39 -0
- package/dist/submit/declaration.js +30 -0
- package/dist/submit/endpoint.d.ts +131 -0
- package/dist/submit/endpoint.js +160 -0
- package/dist/submit/index.d.ts +13 -0
- package/dist/submit/index.js +13 -0
- package/dist/submit/plan.d.ts +49 -0
- package/dist/submit/plan.js +47 -0
- package/dist/submit/resolution.d.ts +61 -0
- package/dist/submit/resolution.js +64 -0
- package/dist/submit/resolve.d.ts +45 -0
- package/dist/submit/resolve.js +36 -0
- package/dist/telemetry/calibration.d.ts +132 -0
- package/dist/telemetry/calibration.js +151 -0
- package/dist/telemetry/episode.d.ts +140 -0
- package/dist/telemetry/episode.js +272 -0
- package/dist/telemetry/event.d.ts +2310 -0
- package/dist/telemetry/event.js +405 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/journal.d.ts +116 -0
- package/dist/telemetry/journal.js +11 -0
- package/dist/telemetry/memory.d.ts +24 -0
- package/dist/telemetry/memory.js +75 -0
- package/dist/telemetry/migrate.d.ts +26 -0
- package/dist/telemetry/migrate.js +40 -0
- package/dist/telemetry/postgres.d.ts +6 -0
- package/dist/telemetry/postgres.js +139 -0
- package/dist/telemetry/retention.d.ts +131 -0
- package/dist/telemetry/retention.js +217 -0
- package/dist/telemetry/schema.d.ts +113 -0
- package/dist/telemetry/schema.js +33 -0
- package/dist/telemetry/sink.d.ts +42 -0
- package/dist/telemetry/sink.js +61 -0
- package/dist/testing/contracts.d.ts +34 -0
- package/dist/testing/contracts.js +34 -0
- package/dist/testing/definitions.d.ts +15 -0
- package/dist/testing/definitions.js +48 -0
- package/dist/testing/doubles.d.ts +94 -0
- package/dist/testing/doubles.js +141 -0
- package/dist/testing/episode-harness.d.ts +49 -0
- package/dist/testing/episode-harness.js +65 -0
- package/dist/testing/filesystem.d.ts +17 -0
- package/dist/testing/filesystem.js +17 -0
- package/dist/testing/fixtures.d.ts +57 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/hold-contract.d.ts +19 -0
- package/dist/testing/hold-contract.js +374 -0
- package/dist/testing/index.d.ts +41 -0
- package/dist/testing/index.js +41 -0
- package/dist/testing/journal-contract.d.ts +17 -0
- package/dist/testing/journal-contract.js +353 -0
- package/dist/testing/model-replies.d.ts +34 -0
- package/dist/testing/model-replies.js +101 -0
- package/dist/testing/primitives.d.ts +7 -0
- package/dist/testing/primitives.js +29 -0
- package/dist/testing/reader-signal-contract.d.ts +38 -0
- package/dist/testing/reader-signal-contract.js +318 -0
- package/dist/testing/row-security.d.ts +17 -0
- package/dist/testing/row-security.js +21 -0
- package/dist/testing/store-contract.d.ts +25 -0
- package/dist/testing/store-contract.js +500 -0
- package/dist/theme/apply.d.ts +17 -0
- package/dist/theme/apply.js +60 -0
- package/dist/theme/contrast.d.ts +197 -0
- package/dist/theme/contrast.js +259 -0
- package/dist/theme/derive.d.ts +77 -0
- package/dist/theme/derive.js +167 -0
- package/dist/theme/faces.d.ts +73 -0
- package/dist/theme/faces.js +119 -0
- package/dist/theme/font-packs.d.ts +25 -0
- package/dist/theme/font-packs.js +257 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/lab.d.ts +30 -0
- package/dist/theme/lab.js +46 -0
- package/dist/theme/library.d.ts +114 -0
- package/dist/theme/library.js +300 -0
- package/dist/theme/measure.d.ts +144 -0
- package/dist/theme/measure.js +145 -0
- package/dist/theme/palettes.d.ts +64 -0
- package/dist/theme/palettes.js +497 -0
- package/dist/theme/registry.d.ts +59 -0
- package/dist/theme/registry.js +60 -0
- package/dist/theme/separation.d.ts +177 -0
- package/dist/theme/separation.js +203 -0
- package/dist/theme/style-presets.d.ts +60 -0
- package/dist/theme/style-presets.js +124 -0
- package/dist/theme/theme.d.ts +253 -0
- package/dist/theme/theme.js +171 -0
- package/dist/tree/apply.d.ts +16 -0
- package/dist/tree/apply.js +104 -0
- package/dist/tree/builders.d.ts +19 -0
- package/dist/tree/builders.js +20 -0
- package/dist/tree/compare.d.ts +68 -0
- package/dist/tree/compare.js +75 -0
- package/dist/tree/configuration.d.ts +25 -0
- package/dist/tree/configuration.js +108 -0
- package/dist/tree/delta.d.ts +288 -0
- package/dist/tree/delta.js +88 -0
- package/dist/tree/errors.d.ts +69 -0
- package/dist/tree/errors.js +34 -0
- package/dist/tree/identity.d.ts +117 -0
- package/dist/tree/identity.js +145 -0
- package/dist/tree/index.d.ts +21 -0
- package/dist/tree/index.js +21 -0
- package/dist/tree/inverse.d.ts +24 -0
- package/dist/tree/inverse.js +112 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +49 -0
- package/dist/tree/naming.d.ts +4 -0
- package/dist/tree/naming.js +35 -0
- package/dist/tree/navigation.d.ts +38 -0
- package/dist/tree/navigation.js +83 -0
- package/dist/tree/node.d.ts +103 -0
- package/dist/tree/node.js +46 -0
- package/dist/tree/outline.d.ts +28 -0
- package/dist/tree/outline.js +10 -0
- package/dist/tree/tree.d.ts +83 -0
- package/dist/tree/tree.js +62 -0
- package/dist/write/commit.d.ts +124 -0
- package/dist/write/commit.js +234 -0
- package/dist/write/held.d.ts +674 -0
- package/dist/write/held.js +185 -0
- package/dist/write/index.d.ts +11 -0
- package/dist/write/index.js +11 -0
- package/dist/write/liveness.d.ts +132 -0
- package/dist/write/liveness.js +91 -0
- package/dist/write/revert.d.ts +79 -0
- package/dist/write/revert.js +134 -0
- package/package.json +160 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { everyMemberOf } from "../closed-set.js";
|
|
2
|
+
/**
|
|
3
|
+
* The buckets a fold has to open before the first proposal arrives, so a reason
|
|
4
|
+
* nobody hit still reads as zero rather than as missing.
|
|
5
|
+
*
|
|
6
|
+
* Checked where it is written because nothing else could: this union has no
|
|
7
|
+
* schema to hold it against, one consumer, and a member added without a bucket
|
|
8
|
+
* costs a telemetry row that never appears — the quietest way a list goes stale.
|
|
9
|
+
* `src/tree/delta.ts` has named it an exemplar of that remedy since it was
|
|
10
|
+
* written, which until now it was not.
|
|
11
|
+
*/
|
|
12
|
+
export const UNJUDGED_REASONS = everyMemberOf()([
|
|
13
|
+
"awaiting-answer",
|
|
14
|
+
"failed",
|
|
15
|
+
"unsettled",
|
|
16
|
+
]);
|
|
17
|
+
/**
|
|
18
|
+
* A repair (0006) is scored as its own proposal, not merged into the one it
|
|
19
|
+
* replaced. Both graded themselves, and the refusal that prompted the repair is
|
|
20
|
+
* exactly the case where the grade was wrong — averaging it away would hide the
|
|
21
|
+
* datapoint calibration exists to collect.
|
|
22
|
+
*/
|
|
23
|
+
export const verdictOf = (proposal) => {
|
|
24
|
+
if (proposal.committedRevision !== undefined)
|
|
25
|
+
return "survived";
|
|
26
|
+
if (proposal.disposition?.kind === "rejected")
|
|
27
|
+
return "rejected";
|
|
28
|
+
if (proposal.answer === "discarded")
|
|
29
|
+
return "rejected";
|
|
30
|
+
if (proposal.failure !== undefined)
|
|
31
|
+
return "failed";
|
|
32
|
+
if (proposal.held)
|
|
33
|
+
return "awaiting-answer";
|
|
34
|
+
return "unsettled";
|
|
35
|
+
};
|
|
36
|
+
export const CALIBRATION_BUCKET_COUNT = 10;
|
|
37
|
+
const BUCKET_LOWER_BOUNDS = Array.from({ length: CALIBRATION_BUCKET_COUNT }, (_, index) => index / CALIBRATION_BUCKET_COUNT);
|
|
38
|
+
/**
|
|
39
|
+
* Counting the bounds a confidence clears, rather than multiplying it out.
|
|
40
|
+
* `Math.floor(0.7 * 10)` is not reliably 7 in binary floating point, and a
|
|
41
|
+
* report that filed a claim under a range its own printed bounds exclude would
|
|
42
|
+
* be wrong in the one way nobody would think to check. Comparing against the
|
|
43
|
+
* very numbers the bucket publishes makes that unrepresentable.
|
|
44
|
+
*/
|
|
45
|
+
const bucketIndexOf = (confidence) => BUCKET_LOWER_BOUNDS.filter((lower) => confidence >= lower).length - 1;
|
|
46
|
+
const scoreOf = (tally) => {
|
|
47
|
+
if (tally.judged === 0) {
|
|
48
|
+
return { judged: 0, survived: 0, observedRate: null, meanConfidence: null, gap: null };
|
|
49
|
+
}
|
|
50
|
+
const observedRate = tally.survived / tally.judged;
|
|
51
|
+
const meanConfidence = tally.confidenceSum / tally.judged;
|
|
52
|
+
return {
|
|
53
|
+
judged: tally.judged,
|
|
54
|
+
survived: tally.survived,
|
|
55
|
+
observedRate,
|
|
56
|
+
meanConfidence,
|
|
57
|
+
gap: meanConfidence - observedRate,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const emptyTally = () => ({ judged: 0, survived: 0, confidenceSum: 0 });
|
|
61
|
+
const emptyBands = () => ({ overall: emptyTally(), byBucket: new Map() });
|
|
62
|
+
const bucketTally = (bands, index) => {
|
|
63
|
+
const existing = bands.byBucket.get(index);
|
|
64
|
+
if (existing)
|
|
65
|
+
return existing;
|
|
66
|
+
const fresh = emptyTally();
|
|
67
|
+
bands.byBucket.set(index, fresh);
|
|
68
|
+
return fresh;
|
|
69
|
+
};
|
|
70
|
+
const addTo = (tally, confidence, verdict) => {
|
|
71
|
+
tally.judged += 1;
|
|
72
|
+
tally.confidenceSum += confidence;
|
|
73
|
+
if (verdict === "survived")
|
|
74
|
+
tally.survived += 1;
|
|
75
|
+
};
|
|
76
|
+
const record = (bands, confidence, verdict) => {
|
|
77
|
+
addTo(bands.overall, confidence, verdict);
|
|
78
|
+
addTo(bucketTally(bands, bucketIndexOf(confidence)), confidence, verdict);
|
|
79
|
+
};
|
|
80
|
+
const bucketsOf = (bands) => BUCKET_LOWER_BOUNDS.map((lower, index) => ({
|
|
81
|
+
lower,
|
|
82
|
+
upper: (index + 1) / CALIBRATION_BUCKET_COUNT,
|
|
83
|
+
...scoreOf(bands.byBucket.get(index) ?? emptyTally()),
|
|
84
|
+
}));
|
|
85
|
+
/**
|
|
86
|
+
* Which policy judged this claim, taken from the disposition and from nowhere
|
|
87
|
+
* else. Its intent also carries a `policyId`, and it is the wrong answer: that
|
|
88
|
+
* one is the *last* resolution the window saw, so on a proposal that was held
|
|
89
|
+
* under one policy and confirmed under a narrower one it names the gate that did
|
|
90
|
+
* not decide this verdict.
|
|
91
|
+
*/
|
|
92
|
+
const judgingPolicyOf = (proposal) => proposal.disposition?.policyId ?? null;
|
|
93
|
+
/** By name, with the unrecorded segment last rather than sorted as a value. */
|
|
94
|
+
const byPolicyName = (left, right) => {
|
|
95
|
+
if (left.policyId === null)
|
|
96
|
+
return right.policyId === null ? 0 : 1;
|
|
97
|
+
if (right.policyId === null)
|
|
98
|
+
return -1;
|
|
99
|
+
return left.policyId < right.policyId ? -1 : left.policyId > right.policyId ? 1 : 0;
|
|
100
|
+
};
|
|
101
|
+
export const calibrationOf = (fold) => {
|
|
102
|
+
const unjudged = { "awaiting-answer": 0, failed: 0, unsettled: 0 };
|
|
103
|
+
const whole = emptyBands();
|
|
104
|
+
const byPolicy = new Map();
|
|
105
|
+
const segmentFor = (policyId) => {
|
|
106
|
+
const existing = byPolicy.get(policyId);
|
|
107
|
+
if (existing)
|
|
108
|
+
return existing;
|
|
109
|
+
const fresh = { bands: emptyBands(), fingerprints: new Set(), unfingerprinted: 0 };
|
|
110
|
+
byPolicy.set(policyId, fresh);
|
|
111
|
+
return fresh;
|
|
112
|
+
};
|
|
113
|
+
let runtimeAuthored = 0;
|
|
114
|
+
for (const episode of fold.episodes) {
|
|
115
|
+
for (const proposal of episode.proposals) {
|
|
116
|
+
if (proposal.provenance.authoredBy !== "model") {
|
|
117
|
+
runtimeAuthored += 1;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const verdict = verdictOf(proposal);
|
|
121
|
+
if (verdict !== "survived" && verdict !== "rejected") {
|
|
122
|
+
unjudged[verdict] += 1;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const { confidence } = proposal.provenance;
|
|
126
|
+
record(whole, confidence, verdict);
|
|
127
|
+
const segment = segmentFor(judgingPolicyOf(proposal));
|
|
128
|
+
record(segment.bands, confidence, verdict);
|
|
129
|
+
const fingerprint = proposal.disposition?.policyFingerprint;
|
|
130
|
+
if (fingerprint === undefined)
|
|
131
|
+
segment.unfingerprinted += 1;
|
|
132
|
+
else
|
|
133
|
+
segment.fingerprints.add(fingerprint);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
overall: scoreOf(whole.overall),
|
|
138
|
+
buckets: bucketsOf(whole),
|
|
139
|
+
byPolicy: Array.from(byPolicy, ([policyId, segment]) => ({
|
|
140
|
+
policyId,
|
|
141
|
+
overall: scoreOf(segment.bands.overall),
|
|
142
|
+
buckets: bucketsOf(segment.bands),
|
|
143
|
+
fingerprints: Array.from(segment.fingerprints).sort(),
|
|
144
|
+
unfingerprinted: segment.unfingerprinted,
|
|
145
|
+
})).sort(byPolicyName),
|
|
146
|
+
unjudged,
|
|
147
|
+
unattributed: fold.unattributed.length,
|
|
148
|
+
runtimeAuthored,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=calibration.js.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { IntentId, ProposalId, TreeId } from "../ids.js";
|
|
2
|
+
import type { Disposition } from "../runtime/disposition.js";
|
|
3
|
+
import type { Provenance } from "../runtime/proposal.js";
|
|
4
|
+
import type { TreeDelta } from "../tree/delta.js";
|
|
5
|
+
import type { AssessmentSummary, IntentSummary, TelemetryFailure } from "./event.js";
|
|
6
|
+
import type { RecordedTelemetry } from "./journal.js";
|
|
7
|
+
/**
|
|
8
|
+
* The fold that turns a stream of records into what §6 was built to answer:
|
|
9
|
+
* for each thing someone asked for, what the model proposed, what the Gate
|
|
10
|
+
* decided, and what became of it.
|
|
11
|
+
*
|
|
12
|
+
* This is a derivation, not a second store. The journal is what is written;
|
|
13
|
+
* episodes are computed from it on demand, the same relationship 0016 set
|
|
14
|
+
* between the log and the snapshot. A stored episode table would be a second
|
|
15
|
+
* copy of the same facts, and the two would eventually disagree — and the
|
|
16
|
+
* disagreement would be silent, because nothing would be checking.
|
|
17
|
+
*
|
|
18
|
+
* It is a pure function of the records it is handed, which also means it is
|
|
19
|
+
* honest about being partial: a page that begins after a proposal was made
|
|
20
|
+
* cannot attribute that proposal's later events, so those records come back as
|
|
21
|
+
* `unattributed` rather than being dropped.
|
|
22
|
+
*/
|
|
23
|
+
export type EpisodeAnswer = "confirmed" | "discarded";
|
|
24
|
+
export type FailureStage = "interpretation" | "assessment" | "repair" | "application" | "custody" | "commit";
|
|
25
|
+
export type EpisodeFailure = TelemetryFailure & {
|
|
26
|
+
readonly stage: FailureStage;
|
|
27
|
+
};
|
|
28
|
+
export type ProposalEpisode = {
|
|
29
|
+
readonly proposalId: ProposalId;
|
|
30
|
+
/** Set when this proposal replaced one the Gate refused (0006). */
|
|
31
|
+
readonly repairOf?: ProposalId;
|
|
32
|
+
readonly provenance: Provenance;
|
|
33
|
+
readonly rationale: string;
|
|
34
|
+
readonly delta: TreeDelta;
|
|
35
|
+
readonly proposedAt: string;
|
|
36
|
+
readonly assessment?: AssessmentSummary;
|
|
37
|
+
readonly disposition?: Disposition;
|
|
38
|
+
/** The Gate held it and custody succeeded, so a human was asked. */
|
|
39
|
+
readonly held: boolean;
|
|
40
|
+
/** A refusal that was handed back for one more attempt. */
|
|
41
|
+
readonly repairRequested: boolean;
|
|
42
|
+
readonly answer?: EpisodeAnswer;
|
|
43
|
+
/**
|
|
44
|
+
* Who answered. Distinct from `provenance.actor`, which is who asked — a hold
|
|
45
|
+
* exists to put a second person in the way of a change, and an episode that
|
|
46
|
+
* showed only the asker would make the two look like one.
|
|
47
|
+
*/
|
|
48
|
+
readonly answeredBy?: string;
|
|
49
|
+
/** Applied in memory. Present without `committedRevision` means it did not persist. */
|
|
50
|
+
readonly appliedRevision?: number;
|
|
51
|
+
readonly committedRevision?: number;
|
|
52
|
+
readonly failure?: EpisodeFailure;
|
|
53
|
+
readonly settledAt?: string;
|
|
54
|
+
};
|
|
55
|
+
export type EpisodeResolution = {
|
|
56
|
+
readonly kind: "committed";
|
|
57
|
+
readonly proposalId: ProposalId;
|
|
58
|
+
readonly revision: number;
|
|
59
|
+
} | {
|
|
60
|
+
readonly kind: "refused";
|
|
61
|
+
readonly proposalId: ProposalId;
|
|
62
|
+
} | {
|
|
63
|
+
readonly kind: "awaiting-answer";
|
|
64
|
+
readonly proposalId: ProposalId;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: "discarded";
|
|
67
|
+
readonly proposalId: ProposalId;
|
|
68
|
+
} | {
|
|
69
|
+
readonly kind: "not-interpreted";
|
|
70
|
+
readonly failure: EpisodeFailure;
|
|
71
|
+
} | {
|
|
72
|
+
readonly kind: "not-writable";
|
|
73
|
+
readonly failure: EpisodeFailure;
|
|
74
|
+
} | {
|
|
75
|
+
readonly kind: "failed";
|
|
76
|
+
readonly proposalId: ProposalId;
|
|
77
|
+
readonly failure: EpisodeFailure;
|
|
78
|
+
}
|
|
79
|
+
/** Nothing in this window settled it — still in flight, or the page ends mid-episode. */
|
|
80
|
+
| {
|
|
81
|
+
readonly kind: "open";
|
|
82
|
+
};
|
|
83
|
+
export type EpisodeResolutionKind = EpisodeResolution["kind"];
|
|
84
|
+
export declare const EPISODE_RESOLUTION_KINDS: readonly EpisodeResolutionKind[];
|
|
85
|
+
export type IntentEpisode = {
|
|
86
|
+
readonly intentId: IntentId;
|
|
87
|
+
readonly treeId: TreeId;
|
|
88
|
+
/** Absent when the window opened after the intent was received. */
|
|
89
|
+
readonly intent?: IntentSummary;
|
|
90
|
+
/**
|
|
91
|
+
* The policy this intent was last resolved to be judged under. Absent when
|
|
92
|
+
* the window opened after resolution, or when the records predate it.
|
|
93
|
+
*
|
|
94
|
+
* "Last" matters for a proposal that was held and later confirmed: the Gate
|
|
95
|
+
* resolves again on the second look, so a host that narrowed its policy in
|
|
96
|
+
* between shows two resolutions and this keeps the one that decided the
|
|
97
|
+
* outcome. Each proposal's disposition carries the policy that judged that
|
|
98
|
+
* proposal, which is the finer-grained truth.
|
|
99
|
+
*/
|
|
100
|
+
readonly policyId?: string;
|
|
101
|
+
readonly startedAt: string;
|
|
102
|
+
readonly proposals: readonly ProposalEpisode[];
|
|
103
|
+
readonly resolution: EpisodeResolution;
|
|
104
|
+
};
|
|
105
|
+
export type EpisodeFold = {
|
|
106
|
+
readonly episodes: readonly IntentEpisode[];
|
|
107
|
+
/**
|
|
108
|
+
* Records that name a proposal this window never saw proposed. Returned
|
|
109
|
+
* rather than discarded: a fold that quietly dropped them would report a
|
|
110
|
+
* refusal rate over a denominator it had silently changed.
|
|
111
|
+
*/
|
|
112
|
+
readonly unattributed: readonly RecordedTelemetry[];
|
|
113
|
+
};
|
|
114
|
+
export declare const episodesOf: (records: readonly RecordedTelemetry[]) => EpisodeFold;
|
|
115
|
+
/**
|
|
116
|
+
* What a window of episodes adds up to.
|
|
117
|
+
*
|
|
118
|
+
* This is the shape of the question 0007 said calibration would eventually need
|
|
119
|
+
* — how often the Gate refuses, how often it asks, how often a repair rescued a
|
|
120
|
+
* refusal — asked of one page rather than of all history. It is a second fold
|
|
121
|
+
* over the first rather than anything the journal stores, for 0016's reason: a
|
|
122
|
+
* counted total that is kept is a total that can disagree with the records it
|
|
123
|
+
* was counted from.
|
|
124
|
+
*/
|
|
125
|
+
export type EpisodeTally = {
|
|
126
|
+
readonly episodes: number;
|
|
127
|
+
readonly proposals: number;
|
|
128
|
+
/** Proposals the Gate would not apply on its own (0002). */
|
|
129
|
+
readonly held: number;
|
|
130
|
+
/** Proposals made to replace one the Gate refused (0006). */
|
|
131
|
+
readonly repairs: number;
|
|
132
|
+
/**
|
|
133
|
+
* Every kind, including the ones that did not happen. A resolution absent from
|
|
134
|
+
* this map and one that occurred zero times are different claims, and only one
|
|
135
|
+
* of them is true.
|
|
136
|
+
*/
|
|
137
|
+
readonly byResolution: Readonly<Record<EpisodeResolutionKind, number>>;
|
|
138
|
+
};
|
|
139
|
+
export declare const tallyEpisodes: (episodes: readonly IntentEpisode[]) => EpisodeTally;
|
|
140
|
+
//# sourceMappingURL=episode.d.ts.map
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { everyMemberOf } from "../closed-set.js";
|
|
2
|
+
import { assertNever } from "../result.js";
|
|
3
|
+
export const EPISODE_RESOLUTION_KINDS = everyMemberOf()([
|
|
4
|
+
"committed",
|
|
5
|
+
"refused",
|
|
6
|
+
"awaiting-answer",
|
|
7
|
+
"discarded",
|
|
8
|
+
"not-interpreted",
|
|
9
|
+
"not-writable",
|
|
10
|
+
"failed",
|
|
11
|
+
"open",
|
|
12
|
+
]);
|
|
13
|
+
const settle = (draft, occurredAt) => {
|
|
14
|
+
draft.settledAt = occurredAt;
|
|
15
|
+
};
|
|
16
|
+
const materialiseProposal = (draft) => ({
|
|
17
|
+
proposalId: draft.proposalId,
|
|
18
|
+
...(draft.repairOf === undefined ? {} : { repairOf: draft.repairOf }),
|
|
19
|
+
provenance: draft.provenance,
|
|
20
|
+
rationale: draft.rationale,
|
|
21
|
+
delta: draft.delta,
|
|
22
|
+
proposedAt: draft.proposedAt,
|
|
23
|
+
...(draft.assessment === undefined ? {} : { assessment: draft.assessment }),
|
|
24
|
+
...(draft.disposition === undefined ? {} : { disposition: draft.disposition }),
|
|
25
|
+
held: draft.held,
|
|
26
|
+
repairRequested: draft.repairRequested,
|
|
27
|
+
...(draft.answer === undefined ? {} : { answer: draft.answer }),
|
|
28
|
+
...(draft.answeredBy === undefined ? {} : { answeredBy: draft.answeredBy }),
|
|
29
|
+
...(draft.appliedRevision === undefined ? {} : { appliedRevision: draft.appliedRevision }),
|
|
30
|
+
...(draft.committedRevision === undefined ? {} : { committedRevision: draft.committedRevision }),
|
|
31
|
+
...(draft.failure === undefined ? {} : { failure: draft.failure }),
|
|
32
|
+
...(draft.settledAt === undefined ? {} : { settledAt: draft.settledAt }),
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* What became of the intent, read off the proposals it produced.
|
|
36
|
+
*
|
|
37
|
+
* A commit anywhere in the chain settles it, because a repaired proposal that
|
|
38
|
+
* applied is the intent being satisfied — the first refusal is part of the
|
|
39
|
+
* story, not the ending. Otherwise the last proposal is the one that speaks:
|
|
40
|
+
* it is either the only attempt, or the repair that replaced the refusal.
|
|
41
|
+
*/
|
|
42
|
+
const resolutionOf = (draft, proposals) => {
|
|
43
|
+
if (draft.failure && draft.failureKind) {
|
|
44
|
+
return draft.failureKind === "not-interpreted"
|
|
45
|
+
? { kind: "not-interpreted", failure: draft.failure }
|
|
46
|
+
: { kind: "not-writable", failure: draft.failure };
|
|
47
|
+
}
|
|
48
|
+
const committed = proposals.find((proposal) => proposal.committedRevision !== undefined);
|
|
49
|
+
if (committed?.committedRevision !== undefined) {
|
|
50
|
+
return {
|
|
51
|
+
kind: "committed",
|
|
52
|
+
proposalId: committed.proposalId,
|
|
53
|
+
revision: committed.committedRevision,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const last = proposals.at(-1);
|
|
57
|
+
if (!last)
|
|
58
|
+
return { kind: "open" };
|
|
59
|
+
if (last.failure)
|
|
60
|
+
return { kind: "failed", proposalId: last.proposalId, failure: last.failure };
|
|
61
|
+
if (last.answer === "discarded")
|
|
62
|
+
return { kind: "discarded", proposalId: last.proposalId };
|
|
63
|
+
if (last.held && last.answer === undefined) {
|
|
64
|
+
return { kind: "awaiting-answer", proposalId: last.proposalId };
|
|
65
|
+
}
|
|
66
|
+
if (last.disposition?.kind === "rejected") {
|
|
67
|
+
return { kind: "refused", proposalId: last.proposalId };
|
|
68
|
+
}
|
|
69
|
+
return { kind: "open" };
|
|
70
|
+
};
|
|
71
|
+
export const episodesOf = (records) => {
|
|
72
|
+
const intents = new Map();
|
|
73
|
+
const proposals = new Map();
|
|
74
|
+
const unattributed = [];
|
|
75
|
+
const intentDraft = (intentId, record) => {
|
|
76
|
+
const existing = intents.get(intentId);
|
|
77
|
+
if (existing)
|
|
78
|
+
return existing;
|
|
79
|
+
const draft = {
|
|
80
|
+
intentId,
|
|
81
|
+
treeId: record.treeId,
|
|
82
|
+
intent: undefined,
|
|
83
|
+
policyId: undefined,
|
|
84
|
+
startedAt: record.occurredAt,
|
|
85
|
+
failure: undefined,
|
|
86
|
+
failureKind: undefined,
|
|
87
|
+
proposalIds: [],
|
|
88
|
+
};
|
|
89
|
+
intents.set(intentId, draft);
|
|
90
|
+
return draft;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Every proposal-keyed event runs through here, so "this record names a
|
|
94
|
+
* proposal the window never saw" is answered in exactly one place and always
|
|
95
|
+
* produces the same outcome.
|
|
96
|
+
*/
|
|
97
|
+
const withProposal = (proposalId, record, update) => {
|
|
98
|
+
const draft = proposals.get(proposalId);
|
|
99
|
+
if (!draft) {
|
|
100
|
+
unattributed.push(record);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
update(draft);
|
|
104
|
+
};
|
|
105
|
+
for (const record of records) {
|
|
106
|
+
const { event, occurredAt } = record;
|
|
107
|
+
switch (event.type) {
|
|
108
|
+
case "intent-received": {
|
|
109
|
+
const draft = intentDraft(event.intent.intentId, record);
|
|
110
|
+
draft.intent = event.intent;
|
|
111
|
+
draft.startedAt = occurredAt;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "policy-resolved": {
|
|
115
|
+
intentDraft(event.intentId, record).policyId = event.policyId;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case "interpretation-failed": {
|
|
119
|
+
const draft = intentDraft(event.intentId, record);
|
|
120
|
+
draft.failure = { stage: "interpretation", ...event.failure };
|
|
121
|
+
draft.failureKind = "not-interpreted";
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case "intent-not-writable": {
|
|
125
|
+
const draft = intentDraft(event.intentId, record);
|
|
126
|
+
draft.failure = { stage: "interpretation", ...event.failure };
|
|
127
|
+
draft.failureKind = "not-writable";
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "change-proposed": {
|
|
131
|
+
const { proposal } = event;
|
|
132
|
+
const intent = intentDraft(proposal.intentId, record);
|
|
133
|
+
intent.treeId = record.treeId;
|
|
134
|
+
intent.proposalIds.push(proposal.proposalId);
|
|
135
|
+
proposals.set(proposal.proposalId, {
|
|
136
|
+
proposalId: proposal.proposalId,
|
|
137
|
+
intentId: proposal.intentId,
|
|
138
|
+
repairOf: proposal.repairOf,
|
|
139
|
+
provenance: proposal.provenance,
|
|
140
|
+
rationale: proposal.rationale,
|
|
141
|
+
delta: proposal.delta,
|
|
142
|
+
proposedAt: occurredAt,
|
|
143
|
+
assessment: undefined,
|
|
144
|
+
disposition: undefined,
|
|
145
|
+
held: false,
|
|
146
|
+
repairRequested: false,
|
|
147
|
+
answer: undefined,
|
|
148
|
+
answeredBy: undefined,
|
|
149
|
+
appliedRevision: undefined,
|
|
150
|
+
committedRevision: undefined,
|
|
151
|
+
failure: undefined,
|
|
152
|
+
settledAt: undefined,
|
|
153
|
+
});
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "change-assessed":
|
|
157
|
+
withProposal(event.assessment.proposalId, record, (draft) => {
|
|
158
|
+
draft.assessment = event.assessment;
|
|
159
|
+
});
|
|
160
|
+
break;
|
|
161
|
+
case "assessment-failed":
|
|
162
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
163
|
+
draft.failure = { stage: "assessment", ...event.failure };
|
|
164
|
+
settle(draft, occurredAt);
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
/**
|
|
168
|
+
* A second disposition overwrites the first on purpose: a held proposal is
|
|
169
|
+
* judged again when it is confirmed, and the Gate's second look is the one
|
|
170
|
+
* that decided whether it applied.
|
|
171
|
+
*/
|
|
172
|
+
case "disposition-decided":
|
|
173
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
174
|
+
draft.disposition = event.disposition;
|
|
175
|
+
if (event.disposition.kind === "rejected")
|
|
176
|
+
settle(draft, occurredAt);
|
|
177
|
+
});
|
|
178
|
+
break;
|
|
179
|
+
case "repair-requested":
|
|
180
|
+
withProposal(event.refusedProposalId, record, (draft) => {
|
|
181
|
+
draft.repairRequested = true;
|
|
182
|
+
});
|
|
183
|
+
break;
|
|
184
|
+
case "repair-failed":
|
|
185
|
+
withProposal(event.refusedProposalId, record, (draft) => {
|
|
186
|
+
draft.failure = { stage: "repair", ...event.failure };
|
|
187
|
+
settle(draft, occurredAt);
|
|
188
|
+
});
|
|
189
|
+
break;
|
|
190
|
+
case "proposal-held":
|
|
191
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
192
|
+
draft.held = true;
|
|
193
|
+
});
|
|
194
|
+
break;
|
|
195
|
+
case "hold-failed":
|
|
196
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
197
|
+
draft.failure = { stage: "custody", ...event.failure };
|
|
198
|
+
settle(draft, occurredAt);
|
|
199
|
+
});
|
|
200
|
+
break;
|
|
201
|
+
case "hold-confirmed":
|
|
202
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
203
|
+
draft.answer = "confirmed";
|
|
204
|
+
draft.answeredBy = event.actor;
|
|
205
|
+
});
|
|
206
|
+
break;
|
|
207
|
+
case "hold-discarded":
|
|
208
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
209
|
+
draft.answer = "discarded";
|
|
210
|
+
draft.answeredBy = event.actor;
|
|
211
|
+
settle(draft, occurredAt);
|
|
212
|
+
});
|
|
213
|
+
break;
|
|
214
|
+
case "change-applied":
|
|
215
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
216
|
+
draft.appliedRevision = event.revision;
|
|
217
|
+
});
|
|
218
|
+
break;
|
|
219
|
+
case "application-failed":
|
|
220
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
221
|
+
draft.failure = { stage: "application", ...event.failure };
|
|
222
|
+
settle(draft, occurredAt);
|
|
223
|
+
});
|
|
224
|
+
break;
|
|
225
|
+
case "change-committed":
|
|
226
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
227
|
+
draft.committedRevision = event.revision;
|
|
228
|
+
settle(draft, occurredAt);
|
|
229
|
+
});
|
|
230
|
+
break;
|
|
231
|
+
case "commit-failed":
|
|
232
|
+
withProposal(event.proposalId, record, (draft) => {
|
|
233
|
+
draft.failure = { stage: "commit", ...event.failure };
|
|
234
|
+
settle(draft, occurredAt);
|
|
235
|
+
});
|
|
236
|
+
break;
|
|
237
|
+
default:
|
|
238
|
+
assertNever(event, "episodesOf");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const episodes = Array.from(intents.values()).map((draft) => {
|
|
242
|
+
const owned = draft.proposalIds.flatMap((proposalId) => {
|
|
243
|
+
const proposal = proposals.get(proposalId);
|
|
244
|
+
return proposal ? [materialiseProposal(proposal)] : [];
|
|
245
|
+
});
|
|
246
|
+
return {
|
|
247
|
+
intentId: draft.intentId,
|
|
248
|
+
treeId: draft.treeId,
|
|
249
|
+
...(draft.intent === undefined ? {} : { intent: draft.intent }),
|
|
250
|
+
...(draft.policyId === undefined ? {} : { policyId: draft.policyId }),
|
|
251
|
+
startedAt: draft.startedAt,
|
|
252
|
+
proposals: owned,
|
|
253
|
+
resolution: resolutionOf(draft, owned),
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
return { episodes, unattributed };
|
|
257
|
+
};
|
|
258
|
+
const emptyTally = () => Object.fromEntries(EPISODE_RESOLUTION_KINDS.map((kind) => [kind, 0]));
|
|
259
|
+
export const tallyEpisodes = (episodes) => {
|
|
260
|
+
const byResolution = emptyTally();
|
|
261
|
+
let proposals = 0;
|
|
262
|
+
let held = 0;
|
|
263
|
+
let repairs = 0;
|
|
264
|
+
for (const episode of episodes) {
|
|
265
|
+
byResolution[episode.resolution.kind] += 1;
|
|
266
|
+
proposals += episode.proposals.length;
|
|
267
|
+
held += episode.proposals.filter((proposal) => proposal.held).length;
|
|
268
|
+
repairs += episode.proposals.filter((proposal) => proposal.repairOf !== undefined).length;
|
|
269
|
+
}
|
|
270
|
+
return { episodes: episodes.length, proposals, held, repairs, byResolution };
|
|
271
|
+
};
|
|
272
|
+
//# sourceMappingURL=episode.js.map
|