@tangle-network/agent-runtime 0.293.2 → 0.294.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 (47) hide show
  1. package/dist/{activation-DKZZAHVn.js → activation-BKz1t1Qb.js} +2 -2
  2. package/dist/{activation-DKZZAHVn.js.map → activation-BKz1t1Qb.js.map} +1 -1
  3. package/dist/agent.d.ts +1 -1
  4. package/dist/agent.js +2 -2
  5. package/dist/{coordination-driver-DSaxqusu.js → coordination-driver-BpEJv7GR.js} +2 -2
  6. package/dist/{coordination-driver-DSaxqusu.js.map → coordination-driver-BpEJv7GR.js.map} +1 -1
  7. package/dist/{delegate-D2I093YC.js → delegate-DEP51NR7.js} +2 -2
  8. package/dist/{delegate-D2I093YC.js.map → delegate-DEP51NR7.js.map} +1 -1
  9. package/dist/durable.d.ts +1 -1
  10. package/dist/durable.js +2 -2
  11. package/dist/{graph-zehf9BmZ.js → graph-oFWfYVpn.js} +4 -4
  12. package/dist/{graph-zehf9BmZ.js.map → graph-oFWfYVpn.js.map} +1 -1
  13. package/dist/{improvement-cycle-BZTq2xAb.js → improvement-cycle-CBAuTq3p.js} +3 -3
  14. package/dist/{improvement-cycle-BZTq2xAb.js.map → improvement-cycle-CBAuTq3p.js.map} +1 -1
  15. package/dist/{index-DZqkIP6a.d.ts → index-D25LzHVg.d.ts} +92 -4
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +7 -7
  18. package/dist/intelligence.js +4 -4
  19. package/dist/kernel.d.ts +2 -2
  20. package/dist/kernel.js +9 -9
  21. package/dist/{loop-runner-bin-BUldbpz8.d.ts → loop-runner-bin-BxwHrpyo.d.ts} +2 -2
  22. package/dist/{loop-runner-bin-oVxfhyGL.js → loop-runner-bin-hjelfQvP.js} +3 -3
  23. package/dist/{loop-runner-bin-oVxfhyGL.js.map → loop-runner-bin-hjelfQvP.js.map} +1 -1
  24. package/dist/loop-runner-bin.d.ts +1 -1
  25. package/dist/loop-runner-bin.js +1 -1
  26. package/dist/mcp/bin.js +3 -3
  27. package/dist/mcp/index.d.ts +1 -1
  28. package/dist/mcp/index.js +4 -4
  29. package/dist/{provision-supervisor-b8XxFaiS.js → provision-supervisor-CIwZLCGR.js} +3 -3
  30. package/dist/{provision-supervisor-b8XxFaiS.js.map → provision-supervisor-CIwZLCGR.js.map} +1 -1
  31. package/dist/{runtime-DMrS3EkC.js → runtime-B_OdIcAW.js} +356 -33
  32. package/dist/runtime-B_OdIcAW.js.map +1 -0
  33. package/dist/{search-method-Cy7fHmsS.js → search-method-3EtnGKdL.js} +2 -2
  34. package/dist/{search-method-Cy7fHmsS.js.map → search-method-3EtnGKdL.js.map} +1 -1
  35. package/dist/{server-nZw7hk9T.js → server-DgEDz4Rn.js} +3 -3
  36. package/dist/{server-nZw7hk9T.js.map → server-DgEDz4Rn.js.map} +1 -1
  37. package/dist/{supervise-CCEhJufC.js → supervise-Cu0yOTkc.js} +3 -3
  38. package/dist/{supervise-CCEhJufC.js.map → supervise-Cu0yOTkc.js.map} +1 -1
  39. package/dist/{supervisor-Ca4b5Lt7.js → supervisor-B-UbeBqD.js} +2 -4
  40. package/dist/{supervisor-Ca4b5Lt7.js.map → supervisor-B-UbeBqD.js.map} +1 -1
  41. package/dist/testing.d.ts +1 -1
  42. package/dist/testing.js +12 -12
  43. package/dist/tui/index.d.ts +1 -1
  44. package/dist/tui/index.js +1 -1
  45. package/package.json +1 -1
  46. package/skills/profile-authoring/SKILL.md +3 -0
  47. package/dist/runtime-DMrS3EkC.js.map +0 -1
@@ -1,24 +1,24 @@
1
- import { Ai as writeAllBytes, Da as zeroSpend, Dn as runBrainLoop, Dt as rollingDispatch, En as routerBrain, Fa as armDeadlineTimer, Fn as createPushTraceSource, Ft as createWorktreeCliExecutor, G as settledToIteration, Gn as assertContentAddress, Hn as InMemoryResultBlobStore, Kn as encodeResultBlob, M as withDriverExecutor, Mt as createExecutor, Nt as createExecutorRegistry, O as verdictFromJudgeScore, Oi as prepareJsonlAppend, Or as contentAddress, Qi as detachedSnapshot, Sa as stringifySafe, Tn as readPromptOptions, Un as InMemorySpawnJournal, Wn as SpawnEventIndex, Xi as executableAgentSpecSnapshot, Yi as executableAgentProfileSnapshot, Zi as detachedFrozen, _ as CheckUnavailableError, _a as hasCompleteCacheBreakdown, ba as randomSuffix, bn as probeSandboxCapabilities, er as isTraceAnalysisStore, gn as defaultSelectWinner, ha as cloneSpend, ki as readCommittedJsonLines, la as notifySandboxEventObserver, ma as chargedTokens, pa as addSpend, qn as insideCursorNamespace, r as createSupervisor, va as isAbortError, vn as runAgentRounds, wn as assertBoxlessPromptOptions, xa as sleep, yn as createSandboxLineage } from "./supervisor-Ca4b5Lt7.js";
1
+ import { Ai as writeAllBytes, Da as zeroSpend, Dn as runBrainLoop, Dt as rollingDispatch, En as routerBrain, Fa as armDeadlineTimer, Fn as createPushTraceSource, Ft as createWorktreeCliExecutor, G as settledToIteration, Gn as assertContentAddress, Hn as InMemoryResultBlobStore, Kn as encodeResultBlob, M as withDriverExecutor, Mt as createExecutor, Nt as createExecutorRegistry, O as verdictFromJudgeScore, Oi as prepareJsonlAppend, Or as contentAddress, Qi as detachedSnapshot, Sa as stringifySafe, Tn as readPromptOptions, Un as InMemorySpawnJournal, Wn as SpawnEventIndex, Xi as executableAgentSpecSnapshot, Yi as executableAgentProfileSnapshot, Zi as detachedFrozen, _ as CheckUnavailableError, _a as hasCompleteCacheBreakdown, ba as randomSuffix, bn as probeSandboxCapabilities, er as isTraceAnalysisStore, gn as defaultSelectWinner, ha as cloneSpend, ki as readCommittedJsonLines, la as notifySandboxEventObserver, ma as chargedTokens, pa as addSpend, qn as insideCursorNamespace, r as createSupervisor, va as isAbortError, vn as runAgentRounds, wn as assertBoxlessPromptOptions, xa as sleep, yn as createSandboxLineage } from "./supervisor-B-UbeBqD.js";
2
2
  import { i as ConfigError, m as ValidationError, n as AnalystError, s as PlannerError } from "./errors-DodWX-cb.js";
3
- import { Q as sample, X as refine, Z as runAgentic, c as reconcileInterruptedSearchCalls, ct as strategyAuthorMethod, et as ObservationError, it as profileChatClient, nt as observe, o as dedicatedLane, r as runtimeShipDecision, rt as renderReport, u as searchExecutor } from "./search-method-Cy7fHmsS.js";
3
+ import { Q as sample, X as refine, Z as runAgentic, c as reconcileInterruptedSearchCalls, ct as strategyAuthorMethod, et as ObservationError, it as profileChatClient, nt as observe, o as dedicatedLane, r as runtimeShipDecision, rt as renderReport, u as searchExecutor } from "./search-method-3EtnGKdL.js";
4
4
  import { c as profileModelExecutionSettings, i as concreteModelId, l as profileProviderModel, o as enforceTokenLimits, p as canonicalObservedModelParts, t as assertExecutableAgentProfile } from "./model-policy-DydyWTQg.js";
5
5
  import { A as sha256Bytes$1, O as immutableCandidateValue, f as WorkspaceScanLimitError, h as captureMaterializedWorkspace, w as canonicalCandidateDigest$1 } from "./workspace-archive-MhowMCmp.js";
6
6
  import { i as notifyRuntimeHookEvent } from "./runtime-hooks-tXpAarhW.js";
7
7
  import { i as redactProtectedValue, r as redactProtectedReason } from "./protected-redaction-DylCC_ot.js";
8
- import { S as foldCoordinationRecords, y as createInMemoryRunContext } from "./coordination-driver-DSaxqusu.js";
9
- import { C as gateOnDeliverable, r as supervise, w as mapExecutorResult } from "./supervise-CCEhJufC.js";
8
+ import { S as foldCoordinationRecords, y as createInMemoryRunContext } from "./coordination-driver-BpEJv7GR.js";
9
+ import { C as gateOnDeliverable, r as supervise, w as mapExecutorResult } from "./supervise-Cu0yOTkc.js";
10
10
  import "./run-layout-DSCWdbX2.js";
11
- import "./provision-supervisor-b8XxFaiS.js";
12
- import "./delegate-D2I093YC.js";
13
- import "./graph-zehf9BmZ.js";
11
+ import "./provision-supervisor-CIwZLCGR.js";
12
+ import "./delegate-DEP51NR7.js";
13
+ import "./graph-oFWfYVpn.js";
14
14
  import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, sha256Bytes, validateAgentProfileSecurity } from "@tangle-network/agent-interface";
15
15
  import { CODING_HARNESSES, DEFAULT_TRACE_ANALYST_KINDS, InMemoryTraceStore, OUTPUT_VALUE, benjaminiHochberg, buildTrajectory, computeFindingId as computeFindingId$1, confidenceInterval, createTraceAnalyst, expandProfileAxes, makeFinding as makeFinding$1, pairedBootstrap, paretoFrontier, wilcoxonSignedRank, wilson } from "@tangle-network/agent-eval";
16
16
  import { createAgentRunOutcomeTracker } from "@tangle-network/sandbox/runtime";
17
- import { createHash, randomUUID } from "node:crypto";
17
+ import { createHash, createHmac, randomUUID } from "node:crypto";
18
18
  import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
19
19
  import { appendFileSync, chmodSync, constants, copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readlinkSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
20
20
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
21
- import { chmod, link, lstat, mkdir, mkdtemp, open, opendir, readFile, readdir, readlink, realpath, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
21
+ import { chmod, link, lstat, mkdir, mkdtemp, open, opendir, readFile, readdir, readlink, realpath, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
22
22
  import { tmpdir } from "node:os";
23
23
  import { isDeepStrictEqual, promisify } from "node:util";
24
24
  import { redact } from "@tangle-network/agent-eval/traces";
@@ -4960,8 +4960,12 @@ function requireSpend(rolled, id, root) {
4960
4960
  }
4961
4961
  //#endregion
4962
4962
  //#region src/runtime/private-cas.ts
4963
- const DIGEST = /^sha256:([0-9a-f]{64})$/u;
4963
+ const DIGEST$1 = /^sha256:([0-9a-f]{64})$/u;
4964
+ const HEX = /^[0-9a-f]{64}$/u;
4965
+ const SHARD = /^[0-9a-f]{2}$/u;
4964
4966
  const SAFE_NAMESPACE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/u;
4967
+ const RECEIPT_SCHEMA = "agent-runtime.private-cas-durable-receipt.v1";
4968
+ const DURABLE_ATTEMPTS = 3;
4965
4969
  async function realDirectory(path) {
4966
4970
  const entry = await lstat(path);
4967
4971
  if (!entry.isDirectory() || entry.isSymbolicLink()) throw new Error(`private CAS directory is not a real directory: ${path}`);
@@ -4980,21 +4984,216 @@ async function checkDirectories(path, create) {
4980
4984
  await realDirectory(current);
4981
4985
  }
4982
4986
  }
4983
- /** Private host-local content-addressed storage scoped to one recorded run identity. */
4984
- function createPrivateCasArtifactPort(root, namespace) {
4987
+ const missing = (error) => error?.code === "ENOENT";
4988
+ const message = (error) => error instanceof Error ? error.message : String(error);
4989
+ const sha256 = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
4990
+ async function syncDirectory(directory) {
4991
+ const handle = await open(directory, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
4992
+ try {
4993
+ await handle.sync();
4994
+ } finally {
4995
+ await handle.close();
4996
+ }
4997
+ }
4998
+ /** Read one local object, or undefined when the host no longer holds it. */
4999
+ async function readLocal(path) {
5000
+ let file;
5001
+ try {
5002
+ file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
5003
+ } catch (error) {
5004
+ if (missing(error)) return void 0;
5005
+ throw error;
5006
+ }
5007
+ try {
5008
+ return await file.readFile();
5009
+ } finally {
5010
+ await file.close();
5011
+ }
5012
+ }
5013
+ /**
5014
+ * Private content-addressed storage scoped to one recorded run identity.
5015
+ *
5016
+ * Bytes are written to the host first. With a durable store, every object is also copied off the
5017
+ * host as it is written, and `localBudgetBytes` bounds what the host keeps: an object's local copy
5018
+ * is deleted only after its durable receipt exists, and reads fall back to the durable store.
5019
+ */
5020
+ function createPrivateCasArtifactPort(root, namespace, options = {}) {
4985
5021
  if (!isAbsolute(root)) throw new Error("private CAS root must be absolute");
4986
5022
  if (!SAFE_NAMESPACE.test(namespace) || namespace === "." || namespace === "..") throw new Error("private CAS namespace must be one safe identifier");
5023
+ const { durable, localBudgetBytes } = options;
5024
+ if (localBudgetBytes !== void 0 && (durable === void 0 || !Number.isSafeInteger(localBudgetBytes) || localBudgetBytes < 0)) throw new Error("private CAS localBudgetBytes needs a durable store and a non-negative integer");
4987
5025
  const store = join(resolve(root), "sha256");
4988
- const destination = (digest) => {
4989
- const match = DIGEST.exec(digest);
5026
+ const receipts = join(resolve(root), "durable", "sha256");
5027
+ const hexOf = (digest) => {
5028
+ const match = DIGEST$1.exec(digest);
4990
5029
  if (!match) throw new Error("private CAS digest must be sha256:<64 lowercase hex>");
4991
- return join(store, match[1].slice(0, 2), match[1]);
5030
+ return match[1];
5031
+ };
5032
+ const destination = (digest) => {
5033
+ const hex = hexOf(digest);
5034
+ return join(store, hex.slice(0, 2), hex);
5035
+ };
5036
+ const hasReceipt = async (hex) => {
5037
+ try {
5038
+ return (await lstat(join(receipts, hex))).isFile();
5039
+ } catch (error) {
5040
+ if (missing(error)) return false;
5041
+ throw error;
5042
+ }
5043
+ };
5044
+ const writeReceipt = async (digest, byteLength) => {
5045
+ await checkDirectories(receipts, true);
5046
+ const hex = hexOf(digest);
5047
+ const temporary = join(receipts, `.${hex}.${randomUUID()}.tmp`);
5048
+ const file = await open(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
5049
+ try {
5050
+ await file.writeFile(`${JSON.stringify({
5051
+ schema: RECEIPT_SCHEMA,
5052
+ location: durable.location,
5053
+ namespace,
5054
+ digest,
5055
+ byteLength,
5056
+ storedAt: (/* @__PURE__ */ new Date()).toISOString()
5057
+ })}\n`);
5058
+ await file.sync();
5059
+ } finally {
5060
+ await file.close();
5061
+ }
5062
+ await rename(temporary, join(receipts, hex));
5063
+ await syncDirectory(receipts);
5064
+ };
5065
+ const storeDurably = async (digest, bytes, signal) => {
5066
+ let failure;
5067
+ for (let attempt = 1; attempt <= DURABLE_ATTEMPTS; attempt++) {
5068
+ signal?.throwIfAborted();
5069
+ try {
5070
+ await durable.put({
5071
+ namespace,
5072
+ digest,
5073
+ bytes,
5074
+ ...signal === void 0 ? {} : { signal }
5075
+ });
5076
+ await writeReceipt(digest, bytes.byteLength);
5077
+ return;
5078
+ } catch (error) {
5079
+ failure = error;
5080
+ if (signal?.aborted) throw error;
5081
+ if (attempt < DURABLE_ATTEMPTS) await new Promise((settle) => setTimeout(settle, 1e3 * 4 ** (attempt - 1)));
5082
+ }
5083
+ }
5084
+ throw failure;
5085
+ };
5086
+ const localObjects = async () => {
5087
+ let shards;
5088
+ try {
5089
+ shards = await readdir(store);
5090
+ } catch (error) {
5091
+ if (missing(error)) return [];
5092
+ throw error;
5093
+ }
5094
+ const objects = [];
5095
+ for (const shard of shards.filter((name) => SHARD.test(name))) for (const hex of await readdir(join(store, shard))) {
5096
+ if (!HEX.test(hex) || hex.slice(0, 2) !== shard) continue;
5097
+ const path = join(store, shard, hex);
5098
+ try {
5099
+ const entry = await lstat(path);
5100
+ if (entry.isFile()) objects.push({
5101
+ hex,
5102
+ path,
5103
+ size: entry.size,
5104
+ modifiedMs: entry.mtimeMs
5105
+ });
5106
+ } catch (error) {
5107
+ if (!missing(error)) throw error;
5108
+ }
5109
+ }
5110
+ return objects;
5111
+ };
5112
+ const sweep = async (signal) => {
5113
+ const objects = await localObjects();
5114
+ const pending = [];
5115
+ let uploaded = 0;
5116
+ let refusal;
5117
+ const durableHex = /* @__PURE__ */ new Set();
5118
+ for (const object of objects) {
5119
+ if (await hasReceipt(object.hex)) {
5120
+ durableHex.add(object.hex);
5121
+ continue;
5122
+ }
5123
+ if (durable === void 0) continue;
5124
+ const digest = `sha256:${object.hex}`;
5125
+ if (refusal !== void 0) {
5126
+ pending.push({
5127
+ digest,
5128
+ error: `not attempted after an earlier refusal: ${refusal}`
5129
+ });
5130
+ continue;
5131
+ }
5132
+ const bytes = await readLocal(object.path);
5133
+ if (bytes === void 0) continue;
5134
+ if (sha256(bytes) !== digest) {
5135
+ pending.push({
5136
+ digest,
5137
+ error: "local object failed digest verification; it stays on the host"
5138
+ });
5139
+ continue;
5140
+ }
5141
+ try {
5142
+ await storeDurably(digest, bytes, signal);
5143
+ durableHex.add(object.hex);
5144
+ uploaded++;
5145
+ } catch (error) {
5146
+ if (signal?.aborted) throw error;
5147
+ refusal = message(error);
5148
+ pending.push({
5149
+ digest,
5150
+ error: refusal
5151
+ });
5152
+ }
5153
+ }
5154
+ let localBytes = objects.reduce((total, object) => total + object.size, 0);
5155
+ let evicted = 0;
5156
+ if (localBudgetBytes !== void 0) for (const object of [...objects].sort((a, b) => a.modifiedMs - b.modifiedMs)) {
5157
+ if (localBytes <= localBudgetBytes) break;
5158
+ if (!durableHex.has(object.hex) || !await hasReceipt(object.hex)) continue;
5159
+ try {
5160
+ await unlink(object.path);
5161
+ } catch (error) {
5162
+ if (!missing(error)) throw error;
5163
+ }
5164
+ localBytes -= object.size;
5165
+ evicted++;
5166
+ }
5167
+ let receiptCount = 0;
5168
+ try {
5169
+ receiptCount = (await readdir(receipts)).filter((name) => HEX.test(name)).length;
5170
+ } catch (error) {
5171
+ if (!missing(error)) throw error;
5172
+ }
5173
+ return {
5174
+ durable: receiptCount,
5175
+ uploaded,
5176
+ pending,
5177
+ evicted,
5178
+ localObjects: objects.length - evicted,
5179
+ localBytes
5180
+ };
5181
+ };
5182
+ let passes = Promise.resolve();
5183
+ const offload = (signal) => {
5184
+ const pass = passes.then(() => sweep(signal));
5185
+ passes = pass.catch(() => void 0);
5186
+ return pass;
5187
+ };
5188
+ const verified = (bytes, ref) => {
5189
+ if (sha256(bytes) !== ref.sha256 || bytes.byteLength !== ref.byteLength) throw new Error("private CAS object failed digest or length verification");
5190
+ return bytes;
4992
5191
  };
4993
5192
  const port = {
4994
5193
  async put({ bytes, signal }) {
4995
5194
  signal?.throwIfAborted();
4996
- const sha = createHash("sha256").update(bytes).digest("hex");
4997
- const digest = `sha256:${sha}`;
5195
+ const digest = sha256(bytes);
5196
+ const sha = hexOf(digest);
4998
5197
  const path = destination(digest);
4999
5198
  const directory = join(store, sha.slice(0, 2));
5000
5199
  await checkDirectories(directory, true);
@@ -5013,12 +5212,7 @@ function createPrivateCasArtifactPort(root, namespace) {
5013
5212
  } catch (error) {
5014
5213
  if (error.code !== "EEXIST") throw error;
5015
5214
  }
5016
- const dir = await open(directory, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
5017
- try {
5018
- await dir.sync();
5019
- } finally {
5020
- await dir.close();
5021
- }
5215
+ await syncDirectory(directory);
5022
5216
  } finally {
5023
5217
  await unlink(temporary).catch(() => void 0);
5024
5218
  }
@@ -5032,21 +5226,33 @@ function createPrivateCasArtifactPort(root, namespace) {
5032
5226
  byteLength: bytes.byteLength
5033
5227
  };
5034
5228
  await port.read(ref);
5229
+ if (durable !== void 0) {
5230
+ if (!await hasReceipt(sha)) await storeDurably(digest, bytes, signal).catch(() => void 0);
5231
+ await offload(signal);
5232
+ }
5035
5233
  return ref;
5036
5234
  },
5037
5235
  async read(ref) {
5038
5236
  if (ref.locator.kind !== "private-cas" || ref.locator.namespace !== namespace || ref.locator.digest !== ref.sha256) throw new Error("private CAS locator does not match its digest and namespace");
5039
5237
  const path = destination(ref.sha256);
5040
- await checkDirectories(join(store, DIGEST.exec(ref.sha256)[1].slice(0, 2)), false);
5041
- const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
5238
+ const shard = join(store, hexOf(ref.sha256).slice(0, 2));
5239
+ let local;
5042
5240
  try {
5043
- const bytes = await file.readFile();
5044
- if (`sha256:${createHash("sha256").update(bytes).digest("hex")}` !== ref.sha256 || bytes.byteLength !== ref.byteLength) throw new Error("private CAS object failed digest or length verification");
5045
- return bytes;
5046
- } finally {
5047
- await file.close();
5241
+ await checkDirectories(shard, false);
5242
+ local = await readLocal(path);
5243
+ } catch (error) {
5244
+ if (!missing(error)) throw error;
5048
5245
  }
5049
- }
5246
+ if (local !== void 0) return verified(local, ref);
5247
+ if (durable === void 0) throw new Error(`private CAS object is not on this host: ${ref.sha256}`);
5248
+ const stored = await durable.get({
5249
+ namespace,
5250
+ digest: ref.sha256
5251
+ });
5252
+ if (stored === void 0) throw new Error(`private CAS object is neither on this host nor in ${durable.location}: ${ref.sha256}`);
5253
+ return verified(stored, ref);
5254
+ },
5255
+ offload
5050
5256
  };
5051
5257
  return port;
5052
5258
  }
@@ -5265,6 +5471,123 @@ function printBenchmarkReport(report) {
5265
5471
  }
5266
5472
  }
5267
5473
  //#endregion
5474
+ //#region src/runtime/s3-private-cas-store.ts
5475
+ const DIGEST = /^sha256:([0-9a-f]{64})$/u;
5476
+ const BUCKET = /^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/u;
5477
+ const PREFIX = /^(?:[A-Za-z0-9._-]+\/)*$/u;
5478
+ const NAMESPACE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/u;
5479
+ const EMPTY_PAYLOAD = createHash("sha256").update("").digest("hex");
5480
+ const CONTENT_TYPE = "application/octet-stream";
5481
+ const METADATA_DIGEST = "x-amz-meta-sha256";
5482
+ const hex = (value) => createHash("sha256").update(value).digest("hex");
5483
+ const hmac = (key, value) => createHmac("sha256", key).update(value).digest();
5484
+ const encode = (segment) => encodeURIComponent(segment).replace(/[!'()*]/gu, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
5485
+ /**
5486
+ * Durable private CAS bytes in one S3-compatible bucket under `<prefix><namespace>/sha256/<hex>`.
5487
+ *
5488
+ * Every write declares its SHA-256 as the signed payload hash, so the store refuses bytes that
5489
+ * do not match the digest. A write is confirmed by reading back the object's length and digest
5490
+ * metadata. Reads return raw bytes; the private CAS port verifies them.
5491
+ */
5492
+ function createS3PrivateCasStore(options) {
5493
+ const endpoint = new URL(options.endpoint);
5494
+ if (endpoint.protocol !== "https:" || endpoint.username || endpoint.password || endpoint.search || endpoint.hash || endpoint.pathname !== "/" && endpoint.pathname !== "") throw new Error("S3 private CAS endpoint must be a bare https origin");
5495
+ if (!BUCKET.test(options.bucket)) throw new Error("S3 private CAS bucket name is invalid");
5496
+ const prefix = options.prefix ?? "";
5497
+ if (!PREFIX.test(prefix)) throw new Error("S3 private CAS prefix must be empty or end in /");
5498
+ if (!options.accessKeyId || !options.secretAccessKey) throw new Error("S3 private CAS needs an access key id and secret");
5499
+ const region = options.region ?? "auto";
5500
+ const timeoutMs = options.timeoutMs ?? 12e4;
5501
+ const send = options.fetch ?? fetch;
5502
+ const key = (namespace, digest) => {
5503
+ if (!NAMESPACE.test(namespace)) throw new Error("S3 private CAS namespace is invalid");
5504
+ const match = DIGEST.exec(digest);
5505
+ if (!match) throw new Error("S3 private CAS digest must be sha256:<64 lowercase hex>");
5506
+ return `${prefix}${namespace}/sha256/${match[1]}`;
5507
+ };
5508
+ const request = async (method, objectKey, { body, payloadHash = EMPTY_PAYLOAD, headers = {}, signal } = {}) => {
5509
+ const path = `/${[options.bucket, ...objectKey.split("/")].map(encode).join("/")}`;
5510
+ const url = new URL(path, endpoint);
5511
+ const amzDate = (/* @__PURE__ */ new Date()).toISOString().replace(/[:-]|\.\d{3}/gu, "");
5512
+ const day = amzDate.slice(0, 8);
5513
+ const signed = {
5514
+ host: url.host,
5515
+ "x-amz-content-sha256": payloadHash,
5516
+ "x-amz-date": amzDate,
5517
+ ...Object.fromEntries(Object.entries(headers).map(([name, value]) => [name.toLowerCase(), value]))
5518
+ };
5519
+ const names = Object.keys(signed).sort();
5520
+ const canonical = [
5521
+ method,
5522
+ path,
5523
+ "",
5524
+ names.map((name) => `${name}:${signed[name].trim()}\n`).join(""),
5525
+ names.join(";"),
5526
+ payloadHash
5527
+ ].join("\n");
5528
+ const scope = `${day}/${region}/s3/aws4_request`;
5529
+ const signature = createHmac("sha256", hmac(hmac(hmac(hmac(`AWS4${options.secretAccessKey}`, day), region), "s3"), "aws4_request")).update([
5530
+ "AWS4-HMAC-SHA256",
5531
+ amzDate,
5532
+ scope,
5533
+ hex(canonical)
5534
+ ].join("\n")).digest("hex");
5535
+ const { host: _host, ...sent } = signed;
5536
+ const deadline = AbortSignal.timeout(timeoutMs + Math.ceil((body?.byteLength ?? 0) / (1024 * 1024)) * 1e3);
5537
+ return await send(url, {
5538
+ method,
5539
+ headers: {
5540
+ ...sent,
5541
+ authorization: `AWS4-HMAC-SHA256 Credential=${options.accessKeyId}/${scope}, SignedHeaders=${names.join(";")}, Signature=${signature}`
5542
+ },
5543
+ ...body === void 0 ? {} : { body },
5544
+ signal: signal === void 0 ? deadline : AbortSignal.any([signal, deadline])
5545
+ });
5546
+ };
5547
+ const refusal = async (response, action) => {
5548
+ const detail = (await response.text().catch(() => "")).replace(/\s+/gu, " ").slice(0, 300);
5549
+ return /* @__PURE__ */ new Error(`S3 private CAS ${action} returned ${response.status}${detail ? `: ${detail}` : ""}`);
5550
+ };
5551
+ /** Whether the bucket holds this exact object; refuses a same-key object of other bytes. */
5552
+ const holds = async (objectKey, digest, byteLength, signal) => {
5553
+ const response = await request("HEAD", objectKey, signal === void 0 ? {} : { signal });
5554
+ if (response.status === 404) return false;
5555
+ if (!response.ok) throw await refusal(response, "HEAD");
5556
+ const length = Number(response.headers.get("content-length"));
5557
+ const recorded = response.headers.get(METADATA_DIGEST);
5558
+ if (length !== byteLength || recorded !== null && recorded !== digest) throw new Error(`S3 private CAS object ${objectKey} has another length or digest`);
5559
+ return recorded === digest;
5560
+ };
5561
+ return {
5562
+ location: `s3://${options.bucket}/${prefix}`,
5563
+ async put({ namespace, digest, bytes, signal }) {
5564
+ const objectKey = key(namespace, digest);
5565
+ if (await holds(objectKey, digest, bytes.byteLength, signal)) return;
5566
+ const response = await request("PUT", objectKey, {
5567
+ body: bytes,
5568
+ payloadHash: DIGEST.exec(digest)[1],
5569
+ headers: {
5570
+ "content-type": CONTENT_TYPE,
5571
+ [METADATA_DIGEST]: digest
5572
+ },
5573
+ ...signal === void 0 ? {} : { signal }
5574
+ });
5575
+ if (!response.ok) throw await refusal(response, "PUT");
5576
+ await response.arrayBuffer().catch(() => void 0);
5577
+ if (!await holds(objectKey, digest, bytes.byteLength, signal)) throw new Error(`S3 private CAS object ${objectKey} is absent after its write`);
5578
+ },
5579
+ async get({ namespace, digest, signal }) {
5580
+ const response = await request("GET", key(namespace, digest), signal === void 0 ? {} : { signal });
5581
+ if (response.status === 404) {
5582
+ await response.arrayBuffer().catch(() => void 0);
5583
+ return;
5584
+ }
5585
+ if (!response.ok) throw await refusal(response, "GET");
5586
+ return new Uint8Array(await response.arrayBuffer());
5587
+ }
5588
+ };
5589
+ }
5590
+ //#endregion
5268
5591
  //#region src/runtime/box-read-retry.ts
5269
5592
  /**
5270
5593
  * One bounded-retry read over a sandbox box's filesystem, shared by every caller that reads a
@@ -8397,6 +8720,6 @@ function tail(s) {
8397
8720
  return s.slice(-400);
8398
8721
  }
8399
8722
  //#endregion
8400
- export { InMemoryCorpus as $, mcpSecretEnvMetadataKey as $t, unsafeInProcessRunner as A, runIsolatedCheck as At, SandboxRunAbortError as B, renderPairwiseMarkdown as Bt, withUntrackedArtifacts as C, superviseDispatch as Ct, patchDelivered as D, declaredCheckDigest as Dt, createSqlRunContext as E, declaredCheckDeliverable as Et, strategyTournament as F, leaderboard as Ft, equalKOnCost as G, SqlResultBlobStore as Gt, printBenchmarkReport as H, defaultAuditorInstruction as Ht, assertStrategyContract as I, pairwiseSignificance as It, runPersonified as J, connectStdioMcp as Jt, trajectoryReport as K, SqlSpawnJournal as Kt, authorStrategy as L, renderLeaderboardHtml as Lt, chatWorkerSeam as M, deterministicCompletion as Mt, createChatSessionStore as N, sentinelCompletion as Nt, runCoderChecks as O, declaredCheckJudge as Ot, runStrategyEvolution as P, stopSentinel as Pt, FileCorpus as Q, envKeyProvider as Qt, strategyAuthorContract as R, renderLeaderboardMarkdown as Rt, copyUntrackedIntoClone as S, loopDispatch as St, createFencedSqlRunContext as T, checkProgramDigest as Tt, runBenchmark as U, SqlRunOwnershipError as Ut, openSandboxRun as V, auditIntent as Vt, createPrivateCasArtifactPort as W, openSqlRunStore as Wt, createShapeRegistry as X, createMcpEnvironment as Xt, builtinShapes as Y, materializeLocalMcp as Yt, registerShape as Z, sanitizeMcpToolSchema as Zt, NOTE_MAX_CHARS as _, defineLeaderboard as _t, localShell as a, pipeline as at, composeWorkerEvidence as b, inlineSandboxClient as bt, createVerifierEnvironment as c, widen as ct, harvestSurfaceDiffs as d, createScopeAnalyst as dt, resolveMcpServerLaunch as en, renderCorpusToInstructions as et, analystsFromRegistry as f, registryScopeAnalyst as ft, EVIDENCE_MAX_CHARS as g, harvestCorpus as gt, worktreeFanout as h, HarvestError as ht, jjWorkspace as i, panel as it, chatTransportExecutor as j, completionAuthorizes as jt, codeModeSupervisorTools as k, readDeclaredCheck as kt, boxSurfaceReader as l, assertTraceDerivedFindings as lt, superviseSurface as m, inProcessSandboxClient as mt, makeFinding$1 as n, secretEnvOfMcpServer as nn, flatWidenGate as nt, runInWorkspace as o, selectValidWinner as ot, failuresAnalyst as p, observationFromRegistry as pt, definePersona as q, McpSpawnFault as qt, gitWorkspace as r, createTangleSandboxExactProcessProvider as rn, loopUntil as rt, createWaterfallCollector as s, verify as st, computeFindingId$1 as t, resolveSecretEnv as tn, fanout as tt, fsSurfaceReader as u, buildSteerContext as ut, VERIFY_TAIL_CHARS as v, resolveSandboxClient as vt, analyzeTrace as w, assertDeclaredCheck as wt, settledWorkerOut as x, loopCampaignDispatch as xt, closingWorkerNote as y, localSandboxClient as yt, strategyAuthorSystemPrompt as z, renderLeaderboardSvg as zt };
8723
+ export { FileCorpus as $, envKeyProvider as $t, unsafeInProcessRunner as A, readDeclaredCheck as At, SandboxRunAbortError as B, renderLeaderboardSvg as Bt, withUntrackedArtifacts as C, loopDispatch as Ct, patchDelivered as D, declaredCheckDeliverable as Dt, createSqlRunContext as E, checkProgramDigest as Et, strategyTournament as F, stopSentinel as Ft, createPrivateCasArtifactPort as G, openSqlRunStore as Gt, createS3PrivateCasStore as H, auditIntent as Ht, assertStrategyContract as I, leaderboard as It, definePersona as J, McpSpawnFault as Jt, equalKOnCost as K, SqlResultBlobStore as Kt, authorStrategy as L, pairwiseSignificance as Lt, chatWorkerSeam as M, completionAuthorizes as Mt, createChatSessionStore as N, deterministicCompletion as Nt, runCoderChecks as O, declaredCheckDigest as Ot, runStrategyEvolution as P, sentinelCompletion as Pt, registerShape as Q, sanitizeMcpToolSchema as Qt, strategyAuthorContract as R, renderLeaderboardHtml as Rt, copyUntrackedIntoClone as S, loopCampaignDispatch as St, createFencedSqlRunContext as T, assertDeclaredCheck as Tt, printBenchmarkReport as U, defaultAuditorInstruction as Ut, openSandboxRun as V, renderPairwiseMarkdown as Vt, runBenchmark as W, SqlRunOwnershipError as Wt, builtinShapes as X, materializeLocalMcp as Xt, runPersonified as Y, connectStdioMcp as Yt, createShapeRegistry as Z, createMcpEnvironment as Zt, NOTE_MAX_CHARS as _, harvestCorpus as _t, localShell as a, panel as at, composeWorkerEvidence as b, localSandboxClient as bt, createVerifierEnvironment as c, verify as ct, harvestSurfaceDiffs as d, buildSteerContext as dt, mcpSecretEnvMetadataKey as en, InMemoryCorpus as et, analystsFromRegistry as f, createScopeAnalyst as ft, EVIDENCE_MAX_CHARS as g, HarvestError as gt, worktreeFanout as h, inProcessSandboxClient as ht, jjWorkspace as i, createTangleSandboxExactProcessProvider as in, loopUntil as it, chatTransportExecutor as j, runIsolatedCheck as jt, codeModeSupervisorTools as k, declaredCheckJudge as kt, boxSurfaceReader as l, widen as lt, superviseSurface as m, observationFromRegistry as mt, makeFinding$1 as n, resolveSecretEnv as nn, fanout as nt, runInWorkspace as o, pipeline as ot, failuresAnalyst as p, registryScopeAnalyst as pt, trajectoryReport as q, SqlSpawnJournal as qt, gitWorkspace as r, secretEnvOfMcpServer as rn, flatWidenGate as rt, createWaterfallCollector as s, selectValidWinner as st, computeFindingId$1 as t, resolveMcpServerLaunch as tn, renderCorpusToInstructions as tt, fsSurfaceReader as u, assertTraceDerivedFindings as ut, VERIFY_TAIL_CHARS as v, defineLeaderboard as vt, analyzeTrace as w, superviseDispatch as wt, settledWorkerOut as x, inlineSandboxClient as xt, closingWorkerNote as y, resolveSandboxClient as yt, strategyAuthorSystemPrompt as z, renderLeaderboardMarkdown as zt };
8401
8724
 
8402
- //# sourceMappingURL=runtime-DMrS3EkC.js.map
8725
+ //# sourceMappingURL=runtime-B_OdIcAW.js.map