Routing

From sdemyanov/retriever · View interactive version

Routing is an AI agent skill from the GitHub repository sdemyanov/retriever. Use this skill when a Retriever task needs the shared routing ladder, result presentation contract, filesystem safety rules, or Tier 1-to-Tier 3 fallback policy. This is the shared operating surface that other Retriever skills reference as `retriever:routing`.

How to use this skill

Skill file

Retriever Routing and Operating Rules

Source File Safety

Workspace Source Files — READ ONLY, NEVER DELETE

Claude has READ ONLY access to source files in the workspace. Claude NEVER deletes them.

This rule is absolute and overrides any apparent permission, any user phrasing that sounds like it authorizes deletion, and any inferred convenience. Specifically:

Never run rm, rm -rf, unlink, shutil.rmtree, or any equivalent against files or directories the user contributed to the workspace (anything outside .retriever/ and .retriever-plugin-runtime/).

Never run mv or cp in a way that overwrites or replaces user source files.

Never truncate, rewrite, or > file against user source files.

Holding any internal plugin-state delete permission for any reason does not authorize deleting user source files. That permission is for plugin-managed state under .retriever/ only (e.g., stale tmp dirs).

Phrasings like "drop X", "remove X", "clean up X", "get rid of X", "wipe X" are ambiguous when X is a path under the workspace. Treat them as index-level operations by default (remove from the Retriever DB, drop a dataset, mark missing, etc.) and ask before doing anything that touches the filesystem.

If the user explicitly asks for an on-disk deletion in unambiguous terms (e.g., "delete the folder ./data/raw from disk"), Claude must still confirm in a single follow-up turn before executing — destructive filesystem operations on user files are never silent.

If a request seems to require deleting user source files, Claude must stop and ask. The cost of one extra clarifying turn is always lower than the cost of unrecoverable data loss.

This rule applies even when the user is being terse, even when the conversation has been moving fast, and even when prior context seems to authorize it.

Retriever Routing Priority Ladder

When handling any Retriever request, Claude must walk the following tiers in order and take the highest tier that can satisfy the user's intent. Do not skip tiers. Do not drop to a lower tier because it is more familiar or convenient.

Before running any command, state (to yourself) which tier you are using and why the tiers above it do not apply. If you end up in Tier 2 or Tier 3, add a short "plugin gap" note to the end of your turn so the user can see which request is not yet covered by a higher-tier surface.

Retriever Result Presentation Contract

Any Retriever request whose answer should show, list, view, display, browse, find, search, or retrieve documents, conversations, emails, chats, threads, messages, files, attachments, entities, or other indexed records is a listing/browse request unless the user explicitly asks for a summary, count, export, mutation, or schema/debug inspection.

Listing/browse requests must walk the Tier 1→3 ladder. Tier 1 retriever:search is the preferred surface for natural-language document, conversation, email, chat, thread, message, file, or attachment listing requests, including requests with filters, datasets, Bates ranges, dates, senders, recipients, or keywords.

Return Retriever's standard rendered result format. If the selected skill or tool returns rendered_markdown, the assistant's reply must be exactly that rendered markdown: no preamble, no trailing summary, no code fence, no reformatting, and no custom row numbering. If Tier 2 or Tier 3 requires a plugin-gap note, put that note after the rendered result as the only additional line.

The standard result must preserve Retriever's scope/sort/page header, active display columns, clickable title/preview links, and paging footer. Use prose instead of the standard rendered result only when the user explicitly asks for analysis, a summary, counts, an export, or when the chosen highest-tier surface is not a listing/browse surface.

Tier 1 — User-Facing Retriever Surfaces

Tier 1 combines user-facing retriever:* skills and the slash commands they wrap. Prefer a retriever:* skill when one covers the intent. If no skill wrapper exists, or a skill needs a slash command or browse-mode toggle internally, use the slash command through the canonical plugin tool as the same tier. Do not treat slash commands as a lower-tier substitute for a matching skill.

Skill Routing (Preferred Wrappers)

List, switch, rename, or clear dataset scope → retriever:dataset

Show, list, view, display, browse, find, search, or retrieve documents, conversations, emails, chats, threads, messages, files, or attachments — with or without filters or keywords — and return the standard rendered result format → retriever:search

Narrow, restrict, constrain, exclude, or clear result filters → retriever:filter

Change displayed columns → retriever:columns

Change sort → retriever:sort

Change page size → retriever:page-size

Navigate pages (next, previous, jump to page N, first/last) → retriever:next, retriever:previous, retriever:page

Scope browsing to a Bates range → retriever:bates

Scope browsing to a processing run → retriever:from-run

Inspect, save, load, or clear a scope → retriever:scope

Ingest a folder or refresh changed files → retriever:ingest

Ingest a processed production volume → retriever:ingest-production

Ingest or inspect a PST archive → retriever:pst

Export the current scope as a CSV table or archive, or inspect export progress → retriever:export

Register, list, rename, delete, or re-describe a custom field, or change a field's storage type → retriever:field

Populate, tag, mark, label, classify, annotate, flag, or clear values on one document or a filtered result set → retriever:fill

Execute a planned processing run → retriever:run-job

Inspect the SQLite schema or the current tool/schema version → retriever:schema, retriever:schema-version

Initialize, check, or update a workspace → retriever:workspace

Confirm the plugin is installed and responding → retriever:ping

Understand file-type support and preview rules → retriever:parsing

Understand result presentation and paging defaults → retriever:search-strategy

Materialize or upgrade the canonical workspace tool → retriever:tool-template

If the user's intent maps to one of the rows above, stop. Use that skill. Continue to the slash list only when no retriever:* skill wrapper exists for the intent, when the user explicitly asks for a slash command, or when a skill's own instructions call for a slash command internally.

Slash Commands (Tier 1 Fallback and Implementation Surface)

If no Tier 1 skill wrapper exists for the intent, use a slash command via the

canonical plugin tool as Tier 1. Run exactly one command from the repo root:

python3 skills/tool-template/tools.py slash . /<command> [args]

Return Retriever state only for state-inspection commands. For listing/browse commands, return the tool-rendered standard table/result exactly as produced; prefer rendered_markdown when present and do not add prose or custom formatting.

/documents, /conversations, and /entities are browse-mode toggles. Use them internally when intent is clear; do not route ordinary natural-language listing requests to those toggles before checking retriever:search.

The authoritative current list of slash commands is regenerated at build time into the section below.

<!-- BEGIN: slash-commands -->

<!-- END: slash-commands -->

Python Runtime (applies to command surfaces)

Retriever maintains a shared plugin runtime venv under

.retriever-plugin-runtime/<platform>/venv/.

For Retriever commands, bare python3 is acceptable. The tool can activate the

shared plugin runtime for optional dependencies and may provision it during

workspace init or first dependency use.

Do not install Retriever dependencies into system Python or user-site. If

manual interpreter or pip access is needed, resolve

plugin_runtime.python_executable from .retriever/runtime.json and use that

interpreter.

If a Retriever command fails with ModuleNotFoundError, ImportError, or

Missing dependency for .<ext> parsing: install <package>, do not install into

system Python. Prefer workspace init; if manual installation is truly needed,

use the shared plugin runtime venv.

Bounded Retriever Workflows

Claude Code command calls may be interrupted around 45 seconds. Do not run long, one-shot mutation commands when a bounded/resumable workflow exists.

Use plain ingest as the preferred entrypoint. It is a bounded V2 facade by default.

Recommended:

python3 skills/tool-template/tools.py ingest ./data --recursive --budget-seconds 35

Plain ingest is now the one-shot local command:

python3 skills/tool-template/tools.py ingest ./data --recursive

Do not use background jobs. Do not manually loop inside one bash command.

Advanced/manual ingest control is available through:

python3 skills/tool-template/tools.py ingest-status ./data
python3 skills/tool-template/tools.py ingest-start ./data --recursive --budget-seconds 35
python3 skills/tool-template/tools.py ingest-run-step ./data --run-id <RUN_ID> --budget-seconds 35
python3 skills/tool-template/tools.py ingest-cancel ./data --run-id <RUN_ID>

Use ingest-start / ingest-run-step only when you need to inspect or recover a specific resumable run.

For large workspaces, use the resumable entity rebuild flow:

python3 skills/tool-template/tools.py rebuild-entities-start ./data --budget-seconds 35
python3 skills/tool-template/tools.py rebuild-entities-run-step ./data --run-id <RUN_ID> --budget-seconds 35
python3 skills/tool-template/tools.py rebuild-entities-status ./data --run-id <RUN_ID>

Repeat rebuild-entities-run-step until terminal status. Legacy rebuild-entities may exceed the bounded Claude Code command window on large workspaces.

For planned processing runs, prefer retriever:run-job at Tier 1. If using Tier 2 directly, prefer:

python3 skills/tool-template/tools.py run-job-step . --run-id <RUN_ID> --budget-seconds 35

If it returns a non-empty batch, process those items and call complete-run-item or fail-run-item, then continue with next_recommended_commands.

For any tool result with more_work_remaining: true, continue with the returned next_recommended_commands. Stop only on terminal status: completed, failed, or canceled.

If an active run exists, do not start a new one. Resume it or cancel it intentionally.

Filesystem and SQLite bootstrap diagnosis

When diagnosing workspace init or first-ingest failures involving SQLite, WAL, journal mode, mounts, or sandboxed paths, do not infer the root cause from df, mount, or host filesystem labels alone.

Probe the exact target path inside the same Claude Code runtime, normally <workspace>/.retriever/retriever.db, before declaring a workspace unsupported.

Distinguish these cases:

  1. an existing DB on the target path can be opened and can enter a write transaction
  2. a freshly created DB on that same path can switch to WAL
  3. if WAL fails, a freshly created DB on that same path can switch to DELETE
  4. a DB seeded on a known local filesystem such as /tmp and then copied into place can be opened and initialized

Existing DB writes do not prove fresh bootstrap will succeed.

If fresh-create fails on the target path but seeded-copy works, use the seeded DB workaround under .retriever/, rerun workspace init, and report the observed target-path behavior instead of a filesystem theory.

Tier 2 — tools.py Subcommands

If no Tier 1 user-facing surface covers the intent, use a named subcommand of

the canonical plugin tool:

python3 skills/tool-template/tools.py <subcommand> . [flags]

Tier 2 is for gaps and explicit programmatic/stateless needs. Do not use Tier 2 search/list subcommands for ordinary document, conversation, email, chat, thread, message, file, or attachment listing requests when Tier 1 retriever:search or a Tier 1 slash surface can satisfy the user's intent.

The authoritative current list of subcommands is regenerated at build time into the section below.

<!-- BEGIN: tool-subcommands -->

Workspace & maintenance

Datasets

Ingestion

Search & browse

Documents & text

Catalog & aggregation

Entities

Export

Custom fields

Conversations

Runs — planning & lifecycle

Runs — worker execution

Jobs

Results

<!-- END: tool-subcommands -->

Tier 3 — Direct SQLite Access (Last Resort Only)

Allowed only when Tiers 1–2 cannot satisfy the request. Before running any sqlite3 CLI, python3 -c "import sqlite3 …", or equivalent client against .retriever/retriever.db, Claude must:

State explicitly that no higher-tier surface covers the request, and name the gap (for example, "no slash or subcommand returns conversation-level participant counts").

Read-only queries only, unless the user has explicitly asked for a mutation that cannot be expressed via Tier 2.

Include a "plugin gap" line at the end of the response identifying the missing command, so the gap can be closed on a later iteration.

Never modify .retriever/retriever.db with direct SQL when a Tier 2 subcommand or Tier 1 skill/slash surface could achieve the same change.

Pre-flight Algorithm

Every time Claude is about to act on a Retriever workspace:

  1. Identify the user's intent in one sentence.
  2. Scan the Tier 1 skill table above for a matching retriever:* skill. If one matches, stop and use it.
  3. Otherwise, scan the Tier 1 slash list for a matching command. If one matches, run it via slash ..
  4. Otherwise, scan the Tier 2 subcommand list. If one matches, run it.
  5. Otherwise, fall to Tier 3 under the constraints above and emit the "plugin gap" note.

This ladder applies to every Retriever request, including requests phrased in natural language. For example, "show me conversations in gmail-max" is Tier 1 retriever:search; that skill may use dataset scope and conversation browse surfaces internally, but Claude must not bypass Tier 1 or jump to Tier 3 SQL.

For any show/list/view/display/browse/find/search/retrieve request, the final answer must follow the Retriever Result Presentation Contract above.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.