@parcha/agentrun-serve 0.1.0-beta.47 → 0.1.0-beta.48

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 (110) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +84 -14
  3. package/dist/acp-package.d.ts +24 -6
  4. package/dist/adapter-facts.d.ts +0 -4
  5. package/dist/adapter-facts.js +1 -4
  6. package/dist/adapters.d.ts +3 -12
  7. package/dist/adapters.js +1 -70
  8. package/dist/answer-json.d.ts +10 -0
  9. package/dist/answer-json.js +24 -0
  10. package/dist/api-only.d.ts +5 -2
  11. package/dist/api-only.js +10 -2
  12. package/dist/browser-live.d.ts +9 -4
  13. package/dist/browser-live.js +18 -5
  14. package/dist/cap.js +7 -9
  15. package/dist/cli.js +6 -6
  16. package/dist/computer-routes.d.ts +8 -5
  17. package/dist/computer-routes.js +7 -5
  18. package/dist/computers.d.ts +6 -2
  19. package/dist/computers.js +4 -2
  20. package/dist/conformance.d.ts +4 -0
  21. package/dist/conformance.js +6 -0
  22. package/dist/console/assets/index-CTGegcKt.css +1 -0
  23. package/dist/console/assets/{index-BBFzAxLB.js → index-D1Se6mgG.js} +165 -165
  24. package/dist/console/index.html +2 -2
  25. package/dist/harness-check.d.ts +3 -1
  26. package/dist/harness-check.js +99 -70
  27. package/dist/harness-cursor.d.ts +10 -27
  28. package/dist/harness-cursor.js +5 -84
  29. package/dist/harness-goose.d.ts +4 -29
  30. package/dist/harness-goose.js +6 -86
  31. package/dist/harness-module.d.ts +4 -0
  32. package/dist/harness-module.js +1 -0
  33. package/dist/harness-owned.d.ts +52 -0
  34. package/dist/harness-owned.js +92 -0
  35. package/dist/harness-recipe.js +2 -24
  36. package/dist/harness-table.d.ts +109 -6
  37. package/dist/harness-table.js +242 -28
  38. package/dist/harness.js +2 -2
  39. package/dist/key-refusal.d.ts +2 -1
  40. package/dist/key-refusal.js +18 -2
  41. package/dist/learn/promote.d.ts +11 -0
  42. package/dist/learn/secrets.d.ts +4 -0
  43. package/dist/learn/secrets.js +23 -0
  44. package/dist/learning-model.d.ts +18 -0
  45. package/dist/learning-model.js +77 -0
  46. package/dist/llms.txt +1 -0
  47. package/dist/model-form.js +12 -12
  48. package/dist/model.d.ts +5 -4
  49. package/dist/model.js +19 -13
  50. package/dist/openapi.js +35 -5
  51. package/dist/page.d.ts +1 -0
  52. package/dist/page.js +1 -1
  53. package/dist/run-secrets.d.ts +2 -2
  54. package/dist/run-secrets.js +6 -5
  55. package/dist/run-trace.js +6 -3
  56. package/dist/runner/adapter-loop.d.ts +4 -1
  57. package/dist/runner/adapter-loop.js +1 -2
  58. package/dist/runner/adapter-run-spec.d.ts +3 -2
  59. package/dist/runner/adapter-run-spec.js +8 -4
  60. package/dist/runner/adapters/index.d.ts +4 -2
  61. package/dist/runner/adapters/index.js +6 -42
  62. package/dist/runner/cli-run-spec.js +10 -6
  63. package/dist/runner/conformance/host-tools.d.ts +4 -0
  64. package/dist/runner/conformance/host-tools.js +14 -0
  65. package/dist/runner/meta-tools.js +4 -2
  66. package/dist/runner/presence.d.ts +3 -0
  67. package/dist/runner/presence.js +19 -12
  68. package/dist/runner/promotion.d.ts +62 -4
  69. package/dist/runner/promotion.js +146 -15
  70. package/dist/runner/sdk-loop.js +25 -1
  71. package/dist/runner/workflow-spec.js +3 -2
  72. package/dist/runs-over-store.d.ts +2 -1
  73. package/dist/runs-over-store.js +2 -4
  74. package/dist/sdk/check.d.ts +31 -0
  75. package/dist/sdk/check.js +58 -0
  76. package/dist/sdk/runs.d.ts +10 -2
  77. package/dist/sdk/runs.js +87 -17
  78. package/dist/sdk/schema.js +11 -3
  79. package/dist/server.d.ts +3 -0
  80. package/dist/server.js +116 -40
  81. package/dist/store/sqlite/store.js +35 -30
  82. package/dist/store/store.d.ts +20 -18
  83. package/dist/store-view.d.ts +5 -3
  84. package/dist/store-view.js +9 -7
  85. package/dist/template-eval.js +5 -2
  86. package/dist/template-github-permissions.d.ts +5 -1
  87. package/dist/template-github-permissions.js +7 -3
  88. package/dist/timeline/index.d.ts +1 -1
  89. package/dist/timeline/index.js +1 -1
  90. package/dist/timeline/timeline.d.ts +8 -0
  91. package/dist/timeline/timeline.js +18 -6
  92. package/dist/tool-gate.d.ts +8 -4
  93. package/dist/tool-gate.js +6 -7
  94. package/dist/tool-plane.d.ts +4 -0
  95. package/dist/tool-plane.js +10 -10
  96. package/dist/trigger-targets.d.ts +11 -2
  97. package/dist/trigger-targets.js +71 -2
  98. package/dist/validate.js +5 -1
  99. package/dist/viewer-credential.d.ts +25 -0
  100. package/dist/viewer-credential.js +51 -0
  101. package/dist/workspace/resolve-computer.d.ts +5 -0
  102. package/dist/workspace/resolve-computer.js +19 -1
  103. package/package.json +18 -10
  104. package/templates/code-review/agent.md +2 -3
  105. package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
  106. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
  107. package/templates/code-review/evals/other-repo/case.yaml +0 -1
  108. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
  109. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
  110. package/dist/console/assets/index-BRi-Rgq6.css +0 -1
@@ -0,0 +1,31 @@
1
+ import type { Shown } from "../learning.js";
2
+ import type { RunLaunch } from "../run-launch.js";
3
+ import type { Store } from "../store/store.js";
4
+ import type { SdkInbox } from "./runs.js";
5
+ export type SdkWorkflowCheckEvent = {
6
+ type: "workflow_check";
7
+ id: string;
8
+ digest: string;
9
+ outcome: "answered" | "handed_back" | "failed" | "skipped_write";
10
+ answer?: string;
11
+ reason?: string;
12
+ skipped?: {
13
+ tool: string;
14
+ unmarked?: true;
15
+ };
16
+ /** Fresh read-only calls the shadow made where the native recording had no result (the client's shadowReadFallback). */
17
+ fresh_reads?: number;
18
+ };
19
+ /** Settles a connected agent's check at its run's end. The client reports execution, never its own verdict, and the
20
+ * immutable completion is the baseline. A shadow that answered or handed back on a valid native turn is one row of the
21
+ * check (decideCheck); any other turn is given back (releaseSdkCheck) and the check waits for the next turn; a turn the
22
+ * backend never completed before its inbox expired is one failed row (sdkCheckDeadline). Exact retries and reclaims
23
+ * compete on the reservation. */
24
+ export declare function settleSdkCheck(deps: {
25
+ store: Store;
26
+ agentId: string;
27
+ launch: RunLaunch;
28
+ inbox: SdkInbox;
29
+ shown: () => Promise<Shown>;
30
+ log: (line: string) => void;
31
+ }): Promise<import("../learn/promote.js").Recorded | undefined>;
@@ -0,0 +1,58 @@
1
+ import { decideCheck, releaseSdkCheck, sdkCheckDeadline, sdkInputText } from "../runner/promotion.js";
2
+ import { promotionOf, promotionsOf } from "../learn/promote.js";
3
+ /** Why a completed inbox's native turn cannot be its check's baseline, or undefined when it can: a completed turn with
4
+ * complete, unredacted evidence and no learned workflow or nested call in it, whose shadow answered or handed back. */
5
+ function notBaseline(inbox, reported) {
6
+ const result = inbox.completion;
7
+ if (result.status !== "completed")
8
+ return `its native turn ${result.status === "cancelled" ? "was cancelled" : "failed"}`;
9
+ if (result.evidence_complete === false)
10
+ return "the backend reported its native turn's evidence incomplete";
11
+ if (inbox.check_redacted)
12
+ return "its native evidence held a protected value, so two different answers could agree by their placeholder";
13
+ if (inbox.batches.some((batch) => batch.events.some((event) => event.type === "tool" && (event.name === "learned_workflow" || event.parent_tool_use_id !== undefined))))
14
+ return "its native turn ran a learned workflow, so its answer is not the agent's own";
15
+ if (!reported)
16
+ return "the connected agent reported no shadow check";
17
+ if (reported.outcome === "failed")
18
+ return `its shadow did not answer (${reported.reason ?? "no reason given"})`;
19
+ if (reported.outcome === "skipped_write")
20
+ return `its shadow stopped at a write the native turn did not make (${reported.skipped?.tool ?? "a tool"})`;
21
+ return undefined;
22
+ }
23
+ /** Settles a connected agent's check at its run's end. The client reports execution, never its own verdict, and the
24
+ * immutable completion is the baseline. A shadow that answered or handed back on a valid native turn is one row of the
25
+ * check (decideCheck); any other turn is given back (releaseSdkCheck) and the check waits for the next turn; a turn the
26
+ * backend never completed before its inbox expired is one failed row (sdkCheckDeadline). Exact retries and reclaims
27
+ * compete on the reservation. */
28
+ export async function settleSdkCheck(deps) {
29
+ const { inbox } = deps;
30
+ const check = inbox.learning_check;
31
+ if (!check)
32
+ return;
33
+ const record = promotionOf(await promotionsOf(deps.store.settings, deps.agentId), check.workflow.name, check.digest);
34
+ if (record?.decided !== "replaying" || record.via !== "sdk" || record.replay_id !== check.id || !record.check || record.commit !== check.revision || record.runs?.[0] !== inbox.run_id)
35
+ return;
36
+ const completion = inbox.completion;
37
+ if (!completion) {
38
+ if (inbox.closed === "expired")
39
+ return sdkCheckDeadline(deps, record);
40
+ if (inbox.closed)
41
+ return releaseSdkCheck(deps, record, inbox.closed === "cancelled" ? "its native turn was stopped before the backend completed it" : "its native turn ended before the backend completed it");
42
+ return;
43
+ }
44
+ const reported = inbox.batches.flatMap((batch) => batch.events)
45
+ .find((event) => event.type === "workflow_check" && event.id === check.id && event.digest === check.digest);
46
+ const cause = notBaseline({ ...inbox, completion }, reported);
47
+ if (cause !== undefined || !reported)
48
+ return releaseSdkCheck(deps, record, cause ?? "the connected agent reported no shadow check");
49
+ const outcomes = { answered: 0, handed_back: 0, failed: 0, skipped_write: 0 };
50
+ outcomes[reported.outcome]++;
51
+ return decideCheck(deps, check.workflow.name, check.digest, record.check, {
52
+ rows: [{ of: inbox.run_id, input: sdkInputText(deps.launch), agent: completion.answer, outcome: reported.outcome,
53
+ answer: reported.outcome === "answered" ? reported.answer ?? null : null,
54
+ ...(reported.outcome === "handed_back" ? { escalated: reported.reason ?? "The shadow workflow handed the task back." } : {}),
55
+ }], cost: null, outcomes, unstarted: 0, ...(reported.fresh_reads ? { fresh_reads: reported.fresh_reads } : {}),
56
+ exactMismatchReason: "its answer did not match the native answer exactly; connected SDK checks do not use a semantic grader, so name the fields that carry the decision (learning.agree_on) when whole-answer equality is not the intended check",
57
+ }, (was) => was?.decided === "replaying" && was.replay_id === check.id, { via: "sdk", runs: record.runs, replay_id: check.id, commit: check.revision });
58
+ }
@@ -2,6 +2,8 @@ import type { Claim, RunOrigin, Store } from "../store/store.js";
2
2
  import type { AgentEntry } from "../agents-store.js";
3
3
  import { type StartDeps } from "../runs-over-store.js";
4
4
  import { type LearnedWorkflow } from "../learning.js";
5
+ import type { SdkWorkflowCheckEvent } from "./check.js";
6
+ import { type SdkWorkflowCheck } from "../runner/promotion.js";
5
7
  export type SdkRuntime = "claude-agent-sdk" | "codex-sdk" | "eve";
6
8
  export type SdkUsage = {
7
9
  input_tokens: number | null;
@@ -10,7 +12,7 @@ export type SdkUsage = {
10
12
  cache_write_tokens: number | null;
11
13
  cost_usd: number | null;
12
14
  };
13
- export type SdkEvent = {
15
+ export type SdkEvent = SdkWorkflowCheckEvent | {
14
16
  type: "text";
15
17
  text: string;
16
18
  } | {
@@ -42,8 +44,12 @@ export type SdkInbox = {
42
44
  sequence: number;
43
45
  events: SdkEvent[];
44
46
  }[];
45
- /** Exact approved executable workflows delivered by the start receipt. */
47
+ /** Exact promoted executable workflows delivered by the start receipt. */
46
48
  learning_workflows?: LearnedWorkflow[];
49
+ /** A compiled draft reserved for a shadow check, never supplied to the native agent. */
50
+ learning_check?: SdkWorkflowCheck;
51
+ /** Server cleaning changed evidence: two different secret-bearing answers must never agree by their placeholder. */
52
+ check_redacted?: true;
47
53
  completion?: SdkCompletion;
48
54
  /** Internal terminal admission fence. No later evidence can be newly acknowledged after this CAS wins. */
49
55
  closed?: "expired" | "failed" | "cancelled";
@@ -81,6 +87,7 @@ export declare class SdkRuns {
81
87
  console_url: string;
82
88
  token: string;
83
89
  learning: {
90
+ check?: SdkWorkflowCheck | undefined;
84
91
  enabled: boolean;
85
92
  revision: string | null;
86
93
  context: string;
@@ -93,6 +100,7 @@ export declare class SdkRuns {
93
100
  console_url: string;
94
101
  token: string;
95
102
  learning: {
103
+ check?: SdkWorkflowCheck | undefined;
96
104
  enabled: boolean;
97
105
  revision: string | null;
98
106
  context: string;
package/dist/sdk/runs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Backend SDK calls remain in their application. This inbox only records their evidence and immutable completion;
2
2
  // the ordinary fenced runner owns journals, reflection, checking and learning commits.
3
3
  import { createHash, createHmac, timingSafeEqual } from "node:crypto";
4
- import { inspectWorkflow } from "@parcha/agentrun-dsl";
4
+ import { inspectWorkflow, resolveSchemaForWorkflow } from "@parcha/agentrun-dsl";
5
5
  import { ApiError } from "../errors.js";
6
6
  import { canonical, isObject } from "../store/agent-body.js";
7
7
  import { uuidv7 } from "../agents-store.js";
@@ -9,10 +9,14 @@ import { launchBody } from "../run-launch.js";
9
9
  import { learningStartFor } from "../runs-over-store.js";
10
10
  import { chooseWorkflows, learningFolderOf, seedAt, secretsShown } from "../learning.js";
11
11
  import { INSTRUCTION_EVIDENCE_BYTES } from "../native/instructions.js";
12
+ import { refuseWhileNoRunner } from "../runner/presence.js";
12
13
  import { secretRedactor } from "../runner/redact.js";
13
14
  import { redactedOutput } from "../key-refusal.js";
14
15
  import { decodedStrings, draftProblems } from "../learn/workflow-draft.js";
15
16
  import { sdkWorkflowManifest, sdkDraftTools } from "./workflows.js";
17
+ import { promotionOf, promotionsOf } from "../learn/promote.js";
18
+ import { championTextOf, releaseSdkCheck, reserveSdkCheck } from "../runner/promotion.js";
19
+ import { fits, workflowDigest } from "../runner/workflow-first.js";
16
20
  const keyOf = (id) => `sdk-run:${id}`;
17
21
  /** The settings key an SDK run's record is kept under (the run's delete with its agent's: agent-delete.ts). */
18
22
  export const sdkRunKey = keyOf;
@@ -189,9 +193,7 @@ export class SdkRuns {
189
193
  throw new ApiError("agent_not_runnable", "AgentRun cannot enforce a spend cap on an external SDK. Configure the budget in the backend SDK and remove this managed run cap.");
190
194
  // A runner keeps an SDK run's evidence and ends it: while every runner here refused to claim, the start is refused in
191
195
  // their words, as any start is (prepareLaunch), before the caller holds a receipt it would run on.
192
- const refused = await deps.runnersRefused?.();
193
- if (refused !== undefined)
194
- throw new ApiError("runner_refused", refused);
196
+ await refuseWhileNoRunner(this.store.runners);
195
197
  const learning = await learningStartFor(deps, entry, pinned.revision, revisionBody, {
196
198
  noWorkflows: !workflow,
197
199
  ...(compile.model ? { model: compile.model } : {}),
@@ -205,9 +207,24 @@ export class SdkRuns {
205
207
  if (learning.seedFailed)
206
208
  throw new ApiError("unavailable", "The learning seed could not be read. Retry after restoring the agent learning folder.");
207
209
  }
208
- const workflows = learning && !learning.noWorkflows && workflow ? await this.selectedWorkflows(entry.agent.id, learning.seed, workflow) : [];
210
+ const selected = learning && !learning.noWorkflows && workflow ? await this.selectedWorkflows(entry.agent.id, learning.seed, workflow) : { workflows: [], candidates: [] };
209
211
  const cleaned = this.clean({ instructions, ...(model ? { model } : {}) });
210
212
  const runId = uuidv7();
213
+ const redacted = cleanedInput !== input || cleaned.instructions !== instructions;
214
+ let task;
215
+ try {
216
+ task = JSON.parse(input);
217
+ }
218
+ catch { /* A prose task: the client resolves the draft's input from the turn. */ }
219
+ // A turn is a check only when it can be one's baseline: no protected value in its task or policy, and an input the
220
+ // draft takes. A JSON object task is the input, so it must fit (the managed check's own rule); a prose task's input
221
+ // is resolved by the client from the turn's recorded tool inputs or the host's resolveCheckInput, and a turn it
222
+ // cannot resolve is given back (releaseSdkCheck), never counted.
223
+ const takes = (flow) => !redacted && (!isObject(task) || fits(flow, task, resolveSchemaForWorkflow));
224
+ const checkDeps = { store: this.store, agentId: entry.agent.id, log: () => { }, shown: async () => secretsShown(this.secrets(), { local: true }) };
225
+ const check = learning ? await reserveSdkCheck(checkDeps, { runId, revision: learning.seed, learning: revisionBody.learning, flows: selected.candidates, takes }) : undefined;
226
+ // A shadow check needs the original agent's own answer, not an answer produced by its existing champion.
227
+ const workflows = check ? [] : selected.workflows;
211
228
  const launch = {
212
229
  input: { content: cleanedInput },
213
230
  title: cleanedInput.trim().replace(/\s+/g, " ").slice(0, 80),
@@ -222,18 +239,27 @@ export class SdkRuns {
222
239
  ...(learning ? { learning: { ...learning, workflows: workflows.map((flow) => flow.name) } } : {}),
223
240
  };
224
241
  const now = Date.now();
225
- await this.store.settings.put(keyOf(runId), {
226
- run_id: runId,
227
- created_at: now,
228
- expires_at: now + 3_600_000,
229
- batches: [],
230
- learning_workflows: workflows,
231
- });
232
242
  try {
243
+ await this.store.settings.put(keyOf(runId), {
244
+ run_id: runId,
245
+ created_at: now,
246
+ expires_at: now + 3_600_000,
247
+ batches: [],
248
+ learning_workflows: workflows,
249
+ ...(check ? { learning_check: check } : {}),
250
+ ...(redacted ? { check_redacted: true } : {}),
251
+ });
233
252
  await this.store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: entry.revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) });
234
253
  }
235
254
  catch (error) {
236
255
  await this.store.settings.remove(keyOf(runId));
256
+ // The reservation comes first because the launch it is created with withholds the champion from a check's turn.
257
+ // No turn ran, so the check waits for the next one, the release uncounted: never a hold of a draft never compared.
258
+ if (check) {
259
+ const record = promotionOf(await promotionsOf(this.store.settings, entry.agent.id).catch(() => []), check.workflow.name, check.digest);
260
+ if (record?.decided === "replaying" && record.replay_id === check.id)
261
+ await releaseSdkCheck(checkDeps, record, "its start could not be admitted", false).catch(() => undefined);
262
+ }
237
263
  throw error;
238
264
  }
239
265
  return this.receipt(runId, consoleOrigin);
@@ -247,7 +273,7 @@ export class SdkRuns {
247
273
  const workflows = inbox.learning_workflows ?? [];
248
274
  const shown = secretsShown(this.secrets(), { local: true });
249
275
  if (shown.holds(launch.learning?.section ?? "") ||
250
- workflows.some((flow) => {
276
+ [...workflows, ...(inbox.learning_check ? [inbox.learning_check.workflow] : [])].some((flow) => {
251
277
  const decoded = decodedStrings(flow.workflow);
252
278
  return shown.holds(flow.name) || shown.holds(flow.description) || shown.holds(flow.workflow) || decoded === "too_deep" || decoded.some(shown.holds);
253
279
  }))
@@ -262,6 +288,7 @@ export class SdkRuns {
262
288
  revision: launch.learning?.seed ?? null,
263
289
  context: launch.learning?.section ?? "",
264
290
  workflows,
291
+ ...(inbox.learning_check ? { check: inbox.learning_check } : {}),
265
292
  },
266
293
  };
267
294
  }
@@ -272,14 +299,25 @@ export class SdkRuns {
272
299
  const { flows } = chooseWorkflows(seed, secretsShown(this.secrets(), { local: true }));
273
300
  const dsl = await import("@parcha/agentrun-dsl");
274
301
  const { tools, gated, deniedBy } = sdkDraftTools(binding.workflow_tools);
302
+ const records = await promotionsOf(this.store.settings, agentId);
275
303
  let room = 256 * 1024;
276
- return flows.filter((flow) => {
304
+ const compatible = (flow) => {
277
305
  const bytes = Buffer.byteLength(JSON.stringify(flow));
278
306
  if (bytes > room || draftProblems(dsl, flow.workflow, tools, gated, deniedBy, undefined, binding.workflow_adapters).length)
279
307
  return false;
280
308
  room -= bytes;
281
309
  return true;
282
- });
310
+ };
311
+ const workflows = [], candidates = [];
312
+ const atCommit = async (name, commit) => chooseWorkflows(await seedAt(folder.workspace, commit), secretsShown(this.secrets(), { local: true })).flows.find((one) => one.name === name);
313
+ for (const flow of flows) {
314
+ const { text: serving } = await championTextOf(records, flow, atCommit);
315
+ if (serving && compatible(serving))
316
+ workflows.push(serving);
317
+ if ((!serving || workflowDigest(serving) !== workflowDigest(flow)) && compatible(flow))
318
+ candidates.push(flow);
319
+ }
320
+ return { workflows, candidates };
283
321
  }
284
322
  finally {
285
323
  await folder.end();
@@ -324,6 +362,31 @@ export class SdkRuns {
324
362
  only(value, ["type", "session_id"]);
325
363
  return { type: "session", session_id: text(value.session_id, "session_id", 256) };
326
364
  }
365
+ if (value.type === "workflow_check") {
366
+ only(value, ["type", "id", "digest", "outcome", "answer", "reason", "skipped", "fresh_reads"]);
367
+ if (value.fresh_reads !== undefined && (!Number.isSafeInteger(value.fresh_reads) || value.fresh_reads < 1 || value.fresh_reads > 256))
368
+ refuse("fresh_reads must be an integer from 1 to 256 when supplied.");
369
+ if (!["answered", "handed_back", "failed", "skipped_write"].includes(String(value.outcome)))
370
+ refuse("Invalid workflow check outcome.");
371
+ if (value.outcome === "answered" && typeof value.answer !== "string")
372
+ refuse("An answered workflow check needs its answer.");
373
+ if (value.skipped !== undefined) {
374
+ if (!isObject(value.skipped))
375
+ refuse("A skipped workflow check names its tool.");
376
+ only(value.skipped, ["tool", "unmarked"]);
377
+ text(value.skipped.tool, "skipped.tool", 256);
378
+ if (value.skipped.unmarked !== undefined && value.skipped.unmarked !== true)
379
+ refuse("skipped.unmarked must be true when supplied.");
380
+ }
381
+ if (value.outcome === "skipped_write" && value.skipped === undefined)
382
+ refuse("A skipped write names its tool.");
383
+ return { type: "workflow_check", id: text(value.id, "id", 256), digest: text(value.digest, "digest", 256), outcome: value.outcome,
384
+ ...(value.answer !== undefined ? { answer: text(value.answer, "answer") } : {}),
385
+ ...(value.reason !== undefined ? { reason: text(value.reason, "reason", 8000) } : {}),
386
+ ...(value.skipped !== undefined ? { skipped: value.skipped } : {}),
387
+ ...(value.fresh_reads !== undefined ? { fresh_reads: value.fresh_reads } : {}),
388
+ };
389
+ }
327
390
  if (value.type === "tool") {
328
391
  only(value, ["type", "id", "name", "status", "input", "output", "parent_tool_use_id"]);
329
392
  if (!["started", "completed", "failed"].includes(String(value.status)))
@@ -341,6 +404,7 @@ export class SdkRuns {
341
404
  return refuse("Unsupported SDK event type.");
342
405
  });
343
406
  const batch = this.clean({ sequence: body.sequence, events }, runId);
407
+ const checkRedacted = canonical(events) !== canonical(batch.events);
344
408
  const known = (await sdkInbox(this.store, runId)).batches.find((item) => item.sequence === batch.sequence);
345
409
  if (known) {
346
410
  if (canonical(known) !== canonical(batch))
@@ -361,7 +425,13 @@ export class SdkRuns {
361
425
  if (batch.sequence !== row.batches.length + 1)
362
426
  throw new ApiError("idempotency_mismatch", "SDK event sequences must be contiguous.");
363
427
  checkToolParents(row, batch.events);
364
- return { ...row, batches: [...row.batches, batch] };
428
+ const checks = [...row.batches.flatMap(item => item.events), ...batch.events].filter((event) => event.type === "workflow_check");
429
+ if (checks.length > 1)
430
+ refuse("Only one workflow check may be delivered per SDK run.");
431
+ for (const check of checks)
432
+ if (!row.learning_check || check.id !== row.learning_check.id || check.digest !== row.learning_check.digest)
433
+ refuse("The workflow check must name this SDK run's reserved candidate.");
434
+ return { ...row, batches: [...row.batches, batch], ...(checkRedacted ? { check_redacted: true } : {}) };
365
435
  }, EVIDENCE_LIMIT);
366
436
  return { accepted: true };
367
437
  }
@@ -394,7 +464,7 @@ export class SdkRuns {
394
464
  return row;
395
465
  }
396
466
  writableInbox(row);
397
- return { ...row, completion };
467
+ return { ...row, completion, ...(completion.answer !== body.answer ? { check_redacted: true } : {}) };
398
468
  });
399
469
  return { accepted: true };
400
470
  }
@@ -25,6 +25,13 @@ const event = {
25
25
  oneOf: [
26
26
  object({ type: { const: "text" }, text: { ...text, maxLength: 128000 } }),
27
27
  object({ type: { const: "session" }, session_id: { ...text, maxLength: 256 } }),
28
+ object({
29
+ type: { const: "workflow_check" }, id: { ...text, maxLength: 256 }, digest: { ...text, maxLength: 256 },
30
+ outcome: { enum: ["answered", "handed_back", "failed", "skipped_write"] },
31
+ answer: { ...text, maxLength: 128000 }, reason: { ...text, maxLength: 8000 },
32
+ skipped: object({ tool: { ...text, maxLength: 256 }, unmarked: { const: true } }, ["tool"]),
33
+ fresh_reads: { type: "integer", minimum: 1, maximum: 256 },
34
+ }, ["type", "id", "digest", "outcome"]),
28
35
  object({
29
36
  type: { const: "tool" },
30
37
  id: { ...text, maxLength: 256 },
@@ -49,15 +56,16 @@ const learning = object({
49
56
  enabled: { type: "boolean" },
50
57
  revision: { type: ["string", "null"] },
51
58
  context: { ...text, description: "The agent's corrections.md as the run reads it under # Learned; empty when Off or nothing is learned yet." },
52
- workflows: { type: "array", items: object({ name: text, workflow: text, description: text }), description: "Active, capability-compatible learned workflows pinned to this run; empty without a backend workflow bridge or when learning is Off." },
53
- });
59
+ workflows: { type: "array", items: object({ name: text, workflow: text, description: text }), description: "Promoted, capability-compatible learned workflows pinned to this run; empty without a backend workflow bridge, during an independent shadow-check turn, or when learning is Off." },
60
+ check: { ...object({ id: text, revision: text, digest: text, workflow: object({ name: text, workflow: text, description: text }) }), description: "One compiled draft reserved for a shadow check against this run's native answer. Keep outside the model context; replay only recorded tool results after the native turn and submit workflow_check evidence." },
61
+ }, ["enabled", "revision", "context", "workflows"]);
54
62
  export const SDK_PATHS = {
55
63
  "/agents/{agent_id}/sdk-runs": {
56
64
  post: {
57
65
  ...mark,
58
66
  operationId: "startSdkRun",
59
67
  summary: "Register a task executed by an existing backend SDK",
60
- description: "Requires an SDK agent definition. Captures the actual original policy and input, pins approved learning, and returns a credential scoped to this run. The backend retains all model/tool/auth settings. Learning requires a configured server reflection/grading model; learning Off needs no server model key.",
68
+ description: "Requires an SDK agent definition. Captures the actual original policy and input, pins promoted workflows and any compiled shadow-check candidate separately, and returns a credential scoped to this run. The backend retains all model/tool/auth settings. Learning requires a configured server reflection/grading model; learning Off needs no server model key.",
61
69
  parameters: [id("agent_id"), { ...key, required: true }],
62
70
  requestBody: body(object({
63
71
  runtime: SDK_BINDING.properties.runtime,
package/dist/server.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type LearningModel } from "./learning-model.js";
1
2
  import { type Server } from "node:http";
2
3
  import { type ModelNeeds } from "./model.js";
3
4
  import { type HarnessCapability } from "./harness.js";
@@ -384,6 +385,7 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
384
385
  fast: string | null;
385
386
  strong: string | null;
386
387
  };
388
+ learning_model: LearningModel;
387
389
  /** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
388
390
  * `approve`: whether the caller can approve one, which takes the owner's password session (forCaller), and
389
391
  * `approve_needs` when not. */
@@ -704,6 +706,7 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
704
706
  fast: string | null;
705
707
  strong: string | null;
706
708
  };
709
+ learning_model: LearningModel;
707
710
  /** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
708
711
  * `approve`: whether the caller can approve one, which takes the owner's password session (forCaller), and
709
712
  * `approve_needs` when not. */