writeonce/docs/examples/skill-catalog/README.md
shoney.arickathil 5941a092f7 feat(query-corpus): iteration 9g corpus #1 — skillhost needs no new query grammar
- resolved 9g's forks EMPIRICALLY against the running compiler:
  - count(<query>) and len(<query>) already work (fork 2 collapses to
    zero code)
  - skillhost's correlated NOT EXISTS is a backlink emptiness in
    writeonce (`where len(x.children) == 0`), using only 9b machinery
    (fork 1) — verified on a self-referential ?ref/backlink table
  => corpus #1 forces NO new grammar; per the method ("add only what a
     corpus uses"), exists/not-exists was NOT built
- docs/examples/skill-catalog: mirrors skillhost's `skills` table
  (name @unique, description/location/root, parent ?ref Skill, children
  backlink) and translates all five of its SQL statements 1:1
  (insert+dup-trap, get-by-name, list, roots via backlink-emptiness,
  count); scripts/skill-catalog-accept.sh 7/0, WAL-durable, dup trap
  persists across restart
- fixture run/db-query-corpus (count(query) + backlink NOT EXISTS);
  just skill-catalog module; target/ gitignored
- general exists/not-exists left unbuilt and recorded as "enters when a
  corpus forces a non-relation correlation"
- gates: oop-e2e 80/0, woc-test 566/0, skill-catalog 7/0; story + board
  record the finding

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 4c82461634d45f11eca1a252702031c03d999c7f)
2026-09-15 01:15:30 +02:00

1.9 KiB

skill-catalog — the query grammar corpus (iteration 9g)

Corpus #1 for the query-grammar method (story 09g): take a real application backed by an embedded SQL database, translate its every statement to the writeonce query surface, and add only the grammar it forces. The application is ~/projects/skillhost (a C++ MCP host whose in-memory SQLite holds its skill catalog).

Result: skillhost forced no new grammar. Its entire SQL footprint — one table, a single-row INSERT, and four SELECTs (whose only non-trivial features are COUNT(*) and a correlated NOT EXISTS) — is expressible on the surface iteration 9b already shipped. The five statements, translated:

skillhost SQL (src/catalog/catalog.cpp) writeonce mode
INSERT INTO skills (…) VALUES (?,…) + SQLITE_CONSTRAINT dup check insert Skill { … } + try…catch on the @unique trap seed
SELECT … WHERE name = ? from x in Skill where x.name == n take 1 select x get <name>
SELECT … ORDER BY name from x in Skill order by x.name select x list
SELECT COUNT(*) FROM skills count(from x in Skill select x) count
SELECT … WHERE NOT EXISTS (SELECT 1 FROM skills c WHERE c.parent = s.name) ORDER BY name from x in Skill where len(x.children) == 0 order by x.name select x roots

The one translation choice: skillhost's correlated NOT EXISTS (skills that are nobody's parent) becomes a backlink emptiness — Skill.children is the inverse of parent, and len(x.children) == 0 is the childless test. No subquery construct is needed; the general exists/not exists is deferred until a corpus uses a correlation a backlink cannot express.

skill-catalog seed | list | roots | count | get <name>, WAL-durable under WO_DATA. Acceptance: scripts/skill-catalog-accept.sh.