Skip to content

CLI auth (PAT/device) + direct-to-org-database data plane - #1

Merged
sagnik11 merged 10 commits into
mainfrom
handle-auth
Jun 17, 2026
Merged

CLI auth (PAT/device) + direct-to-org-database data plane#1
sagnik11 merged 10 commits into
mainfrom
handle-auth

Conversation

@sagnik11

@sagnik11 sagnik11 commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

This branch finishes CLI ↔ platform authentication and reworks how the CLI persists data, removing the intermediate data-plane backend entirely.

Authentication

  • OAuth 2.0 device-authorization flow + token refresh against autter.dev.
  • Personal Access Tokens (autter login --token autter_pat_…) for non-interactive/CI sign-in, with per-org token minting and repo→org resolution.
  • JWT verification/decoding hardening and JWKS URL fixes.

Direct-to-org-database data plane (no more CLI backend)

The CLI now writes authorship notes, prompt transcripts (CAS), and usage metrics straight to each organization's own Postgres, using the org_db_url claim already carried in the signed access token. The previous pass-through server/ crate is deleted.

  • New src/api/org_db.rs: decode org_db_url/identity from the token, cached TLS connection per org DB, schema auto-creation (authorship_notes, cas_objects, cli_audit_log, cli_metrics), and the upsert/read/audit logic the server used to do.
  • upload_notes / read_notes / upload_cas / metrics upload now write to the org DB; data.push audit rows are written by the CLI.
  • Removed the server/ crate, the obsolete notes-backend-spec.md, and the in-memory reference HTTP backend (notes serve).

Editor extension install fix

  • When an editor's marketplace can't resolve the extension by ID (e.g. Cursor resolves against the MS Marketplace, not Open VSX), onboarding now falls back to downloading the .vsix from Open VSX and installing from the local file — works across VS Code / Cursor / Windsurf / VSCodium.
  • Publish workflow now derives the extension version from the vscode-v* tag so the tag and published version can't drift.

Testing

Verified end-to-end against a real org's Neon Postgres from a clean install: authorship notes, ~2k usage-metric rows, and data.push audit rows all landed via the direct connection (TLS + schema auto-create confirmed); the CLI's own upload queue reported synced=1 with no errors.


Created with PostHog Code

Summary by CodeRabbit

  • New Features

    • Personal Access Token (PAT) login for simplified, non-interactive authentication.
    • Organization-scoped database backend enabling seamless multi-org data management.
  • Improvements

    • Streamlined sign-in flow with browser-based token generation and dashboard integration.
    • VS Code extension installation with automatic fallback to Open VSX package registry.
    • Comprehensive documentation updates covering authentication methods and local/cloud configuration options.

sagnik11 added 9 commits June 16, 2026 17:15
- Added workspace configuration to include the CLI and backend in a single workspace for better data contract visibility.
- Set default members to optimize build times, allowing for explicit backend builds when needed.
- Updated resolver version to 3.
- Updated Cargo.lock to include new dependencies such as `async-trait`, `atoi`, `autter-server`, and others, enhancing the project's capabilities.
- Added `BadRequest` variant to `AppError` enum in `error.rs`, marked as dead code for future use in API handling.
- Integrated Better Auth JWT verification into the server, allowing for stateless identity management via JWKS.
- Updated `Cargo.toml` to include new dependencies: `jsonwebtoken`, `reqwest`, and `base64` for handling JWTs and HTTP requests.
- Refactored database interactions to support per-organization PostgreSQL databases, utilizing the `org_db_url` claim from the JWT.
- Revised the schema in `0001_init.sql` to remove organization-specific tables, as each organization now has its own database.
- Updated README to reflect changes in identity and routing mechanisms, clarifying the role of autter.dev as the identity/control plane.
- Enhanced error handling and logging for better traceability during authentication processes.
- Revised the JWKS URL in the documentation to reflect the correct endpoint for token signing keys.
- Made the `resolve_hostname` function public to allow access from other modules.
- Improved device metadata reporting in the OAuth device flow to include hostname and OS information.
- Added `token_id` field to `Claims` and `Identity` structs for tracking Personal Access Token (PAT) usage in audit logs.
- Implemented audit logging for batch uploads in `cas.rs` and per-commit uploads in `notes.rs` to improve traceability of data pushes.
- Introduced `exchange_pat` method in `OAuthClient` for validating PATs during login, enhancing the login experience with a new `--token` option.
- Updated command handling in `login.rs` to support a two-step PAT login process, improving user guidance for token creation and usage.
- Introduced in-process caching for organization resolution and access tokens associated with Personal Access Tokens (PATs).
- Added methods to load and validate stored PATs, enabling organization-specific token minting and routing for note uploads.
- Enhanced the notes database schema to include a `repo_url` field, allowing notes to be associated with their originating repository for better organization routing.
- Updated the HTTP backend to support repository-specific note writing, improving the accuracy of note uploads to the correct organization.
- Refactored login handling to display user and organization information upon successful PAT login, enhancing user feedback during authentication.
- Deleted the `autter-server` package and its associated files, as the backend functionality is no longer required.
- Updated `Cargo.toml` to reflect the removal of the server dependencies and adjusted workspace settings accordingly.
- Enhanced the README to clarify the new architecture, emphasizing direct database interactions from the CLI.
- Removed outdated documentation related to the server's HTTP contract and database schema.
- Updated `Cargo.lock` to remove references to the deleted server dependencies.
Metrics previously POSTed to a `/worker/metrics/upload` endpoint that no
longer exists. Write them straight to each org's own Postgres instead,
matching the notes/CAS data path:

- New `cli_metrics` table (auto-created on connect) stores each event with
  its sparse `values`/`attrs` as JSONB, plus a content-hash `dedup_key` so
  re-flushing the local SQLite queue after a partial failure can't duplicate.
- `org_db::insert_metrics` writes the batch and returns per-event errors.
- `ApiClient::upload_metrics` decodes `org_db_url` from the access token and
  calls into `org_db`; the daemon flush and `flush-metrics-db` now gate on
  being logged in (an API key alone can't carry `org_db_url`).

Generated-By: PostHog Code
Task-Id: 257180bd-77bd-4424-a821-2c67c3a3fa8a
`autter onboard` installs the extension by ID (`autter.autter-vscode`),
which only resolves if the editor's marketplace carries it. Cursor and VS
Code resolve IDs against the Microsoft Marketplace, where the extension
isn't published, so the install failed with "Extension not found" even
though it's on Open VSX.

Add a fallback: when the ID-based install fails, download the .vsix from
Open VSX and install from the local file (every VS Code-family editor
accepts a local .vsix), so onboarding works regardless of which gallery an
editor uses. Wired into the Cursor, Windsurf, and VS Code installers.

Also fix the publish workflow to derive the extension version from the
`vscode-v*` tag (the tag and package.json had drifted: tag 0.1.23 but
package.json 0.1.22, so the "0.1.23" release published 0.1.22), and bump
package.json to 0.1.23 to match.

Generated-By: PostHog Code
Task-Id: 257180bd-77bd-4424-a821-2c67c3a3fa8a
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR migrates the CLI's notes, CAS, and metrics API calls from HTTP worker endpoints to direct per-org PostgreSQL writes via a new src/api/org_db.rs module that decodes JWT routing claims. It adds PAT-based login with org-scoped token caching, propagates repo_url through the local notes queue for per-org routing in the telemetry worker, removes the in-memory reference server, and adds an Open VSX VSIX fallback installer with a publish CI workflow.

Changes

Org DB Data-Plane Migration

Layer / File(s) Summary
org_db module: identity, connection pool, and CRUD
src/api/org_db.rs, src/api/mod.rs
New module decodes JWT org_db_url into OrgIdentity, manages a global TLS connection cache with schema provisioning, and implements upsert_notes, read_notes, upsert_cas, read_cas, and insert_metrics with best-effort audit logging. Unit tests cover JWT decoding edge cases.
PAT & org-scoped token caching
src/auth/client.rs, src/auth/identity.rs, src/api/client.rs
OAuthClient gains exchange_pat, exchange_pat_for_org, and resolve_org_for_repo; TokenIdentity gains active_org_id and active_org(); src/api/client.rs adds in-process repo→org and org→token caches with resolve_org_for_repo_cached, access_token_for_org, and ApiClient::org_identity().
PAT login command, config URL defaults, onboard mode
src/commands/login.rs, src/config.rs, src/commands/onboard.rs, src/commands/autter_handlers.rs, src/commands/notes_migrate.rs, README.md
Adds run_pat_login, --token argument parsing, web URL derivation helpers, and updated handle_login flow; introduces DEFAULT_NOTES_BACKEND_URL, updates DEFAULT_API_BASE_URL, reworks notes_backend_url() precedence; switches connected-mode onboard to Http notes backend; updates help text and README docs.
API clients migrated from HTTP to org_db
src/api/notes.rs, src/api/cas.rs, src/api/metrics.rs
upload_notes, read_notes, upload_cas, read_ca_prompt_store, and upload_metrics are rewritten to call org_identity() then the corresponding org_db function, removing all HTTP request/response handling.
Notes local DB schema v2: repo_url column
src/notes/db.rs, src/git/notes_api.rs
Schema bumped to v2 with a migration adding repo_url; PendingNote extended; upsert_note_with_repo and upsert_notes_batch_with_repo added; HTTP backend note helpers updated to accept and persist repo_url; tests updated.
Telemetry worker: per-org note routing and auth gating
src/daemon/telemetry_worker.rs, src/commands/flush_metrics_db.rs
flush_notes groups pending notes by resolved owning org and uploads each group with an org-scoped token; flush_metrics and flush_cas gate on is_logged_in() and HTTP-backend URL respectively; handle_flush_metrics_db simplified to skip when not logged in.
Remove in-memory reference server and HTTP spec docs
src/notes/reference_server.rs, src/notes/mod.rs, docs/notes-backend-spec.md, Cargo.toml, AGENTS.md
Deletes reference_server.rs (521 lines), removes its module export, deletes the HTTP notes backend spec doc, adds Cargo workspace config and Postgres/base64 dependencies, and removes the notes serve handler from the CLI.

VS Code VSIX Fallback and Publish Workflow

Layer / File(s) Summary
Open VSX VSIX fallback utility and agent wiring
src/mdm/utils.rs, src/mdm/agents/cursor.rs, src/mdm/agents/vscode.rs, src/mdm/agents/windsurf.rs
Adds install_vsc_editor_extension_with_vsix_fallback that downloads from Open VSX on ID-install failure; all three agent installers are updated to call this function.
VS Code extension publish workflow and version bump
.github/workflows/publish-vscode-extension.yml, agent-support/vscode/package.json
New workflow triggers on vscode-v* tags, syncs version, packages and publishes to Open VSX and conditionally the VS Code Marketplace, and uploads the .vsix artifact; extension version bumped to 0.1.23.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as autter CLI
  participant OAuthClient
  participant CredentialStore
  participant org_db
  participant PostgreSQL

  User->>CLI: autter login --token <PAT>
  CLI->>OAuthClient: exchange_pat(pat)
  OAuthClient-->>CLI: StoredCredentials
  CLI->>CredentialStore: save credentials
  CLI->>CLI: extract TokenIdentity (active_org_id)
  CLI-->>User: signed in as <user> / org <org>

  User->>CLI: autter notes migrate (or telemetry flush)
  CLI->>org_db: identity_from_token(access_token)
  org_db-->>CLI: OrgIdentity{org_db_url}
  CLI->>org_db: upsert_notes / upsert_cas / insert_metrics
  org_db->>PostgreSQL: connect (TLS) + provision schema
  org_db->>PostgreSQL: execute upsert with ON CONFLICT
  org_db->>PostgreSQL: record_push (audit log)
  PostgreSQL-->>org_db: result rows
  org_db-->>CLI: NotesUploadResponse / CasUploadResponse / failures
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Poem

🐇 Hop, hop, no more HTTP hops to make,
Direct to Postgres now, for data's sake!
PAT tokens cached, org routed right,
The reference server sleeps—a VSIX takes flight.
From Open VSX we fetch, if IDs fail,
A bunny's CI workflow never goes stale!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main architectural changes: CLI authentication (PAT/device flow) and direct-to-org-database data plane, matching the core objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch handle-auth

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

The repo doesn't use Devin (CodeRabbit is the active review bot), so the
"wait for and address Devin feedback" instruction no longer applies. Keep
the CI-monitoring guidance; remove the Devin-specific parts.

Generated-By: PostHog Code
Task-Id: 257180bd-77bd-4424-a821-2c67c3a3fa8a
@sagnik11
sagnik11 merged commit 18acced into main Jun 17, 2026
1 check was pending
@sagnik11
sagnik11 deleted the handle-auth branch June 23, 2026 17:35
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