@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.53
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 +160 -1
- package/README.md +306 -36
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +14 -4
- package/dist/agent-delete.js +30 -58
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agents-store.d.ts +28 -18
- package/dist/agents-store.js +48 -34
- package/dist/api-only.d.ts +30 -8
- package/dist/api-only.js +40 -16
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +70 -7
- package/dist/composio-preset.d.ts +2 -1
- package/dist/composio-preset.js +4 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +9 -0
- package/dist/computer-setting.js +19 -1
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-BFgyZzF_.js +734 -0
- package/dist/console/assets/index-DbilxljH.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +365 -0
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +19 -1
- package/dist/learn/commit.js +160 -2
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +46 -15
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +16 -0
- package/dist/learn/folder.js +30 -4
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +29 -4
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning-words.d.ts +5 -0
- package/dist/learning-words.js +5 -0
- package/dist/learning.d.ts +15 -10
- package/dist/learning.js +14 -8
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +56 -12
- package/dist/mcp-pin-first.js +1 -1
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +7 -2
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +17 -12
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +211 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +29 -5
- package/dist/run-launch.js +44 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +18 -1
- package/dist/run-view.js +28 -8
- package/dist/runner/adapter-loop.d.ts +14 -4
- package/dist/runner/adapter-loop.js +150 -31
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +35 -22
- package/dist/runner/audit.d.ts +10 -3
- package/dist/runner/audit.js +30 -7
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +31 -4
- package/dist/runner/claim-secrets.js +43 -7
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +32 -20
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +16 -3
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +9 -3
- package/dist/runner/learning-end.js +66 -29
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +7 -2
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +14 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +51 -24
- package/dist/runner/promotion.js +206 -78
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +174 -42
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.js +5 -2
- package/dist/runner/runner.js +41 -12
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +3 -3
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +4 -4
- package/dist/runs-over-store.d.ts +39 -8
- package/dist/runs-over-store.js +147 -32
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +185 -78
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +68 -32
- package/dist/server.js +678 -124
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +8 -0
- package/dist/store/agent-body.js +20 -6
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/schema.d.ts +15 -1
- package/dist/store/schema.js +43 -4
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +14 -0
- package/dist/store/sqlite/run-launch.js +58 -7
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.js +319 -153
- package/dist/store/store-schema.js +2 -2
- package/dist/store/store.d.ts +173 -33
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/template-eval.js +4 -4
- package/dist/template-import.d.ts +10 -2
- package/dist/template-import.js +116 -13
- package/dist/templates.d.ts +29 -5
- package/dist/templates.js +68 -14
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/tools.js +1 -1
- package/dist/trigger-launch-hook.d.ts +47 -0
- package/dist/trigger-launch-hook.js +90 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +2 -1
- package/dist/uploads.d.ts +0 -3
- package/dist/uploads.js +2 -11
- package/dist/validate.js +4 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +5 -2
- package/dist/console/assets/index-Bt1B51b7.js +0 -733
- package/dist/console/assets/index-sVftE9Ht.css +0 -1
package/dist/runner/promotion.js
CHANGED
|
@@ -1,15 +1,60 @@
|
|
|
1
|
+
// Promotion, at a run's claim (champion/challenger, shadow deployment): the learned workflow that fits the run's input
|
|
2
|
+
// serves first only when its digest is promoted (learn/promote.ts). Promote once: a digest with no record yet, the learning
|
|
3
|
+
// folder's newest revision, is checked once (startCheck): a replay run of it (RunLaunch.replay, at workflow cost) on the
|
|
4
|
+
// input of each of the agent's last compile_after completed runs of its own (its definition's `learning`,
|
|
5
|
+
// learning-setting.ts), the agent taking the runs meanwhile. A later claim that finds every check run ended scores each
|
|
6
|
+
// against the agent's own recorded answer (learn/promote.ts sameAnswer; no grade is read) and promotes the digest when,
|
|
7
|
+
// of the inputs it ran on, it answered at least alone_min alone and at least agree_min of those said what the agent said
|
|
8
|
+
// (checkPasses); else it is held, its record keeping the inputs it disagreed on, which the agent's next run's compile
|
|
9
|
+
// turn reads to write its one recompile (learn/compile.ts); that revision is checked the same way, once, and a hold of
|
|
10
|
+
// it stops (nothing compiles again). A check-promoted digest is never checked again: no grade, no refit, no queue, no
|
|
11
|
+
// second replay. Every reserved input counts: one whose replay run was never created, or never ended, by the check's
|
|
12
|
+
// deadline is a failed input. With nothing to check it on (no input of the agent's it takes, or every input skipped at a
|
|
13
|
+
// write) it is never promoted: it stops, its record naming why (stopUnchecked), and asks no recompile.
|
|
14
|
+
//
|
|
15
|
+
// The champion keeps serving meanwhile: while the folder's revision (the challenger) is checked, or once it is held, the
|
|
16
|
+
// digest promoted last (learn/promote.ts championOf) serves the run, read from the learning commit its record names. Only
|
|
17
|
+
// the money rule (workflow-first.ts) stops it. Who serves is the champion alone, read at every run's claim, a queued run's
|
|
18
|
+
// included (servingNow): a digest's own promote record never serves it once another digest was promoted after it. A run
|
|
19
|
+
// already executing (an earlier claim of it served a workflow first) keeps that revision (keptFor). A serving revision
|
|
20
|
+
// this release's workflow DSL refuses (a key an older release took, say) is held at the claim that finds it, once per
|
|
21
|
+
// digest, its reason the DSL's (holdRefused): the run hands back as before, and the hold asks the one recompile.
|
|
22
|
+
// One check at a time: a check at work finishes (a revision newer than it waits, and decides it first: settleAhead). The
|
|
23
|
+
// check is reserved before any of its replay runs starts: its replaying record, naming the runs it will start, is kept
|
|
24
|
+
// only while no other revision of the workflow replays (the rival check in the same guarded write), so two claims of two
|
|
25
|
+
// revisions at once start one check. A reserved run not created yet is pending, never ended: a claim between the
|
|
26
|
+
// reservation and the creates decides nothing, and a launch interrupted there (a crash, a failed create) is finished by a
|
|
27
|
+
// claim REPLAY_LAUNCH_GRACE_MS on, each run under its reserved id on the input its record names (relaunch), with the
|
|
28
|
+
// launch its record chose when it was reserved (PromotionRecord.launch: model, revision, credentials), never the finishing
|
|
29
|
+
// claim's. Every decision is acted on (replay runs started, runs cancelled) only by the claim whose write kept it
|
|
30
|
+
// (learn/promote.ts Recorded.won). A check decided with runs still at work (its deadline passed) cancels them. A replay
|
|
31
|
+
// run's claim refuses it unless its revision still replays (replayClaimed), so a cancel lost to a crash or a failed write
|
|
32
|
+
// never leaves one running.
|
|
33
|
+
// A replay never repeats a side effect and runs with what a served run of the agent has (learn/replay-calls.ts, SPEC B4):
|
|
34
|
+
// each call node's tool is a read or a write; a read runs live through a cache seeded from the agent's recorded calls, a
|
|
35
|
+
// write is answered only from that recording (same tool, same canonical arguments) and is never sent, and an input whose
|
|
36
|
+
// workflow needs a write the recording does not have is skipped (counted in the record's check.outcomes, never scored); a
|
|
37
|
+
// check whose every input was skipped holds the revision in those words, or, when the tool that stopped them is an MCP
|
|
38
|
+
// tool its server listed with no readOnlyHint, naming it (check.skipped_tools). Its credentials resolve at its claim as
|
|
39
|
+
// any run's of the agent do: saved ones from the server's store, and the per_run MCP credentials the run whose claim
|
|
40
|
+
// reserved it was handed (its record's launch.handed_from), sealed anew for the replay run alone (startReplay), never
|
|
41
|
+
// opened outside the claim.
|
|
42
|
+
// Its owner may start one too (askReplay, POST .../revisions/{digest}/replays): a held revision re-checked, or an edited
|
|
43
|
+
// one, on the inputs it was last checked on or the agent's newest, decided by the same settleCheck, at a claim that lays
|
|
44
|
+
// it or at its read (replayView), so its records are a claim-started check's.
|
|
45
|
+
import { sourceSyncOf } from "../source-sync/types.js";
|
|
1
46
|
import { LEARNING_LABEL } from "../learning.js";
|
|
2
47
|
import { loopOf } from "../learning-setting.js";
|
|
3
48
|
import { LEARNED_WORKFLOW_TOOL } from "../learned-workflow.js";
|
|
4
49
|
import { launchBody, readLaunchBody } from "../run-launch.js";
|
|
5
|
-
import { uuidv7 } from "../
|
|
50
|
+
import { uuidv7 } from "../ids.js";
|
|
6
51
|
import { FINAL_STATES, RunFinal, RunPurged, StoreConstraint } from "../store/store.js";
|
|
7
52
|
import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
|
|
8
53
|
import { isCliRecord, piShaped, runEntries, runTimeline } from "../store-reads/journal.js";
|
|
9
54
|
import { pinAnnotations, recordedCalls, replayCalls, SKIPPED_WRITE, toolClassOf, toolWord, unmarkedWords } from "../learn/replay-calls.js";
|
|
10
55
|
import { listed } from "../learning-words.js";
|
|
11
56
|
import { isObject } from "../validate.js";
|
|
12
|
-
import { agentRun, lastOwnRuns, newCompileAttempt } from "../learn/compile.js";
|
|
57
|
+
import { agentRun, lastOwnRuns, newCompileAttempt, sinceReset } from "../learn/compile.js";
|
|
13
58
|
import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedOf, promotionOf, promotionsOf, recordPromotion, replayingOf, skippedToolsOf } from "../learn/promote.js";
|
|
14
59
|
import { sendCommand } from "./commands.js";
|
|
15
60
|
import { ClaimRefused } from "./loop-contract.js";
|
|
@@ -32,7 +77,7 @@ export function claimPromotion(deps) {
|
|
|
32
77
|
return {
|
|
33
78
|
...deps,
|
|
34
79
|
kept: async () => (deps.runId ? servedOf(await runEntries(deps.store, deps.runId, deps.context).catch(() => [])) : undefined),
|
|
35
|
-
champion: async (name, commit) => (await workflowsAt({ folder: deps.folder, shown: deps.shown }, commit)).find((one) => one.name === name),
|
|
80
|
+
champion: async (name, commit) => (await workflowsAt({ folder: deps.folder, store: deps.store, shown: deps.shown }, commit)).find((one) => one.name === name),
|
|
36
81
|
newest: async (name) => {
|
|
37
82
|
const folder = deps.folder();
|
|
38
83
|
let main;
|
|
@@ -42,7 +87,7 @@ export function claimPromotion(deps) {
|
|
|
42
87
|
finally {
|
|
43
88
|
await folder.end().catch(() => undefined);
|
|
44
89
|
}
|
|
45
|
-
const text = main ? (await workflowsAt({ folder: deps.folder, shown: deps.shown }, main)).find((one) => one.name === name) : undefined;
|
|
90
|
+
const text = main ? (await workflowsAt({ folder: deps.folder, store: deps.store, shown: deps.shown }, main)).find((one) => one.name === name) : undefined;
|
|
46
91
|
return text ? workflowDigest(text) : undefined;
|
|
47
92
|
},
|
|
48
93
|
};
|
|
@@ -270,8 +315,9 @@ async function loopOfRevision(deps) {
|
|
|
270
315
|
/** Which check of a compile a new revision's is: 2 when the workflow's newest record of another revision is a first
|
|
271
316
|
* check's hold, an audit's hold or a hold by its reason alone (holdRefused: the DSL refuses a serving revision), or a
|
|
272
317
|
* first compile's failed draft (this revision is its one recompile), else 1. A stop with nothing checked
|
|
273
|
-
* (stopUnchecked) is no first check's hold: it spends no recompile
|
|
274
|
-
*
|
|
318
|
+
* (stopUnchecked) is no first check's hold: it spends no recompile, and neither does a connected agent's hold on its
|
|
319
|
+
* give-backs (heldOnGiveBacks: the revision after it is the same attempt). A workflow's first revision after a first
|
|
320
|
+
* compile whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
|
|
275
321
|
export function attemptOf(records, name, digest) {
|
|
276
322
|
const before = records.findLast((one) => one.workflow === name && one.digest !== digest);
|
|
277
323
|
if (!before)
|
|
@@ -280,6 +326,8 @@ export function attemptOf(records, name, digest) {
|
|
|
280
326
|
return 1;
|
|
281
327
|
if (before.audit)
|
|
282
328
|
return before.audit.stopped ? 1 : 2;
|
|
329
|
+
if (before.check && heldOnGiveBacks(before.check))
|
|
330
|
+
return before.check.attempt;
|
|
283
331
|
return !before.check || (before.check.attempt === 1 && !before.check.stopped) ? 2 : 1;
|
|
284
332
|
}
|
|
285
333
|
/** The shadow runs a recompile's check runs on beside the agent's last runs: the disagreeing audit rows the workflow's
|
|
@@ -300,16 +348,19 @@ const checkable = (deps, row) => row.id !== deps.runId && agentRun(row) && row.a
|
|
|
300
348
|
* never push them out of the read. And `audited`: an audit hold's disagreeing shadow runs (auditInputsOf), each ended.
|
|
301
349
|
* Of those, the ones whose input `workflow` takes (fits), each with its launch read back; one with an uploaded file is
|
|
302
350
|
* never an input. With how many of the agent's runs it looked at (`looked`) and why each it looked at is no input
|
|
303
|
-
* (`unfit`, `files`).
|
|
351
|
+
* (`unfit`, `files`). Every one of them a run on no named disk (one on a named disk learns nothing, learn/learning-of.ts)
|
|
352
|
+
* since the agent's learning's reset (sinceReset), the named and audited ones included. */
|
|
304
353
|
async function checkInputs(deps, workflow, pick, audited = []) {
|
|
305
354
|
const { resolveSchemaForWorkflow } = await import("@parcha/agentrun-dsl");
|
|
306
|
-
const
|
|
355
|
+
const since = await sinceReset(deps.store, deps.agentId);
|
|
356
|
+
const learns = (row) => (row.disk ?? null) === null && since(row);
|
|
357
|
+
const named = (await Promise.all(pick.of.map((id) => deps.store.runs.get(id)))).filter((row) => row !== undefined && checkable(deps, row) && learns(row));
|
|
307
358
|
const last = pick.n ? await lastOwnRuns(deps.store, deps.agentId, pick.n + pick.of.length, deps.runId) : [];
|
|
308
359
|
const own = [...named, ...last.filter((row) => !pick.of.includes(row.id)).slice(0, pick.n)];
|
|
309
360
|
// And an audit hold's disagreeing shadow runs: the agent's answers the recompile must say too.
|
|
310
361
|
for (const id of audited) {
|
|
311
362
|
const row = await deps.store.runs.get(id);
|
|
312
|
-
if (row && row.state === "ended" && !own.some((one) => one.id === id))
|
|
363
|
+
if (row && row.state === "ended" && learns(row) && !own.some((one) => one.id === id))
|
|
313
364
|
own.push(row);
|
|
314
365
|
}
|
|
315
366
|
const out = [];
|
|
@@ -331,6 +382,10 @@ async function checkInputs(deps, workflow, pick, audited = []) {
|
|
|
331
382
|
* it fits), it is decided at once: never promoted, it stops with nothing checked (stopUnchecked). */
|
|
332
383
|
async function startCheck(deps, workflow, digest) {
|
|
333
384
|
const { store, agentId, log } = deps;
|
|
385
|
+
if ((deps.launch.sourceProject || sourceSyncOf((await store.agents.revision(deps.revisionId))?.body)) && !deps.admitAuxiliary) {
|
|
386
|
+
log(`workflow-first: ${PROJECT_REPLAY_REFUSED}`);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
334
389
|
// Its replay runs are runs the runner starts, on no caller's key: skipped where the claimed run brought its own key or
|
|
335
390
|
// the server holds none (claimSpendOff).
|
|
336
391
|
const off = deps.spendOff?.("A learned workflow's replay check");
|
|
@@ -380,18 +435,22 @@ export const NOTHING_TO_CHECK = "nothing to check it on";
|
|
|
380
435
|
export const NEVER_WORD_FOR_WORD = "its answers never matched the agent's word for word, and no fast model compared their decisions (a learning agent with no agree_on wants one: AGENT_MODEL_FAST, or its model_tiers.fast); name the fields that carry the decision (learning.agree_on)";
|
|
381
436
|
/** What a held check the grader compared says of the inputs it disagreed on: k of n, with one of the decisions. */
|
|
382
437
|
export const differentDecisionWords = (k, n, example) => `its answers reached a different decision from the agent's on ${k} of ${n}${example ? ` (for example: ${example})` : ""}`;
|
|
438
|
+
/** The one writer of a hold with nothing checked (n 0): `name` at `digest` held for `reason`, never promoted, its check
|
|
439
|
+
* the bar it was held at (`check`: what else the record keeps of it), `stopped` when nothing compiles again until a hold
|
|
440
|
+
* or its owner acts, and `extra` on the record (a connected agent's check: what its reservation carries). Kept only while
|
|
441
|
+
* `still` holds of the digest's record (the one write), and logged. */
|
|
442
|
+
async function holdUnchecked(deps, name, digest, bar, reason, still, { stopped = false, check = {}, extra = {} } = {}) {
|
|
443
|
+
const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still);
|
|
444
|
+
if (decided.won)
|
|
445
|
+
deps.log(`workflow-first: ${name} at ${digest} ${stopped ? "stopped" : "held"}: ${reason}`);
|
|
446
|
+
return decided;
|
|
447
|
+
}
|
|
383
448
|
/** Stops a draft its check had nothing to run on (`why`: no input of the agent's it takes, or every input skipped at a
|
|
384
449
|
* write): held, never promoted unchecked, its record `stopped` (nothing compiles again until a hold or its owner acts)
|
|
385
450
|
* and naming the cause, which the compile's draft errors show (store-reads/loop.ts). It asks no recompile: a revision
|
|
386
451
|
* would have nothing to be checked on either, and a stop with nothing checked never counts as a compile's first check
|
|
387
|
-
* (attemptOf).
|
|
388
|
-
|
|
389
|
-
const reason = `${NOTHING_TO_CHECK}: ${why}. It is not promoted, and it stops: nothing compiles again until a hold or its owner acts`;
|
|
390
|
-
const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, stopped: true }, ...seedOf(deps), ...extra }, still);
|
|
391
|
-
if (decided.won)
|
|
392
|
-
deps.log(`workflow-first: ${name} at ${digest} stopped: ${reason}`);
|
|
393
|
-
return decided;
|
|
394
|
-
}
|
|
452
|
+
* (attemptOf). */
|
|
453
|
+
const stopUnchecked = (deps, name, digest, bar, why, still, check = {}, extra = {}) => holdUnchecked(deps, name, digest, bar, `${NOTHING_TO_CHECK}: ${why}. It is not promoted, and it stops: nothing compiles again until a hold or its owner acts`, still, { stopped: true, check, extra });
|
|
395
454
|
/** Decides `ahead`, the check at work for a revision older than the laid (newest) one, as a claim laying it would
|
|
396
455
|
* (relaunch, then settleCheck) once its runs ended: its text read at its record's commit, its verdict standing (promote
|
|
397
456
|
* or hold) though a newer revision waits. Left replaying while a run of it is at work, or when its text cannot be read
|
|
@@ -474,45 +533,56 @@ async function settleCheck(deps, workflow, digest, record) {
|
|
|
474
533
|
}
|
|
475
534
|
return decided.record?.decided === "replaying" ? undefined : decided.record;
|
|
476
535
|
}
|
|
477
|
-
/**
|
|
478
|
-
* with the agent's recorded answer (learn/promote.ts
|
|
479
|
-
* when it names fields, else equal, or the same
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const now = deps.now ?? Date.now;
|
|
486
|
-
const ran = read.rows.filter((row) => row.outcome !== "skipped_write");
|
|
536
|
+
/** A check's rows scored on its bar, added to `before` (a connected agent's turns checked so far): each input it ran on
|
|
537
|
+
* (a skipped write is none) agreed when the draft answered it alone with the agent's recorded answer (learn/promote.ts
|
|
538
|
+
* compareAnswers, the audit's one comparison: on the bar's agree_on when it names fields, else equal, or the same
|
|
539
|
+
* decision by the grader's verdict its replay run kept), alone when it answered it with no escalate and no failed step;
|
|
540
|
+
* the inputs it did not agree on, each text cut of the host's secrets whole, then shortened (learn/secrets.ts
|
|
541
|
+
* excerptShown); and the fast model that compared, when it read any input's answers. */
|
|
542
|
+
async function scoreRows(deps, bar, rows, before) {
|
|
543
|
+
const ran = rows.filter((row) => row.outcome !== "skipped_write");
|
|
487
544
|
const alone = (row) => row.outcome === "answered";
|
|
488
545
|
// Compared on the bar's agree_on when it names paths (the definition's), else equal answers agree and the grader's
|
|
489
546
|
// verdict decides the rest; with no grader (no fast model), the whole answer.
|
|
490
547
|
const compared = new Map(ran.map((row) => [row, compareAnswers(row.answer, row.agent, bar.agree_on, row.compared)]));
|
|
491
548
|
const agrees = (row) => alone(row) && compared.get(row).same;
|
|
492
|
-
const score = { n: ran.length, agreed: ran.filter(agrees).length, alone: ran.filter(alone).length };
|
|
493
|
-
const ok = checkPasses(score, bar);
|
|
494
|
-
// The fast model that compared, when it read any input's answers.
|
|
549
|
+
const score = { n: (before?.n ?? 0) + ran.length, agreed: (before?.agreed ?? 0) + ran.filter(agrees).length, alone: (before?.alone ?? 0) + ran.filter(alone).length };
|
|
495
550
|
const grader = [...compared.values()].find((one) => one.grader !== undefined)?.grader;
|
|
496
|
-
// Each text is cut of the host's secrets whole, then shortened (learn/secrets.ts excerptShown).
|
|
497
551
|
const shown = await deps.shown();
|
|
498
552
|
const cut = (text) => excerptShown(text, shown, CHECK_TEXT_MAX);
|
|
499
|
-
const disagreements = ran.filter((row) => !agrees(row)).map((row) => {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
553
|
+
const disagreements = [...(before?.disagreements ?? []), ...ran.filter((row) => !agrees(row)).map((row) => {
|
|
554
|
+
const differs = row.outcome === "answered" ? compared.get(row).differs_on : undefined;
|
|
555
|
+
return {
|
|
556
|
+
run: row.of, input: cut(row.input), agent: row.agent === null ? null : cut(row.agent),
|
|
557
|
+
...(row.outcome === "answered" ? { draft: cut(row.answer ?? "") } : row.outcome === "handed_back" ? { escalated: cut(row.escalated ?? "") } : { failed: true }),
|
|
558
|
+
...(differs ? { differs_on: cut(differs) } : {}),
|
|
559
|
+
};
|
|
560
|
+
})];
|
|
561
|
+
return { score, disagreements, grader };
|
|
562
|
+
}
|
|
563
|
+
/** Two outcome counts added. */
|
|
564
|
+
const outcomesAdded = (a, b) => b ? { answered: a.answered + b.answered, handed_back: a.handed_back + b.handed_back, failed: a.failed + b.failed, skipped_write: a.skipped_write + b.skipped_write } : a;
|
|
565
|
+
/** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
|
|
566
|
+
* (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
|
|
567
|
+
* agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
|
|
568
|
+
* nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
|
|
569
|
+
* (the one write: of two claims at once, one decides). */
|
|
570
|
+
export async function decideCheck(deps, name, digest, bar, read, still, extra) {
|
|
571
|
+
const now = deps.now ?? Date.now;
|
|
572
|
+
const { before } = read;
|
|
573
|
+
const { score, disagreements, grader } = await scoreRows(deps, bar, read.rows, before);
|
|
574
|
+
const ok = checkPasses(score, bar);
|
|
507
575
|
const stopped = !ok && bar.attempt === 2;
|
|
508
576
|
const pct = (value) => `${(value * 100).toFixed(1)}%`;
|
|
509
577
|
const shares = checkShares(score);
|
|
510
578
|
// Inputs stopped at a write the recording lacks are no evidence either way; one stopped at an MCP tool its server listed
|
|
511
579
|
// with no readOnlyHint names that tool (skipWordsOf), never a data problem.
|
|
512
580
|
const tools = skippedToolsOf(read.rows);
|
|
513
|
-
const
|
|
581
|
+
const outcomes = outcomesAdded(read.outcomes, before?.outcomes);
|
|
582
|
+
const { skipped_write: skipped, failed } = outcomes;
|
|
514
583
|
const { hint, why: skipWhy } = skipWordsOf(tools, skipped);
|
|
515
|
-
const
|
|
584
|
+
const fresh = (read.fresh_reads ?? 0) + (before?.fresh_reads ?? 0);
|
|
585
|
+
const numbers = { of: [...read.rows.map((row) => row.of), ...(before?.of ?? [])], cost_usd: read.cost, outcomes, ...(read.unstarted ? { unstarted: read.unstarted } : {}), ...(tools.length ? { skipped_tools: tools } : {}), ...(fresh ? { fresh_reads: fresh } : {}) };
|
|
516
586
|
// Every input skipped at a write (each reserved input counts: one never created or never ended failed, so this is the
|
|
517
587
|
// only way to none): nothing to check it on, so it stops, never promoted unchecked, and asks no recompile.
|
|
518
588
|
if (!score.n) {
|
|
@@ -554,13 +624,24 @@ async function reserve(deps, workflow, digest, inputs, reason, still, check) {
|
|
|
554
624
|
await startReplay(deps, workflow, digest, one.run, one.launch, ids[i], launch);
|
|
555
625
|
return reserved;
|
|
556
626
|
}
|
|
557
|
-
/** How many of a connected agent's reserved native turns its check gives back
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
627
|
+
/** How many of a connected agent's reserved native turns its check gives back in a row (failed, a learned workflow or
|
|
628
|
+
* nested call in it, redacted evidence, no shadow report, or a shadow that did not answer; never a cancel, and a turn
|
|
629
|
+
* that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the
|
|
630
|
+
* agent's next compile after compile_after more of its runs (runner/learning-end.ts compileAskOf) to revise and check
|
|
631
|
+
* afresh: five in a row say the integration cannot give a baseline now, not that it never will. The one list of the
|
|
632
|
+
* causes a give-back has: every other mention points here. */
|
|
563
633
|
export const SDK_CHECK_RELEASES = 5;
|
|
634
|
+
/** Whether a hold's check is a connected agent's held on SDK_CHECK_RELEASES give-backs in a row (releaseSdkCheck): only
|
|
635
|
+
* a connected agent's check counts give-backs. */
|
|
636
|
+
export const heldOnGiveBacks = (check) => (check?.released ?? 0) >= SDK_CHECK_RELEASES;
|
|
637
|
+
/** Which attempt a revision compile of `held` is when its draft fails its checks (runner/learning-end.ts
|
|
638
|
+
* recordDraftFailed): 2, the recompile, for any hold but a connected agent's on give-backs, which spends none: its
|
|
639
|
+
* check's own attempt, until a revise of it has failed once already (the workflow's newest record that failed draft). */
|
|
640
|
+
export function reviseAttemptOf(records, held) {
|
|
641
|
+
if (!held.check || !heldOnGiveBacks(held.check))
|
|
642
|
+
return 2;
|
|
643
|
+
return newCompileAttempt(records.filter((one) => one.workflow === held.workflow)) === 2 ? 2 : held.check.attempt;
|
|
644
|
+
}
|
|
564
645
|
/** A connected agent's check waiting for a native turn (`via` sdk, replaying, no turn reserved). */
|
|
565
646
|
const waitingSdk = (record) => record?.decided === "replaying" && record.via === "sdk" && !record.runs?.length;
|
|
566
647
|
/** Whether a connected agent's check was overtaken: a record of another revision of its workflow came after its own
|
|
@@ -586,7 +667,7 @@ export const sdkInputText = (launch) => {
|
|
|
586
667
|
* check on the native turn `runId`: the first the turn takes (`takes`) with no decision yet, or one waiting for a turn,
|
|
587
668
|
* while no other revision of its workflow is checked; the guarded write keeps one reservation per workflow across
|
|
588
669
|
* concurrent starts. First each SDK check of a candidate's workflow is moved on: one whose turn is past
|
|
589
|
-
* REPLAY_DEADLINE_MS is
|
|
670
|
+
* REPLAY_DEADLINE_MS is one failed row of its turns (sdkCheckDeadline), and one waiting at a revision the folder moved
|
|
590
671
|
* past is set aside. A managed replay's record (no `via`) is never touched here. */
|
|
591
672
|
export async function reserveSdkCheck(deps, turn) {
|
|
592
673
|
const { revision } = turn;
|
|
@@ -613,34 +694,74 @@ export async function reserveSdkCheck(deps, turn) {
|
|
|
613
694
|
if ((own && !waitingSdk(own)) || blocking(records, flow.name, digest).length)
|
|
614
695
|
continue;
|
|
615
696
|
const id = uuidv7();
|
|
697
|
+
const check = own?.check ?? { ...loopOf(turn.learning), attempt: attemptOf(records, flow.name, digest) };
|
|
616
698
|
const reserved = await recordPromotion(deps.store.settings, deps.agentId, {
|
|
617
699
|
workflow: flow.name, digest, at: iso(now()), decided: "replaying", via: "sdk",
|
|
618
|
-
reason:
|
|
619
|
-
replay_id: id, runs: [turn.runId], inputs: [turn.runId], commit: revision,
|
|
620
|
-
check: own?.check ?? { ...loopOf(turn.learning), attempt: attemptOf(records, flow.name, digest) },
|
|
700
|
+
reason: `Checking it in the connected agent against an independent native turn before it can be reused: ${sdkTurnsWords(check)}.`,
|
|
701
|
+
replay_id: id, runs: [turn.runId], inputs: [turn.runId], commit: revision, check,
|
|
621
702
|
}, (was, current) => (own ? waitingSdk(was) && was.replay_id === own.replay_id : was === undefined) && blocking(current, flow.name, digest).length === 0);
|
|
622
703
|
if (reserved.won)
|
|
623
704
|
return { id, revision, digest, workflow: flow };
|
|
624
705
|
}
|
|
625
706
|
}
|
|
707
|
+
/** How far a connected agent's check is: its turns checked of the compile_after it decides on. */
|
|
708
|
+
const sdkTurnsWords = (check) => `${check.turns?.n ?? 0} of ${plural(check.compile_after, "native turn")} checked so far; it decides once on all of them, as a managed check does on the agent's inputs`;
|
|
709
|
+
/** One native turn's row of a connected agent's check: its shadow answered or handed back (sdk/check.ts settleSdkCheck),
|
|
710
|
+
* or the turn did not settle by REPLAY_DEADLINE_MS, a failed row (sdkCheckDeadline). A managed check decides once, on
|
|
711
|
+
* its compile_after inputs, and so does this one: the turn that makes compile_after decides on every turn collected
|
|
712
|
+
* (decideCheck, the same bar); a turn before it is scored and kept (check.turns), the record gives back its reserved
|
|
713
|
+
* turn, and the check waits for the next turn the draft takes, nothing decided or promoted, the agent answering
|
|
714
|
+
* meanwhile. No turn holds it early, as no input of a managed check does. Its rows are never skipped (a shadow stopped
|
|
715
|
+
* at a write gives its turn back), so each is one of the n. Kept only while `still` holds of the digest's record; a
|
|
716
|
+
* check a newer revision overtook keeps no turn (it would hide the newer record), as a release does. */
|
|
717
|
+
export async function sdkCheckTurn(deps, record, row, still, read = {}) {
|
|
718
|
+
// A turn that lands starts the give-back count again (SDK_CHECK_RELEASES counts them in a row).
|
|
719
|
+
const { turns: before, released: _released, ...bar } = record.check;
|
|
720
|
+
const outcomes = { ...NO_OUTCOMES, [row.outcome]: 1 };
|
|
721
|
+
// The turn lands once: its completion and its deadline can both read the reservation, and the first to write takes
|
|
722
|
+
// the turn off it, so the second finds it gone (heldTurn) and never adds the turn twice or replaces the first's row.
|
|
723
|
+
const turnStill = (was, current) => still(was, current) && heldTurn(was, record);
|
|
724
|
+
if ((before?.n ?? 0) + 1 >= bar.compile_after)
|
|
725
|
+
return decideCheck(deps, record.workflow, record.digest, bar, { rows: [row], cost: null, outcomes, unstarted: 0, ...read, ...(before ? { before } : {}) }, turnStill, sdkExtra(record));
|
|
726
|
+
if (overtaken(await promotionsOf(deps.store.settings, deps.agentId), record)) {
|
|
727
|
+
deps.log(`workflow-first: ${record.workflow} at ${record.digest} checked a native turn; a newer revision has a record since, so it is left as it is`);
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
const { score, disagreements } = await scoreRows(deps, bar, [row], before);
|
|
731
|
+
const fresh = (before?.fresh_reads ?? 0) + (read.fresh_reads ?? 0);
|
|
732
|
+
const turns = { ...score, of: [row.of, ...(before?.of ?? [])], outcomes: outcomesAdded(outcomes, before?.outcomes), ...(disagreements.length ? { disagreements } : {}), ...(fresh ? { fresh_reads: fresh } : {}) };
|
|
733
|
+
const check = { ...bar, turns };
|
|
734
|
+
const kept = await waitAgain(deps, record, check, `Waiting for the next native turn of the connected agent that it takes: ${sdkTurnsWords(check)}. Nothing was promoted.`, still);
|
|
735
|
+
if (kept.won)
|
|
736
|
+
deps.log(`workflow-first: ${record.workflow} at ${record.digest}: ${sdkTurnsWords(check)}`);
|
|
737
|
+
return kept;
|
|
738
|
+
}
|
|
739
|
+
/** Puts a connected agent's check back as waiting for the next native turn it takes, nothing decided or promoted: its
|
|
740
|
+
* reserved turn taken off (runs, inputs), its `check` and `reason` kept. The turn lands once: kept only while `still`
|
|
741
|
+
* holds and the record still reserves that turn (sameReplay, heldTurn), so a second writer that read the same
|
|
742
|
+
* reservation finds it gone, and never over a newer revision's record (overtaken). The one writer of a check put back
|
|
743
|
+
* as waiting: a turn's row (sdkCheckTurn) and a give-back (releaseSdkCheck). */
|
|
744
|
+
function waitAgain(deps, record, check, reason, still = () => true) {
|
|
745
|
+
const { runs: _runs, inputs: _inputs, ...rest } = record;
|
|
746
|
+
return recordPromotion(deps.store.settings, deps.agentId, { ...rest, at: iso((deps.now ?? Date.now)()), check, reason }, (was, current) => still(was, current) && sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was));
|
|
747
|
+
}
|
|
626
748
|
/** A connected agent's check whose native turn did not settle it by REPLAY_DEADLINE_MS (the backend never completed the
|
|
627
|
-
* turn, or the server stopped before the run's end):
|
|
628
|
-
*
|
|
629
|
-
* restarts its budget. */
|
|
749
|
+
* turn, or the server stopped before the run's end): one failed row of its turns (sdkCheckTurn), as a managed check's
|
|
750
|
+
* replay run not ended by its deadline is a failed input. The hold the turns end in asks the one recompile, and a
|
|
751
|
+
* recompile's check held so stops (`stopped`): an abandoned check never restarts its budget. */
|
|
630
752
|
export async function sdkCheckDeadline(deps, pending) {
|
|
631
753
|
const runId = pending.runs?.[0];
|
|
632
|
-
|
|
754
|
+
const { check } = pending;
|
|
755
|
+
if (!runId || !check || overtaken(await promotionsOf(deps.store.settings, deps.agentId), pending))
|
|
633
756
|
return;
|
|
634
757
|
const launch = await deps.store.runs.launch(runId).then((one) => readLaunchBody(one.body), () => undefined);
|
|
635
|
-
return
|
|
636
|
-
rows: [{ of: runId, input: sdkInputText(launch), agent: null, outcome: "failed", answer: null }],
|
|
637
|
-
cost: null, outcomes: { ...NO_OUTCOMES, failed: 1 }, unstarted: 0,
|
|
638
|
-
}, (was, current) => sameReplay(was, pending) && !overtaken(current, was), sdkExtra(pending));
|
|
758
|
+
return sdkCheckTurn(deps, { ...pending, check }, { of: runId, input: sdkInputText(launch), agent: null, outcome: "failed", answer: null }, (was, current) => sameReplay(was, pending) && !overtaken(current, was));
|
|
639
759
|
}
|
|
640
760
|
/** Gives back a connected agent's reserved native turn that cannot be its check's baseline (`cause`): the check waits for
|
|
641
|
-
* the next turn the draft takes, nothing decided or promoted,
|
|
642
|
-
*
|
|
643
|
-
*
|
|
761
|
+
* the next turn the draft takes, nothing decided or promoted, the turns it checked kept on the record. A `counted` turn
|
|
762
|
+
* (not a cancel, not a start that was never admitted) counts toward SDK_CHECK_RELEASES in a row, whose last holds the
|
|
763
|
+
* draft for a compile after compile_after more runs, whose revision is checked afresh. Kept only while the record is
|
|
764
|
+
* still this reservation. */
|
|
644
765
|
export async function releaseSdkCheck(deps, record, cause, counted = true) {
|
|
645
766
|
if (!record.check)
|
|
646
767
|
return;
|
|
@@ -651,30 +772,25 @@ export async function releaseSdkCheck(deps, record, cause, counted = true) {
|
|
|
651
772
|
const released = (record.check.released ?? 0) + (counted ? 1 : 0);
|
|
652
773
|
const why = excerptShown(cause, await deps.shown(), CHECK_TEXT_MAX);
|
|
653
774
|
// Overtaken is read again inside the write: a newer revision's record can land while the cause is being cut.
|
|
654
|
-
const still = (was, current) => sameReplay(was, record) && !overtaken(current, was);
|
|
775
|
+
const still = (was, current) => sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was);
|
|
655
776
|
const bar = { ...record.check, ...(released ? { released } : {}) };
|
|
777
|
+
// A hold, never `stopped`: it asks a compile for a revision (learn/compile.ts heldNamesOf) after compile_after more runs
|
|
778
|
+
// (runner/learning-end.ts compileAskOf), checked afresh.
|
|
656
779
|
if (released >= SDK_CHECK_RELEASES)
|
|
657
|
-
return
|
|
658
|
-
const
|
|
659
|
-
const kept = await recordPromotion(deps.store.settings, deps.agentId, {
|
|
660
|
-
...rest, at: iso((deps.now ?? Date.now)()), check: bar,
|
|
661
|
-
reason: `Waiting for a native turn of the connected agent that it takes: ${why}, so that turn was given back${counted ? ` (${released} of ${SDK_CHECK_RELEASES} before the check stops)` : ""}. Nothing was promoted.`,
|
|
662
|
-
}, still);
|
|
780
|
+
return holdUnchecked(deps, record.workflow, record.digest, bar, `the connected agent gave back ${plural(released, "reserved native turn")} in a row with no answer to check it against (the last: ${why}). It is not promoted; the agent's next compile after ${plural(bar.compile_after, "more run")} revises it, and the revision is checked afresh`, still, { check: bar.turns?.disagreements?.length ? { disagreements: bar.turns.disagreements } : {}, extra: sdkExtra(record) });
|
|
781
|
+
const kept = await waitAgain(deps, record, bar, `Waiting for a native turn of the connected agent that it takes: ${why}, so that turn was given back${counted ? ` (${released} of ${SDK_CHECK_RELEASES} in a row before it is held for a recompile)` : ""}. Nothing was promoted.`);
|
|
663
782
|
if (kept.won)
|
|
664
783
|
deps.log(`workflow-first: ${record.workflow} at ${record.digest} waits for another native turn: ${why}`);
|
|
665
784
|
return kept;
|
|
666
785
|
}
|
|
667
786
|
/** A connected agent's check waiting at a revision the folder moved past (an owner's edit landed a newer one): set aside
|
|
668
|
-
* with nothing
|
|
669
|
-
* (attemptOf): the newer revision is the one checked next. */
|
|
787
|
+
* with nothing decided, never promoted (the turns it checked kept on the record), and `stopped` as any stop with
|
|
788
|
+
* nothing checked, so it spends no recompile (attemptOf): the newer revision is the one checked next. */
|
|
670
789
|
async function setAside(deps, pending) {
|
|
671
|
-
|
|
790
|
+
const { workflow, digest, at: _at, decided: _decided, reason: _reason, check, ...extra } = pending;
|
|
791
|
+
if (!check)
|
|
672
792
|
return;
|
|
673
|
-
await
|
|
674
|
-
...pending, at: iso((deps.now ?? Date.now)()), decided: "hold",
|
|
675
|
-
reason: `${NOTHING_TO_CHECK}: a newer revision of it landed before a native turn of the connected agent checked it. It is not promoted; the newer revision is checked instead`,
|
|
676
|
-
check: { ...pending.check, n: 0, agreed: 0, alone: 0, of: [], stopped: true },
|
|
677
|
-
}, (was, current) => waitingSdk(was) && was.replay_id === pending.replay_id && !overtaken(current, was));
|
|
793
|
+
await holdUnchecked(deps, workflow, digest, check, `${NOTHING_TO_CHECK}: a newer revision of it landed before the connected agent's native turns finished checking it. It is not promoted; the newer revision is checked instead`, (was, current) => waitingSdk(was) && was.replay_id === pending.replay_id && !overtaken(current, was), { stopped: true, extra });
|
|
678
794
|
}
|
|
679
795
|
/** The launch a replay's runs all run with (PromotionRecord.launch), chosen once by the claim or person reserving it:
|
|
680
796
|
* `deps.launch` as a replay run takes it (a claim's claimed run's; a person's ask makes one now), the revision it runs,
|
|
@@ -704,6 +820,10 @@ function replayLaunchOf(deps) {
|
|
|
704
820
|
* id. A replay settled meanwhile, and a newer replay of the same revision its owner started since (a held revision may
|
|
705
821
|
* be replayed again), are not: an older replay's late decision never lands over a newer one. */
|
|
706
822
|
const sameReplay = (was, record) => was?.decided === "replaying" && was.replay_id === record.replay_id;
|
|
823
|
+
/** Whether `was` still reserves `record`'s native turn (a connected agent's check: one turn reserved at a time, its run
|
|
824
|
+
* first in `runs`). A turn's row (sdkCheckTurn) and its give-back (releaseSdkCheck) each take the turn off the record, so
|
|
825
|
+
* a second writer that read the same reservation finds it gone. */
|
|
826
|
+
const heldTurn = (was, record) => record.runs?.[0] !== undefined && was?.runs?.[0] === record.runs[0];
|
|
707
827
|
/** Cancels each of `record`'s replay runs not ended, as a person's cancel is (an in-flight one stops, what it spent booked
|
|
708
828
|
* on its row): once its check is decided with runs still at work (past its deadline). How many were sent their cancel. The
|
|
709
829
|
* record is the durable half: a cancel that is lost (a crash after the record, a write that fails) leaves a run whose
|
|
@@ -753,9 +873,14 @@ async function startReplay(deps, workflow, digest, of, from, id, launch) {
|
|
|
753
873
|
const base = readLaunchBody(launch.body);
|
|
754
874
|
if (!base)
|
|
755
875
|
throw new Error(`the launch of ${workflow.name} at ${digest}'s replay could not be read`);
|
|
876
|
+
const source = sourceSyncOf((await store.agents.revision(launch.revision))?.body);
|
|
877
|
+
if (base.sourceProject || source && !deps.admitAuxiliary)
|
|
878
|
+
throw new ReplayRefused("conflict", PROJECT_REPLAY_REFUSED);
|
|
756
879
|
const replay = { ...base, input: from.input, title: `Replay of ${workflow.name}: ${from.title}`.slice(0, 200), replay: { of, workflow: workflow.name, digest } };
|
|
757
880
|
const sealed = await handedTo(deps, launch, id);
|
|
758
881
|
try {
|
|
882
|
+
if (source)
|
|
883
|
+
return (await deps.admitAuxiliary({ runId: id, agentId, revisionId: launch.revision, launch: replay, ...(sealed ? { sealed } : {}) })).created;
|
|
759
884
|
await store.runs.create({ id, agentId, revisionId: launch.revision }, { body: launchBody(replay), ...(sealed ? { sealed } : {}) });
|
|
760
885
|
return true;
|
|
761
886
|
}
|
|
@@ -855,6 +980,7 @@ function skipWordsOf(tools, skipped) {
|
|
|
855
980
|
}
|
|
856
981
|
/** Why a replay a person asked for (askReplay) or read (replayView) was refused: `missing`, no such workflow, revision or
|
|
857
982
|
* replay of the agent (404); `conflict`, the revision cannot replay now (409), in words that say why. */
|
|
983
|
+
const PROJECT_REPLAY_REFUSED = "An auxiliary replay requires its own project placement for this moved agent; nothing was started. Start a normal run to use the saved project.";
|
|
858
984
|
export class ReplayRefused extends Error {
|
|
859
985
|
kind;
|
|
860
986
|
constructor(kind, message) {
|
|
@@ -922,9 +1048,11 @@ export async function askReplay(ask, name, digest, inputs) {
|
|
|
922
1048
|
if (!picked.length)
|
|
923
1049
|
throw new ReplayRefused("conflict", `${name} at ${digest} has no input to replay on: none of ${typeof inputs === "number" ? `the agent's newest ${plural(inputs, "completed run")}` : last ? "the runs it was last checked on" : "the agent's last completed runs"} has an input it fits. Nothing was started.`);
|
|
924
1050
|
const { launch, revisionId } = await ask.launchOf(picked[0].launch.input);
|
|
1051
|
+
if (launch.sourceProject || sourceSyncOf((await ask.store.agents.revision(revisionId))?.body) && !ask.admitAuxiliary)
|
|
1052
|
+
throw new ReplayRefused("conflict", PROJECT_REPLAY_REFUSED);
|
|
925
1053
|
if (!launch.learning || launch.learning.noWorkflows)
|
|
926
1054
|
throw new ReplayRefused("conflict", `A replay runs ${name} as a run of the agent that learns does, and the agent's runs do not take learned workflows here (its learning is off, it takes no workflows, or this server's is off).`);
|
|
927
|
-
const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.now ? { now: ask.now } : {}) };
|
|
1055
|
+
const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.admitAuxiliary ? { admitAuxiliary: ask.admitAuxiliary } : {}), ...(ask.now ? { now: ask.now } : {}) };
|
|
928
1056
|
const bar = { ...loop, attempt: attemptOf(records, name, digest) };
|
|
929
1057
|
const said = `checking it on ${plural(picked.length, "input")} of the agent's own runs, as its owner asked`;
|
|
930
1058
|
// Kept only while the revision's newest record is still the one read here: each record write stamps a new `at`.
|
package/dist/runner/redact.d.ts
CHANGED
|
@@ -24,9 +24,22 @@ export declare const processSecretRedactor: () => Redact;
|
|
|
24
24
|
export interface HeldRedact extends Redact {
|
|
25
25
|
/** Cut `values` too from here on, each in every form; one shorter than MIN_SECRET, whitespace aside, is left out. */
|
|
26
26
|
hold(values: readonly string[]): void;
|
|
27
|
+
/** Hold `values`, and cut them from run `runId`'s journal as it is written too (runner.ts): the run's own tool keys
|
|
28
|
+
* (run-keys.ts), erased at its turn's end, so no read after it could cut them. */
|
|
29
|
+
carry(runId: string, values: readonly string[]): void;
|
|
30
|
+
/** The cut of what run `runId` carried (`carry`), or undefined while it carried none. */
|
|
31
|
+
carried(runId: string): Redact | undefined;
|
|
32
|
+
/** Forget what run `runId` carried, once the runner lets its claim go: a later run's writes are never cut of it. The
|
|
33
|
+
* values stay held (`hold`). */
|
|
34
|
+
dropCarried(runId: string): void;
|
|
27
35
|
}
|
|
28
36
|
/** `base`, then every value held since (`hold`). One that holds already is itself: wrapped once, the one instance. */
|
|
29
37
|
export declare function heldRedactor(base: Redact): HeldRedact;
|
|
38
|
+
/** Every string inside `value` cut by `cut`: what the run's process writes, as the runner's redactor would cut it in a
|
|
39
|
+
* loop of its own (rule three: no secret the runner holds is written). `names`: each object's and map's names too (a
|
|
40
|
+
* model may write a value as a JSON name); two names cut to one are both kept, the later ones numbered. A number that
|
|
41
|
+
* shows a value `cut` holds (a key of digits alone, quoted as a JSON number: key-refusal.ts heldNumber) is "[redacted]". */
|
|
42
|
+
export declare function cutDeep<T>(value: T, cut: Redact, names?: boolean): T;
|
|
30
43
|
/** The secrets a claim opened from the store (`env`, claimSecrets' environment for the run) held by `redact`, the run's
|
|
31
44
|
* one redactor, so a host tool's or a provider's error that echoes one is cut in the run's record, its end and its logs. */
|
|
32
45
|
export declare function holdClaimed(redact: HeldRedact, env: NodeJS.ProcessEnv): void;
|
package/dist/runner/redact.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// loop's failed end), the runner's events, and the model route's error text that pi records. Each passes through the one
|
|
4
4
|
// function made here, which puts "[redacted]" in place of every secret value the runner holds, in every form a value
|
|
5
5
|
// can take in text (key-refusal.ts redactedAnswer: as written, JSON-escaped, base64, hex and percent-encoded).
|
|
6
|
-
import { redactedAnswer } from "../key-refusal.js";
|
|
6
|
+
import { heldNumber, redactedAnswer } from "../key-refusal.js";
|
|
7
7
|
import { MIN_SECRET } from "../learn/secrets.js";
|
|
8
8
|
import { hostSecrets, SECRET_NAMES } from "../secrets.js";
|
|
9
9
|
import { planOf } from "../chatgpt-plan.js";
|
|
@@ -39,6 +39,8 @@ export function heldRedactor(base) {
|
|
|
39
39
|
if (isHeld(base))
|
|
40
40
|
return base;
|
|
41
41
|
const held = new Set();
|
|
42
|
+
/** Each run's carried values and their cut, made at its first use after a carry. */
|
|
43
|
+
const carried = new Map();
|
|
42
44
|
const cut = ((text) => {
|
|
43
45
|
const once = base(text);
|
|
44
46
|
return once && held.size ? redactedAnswer(once, [...held]) : once;
|
|
@@ -48,12 +50,76 @@ export function heldRedactor(base) {
|
|
|
48
50
|
if (value.replace(/\s+/g, "").length >= MIN_SECRET)
|
|
49
51
|
held.add(value);
|
|
50
52
|
};
|
|
53
|
+
cut.carry = (runId, values) => {
|
|
54
|
+
cut.hold(values);
|
|
55
|
+
const kept = values.filter((value) => held.has(value));
|
|
56
|
+
if (!kept.length)
|
|
57
|
+
return;
|
|
58
|
+
const run = new Set([...(carried.get(runId)?.values ?? []), ...kept]);
|
|
59
|
+
carried.set(runId, { values: run });
|
|
60
|
+
};
|
|
61
|
+
cut.carried = (runId) => {
|
|
62
|
+
const run = carried.get(runId);
|
|
63
|
+
if (!run)
|
|
64
|
+
return undefined;
|
|
65
|
+
return (run.cut ??= secretRedactor([...run.values]));
|
|
66
|
+
};
|
|
67
|
+
cut.dropCarried = (runId) => void carried.delete(runId);
|
|
51
68
|
// Its values are the base's and every one held since; a base that does not know its own leaves them unknown.
|
|
52
69
|
const known = base.heldValues;
|
|
53
70
|
if (known)
|
|
54
71
|
withHeldValues(cut, () => [...new Set([...known(), ...held])]);
|
|
55
72
|
return cut;
|
|
56
73
|
}
|
|
74
|
+
/** Every string inside `value` cut by `cut`: what the run's process writes, as the runner's redactor would cut it in a
|
|
75
|
+
* loop of its own (rule three: no secret the runner holds is written). `names`: each object's and map's names too (a
|
|
76
|
+
* model may write a value as a JSON name); two names cut to one are both kept, the later ones numbered. A number that
|
|
77
|
+
* shows a value `cut` holds (a key of digits alone, quoted as a JSON number: key-refusal.ts heldNumber) is "[redacted]". */
|
|
78
|
+
export function cutDeep(value, cut, names = false) {
|
|
79
|
+
// The values `cut` holds, read once for the whole of `value` at its first number.
|
|
80
|
+
let held;
|
|
81
|
+
const shows = (number) => {
|
|
82
|
+
const text = String(number);
|
|
83
|
+
if (held === undefined)
|
|
84
|
+
held = cut.heldValues?.() ?? null;
|
|
85
|
+
if (!held)
|
|
86
|
+
return cut(text) !== text;
|
|
87
|
+
// Digits shorter than any held value can't hold one, in any form; only the same number written otherwise can.
|
|
88
|
+
if (text.length < MIN_SECRET)
|
|
89
|
+
return held.some((secret) => secret.trim() !== "" && Number(secret) === Number(number));
|
|
90
|
+
return heldNumber(number, held);
|
|
91
|
+
};
|
|
92
|
+
const named = (taken, key) => {
|
|
93
|
+
const once = names ? cut(key) : key;
|
|
94
|
+
let name = once;
|
|
95
|
+
for (let n = 2; taken(name); n++)
|
|
96
|
+
name = `${once} (${n})`;
|
|
97
|
+
return name;
|
|
98
|
+
};
|
|
99
|
+
const walk = (one) => {
|
|
100
|
+
if (typeof one === "string")
|
|
101
|
+
return cut(one);
|
|
102
|
+
if (typeof one === "number" || typeof one === "bigint")
|
|
103
|
+
return shows(one) ? "[redacted]" : one;
|
|
104
|
+
if (one === null || typeof one !== "object")
|
|
105
|
+
return one;
|
|
106
|
+
if (ArrayBuffer.isView(one) || one instanceof Date || one instanceof RegExp || one instanceof ArrayBuffer)
|
|
107
|
+
return one;
|
|
108
|
+
if (Array.isArray(one))
|
|
109
|
+
return one.map(walk);
|
|
110
|
+
if (one instanceof Map) {
|
|
111
|
+
const out = new Map();
|
|
112
|
+
for (const [k, v] of one)
|
|
113
|
+
out.set(typeof k === "string" ? named((name) => out.has(name), k) : k, walk(v));
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
const out = {};
|
|
117
|
+
for (const key of Object.keys(one))
|
|
118
|
+
Object.defineProperty(out, named((name) => Object.hasOwn(out, name), key), { value: walk(one[key]), enumerable: true, writable: true, configurable: true });
|
|
119
|
+
return out;
|
|
120
|
+
};
|
|
121
|
+
return walk(value);
|
|
122
|
+
}
|
|
57
123
|
/** The secrets a claim opened from the store (`env`, claimSecrets' environment for the run) held by `redact`, the run's
|
|
58
124
|
* one redactor, so a host tool's or a provider's error that echoes one is cut in the run's record, its end and its logs. */
|
|
59
125
|
export function holdClaimed(redact, env) {
|
|
@@ -9,6 +9,15 @@ export declare class ChannelClosed extends Error {
|
|
|
9
9
|
export declare class ChannelRefused extends Error {
|
|
10
10
|
name: string;
|
|
11
11
|
}
|
|
12
|
+
/** A call or an answer past the channel's cap: it fails alone, and the channel goes on. Its bytes and the cap cross with
|
|
13
|
+
* it (registered on both sides), so a runner can tell a run whose records no longer fit from one that may go on. */
|
|
14
|
+
export declare class FrameTooLarge extends RangeError {
|
|
15
|
+
name: string;
|
|
16
|
+
readonly bytes: number;
|
|
17
|
+
readonly limit: number;
|
|
18
|
+
/** `what`: "an answer", or "a call of <method>". */
|
|
19
|
+
constructor(what: string, bytes: number, limit: number);
|
|
20
|
+
}
|
|
12
21
|
export declare function registerErrors(classes: Record<string, abstract new (...args: never[]) => Error>): void;
|
|
13
22
|
/** What a target exposed by name does with a call: its method and arguments, as decoded. */
|
|
14
23
|
export type Dispatch = (method: string, args: unknown[]) => unknown;
|