authsome icon indicating copy to clipboard operation
authsome copied to clipboard

feat: Add authsome onboard command combining init and credential scan/import

Open manojbajaj95 opened this issue 5 months ago • 0 comments

Summary

Add a single authsome onboard command that performs first-time setup end-to-end: initialize local identity, complete daemon registration/claim, then scan for existing API keys and import them into the vault.

Today this requires two separate steps (authsome init then authsome scan --import), which is awkward for new users and agent quick-start flows.

Current state

authsome init (src/authsome/cli/commands/core.py)

  1. RuntimeIdentity.ensure_local(home) — create local Ed25519 identity files under ~/.authsome/identities/.
  2. ensure_identity_ready() (src/authsome/cli/client.py) — register handle+DID with daemon; if claim_required, open claim URL and poll until claimed.
  3. Print JSON: handle, DID, encryption mode, etc.

Does not import credentials.

authsome scan (src/authsome/cli/commands/core.py)

  1. _scan_env_sources() (src/authsome/cli/helpers.py) — read .env, .env.local, .env.* variants, and process environment.
  2. Match values against bundled/custom API key providers (auth_type == API_KEY only — OAuth providers skipped).
  3. Default: drift report only (env_only, authsome_only, env_and_authsome_match, etc.).
  4. With --import: call start_login + resume_login_session per provider to store keys in the encrypted vault.

Requires vault access — claim must be accepted before import succeeds. Running scan --import before init/claim will fail or be incomplete.

Documentation today

  • docs/site/installation.mdx — documents init separately.
  • docs/site/reference/cli.mdx — documents scan and --import separately.
  • README quick start points to skill install, not a unified onboard path.

Proposed authsome onboard

Single command for “I’m new — set me up and pull in my existing keys”:

authsome onboard

Suggested flow (ordered):

  1. Initialize — same as init: local identity + daemon registration.
  2. Claim — same as ensure_identity_ready: browser claim URL + poll (or print URL for headless).
  3. Scan & import — same as scan --import: discover API keys from dotenv files and process env, write to vault.

Suggested options:

Option Purpose
--connection <name> Target connection name when importing (default: default, same as scan)
--scan-only Report drift without importing (escape hatch)
--no-scan Skip credential scan (init + claim only)
--json Machine-readable combined result

Default behavior: import discovered keys (user expectation for “onboard” — not report-only). Interactive confirmation may still be useful when keys are found in TTY mode; headless/CI should use --json or explicit flags.

Design notes

  • Reuse internals — implement as orchestration calling existing init/scan logic (shared helpers), not duplicated scan loop. Address existing TODO: scan duplication with _scan_env_sources.
  • Output — single JSON blob combining init metadata + scan results (imported_count, per-provider status).
  • OAuth — onboard does not replace authsome login <provider> for OAuth flows; document that API keys are auto-imported, OAuth still needs explicit login.
  • Related work — credential import/restore ADR spike (plans/009-spike-credential-import-restore.md) covers export inverse; onboard is complementary (env discovery, not vault backup restore).
  • Related issue — #426 (single private-key env var) may simplify headless agent onboard later.

Relevant files

  • src/authsome/cli/commands/core.py — init, scan
  • src/authsome/cli/helpers.py — _scan_env_sources, _scan_resolve_should_import
  • src/authsome/cli/client.py — ensure_identity_ready, login session APIs
  • src/authsome/cli/commands/__init__.py — command registration
  • tests/cli/test_init.py, tests/cli/test_import_env.py
  • docs/site/installation.mdx, docs/site/reference/cli.mdx, README.md

Acceptance criteria

  • authsome onboard on a fresh machine: identity created, claim completed (or clear headless instructions), API keys from .env/env imported into vault.
  • No regression to standalone init and scan (keep or alias — decide in implementation).
  • Tests cover: fresh onboard, onboard with no keys found, onboard with existing vault keys (skip unchanged).
  • Docs and README quick start reference onboard as the recommended first-run command.

manojbajaj95 avatar Jun 16 '26 07:06 manojbajaj95