Debian Codegraph @

docs/plans/m3-hsql-technical-plan.md

raw
1 # M3 Technical Plan — docs a machine can read, and the skill
2
3 Implementation plan for milestone M3 of [Harlequin for agents](./harlequin-for-agents.md),
4 following [M1](./m1-hsql-technical-plan.md) and [M2](./m2-hsql-technical-plan.md). M1 built
5 the command, M2 taught it to describe itself. This one is about everything an agent reads
6 *before* it runs `hsql`: the documentation, and the skill that tells it which flag to reach
7 for.
8
9 **M3's scope, from the roadmap:** `llms.txt`, `llms-full.txt`, raw `.md` routes, Docs API v1,
10 copy-as-markdown, homepage positioning, and `AGENTS.md` — Workstream D. **The Harlequin skill
11 (E1) is pulled forward from M4** (Ted's call). The rest of M4 — `hsql open`, JSONL history,
12 "Copy CLI command", the external-command hook — stays in M4.
13
14 **Where M2 actually got to.** PRs 1–12, 15 and 16 shipped: the per-file/per-profile config
15 work, the five self-description modes, secrets and `${VAR}`, `--catalog`, `type_name` and
16 `--catalog-search`. PRs 13 (`--read-only` and the capability declarations), 14 (`--timeout`)
17 and 17 (the safety docs) are in flight and unshipped, which is a real dependency here and not
18 a footnote: two of the nine things the product plan says the skill should teach are flags that
19 do not exist yet (§1.9).
20
21 **Two repos, and most of the work is in the other one.** `tconbeer/harlequin-web` is where
22 `llms.txt`, the raw routes, the API and the docs topic live. That repo has no tests, no CI
23 beyond a Vercel preview build, and a `pnpm lint` pre-commit hook. M3 is the first milestone
24 that has to treat it as a build target rather than a place to paste prose.
25
26 **Bottom line up front.** Three claims, each measured below:
27
28 1. **Docs written for machines have to be true, and today they are not.** `hsql --parquet`
29 and `hsql --results` are documented on the site, in the packaged README, *and* in the
30 homepage's terminal mock-up; both exit 2 with "No such option" (§1.4). The one page
31 written for agents prints `&lbrace"status":"ok"…` where `{"status":"ok"…}` belongs (§1.3).
32 `https://harlequin.sh/schemas/config/v1.json`, which every schema `hsql --config schema`
33 generates names as its `$id`, is a 404 (§1.5). Nothing in either repo checks any of this.
34 **The first thing M3 builds is the check, not the corpus** — publishing more machine-read
35 text over an unchecked pipeline multiplies the blast radius of exactly this bug.
36 2. **A page's markdown source is not its markdown output, and four features want the same
37 transform.** 24 of 55 pages open a `<script>` block; there are 168 `<Key>` tags, 11
38 `<Figure src={identifier}>` whose `src` is a JS binding rather than a path, and 56
39 relative links that mean nothing outside the site's router. The raw route, `llms-full.txt`,
40 the Docs API and the copy button are four consumers of **one** sanitizer, and a raw route
41 that emits `<Figure src={init}>` is worse than no raw route (§3.2).
42 3. **The skill's value is knowing what not to say.** It ships *in the wheel* and prints from
43 `hsql --skill`, so the text an agent installs is the version of `hsql` that is installed;
44 and it teaches `--info`/`--spec`/`--help -a` rather than restating them, so it stays
45 ~1,000 tokens and cannot go stale about adapters it has never heard of (§3.5).
46
47 ---
48
49 ## 1. Where things are today
50
51 Measured on this checkout — 2.10.0 plus the unreleased 2.11 catalog work — and on
52 `tconbeer/harlequin-web` at `31b2051`, built with pnpm 10.33 / Node 22.22 and served from
53 `pnpm preview`.
54
55 ### 1.1 The site is 55 markdown files, a glob, and no tests
56
57 `src/docs/**/*.md` is the source of truth for both page content and the sidebar: there is no
58 nav config. `src/routes/api/docs/+server.ts` globs every `.md`, reads `title` and `menuOrder`
59 out of the frontmatter, and sorts topics and pages together. Rendering is mdsvex through
60 `src/routes/docs/[topic]/[[page]]/`, with ISR at one hour and a hardcoded `repoMap` for the
61 third-party adapter star counts.
62
63 ```
64 55 docs pages 122,992 bytes of markdown
65 3 blog posts
66 0 tests (the repo has no test runner; `pnpm lint` is prettier + eslint)
67 ```
68
69 There is one deployment gate — a Vercel preview build — and it fails only on a build error. A
70 page that renders a component that does not exist fails it; a page that documents a flag that
71 does not exist does not.
72
73 ### 1.2 What one docs page costs an agent today
74
75 Production build, served locally, bytes on the wire for the HTML document alone:
76
77 ```
78 /docs/getting-started/usage 66,187 bytes HTML vs 7,369 bytes markdown source 9.0x
79 /docs/getting-started/hsql 72,523 bytes HTML vs 5,761 bytes markdown source 12.6x
80 ```
81
82 The product plan's D2s story claims "a tenth of the tokens," and it is right — most of a page
83 is the sidebar, which is rendered into every document. The whole docs corpus, with frontmatter
84 and script blocks stripped, is **116,101 bytes — roughly 29,000 tokens**. That number decides
85 the shape of D1 (§3.3): `llms-full.txt` is a real artifact but it is not a thing an agent
86 loads speculatively, so `llms.txt` plus per-page markdown has to be the primary path and
87 `llms-full.txt` the fallback, not the other way round.
88
89 ### 1.3 A page's source is not markdown
90
91 What is actually in `src/docs`, counted:
92
93 | construct | count | why a raw route can't pass it through |
94 | --- | --- | --- |
95 | `<script>` block | 24 pages | imports; renders as literal text outside Svelte |
96 | `<Key>ctrl+q</Key>` | 168 | not markdown; means `` `ctrl+q` `` |
97 | `<Tip>`, `<Note>`, `<Warning>` | 22 | callouts; mean a blockquote |
98 | `<Figure src={init} alt=… caption=…>` | 11 | `src` is a **JS binding** from the script block, not a path |
99 | `<Link href="auth">` | 9 (5 relative) | means a markdown link |
100 | `<ThemeGallery grow=false>` | 1 | has no markdown equivalent at all |
101 | relative `[text](../config-file/index)` | 51 | resolves against the site router, not against a `.md` file |
102 | `&lbrace;` / `&rbrace;` escapes | 4 | mdsvex reserves `{`; the source can't spell one |
103 | ` ```output ` fences | 3 | a site-private fence language |
104
105 The brace escape is not hypothetical. `src/docs/getting-started/hsql.md:119` writes
106 `&lbrace"status":"ok"…` — without the closing semicolon — and the built page serves
107 `&amp;lbrace"status":"ok"…`. **The published page teaching agents to parse `--stats` shows
108 them a JSON object with `&lbrace` where `{` belongs.** It has presumably been wrong since the
109 page was written, because nothing renders that page in a test and no human reads a `--stats`
110 line closely.
111
112 ### 1.4 The docs disagree with the CLI, and with themselves
113
114 Extracting every `--flag` mentioned in the hsql docs and diffing against `hsql --spec` (31
115 core options, plus each adapter's) finds two that do not exist:
116
117 ```
118 $ hsql -c "select 1" --parquet -o out.pq
119 Error: No such option '--parquet'. Did you mean '--path'? exit 2
120
121 $ hsql -c "select 1" --results all
122 Error: No such option '--results'. (Did you mean one of: '--result', '--stats'?) exit 2
123 ```
124
125 `--results` appears in `src/docs/getting-started/hsql.md`, in `packaging/hsql/README.md`, and
126 in the homepage's `hsql_features.svelte` terminal mock-up. `--parquet` appears in the first
127 two. The format shorthands that exist are `--csv`, `--json`, `--jsonl`, `--markdown` and
128 `--vertical`; parquet has never had one, and the correct spelling has always been
129 `--format parquet`. Every one of these is a copy-paste-and-fail for an agent, and the
130 `--result` case is the worse one: it is one character from the truth and the error names the
131 right flag, so a careless reader learns the CLI is unreliable rather than that the docs are.
132
133 This diff took nine lines of Python. Nothing runs it.
134
135 The same is true of the links between pages. Resolving all 56 relative links against the file
136 tree finds two that 404 on the built site:
137
138 ```
139 /docs/hsql 404
140 from getting-started/running.md:64 — [Using hsql](../hsql)
141 /docs/duckdb/troubleshooting/duckdb-version-mismatch 404
142 from duckdb/index.md:11 — [Troubleshooting](troubleshooting/…), missing a ../
143 ```
144
145 The first is the link from "Running Harlequin" to the hsql page. Two more —
146 `[MySQL/MariaDB](mysql/index)` and `[ODBC](odbc/index)` in `adapters.md` — resolve only
147 because the router 308s `/docs/x/index` to `/docs/x` (§1.1); they are correct on the site and
148 dead in any corpus that is files rather than routes, which is exactly what M3 publishes.
149
150 ### 1.5 The site is already a publishing target, and nothing publishes to it
151
152 `src/harlequin/config_schema.py:51` sets
153
154 ```python
155 SCHEMA_ID = "https://harlequin.sh/schemas/config/v1.json"
156 ```
157
158 and `scripts/write_config_schema.py` writes the adapter-free document to
159 `src/harlequin/schemas/config-v1.json`, which ships in the wheel and is pinned by
160 `tests/unit_tests/test_config_schema.py`. The URL in the `$id` of every schema this repo
161 generates has **no route and no static file** on the site: `harlequin-web` has nothing under
162 `schemas/`.
163
164 So the mechanism M3 needs already has a customer that shipped in 2.10 without it: an artifact
165 generated in this repo, versioned here, that has to appear at a stable URL over there. There
166 is no workflow, no directory, and no convention for that — §3.4 is where M3 picks one.
167
168 ### 1.6 The docs API is an accident, not a contract
169
170 `/api/docs` returns 5,049 bytes of `{title, menuOrder, slug}` for pages and
171 `{topic, slug, slugPrefix, menuOrder}` for topics. It exists to build the sidebar, and it
172 shows: the top-level topic's `slugPrefix` is the string `"/src"`, because the code takes the
173 second-to-last path segment of `/src/docs/getting-started/index.md`. There is no per-page
174 route, no content in the payload, no CORS header, and no version in the path. It is fine as a
175 private endpoint and unusable as the public one D3 describes.
176
177 ### 1.7 There is no skill, and no place the docs put one
178
179 `packaging/hsql/README.md` (365 lines) is the closest thing that exists — it covers install,
180 adapters, profiles, secrets, layouts, the catalog modes, scripting, and a "Describing hsql to
181 an Agent" section. It is a README: it optimizes for a human landing on PyPI, it is far too
182 long to load into every request, and it is where two of the wrong flags live (§1.4).
183
184 On the site, hsql is a single page — `getting-started/hsql.md`, 170 lines — inside the
185 Getting Started topic. D5's "Headless & Agents" topic does not exist. There is no page for
186 exit codes, no page for the catalog modes (they are documented only in the packaged README),
187 no page for safety, and no page for the config file spec beyond the three human-facing pages
188 under `config-file/`.
189
190 ### 1.8 D6 and D7 are mostly done already
191
192 The roadmap's M3 row lists homepage positioning and `AGENTS.md`; both largely shipped during
193 M1/M2:
194
195 - The homepage has "One Engine, Two Interfaces," an `#hsql` section headed "Your agent's
196 favorite SQL client," and three terminal mock-ups (`hsql_features.svelte`). What is left is
197 a correction — it is one of the three places that says `--results`.
198 - `AGENTS.md` exists in `tconbeer/harlequin` and in `tconbeer/harlequin-web`. It does **not**
199 exist in `tconbeer/harlequin-adapter-template`, which is the half D7 actually asked for
200 ("so new adapters inherit it").
201
202 ### 1.9 What the skill cannot say yet
203
204 `hsql --info` today reports two capabilities per adapter:
205
206 ```json
207 "capabilities": { "implements_cancel": true, "implements_catalog_search": true }
208 ```
209
210 `IMPLEMENTS_READ_ONLY` and `IMPLEMENTS_VALIDATE_SQL` arrive with M2's PR 13, and `--timeout`
211 with PR 14. The product plan's skill outline says "Prefer `--read-only` unless the human asked
212 for a write," which is advice about a flag that does not exist on `main`. §4 sequences around
213 this: the skill's *text* can be written now, but the PR that ships it lands after 2.12.
214
215 ---
216
217 ## 2. The obstacles, stated plainly
218
219 **One.** *The artifacts are generated in one repo and consumed in another, and there is no
220 pipe between them.* The JSON Schema needs it today; the CLI reference and the skill will need
221 it the moment they exist. Site builds are hermetic (a git checkout plus `pnpm i`), and the
222 site's build machine has no Python, so it cannot run `hsql --spec` itself.
223
224 **Two.** *Sanitization is the whole job of D2, and a half-done one is worse than none.* An
225 agent that fetches `.md` and gets `<Figure src={init}>` has been handed a broken tool and a
226 reason to distrust the next one. The transform has eleven distinct cases (§1.3) and one of
227 them — resolving a `src={identifier}` back to an asset URL — requires reading the script
228 block that the same transform is deleting.
229
230 **Three.** *Neither repo tests documentation.* This repo tests the CLI thoroughly and never
231 reads its own README; the site repo tests nothing. Every claim in §1.3–§1.5 is a bug that a
232 five-line test would have caught on the day it was written.
233
234 **Four.** *The skill has to be short and current at the same time.* Short means it cannot
235 enumerate fifteen adapters, thirteen formats and thirty-one options. Current means it cannot
236 be a snapshot of a CLI that ships every few weeks. Those pull in opposite directions unless
237 the skill's job is redefined as *teaching the agent which question to ask the CLI* — which is
238 what §3.5 does, and what keeps it at ~1,000 tokens.
239
240 **Five.** *`llms-full.txt` is 29,000 tokens.* Every design that treats it as the front door is
241 proposing that an agent spend a fifth of a small context window before it knows whether
242 Harlequin is relevant.
243
244 ---
245
246 ## 3. Target architecture
247
248 ### 3.1 Truth first: generate what can be generated, test the rest
249
250 The principle M2 established for `config-v1.json` — *generate rather than declare, commit the
251 artifact, and let a test fail when the generator and the artifact disagree* — is the whole of
252 M3's answer to §1.4 and §1.5. Three mechanisms, in increasing order of coverage:
253
254 **(a) A flag guard, in this repo.** A unit test extracts every `--long-flag` from
255 `packaging/hsql/README.md` and from the skill, and asserts each one appears in `hsql --spec`
256 (core options, or any installed adapter's). It is nine lines, it fails on `main` today, and it
257 is the cheapest thing in this milestone. Positional and single-dash spellings are out of scope
258 — `-tAc` is a bundle, and `--with` in an install line belongs to `uv`, so the extractor takes
259 long flags only and the test carries a small allowlist for the ones that belong to other
260 programs.
261
262 **(b) A generated CLI reference.** `scripts/write_cli_reference.py` renders `hsql --spec`
263 (with no adapters loaded, exactly as `write_config_schema.py` does) into
264 `docs/generated/hsql-reference.md`: one table of options with type, default, choices, env var
265 and help, plus the arguments, the format list and the exit codes. Committed, pinned by a test
266 that regenerates and compares. This is the page the site publishes as the CLI reference, and
267 it *cannot* drift, because nothing hand-writes it.
268
269 **(c) A docs lint, in the site repo.** Over the sanitized corpus (§3.2), not over the sources:
270 every internal link resolves to a page that exists, no page contains a Svelte component tag or
271 an unresolved `{identifier}`, no page contains `&lbrace`, and `llms.txt` lists exactly as many
272 pages as `src/docs` contains. The site repo gets its first test runner for this.
273
274 What (a) and (c) cannot cover is a flag spelled correctly in prose that says the wrong thing
275 about it. That is a review problem, and M3 does not pretend to solve it.
276
277 ### 3.2 One corpus, one sanitizer, five consumers
278
279 `src/lib/server/docs.ts` in `harlequin-web`. It is the only place that turns a `.md` source
280 into markdown, and everything that serves markdown calls it:
281
282 ```
283 ┌─ /docs/**/*.md (D2, raw per page)
284 ├─ /llms-full.txt (D1, the whole corpus)
285 buildCorpus() ──────────┼─ /llms.txt (D1, titles + one-liners + links)
286 (glob ?raw ├─ /api/docs/v1/… (D3, the same markdown, as JSON)
287 → sanitize) └─ "Copy as Markdown" (D4, fetched from the raw route)
288 ```
289
290 `buildCorpus()` globs `/src/docs/**/*.md` with `{ query: '?raw', eager: true }` and, for each
291 page, returns `{ slug, topic, title, menuOrder, markdown, description }`. `sanitize()` is one
292 function over one page's source, applied in this order:
293
294 1. **Split the frontmatter.** `title` and `menuOrder` come out as fields; the block is dropped
295 from the body, and `# {title}` is prepended, because a raw page with no heading reads as a
296 fragment.
297 2. **Read, then delete, the `<script>` block.** Its `import X from "path"` pairs become a
298 local map before the block is removed. That map is what resolves `src={init}` in step 4.
299 3. **Downgrade the components.** `<Key>x</Key>` → `` `x` ``; `<Tip>` → `> **Tip:** …`;
300 `<Note title_text="X">` → `> **X:** …`; `<Warning>` → `> **Warning:** …`;
301 `<Link href="h">t</Link>` → `[t](h)`. Nested markdown inside a callout keeps working
302 because a blockquote is line-prefixed, not wrapped.
303 4. **Resolve `<Figure>`.** `src={init}` → the import map's path → the URL from a second
304 `import.meta.glob('/src/lib/assets/**', { query: '?url', eager: true })`, absolutized
305 against `https://harlequin.sh`. Emits `![alt](url)` and, if there is a caption, an
306 italic line under it.
307 5. **Un-escape the braces.** `&lbrace;`/`&rbrace;` → `{`/`}`, and the malformed
308 `&lbrace`/`&rbrace` spellings too, which is what fixes §1.3's rendered bug for every
309 machine consumer. (The *rendered page* keeps its bug until the source is corrected; that
310 correction is its own one-line PR, not something the sanitizer should paper over.)
311 6. **Absolutize links.** `[t](../config-file/index)` and `[t](auth)` resolve against the
312 page's own topic and become `https://harlequin.sh/docs/…`, with a trailing `/index`
313 dropped the way the router's 308 drops it. A raw `.md` file has no router under it, so a
314 relative link in it is a dead link, and one the router currently rescues is a dead link
315 waiting.
316 7. **Normalize fences.** ` ```output ` becomes an unlabelled fence; ` ```bash ` stays, and the
317 `$ ` prompt is *not* added — it is injected by the site's highlighter, not present in the
318 source, which means the raw output is already copy-pasteable.
319 8. **Refuse the unknown.** A component tag the table does not cover throws at build time
320 rather than shipping. `<ThemeGallery>` gets one explicit case — dropped, replaced by a link
321 to the rendered page — and the next new component gets a failing build until someone
322 decides what it means in markdown.
323
324 `description`, for `llms.txt`, is the page's first sentence of prose after the heading,
325 truncated at ~120 characters. A `description` frontmatter key overrides it, and new pages
326 should set one; the derived fallback exists so that adding a page never silently degrades the
327 index.
328
329 ### 3.3 The routes
330
331 | route | content type | how it's built |
332 | --- | --- | --- |
333 | `/llms.txt` | `text/plain` | prerendered; title, description and absolute URL per page, grouped by topic |
334 | `/llms-full.txt` | `text/plain` | prerendered; every page's sanitized markdown, `---`-separated, each under its canonical URL |
335 | `/docs/{topic}/{page}.md` | `text/markdown; charset=utf-8` | prerendered per page from the corpus |
336 | `/api/docs/v1` | `application/json` | the index, with `title`, `topic`, `slug`, `url`, `description` |
337 | `/api/docs/v1/{topic}/{page}` | `application/json` | `{ title, topic, slug, url, markdown }` |
338 | `/schemas/config/v1.json` | `application/schema+json` | the artifact from this repo (§3.4) |
339
340 Prerendered, not ISR: the corpus is 55 files that change only when the repo does, and a
341 prerendered route is a static file on Vercel's CDN with no cold start and no way to fail at
342 request time. `/api/docs` stays exactly as it is — the sidebar depends on its shape, and v1 is
343 additive rather than a migration. Every `/api/docs/v1/*` response carries
344 `Access-Control-Allow-Origin: *`, because a browser-based agent is a real consumer and there
345 is nothing here that is not already public. `robots.txt` gains an explicit `Allow` for the two
346 `llms` files; it allows everything today, but naming them is how the convention is read.
347
348 **On the `.md` extension.** `/docs/x/y.md` rather than content negotiation on `/docs/x/y`,
349 because an agent constructs a URL by string-appending far more reliably than it sets an
350 `Accept` header, and because a static path is cacheable without `Vary`. The rendered page
351 links to its own `.md` twin (D4), so the discovery path is: land on HTML → see "View as
352 Markdown" → learn the convention → construct the rest.
353
354 ### 3.4 Getting an artifact from this repo to that one
355
356 Three artifacts need a stable URL on the site: `config-v1.json` (already generated, already
357 committed, already referenced by a live 404), `hsql-reference.md` (§3.1b), and `SKILL.md`
358 (§3.5). The options:
359
360 - **The site fetches at build time** from `raw.githubusercontent.com` at a tag. One source of
361 truth, no sync PR — but the site build stops being hermetic, a network blip fails a deploy,
362 and a docs typo fix requires knowing which tag the site is pinned to.
363 - **The site vendors the artifacts, and the release workflow opens the PR.** `release.yml`
364 gains a step that copies the three files into `harlequin-web/static/artifacts/` and opens a
365 PR. Site builds stay hermetic and reproducible, the diff is reviewable, and the failure mode
366 is a stale-but-working page rather than a failed deploy.
367
368 **Recommended: the second.** It is also the one that matches what the repo already does with
369 `config-v1.json` — generate, commit, pin with a test — applied one repo further along. The
370 site's routes serve the vendored files verbatim; the CLI reference page renders the vendored
371 markdown through the same layout as a hand-written page; and a `manifest.json` beside them
372 records which `harlequin` version they came from, which the reference page prints in a
373 "generated from hsql X.Y.Z" line so a reader can tell when it is behind.
374
375 This is the one piece of M3 that is more mechanism than content, and it is the piece §1.5 says
376 is already overdue.
377
378 ### 3.5 `hsql --skill`, and the skill
379
380 **A skill is a file with a contract, and the contract is not Anthropic's alone.** Agent Skills
381 is an open standard ([agentskills.io](https://agentskills.io)) that Claude Code, claude.ai
382 uploads and the Skills API all read, and its portable frontmatter is six fields: `name`,
383 `description`, `license`, `compatibility`, `metadata`, `allowed-tools`. Harlequin's skill uses
384 **only those six**. Claude Code accepts extension keys (`disable-model-invocation`, `context`,
385 `argument-hint`); the other paths reject an unknown key outright, and a skill whose whole
386 argument over MCP is "it works in any harness" (product plan §9) does not get to ship a
387 vendor-locked file.
388
389 **Where the text lives.** `src/harlequin/hsql/skill/SKILL.md`, shipped as package data
390 alongside `src/harlequin/schemas/config-v1.json` and read the way
391 `components/help_screen.py` reads its markdown — `Path(__file__).parent / …`. One copy, three
392 consumers: the wheel, the plugin (below), and the artifact the site publishes (§3.4).
393
394 **How it's delivered.** `hsql --skill` — a mode option, like every other mode M2 added, in
395 `hsql/modes/skill.py`. It writes the file to stdout and honors `-o PATH` the way `--info`
396 already does, so installing it is one command with no network:
397
398 ```bash
399 hsql --skill -o ~/.claude/skills/hsql/SKILL.md # personal, loads on the next session
400 hsql --skill -o .claude/skills/hsql/SKILL.md # project, and it commits with the repo
401 ```
402
403 Printing a packaged file imports nothing — no adapter, no config read — and the
404 import-hygiene guard says so.
405
406 **Why the wheel rather than a download.** The skill an agent installs is then, necessarily,
407 the skill for the `hsql` on that machine — the one place "which version am I reading about"
408 cannot be got wrong. It also works with no network, which is exactly the environment (CI, a
409 locked-down container) where an agent is most likely to be driving a CLI.
410
411 **The one-command install, in three tiers.** All three serve the same file:
412
413 1. **`hsql --skill -o …`**, above. Already one command, already version-matched, works in any
414 harness that reads a skills directory. This is what the docs lead with.
415 2. **A marketplace entry in this repo.** A plugin that ships exactly one skill may put
416 `SKILL.md` at the plugin root rather than under `skills/`, and a marketplace entry's
417 `source` may be a path inside its own repository. So `.claude-plugin/marketplace.json` at
418 the repo root, with one entry whose source is `./src/harlequin/hsql/skill`, makes that
419 directory the plugin — **no second repo, no copied file, no build step**. A tiny
420 `.claude-plugin/plugin.json` inside it carries the name, description and version; it ships
421 in the wheel too, at a few hundred bytes. Then:
422
423 ```
424 /plugin marketplace add tconbeer/harlequin # once
425 /plugin install hsql@harlequin
426 ```
427
428 `claude plugin validate ./src/harlequin/hsql/skill` is a real command, so this tier comes
429 with a CI guard rather than a promise.
430 3. **The community marketplace.** `anthropics/claude-plugins-community` is public and
431 submission is a form; approved plugins are pinned to a commit SHA and the pin is bumped by
432 CI as we push. For a user who already has that marketplace — which is most of them — the
433 install collapses to a single `/plugin install hsql@claude-community`, with nothing of
434 ours installed first. Tier 2 is the prerequisite, so this is a follow-up to file rather
435 than a PR to write.
436
437 **`allowed-tools` covers introspection and nothing else.** The field pre-approves tools for
438 the turn that invokes the skill, which is worth having — the first thing the skill tells an
439 agent to do is run `hsql --info`, and a permission prompt there is friction on the one command
440 that is unambiguously safe. So the grant names the read-only modes explicitly
441 (`Bash(hsql --info)`, `Bash(hsql --spec*)`, `Bash(hsql --catalog*)`,
442 `Bash(hsql --catalog-search*)`) and never `Bash(hsql *)`, which would pre-approve
443 `hsql -c "drop table orders"`. Deciding whether to run a query is the human's; deciding
444 whether to read a catalog is not.
445
446 **Its own progressive disclosure is the CLI.** A skill's third layer is normally bundled
447 reference files. Harlequin's references are commands — `--info`, `--spec`, `--help -a NAME`,
448 `--catalog` — which are current by construction and cost nothing until they are run. That is
449 why the skill can be one file under a fifth of the 500-line ceiling, and why it does not rot
450 when an adapter we have never heard of is installed beside it.
451
452 **What it says**, in nine short sections, budget ≤4KB / ~1,000 tokens:
453
454 1. **Ask before you assume.** `hsql --info` for versions, config files, the active profile and
455 what each adapter supports; `hsql --help -a NAME` for one adapter's connection options;
456 `hsql --spec` when a machine needs the option list rather than a human.
457 2. **Never put a credential on the command line.** Use a profile and `-P`; use `${VAR}` in the
458 config file; the shell history and the process table are both readable.
459 3. **Orient in the catalog before writing SQL.** `hsql --catalog`, `--path db.schema`,
460 `--path db.schema.table` for columns, `--catalog-search TERM` when you don't know where
461 something lives — and check `--info` first, because searching is a capability not every
462 adapter has.
463 4. **Run it.** `-c` for a statement, `-f` for a file (`-f -` for stdin), `--result` to pick
464 which result set prints, `--on-error` to pick what happens after a failure.
465 5. **Pick a format on purpose.** `-tAc` for one value into a shell variable; `--csv` for a
466 pipe; `--markdown` when the output is going into your own reply; `--format parquet -o` for
467 anything large. `--format` takes the name; only csv, json, jsonl, markdown and vertical
468 have shorthands.
469 6. **The row limit is real.** 500 by default. `--stats` puts `{"truncated": …}` on stderr —
470 read it, and never `2>/dev/null`, because that is where truncation warnings and errors both
471 go.
472 7. **Branch on the exit code.** 0 ok, 1 query error, 2 usage/config error, 3 connection error,
473 4 timeout, 130 interrupted. A usage error is your bug; a query error is the SQL's.
474 8. **Ask before you write.** Prefer `--read-only` where the adapter declares it (`--info`
475 again); say what a DDL or DML statement will do before running it.
476 9. **Know when to hand off.** Schema you can't disambiguate, a query the human will want to
477 iterate on, anything destructive, anything that wants a human eye on 10,000 rows: stop and
478 tell them to open `harlequin -P <profile>` — same profile, same adapter, same engine.
479
480 **What it deliberately does not contain:** the adapter list, any adapter's options, the full
481 format list, the option table, or anything about the config file's schema. All five are
482 one command away, and all five are what makes a skill rot.
483
484 Section 9 is the one nobody else would write, and it is also the one M4 improves: with
485 `hsql open query.sql`, "tell them to open Harlequin" becomes "hand them the query, loaded and
486 unexecuted." The skill gets that paragraph in M4, and the plan should not pretend the M3
487 version is the finished one.
488
489 **The body is written as standing guidance, not a procedure.** A skill's content enters the
490 conversation once and stays for the session; the file is not re-read on later turns. So each
491 section reads as a rule that holds for the rest of the work ("the limit is real; check
492 `truncated` every time"), not as a step that happens once ("first, run `--info`"). Nine
493 sections of standing rules is also why the skill is nine short sections rather than a
494 walkthrough.
495
496 **The description is the product.** It is the only part always in context, and it is what
497 decides whether the skill loads at all — a skill that never triggers is worth exactly nothing,
498 and the current failure mode is under-triggering, not over. So it names the contexts as well
499 as the capability: running SQL, inspecting a database's tables or columns, exporting query
500 results, a `.sql` file, a connection string or DSN, a `harlequin.toml` — including when the
501 user never says "hsql." It gets one deliberate pass with the description-optimization loop in
502 `skill-creator` (about 20 realistic trigger queries, half of them near-miss negatives, split
503 train/test) before PR 3 merges. That loop needs the `claude` CLI, so it is a pre-merge
504 exercise whose eval set is committed, not a CI check — and it is the closest thing this
505 milestone has to the agent eval suite M1 dropped (§5).
506
507 ### 3.6 The "Headless & Agents" topic
508
509 D5, in `src/docs/headless/`, with `index.md` carrying `topic: "Headless & Agents"`. **The
510 topic is additive: `getting-started/hsql.md` stays exactly where it is** (Ted's call). It is
511 the page a human lands on — linked from the packaged README, the homepage and
512 `running.md` — and it earns that spot: it is the tutorial. The new topic is the reference
513 beneath it, and it is where a page goes when it is too long or too machine-facing to belong in
514 Getting Started. No moves, no stub, no redirect, and nothing in the wild breaks.
515
516 | page | source |
517 | --- | --- |
518 | `index.md` — what the topic is, and the path through it | new; links up to the tutorial |
519 | `exit-codes.md` — the six codes, `--stats`, `--on-error`, what goes to stderr | new; today only the packaged README says this |
520 | `catalog.md` — `--catalog`, `--path`, `--catalog-search`, and the capability | new on the site; the packaged README has it |
521 | `formats.md` — every layout and file format, `-o`, the `-tAc` idiom | expands the tutorial's list into a reference |
522 | `config.md` — the config spec, `${VAR}`, secrets, the `--config` modes | new; links across to the `config-file/` topic |
523 | `safety.md` — `--read-only`, `--timeout`, the capability flags | M2's PR 17 content, if it has not landed |
524 | `psql.md` — the differences table | M2's PR 17 content |
525 | `reference.md` — the generated CLI reference | §3.1b, vendored |
526 | `skill.md` — what the skill is, and the three ways to install it | §3.5 |
527 | `mcp.md` | **not in M3** — M6 |
528
529 The tutorial keeps its shape and gains links out: each section that currently ends by
530 summarizing something ("hsql's exit codes are meaningful and stable," the format list) points
531 at the reference page that now covers it in full. The rule for which side of the line a fact
532 falls on is whether a human reads it once or an agent reads it every time.
533
534 ### 3.7 Copy and view as markdown
535
536 In the docs layout, beside the page title: a "Copy as Markdown" button and a "View as
537 Markdown" link to the page's own `.md` URL. The copy variant prepends the canonical URL and
538 title as a two-line header, so a pasted page carries its provenance. The button fetches the
539 `.md` route rather than re-deriving anything — one sanitizer, five consumers, and this is
540 consumer five.
541
542 ---
543
544 ## 4. Sequencing
545
546 Two repos. The `harlequin` PRs go first, because the site's new pages vendor their artifacts,
547 and because the skill cannot honestly say "prefer `--read-only`" until M2's PR 13 has shipped.
548 Numbering continues within this milestone; `harlequin-web` has no version numbers, so its PRs
549 are listed in dependency order and deploy continuously.
550
551 ### Release A — truth and the skill (`harlequin`, 2.13)
552
553 **PR 1 — The flag guard, and the flags it catches.** The extractor and the test (§3.1a), plus
554 the fixes it forces: `--results` → `--result` and `--parquet` → `--format parquet` in
555 `packaging/hsql/README.md`. Fails on `main` today. Bug Fixes entry — this is a documented
556 command line that does not run.
557
558 **PR 2 — The generated CLI reference.** `scripts/write_cli_reference.py`,
559 `docs/generated/hsql-reference.md`, and the regenerate-and-compare test, modeled on
560 `test_config_schema.py`. No user-facing behavior; the artifact is what PR 5 publishes.
561
562 **PR 3 — `hsql --skill`, and the skill.** The skill text as package data,
563 `hsql/modes/skill.py`, `-o` support, the import-hygiene assertion that it loads no adapter,
564 the frontmatter and size guards (§5), and the flag guard extended to cover it. The
565 description gets its optimization pass before merge, with the trigger eval set committed
566 beside the skill (§3.5). **Lands after M2's PR 13**, so §3.5's section 8 is true when it
567 ships. Features entry.
568
569 **PR 4 — The marketplace entry.** `.claude-plugin/marketplace.json` at the repo root and
570 `.claude-plugin/plugin.json` beside the skill, making `src/harlequin/hsql/skill` a
571 single-skill plugin with no copied file (§3.5, tier 2), plus `claude plugin validate` in CI.
572 Small, and separable from PR 3 so a problem with either lands alone. Features entry — the
573 install line is the user-facing part.
574
575 **PR 5 — The publishing workflow.** The `release.yml` step that copies `config-v1.json`,
576 `hsql-reference.md` and `SKILL.md` plus a `manifest.json` into a PR against `harlequin-web`
577 (§3.4). No changelog entry; it is release plumbing.
578
579 ### Release B — the site (`harlequin-web`, continuous)
580
581 **PR 6 — `/schemas/config/v1.json`, and the artifacts directory.** The vendored files and the
582 routes that serve them. First, and separately from everything else, because it fixes a URL
583 that has been live and broken in every generated schema since 2.10 (§1.5).
584
585 **PR 7 — The corpus and the sanitizer.** `src/lib/server/docs.ts`, and the repo's first test
586 runner (vitest): golden files for four representative pages — one with a script block and
587 figures, one dense with `<Key>`, one with a callout and relative links, one plain — plus the
588 docs lint (§3.1c). The lint fails until the two 404 links in §1.4 are fixed, so they are
589 fixed here. Otherwise nothing user-visible ships in this PR; it is the foundation the next
590 four stand on.
591
592 **PR 8 — Raw markdown per page.** `/docs/{topic}/{page}.md`, prerendered, `text/markdown`.
593
594 **PR 9 — `llms.txt` and `llms-full.txt`.** Plus the `robots.txt` lines and, for pages that
595 want one, the `description` frontmatter key.
596
597 **PR 10 — Docs API v1.** The index and the per-page route, CORS, `/api/docs` untouched. No
598 search (§6).
599
600 **PR 11 — Copy and view as markdown.** The layout buttons.
601
602 **PR 12 — The Headless & Agents topic.** The nine new pages in §3.6, the links out from the
603 tutorial, the vendored reference page and the skill page. `getting-started/hsql.md` stays
604 where it is. The largest content PR in the milestone, and the one that most wants a careful
605 read rather than a fast one.
606
607 **PR 13 — The homepage correction.** `--results` in `hsql_features.svelte`, and a link from
608 the `#hsql` section to the new topic.
609
610 ### Release C — the ecosystem
611
612 **PR 14 — `AGENTS.md` in `harlequin-adapter-template`.** D7's remaining half: repo layout, the
613 adapter contract's required members, how to run tests, and — new since the product plan was
614 written — `type_name`, `search_catalog()` and the capability flags M2 added, so an adapter
615 written from the template declares them rather than discovering them later.
616
617 **And one follow-up to file, not to build:** the community-marketplace submission (§3.5,
618 tier 3). It is a form, it depends on PR 4 being live, and it is reviewed on someone else's
619 schedule, so it does not belong in a PR list.
620
621 **Ordering rationale.** Same as M1 and M2: the guard lands before the thing it guards, the
622 artifact lands before the page that publishes it, and nothing that needs another repo's
623 release blocks anything that doesn't. The one hard dependency across milestones is PR 3 on
624 M2's PR 13.
625
626 ---
627
628 ## 5. Testing
629
630 The M1/M2 guards stay. What M3 adds is the first coverage either repo has had of the text
631 humans and agents *read*, which until now has been the only untested output Harlequin
632 produces.
633
634 - **Every long flag in the packaged README and in the skill exists in `hsql --spec`.** With a
635 small allowlist for other programs' flags (`uv`'s `--with`, `pytest`'s `--snapshot-update`),
636 asserted by name so an addition to the allowlist is a visible decision.
637 - **`hsql --skill` is byte-identical to the packaged file**, and writing it with `-o` produces
638 the same bytes as stdout — the M1 property ("the bytes are the contract"), applied to the
639 one output that is not a result set.
640 - **`hsql --skill` imports no adapter, no tomlkit, no questionary.** A subprocess reading
641 `sys.modules`, like every other import-hygiene test, with a matching `ignore_imports` entry.
642 - **The skill's frontmatter uses only the six spec fields**, parses as YAML, and carries a
643 non-empty `description`; the body stays under 200 lines and 4KB. The field check is what
644 keeps the file loadable outside Claude Code (§3.5), and the size check is what keeps a later
645 edit from quietly turning a skill into a manual.
646 - **`claude plugin validate` passes** on `src/harlequin/hsql/skill`, and the marketplace entry
647 names a source directory that exists. In CI where the `claude` CLI is available; skipped,
648 not silently passed, where it is not.
649 - **The generated reference regenerates identically.** `test_cli_reference.py` runs the
650 generator and compares to the committed file, exactly as `test_config_schema.py` does.
651 - **Sanitizer goldens.** Four pages, checked in as expected markdown. A component tag the
652 sanitizer does not know throws, and there is a test that asserts it throws — the degradation
653 path is the one nobody exercises.
654 - **No sanitized page contains** a `<Capitalized` tag, an unresolved `{identifier}`, `&lbrace`,
655 or a relative link. Asserted over the whole corpus, so it covers pages written after this
656 milestone.
657 - **Every internal link in the sanitized corpus resolves** to a page the corpus contains —
658 after the `x/index` normalization, so a link the router rescues today is still checked. It
659 fails on the two 404s in §1.4, and it is what stops the §3.6 moves from leaving holes.
660 - **`llms.txt` lists exactly as many pages as `src/docs` holds**, so a new page cannot be
661 silently missing from the index an agent reads first.
662 - **The `.md` route and `llms-full.txt` agree byte for byte** for the same page. They are two
663 views of one corpus, and the moment they disagree, one of them is a second sanitizer.
664 - **The vendored artifacts parse.** `config-v1.json` is valid JSON Schema; `manifest.json`
665 names a version that matches the reference page's generated-from line.
666
667 Not tested, still: whether an agent that reads the skill picks the right flag first try. That
668 is the agent eval suite dropped from M1 (§13 of the product plan), and M3 is the milestone
669 where it would finally have a stable surface to run against — the skill is a fixed text, and
670 `--spec` makes the expected-flag assertions cheap to write. It stays out of scope here, and it
671 is the single most valuable thing that could be added to it.
672
673 ---
674
675 ## 6. Decisions
676
677 **Settled.**
678
679 - **The skill ships in the wheel and prints from a mode option.** `hsql --skill`, consistent
680 with M2 §3.1 — modes are options, not subcommands. One copy of the text, version-matched to
681 the installed CLI, and no network needed to install it.
682 - **The skill teaches the questions, not the answers.** No adapter list, no option table, no
683 format list; `--info`, `--spec` and `--help -a` instead. This is what keeps it ~1,000 tokens
684 and what keeps it from rotting.
685 - **One sanitizer, one corpus.** The raw route, `llms-full.txt`, the API and the copy button
686 all call `buildCorpus()`. A second markdown-producing path is the same mistake as a second
687 normalizer in `query.fetch()`.
688 - **`llms.txt` is the front door; `llms-full.txt` is the fallback.** 29,000 tokens is not an
689 opening move.
690 - **`.md` suffix routes, not `Accept` negotiation** (§3.3).
691 - **`/api/docs` is untouched and v1 is additive.** The sidebar depends on the old shape,
692 including its `"/src"` quirk; a fix there is a rendering change, not a docs-for-machines
693 change, and it does not belong in this milestone.
694 - **Artifacts are vendored into the site by a release workflow, not fetched at build time**
695 (§3.4) — recommended, and the one worth Ted's explicit yes before PR 5.
696 - **Prerender, don't ISR, for everything M3 adds.** The corpus changes when the repo does.
697 - **Docs API v1 ships no search.** The index plus a page fetch is what an agent actually does,
698 and a mediocre search endpoint is a support surface with no consumer asking for it.
699 - **No `updated_at` in the API payload.** Nothing in the repo can supply one honestly — no
700 date in the frontmatter, no git history on a shallow Vercel checkout — and a field that
701 lies is worse than a field that is missing.
702 - **`getting-started/hsql.md` stays where it is, and Headless & Agents is additive** (§3.6).
703 The tutorial is the page a human lands on and the page the README links to; the new topic is
704 the reference underneath it. No moves, no redirect.
705 - **The skill's frontmatter is the six-field Agent Skills spec, and nothing else** (§3.5). A
706 skill whose argument over MCP is "it works in any harness" does not get to ship a
707 vendor-locked file.
708 - **The description gets a deliberate optimization pass, with its eval set committed** (§3.5).
709 It is the only part always in context and the only thing that decides whether the skill
710 loads at all.
711 - **`allowed-tools` names the introspection modes and never `Bash(hsql *)`.** Reading a
712 catalog without a prompt is a convenience; running arbitrary SQL without one is not a
713 decision this skill gets to make for a user.
714
715 **Open.**
716
717 - **Do we submit to the community marketplace, and when?** Tier 3 in §3.5 is the only install
718 that is genuinely one command for a user who has installed nothing of ours, and it costs a
719 form rather than a repo now that the marketplace entry lives in this repo. The real cost is
720 what it commits us to: a skill in a public catalog is one more surface with a compatibility
721 expectation. Recommend filing it once PR 4 is live and the skill has survived one release.
722 - **Does the release workflow open the `harlequin-web` PR, or does a human run the script?**
723 §3.4 assumes automation, which needs a token with write access to the other repo. A `make
724 publish-artifacts` that a human runs at release time is the same script without the
725 credential, at the cost of a step someone can forget.
726 - **Does anything besides the skill and the reference want to be a vendored artifact?** The
727 packaged README is the obvious candidate — it duplicates a good deal of what the new topic
728 will say — and the answer is probably to shrink the README rather than publish it twice.
729
730 ---
731
732 ## 7. Explicitly not in M3
733
734 - **`hsql mcp`** — M6, and the skill is deliberately the thing that ships first (product plan
735 §9). The `mcp.md` page waits for it.
736 - **`hsql open`, `hsql history`, "Copy CLI command", the external-command hook** — the rest of
737 M4. Only E1 was pulled forward. §3.5's section 9 is the paragraph M4 rewrites.
738 - **Streaming and pagination** — M5.
739 - **An agent eval suite** — still out (§5), still the thing most worth adding back.
740 - **Docs search, in any form** (§6). Not the endpoint, and certainly not a vector index over
741 55 pages: `llms.txt` plus a page fetch is the search.
742 - **Docs versioning.** Per-release snapshots of the docs site, so an agent can read the docs
743 for the version it has installed. Real, and much bigger than this milestone: it changes every
744 route. The `manifest.json` version line (§3.4) is the cheap partial answer.
745 - **Auto-generating adapter pages from each adapter's `--spec`.** It would need every
746 out-of-tree adapter installed at site build time, which is the hermetic-build problem again,
747 multiplied by twelve.
748 - **Bundled reference files, scripts or assets in the skill.** Its third layer is the CLI
749 (§3.5). The day that stops being enough is the day `references/` earns its place, and not
750 before.
751 - **Fixing the site's sidebar API shape** (§1.6's `"/src"`), and the `getting-started/hsql.md`
752 brace bug in the *rendered* page. Both are one-line fixes and both are rendering bugs, not
753 machine-readability ones; they ride along in PRs 6 and 12 respectively rather than earning
754 their own scope.
755
756 ---
757
758 ## 8. Corrections to the product plan
759
760 Recorded here; applied to `harlequin-for-agents.md` in the same PR as this document.
761
762 - **§9's E1 outline uses spellings that do not exist.** `hsql info --json`, `hsql spec --json`
763 and `catalog --depth 2` were all written before M2 settled on mode options. The real
764 spellings are `hsql --info` and `hsql --spec` (both JSON, always), and `--catalog` with
765 `--path`, plus `--catalog-search TERM`. `--depth` was cut from M2 outright (M2 §7), so
766 "orient with `catalog --depth 2`" describes a flag that will not exist until
767 `fetch_descendants()` does.
768 - **§9 calls the skill "one markdown file" and leaves it there.** It is a file with a
769 contract: Agent Skills is an open standard, its portable frontmatter is six fields, and the
770 description is the part that decides whether the skill is ever loaded. §9's own argument for
771 skill-before-MCP — that it works in any harness — is only true if the file is written to
772 that standard rather than to one client's extensions (§3.5).
773 - **§9 says the skill is "published on the site, and installable" without saying how.**
774 Installable now means three things, and they are not equivalent: `hsql --skill -o` from the
775 wheel, a marketplace entry that this repo can host without a second repo or a copied file,
776 and a community-catalog listing. The first is the one the docs lead with, because it is the
777 only one that cannot disagree with the installed CLI (§3.5).
778 - **§9's "Prefer `--read-only`" is conditional on a capability.** Read-only is declared per
779 adapter (M2 §3.4), so the skill has to say "where the adapter declares it, which `--info`
780 will tell you," not "always."
781 - **§8's D6 and D7 largely shipped during M1/M2.** The homepage has its two-command section
782 and its `#hsql` block; `AGENTS.md` is in both `harlequin` and `harlequin-web`. What is left
783 is a one-word correction on the homepage and `AGENTS.md` in the adapter template. The
784 roadmap's M3 row overstates the remaining work by two of its seven items.
785 - **§8's D1 treats `llms-full.txt` as the primary affordance** — "an agent fetches one URL and
786 knows everything." Measured, that URL is ~29,000 tokens. `llms.txt` plus per-page `.md` is
787 the primary path; `llms-full.txt` is for the caller who genuinely wants the corpus.
788 - **§8's D3 asks for `updated_at`, which nothing can supply honestly.** There is no date in
789 the frontmatter and no git history on the build machine. Drop the field (§6).
790 - **§8's D3 search endpoint is cut.** Over 55 pages and 116KB, `llms.txt` plus a page fetch
791 *is* the search, and it is the thing an agent will reach for anyway. v1 is the index and the
792 page (§6).
793 - **§8's D2 says "the real work is sanitization" and understates it by one case.** The hard
794 one is not the components, it is that `<Figure src={init}>` resolves through an import in the
795 `<script>` block the sanitizer is deleting — so the transform has to read the block before it
796 removes it (§3.2, steps 2 and 4).
797 - **§8 does not mention that the site is already a publishing target.** `hsql --config schema`
798 has been emitting `$id: https://harlequin.sh/schemas/config/v1.json` since 2.10, and that
799 URL 404s. Publishing generated artifacts is a Workstream D deliverable that the roadmap
800 never listed (§1.5, §3.4).
801 - **§8 assumes the docs are correct, and they are not.** Two flags documented in three places
802 exit 2, two internal links 404 (§1.4), and the page written for agents renders `&lbrace`
803 where `{` belongs (§1.3).
804 The workstream's first deliverable is a check, not a corpus — otherwise M3 publishes the
805 same errors through four more channels.