Commit Graph

236 Commits

Author SHA1 Message Date
William Valentin d39d3ac367 docs: add Google Calendar section and new-tool checklist
Add GCal tools setup guide to README (prerequisites, config, fields).
Add gmail-auth, gcal-auth, setup to the CLI commands table. Add
"Adding a New Tool" checklist to CLAUDE.md covering the full wiring
chain including the TUI registration gotcha.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 11:51:56 -08:00
William Valentin f6dedf0fbe fix(tui): register Google Calendar tools when gcal is enabled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 11:45:05 -08:00
William Valentin 55d35c80b4 feat(tui): improve tool use display and register Gmail tools
Format tool names as human-readable labels (e.g. "Gmail: List") and
show args as compact key-value pairs instead of raw JSON. Also register
Gmail tools in the TUI when automation.gmail is enabled.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 11:41:35 -08:00
William Valentin 796e143d61 fix(agent): inject tool inventory note when tools change mid-session
Stale session history can cause the model to follow old "I can't do
that" patterns even when new tools are available. NativeAgent now tracks
a tool fingerprint and appends a system prompt note listing current
tools when the inventory changes, resetting on session reset.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 11:41:31 -08:00
William Valentin 94264e848c feat(tools): add Google Calendar tools and register Gmail/GCal in daemon
Add calendar.today, calendar.list, calendar.search tools mirroring the
Gmail tool pattern. Includes gcal-auth CLI command, config schema, tool
policy entries (messaging/coding profiles + group:gcal), and 17 tests.
Also wires up gmail and gcal tool registration in the daemon and TUI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 11:40:53 -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 ff03f74404 feat(cli): add gmail-auth command for OAuth2 token setup
Implements `flynn gmail-auth` to complete the OAuth2 flow that
GmailWatcher references but was never built. Supports local callback
server (default) and --manual paste mode. Adds Gmail health check
to `flynn doctor`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 10:33:01 -08:00
William Valentin f4b9c850ab feat(setup): add contextual help text to all wizard flows
Each setup section now explains what's needed before prompting:
- Providers: links to API key consoles (Anthropic, OpenAI, Gemini, etc.)
- Channels: step-by-step bot creation (Telegram @BotFather, Discord dev
  portal, Slack app setup, WhatsApp QR)
- Gmail: Google Cloud Console OAuth setup walkthrough
- Memory: explains what vector search does and key reuse
- Security: describes each option (sandbox, pairing, tool profiles)
- Gateway: explains auth token, Tailscale Serve, lock mode

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 10:08:44 -08:00
William Valentin f9446a4d67 docs: update gap analysis and state.json for setup wizard
Mark onboard wizard as MATCH (100/128, 78%). Update test count to 1151.
Add setup-wizard plan entry to state.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:44:52 -08:00
William Valentin 7620616c7c test(setup): add integration tests and update shell completion
Adds comprehensive integration tests for the first-run wizard verifying config
generation for different provider/channel combinations. Updates shell completion
to include the 'setup' command with its options.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:38:53 -08:00
William Valentin f50d7d69fb feat(setup): wire setup command into CLI and start command
- Register setup command in CLI index
- Offer setup wizard when running `flynn start` with no config
- Guard telegram log output since telegram is now optional

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:36:58 -08:00
William Valentin d8b7b08270 feat(setup): add main orchestrator, menu, and CLI command
Implements Task 6 of the setup wizard:
- orchestrator.ts: runMenu() for interactive configuration loop
- orchestrator.ts: runFirstRunWizard() for new user onboarding
- orchestrator.test.ts: test for menu exit behavior
- setup.ts: registerSetupCommand() and runSetup() handler
  - Handles both first-run and existing config scenarios
  - Saves YAML config to disk
  - Optional daemon startup after first-run

All tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:35:32 -08:00
William Valentin 182d86957b feat(setup): add memory, automation, security, and gateway setup flows 2026-02-10 09:34:04 -08:00
William Valentin b673632b0f feat(setup): add channel setup flows
Implement setupChannels function with support for Telegram, Discord, Slack, and WhatsApp.
Includes WebChat gateway configuration and channel choice loop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:32:52 -08:00
William Valentin 573cb43534 feat(setup): add model provider setup flows 2026-02-10 09:31:43 -08:00
William Valentin d35ce2beb5 feat(setup): add config builder and summary renderer
Add ConfigBuilder class to accumulate wizard answers into config objects with YAML
serialization, and renderSummary function to display configuration summary. Includes
9 test cases covering provider setup, channel configuration, and feature flags.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:29:56 -08:00
William Valentin 9cc03187b0 feat(setup): add prompt helpers for setup wizard
Created a Prompter interface and factory function for interactive CLI prompts:
- ask(): text input with optional default values
- confirm(): yes/no confirmation with default
- choose(): numbered menu selection with fallback
- password(): text input (no echo planned in TUI)
- println(): simple output helper

All 9 tests pass (ask, confirm, choose, password scenarios).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:28:19 -08:00
William Valentin 213dba855a refactor: make telegram config optional for non-telegram setups
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:27:18 -08:00
William Valentin 48fab11066 docs: add setup wizard implementation plan
9 tasks with TDD approach: prompt helpers, config builder, provider/channel
flows, menu sections, orchestrator, CLI wiring, integration tests. ~29 new
tests, 13 new files, 0 new dependencies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:19:21 -08:00
William Valentin 6b426a1e52 docs: add setup wizard design
Interactive setup wizard with two entry points: auto-trigger on
first run (no config detected) and explicit `flynn setup` command.
Minimal-first flow for quick start, menu-driven for reconfiguration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:14:45 -08:00
William Valentin bab3f26ef6 docs: update pairing docs with SQLite persistence and TUI execution details 2026-02-09 22:09:30 -08:00
William Valentin 99b7e743f4 docs: update state.json with pairing persistence and TUI wiring 2026-02-09 22:05:21 -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 62331c3a09 feat(daemon): wire PairingStore from SessionStore into PairingManager 2026-02-09 21:49:55 -08:00
William Valentin ecd3aca7c1 feat(session): add pairing_approved table and getPairingStore() 2026-02-09 21:46:51 -08:00
William Valentin 1e1a68924e feat(pairing): add PairingStore interface for persistence injection 2026-02-09 21:45:04 -08:00
William Valentin c3ca3f3776 feat(03-02): extend dashboard with live ops sections
- Core counters: messages processed, sessions, queue depth, uptime, active requests, errors
- Model performance table: recent calls with latency, tokens/sec, provider, status
- Event stream: scrollable log with color-coded levels (error/warn/info)
- Active requests: in-flight request table with session, channel, duration
- Channels grid: existing channel status cards preserved
- Dual timer refresh: 3s for metrics/events/requests, 10s for health/channels
- Targeted DOM updates via getElementById for flicker-free fast updates
2026-02-09 21:34:11 -08:00
William Valentin 7065b5e650 docs: update state.json with 03-01 metrics backend completion
- Test count: 1087 → 1107
- Added operator_dx_milestone tracking
- Updated next_up with GSD phase 3 status
2026-02-09 21:31:30 -08:00
William Valentin 982dcee5e0 docs(03-01): complete metrics collection backend plan
- SUMMARY.md with task commits, decisions, self-check
- STATE.md updated: phase 3 in_progress, 1/2 plans, test count 1107
2026-02-09 21:31:07 -08:00
William Valentin a0feff9637 feat(03-01): hook metrics recording into agent request flow
- Track active requests with startRequest/endRequest around lane queue work
- Increment messagesProcessed on successful agent.process completion
- Record errors and error events on agent.send failures
- Record tool failure events with tool name and error details
2026-02-09 21:29:14 -08:00
William Valentin bd1880a44c feat(03-01): create MetricsCollector and wire into gateway
- Add MetricsCollector class with counters, model call ring buffer, event ring buffer, and active request tracking
- Add system.metrics, system.events, system.activeRequests RPC handlers
- Add GET /health unauthenticated HTTP endpoint for Docker HEALTHCHECK
- Add totalPending() to LaneQueue for queue depth metrics
- Add 20 tests for MetricsCollector
2026-02-09 21:28:05 -08:00
William Valentin 7565d55551 docs: update state.json with log-level system feature 2026-02-09 21:23:57 -08:00
William Valentin 35f4cab0dc feat: add log-level system to suppress noisy fallback debug output
Replace console.debug/log/warn calls in model router, retry, and daemon
startup with a structured logger that respects a configurable log_level.
Default level is 'info', suppressing verbose fallback debug messages in
the TUI while keeping them available via config when needed.

- Add src/logger.ts with debug/info/warn/error/silent levels
- Wire log_level into config schema (default: 'info')
- Initialize log level in both daemon and TUI startup paths
- Convert all console.debug in router.ts and retry.ts to logger.debug
- Convert console.log/warn in daemon/models.ts to logger.info/warn
2026-02-09 21:23:07 -08:00
William Valentin 94946eb7a8 docs(03): create phase plan for live ops dashboard 2026-02-09 21:10:03 -08:00
William Valentin fa4d6a057b docs(phase-02): complete phase execution 2026-02-09 21:04:06 -08:00
William Valentin 53d075538e docs(02-02): complete doctor overlay validation plan
- SUMMARY.md with task commit, decisions, metrics
- STATE.md: Phase 2 complete (2/2 plans), ready for Phase 3
2026-02-09 21:01:29 -08:00
William Valentin 6bd372162e feat(02-02): add overlay file validation to flynn doctor
- Import resolveOverlayPath from shared.ts
- Add checkOverlayExists check (skip when no FLYNN_ENV, pass/fail for overlay file)
- Insert after checkConfigExists in allChecks array
- All 1087 tests pass, typecheck clean
2026-02-09 21:00:18 -08:00
William Valentin 19287c4cad docs(02-01): complete core overlay merge plan
- SUMMARY.md with 2 task commits, 10 new tests, 3 min duration
- STATE.md updated: Phase 2 in_progress, 02-01 done
- ROADMAP.md updated: 02-01 checked off
2026-02-09 20:58:52 -08:00
William Valentin 29bc18502f feat(02-01): wire FLYNN_ENV resolution into shared.ts with overlay-aware loadConfigSafe
- Add resolveOverlayPath() that maps FLYNN_ENV to {configDir}/{env}.yaml
- Update loadConfigSafe to pass overlay path through to loadConfig
- All CLI commands using loadConfigSafe() automatically get overlay support
- No FLYNN_ENV = exact same behavior as before (backward compatible)
- Full test suite passes (1087 tests, zero regressions)
2026-02-09 20:57:12 -08:00
William Valentin c2cc052694 feat(02-01): implement deepMerge and overlay-aware loadConfig with tests
- Add deepMerge utility for recursive object merging (arrays replace, not concat)
- Extend loadConfig with optional overlayPath parameter
- Merge happens before env var expansion and Zod validation
- Add 6 deepMerge unit tests and 4 overlay integration tests
- Re-export deepMerge from config/index.ts
- All 1087 existing tests still pass
2026-02-09 20:56:29 -08:00
William Valentin 00b1716418 docs(02-config-overlays): create phase plan 2026-02-09 20:44:03 -08:00
William Valentin d72a04ef99 docs(phase-01): complete phase execution — verification passed 2026-02-09 20:32:24 -08:00
William Valentin 24688d1a16 docs(01-03): complete daemon composition root plan — Phase 1 done
- Created 01-03-SUMMARY.md with self-check passed
- Updated STATE.md: Phase 1 complete, 3/3 plans done
- Updated ROADMAP.md: Phase 1 marked complete
- daemon/index.ts: 1087 → 140 lines (87% reduction)
- All 1077 tests pass, zero type errors
2026-02-09 20:25:39 -08:00
William Valentin 701fcfcaed refactor(01-03): extract services/skills/gateway/mcp into services.ts, reduce index.ts to 140 lines
- Extract initSkills(), initMcp(), loadSystemPrompt(), initPairingManager(), createGateway(), startServices() into services.ts
- daemon/index.ts reduced from 386 to 140 lines (64% reduction, 87% from 1087 baseline)
- Organize imports with section comments (External, Config, Daemon Modules, Infrastructure)
- Add section dividers in startDaemon() (Data & Sessions, Core Services, Model & Prompt, Gateway & Channels, Tier 1 Tools, Lifecycle)
- Convert unused value imports to type-only imports
- DaemonContext interface and re-exports unchanged
2026-02-09 20:22:34 -08:00
William Valentin 688f7a5154 docs(01-02): complete channel/agent/routing extraction plan
- Add 01-02-SUMMARY.md with task commits, deviations, decisions
- Update STATE.md: 2/3 plans complete, daemon/index.ts at 385 lines (-65%)
2026-02-09 20:15:54 -08:00
William Valentin 37901e3c20 docs(01-01): complete extract-models-memory-tools plan
- SUMMARY.md documenting 3 tasks, 3 commits, 9min duration
- STATE.md updated: plan 1/3 complete, metrics, decisions, technical notes
2026-02-09 20:15:17 -08:00
William Valentin 35a0061de9 feat(01-02): extract channel adapter registration into src/daemon/channels.ts
- Move Telegram, Discord, Slack, WhatsApp, WebChat adapter setup to channels.ts
- Move CronScheduler, WebhookHandler, GmailWatcher registration to channels.ts
- Clean up index.ts imports (remove unused adapter value imports)
- index.ts calls registerChannels() and receives cronScheduler for tool wiring
2026-02-09 20:14:23 -08:00
William Valentin fb1199a1da refactor(01-01): extract tool registration into src/daemon/tools.ts
- Create initTools() factory encapsulating ToolRegistry, allBuiltinTools, web search tools, ProcessManager, BrowserManager, ToolExecutor, and ToolPolicy
- Replace ~70 lines of inline tool setup in startDaemon() with single initTools() call
- Clean up tool-specific imports from daemon/index.ts (ToolPolicy, allBuiltinTools, createWebSearchTools, createProcessTools, ProcessManager, createBrowserTools)
- Tier 1 agent tools (session, agents list, message send, cron) remain in daemon/index.ts as intended
- daemon/index.ts reduced to 457 lines (from 1088 baseline)
2026-02-09 20:12:46 -08:00