Skip to content

refactor: route console.log calls in domain/search through logger#1870

Open
carlos-alm wants to merge 1 commit into
fix/issue-1753-points-to-max-iterationsfrom
fix/issue-1754-domain-search-console-log
Open

refactor: route console.log calls in domain/search through logger#1870
carlos-alm wants to merge 1 commit into
fix/issue-1753-points-to-max-iterationsfrom
fix/issue-1754-domain-search-console-log

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • generator.ts (3 progress messages) and semantic.ts (dimension-mismatch warning) called console.log directly, violating this repo's domain→infrastructure logging convention. Routed through logger.info/logger.warn respectively — confirmed logger.info() writes unconditionally (not gated behind verbose), so no visibility regression.
  • cli-formatter.ts moved to src/presentation/search.ts (93%-similarity rename, mechanical — 2 call-site import updates + 1 test import). It's genuinely the CLI-output/--json rendering layer for codegraph search, matching the established presentation/queries-cli/ pattern; verified no actual precedent exists for presentation-ish files living under src/domain/ before ruling out leaving it in place.

Closes #1754

Test plan

  • npm test — full suite green (3513 passed, 0 failed)
  • npm run lint / npm run typecheck — clean
  • Manual end-to-end: real codegraph embed run confirms all 3 progress messages print correctly; forced a dimension-mismatch to confirm the warning renders; ran codegraph search to confirm the moved presentation module renders identical output

Filed #1869 for an out-of-scope finding discovered during manual verification: findDbPath (via embed's default DB resolution) ignores the positional dir argument, unlike build.

Stacked on #1868 (base branch fix/issue-1753-points-to-max-iterations) — only the search/presentation/test diff is this issue's change.

generator.ts's embedding-progress messages now go through logger.info()
(unconditionally visible, matches the info()-based "Reusing previously-
stored embedding model" message already used in cli/commands/embed.ts)
instead of console.log/stdout. semantic.ts's dimension-mismatch message
is a genuine warning (same severity class as the file's existing
warnOnSimilarQueries), so both of its console.log lines are merged into
a single warn() call, following the fix already applied to prepare.ts.

cli-formatter.ts is the actual data-output layer for `codegraph search`
(including the --json contract), directly analogous to
presentation/queries-cli/ — CLI display wrappers for query functions
that already live in presentation/ and call console.log directly. No
other domain/ file has precedent for presentation code living there, so
it moves to presentation/search.ts rather than being kept as a
domain-layer exception. Only two import sites needed updating
(cli/commands/search.ts, the domain/search/index.ts barrel) plus one
test import.

docs check acknowledged: internal logging-layer refactor + file move,
no new feature/language/CLI/architecture surface — README.md, CLAUDE.md,
and ROADMAP.md do not need updates.

Fixes #1754

Impact: 2 functions changed, 9 affected
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR routes console.log calls in the domain/search layer through the structured logger module and moves cli-formatter.ts to src/presentation/search.ts to better reflect its role as a presentation-layer concern.

  • generator.ts: Three progress messages switched from console.log (stdout) to logger.info (stderr), which is the correct stream for diagnostic output in CLI tools.
  • semantic.ts: Two console.log lines for the dimension-mismatch warning collapsed into a single logger.warn call with improved message text.
  • src/domain/search/search/cli-formatter.ts renamed to src/presentation/search.ts with updated relative import paths; two call-site imports and one test import updated accordingly.

Confidence Score: 4/5

Safe to merge — the changes are mechanical routing of console.log through the structured logger and a file rename with updated import paths.

All three embed progress messages and the dimension-mismatch warning are now on stderr via the logger, which is correct for a CLI tool. The only notable side effect is the dropped leading newline before the "Stored embeddings" message, causing slightly different visual spacing in terminal output. Everything else is a clean rename with two call-site and one test import updated.

src/domain/search/generator.ts — the dropped
before the final progress message is the only item worth a second look.

Important Files Changed

Filename Overview
src/domain/search/generator.ts Three console.log progress messages replaced with logger.info; leading \n stripped from the "Stored embeddings" message as a side effect of the migration.
src/domain/search/search/semantic.ts Two console.log lines for dimension-mismatch warning consolidated into a single logger.warn call with improved guidance text; clean change.
src/presentation/search.ts Renamed from src/domain/search/search/cli-formatter.ts; import paths updated to reflect new location; console.log retained correctly for stdout CLI output in the presentation layer.
src/domain/search/index.ts Removed re-export of search from old cli-formatter location; no other public-API exports changed.
src/cli/commands/search.ts Import source updated from domain/search/index.js to presentation/search.js; mechanical one-line change.
tests/search/embedder-search.test.ts search import updated to new presentation/search.js path; no logic changes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    CLI["src/cli/commands/search.ts"] -->|imports search| PRES["src/presentation/search.ts\n(was: domain/search/search/cli-formatter.ts)"]
    PRES -->|imports searchData / multiSearchData| SEM["src/domain/search/search/semantic.ts"]
    PRES -->|imports ftsSearchData| KW["src/domain/search/search/keyword.ts"]
    PRES -->|imports hybridSearchData| HYB["src/domain/search/search/hybrid.ts"]
    PRES -->|imports warn| LOG["src/infrastructure/logger.ts"]
    SEM -->|imports warn| LOG
    GEN["src/domain/search/generator.ts\nbuildEmbeddings"] -->|imports info / warn| LOG
    LOG -->|info / warn / error| STDERR["process.stderr"]
    PRES -->|console.log for CLI output| STDOUT["process.stdout"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    CLI["src/cli/commands/search.ts"] -->|imports search| PRES["src/presentation/search.ts\n(was: domain/search/search/cli-formatter.ts)"]
    PRES -->|imports searchData / multiSearchData| SEM["src/domain/search/search/semantic.ts"]
    PRES -->|imports ftsSearchData| KW["src/domain/search/search/keyword.ts"]
    PRES -->|imports hybridSearchData| HYB["src/domain/search/search/hybrid.ts"]
    PRES -->|imports warn| LOG["src/infrastructure/logger.ts"]
    SEM -->|imports warn| LOG
    GEN["src/domain/search/generator.ts\nbuildEmbeddings"] -->|imports info / warn| LOG
    LOG -->|info / warn / error| STDERR["process.stderr"]
    PRES -->|console.log for CLI output| STDOUT["process.stdout"]
Loading

Fix All in Claude Code

Reviews (1): Last reviewed commit: "refactor: route console.log calls in dom..." | Re-trigger Greptile

Comment on lines +292 to 294
info(
`Stored ${vectors.length} embeddings (${dim}d, ${displayName}, strategy: ${strategy}) in graph.db`,
);

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.

P2 The leading that separated this final progress line from the previous output was dropped during the migration. The original console.log(' Stored ...') printed a blank line before the message; the new info(...) call omits it, so the three embed-progress lines now run together visually without the spacing the old output had.

Suggested change
info(
`Stored ${vectors.length} embeddings (${dim}d, ${displayName}, strategy: ${strategy}) in graph.db`,
);
info(
`\nStored ${vectors.length} embeddings (${dim}d, ${displayName}, strategy: ${strategy}) in graph.db`,
);

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

2 functions changed9 callers affected across 5 files

  • buildEmbeddings in src/domain/search/generator.ts:222 (1 transitive callers)
  • checkDimensionMismatch in src/domain/search/search/semantic.ts:73 (8 transitive callers)

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