@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.45
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 +131 -5
- package/README.md +371 -300
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +52 -16
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
- package/dist/console/assets/index-DaFsZuzQ.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +7 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +23 -89
- package/dist/learn/check.js +57 -335
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +87 -102
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +13 -1
- package/dist/learn/promote.js +9 -0
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +4 -4
- package/dist/learning-setting.js +6 -6
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +268 -316
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +15 -1
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +16 -8
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +16 -5
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +63 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +8 -6
- package/dist/runner/promotion.js +19 -12
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1222 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +1 -5
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +55 -33
- package/dist/server.js +685 -320
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +2 -1
- package/dist/templates.js +6 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +60 -5
- package/dist/triggers.js +123 -18
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +4 -1
- package/dist/webhooks.js +11 -4
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +33 -19
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/templates/README.md +7 -7
- package/templates/inbound-lead/agent.md +3 -3
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -35
- package/dist/learning-evals.js +0 -99
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { ApiError } from "./errors.js";
|
|
2
|
+
import { redacted } from "./key-refusal.js";
|
|
3
|
+
import { runCutValues } from "./run-cut.js";
|
|
4
|
+
import { servedTimelineRows } from "./run-timeline-served.js";
|
|
5
|
+
import { answersOf, asksOf, WITHHELD_SIGN_IN } from "./run-view.js";
|
|
6
|
+
import { costIsBooked } from "./runner/metrics.js";
|
|
7
|
+
import { decisionsOverStore } from "./store-reads/decisions.js";
|
|
8
|
+
import { isCliRecord, piShaped, runEntries } from "./store-reads/journal.js";
|
|
9
|
+
import { answeredRequests } from "./timeline/index.js";
|
|
10
|
+
/** The most spans one read serves: the run's first, in the order they started. `dropped` counts the rest. */
|
|
11
|
+
export const TRACE_SPANS_MAX = 2_000;
|
|
12
|
+
const obj = (value) => (typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined);
|
|
13
|
+
const finite = (value) => (typeof value === "number" && Number.isFinite(value) ? value : undefined);
|
|
14
|
+
const count = (value) => (typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined);
|
|
15
|
+
/** A time as the rows write theirs; undefined for one no Date holds. */
|
|
16
|
+
const iso = (ms) => (Math.abs(ms) <= 8.64e15 ? new Date(ms).toISOString() : undefined);
|
|
17
|
+
const STOP_REASONS = new Set(["stop", "length", "toolUse", "error", "aborted", "deferred", "pending"]);
|
|
18
|
+
/** An answer's tokens, by the usage row's rule (timeline tokensOf): all four known, and some input unless it failed. */
|
|
19
|
+
function tokensOf(usage, failed) {
|
|
20
|
+
const u = obj(usage);
|
|
21
|
+
const [input, output] = [count(u?.input), count(u?.output)];
|
|
22
|
+
const cacheRead = u?.cacheRead === undefined ? 0 : count(u.cacheRead);
|
|
23
|
+
const cacheWrite = u?.cacheWrite === undefined ? 0 : count(u.cacheWrite);
|
|
24
|
+
if (input === undefined || output === undefined || cacheRead === undefined || cacheWrite === undefined)
|
|
25
|
+
return null;
|
|
26
|
+
if (!(failed || input + cacheRead + cacheWrite > 0))
|
|
27
|
+
return null;
|
|
28
|
+
const reasoning = count(u?.reasoning);
|
|
29
|
+
return { input, cache_read: cacheRead, cache_write: cacheWrite, output, ...(reasoning !== undefined && reasoning <= output ? { reasoning } : {}) };
|
|
30
|
+
}
|
|
31
|
+
const keyOf = (conv, id) => `${conv ?? 0}:${id}`;
|
|
32
|
+
/** The approvals of a run's calls, from its journal's asks and answers (run-view.ts asksOf, answersOf), as its served
|
|
33
|
+
* Timeline reads them. `final`: the run's state where it is stopped or failed, whose end its journal may not hold. */
|
|
34
|
+
export function traceApprovals(entries, final) {
|
|
35
|
+
const answers = answersOf(entries, final ? { final } : {});
|
|
36
|
+
return new Map([...asksOf(entries).values()].map((ask) => {
|
|
37
|
+
const answer = answers[ask.id];
|
|
38
|
+
return [ask.call_id, answer ? { decision: answer.decision, ...(answer.answered_at ? { answered_at: answer.answered_at } : {}) } : {}];
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
/** The spans of a run whose served Timeline rows are `rows` and whose journal entries are `entries` (as the store keeps
|
|
42
|
+
* them: runEntries). `redact`: the run's cut, for the one text taken from an entry (a model's name); every other word is
|
|
43
|
+
* a row's, cut already. `approvals`: what came of each call that asked for one (traceApprovals): how such a call ended
|
|
44
|
+
* is read from there, never from its rows, which the Timeline rewords while it waits. `decisions`: a workflow run's
|
|
45
|
+
* decision receipts (store-reads/decisions.ts), each a model request of its own: a judge's, a route's, a verify's. */
|
|
46
|
+
export function traceSpans(rows, entries, options = {}) {
|
|
47
|
+
const said = (text) => (options.redact ? options.redact(text) : text);
|
|
48
|
+
const cli = isCliRecord(entries);
|
|
49
|
+
const booked = costIsBooked(entries, cli);
|
|
50
|
+
// A CLI harness's messages are no requests (its booking counts those, with no time): none is a span.
|
|
51
|
+
const requests = cli ? [] : answeredRequests(piShaped(entries));
|
|
52
|
+
// Each call's rows are its own conversation's (two conversations may each make a call of one id), so a call is known
|
|
53
|
+
// by both. The conversations that made a call of an id, in the order they did: a call named from another conversation
|
|
54
|
+
// (a subagent's rows name the call that started it) is the first of them that is not the namer's own.
|
|
55
|
+
const uses = rows.filter((row) => row.kind === "tool_use" && row.tool_use_id);
|
|
56
|
+
const convsOf = new Map();
|
|
57
|
+
for (const row of uses) {
|
|
58
|
+
const convs = convsOf.get(row.tool_use_id) ?? [];
|
|
59
|
+
if (!convs.includes(row.conversation_id ?? 0))
|
|
60
|
+
convsOf.set(row.tool_use_id, [...convs, row.conversation_id ?? 0]);
|
|
61
|
+
}
|
|
62
|
+
/** The span id of call `callId` as conversation `conv`'s rows name it: its own call of that id where `own`, else another's. */
|
|
63
|
+
const toolId = (callId, conv, own) => {
|
|
64
|
+
const convs = convsOf.get(callId) ?? [];
|
|
65
|
+
const of = own && convs.includes(conv) ? conv : convs.find((other) => other !== conv);
|
|
66
|
+
return of === undefined ? null : `t:${keyOf(of, callId)}`;
|
|
67
|
+
};
|
|
68
|
+
// The call that started each subagent conversation, and the label each conversation's rows carry. Every row of a
|
|
69
|
+
// subagent's conversation names the call that started it, its first row too; a conversation whose first row names
|
|
70
|
+
// none was started by no call (a call nested in one of its own names that call on its own rows alone).
|
|
71
|
+
const startedBy = new Map();
|
|
72
|
+
const labels = new Map();
|
|
73
|
+
const first = new Set();
|
|
74
|
+
for (const row of rows) {
|
|
75
|
+
const conv = row.conversation_id ?? 0;
|
|
76
|
+
if (row.agent_label && !labels.has(conv))
|
|
77
|
+
labels.set(conv, row.agent_label);
|
|
78
|
+
if (first.has(conv))
|
|
79
|
+
continue;
|
|
80
|
+
first.add(conv);
|
|
81
|
+
const started = row.parent_tool_use_id === undefined ? null : toolId(row.parent_tool_use_id, conv, false);
|
|
82
|
+
if (started)
|
|
83
|
+
startedBy.set(conv, started);
|
|
84
|
+
}
|
|
85
|
+
const spans = [];
|
|
86
|
+
const modelEnds = new Map();
|
|
87
|
+
for (const entry of requests) {
|
|
88
|
+
const message = obj(entry.model?.[0]);
|
|
89
|
+
const at = finite(message?.timestamp);
|
|
90
|
+
const started = at === undefined ? undefined : iso(at);
|
|
91
|
+
if (!message || at === undefined || started === undefined || entry.id === undefined)
|
|
92
|
+
continue;
|
|
93
|
+
const conv = entry.conversationId ?? 0;
|
|
94
|
+
const took = count(message.durationMs);
|
|
95
|
+
const ended = took === undefined ? undefined : iso(at + took);
|
|
96
|
+
const failed = message.stopReason === "error";
|
|
97
|
+
const aborted = message.stopReason === "aborted";
|
|
98
|
+
const total = finite(obj(obj(message.usage)?.cost)?.total);
|
|
99
|
+
modelEnds.set(keyOf(conv, entry.id), ended === undefined ? undefined : at + took);
|
|
100
|
+
spans.push({
|
|
101
|
+
at, id: `m:${keyOf(conv, entry.id)}`, kind: "model", parent_id: startedBy.get(conv) ?? null,
|
|
102
|
+
name: said(typeof message.model === "string" && message.model ? message.model : "model"), agent_label: labels.get(conv) ?? null,
|
|
103
|
+
started_at: started, ended_at: ended ?? null, status: failed ? "failed" : aborted ? "interrupted" : "ok",
|
|
104
|
+
stop_reason: typeof message.stopReason === "string" && STOP_REASONS.has(message.stopReason) ? message.stopReason : null,
|
|
105
|
+
// A request cut before its end reported no final usage and no cost (the usage row counts it unknown).
|
|
106
|
+
tokens: aborted ? null : tokensOf(message.usage, failed),
|
|
107
|
+
usd: booked || aborted || total === undefined || total < 0 ? null : total, decision: false,
|
|
108
|
+
charged: false, not_metered: false, tool_use_id: null, input_preview: null, result_preview: null, result_size_bytes: null,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// A workflow's decisions: each receipt is one request to its decision model, written when it answered (`at`), with
|
|
112
|
+
// how long it took, its tokens and its own cost. Its node is its label, as its Timeline row's is.
|
|
113
|
+
(options.decisions ?? []).forEach((receipt, place) => {
|
|
114
|
+
const ended = typeof receipt.at === "string" ? Date.parse(receipt.at) : Number.NaN;
|
|
115
|
+
if (!Number.isFinite(ended))
|
|
116
|
+
return;
|
|
117
|
+
const took = count(receipt.latency_ms);
|
|
118
|
+
const at = took === undefined ? ended : ended - took;
|
|
119
|
+
const usage = obj(receipt.usage);
|
|
120
|
+
const [input, output] = [count(usage?.input_tokens), count(usage?.output_tokens)];
|
|
121
|
+
const cost = finite(receipt.cost_usd);
|
|
122
|
+
const named = typeof receipt.model === "string" && receipt.model ? receipt.model : typeof receipt.provider === "string" && receipt.provider ? receipt.provider : "decision";
|
|
123
|
+
spans.push({
|
|
124
|
+
at, id: `d:${String(receipt.id ?? place)}:${String(obj(receipt.request)?.index ?? 0)}`, kind: "model", parent_id: null,
|
|
125
|
+
name: said(named), agent_label: typeof receipt.node === "string" && receipt.node ? said(receipt.node) : null,
|
|
126
|
+
started_at: iso(at) ?? String(receipt.at), ended_at: took === undefined ? null : iso(ended) ?? null,
|
|
127
|
+
status: receipt.status === "failed" || (receipt.status === undefined && typeof receipt.error === "string" && receipt.error !== "") ? "failed" : receipt.status === "cancelled" ? "interrupted" : "ok",
|
|
128
|
+
stop_reason: null,
|
|
129
|
+
// A receipt keeps its input whole, with no split by cache.
|
|
130
|
+
tokens: input !== undefined && output !== undefined ? { input, cache_read: 0, cache_write: 0, output } : null,
|
|
131
|
+
usd: cost !== undefined && cost >= 0 ? cost : null, decision: true,
|
|
132
|
+
charged: false, not_metered: false, tool_use_id: null, input_preview: null, result_preview: null, result_size_bytes: null,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
// How long each tool ran, where its result says (pi's monotonic clock): a pi call's row is dated by its request's start,
|
|
136
|
+
// so the row alone would count the model's writing as the tool's time. In order, one for each result of a call's id.
|
|
137
|
+
const ran = new Map();
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
const message = entry.kind === "pi.tool-result" ? obj(entry.model?.[0]) : undefined;
|
|
140
|
+
if (!message || typeof message.toolCallId !== "string")
|
|
141
|
+
continue;
|
|
142
|
+
const key = keyOf(entry.conversationId, message.toolCallId);
|
|
143
|
+
ran.set(key, [...(ran.get(key) ?? []), count(message.durationMs)]);
|
|
144
|
+
}
|
|
145
|
+
// Each call's result rows, in order (a conversation that made two calls of one id has two), and what was charged under
|
|
146
|
+
// each: a charge is the call's it follows, so the second call of an id has its own.
|
|
147
|
+
const results = new Map();
|
|
148
|
+
const charges = new Map();
|
|
149
|
+
const chargeOf = (key) => {
|
|
150
|
+
let charge = charges.get(key);
|
|
151
|
+
if (!charge)
|
|
152
|
+
charges.set(key, (charge = { known: 0, unknown: false, charged: false, notMetered: false }));
|
|
153
|
+
return charge;
|
|
154
|
+
};
|
|
155
|
+
const called = new Set(uses.map((row) => keyOf(row.conversation_id, row.tool_use_id)));
|
|
156
|
+
/** How many calls of each id its conversation has made so far, as the rows are read in order. */
|
|
157
|
+
const sofar = new Map();
|
|
158
|
+
const occurrence = (key) => `${key}#${Math.max(0, (sofar.get(key) ?? 1) - 1)}`;
|
|
159
|
+
for (const row of rows) {
|
|
160
|
+
if (!row.tool_use_id)
|
|
161
|
+
continue;
|
|
162
|
+
// A row is its own conversation's call's; a charge written with no conversation of its own is the call's by its id.
|
|
163
|
+
const own = keyOf(row.conversation_id, row.tool_use_id);
|
|
164
|
+
const key = called.has(own) ? own : keyOf(convsOf.get(row.tool_use_id)?.[0] ?? row.conversation_id, row.tool_use_id);
|
|
165
|
+
if (row.kind === "tool_use")
|
|
166
|
+
sofar.set(key, (sofar.get(key) ?? 0) + 1);
|
|
167
|
+
if (row.kind === "tool_result")
|
|
168
|
+
results.set(key, [...(results.get(key) ?? []), row]);
|
|
169
|
+
// A browser call's session time is folded into its own row; a paid tool's fee is a row of its own after the result.
|
|
170
|
+
else if ((row.kind === "tool_use" || row.kind === "phase") && row.usage) {
|
|
171
|
+
const charge = chargeOf(occurrence(key));
|
|
172
|
+
charge.charged = true;
|
|
173
|
+
if (row.usage.usd === null)
|
|
174
|
+
charge.unknown = true;
|
|
175
|
+
else
|
|
176
|
+
charge.known += row.usage.usd;
|
|
177
|
+
}
|
|
178
|
+
else if (row.kind === "phase" && row.tool_name && !row.path && (row.summary ?? "").startsWith("Not metered:"))
|
|
179
|
+
chargeOf(occurrence(key)).notMetered = true;
|
|
180
|
+
}
|
|
181
|
+
const made = new Map();
|
|
182
|
+
for (const use of uses) {
|
|
183
|
+
const conv = use.conversation_id ?? 0;
|
|
184
|
+
const key = keyOf(conv, use.tool_use_id);
|
|
185
|
+
// The nth call of an id in its conversation takes that conversation's nth result of it, and is a span of its own.
|
|
186
|
+
const nth = made.get(key) ?? 0;
|
|
187
|
+
made.set(key, nth + 1);
|
|
188
|
+
const result = results.get(key)?.[nth];
|
|
189
|
+
const shown = Date.parse(use.timestamp);
|
|
190
|
+
const approval = nth === 0 ? options.approvals?.get(use.tool_use_id) : undefined;
|
|
191
|
+
// A result the renderer wrote for a call that never got one (timeline interrupt): the call was cut, and neither that
|
|
192
|
+
// row's status nor its time is the call's. One the run's end closed (no status) was cut too, at its own time.
|
|
193
|
+
const cutShort = result !== undefined && result.id.includes(":interrupted:");
|
|
194
|
+
const answered = approval?.answered_at ? Date.parse(approval.answered_at) : Number.NaN;
|
|
195
|
+
// How it ended, and when, where the record says: a call that asked for approval by what came of that (it waits, it
|
|
196
|
+
// was withdrawn with its run and never ran, it was denied), any other by its result.
|
|
197
|
+
const [status, done] = approval && approval.decision === undefined ? ["waiting", undefined]
|
|
198
|
+
: approval && (approval.decision === "canceled" || approval.decision === "withdrawn") ? ["interrupted", answered]
|
|
199
|
+
: approval?.decision === "deny" ? ["refused", Number.isFinite(answered) ? answered : result ? Date.parse(result.timestamp) : undefined]
|
|
200
|
+
: !result ? ["running", undefined]
|
|
201
|
+
: cutShort ? ["interrupted", undefined]
|
|
202
|
+
: result.refused ? ["refused", Date.parse(result.timestamp)]
|
|
203
|
+
: result.tool_status === "failed" ? ["failed", Date.parse(result.timestamp)]
|
|
204
|
+
: result.tool_status === "success" ? ["ok", Date.parse(result.timestamp)]
|
|
205
|
+
: ["interrupted", Date.parse(result.timestamp)];
|
|
206
|
+
const over = done !== undefined && Number.isFinite(done);
|
|
207
|
+
const model = use.round === undefined ? undefined : keyOf(conv, use.round);
|
|
208
|
+
const asked = model !== undefined && modelEnds.has(model);
|
|
209
|
+
// How long it ran is its result's to say, for a call that ran to a result of its own.
|
|
210
|
+
const took = status === "ok" || status === "failed" ? ran.get(key)?.[nth] : undefined;
|
|
211
|
+
const after = asked ? modelEnds.get(model) : undefined;
|
|
212
|
+
// Where the result keeps how long the tool ran, it started that long before it ended; else when its request ended,
|
|
213
|
+
// where that is known; else when its row says. Never after its own end.
|
|
214
|
+
const from = over && took !== undefined ? done - took : after !== undefined ? Math.max(shown, after) : shown;
|
|
215
|
+
const at = over ? Math.min(from, done) : from;
|
|
216
|
+
const charge = charges.get(`${key}#${nth}`);
|
|
217
|
+
const parent = asked ? `m:${model}` : use.parent_tool_use_id !== undefined ? toolId(use.parent_tool_use_id, conv, true) : null;
|
|
218
|
+
spans.push({
|
|
219
|
+
at, id: nth === 0 ? `t:${key}` : `t:${key}#${nth + 1}`, kind: "tool", parent_id: parent, name: use.tool_name ?? "tool", agent_label: use.agent_label ?? null,
|
|
220
|
+
started_at: iso(at) ?? use.timestamp, ended_at: over ? iso(done) ?? null : null, status,
|
|
221
|
+
stop_reason: null, tokens: null,
|
|
222
|
+
usd: charge?.charged ? (charge.unknown ? null : Math.round(charge.known * 1e12) / 1e12) : null,
|
|
223
|
+
decision: false, charged: charge?.charged ?? false, not_metered: charge?.notMetered ?? false,
|
|
224
|
+
tool_use_id: use.tool_use_id, input_preview: use.tool_input_preview ?? null,
|
|
225
|
+
// A call that never ran has no result of its own: what its rows say of it is the Timeline's words, not its output.
|
|
226
|
+
result_preview: status === "waiting" || cutShort || (approval && status === "interrupted") ? null : result?.tool_result_preview ?? null,
|
|
227
|
+
result_size_bytes: status === "waiting" || cutShort || (approval && status === "interrupted") ? null : result?.tool_result_size_bytes ?? null,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
// In the order they started; a request before the calls it made at the same instant.
|
|
231
|
+
spans.sort((a, b) => a.at - b.at || (a.kind === b.kind ? 0 : a.kind === "model" ? -1 : 1) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
232
|
+
const kept = spans.slice(0, TRACE_SPANS_MAX).map(({ at: _at, ...span }) => span);
|
|
233
|
+
return { model_requests: cli ? "not_recorded" : booked ? "tokens_only" : "priced", spans: kept, dropped: spans.length - kept.length };
|
|
234
|
+
}
|
|
235
|
+
/** Run `runId`'s trace as served: its spans over its served Timeline rows and its journal, the model's name through the
|
|
236
|
+
* run's cut. A run withheld (its sign-in can't be read back here) is refused (403), as its graph and its files are:
|
|
237
|
+
* none of its words is served, and an empty trace would read as a run that did nothing. */
|
|
238
|
+
export async function servedRunTrace(deps, store, runId, context) {
|
|
239
|
+
if ((await runCutValues(deps, store, runId)) === "unreadable")
|
|
240
|
+
throw new ApiError("forbidden", WITHHELD_SIGN_IN);
|
|
241
|
+
const rows = await servedTimelineRows(deps, store, runId, context);
|
|
242
|
+
// The cut after the rows: it only grows, so it holds every value the rows were cut of.
|
|
243
|
+
const cut = await runCutValues(deps, store, runId);
|
|
244
|
+
if (cut === "unreadable")
|
|
245
|
+
throw new ApiError("forbidden", WITHHELD_SIGN_IN);
|
|
246
|
+
const run = await store.runs.get(runId);
|
|
247
|
+
const entries = await runEntries(store, runId, context);
|
|
248
|
+
const approvals = traceApprovals(entries, run?.state === "stopped" || run?.state === "failed" ? run.state : undefined);
|
|
249
|
+
// A workflow's decision receipts; a run that made none has none. Receipts that can't be read leave their spans out
|
|
250
|
+
// (the run's usage row says its cost is unknown then: decision-rows.ts withDecisions).
|
|
251
|
+
const decisions = await decisionsOverStore(store, runId, context).catch(() => []);
|
|
252
|
+
return { run_id: runId, ...traceSpans(rows, entries, { redact: (text) => redacted(text, cut.values), approvals, decisions }) };
|
|
253
|
+
}
|
package/dist/run-view.d.ts
CHANGED
|
@@ -96,6 +96,21 @@ type JournalEntry = {
|
|
|
96
96
|
* so the run waits on it no more (the file path's `resolved` once its process acted). The card's id and call id are both
|
|
97
97
|
* the call's id, and its arguments are kept as JSON (shown cut and redacted by the view), as the file path kept them. */
|
|
98
98
|
export declare function asksOf(entries: readonly JournalEntry[]): Map<string, Approval>;
|
|
99
|
+
/** Whether a person's stop of a run stands asked and not yet taken: an agentic run (readRun's kind) still reading running,
|
|
100
|
+
* with a stop command its runner has neither taken nor refused. The runner cuts the turn first and takes the stop row in
|
|
101
|
+
* the commit that ends the run stopped, so between the two the run is stopped all the same: its view says so (stopped
|
|
102
|
+
* pending) and every call still waiting reads withdrawn (answersOf `final`), as the stop's answer endpoint already says
|
|
103
|
+
* (runs-over-store endBefore: an answer after the stop is 409 withdrawn). */
|
|
104
|
+
export declare function stopAsked(view: {
|
|
105
|
+
kind?: string;
|
|
106
|
+
state?: string;
|
|
107
|
+
} | null | undefined, run: {
|
|
108
|
+
importedFrom: unknown;
|
|
109
|
+
} | null | undefined, commands: readonly {
|
|
110
|
+
kind: string;
|
|
111
|
+
takenAt: number | null;
|
|
112
|
+
refused: string | null;
|
|
113
|
+
}[]): boolean;
|
|
99
114
|
/** The answers a run got to its asks, from its journal's `agentrun.answer` entries, by the call's id (the key the moment
|
|
100
115
|
* and the pending views read as run.meta.approvals): a person's allow or deny with any note, or a withdrawal taken when
|
|
101
116
|
* the run was stopped or cancelled while the call waited. The first answer for a call stands, but for a stop's
|
package/dist/run-view.js
CHANGED
|
@@ -148,6 +148,15 @@ export function asksOf(entries) {
|
|
|
148
148
|
}
|
|
149
149
|
return map;
|
|
150
150
|
}
|
|
151
|
+
/** Whether a person's stop of a run stands asked and not yet taken: an agentic run (readRun's kind) still reading running,
|
|
152
|
+
* with a stop command its runner has neither taken nor refused. The runner cuts the turn first and takes the stop row in
|
|
153
|
+
* the commit that ends the run stopped, so between the two the run is stopped all the same: its view says so (stopped
|
|
154
|
+
* pending) and every call still waiting reads withdrawn (answersOf `final`), as the stop's answer endpoint already says
|
|
155
|
+
* (runs-over-store endBefore: an answer after the stop is 409 withdrawn). */
|
|
156
|
+
export function stopAsked(view, run, commands) {
|
|
157
|
+
return view?.state === "running" && view.kind === "agentic" && run?.importedFrom === null &&
|
|
158
|
+
commands.some((command) => command.kind === "stop" && command.takenAt === null && command.refused === null);
|
|
159
|
+
}
|
|
151
160
|
/** The answers a run got to its asks, from its journal's `agentrun.answer` entries, by the call's id (the key the moment
|
|
152
161
|
* and the pending views read as run.meta.approvals): a person's allow or deny with any note, or a withdrawal taken when
|
|
153
162
|
* the run was stopped or cancelled while the call waited. The first answer for a call stands, but for a stop's
|
package/dist/runnable.js
CHANGED
|
@@ -79,8 +79,9 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
79
79
|
};
|
|
80
80
|
const harness = revision.harness ?? DEFAULT_HARNESS;
|
|
81
81
|
const offer = (offers ?? (await harnessOffers(env))).find((h) => h.id === harness);
|
|
82
|
+
// One the table hides (HarnessEntry.hidden: Goose before its owner installs it) has no offer: its entry says why.
|
|
82
83
|
if (!offer?.available)
|
|
83
|
-
out.push({ field: "definition.harness", reason: NOT_SET_UP, message: offer?.reason ?? `This server does not run ${harness}.`, host: true, harness });
|
|
84
|
+
out.push({ field: "definition.harness", reason: NOT_SET_UP, message: offer?.reason ?? harnessOf(env, harness)?.hidden?.(env) ?? `This server does not run ${harness}.`, host: true, harness });
|
|
84
85
|
const { place } = revision;
|
|
85
86
|
// A workflow's model and call nodes run on the runner here; in a box they do not run yet. Its fix names the runner: an
|
|
86
87
|
// edit that leaves the place out keeps the agent's (agents-store.ts), so removing the field would change nothing.
|
|
@@ -14,8 +14,8 @@ import type { ScriptComputer } from "../workspace/run-tools.js";
|
|
|
14
14
|
import { type RunCapOptions, type RunDecisions, type RunTools } from "@parcha/agentrun-kernel/kernel/cap";
|
|
15
15
|
import { type PortModels } from "../port-models.js";
|
|
16
16
|
/** The run's cap's config, as its spec gives it: the kernel runCap's options but its sessions (the loop's own), and
|
|
17
|
-
* `beside`, what was spent beside the run's sessions on its behalf (
|
|
18
|
-
*
|
|
17
|
+
* `beside`, what was spent beside the run's sessions on its behalf (learning-end.ts shadowBesideOf: its audit's shadow
|
|
18
|
+
* run), which every gate of the run reads with its sessions' spend (runBooking's sessions.beside, overCap, the
|
|
19
19
|
* wrap-ups). None: nothing is. */
|
|
20
20
|
export type RunCapConfig = Omit<RunCapOptions, "sessions"> & {
|
|
21
21
|
beside?(): Promise<number | null>;
|
|
@@ -98,6 +98,9 @@ export interface AdapterRunSpec {
|
|
|
98
98
|
* run, its model requests, its paid tool calls and its decisions, is admitted and booked through it. An uncapped run
|
|
99
99
|
* gives capUsd: () => undefined. */
|
|
100
100
|
readonly runCap: RunCapConfig;
|
|
101
|
+
/** This claim's model-request retry policy over the loop's defaults. A provider whose failed request may already be
|
|
102
|
+
* billed can disable automatic retries for every conversation in the claim, including its subagents. */
|
|
103
|
+
readonly retry?: Partial<ConversationRetryPolicy>;
|
|
101
104
|
/** The run's cap, when it has one (filled from the run's launch): its figure, and what a refusal does to the run (the
|
|
102
105
|
* kernel cap's parkOf: parked with a pending budget for a refusal a raise could fix, else failed in its words), at the
|
|
103
106
|
* cap the run is held to when it parks (`capUsd`: the newest raise's, else the launch's), which its pending budget
|
|
@@ -144,11 +147,10 @@ export interface AdapterRunSpec {
|
|
|
144
147
|
* them): it wins over LoopDeps.endOfRun and is asked where that one is, in the end turn while the claim is held, before
|
|
145
148
|
* a tool host's beforeRelease and the run's release, its rows in the end's commit. */
|
|
146
149
|
readonly endOfRun?: EndOfRunTurn;
|
|
147
|
-
/** What the claim laid of the run's learning seed (runner/learning-seed.ts): the learned
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
+
/** What the claim laid of the run's learning seed (runner/learning-seed.ts): the learned workflows it was given, by
|
|
151
|
+
* name. The loop writes it on the root (KINDS.learningLaid) as this claim opens. Absent for a run that does not
|
|
152
|
+
* learn. */
|
|
150
153
|
readonly learningLaid?: {
|
|
151
|
-
readonly skills: readonly string[];
|
|
152
154
|
readonly workflows: readonly string[];
|
|
153
155
|
};
|
|
154
156
|
/** The run's work folder, as its file tools resolve a path: what the end-of-run turn's refusal under work/.learning/
|
|
@@ -29,7 +29,7 @@ const outputRetried = (entries) => {
|
|
|
29
29
|
import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
|
|
30
30
|
import { ASKED_BECAUSE, deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
|
|
31
31
|
import { ADAPTER_API } from "../turn-end.js";
|
|
32
|
-
import { answerText,
|
|
32
|
+
import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
|
|
33
33
|
import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
|
|
34
34
|
import { outputMiss, outputRetryWords } from "../answer-json.js";
|
|
35
35
|
import { answerOnce, HAND_BACK, handBackOf } from "./hand-back.js";
|
|
@@ -53,6 +53,7 @@ import { Fenced } from "../store/index.js";
|
|
|
53
53
|
import { answerAsServed } from "../answer-json.js";
|
|
54
54
|
import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
|
|
55
55
|
import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprovedTools } from "../learned-workflow.js";
|
|
56
|
+
import { warnHoldShort } from "../print.js";
|
|
56
57
|
import { feedbackAsk, feedbackOf, pendingFeedbackOf } from "./feedback-round.js";
|
|
57
58
|
import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
58
59
|
/** 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,
|
|
@@ -634,8 +635,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
634
635
|
/** The current pass ended in a park that keeps its computer (keepAtPark), for this cause, until its release reads it. */
|
|
635
636
|
let parkedNow;
|
|
636
637
|
/** From the end-of-run step's start (or a claim that found its turn open: lookingBackOpen, from its session's open)
|
|
637
|
-
* until the claim ends: a steer is left for the end,
|
|
638
|
-
* (REFLECT_NOTE_ONLY), and every request is learning's, never the job's: the cap's wrap-up note is never told to it,
|
|
638
|
+
* until the claim ends: a steer is left for the end, and every request is learning's, never the job's: the cap's wrap-up note is never told to it,
|
|
639
639
|
* and a refusal of one never parks the run (learningRefused). Held between the step's asks too: a turn a takeover
|
|
640
640
|
* resumed may send its next request while the step still reads an earlier answer. */
|
|
641
641
|
let reflecting = false;
|
|
@@ -1321,7 +1321,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1321
1321
|
/** The root a phase is making, awaited before the owed writes are read. */
|
|
1322
1322
|
let rootMaking;
|
|
1323
1323
|
harness = await Harness.open(gate.journal, {
|
|
1324
|
-
models: () => models, registry, settings: { restartLimit, retry, stream }, onReport: () => { },
|
|
1324
|
+
models: () => models, registry, settings: () => ({ restartLimit, retry: { ...retry, ...specNow?.retry }, stream }), onReport: () => { },
|
|
1325
1325
|
// A tool host's onConversation, in each agent conversation's creating commit (the spec's, once it is known: the
|
|
1326
1326
|
// root is created when the session opens, after the spec).
|
|
1327
1327
|
conversationCreated: async (tx, record) => {
|
|
@@ -1659,7 +1659,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1659
1659
|
// earlier session's, a grade's), summed as overCap sums them; null while any is unknown. Read at the claim and again
|
|
1660
1660
|
// after each request is admitted (the note is placed before its own request's admission, so it reads the last).
|
|
1661
1661
|
const restOf = async () => {
|
|
1662
|
-
// And what was spent beside the run on its behalf (its
|
|
1662
|
+
// And what was spent beside the run on its behalf (its audit's shadow run).
|
|
1663
1663
|
const beside = await besideNow();
|
|
1664
1664
|
if (beside === null)
|
|
1665
1665
|
return null;
|
|
@@ -1849,6 +1849,9 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1849
1849
|
// at their hold or cut, comes before `capNote.live` and is never one.)
|
|
1850
1850
|
if (capNote.live && event.type === "request_end" && event.host === undefined && !notOwn.has(event.turn) && typeof event.usage.usd === "number" && event.usage.usd > 0 && !event.usage.cut && !event.usage.givenBack)
|
|
1851
1851
|
capNote.costs.push(event.usage.usd);
|
|
1852
|
+
// A request that billed more input than the bound its hold was priced on (the booking's holdShort): one warn
|
|
1853
|
+
// line, ids and figures only (print.ts warnHoldShort). Its booking, the hold and the cap are as they were.
|
|
1854
|
+
warnHoldShort(claim.runId, spec.adapter.id, event);
|
|
1852
1855
|
if (event.type === "request_start") {
|
|
1853
1856
|
// A new request means the model's last message is over: what it said so far is on the record before the request,
|
|
1854
1857
|
// so an answer shows while the turn goes on (a CLI that answers, then makes another request).
|
|
@@ -2317,15 +2320,19 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2317
2320
|
// (a new claim's, or a restart's after a fault: closeSession let the last one go) is not the one an open hold held,
|
|
2318
2321
|
// nor has what the owner set up on it: the run ends in those words.
|
|
2319
2322
|
heldNow = undefined;
|
|
2323
|
+
// This pass's hold began waiting for the start: an owner's row may move it on (start, release) as soon as the pass
|
|
2324
|
+
// opens, before the wait below begins, so a release there still ends the run before its agent runs.
|
|
2325
|
+
let heldBeforeStart = false;
|
|
2320
2326
|
if (spec.held) {
|
|
2321
2327
|
const [journalOf, rootOf] = [harness, root];
|
|
2322
2328
|
heldNow = journalHeld(spec.held, (entries) => journalOf.commit(async (tx) => {
|
|
2323
2329
|
for (const entry of entries)
|
|
2324
2330
|
await tx.appendEntry(rootOf.id, { kind: entry.kind, data: entry.data });
|
|
2325
2331
|
}, context), now);
|
|
2326
|
-
|
|
2332
|
+
const up = await heldNow.up(await entriesOf(gate.journal, root.id, context));
|
|
2333
|
+
if (up === "lost")
|
|
2327
2334
|
return await writeEnd(harness, root, gate, { state: "failed", summary: heldWords.lost }, []);
|
|
2328
|
-
|
|
2335
|
+
heldBeforeStart = up === "held";
|
|
2329
2336
|
}
|
|
2330
2337
|
// The cap a raise left the run at, before any request of this claim, through the one reader the run view and its
|
|
2331
2338
|
// budget card read too (capNowOf: the newest raise entry, else the launch's cap): a claim that takes over a raised
|
|
@@ -2350,7 +2357,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2350
2357
|
// What this claim laid of the run's learning seed, once per claim: the newest is what the run was given.
|
|
2351
2358
|
if (restarts === 0 && spec.learningLaid) {
|
|
2352
2359
|
const [journalOf, rootOf, laid] = [harness, root, spec.learningLaid];
|
|
2353
|
-
await journalOf.commit((tx) => tx.appendEntry(rootOf.id, { kind: KINDS.learningLaid, data: {
|
|
2360
|
+
await journalOf.commit((tx) => tx.appendEntry(rootOf.id, { kind: KINDS.learningLaid, data: { workflows: [...laid.workflows] } }), context);
|
|
2354
2361
|
}
|
|
2355
2362
|
// Reopened by a person's follow-up (runs.reopen, or the end's own reopen): a fresh reopen is a claim whose journal's
|
|
2356
2363
|
// root ends on an end entry, with no input of the root in flight. Then any turn its session still reads open is one
|
|
@@ -2402,7 +2409,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2402
2409
|
// A held computer waits for its owner's start before the agent's first input; the owner's calls set the task up
|
|
2403
2410
|
// meanwhile. A release, or no call for the hold's minutes, ends the run before its agent ever ran. A stop ends it
|
|
2404
2411
|
// stopped, and a lost claim leaves it for the next claim.
|
|
2405
|
-
if (heldNow
|
|
2412
|
+
if (heldNow && (heldNow.state() === "waiting" || (heldBeforeStart && heldNow.state() === "released"))) {
|
|
2406
2413
|
const aborted = new Promise((resolve) => (deps.signal.aborted ? resolve() : deps.signal.addEventListener("abort", () => resolve(), { once: true })));
|
|
2407
2414
|
const waited = await heldNow.untilStarted(Promise.race([stopping, aborted, harness.closed]));
|
|
2408
2415
|
// Set by stop() during the wait: read past the narrowing TypeScript did before it.
|
|
@@ -2992,9 +2999,6 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2992
2999
|
// An MCP tool is asked about by its catalog name (`mcp:<server>/<tool>`), as its settings and its card name it.
|
|
2993
3000
|
const tool = mcp?.catalogOf(call.tool) ?? call.tool;
|
|
2994
3001
|
const kernelCall = { callId: call.callId, tool: tool, args: call.args };
|
|
2995
|
-
// The end-of-run turn's notes are kept only from its answer: a write there is refused before its intent.
|
|
2996
|
-
if (reflecting && WRITES.has(call.tool) && underLearning(spec.workRoot, call.args))
|
|
2997
|
-
return { deny: REFLECT_NOTE_ONLY };
|
|
2998
3002
|
await hooks.beforeIntent(kernelCall);
|
|
2999
3003
|
// 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
|
|
3000
3004
|
// in its fixed words, and the model answers from what it has. A call a running tool makes is that tool's, let through.
|
|
@@ -4,6 +4,7 @@ import type { HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
|
4
4
|
import type { Approvals } from "../approvals.js";
|
|
5
5
|
import type { installForClaim, installSettled } from "../harness-install.js";
|
|
6
6
|
import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
|
|
7
|
+
import { type RunnerLive } from "../live-reach.js";
|
|
7
8
|
import { type PinnedModel, type Tier } from "../model.js";
|
|
8
9
|
import { type RunLaunch } from "../run-launch.js";
|
|
9
10
|
import type { Store } from "../store/store.js";
|
|
@@ -88,8 +89,9 @@ export interface AdapterSpecDeps {
|
|
|
88
89
|
readonly journal: (claim: Claim) => Journal;
|
|
89
90
|
/** The one store: `runs` and `agents` for the run's revision, and the live-viewer seam for the browser tool. */
|
|
90
91
|
readonly store: Store & LiveViewerStore;
|
|
91
|
-
/** The key the store's
|
|
92
|
-
|
|
92
|
+
/** The key the store's sealed values are opened under (store/seal.ts): the runner's. Undefined in a run's own process
|
|
93
|
+
* (run-child.ts), which never holds it: what a claim opens with it is asked of the runner there (held.ts). */
|
|
94
|
+
readonly sealKey: Buffer | undefined;
|
|
93
95
|
/** The run's model route (model-route.ts routeOf), the one route the pi adapter and the cap read, on a wire of `wires`
|
|
94
96
|
* (the caller's; pi speaks both of main's, PI_WIRES). */
|
|
95
97
|
readonly routeOf: (model: string | PinnedModel | undefined, env: NodeJS.ProcessEnv, tier?: Tier, wires?: readonly Wire[], upstream?: typeof fetch, redact?: (text: string) => string) => Promise<ModelRoute>;
|
|
@@ -167,6 +169,9 @@ export type EvalFakes = {
|
|
|
167
169
|
* model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
|
|
168
170
|
* overhead its provider adds; the output ceiling is the route's when it carries one, else none. */
|
|
169
171
|
export declare function capModelOf(route: ModelRoute): CapModel;
|
|
172
|
+
/** Particle requests are never automatically replayed after an uncertain failure. Retry is a harness-wide setting,
|
|
173
|
+
* so a claim with any Particle route disables it for all its conversations, including subagents on other tiers. */
|
|
174
|
+
export declare function modelRetryOf(routes: Iterable<Pick<ModelRoute, "like">>): Pick<AdapterRunSpec, "retry">;
|
|
170
175
|
/** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
|
|
171
176
|
* revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
|
|
172
177
|
* when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
|
|
@@ -293,7 +298,7 @@ export declare function learnedWorkflowHostTool(opts: {
|
|
|
293
298
|
* each a named todo, added as their seams land. */
|
|
294
299
|
/** The run's live-viewer writers over the store (browser-live.ts): a session's hand-over written sealed, and gone. Its
|
|
295
300
|
* viewer token, minted in the run, is held by `cut`, the run's one redactor, as it is handed over, before it is written. */
|
|
296
|
-
export declare function liveViewersOf(store: LiveViewerStore, sealKey: Buffer, claim: Claim, cut: HeldRedact): {
|
|
301
|
+
export declare function liveViewersOf(store: LiveViewerStore, sealKey: Buffer | undefined, claim: Claim, cut: HeldRedact): {
|
|
297
302
|
put(handover: LiveHandover): Promise<boolean>;
|
|
298
303
|
drop(tag?: string): Promise<void>;
|
|
299
304
|
};
|
|
@@ -314,7 +319,8 @@ export declare function buildToolHost(opts: {
|
|
|
314
319
|
readonly env: NodeJS.ProcessEnv;
|
|
315
320
|
readonly run: AdapterRun;
|
|
316
321
|
readonly store: Store & LiveViewerStore;
|
|
317
|
-
|
|
322
|
+
/** The runner's seal key; none in a run's own process, whose sealed reads its runner makes (held.ts). */
|
|
323
|
+
readonly sealKey: Buffer | undefined;
|
|
318
324
|
readonly life: ReturnType<typeof hostLifecycle>;
|
|
319
325
|
readonly redact: HeldRedact;
|
|
320
326
|
/** The run's launch (its trigger and origin) and its agent's own tool settings, as the email tools read them. */
|
|
@@ -326,7 +332,13 @@ export declare function buildToolHost(opts: {
|
|
|
326
332
|
readonly loopback?: boolean;
|
|
327
333
|
/** That server's own addresses (AdapterSpecDeps.mcpOwn): never the ports calendar_events reads on loopback. */
|
|
328
334
|
readonly own?: readonly string[];
|
|
335
|
+
/** A runner on another host than its server: where the run's viewers answer, under its run's key (claimLiveAt). */
|
|
336
|
+
readonly liveAt?: RunnerLive;
|
|
329
337
|
}): ToolHost;
|
|
338
|
+
/** Where the claim's viewers answer on a runner on another host than its server (live-reach.ts runnerLiveOf), under the
|
|
339
|
+
* claim's run's own proof key (liveForRun); none on the server's machine. In a run's own process its runner's
|
|
340
|
+
* (held.ts liveAt): the process holds its run's key, never the runners' shared one. */
|
|
341
|
+
export declare function claimLiveAt(deps: Pick<AdapterSpecDeps, "env" | "sealKey">, runId: string): Promise<RunnerLive | undefined>;
|
|
330
342
|
/** The run's web host tools (tool-list.ts `host` rows: web_fetch, web_search, monid) as HostTool[], each bound through `host` by its
|
|
331
343
|
* catalog name and wrapped as the hands are (host-tools.ts hostToolOf, with `ctx`), the one binding the pi spec and the
|
|
332
344
|
* CLI spec share. Each runs under the adapter loop's one gate (spec.gate) on the claim's keys (host.env), and books its
|