Skip to content

feat(cli): --offline / JCODE_OFFLINE unified startup network kill switch (#24)#197

Merged
quangdang46 merged 2 commits into
masterfrom
feat/offline-mode
May 22, 2026
Merged

feat(cli): --offline / JCODE_OFFLINE unified startup network kill switch (#24)#197
quangdang46 merged 2 commits into
masterfrom
feat/offline-mode

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

What

Adds the missing 'offline mode' switch requested in issue #24. A single flag (or env var) disables every startup network operation:

  • Update check (src/update.rs::check_for_update_blocking)
  • Install/update telemetry (src/telemetry.rs::is_enabled)
  • Provider model-list refresh
    • OpenAI (should_refresh_openai_model_catalog)
    • Anthropic (should_refresh_anthropic_model_catalog)
    • OpenRouter (begin_background_model_catalog_refresh)

Provider API calls during the session itself are NOT affected — this is strictly about startup-time chatter, mirroring pi-mono's PI_OFFLINE.

Usage

jcode --offline run "hello"     # CLI flag
JCODE_OFFLINE=1 jcode             # env var (works for wrappers)

When active, prints once on startup (suppressed by --quiet):
Offline mode: startup network operations disabled (JCODE_OFFLINE=1).

Changes

  • src/cli/args.rs: offline: bool global flag.
  • src/cli/startup.rs: parse_and_prepare_args translates args.offline || env::var('JCODE_OFFLINE').is_ok() into a single in-process JCODE_OFFLINE=1 env so deep code paths can read it without threading an extra arg. should_spawn_background_update_check short-circuits.
  • src/update.rs: check_for_update_blocking returns Ok(None) immediately, logs "Update check skipped".
  • src/telemetry.rs: is_enabled returns false after the existing JCODE_NO_TELEMETRY / DO_NOT_TRACK checks.
  • src/provider/models.rs: should_refresh_*_model_catalog short-circuit before throttle / cache-fresh checks.
  • src/provider/openrouter.rs: begin_background_model_catalog_refresh short-circuits.

Tests

$ cargo test -p jcode --lib offline
test result: ok. 2 passed; 0 failed
  • update::tests::check_for_update_blocking_returns_none_in_offline_mode
  • telemetry::tests::telemetry_disabled_by_jcode_offline_env

Notes

Future feature work that adds new startup network calls (skill index refresh #16, package update checks #6, extension registry #3) should follow the same pattern: short-circuit at the entry point with if std::env::var("JCODE_OFFLINE").is_ok() { return ... }.

Adds the missing 'offline mode' switch requested in issue #24. A
single flag (or env var) disables every startup network operation:

- Update check (`src/update.rs::check_for_update_blocking`)
- Install/update telemetry (`src/telemetry.rs::is_enabled`)
- Provider model-list refresh
  - OpenAI (`src/provider/models.rs::should_refresh_openai_model_catalog`)
  - Anthropic (`src/provider/models.rs::should_refresh_anthropic_model_catalog`)
  - OpenRouter (`src/provider/openrouter.rs::begin_background_model_catalog_refresh`)

Provider API calls during the session itself are NOT affected — this
is strictly about startup-time chatter, mirroring pi-mono's PI_OFFLINE.

Behavior:
- `--offline` CLI flag, `JCODE_OFFLINE=1` env var. Either sets the
  in-process JCODE_OFFLINE flag in `parse_and_prepare_args`. Pre-set
  env value is honored too.
- Prints a one-line banner on startup unless `--quiet`:
  "Offline mode: startup network operations disabled (JCODE_OFFLINE=1)."
- Each downstream gate logs a `debug`/`info` line when it short-circuits
  so the audit trail is preserved.

Two regression tests:
- `update::tests::check_for_update_blocking_returns_none_in_offline_mode`
- `telemetry::tests::telemetry_disabled_by_jcode_offline_env`

Closes #24
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