Skip to content

feat(translate): add text-mode Kagi Translate support#8

Merged
Microck merged 8 commits intomainfrom
feat/translate-session-http
Mar 19, 2026
Merged

feat(translate): add text-mode Kagi Translate support#8
Microck merged 8 commits intomainfrom
feat/translate-session-http

Conversation

@Microck
Copy link
Owner

@Microck Microck commented Mar 18, 2026

Summary

  • add kagi translate for Kagi Translate text mode
  • bootstrap translate_session from the existing KAGI_SESSION_TOKEN
  • return one JSON envelope with detection, translation, alternatives, alignments, suggestions, and word insights
  • add translate docs clarifying the default --from auto --to en behavior
  • add a recorded terminal demo to the README and docs
  • harden translate validation and output metadata before review
  • refactor translate bootstrap to use the same pure-Rust HTTP stack as the rest of the CLI

Implementation

  • normalize Session Link values at runtime for env and config auth
  • bootstrap translate auth by fetching https://translate.kagi.com/ with reqwest and extracting translate_session from Set-Cookie
  • call direct HTTP endpoints for detect, translate, and the text-mode auxiliary sections
  • stabilize the translate envelope by always backfilling translation.source_language and translation.target_language
  • reject invalid kagi translate --to auto requests with a config error before hitting the backend
  • downgrade optional-section failures into warnings while keeping the core translation result
  • add translate-focused unit tests plus ignored live tests gated by KAGI_SESSION_TOKEN
  • document the command, auth matrix, output contract, error cases, and demo workflow
  • add scripts/demo-translate.sh and ship generated GIF assets for docs previews
  • make the existing demo scripts directly executable by the documented asciinema rec -c ./scripts/demo-*.sh flow
  • remove the temporary python3 + curl_cffi runtime dependency and revert the extra Tokio process feature

Verification

  • cargo test
  • cargo test live_translate -- --ignored --nocapture
  • cargo build
  • ./target/debug/kagi translate "Bonjour tout le monde"
  • ./target/debug/kagi translate "Bonjour tout le monde" --no-alternatives --no-word-insights --no-suggestions --no-alignments
  • ./target/debug/kagi translate "Bonjour tout le monde" --to auto
  • ./scripts/demo-translate.sh
  • asciinema rec --overwrite -c ./scripts/demo-translate.sh -q -i 0.2 --cols 92 --rows 22 /tmp/kagi-demos/translate.cast
  • agg --theme asciinema --font-size 14 --idle-time-limit 2 --last-frame-duration 4 /tmp/kagi-demos/translate.cast docs/demo-assets/translate.gif

Notes

  • scope is text mode only
  • translate now uses reqwest end-to-end rather than a Python bootstrap helper

Microck added 2 commits March 18, 2026 18:19
Add a new kagi translate command that bootstraps translate.kagi.com from the existing session token, then calls detect, translate, alternatives, alignments, suggestions, and word insights over direct HTTP.

Document the new command, update auth and coverage references, and note the current runtime dependency on python3 plus curl_cffi for bootstrap.
@Microck Microck merged commit 01e904d into main Mar 19, 2026
6 checks passed
@Microck Microck deleted the feat/translate-session-http branch March 19, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant