Skip to content

chore(drizzle): alias _query to query and enforce via lint#3118

Open
RSO wants to merge 1 commit intomainfrom
RSO/silent-sphere
Open

chore(drizzle): alias _query to query and enforce via lint#3118
RSO wants to merge 1 commit intomainfrom
RSO/silent-sphere

Conversation

@RSO
Copy link
Copy Markdown
Contributor

@RSO RSO commented May 7, 2026

Summary

Prep for drizzle v1, which renames the RQB namespace from query to _query. This change adds a runtime alias so both names work today, rewrites every .query drizzle receiver to ._query, and enforces the new name going forward.

  • New @kilocode/drizzle-shims package patches PgDatabase.prototype and BaseSQLiteDatabase.prototype with a _query getter that returns this.query. Transaction subclasses (PgTransaction, SQLiteTransaction) inherit the alias automatically, so tx._query works everywhere too. Includes module augmentations so TypeScript sees _query on every drizzle db flavour.
  • Side-effect imports (import '@kilocode/drizzle-shims/query-alias';) at every drizzle(...) construction site — packages/db/src/client.ts plus 12 DO service files. The new workspace dep was added to each affected service.
  • oxlint-plugin-drizzle.js gains prefer-underscore-query (AST-only, autofixable, name-gated on ["db", "ctx.db", "this.db", "tx", "trx"] — same posture as the existing two drizzle rules). Enabled as "error" in .oxlintrc.json.
  • scripts/drizzle-query-rename.ts — ts-morph codemod / CI verifier. Because oxlint plugins can't see types, this script is the authoritative check: it walks every workspace tsconfig plus dev/ and scripts/ orphan files and identifies .query property accesses whose query property is declared inside drizzle-orm. Runs as pnpm drizzle:query-rename (--fix) or pnpm drizzle:query-check; the latter is wired into pnpm validate.
  • 372 call sites across 76 files rewritten from .query to ._query.

When drizzle v1 lands, delete packages/drizzle-shims/, the 13 side-effect imports, the oxlint rule, and the codemod script. The codebase already reads from _query.

Verification

  • Ran pnpm drizzle:query-check — zero drizzle .query receivers remain across the whole repo.
  • Typechecked touched packages individually (@kilocode/db, @kilocode/drizzle-shims, @kilocode/worker-utils, web, and the nine DO services) — all clean. Full pnpm typecheck skipped per AGENTS guidance.
  • Ran pnpm lint — 0 warnings, 0 errors across 5,690 files.
  • Ran pnpm test — 4,930 passed, 2 skipped, 317 suites.
  • Sanity-checked the oxlint rule against tRPC .query(...) call sites to confirm no false positives; verified the autofix rewrites cleanly on apps/web/src/lib/user.ts.

Visual Changes

N/A

Reviewer Notes

  • The alias is intentionally temporary. It's documented as such at the top of packages/drizzle-shims/src/query-alias.ts with clear removal instructions for the drizzle v1 migration.
  • The oxlint rule is name-based because oxlint JS plugins are AST-only. The ts-morph CI check is the source of truth — it catches any drizzle db in the repo regardless of what it's named (handy for destructured dbs, txn/trx renames, helpers returning a drizzle db, etc.).
  • Rollup emits a cosmetic warning when building @kilocode/trpc's .d.ts about @kilocode/drizzle-shims/query-alias being an external dep. It's benign (the import is type-only from consumers' perspective and resolves via the workspace), but worth flagging.
  • Risk is concentrated at two points: (1) the prototype mutation in query-alias.ts — only additive, no setter, idempotent, non-enumerable; and (2) the codemod correctness — mitigated by the type-aware check, the full test suite passing, and targeted typechecks. Worth spot-checking a handful of rewrites (e.g. apps/web/src/lib/kilo-pass/usage-triggered-bonus.ts) to confirm semantics are preserved.

Prep for drizzle v1, which renames the RQB namespace from `query` to
`_query`. Adds a runtime alias so both names work, rewrites every
`.query` drizzle receiver to `._query`, and enforces the new name with
an oxlint rule plus a type-aware CI check.

- New `@kilocode/drizzle-shims` package patches PgDatabase and
  BaseSQLiteDatabase prototypes with a `_query` getter; transaction
  subclasses (`tx._query`) are covered automatically.
- Side-effect imports added at every `drizzle(...)` construction site
  (packages/db client plus 12 DO service files).
- `oxlint-plugin-drizzle.js` gains `prefer-underscore-query` (autofix,
  name-gated: db / ctx.db / this.db / tx / trx).
- `scripts/drizzle-query-rename.ts` is a ts-morph codemod/verifier that
  walks every workspace tsconfig plus dev/ and scripts/ orphans and
  checks the drizzle `query` property by declaration location. Exposed
  as `pnpm drizzle:query-rename` and `pnpm drizzle:query-check`; the
  check runs as part of `pnpm validate`.
- 372 call sites across 76 files rewritten.
*/

import { Project, Node, SyntaxKind } from 'ts-morph';
import { readFileSync } from 'node:fs';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WARNING: readFileSync is imported but never used

This new script is wired into pnpm validate, but the unused import will be flagged by the existing no-unused-vars linting and can make validation fail even though the checker itself works. Remove this import so the added CI step does not break lint.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 7, 2026

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
scripts/drizzle-query-rename.ts 19 Unused readFileSync import can fail lint/validation
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
N/A N/A N/A
Files Reviewed (103 files)
  • .oxlintrc.json - 0 issues
  • apps/web/src/app/admin/api/users/add-credit/route.ts - 0 issues
  • apps/web/src/app/admin/api/users/credit-transactions/route.ts - 0 issues
  • apps/web/src/app/admin/api/users/payment-methods/route.ts - 0 issues
  • apps/web/src/app/admin/api/users/route.ts - 0 issues
  • apps/web/src/app/admin/organizations/[id]/webhooks/page.tsx - 0 issues
  • apps/web/src/app/admin/users/[id]/page.tsx - 0 issues
  • apps/web/src/app/admin/users/[id]/webhooks/page.tsx - 0 issues
  • apps/web/src/app/api/cron/deployment-threat-scan/route.ts - 0 issues
  • apps/web/src/app/api/dev/create-kilocode-org/route.ts - 0 issues
  • apps/web/src/app/api/up/route.ts - 0 issues
  • apps/web/src/app/api/user-deployments/webhook/route.ts - 0 issues
  • apps/web/src/app/payments/topup/success/actions.tsx - 0 issues
  • apps/web/src/lib/admin-utils-serverside.ts - 0 issues
  • apps/web/src/lib/affiliate-attribution.ts - 0 issues
  • apps/web/src/lib/affiliate-events.ts - 0 issues
  • apps/web/src/lib/ai-gateway/processUsage.test.ts - 0 issues
  • apps/web/src/lib/ai-gateway/processUsage.ts - 0 issues
  • apps/web/src/lib/autoTopUp.test.ts - 0 issues
  • apps/web/src/lib/autoTopUp.ts - 0 issues
  • apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.test.ts - 0 issues
  • apps/web/src/lib/contributor-champions/service.test.ts - 0 issues
  • apps/web/src/lib/contributor-champions/service.ts - 0 issues
  • apps/web/src/lib/creditExpiration.test.ts - 0 issues
  • apps/web/src/lib/creditExpirationOrg.test.ts - 0 issues
  • apps/web/src/lib/creditTransactions.ts - 0 issues
  • apps/web/src/lib/credits.test.ts - 0 issues
  • apps/web/src/lib/customerInfo.ts - 0 issues
  • apps/web/src/lib/kilo-pass/cancel-and-refund.ts - 0 issues
  • apps/web/src/lib/kilo-pass/scheduled-change-release.ts - 0 issues
  • apps/web/src/lib/kilo-pass/stripe-handlers-invoice-paid.test.ts - 0 issues
  • apps/web/src/lib/kilo-pass/stripe-handlers-invoice-paid.ts - 0 issues
  • apps/web/src/lib/kilo-pass/stripe-handlers-subscription-events.test.ts - 0 issues
  • apps/web/src/lib/kilo-pass/stripe-handlers-subscription-events.ts - 0 issues
  • apps/web/src/lib/kilo-pass/usage-triggered-bonus.test.ts - 0 issues
  • apps/web/src/lib/kilo-pass/usage-triggered-bonus.ts - 0 issues
  • apps/web/src/lib/kiloclaw/credit-billing.ts - 0 issues
  • apps/web/src/lib/organizations/organization-billing.test.ts - 0 issues
  • apps/web/src/lib/organizations/organizations.test.ts - 0 issues
  • apps/web/src/lib/organizations/organizations.ts - 0 issues
  • apps/web/src/lib/promoCustomerRequirement.ts - 0 issues
  • apps/web/src/lib/recomputeNextCreditExpiration.ts - 0 issues
  • apps/web/src/lib/recomputeOrganizationBalances.test.ts - 0 issues
  • apps/web/src/lib/recomputeOrganizationBalances.ts - 0 issues
  • apps/web/src/lib/recomputeUserBalances.test.ts - 0 issues
  • apps/web/src/lib/recomputeUserBalances.ts - 0 issues
  • apps/web/src/lib/referral.ts - 0 issues
  • apps/web/src/lib/stripe.ts - 0 issues
  • apps/web/src/lib/stytch.test.ts - 0 issues
  • apps/web/src/lib/stytch.ts - 0 issues
  • apps/web/src/lib/usageDeduction.test.ts - 0 issues
  • apps/web/src/lib/user.ts - 0 issues
  • apps/web/src/lib/web-session-revocation.test.ts - 0 issues
  • apps/web/src/routers/admin-app-builder-router.ts - 0 issues
  • apps/web/src/routers/admin-deployments-router.ts - 0 issues
  • apps/web/src/routers/admin-kiloclaw-instances-router.test.ts - 0 issues
  • apps/web/src/routers/admin-kiloclaw-user-router.test.ts - 0 issues
  • apps/web/src/routers/admin-router.ts - 0 issues
  • apps/web/src/routers/admin/custom-llm-router.ts - 0 issues
  • apps/web/src/routers/admin/kilo-pass-router.test.ts - 0 issues
  • apps/web/src/routers/code-reviews-router.test.ts - 0 issues
  • apps/web/src/routers/kilo-pass-router.test.ts - 0 issues
  • apps/web/src/routers/kilo-pass-router.ts - 0 issues
  • apps/web/src/routers/organizations/organization-admin-router.ts - 0 issues
  • apps/web/src/routers/organizations/organization-auto-top-up-router.test.ts - 0 issues
  • apps/web/src/routers/organizations/organization-auto-top-up-router.ts - 0 issues
  • apps/web/src/routers/organizations/organization-router.ts - 0 issues
  • apps/web/src/routers/user-router.test.ts - 0 issues
  • apps/web/src/routers/user-router.ts - 0 issues
  • apps/web/src/scripts/d2025-07-15_fix-failed-top-ups.ts - 0 issues
  • apps/web/src/scripts/d2025-07-26_replace-stripe-account-for-kilouser.ts - 0 issues
  • apps/web/src/scripts/d2025-08-22_grant-sonic-usage-compensation.ts - 0 issues
  • apps/web/src/scripts/d2025-09-01_backfill-referral-code-usages.ts - 0 issues
  • apps/web/src/scripts/d2025-10-07-backfill-github-welcome.ts - 0 issues
  • apps/web/src/scripts/d2025-11-24_autocomplete-rollout-2025-11.ts - 0 issues
  • apps/web/src/scripts/db/seed-fake-usage-for-org.ts - 0 issues
  • apps/web/src/tests/stripe.test.ts - 0 issues
  • dev/seed/kiloclaw-billing/inactive-trials.ts - 0 issues
  • oxlint-plugin-drizzle.js - 0 issues
  • package.json - 0 issues
  • packages/db/package.json - 0 issues
  • packages/db/src/client.ts - 0 issues
  • packages/drizzle-shims/package.json - 0 issues
  • packages/drizzle-shims/src/query-alias.ts - 0 issues
  • packages/drizzle-shims/tsconfig.json - 0 issues
  • pnpm-lock.yaml - 0 issues
  • scripts/drizzle-query-rename.ts - 1 issue
  • services/ai-attribution/package.json - 0 issues
  • services/ai-attribution/src/dos/AttributionTracker.do.ts - 0 issues
  • services/app-builder/package.json - 0 issues
  • services/app-builder/src/git-repository-do.ts - 0 issues
  • services/cloud-agent-next/package.json - 0 issues
  • services/cloud-agent-next/src/persistence/CloudAgentSession.ts - 0 issues
  • services/cloud-agent/package.json - 0 issues
  • services/cloud-agent/src/persistence/CloudAgentSession.ts - 0 issues
  • services/kilo-chat/package.json - 0 issues
  • services/kilo-chat/src/do/conversation-do.ts - 0 issues
  • services/kilo-chat/src/do/membership-do.ts - 0 issues
  • services/kilo-chat/src/do/sandbox-status-do.ts - 0 issues
  • services/kiloclaw/package.json - 0 issues
  • services/kiloclaw/src/durable-objects/kiloclaw-registry.ts - 0 issues
  • services/o11y/package.json - 0 issues
  • services/o11y/src/alerting/AlertConfigDO.ts - 0 issues
  • services/session-ingest/package.json - 0 issues
  • services/session-ingest/src/dos/SessionAccessCacheDO.ts - 0 issues
  • services/session-ingest/src/dos/SessionIngestDO.ts - 0 issues
  • services/webhook-agent-ingest/package.json - 0 issues
  • services/webhook-agent-ingest/src/dos/TriggerDO.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by gpt-5.5-2026-04-23 · 723,623 tokens

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