@parcha/agentrun-serve 0.1.0-beta.29 → 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.
Files changed (152) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/README.md +564 -97
  3. package/dist/adapters.d.ts +35 -6
  4. package/dist/adapters.js +152 -26
  5. package/dist/agents.d.ts +11 -5
  6. package/dist/agents.js +16 -10
  7. package/dist/app.js +80 -20
  8. package/dist/background.d.ts +28 -0
  9. package/dist/background.js +376 -0
  10. package/dist/box-egress.d.ts +98 -0
  11. package/dist/box-egress.js +259 -0
  12. package/dist/box-image.d.ts +1 -1
  13. package/dist/box-image.js +9 -7
  14. package/dist/box-relay-vm.d.ts +80 -0
  15. package/dist/box-relay-vm.js +389 -0
  16. package/dist/box-relay.d.ts +8 -5
  17. package/dist/box-relay.js +14 -9
  18. package/dist/boxes.d.ts +21 -3
  19. package/dist/boxes.js +14 -7
  20. package/dist/browser-cost.d.ts +41 -0
  21. package/dist/browser-cost.js +158 -0
  22. package/dist/cap.d.ts +129 -21
  23. package/dist/cap.js +338 -67
  24. package/dist/coding-tools.d.ts +7 -3
  25. package/dist/coding-tools.js +16 -10
  26. package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
  27. package/dist/console/assets/index-34jfpIbQ.js +481 -0
  28. package/dist/console/assets/index-DUHbWcIP.css +1 -0
  29. package/dist/console/index.html +2 -2
  30. package/dist/content-filter.d.ts +7 -0
  31. package/dist/content-filter.js +23 -0
  32. package/dist/decision-rows.d.ts +11 -3
  33. package/dist/decision-rows.js +18 -11
  34. package/dist/errors.d.ts +2 -0
  35. package/dist/errors.js +5 -2
  36. package/dist/files.d.ts +6 -1
  37. package/dist/files.js +7 -2
  38. package/dist/grade.d.ts +7 -10
  39. package/dist/grade.js +31 -51
  40. package/dist/graph-served.d.ts +23 -0
  41. package/dist/graph-served.js +75 -0
  42. package/dist/graph-view.d.ts +7 -5
  43. package/dist/graph-view.js +10 -3
  44. package/dist/harness-app.d.ts +4 -2
  45. package/dist/harness-app.js +101 -19
  46. package/dist/harness-opencode/adapter.d.ts +45 -0
  47. package/dist/harness-opencode/adapter.js +272 -0
  48. package/dist/harness-opencode/binary.d.ts +18 -0
  49. package/dist/harness-opencode/binary.js +87 -0
  50. package/dist/harness-opencode/config.d.ts +24 -0
  51. package/dist/harness-opencode/config.js +61 -0
  52. package/dist/harness-opencode/harness.d.ts +77 -0
  53. package/dist/harness-opencode/harness.js +620 -0
  54. package/dist/harness-opencode/host/mcp.d.ts +40 -0
  55. package/dist/harness-opencode/host/mcp.js +208 -0
  56. package/dist/harness-opencode/host/policy.d.ts +71 -0
  57. package/dist/harness-opencode/host/policy.js +419 -0
  58. package/dist/harness-opencode/host/server.d.ts +55 -0
  59. package/dist/harness-opencode/host/server.js +165 -0
  60. package/dist/harness-opencode/index.d.ts +9 -0
  61. package/dist/harness-opencode/index.js +6 -0
  62. package/dist/harness-opencode/verify.d.ts +32 -0
  63. package/dist/harness-opencode/verify.js +75 -0
  64. package/dist/harness-opencode/versions.d.ts +33 -0
  65. package/dist/harness-opencode/versions.js +64 -0
  66. package/dist/harness.d.ts +4 -1
  67. package/dist/harness.js +5 -2
  68. package/dist/host-tools.d.ts +12 -2
  69. package/dist/host-tools.js +26 -12
  70. package/dist/host.js +6 -2
  71. package/dist/hosted-search.js +5 -1
  72. package/dist/import.d.ts +2 -2
  73. package/dist/import.js +4 -3
  74. package/dist/key-check.d.ts +3 -2
  75. package/dist/key-check.js +7 -3
  76. package/dist/key-refusal.js +8 -4
  77. package/dist/learn/check.d.ts +10 -1
  78. package/dist/learn/check.js +19 -1
  79. package/dist/learn/grade.d.ts +3 -2
  80. package/dist/learn/grade.js +25 -13
  81. package/dist/learn/index.d.ts +2 -2
  82. package/dist/learn/index.js +2 -2
  83. package/dist/learn/notes.js +2 -1
  84. package/dist/learn/reflect.d.ts +2 -2
  85. package/dist/learn/reflect.js +51 -5
  86. package/dist/learn/secrets.js +28 -8
  87. package/dist/learn/skills.d.ts +17 -4
  88. package/dist/learn/skills.js +79 -6
  89. package/dist/learned-workflow.d.ts +59 -0
  90. package/dist/learned-workflow.js +191 -0
  91. package/dist/learning-run.d.ts +7 -5
  92. package/dist/learning-run.js +45 -23
  93. package/dist/learning-words.d.ts +6 -3
  94. package/dist/learning-words.js +8 -5
  95. package/dist/learning.d.ts +44 -3
  96. package/dist/learning.js +148 -3
  97. package/dist/mcp-servers.d.ts +7 -4
  98. package/dist/mcp-servers.js +5 -0
  99. package/dist/mcp.js +5 -5
  100. package/dist/model.d.ts +13 -11
  101. package/dist/model.js +11 -10
  102. package/dist/openapi/agentrun-v2.openapi.json +1 -0
  103. package/dist/openapi.js +358 -48
  104. package/dist/paid-calls.d.ts +5 -1
  105. package/dist/paid-calls.js +1 -1
  106. package/dist/pause.d.ts +2 -0
  107. package/dist/place.d.ts +27 -4
  108. package/dist/place.js +42 -10
  109. package/dist/propose.d.ts +2 -0
  110. package/dist/propose.js +38 -8
  111. package/dist/request-start.d.ts +12 -4
  112. package/dist/request-start.js +139 -15
  113. package/dist/run-box.d.ts +56 -4
  114. package/dist/run-box.js +173 -23
  115. package/dist/runnable.d.ts +5 -2
  116. package/dist/runnable.js +12 -4
  117. package/dist/runs.d.ts +258 -36
  118. package/dist/runs.js +830 -89
  119. package/dist/secrets.d.ts +12 -0
  120. package/dist/secrets.js +18 -0
  121. package/dist/server.d.ts +131 -35
  122. package/dist/server.js +467 -105
  123. package/dist/sign-ins.d.ts +99 -0
  124. package/dist/sign-ins.js +288 -0
  125. package/dist/skills.d.ts +16 -4
  126. package/dist/skills.js +35 -7
  127. package/dist/stats.d.ts +7 -2
  128. package/dist/stats.js +28 -7
  129. package/dist/tool-gate.d.ts +266 -0
  130. package/dist/tool-gate.js +554 -0
  131. package/dist/tool-keys.d.ts +46 -10
  132. package/dist/tool-keys.js +44 -2
  133. package/dist/tool-plane.d.ts +112 -27
  134. package/dist/tool-plane.js +205 -47
  135. package/dist/tools.d.ts +69 -14
  136. package/dist/tools.js +143 -24
  137. package/dist/trigger-secrets.d.ts +32 -0
  138. package/dist/trigger-secrets.js +143 -0
  139. package/dist/triggers.d.ts +439 -0
  140. package/dist/triggers.js +863 -0
  141. package/dist/turn-end.d.ts +3 -2
  142. package/dist/turn-end.js +3 -2
  143. package/dist/usage-lines.d.ts +26 -0
  144. package/dist/usage-lines.js +28 -0
  145. package/dist/validate.d.ts +2 -0
  146. package/dist/validate.js +11 -2
  147. package/dist/webhooks.d.ts +11 -4
  148. package/dist/webhooks.js +17 -1
  149. package/launcher/agentrun-serve +1 -1
  150. package/package.json +19 -13
  151. package/dist/console/assets/index-BN7oVcO4.js +0 -445
  152. package/dist/console/assets/index-By-jkqki.css +0 -1
package/dist/app.js CHANGED
@@ -21,10 +21,12 @@ import { codingSource } from "./coding-tools.js";
21
21
  import { cancelledIn, markRequests } from "./request-start.js";
22
22
  import { decisionProvidersOf } from "./decisions.js";
23
23
  import { FOLLOW_UP_OPEN_ENV, readJson, RUN_META } from "./files.js";
24
- import { adapterFor, claudeModel, claudePriceModel, claudeSkillCheck, codexModel, openRouterOnly, thinkingFor } from "./adapters.js";
24
+ import { adapterFor, claudeModel, claudePriceModel, claudeSkillCheck, codexModel, learnedRoute, learnedWorkflowsOff, openRouterOnly, thinkingFor } from "./adapters.js";
25
25
  import { DEFAULT_HARNESS, FAUX_HARNESS_ENV } from "./harness.js";
26
26
  import { adapterRun } from "./harness-app.js";
27
- import { withLearned } from "./learning.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";
28
30
  import { completer } from "./llm.js";
29
31
  import { searchOn } from "./hosted-search.js";
30
32
  import { imageLoader } from "./pdf-pages.js";
@@ -32,12 +34,14 @@ import { EFFORT_ENV, llmTiers, nodeTiers, runModels, thinkingOf, workflowNodes }
32
34
  import { gated, liveView, nodeLog, readLiveView } from "./pause.js";
33
35
  import { remotePlace, storedPlace } from "./place.js";
34
36
  import { runBox, runBoxProvider } from "./run-box.js";
37
+ import { planeOf } from "./tool-plane.js";
35
38
  import { ASK_TOOL, toolOf, workflowTools } from "./tools.js";
36
- import { promptOf, systemOf } from "./skills.js";
39
+ import { promptOf, readsFiles, systemOf } from "./skills.js";
37
40
  import { EnvironmentLine, environmentLine } from "./environment.js";
38
41
  import { effortGuidance } from "./effort-guidance.js";
39
42
  import { isObject } from "./validate.js";
40
43
  import { mirrorWrites } from "./workspace.js";
44
+ import { deniedText, runGate } from "./tool-gate.js";
41
45
  /** The workflow adapters this host gives every run: model nodes, and calls `via: "tool"` to the table's tools. Typed
42
46
  * questions (`runJudge`) run too where the host sets a decision provider's key (decisions.ts). */
43
47
  export const WORKFLOW_ADAPTERS = ["runNode", "runEffect"];
@@ -72,12 +76,12 @@ async function claudeModels(env, ref) {
72
76
  const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
73
77
  return { models: builtinModels({ authContext: authContextOf(env) }), model: choice.model, byTier: new Map([["default", choice.model]]), unpriced: new Set() };
74
78
  }
75
- /** codex's model and pi-ai's catalog that prices it, where codex reaches OpenAI only through OpenRouter (codexModel: no
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
76
80
  * OpenAI key needed); anywhere else, the run's usual models (runModels). */
77
- async function codexModels(env, ref) {
78
- if (env[FAUX_HARNESS_ENV] || !openRouterOnly("codex", env))
79
- return runModels(env, ref, ["default"], "codex");
80
- const choice = await codexModel(env, ref);
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);
81
85
  if ("why" in choice)
82
86
  throw new Error(choice.why);
83
87
  const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
@@ -103,14 +107,21 @@ export default async function app(where) {
103
107
  const env = withSecrets(process.env);
104
108
  const workflowNodeList = revision.kind === "workflow" ? workflowNodes(revision.body.workflow, (await import("@parcha/agentrun-dsl")).inspectWorkflow(revision.body.workflow)) : [];
105
109
  // codex's model as a save resolves it (codexModel): an OpenAI model it reaches through OpenRouter alone needs no OpenAI key.
106
- 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" ? await codexModels(env, revision.body.model) : revision.kind === "agentic" ? await runModels(env, revision.body.model, ["default"], revision.body.harness) : await runModels(env, undefined, llmTiers(workflowNodeList, nodeTiers(workflowNodeList)));
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)));
107
111
  const { model, byTier } = chosen;
108
112
  // Read before the run opens its store: what it spent in earlier processes counts against its cap.
109
113
  const cap = capOf(process.env);
110
114
  // Each request is marked as it leaves (request-start.ts), inside the cap: a request the cap refuses never leaves, and
111
115
  // gets a start mark of its own, which its error entry answers.
112
116
  const marked = await markRequests(chosen.models, cancelledIn(where.root));
113
- const models = cap === undefined ? marked.models : await capModels(marked.models, cap, spentIn(join(where.store, RUN_STORE_FILE)), { unpriced: chosen.unpriced, refused: marked.refused });
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);
114
125
  const thinkingLevel = thinkingOf(process.env, revision.kind === "agentic" ? revision.body.thinking : undefined);
115
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).
116
127
  const meta = await readJson(join(where.root, RUN_META));
@@ -122,6 +133,10 @@ export default async function app(where) {
122
133
  if (box?.mirror)
123
134
  mirrorWrites(where.work, box.mirror);
124
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);
125
140
  const registry = createRegistry();
126
141
  // An agentic run's system prompt starts with the date and the workspace (environment.ts). On pi it is a section,
127
142
  // installed first so it comes before every other extension's and the instructions.
@@ -131,15 +146,34 @@ export default async function app(where) {
131
146
  // What the run's agent learned goes into its instructions, and the skills it wrote join the revision's, the one path for
132
147
  // every harness (learning.ts).
133
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;
134
167
  // The run's effort, as its thinking level reads it: its note on how to work follows the instructions on every harness
135
168
  // (effort-guidance.ts). None without an effort.
136
169
  const guidance = effortGuidance(process.env[EFFORT_ENV]);
137
170
  if (revision.kind === "agentic" && revision.body.harness && revision.body.harness !== DEFAULT_HARNESS) {
138
171
  const harness = revision.body.harness;
139
172
  // claude-agent loads the skills its adapter takes itself (its Skill tool), and its prompt keeps only the ones it would
140
- // refuse; codex's prompt, and a faux harness's, keep every skill (skills.ts).
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).
141
175
  const check = harness === "claude-agent" && !env[FAUX_HARNESS_ENV] ? await claudeSkillCheck() : undefined;
142
- const { system: instructions, native } = await systemOf(learned.instructions, learned.skills, where.work, check);
176
+ const { system: instructions, native } = await systemOf(learned.instructions, learned.skills, where.work, check, { onDemand: readsFiles(revision.body.tools) });
143
177
  // The session's system prompt starts with the line, made as this process opens it: a run resumed on a later day is
144
178
  // opened with that day.
145
179
  const spec = { key: `run:${run.id}`, label: run.agent, system: [environmentLine(), instructions, guidance].filter((text) => Boolean(text)), context: "fresh", thinking: thinkingFor(harness, thinkingLevel) };
@@ -159,12 +193,11 @@ export default async function app(where) {
159
193
  // The cancel mark serve writes is read here too, as pi's model wrapper reads it (request-start.ts).
160
194
  // The run's stop record (serve.json, as serve saved it before a stop's abort): a turn it names is not resumed.
161
195
  const stopRecord = { ...(typeof meta?.stopped_at === "string" ? { stopped_at: meta.stopped_at } : {}), ...(typeof meta?.stopped_after === "number" ? { stopped_after: meta.stopped_after } : {}) };
162
- const { door, onOpen } = adapterRun(make, harness, spec, BACKGROUND, cap, named, dir, guard, cancelledIn(where.root), where.work, coding.tools, stopRecord);
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] : []);
163
197
  // A paid host tool's settle goes to the run's root, as on pi (paid-calls.ts settleIn).
164
- return { models: {}, registry: createRegistry(), door, onOpen: async (durable) => (settleIn(rootRecordOf(durable.harness)), onOpen(durable)), beforeResume: markResumed };
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 };
165
200
  }
166
- // web_search's own request to the model provider, when it resolves native, goes through the run's models (hosted-search.ts).
167
- searchOn(models);
168
201
  // Each tool the revision names is bound once, from the table: its extensions installed here, its documents written in
169
202
  // each conversation's creating commit, what it settles done before anything resumes, and what it lets go done before
170
203
  // the run is released.
@@ -201,8 +234,21 @@ export default async function app(where) {
201
234
  };
202
235
  if (revision.kind === "agentic") {
203
236
  const tools = (await Promise.all(revision.body.tools.map((name) => bind(name)))).flatMap((binding) => binding.tools);
204
- const instructions = [await promptOf(learned.instructions, learned.skills, where.work), guidance].filter(Boolean).join("\n\n");
205
- return { models, registry, ...hooks, ...(stops.length ? { wake } : {}), root: { agent: { model, thinkingLevel, instructions, tools } }, onOpen: async (durable) => (settleIn(rootRecordOf(durable.harness)), marked.open(durable)) };
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 };
206
252
  }
207
253
  const input = isObject(meta?.input) ? meta.input : {};
208
254
  const [{ BACKGROUND_CONTEXT }, { createWorkflowExtension, decisionRecovery, durableDecisions, nodeRunner, taskScope }, { EffectFailure, inspectWorkflow, judgeFromProviders }, { withRecovery, workspaceFiles }, { startWorkflowRevision }, decisionProviders] = await Promise.all([
@@ -217,6 +263,11 @@ export default async function app(where) {
217
263
  const nodeTools = new Map();
218
264
  for (const name of workflowTools(workflowNodeList).nodes)
219
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);
220
271
  // A decision node's images are files of the run's work directory (pdf_pages draws them there).
221
272
  const loadImage = imageLoader(where.work);
222
273
  const log = nodeLog(where.root);
@@ -244,6 +295,14 @@ export default async function app(where) {
244
295
  const at = { path: executionPath ?? null, item: item?.index ?? null, tool: node.tool, label: node.label };
245
296
  log({ t: "effect.start", ...at, input, at: new Date().toISOString() });
246
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.`);
247
306
  const durable = opened;
248
307
  const ledger = durable ? { call: `${node.label}@${executionPath ?? ""}${item ? `#${item.index}` : ""}`, record: rootRecordOf(durable.harness) } : undefined;
249
308
  const output = await effect(input, { signal, env, work: where.work, complete, ...(ledger ? { ledger } : {}) });
@@ -252,7 +311,8 @@ export default async function app(where) {
252
311
  }
253
312
  catch (error) {
254
313
  const message = String(error?.message ?? error);
255
- log({ t: "effect.end", ...at, status: "failed", error: message.slice(0, 2000), at: new Date().toISOString() });
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() });
256
316
  // An abort (a cancel, the node's deadline) stays a throw: the driver keeps its effect unknown. A tool that failed on
257
317
  // its own (an unreadable PDF, a model's refusal) answered: its failure is the effect's outcome, completed, and is
258
318
  // thrown past the driver as the call node's typed failure (`failing`), which a collecting map ends that item on.
@@ -272,7 +332,7 @@ export default async function app(where) {
272
332
  /** A model node's agent: its tier's model, the tools it names, and the extensions they come from. */
273
333
  const nodeAgent = (node) => {
274
334
  const bindings = (node.tools ?? []).flatMap((name) => nodeTools.get(name) ?? []);
275
- return { model: byTier.get(node.tier ?? "default"), thinkingLevel, extensions: [...new Set([coding.extension, ...bindings.flatMap((b) => b.extensions)])], tools: bindings.flatMap((b) => b.tools) };
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) };
276
336
  };
277
337
  const nodes = nodeRunner({ agent: (node) => nodeAgent(node) });
278
338
  /** The node log's starts and ends, from the workflow's events: what a graph shows of a node's timing. */
@@ -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>;