create-quorum-router 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@ deno task intake
18
18
  deno task supabase:status
19
19
  ```
20
20
 
21
- Current package version: `create-quorum-router@0.1.16`. Releases are published
21
+ Current package version: `create-quorum-router@0.1.18`. Releases are published
22
22
  from an immutable Git tag through GitHub Actions OIDC Trusted Publishing.
23
23
 
24
24
  ## What the generated project supports
@@ -3,7 +3,7 @@ const fs = require("fs");
3
3
  const path = require("path");
4
4
  const { spawnSync } = require("child_process");
5
5
 
6
- const VERSION = "0.1.16";
6
+ const VERSION = "0.1.18";
7
7
  const SUPPORTED_TEMPLATES = new Set(["basic"]);
8
8
 
9
9
  function usage() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-quorum-router",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Create a local QuorumRouter project.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  # QuorumRouter generated workspace
2
2
 
3
3
  This generated workspace contains the MIT-licensed QuorumRouter current release.
4
- npm latest targets v0.1.16.
4
+ npm latest targets v0.1.18.
5
5
 
6
6
  QuorumRouter is **MIT**. It is **open source**. Commercial and production use
7
7
  are permitted under the MIT License.
@@ -8,6 +8,14 @@ function stableMetric(value: number): number {
8
8
  return rounded === 0 ? 0 : rounded;
9
9
  }
10
10
 
11
+ function isCanonicalBinaryAccuracy(
12
+ sampleCount: number,
13
+ accuracy: number,
14
+ ): boolean {
15
+ const correctCount = Math.round(accuracy * sampleCount);
16
+ return accuracy === stableMetric(correctCount / sampleCount);
17
+ }
18
+
11
19
  function boundedCanonicalText(maxLength: number) {
12
20
  return z.string().trim().transform((value) => value.normalize("NFC")).pipe(
13
21
  z.string().min(1).max(maxLength).refine(
@@ -254,6 +262,7 @@ export function aggregateTaskCalibration(
254
262
 
255
263
  export const MAX_HIERARCHICAL_CALIBRATION_GROUPS =
256
264
  MAX_CALIBRATION_OBSERVATIONS * 3;
265
+ const HIERARCHICAL_ROLLUP_TOLERANCE = 1e-9;
257
266
 
258
267
  export const HierarchicalCalibrationScopeSchema = z.enum([
259
268
  "task_type",
@@ -492,11 +501,18 @@ export const HierarchicalCalibrationDriftGuardOptionsSchema = z.object({
492
501
  maximum_child_parent_brier_score_delta: z.number().finite().min(0).max(1),
493
502
  }).strict();
494
503
 
495
- const HIERARCHICAL_ROLLUP_TOLERANCE = 1e-9;
496
-
497
504
  export const HierarchicalTaskCalibrationGuardedReportSchema =
498
505
  HierarchicalTaskCalibrationReportSchema.superRefine((report, context) => {
499
506
  report.groups.forEach((parent, parentIndex) => {
507
+ if (!isCanonicalBinaryAccuracy(parent.sample_count, parent.accuracy)) {
508
+ context.addIssue({
509
+ code: "custom",
510
+ message:
511
+ "guarded accuracy must be the canonical ratio of integer correct observations",
512
+ path: ["groups", parentIndex, "accuracy"],
513
+ });
514
+ }
515
+
500
516
  const childScope = parent.scope === "task_type"
501
517
  ? "task_subtype"
502
518
  : parent.scope === "task_subtype"
@@ -599,6 +615,33 @@ const HierarchicalGuardedCalibrationCandidateSchema = z.object({
599
615
  "candidate metrics must be null exactly when the candidate is missing",
600
616
  });
601
617
  }
618
+ if (
619
+ candidate.sample_count !== null && candidate.accuracy !== null &&
620
+ candidate.mean_confidence !== null &&
621
+ candidate.mean_calibration_bias !== null
622
+ ) {
623
+ if (
624
+ candidate.mean_calibration_bias !==
625
+ stableMetric(candidate.mean_confidence - candidate.accuracy)
626
+ ) {
627
+ context.addIssue({
628
+ code: "custom",
629
+ message:
630
+ "candidate mean_calibration_bias must equal mean_confidence - accuracy",
631
+ path: ["mean_calibration_bias"],
632
+ });
633
+ }
634
+ if (
635
+ !isCanonicalBinaryAccuracy(candidate.sample_count, candidate.accuracy)
636
+ ) {
637
+ context.addIssue({
638
+ code: "custom",
639
+ message:
640
+ "candidate accuracy must be the canonical ratio of integer correct observations",
641
+ path: ["accuracy"],
642
+ });
643
+ }
644
+ }
602
645
  });
603
646
 
604
647
  export const HierarchicalTaskCalibrationGuardedSelectionSchema = z.object({
@@ -608,6 +651,9 @@ export const HierarchicalTaskCalibrationGuardedSelectionSchema = z.object({
608
651
  advisory_only: z.literal(true),
609
652
  query: HierarchicalTaskCalibrationQuerySchema,
610
653
  requested_scope: HierarchicalCalibrationScopeSchema,
654
+ minimum_sample_count: z.number().int().positive().max(
655
+ MAX_CALIBRATION_OBSERVATIONS,
656
+ ),
611
657
  drift_guard: HierarchicalCalibrationDriftGuardOptionsSchema,
612
658
  resolution_status: z.enum(["selected", "no_eligible_group"]),
613
659
  selected_scope: HierarchicalCalibrationScopeSchema.nullable(),
@@ -646,6 +692,19 @@ export const HierarchicalTaskCalibrationGuardedSelectionSchema = z.object({
646
692
  }
647
693
 
648
694
  selection.candidates.forEach((candidate, index) => {
695
+ const expectedSampleStatus = candidate.sample_count === null
696
+ ? "missing"
697
+ : candidate.sample_count < selection.minimum_sample_count
698
+ ? "insufficient"
699
+ : "sufficient";
700
+ if (candidate.sample_status !== expectedSampleStatus) {
701
+ context.addIssue({
702
+ code: "custom",
703
+ message:
704
+ "candidate sample_status must match the configured sample threshold",
705
+ path: ["candidates", index, "sample_status"],
706
+ });
707
+ }
649
708
  const isRoot = candidate.scope === "task_type";
650
709
  const immediateParent = selection.candidates[index + 1];
651
710
  if (isRoot) {
@@ -832,12 +891,21 @@ export const HierarchicalTaskCalibrationGuardedDecisionSchema = z.object({
832
891
  report: HierarchicalTaskCalibrationGuardedReportSchema,
833
892
  selection: HierarchicalTaskCalibrationGuardedSelectionSchema,
834
893
  }).strict().superRefine((decision, context) => {
835
- const expected = resolveHierarchicalTaskCalibrationWithDriftGuard(
894
+ const parsedReport = HierarchicalTaskCalibrationGuardedReportSchema.safeParse(
836
895
  decision.report,
837
- decision.selection.query,
838
- decision.selection.drift_guard,
839
896
  );
840
- if (JSON.stringify(decision.selection) !== JSON.stringify(expected)) {
897
+ const parsedSelection = HierarchicalTaskCalibrationGuardedSelectionSchema
898
+ .safeParse(
899
+ decision.selection,
900
+ );
901
+ if (!parsedReport.success || !parsedSelection.success) return;
902
+
903
+ const expected = resolveHierarchicalTaskCalibrationWithDriftGuard(
904
+ parsedReport.data,
905
+ parsedSelection.data.query,
906
+ parsedSelection.data.drift_guard,
907
+ );
908
+ if (JSON.stringify(parsedSelection.data) !== JSON.stringify(expected)) {
841
909
  context.addIssue({
842
910
  code: "custom",
843
911
  message: "guarded selection must be derived from the aggregate report",
@@ -1180,6 +1248,7 @@ export function resolveHierarchicalTaskCalibrationWithDriftGuard(
1180
1248
  advisory_only: true,
1181
1249
  query: parsedQuery,
1182
1250
  requested_scope,
1251
+ minimum_sample_count: parsedReport.minimum_sample_count,
1183
1252
  drift_guard,
1184
1253
  resolution_status: selected_group === undefined
1185
1254
  ? "no_eligible_group"