modelrig 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +125 -0
- package/README.md +54 -4
- package/dist/adapters/anthropic.d.ts.map +1 -1
- package/dist/adapters/anthropic.js +36 -7
- package/dist/adapters/attempt-meta-map.d.ts +63 -0
- package/dist/adapters/attempt-meta-map.d.ts.map +1 -0
- package/dist/adapters/attempt-meta-map.js +154 -0
- package/dist/adapters/deepseek.d.ts.map +1 -1
- package/dist/adapters/deepseek.js +25 -2
- package/dist/adapters/gemini.d.ts.map +1 -1
- package/dist/adapters/gemini.js +29 -2
- package/dist/adapters/grok.d.ts.map +1 -1
- package/dist/adapters/grok.js +25 -2
- package/dist/adapters/openai-compat.d.ts.map +1 -1
- package/dist/adapters/openai-compat.js +25 -2
- package/dist/adapters/openai-stream.d.ts +2 -0
- package/dist/adapters/openai-stream.d.ts.map +1 -1
- package/dist/adapters/openai-stream.js +23 -3
- package/dist/adapters/openai.d.ts.map +1 -1
- package/dist/adapters/openai.js +36 -6
- package/dist/artifacts/artifact.d.ts.map +1 -1
- package/dist/artifacts/artifact.js +24 -5
- package/dist/artifacts/classification.d.ts +27 -0
- package/dist/artifacts/classification.d.ts.map +1 -0
- package/dist/artifacts/classification.js +38 -0
- package/dist/artifacts/index.d.ts +3 -1
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +10 -1
- package/dist/artifacts/run-context.d.ts +25 -3
- package/dist/artifacts/run-context.d.ts.map +1 -1
- package/dist/artifacts/run-context.js +61 -0
- package/dist/artifacts/scrub.d.ts +26 -0
- package/dist/artifacts/scrub.d.ts.map +1 -1
- package/dist/artifacts/scrub.js +53 -0
- package/dist/artifacts/step.d.ts +9 -0
- package/dist/artifacts/step.d.ts.map +1 -1
- package/dist/artifacts/step.js +9 -0
- package/dist/bakeoff/engine.d.ts +46 -4
- package/dist/bakeoff/engine.d.ts.map +1 -1
- package/dist/bakeoff/engine.js +269 -19
- package/dist/bakeoff/eval-cases.d.ts +5 -0
- package/dist/bakeoff/eval-cases.d.ts.map +1 -1
- package/dist/bakeoff/eval-cases.js +3 -0
- package/dist/bakeoff/judge.d.ts +39 -0
- package/dist/bakeoff/judge.d.ts.map +1 -0
- package/dist/bakeoff/judge.js +102 -0
- package/dist/bakeoff/quality.d.ts +44 -0
- package/dist/bakeoff/quality.d.ts.map +1 -0
- package/dist/bakeoff/quality.js +126 -0
- package/dist/bakeoff/reference.d.ts +34 -0
- package/dist/bakeoff/reference.d.ts.map +1 -0
- package/dist/bakeoff/reference.js +68 -0
- package/dist/bakeoff/replay.d.ts +25 -0
- package/dist/bakeoff/replay.d.ts.map +1 -1
- package/dist/bakeoff/replay.js +48 -1
- package/dist/bakeoff/report.d.ts +8 -1
- package/dist/bakeoff/report.d.ts.map +1 -1
- package/dist/bakeoff/report.js +83 -12
- package/dist/bakeoff/samples.d.ts +35 -2
- package/dist/bakeoff/samples.d.ts.map +1 -1
- package/dist/bakeoff/samples.js +67 -6
- package/dist/bakeoff/stats.d.ts +17 -1
- package/dist/bakeoff/stats.d.ts.map +1 -1
- package/dist/bakeoff/stats.js +67 -0
- package/dist/bakeoff/types.d.ts +76 -5
- package/dist/bakeoff/types.d.ts.map +1 -1
- package/dist/bakeoff/types.js +4 -3
- package/dist/cli-query.d.ts +14 -0
- package/dist/cli-query.d.ts.map +1 -0
- package/dist/cli-query.js +59 -0
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +26 -23
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/detect/detector.d.ts +82 -0
- package/dist/detect/detector.d.ts.map +1 -0
- package/dist/detect/detector.js +23 -0
- package/dist/index.d.ts +19 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -11
- package/dist/query/analytics.d.ts +84 -0
- package/dist/query/analytics.d.ts.map +1 -0
- package/dist/query/analytics.js +280 -0
- package/dist/query/columns.d.ts +59 -0
- package/dist/query/columns.d.ts.map +1 -0
- package/dist/query/columns.js +89 -0
- package/dist/query/grammar.d.ts +74 -7
- package/dist/query/grammar.d.ts.map +1 -1
- package/dist/query/grammar.js +179 -71
- package/dist/query/saved.d.ts +26 -0
- package/dist/query/saved.d.ts.map +1 -0
- package/dist/query/saved.js +51 -0
- package/dist/routes/loader.js +15 -10
- package/dist/routes/objective-loader.d.ts +35 -0
- package/dist/routes/objective-loader.d.ts.map +1 -0
- package/dist/routes/objective-loader.js +286 -0
- package/dist/run/accept.d.ts +43 -0
- package/dist/run/accept.d.ts.map +1 -0
- package/dist/run/accept.js +65 -0
- package/dist/run/cost.d.ts +13 -0
- package/dist/run/cost.d.ts.map +1 -1
- package/dist/run/cost.js +27 -0
- package/dist/run/dispatch.d.ts +24 -1
- package/dist/run/dispatch.d.ts.map +1 -1
- package/dist/run/dispatch.js +19 -0
- package/dist/run/ladder-key.d.ts +4 -0
- package/dist/run/ladder-key.d.ts.map +1 -1
- package/dist/run/ladder-key.js +3 -0
- package/dist/run/quality-gate.d.ts +39 -0
- package/dist/run/quality-gate.d.ts.map +1 -0
- package/dist/run/quality-gate.js +70 -0
- package/dist/run/raw.d.ts.map +1 -1
- package/dist/run/raw.js +22 -3
- package/dist/run/record-attempt.d.ts.map +1 -1
- package/dist/run/record-attempt.js +22 -1
- package/dist/run/routing-docs.d.ts.map +1 -1
- package/dist/run/routing-docs.js +11 -4
- package/dist/run/run.d.ts.map +1 -1
- package/dist/run/run.js +46 -39
- package/dist/settings/index.d.ts +1 -1
- package/dist/settings/index.d.ts.map +1 -1
- package/dist/settings/index.js +2 -1
- package/dist/settings/task-settings.d.ts +10 -0
- package/dist/settings/task-settings.d.ts.map +1 -1
- package/dist/settings/task-settings.js +17 -0
- package/dist/telemetry/attempt-meta.d.ts +178 -0
- package/dist/telemetry/attempt-meta.d.ts.map +1 -0
- package/dist/telemetry/attempt-meta.js +319 -0
- package/dist/telemetry/exporter.d.ts.map +1 -1
- package/dist/telemetry/exporter.js +6 -0
- package/dist/telemetry/ingest-protocol.d.ts +11 -0
- package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
- package/dist/telemetry/ingest-protocol.js +3 -0
- package/dist/telemetry/otel-map.d.ts +10 -0
- package/dist/telemetry/otel-map.d.ts.map +1 -1
- package/dist/telemetry/otel-map.js +64 -0
- package/dist/telemetry/store-migrations.d.ts.map +1 -1
- package/dist/telemetry/store-migrations.js +15 -0
- package/dist/telemetry/store.d.ts.map +1 -1
- package/dist/telemetry/store.js +25 -7
- package/dist/types/failures-teaching.d.ts.map +1 -1
- package/dist/types/failures-teaching.js +20 -0
- package/dist/types/failures.d.ts +1 -1
- package/dist/types/failures.d.ts.map +1 -1
- package/dist/types/failures.js +1 -0
- package/dist/types/provider.d.ts +9 -0
- package/dist/types/provider.d.ts.map +1 -1
- package/dist/types/quality.d.ts +41 -0
- package/dist/types/quality.d.ts.map +1 -0
- package/dist/types/quality.js +12 -0
- package/dist/types/route.d.ts +89 -0
- package/dist/types/route.d.ts.map +1 -1
- package/dist/types/telemetry.d.ts +13 -0
- package/dist/types/telemetry.d.ts.map +1 -1
- package/dist/validate-cli.d.ts.map +1 -1
- package/dist/validate-cli.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The `data_classification` enum — the ONE place the vocabulary is spelled
|
|
4
|
+
* (screening SC-0 S8). Backs three enforcement points that must agree:
|
|
5
|
+
* • the SDK save gate (`artifact.ts` — teaching warn + drop on a bad value),
|
|
6
|
+
* • the server ingest validator (`ingest-artifacts.ts` — enum-only, counted),
|
|
7
|
+
* • the DB CHECK (`00058_artifacts_data_classification_enum.sql`).
|
|
8
|
+
* Keeping the list here (not re-spelled at each site) is what keeps the three
|
|
9
|
+
* from drifting; the migration and this constant are diffed by eye in review.
|
|
10
|
+
*
|
|
11
|
+
* `pii`/`phi` are the SENSITIVE tiers: an artifact tagged either resolves an
|
|
12
|
+
* effective scrub mode of at least `redact` regardless of the task's configured
|
|
13
|
+
* mode (S8-c, `settings/task-settings.ts effectiveScrubMode`). NULL stays a
|
|
14
|
+
* valid "unclassified" state — the column is nullable and the SDK sends null
|
|
15
|
+
* when no classification is given; the enum constrains only NON-null values.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SENSITIVE_CLASSIFICATIONS = exports.DATA_CLASSIFICATIONS = void 0;
|
|
19
|
+
exports.normalizeClassification = normalizeClassification;
|
|
20
|
+
exports.isDataClassification = isDataClassification;
|
|
21
|
+
exports.DATA_CLASSIFICATIONS = ["public", "internal", "confidential", "pii", "phi"];
|
|
22
|
+
/** The tiers that force the scrub floor (S8-c). A set for O(1) membership. */
|
|
23
|
+
exports.SENSITIVE_CLASSIFICATIONS = new Set(["pii", "phi"]);
|
|
24
|
+
/** Normalize a caller-supplied classification the way both enforcement sides
|
|
25
|
+
* do BEFORE the enum check — trim and lowercase, so `"PHI"`/`" phi "` resolve to
|
|
26
|
+
* `phi` (and keep their scrub floor) rather than silently dropping. Non-strings
|
|
27
|
+
* return null. */
|
|
28
|
+
function normalizeClassification(value) {
|
|
29
|
+
if (typeof value !== "string")
|
|
30
|
+
return null;
|
|
31
|
+
const norm = value.trim().toLowerCase();
|
|
32
|
+
return norm === "" ? null : norm;
|
|
33
|
+
}
|
|
34
|
+
/** True when `value` is one of the enum values (after normalization). */
|
|
35
|
+
function isDataClassification(value) {
|
|
36
|
+
const norm = normalizeClassification(value);
|
|
37
|
+
return norm !== null && exports.DATA_CLASSIFICATIONS.includes(norm);
|
|
38
|
+
}
|
|
@@ -18,8 +18,10 @@ export type { ArtifactStore } from "../telemetry/artifact-store";
|
|
|
18
18
|
export type { ArtifactApi, ArtifactHandle, ArtifactSaveOptions, ArtifactEvaluateOptions, ArtifactPromoteOptions, ArtifactContentDeps, ArtifactContentUploader, } from "./artifact";
|
|
19
19
|
export { uploadArtifactContent } from "./content-uploader";
|
|
20
20
|
export type { ContentUploadConfig, ContentUploadInput, ContentUploadOutcome, } from "./content-uploader";
|
|
21
|
-
export { scrubContent, luhnValid } from "./scrub";
|
|
21
|
+
export { scrubContent, luhnValid, detectSpans, scrubDetectors } from "./scrub";
|
|
22
22
|
export type { ScrubMode, ScrubFinding, ScrubResult, ScrubDetectorType } from "./scrub";
|
|
23
|
+
export { DATA_CLASSIFICATIONS, SENSITIVE_CLASSIFICATIONS, isDataClassification, normalizeClassification, } from "./classification";
|
|
24
|
+
export type { DataClassification } from "./classification";
|
|
23
25
|
export { computeDownstreamClosure, TAINT_DEFAULT_MAX_DEPTH, TAINT_DEFAULT_CAP, } from "./taint";
|
|
24
26
|
export type { TaintEdge, Supersession, TaintNode, TaintClosure, TaintOptions, } from "./taint";
|
|
25
27
|
export type { RunRow, StepRow, ArtifactRow, ArtifactEdgeRow, ArtifactEvaluationRow, EvalCaseRow, EvalCaseOrigin, } from "../types/telemetry";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/artifacts/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxE,YAAY,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,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,EAAE,aAAa,GAAG,IAAI,CAAC;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,eAAe,CAAC;CACtC,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAY/F;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAAG,SAAS,GACzC,mBAAmB,GAAG,SAAS,CAWjC;AAED;;2EAE2E;AAC3E,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;4BAEwB;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAC1C,GAAG,iBAAiB,CAYpB"}
|
package/dist/artifacts/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* lifecycle + `@step`; chunk B adds the artifact primitives (save/load/evaluate).
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TAINT_DEFAULT_CAP = exports.TAINT_DEFAULT_MAX_DEPTH = exports.computeDownstreamClosure = exports.luhnValid = exports.scrubContent = exports.uploadArtifactContent = exports.openArtifactStore = exports.createArtifactApi = exports.step = exports.createRunNamespace = exports.getActiveRunContext = void 0;
|
|
10
|
+
exports.TAINT_DEFAULT_CAP = exports.TAINT_DEFAULT_MAX_DEPTH = exports.computeDownstreamClosure = exports.normalizeClassification = exports.isDataClassification = exports.SENSITIVE_CLASSIFICATIONS = exports.DATA_CLASSIFICATIONS = exports.scrubDetectors = exports.detectSpans = exports.luhnValid = exports.scrubContent = exports.uploadArtifactContent = exports.openArtifactStore = exports.createArtifactApi = exports.step = exports.createRunNamespace = exports.getActiveRunContext = void 0;
|
|
11
11
|
exports.wireRigArtifacts = wireRigArtifacts;
|
|
12
12
|
exports.buildArtifactContentDeps = buildArtifactContentDeps;
|
|
13
13
|
exports.createArtifactNamespace = createArtifactNamespace;
|
|
@@ -28,6 +28,15 @@ Object.defineProperty(exports, "uploadArtifactContent", { enumerable: true, get:
|
|
|
28
28
|
var scrub_1 = require("./scrub");
|
|
29
29
|
Object.defineProperty(exports, "scrubContent", { enumerable: true, get: function () { return scrub_1.scrubContent; } });
|
|
30
30
|
Object.defineProperty(exports, "luhnValid", { enumerable: true, get: function () { return scrub_1.luhnValid; } });
|
|
31
|
+
Object.defineProperty(exports, "detectSpans", { enumerable: true, get: function () { return scrub_1.detectSpans; } });
|
|
32
|
+
Object.defineProperty(exports, "scrubDetectors", { enumerable: true, get: function () { return scrub_1.scrubDetectors; } });
|
|
33
|
+
// data_classification enum (screening SC-0 S8) — shared by the SDK save gate,
|
|
34
|
+
// the server ingest validator, and the DB CHECK so the three cannot drift.
|
|
35
|
+
var classification_1 = require("./classification");
|
|
36
|
+
Object.defineProperty(exports, "DATA_CLASSIFICATIONS", { enumerable: true, get: function () { return classification_1.DATA_CLASSIFICATIONS; } });
|
|
37
|
+
Object.defineProperty(exports, "SENSITIVE_CLASSIFICATIONS", { enumerable: true, get: function () { return classification_1.SENSITIVE_CLASSIFICATIONS; } });
|
|
38
|
+
Object.defineProperty(exports, "isDataClassification", { enumerable: true, get: function () { return classification_1.isDataClassification; } });
|
|
39
|
+
Object.defineProperty(exports, "normalizeClassification", { enumerable: true, get: function () { return classification_1.normalizeClassification; } });
|
|
31
40
|
var taint_1 = require("./taint");
|
|
32
41
|
Object.defineProperty(exports, "computeDownstreamClosure", { enumerable: true, get: function () { return taint_1.computeDownstreamClosure; } });
|
|
33
42
|
Object.defineProperty(exports, "TAINT_DEFAULT_MAX_DEPTH", { enumerable: true, get: function () { return taint_1.TAINT_DEFAULT_MAX_DEPTH; } });
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* v1 wire, zero new rows, zero behaviour change (spec §1.4).
|
|
20
20
|
*/
|
|
21
21
|
import type { ArtifactEvaluationRow, RunRow, StepRow } from "../types/telemetry";
|
|
22
|
+
import type { RunMetaV1 } from "../telemetry/attempt-meta";
|
|
22
23
|
/** The narrow buffer the run/artifact namespace writes through — the local
|
|
23
24
|
* telemetry store satisfies it. Kept narrow so this module depends on the row
|
|
24
25
|
* shapes, not the whole store surface (and cannot reach captures). */
|
|
@@ -43,7 +44,15 @@ export interface RunStartOptions {
|
|
|
43
44
|
* counted, logged skip. Set by the caller or derived from a route's
|
|
44
45
|
* `require: zero_retention`. */
|
|
45
46
|
readonly zeroRetention?: boolean;
|
|
47
|
+
/** The run metadata envelope (WI-1, spec §3) — pipeline sha, config hash,
|
|
48
|
+
* trigger, actor, input hash. `pipeline_sha` AUTO-FILLS from git when the
|
|
49
|
+
* caller leaves it unset (never fails the run — {@link resolvePipelineSha} is
|
|
50
|
+
* try/catch'd). Absent ⇒ the run still auto-fills a git sha when one resolves,
|
|
51
|
+
* else `runs.meta` is null. */
|
|
52
|
+
readonly meta?: RunMetaV1;
|
|
46
53
|
}
|
|
54
|
+
/** Test-only: clear the once-per-process RunMeta-sanitize warning latch. */
|
|
55
|
+
export declare function resetRunMetaWarningsForTest(): void;
|
|
47
56
|
/** One ground-truth step attempt the run loop asks the context to record. The
|
|
48
57
|
* context assigns `attempt_no` per step key so the caller need not track it. */
|
|
49
58
|
export interface GroundTruthStepInput {
|
|
@@ -56,6 +65,8 @@ export interface GroundTruthStepInput {
|
|
|
56
65
|
}
|
|
57
66
|
export interface ActiveRunContext {
|
|
58
67
|
readonly runId: string;
|
|
68
|
+
/** The `episodeKey` given to run.start/run.scope, or null (RC-1). */
|
|
69
|
+
readonly episodeKey: string | null;
|
|
59
70
|
/** Trace id adopted from a traceparent at run.start, if any (chunk B use). */
|
|
60
71
|
readonly traceId: string | null;
|
|
61
72
|
/** Zero-retention gate (chunk B): true ⇒ artifact.save refuses fail-closed. */
|
|
@@ -75,15 +86,26 @@ export interface ActiveRunContext {
|
|
|
75
86
|
* `artifact.save` without an explicit `stepKey` attaches to (G1 spec §3). Set
|
|
76
87
|
* by both `nextStepKey` (auto-steps, `@step` scopes) and `emitGroundTruthStep`
|
|
77
88
|
* (a raw-lane call with a caller-supplied key that never minted). Null before
|
|
78
|
-
* any step in this run. NOTE: a single mutable
|
|
79
|
-
*
|
|
80
|
-
*
|
|
89
|
+
* any step in this run. NOTE: the ambient key is a single mutable "most recent
|
|
90
|
+
* step" on this context, so within ONE run's parallel step waves only an
|
|
91
|
+
* explicit `stepKey` (routed `RunOptions.stepKey` / raw `RawRunInput.stepKey`,
|
|
92
|
+
* or a `tags.step`) prevents cross-attribution — the ambient key alone races.
|
|
93
|
+
* (`run.scope()` gives each concurrent run its own context, so it separates
|
|
94
|
+
* DISTINCT runs, not overlapping steps within one run.) */
|
|
81
95
|
currentStepKey(): string | null;
|
|
82
96
|
/** Record one ground-truth step attempt (the rig.run auto-step). attempt_no is
|
|
83
97
|
* assigned here, per step key. Fail-open — a buffer error is logged, dropped,
|
|
84
98
|
* and never thrown into the run loop. Marks its key as the ambient step. */
|
|
85
99
|
emitGroundTruthStep(input: GroundTruthStepInput): void;
|
|
86
100
|
}
|
|
101
|
+
/** RC-1: the `run_id` tag value an active run context stamps on every attempt
|
|
102
|
+
* row of BOTH lanes when the caller supplied none — the run's `episodeKey`
|
|
103
|
+
* (what the `/projects` tree joins on) or, without one, the run's id. Never
|
|
104
|
+
* overrides a caller-supplied `run_id`; no context ⇒ tags unchanged. */
|
|
105
|
+
export declare function withRunIdTag<T extends {
|
|
106
|
+
readonly run_id?: string;
|
|
107
|
+
readonly [key: string]: string | undefined;
|
|
108
|
+
}>(tags: T, ctx: ActiveRunContext | null): T;
|
|
87
109
|
/** The active run context, or null when none is set (namespace disabled, or no
|
|
88
110
|
* run.start on this async path). Read by the run loop's auto-step seam. */
|
|
89
111
|
export declare function getActiveRunContext(): ActiveRunContext | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-context.d.ts","sourceRoot":"","sources":["../../src/artifacts/run-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"run-context.d.ts","sourceRoot":"","sources":["../../src/artifacts/run-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3D;;sEAEsE;AACtE,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEzC,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,mEAAmE;IACnE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;wEAEoE;IACpE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;oCAGgC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC;;;;mCAI+B;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;CAC3B;AA4CD,4EAA4E;AAC5E,wBAAgB,2BAA2B,IAAI,IA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AAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACnE;AASD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;qFAEiF;IACjF,QAAQ,CAAC,aAAa,CAAC,EAAE;QAAE,wBAAwB,CAAC,GAAG,EAAE,qBAAqB,GAAG,IAAI,CAAA;KAAE,CAAC;CACzF,GAAG,YAAY,CAwLf"}
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
* v1 wire, zero new rows, zero behaviour change (spec §1.4).
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.resetRunMetaWarningsForTest = resetRunMetaWarningsForTest;
|
|
24
|
+
exports.withRunIdTag = withRunIdTag;
|
|
23
25
|
exports.getActiveRunContext = getActiveRunContext;
|
|
24
26
|
exports.isValidStepKey = isValidStepKey;
|
|
25
27
|
exports.resolveStepKey = resolveStepKey;
|
|
@@ -28,7 +30,61 @@ exports.createRunNamespace = createRunNamespace;
|
|
|
28
30
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
29
31
|
const node_crypto_1 = require("node:crypto");
|
|
30
32
|
const otel_map_1 = require("../telemetry/otel-map");
|
|
33
|
+
const attempt_meta_1 = require("../telemetry/attempt-meta");
|
|
34
|
+
const attempt_meta_2 = require("../telemetry/attempt-meta");
|
|
35
|
+
/** Once-per-process latch for the run-envelope sanitize warning (Ruling A,
|
|
36
|
+
* PR #262). Mirrors {@link warnedStepKeys}: a dropped field is named ONCE, so a
|
|
37
|
+
* mislabelled `actor` teaches without spamming the run loop. */
|
|
38
|
+
const warnedRunMetaFields = new Set();
|
|
39
|
+
/**
|
|
40
|
+
* Build a run's `RunMeta@v1` (spec §3): the caller's envelope with
|
|
41
|
+
* `pipeline_sha` auto-filled from git when unset, then SANITIZED at the same
|
|
42
|
+
* boundary the wire is (Ruling A, PR #262) — every string field must be an
|
|
43
|
+
* enum/identifier/hash (≤128 chars, no whitespace), so a free-text `actor`
|
|
44
|
+
* ("Jane Doe") is DROPPED, counted, and named in one once-per-process warning,
|
|
45
|
+
* never smuggled into `runs.meta`. Returns null only when the caller supplied no
|
|
46
|
+
* meta AND no sha resolves — a plain `run.start()` in a git tree still stamps the
|
|
47
|
+
* sha. NEVER throws (resolvePipelineSha + sanitizeMetaForWire are both safe); the
|
|
48
|
+
* recorded run row is byte-identical to the un-sanitized path for a clean envelope.
|
|
49
|
+
*/
|
|
50
|
+
function buildRunMeta(meta) {
|
|
51
|
+
const sha = meta?.pipeline_sha ?? (0, attempt_meta_2.resolvePipelineSha)();
|
|
52
|
+
if (meta === undefined && sha === undefined)
|
|
53
|
+
return null;
|
|
54
|
+
const merged = {
|
|
55
|
+
v: 1,
|
|
56
|
+
...(meta ?? {}),
|
|
57
|
+
...(sha !== undefined ? { pipeline_sha: sha } : {}),
|
|
58
|
+
};
|
|
59
|
+
const { meta: cleaned, dropped } = (0, attempt_meta_1.sanitizeMetaForWire)(merged);
|
|
60
|
+
if (dropped > 0) {
|
|
61
|
+
// RunMeta is flat, so a dropped string is a named top-level field (e.g.
|
|
62
|
+
// `actor`). Name each once — instrumentation teaches, never throws.
|
|
63
|
+
for (const key of Object.keys(merged)) {
|
|
64
|
+
if (typeof merged[key] === "string" && (cleaned === undefined || !(key in cleaned)) && !warnedRunMetaFields.has(key)) {
|
|
65
|
+
warnedRunMetaFields.add(key);
|
|
66
|
+
const tip = key === "actor" ? " `actor` must be an opaque identifier, not a display name." : "";
|
|
67
|
+
console.warn(`[modelrig run] RunMeta.${key} is not metadata-safe (an enum/identifier/hash: ≤128 chars, no ` +
|
|
68
|
+
`whitespace) — dropped from runs.meta.${tip}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return (cleaned ?? { v: 1 });
|
|
73
|
+
}
|
|
74
|
+
/** Test-only: clear the once-per-process RunMeta-sanitize warning latch. */
|
|
75
|
+
function resetRunMetaWarningsForTest() {
|
|
76
|
+
warnedRunMetaFields.clear();
|
|
77
|
+
}
|
|
31
78
|
const storage = new node_async_hooks_1.AsyncLocalStorage();
|
|
79
|
+
/** RC-1: the `run_id` tag value an active run context stamps on every attempt
|
|
80
|
+
* row of BOTH lanes when the caller supplied none — the run's `episodeKey`
|
|
81
|
+
* (what the `/projects` tree joins on) or, without one, the run's id. Never
|
|
82
|
+
* overrides a caller-supplied `run_id`; no context ⇒ tags unchanged. */
|
|
83
|
+
function withRunIdTag(tags, ctx) {
|
|
84
|
+
if (ctx === null || (typeof tags.run_id === "string" && tags.run_id !== ""))
|
|
85
|
+
return tags;
|
|
86
|
+
return { ...tags, run_id: ctx.episodeKey ?? ctx.runId };
|
|
87
|
+
}
|
|
32
88
|
/** The active run context, or null when none is set (namespace disabled, or no
|
|
33
89
|
* run.start on this async path). Read by the run loop's auto-step seam. */
|
|
34
90
|
function getActiveRunContext() {
|
|
@@ -99,6 +155,7 @@ function createRunNamespace(deps) {
|
|
|
99
155
|
const inertHandle = { runId: "", end() { }, evaluate() { } };
|
|
100
156
|
function buildContext(startRow, traceId, zeroRetention) {
|
|
101
157
|
const runId = startRow.id;
|
|
158
|
+
const episodeKey = startRow.episodeKey;
|
|
102
159
|
const attemptByStep = new Map();
|
|
103
160
|
const loaded = new Set();
|
|
104
161
|
let stepSeq = 0;
|
|
@@ -107,6 +164,7 @@ function createRunNamespace(deps) {
|
|
|
107
164
|
let lastStepKey = null;
|
|
108
165
|
return {
|
|
109
166
|
runId,
|
|
167
|
+
episodeKey,
|
|
110
168
|
traceId,
|
|
111
169
|
zeroRetention,
|
|
112
170
|
ended: false,
|
|
@@ -167,6 +225,9 @@ function createRunNamespace(deps) {
|
|
|
167
225
|
startedAt: new Date().toISOString(),
|
|
168
226
|
endedAt: null,
|
|
169
227
|
status: "running",
|
|
228
|
+
// WI-1 (spec §3): the run envelope, git-sha auto-filled. endContext spreads
|
|
229
|
+
// ...ctx.startRow, so the terminal projection re-exports the same meta.
|
|
230
|
+
meta: buildRunMeta(opts.meta),
|
|
170
231
|
};
|
|
171
232
|
const traceId = opts.traceparent !== undefined
|
|
172
233
|
? ((0, otel_map_1.parseTraceparent)(opts.traceparent)?.traceId ?? null)
|
|
@@ -20,7 +20,17 @@
|
|
|
20
20
|
* `detect` result as a guarantee of no PII.
|
|
21
21
|
*
|
|
22
22
|
* NEVER logs a matched value. Findings are `{type, count}` only.
|
|
23
|
+
*
|
|
24
|
+
* ── SHARED DETECTOR INTERFACE (screening review A1, 2026-08-22) ─────────────
|
|
25
|
+
* The same patterns are ALSO exposed as span-producing `Detector`s
|
|
26
|
+
* (`detectSpans`, `scrubDetectors`) so the mask (CS-1) and screen (SC-1) lanes
|
|
27
|
+
* reuse this ONE corpus instead of twinning it (spec docs/ModelRig/screening §3;
|
|
28
|
+
* S1: extend, don't twin). `scrubContent`'s behaviour is unchanged — the span
|
|
29
|
+
* exports are additive and share the same DETECTORS table, so a matched value
|
|
30
|
+
* never leaves the process there either (a span is offsets + type + confidence,
|
|
31
|
+
* never a value).
|
|
23
32
|
*/
|
|
33
|
+
import type { DetectionSpan, Detector } from "../detect/detector";
|
|
24
34
|
export type ScrubMode = "off" | "detect" | "redact" | "block";
|
|
25
35
|
/** A finding is a COUNT by type — never a value (the load-bearing invariant). */
|
|
26
36
|
export interface ScrubFinding {
|
|
@@ -57,4 +67,20 @@ export declare function luhnValid(digits: string): boolean;
|
|
|
57
67
|
* Never returns or logs a matched value.
|
|
58
68
|
*/
|
|
59
69
|
export declare function scrubContent(text: string, mode: ScrubMode): ScrubResult;
|
|
70
|
+
/**
|
|
71
|
+
* Detect scrub v1 spans across ALL patterns, sorted by start offset. Deterministic
|
|
72
|
+
* (confidence 1). Offsets index into the exact `text` passed. Overlap resolution
|
|
73
|
+
* (e.g. PAN vs phone) is the CONSUMER's job (CS-1 §4 "earlier stages win") — this
|
|
74
|
+
* reports every pattern's raw hits, never a value.
|
|
75
|
+
*/
|
|
76
|
+
export declare function detectSpans(text: string): DetectionSpan[];
|
|
77
|
+
/**
|
|
78
|
+
* The scrub v1 patterns presented as the shared `Detector` contract
|
|
79
|
+
* (`src/detect/detector.ts`) — one detector per type, `kind: "deterministic"`,
|
|
80
|
+
* `confidence: 1`. The mask (CS-1) and screen (SC-1) lanes consume these so all
|
|
81
|
+
* three policies (`mask` / `scrub` / `screen`) run over ONE detection engine.
|
|
82
|
+
* The `source`/`tier` on the input are ignored by the deterministic PII patterns
|
|
83
|
+
* (they scan any tier); a tier-aware detector would branch on them.
|
|
84
|
+
*/
|
|
85
|
+
export declare function scrubDetectors(): Detector[];
|
|
60
86
|
//# sourceMappingURL=scrub.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrub.d.ts","sourceRoot":"","sources":["../../src/artifacts/scrub.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scrub.d.ts","sourceRoot":"","sources":["../../src/artifacts/scrub.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAkB,aAAa,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAElF,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE9D,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAC3C;iEAC6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;0EAG0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;CAC5C;AAED;;kFAEkF;AAClF,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAG,YAAY,CAEjF;AAaD,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAejD;AA0CD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CA6CvE;AAqBD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAIzD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,QAAQ,EAAE,CAS3C"}
|
package/dist/artifacts/scrub.js
CHANGED
|
@@ -21,11 +21,22 @@
|
|
|
21
21
|
* `detect` result as a guarantee of no PII.
|
|
22
22
|
*
|
|
23
23
|
* NEVER logs a matched value. Findings are `{type, count}` only.
|
|
24
|
+
*
|
|
25
|
+
* ── SHARED DETECTOR INTERFACE (screening review A1, 2026-08-22) ─────────────
|
|
26
|
+
* The same patterns are ALSO exposed as span-producing `Detector`s
|
|
27
|
+
* (`detectSpans`, `scrubDetectors`) so the mask (CS-1) and screen (SC-1) lanes
|
|
28
|
+
* reuse this ONE corpus instead of twinning it (spec docs/ModelRig/screening §3;
|
|
29
|
+
* S1: extend, don't twin). `scrubContent`'s behaviour is unchanged — the span
|
|
30
|
+
* exports are additive and share the same DETECTORS table, so a matched value
|
|
31
|
+
* never leaves the process there either (a span is offsets + type + confidence,
|
|
32
|
+
* never a value).
|
|
24
33
|
*/
|
|
25
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
35
|
exports.summarizeScrub = summarizeScrub;
|
|
27
36
|
exports.luhnValid = luhnValid;
|
|
28
37
|
exports.scrubContent = scrubContent;
|
|
38
|
+
exports.detectSpans = detectSpans;
|
|
39
|
+
exports.scrubDetectors = scrubDetectors;
|
|
29
40
|
/** Build the persisted summary from a scrub result. The only producer of the
|
|
30
41
|
* `artifacts.scrub` value, so the counts-not-values invariant lives in one
|
|
31
42
|
* place — it simply forwards `ScrubResult.findings`, which are already counts. */
|
|
@@ -137,3 +148,45 @@ function scrubContent(text, mode) {
|
|
|
137
148
|
// detect (or block with no findings): upload verbatim, report counts.
|
|
138
149
|
return { findings, text, blocked: false };
|
|
139
150
|
}
|
|
151
|
+
// ── Shared Detector interface (screening review A1) ─────────────────────────
|
|
152
|
+
// Span-producing views over the SAME `DETECTORS` table. Additive: `scrubContent`
|
|
153
|
+
// above is untouched, and these never surface a matched value (a span is offsets
|
|
154
|
+
// + type + confidence, per the load-bearing invariant).
|
|
155
|
+
/** Spans for one pattern in `text` — offsets + type + confidence 1. A fresh
|
|
156
|
+
* RegExp per call keeps the /g `lastIndex` from leaking across calls. */
|
|
157
|
+
function spansForPattern(det, text) {
|
|
158
|
+
const re = new RegExp(det.re.source, det.re.flags);
|
|
159
|
+
const spans = [];
|
|
160
|
+
for (const m of text.matchAll(re)) {
|
|
161
|
+
const value = m[0];
|
|
162
|
+
if (det.accept && !det.accept(value))
|
|
163
|
+
continue;
|
|
164
|
+
const start = m.index ?? 0;
|
|
165
|
+
spans.push({ start, end: start + value.length, type: det.type, confidence: 1 });
|
|
166
|
+
}
|
|
167
|
+
return spans;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Detect scrub v1 spans across ALL patterns, sorted by start offset. Deterministic
|
|
171
|
+
* (confidence 1). Offsets index into the exact `text` passed. Overlap resolution
|
|
172
|
+
* (e.g. PAN vs phone) is the CONSUMER's job (CS-1 §4 "earlier stages win") — this
|
|
173
|
+
* reports every pattern's raw hits, never a value.
|
|
174
|
+
*/
|
|
175
|
+
function detectSpans(text) {
|
|
176
|
+
return DETECTORS.flatMap((det) => spansForPattern(det, text)).sort((a, b) => a.start - b.start || a.end - b.end);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The scrub v1 patterns presented as the shared `Detector` contract
|
|
180
|
+
* (`src/detect/detector.ts`) — one detector per type, `kind: "deterministic"`,
|
|
181
|
+
* `confidence: 1`. The mask (CS-1) and screen (SC-1) lanes consume these so all
|
|
182
|
+
* three policies (`mask` / `scrub` / `screen`) run over ONE detection engine.
|
|
183
|
+
* The `source`/`tier` on the input are ignored by the deterministic PII patterns
|
|
184
|
+
* (they scan any tier); a tier-aware detector would branch on them.
|
|
185
|
+
*/
|
|
186
|
+
function scrubDetectors() {
|
|
187
|
+
return DETECTORS.map((det) => ({
|
|
188
|
+
id: `scrub:${det.type}@v1`,
|
|
189
|
+
kind: "deterministic",
|
|
190
|
+
detect: (input) => Promise.resolve(spansForPattern(det, input.text)),
|
|
191
|
+
}));
|
|
192
|
+
}
|
package/dist/artifacts/step.d.ts
CHANGED
|
@@ -14,6 +14,15 @@
|
|
|
14
14
|
* active run context (chunk B attributes artifact save/load lineage to it) and
|
|
15
15
|
* runs the body; it does not persist a row until it has a valid reference.
|
|
16
16
|
*
|
|
17
|
+
* ── AMBIENT STEP KEY (G1) ─────────────────────────────────────────────────
|
|
18
|
+
* Entering a `@step` / `step()` scope MINTS a unique key (`label#n`) and sets it
|
|
19
|
+
* as the run context's AMBIENT step. An `artifact.save` with no explicit
|
|
20
|
+
* `stepKey` attaches to that ambient key — not only for saves INSIDE the scope,
|
|
21
|
+
* but for every save AFTER it too, until the next step mints a new ambient key
|
|
22
|
+
* (the ambient key is a running "most recent step", not a lexical bracket). So a
|
|
23
|
+
* post-step save lands on the step just run; to detach it, open the next step or
|
|
24
|
+
* pass an explicit `stepKey`.
|
|
25
|
+
*
|
|
17
26
|
* Instrumentation never changes the wrapped function's return value, and never
|
|
18
27
|
* throws into it — a disabled or absent run context just runs the body.
|
|
19
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/artifacts/step.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/artifacts/step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAOnD"}
|
package/dist/artifacts/step.js
CHANGED
|
@@ -15,6 +15,15 @@
|
|
|
15
15
|
* active run context (chunk B attributes artifact save/load lineage to it) and
|
|
16
16
|
* runs the body; it does not persist a row until it has a valid reference.
|
|
17
17
|
*
|
|
18
|
+
* ── AMBIENT STEP KEY (G1) ─────────────────────────────────────────────────
|
|
19
|
+
* Entering a `@step` / `step()` scope MINTS a unique key (`label#n`) and sets it
|
|
20
|
+
* as the run context's AMBIENT step. An `artifact.save` with no explicit
|
|
21
|
+
* `stepKey` attaches to that ambient key — not only for saves INSIDE the scope,
|
|
22
|
+
* but for every save AFTER it too, until the next step mints a new ambient key
|
|
23
|
+
* (the ambient key is a running "most recent step", not a lexical bracket). So a
|
|
24
|
+
* post-step save lands on the step just run; to detach it, open the next step or
|
|
25
|
+
* pass an explicit `stepKey`.
|
|
26
|
+
*
|
|
18
27
|
* Instrumentation never changes the wrapped function's return value, and never
|
|
19
28
|
* throws into it — a disabled or absent run context just runs the body.
|
|
20
29
|
*/
|
package/dist/bakeoff/engine.d.ts
CHANGED
|
@@ -12,8 +12,14 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { CaptureStore } from "../telemetry/capture";
|
|
14
14
|
import type { RunDeps } from "../run/run";
|
|
15
|
+
import type { CandidateSpec, ObjectiveMode, RouteBundle } from "../types/route";
|
|
16
|
+
import type { QualityGate } from "../types/quality";
|
|
15
17
|
import type { ArmSamples, KeepOutputsMode } from "./samples";
|
|
16
|
-
import type { BakeoffArtifact, VariantMetrics } from "./types";
|
|
18
|
+
import type { BakeoffArtifact, BakeoffObjective, VariantMetrics } from "./types";
|
|
19
|
+
/** The arm name carrying the reference (ceiling) metrics. Reserved — a user
|
|
20
|
+
* variant may not be named this (they cannot start a name with "__"; and it is
|
|
21
|
+
* never in `req.variants`). */
|
|
22
|
+
export declare const REFERENCE_ARM = "__reference__";
|
|
17
23
|
/** Sink for retained review samples (addendum A3). The engine assembles the
|
|
18
24
|
* arms to persist (incumbent + winner, or all); the caller — createRig with
|
|
19
25
|
* the service-role config — does the truncation + PostgREST insert. Keeps
|
|
@@ -34,11 +40,40 @@ export interface BakeoffRequest {
|
|
|
34
40
|
* winning challenger; "all" = every arm. Undefined = keep nothing (the
|
|
35
41
|
* default pure-metrics path). Requires a samplesSink to persist. */
|
|
36
42
|
readonly keepOutputs?: KeepOutputsMode;
|
|
43
|
+
/** RB-1: objective-mode override (CLI `--objective`). Absent ⇒ the route's
|
|
44
|
+
* `objective.mode`, else quality-first (spec §3 default). */
|
|
45
|
+
readonly objectiveMode?: ObjectiveMode;
|
|
46
|
+
/** RB-1: resolver for `reference: auto` → a concrete declared candidate. The
|
|
47
|
+
* rig injects a registry-backed resolver (bakeoff/reference.ts); absent ⇒ an
|
|
48
|
+
* `auto` reference cannot be resolved and no reference arm runs. */
|
|
49
|
+
readonly resolveReferenceAuto?: (route: RouteBundle) => CandidateSpec | null;
|
|
50
|
+
/** RB-1: eval-case expected values keyed by captureId (from-eval-cases path);
|
|
51
|
+
* feeds quality tier 1. */
|
|
52
|
+
readonly expected?: ReadonlyMap<string, {
|
|
53
|
+
readonly value: unknown;
|
|
54
|
+
}>;
|
|
55
|
+
/** Q1 quality gate (spec §4.2): scored on every replayed sample to populate
|
|
56
|
+
* valueAccuracy + the quality pass rate, unlocking computeProposal's cost-first
|
|
57
|
+
* third clause. A function, so it rides `rig.bakeoff` (programmatic) only — the
|
|
58
|
+
* `modelrig bakeoff` CLI cannot carry one until Q2's declared judge. When a
|
|
59
|
+
* route also declares a `bakeoff.judge`, the SDK gate wins the value tier (both
|
|
60
|
+
* are caller-quality signals; F5 deterministic checks still run first). */
|
|
61
|
+
readonly qualityGate?: QualityGate;
|
|
37
62
|
}
|
|
38
63
|
export declare function runBakeoff(deps: RunDeps, captures: CaptureStore, req: BakeoffRequest, samplesSink?: BakeoffSamplesSink): Promise<BakeoffArtifact>;
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
export
|
|
64
|
+
/** Objective context for the gate (RB-1). Absent ⇒ the legacy cost-first path
|
|
65
|
+
* (byte-identical to pre-RB-1, so the existing goldens hold). */
|
|
66
|
+
export interface ProposalContext {
|
|
67
|
+
readonly objective?: BakeoffObjective;
|
|
68
|
+
/** The reference arm's name — excluded from the challenger set. */
|
|
69
|
+
readonly referenceVariant?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Winner among gate-passing challengers; null when nobody beats the incumbent.
|
|
73
|
+
* Exported for direct unit testing. `ctx` absent OR `ctx.objective` absent ⇒ the
|
|
74
|
+
* legacy cost-first gate (goldens). Otherwise per the objective's mode.
|
|
75
|
+
*/
|
|
76
|
+
export declare function computeProposal(requested: readonly string[], metrics: readonly VariantMetrics[], ctx?: ProposalContext): BakeoffArtifact["proposal"];
|
|
42
77
|
export interface BakeoffMirrorConfig {
|
|
43
78
|
readonly supabaseUrl: string;
|
|
44
79
|
readonly serviceRoleKey: string;
|
|
@@ -49,4 +84,11 @@ export interface BakeoffMirrorConfig {
|
|
|
49
84
|
* Same PostgREST transport pattern as the telemetry exporter; captures have
|
|
50
85
|
* no cloud surface — ONLY aggregate metrics travel. */
|
|
51
86
|
export declare function mirrorBakeoff(artifact: BakeoffArtifact, config: BakeoffMirrorConfig): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* The proposal-evidence jsonb for a bake-off artifact (near-optimal spec §4.6) —
|
|
89
|
+
* the winning variant, the RB-1 objective/reference/regret/quality_metric, and a
|
|
90
|
+
* per-arm matrix (with per-arm regret). Built here so the CLI stays thin; the PR
|
|
91
|
+
* body reads these fields back off `proposal.evidence`. ZERO DDL — freeform jsonb.
|
|
92
|
+
*/
|
|
93
|
+
export declare function bakeoffEvidence(artifact: BakeoffArtifact, spentUsd: number): Record<string, unknown>;
|
|
52
94
|
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/bakeoff/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/bakeoff/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAgB,MAAM,gBAAgB,CAAC;AAM9F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAmC,cAAc,EAAE,MAAM,SAAS,CAAC;AAElH;;+BAE+B;AAC/B,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C;;;g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