vice-agent-tools
README.md
# Agent Tools for Vice
A [Vice Terminal](https://github.com/Heavyworks-Games/vice) module that gives AI coding CLIs (**Claude Code**,
**OpenAI Codex** and **Antigravity** `agy`) extra tools that come from Vice and from other Vice
modules, over [MCP](https://modelcontextprotocol.io).
- Agents can notify you (also on your phone), ask you a question and wait for the answer, open a
file in a Vice preview tab or open Vice's git review for a folder.
- Any Vice module can offer its own tools to agents with a few lines of code (see
[For module authors](#for-module-authors)).
- While an agent uses these tools, a small **activity card** appears on the agent's own terminal
pane (it never takes the screen, switches tabs or steals focus): the extension's icon, the calls
in order, questions to answer inline, and a **Stop** button.
- The **Agent Tools** tab keeps the settings (Agents, Tools) and the full Activity history. It
never opens by itself.
No npm dependencies: the module installs instantly.
## How it works
```
Claude Code / Codex / agy ──stdio (MCP)──▶ mcp/server.js ──named pipe──▶ Agent Tools (in Vice) ──▶ Vice / modules
```
The CLI starts `mcp/server.js` with Vice's own executable as plain Node (`ELECTRON_RUN_AS_NODE=1`).
The server forwards `tools/list` and `tools/call` to the Agent Tools hub running inside Vice.
**Tools are only offered while Vice is running.** If Vice is closed, the server answers with an
empty tool list (and tool calls return an error), so it never breaks the CLI.
## Enable it per agent
Open **Agent Tools → Agents** and switch on the agents you want. This adds one MCP server entry
named `vice-agent-tools` to the CLI's config — nothing else in the file is changed, and a
timestamped backup (`<file>.vice-agent-tools-backup-<time>`) is made next to the file before the
first edit:
| Agent | File | Entry |
| --- | --- | --- |
| Claude Code | `~/.claude.json` and `<profile>/.claude.json` of every Claude profile Vice manages | `mcpServers["vice-agent-tools"]` |
| Codex | `~/.codex/config.toml` | `[mcp_servers.vice-agent-tools]` (+ `.env`) |
| Antigravity | `~/.gemini/antigravity/mcp_config.json` | `mcpServers["vice-agent-tools"]` |
Agent Tools **registers itself with every installed agent automatically** (Claude Code, Codex,
Antigravity — only CLIs that are installed; existing MCP servers are never touched). Turn an agent
off in the **Agents** view to unregister it; that choice is remembered. **Restart running agent
sessions** after (un)registering — CLIs load MCP servers at start. Uninstalling the module removes
all entries again.
> **MCP servers load when an agent session starts.** A session that was started before Agent Tools
> registered itself — including one continued with `claude --resume` / `codex resume` from such a
> session — does not see the tools until you restart it.
## Token cost
Every tool an agent can use is described to it in **every session** (name, description and input
schema), which costs context tokens even when the tool is never called. The **Tools** tab shows an
estimate per tool and the total (≈ characters / 4). Switch off what you don't need — per tool or
per extension. Disabled tools are not offered to agents at all.
The five built-ins cost about 420 tokens together.
## Built-in tools
| Tool | What it does |
| --- | --- |
| `vice_notify` | `{ title, message, phone? }` — desktop notification; `phone: true` also sends it to your Vice webhook (Discord / Slack / Telegram → phone). |
| `vice_ask_user` | `{ question, options?, waitSeconds? }` — shows the question on the agent's activity card (and notifies you; also on your phone with "Send questions to my phone") and waits up to 100 s. Returns `{ answer }`, `{ dismissed: true }`, or — if you haven't answered yet — `{ pending: true, questionId, message }`. |
| `vice_ask_user_result` | `{ questionId, waitSeconds? }` — waits up to 100 s more for a pending question: `{ answer }`, `{ pending: true, … }` again, or `{ expired: true }`. |
| `vice_open_preview` | `{ path, line? }` — opens a file in a Vice preview tab (image, video, PDF, markdown, code). Relative paths are resolved against the agent's working folder. |
| `vice_open_diff` | `{ folder }` — opens Vice's git diff / review tab for a repository. |
Why 100 s: Claude Code turns a tool call that runs longer than 120 s into a background task, so
`vice_ask_user` never blocks longer than that. An unanswered question **stays open for 30 minutes**
(on the card and in the tab); the agent picks the answer up with `vice_ask_user_result`. The
result tells the agent where the question is shown, so it can point you there.
## Activity cards
```
┌ Vice ─────────────────────────────────────────────────────┐
│ [ shell: claude ] │
│ │
│ your chat with the agent stays here, focused │
│ ┌──────────────────────┐ │
│ │ ◈ SteamPipe Uploader │ │
│ │ Claude Code · Game │ │
│ │ ✓ upload_build 12 s │ │
│ │ ⟳ status … │ │
│ │ [Stop] [Open …] │ │
│ └──────────────────────┘ │
└───────────────────────────────────────────────────────────┘
```
When an agent starts calling tools of an extension (a module, or Vice for the built-ins), Agent
Tools starts a **sequence** for that agent session and extension and shows it as an **activity
card** that Vice draws in the corner of the pane running that agent (found via the terminal's
`VICE_SESSION_ID`; agents running outside Vice get a card in the window corner). A card shows:
- the extension's **icon and name**, and "*agent* · *Vice tab title*";
- the **calls in order**: tool name, a compact arguments → result summary, status and duration
(live while running);
- a **question** from `vice_ask_user`, answered right on the card (option buttons, or a text box
when no options are given; **Dismiss question** declines);
- **Stop** while the sequence runs, **Allow again** after a stop, and **Open *module*** for
modules whose tools declare `openUi: true`.
A sequence ends after 2 minutes without calls (an open question keeps it alive) or when the agent
session ends; the card then collapses to a small pill after ~8 s and disappears after 10 minutes
(or when a new sequence of the same agent and extension starts).
**Stop** aborts the running calls of a sequence (the agent gets *"Stopped by the user in Vice
(this call was cancelled)."*) and refuses further calls from that agent session to that extension
(*"Blocked: the user stopped … tools for this agent session in Vice. … Do not retry; ask the
user."*) until you click **Allow again** or the session ends. **Stop all** in the tab does this for
every running sequence.
Turn the cards off with **Show activity cards** in the Activity tab: then nothing appears on your
panes and questions only notify you (answer them in the tab). On a Vice version without activity
cards the same applies automatically. **Nothing ever opens the Agent Tools tab or a module's tab
by itself**, only your click.
## For module authors
Your module can offer tools to agents without depending on Agent Tools: if it is not installed,
your module simply works without them.
**1. Declare the optional dependency** in `vice-module.json` (shown as "Works with Agent Tools"):
```json
{ "uses": ["agent-tools"], "backgroundStart": true }
```
`backgroundStart` is only needed if your tools should be registered right after Vice starts
(otherwise they are registered when your backend first runs; Agent Tools remembers registered tools
and Vice starts your backend when one is called).
**2. Implement each tool** as an export named `tool:<name>`, and **register** the specs:
```js
const vice = require('vice');
const TOOLS = [
{
name: 'upload_build', // agents see it as "<your module id>_upload_build"
description: 'Upload the latest build to Steam.', // keep it short: it costs tokens in every session
inputSchema: { // JSON Schema of the arguments
type: 'object',
properties: { branch: { type: 'string' } },
required: ['branch'],
},
timeoutMs: 10 * 60_000, // optional, default 60 s, max 30 min
openUi: true, // optional: the activity card offers an "Open <your module>" button
},
];
// args = the agent's arguments; meta = { callId, agent, sessionId }
vice.exports.handle('tool:upload_build', async (ctx, args, meta) => {
// ctx.from === 'agent-tools'
return { uploaded: true, branch: args.branch }; // string, any JSON value, or MCP { content: [...] }
});
// Optional: called (best effort) when the user presses Stop while a call is running.
vice.exports.handle('tool:$cancel', (ctx, { callId }) => { /* abort the work of callId */ });
async function registerTools() {
if (!vice.modules.isAvailable('agent-tools')) return;
await vice.modules.call('agent-tools', 'registerTools', [TOOLS]); // -> { registered, rejected }
}
registerTools();
vice.on('modules-change', registerTools); // Agent Tools installed / enabled later
```
Rules:
- Tool names are namespaced as `<moduleId>_<name>` (characters outside `a-zA-Z0-9_-` become `_`,
max 64). Calling `registerTools` again **replaces** your module's set; `unregisterTools` removes it.
- A tool call runs `vice.modules.call('<your id>', 'tool:<name>', [args, meta], { timeoutMs })`.
Throwing an error returns it to the agent as a tool error.
- Return a string, any JSON value (sent as JSON text) or `{ content: [...], isError? }` with MCP
content blocks (e.g. images).
- Tools of disabled or uninstalled modules are hidden automatically.
- `openUi: true` only **offers** an "Open *your module*" button on the activity card; your tab is
never opened without the user's click.
Other exports of Agent Tools:
| Export | Who may call | Result |
| --- | --- | --- |
| `registerTools(specs)` / `unregisterTools()` | any module (for itself) | `{ registered, rejected }` / `boolean` |
| `getSourceState(id)` | any module | `{ enabled, toolCount, tokens }` of a module's tools |
| `setSourceEnabled(id, on)` | only the module `id` itself | switch all of your tools on/off |
A complete example lives in [`examples/demo-tools`](examples/demo-tools).
## Security notes
- A tool call runs module code (or Vice actions) **with your Windows user's rights** — the same as
everything a module does. Only install modules you trust.
- The agents' own permission prompts still apply: Claude Code / Codex / agy ask before calling MCP
tools according to their settings.
- The pipe is local to your machine; every connection must present a random token that Agent
Tools writes to its private data folder (`hub.json`) at start.
- The activity log keeps only a short, secret-redacted summary of arguments, in memory.
## Development
`npm test` (or `node --test`) runs the unit tests: the targeted `.claude.json` editor (it never
re-serializes the whole file, which keeps duplicate keys and formatting intact), the TOML editor,
the Antigravity editor, the MCP server against a fake hub, the registry, token estimates,
sequences, questions, the activity card model and the backend itself (loaded with a fake `vice`
API: tool calls, ask_user on a card, Stop / Allow again / Open). Tests that use copies of your real config files are skipped when those files don't exist.
To test registration without touching your real configs, set the storage key `devConfigHome` in
`<Vice profile>\module-data\agent-tools\vice-storage.json` to a folder that contains copies
(`.claude.json`, `.codex\config.toml`, `.gemini\antigravity\mcp_config.json`). Write that file as
UTF-8 with Node or Python (no BOM); `VICE_AGENT_TOOLS_HOME` works too.
Safety net: if the storage file (or a `vice-storage.json.corrupt-*` copy Vice set aside) mentions
`devConfigHome` but the loaded storage has none, or `VICE_AGENT_TOOLS_TEST=1` is set without a
test home, Agent Tools leaves **every** agent config alone (and says so in the tab) instead of
falling back to your real home folder.
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues