Commit Graph

60 Commits

Author SHA1 Message Date
William Valentin 409ab04ca1 feat(tui,dashboard,docs): add context command parity and context health panel 2026-02-16 18:08:19 -08:00
William Valentin 1d16cd54e6 fix(tui): align slash command parsing and handlers 2026-02-16 12:22:40 -08:00
William Valentin fd7ad7bfb0 fix(tui): add /queue command support across tui and routing 2026-02-16 12:19:21 -08:00
William Valentin 527602fd8a feat(tui): let Esc cancel active minimal-mode response generation 2026-02-16 11:42:25 -08:00
William Valentin b7a9fc1d35 fix(tui): make Esc clear line and cancel hidden prompts in minimal mode 2026-02-16 11:38:22 -08:00
William Valentin a5e8d6c216 fix(tui): cancel prompts on raw Esc input in minimal mode 2026-02-16 11:36:14 -08:00
William Valentin 205203a458 fix(tui): detect escape key variants for prompt cancellation 2026-02-16 11:34:05 -08:00
William Valentin c34ae9b75b feat(tui): add Esc key to cancel active prompt without exiting 2026-02-16 11:31:17 -08:00
William Valentin 948d4ac6d8 chore(lint): burn down remaining warnings to zero 2026-02-15 23:14:21 -08:00
William Valentin 49b752e8b0 chore(lint): reduce warning debt across core adapters and model clients 2026-02-15 23:03:42 -08:00
William Valentin e16c0bc2c7 audit follow-up: reduce warning hotspots in automation and gateway tests 2026-02-15 22:49:45 -08:00
William Valentin 1a075e62b0 audit follow-up: burn down lint hotspots and dedupe channel gating flows 2026-02-15 22:44:04 -08:00
William Valentin 46538e71a8 chore(lint): restore zero-error eslint baseline 2026-02-15 22:25:29 -08:00
William Valentin 50dcff5ea6 chore: commit unrelated local changes 2026-02-15 21:51:22 -08:00
William Valentin 42c526bce9 Add re-auth y/N confirmation to minimal TUI login flows 2026-02-15 20:12:31 -08:00
William Valentin 99ad53a1ee Add API vs Coding Plan mode selection for Z.AI auth 2026-02-15 20:06:35 -08:00
William Valentin 8b1ed2f689 Make /model provider switch activate selected tier in minimal TUI 2026-02-15 19:53:42 -08:00
William Valentin 7e390dd777 tui: extend /login for OpenAI key and Anthropic token 2026-02-15 10:32:13 -08:00
William Valentin 7df0569a39 feat(models): add Z.AI (GLM) credential integration and setup flow
Implement first-class Z.AI credential storage and authentication:

- New auth provider: src/auth/zai.ts for Z.AI API key management
- New CLI command: flynn zai-auth to store Z.AI API keys
- New TUI command: /login zai for interactive credential entry
- Modified src/auth/index.ts to register zai provider
- Modified src/cli/index.ts to register zai-auth command
- Modified src/cli/setup/providers.ts to include Z.AI in setup wizard
- Modified src/daemon/models.ts to support zhipuai use_oauth flag
- Modified src/daemon/clientFactory.test.ts to add Z.AI tests
- Modified src/frontends/tui/commands.ts to add login command
- Modified src/frontends/tui/minimal.ts to support credential prompts

This allows users to authenticate with Z.AI (GLM models) without
embedding secrets in config files. Credentials are stored securely in
~/.config/flynn/auth.json and resolved at runtime.

Updated state.json with new feature entry documenting the integration.
2026-02-13 16:23:49 -08:00
William Valentin 955b9e28e0 feat: add OpenAI OAuth, strict model overrides, and Gmail pull mode 2026-02-13 14:55:40 -08:00
William Valentin 125af4e832 refactor(backend): use systemd for daemon management
Replace manual process management with systemctl --user commands.
Uses ollama.service and llama-server.service units for proper lifecycle
management, VRAM cleanup, and integration with system services.
2026-02-12 00:24:43 -08:00
William Valentin 1c8da30905 fix(backend): only kill processes started by TUI
Track PIDs of backends started by /backend command and only kill those
specific PIDs. Previous implementation used pkill which would kill all
Ollama/llama-server processes including those started by the user or
systemd services. Now we only terminate processes we started.
2026-02-12 00:19:26 -08:00
William Valentin 05037a917e feat(backend): auto-stop/start daemon when switching backends
- Add local_providers with ollama and llamacpp configurations
- /backend command now stops current daemon before starting new one
- Start backends as detached processes to avoid blocking TUI
- Wait 500ms for daemon to initialize before switching
2026-02-12 00:13:59 -08:00
William Valentin 6090508bad style: auto-fix ESLint issues (curly braces and formatting)
- Add curly braces to all if/else/for/while statements
- Fix indentation and trailing spaces
- Auto-fixed 372 linting errors using eslint --fix
- Remaining issues are warnings only (non-null assertions, explicit any types)
2026-02-11 10:30:24 -08:00
William Valentin 5c90640e2a fix: clear error messages for missing API keys on provider switch
Previously, switching to zhipuai/openrouter/xai via /model would throw a
confusing 'OPENAI_API_KEY missing' error from the OpenAI SDK. Now
createClientFromConfig validates API keys before constructing the client,
throwing errors that name the correct env var (e.g. ZHIPUAI_API_KEY).

Also fixes the misleading 'as anthropic' type cast in the /model handler
to validate against MODEL_PROVIDERS and use the ModelProvider type.
2026-02-10 21:32:44 -08:00
William Valentin 25482b8516 feat: sync PROVIDER_NAMES with config schema and update README docs
Extract MODEL_PROVIDERS const from config schema as single source of truth
for provider names. PROVIDER_NAMES in TUI commands now imports from schema
instead of maintaining a hardcoded list. Adds tests verifying sync.

Updates README TUI Commands section with /model hot-swap documentation,
supported providers, and runtime model switching examples.
2026-02-10 21:26:18 -08:00
William Valentin 7a69794418 fix: sync model tier between TUI and WebChat when switching models
ModelRouter now supports multiple tier-change listeners via addOnTierChange(),
SessionBridge subscribes to tier changes and propagates them to all WebChat
agents (both existing and newly created), and the fullscreen TUI now also
updates the agent's tier when switching models (matching minimal TUI behavior).
2026-02-10 20:22:40 -08:00
William Valentin 2644ed269e fix(tui): reset agent state on /reset command in fullscreen mode
Use agent.reset() instead of session.clear() when agent is available,
ensuring tool fingerprint, usage counters, and agent history are all
cleared properly alongside the session.
2026-02-10 13:27:58 -08:00
William Valentin 671ec035e9 fix(tui): show tool activity in fullscreen mode via Ink-compatible callback
Replace process.stdout.write-based onToolUse callback (which corrupts
Ink rendering) with a React state-driven approach that shows tool names,
args, and completion status in the streaming content area.
2026-02-10 13:26:47 -08:00
William Valentin e46e8740a1 fix(tui): enable tool access in fullscreen mode via NativeAgent
Fullscreen TUI was calling modelClient directly, bypassing the NativeAgent
tool loop entirely. Pass the agent through FullscreenTuiConfig → App and
use agent.process() for message handling, which enables the full tool
registry and executor.
2026-02-10 13:21:22 -08:00
William Valentin f892bbe6ca feat(tui): add ASCII art banner on startup 2026-02-10 13:11:32 -08:00
William Valentin 411c6d84a2 feat(tui): persist model tier selection and fix formatting
Persist /model tier choice to ~/.local/share/flynn/preferences.json so
it survives restarts. Decode HTML entities (e.g. ') in markdown
renderer output. Suppress noisy logger.info and punycode deprecation
warnings in TUI startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 12:23:12 -08:00
William Valentin 4cc29f534a fix(tui): render inline markdown formatting with ANSI codes
Block-level renderer methods (paragraph, heading, blockquote, list) were
using raw token.text instead of this.parser.parseInline(tokens), causing
bold, italic, and inline code to never render. Add table renderer with
aligned columns and box-drawing separators. Remove unused marked-terminal
dependency (incompatible with marked v17).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 11:29:57 -08:00
William Valentin 64e3716ede test(tui): add /pair command parsing tests 2026-02-09 21:56:27 -08:00
William Valentin 3ea4f64d6b feat(tui): wire /pair command execution with PairingManager 2026-02-09 21:56:27 -08:00
William Valentin 322852917c fix(tui): remove stale readline close listeners to prevent memory leak warning
Clean up the once('close') listener on the readline Interface when
rl.question() resolves normally. Previously, each prompt loop iteration
accumulated a close listener that was never removed, triggering
MaxListenersExceededWarning after 11 prompts.
2026-02-09 21:50:43 -08:00
William Valentin 1e29da4da2 feat: complete DM pairing codes with channel adapters, gateway handlers, and TUI command (Tier 4 feature 4) 2026-02-09 18:28:10 -08:00
William Valentin 9be8f76bc7 feat: implement Tier 3 features — lane queue, credential redaction, token dashboard, xAI, Voyage AI
- Lane Queue: per-session FIFO queue in gateway replacing reject-when-busy (9 tests)
- Credential Redaction: redactConfig() expanded to cover 18+ secret fields (16 tests)
- Web UI Token Dashboard: system.tokenUsage endpoint + Usage page with summary cards
- xAI (Grok) Provider: OpenAI-compatible client with model pricing
- Voyage AI Embeddings: new embedding provider with configurable dimensions (5 tests)
- Update gap analysis: 90→95 match (70%→74%), Tier 3 section marked DONE
- Update state.json: test count 1001→1034, add tier3_completion entry

Total: 1034 tests passing across 85 files, typecheck clean
2026-02-09 10:32:57 -08:00
William Valentin 1c2f54fae3 feat: implement tier 1 quick wins (tool groups, typing, pruning, verbose, think)
Five additive features with no breaking changes:

- Tool groups: group:fs, group:runtime, group:web, group:memory syntactic
  sugar for allow/deny lists in tool policy config
- Typing indicators: Discord sendTyping() and WhatsApp sendStateTyping()
  on message receipt for better UX feedback
- Session pruning: TTL-based auto-cleanup via sessions.ttl config with
  hourly daemon timer and SQLite GROUP BY pruning
- /verbose command: TUI command parser toggle for raw streaming display
- !!think prefix: per-message extended thinking mode wired through
  Anthropic (budget_tokens), OpenAI/GitHub (reasoning_effort), and
  Gemini (thinkingConfig) providers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:35:00 -08:00
William Valentin d4530a7034 feat: add runtime provider/model switching via /model <tier> <provider/model>
- ModelRouter: add setClient(), labels map, getLabel(), getAllLabels()
- TUI commands: parse /model <tier> <provider/model> syntax with autocompletion
- TUI minimal: handle provider switching via createClientFromConfig factory
- Daemon: wire initial labels into router config
- Fix /model alias mappings (opus=complex, sonnet=default, haiku=fast)
- Add design doc and update state.json with feature status
2026-02-06 23:42:14 -08:00
William Valentin f363717f5f feat: add GitHub Copilot model provider with OAuth device flow
Add a new 'github' model provider backed by the Copilot API
(api.githubcopilot.com), with OAuth device flow for authentication.

- New src/auth/github.ts: device flow login, token storage at
  ~/.config/flynn/auth.json with 0600 permissions
- New src/models/github.ts: OpenAI-compatible client with streaming,
  tool calling, and Copilot-specific headers
- Add 'github' to provider enum in config schema
- Register provider in daemon factory and TUI client factory
- Refactor TUI to use provider-agnostic client factory (was hardcoded
  to AnthropicClient for all tiers)
- Add /login command to TUI for interactive OAuth authorization
- Add Copilot model cost tracking entries
2026-02-06 22:26:52 -08:00
William Valentin a515912537 feat: add multimodal media pipeline for image support across all providers and channels
Widen Message.content from string to string | MessageContentPart[] to support
multimodal content. Add Attachment type to channel layer, media conversion
utilities, and image extraction to all channel adapters (Telegram, Discord,
Slack, WhatsApp). Update all model clients (Anthropic, OpenAI, Gemini, Bedrock)
to convert structured content to provider-specific formats. Fix downstream
consumers (tokens, compaction, TUI, local models) to handle the widened type
via getMessageText() helper.
2026-02-06 17:17:21 -08:00
William Valentin 4316dbd3be feat: add P2 features — retry policy, prompt templating, usage tracking, tech debt cleanup
- Extract shared splitMessage() into channels/utils.ts (dedup 4 adapters)
- Add Slack user name resolution with caching (users.info API)
- Add withRetry() with exponential backoff + jitter, isRetryable() filter
- Wire retry config into ModelRouter.chat() (non-streaming only)
- Add assembleSystemPrompt() multi-file template system (SOUL/AGENTS/IDENTITY/USER/TOOLS.md)
- Add usage tracking accumulators in NativeAgent + AgentOrchestrator
- Add estimateCost() with per-model pricing table
- Add /usage TUI command with full usage report formatting
- Add retrySchema and promptSchema to config schema

Tests: 569 passing, typecheck clean
2026-02-06 15:12:35 -08:00
William Valentin 306e11bd2e feat: add multi-model delegation (Phase 0) and context compaction (Phase 1)
Phase 0 — Multi-Model Delegation:
- AgentOrchestrator wraps NativeAgent with delegate() for stateless
  single-turn calls to any model tier (fast/default/complex/local)
- DelegationConfig maps task types (compaction, classification, etc.)
  to model tiers
- Delegation prompts for compaction, memory extraction, classification,
  and tool summarisation
- Per-tier usage tracking for cost visibility
- Config schema: agents.delegation and agents.primary_tier

Phase 1 — Context Compaction:
- Token estimation (char/4 heuristic) with context window lookup
- shouldCompact() threshold check against context window percentage
- compactHistory() splits old/recent messages, delegates summary to
  fast tier, returns CompactionResult
- Automatic compaction in AgentOrchestrator.process() when configured
- Force-compact via orchestrator.compact() with session persistence
- Session.replaceHistory() with atomic SQLite transaction
- /compact TUI command with feedback on compacted token counts
- Config schema: compaction.enabled, threshold_pct, keep_turns,
  summary_max_tokens

Tests: 385 passing across 50 files (22 new tests in 2 new test files)
2026-02-06 13:17:02 -08:00
William Valentin f7cc87a4bb fix: sync agent tier when /model command switches model
The /model command was only updating the router's currentTier but not
the agent's currentTier. Since NativeAgent.chatWithRouter() passes its
own tier to router.chat(), switching to 'local' still sent requests
through the default (Anthropic) client first.
2026-02-06 10:05:32 -08:00
William Valentin e4b7f96d33 fix: provider-aware model routing with fallback visibility
- Extract createClientFromConfig() to dispatch on provider field instead
  of hardcoding all tiers as AnthropicClient
- Add fallback/fallbackReason metadata to ChatResponse and ChatStreamEvent
  so callers know when a fallback model was used
- Enhance doctor check to report full model stack and warn on missing
  API keys for cloud providers
- Log fallback warnings in NativeAgent and display them in TUI
- Support tier names and local_providers entries in fallback_chain
- Add 8 tests for createClientFromConfig covering all provider types
2026-02-06 09:58:56 -08:00
William Valentin 5088f7a6be feat(tui): display tool execution status in minimal TUI
TUI now creates a NativeAgent with tool registry/executor and uses
agent.process() for message handling. Tool calls display status lines
showing tool name, args, and success/error result. Falls back to
direct model client when agent is not configured.
2026-02-05 17:53:00 -08:00
William Valentin c1f64d6ded feat: enhance TUI with colors, command hints, and improved rendering 2026-02-05 15:51:29 -08:00
William Valentin f722cf2bf0 feat: add /backend command handler to MinimalTui 2026-02-05 13:36:36 -08:00
William Valentin 465b4a0c3c feat: add /backend command parsing
Add support for /backend command to show or switch local backend providers. Follows the same pattern as /model command with optional argument support.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:35:10 -08:00