@tangle-network/agent-eval 0.115.3 → 0.116.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/analyst/index.d.ts +8 -10
- package/dist/analyst/index.js +27 -22
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyst-C8HHvfJp.d.ts → analyst-CFBc14Wc.d.ts} +1 -1
- package/dist/{analyze-runs-BYHg6Irm.d.ts → analyze-runs-0rz_m29H.d.ts} +3 -3
- package/dist/belief-state/index.d.ts +3 -3
- package/dist/benchmarks/index.d.ts +7 -3
- package/dist/benchmarks/index.js +4 -4
- package/dist/campaign/index.d.ts +212 -23
- package/dist/campaign/index.js +19 -4
- package/dist/{chunk-ADYLPOSX.js → chunk-3274WNK7.js} +427 -93
- package/dist/chunk-3274WNK7.js.map +1 -0
- package/dist/{chunk-I6LVHOV3.js → chunk-7GKEAIAD.js} +2 -2
- package/dist/{chunk-5S5NJ63F.js → chunk-CIUOICJT.js} +747 -2
- package/dist/chunk-CIUOICJT.js.map +1 -0
- package/dist/{chunk-KG4TD7EQ.js → chunk-GSW3OBHK.js} +1283 -181
- package/dist/chunk-GSW3OBHK.js.map +1 -0
- package/dist/chunk-MPHTT5HE.js +74 -0
- package/dist/chunk-MPHTT5HE.js.map +1 -0
- package/dist/{chunk-WSBUZMBU.js → chunk-NBSS5NDZ.js} +3 -3
- package/dist/{code-agent-session-D-g04tcy.d.ts → code-agent-session-CdxteG0y.d.ts} +1 -1
- package/dist/contract/index.d.ts +19 -19
- package/dist/contract/index.js +5 -3
- package/dist/contract/index.js.map +1 -1
- package/dist/{control-CcBiAEnn.d.ts → control-DbcDxouY.d.ts} +1 -1
- package/dist/control.d.ts +2 -2
- package/dist/{default-registry-DltpYR5u.d.ts → default-registry-DDfv22MQ.d.ts} +2 -1
- package/dist/{gepa-dne9JDPL.d.ts → gepa-CQelRtuC.d.ts} +10 -8
- package/dist/hosted/index.d.ts +8 -4
- package/dist/{index-BTEpx9He.d.ts → index-DbCXJfZ1.d.ts} +2 -2
- package/dist/index.d.ts +27 -30
- package/dist/index.js +26 -20
- package/dist/index.js.map +1 -1
- package/dist/{insight-report-IwwvqZZv.d.ts → insight-report-oMVxDTxl.d.ts} +1 -1
- package/dist/{integrity-qemeBAyx.d.ts → integrity-C6PZ73iC.d.ts} +1 -1
- package/dist/kind-factory-DWOvXjR_.d.ts +171 -0
- package/dist/meta-eval/index.d.ts +2 -2
- package/dist/multishot/index.d.ts +6 -2
- package/dist/openapi.json +1 -1
- package/dist/policy-edit-Clb2v6Oa.d.ts +708 -0
- package/dist/{pre-registration-D8h7ZxNL.d.ts → pre-registration--vU0mMtD.d.ts} +4 -4
- package/dist/{provenance-Bibyg1U9.d.ts → provenance-BbVagC68.d.ts} +26 -14
- package/dist/{release-report-CCtzajxP.d.ts → release-report-CamNDe90.d.ts} +2 -2
- package/dist/reporting.d.ts +4 -4
- package/dist/{researcher-Dq-EtpbE.d.ts → researcher-Dwbo_Fxx.d.ts} +5 -5
- package/dist/rl.d.ts +11 -9
- package/dist/{rubric-predictive-validity-DYTLjGWu.d.ts → rubric-predictive-validity-BIdf9h4R.d.ts} +1 -1
- package/dist/{run-record-B7RTi_ix.d.ts → run-record-CZmcpWPo.d.ts} +1 -1
- package/dist/{runtime-trajectory-Dws7Kpgi.d.ts → runtime-trajectory-CC0jx9ql.d.ts} +1 -1
- package/dist/{semantic-concept-judge-DxJmRkyJ.d.ts → semantic-concept-judge-CKjePUMh.d.ts} +3 -3
- package/dist/{store-C1YxJDEK.d.ts → store-9cAScOcb.d.ts} +132 -1
- package/dist/{summary-report-BJ5aNwZ1.d.ts → summary-report-DTNgQycC.d.ts} +1 -1
- package/dist/traces.d.ts +6 -8
- package/dist/{types-C5gJrOVT.d.ts → types-Ca_63YSD.d.ts} +59 -2
- package/docs/design/loop-taxonomy.md +1 -2
- package/package.json +1 -1
- package/dist/chunk-5S5NJ63F.js.map +0 -1
- package/dist/chunk-ADYLPOSX.js.map +0 -1
- package/dist/chunk-KG4TD7EQ.js.map +0 -1
- package/dist/chunk-QMXXSNC4.js +0 -761
- package/dist/chunk-QMXXSNC4.js.map +0 -1
- package/dist/kind-factory-DcNg13sZ.d.ts +0 -508
- package/dist/llm-client-DyqEH4jH.d.ts +0 -265
- package/dist/policy-edit-RLn8GWof.d.ts +0 -103
- package/dist/raw-provider-sink-C46HDghv.d.ts +0 -132
- /package/dist/{chunk-I6LVHOV3.js.map → chunk-7GKEAIAD.js.map} +0 -0
- /package/dist/{chunk-WSBUZMBU.js.map → chunk-NBSS5NDZ.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/concurrency.ts","../src/analyst/steer-firewall.ts","../src/analyst/policy-edit.ts","../src/run-score.ts"],"sourcesContent":["/**\n * concurrency — small primitives the evolution loop needs.\n *\n * `Mutex` is a zero-dep async lock with FIFO fairness. The evolution loop\n * uses it to serialise checkout/build/commit sequences inside a single\n * pool slot, and to gate concurrent JSONL writers (see\n * `lockedJsonlReferenceReplayStore`).\n *\n * Deliberately minimal — no priority queue, no timeouts. If you need\n * those, swap to `async-mutex` at the call site.\n */\n\nexport class Mutex {\n private locked = false\n private readonly waiters: Array<() => void> = []\n\n async acquire(): Promise<() => void> {\n if (!this.locked) {\n this.locked = true\n return () => this.release()\n }\n return new Promise<() => void>((resolve) => {\n this.waiters.push(() => {\n resolve(() => this.release())\n })\n })\n }\n\n private release(): void {\n const next = this.waiters.shift()\n if (next) {\n next()\n } else {\n this.locked = false\n }\n }\n\n async runExclusive<T>(fn: () => Promise<T> | T): Promise<T> {\n const release = await this.acquire()\n try {\n return await fn()\n } finally {\n release()\n }\n }\n\n /** True iff someone holds the lock right now. Diagnostics only. */\n get isLocked(): boolean {\n return this.locked\n }\n\n /** Pending waiter count. Diagnostics only. */\n get pending(): number {\n return this.waiters.length\n }\n}\n","// The realness-oracle firewall (docs/learning-flywheel.md, \"The steer is f(trace)\").\n//\n// A realness/authenticity signal has TWO legitimate roles that must stay\n// separated by a firewall:\n// (a) anchor judge J — write-only: scores the chosen output, gates promotion,\n// NEVER seen by the worker/optimizer mid-run (else the loop games it).\n// (b) steer f(trace) — an analyst observes the agent's OWN behavior in the\n// trace (\"imported a stub\", \"used a non-crypto PRNG where encryption was\n// required\") and steers the next attempt. Legitimate, because it is derived\n// from OBSERVABLE BEHAVIOR, not from J's held-out verdict.\n//\n// The correct discriminator is PROVENANCE, not evidence presence. A judge verdict\n// lifted into a finding (createJudgeAdapter → liftJudgeScore) is a verdict even\n// when it cites an artifact; an evidence-less trace-analyst bullet is an\n// observation even though it cites nothing. So the firewall keys on\n// `AnalystFinding.derived_from_judge` (set at the judge lift site), NOT on whether\n// evidence_refs is populated. The instant a verdict steers the next attempt it is\n// a back-channel for J and the loop Goodharts realness exactly as it would\n// Goodhart pass-rate.\n\nimport type { AnalystFinding, EvidenceRef } from './types'\n\n/** Evidence grounded in the agent's OWN execution: OTLP trace elements\n * (`span`/`event`) or the artifact it produced (`artifact`). */\nconst OBSERVABLE_KINDS: ReadonlySet<EvidenceRef['kind']> = new Set<EvidenceRef['kind']>([\n 'span',\n 'event',\n 'artifact',\n])\n\n/** DESCRIPTIVE predicate: does the finding cite at least one observable\n * (span/event/artifact) evidence ref. Useful for ranking evidence quality or\n * rendering — it is NOT the steer gate. Evidence presence is the WRONG\n * discriminator for steering: a legitimate trace-analyst observation may cite\n * nothing (it would be wrongly rejected), and a judge verdict may cite an\n * artifact (it would be wrongly admitted). Use `assertNoJudgeVerdict` to gate\n * steering; use this only where \"is this grounded in observable evidence\" is the\n * literal question. */\nexport function isTraceObservable(finding: AnalystFinding): boolean {\n return finding.evidence_refs.some((ref) => OBSERVABLE_KINDS.has(ref.kind))\n}\n\n/** True iff the finding is a JUDGE VERDICT (an acceptance score lifted into a\n * finding), identified by provenance set at the lift site — independent of\n * whatever evidence it cites. */\nexport function isJudgeVerdict(finding: AnalystFinding): boolean {\n return finding.derived_from_judge === true\n}\n\n/**\n * THE steer firewall. Fail-loud guard for any path that admits analyst findings\n * as STEERING input (the `f(trace)` role): rejects — naming the offenders — any\n * finding whose provenance is a judge verdict, rather than let `J` leak into the\n * loop. Returns the findings unchanged for chaining.\n *\n * Call this at the chokepoint where a detector that ALSO scores/gates has its\n * findings turned into a steer (the judge-and-steer dual-role case). It keys on\n * provenance, so it correctly admits evidence-less trace-analyst observations and\n * correctly rejects an artifact-citing judge verdict — the cases an evidence\n * check gets backwards.\n *\n * It is necessary, not sufficient: it stops PROVENANCE-tagged verdicts. A judge\n * whose output is laundered through a hand-built finding with no provenance flag\n * is out of its reach — provenance must be honestly set at every judge→finding\n * lift (today: createJudgeAdapter). That is why the integrity rule lives at the\n * lift site, and why ProposeContext.judgeScores?: never is the complementary\n * compile-time tripwire on the obvious direct channel.\n */\nexport function assertNoJudgeVerdict(\n findings: ReadonlyArray<AnalystFinding>,\n context = 'steer',\n): ReadonlyArray<AnalystFinding> {\n const leaks = findings.filter(isJudgeVerdict)\n if (leaks.length > 0) {\n throw new Error(\n `${context}: a judge verdict cannot be admitted as steering input — that is the ` +\n `held-out judge leaking into the loop. Offending judge-derived findings: [${leaks\n .map((f) => f.finding_id)\n .join(', ')}]. Steering consumes observations of behavior, never acceptance verdicts.`,\n )\n }\n return findings\n}\n","import { createHash } from 'node:crypto'\nimport type { AgentProfileCell, AgentProfileJson } from '../agent-profile-cell'\nimport { validateAgentProfileCell } from '../agent-profile-cell'\nimport { ValidationError } from '../errors'\nimport { canonicalize } from '../pre-registration'\nimport { type FindingSubject, parseFindingSubject } from './finding-subject'\nimport { assertNoJudgeVerdict } from './steer-firewall'\nimport type { AnalystFinding, EvidenceRef } from './types'\n\nexport type PolicyEditSchemaVersion = 'policy-edit/v1'\n\nexport const POLICY_EDIT_AXES = [\n 'carrier',\n 'representation',\n 'budget',\n 'sampling',\n 'output_contract',\n 'tool_contract',\n 'routing',\n 'memory',\n 'agent_profile',\n 'deployment_target',\n] as const\n\nexport type PolicyEditAxis = (typeof POLICY_EDIT_AXES)[number]\n\nexport const POLICY_EDIT_TARGET_SURFACES = [\n 'prompt',\n 'tool-contract',\n 'runtime-config',\n 'memory',\n 'agent-profile',\n 'code',\n 'deployment',\n] as const\n\nexport type PolicyEditTargetSurface = (typeof POLICY_EDIT_TARGET_SURFACES)[number]\nexport type PolicyEditRisk = 'low' | 'medium' | 'high' | 'unknown'\nexport type PolicyEditGainDirection = 'increase' | 'decrease'\nexport type PolicyEditGainUnit = 'absolute' | 'relative' | 'percent' | 'score'\n\nexport interface PolicyEditTarget {\n surface: PolicyEditTargetSurface\n /** Stable path inside the target surface, for example `system-prompt:tools`\n * or `budget.maxTurns`. */\n path?: string\n /** Optional canonical deployment identity. Store the existing cell, not a\n * local profile shape. */\n agentProfileCell?: AgentProfileCell\n /** Human label when the path is not enough for a readable audit trail. */\n label?: string\n}\n\nexport type PolicyEditChange =\n | {\n kind: 'text'\n mode: 'append' | 'prepend' | 'replace'\n value: string\n /** Required when `mode === 'replace'`; exact match only. */\n find?: string\n }\n | {\n kind: 'json'\n mode: 'set' | 'merge' | 'remove'\n path: string\n value?: AgentProfileJson\n }\n\nexport interface PolicyEditExpectedGain {\n /** Metric this edit is expected to move, e.g. `holdout.composite`. */\n metric: string\n direction: PolicyEditGainDirection\n /** Positive magnitude in the metric's native units. */\n amount: number\n unit?: PolicyEditGainUnit\n rationale?: string\n}\n\nexport interface PolicyEditSource {\n findingIds: string[]\n analystIds: string[]\n evidenceRefs: EvidenceRef[]\n /** Mirrors `AnalystFinding.derived_from_judge`; admission rejects it. */\n derivedFromJudge?: boolean\n}\n\nexport interface PolicyEdit {\n schemaVersion: PolicyEditSchemaVersion\n editId: string\n axis: PolicyEditAxis\n target: PolicyEditTarget\n change: PolicyEditChange\n claim: string\n expectedGain: PolicyEditExpectedGain\n confidence: number\n risk: PolicyEditRisk\n source: PolicyEditSource\n rationale?: string\n validationPlan?: string\n metadata?: Record<string, unknown>\n}\n\nexport type PolicyEditInit = Omit<PolicyEdit, 'schemaVersion' | 'editId'> & {\n schemaVersion?: PolicyEditSchemaVersion\n editId?: string\n}\n\nexport class PolicyEditValidationError extends ValidationError {\n readonly path: string\n constructor(message: string, path = '') {\n super(path ? `${message} (at ${path})` : message)\n this.path = path\n }\n}\n\nexport interface FindingToPolicyEditOptions {\n expectedGain?:\n | PolicyEditExpectedGain\n | ((finding: AnalystFinding) => PolicyEditExpectedGain | null | undefined)\n risk?: PolicyEditRisk | ((finding: AnalystFinding) => PolicyEditRisk)\n defaultAxis?: PolicyEditAxis\n defaultTargetSurface?: PolicyEditTargetSurface\n}\n\nexport interface PolicyEditAdmissionOptions {\n minScore?: number\n minExpectedGain?: number\n allowHighRisk?: boolean\n requireEvidence?: boolean\n}\n\nexport interface PolicyEditAdmission {\n edit: PolicyEdit\n decision: 'admit' | 'reject'\n score: number\n reasons: string[]\n}\n\nconst DEFAULT_MIN_SCORE = 0.7\nconst DEFAULT_MIN_EXPECTED_GAIN = 0.01\nconst POLICY_EDIT_ID = /^policy-edit:sha256:[0-9a-f]{64}$/\n\nexport function makePolicyEdit(init: PolicyEditInit): PolicyEdit {\n const normalized = normalizePolicyEdit({\n schemaVersion: 'policy-edit/v1',\n ...init,\n source: normalizeSource(init.source),\n })\n const edit = {\n ...normalized,\n editId: init.editId ?? computePolicyEditId(normalized),\n }\n return validatePolicyEdit(edit)\n}\n\nexport function computePolicyEditId(edit: Omit<PolicyEdit, 'editId'> | PolicyEdit): string {\n const { editId: _editId, schemaVersion, ...material } = edit as PolicyEdit\n void _editId\n const canonical = JSON.stringify(canonicalize({ schemaVersion, ...material }))\n return `policy-edit:sha256:${createHash('sha256').update(canonical).digest('hex')}`\n}\n\nexport function validatePolicyEdit(input: unknown): PolicyEdit {\n if (input === null || typeof input !== 'object') {\n throw new PolicyEditValidationError('expected object')\n }\n const obj = input as PolicyEdit\n expectLiteral(obj.schemaVersion, 'policy-edit/v1', 'schemaVersion')\n expectString(obj.editId, 'editId')\n if (!POLICY_EDIT_ID.test(obj.editId)) {\n throw new PolicyEditValidationError(\n 'editId must match policy-edit:sha256:<64 lowercase hex chars>',\n 'editId',\n )\n }\n expectOneOf(obj.axis, POLICY_EDIT_AXES, 'axis')\n validateTarget(obj.target)\n validateChange(obj.change)\n expectString(obj.claim, 'claim')\n validateExpectedGain(obj.expectedGain)\n expectConfidence(obj.confidence, 'confidence')\n expectOneOf(obj.risk, ['low', 'medium', 'high', 'unknown'] as const, 'risk')\n validateSource(obj.source)\n if (obj.rationale !== undefined) expectString(obj.rationale, 'rationale')\n if (obj.validationPlan !== undefined) expectString(obj.validationPlan, 'validationPlan')\n if (obj.metadata !== undefined && (obj.metadata === null || typeof obj.metadata !== 'object')) {\n throw new PolicyEditValidationError('expected object', 'metadata')\n }\n const expectedId = computePolicyEditId(obj)\n if (obj.editId !== expectedId) {\n throw new PolicyEditValidationError('editId does not match policy edit content', 'editId')\n }\n return obj\n}\n\nexport function isPolicyEdit(input: unknown): input is PolicyEdit {\n try {\n validatePolicyEdit(input)\n return true\n } catch {\n return false\n }\n}\n\nexport function policyEditsFromFindings(\n findings: ReadonlyArray<AnalystFinding>,\n opts: FindingToPolicyEditOptions = {},\n): PolicyEdit[] {\n assertNoJudgeVerdict(findings, 'policyEditsFromFindings')\n const edits: PolicyEdit[] = []\n for (const finding of findings) {\n const edit = policyEditFromFinding(finding, opts)\n if (edit) edits.push(edit)\n }\n return edits\n}\n\nexport function policyEditFromFinding(\n finding: AnalystFinding,\n opts: FindingToPolicyEditOptions = {},\n): PolicyEdit | null {\n assertNoJudgeVerdict([finding], 'policyEditFromFinding')\n if (!finding.recommended_action?.trim()) return null\n\n const expectedGain = resolveExpectedGain(finding, opts)\n if (!expectedGain) return null\n\n const routed = routeFindingSubject(finding.subject, opts)\n const risk = resolveRisk(finding, opts)\n return makePolicyEdit({\n axis: routed.axis,\n target: routed.target,\n change: { kind: 'text', mode: 'append', value: finding.recommended_action.trim() },\n claim: finding.claim,\n rationale: finding.rationale,\n expectedGain,\n confidence: finding.confidence,\n risk,\n validationPlan: finding.validation_plan,\n source: {\n findingIds: [finding.finding_id],\n analystIds: [finding.analyst_id],\n evidenceRefs: finding.evidence_refs,\n derivedFromJudge: finding.derived_from_judge,\n },\n })\n}\n\nexport function scorePolicyEditReadiness(\n edit: PolicyEdit,\n opts: PolicyEditAdmissionOptions = {},\n): number {\n validatePolicyEdit(edit)\n const minExpectedGain = opts.minExpectedGain ?? DEFAULT_MIN_EXPECTED_GAIN\n const evidenceScore = Math.min(1, edit.source.evidenceRefs.length / 2)\n const confidenceScore = clamp01(edit.confidence)\n const gainScore = clamp01(\n Math.abs(edit.expectedGain.amount) / Math.max(minExpectedGain * 5, 0.001),\n )\n const targetScore = targetSpecificityScore(edit)\n const riskPenalty =\n edit.risk === 'high' && opts.allowHighRisk !== true ? 0.35 : edit.risk === 'unknown' ? 0.2 : 0\n\n return clamp01(\n 0.3 * evidenceScore +\n 0.25 * confidenceScore +\n 0.25 * gainScore +\n 0.2 * targetScore -\n riskPenalty,\n )\n}\n\nexport function admitPolicyEdit(\n edit: PolicyEdit,\n opts: PolicyEditAdmissionOptions = {},\n): PolicyEditAdmission {\n const validated = validatePolicyEdit(edit)\n const score = scorePolicyEditReadiness(validated, opts)\n const reasons: string[] = []\n const minExpectedGain = opts.minExpectedGain ?? DEFAULT_MIN_EXPECTED_GAIN\n const requireEvidence = opts.requireEvidence ?? true\n\n if (validated.source.derivedFromJudge) {\n reasons.push('source is judge-derived; judge verdicts cannot steer policy edits')\n }\n if (requireEvidence && validated.source.evidenceRefs.length === 0) {\n reasons.push('missing evidence refs')\n }\n if (Math.abs(validated.expectedGain.amount) < minExpectedGain) {\n reasons.push(`expected gain below ${minExpectedGain}`)\n }\n if (validated.risk === 'high' && opts.allowHighRisk !== true) {\n reasons.push('high-risk edit requires explicit allowHighRisk')\n }\n if (score < (opts.minScore ?? DEFAULT_MIN_SCORE)) {\n reasons.push(\n `readiness score ${score.toFixed(3)} below ${(opts.minScore ?? DEFAULT_MIN_SCORE).toFixed(3)}`,\n )\n }\n\n return {\n edit: validated,\n decision: reasons.length === 0 ? 'admit' : 'reject',\n score,\n reasons,\n }\n}\n\nexport function applyPolicyEditToSurface(surface: unknown, edit: PolicyEdit): unknown {\n const validated = validatePolicyEdit(edit)\n if (validated.change.kind === 'text') return applyTextChange(surface, validated.change)\n return applyJsonChange(surface, validated.change)\n}\n\nfunction routeFindingSubject(\n subject: string | undefined,\n opts: FindingToPolicyEditOptions,\n): { axis: PolicyEditAxis; target: PolicyEditTarget } {\n const parsed = parseFindingSubject(subject)\n if (!parsed) {\n return {\n axis: opts.defaultAxis ?? 'representation',\n target: { surface: opts.defaultTargetSurface ?? 'prompt' },\n }\n }\n return routeParsedSubject(parsed)\n}\n\nfunction routeParsedSubject(subject: FindingSubject): {\n axis: PolicyEditAxis\n target: PolicyEditTarget\n} {\n switch (subject.kind) {\n case 'system-prompt':\n return {\n axis: 'representation',\n target: { surface: 'prompt', path: `system-prompt:${subject.section}` },\n }\n case 'skill':\n return {\n axis: 'agent_profile',\n target: { surface: 'agent-profile', path: `skill:${subject.name}` },\n }\n case 'tool-doc':\n return {\n axis: 'tool_contract',\n target: {\n surface: 'tool-contract',\n path: subject.aspect\n ? `tool-doc:${subject.tool}:${subject.aspect}`\n : `tool-doc:${subject.tool}`,\n },\n }\n case 'new-tool':\n return {\n axis: 'tool_contract',\n target: { surface: 'tool-contract', path: `new-tool:${subject.name}` },\n }\n case 'mcp':\n return {\n axis: 'tool_contract',\n target: {\n surface: 'agent-profile',\n path: subject.tool ? `mcp:${subject.server}:${subject.tool}` : `mcp:${subject.server}`,\n },\n }\n case 'hook':\n return {\n axis: 'agent_profile',\n target: { surface: 'agent-profile', path: `hook:${subject.name}` },\n }\n case 'subagent':\n return {\n axis: 'routing',\n target: { surface: 'agent-profile', path: `subagent:${subject.name}` },\n }\n case 'workflow':\n return {\n axis: 'routing',\n target: { surface: 'runtime-config', path: `workflow:${subject.name}` },\n }\n case 'rollout-policy':\n return {\n axis: rolloutPolicyAxis(subject.field),\n target: { surface: 'runtime-config', path: `rollout-policy:${subject.field}` },\n }\n case 'agent-profile':\n return {\n axis: 'agent_profile',\n target: { surface: 'agent-profile', path: `agent-profile:${subject.field}` },\n }\n case 'code':\n return {\n axis: 'representation',\n target: { surface: 'code', path: `code:${subject.path}` },\n }\n case 'rag':\n return {\n axis: 'memory',\n target: { surface: 'memory', path: `rag:${subject.corpus}:${subject.docId}` },\n }\n case 'memory':\n return { axis: 'memory', target: { surface: 'memory', path: `memory:${subject.key}` } }\n case 'scaffolding':\n return {\n axis: 'routing',\n target: { surface: 'runtime-config', path: `scaffolding:${subject.concern}` },\n }\n case 'output-schema':\n return {\n axis: 'output_contract',\n target: { surface: 'runtime-config', path: `output-schema:${subject.field}` },\n }\n case 'knowledge.wiki':\n return {\n axis: 'memory',\n target: {\n surface: 'memory',\n path: `agent-knowledge:wiki:${subject.slug}${subject.heading ? `#${subject.heading}` : ''}`,\n },\n }\n case 'knowledge.claim':\n return {\n axis: 'memory',\n target: { surface: 'memory', path: `agent-knowledge:claim:${subject.topic}` },\n }\n case 'knowledge.raw':\n return {\n axis: 'memory',\n target: { surface: 'memory', path: `agent-knowledge:raw:${subject.sourceId}` },\n }\n case 'knowledge.stale':\n return {\n axis: 'memory',\n target: { surface: 'memory', path: `agent-knowledge:stale:${subject.slug}` },\n }\n case 'websearch.outdated':\n return {\n axis: 'memory',\n target: { surface: 'memory', path: `websearch:outdated:${subject.topic}` },\n }\n case 'prior-run-summary':\n return {\n axis: 'memory',\n target: { surface: 'memory', path: `prior-run-summary:${subject.topic}` },\n }\n case 'cluster':\n return { axis: 'representation', target: { surface: 'prompt', path: subject.label } }\n }\n}\n\nfunction rolloutPolicyAxis(field: string): PolicyEditAxis {\n const normalized = field.toLowerCase()\n if (/budget|max(?:imum)?[-_. ]?(?:turns?|tokens?|cost)|timeout|deadline/.test(normalized)) {\n return 'budget'\n }\n if (/temperature|top[-_. ]?p|sampling|seed|shots?|parallel|concurrency/.test(normalized)) {\n return 'sampling'\n }\n if (/output|schema|format/.test(normalized)) return 'output_contract'\n return 'routing'\n}\n\nfunction resolveExpectedGain(\n finding: AnalystFinding,\n opts: FindingToPolicyEditOptions,\n): PolicyEditExpectedGain | null {\n if (typeof opts.expectedGain === 'function') return opts.expectedGain(finding) ?? null\n if (opts.expectedGain) return opts.expectedGain\n return readExpectedGainFromMetadata(finding.metadata)\n}\n\nfunction readExpectedGainFromMetadata(\n metadata: Record<string, unknown> | undefined,\n): PolicyEditExpectedGain | null {\n const raw =\n readPolicyEditMetadata(metadata)?.expectedGain ??\n readPolicyEditMetadata(metadata)?.expected_gain\n if (!raw || typeof raw !== 'object') return null\n const obj = raw as Record<string, unknown>\n if (\n typeof obj.metric !== 'string' ||\n (obj.direction !== 'increase' && obj.direction !== 'decrease') ||\n typeof obj.amount !== 'number'\n ) {\n return null\n }\n const out: PolicyEditExpectedGain = {\n metric: obj.metric,\n direction: obj.direction,\n amount: obj.amount,\n }\n if (\n obj.unit === 'absolute' ||\n obj.unit === 'relative' ||\n obj.unit === 'percent' ||\n obj.unit === 'score'\n ) {\n out.unit = obj.unit\n }\n if (typeof obj.rationale === 'string') out.rationale = obj.rationale\n return out\n}\n\nfunction readPolicyEditMetadata(\n metadata: Record<string, unknown> | undefined,\n): Record<string, unknown> | null {\n const raw = metadata?.policyEdit ?? metadata?.policy_edit\n return raw && typeof raw === 'object' ? (raw as Record<string, unknown>) : null\n}\n\nfunction resolveRisk(finding: AnalystFinding, opts: FindingToPolicyEditOptions): PolicyEditRisk {\n if (typeof opts.risk === 'function') return opts.risk(finding)\n if (opts.risk) return opts.risk\n const raw = readPolicyEditMetadata(finding.metadata)?.risk\n if (raw === 'low' || raw === 'medium' || raw === 'high' || raw === 'unknown') return raw\n if (finding.severity === 'critical' || finding.severity === 'high') return 'medium'\n return 'low'\n}\n\nfunction applyTextChange(\n surface: unknown,\n change: Extract<PolicyEditChange, { kind: 'text' }>,\n): string {\n if (typeof surface !== 'string') {\n throw new PolicyEditValidationError('text policy edits require a string surface', 'change')\n }\n if (change.mode === 'append') {\n if (hasExactTextBlock(surface, change.value)) return surface\n return `${surface.trimEnd()}\\n\\n${change.value}`.trimStart()\n }\n if (change.mode === 'prepend') {\n if (hasExactTextBlock(surface, change.value)) return surface\n return `${change.value}\\n\\n${surface.trimStart()}`.trimEnd()\n }\n const find = expectNonEmpty(change.find, 'change.find')\n if (!surface.includes(find)) {\n throw new PolicyEditValidationError('replace target not found in surface', 'change.find')\n }\n return surface.replace(find, change.value)\n}\n\nfunction applyJsonChange(\n surface: unknown,\n change: Extract<PolicyEditChange, { kind: 'json' }>,\n): AgentProfileJson {\n const root = parseJsonSurface(surface)\n const path = splitPath(change.path)\n if (change.mode === 'remove') return setJsonAtPath(root, path, undefined, 'remove')\n if (change.mode === 'set') return setJsonAtPath(root, path, change.value ?? null, 'set')\n const prior = readJsonAtPath(root, path)\n const merged =\n prior &&\n typeof prior === 'object' &&\n !Array.isArray(prior) &&\n change.value &&\n typeof change.value === 'object' &&\n !Array.isArray(change.value)\n ? { ...prior, ...change.value }\n : (change.value ?? null)\n return setJsonAtPath(root, path, merged as AgentProfileJson, 'set')\n}\n\nfunction parseJsonSurface(surface: unknown): AgentProfileJson {\n if (typeof surface === 'string') {\n try {\n return JSON.parse(surface) as AgentProfileJson\n } catch {\n throw new PolicyEditValidationError(\n 'json policy edits require a JSON string surface',\n 'change',\n )\n }\n }\n assertJson(surface, 'surface')\n return surface as AgentProfileJson\n}\n\nfunction readJsonAtPath(root: AgentProfileJson, path: string[]): AgentProfileJson | undefined {\n let cursor: AgentProfileJson | undefined = root\n for (const part of path) {\n if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor)) return undefined\n cursor = cursor[part]\n }\n return cursor\n}\n\nfunction setJsonAtPath(\n root: AgentProfileJson,\n path: string[],\n value: AgentProfileJson | undefined,\n mode: 'set' | 'remove',\n): AgentProfileJson {\n if (path.length === 0) {\n if (mode === 'remove') return null\n return value ?? null\n }\n if (root === null || typeof root !== 'object' || Array.isArray(root)) {\n throw new PolicyEditValidationError('json edit root must be an object', 'change.path')\n }\n const out: Record<string, AgentProfileJson> = { ...root }\n let cursor: Record<string, AgentProfileJson> = out\n for (let i = 0; i < path.length - 1; i++) {\n const key = path[i]!\n const existing = cursor[key]\n if (\n mode === 'remove' &&\n (!existing || typeof existing !== 'object' || Array.isArray(existing))\n ) {\n return out\n }\n const next =\n existing && typeof existing === 'object' && !Array.isArray(existing) ? { ...existing } : {}\n cursor[key] = next\n cursor = next\n }\n const leaf = path[path.length - 1]!\n if (mode === 'remove') delete cursor[leaf]\n else cursor[leaf] = value ?? null\n return out\n}\n\nfunction normalizePolicyEdit(input: Omit<PolicyEdit, 'editId'>): Omit<PolicyEdit, 'editId'> {\n const out: Omit<PolicyEdit, 'editId'> = {\n schemaVersion: 'policy-edit/v1',\n axis: input.axis,\n target: normalizeTarget(input.target),\n change: normalizeChange(input.change),\n claim: input.claim.trim(),\n expectedGain: normalizeExpectedGain(input.expectedGain),\n confidence: input.confidence,\n risk: input.risk,\n source: normalizeSource(input.source),\n }\n if (input.rationale?.trim()) out.rationale = input.rationale.trim()\n if (input.validationPlan?.trim()) out.validationPlan = input.validationPlan.trim()\n if (input.metadata) out.metadata = input.metadata\n return out\n}\n\nfunction normalizeTarget(target: PolicyEditTarget): PolicyEditTarget {\n const out: PolicyEditTarget = { surface: target.surface }\n if (target.path?.trim()) out.path = target.path.trim()\n if (target.agentProfileCell)\n out.agentProfileCell = validateAgentProfileCell(target.agentProfileCell)\n if (target.label?.trim()) out.label = target.label.trim()\n return out\n}\n\nfunction normalizeChange(change: PolicyEditChange): PolicyEditChange {\n if (change.kind === 'text') {\n const out: Extract<PolicyEditChange, { kind: 'text' }> = {\n kind: 'text',\n mode: change.mode,\n value: change.value.trim(),\n }\n if (change.find?.trim()) out.find = change.find.trim()\n return out\n }\n const out: Extract<PolicyEditChange, { kind: 'json' }> = {\n kind: 'json',\n mode: change.mode,\n path: change.path.trim(),\n }\n if (change.value !== undefined) out.value = change.value\n return out\n}\n\nfunction normalizeExpectedGain(gain: PolicyEditExpectedGain): PolicyEditExpectedGain {\n const out: PolicyEditExpectedGain = {\n metric: gain.metric.trim(),\n direction: gain.direction,\n amount: gain.amount,\n }\n if (gain.unit) out.unit = gain.unit\n if (gain.rationale?.trim()) out.rationale = gain.rationale.trim()\n return out\n}\n\nfunction normalizeSource(source: PolicyEditSource): PolicyEditSource {\n const out: PolicyEditSource = {\n findingIds: uniqueSorted(source.findingIds.map((s) => s.trim()).filter(Boolean)),\n analystIds: uniqueSorted(source.analystIds.map((s) => s.trim()).filter(Boolean)),\n evidenceRefs: source.evidenceRefs,\n }\n if (source.derivedFromJudge) out.derivedFromJudge = true\n return out\n}\n\nfunction validateTarget(target: unknown): asserts target is PolicyEditTarget {\n if (!target || typeof target !== 'object')\n throw new PolicyEditValidationError('expected object', 'target')\n const obj = target as PolicyEditTarget\n expectOneOf(obj.surface, POLICY_EDIT_TARGET_SURFACES, 'target.surface')\n if (obj.path !== undefined) expectString(obj.path, 'target.path')\n if (obj.label !== undefined) expectString(obj.label, 'target.label')\n if (obj.agentProfileCell !== undefined) validateAgentProfileCell(obj.agentProfileCell)\n}\n\nfunction validateChange(change: unknown): asserts change is PolicyEditChange {\n if (!change || typeof change !== 'object')\n throw new PolicyEditValidationError('expected object', 'change')\n const obj = change as PolicyEditChange\n if (obj.kind !== 'text' && obj.kind !== 'json') {\n throw new PolicyEditValidationError('kind must be text or json', 'change.kind')\n }\n if (obj.kind === 'text') {\n expectOneOf(obj.mode, ['append', 'prepend', 'replace'] as const, 'change.mode')\n expectString(obj.value, 'change.value')\n if (obj.mode === 'replace') expectString(obj.find, 'change.find')\n return\n }\n expectOneOf(obj.mode, ['set', 'merge', 'remove'] as const, 'change.mode')\n expectString(obj.path, 'change.path')\n if (obj.value !== undefined) assertJson(obj.value, 'change.value')\n}\n\nfunction validateExpectedGain(gain: unknown): asserts gain is PolicyEditExpectedGain {\n if (!gain || typeof gain !== 'object')\n throw new PolicyEditValidationError('expected object', 'expectedGain')\n const obj = gain as PolicyEditExpectedGain\n expectString(obj.metric, 'expectedGain.metric')\n expectOneOf(obj.direction, ['increase', 'decrease'] as const, 'expectedGain.direction')\n if (!Number.isFinite(obj.amount) || obj.amount <= 0) {\n throw new PolicyEditValidationError(\n 'amount must be a positive finite number',\n 'expectedGain.amount',\n )\n }\n if (obj.unit !== undefined) {\n expectOneOf(\n obj.unit,\n ['absolute', 'relative', 'percent', 'score'] as const,\n 'expectedGain.unit',\n )\n }\n if (obj.rationale !== undefined) expectString(obj.rationale, 'expectedGain.rationale')\n}\n\nfunction validateSource(source: unknown): asserts source is PolicyEditSource {\n if (!source || typeof source !== 'object')\n throw new PolicyEditValidationError('expected object', 'source')\n const obj = source as PolicyEditSource\n expectNonEmptyStringArray(obj.findingIds, 'source.findingIds')\n expectNonEmptyStringArray(obj.analystIds, 'source.analystIds')\n if (!Array.isArray(obj.evidenceRefs)) {\n throw new PolicyEditValidationError('expected array', 'source.evidenceRefs')\n }\n for (const [i, ref] of obj.evidenceRefs.entries())\n validateEvidenceRef(ref, `source.evidenceRefs.${i}`)\n if (obj.derivedFromJudge !== undefined && typeof obj.derivedFromJudge !== 'boolean') {\n throw new PolicyEditValidationError('expected boolean', 'source.derivedFromJudge')\n }\n}\n\nfunction validateEvidenceRef(ref: unknown, path: string): asserts ref is EvidenceRef {\n if (!ref || typeof ref !== 'object') throw new PolicyEditValidationError('expected object', path)\n const obj = ref as EvidenceRef\n expectOneOf(obj.kind, ['span', 'event', 'artifact', 'finding', 'metric'] as const, `${path}.kind`)\n expectString(obj.uri, `${path}.uri`)\n if (obj.excerpt !== undefined) expectString(obj.excerpt, `${path}.excerpt`)\n}\n\nfunction assertJson(value: unknown, path: string): asserts value is AgentProfileJson {\n if (\n value === null ||\n typeof value === 'string' ||\n typeof value === 'boolean' ||\n (typeof value === 'number' && Number.isFinite(value))\n ) {\n return\n }\n if (Array.isArray(value)) {\n for (const [i, item] of value.entries()) assertJson(item, `${path}.${i}`)\n return\n }\n if (typeof value === 'object') {\n for (const [key, item] of Object.entries(value)) {\n if (!key) throw new PolicyEditValidationError('empty object key', path)\n assertJson(item, `${path}.${key}`)\n }\n return\n }\n throw new PolicyEditValidationError('expected JSON-compatible value', path)\n}\n\nfunction targetSpecificityScore(edit: PolicyEdit): number {\n let score = 0.4\n if (edit.target.path) score += 0.25\n if (edit.target.agentProfileCell) score += 0.15\n if (edit.change.kind === 'json' || edit.change.mode === 'replace') score += 0.2\n else if (edit.change.value.length > 0) score += 0.1\n return clamp01(score)\n}\n\nfunction splitPath(path: string): string[] {\n const parts = path\n .split('.')\n .map((p) => p.trim())\n .filter(Boolean)\n if (parts.length === 0)\n throw new PolicyEditValidationError('path must not be empty', 'change.path')\n return parts\n}\n\nfunction expectLiteral<T extends string>(\n value: unknown,\n expected: T,\n path: string,\n): asserts value is T {\n if (value !== expected) throw new PolicyEditValidationError(`expected ${expected}`, path)\n}\n\nfunction expectString(value: unknown, path: string): asserts value is string {\n if (typeof value !== 'string' || value.trim().length === 0) {\n throw new PolicyEditValidationError('expected non-empty string', path)\n }\n}\n\nfunction expectNonEmpty(value: unknown, path: string): string {\n expectString(value, path)\n return value\n}\n\nfunction expectConfidence(value: unknown, path: string): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1) {\n throw new PolicyEditValidationError('expected finite number in [0,1]', path)\n }\n}\n\nfunction hasExactTextBlock(surface: string, value: string): boolean {\n const needle = normalizeTextBlock(value)\n const normalizedSurface = surface.replace(/\\r\\n/g, '\\n')\n return [...normalizedSurface.split(/\\n{2,}/), ...normalizedSurface.split('\\n')].some(\n (block) => normalizeTextBlock(block) === needle,\n )\n}\n\nfunction normalizeTextBlock(value: string): string {\n return value.replace(/\\r\\n/g, '\\n').trim()\n}\n\nfunction expectOneOf<const T extends readonly string[]>(\n value: unknown,\n allowed: T,\n path: string,\n): asserts value is T[number] {\n if (typeof value !== 'string' || !allowed.includes(value)) {\n throw new PolicyEditValidationError(`expected one of ${allowed.join(', ')}`, path)\n }\n}\n\nfunction expectStringArray(value: unknown, path: string): asserts value is string[] {\n if (!Array.isArray(value)) throw new PolicyEditValidationError('expected array', path)\n for (const [i, item] of value.entries()) expectString(item, `${path}.${i}`)\n}\n\nfunction expectNonEmptyStringArray(value: unknown, path: string): asserts value is string[] {\n expectStringArray(value, path)\n if (value.length === 0) throw new PolicyEditValidationError('expected non-empty array', path)\n}\n\nfunction uniqueSorted(values: string[]): string[] {\n return [...new Set(values)].sort()\n}\n\nfunction clamp01(n: number): number {\n if (!Number.isFinite(n)) return 0\n if (n < 0) return 0\n if (n > 1) return 1\n return n\n}\n","export interface RunScore {\n success: number\n goalProgress: number\n repoGroundedness: number\n driftPenalty: number\n toolUseQuality: number\n patchQuality: number\n testReality: number\n finalGate: number\n reviewerBlockers: number\n costUsd: number\n wallSeconds: number\n notes?: string[]\n}\n\nexport interface RunScoreWeights {\n success: number\n goalProgress: number\n repoGroundedness: number\n driftPenalty: number\n toolUseQuality: number\n patchQuality: number\n testReality: number\n finalGate: number\n reviewerBlockers: number\n costUsd: number\n wallSeconds: number\n}\n\nexport const DEFAULT_RUN_SCORE_WEIGHTS: RunScoreWeights = {\n success: 4,\n goalProgress: 2,\n repoGroundedness: 1.5,\n driftPenalty: -1.5,\n toolUseQuality: 1,\n patchQuality: 1.25,\n testReality: 1.5,\n finalGate: 3,\n reviewerBlockers: -2,\n costUsd: -0.2,\n wallSeconds: -0.1,\n}\n\nexport function aggregateRunScore(score: RunScore, weights: Partial<RunScoreWeights> = {}): number {\n const w = { ...DEFAULT_RUN_SCORE_WEIGHTS, ...weights }\n return (\n w.success * clamp01(score.success) +\n w.goalProgress * clamp01(score.goalProgress) +\n w.repoGroundedness * clamp01(score.repoGroundedness) +\n w.driftPenalty * clamp01(score.driftPenalty) +\n w.toolUseQuality * clamp01(score.toolUseQuality) +\n w.patchQuality * clamp01(score.patchQuality) +\n w.testReality * clamp01(score.testReality) +\n w.finalGate * clamp01(score.finalGate) +\n w.reviewerBlockers * clamp01(score.reviewerBlockers) +\n w.costUsd * Math.max(0, finiteOrZero(score.costUsd)) +\n w.wallSeconds * Math.max(0, finiteOrZero(score.wallSeconds) / 60)\n )\n}\n\nexport function clamp01(value: number): number {\n if (!Number.isFinite(value)) return 0\n return Math.max(0, Math.min(1, value))\n}\n\nfunction finiteOrZero(value: number): number {\n return Number.isFinite(value) ? value : 0\n}\n"],"mappings":";;;;;;;;;;;;;;AAYO,IAAM,QAAN,MAAY;AAAA,EACT,SAAS;AAAA,EACA,UAA6B,CAAC;AAAA,EAE/C,MAAM,UAA+B;AACnC,QAAI,CAAC,KAAK,QAAQ;AAChB,WAAK,SAAS;AACd,aAAO,MAAM,KAAK,QAAQ;AAAA,IAC5B;AACA,WAAO,IAAI,QAAoB,CAAC,YAAY;AAC1C,WAAK,QAAQ,KAAK,MAAM;AACtB,gBAAQ,MAAM,KAAK,QAAQ,CAAC;AAAA,MAC9B,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEQ,UAAgB;AACtB,UAAM,OAAO,KAAK,QAAQ,MAAM;AAChC,QAAI,MAAM;AACR,WAAK;AAAA,IACP,OAAO;AACL,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,MAAM,aAAgB,IAAsC;AAC1D,UAAM,UAAU,MAAM,KAAK,QAAQ;AACnC,QAAI;AACF,aAAO,MAAM,GAAG;AAAA,IAClB,UAAE;AACA,cAAQ;AAAA,IACV;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,WAAoB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,UAAkB;AACpB,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;;;AC/BA,IAAM,mBAAqD,oBAAI,IAAyB;AAAA,EACtF;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAUM,SAAS,kBAAkB,SAAkC;AAClE,SAAO,QAAQ,cAAc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AAE,UAAU,KAAK,IAAI,GAAG,aAAa,MAAM,OAAO,CAAC,IACnD,EAAE,cAAc,KAAK,IAAI,GAAG,aAAa,MAAM,WAAW,IAAI,EAAE;AAEpE;AAEO,SAASA,SAAQ,OAAuB;AAC7C,MAAI,CAAC,OAAO,SAAS,KAAK,EAAG,QAAO;AACpC,SAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,CAAC;AACvC;AAEA,SAAS,aAAa,OAAuB;AAC3C,SAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;AAC1C;","names":["out","clamp01"]}
|
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
import { AxAIService, AxFunction } from '@ax-llm/ax';
|
|
2
|
-
import { T as TraceAnalysisStore } from './store-C1YxJDEK.js';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { R as RunRecord } from './run-record-B7RTi_ix.js';
|
|
5
|
-
import { a as JudgeInput } from './types-C7DGg5ex.js';
|
|
6
|
-
import { b as LlmCallRequest, c as LlmCallResult } from './llm-client-DyqEH4jH.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* ChatClient — the single LLM abstraction analysts call.
|
|
10
|
-
*
|
|
11
|
-
* agent-eval already ships an `LlmClient` (OpenAI-compatible, retry,
|
|
12
|
-
* graceful JSON-schema degrade) and judges that talk to `TCloud`. Two
|
|
13
|
-
* mixed patterns force every analyst author to pick a transport, which
|
|
14
|
-
* couples analyst code to runtime concerns (cli-bridge vs router vs
|
|
15
|
-
* sandbox-sdk) it shouldn't know about.
|
|
16
|
-
*
|
|
17
|
-
* `ChatClient` is one interface every analyst takes via `AnalystContext.chat`.
|
|
18
|
-
* The operator decides at the registry boundary which transport binds
|
|
19
|
-
* to it. Analyst code stays transport-agnostic; swapping production
|
|
20
|
-
* (sandbox-sdk) for local dev (cli-bridge) or tests (mock) is a one-
|
|
21
|
-
* line factory call.
|
|
22
|
-
*
|
|
23
|
-
* Designed to coexist: existing `LlmClient` callers and existing
|
|
24
|
-
* `TCloud`-based judges keep working untouched. New analyst code uses
|
|
25
|
-
* `ChatClient`. When old call sites migrate, they pick up budgeting,
|
|
26
|
-
* cancellation, and unified telemetry for free.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Unified chat interface. Mirrors LlmCallRequest/Result so the OpenAI-
|
|
31
|
-
* compatible mental model stays. Two methods: a one-shot `chat()` and
|
|
32
|
-
* an `streamChat()` for future agentic loops (not yet exposed).
|
|
33
|
-
*/
|
|
34
|
-
interface ChatClient {
|
|
35
|
-
/** Display name of the bound transport — included in telemetry. */
|
|
36
|
-
readonly transport: ChatTransport;
|
|
37
|
-
/** Default model when caller omits — operators bind this per environment. */
|
|
38
|
-
readonly defaultModel?: string;
|
|
39
|
-
chat(req: ChatRequest, opts?: ChatCallOpts): Promise<ChatResponse>;
|
|
40
|
-
}
|
|
41
|
-
type ChatTransport = 'router' | 'sandbox-sdk' | 'cli-bridge' | 'direct-provider' | 'mock';
|
|
42
|
-
interface ChatRequest extends Omit<LlmCallRequest, 'model'> {
|
|
43
|
-
/** Optional — falls back to ChatClient.defaultModel. */
|
|
44
|
-
model?: string;
|
|
45
|
-
}
|
|
46
|
-
type ChatResponse = LlmCallResult;
|
|
47
|
-
interface ChatCallOpts {
|
|
48
|
-
/** Cancel the in-flight request. */
|
|
49
|
-
signal?: AbortSignal;
|
|
50
|
-
/** Hard USD ceiling for this single call (informational; the underlying transport may not enforce). */
|
|
51
|
-
maxCostUsd?: number;
|
|
52
|
-
/** Correlation tag carried into request headers when the transport allows. */
|
|
53
|
-
correlationId?: string;
|
|
54
|
-
}
|
|
55
|
-
type CreateChatClientOpts = RouterTransportOpts | CliBridgeTransportOpts | DirectProviderTransportOpts | SandboxSdkTransportOpts | MockTransportOpts;
|
|
56
|
-
interface BaseTransportOpts {
|
|
57
|
-
defaultModel?: string;
|
|
58
|
-
}
|
|
59
|
-
interface RouterTransportOpts extends BaseTransportOpts {
|
|
60
|
-
transport: 'router';
|
|
61
|
-
baseUrl?: string;
|
|
62
|
-
apiKey: string;
|
|
63
|
-
}
|
|
64
|
-
interface CliBridgeTransportOpts extends BaseTransportOpts {
|
|
65
|
-
transport: 'cli-bridge';
|
|
66
|
-
baseUrl?: string;
|
|
67
|
-
bearer?: string;
|
|
68
|
-
}
|
|
69
|
-
interface DirectProviderTransportOpts extends BaseTransportOpts {
|
|
70
|
-
transport: 'direct-provider';
|
|
71
|
-
baseUrl: string;
|
|
72
|
-
apiKey: string;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Sandbox-SDK transport. Provided as a thin pass-through: the caller
|
|
76
|
-
* supplies a callable that mimics LlmClient.chat() against an already-
|
|
77
|
-
* configured Sandbox handle. We don't import the SDK here to keep
|
|
78
|
-
* agent-eval dep-free of @tangle-network/sandbox.
|
|
79
|
-
*/
|
|
80
|
-
interface SandboxSdkTransportOpts extends BaseTransportOpts {
|
|
81
|
-
transport: 'sandbox-sdk';
|
|
82
|
-
chat: (req: ChatRequest, opts?: ChatCallOpts) => Promise<ChatResponse>;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Mock transport for tests. The handler receives the request and returns
|
|
86
|
-
* whatever the test wants. No retries, no JSON-schema degrade.
|
|
87
|
-
*/
|
|
88
|
-
interface MockTransportOpts extends BaseTransportOpts {
|
|
89
|
-
transport: 'mock';
|
|
90
|
-
handler: (req: ChatRequest, opts?: ChatCallOpts) => Promise<ChatResponse>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Build a ChatClient bound to a specific transport. The returned client
|
|
94
|
-
* is safe to share across analysts in a single registry run.
|
|
95
|
-
*/
|
|
96
|
-
declare function createChatClient(opts: CreateChatClientOpts): ChatClient;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Typed Ax output for analyst findings.
|
|
100
|
-
*
|
|
101
|
-
* Replaces the legacy `findings:string[]` pattern (where every bullet
|
|
102
|
-
* became a flat-severity `AnalystFinding`) with a structured object
|
|
103
|
-
* array. Ax binds the field as `findings:json[]` so the provider emits
|
|
104
|
-
* native structured output; at the kind-factory boundary we Zod-validate
|
|
105
|
-
* each emitted finding so malformed rows fail loud instead of being
|
|
106
|
-
* silently lifted with default severity.
|
|
107
|
-
*
|
|
108
|
-
* Why not `f.object().array()` directly in the signature? The Ax
|
|
109
|
-
* signature string `question:string -> findings:json[]` already lets
|
|
110
|
-
* the provider emit JSON arrays. A Zod boundary is required either
|
|
111
|
-
* way (the provider can return any JSON), and Zod gives us a single
|
|
112
|
-
* validation surface independent of which Ax version is installed.
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
declare const ANALYST_SEVERITIES: readonly ["critical", "high", "medium", "low", "info"];
|
|
116
|
-
declare const RawAnalystFindingSchema: z.ZodObject<{
|
|
117
|
-
severity: z.ZodEnum<{
|
|
118
|
-
info: "info";
|
|
119
|
-
critical: "critical";
|
|
120
|
-
medium: "medium";
|
|
121
|
-
low: "low";
|
|
122
|
-
high: "high";
|
|
123
|
-
}>;
|
|
124
|
-
claim: z.ZodString;
|
|
125
|
-
subject: z.ZodOptional<z.ZodString>;
|
|
126
|
-
evidence_uri: z.ZodString;
|
|
127
|
-
evidence_excerpt: z.ZodOptional<z.ZodString>;
|
|
128
|
-
confidence: z.ZodNumber;
|
|
129
|
-
rationale: z.ZodOptional<z.ZodString>;
|
|
130
|
-
recommended_action: z.ZodOptional<z.ZodString>;
|
|
131
|
-
}, z.core.$strict>;
|
|
132
|
-
type RawAnalystFinding = z.infer<typeof RawAnalystFindingSchema>;
|
|
133
|
-
/**
|
|
134
|
-
* Description embedded into the actor prompt so the LLM knows what
|
|
135
|
-
* shape to emit. Kept here so kinds share one source of truth rather
|
|
136
|
-
* than restating the schema in every prompt.
|
|
137
|
-
*/
|
|
138
|
-
declare const RAW_FINDING_SCHEMA_PROMPT = "Each finding MUST be a JSON object with these fields:\n - severity: one of \"critical\" | \"high\" | \"medium\" | \"low\" | \"info\"\n - claim: one-sentence statement (max 2000 chars)\n - subject?: the routing locus this finding is about. It MUST be one of the exact subject forms listed in this kind's instructions above (e.g. `system-prompt:<section>`, `agent-knowledge:wiki:<slug>`, `tool-doc:<tool>`). A free phrase, a bare noun, or any form not in that list is REJECTED at parse time and the finding is discarded \u2014 omit subject entirely rather than guess a form.\n - evidence_uri: REQUIRED, never blank. Exactly one of \"span://<trace_id>/<span_id>\" (trace evidence), \"artifact://<relative-path>\" (files), \"metric://<name>\" (named scalars) \u2014 ALWAYS cite a real id surfaced by the tools. If you have no citable id, do not emit the finding.\n - evidence_excerpt?: short quote (<=2000 chars) from the cited span/artifact\n - confidence: number 0..1 \u2014 0.9+ when backed by exact quotes, 0.6-0.8 for inferred patterns, <0.5 for speculative\n - rationale?: one or two sentences explaining the reasoning\n - recommended_action?: concrete change phrased as an imperative (\"Add ...\", \"Replace ...\", \"Stop ...\") \u2014 omit when the finding is purely descriptive\n\nEmit an empty array when the question has no findings to report. Do not fabricate evidence.";
|
|
139
|
-
/**
|
|
140
|
-
* Validate one row emitted by the LLM. Returns the typed finding on
|
|
141
|
-
* success; returns `null` and logs the reason on failure so the kind
|
|
142
|
-
* factory can skip-and-count rather than abort the whole analyst run.
|
|
143
|
-
*/
|
|
144
|
-
declare function parseRawFinding(row: unknown, log?: (msg: string, fields?: Record<string, unknown>) => void): RawAnalystFinding | null;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Analyst contract — the missing orchestration layer over agent-eval's
|
|
148
|
-
* existing analyzers (analyzeTraces, MultiLayerVerifier, RunCritic,
|
|
149
|
-
* SemanticConceptJudge, JudgeFn, ...).
|
|
150
|
-
*
|
|
151
|
-
* Each existing primitive returns its own output shape. The Analyst
|
|
152
|
-
* contract is the single envelope every primitive lifts into, so a
|
|
153
|
-
* registry can run N analysts against a run and a single renderer can
|
|
154
|
-
* compose findings without knowing which analyzer produced them.
|
|
155
|
-
*
|
|
156
|
-
* The contract is intentionally domain-agnostic: nothing here knows
|
|
157
|
-
* about code, voice, RAG, or any particular agent stack. Analysts
|
|
158
|
-
* declare what INPUT KIND they need (a trace store, an artifact dir,
|
|
159
|
-
* a RunRecord, a JudgeInput, or `custom`), and the registry routes
|
|
160
|
-
* the matching input from `AnalystRunInputs`.
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Unified envelope every analyst emits. Schema-versioned so renderers
|
|
165
|
-
* and time-series diffs survive future field additions.
|
|
166
|
-
*/
|
|
167
|
-
interface AnalystFinding {
|
|
168
|
-
schema_version: '1.0.0';
|
|
169
|
-
/**
|
|
170
|
-
* Stable hash over identity-defining fields (analyst_id + canonical
|
|
171
|
-
* claim + area + optional subject). Two findings from two runs that
|
|
172
|
-
* "are the same finding" share this id — that's what `diffFindings`
|
|
173
|
-
* uses to compute appeared/disappeared sets across runs.
|
|
174
|
-
*/
|
|
175
|
-
finding_id: string;
|
|
176
|
-
analyst_id: string;
|
|
177
|
-
produced_at: string;
|
|
178
|
-
severity: AnalystSeverity;
|
|
179
|
-
/**
|
|
180
|
-
* Coarse classification. Renderers group by this. Free-form so
|
|
181
|
-
* domain-specific analysts can introduce categories without a
|
|
182
|
-
* schema change ('agent-reasoning', 'verification', 'cost',
|
|
183
|
-
* 'tool-use', 'safety', 'latency', 'data-quality', ...).
|
|
184
|
-
*/
|
|
185
|
-
area: string;
|
|
186
|
-
claim: string;
|
|
187
|
-
rationale?: string;
|
|
188
|
-
evidence_refs: EvidenceRef[];
|
|
189
|
-
recommended_action?: string;
|
|
190
|
-
validation_plan?: string;
|
|
191
|
-
/** 0..1 — the analyst's own confidence. Not calibrated across analysts. */
|
|
192
|
-
confidence: number;
|
|
193
|
-
/**
|
|
194
|
-
* Optional subject the finding is about — leaf id, agent id, request
|
|
195
|
-
* id. Included in finding_id when present so per-subject findings
|
|
196
|
-
* diff cleanly across runs.
|
|
197
|
-
*/
|
|
198
|
-
subject?: string;
|
|
199
|
-
/** FIREWALL provenance (docs/learning-flywheel.md): true iff this finding was
|
|
200
|
-
* lifted from a JUDGE verdict (an acceptance score), not OBSERVED from the
|
|
201
|
-
* agent's behavior. A judge-derived finding must NEVER be admitted as a
|
|
202
|
-
* steering input — that is the held-out judge leaking into the loop. Set at
|
|
203
|
-
* the lift site (createJudgeAdapter); checked by `assertNoJudgeVerdict`.
|
|
204
|
-
* Provenance, not evidence presence, is the correct discriminator: an
|
|
205
|
-
* evidence-less trace-analyst observation legitimately steers, while a judge
|
|
206
|
-
* verdict that happens to cite an artifact must not. */
|
|
207
|
-
derived_from_judge?: boolean;
|
|
208
|
-
/** Analyst-private extras; renderers ignore unless they know the analyst. */
|
|
209
|
-
metadata?: Record<string, unknown>;
|
|
210
|
-
}
|
|
211
|
-
type AnalystSeverity = 'critical' | 'high' | 'medium' | 'low' | 'info';
|
|
212
|
-
interface EvidenceRef {
|
|
213
|
-
/**
|
|
214
|
-
* Where the evidence lives. `span` and `event` refer to OTLP trace
|
|
215
|
-
* elements; `artifact` to a file inside the run's artifact tree;
|
|
216
|
-
* `finding` to another AnalystFinding (cross-analyst chaining);
|
|
217
|
-
* `metric` to a named scalar reading the renderer knows how to read.
|
|
218
|
-
*/
|
|
219
|
-
kind: 'span' | 'event' | 'artifact' | 'finding' | 'metric';
|
|
220
|
-
uri: string;
|
|
221
|
-
excerpt?: string;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* The discriminator the registry uses to pass the right input.
|
|
225
|
-
* `custom` is the escape hatch — analysts that need something else
|
|
226
|
-
* (e.g. an embedding cache, a partner SDK handle) read it from
|
|
227
|
-
* `AnalystRunInputs.custom[<analyst id>]`.
|
|
228
|
-
*/
|
|
229
|
-
type AnalystInputKind = 'trace-store' | 'artifact-dir' | 'run-record' | 'judge-input' | 'custom';
|
|
230
|
-
interface AnalystCost {
|
|
231
|
-
/** `deterministic` analysts MUST NOT call the LLM. */
|
|
232
|
-
kind: 'deterministic' | 'llm';
|
|
233
|
-
/** Optional declared upper bound; the registry can enforce a budget. */
|
|
234
|
-
est_usd_per_run?: number;
|
|
235
|
-
/** Models the analyst expects to use (informational). */
|
|
236
|
-
models?: string[];
|
|
237
|
-
}
|
|
238
|
-
interface AnalystRequirements {
|
|
239
|
-
/** Min number of shots / samples the analyst needs to produce signal. */
|
|
240
|
-
min_shots?: number;
|
|
241
|
-
/** Capabilities the runtime must supply (e.g. ['network', 'gpu']). */
|
|
242
|
-
capabilities?: string[];
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* What's passed to every analyst call. The registry resolves which
|
|
246
|
-
* field the analyst's `inputKind` selects and asserts it's present.
|
|
247
|
-
*/
|
|
248
|
-
interface AnalystRunInputs {
|
|
249
|
-
traceStore?: TraceAnalysisStore;
|
|
250
|
-
artifactDir?: string;
|
|
251
|
-
runRecord?: RunRecord;
|
|
252
|
-
judgeInput?: JudgeInput;
|
|
253
|
-
/** Keyed by analyst id; populated by callers that registered custom analysts. */
|
|
254
|
-
custom?: Record<string, unknown>;
|
|
255
|
-
}
|
|
256
|
-
interface AnalystContext {
|
|
257
|
-
runId: string;
|
|
258
|
-
/** Stable correlation id so logs from a single registry.run() share a tag. */
|
|
259
|
-
correlationId: string;
|
|
260
|
-
/** Wall-clock deadline (epoch ms). Analysts SHOULD honor for graceful cancel. */
|
|
261
|
-
deadlineMs?: number;
|
|
262
|
-
/** Per-analyst USD budget. Analysts MAY check before issuing LLM calls. */
|
|
263
|
-
budgetUsd?: number;
|
|
264
|
-
/**
|
|
265
|
-
* Shared chat client. Analysts that call an LLM go through this so
|
|
266
|
-
* the operator picks transport (sandbox-sdk | router | cli-bridge |
|
|
267
|
-
* direct-provider | mock) at the registry boundary without touching
|
|
268
|
-
* analyst code.
|
|
269
|
-
*/
|
|
270
|
-
chat?: ChatClient;
|
|
271
|
-
/**
|
|
272
|
-
* Findings from a prior run the operator wants the analyst to see as
|
|
273
|
-
* retrieval context. Kinds that take advantage of cross-run memory
|
|
274
|
-
* (failure-mode "I saw this cluster last run", knowledge-gap "the wiki
|
|
275
|
-
* page I asked for is still missing") render these into the actor's
|
|
276
|
-
* working set. Filtering is the operator's job: pass the slice that
|
|
277
|
-
* matches the analyst's id, or pass everything and let the kind
|
|
278
|
-
* filter. Empty / absent means no cross-run context.
|
|
279
|
-
*/
|
|
280
|
-
priorFindings?: ReadonlyArray<AnalystFinding>;
|
|
281
|
-
/** Free-form runtime tags (env, host, op). Findings can echo these into metadata. */
|
|
282
|
-
tags?: Record<string, string>;
|
|
283
|
-
/** Logger callback — analysts SHOULD prefer this over console.* for testability. */
|
|
284
|
-
log?: (msg: string, fields?: Record<string, unknown>) => void;
|
|
285
|
-
/** Optional abort signal. Analysts SHOULD pass it through to LLM calls. */
|
|
286
|
-
signal?: AbortSignal;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* The minimal contract. Concrete analysts can refine `TInput` so
|
|
290
|
-
* implementations stay type-safe (e.g. a trace analyst's `TInput` is
|
|
291
|
-
* `TraceAnalysisStore`); the registry passes the right field from
|
|
292
|
-
* `AnalystRunInputs` based on `inputKind`.
|
|
293
|
-
*/
|
|
294
|
-
interface Analyst<TInput = unknown> {
|
|
295
|
-
/** Stable identifier — appears in finding_id, telemetry, and registry exclusion lists. */
|
|
296
|
-
readonly id: string;
|
|
297
|
-
/** Human-readable. One sentence. */
|
|
298
|
-
readonly description: string;
|
|
299
|
-
readonly inputKind: AnalystInputKind;
|
|
300
|
-
readonly cost: AnalystCost;
|
|
301
|
-
readonly requires?: AnalystRequirements;
|
|
302
|
-
/** Bump on breaking changes to claim wording or area so old finding_ids don't collide. */
|
|
303
|
-
readonly version: string;
|
|
304
|
-
analyze(input: TInput, ctx: AnalystContext): Promise<AnalystFinding[]>;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Compute the stable finding_id from the identity-defining fields.
|
|
308
|
-
* Default implementation hashes {analyst_id, area, subject, normalized claim}.
|
|
309
|
-
* Analysts that emit findings whose claim text varies per run (timestamps,
|
|
310
|
-
* counts) SHOULD either: (a) pass an explicit `id_basis` to fix the hash,
|
|
311
|
-
* or (b) move the variable part into `rationale`/`metadata` and keep the
|
|
312
|
-
* `claim` static.
|
|
313
|
-
*/
|
|
314
|
-
declare function computeFindingId(input: {
|
|
315
|
-
analyst_id: string;
|
|
316
|
-
area: string;
|
|
317
|
-
subject?: string;
|
|
318
|
-
claim: string;
|
|
319
|
-
/** Override the claim for hashing — use when the displayed claim has run-specific bits. */
|
|
320
|
-
id_basis?: string;
|
|
321
|
-
}): string;
|
|
322
|
-
/**
|
|
323
|
-
* Convenience factory: produce a fully-formed AnalystFinding with the
|
|
324
|
-
* id computed automatically. Analyst code stays terse.
|
|
325
|
-
*/
|
|
326
|
-
declare function makeFinding(init: Omit<AnalystFinding, 'schema_version' | 'finding_id' | 'produced_at'> & {
|
|
327
|
-
id_basis?: string;
|
|
328
|
-
produced_at?: string;
|
|
329
|
-
}): AnalystFinding;
|
|
330
|
-
interface AnalystRunSummary {
|
|
331
|
-
analyst_id: string;
|
|
332
|
-
status: 'ok' | 'skipped' | 'failed';
|
|
333
|
-
/** Why skipped — missing input, budget exceeded, capability unmet. */
|
|
334
|
-
reason?: string;
|
|
335
|
-
findings_count: number;
|
|
336
|
-
latency_ms: number;
|
|
337
|
-
cost_usd: number;
|
|
338
|
-
/** When `status='failed'`: the error class + message, never the full stack. */
|
|
339
|
-
error?: {
|
|
340
|
-
class: string;
|
|
341
|
-
message: string;
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
interface AnalystRunResult {
|
|
345
|
-
run_id: string;
|
|
346
|
-
correlation_id: string;
|
|
347
|
-
started_at: string;
|
|
348
|
-
ended_at: string;
|
|
349
|
-
findings: AnalystFinding[];
|
|
350
|
-
per_analyst: AnalystRunSummary[];
|
|
351
|
-
/** Total LLM cost in USD across all analysts in this registry.run(). */
|
|
352
|
-
total_cost_usd: number;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Events emitted by `AnalystRegistry.runStream(...)` in real time as
|
|
356
|
-
* the registry executes. UIs subscribe via `for await (const ev of
|
|
357
|
-
* registry.runStream(...))`; `registry.run(...)` is a thin collector
|
|
358
|
-
* over the same stream, so the two surfaces share their invariants.
|
|
359
|
-
*
|
|
360
|
-
* Per-finding events are intentionally omitted — analyzers are batch
|
|
361
|
-
* operations (an Ax actor returns the full `findings:json[]` at the
|
|
362
|
-
* end of the responder), so streaming inside one analyst would only
|
|
363
|
-
* emit partial JSON consumers can't render. The kind-completion event
|
|
364
|
-
* is the right granularity; subscribers wanting per-finding rendering
|
|
365
|
-
* iterate `event.findings` themselves.
|
|
366
|
-
*/
|
|
367
|
-
type AnalystRunEvent = {
|
|
368
|
-
type: 'run-started';
|
|
369
|
-
run_id: string;
|
|
370
|
-
correlation_id: string;
|
|
371
|
-
started_at: string;
|
|
372
|
-
/** The ordered list of analyst ids the registry will run. */
|
|
373
|
-
analyst_ids: ReadonlyArray<string>;
|
|
374
|
-
} | {
|
|
375
|
-
type: 'analyst-skipped';
|
|
376
|
-
summary: AnalystRunSummary;
|
|
377
|
-
} | {
|
|
378
|
-
type: 'analyst-started';
|
|
379
|
-
analyst_id: string;
|
|
380
|
-
started_at: string;
|
|
381
|
-
} | {
|
|
382
|
-
type: 'analyst-completed';
|
|
383
|
-
/** `summary.status` is `'ok'` for clean completion or `'failed'` for thrown analysts. */
|
|
384
|
-
summary: AnalystRunSummary;
|
|
385
|
-
findings: ReadonlyArray<AnalystFinding>;
|
|
386
|
-
} | {
|
|
387
|
-
type: 'run-completed';
|
|
388
|
-
result: AnalystRunResult;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Analyst-kind factory — the typed way to define trace analysts.
|
|
393
|
-
*
|
|
394
|
-
* A "kind" is a specialized analyst whose actor prompt, tool subset,
|
|
395
|
-
* and Ax recursion config target one failure-mode lens (failure-mode
|
|
396
|
-
* classification, knowledge gap discovery, knowledge poisoning, recursive
|
|
397
|
-
* self-improvement, ...). Kinds emit findings in the typed `RawAnalystFinding`
|
|
398
|
-
* shape via a JSON-array Ax output; the factory validates each row with
|
|
399
|
-
* Zod and lifts it into `AnalystFinding[]` with no shape guessing.
|
|
400
|
-
*
|
|
401
|
-
* Composition rules:
|
|
402
|
-
* - Each kind owns its actor description. No generic "answer this
|
|
403
|
-
* question" prompt — the prompt names the failure lens.
|
|
404
|
-
* - Each kind picks a narrow tool subset from `ANALYST_TOOL_GROUPS`.
|
|
405
|
-
* A kind that never needs full-trace dumps can drop `viewTrace` /
|
|
406
|
-
* `viewSpans` and stay cheap.
|
|
407
|
-
* - Each kind declares its recursion + parallelism budget. Discovery-
|
|
408
|
-
* heavy kinds (failure-mode) get higher `maxDepth`; lens kinds
|
|
409
|
-
* (poisoning) usually stay at 0 since they have a tighter brief.
|
|
410
|
-
*
|
|
411
|
-
* Optimizer hook: kinds may declare `goldens` — labeled examples used
|
|
412
|
-
* by `AxMiPRO` / `AxBootstrapFewShot` / `AxGEPA` to fit the actor
|
|
413
|
-
* description programmatically. Stored on the kind, not the registry,
|
|
414
|
-
* because the right metric is kind-specific.
|
|
415
|
-
*/
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Per-kind specification. The factory turns this into a regular
|
|
419
|
-
* `Analyst<TraceAnalysisStore>` ready for `AnalystRegistry.register()`.
|
|
420
|
-
*/
|
|
421
|
-
interface TraceAnalystKindSpec {
|
|
422
|
-
/** Stable id. Appears in finding_id, telemetry, and registry exclusions. */
|
|
423
|
-
id: string;
|
|
424
|
-
/** One-sentence description shown in `registry.list()`. */
|
|
425
|
-
description: string;
|
|
426
|
-
/** Coarse classification stamped on every emitted finding (`failure-mode`, `knowledge-gap`, ...). */
|
|
427
|
-
area: string;
|
|
428
|
-
/** Bump on any breaking change to the actor prompt or output schema. */
|
|
429
|
-
version: string;
|
|
430
|
-
/** Actor system prompt. Must instruct the LLM to emit `findings` per the schema. */
|
|
431
|
-
actorDescription: string;
|
|
432
|
-
/** Responder system prompt; falls back to a minimal "format the findings" instruction. */
|
|
433
|
-
responderDescription?: string;
|
|
434
|
-
/** Tool functions the actor may call. Pick narrow subsets via `ANALYST_TOOL_GROUPS`. */
|
|
435
|
-
buildTools: (store: TraceAnalysisStore) => AxFunction[];
|
|
436
|
-
/** Recursion budget. `maxDepth: 0` disables subagents. */
|
|
437
|
-
recursion?: {
|
|
438
|
-
maxDepth: number;
|
|
439
|
-
maxParallelSubagents?: number;
|
|
440
|
-
};
|
|
441
|
-
/** Actor turn cap. Default 12. */
|
|
442
|
-
maxTurns?: number;
|
|
443
|
-
/** Runtime char cap. Default 6000. */
|
|
444
|
-
maxRuntimeChars?: number;
|
|
445
|
-
/** Cost classification surfaced in `registry.list()` and budget enforcement. */
|
|
446
|
-
cost: AnalystCost;
|
|
447
|
-
/** Per-finding-row hook — kinds may reject / rewrite before lifting. */
|
|
448
|
-
postProcess?: (row: RawAnalystFinding, ctx: AnalystContext) => RawAnalystFinding | null;
|
|
449
|
-
/** Optional optimizer hook — populated when a kind wants to fit its prompt against labeled examples. */
|
|
450
|
-
goldens?: TraceAnalystGolden[];
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* One labeled example consumed by Ax optimizers (MIPRO / GEPA / Bootstrap).
|
|
454
|
-
* Each input is the same `{question}` an analyst would receive; `expected`
|
|
455
|
-
* is the ground-truth finding set a fitted prompt should produce on this
|
|
456
|
-
* input. Metric: kind-specific (default: F1 on `finding_id` overlap).
|
|
457
|
-
*/
|
|
458
|
-
interface TraceAnalystGolden {
|
|
459
|
-
question: string;
|
|
460
|
-
expected: ReadonlyArray<Omit<RawAnalystFinding, 'confidence'>>;
|
|
461
|
-
}
|
|
462
|
-
interface CreateTraceAnalystKindOpts {
|
|
463
|
-
/** AxAIService bound at registration time. */
|
|
464
|
-
ai: AxAIService;
|
|
465
|
-
/** Optional model override; falls back to the AI service's default. */
|
|
466
|
-
model?: string;
|
|
467
|
-
/** Override the spec's `version` (e.g. when an optimizer has fitted a new prompt). */
|
|
468
|
-
versionSuffix?: string;
|
|
469
|
-
/**
|
|
470
|
-
* Optional two-phase recovery: when the agentic harvest is empty but the
|
|
471
|
-
* actor produced a substantive free-form `report`, extract findings from that
|
|
472
|
-
* prose via a tolerant chat-completions pass (`structureFindings`) — no
|
|
473
|
-
* strict-emission contract, so it works on weak models. Omit to leave the
|
|
474
|
-
* actor's harvest as-is (the report is still surfaced fail-loud either way).
|
|
475
|
-
*/
|
|
476
|
-
recovery?: {
|
|
477
|
-
baseUrl: string;
|
|
478
|
-
apiKey?: string;
|
|
479
|
-
model?: string;
|
|
480
|
-
fetchImpl?: typeof fetch;
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Build an `Analyst<TraceAnalysisStore>` from a kind spec.
|
|
485
|
-
*
|
|
486
|
-
* Lifts the Ax pipeline once at registration time so the registry
|
|
487
|
-
* gets a stateless analyst. The Ax agent is freshly constructed per
|
|
488
|
-
* `analyze()` call (the agent carries chat-log + usage state we don't
|
|
489
|
-
* want shared across analyst runs).
|
|
490
|
-
*/
|
|
491
|
-
declare function createTraceAnalystKind(spec: TraceAnalystKindSpec, opts: CreateTraceAnalystKindOpts): Analyst<TraceAnalysisStore>;
|
|
492
|
-
/**
|
|
493
|
-
* Render a compact prior-findings block the actor reads alongside its
|
|
494
|
-
* brief. Each row is one line so the actor can scan dozens cheaply.
|
|
495
|
-
* The kind's prompt instructs the actor to (a) check whether a new
|
|
496
|
-
* cluster matches a prior `finding_id` (carry the id forward via
|
|
497
|
-
* `id_basis` to keep diffs stable) and (b) raise severity / confidence
|
|
498
|
-
* when a prior finding has reappeared without remediation.
|
|
499
|
-
*
|
|
500
|
-
* Returns the empty string when there are no prior findings — most
|
|
501
|
-
* runs are "first-of-its-kind" and the prompt stays unchanged.
|
|
502
|
-
*
|
|
503
|
-
* Exported for tests + for consumers that build their own actor
|
|
504
|
-
* prompts (e.g. specialized analysts living outside the default kinds).
|
|
505
|
-
*/
|
|
506
|
-
declare function renderPriorFindings(prior: AnalystContext['priorFindings']): string;
|
|
507
|
-
|
|
508
|
-
export { type AnalystFinding as A, parseRawFinding as B, type ChatClient as C, type DirectProviderTransportOpts as D, type EvidenceRef as E, renderPriorFindings as F, type MockTransportOpts as M, RAW_FINDING_SCHEMA_PROMPT as R, type SandboxSdkTransportOpts as S, type TraceAnalystKindSpec as T, type Analyst as a, type AnalystContext as b, type AnalystRunSummary as c, type AnalystRunResult as d, type AnalystRunInputs as e, type AnalystRunEvent as f, type AnalystSeverity as g, ANALYST_SEVERITIES as h, type AnalystCost as i, type AnalystInputKind as j, type AnalystRequirements as k, type ChatCallOpts as l, type ChatRequest as m, type ChatResponse as n, type ChatTransport as o, type CliBridgeTransportOpts as p, type CreateChatClientOpts as q, type CreateTraceAnalystKindOpts as r, type RawAnalystFinding as s, RawAnalystFindingSchema as t, type RouterTransportOpts as u, type TraceAnalystGolden as v, computeFindingId as w, createChatClient as x, createTraceAnalystKind as y, makeFinding as z };
|