Single export:resolveDbPath(): string -- the only function in the entire src/shared/ directory.
Imports: Only existsSync from node:fs (Node built-in).
Priority chain: (1) NBA_DUCKDB_PATH env var, (2) CI fixture if CI=true or GITHUB_ACTIONS=true AND the fixture file exists on disk, (3) default data/nba.duckdb.
Environment variable access: Uses bracket notation (process.env['NBA_DUCKDB_PATH']) per the strict chatbot typecheck rules (noPropertyAccessFromIndexSignature).
Constants:DEFAULT_DB_PATH and CI_FIXTURE_PATH are module-scoped const (SCREAMING_SNAKE_CASE).
This is the sole shared module between hub and chatbot packages.
2. src/shared/ Directory Listing
Full path:C:\Users\nicolas\Documents\GitHub\bballgenius\src\shared\
File
Description
dbPath.ts
The only file in the directory
The src/shared/ directory contains exactly one file: dbPath.ts. There are no other shared modules, types, or utilities. This confirms the architectural boundary described in AGENTS.md -- hub and chatbot share only the DB path resolver.
3. src/hub/shared/utils/formatters.ts
Full path:C:\Users\nicolas\Documents\GitHub\bballgenius\src\hub\shared\utils\formatters.tsLine count: 465 lines
Imports / Dependencies
typescript
import { createTextAttributes, parseColor, StyledText, type TextChunk } from '@opentui/core';
import type { TableDataRow } from '../../core/types.js';
import { ansiBrightGreen, ansiBrightRed, ansiGreen, ansiRed, isNoColor } from './theme.js';
Accepts both arrays-of-arrays and arrays-of-objects as rows (polymorphic via TableDataRow type).
colKeys option maps object keys to column positions; defaults to headers themselves.
maxRows truncates output to a maximum number of data rows.
Auto-alignment: Columns are right-aligned if more than half the values are numeric; otherwise left-aligned. Explicit alignments override auto-detection.
Unicode box-drawing: Uses ┌─┬┐, │, ├─┼┤, └─┴┘ characters for borders.
Column widths: Computed as max(header.length, max_data_value_length) per column.
Returns string[] (array of lines, one per visual row including borders).
export function ansiToStyledText(text: string): StyledText
Key behaviors:
Parses ANSI SGR escape sequences via regex /\x1b\[([0-9;]*)m/g.
Tracks state across escape sequences: currentFg, currentBg, isBold, isDim, isItalic, isUnderline.
Full SGR support:
Reset (0), bold (1), dim (2), italic (3), underline (4)
Selective resets: bold/dim off (22), italic off (23), underline off (24)
Default fg/bg reset: 39, 49
Standard 8 foreground colors (30-37) and 8 background colors (40-47)
Bright 8 foreground colors (90-97) and 8 background colors (100-107)
24-bit RGB:38;2;r;g;b (foreground) and 48;2;r;g;b (background)
256-color:38;5;index (foreground) and 48;5;index (background)
Uses a colorMap record (lines 287-320) mapping SGR codes to OpenTUI color names.
Produces TextChunk[] and wraps in new StyledText(chunks).
Private helper colorToParseable (lines 423-433):
Converts rgb(r,g,b) strings to #rrggbb hex for OpenTUI's parseColor.
Falls back to #888888 for ansi256:N tokens (approximation).
Passes through named colors unchanged.
Private helper createChunk (lines 435-465):
Builds a TextChunk object with __isChunk: true, text, optional fg/bg (via parseColor), and optional attributes (via createTextAttributes).
Notable Patterns
ANSI-at-the-boundary pattern: Tabs produce raw ANSI strings; this function converts to OpenTUI's StyledText before rendering, keeping layout calculations clean.
No color degradation: The hub version is significantly richer than the chatbot version (see comparison below).
stripAnsi is a simple regex replacement, separate from the StyledText conversion.
4. src/chatbot/utils/ansi.ts
Full path:C:\Users\nicolas\Documents\GitHub\bballgenius\src\chatbot\utils\ansi.tsLine count: 87 lines
Imports / Dependencies
typescript
import { createTextAttributes, parseColor, StyledText, type TextChunk } from '@opentui/core';
Only @opentui/core -- no hub imports, no theme imports.
export function ansiToStyledText(text: string): StyledText
Key behaviors:
Parses ANSI SGR via /\x1b\[([0-9;]*)m/g (same regex pattern as hub).
Tracks only 3 state variables: currentFg, isBold, isDim.
Limited SGR support:
Reset (0), bold (1), dim (2), bold/dim off (22)
Only 6 foreground colors: blue (34), green (32), red (31), cyan (36), white (37), brightBlack (90)
No background color support at all.
No italic or underline support.
No 24-bit RGB or 256-color support.
Uses hardcoded if/else if chain instead of a color map lookup.
getStyle helper returns a plain object (no bg field).
Comparison: Hub vs Chatbot ansiToStyledText
Feature
Hub (formatters.ts)
Chatbot (ansi.ts)
State variables
6 (fg, bg, bold, dim, italic, underline)
3 (fg, bold, dim)
Background colors
Full (40-47, 100-107)
None
Italic / underline
Yes
No
24-bit RGB (38;2;r;g;b)
Yes
No
256-color (38;5;index)
Yes
No
Color map approach
Record lookup table
Hardcoded if/else
colorToParseable helper
Yes (rgb->hex, ansi256->grey)
No
stripAnsi companion
Yes
No
Line count
~148 lines (273-420) + 43 helper lines
87 lines total
The chatbot version is a minimal subset -- it handles only the ANSI codes the chatbot's own output is likely to produce. The hub version is a comprehensive ANSI parser.
5. src/chatbot/utils/tableFormatter.ts
Full path:C:\Users\nicolas\Documents\GitHub\bballgenius\src\chatbot\utils\tableFormatter.tsLine count: 45 lines
Imports / Dependencies
None. This file has zero imports -- it is entirely self-contained.
export function formatResultsTable(results: Record<string, unknown>[]): string
Key behaviors:
Input: Array of row objects (Record<string, unknown>[]). Only accepts objects, not arrays-of-arrays.
Empty result: Returns 'Query returned no results.' string.
Row cap: Hardcoded to first 20 rows (results.slice(0, 20)). If truncated, prepends a line "Rows: N (showing first 20)".
Column extraction: Derives headers from Object.keys(results[0]!) -- uses the first row's keys.
Null/undefined handling: Converts to empty string.
Auto-alignment: Columns where every non-empty value is numeric get right-aligned (padStart); others get left-aligned (padEnd). This is stricter than the hub's "majority" heuristic (the chatbot requires 100% numeric, the hub requires >50%).
Unicode box-drawing: Same character set as hub (┌─┬┐│├─┼┤└─┴┘).
Returns string (single joined string with \n), unlike hub's formatTable which returns string[].
Non-null assertions: Uses ! operator on indexed access (results[0]!, colWidths[i]!, r[i]!) -- required by noUncheckedIndexedAccess in chatbot's strict tsconfig.
Comparison: Hub formatTable vs Chatbot formatResultsTable
Feature
Hub (formatters.ts)
Chatbot (tableFormatter.ts)
Return type
string[] (array of lines)
string (newline-joined)
Input types
Arrays + objects (TableDataRow[])
Objects only (Record<string, unknown>[])
Row limit
Configurable via options.maxRows
Hardcoded 20
Alignment heuristic
>50% numeric = right
100% numeric = right
Custom alignments
Supported via options
Not supported
Column key mapping
Supported via colKeys
Not supported (uses Object.keys)
Imports
3 imports
0 imports
Line count
113 lines
45 lines
Summary of Cross-Cutting Observations
src/shared/ is minimal by design -- a single file (dbPath.ts, 18 lines) that is the only module shared between hub and chatbot.
Duplicated ansiToStyledText -- The function exists in two places with significantly different capability levels. The hub version (465-line file, ~148 lines for the function) is a full ANSI parser; the chatbot version (87-line file) is a minimal subset. This is a clear candidate for extraction into src/shared/ if consolidation is desired.
Duplicated table formatting -- formatTable (hub) and formatResultsTable (chatbot) produce visually identical Unicode box-drawing tables but differ in API surface (return type, input types, configurability). The chatbot version is zero-dependency and simpler.
Consistent conventions across all files:
.js extensions on relative imports (where present)
Bracket notation for process.env access
const preference throughout
export function declarations (not arrow functions)
Unicode box-drawing characters for table borders
OpenTUI StyledText/TextChunk for ANSI-to-renderable conversion