@switchbot/openapi-cli 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +34 -42
  2. package/dist/index.js +56945 -169
  3. package/dist/policy/schema/v0.2.json +1 -1
  4. package/package.json +3 -2
  5. package/dist/api/client.js +0 -235
  6. package/dist/auth.js +0 -20
  7. package/dist/commands/agent-bootstrap.js +0 -182
  8. package/dist/commands/auth.js +0 -354
  9. package/dist/commands/batch.js +0 -413
  10. package/dist/commands/cache.js +0 -126
  11. package/dist/commands/capabilities.js +0 -385
  12. package/dist/commands/catalog.js +0 -359
  13. package/dist/commands/completion.js +0 -385
  14. package/dist/commands/config.js +0 -376
  15. package/dist/commands/daemon.js +0 -367
  16. package/dist/commands/device-meta.js +0 -159
  17. package/dist/commands/devices.js +0 -948
  18. package/dist/commands/doctor.js +0 -1015
  19. package/dist/commands/events.js +0 -563
  20. package/dist/commands/expand.js +0 -130
  21. package/dist/commands/explain.js +0 -139
  22. package/dist/commands/health.js +0 -113
  23. package/dist/commands/history.js +0 -320
  24. package/dist/commands/identity.js +0 -59
  25. package/dist/commands/install.js +0 -246
  26. package/dist/commands/mcp.js +0 -2017
  27. package/dist/commands/plan.js +0 -653
  28. package/dist/commands/policy.js +0 -586
  29. package/dist/commands/quota.js +0 -78
  30. package/dist/commands/rules.js +0 -875
  31. package/dist/commands/scenes.js +0 -264
  32. package/dist/commands/schema.js +0 -177
  33. package/dist/commands/status-sync.js +0 -131
  34. package/dist/commands/uninstall.js +0 -237
  35. package/dist/commands/upgrade-check.js +0 -88
  36. package/dist/commands/watch.js +0 -194
  37. package/dist/commands/webhook.js +0 -182
  38. package/dist/config.js +0 -258
  39. package/dist/credentials/backends/file.js +0 -101
  40. package/dist/credentials/backends/linux.js +0 -129
  41. package/dist/credentials/backends/macos.js +0 -129
  42. package/dist/credentials/backends/windows.js +0 -215
  43. package/dist/credentials/keychain.js +0 -88
  44. package/dist/credentials/prime.js +0 -52
  45. package/dist/devices/cache.js +0 -293
  46. package/dist/devices/catalog.js +0 -767
  47. package/dist/devices/device-meta.js +0 -56
  48. package/dist/devices/history-agg.js +0 -138
  49. package/dist/devices/history-query.js +0 -181
  50. package/dist/devices/param-validator.js +0 -433
  51. package/dist/devices/resources.js +0 -270
  52. package/dist/install/default-steps.js +0 -257
  53. package/dist/install/preflight.js +0 -212
  54. package/dist/install/steps.js +0 -67
  55. package/dist/lib/command-keywords.js +0 -17
  56. package/dist/lib/daemon-state.js +0 -46
  57. package/dist/lib/destructive-mode.js +0 -12
  58. package/dist/lib/devices.js +0 -382
  59. package/dist/lib/idempotency.js +0 -106
  60. package/dist/lib/plan-store.js +0 -68
  61. package/dist/lib/request-context.js +0 -12
  62. package/dist/lib/scenes.js +0 -10
  63. package/dist/logger.js +0 -16
  64. package/dist/mcp/device-history.js +0 -145
  65. package/dist/mcp/events-subscription.js +0 -213
  66. package/dist/mqtt/client.js +0 -180
  67. package/dist/mqtt/credential.js +0 -30
  68. package/dist/policy/add-rule.js +0 -124
  69. package/dist/policy/diff.js +0 -91
  70. package/dist/policy/format.js +0 -57
  71. package/dist/policy/load.js +0 -61
  72. package/dist/policy/migrate.js +0 -67
  73. package/dist/policy/schema.js +0 -18
  74. package/dist/policy/validate.js +0 -262
  75. package/dist/rules/action.js +0 -205
  76. package/dist/rules/audit-query.js +0 -89
  77. package/dist/rules/conflict-analyzer.js +0 -203
  78. package/dist/rules/cron-scheduler.js +0 -186
  79. package/dist/rules/destructive.js +0 -52
  80. package/dist/rules/engine.js +0 -757
  81. package/dist/rules/matcher.js +0 -230
  82. package/dist/rules/pid-file.js +0 -95
  83. package/dist/rules/quiet-hours.js +0 -45
  84. package/dist/rules/suggest.js +0 -95
  85. package/dist/rules/throttle.js +0 -116
  86. package/dist/rules/types.js +0 -34
  87. package/dist/rules/webhook-listener.js +0 -223
  88. package/dist/rules/webhook-token.js +0 -90
  89. package/dist/schema/field-aliases.js +0 -131
  90. package/dist/sinks/dispatcher.js +0 -12
  91. package/dist/sinks/file.js +0 -19
  92. package/dist/sinks/format.js +0 -56
  93. package/dist/sinks/homeassistant.js +0 -44
  94. package/dist/sinks/openclaw.js +0 -33
  95. package/dist/sinks/stdout.js +0 -5
  96. package/dist/sinks/telegram.js +0 -28
  97. package/dist/sinks/types.js +0 -1
  98. package/dist/sinks/webhook.js +0 -22
  99. package/dist/status-sync/manager.js +0 -268
  100. package/dist/utils/arg-parsers.js +0 -66
  101. package/dist/utils/audit.js +0 -117
  102. package/dist/utils/filter.js +0 -189
  103. package/dist/utils/flags.js +0 -186
  104. package/dist/utils/format.js +0 -117
  105. package/dist/utils/health.js +0 -101
  106. package/dist/utils/help-json.js +0 -54
  107. package/dist/utils/name-resolver.js +0 -137
  108. package/dist/utils/output.js +0 -404
  109. package/dist/utils/quota.js +0 -227
  110. package/dist/utils/redact.js +0 -68
  111. package/dist/utils/retry.js +0 -140
  112. package/dist/utils/string.js +0 -22
  113. package/dist/version.js +0 -4
package/README.md CHANGED
@@ -73,6 +73,7 @@ Under the hood every surface shares the same catalog, cache, and HMAC client —
73
73
  - [`capabilities`](#capabilities--cli-manifest)
74
74
  - [`cache`](#cache--inspect-and-clear-local-cache)
75
75
  - [`policy`](#policy--validate-scaffold-and-migrate-policyyaml)
76
+ - [`daemon`](#daemon--background-rules-engine-process)
76
77
  - [`completion`](#completion--shell-tab-completion)
77
78
  - [Output modes](#output-modes)
78
79
  - [Cache](#cache)
@@ -80,8 +81,6 @@ Under the hood every surface shares the same catalog, cache, and HMAC client —
80
81
  - [Environment variables](#environment-variables)
81
82
  - [Scripting examples](#scripting-examples)
82
83
  - [Development](#development)
83
- - [Contributing](#contributing)
84
- - [Roadmap](#roadmap)
85
84
  - [License](#license)
86
85
  - [References](#references)
87
86
 
@@ -94,7 +93,7 @@ Under the hood every surface shares the same catalog, cache, and HMAC client —
94
93
  - 🎨 **Dual output modes** — colorized tables by default; `--json` passthrough for `jq` and scripting
95
94
  - 🔐 **Secure credentials** — HMAC-SHA256 signed requests; config file written with `0600`; env-var override for CI
96
95
  - 🔍 **Dry-run mode** — preview every mutating request before it hits the API
97
- - 🧪 **Fully tested** — 1856 Vitest tests, mocked axios, zero network in CI
96
+ - 🧪 **Fully tested** — 1959 Vitest tests, mocked axios, zero network in CI
98
97
  - ⚡ **Shell completion** — Bash / Zsh / Fish / PowerShell
99
98
 
100
99
  ## Requirements
@@ -743,6 +742,34 @@ switchbot events mqtt-tail --sink homeassistant --ha-url http://homeassistant.lo
743
742
 
744
743
  Device state is also persisted to `~/.switchbot/device-history/<deviceId>.json` (latest + 100-entry ring buffer) regardless of sink configuration. This enables the `get_device_history` MCP tool to answer state queries without an API call.
745
744
 
745
+ ### `daemon` — background rules-engine process
746
+
747
+ Runs `switchbot rules run` as a detached background process. Tracks runtime
748
+ metadata in `~/.switchbot/daemon.state.json` and can co-launch a health HTTP
749
+ server.
750
+
751
+ ```bash
752
+ # Start the daemon (no-op if already running)
753
+ switchbot daemon start
754
+ switchbot daemon start --policy ./my-policy.yaml
755
+ switchbot daemon start --healthz-port 3100 # also launch health serve on port 3100
756
+ switchbot daemon start --force # restart even if already running
757
+
758
+ # Inspect daemon state (pid, log path, health server, last reload)
759
+ switchbot daemon status
760
+ switchbot daemon status --json
761
+
762
+ # Hot-reload policy without restarting (sends SIGHUP on Unix, writes sentinel on Windows)
763
+ switchbot daemon reload
764
+
765
+ # Stop the daemon and any co-launched health server
766
+ switchbot daemon stop
767
+ ```
768
+
769
+ Start prints the PID, log path, and state file location. If the process exits
770
+ within 300 ms of launch, start fails immediately and includes the last 20 lines
771
+ of the log in the error message for fast diagnosis.
772
+
746
773
  ### `completion` — shell tab-completion
747
774
 
748
775
  ```bash
@@ -862,7 +889,7 @@ switchbot upgrade-check --json # structured JSON output
862
889
  switchbot upgrade-check --timeout 5000 # custom registry timeout (ms)
863
890
  ```
864
891
 
865
- Queries the npm registry for the latest published version and compares it against the running version.
892
+ Queries the npm registry for the latest published version and compares it against the running version. When the registry's `dist-tags.latest` is itself a prerelease (e.g. `4.0.0-rc.1`), the check is skipped and the current version is treated as up-to-date — accidental prerelease tags don't trigger spurious upgrade prompts.
866
893
  `--json` output:
867
894
 
868
895
  ```json
@@ -1096,7 +1123,7 @@ npm install
1096
1123
 
1097
1124
  npm run dev -- <args> # Run from TypeScript sources via tsx
1098
1125
  npm run build # Compile to dist/
1099
- npm test # Run the Vitest suite (1856 tests)
1126
+ npm test # Run the Vitest suite (1959 tests)
1100
1127
  npm run test:watch # Watch mode
1101
1128
  npm run test:coverage # Coverage report (v8, HTML + text)
1102
1129
  ```
@@ -1152,7 +1179,7 @@ src/
1152
1179
  │ ├── explain.ts # `devices explain` — one-shot device summary
1153
1180
  │ ├── device-meta.ts # `devices meta` — local aliases / hide flags
1154
1181
  │ ├── install.ts # `switchbot install` / `uninstall`
1155
- │ ├── policy.ts # `policy validate/new/migrate/diff/add-rule`
1182
+ │ ├── policy.ts # `policy validate/new/migrate/diff/add-rule/backup/restore`
1156
1183
  │ ├── rules.ts # `rules suggest/lint/list/explain/run/reload/tail/replay/
1157
1184
  │ │ # conflicts/doctor/summary/last-fired/webhook-*`
1158
1185
  │ ├── scenes.ts
@@ -1178,7 +1205,7 @@ src/
1178
1205
  ├── format.ts # renderRows / filterFields / output-format dispatch
1179
1206
  ├── audit.ts # JSONL audit log writer
1180
1207
  └── quota.ts # Local daily-quota counter
1181
- tests/ # Vitest suite (1856 tests, mocked axios, no network)
1208
+ tests/ # Vitest suite (1959 tests, mocked axios, no network)
1182
1209
  ```
1183
1210
 
1184
1211
  ### Release flow
@@ -1192,41 +1219,6 @@ git push --follow-tags
1192
1219
 
1193
1220
  Then on GitHub → **Releases → Draft a new release → select tag → Publish**. The `publish.yml` workflow runs tests, verifies the tag matches `package.json`, and publishes `@switchbot/openapi-cli` to npm with [provenance](https://docs.npmjs.com/generating-provenance-statements).
1194
1221
 
1195
- ## Contributing
1196
-
1197
- Bug reports, feature requests, and PRs are welcome.
1198
-
1199
- 1. Fork the repo and create a topic branch.
1200
- 2. Keep changes small and focused; add or update Vitest cases for any behavior change.
1201
- 3. Run `npm test` and `npm run build` locally — both must pass.
1202
- 4. Open a pull request against `main`. CI runs on Node 18/20/22; all three must stay green.
1203
-
1204
- ## Roadmap
1205
-
1206
- Phase 1 through Phase 4 are shipped. The authoritative phase/track table
1207
- (including skill-side `autonomyLevel` L1/L2/L3 mapping) lives in
1208
- [`docs/design/roadmap.md`](./docs/design/roadmap.md).
1209
-
1210
- Shipped tracks summary:
1211
-
1212
- - **Track β**: one-command install/uninstall surface (`switchbot install` / `switchbot uninstall`).
1213
- - **Track γ**: rules v0.2 runtime increment (`days` + `all`/`any`/`not`).
1214
- - **Track δ (L2)**: plan authoring + guarded execution (`plan suggest`, `plan run --require-approval`) and MCP review/execute tools (`plan_suggest`, `plan_run`, `audit_query`, `audit_stats`, `policy_diff`).
1215
- - **Track ζ (L3)**: autonomous rule authoring (`rules suggest`, `policy add-rule`) with MCP parity (`rules_suggest`, `policy_add_rule`).
1216
- - **Track ε**: cross-OS keychain CI matrix (macOS + Linux libsecret + Windows Credential Manager).
1217
-
1218
- Backlog tracks still open:
1219
-
1220
- 1. **Daemon mode** — long-running local process with Unix/named-pipe
1221
- transport so repeated MCP or plan invocations avoid fresh-process
1222
- startup cost.
1223
- 2. **`npx @switchbot/mcp-server`** — split the MCP server into a tiny
1224
- package so non-CLI users can run it directly with `npx`.
1225
- 3. **`switchbot self-test`** — scripted end-to-end go/no-go checks for
1226
- token/secret validity plus representative device control.
1227
- 4. **Record / replay** — capture request/response fixtures and replay
1228
- offline for deterministic integration tests and CI.
1229
-
1230
1222
  ## License
1231
1223
 
1232
1224
  [MIT](./LICENSE) © chenliuyun