Skip to content

feat(query): query doctor readiness probe + Hermes-aware install script (Phase 1)#5

Merged
alexskatell merged 2 commits into
mainfrom
feat/query-doctor
May 13, 2026
Merged

feat(query): query doctor readiness probe + Hermes-aware install script (Phase 1)#5
alexskatell merged 2 commits into
mainfrom
feat/query-doctor

Conversation

@alexskatell
Copy link
Copy Markdown
Contributor

Summary

Phase 1 of the SQL-first retrieval plan (docs/plans/2026-05-13-sql-first-retrieval-improvements.md, committed in this PR). Two strictly additive changes — no behavior change to existing commands.

1. topline query doctor — SQL readiness probe

One command, JSON output, agents run it before deciding SQL vs REST.

topline --agent query doctor

Reports:

  • queryTokenPresent (looks at TOPLINE_QUERY_TOKENTOPLINE_MCP_ACCESS_TOKENTOPLINE_MCP_TOKEN)
  • tokenSourceEnvVar (which env key was actually used)
  • rawPitRejected (true when the token still starts with pit-)
  • baseUrl
  • schemaReachable (calls /query/api/get-overview if the token looks valid)
  • tableCount
  • expectedTables — presence of contacts, opportunities, messages, pipelines, pipeline_stages, call_events, appointments, conversations
  • missingTables
  • recommendation — human-readable next step

Never prints the token value. Missing tables surface as an os-mcp coverage bug, not a reason to silently fall back to REST — matches the v1.2.0 / v2.2.0 skill contract from #4.

2. scripts/install-local.sh — Hermes-aware installer

Idempotent. Builds ~/.local/bin/topline-bin and writes a wrapper at ~/.local/bin/topline that loads only the TOPLINE_* env keys needed by REST and SQL commands (TOPLINE_PIT, TOPLINE_LOCATION_ID, TOPLINE_BRAND_NAME, TOPLINE_BASE_URL, TOPLINE_QUERY_TOKEN, TOPLINE_QUERY_BASE_URL, TOPLINE_MCP_ACCESS_TOKEN, TOPLINE_MCP_TOKEN). No secrets are printed or persisted — only the env-var keys are written into the wrapper.

Fixes the local wrapper drift problem from this week: anyone installing os-cli now gets the SQL allowlist for free.

3. Plan doc committed

docs/plans/2026-05-13-sql-first-retrieval-improvements.md records Phase 0–6 so downstream contributors can pick up Phase 2 (query template registry), Phase 3 (sales-native report commands like activity rollup), Phase 4 (agent-shaped answer packets), and Phase D (os-mcp freshness metadata).

Test plan

  • go test ./... — all packages pass, including 4 new query doctor tests
  • go build ./... — clean
  • Install script smoke-tested in $(mktemp -d) — builds binary, writes valid wrapper, bash -n syntax-checks clean
  • No secrets touched; doctor output PII-safe under --agent

Alex Skatell added 2 commits May 13, 2026 11:01
…l script

Phase 1 of the SQL-first retrieval plan. Two additions, both strictly additive:

1. `topline query doctor` — JSON readiness report agents run before deciding SQL
   vs REST. Reports: queryTokenPresent (via TOPLINE_QUERY_TOKEN /
   TOPLINE_MCP_ACCESS_TOKEN / TOPLINE_MCP_TOKEN), rawPitRejected, baseUrl,
   schemaReachable, tableCount, expectedTables (contacts, opportunities,
   messages, pipelines, pipeline_stages, call_events, appointments,
   conversations), missingTables, and a recommendation string. Missing tables
   are surfaced as an os-mcp coverage bug, not a reason to silently fall back
   to REST. Never prints the token value.

2. `scripts/install-local.sh` — idempotent installer that builds
   ~/.local/bin/topline-bin and writes a Hermes-friendly wrapper at
   ~/.local/bin/topline. The wrapper allowlist now includes TOPLINE_QUERY_TOKEN,
   TOPLINE_QUERY_BASE_URL, TOPLINE_MCP_ACCESS_TOKEN, and TOPLINE_MCP_TOKEN, so a
   fresh install just works for the SQL surface. No secrets are printed or
   written by the script — only the env-var keys.

Implementation:
- internal/topline/query_client.go: add InspectQueryEnv() that reports
  TokenPresent / RawPITToken without erroring, and refactor LoadQueryConfig to
  reuse it. Existing error messages and behavior unchanged for callers that
  hard-fail on missing token.
- internal/commands/query.go: register `doctor` subcommand and the
  queryDoctorReport JSON shape.
- internal/commands/query_test.go: four new tests covering missing token, raw
  PIT rejection, full table presence (recommendation = ready), and missing
  expected tables (recommendation = coverage gap).
- README.md / docs/examples.md: document the new command and install script.

go test ./... passes. Existing query commands and the SQL-first skill contract
(PR #4) are unchanged.
Records the full Phase 0-6 plan so contributors and downstream agents can pick
up tasks. Phase 1 (`query doctor` + install script) lands in this PR; later
phases (query template registry, sales-native report commands, os-mcp freshness
metadata) reference this doc.

No code change in this commit — plan only.
@alexskatell alexskatell merged commit 9138857 into main May 13, 2026
1 check passed
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