@switchbot/openapi-cli 3.3.2 → 3.3.3
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.
- package/README.md +56 -5
- package/dist/index.js +30808 -29888
- package/dist/policy/schema/v0.2.json +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -278,6 +278,24 @@ Supported conditions: `time_between` (quiet hours) and `device_state`
|
|
|
278
278
|
`~/.switchbot/audit.log`. `rules run` is long-running; use
|
|
279
279
|
`daemon start` / `daemon reload` for the managed background mode.
|
|
280
280
|
|
|
281
|
+
**Actions** — each rule's `then` array accepts two action types:
|
|
282
|
+
|
|
283
|
+
- `type: command` (default, no `type` field required) — sends a device command, e.g. `devices command <id> turnOn`
|
|
284
|
+
- `type: notify` — delivers a payload to an external channel after the rule fires:
|
|
285
|
+
- `channel: webhook` — HTTP POST to a URL (only `http://` and `https://` schemes are accepted; `rules lint` rejects others)
|
|
286
|
+
- `channel: file` — appends a JSONL line to a local file. `to` must be an absolute path; relative or `~`-prefixed paths are rejected by `rules lint` (code `notify-relative-path`) and at runtime
|
|
287
|
+
- `channel: openclaw` — HTTP POST to an OpenClaw endpoint (same protocol restriction)
|
|
288
|
+
- Optional `template` field supports `{{ rule.name }}`, `{{ event.* }}`, `{{ device.id }}` placeholders. Nested fields use dot paths, e.g. `{{ event.context.deviceMac }}`; arrays index numerically, e.g. `{{ event.list.0 }}`
|
|
289
|
+
|
|
290
|
+
```yaml
|
|
291
|
+
then:
|
|
292
|
+
- command: devices command AC_001 turnOn
|
|
293
|
+
- type: notify
|
|
294
|
+
channel: webhook
|
|
295
|
+
to: https://your.host/hook
|
|
296
|
+
template: '{"rule":"{{ rule.name }}","fired":"{{ rule.fired_at }}"}'
|
|
297
|
+
```
|
|
298
|
+
|
|
281
299
|
```bash
|
|
282
300
|
# 1. Author rules under `automation.rules`. See examples/policies/automation.yaml
|
|
283
301
|
# for a walkthrough covering the three trigger sources.
|
|
@@ -308,8 +326,29 @@ switchbot rules last-fired -n 20 # 20 most recent fire entries
|
|
|
308
326
|
switchbot rules conflicts # opposing actions, high-frequency MQTT,
|
|
309
327
|
# destructive commands, quiet-hours gaps
|
|
310
328
|
switchbot rules doctor --json # lint + conflicts combined; exit 0 when clean
|
|
329
|
+
|
|
330
|
+
# 8. Scaffold a new rule from natural language (heuristic or LLM-backed).
|
|
331
|
+
switchbot rules suggest --intent "turn off AC at 11pm"
|
|
332
|
+
switchbot rules suggest --intent "if door opens and temp below 20 turn on heater" \
|
|
333
|
+
--llm auto # routes complex intents to LLM automatically
|
|
334
|
+
switchbot rules suggest --intent "..." --llm openai # explicit backend
|
|
335
|
+
# Set OPENAI_API_KEY or ANTHROPIC_API_KEY; auto mode falls back to heuristic on failure
|
|
311
336
|
```
|
|
312
337
|
|
|
338
|
+
`rules suggest` enforces several guardrails on LLM output so a model can't quietly arm
|
|
339
|
+
something unsafe:
|
|
340
|
+
|
|
341
|
+
- **`dry_run` is forced to `true`** on every LLM-generated rule. Review the output and
|
|
342
|
+
flip it yourself before running the engine without `--dry-run`.
|
|
343
|
+
- **Explicit overrides always win.** If you pass `--trigger`, the LLM's answer must match;
|
|
344
|
+
a mismatch fails fast. Within the same trigger, mismatched `--event` / `--schedule` /
|
|
345
|
+
`--days` / `--webhook-path` are rewritten to your value with a warning.
|
|
346
|
+
- **`--llm` is enum-validated at the CLI** (`auto | openai | anthropic`) — junk values
|
|
347
|
+
exit non-zero instead of falling through.
|
|
348
|
+
- **Notify URLs must be `http://` or `https://`.** `rules lint` and the runtime both
|
|
349
|
+
reject `file://`, `ftp://`, etc., so a generated webhook can't smuggle in a non-HTTP
|
|
350
|
+
scheme.
|
|
351
|
+
|
|
313
352
|
When `quiet_hours` is configured in `policy.yaml`, `rules conflicts` additionally flags event-driven (MQTT / webhook) rules that lack a `time_between` condition — they would fire uninhibited during the quiet window. The hint in each finding includes a ready-to-paste `time_between` condition to add.
|
|
314
353
|
|
|
315
354
|
Webhook trigger token management:
|
|
@@ -842,8 +881,12 @@ Exposes MCP tools (`list_devices`, `describe_device`, `get_device_status`,
|
|
|
842
881
|
`send_command`, `list_scenes`, `run_scene`, `search_catalog`,
|
|
843
882
|
`account_overview`, `plan_suggest`, `plan_run`, `audit_query`,
|
|
844
883
|
`audit_stats`, `policy_diff`, `policy_validate`, `policy_new`,
|
|
845
|
-
`policy_migrate`) plus a
|
|
846
|
-
shadow updates.
|
|
884
|
+
`policy_migrate`, `rules_suggest`, `rule_notifications`) plus a
|
|
885
|
+
`switchbot://events` resource for real-time shadow updates.
|
|
886
|
+
`rules_suggest` accepts an optional `llm` parameter (`openai | anthropic | auto`)
|
|
887
|
+
to generate YAML for complex intents via an LLM backend.
|
|
888
|
+
`rule_notifications` returns `rule-notify` audit entries, filterable by rule
|
|
889
|
+
name, time range, channel, and result.
|
|
847
890
|
See [`docs/agent-guide.md`](./docs/agent-guide.md) for the full tool reference and safety rules (destructive-command guard).
|
|
848
891
|
|
|
849
892
|
### `doctor` — self-check
|
|
@@ -853,7 +896,7 @@ switchbot doctor
|
|
|
853
896
|
switchbot doctor --json
|
|
854
897
|
```
|
|
855
898
|
|
|
856
|
-
Runs local checks (Node version, credentials, profiles, catalog, cache, quota, clock, MQTT, policy, MCP) and exits 1 if any check fails. `warn` results exit 0. The MQTT check reports `ok` when REST credentials are configured (auto-provisioned on first use). Use this to diagnose connectivity or config issues before running automation.
|
|
899
|
+
Runs local checks (Node version, credentials, profiles, catalog, cache, quota, clock, MQTT, policy, MCP, notify-connectivity) and exits 1 if any check fails. `warn` results exit 0. The MQTT check reports `ok` when REST credentials are configured (auto-provisioned on first use). The `notify-connectivity` check probes webhook URLs declared in `type: notify` actions. Use this to diagnose connectivity or config issues before running automation.
|
|
857
900
|
|
|
858
901
|
`--json` output includes `maturityScore` (0–100) and `maturityLabel` (`production-ready` / `mostly-ready` / `needs-work` / `not-ready`) to give an at-a-glance readiness rating:
|
|
859
902
|
|
|
@@ -1165,8 +1208,16 @@ src/
|
|
|
1165
1208
|
│ ├── audit-query.ts # Audit log filtering + aggregation
|
|
1166
1209
|
│ ├── conflict-analyzer.ts # Static conflict detection (opposing actions,
|
|
1167
1210
|
│ │ # high-freq MQTT, destructive cmds, quiet-hours gaps)
|
|
1168
|
-
│ ├── suggest.ts # Heuristic-
|
|
1169
|
-
│
|
|
1211
|
+
│ ├── suggest.ts # Heuristic + LLM-backed rule YAML generation
|
|
1212
|
+
│ ├── notify.ts # notify action executor (webhook / file / openclaw)
|
|
1213
|
+
│ └── types.ts # Shared rule/trigger/condition/action types (CommandAction | NotifyAction)
|
|
1214
|
+
├── llm/
|
|
1215
|
+
│ ├── index.ts # createLLMProvider factory + LLM_AUTO_THRESHOLD
|
|
1216
|
+
│ ├── complexity.ts # Intent complexity scorer (0–10) for auto-routing
|
|
1217
|
+
│ ├── rule-prompt.ts # System prompt builder (embeds v0.2 schema snippet)
|
|
1218
|
+
│ └── providers/
|
|
1219
|
+
│ ├── openai.ts # OpenAI-compatible provider (uses Node.js https)
|
|
1220
|
+
│ └── anthropic.ts # Anthropic provider
|
|
1170
1221
|
├── status-sync/
|
|
1171
1222
|
│ └── manager.ts # Spawn/stop logic, state file, OpenClaw bridge
|
|
1172
1223
|
├── lib/
|