@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.51

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 (146) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +142 -17
  3. package/dist/agents-store.js +7 -3
  4. package/dist/api-only.d.ts +2 -1
  5. package/dist/api-only.js +3 -2
  6. package/dist/capacity.d.ts +50 -0
  7. package/dist/capacity.js +49 -0
  8. package/dist/cli-learning/claude-wire.d.ts +41 -0
  9. package/dist/cli-learning/claude-wire.js +258 -0
  10. package/dist/cli-learning/cli.d.ts +11 -0
  11. package/dist/cli-learning/cli.js +241 -0
  12. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  13. package/dist/cli-learning/codex-worktree.js +119 -0
  14. package/dist/cli-learning/connections.d.ts +62 -0
  15. package/dist/cli-learning/connections.js +87 -0
  16. package/dist/cli-learning/entry.d.ts +1 -0
  17. package/dist/cli-learning/entry.js +4 -0
  18. package/dist/cli-learning/evidence.d.ts +78 -0
  19. package/dist/cli-learning/evidence.js +492 -0
  20. package/dist/cli-learning/hook.d.ts +33 -0
  21. package/dist/cli-learning/hook.js +544 -0
  22. package/dist/cli-learning/install.d.ts +33 -0
  23. package/dist/cli-learning/install.js +335 -0
  24. package/dist/cli-learning/observation-proof.d.ts +14 -0
  25. package/dist/cli-learning/observation-proof.js +10 -0
  26. package/dist/cli-learning/policy.d.ts +48 -0
  27. package/dist/cli-learning/policy.js +363 -0
  28. package/dist/cli-learning/schema.d.ts +16 -0
  29. package/dist/cli-learning/schema.js +27 -0
  30. package/dist/cli-learning/state.d.ts +23 -0
  31. package/dist/cli-learning/state.js +61 -0
  32. package/dist/cli.js +24 -2
  33. package/dist/console/assets/index-Bt1B51b7.js +733 -0
  34. package/dist/console/assets/index-sVftE9Ht.css +1 -0
  35. package/dist/console/index.html +2 -2
  36. package/dist/email/email-faux.d.ts +3 -1
  37. package/dist/email/email-faux.js +3 -2
  38. package/dist/email/routes.js +22 -12
  39. package/dist/harness-install.d.ts +6 -2
  40. package/dist/harness-install.js +40 -8
  41. package/dist/harness.d.ts +1 -1
  42. package/dist/harness.js +2 -2
  43. package/dist/learn/secrets.js +14 -3
  44. package/dist/learning-words.d.ts +1 -1
  45. package/dist/learning-words.js +1 -1
  46. package/dist/mcp-pin-first.js +2 -1
  47. package/dist/mcp-private-hosts.d.ts +24 -3
  48. package/dist/mcp-private-hosts.js +53 -3
  49. package/dist/model-gateway.d.ts +2 -0
  50. package/dist/model-gateway.js +3 -1
  51. package/dist/native/runtimes.d.ts +2 -0
  52. package/dist/native/runtimes.js +2 -0
  53. package/dist/observation/learning.d.ts +32 -0
  54. package/dist/observation/learning.js +66 -0
  55. package/dist/observation/observer.d.ts +8 -1
  56. package/dist/observation/observer.js +89 -9
  57. package/dist/observation/schema.js +12 -4
  58. package/dist/observation/usage-identity.d.ts +9 -0
  59. package/dist/observation/usage-identity.js +11 -0
  60. package/dist/openapi.js +89 -13
  61. package/dist/run-launch.d.ts +14 -0
  62. package/dist/run-launch.js +4 -0
  63. package/dist/run-view.d.ts +2 -0
  64. package/dist/run-view.js +12 -7
  65. package/dist/runner/adapter-loop.js +29 -26
  66. package/dist/runner/adapter-run-spec.js +2 -2
  67. package/dist/runner/beside.d.ts +13 -0
  68. package/dist/runner/beside.js +27 -8
  69. package/dist/runner/cli-run-spec.js +2 -2
  70. package/dist/runner/disk-free.d.ts +44 -0
  71. package/dist/runner/disk-free.js +96 -0
  72. package/dist/runner/feedback-round.d.ts +12 -8
  73. package/dist/runner/feedback-round.js +16 -30
  74. package/dist/runner/harness-loops.js +3 -1
  75. package/dist/runner/journal-kinds.d.ts +1 -1
  76. package/dist/runner/learning-end.js +4 -0
  77. package/dist/runner/main.d.ts +17 -6
  78. package/dist/runner/main.js +187 -45
  79. package/dist/runner/presence.d.ts +11 -2
  80. package/dist/runner/presence.js +31 -3
  81. package/dist/runner/run-child-host.d.ts +12 -15
  82. package/dist/runner/run-child-host.js +46 -108
  83. package/dist/runner/run-errors.js +2 -0
  84. package/dist/runner/runner-check.d.ts +51 -0
  85. package/dist/runner/runner-check.js +206 -0
  86. package/dist/runner/runner-metrics.d.ts +19 -0
  87. package/dist/runner/runner-metrics.js +49 -0
  88. package/dist/runner/runner.d.ts +37 -0
  89. package/dist/runner/runner.js +43 -3
  90. package/dist/runner/sdk-loop.js +34 -22
  91. package/dist/runs-over-store.d.ts +8 -1
  92. package/dist/runs-over-store.js +57 -9
  93. package/dist/sdk/runs.d.ts +22 -2
  94. package/dist/sdk/runs.js +103 -34
  95. package/dist/server.d.ts +3 -0
  96. package/dist/server.js +149 -26
  97. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  98. package/dist/start-switches.js +2 -0
  99. package/dist/stats.d.ts +4 -0
  100. package/dist/stats.js +1 -1
  101. package/dist/store/agent-body.d.ts +12 -0
  102. package/dist/store/agent-body.js +16 -2
  103. package/dist/store/dialect.d.ts +2 -0
  104. package/dist/store/dialect.js +1 -0
  105. package/dist/store/index.d.ts +3 -3
  106. package/dist/store/index.js +2 -2
  107. package/dist/store/postgres/connection.d.ts +5 -2
  108. package/dist/store/postgres/connection.js +19 -7
  109. package/dist/store/postgres/dialect.js +1 -0
  110. package/dist/store/postgres/migrate.d.ts +30 -0
  111. package/dist/store/postgres/migrate.js +72 -5
  112. package/dist/store/postgres/migration-lint.d.ts +8 -0
  113. package/dist/store/postgres/migration-lint.js +119 -0
  114. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  115. package/dist/store/postgres/store.d.ts +8 -3
  116. package/dist/store/postgres/store.js +31 -11
  117. package/dist/store/schema.d.ts +18 -1
  118. package/dist/store/schema.js +33 -2
  119. package/dist/store/sqlite/run-launch.d.ts +9 -1
  120. package/dist/store/sqlite/run-launch.js +44 -0
  121. package/dist/store/sqlite/store.d.ts +17 -0
  122. package/dist/store/sqlite/store.js +87 -10
  123. package/dist/store/store-schema.d.ts +34 -0
  124. package/dist/store/store-schema.js +125 -0
  125. package/dist/store/store.d.ts +53 -1
  126. package/dist/store/store.js +13 -0
  127. package/dist/store-reads/analytics.d.ts +3 -2
  128. package/dist/store-reads/analytics.js +20 -8
  129. package/dist/store-view.d.ts +4 -3
  130. package/dist/store-view.js +11 -7
  131. package/dist/templates.d.ts +3 -2
  132. package/dist/tool-gate.d.ts +4 -2
  133. package/dist/unified-usage.d.ts +24 -0
  134. package/dist/unified-usage.js +400 -0
  135. package/dist/uploads-archil.d.ts +100 -0
  136. package/dist/uploads-archil.js +430 -0
  137. package/dist/uploads.d.ts +55 -1
  138. package/dist/uploads.js +185 -98
  139. package/dist/validate.js +1 -1
  140. package/dist/workspace/archil-disk.d.ts +6 -5
  141. package/dist/workspace/archil-disk.js +27 -12
  142. package/dist/workspace/archil.js +3 -2
  143. package/package.json +10 -10
  144. package/skills/agentrun-serve/SKILL.md +52 -7
  145. package/dist/console/assets/index-D0mr9wfZ.css +0 -1
  146. package/dist/console/assets/index-D7G6o-1E.js +0 -720
package/dist/sdk/runs.js CHANGED
@@ -3,12 +3,13 @@
3
3
  import { createHash, createHmac, timingSafeEqual } from "node:crypto";
4
4
  import { inspectWorkflow, resolveSchemaForWorkflow } from "@parcha/agentrun-dsl";
5
5
  import { ApiError } from "../errors.js";
6
- import { canonical, isObject } from "../store/agent-body.js";
6
+ import { canonical, isObject, cliLearningOf, learningSettingForBody } from "../store/agent-body.js";
7
7
  import { uuidv7 } from "../agents-store.js";
8
8
  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 { CLI_POLICY_BYTES } from "../cli-learning/policy.js";
12
13
  import { refuseWhileNoRunner } from "../runner/presence.js";
13
14
  import { secretRedactor } from "../runner/redact.js";
14
15
  import { redactedOutput } from "../key-refusal.js";
@@ -19,6 +20,13 @@ import { championTextOf, releaseSdkCheck, reserveSdkCheck } from "../runner/prom
19
20
  import { fits, workflowDigest } from "../runner/workflow-first.js";
20
21
  import { SDK_WORKFLOW_RUNTIMES, sdkBindingOf } from "./runtimes.js";
21
22
  export { SDK_RUNTIMES, isSdkRuntime } from "./runtimes.js";
23
+ /** Claude's begin snapshot is provisional; only its immutable same-window completion can establish policy. */
24
+ export function cliPolicyOf(launch, completion) {
25
+ const cli = launch.cli_learning;
26
+ if (!cli)
27
+ return undefined;
28
+ return cli.runtime === "claude-code-cli" ? completion?.source_policy ?? { instructions: "The current Claude prompt policy was not captured.", complete: false } : { instructions: cli.instructions, complete: cli.policy_complete };
29
+ }
22
30
  const keyOf = (id) => `sdk-run:${id}`;
23
31
  /** The settings key an SDK run's record is kept under (the run's delete with its agent's: agent-delete.ts). */
24
32
  export const sdkRunKey = keyOf;
@@ -126,7 +134,7 @@ function checkToolParents(row, events) {
126
134
  /** The key a server signs its SDK runs' credentials with: derived from its seal key (seal-key.ts), which stays the
127
135
  * store's for its life, so adding, reordering or removing an API token (api-token.ts) never changes a run's credential. */
128
136
  export const sdkRunSecret = (sealKey) => createHmac("sha256", sealKey).update("agentrun sdk-run credentials").digest("base64url");
129
- const sign = (secret, runId) => `ar_sdk_${createHmac("sha256", secret).update(`sdk-run\0${runId}`).digest("base64url")}`;
137
+ const sign = (secret, runId, lane = "sdk") => `${lane === "cli" ? "ar_cli_run_" : "ar_sdk_"}${createHmac("sha256", secret).update(`${lane}-run\0${runId}`).digest("base64url")}`;
130
138
  const digest = (text) => createHash("sha256").update(text).digest();
131
139
  export class SdkRuns {
132
140
  store;
@@ -134,50 +142,61 @@ export class SdkRuns {
134
142
  secret;
135
143
  secrets;
136
144
  earlier;
145
+ lane;
137
146
  /** `earlier` are the keys credentials were once signed with (the server's API tokens, before `secret` was its seal
138
147
  * key's): a credential any of them signed is still taken, so a run started before an upgrade keeps its credential. */
139
- constructor(store, data, secret, secrets = () => [], earlier = []) {
148
+ constructor(store, data, secret, secrets = () => [], earlier = [], lane = "sdk") {
140
149
  this.store = store;
141
150
  this.data = data;
142
151
  this.secret = secret;
143
152
  this.secrets = secrets;
144
153
  this.earlier = earlier;
154
+ this.lane = lane;
145
155
  }
146
156
  token(runId) {
147
- return sign(this.secret, runId);
157
+ return sign(this.secret, runId, this.lane);
148
158
  }
149
159
  async authenticate(runId, token) {
150
160
  // Every key compared, on equal-length digests, with no early return.
151
161
  const given = digest(token);
152
162
  let ok = false;
153
163
  for (const key of [this.secret, ...this.earlier])
154
- ok = timingSafeEqual(given, digest(sign(key, runId))) || ok;
164
+ ok = timingSafeEqual(given, digest(sign(key, runId, this.lane))) || ok;
155
165
  if (!ok)
156
166
  throw new ApiError("unauthenticated", "This credential is scoped to a different SDK run.");
157
167
  await sdkInbox(this.store, runId);
158
168
  }
159
169
  clean(body, runId) {
160
- const redact = secretRedactor([...this.secrets(), ...(runId ? [this.secret, ...this.earlier].map((key) => sign(key, runId)) : [])]);
170
+ const redact = secretRedactor([...this.secrets(), ...(runId ? [this.secret, ...this.earlier].map((key) => sign(key, runId, this.lane)) : [])]);
161
171
  // Redact values structurally: a long string or encoded credential can be withheld whole,
162
172
  // so treating serialized JSON as prose could remove its delimiters and corrupt the envelope.
163
173
  return redactedOutput(body, redact.heldValues?.() ?? []);
164
174
  }
165
- async start(entry, body, deps, origin, compile, consoleOrigin) {
166
- only(body, ["runtime", "platform", "input", "instructions", "model", "workflow_tools", "workflow_adapters"]);
167
- const source = sdkBindingOf(body) ?? refuse("The SDK source needs a supported runtime; external requires a platform label of 1–80 characters without surrounding whitespace, controls or lone surrogates. Other runtimes do not take platform.");
168
- if (!SDK_WORKFLOW_RUNTIMES.includes(source.runtime) && (body.workflow_tools !== undefined || body.workflow_adapters !== undefined))
175
+ async start(entry, body, deps, origin, compile, consoleOrigin, cli) {
176
+ if (this.lane !== (cli ? "cli" : "sdk"))
177
+ refuse("The run must use its enrolled credential lane.");
178
+ only(body, cli ? ["runtime", "input", "instructions", "model"] : ["runtime", "platform", "input", "instructions", "model", "workflow_tools", "workflow_adapters"]);
179
+ const source = cli ? undefined : sdkBindingOf(body) ?? refuse("The SDK source needs a supported runtime; external requires a platform label of 1–80 characters without surrounding whitespace, controls or lone surrogates. Other runtimes do not take platform.");
180
+ if (source && !SDK_WORKFLOW_RUNTIMES.includes(source.runtime) && (body.workflow_tools !== undefined || body.workflow_adapters !== undefined))
169
181
  refuse("External runs receive owner corrections; workflow_tools and workflow_adapters require a backend workflow bridge.");
170
- const workflow = sdkWorkflowManifest(body.workflow_tools, body.workflow_adapters);
182
+ const workflow = cli ? undefined : sdkWorkflowManifest(body.workflow_tools, body.workflow_adapters);
171
183
  if (workflow && canonical(this.clean(workflow)) !== canonical(workflow))
172
184
  refuse("The workflow manifest contains a protected value; keep credentials in the backend.");
173
185
  const binding = sdkOf(entry.revision?.body);
174
- if (!binding || !entry.revision)
175
- throw new ApiError("agent_not_runnable", "This agent is not registered as a backend SDK agent.");
186
+ if (cli) {
187
+ if (cliLearningOf(entry.revision?.body)?.connection_id !== cli.connection_id)
188
+ refuse("CLI connection does not match the enrolled agent.");
189
+ if (body.runtime !== cli.runtime)
190
+ refuse("The CLI runtime must match the enrolled agent.");
191
+ }
192
+ else if (!binding || source.runtime !== binding.runtime || source.platform !== binding.platform) {
193
+ refuse("The SDK runtime and platform must match the registered agent.");
194
+ }
195
+ if (!entry.revision)
196
+ throw new ApiError("agent_not_runnable", "This agent has no current registered revision.");
176
197
  if (entry.agent.archivedAt !== null)
177
198
  throw new ApiError("agent_archived", "This SDK agent is archived.");
178
- if (source.runtime !== binding.runtime || source.platform !== binding.platform)
179
- refuse("The SDK runtime and platform must match the registered agent.");
180
- const input = text(body.input, "input"), instructions = text(body.instructions, "instructions");
199
+ const input = text(body.input, "input"), instructions = text(body.instructions, "instructions", cli ? CLI_POLICY_BYTES : TEXT_LIMIT);
181
200
  const model = body.model === undefined ? undefined : text(body.model, "model", 256);
182
201
  if (origin) {
183
202
  const known = await this.store.runOfOrigin(origin.key);
@@ -197,16 +216,17 @@ export class SdkRuns {
197
216
  // A runner keeps an SDK run's evidence and ends it: while every runner here refused to claim, the start is refused in
198
217
  // their words, as any start is (prepareLaunch), before the caller holds a receipt it would run on.
199
218
  await refuseWhileNoRunner(this.store.runners);
200
- const learning = await learningStartFor(deps, entry, pinned.revision, revisionBody, {
219
+ const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, learning: learningSettingForBody(revisionBody) }, {
201
220
  noWorkflows: !workflow,
202
221
  ...(compile.model ? { model: compile.model } : {}),
203
222
  });
204
223
  if (learning) {
205
- if (Buffer.byteLength(instructions) > INSTRUCTION_EVIDENCE_BYTES)
206
- refuse("Original SDK instructions exceed the 64 KiB learning evidence limit. Keep learning off or provide a complete policy within that limit.");
207
- if (!learning.model)
224
+ if (Buffer.byteLength(instructions) > (cli ? CLI_POLICY_BYTES : INSTRUCTION_EVIDENCE_BYTES))
225
+ refuse(cli ? "Original CLI instructions exceed the 256 KiB evidence limit. Keep capture off or provide a complete policy within that limit." : "Original SDK instructions exceed the 64 KiB learning evidence limit. Keep learning off or provide a complete policy within that limit.");
226
+ if (!cli && !learning.model)
208
227
  throw new ApiError("agent_not_runnable", "Self-improving SDK runs need a server model and its model key to compile workflows. Configure the model or turn self-improving off.");
209
- await compile.check(learning.model);
228
+ if (!cli)
229
+ await compile.check(learning.model);
210
230
  if (learning.seedFailed)
211
231
  throw new ApiError("unavailable", "The learning seed could not be read. Retry after restoring the agent learning folder.");
212
232
  }
@@ -232,13 +252,13 @@ export class SdkRuns {
232
252
  input: { content: cleanedInput },
233
253
  title: cleanedInput.trim().replace(/\s+/g, " ").slice(0, 80),
234
254
  place: { mode: "runner" },
235
- harness: "sdk",
236
- sdk: {
237
- ...binding,
238
- ...workflow,
239
- instructions: cleaned.instructions,
240
- ...(cleaned.model ? { model: cleaned.model } : {}),
241
- },
255
+ ...(cli ? {
256
+ harness: "cli",
257
+ cli_learning: { ...cli, instructions: cleaned.instructions, policy_complete: cli.policy_complete && cleaned.instructions === instructions, ...(cleaned.model ? { model: cleaned.model } : {}) },
258
+ } : {
259
+ harness: "sdk",
260
+ sdk: { ...binding, ...workflow, instructions: cleaned.instructions, ...(cleaned.model ? { model: cleaned.model } : {}) },
261
+ }),
242
262
  ...(learning ? { learning: { ...learning, workflows: workflows.map((flow) => flow.name) } } : {}),
243
263
  };
244
264
  const now = Date.now();
@@ -246,11 +266,12 @@ export class SdkRuns {
246
266
  await this.store.settings.put(keyOf(runId), {
247
267
  run_id: runId,
248
268
  created_at: now,
249
- expires_at: now + 3_600_000,
269
+ expires_at: now + (cli ? 86_400_000 : 3_600_000),
250
270
  batches: [],
251
271
  learning_workflows: workflows,
252
272
  ...(check ? { learning_check: check } : {}),
253
273
  ...(redacted ? { check_redacted: true } : {}),
274
+ ...(cli && cleanedInput !== input ? { evidence_incomplete: true } : {}),
254
275
  });
255
276
  await this.store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: entry.revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) });
256
277
  }
@@ -263,6 +284,16 @@ export class SdkRuns {
263
284
  if (record?.decided === "replaying" && record.replay_id === check.id)
264
285
  await releaseSdkCheck(checkDeps, record, "its start could not be admitted", false).catch(() => undefined);
265
286
  }
287
+ // Two source hooks may admit the same immutable prompt window under different transport keys.
288
+ // The store's origin constraint chooses one; recover its receipt without creating another run.
289
+ if (origin) {
290
+ const known = await this.store.runOfOrigin(origin.key);
291
+ if (known) {
292
+ if (known.fingerprint !== origin.fingerprint)
293
+ throw new ApiError("idempotency_mismatch", "The key was used with another SDK start.");
294
+ return this.receipt(known.runId, consoleOrigin);
295
+ }
296
+ }
266
297
  throw error;
267
298
  }
268
299
  return this.receipt(runId, consoleOrigin);
@@ -354,9 +385,16 @@ export class SdkRuns {
354
385
  refuse("Supply a positive sequence and at most 100 events.");
355
386
  if (Buffer.byteLength(JSON.stringify(body)) > BATCH_LIMIT)
356
387
  throw new ApiError("payload_too_large", "An SDK event batch exceeds 256 KB.");
388
+ const launch = (await this.store.runs.launch(runId)).body;
357
389
  const events = body.events.map((value) => {
358
390
  if (!isObject(value))
359
391
  return refuse("An SDK event must be an object.");
392
+ if (value.type === "message" && launch.cli_learning) {
393
+ only(value, ["type", "role", "text"]);
394
+ if (value.role !== "user" && value.role !== "assistant")
395
+ return refuse("A dialogue message role must be user or assistant.");
396
+ return { type: "message", role: value.role, text: text(value.text, "text") };
397
+ }
360
398
  if (value.type === "text") {
361
399
  only(value, ["type", "text"]);
362
400
  return { type: "text", text: text(value.text, "text") };
@@ -434,25 +472,56 @@ export class SdkRuns {
434
472
  for (const check of checks)
435
473
  if (!row.learning_check || check.id !== row.learning_check.id || check.digest !== row.learning_check.digest)
436
474
  refuse("The workflow check must name this SDK run's reserved candidate.");
437
- return { ...row, batches: [...row.batches, batch], ...(checkRedacted ? { check_redacted: true } : {}) };
475
+ return { ...row, batches: [...row.batches, batch], ...(checkRedacted ? { check_redacted: true, ...(launch.cli_learning ? { evidence_incomplete: true } : {}) } : {}) };
438
476
  }, EVIDENCE_LIMIT);
439
477
  return { accepted: true };
440
478
  }
441
479
  async complete(runId, body) {
442
- only(body, ["status", "answer", "error", "model", "session_id", "usage", "evidence_complete"]);
480
+ const launch = (await this.store.runs.launch(runId)).body;
481
+ only(body, ["status", "answer", "error", "model", "session_id", "usage", "evidence_complete", ...(launch.cli_learning ? ["seed_observed", "seed_revision"] : []), ...(launch.cli_learning?.runtime === "claude-code-cli" ? ["source_policy"] : [])]);
482
+ if (body.seed_observed !== undefined && typeof body.seed_observed !== "boolean")
483
+ refuse("seed_observed must be a boolean.");
484
+ if (body.seed_observed === true && (!launch.learning?.seed || !launch.learning.section.trim() || body.seed_revision !== launch.learning.seed))
485
+ refuse("An observed seed requires pinned owner corrections and the matching revision from this prompt window receipt.");
443
486
  if (body.evidence_complete !== undefined && typeof body.evidence_complete !== "boolean")
444
487
  refuse("evidence_complete must be a boolean.");
445
488
  if (!["completed", "failed", "cancelled"].includes(String(body.status)))
446
489
  refuse("SDK completion status is completed, failed or cancelled.");
447
- const completion = this.clean({
490
+ if (launch.cli_learning && body.session_id !== undefined && body.session_id !== launch.cli_learning.session_id)
491
+ refuse("The completion session_id must match this CLI prompt window.");
492
+ let sourcePolicy;
493
+ if (body.source_policy !== undefined) {
494
+ if (!isObject(body.source_policy))
495
+ refuse("source_policy must be the current Claude prompt snapshot.");
496
+ const policy = body.source_policy;
497
+ only(policy, ["instructions", "complete"]);
498
+ if (typeof policy.complete !== "boolean")
499
+ refuse("source_policy.complete must be explicit.");
500
+ const instructions = text(policy.instructions, "source_policy.instructions", CLI_POLICY_BYTES);
501
+ if (Buffer.byteLength(instructions) > CLI_POLICY_BYTES)
502
+ refuse("The CLI source policy exceeds 256 KiB; mark capture incomplete rather than truncating it.");
503
+ sourcePolicy = { instructions, complete: policy.complete };
504
+ }
505
+ const submitted = {
448
506
  status: body.status,
507
+ ...(sourcePolicy ? { source_policy: sourcePolicy } : {}),
449
508
  answer: text(body.answer, "answer"),
450
509
  ...(body.evidence_complete !== undefined ? { evidence_complete: body.evidence_complete } : {}),
510
+ ...(body.seed_observed !== undefined ? { seed_observed: body.seed_observed } : {}),
511
+ ...(body.seed_revision !== undefined ? { seed_revision: text(body.seed_revision, "seed_revision", 128) } : {}),
451
512
  ...(body.error !== undefined ? { error: text(body.error, "error", 8000) } : {}),
452
513
  ...(body.model !== undefined ? { model: text(body.model, "model", 256) } : {}),
453
514
  ...(body.session_id !== undefined ? { session_id: text(body.session_id, "session_id", 256) } : {}),
454
515
  ...(body.usage !== undefined ? { usage: usageOf(body.usage) } : {}),
455
- }, runId);
516
+ };
517
+ const completion = this.clean(submitted, runId);
518
+ // Source policy has its own completeness flag; redacted execution evidence cannot
519
+ // be represented as complete even when the source explicitly claimed it was.
520
+ const { source_policy: _submittedPolicy, ...submittedEvidence } = submitted;
521
+ const { source_policy: _cleanedPolicy, ...cleanedEvidence } = completion;
522
+ const evidenceIncomplete = !!launch.cli_learning && canonical(submittedEvidence) !== canonical(cleanedEvidence);
523
+ if (completion.source_policy && completion.source_policy.instructions !== sourcePolicy.instructions)
524
+ completion.source_policy.complete = false;
456
525
  const known = (await sdkInbox(this.store, runId)).completion;
457
526
  if (known) {
458
527
  if (canonical(known) !== canonical(completion))
@@ -467,7 +536,7 @@ export class SdkRuns {
467
536
  return row;
468
537
  }
469
538
  writableInbox(row);
470
- return { ...row, completion, ...(completion.answer !== body.answer ? { check_redacted: true } : {}) };
539
+ return { ...row, completion, ...(evidenceIncomplete ? { evidence_incomplete: true } : {}), ...(completion.answer !== body.answer ? { check_redacted: true } : {}) };
471
540
  });
472
541
  return { accepted: true };
473
542
  }
package/dist/server.d.ts CHANGED
@@ -92,6 +92,9 @@ export type ServeOptions = {
92
92
  * test's fakes, for the server's own Archil calls (a launch's disk read, the settings' test, an agent's disk removed,
93
93
  * a deleted agent's run folder removed from a disk its launch named). */
94
94
  archilControl?: ArchilRoutesOptions["control"];
95
+ /** How long an uploaded file no run names is kept on the uploads disk in Mode 2 (uploads-archil.ts): a duration such
96
+ * as 7d, or "off". Default AGENTRUN_UPLOAD_RETENTION, else 7d. */
97
+ uploadRetention?: string;
95
98
  /** Another Composio than the real one, and its fetch: a test's fake, for the Composio preset's calls (composio-preset.ts). */
96
99
  composioControl?: ComposioControl;
97
100
  /** With `faux` only: a module whose default export gives the `browser` tool's `{ provider, driver }` (the tests' fake