@camstack/types 1.2.404 → 1.2.405

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.
@@ -1,4 +1,5 @@
1
1
  import type { InferenceDeviceDescriptor } from '../inference/runtime-capabilities.js';
2
+ import type { AcceleratorCompute } from '../pipeline/auto-tune/accelerator-compute.js';
2
3
  /** Hardware information detected at boot */
3
4
  export interface HardwareInfo {
4
5
  readonly platform: 'darwin' | 'linux' | 'win32';
@@ -9,6 +10,12 @@ export interface HardwareInfo {
9
10
  readonly availableRAM_MB: number;
10
11
  readonly gpu: GpuInfo | null;
11
12
  readonly npu: NpuInfo | null;
13
+ /**
14
+ * Per-accelerator compute the probe reported (D930). Absent when the probe
15
+ * did not run; an empty list means it ran and found no accelerator. A
16
+ * failed field inside an entry is null, never 0.
17
+ */
18
+ readonly accelerators?: readonly AcceleratorCompute[];
12
19
  /**
13
20
  * Coral Edge TPU hardware (USB and/or PCIe), when found. Optional so existing
14
21
  * HardwareInfo construction sites and older cross-node probe reports stay
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  /** Fixed cluster node palette ids (maps to `--color-node-*` theme tokens). */
3
3
  export declare const NODE_COLOR_IDS: readonly ['node-a', 'node-b', 'node-c', 'node-d', 'node-e', 'node-f', 'node-g', 'node-h'];
4
- export type NodeColorId = (typeof NODE_COLOR_IDS)[number];
5
4
  export declare const NodeColorIdSchema: z.ZodEnum<{
6
5
  "node-a": "node-a";
7
6
  "node-b": "node-b";
@@ -12,4 +11,5 @@ export declare const NodeColorIdSchema: z.ZodEnum<{
12
11
  "node-g": "node-g";
13
12
  "node-h": "node-h";
14
13
  }>;
14
+ export type NodeColorId = z.infer<typeof NodeColorIdSchema>;
15
15
  export declare function assignNodeColorId(nodeId: string): NodeColorId;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Capacity of an accelerator we have not measured (D930).
3
+ *
4
+ * The latency table stays the measured columns. A device that reports compute
5
+ * (OpenVINO GOPS, or execution units × clock, or compute units, or TOPS) is
6
+ * estimated from the nearest measured column of the same accelerator kind,
7
+ * scaled by the compute ratio and clamped. A node benchmark still replaces
8
+ * the estimate. A device that reports neither compute nor a known class stays
9
+ * `unknown`.
10
+ *
11
+ * A failed probe field is `null`, never `0` (D393): zero would be a compute
12
+ * ratio of zero and would size the device as if it could not run.
13
+ */
14
+ import { z } from 'zod';
15
+ import type { AcceleratorKind, HardwareClassId } from './plan-schemas.js';
16
+ import { type DetectorLatencyColumn, type DetectorPerfTable } from './detector-performance.js';
17
+ /**
18
+ * An unmeasured device is never estimated outside this band of its reference.
19
+ *
20
+ * Peak GOPS and detector latency do not move together: a 640 model is memory
21
+ * bound, a 320 model less so, and the N100→N305 public EU×clock ratio is
22
+ * about 2.2×. 2× is the widest that spread justifies without a measurement
23
+ * on the device; 0.5× is the symmetric floor so a tiny iGPU is not told it
24
+ * is many times slower than the weakest column we measured. A node benchmark
25
+ * replaces the estimate and is not clamped.
26
+ */
27
+ export declare const ESTIMATE_COMPUTE_RATIO_MIN = 0.5;
28
+ export declare const ESTIMATE_COMPUTE_RATIO_MAX = 2;
29
+ /**
30
+ * Within this of 1.0, a device whose class IS the reference is that measured
31
+ * machine (a probe clock a few percent off the spec), not a different chip.
32
+ * An unknown class is still estimated, so the plan says so.
33
+ */
34
+ export declare const REFERENCE_MATCH_FRACTION = 0.05;
35
+ /** N100 iGPU: 24 execution units, 750 MHz graphics max (Intel specification). */
36
+ export declare const N100_IGPU_EU = 24;
37
+ export declare const N100_IGPU_CLOCK_MHZ = 750;
38
+ /**
39
+ * Core Ultra 7 265K iGPU: 4 Xe-cores. OpenVINO's execution-unit count for
40
+ * Xe-LP is 16 per Xe-core, and the graphics max dynamic frequency is 2000 MHz.
41
+ * Used only to choose the nearest column for a chip that is not itself a
42
+ * Core Ultra — that class is the measurement and is never scaled.
43
+ */
44
+ export declare const CORE_ULTRA_265K_IGPU_EU = 64;
45
+ export declare const CORE_ULTRA_265K_IGPU_CLOCK_MHZ = 2000;
46
+ /** Phoenix / Hawk Point Radeon 780M: 12 compute units. */
47
+ export declare const PHOENIX_780M_CU = 12;
48
+ export declare const PrecisionGopsSchema: z.ZodObject<{
49
+ int8: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
50
+ fp16: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
51
+ }, z.core.$strip>;
52
+ export type PrecisionGops = z.infer<typeof PrecisionGopsSchema>;
53
+ /** What one accelerator device reported. Every failed query is null. */
54
+ export declare const AcceleratorComputeSchema: z.ZodObject<{
55
+ deviceKey: z.ZodString;
56
+ fullDeviceName: z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | null, string | null>>;
57
+ executionUnits: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
58
+ clockMHz: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
59
+ gops: z.ZodNullable<z.ZodObject<{
60
+ int8: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
61
+ fp16: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
62
+ }, z.core.$strip>>;
63
+ architecture: z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | null, string | null>>;
64
+ npuName: z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | null, string | null>>;
65
+ tops: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
66
+ vendor: z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | null, string | null>>;
67
+ webgpuArchitecture: z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | null, string | null>>;
68
+ webgpuDevice: z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | null, string | null>>;
69
+ computeUnits: z.ZodPipe<z.ZodNullable<z.ZodNumber>, z.ZodTransform<number | null, number | null>>;
70
+ }, z.core.$strip>;
71
+ export type AcceleratorCompute = z.infer<typeof AcceleratorComputeSchema>;
72
+ /** The unit a compute ratio is taken in. Two scores of different units are not compared. */
73
+ export type ComputeMetric = 'gops-int8' | 'gops-fp16' | 'eu-mhz' | 'cu' | 'tops';
74
+ export interface ComputeScore {
75
+ readonly metric: ComputeMetric;
76
+ readonly value: number;
77
+ }
78
+ /** The compute of one measured column, in the unit the probe reports. */
79
+ export interface ReferenceCompute {
80
+ readonly hardwareClass: HardwareClassId;
81
+ readonly accelerator: AcceleratorKind;
82
+ readonly score: ComputeScore;
83
+ }
84
+ /**
85
+ * Compute of the machines the latency columns were measured on.
86
+ * GOPS is preferred when a column carries it; none of these do yet — the
87
+ * boxes were measured before the probe reported `DEVICE_GOPS` — so the scale
88
+ * uses execution units × clock (Intel) or compute units (AMD) until a
89
+ * re-measure locks a GOPS figure on the column.
90
+ */
91
+ export declare const REFERENCE_COMPUTE: readonly ReferenceCompute[];
92
+ export interface ResolveLatencyInput {
93
+ readonly hardwareClass: HardwareClassId;
94
+ readonly accelerator: AcceleratorKind;
95
+ readonly report: AcceleratorCompute | null;
96
+ readonly perf?: DetectorPerfTable;
97
+ readonly references?: readonly ReferenceCompute[];
98
+ }
99
+ export interface ResolvedLatencyColumn {
100
+ readonly column: DetectorLatencyColumn;
101
+ /** Null when the column is the measurement itself. */
102
+ readonly estimatedFrom: HardwareClassId | null;
103
+ }
104
+ /** Parse a probe payload. `null` means the probe failed — not "no accelerators". */
105
+ export declare function parseAcceleratorFactsJson(raw: unknown): readonly AcceleratorCompute[] | null;
106
+ /** Scores in the order the estimate prefers. A non-positive field is absent. */
107
+ export declare function computeScores(report: AcceleratorCompute): readonly ComputeScore[];
108
+ /** True when this report can scale a measured column of `kind`. */
109
+ export declare function reportIsScalable(report: AcceleratorCompute, kind: AcceleratorKind, references?: readonly ReferenceCompute[]): boolean;
110
+ /**
111
+ * The latency column for one device. A measured class other than the N-series
112
+ * spread is returned unchanged — one class there is one measured machine.
113
+ * `intel-n-series` is the N100 column; a different reported compute scales it.
114
+ * An unknown class scales from the nearest reference of the same kind.
115
+ */
116
+ export declare function resolveLatencyColumn(input: ResolveLatencyInput): ResolvedLatencyColumn | null;
@@ -21,6 +21,11 @@ export interface DetectorLatencyCell {
21
21
  readonly fps: number;
22
22
  /** False for a cell derived from another column (scaled), not measured. */
23
23
  readonly measured: boolean;
24
+ /**
25
+ * Set when this cell was scaled from another class's measured column (D930).
26
+ * Absent on a measured cell and on a cell derived inside the same column.
27
+ */
28
+ readonly estimatedFrom?: HardwareClassId;
24
29
  }
25
30
  /** `modelId → cell` for one (hardware class, accelerator) column. */
26
31
  export type DetectorLatencyColumn = Readonly<Record<string, DetectorLatencyCell>>;
@@ -1,11 +1,12 @@
1
1
  /**
2
- * Static hardware classification for the Auto tune recommender (D745).
2
+ * Static hardware classification for the Auto tune recommender (D745, D930).
3
3
  *
4
4
  * A node is classified from the facts its platform probe already reports —
5
5
  * `cpuModel`, `arch`, `gpu`, `npu` — never from a benchmark. The class picks a
6
- * column of the measured latency table (`detector-performance.ts`); a node
7
- * whose CPU matches no measured class is `unknown` and the recommender leaves
8
- * it alone, saying so.
6
+ * column of the measured latency table (`detector-performance.ts`). A CPU that
7
+ * matches no measured class is `unknown`: the recommender then scales from
8
+ * reported accelerator compute when the probe supplied it, and leaves the
9
+ * node alone only when it has neither.
9
10
  *
10
11
  * `cpuModel` is the host's CPU string even inside Docker (`os.cpus()`), which
11
12
  * is why it is the discriminator: "Intel(R) Core(TM) Ultra 7 265K",
@@ -5,5 +5,6 @@
5
5
  */
6
6
  export * from './hardware-class.js';
7
7
  export * from './detector-performance.js';
8
+ export * from './accelerator-compute.js';
8
9
  export * from './recommend.js';
9
10
  export * from './plan-schemas.js';
@@ -99,6 +99,16 @@ export declare const LatencySourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
99
99
  kind: z.ZodLiteral<"node-benchmark">;
100
100
  resultId: z.ZodString;
101
101
  measuredAtMs: z.ZodNumber;
102
+ }, z.core.$strip>, z.ZodObject<{
103
+ kind: z.ZodLiteral<"estimated">;
104
+ estimatedFrom: z.ZodEnum<{
105
+ "amd-phoenix": "amd-phoenix";
106
+ "apple-m-base": "apple-m-base";
107
+ "apple-m-pro": "apple-m-pro";
108
+ "intel-core-ultra": "intel-core-ultra";
109
+ "intel-n-series": "intel-n-series";
110
+ unknown: "unknown";
111
+ }>;
102
112
  }, z.core.$strip>], "kind">;
103
113
  export type LatencySource = z.infer<typeof LatencySourceSchema>;
104
114
  export declare const DeviceModelChoiceSchema: z.ZodObject<{
@@ -112,7 +122,25 @@ export declare const DeviceModelChoiceSchema: z.ZodObject<{
112
122
  kind: z.ZodLiteral<"node-benchmark">;
113
123
  resultId: z.ZodString;
114
124
  measuredAtMs: z.ZodNumber;
125
+ }, z.core.$strip>, z.ZodObject<{
126
+ kind: z.ZodLiteral<"estimated">;
127
+ estimatedFrom: z.ZodEnum<{
128
+ "amd-phoenix": "amd-phoenix";
129
+ "apple-m-base": "apple-m-base";
130
+ "apple-m-pro": "apple-m-pro";
131
+ "intel-core-ultra": "intel-core-ultra";
132
+ "intel-n-series": "intel-n-series";
133
+ unknown: "unknown";
134
+ }>;
115
135
  }, z.core.$strip>], "kind">>;
136
+ estimatedFrom: z.ZodOptional<z.ZodEnum<{
137
+ "amd-phoenix": "amd-phoenix";
138
+ "apple-m-base": "apple-m-base";
139
+ "apple-m-pro": "apple-m-pro";
140
+ "intel-core-ultra": "intel-core-ultra";
141
+ "intel-n-series": "intel-n-series";
142
+ unknown: "unknown";
143
+ }>>;
116
144
  capacitySessions: z.ZodNumber;
117
145
  personRecall: z.ZodNumber;
118
146
  }, z.core.$strip>;
@@ -141,7 +169,25 @@ export declare const DeviceRecommendationSchema: z.ZodObject<{
141
169
  kind: z.ZodLiteral<"node-benchmark">;
142
170
  resultId: z.ZodString;
143
171
  measuredAtMs: z.ZodNumber;
172
+ }, z.core.$strip>, z.ZodObject<{
173
+ kind: z.ZodLiteral<"estimated">;
174
+ estimatedFrom: z.ZodEnum<{
175
+ "amd-phoenix": "amd-phoenix";
176
+ "apple-m-base": "apple-m-base";
177
+ "apple-m-pro": "apple-m-pro";
178
+ "intel-core-ultra": "intel-core-ultra";
179
+ "intel-n-series": "intel-n-series";
180
+ unknown: "unknown";
181
+ }>;
144
182
  }, z.core.$strip>], "kind">>;
183
+ estimatedFrom: z.ZodOptional<z.ZodEnum<{
184
+ "amd-phoenix": "amd-phoenix";
185
+ "apple-m-base": "apple-m-base";
186
+ "apple-m-pro": "apple-m-pro";
187
+ "intel-core-ultra": "intel-core-ultra";
188
+ "intel-n-series": "intel-n-series";
189
+ unknown: "unknown";
190
+ }>>;
145
191
  capacitySessions: z.ZodNumber;
146
192
  personRecall: z.ZodNumber;
147
193
  }, z.core.$strip>>;
@@ -243,7 +289,25 @@ export declare const NodeRecommendationSchema: z.ZodObject<{
243
289
  kind: z.ZodLiteral<"node-benchmark">;
244
290
  resultId: z.ZodString;
245
291
  measuredAtMs: z.ZodNumber;
292
+ }, z.core.$strip>, z.ZodObject<{
293
+ kind: z.ZodLiteral<"estimated">;
294
+ estimatedFrom: z.ZodEnum<{
295
+ "amd-phoenix": "amd-phoenix";
296
+ "apple-m-base": "apple-m-base";
297
+ "apple-m-pro": "apple-m-pro";
298
+ "intel-core-ultra": "intel-core-ultra";
299
+ "intel-n-series": "intel-n-series";
300
+ unknown: "unknown";
301
+ }>;
246
302
  }, z.core.$strip>], "kind">>;
303
+ estimatedFrom: z.ZodOptional<z.ZodEnum<{
304
+ "amd-phoenix": "amd-phoenix";
305
+ "apple-m-base": "apple-m-base";
306
+ "apple-m-pro": "apple-m-pro";
307
+ "intel-core-ultra": "intel-core-ultra";
308
+ "intel-n-series": "intel-n-series";
309
+ unknown: "unknown";
310
+ }>>;
247
311
  capacitySessions: z.ZodNumber;
248
312
  personRecall: z.ZodNumber;
249
313
  }, z.core.$strip>>;
@@ -445,7 +509,25 @@ export declare const AutoTunePlanSchema: z.ZodObject<{
445
509
  kind: z.ZodLiteral<"node-benchmark">;
446
510
  resultId: z.ZodString;
447
511
  measuredAtMs: z.ZodNumber;
512
+ }, z.core.$strip>, z.ZodObject<{
513
+ kind: z.ZodLiteral<"estimated">;
514
+ estimatedFrom: z.ZodEnum<{
515
+ "amd-phoenix": "amd-phoenix";
516
+ "apple-m-base": "apple-m-base";
517
+ "apple-m-pro": "apple-m-pro";
518
+ "intel-core-ultra": "intel-core-ultra";
519
+ "intel-n-series": "intel-n-series";
520
+ unknown: "unknown";
521
+ }>;
448
522
  }, z.core.$strip>], "kind">>;
523
+ estimatedFrom: z.ZodOptional<z.ZodEnum<{
524
+ "amd-phoenix": "amd-phoenix";
525
+ "apple-m-base": "apple-m-base";
526
+ "apple-m-pro": "apple-m-pro";
527
+ "intel-core-ultra": "intel-core-ultra";
528
+ "intel-n-series": "intel-n-series";
529
+ unknown: "unknown";
530
+ }>>;
449
531
  capacitySessions: z.ZodNumber;
450
532
  personRecall: z.ZodNumber;
451
533
  }, z.core.$strip>>;
@@ -673,7 +755,25 @@ export declare const AutoTuneApplyResultSchema: z.ZodDiscriminatedUnion<[z.ZodOb
673
755
  kind: z.ZodLiteral<"node-benchmark">;
674
756
  resultId: z.ZodString;
675
757
  measuredAtMs: z.ZodNumber;
758
+ }, z.core.$strip>, z.ZodObject<{
759
+ kind: z.ZodLiteral<"estimated">;
760
+ estimatedFrom: z.ZodEnum<{
761
+ "amd-phoenix": "amd-phoenix";
762
+ "apple-m-base": "apple-m-base";
763
+ "apple-m-pro": "apple-m-pro";
764
+ "intel-core-ultra": "intel-core-ultra";
765
+ "intel-n-series": "intel-n-series";
766
+ unknown: "unknown";
767
+ }>;
676
768
  }, z.core.$strip>], "kind">>;
769
+ estimatedFrom: z.ZodOptional<z.ZodEnum<{
770
+ "amd-phoenix": "amd-phoenix";
771
+ "apple-m-base": "apple-m-base";
772
+ "apple-m-pro": "apple-m-pro";
773
+ "intel-core-ultra": "intel-core-ultra";
774
+ "intel-n-series": "intel-n-series";
775
+ unknown: "unknown";
776
+ }>>;
677
777
  capacitySessions: z.ZodNumber;
678
778
  personRecall: z.ZodNumber;
679
779
  }, z.core.$strip>>;
@@ -7,18 +7,21 @@
7
7
  * Per node:
8
8
  * 1. Classify the hardware (`classifyInferenceHardware`). An unknown class,
9
9
  * an offline node or a node with nothing to recommend is left untouched —
10
- * unless the node has its own measurements (below).
11
- * 1b. MEASURED ON THE NODE BEATS THE TABLE (D791): a fresh node benchmark
12
- * result for (device, model) replaces the table's cell, and the choice
13
- * names it as its source. A node of unknown hardware with measurements is
14
- * recommended from them alone.
10
+ * unless the node has its own measurements (below) or a device reported
11
+ * compute that can be scaled from a measured column (D930).
12
+ * 1b. MEASURED ON THE NODE BEATS THE TABLE (D791), and the table beats an
13
+ * estimate: a fresh node benchmark result for (device, model) replaces
14
+ * whatever cell the class or the compute scale produced. A node of
15
+ * unknown hardware with measurements is recommended from them alone.
15
16
  * 2. The node's ACCELERATORS (NPU, iGPU, Neural Engine) that are enabled and
16
17
  * available share ONE model — so a camera's floors never flip with the
17
18
  * device the balancer rotated it onto. A candidate must have a build for
18
19
  * every accelerator's format and a latency cell for each.
19
20
  * 3. A candidate FITS a device when the device sustains at least
20
21
  * `minSessionsPerDevice` parallel sessions with it:
21
- * ⌊fps × (1 − headroom) / camera fps⌋ ≥ minSessionsPerDevice.
22
+ * ⌊fps × factor × (1 − headroom) / camera fps⌋ ≥ minSessionsPerDevice.
23
+ * factor is 1 at 10 fps; below that an Intel iGPU uses the measured
24
+ * overlap (D930).
22
25
  * 4. Among candidates that fit everywhere, the most accurate wins (person
23
26
  * recall at the shipped floor); within `RECALL_TIE` of the best, the
24
27
  * fastest wins. That IS the step-down order the data gives: the first
@@ -37,7 +40,7 @@
37
40
  import type { HardwareInfo } from '../../interfaces/platform.js';
38
41
  import type { ModelFormat } from '../../types/models.js';
39
42
  import { type DetectorPerfTable } from './detector-performance.js';
40
- import { type NodeRecommendation } from './plan-schemas.js';
43
+ import { type AcceleratorKind, type NodeRecommendation } from './plan-schemas.js';
41
44
  /** The family the cluster runs. */
42
45
  export declare const AUTO_TUNE_FAMILY = "yolov9";
43
46
  /**
@@ -51,8 +54,27 @@ export declare const RECALL_TIE = 0.02;
51
54
  export declare const DEFAULT_HEADROOM = 0.4;
52
55
  /** Detection rate a session is counted at when no camera says otherwise. */
53
56
  export declare const DEFAULT_CAMERA_FPS = 10;
54
- /** Parallel sessions one device sustains at `fps` with `headroom` kept free. */
55
- export declare function capacitySessionsOf(fps: number, headroom: number, cameraFps: number): number;
57
+ /**
58
+ * Camera rate at which serial `1000/p50` matched the cameras that held
59
+ * (N100 iGPU, 2026-10-24). Below this the second InferRequest's overlap
60
+ * becomes extra sessions; at and above it the serial ceiling is the count.
61
+ */
62
+ export declare const SERIAL_CAPACITY_CAMERA_FPS = 10;
63
+ /**
64
+ * Aggregate throughput ÷ serial throughput when the frame interval is wide
65
+ * enough to hide the second request. intel-igpu is the N100 measurement
66
+ * (~1.4× under LATENCY with 2 InferRequests). Every other kind stays 1
67
+ * until it is measured the same way.
68
+ */
69
+ export declare const AGGREGATE_THROUGHPUT_BY_KIND: Readonly<Partial<Record<AcceleratorKind, number>>>;
70
+ /** The overlap factor for this kind at this camera rate. 1 at {@link SERIAL_CAPACITY_CAMERA_FPS} and above. */
71
+ export declare function aggregateThroughputFactor(kind: AcceleratorKind, cameraFps: number): number;
72
+ /**
73
+ * Parallel sessions one device sustains at `fps` with `headroom` kept free.
74
+ * `aggregateFactor` is the kind's overlap (1 unless the caller measured
75
+ * extra throughput at this camera rate).
76
+ */
77
+ export declare function capacitySessionsOf(fps: number, headroom: number, cameraFps: number, aggregateFactor?: number): number;
56
78
  /** A latency measured on the node itself (a fresh node benchmark result, D791). */
57
79
  export interface MeasuredLatencyCell {
58
80
  readonly p50Ms: number;
@@ -0,0 +1,2 @@
1
+ export * from './small-subject-recovery.js';
2
+ export * from './motion-crop-plan.js';
@@ -0,0 +1,183 @@
1
+ /**
2
+ * The MEASURED motion-crop recipe (D396) — per camera, default off.
3
+ *
4
+ * ## What this adds to the pass that already exists
5
+ *
6
+ * `small-subject-recovery.ts` ships a second detector pass gated on an
7
+ * UNCOVERED motion region: a region is worth a crop when it is small AND
8
+ * mostly NOT accounted for by a full-frame box. That rule was built to find a
9
+ * subject standing NEXT TO one the detector already sees, and it works.
10
+ *
11
+ * The measurement says the cheaper question is the better one. On camera 615,
12
+ * against the production detector (`yolov9m-320-int8`, python+openvino) on the
13
+ * node that runs that camera, over 38 visually confirmed positive frames from
14
+ * six real animal pass-bys: full-frame recall at our animal floor **24%**,
15
+ * detecting on motion-derived crops **42%**, the same crops with the motion
16
+ * area bar lowered **74%**. Per pass-by 4/6 → 6/6 at our floor, 3/6 → 6/6 at
17
+ * a 0.70 floor. The score distribution moves with it — full frame median
18
+ * 0.780 / p25 0.526, crops 0.840 / p25 0.652.
19
+ *
20
+ * So this rule keeps every moving region, and treats a tracked box that
21
+ * intersects one as a SEED rather than as an exclusion.
22
+ *
23
+ * ## Additive, never substitutive
24
+ *
25
+ * On frames where motion is silent the crop arm scores 0% and the full-frame
26
+ * arm still scores 5% — and the full frame is the only arm that can see a
27
+ * STATIONARY subject at all. Both recipes only ever ADD boxes to the
28
+ * full-frame result; nothing here can remove one.
29
+ *
30
+ * ## Cost
31
+ *
32
+ * Mean 0.25 extra detector invocations per frame at the shipped motion
33
+ * sensitivity and 0.88 at the lowered bar, on the node that would run it. A
34
+ * crop costs about the same as a full frame (45.2 ms vs 40.8 ms p50) — it is
35
+ * not cheaper, it is better aimed — and the whole thing is bounded by the
36
+ * motion duty cycle. The runner's own per-camera rate limit
37
+ * (`RECOVERY_MIN_INTERVAL_MS`) is the ceiling above that.
38
+ *
39
+ * ## What this is NOT (D52)
40
+ *
41
+ * Not a detail/CLIP crop, for the same reason `small-subject-recovery.ts` is
42
+ * not one: `deriveDetailCropRect` derives the rectangle an enrichment step is
43
+ * fed from a KNOWN subject box, and `object-clip` is one vector index that
44
+ * tolerates exactly one such derivation. This module derives a square from a
45
+ * MOTION region, before any subject exists, for the FIRST-LEVEL detector; its
46
+ * output is a detection, never a vector. Nothing here calls the detail
47
+ * derivation and nothing here may be reused for one.
48
+ *
49
+ * Pure: no runner state, no IPC, no pixels.
50
+ *
51
+ * Lives in `@camstack/types` so the live runner (`addon-pipeline`) and the
52
+ * offline accuracy evaluation (`addon-benchmark`) plan the SAME crops: one
53
+ * module, two callers, no copy to drift.
54
+ */
55
+ import type { ObjectDetection } from '../../types/detection.js';
56
+ import type { PipelineStepInputOutput } from '../../capabilities/pipeline-executor.cap.js';
57
+ import { type NormalizedRect, type RecoveryCrop, type RecoveryPlanInput } from './small-subject-recovery.js';
58
+ /**
59
+ * Which region rule this camera's second pass runs.
60
+ *
61
+ * The selector is per camera and defaults to the shipped rule, exactly like
62
+ * the motion area bar's own `minArea: 0` opt-in (D394): a deploy changes
63
+ * nothing until an operator moves a camera.
64
+ */
65
+ export type RecoveryRecipe = 'uncovered-region' | 'motion-crop';
66
+ /**
67
+ * Step-settings key of the opt-in, on the `object-detection` step — so it is
68
+ * per camera through `pipelineOrchestrator.setCameraStepSettings` (a
69
+ * camera-semantic key, D927), and it rides the same
70
+ * `PipelineStepInputOutput.settings` the per-macro confidence floors ride.
71
+ */
72
+ export declare const MOTION_CROP_DISPATCH_KEY = "motionCropDispatch";
73
+ /**
74
+ * Read the opt-in. Anything that is not the boolean `true` is the shipped
75
+ * rule: a stored string or a number is a mis-write (this repo has shipped a
76
+ * setting written into the wrong sqlite table before), and a mis-write must
77
+ * not silently change what a camera detects on.
78
+ */
79
+ export declare function readRecoveryRecipe(settings: Readonly<Record<string, unknown>> | undefined): RecoveryRecipe;
80
+ /**
81
+ * The recipe this camera's resolved step tree selects.
82
+ *
83
+ * Reads the ENABLED first-level detector's own settings, which is where
84
+ * `pipelineOrchestrator.setCameraStepSettings` writes a per-camera value. A
85
+ * tree with no enabled detector runs no second pass at all, so the answer
86
+ * there is the shipped rule and it is never used.
87
+ */
88
+ export declare function readRecoveryRecipeForSteps(steps: readonly PipelineStepInputOutput[]): RecoveryRecipe;
89
+ /**
90
+ * A motion box is grown ×1.5 about its centre before anything else.
91
+ *
92
+ * The motion step's box is the CHANGED pixels, which on a moving animal is the
93
+ * leading edge plus its shadow, not the animal. The detector needs the subject
94
+ * and the context it was trained on.
95
+ */
96
+ export declare const MOTION_CROP_MOTION_PAD = 1.5;
97
+ /**
98
+ * An intersecting tracked box is grown ×1.25 — less, because it is already a
99
+ * subject rectangle rather than a change mask.
100
+ */
101
+ export declare const MOTION_CROP_TRACKED_PAD = 1.25;
102
+ /**
103
+ * Regions per frame, largest area first.
104
+ *
105
+ * Measured as NON-BINDING: over the 156 frames of the recall harness the cap
106
+ * bound on 0 of them. It is the bound on a storm, not a tuning knob, and the
107
+ * runner reports when it binds so a camera on which it starts to is visible.
108
+ */
109
+ export declare const MOTION_CROP_MAX_REGIONS = 3;
110
+ /**
111
+ * The floor a `person` or `vehicle` box must clear when it came out of a CROP
112
+ * rather than out of the full frame.
113
+ *
114
+ * Collected, not assumed: 3 085 quiet frames produced 27 motion-positive
115
+ * frames and 28 crop invocations. The full-frame arm produced 0 boxes above
116
+ * any gate; the crop arm produced 3, of which two are genuine false positives,
117
+ * and both are night-IR corners upscaled into a 320 model — `vehicle 0.749`
118
+ * and `person 0.701`. Zero false `animal` at any gate, which is why `animal`
119
+ * is deliberately absent from this table: the class the pass exists to recover
120
+ * is the class that never produced a false positive, and gating it would cost
121
+ * the whole measured gain.
122
+ *
123
+ * This is a CROP-ONLY floor, applied on top of the per-macro floors the
124
+ * executor already enforced. A full-frame `person` at 0.70 is untouched — the
125
+ * full-frame arm is the one arm with ground truth behind its floor
126
+ * (`minConfidencePerson` 0.65, raised on 2026-07-30 from a measured
127
+ * distribution).
128
+ *
129
+ * The cost of this floor is stated rather than assumed away: it can also
130
+ * remove a real distant person or vehicle recovered from a crop at 0.70–0.80.
131
+ * Nothing in the quiet-footage sample measures that, so the floor is a
132
+ * constant here rather than a slider, and the runner reports every drop it
133
+ * makes per camera.
134
+ */
135
+ export declare const CROP_CLASS_FLOORS: Readonly<Record<string, number>>;
136
+ /** One box the crop floor removed, with the numbers that removed it. */
137
+ export interface CropFloorDrop {
138
+ readonly macroClass: string;
139
+ readonly score: number;
140
+ readonly floor: number;
141
+ }
142
+ /** What {@link applyCropClassFloors} kept, and everything it did not. */
143
+ export interface CropFloorVerdict {
144
+ readonly kept: readonly ObjectDetection[];
145
+ readonly dropped: readonly CropFloorDrop[];
146
+ }
147
+ /**
148
+ * Apply the crop-only class floors, REPORTING every drop.
149
+ *
150
+ * A class with no entry in {@link CROP_CLASS_FLOORS} is kept: a floor this
151
+ * table cannot express is not a floor of zero, and silently dropping a class
152
+ * nobody measured is the exact shape of silent drop this repo has paid for
153
+ * three separate times.
154
+ */
155
+ export declare function applyCropClassFloors(detections: readonly ObjectDetection[]): CropFloorVerdict;
156
+ /**
157
+ * The regions the measured recipe judges this frame on.
158
+ *
159
+ * Motion boxes padded {@link MOTION_CROP_MOTION_PAD}; every full-frame box
160
+ * that intersects a RAW motion box padded {@link MOTION_CROP_TRACKED_PAD} and
161
+ * added as a seed of its own; everything that overlaps merged; the result
162
+ * clamped to the frame, ordered largest first and capped at
163
+ * {@link MOTION_CROP_MAX_REGIONS}.
164
+ *
165
+ * There is deliberately no coverage gate and no size gate here. Those belong
166
+ * to the shipped rule, and they are what makes it a rule about a subject
167
+ * BESIDE a detected one; the measurement says the pass is worth running on the
168
+ * detected subject's own region too.
169
+ */
170
+ export declare function planMotionCropRegions(input: RecoveryPlanInput): readonly NormalizedRect[];
171
+ /**
172
+ * The crops the measured recipe runs on this frame.
173
+ *
174
+ * Dedupe is by CONTAINMENT only. Two squares that merely overlap both run: the
175
+ * pixels the second adds are pixels no other crop shows the detector, and the
176
+ * fusion step downstream already refuses a duplicate BOX. Dropping a crop
177
+ * because it overlapped would drop the subject sitting at its edge, which is
178
+ * the whole population this pass exists for.
179
+ *
180
+ * A frame that cannot hold the smallest crop yields nothing: it is already
181
+ * seen at scale.
182
+ */
183
+ export declare function planMotionCrops(input: RecoveryPlanInput): readonly RecoveryCrop[];