diff --git a/.changeset/lot-10f-tool-family-docs.md b/.changeset/lot-10f-tool-family-docs.md new file mode 100644 index 000000000..23e00c43b --- /dev/null +++ b/.changeset/lot-10f-tool-family-docs.md @@ -0,0 +1,6 @@ +--- +"@agentproto/runtime": patch +"@agentproto/cli": patch +--- + +Document the remaining file, browser, panel, daemon status and introspection tools as family docs (fs, browser, panels, daemon-status, introspection). Every daemon tool now has a family doc, so `tool_help` and `agentproto help` drop the unreachable "known tool without a doc" answer. diff --git a/packages/cli/src/__tests__/help.test.ts b/packages/cli/src/__tests__/help.test.ts index 1601282d6..17de94e1f 100644 --- a/packages/cli/src/__tests__/help.test.ts +++ b/packages/cli/src/__tests__/help.test.ts @@ -69,14 +69,6 @@ describe("runHelp", () => { expect(list.length).toBeLessThanOrEqual(10) }) - it("says a real tool has no doc yet, exit 0, no suggestions", async () => { - const { out, err, code } = await capture(["host_load"]) - expect(code).toBe(0) - expect(err).toBe("") - expect(out).toContain("has no help doc yet") - expect(out).not.toContain("Close names") - }) - it("--topic selects a section of the family doc", async () => { const { out, code } = await capture(["desktop_conversation_create", "--topic", "Examples"]) expect(code).toBe(0) diff --git a/packages/cli/src/commands/help.ts b/packages/cli/src/commands/help.ts index f758070ad..d690e1677 100644 --- a/packages/cli/src/commands/help.ts +++ b/packages/cli/src/commands/help.ts @@ -13,7 +13,6 @@ import { extractHelpSection, getToolFamilyHelp, getToolHelp, - isKnownDaemonTool, unknownToolHelpMessage, } from "@agentproto/runtime" @@ -55,9 +54,8 @@ export async function runHelp(argv: readonly string[]): Promise { process.stdout.write((section ?? family) + "\n") return 0 } - const known = isKnownDaemonTool(name) - ;(known ? process.stdout : process.stderr).write(`agentproto help: ${unknownToolHelpMessage(name)}\n`) - return known ? 0 : 1 + process.stderr.write(`agentproto help: ${unknownToolHelpMessage(name)}\n`) + return 1 } if (!topic) { diff --git a/packages/runtime/src/__tests__/tool-help.test.ts b/packages/runtime/src/__tests__/tool-help.test.ts index dd1d8dbfb..aa58567ef 100644 --- a/packages/runtime/src/__tests__/tool-help.test.ts +++ b/packages/runtime/src/__tests__/tool-help.test.ts @@ -106,17 +106,6 @@ describe("tool_help MCP tool", () => { await close() }) - it("says a real tool has no doc yet, without suggestions or an error", async () => { - const { client, close } = await buildHarness() - const result = await client.callTool({ name: "tool_help", arguments: { name: "host_load" } }) - expect(result.isError).toBeFalsy() - const text = textOf(result) - expect(text).toContain("`host_load` has no help doc yet") - expect(text).toContain("tools/list") - expect(text).not.toContain("Close names") - await close() - }) - it("does not crash on Object.prototype names and honors topic on the family doc", async () => { expect(getToolFamilyHelp("constructor")).toBeUndefined() expect(getToolFamilyHelp("__proto__")).toBeUndefined() diff --git a/packages/runtime/src/tool-docs/browser.ts b/packages/runtime/src/tool-docs/browser.ts new file mode 100644 index 000000000..9869f21cf --- /dev/null +++ b/packages/runtime/src/tool-docs/browser.ts @@ -0,0 +1,256 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `browser-tools.ts` (registration, schemas, `builtin` modes), + * `browser-proxy.ts` (field mapping, refused and dropped fields, `notes`), + * `page-text.ts` (extraction, blocked detection). + */ +export const browserToolDoc = defineToolFamilyDoc({ + family: "browser", + title: "Web pages and the browser relay", + summary: + "Read a public page over plain HTTP, or drive a real browser tab (navigate, read, click, fill, scroll, screenshot, record) through the external browser server.", + whenToUse: [ + "Read a public web page as clean text: start with `fetch_page`, which needs no browser.", + "Handle a page that is anti-bot gated, needs JavaScript or needs clicks and typing: use a browser tab.", + "Capture a screenshot or a short recording of a page.", + ], + workflow: [ + "Call `fetch_page` with the URL. When `blocked` is true or the text is empty because the page needs JavaScript, switch to a browser tab.", + "Call `browser_navigate` to open the URL in this session's own tab, then `browser_extract_text` to read it.", + "Use `browser_get_dom` to find a CSS selector, then `browser_click`, `browser_fill`, `browser_press_key` or `browser_scroll` to interact.", + "Call `browser_screenshot` to see the page, or `browser_screencast_start`, `browser_screencast_frame` and `browser_screencast_stop` to record it.", + ], + cliCommands: [], + seeAlso: ["browser-instances", "ap-import-mcp"], + tools: { + fetch_page: { + effect: "external", + examples: [ + { + label: "Read a public page", + args: { url: "https://example.com/docs" }, + outcome: "Returns `{ title, text, url, blocked: false }` with `text` as markdown without boilerplate.", + }, + { + label: "Allow a slow server more time", + args: { url: "https://example.com/report", timeoutMs: 30000 }, + outcome: "Same result, with the request aborted after 30 seconds instead of 15.", + }, + ], + returns: "`title`, `text`, `url` (after redirects) and `blocked`.", + pitfalls: [ + "`blocked: true` (HTTP 403, 429 or 503, or a known challenge page) returns only `url`, `blocked` and `status`, with no text: retry with a browser tab, not with the same fetch.", + "Any other non-2xx status is a tool error; `timeoutMs` defaults to 15000 and is capped at 60000.", + "It does not run JavaScript: a page that renders its content client-side comes back nearly empty.", + "It is the only tool of the family still registered when `defaults.browser.builtin` is `off`.", + ], + }, + browser_navigate: { + effect: "external", + examples: [ + { + label: "Open a page in this session's tab", + args: { url: "https://example.com/login" }, + outcome: "Opens the tab on first use, loads the URL and returns the browser server's answer, with a `deprecated` marker.", + }, + { + label: "Target an owned tab on a named instance", + args: { url: "https://example.com/dashboard", tabId: "", instance: "" }, + outcome: "Navigates that tab instead of the default one.", + }, + ], + returns: "The browser server's result, plus `deprecated` and, when a field was dropped, `notes`.", + pitfalls: [ + "Every `browser_*` tool is a deprecated relay: it forwards to the server named by `defaults.browser.proxyImport` (default `bureau`) and answers an error when that import is missing; prefer calling that server's own tool.", + "A session only touches tabs it owns; the tab is opened on first use, so there is no separate open-tab call.", + "`sessionId` is accepted and ignored (reported in `notes`): the server identifies the calling session itself.", + "A server-side error such as `browser:not_owner` or `browser:awaiting_consent` is returned unchanged; consent needs a person to act in the browser.", + ], + }, + browser_extract_text: { + effect: "external", + examples: [ + { + label: "Read the current tab as clean text", + args: {}, + outcome: "Returns `{ title, text, url }` with `text` as markdown, built from the tab's DOM with boilerplate removed.", + }, + ], + returns: "`title`, `text` (markdown) and `url`.", + pitfalls: ["Call `browser_navigate` first: with no loaded page there is nothing to read."], + }, + browser_get_dom: { + effect: "external", + examples: [ + { + label: "Get the raw markup to find a selector", + args: {}, + outcome: "Returns the tab's serialized DOM (outerHTML).", + }, + ], + returns: "The raw DOM text.", + pitfalls: ["The result can be very large: prefer `browser_extract_text` unless you need exact markup."], + }, + browser_click: { + effect: "external", + examples: [ + { + label: "Click a button", + args: { selector: "button[type=submit]" }, + outcome: "Left-clicks the element once.", + }, + { + label: "Double-click with the right button", + args: { selector: "#row-1", button: "right", clickCount: 2 }, + outcome: "Sends two clicks with the right mouse button.", + }, + ], + returns: "The browser server's result.", + pitfalls: ["`clickCount` is 1 to 3; use `browser_get_dom` first when you do not know a selector."], + }, + browser_fill: { + effect: "external", + examples: [ + { + label: "Fill a field", + args: { selector: "input[name=email]", value: "user@example.com" }, + outcome: "Clears the field, then types the value.", + }, + { + label: "Append to existing text", + args: { selector: "textarea#notes", value: " more text", clear: false }, + outcome: "Types after the current content.", + }, + ], + returns: "The browser server's result.", + pitfalls: ["`selector` must designate an input or textarea element; an error from the browser server is returned unchanged."], + }, + browser_evaluate: { + effect: "external", + examples: [ + { + label: "Read a value from the page", + args: { expression: "document.title" }, + outcome: "Returns the serialized result of the expression.", + }, + { + label: "Await a request and cap the output", + args: { expression: "fetch('/api/items').then(r => r.json())", awaitPromise: true, maxResultBytes: 20000 }, + outcome: "Waits for the promise and truncates the serialized result at 20000 bytes.", + }, + ], + returns: "The expression's value as the browser server serializes it.", + pitfalls: [ + "`awaitPromise` and `returnByValue` both default to true.", + "The expression runs with the page's own privileges and cookies: treat page content as untrusted and do not run text taken from it.", + ], + }, + browser_scroll: { + effect: "external", + examples: [ + { + label: "Scroll an element into view", + args: { selector: "#comments" }, + outcome: "Centers the element in the viewport.", + }, + { + label: "Scroll the window down by 800 px", + args: { y: 800 }, + outcome: "Scrolls relative to the current position.", + }, + ], + returns: "The browser server's result.", + pitfalls: [ + "`x` and `y` are deltas in CSS pixels, not absolute positions, and are ignored when `selector` is set.", + "The daemon runs a fixed script through the server's evaluate tool; your selector is passed as data, never as code.", + ], + }, + browser_press_key: { + effect: "external", + examples: [ + { + label: "Press Enter", + args: { key: "Enter" }, + outcome: "Sends the key to whatever has focus.", + }, + { + label: "Select all", + args: { key: "a", modifiers: ["Control"] }, + outcome: "Presses the key while holding Control.", + }, + ], + returns: "The browser server's result.", + pitfalls: [ + "`selector` and `count` exist in the schema but are refused with an error and nothing is sent: click the element first, and call again to repeat.", + "`key` is a name such as Enter, Tab, Escape, Backspace, Delete, an arrow, Home, End, PageUp, PageDown, Space, or one printable character.", + ], + }, + browser_screenshot: { + effect: "external", + examples: [ + { + label: "Screenshot the current tab", + args: {}, + outcome: "Returns the image as base64 with its format.", + }, + ], + returns: "The base64 image and its format.", + pitfalls: ["This relay exposes only `tabId` and `instance`: format, quality and full-page options of the server are not reachable here."], + }, + browser_list_tabs: { + effect: "read", + examples: [ + { + label: "List this session's tabs", + args: {}, + outcome: "Returns the tabs the session owns, with the ids to pass as `tabId`.", + }, + ], + returns: "The owned tabs and their `tabId` values.", + }, + browser_screencast_start: { + effect: "external", + examples: [ + { + label: "Record an owned tab at 5 frames per second", + args: { tabId: "", fps: 5, format: "jpeg" }, + outcome: "Starts recording; the call then needs `browser_screencast_stop` to finish.", + }, + ], + returns: "The browser server's result, with `notes` naming any dropped field.", + pitfalls: [ + "`tabId` is required by the server although the schema marks it optional: get it from `browser_list_tabs`.", + "`quality`, `everyNthFrame`, `maxWidth` and `maxHeight` are dropped and listed in `notes`; only `fps` (default 3, clamped to 1 to 10) and `format` take effect.", + ], + }, + browser_screencast_frame: { + effect: "read", + examples: [ + { + label: "Grab the latest frame", + args: { tabId: "" }, + outcome: "Returns the most recent recorded frame.", + }, + ], + returns: "One frame as the browser server returns it.", + pitfalls: ["A recording must be running on that tab, started with `browser_screencast_start`."], + }, + browser_screencast_stop: { + effect: "external", + examples: [ + { + label: "Stop and encode", + args: { tabId: "" }, + outcome: "Ends the recording and encodes the frames into a video (`encode` defaults to true).", + }, + { + label: "Stop and keep raw frames", + args: { tabId: "", encode: false }, + outcome: "Ends the recording without encoding.", + }, + ], + returns: "The browser server's result for the recording.", + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/daemon-status.ts b/packages/runtime/src/tool-docs/daemon-status.ts new file mode 100644 index 000000000..743531d56 --- /dev/null +++ b/packages/runtime/src/tool-docs/daemon-status.ts @@ -0,0 +1,137 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `daemon-health-tools.ts` (daemon_health), `session-tools.ts` + * (host_load, usage_rollup), `host-load.ts` (report shape), + * `orchestration-tools.ts` and `activity-projection.ts` (activities_list), + * `usage-rollup.ts` (rollup shape), `docs/cli/verbs/{host,usage,doctor}.md`. + */ +export const daemonStatusToolDoc = defineToolFamilyDoc({ + family: "daemon-status", + title: "Daemon and host status", + summary: + "Check that the daemon is alive and how it is configured, why the host is slow, what the daemon is busy or waiting on, and what the sessions cost.", + whenToUse: [ + "Confirm the daemon still answers and read its boot settings, version and warnings.", + "Find out why the machine is slow and which session owns the heavy processes.", + "See what is active or blocked right now (turns, gates, workflow steps, PRs, cron runs).", + "Estimate spend over a window by profile, model or harness.", + ], + workflow: [ + "Call `daemon_health` first: a failed call, not a field, is how an unreachable daemon shows up.", + "Call `host_load` when the host is slow; read `warnings` and the `session` tag of each top process.", + "Call `activities_list` to see what is `active` or `pending` and what each pending item is `waitingOn`.", + "Call `usage_rollup` with a `window` for a local cost estimate.", + ], + cliCommands: [ + { + verb: "host", + command: "agentproto host load --full", + note: "Same report as `host_load`; `--fresh` and `--budget ` map to `fresh` and `budgetMs`. `host health` and `host stop-process` have no MCP tool.", + }, + { + verb: "usage", + command: "agentproto usage rollup --window 7d --profile team-primary", + note: "Same as `usage_rollup` (`--profile` is `profileRef`); `--json` prints the raw rollup. The CLI has no `groupBy` or `probe` flag.", + }, + { + verb: "doctor", + command: "agentproto doctor --only daemon", + note: "Read-only install check that includes the daemon's `/health`. No MCP tool.", + }, + ], + seeAlso: ["quota", "account-health", "session-lifecycle", "ap-models-auth"], + tools: { + daemon_health: { + effect: "read", + examples: [ + { + label: "Probe the daemon", + args: {}, + outcome: + "Returns `alive`, `status`, `workspace`, `uptimeMs`, `version`, `build`, the effective boot knobs (`resumeSessionsOnBoot`, `idleReapAfterMs`, `crashDetectIntervalMs`, `turnStallAfterMs`, ...), and `warnings`.", + }, + ], + returns: + "Besides the settings: `modelCooldowns`, `accountHealth` (closed accounts and when they return), `cron.pausedJobs`, `appRegistryIssues` and `appRegistryRepairs`, and `sandboxSessions` when available.", + pitfalls: [ + "`alive` is always true on a successful return: an unreachable daemon shows up as a failed or timed-out call, never as `alive: false`.", + "It is the in-process twin of `GET /health`, with no side effect.", + "Numeric knobs read 0 when the matching feature is off.", + ], + }, + host_load: { + effect: "read", + examples: [ + { + label: "Quick report", + args: {}, + outcome: + "Returns load average against core count, CPU, memory, swap, disks, the top 10 processes by CPU and by memory (each tagged with its owner), and `warnings`.", + }, + { + label: "Full detail on a saturated host", + args: { detail: "full", fresh: true, budgetMs: 5000 }, + outcome: "Adds a per-session rollup and every process, bypasses the cache and gives the memory probe 5 seconds.", + }, + ], + returns: + "`loadPerCore`, `cpu`, `memory`, `swap`, `disks`, `topByCpu`, `topByMemory`, `warnings`, and `partial` naming probes that failed or timed out; `sessions` and `processes` with `detail: \"full\"`.", + pitfalls: [ + "It is bounded to about 2 seconds: a slow probe is named in `partial` and the rest still ships. `budgetMs` accepts 300 to 60000 (default 1900).", + "The answer is cached for about 2 seconds; `fresh: true` resamples.", + "A caller limited to a subtree of sessions sees the host metrics but only its own sessions' processes, marked `scoped`.", + "Read-only: nothing is stopped and no sudo is needed.", + ], + }, + activities_list: { + effect: "read", + examples: [ + { + label: "What is running or blocked now", + args: {}, + outcome: "Returns `{ activities, counts }` with non-terminal records only; `counts` holds the `active` and `pending` numbers.", + }, + { + label: "What one session is waiting on", + args: { sessionId: "", state: "pending" }, + outcome: "Returns that session's pending records, each with `waitingOn` naming the blocker.", + }, + { + label: "Recent finished PR activity, paged", + args: { kind: "pr", includeTerminal: true, limit: 20 }, + outcome: "Returns `{ items, nextCursor?, total }` including done, failed and cancelled records.", + }, + ], + returns: "Each record: `id`, `kind`, `sessionId`, `source`, `title`, `state`, `waitingOn`, `startedAt`, `endedAt`, `staleSince`, `taskId`.", + pitfalls: [ + "States are `active`, `pending`, `done`, `failed`, `cancelled`; kinds are `turn`, `policy`, `gate`, `commit`, `workflow-step`, `pr`, `cron-run`; sources are `supervisor`, `workflow`, `session`, `code-host`, `cron`.", + "Passing a terminal `state` implies `includeTerminal`.", + "Records are compact by default and the `error` detail only comes with `full: true`; `limit` is capped at 200.", + "For live changes subscribe to the `activity:changed` event with `session_events_poll` instead of polling this list.", + ], + }, + usage_rollup: { + effect: "read", + examples: [ + { + label: "Spend over the last 7 days", + args: { window: "7d" }, + outcome: "Returns `total`, `byProfile`, `byModel`, `byHarness`, `sessionsConsidered` and `basis: \"local-estimate\"`.", + }, + { + label: "One profile, by model only", + args: { window: "5h", profileRef: "team-primary", groupBy: ["model"] }, + outcome: "Returns `total` and `byModel` for that profile over the last 5 hours.", + }, + ], + returns: "Buckets with cost, token counts and `unpricedTokens`; cache and reasoning token counts only when some session reports them.", + pitfalls: [ + "It is a local estimate from per-session usage snapshots, not the provider's bill; tokens of a model with no catalog price are counted in `unpricedTokens`, never as zero cost.", + "`window` is `` such as `30m` or `2w`, or an ISO-8601 duration such as `P7D`; anything else returns an `invalid_window` error.", + "`probe: true` makes one small live call per Anthropic OAuth profile to refresh `remaining`, which spends a little of that profile's own rate limit; the default reads the last-seen value only.", + "A scoped orchestrator only sees the sessions of its own subtree.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/fs.ts b/packages/runtime/src/tool-docs/fs.ts new file mode 100644 index 000000000..4281302d0 --- /dev/null +++ b/packages/runtime/src/tool-docs/fs.ts @@ -0,0 +1,127 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `fs-tools.ts` (all six tools, path confinement, read windows, + * pagination), `tool-envelope.ts` (page envelope). + */ +export const fsToolDoc = defineToolFamilyDoc({ + family: "fs", + title: "Workspace files and directories", + summary: + "Read, write, stat, list and delete files inside the workspace over MCP, for clients that have no shell on the daemon's machine.", + whenToUse: [ + "Reach files on the daemon's machine from a remote MCP client (a cloud agent through a tunnel, an IDE) that has no filesystem of its own.", + "Read a large file in windows, or a binary file as base64.", + "Create, overwrite or remove a file or directory under the workspace.", + ], + workflow: [ + "Call `directory_list` on a directory to see its entries (`[DIR]` or `[FILE]` per line), then `file_info` for a size or modification time.", + "Call `file_read` with the path; add `offset` and `limit` to read a window of a big file.", + "Call `file_write` to create or replace a file (parent directories are created), or `directory_create` for an empty directory.", + "Call `file_delete` to remove a path.", + ], + cliCommands: [], + seeAlso: ["ap-run-command"], + tools: { + file_read: { + effect: "read", + examples: [ + { + label: "Read a whole text file", + args: { path: "README.md" }, + outcome: "Returns the file body as plain text.", + }, + { + label: "Read lines 100 to 199 of a long file", + args: { path: "logs/build.log", offset: 100, limit: 100 }, + outcome: "Returns `{ content, truncated, offset, returned, total }`, counted in lines.", + }, + { + label: "Read a binary file in a 64 KiB window", + args: { path: "assets/logo.png", encoding: "base64", offset: 0, limit: 65536 }, + outcome: "Returns `{ content, truncated, offset, returned, total }` where `content` is base64 and the counts are in bytes.", + }, + ], + returns: "Plain text when neither `offset` nor `limit` is given; otherwise a JSON window with `truncated` (more remains) and `total`.", + pitfalls: [ + "`offset` and `limit` count lines for `utf8` and bytes for `base64`.", + "Reading a binary file as `utf8` replaces invalid bytes and corrupts the content: pass `encoding: \"base64\"`.", + "With no `offset` or `limit` the whole file is read in one call; use a window for big files.", + "A path outside the workspace, or in a part of the tree the caller's node scope hides, is refused or reported as missing.", + ], + }, + file_write: { + effect: "write", + examples: [ + { + label: "Create a file in a new directory", + args: { path: "notes/todo.md", content: "- first item\n" }, + outcome: "Creates `notes/` if needed, writes the file as UTF-8 and returns `ok`.", + }, + ], + returns: "The text `ok`.", + pitfalls: [ + "An existing file is overwritten without a prompt or a backup.", + "Content is written as UTF-8 text only: there is no base64 mode for writing.", + "In an app-spawned session the path must fall in a writable zone of the app boundary; relative paths resolve against the app directory, not the workspace.", + ], + }, + directory_list: { + effect: "read", + examples: [ + { + label: "List the workspace root", + args: {}, + outcome: "Returns one line per entry: `[DIR] src` or `[FILE] package.json`.", + }, + { + label: "List a big directory page by page", + args: { path: "packages", limit: 50 }, + outcome: "Returns `{ items, nextCursor?, total }` with at most 50 lines; pass `nextCursor` as `cursor` for the next page.", + }, + ], + returns: "Newline-joined entries without paging parameters; `{ items, nextCursor, total }` with `limit` or `cursor`.", + pitfalls: [ + "Without `limit` or `cursor` every entry is returned; with them `limit` is capped at 200.", + "Entries come in the filesystem's own order and are not recursive; only `[DIR]` and `[FILE]` exist, so a symbolic link is listed as `[FILE]`.", + ], + }, + file_info: { + effect: "read", + examples: [ + { + label: "Stat a file", + args: { path: "package.json" }, + outcome: "Returns `{ name, path, type, size, modified, created }` with ISO timestamps and `type` of `file` or `directory`.", + }, + ], + returns: "`type`, `size` in bytes, and `modified` / `created` timestamps.", + }, + directory_create: { + effect: "write", + examples: [ + { + label: "Create nested directories", + args: { path: "build/output/reports" }, + outcome: "Creates every missing level and returns `ok`; an existing directory is not an error.", + }, + ], + returns: "The text `ok`.", + }, + file_delete: { + effect: "write", + examples: [ + { + label: "Delete one file", + args: { path: "notes/todo.md" }, + outcome: "Removes the file and returns `ok`.", + }, + ], + returns: "The text `ok`, also when the path did not exist.", + pitfalls: [ + "The description says \"file or empty directory\" but the removal is recursive and forced: a directory is deleted with everything in it, and a missing path is not an error.", + "There is no trash and no confirmation: check the path with `directory_list` first.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/index.ts b/packages/runtime/src/tool-docs/index.ts index a5ac89925..b21642579 100644 --- a/packages/runtime/src/tool-docs/index.ts +++ b/packages/runtime/src/tool-docs/index.ts @@ -18,6 +18,11 @@ import { branchGcToolDoc } from "./branch-gc.js" import { approvalsToolDoc } from "./approvals.js" import { agentToolDoc } from "./agent.js" import { appDataToolDoc, appToolDoc, appUiToolDoc } from "./app.js" +import { browserToolDoc } from "./browser.js" +import { daemonStatusToolDoc } from "./daemon-status.js" +import { fsToolDoc } from "./fs.js" +import { introspectionToolDoc } from "./introspection.js" +import { panelsToolDoc } from "./panels.js" import { desktopToolDoc } from "./desktop.js" import { devicesToolDoc } from "./devices.js" import { joinTokensToolDoc } from "./join-tokens.js" @@ -79,6 +84,11 @@ export const TOOL_FAMILY_DOCS: readonly ToolFamilyDoc[] = [ remoteToolDoc, llmEndpointToolDoc, decisionToolDoc, + browserToolDoc, + daemonStatusToolDoc, + fsToolDoc, + introspectionToolDoc, + panelsToolDoc, authProfileToolDoc, catalogToolDoc, harnessToolDoc, diff --git a/packages/runtime/src/tool-docs/introspection.ts b/packages/runtime/src/tool-docs/introspection.ts new file mode 100644 index 000000000..c0b077843 --- /dev/null +++ b/packages/runtime/src/tool-docs/introspection.ts @@ -0,0 +1,119 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `session-tools.ts` and `capabilities-inventory.ts` + * (capabilities_inventory), `agent-tools.ts` (role_list), + * `mcp-server/src/self-inspect-tool.ts` (self_inspect), `tool-help-mcp.ts` and + * `tool-help-family.ts` (tool_help), `command-tools.ts` (tool_calls_list). + */ +export const introspectionToolDoc = defineToolFamilyDoc({ + family: "introspection", + title: "Introspection: tools, roles, capabilities and call history", + summary: + "Ask the daemon about itself: how a tool works, which roles, MCP servers and skills exist, what an agent manifest declares, and which tool calls ran.", + whenToUse: [ + "Read the long-form guide of a tool before using it in an unfamiliar way.", + "Check which roles a session may spawn, or which MCP servers and skills a harness will see.", + "Inspect your own agent manifest, or audit the tool calls of a session.", + ], + workflow: [ + "Call `tool_help` with a tool `name` (and a `topic` heading to read one section).", + "Call `role_list` before spawning with a role, and `capabilities_inventory` to see MCP servers and skills.", + "Call `tool_calls_list` with a `sessionId` to see what that session ran, or with no session for the latest calls across sessions.", + ], + cliCommands: [], + seeAlso: ["ap-tool-index", "agent", "session-lifecycle", "ap-import-mcp"], + tools: { + tool_help: { + effect: "read", + examples: [ + { + label: "Read a tool's guide", + args: { name: "agent_start" }, + outcome: "Returns the long-form doc, or the family doc when the tool has one.", + }, + { + label: "Read one section", + args: { name: "agent_start", topic: "Pitfalls" }, + outcome: "Returns only that `##` section; if it does not exist the full doc is returned with a note.", + }, + ], + returns: "Markdown text.", + pitfalls: [ + "A tool with no doc answers that it has none and points at tools/list; an unknown name is an error that suggests close names.", + "When the tool is not exposed by the active MCP profiles, the answer ends with a note naming the profiles that expose it.", + ], + }, + role_list: { + effect: "read", + examples: [ + { + label: "List spawn roles", + args: {}, + outcome: "Returns `{ roles }`, one row per role with `name`, `level`, `delegation`, `spawnable`, and `delegatesTo` when declared.", + }, + ], + returns: "`roles[].name`, accepted as `role` by `agent_start`; `spawnable` names the roles this role may start in turn.", + pitfalls: [ + "The built-in roles are `executor` and `supervisor`; custom roles come from installed role packs.", + "It only reads the registry: it never grants or denies a spawn.", + "`limit` is capped at 200; the rows are already compact.", + ], + }, + capabilities_inventory: { + effect: "read", + examples: [ + { + label: "Read the full inventory", + args: {}, + outcome: + "Returns `{ mcp, skills }`: imported and discovered MCP servers with status and tool count, which harnesses get the daemon's own mount, installed skill packs, and skills per harness.", + }, + ], + returns: "`mcp.imported[]` (`status`, `toolCount`, `usedBySessions`, `reach`), `mcp.discovered[]`, `mcp.daemonMountByHarness`, `skills.packs`, `skills.byHarness`, `skills.defaults`.", + pitfalls: [ + "It never connects to an MCP server just to count tools: `toolCount` is only present for a connected server.", + "It never fetches a skill pack from the network, and shows header and env key names behind secret references, never their values.", + "A section that failed carries an `error` field instead of failing the whole call.", + ], + }, + self_inspect: { + effect: "read", + examples: [ + { + label: "Inspect an agent manifest by its id", + args: { agentId: "writer" }, + outcome: "Returns `{ agentPath, tools, routines }`, each item with `id` and `description`.", + }, + ], + returns: "`agentPath` and the declared `tools` and `routines`.", + pitfalls: [ + "`agentId` is the `id` in the manifest's frontmatter; the file is looked up at `/.agents//AGENT.md`, then at `/.agentproto/agents//AGENT.md`.", + "Only file and inline references are loaded; plain string or `ref` references come back as their identifier with a placeholder description.", + "A missing manifest is an error with code `agent_not_found` that lists both paths tried.", + ], + }, + tool_calls_list: { + effect: "read", + examples: [ + { + label: "What one session ran", + args: { sessionId: "", lastN: 20 }, + outcome: "Returns `{ records }`, oldest first, each with `tool`, `command`, `exitCode`, `isError`, `durationMs`, and the session's `harness` and `origin`.", + }, + { + label: "Latest calls across recent sessions, projected", + args: { lastN: 100, fields: ["sessionId", "tool", "isError"] }, + outcome: "Returns up to 100 records from recent command and agent sessions, keeping only those three keys.", + }, + ], + returns: "`records`, in time order, including `createdPrUrl` and `createdPrNumber` on a call that opened a PR.", + pitfalls: [ + "`lastN` defaults to 50 and is capped at 500; a long `result` is cut to about 500 characters unless `full: true`.", + "One log covers both `command_execute` calls and an agent's own tool calls (Bash, Read, Edit, ...); only the first has an `exitCode`.", + "Without a session it reads only command and agent-cli sessions, newest first, and stops as soon as `lastN` records are collected.", + "A session reference that is ambiguous is an error; one that is not found yields an empty list.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/legacy.ts b/packages/runtime/src/tool-docs/legacy.ts index 668522ce5..be13711af 100644 --- a/packages/runtime/src/tool-docs/legacy.ts +++ b/packages/runtime/src/tool-docs/legacy.ts @@ -8,42 +8,4 @@ import type { DaemonToolName } from "../daemon-tool-names.generated.js" export const LEGACY_UNDOCUMENTED_TOOLS: readonly DaemonToolName[] = [ - "activities_list", - "agentproto_agents_overview", - "agentproto_bureau_sessions", - "agentproto_reviews", - "agentproto_session_chat", - "agentproto_session_story", - "agentproto_sessions", - "agentproto_store", - "agentproto_work_board", - "browser_click", - "browser_evaluate", - "browser_extract_text", - "browser_fill", - "browser_get_dom", - "browser_list_tabs", - "browser_navigate", - "browser_press_key", - "browser_screencast_frame", - "browser_screencast_start", - "browser_screencast_stop", - "browser_screenshot", - "browser_scroll", - "capabilities_inventory", - "daemon_health", - "directory_create", - "directory_list", - "fetch_page", - "file_delete", - "file_info", - "file_read", - "file_write", - "host_load", - "live_session", - "role_list", - "self_inspect", - "tool_calls_list", - "tool_help", - "usage_rollup", ] diff --git a/packages/runtime/src/tool-docs/panels.ts b/packages/runtime/src/tool-docs/panels.ts new file mode 100644 index 000000000..8803f1e58 --- /dev/null +++ b/packages/runtime/src/tool-docs/panels.ts @@ -0,0 +1,187 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `packages/apps/src/{sessions-panel,agents-overview,bureau-sessions, + * session-story,session-chat,live-session,work-board,review-panel,store}/index.ts` + * (input schema and `execute()` of each panel), `builtin-apps.ts` (wiring). + */ +export const panelsToolDoc = defineToolFamilyDoc({ + family: "panels", + title: "Built-in UI panels", + summary: + "Open the daemon's built-in interactive panels (sessions, agents overview, session story and chat, live session, work board, reviews, app store) from a client that can render MCP apps.", + whenToUse: [ + "Show a person a live view of sessions, a session's story, the work board, the review ledger or the app store, instead of dumping JSON.", + "Get the initial data snapshot a panel starts from, without a UI.", + ], + workflow: [ + "Call the panel tool; a client that renders MCP apps shows the interface, and every other client gets the snapshot JSON.", + "The panel then polls the daemon's ordinary tools itself (`session_list`, `task_list`, `review_ledger`, ...), so anything it shows can also be read by calling those tools directly.", + "Actions inside a panel (claim a task, cancel a review, install an app) go through the same tools any caller uses, with their own confirmations.", + ], + cliCommands: [], + seeAlso: ["session-lifecycle", "tasks", "review", "ap-apps", "terminals"], + tools: { + agentproto_sessions: { + effect: "read", + examples: [ + { + label: "Open the panel on running sessions only", + args: { filter: "running" }, + outcome: "Returns `{ sessions }` with the live agent and terminal sessions, and renders the panel.", + }, + { + label: "Include recent sessions", + args: { filter: "all" }, + outcome: "Same, with recent ended sessions too (the default).", + }, + ], + returns: "`sessions`: the registry's session descriptors for the filter.", + pitfalls: ["Raw shell command runs are a log, not sessions, and do not appear here: use `command_list`."], + }, + agentproto_agents_overview: { + effect: "read", + examples: [ + { + label: "Open the plain-language agent cards", + args: {}, + outcome: "Returns `{ sessions }` for `all` (running and recent) and renders one card per session.", + }, + { + label: "Only live sessions", + args: { filter: "running" }, + outcome: "Returns `{ sessions }` limited to alive sessions.", + }, + ], + returns: "`sessions`.", + pitfalls: [ + "Cards get their one-sentence summary and coarse state from `summarize_session`, called per visible session by the panel: opening the panel makes those calls, the tool itself only returns the list.", + "The panel's own labels are French.", + ], + }, + agentproto_session_story: { + effect: "read", + examples: [ + { + label: "Open the story of one session", + args: { sessionId: "" }, + outcome: "Returns `{ sessionId }`; the panel loads that session's transcript and folds it into chapters and steps.", + }, + { + label: "Open the session picker", + args: {}, + outcome: "Returns `{ sessions }` (all sessions) for the picker.", + }, + ], + returns: "`{ sessionId }` when one is given, else `{ sessions }`.", + pitfalls: ["The panel includes a composer that sends prompts into the session, so opening it on someone else's session lets its user drive that session."], + }, + agentproto_session_chat: { + effect: "read", + examples: [ + { + label: "Deep-link the chat to a session", + args: { sessionId: "" }, + outcome: "Returns `{ installed, url, embedToken? }`; when the chat app is installed, `url` is its standalone link to that session.", + }, + { + label: "Open the chat with its session picker", + args: {}, + outcome: "Same, without a session selected.", + }, + ], + returns: "`installed`, `url` (null when not installed), `embedToken` when available, and `storeUrl` when the chat app is missing.", + pitfalls: [ + "It is a launcher for the separate session-chat app: when that app is not installed the panel only shows install instructions and `storeUrl` points at the App Store entry.", + ], + }, + live_session: { + effect: "read", + examples: [ + { + label: "Watch the newest running session", + args: {}, + outcome: "Returns `{ sessionId, httpBaseUrl }` with `sessionId` unset; the panel picks the newest running session from the live tree.", + }, + { + label: "Attach to a known session", + args: { sessionId: "" }, + outcome: "The panel attaches to that session (id or name) directly.", + }, + ], + returns: "`sessionId` (when given) and the daemon's `httpBaseUrl`, which the panel uses for its event stream.", + }, + agentproto_work_board: { + effect: "read", + examples: [ + { + label: "Open the caller's default board", + args: {}, + outcome: "Returns `{ boardId, tasks }` for the default board (a session tree's `tree:` or the operator's `ws:`).", + }, + { + label: "Open a named workspace board", + args: { boardId: "ws:my-workspace" }, + outcome: "Returns that board's tasks as a kanban.", + }, + ], + returns: "`boardId` (always echoed) and the full task records, including `verification`.", + pitfalls: ["Cards write through `task_claim`, `task_update` and `task_create`; a gate-passed done is shown apart from a self-reported one."], + }, + agentproto_reviews: { + effect: "read", + examples: [ + { + label: "Open the review ledger for one repository", + args: { repoRemote: "github.com/example/project" }, + outcome: "Returns `{ total, attestations }` scoped to that remote, running reviews included.", + }, + { + label: "Scope to the reviews one session asked for", + args: { requesterSessionId: "" }, + outcome: "Returns only that requester's reviews in the snapshot.", + }, + ], + returns: "`total`, `attestations` (the same body `review_ledger` returns) and `focusRunId` when a `runId` was passed.", + pitfalls: [ + "`cwd`, `repoRemote` and `requesterSessionId` scope only the initial snapshot: the panel's own live view re-polls unscoped.", + "`runId` is informational on the snapshot and only echoed back as `focusRunId`.", + ], + }, + agentproto_store: { + effect: "read", + examples: [ + { + label: "Open the app store", + args: {}, + outcome: "Returns `{ catalog, installed, updates, warnings? }`: what `app_catalog`, `app_list` and `app_updates` answer.", + }, + { + label: "Restrict the catalog to one source", + args: { catalogUrl: "https://example.com/catalog.json" }, + outcome: "Same, with catalog rows from that source only.", + }, + ], + returns: "`catalog`, `installed`, `updates`, and `warnings` from failing catalog sources.", + pitfalls: [ + "A failing catalog source becomes a warning, never an error.", + "Installing from the panel shows an explicit confirmation dialog that a person must accept; direct tool callers use `app_install` instead.", + ], + }, + agentproto_bureau_sessions: { + effect: "read", + examples: [ + { + label: "List browser sessions", + args: { filter: "all" }, + outcome: "Returns `{ sessions }` limited to sessions of kind `browser`, normally an empty list.", + }, + ], + returns: "`sessions` of kind `browser`.", + pitfalls: [ + "Legacy panel: it lists browser sessions of a retired path and is normally empty. It says nothing about the browser server the `browser_*` tools relay to.", + "To see that server, use its own overview tools through `mcp_imported_call`, or the `browser` tools of this daemon.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-help-family.ts b/packages/runtime/src/tool-help-family.ts index ef8e89cb2..4e0f700fc 100644 --- a/packages/runtime/src/tool-help-family.ts +++ b/packages/runtime/src/tool-help-family.ts @@ -57,12 +57,6 @@ export function isKnownDaemonTool(name: string): boolean { /** Short answer for a name with neither a long doc nor a family doc. */ export function unknownToolHelpMessage(name: string): string { - if (isKnownDaemonTool(name)) { - return ( - `\`${name}\` has no help doc yet; its description and input schema are in tools/list. ` + - "The `ap-tool-index` skill lists every tool by family." - ) - } const close = suggestToolNames(name) return ( `No help doc for "${name}". ` + diff --git a/packages/runtime/src/tool-help-mcp.ts b/packages/runtime/src/tool-help-mcp.ts index abf7e8c5f..ff5f07912 100644 --- a/packages/runtime/src/tool-help-mcp.ts +++ b/packages/runtime/src/tool-help-mcp.ts @@ -10,7 +10,7 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" import { z } from "zod" -import { getToolFamilyHelp, isKnownDaemonTool, unknownToolHelpMessage } from "./tool-help-family.js" +import { getToolFamilyHelp, unknownToolHelpMessage } from "./tool-help-family.js" import { extractHelpSection, getToolHelp } from "./tool-help.js" import { profilesExposingTool, type ToolProfileName } from "./tool-profiles.js" @@ -65,7 +65,7 @@ export function registerToolHelpTool(server: McpServer, options: RegisterToolHel text: unknownToolHelpMessage(name) + profileNote(name, options.activeProfiles), }, ], - isError: !isKnownDaemonTool(name), + isError: true, } } if (!topic) { diff --git a/packages/skill-pack-agentproto/cli-verbs.json b/packages/skill-pack-agentproto/cli-verbs.json index 6b61b9ae1..2fc47ad8a 100644 --- a/packages/skill-pack-agentproto/cli-verbs.json +++ b/packages/skill-pack-agentproto/cli-verbs.json @@ -32,18 +32,12 @@ "daemon": { "skill": "ap-run-command" }, - "doctor": { - "exception": "no skill presents this verb yet" - }, "help": { "exception": "prints usage, nothing to teach" }, "hook": { "exception": "no skill presents this verb yet" }, - "host": { - "skill": "agentproto" - }, "install": { "skill": "ap-adapters" }, @@ -86,9 +80,6 @@ "steward": { "exception": "no skill presents this verb yet" }, - "usage": { - "skill": "ap-models-auth" - }, "workspace": { "exception": "no skill presents this verb yet" }