modelrig 0.4.0 → 0.6.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 (189) hide show
  1. package/CHANGELOG.md +238 -0
  2. package/README.md +65 -3
  3. package/dist/adapters/anthropic.d.ts.map +1 -1
  4. package/dist/adapters/anthropic.js +36 -7
  5. package/dist/adapters/attempt-meta-map.d.ts +63 -0
  6. package/dist/adapters/attempt-meta-map.d.ts.map +1 -0
  7. package/dist/adapters/attempt-meta-map.js +154 -0
  8. package/dist/adapters/deepseek.d.ts.map +1 -1
  9. package/dist/adapters/deepseek.js +25 -2
  10. package/dist/adapters/gemini.d.ts +39 -0
  11. package/dist/adapters/gemini.d.ts.map +1 -1
  12. package/dist/adapters/gemini.js +82 -4
  13. package/dist/adapters/grok.d.ts.map +1 -1
  14. package/dist/adapters/grok.js +25 -2
  15. package/dist/adapters/openai-compat.d.ts.map +1 -1
  16. package/dist/adapters/openai-compat.js +25 -2
  17. package/dist/adapters/openai-stream.d.ts +2 -0
  18. package/dist/adapters/openai-stream.d.ts.map +1 -1
  19. package/dist/adapters/openai-stream.js +23 -3
  20. package/dist/adapters/openai.d.ts.map +1 -1
  21. package/dist/adapters/openai.js +36 -6
  22. package/dist/artifacts/artifact.d.ts +3 -2
  23. package/dist/artifacts/artifact.d.ts.map +1 -1
  24. package/dist/artifacts/artifact.js +35 -9
  25. package/dist/artifacts/classification.d.ts +27 -0
  26. package/dist/artifacts/classification.d.ts.map +1 -0
  27. package/dist/artifacts/classification.js +38 -0
  28. package/dist/artifacts/index.d.ts +3 -1
  29. package/dist/artifacts/index.d.ts.map +1 -1
  30. package/dist/artifacts/index.js +10 -1
  31. package/dist/artifacts/run-context.d.ts +33 -2
  32. package/dist/artifacts/run-context.d.ts.map +1 -1
  33. package/dist/artifacts/run-context.js +95 -1
  34. package/dist/artifacts/scrub.d.ts +26 -0
  35. package/dist/artifacts/scrub.d.ts.map +1 -1
  36. package/dist/artifacts/scrub.js +53 -0
  37. package/dist/artifacts/step.d.ts +9 -0
  38. package/dist/artifacts/step.d.ts.map +1 -1
  39. package/dist/artifacts/step.js +9 -0
  40. package/dist/bakeoff/engine.d.ts +46 -4
  41. package/dist/bakeoff/engine.d.ts.map +1 -1
  42. package/dist/bakeoff/engine.js +269 -19
  43. package/dist/bakeoff/eval-cases.d.ts +5 -0
  44. package/dist/bakeoff/eval-cases.d.ts.map +1 -1
  45. package/dist/bakeoff/eval-cases.js +3 -0
  46. package/dist/bakeoff/judge.d.ts +39 -0
  47. package/dist/bakeoff/judge.d.ts.map +1 -0
  48. package/dist/bakeoff/judge.js +102 -0
  49. package/dist/bakeoff/quality.d.ts +44 -0
  50. package/dist/bakeoff/quality.d.ts.map +1 -0
  51. package/dist/bakeoff/quality.js +126 -0
  52. package/dist/bakeoff/reference.d.ts +34 -0
  53. package/dist/bakeoff/reference.d.ts.map +1 -0
  54. package/dist/bakeoff/reference.js +68 -0
  55. package/dist/bakeoff/replay.d.ts +25 -0
  56. package/dist/bakeoff/replay.d.ts.map +1 -1
  57. package/dist/bakeoff/replay.js +65 -2
  58. package/dist/bakeoff/report.d.ts +8 -1
  59. package/dist/bakeoff/report.d.ts.map +1 -1
  60. package/dist/bakeoff/report.js +83 -12
  61. package/dist/bakeoff/samples.d.ts +35 -2
  62. package/dist/bakeoff/samples.d.ts.map +1 -1
  63. package/dist/bakeoff/samples.js +67 -6
  64. package/dist/bakeoff/stats.d.ts +17 -1
  65. package/dist/bakeoff/stats.d.ts.map +1 -1
  66. package/dist/bakeoff/stats.js +67 -0
  67. package/dist/bakeoff/types.d.ts +76 -5
  68. package/dist/bakeoff/types.d.ts.map +1 -1
  69. package/dist/bakeoff/types.js +4 -3
  70. package/dist/cli-query.d.ts +14 -0
  71. package/dist/cli-query.d.ts.map +1 -0
  72. package/dist/cli-query.js +59 -0
  73. package/dist/cli.d.ts +2 -1
  74. package/dist/cli.d.ts.map +1 -1
  75. package/dist/cli.js +47 -24
  76. package/dist/config.d.ts +6 -0
  77. package/dist/config.d.ts.map +1 -1
  78. package/dist/config.js +14 -0
  79. package/dist/detect/detector.d.ts +82 -0
  80. package/dist/detect/detector.d.ts.map +1 -0
  81. package/dist/detect/detector.js +23 -0
  82. package/dist/index.d.ts +34 -23
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +49 -12
  85. package/dist/query/analytics.d.ts +84 -0
  86. package/dist/query/analytics.d.ts.map +1 -0
  87. package/dist/query/analytics.js +280 -0
  88. package/dist/query/columns.d.ts +59 -0
  89. package/dist/query/columns.d.ts.map +1 -0
  90. package/dist/query/columns.js +89 -0
  91. package/dist/query/grammar.d.ts +74 -7
  92. package/dist/query/grammar.d.ts.map +1 -1
  93. package/dist/query/grammar.js +179 -71
  94. package/dist/query/saved.d.ts +26 -0
  95. package/dist/query/saved.d.ts.map +1 -0
  96. package/dist/query/saved.js +51 -0
  97. package/dist/registry/select.d.ts +59 -0
  98. package/dist/registry/select.d.ts.map +1 -1
  99. package/dist/registry/select.js +66 -0
  100. package/dist/routes/loader-warnings.d.ts +28 -0
  101. package/dist/routes/loader-warnings.d.ts.map +1 -0
  102. package/dist/routes/loader-warnings.js +56 -0
  103. package/dist/routes/loader.d.ts +1 -11
  104. package/dist/routes/loader.d.ts.map +1 -1
  105. package/dist/routes/loader.js +54 -31
  106. package/dist/routes/objective-loader.d.ts +35 -0
  107. package/dist/routes/objective-loader.d.ts.map +1 -0
  108. package/dist/routes/objective-loader.js +286 -0
  109. package/dist/run/accept.d.ts +43 -0
  110. package/dist/run/accept.d.ts.map +1 -0
  111. package/dist/run/accept.js +65 -0
  112. package/dist/run/cost.d.ts +13 -0
  113. package/dist/run/cost.d.ts.map +1 -1
  114. package/dist/run/cost.js +27 -0
  115. package/dist/run/dispatch.d.ts +24 -1
  116. package/dist/run/dispatch.d.ts.map +1 -1
  117. package/dist/run/dispatch.js +19 -0
  118. package/dist/run/ladder-key.d.ts +4 -0
  119. package/dist/run/ladder-key.d.ts.map +1 -1
  120. package/dist/run/ladder-key.js +3 -0
  121. package/dist/run/quality-gate.d.ts +39 -0
  122. package/dist/run/quality-gate.d.ts.map +1 -0
  123. package/dist/run/quality-gate.js +70 -0
  124. package/dist/run/raw-defaults.d.ts +52 -0
  125. package/dist/run/raw-defaults.d.ts.map +1 -0
  126. package/dist/run/raw-defaults.js +123 -0
  127. package/dist/run/raw.d.ts +12 -0
  128. package/dist/run/raw.d.ts.map +1 -1
  129. package/dist/run/raw.js +107 -8
  130. package/dist/run/record-attempt.d.ts.map +1 -1
  131. package/dist/run/record-attempt.js +22 -1
  132. package/dist/run/resolve.d.ts +17 -1
  133. package/dist/run/resolve.d.ts.map +1 -1
  134. package/dist/run/resolve.js +20 -4
  135. package/dist/run/routing-docs.d.ts.map +1 -1
  136. package/dist/run/routing-docs.js +12 -5
  137. package/dist/run/run.d.ts +7 -1
  138. package/dist/run/run.d.ts.map +1 -1
  139. package/dist/run/run.js +54 -69
  140. package/dist/run/variant.d.ts +43 -0
  141. package/dist/run/variant.d.ts.map +1 -0
  142. package/dist/run/variant.js +86 -0
  143. package/dist/savings/emit.d.ts +33 -0
  144. package/dist/savings/emit.d.ts.map +1 -1
  145. package/dist/savings/emit.js +75 -3
  146. package/dist/settings/index.d.ts +1 -1
  147. package/dist/settings/index.d.ts.map +1 -1
  148. package/dist/settings/index.js +2 -1
  149. package/dist/settings/task-settings.d.ts +10 -0
  150. package/dist/settings/task-settings.d.ts.map +1 -1
  151. package/dist/settings/task-settings.js +17 -0
  152. package/dist/telemetry/attempt-meta.d.ts +178 -0
  153. package/dist/telemetry/attempt-meta.d.ts.map +1 -0
  154. package/dist/telemetry/attempt-meta.js +319 -0
  155. package/dist/telemetry/exporter.d.ts.map +1 -1
  156. package/dist/telemetry/exporter.js +6 -0
  157. package/dist/telemetry/ingest-protocol.d.ts +11 -0
  158. package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
  159. package/dist/telemetry/ingest-protocol.js +3 -0
  160. package/dist/telemetry/otel-map.d.ts +10 -0
  161. package/dist/telemetry/otel-map.d.ts.map +1 -1
  162. package/dist/telemetry/otel-map.js +64 -0
  163. package/dist/telemetry/store-migrations.d.ts.map +1 -1
  164. package/dist/telemetry/store-migrations.js +15 -0
  165. package/dist/telemetry/store.d.ts.map +1 -1
  166. package/dist/telemetry/store.js +25 -7
  167. package/dist/types/failures-teaching.d.ts.map +1 -1
  168. package/dist/types/failures-teaching.js +20 -0
  169. package/dist/types/failures.d.ts +1 -1
  170. package/dist/types/failures.d.ts.map +1 -1
  171. package/dist/types/failures.js +1 -0
  172. package/dist/types/provider.d.ts +9 -0
  173. package/dist/types/provider.d.ts.map +1 -1
  174. package/dist/types/quality.d.ts +41 -0
  175. package/dist/types/quality.d.ts.map +1 -0
  176. package/dist/types/quality.js +12 -0
  177. package/dist/types/route.d.ts +120 -0
  178. package/dist/types/route.d.ts.map +1 -1
  179. package/dist/types/telemetry.d.ts +13 -0
  180. package/dist/types/telemetry.d.ts.map +1 -1
  181. package/dist/validate-cli.d.ts.map +1 -1
  182. package/dist/validate-cli.js +10 -0
  183. package/dist/watch/evaluate.d.ts +27 -1
  184. package/dist/watch/evaluate.d.ts.map +1 -1
  185. package/dist/watch/evaluate.js +13 -0
  186. package/dist/watch/proposals.d.ts +28 -0
  187. package/dist/watch/proposals.d.ts.map +1 -1
  188. package/dist/watch/proposals.js +51 -0
  189. package/package.json +1 -1
@@ -16,6 +16,8 @@ import type { AdapterRequest, AdapterStreamEvent, ProviderId, ServiceTier } from
16
16
  import type { OpenAIToolCallDelta } from "./tool-mapping";
17
17
  /** The permissive chunk shape common to the OpenAI-dialect hosts. */
18
18
  export interface OpenAIDialectChunk {
19
+ readonly id?: string;
20
+ readonly model?: string;
19
21
  readonly service_tier?: string;
20
22
  readonly choices: Array<{
21
23
  readonly delta?: {
@@ -1 +1 @@
1
- {"version":3,"file":"openai-stream.d.ts","sourceRoot":"","sources":["../../src/adapters/openai-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;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C;QACpC,QAAQ,CAAC,qBAAqB,CAAC,EAAE;YAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACrE,QAAQ,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC;QAC1C;;6DAEqD;QACrD,QAAQ,CAAC,oBAAoB,CAAC,EAAE;YAAE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KAC1E,GAAG,IAAI,CAAC;CACV;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,oEAAoE;IACpE,QAAQ,CAAC,iBAAiB,EAAE,SAAS,GAAG,WAAW,CAAC;IACpD,+EAA+E;IAC/E,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,SAAS,EAAE,WAAW,KAAK,WAAW,CAAC;CACrF;AAED;;;;;;GAMG;AACH,wBAAuB,mBAAmB,CACxC,MAAM,EAAE,aAAa,CAAC,kBAAkB,CAAC,EACzC,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,kBAAkB,GACtB,cAAc,CAAC,kBAAkB,CAAC,CAuHpC"}
@@ -15,6 +15,7 @@
15
15
  */
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.streamOpenAIDialect = streamOpenAIDialect;
18
+ const attempt_meta_map_1 = require("./attempt-meta-map");
18
19
  const tool_mapping_1 = require("./tool-mapping");
19
20
  /**
20
21
  * Drain an OpenAI-dialect completion stream into `AdapterStreamEvent`s. Emits a
@@ -34,11 +35,17 @@ async function* streamOpenAIDialect(chunks, req, dispatchedAt, cfg) {
34
35
  let cacheWriteTokens = 0;
35
36
  let responseTier = null;
36
37
  let finishReason = null;
38
+ let responseModel = "";
39
+ let responseId = "";
37
40
  for await (const chunk of chunks) {
38
41
  if (ttfbMs === undefined)
39
42
  ttfbMs = Date.now() - dispatchedAt;
40
43
  if (responseTier === null && chunk.service_tier !== undefined)
41
44
  responseTier = chunk.service_tier;
45
+ if (responseModel === "" && typeof chunk.model === "string")
46
+ responseModel = chunk.model;
47
+ if (responseId === "" && typeof chunk.id === "string")
48
+ responseId = chunk.id;
42
49
  const choice = chunk.choices[0];
43
50
  const content = choice?.delta?.content;
44
51
  if (content) {
@@ -73,6 +80,18 @@ async function* streamOpenAIDialect(chunks, req, dispatchedAt, cfg) {
73
80
  servedTier: cfg.mapServedTier(responseTier, req.requestedTier),
74
81
  ...(ttfbMs !== undefined ? { ttfbMs } : {}),
75
82
  };
83
+ const toolCalls = toolCallAcc.finalize();
84
+ // WI-1: native attempt envelope for the streamed call (streaming: true). Built
85
+ // once, attached to every terminal `final` result below.
86
+ const meta = (0, attempt_meta_map_1.buildAdapterMeta)(cfg.provider, {
87
+ req,
88
+ finishReasonRaw: finishReason,
89
+ refusal: refusalText.length > 0 || finishReason === "content_filter",
90
+ modelSnapshot: responseModel,
91
+ providerRequestId: responseId,
92
+ toolCalls,
93
+ streaming: true,
94
+ });
76
95
  const fail = (message, fixHint) => ({
77
96
  kind: "final",
78
97
  result: {
@@ -85,6 +104,7 @@ async function* streamOpenAIDialect(chunks, req, dispatchedAt, cfg) {
85
104
  ...(fixHint !== undefined ? { fixHint } : {}),
86
105
  },
87
106
  usage,
107
+ meta,
88
108
  },
89
109
  });
90
110
  if (refusalText.length > 0) {
@@ -99,13 +119,13 @@ async function* streamOpenAIDialect(chunks, req, dispatchedAt, cfg) {
99
119
  model: req.candidate.model,
100
120
  },
101
121
  usage,
122
+ meta,
102
123
  },
103
124
  };
104
125
  return;
105
126
  }
106
- const toolCalls = toolCallAcc.finalize();
107
127
  if (toolCalls !== undefined) {
108
- yield { kind: "final", result: { ok: true, text, usage, toolCalls } };
128
+ yield { kind: "final", result: { ok: true, text, usage, toolCalls, meta } };
109
129
  return;
110
130
  }
111
131
  if (text.trim().length === 0) {
@@ -116,5 +136,5 @@ async function* streamOpenAIDialect(chunks, req, dispatchedAt, cfg) {
116
136
  yield fail(`${cfg.provider} output truncated (finish_reason=length)`, "raise maxOutputTokens for this route");
117
137
  return;
118
138
  }
119
- yield { kind: "final", result: { ok: true, text, usage } };
139
+ yield { kind: "final", result: { ok: true, text, usage, meta } };
120
140
  }
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAIV,cAAc,EACd,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMhE,OAAO,KAAK,EAAuB,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAMhG,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAMD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI9D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAe9E;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CA8BxE;AAED,UAAU,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE;QAAE,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAA;KAAE,CAAC;I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Q,CAAC,IAAI,EAAE,aAAa,CAAA;KAAE,GAChC;QACE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;QAC7B,QAAQ,CAAC,WAAW,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;SAAE,CAAC;KACjG,CAAC;IACN,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,kBAAkB,CAuDtF;AAcD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,eAAe,CAsOhF"}
@@ -24,6 +24,7 @@ exports.createOpenAIAdapter = createOpenAIAdapter;
24
24
  const openai_1 = __importDefault(require("openai"));
25
25
  const tool_mapping_1 = require("./tool-mapping");
26
26
  const openai_stream_1 = require("./openai-stream");
27
+ const attempt_meta_map_1 = require("./attempt-meta-map");
27
28
  const sampling_1 = require("./sampling");
28
29
  /** OpenAI's documented flex-eligible allowlist as of 2026-05 (ported).
29
30
  * Mini and nano variants are silently downgraded to default tier. */
@@ -162,6 +163,11 @@ function createOpenAIAdapter(config) {
162
163
  supportsTools: () => true,
163
164
  async call(req) {
164
165
  const model = req.candidate.model;
166
+ // WI-1: the native attempt envelope for this call — set once the signals
167
+ // are known (after the stream, or from the transport error), read by every
168
+ // return via the closure. Absent until then (a pre-signal throw ⇒ null meta
169
+ // downstream, byte-identical run result).
170
+ let attemptMeta;
165
171
  // F1: post-stream failures still billed tokens — attach usage.
166
172
  const fail = (cls, message, fixHint, usage) => ({
167
173
  ok: false,
@@ -173,6 +179,7 @@ function createOpenAIAdapter(config) {
173
179
  ...(fixHint !== undefined ? { fixHint } : {}),
174
180
  },
175
181
  ...(usage !== undefined ? { usage } : {}),
182
+ ...(attemptMeta !== undefined ? { meta: attemptMeta } : {}),
176
183
  });
177
184
  try {
178
185
  const client = new openai_1.default({ apiKey: config.apiKey, timeout: req.timeoutMs });
@@ -191,12 +198,19 @@ function createOpenAIAdapter(config) {
191
198
  let reasoningTokens = 0;
192
199
  let responseTier = null;
193
200
  let finishReason = null;
201
+ // WI-1 native fields: the provider-reported model snapshot + request id.
202
+ let responseModel = "";
203
+ let responseId = "";
194
204
  for await (const chunk of stream) {
195
205
  if (ttfbMs === undefined)
196
206
  ttfbMs = Date.now() - dispatchedAt;
197
207
  if (responseTier === null && chunk.service_tier !== undefined) {
198
208
  responseTier = chunk.service_tier;
199
209
  }
210
+ if (responseModel === "" && typeof chunk.model === "string")
211
+ responseModel = chunk.model;
212
+ if (responseId === "" && typeof chunk.id === "string")
213
+ responseId = chunk.id;
200
214
  const choice = chunk.choices[0];
201
215
  if (choice?.delta?.content)
202
216
  text += choice.delta.content;
@@ -223,17 +237,30 @@ function createOpenAIAdapter(config) {
223
237
  servedTier: mapServedTier(responseTier, req.requestedTier),
224
238
  ...(ttfbMs !== undefined ? { ttfbMs } : {}),
225
239
  };
240
+ // Tool-call turn (spec §4.4): the model chose to call a tool. Surface
241
+ // the normalized calls; text may legitimately be empty — do NOT run the
242
+ // empty/suspicious-short/validation guards below.
243
+ const toolCalls = toolCallAcc.finalize();
244
+ // WI-1: native attempt envelope, built once from this call's signals.
245
+ // refusal derivation: a streamed `refusal` delta OR finish_reason
246
+ // content_filter (documented in attempt-meta-map.ts).
247
+ attemptMeta = (0, attempt_meta_map_1.buildAdapterMeta)("openai", {
248
+ req,
249
+ finishReasonRaw: finishReason,
250
+ refusal: refusalText.length > 0 || finishReason === "content_filter",
251
+ reasoningTokens,
252
+ modelSnapshot: responseModel,
253
+ providerRequestId: responseId,
254
+ toolCalls,
255
+ streaming: false,
256
+ });
226
257
  // Any streamed refusal is terminal for this call, even alongside
227
258
  // partial content — OpenAI's structured-output semantics (ported).
228
259
  if (refusalText.length > 0) {
229
260
  return fail("refusal", `OpenAI refused structured output: ${refusalText.slice(0, 200)}`, undefined, usage);
230
261
  }
231
- // Tool-call turn (spec §4.4): the model chose to call a tool. Surface
232
- // the normalized calls; text may legitimately be empty — do NOT run the
233
- // empty/suspicious-short/validation guards below.
234
- const toolCalls = toolCallAcc.finalize();
235
262
  if (toolCalls !== undefined) {
236
- return { ok: true, text, usage, toolCalls };
263
+ return { ok: true, text, usage, toolCalls, meta: attemptMeta };
237
264
  }
238
265
  const visibleCompletionTokens = Math.max(0, completionTokens - reasoningTokens);
239
266
  if (finishReason === "stop" &&
@@ -249,11 +276,13 @@ function createOpenAIAdapter(config) {
249
276
  if (finishReason === "length" && req.outputSchema !== null) {
250
277
  return fail("content_invalid", "OpenAI structured output truncated (finish_reason=length)", "raise maxOutputTokens for this route", usage);
251
278
  }
252
- return { ok: true, text, usage };
279
+ return { ok: true, text, usage, meta: attemptMeta };
253
280
  }
254
281
  catch (error) {
255
282
  const message = error instanceof Error ? error.message : String(error);
256
283
  const { cls, fixHint } = classifyOpenAIFailure(message);
284
+ // WI-1: a transport/SDK error carries only its coarse status/code.
285
+ attemptMeta = (0, attempt_meta_map_1.transportErrorMeta)(error);
257
286
  return {
258
287
  ok: false,
259
288
  failure: {
@@ -264,6 +293,7 @@ function createOpenAIAdapter(config) {
264
293
  cause: error,
265
294
  ...(fixHint !== undefined ? { fixHint } : {}),
266
295
  },
296
+ meta: attemptMeta,
267
297
  };
268
298
  }
269
299
  },
@@ -39,8 +39,9 @@ export interface ArtifactSaveOptions {
39
39
  /** The pipeline step this artifact belongs to — the semantic grouping key the
40
40
  * console's chain view orders on (E3 spec §2.1). E2 deferred step attribution
41
41
  * ("refined when @step scopes persist, E3"); an EXPLICIT key set by the caller
42
- * is the E3 refinement — safe under parallel step waves where an ambient
43
- * mutable current-step would cross-attribute. Null (absent) ⇒ ungrouped. */
42
+ * is the E3 refinement and stays the safe choice under parallel steps inside
43
+ * ONE run; absent one, the ambient current step (G1) is used — see
44
+ * run-context.ts currentStepKey(). Null (no key, no context) ⇒ ungrouped. */
44
45
  readonly stepKey?: string;
45
46
  /** The step attempt this artifact came from (mirrors steps.attempt_no). Only
46
47
  * meaningful alongside stepKey; null for artifacts saved outside a step. */
@@ -1 +1 @@
1
- {"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../../src/artifacts/artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEnF;4DAC4D;AAC5D,MAAM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnG;8CAC8C;AAC9C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;CAC1C;AAYD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;gFAI4E;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE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 const node_crypto_1 = require("node:crypto");
20
20
  const fingerprint_1 = require("../registry/fingerprint");
21
21
  const run_context_1 = require("./run-context");
22
22
  const scrub_1 = require("./scrub");
23
+ const classification_1 = require("./classification");
24
+ const task_settings_1 = require("../settings/task-settings");
23
25
  /** Map an artifact `type` to a content-type for the object store. */
24
26
  function contentTypeFor(type) {
25
27
  const t = type.toLowerCase();
@@ -166,6 +168,24 @@ function createArtifactApi(deps) {
166
168
  const schema = opts.schema ?? null;
167
169
  const id = (0, node_crypto_1.randomUUID)();
168
170
  const version = opts.supersedes !== undefined ? opts.supersedes.version + 1 : 1;
171
+ // G1 (spec §3): an explicit stepKey wins; absent, the artifact lands in the
172
+ // AMBIENT step — the most recent auto-step in this run context — so
173
+ // `artifact.save` and the run/@step graph compose. Null outside a step (or
174
+ // outside a run context), exactly as before.
175
+ const stepKey = opts.stepKey ?? ctx?.currentStepKey() ?? null;
176
+ // S8-b: validate data_classification against the shared enum. A bad value
177
+ // would fail the DB CHECK (00058) and drop the row at ingest, so catch it
178
+ // here with a teaching warning and drop the LABEL (the artifact still
179
+ // saves — a metadata typo must not lose the artifact). Normalize first so
180
+ // "PHI"/" pii " keep their meaning (and their scrub floor) rather than
181
+ // silently dropping.
182
+ let classification = (0, classification_1.normalizeClassification)(opts.classification);
183
+ if (opts.classification !== undefined && classification !== null && !(0, classification_1.isDataClassification)(classification)) {
184
+ console.warn(`[modelrig artifacts] artifact "${opts.name}" has an unknown data_classification ` +
185
+ `${JSON.stringify(opts.classification)} — label dropped (artifact still saved). ` +
186
+ `fix_hint: use one of ${classification_1.DATA_CLASSIFICATIONS.join(", ")}.`);
187
+ classification = null;
188
+ }
169
189
  // Custody applies only when a rig content policy exists AND the caller left
170
190
  // the bytes to us (a caller-supplied contentRef = their own store; managed
171
191
  // custody must not double-home it).
@@ -173,17 +193,22 @@ function createArtifactApi(deps) {
173
193
  // Scrub is computed HERE (before the row is written) so its counts-only
174
194
  // summary can ride the immutable artifact row (00039). Only when custody
175
195
  // applies; null otherwise (custody off ⇒ nothing was scanned).
176
- const scrubbed = custodyApplies && content !== undefined ? (0, scrub_1.scrubContent)(serialized, content.scrub) : null;
177
- const scrubSummary = scrubbed !== null && content !== undefined ? (0, scrub_1.summarizeScrub)(content.scrub, scrubbed) : null;
196
+ // S8-c: a `pii`/`phi` artifact forces the scrub mode to a floor of
197
+ // `redact`, so PII/PHI content is never uploaded verbatim even when the
198
+ // task's configured mode is `off`/`detect`. A stronger `block` stays.
199
+ const effScrub = content !== undefined ? (0, task_settings_1.effectiveScrubMode)(content.scrub, classification) : null;
200
+ const scrubbed = custodyApplies && content !== undefined && effScrub !== null ? (0, scrub_1.scrubContent)(serialized, effScrub) : null;
201
+ const scrubSummary = scrubbed !== null && effScrub !== null ? (0, scrub_1.summarizeScrub)(effScrub, scrubbed) : null;
178
202
  if (scrubbed !== null)
179
203
  scrubFindings += scrubbed.findings.reduce((n, f) => n + f.count, 0);
180
204
  try {
181
205
  store.recordArtifact({
182
206
  id,
183
207
  runId: ctx?.runId ?? null,
184
- // E3: step attribution is now an explicit caller-supplied key (see
185
- // ArtifactSaveOptions.stepKey). Absent ⇒ null, exactly as before.
186
- stepKey: opts.stepKey ?? null,
208
+ // E3: step attribution is an explicit caller-supplied key; G1 adds the
209
+ // ambient-step fallback (resolved above) so a save with no stepKey joins
210
+ // the current run/@step. Absent both ⇒ null, exactly as before.
211
+ stepKey,
187
212
  attemptNo: opts.attemptNo ?? null,
188
213
  task: opts.task ?? null,
189
214
  name: opts.name,
@@ -195,7 +220,7 @@ function createArtifactApi(deps) {
195
220
  contentRef: opts.contentRef ?? null,
196
221
  contentHash,
197
222
  contentBytes: bytes,
198
- dataClassification: opts.classification ?? null,
223
+ dataClassification: classification,
199
224
  expiresAt: opts.expiresAt ?? null,
200
225
  // Per-row scrub findings ride the original (scanned) row (00039).
201
226
  scrub: scrubSummary,
@@ -230,7 +255,7 @@ function createArtifactApi(deps) {
230
255
  console.warn(`[modelrig artifacts] scrub blocked content for "${opts.name}" ` +
231
256
  `(${scrubbed.findings.length} finding type(s)); metadata + hash kept, no content stored.`);
232
257
  }
233
- else if (content.scrub === "redact" && scrubbed.findings.length > 0 && scrubbed.text !== null) {
258
+ else if (effScrub === "redact" && scrubbed.findings.length > 0 && scrubbed.text !== null) {
234
259
  // Redaction is a SUPERSEDING version (immutability): the original row
235
260
  // keeps its hash and stores NO content; a new version records the
236
261
  // masked content's hash and uploads the masked bytes.
@@ -243,7 +268,8 @@ function createArtifactApi(deps) {
243
268
  store.recordArtifact({
244
269
  id: redactedId,
245
270
  runId: ctx?.runId ?? null,
246
- stepKey: opts.stepKey ?? null,
271
+ // Same ambient-step resolution as the original row it supersedes.
272
+ stepKey,
247
273
  attemptNo: opts.attemptNo ?? null,
248
274
  task: opts.task ?? null,
249
275
  name: opts.name,
@@ -255,7 +281,7 @@ function createArtifactApi(deps) {
255
281
  contentRef: null,
256
282
  contentHash: maskedHash,
257
283
  contentBytes: maskedBytes,
258
- dataClassification: opts.classification ?? null,
284
+ dataClassification: classification,
259
285
  expiresAt: opts.expiresAt ?? null,
260
286
  // Findings ride the original scanned row; the masked version stores
261
287
  // no PII, so its own scrub is null (avoid double-counting).
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The `data_classification` enum — the ONE place the vocabulary is spelled
3
+ * (screening SC-0 S8). Backs three enforcement points that must agree:
4
+ * • the SDK save gate (`artifact.ts` — teaching warn + drop on a bad value),
5
+ * • the server ingest validator (`ingest-artifacts.ts` — enum-only, counted),
6
+ * • the DB CHECK (`00058_artifacts_data_classification_enum.sql`).
7
+ * Keeping the list here (not re-spelled at each site) is what keeps the three
8
+ * from drifting; the migration and this constant are diffed by eye in review.
9
+ *
10
+ * `pii`/`phi` are the SENSITIVE tiers: an artifact tagged either resolves an
11
+ * effective scrub mode of at least `redact` regardless of the task's configured
12
+ * mode (S8-c, `settings/task-settings.ts effectiveScrubMode`). NULL stays a
13
+ * valid "unclassified" state — the column is nullable and the SDK sends null
14
+ * when no classification is given; the enum constrains only NON-null values.
15
+ */
16
+ export declare const DATA_CLASSIFICATIONS: readonly ["public", "internal", "confidential", "pii", "phi"];
17
+ export type DataClassification = (typeof DATA_CLASSIFICATIONS)[number];
18
+ /** The tiers that force the scrub floor (S8-c). A set for O(1) membership. */
19
+ export declare const SENSITIVE_CLASSIFICATIONS: ReadonlySet<string>;
20
+ /** Normalize a caller-supplied classification the way both enforcement sides
21
+ * do BEFORE the enum check — trim and lowercase, so `"PHI"`/`" phi "` resolve to
22
+ * `phi` (and keep their scrub floor) rather than silently dropping. Non-strings
23
+ * return null. */
24
+ export declare function normalizeClassification(value: unknown): string | null;
25
+ /** True when `value` is one of the enum values (after normalization). */
26
+ export declare function isDataClassification(value: unknown): value is DataClassification;
27
+ //# sourceMappingURL=classification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classification.d.ts","sourceRoot":"","sources":["../../src/artifacts/classification.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,oBAAoB,+DAAgE,CAAC;AAElG,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvE,8EAA8E;AAC9E,eAAO,MAAM,yBAAyB,EAAE,WAAW,CAAC,MAAM,CAA2B,CAAC;AAEtF;;;kBAGkB;AAClB,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIrE;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAGhF"}
@@ -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,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,YAAY,EAAE,aAAa,EAAE,MAA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AAC,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"}
@@ -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 {
@@ -68,16 +77,38 @@ export interface ActiveRunContext {
68
77
  takeLoadedIds(): string[];
69
78
  /** Mint a unique step key for ONE rig.run()/@step invocation. Retries of that
70
79
  * invocation reuse the returned key (attempt_no distinguishes them); a later
71
- * invocation gets a fresh key, so two calls never collapse into one step. */
80
+ * invocation gets a fresh key, so two calls never collapse into one step. Also
81
+ * marks the minted key as the ambient step (see currentStepKey). */
72
82
  nextStepKey(label: string): string;
83
+ /** The most recent step key in this context — the ambient step an
84
+ * `artifact.save` without an explicit `stepKey` attaches to (G1 spec §3). Set
85
+ * by both `nextStepKey` (auto-steps, `@step` scopes) and `emitGroundTruthStep`
86
+ * (a raw-lane call with a caller-supplied key that never minted). Null before
87
+ * any step in this run. NOTE: the ambient key is a single mutable "most recent
88
+ * step" on this context, so within ONE run's parallel step waves only an
89
+ * explicit `stepKey` (routed `RunOptions.stepKey` / raw `RawRunInput.stepKey`,
90
+ * or a `tags.step`) prevents cross-attribution — the ambient key alone races.
91
+ * (`run.scope()` gives each concurrent run its own context, so it separates
92
+ * DISTINCT runs, not overlapping steps within one run.) */
93
+ currentStepKey(): string | null;
73
94
  /** Record one ground-truth step attempt (the rig.run auto-step). attempt_no is
74
95
  * assigned here, per step key. Fail-open — a buffer error is logged, dropped,
75
- * and never thrown into the run loop. */
96
+ * and never thrown into the run loop. Marks its key as the ambient step. */
76
97
  emitGroundTruthStep(input: GroundTruthStepInput): void;
77
98
  }
78
99
  /** The active run context, or null when none is set (namespace disabled, or no
79
100
  * run.start on this async path). Read by the run loop's auto-step seam. */
80
101
  export declare function getActiveRunContext(): ActiveRunContext | null;
102
+ /** True when `key` is a valid caller-supplied step key (spec §3). */
103
+ export declare function isValidStepKey(key: string): boolean;
104
+ /** Resolve a ground-truth step key for either lane (spec §3): an explicit
105
+ * caller-supplied key wins, then the `tags.step` convention, else a freshly
106
+ * minted auto key. A caller key is validated `[A-Za-z0-9_.:#-]{1,128}`; an
107
+ * invalid one is warned (once per bad value) and DROPPED to the auto key —
108
+ * instrumentation never throws a telemetry-label error into customer code. */
109
+ export declare function resolveStepKey(explicit: string | undefined, tagStep: string | undefined, auto: () => string): string;
110
+ /** Test-only: clear the once-per-process invalid-stepKey warning latch. */
111
+ export declare function resetStepKeyWarningsForTest(): void;
81
112
  /** A run-level evaluation the caller attaches (E5 chunk V.2) — the run-subject
82
113
  * mirror of ArtifactEvaluateOptions. The subject is the run, so there is no ref. */
83
114
  export interface RunEvaluateOptions {
@@ -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;AAGjF;;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,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