Skip to content

AI Module

Slug: ai

Overview

The AI capability layer manages all AI-powered features in Tower. There are 5 distinct capabilities, each serving a different purpose:

  1. Assistant chat — Multi-turn streaming conversation via the Claude Agent SDK. The assistant acts as a task management operator with access to Tower's MCP tools.
  2. Mini summary — Generates a short (~50 character) summary when a task execution stops, used for quick reference in the UI.
  3. Dreaming — Produces structured insight JSON when a task execution completes, capturing what was accomplished, patterns discovered, and learnings. These are auto-saved as notes.
  4. Project analysis — Analyzes a project's local directory structure on import, generating a structured description covering tech stack, architecture, and key directories.
  5. Task execution — Spawns a PTY terminal running Claude CLI in an isolated environment for interactive AI-driven development.

Different capabilities can use different models. Lightweight tasks like mini summaries use Haiku for cost efficiency, while deeper analysis like Dreaming uses Sonnet for higher quality output.

Details

  • Model routing: Each capability specifies a suggested model. generateSummaryFromLog uses Haiku 4.5 for fast, cheap summaries. generateDreamingInsight and analyzeProjectDirectory use Sonnet 4.6 for deeper reasoning. Task execution and assistant chat use the system's configured default model.
  • CLI adapter: Currently hardcoded for Claude Code. The interface (spawn, resume, continue, getSessionId, buildEnvOverrides) is designed for future abstraction to support multiple CLI providers.
  • Execution summaries: When a task execution ends, Tower automatically extracts the terminal output log and generates both a mini summary and a Dreaming insight, attaching them to the execution record and saving the insight as a project note.

AI Capability Entry Points

CapabilityFileInvocation MethodSuggested Model
Assistant chatapi/internal/assistant/chat/route.tsAgent SDK query()Current default
Short summarylib/claude-session.ts -> generateSummaryFromLogAgent SDK aiQuery()Haiku 4.5
Long summary (Dreaming)lib/claude-session.ts -> generateDreamingInsightAgent SDK aiQuery()Sonnet 4.6
Project analysisactions/project-actions.ts -> analyzeProjectDirectoryAgent SDK aiQuery()Sonnet 4.6
Task executionactions/agent-actions.ts -> startPtyExecutionPTY spawn CLICurrent default

File Reference

Core Library

FileDescription
lib/claude-session.tsUnified AI entry: aiQuery(), generateSummaryFromLog(), generateDreamingInsight()
lib/assistant-sessions.tsAssistant session management (localStorage registry)
lib/assistant-constants.tsASSISTANT_SESSION_KEY and other constants
lib/assistant-message-converter.tsSDK message to UI message format conversion
lib/build-multimodal-prompt.tsMultimodal prompt construction (text + images)
lib/execution-summary.tsPost-execution summary and Dreaming insight generation
lib/cli-test.tsCLI adapter environment detection

Server Actions

FileFunctionDescription
actions/agent-actions.tsstartPtyExecutionStart Claude CLI PTY
actions/agent-actions.tsresumePtyExecutionResume session
actions/agent-actions.tscontinueLatestPtyExecutionContinue latest session
actions/cli-profile-actions.tsgetDefaultCliProfileGet active CLI profile
actions/prompt-actions.tsgetPrompts / createPromptPrompt template management
actions/project-actions.tsanalyzeProjectDirectoryAI project analysis

API Routes

RouteDescription
/api/internal/assistant/chatAssistant chat SSE streaming
/api/internal/assistant/sessionsSession message retrieval
/api/internal/assistant/imagesImage serving
/api/adapters/testCLI adapter connection test

Data Models

ModelDescription
CliProfileCLI command, arguments, and environment variable config. command only allows claude/claude-code
AgentConfigAgent-specific config with unique constraint (agent, configName)
AgentPromptPrompt templates, supporting global and workspace-level scopes
TaskExecutionExecution records, including sessionId, summary, gitLog, insightNoteId

Components

ComponentDescription
settings/cli-profile-config.tsxCLI Profile configuration UI
settings/cli-adapter-tester.tsxCLI connection test UI
settings/prompts-config.tsxPrompt template management UI
settings/ai-tools-config.tsxAgent configuration UI

CLI Adapter Interface (TODO)

Currently hardcoded for Claude Code. Will be abstracted when integrating a second CLI:

spawn(cwd, args, env)        -- Start CLI process (PTY)
resume(sessionId)            -- Resume session
continue()                   -- Continue latest session
getSessionId()               -- Get session ID
getHooks() / installHooks()  -- Hook configuration and registration
buildEnvOverrides(taskId)    -- Environment variable injection

See README.md TODO for the detailed interface list.

Security Constraints

  • CliProfile.command is restricted to the whitelist: claude, claude-code
  • baseArgs prohibits shell metacharacters ;&|$()
  • envVars prohibits dangerous keys: PATH, LD_PRELOAD, NODE_OPTIONS, etc.
  • Environment variables are injected via envOverrides; modifying process.env is forbidden