agent-tool-audit
Skill15 starsChanged 6 days agoMITView on GitHub
Audit Anvia (@anvia/core) tool definitions, createTool handlers, output schemas, and onToolOutput middlewares against plain-text formatting conventions, metadata separation, truncation guardrails, and runtime safety hygiene. Use when reviewing or building Anvia tools, checking whether tools return raw JSON vs. structured plain text, verifying line-number anchoring, or hardening tool contracts. Manual invocation only — do not auto-invoke unless explicitly requested by the user.
In this repository14 other files it gives its agents.
- agent-instruction-auditSkill
- changes-verificationSkill
- cheap-ui-auditSkill
- code-reviewSkill
- create-prSkill
- debuggingSkill
- engineering-decisionSkill
- formal-verificationSkill
- micro-animationSkill
- optimistic-uiSkill
- optimize-ciSkill
- oxlint-setupSkill
- test-auditSkill
- zstack-modeSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
Compact, Scannable Search & List Results: Search tools should group matches by file path with line numbers (path/to/file.ts:\n Line 42: …
- Very specific: line 28
Use handler instead of deprecated execute in createTool(...).
- Very specific: line 29
Keep createTool({ examples }) concise (rendered into tool descriptions on every turn), add concise .describe(...) hints on non-obvious Zod …
- Very specific: line 38
Optional Automated Guard: If the repository has a test suite for tools, recommend adding the invariant check in …
- Very specific: line 42
Do not flag external @anvia/mcp servers (registered via Agent.mcpServers) for returning JSON payloads.
- Very specific: line 43
Do not confuse the outer provider/stream transport envelope (ToolResultEventPayload / { type: "tool-result", output }) with the inner …
- Very specific: line 44
If a file happens to contain JSON content (e.g., package.json), read_file returning line-numbered JSON text (00001| {) is valid because the …
- Very specific: line 45
If using @anvia/tool-sandbox's built-in createSandboxTools(...) (whose default outputSchema returns JSON objects), do not fork the package …
- Very specific: line 46
Never auto-invoke agent-tool-audit.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Agent Tool Audit (Anvia)
Evaluate every createTool(...) / Tool implementation, @anvia/tool-sandbox wrapper, and createMiddleware({ onToolOutput }) handler in an Anvia codebase against plain-text LLM output conventions and Anvia runtime best practices, and produce a concrete refactoring report.
- Invocation: Manual-only (
disable-model-invocation: true). Run only when explicitly invoked by the user.
When to Use
- Reviewing existing Anvia tools (
createTool, customToolimplementations,@anvia/tool-sandboxtools,agent.asTool(...)) for token efficiency, LLM readability, and Anvia runtime hygiene. - Designing new
@anvia/core/toolhandlers and verifying their return shape (string/ToolOutput.content(...)vs. raw JSON objects). - Auditing
createMiddleware({ onToolOutput })truncation/spill gates to ensure they emit clean plain text rather thanJSON.stringify(...)blobs.
Core Principles (Anvia-Optimized)
- Plain Formatted Text over JSON (
stringorToolOutput.content): In Anvia, returning an object/array fromcreateToolcausesnormalizeToolResultOutputto wrap it as{ type: "json" }, whichtoolOutputToTextserializes via rawJSON.stringify(...)into the LLM context. Built-in and application tools must return clean, formattedstringoutputs (withoutputSchema: z.string()or no JSON objectoutputSchema)—orToolOutput.content([...])when returning multimodal text + files—never raw JSON objects, arrays, orJSON.stringify(...)strings. - Metadata Separation via Anvia Observability / Lifecycle / Middleware: Keep UI and telemetry metadata (
durationMs,bytesWritten,stdoutTruncated,exitCode: 0, full diffs, raw records) out of the LLM-facing string. Emit UI/telemetry state viaAgent.lifecycle(onToolFinish),Agent.observability, orToolCallContext.emitStreamEvent(...)—or reshape structured outputs into compact plain text insidecreateMiddleware({ onToolOutput }). Only surface metadata inside the text string when the model needs it to decide the next step (e.g., non-zero exit code, pagination cursor, truncation notice). - Line-Number Anchoring: File-reading tools (
read_file/ custom readers) must prefix lines with 1-based line numbers (00001|orL1:) and append a plain-text pagination footer (Showing lines 1-200 of 420. Call read_file with startLine=201 to continue.) instead of returning{ content, startLine, endLine, nextStartLine, truncated }JSON. - Compact, Scannable Search & List Results: Search tools should group matches by file path with line numbers (
path/to/file.ts:\n Line 42: ...). Directory/list tools (list_files,list_processes,list_ports) should emit compact newline-separated entries instead of JSON arrays of objects. - Actionable Confirmations: Mutation tools (
write_file,edit, domain write tools) should return concise confirmation strings (plus compiler/linter/validation diagnostics if triggered) instead of echoing the full payload or returning{ ok: true, path, bytesWritten }JSON blobs. - Hard Truncation Guardrails & Anvia Runtime Hygiene:
- Enforce line and byte caps inside high-volume tools AND backstop with a
createMiddleware({ onToolOutput })output gate that truncates or spills oversized results to disk and returns a plain-text pointer (notJSON.stringify({ type: "file_reference", ... })). - Use
handlerinstead of deprecatedexecuteincreateTool(...). - Keep
createTool({ examples })concise (rendered into tool descriptions on every turn), add concise.describe(...)hints on non-obvious ZodinputSchemafields, propagatecontext.abortSignalandcontext.operationId(for@anvia/durableidempotency), and setrequiresApprovalon destructive/irreversible tools.
- Enforce line and byte caps inside high-volume tools AND backstop with a
Audit Workflow
- Discover & Inventory: Locate all
createTool(...)calls, customToolobjects,@anvia/tool-sandboxregistrations,agent.asTool(...)wrappers, andcreateMiddleware({ onToolOutput })middlewares. Readreferences/format-examples.mdfor canonical Anvia plain-text templates and refactoring patterns. - Audit Each Tool & Output Middleware: Inspect what enters the LLM context (return value of
handler/execute,outputSchema, andonToolOutputreplacements) plus Anvia runtime hygiene (handlervsexecute,abortSignal/operationId,requiresApproval,examplesbloat) and grade each item:PASS: Returns clean, bounded plain text (orToolOutput.contentfor multimodal), separates UI/telemetry metadata cleanly, and follows Anvia runtime hygiene.NEEDS REFACTOR: Returns raw JSON objects/arrays orJSON.stringify(...), lacks line numbers or truncation guardrails, uses deprecatedexecute, or leaks noisy metadata into LLM tokens.
- Generate Report: Output a Markdown summary table (
Tool / Middleware,File Path,Current Return Shape,Status,Issues Found), followed by exact before/after TypeScript diffs showing how to refactor failing tools (includingonToolOutputadapters when wrapping upstream tools likecreateSandboxTools). - Optional Automated Guard: If the repository has a test suite for tools, recommend adding the invariant check in
scripts/assert-plain-text-output.jsagainsttool.call(...)results andtool_resultstream events to prevent regressions.
Gotchas
- Do not flag external
@anvia/mcpservers (registered viaAgent.mcpServers) for returning JSON payloads; MCP tool schemas are externally controlled. (Do flag MCP tools mistakenly passed intoAgent.tools.) - Do not confuse the outer provider/stream transport envelope (
ToolResultEventPayload/{ type: "tool-result", output }) with the inner LLM-facingoutputvalue. - If a file happens to contain JSON content (e.g.,
package.json),read_filereturning line-numbered JSON text (00001| {) is valid because the tool wrapper itself is line-numbered plain text. - If using
@anvia/tool-sandbox's built-increateSandboxTools(...)(whose defaultoutputSchemareturns JSON objects), do not fork the package unnecessarily—recommend formatting its outputs into compact plain text via a dedicated AnviacreateMiddleware({ onToolOutput })adapter. - Never auto-invoke
agent-tool-audit; wait for explicit user activation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

