refactor(query): extract command catalog seam for registry wiring (#3060)

* refactor(sdk): extract gsdtools transport seam with per-command policy

* refactor(query): centralize registry command catalog wiring

* refactor(query): unify command resolution seam across sdk callers

* fix(sdk): address CodeRabbit transport policy and timeout findings

* refactor(query): extract mutation event mapper seam

* refactor(query): converge mutation and transport policy data

* refactor(query): share fallback orchestration across cli and sdk

* refactor(query): split static registry catalog by domain clusters

* refactor(query): extract mutation event emission decorator seam

* refactor(query): extract alias-family handler catalog module

* refactor(query): extract cjs fallback execution adapter

* refactor(query): deepen command semantics seam

* refactor(query): extract deep dispatch seam

* refactor(query): deepen cjs fallback execution seam

* refactor(query): merge routing plan into dispatch seam

* fix(query): address CodeRabbit review findings on PR #3060

Critical: prevent double-execution race by checking timeout errors
before subprocess fallback (gsd-transport.ts).

Major: fix execRaw() to respect transport policy outputMode instead
of hardcoding 'raw' (gsd-tools.ts).

Major: add explicit 30s timeout to subprocess fallback execution
(query-fallback-executor.ts).

Major: remove raw args from stderr banner to prevent secret leakage
(query-fallback-executor.ts).

Minor: ensure native text output has trailing newline for CLI parity
(query-dispatch.ts).

Update gsd-tools.test.ts to match new execRaw() behavior.

* fix(tests): update CLI integration tests for catalog-based registration

The refactoring moved handler registration from inline registry.register()
calls to catalog-based registration (registerStaticCatalog/registerAliasCatalog).

- gsd-sdk-query-registry-integration.test.cjs: collectRegisteredNames() now
  also scans catalog files for handler names registered via the new system.
- bug-2492-context-coverage-gate.test.cjs: checks for catalog-based
  registration (DECISION_ROUTING_STATIC_CATALOG) instead of inline strings.
- bug-2524-sdk-query-ws-flag.test.cjs: checks for dispatchNative callback
  pattern instead of direct registry.dispatch() call.

* fix(query): address remaining CodeRabbit review findings

- query-command-semantics.ts: guard stats/progress rewrite so option
  tokens (e.g. --pick) are not turned into subcommands, preserving the
  top-level handler dispatch.

- query-dispatch.ts: formatOutput now skips --pick for text-format
  responses (matching CJS fallback behavior) and surfaces a proper error
  when extractField returns undefined instead of silently producing
  'undefined'.

- query-dispatch.ts: fix backwards error message — 'registered' is the
  restrictive policy that disables fallback, not enables it.

- tests/bug-2492-context-coverage-gate.test.cjs: check
  VERIFY_DECISION_STATIC_CATALOG (the correct catalog for plan-gate
  handlers) instead of DECISION_ROUTING_STATIC_CATALOG.

- tests/gsd-sdk-query-registry-integration.test.cjs: resolve catalog
  variable before loading entries so the drift guard checks each
  referenced catalog individually.

* refactor(query): deepen registry assembly module with strict invariants

- extract registry assembly into dedicated module
- split build vs mutation decoration internals
- add strict assembly invariants:
  1) no duplicate keys
  2) alias canonicals must have handlers
  3) mutation commands must be registered
  4) raw-output policy commands must be registered
- slim query index to thin re-export seam
- add focused registry assembly tests
- update drift-guard tests to target new seam

* test(query): add thin-seam coverage for query index re-exports

* fix(query): return structured native dispatch errors + tighten decisions.parse guard

- runQueryDispatch native path now catches adapter errors and returns
  QueryDispatchResult.error instead of throwing.
- preserve legacy CLI exit contract by using code=1 for native dispatch
  failures.
- strengthen bug-2492 guard: decisions.parse assertion now checks
  VERIFY_DECISION_STATIC_CATALOG OR explicit command token.
This commit is contained in:
Tom Boucher
2026-05-03 13:57:32 -04:00
committed by GitHub
parent 0f98952a3d
commit 5975f06b6a
42 changed files with 1773 additions and 948 deletions

View File

@@ -0,0 +1,106 @@
import type { QueryHandler } from './utils.js';
import { agentSkills } from './skills.js';
import { requirementsMarkComplete } from './roadmap.js';
import { todoMatchPhase, statsJson, statsTable, progressBar, progressTable, listTodos, todoComplete } from './progress.js';
import { milestoneComplete } from './phase-lifecycle.js';
import { summaryExtract, historyDigest } from './summary.js';
import { commitToSubrepo } from './commit.js';
import { workstreamGet, workstreamList, workstreamCreate, workstreamSet, workstreamStatus, workstreamComplete, workstreamProgress } from './workstream.js';
import { docsInit } from './docs-init.js';
import { websearch } from './websearch.js';
import { learningsCopy, learningsQuery, learningsListHandler, learningsPrune, learningsDelete, extractMessages, scanSessions, profileSample, profileQuestionnaire } from './profile.js';
import { skillManifest } from './skill-manifest.js';
import { auditOpen } from './audit-open.js';
import { detectCustomFiles } from './detect-custom-files.js';
import { uatRenderCheckpoint, auditUat } from './uat.js';
import { intelStatus, intelDiff, intelSnapshot, intelValidate, intelQuery, intelExtractExports, intelPatchMeta, intelUpdate } from './intel.js';
import { writeProfile, generateClaudeProfile, generateDevPreferences, generateClaudeMd } from './profile-output.js';
export const DOMAIN_STATIC_CATALOG: ReadonlyArray<readonly [string, QueryHandler]> = [
['agent-skills', agentSkills],
['requirements.mark-complete', requirementsMarkComplete],
['requirements mark-complete', requirementsMarkComplete],
['todo.match-phase', todoMatchPhase],
['todo match-phase', todoMatchPhase],
['list-todos', listTodos],
['list.todos', listTodos],
['todo.complete', todoComplete],
['todo complete', todoComplete],
['milestone.complete', milestoneComplete],
['milestone complete', milestoneComplete],
['summary.extract', summaryExtract],
['summary extract', summaryExtract],
['summary-extract', summaryExtract],
['history.digest', historyDigest],
['history digest', historyDigest],
['history-digest', historyDigest],
['stats', statsJson],
['stats.json', statsJson],
['stats json', statsJson],
['stats.table', statsTable],
['stats table', statsTable],
['commit-to-subrepo', commitToSubrepo],
['progress.bar', progressBar],
['progress bar', progressBar],
['progress.table', progressTable],
['progress table', progressTable],
['workstream.get', workstreamGet],
['workstream get', workstreamGet],
['workstream.list', workstreamList],
['workstream list', workstreamList],
['workstream.create', workstreamCreate],
['workstream create', workstreamCreate],
['workstream.set', workstreamSet],
['workstream set', workstreamSet],
['workstream.status', workstreamStatus],
['workstream status', workstreamStatus],
['workstream.complete', workstreamComplete],
['workstream complete', workstreamComplete],
['workstream.progress', workstreamProgress],
['workstream progress', workstreamProgress],
['docs-init', docsInit],
['websearch', websearch],
['learnings.copy', learningsCopy],
['learnings copy', learningsCopy],
['learnings.query', learningsQuery],
['learnings query', learningsQuery],
['learnings.list', learningsListHandler],
['learnings list', learningsListHandler],
['learnings.prune', learningsPrune],
['learnings prune', learningsPrune],
['learnings.delete', learningsDelete],
['learnings delete', learningsDelete],
['skill-manifest', skillManifest],
['skill manifest', skillManifest],
['audit-open', auditOpen],
['audit open', auditOpen],
['detect-custom-files', detectCustomFiles],
['extract-messages', extractMessages],
['extract.messages', extractMessages],
['audit-uat', auditUat],
['uat.render-checkpoint', uatRenderCheckpoint],
['uat render-checkpoint', uatRenderCheckpoint],
['intel.diff', intelDiff],
['intel diff', intelDiff],
['intel.snapshot', intelSnapshot],
['intel snapshot', intelSnapshot],
['intel.validate', intelValidate],
['intel validate', intelValidate],
['intel.status', intelStatus],
['intel status', intelStatus],
['intel.query', intelQuery],
['intel query', intelQuery],
['intel.extract-exports', intelExtractExports],
['intel extract-exports', intelExtractExports],
['intel.patch-meta', intelPatchMeta],
['intel patch-meta', intelPatchMeta],
['intel.update', intelUpdate],
['intel update', intelUpdate],
['generate-claude-profile', generateClaudeProfile],
['generate-dev-preferences', generateDevPreferences],
['write-profile', writeProfile],
['profile-questionnaire', profileQuestionnaire],
['profile-sample', profileSample],
['scan-sessions', scanSessions],
['generate-claude-md', generateClaudeMd],
] as const;