diff --git a/packages/coding-agent/README.md b/packages/coding-agent/README.md index 79184178..1858f9d1 100644 --- a/packages/coding-agent/README.md +++ b/packages/coding-agent/README.md @@ -1132,21 +1132,6 @@ import { getPackageDir, getThemeDir } from "./paths.js"; Never use `__dirname` directly for package assets. -### Module Resolution with tsx - -When running from source via `npx tsx src/cli.ts`, hooks loaded via jiti may get separate module instances from the main app. This can cause issues with global state (like the theme object). - -**Workaround**: Functions like `getSettingsListTheme()` accept an optional theme parameter. In hooks, pass the theme from `ctx.ui.custom()`: - -```typescript -await ctx.ui.custom((tui, theme, done) => { - const settingsTheme = getSettingsListTheme(theme); - // ... -}); -``` - -When running the built version (`node dist/cli.js` or installed via npm), this is not an issue. - ### Debug Command `/debug` (hidden) writes rendered lines with ANSI codes to `~/.pi/agent/pi-debug.log` for TUI debugging, as well as the last set of messages that were sent to the LLM. diff --git a/packages/coding-agent/examples/hooks/tools.ts b/packages/coding-agent/examples/hooks/tools.ts index 4ee3aa2b..77c57490 100644 --- a/packages/coding-agent/examples/hooks/tools.ts +++ b/packages/coding-agent/examples/hooks/tools.ts @@ -91,7 +91,7 @@ export default function toolsHook(pi: HookAPI) { const settingsList = new SettingsList( items, Math.min(items.length + 2, 15), - getSettingsListTheme(theme), + getSettingsListTheme(), (id, newValue) => { // Update enabled state and apply immediately if (newValue === "enabled") { diff --git a/packages/coding-agent/src/modes/interactive/theme/theme.ts b/packages/coding-agent/src/modes/interactive/theme/theme.ts index 461b507c..69b3db7a 100644 --- a/packages/coding-agent/src/modes/interactive/theme/theme.ts +++ b/packages/coding-agent/src/modes/interactive/theme/theme.ts @@ -946,14 +946,13 @@ export function getMarkdownTheme(): MarkdownTheme { }; } -export function getSelectListTheme(themeOverride?: Theme): SelectListTheme { - const t = themeOverride ?? theme; +export function getSelectListTheme(): SelectListTheme { return { - selectedPrefix: (text: string) => t.fg("accent", text), - selectedText: (text: string) => t.fg("accent", text), - description: (text: string) => t.fg("muted", text), - scrollInfo: (text: string) => t.fg("muted", text), - noMatch: (text: string) => t.fg("muted", text), + selectedPrefix: (text: string) => theme.fg("accent", text), + selectedText: (text: string) => theme.fg("accent", text), + description: (text: string) => theme.fg("muted", text), + scrollInfo: (text: string) => theme.fg("muted", text), + noMatch: (text: string) => theme.fg("muted", text), }; } @@ -964,13 +963,12 @@ export function getEditorTheme(): EditorTheme { }; } -export function getSettingsListTheme(themeOverride?: Theme): import("@mariozechner/pi-tui").SettingsListTheme { - const t = themeOverride ?? theme; +export function getSettingsListTheme(): import("@mariozechner/pi-tui").SettingsListTheme { return { - label: (text: string, selected: boolean) => (selected ? t.fg("accent", text) : text), - value: (text: string, selected: boolean) => (selected ? t.fg("accent", text) : t.fg("muted", text)), - description: (text: string) => t.fg("dim", text), - cursor: t.fg("accent", "→ "), - hint: (text: string) => t.fg("dim", text), + label: (text: string, selected: boolean) => (selected ? theme.fg("accent", text) : text), + value: (text: string, selected: boolean) => (selected ? theme.fg("accent", text) : theme.fg("muted", text)), + description: (text: string) => theme.fg("dim", text), + cursor: theme.fg("accent", "→ "), + hint: (text: string) => theme.fg("dim", text), }; }