Make Reference Queries Inspectable
tasks13/15
1. Inventory
- Re-audit
swap-sqlite-driver/tasks.mdand classify every remaining query-extraction checkbox as static, dynamic, or obsolete.- 2026-04-24 proof slice:
swap-sqlite-driveris archived atopenspec/changes/archive/2026-04-25-swap-sqlite-driver/; its only query-extraction follow-up is transferred to this change. Static extraction remains active here, dynamic builders remain in code, and obsolete driver-swap work is complete.
- 2026-04-24 proof slice:
- Count current SQL call sites across
server/,runtime/,lib/, and tests.- 2026-04-24 proof slice count after the registry/test addition: 285
prepare/execmatches total (server: 164,runtime: 10,lib: 13,test: 98).
- 2026-04-24 proof slice count after the registry/test addition: 285
- Identify dynamic query sites that should explicitly stay in code.
- 2026-04-24 proof slice: dynamic builders remain in
records.jsfor grant/resource filters, cursor predicates, expansionIN (...)lists, and order clauses; insearch.js/search-semantic.jsfor authorized stream/resource plans and variable candidate sets; inlib/spine.tsfor correlation filters and checked dynamic columns; and inref-control.tsfor records timeline filters/timestamp ordering.
- 2026-04-24 proof slice: dynamic builders remain in
2. Query Registry
- Add
reference-implementation/server/queries/with a deterministic loader. - Map query file names to stable camelCase registry keys.
- Fail fast when a required query artifact is missing or malformed.
3. Extraction
- Extract one low-risk server module first and validate the pattern.
- 2026-04-24 proof slice: extracted
list-registered-connectors.sqland wiredref-control.tsconnector listing throughreferenceQueries.listRegisteredConnectors.
- 2026-04-24 proof slice: extracted
- Extract remaining static server/runtime/lib statements in small commits.
- Extract test-only static statements only where it improves readability.
- Leave dynamic query builders in code with short comments explaining why.
- 2026-04-24 proof slice: documented the touched
ref-control.tstimeline dynamic builder; broader dynamic builders listed above remain for later extraction slices.
- 2026-04-24 proof slice: documented the touched
4. Validation
- Add a query/schema validation command or test.
- 2026-04-24 proof slice:
reference-implementation/test/query-registry.test.jsvalidates deterministic loading and prepares extracted queries against the reference schema.
- 2026-04-24 proof slice:
- Run the focused reference test suites touched by extraction.
- 2026-04-24 proof slice:
node --test reference-implementation/test/query-registry.test.jsandnode --test reference-implementation/test/control-actions.test.jspassed.
- 2026-04-24 proof slice:
- Run
pnpm --dir reference-implementation run verify.- 2026-04-24 proof slice: passed after tightening the required-query registry type and moving loader regexes to module scope.
- Run
openspec validate make-reference-queries-inspectable --strict.- 2026-04-24 proof slice: passed.
- Run
openspec validate --all --strict.- 2026-04-24 proof slice: passed, 12 items.