Skip to content

feat(desktop): pass through ADAL_APP_URL to sidecar for token compression#29158

Open
chindris-mihai-alexandru wants to merge 1 commit into
anomalyco:devfrom
chindris-mihai-alexandru:feat/desktop-compression-proxy
Open

feat(desktop): pass through ADAL_APP_URL to sidecar for token compression#29158
chindris-mihai-alexandru wants to merge 1 commit into
anomalyco:devfrom
chindris-mihai-alexandru:feat/desktop-compression-proxy

Conversation

@chindris-mihai-alexandru
Copy link
Copy Markdown

@chindris-mihai-alexandru chindris-mihai-alexandru commented May 25, 2026

Summary

Pass through ADAL_APP_URL environment variable to the sidecar process, enabling AdaL CLI's token compression proxy to transparently reduce token usage for Desktop users.

What type of PR is this?

Feature (non-breaking addition)

What this PR does

When the user has ADAL_APP_URL set in their environment, the Desktop app now forwards it to the sidecar process. This enables the adal-compress token compression proxy to intercept and compress LLM requests before they reach providers.

Security hardening: Only localhost/loopback URLs are accepted (http://localhost, http://127.0.0.1, http://[::1]). Any non-local URL is rejected with a tracing::warn log to prevent unintended traffic routing.

Implementation: Uses std::env::var_os for robustness with non-UTF8 edge cases, then validates and converts to a known-good UTF-8 string before pushing to the env vec.

Context: What is ADAL_APP_URL?

AdaL is a coding agent built on top of OpenCode. It uses a transparent compression proxy (adal-compress) that sits between the CLI/Desktop sidecar and the backend API:

Sidecar → [adal-compress proxy on localhost] → adal.sylph.ai → LLM Provider
                     ↓
          Compresses messages:
          - Strips natural language filler (~40% savings)
          - Compresses tool outputs like git diff, npm install (~60-99%)
          - Deduplicates repeated system prompts
          - Compresses tool schemas (~70-97%)

The proxy is inspired by Caveman (37k+ ★) and achieves 30-70% token savings while preserving all code, paths, URLs, and technical content.

Current issue: The Desktop sidecar doesn't reliably inherit ADAL_APP_URL because:

  • macOS apps launched from Dock/Spotlight don't get shell profile exports
  • The load_shell_env probe is best-effort and can timeout or fail
  • Users have no other way to configure sidecar-level env vars

Why this benefits OpenCode broadly

While ADAL_APP_URL is the immediate use case, this pattern enables any localhost middleware for the sidecar:

  • Token compression proxies (AdaL, Caveman-shrink)
  • Request logging/debugging middleware
  • Rate limiting or cost control proxies
  • Custom routing/load balancing

This is consistent with how OPENCODE_PORT and other env vars are already passed through.

Testing

  • Verified env var propagates to sidecar process environment
  • No behavioral change when ADAL_APP_URL is unset (existing path unchanged)
  • Non-localhost URLs are rejected with warning log
  • WSL path also benefits since it reads from the same envs vec
  • Non-UTF8 values handled gracefully (skipped silently)

Risk

  • None when unset: the if let Some(...) pattern is a no-op
  • None for non-localhost: explicitly rejected with log warning
  • Minimal when set to localhost: sidecar routes through specified local proxy

Related issues


🌸 Generated with AdaL

Copilot AI review requested due to automatic review settings May 25, 2026 02:48
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for forwarding an ADAL_APP_URL environment variable from the desktop app to the sidecar process so LLM requests can be routed through a compression proxy.

Changes:

  • Detect ADAL_APP_URL in the parent process environment.
  • Forward ADAL_APP_URL to the sidecar process environment when present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +392 to +397
// Pass through token compression proxy URL to the sidecar process.
// When ADAL_APP_URL is set (e.g., by adal-compress proxy), the sidecar
// routes LLM requests through the proxy for transparent compression.
if let Ok(app_url) = std::env::var("ADAL_APP_URL") {
envs.push(("ADAL_APP_URL".to_string(), app_url));
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in force-push. Now validates that only localhost/loopback URLs are accepted:

if url_str.starts_with("http://localhost")
    || url_str.starts_with("http://127.0.0.1")
    || url_str.starts_with("http://[::1]")

Non-local URLs are rejected with tracing::warn. This prevents any env injection from routing sensitive traffic externally.

HTTPS enforcement was considered but intentionally omitted — localhost proxies typically run plain HTTP (TLS adds complexity for loopback with no security benefit since traffic never leaves the machine).

Comment thread packages/desktop/src-tauri/src/cli.rs Outdated
Comment on lines +395 to +396
if let Ok(app_url) = std::env::var("ADAL_APP_URL") {
envs.push(("ADAL_APP_URL".to_string(), app_url));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in force-push. Now uses std::env::var_os + .to_str() validation:

if let Some(app_url) = std::env::var_os("ADAL_APP_URL") {
    if let Some(url_str) = app_url.to_str() {
        // validate and push
    }
}

Non-UTF8 values are silently skipped (no panic, no lossy conversion). Since the sidecar expects a valid URL string, non-UTF8 values would be invalid anyway — skipping is the correct behavior.

…sion

When ADAL_APP_URL is set in the user's environment, the Desktop app
now passes it through to the sidecar process. This allows transparent
token compression proxies to intercept LLM requests.

Security: Only localhost/loopback URLs are accepted (http://localhost,
http://127.0.0.1, http://[::1]). Non-local URLs are rejected with a
warning log. Uses var_os for robustness with non-UTF8 edge cases.

No behavioral change when ADAL_APP_URL is unset.

Co-Authored-By: AdaL <adal@sylph.ai>
@chindris-mihai-alexandru chindris-mihai-alexandru force-pushed the feat/desktop-compression-proxy branch from 6b0bd29 to 85e6b12 Compare May 25, 2026 02:57
Copy link
Copy Markdown
Author

@chindris-mihai-alexandru chindris-mihai-alexandru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressing Copilot feedback

High: URL validation / traffic interception risk

Fixed in force-push. Now only localhost/loopback URLs are accepted:

  • http://localhost*
  • http://127.0.0.1*
  • http://[::1]*

Any non-local URL is rejected with a tracing::warn log. This prevents environment injection from routing LLM traffic to external endpoints.

Low: std::env::var vs var_os

Fixed in force-push. Now uses std::env::var_os + .to_str() check, so non-UTF8 values are handled gracefully (silently skipped) rather than causing a panic or silent drop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants