Skip to content

u29dc/cho

Repository files navigation

cho is a Rust workspace for FreeAgent automation: crates/cho-sdk/ owns OAuth, transport, resources, and finance heuristics; crates/cho-cli/ exposes a compact JSON-first command surface; crates/cho-tui/ is a read-first ratatui navigator over the same config, auth, and runtime state.

1. Documentation

2. Repository Structure

.
├── crates/
│   ├── cho-sdk/            reusable FreeAgent client, auth, resource specs, liabilities logic
│   ├── cho-cli/            clap CLI, audit log, output envelopes, command registry, tests
│   └── cho-tui/            ratatui app, route catalog, background fetch worker, cache
├── AGENTS.md               canonical repo-level instructions
├── Cargo.toml              workspace manifest and shared Rust deps/lints
├── package.json            Bun quality gate and release/install wrapper
└── .husky/                 pre-commit and commit-msg hooks

3. Stack

Layer Choice Notes
Workspace Rust 2024 three-crate workspace with shared deps in Cargo.toml
SDK/runtime tokio + reqwest + rustls async transport, pagination, retries, 401 refresh, 429 handling
CLI clap + custom JSON/Toon envelope adapters default stdout is one compact JSON envelope; --toon emits the same structured envelope
TUI ratatui + crossterm direct SDK consumer with background fetch worker and persisted cache
Auth/secrets OAuth code flow + secrecy tokens stored in tokens.json, login callback defaults to 127.0.0.1:53682
JS tooling Bun + Husky + commitlint + Biome hooks, lockfile, and util:* quality orchestration only

4. Commands

  • bun install installs JS tooling and Husky hooks
  • cargo run -p cho-cli -- tools and cargo run -p cho-cli -- tools <name> are the authoritative machine-readable command catalog
  • cargo run -p cho-cli -- health checks home/config/credentials/audit/token readiness before trying real work
  • cargo run -p cho-cli -- --help, cargo run -p cho-cli -- start, and cargo run -p cho-tui are the fastest local iteration paths
  • cargo test --workspace runs all Rust tests; use the crate-specific contract suites when narrowing failures
  • bun run util:check is the required full gate before completion
  • bun run build builds release binaries and installs cho plus cho-tui into ${CHO_HOME:-${TOOLS_HOME:-$HOME/.tools}/cho}/

5. Architecture

6. Runtime and State

  • Home resolution order is CHO_HOME -> TOOLS_HOME/cho -> $HOME/.tools/cho via crates/cho-sdk/src/home.rs
  • Runtime files live outside the repo: config.toml, history.log, tokens.json, and tui-cache.json under the resolved cho home
  • CLI credential precedence is --client-id/--client-secret -> CHO_CLIENT_ID / CHO_CLIENT_SECRET -> config.toml auth.*; SDK base URL precedence is CHO_BASE_URL -> config.toml sdk.base_url -> FreeAgent default
  • auth status, health, CLI bootstrap, and TUI startup all call trusted session checks that can refresh tokens and rewrite tokens.json; these are not read-only inspections
  • TUI route data uses stale-while-revalidate caching in crates/cho-tui/src/cache.rs; preview and full payloads persist to tui-cache.json, oversized cache files are rejected, and stale cached data may be shown while a refresh is in flight
  • Structured mode writes only the selected envelope to stdout; default output is compact JSON, --toon switches the envelope to Toon, and --verbose enables tracing to stderr

7. Conventions

  • cho tools is the authoritative contract surface; crates/cho-cli/tests/cli_contract.rs and crates/cho-cli/tests/cli_drift.rs reject duplicate names, stale help/output metadata, and any reintroduction of the removed --json flag
  • Generic resource writes consume JSON files up to 50 MB, auto-wrap unwrapped payloads under the singular resource key, and support repeated --query key=value pairs for FreeAgent edge cases
  • Bank transaction explanation updates can attach local files; attachments are base64-encoded client-side, MIME-sniffed by extension, and capped at FreeAgent's 5 MB limit
  • Several surfaces are client-composed rather than direct endpoint pass-through: cross-account bank transaction listing, invoice --unpaid-only filtering, grouped category flattening, tax-calendar assembly, HMRC reconciliation, and TUI bank annotations
  • --precise preserves decimal-like JSON values as strings; JSON output also compact-redacts signed company logo URLs instead of dumping volatile query tokens

8. Constraints

9. Validation

  • Required gate: bun run util:check
  • If you change CLI command surface, registry metadata, help text, output envelopes, or write gating, run cargo test -p cho-cli --test cli_contract --test cli_drift and smoke cargo run -p cho-cli -- tools
  • If you change SDK auth, transport, pagination, absolute URL handling, or resource behavior, run cargo test -p cho-sdk --test http_contract
  • If you change TUI routes, fetch context, cache logic, or palette/navigation behavior, run cargo run -p cho-tui and verify startup warnings, palette prompts, stale-cache revalidation, and route refresh with a seeded CHO_HOME
  • For mutating workflows, validate both the default blocked path and an explicit [safety] allow_writes = true path
  • There is no checked-in CI workflow; the local commands above are the completion bar

About

SDK, CLI, and TUI for FreeAgent

Resources

Stars

Watchers

Forks

Contributors

Languages