Skip to content

fix: make trgm adapter supplementary, enhance codegen docs, and slim down AGENTS.md#825

Merged
pyramation merged 6 commits intomainfrom
devin/1773602933-fix-trgm-search-codegen
Mar 15, 2026
Merged

fix: make trgm adapter supplementary, enhance codegen docs, and slim down AGENTS.md#825
pyramation merged 6 commits intomainfrom
devin/1773602933-fix-trgm-search-codegen

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Mar 15, 2026

Summary

Fixes the issue where trgm similarity fields (nameTrgmSimilarity, searchScore, etc.) were appearing as required create fields in generated CLI README docs for every table with text columns — even tables with no intentional search configuration.

Three-layer fix:

  1. Graphile search plugin (graphile-search): Introduces isSupplementary and isIntentionalSearch flags on the SearchAdapter interface. The trgm adapter now defaults to requireIntentionalSearch: true, making it supplementary. The plugin's getAdapterColumns runs primary adapters first, then only runs supplementary adapters (trgm) if at least one adapter with isIntentionalSearch: true found columns on that table.

    Crucially, pgvector sets isIntentionalSearch: false — embedding columns are a different domain from text search, so their presence alone does not trigger trgm. Only tsvector columns and BM25 indexes count as "intentional search."

  2. Codegen docs (graphql/codegen): getEditableFields now accepts an optional TypeRegistry and uses getWritableFieldNames to filter out computed/plugin-added fields. A new getSearchFields utility identifies these fields so they can be excluded from create/update field lists.

  3. Special field categorization in generated docs: A new categorizeSpecialFields utility detects and groups fields into three categories — PostGIS geospatial, pgvector embeddings, and Unified Search API — and surfaces them with descriptive context in README and skill reference docs.

Updates since last revision

  • Removed AGENTS.md snapshot tests: All four AGENTS.md snapshot tests (generates CLI AGENTS.md, generates ORM AGENTS.md, generates hooks AGENTS.md, generates multi-target AGENTS.md) removed from cli-generator.test.ts along with their stale snapshot entries (~903 lines deleted from snapshot file) and unused imports. Since AGENTS.md is now a thin router, snapshot-testing its content adds maintenance burden without meaningful coverage.

Previous updates

  • AGENTS.md refactored to thin routers: All four AGENTS.md generators (generateAgentsDocs, generateMultiTargetAgentsDocs, generateOrmAgentsDocs, generateHooksAgentsDocs) now emit ~30-50 line index files instead of full inline API references. Each AGENTS.md now contains only: stack overview, quick start snippet, links to README.md for full API docs, conventions, and a "do not edit" boundary notice. This is motivated by research showing large auto-ingested AGENTS.md files reduce agent task success rates and increase inference cost. Full API references remain in README.md (opt-in, not auto-ingested). Net change: ~780 lines of inline content generation removed, replaced with ~89 lines of minimal router content.
  • Skills references removed from AGENTS.md (skills are generated to a separate directory and don't need to be referenced in the auto-ingested file).
  • Unused buildSpecialFieldsPlain import removed from CLI and ORM docs generators (special field sections now only appear in README and skill files, not in the slim AGENTS.md).
  • Updated schema snapshot (graphql/server-test): The schema-snapshot.test.ts snapshot was regenerated. It confirms the plugin changes work correctly — trgm similarity fields, trgm search filters, fullTextSearch filters, trgm ordering enums, and searchScore were all removed from 5 tables (users, posts, tags, comments, post_tags) that have no tsvector/BM25 columns. This is a 200-line deletion from the snapshot, validating the supplementary adapter logic.

Review & Testing Checklist for Human

  • Breaking change review: requireIntentionalSearch defaults to true — any existing createTrgmAdapter() call with no options will now suppress trgm on tables without intentional search. Pass requireIntentionalSearch: false to restore old behavior. Check all call sites.
  • Two-flag interaction review (types.ts): isSupplementary controls whether an adapter waits for others; isIntentionalSearch controls whether an adapter's presence triggers supplementary adapters. Verify the interaction is correct — e.g. a table with only pgvector columns (isIntentionalSearch: false) should NOT activate trgm, but a table with tsvector + pgvector should.
  • AGENTS.md output review: Generated AGENTS.md files now reference specific sibling files (README.md, types.ts, orm.ts, hooks.ts, helpers.ts). Verify these files are actually emitted by the corresponding generators so the links resolve. Run cnc codegen and inspect the generated AGENTS.md files across CLI, ORM, and hooks directories.
  • Downstream tooling check: If any scripts, CI jobs, or agent workflows parse the old AGENTS.md structure (e.g. looking for ## TOOLS, ## HOOKS, ## MODELS sections), they will need updating — those sections no longer exist in AGENTS.md (they remain in README.md).
  • Verify generated output end-to-end: Run cnc codegen against constructive-db and diff the generated sdk/constructive-cli/cli/README.md and AGENTS.md. Confirm: (a) tables without intentional search no longer show *TrgmSimilarity or searchScore in "Required create fields", (b) tables WITH tsvector/BM25 still get trgm fields, (c) PostGIS/pgvector/search fields appear in dedicated descriptive sections in README where expected, (d) AGENTS.md is now a short ~30-50 line router file.

Recommended test plan: Run cnc codegen against constructive-db, then inspect: (1) cli/AGENTS.md is a thin router pointing to README.md, (2) orm/AGENTS.md similarly minimal, (3) cli/README.md still has full API docs with special field sections, (4) trgm fields gone from tables without search in both README and schema snapshot.

Notes

  • The fix addresses the issue seen in constructive-db PR #585 where the generated sdk/constructive-cli/cli/README.md listed trgm fields as required create fields.
  • Build passes (pnpm build). Codegen unit tests have a pre-existing Jest ESM configuration issue (all 18 suites fail to parse TypeScript imports) that is unrelated to these changes.
  • All getEditableFields call sites in CLI generators now pass the TypeRegistry. ORM generators do not yet thread the registry (backward-compatible — no filtering when registry is absent).
  • The schema snapshot test passes with the updated snapshot confirming trgm fields removed from 5 tables.
  • AGENTS.md snapshot tests were intentionally removed (not just updated) since the thin router content is simple enough that snapshot testing adds more maintenance cost than value.

Link to Devin session: https://app.devin.ai/sessions/1032ba4c970343ad8b0d8e00a56a6d51
Requested by: @pyramation


Open with Devin

…degen docs

- Add isSupplementary flag to SearchAdapter interface
- trgm adapter now only activates on tables that already have intentional
  search (bm25 indexes, tsvector columns, pgvector embeddings)
- Plugin's getAdapterColumns runs primary adapters first, then only runs
  supplementary adapters if primary adapters found columns
- getEditableFields now accepts TypeRegistry to filter out computed/search fields
- Add getSearchFields utility to identify plugin-added search fields
- CLI docs generators pass registry to getEditableFields for proper filtering
- Add 'Search API fields (computed, read-only)' callout in generated docs
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

pgvector operates on embedding vectors, not text search. Add
isIntentionalSearch flag to SearchAdapter interface so that only
adapters representing real search infrastructure (tsvector, BM25)
trigger supplementary adapters. pgvector sets isIntentionalSearch: false.
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@devin-ai-integration devin-ai-integration bot changed the title fix: make trgm adapter supplementary and filter search fields from codegen docs fix: make trgm adapter supplementary and enhance codegen docs for search fields Mar 15, 2026
… inline references

AGENTS.md files are auto-ingested by AI coding agents. Large files reduce
task success rates and increase inference cost (ETH Zurich research).

Changes:
- CLI AGENTS.md: stack overview, quick start, pointer to README.md
- Multi-target CLI AGENTS.md: same pattern with target info
- ORM AGENTS.md: stack overview, quick start, pointer to README.md
- Hooks AGENTS.md: stack overview, quick start, pointer to README.md
- Full API references remain in README.md (opt-in, not auto-ingested)
- Skills references removed from AGENTS.md (generated separately)
@devin-ai-integration devin-ai-integration bot changed the title fix: make trgm adapter supplementary and enhance codegen docs for search fields fix: make trgm adapter supplementary, enhance codegen docs, and slim down AGENTS.md Mar 15, 2026
@pyramation pyramation merged commit 4f80932 into main Mar 15, 2026
44 checks passed
@pyramation pyramation deleted the devin/1773602933-fix-trgm-search-codegen branch March 15, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant