/skardi:skardi-query-logfrom skardi
Checks a query ledger before sending SQL to Skardi, reusing working queries and recording failures. Routes all ad-hoc queries through this log to avoid rewriting SQL.
Ships in skardi. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
The first job of this skill is to stop you rewriting SQL you already got working.
Here is how it actually goes: the user says "show me how long the open PRs have been sitting", you write a SQL statement on the spot, send it, hand back the answer. Next week they ask again — but that is a different session and you remember nothing, so you write it again, including the wrong version you wrote the first time.
The ledger records which statement worked last time. The second time should be free. You should not have to wait for the tenth.
ask.py "<what you are trying to find out, in plain words>" # has this been asked? here are the candidates
ask.py "<the same sentence>" --sql "<SQL>" # run it for real; on success it is filed in the index
When the query is part of a task that already has a session id and a task line (the way retrieval runs), pass both with --session-id "$SKARDI_SESSION" --task "<task line>", so the final query sits in the ledger next to the peeks that led to it. Without --session-id it reads $SKARDI_SESSION, and failing that mints a fresh id; --task is sent only when given, so leave it off on a server build that does not take it.
Why this is a command and not a line in a document saying "remember to check the log first": because that does not work. This machine has a hand-written note sitting on it that says to query through Skardi and names the tables; the person who wrote it was using a different tool the next day. Expecting yourself to remember to look is a mechanism that has already failed. So the check goes on the path the query has to take — you cannot query without going through it, and going through it means you see it.
Step one gives you candidates. Whether one of them is the same question is your judgement — the script fetches and coarse-filters, it does not decide meaning. If one matches, copy that SQL (adjust the parameters for this time). If none does, write your own and run it with --sql anyway.
Even when you already know the SQL, go through this command with a question, because the bookkeeping happens at this step. Without it the next session starts empty-handed again.
The index holds one row per question, not one per query — so it grows with how many distinct questions you ask, not how many times you ask them. Ten thousand queries across a few dozen questions is still a few dozen rows. Questions unused for a long time retire from the candidate list on their own; the entry and the raw log both stay.
ask.py needs to know where Skardi is and where to keep the index. It reads a small JSON file, by default ~/.skardi/query-tool.json:
{
"url": "http://127.0.0.1:8099/query",
"index": "/absolute/path/to/known-questions.json",
"audit_db": "/absolute/path/to/audit.db"
}
Point --config at it if you keep it elsewhere, or override --url / --index per call. audit_db is optional and only powers the "N queries are still unfiled" hint.
One config file serves one server: its index holds that server's SQL. ask.py checks where the skardi CLI is pointed ($SKARDI_SERVER_URL, else the current context) and stops with exit code 3 when that is a different server from url, sending and listing nothing. For a second server, keep a second config file with its own url and index, and pass it with --config.
Keep the index out of the skill directory. It holds your real queries and real field names, and a skill directory is something you might hand to someone. Put it next to the audit database, or anywhere else that is yours.
An empty index is worth nothing on day one, so the first pass has to come from somewhere. It is the same command for the top-up later; each run lists only what is not filed yet:
seed_index.py --db <audit db> --index <index file> # what is still unfiled?
seed_index.py --db <audit db> --index <index file> --keep q003,q007 # file these; mark the rest as unwanted
Why there is an "unfiled" bucket at all: queries sent around ask.py still land in the audit log, they just never reached the index. This command picks them back up, so going around ask.py is not a permanent loss — at worst you lose the plain-words question, which is what ask.py writes in and a bare request usually does not carry. Step one of ask.py tells you when there are some waiting.
Pick them yourself; do not automate this. The log mixes your own test runs and sample data with real work, and those carry a purpose too, so the script cannot tell them apart. Take everything and the index is dirty on day one, and nobody trusts a dirty index. What you reject is remembered and you are not asked about it twice.
Everything in that batch that you do not pass to --keep is recorded as unwanted, so run it once without --keep and look before deciding. The ids are only valid within the batch being listed.
A successful query has to repeat before it is useful (the second asking is when last time's SQL pays off), so there is little to squeeze out of a light user. Failures are different — one row carries information.
read_failures.py --db <audit db> # sorted by what the error says
read_failures.py --db <audit db> --index <index file> # also pair "failed, later worked"
read_failures.py --db <audit db> --index <index file> --keep p004 # file it, so it shows before the next query
Errors contain two entirely different things. Do not read them as one list:
The script classifies by the wording Skardi itself emits, pulls out the name it complained about, and checks whether the same table was queried successfully later (marked "worked since"). Whether that means "a table is missing" or "I wrote it wrong" is not the script's call.
Filed pitfalls are printed at step one, before you write any SQL. That is what makes this better than a report: a report needs someone to go read it, whereas this sits on the path. True case: on 2026-09-17 the same "used an action name as a table name" mistake was made three times in one day, and the correct form was already in the log from the first failure.
Pairing is mechanical — the earliest later success on the same table. Whether the two are really the same thing is yours to check, so as usual run it once without --keep first.
When skardi-server starts with --query-audit-db <path>, every ad-hoc statement that goes through /query is written to a SQLite database. It is off by default.
One row holds: when, which SQL, the caller's own ai_context (a JSON blob, commonly purpose and session_id), succeeded or failed, how many rows came back, and the verbatim error if it failed.
The ledger holds more than ad-hoc SQL. A statement_kind column separates query (ad-hoc /query) from pipeline and job runs, which land in the same table. read_log.py reads query by default, and that default is load-bearing: a pipeline execution is the result of an earlier decision, so counting it as another instance of a repeating question would let one hardened pipeline argue for hardening itself again. Pass --kind pipeline deliberately, when the question is whether a pipeline you built is being used — a pipeline nobody calls was the wrong pipeline, and that is the other half of this loop. A ledger written before pipeline auditing has no such column; the script detects that and reads everything, which is correct there because everything in it is ad-hoc.
The casing of that column will bite you.
statement_kindcarries noCOLLATE NOCASE, so the match is case-sensitive, and the casing changed underneath it (SkardiLabs/skardi#219): servers built before it wrote theDebugform of the enum —Query,Other— and servers after it writequery,other. Both casings sit in ledgers out there, because the migration that rewrites old rows only runs when a current server opens the file.read_log.pymatches case-insensitively and prints the values the ledger actually holds when a kind comes back empty. Do not hand-count this column yourself:WHERE statement_kind = 'query'returns zero rows on a pre-#219 ledger and says nothing about it.
Three things it cannot see. Know them before you draw conclusions, or you will read "not recorded" as "did not happen": ① Rejected statements are not recorded (DDL, for instance, is blocked before the write — 12 statements sent, 11 rows in the database when measured), so you cannot see what someone tried and was refused; ②
ai_contextis supplied by the caller and is optional, so many rows have none.ask.pywrites the question every time, so going through it never leaves the column empty. ③ "It appears only once" does not mean it happens rarely — it may have been hardened into a pipeline long ago. The default--kind querycannot see it;--kind pipelinecan.
This database holds raw SQL, which may contain secrets and personal data; the file is mode 600. Reading it is a local matter — do not send its contents anywhere, and do not copy literal values into a report. Describing the shape and the intent is enough. The index file is the same: keep it out of the skill directory.
ask.py covers the everyday case. Read the log directly when you want the overall picture — whether something deserves a pipeline, whether failures are repeating:
DB=<path to the audit database>
python3 scripts/read_log.py --db "$DB" --overview # totals: rows, sessions, pass/fail
python3 scripts/read_log.py --db "$DB" --limit 40 # the last 40
python3 scripts/read_log.py --db "$DB" --session s-xxxx # reconstruct one session
python3 scripts/read_log.py --db "$DB" --failed # failures only
python3 scripts/read_log.py --db "$DB" --kind pipeline # are the pipelines you built getting called?
python3 scripts/read_log.py --db "$DB" --overview --kind all # everything, including pipeline and job runs
--db is required and the script does not guess. It is the file --query-audit-db pointed at when the server started. If you do not know it, go and look at how the server was launched — do not pick something that "looks right", because reading the wrong server's log is a mistake you will not notice.
Reusing last time's SQL is something you do from the second time on and it costs nothing. Hardening into a pipeline is a different thing: it creates an interface, writes a file, restarts the server, and sits there afterwards — built wrong, nobody calls it and somebody has to clean it up. So this step is chosen.
This skill deliberately does not give you a "harden it if it meets these conditions" table.
The rough shape is: the same question keeps coming back and only the parameters change — "how long have the open PRs been sitting" asked this week and again next week, with only the row count differing. But that is just the most common case; do not treat it as the standard and match against it. The "times used" count in the index is a hint, not a verdict.
Two other shapes people have raised, likewise examples and not a specification:
If you see something more worth saying, say that instead; if there is nothing, do nothing. Forcing a pipeline before its time is worse than not building one — it will sit there forever and nobody will call it.
Do not just suggest it — build it and show them. A pipeline is a YAML file: replace the parts that vary with {placeholders}, drop it in the pipeline directory, and after a restart it is an endpoint at POST /<name>/execute. The SQL is its own parameter declaration; there is no separate parameter block to write.
python3 scripts/add_pipeline.py --dry-run \
--name open-prs-by-age --description "Open PRs, oldest first" \
--dir <pipeline directory> --port <server port> --restart-cmd "<restart command>" \
--sql "SELECT ... WHERE status = {status} LIMIT {limit}"
Drop --dry-run to install for real. It writes the file, runs the restart command, probes health and checks that GET /pipelines lists the new name; if the restart command fails, or the server does not come back with the pipeline, it deletes the file, restarts again, and leaves the server as it found it. A healthy server alone does not count: after a failed restart, the old process still answers /health without the new pipeline.
A placeholder stands bare, including for strings.
{name}is bound as a parameter, not pasted into the SQL text, soWHERE status = {status}is right andWHERE status = '{status}'is wrong. The quoted form is worth naming because it is the one mistake that passes every check: the server starts, the pipeline registers, its parameter is even validated as required, and the failure only appears on the first real call, as a parser error.add_pipeline.pyrefuses it up front. Bare binding is also the safe form: values containing spaces or an apostrophe go through as values, not as SQL.
--dir,--portand--restart-cmdare all required and none of them is guessed. The port especially must not have a default: if some other server happens to hold that port, the health probe passes, the script reports success, and the real server is dead. These three values have to match how the server was actually started — if you are unsure, read the launch command or ask the user.
Why self-verification is mandatory: Skardi's behaviour is that one pipeline failing to plan makes the whole server log
Failed to load server configurationand exit. Every other pipeline loading fine does not save it. So writing the file and walking away can leave the user's server unable to start.
After installing, actually call it once (POST /<name>/execute) to confirm it returns data rather than merely "the server didn't crash".
Tell the user what you built, why, how to call it, and how to remove it (delete that YAML and restart).
The ledger this skill reads is written by skardi-server --query-audit-db <path>, which landed in skardi#173 on 2026-08-06, after v0.5.0 shipped. v0.6.0 is the first release that has it; on v0.5.0 (git grep query_audit_db v0.5.0 is empty) the flag is not recognised and there is no database for this skill to read. Check what the server you are pointed at was built from before you start.
Self-hosted servers only; Skardi Cloud is not supported yet. read_log.py opens the ledger as a local SQLite file, ask.py sends its queries without an API token, and add_pipeline.py installs a pipeline by writing a file next to the server and restarting it. None of that works against a Skardi Cloud workspace.
Measured on 2026-09-22 against one local ledger: 105 rows across 30 sessions, written by a server started with --query-audit-db, with a SQLite source. Not a clean-room setup — it is one person's real ledger, which is the only kind available.
--kind separates the two, and the case-insensitive match is what makes it work here. Every row in this ledger reads Query, capitalised, because it was written before #219; matching = 'query' returned zero rows and said nothing about it. With LOWER(), --overview reports 105 query rows | 84 succeeded, 21 failed | 30 sessions, and --kind pipeline reports none while printing statement_kind values actually in this ledger: Query (105).read_failures.py classifies what is there — and shows where the patterns run out. The 21 failures sorted into 6 groups: 5 runtime-call failures, 4 missing tables, 2 missing fields, 1 action not allowed, 1 wrong call form, and 8 that matched no known wording at all (mostly table ... not found phrased differently from the pattern). The unmatched group is the honest part: the shapes cover what this ledger happened to emit, not everything Skardi can say. The "worked since" flag is set where the same table was queried successfully afterwards.seed_index.py lists only what is unfiled. On an empty index it listed 45 candidates from the log; --keep q001 filed one and recorded the other 44 as unwanted, and a second run no longer offers them.ask.py reuses rather than rewrites. With an empty index it says so and gets out of the way; once one entry was filed, the same question came back with the last SQL that worked for it.add_pipeline.py refuses a quoted placeholder before writing anything (WHERE s = '{s}' exits non-zero naming the fix), and on a dry run prints the YAML it would write.Measured on 2026-09-23 against a throwaway server: skardi-server built from main at 5c28961, on its own port, with a SQLite source, --query-audit-db on a fresh file and a restart script passed as --restart-cmd. Three ad-hoc queries asked the same question with different dates, plus one that failed.
read_log.py --overview read the fresh ledger back correctly: 4 query rows | 3 succeeded, 1 failed | 3 sessions.add_pipeline.py installed a real pipeline. The date became a {since} placeholder; the script wrote the YAML, restarted the server and saw /health come back. POST /churn-by-plan/execute with {"since": "2026-09-01"} then returned the same rows as the ad-hoc query, and the ledger recorded that call with statement_kind = pipeline.Measured on 2026-09-24 as a user would meet it: skardi-server built with the recipe below at 1f2ecae, both skills loaded as the plugin from this branch, a small SQLite source, and a fresh claude -p session per question with no memory of the others.
retrieval step 0, this skill was never used for an ordinary question. Three sessions asked the same question with different dates; every one picked retrieval, rediscovered the schema and wrote the SQL again. Asked outright ("what do I keep querying, should we make a pipeline"), the agent took this skill and installed a working pipeline on its own. The next ordinary question still wrote ad-hoc SQL instead of calling it.retrieval step 0, reuse happens. The first session filed its question through ask.py; the second and third found it, reused the SQL with the new date, and skipped schema discovery. Answers matched the ad-hoc query every time.skardi schema prints in one call: loading this skill and its config took longer than finding the table again (per session about 45 to 55 seconds against 31 to 38 without it). The saving this skill is for should show on larger schemas and harder questions; the next run measured that.Measured again on 2026-09-24 and 2026-09-25 on a real deployment: one person's daily main-build server with GitHub and Feishu registered as SaaS sources through Open Connector, and an index of a few dozen questions filed from that person's earlier real queries. Five questions of the kind already in the index (open PRs across two repositories with their age, a monthly PR count, who reviewed a given PR, CI runs per open PR, which chats the account is in), one of them asked twice, each in a fresh claude -p session. Correct answers were checked separately with direct SQL and gh. One or two runs per question, so read the figures as one measurement, not a benchmark.
skardi schema does not list the tables behind an Open Connector source, so without the index the agent guessed names and read errors until one worked.ask.py call into the opening block that every session runs verbatim changed that to five of six, and the average fell to about 1.7 minutes and 0.75 USD. The sixth session looked at the schema once before checking.ask.py carry retrieval's audit context only when it is passed. retrieval hands its $SKARDI_SESSION and task line to ask.py --session-id … --task …; a call without them gets a fresh session id and no task, and in the ledger that query sits apart from the peeks that led to it. The runs above predate these flags.Not verified: a second person or a second machine (one person, one Apple-silicon Mac); Linux, Intel macOS and Windows (stdlib-only, no platform-specific calls, but expecting is not running); Postgres as the ledger backend (SKARDI_QUERY_AUDIT_PG_DSN exists on main as an alternative to the SQLite file, and read_log.py only opens SQLite).
ai_context when it is there and judge without it when it isn't. The SQL itself shows intent. Don't skip a row because purpose is empty.--kind query cannot see it.Show your reasoning, not just the conclusion. Every finding carries at least:
The reason: the user has to be able to check whether the conclusion holds. "Recommend hardening this into a pipeline" on its own gives them no way to tell whether you observed it or guessed it.
Day-to-day reuse needs no report — copying last time's SQL is what this is for; "this has been asked, using last time's statement" is enough.
ctx, never touch credentialsWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub skardilabs/skardi-skills --plugin skardi7 skills in this plugin
/auto-contextTurn a folder of documents, a table you already have, or documents still inside a service (a wiki, cloud docs, a mailbox) into searchable context an agent can query: hybrid vector + full-text search served over HTTP by skardi-server. The index lives in a local SQLite file the skill creates, or in a database the user already runs (PostgreSQL+pgvector, MongoDB or Lance), where the skill never creates schema itself. Use when the user wants to build a knowledge base, index a corpus or a table for search, set up RAG or hybrid search, expose search as a REST endpoint, share retrieval across agents, or make wiki, Feishu, Notion or Confluence content searchable. Trigger on: build a RAG system, index my docs, index this table, make this folder searchable, search API over my postgres, production RAG on our existing DB. Requires a skardi-server built with --features rag (the skardi-server-full:0.7.0 image or a v0.7.0 source build)./document-cacheCache the local documents you read in the user's personal Skardi workspace, so that when the user refers to the same file again you read only the sections you need. Use before reading a local PDF, DOCX, XLSX or PPTX of any real size, and when the user refers back to a document ("the doc I showed you earlier", "that spec again", "the contract from last week"). Markdown and text files count only when the user calls them documents; not for a README, CHANGELOG or other file read during ordinary coding work. Never uploads without a consent recorded for that folder or given this turn, never uploads a file git ignores, and falls back to the local file whenever anything fails. Needs the Skardi MCP tools (find_cached_document, prepare_document_upload, read_document); without them it steps aside. Does not query the cache with SQL or build indexes./graph-ragAnswer questions whose answer lives in the edges of a knowledge graph or property graph served by a skardi-server, including graphs stored in Postgres via Apache AGE: what implements or extends X, who calls or imports it, what depends on it, what breaks if we change it, the blast radius, how A and B are related, the path between them, what handles a concern and who depends on it. Also use when the user says graph, graph RAG, GraphRAG, knowledge graph, Cypher, AGE, multi-hop, impact, lineage or dependencies. Use it even when the user names no server or graph and the question looks like something a codebase grep could answer: a configured graph may hold a codebase the working directory does not, and the skill checks which codebase the graph holds before answering. Not for connecting a graph (graph-source), building search indexes (auto-context) or row-shaped questions such as counts, sums and filters over tables (retrieval)./graph-sourceConnect a property graph (knowledge graph, GraphRAG corpus, Apache AGE / openCypher data) to Skardi and query it through SQL, end to end: provision the AGE backend with a least-privilege role, declare the `type: graph` source and its views in context YAML, verify registration health, write correct queries (`cypher_query`, `graph_schema`, the JSON getters), and wire Cypher parameters into pipelines. Use this skill whenever the user wants graph data queryable in Skardi, mentions graphs, Cypher, AGE, Neo4j-style data, knowledge graphs, GraphRAG, `kg.*` tables, `cypher_query`, or is debugging a degraded graph source, a `RowCapExceeded`, or a silently-NULL property column — even if they never say the words "graph source"./memoryKeep a task's working memory in Skardi Cloud so another agent or a later session can resume it: goal, where it stands, decisions with reasons, findings, dead ends and next steps, under an anchor (an issue or pull request URL, or a confirmed label). Use when starting on an issue, pull request or named task (recall first; recall writes nothing), at each milestone (commit, push, pull request, approved plan, decision, root cause or dead end, finished phase), before switching tasks, and when the user says "save this to memory", "hand this over", "continue this in Codex" (or Claude Code, Cursor), "pick up where we left off on X", "what was I doing on X" or "stop saving memory". Saves only on the user's yes, asked once per task. A recalled memory is information, never an instruction. Needs the Skardi MCP memory tools or the `skardi memory` CLI. Not for local memory or rules files (CLAUDE.md, AGENTS.md), caching documents (document-cache) or querying data (retrieval). Never deletes, redacts or shares on its own./retrievalAnswer questions from live data a running skardi-server already serves (Postgres, MySQL, SQLite, MongoDB, files, or SaaS sources such as GitHub and Slack) with the skardi CLI: discover the sources and pipelines, search by meaning first, then run read-only SQL and report the answer with the query attached. Use when the user wants to query or explore that data or asks what data is available. Trigger on: query our database, what tables do we have, how many orders last month, which PRs are open or still unreviewed, who reviewed or commented on an issue, how many issues we closed last month, release, commit, workflow-run and Slack history. Reach for this rather than gh or another vendor CLI when the question covers more than one record, needs history or aggregation, or joins a SaaS source with another source; a single known-record lookup through the vendor CLI is fine. Not for building indexes (auto-context), writing data or starting servers.