diff --git a/README.md b/README.md index 514e552..211625e 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,21 @@ openclaw config set channels.helloagent.allowFrom.0 alice | `allow-all` | Any HelloAgent peer can DM (a warning is logged) | | `deny-all` | Inbound DMs are dropped | +## Uninstalling + +`openclaw plugins uninstall helloagent` removes the cfg entry, install record, and load path — but it does **not** wipe credentials. Log out each account first so the live WebSocket session is torn down and the `creds.json` files are deleted: + +```bash +openclaw channels logout --channel helloagent # repeat per --account if you have several +openclaw plugins uninstall helloagent +``` + +Or, if you've already uninstalled and want to scrub leftover tokens: + +```bash +rm -rf ~/.openclaw/credentials/helloagent +``` + ## Capabilities | | | diff --git a/openclaw.plugin.json b/openclaw.plugin.json index 4eebe97..3094e14 100644 --- a/openclaw.plugin.json +++ b/openclaw.plugin.json @@ -68,6 +68,44 @@ "type": "string", "enum": ["allowlist", "allow-all", "deny-all", "pairing"], "description": "Direct-message gating policy." + }, + "accounts": { + "type": "object", + "description": "Per-account overrides keyed by accountId.", + "additionalProperties": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "description": "Set false to keep paired creds on disk but prevent OpenClaw from starting this account." + }, + "name": { + "type": "string", + "description": "Display name for this account." + }, + "apiUrl": { + "type": "string", + "format": "uri", + "description": "Per-account HelloAgent REST base URL override." + }, + "relayWs": { + "type": "string", + "format": "uri", + "description": "Per-account relay WebSocket URL override." + }, + "allowFrom": { + "type": "array", + "items": { "type": "string" }, + "description": "Per-account allowlist of peer handles permitted to DM." + }, + "dmPolicy": { + "type": "string", + "enum": ["allowlist", "allow-all", "deny-all", "pairing"], + "description": "Per-account direct-message gating policy." + } + } + } } } }, diff --git a/src/channel/plugin.ts b/src/channel/plugin.ts index 27734f9..21e3c08 100644 --- a/src/channel/plugin.ts +++ b/src/channel/plugin.ts @@ -33,7 +33,7 @@ import type { HelloAgentAccount, ResolvedHelloAgentAccount } from "../core/types import { sendText } from "../messaging/outbound/send.js"; import { helloAgentOutbound } from "../messaging/outbound/outbound.js"; import { loginHelloAgent } from "../commands/auth-login.js"; -import { logoutHelloAgent } from "../commands/auth-logout.js"; +import { logoutHelloAgent, onHelloAgentAccountRemoved } from "../commands/auth-logout.js"; import { applyAccountConfig, collectHelloAgentSecurityWarnings, @@ -380,6 +380,16 @@ export const helloAgentPlugin: ChannelPlugin = { logoutAccount: logoutHelloAgent, }, + // ------------------------------------------------------------------------- + // Lifecycle — react to account removal from cfg (covers `channels logout` + // and the cascade from `plugins uninstall helloagent`). Deletes the + // on-disk creds so sensitive ha_* tokens don't outlive the install. + // ------------------------------------------------------------------------- + + lifecycle: { + onAccountRemoved: onHelloAgentAccountRemoved, + }, + // ------------------------------------------------------------------------- // Auth — channels login dispatch (oauth/device/import). // ------------------------------------------------------------------------- diff --git a/src/commands/auth-logout.ts b/src/commands/auth-logout.ts index 2165cd5..480371a 100644 --- a/src/commands/auth-logout.ts +++ b/src/commands/auth-logout.ts @@ -1,9 +1,17 @@ /** - * `gateway.logoutAccount` adapter — invoked by OpenClaw when the user runs - * `openclaw channels logout --channel helloagent [--account ]`. + * Account-teardown adapters. * - * Behavior: stop the live WS session (if any) and delete the credentials - * file from disk. Returns `{ cleared: true, loggedOut: true }`. + * Two entry points share one cleanup routine: + * + * - `logoutHelloAgent` — `gateway.logoutAccount`, invoked by + * `openclaw channels logout --channel helloagent [--account ]`. + * - `onHelloAgentAccountRemoved` — `lifecycle.onAccountRemoved`, invoked + * whenever an account leaves the cfg (per-account removal, or as a + * side-effect of `openclaw plugins uninstall helloagent` blowing away + * the entire `channels.helloagent` block). + * + * Cleanup is best-effort and idempotent: stops the live WS session if any, + * then deletes the on-disk `creds.json`. Both steps tolerate "already gone". */ import type { ChannelPlugin } from "openclaw/plugin-sdk/channel-core"; @@ -17,11 +25,23 @@ type LogoutAccountFn = NonNullable< type LogoutCtx = Parameters[0]; type LogoutResult = Awaited>; +type LifecycleAdapter = NonNullable["lifecycle"]>; +type OnAccountRemovedFn = NonNullable; +type OnAccountRemovedParams = Parameters[0]; + +async function cleanupAccount(accountId: string, log: (s: string) => void): Promise { + log(`[helloagent] cleaning up account ${accountId}`); + await stopAccount(accountId).catch(() => undefined); + await deleteCreds(accountId).catch(() => undefined); +} + export async function logoutHelloAgent(ctx: LogoutCtx): Promise { - const accountId = ctx.accountId; - ctx.runtime.log(`[helloagent] logout: stopping session for ${accountId}`); - await stopAccount(accountId); - await deleteCreds(accountId); - ctx.runtime.log(`[helloagent] logout: creds removed for ${accountId}`); + await cleanupAccount(ctx.accountId, (s) => ctx.runtime.log(s)); return { cleared: true, loggedOut: true }; } + +export async function onHelloAgentAccountRemoved( + params: OnAccountRemovedParams, +): Promise { + await cleanupAccount(params.accountId, (s) => params.runtime.log(s)); +}