@tangle-network/agent-eval 0.109.1 → 0.110.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/analyst/index.d.ts +10 -12
- package/dist/analyst/index.js +8 -11
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyze-runs-DJYpep3L.d.ts → analyze-runs-Dmz6LA9e.d.ts} +4 -4
- package/dist/{baseline-Bbid3WoO.d.ts → baseline-DsNteOgR.d.ts} +32 -2
- package/dist/belief-state/index.d.ts +6 -6
- package/dist/benchmarks/index.d.ts +4 -4
- package/dist/benchmarks/index.js +7 -8
- package/dist/builder-eval/index.d.ts +4 -4
- package/dist/builder-eval/index.js +1 -2
- package/dist/builder-eval/index.js.map +1 -1
- package/dist/{calibration-BPmzuVPk.d.ts → calibration-Dz8TQV4y.d.ts} +2 -2
- package/dist/campaign/index.d.ts +62 -20
- package/dist/campaign/index.js +9 -8
- package/dist/{chunk-LOJ2QVCE.js → chunk-2IY4ILP4.js} +2 -2
- package/dist/{chunk-LIEJUH2I.js → chunk-6PL5MGDL.js} +9 -9
- package/dist/{chunk-2OGPXHOB.js → chunk-7NX6ZSBG.js} +36 -7
- package/dist/chunk-7NX6ZSBG.js.map +1 -0
- package/dist/{chunk-R6D7NEYJ.js → chunk-GBI5J5DB.js} +81 -11
- package/dist/chunk-GBI5J5DB.js.map +1 -0
- package/dist/{chunk-YEHAEDUD.js → chunk-IMWDSFUM.js} +604 -2
- package/dist/chunk-IMWDSFUM.js.map +1 -0
- package/dist/{chunk-OVPVM4JC.js → chunk-J4AKLZEV.js} +15 -4
- package/dist/{chunk-OVPVM4JC.js.map → chunk-J4AKLZEV.js.map} +1 -1
- package/dist/{chunk-JZXGWLK5.js → chunk-MHNQWM4I.js} +62 -6
- package/dist/chunk-MHNQWM4I.js.map +1 -0
- package/dist/{chunk-QRVS7MX4.js → chunk-OW47B5WA.js} +3 -5
- package/dist/{chunk-QRVS7MX4.js.map → chunk-OW47B5WA.js.map} +1 -1
- package/dist/{chunk-DBDRR6GF.js → chunk-PLOMR3HP.js} +48 -2
- package/dist/chunk-PLOMR3HP.js.map +1 -0
- package/dist/{chunk-GDZAWO2I.js → chunk-QFGTU7MT.js} +2 -2
- package/dist/{chunk-V7HNA47Z.js → chunk-RSVSSZKF.js} +5 -5
- package/dist/{chunk-5PK3626Q.js → chunk-XRGOKCMO.js} +88 -17
- package/dist/chunk-XRGOKCMO.js.map +1 -0
- package/dist/{code-agent-session-rnJKlqmT.d.ts → code-agent-session-yitf9I-F.d.ts} +1 -1
- package/dist/contract/index.d.ts +26 -28
- package/dist/contract/index.js +11 -13
- package/dist/contract/index.js.map +1 -1
- package/dist/{control-B8UthSBL.d.ts → control-U8LBKUES.d.ts} +5 -6
- package/dist/control.d.ts +8 -9
- package/dist/control.js +6 -8
- package/dist/{dataset-DS7ytHZU.d.ts → dataset-NENEzRgk.d.ts} +1 -1
- package/dist/{default-registry-BswHCXnU.d.ts → default-registry-Bcf1uKVI.d.ts} +1 -2
- package/dist/{emitter-C2rqGH_l.d.ts → emitter-BRchAAAx.d.ts} +2 -2
- package/dist/{failure-cluster-DH9Flgcf.d.ts → failure-cluster-C48PiReX.d.ts} +2 -2
- package/dist/feedback-trajectory-pDcz1lQ1.d.ts +348 -0
- package/dist/{gepa-B3x5Ulcv.d.ts → gepa-T8T215nw.d.ts} +149 -6
- package/dist/hosted/index.d.ts +7 -7
- package/dist/{index-pPtfoIJO.d.ts → index-Dc3VLGhp.d.ts} +2 -2
- package/dist/index.d.ts +645 -61
- package/dist/index.js +1282 -190
- package/dist/index.js.map +1 -1
- package/dist/{insight-report-B4xrdwEK.d.ts → insight-report-D4cXFsLt.d.ts} +1 -1
- package/dist/{integrity-DqGZg3st.d.ts → integrity-qemeBAyx.d.ts} +1 -1
- package/dist/{types-D1ytG0Yg.d.ts → kind-factory-20hcaYpf.d.ts} +169 -2
- package/dist/meta-eval/index.d.ts +5 -5
- package/dist/meta-eval/index.js +1 -2
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/{multi-layer-verifier-CI4jdX-q.d.ts → multi-layer-verifier-BsqKuLyN.d.ts} +1 -1
- package/dist/multishot/index.d.ts +3 -3
- package/dist/openapi.json +1 -1
- package/dist/pipelines/index.d.ts +6 -7
- package/dist/pipelines/index.js +3 -6
- package/dist/pipelines/index.js.map +1 -1
- package/dist/{policy-edit-DQUXYMDm.d.ts → policy-edit-D2bBDZDf.d.ts} +2 -2
- package/dist/{pre-registration-BUhVPzE7.d.ts → pre-registration-BepVVa6P.d.ts} +3 -3
- package/dist/{provenance-DdDhf6cg.d.ts → provenance-CyxkvEi9.d.ts} +3 -5
- package/dist/{query-0aTmbmQe.d.ts → query-Ck190MOd.d.ts} +2 -2
- package/dist/{release-report-DeJpsBiA.d.ts → release-report-oBfOz8ku.d.ts} +3 -3
- package/dist/reporting.d.ts +8 -8
- package/dist/{researcher-Wc7dx6GM.d.ts → researcher-CaH0CwFC.d.ts} +6 -6
- package/dist/rl.d.ts +568 -15
- package/dist/rl.js +4 -4
- package/dist/{rubric-predictive-validity-DPnyG-CE.d.ts → rubric-predictive-validity-C-fMteAW.d.ts} +1 -1
- package/dist/{run-record-I-Z3JNvO.d.ts → run-record-DksGsfgv.d.ts} +1 -1
- package/dist/{runtime-trajectory-iW9IhV3e.d.ts → runtime-trajectory-h5i0SZUj.d.ts} +1 -1
- package/dist/{schema-m0gsnbt3.d.ts → schema-SGWcK9wa.d.ts} +1 -1
- package/dist/{semantic-concept-judge-BmNZPB_j.d.ts → semantic-concept-judge-D7z6JCLZ.d.ts} +57 -4
- package/dist/{store-BcFXE6LG.d.ts → store-BsVi7ncX.d.ts} +1 -1
- package/dist/storyboard/index.d.ts +1 -1
- package/dist/{summary-report-QMZVe3P-.d.ts → summary-report-Bz-0-t8v.d.ts} +2 -2
- package/dist/{test-graded-scenario-DeODGLra.d.ts → test-graded-scenario-mzYBKspu.d.ts} +3 -3
- package/dist/traces.d.ts +54 -11
- package/dist/traces.js +25 -27
- package/dist/{types-BdIv5dvA.d.ts → types-v--ctu-b.d.ts} +2 -2
- package/dist/wire/index.d.ts +5 -6
- package/docs/improvement-glossary.md +14 -13
- package/package.json +1 -71
- package/dist/adapters/http.d.ts +0 -142
- package/dist/adapters/http.js +0 -203
- package/dist/adapters/http.js.map +0 -1
- package/dist/adapters/langchain.d.ts +0 -95
- package/dist/adapters/langchain.js +0 -34
- package/dist/adapters/langchain.js.map +0 -1
- package/dist/adapters/otel.d.ts +0 -112
- package/dist/adapters/otel.js +0 -110
- package/dist/adapters/otel.js.map +0 -1
- package/dist/chunk-2OGPXHOB.js.map +0 -1
- package/dist/chunk-45EEMHTC.js +0 -35
- package/dist/chunk-45EEMHTC.js.map +0 -1
- package/dist/chunk-5BKGXME7.js +0 -65
- package/dist/chunk-5BKGXME7.js.map +0 -1
- package/dist/chunk-5PK3626Q.js.map +0 -1
- package/dist/chunk-6SK5VFYK.js +0 -100
- package/dist/chunk-6SK5VFYK.js.map +0 -1
- package/dist/chunk-DBDRR6GF.js.map +0 -1
- package/dist/chunk-DJWX3GVS.js +0 -81
- package/dist/chunk-DJWX3GVS.js.map +0 -1
- package/dist/chunk-FOUG2VVS.js +0 -855
- package/dist/chunk-FOUG2VVS.js.map +0 -1
- package/dist/chunk-JZXGWLK5.js.map +0 -1
- package/dist/chunk-K7QEIHHJ.js +0 -613
- package/dist/chunk-K7QEIHHJ.js.map +0 -1
- package/dist/chunk-KKHDIONI.js +0 -414
- package/dist/chunk-KKHDIONI.js.map +0 -1
- package/dist/chunk-KMPRBJK4.js +0 -74
- package/dist/chunk-KMPRBJK4.js.map +0 -1
- package/dist/chunk-Q2JRAWRI.js +0 -196
- package/dist/chunk-Q2JRAWRI.js.map +0 -1
- package/dist/chunk-R6D7NEYJ.js.map +0 -1
- package/dist/chunk-RZTMDUO7.js +0 -49
- package/dist/chunk-RZTMDUO7.js.map +0 -1
- package/dist/chunk-STGVSCDH.js +0 -202
- package/dist/chunk-STGVSCDH.js.map +0 -1
- package/dist/chunk-YEHAEDUD.js.map +0 -1
- package/dist/control-runtime-Acf9CGhw.d.ts +0 -182
- package/dist/corpus-eBVwhCp1.d.ts +0 -560
- package/dist/counterfactual-DlOz8PBx.d.ts +0 -85
- package/dist/diagnose.d.ts +0 -252
- package/dist/diagnose.js +0 -382
- package/dist/diagnose.js.map +0 -1
- package/dist/feedback-trajectory-C9KCo8ag.d.ts +0 -169
- package/dist/governance/index.d.ts +0 -135
- package/dist/governance/index.js +0 -18
- package/dist/governance/index.js.map +0 -1
- package/dist/groundedness/index.d.ts +0 -112
- package/dist/groundedness/index.js +0 -77
- package/dist/groundedness/index.js.map +0 -1
- package/dist/harness-optimizer-mOl9XX_O.d.ts +0 -106
- package/dist/kind-factory-DvIGo_cP.d.ts +0 -171
- package/dist/knowledge/index.d.ts +0 -103
- package/dist/knowledge/index.js +0 -18
- package/dist/knowledge/index.js.map +0 -1
- package/dist/pareto-E-pembql.d.ts +0 -81
- package/dist/perf/index.d.ts +0 -123
- package/dist/perf/index.js +0 -18
- package/dist/perf/index.js.map +0 -1
- package/dist/prm/index.d.ts +0 -104
- package/dist/prm/index.js +0 -265
- package/dist/prm/index.js.map +0 -1
- package/dist/product-benchmark/index.d.ts +0 -247
- package/dist/product-benchmark/index.js +0 -37
- package/dist/product-benchmark/index.js.map +0 -1
- package/dist/red-team-KmmiqBlY.d.ts +0 -63
- package/dist/redact-B40YG2M_.d.ts +0 -45
- package/dist/rubric-Cc6UHvUb.d.ts +0 -73
- package/dist/run-critic-CmMf05uV.d.ts +0 -56
- package/dist/sink-fetch-B1Yg4Til.d.ts +0 -101
- package/dist/telemetry/file.d.ts +0 -19
- package/dist/telemetry/file.js +0 -45
- package/dist/telemetry/file.js.map +0 -1
- package/dist/telemetry/index.d.ts +0 -38
- package/dist/telemetry/index.js +0 -130
- package/dist/telemetry/index.js.map +0 -1
- package/dist/testing-C21CHsq2.d.ts +0 -20
- package/dist/testing.d.ts +0 -1
- package/dist/testing.js +0 -8
- package/dist/testing.js.map +0 -1
- package/dist/trajectory-2TkpSEVh.d.ts +0 -33
- package/dist/workflow/index.d.ts +0 -496
- package/dist/workflow/index.js +0 -2178
- package/dist/workflow/index.js.map +0 -1
- /package/dist/{chunk-LOJ2QVCE.js.map → chunk-2IY4ILP4.js.map} +0 -0
- /package/dist/{chunk-LIEJUH2I.js.map → chunk-6PL5MGDL.js.map} +0 -0
- /package/dist/{chunk-GDZAWO2I.js.map → chunk-QFGTU7MT.js.map} +0 -0
- /package/dist/{chunk-V7HNA47Z.js.map → chunk-RSVSSZKF.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/product-benchmark/index.ts","../src/product-benchmark/export.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { ValidationError } from '../errors'\n\nexport const productBenchmarkSplits = ['practice', 'dev', 'holdout', 'safety', 'sentinel'] as const\n\nexport type ProductBenchmarkSplit = (typeof productBenchmarkSplits)[number]\n\nexport interface ProductBenchmarkRepoRef {\n readonly url: string\n readonly commit: string\n readonly branch: string\n}\n\nexport interface ProductBenchmarkSubstrateVersions {\n readonly agentEval: string\n readonly agentRuntime: string\n readonly agentInterface: string\n readonly sandbox: string\n readonly agentBench?: string\n}\n\nexport interface ProductBenchmarkProfileRef {\n readonly id: string\n readonly profileHash: string\n readonly agentProfilePath: string\n}\n\nexport interface ProductBenchmarkArm {\n readonly id: string\n readonly profileId: string\n readonly mutableSurfaces: readonly string[]\n readonly policyAxes: Record<string, unknown>\n}\n\nexport interface ProductBenchmarkScenario {\n readonly id: string\n readonly split: ProductBenchmarkSplit\n readonly tags: readonly string[]\n readonly sourceAllowedForSynthesis: boolean\n}\n\nexport interface ProductBenchmarkBudgets {\n readonly maxUsd: number\n readonly maxCells: number\n readonly maxWallMs: number\n}\n\nexport interface ProductBenchmarkManifest {\n readonly schemaVersion: 1\n readonly projectId: string\n readonly benchmarkId: string\n readonly repo: ProductBenchmarkRepoRef\n readonly substrate: ProductBenchmarkSubstrateVersions\n readonly profiles: readonly ProductBenchmarkProfileRef[]\n readonly arms: readonly ProductBenchmarkArm[]\n readonly scenarios: readonly ProductBenchmarkScenario[]\n readonly budgets: ProductBenchmarkBudgets\n readonly expectedArtifactDir: string\n}\n\nexport interface AgentProfileRuntimeReceipt {\n readonly model: string\n readonly harness: string\n readonly backend: string\n readonly reasoningEffort?: string\n}\n\nexport type RuntimeResolution = AgentProfileRuntimeReceipt\n\nexport interface ProductBenchmarkRecord {\n readonly schemaVersion: 1\n readonly projectId: string\n readonly benchmarkId: string\n readonly runId: string\n readonly scenarioId: string\n readonly split: ProductBenchmarkSplit\n readonly armId: string\n readonly rep: number\n readonly agentProfile: {\n readonly id: string\n readonly hash: string\n readonly path: string\n readonly declared: RuntimeResolution\n readonly resolved: RuntimeResolution\n }\n readonly model: {\n readonly provider: string\n readonly id: string\n }\n readonly backend: {\n readonly kind: string\n readonly version: string\n }\n readonly outcome: {\n readonly pass: boolean\n readonly score: number\n readonly dimensions: Record<string, number>\n readonly failureMode: string | null\n }\n readonly usage: {\n readonly inputTokens: number\n readonly outputTokens: number\n readonly costUsd: number\n readonly wallMs: number\n readonly toolCalls: number\n }\n readonly integrity: {\n readonly realBackend: boolean\n readonly rawCapture: boolean\n readonly traceCapture: boolean\n readonly noStubRows: boolean\n readonly priced: boolean\n readonly profileMaterialized: boolean\n }\n readonly artifacts: {\n readonly records: string\n readonly traces: string\n readonly raws: string\n readonly scores: string\n readonly workspace: string\n }\n}\n\nexport interface ProductBenchmarkRunInput {\n readonly manifestPath: string\n readonly recordsPath: string\n readonly artifactRoot?: string\n readonly checkArtifacts?: boolean\n}\n\nexport interface ProductBenchmarkValidationReport {\n readonly manifestPath: string\n readonly recordsPath: string\n readonly records: number\n /** Manifest repo fields that are empty or the `'unknown'` export sentinel. */\n readonly repoFailures: readonly string[]\n /** Manifest substrate versions that are empty or the `'unknown'` export\n * sentinel — a bundle without substrate identity is not reproducible. */\n readonly substrateFailures: readonly string[]\n readonly projects: readonly string[]\n readonly benchmarks: readonly string[]\n readonly arms: readonly string[]\n readonly scenarios: readonly string[]\n readonly passed: number\n readonly failed: number\n readonly inputTokens: number\n readonly outputTokens: number\n readonly costUsd: number\n readonly wallMs: number\n readonly integrityFailures: readonly string[]\n readonly missingArtifacts: readonly string[]\n}\n\nexport interface ProductBenchmarkArtifactPaths {\n readonly manifestPath: string\n readonly recordsPath: string\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction fail(path: string, message: string): never {\n throw new ValidationError(`${path}: ${message}`)\n}\n\nfunction wrapValidationError(path: string, err: unknown): never {\n if (err instanceof ValidationError) {\n throw new ValidationError(`${path}: ${err.message}`, { cause: err })\n }\n throw new ValidationError(`${path}: ${err instanceof Error ? err.message : String(err)}`, {\n cause: err,\n })\n}\n\nfunction expectObject(value: unknown, path: string): Record<string, unknown> {\n if (!isObject(value)) fail(path, 'must be an object')\n return value\n}\n\nfunction expectString(value: unknown, path: string): string {\n if (typeof value !== 'string' || value.trim().length === 0)\n fail(path, 'must be a non-empty string')\n return value\n}\n\nfunction expectBoolean(value: unknown, path: string): boolean {\n if (typeof value !== 'boolean') fail(path, 'must be a boolean')\n return value\n}\n\nfunction expectNumber(\n value: unknown,\n path: string,\n opts: { readonly min?: number; readonly max?: number; readonly integer?: boolean } = {},\n): number {\n if (typeof value !== 'number' || !Number.isFinite(value)) fail(path, 'must be a finite number')\n if (opts.integer && !Number.isInteger(value)) fail(path, 'must be an integer')\n if (opts.min !== undefined && value < opts.min) fail(path, `must be >= ${opts.min}`)\n if (opts.max !== undefined && value > opts.max) fail(path, `must be <= ${opts.max}`)\n return value\n}\n\nfunction expectStringArray(value: unknown, path: string): string[] {\n if (!Array.isArray(value)) fail(path, 'must be an array')\n return value.map((entry, index) => expectString(entry, `${path}[${index}]`))\n}\n\nfunction expectObjectArray(value: unknown, path: string): Record<string, unknown>[] {\n if (!Array.isArray(value)) fail(path, 'must be an array')\n return value.map((entry, index) => expectObject(entry, `${path}[${index}]`))\n}\n\nfunction expectSplit(value: unknown, path: string): ProductBenchmarkSplit {\n const split = expectString(value, path)\n if (!productBenchmarkSplits.includes(split as ProductBenchmarkSplit)) {\n fail(path, `must be one of ${productBenchmarkSplits.join(', ')}`)\n }\n return split as ProductBenchmarkSplit\n}\n\nfunction optionalString(value: unknown, path: string): string | undefined {\n if (value === undefined) return undefined\n return expectString(value, path)\n}\n\nfunction expectDimensions(value: unknown, path: string): Record<string, number> {\n const obj = expectObject(value, path)\n const out: Record<string, number> = {}\n for (const [key, raw] of Object.entries(obj)) out[key] = expectNumber(raw, `${path}.${key}`)\n return out\n}\n\nfunction expectRuntimeResolution(value: unknown, path: string): RuntimeResolution {\n const obj = expectObject(value, path)\n return {\n model: expectString(obj.model, `${path}.model`),\n harness: expectString(obj.harness, `${path}.harness`),\n backend: expectString(obj.backend, `${path}.backend`),\n ...(obj.reasoningEffort !== undefined\n ? { reasoningEffort: optionalString(obj.reasoningEffort, `${path}.reasoningEffort`) }\n : {}),\n }\n}\n\nexport function validateProductBenchmarkManifest(value: unknown): ProductBenchmarkManifest {\n const obj = expectObject(value, 'manifest')\n if (obj.schemaVersion !== 1) fail('manifest.schemaVersion', 'must be 1')\n const repo = expectObject(obj.repo, 'manifest.repo')\n const substrate = expectObject(obj.substrate, 'manifest.substrate')\n const profiles = expectObjectArray(obj.profiles, 'manifest.profiles').map((profile, index) => ({\n id: expectString(profile.id, `manifest.profiles[${index}].id`),\n profileHash: expectString(profile.profileHash, `manifest.profiles[${index}].profileHash`),\n agentProfilePath: expectString(\n profile.agentProfilePath,\n `manifest.profiles[${index}].agentProfilePath`,\n ),\n }))\n const arms = expectObjectArray(obj.arms, 'manifest.arms').map((arm, index) => ({\n id: expectString(arm.id, `manifest.arms[${index}].id`),\n profileId: expectString(arm.profileId, `manifest.arms[${index}].profileId`),\n mutableSurfaces: expectStringArray(\n arm.mutableSurfaces,\n `manifest.arms[${index}].mutableSurfaces`,\n ),\n policyAxes: expectObject(arm.policyAxes, `manifest.arms[${index}].policyAxes`),\n }))\n const scenarios = expectObjectArray(obj.scenarios, 'manifest.scenarios').map(\n (scenario, index) => ({\n id: expectString(scenario.id, `manifest.scenarios[${index}].id`),\n split: expectSplit(scenario.split, `manifest.scenarios[${index}].split`),\n tags: expectStringArray(scenario.tags, `manifest.scenarios[${index}].tags`),\n sourceAllowedForSynthesis: expectBoolean(\n scenario.sourceAllowedForSynthesis,\n `manifest.scenarios[${index}].sourceAllowedForSynthesis`,\n ),\n }),\n )\n const budgets = expectObject(obj.budgets, 'manifest.budgets')\n if (profiles.length === 0) fail('manifest.profiles', 'must contain at least one profile')\n if (arms.length === 0) fail('manifest.arms', 'must contain at least one arm')\n if (scenarios.length === 0) fail('manifest.scenarios', 'must contain at least one scenario')\n assertUnique(\n profiles.map((profile) => profile.id),\n 'manifest.profiles.id',\n )\n assertUnique(\n arms.map((arm) => arm.id),\n 'manifest.arms.id',\n )\n assertUnique(\n scenarios.map((scenario) => scenario.id),\n 'manifest.scenarios.id',\n )\n const profileIds = new Set(profiles.map((profile) => profile.id))\n for (const arm of arms) {\n if (!profileIds.has(arm.profileId))\n fail(`manifest.arms.${arm.id}.profileId`, `unknown profile ${arm.profileId}`)\n }\n return {\n schemaVersion: 1,\n projectId: expectString(obj.projectId, 'manifest.projectId'),\n benchmarkId: expectString(obj.benchmarkId, 'manifest.benchmarkId'),\n repo: {\n url: expectString(repo.url, 'manifest.repo.url'),\n commit: expectString(repo.commit, 'manifest.repo.commit'),\n branch: expectString(repo.branch, 'manifest.repo.branch'),\n },\n substrate: {\n agentEval: expectString(substrate.agentEval, 'manifest.substrate.agentEval'),\n agentRuntime: expectString(substrate.agentRuntime, 'manifest.substrate.agentRuntime'),\n agentInterface: expectString(substrate.agentInterface, 'manifest.substrate.agentInterface'),\n sandbox: expectString(substrate.sandbox, 'manifest.substrate.sandbox'),\n ...(substrate.agentBench !== undefined\n ? { agentBench: expectString(substrate.agentBench, 'manifest.substrate.agentBench') }\n : {}),\n },\n profiles,\n arms,\n scenarios,\n budgets: {\n maxUsd: expectNumber(budgets.maxUsd, 'manifest.budgets.maxUsd', { min: 0 }),\n maxCells: expectNumber(budgets.maxCells, 'manifest.budgets.maxCells', {\n min: 0,\n integer: true,\n }),\n maxWallMs: expectNumber(budgets.maxWallMs, 'manifest.budgets.maxWallMs', {\n min: 0,\n integer: true,\n }),\n },\n expectedArtifactDir: expectString(obj.expectedArtifactDir, 'manifest.expectedArtifactDir'),\n }\n}\n\nexport function validateProductBenchmarkRecord(value: unknown): ProductBenchmarkRecord {\n const obj = expectObject(value, 'record')\n if (obj.schemaVersion !== 1) fail('record.schemaVersion', 'must be 1')\n const agentProfile = expectObject(obj.agentProfile, 'record.agentProfile')\n const model = expectObject(obj.model, 'record.model')\n const backend = expectObject(obj.backend, 'record.backend')\n const outcome = expectObject(obj.outcome, 'record.outcome')\n const usage = expectObject(obj.usage, 'record.usage')\n const integrity = expectObject(obj.integrity, 'record.integrity')\n const artifacts = expectObject(obj.artifacts, 'record.artifacts')\n const record: ProductBenchmarkRecord = {\n schemaVersion: 1,\n projectId: expectString(obj.projectId, 'record.projectId'),\n benchmarkId: expectString(obj.benchmarkId, 'record.benchmarkId'),\n runId: expectString(obj.runId, 'record.runId'),\n scenarioId: expectString(obj.scenarioId, 'record.scenarioId'),\n split: expectSplit(obj.split, 'record.split'),\n armId: expectString(obj.armId, 'record.armId'),\n rep: expectNumber(obj.rep, 'record.rep', { min: 1, integer: true }),\n agentProfile: {\n id: expectString(agentProfile.id, 'record.agentProfile.id'),\n hash: expectString(agentProfile.hash, 'record.agentProfile.hash'),\n path: expectString(agentProfile.path, 'record.agentProfile.path'),\n declared: expectRuntimeResolution(agentProfile.declared, 'record.agentProfile.declared'),\n resolved: expectRuntimeResolution(agentProfile.resolved, 'record.agentProfile.resolved'),\n },\n model: {\n provider: expectString(model.provider, 'record.model.provider'),\n id: expectString(model.id, 'record.model.id'),\n },\n backend: {\n kind: expectString(backend.kind, 'record.backend.kind'),\n version: expectString(backend.version, 'record.backend.version'),\n },\n outcome: {\n pass: expectBoolean(outcome.pass, 'record.outcome.pass'),\n score: expectNumber(outcome.score, 'record.outcome.score', { min: 0, max: 1 }),\n dimensions: expectDimensions(outcome.dimensions, 'record.outcome.dimensions'),\n failureMode:\n outcome.failureMode === null\n ? null\n : expectString(outcome.failureMode, 'record.outcome.failureMode'),\n },\n usage: {\n inputTokens: expectNumber(usage.inputTokens, 'record.usage.inputTokens', {\n min: 0,\n integer: true,\n }),\n outputTokens: expectNumber(usage.outputTokens, 'record.usage.outputTokens', {\n min: 0,\n integer: true,\n }),\n costUsd: expectNumber(usage.costUsd, 'record.usage.costUsd', { min: 0 }),\n wallMs: expectNumber(usage.wallMs, 'record.usage.wallMs', { min: 0, integer: true }),\n toolCalls: expectNumber(usage.toolCalls, 'record.usage.toolCalls', { min: 0, integer: true }),\n },\n integrity: {\n realBackend: expectBoolean(integrity.realBackend, 'record.integrity.realBackend'),\n rawCapture: expectBoolean(integrity.rawCapture, 'record.integrity.rawCapture'),\n traceCapture: expectBoolean(integrity.traceCapture, 'record.integrity.traceCapture'),\n noStubRows: expectBoolean(integrity.noStubRows, 'record.integrity.noStubRows'),\n priced: expectBoolean(integrity.priced, 'record.integrity.priced'),\n profileMaterialized: expectBoolean(\n integrity.profileMaterialized,\n 'record.integrity.profileMaterialized',\n ),\n },\n artifacts: {\n records: expectString(artifacts.records, 'record.artifacts.records'),\n traces: expectString(artifacts.traces, 'record.artifacts.traces'),\n raws: expectString(artifacts.raws, 'record.artifacts.raws'),\n scores: expectString(artifacts.scores, 'record.artifacts.scores'),\n workspace: expectString(artifacts.workspace, 'record.artifacts.workspace'),\n },\n }\n if (record.integrity.realBackend && record.usage.inputTokens + record.usage.outputTokens === 0) {\n fail('record.usage', 'realBackend rows must carry non-zero token usage')\n }\n return record\n}\n\nexport function productBenchmarkIntegrityFailures(record: ProductBenchmarkRecord): string[] {\n const failures: string[] = []\n for (const [key, value] of Object.entries(record.integrity)) {\n if (!value) failures.push(`${record.runId}:${key}=false`)\n }\n return failures\n}\n\nexport function readProductBenchmarkRecords(path: string): ProductBenchmarkRecord[] {\n const lines = readFileSync(path, 'utf8')\n .split('\\n')\n .map((line) => line.trim())\n .filter(Boolean)\n const records: ProductBenchmarkRecord[] = []\n for (const [index, line] of lines.entries()) {\n try {\n records.push(validateProductBenchmarkRecord(JSON.parse(line)))\n } catch (err) {\n wrapValidationError(`${path}:${index + 1}`, err)\n }\n }\n return records\n}\n\nexport function readProductBenchmarkManifest(path: string): ProductBenchmarkManifest {\n try {\n return validateProductBenchmarkManifest(JSON.parse(readFileSync(path, 'utf8')))\n } catch (err) {\n wrapValidationError(path, err)\n }\n}\n\nexport function validateProductBenchmarkRun(\n input: ProductBenchmarkRunInput,\n): ProductBenchmarkValidationReport {\n const manifest = readProductBenchmarkManifest(input.manifestPath)\n const records = readProductBenchmarkRecords(input.recordsPath)\n const manifestProjectBench = `${manifest.projectId}/${manifest.benchmarkId}`\n const integrityFailures = records.flatMap(productBenchmarkIntegrityFailures)\n const missingArtifacts =\n input.checkArtifacts === false\n ? []\n : records.flatMap((record) =>\n missingArtifactsForRecord(record, input.artifactRoot ?? dirname(input.recordsPath)),\n )\n for (const [index, record] of records.entries()) {\n const recordProjectBench = `${record.projectId}/${record.benchmarkId}`\n if (recordProjectBench !== manifestProjectBench) {\n fail(\n `records[${index}]`,\n `project/benchmark ${recordProjectBench} does not match manifest ${manifestProjectBench}`,\n )\n }\n if (!manifest.arms.some((arm) => arm.id === record.armId))\n fail(`records[${index}].armId`, `unknown arm ${record.armId}`)\n if (!manifest.scenarios.some((scenario) => scenario.id === record.scenarioId)) {\n fail(`records[${index}].scenarioId`, `unknown scenario ${record.scenarioId}`)\n }\n }\n const repoFailures = (['url', 'commit', 'branch'] as const)\n .filter((key) => manifest.repo[key].trim().length === 0 || manifest.repo[key] === 'unknown')\n .map((key) => `manifest.repo.${key}`)\n const substrateFailures = (['agentEval', 'agentRuntime', 'agentInterface', 'sandbox'] as const)\n .filter(\n (key) => manifest.substrate[key].trim().length === 0 || manifest.substrate[key] === 'unknown',\n )\n .map((key) => `manifest.substrate.${key}`)\n return {\n manifestPath: input.manifestPath,\n recordsPath: input.recordsPath,\n records: records.length,\n repoFailures,\n substrateFailures,\n projects: sortedUnique(records.map((record) => record.projectId)),\n benchmarks: sortedUnique(records.map((record) => record.benchmarkId)),\n arms: sortedUnique(records.map((record) => record.armId)),\n scenarios: sortedUnique(records.map((record) => record.scenarioId)),\n passed: records.filter((record) => record.outcome.pass).length,\n failed: records.filter((record) => !record.outcome.pass).length,\n inputTokens: sum(records, (record) => record.usage.inputTokens),\n outputTokens: sum(records, (record) => record.usage.outputTokens),\n costUsd: sum(records, (record) => record.usage.costUsd),\n wallMs: sum(records, (record) => record.usage.wallMs),\n integrityFailures,\n missingArtifacts,\n }\n}\n\nfunction missingArtifactsForRecord(record: ProductBenchmarkRecord, artifactRoot: string): string[] {\n const missing: string[] = []\n for (const [key, value] of Object.entries(record.artifacts)) {\n const path = resolveArtifactPath(value, artifactRoot)\n if (!existsSync(path)) missing.push(`${record.runId}:${key}:${value}`)\n }\n return missing\n}\n\nfunction resolveArtifactPath(value: string, artifactRoot: string): string {\n return value.startsWith('/') ? value : join(artifactRoot, value)\n}\n\nfunction assertUnique(values: readonly string[], path: string): void {\n const seen = new Set<string>()\n for (const value of values) {\n if (seen.has(value)) fail(path, `duplicate ${value}`)\n seen.add(value)\n }\n}\n\nfunction sortedUnique(values: readonly string[]): string[] {\n return [...new Set(values)].sort()\n}\n\nfunction sum<T>(items: readonly T[], fn: (item: T) => number): number {\n return items.reduce((total, item) => total + fn(item), 0)\n}\n\nexport function findProductBenchmarkArtifacts(\n runDir: string,\n): ProductBenchmarkArtifactPaths | null {\n const manifestPath = join(runDir, 'product-benchmark-manifest.json')\n const recordsPath = join(runDir, 'product-benchmark-records.jsonl')\n if (\n existsSync(manifestPath) &&\n statSync(manifestPath).isFile() &&\n existsSync(recordsPath) &&\n statSync(recordsPath).isFile()\n ) {\n return { manifestPath, recordsPath }\n }\n return null\n}\n\n/**\n * Fail-loud gate over a bundle directory: locates the manifest + records,\n * runs `validateProductBenchmarkRun`, and throws with every repo,\n * integrity, and artifact failure listed. Returns the report when clean.\n */\nexport function assertProductBenchmarkRun(runDir: string): ProductBenchmarkValidationReport {\n const artifacts = findProductBenchmarkArtifacts(runDir)\n if (!artifacts) {\n fail(runDir, 'missing product-benchmark-manifest.json or product-benchmark-records.jsonl')\n }\n const report = validateProductBenchmarkRun({ ...artifacts, artifactRoot: runDir })\n const failures = [\n ...report.repoFailures,\n ...report.substrateFailures,\n ...report.integrityFailures,\n ...report.missingArtifacts,\n ]\n if (failures.length > 0) {\n fail(runDir, `product benchmark validation failed:\\n${failures.join('\\n')}`)\n }\n return report\n}\n\nexport type {\n ProductBenchmarkExportOptions,\n ProductBenchmarkExportResult,\n ProductBenchmarkSingleRunExportOptions,\n} from './export'\nexport {\n buildProductBenchmarkManifest,\n exportProductBenchmark,\n exportProductBenchmarkRuns,\n productBenchmarkMutableSurfaces,\n productBenchmarkRepoIdentity,\n runRecordToProductBenchmarkRecord,\n} from './export'\n","/**\n * Export side of the product benchmark bundle contract: convert product\n * eval run directories (`records.jsonl` of `RunRecord` rows + trace/raw\n * artifacts) into a portable `product-benchmark-manifest.json` +\n * `product-benchmark-records.jsonl` bundle that\n * `validateProductBenchmarkRun` accepts.\n *\n * Product-specific policy (safety-split detection, tool-call recovery,\n * profile id fallback, artifact materialization) enters through explicit\n * options; everything else is the shared union of the tax/legal/creative\n * exporters. Scenario catalogs, smoke runners, and CLIs stay in the\n * products.\n *\n * Input rows are checked structurally, not with `validateRunRecord`:\n * product harnesses record bare model aliases and partial provenance, and\n * the bundle contract's own validators re-check every field that matters\n * on the way out.\n */\n\nimport { spawnSync } from 'node:child_process'\nimport { createHash } from 'node:crypto'\nimport { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'\nimport { ValidationError } from '../errors'\nimport type { RunRecord } from '../run-record'\nimport type {\n ProductBenchmarkManifest,\n ProductBenchmarkRecord,\n ProductBenchmarkSplit,\n RuntimeResolution,\n} from './index'\nimport { validateProductBenchmarkManifest, validateProductBenchmarkRecord } from './index'\n\n/** Full mutable-surface superset a product arm may declare. */\nexport const productBenchmarkMutableSurfaces = [\n 'prompt',\n 'resources.files',\n 'tools',\n 'mcp',\n 'hooks',\n 'subagents',\n] as const\n\nexport interface ProductBenchmarkExportOptions {\n /** Source eval run directories, each containing a `records.jsonl` of RunRecord rows. */\n readonly runDirs: readonly string[]\n /** Destination directory for the bundle (manifest + records + materialized source runs). */\n readonly outDir: string\n readonly projectId: string\n readonly benchmarkId: string\n /** Repo-relative path of the product's canonical agent profile source. */\n readonly agentProfilePath: string\n /** Pass threshold applied when a row carries no explicit `outcome.raw.pass`. Default 0.7. */\n readonly passThreshold?: number\n /**\n * First scenario tag. Defaults to `projectId` with a trailing `-agent`\n * stripped (`tax-agent` → `tax`), matching the product exporters.\n */\n readonly scenarioTagPrefix?: string\n /** Profile id used when a row has no `agentProfile.profileId`. Defaults to the row's arm id. */\n readonly fallbackProfileId?: string\n /** Arm mutable surfaces recorded in the manifest. Defaults to the full superset. */\n readonly mutableSurfaces?: readonly string[]\n /**\n * Copy each run dir into `<outDir>/source-runs/` and record\n * bundle-relative artifact paths (portable, self-contained). When false,\n * artifacts keep absolute paths into the original run dirs. Default true.\n */\n readonly materializeSourceRuns?: boolean\n /**\n * Override split classification for a row. Return undefined to fall back\n * to the default (`outcome.raw.safety === 1` → safety, then splitTag).\n */\n readonly classifySplit?: (record: RunRecord) => ProductBenchmarkSplit | undefined\n /** Recovers a tool-call count when the row's raw bag carries none (e.g. from turn artifacts). */\n readonly toolCallFallback?: (record: RunRecord, runDir: string) => number\n /** Backend version recorded per row. Defaults to the cwd package.json's `@tangle-network/sandbox` range. */\n readonly backendVersion?: string\n /**\n * Explicit substrate versions for the manifest, merged over what the cwd\n * package.json / node_modules resolve. Use when a substrate package is not\n * installed where the export runs — the validator refuses an `'unknown'`\n * version, so provide the real one rather than shipping the sentinel.\n */\n readonly substrate?: Partial<ProductBenchmarkManifest['substrate']>\n}\n\nexport interface ProductBenchmarkSingleRunExportOptions\n extends Omit<ProductBenchmarkExportOptions, 'runDirs'> {\n readonly runDir: string\n}\n\nexport interface ProductBenchmarkExportResult {\n readonly manifestPath: string\n readonly recordsPath: string\n readonly records: number\n}\n\ninterface ResolvedExportOptions {\n readonly projectId: string\n readonly benchmarkId: string\n readonly agentProfilePath: string\n readonly passThreshold: number\n readonly scenarioTagPrefix: string\n readonly fallbackProfileId?: string\n readonly mutableSurfaces: readonly string[]\n readonly classifySplit?: (record: RunRecord) => ProductBenchmarkSplit | undefined\n readonly toolCallFallback?: (record: RunRecord, runDir: string) => number\n readonly backendVersion: string\n}\n\n// ── Provenance helpers ───────────────────────────────────────────────\n\nfunction sha256(value: string): string {\n return `sha256:${createHash('sha256').update(value).digest('hex')}`\n}\n\nfunction safePathPart(value: string): string {\n return (\n value\n .replace(/[^a-zA-Z0-9_.-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 80) || 'artifact'\n )\n}\n\nfunction git(args: readonly string[], fallback: string): string {\n const res = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8' })\n const value = res.status === 0 ? res.stdout.trim() : ''\n return value.length > 0 ? value : fallback\n}\n\nfunction knownEnv(name: string): string | undefined {\n const value = process.env[name]?.trim()\n return value && value !== 'unknown' ? value : undefined\n}\n\nfunction ciBranchName(): string | undefined {\n const direct =\n knownEnv('GITHUB_HEAD_REF') ?? knownEnv('GITHUB_REF_NAME') ?? knownEnv('VERCEL_GIT_COMMIT_REF')\n if (direct) return direct\n const ref = knownEnv('GITHUB_REF')\n return ref?.startsWith('refs/heads/') ? ref.slice('refs/heads/'.length) : undefined\n}\n\nfunction repoBranch(): string {\n const ci = ciBranchName()\n if (ci) return ci\n const branch = git(['branch', '--show-current'], '')\n if (branch) return branch\n const name = git(['name-rev', '--name-only', '--exclude=tags/*', 'HEAD'], '')\n if (name && name !== 'undefined') return name\n return `detached:${git(['rev-parse', '--short', 'HEAD'], 'unknown')}`\n}\n\n/** Repo identity from the exporting process's cwd. `'unknown'` values are flagged by `validateProductBenchmarkRun`. */\nexport function productBenchmarkRepoIdentity(): ProductBenchmarkManifest['repo'] {\n return {\n url: git(['config', '--get', 'remote.origin.url'], 'unknown'),\n commit: git(['rev-parse', 'HEAD'], 'unknown'),\n branch: repoBranch(),\n }\n}\n\n/** The declared range from the cwd package.json when present, else the\n * INSTALLED version read from node_modules (covers transitive installs —\n * a product that gets sandbox via agent-runtime still records real\n * provenance), else the `'unknown'` sentinel the validator refuses. */\nfunction packageVersion(name: string): string {\n const pkg = JSON.parse(readFileSync(resolve('package.json'), 'utf8')) as {\n name?: string\n version?: string\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n }\n if (pkg.name === name && pkg.version) return pkg.version\n const declared = pkg.dependencies?.[name] ?? pkg.devDependencies?.[name]\n if (declared) return declared\n const installed = resolve('node_modules', name, 'package.json')\n if (existsSync(installed)) {\n const installedPkg = JSON.parse(readFileSync(installed, 'utf8')) as { version?: string }\n if (installedPkg.version) return installedPkg.version\n }\n return 'unknown'\n}\n\n// ── Run record ingestion ─────────────────────────────────────────────\n\nfunction readRunRecords(path: string): RunRecord[] {\n const lines = readFileSync(path, 'utf8')\n .split('\\n')\n .map((line) => line.trim())\n .filter(Boolean)\n return lines.map((line, index) => {\n let parsed: unknown\n try {\n parsed = JSON.parse(line)\n } catch (err) {\n throw new ValidationError(\n `${path}:${index + 1}: ${err instanceof Error ? err.message : String(err)}`,\n { cause: err },\n )\n }\n return expectRunRecordShape(parsed, `${path}:${index + 1}`)\n })\n}\n\nfunction expectRunRecordShape(value: unknown, path: string): RunRecord {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n throw new ValidationError(`${path}: run record must be an object`)\n }\n const obj = value as Record<string, unknown>\n for (const key of ['runId', 'model'] as const) {\n if (typeof obj[key] !== 'string' || obj[key].length === 0) {\n throw new ValidationError(`${path}: run record ${key} must be a non-empty string`)\n }\n }\n for (const key of ['costUsd', 'wallMs'] as const) {\n if (typeof obj[key] !== 'number' || !Number.isFinite(obj[key])) {\n throw new ValidationError(`${path}: run record ${key} must be a finite number`)\n }\n }\n const tokenUsage = obj.tokenUsage as Record<string, unknown> | undefined\n if (\n !tokenUsage ||\n typeof tokenUsage.input !== 'number' ||\n typeof tokenUsage.output !== 'number'\n ) {\n throw new ValidationError(`${path}: run record tokenUsage.input/output must be numbers`)\n }\n const outcome = obj.outcome as Record<string, unknown> | undefined\n if (!outcome || !outcome.raw || typeof outcome.raw !== 'object') {\n throw new ValidationError(`${path}: run record outcome.raw must be an object`)\n }\n return value as RunRecord\n}\n\n// ── Row mapping ──────────────────────────────────────────────────────\n\nfunction clamp01(value: number): number {\n return Math.max(0, Math.min(1, value))\n}\n\nfunction splitOf(record: RunRecord, opts: ResolvedExportOptions): ProductBenchmarkSplit {\n const custom = opts.classifySplit?.(record)\n if (custom) return custom\n if ((record.outcome.raw as Record<string, number>).safety === 1) return 'safety'\n if (record.splitTag === 'holdout') return 'holdout'\n if (record.splitTag === 'dev') return 'dev'\n return 'practice'\n}\n\nfunction scoreOf(record: RunRecord): number {\n const score = record.outcome.holdoutScore ?? record.outcome.searchScore\n if (typeof score === 'number' && Number.isFinite(score)) return clamp01(score)\n const rawScore = record.outcome.raw.score ?? record.outcome.raw.composite\n return typeof rawScore === 'number' && Number.isFinite(rawScore) ? clamp01(rawScore) : 0\n}\n\nfunction rawPassOf(record: RunRecord): boolean | null {\n const rawPass = (record.outcome.raw as Record<string, unknown>).pass\n if (typeof rawPass === 'boolean') return rawPass\n if (typeof rawPass === 'number' && Number.isFinite(rawPass)) return rawPass >= 1\n return null\n}\n\nfunction passOf(record: RunRecord, score: number, threshold: number): boolean {\n const rawPass = rawPassOf(record)\n if (rawPass !== null) return rawPass && !record.failureMode\n return score >= threshold && !record.failureMode\n}\n\n/** A failed row always carries a failure mode; synthesized when the harness left it empty. */\nfunction failureModeOf(record: RunRecord, score: number, threshold: number): string | null {\n if (record.failureMode) return record.failureMode\n const belowThreshold = `quality-below-threshold: ${Math.round(score * 100)}% < ${Math.round(threshold * 100)}%`\n if (rawPassOf(record) === false) {\n return score < threshold ? belowThreshold : 'product-pass-failed'\n }\n if (passOf(record, score, threshold)) return null\n return belowThreshold\n}\n\nfunction numericDimensions(record: RunRecord): Record<string, number> {\n const dimensions: Record<string, number> = {}\n for (const [key, value] of Object.entries(record.outcome.raw ?? {})) {\n if (typeof value === 'number' && Number.isFinite(value)) dimensions[key] = value\n }\n if (Object.keys(dimensions).length === 0) dimensions.score = scoreOf(record)\n return dimensions\n}\n\nfunction armIdOf(record: RunRecord): string {\n if (record.candidateId) return record.candidateId\n const variant = record.agentProfile?.dimensions?.variant\n if (typeof variant === 'string' && variant.length > 0) return variant\n const variantId = record.agentProfile?.dimensions?.variantId\n if (typeof variantId === 'string' && variantId.length > 0) return variantId\n return 'production-profile'\n}\n\nfunction backendOf(record: RunRecord): string {\n const backend = record.agentProfile?.dimensions?.backend\n return typeof backend === 'string' && backend.length > 0 ? backend : 'unknown'\n}\n\nfunction modelProvider(record: RunRecord): string {\n const backend = backendOf(record)\n if (backend === 'cli-bridge') return 'cli-bridge'\n if (backend === 'sandbox') return 'router'\n if (record.model.startsWith('router/')) return 'router'\n return backend === 'unknown' ? 'router' : backend\n}\n\nfunction runtimeResolution(record: RunRecord, opts: ResolvedExportOptions): RuntimeResolution {\n const reasoningEffort = record.agentProfile?.dimensions?.reasoningLevel\n return {\n model: record.agentProfile?.model ?? record.model,\n harness: record.agentProfile?.harness?.id ?? `${opts.projectId}-canonical-eval`,\n backend: backendOf(record),\n ...(typeof reasoningEffort === 'string' && reasoningEffort.length > 0\n ? { reasoningEffort }\n : {}),\n }\n}\n\nfunction sourceProfileHash(record: RunRecord): string {\n return (\n record.agentProfile?.sourceProfile?.hash ??\n record.agentProfile?.cellId ??\n sha256(\n JSON.stringify({\n candidateId: record.candidateId,\n promptHash: record.promptHash,\n configHash: record.configHash,\n }),\n )\n )\n}\n\nfunction materializedProfileHash(record: RunRecord, runtime: RuntimeResolution): string {\n return sha256(\n JSON.stringify({ sourceProfileHash: sourceProfileHash(record), model: runtime.model }),\n )\n}\n\nfunction profileIdOf(\n record: RunRecord,\n armId: string,\n runtime: RuntimeResolution,\n opts: ResolvedExportOptions,\n): string {\n const base = record.agentProfile?.profileId ?? opts.fallbackProfileId ?? armId\n const withArm = base.endsWith(`:${armId}`) ? base : `${base}:${armId}`\n return `${withArm}:${runtime.model}`\n}\n\nfunction toolCallsOf(record: RunRecord, runDir: string, opts: ResolvedExportOptions): number {\n const raw = record.outcome.raw as Record<string, unknown>\n const primary = Number(raw.tool_call_count ?? raw.tool_calls ?? raw.toolCalls ?? 0)\n if (Number.isFinite(primary) && primary > 0) return primary\n const fallback = opts.toolCallFallback?.(record, runDir)\n if (fallback !== undefined && Number.isFinite(fallback) && fallback > 0) return fallback\n return Number.isFinite(primary) ? primary : 0\n}\n\n// ── Artifact layout ──────────────────────────────────────────────────\n\nconst TRACE_CANDIDATES = ['traces.jsonl', 'traces', 'trace', 'trace-store'] as const\nconst RAW_CANDIDATES = ['raws.jsonl', 'raw-events'] as const\nconst SCORE_CANDIDATES = ['scores.json', 'manifest.json'] as const\n\nfunction firstExisting(runDir: string, candidates: readonly string[]): string {\n return candidates.find((candidate) => existsSync(join(runDir, candidate))) ?? candidates[0]!\n}\n\nfunction relativeArtifacts(runDir: string): ProductBenchmarkRecord['artifacts'] {\n return {\n records: 'records.jsonl',\n traces: firstExisting(runDir, TRACE_CANDIDATES),\n raws: firstExisting(runDir, RAW_CANDIDATES),\n scores: firstExisting(runDir, SCORE_CANDIDATES),\n workspace: existsSync(join(runDir, 'workspace')) ? 'workspace' : '.',\n }\n}\n\nfunction absoluteArtifacts(runDir: string): ProductBenchmarkRecord['artifacts'] {\n const rel = relativeArtifacts(runDir)\n return {\n records: resolve(runDir, rel.records),\n traces: resolve(runDir, rel.traces),\n raws: resolve(runDir, rel.raws),\n scores: resolve(runDir, rel.scores),\n workspace: resolve(runDir, rel.workspace),\n }\n}\n\nfunction materializeRunArtifacts(\n runDir: string,\n outDir: string,\n index: number,\n): ProductBenchmarkRecord['artifacts'] {\n if (resolve(runDir) === resolve(outDir)) return relativeArtifacts(runDir)\n const rel = relative(runDir, outDir)\n if (rel && !rel.startsWith('..') && !isAbsolute(rel)) {\n throw new ValidationError(`outDir must not be nested inside runDir: ${outDir}`)\n }\n const id = `${String(index + 1).padStart(2, '0')}-${safePathPart(basename(runDir))}-${sha256(runDir).slice(7, 19)}`\n const destRel = join('source-runs', id)\n const destAbs = join(outDir, destRel)\n mkdirSync(dirname(destAbs), { recursive: true })\n cpSync(runDir, destAbs, { recursive: true, force: true })\n const source = relativeArtifacts(runDir)\n return {\n records: join(destRel, source.records),\n traces: join(destRel, source.traces),\n raws: join(destRel, source.raws),\n scores: join(destRel, source.scores),\n workspace: source.workspace === '.' ? destRel : join(destRel, source.workspace),\n }\n}\n\nfunction existsArtifact(artifactRoot: string, value: string): boolean {\n return existsSync(resolve(artifactRoot, value))\n}\n\n// ── Record + manifest construction ───────────────────────────────────\n\n/** Map one RunRecord row to a validated product benchmark record. */\nexport function runRecordToProductBenchmarkRecord(\n record: RunRecord,\n runDir: string,\n artifactRoot: string,\n artifacts: ProductBenchmarkRecord['artifacts'],\n options: ProductBenchmarkExportOptions | ProductBenchmarkSingleRunExportOptions,\n): ProductBenchmarkRecord {\n const opts = resolveOptions(options)\n const runtime = runtimeResolution(record, opts)\n const score = scoreOf(record)\n const armId = armIdOf(record)\n const inputTokens = record.tokenUsage.input\n const outputTokens = record.tokenUsage.output\n const toolCallCount = toolCallsOf(record, runDir, opts)\n const dimensions = numericDimensions(record)\n if (!('tool_calls' in dimensions)) dimensions.tool_calls = toolCallCount\n const product: ProductBenchmarkRecord = {\n schemaVersion: 1,\n projectId: opts.projectId,\n benchmarkId: opts.benchmarkId,\n runId: record.runId,\n scenarioId: record.scenarioId ?? record.experimentId,\n split: splitOf(record, opts),\n armId,\n rep: Number(record.seed ?? 0) + 1,\n agentProfile: {\n id: profileIdOf(record, armId, runtime, opts),\n hash: materializedProfileHash(record, runtime),\n path: opts.agentProfilePath,\n declared: runtime,\n resolved: runtime,\n },\n model: { provider: modelProvider(record), id: record.model },\n backend: { kind: backendOf(record), version: opts.backendVersion },\n outcome: {\n pass: passOf(record, score, opts.passThreshold),\n score,\n dimensions,\n failureMode: failureModeOf(record, score, opts.passThreshold),\n },\n usage: {\n inputTokens,\n outputTokens,\n costUsd: record.costUsd,\n // Rounded: the bundle contract requires integer milliseconds.\n wallMs: Math.round(record.wallMs),\n toolCalls: toolCallCount,\n },\n integrity: {\n realBackend: inputTokens + outputTokens > 0,\n rawCapture: existsArtifact(artifactRoot, artifacts.raws),\n traceCapture: existsArtifact(artifactRoot, artifacts.traces),\n noStubRows: inputTokens + outputTokens > 0,\n priced: record.costUsd > 0,\n profileMaterialized: Boolean(record.agentProfile?.cellId),\n },\n artifacts,\n }\n return validateProductBenchmarkRecord(product)\n}\n\n/** One record per arm id, failing loud when records sharing an arm id\n * disagree on any attribute the manifest arm carries (profile, model,\n * backend, harness, reasoning effort) — an id-only dedup would silently\n * keep one policy and misrepresent the rest. */\nfunction uniqueArmRecords(records: readonly ProductBenchmarkRecord[]): ProductBenchmarkRecord[] {\n const byArm = new Map<string, ProductBenchmarkRecord>()\n for (const record of records) {\n const prior = byArm.get(record.armId)\n if (!prior) {\n byArm.set(record.armId, record)\n continue\n }\n const fields = [\n ['profileId', prior.agentProfile.id, record.agentProfile.id],\n ['model', prior.agentProfile.resolved.model, record.agentProfile.resolved.model],\n ['backend', prior.agentProfile.resolved.backend, record.agentProfile.resolved.backend],\n ['harness', prior.agentProfile.resolved.harness, record.agentProfile.resolved.harness],\n [\n 'reasoningEffort',\n prior.agentProfile.resolved.reasoningEffort,\n record.agentProfile.resolved.reasoningEffort,\n ],\n ] as const\n for (const [name, a, b] of fields) {\n if (a !== b) {\n throw new ValidationError(\n `records for arm '${record.armId}' disagree on ${name} (${String(a)} vs ${String(b)}) — one arm id must map to one policy`,\n )\n }\n }\n }\n return [...byArm.values()]\n}\n\n/** One record per scenario id, failing loud on a divergent split — the\n * manifest scenario carries one split, so two records disagreeing would be\n * silently misfiled. */\nfunction uniqueScenarioRecords(\n records: readonly ProductBenchmarkRecord[],\n): ProductBenchmarkRecord[] {\n const byScenario = new Map<string, ProductBenchmarkRecord>()\n for (const record of records) {\n const prior = byScenario.get(record.scenarioId)\n if (!prior) {\n byScenario.set(record.scenarioId, record)\n continue\n }\n if (prior.split !== record.split) {\n throw new ValidationError(\n `records for scenario '${record.scenarioId}' disagree on split (${prior.split} vs ${record.split})`,\n )\n }\n }\n return [...byScenario.values()]\n}\n\n/** Derive the bundle manifest from already-normalized records. */\nexport function buildProductBenchmarkManifest(\n records: readonly ProductBenchmarkRecord[],\n options: Pick<\n ProductBenchmarkExportOptions,\n 'outDir' | 'projectId' | 'benchmarkId' | 'scenarioTagPrefix' | 'mutableSurfaces' | 'substrate'\n >,\n): ProductBenchmarkManifest {\n if (records.length === 0) {\n throw new ValidationError('cannot build a product benchmark manifest from zero records')\n }\n const scenarioTagPrefix = options.scenarioTagPrefix ?? defaultScenarioTagPrefix(options.projectId)\n const mutableSurfaces = options.mutableSurfaces ?? productBenchmarkMutableSurfaces\n const byProfile = new Map<string, ProductBenchmarkManifest['profiles'][number]>()\n for (const record of records) {\n byProfile.set(record.agentProfile.id, {\n id: record.agentProfile.id,\n profileHash: record.agentProfile.hash,\n agentProfilePath: record.agentProfile.path,\n })\n }\n const manifest: ProductBenchmarkManifest = {\n schemaVersion: 1,\n projectId: options.projectId,\n benchmarkId: options.benchmarkId,\n repo: productBenchmarkRepoIdentity(),\n substrate: {\n agentEval: packageVersion('@tangle-network/agent-eval'),\n agentRuntime: packageVersion('@tangle-network/agent-runtime'),\n agentInterface: packageVersion('@tangle-network/agent-interface'),\n sandbox: packageVersion('@tangle-network/sandbox'),\n ...options.substrate,\n },\n profiles: [...byProfile.values()],\n arms: uniqueArmRecords(records).map((record) => ({\n id: record.armId,\n profileId: record.agentProfile.id,\n mutableSurfaces: [...mutableSurfaces],\n policyAxes: {\n carrier: record.armId.includes('policy') ? 'resource-file' : 'profile',\n model: record.agentProfile.resolved.model,\n backend: record.agentProfile.resolved.backend,\n harness: record.agentProfile.resolved.harness,\n ...(record.agentProfile.resolved.reasoningEffort !== undefined\n ? { reasoningEffort: record.agentProfile.resolved.reasoningEffort }\n : {}),\n },\n })),\n scenarios: uniqueScenarioRecords(records).map((record) => ({\n id: record.scenarioId,\n split: record.split,\n tags: [scenarioTagPrefix, options.benchmarkId, record.split],\n sourceAllowedForSynthesis: false,\n })),\n budgets: {\n maxUsd: records.reduce((sum, record) => sum + record.usage.costUsd, 0),\n maxCells: records.length,\n maxWallMs: records.reduce((sum, record) => sum + record.usage.wallMs, 0),\n },\n expectedArtifactDir: resolve(options.outDir),\n }\n return validateProductBenchmarkManifest(manifest)\n}\n\n// ── Entry points ─────────────────────────────────────────────────────\n\n/** Single-run convenience wrapper over `exportProductBenchmarkRuns`. */\nexport function exportProductBenchmark(\n options: ProductBenchmarkSingleRunExportOptions,\n): ProductBenchmarkExportResult {\n const { runDir, ...rest } = options\n return exportProductBenchmarkRuns({ ...rest, runDirs: [runDir] })\n}\n\n/**\n * Export one or more product eval run dirs into a validated product\n * benchmark bundle at `outDir`. Both the manifest and every record are\n * run through the contract validators before anything is written.\n */\nexport function exportProductBenchmarkRuns(\n options: ProductBenchmarkExportOptions,\n): ProductBenchmarkExportResult {\n const opts = resolveOptions(options)\n const outDir = resolve(options.outDir)\n const runDirs = options.runDirs.map((runDir) => resolve(runDir))\n if (runDirs.length === 0) throw new ValidationError('export requires at least one run directory')\n const materialize = options.materializeSourceRuns !== false\n const rows = runDirs.flatMap((runDir) => {\n const sourceRecordsPath = join(runDir, 'records.jsonl')\n if (!existsSync(sourceRecordsPath)) throw new ValidationError(`missing ${sourceRecordsPath}`)\n const records = readRunRecords(sourceRecordsPath)\n if (records.length === 0) throw new ValidationError(`${sourceRecordsPath} is empty`)\n return records.map((record) => ({ record, runDir }))\n })\n mkdirSync(outDir, { recursive: true })\n const artifactsByRunDir = new Map<string, ProductBenchmarkRecord['artifacts']>()\n for (const [index, runDir] of runDirs.entries()) {\n artifactsByRunDir.set(\n runDir,\n materialize ? materializeRunArtifacts(runDir, outDir, index) : absoluteArtifacts(runDir),\n )\n }\n const artifactRoot = materialize ? outDir : '/'\n const normalized = rows.map(({ record, runDir }) =>\n runRecordToProductBenchmarkRecord(\n record,\n runDir,\n artifactRoot,\n artifactsByRunDir.get(runDir)!,\n { ...options, runDirs, backendVersion: opts.backendVersion },\n ),\n )\n const manifest = buildProductBenchmarkManifest(normalized, {\n outDir,\n projectId: opts.projectId,\n benchmarkId: opts.benchmarkId,\n scenarioTagPrefix: opts.scenarioTagPrefix,\n mutableSurfaces: opts.mutableSurfaces,\n ...(options.substrate !== undefined ? { substrate: options.substrate } : {}),\n })\n const manifestPath = join(outDir, 'product-benchmark-manifest.json')\n const recordsPath = join(outDir, 'product-benchmark-records.jsonl')\n writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`)\n writeFileSync(recordsPath, `${normalized.map((record) => JSON.stringify(record)).join('\\n')}\\n`)\n return { manifestPath, recordsPath, records: normalized.length }\n}\n\nfunction defaultScenarioTagPrefix(projectId: string): string {\n return projectId.replace(/-agent$/, '') || projectId\n}\n\nfunction resolveOptions(\n options: ProductBenchmarkExportOptions | ProductBenchmarkSingleRunExportOptions,\n): ResolvedExportOptions {\n return {\n projectId: options.projectId,\n benchmarkId: options.benchmarkId,\n agentProfilePath: options.agentProfilePath,\n passThreshold: options.passThreshold ?? 0.7,\n scenarioTagPrefix: options.scenarioTagPrefix ?? defaultScenarioTagPrefix(options.projectId),\n ...(options.fallbackProfileId !== undefined\n ? { fallbackProfileId: options.fallbackProfileId }\n : {}),\n mutableSurfaces: options.mutableSurfaces ?? productBenchmarkMutableSurfaces,\n ...(options.classifySplit !== undefined ? { classifySplit: options.classifySplit } : {}),\n ...(options.toolCallFallback !== undefined\n ? { toolCallFallback: options.toolCallFallback }\n : {}),\n backendVersion: options.backendVersion ?? packageVersion('@tangle-network/sandbox'),\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,cAAAA,aAAY,gBAAAC,eAAc,gBAAgB;AACnD,SAAS,WAAAC,UAAS,QAAAC,aAAY;;;ACkB9B,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,QAAQ,YAAY,WAAW,cAAc,qBAAqB;AAC3E,SAAS,UAAU,SAAS,YAAY,MAAM,UAAU,eAAe;AAYhE,IAAM,kCAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAwEA,SAAS,OAAO,OAAuB;AACrC,SAAO,UAAU,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC;AACnE;AAEA,SAAS,aAAa,OAAuB;AAC3C,SACE,MACG,QAAQ,qBAAqB,GAAG,EAChC,QAAQ,YAAY,EAAE,EACtB,MAAM,GAAG,EAAE,KAAK;AAEvB;AAEA,SAAS,IAAI,MAAyB,UAA0B;AAC9D,QAAM,MAAM,UAAU,OAAO,MAAM,EAAE,KAAK,QAAQ,IAAI,GAAG,UAAU,OAAO,CAAC;AAC3E,QAAM,QAAQ,IAAI,WAAW,IAAI,IAAI,OAAO,KAAK,IAAI;AACrD,SAAO,MAAM,SAAS,IAAI,QAAQ;AACpC;AAEA,SAAS,SAAS,MAAkC;AAClD,QAAM,QAAQ,QAAQ,IAAI,IAAI,GAAG,KAAK;AACtC,SAAO,SAAS,UAAU,YAA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A8B,MAAM;AACtD,MAAI,CAAC,WAAW;AACd,SAAK,QAAQ,4EAA4E;AAAA,EAC3F;AACA,QAAM,SAAS,4BAA4B,EAAE,GAAG,WAAW,cAAc,OAAO,CAAC;AACjF,QAAM,WAAW;AAAA,IACf,GAAG,OAAO;AAAA,IACV,GAAG,OAAO;AAAA,IACV,GAAG,OAAO;AAAA,IACV,GAAG,OAAO;AAAA,EACZ;AACA,MAAI,SAAS,SAAS,GAAG;AACvB,SAAK,QAAQ;AAAA,EAAyC,SAAS,KAAK,IAAI,CAAC,EAAE;AAAA,EAC7E;AACA,SAAO;AACT;","names":["existsSync","readFileSync","dirname","join","sum","readFileSync","dirname","existsSync","join"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/trace/query.ts"],"sourcesContent":["/**\n * Typed query helpers over TraceStore.\n *\n * Not a full SQL engine — a minimal, composable set of operators that\n * cover the canned-pipeline use cases. For ad-hoc analytics, persist to\n * NDJSON and point DuckDB at it; the schema is stable so external SQL\n * tooling works out of the box.\n */\n\nimport type { FailureClass, JudgeSpan, LlmSpan, Run, ToolSpan } from './schema'\nimport { isJudgeSpan, isLlmSpan, isToolSpan } from './schema'\nimport type { TraceStore } from './store'\n\nexport async function runsForScenario(store: TraceStore, scenarioId: string): Promise<Run[]> {\n return store.listRuns({ scenarioId })\n}\n\nexport async function llmSpans(store: TraceStore, runId?: string): Promise<LlmSpan[]> {\n const spans = await store.spans({ runId, kind: 'llm' })\n return spans.filter(isLlmSpan)\n}\n\nexport async function toolSpans(\n store: TraceStore,\n runId?: string,\n toolName?: string,\n): Promise<ToolSpan[]> {\n const spans = await store.spans({ runId, kind: 'tool', toolName })\n return spans.filter(isToolSpan)\n}\n\n/** Query judge-kind spans from the trace store, optionally scoped to a single run. */\nexport async function judgeSpans(store: TraceStore, runId?: string): Promise<JudgeSpan[]> {\n const spans = await store.spans({ runId, kind: 'judge' })\n return spans.filter(isJudgeSpan)\n}\n\n/** Group spans by any key selector. */\nexport function groupBy<T, K extends string | number>(items: T[], key: (t: T) => K): Map<K, T[]> {\n const map = new Map<K, T[]>()\n for (const item of items) {\n const k = key(item)\n let bucket = map.get(k)\n if (!bucket) {\n bucket = []\n map.set(k, bucket)\n }\n bucket.push(item)\n }\n return map\n}\n\n/** Hash tool arguments to an orderless-key-stable string for de-duplication. */\nexport function argHash(args: unknown): string {\n return stableStringify(args)\n}\n\nfunction stableStringify(value: unknown): string {\n // Must ALWAYS return a string: JSON.stringify(undefined) — and stringify of\n // functions/symbols — yields the JS value `undefined`, which would make\n // argHash return a non-string and silently break the de-dup keys behind\n // stuck-loop and failure-cluster.\n if (value === undefined) return 'undefined'\n if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'undefined'\n if (Array.isArray(value)) return `[${value.map(stableStringify).join(',')}]`\n // Drop undefined-valued keys to match JSON.stringify semantics, so\n // `{a:1}` and `{a:1,b:undefined}` hash identically.\n const obj = value as Record<string, unknown>\n const keys = Object.keys(obj)\n .filter((k) => obj[k] !== undefined)\n .sort()\n const parts = keys.map((k) => `${JSON.stringify(k)}:${stableStringify(obj[k])}`)\n return `{${parts.join(',')}}`\n}\n\n/** Sum an LLM-span array into aggregate token + cost. */\nexport function aggregateLlm(spans: LlmSpan[]): {\n inputTokens: number\n outputTokens: number\n cachedTokens: number\n reasoningTokens: number\n costUsd: number\n} {\n return spans.reduce(\n (acc, s) => ({\n inputTokens: acc.inputTokens + (s.inputTokens ?? 0),\n outputTokens: acc.outputTokens + (s.outputTokens ?? 0),\n cachedTokens: acc.cachedTokens + (s.cachedTokens ?? 0),\n // reasoningTokens is on LlmSpan but was omitted here — reasoning usage was\n // invisible to any cost/perf analysis reading this aggregate.\n reasoningTokens: acc.reasoningTokens + (s.reasoningTokens ?? 0),\n costUsd: acc.costUsd + (s.costUsd ?? 0),\n }),\n { inputTokens: 0, outputTokens: 0, cachedTokens: 0, reasoningTokens: 0, costUsd: 0 },\n )\n}\n\n/** Pick the outcome's failure class when present, else derive 'success' from run status. */\nexport function runFailureClass(run: Run): FailureClass {\n if (run.outcome?.failureClass) return run.outcome.failureClass\n if (run.status === 'completed' && run.outcome?.pass !== false) return 'success'\n if (run.status === 'aborted') return 'budget_exceeded'\n return 'unknown'\n}\n"],"mappings":";;;;;;;AAaA,eAAsB,gBAAgB,OAAmB,YAAoC;AAC3F,SAAO,MAAM,SAAS,EAAE,WAAW,CAAC;AACtC;AAEA,eAAsB,SAAS,OAAmB,OAAoC;AACpF,QAAM,QAAQ,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,MAAM,CAAC;AACtD,SAAO,MAAM,OAAO,SAAS;AAC/B;AAEA,eAAsB,UACpB,OACA,OACA,UACqB;AACrB,QAAM,QAAQ,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,QAAQ,SAAS,CAAC;AACjE,SAAO,MAAM,OAAO,UAAU;AAChC;AAGA,eAAsB,WAAW,OAAmB,OAAsC;AACxF,QAAM,QAAQ,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,QAAQ,CAAC;AACxD,SAAO,MAAM,OAAO,WAAW;AACjC;AAGO,SAAS,QAAsC,OAAY,KAA+B;AAC/F,QAAM,MAAM,oBAAI,IAAY;AAC5B,aAAW,QAAQ,OAAO;AACxB,UAAM,IAAI,IAAI,IAAI;AAClB,QAAI,SAAS,IAAI,IAAI,CAAC;AACtB,QAAI,CAAC,QAAQ;AACX,eAAS,CAAC;AACV,UAAI,IAAI,GAAG,MAAM;AAAA,IACnB;AACA,WAAO,KAAK,IAAI;AAAA,EAClB;AACA,SAAO;AACT;AAGO,SAAS,QAAQ,MAAuB;AAC7C,SAAO,gBAAgB,IAAI;AAC7B;AAEA,SAAS,gBAAgB,OAAwB;AAK/C,MAAI,UAAU,OAAW,QAAO;AAChC,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO,KAAK,UAAU,KAAK,KAAK;AACjF,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,IAAI,MAAM,IAAI,eAA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