@tangle-network/agent-eval 0.46.0 → 0.48.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 (37) hide show
  1. package/dist/adapters/traceai.d.ts +109 -0
  2. package/dist/adapters/traceai.js +106 -0
  3. package/dist/adapters/traceai.js.map +1 -0
  4. package/dist/campaign/index.d.ts +2 -2
  5. package/dist/campaign/index.js +1 -1
  6. package/dist/chunk-OYI6RZJK.js +80 -0
  7. package/dist/chunk-OYI6RZJK.js.map +1 -0
  8. package/dist/{chunk-HRKOCLQA.js → chunk-XAP6DJZE.js} +1 -1
  9. package/dist/chunk-XAP6DJZE.js.map +1 -0
  10. package/dist/contract/index.d.ts +21 -3
  11. package/dist/contract/index.js +83 -3
  12. package/dist/contract/index.js.map +1 -1
  13. package/dist/hosted/index.d.ts +192 -0
  14. package/dist/hosted/index.js +10 -0
  15. package/dist/hosted/index.js.map +1 -0
  16. package/dist/index.d.ts +6 -5
  17. package/dist/index.js +30 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/matrix/index.d.ts +2 -2
  20. package/dist/multishot/index.d.ts +2 -2
  21. package/dist/openapi.json +1 -1
  22. package/dist/{release-report-BtpgWRI0.d.ts → release-report-DBB8lB1P.d.ts} +1 -1
  23. package/dist/reporting.d.ts +2 -2
  24. package/dist/{researcher-CoJMs2Iz.d.ts → researcher-CHMO56K0.d.ts} +1 -1
  25. package/dist/rl.d.ts +3 -3
  26. package/dist/rl.js +3 -1
  27. package/dist/rl.js.map +1 -1
  28. package/dist/{run-improvement-loop-Bfam3MT1.d.ts → run-improvement-loop-B-L8GgpW.d.ts} +1 -1
  29. package/dist/{sequential-DdV5ShjT.d.ts → sequential-CbFH___X.d.ts} +23 -1
  30. package/dist/{types-DHqkLwEU.d.ts → types-CqPax19X.d.ts} +1 -1
  31. package/dist/verdict-CeEgtjyI.d.ts +32 -0
  32. package/docs/adapters-observability.md +15 -0
  33. package/docs/design/phase-d-rfc.md +125 -0
  34. package/docs/design/substrate-gaps-2026-05-27.md +118 -0
  35. package/docs/hosted-ingest-spec.md +204 -0
  36. package/package.json +22 -31
  37. package/dist/chunk-HRKOCLQA.js.map +0 -1
@@ -0,0 +1,109 @@
1
+ import { TraceSpanEvent, HostedClient } from '../hosted/index.js';
2
+ import '../types-8u72Gc76.js';
3
+
4
+ /**
5
+ * # `@tangle-network/agent-eval/adapters/traceai` — OTel→hosted bridge.
6
+ *
7
+ * Forwards OpenTelemetry-shaped spans (from `future-agi/traceai`, from the
8
+ * OTel SDK directly, or from any library that emits OTel `ReadableSpan`s)
9
+ * into the hosted-tier ingest endpoint via `createHostedClient`.
10
+ *
11
+ * **Why this exists:** future-agi ships the strongest OTel-native
12
+ * instrumentation library in the TypeScript-agent ecosystem. Partners using
13
+ * traceai for tracing should be able to plug it into Tangle Intelligence
14
+ * with one config line — not rebuild OTel emission from scratch. Adapter
15
+ * shape applies equally to any OTel SpanProcessor pipeline.
16
+ *
17
+ * **Pattern:**
18
+ *
19
+ * ```ts
20
+ * import { createHostedClient } from '@tangle-network/agent-eval/hosted'
21
+ * import { createTraceAiBridge } from '@tangle-network/agent-eval/adapters/traceai'
22
+ *
23
+ * const client = createHostedClient({ endpoint, apiKey, tenantId })
24
+ * const bridge = createTraceAiBridge({ client, defaultRunId: substrateRunId })
25
+ *
26
+ * // Wherever your OTel SpanProcessor hands you a finished span:
27
+ * processor.onEnd = (span) => bridge.ingest([span])
28
+ * // …or in a SpanProcessor.onShutdown / batch flush:
29
+ * await bridge.ingest(batchedSpans)
30
+ * ```
31
+ *
32
+ * No `@opentelemetry/*` dependency is declared here — the adapter accepts
33
+ * a structurally-typed `OtelLikeSpan`. This keeps the substrate dep graph
34
+ * lean while remaining compatible with OTel SDK `ReadableSpan` instances
35
+ * and with traceai's emitted spans. If a consumer's span shape differs
36
+ * (e.g. `parentSpanId` as a top-level field rather than via
37
+ * `parentSpanContext()`), the adapter accepts both forms.
38
+ */
39
+
40
+ /**
41
+ * `[seconds, nanoseconds]` — the OTel SDK's `HrTime` shape. Spans emitted
42
+ * by the OTel SDK carry timestamps in this representation; we convert to
43
+ * a single unix-nano number for the wire format.
44
+ */
45
+ type HrTime = [number, number];
46
+ /** Standard OTel `SpanStatusCode` numeric values: 0 = UNSET, 1 = OK, 2 = ERROR. */
47
+ declare const OTEL_STATUS_UNSET = 0;
48
+ declare const OTEL_STATUS_OK = 1;
49
+ declare const OTEL_STATUS_ERROR = 2;
50
+ type OtelAttributeValue = string | number | boolean | null | undefined;
51
+ /**
52
+ * Structural surface compatible with `@opentelemetry/sdk-trace-base`'s
53
+ * `ReadableSpan`. Consumers pass instances they get from their OTel SDK
54
+ * (or from `future-agi/traceai`, which produces spans of this shape).
55
+ */
56
+ interface OtelLikeSpan {
57
+ spanContext: () => {
58
+ traceId: string;
59
+ spanId: string;
60
+ traceFlags?: number;
61
+ };
62
+ /** Set on the span itself by some SDKs (legacy / OTLP-shape). Some SDKs
63
+ * expose the parent via `parentSpanContext()` instead — the adapter
64
+ * checks both. */
65
+ parentSpanId?: string;
66
+ parentSpanContext?: () => {
67
+ spanId: string;
68
+ } | undefined;
69
+ name: string;
70
+ startTime: HrTime;
71
+ endTime: HrTime;
72
+ attributes: Record<string, OtelAttributeValue>;
73
+ events?: Array<{
74
+ name: string;
75
+ time: HrTime;
76
+ attributes?: Record<string, OtelAttributeValue>;
77
+ }>;
78
+ status?: {
79
+ code: number;
80
+ message?: string;
81
+ };
82
+ }
83
+ /** `[seconds, nanoseconds]` → unix-nano number. */
84
+ declare function hrTimeToUnixNano(hr: HrTime): number;
85
+ interface TraceAiBridgeOptions {
86
+ /** Hosted client to forward spans to. */
87
+ client: HostedClient;
88
+ /** When set, spans missing a `tangle.runId` attribute receive this value
89
+ * on the way out. Useful when the OTel emitter doesn't know which
90
+ * substrate run it's serving. */
91
+ defaultRunId?: string;
92
+ /** Max spans per ingest call. Default 200. The hosted ingest endpoint
93
+ * caps at 5000 per call; we batch smaller by default to keep individual
94
+ * retries cheap. */
95
+ batchSize?: number;
96
+ /** Called when a batch fails to ingest. Defaults to a console.warn. Hook
97
+ * this when you need backpressure or to spill to a fallback. */
98
+ onError?: (err: unknown, batch: TraceSpanEvent[]) => void | Promise<void>;
99
+ }
100
+ interface TraceAiBridge {
101
+ /** Convert + ingest a batch of OTel-shape spans. */
102
+ ingest(spans: OtelLikeSpan[]): Promise<void>;
103
+ /** Convert one OTel span to the wire-format event. Useful for tests or
104
+ * custom batching pipelines. */
105
+ spanToEvent(span: OtelLikeSpan): TraceSpanEvent;
106
+ }
107
+ declare function createTraceAiBridge(opts: TraceAiBridgeOptions): TraceAiBridge;
108
+
109
+ export { type HrTime, OTEL_STATUS_ERROR, OTEL_STATUS_OK, OTEL_STATUS_UNSET, type OtelAttributeValue, type OtelLikeSpan, type TraceAiBridge, type TraceAiBridgeOptions, createTraceAiBridge, hrTimeToUnixNano };
@@ -0,0 +1,106 @@
1
+ import "../chunk-NSBPE2FW.js";
2
+
3
+ // src/adapters/traceai.ts
4
+ var OTEL_STATUS_UNSET = 0;
5
+ var OTEL_STATUS_OK = 1;
6
+ var OTEL_STATUS_ERROR = 2;
7
+ function hrTimeToUnixNano(hr) {
8
+ const [seconds, nanos] = hr;
9
+ return seconds * 1e9 + nanos;
10
+ }
11
+ function statusCodeName(code) {
12
+ if (code === OTEL_STATUS_OK) return "OK";
13
+ if (code === OTEL_STATUS_ERROR) return "ERROR";
14
+ return "UNSET";
15
+ }
16
+ function cleanAttributes(attrs) {
17
+ const out = {};
18
+ if (!attrs) return out;
19
+ for (const [k, v] of Object.entries(attrs)) {
20
+ if (v === null || v === void 0) continue;
21
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
22
+ out[k] = v;
23
+ }
24
+ }
25
+ return out;
26
+ }
27
+ function readPivotString(attrs, key) {
28
+ const v = attrs[key];
29
+ return typeof v === "string" ? v : void 0;
30
+ }
31
+ function readPivotNumber(attrs, key) {
32
+ const v = attrs[key];
33
+ return typeof v === "number" ? v : void 0;
34
+ }
35
+ function resolveParentSpanId(span) {
36
+ if (span.parentSpanId) return span.parentSpanId;
37
+ const ctx = span.parentSpanContext?.();
38
+ return ctx?.spanId;
39
+ }
40
+ function createTraceAiBridge(opts) {
41
+ const batchSize = opts.batchSize ?? 200;
42
+ const onError = opts.onError ?? ((err) => {
43
+ console.warn("[traceai-bridge] ingest batch failed:", err);
44
+ });
45
+ function convert(span) {
46
+ const ctx = span.spanContext();
47
+ const attributes = cleanAttributes(span.attributes);
48
+ const runId = readPivotString(attributes, "tangle.runId") ?? opts.defaultRunId;
49
+ const scenarioId = readPivotString(attributes, "tangle.scenarioId");
50
+ const cellId = readPivotString(attributes, "tangle.cellId");
51
+ const generation = readPivotNumber(attributes, "tangle.generation");
52
+ if (runId && !attributes["tangle.runId"]) {
53
+ attributes["tangle.runId"] = runId;
54
+ }
55
+ const event = {
56
+ traceId: ctx.traceId,
57
+ spanId: ctx.spanId,
58
+ name: span.name,
59
+ startTimeUnixNano: hrTimeToUnixNano(span.startTime),
60
+ endTimeUnixNano: hrTimeToUnixNano(span.endTime),
61
+ attributes
62
+ };
63
+ const parentSpanId = resolveParentSpanId(span);
64
+ if (parentSpanId) event.parentSpanId = parentSpanId;
65
+ if (span.events && span.events.length > 0) {
66
+ event.events = span.events.map((e) => {
67
+ const eventAttrs = cleanAttributes(e.attributes);
68
+ const node = {
69
+ timeUnixNano: hrTimeToUnixNano(e.time),
70
+ name: e.name
71
+ };
72
+ if (Object.keys(eventAttrs).length > 0) node.attributes = eventAttrs;
73
+ return node;
74
+ });
75
+ }
76
+ if (span.status) {
77
+ event.status = { code: statusCodeName(span.status.code), message: span.status.message };
78
+ }
79
+ if (runId) event["tangle.runId"] = runId;
80
+ if (scenarioId) event["tangle.scenarioId"] = scenarioId;
81
+ if (cellId) event["tangle.cellId"] = cellId;
82
+ if (generation !== void 0) event["tangle.generation"] = generation;
83
+ return event;
84
+ }
85
+ async function ingest(spans) {
86
+ if (spans.length === 0) return;
87
+ const events = spans.map(convert);
88
+ for (let i = 0; i < events.length; i += batchSize) {
89
+ const batch = events.slice(i, i + batchSize);
90
+ try {
91
+ await opts.client.ingestTraces(batch);
92
+ } catch (err) {
93
+ await onError(err, batch);
94
+ }
95
+ }
96
+ }
97
+ return { ingest, spanToEvent: convert };
98
+ }
99
+ export {
100
+ OTEL_STATUS_ERROR,
101
+ OTEL_STATUS_OK,
102
+ OTEL_STATUS_UNSET,
103
+ createTraceAiBridge,
104
+ hrTimeToUnixNano
105
+ };
106
+ //# sourceMappingURL=traceai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapters/traceai.ts"],"sourcesContent":["/**\n * # `@tangle-network/agent-eval/adapters/traceai` — OTel→hosted bridge.\n *\n * Forwards OpenTelemetry-shaped spans (from `future-agi/traceai`, from the\n * OTel SDK directly, or from any library that emits OTel `ReadableSpan`s)\n * into the hosted-tier ingest endpoint via `createHostedClient`.\n *\n * **Why this exists:** future-agi ships the strongest OTel-native\n * instrumentation library in the TypeScript-agent ecosystem. Partners using\n * traceai for tracing should be able to plug it into Tangle Intelligence\n * with one config line — not rebuild OTel emission from scratch. Adapter\n * shape applies equally to any OTel SpanProcessor pipeline.\n *\n * **Pattern:**\n *\n * ```ts\n * import { createHostedClient } from '@tangle-network/agent-eval/hosted'\n * import { createTraceAiBridge } from '@tangle-network/agent-eval/adapters/traceai'\n *\n * const client = createHostedClient({ endpoint, apiKey, tenantId })\n * const bridge = createTraceAiBridge({ client, defaultRunId: substrateRunId })\n *\n * // Wherever your OTel SpanProcessor hands you a finished span:\n * processor.onEnd = (span) => bridge.ingest([span])\n * // …or in a SpanProcessor.onShutdown / batch flush:\n * await bridge.ingest(batchedSpans)\n * ```\n *\n * No `@opentelemetry/*` dependency is declared here — the adapter accepts\n * a structurally-typed `OtelLikeSpan`. This keeps the substrate dep graph\n * lean while remaining compatible with OTel SDK `ReadableSpan` instances\n * and with traceai's emitted spans. If a consumer's span shape differs\n * (e.g. `parentSpanId` as a top-level field rather than via\n * `parentSpanContext()`), the adapter accepts both forms.\n */\n\nimport type { HostedClient } from '../hosted/client'\nimport type { TraceSpanEvent } from '../hosted/types'\n\n// ── OTel-compatible structural types ─────────────────────────────────\n\n/**\n * `[seconds, nanoseconds]` — the OTel SDK's `HrTime` shape. Spans emitted\n * by the OTel SDK carry timestamps in this representation; we convert to\n * a single unix-nano number for the wire format.\n */\nexport type HrTime = [number, number]\n\n/** Standard OTel `SpanStatusCode` numeric values: 0 = UNSET, 1 = OK, 2 = ERROR. */\nexport const OTEL_STATUS_UNSET = 0\nexport const OTEL_STATUS_OK = 1\nexport const OTEL_STATUS_ERROR = 2\n\nexport type OtelAttributeValue = string | number | boolean | null | undefined\n\n/**\n * Structural surface compatible with `@opentelemetry/sdk-trace-base`'s\n * `ReadableSpan`. Consumers pass instances they get from their OTel SDK\n * (or from `future-agi/traceai`, which produces spans of this shape).\n */\nexport interface OtelLikeSpan {\n spanContext: () => { traceId: string; spanId: string; traceFlags?: number }\n /** Set on the span itself by some SDKs (legacy / OTLP-shape). Some SDKs\n * expose the parent via `parentSpanContext()` instead — the adapter\n * checks both. */\n parentSpanId?: string\n parentSpanContext?: () => { spanId: string } | undefined\n name: string\n startTime: HrTime\n endTime: HrTime\n attributes: Record<string, OtelAttributeValue>\n events?: Array<{\n name: string\n time: HrTime\n attributes?: Record<string, OtelAttributeValue>\n }>\n status?: { code: number; message?: string }\n}\n\n// ── Conversion ───────────────────────────────────────────────────────\n\n/** `[seconds, nanoseconds]` → unix-nano number. */\nexport function hrTimeToUnixNano(hr: HrTime): number {\n const [seconds, nanos] = hr\n return seconds * 1_000_000_000 + nanos\n}\n\nfunction statusCodeName(code: number | undefined): 'OK' | 'ERROR' | 'UNSET' {\n if (code === OTEL_STATUS_OK) return 'OK'\n if (code === OTEL_STATUS_ERROR) return 'ERROR'\n return 'UNSET'\n}\n\n/** Drop null/undefined attribute values; keep string/number/boolean. */\nfunction cleanAttributes(\n attrs: Record<string, OtelAttributeValue> | undefined,\n): Record<string, string | number | boolean> {\n const out: Record<string, string | number | boolean> = {}\n if (!attrs) return out\n for (const [k, v] of Object.entries(attrs)) {\n if (v === null || v === undefined) continue\n if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') {\n out[k] = v\n }\n }\n return out\n}\n\nfunction readPivotString(\n attrs: Record<string, OtelAttributeValue>,\n key: string,\n): string | undefined {\n const v = attrs[key]\n return typeof v === 'string' ? v : undefined\n}\n\nfunction readPivotNumber(\n attrs: Record<string, OtelAttributeValue>,\n key: string,\n): number | undefined {\n const v = attrs[key]\n return typeof v === 'number' ? v : undefined\n}\n\nfunction resolveParentSpanId(span: OtelLikeSpan): string | undefined {\n if (span.parentSpanId) return span.parentSpanId\n const ctx = span.parentSpanContext?.()\n return ctx?.spanId\n}\n\n// ── Bridge ───────────────────────────────────────────────────────────\n\nexport interface TraceAiBridgeOptions {\n /** Hosted client to forward spans to. */\n client: HostedClient\n /** When set, spans missing a `tangle.runId` attribute receive this value\n * on the way out. Useful when the OTel emitter doesn't know which\n * substrate run it's serving. */\n defaultRunId?: string\n /** Max spans per ingest call. Default 200. The hosted ingest endpoint\n * caps at 5000 per call; we batch smaller by default to keep individual\n * retries cheap. */\n batchSize?: number\n /** Called when a batch fails to ingest. Defaults to a console.warn. Hook\n * this when you need backpressure or to spill to a fallback. */\n onError?: (err: unknown, batch: TraceSpanEvent[]) => void | Promise<void>\n}\n\nexport interface TraceAiBridge {\n /** Convert + ingest a batch of OTel-shape spans. */\n ingest(spans: OtelLikeSpan[]): Promise<void>\n /** Convert one OTel span to the wire-format event. Useful for tests or\n * custom batching pipelines. */\n spanToEvent(span: OtelLikeSpan): TraceSpanEvent\n}\n\nexport function createTraceAiBridge(opts: TraceAiBridgeOptions): TraceAiBridge {\n const batchSize = opts.batchSize ?? 200\n const onError =\n opts.onError ??\n ((err) => {\n console.warn('[traceai-bridge] ingest batch failed:', err)\n })\n\n function convert(span: OtelLikeSpan): TraceSpanEvent {\n const ctx = span.spanContext()\n const attributes = cleanAttributes(span.attributes)\n // Pull pivot attributes off the cleaned attribute map so they round-trip\n // through the wire format's first-class fields. They REMAIN in\n // `attributes` as well so downstream OTel viewers see the same values.\n const runId = readPivotString(attributes, 'tangle.runId') ?? opts.defaultRunId\n const scenarioId = readPivotString(attributes, 'tangle.scenarioId')\n const cellId = readPivotString(attributes, 'tangle.cellId')\n const generation = readPivotNumber(attributes, 'tangle.generation')\n\n if (runId && !attributes['tangle.runId']) {\n attributes['tangle.runId'] = runId\n }\n\n const event: TraceSpanEvent = {\n traceId: ctx.traceId,\n spanId: ctx.spanId,\n name: span.name,\n startTimeUnixNano: hrTimeToUnixNano(span.startTime),\n endTimeUnixNano: hrTimeToUnixNano(span.endTime),\n attributes,\n }\n const parentSpanId = resolveParentSpanId(span)\n if (parentSpanId) event.parentSpanId = parentSpanId\n if (span.events && span.events.length > 0) {\n event.events = span.events.map((e) => {\n const eventAttrs = cleanAttributes(e.attributes)\n const node: {\n timeUnixNano: number\n name: string\n attributes?: Record<string, string | number | boolean>\n } = {\n timeUnixNano: hrTimeToUnixNano(e.time),\n name: e.name,\n }\n if (Object.keys(eventAttrs).length > 0) node.attributes = eventAttrs\n return node\n })\n }\n if (span.status) {\n event.status = { code: statusCodeName(span.status.code), message: span.status.message }\n }\n if (runId) event['tangle.runId'] = runId\n if (scenarioId) event['tangle.scenarioId'] = scenarioId\n if (cellId) event['tangle.cellId'] = cellId\n if (generation !== undefined) event['tangle.generation'] = generation\n return event\n }\n\n async function ingest(spans: OtelLikeSpan[]): Promise<void> {\n if (spans.length === 0) return\n const events = spans.map(convert)\n for (let i = 0; i < events.length; i += batchSize) {\n const batch = events.slice(i, i + batchSize)\n try {\n await opts.client.ingestTraces(batch)\n } catch (err) {\n await onError(err, batch)\n }\n }\n }\n\n return { ingest, spanToEvent: convert }\n}\n"],"mappings":";;;AAiDO,IAAM,oBAAoB;AAC1B,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AA+B1B,SAAS,iB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,SAAS,KAAK;AACZ,cAAM,QAAQ,KAAK,KAAK;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,aAAa,QAAQ;AACxC;","names":[]}
@@ -1,13 +1,13 @@
1
- export { C as CampaignStorage, D as DefaultProductionGateOptions, E as EvolutionaryDriverOptions, G as GepaDriverOptions, H as HeldOutGateOptions, O as OpenAutoPrOptions, m as OpenAutoPrResult, a as RunCampaignOptions, b as RunEvalOptions, c as RunImprovementLoopOptions, R as RunImprovementLoopResult, n as RunOptimizationOptions, o as RunOptimizationResult, d as composeGate, e as defaultProductionGate, f as evolutionaryDriver, g as fsCampaignStorage, h as gepaDriver, i as heldOutGate, j as inMemoryCampaignStorage, p as openAutoPr, r as runCampaign, k as runEval, l as runImprovementLoop, q as runOptimization, s as surfaceHash } from '../run-improvement-loop-Bfam3MT1.js';
1
+ export { C as CampaignStorage, D as DefaultProductionGateOptions, E as EvolutionaryDriverOptions, G as GepaDriverOptions, H as HeldOutGateOptions, O as OpenAutoPrOptions, m as OpenAutoPrResult, a as RunCampaignOptions, b as RunEvalOptions, c as RunImprovementLoopOptions, R as RunImprovementLoopResult, n as RunOptimizationOptions, o as RunOptimizationResult, d as composeGate, e as defaultProductionGate, f as evolutionaryDriver, g as fsCampaignStorage, h as gepaDriver, i as heldOutGate, j as inMemoryCampaignStorage, p as openAutoPr, r as runCampaign, k as runEval, l as runImprovementLoop, q as runOptimization, s as surfaceHash } from '../run-improvement-loop-B-L8GgpW.js';
2
2
  import { L as LabeledScenarioStore, q as LabeledScenarioWrite, r as LabeledScenarioSampleArgs, s as LabeledScenarioRecord, f as CodeSurface } from '../types-8u72Gc76.js';
3
3
  export { C as CampaignAggregates, a as CampaignArtifactWriter, b as CampaignCellResult, c as CampaignCostMeter, d as CampaignResult, e as CampaignTraceWriter, D as DispatchContext, g as DispatchFn, G as Gate, h as GateContext, i as GateDecision, j as GateResult, k as GenerationCandidate, l as GenerationRecord, I as ImprovementDriver, t as JudgeAggregate, J as JudgeConfig, m as JudgeDimension, n as JudgeScore, u as LabeledScenarioSource, M as MutableSurface, o as Mutator, O as OptimizerConfig, P as ProposeContext, R as RedactionStatus, S as Scenario, v as ScenarioAggregate, p as SessionScript, T as TraceSpan } from '../types-8u72Gc76.js';
4
4
  import '../llm-client-BXVRUZyX.js';
5
5
  import '../errors-mje_cKOs.js';
6
6
  import '../raw-provider-sink-C46HDghv.js';
7
- import '@tangle-network/agent-runtime';
8
7
  import '../red-team-30II1T4o.js';
9
8
  import '../dataset-BlwAtYYf.js';
10
9
  import '../store-Db2Bv8Cf.js';
10
+ import '../run-record-BGY6bHRh.js';
11
11
 
12
12
  /**
13
13
  * @experimental
@@ -9,7 +9,7 @@ import {
9
9
  runImprovementLoop,
10
10
  runOptimization,
11
11
  surfaceHash
12
- } from "../chunk-HRKOCLQA.js";
12
+ } from "../chunk-XAP6DJZE.js";
13
13
  import {
14
14
  fsCampaignStorage,
15
15
  inMemoryCampaignStorage,
@@ -0,0 +1,80 @@
1
+ // src/hosted/types.ts
2
+ var HOSTED_WIRE_VERSION = "2026-05-26.v1";
3
+
4
+ // src/hosted/client.ts
5
+ function sleep(ms) {
6
+ return new Promise((resolve) => {
7
+ const t = setTimeout(resolve, ms);
8
+ if (typeof t.unref === "function")
9
+ t.unref();
10
+ });
11
+ }
12
+ async function post(tenant, path, body, opts = {}) {
13
+ const timeoutMs = tenant.timeoutMs ?? 3e4;
14
+ const maxRetries = tenant.retries ?? 2;
15
+ const f = tenant.fetchImpl ?? ((...args) => fetch(...args));
16
+ const url = `${tenant.endpoint.replace(/\/$/, "")}${path}`;
17
+ let lastError;
18
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
19
+ const ourTimeout = AbortSignal.timeout(timeoutMs);
20
+ const combinedSignal = opts.signal ? AbortSignal.any([opts.signal, ourTimeout]) : ourTimeout;
21
+ try {
22
+ const headers = {
23
+ "content-type": "application/json",
24
+ authorization: `Bearer ${tenant.apiKey}`,
25
+ "x-tangle-tenant-id": tenant.tenantId,
26
+ "x-tangle-wire-version": HOSTED_WIRE_VERSION
27
+ };
28
+ if (opts.idempotencyKey) headers["idempotency-key"] = opts.idempotencyKey;
29
+ const res = await f(url, {
30
+ method: "POST",
31
+ headers,
32
+ body: JSON.stringify(body),
33
+ signal: combinedSignal
34
+ });
35
+ if (!res.ok) {
36
+ const retryable = res.status >= 500 || res.status === 408 || res.status === 429;
37
+ if (!retryable || attempt === maxRetries) {
38
+ const text = await res.text().catch(() => "");
39
+ throw new Error(`hosted ingest ${url} failed (${res.status}): ${text.slice(0, 500)}`);
40
+ }
41
+ await sleep(2 ** attempt * 200 + Math.random() * 200);
42
+ continue;
43
+ }
44
+ return await res.json();
45
+ } catch (err) {
46
+ if (opts.signal?.aborted) throw err;
47
+ lastError = err;
48
+ if (attempt === maxRetries) throw err;
49
+ await sleep(2 ** attempt * 200 + Math.random() * 200);
50
+ }
51
+ }
52
+ throw lastError ?? new Error("hosted ingest exhausted retries");
53
+ }
54
+ function createHostedClient(tenant) {
55
+ return {
56
+ tenant,
57
+ wireVersion: HOSTED_WIRE_VERSION,
58
+ async ingestEvalRun(event, idempotencyKey) {
59
+ return this.ingestEvalRuns([event], idempotencyKey);
60
+ },
61
+ async ingestEvalRuns(events, idempotencyKey) {
62
+ const body = { wireVersion: HOSTED_WIRE_VERSION, events };
63
+ return post(tenant, "/v1/ingest/eval-runs", body, {
64
+ idempotencyKey
65
+ });
66
+ },
67
+ async ingestTraces(spans, idempotencyKey) {
68
+ const body = { wireVersion: HOSTED_WIRE_VERSION, spans };
69
+ return post(tenant, "/v1/ingest/traces", body, {
70
+ idempotencyKey
71
+ });
72
+ }
73
+ };
74
+ }
75
+
76
+ export {
77
+ HOSTED_WIRE_VERSION,
78
+ createHostedClient
79
+ };
80
+ //# sourceMappingURL=chunk-OYI6RZJK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hosted/types.ts","../src/hosted/client.ts"],"sourcesContent":["/**\n * # Hosted-tier wire format — the schema that EVERY orchestrator (ours,\n * a partner's self-hosted one, a future open implementation) must accept.\n *\n * **Stability:** every type in this file is committed under semver. New\n * minors only ADD optional fields. Breaking changes mean a major bump\n * (`HostedWireVersion` literal increment).\n *\n * The wire format is two event streams in one transport:\n *\n * 1. **Eval-run events** (`POST /v1/ingest/eval-runs`). Posted when a\n * campaign / improvement-loop completes (or per-generation if\n * streaming). Carries the structured result + per-cell scores +\n * surface diffs the orchestrator stores for the dashboard.\n *\n * 2. **Trace spans** (`POST /v1/ingest/traces`). Standard OTLP-shaped\n * spans with a few additional attributes so the orchestrator can\n * pivot from eval-run → underlying execution. Compatible with any\n * OTel collector.\n *\n * Both endpoints are authenticated with a bearer token + a tenant id\n * header. Tenants isolate everything downstream of ingest; no tenant\n * ever sees another tenant's data.\n */\n\nimport type { GateDecision, MutableSurface } from '../campaign/types'\n\nexport const HOSTED_WIRE_VERSION = '2026-05-26.v1' as const\nexport type HostedWireVersion = typeof HOSTED_WIRE_VERSION\n\n// ── Transport headers ───────────────────────────────────────────────\n\n/** Every ingest request carries these. */\nexport interface HostedIngestHeaders {\n /** Bearer token. The orchestrator validates against the tenant key. */\n authorization: `Bearer ${string}`\n /** Stable tenant id (the orchestrator-side primary key for the tenant). */\n 'x-tangle-tenant-id': string\n /** Wire-version pin so the server can reject incompatible payloads. */\n 'x-tangle-wire-version': HostedWireVersion\n /** Optional idempotency key for retry-safe ingest. */\n 'idempotency-key'?: string\n}\n\n// ── Eval-run event ──────────────────────────────────────────────────\n\n/** Lifecycle stages of an eval-run as the substrate reports them. */\nexport type EvalRunStatus =\n | 'started'\n | 'baseline-complete'\n | 'generation-complete'\n | 'gate-decided'\n | 'finished'\n | 'errored'\n\nexport interface EvalRunCellScore {\n /** Stable scenario id from the consumer's scenario set. */\n scenarioId: string\n /** Repetition index when reps > 1; 0 for the default. */\n rep: number\n /** Composite score across all judges + dimensions for this cell. */\n compositeMean: number\n /** Per-judge → per-dimension scores; null where the judge did not run. */\n dimensions: Record<string, Record<string, number>>\n /** Per-cell error message if the dispatch threw. Null on success. */\n errorMessage?: string\n}\n\nexport interface EvalRunGenerationSnapshot {\n /** Generation index. 0 is baseline. */\n index: number\n /** Candidate surface fingerprint (stable hash) — pivot key into the\n * trace stream to fetch the underlying execution. */\n surfaceHash: string\n /** The candidate surface itself. May be omitted to avoid PII when the\n * consumer prefers not to ship verbatim prompts. */\n surface?: MutableSurface\n /** Per-cell scores for this generation. */\n cells: EvalRunCellScore[]\n /** Aggregate composite mean across all cells in this generation. */\n compositeMean: number\n /** Total $ spent across this generation. */\n costUsd: number\n /** Wall-clock duration of this generation. */\n durationMs: number\n}\n\n/**\n * The top-level eval-run event. One ingest call per logical eval-run;\n * generations stream in incrementally via repeated calls with the same\n * `runId`. The orchestrator deduplicates by `(runId, generation.index)`.\n */\nexport interface EvalRunEvent {\n /** Stable run id (the substrate's `runId`). UUID or substrate-generated. */\n runId: string\n /** Where this run was happening — derived from `RunCampaignOptions.runDir`. */\n runDir: string\n /** ISO-8601 timestamp the substrate recorded the event. */\n timestamp: string\n /** Lifecycle stage this event represents. */\n status: EvalRunStatus\n /** Free-form consumer tags (env, branch, model id, etc.). Searchable. */\n labels: Record<string, string>\n /** Baseline campaign snapshot. Present when status >= baseline-complete. */\n baseline?: EvalRunGenerationSnapshot\n /** Per-generation snapshots. Streams in; orchestrator appends. */\n generations: EvalRunGenerationSnapshot[]\n /** Final gate decision. Present when status >= gate-decided. */\n gateDecision?: GateDecision\n /** Held-out lift = winner-on-holdout - baseline-on-holdout. */\n holdoutLift?: number\n /** Total $ spent across baseline + every generation. */\n totalCostUsd: number\n /** Total wall-clock duration. */\n totalDurationMs: number\n /** Error message if status === 'errored'. */\n errorMessage?: string\n}\n\n// ── Trace span event ────────────────────────────────────────────────\n\n/**\n * OTel-shape span with a few additional attributes for eval-run pivoting.\n * Compatible with any OTLP collector — `name`, `traceId`, `spanId`,\n * `startTimeUnixNano`, `endTimeUnixNano`, `attributes` are stock OTel.\n */\nexport interface TraceSpanEvent {\n traceId: string\n spanId: string\n parentSpanId?: string\n name: string\n startTimeUnixNano: number\n endTimeUnixNano: number\n attributes: Record<string, string | number | boolean>\n events?: Array<{\n timeUnixNano: number\n name: string\n attributes?: Record<string, string | number | boolean>\n }>\n status?: { code: 'OK' | 'ERROR' | 'UNSET'; message?: string }\n /** Pivot back into the eval-run stream. */\n 'tangle.runId'?: string\n /** Pivot to the specific generation. */\n 'tangle.generation'?: number\n /** Pivot to the specific cell. */\n 'tangle.cellId'?: string\n /** Pivot to the specific scenario. */\n 'tangle.scenarioId'?: string\n}\n\n// ── Ingest request bodies ───────────────────────────────────────────\n\nexport interface IngestEvalRunsRequest {\n wireVersion: HostedWireVersion\n events: EvalRunEvent[]\n}\n\nexport interface IngestTracesRequest {\n wireVersion: HostedWireVersion\n spans: TraceSpanEvent[]\n}\n\nexport interface IngestResponse {\n /** Accepted events / spans count. */\n accepted: number\n /** Rejected events with reasons (validation failures, dup idempotency key, etc.). */\n rejected: Array<{ index: number; reason: string }>\n}\n","/**\n * # Hosted-tier ingest client.\n *\n * Ships eval-run events + trace spans to any orchestrator (ours, a\n * partner's self-hosted one, or a future open implementation) that\n * speaks the wire format in `./types.ts`.\n *\n * Three modes:\n * - **Ours:** point at `https://orchestrator.tangle.tools/v1`. We\n * handle ingest + storage + dashboard.\n * - **Self-hosted:** point at whatever URL runs the reference receiver\n * from `examples/hosted-ingest-server/`.\n * - **Off (default):** when `hostedTenant` is unset, nothing is sent.\n * Everything stays local.\n */\n\nimport {\n type EvalRunEvent,\n HOSTED_WIRE_VERSION,\n type HostedWireVersion,\n type IngestEvalRunsRequest,\n type IngestResponse,\n type IngestTracesRequest,\n type TraceSpanEvent,\n} from './types'\n\nexport interface HostedTenant {\n /** Orchestrator endpoint base URL (no trailing slash). Required. */\n endpoint: string\n /** Bearer token issued by the orchestrator. Required. */\n apiKey: string\n /** Tenant id — the orchestrator's primary key for this consumer. Required. */\n tenantId: string\n /** Optional `fetch` override (auth wrappers, custom agent, test mocks). */\n fetchImpl?: typeof fetch\n /** Per-call timeout in ms. Default 30s. */\n timeoutMs?: number\n /** Retries on 5xx / network errors. Default 2. */\n retries?: number\n}\n\nexport interface HostedClient {\n ingestEvalRun(event: EvalRunEvent, idempotencyKey?: string): Promise<IngestResponse>\n ingestEvalRuns(events: EvalRunEvent[], idempotencyKey?: string): Promise<IngestResponse>\n ingestTraces(spans: TraceSpanEvent[], idempotencyKey?: string): Promise<IngestResponse>\n readonly tenant: HostedTenant\n readonly wireVersion: HostedWireVersion\n}\n\ninterface RequestOptions {\n idempotencyKey?: string\n signal?: AbortSignal\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => {\n const t = setTimeout(resolve, ms)\n if (typeof (t as { unref?: () => void }).unref === 'function')\n (t as { unref: () => void }).unref()\n })\n}\n\nasync function post<TReq, TRes>(\n tenant: HostedTenant,\n path: string,\n body: TReq,\n opts: RequestOptions = {},\n): Promise<TRes> {\n const timeoutMs = tenant.timeoutMs ?? 30_000\n const maxRetries = tenant.retries ?? 2\n const f: typeof fetch = tenant.fetchImpl ?? ((...args) => fetch(...args))\n const url = `${tenant.endpoint.replace(/\\/$/, '')}${path}`\n\n let lastError: unknown\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const ourTimeout = AbortSignal.timeout(timeoutMs)\n const combinedSignal = opts.signal ? AbortSignal.any([opts.signal, ourTimeout]) : ourTimeout\n try {\n const headers: Record<string, string> = {\n 'content-type': 'application/json',\n authorization: `Bearer ${tenant.apiKey}`,\n 'x-tangle-tenant-id': tenant.tenantId,\n 'x-tangle-wire-version': HOSTED_WIRE_VERSION,\n }\n if (opts.idempotencyKey) headers['idempotency-key'] = opts.idempotencyKey\n\n const res = await f(url, {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: combinedSignal,\n })\n if (!res.ok) {\n const retryable = res.status >= 500 || res.status === 408 || res.status === 429\n if (!retryable || attempt === maxRetries) {\n const text = await res.text().catch(() => '')\n throw new Error(`hosted ingest ${url} failed (${res.status}): ${text.slice(0, 500)}`)\n }\n await sleep(2 ** attempt * 200 + Math.random() * 200)\n continue\n }\n return (await res.json()) as TRes\n } catch (err) {\n if (opts.signal?.aborted) throw err\n lastError = err\n if (attempt === maxRetries) throw err\n await sleep(2 ** attempt * 200 + Math.random() * 200)\n }\n }\n throw lastError ?? new Error('hosted ingest exhausted retries')\n}\n\nexport function createHostedClient(tenant: HostedTenant): HostedClient {\n return {\n tenant,\n wireVersion: HOSTED_WIRE_VERSION,\n\n async ingestEvalRun(event, idempotencyKey) {\n return this.ingestEvalRuns([event], idempotencyKey)\n },\n\n async ingestEvalRuns(events, idempotencyKey) {\n const body: IngestEvalRunsRequest = { wireVersion: HOSTED_WIRE_VERSION, events }\n return post<IngestEvalRunsRequest, IngestResponse>(tenant, '/v1/ingest/eval-runs', body, {\n idempotencyKey,\n })\n },\n\n async ingestTraces(spans, idempotencyKey) {\n const body: IngestTracesRequest = { wireVersion: HOSTED_WIRE_VERSION, spans }\n return post<IngestTracesRequest, IngestResponse>(tenant, '/v1/ingest/traces', body, {\n idempotencyKey,\n })\n },\n }\n}\n"],"mappings":";AA2BO,IAAM,sBAAsB;;;AC2BnC,SAAS,MAAM,IAA2B;AACxC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,IAAI,WAAW,SAAS,EAAE;AAChC,QAAI,OAAQ,EAA6B,UAAU;AACjD,MAAC,EAA4B,MAAM;AAAA,EACvC,CAAC;AACH;AAEA,eAAe,KACb,QACA,MACA,MACA,OAAuB,CAAC,GACT;AACf,QAAM,YAAY,OAAO,aAAa;AACtC,QAAM,aAAa,OAAO,WAAW;AACrC,QAAM,IAAkB,OAAO,cAAc,IAAI,SAAS,MAAM,GAAG,IAAI;AACvE,QAAM,MAAM,GAAG,OAAO,SAAS,QAAQ,OAAO,EAAE,CAAC,GAAG,IAAI;AAExD,MAAI;AACJ,WAAS,UAAU,GAAG,WAAW,YAAY,WAAW;AACtD,UA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,GAAG,cAAc;AAAA,IACpD;AAAA,IAEA,MAAM,eAAe,QAAQ,gBAAgB;AAC3C,YAAM,OAA8B,EAAE,aAAa,qBAAqB,OAAO;AAC/E,aAAO,KAA4C,QAAQ,wBAAwB,MAAM;AAAA,QACvF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA,MAAM,aAAa,OAAO,gBAAgB;AACxC,YAAM,OAA4B,EAAE,aAAa,qBAAqB,MAAM;AAC5E,aAAO,KAA0C,QAAQ,qBAAqB,MAAM;AAAA,QAClF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -639,4 +639,4 @@ export {
639
639
  surfaceHash,
640
640
  runImprovementLoop
641
641
  };
642
- //# sourceMappingURL=chunk-HRKOCLQA.js.map
642
+ //# sourceMappingURL=chunk-XAP6DJZE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/campaign/auto-pr.ts","../src/campaign/drivers/evolutionary.ts","../src/campaign/drivers/gepa.ts","../src/campaign/gates/compose.ts","../src/campaign/gates/default-production-gate.ts","../src/campaign/gates/heldout-gate.ts","../src/campaign/presets/run-eval.ts","../src/campaign/presets/run-optimization.ts","../src/campaign/presets/run-improvement-loop.ts"],"sourcesContent":["/**\n * @experimental\n *\n * `openAutoPr` — thin shell-out helper for the `runImprovementLoop` preset's\n * `autoOnPromote: 'pr'` mode. Substitutes for the per-product PR-opening\n * code consumers duplicated 4 times. The PR body includes the campaign's\n * manifest hash, gate verdict, and scorecard summary so reviewers can see\n * exactly what was promoted + why.\n *\n * NOT a deploy mechanism — this only OPENS a PR. The human reviews + merges.\n * The Shape B (`autoOnPromote: 'config'`) live-runtime-mutation path is\n * deferred to Pass B with the full shadow / canary / rollback stack.\n */\n\nimport { execSync } from 'node:child_process'\nimport { writeFileSync } from 'node:fs'\nimport { tmpdir } from 'node:os'\nimport { join } from 'node:path'\nimport type { CampaignResult, GateResult, Scenario } from './types'\n\nexport interface OpenAutoPrOptions<TArtifact, TScenario extends Scenario> {\n /** Campaign result to attach to the PR. */\n result: CampaignResult<TArtifact, TScenario>\n /** Gate verdict explaining the promotion. Substrate refuses to open a PR\n * when `gate.decision !== 'ship'` — fails loud. */\n gate: GateResult\n /** Promoted surface diff — typically the new system prompt addendum or\n * full profile diff. Substrate writes it as the PR body. */\n promotedDiff: string\n /** GH owner/repo target (e.g., `tangle-network/gtm-agent`). */\n ghOwner: string\n ghRepo: string\n /** Branch name for the PR. Default `auto/<manifestHash[:12]>`. */\n branch?: string\n /** PR title. Default includes manifest hash. */\n title?: string\n /** Whether to actually open the PR or just dry-run. Default reads\n * `GH_AUTO_PR_TOKEN` env — present = open, absent = dry-run. */\n dryRun?: boolean\n /** Test seam — substitute `gh pr create` invocation. */\n ghExec?: (args: string[]) => { stdout: string; stderr: string; status: number }\n}\n\nexport interface OpenAutoPrResult {\n opened: boolean\n prUrl?: string\n dryRun: boolean\n reason: string\n}\n\nexport function openAutoPr<TArtifact, TScenario extends Scenario>(\n options: OpenAutoPrOptions<TArtifact, TScenario>,\n): OpenAutoPrResult {\n if (options.gate.decision !== 'ship') {\n return {\n opened: false,\n dryRun: false,\n reason: `gate verdict was \"${options.gate.decision}\" — refusing to open PR`,\n }\n }\n\n const dryRun = options.dryRun ?? !process.env.GH_AUTO_PR_TOKEN\n const branch = options.branch ?? `auto/${options.result.manifestHash.slice(0, 12)}`\n const title =\n options.title ?? `auto: campaign ${options.result.manifestHash.slice(0, 8)} promoted by gate`\n\n const body = renderPrBody(options.result, options.gate, options.promotedDiff)\n const bodyPath = join(tmpdir(), `auto-pr-body-${Date.now()}.md`)\n writeFileSync(bodyPath, body)\n\n if (dryRun) {\n return {\n opened: false,\n dryRun: true,\n reason: `dry-run (GH_AUTO_PR_TOKEN not set). Would create PR on ${options.ghOwner}/${options.ghRepo} branch ${branch}. Body at ${bodyPath}.`,\n }\n }\n\n const ghExec = options.ghExec ?? defaultGhExec\n const result = ghExec([\n 'pr',\n 'create',\n '--repo',\n `${options.ghOwner}/${options.ghRepo}`,\n '--head',\n branch,\n '--title',\n title,\n '--body-file',\n bodyPath,\n ])\n if (result.status !== 0) {\n return {\n opened: false,\n dryRun: false,\n reason: `gh pr create failed (exit ${result.status}): ${result.stderr.slice(0, 400)}`,\n }\n }\n const prUrl = result.stdout.trim()\n return { opened: true, prUrl, dryRun: false, reason: 'PR opened' }\n}\n\nfunction renderPrBody<TArtifact, TScenario extends Scenario>(\n result: CampaignResult<TArtifact, TScenario>,\n gate: GateResult,\n diff: string,\n): string {\n const lines: string[] = []\n lines.push(`## Automated promotion by \\`runImprovementLoop\\``)\n lines.push('')\n lines.push(`**Manifest**: \\`${result.manifestHash}\\``)\n lines.push(`**Seed**: ${result.seed}`)\n lines.push(`**Duration**: ${Math.round(result.durationMs / 1000)}s`)\n lines.push(\n `**Cells**: executed ${result.aggregates.cellsExecuted}, cached ${result.aggregates.cellsCached}, skipped ${result.aggregates.cellsSkipped}, failed ${result.aggregates.cellsFailed}`,\n )\n lines.push(`**Total spend**: $${result.aggregates.totalCostUsd.toFixed(2)}`)\n lines.push('')\n lines.push(`### Gate verdict: \\`${gate.decision}\\``)\n lines.push('')\n for (const reason of gate.reasons) lines.push(`- ${reason}`)\n if (gate.delta !== undefined) lines.push(`- delta: ${gate.delta.toFixed(3)}`)\n lines.push('')\n lines.push('### Contributing gates')\n lines.push('')\n lines.push('| gate | passed | detail |')\n lines.push('|---|---|---|')\n for (const c of gate.contributingGates) {\n const detail =\n typeof c.detail === 'object'\n ? JSON.stringify(c.detail).slice(0, 80)\n : String(c.detail).slice(0, 80)\n lines.push(`| ${c.name} | ${c.passed ? '✓' : '✗'} | ${detail} |`)\n }\n lines.push('')\n lines.push('### Promoted surface')\n lines.push('')\n lines.push('```diff')\n lines.push(diff.slice(0, 8000))\n lines.push('```')\n lines.push('')\n lines.push('### By-judge aggregates')\n lines.push('')\n lines.push('| judge | mean | ci95 | n |')\n lines.push('|---|---|---|---|')\n for (const [name, agg] of Object.entries(result.aggregates.byJudge)) {\n lines.push(\n `| ${name} | ${agg.mean.toFixed(3)} | [${agg.ci95[0].toFixed(3)}, ${agg.ci95[1].toFixed(3)}] | ${agg.n} |`,\n )\n }\n return lines.join('\\n')\n}\n\nfunction defaultGhExec(args: string[]): { stdout: string; stderr: string; status: number } {\n try {\n const stdout = execSync(`gh ${args.map(quoteArg).join(' ')}`, {\n env: { ...process.env, GH_TOKEN: process.env.GH_AUTO_PR_TOKEN ?? process.env.GH_TOKEN ?? '' },\n stdio: ['ignore', 'pipe', 'pipe'],\n }).toString('utf8')\n return { stdout, stderr: '', status: 0 }\n } catch (err) {\n const e = err as { status?: number; stderr?: Buffer; stdout?: Buffer }\n return {\n stdout: e.stdout?.toString('utf8') ?? '',\n stderr: e.stderr?.toString('utf8') ?? '',\n status: e.status ?? 1,\n }\n }\n}\n\nfunction quoteArg(arg: string): string {\n if (/^[a-zA-Z0-9_/\\-:.@]+$/.test(arg)) return arg\n return `\"${arg.replace(/\"/g, '\\\\\"')}\"`\n}\n","/**\n * @experimental\n *\n * `evolutionaryDriver` — adapts a stateless `Mutator` (population mutation:\n * GEPA / AxGEPA / reflective-mutation) into an `ImprovementDriver`. This is\n * the evolutionary strategy: each generation, mutate the current best surface\n * into N candidates, measure, select. No generation memory beyond the current\n * surface; the loop body handles ranking + promotion.\n *\n * The reflective alternative is agent-runtime's `improvementDriver` with a\n * `reflectiveGenerator` / `agenticGenerator`: it reasons over the report +\n * trace findings to propose targeted edits rather than blind mutations. Both\n * conform to `ImprovementDriver`; the improvement loop is identical regardless\n * of which drives it.\n */\n\nimport type { ImprovementDriver, Mutator } from '../types'\n\nexport interface EvolutionaryDriverOptions<TFindings = unknown> {\n mutator: Mutator<TFindings>\n /** External findings fed to the mutator each generation. Default: []. */\n findings?: TFindings[]\n}\n\nexport function evolutionaryDriver<TFindings = unknown>(\n opts: EvolutionaryDriverOptions<TFindings>,\n): ImprovementDriver<TFindings> {\n return {\n kind: `evolutionary:${opts.mutator.kind}`,\n async propose({ currentSurface, findings, populationSize, signal }) {\n return opts.mutator.mutate({\n findings: findings.length > 0 ? findings : (opts.findings ?? []),\n currentSurface,\n populationSize,\n signal,\n })\n },\n }\n}\n","/**\n * @experimental\n *\n * `gepaDriver` — a reflective `ImprovementDriver` for prompt-tier surfaces.\n * Each generation it reflects on the prior best candidate's per-scenario\n * scores + weakest dimensions (the `GenerationCandidate` evidence from\n * `runOptimization`), asks an LLM to propose targeted rewrites of the current\n * surface, and returns them as the next population.\n *\n * This is the substrate's best-in-class prompt optimizer: surface-agnostic, so\n * ANY string surface in ANY consumer opts in by selecting it — system prompts,\n * prompt addenda, judge/reviewer prompts, even a driver's own reflection\n * prompt. It reuses the generic reflection primitive (`buildReflectionPrompt` /\n * `parseReflectionResponse`) and the router client; it has NO dependency on the\n * legacy `runMultiShotOptimization` / `prompt-evolution` orchestration.\n *\n * It earns its keep where there is real per-instance signal (which the\n * dimensional + per-scenario evidence + the `LabeledScenarioStore` flywheel\n * now provide). For thin-signal surfaces it degrades to plain reflection — so\n * it is a SELECTABLE driver, never a forced default. On generation 0 (no\n * history) it reflects on the current surface against the mutation primitives\n * alone.\n */\n\nimport { callLlm, type LlmClientOptions } from '../../llm-client'\nimport {\n buildReflectionPrompt,\n parseReflectionResponse,\n type TrialTrace,\n} from '../../reflective-mutation'\nimport type { ImprovementDriver, MutableSurface, ProposeContext } from '../types'\n\nconst REFLECTION_SYSTEM =\n 'You are an expert prompt engineer. Output ONLY a JSON object of shape ' +\n '{\"proposals\":[{\"label\":string,\"rationale\":string,\"payload\":string}]} where ' +\n 'each `payload` is the FULL improved surface text. No prose outside the JSON.'\n\nexport interface GepaDriverOptions {\n /** Router transport (apiKey/baseUrl). */\n llm: LlmClientOptions\n /** Model that performs the reflection. */\n model: string\n /** What is being optimized — appears in the reflection prompt for orientation. */\n target: string\n /** Surface-specific mutation levers offered to the model. */\n mutationPrimitives?: string[]\n /** Top/bottom scenarios surfaced as evidence each generation. Default 3. */\n evidenceK?: number\n /** Reflection sampling temperature. Default 0.7. */\n temperature?: number\n /** Reflection max tokens. Default 6000. */\n maxTokens?: number\n}\n\nexport function gepaDriver(opts: GepaDriverOptions): ImprovementDriver {\n const evidenceK = opts.evidenceK ?? 3\n return {\n kind: 'gepa',\n async propose(ctx: ProposeContext): Promise<MutableSurface[]> {\n const parent =\n typeof ctx.currentSurface === 'string'\n ? ctx.currentSurface\n : JSON.stringify(ctx.currentSurface)\n const { top, bottom, target } = buildEvidence(ctx, evidenceK, opts.target)\n\n const userPrompt = buildReflectionPrompt({\n target,\n parentPayload: parent,\n topTrials: top,\n bottomTrials: bottom,\n childCount: ctx.populationSize,\n mutationPrimitives: opts.mutationPrimitives,\n })\n\n const result = await callLlm(\n {\n model: opts.model,\n messages: [\n { role: 'system', content: REFLECTION_SYSTEM },\n { role: 'user', content: userPrompt },\n ],\n jsonMode: true,\n temperature: opts.temperature ?? 0.7,\n maxTokens: opts.maxTokens ?? 6000,\n },\n opts.llm,\n )\n\n const proposals = parseReflectionResponse(result.content, ctx.populationSize)\n const out: MutableSurface[] = []\n for (const proposal of proposals) {\n const text = typeof proposal.payload === 'string' ? proposal.payload.trim() : ''\n if (text && text !== parent && !out.includes(text)) out.push(text)\n }\n return out\n },\n }\n}\n\n/** Turn the prior generation's best candidate into reflective evidence:\n * top/bottom scenarios by composite + a weakest-dimensions note on the target.\n * Empty on generation 0 — the model reflects on the surface alone. */\nfunction buildEvidence(\n ctx: ProposeContext,\n evidenceK: number,\n baseTarget: string,\n): { top: TrialTrace[]; bottom: TrialTrace[]; target: string } {\n const last = ctx.history.at(-1)\n if (!last || last.candidates.length === 0) {\n return { top: [], bottom: [], target: baseTarget }\n }\n const best = [...last.candidates].sort((a, b) => b.composite - a.composite)[0]\n if (!best) return { top: [], bottom: [], target: baseTarget }\n\n const byScore = [...best.scenarios].sort((a, b) => b.composite - a.composite)\n const toTrace = (s: { scenarioId: string; composite: number }): TrialTrace => ({\n id: s.scenarioId,\n score: s.composite,\n })\n const top = byScore.slice(0, evidenceK).map(toTrace)\n const bottom = byScore.slice(-evidenceK).reverse().map(toTrace)\n\n const weakest = Object.entries(best.dimensions)\n .sort((a, b) => a[1] - b[1])\n .slice(0, 3)\n .map(([dim, value]) => `${dim} (${value.toFixed(2)})`)\n const target =\n weakest.length > 0 ? `${baseTarget} — weakest dimensions: ${weakest.join(', ')}` : baseTarget\n\n return { top, bottom, target }\n}\n","/**\n * @experimental\n *\n * Compose multiple `Gate` implementations — every gate must pass for the\n * composite to ship. Closes the alignment reviewer's \"default-only\n * heldOutGate + costGate would happily promote a reward-hacked prompt\"\n * concern by making safety gates first-class composable defaults.\n */\n\nimport type { Gate, GateContext, GateDecision, GateResult, Scenario } from '../types'\n\n/** Compose gates — all must `ship` for the composite to `ship`. First\n * non-ship verdict short-circuits the composite verdict, but ALL gates run\n * (so the result records every gate's reason — useful for diagnostics). */\nexport function composeGate<TArtifact = unknown, TScenario extends Scenario = Scenario>(\n ...gates: Array<Gate<TArtifact, TScenario>>\n): Gate<TArtifact, TScenario> {\n if (gates.length === 0) {\n throw new Error('composeGate requires at least one gate')\n }\n return {\n name: `composed(${gates.map((g) => g.name).join(',')})`,\n async decide(ctx: GateContext<TArtifact, TScenario>): Promise<GateResult> {\n const results: Array<{ gate: Gate<TArtifact, TScenario>; res: GateResult }> = []\n for (const gate of gates) {\n const res = await gate.decide(ctx)\n results.push({ gate, res })\n }\n\n // Substrate-wide verdict policy:\n // - all 'ship' → 'ship'\n // - any 'arch_ceiling' → 'arch_ceiling' (architectural ceiling beats other holds)\n // - any 'model_ceiling' → 'model_ceiling'\n // - any 'hold' → 'hold'\n // - else 'need_more_work'\n const decisions = results.map((r) => r.res.decision)\n const overall: GateDecision = decisions.every((d) => d === 'ship')\n ? 'ship'\n : decisions.includes('arch_ceiling')\n ? 'arch_ceiling'\n : decisions.includes('model_ceiling')\n ? 'model_ceiling'\n : decisions.includes('hold')\n ? 'hold'\n : 'need_more_work'\n\n const contributing = results.flatMap((r) =>\n r.res.contributingGates.length > 0\n ? r.res.contributingGates\n : [{ name: r.gate.name, passed: r.res.decision === 'ship', detail: r.res }],\n )\n\n const reasons = results.flatMap((r) =>\n r.res.reasons.map((reason) => `[${r.gate.name}] ${reason}`),\n )\n\n return {\n decision: overall,\n reasons,\n contributingGates: contributing,\n delta: results[0]?.res.delta,\n }\n },\n }\n}\n","/**\n * @experimental\n *\n * `defaultProductionGate` — composes the substrate's existing safety\n * primitives (red-team / reward-hacking / canary / heldout) into a single\n * Gate.decide shape. Closes the alignment + Anthropic-SI reviewers' \"safety\n * primitives are off the critical path\" blocker.\n *\n * The composition is opinionated — when consumers wire `runImprovementLoop`,\n * THIS gate is the default. Consumers can still pass a custom gate to\n * override; the recommended pattern is to compose THIS gate with whatever\n * extra domain-specific gates they need (`composeGate(defaultProductionGate(...), customGate)`).\n */\n\nimport type { CanaryReport } from '../../canary'\nimport { runCanaries } from '../../canary'\nimport type { RedTeamCase } from '../../red-team'\nimport { scoreRedTeamOutput } from '../../red-team'\nimport type { RewardHackingReport } from '../../rl/reward-hacking'\nimport { detectRewardHacking } from '../../rl/reward-hacking'\nimport type { RunRecord } from '../../run-record'\nimport type { Gate, GateContext, GateResult, Scenario } from '../types'\n\nexport interface DefaultProductionGateOptions {\n /** Required: scenarios held out from training; substrate compares\n * candidate-on-holdout vs baseline-on-holdout. */\n holdoutScenarios: Scenario[]\n /** Minimum mean-composite improvement required to ship. Default 0.5. */\n deltaThreshold?: number\n /** Total $ budget for ALL cells in this campaign — including baseline + candidate.\n * Composite verdict refuses to ship when spend exceeded budget. */\n budgetUsd?: number\n /** Red-team cases to probe candidate outputs against. When omitted the\n * substrate uses `DEFAULT_RED_TEAM_CORPUS`. Provide a domain-specific\n * battery for tighter coverage. */\n redTeamBattery?: RedTeamCase[]\n /** Run records (oldest-first) needed for the reward-hacking detector.\n * Substrate populates from prior production-loop generations. */\n recentRuns?: RunRecord[]\n /** When true, the gate refuses to ship if the reward-hacking detector\n * fires at the `gaming` severity. Default true. */\n blockOnRewardHackingGaming?: boolean\n}\n\nexport function defaultProductionGate<TArtifact, TScenario extends Scenario>(\n options: DefaultProductionGateOptions,\n): Gate<TArtifact, TScenario> {\n const deltaThreshold = options.deltaThreshold ?? 0.5\n const blockOnGaming = options.blockOnRewardHackingGaming ?? true\n\n return {\n name: 'defaultProductionGate',\n async decide(ctx: GateContext<TArtifact, TScenario>): Promise<GateResult> {\n const reasons: string[] = []\n const contributing: Array<{ name: string; passed: boolean; detail: unknown }> = []\n\n // ── (1) heldout composite delta ─────────────────────────────────\n // Baseline scores come from their OWN map; sharing `judgeScores` would\n // compare the candidate against itself (delta 0).\n const baselineComposite = meanComposite(\n ctx.baselineArtifacts,\n ctx.baselineJudgeScores ?? ctx.judgeScores,\n options.holdoutScenarios,\n )\n const candidateComposite = meanComposite(\n ctx.candidateArtifacts,\n ctx.judgeScores,\n options.holdoutScenarios,\n )\n const delta = candidateComposite - baselineComposite\n const heldoutPass = delta >= deltaThreshold\n contributing.push({\n name: 'heldout-delta',\n passed: heldoutPass,\n detail: { baselineComposite, candidateComposite, delta, deltaThreshold },\n })\n if (!heldoutPass) {\n reasons.push(`heldout delta ${delta.toFixed(3)} < threshold ${deltaThreshold}`)\n }\n\n // ── (2) budget gate ─────────────────────────────────────────────\n const budgetPass =\n options.budgetUsd === undefined ||\n ctx.cost.candidate + ctx.cost.baseline <= options.budgetUsd\n contributing.push({\n name: 'budget',\n passed: budgetPass,\n detail: {\n candidateUsd: ctx.cost.candidate,\n baselineUsd: ctx.cost.baseline,\n budgetUsd: options.budgetUsd,\n },\n })\n if (!budgetPass) {\n reasons.push(\n `spend ${(ctx.cost.candidate + ctx.cost.baseline).toFixed(2)} > budget ${options.budgetUsd}`,\n )\n }\n\n // ── (3) red-team probe on candidate ─────────────────────────────\n const redTeamFindings = options.redTeamBattery\n ? probeRedTeam(ctx.candidateArtifacts, options.redTeamBattery)\n : { passed: true, findings: [] }\n contributing.push({\n name: 'red-team',\n passed: redTeamFindings.passed,\n detail: {\n failures: redTeamFindings.findings.length,\n sample: redTeamFindings.findings.slice(0, 3),\n },\n })\n if (!redTeamFindings.passed) {\n reasons.push(`red-team probe failed (${redTeamFindings.findings.length} findings)`)\n }\n\n // ── (4) reward-hacking detector on the run-history window ───────\n let rewardHackingReport: RewardHackingReport | null = null\n if (options.recentRuns && options.recentRuns.length >= 10) {\n rewardHackingReport = detectRewardHacking({ runs: options.recentRuns })\n }\n // reward-hacking severity is numeric (0..1). \"gaming\" threshold per\n // detectRewardHacking defaults = 0.6. Block when ANY finding is at\n // gaming threshold OR the report verdict is 'gaming'.\n const gamingThreshold = 0.6\n const gamingFindings = (rewardHackingReport?.findings ?? []).filter(\n (f) => f.severity >= gamingThreshold,\n )\n const rewardHackingPass =\n !rewardHackingReport ||\n !blockOnGaming ||\n (gamingFindings.length === 0 && rewardHackingReport.verdict !== 'gaming')\n contributing.push({\n name: 'reward-hacking',\n passed: rewardHackingPass,\n detail: { report: rewardHackingReport, gamingFindingCount: gamingFindings.length },\n })\n if (!rewardHackingPass) {\n reasons.push(\n `reward-hacking detector flagged ${gamingFindings.length} gaming-severity findings (verdict=${rewardHackingReport!.verdict})`,\n )\n }\n\n // ── (5) canary check on runs ────────────────────────────────────\n let canaryReport: CanaryReport | null = null\n if (options.recentRuns && options.recentRuns.length >= 10) {\n canaryReport = runCanaries(options.recentRuns, {})\n }\n // CanarySeverity is 'info' | 'warn' | 'error' — block on 'error'.\n const errorAlerts = (canaryReport?.alerts ?? []).filter((a) => a.severity === 'error')\n const canaryPass = errorAlerts.length === 0\n contributing.push({\n name: 'canary',\n passed: canaryPass,\n detail: { totalAlerts: canaryReport?.alerts.length ?? 0, errorAlerts: errorAlerts.length },\n })\n if (!canaryPass) {\n reasons.push(`canary error alerts: ${errorAlerts.length}`)\n }\n\n // ── Verdict ─────────────────────────────────────────────────────\n const allPassed = contributing.every((c) => c.passed)\n const decision = allPassed ? 'ship' : 'hold'\n\n return {\n decision,\n reasons: reasons.length > 0 ? reasons : ['all gates passed'],\n contributingGates: contributing,\n delta,\n }\n },\n }\n}\n\nfunction meanComposite<TArtifact, TScenario extends Scenario>(\n artifacts: Map<string, TArtifact> | undefined,\n judgeScoresByCell: Map<string, Record<string, { composite: number }>>,\n scenarios: TScenario[],\n): number {\n if (!artifacts || artifacts.size === 0) return 0\n const scenarioIds = new Set(scenarios.map((s) => s.id))\n const composites: number[] = []\n for (const [cellId, scores] of judgeScoresByCell) {\n const scenarioId = cellId.split(':')[0] ?? ''\n if (!scenarioIds.has(scenarioId)) continue\n const cellComposites = Object.values(scores).map((s) => s.composite)\n if (cellComposites.length === 0) continue\n composites.push(cellComposites.reduce((a, b) => a + b, 0) / cellComposites.length)\n }\n if (composites.length === 0) return 0\n return composites.reduce((a, b) => a + b, 0) / composites.length\n}\n\nfunction probeRedTeam<TArtifact>(\n artifacts: Map<string, TArtifact>,\n battery: RedTeamCase[],\n): { passed: boolean; findings: Array<{ scenarioId: string; reason: string }> } {\n const findings: Array<{ scenarioId: string; reason: string }> = []\n for (const [_cellId, artifact] of artifacts) {\n const text = extractText(artifact)\n if (text === undefined) continue\n for (const rtCase of battery) {\n const finding = scoreRedTeamOutput(text, [], rtCase)\n if (!finding.passed) {\n findings.push({ scenarioId: rtCase.id, reason: finding.reason ?? 'red-team probe failed' })\n }\n }\n }\n return { passed: findings.length === 0, findings }\n}\n\nfunction extractText(artifact: unknown): string | undefined {\n if (typeof artifact === 'string') return artifact\n if (artifact && typeof artifact === 'object') {\n const rec = artifact as Record<string, unknown>\n if (typeof rec.text === 'string') return rec.text\n if (typeof rec.output === 'string') return rec.output\n if (typeof rec.content === 'string') return rec.content\n }\n return undefined\n}\n","/**\n * @experimental\n *\n * Thin Gate adapter — exposes delta-threshold-on-holdout as a composable\n * `Gate`. Use when you want held-out as one of N composed gates instead of\n * the full `defaultProductionGate` stack.\n */\n\nimport type { Gate, GateContext, GateResult, Scenario } from '../types'\n\nexport interface HeldOutGateOptions<TScenario extends Scenario = Scenario> {\n scenarios: TScenario[]\n deltaThreshold?: number\n}\n\nexport function heldOutGate<TArtifact, TScenario extends Scenario>(\n options: HeldOutGateOptions<TScenario>,\n): Gate<TArtifact, TScenario> {\n const deltaThreshold = options.deltaThreshold ?? 0.5\n return {\n name: 'heldOutGate',\n async decide(ctx: GateContext<TArtifact, TScenario>): Promise<GateResult> {\n const scenarioIds = new Set(options.scenarios.map((s) => s.id))\n // Baseline scores live in their OWN map — falling back to `judgeScores`\n // would compare the candidate against itself (delta 0).\n const baseline = meanForScenarios(ctx.baselineJudgeScores ?? ctx.judgeScores, scenarioIds)\n const candidate = meanForScenarios(ctx.judgeScores, scenarioIds)\n const delta = candidate - baseline\n const passed = delta >= deltaThreshold\n return {\n decision: passed ? 'ship' : 'hold',\n reasons: passed\n ? [`held-out delta ${delta.toFixed(3)} ≥ ${deltaThreshold}`]\n : [`held-out delta ${delta.toFixed(3)} < ${deltaThreshold}`],\n contributingGates: [\n { name: 'heldOutGate', passed, detail: { baseline, candidate, delta, deltaThreshold } },\n ],\n delta,\n }\n },\n }\n}\n\nfunction meanForScenarios(\n judgeScoresByCell: Map<string, Record<string, { composite: number }>>,\n scenarioIds: Set<string>,\n): number {\n const composites: number[] = []\n for (const [cellId, scores] of judgeScoresByCell) {\n const scenarioId = cellId.split(':')[0] ?? ''\n if (!scenarioIds.has(scenarioId)) continue\n const vals = Object.values(scores).map((s) => s.composite)\n if (vals.length > 0) composites.push(vals.reduce((a, b) => a + b, 0) / vals.length)\n }\n return composites.length === 0 ? 0 : composites.reduce((a, b) => a + b, 0) / composites.length\n}\n","/**\n * @experimental\n *\n * `runEval` — the simplest preset over `runCampaign`. No optimizer, no\n * gate, no auto-PR. Just: run scenarios through dispatch, score with\n * judges, return CampaignResult.\n *\n * The 80% case for consumers who want a scorecard, not an improvement loop.\n */\n\nimport { type RunCampaignOptions, runCampaign } from '../run-campaign'\nimport type { CampaignResult, Scenario } from '../types'\n\nexport interface RunEvalOptions<TScenario extends Scenario, TArtifact>\n extends Omit<RunCampaignOptions<TScenario, TArtifact>, 'runDir'> {\n runDir: string\n}\n\nexport async function runEval<TScenario extends Scenario, TArtifact>(\n opts: RunEvalOptions<TScenario, TArtifact>,\n): Promise<CampaignResult<TArtifact, TScenario>> {\n return runCampaign(opts)\n}\n","/**\n * @experimental\n *\n * `runOptimization` — the improvement loop body. Runs N generations: the\n * `ImprovementDriver` proposes K candidate surfaces per generation, each\n * candidate runs a campaign (the measurement), top-scoring promote to the\n * next generation. Driver-agnostic — the same loop runs an evolutionary\n * population mutator (`evolutionaryDriver`) or agent-runtime's\n * `improvementDriver` (reflective / agentic generators); they differ only in\n * how `propose()` picks candidates.\n *\n * This is `runLoop`'s shape (plan → measure → decide) specialized to surface\n * improvement: `driver.propose` = plan, `runCampaign` = the measurement (which\n * runs the worker behind `dispatch`), the mean-composite ranking = the\n * validator, `driver.decide` = the stop check.\n *\n * The gated-promotion shell (`runImprovementLoop`) wraps this with a holdout\n * re-score + release gate + optional PR.\n */\n\nimport { createHash } from 'node:crypto'\nimport { type RunCampaignOptions, runCampaign } from '../run-campaign'\nimport type {\n CampaignResult,\n GenerationRecord,\n ImprovementDriver,\n MutableSurface,\n Scenario,\n} from '../types'\n\nexport interface RunOptimizationOptions<TScenario extends Scenario, TArtifact>\n extends Omit<RunCampaignOptions<TScenario, TArtifact>, 'dispatch'> {\n /** Initial mutable surface (typically system prompt or addendum). */\n baselineSurface: MutableSurface\n /** Dispatcher that takes the CURRENT surface + scenario → artifact. */\n dispatchWithSurface: (\n surface: MutableSurface,\n scenario: TScenario,\n ctx: Parameters<RunCampaignOptions<TScenario, TArtifact>['dispatch']>[1],\n ) => Promise<TArtifact>\n /** The improvement strategy. Wrap a population `Mutator` via\n * `evolutionaryDriver({ mutator })`, or pass agent-runtime's\n * `improvementDriver` (reflective / agentic generators). */\n driver: ImprovementDriver\n populationSize: number\n maxGenerations: number\n /** How many top-scoring candidates carry to the next generation. Default 2. */\n promoteTopK?: number\n /** DEPTH knob forwarded to the driver's `propose()` — max iterations the\n * agentic generator may take per candidate. */\n maxImprovementShots?: number\n /** Phase-2 research report forwarded to `propose()` (analyst findings +\n * diff). Opaque here; the driver types it. */\n report?: unknown\n}\n\nexport interface RunOptimizationResult<TArtifact, TScenario extends Scenario> {\n generations: Array<{\n record: GenerationRecord\n surfaces: Array<{\n surfaceHash: string\n surface: MutableSurface\n campaign: CampaignResult<TArtifact, TScenario>\n }>\n }>\n winnerSurface: MutableSurface\n winnerSurfaceHash: string\n baselineCampaign: CampaignResult<TArtifact, TScenario>\n}\n\nexport async function runOptimization<TScenario extends Scenario, TArtifact>(\n opts: RunOptimizationOptions<TScenario, TArtifact>,\n): Promise<RunOptimizationResult<TArtifact, TScenario>> {\n const promoteTopK = opts.promoteTopK ?? 2\n\n // Baseline run\n const baselineCampaign = await runCampaign<TScenario, TArtifact>({\n ...opts,\n dispatch: (scenario, ctx) => opts.dispatchWithSurface(opts.baselineSurface, scenario, ctx),\n runDir: `${opts.runDir}/baseline`,\n })\n\n const generations: RunOptimizationResult<TArtifact, TScenario>['generations'] = []\n const history: GenerationRecord[] = []\n let currentSurfaces: MutableSurface[] = [opts.baselineSurface]\n let winnerSurface = opts.baselineSurface\n let winnerSurfaceHash = surfaceHash(opts.baselineSurface)\n let winnerComposite = meanComposite(baselineCampaign)\n\n for (let gen = 0; gen < opts.maxGenerations; gen++) {\n // Decide: the driver may stop early based on accumulated history.\n if (opts.driver.decide?.({ history }).stop) break\n\n // Plan: the driver proposes N candidates from the current best surface,\n // the accumulated generation history, and any external findings.\n const candidates = await opts.driver.propose({\n currentSurface: currentSurfaces[0] ?? opts.baselineSurface,\n history,\n findings: [],\n populationSize: opts.populationSize,\n generation: gen,\n signal: new AbortController().signal,\n report: opts.report,\n dataset: opts.labeledStore && opts.labeledStore !== 'off' ? opts.labeledStore : undefined,\n maxImprovementShots: opts.maxImprovementShots,\n })\n\n // Run each candidate as its own campaign.\n const surfaceResults: Array<{\n surfaceHash: string\n surface: MutableSurface\n campaign: CampaignResult<TArtifact, TScenario>\n composite: number\n }> = []\n for (let i = 0; i < candidates.length; i++) {\n const surface = candidates[i] as MutableSurface\n const hash = surfaceHash(surface)\n const campaign = await runCampaign<TScenario, TArtifact>({\n ...opts,\n dispatch: (scenario, ctx) => opts.dispatchWithSurface(surface, scenario, ctx),\n runDir: `${opts.runDir}/gen-${gen}/candidate-${i}`,\n })\n const composite = meanComposite(campaign)\n surfaceResults.push({ surfaceHash: hash, surface, campaign, composite })\n }\n\n // Rank, promote top-K.\n surfaceResults.sort((a, b) => b.composite - a.composite)\n const promoted = surfaceResults.slice(0, promoteTopK)\n currentSurfaces = promoted.map((p) => p.surface)\n const top = surfaceResults[0]\n if (top && top.composite > winnerComposite) {\n winnerSurface = top.surface\n winnerSurfaceHash = top.surfaceHash\n winnerComposite = top.composite\n }\n\n const record: GenerationRecord = {\n generationIndex: gen,\n candidates: surfaceResults.map((s) => {\n const breakdown = candidateBreakdown(s.campaign)\n return {\n surfaceHash: s.surfaceHash,\n composite: s.composite,\n ci95: [s.composite, s.composite] as [number, number],\n dimensions: breakdown.dimensions,\n scenarios: breakdown.scenarios,\n }\n }),\n promoted: promoted.map((p) => p.surfaceHash),\n }\n history.push(record)\n generations.push({\n record,\n surfaces: surfaceResults.map((s) => ({\n surfaceHash: s.surfaceHash,\n surface: s.surface,\n campaign: s.campaign,\n })),\n })\n }\n\n return {\n generations,\n winnerSurface,\n winnerSurfaceHash,\n baselineCampaign,\n }\n}\n\nexport function surfaceHash(surface: MutableSurface): string {\n // Prompt/tool surfaces (string) hash by content; code surfaces hash by the\n // worktree + base ref pair (the content lives in git, not in the string).\n const material =\n typeof surface === 'string'\n ? surface\n : JSON.stringify({\n kind: surface.kind,\n worktreeRef: surface.worktreeRef,\n baseRef: surface.baseRef ?? null,\n })\n return createHash('sha256').update(material).digest('hex').slice(0, 16)\n}\n\nfunction meanComposite<TArtifact, TScenario extends Scenario>(\n campaign: CampaignResult<TArtifact, TScenario>,\n): number {\n const composites: number[] = []\n for (const cell of campaign.cells) {\n const cellComposites = Object.values(cell.judgeScores).map((s) => s.composite)\n if (cellComposites.length > 0) {\n composites.push(cellComposites.reduce((a, b) => a + b, 0) / cellComposites.length)\n }\n }\n return composites.length === 0 ? 0 : composites.reduce((a, b) => a + b, 0) / composites.length\n}\n\n/** Per-candidate evidence a reflective driver grounds its next proposal on:\n * mean score per judge dimension + per-scenario composite. */\nfunction candidateBreakdown<TArtifact, TScenario extends Scenario>(\n campaign: CampaignResult<TArtifact, TScenario>,\n): {\n dimensions: Record<string, number>\n scenarios: Array<{ scenarioId: string; composite: number }>\n} {\n const dimSums: Record<string, number> = {}\n const dimCounts: Record<string, number> = {}\n const byScenario = new Map<string, number[]>()\n for (const cell of campaign.cells) {\n const judgeScores = Object.values(cell.judgeScores)\n if (judgeScores.length === 0) continue\n const cellComposite = judgeScores.reduce((a, s) => a + s.composite, 0) / judgeScores.length\n const arr = byScenario.get(cell.scenarioId) ?? []\n arr.push(cellComposite)\n byScenario.set(cell.scenarioId, arr)\n for (const score of judgeScores) {\n for (const [key, value] of Object.entries(score.dimensions)) {\n dimSums[key] = (dimSums[key] ?? 0) + value\n dimCounts[key] = (dimCounts[key] ?? 0) + 1\n }\n }\n }\n const dimensions: Record<string, number> = {}\n for (const key of Object.keys(dimSums)) {\n const count = dimCounts[key] ?? 0\n dimensions[key] = count > 0 ? (dimSums[key] ?? 0) / count : 0\n }\n const scenarios = [...byScenario.entries()].map(([scenarioId, comps]) => ({\n scenarioId,\n composite: comps.reduce((a, b) => a + b, 0) / comps.length,\n }))\n return { dimensions, scenarios }\n}\n","/**\n * @experimental\n *\n * `runImprovementLoop` — the gated-promotion shell around the improvement\n * loop body (`runOptimization`). Drives candidate surfaces via the\n * `ImprovementDriver`, re-scores the winner against the baseline on a\n * holdout set, runs the release gate, and optionally opens a PR.\n *\n * Role vocabulary (see docs/design/loop-taxonomy.md):\n * - DRIVER = the `ImprovementDriver` (evolutionary GEPA mutator OR\n * reflective analyst). Proposes candidate SURFACES — the\n * worker's system prompt / tool config — NOT conversation\n * turns.\n * - MEASUREMENT= `runCampaign`. Scores one surface by running the worker\n * (via `dispatch`) over scenarios and judging the output.\n * - WORKER = the agent harness in the sandbox, invoked behind the\n * topology-opaque `dispatch` seam — never referenced here.\n *\n * Distinct from `runLoop` in `@tangle-network/agent-runtime`, which is the\n * INNER conversation loop (driver↔workers in a sandbox). `runImprovementLoop`\n * is the OUTER loop: it improves the surface that those workers run.\n *\n * Hard-refuses unsafe configurations:\n * - `tracing: 'off'` when a driver is wired (improvement is unattributable)\n * - `autoOnPromote: 'config'` — DEFERRED to Pass B; v0.40 only ships\n * `'pr'` and `'none'`.\n */\n\nimport { openAutoPr } from '../auto-pr'\nimport type { CampaignResult, Gate, MutableSurface, Scenario } from '../types'\nimport type { RunOptimizationOptions, RunOptimizationResult } from './run-optimization'\nimport { runOptimization } from './run-optimization'\n\nexport interface RunImprovementLoopOptions<TScenario extends Scenario, TArtifact>\n extends RunOptimizationOptions<TScenario, TArtifact> {\n /** Holdout scenarios kept OUT of the training optimization pool — used\n * ONLY to score baseline vs winner for the gate. */\n holdoutScenarios: TScenario[]\n /** Promotion gate. Substrate strongly recommends `defaultProductionGate`\n * for production wiring (composes red-team / reward-hacking / canary /\n * heldout). */\n gate: Gate<TArtifact, TScenario>\n /** What to do when the gate ships:\n * - `'pr'`: open a PR via `openAutoPr`\n * - `'none'`: just report — caller decides what to do with the winner\n * v0.40 does NOT support `'config'` (live-runtime self-mutation) —\n * deferred to Pass B behind safety stack. */\n autoOnPromote: 'pr' | 'none'\n /** GH owner / repo for the auto-PR. Required when autoOnPromote === 'pr'. */\n ghOwner?: string\n ghRepo?: string\n /** Optional render override — substrate writes a diff-shaped surface; pass\n * a function to format the promoted surface differently. */\n renderPromotedDiff?: (winnerSurface: MutableSurface, baselineSurface: MutableSurface) => string\n}\n\nexport interface RunImprovementLoopResult<TArtifact, TScenario extends Scenario>\n extends RunOptimizationResult<TArtifact, TScenario> {\n baselineOnHoldout: CampaignResult<TArtifact, TScenario>\n winnerOnHoldout: CampaignResult<TArtifact, TScenario>\n gateResult: Awaited<ReturnType<Gate<TArtifact, TScenario>['decide']>>\n prResult?: ReturnType<typeof openAutoPr>\n}\n\nexport async function runImprovementLoop<TScenario extends Scenario, TArtifact>(\n opts: RunImprovementLoopOptions<TScenario, TArtifact>,\n): Promise<RunImprovementLoopResult<TArtifact, TScenario>> {\n // ── Safety pre-flight ─────────────────────────────────────────────\n // biome-ignore lint/suspicious/noExplicitAny: Pass A reserved field for Pass B Shape B\n if ((opts as any).autoOnPromote === 'config') {\n throw new Error(\n \"runImprovementLoop: autoOnPromote='config' is deferred to Pass B (requires shadow deploy + rollback + ensemble judges). Use 'pr' or 'none' in v0.40.\",\n )\n }\n // Refuse tracing=off whenever a driver is wired. An improvement loop\n // without traces is unattributable — its candidate surfaces cannot be\n // cited back to the spans that motivated them, and the dataset flywheel\n // (LabeledScenarioStore) that GEPA optimizes against goes unfed.\n if (opts.tracing === 'off' && opts.driver) {\n throw new Error(\n \"runImprovementLoop: tracing='off' is forbidden when a driver is wired. The improvement loop without traces is unattributable; candidate surfaces cannot be cited back to spans and the optimization dataset goes unfed.\",\n )\n }\n if (opts.autoOnPromote === 'pr' && (!opts.ghOwner || !opts.ghRepo)) {\n throw new Error(\"runImprovementLoop: autoOnPromote='pr' requires ghOwner + ghRepo.\")\n }\n\n // ── (1) optimization loop produces a winner ────────────────────────\n const optimization = await runOptimization(opts)\n\n // ── (2) baseline + winner re-scored on the holdout set ─────────────\n const { runCampaign } = await import('../run-campaign')\n\n const baselineOnHoldout = await runCampaign<TScenario, TArtifact>({\n ...opts,\n scenarios: opts.holdoutScenarios,\n dispatch: (scenario, ctx) => opts.dispatchWithSurface(opts.baselineSurface, scenario, ctx),\n runDir: `${opts.runDir}/holdout-baseline`,\n })\n\n const winnerOnHoldout = await runCampaign<TScenario, TArtifact>({\n ...opts,\n scenarios: opts.holdoutScenarios,\n dispatch: (scenario, ctx) =>\n opts.dispatchWithSurface(optimization.winnerSurface, scenario, ctx),\n runDir: `${opts.runDir}/holdout-winner`,\n })\n\n // ── (3) gate verdict ───────────────────────────────────────────────\n // Candidate + baseline share cellIds (same holdout scenarios), so their\n // judge scores MUST stay in separate maps — merging them collapses the\n // holdout delta to zero and the gate can never ship a real improvement.\n type ScoreMap = Map<\n string,\n Record<string, { composite: number; dimensions: Record<string, number>; notes: string }>\n >\n const candidateArtifacts = new Map<string, TArtifact>()\n const baselineArtifacts = new Map<string, TArtifact>()\n const judgeScores: ScoreMap = new Map()\n const baselineJudgeScores: ScoreMap = new Map()\n for (const cell of winnerOnHoldout.cells) {\n candidateArtifacts.set(cell.cellId, cell.artifact)\n judgeScores.set(cell.cellId, cell.judgeScores)\n }\n for (const cell of baselineOnHoldout.cells) {\n baselineArtifacts.set(cell.cellId, cell.artifact)\n baselineJudgeScores.set(cell.cellId, cell.judgeScores)\n }\n\n const gateResult = await opts.gate.decide({\n candidateArtifacts,\n baselineArtifacts,\n judgeScores,\n baselineJudgeScores,\n scenarios: opts.holdoutScenarios,\n cost: {\n candidate: winnerOnHoldout.aggregates.totalCostUsd,\n baseline: baselineOnHoldout.aggregates.totalCostUsd,\n },\n signal: new AbortController().signal,\n })\n\n // ── (4) auto-PR when gate ships ────────────────────────────────────\n let prResult: ReturnType<typeof openAutoPr> | undefined\n if (opts.autoOnPromote === 'pr' && gateResult.decision === 'ship') {\n const render = opts.renderPromotedDiff ?? defaultRenderDiff\n const promotedDiff = render(optimization.winnerSurface, opts.baselineSurface)\n prResult = openAutoPr({\n result: winnerOnHoldout,\n gate: gateResult,\n promotedDiff,\n ghOwner: opts.ghOwner!,\n ghRepo: opts.ghRepo!,\n })\n }\n\n return {\n ...optimization,\n baselineOnHoldout,\n winnerOnHoldout,\n gateResult,\n prResult,\n }\n}\n\nfunction defaultRenderDiff(winnerSurface: MutableSurface, baselineSurface: MutableSurface): string {\n // Code surfaces aren't text-diffable here — the diff lives in git. Render\n // the worktree/base refs + summary so the PR body points at the change.\n if (typeof winnerSurface !== 'string' || typeof baselineSurface !== 'string') {\n const fmt = (s: MutableSurface): string =>\n typeof s === 'string'\n ? '(prompt surface)'\n : `worktree=${s.worktreeRef}${s.baseRef ? ` base=${s.baseRef}` : ''}${s.summary ? `\\n${s.summary}` : ''}`\n return `--- baseline\\n${fmt(baselineSurface)}\\n+++ winner\\n${fmt(winnerSurface)}`\n }\n const lines: string[] = []\n lines.push('--- baseline')\n lines.push('+++ winner')\n for (const l of baselineSurface.split('\\n')) lines.push(`- ${l}`)\n for (const l of winnerSurface.split('\\n')) lines.push(`+ ${l}`)\n return lines.join('\\n')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,YAAY;AAiCd,SAAS,WACd,SACkB;AAClB,MAAI,QAAQ,KAAK,aAAa,QAAQ;AACpC,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,QAAQ,qBAAqB,QAAQ,KAAK,QAAQ;AAAA,IACpD;AAAA,EACF;AAEA,QAAM,SAAS,QAAQ,UAAU,CAAC,QAAQ,IAAI;AAC9C,QAAM,SAAS,QAAQ,UAAU,QAAQ,QAAQ,OAAO,aAAa,MAAM,GAAG,EAAE,CAAC;AACjF,QAAM,QACJ,QAAQ,SAAS,kBAAkB,QAAQ,OAAO,aAAa,MAAM,GAAG,CAAC,CAAC;AAE5E,QAAM,OAAO,aAAa,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,YAAY;AAC5E,QAAM,WAAW,KAAK,OAAO,GAAG,gBAAgB,KAAK,IAAI,CAAC,KAAK;AAC/D,gBAAc,UAAU,IAAI;AAE5B,MAAI,QAAQ;AACV,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,QAAQ,0DAA0D,QAAQ,OAAO,IAAI,QAAQ,MAAM,WAAW,MAAM,aAAa,QAAQ;AAAA,IAC3I;AAAA,EACF;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1
  import { S as Scenario, M as MutableSurface, D as DispatchContext, J as JudgeConfig, I as ImprovementDriver, G as Gate } from '../types-8u72Gc76.js';
2
2
  export { C as CampaignAggregates, a as CampaignArtifactWriter, b as CampaignCellResult, c as CampaignCostMeter, d as CampaignResult, e as CampaignTraceWriter, f as CodeSurface, g as Dispatch, h as GateContext, i as GateDecision, j as GateResult, k as GenerationCandidate, l as GenerationRecord, m as JudgeDimension, n as JudgeScore, o as Mutator, O as OptimizerConfig, p as SessionScript } from '../types-8u72Gc76.js';
3
- import { C as CampaignStorage, R as RunImprovementLoopResult } from '../run-improvement-loop-Bfam3MT1.js';
4
- export { D as DefaultProductionGateOptions, E as EvolutionaryDriverOptions, G as GepaDriverOptions, H as HeldOutGateOptions, a as RunCampaignOptions, b as RunEvalOptions, c as RunImprovementLoopOptions, d as composeGate, e as defaultProductionGate, f as evolutionaryDriver, g as fsCampaignStorage, h as gepaDriver, i as heldOutGate, j as inMemoryCampaignStorage, r as runCampaign, k as runEval, l as runImprovementLoop } from '../run-improvement-loop-Bfam3MT1.js';
3
+ import { C as CampaignStorage, R as RunImprovementLoopResult } from '../run-improvement-loop-B-L8GgpW.js';
4
+ export { D as DefaultProductionGateOptions, E as EvolutionaryDriverOptions, G as GepaDriverOptions, H as HeldOutGateOptions, a as RunCampaignOptions, b as RunEvalOptions, c as RunImprovementLoopOptions, d as composeGate, e as defaultProductionGate, f as evolutionaryDriver, g as fsCampaignStorage, h as gepaDriver, i as heldOutGate, j as inMemoryCampaignStorage, r as runCampaign, k as runEval, l as runImprovementLoop } from '../run-improvement-loop-B-L8GgpW.js';
5
5
  export { D as DeploymentOutcome, F as FileSystemOutcomeStore, a as FileSystemOutcomeStoreOptions, I as InMemoryOutcomeStore, O as OutcomeStore } from '../outcome-store-BxJ3DQKJ.js';
6
+ import { HostedTenant } from '../hosted/index.js';
6
7
  import '../llm-client-BXVRUZyX.js';
7
8
  import '../errors-mje_cKOs.js';
8
9
  import '../raw-provider-sink-C46HDghv.js';
9
- import '@tangle-network/agent-runtime';
10
10
  import '../red-team-30II1T4o.js';
11
11
  import '../dataset-BlwAtYYf.js';
12
12
  import '../store-Db2Bv8Cf.js';
13
+ import '../run-record-BGY6bHRh.js';
13
14
 
14
15
  /**
15
16
  * # `selfImprove()` — the LAND-tier one-shot.
@@ -145,6 +146,23 @@ interface SelfImproveOptions<TScenario extends Scenario, TArtifact> {
145
146
  autoOnPromote?: 'pr' | 'none';
146
147
  ghOwner?: string;
147
148
  ghRepo?: string;
149
+ /**
150
+ * Opt-in: ship eval-run events to a hosted orchestrator (ours, your
151
+ * self-hosted one, or any compatible implementation of the
152
+ * `docs/hosted-ingest-spec.md` wire format). When set, the substrate
153
+ * POSTs the final `EvalRunEvent` to `${endpoint}/v1/ingest/eval-runs`
154
+ * after the loop completes. Failures are logged but do not fail the
155
+ * loop — local result is always returned.
156
+ *
157
+ * For our orchestrator: `{ endpoint: 'https://orchestrator.tangle.tools/v1', apiKey, tenantId }`.
158
+ *
159
+ * For your self-hosted: any URL serving the wire format. See
160
+ * `examples/hosted-ingest-server/` for the reference receiver.
161
+ */
162
+ hostedTenant?: HostedTenant;
163
+ /** Free-form labels attached to the hosted event (env, branch, model id,
164
+ * etc.). Ignored when `hostedTenant` is unset. */
165
+ hostedLabels?: Record<string, string>;
148
166
  }
149
167
  interface SelfImproveResult<TScenario extends Scenario, TArtifact> {
150
168
  /** Composite mean across all scenarios, baseline run. */