fix: support CLI login on fresh Linux hosts#17
Conversation
Greptile SummaryThis PR fixes two independent regressions on fresh Linux hosts: Key changes:
Confidence Score: 4/5Safe to merge — the fallback logic is correct, existing secure-store paths are unaffected, and the exit-code fix is straightforward. The core logic is sound: No files require special attention; Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["delega login / delega init"] --> B["persistApiKey\nsrc/config.ts"]
B --> C{secret-store\nreturns a label?}
C -- "yes — keyring available" --> D["Return\nlocation: keyring label\nsecure: true"]
C -- "no — no keyring backend" --> E["Return\nlocation: config.json path\nsecure: false"]
D --> F{secure flag?}
E --> F
F -- "true" --> G["Remove credential field\nfrom config\nsaveConfig\nkey lives only in keyring"]
F -- "false" --> H["Write credential field\ninto config\nsaveConfig\nkey lives in config.json"]
G --> I["Log: saved to keyring label"]
H --> I
Reviews (1): Last reviewed commit: "fix: support cli login fallback on fresh..." | Re-trigger Greptile |
| } catch (err) { | ||
| const msg = err instanceof Error ? err.message : String(err); | ||
| console.error(`Unable to store API key securely: ${msg}`); | ||
| console.error(`Unable to store API key: ${msg}`); | ||
| process.exit(1); |
There was a problem hiding this comment.
Mixed error message if config write fails
saveConfig is now inside the catch-all try block, which is the right change. But if saveConfig throws (e.g. a permission error writing the config directory), the catch clause will surface it as Unable to store API key, implying the credential-store step failed rather than the file write.
For clarity, consider wrapping saveConfig in its own try/catch with a distinct message like Unable to save config, consistent with the wording already used in saveApiConfig inside init.ts.
Summary
~/.delega/config.jsonwhen no secure credential store is availableWhy
On a fresh Linux controller with no keyring backend,
delega logincould validate the key but then failed to store it at all. The CLI also returned exit code 0 for unknown commands, which is wrong for scripts and automation.Validation
cd /Users/openclaw/projects/delega-cli && npm run buildprintf "$DELEGA_HOSTED_KEY " | delega loginnow succeeds and stores config in/root/.delega/config.jsondelega totally-fake-commandnow exits 1/root/work/delega-tests/cli/cli-hosted.shon the fresh controller -> 20/20 pass