Skip to content

fix(import): adapt OpenClaw import for relocated auth profiles and auth config field #427

@alexey-pelykh

Description

@alexey-pelykh

Context

The OpenClaw → RemoteClaw import command (`src/commands/import.ts`) copies and transforms config files from `/.openclaw/` to `/.remoteclaw/`. After #415 Phase 1 and auth store relocation (#438), import needs adaptation for:

  1. Global auth store (refactor(auth): relocate auth store from per-agent to global path #438): OpenClaw stores auth profiles per-agent at `/.openclaw/agents/{id}/agent/auth-profiles.json`. RemoteClaw now uses a single global store at `/.remoteclaw/auth-profiles.json`. Import must consolidate per-agent files into the global store.
  2. Missing `auth` config field: OpenClaw configs don't have the `auth` field. Imported configs will have auth profiles but no config field pointing to them — credentials are silently unused.

Current import behavior

  • `transformConfigContent()`: Renames `OPENCLAW_` env vars → `REMOTECLAW_`, `.openclaw/` paths → `.remoteclaw/`
  • `stripUnrecognizedConfigKeys()`: Filters config against current `RemoteClawSchema` (drops unknown keys)
  • `materializeWorkspaceDefaults()`: Fills in implicit workspace paths
  • `discoverSourceAuthProfileIds()`: Walks directory tree finding `auth-profiles.json` files
  • Auth profiles files are copied as-is preserving directory structure (per-agent)

Required changes

1. Consolidate per-agent auth files into global store

During import:

  • Discover all `auth-profiles.json` files under source (existing `discoverSourceAuthProfileIds` logic)
  • Merge all discovered profiles into a single store
  • Conflict resolution: warn if same profile ID appears in multiple agent dirs with different keys; last-wins or user prompt
  • Write consolidated store to `~/.remoteclaw/auth-profiles.json` (global path)
  • Do NOT copy auth files into per-agent directories (old structure)

2. Materialize `auth` config field

Add a transform step (similar to `materializeWorkspaceDefaults`) that:

  • Reads profile IDs from the consolidated auth store
  • Sets `agents.defaults.auth` to the first runtime-matching profile ID
  • Example: if `anthropic:default` profile exists and `agents.defaults.runtime: "claude"` → set `agents.defaults.auth: "anthropic:default"`

3. Provider mapping for auto-detection

Runtime Expected profile provider Profile ID pattern
claude anthropic `anthropic:` or `claude:`
gemini google `google:*`
codex codex / openai `codex:` or `openai:`
opencode varies `openai:`, `anthropic:`, `opencode:*`

Tests

  • Import with per-agent auth profiles → consolidated into single global file
  • Import with auth profiles in multiple agent dirs → merged correctly
  • Profile ID conflict across agents → warning logged, one value chosen
  • Import with auth profiles + runtime config → `auth` field set correctly
  • Import without auth profiles → `auth` field not set (or `false`)
  • Auth profiles NOT copied to per-agent directories
  • Existing tests continue to pass

Depends on

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions