Commit Graph

363 Commits

Author SHA1 Message Date
William Valentin 8bf88049bf feat: add runtime context awareness — system.info tool + date/time in system prompt
- assembleSystemPrompt() now injects '# Runtime Context' with current date/time
- New system.info tool: date, time, hostname, platform, arch, uptime, memory, Node.js version
- Tool available in all profiles (minimal/messaging/coding/full)
- 983 tests passing (+7 new)
2026-02-07 16:22:17 -08:00
William Valentin 33f6f142bc docs: add file.patch and Gmail Pub/Sub watcher documentation
- README: features list, Gmail config section with field reference and
  template variables, hook examples, architecture tree, CLI description
- CHANGELOG: new Added entries for both features
- SOUL.md: file.patch in capabilities list
- config/default.yaml: file.patch in confirm hooks, commented-out
  automation section with cron, webhooks, gmail, heartbeat examples
2026-02-07 15:45:41 -08:00
William Valentin be3363fdc8 docs: update state.json and gap analysis — file.patch + Gmail (87/116 = 75%) 2026-02-07 15:40:45 -08:00
William Valentin 06438bb44f feat: add Gmail Pub/Sub watcher for inbound email automation
New ChannelAdapter that monitors Gmail via Google Cloud Pub/Sub push
notifications with polling fallback. Supports OAuth2 auth, configurable
watch labels, template rendering with email metadata placeholders
(from, to, subject, snippet, date, id, labels).

Wired into daemon lifecycle and gateway (POST /gmail/push endpoint).
Includes 16 tests covering auth, templates, push notifications, and
channel routing.
2026-02-07 15:39:24 -08:00
William Valentin 131d23989c feat: add file.patch tool for multi-hunk structured patches
Implements apply_patch equivalent: a single tool call can make multiple
line-based edits (replacements, insertions, deletions) across one or more
files. Hunks are applied bottom-up to preserve line numbers.

Includes 10 tests covering replacement, multi-hunk, insertion, deletion,
multi-file, overlapping hunks error, OOB error, and edge cases.
2026-02-07 15:39:15 -08:00
William Valentin c1e2f1e86c Add documentation for agent model delegation fix
Document the solution to OpenCode/Claude Code issue where LLMs
cannot properly delegate to specific model tiers when using subagents.
2026-02-07 15:06:48 -08:00
William Valentin c062f687d2 docs: add state.json update rule to AGENTS.md 2026-02-07 14:55:25 -08:00
William Valentin 308e7f228e docs: update state.json with tier 2 completion stats 2026-02-07 14:53:50 -08:00
William Valentin d0ebbff608 docs: add documentation for Tier 2 features
- README: webhooks, heartbeat, vector memory, Docker sections with config examples
- README: updated features list, architecture tree, environment variables
- CHANGELOG: entries for all 4 Tier 2 features
2026-02-07 14:52:02 -08:00
William Valentin 93c0d64e8d docs: update gap analysis — mark Tier 2 as complete (85/116 = 73%) 2026-02-07 14:46:23 -08:00
William Valentin 88731a50e3 feat: add heartbeat monitor and vector memory search (Tier 2)
Heartbeat:
- HeartbeatMonitor with 5 checks: gateway, model, channels, memory, disk
- Configurable interval, failure threshold, notification channel
- Recovery notifications when health restores
- 25 new tests

Vector Memory Search:
- EmbeddingProvider interface with OpenAI, Gemini, Ollama, LlamaCpp backends
- SQLite-backed VectorStore with cosine similarity search
- Text chunker with paragraph-aware splitting and overlap
- HybridSearch merging keyword + vector results with configurable weight
- Background indexer with dirty-namespace tracking
- Graceful fallback to keyword search when embeddings unavailable
- 51 new tests

Config: automation.heartbeat + memory.embedding schema sections
Total: 950 tests passing, all types clean
2026-02-07 14:45:11 -08:00
William Valentin b50c140d25 feat: add Docker support and inbound webhooks (Tier 2)
- Dockerfile: multi-stage build (node:22-alpine), better-sqlite3 native deps handled
- .dockerignore + docker-compose.yml for deployment
- FLYNN_DATA_DIR env var support in daemon, CLI, and TUI
- WebhookHandler: ChannelAdapter for HTTP POST /webhooks/:name
- Per-webhook HMAC auth, template rendering ({{body}}, {{json.field}})
- Config schema: automation.webhooks array with name/secret/message/output
- Gateway routes webhook requests before static files (bypasses gateway auth)
- 23 new tests for webhook functionality, 874 total tests passing
2026-02-07 14:36:05 -08:00
William Valentin b322e8f29c fix: GitHub Copilot fallback — remove stale API version header and fix model name mapping
Two issues prevented the GitHub Models fallback from working:

1. The X-GitHub-Api-Version: 2022-11-28 header caused '400 invalid
   apiVersion' errors. The Copilot chat completions endpoint does not
   use this header — removed from both constructor and rebuildClient.

2. The anthropicToGitHubModel mapping was incomplete: it only knew
   three models and the generic date-stripping fallback produced wrong
   names (e.g. 'claude-sonnet-4-5' instead of 'claude-sonnet-4.5').
   GitHub Copilot uses dots for sub-versions, not hyphens.

   Updated with explicit mappings for all current models (sonnet 4,
   4.5; opus 4, 4.5, 4.6; haiku 4.5) and a smarter generic fallback
   that converts digit-hyphen-digit to digit.digit at the end.

3. createClientFromConfig now auto-maps Anthropic-style model names
   when the provider is 'github', so users can copy model names from
   their Anthropic config into fallback blocks without manual renaming.
2026-02-07 14:04:54 -08:00
William Valentin e12eb3a0be fix: TUI now uses shared model router with auto-fallback support
The TUI was building its own ModelRouter with a duplicated client factory
that lacked auto same-model fallback, local_providers resolution, retry
config, and per-tier fallback logic. When Anthropic failed, it skipped
GitHub Models and fell straight to the local Ollama model.

Replace the duplicated ~50-line createClient + router setup in tui.ts
with a single call to the daemon's createModelRouter(), which already
handles all of these correctly. This removes ~50 lines of duplicated
code and ensures TUI and daemon have identical fallback behavior.
2026-02-07 13:58:34 -08:00
William Valentin f43d6edfe0 docs: document fallback patterns in default.yaml
Add comments explaining:
- Auto same-model fallback via GitHub Models for Anthropic tiers
- Inline per-tier fallback blocks
- The full fallback order (primary → auto → inline → global chain)
- local_providers map for named providers in fallback_chain
- Usage examples for both patterns
2026-02-07 13:55:38 -08:00
William Valentin 4876bad9ab feat: register web search and process tools in TUI mode
Previously these tools were only available in daemon mode. Now TUI mode
also registers web search tools (when credentials are configured) and
process management tools with proper cleanup on exit.
2026-02-07 13:54:17 -08:00
William Valentin 5984c42bfd feat: auto same-model fallback via GitHub Models when primary Anthropic provider fails
When a tier uses the Anthropic provider and has no user-configured inline
fallback, automatically insert a GitHub Models client for the equivalent
model as a tier fallback. This ensures the same model is tried via an
alternative provider before degrading to the global fallback chain (which
may be a much weaker local model).

Mapping: claude-sonnet-4-20250514 → claude-sonnet-4, etc.
2026-02-07 13:52:53 -08:00
William Valentin d5694649bf docs: update gap analysis for tier 1 implementation (65% → 69%)
Mark 5 features as MATCH: tool groups, session pruning, /think,
/verbose, typing indicators. Update scorecard (80/116 features),
remove completed Tier 1 section from remaining gaps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:36:22 -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 6bb424cddc feat: add agent tools and sanitize tool names for Anthropic API
Add 8 new agent-callable tools (sessions.list/history/create/delete,
agents.list, message.send, cron.list/trigger) and sanitize tool names
at the API boundary (dots → underscores) to comply with Anthropic's
`^[a-zA-Z0-9_-]{1,128}` requirement. Reverse-maps sanitized names
back to internal names for hook callbacks and tool execution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 12:23:09 -08:00
William Valentin f0e3987d1c feat: wire per-tier fallbacks in daemon model router setup
Reads the optional fallback field from each tier's config and builds
a tierFallbacks map passed to ModelRouter at startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 12:10:17 -08:00
William Valentin b9b70ce2b1 feat: add per-tier fallback support to ModelRouter
The router now accepts a tierFallbacks map so each model tier can have
its own fallback providers. Tier fallbacks are tried before the global
fallback chain in both chat() and chatStream().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 12:09:38 -08:00
William Valentin c8c3c74fde feat: add per-tier fallback field to model config schema
Each model tier (fast, default, complex, local) can now specify an
optional fallback provider config that the router will try before
falling through to the global fallback chain.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 12:08:17 -08:00
William Valentin 42696566f6 fix: resolve whatsapp-web.js ESM import for Node.js v25
whatsapp-web.js lacks proper ESM named exports, causing SyntaxError on
import. Switch to default import with destructuring, use InstanceType
for the Client type annotation, and update test mock to provide both
default and named exports.
2026-02-07 10:15:40 -08:00
William Valentin 130711a377 docs: update documentation for P7 web UI dashboard completion
- README: add Web UI Dashboard section, update features list with all
  current capabilities (multi-channel, media pipeline, sandboxing, etc.),
  expand model providers table, update architecture diagram
- CHANGELOG: add P7 entries (dashboard SPA, 4 new gateway handlers)
- state.json: add P7 entry with all 6 phases and file lists, update
  overall_progress to reflect P0-P7 completion
- web-ui-dashboard.md: mark as completed with detailed phase outcomes
2026-02-07 10:11:54 -08:00
William Valentin 22230a3e3f feat: add web UI dashboard SPA with dashboard, chat, sessions, and settings pages
- Add SPA shell with hash-based router, sidebar navigation, and WebSocket RPC client
- Add dashboard page with system health cards, channel status, and auto-refresh
- Add chat page with session selector, streaming tool events, and markdown rendering
- Add sessions page with list, history viewer, and delete functionality
- Add settings page with hook pattern editor, tool list, and config viewer
- Add backend handlers: sessions.delete, sessions.switch, system.channels, system.usage
- Wire channelRegistry into gateway server for channel status reporting
- Extend static file server with .mjs, .png, .ico, .woff2 content types
2026-02-07 10:07:45 -08:00
William Valentin f7d889e35e docs: update state.json with P6 completion and overall progress 2026-02-07 09:11:49 -08:00
William Valentin 2a962abcd0 feat: add audio transcription pipeline for voice messages
Adds Whisper-compatible audio transcription via configurable endpoint.
New functions: isSupportedAudio(), mimeToExtension(), transcribeAudio(),
buildUserMessageWithAudio(). Config schema gains audio section with
transcription_endpoint, api_key, and model. Daemon wires transcription
into the message router. Channel adapters extract audio from voice/audio
messages (Telegram voice+audio, Discord audio/*, Slack audio/*, WhatsApp
ptt+audio). Includes 57 media tests (was 25, now covers all audio paths).
2026-02-07 09:09:13 -08:00
William Valentin e052778b0a feat: add gateway protocol attachment support
Extends the gateway wire protocol with GatewayAttachment type and
attachment event. agent.send handler now accepts optional attachments
parameter and converts them for the agent pipeline. Includes 5 new
tests for protocol and handler layers.
2026-02-07 09:09:06 -08:00
William Valentin b9bfee9c5b feat: add outbound attachment support with media.send tool
Introduces OutboundAttachment type on OutboundMessage, an
OutboundAttachmentCollector (push/drain pattern), and a media.send
tool that queues files for outbound delivery. Each channel adapter
(Telegram, Discord, Slack, WhatsApp) sends attachments after the
text reply. Includes 15 tests for collector and tool.
2026-02-07 09:09:00 -08:00
William Valentin 1e6f6bb5a4 feat: add image.analyze tool for vision model analysis
Provides a factory createImageAnalyzeTool(modelClient) that sends images
to a vision-capable model and returns a textual analysis. Includes 15
tests covering base64, URL, multi-image, error, and edge cases.
2026-02-07 09:08:53 -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 e92ce69067 docs: add commit-often and subagent model selection rules to AGENTS.md 2026-02-06 23:42:06 -08:00
William Valentin 73fc5d173d feat: add auto-login for GitHub Copilot when no token is available
GitHubModelsClient now lazily resolves tokens at first API call. If no
token exists (env var, stored OAuth, or config), it triggers the OAuth
device flow automatically via an onLoginRequired callback wired in both
the TUI and daemon entry points.
2026-02-06 22:33:48 -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 cfdd448495 docs: add Docker sandbox and multi-agent routing design/implementation plans 2026-02-06 16:52:38 -08:00
William Valentin 880744846f feat: wire new providers, auth, mention-gating, and browser into daemon
Update config schema with server auth fields (token, tailscale_identity,
auth_http), channel mention settings, browser config, and openrouter/bedrock
provider enum values. Wire GeminiClient, BedrockClient, OpenRouter into
createClientFromConfig. Initialize BrowserManager and register browser tools
in daemon startup. Pass auth config and channel mention settings through to
gateway and adapters. Add puppeteer-core, @google/generative-ai, and
@aws-sdk/client-bedrock-runtime dependencies.
2026-02-06 16:52:18 -08:00
William Valentin 8c56a5a1a8 feat: add Chrome DevTools Protocol browser tools
Add BrowserManager (puppeteer-core) with page pool and auto-detection of
Chrome/Chromium. Six tools: browser.navigate, browser.screenshot,
browser.click, browser.type, browser.content, browser.eval. Feature is
opt-in (browser.enabled defaults to false). Add to coding tool profile.
Includes 22 unit tests for manager and all tools.
2026-02-06 16:52:03 -08:00
William Valentin 647d7779c7 feat: add group chat and mention-gating to channel adapters
Slack: add requireMention option, resolve bot user ID on connect.
Telegram: add group chat mention/reply-to-bot detection, strip @mention
from message text, default requireMention=true for groups.
WhatsApp: add allowedGroupIds for group chat support, mention detection
via mentionedIds and body text, strip bot mention from messages.
2026-02-06 16:51:52 -08:00
William Valentin 20930a4816 feat: add query-param token auth and optional HTTP auth to gateway
Support ?token= query parameter as a fallback for WebSocket clients that
cannot set Authorization headers (e.g. browsers). Add authHttp option to
GatewayServer so token auth can be applied to HTTP requests too, returning
401 with WWW-Authenticate header on failure.
2026-02-06 16:51:41 -08:00
William Valentin 0eb1f7a073 feat: add Gemini and Bedrock model providers
Add native GeminiClient using @google/generative-ai SDK and BedrockClient
using @aws-sdk/client-bedrock-runtime. Replace the previous Gemini fallback
(OpenAI-compatible shim) with the real implementation. Add OpenRouter as a
provider option (OpenAI-compatible with custom baseURL). Update model costs,
doctor CLI checks, and client factory tests.
2026-02-06 16:51:32 -08:00
William Valentin e8e4fcd758 docs: update state.json with Docker sandbox and multi-agent routing 2026-02-06 16:04:51 -08:00
William Valentin 4dfa242716 feat: wire Docker sandboxing and agent routing into daemon 2026-02-06 16:04:14 -08:00
William Valentin fecf02acd1 feat: add agents barrel export 2026-02-06 15:58:56 -08:00
William Valentin 0d5601fb13 feat: add SandboxManager for per-session container lifecycle 2026-02-06 15:58:34 -08:00
William Valentin 1314ac0163 feat: add ToolRegistry.clone() and replace() for per-session registries 2026-02-06 15:58:19 -08:00
William Valentin ed1e290ddd feat: add AgentRouter for config-based sender/channel routing 2026-02-06 15:53:50 -08:00
William Valentin 7cb5287ed3 feat: add DockerSandbox class for container lifecycle 2026-02-06 15:53:50 -08:00
William Valentin d65ce078b7 feat: add AgentConfigRegistry for named agent configurations 2026-02-06 15:52:58 -08:00