Skip to content

Commit 7fec23e

Browse files
committed
feat(recipes): migrate bundled recipes to templates/recipes/<id>.{sql,md} (Tracer 2 of 6)
QUERY_RECIPES TypeScript object map → templates/recipes/<id>.sql + sibling .md description files. cli/query-recipes.ts becomes a thin shim that calls loadAllRecipes() at first access and caches the result. 12 bundled recipes migrated: fan-out, fan-out-sample, fan-out-sample-json, fan-in, index-summary, files-largest, components-by-hooks, markers-by-kind, deprecated-symbols, visibility-tags, files-hashes, barrel-files. Each gets a .sql file (verbatim) + .md (description body — first non-empty line becomes the catalog 'description'). Backwards-compat preserved: - QUERY_RECIPES exported as a Proxy so callers (cmd-query.ts, mcp-server.ts) can still use the legacy object-shape access (QUERY_RECIPES['fan-out'].description, Object.keys(QUERY_RECIPES), etc.) without changes - getQueryRecipeSql / getQueryRecipeActions / listQueryRecipeIds / listQueryRecipeCatalog all derive from the registry — same return shapes - Smoke tested: bun src/index.ts query --recipes-json + query --print-sql fan-out + query-golden all green Bundled recipe actions stay in code (BUNDLED_RECIPE_ACTIONS map) through Tracer 5 — that tracer adds the YAML frontmatter parser and lifts these into the .md files alongside descriptions, completing the migration. New: resolveBundledRecipesDir() in cli/query-recipes.ts mirrors resolveAgentsTemplateDir()'s npm-package layout (templates/recipes/ next to templates/agents/). _resetRecipesCacheForTests() escape hatch added for fixture swaps. templates/ already shipped in the npm artifact (per package.json files); templates/recipes/ inherits. Tracer 1's loader now has a real consumer; Tracer 3 will plug in projectDir for .codemap/recipes/<id>.sql discovery.
1 parent b19c603 commit 7fec23e

25 files changed

Lines changed: 259 additions & 215 deletions

src/cli/query-recipes.ts

Lines changed: 161 additions & 215 deletions
Large diffs are not rendered by default.

templates/recipes/barrel-files.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Top 20 files by export count (barrel / public-API candidates)
2+
3+
High export count can indicate either an intentional public API surface or accidental fan-out. Agents can use this to decide whether a new export should land here or stay local. If it's accidental fan-out, consider splitting into smaller barrels.

templates/recipes/barrel-files.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT file_path, COUNT(*) AS exports
2+
FROM exports
3+
GROUP BY file_path
4+
ORDER BY exports DESC, file_path ASC
5+
LIMIT 20
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
React components with the most hooks (comma count on stored JSON array)
2+
3+
Hook count uses comma tally + 1 on the stored JSON array (Codemap emits flat `["useFoo","useBar"]` shapes). Avoids SQLite JSON1 (`json_array_length`) so the recipe runs on any SQLite build the CLI already supports.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT name, file_path,
2+
CASE
3+
WHEN hooks_used IS NULL OR trim(hooks_used) = '' OR trim(hooks_used) = '[]' THEN 0
4+
ELSE (length(hooks_used) - length(replace(hooks_used, ',', ''))) + 1
5+
END AS hook_count
6+
FROM components
7+
ORDER BY hook_count DESC, file_path ASC, name ASC
8+
LIMIT 20
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Symbols whose JSDoc contains @deprecated (caller-warning candidates)
2+
3+
Useful for agents to flag callers of soon-to-be-removed APIs before suggesting changes. Pair with `WHERE name = '<symbol>'` against the `calls` table to find the actual call sites.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT name, kind, file_path, line_start, signature, doc_comment
2+
FROM symbols
3+
WHERE doc_comment LIKE '%@deprecated%'
4+
ORDER BY file_path ASC, line_start ASC
5+
LIMIT 50

templates/recipes/fan-in.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Top 15 files by fan-in (how many other files depend on them)
2+
3+
Files at the top are the most-imported in the codebase — changes here ripple through many consumers. Protect with tests before refactoring; treat as the project's de-facto stable API even if not formally exported.

templates/recipes/fan-in.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT to_path, COUNT(*) AS fan_in
2+
FROM dependencies
3+
GROUP BY to_path
4+
ORDER BY fan_in DESC, to_path ASC
5+
LIMIT 15
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Like fan-out-sample, but sample_targets is a JSON array (requires JSON1)
2+
3+
Same ranking as `fan-out-sample`, but uses SQLite's JSON1 `json_group_array`. Prefer `fan-out-sample` if your SQLite build doesn't include JSON1.

0 commit comments

Comments
 (0)