@parcha/agentrun-serve 0.1.0-beta.52 → 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 +122 -1
- package/README.md +213 -24
- package/dist/agent-delete.d.ts +5 -6
- package/dist/agent-delete.js +30 -67
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agents-store.d.ts +26 -20
- package/dist/agents-store.js +41 -33
- package/dist/api-only.d.ts +26 -6
- package/dist/api-only.js +35 -13
- 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 +1 -0
- package/dist/computer-setting.js +8 -1
- 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.js +10 -13
- 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 +14 -1
- package/dist/learn/commit.js +156 -1
- package/dist/learn/compile.js +22 -8
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +10 -1
- package/dist/learn/learning.sh +15 -3
- package/dist/learn/promote.d.ts +2 -2
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning.d.ts +9 -6
- package/dist/learning.js +9 -4
- package/dist/mcp-gateway.js +15 -2
- 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 +16 -12
- 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 +167 -36
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +16 -1
- package/dist/run-launch.js +30 -1
- 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-view.d.ts +17 -0
- package/dist/run-view.js +25 -1
- package/dist/runner/adapter-loop.d.ts +11 -3
- package/dist/runner/adapter-loop.js +138 -22
- package/dist/runner/adapter-run-spec.js +25 -12
- package/dist/runner/audit.d.ts +2 -0
- package/dist/runner/audit.js +9 -1
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +29 -3
- package/dist/runner/claim-secrets.js +38 -4
- package/dist/runner/cli-run-spec.js +23 -12
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +11 -1
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +2 -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 +7 -2
- package/dist/runner/learning-end.js +22 -10
- 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 +6 -1
- package/dist/runner/mcp-run.d.ts +10 -7
- package/dist/runner/mcp-run.js +3 -5
- 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 +14 -6
- package/dist/runner/promotion.js +98 -41
- 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 +171 -41
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.js +5 -2
- package/dist/runner/runner.js +26 -9
- 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 +1 -1
- package/dist/runs-over-store.d.ts +34 -6
- package/dist/runs-over-store.js +133 -25
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +117 -26
- 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 +600 -110
- 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 +4 -0
- package/dist/store/agent-body.js +16 -5
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +2 -1
- 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 +4 -12
- package/dist/store/sqlite/run-launch.js +5 -19
- package/dist/store/sqlite/store.js +224 -170
- package/dist/store/store.d.ts +116 -39
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +2 -2
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/template-import.d.ts +10 -2
- package/dist/template-import.js +116 -13
- package/dist/templates.d.ts +26 -5
- package/dist/templates.js +62 -10
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.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/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 +1 -1
- package/dist/uploads.js +1 -1
- package/dist/validate.js +1 -2
- 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/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- 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-B-D0EM3j.js +0 -733
- package/dist/console/assets/index-DlQepP2J.css +0 -1
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
// The kernel's loop for any harness on the adapter contract (AgentAdapter: claude-agent, codex, opencode, and pi through
|
|
2
|
+
// runner/adapters/pi.ts): one claimed run, one Harness on the claim's journal (behind the loop's Gate), one session.
|
|
3
|
+
// What the loop owns, the same for every harness:
|
|
4
|
+
// - the claim and its journal: every commit the loop stages is matched to the commit that carries it (Gate);
|
|
5
|
+
// - the run's end: an `agentrun.end` entry with the run row's patch (ended, stopped with why, failed with why) and a
|
|
6
|
+
// stop's take; a park (an ask with the run parked); an interrupt on a lost claim or a shutdown (nothing more written;
|
|
7
|
+
// the session ended with the adapter's interrupt() and then close(), the path a CLI adapter's kill rides);
|
|
8
|
+
// - a restart of the Session on the kernel's own fault between a call and its result, under a finite restart limit;
|
|
9
|
+
// - the gate before a call's intent (io.gate: the kernel's beforeIntent point, then allow, deny or ask), and the rule
|
|
10
|
+
// before a side effect around every host tool (side-effects.ts: a flush unless the tool is replay-safe, the call, the
|
|
11
|
+
// beforeResult point), on the host-tool path every adapter's calls take;
|
|
12
|
+
// - the paid model requests: the runner's booking (modelPortFor), the one ledger, every request through it;
|
|
13
|
+
// - the held state (pi.live) reported through deps.live; the commands (steer, approve, deny).
|
|
14
|
+
import { ProjectDrain } from "./project-drain.js";
|
|
1
15
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
2
16
|
import { createModels } from "@earendil-works/pi-ai/models";
|
|
3
17
|
import { createRegistry, defineDoc, Harness, LiveDoc, ROOT_CONVERSATION_ID, ToolTask } from "@earendil-works/pi-durable";
|
|
4
18
|
import { modelPortFor, RUNNER_RECORDS, sessionSpendOf, turnCostOf } from "@parcha/agentrun-kernel";
|
|
5
19
|
import { ASK_PERSON_WAITING, capNowOf, endedAnswer, KINDS, MESSAGE_SENT_AGAIN, toolCalls, withdrawnAnswers } from "./journal-kinds.js";
|
|
6
20
|
import { turnEndedOnAsk } from "../store-reads/journal.js";
|
|
7
|
-
import { CAP_WRAPUP, COMPUTER_NOTE, endsTurn, HOST_PHASE, MESSAGE_ORIGIN, originOf, REQUEST_ENDED, REQUEST_STARTED, RUN_RESUMED } from "../timeline/index.js";
|
|
21
|
+
import { CAP_REFUSED, CAP_WRAPUP, COMPUTER_NOTE, endsTurn, HOST_PHASE, MESSAGE_ORIGIN, originOf, REQUEST_ENDED, REQUEST_STARTED, RUN_RESUMED } from "../timeline/index.js";
|
|
8
22
|
import { raiseFollowUpId } from "../run-view.js";
|
|
9
23
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
10
24
|
/** The root entries a claim writes before its turn, whatever the run's turns are (its session's key, a phase row, a
|
|
@@ -27,6 +41,7 @@ const outputRetried = (entries) => {
|
|
|
27
41
|
return at >= 0 && entries.slice(at + 1).some((entry) => entry.kind === "pi.assistant" || (entry.kind === KINDS.message && entry.data?.role === "model"));
|
|
28
42
|
};
|
|
29
43
|
import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
|
|
44
|
+
import { heldRedactor } from "./redact.js";
|
|
30
45
|
import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
|
|
31
46
|
import { ADAPTER_API } from "../turn-end.js";
|
|
32
47
|
import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
|
|
@@ -41,9 +56,9 @@ import { COMPUTER_CALLS, recordingCalls } from "../computer-calls.js";
|
|
|
41
56
|
import { channelCallOf, runChannelCall } from "./computer-channel.js";
|
|
42
57
|
import { COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND } from "../computer-commands.js";
|
|
43
58
|
import { journalSessions } from "./sessions.js";
|
|
44
|
-
import { DECISION_SESSION, FIT_TOLERANCE, freeModel, freeRequestsIn, freeWrapUpDue, freeWrapUpWords, noteFor, overCapOf, paidRefusal, requestFigures, runCap, SERVER_NOTE_LABEL, typicalCost, wrapUpWords, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
59
|
+
import { DECISION_SESSION, FIT_TOLERANCE, freeModel, freeRequestsIn, freeWrapUpDue, freeWrapUpWords, noteFor, overCapEnd, overCapOf, paidRefusal, requestFigures, runCap, SERVER_NOTE_LABEL, typicalCost, wrapUpWords, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
45
60
|
import { PORT_PROVIDER, portModels, tierProvider } from "../port-models.js";
|
|
46
|
-
import { bookedIn } from "../paid-calls.js";
|
|
61
|
+
import { bookedIn, stopRunWith } from "../paid-calls.js";
|
|
47
62
|
import { sideEffect } from "./side-effects.js";
|
|
48
63
|
import { McpClaimRefused } from "./mcp-claim.js";
|
|
49
64
|
import { CODEMODE, defersCatalog, isCatalogWire, TOOLS_CALL, TOOLS_SEARCH } from "@parcha/agentrun-kernel";
|
|
@@ -55,6 +70,20 @@ import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprov
|
|
|
55
70
|
import { warnHoldShort } from "../print.js";
|
|
56
71
|
import { feedbackAsk, feedbackOf, jobEndOpen, pendingFeedbackOf } from "./feedback-round.js";
|
|
57
72
|
import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
73
|
+
/** What a session's requests were charged (sessionSpendOf's figures of those answered, a crash's cut one at its hold among
|
|
74
|
+
* them), never one still in flight at its hold. Null: one charged has no figure. */
|
|
75
|
+
function chargedOf(records) {
|
|
76
|
+
const read = sessionSpendOf(records);
|
|
77
|
+
let usd = 0;
|
|
78
|
+
for (const figure of read.figures) {
|
|
79
|
+
if (!read.answered.has(figure.turn))
|
|
80
|
+
continue;
|
|
81
|
+
if (figure.usd === null)
|
|
82
|
+
return null;
|
|
83
|
+
usd += figure.usd;
|
|
84
|
+
}
|
|
85
|
+
return usd;
|
|
86
|
+
}
|
|
58
87
|
/** The end of a harness's own call (Claude Code's WebSearch) the gate held and then let run: the host ran nothing of it,
|
|
59
88
|
* and the harness's next call runs it. */
|
|
60
89
|
export const OWN_TOOL_RELEASED = "Allowed after it waited; the agent's own tool runs it on its next call.";
|
|
@@ -375,6 +404,13 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
|
|
|
375
404
|
void flushText().catch(() => undefined);
|
|
376
405
|
else if (event.type === "turn_end")
|
|
377
406
|
void flushText(event).catch(() => undefined);
|
|
407
|
+
else if (event.type === "notice") {
|
|
408
|
+
// The adapter's own words (the ACP mirror past its budget): a phase row after what the model said before it.
|
|
409
|
+
void flushText().catch(() => undefined);
|
|
410
|
+
void inTurn(async () => {
|
|
411
|
+
await harness.commit((tx) => tx.appendEntry(root.id, { kind: HOST_PHASE, data: { summary: event.text, at: now() } }), context);
|
|
412
|
+
}).catch(() => undefined);
|
|
413
|
+
}
|
|
378
414
|
},
|
|
379
415
|
flushText,
|
|
380
416
|
flushSaid: () => (answer === undefined && text.trim() !== "" ? flushText(undefined, true) : Promise.resolve()),
|
|
@@ -640,6 +676,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
640
676
|
};
|
|
641
677
|
/** The current pass's spec's release, until it is called (closeSession). */
|
|
642
678
|
let releaseNow;
|
|
679
|
+
const projectWork = new ProjectDrain();
|
|
680
|
+
const projectCall = (call, strict = !!specNow?.projectCheckpoint) => strict ? projectWork.run(call) : call();
|
|
643
681
|
/** The current pass ended in a park that keeps its computer (keepAtPark), for this cause, until its release reads it. */
|
|
644
682
|
let parkedNow;
|
|
645
683
|
/** From the end-of-run step's start (or a claim that found its turn open: lookingBackOpen, from its session's open)
|
|
@@ -951,7 +989,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
951
989
|
const channelCommand = async (command) => {
|
|
952
990
|
await Promise.race([ready, (finished ?? new Promise(() => { })).then(() => undefined, () => undefined)]);
|
|
953
991
|
const [theGate, pass, theHeld] = [gate, channelNow, heldNow];
|
|
954
|
-
if (!theGate || theGate.sealed)
|
|
992
|
+
if (!theGate || theGate.sealed || projectWork.closed)
|
|
955
993
|
return { refused: "The run's computer is not up now: the run is starting, parking or ending." };
|
|
956
994
|
if (!pass)
|
|
957
995
|
return { refused: specNow?.computer ? "The run's computer is not up now: the run is starting, parking or ending." : "This run has no computer that takes protocol calls: none, or a browser." };
|
|
@@ -966,7 +1004,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
966
1004
|
theHeld?.callStarted();
|
|
967
1005
|
let done;
|
|
968
1006
|
try {
|
|
969
|
-
done = await runChannelCall(pass.computer, call, AbortSignal.any([deps.signal, AbortSignal.timeout(CALL_MS)]), now);
|
|
1007
|
+
done = await projectCall(() => runChannelCall(pass.computer, call, AbortSignal.any([deps.signal, AbortSignal.timeout(CALL_MS)]), now));
|
|
970
1008
|
}
|
|
971
1009
|
finally {
|
|
972
1010
|
theHeld?.callEnded(now());
|
|
@@ -1460,7 +1498,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1460
1498
|
return;
|
|
1461
1499
|
passGate.expect(writesEntry(kind, test), { run: { summary } }).catch(() => undefined);
|
|
1462
1500
|
};
|
|
1463
|
-
const runOf = { harness, registry, setModels: (given) => (models = given), ledger, ...(deps.redact ? { redact: deps.redact } : {}), signal: deps.signal, stopped: AbortSignal.any([deps.signal, stopAbort.signal]), phase, rowSummaryOn };
|
|
1501
|
+
const runOf = { harness, registry, setModels: (given) => (models = given), ledger, ...(deps.redact ? { redact: heldRedactor(deps.redact) } : {}), signal: deps.signal, stopped: AbortSignal.any([deps.signal, stopAbort.signal]), phase, rowSummaryOn };
|
|
1464
1502
|
// The spec, its MCP claim step among it (mcpForClaim, before the session opens). A refusal there ends the run in its
|
|
1465
1503
|
// words with nothing sent; a claim lost during its refresh ends the loop with nothing more written. A claim the spec
|
|
1466
1504
|
// refuses (ClaimRefused: a handed sign-in that won't read back) ends the run in its words too.
|
|
@@ -1531,7 +1569,33 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1531
1569
|
// A host tool call's paid requests name the session the call runs in (RunTools.admit `under`): a request of it still
|
|
1532
1570
|
// in flight may be the one that asked for the call (Claude Code books its cost after its calls; Codex starts a call
|
|
1533
1571
|
// with its response open), so the call is judged beside it and never waits on it. pi's request has answered by then.
|
|
1534
|
-
|
|
1572
|
+
// A call settled above its hold (a fal job whose output states more than its input asked, a monid call charged above
|
|
1573
|
+
// its maxCost) can take what the run was
|
|
1574
|
+
// charged past its cap. From then on, a settle that leaves the run's charges over its cap stops the run at once in
|
|
1575
|
+
// the cap's words (overCap, settled charges only), as a stop for good (paid-calls.ts stopRun): no tool runs after it,
|
|
1576
|
+
// a script's own calls included. A charge is never given back, so that stop holds; a call still in flight counts
|
|
1577
|
+
// only toward admissions (the cap's rule), where it refuses a new call, never stops the run. Its hold, kept from its
|
|
1578
|
+
// admission, tells an overrun.
|
|
1579
|
+
const holds = new Map();
|
|
1580
|
+
let overran = false;
|
|
1581
|
+
const paidUnder = {
|
|
1582
|
+
admit: async (request) => {
|
|
1583
|
+
const admitted = await paid.admit({ ...request, under: spec.session.key });
|
|
1584
|
+
holds.set(request.id, request.holdUsd);
|
|
1585
|
+
return admitted;
|
|
1586
|
+
},
|
|
1587
|
+
settle: async (id, usd, options) => {
|
|
1588
|
+
const held = holds.get(id);
|
|
1589
|
+
holds.delete(id);
|
|
1590
|
+
const settled = await paid.settle(id, usd, options);
|
|
1591
|
+
if (typeof usd === "number" && held !== undefined && Math.round(usd * 1e6) > Math.round(held * 1e6))
|
|
1592
|
+
overran = true;
|
|
1593
|
+
const over = overran ? await overCap({ settled: true }) : undefined;
|
|
1594
|
+
if (over)
|
|
1595
|
+
await stopRunWith(ledger.pause)(over);
|
|
1596
|
+
return settled;
|
|
1597
|
+
},
|
|
1598
|
+
};
|
|
1535
1599
|
let refused;
|
|
1536
1600
|
/** The pause a refusal for room journaled before pi heard of it (pauseAtCap), the run parked with it. */
|
|
1537
1601
|
let pausedAtRefusal = false;
|
|
@@ -1540,8 +1604,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1540
1604
|
/** How the run ends once its booked spend passed its cap (the kernel's overCapEnd, main's run end): every session's
|
|
1541
1605
|
* booked spend summed, as the cap reads it; the bound, its model session's requests' since the cost last fit, so a
|
|
1542
1606
|
* cache miss within that bound pauses the run at its next request instead. Undefined while it fits, with no cap, or
|
|
1543
|
-
* with a spend unknown. */
|
|
1544
|
-
const overCap = async () => {
|
|
1607
|
+
* with a spend unknown. `settled`: what its sessions were charged only, never a request still in flight at its hold. */
|
|
1608
|
+
const overCap = async ({ settled = false } = {}) => {
|
|
1545
1609
|
// A run whose spec gives no cap (no runCap, or no cap's rule) has none to pass.
|
|
1546
1610
|
if (!spec.cap || !spec.runCap)
|
|
1547
1611
|
return undefined;
|
|
@@ -1556,11 +1620,15 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1556
1620
|
for (const key of await sessions.keys()) {
|
|
1557
1621
|
if (key === spec.session.key)
|
|
1558
1622
|
continue;
|
|
1559
|
-
const spent = sessionSpendOf(await sessions.read(key)).spentUsd;
|
|
1623
|
+
const spent = settled ? chargedOf(await sessions.read(key)) : sessionSpendOf(await sessions.read(key)).spentUsd;
|
|
1560
1624
|
if (spent === null)
|
|
1561
1625
|
return undefined;
|
|
1562
1626
|
others += spent;
|
|
1563
1627
|
}
|
|
1628
|
+
if (settled) {
|
|
1629
|
+
const own = chargedOf(await sessions.read(spec.session.key));
|
|
1630
|
+
return own === null ? undefined : overCapEnd(others + own, cap);
|
|
1631
|
+
}
|
|
1564
1632
|
// Its model session read as the cap reads it (the kernel's overCapOf: a request cut by a crash at its hold plus its
|
|
1565
1633
|
// bound, and that bound kept, so a possible cache miss pauses the run, never fails it).
|
|
1566
1634
|
return overCapOf(await sessions.read(spec.session.key), others, cap);
|
|
@@ -1617,8 +1685,12 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1617
1685
|
// A paid call's refusal is the call's result first: its pause is journaled at the model's next request (beforeRequest,
|
|
1618
1686
|
// pendingPause), once the harness has stored that result, so the run never reads waiting on a raise before its
|
|
1619
1687
|
// Timeline says why. The refusal is kept on the root at once (KINDS.pausePending, no run patch, nothing a person
|
|
1620
|
-
// reads), so a claim lost in between restores it (pendingPauseOf) and the next claim's request parks the run.
|
|
1688
|
+
// reads), so a claim lost in between restores it (pendingPauseOf) and the next claim's request parks the run. A stop
|
|
1689
|
+
// for good (paid-calls.ts stopRun) stays: a refusal after it (a call admitted after the stop, refused for room) never
|
|
1690
|
+
// replaces it, so no tool runs after the stop.
|
|
1621
1691
|
pauseFor = async (refusal) => {
|
|
1692
|
+
if (pendingPause?.forGood)
|
|
1693
|
+
return;
|
|
1622
1694
|
pendingPause = refusal;
|
|
1623
1695
|
await keepPending(refusal);
|
|
1624
1696
|
};
|
|
@@ -1931,8 +2003,10 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1931
2003
|
// spend and each request or paid step still out at its hold and bound, read from the run's records at each call. A
|
|
1932
2004
|
// hold-only step still open (a browser session's reserve) is no spend in its records, but the cap holds it in
|
|
1933
2005
|
// flight: it counts at its hold too. One a lost claim left open was given back at this claim's open (bookCut).
|
|
1934
|
-
// Its answer is the words a call reads once the run wraps up (wrap-up.ts wrapUpText),
|
|
1935
|
-
|
|
2006
|
+
// Its answer is the words a call reads once the run wraps up (wrap-up.ts wrapUpText), with the cap it was judged
|
|
2007
|
+
// under (read once, before the spend reads it awaits: a raise landing meanwhile is the next call's), undefined while
|
|
2008
|
+
// it does not.
|
|
2009
|
+
const wrapUpAt = async () => {
|
|
1936
2010
|
// A run whose spec gives no cap (no runCap) has none to wrap up at, as overCap reads it.
|
|
1937
2011
|
if (!spec.runCap)
|
|
1938
2012
|
return undefined;
|
|
@@ -1951,9 +2025,32 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1951
2025
|
if (!wrappingUp(capUsd, taken, reserveOf(capNote.lastFigures)))
|
|
1952
2026
|
return undefined;
|
|
1953
2027
|
// A cap below what the model needs for one more step and an answer is named in the words, by the same rule.
|
|
1954
|
-
return wrapUpText(capUsd, capNote.lastModel, stepAndAnswerFor(capNote.lastFigures, (step0Usd) => typicalCost(capNote.costs, step0Usd)), capNote.lastEffort);
|
|
2028
|
+
return { words: wrapUpText(capUsd, capNote.lastModel, stepAndAnswerFor(capNote.lastFigures, (step0Usd) => typicalCost(capNote.costs, step0Usd)), capNote.lastEffort), capUsd };
|
|
2029
|
+
};
|
|
2030
|
+
/** The wrap-up's words alone (wrapUpAt). */
|
|
2031
|
+
const wrapUp = async () => (await wrapUpAt())?.words;
|
|
2032
|
+
// The wrap-up's refusal of a call (the gate's, wrapUp's words): kept on the run's root as a CAP_REFUSED entry, its
|
|
2033
|
+
// call and the cap it was refused under, so the run's view says it wound down for its cap (store-view.ts
|
|
2034
|
+
// windDownOf: `stopped_for`, `budget_refused_calls`). A call refused again (a replay) is the same call: the reader
|
|
2035
|
+
// counts each call once. Not written once the journal is sealed; a write that fails is warned and the call is
|
|
2036
|
+
// refused all the same. The cap kept is the one the refusal was judged under (wrapUpAt's), never one read after it.
|
|
2037
|
+
const wrapUpRefusal = async (callId) => {
|
|
2038
|
+
const refusal = await wrapUpAt();
|
|
2039
|
+
if (refusal === undefined)
|
|
2040
|
+
return undefined;
|
|
2041
|
+
const { words, capUsd } = refusal;
|
|
2042
|
+
if (gate?.sealed)
|
|
2043
|
+
return words;
|
|
2044
|
+
try {
|
|
2045
|
+
await wrapUpHarness.commit((tx) => tx.appendEntry(wrapUpRoot.id, { kind: CAP_REFUSED, data: { callId, capUsd } }), context);
|
|
2046
|
+
await deps.flush();
|
|
2047
|
+
}
|
|
2048
|
+
catch (error) {
|
|
2049
|
+
console.warn(`[runner] the wrap-up's refusal of a call was not kept (the call is refused): ${said(error)}`);
|
|
2050
|
+
}
|
|
2051
|
+
return words;
|
|
1955
2052
|
};
|
|
1956
|
-
const gateOf = preIntentGate(spec, hooks,
|
|
2053
|
+
const gateOf = preIntentGate(spec, hooks, wrapUpRefusal);
|
|
1957
2054
|
// A CLI's run: the loop keeps its visible record (record: "loop"), every call a crash or a fault left open ended.
|
|
1958
2055
|
const record = spec.record === "loop" ? await openCliRecord(harness, gate.journal, context, now, spec.cwd) : undefined;
|
|
1959
2056
|
cliRecord = record;
|
|
@@ -2036,7 +2133,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2036
2133
|
// refused for room pauses the run (Ledger.pause, the run's pause), as main's paidCall does.
|
|
2037
2134
|
// The computer protocol calls it makes, kept beside it on the run's root (COMPUTER_CALLS) for its result
|
|
2038
2135
|
// row's computer_calls, before its result is written.
|
|
2039
|
-
route: () => bookedIn({ call: toolContext.callId, paid: paidUnder, pause: ledger.pause }, () => recordingCalls(() => tool.call(args, { ...toolContext, signal: toolContext.signal ? AbortSignal.any([toolContext.signal, stopAbort.signal]) : stopAbort.signal }), (calls, dropped) => keepCalls(toolContext.callId, calls, dropped))),
|
|
2136
|
+
route: () => bookedIn({ call: toolContext.callId, paid: paidUnder, pause: ledger.pause }, () => recordingCalls(() => projectCall(() => tool.call(args, { ...toolContext, signal: toolContext.signal ? AbortSignal.any([toolContext.signal, stopAbort.signal]) : stopAbort.signal }), !!spec.projectCheckpoint), (calls, dropped) => keepCalls(toolContext.callId, calls, dropped))),
|
|
2040
2137
|
beforeResult: async (answer) => {
|
|
2041
2138
|
const call = { callId: toolContext.callId, tool: tool.name, args: (args ?? {}) };
|
|
2042
2139
|
try {
|
|
@@ -2245,7 +2342,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2245
2342
|
if (!gate?.sealed)
|
|
2246
2343
|
throw error;
|
|
2247
2344
|
};
|
|
2248
|
-
const nestedAsking = preIntentGate(spec, hooks,
|
|
2345
|
+
const nestedAsking = preIntentGate(spec, hooks, wrapUpRefusal, async (call) => (await nestedRecord()).park(call.callId, call.tool, call.args ?? {}, replaySafe(call.tool)).catch(unlessSealed));
|
|
2249
2346
|
const nestedGate = async (call, hookContext) => {
|
|
2250
2347
|
if (call.nested !== true)
|
|
2251
2348
|
return gateOf(call, hookContext);
|
|
@@ -2259,7 +2356,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2259
2356
|
};
|
|
2260
2357
|
const nestedEnded = async (callId, status, output) => (await nestedRecord()).end(callId, status, output).catch(unlessSealed);
|
|
2261
2358
|
const askingGate = record
|
|
2262
|
-
? preIntentGate(spec, hooks,
|
|
2359
|
+
? preIntentGate(spec, hooks, wrapUpRefusal, (call) => record.park(call.callId, call.tool, call.args ?? {}, replaySafe(call.tool)).catch((error) => {
|
|
2263
2360
|
if (!gate?.sealed)
|
|
2264
2361
|
throw error;
|
|
2265
2362
|
}))
|
|
@@ -2635,7 +2732,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2635
2732
|
if (ended)
|
|
2636
2733
|
answer = recorded(ended);
|
|
2637
2734
|
else {
|
|
2638
|
-
const verdict = await preIntentGate(spec, hooks,
|
|
2735
|
+
const verdict = await preIntentGate(spec, hooks, wrapUpRefusal, (asked) => rec.park(asked.callId, asked.tool, asked.args ?? {}, false))(call, context);
|
|
2639
2736
|
if (verdict !== "allow" && "park" in verdict)
|
|
2640
2737
|
return "park";
|
|
2641
2738
|
if (verdict !== "allow") {
|
|
@@ -3049,18 +3146,21 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3049
3146
|
}
|
|
3050
3147
|
}
|
|
3051
3148
|
/** The gate before a call's intent: the kernel's beforeIntent point, then allow, deny, or ask (answered, or park).
|
|
3052
|
-
* `wrapUp`: once the run has taken its share of the cap, the words every call the model makes is refused in (wrapUpText)
|
|
3149
|
+
* `wrapUp`: once the run has taken its share of the cap, the words every call the model makes is refused in (wrapUpText),
|
|
3150
|
+
* each refusal kept on the run (wrapUpRefusal).
|
|
3053
3151
|
* `beforeAsk`: what goes on the record of a call the gate asks about, before its ask is written or read (a CLI's call
|
|
3054
3152
|
* through its tool bridge: its start, marked parked, so its row shows while it waits and reads before its approval). */
|
|
3055
3153
|
function preIntentGate(spec, hooks, wrapUp, beforeAsk) {
|
|
3056
3154
|
return async (call, _hookContext) => {
|
|
3155
|
+
if (projectWork.closed)
|
|
3156
|
+
return { deny: "The project is finishing its checkpoint; no new call can start." };
|
|
3057
3157
|
// An MCP tool is asked about by its catalog name (`mcp:<server>/<tool>`), as its settings and its card name it.
|
|
3058
3158
|
const tool = mcp?.catalogOf(call.tool) ?? call.tool;
|
|
3059
3159
|
const kernelCall = { callId: call.callId, tool: tool, args: call.args };
|
|
3060
3160
|
await hooks.beforeIntent(kernelCall);
|
|
3061
3161
|
// The cap's wrap-up, the same way: once the run has taken its share of the cap, every call the model makes is refused
|
|
3062
3162
|
// in its fixed words, and the model answers from what it has. A call a running tool makes is that tool's, let through.
|
|
3063
|
-
const wrapUpDeny = call.nested !== true ? await wrapUp() : undefined;
|
|
3163
|
+
const wrapUpDeny = call.nested !== true ? await wrapUp(call.callId) : undefined;
|
|
3064
3164
|
if (wrapUpDeny !== undefined)
|
|
3065
3165
|
return { deny: wrapUpDeny };
|
|
3066
3166
|
// A CLI bridge's call run again after an attempt that may have been sent: its refusals say so (RAN_UNKNOWN).
|
|
@@ -3953,6 +4053,22 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3953
4053
|
// their own commits, the end's patch reading the cost they book), and its requests' bookings come first.
|
|
3954
4054
|
await releaseHost(on);
|
|
3955
4055
|
await bookingsSettled();
|
|
4056
|
+
let projectCheckpoint;
|
|
4057
|
+
if (specNow?.projectCheckpoint) {
|
|
4058
|
+
const project = specNow.projectCheckpoint;
|
|
4059
|
+
const signal = AbortSignal.any([deps.signal, AbortSignal.timeout(project.timeoutMs ?? 60_000)]);
|
|
4060
|
+
try {
|
|
4061
|
+
await projectWork.close(signal);
|
|
4062
|
+
// Abort asks the bounded backend operations to stop; it is not evidence that they stopped. Keep the actual
|
|
4063
|
+
// capture promise through its cleanup before teardown/end. A capability that ignores cancellation leaves
|
|
4064
|
+
// this claim unresolved, never a published candidate or a falsely completed release.
|
|
4065
|
+
projectCheckpoint = await project.capture(signal);
|
|
4066
|
+
signal.throwIfAborted();
|
|
4067
|
+
}
|
|
4068
|
+
catch {
|
|
4069
|
+
projectCheckpoint = project.uncertain();
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
3956
4072
|
// The pull request's checkout goes before the end is committed: a run that reads final never still holds its code.
|
|
3957
4073
|
await specNow?.endCheckout?.();
|
|
3958
4074
|
const patch = await endPatchOf(base);
|
|
@@ -3965,7 +4081,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3965
4081
|
if (lateStop)
|
|
3966
4082
|
take = [...take, lateStop.commandId];
|
|
3967
4083
|
// An end that keeps the job's takes it too, and stays the job's.
|
|
3968
|
-
const data = { ...base, ...(patch.outcome !== undefined ? { outcome: patch.outcome } : {}), ...(patch.costUsd !== undefined ? { costUsd: patch.costUsd, ...(patch.costUpperBound ? { costUpperBound: true } : {}) } : {}), ...(patch.metrics !== undefined ? { metrics: patch.metrics } : {}), ...(lateStop && keptAt === undefined ? stopEnd(lateStop.cancel) : {}) };
|
|
4084
|
+
const data = { ...base, ...(projectCheckpoint ? { projectCheckpoint } : {}), ...(patch.outcome !== undefined ? { outcome: patch.outcome } : {}), ...(patch.costUsd !== undefined ? { costUsd: patch.costUsd, ...(patch.costUpperBound ? { costUpperBound: true } : {}) } : {}), ...(patch.metrics !== undefined ? { metrics: patch.metrics } : {}), ...(lateStop && keptAt === undefined ? stopEnd(lateStop.cancel) : {}) };
|
|
3969
4085
|
const run = {
|
|
3970
4086
|
state: data.state,
|
|
3971
4087
|
...(keptAt !== undefined ? { endedAt: keptAt, keepsEnd: true } : {}),
|
|
@@ -49,10 +49,10 @@ import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
|
49
49
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
50
50
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
51
51
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
52
|
-
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
52
|
+
import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
|
|
53
53
|
import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
|
|
54
54
|
import { agreeOnOf } from "../learning-setting.js";
|
|
55
|
-
import { catalogSessionNames, mcpWhereHeld
|
|
55
|
+
import { catalogSessionNames, mcpWhereHeld } from "./mcp-run.js";
|
|
56
56
|
import { held as runnerSeam, heldOrThrow, heldSignInReads } from "./held.js";
|
|
57
57
|
import { hostLifecycle } from "./adapter-loop.js";
|
|
58
58
|
import { RUNNER_HARNESSES } from "./adapters/index.js";
|
|
@@ -83,6 +83,9 @@ import { prCheckoutForClaim } from "./pr-checkout.js";
|
|
|
83
83
|
import { holdStored, storeSecrets } from "./store-secrets.js";
|
|
84
84
|
import { bashPolicyOf } from "../bash-read-only.js";
|
|
85
85
|
import { monidForClaim, withMonid } from "./monid-run.js";
|
|
86
|
+
import { verifyPlacedProject, movedSkillFiles } from "../source-sync/claim.js";
|
|
87
|
+
import { projectCheckpointForRun } from "./project-checkpoint.js";
|
|
88
|
+
import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
|
|
86
89
|
/** The wires pi speaks on the runner: main's pi's (provider.ts), Anthropic's Messages and OpenAI's Responses. */
|
|
87
90
|
export const PI_WIRES = Object.freeze(["anthropic-messages", "openai-responses"]);
|
|
88
91
|
/** The browser's catalog name (tools.ts TOOLS.browser). */
|
|
@@ -279,6 +282,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
279
282
|
if (!revisionRow)
|
|
280
283
|
throw new Error(`run ${claim.runId}: its revision ${runRow.revisionId} is gone from the store`);
|
|
281
284
|
const body = (revisionRow.body ?? {});
|
|
285
|
+
const movedProject = await verifyPlacedProject(deps.store, runRow, revisionRow, launch, { data: deps.data, sealKey: deps.sealKey, env: deps.env, ...(run.signal ? { signal: run.signal } : {}), control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
|
|
282
286
|
const revision = { kind: revisionRow.kind, body };
|
|
283
287
|
const granted = body.tools ?? [];
|
|
284
288
|
// The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
|
|
@@ -329,14 +333,17 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
329
333
|
// on the one store the claim does), from the revision row's texts (the body keeps only each file's SHA-256): each
|
|
330
334
|
// folder not there yet, never over an earlier claim's. A desktop or a phone (the revision's computer
|
|
331
335
|
// setting, the one computerForClaim starts) brings its kind's skill, named in the prompt beside the revision's own.
|
|
332
|
-
const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
|
|
336
|
+
const kindSkills = movedProject ? [] : await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
|
|
337
|
+
const currentSkills = movedProject ? await movedSkillFiles(ws.workspace, body.skills ?? {}, settingOfDefinition(body)?.computer.kind) : [...Object.keys(body.skills ?? {}), ...kindSkills];
|
|
333
338
|
// A learning run's seed, read once from its learning folder where the run's place keeps it (runner/learning-seed.ts):
|
|
334
339
|
// its learned workflows, cut of the server's secrets, the ones its learned_workflow tool runs. Read before the run's
|
|
335
|
-
// tools are bound. A learning fault, or a seed that failed (seedFailed), gives none.
|
|
340
|
+
// tools are bound. A learning fault, or a seed that failed (seedFailed), gives none. None a purged run wrote, by the
|
|
341
|
+
// store's runs; a run's own process (no seal key) reads no other run, and its runner reads the seed again
|
|
342
|
+
// (learned-first.ts learnedFirstWhereHeld).
|
|
336
343
|
const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
|
|
337
344
|
const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
|
|
338
345
|
const seedLaid = start && !seedFailed(start)
|
|
339
|
-
? await layLearningSeed({ seed: start.seed, folder: learningFolder, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
|
|
346
|
+
? await layLearningSeed({ seed: start.seed, folder: learningFolder, store: deps.sealKey ? deps.store : null, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
|
|
340
347
|
: undefined;
|
|
341
348
|
// The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
|
|
342
349
|
// credentials opened under the server's seal key into this claim's memory, one gateway for the claim. First, before
|
|
@@ -344,7 +351,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
344
351
|
// words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
|
|
345
352
|
// A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
|
|
346
353
|
const hold = (values) => cut.hold(values);
|
|
347
|
-
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped:
|
|
354
|
+
const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(runRow.agentId)?.web, slots: deps.saveSlots } });
|
|
348
355
|
// The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
|
|
349
356
|
holds.hold({ passed: mcp });
|
|
350
357
|
// The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
|
|
@@ -374,7 +381,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
374
381
|
// as `tools.<name>`, each a nested call, gated and recorded as the model's own call is. A computer that replaced an
|
|
375
382
|
// earlier claim's holds its acts to what it showed.
|
|
376
383
|
const tools = await runTools(ws.workspace, computer.computer, { mode, context, ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
|
|
377
|
-
|
|
384
|
+
let remoteProjectCapture = false;
|
|
385
|
+
holds.hold({ tools: { end: () => remoteProjectCapture ? Promise.resolve() : tools.end() } });
|
|
378
386
|
// The run's model route: its model through routeOf (NEVER re-resolved — the launch's model, pinned at start), the catalog
|
|
379
387
|
// price with tiers for the cap, and the proxy's price (pi-ai calculateCost, tiered).
|
|
380
388
|
// pi speaks both of main's wires: an OpenAI-family model's route is OpenAI's Responses itself.
|
|
@@ -383,7 +391,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
383
391
|
// The run's secrets for this claim, read from the one store (never this process's environment or a pipe): the keys its
|
|
384
392
|
// tools unlock and its model needs, scoped to the run as the old per-run environment was, so one run's keys never reach
|
|
385
393
|
// another's on this runner (claim-secrets.ts). MCP credentials are the other per-claim secret and come through mcp-claim.
|
|
386
|
-
const toolEnv = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, revisionRow, launch);
|
|
394
|
+
const toolEnv = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env, redact: run.redact }, revisionRow, launch, claim.runId);
|
|
387
395
|
// The run's own model key, when its caller handed one (model_key, sealed in its launch): opened at every claim, a reclaim
|
|
388
396
|
// after a crash among them, and held by the run's one redactor. Its model routes read it alone; its tools never do.
|
|
389
397
|
// A run that starts on the server's key holds the claim's key holder too: a message's first key reaches its next request.
|
|
@@ -533,10 +541,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
533
541
|
// Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
|
|
534
542
|
// are skipped, in words, where the run brought its own key or the server holds none.
|
|
535
543
|
const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
|
|
536
|
-
const
|
|
544
|
+
const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
|
|
545
|
+
const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff, admitAuxiliary };
|
|
537
546
|
// Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
|
|
538
547
|
// them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
|
|
539
|
-
const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff }, seedLaid?.workflows ?? []);
|
|
548
|
+
const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff, admitAuxiliary }, seedLaid?.workflows ?? []);
|
|
540
549
|
const firstChoice = learned.choice;
|
|
541
550
|
// A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
|
|
542
551
|
// answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
|
|
@@ -563,7 +572,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
563
572
|
}
|
|
564
573
|
const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
|
|
565
574
|
holdClaimed(cut, learnedKeys);
|
|
566
|
-
|
|
575
|
+
underClaimed(toolEnv, learnedKeys);
|
|
567
576
|
}
|
|
568
577
|
// A replay run's or a shadow's grader (runner/compare-end.ts), on a route of its own beside the session's, on the
|
|
569
578
|
// session's booking under the run's one cap. None: the pair is compared whole, in words saying so.
|
|
@@ -610,7 +619,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
610
619
|
// The one path for every harness.
|
|
611
620
|
// A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
|
|
612
621
|
const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
|
|
613
|
-
const instructions = await promptOf(laid,
|
|
622
|
+
const instructions = await promptOf(laid, currentSkills, ws.workspace, { onDemand: movedProject || readsFiles(granted) });
|
|
614
623
|
const guidance = effortGuidance(launch.effort);
|
|
615
624
|
// The run's clock: a template eval case's (EvalFakes.now), else the real one.
|
|
616
625
|
const now = fakes?.now;
|
|
@@ -766,6 +775,10 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
766
775
|
// credential with it, and the run's timeline is told so.
|
|
767
776
|
...(computer.keeps ? { keptWords: computerKeptWords(computer.keeps) } : {}),
|
|
768
777
|
release: (how) => holds.release(how),
|
|
778
|
+
...(movedProject ? { projectCheckpoint: projectCheckpointForRun({ store: deps.store, agentId: runRow.agentId, claim, launch, tools, computer,
|
|
779
|
+
workspace: { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } },
|
|
780
|
+
secrets: async () => runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)),
|
|
781
|
+
}, () => { remoteProjectCapture = true; }) } : {}),
|
|
769
782
|
endCheckout: () => holds.endCheckout(),
|
|
770
783
|
};
|
|
771
784
|
}
|
package/dist/runner/audit.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Context } from "@earendil-works/chord/context";
|
|
2
|
+
import type { AuxiliaryAdmitter } from "../source-sync/auxiliary.js";
|
|
2
3
|
import { type AuditLoop } from "../learning-setting.js";
|
|
3
4
|
import { type RunLaunch } from "../run-launch.js";
|
|
4
5
|
import { type RunRow, type Store } from "../store/store.js";
|
|
@@ -19,6 +20,7 @@ export type AuditDeps = {
|
|
|
19
20
|
readonly shown: () => Promise<Pick<Shown, "text">>;
|
|
20
21
|
readonly log: (line: string) => void;
|
|
21
22
|
readonly sealKey?: Buffer;
|
|
23
|
+
readonly admitAuxiliary?: AuxiliaryAdmitter;
|
|
22
24
|
readonly now?: () => number;
|
|
23
25
|
/** Why model spend beside the claimed run is skipped (claim-secrets.ts claimSpendOff): a shadow is a run the runner
|
|
24
26
|
* starts with no caller's key. Absent: it runs. */
|
package/dist/runner/audit.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
// Every number is the agent definition's (learning-setting.ts auditLoopOf). Nothing here fails a claim: a failure is logged.
|
|
27
27
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
28
28
|
import { overCapMessage } from "@parcha/agentrun-kernel/kernel/cap";
|
|
29
|
+
import { sourceSyncOf } from "../source-sync/types.js";
|
|
29
30
|
import { agreeOnOf, auditLoopOf } from "../learning-setting.js";
|
|
30
31
|
import { launchBody, readLaunchBody } from "../run-launch.js";
|
|
31
32
|
import { runEntries } from "../store-reads/journal.js";
|
|
@@ -158,6 +159,10 @@ export async function startAudit(deps, serve) {
|
|
|
158
159
|
// Read after the claim pinned the revision's MCP tools (mcp-claim.ts pinFirst): the pin a revision saved without one
|
|
159
160
|
// takes at its first run is what its tools are classed by.
|
|
160
161
|
const revision = await store.agents.revision(deps.revisionId);
|
|
162
|
+
if ((launch.sourceProject || sourceSyncOf(revision?.body)) && !deps.admitAuxiliary) {
|
|
163
|
+
log("workflow-first: an auxiliary audit requires its own project placement for this moved agent; no audit was started. Start a normal run to use the saved project.");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
161
166
|
const writer = auditWriterOf(revision);
|
|
162
167
|
if (writer !== undefined) {
|
|
163
168
|
log(`workflow-first: ${serve.name} at ${serve.digest} serves this run, never audited: ${auditsOffWords(writer)}`);
|
|
@@ -209,7 +214,10 @@ export async function startAudit(deps, serve) {
|
|
|
209
214
|
await addLines(deps, [started]);
|
|
210
215
|
const sealed = await handedTo(deps, runId, id);
|
|
211
216
|
try {
|
|
212
|
-
|
|
217
|
+
if (sourceSyncOf(revision?.body))
|
|
218
|
+
await deps.admitAuxiliary({ runId: id, agentId, revisionId: deps.revisionId, launch: shadow, ...(sealed ? { sealed } : {}) });
|
|
219
|
+
else
|
|
220
|
+
await store.runs.create({ id, agentId, revisionId: deps.revisionId }, { body: launchBody(shadow), ...(sealed ? { sealed } : {}) });
|
|
213
221
|
}
|
|
214
222
|
catch (error) {
|
|
215
223
|
if (error instanceof StoreConstraint && (await store.runs.get(id)))
|
package/dist/runner/beside.js
CHANGED
|
@@ -118,7 +118,8 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
118
118
|
};
|
|
119
119
|
// A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts).
|
|
120
120
|
const { runEndComputers } = await import("../workspace/run-end-computers.js");
|
|
121
|
-
const
|
|
121
|
+
const { projectRunEnded } = await import("../source-sync/checkpoints.js");
|
|
122
|
+
const runEnded = projectRunEnded(store, runEndComputers({ store, computers: computers.computerDeps, log: (line) => console.error(`agentrun-serve runner: ${line}`) }));
|
|
122
123
|
const runner = startRunner({ store, name, createLoop, memory: runnerMemory(store, undefined, runs, isolation ? RUN_PROCESS_MIB : 0), onEvent: said, runEnded, ...(held !== undefined ? { loops: held } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
|
|
123
124
|
// The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
|
|
124
125
|
// runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
|
|
@@ -5,24 +5,43 @@ import type { SealedKeys } from "../store/store.js";
|
|
|
5
5
|
import type { Revision } from "../agent-rows.js";
|
|
6
6
|
import type { HeldRedact } from "./redact.js";
|
|
7
7
|
import { type HeldModelKey } from "../run-model-key.js";
|
|
8
|
-
import { type RunModelKey } from "../store/seal.js";
|
|
8
|
+
import { type RunModelKey, type RunToolKeys } from "../store/seal.js";
|
|
9
9
|
import { type Claim } from "../store/store.js";
|
|
10
10
|
/** What claimSecrets reads the keys from: the one store (its sealed keys) and the runner's seal key, and the runner's base
|
|
11
11
|
* environment (its own, with no server secret in it: those are the store's). */
|
|
12
12
|
export interface ClaimSecretsDeps {
|
|
13
13
|
/** `put`, `replaceIf`, `removeIf` and `clock` for the ChatGPT sign-in alone, which a run renews and seals again under a
|
|
14
|
-
* lease on the store's clock (chatgpt-plan.ts).
|
|
14
|
+
* lease on the store's clock (chatgpt-plan.ts). `runs.launch` for a claim given its run's id: its launch's sealed
|
|
15
|
+
* column, which holds the run's own tool keys. */
|
|
15
16
|
readonly store: {
|
|
16
17
|
readonly sealedKeys: Pick<SealedKeys, "get" | "put" | "replaceIf" | "removeIf" | "clock">;
|
|
18
|
+
readonly runs?: RunLaunchReader;
|
|
17
19
|
};
|
|
18
20
|
/** The runner's seal key: with none, no saved key is opened, and only the environment's values are read. */
|
|
19
21
|
readonly sealKey: Buffer | undefined;
|
|
20
22
|
readonly env?: NodeJS.ProcessEnv;
|
|
23
|
+
/** The runner's one redactor (redact.ts), for a claim given its run's id: the run's own tool keys it lays are carried
|
|
24
|
+
* there first, cut from the run's journal as it is written, since no one holds them after the turn. A claim with run
|
|
25
|
+
* keys to lay and no redactor lays none, and throws. */
|
|
26
|
+
readonly redact?: HeldRedact;
|
|
21
27
|
}
|
|
28
|
+
/** What reads a run's launch sealed column. */
|
|
29
|
+
type RunLaunchReader = {
|
|
30
|
+
launch(runId: string): Promise<{
|
|
31
|
+
readonly sealed: Uint8Array | null;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
22
34
|
/** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
|
|
23
35
|
* revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
|
|
24
|
-
* decision provider keys
|
|
36
|
+
* decision provider keys — and, for claim `runId`, the run's own tool keys its revision declares (run-keys.ts) over the
|
|
37
|
+
* server's by the same name. A fresh object per claim, so no run's keys reach another's. */
|
|
38
|
+
export declare function claimSecrets(deps: ClaimSecretsDeps & {
|
|
39
|
+
readonly redact: HeldRedact | undefined;
|
|
40
|
+
}, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">, runId: string): Promise<NodeJS.ProcessEnv>;
|
|
25
41
|
export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">): Promise<NodeJS.ProcessEnv>;
|
|
42
|
+
/** `keys` (learnedDecisionKeys') laid onto `env`, a claim's environment, where it holds no value of that name: what the
|
|
43
|
+
* claim laid stays, a run's own tool key over the server's above all. A name both read holds the same server key. */
|
|
44
|
+
export declare function underClaimed(env: NodeJS.ProcessEnv, keys: Readonly<Record<string, string>>): void;
|
|
26
45
|
/** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
|
|
27
46
|
* are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
|
|
28
47
|
* questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
|
|
@@ -74,6 +93,12 @@ export declare function openRunModelKey(deps: {
|
|
|
74
93
|
};
|
|
75
94
|
readonly sealKey: Buffer | undefined;
|
|
76
95
|
}, runId: string): Promise<RunModelKey | undefined>;
|
|
96
|
+
/** Run `runId`'s own tool keys as its launch's sealed column holds them (run-keys.ts), opened under `deps.sealKey`: none
|
|
97
|
+
* for a launch that holds none (or no launch row). Throws, in words, where the launch does not open. */
|
|
98
|
+
export declare function openRunKeys(deps: {
|
|
99
|
+
readonly runs: RunLaunchReader;
|
|
100
|
+
readonly sealKey: Buffer;
|
|
101
|
+
}, runId: string): Promise<RunToolKeys | undefined>;
|
|
77
102
|
/**
|
|
78
103
|
* The run's own model key for claim `runId`, opened from its launch's sealed column under the runner's seal key (the
|
|
79
104
|
* server sealed it there with mcp_auth, store/seal.ts). Undefined only where the server has no gateway and the run holds
|
|
@@ -115,3 +140,4 @@ export declare function claimModelEnv(env: NodeJS.ProcessEnv, opened: NodeJS.Pro
|
|
|
115
140
|
* run's model routes do not send. The decision providers' keys stay (DECISION_KEY_NAMES): a keyed workflow's judge,
|
|
116
141
|
* pick, sift, route and ask nodes run on them as any run's do. */
|
|
117
142
|
export declare function withoutModelKeys(toolEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
143
|
+
export {};
|