diff --git a/.changeset/tool-docs-10e-1.md b/.changeset/tool-docs-10e-1.md new file mode 100644 index 000000000..d4dfba213 --- /dev/null +++ b/.changeset/tool-docs-10e-1.md @@ -0,0 +1,5 @@ +--- +"@agentproto/runtime": patch +--- + +Document the sandbox, tunnels, remote, llm-endpoint and decision tool families (32 tools leave the legacy undocumented list). diff --git a/packages/runtime/src/tool-docs/decision.ts b/packages/runtime/src/tool-docs/decision.ts new file mode 100644 index 000000000..3168f10f6 --- /dev/null +++ b/packages/runtime/src/tool-docs/decision.ts @@ -0,0 +1,170 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `decision-tools.ts` (`decision_decide`), `decision-workflow-tools.ts` + * (the seven stage tools), `workflows/decision-route/` (the shipped workflow and + * its example DECISION.md). + */ +export const decisionToolDoc = defineToolFamilyDoc({ + family: "decision", + title: "Decision router: closed-set choices from a DECISION.md policy", + summary: + "Resolve one closed choice from a policy plus evidence (rules, one classifier call, conservative default), or run it as the staged review-routing workflow.", + whenToUse: [ + "Pick one of a few declared choices from evidence, with rules that a classifier cannot downgrade.", + "Route a code change to the right review binding (light, standard or deep) with a recorded trace.", + ], + workflow: [ + "One decision: `decision_decide` with the policy text and an evidence object. It never mutates anything.", + "Staged routing: run the `decision-route` workflow, or call the stages in order, each fed with the previous result: `decision_collect_evidence`, `decision_stage_rules`, `decision_stage_classify`, `decision_stage_escalate`, `decision_select_review`, `decision_run_review`, `decision_validate_verdict`.", + "Read `approved` only from `decision_validate_verdict`; every other state (shadow, timeout, provider-unavailable, incomplete) is not an approval.", + ], + cliCommands: [], + seeAlso: ["review", "workflows"], + tools: { + decision_decide: { + effect: "read", + examples: [ + { + label: "Decide from a policy and evidence", + args: { + policy: "---\nschema: 1\nname: review-router\nversion: 1\nchoices: [light, standard, deep]\ndefault: deep\n...\n---\n", + evidence: { changeTypes: ["docs-only"], riskCategories: [] }, + }, + outcome: "Returns `{ choice, source, matchedRules, status, ... }`. Here a docs-only rule would settle it with zero model calls.", + }, + ], + returns: "`choice`, `source` (rule, rule-floor, classifier, escalation or default), `status` (`decided` or `fallback`), `matchedRules`, `probabilities`, `confidence`, hashes.", + pitfalls: [ + "A malformed policy comes back as `{ ok: false, errors }`, not as a tool error; a failed classification gives `status: \"fallback\"` with the policy's default.", + "`fallback` is a safe answer, not a trusted one, and is never cached.", + "Paths, code and messages are removed from the evidence before the classifier unless the policy's evidence section allows them. No harness escalation runs here.", + "The classifier needs a Jev API key; without one the call degrades to the default.", + ], + }, + decision_collect_evidence: { + effect: "read", + examples: [ + { + label: "Evidence for a git range", + args: { cwd: "/path/to/repo", policyPath: "DECISION.md", base: "origin/main", head: "HEAD" }, + outcome: "Returns `{ ok, policy, evidence, range, complete, withheld, notes, trace }`: counts, change types and risk categories, never code.", + }, + { + label: "Consumer-built evidence", + args: { cwd: "/path/to/repo", policy: "", supplied: { changeTypes: ["docs-only"] } }, + outcome: "Same export policy applied to the evidence you supply.", + }, + ], + returns: "`evidence` and `policy` to pass to the next stages; `complete: false` means classifier scores will not be trusted.", + pitfalls: [ + "Pass `policy` or `policyPath`; neither is `{ ok: false }`. Stage failures are data, never MCP errors.", + "Paths appear only if the policy's evidence section allows them; secrets are scrubbed.", + ], + }, + decision_stage_rules: { + effect: "read", + examples: [ + { + label: "Apply the rules, no model call", + args: { policy: "", evidence: { riskCategories: ["security"] } }, + outcome: "Returns `{ ok, settled, decision, trace }`; `settled: true` when a rule decided.", + }, + ], + returns: "`settled`, `decision`; pass `decision` along as `rules`.", + }, + decision_stage_classify: { + effect: "external", + examples: [ + { + label: "Classify an unresolved case", + args: { policy: "", evidence: { changeTypes: ["code"] }, rules: { ok: true, settled: false } }, + outcome: "Returns `{ ok, settled, decision, trace }`; skipped (no model call) when the rules settled it, the policy disables the classifier or the profile disables Jev.", + }, + ], + returns: "`settled`, `decision`; pass the whole result along as `classify`.", + pitfalls: [ + "One call, no retries. Low confidence is not a human request: it flows to escalation.", + "It sends the bounded evidence to the Jev API when the profile allows it.", + ], + }, + decision_stage_escalate: { + effect: "external", + examples: [ + { + label: "Escalate a still-unresolved case under the free profile", + args: { + policy: "", + profile: "local-free", + evidence: { changeTypes: ["code"] }, + classify: { ok: true, settled: false }, + rules: { ok: true, settled: false }, + }, + outcome: "Returns `{ ok, settled, decision, escalation, trace }`; no session is spawned when already settled.", + }, + ], + returns: "`settled`, `decision`, `escalation` (status, wait, `toolControls`).", + pitfalls: [ + "At most one harness session, spawned read-only with no MCP servers. The harness's own built-in tools stay available: `toolControls` reports what is configured versus enforced.", + "The profile validates the adapter and model before any spawn; an unknown identity fails closed, and placement (a sandbox) grants no entitlement.", + "If the escalation session asks for human input, nobody answers it here: the result is `wait: \"human-input-required\"` and the policy default applies, so there is no human gate to wait on.", + "`profile` is `local-free` (default) or `remote-sonnet`; `profileOptions` narrows targets and budgets but cannot change the entitlement. `profileOptions.escalation.adapter` is a deprecated alias of `harness`.", + ], + }, + decision_select_review: { + effect: "read", + examples: [ + { + label: "Map the choice to a review binding", + args: { policy: "", escalate: { ok: true, settled: true }, cwd: "/path/to/repo" }, + outcome: "Returns `{ ok, ready, state, choice, binding, targets, trace }`.", + }, + ], + returns: "`binding` and `targets`; pass the whole result along as `select`.", + pitfalls: [ + "Default bindings: skip and light map to `light`, standard to `local`, deep to `deep`; `freeBindings` overrides under a free-only profile (deep becomes `deep-free`).", + "Every reviewer, fallback and recovery preset of the binding is preflighted against the profile; one non-entitled target refuses the whole selection and nothing is substituted.", + ], + }, + decision_run_review: { + effect: "external", + examples: [ + { + label: "Shadow run (default): report only", + args: { policy: "", select: { ok: true, ready: true, binding: "local" }, cwd: "/path/to/repo" }, + outcome: "Returns `{ ok, mode: \"shadow\", ... }` saying which binding would run; no review lane is spawned.", + }, + { + label: "Enforce", + args: { policy: "", select: { ok: true, ready: true, binding: "local" }, cwd: "/path/to/repo", mode: "enforce" }, + outcome: "Starts the review with a profile deadline and returns `review` ({ runId, status, verdict, lanes, durationMs }).", + }, + ], + returns: "`state`, `review.verdict`; pass the whole result along as `review`.", + pitfalls: [ + "Only `mode: \"enforce\"` starts anything; the review is cancelled on the deadline or on abort.", + "`nocache: true` skips a cached review result.", + ], + }, + decision_validate_verdict: { + effect: "read", + examples: [ + { + label: "Fold everything into one report", + args: { + policy: "", + escalate: { ok: true, settled: true }, + select: { ok: true, binding: "local" }, + review: { ok: true, mode: "enforce", state: "done" }, + }, + outcome: "Returns `{ ok, approved, state, reason, verdict, choice, binding, violations, trace }`.", + }, + ], + returns: "`approved` and `state`.", + pitfalls: [ + "`approved` is true only for a real passing verdict from lanes that stayed inside the profile. completed, provider-unavailable, human-input-required, incomplete, timeout, cancelled, refused, failed and shadow are separate states, never approvals.", + "A blocking finding stops the flow: no other model is asked to approve it.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/index.ts b/packages/runtime/src/tool-docs/index.ts index b37dcd603..b7f59cd1d 100644 --- a/packages/runtime/src/tool-docs/index.ts +++ b/packages/runtime/src/tool-docs/index.ts @@ -45,6 +45,11 @@ import { mcpAppsToolDoc } from "./mcp-apps.js" import { mcpImportToolDoc } from "./mcp-import.js" import { skillImportToolDoc } from "./skill-import.js" import { toolAuthoringToolDoc } from "./tool-authoring.js" +import { decisionToolDoc } from "./decision.js" +import { llmEndpointToolDoc } from "./llm-endpoint.js" +import { remoteToolDoc } from "./remote.js" +import { sandboxToolDoc } from "./sandbox.js" +import { tunnelsToolDoc } from "./tunnels.js" import type { ToolFamilyDoc } from "./types.js" import { worktreeToolDoc } from "./worktree.js" @@ -61,6 +66,11 @@ export type { } from "./types.js" export const TOOL_FAMILY_DOCS: readonly ToolFamilyDoc[] = [ + tunnelsToolDoc, + sandboxToolDoc, + remoteToolDoc, + llmEndpointToolDoc, + decisionToolDoc, authProfileToolDoc, catalogToolDoc, harnessToolDoc, diff --git a/packages/runtime/src/tool-docs/legacy.ts b/packages/runtime/src/tool-docs/legacy.ts index 3563c41c7..5d3a16777 100644 --- a/packages/runtime/src/tool-docs/legacy.ts +++ b/packages/runtime/src/tool-docs/legacy.ts @@ -35,14 +35,6 @@ export const LEGACY_UNDOCUMENTED_TOOLS: readonly DaemonToolName[] = [ "conversation_locate", "conversation_read", "daemon_health", - "decision_collect_evidence", - "decision_decide", - "decision_run_review", - "decision_select_review", - "decision_stage_classify", - "decision_stage_escalate", - "decision_stage_rules", - "decision_validate_verdict", "directory_create", "directory_list", "fetch_page", @@ -58,23 +50,8 @@ export const LEGACY_UNDOCUMENTED_TOOLS: readonly DaemonToolName[] = [ "inbound_watcher_start", "inbound_watcher_stop", "live_session", - "llm_endpoint_list_links", - "llm_endpoint_set_upstream_link", - "llm_endpoint_start", - "llm_endpoint_status", - "llm_endpoint_stop", "reach_send", - "remote_disable", - "remote_enable", - "remote_status", "role_list", - "sandbox_attach", - "sandbox_checkpoint_gc", - "sandbox_checkpoint_gc_status", - "sandbox_egress_health", - "sandbox_exec", - "sandbox_gc", - "sandbox_list", "self_inspect", "telegram_bot_set_webhook", "telegram_bot_token_set", @@ -84,15 +61,6 @@ export const LEGACY_UNDOCUMENTED_TOOLS: readonly DaemonToolName[] = [ "transcript_read", "transcript_search", "transmit_message", - "tunnel_add_hostname", - "tunnel_create", - "tunnel_delete", - "tunnel_list", - "tunnel_login", - "tunnel_remove_hostname", - "tunnel_revoke", - "tunnel_status", - "tunnel_stop", "usage_rollup", "workspace_brain_ingest", "workspace_brain_query", diff --git a/packages/runtime/src/tool-docs/llm-endpoint.ts b/packages/runtime/src/tool-docs/llm-endpoint.ts new file mode 100644 index 000000000..83d6868bd --- /dev/null +++ b/packages/runtime/src/tool-docs/llm-endpoint.ts @@ -0,0 +1,105 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `llm-endpoint-tools.ts` (every tool), `llm-endpoint-links-store.ts` + * (canonical upstreams). + */ +export const llmEndpointToolDoc = defineToolFamilyDoc({ + family: "llm-endpoint", + title: "LLM endpoint: the local inference proxy sidecar", + summary: + "Start, stop and inspect the inference-endpoint proxy the daemon supervises, and link each of its upstreams to an auth profile.", + whenToUse: [ + "Run the OpenAI-compatible proxy on this machine without starting it by hand.", + "Make an upstream authenticate from a named auth profile instead of a bare environment key.", + ], + workflow: [ + "`llm_endpoint_status` to see whether it runs and is healthy.", + "`llm_endpoint_list_links` shows each upstream, its linked profile and the eligible profiles; `llm_endpoint_set_upstream_link` links one.", + "`llm_endpoint_start` (after `llm_endpoint_stop` when links changed), because links are read only when the proxy is spawned.", + ], + cliCommands: [], + seeAlso: ["agentproto-llm-endpoint"], + tools: { + llm_endpoint_start: { + effect: "external", + examples: [ + { + label: "Start on the default port", + args: {}, + outcome: "Spawns the proxy (port 18090 unless `LLM_ENDPOINT_PORT` is set) and returns `{ pid, port, baseUrl, status, startedAt }` once ready.", + }, + { + label: "Start behind an access token", + args: { port: 18091, accessTokens: "" }, + outcome: "The proxy requires that bearer token on inbound requests.", + }, + ], + returns: "`baseUrl` and `port` to point clients at, `pid`, `status`.", + pitfalls: [ + "Idempotent: when the proxy is already running and healthy, the existing descriptor is returned and nothing is respawned, so new `port`, `accessTokens` or `env` are not applied. Stop first.", + "Without `accessTokens` the proxy is open; it also carries the stored provider keys, so bind it only where that is acceptable.", + "Explicit `env` wins over the injected provider keys and the port default.", + ], + }, + llm_endpoint_stop: { + effect: "write", + examples: [ + { label: "Stop the proxy", args: {}, outcome: "Returns `{ ok }` after SIGTERM to the child; idempotent when it is not running." }, + ], + returns: "`ok`.", + }, + llm_endpoint_status: { + effect: "read", + examples: [ + { + label: "Probe it", + args: {}, + outcome: "Returns `{ running, pid, port, baseUrl, healthy, startedAt }`; `healthy` comes from a live `GET /v1/models`.", + }, + ], + returns: "`running`, `healthy`, `baseUrl`.", + }, + llm_endpoint_list_links: { + effect: "read", + examples: [ + { + label: "Links and eligible profiles", + args: {}, + outcome: "Returns `{ links, upstreams }`: `links` maps provider to profile id; each upstream row has `provider`, `linkedProfile` and `eligible` ({ id, label, method, endpoint }).", + }, + { + label: "Paged, full profile metadata", + args: { full: true, limit: 5 }, + outcome: "Pages the rows with the whole non-secret profile metadata. Never a secret.", + }, + ], + returns: "Upstream names to pass as `provider` and eligible profile ids to pass as `profileId`.", + pitfalls: [ + "It reports the persisted link; a running proxy may lag until restarted.", + "A profile is eligible when its endpoint equals the upstream, it is not disabled, and its method fits (`oauth-bearer` only for `anthropic`).", + ], + }, + llm_endpoint_set_upstream_link: { + effect: "write", + examples: [ + { + label: "Link an upstream to an auth profile", + args: { provider: "anthropic", profileId: "team-primary" }, + outcome: "Persists the link and returns `{ ok: true, applied: false, restartRequired }`.", + }, + { + label: "Clear the link", + args: { provider: "anthropic", profileId: null }, + outcome: "Reverts that upstream to its environment key; `cleared` says whether a link existed.", + }, + ], + returns: "`restartRequired` (true when the proxy is running), `applied` (always false).", + pitfalls: [ + "It never restarts the proxy: the link is injected as an environment variable only at spawn.", + "The profile id is not checked for existence; a dangling link gives a 401 at request time.", + "`provider` must be a canonical upstream, and an account slot ref is refused: pass a real profile id from `auth_profile_list`.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/remote.ts b/packages/runtime/src/tool-docs/remote.ts new file mode 100644 index 000000000..8a2123531 --- /dev/null +++ b/packages/runtime/src/tool-docs/remote.ts @@ -0,0 +1,81 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `remote-tools.ts`, `remote-controller.ts` (enable, disable, status + * results), `docs/cli/verbs/remote.md` (CLI). + */ +export const remoteToolDoc = defineToolFamilyDoc({ + family: "remote", + title: "Remote: publish this daemon to the internet", + summary: + "Open one Cloudflare quick tunnel to the daemon's own MCP endpoint behind a bearer token (or to another local port), check it, and close it.", + whenToUse: [ + "Let a remote MCP client reach this daemon.", + "Tunnel another local service for a moment and take it down afterwards.", + ], + workflow: [ + "`remote_status` to see whether a tunnel is already up.", + "`remote_enable` returns the public URL and, for the gateway, the bearer token ONCE; store it.", + "To rotate the token, `remote_disable` then `remote_enable` again.", + ], + cliCommands: [ + { + verb: "remote", + command: "agentproto remote enable --qr", + note: "Same as `remote_enable`; `remote status` and `remote disable` map to the other two tools. `--qr` prints a phone link, which pairing (`pair_offer`) replaces.", + }, + ], + seeAlso: ["tunnels", "pairing"], + tools: { + remote_enable: { + effect: "external", + examples: [ + { + label: "Publish the gateway behind a bearer token", + args: {}, + outcome: + "Returns `publicUrl`, `bearerToken`, `mcpEndpoint` (the public URL plus `/mcp`) and `mcpConfigSnippet`, a paste-ready `.mcp.json` entry. The token is shown only now.", + }, + { + label: "Tunnel a different local service", + args: { targetPort: 5173, targetHost: "127.0.0.1" }, + outcome: "Returns `publicUrl` with `exposesGateway: false` and a `warning`: the daemon gates nothing on this URL.", + }, + ], + returns: "`publicUrl`, `bearerToken` and `mcpConfigSnippet` (gateway mode only), `exposesGateway`, `warning` (passthrough only).", + pitfalls: [ + "Calling it while a tunnel is up is an error: only the token hash is kept, so rotating means `remote_disable` first.", + "With `targetPort` set to another service, bearer auth is OFF and anyone with the URL reaches that service. Run `remote_disable` when done.", + "Phones do not need this: they pair end to end with `pair_offer`. `phoneLink: true` adds a `phoneUrl` with the bearer in the URL fragment, and Cloudflare can read that traffic.", + "Only the `quick` provider (an ephemeral URL) exists.", + ], + humanGate: { + when: "in gateway mode (no `targetPort`)", + action: + "The daemon asks nobody to confirm the exposure (the tool is gated only by the /mcp credential). The one-time `bearerToken` is shown once: the person who sets up the remote client must paste `mcpConfigSnippet` into it and store the token, or run `remote_disable` then `remote_enable` again to get a new one.", + }, + }, + remote_disable: { + effect: "write", + examples: [ + { + label: "Close the tunnel", + args: {}, + outcome: "Returns `{ disabled: true }`; bearer auth falls back to loopback only. `{ disabled: false }` when nothing was active.", + }, + ], + returns: "`disabled`.", + }, + remote_status: { + effect: "read", + examples: [ + { + label: "Check the tunnel", + args: {}, + outcome: "Returns `{ enabled, provider, publicUrl, pid, createdAt, target, exposesGateway, lastError }`, or `{ enabled: false, lastError }`.", + }, + ], + returns: "`enabled`, `publicUrl`, `exposesGateway`, `lastError`. The token is never returned.", + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/sandbox.ts b/packages/runtime/src/tool-docs/sandbox.ts new file mode 100644 index 000000000..bce159348 --- /dev/null +++ b/packages/runtime/src/tool-docs/sandbox.ts @@ -0,0 +1,181 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `session-tools.ts` (sandbox_list, sandbox_gc, sandbox_checkpoint_gc, + * sandbox_checkpoint_gc_status), `sandbox-attach.ts`, `sandbox-exec.ts` + * (limits), `egress-health-report.ts`, `docs/cli/verbs/sandbox.md` (CLI). + */ +export const sandboxToolDoc = defineToolFamilyDoc({ + family: "sandbox", + title: "Sandbox boxes: inventory, attach, one-shot exec and cleanup", + summary: + "List the boxes your sandbox providers hold, attach to one, run a single command in a box, read the egress address pool, and reap orphan boxes and stale checkpoint refs.", + whenToUse: [ + "Run one test gate or script in a throwaway or existing box without moving the whole agent session into it.", + "Find out which boxes a provider still holds (and charges for), then reap the orphans.", + "Get a durable, token-gated MCP descriptor for a box that already exists.", + "Clean up the `agentproto-checkpoint/*` refs a dead sandbox left on a repo's remote.", + ], + workflow: [ + "Call `list_sandbox_providers` (and `setup_sandbox_provider` if one needs credentials) to get a provider slug.", + "`sandbox_list` shows each box's provider and id; pass that `sandboxId` to `sandbox_exec` or `sandbox_attach`.", + "`sandbox_exec` without `sandboxId` boots an ephemeral box and always tears it down; with `sandboxId` it leaves the box as found.", + "`sandbox_gc` and `sandbox_checkpoint_gc` are dry runs until `apply: true`; review the candidates first. A long checkpoint sweep returns a `jobId` to poll with `sandbox_checkpoint_gc_status`.", + ], + cliCommands: [ + { + verb: "sandbox", + command: "agentproto sandbox list --json", + note: "Prints the daemon's sandbox ledger (boxes it booted, reconnected or paused). `sandbox rm ` forgets an entry and has no MCP tool.", + }, + { + verb: "sandbox", + command: "agentproto sandbox exec e2b --cwd /home/user -- npm test", + note: "Same as `sandbox_exec`; `attach`, `gc`, `checkpoint-gc` and `egress-health` map to the tools of the same name.", + }, + { + verb: "sandbox", + command: "agentproto sandbox egress-health --probe ", + note: "Re-probes every egress slot by booting one box each. The MCP tool only reads the stored state.", + }, + ], + seeAlso: ["worktree", "branch-gc"], + tools: { + sandbox_list: { + effect: "read", + examples: [ + { + label: "Every box of every concrete provider", + args: {}, + outcome: "Returns the deduplicated boxes tagged with their provider, plus `totals`, `notScanned` and `errors`.", + }, + { + label: "One provider with usage windows", + args: { providers: ["e2b"], includeUsage: true, from: "2026-11-30T00:00:00Z", to: "2026-12-01T00:00:00Z" }, + outcome: "Same list for `e2b`, joined with its usage windows; `totals` sums active, vcpu and gib seconds and EUR cost.", + }, + ], + returns: "Boxes (`provider`, `id`, state), `totals`, and per-provider `notScanned` / `errors`.", + pitfalls: [ + "A provider that is unavailable or cannot enumerate its boxes is reported in `notScanned` or `errors`; it never fails the call, so an empty list can mean \"not scanned\".", + "`totals.costPartial` is true when a window has no cost model: the cost sum is then a lower bound.", + "With `includeUsage` and no `from`/`to`, the window is the last 24 hours.", + ], + }, + sandbox_attach: { + effect: "write", + examples: [ + { + label: "Attach to an existing box and keep it awake", + args: { provider: "e2b", sandboxId: "", keepAlive: true }, + outcome: "Returns `{ descriptor, mcpConfig }`: the box's `mcpUrl`, a `token`, `authHeaders`, `allowOrigin`, plus a paste-ready `.mcp.json` entry.", + }, + ], + returns: "`descriptor.mcpUrl`, `descriptor.token` / `authHeaders` and `mcpConfig`. On failure `{ error, code }`.", + pitfalls: [ + "The descriptor carries a secret: treat `token`, `authHeaders` and `mcpConfig` as credentials and do not log or repeat them.", + "It resumes the box and never stops or pauses it. A provider that cannot return a token-gated URL is refused with `sandbox_attach_ungated` instead of handing out an open one.", + "Failure codes: `sandbox_provider_not_found`, `sandbox_no_connect` (the provider can only boot fresh boxes), `sandbox_attach_failed`, `sandbox_attach_ungated`.", + ], + }, + sandbox_exec: { + effect: "external", + examples: [ + { + label: "Run a test gate in a throwaway box", + args: { provider: "e2b", command: "npm test", cwd: "/home/user/repo", timeoutMs: 300000 }, + outcome: "Boots an ephemeral box, runs the command, tears the box down, and returns the exit code with captured stdout and stderr.", + }, + { + label: "Run in an existing box with a stored credential and a shipped script", + args: { + provider: "e2b", + sandboxId: "", + command: "bash /home/user/run.sh", + envProfiles: { API_TOKEN: "team-primary" }, + files: [{ path: "/home/user/run.sh", content: "echo ok\n" }], + }, + outcome: "Writes the file into the box, runs the command with `API_TOKEN` set from that auth profile, and leaves the box as found.", + }, + ], + returns: "The command's exit code, stdout and stderr (each truncated with a marker past 20000 characters).", + pitfalls: [ + "`cwd` is a path INSIDE the box, never a host path.", + "The command is limited to 16 KB, at most 32 `files` of 25 MB each are accepted, and env is limited to 32 KB: ship a large script with `files`.", + "Put secrets in `envProfiles` (an auth profile id per env name), not in `env`, which passes through your context. A name present in both is rejected, and device targets do not support `envProfiles`.", + "A non-zero exit code is a normal result, not a tool error. Without `timeoutMs` the command runs as long as the box lives.", + ], + }, + sandbox_egress_health: { + effect: "read", + examples: [ + { + label: "Read the egress pool and the cooldowns for one model", + args: { provider: "e2b", model: "" }, + outcome: "Returns the pool's slots (id, public IP, boxes in use) with the active per-IP model cooldowns narrowed to that model.", + }, + ], + returns: "The slots and the active cooldowns; `ok: false` marks an error result.", + pitfalls: [ + "It boots nothing, so it shows what was last learned. Re-probing every slot is the CLI `--probe` form and boots one box each.", + "A slot whose address is cooling down for a model is skipped when a box boots with `egressIp: auto`.", + ], + }, + sandbox_gc: { + effect: "external", + examples: [ + { + label: "Dry run: list the orphan boxes", + args: {}, + outcome: "Returns `{ applied: false, candidates, providerErrors, scanned, notScanned, deleted, failed }`; nothing is deleted.", + }, + { + label: "Delete the orphans, boxes with a still-attached session included", + args: { apply: true, includeAttached: true }, + outcome: "Deletes the candidates on their provider (forced) and lists them in `deleted` or `failed`.", + }, + ], + returns: "`candidates` (state, age, RAM when known), `deleted`, `failed`, `providerErrors`, `notScanned`.", + pitfalls: [ + "Only `computer` is swept by default. `e2b` is never swept, even when named, because its account is shared: it is reported in `notScanned`.", + "A box younger than the 15-minute grace window, or held by a live session, is never a candidate. `includeAttached` lifts only the check on a provider-side attached session.", + "`apply: true` is irreversible: the box and its data are destroyed.", + ], + }, + sandbox_checkpoint_gc: { + effect: "external", + examples: [ + { + label: "Dry run on the active workspace's repo", + args: { repoRoot: "/path/to/repo" }, + outcome: "Returns the plan: every `agentproto-checkpoint/*` ref classed `safe`, `keep` or `unknown`, with a `summary`.", + }, + { + label: "Delete the safe refs, in the background", + args: { repoRoot: "/path/to/repo", apply: true, wait: false }, + outcome: "Returns `{ jobId, status: \"running\" }` at once; poll it with `sandbox_checkpoint_gc_status`.", + }, + ], + returns: "The plan `summary` and refs, `applySummary` (deleted, skipped, failed) on an apply, `resultPath` of the full result, or a `jobId`.", + pitfalls: [ + "`repoRoot` wins over `workspaceSlug`; with neither, the active workspace is used. `remote` defaults to `origin`.", + "Only `safe` refs are ever deleted, and each is re-planned and re-classified just before its deletion. `keep` may be the only copy of some work.", + "`wait: false`, or `waitMs` expiring, switches to a background job. The tool is absent from a daemon started without a checkpoint gc runner.", + ], + }, + sandbox_checkpoint_gc_status: { + effect: "read", + examples: [ + { + label: "Poll a background sweep", + args: { jobId: "scg_" }, + outcome: "While running: status and elapsed time with `followUp.pollAfterMs`. When done: `summary`, `applySummary` and `resultPath`. When failed: the error.", + }, + ], + returns: "`status`, `summary`, `applySummary`, `resultPath`, `followUp.pollAfterMs` (30 s).", + pitfalls: [ + "A job from an earlier daemon run is read back from its result file on disk; a job id with neither a live job nor a file is an error.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/tunnels.ts b/packages/runtime/src/tool-docs/tunnels.ts new file mode 100644 index 000000000..b4cad8de9 --- /dev/null +++ b/packages/runtime/src/tool-docs/tunnels.ts @@ -0,0 +1,185 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `tunnel-tools.ts` (every tool except login), `tunnel-adapters.ts` + * (`tunnel_login`), `docs/cli/verbs/tunnel.md` (CLI). + */ +export const tunnelsToolDoc = defineToolFamilyDoc({ + family: "tunnels", + title: "Tunnels: a public HTTPS URL for a local port", + summary: + "Expose a local port through a tunnel provider, hand out a signed private link, revoke it, swap hostnames and tear the tunnel down.", + whenToUse: [ + "Show a local dev server or preview to someone outside this machine.", + "Give a webhook sender a stable hostname that reaches a local port.", + "Invalidate a link that leaked, or retire a tunnel.", + ], + workflow: [ + "`tunnel_list` first, to avoid a second tunnel for the same port.", + "`tunnel_create` with `targetPort`; hand out the returned `url` (publicUrl plus a signed token), never `publicUrl` alone. Providers that act on your behalf need `tunnel_login` first; keys are set with `setup_tunnel_provider`.", + "`tunnel_status` reads one tunnel by id or `name`; `tunnel_revoke` rotates a leaked link; `tunnel_stop` pauses; `tunnel_delete` also removes the provider's remote state.", + "For a hostname change on `cloudflare-managed`: `tunnel_add_hostname`, move the consumers, then `tunnel_remove_hostname`.", + ], + cliCommands: [ + { + verb: "tunnel", + command: "agentproto tunnel create --port 5173 --name vite-preview", + note: "Same as `tunnel_create`; `list`, `stop`, `login`, `add-hostname`, `remove-hostname`, `revoke` and `status` map to the tools of the same name.", + }, + { + verb: "tunnel", + command: "agentproto tunnel purge wa-relay", + note: "Same as `tunnel_delete` (the CLI `stop` alias `delete` is a plain stop).", + }, + ], + seeAlso: ["ap-tunnels", "remote"], + tools: { + tunnel_create: { + effect: "external", + examples: [ + { + label: "Private preview link (default)", + args: { targetPort: 5173, name: "vite-preview", ttl: "24h" }, + outcome: "Returns the TunnelDescriptor once ready (typically under 10 s) with `publicUrl` and `url`; only `url` carries the signed token.", + }, + { + label: "Stable hostname through a managed Cloudflare tunnel", + args: { targetPort: 3040, provider: "cloudflare-managed", hostname: "relay.example.com", autostart: true }, + outcome: "The daemon creates the tunnel, its ingress and the DNS record; `tunnel_status` then reports `health`.", + }, + { + label: "Deliberately public", + args: { targetPort: 8080, public: true }, + outcome: "No access guard: no token, no TTL, no revoke. The descriptor carries a `warning` saying so.", + }, + ], + returns: "`id` and `name` (accepted by the other tunnel tools), `url`, `publicUrl`, `access`, `expiresAt`, `status`.", + pitfalls: [ + "`cloudflare-named` requires `hostname` and `tunnelId`; `cloudflare-managed` requires `hostname`; `root` is for `cloudflare-provisioned` only.", + "`ttl` is clamped to 1 minute to 30 days and ignored with `public: true`.", + "A relaunched quick tunnel gets a new URL, so `autostart` is only useful for stable-hostname providers.", + "`public: true` exposes the target to anyone who finds the URL. Use it only for content that is meant to be public.", + "`targetHost` defaults to `127.0.0.1`; use `localhost` only for an IPv6-bound target.", + ], + }, + tunnel_list: { + effect: "read", + examples: [ + { + label: "Active tunnels only", + args: { onlyActive: true }, + outcome: "Returns `{ tunnels }` in a compact projection (id, name, label, provider, targetPort, publicUrl, url, access, status, hostname).", + }, + { + label: "Full descriptors, one page", + args: { full: true, limit: 20 }, + outcome: "Adds pid, stoppedAt, lastError, targetHost, autostart, tunnelId and credentialsFile; paged with a cursor.", + }, + ], + returns: "`tunnels[].id` and `.name`, accepted as `tunnelId` by the other tools.", + pitfalls: ["The list includes stopped and errored tunnels unless `onlyActive` is set."], + }, + tunnel_status: { + effect: "read", + examples: [ + { + label: "Read one tunnel by its name", + args: { tunnelId: "vite-preview" }, + outcome: "Returns the full descriptor; `cloudflare-managed` adds `health` and, during a hostname swap, `hostnames`.", + }, + ], + returns: "`status`, `url`, `health` ({ state: active, degraded or error, reason? }), `hostnames`.", + }, + tunnel_login: { + effect: "external", + examples: [ + { + label: "Start a device login", + args: { slug: "cloudflare-provisioned" }, + outcome: "Returns `{ status: \"pending\", userCode, verificationUri, expiresAt }`; the daemon keeps polling in the background.", + }, + { + label: "Forget the stored session", + args: { slug: "cloudflare-provisioned", logout: true }, + outcome: "Returns `{ status: \"logged_out\" }`.", + }, + ], + returns: "`status` (pending, logged_in, logged_out or failed). No token is ever returned.", + pitfalls: [ + "Call it again to read the state: it returns the current state instead of starting a second login.", + "A provider without a login flow answers `provider '' has no login`.", + ], + humanGate: { + when: "when `status` is `pending`", + action: + "Show the person `verificationUri` and `userCode`; they open the page in their browser and approve there. No tool can approve for them.", + }, + }, + tunnel_revoke: { + effect: "write", + examples: [ + { + label: "Rotate a leaked link", + args: { tunnelId: "vite-preview" }, + outcome: "Every earlier link and cookie stops working at once; returns the descriptor with a fresh signed `url` on a fresh TTL window.", + }, + ], + returns: "The descriptor with the new `url` and `expiresAt`.", + pitfalls: [ + "It errors for a `public: true` tunnel (no guard) and for a tunnel that is not active.", + "The tunnel keeps running: use `tunnel_stop` to take it down.", + ], + }, + tunnel_stop: { + effect: "write", + examples: [ + { + label: "Stop a tunnel", + args: { tunnelId: "vite-preview" }, + outcome: "Returns `{ ok: true, tunnelId }`; the provider process ends and the signed link stops working.", + }, + ], + returns: "`ok`. An unknown id is an error pointing at `tunnel_list`.", + pitfalls: ["It is idempotent on a stopped tunnel, and the descriptor stays listed as stopped. Remote state (managed tunnel, DNS) is kept: see `tunnel_delete`."], + }, + tunnel_delete: { + effect: "external", + examples: [ + { + label: "Remove a managed tunnel and its DNS", + args: { tunnelId: "relay" }, + outcome: "Returns `{ ok: true, tunnelId, deleted: true }`; the hostname stops resolving.", + }, + ], + returns: "`ok` and `deleted`.", + pitfalls: [ + "Irreversible. For `cloudflare-managed` it deletes only the records and the tunnel the engine created, and tolerates pieces already gone.", + "For any other provider it is a stop plus forgetting the descriptor.", + ], + }, + tunnel_add_hostname: { + effect: "external", + examples: [ + { + label: "Route a second hostname to the same tunnel", + args: { tunnelId: "relay", hostname: "relay.example.org" }, + outcome: "Adds the ingress rule and a proxied CNAME, makes it the primary `hostname`/`publicUrl`, and keeps the old hostname live.", + }, + ], + returns: "The updated descriptor with every routed hostname in `hostnames`.", + pitfalls: ["Only for `cloudflare-managed`; the hostname may be on another configured zone of the same account."], + }, + tunnel_remove_hostname: { + effect: "external", + examples: [ + { + label: "Retire the old hostname", + args: { tunnelId: "relay", hostname: "relay.example.com" }, + outcome: "Drops its ingress rule and deletes the engine's own CNAME for it.", + }, + ], + returns: "The updated descriptor.", + pitfalls: ["It refuses to remove the last hostname: use `tunnel_delete` for that."], + }, + }, +}) diff --git a/packages/skill-pack-agentproto/cli-verbs.json b/packages/skill-pack-agentproto/cli-verbs.json index 969c46e82..982d212b1 100644 --- a/packages/skill-pack-agentproto/cli-verbs.json +++ b/packages/skill-pack-agentproto/cli-verbs.json @@ -74,18 +74,12 @@ "presets": { "exception": "no skill presents this verb yet" }, - "remote": { - "exception": "no skill presents this verb yet" - }, "run": { "skill": "ap-adapters" }, "run-swarm": { "exception": "no skill presents this verb yet" }, - "sandbox": { - "exception": "no skill presents this verb yet" - }, "serve": { "skill": "agentproto-llm-endpoint" },