Skip to content

refactor: centralize KB_ROOT import across 39 scripts#6

Merged
gorajing merged 1 commit into
mainfrom
refactor/kb-root-centralization
May 28, 2026
Merged

refactor: centralize KB_ROOT import across 39 scripts#6
gorajing merged 1 commit into
mainfrom
refactor/kb-root-centralization

Conversation

@gorajing
Copy link
Copy Markdown
Owner

Summary

Each script used to declare its own const KB_ROOT = join(__dirname, ...). Now they all import { KB_ROOT } from "./lib/kb-root" — the single source of truth that landed on main with the gate PR. Side benefit: the ZUHN_KB_ROOT env override now applies uniformly to every entry point.

Purely mechanical: 39 files × ±2 lines, no behavior change. The full suite has been green with these imports applied in the working tree all session — this PR just commits them.

Scope

  • 39 scripts: the import swap, nothing else.
  • Excluded (will land in a separate ingest-improvements PR):
    • scripts/ingest.ts (+ paste handler wiring)
    • scripts/lib/ingest/audio.ts (Whisper env-config; fixes the Korean-audio hallucination bug)
    • scripts/lib/ingest/detect.ts + detect.test.ts (paste-type detection)
      These 4 have substantive non-refactor changes and belong with the untracked paste.ts / paste.test.ts as their own coherent unit.

Test plan

  • full suite green (was 578 passed locally with these imports applied)
  • typecheck clean
  • CI

🤖 Generated with Claude Code

Each script previously declared its own `const KB_ROOT = join(__dirname, "../knowledge-base")`
(or a project-root variant). With `scripts/lib/kb-root.ts` already on main
(landed in the gate PR), each of these scripts can simply
`import { KB_ROOT } from "./lib/kb-root"` — one source of truth, and the
ZUHN_KB_ROOT env override now applies to every entry point uniformly.

Purely mechanical: 39 files × ±2 lines, no behavior change. The full test
suite has been passing with these imports applied in the working tree all
session (the imports were ALREADY being exercised — this just commits them).

Excluded from this PR (will land separately as ingest-improvements):
  - scripts/ingest.ts          (also wires the paste handler)
  - scripts/lib/ingest/audio.ts (Whisper env-config / Korean-audio fix)
  - scripts/lib/ingest/detect.ts + detect.test.ts (paste-type detection)
These four have substantive non-refactor changes belonging in a separate PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gorajing gorajing merged commit cc66ba1 into main May 28, 2026
1 check passed
gorajing added a commit that referenced this pull request May 28, 2026
Three coherent, long-pending ingest improvements that grew from the original
session work, plus the matching tests.

- lib/ingest/paste.ts (+ paste.test.ts) — ingest a local plain-text/markdown
  file as a "paste" source. Mirrors the pdf.ts pattern: copy the raw, derive
  the title from the first H1 or filename, write a "paste" source file via
  generateSourceId/slugify. No `url` field (paste sources have no scrapeable
  origin; gray-matter can't serialize undefined).
- lib/ingest/detect.ts (+ detect.test.ts) — detect local text/markdown files
  as type "paste" so `npm run ingest <file.txt>` routes through the new
  paste handler instead of erroring out.
- ingest.ts — wire the paste handler into the dispatch.
- lib/ingest/audio.ts — Whisper invocation is now ENV-CONFIGURABLE
  (ZUHN_WHISPER_MODEL, ZUHN_WHISPER_TASK, ZUHN_WHISPER_LANGUAGE) and
  auto-detects language by default. Fixes a real bug: the previous hardcoded
  `--model base --language en` confabulated on non-English audio (forcing
  English on the weakest model produced fluent hallucination + repetition
  loops on Korean audio).

Carries the KB_ROOT-import refactor for these 4 files; the same refactor
across the OTHER 39 scripts is in PR #6 — splitting because these 4 also
have substantive non-refactor changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gorajing gorajing deleted the refactor/kb-root-centralization branch May 28, 2026 06:38
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