@tangle-network/agent-eval 0.217.1 → 0.218.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -1
- package/dist/adapters/http.d.ts +2 -2
- package/dist/analyst/index.d.ts +1 -1
- package/dist/analyst/index.d.ts.map +1 -1
- package/dist/analyst/index.js +9 -9
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyze-runs-DyeNcenW.d.ts → analyze-runs-DjlZOVXx.d.ts} +2 -2
- package/dist/{analyze-runs-DyeNcenW.d.ts.map → analyze-runs-DjlZOVXx.d.ts.map} +1 -1
- package/dist/{benchmark-command-xQK8nOI6.js → benchmark-command-BupdHRyf.js} +661 -562
- package/dist/benchmark-command-BupdHRyf.js.map +1 -0
- package/dist/benchmarks/index.d.ts +4 -4
- package/dist/benchmarks/index.js +3 -3
- package/dist/campaign/index.d.ts +4 -4
- package/dist/campaign/index.js +10 -10
- package/dist/{campaign-CJGkxAQ6.js → campaign-CGvUTnmc.js} +312 -281
- package/dist/{campaign-CJGkxAQ6.js.map → campaign-CGvUTnmc.js.map} +1 -1
- package/dist/{campaign-evidence-CQYw8_0H.js → campaign-evidence-DunzcJGv.js} +2 -2
- package/dist/{campaign-evidence-CQYw8_0H.js.map → campaign-evidence-DunzcJGv.js.map} +1 -1
- package/dist/{chat-client-ldqxYYTN.js → chat-client-B2pXlPdx.js} +2 -2
- package/dist/{chat-client-ldqxYYTN.js.map → chat-client-B2pXlPdx.js.map} +1 -1
- package/dist/{chat-json-call-DavzexSp.js → chat-json-call-Dm9c-b41.js} +2 -2
- package/dist/{chat-json-call-DavzexSp.js.map → chat-json-call-Dm9c-b41.js.map} +1 -1
- package/dist/cli.js +10 -10
- package/dist/{completion-verifier-B_jw6C9p.js → completion-verifier-DbLVf3i8.js} +4 -4
- package/dist/{completion-verifier-B_jw6C9p.js.map → completion-verifier-DbLVf3i8.js.map} +1 -1
- package/dist/contract/index.d.ts +7 -7
- package/dist/contract/index.js +90 -10
- package/dist/contract/index.js.map +1 -1
- package/dist/{default-registry-ClYjq3QE.js → default-registry-BJ-Pq6yL.js} +309 -277
- package/dist/{default-registry-ClYjq3QE.js.map → default-registry-BJ-Pq6yL.js.map} +1 -1
- package/dist/{define-agent-eval-BDxNlP3D.js → define-agent-eval-BGdFKlrc.js} +165 -105
- package/dist/define-agent-eval-BGdFKlrc.js.map +1 -0
- package/dist/{define-agent-eval-BIkH_gAR.d.ts → define-agent-eval-BlH10zEw.d.ts} +6 -6
- package/dist/{define-agent-eval-BIkH_gAR.d.ts.map → define-agent-eval-BlH10zEw.d.ts.map} +1 -1
- package/dist/diagnosis/index.d.ts +1 -1
- package/dist/{dspy-rlm-engine-DhdCr1Dc.js → dspy-rlm-engine-CSMwudLO.js} +2 -2
- package/dist/{dspy-rlm-engine-DhdCr1Dc.js.map → dspy-rlm-engine-CSMwudLO.js.map} +1 -1
- package/dist/eval-campaign-BUMIxKTE.js +393 -0
- package/dist/eval-campaign-BUMIxKTE.js.map +1 -0
- package/dist/{evaluation-jTjC_QQD.d.ts → evaluation-BOZ38vOH.d.ts} +2 -2
- package/dist/{evaluation-jTjC_QQD.d.ts.map → evaluation-BOZ38vOH.d.ts.map} +1 -1
- package/dist/evaluation.d.ts +1 -1
- package/dist/experiment/index.d.ts +1 -1
- package/dist/experiment/index.d.ts.map +1 -1
- package/dist/experiment/index.js +110 -71
- package/dist/experiment/index.js.map +1 -1
- package/dist/{exporters-Cl6IeNAu.js → exporters-DWvM16LE.js} +2 -2
- package/dist/{exporters-Cl6IeNAu.js.map → exporters-DWvM16LE.js.map} +1 -1
- package/dist/{external-optimizer-process-KVFGvYX1.js → external-optimizer-process-C3Wm7Vhn.js} +2 -2
- package/dist/{external-optimizer-process-KVFGvYX1.js.map → external-optimizer-process-C3Wm7Vhn.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-XIHBOSKt.js → external-optimizer-subprocess-B5gdLRZv.js} +3 -3
- package/dist/{external-optimizer-subprocess-XIHBOSKt.js.map → external-optimizer-subprocess-B5gdLRZv.js.map} +1 -1
- package/dist/{findings-store-BMVQtEsm.js → findings-store-BtTzPL0d.js} +5 -5
- package/dist/{findings-store-BMVQtEsm.js.map → findings-store-BtTzPL0d.js.map} +1 -1
- package/dist/{hf-dataset-D9f7-oX7.js → hf-dataset-CKxIJQba.js} +3 -3
- package/dist/{hf-dataset-D9f7-oX7.js.map → hf-dataset-CKxIJQba.js.map} +1 -1
- package/dist/hosted/index.js +1 -1
- package/dist/{index-ZuWx52WG.d.ts → index-B16FNdW5.d.ts} +34 -17
- package/dist/index-B16FNdW5.d.ts.map +1 -0
- package/dist/{index-9jJ2fKSX.d.ts → index-CalAsXMR.d.ts} +7 -5
- package/dist/index-CalAsXMR.d.ts.map +1 -0
- package/dist/{index-BiT6RtNH.d.ts → index-DbMOXYnP.d.ts} +6 -6
- package/dist/{index-BiT6RtNH.d.ts.map → index-DbMOXYnP.d.ts.map} +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +611 -688
- package/dist/index.js.map +1 -1
- package/dist/{integrity-DOd9Q86O.js → integrity-C8oUeB0g.js} +322 -197
- package/dist/integrity-C8oUeB0g.js.map +1 -0
- package/dist/{journal-CR4QikYp.js → journal-C7om8Gum.js} +48 -38
- package/dist/journal-C7om8Gum.js.map +1 -0
- package/dist/ledger-core/index.d.ts +1 -1
- package/dist/ledger-core/index.js +2 -2
- package/dist/ledger-core/lock-holder.d.ts +2 -0
- package/dist/ledger-core/lock-holder.js +181 -0
- package/dist/ledger-core/lock-holder.js.map +1 -0
- package/dist/{ledger-core-DrJhbms9.js → ledger-core-CAxUdDk0.js} +2 -2
- package/dist/{ledger-core-DrJhbms9.js.map → ledger-core-CAxUdDk0.js.map} +1 -1
- package/dist/{llm-client-BshCREn6.js → llm-client-_Y6ic-tf.js} +238 -248
- package/dist/llm-client-_Y6ic-tf.js.map +1 -0
- package/dist/{llm-judge-C8jMTNNG.js → llm-judge-Djxh-Uhs.js} +646 -458
- package/dist/llm-judge-Djxh-Uhs.js.map +1 -0
- package/dist/lock-holder-DaJbfpci.d.ts +86 -0
- package/dist/lock-holder-DaJbfpci.d.ts.map +1 -0
- package/dist/{matrix-DHe-dwVJ.d.ts → matrix-CCSBna4q.d.ts} +2 -2
- package/dist/{matrix-DHe-dwVJ.d.ts.map → matrix-CCSBna4q.d.ts.map} +1 -1
- package/dist/{mint-zszyYlpA.js → mint-CbdwjTPW.js} +2 -2
- package/dist/{mint-zszyYlpA.js.map → mint-CbdwjTPW.js.map} +1 -1
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/index.d.ts +2 -2
- package/dist/openapi.json +1 -1
- package/dist/{pareto-BzsxidFD.js → pareto-CTv8vozZ.js} +4 -4
- package/dist/{pareto-BzsxidFD.js.map → pareto-CTv8vozZ.js.map} +1 -1
- package/dist/{promotion-gate-DaY95yU6.d.ts → promotion-gate-CxEHRsZW.d.ts} +2 -2
- package/dist/{promotion-gate-DaY95yU6.d.ts.map → promotion-gate-CxEHRsZW.d.ts.map} +1 -1
- package/dist/{proposal-findings-BbWidvUk.js → proposal-findings-n-5WBbEx.js} +2 -2
- package/dist/{proposal-findings-BbWidvUk.js.map → proposal-findings-n-5WBbEx.js.map} +1 -1
- package/dist/{render-C-w2EZ6p.js → render-Cs34y0iX.js} +404 -208
- package/dist/render-Cs34y0iX.js.map +1 -0
- package/dist/reporting.d.ts +2 -2
- package/dist/{researcher-0ABVIdGa.d.ts → researcher-GU1tV4dn.d.ts} +2 -2
- package/dist/{researcher-0ABVIdGa.d.ts.map → researcher-GU1tV4dn.d.ts.map} +1 -1
- package/dist/rl.d.ts +2 -2
- package/dist/rl.js +4 -4
- package/dist/rollout/index.js +5 -5
- package/dist/{rollout-D6C50mfA.js → rollout-Dd1ucT_M.js} +5 -5
- package/dist/{rollout-D6C50mfA.js.map → rollout-Dd1ucT_M.js.map} +1 -1
- package/dist/schema-C-ziyJD7.d.ts.map +1 -1
- package/dist/{schema-DxcKTzbi.js → schema-CvhfLjtZ.js} +77 -47
- package/dist/schema-CvhfLjtZ.js.map +1 -0
- package/dist/search/index.d.ts +2 -2
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +2 -2
- package/dist/{search-kernel-DxqjBxA-.d.ts → search-kernel-p9JB3SmL.d.ts} +3 -3
- package/dist/{search-kernel-DxqjBxA-.d.ts.map → search-kernel-p9JB3SmL.d.ts.map} +1 -1
- package/dist/{search-ledger-TUvB5gWH.js → search-ledger-ClpN4I3e.js} +4 -4
- package/dist/{search-ledger-TUvB5gWH.js.map → search-ledger-ClpN4I3e.js.map} +1 -1
- package/dist/{search-ledger-file-UKCO2r8a.js → search-ledger-file-Bd5Tioq6.js} +3 -3
- package/dist/{search-ledger-file-UKCO2r8a.js.map → search-ledger-file-Bd5Tioq6.js.map} +1 -1
- package/dist/{search-shipper-Cw2z3-td.js → search-shipper-Bg2HW3Uv.js} +3 -3
- package/dist/{search-shipper-Cw2z3-td.js.map → search-shipper-Bg2HW3Uv.js.map} +1 -1
- package/dist/{search-summary-DQIvJsSB.js → search-summary-CrBuvVnf.js} +3 -3
- package/dist/{search-summary-DQIvJsSB.js.map → search-summary-CrBuvVnf.js.map} +1 -1
- package/dist/{server-DoVbqqtJ.js → server-C6M0qR8h.js} +2 -2
- package/dist/{server-DoVbqqtJ.js.map → server-C6M0qR8h.js.map} +1 -1
- package/dist/{single-run-lock-U58yf8N6.js → single-run-lock-Dekd8_Wv.js} +7 -7
- package/dist/single-run-lock-Dekd8_Wv.js.map +1 -0
- package/dist/{skillopt-optimization-method-kyL94-ri.js → skillopt-optimization-method-5dlex7MJ.js} +1339 -1059
- package/dist/skillopt-optimization-method-5dlex7MJ.js.map +1 -0
- package/dist/{statistical-heldout-C9AbgREN.d.ts → statistical-heldout-BHfLZHrm.d.ts} +2 -2
- package/dist/{statistical-heldout-C9AbgREN.d.ts.map → statistical-heldout-BHfLZHrm.d.ts.map} +1 -1
- package/dist/{summary-report-DM7tlml1.d.ts → summary-report-CkbRcSuu.d.ts} +16 -1
- package/dist/summary-report-CkbRcSuu.d.ts.map +1 -0
- package/dist/supervisor-run/index.d.ts.map +1 -1
- package/dist/supervisor-run/index.js +3 -3
- package/dist/{systemone-Bp_Ac0p1.d.ts → systemone-BMzDJb1i.d.ts} +3 -3
- package/dist/{systemone-Bp_Ac0p1.d.ts.map → systemone-BMzDJb1i.d.ts.map} +1 -1
- package/dist/systemone.d.ts +2 -2
- package/dist/{terminal-record-78g6E4vh.js → terminal-record-D4Rv-j1W.js} +241 -193
- package/dist/{terminal-record-78g6E4vh.js.map → terminal-record-D4Rv-j1W.js.map} +1 -1
- package/dist/trajectory-replay/index.d.ts +4 -1
- package/dist/trajectory-replay/index.d.ts.map +1 -1
- package/dist/trajectory-replay/index.js +834 -824
- package/dist/trajectory-replay/index.js.map +1 -1
- package/dist/{tree-BGRglkKd.js → tree-B5e1uAeL.js} +122 -14
- package/dist/tree-B5e1uAeL.js.map +1 -0
- package/dist/{types-DtMbFw6U.d.ts → types-BKCzzmit.d.ts} +2 -2
- package/dist/{types-DtMbFw6U.d.ts.map → types-BKCzzmit.d.ts.map} +1 -1
- package/dist/{types-D8GhJoHk.d.ts → types-DtkO1G9L.d.ts} +2 -2
- package/dist/{types-D8GhJoHk.d.ts.map → types-DtkO1G9L.d.ts.map} +1 -1
- package/dist/wire/index.js +1 -1
- package/docs/design/statistics-decisions.md +1 -1
- package/docs/eval-surface-map.md +1 -0
- package/docs/profile-json-identity.md +1 -2
- package/docs/public-api.md +27 -16
- package/package.json +7 -2
- package/dist/benchmark-command-xQK8nOI6.js.map +0 -1
- package/dist/define-agent-eval-BDxNlP3D.js.map +0 -1
- package/dist/eval-campaign-BLEfBGbA.js +0 -343
- package/dist/eval-campaign-BLEfBGbA.js.map +0 -1
- package/dist/index-9jJ2fKSX.d.ts.map +0 -1
- package/dist/index-ZuWx52WG.d.ts.map +0 -1
- package/dist/integrity-DOd9Q86O.js.map +0 -1
- package/dist/journal-CR4QikYp.js.map +0 -1
- package/dist/llm-client-BshCREn6.js.map +0 -1
- package/dist/llm-judge-C8jMTNNG.js.map +0 -1
- package/dist/render-C-w2EZ6p.js.map +0 -1
- package/dist/schema-DxcKTzbi.js.map +0 -1
- package/dist/single-run-lock-U58yf8N6.js.map +0 -1
- package/dist/skillopt-optimization-method-kyL94-ri.js.map +0 -1
- package/dist/summary-report-DM7tlml1.d.ts.map +0 -1
- package/dist/tree-BGRglkKd.js.map +0 -1
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { s as ValidationError, t as AgentEvalError } from "./errors-BcOs5MKW.js";
|
|
2
2
|
import { a as hashCanonical, i as compareCodeUnits, r as canonicalString } from "./canonical-Dq2hOQ8L.js";
|
|
3
|
-
import { c as agentProfileModelId, o as agentProfileHash, r as verifyCompletion, s as agentProfileId, u as harnessAxisOf } from "./completion-verifier-
|
|
3
|
+
import { c as agentProfileModelId, o as agentProfileHash, r as verifyCompletion, s as agentProfileId, u as harnessAxisOf } from "./completion-verifier-DbLVf3i8.js";
|
|
4
4
|
import { i as buildAgentProfileCell } from "./agent-profile-cell-B1V1gUZs.js";
|
|
5
5
|
import { c as validateRunRecord, i as modelHasSnapshot, n as UNKNOWN_MODEL, o as runTaskScore } from "./run-record-DhEJgoPz.js";
|
|
6
6
|
import { t as comparePairedArms } from "./paired-arms-Ct4LTKc1.js";
|
|
7
7
|
import { i as pairedBootstrap } from "./mean-BbA_JCzW.js";
|
|
8
8
|
import { o as pairHoldout } from "./statistical-heldout-Bksv92Th.js";
|
|
9
9
|
import { n as contentHash, t as canonicalJson } from "./verdict-cache-CL_7tePD.js";
|
|
10
|
-
import { $ as planCampaignRun, Q as runCampaign, et as resolveRunDir, nt as cellCachePath, rt as computeManifestHash, s as executeOptimizationMethod, u as combineComparisonCosts } from "./llm-judge-
|
|
10
|
+
import { $ as planCampaignRun, Q as runCampaign, et as resolveRunDir, nt as cellCachePath, rt as computeManifestHash, s as executeOptimizationMethod, u as combineComparisonCosts } from "./llm-judge-Djxh-Uhs.js";
|
|
11
11
|
import { n as campaignCellToRunRecord, r as projectCampaignCellQuality, t as campaignCellCostProvenance } from "./run-record-CysKLB93.js";
|
|
12
|
-
import { C as assertCodeSurfaceIdentity, D as surfaceContentHash, M as assertRealBackend, N as summarizeBackendIntegrity, P as assertCampaignDesign, R as campaignScenarioIdentity } from "./campaign-evidence-
|
|
13
|
-
import { a as mapConcurrent } from "./journal-
|
|
14
|
-
import { M as fsCampaignStorage } from "./external-optimizer-subprocess-
|
|
15
|
-
import "./pareto-
|
|
16
|
-
import "./search-ledger-
|
|
17
|
-
import "./search-summary-
|
|
18
|
-
import "./external-optimizer-process-
|
|
19
|
-
import "./skillopt-optimization-method-
|
|
12
|
+
import { C as assertCodeSurfaceIdentity, D as surfaceContentHash, M as assertRealBackend, N as summarizeBackendIntegrity, P as assertCampaignDesign, R as campaignScenarioIdentity } from "./campaign-evidence-DunzcJGv.js";
|
|
13
|
+
import { a as mapConcurrent } from "./journal-C7om8Gum.js";
|
|
14
|
+
import { M as fsCampaignStorage } from "./external-optimizer-subprocess-B5gdLRZv.js";
|
|
15
|
+
import "./pareto-CTv8vozZ.js";
|
|
16
|
+
import "./search-ledger-ClpN4I3e.js";
|
|
17
|
+
import "./search-summary-CrBuvVnf.js";
|
|
18
|
+
import "./external-optimizer-process-C3Wm7Vhn.js";
|
|
19
|
+
import "./skillopt-optimization-method-5dlex7MJ.js";
|
|
20
20
|
import "./sequential-CimQrbjv.js";
|
|
21
21
|
import { createHash } from "node:crypto";
|
|
22
22
|
import { closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync } from "node:fs";
|
|
@@ -2036,6 +2036,9 @@ const anchorEntrySchema = z.object({
|
|
|
2036
2036
|
bytes: z.number().int().positive(),
|
|
2037
2037
|
digest
|
|
2038
2038
|
}).strict();
|
|
2039
|
+
function fail(message) {
|
|
2040
|
+
throw new ValidationError(`retained dispatch: ${message}`);
|
|
2041
|
+
}
|
|
2039
2042
|
/**
|
|
2040
2043
|
* Persist dispatch intent before an external call and its validated result afterward.
|
|
2041
2044
|
* Replays settled calls; never repeats an uncertain call or refunds its allowance.
|
|
@@ -2047,157 +2050,192 @@ const anchorEntrySchema = z.object({
|
|
|
2047
2050
|
function createRetainedDispatch(options) {
|
|
2048
2051
|
if (!options.runDir.trim()) throw new ValidationError("retained dispatch requires a run directory");
|
|
2049
2052
|
const storage = options.storage ?? fsCampaignStorage();
|
|
2050
|
-
const parse = options.parse;
|
|
2051
2053
|
const header = headerSchema.parse({
|
|
2052
2054
|
kind: "retained-dispatch-v1",
|
|
2053
2055
|
scope: hashCanonical(options.scope),
|
|
2054
2056
|
limits: Object.entries(options.limits).sort(([a], [b]) => compareCodeUnits(a, b))
|
|
2055
2057
|
});
|
|
2056
2058
|
if (!header.limits.length) throw new ValidationError("retained dispatch requires named allowances");
|
|
2057
|
-
const
|
|
2058
|
-
|
|
2059
|
-
|
|
2059
|
+
const journal = {
|
|
2060
|
+
storage,
|
|
2061
|
+
parse: options.parse,
|
|
2062
|
+
header,
|
|
2063
|
+
limits: new Map(header.limits),
|
|
2064
|
+
counts: /* @__PURE__ */ new Map(),
|
|
2065
|
+
calls: /* @__PURE__ */ new Map(),
|
|
2066
|
+
indexPath: join(options.runDir, "dispatches.jsonl"),
|
|
2067
|
+
scopePath: join(options.runDir, "dispatch-scope.json"),
|
|
2068
|
+
anchorPath: join(options.runDir, "dispatch-anchor.jsonl"),
|
|
2069
|
+
receiptsDir: join(options.runDir, "dispatch-results"),
|
|
2070
|
+
scopeText: canonicalString(header),
|
|
2071
|
+
scopeDigest: hashCanonical(header),
|
|
2072
|
+
retainedText: "",
|
|
2073
|
+
revision: 0,
|
|
2074
|
+
chain: null,
|
|
2075
|
+
opened: false
|
|
2076
|
+
};
|
|
2060
2077
|
const active = /* @__PURE__ */ new Map();
|
|
2061
|
-
const indexPath = join(options.runDir, "dispatches.jsonl");
|
|
2062
|
-
const scopePath = join(options.runDir, "dispatch-scope.json");
|
|
2063
|
-
const anchorPath = join(options.runDir, "dispatch-anchor.jsonl");
|
|
2064
|
-
const scopeText = canonicalString(header);
|
|
2065
|
-
const scopeDigest = hashCanonical(header);
|
|
2066
|
-
const receiptsDir = join(options.runDir, "dispatch-results");
|
|
2067
|
-
const resultPath = (id) => join(receiptsDir, `${id.slice(7)}.json`);
|
|
2068
2078
|
storage.ensureDir(options.runDir);
|
|
2069
|
-
storage.ensureDir(receiptsDir);
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
const
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
if (content === void 0 && storage.exists(anchorPath)) fail("cannot read durable anchor");
|
|
2093
|
-
const text = content ?? "";
|
|
2094
|
-
if (text && !text.endsWith("\n")) fail("durable anchor is torn");
|
|
2095
|
-
const entries = [];
|
|
2096
|
-
let previous = 0;
|
|
2097
|
-
const lines = text.split("\n");
|
|
2098
|
-
if (lines.at(-1) === "") lines.pop();
|
|
2099
|
-
if (lines.some((line) => !line)) fail("durable anchor contains an empty record");
|
|
2100
|
-
for (const line of lines) {
|
|
2101
|
-
const entry = anchorEntrySchema.parse(JSON.parse(line));
|
|
2102
|
-
if (entry.scope !== scopeDigest) fail("durable anchor scope changed");
|
|
2103
|
-
if (entry.bytes <= previous) fail("durable anchor is not append-only");
|
|
2104
|
-
previous = entry.bytes;
|
|
2105
|
-
entries.push(entry);
|
|
2106
|
-
}
|
|
2107
|
-
return {
|
|
2108
|
-
text,
|
|
2109
|
-
entries
|
|
2110
|
-
};
|
|
2111
|
-
};
|
|
2112
|
-
const refresh = () => {
|
|
2113
|
-
if (storage.read(scopePath) !== scopeText) fail("scope anchor is missing or changed");
|
|
2114
|
-
const stored = storage.read(indexPath);
|
|
2115
|
-
if (stored === void 0 && storage.exists(indexPath)) fail("cannot read existing history");
|
|
2116
|
-
const text = stored ?? "";
|
|
2117
|
-
if (!text.startsWith(retainedText) || text && !text.endsWith("\n")) fail("history was truncated, replaced or torn");
|
|
2118
|
-
const { entries } = readAnchor();
|
|
2119
|
-
const bytes = Buffer.byteLength(text);
|
|
2120
|
-
const applied = Buffer.byteLength(retainedText);
|
|
2121
|
-
if (text && !entries.length) fail("durable anchor is missing");
|
|
2122
|
-
const highWater = entries[entries.length - 1];
|
|
2123
|
-
if (highWater && bytes !== highWater.bytes) {
|
|
2124
|
-
if (bytes < highWater.bytes) fail("history was truncated below its durable anchor");
|
|
2125
|
-
fail("history extends beyond its durable anchor");
|
|
2126
|
-
}
|
|
2127
|
-
let offset = 0;
|
|
2128
|
-
let running = null;
|
|
2129
|
-
let entryIndex = 0;
|
|
2130
|
-
let seenHeader = opened;
|
|
2131
|
-
for (const line of text.split("\n")) {
|
|
2132
|
-
if (!line) continue;
|
|
2133
|
-
running = hashCanonical([running, line]);
|
|
2134
|
-
offset += Buffer.byteLength(line) + 1;
|
|
2135
|
-
while (entryIndex < entries.length && entries[entryIndex].bytes === offset) {
|
|
2136
|
-
if (entries[entryIndex].digest !== running) fail("history diverges from its durable anchor");
|
|
2137
|
-
entryIndex += 1;
|
|
2138
|
-
}
|
|
2139
|
-
if (offset <= applied) continue;
|
|
2140
|
-
if (!seenHeader) {
|
|
2141
|
-
const value = JSON.parse(line);
|
|
2142
|
-
if (hashCanonical(headerSchema.parse(value)) !== hashCanonical(header)) fail("resume changed its scope or allowances");
|
|
2143
|
-
seenHeader = true;
|
|
2144
|
-
} else apply(eventSchema.parse(JSON.parse(line)));
|
|
2079
|
+
storage.ensureDir(journal.receiptsDir);
|
|
2080
|
+
openJournal(journal, options.requireExisting);
|
|
2081
|
+
return {
|
|
2082
|
+
/** The input binds all behavior-affecting request material, not just a caller-selected nonce. */
|
|
2083
|
+
run(request) {
|
|
2084
|
+
const id = hashCanonical([
|
|
2085
|
+
header.scope,
|
|
2086
|
+
request.lane,
|
|
2087
|
+
request.input
|
|
2088
|
+
]);
|
|
2089
|
+
const pending = active.get(id);
|
|
2090
|
+
if (pending) return pending;
|
|
2091
|
+
const promise = dispatchOnce(journal, id, request);
|
|
2092
|
+
active.set(id, promise);
|
|
2093
|
+
promise.finally(() => {
|
|
2094
|
+
active.delete(id);
|
|
2095
|
+
}).catch(() => {});
|
|
2096
|
+
return promise;
|
|
2097
|
+
},
|
|
2098
|
+
/** Counts include uncertain dispatches, which keep their reservation. No pricing is inferred. */
|
|
2099
|
+
committed() {
|
|
2100
|
+
refreshJournal(journal);
|
|
2101
|
+
return new Map(header.limits.map(([lane]) => [lane, journal.counts.get(lane) ?? 0]));
|
|
2145
2102
|
}
|
|
2146
|
-
if (entries.length && entryIndex !== entries.length) fail("history diverges from its durable anchor");
|
|
2147
|
-
chain = running;
|
|
2148
|
-
retainedText = text;
|
|
2149
|
-
revision = bytes;
|
|
2150
|
-
opened = seenHeader;
|
|
2151
2103
|
};
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2104
|
+
}
|
|
2105
|
+
/** Fold one journal event into the per-lane counts and pending-call map. */
|
|
2106
|
+
function applyEvent(journal, event) {
|
|
2107
|
+
const existing = journal.calls.get(event.id);
|
|
2108
|
+
if (event.kind === "started") {
|
|
2109
|
+
const limit = journal.limits.get(event.lane);
|
|
2110
|
+
const count = journal.counts.get(event.lane) ?? 0;
|
|
2111
|
+
if (existing || limit === void 0 || count >= limit) fail("invalid or over-budget dispatch history");
|
|
2112
|
+
journal.calls.set(event.id, { lane: event.lane });
|
|
2113
|
+
journal.counts.set(event.lane, count + 1);
|
|
2114
|
+
} else {
|
|
2115
|
+
if (!existing || existing.receipt) fail("settlement has no unique pending dispatch");
|
|
2116
|
+
existing.receipt = event.receipt;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
/** Read the durable anchor file, refusing a torn, empty-record, foreign-scope or non-monotonic one. */
|
|
2120
|
+
function readAnchor(journal) {
|
|
2121
|
+
const { storage, anchorPath } = journal;
|
|
2122
|
+
const content = storage.read(anchorPath);
|
|
2123
|
+
if (content === void 0 && storage.exists(anchorPath)) fail("cannot read durable anchor");
|
|
2124
|
+
const text = content ?? "";
|
|
2125
|
+
if (text && !text.endsWith("\n")) fail("durable anchor is torn");
|
|
2126
|
+
const entries = [];
|
|
2127
|
+
let previous = 0;
|
|
2128
|
+
const lines = text.split("\n");
|
|
2129
|
+
if (lines.at(-1) === "") lines.pop();
|
|
2130
|
+
if (lines.some((line) => !line)) fail("durable anchor contains an empty record");
|
|
2131
|
+
for (const line of lines) {
|
|
2132
|
+
const entry = anchorEntrySchema.parse(JSON.parse(line));
|
|
2133
|
+
if (entry.scope !== journal.scopeDigest) fail("durable anchor scope changed");
|
|
2134
|
+
if (entry.bytes <= previous) fail("durable anchor is not append-only");
|
|
2135
|
+
previous = entry.bytes;
|
|
2136
|
+
entries.push(entry);
|
|
2137
|
+
}
|
|
2138
|
+
return {
|
|
2139
|
+
text,
|
|
2140
|
+
entries
|
|
2167
2141
|
};
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2142
|
+
}
|
|
2143
|
+
/** Re-read the journal, prove it extends what was applied and matches its anchor, and apply the new events. */
|
|
2144
|
+
function refreshJournal(journal) {
|
|
2145
|
+
const { storage } = journal;
|
|
2146
|
+
if (storage.read(journal.scopePath) !== journal.scopeText) fail("scope anchor is missing or changed");
|
|
2147
|
+
const stored = storage.read(journal.indexPath);
|
|
2148
|
+
if (stored === void 0 && storage.exists(journal.indexPath)) fail("cannot read existing history");
|
|
2149
|
+
const text = stored ?? "";
|
|
2150
|
+
if (!text.startsWith(journal.retainedText) || text && !text.endsWith("\n")) fail("history was truncated, replaced or torn");
|
|
2151
|
+
const { entries } = readAnchor(journal);
|
|
2152
|
+
const bytes = Buffer.byteLength(text);
|
|
2153
|
+
const applied = Buffer.byteLength(journal.retainedText);
|
|
2154
|
+
if (text && !entries.length) fail("durable anchor is missing");
|
|
2155
|
+
const highWater = entries[entries.length - 1];
|
|
2156
|
+
if (highWater && bytes !== highWater.bytes) {
|
|
2157
|
+
if (bytes < highWater.bytes) fail("history was truncated below its durable anchor");
|
|
2158
|
+
fail("history extends beyond its durable anchor");
|
|
2159
|
+
}
|
|
2160
|
+
let offset = 0;
|
|
2161
|
+
let running = null;
|
|
2162
|
+
let entryIndex = 0;
|
|
2163
|
+
let seenHeader = journal.opened;
|
|
2164
|
+
for (const line of text.split("\n")) {
|
|
2165
|
+
if (!line) continue;
|
|
2166
|
+
running = hashCanonical([running, line]);
|
|
2167
|
+
offset += Buffer.byteLength(line) + 1;
|
|
2168
|
+
while (entryIndex < entries.length && entries[entryIndex].bytes === offset) {
|
|
2169
|
+
if (entries[entryIndex].digest !== running) fail("history diverges from its durable anchor");
|
|
2170
|
+
entryIndex += 1;
|
|
2179
2171
|
}
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
})
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2172
|
+
if (offset <= applied) continue;
|
|
2173
|
+
if (!seenHeader) {
|
|
2174
|
+
const value = JSON.parse(line);
|
|
2175
|
+
if (hashCanonical(headerSchema.parse(value)) !== hashCanonical(journal.header)) fail("resume changed its scope or allowances");
|
|
2176
|
+
seenHeader = true;
|
|
2177
|
+
} else applyEvent(journal, eventSchema.parse(JSON.parse(line)));
|
|
2178
|
+
}
|
|
2179
|
+
if (entries.length && entryIndex !== entries.length) fail("history diverges from its durable anchor");
|
|
2180
|
+
journal.chain = running;
|
|
2181
|
+
journal.retainedText = text;
|
|
2182
|
+
journal.revision = bytes;
|
|
2183
|
+
journal.opened = seenHeader;
|
|
2184
|
+
}
|
|
2185
|
+
/** Compare-and-append one event; a lost race refreshes the journal and returns false. */
|
|
2186
|
+
function appendEvent(journal, event) {
|
|
2187
|
+
const encoded = canonicalString(event);
|
|
2188
|
+
const line = `${encoded}\n`;
|
|
2189
|
+
const next = journal.storage.append(journal.indexPath, line, journal.revision);
|
|
2190
|
+
if (next === void 0) {
|
|
2191
|
+
refreshJournal(journal);
|
|
2192
|
+
return false;
|
|
2193
|
+
}
|
|
2194
|
+
if (next !== journal.revision + Buffer.byteLength(line)) fail("storage returned an invalid append revision");
|
|
2195
|
+
journal.chain = hashCanonical([journal.chain, encoded]);
|
|
2196
|
+
journal.retainedText += line;
|
|
2197
|
+
journal.revision = next;
|
|
2198
|
+
if (event.kind === "retained-dispatch-v1") journal.opened = true;
|
|
2199
|
+
else applyEvent(journal, event);
|
|
2200
|
+
return true;
|
|
2201
|
+
}
|
|
2202
|
+
/** Record the journal's current length and digest in the durable anchor. */
|
|
2203
|
+
function advanceAnchor(journal) {
|
|
2204
|
+
const currentChain = journal.chain ?? fail("cannot anchor an empty history");
|
|
2205
|
+
if (journal.revision <= 0) fail("cannot anchor an empty history");
|
|
2206
|
+
const { text, entries } = readAnchor(journal);
|
|
2207
|
+
const last = entries[entries.length - 1];
|
|
2208
|
+
if (last) {
|
|
2209
|
+
if (last.bytes > journal.revision) fail("history is behind its durable anchor");
|
|
2210
|
+
if (last.bytes === journal.revision) {
|
|
2211
|
+
if (last.digest !== currentChain) fail("history diverges from its durable anchor");
|
|
2212
|
+
return;
|
|
2191
2213
|
}
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
if (
|
|
2214
|
+
}
|
|
2215
|
+
const line = `${canonicalString({
|
|
2216
|
+
kind: "retained-dispatch-anchor-v1",
|
|
2217
|
+
scope: journal.scopeDigest,
|
|
2218
|
+
bytes: journal.revision,
|
|
2219
|
+
digest: currentChain
|
|
2220
|
+
})}\n`;
|
|
2221
|
+
const next = journal.storage.append(journal.anchorPath, line, Buffer.byteLength(text));
|
|
2222
|
+
if (next === void 0) {
|
|
2223
|
+
const concurrent = readAnchor(journal).entries.at(-1);
|
|
2224
|
+
if (concurrent?.bytes === journal.revision && concurrent.digest === journal.chain) return;
|
|
2225
|
+
fail("durable anchor append is busy; retry with the same run directory");
|
|
2226
|
+
}
|
|
2227
|
+
if (next !== Buffer.byteLength(text) + Buffer.byteLength(line)) fail("storage returned an invalid durable anchor revision");
|
|
2228
|
+
}
|
|
2229
|
+
/** An event takes effect only after both its journal append and its anchor entry are durable. */
|
|
2230
|
+
function commitEvent(journal, event) {
|
|
2231
|
+
if (!appendEvent(journal, event)) return false;
|
|
2232
|
+
advanceAnchor(journal);
|
|
2233
|
+
return true;
|
|
2234
|
+
}
|
|
2235
|
+
/** Create or verify the scope anchor, load existing history, and commit the header on a fresh journal. */
|
|
2236
|
+
function openJournal(journal, requireExisting) {
|
|
2237
|
+
const { storage, scopePath, indexPath, anchorPath, scopeText } = journal;
|
|
2238
|
+
if (requireExisting && (!storage.exists(scopePath) || !storage.exists(indexPath) || !storage.exists(anchorPath))) fail("required retained history is missing");
|
|
2201
2239
|
if (storage.exists(scopePath)) {
|
|
2202
2240
|
if (storage.read(scopePath) !== scopeText) fail("resume changed its scope or allowances");
|
|
2203
2241
|
if (!storage.read(indexPath)?.trim()) fail("dispatch history is missing or empty");
|
|
@@ -2209,145 +2247,138 @@ function createRetainedDispatch(options) {
|
|
|
2209
2247
|
if (storage.read(scopePath) !== scopeText || !storage.read(indexPath)?.trim()) fail("scope initialization is busy; retry the same scope");
|
|
2210
2248
|
} else if (created !== Buffer.byteLength(scopeText)) fail("storage returned an invalid scope revision");
|
|
2211
2249
|
}
|
|
2212
|
-
|
|
2213
|
-
if (!opened && !
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2250
|
+
refreshJournal(journal);
|
|
2251
|
+
if (!journal.opened && !commitEvent(journal, journal.header) && !journal.opened) fail("history is busy; retry with the same run directory");
|
|
2252
|
+
}
|
|
2253
|
+
/** Read and verify a retained result file, or undefined when none was written. */
|
|
2254
|
+
function readResult(journal, id) {
|
|
2255
|
+
const content = journal.storage.read(resultPath(journal, id));
|
|
2256
|
+
if (content === void 0) return void 0;
|
|
2257
|
+
const result = resultSchema.parse(JSON.parse(content));
|
|
2258
|
+
if (result.id !== id) return fail("retained result dispatch id mismatch");
|
|
2259
|
+
if (hashCanonical(result.value) !== result.receipt) return fail("retained result digest mismatch");
|
|
2260
|
+
const value = journal.parse(result.value);
|
|
2261
|
+
if (hashCanonical(value) !== result.receipt) return fail("result decoder changed retained output");
|
|
2262
|
+
return {
|
|
2263
|
+
value,
|
|
2264
|
+
receipt: result.receipt
|
|
2226
2265
|
};
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
if (
|
|
2237
|
-
|
|
2238
|
-
id,
|
|
2239
|
-
receipt
|
|
2240
|
-
})) return;
|
|
2241
|
-
if (revision === previousRevision) fail("settlement is busy; retained result awaits reconciliation");
|
|
2266
|
+
}
|
|
2267
|
+
function resultPath(journal, id) {
|
|
2268
|
+
return join(journal.receiptsDir, `${id.slice(7)}.json`);
|
|
2269
|
+
}
|
|
2270
|
+
/** Commit the settlement of a dispatch whose result is already durable. */
|
|
2271
|
+
function settle(journal, id, receipt) {
|
|
2272
|
+
while (true) {
|
|
2273
|
+
const existing = journal.calls.get(id);
|
|
2274
|
+
if (existing?.receipt) {
|
|
2275
|
+
if (existing.receipt !== receipt) fail("settled result digest mismatch");
|
|
2276
|
+
return;
|
|
2242
2277
|
}
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2278
|
+
if (!existing) fail("settlement has no pending dispatch");
|
|
2279
|
+
const previousRevision = journal.revision;
|
|
2280
|
+
if (commitEvent(journal, {
|
|
2281
|
+
kind: "settled",
|
|
2282
|
+
id,
|
|
2283
|
+
receipt
|
|
2284
|
+
})) return;
|
|
2285
|
+
if (journal.revision === previousRevision) fail("settlement is busy; retained result awaits reconciliation");
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
/** Replay a settled dispatch from its retained result. */
|
|
2289
|
+
function loadSettled(journal, id, receipt) {
|
|
2290
|
+
const result = readResult(journal, id);
|
|
2291
|
+
if (!result) return fail("settled result is missing");
|
|
2292
|
+
if (result.receipt !== receipt) return fail("settled result digest mismatch");
|
|
2256
2293
|
return {
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
value: result.value,
|
|
2284
|
-
dispatchId: id,
|
|
2285
|
-
receiptDigest: result.receipt,
|
|
2286
|
-
replayed: true
|
|
2287
|
-
};
|
|
2288
|
-
}
|
|
2289
|
-
signal?.throwIfAborted();
|
|
2290
|
-
if ((counts.get(lane) ?? 0) >= limits.get(lane)) return {
|
|
2291
|
-
succeeded: false,
|
|
2292
|
-
reason: "allowance_exhausted",
|
|
2293
|
-
dispatchId: id
|
|
2294
|
-
};
|
|
2295
|
-
const previousRevision = revision;
|
|
2296
|
-
if (commit({
|
|
2297
|
-
kind: "started",
|
|
2298
|
-
id,
|
|
2299
|
-
lane
|
|
2300
|
-
})) break;
|
|
2301
|
-
if (revision === previousRevision) return fail("history is busy; retry with the same input");
|
|
2302
|
-
}
|
|
2303
|
-
let value;
|
|
2304
|
-
try {
|
|
2305
|
-
signal?.throwIfAborted();
|
|
2306
|
-
value = parse(await dispatch());
|
|
2307
|
-
} catch (error) {
|
|
2308
|
-
return {
|
|
2309
|
-
succeeded: false,
|
|
2310
|
-
reason: "outcome_unknown",
|
|
2311
|
-
dispatchId: id,
|
|
2312
|
-
diagnostic: error instanceof Error ? error.message : String(error)
|
|
2313
|
-
};
|
|
2314
|
-
}
|
|
2315
|
-
const encoded = canonicalString(value);
|
|
2316
|
-
const decoded = JSON.parse(encoded);
|
|
2317
|
-
const retainedValue = parse(decoded);
|
|
2318
|
-
if (canonicalString(retainedValue) !== encoded) return fail("result decoder is not stable across serialization");
|
|
2319
|
-
const receipt = hashCanonical(decoded);
|
|
2320
|
-
const retainedResult = canonicalString({
|
|
2321
|
-
kind: "retained-dispatch-result-v1",
|
|
2322
|
-
id,
|
|
2323
|
-
receipt,
|
|
2324
|
-
value: decoded
|
|
2325
|
-
});
|
|
2326
|
-
const file = resultPath(id);
|
|
2327
|
-
if (storage.append(file, retainedResult, 0) === void 0 && storage.read(file) !== retainedResult) fail("cannot retain dispatch result");
|
|
2328
|
-
settle(id, receipt);
|
|
2329
|
-
return {
|
|
2330
|
-
succeeded: true,
|
|
2331
|
-
value: retainedValue,
|
|
2332
|
-
dispatchId: id,
|
|
2333
|
-
receiptDigest: receipt,
|
|
2334
|
-
replayed: false
|
|
2335
|
-
};
|
|
2294
|
+
succeeded: true,
|
|
2295
|
+
value: result.value,
|
|
2296
|
+
dispatchId: id,
|
|
2297
|
+
receiptDigest: receipt,
|
|
2298
|
+
replayed: true
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
/** Replay a known dispatch, or commit its started intent; returns the outcome when no call should be made. */
|
|
2302
|
+
function claimDispatch(journal, id, lane, signal) {
|
|
2303
|
+
while (true) {
|
|
2304
|
+
const existing = journal.calls.get(id);
|
|
2305
|
+
if (existing) {
|
|
2306
|
+
if (existing.receipt) return loadSettled(journal, id, existing.receipt);
|
|
2307
|
+
const result = readResult(journal, id);
|
|
2308
|
+
if (!result) return {
|
|
2309
|
+
succeeded: false,
|
|
2310
|
+
reason: "outcome_unknown",
|
|
2311
|
+
dispatchId: id
|
|
2312
|
+
};
|
|
2313
|
+
settle(journal, id, result.receipt);
|
|
2314
|
+
return {
|
|
2315
|
+
succeeded: true,
|
|
2316
|
+
value: result.value,
|
|
2317
|
+
dispatchId: id,
|
|
2318
|
+
receiptDigest: result.receipt,
|
|
2319
|
+
replayed: true
|
|
2336
2320
|
};
|
|
2337
|
-
const promise = work();
|
|
2338
|
-
active.set(id, promise);
|
|
2339
|
-
promise.finally(() => {
|
|
2340
|
-
active.delete(id);
|
|
2341
|
-
}).catch(() => {});
|
|
2342
|
-
return promise;
|
|
2343
|
-
},
|
|
2344
|
-
/** Counts include uncertain dispatches, which keep their reservation. No pricing is inferred. */
|
|
2345
|
-
committed() {
|
|
2346
|
-
refresh();
|
|
2347
|
-
return new Map(header.limits.map(([lane]) => [lane, counts.get(lane) ?? 0]));
|
|
2348
2321
|
}
|
|
2322
|
+
signal?.throwIfAborted();
|
|
2323
|
+
if ((journal.counts.get(lane) ?? 0) >= journal.limits.get(lane)) return {
|
|
2324
|
+
succeeded: false,
|
|
2325
|
+
reason: "allowance_exhausted",
|
|
2326
|
+
dispatchId: id
|
|
2327
|
+
};
|
|
2328
|
+
const previousRevision = journal.revision;
|
|
2329
|
+
if (commitEvent(journal, {
|
|
2330
|
+
kind: "started",
|
|
2331
|
+
id,
|
|
2332
|
+
lane
|
|
2333
|
+
})) return void 0;
|
|
2334
|
+
if (journal.revision === previousRevision) return fail("history is busy; retry with the same input");
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
/** Retain a dispatched value's result file, settle it, and return the decoded outcome. */
|
|
2338
|
+
function retainResult(journal, id, value) {
|
|
2339
|
+
const encoded = canonicalString(value);
|
|
2340
|
+
const decoded = JSON.parse(encoded);
|
|
2341
|
+
const retainedValue = journal.parse(decoded);
|
|
2342
|
+
if (canonicalString(retainedValue) !== encoded) return fail("result decoder is not stable across serialization");
|
|
2343
|
+
const receipt = hashCanonical(decoded);
|
|
2344
|
+
const retainedResult = canonicalString({
|
|
2345
|
+
kind: "retained-dispatch-result-v1",
|
|
2346
|
+
id,
|
|
2347
|
+
receipt,
|
|
2348
|
+
value: decoded
|
|
2349
|
+
});
|
|
2350
|
+
const file = resultPath(journal, id);
|
|
2351
|
+
if (journal.storage.append(file, retainedResult, 0) === void 0 && journal.storage.read(file) !== retainedResult) fail("cannot retain dispatch result");
|
|
2352
|
+
settle(journal, id, receipt);
|
|
2353
|
+
return {
|
|
2354
|
+
succeeded: true,
|
|
2355
|
+
value: retainedValue,
|
|
2356
|
+
dispatchId: id,
|
|
2357
|
+
receiptDigest: receipt,
|
|
2358
|
+
replayed: false
|
|
2349
2359
|
};
|
|
2350
2360
|
}
|
|
2361
|
+
/** Replay, claim an allowance, call the dispatch once, and retain its result. */
|
|
2362
|
+
async function dispatchOnce(journal, id, request) {
|
|
2363
|
+
const { lane, dispatch, signal } = request;
|
|
2364
|
+
if (!journal.limits.has(lane)) return fail("unknown allowance lane");
|
|
2365
|
+
refreshJournal(journal);
|
|
2366
|
+
const claimed = claimDispatch(journal, id, lane, signal);
|
|
2367
|
+
if (claimed) return claimed;
|
|
2368
|
+
let value;
|
|
2369
|
+
try {
|
|
2370
|
+
signal?.throwIfAborted();
|
|
2371
|
+
value = journal.parse(await dispatch());
|
|
2372
|
+
} catch (error) {
|
|
2373
|
+
return {
|
|
2374
|
+
succeeded: false,
|
|
2375
|
+
reason: "outcome_unknown",
|
|
2376
|
+
dispatchId: id,
|
|
2377
|
+
diagnostic: error instanceof Error ? error.message : String(error)
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
return retainResult(journal, id, value);
|
|
2381
|
+
}
|
|
2351
2382
|
//#endregion
|
|
2352
2383
|
//#region src/campaign/scenario-selection.ts
|
|
2353
2384
|
const DEFAULT_SATURATION_CEILING = .999;
|
|
@@ -2927,4 +2958,4 @@ function resolveWorktreePath(surface, worktreeDir) {
|
|
|
2927
2958
|
//#endregion
|
|
2928
2959
|
export { analyzeCrossSurfaceInteractions as S, neutralizationGate as _, createRetainedDispatch as a, loadEvalFixtureScenarios as b, runProfileMatrixSegment as c, scoreUserStory as d, scoreboardSummary as f, neutralizeText as g, sequentialOptimizationMethod as h, scoreDiscrimination as i, runProfileMatrix as l, scopedOptimizationMethod as m, resolveWorktreePath as n, createProfileMatrixPlan as o, userStoryScoreboard as p, verifyCodeSurface as r, finalizeProfileMatrix as s, gitWorktreeAdapter as t, renderScoreboardMarkdown as u, discoverEvalFixtures as v, planEvalFixtureRun as x, loadEvalFixture as y };
|
|
2929
2960
|
|
|
2930
|
-
//# sourceMappingURL=campaign-
|
|
2961
|
+
//# sourceMappingURL=campaign-CGvUTnmc.js.map
|