@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.59
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 +325 -1
- package/README.md +332 -88
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +5 -0
- package/dist/chatgpt-plan.js +25 -11
- package/dist/claude-login-token.d.ts +15 -11
- package/dist/claude-login-token.js +167 -107
- package/dist/claude-login.d.ts +76 -31
- package/dist/claude-login.js +426 -79
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-BztxEAvb.js +166 -0
- package/dist/console/assets/index-LwNL4L9q.js +619 -0
- package/dist/console/assets/share-L84tlUDW.js +6 -0
- package/dist/console/assets/styles-CaRKlHke.js +291 -0
- package/dist/console/assets/styles-DQo8rzY-.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.js +9 -6
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +8 -0
- package/dist/harness-table.js +17 -6
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import.d.ts +11 -8
- package/dist/import.js +437 -186
- package/dist/key-refusal.d.ts +9 -2
- package/dist/key-refusal.js +86 -32
- package/dist/learn/audit.d.ts +8 -5
- package/dist/learn/audit.js +15 -7
- package/dist/learn/compile.d.ts +5 -2
- package/dist/learn/compile.js +45 -21
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/promote.d.ts +79 -36
- package/dist/learn/promote.js +60 -65
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +16 -2
- package/dist/mcp-gateway.js +41 -3
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +202 -51
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +55 -34
- package/dist/place-offers.js +93 -54
- package/dist/place.d.ts +13 -14
- package/dist/place.js +56 -41
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/redact/match.d.ts +27 -9
- package/dist/redact/match.js +266 -57
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.js +16 -3
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.js +3 -1
- package/dist/runnable.js +2 -2
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +64 -28
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +8 -5
- package/dist/runner/audit.js +37 -17
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +81 -46
- package/dist/runner/compare-end.d.ts +2 -1
- package/dist/runner/compare-end.js +25 -10
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/harness-loops.js +3 -3
- package/dist/runner/held.d.ts +5 -2
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +22 -4
- package/dist/runner/learned-first.js +20 -4
- package/dist/runner/learning-end.d.ts +2 -8
- package/dist/runner/learning-end.js +11 -19
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +12 -11
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +10 -8
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +25 -13
- package/dist/runner/promotion.js +125 -50
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +20 -5
- package/dist/runner/run-child-host.js +179 -77
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +2 -3
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +8 -8
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/runs.d.ts +6 -0
- package/dist/sdk/runs.js +89 -10
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +51 -9
- package/dist/secrets.js +311 -21
- package/dist/server-keys.d.ts +4 -3
- package/dist/server-keys.js +4 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +15 -3
- package/dist/server.js +312 -80
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +33 -10
- package/dist/store/schema.js +70 -16
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +3 -0
- package/dist/store/sqlite/store.js +116 -34
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +67 -32
- package/dist/store/store.js +14 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/learning.d.ts +35 -26
- package/dist/store-reads/learning.js +120 -92
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.js +10 -7
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +50 -11
- package/dist/tool-plane.js +94 -30
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +32 -0
- package/dist/web-holds.js +86 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +75 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +35 -17
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +8 -3
- package/dist/workspace/computer-providers.js +12 -5
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +6 -0
- package/package.json +12 -13
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Checking a learned workflow, field by field, against the best answer each field has: a grade's expected answer, else
|
|
2
|
+
// the agent's own answer. Pure: rows and a bar in, a verdict out; no store, no settings, no secrets, no prose beyond
|
|
3
|
+
// each field's numbers in words. The caller turns its replays (or native turns) into rows, and stores and words what
|
|
4
|
+
// comes back (runner/promotion.ts decideCheck).
|
|
5
|
+
//
|
|
6
|
+
// A field passes when, on the inputs the workflow answered alone, its answers are right against the known answer, over
|
|
7
|
+
// all of its known inputs at once (pooled across where each input's known answer came from):
|
|
8
|
+
// - at least `agree_min` of them right;
|
|
9
|
+
// - and, on the inputs a grade gave the answer of, at least `agree_min` of them right and at most MARGIN under the
|
|
10
|
+
// agent's own accuracy on them, one miss always allowed in each (a correction, where the agent was wrong, gives no
|
|
11
|
+
// free pass; one input missed is never a hold on its own).
|
|
12
|
+
// Each row's field is judged against its own best known answer, so a field with grades on some inputs is judged against
|
|
13
|
+
// the grades there and against the agent elsewhere; one graded input missed among many the agent knows is one input of
|
|
14
|
+
// the field's floor, not a source of its own that fails. An input with no known answer on a field (the
|
|
15
|
+
// agent's answer graded wrong with none given, and the workflow said another) is unjudged there: never right, so never
|
|
16
|
+
// right on every field at once, and a field judged on fewer than `alone_min` of the inputs that carried it fails. The
|
|
17
|
+
// workflow serves only when it answered at least `alone_min` of the inputs alone, at least `agree_min` of those were
|
|
18
|
+
// right on every field at once (the joint floor: misses spread over several fields add up, and an unjudged field is not
|
|
19
|
+
// right), and every field passes; a hold names each failing field and its misses, an unjudged input among them (known
|
|
20
|
+
// "unknown": marked wrong, with no right answer to show). Field names are the caller's (agree_on paths, which never hold
|
|
21
|
+
// `__proto__`, else the whole answer): they key Maps here, never a plain object's lookup, so a name Object.prototype
|
|
22
|
+
// holds (`constructor`, `toString`) is a field like any other.
|
|
23
|
+
/** Where a field's known answer came from, strongest first. */
|
|
24
|
+
export const KNOWN = ["grade", "agent"];
|
|
25
|
+
/** How far under the agent's own accuracy a field's graded inputs may be. */
|
|
26
|
+
const MARGIN = 0.02;
|
|
27
|
+
/** JSON values equal as values: keys in any order, arrays in order. */
|
|
28
|
+
export function sameValue(a, b) {
|
|
29
|
+
if (a === b)
|
|
30
|
+
return true;
|
|
31
|
+
if (typeof a !== typeof b || a === null || b === null || typeof a !== "object")
|
|
32
|
+
return false;
|
|
33
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
34
|
+
return false;
|
|
35
|
+
if (Array.isArray(a))
|
|
36
|
+
return a.length === b.length && a.every((one, i) => sameValue(one, b[i]));
|
|
37
|
+
const [ka, kb] = [Object.keys(a), Object.keys(b)];
|
|
38
|
+
return ka.length === kb.length && ka.every((key) => Object.hasOwn(b, key) && sameValue(a[key], b[key]));
|
|
39
|
+
}
|
|
40
|
+
/** A value is right against a known one when both are there and equal; a missing value is never right. */
|
|
41
|
+
const right = (value, known) => value !== undefined && known !== undefined && sameValue(value, known);
|
|
42
|
+
/** A field's best known answer on one input, and where it came from. */
|
|
43
|
+
function knownOf(one) {
|
|
44
|
+
return one.grade !== undefined ? { value: one.grade, known: "grade" } : { value: one.agent, known: "agent" };
|
|
45
|
+
}
|
|
46
|
+
/** Whether the workflow's value on one field is right, and the agent's, against that field's best known answer;
|
|
47
|
+
* undefined when it has none (the agent's answer graded wrong with no expected one, and the workflow said another).
|
|
48
|
+
* `marked`: judged by a grade that gave no right answer (the workflow repeated the answer it marked wrong). A value equal
|
|
49
|
+
* to an answer a grade marked wrong is never right, whatever `agrees` says; where the agent gave no value, the agent is
|
|
50
|
+
* never right either. */
|
|
51
|
+
function judged(one) {
|
|
52
|
+
if (one.no_known)
|
|
53
|
+
return undefined;
|
|
54
|
+
const { value, known } = knownOf(one);
|
|
55
|
+
const repeatsWrong = one.agent_correct === false && right(one.workflow, one.agent);
|
|
56
|
+
if (known === "grade") {
|
|
57
|
+
const agent = one.agent_correct ?? right(one.agent, value);
|
|
58
|
+
return { known, expected: value, workflow: !repeatsWrong && (one.agrees ?? right(one.workflow, value)), agent };
|
|
59
|
+
}
|
|
60
|
+
const same = one.agrees ?? right(one.workflow, one.agent);
|
|
61
|
+
if (one.agent_correct === false)
|
|
62
|
+
return same || repeatsWrong ? { known: "grade", expected: undefined, workflow: false, agent: false, marked: true } : undefined;
|
|
63
|
+
return { known, expected: value, workflow: same, agent: one.agent !== undefined };
|
|
64
|
+
}
|
|
65
|
+
const NO_TALLY = { n: 0, alone: 0, agreed: 0, agent_agreed: 0, fields: {} };
|
|
66
|
+
/** `rows` counted, added to `before` (a check's inputs counted so far). */
|
|
67
|
+
export function tallyOf(rows, before = NO_TALLY) {
|
|
68
|
+
let { n, alone, agreed, agent_agreed: agentAgreed } = before;
|
|
69
|
+
const fields = new Map(Object.entries(before.fields).map(([name, by]) => [name, countsOf(by)]));
|
|
70
|
+
for (const row of rows) {
|
|
71
|
+
if (row.outcome === "skipped")
|
|
72
|
+
continue;
|
|
73
|
+
n += 1;
|
|
74
|
+
if (row.outcome !== "answered")
|
|
75
|
+
continue;
|
|
76
|
+
alone += 1;
|
|
77
|
+
let all = true;
|
|
78
|
+
let agentAll = true;
|
|
79
|
+
for (const [name, one] of Object.entries(row.fields ?? {})) {
|
|
80
|
+
const j = judged(one);
|
|
81
|
+
const by = fields.get(name) ?? {};
|
|
82
|
+
fields.set(name, by);
|
|
83
|
+
if (!j) {
|
|
84
|
+
// No known answer: not right, and the agent's answer was graded wrong.
|
|
85
|
+
by.unjudged = (by.unjudged ?? 0) + 1;
|
|
86
|
+
all = false;
|
|
87
|
+
agentAll = false;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const was = by[j.known] ?? { n: 0, workflow_right: 0, agent_right: 0 };
|
|
91
|
+
by[j.known] = { n: was.n + 1, workflow_right: was.workflow_right + (j.workflow ? 1 : 0), agent_right: was.agent_right + (j.agent ? 1 : 0) };
|
|
92
|
+
if (!j.workflow)
|
|
93
|
+
all = false;
|
|
94
|
+
if (!j.agent)
|
|
95
|
+
agentAll = false;
|
|
96
|
+
}
|
|
97
|
+
if (all)
|
|
98
|
+
agreed += 1;
|
|
99
|
+
if (agentAll)
|
|
100
|
+
agentAgreed += 1;
|
|
101
|
+
}
|
|
102
|
+
return { n, alone, agreed, agent_agreed: agentAgreed, fields: Object.fromEntries(fields) };
|
|
103
|
+
}
|
|
104
|
+
/** A field's counts, copied: only the sources KNOWN names and its unjudged count, whatever else the object holds. */
|
|
105
|
+
const countsOf = (by) => ({
|
|
106
|
+
...Object.fromEntries(KNOWN.flatMap((known) => (Object.hasOwn(by, known) && by[known] ? [[known, { ...by[known] }]] : []))),
|
|
107
|
+
...(Object.hasOwn(by, "unjudged") && typeof by.unjudged === "number" && by.unjudged > 0 ? { unjudged: by.unjudged } : {}),
|
|
108
|
+
});
|
|
109
|
+
/** The misses in `rows`: each field the workflow had wrong on an input it answered alone, inputs in order, and each it
|
|
110
|
+
* had no known answer on (never right), no value: "contradicts" where its grade contradicts itself, else "unknown". */
|
|
111
|
+
export function missesOf(rows) {
|
|
112
|
+
return rows.flatMap((row) => row.outcome !== "answered" ? [] : Object.entries(row.fields ?? {}).flatMap(([field, one]) => {
|
|
113
|
+
const j = judged(one);
|
|
114
|
+
if (j?.workflow)
|
|
115
|
+
return [];
|
|
116
|
+
return [{ field, input_id: row.input_id, workflow: one.workflow, expected: j?.expected, known: one.no_known ? "contradicts" : !j || j.marked ? "unknown" : j.known }];
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
/** At least `share` of `n`, counted in whole inputs. Bars are decimals (0.8), so the product is rounded off its float
|
|
120
|
+
* noise before it is rounded up: 0.9 of 20 needs 18, never 19. */
|
|
121
|
+
const atLeast = (count, share, n) => count >= Math.ceil(Math.round(share * n * 1e6) / 1e6);
|
|
122
|
+
const pct = (value) => `${(value * 100).toFixed(1)}%`;
|
|
123
|
+
const share = (count, n) => pct(n ? count / n : 0);
|
|
124
|
+
/** The misses `n` inputs may have under a share `share` of them, one at least: one input missed is never a hold alone. */
|
|
125
|
+
const missesAllowed = (share, n) => Math.max(1, Math.floor(Math.round(share * n * 1e6) / 1e6));
|
|
126
|
+
/** Whether a field's graded inputs keep their bar: at least agree_min of them right and workflow_right / n >=
|
|
127
|
+
* agent_right / n - MARGIN (the workflow may be MARGIN * n inputs under the agent), one miss always allowed in each. */
|
|
128
|
+
const keepsGraded = (count, bar) => count.n - count.workflow_right <= missesAllowed(1 - bar.agree_min, count.n) && count.agent_right - count.workflow_right <= missesAllowed(MARGIN, count.n);
|
|
129
|
+
/** One source's counts in words. */
|
|
130
|
+
const sourceWords = (known, count, bar) => known === "agent"
|
|
131
|
+
? `${count.workflow_right} of ${count.n} said what the agent said (${share(count.workflow_right, count.n)}, the bar ${pct(bar.agree_min)})`
|
|
132
|
+
: `${count.workflow_right} of ${count.n} right against the grades' expected answers (${share(count.workflow_right, count.n)}, the bar ${pct(bar.agree_min)}), the agent ${count.agent_right} (${share(count.agent_right, count.n)}; at most ${pct(MARGIN)} under it), one miss allowed in each`;
|
|
133
|
+
/** `tally` judged on `bar`. A field passes on three tests: over all its known inputs pooled, at least agree_min of them
|
|
134
|
+
* right (the floor); its graded inputs keep their bar (keepsGraded: agree_min and MARGIN, one miss allowed in each);
|
|
135
|
+
* and it was judged on at least `alone_min` of the inputs that carried it. It fails with no input. So agent-known
|
|
136
|
+
* inputs never carry graded ones the draft got wrong past one miss, and one graded input missed is never a hold alone. */
|
|
137
|
+
export function verdictOf(tally, bar) {
|
|
138
|
+
const fields = new Map();
|
|
139
|
+
for (const [name, stored] of Object.entries(tally.fields)) {
|
|
140
|
+
const by = countsOf(stored);
|
|
141
|
+
const sources = KNOWN.filter((known) => (by[known]?.n ?? 0) > 0);
|
|
142
|
+
const sum = (key) => sources.reduce((total, known) => total + by[known][key], 0);
|
|
143
|
+
const unjudged = by.unjudged ?? 0;
|
|
144
|
+
const carried = sum("n") + unjudged;
|
|
145
|
+
// Judged on enough of the inputs that carried it: unknown answers never stand in for known ones.
|
|
146
|
+
const enough = atLeast(sum("n"), bar.alone_min, carried);
|
|
147
|
+
const floor = atLeast(sum("workflow_right"), bar.agree_min, sum("n"));
|
|
148
|
+
const graded = by.grade;
|
|
149
|
+
const pass = sources.length > 0 && floor && (!graded?.n || keepsGraded(graded, bar)) && enough;
|
|
150
|
+
const words = [
|
|
151
|
+
...sources.map((known) => sourceWords(known, by[known], bar)),
|
|
152
|
+
...(sources.length > 1 ? [`in all: ${sum("workflow_right")} of ${sum("n")} right (${share(sum("workflow_right"), sum("n"))}, the bar ${pct(bar.agree_min)})`] : []),
|
|
153
|
+
...(unjudged ? [`judged on ${sum("n")} of ${carried} (${share(sum("n"), carried)}, the bar ${pct(bar.alone_min)}): ${unjudged} had no known answer (graded wrong with none given and the workflow said another, or a grade that contradicts itself)`] : []),
|
|
154
|
+
];
|
|
155
|
+
fields.set(name, {
|
|
156
|
+
n: sum("n"), workflow_right: sum("workflow_right"), agent_right: graded?.agent_right ?? 0, ...(unjudged ? { unjudged } : {}), known: sources[0] ?? "agent", pass,
|
|
157
|
+
reason: words.length ? `${name}: ${words.join("; ")}` : `${name}: no input answered alone`,
|
|
158
|
+
by: Object.fromEntries(sources.map((known) => [known, { ...by[known] }])),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const alone_pass = tally.alone > 0 && atLeast(tally.alone, bar.alone_min, tally.n);
|
|
162
|
+
const joint = { agreed: tally.agreed, alone: tally.alone, pass: tally.alone > 0 && atLeast(tally.agreed, bar.agree_min, tally.alone) };
|
|
163
|
+
const failing = [...fields].filter(([, one]) => !one.pass).map(([name]) => name);
|
|
164
|
+
const serve = alone_pass && joint.pass && fields.size > 0 && failing.length === 0;
|
|
165
|
+
return { verdict: serve ? "serve" : "hold", tally, alone_pass, joint, fields: Object.fromEntries(fields), failing };
|
|
166
|
+
}
|
|
167
|
+
/** Checks a workflow on `rows`, with the inputs a check counted before them (`before`), against `bar`. */
|
|
168
|
+
export function check(rows, bar, before) {
|
|
169
|
+
return { ...verdictOf(tallyOf(rows, before), bar), misses: missesOf(rows) };
|
|
170
|
+
}
|
|
171
|
+
/** Whether a verdict's words say the joint floor: when it says more than one field's own count, with two or more fields,
|
|
172
|
+
* or with one that passed while the joint fell short (inputs with no known answer kept it from being right on all).
|
|
173
|
+
* `fields`: each field's pass; `joint`: the joint floor's. */
|
|
174
|
+
export const jointSaid = (fields, joint) => fields.length > 1 || (fields.length === 1 && !joint && fields[0]);
|
package/dist/learn/ledger.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type Bill, type CostRun, type CostSummary, type NotServed, type RevisionSpend, type RunPath } from "../learning-cost.js";
|
|
1
|
+
import { type Bill, type CostRun, type CostSummary, type NotServed, type RevisionSpend, type RunPath, type WorkflowCall } from "../learning-cost.js";
|
|
2
|
+
import { type RunRow } from "../store/store.js";
|
|
2
3
|
/** A run's own cost as its row stores it: `known`, an exact figure; `unknown`, none; `at_most`, only a bound (a request
|
|
3
4
|
* cut at its cap hold), never shown as a cost. */
|
|
4
5
|
export declare const COST_STATES: readonly ["known", "unknown", "at_most"];
|
|
@@ -6,7 +7,9 @@ export type CostState = (typeof COST_STATES)[number];
|
|
|
6
7
|
/** One ended run: who answered it (`path`, null when its end named none), the learned workflow revision that ran it
|
|
7
8
|
* (`workflow` at `digest`; for an audit's shadow, the revision it audits), why that workflow did not serve it alone,
|
|
8
9
|
* the job's own $ (`jobUsd`: what it had cost when its answer was final, its look-back left out) and everything its
|
|
9
|
-
* rounds looked back for (`lookBackUsd`: its compile turns and its follow-up rounds' turns); each null when unknown
|
|
10
|
+
* rounds looked back for (`lookBackUsd`: its compile turns and its follow-up rounds' turns); each null when unknown; and
|
|
11
|
+
* every learned workflow call it made (`workflowCalls`: its metrics' `workflow_calls`, the platform's and the agent's,
|
|
12
|
+
* each with its digest, caller, outcome and booked $), none for a run that made none. */
|
|
10
13
|
export type LedgerRow = {
|
|
11
14
|
readonly runId: string;
|
|
12
15
|
readonly agentId: string;
|
|
@@ -18,6 +21,7 @@ export type LedgerRow = {
|
|
|
18
21
|
readonly jobUsd: number | null;
|
|
19
22
|
readonly lookBackUsd: number | null;
|
|
20
23
|
readonly cost: CostState;
|
|
24
|
+
readonly workflowCalls: readonly WorkflowCall[];
|
|
21
25
|
};
|
|
22
26
|
/** What a spend row paid for: a compile turn that drafted a revision (`compile`), a replay run checking one (`check`), or
|
|
23
27
|
* an audit's shadow run of a served run (`audit`). */
|
|
@@ -37,7 +41,9 @@ export type SpendRow = {
|
|
|
37
41
|
readonly usd: number | null;
|
|
38
42
|
};
|
|
39
43
|
/** What record() reads of an ended run: its row (its cost, the bound beside it, its metrics: the run-end classifier's
|
|
40
|
-
* path, workflow and digest, runner/workflow-first.ts pathMetrics)
|
|
44
|
+
* path, workflow and digest, runner/workflow-first.ts pathMetrics), every round its learning kept (learning_proposals)
|
|
45
|
+
* and, for an audit's shadow run, the run its launch audits (`auditOf`: its end may name no audit, when it failed first).
|
|
46
|
+
* `learns`: whether its launch learns (learnsOfLaunch); false, an end that named no path is the agent's. */
|
|
41
47
|
export type RunEnd = {
|
|
42
48
|
readonly id: string;
|
|
43
49
|
readonly agentId: string;
|
|
@@ -49,7 +55,15 @@ export type RunEnd = {
|
|
|
49
55
|
readonly round: number;
|
|
50
56
|
readonly proposal: unknown;
|
|
51
57
|
}[];
|
|
58
|
+
readonly auditOf?: string | null;
|
|
59
|
+
readonly learns?: boolean;
|
|
52
60
|
};
|
|
61
|
+
/** RunEnd.auditOf of run `runId` from its stored launch body (`body`, undefined with none): the run its launch audits
|
|
62
|
+
* (null when it names none) for an audit's shadow run (learn/audit.ts SHADOW_PREFIX "audit."), undefined for any other. */
|
|
63
|
+
export declare const auditOfLaunch: (runId: string, body: unknown) => string | null | undefined;
|
|
64
|
+
/** RunEnd.learns from a run's stored launch body (`body`, undefined with none): whether it holds a learning start, as
|
|
65
|
+
* run-launch.ts learningStartOfStored reads one. No launch reads as a run that does not learn. */
|
|
66
|
+
export declare const learnsOfLaunch: (body: unknown) => boolean;
|
|
53
67
|
/** What a kept round says of its job as it answered (runner/reflect-hook.ts): when, what the job had cost by then, and
|
|
54
68
|
* what looking back cost after it. */
|
|
55
69
|
export type Answered = {
|
|
@@ -80,22 +94,10 @@ export declare function record(end: RunEnd): {
|
|
|
80
94
|
row: LedgerRow;
|
|
81
95
|
spend: SpendRow[];
|
|
82
96
|
};
|
|
83
|
-
/** The audit spend row of shadow run `shadow` of run `ofRun`, from its row alone: for a shadow whose end named no audit
|
|
84
|
-
* (it failed before its end wrote its metrics), found by its id (learn/audit.ts shadowRunId). Its cost is the row's,
|
|
85
|
-
* null when unknown or only a bound. */
|
|
86
|
-
export declare function shadowSpend(shadow: Pick<RunEnd, "id" | "agentId" | "costUsd" | "costAtMostUsd">, ofRun: string): SpendRow;
|
|
87
97
|
/** An audit's shadow run of a run, as the reader finds it: `open` while it is queued or running (its cost not known yet),
|
|
88
98
|
* `ended` once it ended, stopped or failed. A run with none has no entry. */
|
|
89
99
|
export type Shadow = "open" | "ended";
|
|
90
|
-
/** A run's figures,
|
|
91
|
-
* - `usd`: the job's own $ (GET /runs/{id} `cost.usd`, the series' `cost_usd`);
|
|
92
|
-
* - `compile_usd`, `followup_usd`, `shadow_usd`: its own compile turns, the rest of its look-back (its follow-up rounds'
|
|
93
|
-
* turns) and its audit's shadow run;
|
|
94
|
-
* - `share_usd`: its share of its revision's compile and check (amortize), 0 for a run that carries none;
|
|
95
|
-
* - `series_learning_usd` and `series_total_usd`: the cost series' `learning_usd` (its whole look-back and its shadow)
|
|
96
|
-
* and `total_usd`, the all-in both sides of the money rule read;
|
|
97
|
-
* - `learning_usd` and `all_in_usd`: GET /runs/{id}'s (its follow-ups, its shadow and its share: its compile turns are
|
|
98
|
-
* its revision's), 0 for a replay or a shadow run, whose spend is on the runs it serves. */
|
|
100
|
+
/** A run's figures (figuresOf), null when unknown: `series_*` are the cost series', the rest GET /runs/{id}'s. */
|
|
99
101
|
export type RunFigures = {
|
|
100
102
|
readonly usd: number | null;
|
|
101
103
|
readonly compile_usd: number | null;
|
|
@@ -119,8 +121,19 @@ export declare function spendByRun(spend: readonly SpendRow[]): {
|
|
|
119
121
|
compile: Map<string, number | null>;
|
|
120
122
|
audit: Map<string, number | null>;
|
|
121
123
|
};
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
+
/** An audit's shadow run as its cost reads: `ended` once it is final (FINAL_STATES), `usd` its cost (null while unknown
|
|
125
|
+
* or only a bound). */
|
|
126
|
+
export type ShadowCost = {
|
|
127
|
+
readonly ended: boolean;
|
|
128
|
+
readonly usd: number | null;
|
|
129
|
+
};
|
|
130
|
+
/** A shadow run's row as a ShadowCost. */
|
|
131
|
+
export declare const shadowOfRun: (run: Pick<RunRow, "state" | "costUsd" | "costAtMostUsd">) => ShadowCost;
|
|
132
|
+
/** A run's shadow cost, the one rule the ledger, GET /stats and analytics read: 0 with no shadow (undefined); unknown
|
|
133
|
+
* (null) while it is queued or running, or once it ended at an unknown cost, never $0; its cost once known. */
|
|
134
|
+
export declare const shadowUsdOf: (shadow: ShadowCost | undefined) => number | null;
|
|
135
|
+
/** A run's shadow cost (shadowUsdOf) from the reader's shadows and the audit spend rows: an ended shadow costs its
|
|
136
|
+
* spend row's, unknown with none. */
|
|
124
137
|
export declare function shadowCostOf(runId: string, audit: ReadonlyMap<string, number | null>, shadows: ReadonlyMap<string, Shadow>): number | null;
|
|
125
138
|
/** A revision of a learned workflow as its records say it now (store-reads/learning.ts revisionsOf): the served runs its
|
|
126
139
|
* spend is spread over (`k`, its check's compile_after) and where it stands. Order is the records'. */
|
|
@@ -130,17 +143,7 @@ export type RevisionAt = {
|
|
|
130
143
|
readonly k: number;
|
|
131
144
|
readonly state: RevisionSpend["state"];
|
|
132
145
|
};
|
|
133
|
-
/** What summarize reads:
|
|
134
|
-
* - `rows`, the runs of the series (ended, neither imported nor archived nor purged, no workflow revision's run, no
|
|
135
|
-
* shadow), any order, each with its path (null: its end named none);
|
|
136
|
-
* - `spend`, the agent's spend rows: a compile or a check of a run `rows` leaves out is left out as its run is, an
|
|
137
|
-
* audit's by the run it audits;
|
|
138
|
-
* - `shadows`, each run's audit shadow by the run it audits;
|
|
139
|
-
* - `learning`, the runs of `rows` whose spend and service make up a revision's (on no named disk: one on a named disk
|
|
140
|
-
* learns nothing and serves nothing, learn/learning-of.ts); absent, every one;
|
|
141
|
-
* - `revisions`, as the records say them; `compileAfter`, the K of a revision no record names;
|
|
142
|
-
* - `named`, the workflow name a run's series row shows (its row's when absent).
|
|
143
|
-
* The summary's `replay` is the records' (store-reads/learning.ts servingReplayOf), null here. */
|
|
146
|
+
/** What summarize reads: the series' rows and spend, shadows by audited run, learning runs (absent: all), revisions. */
|
|
144
147
|
export type LedgerRead = {
|
|
145
148
|
readonly rows: readonly LedgerRow[];
|
|
146
149
|
readonly spend: readonly SpendRow[];
|
package/dist/learn/ledger.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// transaction (store/sqlite/run-patch.ts); summarize() is the one reading of them, which GET /agents/{id}/learning/cost,
|
|
4
4
|
// GET /runs/{id}'s cost and the money rule (runner/workflow-first.ts costLineOf, over RunFigures) all take. Pure: no
|
|
5
5
|
// store, no clock.
|
|
6
|
-
import { amortize, billOf, costSummary, JOB_PATHS, NOT_SERVED, noiseOff, RUN_PATHS, SERVED_PATHS, tookOverOf } from "../learning-cost.js";
|
|
6
|
+
import { amortize, billOf, costSummary, JOB_PATHS, NOT_SERVED, noiseOff, RUN_PATHS, SERVED_PATHS, tookOverOf, workflowCallsIn } from "../learning-cost.js";
|
|
7
|
+
import { FINAL_STATES } from "../store/store.js";
|
|
7
8
|
/** A run's own cost as its row stores it: `known`, an exact figure; `unknown`, none; `at_most`, only a bound (a request
|
|
8
9
|
* cut at its cap hold), never shown as a cost. */
|
|
9
10
|
export const COST_STATES = ["known", "unknown", "at_most"];
|
|
@@ -13,6 +14,12 @@ export const SPEND_KINDS = ["compile", "check", "audit"];
|
|
|
13
14
|
const usdOrNull = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
|
|
14
15
|
const textOrNull = (value) => (typeof value === "string" ? value : null);
|
|
15
16
|
const objectOf = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : {});
|
|
17
|
+
/** RunEnd.auditOf of run `runId` from its stored launch body (`body`, undefined with none): the run its launch audits
|
|
18
|
+
* (null when it names none) for an audit's shadow run (learn/audit.ts SHADOW_PREFIX "audit."), undefined for any other. */
|
|
19
|
+
export const auditOfLaunch = (runId, body) => runId.startsWith("audit.") ? textOrNull(objectOf(objectOf(body).audit).of) : undefined;
|
|
20
|
+
/** RunEnd.learns from a run's stored launch body (`body`, undefined with none): whether it holds a learning start, as
|
|
21
|
+
* run-launch.ts learningStartOfStored reads one. No launch reads as a run that does not learn. */
|
|
22
|
+
export const learnsOfLaunch = (body) => objectOf(body).learning !== undefined;
|
|
16
23
|
/** A sum of parts, null once one is unknown; 0 for none. */
|
|
17
24
|
const sumOf = (parts) => (parts.some((one) => one === null) ? null : noiseOff(parts.reduce((total, one) => total + one, 0)));
|
|
18
25
|
/** A kept round's Answered; undefined for one that never answered. */
|
|
@@ -80,9 +87,13 @@ export function record(end) {
|
|
|
80
87
|
// What the row holds past the answer and its look-back is a later turn's spend, unknown once the row's cost is; with the
|
|
81
88
|
// look-back's cost unknown the two can't be told apart, and the job is what it had cost when it answered.
|
|
82
89
|
const job = !looked || asAnswered === null || back === null ? asAnswered : rowUsd === null ? null : Math.max(asAnswered, rowUsd - back);
|
|
83
|
-
const
|
|
90
|
+
const audited = metrics.path === "audit" || end.auditOf !== undefined;
|
|
91
|
+
// The one by-hand rule (the window's read and Learning.byHandBefore read the row's path, each leaving a workflow
|
|
92
|
+
// revision's runs out): a run whose end named no path is the agent's when its launch does not learn; one that learns
|
|
93
|
+
// and named none is unknown (null).
|
|
94
|
+
const named = RUN_PATHS.includes(metrics.path) ? metrics.path : null;
|
|
95
|
+
const path = audited ? "audit" : named ?? (end.learns === false ? "agent" : null);
|
|
84
96
|
const audit = objectOf(metrics.audit);
|
|
85
|
-
const audited = path === "audit";
|
|
86
97
|
const workflow = textOrNull(audited ? audit.workflow : metrics.workflow);
|
|
87
98
|
const digest = textOrNull(audited ? audit.digest : metrics.workflow_digest);
|
|
88
99
|
// A hand-back a restart cut (pathMetrics workflow_cut) is `cut`, never the workflow's own `back`.
|
|
@@ -90,23 +101,16 @@ export function record(end) {
|
|
|
90
101
|
const notServed = cut ? "cut" : NOT_SERVED.includes(metrics.not_served) ? metrics.not_served : null;
|
|
91
102
|
const row = {
|
|
92
103
|
runId: end.id, agentId: end.agentId, startedAt: end.startedAt, path, workflow, digest, notServed,
|
|
93
|
-
jobUsd: job === null ? null : noiseOff(job), lookBackUsd: back === null ? null : noiseOff(back), cost,
|
|
104
|
+
jobUsd: job === null ? null : noiseOff(job), lookBackUsd: back === null ? null : noiseOff(back), cost, workflowCalls: workflowCallsIn(metrics),
|
|
94
105
|
};
|
|
95
106
|
const base = { runId: end.id, agentId: end.agentId };
|
|
96
107
|
const spend = compilesIn(rounds).map((one) => ({ ...base, round: one.round, kind: "compile", ofRun: null, workflow: one.workflow, digest: one.digest, usd: one.usd }));
|
|
97
108
|
if (path === "replay")
|
|
98
109
|
spend.push({ ...base, round: 0, kind: "check", ofRun: null, workflow, digest, usd: rowUsd });
|
|
99
110
|
if (audited)
|
|
100
|
-
spend.push({ ...base, round: 0, kind: "audit", ofRun: textOrNull(audit.of), workflow, digest, usd: rowUsd });
|
|
111
|
+
spend.push({ ...base, round: 0, kind: "audit", ofRun: textOrNull(audit.of) ?? end.auditOf ?? null, workflow, digest, usd: rowUsd });
|
|
101
112
|
return { row, spend };
|
|
102
113
|
}
|
|
103
|
-
/** The audit spend row of shadow run `shadow` of run `ofRun`, from its row alone: for a shadow whose end named no audit
|
|
104
|
-
* (it failed before its end wrote its metrics), found by its id (learn/audit.ts shadowRunId). Its cost is the row's,
|
|
105
|
-
* null when unknown or only a bound. */
|
|
106
|
-
export function shadowSpend(shadow, ofRun) {
|
|
107
|
-
const usd = typeof shadow.costAtMostUsd === "number" ? null : shadow.costUsd;
|
|
108
|
-
return { runId: shadow.id, agentId: shadow.agentId, round: 0, kind: "audit", ofRun, workflow: null, digest: null, usd };
|
|
109
|
-
}
|
|
110
114
|
/** One run's figures (RunFigures) from its row and the parts the spend rows give it (its compile turns, its shadow's
|
|
111
115
|
* cost, its share): the one formula every reader of a run's cost takes. */
|
|
112
116
|
export function figuresOf(row, parts) {
|
|
@@ -135,15 +139,18 @@ export function spendByRun(spend) {
|
|
|
135
139
|
}
|
|
136
140
|
return { compile, audit };
|
|
137
141
|
}
|
|
138
|
-
/** A run's
|
|
139
|
-
|
|
142
|
+
/** A shadow run's row as a ShadowCost. */
|
|
143
|
+
export const shadowOfRun = (run) => ({ ended: FINAL_STATES.includes(run.state), usd: typeof run.costAtMostUsd === "number" ? null : run.costUsd });
|
|
144
|
+
/** A run's shadow cost, the one rule the ledger, GET /stats and analytics read: 0 with no shadow (undefined); unknown
|
|
145
|
+
* (null) while it is queued or running, or once it ended at an unknown cost, never $0; its cost once known. */
|
|
146
|
+
export const shadowUsdOf = (shadow) => (shadow === undefined ? 0 : shadow.ended ? shadow.usd : null);
|
|
147
|
+
/** A run's shadow cost (shadowUsdOf) from the reader's shadows and the audit spend rows: an ended shadow costs its
|
|
148
|
+
* spend row's, unknown with none. */
|
|
140
149
|
export function shadowCostOf(runId, audit, shadows) {
|
|
141
150
|
const state = shadows.get(runId);
|
|
142
|
-
if (state ===
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
return audit.get(runId);
|
|
146
|
-
return state === "ended" ? null : 0;
|
|
151
|
+
if (state === undefined && !audit.has(runId))
|
|
152
|
+
return 0;
|
|
153
|
+
return shadowUsdOf({ ended: state !== "open", usd: audit.has(runId) ? audit.get(runId) : null });
|
|
147
154
|
}
|
|
148
155
|
/** What the ledger says over an agent's series: each run of it (`runs`, oldest first, every one), what they show
|
|
149
156
|
* (`summary`), the owner's bill (`bill`, its holds aside: they are the records'), each run's figures by id (`figures`)
|
package/dist/learn/promote.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { RunPath } from "../learning-cost.js";
|
|
|
2
2
|
import type { FeedbackRound, OpenedRound } from "../runner/feedback-round.js";
|
|
3
3
|
import type { Settings } from "../store/store.js";
|
|
4
4
|
import type { Skipped } from "./replay-calls.js";
|
|
5
|
+
import { type CheckTally, type FieldVerdict } from "./field-check.js";
|
|
5
6
|
import type { ReplayOutcome } from "../runner/workflow-first.js";
|
|
6
7
|
/** How many grades, and how many promotion records, an agent keeps (newest kept). */
|
|
7
8
|
export declare const GRADES_KEPT = 500;
|
|
@@ -38,10 +39,10 @@ export interface Grade {
|
|
|
38
39
|
readonly feedbackCommand?: number;
|
|
39
40
|
}
|
|
40
41
|
/** What a replay says, the shape a replay's read keeps (SPEC: replay {n, agree, agent_acc, wf_acc, delta}): `n` inputs;
|
|
41
|
-
* `agree`, how many the workflow answered alone
|
|
42
|
-
* them
|
|
43
|
-
* `delta` = wf_acc - agent_acc; `handed_back`, how many it handed back (it answered
|
|
44
|
-
*
|
|
42
|
+
* `agree`, how many the workflow answered alone right on every field (CheckRecord.agreed); `agent_acc`, the agent's
|
|
43
|
+
* accuracy on them against the same known answers (CheckRecord.agent_agreed); `wf_acc`, the workflow's, a hand-back
|
|
44
|
+
* counting as the agent's answer; `delta` = wf_acc - agent_acc; `handed_back`, how many it handed back (it answered
|
|
45
|
+
* n - handed_back alone). Accuracies to 1e-4. */
|
|
45
46
|
export interface ReplayScore {
|
|
46
47
|
readonly n: number;
|
|
47
48
|
readonly agree: number;
|
|
@@ -50,9 +51,6 @@ export interface ReplayScore {
|
|
|
50
51
|
readonly delta: number;
|
|
51
52
|
readonly handed_back: number;
|
|
52
53
|
}
|
|
53
|
-
/** Whether a replay answered alone on at least one of its inputs: one that hands back every input would never serve. The
|
|
54
|
-
* one spelling of it (the compile's held line); the count is n - handed_back. */
|
|
55
|
-
export declare const answersAlone: (score: Pick<ReplayScore, "n" | "handed_back">) => boolean;
|
|
56
54
|
/** A learned workflow's promotion record at one digest. `decided`: `promote` (it serves first), `hold` (it does not: the
|
|
57
55
|
* champion, championOf, takes its runs, else the agent, until a new revision) or `replaying` (its check's replay runs,
|
|
58
56
|
* `runs`, are at work; the champion serves meanwhile, else the agent). `check`: the bar it was checked at and the
|
|
@@ -92,8 +90,9 @@ export interface PromotionRecord {
|
|
|
92
90
|
}
|
|
93
91
|
/** One audit row a hold was decided on that disagreed: the served run (`served`) and its input, the run whose answer is
|
|
94
92
|
* the agent's (`run`: the shadow run, else the served run for a grade), the agent's answer (`agent`: the shadow's, null
|
|
95
|
-
* for a grade
|
|
96
|
-
*
|
|
93
|
+
* for a grade) and the served answer (`draft`); `graded`, a row an owner's grade wrote, with the right answer it gave
|
|
94
|
+
* (`expected`, its JSON: the known answer the served one missed; absent where it gave none). Each text cut to
|
|
95
|
+
* CHECK_TEXT_MAX: what the one recompile reads as data. */
|
|
97
96
|
export interface AuditDisagreement {
|
|
98
97
|
readonly run: string;
|
|
99
98
|
readonly served: string;
|
|
@@ -101,6 +100,7 @@ export interface AuditDisagreement {
|
|
|
101
100
|
readonly agent: string | null;
|
|
102
101
|
readonly draft: string | null;
|
|
103
102
|
readonly graded?: true;
|
|
103
|
+
readonly expected?: string;
|
|
104
104
|
}
|
|
105
105
|
/** An audit hold (runner/audit.ts): the definition's `hold_window` and `hold_disagree` it was decided at, how many rows
|
|
106
106
|
* it read (`rows`, at most the window), the disagreeing ones, and `stopped` when it was a second hold within
|
|
@@ -134,9 +134,25 @@ export interface CheckDisagreement {
|
|
|
134
134
|
readonly failed?: true;
|
|
135
135
|
/** The decision the grader said they differ on, or why its verdict could not be had (cut to CHECK_TEXT_MAX). */
|
|
136
136
|
readonly differs_on?: string;
|
|
137
|
+
/** The fields the draft's answer had wrong on it, against each field's known answer (CheckRecord.fields): agree_on's
|
|
138
|
+
* paths (the definition's names), else `answer`, the whole answer. Never a name taken from a grade. */
|
|
139
|
+
readonly fields?: readonly string[];
|
|
140
|
+
/** Of those, each one known from a grade (never the agent's own answer, `agent` above): the known answer
|
|
141
|
+
* (its text or JSON, cut to CHECK_TEXT_MAX) and where it came from, which the recompile is asked to say; or
|
|
142
|
+
* "unknown", no value, where a grade marked the agent's answer wrong without giving the right one; or "contradicts", no
|
|
143
|
+
* value, where the grade marked it wrong yet the right answer it gave is the agent's. */
|
|
144
|
+
readonly expected?: readonly CheckKnown[];
|
|
137
145
|
}
|
|
138
|
-
/** A
|
|
139
|
-
*
|
|
146
|
+
/** A known answer a draft missed on one field of one input: the field, its source, and the value as text; none when the
|
|
147
|
+
* grade gave no right answer ("unknown") or contradicts itself ("contradicts"). */
|
|
148
|
+
export type CheckKnown = {
|
|
149
|
+
readonly field: string;
|
|
150
|
+
readonly known: "grade" | "unknown" | "contradicts";
|
|
151
|
+
readonly value?: string;
|
|
152
|
+
};
|
|
153
|
+
/** A check's numbers, once decided: `n` inputs it ran on (a skipped write is none), `agreed` of them answered alone right
|
|
154
|
+
* on every field, `alone` answered alone (no escalate, no failed step), each field's verdict (`fields`,
|
|
155
|
+
* learn/field-check.ts: its counts, the source of its known answer, whether it passed and why); the inputs (`of`, the
|
|
140
156
|
* agent's runs), what its replay runs cost, their outcomes (one per input: a replay run never created by the deadline
|
|
141
157
|
* failed), how many of its replay runs were never created (`unstarted`, when any), the tools that stopped its skipped
|
|
142
158
|
* inputs, the inputs it did not agree on, and `stopped` when a recompile's check held it too (nothing compiles again). */
|
|
@@ -144,6 +160,13 @@ export type CheckRecord = CheckBar & {
|
|
|
144
160
|
readonly n?: number;
|
|
145
161
|
readonly agreed?: number;
|
|
146
162
|
readonly alone?: number;
|
|
163
|
+
/** Of `alone`, how many the agent's own answers were right on every field, against the same known answers (an answer
|
|
164
|
+
* graded wrong is its miss): the agent's side of `agreed`. Set with `agreed` on every decided check. */
|
|
165
|
+
readonly agent_agreed?: number;
|
|
166
|
+
/** The joint floor's verdict, as the check decided it (learn/field-check.ts CheckVerdict.joint.pass): of `alone`, at
|
|
167
|
+
* least `agree_min` right on every field at once. What a hold's words and the cost summary's `cleared` read. */
|
|
168
|
+
readonly joint?: boolean;
|
|
169
|
+
readonly fields?: Readonly<Record<string, FieldVerdict>>;
|
|
147
170
|
readonly of?: readonly string[];
|
|
148
171
|
readonly cost_usd?: number | null;
|
|
149
172
|
readonly outcomes?: ReplayOutcomes;
|
|
@@ -167,13 +190,15 @@ export type CheckRecord = CheckBar & {
|
|
|
167
190
|
readonly grader?: string;
|
|
168
191
|
};
|
|
169
192
|
/** A connected agent's checked native turns before its check decides, counted as a decided check counts its inputs:
|
|
170
|
-
* `n` turns, `agreed` and `alone` of them,
|
|
171
|
-
* deadline failed), each turn it did not agree on, and
|
|
172
|
-
* texts cut as a decided check's are. */
|
|
193
|
+
* `n` turns, `agreed` and `alone` of them, each field's counts (`fields`, learn/field-check.ts CheckTally), the agent's
|
|
194
|
+
* runs (`of`, newest first), one outcome per turn (a turn past its deadline failed), each turn it did not agree on, and
|
|
195
|
+
* the shadows' fresh reads. Each is compared on its own turn, its texts cut as a decided check's are. */
|
|
173
196
|
export interface CheckTurns {
|
|
174
197
|
readonly n: number;
|
|
175
198
|
readonly agreed: number;
|
|
176
199
|
readonly alone: number;
|
|
200
|
+
readonly agent_agreed: number;
|
|
201
|
+
readonly fields: CheckTally["fields"];
|
|
177
202
|
readonly of: readonly string[];
|
|
178
203
|
readonly outcomes: ReplayOutcomes;
|
|
179
204
|
readonly disagreements?: readonly CheckDisagreement[];
|
|
@@ -181,8 +206,8 @@ export interface CheckTurns {
|
|
|
181
206
|
}
|
|
182
207
|
/** The most characters of an input or an answer a check's disagreement keeps. */
|
|
183
208
|
export declare const CHECK_TEXT_MAX = 1200;
|
|
184
|
-
/** A check's two shares: `agreement`, of the inputs the draft answered alone those
|
|
185
|
-
*
|
|
209
|
+
/** A check's two shares: `agreement`, of the inputs the draft answered alone those right on every field (0 when it
|
|
210
|
+
* answered none alone); `alone`, of the inputs it ran on those it answered alone (0 when none ran). */
|
|
186
211
|
export declare const checkShares: (score: {
|
|
187
212
|
readonly n: number;
|
|
188
213
|
readonly agreed: number;
|
|
@@ -191,12 +216,6 @@ export declare const checkShares: (score: {
|
|
|
191
216
|
agreement: number;
|
|
192
217
|
alone: number;
|
|
193
218
|
};
|
|
194
|
-
/** Whether a check promotes its draft: agreement at least the bar's agree_min, and alone at least its alone_min. */
|
|
195
|
-
export declare const checkPasses: (score: {
|
|
196
|
-
readonly n: number;
|
|
197
|
-
readonly agreed: number;
|
|
198
|
-
readonly alone: number;
|
|
199
|
-
}, bar: Pick<CheckBar, "agree_min" | "alone_min">) => boolean;
|
|
200
219
|
/** What a replay's runs are launched with (PromotionRecord.launch). */
|
|
201
220
|
export interface ReplayLaunch {
|
|
202
221
|
readonly revision: string;
|
|
@@ -355,23 +374,45 @@ export declare function trimPromotions(items: readonly PromotionRecord[], refuse
|
|
|
355
374
|
/** How many of a replay's own runs ended each way (a run not ended past its deadline is failed): what each run did. A
|
|
356
375
|
* check record keeps them as it was decided on. */
|
|
357
376
|
export type ReplayOutcomes = Readonly<Record<ReplayOutcome, number>>;
|
|
358
|
-
/** Whether two answers say the same: equal as JSON values, else as trimmed text.
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
377
|
+
/** Whether two answers say the same: equal as JSON values, else as trimmed text. */
|
|
378
|
+
export declare function sameAnswer(a: string | null, b: string | null): boolean;
|
|
379
|
+
/** The value at a dotted path (learning-setting.ts pathSegments: an agree_on path) of a JSON value (an answer's, a
|
|
380
|
+
* grade's expected answer): each segment an own key of an object (never an array's index, never through text or null);
|
|
381
|
+
* undefined where one is not, so the path does not resolve, and a field there is never right (learn/field-check.ts). */
|
|
382
|
+
export declare function valueAtPath(value: unknown, path: string): unknown;
|
|
383
|
+
/** The value at dotted `path` of an answer (its JSON, valueOf), undefined where it does not resolve or there is none. */
|
|
384
|
+
export declare const answerAt: (answer: string | null, path: string) => unknown;
|
|
385
|
+
/** An answer as the value sameAnswer compares (its JSON, else its trimmed text), undefined when there is none. */
|
|
386
|
+
export declare const answerValue: (answer: string | null) => unknown;
|
|
387
|
+
/** The known answer a whole-answer check compares a draft with, given a grade's `expected` answer, as JSON: the agent's
|
|
388
|
+
* answer (`agent`, its JSON) with the grade's keys written over it when both are JSON objects, so a grade that names
|
|
389
|
+
* only the keys it corrects leaves the rest of the agent's answer standing; else the expected answer whole. Own keys
|
|
390
|
+
* only, and never one named `__proto__`. A replay run's grader (runner/compare-end.ts) and the check
|
|
391
|
+
* (runner/promotion.ts judgeRows) read the same text, so its verdict's pair is this answer's. */
|
|
392
|
+
export declare function knownAnswerText(agent: string | null, expected: unknown): string;
|
|
393
|
+
/** The grader's instructions. The first answer is the known one: the agent's own, or a grade's correction of it. Measured
|
|
394
|
+
* on the live demo's check pairs when it named the agent's own answer; not measured again since it says the known one. */
|
|
363
395
|
export declare const GRADER_PROMPT: string;
|
|
364
|
-
/** The grader's one user message: the job input, the
|
|
365
|
-
|
|
396
|
+
/** The grader's one user message: the job input, the known answer (the agent's, or a grade's correction of it) and the
|
|
397
|
+
* workflow's answer, each fenced in <<< >>>. */
|
|
398
|
+
export declare const graderUserText: (input: string, known: string, draft: string) => string;
|
|
366
399
|
/** How a pair of answers compared: `same`, the grader's model when it was asked (`grader`; none when they were equal,
|
|
367
400
|
* compared on agree_on, or compared whole), what they differ on when they do (`differs_on`: the grader's words, or
|
|
368
401
|
* why its verdict could not be had), and the two answers the grader read (`pair`, answersPair): its verdict is of that
|
|
369
|
-
* pair alone.
|
|
402
|
+
* pair alone. A replay's verdict keeps the grade of its source run it was asked against (`graded`: whether the agent
|
|
403
|
+
* was right, and its expected answer when it gave one; null: none), so the check judges that input on that grade
|
|
404
|
+
* (runner/promotion.ts checkRows), never on one given after the grader was asked, whose pair it is not. */
|
|
370
405
|
export type Compared = {
|
|
371
406
|
readonly same: boolean;
|
|
372
407
|
readonly grader?: string;
|
|
373
408
|
readonly differs_on?: string;
|
|
374
409
|
readonly pair?: string;
|
|
410
|
+
readonly graded?: ComparedGrade | null;
|
|
411
|
+
};
|
|
412
|
+
/** The grade a replay's verdict was asked against (Compared.graded). */
|
|
413
|
+
export type ComparedGrade = {
|
|
414
|
+
readonly correct: boolean;
|
|
415
|
+
readonly expected?: Readonly<Record<string, unknown>>;
|
|
375
416
|
};
|
|
376
417
|
/** The two answers a grader's verdict is of, as one digest: the sha256 of each answer's sha256, the two in order, so
|
|
377
418
|
* the pair reads the same whichever side is named first and no two answers run together. */
|
|
@@ -415,14 +456,16 @@ export declare function graderVerdictOf(text: string): {
|
|
|
415
456
|
* on a transport error alone. A refusal of the run's cap, a failed request, one the run's stop or its deadline cut, or a
|
|
416
457
|
* reply that is not the verdict differs, in words saying so; never "same" by default. The verdict names its pair. */
|
|
417
458
|
export declare function gradeAnswers(input: string, agent: string, draft: string, grader: Grader): Promise<Compared>;
|
|
418
|
-
/**
|
|
419
|
-
* (
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
export declare function compareAnswers(a: string | null, b: string | null,
|
|
459
|
+
/** Two whole answers compared (`a`, `b`; either null: they differ), as a check and an audit judge one with no agree_on
|
|
460
|
+
* (runner/promotion.ts checkInputOf): equal byte for byte or as JSON values, they agree with no model; two that differ
|
|
461
|
+
* take the grader's verdict on that pair when it was asked (`compared`, kept on the run that asked it); with none (no
|
|
462
|
+
* fast model) they differ. A verdict whose `pair` is not these two answers' (one answered again since it was read) is
|
|
463
|
+
* stale: they differ, in its words (COMPARE_STALE), as with none. */
|
|
464
|
+
export declare function compareAnswers(a: string | null, b: string | null, compared?: Compared): Compared;
|
|
424
465
|
/** A `compared` as a run's record keeps it (metrics `compared`), else undefined. */
|
|
425
466
|
export declare function comparedOf(value: unknown): Compared | undefined;
|
|
467
|
+
/** A run's newest grade as a check judges it (an empty expected answer is none), null for none. */
|
|
468
|
+
export declare const comparedGrade: (grade: Grade | undefined) => ComparedGrade | null;
|
|
426
469
|
/** A grade as the API answers it (PUT /runs/{id}/grade; GET /runs/{id}/learning's `graded`, without `expected`). */
|
|
427
470
|
export declare const gradeView: (grade: Grade) => {
|
|
428
471
|
source: "feedback" | "eval";
|