@idlekit/core 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +7 -0
  3. package/dist/index.js +7 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/scenario/compile.js +1 -0
  6. package/dist/scenario/compile.js.map +1 -1
  7. package/dist/scenario/scenarioContract.d.ts +30 -0
  8. package/dist/scenario/scenarioContract.js +35 -0
  9. package/dist/scenario/scenarioContract.js.map +1 -1
  10. package/dist/sim/advance.d.ts +198 -0
  11. package/dist/sim/advance.js +609 -0
  12. package/dist/sim/advance.js.map +1 -0
  13. package/dist/sim/analysis/checks.d.ts +260 -0
  14. package/dist/sim/analysis/checks.js +1442 -0
  15. package/dist/sim/analysis/checks.js.map +1 -0
  16. package/dist/sim/analysis/flow.d.ts +169 -0
  17. package/dist/sim/analysis/flow.js +1359 -0
  18. package/dist/sim/analysis/flow.js.map +1 -0
  19. package/dist/sim/analysis/jevAdvisory.d.ts +113 -0
  20. package/dist/sim/analysis/jevAdvisory.js +846 -0
  21. package/dist/sim/analysis/jevAdvisory.js.map +1 -0
  22. package/dist/sim/analysis/judge.d.ts +145 -0
  23. package/dist/sim/analysis/judge.js +1451 -0
  24. package/dist/sim/analysis/judge.js.map +1 -0
  25. package/dist/sim/analysis/registry.d.ts +9 -6
  26. package/dist/sim/analysis/registry.js +15 -2
  27. package/dist/sim/analysis/registry.js.map +1 -1
  28. package/dist/sim/executionBackend.d.ts +165 -0
  29. package/dist/sim/executionBackend.js +521 -0
  30. package/dist/sim/executionBackend.js.map +1 -0
  31. package/dist/sim/integrationMatrix.d.ts +52 -0
  32. package/dist/sim/integrationMatrix.js +68 -0
  33. package/dist/sim/integrationMatrix.js.map +1 -0
  34. package/dist/sim/observation.d.ts +11 -0
  35. package/dist/sim/observation.js +12 -0
  36. package/dist/sim/observation.js.map +1 -1
  37. package/dist/sim/offline.d.ts +2 -0
  38. package/dist/sim/offline.js +68 -1
  39. package/dist/sim/offline.js.map +1 -1
  40. package/dist/sim/simulator.d.ts +2 -0
  41. package/dist/sim/simulator.js +71 -1
  42. package/dist/sim/simulator.js.map +1 -1
  43. package/dist/sim/step.d.ts +10 -0
  44. package/dist/sim/step.js +10 -0
  45. package/dist/sim/step.js.map +1 -1
  46. package/dist/sim/types.d.ts +11 -0
  47. package/package.json +1 -1
@@ -0,0 +1,1359 @@
1
+ import * as _validateReport_1 from "typia/lib/internal/_validateReport";
2
+ import * as _createStandardSchema_1 from "typia/lib/internal/_createStandardSchema";
3
+ import typia, {} from "typia";
4
+ /**
5
+ * Passive flow diagnosis. This is not a factory runtime and not a second simulator loop.
6
+ * Samples arrive from a fixture or from RunObserver.onFlow. A growth regime is not a cause.
7
+ */
8
+ const FLOW_SCHEMA_ID = "https://idlekit.dev/schemas/flow.v1.schema.json";
9
+ const FLOW_ALGORITHM_VERSION = "flow-observation-1";
10
+ /**
11
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-flow-adapter The published schema id is the flow report.
12
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-flow-adapter #3c616c8 Re-read the section: the id is the flow v1 schema.
13
+ */
14
+ export function flowSchemaId() {
15
+ return FLOW_SCHEMA_ID;
16
+ }
17
+ /**
18
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-flow-adapter The algorithm version is flow-observation-1.
19
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-flow-adapter #3c616c8 Re-read the section: the version string is flow-observation-1.
20
+ */
21
+ export function flowAlgorithmVersion() {
22
+ return FLOW_ALGORITHM_VERSION;
23
+ }
24
+ /**
25
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-flow-adapter Flow samples are optional. Model gains no required method.
26
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-flow-adapter #3c616c8 Re-read the section: the observer hook is optional and resource names stay in the fixture.
27
+ */
28
+ export const flowOptionalAdapter = "observer-not-required-model";
29
+ /**
30
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-pipeline A steady 100 to 20 to 30 chain binds at the middle stage.
31
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-pipeline #597bca1 Re-read the section: final throughput stays 20 when inflow doubles, a bind reads one resource and one window, the causally named bind is confirmed among several, each terminal process reports a final throughput per delivered resource from its latest window and cites the delivering edges, an inflow source offers work, a process series is judged only on its latest saturated window, downstream slack counts every feed into that stage, a confirmed bind cites the causal record, and the bind cites its edges and requires a downstream capacity, upstream offer, and side feed in the unit an identity edge keeps, citing the throughput that named it.
32
+ */
33
+ export const flowPipelineConstraint = "process-throughput-20";
34
+ /**
35
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-conservation Conversion, loss, and inventory stay in their own units.
36
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-conservation #514285c Re-read the section: the source unit and the destination unit are not added, queue and unretained are read for the destination resource in the source window, every source window is tried with the latest conserving one kept, the stock must match an observed destination throughput unit and the fact cites it, conservation compares per-window rates, edges into one stock are summed, a positive conversion underflowing to zero cannot establish conservation, genuine zero operands or exactly total loss retain a valid zero conversion, and zero matches only zero.
37
+ */
38
+ export const flowConservation = "converted-units-stay-apart";
39
+ /**
40
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-unsupported A model without flow observations is unsupported.
41
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-unsupported #2733085 Re-read the section: a stall regime does not become a capacity cause.
42
+ */
43
+ export const flowUnsupportedModel = "no-invented-stall";
44
+ /**
45
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-suspected Missing demand and capacity observations stay unresolved.
46
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-suspected #f4956d5 Re-read the section: facts and hypotheses are separate, starved and blocked time in seconds are judged per process from their latest window, where every resource in that window counts and a latest zero clears an older wait and is cited, with mixed waits unresolved, a Little's law product of positive representable operands that underflows to zero is insufficient-data while a genuinely zero arrival or wait keeps a valid zero product, and a ramp-up observation or window skips Little's law.
47
+ */
48
+ export const flowSuspectedCause = "facts-apart-from-cause";
49
+ /*
50
+ * typia runs on first call, not at module load. A plugin that the bundled CLI loads
51
+ * imports core source without the transform, and a module-load call would throw there.
52
+ */
53
+ let validateFlowReportValidator;
54
+ let validateObservationValidator;
55
+ /**
56
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-flow-adapter The published validator is createValidate of the flow report.
57
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-flow-adapter #3c616c8 Re-read the section: the structural document is FlowReportV1.
58
+ */
59
+ export const validateFlowReport = (input) => (validateFlowReportValidator ??= (() => {
60
+ const _ip0 = input => "string" === typeof input["id"];
61
+ const _iv0 = new Set(["blocked-time", "capacity", "conservation", "final-throughput", "inflow", "queue", "saturation-time", "starved-time", "throughput", "unretained"]);
62
+ const _ip1 = input => Array.isArray(input["evidenceRefs"]) && input["evidenceRefs"].every(elem => "string" === typeof elem);
63
+ const _ve0 = "Readonly<{ schemaVersion: 1; contract: \"idlekit.flow.v1\"; algorithmVersion: \"flow-observation-1\"; capability: \"statically-known\" | \"unknown\" | \"unsupported\"; status: \"insufficient-data\" | \"ok\" | \"unsupported\"; ... 4 more ...; externalProvider: false; }>";
64
+ const _ve1 = "Readonly<{ id: string; processId: string; resourceId: string; kind: FlowFactKind; amount: string; unit: string; window: Readonly<{ startSec: number; endSec: number; }>; evidenceRefs: readonly string[]; }>";
65
+ const _ve2 = "ReadonlyArray<Readonly<{ id: string; processId: string; resourceId: string; kind: FlowFactKind; amount: string; unit: string; window: Readonly<{ startSec: number; endSec: number; }>; evidenceRefs: readonly string[]; }>>";
66
+ const _ve3 = "Readonly<{ id: string; processId: string | null; status: FlowCauseStatus; claim: FlowCauseClaim; evidenceRefs: readonly string[]; reason: string; }>";
67
+ const _ve4 = "ReadonlyArray<Readonly<{ id: string; processId: string | null; status: FlowCauseStatus; claim: FlowCauseClaim; evidenceRefs: readonly string[]; reason: string; }>>";
68
+ const _vp0 = (input, _path, _exceptionable = true) => "string" === typeof input["id"] || _report(_exceptionable, {
69
+ path: _path + ".id",
70
+ expected: "string",
71
+ value: input["id"]
72
+ });
73
+ const _vv0 = new Set(["blocked-time", "capacity", "conservation", "final-throughput", "inflow", "queue", "saturation-time", "starved-time", "throughput", "unretained"]);
74
+ const _ve5 = "(\"blocked-time\" | \"capacity\" | \"conservation\" | \"final-throughput\" | \"inflow\" | \"queue\" | \"saturation-time\" | \"starved-time\" | \"throughput\" | \"unretained\")";
75
+ const _vp1 = (input, _path, _exceptionable = true) => (Array.isArray(input["evidenceRefs"]) || _report(_exceptionable, {
76
+ path: _path + ".evidenceRefs",
77
+ expected: "ReadonlyArray<string>",
78
+ value: input["evidenceRefs"]
79
+ })) && input["evidenceRefs"].map((elem, _index6) => "string" === typeof elem || _report(_exceptionable, {
80
+ path: _path + ".evidenceRefs[" + _index6 + "]",
81
+ expected: "string",
82
+ value: elem
83
+ })).every(flag => flag) || _report(_exceptionable, {
84
+ path: _path + ".evidenceRefs",
85
+ expected: "ReadonlyArray<string>",
86
+ value: input["evidenceRefs"]
87
+ });
88
+ const _io0 = input => 1 === input.schemaVersion && "idlekit.flow.v1" === input.contract && "flow-observation-1" === input.algorithmVersion && ("statically-known" === input.capability || "unknown" === input.capability || "unsupported" === input.capability) && ("insufficient-data" === input.status || "ok" === input.status || "unsupported" === input.status) && (Array.isArray(input.facts) && input.facts.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && (Array.isArray(input.hypotheses) && input.hypotheses.every(elem => "object" === typeof elem && null !== elem && _io3(elem))) && ("object" === typeof input.littlesLaw && null !== input.littlesLaw && _io4(input.littlesLaw)) && false === input.stallMapped && false === input.externalProvider;
89
+ const _io1 = input => _ip0(input) && "string" === typeof input.processId && "string" === typeof input.resourceId && true === _iv0.has(input.kind) && "string" === typeof input.amount && "string" === typeof input.unit && ("object" === typeof input.window && null !== input.window && _io2(input.window)) && _ip1(input);
90
+ const _io2 = input => "number" === typeof input.startSec && "number" === typeof input.endSec;
91
+ const _io3 = input => _ip0(input) && (null === input.processId || "string" === typeof input.processId) && ("confirmed" === input.status || "insufficient-data" === input.status || "suspected" === input.status || "unsupported" === input.status) && ("capacity-constraint" === input.claim || "demand-shortage" === input.claim || "material-shortage" === input.claim || "none" === input.claim) && _ip1(input) && "string" === typeof input.reason;
92
+ const _io4 = input => ("consistent" === input.status || "inconsistent" === input.status || "insufficient-data" === input.status || "not-applicable" === input.status) && "string" === typeof input.assumption;
93
+ const _vo0 = (input, _path, _exceptionable = true) => [1 === input.schemaVersion || _report(_exceptionable, {
94
+ path: _path + ".schemaVersion",
95
+ expected: "1",
96
+ value: input.schemaVersion
97
+ }), "idlekit.flow.v1" === input.contract || _report(_exceptionable, {
98
+ path: _path + ".contract",
99
+ expected: "\"idlekit.flow.v1\"",
100
+ value: input.contract
101
+ }), "flow-observation-1" === input.algorithmVersion || _report(_exceptionable, {
102
+ path: _path + ".algorithmVersion",
103
+ expected: "\"flow-observation-1\"",
104
+ value: input.algorithmVersion
105
+ }), "statically-known" === input.capability || "unknown" === input.capability || "unsupported" === input.capability || _report(_exceptionable, {
106
+ path: _path + ".capability",
107
+ expected: "(\"statically-known\" | \"unknown\" | \"unsupported\")",
108
+ value: input.capability
109
+ }), "insufficient-data" === input.status || "ok" === input.status || "unsupported" === input.status || _report(_exceptionable, {
110
+ path: _path + ".status",
111
+ expected: "(\"insufficient-data\" | \"ok\" | \"unsupported\")",
112
+ value: input.status
113
+ }), (Array.isArray(input.facts) || _report(_exceptionable, {
114
+ path: _path + ".facts",
115
+ expected: _ve2,
116
+ value: input.facts
117
+ })) && input.facts.map((elem, _index4) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
118
+ path: _path + ".facts[" + _index4 + "]",
119
+ expected: _ve1,
120
+ value: elem
121
+ })) && _vo1(elem, _path + ".facts[" + _index4 + "]", true && _exceptionable) || _report(_exceptionable, {
122
+ path: _path + ".facts[" + _index4 + "]",
123
+ expected: _ve1,
124
+ value: elem
125
+ })).every(flag => flag) || _report(_exceptionable, {
126
+ path: _path + ".facts",
127
+ expected: _ve2,
128
+ value: input.facts
129
+ }), (Array.isArray(input.hypotheses) || _report(_exceptionable, {
130
+ path: _path + ".hypotheses",
131
+ expected: _ve4,
132
+ value: input.hypotheses
133
+ })) && input.hypotheses.map((elem, _index5) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
134
+ path: _path + ".hypotheses[" + _index5 + "]",
135
+ expected: _ve3,
136
+ value: elem
137
+ })) && _vo3(elem, _path + ".hypotheses[" + _index5 + "]", true && _exceptionable) || _report(_exceptionable, {
138
+ path: _path + ".hypotheses[" + _index5 + "]",
139
+ expected: _ve3,
140
+ value: elem
141
+ })).every(flag => flag) || _report(_exceptionable, {
142
+ path: _path + ".hypotheses",
143
+ expected: _ve4,
144
+ value: input.hypotheses
145
+ }), ("object" === typeof input.littlesLaw && null !== input.littlesLaw || _report(_exceptionable, {
146
+ path: _path + ".littlesLaw",
147
+ expected: "Readonly<{ status: \"consistent\" | \"inconsistent\" | \"insufficient-data\" | \"not-applicable\"; assumption: string; }>",
148
+ value: input.littlesLaw
149
+ })) && _vo4(input.littlesLaw, _path + ".littlesLaw", true && _exceptionable) || _report(_exceptionable, {
150
+ path: _path + ".littlesLaw",
151
+ expected: "Readonly<{ status: \"consistent\" | \"inconsistent\" | \"insufficient-data\" | \"not-applicable\"; assumption: string; }>",
152
+ value: input.littlesLaw
153
+ }), false === input.stallMapped || _report(_exceptionable, {
154
+ path: _path + ".stallMapped",
155
+ expected: "false",
156
+ value: input.stallMapped
157
+ }), false === input.externalProvider || _report(_exceptionable, {
158
+ path: _path + ".externalProvider",
159
+ expected: "false",
160
+ value: input.externalProvider
161
+ })].every(flag => flag);
162
+ const _vo1 = (input, _path, _exceptionable = true) => [_vp0(input, _path, true && _exceptionable), "string" === typeof input.processId || _report(_exceptionable, {
163
+ path: _path + ".processId",
164
+ expected: "string",
165
+ value: input.processId
166
+ }), "string" === typeof input.resourceId || _report(_exceptionable, {
167
+ path: _path + ".resourceId",
168
+ expected: "string",
169
+ value: input.resourceId
170
+ }), true === _vv0.has(input.kind) || _report(_exceptionable, {
171
+ path: _path + ".kind",
172
+ expected: _ve5,
173
+ value: input.kind
174
+ }), "string" === typeof input.amount || _report(_exceptionable, {
175
+ path: _path + ".amount",
176
+ expected: "string",
177
+ value: input.amount
178
+ }), "string" === typeof input.unit || _report(_exceptionable, {
179
+ path: _path + ".unit",
180
+ expected: "string",
181
+ value: input.unit
182
+ }), ("object" === typeof input.window && null !== input.window || _report(_exceptionable, {
183
+ path: _path + ".window",
184
+ expected: "Readonly<{ startSec: number; endSec: number; }>",
185
+ value: input.window
186
+ })) && _vo2(input.window, _path + ".window", true && _exceptionable) || _report(_exceptionable, {
187
+ path: _path + ".window",
188
+ expected: "Readonly<{ startSec: number; endSec: number; }>",
189
+ value: input.window
190
+ }), _vp1(input, _path, true && _exceptionable)].every(flag => flag);
191
+ const _vo2 = (input, _path, _exceptionable = true) => ["number" === typeof input.startSec || _report(_exceptionable, {
192
+ path: _path + ".startSec",
193
+ expected: "number",
194
+ value: input.startSec
195
+ }), "number" === typeof input.endSec || _report(_exceptionable, {
196
+ path: _path + ".endSec",
197
+ expected: "number",
198
+ value: input.endSec
199
+ })].every(flag => flag);
200
+ const _vo3 = (input, _path, _exceptionable = true) => [_vp0(input, _path, true && _exceptionable), null === input.processId || "string" === typeof input.processId || _report(_exceptionable, {
201
+ path: _path + ".processId",
202
+ expected: "(null | string)",
203
+ value: input.processId
204
+ }), "confirmed" === input.status || "insufficient-data" === input.status || "suspected" === input.status || "unsupported" === input.status || _report(_exceptionable, {
205
+ path: _path + ".status",
206
+ expected: "(\"confirmed\" | \"insufficient-data\" | \"suspected\" | \"unsupported\")",
207
+ value: input.status
208
+ }), "capacity-constraint" === input.claim || "demand-shortage" === input.claim || "material-shortage" === input.claim || "none" === input.claim || _report(_exceptionable, {
209
+ path: _path + ".claim",
210
+ expected: "(\"capacity-constraint\" | \"demand-shortage\" | \"material-shortage\" | \"none\")",
211
+ value: input.claim
212
+ }), _vp1(input, _path, true && _exceptionable), "string" === typeof input.reason || _report(_exceptionable, {
213
+ path: _path + ".reason",
214
+ expected: "string",
215
+ value: input.reason
216
+ })].every(flag => flag);
217
+ const _vo4 = (input, _path, _exceptionable = true) => ["consistent" === input.status || "inconsistent" === input.status || "insufficient-data" === input.status || "not-applicable" === input.status || _report(_exceptionable, {
218
+ path: _path + ".status",
219
+ expected: "(\"consistent\" | \"inconsistent\" | \"insufficient-data\" | \"not-applicable\")",
220
+ value: input.status
221
+ }), "string" === typeof input.assumption || _report(_exceptionable, {
222
+ path: _path + ".assumption",
223
+ expected: "string",
224
+ value: input.assumption
225
+ })].every(flag => flag);
226
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
227
+ let errors;
228
+ let _report;
229
+ return _createStandardSchema_1._createStandardSchema(input => {
230
+ if (false === __is(input)) {
231
+ errors = [];
232
+ _report = _validateReport_1._validateReport(errors);
233
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
234
+ path: _path + "",
235
+ expected: _ve0,
236
+ value: input
237
+ })) && _vo0(input, _path + "", true) || _report(true, {
238
+ path: _path + "",
239
+ expected: _ve0,
240
+ value: input
241
+ }))(input, "$input", true);
242
+ const success = 0 === errors.length;
243
+ return success ? {
244
+ success,
245
+ data: input
246
+ } : {
247
+ success,
248
+ errors,
249
+ data: input
250
+ };
251
+ }
252
+ return {
253
+ success: true,
254
+ data: input
255
+ };
256
+ });
257
+ })())(input);
258
+ function buildFlowJsonSchema() {
259
+ return {
260
+ components: {
261
+ schemas: {
262
+ "ReadonlyschemaVersion1contractidlekit_x2E_flow_x2E_v1algorithmVersionflow-observation-1capabilitystatically-knownunknownunsupportedstatusinsufficient-dataokunsupported---4more---externalProviderfalse-xABBAB21BB2DB84A3": {
263
+ type: "object",
264
+ properties: {
265
+ schemaVersion: {
266
+ "const": 1
267
+ },
268
+ contract: {
269
+ "const": "idlekit.flow.v1"
270
+ },
271
+ algorithmVersion: {
272
+ "const": "flow-observation-1"
273
+ },
274
+ capability: {
275
+ oneOf: [
276
+ {
277
+ "const": "statically-known"
278
+ },
279
+ {
280
+ "const": "unknown"
281
+ },
282
+ {
283
+ "const": "unsupported"
284
+ }
285
+ ]
286
+ },
287
+ status: {
288
+ oneOf: [
289
+ {
290
+ "const": "insufficient-data"
291
+ },
292
+ {
293
+ "const": "ok"
294
+ },
295
+ {
296
+ "const": "unsupported"
297
+ }
298
+ ]
299
+ },
300
+ facts: {
301
+ type: "array",
302
+ items: {
303
+ $ref: "#/components/schemas/ReadonlyidstringprocessIdstringresourceIdstringkindFlowFactKindamountstringunitstringwindowReadonlystartSecnumberendSecnumberevidenceRefsreadonlystring"
304
+ }
305
+ },
306
+ hypotheses: {
307
+ type: "array",
308
+ items: {
309
+ $ref: "#/components/schemas/ReadonlyidstringprocessIdstringnullstatusFlowCauseStatusclaimFlowCauseClaimevidenceRefsreadonlystringreasonstring"
310
+ }
311
+ },
312
+ littlesLaw: {
313
+ $ref: "#/components/schemas/Readonlystatusconsistentinconsistentinsufficient-datanot-applicableassumptionstring"
314
+ },
315
+ stallMapped: {
316
+ "const": false
317
+ },
318
+ externalProvider: {
319
+ "const": false
320
+ }
321
+ },
322
+ required: [
323
+ "schemaVersion",
324
+ "contract",
325
+ "algorithmVersion",
326
+ "capability",
327
+ "status",
328
+ "facts",
329
+ "hypotheses",
330
+ "littlesLaw",
331
+ "stallMapped",
332
+ "externalProvider"
333
+ ],
334
+ additionalProperties: false
335
+ },
336
+ ReadonlyidstringprocessIdstringresourceIdstringkindFlowFactKindamountstringunitstringwindowReadonlystartSecnumberendSecnumberevidenceRefsreadonlystring: {
337
+ type: "object",
338
+ properties: {
339
+ id: {
340
+ type: "string"
341
+ },
342
+ processId: {
343
+ type: "string"
344
+ },
345
+ resourceId: {
346
+ type: "string",
347
+ description: "The resource the fact describes, so one process's resources stay apart."
348
+ },
349
+ kind: {
350
+ $ref: "#/components/schemas/FlowFactKind"
351
+ },
352
+ amount: {
353
+ type: "string"
354
+ },
355
+ unit: {
356
+ type: "string"
357
+ },
358
+ window: {
359
+ $ref: "#/components/schemas/ReadonlystartSecnumberendSecnumber"
360
+ },
361
+ evidenceRefs: {
362
+ type: "array",
363
+ items: {
364
+ type: "string"
365
+ }
366
+ }
367
+ },
368
+ required: [
369
+ "id",
370
+ "processId",
371
+ "resourceId",
372
+ "kind",
373
+ "amount",
374
+ "unit",
375
+ "window",
376
+ "evidenceRefs"
377
+ ],
378
+ additionalProperties: false
379
+ },
380
+ FlowFactKind: {
381
+ oneOf: [
382
+ {
383
+ "const": "blocked-time"
384
+ },
385
+ {
386
+ "const": "capacity"
387
+ },
388
+ {
389
+ "const": "conservation"
390
+ },
391
+ {
392
+ "const": "final-throughput"
393
+ },
394
+ {
395
+ "const": "inflow"
396
+ },
397
+ {
398
+ "const": "queue"
399
+ },
400
+ {
401
+ "const": "saturation-time"
402
+ },
403
+ {
404
+ "const": "starved-time"
405
+ },
406
+ {
407
+ "const": "throughput"
408
+ },
409
+ {
410
+ "const": "unretained"
411
+ }
412
+ ]
413
+ },
414
+ ReadonlystartSecnumberendSecnumber: {
415
+ type: "object",
416
+ properties: {
417
+ startSec: {
418
+ type: "number"
419
+ },
420
+ endSec: {
421
+ type: "number"
422
+ }
423
+ },
424
+ required: [
425
+ "startSec",
426
+ "endSec"
427
+ ],
428
+ additionalProperties: false
429
+ },
430
+ ReadonlyidstringprocessIdstringnullstatusFlowCauseStatusclaimFlowCauseClaimevidenceRefsreadonlystringreasonstring: {
431
+ type: "object",
432
+ properties: {
433
+ id: {
434
+ type: "string"
435
+ },
436
+ processId: {
437
+ oneOf: [
438
+ {
439
+ type: "null"
440
+ },
441
+ {
442
+ type: "string"
443
+ }
444
+ ]
445
+ },
446
+ status: {
447
+ $ref: "#/components/schemas/FlowCauseStatus"
448
+ },
449
+ claim: {
450
+ $ref: "#/components/schemas/FlowCauseClaim"
451
+ },
452
+ evidenceRefs: {
453
+ type: "array",
454
+ items: {
455
+ type: "string"
456
+ }
457
+ },
458
+ reason: {
459
+ type: "string"
460
+ }
461
+ },
462
+ required: [
463
+ "id",
464
+ "processId",
465
+ "status",
466
+ "claim",
467
+ "evidenceRefs",
468
+ "reason"
469
+ ],
470
+ additionalProperties: false
471
+ },
472
+ FlowCauseStatus: {
473
+ oneOf: [
474
+ {
475
+ "const": "confirmed"
476
+ },
477
+ {
478
+ "const": "insufficient-data"
479
+ },
480
+ {
481
+ "const": "suspected"
482
+ },
483
+ {
484
+ "const": "unsupported"
485
+ }
486
+ ]
487
+ },
488
+ FlowCauseClaim: {
489
+ oneOf: [
490
+ {
491
+ "const": "capacity-constraint"
492
+ },
493
+ {
494
+ "const": "demand-shortage"
495
+ },
496
+ {
497
+ "const": "material-shortage"
498
+ },
499
+ {
500
+ "const": "none"
501
+ }
502
+ ]
503
+ },
504
+ "Readonlystatusconsistentinconsistentinsufficient-datanot-applicableassumptionstring": {
505
+ type: "object",
506
+ properties: {
507
+ status: {
508
+ oneOf: [
509
+ {
510
+ "const": "consistent"
511
+ },
512
+ {
513
+ "const": "inconsistent"
514
+ },
515
+ {
516
+ "const": "insufficient-data"
517
+ },
518
+ {
519
+ "const": "not-applicable"
520
+ }
521
+ ]
522
+ },
523
+ assumption: {
524
+ type: "string"
525
+ }
526
+ },
527
+ required: [
528
+ "status",
529
+ "assumption"
530
+ ],
531
+ additionalProperties: false
532
+ }
533
+ }
534
+ },
535
+ schema: {
536
+ type: "object",
537
+ properties: {
538
+ schemaVersion: {
539
+ "const": 1
540
+ },
541
+ contract: {
542
+ "const": "idlekit.flow.v1"
543
+ },
544
+ algorithmVersion: {
545
+ "const": "flow-observation-1"
546
+ },
547
+ capability: {
548
+ oneOf: [
549
+ {
550
+ "const": "statically-known"
551
+ },
552
+ {
553
+ "const": "unknown"
554
+ },
555
+ {
556
+ "const": "unsupported"
557
+ }
558
+ ]
559
+ },
560
+ status: {
561
+ oneOf: [
562
+ {
563
+ "const": "insufficient-data"
564
+ },
565
+ {
566
+ "const": "ok"
567
+ },
568
+ {
569
+ "const": "unsupported"
570
+ }
571
+ ]
572
+ },
573
+ facts: {
574
+ type: "array",
575
+ items: {
576
+ $ref: "#/components/schemas/ReadonlyidstringprocessIdstringresourceIdstringkindFlowFactKindamountstringunitstringwindowReadonlystartSecnumberendSecnumberevidenceRefsreadonlystring"
577
+ }
578
+ },
579
+ hypotheses: {
580
+ type: "array",
581
+ items: {
582
+ $ref: "#/components/schemas/ReadonlyidstringprocessIdstringnullstatusFlowCauseStatusclaimFlowCauseClaimevidenceRefsreadonlystringreasonstring"
583
+ }
584
+ },
585
+ littlesLaw: {
586
+ $ref: "#/components/schemas/Readonlystatusconsistentinconsistentinsufficient-datanot-applicableassumptionstring"
587
+ },
588
+ stallMapped: {
589
+ "const": false
590
+ },
591
+ externalProvider: {
592
+ "const": false
593
+ }
594
+ },
595
+ required: [
596
+ "schemaVersion",
597
+ "contract",
598
+ "algorithmVersion",
599
+ "capability",
600
+ "status",
601
+ "facts",
602
+ "hypotheses",
603
+ "littlesLaw",
604
+ "stallMapped",
605
+ "externalProvider"
606
+ ],
607
+ additionalProperties: false
608
+ },
609
+ version: "3.1"
610
+ };
611
+ }
612
+ let flowJsonSchemaUnit;
613
+ /**
614
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-flow-adapter The structural schema is OpenAPI 3.1 from typia.
615
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-flow-adapter #3c616c8 Re-read the section: schema version is 3.1 and the contract id is idlekit.flow.v1.
616
+ */
617
+ export function flowJsonSchema() {
618
+ flowJsonSchemaUnit ??= buildFlowJsonSchema();
619
+ return flowJsonSchemaUnit;
620
+ }
621
+ const validateObservation = (input) => (validateObservationValidator ??= (() => {
622
+ const _ip0 = input => "boolean" === typeof input["steady"];
623
+ const _ip1 = input => "string" === typeof input["processId"];
624
+ const _ve0 = "Readonly<{ schemaVersion: 1; contract: \"idlekit.flow.observation.v1\"; capability: \"statically-known\" | \"unknown\" | \"unsupported\"; steady: boolean; samples: readonly Readonly<{ processId: string; resourceId: string; ... 4 more ...; endSec: number; }>[]; edges: readonly Readonly<...>[]; causal: Readonly<...> | null; l...";
625
+ const _vp0 = (input, _path, _exceptionable = true) => "boolean" === typeof input["steady"] || _report(_exceptionable, {
626
+ path: _path + ".steady",
627
+ expected: "boolean",
628
+ value: input["steady"]
629
+ });
630
+ const _ve1 = "Readonly<{ processId: string; resourceId: string; kind: FlowSampleKind; amount: string; unit: string; startSec: number; endSec: number; }>";
631
+ const _ve2 = "ReadonlyArray<Readonly<{ processId: string; resourceId: string; kind: FlowSampleKind; amount: string; unit: string; startSec: number; endSec: number; }>>";
632
+ const _ve3 = "Readonly<{ fromProcessId: string; toProcessId: string; fromResourceId: string; toResourceId: string; numerator: string; denominator: string; loss: string; }>";
633
+ const _ve4 = "ReadonlyArray<Readonly<{ fromProcessId: string; toProcessId: string; fromResourceId: string; toResourceId: string; numerator: string; denominator: string; loss: string; }>>";
634
+ const _vp1 = (input, _path, _exceptionable = true) => "string" === typeof input["processId"] || _report(_exceptionable, {
635
+ path: _path + ".processId",
636
+ expected: "string",
637
+ value: input["processId"]
638
+ });
639
+ const _io0 = input => 1 === input.schemaVersion && "idlekit.flow.observation.v1" === input.contract && ("statically-known" === input.capability || "unknown" === input.capability || "unsupported" === input.capability) && _ip0(input) && (Array.isArray(input.samples) && input.samples.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && (Array.isArray(input.edges) && input.edges.every(elem => "object" === typeof elem && null !== elem && _io2(elem))) && (null === input.causal || "object" === typeof input.causal && null !== input.causal && _io3(input.causal)) && (null === input.littles || "object" === typeof input.littles && null !== input.littles && _io4(input.littles));
640
+ const _io1 = input => _ip1(input) && "string" === typeof input.resourceId && ("blocked-time" === input.kind || "capacity" === input.kind || "inflow" === input.kind || "queue" === input.kind || "starved-time" === input.kind || "throughput" === input.kind || "unretained" === input.kind) && "string" === typeof input.amount && "string" === typeof input.unit && "number" === typeof input.startSec && "number" === typeof input.endSec;
641
+ const _io2 = input => "string" === typeof input.fromProcessId && "string" === typeof input.toProcessId && "string" === typeof input.fromResourceId && "string" === typeof input.toResourceId && "string" === typeof input.numerator && "string" === typeof input.denominator && "string" === typeof input.loss;
642
+ const _io3 = input => ("experiment" === input.kind || "model" === input.kind) && _ip1(input);
643
+ const _io4 = input => "string" === typeof input.inventory && "string" === typeof input.arrivalPerSec && "string" === typeof input.waitSec && _ip0(input) && "boolean" === typeof input.workFlowDefined;
644
+ const _vo0 = (input, _path, _exceptionable = true) => [1 === input.schemaVersion || _report(_exceptionable, {
645
+ path: _path + ".schemaVersion",
646
+ expected: "1",
647
+ value: input.schemaVersion
648
+ }), "idlekit.flow.observation.v1" === input.contract || _report(_exceptionable, {
649
+ path: _path + ".contract",
650
+ expected: "\"idlekit.flow.observation.v1\"",
651
+ value: input.contract
652
+ }), "statically-known" === input.capability || "unknown" === input.capability || "unsupported" === input.capability || _report(_exceptionable, {
653
+ path: _path + ".capability",
654
+ expected: "(\"statically-known\" | \"unknown\" | \"unsupported\")",
655
+ value: input.capability
656
+ }), _vp0(input, _path, true && _exceptionable), (Array.isArray(input.samples) || _report(_exceptionable, {
657
+ path: _path + ".samples",
658
+ expected: _ve2,
659
+ value: input.samples
660
+ })) && input.samples.map((elem, _index3) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
661
+ path: _path + ".samples[" + _index3 + "]",
662
+ expected: _ve1,
663
+ value: elem
664
+ })) && _vo1(elem, _path + ".samples[" + _index3 + "]", true && _exceptionable) || _report(_exceptionable, {
665
+ path: _path + ".samples[" + _index3 + "]",
666
+ expected: _ve1,
667
+ value: elem
668
+ })).every(flag => flag) || _report(_exceptionable, {
669
+ path: _path + ".samples",
670
+ expected: _ve2,
671
+ value: input.samples
672
+ }), (Array.isArray(input.edges) || _report(_exceptionable, {
673
+ path: _path + ".edges",
674
+ expected: _ve4,
675
+ value: input.edges
676
+ })) && input.edges.map((elem, _index4) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
677
+ path: _path + ".edges[" + _index4 + "]",
678
+ expected: _ve3,
679
+ value: elem
680
+ })) && _vo2(elem, _path + ".edges[" + _index4 + "]", true && _exceptionable) || _report(_exceptionable, {
681
+ path: _path + ".edges[" + _index4 + "]",
682
+ expected: _ve3,
683
+ value: elem
684
+ })).every(flag => flag) || _report(_exceptionable, {
685
+ path: _path + ".edges",
686
+ expected: _ve4,
687
+ value: input.edges
688
+ }), null === input.causal || ("object" === typeof input.causal && null !== input.causal || _report(_exceptionable, {
689
+ path: _path + ".causal",
690
+ expected: "(Readonly<{ kind: \"experiment\" | \"model\"; processId: string; }> | null)",
691
+ value: input.causal
692
+ })) && _vo3(input.causal, _path + ".causal", true && _exceptionable) || _report(_exceptionable, {
693
+ path: _path + ".causal",
694
+ expected: "(Readonly<{ kind: \"experiment\" | \"model\"; processId: string; }> | null)",
695
+ value: input.causal
696
+ }), null === input.littles || ("object" === typeof input.littles && null !== input.littles || _report(_exceptionable, {
697
+ path: _path + ".littles",
698
+ expected: "(Readonly<{ inventory: string; arrivalPerSec: string; waitSec: string; steady: boolean; workFlowDefined: boolean; }> | null)",
699
+ value: input.littles
700
+ })) && _vo4(input.littles, _path + ".littles", true && _exceptionable) || _report(_exceptionable, {
701
+ path: _path + ".littles",
702
+ expected: "(Readonly<{ inventory: string; arrivalPerSec: string; waitSec: string; steady: boolean; workFlowDefined: boolean; }> | null)",
703
+ value: input.littles
704
+ })].every(flag => flag);
705
+ const _vo1 = (input, _path, _exceptionable = true) => [_vp1(input, _path, true && _exceptionable), "string" === typeof input.resourceId || _report(_exceptionable, {
706
+ path: _path + ".resourceId",
707
+ expected: "string",
708
+ value: input.resourceId
709
+ }), "blocked-time" === input.kind || "capacity" === input.kind || "inflow" === input.kind || "queue" === input.kind || "starved-time" === input.kind || "throughput" === input.kind || "unretained" === input.kind || _report(_exceptionable, {
710
+ path: _path + ".kind",
711
+ expected: "(\"blocked-time\" | \"capacity\" | \"inflow\" | \"queue\" | \"starved-time\" | \"throughput\" | \"unretained\")",
712
+ value: input.kind
713
+ }), "string" === typeof input.amount || _report(_exceptionable, {
714
+ path: _path + ".amount",
715
+ expected: "string",
716
+ value: input.amount
717
+ }), "string" === typeof input.unit || _report(_exceptionable, {
718
+ path: _path + ".unit",
719
+ expected: "string",
720
+ value: input.unit
721
+ }), "number" === typeof input.startSec || _report(_exceptionable, {
722
+ path: _path + ".startSec",
723
+ expected: "number",
724
+ value: input.startSec
725
+ }), "number" === typeof input.endSec || _report(_exceptionable, {
726
+ path: _path + ".endSec",
727
+ expected: "number",
728
+ value: input.endSec
729
+ })].every(flag => flag);
730
+ const _vo2 = (input, _path, _exceptionable = true) => ["string" === typeof input.fromProcessId || _report(_exceptionable, {
731
+ path: _path + ".fromProcessId",
732
+ expected: "string",
733
+ value: input.fromProcessId
734
+ }), "string" === typeof input.toProcessId || _report(_exceptionable, {
735
+ path: _path + ".toProcessId",
736
+ expected: "string",
737
+ value: input.toProcessId
738
+ }), "string" === typeof input.fromResourceId || _report(_exceptionable, {
739
+ path: _path + ".fromResourceId",
740
+ expected: "string",
741
+ value: input.fromResourceId
742
+ }), "string" === typeof input.toResourceId || _report(_exceptionable, {
743
+ path: _path + ".toResourceId",
744
+ expected: "string",
745
+ value: input.toResourceId
746
+ }), "string" === typeof input.numerator || _report(_exceptionable, {
747
+ path: _path + ".numerator",
748
+ expected: "string",
749
+ value: input.numerator
750
+ }), "string" === typeof input.denominator || _report(_exceptionable, {
751
+ path: _path + ".denominator",
752
+ expected: "string",
753
+ value: input.denominator
754
+ }), "string" === typeof input.loss || _report(_exceptionable, {
755
+ path: _path + ".loss",
756
+ expected: "string",
757
+ value: input.loss
758
+ })].every(flag => flag);
759
+ const _vo3 = (input, _path, _exceptionable = true) => ["experiment" === input.kind || "model" === input.kind || _report(_exceptionable, {
760
+ path: _path + ".kind",
761
+ expected: "(\"experiment\" | \"model\")",
762
+ value: input.kind
763
+ }), _vp1(input, _path, true && _exceptionable)].every(flag => flag);
764
+ const _vo4 = (input, _path, _exceptionable = true) => ["string" === typeof input.inventory || _report(_exceptionable, {
765
+ path: _path + ".inventory",
766
+ expected: "string",
767
+ value: input.inventory
768
+ }), "string" === typeof input.arrivalPerSec || _report(_exceptionable, {
769
+ path: _path + ".arrivalPerSec",
770
+ expected: "string",
771
+ value: input.arrivalPerSec
772
+ }), "string" === typeof input.waitSec || _report(_exceptionable, {
773
+ path: _path + ".waitSec",
774
+ expected: "string",
775
+ value: input.waitSec
776
+ }), _vp0(input, _path, true && _exceptionable), "boolean" === typeof input.workFlowDefined || _report(_exceptionable, {
777
+ path: _path + ".workFlowDefined",
778
+ expected: "boolean",
779
+ value: input.workFlowDefined
780
+ })].every(flag => flag);
781
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
782
+ let errors;
783
+ let _report;
784
+ return _createStandardSchema_1._createStandardSchema(input => {
785
+ if (false === __is(input)) {
786
+ errors = [];
787
+ _report = _validateReport_1._validateReport(errors);
788
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
789
+ path: _path + "",
790
+ expected: _ve0,
791
+ value: input
792
+ })) && _vo0(input, _path + "", true) || _report(true, {
793
+ path: _path + "",
794
+ expected: _ve0,
795
+ value: input
796
+ }))(input, "$input", true);
797
+ const success = 0 === errors.length;
798
+ return success ? {
799
+ success,
800
+ data: input
801
+ } : {
802
+ success,
803
+ errors,
804
+ data: input
805
+ };
806
+ }
807
+ return {
808
+ success: true,
809
+ data: input
810
+ };
811
+ });
812
+ })())(input);
813
+ /**
814
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-flow-adapter A flow observation is validated as data.
815
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-flow-adapter #3c616c8 Re-read the section: the observation contract is idlekit.flow.observation.v1, and nonzero decimals that become Number zero are rejected while true zero spellings and positive representable subnormals are accepted; invalid finite non-negative decimal spellings, duplicate sample keys or edges, zero denominators, losses above 1, and losses that round to 1 without exactly spelling 1 are rejected while parsing.
816
+ */
817
+ export function parseFlowObservation(input) {
818
+ const validated = validateObservation(input);
819
+ if (!validated.success) {
820
+ return { ok: false, issues: validated.errors.map((error) => `${error.path} ${error.expected}`) };
821
+ }
822
+ const issues = decimalIssues(validated.data);
823
+ return issues.length === 0 ? { ok: true, observation: validated.data } : { ok: false, issues };
824
+ }
825
+ /** The decimal wire spelling engines print: optional sign, fraction, and exponent. */
826
+ const DECIMAL_WIRE = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
827
+ /** A finite, non-negative amount representable without rounding a nonzero wire value to zero. */
828
+ function parseDecimal(text) {
829
+ if (!DECIMAL_WIRE.test(text))
830
+ return null;
831
+ const value = Number(text);
832
+ if (!Number.isFinite(value) || value < 0)
833
+ return null;
834
+ if (value === 0 && /[1-9]/.test(text.split(/[eE]/, 1)[0]))
835
+ return null;
836
+ return value === 0 ? 0 : value;
837
+ }
838
+ /** Exact total loss is a wire property; a near-one decimal can round to 1 as a number. */
839
+ function isExactOne(text) {
840
+ const [mantissa, exponent = "0"] = text.toLowerCase().split("e");
841
+ const base = mantissa;
842
+ const dot = base.indexOf(".");
843
+ const fractionDigits = dot < 0 ? 0 : base.length - dot - 1;
844
+ const digits = base.replace(/^\+/, "").replace(".", "").replace(/^0+/, "");
845
+ return /^10*$/.test(digits) && BigInt(exponent) - BigInt(fractionDigits) + BigInt(digits.length - 1) === 0n;
846
+ }
847
+ /** An amount the diagnosis could not read is rejected here, not dropped later. */
848
+ function decimalIssues(observation) {
849
+ const issues = [];
850
+ const check = (path, text) => {
851
+ if (parseDecimal(text) === null)
852
+ issues.push(`${path} finite non-negative decimal representable without underflow to Number zero`);
853
+ };
854
+ // One process, resource, kind, and window names one sample. A second one would make the reading order-dependent.
855
+ const keys = new Map();
856
+ observation.samples.forEach((sample, index) => {
857
+ check(`$input.samples[${index}].amount`, sample.amount);
858
+ if (!(sample.endSec >= sample.startSec))
859
+ issues.push(`$input.samples[${index}].endSec >= startSec`);
860
+ if ((sample.kind === "starved-time" || sample.kind === "blocked-time") && sample.unit !== "s") {
861
+ issues.push(`$input.samples[${index}].unit "s" for a wait`);
862
+ }
863
+ const key = JSON.stringify([sample.processId, sample.resourceId, sample.kind, sample.startSec, sample.endSec]);
864
+ const first = keys.get(key);
865
+ if (first !== undefined)
866
+ issues.push(`$input.samples[${index}] duplicates samples[${first}]`);
867
+ else
868
+ keys.set(key, index);
869
+ });
870
+ // One source and destination pair names one edge. A copy would count the same flow twice.
871
+ const edgeKeys = new Map();
872
+ observation.edges.forEach((edge, index) => {
873
+ const key = JSON.stringify([edge.fromProcessId, edge.fromResourceId, edge.toProcessId, edge.toResourceId]);
874
+ const first = edgeKeys.get(key);
875
+ if (first !== undefined)
876
+ issues.push(`$input.edges[${index}] duplicates edges[${first}]`);
877
+ else
878
+ edgeKeys.set(key, index);
879
+ check(`$input.edges[${index}].numerator`, edge.numerator);
880
+ check(`$input.edges[${index}].denominator`, edge.denominator);
881
+ check(`$input.edges[${index}].loss`, edge.loss);
882
+ if (parseDecimal(edge.denominator) === 0)
883
+ issues.push(`$input.edges[${index}].denominator > 0`);
884
+ const loss = parseDecimal(edge.loss);
885
+ if (loss !== null && loss > 1)
886
+ issues.push(`$input.edges[${index}].loss <= 1`);
887
+ if (loss === 1 && !isExactOne(edge.loss))
888
+ issues.push(`$input.edges[${index}].loss must not round a remaining fraction to total loss`);
889
+ });
890
+ if (observation.littles) {
891
+ check("$input.littles.inventory", observation.littles.inventory);
892
+ check("$input.littles.arrivalPerSec", observation.littles.arrivalPerSec);
893
+ check("$input.littles.waitSec", observation.littles.waitSec);
894
+ }
895
+ return issues;
896
+ }
897
+ /**
898
+ * Rounds to nine fraction digits. A value too large to scale has no fraction digits to round, and a nonzero
899
+ * value that would round to zero keeps its own spelling.
900
+ */
901
+ function formatDecimal(value) {
902
+ const scaled = value * 1_000_000_000;
903
+ if (!Number.isFinite(scaled) || Math.abs(scaled) >= Number.MAX_SAFE_INTEGER)
904
+ return String(value);
905
+ const rounded = Math.round(scaled) / 1_000_000_000;
906
+ return rounded === 0 && value !== 0 ? String(value) : String(rounded);
907
+ }
908
+ /**
909
+ * Relative closeness. Zero is close only to zero, so a positive flow of any size is not equal to an empty stock.
910
+ * A non-finite operand, such as an overflowed product, is never close.
911
+ */
912
+ function nearly(left, right) {
913
+ if (!Number.isFinite(left) || !Number.isFinite(right))
914
+ return false;
915
+ if (left === 0 || right === 0)
916
+ return left === right;
917
+ const scale = Math.max(Math.abs(left), Math.abs(right));
918
+ return Math.abs(left - right) <= 1e-6 * scale;
919
+ }
920
+ function hypothesis(processId, status, claim, evidenceRefs, reason) {
921
+ return { id: `cause:${processId ?? "none"}`, processId, status, claim, evidenceRefs, reason };
922
+ }
923
+ function blank(capability, status, cause, littlesStatus, assumption) {
924
+ return {
925
+ schemaVersion: 1,
926
+ contract: "idlekit.flow.v1",
927
+ algorithmVersion: FLOW_ALGORITHM_VERSION,
928
+ capability,
929
+ status,
930
+ facts: [],
931
+ hypotheses: [cause],
932
+ littlesLaw: { status: littlesStatus, assumption },
933
+ stallMapped: false,
934
+ externalProvider: false,
935
+ };
936
+ }
937
+ function littlesOf(littles, capability, observationSteady) {
938
+ if (capability !== "statically-known" || !littles) {
939
+ return { status: "not-applicable", assumption: "Little's law needs a steady work-flow window" };
940
+ }
941
+ // A ramp-up marker on either the observation or the Little's law window keeps the law off.
942
+ if (!observationSteady || !littles.steady || !littles.workFlowDefined) {
943
+ return { status: "not-applicable", assumption: "Little's law is not applied to a ramp-up or an undefined work flow" };
944
+ }
945
+ const inventory = parseDecimal(littles.inventory);
946
+ const arrival = parseDecimal(littles.arrivalPerSec);
947
+ const wait = parseDecimal(littles.waitSec);
948
+ if (inventory === null || arrival === null || wait === null) {
949
+ return { status: "insufficient-data", assumption: "Little's law inputs must be finite decimals" };
950
+ }
951
+ const expected = arrival * wait;
952
+ if (!Number.isFinite(expected)) {
953
+ return { status: "insufficient-data", assumption: "Little's law inputs overflow a finite product" };
954
+ }
955
+ if (expected === 0 && arrival !== 0 && wait !== 0) {
956
+ return { status: "insufficient-data", assumption: "Little's law inputs underflow a finite product" };
957
+ }
958
+ return {
959
+ status: nearly(inventory, expected) ? "consistent" : "inconsistent",
960
+ assumption: "steady window and a defined work flow",
961
+ };
962
+ }
963
+ function rated(samples) {
964
+ const found = [];
965
+ samples.forEach((sample, index) => {
966
+ const value = parseDecimal(sample.amount);
967
+ // A reversed window has no duration, so its sample is not evidence.
968
+ if (value !== null && sample.endSec >= sample.startSec)
969
+ found.push({ sample, index, value });
970
+ });
971
+ return found;
972
+ }
973
+ /** The sample of one process, resource, and kind inside exactly this evidence window. */
974
+ function sampleAt(rows, processId, resourceId, kind, window) {
975
+ return rows.find((row) => row.sample.processId === processId &&
976
+ row.sample.resourceId === resourceId &&
977
+ row.sample.kind === kind &&
978
+ row.sample.startSec === window.startSec &&
979
+ row.sample.endSec === window.endSec);
980
+ }
981
+ /** The sample with the latest window: the greatest end, then the greatest start. Order in the input does not matter. */
982
+ function latest(candidates) {
983
+ let best;
984
+ for (const row of candidates) {
985
+ if (!best ||
986
+ row.sample.endSec > best.sample.endSec ||
987
+ (row.sample.endSec === best.sample.endSec && row.sample.startSec > best.sample.startSec)) {
988
+ best = row;
989
+ }
990
+ }
991
+ return best;
992
+ }
993
+ /** True when `candidate` is the defined bind over `held`: a later window, then a smaller resource id. */
994
+ function preferredBind(candidate, held) {
995
+ if (candidate.sample.endSec !== held.sample.endSec)
996
+ return candidate.sample.endSec > held.sample.endSec;
997
+ if (candidate.sample.startSec !== held.sample.startSec)
998
+ return candidate.sample.startSec > held.sample.startSec;
999
+ return candidate.sample.resourceId < held.sample.resourceId;
1000
+ }
1001
+ function convert(amount, edge) {
1002
+ const numerator = parseDecimal(edge.numerator);
1003
+ const denominator = parseDecimal(edge.denominator);
1004
+ const loss = parseDecimal(edge.loss);
1005
+ if (numerator === null || denominator === null || loss === null || denominator === 0 || loss > 1)
1006
+ return null;
1007
+ if (loss === 1 && !isExactOne(edge.loss))
1008
+ return null;
1009
+ const converted = (amount * numerator) / denominator * (1 - loss);
1010
+ if (converted === 0 && amount !== 0 && numerator !== 0 && loss !== 1)
1011
+ return null;
1012
+ return Number.isFinite(converted) ? converted : null;
1013
+ }
1014
+ /**
1015
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-pipeline Diagnosis reads throughput, capacity, and the evidence window.
1016
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-pipeline #597bca1 Re-read the section: the middle stage binds and doubling inflow leaves throughput at 20; capacity and upstream samples match the edge resource and the throughput window, and every saturated process is a candidate.
1017
+ */
1018
+ export function diagnoseFlow(observation) {
1019
+ const littlesLaw = littlesOf(observation.littles, observation.capability, observation.steady);
1020
+ if (observation.capability === "unsupported") {
1021
+ return blank(observation.capability, "unsupported", hypothesis(null, "unsupported", "none", [], "flow capability is unsupported"), littlesLaw.status, littlesLaw.assumption);
1022
+ }
1023
+ if (observation.capability === "unknown") {
1024
+ return blank(observation.capability, "insufficient-data", hypothesis(null, "insufficient-data", "none", [], "flow capability is unknown"), littlesLaw.status, littlesLaw.assumption);
1025
+ }
1026
+ const rows = rated(observation.samples);
1027
+ const facts = rows.map((row) => ({
1028
+ id: `fact:${row.index}:${row.sample.kind}`,
1029
+ processId: row.sample.processId,
1030
+ resourceId: row.sample.resourceId,
1031
+ kind: row.sample.kind,
1032
+ amount: row.sample.amount,
1033
+ unit: row.sample.unit,
1034
+ window: { startSec: row.sample.startSec, endSec: row.sample.endSec },
1035
+ evidenceRefs: [`sample:${row.index}`],
1036
+ }));
1037
+ const sinks = new Set();
1038
+ const sources = new Set();
1039
+ for (const edge of observation.edges) {
1040
+ sources.add(edge.fromProcessId);
1041
+ sinks.add(edge.toProcessId);
1042
+ }
1043
+ for (const source of sources)
1044
+ sinks.delete(source);
1045
+ // Each terminal process reports the throughput of every resource its incoming edges deliver. A graph with
1046
+ // edges but no terminal process, such as a cycle, has no final throughput. Only an edgeless observation falls back.
1047
+ // A graph-derived final cites the incoming edges that deliver its resource, the topology that made it final.
1048
+ const finals = [];
1049
+ for (const sinkId of sinks) {
1050
+ const delivered = new Set(observation.edges.filter((edge) => edge.toProcessId === sinkId).map((edge) => edge.toResourceId));
1051
+ for (const resourceId of delivered) {
1052
+ const found = latest(rows.filter((row) => row.sample.processId === sinkId && row.sample.resourceId === resourceId && row.sample.kind === "throughput"));
1053
+ const edgeRefs = [...observation.edges.entries()]
1054
+ .filter(([, edge]) => edge.toProcessId === sinkId && edge.toResourceId === resourceId)
1055
+ .map(([edgeIndex]) => `edge:${edgeIndex}`);
1056
+ if (found)
1057
+ finals.push({ row: found, edgeRefs });
1058
+ }
1059
+ }
1060
+ if (observation.edges.length === 0) {
1061
+ // Without edges no series is the terminal one, so every throughput series reports its latest window.
1062
+ const series = new Map();
1063
+ for (const row of rows) {
1064
+ if (row.sample.kind !== "throughput")
1065
+ continue;
1066
+ const key = JSON.stringify([row.sample.processId, row.sample.resourceId]);
1067
+ series.set(key, [...(series.get(key) ?? []), row]);
1068
+ }
1069
+ for (const members of series.values()) {
1070
+ const chosen = latest(members);
1071
+ if (chosen)
1072
+ finals.push({ row: chosen, edgeRefs: [] });
1073
+ }
1074
+ }
1075
+ for (const { row: final, edgeRefs } of finals) {
1076
+ facts.push({
1077
+ // The pair is encoded structurally, so two different pairs never share an id and no string makes it throw.
1078
+ id: `fact:final-throughput:${JSON.stringify([final.sample.processId, final.sample.resourceId])}`,
1079
+ processId: final.sample.processId,
1080
+ resourceId: final.sample.resourceId,
1081
+ kind: "final-throughput",
1082
+ amount: final.sample.amount,
1083
+ unit: final.sample.unit,
1084
+ window: { startSec: final.sample.startSec, endSec: final.sample.endSec },
1085
+ evidenceRefs: [`sample:${final.index}`, ...edgeRefs],
1086
+ });
1087
+ }
1088
+ // Every saturated process is a candidate, so a later causally named bind is not missed. Each process and
1089
+ // resource series is judged on its latest saturated window, chosen before its evidence is read, so an older
1090
+ // window never stands in for a newer unproven one. A process with binds on several resources keeps one:
1091
+ // the latest window, then the smaller resource id.
1092
+ const saturated = new Map();
1093
+ for (const row of rows) {
1094
+ if (row.sample.kind !== "throughput")
1095
+ continue;
1096
+ const window = { startSec: row.sample.startSec, endSec: row.sample.endSec };
1097
+ const capacity = sampleAt(rows, row.sample.processId, row.sample.resourceId, "capacity", window);
1098
+ if (!capacity || capacity.sample.unit !== row.sample.unit || !nearly(row.value, capacity.value))
1099
+ continue;
1100
+ const key = JSON.stringify([row.sample.processId, row.sample.resourceId]);
1101
+ const held = saturated.get(key);
1102
+ if (!held || preferredBind(row, held.row))
1103
+ saturated.set(key, { row, capacity });
1104
+ }
1105
+ const byProcess = new Map();
1106
+ for (const { row, capacity } of saturated.values()) {
1107
+ const { processId, resourceId } = row.sample;
1108
+ const window = { startSec: row.sample.startSec, endSec: row.sample.endSec };
1109
+ // Every edge into this process and resource offers work, each read in the same window.
1110
+ const upstream = observation.edges.filter((edge) => edge.toProcessId === processId && edge.toResourceId === resourceId);
1111
+ const upstreamRefs = [];
1112
+ let offered = upstream.length > 0 ? 0 : null;
1113
+ for (const edge of upstream) {
1114
+ // A source may report its offer as throughput or, failing that, as inflow, as conservation reads it.
1115
+ const source = sampleAt(rows, edge.fromProcessId, edge.fromResourceId, "throughput", window) ??
1116
+ sampleAt(rows, edge.fromProcessId, edge.fromResourceId, "inflow", window);
1117
+ const converted = source ? convert(source.value, edge) : null;
1118
+ // An edge that keeps the resource keeps its rate unit, so its source must be in this process's unit.
1119
+ const unitMismatch = source !== undefined && edge.fromResourceId === edge.toResourceId && source.sample.unit !== row.sample.unit;
1120
+ if (!source || converted === null || offered === null || unitMismatch) {
1121
+ offered = null;
1122
+ break;
1123
+ }
1124
+ offered += converted;
1125
+ upstreamRefs.push(`sample:${source.index}`, `edge:${observation.edges.indexOf(edge)}`);
1126
+ }
1127
+ if (offered === null || !Number.isFinite(offered) || !(offered > row.value && !nearly(offered, row.value)))
1128
+ continue;
1129
+ // An observed downstream capacity must exceed everything that reaches it in this window: this process's
1130
+ // forwarded amount plus every other incoming edge. An unobserved other feed leaves the slack unproven.
1131
+ const downstream = observation.edges.filter((edge) => edge.fromProcessId === processId && edge.fromResourceId === resourceId);
1132
+ const downstreamRefs = [];
1133
+ const slack = downstream.every((edge) => {
1134
+ const downstreamCapacity = sampleAt(rows, edge.toProcessId, edge.toResourceId, "capacity", window);
1135
+ if (!downstreamCapacity)
1136
+ return true;
1137
+ // The capacity must be in the destination's rate unit: its own throughput unit, or this process's unit
1138
+ // when the edge keeps the resource. Without either, the comparison has no common unit.
1139
+ const destinationRate = sampleAt(rows, edge.toProcessId, edge.toResourceId, "throughput", window);
1140
+ const destinationUnit = destinationRate?.sample.unit ?? (edge.fromResourceId === edge.toResourceId ? row.sample.unit : undefined);
1141
+ if (downstreamCapacity.sample.unit !== destinationUnit)
1142
+ return false;
1143
+ let load = 0;
1144
+ const feedRefs = [];
1145
+ for (const [feedIndex, feed] of observation.edges.entries()) {
1146
+ if (feed.toProcessId !== edge.toProcessId || feed.toResourceId !== edge.toResourceId)
1147
+ continue;
1148
+ feedRefs.push(`edge:${feedIndex}`);
1149
+ if (feed === edge) {
1150
+ // This process's own feed is held to the same unit rule as every other feed.
1151
+ if (feed.fromResourceId === feed.toResourceId && row.sample.unit !== destinationUnit)
1152
+ return false;
1153
+ load += convert(row.value, feed) ?? Number.NaN;
1154
+ continue;
1155
+ }
1156
+ const other = sampleAt(rows, feed.fromProcessId, feed.fromResourceId, "throughput", window) ??
1157
+ sampleAt(rows, feed.fromProcessId, feed.fromResourceId, "inflow", window);
1158
+ if (!other)
1159
+ return false;
1160
+ // A feed that keeps the resource must already be in the destination unit to be added to the load.
1161
+ if (feed.fromResourceId === feed.toResourceId && other.sample.unit !== destinationUnit)
1162
+ return false;
1163
+ load += convert(other.value, feed) ?? Number.NaN;
1164
+ feedRefs.push(`sample:${other.index}`);
1165
+ }
1166
+ if (!Number.isFinite(load) || !(downstreamCapacity.value > load && !nearly(downstreamCapacity.value, load)))
1167
+ return false;
1168
+ // The throughput that named the destination unit is cited with the capacity it checked.
1169
+ downstreamRefs.push(`sample:${downstreamCapacity.index}`, ...(destinationRate ? [`sample:${destinationRate.index}`] : []), ...feedRefs);
1170
+ return true;
1171
+ });
1172
+ if (!slack)
1173
+ continue;
1174
+ const held = byProcess.get(processId);
1175
+ if (!held || preferredBind(row, held.row)) {
1176
+ byProcess.set(processId, {
1177
+ row,
1178
+ capacity,
1179
+ refs: [`sample:${row.index}`, `sample:${capacity.index}`, ...upstreamRefs, ...downstreamRefs],
1180
+ });
1181
+ }
1182
+ }
1183
+ const bindings = [...byProcess.values()];
1184
+ for (const { row, capacity } of bindings) {
1185
+ facts.push({
1186
+ id: `fact:saturation:${row.sample.processId}`,
1187
+ processId: row.sample.processId,
1188
+ resourceId: row.sample.resourceId,
1189
+ kind: "saturation-time",
1190
+ amount: formatDecimal(row.sample.endSec - row.sample.startSec),
1191
+ unit: "s",
1192
+ window: { startSec: row.sample.startSec, endSec: row.sample.endSec },
1193
+ evidenceRefs: [`sample:${row.index}`, `sample:${capacity.index}`],
1194
+ });
1195
+ }
1196
+ // Edges that deliver one destination process and resource are checked together, so fan-in is summed.
1197
+ // Every source window is tried, throughput before inflow, so sample order does not hide a conserving window.
1198
+ const groups = new Map();
1199
+ observation.edges.forEach((edge, edgeIndex) => {
1200
+ const key = JSON.stringify([edge.toProcessId, edge.toResourceId]);
1201
+ groups.set(key, [...(groups.get(key) ?? []), edgeIndex]);
1202
+ });
1203
+ const sourcesOf = (edge) => {
1204
+ const sourced = rows.filter((row) => row.sample.processId === edge.fromProcessId &&
1205
+ row.sample.resourceId === edge.fromResourceId &&
1206
+ (row.sample.kind === "throughput" || row.sample.kind === "inflow"));
1207
+ return [...sourced.filter((row) => row.sample.kind === "throughput"), ...sourced.filter((row) => row.sample.kind === "inflow")];
1208
+ };
1209
+ for (const edgeIndexes of groups.values()) {
1210
+ const grouped = edgeIndexes.map((edgeIndex) => ({ edge: observation.edges[edgeIndex], edgeIndex, sources: [] }));
1211
+ for (const item of grouped)
1212
+ item.sources = sourcesOf(item.edge);
1213
+ const destination = grouped[0]?.edge;
1214
+ if (!destination)
1215
+ continue;
1216
+ const windows = [];
1217
+ for (const item of grouped) {
1218
+ for (const row of item.sources) {
1219
+ if (!windows.some((window) => window.startSec === row.sample.startSec && window.endSec === row.sample.endSec)) {
1220
+ windows.push({ startSec: row.sample.startSec, endSec: row.sample.endSec });
1221
+ }
1222
+ }
1223
+ }
1224
+ // The latest conserving window is the fact, whatever the sample order.
1225
+ windows.sort((left, right) => right.endSec - left.endSec || right.startSec - left.startSec);
1226
+ for (const window of windows) {
1227
+ const inputs = grouped.map((item) => item.sources.find((row) => row.sample.startSec === window.startSec && row.sample.endSec === window.endSec));
1228
+ if (inputs.some((input) => input === undefined))
1229
+ continue;
1230
+ const present = inputs;
1231
+ let theoretical = 0;
1232
+ for (const [k, input] of present.entries()) {
1233
+ const converted = convert(input.value, grouped[k].edge);
1234
+ theoretical = converted === null ? Number.NaN : theoretical + converted;
1235
+ }
1236
+ if (!Number.isFinite(theoretical))
1237
+ continue;
1238
+ const queue = sampleAt(rows, destination.toProcessId, destination.toResourceId, "queue", window);
1239
+ const unretained = sampleAt(rows, destination.toProcessId, destination.toResourceId, "unretained", window);
1240
+ if (!queue || !unretained || queue.sample.unit !== unretained.sample.unit)
1241
+ continue;
1242
+ // When the destination's throughput names its unit in this window, the stock must be in that unit.
1243
+ const destinationRate = sampleAt(rows, destination.toProcessId, destination.toResourceId, "throughput", window);
1244
+ if (destinationRate !== undefined && queue.sample.unit !== destinationRate.sample.unit)
1245
+ continue;
1246
+ if (present.some((input) => input.sample.unit === queue.sample.unit))
1247
+ continue;
1248
+ const held = queue.value + unretained.value;
1249
+ if (!nearly(held, theoretical))
1250
+ continue;
1251
+ facts.push({
1252
+ id: `fact:conservation:${edgeIndexes[0]}`,
1253
+ processId: destination.toProcessId,
1254
+ resourceId: destination.toResourceId,
1255
+ kind: "conservation",
1256
+ amount: formatDecimal(theoretical),
1257
+ unit: queue.sample.unit,
1258
+ window,
1259
+ evidenceRefs: [
1260
+ ...present.map((input) => `sample:${input.index}`),
1261
+ `sample:${queue.index}`,
1262
+ `sample:${unretained.index}`,
1263
+ // The destination throughput that named the stock's unit is cited too.
1264
+ ...(destinationRate ? [`sample:${destinationRate.index}`] : []),
1265
+ ...edgeIndexes.map((edgeIndex) => `edge:${edgeIndex}`),
1266
+ ],
1267
+ });
1268
+ break;
1269
+ }
1270
+ }
1271
+ const hypotheses = [];
1272
+ // The bind a causal model or experiment names is confirmed and comes first. Other binds stay suspected.
1273
+ const causalId = observation.causal?.processId;
1274
+ const rankedBindings = [
1275
+ ...bindings.filter((bound) => bound.row.sample.processId === causalId),
1276
+ ...bindings.filter((bound) => bound.row.sample.processId !== causalId),
1277
+ ];
1278
+ for (const { row, refs } of rankedBindings) {
1279
+ const confirmed = row.sample.processId === causalId;
1280
+ hypotheses.push(hypothesis(row.sample.processId, confirmed ? "confirmed" : "suspected", "capacity-constraint",
1281
+ // A confirmation cites the causal record it rests on, next to the samples.
1282
+ confirmed ? [...refs, "causal"] : refs, confirmed ? "a causal model or experiment names this saturated process" : "the process is saturated, without a causal model or experiment"));
1283
+ }
1284
+ // Starved and blocked time are judged per process. One process's wait or bind does not mask another's.
1285
+ const bound = new Set(bindings.map((item) => item.row.sample.processId));
1286
+ const waits = new Map();
1287
+ for (const row of rows) {
1288
+ if (bound.has(row.sample.processId))
1289
+ continue;
1290
+ if (row.sample.kind !== "starved-time" && row.sample.kind !== "blocked-time")
1291
+ continue;
1292
+ // A wait is a duration in seconds. A sample in another unit is not wait evidence.
1293
+ if (row.sample.unit !== "s")
1294
+ continue;
1295
+ const entry = waits.get(row.sample.processId) ?? { starved: [], blocked: [] };
1296
+ (row.sample.kind === "starved-time" ? entry.starved : entry.blocked).push(row);
1297
+ waits.set(row.sample.processId, entry);
1298
+ }
1299
+ // Each wait kind is read from its latest window, whatever the sample order. Every resource's sample in that
1300
+ // window counts, and a latest window with no positive wait clears an older one.
1301
+ const positiveInLatest = (samples) => {
1302
+ const newest = latest(samples);
1303
+ if (!newest)
1304
+ return [];
1305
+ return samples.filter((row) => row.sample.startSec === newest.sample.startSec && row.sample.endSec === newest.sample.endSec && row.value > 0);
1306
+ };
1307
+ const refsOf = (samples) => samples.map((row) => `sample:${row.index}`);
1308
+ const inLatest = (samples) => {
1309
+ const newest = latest(samples);
1310
+ if (!newest)
1311
+ return [];
1312
+ return samples.filter((row) => row.sample.startSec === newest.sample.startSec && row.sample.endSec === newest.sample.endSec);
1313
+ };
1314
+ for (const [processId, kinds] of waits) {
1315
+ const starved = positiveInLatest(kinds.starved);
1316
+ const blocked = positiveInLatest(kinds.blocked);
1317
+ const olderPositive = [...kinds.starved, ...kinds.blocked].some((row) => row.value > 0);
1318
+ if (starved.length === 0 && blocked.length === 0 && olderPositive) {
1319
+ // The latest windows show no wait. They cleared an older one, so they are cited as the deciding evidence.
1320
+ const clearing = [...inLatest(kinds.starved), ...inLatest(kinds.blocked)].sort((left, right) => left.index - right.index);
1321
+ hypotheses.push(hypothesis(processId, "insufficient-data", "none", refsOf(clearing), "the latest wait windows show no starved or blocked time"));
1322
+ }
1323
+ else if (starved.length > 0 && blocked.length === 0) {
1324
+ hypotheses.push(hypothesis(processId, "suspected", "material-shortage", refsOf(starved), "starved time was observed without a capacity bind"));
1325
+ }
1326
+ else if (blocked.length > 0 && starved.length === 0) {
1327
+ hypotheses.push(hypothesis(processId, "suspected", "demand-shortage", refsOf(blocked), "blocked time was observed without a capacity bind"));
1328
+ }
1329
+ else if (starved.length > 0 && blocked.length > 0) {
1330
+ hypotheses.push(hypothesis(processId, "insufficient-data", "none", [...refsOf(starved), ...refsOf(blocked)], "starved and blocked time were both observed on this process"));
1331
+ }
1332
+ }
1333
+ if (hypotheses.length === 0) {
1334
+ hypotheses.push(hypothesis(null, "insufficient-data", "none", [], "demand and capacity were not both observed"));
1335
+ }
1336
+ const conserved = facts.some((fact) => fact.kind === "conservation");
1337
+ const resolved = hypotheses.some((item) => item.status === "confirmed" || item.status === "suspected");
1338
+ return {
1339
+ schemaVersion: 1,
1340
+ contract: "idlekit.flow.v1",
1341
+ algorithmVersion: FLOW_ALGORITHM_VERSION,
1342
+ capability: observation.capability,
1343
+ // A lone final throughput is a fact, not a diagnosis.
1344
+ status: resolved || conserved ? "ok" : "insufficient-data",
1345
+ facts,
1346
+ hypotheses,
1347
+ littlesLaw,
1348
+ stallMapped: false,
1349
+ externalProvider: false,
1350
+ };
1351
+ }
1352
+ /**
1353
+ * @evidence docs/requirements/active/flow-observability.md#req-pr15-unsupported A growth regime is not a flow sample.
1354
+ * @evidenceReview docs/requirements/active/flow-observability.md#req-pr15-unsupported #2733085 Re-read the section: stall is not a capacity bottleneck.
1355
+ */
1356
+ export function flowCauseForGrowthRegime(regime) {
1357
+ return blank("unsupported", "unsupported", hypothesis(null, "unsupported", "none", [], `growth regime ${regime} is not a flow observation`), "not-applicable", "a growth regime is not a flow sample");
1358
+ }
1359
+ //# sourceMappingURL=flow.js.map