@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30
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 +748 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +2190 -2
- package/dist/adapters.d.ts +234 -0
- package/dist/adapters.js +585 -0
- package/dist/agents.d.ts +130 -0
- package/dist/agents.js +308 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +384 -0
- package/dist/background.d.ts +28 -0
- package/dist/background.js +376 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-egress.d.ts +98 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +285 -0
- package/dist/box-relay-vm.d.ts +80 -0
- package/dist/box-relay-vm.js +389 -0
- package/dist/box-relay.d.ts +45 -0
- package/dist/box-relay.js +227 -0
- package/dist/boxes.d.ts +72 -0
- package/dist/boxes.js +189 -0
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +332 -0
- package/dist/cap.js +992 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +35 -0
- package/dist/coding-tools.js +87 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
- package/dist/console/assets/index-34jfpIbQ.js +481 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +19 -0
- package/dist/decision-rows.js +123 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.js +69 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +65 -0
- package/dist/files.js +158 -0
- package/dist/grade.d.ts +93 -0
- package/dist/grade.js +328 -0
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +102 -0
- package/dist/graph-view.js +219 -0
- package/dist/harness-app.d.ts +40 -0
- package/dist/harness-app.js +708 -0
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +56 -0
- package/dist/harness.js +77 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +30 -0
- package/dist/host-tools.js +154 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +85 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +133 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1222 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +37 -0
- package/dist/key-check.js +112 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +191 -0
- package/dist/learn/check.d.ts +108 -0
- package/dist/learn/check.js +277 -0
- package/dist/learn/grade.d.ts +80 -0
- package/dist/learn/grade.js +445 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +147 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +213 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +131 -0
- package/dist/learn/skills.d.ts +97 -0
- package/dist/learn/skills.js +271 -0
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +306 -0
- package/dist/learning-run.js +819 -0
- package/dist/learning-words.d.ts +76 -0
- package/dist/learning-words.js +174 -0
- package/dist/learning.d.ts +418 -0
- package/dist/learning.js +946 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +118 -0
- package/dist/mcp-servers.js +450 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +485 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4806 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1727 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +50 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +70 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +69 -0
- package/dist/place.js +137 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +40 -0
- package/dist/propose.js +112 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +22 -0
- package/dist/request-start.js +350 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +186 -0
- package/dist/run-box.js +590 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +83 -0
- package/dist/runnable.js +170 -0
- package/dist/runs.d.ts +1062 -0
- package/dist/runs.js +3020 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +62 -0
- package/dist/secrets.js +158 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +722 -0
- package/dist/server.js +2118 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +96 -0
- package/dist/stats.d.ts +106 -0
- package/dist/stats.js +103 -0
- package/dist/tool-gate.d.ts +266 -0
- package/dist/tool-gate.js +554 -0
- package/dist/tool-keys.d.ts +187 -0
- package/dist/tool-keys.js +315 -0
- package/dist/tool-plane.d.ts +228 -0
- package/dist/tool-plane.js +400 -0
- package/dist/tools.d.ts +202 -0
- package/dist/tools.js +372 -0
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +24 -0
- package/dist/turn-end.js +15 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +57 -0
- package/dist/validate.js +184 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +189 -0
- package/dist/webhooks.js +503 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +100 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
package/dist/app.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// The app `pi-durable-disk run --app` loads for each run serve starts. It reads the run's revision from the agent store
|
|
2
|
+
// (`<data>/store.sqlite`, the run being `<data>/runs/<id>`) and runs it on the model model.ts chooses:
|
|
3
|
+
// - agentic: the root agent with the revision's instructions and skills, and the tools it names, bound from the
|
|
4
|
+
// closed table in tools.ts;
|
|
5
|
+
// - workflow: the revision's workflow, started with startWorkflowRevision of @parcha/pi-durable-agent/workflow on
|
|
6
|
+
// agentrun-pi's durable workflow task, each model node on the host's model of its tier with the tools it names of the
|
|
7
|
+
// table's node tools, and its typed questions on Jev or Parallel when the server hands this process the provider's key. When the
|
|
8
|
+
// workflow ends the app writes the run's final status, with the outcome, and releases the run. The server carries
|
|
9
|
+
// it back once this process has exited: this process holds the run's store until then.
|
|
10
|
+
// First: the secrets serve hands this process over a pipe, read and the pipe closed before anything else runs.
|
|
11
|
+
import { authContextOf, withSecrets } from "./secrets.js";
|
|
12
|
+
import { mkdir } from "node:fs/promises";
|
|
13
|
+
import { BACKGROUND_CONTEXT as BACKGROUND } from "@earendil-works/chord/context";
|
|
14
|
+
import { basename, join, resolve } from "node:path";
|
|
15
|
+
import { createRegistry, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
16
|
+
import { openStoreReader, RUN_STORE_FILE } from "@parcha/pi-durable-agent";
|
|
17
|
+
import { RUN_RESUMED } from "@parcha/pi-durable-agent/timeline";
|
|
18
|
+
import { settleIn } from "./paid-calls.js";
|
|
19
|
+
import { capBefore, capModels, capOf, spentIn } from "./cap.js";
|
|
20
|
+
import { codingSource } from "./coding-tools.js";
|
|
21
|
+
import { cancelledIn, markRequests } from "./request-start.js";
|
|
22
|
+
import { decisionProvidersOf } from "./decisions.js";
|
|
23
|
+
import { FOLLOW_UP_OPEN_ENV, readJson, RUN_META } from "./files.js";
|
|
24
|
+
import { adapterFor, claudeModel, claudePriceModel, claudeSkillCheck, codexModel, learnedRoute, learnedWorkflowsOff, openRouterOnly, thinkingFor } from "./adapters.js";
|
|
25
|
+
import { DEFAULT_HARNESS, FAUX_HARNESS_ENV } from "./harness.js";
|
|
26
|
+
import { adapterRun } from "./harness-app.js";
|
|
27
|
+
import { pinnedWorkflows, readPin, withLearned } from "./learning.js";
|
|
28
|
+
import { LEARNED_WORKFLOW_TOOL, learnedWorkflowTool } from "./learned-workflow.js";
|
|
29
|
+
import { defineExtension } from "@earendil-works/pi-durable";
|
|
30
|
+
import { completer } from "./llm.js";
|
|
31
|
+
import { searchOn } from "./hosted-search.js";
|
|
32
|
+
import { imageLoader } from "./pdf-pages.js";
|
|
33
|
+
import { EFFORT_ENV, llmTiers, nodeTiers, runModels, thinkingOf, workflowNodes } from "./model.js";
|
|
34
|
+
import { gated, liveView, nodeLog, readLiveView } from "./pause.js";
|
|
35
|
+
import { remotePlace, storedPlace } from "./place.js";
|
|
36
|
+
import { runBox, runBoxProvider } from "./run-box.js";
|
|
37
|
+
import { planeOf } from "./tool-plane.js";
|
|
38
|
+
import { ASK_TOOL, toolOf, workflowTools } from "./tools.js";
|
|
39
|
+
import { promptOf, readsFiles, systemOf } from "./skills.js";
|
|
40
|
+
import { EnvironmentLine, environmentLine } from "./environment.js";
|
|
41
|
+
import { effortGuidance } from "./effort-guidance.js";
|
|
42
|
+
import { isObject } from "./validate.js";
|
|
43
|
+
import { mirrorWrites } from "./workspace.js";
|
|
44
|
+
import { deniedText, runGate } from "./tool-gate.js";
|
|
45
|
+
/** The workflow adapters this host gives every run: model nodes, and calls `via: "tool"` to the table's tools. Typed
|
|
46
|
+
* questions (`runJudge`) run too where the host sets a decision provider's key (decisions.ts). */
|
|
47
|
+
export const WORKFLOW_ADAPTERS = ["runNode", "runEffect"];
|
|
48
|
+
/** A call node's tool failure, as the value its effect completed with (runEffect below). */
|
|
49
|
+
const TOOL_FAILED = "agentrun_serve_tool_failed";
|
|
50
|
+
/** A run's own commit of `kind` to its root, outside any one call's turn: a workflow call node's ledger, and every
|
|
51
|
+
* request's settle (paid-calls.ts settleIn). */
|
|
52
|
+
const rootRecordOf = (harness) => (kind, data) => harness.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind, data })), BACKGROUND);
|
|
53
|
+
export { promptOf };
|
|
54
|
+
/** A run's process that opens to go on with a run its last process left unfinished writes that on the root
|
|
55
|
+
* (RUN_RESUMED), so the run's timeline shows it from the store, which the settle's read keeps: after a crash (that
|
|
56
|
+
* process died holding the run, and left it `running`) or after the server stopped (it drained, `sleeping`). A first
|
|
57
|
+
* open, a follow-up's and a wake from a park get none. A run whose root conversation was never made writes nothing
|
|
58
|
+
* and opens as before: the root comes with a workflow run's task (its start) and with an agentic run's first message,
|
|
59
|
+
* so a process that died or drained before then left none. */
|
|
60
|
+
async function markResumed({ harness, context, generation, previous }) {
|
|
61
|
+
const drained = previous?.status === "sleeping" && isObject(previous.detail) && previous.detail.reason === "drained";
|
|
62
|
+
const after = previous?.status === "running" ? "crash" : drained ? "server_stop" : undefined;
|
|
63
|
+
// A follow-up's open, which the server names (FOLLOW_UP_OPEN_ENV): the run's turn had ended, and the record its last
|
|
64
|
+
// process left is its server letting it go once it answered (a drain, as a server stop writes one), not cut work.
|
|
65
|
+
if (process.env[FOLLOW_UP_OPEN_ENV] === "1")
|
|
66
|
+
return;
|
|
67
|
+
if (!after || !(await harness.conversation(ROOT_CONVERSATION_ID, context)))
|
|
68
|
+
return;
|
|
69
|
+
await harness.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: RUN_RESUMED, data: { after, generation, at: Date.now() } })), context);
|
|
70
|
+
}
|
|
71
|
+
/** claude-agent's model and pi-ai's catalog that prices it: its own settings, never the gateway's (adapters.ts). */
|
|
72
|
+
async function claudeModels(env, ref) {
|
|
73
|
+
const choice = claudeModel(env, ref);
|
|
74
|
+
if ("why" in choice)
|
|
75
|
+
throw new Error(choice.why);
|
|
76
|
+
const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
|
|
77
|
+
return { models: builtinModels({ authContext: authContextOf(env) }), model: choice.model, byTier: new Map([["default", choice.model]]), unpriced: new Set() };
|
|
78
|
+
}
|
|
79
|
+
/** codex's model (or opencode's, `harness`, on codex's route) and pi-ai's catalog that prices it, where it reaches OpenAI only through OpenRouter (codexModel: no
|
|
80
|
+
* OpenAI key needed); anywhere else, the run's usual models (runModels). */
|
|
81
|
+
async function codexModels(env, ref, harness = "codex") {
|
|
82
|
+
if (env[FAUX_HARNESS_ENV] || !openRouterOnly(harness, env))
|
|
83
|
+
return runModels(env, ref, ["default"], harness);
|
|
84
|
+
const choice = await codexModel(env, ref, harness);
|
|
85
|
+
if ("why" in choice)
|
|
86
|
+
throw new Error(choice.why);
|
|
87
|
+
const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
|
|
88
|
+
return { models: builtinModels({ authContext: authContextOf(env) }), model: choice.model, byTier: new Map([["default", choice.model]]), unpriced: new Set() };
|
|
89
|
+
}
|
|
90
|
+
/** The run's row and its pinned revision, read from the store the run's directory sits in. */
|
|
91
|
+
function revisionOf(where) {
|
|
92
|
+
const reader = openStoreReader(resolve(where.root, "..", ".."));
|
|
93
|
+
try {
|
|
94
|
+
const id = basename(resolve(where.root));
|
|
95
|
+
const run = reader.readRun(id);
|
|
96
|
+
if (!run)
|
|
97
|
+
throw new Error(`the agent store has no run ${id}`);
|
|
98
|
+
return { run, revision: reader.readRevision(run.revision) };
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
reader.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export default async function app(where) {
|
|
105
|
+
const { run, revision } = revisionOf(where);
|
|
106
|
+
// This process's reading of its environment, with its secrets: never a child's (secrets.ts).
|
|
107
|
+
const env = withSecrets(process.env);
|
|
108
|
+
const workflowNodeList = revision.kind === "workflow" ? workflowNodes(revision.body.workflow, (await import("@parcha/agentrun-dsl")).inspectWorkflow(revision.body.workflow)) : [];
|
|
109
|
+
// codex's model as a save resolves it (codexModel): an OpenAI model it reaches through OpenRouter alone needs no OpenAI key.
|
|
110
|
+
const chosen = revision.kind === "agentic" && revision.body.harness === "claude-agent" && !env[FAUX_HARNESS_ENV] ? await claudeModels(env, revision.body.model) : revision.kind === "agentic" && (revision.body.harness === "codex" || revision.body.harness === "opencode") ? await codexModels(env, revision.body.model, revision.body.harness) : revision.kind === "agentic" ? await runModels(env, revision.body.model, ["default"], revision.body.harness) : await runModels(env, undefined, llmTiers(workflowNodeList, nodeTiers(workflowNodeList)));
|
|
111
|
+
const { model, byTier } = chosen;
|
|
112
|
+
// Read before the run opens its store: what it spent in earlier processes counts against its cap.
|
|
113
|
+
const cap = capOf(process.env);
|
|
114
|
+
// Each request is marked as it leaves (request-start.ts), inside the cap: a request the cap refuses never leaves, and
|
|
115
|
+
// gets a start mark of its own, which its error entry answers.
|
|
116
|
+
const marked = await markRequests(chosen.models, cancelledIn(where.root));
|
|
117
|
+
// On another harness these models carry only the run's own requests (a learned workflow's, a hosted search's), under
|
|
118
|
+
// the run's one total, which the harness keeps (cap.ts capModels' `joined`): what they cost in earlier processes is
|
|
119
|
+
// read here, as the harness's booking does not hold it.
|
|
120
|
+
const joined = revision.kind === "agentic" && Boolean(revision.body.harness) && revision.body.harness !== DEFAULT_HARNESS;
|
|
121
|
+
const models = cap === undefined ? marked.models : await capModels(marked.models, cap, spentIn(join(where.store, RUN_STORE_FILE), { sides: joined }), { unpriced: chosen.unpriced, refused: marked.refused, joined });
|
|
122
|
+
// web_search's own request to the model provider, when it resolves native, goes through the run's models (hosted-search.ts):
|
|
123
|
+
// on another harness too, for a learned workflow's call node.
|
|
124
|
+
searchOn(models);
|
|
125
|
+
const thinkingLevel = thinkingOf(process.env, revision.kind === "agentic" ? revision.body.thinking : undefined);
|
|
126
|
+
// The run's place, as its start resolved and kept it (serve.json): in a box, its coding tools run there (run-box.ts).
|
|
127
|
+
const meta = await readJson(join(where.root, RUN_META));
|
|
128
|
+
const place = storedPlace(meta?.place);
|
|
129
|
+
const root = resolve(where.root, "..", "..");
|
|
130
|
+
// A remote box (Daytona) is the server's to make and seed, reached through its relay; Docker's is made here.
|
|
131
|
+
const box = place.mode === "sandbox" ? runBox(remotePlace(place) ? { relay: root } : { provider: () => runBoxProvider(place, env, root) }, { id: run.id, root, dir: where.root, place }) : undefined;
|
|
132
|
+
// What the run's host tools file in work/ is copied into a remote box too, which does not share this machine's work/.
|
|
133
|
+
if (box?.mirror)
|
|
134
|
+
mirrorWrites(where.work, box.mirror);
|
|
135
|
+
const coding = codingSource(place, box);
|
|
136
|
+
// Every tool call the run's model makes passes the run's tool gate (tool-gate.ts): pi's tools wrapped by name where the
|
|
137
|
+
// registry composes each agent's, another harness's host tools in their call. An approved call runs on this coding
|
|
138
|
+
// source, as the run's own would.
|
|
139
|
+
const toolGate = runGate(where, run.id, revision);
|
|
140
|
+
const registry = createRegistry();
|
|
141
|
+
// An agentic run's system prompt starts with the date and the workspace (environment.ts). On pi it is a section,
|
|
142
|
+
// installed first so it comes before every other extension's and the instructions.
|
|
143
|
+
if (revision.kind === "agentic")
|
|
144
|
+
registry.install(EnvironmentLine);
|
|
145
|
+
registry.install(coding.extension);
|
|
146
|
+
// What the run's agent learned goes into its instructions, and the skills it wrote join the revision's, the one path for
|
|
147
|
+
// every harness (learning.ts).
|
|
148
|
+
const learned = revision.kind === "agentic" ? await withLearned(where.root, where.work, revision.body.instructions, Object.keys(revision.body.skills)) : { instructions: "", skills: [] };
|
|
149
|
+
// The workflows the agent learned that its run may run, as one tool (learned-workflow.ts), when its pin names any: on
|
|
150
|
+
// the run's models, as side requests under its cap, each model node and `llm` call on the run's model of its tier,
|
|
151
|
+
// else the run's own (the only one the run was made with, and handed the key of); the `llm` tool's completion for a
|
|
152
|
+
// call node that names it; its call nodes on the agent's tools its run's plane resolves (the plane its harness and
|
|
153
|
+
// its tools read).
|
|
154
|
+
const flows = revision.kind === "agentic" ? await pinnedWorkflows(where.root, await readPin(where.root)) : [];
|
|
155
|
+
// On claude-agent and codex, on the route the harness's own requests take (learnedRoute): on OpenRouter alone,
|
|
156
|
+
// OpenRouter's name for the run's model, whose key the run holds, never the vendor's provider.
|
|
157
|
+
const learnedHarness = revision.kind === "agentic" ? revision.body.harness : undefined;
|
|
158
|
+
const learnedModel = (tier) => {
|
|
159
|
+
const ref = byTier.get(tier ?? "default") ?? byTier.get("default");
|
|
160
|
+
return ref && learnedHarness && learnedHarness !== DEFAULT_HARNESS ? learnedRoute(learnedHarness, env, ref) : ref;
|
|
161
|
+
};
|
|
162
|
+
// A second guard beside the pin's (learning-run.ts): a run whose harness's requests go where a learned workflow's could
|
|
163
|
+
// not follow gets no tool, whatever its pin says.
|
|
164
|
+
const learnedTool = flows.length && revision.kind === "agentic" && !(await learnedWorkflowsOff(revision.body.harness, env, revision.body.model))
|
|
165
|
+
? learnedWorkflowTool({ workflows: flows, granted: revision.body.tools, plane: planeOf(process.env), policy: toolGate.policy, env, work: where.work, models: models, modelOf: learnedModel, complete: completer(models, learnedModel, thinkingLevel) })
|
|
166
|
+
: undefined;
|
|
167
|
+
// The run's effort, as its thinking level reads it: its note on how to work follows the instructions on every harness
|
|
168
|
+
// (effort-guidance.ts). None without an effort.
|
|
169
|
+
const guidance = effortGuidance(process.env[EFFORT_ENV]);
|
|
170
|
+
if (revision.kind === "agentic" && revision.body.harness && revision.body.harness !== DEFAULT_HARNESS) {
|
|
171
|
+
const harness = revision.body.harness;
|
|
172
|
+
// claude-agent loads the skills its adapter takes itself (its Skill tool), and its prompt keeps only the ones it would
|
|
173
|
+
// refuse; codex's prompt, and a faux harness's, name each skill and its file when the run reads its files (it reads
|
|
174
|
+
// the SKILL.md when it fits), else keep every skill whole (skills.ts).
|
|
175
|
+
const check = harness === "claude-agent" && !env[FAUX_HARNESS_ENV] ? await claudeSkillCheck() : undefined;
|
|
176
|
+
const { system: instructions, native } = await systemOf(learned.instructions, learned.skills, where.work, check, { onDemand: readsFiles(revision.body.tools) });
|
|
177
|
+
// The session's system prompt starts with the line, made as this process opens it: a run resumed on a later day is
|
|
178
|
+
// opened with that day.
|
|
179
|
+
const spec = { key: `run:${run.id}`, label: run.agent, system: [environmentLine(), instructions, guidance].filter((text) => Boolean(text)), context: "fresh", thinking: thinkingFor(harness, thinkingLevel) };
|
|
180
|
+
// ask_person stays pi's (runnable.ts refuses a run that names it here); the file tools are pi's own.
|
|
181
|
+
const named = revision.body.tools.filter((name) => name !== ASK_TOOL);
|
|
182
|
+
// The harness's own files (its homes, its state) go in a private directory beside the workspace, never in it. It works
|
|
183
|
+
// in the workspace itself (where.work), the directory the run's file tools confine to: a path the model builds from
|
|
184
|
+
// its working directory is then one they take.
|
|
185
|
+
const dir = join(where.root, "harness");
|
|
186
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
187
|
+
// Built at the open: the harness's own process runs under the run's confinement, the prefix pi's commands get there.
|
|
188
|
+
const make = (confine) => adapterFor(harness, env, { model: model, models: chosen.models, ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}) });
|
|
189
|
+
// The run's cap, checked before each of the harness's requests: the same ceiling rule as pi's (cap.ts).
|
|
190
|
+
// claude-agent's run is capped at the price of whoever bills it (claudeProvider's priceModel), as its adapter prices it.
|
|
191
|
+
const priced = harness === "claude-agent" && !env[FAUX_HARNESS_ENV] ? claudePriceModel(env, model) : model;
|
|
192
|
+
const guard = await capBefore(cap, chosen.models.getModel(priced.provider, priced.modelId), { listed: !chosen.unpriced.has(priced.modelId) });
|
|
193
|
+
// The cancel mark serve writes is read here too, as pi's model wrapper reads it (request-start.ts).
|
|
194
|
+
// The run's stop record (serve.json, as serve saved it before a stop's abort): a turn it names is not resumed.
|
|
195
|
+
const stopRecord = { ...(typeof meta?.stopped_at === "string" ? { stopped_at: meta.stopped_at } : {}), ...(typeof meta?.stopped_after === "number" ? { stopped_after: meta.stopped_after } : {}) };
|
|
196
|
+
const { door, onOpen } = adapterRun(make, harness, spec, BACKGROUND, cap, learnedTool ? [...named, LEARNED_WORKFLOW_TOOL] : named, dir, guard, cancelledIn(where.root), where.work, coding.tools, stopRecord, toolGate, learnedTool ? [learnedTool] : []);
|
|
197
|
+
// A paid host tool's settle goes to the run's root, as on pi (paid-calls.ts settleIn).
|
|
198
|
+
// A learned workflow's model requests go through the run's models, marked on its store once it opens (markRequests).
|
|
199
|
+
return { models: {}, registry: createRegistry(), door, onOpen: async (durable) => (settleIn(rootRecordOf(durable.harness)), learnedTool && marked.open(durable), onOpen(durable)), beforeResume: markResumed };
|
|
200
|
+
}
|
|
201
|
+
// Each tool the revision names is bound once, from the table: its extensions installed here, its documents written in
|
|
202
|
+
// each conversation's creating commit, what it settles done before anything resumes, and what it lets go done before
|
|
203
|
+
// the run is released.
|
|
204
|
+
const writes = [];
|
|
205
|
+
const settles = [];
|
|
206
|
+
const stops = [];
|
|
207
|
+
const host = {
|
|
208
|
+
where, env, coding, install: (extension) => registry.install(extension),
|
|
209
|
+
onConversation: (write) => void writes.push(write), beforeResume: (settle) => void settles.push(settle), beforeRelease: (stop) => void stops.push(stop),
|
|
210
|
+
};
|
|
211
|
+
const letGo = async (harness) => { for (const stop of stops)
|
|
212
|
+
await stop(harness); };
|
|
213
|
+
const bound = new Map();
|
|
214
|
+
const bind = (name, nodes = false) => {
|
|
215
|
+
const entry = toolOf(name);
|
|
216
|
+
if (!entry || (nodes && !entry.nodes))
|
|
217
|
+
throw new Error(`the revision names the tool ${name}, which agentrun-serve does not bind${nodes ? " for a workflow's model node" : ""}`);
|
|
218
|
+
let tools = bound.get(name);
|
|
219
|
+
if (!tools)
|
|
220
|
+
bound.set(name, (tools = entry.bind(host)));
|
|
221
|
+
return tools;
|
|
222
|
+
};
|
|
223
|
+
const hooks = {
|
|
224
|
+
conversationCreated: async (tx, conversation) => { for (const write of writes)
|
|
225
|
+
await write(tx, conversation.id); },
|
|
226
|
+
beforeResume: async (run) => { await markResumed(run); for (const settle of settles)
|
|
227
|
+
await settle(run.harness); },
|
|
228
|
+
};
|
|
229
|
+
// A SIGTERM lets the run go: what a tool holds is let go there, then the wake is recorded as pi-durable-disk records it
|
|
230
|
+
// by default (sleeping, due at `at`).
|
|
231
|
+
const wake = async (durable, at) => {
|
|
232
|
+
await letGo(durable.harness);
|
|
233
|
+
await durable.setStatus("sleeping", { reason: "drained" }, { wakeAt: at === null ? null : new Date(at).toISOString() });
|
|
234
|
+
};
|
|
235
|
+
if (revision.kind === "agentic") {
|
|
236
|
+
const tools = (await Promise.all(revision.body.tools.map((name) => bind(name)))).flatMap((binding) => binding.tools);
|
|
237
|
+
if (learnedTool) {
|
|
238
|
+
registry.install(defineExtension({ name: "learned-workflow", tools: [learnedTool] }));
|
|
239
|
+
tools.push(learnedTool);
|
|
240
|
+
}
|
|
241
|
+
registry.install(toolGate.extension(tools));
|
|
242
|
+
// Each skill named with its file when the run reads its files (it reads the SKILL.md when it fits), else whole.
|
|
243
|
+
const instructions = [await promptOf(learned.instructions, learned.skills, where.work, { onDemand: readsFiles(revision.body.tools) }), guidance].filter(Boolean).join("\n\n");
|
|
244
|
+
// The calls that wait for a person's approval are read as the run opens, and their answers acted on from then.
|
|
245
|
+
const onOpen = async (durable) => {
|
|
246
|
+
settleIn(rootRecordOf(durable.harness));
|
|
247
|
+
marked.open(durable);
|
|
248
|
+
await toolGate.load(durable, BACKGROUND, coding.tools, learnedTool ? [learnedTool] : []);
|
|
249
|
+
toolGate.start();
|
|
250
|
+
};
|
|
251
|
+
return { models, registry, ...hooks, ...(stops.length ? { wake } : {}), root: { agent: { model, thinkingLevel, instructions, tools } }, onOpen };
|
|
252
|
+
}
|
|
253
|
+
const input = isObject(meta?.input) ? meta.input : {};
|
|
254
|
+
const [{ BACKGROUND_CONTEXT }, { createWorkflowExtension, decisionRecovery, durableDecisions, nodeRunner, taskScope }, { EffectFailure, inspectWorkflow, judgeFromProviders }, { withRecovery, workspaceFiles }, { startWorkflowRevision }, decisionProviders] = await Promise.all([
|
|
255
|
+
import("@earendil-works/chord/context"),
|
|
256
|
+
import("@parcha/agentrun-pi/durable"),
|
|
257
|
+
import("@parcha/agentrun-dsl"),
|
|
258
|
+
import("@parcha/agentrun-dsl/recovery"),
|
|
259
|
+
import("@parcha/pi-durable-agent/workflow"),
|
|
260
|
+
// The decision providers, holding the decision keys the server handed this process: in no environment a tool reads.
|
|
261
|
+
decisionProvidersOf(process.env),
|
|
262
|
+
]);
|
|
263
|
+
const nodeTools = new Map();
|
|
264
|
+
for (const name of workflowTools(workflowNodeList).nodes)
|
|
265
|
+
nodeTools.set(name, await bind(name, true));
|
|
266
|
+
// A model node's tools pass the gate too; one set to ask is refused there, as no node can wait for a person. A call
|
|
267
|
+
// node is the author's own step, which cannot wait for an approval: runnable.ts refuses a run whose call node calls a tool
|
|
268
|
+
// set to deny or ask, and a tool set to either since is refused as its call node runs (runEffect).
|
|
269
|
+
const gatedTools = toolGate.extension([...nodeTools.values()].flatMap((binding) => binding.tools));
|
|
270
|
+
registry.install(gatedTools);
|
|
271
|
+
// A decision node's images are files of the run's work directory (pdf_pages draws them there).
|
|
272
|
+
const loadImage = imageLoader(where.work);
|
|
273
|
+
const log = nodeLog(where.root);
|
|
274
|
+
// The receipts earlier processes recorded, read before this one opens the store, which then holds it exclusively.
|
|
275
|
+
const earlier = await (async () => {
|
|
276
|
+
try {
|
|
277
|
+
return durableDecisions(join(where.store, RUN_STORE_FILE));
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return (await readLiveView(where.root))?.receipts ?? [];
|
|
281
|
+
}
|
|
282
|
+
})();
|
|
283
|
+
const live = liveView(where.root, [...earlier]);
|
|
284
|
+
// The `llm` tool's one completion: on the run's models (capped and marked as a model node's), its tier's model.
|
|
285
|
+
const complete = completer(models, (tier) => byTier.get(tier ?? "default"), thinkingLevel);
|
|
286
|
+
/** The run, once it opens: a call node's paid requests are booked in its store (paid-calls.ts). */
|
|
287
|
+
let opened;
|
|
288
|
+
/** A call node `via: "tool"`: the table's tool by name, its interpolated args in, what its `out` schema checks out. Its
|
|
289
|
+
* input and output go to the node log, and its paid requests are booked under the node's own call (its execution
|
|
290
|
+
* path, and its item in a map). */
|
|
291
|
+
const runEffect = async ({ node, input, signal, executionPath, item }) => {
|
|
292
|
+
const effect = node.via === "tool" && node.tool ? toolOf(node.tool)?.effect : undefined;
|
|
293
|
+
if (!effect)
|
|
294
|
+
throw new Error(`call node "${node.label}": agentrun-serve runs no tool ${node.tool ?? `via ${node.via}`}`);
|
|
295
|
+
const at = { path: executionPath ?? null, item: item?.index ?? null, tool: node.tool, label: node.label };
|
|
296
|
+
log({ t: "effect.start", ...at, input, at: new Date().toISOString() });
|
|
297
|
+
try {
|
|
298
|
+
// Its tool's permission now, the gate's one rule read as each call node runs (tool-gate.ts policy): a tool set to
|
|
299
|
+
// deny since the run started is refused in the gate's words, and one set to ask too, since a call node cannot wait
|
|
300
|
+
// for an approval. Neither runs.
|
|
301
|
+
const permission = toolGate.policy(node.tool);
|
|
302
|
+
if (permission === "deny")
|
|
303
|
+
throw new Error(deniedText(node.tool));
|
|
304
|
+
if (permission === "ask")
|
|
305
|
+
throw new Error(`This ${node.tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`);
|
|
306
|
+
const durable = opened;
|
|
307
|
+
const ledger = durable ? { call: `${node.label}@${executionPath ?? ""}${item ? `#${item.index}` : ""}`, record: rootRecordOf(durable.harness) } : undefined;
|
|
308
|
+
const output = await effect(input, { signal, env, work: where.work, complete, ...(ledger ? { ledger } : {}) });
|
|
309
|
+
log({ t: "effect.end", ...at, status: "done", output, at: new Date().toISOString() });
|
|
310
|
+
return output;
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
const message = String(error?.message ?? error);
|
|
314
|
+
// Whole up to 64 KB, so the server redacts it before it cuts it for the graph (graph-view.ts); a longer one is marked cut.
|
|
315
|
+
log({ t: "effect.end", ...at, status: "failed", error: message.slice(0, 65_536), ...(message.length > 65_536 ? { error_truncated: true } : {}), at: new Date().toISOString() });
|
|
316
|
+
// An abort (a cancel, the node's deadline) stays a throw: the driver keeps its effect unknown. A tool that failed on
|
|
317
|
+
// its own (an unreadable PDF, a model's refusal) answered: its failure is the effect's outcome, completed, and is
|
|
318
|
+
// thrown past the driver as the call node's typed failure (`failing`), which a collecting map ends that item on.
|
|
319
|
+
if (signal.aborted || error?.name === "AbortError")
|
|
320
|
+
throw error;
|
|
321
|
+
return { [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
/** `runEffect` past the driver: a tool's failure the driver recorded as its effect's outcome is thrown here, on the
|
|
325
|
+
* first run and on a resume that answers it from the receipt alike. */
|
|
326
|
+
const failing = (run) => async (params) => {
|
|
327
|
+
const value = await run(params);
|
|
328
|
+
if (isObject(value) && typeof value[TOOL_FAILED] === "string")
|
|
329
|
+
throw new EffectFailure(value[TOOL_FAILED], null, { code: null });
|
|
330
|
+
return value;
|
|
331
|
+
};
|
|
332
|
+
/** A model node's agent: its tier's model, the tools it names, and the extensions they come from. */
|
|
333
|
+
const nodeAgent = (node) => {
|
|
334
|
+
const bindings = (node.tools ?? []).flatMap((name) => nodeTools.get(name) ?? []);
|
|
335
|
+
return { model: byTier.get(node.tier ?? "default"), thinkingLevel, extensions: [...new Set([coding.extension, ...bindings.flatMap((b) => b.extensions), gatedTools])], tools: bindings.flatMap((b) => b.tools) };
|
|
336
|
+
};
|
|
337
|
+
const nodes = nodeRunner({ agent: (node) => nodeAgent(node) });
|
|
338
|
+
/** The node log's starts and ends, from the workflow's events: what a graph shows of a node's timing. */
|
|
339
|
+
const onEvent = (event) => {
|
|
340
|
+
if ((event.type !== "node.start" && event.type !== "node.end") || typeof event.executionPath !== "string")
|
|
341
|
+
return;
|
|
342
|
+
const detail = (event.detail ?? {});
|
|
343
|
+
log({ t: event.type, path: event.executionPath, kind: String(detail.kind ?? ""), at: new Date().toISOString(), ...(detail.status ? { status: detail.status } : {}), ...(typeof detail.duration_ms === "number" ? { duration_ms: detail.duration_ms } : {}), ...(detail.error !== undefined ? { error: String(detail.error?.message ?? detail.error).slice(0, 500) } : {}) });
|
|
344
|
+
};
|
|
345
|
+
const workflows = createWorkflowExtension({
|
|
346
|
+
options: () => ({ files: workspaceFiles(where.work) }),
|
|
347
|
+
run: ({ key, runtime, context, driver }) => {
|
|
348
|
+
// Each typed question's receipt is a row of the run's store before its answer acts, and a resumed run takes an
|
|
349
|
+
// answered one instead of asking again.
|
|
350
|
+
const decisions = decisionRecovery({ key, runtime, context });
|
|
351
|
+
live.driver(driver);
|
|
352
|
+
const deps = withRecovery(driver, {
|
|
353
|
+
runNode: nodes.on(taskScope(runtime), context).runNode, runEffect: runEffect, ...(decisionProviders ? { runJudge: judgeFromProviders({ ...decisionProviders, loadImage }), decisionProviders } : {}),
|
|
354
|
+
recordDecision: async (receipt, exchange) => {
|
|
355
|
+
await decisions.recordDecision(receipt, exchange);
|
|
356
|
+
live.receipt(receipt);
|
|
357
|
+
},
|
|
358
|
+
}, { durableNodes: true });
|
|
359
|
+
const { recovery } = deps;
|
|
360
|
+
if (!recovery)
|
|
361
|
+
throw new Error("the workflow's recovery gave the run no recovery hooks");
|
|
362
|
+
// The pause gate: each node's resume, which the interpreter awaits before it starts the node (before a call's deadline
|
|
363
|
+
// is armed), and each model call and decision, outside the recovery: one waiting at it was never admitted, so a kill
|
|
364
|
+
// while paused leaves nothing half asked.
|
|
365
|
+
const gate = (fn) => (fn ? gated(where.root, fn) : fn);
|
|
366
|
+
const resume = gated(where.root, (args) => recovery.resume(...args));
|
|
367
|
+
return { deps: { ...deps, runEffect: deps.runEffect && failing(deps.runEffect), runNode: gate(deps.runNode), runJudge: gate(deps.runJudge), onEvent, recovery: { ...recovery, resume: (...args) => resume(args), decision: decisions.decision } } };
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
registry.install(nodes.extension);
|
|
371
|
+
registry.install(workflows.extension);
|
|
372
|
+
const onOpen = async (durable) => {
|
|
373
|
+
opened = durable;
|
|
374
|
+
settleIn(rootRecordOf(durable.harness));
|
|
375
|
+
marked.open(durable);
|
|
376
|
+
const started = { runId: run.id, storePath: join(where.store, RUN_STORE_FILE), agentId: run.agent, revision: revision };
|
|
377
|
+
const outcome = await startWorkflowRevision({ harness: durable.harness, workflows, context: BACKGROUND_CONTEXT, run: started, input, tools: inspectWorkflow(revision.body.workflow).requires.tools });
|
|
378
|
+
live.stop();
|
|
379
|
+
await letGo(durable.harness);
|
|
380
|
+
await durable.setStatus(outcome.status === "complete" ? "done" : "failed", { workflow: outcome.status, ...(outcome.status === "refused" ? { code: outcome.code, message: outcome.message.slice(0, 500) } : {}) });
|
|
381
|
+
await durable.release();
|
|
382
|
+
};
|
|
383
|
+
return { models, registry, ...hooks, ...(stops.length ? { wake } : {}), onOpen };
|
|
384
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { BoxProvider } from "@parcha/pi-transport";
|
|
4
|
+
/** The most background processes that run at once in one run's box. */
|
|
5
|
+
export declare const BACKGROUND_MAX = 8;
|
|
6
|
+
/** The most bytes of output one background process's log keeps: later output is dropped, and the process runs on. */
|
|
7
|
+
export declare const BACKGROUND_LOG_BYTES: number;
|
|
8
|
+
/** The most bytes of output one `bash_output` call answers, and its default. */
|
|
9
|
+
export declare const BACKGROUND_PAGE_BYTES: number;
|
|
10
|
+
/** The most bytes one `bash_input` call writes. */
|
|
11
|
+
export declare const BACKGROUND_INPUT_BYTES: number;
|
|
12
|
+
/** The most processes `bash_list` names: every running one, then the newest that ended. */
|
|
13
|
+
export declare const BACKGROUND_LIST_MAX = 40;
|
|
14
|
+
/** Where a background process's log and state live, under the run's work/. */
|
|
15
|
+
export declare const BACKGROUND_DIR = "background";
|
|
16
|
+
/** The signals `bash_signal` sends. */
|
|
17
|
+
export declare const BACKGROUND_SIGNALS: readonly ["TERM", "INT", "KILL"];
|
|
18
|
+
/** The tools, by name. */
|
|
19
|
+
export declare const BACKGROUND_TOOLS: readonly ["bash_background", "bash_output", "bash_input", "bash_signal", "bash_list"];
|
|
20
|
+
/** The tools that run a command in the box, never on this server: bash, and the background tools. The tool gate holds
|
|
21
|
+
* each to bash's setting (tool-gate.ts SHELL_FAMILY). */
|
|
22
|
+
export declare const SHELL_TOOLS: readonly string[];
|
|
23
|
+
/** The background tools, each run on the environment its call gives (the box's, coding-tools.ts). */
|
|
24
|
+
export declare const backgroundTools: () => ToolRegistration[];
|
|
25
|
+
/** The run's end: every background process still running in run `runId`'s box (found by `label`) is sent TERM, then
|
|
26
|
+
* KILL after 3 s, and marked as ended at the run's end, so its runner writes its exit code and its log is whole before
|
|
27
|
+
* the box is pulled and destroyed. How many it ended; a run with no box ends none. */
|
|
28
|
+
export declare function endBackground(boxes: BoxProvider, label: Record<string, string>, context: Context): Promise<number>;
|