Reorganize file structure: core/, utils/, modes/interactive/components/, modes/interactive/theme/

This commit is contained in:
Mario Zechner 2025-12-09 00:51:33 +01:00
parent 00982705f2
commit 83a6c26969
56 changed files with 133 additions and 128 deletions

View file

@ -15,15 +15,15 @@
import type { Agent, AgentEvent, AgentState, AppMessage, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core";
import type { AssistantMessage, Model } from "@mariozechner/pi-ai";
import { calculateContextTokens, compact, shouldCompact } from "../compaction.js";
import { getModelsPath } from "../config.js";
import { exportSessionToHtml } from "../export-html.js";
import type { BashExecutionMessage } from "../messages.js";
import { getApiKeyForModel, getAvailableModels } from "../model-config.js";
import { loadSessionFromEntries, type SessionManager } from "../session-manager.js";
import type { SettingsManager } from "../settings-manager.js";
import { expandSlashCommand, type FileSlashCommand } from "../slash-commands.js";
import { getModelsPath } from "../utils/config.js";
import { type BashResult, executeBash as executeBashCommand } from "./bash-executor.js";
import { calculateContextTokens, compact, shouldCompact } from "./compaction.js";
import { exportSessionToHtml } from "./export-html.js";
import type { BashExecutionMessage } from "./messages.js";
import { getApiKeyForModel, getAvailableModels } from "./model-config.js";
import { loadSessionFromEntries, type SessionManager } from "./session-manager.js";
import type { SettingsManager } from "./settings-manager.js";
import { expandSlashCommand, type FileSlashCommand } from "./slash-commands.js";
/** Listener function for agent events */
export type AgentEventListener = (event: AgentEvent) => void;

View file

@ -12,8 +12,8 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { type ChildProcess, spawn } from "child_process";
import stripAnsi from "strip-ansi";
import { getShellConfig, killProcessTree, sanitizeBinaryOutput } from "../shell.js";
import { DEFAULT_MAX_BYTES, truncateTail } from "../tools/truncate.js";
import { getShellConfig, killProcessTree, sanitizeBinaryOutput } from "../utils/shell.js";
import { DEFAULT_MAX_BYTES, truncateTail } from "./tools/truncate.js";
// ============================================================================
// Types

View file

@ -3,7 +3,7 @@ import type { AssistantMessage, Message, ToolResultMessage, UserMessage } from "
import { existsSync, readFileSync, writeFileSync } from "fs";
import { homedir } from "os";
import { basename } from "path";
import { APP_NAME, VERSION } from "./config.js";
import { APP_NAME, VERSION } from "../utils/config.js";
import { type BashExecutionMessage, isBashExecutionMessage } from "./messages.js";
import type { SessionManager } from "./session-manager.js";

View file

@ -2,7 +2,7 @@ import { type Api, getApiKey, getModels, getProviders, type KnownProvider, type
import { type Static, Type } from "@sinclair/typebox";
import AjvModule from "ajv";
import { existsSync, readFileSync } from "fs";
import { getModelsPath } from "./config.js";
import { getModelsPath } from "../utils/config.js";
import { getOAuthToken, type SupportedOAuthProvider } from "./oauth/index.js";
import { loadOAuthCredentials } from "./oauth/storage.js";

View file

@ -1,5 +1,5 @@
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { getAgentDir, getOAuthPath } from "../config.js";
import { getAgentDir, getOAuthPath } from "../../utils/config.js";
export interface OAuthCredentials {
type: "oauth";

View file

@ -2,7 +2,7 @@ import type { AgentState, AppMessage } from "@mariozechner/pi-agent-core";
import { randomBytes } from "crypto";
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "fs";
import { join, resolve } from "path";
import { getAgentDir } from "./config.js";
import { getAgentDir } from "../utils/config.js";
function uuidv4(): string {
const bytes = randomBytes(16);

View file

@ -1,6 +1,6 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { getAgentDir } from "./config.js";
import { getAgentDir } from "../utils/config.js";
export interface CompactionSettings {
enabled?: boolean; // default: true

View file

@ -1,6 +1,6 @@
import { existsSync, readdirSync, readFileSync } from "fs";
import { join, resolve } from "path";
import { CONFIG_DIR_NAME, getCommandsDir } from "./config.js";
import { CONFIG_DIR_NAME, getCommandsDir } from "../utils/config.js";
/**
* Represents a custom slash command loaded from a file

View file

@ -5,7 +5,7 @@ import { join } from "node:path";
import type { AgentTool } from "@mariozechner/pi-ai";
import { Type } from "@sinclair/typebox";
import { spawn } from "child_process";
import { getShellConfig, killProcessTree } from "../shell.js";
import { getShellConfig, killProcessTree } from "../../utils/shell.js";
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateTail } from "./truncate.js";
/**

View file

@ -5,7 +5,7 @@ import { existsSync } from "fs";
import { globSync } from "glob";
import { homedir } from "os";
import path from "path";
import { ensureTool } from "../tools-manager.js";
import { ensureTool } from "../../utils/tools-manager.js";
import { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from "./truncate.js";
/**

View file

@ -5,7 +5,7 @@ import { spawn } from "child_process";
import { readFileSync, type Stats, statSync } from "fs";
import { homedir } from "os";
import path from "path";
import { ensureTool } from "../tools-manager.js";
import { ensureTool } from "../../utils/tools-manager.js";
import {
DEFAULT_MAX_BYTES,
formatSize,

View file

@ -1,3 +1,3 @@
export { SessionManager } from "./core/session-manager.js";
export { bashTool, codingTools, editTool, readTool, writeTool } from "./core/tools/index.js";
export { main } from "./main.js";
export { SessionManager } from "./session-manager.js";
export { bashTool, codingTools, editTool, readTool, writeTool } from "./tools/index.js";

View file

@ -5,7 +5,18 @@ import chalk from "chalk";
import { existsSync, readFileSync, statSync } from "fs";
import { homedir } from "os";
import { extname, join, resolve } from "path";
import { getChangelogPath, getNewEntries, parseChangelog } from "./changelog.js";
import { AgentSession } from "./core/agent-session.js";
import { exportFromFile } from "./core/export-html.js";
import { messageTransformer } from "./core/messages.js";
import { findModel, getApiKeyForModel, getAvailableModels } from "./core/model-config.js";
import { SessionManager } from "./core/session-manager.js";
import { SettingsManager } from "./core/settings-manager.js";
import { loadSlashCommands } from "./core/slash-commands.js";
import { allTools, codingTools, type ToolName } from "./core/tools/index.js";
import { InteractiveMode, runPrintMode, runRpcMode } from "./modes/index.js";
import { SessionSelectorComponent } from "./modes/interactive/components/session-selector.js";
import { initTheme } from "./modes/interactive/theme/theme.js";
import { getChangelogPath, getNewEntries, parseChangelog } from "./utils/changelog.js";
import {
APP_NAME,
CONFIG_DIR_NAME,
@ -14,19 +25,8 @@ import {
getModelsPath,
getReadmePath,
VERSION,
} from "./config.js";
import { AgentSession } from "./core/agent-session.js";
import { exportFromFile } from "./export-html.js";
import { messageTransformer } from "./messages.js";
import { findModel, getApiKeyForModel, getAvailableModels } from "./model-config.js";
import { InteractiveMode, runPrintMode, runRpcMode } from "./modes/index.js";
import { SessionManager } from "./session-manager.js";
import { SettingsManager } from "./settings-manager.js";
import { loadSlashCommands } from "./slash-commands.js";
import { initTheme } from "./theme/theme.js";
import { allTools, codingTools, type ToolName } from "./tools/index.js";
import { ensureTool } from "./tools-manager.js";
import { SessionSelectorComponent } from "./tui/session-selector.js";
} from "./utils/config.js";
import { ensureTool } from "./utils/tools-manager.js";
const defaultModelPerProvider: Record<KnownProvider, string> = {
anthropic: "claude-sonnet-4-5",

View file

@ -8,8 +8,19 @@ import { createWriteStream, existsSync, readFileSync, statSync } from "fs";
import { homedir, tmpdir } from "os";
import { extname, join, resolve } from "path";
import stripAnsi from "strip-ansi";
import { getChangelogPath, getNewEntries, parseChangelog } from "./changelog.js";
import { calculateContextTokens, compact, shouldCompact } from "./compaction.js";
import { calculateContextTokens, compact, shouldCompact } from "./core/compaction.js";
import { exportFromFile } from "./core/export-html.js";
import { type BashExecutionMessage, messageTransformer } from "./core/messages.js";
import { findModel, getApiKeyForModel, getAvailableModels } from "./core/model-config.js";
import { loadSessionFromEntries, SessionManager } from "./core/session-manager.js";
import { SettingsManager } from "./core/settings-manager.js";
import { expandSlashCommand, loadSlashCommands } from "./core/slash-commands.js";
import { allTools, codingTools, type ToolName } from "./core/tools/index.js";
import { DEFAULT_MAX_BYTES, truncateTail } from "./core/tools/truncate.js";
import { SessionSelectorComponent } from "./modes/interactive/components/session-selector.js";
import { initTheme } from "./modes/interactive/theme/theme.js";
import { TuiRenderer } from "./tui/tui-renderer.js";
import { getChangelogPath, getNewEntries, parseChangelog } from "./utils/changelog.js";
import {
APP_NAME,
CONFIG_DIR_NAME,
@ -18,20 +29,9 @@ import {
getModelsPath,
getReadmePath,
VERSION,
} from "./config.js";
import { exportFromFile } from "./export-html.js";
import { type BashExecutionMessage, messageTransformer } from "./messages.js";
import { findModel, getApiKeyForModel, getAvailableModels } from "./model-config.js";
import { loadSessionFromEntries, SessionManager } from "./session-manager.js";
import { SettingsManager } from "./settings-manager.js";
import { getShellConfig } from "./shell.js";
import { expandSlashCommand, loadSlashCommands } from "./slash-commands.js";
import { initTheme } from "./theme/theme.js";
import { allTools, codingTools, type ToolName } from "./tools/index.js";
import { DEFAULT_MAX_BYTES, truncateTail } from "./tools/truncate.js";
import { ensureTool } from "./tools-manager.js";
import { SessionSelectorComponent } from "./tui/session-selector.js";
import { TuiRenderer } from "./tui/tui-renderer.js";
} from "./utils/config.js";
import { getShellConfig } from "./utils/shell.js";
import { ensureTool } from "./utils/tools-manager.js";
const defaultModelPerProvider: Record<KnownProvider, string> = {
anthropic: "claude-sonnet-4-5",

View file

@ -4,8 +4,13 @@
import { Container, Loader, Spacer, Text, type TUI } from "@mariozechner/pi-tui";
import stripAnsi from "strip-ansi";
import {
DEFAULT_MAX_BYTES,
DEFAULT_MAX_LINES,
type TruncationResult,
truncateTail,
} from "../../../core/tools/truncate.js";
import { theme } from "../theme/theme.js";
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from "../tools/truncate.js";
import { DynamicBorder } from "./dynamic-border.js";
// Preview line limit when not expanded (matches tool execution behavior)

View file

@ -3,7 +3,7 @@ import type { AssistantMessage } from "@mariozechner/pi-ai";
import { type Component, visibleWidth } from "@mariozechner/pi-tui";
import { existsSync, type FSWatcher, readFileSync, watch } from "fs";
import { join } from "path";
import { isModelUsingOAuth } from "../model-config.js";
import { isModelUsingOAuth } from "../../../core/model-config.js";
import { theme } from "../theme/theme.js";
/**

View file

@ -1,8 +1,8 @@
import type { Model } from "@mariozechner/pi-ai";
import { Container, Input, Spacer, Text, type TUI } from "@mariozechner/pi-tui";
import { fuzzyFilter } from "../fuzzy.js";
import { getAvailableModels } from "../model-config.js";
import type { SettingsManager } from "../settings-manager.js";
import { getAvailableModels } from "../../../core/model-config.js";
import type { SettingsManager } from "../../../core/settings-manager.js";
import { fuzzyFilter } from "../../../utils/fuzzy.js";
import { theme } from "../theme/theme.js";
import { DynamicBorder } from "./dynamic-border.js";

View file

@ -1,6 +1,6 @@
import { Container, Spacer, TruncatedText } from "@mariozechner/pi-tui";
import { getOAuthProviders, type OAuthProviderInfo } from "../oauth/index.js";
import { loadOAuthCredentials } from "../oauth/storage.js";
import { getOAuthProviders, type OAuthProviderInfo } from "../../../core/oauth/index.js";
import { loadOAuthCredentials } from "../../../core/oauth/storage.js";
import { theme } from "../theme/theme.js";
import { DynamicBorder } from "./dynamic-border.js";

View file

@ -1,6 +1,6 @@
import { type Component, Container, Input, Spacer, Text, truncateToWidth } from "@mariozechner/pi-tui";
import { fuzzyFilter } from "../fuzzy.js";
import type { SessionManager } from "../session-manager.js";
import type { SessionManager } from "../../../core/session-manager.js";
import { fuzzyFilter } from "../../../utils/fuzzy.js";
import { theme } from "../theme/theme.js";
import { DynamicBorder } from "./dynamic-border.js";

View file

@ -22,31 +22,31 @@ import {
visibleWidth,
} from "@mariozechner/pi-tui";
import { exec } from "child_process";
import { getChangelogPath, parseChangelog } from "../../changelog.js";
import { copyToClipboard } from "../../clipboard.js";
import { APP_NAME, getDebugLogPath, getOAuthPath } from "../../config.js";
import type { AgentSession } from "../../core/agent-session.js";
import { type BashExecutionMessage, isBashExecutionMessage } from "../../messages.js";
import { invalidateOAuthCache } from "../../model-config.js";
import { listOAuthProviders, login, logout, type SupportedOAuthProvider } from "../../oauth/index.js";
import { getLatestCompactionEntry, SUMMARY_PREFIX, SUMMARY_SUFFIX } from "../../session-manager.js";
import { getEditorTheme, getMarkdownTheme, onThemeChange, setTheme, theme } from "../../theme/theme.js";
import type { TruncationResult } from "../../tools/truncate.js";
import { AssistantMessageComponent } from "../../tui/assistant-message.js";
import { BashExecutionComponent } from "../../tui/bash-execution.js";
import { CompactionComponent } from "../../tui/compaction.js";
import { CustomEditor } from "../../tui/custom-editor.js";
import { DynamicBorder } from "../../tui/dynamic-border.js";
import { FooterComponent } from "../../tui/footer.js";
import { ModelSelectorComponent } from "../../tui/model-selector.js";
import { OAuthSelectorComponent } from "../../tui/oauth-selector.js";
import { QueueModeSelectorComponent } from "../../tui/queue-mode-selector.js";
import { SessionSelectorComponent } from "../../tui/session-selector.js";
import { ThemeSelectorComponent } from "../../tui/theme-selector.js";
import { ThinkingSelectorComponent } from "../../tui/thinking-selector.js";
import { ToolExecutionComponent } from "../../tui/tool-execution.js";
import { UserMessageComponent } from "../../tui/user-message.js";
import { UserMessageSelectorComponent } from "../../tui/user-message-selector.js";
import { type BashExecutionMessage, isBashExecutionMessage } from "../../core/messages.js";
import { invalidateOAuthCache } from "../../core/model-config.js";
import { listOAuthProviders, login, logout, type SupportedOAuthProvider } from "../../core/oauth/index.js";
import { getLatestCompactionEntry, SUMMARY_PREFIX, SUMMARY_SUFFIX } from "../../core/session-manager.js";
import type { TruncationResult } from "../../core/tools/truncate.js";
import { getChangelogPath, parseChangelog } from "../../utils/changelog.js";
import { copyToClipboard } from "../../utils/clipboard.js";
import { APP_NAME, getDebugLogPath, getOAuthPath } from "../../utils/config.js";
import { AssistantMessageComponent } from "./components/assistant-message.js";
import { BashExecutionComponent } from "./components/bash-execution.js";
import { CompactionComponent } from "./components/compaction.js";
import { CustomEditor } from "./components/custom-editor.js";
import { DynamicBorder } from "./components/dynamic-border.js";
import { FooterComponent } from "./components/footer.js";
import { ModelSelectorComponent } from "./components/model-selector.js";
import { OAuthSelectorComponent } from "./components/oauth-selector.js";
import { QueueModeSelectorComponent } from "./components/queue-mode-selector.js";
import { SessionSelectorComponent } from "./components/session-selector.js";
import { ThemeSelectorComponent } from "./components/theme-selector.js";
import { ThinkingSelectorComponent } from "./components/thinking-selector.js";
import { ToolExecutionComponent } from "./components/tool-execution.js";
import { UserMessageComponent } from "./components/user-message.js";
import { UserMessageSelectorComponent } from "./components/user-message-selector.js";
import { getEditorTheme, getMarkdownTheme, onThemeChange, setTheme, theme } from "./theme/theme.js";
export class InteractiveMode {
private session: AgentSession;

View file

@ -4,7 +4,7 @@ import type { EditorTheme, MarkdownTheme, SelectListTheme } from "@mariozechner/
import { type Static, Type } from "@sinclair/typebox";
import { TypeCompiler } from "@sinclair/typebox/compiler";
import chalk from "chalk";
import { getCustomThemesDir, getThemesDir } from "../config.js";
import { getCustomThemesDir, getThemesDir } from "../../../utils/config.js";
// ============================================================================
// Types & Schema

View file

@ -22,41 +22,41 @@ import {
} from "@mariozechner/pi-tui";
import { exec, spawn } from "child_process";
import stripAnsi from "strip-ansi";
import { getChangelogPath, parseChangelog } from "../changelog.js";
import { copyToClipboard } from "../clipboard.js";
import { calculateContextTokens, compact, shouldCompact } from "../compaction.js";
import { APP_NAME, getDebugLogPath, getModelsPath, getOAuthPath } from "../config.js";
import { exportSessionToHtml } from "../export-html.js";
import { type BashExecutionMessage, isBashExecutionMessage } from "../messages.js";
import { getApiKeyForModel, getAvailableModels, invalidateOAuthCache } from "../model-config.js";
import { listOAuthProviders, login, logout, type SupportedOAuthProvider } from "../oauth/index.js";
import { calculateContextTokens, compact, shouldCompact } from "../core/compaction.js";
import { exportSessionToHtml } from "../core/export-html.js";
import { type BashExecutionMessage, isBashExecutionMessage } from "../core/messages.js";
import { getApiKeyForModel, getAvailableModels, invalidateOAuthCache } from "../core/model-config.js";
import { listOAuthProviders, login, logout, type SupportedOAuthProvider } from "../core/oauth/index.js";
import {
getLatestCompactionEntry,
loadSessionFromEntries,
type SessionManager,
SUMMARY_PREFIX,
SUMMARY_SUFFIX,
} from "../session-manager.js";
import type { SettingsManager } from "../settings-manager.js";
import { getShellConfig, killProcessTree, sanitizeBinaryOutput } from "../shell.js";
import { expandSlashCommand, type FileSlashCommand, loadSlashCommands } from "../slash-commands.js";
import { getEditorTheme, getMarkdownTheme, onThemeChange, setTheme, theme } from "../theme/theme.js";
import { DEFAULT_MAX_BYTES, type TruncationResult, truncateTail } from "../tools/truncate.js";
import { AssistantMessageComponent } from "./assistant-message.js";
import { BashExecutionComponent } from "./bash-execution.js";
import { CompactionComponent } from "./compaction.js";
import { CustomEditor } from "./custom-editor.js";
import { DynamicBorder } from "./dynamic-border.js";
import { FooterComponent } from "./footer.js";
import { ModelSelectorComponent } from "./model-selector.js";
import { OAuthSelectorComponent } from "./oauth-selector.js";
import { QueueModeSelectorComponent } from "./queue-mode-selector.js";
import { SessionSelectorComponent } from "./session-selector.js";
import { ThemeSelectorComponent } from "./theme-selector.js";
import { ThinkingSelectorComponent } from "./thinking-selector.js";
import { ToolExecutionComponent } from "./tool-execution.js";
import { UserMessageComponent } from "./user-message.js";
import { UserMessageSelectorComponent } from "./user-message-selector.js";
} from "../core/session-manager.js";
import type { SettingsManager } from "../core/settings-manager.js";
import { expandSlashCommand, type FileSlashCommand, loadSlashCommands } from "../core/slash-commands.js";
import { DEFAULT_MAX_BYTES, type TruncationResult, truncateTail } from "../core/tools/truncate.js";
import { AssistantMessageComponent } from "../modes/interactive/components/assistant-message.js";
import { BashExecutionComponent } from "../modes/interactive/components/bash-execution.js";
import { CompactionComponent } from "../modes/interactive/components/compaction.js";
import { CustomEditor } from "../modes/interactive/components/custom-editor.js";
import { DynamicBorder } from "../modes/interactive/components/dynamic-border.js";
import { FooterComponent } from "../modes/interactive/components/footer.js";
import { ModelSelectorComponent } from "../modes/interactive/components/model-selector.js";
import { OAuthSelectorComponent } from "../modes/interactive/components/oauth-selector.js";
import { QueueModeSelectorComponent } from "../modes/interactive/components/queue-mode-selector.js";
import { SessionSelectorComponent } from "../modes/interactive/components/session-selector.js";
import { ThemeSelectorComponent } from "../modes/interactive/components/theme-selector.js";
import { ThinkingSelectorComponent } from "../modes/interactive/components/thinking-selector.js";
import { ToolExecutionComponent } from "../modes/interactive/components/tool-execution.js";
import { UserMessageComponent } from "../modes/interactive/components/user-message.js";
import { UserMessageSelectorComponent } from "../modes/interactive/components/user-message-selector.js";
import { getEditorTheme, getMarkdownTheme, onThemeChange, setTheme, theme } from "../modes/interactive/theme/theme.js";
import { getChangelogPath, parseChangelog } from "../utils/changelog.js";
import { copyToClipboard } from "../utils/clipboard.js";
import { APP_NAME, getDebugLogPath, getModelsPath, getOAuthPath } from "../utils/config.js";
import { getShellConfig, killProcessTree, sanitizeBinaryOutput } from "../utils/shell.js";
/**
* TUI renderer for the coding agent

View file

@ -1,6 +1,6 @@
import { existsSync } from "node:fs";
import { spawn, spawnSync } from "child_process";
import { SettingsManager } from "./settings-manager.js";
import { SettingsManager } from "../core/settings-manager.js";
let cachedShellConfig: { shell: string; args: string[] } | null = null;