Commit Graph

14 Commits

Author SHA1 Message Date
DaiChaoXiong 4ffd82b096 feat(tui): animated working indicator with phase detection
- Braille spinner driven by a per-frame counter, shown in both the status
  bar (bottom) and at the bottom of the message area while a job runs
- phase detection (RunState::working_phase): running tool > thinking >
  streaming > generic, so the hint reads e.g. "⠹ shell: cargo test…"
- testable via the injected clock (tests/state_tests.rs)
2026-08-09 21:43:28 +08:00
DaiChaoXiong 676dc1503e feat(tui): add focus-tui terminal UI
- ratatui + crossterm chat UI: streaming assistant text, multi-line input,
  bottom status bar (model / protocol / session id / context usage)
- thinking blocks collapse to a summary with duration + estimated tokens;
  tool calls collapse to a concrete summary (path / command) + duration;
  click or Tab expands the details
- config modal (/config): provider, OpenAI protocol, baseUrl, apiKey, model,
  contextWindow — persisted to ~/.focus/config.json; session list (/sessions)
  on the harness JSONL tree; /new, /compact, /help
- auto-compaction (80% threshold, no confirmation) + dynamic system prompt
  with usage info run in a background job (fake-provider-testable)
- Esc aborts a run (abandons the job thread; bounded by the provider timeout)
- tests: config codec, summaries/durations/wrap/caret, UI state machine with
  an injected clock, job flow with a fake provider, session persistence
2026-08-09 21:35:58 +08:00
DaiChaoXiong 792f2fae4c docs(workspace): whitelist ratatui/crossterm for focus-tui
Terminal interaction (raw mode, incremental redraw, scrolling, mouse, keys)
is a genuine need that pure std cannot reasonably solve, so AGENTS.md §2.1
now exempts ratatui + crossterm for focus-tui only (transitives follow).
Workspace gains the focus-tui member and the 7-crate layout is documented.
2026-08-09 21:35:58 +08:00
DaiChaoXiong 159f1ca815 docs: state the tests-location rule in AGENTS.md §5.1
All test cases live in tests/<module>_tests.rs and access only public API;
internals are either tested through the public API or promoted to pub. The
sole exception is #[cfg(test)] test infrastructure (e.g. the permissive TLS
config in focus-transport).
2026-08-09 21:09:01 +08:00
DaiChaoXiong f695acc845 refactor(test): move all unit tests from src/ into tests/<module>_tests.rs
Per AGENTS.md §5.1 every test must live under crates/<name>/tests/, so the
inline #[cfg(test)] modules in harness/tools/providers/transport are gone:

- harness: session_tests / compaction_tests / prompt_tests (days_to_ymd made pub)
- tools: read / write / edit / shell tests (Tool trait imported explicitly)
- providers: config_tests; request-body and stop-reason coverage folded into
  integration tests via mock-recorded requests and SSE events (private builders
  no longer tested directly)
- transport: ChunkedDecoder made pub (with Default), decoder tests moved into
  transport_tests.rs

The only #[cfg(test)] left in src/ is the test-only TLS infra in tls.rs.
2026-08-09 21:09:01 +08:00
DaiChaoXiong 7c4c465a18 chore(workspace): sync manifests, docs and lockfile
- drop focus-cli from workspace members; remove tokio from focus-tools and
  focus-harness (sync std I/O); add focus-json to focus-tools
- AGENTS.md: reflect 6-crate layout, focus-cli removal, TUI coming later
- lockfile updated for the new dependency graph
2026-08-09 21:00:04 +08:00
DaiChaoXiong 647cf1ba83 feat(harness): session tree, compaction plans, system prompt templates
- SessionStore/SessionTree: JSONL append-only tree (id + parentId) under
  ~/.focus/sessions, branching and continuation queries
- compaction: lightweight token estimation; scheme D+E plans (summary +
  key-facts, keep recent messages, tool_call/tool_result pairs kept intact);
  auto-trigger threshold (default 80%, configurable); apply_summary writes back
- prompts: system template with cwd/os/date/shell + context occupancy and
  last-turn usage (scheme E); pure-std date formatting
2026-08-09 20:59:59 +08:00
DaiChaoXiong ee165235ec feat(tools): add cross-platform read/write/edit/shell tools
- read: line-range reads, binary detection
- write: overwrite with parent-dir creation
- edit: pi-style exact oldString/newString replacement with occurrence
- shell: bash on Linux, PowerShell (cmd fallback) on Windows; streaming
  line updates via ToolUpdateSink, kill-on-timeout
- sync std I/O consistent with the core Tool trait; no tokio needed
2026-08-09 20:59:54 +08:00
DaiChaoXiong 8ed56c3952 feat(providers): rewrite Anthropic and OpenAI providers
- Anthropic Messages API (2023-06-01) SSE streaming: text/thinking/tool_use
  blocks, cache usage, stop-reason mapping, errors encoded as events
- OpenAI Responses API + Chat Completions (switchable), tool_calls delta
  accumulation, include_usage, reasoning_content -> thinking
- ProviderConfig with base_url/api_key/context_window/timeout; known-model
  context-window table with three-layer resolution
- background current-thread runtime bridges sync agent loop to async I/O
- mock-transport replay tests (chunks straddle SSE boundaries) + full agent
  integration test
2026-08-09 20:59:49 +08:00
DaiChaoXiong 112342c42e feat(core): agent message setters, thinking support, reducer arg-slot fix
- Agent::set_system_prompt / replace_messages (dynamic prompts + compaction)
- ProviderEventReducer::thinking_delta with per-block tracking
- fix: interleaved text/tool-call streams no longer misroute partial args
  (args aligned per content slot; regression tests added)
2026-08-09 20:59:39 +08:00
DaiChaoXiong 7f00886150 feat(transport): add incremental streaming body reader and custom ports
- Transport::stream_request returns a ChunkStream for true SSE streaming
  (head read incrementally, body drained chunk by chunk)
- transparent incremental chunked-transfer decoding (ChunkedDecoder)
- HttpRequest.port for non-standard base_url ports (Host header + TLS connect)
- per-read timeouts on the streaming path
2026-08-09 20:59:33 +08:00
DaiChaoXiong 32b630e440 chore: remove focus-cli and obsolete provider sources
focus-cli is deleted entirely (the TUI will be a new crate later); the old
Anthropic/OpenAI/Zai provider sources and the core mock module are removed as
part of the rewrite.
2026-08-09 20:59:29 +08:00
DaiChaoXiong 5364ca004c ADD: 注释 2026-07-17 11:19:22 +08:00
DaiChaoXiong a7ddba035a INIT 2026-07-16 17:59:16 +08:00