diff --git a/.changeset/tool-docs-10e-2.md b/.changeset/tool-docs-10e-2.md new file mode 100644 index 000000000..eedc56d2c --- /dev/null +++ b/.changeset/tool-docs-10e-2.md @@ -0,0 +1,5 @@ +--- +"@agentproto/runtime": patch +--- + +Document the channels, reach, conversation and workspace-brain tool families (19 tools leave the legacy undocumented list). diff --git a/packages/cli/src/__tests__/help.test.ts b/packages/cli/src/__tests__/help.test.ts index 3192be7b5..1601282d6 100644 --- a/packages/cli/src/__tests__/help.test.ts +++ b/packages/cli/src/__tests__/help.test.ts @@ -70,7 +70,7 @@ describe("runHelp", () => { }) it("says a real tool has no doc yet, exit 0, no suggestions", async () => { - const { out, err, code } = await capture(["telegram_bot_token_status"]) + const { out, err, code } = await capture(["host_load"]) expect(code).toBe(0) expect(err).toBe("") expect(out).toContain("has no help doc yet") diff --git a/packages/runtime/src/__tests__/tool-help.test.ts b/packages/runtime/src/__tests__/tool-help.test.ts index b28862d10..dd1d8dbfb 100644 --- a/packages/runtime/src/__tests__/tool-help.test.ts +++ b/packages/runtime/src/__tests__/tool-help.test.ts @@ -108,10 +108,10 @@ describe("tool_help MCP tool", () => { 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: "telegram_bot_token_status" } }) + const result = await client.callTool({ name: "tool_help", arguments: { name: "host_load" } }) expect(result.isError).toBeFalsy() const text = textOf(result) - expect(text).toContain("`telegram_bot_token_status` has no help doc yet") + expect(text).toContain("`host_load` has no help doc yet") expect(text).toContain("tools/list") expect(text).not.toContain("Close names") await close() diff --git a/packages/runtime/src/tool-docs/channels.ts b/packages/runtime/src/tool-docs/channels.ts new file mode 100644 index 000000000..dcfa10227 --- /dev/null +++ b/packages/runtime/src/tool-docs/channels.ts @@ -0,0 +1,159 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `orchestration-tools.ts` (transmit_message, inbound_endpoint_*, + * inbound_watcher_*), `outbound-adapters.ts` (send result and blocked + * statuses), `telegram-bot-creds.ts` (telegram_*). + */ +export const channelsToolDoc = defineToolFamilyDoc({ + family: "channels", + title: "Channels: outbound messages, inbound endpoints, watchers and Telegram bots", + summary: + "Send a message to an external contact through a provider, receive replies by webhook or by polling and route them to a session, and set up a Telegram bot.", + whenToUse: [ + "Message an outside contact (Telegram, an agentpush channel) and have their replies come back to the same session.", + "Expose a signed `/inbound/` webhook that spawns or routes into sessions.", + "Poll an agentpush source and spawn one agent per contact.", + "Connect a Telegram bot and point its webhook at this daemon.", + ], + workflow: [ + "Telegram only: `telegram_bot_token_set`, check with `telegram_bot_token_status`, then `telegram_bot_set_webhook` with a public https URL (see `tunnels`).", + "Receiving: `inbound_endpoint_create` (webhook; keep the generated `secret`) or `inbound_watcher_start` (polling; keep the `watcherId`).", + "Sending: `transmit_message` with a `sessionId` binds the contact to that session, so their replies route into it. The `alias` must match the one the endpoint was created with.", + "Clean up with `inbound_endpoint_delete` and `inbound_watcher_stop`; `inbound_endpoint_list` and `inbound_watcher_list` show what is live.", + ], + cliCommands: [], + seeAlso: ["tunnels", "messaging", "reach"], + tools: { + transmit_message: { + effect: "external", + examples: [ + { + label: "Message a Telegram chat and bind it to this session", + args: { provider: "telegram", source: "", contact_ref: "", text: "Build finished, tests green.", sessionId: "" }, + outcome: "Returns `{ sent: true, bound: true, message_id }`; the chat's next replies route into the session.", + }, + { + label: "Fire and forget through agentpush", + args: { alias: "agentpush", source: "", contact_ref: "", text: "Reminder: standup at 10.", bind: false }, + outcome: "Returns `{ sent: true, bound: false }`; nothing is bound.", + }, + ], + returns: "`sent`, `bound`, `message_id`; on failure `error`, and `blocked_reason` / `suggestion` when the provider refused the send.", + pitfalls: [ + "Provider defaults to `agentpush`, which requires `alias`; telegram defaults the alias to `default`.", + "`text` or `attachments` is required, and `sessionId` is required unless `bind: false`.", + "A blocked send (opt-out, expired window, unapproved template) is an error result with `blocked_reason`, not `sent: true`.", + "It is a real message to a real person: there is no dry run. The tool exists only when an MCP proxy and a binding store are wired.", + ], + }, + inbound_endpoint_create: { + effect: "write", + examples: [ + { + label: "Create a webhook endpoint and keep its generated secret", + args: { slug: "support-line", provider: "generic", alias: "agentpush", mode: "route-or-spawn" }, + outcome: "Returns `{ slug, provider, alias, mode, enabled, has_secret, secret }`; `secret` appears only when it was generated now.", + }, + ], + returns: "`slug` (the path of `POST /inbound/`) and `secret` (once).", + pitfalls: [ + "It creates or updates by `slug`; an update keeps the existing secret unless you pass one.", + "`alias` must match what `transmit_message` used, or replies will not find their binding.", + "Modes: `spawn` always starts a fresh agent, `route` only delivers to a bound session, `route-or-spawn` (default) does both.", + "The URL must be reachable from outside (see `tunnels`); the secret is shown once, so store it.", + ], + }, + inbound_endpoint_list: { + effect: "read", + examples: [ + { label: "Compact list", args: {}, outcome: "Returns `{ endpoints }` with slug, provider, alias, mode and enabled. No secret." }, + { label: "Full records", args: { full: true }, outcome: "Adds source, createdTs, lastSeenTs and `has_secret`." }, + ], + returns: "`endpoints[].slug`.", + }, + inbound_endpoint_delete: { + effect: "write", + examples: [ + { label: "Remove an endpoint", args: { slug: "support-line" }, outcome: "Returns `{ deleted: true }`, or `false` when the slug did not exist." }, + ], + returns: "`deleted`.", + pitfalls: ["Bindings made by `transmit_message` stay; only the webhook stops accepting posts."], + }, + inbound_watcher_start: { + effect: "write", + examples: [ + { + label: "Poll a source and spawn an agent per contact", + args: { + alias: "agentpush", + source: "", + harness: "claude-code", + promptTemplate: "{{count}} new message(s) from {{contact_ref}}: {{messages_json}}. Answer them.", + pollIntervalMs: 5000, + mode: "route-or-spawn", + }, + outcome: "Returns the watcher descriptor with a `watcherId`.", + }, + ], + returns: "`watcherId` for `inbound_watcher_stop`.", + pitfalls: [ + "Import the agentpush server first (`mcp_import`); `alias` names that import.", + "`pollIntervalMs` is 1000 to 60000 (default 5000). `harness` is required; `adapter` is a deprecated alias.", + "Each contact spawns an agent that replies through `mcpServersForChild`; without agentpush mounted there, the agent cannot answer.", + "`mode` defaults to `spawn`, unlike the endpoint default.", + ], + }, + inbound_watcher_stop: { + effect: "write", + examples: [ + { label: "Stop a watcher", args: { watcherId: "" }, outcome: "Returns `{ ok: true, status: \"stopped\" }`; the cursor is kept so a new watcher resumes there." }, + ], + returns: "`ok`; an unknown id is an error result.", + }, + inbound_watcher_list: { + effect: "read", + examples: [ + { label: "Watchers, running and stopped", args: {}, outcome: "Returns `{ watchers }` with watcherId, alias, source, adapter, status and spawned count." }, + { label: "With cursors", args: { full: true }, outcome: "Adds cursor, lastPollAt and lastFireAt." }, + ], + returns: "`watchers[].watcherId`.", + }, + telegram_bot_token_set: { + effect: "write", + examples: [ + { label: "Store the primary bot token", args: { token: "" }, outcome: "Returns `{ ok, alias: \"default\", fingerprint, last4 }`. The token is never returned." }, + { label: "A second bot", args: { token: "", alias: "support-bot" }, outcome: "Stored under that alias." }, + ], + returns: "`alias`, `fingerprint`, `last4`.", + pitfalls: ["Stored in a 0600 file under the user's agentproto home; setting it again rotates it. The token passes through your context once: do not echo it."], + humanGate: { + when: "always", + action: "The person creates the bot with @BotFather in Telegram and gives you the token it prints. No tool can create a bot or fetch that token.", + }, + }, + telegram_bot_token_status: { + effect: "read", + examples: [ + { label: "Is a token stored?", args: {}, outcome: "Returns `{ alias, configured, fingerprint, last4 }`, or `configured: false`." }, + ], + returns: "`configured`; compare `fingerprint` and `last4` to confirm which token is loaded.", + }, + telegram_bot_set_webhook: { + effect: "external", + examples: [ + { + label: "Point the bot at a public https URL", + args: { url: "https://bot.example.com/inbound/telegram" }, + outcome: "Calls Telegram's setWebhook with the stored token; returns `{ ok: true, alias, url, secret_token }`.", + }, + ], + returns: "`secret_token` (generated when omitted), the value Telegram echoes in a header on each delivery.", + pitfalls: [ + "Without a stored token it fails with `telegram_token_not_configured`: run `telegram_bot_token_set` first.", + "The URL must be public https and should end at an `inbound_endpoint_create` slug; keep `secret_token` and use it as that endpoint's secret.", + "A Telegram refusal is an error result carrying `telegram_error`.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/conversation.ts b/packages/runtime/src/tool-docs/conversation.ts new file mode 100644 index 000000000..ad8e59480 --- /dev/null +++ b/packages/runtime/src/tool-docs/conversation.ts @@ -0,0 +1,93 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `conversation-read.ts`, `conversation-export.ts`, + * `conversation-locate-tool.ts`, `session-tools.ts` (transcript_search, + * transcript_read: bounds and result shape), `docs/cli/verbs/conversation.md`. + */ +export const conversationToolDoc = defineToolFamilyDoc({ + family: "conversation", + title: "Conversations and transcripts: read what a session said", + summary: + "Read a session's native conversation, find which session owns a transcript file, copy a transcript into another harness's store, and search or excerpt a session and its predecessors.", + whenToUse: [ + "Recover what was said before a restart or a continue-fresh.", + "Find the session behind a transcript file, or the transcript behind a forgotten session.", + "Resume a daemon session's conversation in the native CLI of a harness.", + ], + workflow: [ + "To find a fact: `transcript_search` with a `query`, then `transcript_read` with a `since` cursor for context around it.", + "To read the whole native conversation: `conversation_read` (paged with `lastN` and `cursor`).", + "With only a session id or a file path: `conversation_locate` returns the owner and the native file.", + "To continue elsewhere: `conversation_export` writes a copy and returns the resume command.", + ], + cliCommands: [ + { + verb: "conversation", + command: "agentproto conversation locate sess_ab12cd34 --json", + note: "Same as `conversation_locate`; it also accepts a native transcript path.", + }, + ], + seeAlso: ["workspace-brain", "agent"], + tools: { + transcript_search: { + effect: "read", + examples: [ + { + label: "Find a decision made before a restart", + args: { sessionId: "", query: "retry budget", maxResults: 5 }, + outcome: "Returns `{ sessionId, query, chain, hits, truncated }`: dated excerpts, one bounded snippet per hit, across the session and its predecessors.", + }, + ], + returns: "`hits[]` (excerpt with its session and date), `chain` (the lineage walked), `truncated`.", + pitfalls: [ + "Case-insensitive substring match, not semantic. Defaults: 10 hits (max 50), 600 characters per excerpt (80 to 4000), 20000 characters in total (200 to 100000).", + "The chain follows `resumedFrom`, `continuedFrom` and `succeeds` links; a session with no such link searches only itself.", + "Give `sessionId`, `idOrName` or `slug`; none is an error.", + ], + }, + transcript_read: { + effect: "read", + examples: [ + { label: "The latest excerpts", args: { sessionId: "", maxRecords: 10 }, outcome: "Returns `{ sessionId, chain, excerpts, truncated }`." }, + { label: "Only what matches, after a cursor", args: { sessionId: "", query: "migration", since: 120 }, outcome: "Excerpts containing `migration` from records past sequence 120 of the target's own transcript." }, + ], + returns: "`excerpts[]` with sequence numbers to reuse as `since`.", + pitfalls: [ + "Bounded: 10 excerpts by default (max 50), 600 characters each (80 to 4000), 20000 total. Never a whole transcript: use `conversation_read` for that.", + "`since` applies only to the target session's own file; predecessors are read from their start.", + ], + }, + conversation_read: { + effect: "read", + examples: [ + { label: "Last 20 messages as markdown", args: { sessionId: "", lastN: 20 }, outcome: "Returns the rendered conversation with a `window` including `nextCursor`." }, + { label: "Page forward as JSON", args: { sessionId: "", format: "json", cursor: 40 }, outcome: "Starts at message index 40." }, + ], + returns: "The rendered conversation and `window.nextCursor`; or `{ conversation: null, reason }`, or a candidate list.", + pitfalls: [ + "A session with no underlying conversation (a bash or vim terminal) returns `conversation: null`: a normal outcome, not an error.", + "When discovery finds several candidate conversations it returns the list instead of guessing.", + "Read-only: it never spawns, resumes or writes.", + ], + }, + conversation_locate: { + effect: "read", + examples: [ + { label: "Session to transcript", args: { target: "sess_ab12cd34" }, outcome: "Returns `{ found: true, workspace, record, matchedBy: \"sessionId\" }`." }, + { label: "Transcript file to session", args: { target: "/path/to/native/conversation.jsonl" }, outcome: "Returns the owner session; `matchedSubagentPath` is set when the file was a subagent transcript." }, + ], + returns: "`found`, `record`, `workspace`, or `reason` when nothing matched.", + pitfalls: ["Not found is `{ found: false, reason }`, not an error. Useful after `session_gc` with `forget`, when the session is gone but its transcript is not."], + }, + conversation_export: { + effect: "write", + examples: [ + { label: "Make a Claude Code resumable copy", args: { sessionId: "", target: "claude-code" }, outcome: "Writes a copy into the native store and returns the conversation id, the written path and the `claude --resume ` command." }, + { label: "Scope it to another directory", args: { sessionId: "", target: "claude-code", cwd: "/path/to/repo" }, outcome: "The copy lands under the project slug of that directory." }, + ], + returns: "Conversation id, written path, resume command.", + pitfalls: ["It writes a copy into the harness's own store under the user's home; the daemon session is never modified and nothing is resumed for you. Only `claude-code` is supported."], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/index.ts b/packages/runtime/src/tool-docs/index.ts index b7f59cd1d..a5ac89925 100644 --- a/packages/runtime/src/tool-docs/index.ts +++ b/packages/runtime/src/tool-docs/index.ts @@ -50,6 +50,10 @@ import { llmEndpointToolDoc } from "./llm-endpoint.js" import { remoteToolDoc } from "./remote.js" import { sandboxToolDoc } from "./sandbox.js" import { tunnelsToolDoc } from "./tunnels.js" +import { channelsToolDoc } from "./channels.js" +import { reachToolDoc } from "./reach.js" +import { conversationToolDoc } from "./conversation.js" +import { workspaceBrainToolDoc } from "./workspace-brain.js" import type { ToolFamilyDoc } from "./types.js" import { worktreeToolDoc } from "./worktree.js" @@ -66,6 +70,10 @@ export type { } from "./types.js" export const TOOL_FAMILY_DOCS: readonly ToolFamilyDoc[] = [ + workspaceBrainToolDoc, + conversationToolDoc, + reachToolDoc, + channelsToolDoc, tunnelsToolDoc, sandboxToolDoc, remoteToolDoc, diff --git a/packages/runtime/src/tool-docs/legacy.ts b/packages/runtime/src/tool-docs/legacy.ts index 5d3a16777..668522ce5 100644 --- a/packages/runtime/src/tool-docs/legacy.ts +++ b/packages/runtime/src/tool-docs/legacy.ts @@ -31,9 +31,6 @@ export const LEGACY_UNDOCUMENTED_TOOLS: readonly DaemonToolName[] = [ "browser_screenshot", "browser_scroll", "capabilities_inventory", - "conversation_export", - "conversation_locate", - "conversation_read", "daemon_health", "directory_create", "directory_list", @@ -43,26 +40,10 @@ export const LEGACY_UNDOCUMENTED_TOOLS: readonly DaemonToolName[] = [ "file_read", "file_write", "host_load", - "inbound_endpoint_create", - "inbound_endpoint_delete", - "inbound_endpoint_list", - "inbound_watcher_list", - "inbound_watcher_start", - "inbound_watcher_stop", "live_session", - "reach_send", "role_list", "self_inspect", - "telegram_bot_set_webhook", - "telegram_bot_token_set", - "telegram_bot_token_status", "tool_calls_list", "tool_help", - "transcript_read", - "transcript_search", - "transmit_message", "usage_rollup", - "workspace_brain_ingest", - "workspace_brain_query", - "workspace_brain_status", ] diff --git a/packages/runtime/src/tool-docs/reach.ts b/packages/runtime/src/tool-docs/reach.ts new file mode 100644 index 000000000..9553b6609 --- /dev/null +++ b/packages/runtime/src/tool-docs/reach.ts @@ -0,0 +1,48 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `reach/tools.ts` (the tool and its limits), `reach/tell.ts` + * (statuses, dedupe). + */ +export const reachToolDoc = defineToolFamilyDoc({ + family: "reach", + title: "Reach: tell the owner something", + summary: "Send the owner a short, one-way notice on their phone or chat through the daemon's reach route.", + whenToUse: [ + "A session has news the owner would want to know now, and no answer is needed.", + "A long job finished or hit a blocker the owner should see without opening the daemon.", + ], + workflow: [ + "Call `reach_send` with a short `summary` and a stable `dedupeKey`.", + "Read `status`: a delivered status means the route took it; `deduped` means the same key already went out in the last 24 hours; `undelivered` carries a `reason` (for example `no-route`).", + ], + cliCommands: [], + seeAlso: ["messaging", "channels"], + tools: { + reach_send: { + effect: "external", + examples: [ + { + label: "Tell the owner a job finished", + args: { + summary: "Nightly migration finished, 0 errors.", + dedupeKey: "nightly-migration-2026-12-01", + links: [{ url: "https://example.com/runs/42", label: "Run" }], + }, + outcome: "Returns `{ status, adapterId?, attempts }` with one attempt per route entry tried.", + }, + { + label: "A digest-grade notice via a chosen route entry", + args: { summary: "Three PRs are waiting for review.", dedupeKey: "review-queue-digest", urgency: "digest", via: "" }, + outcome: "May be grouped with other digests; `via` is tried first and the rest of the route follows.", + }, + ], + returns: "`status`, `adapterId`, `attempts[]` (each with status and, on failure, `reason`).", + pitfalls: [ + "A tell only: no question, no answer comes back. Use `approval_request` when you need a decision.", + "`summary` is 1 to 1000 characters, at most 3 `links`, https only; at most 20 tells per session per day.", + "Without a reach route configured, the answer is `reach_not_available` or `undelivered` with `no-route`.", + ], + }, + }, +}) diff --git a/packages/runtime/src/tool-docs/workspace-brain.ts b/packages/runtime/src/tool-docs/workspace-brain.ts new file mode 100644 index 000000000..02a94fb97 --- /dev/null +++ b/packages/runtime/src/tool-docs/workspace-brain.ts @@ -0,0 +1,59 @@ +import { defineToolFamilyDoc } from "./types.js" + +/** + * Sources: `brain-tools.ts` (every tool, scope rule, limits), + * `docs/cli/verbs/brain.md` (CLI). + */ +export const workspaceBrainToolDoc = defineToolFamilyDoc({ + family: "workspace-brain", + title: "Workspace brain: search what a workspace's sessions did", + summary: "Keyword-search the ingested transcripts of a workspace, check how current that index is, and backfill or repair it.", + whenToUse: [ + "Recall a decision, an API or a file a past session touched, without knowing which session.", + "Check whether the index is up to date before trusting an empty answer.", + ], + workflow: [ + "`workspace_brain_status` first: a high `pending` or `staleSources` means answers may be incomplete.", + "`workspace_brain_query` with a `query`; hits carry the source session id in `metadata.sessionId` and the matching `text`.", + "`workspace_brain_ingest` to backfill pending sessions, re-ingest one session, or refresh stale sources.", + ], + cliCommands: [ + { + verb: "brain", + command: "agentproto brain query \"flaky test\" --workspace demo-app --topk 5 --json", + note: "Same as `workspace_brain_query`; `--workspace all` searches every workspace. Status and ingest have no CLI verb.", + }, + ], + seeAlso: ["conversation", "memory"], + tools: { + workspace_brain_query: { + effect: "read", + examples: [ + { label: "Search the calling session's workspace", args: { query: "worktree gc decision", topK: 5 }, outcome: "Returns `{ workspace, hits }` ranked by BM25, each with `sourceId`, `chunkId`, `text` (the snippet), `score` and `metadata.sessionId`." }, + { label: "Another workspace", args: { query: "flaky test", workspace: "demo-app" }, outcome: "Same, against that workspace's brain." }, + ], + returns: "`hits[]` (`text` is the snippet; `metadata.sessionId` is the source session; also `sourceId`, `chunkId`, `score`).", + pitfalls: [ + "Keyword (BM25) search, not semantic. `topK` is 1 to 50, default 10.", + "An unregistered `workspace` slug falls back to `default` instead of failing.", + "A caller confined to a node of a tree only sees hits from sessions visible to that node; a caller that cannot be identified is refused.", + ], + }, + workspace_brain_status: { + effect: "read", + examples: [{ label: "Index freshness", args: {}, outcome: "Returns indexed and pending session counts, skipped (unavailable) ones, `staleSources`, total bytes and whether it is query-ready." }], + returns: "`staleSources`, pending and skipped counts.", + pitfalls: ["`staleSources` are indexed under an older chunking version: a chunking fix does not apply to old data until they are re-ingested."], + }, + workspace_brain_ingest: { + effect: "write", + examples: [ + { label: "Backfill every pending session", args: {}, outcome: "Ingests the known-but-unindexed sessions of the workspace." }, + { label: "Re-ingest one session", args: { sessionId: "", reindex: true }, outcome: "Forces a re-ingest from its current transcript, retrying one skipped as unavailable too." }, + { label: "Refresh stale sources", args: { reindexStale: true }, outcome: "Also re-ingests indexed sessions behind the current pipeline version." }, + ], + returns: "Counts of ingested and skipped sessions and `staleSources`.", + pitfalls: ["The daemon already ingests on session exit: use this for backfill or repair. `reindexStale` applies only without a session ref."], + }, + }, +}) diff --git a/packages/skill-pack-agentproto/cli-verbs.json b/packages/skill-pack-agentproto/cli-verbs.json index 982d212b1..6b61b9ae1 100644 --- a/packages/skill-pack-agentproto/cli-verbs.json +++ b/packages/skill-pack-agentproto/cli-verbs.json @@ -20,9 +20,6 @@ "acp": { "exception": "protocol entry point started by editors, not run by an agent" }, - "brain": { - "exception": "no skill presents this verb yet" - }, "catalog": { "exception": "no skill presents this verb yet" }, @@ -32,9 +29,6 @@ "chat-tui": { "exception": "interactive terminal UI, no agent-facing workflow" }, - "conversation": { - "exception": "no skill presents this verb yet" - }, "daemon": { "skill": "ap-run-command" },