@arnilo/prism-hosts 0.0.0-stage → 0.13.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 +394 -0
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/acp/README.md +87 -0
- package/acp/src/capabilities.ts +184 -0
- package/acp/src/errors.ts +24 -0
- package/acp/src/host.ts +36 -0
- package/acp/src/index.ts +25 -0
- package/acp/src/limits.ts +49 -0
- package/acp/src/mapper.ts +419 -0
- package/acp/src/permission.ts +37 -0
- package/acp/src/projection.ts +39 -0
- package/acp/src/prompt.ts +170 -0
- package/acp/src/serve.ts +345 -0
- package/acp/src/session-map.ts +49 -0
- package/ag-ui/README.md +56 -0
- package/ag-ui/src/a2ui.ts +570 -0
- package/ag-ui/src/ag-ui-mapper.ts +507 -0
- package/ag-ui/src/encrypted-value.ts +40 -0
- package/ag-ui/src/errors.ts +29 -0
- package/ag-ui/src/handler.ts +642 -0
- package/ag-ui/src/index.ts +177 -0
- package/ag-ui/src/input.ts +190 -0
- package/ag-ui/src/limits.ts +279 -0
- package/ag-ui/src/mcp-apps.ts +256 -0
- package/ag-ui/src/mcp.ts +94 -0
- package/ag-ui/src/projection.ts +201 -0
- package/ag-ui/src/projectors.ts +272 -0
- package/ag-ui/src/renderer/bind.ts +152 -0
- package/ag-ui/src/renderer/core.ts +270 -0
- package/ag-ui/src/renderer/index.ts +165 -0
- package/ag-ui/src/replay.ts +189 -0
- package/ag-ui/src/types.ts +66 -0
- package/channels/README.md +139 -0
- package/channels/src/admission.ts +8 -0
- package/channels/src/approvals.ts +262 -0
- package/channels/src/checkpoint-contract.ts +97 -0
- package/channels/src/delivery.ts +116 -0
- package/channels/src/host-ui.ts +356 -0
- package/channels/src/identity.ts +46 -0
- package/channels/src/index.ts +82 -0
- package/channels/src/limits.ts +49 -0
- package/channels/src/memory-stores.ts +112 -0
- package/channels/src/pairing.ts +178 -0
- package/channels/src/runtime-admit.ts +389 -0
- package/channels/src/runtime-core.ts +621 -0
- package/channels/src/runtime-reconcile.ts +299 -0
- package/channels/src/runtime-turn.ts +664 -0
- package/channels/src/runtime-types.ts +95 -0
- package/channels/src/runtime.ts +86 -0
- package/channels/src/secret-ref.ts +42 -0
- package/channels/src/signal.ts +790 -0
- package/channels/src/state.ts +355 -0
- package/channels/src/telegram.ts +1317 -0
- package/channels/src/types.ts +442 -0
- package/devtools/README.md +92 -0
- package/devtools/bin/prism-devtools.ts +63 -0
- package/devtools/src/args.ts +71 -0
- package/devtools/src/bun.d.ts +27 -0
- package/devtools/src/compare.ts +190 -0
- package/devtools/src/errors.ts +15 -0
- package/devtools/src/index.ts +25 -0
- package/devtools/src/replay.ts +36 -0
- package/devtools/src/security.ts +80 -0
- package/devtools/src/serve.ts +259 -0
- package/devtools/src/ui/assets.ts +108 -0
- package/devtools/src/ui/inspector.ts +182 -0
- package/driver-process/README.md +197 -0
- package/driver-process/src/abort.ts +74 -0
- package/driver-process/src/adapter.ts +211 -0
- package/driver-process/src/driver.ts +303 -0
- package/driver-process/src/errors.ts +17 -0
- package/driver-process/src/extend.ts +72 -0
- package/driver-process/src/index.ts +5 -0
- package/driver-process/src/inspect.ts +33 -0
- package/driver-process/src/session.ts +72 -0
- package/driver-process/src/testing.ts +394 -0
- package/driver-process/src/transports/json-rpc.ts +147 -0
- package/driver-process/src/transports/jsonl-stream.ts +12 -0
- package/driver-process/src/transports/types.ts +11 -0
- package/driver-process/src/turn.ts +106 -0
- package/evals/README.md +843 -0
- package/evals/src/calibration.ts +179 -0
- package/evals/src/citation-integrity.ts +98 -0
- package/evals/src/citations.ts +45 -0
- package/evals/src/compare-experiments.ts +153 -0
- package/evals/src/comparison.ts +230 -0
- package/evals/src/curate.ts +257 -0
- package/evals/src/dataset.ts +81 -0
- package/evals/src/erp-invariants.ts +163 -0
- package/evals/src/errors.ts +23 -0
- package/evals/src/experiment.ts +537 -0
- package/evals/src/failure-injection.ts +77 -0
- package/evals/src/feedback.ts +53 -0
- package/evals/src/index.ts +198 -0
- package/evals/src/injection.ts +247 -0
- package/evals/src/judge-panel.ts +109 -0
- package/evals/src/judge.ts +89 -0
- package/evals/src/limits.ts +50 -0
- package/evals/src/report-record.ts +47 -0
- package/evals/src/rubric-judge.ts +334 -0
- package/evals/src/scenario-runner.ts +317 -0
- package/evals/src/scenarios.ts +81 -0
- package/evals/src/score.ts +328 -0
- package/evals/src/scorer.ts +21 -0
- package/evals/src/state-match.ts +130 -0
- package/evals/src/stats.ts +635 -0
- package/evals/src/threshold.ts +117 -0
- package/evals/src/timeline.ts +38 -0
- package/evals/src/toolless-session.ts +33 -0
- package/evals/src/trace.ts +80 -0
- package/evals/src/trajectory.ts +623 -0
- package/evals/src/types.ts +672 -0
- package/evals/src/user-simulator.ts +101 -0
- package/evals/src/util.ts +207 -0
- package/headless/README.md +172 -0
- package/headless/src/answers.ts +91 -0
- package/headless/src/authority.ts +32 -0
- package/headless/src/errors.ts +36 -0
- package/headless/src/index.ts +17 -0
- package/headless/src/limits.ts +11 -0
- package/headless/src/pending.ts +16 -0
- package/headless/src/policy.ts +36 -0
- package/headless/src/resume.ts +103 -0
- package/headless/src/route.ts +153 -0
- package/headless/src/scheduler/clock.ts +22 -0
- package/headless/src/scheduler/cron.ts +19 -0
- package/headless/src/scheduler/firing.ts +58 -0
- package/headless/src/scheduler/index.ts +399 -0
- package/headless/src/scheduler/lease.ts +38 -0
- package/headless/src/scheduler/missed.ts +12 -0
- package/headless/src/scheduler/state.ts +132 -0
- package/host-builder/README.md +251 -0
- package/host-builder/bin/prism-host-builder.ts +169 -0
- package/host-builder/data/api.json +6167 -0
- package/host-builder/data/errors.json +546 -0
- package/host-builder/data/examples/acp.ts +63 -0
- package/host-builder/data/examples/adapters/conformance.ts +34 -0
- package/host-builder/data/examples/adapters/fixtures/rpc-server.json +26 -0
- package/host-builder/data/examples/adapters/fixtures/stream-cli.json +27 -0
- package/host-builder/data/examples/adapters/fixtures/workspace-config.json +28 -0
- package/host-builder/data/examples/adapters/rpc-server.dialect.ts +218 -0
- package/host-builder/data/examples/adapters/rpc-server.ts +309 -0
- package/host-builder/data/examples/adapters/stream-cli.dialect.ts +165 -0
- package/host-builder/data/examples/adapters/stream-cli.ts +256 -0
- package/host-builder/data/examples/adapters/workspace-config.dialect.ts +172 -0
- package/host-builder/data/examples/adapters/workspace-config.ts +251 -0
- package/host-builder/data/examples/advisor.ts +94 -0
- package/host-builder/data/examples/ag-ui-a2ui.ts +80 -0
- package/host-builder/data/examples/ag-ui-mcp-apps.ts +44 -0
- package/host-builder/data/examples/ag-ui-server.ts +118 -0
- package/host-builder/data/examples/agent-durable-approval.ts +43 -0
- package/host-builder/data/examples/api-key-auth.ts +23 -0
- package/host-builder/data/examples/approval.ts +92 -0
- package/host-builder/data/examples/attention-compiler.ts +81 -0
- package/host-builder/data/examples/autonomous-coding-loop.ts +343 -0
- package/host-builder/data/examples/behavior-evaluation.ts +303 -0
- package/host-builder/data/examples/build-workflow.ts +334 -0
- package/host-builder/data/examples/cache-aware-prompt-assembly.ts +139 -0
- package/host-builder/data/examples/caveman-ponytail.ts +197 -0
- package/host-builder/data/examples/cli.ts +31 -0
- package/host-builder/data/examples/coding-approval.ts +115 -0
- package/host-builder/data/examples/coding-browser-evaluation.ts +208 -0
- package/host-builder/data/examples/coding-compaction.ts +30 -0
- package/host-builder/data/examples/coding-goal-verify.ts +121 -0
- package/host-builder/data/examples/coding-tools-capability-gaps.ts +75 -0
- package/host-builder/data/examples/compaction.ts +36 -0
- package/host-builder/data/examples/connected-slack-mcp.ts +67 -0
- package/host-builder/data/examples/context.ts +29 -0
- package/host-builder/data/examples/custom-adapter.ts +256 -0
- package/host-builder/data/examples/custom-builders.ts +66 -0
- package/host-builder/data/examples/custom-loop.ts +89 -0
- package/host-builder/data/examples/custom-provider.ts +70 -0
- package/host-builder/data/examples/custom-session-store.ts +72 -0
- package/host-builder/data/examples/custom-tools-skills-context.ts +97 -0
- package/host-builder/data/examples/decision-models.ts +98 -0
- package/host-builder/data/examples/define-package.ts +188 -0
- package/host-builder/data/examples/delegate.ts +200 -0
- package/host-builder/data/examples/discover-skills.ts +65 -0
- package/host-builder/data/examples/drive-rag-sync.ts +44 -0
- package/host-builder/data/examples/durable-approval.ts +139 -0
- package/host-builder/data/examples/durable-investigation.ts +93 -0
- package/host-builder/data/examples/durable-loops-and-approvals.ts +94 -0
- package/host-builder/data/examples/enterprise-identity.ts +21 -0
- package/host-builder/data/examples/enterprise-policy-audit.ts +50 -0
- package/host-builder/data/examples/enterprise-work-connectors.ts +103 -0
- package/host-builder/data/examples/eval-injection.ts +73 -0
- package/host-builder/data/examples/eval-judges.ts +145 -0
- package/host-builder/data/examples/evals.ts +86 -0
- package/host-builder/data/examples/evaluation-gate.ts +40 -0
- package/host-builder/data/examples/execution-timeline.ts +173 -0
- package/host-builder/data/examples/external-agent.ts +541 -0
- package/host-builder/data/examples/external-app-db-backed.ts +344 -0
- package/host-builder/data/examples/governance-deny.ts +122 -0
- package/host-builder/data/examples/guardrail-packs.ts +240 -0
- package/host-builder/data/examples/headless-host.ts +245 -0
- package/host-builder/data/examples/hooks-audit-command.mjs +31 -0
- package/host-builder/data/examples/hooks-json.ts +87 -0
- package/host-builder/data/examples/host-builder-agent.ts +150 -0
- package/host-builder/data/examples/host-hooks.ts +71 -0
- package/host-builder/data/examples/host-step-loop-timeline.ts +212 -0
- package/host-builder/data/examples/hosted-sandbox.ts +48 -0
- package/host-builder/data/examples/instruction-injection.ts +127 -0
- package/host-builder/data/examples/jsonl-stores-branching.ts +49 -0
- package/host-builder/data/examples/long-term-memory.ts +158 -0
- package/host-builder/data/examples/manifest.ts +112 -0
- package/host-builder/data/examples/mcp-server.ts +48 -0
- package/host-builder/data/examples/mcp-trust.ts +173 -0
- package/host-builder/data/examples/memory-and-wiki.ts +315 -0
- package/host-builder/data/examples/memory-lifecycle.ts +302 -0
- package/host-builder/data/examples/memory-system.ts +252 -0
- package/host-builder/data/examples/messaging-agent.ts +70 -0
- package/host-builder/data/examples/minimal-host-app.ts +41 -0
- package/host-builder/data/examples/model-router-aggregate-budgets.ts +364 -0
- package/host-builder/data/examples/model-router.ts +106 -0
- package/host-builder/data/examples/obscura.ts +48 -0
- package/host-builder/data/examples/observability.ts +116 -0
- package/host-builder/data/examples/open-connector-sidecar.ts +105 -0
- package/host-builder/data/examples/openai-compatible.ts +70 -0
- package/host-builder/data/examples/package-skills.ts +85 -0
- package/host-builder/data/examples/phase9-coding-intelligence.ts +221 -0
- package/host-builder/data/examples/provider-registration.ts +29 -0
- package/host-builder/data/examples/provider-resolver.ts +39 -0
- package/host-builder/data/examples/rag.ts +40 -0
- package/host-builder/data/examples/remote-agent-server.ts +45 -0
- package/host-builder/data/examples/remote-agent.ts +124 -0
- package/host-builder/data/examples/research-ledger.ts +79 -0
- package/host-builder/data/examples/revocation-propagation.ts +287 -0
- package/host-builder/data/examples/run-feedback.ts +93 -0
- package/host-builder/data/examples/scanned-document-rag.ts +48 -0
- package/host-builder/data/examples/sdk-basics.ts +21 -0
- package/host-builder/data/examples/secure-agent.ts +55 -0
- package/host-builder/data/examples/semantic-memory.ts +52 -0
- package/host-builder/data/examples/serve-tools.ts +495 -0
- package/host-builder/data/examples/session-memory.ts +317 -0
- package/host-builder/data/examples/session-search.ts +131 -0
- package/host-builder/data/examples/session.ts +52 -0
- package/host-builder/data/examples/side-call.ts +64 -0
- package/host-builder/data/examples/signal-agent.ts +9 -0
- package/host-builder/data/examples/skills-progressive-disclosure.ts +88 -0
- package/host-builder/data/examples/skills.ts +19 -0
- package/host-builder/data/examples/sqlite-resume.ts +147 -0
- package/host-builder/data/examples/system-project-prompts.ts +74 -0
- package/host-builder/data/examples/system-prompts.ts +19 -0
- package/host-builder/data/examples/telegram-agent.ts +30 -0
- package/host-builder/data/examples/tool-narrowing-planes.ts +99 -0
- package/host-builder/data/examples/tools.ts +29 -0
- package/host-builder/data/examples/validator.ts +67 -0
- package/host-builder/data/examples/web-no-key.ts +85 -0
- package/host-builder/data/examples/web-research.ts +35 -0
- package/host-builder/data/examples/workflow-event-sink.ts +114 -0
- package/host-builder/data/examples/workflow-loop.ts +93 -0
- package/host-builder/data/examples/workflow-multimodal-document.ts +94 -0
- package/host-builder/data/examples/workflow-parallel-research.ts +111 -0
- package/host-builder/data/examples/workflow-postgres-resume.ts +75 -0
- package/host-builder/data/examples/workflow-research-and-review.ts +98 -0
- package/host-builder/data/examples/workflow-sqlite-resume.ts +163 -0
- package/host-builder/data/examples.json +130 -0
- package/host-builder/skills/prism-host-builder/SKILL.md +85 -0
- package/host-builder/skills/prism-host-builder/references/choosing.md +101 -0
- package/host-builder/skills/prism-host-builder/references/layout.md +52 -0
- package/host-builder/skills/prism-host-builder/references/pitfalls.md +50 -0
- package/host-builder/skills/prism-host-builder/references/recipes.md +129 -0
- package/host-builder/skills/prism-host-builder/references/security.md +52 -0
- package/host-builder/skills/prism-host-builder/references/upgrading.md +67 -0
- package/host-builder/skills/prism-host-builder/references/verification.md +108 -0
- package/host-builder/src/check/child.ts +108 -0
- package/host-builder/src/check/conformance.ts +13 -0
- package/host-builder/src/check/inspect.ts +20 -0
- package/host-builder/src/check/manifest.ts +23 -0
- package/host-builder/src/check/runner.ts +181 -0
- package/host-builder/src/check/targets.ts +65 -0
- package/host-builder/src/errors.ts +35 -0
- package/host-builder/src/index.ts +25 -0
- package/host-builder/src/indexes.ts +145 -0
- package/host-builder/src/install/install.ts +400 -0
- package/host-builder/src/install/targets.ts +50 -0
- package/host-builder/src/lookup/api.ts +127 -0
- package/host-builder/src/lookup/bound.ts +38 -0
- package/host-builder/src/lookup/docs.ts +238 -0
- package/host-builder/src/lookup/errors.ts +92 -0
- package/host-builder/src/lookup/examples.ts +117 -0
- package/host-builder/src/lookup/text.ts +60 -0
- package/host-builder/src/server.ts +300 -0
- package/host-builder/src/version.ts +38 -0
- package/mcp-server/README.md +219 -0
- package/mcp-server/src/bounds.ts +23 -0
- package/mcp-server/src/host.ts +31 -0
- package/mcp-server/src/index.ts +27 -0
- package/mcp-server/src/serve-tools.ts +408 -0
- package/mcp-server/src/serve.ts +329 -0
- package/mcp-server/src/server.ts +331 -0
- package/mcp-server/src/session-map.ts +47 -0
- package/mcp-server/src/skill-resources.ts +85 -0
- package/mcp-server/src/types.ts +215 -0
- package/package.json +130 -4
- package/remote/README.md +244 -0
- package/remote/src/attribution.ts +22 -0
- package/remote/src/auth.ts +30 -0
- package/remote/src/bun-module.d.ts +34 -0
- package/remote/src/channel.ts +86 -0
- package/remote/src/connect.ts +212 -0
- package/remote/src/dispatcher.ts +282 -0
- package/remote/src/errors.ts +59 -0
- package/remote/src/host-ui.ts +152 -0
- package/remote/src/http-gate.ts +43 -0
- package/remote/src/index.ts +53 -0
- package/remote/src/jsonl.ts +69 -0
- package/remote/src/limits.ts +43 -0
- package/remote/src/mirror.ts +90 -0
- package/remote/src/pending.ts +22 -0
- package/remote/src/protocol.ts +107 -0
- package/remote/src/serve.ts +560 -0
- package/remote/src/session-proxy.ts +219 -0
- package/remote/src/sse.ts +38 -0
- package/remote/src/stdio-client.ts +41 -0
- package/remote/src/testing-fixtures/serve-stdio.ts +32 -0
- package/remote/src/testing.ts +230 -0
- package/remote/src/transport.ts +139 -0
- package/remote/src/transports/client.ts +126 -0
- package/remote/src/transports/network.ts +268 -0
- package/remote/src/wire.ts +244 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { resolveRedactor } from "@arnilo/prism";
|
|
2
|
+
import { compareExperiments } from "./compare-experiments.js";
|
|
3
|
+
import { EvalError } from "./errors.js";
|
|
4
|
+
import { DEFAULT_REPORT_MAX_BYTES, HARD_REPORT_MAX_BYTES } from "./limits.js";
|
|
5
|
+
import type { ComparisonReport, EvaluationThresholds, ExperimentReport } from "./types.js";
|
|
6
|
+
import { assertFiniteUnitInterval } from "./util.js";
|
|
7
|
+
|
|
8
|
+
export class EvalThresholdError extends EvalError {
|
|
9
|
+
constructor(message: string) {
|
|
10
|
+
super(message, "ERR_PRISM_EVAL_THRESHOLD");
|
|
11
|
+
this.name = "EvalThresholdError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Fail a CI process through a stable thrown error when report thresholds regress. */
|
|
16
|
+
export function assertEvaluationThreshold(report: ExperimentReport | ComparisonReport, thresholds: EvaluationThresholds): void {
|
|
17
|
+
const failures: string[] = [];
|
|
18
|
+
const experiment = "aggregate" in report ? report : undefined;
|
|
19
|
+
const comparison = "wins" in report ? report : undefined;
|
|
20
|
+
if (thresholds.minimumMacroMean !== undefined) {
|
|
21
|
+
const minimum = assertFiniteUnitInterval(thresholds.minimumMacroMean, "minimumMacroMean");
|
|
22
|
+
if (!experiment || experiment.aggregate.macroMean === undefined || experiment.aggregate.macroMean < minimum)
|
|
23
|
+
failures.push(`macro mean < ${minimum}`);
|
|
24
|
+
}
|
|
25
|
+
const maximumFailures = thresholds.maximumFailures ?? 0;
|
|
26
|
+
if (!Number.isInteger(maximumFailures) || maximumFailures < 0) throw new EvalThresholdError("maximumFailures must be an integer >= 0");
|
|
27
|
+
const failedCount = experiment?.aggregate.failedCount ?? comparison?.failures ?? 0;
|
|
28
|
+
if (failedCount > maximumFailures) failures.push(`failures > ${maximumFailures}`);
|
|
29
|
+
for (const [scorerId, rawMinimum] of Object.entries(thresholds.minimumByScorer ?? {}).sort()) {
|
|
30
|
+
const minimum = assertFiniteUnitInterval(rawMinimum, `minimumByScorer.${scorerId}`);
|
|
31
|
+
const mean = experiment?.aggregate.scorers[scorerId]?.mean;
|
|
32
|
+
if (mean === undefined || mean < minimum) failures.push(`${scorerId} mean < ${minimum}`);
|
|
33
|
+
}
|
|
34
|
+
for (const [scorerId, { k, minimum: rawMinimum }] of Object.entries(thresholds.minimumPassHatK ?? {}).sort()) {
|
|
35
|
+
if (!Number.isSafeInteger(k) || k < 1) throw new EvalThresholdError(`minimumPassHatK.${scorerId}.k must be an integer >= 1`);
|
|
36
|
+
const minimum = assertFiniteUnitInterval(rawMinimum, `minimumPassHatK.${scorerId}.minimum`);
|
|
37
|
+
const value = experiment?.aggregate.scorers[scorerId]?.passHatK?.[k];
|
|
38
|
+
if (value === undefined || value < minimum) failures.push(`${scorerId} pass^${k} < ${minimum} or unavailable`);
|
|
39
|
+
}
|
|
40
|
+
for (const [scorerId, rawMinimum] of Object.entries(thresholds.minimumLowerBound ?? {}).sort()) {
|
|
41
|
+
const minimum = assertFiniteUnitInterval(rawMinimum, `minimumLowerBound.${scorerId}`);
|
|
42
|
+
const ci = experiment?.aggregate.scorers[scorerId]?.ci95;
|
|
43
|
+
if (!ci || !Number.isFinite(ci.low) || !Number.isFinite(ci.high) || ci.low < 0 || ci.high > 1 || ci.low > ci.high) {
|
|
44
|
+
failures.push(`${scorerId} lower bound < ${minimum}: ci95 unavailable or invalid`);
|
|
45
|
+
} else if (ci.low < minimum) {
|
|
46
|
+
failures.push(`${scorerId} lower bound < ${minimum}: ci95=[${ci.low}, ${ci.high}]`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (thresholds.maximumRegression) {
|
|
50
|
+
const { baseline, delta = 0, alpha = 0.05, scorers } = thresholds.maximumRegression;
|
|
51
|
+
assertFiniteUnitInterval(delta, "maximumRegression.delta");
|
|
52
|
+
if (!experiment) throw new EvalThresholdError("maximumRegression requires an experiment report");
|
|
53
|
+
const compared = compareExperiments(baseline, experiment, { alpha, scorers });
|
|
54
|
+
for (const [scorerId, stats] of Object.entries(compared.scorers)) {
|
|
55
|
+
if (stats.difference < -delta && stats.significant) {
|
|
56
|
+
failures.push(
|
|
57
|
+
`${scorerId} difference ${stats.difference} < -${delta}: ci95=[${stats.ci95.low}, ${stats.ci95.high}], p=${stats.pValue}, q=${stats.qValue} <= alpha=${alpha}`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const [scorerId, { report: calibration, minimumKappa, minimumN = 30 }] of Object.entries(thresholds.calibrations ?? {}).sort()) {
|
|
63
|
+
if (!Number.isFinite(minimumKappa) || minimumKappa < -1 || minimumKappa > 1 || !Number.isSafeInteger(minimumN) || minimumN < 1) {
|
|
64
|
+
throw new EvalThresholdError(`invalid calibration threshold for ${scorerId}`);
|
|
65
|
+
}
|
|
66
|
+
const used = experiment
|
|
67
|
+
? experiment.evaluations.some((record) => record.scorerId === scorerId)
|
|
68
|
+
: comparison?.records.some((record) => record.scorerId === scorerId);
|
|
69
|
+
if (!used) continue;
|
|
70
|
+
const ci = calibration?.kappaCi95;
|
|
71
|
+
const validKappa = (value: unknown): value is number =>
|
|
72
|
+
typeof value === "number" && Number.isFinite(value) && value >= -1 && value <= 1;
|
|
73
|
+
if (
|
|
74
|
+
!calibration ||
|
|
75
|
+
!Number.isSafeInteger(calibration.n) ||
|
|
76
|
+
calibration.n < minimumN ||
|
|
77
|
+
!validKappa(calibration.cohensKappa) ||
|
|
78
|
+
(ci !== undefined && (!ci || !validKappa(ci.low) || !validKappa(ci.high) || ci.low > ci.high)) ||
|
|
79
|
+
(ci?.low ?? calibration.cohensKappa ?? -Infinity) < minimumKappa
|
|
80
|
+
) {
|
|
81
|
+
failures.push(`${scorerId} calibration requires n >= ${minimumN} and kappa lower bound >= ${minimumKappa}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const [candidate, minimum] of Object.entries(thresholds.minimumCandidateWins ?? {}).sort()) {
|
|
85
|
+
if (!Number.isInteger(minimum) || minimum < 0)
|
|
86
|
+
throw new EvalThresholdError(`minimumCandidateWins.${candidate} must be an integer >= 0`);
|
|
87
|
+
if ((comparison?.wins[candidate] ?? 0) < minimum) failures.push(`${candidate} wins < ${minimum}`);
|
|
88
|
+
}
|
|
89
|
+
if (experiment?.aggregate.invariantsPassed === false) {
|
|
90
|
+
failures.push("hard invariant failed");
|
|
91
|
+
}
|
|
92
|
+
// Requiring invariants means requiring evidence that they ran: an omitted invariant scorer is a gap.
|
|
93
|
+
if (thresholds.requireInvariants === true && experiment?.aggregate.invariantsPassed !== true) {
|
|
94
|
+
const reason = experiment?.aggregate.invariantsPassed === false ? "hard invariant failed" : "no invariant scorers evaluated";
|
|
95
|
+
if (!failures.includes(reason)) failures.push(reason);
|
|
96
|
+
}
|
|
97
|
+
if (failures.length) throw new EvalThresholdError(failures.join("; "));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Produce deterministic, bounded, optionally redacted JSON suitable for CI artifacts. */
|
|
101
|
+
export function serializeEvaluationReport(
|
|
102
|
+
report: unknown,
|
|
103
|
+
options: {
|
|
104
|
+
readonly maxBytes?: number;
|
|
105
|
+
readonly redactor?: import("@arnilo/prism").SecretRedactor;
|
|
106
|
+
readonly secrets?: readonly (string | undefined)[];
|
|
107
|
+
} = {},
|
|
108
|
+
): string {
|
|
109
|
+
const maxBytes = options.maxBytes ?? DEFAULT_REPORT_MAX_BYTES;
|
|
110
|
+
if (!Number.isInteger(maxBytes) || maxBytes < 1 || maxBytes > HARD_REPORT_MAX_BYTES) {
|
|
111
|
+
throw new EvalError(`maxBytes must be an integer in [1, ${HARD_REPORT_MAX_BYTES}]`, "ERR_PRISM_EVAL_REPORT_BOUNDS");
|
|
112
|
+
}
|
|
113
|
+
const redactor = resolveRedactor(options.redactor, options.secrets);
|
|
114
|
+
const json = JSON.stringify(redactor ? redactor.redact(report) : report, null, 2);
|
|
115
|
+
if (Buffer.byteLength(json) > maxBytes) throw new EvalError("evaluation report byte limit exceeded", "ERR_PRISM_EVAL_REPORT_BOUNDS");
|
|
116
|
+
return json;
|
|
117
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeline projection is the only reason evals needs `@arnilo/prism-extensions/observability`, so it is an
|
|
3
|
+
* optional peer loaded on demand. A host that scores text only never installs it, and a host that
|
|
4
|
+
* asks for a timeline without it gets a named error instead of a module-resolution stack.
|
|
5
|
+
*/
|
|
6
|
+
import { EvalError } from "./errors.js";
|
|
7
|
+
|
|
8
|
+
type Observability = typeof import("@arnilo/prism-extensions/observability");
|
|
9
|
+
|
|
10
|
+
/** The two projections evals needs from the optional peer. */
|
|
11
|
+
export type TimelineTools = Pick<Observability, "createTimelineFolder" | "projectTraceTimeline">;
|
|
12
|
+
|
|
13
|
+
const TIMELINE_PACKAGE = "@arnilo/prism-extensions/observability";
|
|
14
|
+
|
|
15
|
+
let importer = (): Promise<Observability> => import("@arnilo/prism-extensions/observability");
|
|
16
|
+
|
|
17
|
+
/** @internal Test seam: production always resolves through this module's literal import. */
|
|
18
|
+
export function setTimelineImporterForTests(next?: () => Promise<Observability>): void {
|
|
19
|
+
importer = next ?? ((): Promise<Observability> => import("@arnilo/prism-extensions/observability"));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Load the optional observability peer. Called only on the timeline path, so text-only scoring and
|
|
24
|
+
* experiments never touch it.
|
|
25
|
+
*/
|
|
26
|
+
export async function loadTimeline(): Promise<TimelineTools> {
|
|
27
|
+
let module: Observability;
|
|
28
|
+
try {
|
|
29
|
+
module = await importer();
|
|
30
|
+
} catch (cause) {
|
|
31
|
+
throw new EvalError(
|
|
32
|
+
`timeline projection requires the optional peer ${TIMELINE_PACKAGE}; install it to score timelines`,
|
|
33
|
+
"ERR_PRISM_EVAL_TIMELINE_UNAVAILABLE",
|
|
34
|
+
{ cause },
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return { createTimelineFolder: module.createTimelineFolder, projectTraceTimeline: module.projectTraceTimeline };
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Agent } from "@arnilo/prism";
|
|
2
|
+
import { EvalError } from "./errors.js";
|
|
3
|
+
import { HARD_JUDGE_MAX_INPUT_BYTES } from "./limits.js";
|
|
4
|
+
|
|
5
|
+
/** @internal One attempt; the host retains ownership of the agent. */
|
|
6
|
+
export async function runToollessSession(agent: Agent, prompt: string, signal: AbortSignal, timeoutMs: number): Promise<string> {
|
|
7
|
+
signal.throwIfAborted();
|
|
8
|
+
const session = await agent.session();
|
|
9
|
+
try {
|
|
10
|
+
signal.throwIfAborted();
|
|
11
|
+
const result = await session.run(prompt, {
|
|
12
|
+
signal,
|
|
13
|
+
tools: { only: [] },
|
|
14
|
+
limits: {
|
|
15
|
+
maxTurns: 1,
|
|
16
|
+
maxProviderAttempts: 1,
|
|
17
|
+
maxToolCalls: 1,
|
|
18
|
+
maxToolRounds: 1,
|
|
19
|
+
maxContinuations: 0,
|
|
20
|
+
maxWallTimeMs: timeoutMs,
|
|
21
|
+
maxInputTokens: HARD_JUDGE_MAX_INPUT_BYTES,
|
|
22
|
+
maxOutputTokens: 4096,
|
|
23
|
+
maxTotalTokens: HARD_JUDGE_MAX_INPUT_BYTES + 4096,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (result.status !== "completed") {
|
|
27
|
+
throw new EvalError("judge run did not complete", "ERR_PRISM_EVAL_JUDGE_OUTPUT");
|
|
28
|
+
}
|
|
29
|
+
return result.text;
|
|
30
|
+
} finally {
|
|
31
|
+
await session.close();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { AgentEventRecord, ProductionPersistenceStore, RunRecord, ToolCallRecord, UsageRecord } from "@arnilo/prism";
|
|
2
|
+
import { resolveRedactor } from "@arnilo/prism";
|
|
3
|
+
import { EvalError } from "./errors.js";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_TRACE_MAX_BYTES,
|
|
6
|
+
DEFAULT_TRACE_PAGE_SIZE,
|
|
7
|
+
DEFAULT_TRACE_PAGES,
|
|
8
|
+
HARD_TRACE_MAX_BYTES,
|
|
9
|
+
HARD_TRACE_PAGE_SIZE,
|
|
10
|
+
HARD_TRACE_PAGES,
|
|
11
|
+
} from "./limits.js";
|
|
12
|
+
import type { EvaluationTrace, TraceResolver, TraceResolverInput } from "./types.js";
|
|
13
|
+
import { exactOwnershipMatches } from "./util.js";
|
|
14
|
+
|
|
15
|
+
/** Shared integer-limit selector with the trace hard ceilings. */
|
|
16
|
+
export function limit(value: number | undefined, fallback: number, hard: number, name: string): number {
|
|
17
|
+
const selected = value ?? fallback;
|
|
18
|
+
if (!Number.isInteger(selected) || selected < 1 || selected > hard) {
|
|
19
|
+
throw new EvalError(`${name} must be an integer in [1, ${hard}]`, "ERR_PRISM_EVAL_TRACE_BOUNDS");
|
|
20
|
+
}
|
|
21
|
+
return selected;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Shared bounded cursor pagination used by trace resolution and curation scans. */
|
|
25
|
+
export async function pages<T>(
|
|
26
|
+
query: (cursor?: string) => Promise<{ readonly items: readonly T[]; readonly nextCursor?: string }>,
|
|
27
|
+
maxPages: number,
|
|
28
|
+
): Promise<T[]> {
|
|
29
|
+
const output: T[] = [];
|
|
30
|
+
let cursor: string | undefined;
|
|
31
|
+
const seen = new Set<string>();
|
|
32
|
+
for (let page = 0; page < maxPages; page += 1) {
|
|
33
|
+
const result = await query(cursor);
|
|
34
|
+
output.push(...result.items);
|
|
35
|
+
if (!result.nextCursor) return output;
|
|
36
|
+
if (seen.has(result.nextCursor)) throw new EvalError("trace cursor repeated", "ERR_PRISM_EVAL_TRACE_CURSOR");
|
|
37
|
+
seen.add(result.nextCursor);
|
|
38
|
+
cursor = result.nextCursor;
|
|
39
|
+
}
|
|
40
|
+
throw new EvalError("trace page limit exceeded", "ERR_PRISM_EVAL_TRACE_BOUNDS");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Resolve one owner/session/run-scoped, redacted, bounded persistence trace. */
|
|
44
|
+
export function createPersistenceTraceResolver(store: ProductionPersistenceStore): TraceResolver {
|
|
45
|
+
return async (input: TraceResolverInput): Promise<EvaluationTrace> => {
|
|
46
|
+
input.signal?.throwIfAborted();
|
|
47
|
+
const pageSize = limit(input.limits?.pageSize, DEFAULT_TRACE_PAGE_SIZE, HARD_TRACE_PAGE_SIZE, "pageSize");
|
|
48
|
+
const maxPages = limit(input.limits?.maxPages, DEFAULT_TRACE_PAGES, HARD_TRACE_PAGES, "maxPages");
|
|
49
|
+
const maxBytes = limit(input.limits?.maxBytes, DEFAULT_TRACE_MAX_BYTES, HARD_TRACE_MAX_BYTES, "maxBytes");
|
|
50
|
+
const ownership = { tenantId: input.tenantId, accountId: input.accountId, userId: input.userId };
|
|
51
|
+
const query = { sessionId: input.sessionId, runId: input.runId, order: "asc" as const, limit: pageSize, ...ownership };
|
|
52
|
+
|
|
53
|
+
const [runs, events, toolCalls, usage] = await Promise.all([
|
|
54
|
+
pages<RunRecord>(
|
|
55
|
+
(cursor) => store.queryRuns({ sessionId: input.sessionId, cursor, order: "asc", limit: pageSize, ...ownership }),
|
|
56
|
+
maxPages,
|
|
57
|
+
),
|
|
58
|
+
pages<AgentEventRecord>((cursor) => store.queryEvents({ ...query, cursor }), maxPages),
|
|
59
|
+
pages<ToolCallRecord>((cursor) => store.queryToolCalls({ ...query, cursor }), maxPages),
|
|
60
|
+
pages<UsageRecord>((cursor) => store.queryUsage({ ...query, cursor }), maxPages),
|
|
61
|
+
]);
|
|
62
|
+
const run = runs.find((candidate) => candidate.id === input.runId);
|
|
63
|
+
if (!run) throw new EvalError("evaluation trace run not found", "ERR_PRISM_EVAL_TRACE_NOT_FOUND");
|
|
64
|
+
const all = [run, ...events, ...toolCalls, ...usage];
|
|
65
|
+
if (run.sessionId !== input.sessionId || all.some((record) => !exactOwnershipMatches(ownership, record))) {
|
|
66
|
+
throw new EvalError("evaluation trace ownership mismatch", "ERR_PRISM_EVAL_TRACE_OWNERSHIP");
|
|
67
|
+
}
|
|
68
|
+
if ([...events, ...toolCalls, ...usage].some((record) => record.sessionId !== input.sessionId || record.runId !== input.runId)) {
|
|
69
|
+
throw new EvalError("evaluation trace identity mismatch", "ERR_PRISM_EVAL_TRACE_IDENTITY");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const redactor = resolveRedactor(input.redactor, input.secrets);
|
|
73
|
+
const trace = redactor ? redactor.redact({ run, events, toolCalls, usage }) : { run, events, toolCalls, usage };
|
|
74
|
+
if (Buffer.byteLength(JSON.stringify(trace)) > maxBytes) {
|
|
75
|
+
throw new EvalError("evaluation trace byte limit exceeded", "ERR_PRISM_EVAL_TRACE_BOUNDS");
|
|
76
|
+
}
|
|
77
|
+
input.signal?.throwIfAborted();
|
|
78
|
+
return trace;
|
|
79
|
+
};
|
|
80
|
+
}
|