Skip to content

Auto-enable channels.helloagent on first plugin import - #3

Merged
hsyvy merged 5 commits into
mainfrom
auto-enable-channel-on-install
May 12, 2026
Merged

hsyvy merged 5 commits into
mainfrom
auto-enable-channel-on-install

Conversation

@hsyvy

@hsyvy hsyvy commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

openclaw channels login --channel helloagent previously failed with Unsupported channel: helloagent on a fresh install. OpenClaw's CLI resolver only knows third-party channels via either the bundled official catalog (we're not in it) or cfg.channels.<id> (the configured-channels loader scope). Without a cfg entry the resolver short-circuits before our plugin code ever runs, so users had to manually run openclaw config set channels.helloagent.enabled true before their first login.

This PR adds ensureHelloAgentChannelEnabled() and calls it as a top-level side effect from setup-entry.ts and index.ts. OpenClaw imports setup-entry during applyPluginAutoEnable, which runs before the channel resolver — giving us a chance to:

  1. Persist channels.helloagent.enabled = true to disk via an atomic temp-file rename + .bak backup. Idempotent. Respects an existing enabled: false so a user opt-out is never overwritten.
  2. Mutate the in-memory runtime config snapshot returned by getRuntimeConfig() so the current invocation sees the new entry immediately. Without this, the disk write would only take effect on the next invocation (openclaw caches cfg per-process and never re-reads from disk during a single command).

Both steps are best-effort and wrapped in try/catch; failures degrade the UX (user has to re-run once) but never break the plugin import. The in-memory patch uses createRequire so an older openclaw that doesn't expose runtime-config-snapshot still imports cleanly.

Files

  • src/core/auto-enable-channel.ts (new) — disk + in-memory cfg patcher
  • setup-entry.ts — call the patcher at module top level
  • index.ts — same, mirrored, so whichever entry openclaw imports first wins

Test plan

  • Clean slate: plugins uninstall helloagent && config unset channels.helloagent
  • plugins install /local/path — cfg still has no helloagent entry afterward
  • channels login --channel helloagent succeeds first try (prompts for ha_* token, no "Unsupported channel" error)
  • After the run, config get channels.helloagent returns { "enabled": true } (disk persistence)
  • Subsequent channels login invocations are idempotent
  • config set channels.helloagent.enabled false survives the next plugin import (opt-out respected)

🤖 Generated with Claude Code

hsyvy and others added 5 commits May 12, 2026 10:32
`openclaw channels login --channel helloagent` previously failed with
"Unsupported channel: helloagent" on a fresh install. OpenClaw's CLI
resolver only knows third-party channels via either the bundled official
catalog (we're not in it) or `cfg.channels.<id>` (the
"configured-channels" loader scope). Without a cfg entry the resolver
short-circuits before the plugin code ever runs, so users had to
manually run `openclaw config set channels.helloagent.enabled true`
before their first login.

Add `ensureHelloAgentChannelEnabled()` and call it as a top-level side
effect from setup-entry.ts and index.ts. OpenClaw imports setup-entry
during `applyPluginAutoEnable`, which runs before the channel resolver,
so we get a chance to:

  1. Persist `channels.helloagent.enabled = true` to disk via an atomic
     temp-file rename with a `.bak` backup. Idempotent; respects an
     existing `enabled: false` so a user opt-out is never overwritten.
  2. Mutate the in-memory runtime config snapshot returned by
     `getRuntimeConfig()` so the current invocation sees the new entry
     immediately. Without this, the disk write would only take effect
     on the *next* invocation (openclaw caches cfg per-process and
     never re-reads from disk during a single command).

Both steps are best-effort and wrapped in try/catch; failures degrade
the UX (user has to re-run once) but never break the plugin import.
The in-memory patch uses `createRequire` to dynamically load
`openclaw/plugin-sdk/runtime-config-snapshot` so an older openclaw that
doesn't expose this SDK surface still imports cleanly.

Verified end-to-end on a clean slate:

  plugins uninstall helloagent           # no cfg entry, no install record
  plugins install <local path>           # installed; cfg still untouched
  channels login --channel helloagent    # resolves; prompts for ha_* token
  config get channels.helloagent         # { "enabled": true } now persisted

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Replace `npm install` (would install as a project dep, wrong for end
  users) with `openclaw plugins install`, the supported entry point.
- Note that `channels.helloagent.enabled` is now set automatically on
  first import, so login no longer requires a prior `config set`.
- Drop the now-defunct `config set` step from the run-from-source
  recipe.
- Add a Troubleshooting section covering the most common failure modes:
  Unsupported channel, empty stdin, gateway not picking up creds,
  expired tokens, corp proxies, verbose logs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Replace separate Install / Log in / Alternate-modes sections with one
  Get-started block: install → restart gateway (if running) → login.
  Single copy-pasteable recipe.
- Drop the oauth / device pairing-mode docs — the import-token flow
  covers every supported environment, and the alternates have been a
  source of "which one do I run?" confusion. The env vars and code
  paths still exist for power users; they're just no longer surfaced.
- Trim the env-var table to the variables that actually affect the
  documented import flow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…t to manual recovery

- Remove the Usage block (channels list/logout, dmPolicy table) and the
  Multiple accounts block. The Get-started recipe is enough; the rest
  belonged in dedicated docs, not the front-page README.
- In the "Unsupported channel" troubleshooting step, add the
  `openclaw gateway restart` line between the cfg flag write and the
  retry login. Same reasoning as the Get-started block: a running
  gateway needs to reload its plugin registry to pick up the new
  channel.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Covers the helper that this PR introduces:

- channelAlreadyDecided across six cfg shapes (empty, partial, primitive,
  enabled:true, enabled:false, non-object entry).
- patchCfgInPlace preserves sibling channels and existing helloagent keys
  (dmPolicy, allowFrom) when merging in enabled:true.
- End-to-end ensureHelloAgentChannelEnabled disk behavior:
  - Missing cfg → fresh write, no .bak.
  - Existing cfg → patch in + .bak rotation.
  - User opt-out (enabled:false) preserved byte-for-byte.
  - Already enabled → no-op (no rewrite, no .bak).
  - Corrupt cfg → leave it alone.
  - Idempotent per process (attempted guard).
  - Post-reset re-evaluates and patches without losing existing keys.

Exposes a narrow __testing namespace from auto-enable-channel.ts for the
helpers and an attempted-flag reset; not part of the public API.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@hsyvy
hsyvy merged commit 2424dfd into main May 12, 2026
1 check passed
@hsyvy hsyvy mentioned this pull request May 12, 2026
3 of 5 tasks
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