@arnilo/prism-hosts 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/a2a/README.md +195 -0
  3. package/a2a/src/card.ts +208 -0
  4. package/a2a/src/codec.ts +523 -0
  5. package/a2a/src/connect.ts +415 -0
  6. package/a2a/src/errors.ts +87 -0
  7. package/a2a/src/index.ts +40 -0
  8. package/a2a/src/limits.ts +43 -0
  9. package/a2a/src/pending.ts +28 -0
  10. package/a2a/src/proxy.ts +526 -0
  11. package/a2a/src/serve.ts +886 -0
  12. package/acp/README.md +3 -1
  13. package/acp/src/limits.ts +3 -16
  14. package/acp/src/mapper.ts +26 -5
  15. package/acp/src/serve.ts +6 -5
  16. package/ag-ui/README.md +2 -1
  17. package/ag-ui/src/a2ui.ts +8 -31
  18. package/ag-ui/src/ag-ui-mapper.ts +27 -1
  19. package/ag-ui/src/encrypted-value.ts +3 -3
  20. package/ag-ui/src/handler.ts +4 -4
  21. package/ag-ui/src/index.ts +0 -33
  22. package/ag-ui/src/limits.ts +5 -88
  23. package/ag-ui/src/projectors.ts +8 -6
  24. package/ag-ui/src/renderer/bind.ts +2 -1
  25. package/channels/README.md +61 -5
  26. package/channels/src/discord-gateway.ts +354 -0
  27. package/channels/src/discord.ts +873 -0
  28. package/channels/src/index.ts +4 -2
  29. package/channels/src/limits.ts +3 -19
  30. package/channels/src/pairing.ts +1 -2
  31. package/channels/src/runtime-turn.ts +10 -2
  32. package/channels/src/signal.ts +11 -19
  33. package/channels/src/slack.ts +854 -0
  34. package/channels/src/telegram.ts +22 -44
  35. package/channels/src/types.ts +5 -2
  36. package/devtools/README.md +1 -1
  37. package/driver-process/src/driver.ts +3 -1
  38. package/driver-process/src/testing.ts +1 -1
  39. package/driver-process/src/turn.ts +5 -1
  40. package/evals/README.md +11 -7
  41. package/evals/src/calibration.ts +5 -13
  42. package/evals/src/compare-experiments.ts +1 -2
  43. package/evals/src/comparison.ts +7 -25
  44. package/evals/src/curate.ts +3 -9
  45. package/evals/src/dataset.ts +0 -2
  46. package/evals/src/index.ts +3 -20
  47. package/evals/src/injection.ts +33 -6
  48. package/evals/src/judge.ts +9 -13
  49. package/evals/src/limits.ts +0 -17
  50. package/evals/src/rubric-judge.ts +5 -10
  51. package/evals/src/scenario-runner.ts +8 -4
  52. package/evals/src/scenarios.ts +5 -5
  53. package/evals/src/score.ts +3 -5
  54. package/evals/src/stats.ts +0 -2
  55. package/evals/src/threshold.ts +3 -3
  56. package/evals/src/toolless-session.ts +7 -3
  57. package/evals/src/trace.ts +8 -14
  58. package/evals/src/trajectory.ts +45 -11
  59. package/evals/src/types.ts +2 -2
  60. package/evals/src/user-simulator.ts +1 -7
  61. package/evals/src/util.ts +3 -9
  62. package/headless/README.md +20 -1
  63. package/headless/src/authority.ts +14 -1
  64. package/headless/src/errors.ts +3 -1
  65. package/headless/src/index.ts +10 -1
  66. package/headless/src/limits.ts +2 -2
  67. package/headless/src/pending.ts +4 -3
  68. package/headless/src/recover.ts +126 -0
  69. package/headless/src/resume.ts +1 -1
  70. package/host-builder/data/api.json +1308 -1367
  71. package/host-builder/data/errors.json +207 -181
  72. package/host-builder/data/examples/a2a-client.ts +125 -0
  73. package/host-builder/data/examples/a2a-server.ts +133 -0
  74. package/host-builder/data/examples/autonomous-coding-loop.ts +1 -1
  75. package/host-builder/data/examples/build-workflow.ts +2 -2
  76. package/host-builder/data/examples/caveman-ponytail.ts +1 -1
  77. package/host-builder/data/examples/channel-discord.ts +176 -0
  78. package/host-builder/data/examples/channel-slack.ts +146 -0
  79. package/host-builder/data/examples/continue-after-failure.ts +80 -0
  80. package/host-builder/data/examples/custom-adapter.ts +1 -1
  81. package/host-builder/data/examples/decision-models.ts +1 -1
  82. package/host-builder/data/examples/define-package.ts +1 -1
  83. package/host-builder/data/examples/delegate.ts +74 -9
  84. package/host-builder/data/examples/durable-loops-and-approvals.ts +11 -10
  85. package/host-builder/data/examples/governance-deny.ts +1 -1
  86. package/host-builder/data/examples/guardrail-content.ts +126 -0
  87. package/host-builder/data/examples/headless-host.ts +1 -1
  88. package/host-builder/data/examples/long-running-job.ts +129 -0
  89. package/host-builder/data/examples/long-term-memory.ts +1 -1
  90. package/host-builder/data/examples/mcp-oauth.ts +197 -0
  91. package/host-builder/data/examples/mcp-trust.ts +1 -1
  92. package/host-builder/data/examples/memory-and-wiki.ts +3 -3
  93. package/host-builder/data/examples/memory-system.ts +31 -18
  94. package/host-builder/data/examples/model-router-aggregate-budgets.ts +1 -1
  95. package/host-builder/data/examples/parallel-tools.ts +70 -0
  96. package/host-builder/data/examples/remote-agent.ts +1 -1
  97. package/host-builder/data/examples/serve-tools.ts +1 -1
  98. package/host-builder/data/examples/session-memory.ts +29 -26
  99. package/host-builder/data/examples/side-call.ts +9 -5
  100. package/host-builder/data/examples/sqlite-resume.ts +1 -1
  101. package/host-builder/data/examples/structured-output.ts +57 -0
  102. package/host-builder/data/examples.json +15 -5
  103. package/host-builder/skills/prism-host-builder/SKILL.md +1 -1
  104. package/host-builder/skills/prism-host-builder/references/choosing.md +14 -10
  105. package/host-builder/skills/prism-host-builder/references/pitfalls.md +5 -3
  106. package/host-builder/skills/prism-host-builder/references/recipes.md +5 -5
  107. package/host-builder/skills/prism-host-builder/references/verification.md +1 -1
  108. package/host-builder/src/check/runner.ts +2 -3
  109. package/host-builder/src/server.ts +2 -2
  110. package/mcp-server/README.md +3 -3
  111. package/mcp-server/src/bounds.ts +3 -3
  112. package/mcp-server/src/serve-tools.ts +2 -9
  113. package/mcp-server/src/serve.ts +2 -4
  114. package/mcp-server/src/server.ts +10 -20
  115. package/package.json +12 -6
  116. package/remote/README.md +7 -4
  117. package/remote/src/channel.ts +6 -2
  118. package/remote/src/connect.ts +9 -3
  119. package/remote/src/errors.ts +3 -1
  120. package/remote/src/limits.ts +3 -13
  121. package/remote/src/mirror.ts +2 -1
  122. package/remote/src/pending.ts +4 -3
  123. package/remote/src/protocol.ts +3 -0
  124. package/remote/src/serve.ts +43 -5
  125. package/remote/src/session-proxy.ts +28 -5
  126. package/remote/src/testing.ts +3 -1
  127. package/remote/src/wire.ts +74 -14
@@ -2,7 +2,6 @@
2
2
  export const DEFAULT_EXPERIMENT_CONCURRENCY = 1;
3
3
 
4
4
  /** Hard ceiling for experiment concurrency. */
5
- export const HARD_EXPERIMENT_CONCURRENCY_CAP = 32;
6
5
 
7
6
  /** Default sample rate (always score). */
8
7
  export const DEFAULT_SAMPLE_RATE = 1;
@@ -11,40 +10,24 @@ export const DEFAULT_SAMPLE_RATE = 1;
11
10
  export const DEFAULT_EVALUATION_PAGE_SIZE = 100;
12
11
 
13
12
  /** Hard ceiling for evaluation store page size. */
14
- export const HARD_EVALUATION_PAGE_CAP = 1000;
15
13
 
16
14
  export const DEFAULT_TRACE_PAGE_SIZE = 100;
17
- export const HARD_TRACE_PAGE_SIZE = 1000;
18
15
  export const DEFAULT_TRACE_PAGES = 20;
19
- export const HARD_TRACE_PAGES = 100;
20
16
  export const DEFAULT_TRACE_MAX_BYTES = 4 * 1024 * 1024;
21
- export const HARD_TRACE_MAX_BYTES = 32 * 1024 * 1024;
22
17
  export const DEFAULT_JUDGE_TIMEOUT_MS = 30_000;
23
- export const HARD_JUDGE_TIMEOUT_MS = 300_000;
24
18
  export const DEFAULT_JUDGE_MAX_ATTEMPTS = 1;
25
19
  export const DEFAULT_RUBRIC_JUDGE_MAX_ATTEMPTS = 2;
26
- export const HARD_JUDGE_MAX_ATTEMPTS = 3;
27
20
  export const DEFAULT_JUDGE_MAX_OUTPUT_BYTES = 16 * 1024;
28
- export const HARD_JUDGE_MAX_OUTPUT_BYTES = 64 * 1024;
29
21
  export const DEFAULT_COMPARISON_CANDIDATES = 8;
30
- export const HARD_COMPARISON_CANDIDATES = 32;
31
22
  export const DEFAULT_REPORT_MAX_BYTES = 4 * 1024 * 1024;
32
- export const HARD_REPORT_MAX_BYTES = 32 * 1024 * 1024;
33
- export const HARD_DATASET_ITEMS = 10_000;
34
23
  /** Frozen ceiling for one curated dataset item (datasetFromRuns); not configurable. */
35
24
  export const HARD_CURATION_ITEM_MAX_BYTES = 4 * 1024 * 1024;
36
25
 
37
26
  export const DEFAULT_CANDIDATE_MAX_BYTES = 1024 * 1024;
38
- export const HARD_CANDIDATE_MAX_BYTES = 8 * 1024 * 1024;
39
27
  export const DEFAULT_JUDGE_MAX_INPUT_BYTES = 1024 * 1024;
40
- export const HARD_JUDGE_MAX_INPUT_BYTES = 8 * 1024 * 1024;
41
28
  export const DEFAULT_JUDGE_MAX_RUBRIC_BYTES = 16 * 1024;
42
- export const HARD_JUDGE_MAX_RUBRIC_BYTES = 64 * 1024;
43
29
 
44
30
  export const DEFAULT_MAX_STEP_SCORES = 32;
45
- export const HARD_MAX_STEP_SCORES = 128;
46
31
  export const DEFAULT_TRIALS_COUNT = 1;
47
- export const HARD_MAX_TRIALS = 16;
48
32
 
49
33
  /** Hard ceiling for bootstrap and Monte Carlo permutation resamples. */
50
- export const HARD_STATS_RESAMPLES = 100_000;
@@ -7,14 +7,9 @@ import { canonicalJson } from "./util.js";
7
7
  import {
8
8
  DEFAULT_RUBRIC_JUDGE_MAX_ATTEMPTS,
9
9
  DEFAULT_JUDGE_TIMEOUT_MS,
10
- HARD_JUDGE_TIMEOUT_MS,
11
10
  DEFAULT_JUDGE_MAX_INPUT_BYTES,
12
- HARD_JUDGE_MAX_INPUT_BYTES,
13
11
  DEFAULT_JUDGE_MAX_OUTPUT_BYTES,
14
- HARD_JUDGE_MAX_OUTPUT_BYTES,
15
12
  DEFAULT_JUDGE_MAX_RUBRIC_BYTES,
16
- HARD_JUDGE_MAX_RUBRIC_BYTES,
17
- HARD_JUDGE_MAX_ATTEMPTS,
18
13
  } from "./limits.js";
19
14
  import type { RubricJudgeOptions, Scorer, JudgeRubric, PairwiseJudgeOptions, PairwiseScorer } from "./types.js";
20
15
 
@@ -95,11 +90,11 @@ function createJudgeRunner<TRubric extends Pick<JudgeRubric, "id" | "version" |
95
90
  ) {
96
91
  throw new EvalError("invalid judge rubric or id", "ERR_PRISM_EVAL_JUDGE");
97
92
  }
98
- const timeoutMs = bounded(options.timeoutMs, DEFAULT_JUDGE_TIMEOUT_MS, HARD_JUDGE_TIMEOUT_MS, "timeoutMs");
99
- const maxAttempts = bounded(options.maxAttempts, DEFAULT_RUBRIC_JUDGE_MAX_ATTEMPTS, HARD_JUDGE_MAX_ATTEMPTS, "maxAttempts");
100
- const maxInputBytes = bounded(options.maxInputBytes, DEFAULT_JUDGE_MAX_INPUT_BYTES, HARD_JUDGE_MAX_INPUT_BYTES, "maxInputBytes");
101
- const maxOutputBytes = bounded(options.maxOutputBytes, DEFAULT_JUDGE_MAX_OUTPUT_BYTES, HARD_JUDGE_MAX_OUTPUT_BYTES, "maxOutputBytes");
102
- const maxRubricBytes = bounded(options.maxRubricBytes, DEFAULT_JUDGE_MAX_RUBRIC_BYTES, HARD_JUDGE_MAX_RUBRIC_BYTES, "maxRubricBytes");
93
+ const timeoutMs = bounded(options.timeoutMs, DEFAULT_JUDGE_TIMEOUT_MS, "timeoutMs");
94
+ const maxAttempts = bounded(options.maxAttempts, DEFAULT_RUBRIC_JUDGE_MAX_ATTEMPTS, "maxAttempts");
95
+ const maxInputBytes = bounded(options.maxInputBytes, DEFAULT_JUDGE_MAX_INPUT_BYTES, "maxInputBytes");
96
+ const maxOutputBytes = bounded(options.maxOutputBytes, DEFAULT_JUDGE_MAX_OUTPUT_BYTES, "maxOutputBytes");
97
+ const maxRubricBytes = bounded(options.maxRubricBytes, DEFAULT_JUDGE_MAX_RUBRIC_BYTES, "maxRubricBytes");
103
98
  // Share the canonical JSON rules used by dataset hashes.
104
99
  const canonical = canonicalJson({
105
100
  id: rubric.id,
@@ -26,6 +26,9 @@ import type {
26
26
  import { requireSimulator, nextSimulatedUser } from "./user-simulator.js";
27
27
  import { toErrorInfo } from "./util.js";
28
28
 
29
+ const DEFAULT_SIMULATED_USER_MAX_TURNS = 8;
30
+ const DEFAULT_SIMULATED_RUN_MAX_TURNS = 32;
31
+
29
32
  // ─── Multi-Turn Scenarios (R-E12) ─────────────────────────────────────────────
30
33
 
31
34
  export interface ScenarioTurn {
@@ -74,7 +77,6 @@ export interface ScenarioResult {
74
77
  }
75
78
 
76
79
  export const DEFAULT_MAX_SCENARIO_TURNS = 8;
77
- export const HARD_MAX_SCENARIO_TURNS = 32;
78
80
 
79
81
  /** Collect session events until `work` settles, then close the subscriber. No timeout drain. */
80
82
  export async function collectWhileRunning<T>(
@@ -263,8 +265,8 @@ export function validateScenario(options: {
263
265
  }
264
266
  const requestedMax = options.maxTurns ?? DEFAULT_MAX_SCENARIO_TURNS;
265
267
  // Bound violations are configuration errors: a silently truncated scenario passes for the wrong reason.
266
- if (!Number.isInteger(requestedMax) || requestedMax < 1 || requestedMax > HARD_MAX_SCENARIO_TURNS) {
267
- throw new EvalError(`maxTurns must be an integer in [1, ${HARD_MAX_SCENARIO_TURNS}]`, "ERR_PRISM_EVAL_SCENARIO_BOUNDS");
268
+ if (!Number.isInteger(requestedMax) || requestedMax < 1) {
269
+ throw new EvalError("maxTurns must be a positive integer", "ERR_PRISM_EVAL_SCENARIO_BOUNDS");
268
270
  }
269
271
  if (options.turns && options.turns.length > requestedMax) {
270
272
  throw new EvalError(`scenario has ${options.turns!.length} turns but maxTurns is ${requestedMax}`, "ERR_PRISM_EVAL_SCENARIO_BOUNDS");
@@ -289,7 +291,9 @@ export async function executeScenario(
289
291
  stopReason,
290
292
  simulatorModel: user!.simulatorModel,
291
293
  });
292
- const maxTurns = user ? Math.min(user.maxTurns ?? 8, options.maxTurns ?? 32) : options.turns!.length;
294
+ const maxTurns = user
295
+ ? Math.min(user.maxTurns ?? DEFAULT_SIMULATED_USER_MAX_TURNS, options.maxTurns ?? DEFAULT_SIMULATED_RUN_MAX_TURNS)
296
+ : options.turns!.length;
293
297
  for (let turnIndex = 0; turnIndex < maxTurns; turnIndex++) {
294
298
  const turn = user ? await nextSimulatedUser(user, turns, redactor, options.signal) : options.turns![turnIndex]!;
295
299
  if (user && turn === user.stop) return simulation("goal_reached");
@@ -1,6 +1,6 @@
1
1
  import { EvalError } from "./errors.js";
2
+ import { DEFAULT_TRIALS_COUNT } from "./limits.js";
2
3
  import { type FailureInjectionOptions, failingStore, failureInjection } from "./failure-injection.js";
3
- import { HARD_MAX_TRIALS } from "./limits.js";
4
4
  import type { ExperimentReport, EvalManifest, ExperimentTrials } from "./types.js";
5
5
 
6
6
  export { type FailureInjectionOptions, failingStore, failureInjection };
@@ -51,7 +51,7 @@ export function validateReleaseEvalManifest(manifest: EvalManifest, report?: Exp
51
51
  }
52
52
 
53
53
  export type { AgentFactory, ScenarioDefinition, ScenarioTurn, RunScenarioOptions, ScenarioResult } from "./scenario-runner.js";
54
- export { runScenario, collectWhileRunning, DEFAULT_MAX_SCENARIO_TURNS, HARD_MAX_SCENARIO_TURNS } from "./scenario-runner.js";
54
+ export { runScenario, collectWhileRunning, DEFAULT_MAX_SCENARIO_TURNS } from "./scenario-runner.js";
55
55
 
56
56
  // ─── Trials Resolution (R-E12) ────────────────────────────────────────────────
57
57
 
@@ -67,9 +67,9 @@ export function mulberry32(seed: number): () => number {
67
67
  }
68
68
 
69
69
  export function resolveTrialsConfig(trials?: number, seed?: number): Omit<ExperimentTrials, "sampleCount"> {
70
- const count = trials ?? 1;
71
- if (!Number.isInteger(count) || count < 1 || count > HARD_MAX_TRIALS) {
72
- throw new EvalError(`trials must be an integer in [1, ${HARD_MAX_TRIALS}]`, "ERR_PRISM_EVAL_TRIALS");
70
+ const count = trials ?? DEFAULT_TRIALS_COUNT;
71
+ if (!Number.isInteger(count) || count < 1) {
72
+ throw new EvalError("trials must be a positive integer", "ERR_PRISM_EVAL_TRIALS");
73
73
  }
74
74
  if (seed !== undefined && !Number.isInteger(seed)) {
75
75
  throw new EvalError("seed must be an integer", "ERR_PRISM_EVAL_TRIALS");
@@ -1,7 +1,7 @@
1
1
  import type { EvaluationRecord } from "@arnilo/prism";
2
2
  import { type Message, type RunResult, resolveRedactor } from "@arnilo/prism";
3
3
  import { EvalError, EvalScoreError } from "./errors.js";
4
- import { DEFAULT_MAX_STEP_SCORES, DEFAULT_SAMPLE_RATE, HARD_MAX_STEP_SCORES } from "./limits.js";
4
+ import { DEFAULT_MAX_STEP_SCORES, DEFAULT_SAMPLE_RATE } from "./limits.js";
5
5
  import { mulberry32 } from "./scenarios.js";
6
6
  import { loadTimeline } from "./timeline.js";
7
7
  import type {
@@ -210,12 +210,10 @@ export async function scoreRun<TInput = unknown, TExpected = unknown>(
210
210
  return false;
211
211
  });
212
212
 
213
- const cap = Math.min(
213
+ const cap =
214
214
  options.maxStepScores !== undefined && Number.isInteger(options.maxStepScores) && options.maxStepScores > 0
215
215
  ? options.maxStepScores
216
- : DEFAULT_MAX_STEP_SCORES,
217
- HARD_MAX_STEP_SCORES,
218
- );
216
+ : DEFAULT_MAX_STEP_SCORES;
219
217
  const stepsToScore = matchingSteps.slice(0, cap);
220
218
 
221
219
  if (!stepsToScore.length) {
@@ -1,6 +1,5 @@
1
1
  import type { EvaluationRecord } from "@arnilo/prism";
2
2
  import { EvalError } from "./errors.js";
3
- import { HARD_STATS_RESAMPLES } from "./limits.js";
4
3
  import { mulberry32 } from "./scenarios.js";
5
4
  import type { EstimateOnlineOptions, OnlineEstimate } from "./types.js";
6
5
 
@@ -114,7 +113,6 @@ function probability(value: number): void {
114
113
 
115
114
  function resampling(resamples: number, seed: number): () => number {
116
115
  integer(resamples, 1);
117
- check(resamples <= HARD_STATS_RESAMPLES, `resamples must not exceed ${HARD_STATS_RESAMPLES}`);
118
116
  check(Number.isSafeInteger(seed), "seed must be a safe integer");
119
117
  return mulberry32(seed);
120
118
  }
@@ -1,7 +1,7 @@
1
1
  import { resolveRedactor } from "@arnilo/prism";
2
2
  import { compareExperiments } from "./compare-experiments.js";
3
3
  import { EvalError } from "./errors.js";
4
- import { DEFAULT_REPORT_MAX_BYTES, HARD_REPORT_MAX_BYTES } from "./limits.js";
4
+ import { DEFAULT_REPORT_MAX_BYTES } from "./limits.js";
5
5
  import type { ComparisonReport, EvaluationThresholds, ExperimentReport } from "./types.js";
6
6
  import { assertFiniteUnitInterval } from "./util.js";
7
7
 
@@ -107,8 +107,8 @@ export function serializeEvaluationReport(
107
107
  } = {},
108
108
  ): string {
109
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");
110
+ if (!Number.isInteger(maxBytes) || maxBytes < 1) {
111
+ throw new EvalError("maxBytes must be a positive integer", "ERR_PRISM_EVAL_REPORT_BOUNDS");
112
112
  }
113
113
  const redactor = resolveRedactor(options.redactor, options.secrets);
114
114
  const json = JSON.stringify(redactor ? redactor.redact(report) : report, null, 2);
@@ -1,10 +1,14 @@
1
1
  import type { Agent } from "@arnilo/prism";
2
2
  import { EvalError } from "./errors.js";
3
- import { HARD_JUDGE_MAX_INPUT_BYTES } from "./limits.js";
3
+
4
+ /** Input tokens allowed beyond the prompt itself, for the agent's system prompt. */
5
+ const SYSTEM_PROMPT_TOKEN_ALLOWANCE = 4096;
4
6
 
5
7
  /** @internal One attempt; the host retains ownership of the agent. */
6
8
  export async function runToollessSession(agent: Agent, prompt: string, signal: AbortSignal, timeoutMs: number): Promise<string> {
7
9
  signal.throwIfAborted();
10
+ // The caller bounded the prompt by its host-set `maxInputBytes`; a token is at least one byte, plus room for the system prompt.
11
+ const inputTokens = Buffer.byteLength(prompt, "utf8") + SYSTEM_PROMPT_TOKEN_ALLOWANCE;
8
12
  const session = await agent.session();
9
13
  try {
10
14
  signal.throwIfAborted();
@@ -18,9 +22,9 @@ export async function runToollessSession(agent: Agent, prompt: string, signal: A
18
22
  maxToolRounds: 1,
19
23
  maxContinuations: 0,
20
24
  maxWallTimeMs: timeoutMs,
21
- maxInputTokens: HARD_JUDGE_MAX_INPUT_BYTES,
25
+ maxInputTokens: inputTokens,
22
26
  maxOutputTokens: 4096,
23
- maxTotalTokens: HARD_JUDGE_MAX_INPUT_BYTES + 4096,
27
+ maxTotalTokens: inputTokens + 4096,
24
28
  },
25
29
  });
26
30
  if (result.status !== "completed") {
@@ -1,22 +1,16 @@
1
1
  import type { AgentEventRecord, ProductionPersistenceStore, RunRecord, ToolCallRecord, UsageRecord } from "@arnilo/prism";
2
2
  import { resolveRedactor } from "@arnilo/prism";
3
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";
4
+ import { DEFAULT_TRACE_MAX_BYTES, DEFAULT_TRACE_PAGE_SIZE, DEFAULT_TRACE_PAGES } from "./limits.js";
12
5
  import type { EvaluationTrace, TraceResolver, TraceResolverInput } from "./types.js";
13
6
  import { exactOwnershipMatches } from "./util.js";
14
7
 
15
8
  /** Shared integer-limit selector with the trace hard ceilings. */
16
- export function limit(value: number | undefined, fallback: number, hard: number, name: string): number {
9
+ /** A host-set trace limit: a positive integer. The host's value is the cap (plan 239 Task 5). */
10
+ export function limit(value: number | undefined, fallback: number, name: string): number {
17
11
  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");
12
+ if (!Number.isInteger(selected) || selected < 1) {
13
+ throw new EvalError(`${name} must be a positive integer`, "ERR_PRISM_EVAL_TRACE_BOUNDS");
20
14
  }
21
15
  return selected;
22
16
  }
@@ -44,9 +38,9 @@ export async function pages<T>(
44
38
  export function createPersistenceTraceResolver(store: ProductionPersistenceStore): TraceResolver {
45
39
  return async (input: TraceResolverInput): Promise<EvaluationTrace> => {
46
40
  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");
41
+ const pageSize = limit(input.limits?.pageSize, DEFAULT_TRACE_PAGE_SIZE, "pageSize");
42
+ const maxPages = limit(input.limits?.maxPages, DEFAULT_TRACE_PAGES, "maxPages");
43
+ const maxBytes = limit(input.limits?.maxBytes, DEFAULT_TRACE_MAX_BYTES, "maxBytes");
50
44
  const ownership = { tenantId: input.tenantId, accountId: input.accountId, userId: input.userId };
51
45
  const query = { sessionId: input.sessionId, runId: input.runId, order: "asc" as const, limit: pageSize, ...ownership };
52
46
 
@@ -2,10 +2,7 @@ import { type JsonSchema, type ToolCapabilityKind, type ToolInfo, validateJsonSc
2
2
  import { EvalError } from "./errors.js";
3
3
  import type { ExecutionStep, ExecutionTimeline, ScoreResult, Scorer, ScorerInput } from "./types.js";
4
4
 
5
- // ─── Caps & Limits ────────────────────────────────────────────────────────────
6
-
7
- export const DEFAULT_MAX_EXPECTED_CALLS = 64;
8
- export const HARD_MAX_EXPECTED_CALLS = 256;
5
+ const DEFAULT_MAX_REPEATED_TOOL_CALLS = 2;
9
6
 
10
7
  // ─── ToolCallSpec & Helpers ───────────────────────────────────────────────────
11
8
 
@@ -54,12 +51,6 @@ export function createToolCallMatchScorer<TInput = unknown, TExpected = unknown>
54
51
  const mode = options.mode;
55
52
  const isInvariant = options.invariant ?? (options.deny !== undefined && options.deny.length > 0);
56
53
  const rawExpected = options.expected ?? [];
57
- if (rawExpected.length > HARD_MAX_EXPECTED_CALLS) {
58
- throw new EvalError(
59
- `expected tool calls count (${rawExpected.length}) exceeds hard limit (${HARD_MAX_EXPECTED_CALLS})`,
60
- "ERR_PRISM_EVAL_TRAJECTORY_BOUNDS",
61
- );
62
- }
63
54
  const expectedSpecs = rawExpected.map(normalizeSpec);
64
55
  const denySpecs = (options.deny ?? []).map(normalizeSpec);
65
56
 
@@ -277,7 +268,7 @@ export interface NoLoopScorerOptions {
277
268
  * Detects degenerate loops where an agent calls the exact same tool with identical arguments repeatedly.
278
269
  */
279
270
  export function createNoLoopScorer<TInput = unknown, TExpected = unknown>(options: NoLoopScorerOptions = {}): Scorer<TInput, TExpected> {
280
- const threshold = options.maxRepeatedToolCalls ?? 2;
271
+ const threshold = options.maxRepeatedToolCalls ?? DEFAULT_MAX_REPEATED_TOOL_CALLS;
281
272
 
282
273
  return {
283
274
  id: options.id ?? "no_loop",
@@ -510,6 +501,49 @@ export function createGuardrailPackScorer<TInput = unknown, TExpected = unknown>
510
501
  };
511
502
  }
512
503
 
504
+ // ─── Guardrail-Flagged Detection Scorer ───────────────────────────────────────
505
+
506
+ export interface GuardrailFlaggedScorerOptions {
507
+ /** Pack id; any rule named `pack:<pack>/…` that fired counts, whatever its action. */
508
+ readonly pack: string;
509
+ /** Scorer id. Default `guardrail_flagged:<pack>`. */
510
+ readonly id?: string;
511
+ }
512
+
513
+ /**
514
+ * Scores 1 when a rule of `pack` fired on the trajectory (any guardrail step named `pack:<pack>/…`,
515
+ * whether it denied, redacted, or only flagged), else 0. A detector measure, not a safety verdict: its
516
+ * pass rate on attacked items is the pack's catch rate and on benign items its false-positive rate.
517
+ * Content rules emit a record only when they fire, so a step's presence is the signal. A judge rule
518
+ * that failed under `onError: "allow"` also emits a record, and the timeline does not project
519
+ * `metadata.outcome`, so this scorer is not exact for packs with judge rules.
520
+ */
521
+ export function createGuardrailFlaggedScorer<TInput = unknown, TExpected = unknown>(
522
+ options: GuardrailFlaggedScorerOptions,
523
+ ): Scorer<TInput, TExpected> {
524
+ if (typeof options?.pack !== "string" || !options.pack.trim() || options.pack.includes("/")) {
525
+ throw new EvalError("guardrail flagged scorer requires a pack id");
526
+ }
527
+ const prefix = `${DEFAULT_PACK_RULE_PREFIX}${options.pack}/`;
528
+ return {
529
+ id: options.id ?? `guardrail_flagged:${options.pack}`,
530
+ description: `1 when a ${options.pack} pack rule fired on the trajectory`,
531
+ requires: ["timeline"],
532
+ invariant: false,
533
+ score(input: ScorerInput<TInput, TExpected>): ScoreResult {
534
+ const timeline: ExecutionTimeline | undefined = input.timeline ?? input.target?.timeline;
535
+ if (!timeline) return { score: 0, reason: "no execution timeline available for guardrail detection scoring" };
536
+ const rules = new Set<string>();
537
+ for (const step of timeline.steps) {
538
+ if (step.kind !== "guardrail") continue;
539
+ const rule = step.metadata?.guardrail;
540
+ if (typeof rule === "string" && rule.startsWith(prefix)) rules.add(rule);
541
+ }
542
+ return rules.size ? { score: 1, metadata: { rules: [...rules].sort() } } : { score: 0 };
543
+ },
544
+ };
545
+ }
546
+
513
547
  // ─── Approval-Before-Effect Scorer (R-E12) ────────────────────────────────────
514
548
 
515
549
  export interface ApprovalBeforeEffectScorerOptions {
@@ -211,7 +211,7 @@ export interface EstimateOnlineOptions {
211
211
  readonly scorerId?: string;
212
212
  /** Bootstrap seed, default 0. */
213
213
  readonly seed?: number;
214
- /** Bootstrap resamples, default 2,000, maximum HARD_STATS_RESAMPLES. */
214
+ /** Bootstrap resamples, default 2,000. */
215
215
  readonly resamples?: number;
216
216
  /** Interval coverage in (0, 1), default 0.95. */
217
217
  readonly confidence?: number;
@@ -360,7 +360,7 @@ export interface CompareExperimentsOptions {
360
360
  readonly scorers?: readonly string[];
361
361
  readonly byTag?: boolean;
362
362
  readonly seed?: number;
363
- /** Bootstrap default 2,000; permutation default 10,000. Maximum HARD_STATS_RESAMPLES. */
363
+ /** Bootstrap default 2,000; permutation default 10,000. */
364
364
  readonly resamples?: number;
365
365
  /** BH-adjusted significance level, default 0.05. Does not change ci95 coverage. */
366
366
  readonly alpha?: number;
@@ -1,11 +1,6 @@
1
1
  import type { Agent, SecretRedactor } from "@arnilo/prism";
2
2
  import { EvalError } from "./errors.js";
3
- import {
4
- DEFAULT_JUDGE_TIMEOUT_MS,
5
- HARD_JUDGE_TIMEOUT_MS,
6
- DEFAULT_JUDGE_MAX_INPUT_BYTES,
7
- DEFAULT_JUDGE_MAX_OUTPUT_BYTES,
8
- } from "./limits.js";
3
+ import { DEFAULT_JUDGE_TIMEOUT_MS, DEFAULT_JUDGE_MAX_INPUT_BYTES, DEFAULT_JUDGE_MAX_OUTPUT_BYTES } from "./limits.js";
9
4
  import { runToollessSession } from "./toolless-session.js";
10
5
  import type { UserSimulatorSpec, UserSimulator, UserSimulation } from "./types.js";
11
6
 
@@ -50,7 +45,6 @@ export function createUserSimulator(options: UserSimulatorSpec & { readonly agen
50
45
  maxTurns > 32 ||
51
46
  !Number.isInteger(timeoutMs) ||
52
47
  timeoutMs < 1 ||
53
- timeoutMs > HARD_JUDGE_TIMEOUT_MS ||
54
48
  !model?.provider?.trim() ||
55
49
  !model.model?.trim()
56
50
  )
package/evals/src/util.ts CHANGED
@@ -2,13 +2,7 @@ import type { EvaluationRecord, EvaluationStatus } from "@arnilo/prism";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { errorToErrorInfo, type OwnershipScope, type RunResult, redactSecrets, resolveRedactor, type SecretRedactor } from "@arnilo/prism";
4
4
  import { EvalError } from "./errors.js";
5
- import {
6
- DEFAULT_EVALUATION_PAGE_SIZE,
7
- DEFAULT_EXPERIMENT_CONCURRENCY,
8
- DEFAULT_SAMPLE_RATE,
9
- HARD_EVALUATION_PAGE_CAP,
10
- HARD_EXPERIMENT_CONCURRENCY_CAP,
11
- } from "./limits.js";
5
+ import { DEFAULT_EVALUATION_PAGE_SIZE, DEFAULT_EXPERIMENT_CONCURRENCY, DEFAULT_SAMPLE_RATE } from "./limits.js";
12
6
  import type { EvaluationSampling, EvaluationSamplingMetadata, ScoreResult } from "./types.js";
13
7
 
14
8
  export function randomId(prefix: string): string {
@@ -63,7 +57,7 @@ export function normalizeConcurrency(concurrency: number | undefined): number {
63
57
  if (!Number.isInteger(value) || value < 1) {
64
58
  throw new EvalError("concurrency must be an integer >= 1", "ERR_PRISM_EVAL_BOUNDS");
65
59
  }
66
- return Math.min(value, HARD_EXPERIMENT_CONCURRENCY_CAP);
60
+ return value;
67
61
  }
68
62
 
69
63
  export function normalizePageLimit(limit: number | undefined): number {
@@ -71,7 +65,7 @@ export function normalizePageLimit(limit: number | undefined): number {
71
65
  if (!Number.isInteger(value) || value < 1) {
72
66
  throw new EvalError("limit must be an integer >= 1", "ERR_PRISM_EVAL_BOUNDS");
73
67
  }
74
- return Math.min(value, HARD_EVALUATION_PAGE_CAP);
68
+ return value;
75
69
  }
76
70
 
77
71
  export function validateScoreResult(result: ScoreResult): ScoreResult {
@@ -97,9 +97,28 @@ With no pending suspension the result is `{ status: "already_resolved" }`. Once
97
97
 
98
98
  After restart, recreate the agent, authority, and router over the same durable store and call the same method. The authority keeps only an in-process guard, adds no model calls or durable writes, and reads the session index/branch before resume; optional answer logging retains its per-attempt checkpoint-write cost. Use one authority per agent across every resume entry point. Direct `session.resume`, independent authorities, and separate processes bypass that guard and are not coordinated. Channel bindings and scheduling are separate capabilities.
99
99
 
100
+ ## Recovering interrupted runs
101
+
102
+ A run whose process died leaves its run-ledger record at `status: "running"` with no `finishedAt`. At startup, list those runs and continue them:
103
+
104
+ ```ts
105
+ import { continueInterrupted, findInterruptedRuns } from "@arnilo/prism-hosts/headless";
106
+ import { createSqlitePersistence } from "@arnilo/prism-extensions/store-sqlite";
107
+
108
+ const persistence = createSqlitePersistence({ filename }); // also the agent's `runLedger`
109
+ const runs = await findInterruptedRuns(persistence, { ownership: agent.config.ownership ?? {}, olderThanMs: 60_000 });
110
+ const outcomes = await continueInterrupted(agent, runs, { concurrency: 2 });
111
+ ```
112
+
113
+ `findInterruptedRuns` takes anything with `queryRuns` (a `ProductionPersistenceStore`); a `RunLedger` alone is write-only and fails with `ledger_query_unsupported`. It pages `queryRuns({ status: "running", ...ownership })`, then checks every row again: a row outside the exact ownership scope, a finished row, or one that started less than `olderThanMs` ago (default 60 000) is dropped. Age is measured from `startedAt`, because `RunRecord` has no last-activity field and not every store applies `toStartedAt`. Pick an `olderThanMs` longer than your longest run when another process might still be driving it: the ledger holds no lease. One entry is returned per session, its newest run.
114
+
115
+ `continueInterrupted` opens each session on the agent and calls `session.continue()`, at most `concurrency` at once. Each outcome is `continued` (with the `RunResult`), `skipped` (`nothing_to_continue` when the session no longer owes a model turn, `session_not_found` when this agent cannot open it), or `failed` (with the error). It never throws for one run. A continuation without a turn checkpoint runs under a new run id, so the old `running` row stays and the next sweep skips that session as `nothing_to_continue`. With `durability: "turn"` it reuses the run id and the row is finished.
116
+
117
+ The sweep costs one paged ledger read plus each continuation's own work. Nothing runs unless the host calls it.
118
+
100
119
  ## Failures and security
101
120
 
102
- Construction rejects empty routes (`no_routes`), duplicate labels (`duplicate_route`), unknown kinds (`unknown_kind`), invalid timeouts (`invalid_timeout`), invalid limits (`invalid_limit`), and malformed routes (`invalid_route`). Missing resume authority rejects with `resume_authority_required`; a foreign id or mismatched ownership rejects with `session_not_found` before any offer; stale supplied ids reject with `stale_decisions`. Route errors are treated as unavailable without logging their messages. Configure finite timeouts for routes that might never settle. The library opens no network connection and adds no kernel contract.
121
+ Construction rejects empty routes (`no_routes`), duplicate labels (`duplicate_route`), unknown kinds (`unknown_kind`), invalid timeouts (`invalid_timeout`), invalid limits (`invalid_limit`), and malformed routes (`invalid_route`). The recovery sweep rejects a store without `queryRuns` (`ledger_query_unsupported`), a missing ownership scope (`invalid_ownership`), and a bad `olderThanMs`, `pageSize` or `concurrency` (`invalid_limit`). Missing resume authority rejects with `resume_authority_required`; a foreign id or mismatched ownership rejects with `session_not_found` before any offer; stale supplied ids reject with `stale_decisions`. Route errors are treated as unavailable without logging their messages. Configure finite timeouts for routes that might never settle. The library opens no network connection and adds no kernel contract.
103
122
 
104
123
  ## Scheduling
105
124
 
@@ -1,9 +1,21 @@
1
- import type { Agent, AgentEvent, Decision, OwnershipScope, RunOptions, Session } from "@arnilo/prism";
1
+ import {
2
+ type Agent,
3
+ type AgentEvent,
4
+ type Decision,
5
+ type OwnershipScope,
6
+ resolveCeilings,
7
+ type RunOptions,
8
+ type RunStateBounds,
9
+ runStateBounds,
10
+ type Session,
11
+ } from "@arnilo/prism";
2
12
  import { HeadlessError } from "./errors.js";
3
13
 
4
14
  /** Share this instance with every router and serveAgent that can resume this agent. */
5
15
  export interface ResumeAuthority {
6
16
  readonly ownership: OwnershipScope;
17
+ /** The agent's run-state bounds (from its ceilings), so a raised `ceilings.runStateBytes` still reads its suspensions. */
18
+ readonly runStateBounds?: RunStateBounds;
7
19
  session(id: string): Promise<Session>;
8
20
  resume(id: string, decisions: readonly Decision[], options?: RunOptions): AsyncIterable<AgentEvent>;
9
21
  }
@@ -17,6 +29,7 @@ export function createResumeAuthority(agent: Agent): ResumeAuthority {
17
29
  };
18
30
  return {
19
31
  ownership,
32
+ runStateBounds: runStateBounds(resolveCeilings(agent.config.ceilings)),
20
33
  session,
21
34
  async *resume(id, decisions, options) {
22
35
  // Claim before any await: the kernel's asynchronous resume preparation cannot arbitrate this race.
@@ -26,7 +26,9 @@ export type HeadlessErrorCode =
26
26
  | "invalid_limit"
27
27
  | "invalid_route"
28
28
  | "invalid_policy"
29
- | "policy_allow_refused";
29
+ | "policy_allow_refused"
30
+ | "ledger_query_unsupported"
31
+ | "invalid_ownership";
30
32
 
31
33
  export class HeadlessError extends Error {
32
34
  constructor(readonly code: HeadlessErrorCode) {
@@ -1,8 +1,17 @@
1
1
  export type { AnswerQuery, RoutedAnswer } from "./answers.js";
2
2
  export { createResumeAuthority, type ResumeAuthority } from "./authority.js";
3
3
  export { HeadlessError, type HeadlessErrorCode } from "./errors.js";
4
- export { DEFAULT_MAX_ANSWERS, HARD_MAX_ANSWERS } from "./limits.js";
4
+ export { DEFAULT_MAX_ANSWERS } from "./limits.js";
5
5
  export { type PolicyAnswers, policyDefault } from "./policy.js";
6
+ export {
7
+ type ContinueInterruptedOptions,
8
+ type ContinueInterruptedOutcome,
9
+ continueInterrupted,
10
+ type FindInterruptedRunsOptions,
11
+ findInterruptedRuns,
12
+ type InterruptedRun,
13
+ type RunListing,
14
+ } from "./recover.js";
6
15
  export type { ResumeWhenAnsweredOptions, ResumeWhenAnsweredResult } from "./resume.js";
7
16
  export { type HostUiRoute, type RoutedHostUi, type RouteHostUiOptions, routeHostUi } from "./route.js";
8
17
  export {
@@ -2,10 +2,10 @@ import type { HostUiRequestKind } from "@arnilo/prism";
2
2
  import { HeadlessError } from "./errors.js";
3
3
 
4
4
  export const DEFAULT_MAX_ANSWERS = 1_000;
5
- export const HARD_MAX_ANSWERS = 100_000;
6
5
  export const HOST_UI_KINDS: readonly HostUiRequestKind[] = ["confirm", "select", "input", "secret", "open-url", "notify", "terminal"];
7
6
 
8
7
  export function answerLimit(value = DEFAULT_MAX_ANSWERS): number {
9
- if (!Number.isSafeInteger(value) || value < 1 || value > HARD_MAX_ANSWERS) throw new HeadlessError("invalid_limit");
8
+ // Host-set: the host's value is the cap (plan 239 Task 5).
9
+ if (!Number.isSafeInteger(value) || value < 1) throw new HeadlessError("invalid_limit");
10
10
  return value;
11
11
  }
@@ -1,13 +1,14 @@
1
- import { type PendingDecision, parseSuspendedRunEntry, type SessionEntry } from "@arnilo/prism";
1
+ import { type PendingDecision, parseSuspendedRunEntry, type RunStateBounds, type SessionEntry } from "@arnilo/prism";
2
2
 
3
- export function pendingDecisionsOf(branch: readonly SessionEntry[]): readonly PendingDecision[] {
3
+ /** `bounds` are the agent's run-state bounds (`runStateBounds(resolveCeilings(agent.config.ceilings))`), so a host with raised ceilings reads its own suspensions. */
4
+ export function pendingDecisionsOf(branch: readonly SessionEntry[], bounds?: RunStateBounds): readonly PendingDecision[] {
4
5
  for (let index = branch.length - 1; index >= 0; index--) {
5
6
  const entry = branch[index];
6
7
  if (!entry) continue;
7
8
  if (entry.kind === "package_state") continue;
8
9
  if (entry.kind !== "suspended_run") return [];
9
10
  try {
10
- return parseSuspendedRunEntry(entry).interruption.pendingDecisions ?? [];
11
+ return parseSuspendedRunEntry(entry, bounds).interruption.pendingDecisions ?? [];
11
12
  } catch {
12
13
  return [];
13
14
  }