Skip to content

feat: UX improvements and sink system (v2.2.0)#12

Merged
chenliuyun merged 2 commits intomainfrom
feat/ux-improvements-v2.2
Apr 19, 2026
Merged

feat: UX improvements and sink system (v2.2.0)#12
chenliuyun merged 2 commits intomainfrom
feat/ux-improvements-v2.2

Conversation

@chenliuyun
Copy link
Copy Markdown
Collaborator

Summary

  • Sink system: Added 9 sink types for events mqtt-tail output routing — stdout, file, webhook, OpenClaw, Telegram, Home Assistant
  • MCP get_device_history tool: New 9th MCP tool backed by DeviceHistoryStore (persists shadow snapshots per device)
  • 20+ UX fixes from a comprehensive CLI audit (P0/P1/P2): field aliases, --filter in JSON mode, batch status --fields/--format, --name on expand/watch, role column in types table, example params in commands output, and more
  • Bug fixes: --audit-log boolean flag, outer try/catch in devices command, case-insensitive command name suggestions, missing-parameter validation

Changes

Sink system (src/sinks/)

  • types.ts, format.ts, dispatcher.ts — shared infrastructure
  • stdout.ts, file.ts, webhook.ts, openclaw.ts, telegram.ts, homeassistant.ts — individual sinks
  • events mqtt-tail gains --sink, --sink-file, --webhook-url, --openclaw-*, --telegram-*, --ha-* flags

MCP

  • src/mcp/device-history.ts — DeviceHistoryStore persists shadow snapshots to ~/.switchbot/device-history/
  • src/commands/mcp.tsget_device_history tool (9th tool)

UX fixes

ID Fix
BUG-1 --audit-log is now a boolean flag; add separate --audit-log-path
BUG-2/3 devices command outer try/catch + --name positional shift fix
BUG-7/P1-04 Case-insensitive command suggestion ("Did you mean getStatus?")
P0-05 Field aliases in devices list (type, room, hub, cloud)
P0-06/07 capabilities --minimal flag
P0-08 --timeout minimum 100 ms with warning
P0-09 --filter for devices list (type, name, category, room)
P1-02 Missing-parameter validation
P1-03 IR command shows "→ IR signal sent" (no fake ✓)
P1-05 scenes list --fields accepts id/name aliases
P1-06 devices status --ids for batch status
P1-08 --yes warns when used on non-destructive commands
P1-11 devices list --json returns { ok: true, deviceList, infraredRemoteList }
P1-13 devices status --ids supports --fields and --format jsonl
P1-14 plan validate warns when plan has 0 steps
P1-15 --name added to devices expand and devices watch
P1-16 devices status --json includes _fetchedAt timestamp
P2 devices list --json now respects --filter
P2 devices types table includes role column
P2 devices commands shows example params when available

Test plan

  • npm run build && npm test — 697 tests passing
  • switchbot devices list --filter category=physical --json — verifies filter in JSON mode
  • switchbot devices status --ids <id1>,<id2> --fields power,battery — verifies batch fields
  • switchbot devices expand --name "device-name" setAll --temp 26 --mode cool --fan low --power on
  • switchbot devices watch --name "device-name" --max 1
  • switchbot events mqtt-tail --sink file --sink-file /tmp/events.jsonl --max 1
  • switchbot capabilities --json | jq '.data.mcpTools | length' — should be 9

chenliuyun added 2 commits April 19, 2026 20:51
- Use random instanceId per session so each CLI run gets its own clientId,
  preventing conflicts with the SwitchBot cloud service that shares the same
  account credentials and causes an immediate session-kicking loop
- Remove stale listeners from old mqtt.js client before replacing it in
  connect(), preventing the old client's close event from triggering a
  spurious extra reconnect cycle
- Add onStateChange logging in events mqtt-tail so connection state
  transitions (connected/reconnecting/failed) are visible on stderr
- Add onStateChange to test mock to avoid unsubState() TypeError
Sink system:
- Add src/sinks/ — stdout, file, webhook, openclaw, telegram, homeassistant
- Add DeviceHistoryStore (src/mcp/device-history.ts) and get_device_history MCP tool
- Add --sink, --sink-file, --webhook-url, --openclaw-*, --telegram-*, --ha-* to events mqtt-tail

CLI UX fixes (P0/P1/P2):
- BUG-1: --audit-log now boolean; add --audit-log-path for explicit path
- BUG-2/3: devices command outer try/catch; --name positional shift fix
- BUG-7/P1-04: case-insensitive command name suggestion ("Did you mean getStatus?")
- P0-05: field aliases in devices list (type, room, hub, cloud short names)
- P0-06/07: capabilities --minimal flag; explicit help entry in manifest
- P0-08: --timeout minimum 100ms with warning
- P0-09: --filter expr for devices list (type, name, category, room)
- P1-02: missing-parameter validation for commands requiring a param
- P1-03: IR command shows "→ IR signal sent" (not fake ✓)
- P1-05: scenes list --fields accepts id/name aliases
- P1-06: devices status --ids for batch status
- P1-08: --yes warning when passed to non-destructive commands
- P1-11: devices list --json returns { ok: true, deviceList, infraredRemoteList }
- P1-13: devices status --ids now supports --fields and --format jsonl
- P1-14: plan validate warns when plan has 0 steps
- P1-15: --name added to devices expand and devices watch
- P1-16: devices status --json includes _fetchedAt timestamp
- P2: devices list --json now respects --filter
- P2: devices types table includes role column
- P2: devices commands output shows example params when available

Tests: 697 passing (added 5 new tests for --filter JSON, expand --name, watch no-args)
@chenliuyun chenliuyun merged commit 55c2a40 into main Apr 19, 2026
3 checks passed
@chenliuyun chenliuyun deleted the feat/ux-improvements-v2.2 branch April 19, 2026 15:22
chenliuyun pushed a commit that referenced this pull request Apr 20, 2026
Add --no-color as a root-level option to suppress ANSI colors in output.
Also respect the NO_COLOR environment variable per https://no-color.org/.
Early initialization sets chalk.level=0 when either flag or env is set,
ensuring colors are disabled globally before any commands execute.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chenliuyun pushed a commit that referenced this pull request Apr 20, 2026
Document every fix landed in this branch beyond the history-aggregate
feature: bugs #1, #4, #5, #6, #8, #9, #10, #11, #12, #13, #14, #15,
#16, #17, #18 from the OpenClaw v2.4.0 smoke-test report. Call out
the deferred items (#2, #7) explicitly so readers don't assume they
were overlooked.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chenliuyun pushed a commit that referenced this pull request Apr 20, 2026
Add --no-color as a root-level option to suppress ANSI colors in output.
Also respect the NO_COLOR environment variable per https://no-color.org/.
Early initialization sets chalk.level=0 when either flag or env is set,
ensuring colors are disabled globally before any commands execute.
chenliuyun pushed a commit that referenced this pull request Apr 20, 2026
Document every fix landed in this branch beyond the history-aggregate
feature: bugs #1, #4, #5, #6, #8, #9, #10, #11, #12, #13, #14, #15,
#16, #17, #18 from the OpenClaw v2.4.0 smoke-test report. Call out
the deferred items (#2, #7) explicitly so readers don't assume they
were overlooked.
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