feat(setup): optional WhatsApp wiring + cross-channel UX polish
WhatsApp (community/Baileys) joins the setup:auto channel picker, with
the same clack-native UX discipline as Telegram and Discord:
- setup/channels/whatsapp.ts — driver. Collects auth method (QR terminal
or pairing code), runs the auth step, renders QR blocks in-place with
ANSI cursor-rewind on rotation so the terminal doesn't fill up with
stale codes, reads creds.me.id for the bot phone, restarts the service,
asks for the operator's personal phone (defaulting to the authed
number), writes ASSISTANT_HAS_OWN_NUMBER=true when they differ
(dedicated mode), and hands off to init-first-agent.
- setup/whatsapp-auth.ts — forked standalone auth step. Channels-branch
version had a browser-QR path with an HTTP server + <canvas> QR
renderer; stripped entirely (headless/SSH users hit dead ends too
often, and the extra deps complicate install). The remaining terminal
QR emits raw QR strings in WHATSAPP_AUTH_QR blocks so the parent
driver owns the rendering. Pairing-code path retained. Status blocks
now use the runner's vocabulary (success/skipped/failed) so spawnStep
sets ok correctly; WhatsApp-specific UI text ("WhatsApp linked", "You
chat") lives in the driver.
- setup/add-whatsapp.sh — non-interactive installer, mirror of
add-telegram.sh. Fetches the adapter + groups step from the channels
branch (whatsapp-auth.ts stays local, pair-telegram.ts pattern),
installs pinned baileys/qrcode/pino, registers the steps in
setup/index.ts's STEPS map. No service restart (adapter factory
returns null until creds exist).
Cross-channel fixes bundled:
- scripts/init-first-agent.ts: always addMember(user, agentGroup) for
the target user so subsequent wirings (not the first) pass the access
gate. Telegram wiring first → Discord/WhatsApp second was dropping
every inbound with accessReason='not_member' because only the first
user gets owner. namespacedPlatformId also passes through JID-format
raws (contains '@') so WhatsApp's bare <phone>@s.whatsapp.net matches
what the adapter stores.
- setup/service.ts: launchctl unload-then-load instead of bare load (bare
load errors 'already loaded' when a prior plist was cached, keeping
launchd on the OLD ProgramArguments even after the file on disk
changed). systemctl start → restart (start is a no-op on an active
unit, swallowing unit-file edits).
- setup/add-telegram.sh: removed the in-script open "tg://resolve"
block. The driver (setup/channels/telegram.ts) now owns the deep-link,
gated on a p.confirm so the browser can't steal focus unexpectedly.
- setup/channels/discord.ts + setup/channels/telegram.ts: every browser
open goes through confirmThenOpen (new shared helper in
setup/lib/browser.ts) — operator presses Enter before their browser
takes focus. Telegram switched from tg://resolve?domain= to
https://t.me/<bot> which works everywhere.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -116,13 +116,30 @@ function setupLaunchd(
|
||||
fs.writeFileSync(plistPath, plist);
|
||||
log.info('Wrote launchd plist', { plistPath });
|
||||
|
||||
// Unload first to force launchd to drop any cached plist and re-read from
|
||||
// disk. Bare `launchctl load` on an already-loaded plist errors with
|
||||
// "already loaded" and keeps the ORIGINAL plist's ProgramArguments /
|
||||
// WorkingDirectory in memory — even if the file on disk changed. That
|
||||
// bit us when the plist target shifted between installs: kickstart kept
|
||||
// relaunching the old binary and the CLI socket landed in the wrong dir.
|
||||
// unload succeeds whether or not the service was previously loaded; the
|
||||
// failure case is "Could not find specified service" which is harmless.
|
||||
try {
|
||||
execSync(`launchctl unload ${JSON.stringify(plistPath)}`, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
log.info('launchctl unload succeeded');
|
||||
} catch {
|
||||
log.info('launchctl unload noop (plist was not previously loaded)');
|
||||
}
|
||||
|
||||
try {
|
||||
execSync(`launchctl load ${JSON.stringify(plistPath)}`, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
log.info('launchctl load succeeded');
|
||||
} catch {
|
||||
log.warn('launchctl load failed (may already be loaded)');
|
||||
} catch (err) {
|
||||
log.error('launchctl load failed', { err });
|
||||
}
|
||||
|
||||
// Verify
|
||||
@@ -316,10 +333,15 @@ WantedBy=${runningAsRoot ? 'multi-user.target' : 'default.target'}`;
|
||||
log.error('systemctl enable failed', { err });
|
||||
}
|
||||
|
||||
// restart (not start) so a previously-running instance picks up edits to
|
||||
// the unit file. `start` on an active unit is a no-op, which would leave
|
||||
// the old ExecStart / WorkingDirectory in effect even after daemon-reload.
|
||||
// `restart` on a stopped unit is equivalent to `start`, so this is safe
|
||||
// as a first-install path too.
|
||||
try {
|
||||
execSync(`${systemctlPrefix} start nanoclaw`, { stdio: 'ignore' });
|
||||
execSync(`${systemctlPrefix} restart nanoclaw`, { stdio: 'ignore' });
|
||||
} catch (err) {
|
||||
log.error('systemctl start failed', { err });
|
||||
log.error('systemctl restart failed', { err });
|
||||
}
|
||||
|
||||
// Verify
|
||||
|
||||
Reference in New Issue
Block a user