@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37
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 +170 -0
- package/README.md +158 -52
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -17
- package/dist/cap.js +0 -91
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-view.d.ts +13 -0
- package/dist/computer-view.js +50 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +33 -7
- package/dist/computers.js +50 -8
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +53 -25
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +1 -1
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/learn/check.d.ts +4 -1
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +4 -2
- package/dist/learn/commit.js +5 -5
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +22 -1
- package/dist/learn/reflect.d.ts +10 -1
- package/dist/learn/reflect.js +14 -4
- package/dist/learn/skills.d.ts +33 -5
- package/dist/learn/skills.js +53 -7
- package/dist/learned-workflow.d.ts +24 -0
- package/dist/learned-workflow.js +66 -3
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +25 -2
- package/dist/learning-routes.js +39 -6
- package/dist/learning-words.d.ts +6 -0
- package/dist/learning-words.js +6 -0
- package/dist/learning.d.ts +28 -15
- package/dist/learning.js +84 -44
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +19 -2
- package/dist/mcp-probe.js +44 -9
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +112 -20
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.js +23 -10
- package/dist/openapi.js +386 -21
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +13 -5
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-launch.d.ts +14 -2
- package/dist/run-launch.js +9 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-view.d.ts +3 -3
- package/dist/run-view.js +14 -7
- package/dist/runner/adapter-loop.d.ts +23 -7
- package/dist/runner/adapter-loop.js +648 -62
- package/dist/runner/adapter-run-spec.d.ts +11 -3
- package/dist/runner/adapter-run-spec.js +77 -22
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +9 -4
- package/dist/runner/adapters/pi.js +76 -14
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +20 -3
- package/dist/runner/cli-run-spec.js +113 -43
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.js +80 -14
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +20 -1
- package/dist/runner/journal-kinds.js +14 -0
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +22 -1
- package/dist/runner/learning-end.js +92 -12
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +67 -7
- package/dist/runner/learning-loop.js +173 -21
- package/dist/runner/learning-seed.d.ts +7 -0
- package/dist/runner/learning-seed.js +13 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +2 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +10 -7
- package/dist/runner/mcp-claim.js +113 -24
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +5 -5
- package/dist/runner/mcp-run.js +15 -3
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +12 -2
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/reflect-hook.d.ts +18 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +184 -15
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.js +3 -1
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-spec.d.ts +14 -2
- package/dist/runner/workflow-spec.js +56 -20
- package/dist/runs-over-store.d.ts +6 -1
- package/dist/runs-over-store.js +38 -9
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +43 -14
- package/dist/server.js +472 -126
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.js +77 -8
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +28 -13
- package/dist/store/sqlite/store.js +272 -54
- package/dist/store/store.d.ts +268 -9
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +73 -15
- package/dist/store-reads/learning.d.ts +20 -4
- package/dist/store-reads/learning.js +74 -18
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +26 -11
- package/dist/template-eval.js +6 -4
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/timeline/timeline.d.ts +27 -0
- package/dist/timeline/timeline.js +10 -9
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-budget.d.ts +19 -7
- package/dist/tool-budget.js +14 -8
- package/dist/tool-gate.d.ts +16 -9
- package/dist/tool-gate.js +53 -42
- package/dist/tool-plane.d.ts +16 -12
- package/dist/tool-plane.js +9 -4
- package/dist/tools.d.ts +13 -4
- package/dist/tools.js +13 -4
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +25 -6
- package/dist/trigger-signatures.js +41 -7
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.js +11 -1
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +16 -9
- package/dist/workspace/computer-deps.js +19 -7
- package/dist/workspace/computer-for-claim.d.ts +17 -8
- package/dist/workspace/computer-for-claim.js +62 -21
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +3 -0
- package/dist/workspace/resolve-computer.js +8 -2
- package/dist/workspace/run-tools.d.ts +32 -15
- package/dist/workspace/run-tools.js +23 -30
- package/package.json +19 -16
- package/templates/market-monitor/agent.md +1 -1
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
|
@@ -1,32 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NOT_SET_UP } from "./runnable.js";
|
|
2
2
|
/** Each GitHub MCP tool a template may grant that needs more than reading what the App's metadata gives: the permission
|
|
3
|
-
* and level
|
|
3
|
+
* and level GitHub's permission table for its request names, and what the template does instead when it can't. */
|
|
4
4
|
export const TOOL_PERMISSIONS = {
|
|
5
5
|
issue_write: { permission: "issues", level: "write", instead: "keeps its draft in its answer" },
|
|
6
6
|
};
|
|
7
7
|
/** Each permission as GitHub's App settings name it. */
|
|
8
8
|
const LABELS = { issues: "Issues", pull_requests: "Pull requests", contents: "Contents", metadata: "Metadata" };
|
|
9
9
|
const holds = (has, needs) => has === "write" || (has === "read" && needs === "read");
|
|
10
|
-
/** The warnings applying `pkg` adds: one for each GitHub MCP tool it grants that needs a permission
|
|
11
|
-
* App's
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** The warnings applying `pkg` adds: one for each GitHub MCP tool it grants that needs a permission an installation of the
|
|
11
|
+
* App does not hold (naming each installation's account and what it holds), on an MCP server `onApp` says runs on the App's
|
|
12
|
+
* tokens; or, where `held` could not be read, one saying it could not check. `held` is asked once, and only when a tool
|
|
13
|
+
* with a need is granted on such a server. */
|
|
14
|
+
export async function appPermissionWarnings(pkg, onApp, held) {
|
|
15
|
+
const asked = [];
|
|
14
16
|
for (const need of pkg.mcp) {
|
|
15
17
|
if (!onApp(need.server))
|
|
16
18
|
continue;
|
|
17
19
|
for (const tool of need.tools) {
|
|
18
20
|
const wants = TOOL_PERMISSIONS[tool];
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (wants)
|
|
22
|
+
asked.push({ server: need.server, tool, wants });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!asked.length)
|
|
26
|
+
return [];
|
|
27
|
+
const map = await held();
|
|
28
|
+
const warnings = [];
|
|
29
|
+
for (const { server, tool, wants } of asked) {
|
|
30
|
+
// One of the grants.<tool> family (a tool the server denies is another): its field and its shape.
|
|
31
|
+
const label = LABELS[wants.permission] ?? wants.permission;
|
|
32
|
+
const name = `mcp:${server}/${tool}`;
|
|
33
|
+
if ("unreadable" in map) {
|
|
34
|
+
warnings.push({ field: `grants.${name}`, reason: NOT_SET_UP, message: `${name} needs ${label}: ${wants.level} of the GitHub App, and this server could not check whether it has it (${map.unreadable}): if ${pkg.name} can't use it, it ${wants.instead}.` });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const short = map.installations.filter((installation) => !holds(installation.permissions[wants.permission], wants.level));
|
|
38
|
+
if (short.length) {
|
|
39
|
+
const holding = short.map(({ account, permissions }) => `${permissions[wants.permission] ? `${label}: ${permissions[wants.permission]}` : `no ${label} permission`} on ${account}`).join(", ");
|
|
28
40
|
warnings.push({ field: `grants.${name}`, reason: "not_allowed", message: `${name} needs ${label}: ${wants.level}, and this server's GitHub App has ${holding}, so GitHub refuses it: ${pkg.name} ${wants.instead}. The App's owner can add ${label}: ${wants.level} to it on GitHub.` });
|
|
29
41
|
}
|
|
42
|
+
// Installations whose map was not read in time or at all: said apart, never passed as holding it.
|
|
43
|
+
if (map.unread?.length) {
|
|
44
|
+
const byReason = new Map();
|
|
45
|
+
for (const { account, why } of map.unread)
|
|
46
|
+
byReason.set(why, [...(byReason.get(why) ?? []), account]);
|
|
47
|
+
const unread = [...byReason].map(([why, accounts]) => `${accounts.join(", ")} (${why})`).join("; ");
|
|
48
|
+
warnings.push({ field: `grants.${name}`, reason: NOT_SET_UP, message: `${name} needs ${label}: ${wants.level} of the GitHub App, and this server could not check whether it has it on ${unread}: if ${pkg.name} can't use it there, it ${wants.instead}.` });
|
|
49
|
+
}
|
|
30
50
|
}
|
|
31
51
|
return warnings;
|
|
32
52
|
}
|
|
@@ -50,6 +50,10 @@ export type TimelineEvent = {
|
|
|
50
50
|
* server and its id ending NOTE_SUFFIX: the request was not sent and the run paused for a raise; a pause, never a
|
|
51
51
|
* failure, whether the run waits on its cap now or was raised since. */
|
|
52
52
|
paused?: true;
|
|
53
|
+
/** `true` on the `tool_result` row of a call refused before it ran (its host's mark, CALL_REFUSED: a gate's deny, a
|
|
54
|
+
* person's, a call held for an approval the run ended or stopped without): it never ran, so it never failed, though
|
|
55
|
+
* `tool_status` stays `failed` (it did not do its work). A client shows it apart from a call that ran and failed. */
|
|
56
|
+
refused?: true;
|
|
53
57
|
/** On the usage row, the run's cost. On a paid tool's charge row (a `phase` naming the tool), that charge alone. On a
|
|
54
58
|
* browser call's `tool_use` row, every browser charge booked under that call (BROWSER_CHARGE): its session's time
|
|
55
59
|
* since its last charge, and its release's when it was the session's last call. `requests` is 0 on all but the usage
|
|
@@ -73,6 +77,24 @@ export type TimelineEvent = {
|
|
|
73
77
|
model?: string;
|
|
74
78
|
tier?: string;
|
|
75
79
|
}[];
|
|
80
|
+
/** On a tool call's `tool_result` row: each computer protocol call the tool made, in order (serve's computer-calls.ts):
|
|
81
|
+
* its method, whether it answered, its ms, its error's code, and for ui.act each step's kind, route and readback.
|
|
82
|
+
* Never a param's value or an answer's bytes. `computer_calls_dropped` counts the calls past the record's bound. This
|
|
83
|
+
* projector writes none (store-reads/journal.ts withComputerCalls). */
|
|
84
|
+
computer_calls?: readonly {
|
|
85
|
+
readonly method: string;
|
|
86
|
+
readonly ok: boolean;
|
|
87
|
+
readonly ms: number;
|
|
88
|
+
readonly code?: string;
|
|
89
|
+
readonly steps?: readonly {
|
|
90
|
+
readonly do: string;
|
|
91
|
+
readonly route?: string;
|
|
92
|
+
readonly verified?: boolean;
|
|
93
|
+
readonly error?: string;
|
|
94
|
+
}[];
|
|
95
|
+
readonly expect?: "met" | "unmet";
|
|
96
|
+
}[];
|
|
97
|
+
computer_calls_dropped?: number;
|
|
76
98
|
};
|
|
77
99
|
/** A pi conversation entry as stored: `pi.assistant`, `pi.tool-result`, a host's own kind. */
|
|
78
100
|
export type EntryLike = {
|
|
@@ -174,6 +196,11 @@ export type TimelineOptions = {
|
|
|
174
196
|
caps?: Partial<typeof CAPS>;
|
|
175
197
|
/** Nothing is running: a call with no result is interrupted. */
|
|
176
198
|
settled?: boolean;
|
|
199
|
+
/** The run's newest turn is over, cut by a stop or a cancel, while its process may live on: nothing of that turn is in
|
|
200
|
+
* flight, so the usage row counts a request marked with no answer or end, and a paid call marked with no charge, as
|
|
201
|
+
* cut, as a settled read counts them. The marks the runner writes once it has booked what the abort cut can land after
|
|
202
|
+
* the turn reads over; they change nothing then. Its rows are as they are. */
|
|
203
|
+
turnCut?: boolean;
|
|
177
204
|
/** The run has ended (completed, failed, cancelled): its usage row says its cost ("Cost: …"), never what it has cost
|
|
178
205
|
* "so far". A run settled and not ended (paused, its process let go) keeps "Cost so far". */
|
|
179
206
|
ended?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BROWSER_OPENERS, BROWSER_STEPS, callFailed, endsTurn, failedWith, inputPreview, labelOf, outcomeOf, refusedLabel, savedPaths } from "./labels.js";
|
|
2
|
-
import { cut, firstLine, firstSentence, json, obj, scrubUrls, str, utf8Bytes } from "./util.js";
|
|
2
|
+
import { cut, firstLine, firstSentence, json, obj, saidSummary, scrubUrls, str, utf8Bytes } from "./util.js";
|
|
3
3
|
import { BESIDE_SUFFIX, NOTE_SUFFIX, originMatcher, TRIGGER_LABELS } from "./origin.js";
|
|
4
4
|
/** Grep's caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
5
5
|
export const CAPS = { summary: 500, preview: 500, text: 2000, thinking: 100 };
|
|
@@ -568,7 +568,7 @@ function createProjector(options) {
|
|
|
568
568
|
return make("tool_result", conv, rowId, {
|
|
569
569
|
summary: !view.isError && pageChanged(tool.name, view) ? PAGE_CHANGED_ROW : view.isError ? failedSummary : worded ? `${named}: ${saidOf(worded.text)}` : outcome?.failed ? `${named}: failed` : `${named}: ok`, tool_name: tool.name, tool_use_id: tool.callId,
|
|
570
570
|
tool_status: failedWith(view, outcome) ? "failed" : "success", tool_result_preview: shown.text ? cut(scrubUrls(shown.text), caps.preview) : null,
|
|
571
|
-
tool_result_size_bytes: utf8Bytes(view.text), round: tool.round, parent_tool_use_id: parent,
|
|
571
|
+
tool_result_size_bytes: utf8Bytes(view.text), round: tool.round, parent_tool_use_id: parent, ...(refused(view) ? { refused: true } : {}),
|
|
572
572
|
});
|
|
573
573
|
};
|
|
574
574
|
/** The call a browser charge belongs to (BROWSER_CHARGE): the one it names, else its session's last charged call, else
|
|
@@ -695,7 +695,7 @@ function createProjector(options) {
|
|
|
695
695
|
// say. A message with no text block (a request the adapter bridge writes without content) shows none.
|
|
696
696
|
// An answer its turn goes on from is a text_block (provisional, below), an empty one too.
|
|
697
697
|
if (text || (final && first("text") >= 0)) {
|
|
698
|
-
const row = make(final ? "final_answer" : "text_block", conv, `${base}:${first("text")}`, { summary:
|
|
698
|
+
const row = make(final ? "final_answer" : "text_block", conv, `${base}:${first("text")}`, { summary: saidSummary(text), text });
|
|
699
699
|
add(row);
|
|
700
700
|
if (final) {
|
|
701
701
|
const earlier = provisional.get(conv);
|
|
@@ -732,7 +732,7 @@ function createProjector(options) {
|
|
|
732
732
|
const named = nameFor(name, args, before.view, before.shown);
|
|
733
733
|
use.summary = clean(named, caps.summary);
|
|
734
734
|
const fresh = resultRow(conv, before.row.id, { name, callId: id, round }, named, before.view, before.shown);
|
|
735
|
-
Object.assign(before.row, { summary: fresh.summary, tool_name: fresh.tool_name, tool_status: fresh.tool_status, seq: (use.seq ?? 0) + 0.5, ...(round === undefined ? {} : { round }) });
|
|
735
|
+
Object.assign(before.row, { summary: fresh.summary, tool_name: fresh.tool_name, tool_status: fresh.tool_status, seq: (use.seq ?? 0) + 0.5, ...(round === undefined ? {} : { round }), ...(fresh.refused ? { refused: true } : {}) });
|
|
736
736
|
rows.splice(rows.indexOf(before.row), 1);
|
|
737
737
|
rows.splice(rows.indexOf(use) + 1, 0, before.row);
|
|
738
738
|
touch(before.row);
|
|
@@ -768,7 +768,7 @@ function createProjector(options) {
|
|
|
768
768
|
if (!view.isError) {
|
|
769
769
|
const answer = str(args.answer);
|
|
770
770
|
if (name === "submit" && answer !== undefined)
|
|
771
|
-
add(make("final_answer", conv, `${base}:answer`, { summary:
|
|
771
|
+
add(make("final_answer", conv, `${base}:answer`, { summary: saidSummary(answer), text: answer }));
|
|
772
772
|
if (name === "request_sign_in") {
|
|
773
773
|
const reason = str(args.reason);
|
|
774
774
|
add(make("waiting", conv, `${base}:waiting`, { summary: `Waiting for you: ${reason ? firstLine(reason) : "sign in on the live browser"}` }));
|
|
@@ -792,10 +792,11 @@ function createProjector(options) {
|
|
|
792
792
|
systems.add(conv);
|
|
793
793
|
}
|
|
794
794
|
else if (entry.kind === "pi.reset") {
|
|
795
|
-
|
|
795
|
+
// The new context and a summary of the older one are words from the run: redacted by the host, before any cut.
|
|
796
|
+
add(make("phase", conv, base, { summary: "Context reset", text: redactText(textOf(message)) || null }));
|
|
796
797
|
}
|
|
797
798
|
else if (entry.kind === "pi.compaction") {
|
|
798
|
-
add(make("phase", conv, base, { summary: "Summarized older context", text: textOf(message) || null }));
|
|
799
|
+
add(make("phase", conv, base, { summary: "Summarized older context", text: redactText(textOf(message)) || null }));
|
|
799
800
|
}
|
|
800
801
|
else if (entry.kind === HOST_PHASE) {
|
|
801
802
|
// A step the host stamped (`at`, ms) shows at that time: written as it happened, it can sit after a message whose time
|
|
@@ -962,7 +963,7 @@ export function timelineOf(entries, options = {}) {
|
|
|
962
963
|
if (options.settled)
|
|
963
964
|
for (const [id, call] of projector.open())
|
|
964
965
|
projector.interrupt(call, id);
|
|
965
|
-
const usage = projector.usage();
|
|
966
|
+
const usage = projector.usage(options.turnCut === true);
|
|
966
967
|
return usage ? [...projector.rows(), usage] : [...projector.rows()];
|
|
967
968
|
}
|
|
968
969
|
/** The id of the call a run's turn ended waiting on a person by, or undefined: its last meaningful row is a successful tool
|
|
@@ -1123,7 +1124,7 @@ export function timelineReducer(options = {}) {
|
|
|
1123
1124
|
const shown = options.redactLive ? options.redactLive(raw) : fallback();
|
|
1124
1125
|
// The agent's text streams as it will settle, its URLs whole; its thinking is scrubbed, as when it settles.
|
|
1125
1126
|
const text = kind === "thinking" ? scrubUrls(shown) : shown;
|
|
1126
|
-
const summary = kind === "thinking" ? `Thinking: ${cut(firstSentence(text), thinkingCap)}` :
|
|
1127
|
+
const summary = kind === "thinking" ? `Thinking: ${cut(firstSentence(text), thinkingCap)}` : saidSummary(text);
|
|
1127
1128
|
live(kind, `${conv()}:live:${kind}`, text ? summary : undefined, { text });
|
|
1128
1129
|
}
|
|
1129
1130
|
};
|
package/dist/timeline/util.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export declare const obj: (value: unknown) => Obj | undefined;
|
|
|
3
3
|
export declare const str: (value: unknown) => string | undefined;
|
|
4
4
|
export declare const cut: (text: string, max: number) => string;
|
|
5
5
|
export declare const firstLine: (text: string) => string;
|
|
6
|
+
/** The summary of the agent's words (an answer, a text block): their first line; words that open with a fenced code block
|
|
7
|
+
* (a JSON answer's ```json … ```) the code inside the fence, up to its closing fence, each whitespace run one space, so
|
|
8
|
+
* the row previews the code itself, never the fence's label. The row's text keeps the words whole. */
|
|
9
|
+
export declare const saidSummary: (text: string) => string;
|
|
6
10
|
export declare const firstSentence: (text: string) => string;
|
|
7
11
|
export declare function utf8Bytes(text: string): number;
|
|
8
12
|
export declare function json(text: string): Obj | undefined;
|
package/dist/timeline/util.js
CHANGED
|
@@ -2,6 +2,20 @@ export const obj = (value) => typeof value === "object" && value !== null && !Ar
|
|
|
2
2
|
export const str = (value) => (typeof value === "string" ? value : undefined);
|
|
3
3
|
export const cut = (text, max) => (text.length > max ? `${text.slice(0, max - 3)}...` : text);
|
|
4
4
|
export const firstLine = (text) => text.split("\n").map((line) => line.trim()).find(Boolean) ?? "";
|
|
5
|
+
/** The summary of the agent's words (an answer, a text block): their first line; words that open with a fenced code block
|
|
6
|
+
* (a JSON answer's ```json … ```) the code inside the fence, up to its closing fence, each whitespace run one space, so
|
|
7
|
+
* the row previews the code itself, never the fence's label. The row's text keeps the words whole. */
|
|
8
|
+
export const saidSummary = (text) => {
|
|
9
|
+
// A fence's info string (its language) holds no backtick, so an inline ```code``` on one line is no fence.
|
|
10
|
+
const open = /^\s*(`{3,}|~{3,})[^\n`]*\n/.exec(text);
|
|
11
|
+
if (!open)
|
|
12
|
+
return firstLine(text);
|
|
13
|
+
const body = text.slice(open[0].length);
|
|
14
|
+
// Its closing fence (CommonMark): the same character, at least as many of it as the opening fence, alone on its line,
|
|
15
|
+
// indented at most 3 spaces (4 or a tab is code inside the fence, not its close).
|
|
16
|
+
const close = body.search(new RegExp(`^ {0,3}\\${open[1][0]}{${open[1].length},}[ \\t]*$`, "m"));
|
|
17
|
+
return (close >= 0 ? body.slice(0, close) : body).replace(/\s+/g, " ").trim() || firstLine(text);
|
|
18
|
+
};
|
|
5
19
|
export const firstSentence = (text) => {
|
|
6
20
|
const flat = text.replace(/\s+/g, " ").trim();
|
|
7
21
|
return /^.*?[.!?](?=\s|$)/.exec(flat)?.[0] ?? flat;
|
package/dist/tool-budget.d.ts
CHANGED
|
@@ -17,10 +17,22 @@ export declare function countCalls(entries: readonly EntryRecord[], callId: stri
|
|
|
17
17
|
};
|
|
18
18
|
/** What a call reads once its run's cap is nearly taken: the same words every time, as the tool-call budget's. */
|
|
19
19
|
export declare const WRAP_UP_TEXT = "Budget nearly spent: stop calling tools and answer now from what you have.";
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
/** A main-model request's figures as the cap prices them (kernel cap requestFigures): its answer at its least, its step-0
|
|
21
|
+
* typical cost, and its worst (its full asked output). */
|
|
22
|
+
export type RequestFigures = {
|
|
23
|
+
readonly leastUsd: number;
|
|
24
|
+
readonly step0Usd: number;
|
|
25
|
+
readonly worstUsd: number;
|
|
26
|
+
};
|
|
27
|
+
/** What a run keeps back of its cap so it can still answer: one typical step and one final answer at its least. The
|
|
28
|
+
* typical step is the run's own priced answers' typical cost (the wrap-up note's figure, kernel cap typicalCost; before
|
|
29
|
+
* any is priced, the step-0 cost of the request), the answer the cap's least for the main model's next request.
|
|
30
|
+
* Undefined when the request cannot be priced. The rule's one place: keeping back one final answer at its worst case
|
|
31
|
+
* instead would be `figures.worstUsd`, and a worst step and a least answer `figures.worstUsd + figures.leastUsd`. */
|
|
32
|
+
export declare const reserveFor: (figures: RequestFigures | undefined, typical: (step0Usd: number) => number) => number | undefined;
|
|
33
|
+
/** Whether a run under `capUsd` that has taken `takenUsd` wraps up. `takenUsd`: its spend and every step still out at its
|
|
34
|
+
* worst case, as the cap counts them (null: unknown). It wraps up once what it keeps back to answer (`reserveUsd`,
|
|
35
|
+
* reserveFor) no longer fits on top: in flight is reserved as it stands, so a fan-out keeps room for each conversation to
|
|
36
|
+
* answer, and a simple run uses its cap up to its last step and answer. No cap, a figure no one knows (the cap refuses
|
|
37
|
+
* the next request for that), or no reserve yet (no main-model request priced on this claim) is no. */
|
|
38
|
+
export declare const wrappingUp: (capUsd: number | undefined, takenUsd: number | null, reserveUsd: number | undefined) => boolean;
|
package/dist/tool-budget.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// its first calls up to it and the rest are refused.
|
|
12
12
|
//
|
|
13
13
|
// The cap's wrap-up, the same refusal for money: a run with a cap whose spend, plus what its requests and paid steps
|
|
14
|
-
// still out hold at their worst case,
|
|
14
|
+
// still out hold at their worst case, leaves too little to keep back one typical step and one final answer (reserveFor)
|
|
15
|
+
// has every model-issued tool call refused before
|
|
15
16
|
// its intent, in WRAP_UP_TEXT, on every harness and in every conversation of the run (a `subagent` spawn is a call too).
|
|
16
17
|
// Nothing in flight is cut, and model requests are not touched: each conversation answers from what it has, under the
|
|
17
18
|
// cap, which stays the last line. The figure is read from the run's committed booking records at each call (the cap's
|
|
@@ -47,10 +48,15 @@ export function countCalls(entries, callId, upTo, count = 0) {
|
|
|
47
48
|
}
|
|
48
49
|
/** What a call reads once its run's cap is nearly taken: the same words every time, as the tool-call budget's. */
|
|
49
50
|
export const WRAP_UP_TEXT = "Budget nearly spent: stop calling tools and answer now from what you have.";
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
/** What a run keeps back of its cap so it can still answer: one typical step and one final answer at its least. The
|
|
52
|
+
* typical step is the run's own priced answers' typical cost (the wrap-up note's figure, kernel cap typicalCost; before
|
|
53
|
+
* any is priced, the step-0 cost of the request), the answer the cap's least for the main model's next request.
|
|
54
|
+
* Undefined when the request cannot be priced. The rule's one place: keeping back one final answer at its worst case
|
|
55
|
+
* instead would be `figures.worstUsd`, and a worst step and a least answer `figures.worstUsd + figures.leastUsd`. */
|
|
56
|
+
export const reserveFor = (figures, typical) => figures === undefined ? undefined : typical(figures.step0Usd) + figures.leastUsd;
|
|
57
|
+
/** Whether a run under `capUsd` that has taken `takenUsd` wraps up. `takenUsd`: its spend and every step still out at its
|
|
58
|
+
* worst case, as the cap counts them (null: unknown). It wraps up once what it keeps back to answer (`reserveUsd`,
|
|
59
|
+
* reserveFor) no longer fits on top: in flight is reserved as it stands, so a fan-out keeps room for each conversation to
|
|
60
|
+
* answer, and a simple run uses its cap up to its last step and answer. No cap, a figure no one knows (the cap refuses
|
|
61
|
+
* the next request for that), or no reserve yet (no main-model request priced on this claim) is no. */
|
|
62
|
+
export const wrappingUp = (capUsd, takenUsd, reserveUsd) => capUsd !== undefined && takenUsd !== null && reserveUsd !== undefined && Number.isFinite(takenUsd) && Number.isFinite(reserveUsd) && takenUsd + reserveUsd > capUsd;
|
package/dist/tool-gate.d.ts
CHANGED
|
@@ -39,15 +39,17 @@ export declare const SHELL_WATCHERS: ReadonlySet<string>;
|
|
|
39
39
|
/** The settings keys that may set `name`'s permission, most specific first: the tool's own name, then, for an MCP
|
|
40
40
|
* tool, its server's wildcard `mcp:<server>/*`. */
|
|
41
41
|
export declare function permissionKeys(name: string): string[];
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
/** A session's `{name -> settings key}` map (nameMapOf). */
|
|
43
|
+
export type NameMap = ReadonlyMap<string, string>;
|
|
44
|
+
/** Every name a session on `harness` (with MCP servers `mcpServers`) gives its tools, to the settings key each is held to:
|
|
45
|
+
* the shell family (bash's), table, own and decision tools, read_skill_file (`read`, unless the harness's alias makes it a
|
|
46
|
+
* configured server's tool), the kinds' tools (a shared one by its first kind), nativeTools, the browser's registrations;
|
|
47
|
+
* each also as claude-agent's `mcp__hands__<name>`. The first named wins. */
|
|
48
|
+
export declare function nameMapOf(harness: string, mcpServers?: readonly string[]): NameMap;
|
|
49
|
+
/** The settings key a call named `name` on `harness` is held to: a lookup in the session's names (`names`), then the open
|
|
50
|
+
* families no list holds (`monid.<tool>`, `mcp:<server>/<tool>`, `mcp__<server>__<tool>`, `monid_<kind>`, and a harness's
|
|
51
|
+
* own `<server>_<tool>` for a server of `mcpServers` only). Undefined: nothing maps it, and the gate asks. */
|
|
52
|
+
export declare function settingsKeyOf(harness: string, name: string, mcpServers?: readonly string[], names?: NameMap): string | undefined;
|
|
51
53
|
/** A pinned argument's scalar: `null` holds for a call that leaves the argument out (or gives null). */
|
|
52
54
|
export type PinScalar = string | number | boolean | null;
|
|
53
55
|
/** A pinned argument's value: one scalar the call must carry, or a list of 1 to MAX_PIN_CHOICES ("one of"), kept and
|
|
@@ -165,6 +167,9 @@ export declare const RESUME_PREFIX = "[tool approval] ";
|
|
|
165
167
|
* runs.ts) cut again at 300 characters, and the words that say it is not the person's. The one source of it: the resume
|
|
166
168
|
* writes it, and the Timeline strips exactly it from the row a person opens (runs.ts resumeShows). */
|
|
167
169
|
export declare function resumeHead(request: Pick<ApprovalRequest, "tool" | "call_id">, shown: string): string;
|
|
170
|
+
/** The last line of a CLI's resume message (one, after every call it answers): the message arrives as a new turn, and a
|
|
171
|
+
* model that reads only results there answers about the approval, not the person's request (Claude Code, live). */
|
|
172
|
+
export declare const RESUME_GO_ON = "Go on with the person's request from where you stopped, using these results; don't call these tools again for them.";
|
|
168
173
|
export declare function resumeText(request: Pick<ApprovalRequest, "tool" | "call_id">, shown: string, decision: "allow" | "deny", result: ToolAnswer): string;
|
|
169
174
|
/** The gate of the run `runId` whose folder is `where`, on its pinned revision. `serverSettings`: the server's tool
|
|
170
175
|
* settings as the runner read them from the one store at the claim (tool-plane.ts loadToolSettings), read at each call as
|
|
@@ -205,6 +210,7 @@ export declare class RunGate {
|
|
|
205
210
|
mcpServers?: readonly string[];
|
|
206
211
|
computer?: boolean;
|
|
207
212
|
}, readServerSettings: () => ToolSettingsRead, overrides?: PermissionSettings, approvers?: boolean, approvals?: Approvals);
|
|
213
|
+
private names?;
|
|
208
214
|
/** A tool's permission now (permissionOf): the revision's own over the server's setting, read at each call, so a change
|
|
209
215
|
* reaches a live run at its next call; under approvals "never", an ask is an allow. */
|
|
210
216
|
readonly policy: (tool: string) => Permission;
|
|
@@ -221,6 +227,7 @@ export declare class RunGate {
|
|
|
221
227
|
}): Promise<"allow" | "ask" | {
|
|
222
228
|
deny: string;
|
|
223
229
|
}>;
|
|
230
|
+
private keyOf;
|
|
224
231
|
/** The name a call is asked about by, as main's request names it (enter's `tool`): its settings key, a shell tool its
|
|
225
232
|
* own name; a name nothing maps, as it came. */
|
|
226
233
|
askedAs(name: string): string;
|
package/dist/tool-gate.js
CHANGED
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
// wins; the same answer again is 204, a conflicting one 409. Only the owner's password session answers (server.ts), never
|
|
23
23
|
// a token. A cancel marks pending approvals canceled. Where no one can approve (accounts off), an ask is refused at once
|
|
24
24
|
// in words, never parked.
|
|
25
|
-
import {
|
|
25
|
+
import { CODEMODE_TOOL_NAME } from "@earendil-works/pi-durable/codemode";
|
|
26
|
+
import { computerToolDefs, defaultPermissionOf } from "@parcha/agentrun-kernel/kernel";
|
|
26
27
|
import { READ_SKILL_FILE } from "@parcha/agentrun-kernel";
|
|
27
28
|
import { LEARNED_DIR } from "./learning.js";
|
|
28
29
|
import { COMPUTER_ROOT, portPath } from "./workspace/paths.js";
|
|
29
30
|
import { builtinHarness } from "./harness-table.js";
|
|
30
31
|
import { DEFAULT_HARNESS } from "./harness.js";
|
|
31
32
|
import { SHELL_TOOLS } from "./background.js";
|
|
32
|
-
import { SERVE_OWN_TOOLS, TABLE_TOOLS } from "./tool-plane.js";
|
|
33
|
+
import { DECISION_PROVIDER_KEYS, SERVE_OWN_TOOLS, TABLE_TOOLS } from "./tool-plane.js";
|
|
33
34
|
import { deniedText, NOT_RUN, RAN_UNKNOWN } from "./refusal-words.js";
|
|
34
35
|
import { approvalsOf } from "./approvals.js";
|
|
35
36
|
import { BASH_POLICIES, readOnlyReason, readOnlyText } from "./bash-read-only.js";
|
|
@@ -83,54 +84,56 @@ const BROWSER_REGISTRATIONS = ["snapshot", "run", "screenshot", "browser_read",
|
|
|
83
84
|
* registry's own definitions say it (their settingsKey), so a tool a kind gains is held to its key with no line here. */
|
|
84
85
|
const KIND_TOOLS = (() => {
|
|
85
86
|
const keys = new Map();
|
|
86
|
-
for (const def of [...
|
|
87
|
+
for (const def of [...computerToolDefs("desktop", []), ...computerToolDefs("phone", [])])
|
|
87
88
|
keys.set(def.name, [...new Set([...(keys.get(def.name) ?? []), def.settingsKey])]);
|
|
89
|
+
// pi's code mode, offered only beside a desktop's or a phone's tools (runner/adapters/pi-computer.ts): its scripts
|
|
90
|
+
// reach the computer as computer_script's do, so it is held to the same keys. Its nested tool calls pass the gate each.
|
|
91
|
+
keys.set(CODEMODE_TOOL_NAME, keys.get("computer_script") ?? []);
|
|
88
92
|
return keys;
|
|
89
93
|
})();
|
|
90
94
|
const STRICTNESS = { allow: 0, ask: 1, deny: 2 };
|
|
91
95
|
/** The MCP server through which claude-agent calls the kernel's host tools (`mcp__hands__<wire name>`). */
|
|
92
96
|
const HOST_TOOLS_SERVER = "hands";
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
/** Every name a session on `harness` (with MCP servers `mcpServers`) gives its tools, to the settings key each is held to:
|
|
98
|
+
* the shell family (bash's), table, own and decision tools, read_skill_file (`read`, unless the harness's alias makes it a
|
|
99
|
+
* configured server's tool), the kinds' tools (a shared one by its first kind), nativeTools, the browser's registrations;
|
|
100
|
+
* each also as claude-agent's `mcp__hands__<name>`. The first named wins. */
|
|
101
|
+
export function nameMapOf(harness, mcpServers = []) {
|
|
102
|
+
const facts = builtinHarness(harness)?.facts;
|
|
103
|
+
const names = new Map();
|
|
104
|
+
const name = (own, key) => void (names.has(own) || names.set(own, key));
|
|
105
|
+
for (const [own, key] of Object.entries(SHELL_FAMILY))
|
|
106
|
+
name(own, key);
|
|
107
|
+
for (const own of [...TABLE_TOOLS, ...SERVE_OWN_TOOLS, ...DECISION_PROVIDER_KEYS])
|
|
108
|
+
name(own, own);
|
|
109
|
+
const alias = facts?.toolAlias?.exec(READ_SKILL_FILE) ?? null;
|
|
110
|
+
name(READ_SKILL_FILE, alias && mcpServers.includes(alias[1]) ? mcpToolName(alias[1], alias[2]) : "read");
|
|
111
|
+
for (const [own, keys] of KIND_TOOLS)
|
|
112
|
+
name(own, keys[0]);
|
|
113
|
+
for (const [own, key] of Object.entries(facts?.nativeTools ?? {}))
|
|
114
|
+
if (key)
|
|
115
|
+
name(own, key);
|
|
116
|
+
for (const own of BROWSER_REGISTRATIONS)
|
|
117
|
+
name(own, "browser");
|
|
118
|
+
for (const [own, key] of [...names])
|
|
119
|
+
name(`mcp__${HOST_TOOLS_SERVER}__${own}`, key);
|
|
120
|
+
return names;
|
|
121
|
+
}
|
|
122
|
+
/** The settings key a call named `name` on `harness` is held to: a lookup in the session's names (`names`), then the open
|
|
123
|
+
* families no list holds (`monid.<tool>`, `mcp:<server>/<tool>`, `mcp__<server>__<tool>`, `monid_<kind>`, and a harness's
|
|
124
|
+
* own `<server>_<tool>` for a server of `mcpServers` only). Undefined: nothing maps it, and the gate asks. */
|
|
125
|
+
export function settingsKeyOf(harness, name, mcpServers = [], names = nameMapOf(harness, mcpServers)) {
|
|
126
|
+
const own = names.get(name);
|
|
127
|
+
if (own !== undefined)
|
|
128
|
+
return own;
|
|
129
|
+
if (isCatalogTool(name))
|
|
106
130
|
return name;
|
|
107
|
-
// An adapter's own read of a skill's file (codex's and OpenCode's read_skill_file, from the session's copy of the run's
|
|
108
|
-
// skills) is a read: held to read's key, so a server's read deny refuses it and the default allows it, on every harness.
|
|
109
|
-
// Unless the name is an agent's MCP tool on this harness (OpenCode's <server>_<tool>: a configured server `read` with a
|
|
110
|
-
// tool `skill_file`): that tool keeps its own key, so read's setting never stands in for it.
|
|
111
|
-
if (name === READ_SKILL_FILE) {
|
|
112
|
-
const alias = builtinHarness(harness)?.facts?.toolAlias?.exec(name) ?? null;
|
|
113
|
-
return alias && mcpServers.includes(alias[1]) ? mcpToolName(alias[1], alias[2]) : "read";
|
|
114
|
-
}
|
|
115
|
-
// A desktop's or a phone's tool is its kind's key, as the browser's registrations are `browser`; one both kinds have
|
|
116
|
-
// (the hand-over) is named by the first, its permission the stricter of both (RunGate's setting).
|
|
117
|
-
const kind = KIND_TOOLS.get(name);
|
|
118
|
-
if (kind !== undefined)
|
|
119
|
-
return kind[0];
|
|
120
|
-
// A CLI's own tool, the table's tool it is (its facts' nativeTools), by an own name only.
|
|
121
|
-
const nativeTools = builtinHarness(harness)?.facts?.nativeTools;
|
|
122
|
-
const native = nativeTools && Object.hasOwn(nativeTools, name) ? nativeTools[name] : undefined;
|
|
123
|
-
if (native)
|
|
124
|
-
return native;
|
|
125
131
|
const mcp = /^mcp__([a-z][a-z0-9-]*)__(.+)$/.exec(name);
|
|
126
132
|
if (mcp)
|
|
127
|
-
return mcp[1] === HOST_TOOLS_SERVER ? settingsKeyOf(harness, mcp[2], mcpServers) : mcpToolName(mcp[1], mcp[2]);
|
|
133
|
+
return mcp[1] === HOST_TOOLS_SERVER ? settingsKeyOf(harness, mcp[2], mcpServers, names) : mcpToolName(mcp[1], mcp[2]);
|
|
128
134
|
const monid = /^monid_([a-z]+)$/.exec(name);
|
|
129
135
|
if (monid)
|
|
130
136
|
return `monid.${monid[1]}`;
|
|
131
|
-
if (BROWSER_REGISTRATIONS.includes(name))
|
|
132
|
-
return "browser";
|
|
133
|
-
// A harness whose client names a session's MCP tool another way too (its facts' toolAlias: OpenCode's `<server>_<tool>`).
|
|
134
137
|
const alias = builtinHarness(harness)?.facts?.toolAlias?.exec(name) ?? null;
|
|
135
138
|
return alias && mcpServers.includes(alias[1]) ? mcpToolName(alias[1], alias[2]) : undefined;
|
|
136
139
|
}
|
|
@@ -315,6 +318,9 @@ export function resumeHead(request, shown) {
|
|
|
315
318
|
const args = shown.length > 300 ? `${shown.slice(0, 299)}…` : shown;
|
|
316
319
|
return `${RESUME_PREFIX}This answers your ${request.tool} call ${request.call_id} (arguments ${args}), which waited for a person's approval; it is not a new message from them.`;
|
|
317
320
|
}
|
|
321
|
+
/** The last line of a CLI's resume message (one, after every call it answers): the message arrives as a new turn, and a
|
|
322
|
+
* model that reads only results there answers about the approval, not the person's request (Claude Code, live). */
|
|
323
|
+
export const RESUME_GO_ON = "Go on with the person's request from where you stopped, using these results; don't call these tools again for them.";
|
|
318
324
|
export function resumeText(request, shown, decision, result) {
|
|
319
325
|
const head = resumeHead(request, shown);
|
|
320
326
|
return decision === "allow" ? `${head} They allowed it, and it ran${result.isError ? " and failed" : ""}. Its result:\n${result.text}` : `${head}\n${result.text}`;
|
|
@@ -344,6 +350,7 @@ export class RunGate {
|
|
|
344
350
|
this.approvers = approvers;
|
|
345
351
|
this.approvals = approvals;
|
|
346
352
|
}
|
|
353
|
+
names;
|
|
347
354
|
/** A tool's permission now (permissionOf): the revision's own over the server's setting, read at each call, so a change
|
|
348
355
|
* reaches a live run at its next call; under approvals "never", an ask is an allow. */
|
|
349
356
|
policy = (tool) => this.setting(tool).permission;
|
|
@@ -356,7 +363,7 @@ export class RunGate {
|
|
|
356
363
|
* the call is run again after an earlier attempt that may have been sent (a replay-safe call rerun after a crash), so a
|
|
357
364
|
* refusal says whether it took effect is not known, never that nothing was sent. */
|
|
358
365
|
async decide(name, args, options = {}) {
|
|
359
|
-
const key =
|
|
366
|
+
const key = this.keyOf(name) ?? name;
|
|
360
367
|
const tool = this.askedAs(name);
|
|
361
368
|
const ran = options.replayed ? "unknown" : "no";
|
|
362
369
|
const verdict = this.policy(name);
|
|
@@ -372,22 +379,26 @@ export class RunGate {
|
|
|
372
379
|
return "allow";
|
|
373
380
|
return this.approvers ? "ask" : { deny: noApproverText(tool, ran) };
|
|
374
381
|
}
|
|
382
|
+
keyOf(name) {
|
|
383
|
+
const harness = this.where.harness ?? DEFAULT_HARNESS;
|
|
384
|
+
return settingsKeyOf(harness, name, this.where.mcpServers, (this.names ??= nameMapOf(harness, this.where.mcpServers)));
|
|
385
|
+
}
|
|
375
386
|
/** The name a call is asked about by, as main's request names it (enter's `tool`): its settings key, a shell tool its
|
|
376
387
|
* own name; a name nothing maps, as it came. */
|
|
377
388
|
askedAs(name) {
|
|
378
|
-
return shellToolOf(name) ??
|
|
389
|
+
return shellToolOf(name) ?? this.keyOf(name) ?? name;
|
|
379
390
|
}
|
|
380
391
|
/** Where the permission `policy` gives `tool` was set: the agent's own tool settings, the server's, or the default; or
|
|
381
392
|
* "unattended", an ask the agent's approvals allowed. */
|
|
382
393
|
denyFrom = (tool) => this.setting(tool).from;
|
|
383
394
|
setting(tool) {
|
|
384
|
-
// A tool the desktop and the phone both have (
|
|
395
|
+
// A tool the desktop and the phone both have (every computer tool): the gate knows not the run's kind, so it is held to the
|
|
385
396
|
// stricter of both keys' settings, never more permissive than the run's own kind's.
|
|
386
397
|
const shared = KIND_TOOLS.get(tool.replace(/^mcp__hands__/, ""));
|
|
387
398
|
if (shared && shared.length > 1) {
|
|
388
399
|
return shared.map((key) => this.settingOf(tool, key)).reduce((strictest, one) => (STRICTNESS[one.permission] > STRICTNESS[strictest.permission] ? one : strictest));
|
|
389
400
|
}
|
|
390
|
-
return this.settingOf(tool,
|
|
401
|
+
return this.settingOf(tool, this.keyOf(tool));
|
|
391
402
|
}
|
|
392
403
|
/** `tool`'s permission under its settings key `key`, and where it was set. */
|
|
393
404
|
settingOf(tool, key) {
|
package/dist/tool-plane.d.ts
CHANGED
|
@@ -39,9 +39,9 @@ export declare const permissionsOf: (name: string) => readonly Permission[];
|
|
|
39
39
|
* give it: the one in force under the server's settings (`permission`), the owner's default (`default_permission`) and
|
|
40
40
|
* those it may be set to. An agent's read gives the same, the agent's own layer over it (agentTools). */
|
|
41
41
|
export declare const serverGate: (name: string, settings: ToolSettingsMap) => {
|
|
42
|
-
permission: "deny" | "
|
|
43
|
-
default_permission: "deny" | "
|
|
44
|
-
permissions: ("deny" | "
|
|
42
|
+
permission: "deny" | "ask" | "allow";
|
|
43
|
+
default_permission: "deny" | "ask" | "allow";
|
|
44
|
+
permissions: ("deny" | "ask" | "allow")[];
|
|
45
45
|
};
|
|
46
46
|
/** The run's own tools beyond the table, each its own settings key, allowed by default like a table tool: the learned
|
|
47
47
|
* workflow a run's pin names runs as `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL). */
|
|
@@ -50,6 +50,10 @@ export declare const SERVE_OWN_TOOLS: readonly string[];
|
|
|
50
50
|
* held to `desktop`, every phone tool to `phone` (the kernel registry's definitions name the key; tool-gate.ts
|
|
51
51
|
* settingsKeyOf reads it there). Allowed by default like a table tool; allow or deny. */
|
|
52
52
|
export declare const KIND_KEYS: readonly string[];
|
|
53
|
+
/** A decision provider's settings key, its bare id (decisions.ts' providers: Jev, Parallel, OpenRouter's Decisions
|
|
54
|
+
* models): what an agent's learned workflow's decision nodes may ask (learned-workflow.ts, LS-07), and whose keys the
|
|
55
|
+
* runner hands its claim. Allowed by default; allow or deny. A workflow agent's own decisions read no setting of it. */
|
|
56
|
+
export declare const DECISION_PROVIDER_KEYS: readonly string[];
|
|
53
57
|
/** One tool's settings: its provider (a capability that has a choice), its permission, and an MCP tool's pin (the
|
|
54
58
|
* arguments its calls must carry, tool-gate.ts pinRefusal). */
|
|
55
59
|
export type ToolSetting = {
|
|
@@ -275,17 +279,17 @@ export declare function shellUnavailable(name: string, shell: ShellPlace): Resol
|
|
|
275
279
|
* computer setting); a tool of bash's family that leaves out resolves unavailable, saying why (shellUnavailable). */
|
|
276
280
|
export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, agent: Tooling, order: readonly string[], shell?: ShellPlace): ({
|
|
277
281
|
resolved: Resolution;
|
|
278
|
-
permission: "deny" | "
|
|
282
|
+
permission: "deny" | "ask" | "allow";
|
|
279
283
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
280
|
-
default_permission: "deny" | "
|
|
281
|
-
permissions: ("deny" | "
|
|
284
|
+
default_permission: "deny" | "ask" | "allow";
|
|
285
|
+
permissions: ("deny" | "ask" | "allow")[];
|
|
282
286
|
blurb?: string | undefined;
|
|
283
287
|
name: string;
|
|
284
288
|
} | {
|
|
285
|
-
permission: "deny" | "
|
|
289
|
+
permission: "deny" | "ask" | "allow";
|
|
286
290
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
287
|
-
default_permission: "deny" | "
|
|
288
|
-
permissions: ("deny" | "
|
|
291
|
+
default_permission: "deny" | "ask" | "allow";
|
|
292
|
+
permissions: ("deny" | "ask" | "allow")[];
|
|
289
293
|
blurb?: string | undefined;
|
|
290
294
|
name: string;
|
|
291
295
|
} | {
|
|
@@ -293,10 +297,10 @@ export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSetting
|
|
|
293
297
|
provider_from: string;
|
|
294
298
|
default_provider: string;
|
|
295
299
|
resolved: Resolution;
|
|
296
|
-
permission: "deny" | "
|
|
300
|
+
permission: "deny" | "ask" | "allow";
|
|
297
301
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
298
|
-
default_permission: "deny" | "
|
|
299
|
-
permissions: ("deny" | "
|
|
302
|
+
default_permission: "deny" | "ask" | "allow";
|
|
303
|
+
permissions: ("deny" | "ask" | "allow")[];
|
|
300
304
|
blurb?: string | undefined;
|
|
301
305
|
name: string;
|
|
302
306
|
})[];
|